@opencrvs/toolkit 1.9.13-rc.56b7f8b → 1.9.13-rc.59bb028

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.
@@ -5,7 +5,7 @@ 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
7
  import { todayDateTimeValueSerializer } from '../events/serializers/date/serializer';
8
- import { FieldReference } from '../events/FieldConfig';
8
+ import { CodeToEvaluate, FieldReference } from '../events/FieldConfig';
9
9
  /** @knipignore */
10
10
  export type JSONSchema = {
11
11
  $id: string;
@@ -82,6 +82,11 @@ export declare const user: typeof userSerializer & {
82
82
  };
83
83
  export declare function isFieldReference(value: unknown): value is FieldReference;
84
84
  export declare function isEventFieldReference(value: unknown): value is FieldReference;
85
+ /**
86
+ * Centralised guard so a future third reference type only needs to be added here
87
+ * and in {@link parseFieldReferenceToValue}, not at every call site.
88
+ */
89
+ export declare function isResolvableValueReference(value: unknown): value is FieldReference | CodeToEvaluate;
85
90
  /**
86
91
  * Generate conditional rules for a form field.
87
92
  *
@@ -172,6 +177,32 @@ export declare function createFieldConditionals(fieldId: string): {
172
177
  * )
173
178
  */
174
179
  object: (options: Record<string, any>) => JSONSchema;
180
+ /**
181
+ * Custom client-side validator. The provided function is serialised and executed
182
+ * just-in-time on the client only. External references (e.g. lodash) are not
183
+ * available inside the function body — all logic must be self-contained.
184
+ *
185
+ * @example
186
+ * field('nid').customClientValidator((value) => {
187
+ * // LUHN check — all logic must be inline
188
+ * const digits = String(value).split('').map(Number)
189
+ * // ...
190
+ * return isValid
191
+ * })
192
+ */
193
+ customClientValidator(validationFn: (fieldValue: unknown, context: FormConditionalParameters) => boolean): JSONSchema;
194
+ /**
195
+ * Custom client-side evaluation. Returns a {@link CodeToEvaluate} descriptor
196
+ * that can be used as `value`, `evaluatedDefaultValue`, or a DATA component entry.
197
+ * The function is serialised and executed just-in-time on the client only.
198
+ * External references (e.g. lodash) are not available inside the function body.
199
+ *
200
+ * @example
201
+ * field('a').customClientEvaluation((aValue, ctx) =>
202
+ * Number(aValue) + Number(ctx.$form.b)
203
+ * )
204
+ */
205
+ customClientEvaluation(computationFn: (fieldValue: unknown, context: FormConditionalParameters) => unknown): CodeToEvaluate;
175
206
  };
176
207
  asDob(): any;
177
208
  asAge(): any;
@@ -231,6 +262,32 @@ export declare function createFieldConditionals(fieldId: string): {
231
262
  * )
232
263
  */
233
264
  object: (options: Record<string, any>) => JSONSchema;
265
+ /**
266
+ * Custom client-side validator. The provided function is serialised and executed
267
+ * just-in-time on the client only. External references (e.g. lodash) are not
268
+ * available inside the function body — all logic must be self-contained.
269
+ *
270
+ * @example
271
+ * field('nid').customClientValidator((value) => {
272
+ * // LUHN check — all logic must be inline
273
+ * const digits = String(value).split('').map(Number)
274
+ * // ...
275
+ * return isValid
276
+ * })
277
+ */
278
+ customClientValidator(validationFn: (fieldValue: unknown, context: FormConditionalParameters) => boolean): JSONSchema;
279
+ /**
280
+ * Custom client-side evaluation. Returns a {@link CodeToEvaluate} descriptor
281
+ * that can be used as `value`, `evaluatedDefaultValue`, or a DATA component entry.
282
+ * The function is serialised and executed just-in-time on the client only.
283
+ * External references (e.g. lodash) are not available inside the function body.
284
+ *
285
+ * @example
286
+ * field('a').customClientEvaluation((aValue, ctx) =>
287
+ * Number(aValue) + Number(ctx.$form.b)
288
+ * )
289
+ */
290
+ customClientEvaluation(computationFn: (fieldValue: unknown, context: FormConditionalParameters) => unknown): CodeToEvaluate;
234
291
  };
235
292
  getByPath(fieldPath: string[]): {
236
293
  $$subfield: string[];
@@ -304,6 +361,32 @@ export declare function createFieldConditionals(fieldId: string): {
304
361
  * )
305
362
  */
306
363
  object: (options: Record<string, any>) => JSONSchema;
364
+ /**
365
+ * Custom client-side validator. The provided function is serialised and executed
366
+ * just-in-time on the client only. External references (e.g. lodash) are not
367
+ * available inside the function body — all logic must be self-contained.
368
+ *
369
+ * @example
370
+ * field('nid').customClientValidator((value) => {
371
+ * // LUHN check — all logic must be inline
372
+ * const digits = String(value).split('').map(Number)
373
+ * // ...
374
+ * return isValid
375
+ * })
376
+ */
377
+ customClientValidator(validationFn: (fieldValue: unknown, context: FormConditionalParameters) => boolean): JSONSchema;
378
+ /**
379
+ * Custom client-side evaluation. Returns a {@link CodeToEvaluate} descriptor
380
+ * that can be used as `value`, `evaluatedDefaultValue`, or a DATA component entry.
381
+ * The function is serialised and executed just-in-time on the client only.
382
+ * External references (e.g. lodash) are not available inside the function body.
383
+ *
384
+ * @example
385
+ * field('a').customClientEvaluation((aValue, ctx) =>
386
+ * Number(aValue) + Number(ctx.$form.b)
387
+ * )
388
+ */
389
+ customClientEvaluation(computationFn: (fieldValue: unknown, context: FormConditionalParameters) => unknown): CodeToEvaluate;
307
390
  };
308
391
  getByPath(fieldPath: string[]): any;
309
392
  asDob(): {
@@ -372,6 +455,32 @@ export declare function createFieldConditionals(fieldId: string): {
372
455
  * )
373
456
  */
374
457
  object: (options: Record<string, any>) => JSONSchema;
458
+ /**
459
+ * Custom client-side validator. The provided function is serialised and executed
460
+ * just-in-time on the client only. External references (e.g. lodash) are not
461
+ * available inside the function body — all logic must be self-contained.
462
+ *
463
+ * @example
464
+ * field('nid').customClientValidator((value) => {
465
+ * // LUHN check — all logic must be inline
466
+ * const digits = String(value).split('').map(Number)
467
+ * // ...
468
+ * return isValid
469
+ * })
470
+ */
471
+ customClientValidator(validationFn: (fieldValue: unknown, context: FormConditionalParameters) => boolean): JSONSchema;
472
+ /**
473
+ * Custom client-side evaluation. Returns a {@link CodeToEvaluate} descriptor
474
+ * that can be used as `value`, `evaluatedDefaultValue`, or a DATA component entry.
475
+ * The function is serialised and executed just-in-time on the client only.
476
+ * External references (e.g. lodash) are not available inside the function body.
477
+ *
478
+ * @example
479
+ * field('a').customClientEvaluation((aValue, ctx) =>
480
+ * Number(aValue) + Number(ctx.$form.b)
481
+ * )
482
+ */
483
+ customClientEvaluation(computationFn: (fieldValue: unknown, context: FormConditionalParameters) => unknown): CodeToEvaluate;
375
484
  };
376
485
  asAge(): {
377
486
  $$subfield: string[];
@@ -439,6 +548,32 @@ export declare function createFieldConditionals(fieldId: string): {
439
548
  * )
440
549
  */
441
550
  object: (options: Record<string, any>) => JSONSchema;
551
+ /**
552
+ * Custom client-side validator. The provided function is serialised and executed
553
+ * just-in-time on the client only. External references (e.g. lodash) are not
554
+ * available inside the function body — all logic must be self-contained.
555
+ *
556
+ * @example
557
+ * field('nid').customClientValidator((value) => {
558
+ * // LUHN check — all logic must be inline
559
+ * const digits = String(value).split('').map(Number)
560
+ * // ...
561
+ * return isValid
562
+ * })
563
+ */
564
+ customClientValidator(validationFn: (fieldValue: unknown, context: FormConditionalParameters) => boolean): JSONSchema;
565
+ /**
566
+ * Custom client-side evaluation. Returns a {@link CodeToEvaluate} descriptor
567
+ * that can be used as `value`, `evaluatedDefaultValue`, or a DATA component entry.
568
+ * The function is serialised and executed just-in-time on the client only.
569
+ * External references (e.g. lodash) are not available inside the function body.
570
+ *
571
+ * @example
572
+ * field('a').customClientEvaluation((aValue, ctx) =>
573
+ * Number(aValue) + Number(ctx.$form.b)
574
+ * )
575
+ */
576
+ customClientEvaluation(computationFn: (fieldValue: unknown, context: FormConditionalParameters) => unknown): CodeToEvaluate;
442
577
  };
443
578
  isAfter(): {
444
579
  days: (days: number) => {
@@ -496,6 +631,32 @@ export declare function createFieldConditionals(fieldId: string): {
496
631
  * )
497
632
  */
498
633
  object: (options: Record<string, any>) => JSONSchema;
634
+ /**
635
+ * Custom client-side validator. The provided function is serialised and executed
636
+ * just-in-time on the client only. External references (e.g. lodash) are not
637
+ * available inside the function body — all logic must be self-contained.
638
+ *
639
+ * @example
640
+ * field('nid').customClientValidator((value) => {
641
+ * // LUHN check — all logic must be inline
642
+ * const digits = String(value).split('').map(Number)
643
+ * // ...
644
+ * return isValid
645
+ * })
646
+ */
647
+ customClientValidator(validationFn: (fieldValue: unknown, context: FormConditionalParameters) => boolean): JSONSchema;
648
+ /**
649
+ * Custom client-side evaluation. Returns a {@link CodeToEvaluate} descriptor
650
+ * that can be used as `value`, `evaluatedDefaultValue`, or a DATA component entry.
651
+ * The function is serialised and executed just-in-time on the client only.
652
+ * External references (e.g. lodash) are not available inside the function body.
653
+ *
654
+ * @example
655
+ * field('a').customClientEvaluation((aValue, ctx) =>
656
+ * Number(aValue) + Number(ctx.$form.b)
657
+ * )
658
+ */
659
+ customClientEvaluation(computationFn: (fieldValue: unknown, context: FormConditionalParameters) => unknown): CodeToEvaluate;
499
660
  };
500
661
  asDob(): {
501
662
  $$subfield: string[];
@@ -570,6 +731,32 @@ export declare function createFieldConditionals(fieldId: string): {
570
731
  * )
571
732
  */
572
733
  object: (options: Record<string, any>) => JSONSchema;
734
+ /**
735
+ * Custom client-side validator. The provided function is serialised and executed
736
+ * just-in-time on the client only. External references (e.g. lodash) are not
737
+ * available inside the function body — all logic must be self-contained.
738
+ *
739
+ * @example
740
+ * field('nid').customClientValidator((value) => {
741
+ * // LUHN check — all logic must be inline
742
+ * const digits = String(value).split('').map(Number)
743
+ * // ...
744
+ * return isValid
745
+ * })
746
+ */
747
+ customClientValidator(validationFn: (fieldValue: unknown, context: FormConditionalParameters) => boolean): JSONSchema;
748
+ /**
749
+ * Custom client-side evaluation. Returns a {@link CodeToEvaluate} descriptor
750
+ * that can be used as `value`, `evaluatedDefaultValue`, or a DATA component entry.
751
+ * The function is serialised and executed just-in-time on the client only.
752
+ * External references (e.g. lodash) are not available inside the function body.
753
+ *
754
+ * @example
755
+ * field('a').customClientEvaluation((aValue, ctx) =>
756
+ * Number(aValue) + Number(ctx.$form.b)
757
+ * )
758
+ */
759
+ customClientEvaluation(computationFn: (fieldValue: unknown, context: FormConditionalParameters) => unknown): CodeToEvaluate;
573
760
  };
574
761
  asDob(): any;
575
762
  asAge(): any;
@@ -629,6 +816,32 @@ export declare function createFieldConditionals(fieldId: string): {
629
816
  * )
630
817
  */
631
818
  object: (options: Record<string, any>) => JSONSchema;
819
+ /**
820
+ * Custom client-side validator. The provided function is serialised and executed
821
+ * just-in-time on the client only. External references (e.g. lodash) are not
822
+ * available inside the function body — all logic must be self-contained.
823
+ *
824
+ * @example
825
+ * field('nid').customClientValidator((value) => {
826
+ * // LUHN check — all logic must be inline
827
+ * const digits = String(value).split('').map(Number)
828
+ * // ...
829
+ * return isValid
830
+ * })
831
+ */
832
+ customClientValidator(validationFn: (fieldValue: unknown, context: FormConditionalParameters) => boolean): JSONSchema;
833
+ /**
834
+ * Custom client-side evaluation. Returns a {@link CodeToEvaluate} descriptor
835
+ * that can be used as `value`, `evaluatedDefaultValue`, or a DATA component entry.
836
+ * The function is serialised and executed just-in-time on the client only.
837
+ * External references (e.g. lodash) are not available inside the function body.
838
+ *
839
+ * @example
840
+ * field('a').customClientEvaluation((aValue, ctx) =>
841
+ * Number(aValue) + Number(ctx.$form.b)
842
+ * )
843
+ */
844
+ customClientEvaluation(computationFn: (fieldValue: unknown, context: FormConditionalParameters) => unknown): CodeToEvaluate;
632
845
  };
633
846
  asAge(): {
634
847
  $$subfield: string[];
@@ -703,6 +916,32 @@ export declare function createFieldConditionals(fieldId: string): {
703
916
  * )
704
917
  */
705
918
  object: (options: Record<string, any>) => JSONSchema;
919
+ /**
920
+ * Custom client-side validator. The provided function is serialised and executed
921
+ * just-in-time on the client only. External references (e.g. lodash) are not
922
+ * available inside the function body — all logic must be self-contained.
923
+ *
924
+ * @example
925
+ * field('nid').customClientValidator((value) => {
926
+ * // LUHN check — all logic must be inline
927
+ * const digits = String(value).split('').map(Number)
928
+ * // ...
929
+ * return isValid
930
+ * })
931
+ */
932
+ customClientValidator(validationFn: (fieldValue: unknown, context: FormConditionalParameters) => boolean): JSONSchema;
933
+ /**
934
+ * Custom client-side evaluation. Returns a {@link CodeToEvaluate} descriptor
935
+ * that can be used as `value`, `evaluatedDefaultValue`, or a DATA component entry.
936
+ * The function is serialised and executed just-in-time on the client only.
937
+ * External references (e.g. lodash) are not available inside the function body.
938
+ *
939
+ * @example
940
+ * field('a').customClientEvaluation((aValue, ctx) =>
941
+ * Number(aValue) + Number(ctx.$form.b)
942
+ * )
943
+ */
944
+ customClientEvaluation(computationFn: (fieldValue: unknown, context: FormConditionalParameters) => unknown): CodeToEvaluate;
706
945
  };
707
946
  asDob(): any;
708
947
  asAge(): any;
@@ -762,6 +1001,32 @@ export declare function createFieldConditionals(fieldId: string): {
762
1001
  * )
763
1002
  */
764
1003
  object: (options: Record<string, any>) => JSONSchema;
1004
+ /**
1005
+ * Custom client-side validator. The provided function is serialised and executed
1006
+ * just-in-time on the client only. External references (e.g. lodash) are not
1007
+ * available inside the function body — all logic must be self-contained.
1008
+ *
1009
+ * @example
1010
+ * field('nid').customClientValidator((value) => {
1011
+ * // LUHN check — all logic must be inline
1012
+ * const digits = String(value).split('').map(Number)
1013
+ * // ...
1014
+ * return isValid
1015
+ * })
1016
+ */
1017
+ customClientValidator(validationFn: (fieldValue: unknown, context: FormConditionalParameters) => boolean): JSONSchema;
1018
+ /**
1019
+ * Custom client-side evaluation. Returns a {@link CodeToEvaluate} descriptor
1020
+ * that can be used as `value`, `evaluatedDefaultValue`, or a DATA component entry.
1021
+ * The function is serialised and executed just-in-time on the client only.
1022
+ * External references (e.g. lodash) are not available inside the function body.
1023
+ *
1024
+ * @example
1025
+ * field('a').customClientEvaluation((aValue, ctx) =>
1026
+ * Number(aValue) + Number(ctx.$form.b)
1027
+ * )
1028
+ */
1029
+ customClientEvaluation(computationFn: (fieldValue: unknown, context: FormConditionalParameters) => unknown): CodeToEvaluate;
765
1030
  };
766
1031
  isAfter(): {
767
1032
  days: (days: number) => {
@@ -819,6 +1084,32 @@ export declare function createFieldConditionals(fieldId: string): {
819
1084
  * )
820
1085
  */
821
1086
  object: (options: Record<string, any>) => JSONSchema;
1087
+ /**
1088
+ * Custom client-side validator. The provided function is serialised and executed
1089
+ * just-in-time on the client only. External references (e.g. lodash) are not
1090
+ * available inside the function body — all logic must be self-contained.
1091
+ *
1092
+ * @example
1093
+ * field('nid').customClientValidator((value) => {
1094
+ * // LUHN check — all logic must be inline
1095
+ * const digits = String(value).split('').map(Number)
1096
+ * // ...
1097
+ * return isValid
1098
+ * })
1099
+ */
1100
+ customClientValidator(validationFn: (fieldValue: unknown, context: FormConditionalParameters) => boolean): JSONSchema;
1101
+ /**
1102
+ * Custom client-side evaluation. Returns a {@link CodeToEvaluate} descriptor
1103
+ * that can be used as `value`, `evaluatedDefaultValue`, or a DATA component entry.
1104
+ * The function is serialised and executed just-in-time on the client only.
1105
+ * External references (e.g. lodash) are not available inside the function body.
1106
+ *
1107
+ * @example
1108
+ * field('a').customClientEvaluation((aValue, ctx) =>
1109
+ * Number(aValue) + Number(ctx.$form.b)
1110
+ * )
1111
+ */
1112
+ customClientEvaluation(computationFn: (fieldValue: unknown, context: FormConditionalParameters) => unknown): CodeToEvaluate;
822
1113
  };
823
1114
  export {};
824
1115
  //# sourceMappingURL=conditionals.d.ts.map
@@ -9,6 +9,14 @@ import { UUID } from '../uuid';
9
9
  import { FormState } from '../events/utils';
10
10
  import { ActionType } from '../events/ActionType';
11
11
  import { EventDocument } from '../events/EventDocument';
12
+ /** Returns today's date as an ISO date string (YYYY-MM-DD). */
13
+ export declare function todayISO(): string;
14
+ /**
15
+ * Deserialises a serialised function string (produced by `.toString()`) into a callable.
16
+ * Results are cached by code string so each unique function body is compiled at most once.
17
+ * Runs in a clean scope — no access to outer closures or external imports.
18
+ */
19
+ export declare function compileClientFunction(code: string): (...args: unknown[]) => unknown;
12
20
  export declare function validate(schema: JSONSchema, data: ConditionalParameters): boolean;
13
21
  export declare function validateValue(schema: JSONSchema, data: unknown): boolean;
14
22
  export declare function isOnline(): boolean;