-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathddd.d.ts
70 lines (59 loc) · 1.94 KB
/
ddd.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import {
ZodBoolean,
ZodFunction,
ZodObject,
ZodRawShape,
ZodString,
ZodTuple,
ZodUnknown,
infer as zinfer,
} from 'zod';
export interface IDomainObject<T> {
isEqual(comparable: T): boolean;
}
export type TMetaEntity = { id: string };
export interface IEntity<T> extends IDomainObject<T>, TMetaEntity {}
export const Entity: {
fromKeys: <TMetaModel>(
keys: (keyof TMetaModel)[],
) => new (args: TMetaModel & TMetaEntity) => TMetaModel & IEntity<TMetaModel>;
fromZodSchema: <TMetaSchema extends ZodRawShape>(
schema: ZodObject<TMetaSchema>,
) => new (argsObj: zinfer<typeof schema> & TMetaEntity) => zinfer<
typeof schema
> &
IEntity<zinfer<typeof schema>>;
};
export interface IValueObject<T> extends IDomainObject<T> {}
export const ValueObject: {
fromKeys: <TMetaModel>(
keys: (keyof TMetaModel)[],
) => new (args: TMetaModel) => TMetaModel & IValueObject<TMetaModel>;
fromZodSchema: <TMetaSchema extends ZodRawShape>(
schema: ZodObject<TMetaSchema>,
) => new (argsObj: zinfer<typeof schema>) => zinfer<typeof schema> &
IValueObject<zinfer<typeof schema>>;
};
type TDomainObjectZodRawShape<TSchema extends ZodObject<ZodRawShape>> = {
isEqual: ZodFunction<ZodTuple<[TSchema], ZodUnknown>, ZodBoolean>;
};
type TDomainObjectZodSchema<TSchema extends ZodObject<ZodRawShape>> = ZodObject<
TDomainObjectZodRawShape<TSchema>
>;
export const DomainObjectZodSchema: {
fromModelSchema: <TShape extends ZodRawShape>(
modelSchema: ZodObject<TShape>,
) => TDomainObjectZodSchema<ZodObject<TShape>>;
};
export const EntityZodSchema: {
fromModelSchema: <TShape extends ZodRawShape>(
modelSchema: ZodObject<TShape>,
) => ZodObject<
TDomainObjectZodRawShape<ZodObject<TShape>> & { id: ZodString }
>;
};
export const ValueObjectZodSchema: {
fromModelSchema: <TShape extends ZodRawShape>(
modelSchema: ZodObject<TShape>,
) => ZodObject<TDomainObjectZodRawShape<ZodObject<TShape>> & {}>;
};