@opencrvs/toolkit 1.8.0-rc.fc43738 → 1.8.0-rc.fd16d13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,9 +1,26 @@
1
1
  import { z } from 'zod';
2
+ import { AddressFieldValue, AddressFieldUpdateValue, FileFieldValue, FileFieldWithOptionValue } from './CompositeFieldValue';
3
+ /**
4
+ * FieldValues defined in this file are primitive field values.
5
+ * FieldValues defined in CompositeFieldValue.ts are composed of multiple primitive field values (Address, File etc).
6
+ *
7
+ * FieldValue is a union of primitive and composite field values.
8
+ * FieldValue can never be null.
9
+ *
10
+ * FieldUpdateValue accepts null values for primitive field values when they are optional.
11
+ * API is build assuming partial (PATCH) updates. In order to edit and remove optional value, we need to accept null values.
12
+ * Omitting a field value in partial updates leaves it untouched.
13
+ *
14
+ */
2
15
  export declare const TextValue: z.ZodString;
3
16
  export declare const RequiredTextValue: z.ZodString;
4
17
  export declare const DateValue: z.ZodString;
5
18
  export declare const EmailValue: z.ZodString;
6
- export declare const FileFieldValue: z.ZodObject<{
19
+ export declare const CheckboxFieldValue: z.ZodBoolean;
20
+ export type CheckboxFieldValue = z.infer<typeof CheckboxFieldValue>;
21
+ export declare const NumberFieldValue: z.ZodNumber;
22
+ export type NumberFieldValue = z.infer<typeof NumberFieldValue>;
23
+ export declare const FieldValue: z.ZodUnion<[z.ZodString, z.ZodString, z.ZodBoolean, z.ZodNumber, z.ZodObject<{
7
24
  filename: z.ZodString;
8
25
  originalFilename: z.ZodString;
9
26
  type: z.ZodString;
@@ -15,10 +32,23 @@ export declare const FileFieldValue: z.ZodObject<{
15
32
  type: string;
16
33
  filename: string;
17
34
  originalFilename: string;
18
- }>;
19
- export type FileFieldValue = z.infer<typeof FileFieldValue>;
20
- export declare const AddressFieldValue: z.ZodDiscriminatedUnion<"urbanOrRural", [z.ZodObject<z.objectUtil.extendShape<{
21
- country: z.ZodString;
35
+ }>, z.ZodArray<z.ZodObject<{
36
+ filename: z.ZodString;
37
+ originalFilename: z.ZodString;
38
+ type: z.ZodString;
39
+ option: z.ZodString;
40
+ }, "strip", z.ZodTypeAny, {
41
+ type: string;
42
+ option: string;
43
+ filename: string;
44
+ originalFilename: string;
45
+ }, {
46
+ type: string;
47
+ option: string;
48
+ filename: string;
49
+ originalFilename: string;
50
+ }>, "many">, z.ZodObject<z.objectUtil.extendShape<{
51
+ country: z.ZodLiteral<string>;
22
52
  province: z.ZodString;
23
53
  district: z.ZodString;
24
54
  }, {
@@ -49,7 +79,7 @@ export declare const AddressFieldValue: z.ZodDiscriminatedUnion<"urbanOrRural",
49
79
  street?: string | undefined;
50
80
  zipCode?: string | undefined;
51
81
  }>, z.ZodObject<z.objectUtil.extendShape<{
52
- country: z.ZodString;
82
+ country: z.ZodLiteral<string>;
53
83
  province: z.ZodString;
54
84
  district: z.ZodString;
55
85
  }, {
@@ -67,47 +97,36 @@ export declare const AddressFieldValue: z.ZodDiscriminatedUnion<"urbanOrRural",
67
97
  province: string;
68
98
  urbanOrRural: "RURAL";
69
99
  village?: string | undefined;
70
- }>]>;
71
- export type AddressFieldValue = z.infer<typeof AddressFieldValue>;
72
- export declare const FileFieldValueWithOption: z.ZodObject<{
73
- filename: z.ZodString;
74
- originalFilename: z.ZodString;
75
- type: z.ZodString;
76
- option: z.ZodString;
77
- }, "strip", z.ZodTypeAny, {
78
- type: string;
79
- option: string;
80
- filename: string;
81
- originalFilename: string;
82
- }, {
83
- type: string;
84
- option: string;
85
- filename: string;
86
- originalFilename: string;
87
- }>;
88
- export type FileFieldValueWithOption = z.infer<typeof FileFieldValueWithOption>;
89
- export declare const FileFieldWithOptionValue: z.ZodArray<z.ZodObject<{
90
- filename: z.ZodString;
91
- originalFilename: z.ZodString;
92
- type: z.ZodString;
93
- option: z.ZodString;
100
+ }>, z.ZodObject<{
101
+ country: z.ZodEffects<z.ZodString, string, string>;
102
+ state: z.ZodString;
103
+ district2: z.ZodString;
104
+ cityOrTown: z.ZodOptional<z.ZodString>;
105
+ addressLine1: z.ZodOptional<z.ZodString>;
106
+ addressLine2: z.ZodOptional<z.ZodString>;
107
+ addressLine3: z.ZodOptional<z.ZodString>;
108
+ postcodeOrZip: z.ZodOptional<z.ZodString>;
94
109
  }, "strip", z.ZodTypeAny, {
95
- type: string;
96
- option: string;
97
- filename: string;
98
- originalFilename: string;
110
+ country: string;
111
+ state: string;
112
+ district2: string;
113
+ cityOrTown?: string | undefined;
114
+ addressLine1?: string | undefined;
115
+ addressLine2?: string | undefined;
116
+ addressLine3?: string | undefined;
117
+ postcodeOrZip?: string | undefined;
99
118
  }, {
100
- type: string;
101
- option: string;
102
- filename: string;
103
- originalFilename: string;
104
- }>, "many">;
105
- export type FileFieldWithOptionValue = z.infer<typeof FileFieldWithOptionValue>;
106
- export declare const CheckboxFieldValue: z.ZodBoolean;
107
- export type CheckboxFieldValue = z.infer<typeof CheckboxFieldValue>;
108
- export declare const NumberFieldValue: z.ZodNumber;
109
- export type NumberFieldValue = z.infer<typeof NumberFieldValue>;
110
- export declare const FieldValue: z.ZodUnion<[z.ZodString, z.ZodString, z.ZodObject<{
119
+ country: string;
120
+ state: string;
121
+ district2: string;
122
+ cityOrTown?: string | undefined;
123
+ addressLine1?: string | undefined;
124
+ addressLine2?: string | undefined;
125
+ addressLine3?: string | undefined;
126
+ postcodeOrZip?: string | undefined;
127
+ }>]>;
128
+ export type FieldValue = z.infer<typeof FieldValue>;
129
+ export declare const FieldUpdateValue: z.ZodUnion<[z.ZodString, z.ZodString, z.ZodBoolean, z.ZodNumber, z.ZodObject<{
111
130
  filename: z.ZodString;
112
131
  originalFilename: z.ZodString;
113
132
  type: z.ZodString;
@@ -134,61 +153,93 @@ export declare const FieldValue: z.ZodUnion<[z.ZodString, z.ZodString, z.ZodObje
134
153
  option: string;
135
154
  filename: string;
136
155
  originalFilename: string;
137
- }>, "many">, z.ZodBoolean, z.ZodNumber, z.ZodObject<z.objectUtil.extendShape<{
138
- country: z.ZodString;
156
+ }>, "many">, z.ZodObject<z.objectUtil.extendShape<{
157
+ country: z.ZodLiteral<string>;
139
158
  province: z.ZodString;
140
159
  district: z.ZodString;
141
160
  }, {
142
161
  urbanOrRural: z.ZodLiteral<"URBAN">;
143
- town: z.ZodOptional<z.ZodString>;
144
- residentialArea: z.ZodOptional<z.ZodString>;
145
- street: z.ZodOptional<z.ZodString>;
146
- number: z.ZodOptional<z.ZodString>;
147
- zipCode: z.ZodOptional<z.ZodString>;
162
+ town: z.ZodOptional<z.ZodNullable<z.ZodString>>;
163
+ residentialArea: z.ZodOptional<z.ZodNullable<z.ZodString>>;
164
+ street: z.ZodOptional<z.ZodNullable<z.ZodString>>;
165
+ number: z.ZodOptional<z.ZodNullable<z.ZodString>>;
166
+ zipCode: z.ZodOptional<z.ZodNullable<z.ZodString>>;
148
167
  }>, "strip", z.ZodTypeAny, {
149
168
  country: string;
150
169
  district: string;
151
170
  province: string;
152
171
  urbanOrRural: "URBAN";
153
- number?: string | undefined;
154
- town?: string | undefined;
155
- residentialArea?: string | undefined;
156
- street?: string | undefined;
157
- zipCode?: string | undefined;
172
+ number?: string | null | undefined;
173
+ town?: string | null | undefined;
174
+ residentialArea?: string | null | undefined;
175
+ street?: string | null | undefined;
176
+ zipCode?: string | null | undefined;
158
177
  }, {
159
178
  country: string;
160
179
  district: string;
161
180
  province: string;
162
181
  urbanOrRural: "URBAN";
163
- number?: string | undefined;
164
- town?: string | undefined;
165
- residentialArea?: string | undefined;
166
- street?: string | undefined;
167
- zipCode?: string | undefined;
182
+ number?: string | null | undefined;
183
+ town?: string | null | undefined;
184
+ residentialArea?: string | null | undefined;
185
+ street?: string | null | undefined;
186
+ zipCode?: string | null | undefined;
168
187
  }>, z.ZodObject<z.objectUtil.extendShape<{
169
- country: z.ZodString;
188
+ country: z.ZodLiteral<string>;
170
189
  province: z.ZodString;
171
190
  district: z.ZodString;
172
191
  }, {
173
192
  urbanOrRural: z.ZodLiteral<"RURAL">;
174
- village: z.ZodOptional<z.ZodString>;
193
+ village: z.ZodOptional<z.ZodNullable<z.ZodString>>;
175
194
  }>, "strip", z.ZodTypeAny, {
176
195
  country: string;
177
196
  district: string;
178
197
  province: string;
179
198
  urbanOrRural: "RURAL";
180
- village?: string | undefined;
199
+ village?: string | null | undefined;
181
200
  }, {
182
201
  country: string;
183
202
  district: string;
184
203
  province: string;
185
204
  urbanOrRural: "RURAL";
186
- village?: string | undefined;
205
+ village?: string | null | undefined;
206
+ }>, z.ZodObject<{
207
+ country: z.ZodEffects<z.ZodString, string, string>;
208
+ state: z.ZodString;
209
+ district2: z.ZodString;
210
+ cityOrTown: z.ZodOptional<z.ZodNullable<z.ZodString>>;
211
+ addressLine1: z.ZodOptional<z.ZodNullable<z.ZodString>>;
212
+ addressLine2: z.ZodOptional<z.ZodNullable<z.ZodString>>;
213
+ addressLine3: z.ZodOptional<z.ZodNullable<z.ZodString>>;
214
+ postcodeOrZip: z.ZodOptional<z.ZodNullable<z.ZodString>>;
215
+ }, "strip", z.ZodTypeAny, {
216
+ country: string;
217
+ state: string;
218
+ district2: string;
219
+ cityOrTown?: string | null | undefined;
220
+ addressLine1?: string | null | undefined;
221
+ addressLine2?: string | null | undefined;
222
+ addressLine3?: string | null | undefined;
223
+ postcodeOrZip?: string | null | undefined;
224
+ }, {
225
+ country: string;
226
+ state: string;
227
+ district2: string;
228
+ cityOrTown?: string | null | undefined;
229
+ addressLine1?: string | null | undefined;
230
+ addressLine2?: string | null | undefined;
231
+ addressLine3?: string | null | undefined;
232
+ postcodeOrZip?: string | null | undefined;
187
233
  }>]>;
188
- export type FieldValue = z.infer<typeof FieldValue>;
234
+ export type FieldUpdateValue = z.infer<typeof FieldUpdateValue>;
189
235
  /**
190
236
  * NOTE: This is an exception. We need schema as a type in order to generate schema dynamically.
191
237
  * */
192
238
  export type FieldValueSchema = typeof FileFieldValue | typeof FileFieldWithOptionValue | typeof CheckboxFieldValue | typeof AddressFieldValue | typeof NumberFieldValue | z.ZodString | z.ZodBoolean;
193
- export type OptionalFieldValueSchema = z.ZodOptional<FieldValueSchema>;
239
+ /**
240
+ * NOTE: This is an exception. We need schema as a type in order to generate schema dynamically.
241
+ *
242
+ * FieldValueInputSchema uses Input types which have set optional values as nullish
243
+ * */
244
+ export type FieldUpdateValueSchema = typeof FileFieldValue | typeof FileFieldWithOptionValue | typeof CheckboxFieldValue | typeof AddressFieldUpdateValue | typeof NumberFieldValue | z.ZodString | z.ZodBoolean;
194
245
  //# sourceMappingURL=FieldValue.d.ts.map
@@ -0,0 +1,38 @@
1
+ /**
2
+ * TemplateConfig defines configuration rules for system-based variables (e.g. $user.province).
3
+ * They are currently used for providing default values in FieldConfig.
4
+ */
5
+ import { FieldValue } from './FieldValue';
6
+ /**
7
+ * Available system variables for configuration.
8
+ */
9
+ export interface MetaFields {
10
+ $user: {
11
+ province: string;
12
+ district: string;
13
+ };
14
+ }
15
+ /**
16
+ * Recursively flatten the keys of an object. Used to limit types when configuring default values in country config.
17
+ * @example
18
+ * type Test = FlattenedKeyStrings<{ a: { b: string, c: { d: string } } }>
19
+ * // 'a.b' | 'a.c.d' but not 'a' or 'a.c'
20
+ */
21
+ type FlattenedKeyStrings<T, Prefix extends string = ''> = {
22
+ [K in keyof T]: T[K] extends Record<string, any> ? FlattenedKeyStrings<T[K], `${Prefix}${K & string}.`> : `${Prefix}${K & string}`;
23
+ }[keyof T];
24
+ export type FlattenedMetaFields = FlattenedKeyStrings<MetaFields>;
25
+ /**
26
+ * Default value for a field when configuring a form.
27
+ */
28
+ export type FieldConfigDefaultValue = FieldValue | FlattenedMetaFields | Record<string, FlattenedMetaFields | FieldValue>;
29
+ export declare function isTemplateVariable(value: FieldConfigDefaultValue): value is FlattenedMetaFields;
30
+ export declare function isFieldValue(value: FieldConfigDefaultValue): value is FieldValue;
31
+ /**
32
+ * Checks if given value is valid for a field, and known template variables are already resolved.
33
+ * @todo: Extend functionality to arbitrary depth objects. Currently only checks first level since our compoosite fields are only 1 level deep.
34
+ */
35
+ export declare function isFieldValueWithoutTemplates(value: FieldConfigDefaultValue): value is FieldValue;
36
+ export declare function isFieldConfigDefaultValue(value: any): value is FieldConfigDefaultValue;
37
+ export {};
38
+ //# sourceMappingURL=TemplateConfig.d.ts.map
@@ -63,7 +63,6 @@ export declare const defineConfig: (config: EventConfigInput) => {
63
63
  draft?: boolean | undefined;
64
64
  } | {
65
65
  type: "REJECT";
66
- comment: string;
67
66
  conditionals: ({
68
67
  type: "SHOW";
69
68
  conditional: import(".").JSONSchema;
@@ -89,11 +88,9 @@ export declare const defineConfig: (config: EventConfigInput) => {
89
88
  fields: import("./FieldConfig").Inferred[];
90
89
  };
91
90
  }[];
92
- isDuplicate: boolean;
93
91
  draft?: boolean | undefined;
94
92
  } | {
95
93
  type: "MARKED_AS_DUPLICATE";
96
- comment: string;
97
94
  conditionals: ({
98
95
  type: "SHOW";
99
96
  conditional: import(".").JSONSchema;
@@ -119,11 +116,9 @@ export declare const defineConfig: (config: EventConfigInput) => {
119
116
  fields: import("./FieldConfig").Inferred[];
120
117
  };
121
118
  }[];
122
- duplicates: string[];
123
119
  draft?: boolean | undefined;
124
120
  } | {
125
- type: "ARCHIVED";
126
- comment: string;
121
+ type: "ARCHIVE";
127
122
  conditionals: ({
128
123
  type: "SHOW";
129
124
  conditional: import(".").JSONSchema;
@@ -149,7 +144,6 @@ export declare const defineConfig: (config: EventConfigInput) => {
149
144
  fields: import("./FieldConfig").Inferred[];
150
145
  };
151
146
  }[];
152
- isDuplicate: boolean;
153
147
  draft?: boolean | undefined;
154
148
  } | {
155
149
  type: "REGISTER";
@@ -15,6 +15,7 @@ export * from './ActionDocument';
15
15
  export * from './EventIndex';
16
16
  export * from './TranslationConfig';
17
17
  export * from './FieldValue';
18
+ export * from './CompositeFieldValue';
18
19
  export * from './state';
19
20
  export * from './utils';
20
21
  export * from './defineConfig';
@@ -27,6 +28,7 @@ export * from './FieldTypeMapping';
27
28
  export * from './Conditional';
28
29
  export * from './AdvancedSearchConfig';
29
30
  export * from './test.utils';
31
+ export * from './TemplateConfig';
30
32
  export * from '../conditionals/conditionals';
31
33
  export * from '../conditionals/validate';
32
34
  //# sourceMappingURL=index.d.ts.map