-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTypes.ts
121 lines (109 loc) · 2.66 KB
/
Types.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
import { type IdConstraint, type NullFilter, strId, both } from "../src";
export namespace Test {
export type User = {
id: string;
name: string;
email: string;
dob: number | null;
deleted: 0 | 1;
verified: 0 | 1;
primaryAddressId: string | null;
status: "signed-up" | "ready-for-review" | "approved" | "denied" | "needs-followup";
createdMs: number;
};
export type Address = {
id: string;
street1: string;
street2: string | null;
city: string;
state: string;
country: string;
zip: string;
};
export type Organization = {
id: string;
name: string;
createdMs: number;
};
export type OrgRole = {
organizationId: string;
userId: string;
role: "user" | "admin" | "superadmin";
};
export type Pet = {
id: string;
name: string;
type: "dog" | "cat" | "mouse";
ownerId: string;
};
export const Defaults = {
users: both(strId, {
dob: null,
deleted: 0 as const,
verified: 0 as const,
primaryAddressId: null,
status: "signed-up" as const,
createdMs: () => Date.now(),
}),
addresses: both(strId, {
street2: null,
}),
organizations: both(strId, {
createdMs: () => Date.now(),
}),
"org-roles": strId,
pets: strId,
};
export type TypeMap = {
users: {
type: User;
constraints:
| IdConstraint
| { email: string | undefined | null }
| { primaryAddressId: string | undefined | null };
filters: Filter<{
pet?: {
type?: Pet["type"];
nameLike?: string;
};
emailLike?: string;
}>;
defaults: (typeof Defaults)["users"];
};
addresses: {
type: Address;
constraints: IdConstraint;
filters: Filter<{
country?: string | Array<string>;
zip?: string | Array<string>;
}>;
defaults: (typeof Defaults)["addresses"];
};
organizations: {
type: Organization;
constraints: IdConstraint;
filters: NullFilter;
defaults: (typeof Defaults)["organizations"];
};
"org-roles": {
type: OrgRole;
constraints: { organizationId: string; userId: string; role: OrgRole["role"] };
filters: Filter<{
organizationId?: string;
userId?: string;
}>;
defaults: (typeof Defaults)["org-roles"];
};
pets: {
type: Pet;
constraints: IdConstraint;
filters: Filter<{
ownerId?: string;
type?: Pet["type"];
nameLike?: string;
}>;
defaults: (typeof Defaults)["pets"];
};
};
}
type Filter<T> = { _t: "filter" } & { [K in keyof T]: undefined | null | T[K] };