@opencrvs/toolkit 1.9.6-rc.690a282 → 1.9.6-rc.6ae1b5a

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.
@@ -119,14 +119,32 @@ declare const DateRangeMatcher: z.ZodObject<z.objectUtil.extendShape<{
119
119
  pivot: z.ZodOptional<z.ZodNumber>;
120
120
  days: z.ZodNumber;
121
121
  boost: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
122
+ matchAgainst: z.ZodOptional<z.ZodArray<z.ZodObject<{
123
+ $$field: z.ZodEffects<z.ZodString, string, string>;
124
+ $$subfield: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
125
+ }, "strip", z.ZodTypeAny, {
126
+ $$field: string;
127
+ $$subfield?: string[] | undefined;
128
+ }, {
129
+ $$field: string;
130
+ $$subfield?: string[] | undefined;
131
+ }>, "many">>;
122
132
  }, "strip", z.ZodTypeAny, {
123
133
  boost: number;
124
134
  days: number;
125
135
  pivot?: number | undefined;
136
+ matchAgainst?: {
137
+ $$field: string;
138
+ $$subfield?: string[] | undefined;
139
+ }[] | undefined;
126
140
  }, {
127
141
  days: number;
128
142
  boost?: number | undefined;
129
143
  pivot?: number | undefined;
144
+ matchAgainst?: {
145
+ $$field: string;
146
+ $$subfield?: string[] | undefined;
147
+ }[] | undefined;
130
148
  }>;
131
149
  }>, "strip", z.ZodTypeAny, {
132
150
  type: "dateRange";
@@ -134,6 +152,10 @@ declare const DateRangeMatcher: z.ZodObject<z.objectUtil.extendShape<{
134
152
  boost: number;
135
153
  days: number;
136
154
  pivot?: number | undefined;
155
+ matchAgainst?: {
156
+ $$field: string;
157
+ $$subfield?: string[] | undefined;
158
+ }[] | undefined;
137
159
  };
138
160
  fieldId: string;
139
161
  }, {
@@ -142,6 +164,10 @@ declare const DateRangeMatcher: z.ZodObject<z.objectUtil.extendShape<{
142
164
  days: number;
143
165
  boost?: number | undefined;
144
166
  pivot?: number | undefined;
167
+ matchAgainst?: {
168
+ $$field: string;
169
+ $$subfield?: string[] | undefined;
170
+ }[] | undefined;
145
171
  };
146
172
  fieldId: string;
147
173
  }>;
@@ -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<{
@@ -19,6 +19,47 @@ export declare function field(fieldId: string): {
19
19
  boost?: number | undefined;
20
20
  } | undefined;
21
21
  };
22
+ /**
23
+ * Creates a date range matcher that finds records where date fields fall within a specified range.
24
+ *
25
+ * By default, matches against the field specified in `field()` (e.g., 'mother.dob').
26
+ * When `matchAgainst` is provided, it overwrites the default field and searches across multiple fields with OR logic .
27
+ *
28
+ * @param options - Configuration for the date range matching
29
+ * @param options.days - Number of days before and after the target date to search (creates a ±days range)
30
+ * @param options.pivot - Optional. Distance in days where relevance scoring drops by 50%. Defaults to ⌊(days * 2) / 3⌋
31
+ * @param options.boost - Optional. Scoring boost multiplier for matching results. Defaults to 1
32
+ * @param options.matchAgainst - Optional. Additional fields to match against. When provided,
33
+ * 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.
34
+ * If you want to add the default field, you have to explicitly add that field in `matchAgainst` option
35
+ *
36
+ * @returns A clause that matches records where at least one of the specified date fields is within the range
37
+ *
38
+ * @example
39
+ * // Matches only against mother.dob (±365 days)
40
+ * field('mother.dob').dateRangeMatches({ days: 365 })
41
+ *
42
+ * @example
43
+ * // Matches against mother.age OR spouse.dob, not mother.dob
44
+ * field('mother.dob').dateRangeMatches({
45
+ * days: 365,
46
+ * matchAgainst: [$field('mother.age'), $field('spouse.dob')]
47
+ * })
48
+ *
49
+ * If you want to add mother.dob, then
50
+ * field('mother.dob').dateRangeMatches({
51
+ * days: 365,
52
+ * matchAgainst: [$field('mother.age'), $field('spouse.dob'), $field('mother.dob')]
53
+ * })
54
+ *
55
+ * @example
56
+ * // With custom pivot and boost
57
+ * field('mother.dob').dateRangeMatches({
58
+ * days: 730,
59
+ * pivot: 365,
60
+ * boost: 2
61
+ * })
62
+ */
22
63
  dateRangeMatches: (options: DateRangeMatcherOptions) => {
23
64
  fieldId: string;
24
65
  type: "dateRange";
@@ -26,6 +67,10 @@ export declare function field(fieldId: string): {
26
67
  days: number;
27
68
  boost?: number | undefined;
28
69
  pivot?: number | undefined;
70
+ matchAgainst?: {
71
+ $$field: string;
72
+ $$subfield?: string[] | undefined;
73
+ }[] | undefined;
29
74
  };
30
75
  };
31
76
  };
@@ -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",
@@ -19,6 +19,47 @@ export declare function field(fieldId: string): {
19
19
  boost?: number | undefined;
20
20
  } | undefined;
21
21
  };
22
+ /**
23
+ * Creates a date range matcher that finds records where date fields fall within a specified range.
24
+ *
25
+ * By default, matches against the field specified in `field()` (e.g., 'mother.dob').
26
+ * When `matchAgainst` is provided, it overwrites the default field and searches across multiple fields with OR logic .
27
+ *
28
+ * @param options - Configuration for the date range matching
29
+ * @param options.days - Number of days before and after the target date to search (creates a ±days range)
30
+ * @param options.pivot - Optional. Distance in days where relevance scoring drops by 50%. Defaults to ⌊(days * 2) / 3⌋
31
+ * @param options.boost - Optional. Scoring boost multiplier for matching results. Defaults to 1
32
+ * @param options.matchAgainst - Optional. Additional fields to match against. When provided,
33
+ * 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.
34
+ * If you want to add the default field, you have to explicitly add that field in `matchAgainst` option
35
+ *
36
+ * @returns A clause that matches records where at least one of the specified date fields is within the range
37
+ *
38
+ * @example
39
+ * // Matches only against mother.dob (±365 days)
40
+ * field('mother.dob').dateRangeMatches({ days: 365 })
41
+ *
42
+ * @example
43
+ * // Matches against mother.age OR spouse.dob, not mother.dob
44
+ * field('mother.dob').dateRangeMatches({
45
+ * days: 365,
46
+ * matchAgainst: [$field('mother.age'), $field('spouse.dob')]
47
+ * })
48
+ *
49
+ * If you want to add mother.dob, then
50
+ * field('mother.dob').dateRangeMatches({
51
+ * days: 365,
52
+ * matchAgainst: [$field('mother.age'), $field('spouse.dob'), $field('mother.dob')]
53
+ * })
54
+ *
55
+ * @example
56
+ * // With custom pivot and boost
57
+ * field('mother.dob').dateRangeMatches({
58
+ * days: 730,
59
+ * pivot: 365,
60
+ * boost: 2
61
+ * })
62
+ */
22
63
  dateRangeMatches: (options: DateRangeMatcherOptions) => {
23
64
  fieldId: string;
24
65
  type: "dateRange";
@@ -26,6 +67,10 @@ export declare function field(fieldId: string): {
26
67
  days: number;
27
68
  boost?: number | undefined;
28
69
  pivot?: number | undefined;
70
+ matchAgainst?: {
71
+ $$field: string;
72
+ $$subfield?: string[] | undefined;
73
+ }[] | undefined;
29
74
  };
30
75
  };
31
76
  };
@@ -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",