@opencrvs/toolkit 1.9.6-rc.ea8c258 → 1.9.6-rc.f165ddc

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.
@@ -10,10 +10,13 @@ declare const FuzzyMatcher: z.ZodObject<z.objectUtil.extendShape<{
10
10
  fieldId: z.ZodString;
11
11
  options: z.ZodDefault<z.ZodOptional<z.ZodObject<{
12
12
  boost: z.ZodOptional<z.ZodNumber>;
13
+ matchAgainst: z.ZodOptional<z.ZodString>;
13
14
  }, "strip", z.ZodTypeAny, {
14
15
  boost?: number | undefined;
16
+ matchAgainst?: string | undefined;
15
17
  }, {
16
18
  boost?: number | undefined;
19
+ matchAgainst?: string | undefined;
17
20
  }>>>;
18
21
  }, {
19
22
  type: z.ZodLiteral<"fuzzy">;
@@ -25,11 +28,14 @@ declare const FuzzyMatcher: z.ZodObject<z.objectUtil.extendShape<{
25
28
  */
26
29
  fuzziness: z.ZodDefault<z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodNumber]>>>;
27
30
  boost: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
31
+ matchAgainst: z.ZodOptional<z.ZodString>;
28
32
  }, "strip", z.ZodTypeAny, {
29
33
  boost: number;
30
34
  fuzziness: string | number;
35
+ matchAgainst?: string | undefined;
31
36
  }, {
32
37
  boost?: number | undefined;
38
+ matchAgainst?: string | undefined;
33
39
  fuzziness?: string | number | undefined;
34
40
  }>>>;
35
41
  }>, "strip", z.ZodTypeAny, {
@@ -37,6 +43,7 @@ declare const FuzzyMatcher: z.ZodObject<z.objectUtil.extendShape<{
37
43
  options: {
38
44
  boost: number;
39
45
  fuzziness: string | number;
46
+ matchAgainst?: string | undefined;
40
47
  };
41
48
  fieldId: string;
42
49
  }, {
@@ -44,6 +51,7 @@ declare const FuzzyMatcher: z.ZodObject<z.objectUtil.extendShape<{
44
51
  fieldId: string;
45
52
  options?: {
46
53
  boost?: number | undefined;
54
+ matchAgainst?: string | undefined;
47
55
  fuzziness?: string | number | undefined;
48
56
  } | undefined;
49
57
  }>;
@@ -58,10 +66,13 @@ declare const StrictMatcher: z.ZodObject<z.objectUtil.extendShape<{
58
66
  fieldId: z.ZodString;
59
67
  options: z.ZodDefault<z.ZodOptional<z.ZodObject<{
60
68
  boost: z.ZodOptional<z.ZodNumber>;
69
+ matchAgainst: z.ZodOptional<z.ZodString>;
61
70
  }, "strip", z.ZodTypeAny, {
62
71
  boost?: number | undefined;
72
+ matchAgainst?: string | undefined;
63
73
  }, {
64
74
  boost?: number | undefined;
75
+ matchAgainst?: string | undefined;
65
76
  }>>>;
66
77
  }, {
67
78
  type: z.ZodLiteral<"strict">;
@@ -71,18 +82,22 @@ declare const StrictMatcher: z.ZodObject<z.objectUtil.extendShape<{
71
82
  * The constant value to be present in the field for both records
72
83
  */
73
84
  value: z.ZodOptional<z.ZodString>;
85
+ matchAgainst: z.ZodOptional<z.ZodString>;
74
86
  }, "strip", z.ZodTypeAny, {
75
87
  boost: number;
76
88
  value?: string | undefined;
89
+ matchAgainst?: string | undefined;
77
90
  }, {
78
91
  value?: string | undefined;
79
92
  boost?: number | undefined;
93
+ matchAgainst?: string | undefined;
80
94
  }>>>;
81
95
  }>, "strip", z.ZodTypeAny, {
82
96
  type: "strict";
83
97
  options: {
84
98
  boost: number;
85
99
  value?: string | undefined;
100
+ matchAgainst?: string | undefined;
86
101
  };
87
102
  fieldId: string;
88
103
  }, {
@@ -91,6 +106,7 @@ declare const StrictMatcher: z.ZodObject<z.objectUtil.extendShape<{
91
106
  options?: {
92
107
  value?: string | undefined;
93
108
  boost?: number | undefined;
109
+ matchAgainst?: string | undefined;
94
110
  } | undefined;
95
111
  }>;
96
112
  export type StrictMatcherOptions = z.input<typeof StrictMatcher>['options'];
@@ -104,10 +120,13 @@ declare const DateRangeMatcher: z.ZodObject<z.objectUtil.extendShape<{
104
120
  fieldId: z.ZodString;
105
121
  options: z.ZodDefault<z.ZodOptional<z.ZodObject<{
106
122
  boost: z.ZodOptional<z.ZodNumber>;
123
+ matchAgainst: z.ZodOptional<z.ZodString>;
107
124
  }, "strip", z.ZodTypeAny, {
108
125
  boost?: number | undefined;
126
+ matchAgainst?: string | undefined;
109
127
  }, {
110
128
  boost?: number | undefined;
129
+ matchAgainst?: string | undefined;
111
130
  }>>>;
112
131
  }, {
113
132
  type: z.ZodLiteral<"dateRange">;
@@ -119,13 +138,16 @@ declare const DateRangeMatcher: z.ZodObject<z.objectUtil.extendShape<{
119
138
  pivot: z.ZodOptional<z.ZodNumber>;
120
139
  days: z.ZodNumber;
121
140
  boost: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
141
+ matchAgainst: z.ZodOptional<z.ZodString>;
122
142
  }, "strip", z.ZodTypeAny, {
123
143
  boost: number;
124
144
  days: number;
145
+ matchAgainst?: string | undefined;
125
146
  pivot?: number | undefined;
126
147
  }, {
127
148
  days: number;
128
149
  boost?: number | undefined;
150
+ matchAgainst?: string | undefined;
129
151
  pivot?: number | undefined;
130
152
  }>;
131
153
  }>, "strip", z.ZodTypeAny, {
@@ -133,6 +155,7 @@ declare const DateRangeMatcher: z.ZodObject<z.objectUtil.extendShape<{
133
155
  options: {
134
156
  boost: number;
135
157
  days: number;
158
+ matchAgainst?: string | undefined;
136
159
  pivot?: number | undefined;
137
160
  };
138
161
  fieldId: string;
@@ -141,6 +164,7 @@ declare const DateRangeMatcher: z.ZodObject<z.objectUtil.extendShape<{
141
164
  options: {
142
165
  days: number;
143
166
  boost?: number | undefined;
167
+ matchAgainst?: string | undefined;
144
168
  pivot?: number | undefined;
145
169
  };
146
170
  fieldId: string;
@@ -230,6 +230,15 @@ export declare function mapFieldTypeToZod(field: FieldConfig, actionType?: Actio
230
230
  }, {
231
231
  data?: any;
232
232
  }>>> | z.ZodObject<{
233
+ numericValue: z.ZodNumber;
234
+ unit: z.ZodString;
235
+ }, "strip", z.ZodTypeAny, {
236
+ numericValue: number;
237
+ unit: string;
238
+ }, {
239
+ numericValue: number;
240
+ unit: string;
241
+ }> | z.ZodObject<{
233
242
  numericValue: z.ZodOptional<z.ZodNumber>;
234
243
  unit: z.ZodOptional<z.ZodString>;
235
244
  }, "strip", z.ZodTypeAny, {
@@ -239,6 +248,15 @@ export declare function mapFieldTypeToZod(field: FieldConfig, actionType?: Actio
239
248
  numericValue?: number | undefined;
240
249
  unit?: string | undefined;
241
250
  }> | z.ZodOptional<z.ZodNullable<z.ZodObject<{
251
+ numericValue: z.ZodNumber;
252
+ unit: z.ZodString;
253
+ }, "strip", z.ZodTypeAny, {
254
+ numericValue: number;
255
+ unit: string;
256
+ }, {
257
+ numericValue: number;
258
+ unit: string;
259
+ }>>> | z.ZodOptional<z.ZodNullable<z.ZodObject<{
242
260
  numericValue: z.ZodOptional<z.ZodNumber>;
243
261
  unit: z.ZodOptional<z.ZodString>;
244
262
  }, "strip", z.ZodTypeAny, {
@@ -8,6 +8,7 @@ export declare function field(fieldId: string): {
8
8
  type: "fuzzy";
9
9
  options: {
10
10
  boost?: number | undefined;
11
+ matchAgainst?: string | undefined;
11
12
  fuzziness?: string | number | undefined;
12
13
  } | undefined;
13
14
  };
@@ -17,14 +18,57 @@ export declare function field(fieldId: string): {
17
18
  options: {
18
19
  value?: string | undefined;
19
20
  boost?: number | undefined;
21
+ matchAgainst?: string | undefined;
20
22
  } | undefined;
21
23
  };
24
+ /**
25
+ * Creates a date range matcher that finds records where date fields fall within a specified range.
26
+ *
27
+ * By default, matches against the field specified in `field()` (e.g., 'mother.dob').
28
+ * When `matchAgainst` is provided, it overwrites the default field and searches across multiple fields with OR logic .
29
+ *
30
+ * @param options - Configuration for the date range matching
31
+ * @param options.days - Number of days before and after the target date to search (creates a ±days range)
32
+ * @param options.pivot - Optional. Distance in days where relevance scoring drops by 50%. Defaults to ⌊(days * 2) / 3⌋
33
+ * @param options.boost - Optional. Scoring boost multiplier for matching results. Defaults to 1
34
+ * @param options.matchAgainst - Optional. Additional fields to match against. When provided,
35
+ * the query matches if any of these fields fall within the date range. The default field is always excluded in the search in that case.
36
+ * If you want to add the default field, you have to explicitly add that field in `matchAgainst` option
37
+ *
38
+ * @returns A clause that matches records where at least one of the specified date fields is within the range
39
+ *
40
+ * @example
41
+ * // Matches only against mother.dob (±365 days)
42
+ * field('mother.dob').dateRangeMatches({ days: 365 })
43
+ *
44
+ * @example
45
+ * // Matches against mother.age OR spouse.dob, not mother.dob
46
+ * field('mother.dob').dateRangeMatches({
47
+ * days: 365,
48
+ * matchAgainst: [$field('mother.age'), $field('spouse.dob')]
49
+ * })
50
+ *
51
+ * If you want to add mother.dob, then
52
+ * field('mother.dob').dateRangeMatches({
53
+ * days: 365,
54
+ * matchAgainst: [$field('mother.age'), $field('spouse.dob'), $field('mother.dob')]
55
+ * })
56
+ *
57
+ * @example
58
+ * // With custom pivot and boost
59
+ * field('mother.dob').dateRangeMatches({
60
+ * days: 730,
61
+ * pivot: 365,
62
+ * boost: 2
63
+ * })
64
+ */
22
65
  dateRangeMatches: (options: DateRangeMatcherOptions) => {
23
66
  fieldId: string;
24
67
  type: "dateRange";
25
68
  options: {
26
69
  days: number;
27
70
  boost?: number | undefined;
71
+ matchAgainst?: string | undefined;
28
72
  pivot?: number | undefined;
29
73
  };
30
74
  };
@@ -8,6 +8,7 @@ export declare function field(fieldId: string): {
8
8
  type: "fuzzy";
9
9
  options: {
10
10
  boost?: number | undefined;
11
+ matchAgainst?: string | undefined;
11
12
  fuzziness?: string | number | undefined;
12
13
  } | undefined;
13
14
  };
@@ -17,14 +18,57 @@ export declare function field(fieldId: string): {
17
18
  options: {
18
19
  value?: string | undefined;
19
20
  boost?: number | undefined;
21
+ matchAgainst?: string | undefined;
20
22
  } | undefined;
21
23
  };
24
+ /**
25
+ * Creates a date range matcher that finds records where date fields fall within a specified range.
26
+ *
27
+ * By default, matches against the field specified in `field()` (e.g., 'mother.dob').
28
+ * When `matchAgainst` is provided, it overwrites the default field and searches across multiple fields with OR logic .
29
+ *
30
+ * @param options - Configuration for the date range matching
31
+ * @param options.days - Number of days before and after the target date to search (creates a ±days range)
32
+ * @param options.pivot - Optional. Distance in days where relevance scoring drops by 50%. Defaults to ⌊(days * 2) / 3⌋
33
+ * @param options.boost - Optional. Scoring boost multiplier for matching results. Defaults to 1
34
+ * @param options.matchAgainst - Optional. Additional fields to match against. When provided,
35
+ * the query matches if any of these fields fall within the date range. The default field is always excluded in the search in that case.
36
+ * If you want to add the default field, you have to explicitly add that field in `matchAgainst` option
37
+ *
38
+ * @returns A clause that matches records where at least one of the specified date fields is within the range
39
+ *
40
+ * @example
41
+ * // Matches only against mother.dob (±365 days)
42
+ * field('mother.dob').dateRangeMatches({ days: 365 })
43
+ *
44
+ * @example
45
+ * // Matches against mother.age OR spouse.dob, not mother.dob
46
+ * field('mother.dob').dateRangeMatches({
47
+ * days: 365,
48
+ * matchAgainst: [$field('mother.age'), $field('spouse.dob')]
49
+ * })
50
+ *
51
+ * If you want to add mother.dob, then
52
+ * field('mother.dob').dateRangeMatches({
53
+ * days: 365,
54
+ * matchAgainst: [$field('mother.age'), $field('spouse.dob'), $field('mother.dob')]
55
+ * })
56
+ *
57
+ * @example
58
+ * // With custom pivot and boost
59
+ * field('mother.dob').dateRangeMatches({
60
+ * days: 730,
61
+ * pivot: 365,
62
+ * boost: 2
63
+ * })
64
+ */
22
65
  dateRangeMatches: (options: DateRangeMatcherOptions) => {
23
66
  fieldId: string;
24
67
  type: "dateRange";
25
68
  options: {
26
69
  days: number;
27
70
  boost?: number | undefined;
71
+ matchAgainst?: string | undefined;
28
72
  pivot?: number | undefined;
29
73
  };
30
74
  };
@@ -58,6 +58,47 @@ function field(fieldId) {
58
58
  type: "strict",
59
59
  options
60
60
  }),
61
+ /**
62
+ * Creates a date range matcher that finds records where date fields fall within a specified range.
63
+ *
64
+ * By default, matches against the field specified in `field()` (e.g., 'mother.dob').
65
+ * When `matchAgainst` is provided, it overwrites the default field and searches across multiple fields with OR logic .
66
+ *
67
+ * @param options - Configuration for the date range matching
68
+ * @param options.days - Number of days before and after the target date to search (creates a ±days range)
69
+ * @param options.pivot - Optional. Distance in days where relevance scoring drops by 50%. Defaults to ⌊(days * 2) / 3⌋
70
+ * @param options.boost - Optional. Scoring boost multiplier for matching results. Defaults to 1
71
+ * @param options.matchAgainst - Optional. Additional fields to match against. When provided,
72
+ * the query matches if any of these fields fall within the date range. The default field is always excluded in the search in that case.
73
+ * If you want to add the default field, you have to explicitly add that field in `matchAgainst` option
74
+ *
75
+ * @returns A clause that matches records where at least one of the specified date fields is within the range
76
+ *
77
+ * @example
78
+ * // Matches only against mother.dob (±365 days)
79
+ * field('mother.dob').dateRangeMatches({ days: 365 })
80
+ *
81
+ * @example
82
+ * // Matches against mother.age OR spouse.dob, not mother.dob
83
+ * field('mother.dob').dateRangeMatches({
84
+ * days: 365,
85
+ * matchAgainst: [$field('mother.age'), $field('spouse.dob')]
86
+ * })
87
+ *
88
+ * If you want to add mother.dob, then
89
+ * field('mother.dob').dateRangeMatches({
90
+ * days: 365,
91
+ * matchAgainst: [$field('mother.age'), $field('spouse.dob'), $field('mother.dob')]
92
+ * })
93
+ *
94
+ * @example
95
+ * // With custom pivot and boost
96
+ * field('mother.dob').dateRangeMatches({
97
+ * days: 730,
98
+ * pivot: 365,
99
+ * boost: 2
100
+ * })
101
+ */
61
102
  dateRangeMatches: (options) => ({
62
103
  fieldId,
63
104
  type: "dateRange",
@@ -2557,7 +2557,8 @@ var Matcher = import_zod19.z.object({
2557
2557
  */
2558
2558
  fieldId: FieldReference2,
2559
2559
  options: import_zod19.z.object({
2560
- boost: import_zod19.z.number().optional()
2560
+ boost: import_zod19.z.number().optional(),
2561
+ matchAgainst: FieldReference2.optional()
2561
2562
  }).optional().default({
2562
2563
  boost: 1
2563
2564
  })
@@ -2571,7 +2572,8 @@ var FuzzyMatcher = Matcher.extend({
2571
2572
  * Names of length >7 characters = 2 edits allowed
2572
2573
  */
2573
2574
  fuzziness: import_zod19.z.union([import_zod19.z.string(), import_zod19.z.number()]).optional().default("AUTO:4,7"),
2574
- boost: import_zod19.z.number().optional().default(1)
2575
+ boost: import_zod19.z.number().optional().default(1),
2576
+ matchAgainst: FieldReference2.optional()
2575
2577
  }).optional().default({
2576
2578
  fuzziness: "AUTO:4,7",
2577
2579
  boost: 1
@@ -2584,7 +2586,8 @@ var StrictMatcher = Matcher.extend({
2584
2586
  /**
2585
2587
  * The constant value to be present in the field for both records
2586
2588
  */
2587
- value: import_zod19.z.string().optional()
2589
+ value: import_zod19.z.string().optional(),
2590
+ matchAgainst: FieldReference2.optional()
2588
2591
  }).optional().default({
2589
2592
  boost: 1
2590
2593
  })
@@ -2598,7 +2601,8 @@ var DateRangeMatcher = Matcher.extend({
2598
2601
  */
2599
2602
  pivot: import_zod19.z.number().optional(),
2600
2603
  days: import_zod19.z.number(),
2601
- boost: import_zod19.z.number().optional().default(1)
2604
+ boost: import_zod19.z.number().optional().default(1),
2605
+ matchAgainst: FieldReference2.optional()
2602
2606
  })
2603
2607
  });
2604
2608
  var Not = import_zod19.z.object({
@@ -3009,7 +3013,7 @@ function mapFieldTypeToZod(field3, actionType) {
3009
3013
  schema = NumberFieldValue;
3010
3014
  break;
3011
3015
  case FieldType.NUMBER_WITH_UNIT:
3012
- schema = NumberWithUnitFieldUpdateValue;
3016
+ schema = field3.required ? NumberWithUnitFieldValue : NumberWithUnitFieldUpdateValue;
3013
3017
  break;
3014
3018
  case FieldType.CHECKBOX:
3015
3019
  schema = CheckboxFieldValue;
@@ -3400,7 +3404,7 @@ function isFieldVisible(field3, form, context) {
3400
3404
  }
3401
3405
  function isFieldEmptyAndNotRequired(field3, form) {
3402
3406
  const fieldValue = form[field3.id];
3403
- return !field3.required && (fieldValue === void 0 || fieldValue === "");
3407
+ return !field3.required && (fieldValue === void 0 || fieldValue === "" || fieldValue && typeof fieldValue === "object" && Object.values(fieldValue).every((v) => v === void 0 || v === ""));
3404
3408
  }
3405
3409
  function isFieldEnabled(field3, form, context) {
3406
3410
  return isFieldConditionMet(field3, form, ConditionalType.ENABLE, context);
@@ -7813,8 +7817,35 @@ var mother = defineFormPage({
7813
7817
  secured: true,
7814
7818
  validation: [],
7815
7819
  label: generateTranslationConfig("Date of birth"),
7820
+ conditionals: [
7821
+ {
7822
+ type: "SHOW",
7823
+ conditional: not(field("mother.dobUnknown").isEqualTo(true))
7824
+ }
7825
+ ]
7826
+ },
7827
+ {
7828
+ id: "mother.dobUnknown",
7829
+ type: "CHECKBOX",
7830
+ label: generateTranslationConfig("Exact date of birth unknown"),
7816
7831
  conditionals: []
7817
7832
  },
7833
+ {
7834
+ id: "mother.age",
7835
+ type: FieldType.AGE,
7836
+ required: true,
7837
+ analytics: true,
7838
+ label: generateTranslationConfig("Age of mother"),
7839
+ configuration: {
7840
+ asOfDate: field("child.dob")
7841
+ },
7842
+ conditionals: [
7843
+ {
7844
+ type: "SHOW",
7845
+ conditional: field("mother.dobUnknown").isEqualTo(true)
7846
+ }
7847
+ ]
7848
+ },
7818
7849
  {
7819
7850
  id: "mother.idType",
7820
7851
  type: FieldType.SELECT,
@@ -2079,7 +2079,8 @@ var Matcher = import_zod19.z.object({
2079
2079
  */
2080
2080
  fieldId: FieldReference2,
2081
2081
  options: import_zod19.z.object({
2082
- boost: import_zod19.z.number().optional()
2082
+ boost: import_zod19.z.number().optional(),
2083
+ matchAgainst: FieldReference2.optional()
2083
2084
  }).optional().default({
2084
2085
  boost: 1
2085
2086
  })
@@ -2093,7 +2094,8 @@ var FuzzyMatcher = Matcher.extend({
2093
2094
  * Names of length >7 characters = 2 edits allowed
2094
2095
  */
2095
2096
  fuzziness: import_zod19.z.union([import_zod19.z.string(), import_zod19.z.number()]).optional().default("AUTO:4,7"),
2096
- boost: import_zod19.z.number().optional().default(1)
2097
+ boost: import_zod19.z.number().optional().default(1),
2098
+ matchAgainst: FieldReference2.optional()
2097
2099
  }).optional().default({
2098
2100
  fuzziness: "AUTO:4,7",
2099
2101
  boost: 1
@@ -2106,7 +2108,8 @@ var StrictMatcher = Matcher.extend({
2106
2108
  /**
2107
2109
  * The constant value to be present in the field for both records
2108
2110
  */
2109
- value: import_zod19.z.string().optional()
2111
+ value: import_zod19.z.string().optional(),
2112
+ matchAgainst: FieldReference2.optional()
2110
2113
  }).optional().default({
2111
2114
  boost: 1
2112
2115
  })
@@ -2120,7 +2123,8 @@ var DateRangeMatcher = Matcher.extend({
2120
2123
  */
2121
2124
  pivot: import_zod19.z.number().optional(),
2122
2125
  days: import_zod19.z.number(),
2123
- boost: import_zod19.z.number().optional().default(1)
2126
+ boost: import_zod19.z.number().optional().default(1),
2127
+ matchAgainst: FieldReference2.optional()
2124
2128
  })
2125
2129
  });
2126
2130
  var Not = import_zod19.z.object({
@@ -6066,8 +6070,35 @@ var mother = defineFormPage({
6066
6070
  secured: true,
6067
6071
  validation: [],
6068
6072
  label: generateTranslationConfig("Date of birth"),
6073
+ conditionals: [
6074
+ {
6075
+ type: "SHOW",
6076
+ conditional: not(field("mother.dobUnknown").isEqualTo(true))
6077
+ }
6078
+ ]
6079
+ },
6080
+ {
6081
+ id: "mother.dobUnknown",
6082
+ type: "CHECKBOX",
6083
+ label: generateTranslationConfig("Exact date of birth unknown"),
6069
6084
  conditionals: []
6070
6085
  },
6086
+ {
6087
+ id: "mother.age",
6088
+ type: FieldType.AGE,
6089
+ required: true,
6090
+ analytics: true,
6091
+ label: generateTranslationConfig("Age of mother"),
6092
+ configuration: {
6093
+ asOfDate: field("child.dob")
6094
+ },
6095
+ conditionals: [
6096
+ {
6097
+ type: "SHOW",
6098
+ conditional: field("mother.dobUnknown").isEqualTo(true)
6099
+ }
6100
+ ]
6101
+ },
6071
6102
  {
6072
6103
  id: "mother.idType",
6073
6104
  type: FieldType.SELECT,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opencrvs/toolkit",
3
- "version": "1.9.6-rc.ea8c258",
3
+ "version": "1.9.6-rc.f165ddc",
4
4
  "description": "OpenCRVS toolkit for building country configurations",
5
5
  "license": "MPL-2.0",
6
6
  "exports": {