@opencrvs/toolkit 1.8.0-rc.f7910f3 → 1.8.0-rc.f876361

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.
@@ -126,6 +126,10 @@ function field(fieldId) {
126
126
  required: ["$form"]
127
127
  });
128
128
  return {
129
+ /**
130
+ * @private Internal property used for field reference tracking.
131
+ */
132
+ _returning: fieldId,
129
133
  isAfter: () => ({
130
134
  days: (days) => ({
131
135
  inPast: () => defineConditional(
@@ -150,25 +154,54 @@ function field(fieldId) {
150
154
  date: (date) => defineConditional(getDateRange(date, "formatMaximum")),
151
155
  now: () => defineConditional(getDateRange(getDateFromNow(0), "formatMaximum"))
152
156
  }),
153
- isEqualTo: (value) => defineConditional({
154
- type: "object",
155
- properties: {
156
- $form: {
157
+ // TODO CIHAN: typing
158
+ isEqualTo: (value) => {
159
+ if (typeof value === "object" && value._returning) {
160
+ const comparedFieldId = value._returning;
161
+ return defineConditional({
157
162
  type: "object",
158
163
  properties: {
159
- [fieldId]: {
160
- oneOf: [
161
- { type: "string", const: value },
162
- { type: "boolean", const: value }
163
- ],
164
- const: value
164
+ $form: {
165
+ type: "object",
166
+ properties: {
167
+ [fieldId]: { type: ["string", "boolean"] },
168
+ [comparedFieldId]: { type: ["string", "boolean"] }
169
+ },
170
+ required: [fieldId, comparedFieldId],
171
+ allOf: [
172
+ {
173
+ properties: {
174
+ [fieldId]: {
175
+ const: { $data: `1/${comparedFieldId}` }
176
+ }
177
+ }
178
+ }
179
+ ]
165
180
  }
166
181
  },
167
- required: [fieldId]
168
- }
169
- },
170
- required: ["$form"]
171
- }),
182
+ required: ["$form"]
183
+ });
184
+ }
185
+ return defineConditional({
186
+ type: "object",
187
+ properties: {
188
+ $form: {
189
+ type: "object",
190
+ properties: {
191
+ [fieldId]: {
192
+ oneOf: [
193
+ { type: "string", const: value },
194
+ { type: "boolean", const: value }
195
+ ],
196
+ const: value
197
+ }
198
+ },
199
+ required: [fieldId]
200
+ }
201
+ },
202
+ required: ["$form"]
203
+ });
204
+ },
172
205
  /**
173
206
  * Use case: Some fields are rendered when selection is not made, or boolean false is explicitly selected.
174
207
  * @example field('recommender.none').isFalsy() vs not(field('recommender.none').isEqualTo(true))
@@ -256,6 +289,61 @@ function field(fieldId) {
256
289
  }
257
290
  },
258
291
  required: ["$form"]
292
+ }),
293
+ isValidNationalId: () => defineConditional({
294
+ type: "object",
295
+ properties: {
296
+ $form: {
297
+ type: "object",
298
+ properties: {
299
+ [fieldId]: {
300
+ type: "string",
301
+ pattern: "^[0-9]{9}$",
302
+ description: "The National ID can only be numeric and must be 9 digits long."
303
+ }
304
+ },
305
+ required: [fieldId]
306
+ }
307
+ },
308
+ required: ["$form"]
309
+ }),
310
+ /**
311
+ * Checks if the field value matches a given regular expression pattern.
312
+ * @param pattern - The regular expression pattern to match the field value against.
313
+ * @returns A JSONSchema conditional that validates the field value against the pattern.
314
+ */
315
+ matches: (pattern) => defineConditional({
316
+ type: "object",
317
+ properties: {
318
+ $form: {
319
+ type: "object",
320
+ properties: {
321
+ [fieldId]: {
322
+ type: "string",
323
+ pattern
324
+ }
325
+ },
326
+ required: [fieldId]
327
+ }
328
+ },
329
+ required: ["$form"]
330
+ }),
331
+ isBetween: (min, max) => defineConditional({
332
+ type: "object",
333
+ properties: {
334
+ $form: {
335
+ type: "object",
336
+ properties: {
337
+ [fieldId]: {
338
+ type: "number",
339
+ minimum: min,
340
+ maximum: max
341
+ }
342
+ },
343
+ required: [fieldId]
344
+ }
345
+ },
346
+ required: ["$form"]
259
347
  })
260
348
  };
261
349
  }