@opencrvs/toolkit 1.8.0-rc.f7e8fb5 → 1.8.0-rc.f8e4107

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.
Files changed (34) hide show
  1. package/README.md +1 -1
  2. package/dist/commons/api/router.d.ts +6649 -9067
  3. package/dist/commons/conditionals/conditionals.d.ts +91 -3
  4. package/dist/commons/conditionals/validate-address.test.d.ts +2 -0
  5. package/dist/commons/conditionals/validate.d.ts +41 -17
  6. package/dist/commons/conditionals/validate.test.d.ts +2 -0
  7. package/dist/commons/events/ActionConfig.d.ts +1123 -2056
  8. package/dist/commons/events/ActionDocument.d.ts +9644 -363
  9. package/dist/commons/events/ActionInput.d.ts +5329 -472
  10. package/dist/commons/events/ActionType.d.ts +26 -11
  11. package/dist/commons/events/AdvancedSearchConfig.d.ts +107 -14
  12. package/dist/commons/events/CompositeFieldValue.d.ts +152 -2
  13. package/dist/commons/events/Conditional.d.ts +21 -5
  14. package/dist/commons/events/Draft.d.ts +361 -53
  15. package/dist/commons/events/EventConfig.d.ts +634 -1223
  16. package/dist/commons/events/EventConfigInput.d.ts +6 -3
  17. package/dist/commons/events/EventDocument.d.ts +3495 -499
  18. package/dist/commons/events/EventIndex.d.ts +752 -7
  19. package/dist/commons/events/EventMetadata.d.ts +9 -3
  20. package/dist/commons/events/FieldConfig.d.ts +571 -119
  21. package/dist/commons/events/FieldType.d.ts +2 -1
  22. package/dist/commons/events/FieldTypeMapping.d.ts +154 -3
  23. package/dist/commons/events/FieldValue.d.ts +76 -2
  24. package/dist/commons/events/FormConfig.d.ts +633 -48
  25. package/dist/commons/events/PageConfig.d.ts +335 -0
  26. package/dist/commons/events/TemplateConfig.d.ts +5 -5
  27. package/dist/commons/events/defineConfig.d.ts +94 -215
  28. package/dist/commons/events/index.d.ts +2 -1
  29. package/dist/commons/events/test.utils.d.ts +140 -213
  30. package/dist/commons/events/utils.d.ts +125 -86
  31. package/dist/commons/events/utils.test.d.ts +2 -0
  32. package/dist/conditionals/index.js +215 -81
  33. package/dist/events/index.js +1949 -1232
  34. package/package.json +1 -1
@@ -1,99 +1,90 @@
1
- import { TranslationConfig } from './TranslationConfig';
2
- import { ActionType } from './ActionType';
1
+ import { ActionType, DeclarationActionType } from './ActionType';
3
2
  import { EventConfig } from './EventConfig';
4
- import { EventConfigInput } from './EventConfigInput';
5
- import { EventMetadataKeys } from './EventMetadata';
6
3
  import { FieldConfig } from './FieldConfig';
7
4
  import { WorkqueueConfig } from './WorkqueueConfig';
8
- import { EventState } from './ActionDocument';
9
- import { FormConfig } from './FormConfig';
5
+ import { Action, ActionUpdate, EventState } from './ActionDocument';
6
+ import { PageConfig, VerificationPageConfig } from './PageConfig';
10
7
  import { Draft } from './Draft';
11
8
  import { EventDocument } from './EventDocument';
12
- /**
13
- * @returns All the fields in the event configuration input.
14
- */
15
- export declare const findInputPageFields: (config: EventConfigInput) => {
16
- id: string;
17
- label: TranslationConfig;
18
- }[];
19
- /**
20
- * @returns All the fields in the event configuration.
21
- */
22
- export declare const findPageFields: (config: EventConfig) => FieldConfig[];
23
- /**
24
- *
25
- * @param pageFields - All the fields in the event configuration
26
- * @param refFields - The fields referencing values within the event configuration (e.g. summary fields) or within system provided metadata fields (e.g. createdAt, updatedBy)
27
- * @returns referenced fields with populated labels
28
- */
29
- export declare const resolveLabelsFromKnownFields: ({ pageFields, refFields }: {
30
- pageFields: {
31
- id: string;
32
- label: TranslationConfig;
33
- }[];
34
- refFields: {
35
- id: EventMetadataKeys | string;
36
- label?: TranslationConfig;
37
- }[];
38
- }) => {
39
- id: EventMetadataKeys | string;
40
- label?: TranslationConfig;
41
- }[];
42
- export declare function getAllFields(configuration: EventConfig): import("./FieldConfig").Inferred[];
43
- export declare function getAllPages(configuration: EventConfig): {
9
+ import { ActionConfig } from './ActionConfig';
10
+ import { FormConfig } from './FormConfig';
11
+ export declare function getDeclarationFields(configuration: EventConfig): FieldConfig[];
12
+ export declare function getDeclarationPages(configuration: EventConfig): {
13
+ type: "FORM";
44
14
  id: string;
45
- title: TranslationConfig;
15
+ title: import("./TranslationConfig").TranslationConfig;
46
16
  fields: import("./FieldConfig").Inferred[];
17
+ conditional?: import(".").JSONSchema | undefined;
47
18
  }[];
48
- export declare function validateWorkqueueConfig(workqueueConfigs: WorkqueueConfig[]): void;
49
- export declare const findActiveActionForm: (configuration: EventConfig, action: ActionType) => {
50
- active: boolean;
51
- version: {
52
- id: string;
53
- label: TranslationConfig;
54
- };
55
- label: TranslationConfig;
19
+ export declare function getDeclaration(configuration: EventConfig): {
20
+ label: import("./TranslationConfig").TranslationConfig;
56
21
  pages: {
22
+ type: "FORM";
57
23
  id: string;
58
- title: TranslationConfig;
24
+ title: import("./TranslationConfig").TranslationConfig;
59
25
  fields: import("./FieldConfig").Inferred[];
26
+ conditional?: import(".").JSONSchema | undefined;
60
27
  }[];
61
- review: {
62
- title: TranslationConfig;
63
- fields: import("./FieldConfig").Inferred[];
64
- };
65
- } | undefined;
66
- export declare const findActiveActionFormPages: (configuration: EventConfig, action: ActionType) => {
67
- id: string;
68
- title: TranslationConfig;
69
- fields: import("./FieldConfig").Inferred[];
70
- }[] | undefined;
71
- export declare const getFormFields: (formConfig: FormConfig) => import("./FieldConfig").Inferred[];
72
- /**
73
- * Returns only form fields for the action type, if any, excluding review fields.
74
- */
75
- export declare const findActiveActionFormFields: (configuration: EventConfig, action: ActionType) => FieldConfig[] | undefined;
28
+ };
29
+ export declare const getActionAnnotationFields: (actionConfig: ActionConfig) => import("./FieldConfig").Inferred[];
30
+ export declare const getAllAnnotationFields: (config: EventConfig) => FieldConfig[];
76
31
  /**
77
- * Returns all fields for the action type, including review fields, if any.
32
+ * @TODO: Request correction should have same format as print certificate
78
33
  */
79
- export declare const findActiveActionFields: (configuration: EventConfig, action: ActionType) => FieldConfig[] | undefined;
80
- export declare const getActiveActionFormPages: (configuration: EventConfig, action: ActionType) => {
81
- id: string;
82
- title: TranslationConfig;
34
+ export declare const findRecordActionPages: (config: EventConfig, actionType: ActionType) => PageConfig[];
35
+ export declare function getActionReview(configuration: EventConfig, actionType: ActionType): {
36
+ title: import("./TranslationConfig").TranslationConfig;
83
37
  fields: import("./FieldConfig").Inferred[];
84
- }[];
85
- /**
86
- * Returns all fields for the action type, including review fields, or throws
87
- */
88
- export declare function getActiveActionFields(configuration: EventConfig, action: ActionType): FieldConfig[];
89
- export declare function getEventConfiguration(eventConfigurations: EventConfig[], type: string): EventConfig;
90
- export declare function stripHiddenFields(fields: FieldConfig[], data: EventState): import("lodash").Dictionary<string | number | boolean | {
38
+ };
39
+ export declare function getActionReviewFields(configuration: EventConfig, actionType: DeclarationActionType): import("./FieldConfig").Inferred[];
40
+ export declare function validateWorkqueueConfig(workqueueConfigs: WorkqueueConfig[]): void;
41
+ export declare function isPageVisible(page: PageConfig, formValues: ActionUpdate): boolean;
42
+ export declare function omitHiddenFields(fields: FieldConfig[], values: EventState): import("lodash").Dictionary<string | number | boolean | {
43
+ type: string;
44
+ filename: string;
45
+ originalFilename: string;
46
+ } | {
47
+ country: string;
48
+ district: string;
49
+ addressType: "DOMESTIC";
50
+ province: string;
51
+ urbanOrRural: "URBAN";
52
+ number?: string | undefined;
53
+ town?: string | undefined;
54
+ residentialArea?: string | undefined;
55
+ street?: string | undefined;
56
+ zipCode?: string | undefined;
57
+ } | {
58
+ country: string;
59
+ district: string;
60
+ addressType: "DOMESTIC";
61
+ province: string;
62
+ urbanOrRural: "RURAL";
63
+ village?: string | undefined;
64
+ } | {
65
+ country: string;
66
+ state: string;
67
+ addressType: "INTERNATIONAL";
68
+ district2: string;
69
+ cityOrTown?: string | undefined;
70
+ addressLine1?: string | undefined;
71
+ addressLine2?: string | undefined;
72
+ addressLine3?: string | undefined;
73
+ postcodeOrZip?: string | undefined;
74
+ } | {
75
+ type: string;
76
+ option: string;
77
+ filename: string;
78
+ originalFilename: string;
79
+ }[] | undefined>;
80
+ export declare function omitHiddenPaginatedFields(formConfig: FormConfig, declaration: EventState): import("lodash").Dictionary<string | number | boolean | {
91
81
  type: string;
92
82
  filename: string;
93
83
  originalFilename: string;
94
84
  } | {
95
85
  country: string;
96
86
  district: string;
87
+ addressType: "DOMESTIC";
97
88
  province: string;
98
89
  urbanOrRural: "URBAN";
99
90
  number?: string | undefined;
@@ -104,29 +95,44 @@ export declare function stripHiddenFields(fields: FieldConfig[], data: EventStat
104
95
  } | {
105
96
  country: string;
106
97
  district: string;
98
+ addressType: "DOMESTIC";
107
99
  province: string;
108
100
  urbanOrRural: "RURAL";
109
101
  village?: string | undefined;
102
+ } | {
103
+ country: string;
104
+ state: string;
105
+ addressType: "INTERNATIONAL";
106
+ district2: string;
107
+ cityOrTown?: string | undefined;
108
+ addressLine1?: string | undefined;
109
+ addressLine2?: string | undefined;
110
+ addressLine3?: string | undefined;
111
+ postcodeOrZip?: string | undefined;
110
112
  } | {
111
113
  type: string;
112
114
  option: string;
113
115
  filename: string;
114
116
  originalFilename: string;
115
- }[]>;
117
+ }[] | undefined>;
116
118
  export declare function findActiveDrafts(event: EventDocument, drafts: Draft[]): {
117
119
  id: string;
118
120
  createdAt: string;
119
121
  eventId: string;
120
122
  transactionId: string;
121
123
  action: {
122
- type: ActionType;
123
- data: Record<string, string | number | boolean | {
124
+ type: "DECLARE" | "REGISTER" | "VALIDATE" | "DELETE" | "CREATE" | "NOTIFY" | "DETECT_DUPLICATE" | "REJECT" | "MARKED_AS_DUPLICATE" | "ARCHIVE" | "PRINT_CERTIFICATE" | "REQUEST_CORRECTION" | "REJECT_CORRECTION" | "APPROVE_CORRECTION" | "READ" | "ASSIGN" | "UNASSIGN";
125
+ status: "Rejected" | "Requested" | "Accepted";
126
+ createdAt: string;
127
+ createdBy: string;
128
+ declaration: Record<string, string | number | boolean | {
124
129
  type: string;
125
130
  filename: string;
126
131
  originalFilename: string;
127
132
  } | {
128
133
  country: string;
129
134
  district: string;
135
+ addressType: "DOMESTIC";
130
136
  province: string;
131
137
  urbanOrRural: "URBAN";
132
138
  number?: string | null | undefined;
@@ -137,25 +143,34 @@ export declare function findActiveDrafts(event: EventDocument, drafts: Draft[]):
137
143
  } | {
138
144
  country: string;
139
145
  district: string;
146
+ addressType: "DOMESTIC";
140
147
  province: string;
141
148
  urbanOrRural: "RURAL";
142
149
  village?: string | null | undefined;
150
+ } | {
151
+ country: string;
152
+ state: string;
153
+ addressType: "INTERNATIONAL";
154
+ district2: string;
155
+ cityOrTown?: string | null | undefined;
156
+ addressLine1?: string | null | undefined;
157
+ addressLine2?: string | null | undefined;
158
+ addressLine3?: string | null | undefined;
159
+ postcodeOrZip?: string | null | undefined;
143
160
  } | {
144
161
  type: string;
145
162
  option: string;
146
163
  filename: string;
147
164
  originalFilename: string;
148
- }[]>;
149
- createdAt: string;
150
- createdBy: string;
151
- createdAtLocation: string;
152
- metadata?: Record<string, string | number | boolean | {
165
+ }[] | undefined>;
166
+ annotation?: Record<string, string | number | boolean | {
153
167
  type: string;
154
168
  filename: string;
155
169
  originalFilename: string;
156
170
  } | {
157
171
  country: string;
158
172
  district: string;
173
+ addressType: "DOMESTIC";
159
174
  province: string;
160
175
  urbanOrRural: "URBAN";
161
176
  number?: string | null | undefined;
@@ -166,15 +181,29 @@ export declare function findActiveDrafts(event: EventDocument, drafts: Draft[]):
166
181
  } | {
167
182
  country: string;
168
183
  district: string;
184
+ addressType: "DOMESTIC";
169
185
  province: string;
170
186
  urbanOrRural: "RURAL";
171
187
  village?: string | null | undefined;
188
+ } | {
189
+ country: string;
190
+ state: string;
191
+ addressType: "INTERNATIONAL";
192
+ district2: string;
193
+ cityOrTown?: string | null | undefined;
194
+ addressLine1?: string | null | undefined;
195
+ addressLine2?: string | null | undefined;
196
+ addressLine3?: string | null | undefined;
197
+ postcodeOrZip?: string | null | undefined;
172
198
  } | {
173
199
  type: string;
174
200
  option: string;
175
201
  filename: string;
176
202
  originalFilename: string;
177
- }[]> | undefined;
203
+ }[] | undefined> | undefined;
204
+ createdAtLocation?: string | undefined;
205
+ updatedAtLocation?: string | undefined;
206
+ originalActionId?: string | undefined;
178
207
  };
179
208
  }[];
180
209
  export declare function createEmptyDraft(eventId: string, draftId: string, actionType: ActionType): {
@@ -184,11 +213,21 @@ export declare function createEmptyDraft(eventId: string, draftId: string, actio
184
213
  transactionId: import("../uuid").UUID;
185
214
  action: {
186
215
  type: ActionType;
187
- data: {};
188
- metadata: {};
216
+ declaration: {};
217
+ annotation: {};
189
218
  createdAt: string;
190
219
  createdBy: string;
191
220
  createdAtLocation: string;
192
221
  };
193
222
  };
223
+ export declare function isVerificationPage(page: PageConfig): page is VerificationPageConfig;
224
+ export declare function deepMerge<T extends Record<string, unknown>>(currentDocument: T, actionDocument: T): T;
225
+ export declare function findLastAssignmentAction(actions: Action[]): Action | undefined;
226
+ /** Tell compiler that accessing record with arbitrary key might result to undefined
227
+ * Use when you **cannot guarantee** that key exists in the record
228
+ */
229
+ export type IndexMap<T> = {
230
+ [id: string]: T | undefined;
231
+ };
232
+ export declare function isWriteAction(actionType: ActionType): boolean;
194
233
  //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=utils.test.d.ts.map
@@ -23,8 +23,11 @@ __export(conditionals_exports, {
23
23
  alwaysTrue: () => alwaysTrue,
24
24
  and: () => and,
25
25
  defineConditional: () => defineConditional,
26
+ defineFormConditional: () => defineFormConditional,
26
27
  event: () => event,
28
+ eventField: () => eventField,
27
29
  field: () => field,
30
+ never: () => never,
28
31
  not: () => not,
29
32
  or: () => or,
30
33
  user: () => user
@@ -35,6 +38,16 @@ module.exports = __toCommonJS(conditionals_exports);
35
38
  function defineConditional(schema) {
36
39
  return schema;
37
40
  }
41
+ function defineFormConditional(schema) {
42
+ const schemaWithForm = {
43
+ type: "object",
44
+ properties: {
45
+ $form: schema
46
+ },
47
+ required: ["$form"]
48
+ };
49
+ return defineConditional(schemaWithForm);
50
+ }
38
51
  function alwaysTrue() {
39
52
  return {};
40
53
  }
@@ -59,6 +72,9 @@ function not(condition) {
59
72
  required: []
60
73
  });
61
74
  }
75
+ function never() {
76
+ return not(alwaysTrue());
77
+ }
62
78
  var user = {
63
79
  hasScope: (scope) => defineConditional({
64
80
  type: "object",
@@ -106,69 +122,120 @@ var event = {
106
122
  required: ["$event"]
107
123
  })
108
124
  };
125
+ function getDateFromNow(days) {
126
+ return new Date(Date.now() - days * 24 * 60 * 60 * 1e3).toISOString().split("T")[0];
127
+ }
128
+ function getDateRangeToFieldReference(fieldId, comparedFieldId, clause) {
129
+ return {
130
+ type: "object",
131
+ properties: {
132
+ [fieldId]: {
133
+ type: "string",
134
+ format: "date",
135
+ [clause]: { $data: `1/${comparedFieldId}` }
136
+ },
137
+ [comparedFieldId]: { type: "string", format: "date" }
138
+ },
139
+ required: [fieldId]
140
+ };
141
+ }
142
+ function isFieldReference(value) {
143
+ return typeof value === "object" && value !== null && "_fieldId" in value;
144
+ }
109
145
  function field(fieldId) {
110
- const getDateFromNow = (days) => new Date(Date.now() - days * 24 * 60 * 60 * 1e3).toISOString().split("T")[0];
111
146
  const getDateRange = (date, clause) => ({
112
147
  type: "object",
113
148
  properties: {
114
- $form: {
115
- type: "object",
116
- properties: {
117
- [fieldId]: {
118
- type: "string",
119
- format: "date",
120
- [clause]: date
121
- }
122
- },
123
- required: [fieldId]
149
+ [fieldId]: {
150
+ type: "string",
151
+ format: "date",
152
+ [clause]: date
124
153
  }
125
154
  },
126
- required: ["$form"]
155
+ required: [fieldId]
127
156
  });
128
157
  return {
158
+ /**
159
+ * @private Internal property used for field reference tracking.
160
+ */
161
+ _fieldId: fieldId,
129
162
  isAfter: () => ({
130
163
  days: (days) => ({
131
- inPast: () => defineConditional(
164
+ inPast: () => defineFormConditional(
132
165
  getDateRange(getDateFromNow(days), "formatMinimum")
133
166
  ),
134
- inFuture: () => defineConditional(
167
+ inFuture: () => defineFormConditional(
135
168
  getDateRange(getDateFromNow(-days), "formatMinimum")
136
169
  )
137
170
  }),
138
- date: (date) => defineConditional(getDateRange(date, "formatMinimum")),
139
- now: () => defineConditional(getDateRange(getDateFromNow(0), "formatMinimum"))
171
+ date: (date) => {
172
+ if (isFieldReference(date)) {
173
+ const comparedFieldId = date._fieldId;
174
+ return defineFormConditional(
175
+ getDateRangeToFieldReference(
176
+ fieldId,
177
+ comparedFieldId,
178
+ "formatMinimum"
179
+ )
180
+ );
181
+ }
182
+ return defineFormConditional(getDateRange(date, "formatMinimum"));
183
+ },
184
+ now: () => defineFormConditional(getDateRange(getDateFromNow(0), "formatMinimum"))
140
185
  }),
141
186
  isBefore: () => ({
142
187
  days: (days) => ({
143
- inPast: () => defineConditional(
188
+ inPast: () => defineFormConditional(
144
189
  getDateRange(getDateFromNow(days), "formatMaximum")
145
190
  ),
146
- inFuture: () => defineConditional(
191
+ inFuture: () => defineFormConditional(
147
192
  getDateRange(getDateFromNow(-days), "formatMaximum")
148
193
  )
149
194
  }),
150
- date: (date) => defineConditional(getDateRange(date, "formatMaximum")),
151
- now: () => defineConditional(getDateRange(getDateFromNow(0), "formatMaximum"))
195
+ date: (date) => {
196
+ if (isFieldReference(date)) {
197
+ const comparedFieldId = date._fieldId;
198
+ return defineFormConditional(
199
+ getDateRangeToFieldReference(
200
+ fieldId,
201
+ comparedFieldId,
202
+ "formatMaximum"
203
+ )
204
+ );
205
+ }
206
+ return defineFormConditional(getDateRange(date, "formatMaximum"));
207
+ },
208
+ now: () => defineFormConditional(getDateRange(getDateFromNow(0), "formatMaximum"))
152
209
  }),
153
- isEqualTo: (value) => defineConditional({
154
- type: "object",
155
- properties: {
156
- $form: {
210
+ isEqualTo: (value) => {
211
+ if (isFieldReference(value)) {
212
+ const comparedFieldId = value._fieldId;
213
+ return defineFormConditional({
157
214
  type: "object",
158
215
  properties: {
159
216
  [fieldId]: {
160
- oneOf: [
161
- { type: "string", const: value },
162
- { type: "boolean", const: value }
163
- ],
164
- const: value
165
- }
217
+ type: ["string", "boolean"],
218
+ const: { $data: `1/${comparedFieldId}` }
219
+ },
220
+ [comparedFieldId]: { type: ["string", "boolean"] }
166
221
  },
167
- required: [fieldId]
168
- }
169
- },
170
- required: ["$form"]
171
- }),
222
+ required: [fieldId, comparedFieldId]
223
+ });
224
+ }
225
+ return defineFormConditional({
226
+ type: "object",
227
+ properties: {
228
+ [fieldId]: {
229
+ oneOf: [
230
+ { type: "string", const: value },
231
+ { type: "boolean", const: value }
232
+ ],
233
+ const: value
234
+ }
235
+ },
236
+ required: [fieldId]
237
+ });
238
+ },
172
239
  /**
173
240
  * Use case: Some fields are rendered when selection is not made, or boolean false is explicitly selected.
174
241
  * @example field('recommender.none').isFalsy() vs not(field('recommender.none').isEqualTo(true))
@@ -177,68 +244,135 @@ function field(fieldId) {
177
244
  * NOTE: For now, this only works with string, boolean, and null types. 0 is still allowed.
178
245
  *
179
246
  */
180
- isFalsy: () => defineConditional({
247
+ isFalsy: () => defineFormConditional({
181
248
  type: "object",
182
249
  properties: {
183
- $form: {
184
- type: "object",
185
- properties: {
186
- [fieldId]: {
187
- anyOf: [
188
- { const: "undefined" },
189
- { const: false },
190
- { const: null },
191
- { const: "" }
192
- ]
193
- }
194
- },
250
+ [fieldId]: {
195
251
  anyOf: [
196
- {
197
- required: [fieldId]
198
- },
199
- {
200
- not: {
201
- required: [fieldId]
202
- }
203
- }
252
+ { const: "undefined" },
253
+ { const: false },
254
+ { const: null },
255
+ { const: "" }
204
256
  ]
205
257
  }
206
258
  },
207
- required: ["$form"]
208
- }),
209
- isUndefined: () => defineConditional({
210
- type: "object",
211
- properties: {
212
- $form: {
213
- type: "object",
214
- properties: {
215
- [fieldId]: {
216
- type: "string",
217
- enum: ["undefined"]
218
- }
219
- },
259
+ anyOf: [
260
+ {
261
+ required: [fieldId]
262
+ },
263
+ {
220
264
  not: {
221
265
  required: [fieldId]
222
266
  }
223
267
  }
268
+ ]
269
+ }),
270
+ isUndefined: () => defineFormConditional({
271
+ type: "object",
272
+ properties: {
273
+ [fieldId]: {
274
+ type: "string",
275
+ enum: ["undefined"]
276
+ }
224
277
  },
225
- required: ["$form"]
278
+ not: {
279
+ required: [fieldId]
280
+ }
226
281
  }),
227
- inArray: (values) => defineConditional({
282
+ inArray: (values) => defineFormConditional({
228
283
  type: "object",
229
284
  properties: {
230
- $form: {
231
- type: "object",
232
- properties: {
233
- [fieldId]: {
234
- type: "string",
235
- enum: values
236
- }
237
- },
238
- required: [fieldId]
285
+ [fieldId]: {
286
+ type: "string",
287
+ enum: values
288
+ }
289
+ },
290
+ required: [fieldId]
291
+ }),
292
+ isValidEnglishName: () => defineFormConditional({
293
+ type: "object",
294
+ properties: {
295
+ [fieldId]: {
296
+ type: "string",
297
+ pattern: "^[\\p{Script=Latin}0-9'._-]*(\\([\\p{Script=Latin}0-9'._-]+\\))?[\\p{Script=Latin}0-9'._-]*( [\\p{Script=Latin}0-9'._-]*(\\([\\p{Script=Latin}0-9'._-]+\\))?[\\p{Script=Latin}0-9'._-]*)*$",
298
+ description: "Name must contain only letters, numbers, and allowed special characters ('._-). No double spaces."
239
299
  }
240
300
  },
241
- required: ["$form"]
301
+ required: [fieldId]
302
+ }),
303
+ /**
304
+ * Checks if the field value matches a given regular expression pattern.
305
+ * @param pattern - The regular expression pattern to match the field value against.
306
+ * @returns A JSONSchema conditional that validates the field value against the pattern.
307
+ */
308
+ matches: (pattern) => defineFormConditional({
309
+ type: "object",
310
+ properties: {
311
+ [fieldId]: {
312
+ type: "string",
313
+ pattern
314
+ }
315
+ },
316
+ required: [fieldId]
317
+ }),
318
+ isBetween: (min, max) => defineFormConditional({
319
+ type: "object",
320
+ properties: {
321
+ [fieldId]: {
322
+ type: "number",
323
+ minimum: min,
324
+ maximum: max
325
+ }
326
+ },
327
+ required: [fieldId]
328
+ }),
329
+ /**
330
+ * Creates a range configuration for the specified field.
331
+ *
332
+ * @returns An object containing the field ID and a configuration object with a type of 'RANGE'.
333
+ *
334
+ * @example field('age').range()
335
+ * // {
336
+ * // fieldId: 'age',
337
+ * // config: { type: 'RANGE' }
338
+ * // }
339
+ */
340
+ range: () => ({
341
+ fieldId,
342
+ config: { type: "RANGE" }
343
+ }),
344
+ /**
345
+ * Creates a configuration for exact matching of the specified field.
346
+ * @returns An object containing the field ID and a configuration object with a type of 'EXACT'.
347
+ * @example field('dob').exact()
348
+ * // {
349
+ * // fieldId: 'dob',
350
+ * // config: { type: 'EXACT' }
351
+ * // }
352
+ */
353
+ exact: () => ({
354
+ fieldId,
355
+ config: { type: "EXACT" }
356
+ }),
357
+ /**
358
+ * Creates a configuration for fuzzy matching of the specified field.
359
+ * @returns An object containing the field ID and a configuration object with a type of 'EXACT'.
360
+ * @example field('name').fuzzy()
361
+ * // {
362
+ * // fieldId: 'name',
363
+ * // config: { type: 'FUZZY' }
364
+ * // }
365
+ */
366
+ fuzzy: () => ({
367
+ fieldId,
368
+ config: { type: "FUZZY" }
242
369
  })
243
370
  };
244
371
  }
372
+ function eventField(fieldId, options) {
373
+ return {
374
+ fieldId,
375
+ options,
376
+ config: { type: "EXACT" }
377
+ };
378
+ }