@opencrvs/toolkit 1.9.6-rc.92becff → 1.9.6-rc.9a9f99f

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.
@@ -4,6 +4,7 @@ import { ITokenPayload as TokenPayload, Scope } from '../authentication';
4
4
  import { PartialSchema as AjvJSONSchemaType } from 'ajv/dist/types/json-schema';
5
5
  import { userSerializer } from '../events/serializers/user/serializer';
6
6
  import { UUID } from '../uuid';
7
+ import { todayDateTimeValueSerializer } from '../events/serializers/date/serializer';
7
8
  /** @knipignore */
8
9
  export type JSONSchema = {
9
10
  $id: string;
@@ -64,6 +65,10 @@ type FieldReference = {
64
65
  $$field: string;
65
66
  $$subfield: string[];
66
67
  };
68
+ /**
69
+ * Generate conditional rules for current date
70
+ */
71
+ export declare const now: typeof todayDateTimeValueSerializer;
67
72
  /**
68
73
  *
69
74
  * Generate conditional rules for user.
@@ -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;
@@ -1768,7 +1768,13 @@ declare const DateField: z.ZodObject<z.objectUtil.extendShape<{
1768
1768
  analytics: z.ZodOptional<z.ZodDefault<z.ZodBoolean>>;
1769
1769
  }, {
1770
1770
  type: z.ZodLiteral<"DATE">;
1771
- defaultValue: z.ZodOptional<z.ZodString>;
1771
+ defaultValue: z.ZodOptional<z.ZodUnion<[z.ZodObject<{
1772
+ $$now: z.ZodLiteral<true>;
1773
+ }, "strip", z.ZodTypeAny, {
1774
+ $$now: true;
1775
+ }, {
1776
+ $$now: true;
1777
+ }>, z.ZodString]>>;
1772
1778
  configuration: z.ZodOptional<z.ZodObject<{
1773
1779
  notice: z.ZodOptional<z.ZodObject<import("./TranslationConfig").MessageDescriptorZod, "strip", z.ZodTypeAny, TranslationConfig, {
1774
1780
  id: string;
@@ -1825,7 +1831,9 @@ declare const DateField: z.ZodObject<z.objectUtil.extendShape<{
1825
1831
  hideLabel?: boolean | undefined;
1826
1832
  uncorrectable?: boolean | undefined;
1827
1833
  analytics?: boolean | undefined;
1828
- defaultValue?: string | undefined;
1834
+ defaultValue?: string | {
1835
+ $$now: true;
1836
+ } | undefined;
1829
1837
  configuration?: {
1830
1838
  notice?: TranslationConfig | undefined;
1831
1839
  } | undefined;
@@ -1890,7 +1898,9 @@ declare const DateField: z.ZodObject<z.objectUtil.extendShape<{
1890
1898
  hideLabel?: boolean | undefined;
1891
1899
  uncorrectable?: boolean | undefined;
1892
1900
  analytics?: boolean | undefined;
1893
- defaultValue?: string | undefined;
1901
+ defaultValue?: string | {
1902
+ $$now: true;
1903
+ } | undefined;
1894
1904
  configuration?: {
1895
1905
  notice?: {
1896
1906
  id: string;
@@ -2265,7 +2275,13 @@ declare const TimeField: z.ZodObject<z.objectUtil.extendShape<{
2265
2275
  analytics: z.ZodOptional<z.ZodDefault<z.ZodBoolean>>;
2266
2276
  }, {
2267
2277
  type: z.ZodLiteral<"TIME">;
2268
- defaultValue: z.ZodOptional<z.ZodString>;
2278
+ defaultValue: z.ZodOptional<z.ZodUnion<[z.ZodObject<{
2279
+ $$now: z.ZodLiteral<true>;
2280
+ }, "strip", z.ZodTypeAny, {
2281
+ $$now: true;
2282
+ }, {
2283
+ $$now: true;
2284
+ }>, z.ZodString]>>;
2269
2285
  configuration: z.ZodOptional<z.ZodObject<{
2270
2286
  use12HourFormat: z.ZodOptional<z.ZodBoolean>;
2271
2287
  notice: z.ZodOptional<z.ZodObject<import("./TranslationConfig").MessageDescriptorZod, "strip", z.ZodTypeAny, TranslationConfig, {
@@ -2325,7 +2341,9 @@ declare const TimeField: z.ZodObject<z.objectUtil.extendShape<{
2325
2341
  hideLabel?: boolean | undefined;
2326
2342
  uncorrectable?: boolean | undefined;
2327
2343
  analytics?: boolean | undefined;
2328
- defaultValue?: string | undefined;
2344
+ defaultValue?: string | {
2345
+ $$now: true;
2346
+ } | undefined;
2329
2347
  configuration?: {
2330
2348
  notice?: TranslationConfig | undefined;
2331
2349
  use12HourFormat?: boolean | undefined;
@@ -2391,7 +2409,9 @@ declare const TimeField: z.ZodObject<z.objectUtil.extendShape<{
2391
2409
  hideLabel?: boolean | undefined;
2392
2410
  uncorrectable?: boolean | undefined;
2393
2411
  analytics?: boolean | undefined;
2394
- defaultValue?: string | undefined;
2412
+ defaultValue?: string | {
2413
+ $$now: true;
2414
+ } | undefined;
2395
2415
  configuration?: {
2396
2416
  notice?: {
2397
2417
  id: 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, {
@@ -38,6 +38,7 @@ export declare const AgeUpdateValue: z.ZodNullable<z.ZodOptional<z.ZodObject<{
38
38
  asOfDateRef: string;
39
39
  }>>>;
40
40
  export declare const TimeValue: z.ZodString;
41
+ export type TimeValue = z.infer<typeof TimeValue>;
41
42
  export declare const DatetimeValue: z.ZodString;
42
43
  export declare const SelectDateRangeValue: z.ZodEnum<["last7Days", "last30Days", "last90Days", "last365Days"]>;
43
44
  export declare const DateRangeFieldValue: z.ZodUnion<[z.ZodObject<{
@@ -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
  };
@@ -38,6 +38,7 @@ __export(conditionals_exports, {
38
38
  isFieldReference: () => isFieldReference,
39
39
  never: () => never,
40
40
  not: () => not,
41
+ now: () => now,
41
42
  or: () => or,
42
43
  user: () => user
43
44
  });
@@ -106,6 +107,15 @@ function omitKeyDeep(obj, keyToRemove) {
106
107
  return newObj;
107
108
  }
108
109
 
110
+ // ../commons/src/events/serializers/date/serializer.ts
111
+ var import_zod2 = require("zod");
112
+ var SerializedNowDateTime = import_zod2.z.object({
113
+ $$now: import_zod2.z.literal(true)
114
+ });
115
+ function todayDateTimeValueSerializer() {
116
+ return { $$now: true };
117
+ }
118
+
109
119
  // ../commons/src/conditionals/conditionals.ts
110
120
  function defineConditional(schema) {
111
121
  const schemaWithooutIDRef = omitKeyDeep(schema, "$id");
@@ -179,6 +189,7 @@ function wrapToPathOptional(condition, path) {
179
189
  };
180
190
  }, condition);
181
191
  }
192
+ var now = Object.assign(todayDateTimeValueSerializer, {});
182
193
  var user = Object.assign(userSerializer, {
183
194
  hasScope: (scope) => defineConditional({
184
195
  type: "object",
@@ -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",