@opencrvs/toolkit 2.0.0-rc.fe94e41 → 2.0.0-rc.fedb8b0
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.
- package/dist/application-config/index.js +45 -33
- package/dist/cli.js +9 -3
- package/dist/commons/api/router.d.ts +15 -15
- package/dist/commons/application-config/index.d.ts +1 -0
- package/dist/commons/conditionals/conditionals.d.ts +348 -4
- package/dist/commons/conditionals/validate.d.ts +51 -2
- package/dist/commons/events/AdvancedSearchConfig.d.ts +342 -0
- package/dist/commons/events/FieldConfig.d.ts +377 -50
- package/dist/commons/events/FieldValue.d.ts +6 -0
- package/dist/commons/events/field.d.ts +53 -1
- package/dist/commons/events/state/utils.d.ts +12 -290
- package/dist/commons/events/utils.d.ts +1 -1
- package/dist/conditionals/index.js +48 -1
- package/dist/events/index.js +205 -84
- package/dist/migrations/v2.0/index.js +9 -3
- package/dist/notification/index.js +149 -35
- package/dist/scopes/index.d.ts +4 -6
- package/dist/scopes/index.js +9 -3
- package/opencrvs-toolkit-2.0.0-rc.fedb8b0.tgz +0 -0
- package/package.json +1 -1
- package/opencrvs-toolkit-2.0.0-rc.fe94e41.tgz +0 -0
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { EventDocument } from '../events/EventDocument';
|
|
2
|
-
import { EventState } from '../events/ActionDocument';
|
|
2
|
+
import { ActionUpdate, EventState } from '../events/ActionDocument';
|
|
3
3
|
import { ITokenPayload as TokenPayload } 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
7
|
import { todayDateTimeValueSerializer } from '../events/serializers/date/serializer';
|
|
8
8
|
import { EventStatus } from '../events/EventMetadata';
|
|
9
|
-
import { FieldReference } from '../events/FieldConfig';
|
|
9
|
+
import { CodeToEvaluate, FieldReference } from '../events/FieldConfig';
|
|
10
|
+
import type { ClientFunctionContext } from './validate';
|
|
10
11
|
/** @knipignore */
|
|
11
12
|
export type JSONSchema = {
|
|
12
13
|
$id: string;
|
|
@@ -25,7 +26,7 @@ export type EventConditionalParameters = CommonConditionalParameters & {
|
|
|
25
26
|
$event: EventDocument;
|
|
26
27
|
};
|
|
27
28
|
export type FormConditionalParameters = CommonConditionalParameters & {
|
|
28
|
-
$form: EventState |
|
|
29
|
+
$form: EventState | ActionUpdate;
|
|
29
30
|
$leafAdminStructureLocationIds?: Array<{
|
|
30
31
|
id: UUID;
|
|
31
32
|
}>;
|
|
@@ -107,7 +108,9 @@ export declare const user: typeof userSerializer & {
|
|
|
107
108
|
};
|
|
108
109
|
};
|
|
109
110
|
export declare function isFieldReference(value: unknown): value is FieldReference;
|
|
110
|
-
export declare function isEventFieldReference(value: unknown): value is
|
|
111
|
+
export declare function isEventFieldReference(value: unknown): value is {
|
|
112
|
+
$$event: string;
|
|
113
|
+
};
|
|
111
114
|
/** Check if an event flag is present */
|
|
112
115
|
export declare function flag(flagvalue: string): JSONSchema;
|
|
113
116
|
/** Check if an event flag is present */
|
|
@@ -202,6 +205,37 @@ export declare function createFieldConditionals(fieldId: string): {
|
|
|
202
205
|
* )
|
|
203
206
|
*/
|
|
204
207
|
object: (options: Record<string, any>) => JSONSchema;
|
|
208
|
+
/**
|
|
209
|
+
* Custom client-side validator. The provided function is serialised and executed
|
|
210
|
+
* just-in-time on the client only. External references (e.g. lodash) are not
|
|
211
|
+
* available inside the function body — all logic must be self-contained.
|
|
212
|
+
*
|
|
213
|
+
* @example
|
|
214
|
+
* field('nid').customClientValidator((value) => {
|
|
215
|
+
* // LUHN check — all logic must be inline
|
|
216
|
+
* const digits = String(value).split('').map(Number)
|
|
217
|
+
* // ...
|
|
218
|
+
* return isValid
|
|
219
|
+
* })
|
|
220
|
+
*/
|
|
221
|
+
customClientValidator(validationFn: (fieldValue: unknown, context: ClientFunctionContext) => boolean): JSONSchema;
|
|
222
|
+
/**
|
|
223
|
+
* Custom client-side evaluation. Returns a {@link FieldReference} descriptor
|
|
224
|
+
* that can be used as the `value` property or a DATA component entry.
|
|
225
|
+
* The function receives the referenced field's value as the first argument and
|
|
226
|
+
* the full form context as the second; its return value replaces the field reference.
|
|
227
|
+
* The function is serialised and executed just-in-time on the client only.
|
|
228
|
+
* External references (e.g. lodash) are not available inside the function body.
|
|
229
|
+
*
|
|
230
|
+
* For computing a default value without referencing a specific field, use
|
|
231
|
+
* `evaluate(fn)` in the `defaultValue` property instead.
|
|
232
|
+
*
|
|
233
|
+
* @example
|
|
234
|
+
* field('a').customClientEvaluation((aValue, ctx) =>
|
|
235
|
+
* Number(aValue) + Number(ctx.$form.b)
|
|
236
|
+
* )
|
|
237
|
+
*/
|
|
238
|
+
customClientEvaluation(computationFn: (fieldValue: unknown, context: ClientFunctionContext) => unknown): CodeToEvaluate;
|
|
205
239
|
};
|
|
206
240
|
asDob(): any;
|
|
207
241
|
asAge(): any;
|
|
@@ -261,6 +295,37 @@ export declare function createFieldConditionals(fieldId: string): {
|
|
|
261
295
|
* )
|
|
262
296
|
*/
|
|
263
297
|
object: (options: Record<string, any>) => JSONSchema;
|
|
298
|
+
/**
|
|
299
|
+
* Custom client-side validator. The provided function is serialised and executed
|
|
300
|
+
* just-in-time on the client only. External references (e.g. lodash) are not
|
|
301
|
+
* available inside the function body — all logic must be self-contained.
|
|
302
|
+
*
|
|
303
|
+
* @example
|
|
304
|
+
* field('nid').customClientValidator((value) => {
|
|
305
|
+
* // LUHN check — all logic must be inline
|
|
306
|
+
* const digits = String(value).split('').map(Number)
|
|
307
|
+
* // ...
|
|
308
|
+
* return isValid
|
|
309
|
+
* })
|
|
310
|
+
*/
|
|
311
|
+
customClientValidator(validationFn: (fieldValue: unknown, context: ClientFunctionContext) => boolean): JSONSchema;
|
|
312
|
+
/**
|
|
313
|
+
* Custom client-side evaluation. Returns a {@link FieldReference} descriptor
|
|
314
|
+
* that can be used as the `value` property or a DATA component entry.
|
|
315
|
+
* The function receives the referenced field's value as the first argument and
|
|
316
|
+
* the full form context as the second; its return value replaces the field reference.
|
|
317
|
+
* The function is serialised and executed just-in-time on the client only.
|
|
318
|
+
* External references (e.g. lodash) are not available inside the function body.
|
|
319
|
+
*
|
|
320
|
+
* For computing a default value without referencing a specific field, use
|
|
321
|
+
* `evaluate(fn)` in the `defaultValue` property instead.
|
|
322
|
+
*
|
|
323
|
+
* @example
|
|
324
|
+
* field('a').customClientEvaluation((aValue, ctx) =>
|
|
325
|
+
* Number(aValue) + Number(ctx.$form.b)
|
|
326
|
+
* )
|
|
327
|
+
*/
|
|
328
|
+
customClientEvaluation(computationFn: (fieldValue: unknown, context: ClientFunctionContext) => unknown): CodeToEvaluate;
|
|
264
329
|
};
|
|
265
330
|
getByPath(fieldPath: string[]): {
|
|
266
331
|
$$subfield: string[];
|
|
@@ -334,6 +399,37 @@ export declare function createFieldConditionals(fieldId: string): {
|
|
|
334
399
|
* )
|
|
335
400
|
*/
|
|
336
401
|
object: (options: Record<string, any>) => JSONSchema;
|
|
402
|
+
/**
|
|
403
|
+
* Custom client-side validator. The provided function is serialised and executed
|
|
404
|
+
* just-in-time on the client only. External references (e.g. lodash) are not
|
|
405
|
+
* available inside the function body — all logic must be self-contained.
|
|
406
|
+
*
|
|
407
|
+
* @example
|
|
408
|
+
* field('nid').customClientValidator((value) => {
|
|
409
|
+
* // LUHN check — all logic must be inline
|
|
410
|
+
* const digits = String(value).split('').map(Number)
|
|
411
|
+
* // ...
|
|
412
|
+
* return isValid
|
|
413
|
+
* })
|
|
414
|
+
*/
|
|
415
|
+
customClientValidator(validationFn: (fieldValue: unknown, context: ClientFunctionContext) => boolean): JSONSchema;
|
|
416
|
+
/**
|
|
417
|
+
* Custom client-side evaluation. Returns a {@link FieldReference} descriptor
|
|
418
|
+
* that can be used as the `value` property or a DATA component entry.
|
|
419
|
+
* The function receives the referenced field's value as the first argument and
|
|
420
|
+
* the full form context as the second; its return value replaces the field reference.
|
|
421
|
+
* The function is serialised and executed just-in-time on the client only.
|
|
422
|
+
* External references (e.g. lodash) are not available inside the function body.
|
|
423
|
+
*
|
|
424
|
+
* For computing a default value without referencing a specific field, use
|
|
425
|
+
* `evaluate(fn)` in the `defaultValue` property instead.
|
|
426
|
+
*
|
|
427
|
+
* @example
|
|
428
|
+
* field('a').customClientEvaluation((aValue, ctx) =>
|
|
429
|
+
* Number(aValue) + Number(ctx.$form.b)
|
|
430
|
+
* )
|
|
431
|
+
*/
|
|
432
|
+
customClientEvaluation(computationFn: (fieldValue: unknown, context: ClientFunctionContext) => unknown): CodeToEvaluate;
|
|
337
433
|
};
|
|
338
434
|
getByPath(fieldPath: string[]): any;
|
|
339
435
|
asDob(): {
|
|
@@ -402,6 +498,37 @@ export declare function createFieldConditionals(fieldId: string): {
|
|
|
402
498
|
* )
|
|
403
499
|
*/
|
|
404
500
|
object: (options: Record<string, any>) => JSONSchema;
|
|
501
|
+
/**
|
|
502
|
+
* Custom client-side validator. The provided function is serialised and executed
|
|
503
|
+
* just-in-time on the client only. External references (e.g. lodash) are not
|
|
504
|
+
* available inside the function body — all logic must be self-contained.
|
|
505
|
+
*
|
|
506
|
+
* @example
|
|
507
|
+
* field('nid').customClientValidator((value) => {
|
|
508
|
+
* // LUHN check — all logic must be inline
|
|
509
|
+
* const digits = String(value).split('').map(Number)
|
|
510
|
+
* // ...
|
|
511
|
+
* return isValid
|
|
512
|
+
* })
|
|
513
|
+
*/
|
|
514
|
+
customClientValidator(validationFn: (fieldValue: unknown, context: ClientFunctionContext) => boolean): JSONSchema;
|
|
515
|
+
/**
|
|
516
|
+
* Custom client-side evaluation. Returns a {@link FieldReference} descriptor
|
|
517
|
+
* that can be used as the `value` property or a DATA component entry.
|
|
518
|
+
* The function receives the referenced field's value as the first argument and
|
|
519
|
+
* the full form context as the second; its return value replaces the field reference.
|
|
520
|
+
* The function is serialised and executed just-in-time on the client only.
|
|
521
|
+
* External references (e.g. lodash) are not available inside the function body.
|
|
522
|
+
*
|
|
523
|
+
* For computing a default value without referencing a specific field, use
|
|
524
|
+
* `evaluate(fn)` in the `defaultValue` property instead.
|
|
525
|
+
*
|
|
526
|
+
* @example
|
|
527
|
+
* field('a').customClientEvaluation((aValue, ctx) =>
|
|
528
|
+
* Number(aValue) + Number(ctx.$form.b)
|
|
529
|
+
* )
|
|
530
|
+
*/
|
|
531
|
+
customClientEvaluation(computationFn: (fieldValue: unknown, context: ClientFunctionContext) => unknown): CodeToEvaluate;
|
|
405
532
|
};
|
|
406
533
|
asAge(): {
|
|
407
534
|
$$subfield: string[];
|
|
@@ -469,6 +596,37 @@ export declare function createFieldConditionals(fieldId: string): {
|
|
|
469
596
|
* )
|
|
470
597
|
*/
|
|
471
598
|
object: (options: Record<string, any>) => JSONSchema;
|
|
599
|
+
/**
|
|
600
|
+
* Custom client-side validator. The provided function is serialised and executed
|
|
601
|
+
* just-in-time on the client only. External references (e.g. lodash) are not
|
|
602
|
+
* available inside the function body — all logic must be self-contained.
|
|
603
|
+
*
|
|
604
|
+
* @example
|
|
605
|
+
* field('nid').customClientValidator((value) => {
|
|
606
|
+
* // LUHN check — all logic must be inline
|
|
607
|
+
* const digits = String(value).split('').map(Number)
|
|
608
|
+
* // ...
|
|
609
|
+
* return isValid
|
|
610
|
+
* })
|
|
611
|
+
*/
|
|
612
|
+
customClientValidator(validationFn: (fieldValue: unknown, context: ClientFunctionContext) => boolean): JSONSchema;
|
|
613
|
+
/**
|
|
614
|
+
* Custom client-side evaluation. Returns a {@link FieldReference} descriptor
|
|
615
|
+
* that can be used as the `value` property or a DATA component entry.
|
|
616
|
+
* The function receives the referenced field's value as the first argument and
|
|
617
|
+
* the full form context as the second; its return value replaces the field reference.
|
|
618
|
+
* The function is serialised and executed just-in-time on the client only.
|
|
619
|
+
* External references (e.g. lodash) are not available inside the function body.
|
|
620
|
+
*
|
|
621
|
+
* For computing a default value without referencing a specific field, use
|
|
622
|
+
* `evaluate(fn)` in the `defaultValue` property instead.
|
|
623
|
+
*
|
|
624
|
+
* @example
|
|
625
|
+
* field('a').customClientEvaluation((aValue, ctx) =>
|
|
626
|
+
* Number(aValue) + Number(ctx.$form.b)
|
|
627
|
+
* )
|
|
628
|
+
*/
|
|
629
|
+
customClientEvaluation(computationFn: (fieldValue: unknown, context: ClientFunctionContext) => unknown): CodeToEvaluate;
|
|
472
630
|
};
|
|
473
631
|
isAfter(): {
|
|
474
632
|
days: (days: number) => {
|
|
@@ -526,6 +684,37 @@ export declare function createFieldConditionals(fieldId: string): {
|
|
|
526
684
|
* )
|
|
527
685
|
*/
|
|
528
686
|
object: (options: Record<string, any>) => JSONSchema;
|
|
687
|
+
/**
|
|
688
|
+
* Custom client-side validator. The provided function is serialised and executed
|
|
689
|
+
* just-in-time on the client only. External references (e.g. lodash) are not
|
|
690
|
+
* available inside the function body — all logic must be self-contained.
|
|
691
|
+
*
|
|
692
|
+
* @example
|
|
693
|
+
* field('nid').customClientValidator((value) => {
|
|
694
|
+
* // LUHN check — all logic must be inline
|
|
695
|
+
* const digits = String(value).split('').map(Number)
|
|
696
|
+
* // ...
|
|
697
|
+
* return isValid
|
|
698
|
+
* })
|
|
699
|
+
*/
|
|
700
|
+
customClientValidator(validationFn: (fieldValue: unknown, context: ClientFunctionContext) => boolean): JSONSchema;
|
|
701
|
+
/**
|
|
702
|
+
* Custom client-side evaluation. Returns a {@link FieldReference} descriptor
|
|
703
|
+
* that can be used as the `value` property or a DATA component entry.
|
|
704
|
+
* The function receives the referenced field's value as the first argument and
|
|
705
|
+
* the full form context as the second; its return value replaces the field reference.
|
|
706
|
+
* The function is serialised and executed just-in-time on the client only.
|
|
707
|
+
* External references (e.g. lodash) are not available inside the function body.
|
|
708
|
+
*
|
|
709
|
+
* For computing a default value without referencing a specific field, use
|
|
710
|
+
* `evaluate(fn)` in the `defaultValue` property instead.
|
|
711
|
+
*
|
|
712
|
+
* @example
|
|
713
|
+
* field('a').customClientEvaluation((aValue, ctx) =>
|
|
714
|
+
* Number(aValue) + Number(ctx.$form.b)
|
|
715
|
+
* )
|
|
716
|
+
*/
|
|
717
|
+
customClientEvaluation(computationFn: (fieldValue: unknown, context: ClientFunctionContext) => unknown): CodeToEvaluate;
|
|
529
718
|
};
|
|
530
719
|
asDob(): {
|
|
531
720
|
$$subfield: string[];
|
|
@@ -600,6 +789,37 @@ export declare function createFieldConditionals(fieldId: string): {
|
|
|
600
789
|
* )
|
|
601
790
|
*/
|
|
602
791
|
object: (options: Record<string, any>) => JSONSchema;
|
|
792
|
+
/**
|
|
793
|
+
* Custom client-side validator. The provided function is serialised and executed
|
|
794
|
+
* just-in-time on the client only. External references (e.g. lodash) are not
|
|
795
|
+
* available inside the function body — all logic must be self-contained.
|
|
796
|
+
*
|
|
797
|
+
* @example
|
|
798
|
+
* field('nid').customClientValidator((value) => {
|
|
799
|
+
* // LUHN check — all logic must be inline
|
|
800
|
+
* const digits = String(value).split('').map(Number)
|
|
801
|
+
* // ...
|
|
802
|
+
* return isValid
|
|
803
|
+
* })
|
|
804
|
+
*/
|
|
805
|
+
customClientValidator(validationFn: (fieldValue: unknown, context: ClientFunctionContext) => boolean): JSONSchema;
|
|
806
|
+
/**
|
|
807
|
+
* Custom client-side evaluation. Returns a {@link FieldReference} descriptor
|
|
808
|
+
* that can be used as the `value` property or a DATA component entry.
|
|
809
|
+
* The function receives the referenced field's value as the first argument and
|
|
810
|
+
* the full form context as the second; its return value replaces the field reference.
|
|
811
|
+
* The function is serialised and executed just-in-time on the client only.
|
|
812
|
+
* External references (e.g. lodash) are not available inside the function body.
|
|
813
|
+
*
|
|
814
|
+
* For computing a default value without referencing a specific field, use
|
|
815
|
+
* `evaluate(fn)` in the `defaultValue` property instead.
|
|
816
|
+
*
|
|
817
|
+
* @example
|
|
818
|
+
* field('a').customClientEvaluation((aValue, ctx) =>
|
|
819
|
+
* Number(aValue) + Number(ctx.$form.b)
|
|
820
|
+
* )
|
|
821
|
+
*/
|
|
822
|
+
customClientEvaluation(computationFn: (fieldValue: unknown, context: ClientFunctionContext) => unknown): CodeToEvaluate;
|
|
603
823
|
};
|
|
604
824
|
asDob(): any;
|
|
605
825
|
asAge(): any;
|
|
@@ -659,6 +879,37 @@ export declare function createFieldConditionals(fieldId: string): {
|
|
|
659
879
|
* )
|
|
660
880
|
*/
|
|
661
881
|
object: (options: Record<string, any>) => JSONSchema;
|
|
882
|
+
/**
|
|
883
|
+
* Custom client-side validator. The provided function is serialised and executed
|
|
884
|
+
* just-in-time on the client only. External references (e.g. lodash) are not
|
|
885
|
+
* available inside the function body — all logic must be self-contained.
|
|
886
|
+
*
|
|
887
|
+
* @example
|
|
888
|
+
* field('nid').customClientValidator((value) => {
|
|
889
|
+
* // LUHN check — all logic must be inline
|
|
890
|
+
* const digits = String(value).split('').map(Number)
|
|
891
|
+
* // ...
|
|
892
|
+
* return isValid
|
|
893
|
+
* })
|
|
894
|
+
*/
|
|
895
|
+
customClientValidator(validationFn: (fieldValue: unknown, context: ClientFunctionContext) => boolean): JSONSchema;
|
|
896
|
+
/**
|
|
897
|
+
* Custom client-side evaluation. Returns a {@link FieldReference} descriptor
|
|
898
|
+
* that can be used as the `value` property or a DATA component entry.
|
|
899
|
+
* The function receives the referenced field's value as the first argument and
|
|
900
|
+
* the full form context as the second; its return value replaces the field reference.
|
|
901
|
+
* The function is serialised and executed just-in-time on the client only.
|
|
902
|
+
* External references (e.g. lodash) are not available inside the function body.
|
|
903
|
+
*
|
|
904
|
+
* For computing a default value without referencing a specific field, use
|
|
905
|
+
* `evaluate(fn)` in the `defaultValue` property instead.
|
|
906
|
+
*
|
|
907
|
+
* @example
|
|
908
|
+
* field('a').customClientEvaluation((aValue, ctx) =>
|
|
909
|
+
* Number(aValue) + Number(ctx.$form.b)
|
|
910
|
+
* )
|
|
911
|
+
*/
|
|
912
|
+
customClientEvaluation(computationFn: (fieldValue: unknown, context: ClientFunctionContext) => unknown): CodeToEvaluate;
|
|
662
913
|
};
|
|
663
914
|
asAge(): {
|
|
664
915
|
$$subfield: string[];
|
|
@@ -733,6 +984,37 @@ export declare function createFieldConditionals(fieldId: string): {
|
|
|
733
984
|
* )
|
|
734
985
|
*/
|
|
735
986
|
object: (options: Record<string, any>) => JSONSchema;
|
|
987
|
+
/**
|
|
988
|
+
* Custom client-side validator. The provided function is serialised and executed
|
|
989
|
+
* just-in-time on the client only. External references (e.g. lodash) are not
|
|
990
|
+
* available inside the function body — all logic must be self-contained.
|
|
991
|
+
*
|
|
992
|
+
* @example
|
|
993
|
+
* field('nid').customClientValidator((value) => {
|
|
994
|
+
* // LUHN check — all logic must be inline
|
|
995
|
+
* const digits = String(value).split('').map(Number)
|
|
996
|
+
* // ...
|
|
997
|
+
* return isValid
|
|
998
|
+
* })
|
|
999
|
+
*/
|
|
1000
|
+
customClientValidator(validationFn: (fieldValue: unknown, context: ClientFunctionContext) => boolean): JSONSchema;
|
|
1001
|
+
/**
|
|
1002
|
+
* Custom client-side evaluation. Returns a {@link FieldReference} descriptor
|
|
1003
|
+
* that can be used as the `value` property or a DATA component entry.
|
|
1004
|
+
* The function receives the referenced field's value as the first argument and
|
|
1005
|
+
* the full form context as the second; its return value replaces the field reference.
|
|
1006
|
+
* The function is serialised and executed just-in-time on the client only.
|
|
1007
|
+
* External references (e.g. lodash) are not available inside the function body.
|
|
1008
|
+
*
|
|
1009
|
+
* For computing a default value without referencing a specific field, use
|
|
1010
|
+
* `evaluate(fn)` in the `defaultValue` property instead.
|
|
1011
|
+
*
|
|
1012
|
+
* @example
|
|
1013
|
+
* field('a').customClientEvaluation((aValue, ctx) =>
|
|
1014
|
+
* Number(aValue) + Number(ctx.$form.b)
|
|
1015
|
+
* )
|
|
1016
|
+
*/
|
|
1017
|
+
customClientEvaluation(computationFn: (fieldValue: unknown, context: ClientFunctionContext) => unknown): CodeToEvaluate;
|
|
736
1018
|
};
|
|
737
1019
|
asDob(): any;
|
|
738
1020
|
asAge(): any;
|
|
@@ -792,6 +1074,37 @@ export declare function createFieldConditionals(fieldId: string): {
|
|
|
792
1074
|
* )
|
|
793
1075
|
*/
|
|
794
1076
|
object: (options: Record<string, any>) => JSONSchema;
|
|
1077
|
+
/**
|
|
1078
|
+
* Custom client-side validator. The provided function is serialised and executed
|
|
1079
|
+
* just-in-time on the client only. External references (e.g. lodash) are not
|
|
1080
|
+
* available inside the function body — all logic must be self-contained.
|
|
1081
|
+
*
|
|
1082
|
+
* @example
|
|
1083
|
+
* field('nid').customClientValidator((value) => {
|
|
1084
|
+
* // LUHN check — all logic must be inline
|
|
1085
|
+
* const digits = String(value).split('').map(Number)
|
|
1086
|
+
* // ...
|
|
1087
|
+
* return isValid
|
|
1088
|
+
* })
|
|
1089
|
+
*/
|
|
1090
|
+
customClientValidator(validationFn: (fieldValue: unknown, context: ClientFunctionContext) => boolean): JSONSchema;
|
|
1091
|
+
/**
|
|
1092
|
+
* Custom client-side evaluation. Returns a {@link FieldReference} descriptor
|
|
1093
|
+
* that can be used as the `value` property or a DATA component entry.
|
|
1094
|
+
* The function receives the referenced field's value as the first argument and
|
|
1095
|
+
* the full form context as the second; its return value replaces the field reference.
|
|
1096
|
+
* The function is serialised and executed just-in-time on the client only.
|
|
1097
|
+
* External references (e.g. lodash) are not available inside the function body.
|
|
1098
|
+
*
|
|
1099
|
+
* For computing a default value without referencing a specific field, use
|
|
1100
|
+
* `evaluate(fn)` in the `defaultValue` property instead.
|
|
1101
|
+
*
|
|
1102
|
+
* @example
|
|
1103
|
+
* field('a').customClientEvaluation((aValue, ctx) =>
|
|
1104
|
+
* Number(aValue) + Number(ctx.$form.b)
|
|
1105
|
+
* )
|
|
1106
|
+
*/
|
|
1107
|
+
customClientEvaluation(computationFn: (fieldValue: unknown, context: ClientFunctionContext) => unknown): CodeToEvaluate;
|
|
795
1108
|
};
|
|
796
1109
|
isAfter(): {
|
|
797
1110
|
days: (days: number) => {
|
|
@@ -849,6 +1162,37 @@ export declare function createFieldConditionals(fieldId: string): {
|
|
|
849
1162
|
* )
|
|
850
1163
|
*/
|
|
851
1164
|
object: (options: Record<string, any>) => JSONSchema;
|
|
1165
|
+
/**
|
|
1166
|
+
* Custom client-side validator. The provided function is serialised and executed
|
|
1167
|
+
* just-in-time on the client only. External references (e.g. lodash) are not
|
|
1168
|
+
* available inside the function body — all logic must be self-contained.
|
|
1169
|
+
*
|
|
1170
|
+
* @example
|
|
1171
|
+
* field('nid').customClientValidator((value) => {
|
|
1172
|
+
* // LUHN check — all logic must be inline
|
|
1173
|
+
* const digits = String(value).split('').map(Number)
|
|
1174
|
+
* // ...
|
|
1175
|
+
* return isValid
|
|
1176
|
+
* })
|
|
1177
|
+
*/
|
|
1178
|
+
customClientValidator(validationFn: (fieldValue: unknown, context: ClientFunctionContext) => boolean): JSONSchema;
|
|
1179
|
+
/**
|
|
1180
|
+
* Custom client-side evaluation. Returns a {@link FieldReference} descriptor
|
|
1181
|
+
* that can be used as the `value` property or a DATA component entry.
|
|
1182
|
+
* The function receives the referenced field's value as the first argument and
|
|
1183
|
+
* the full form context as the second; its return value replaces the field reference.
|
|
1184
|
+
* The function is serialised and executed just-in-time on the client only.
|
|
1185
|
+
* External references (e.g. lodash) are not available inside the function body.
|
|
1186
|
+
*
|
|
1187
|
+
* For computing a default value without referencing a specific field, use
|
|
1188
|
+
* `evaluate(fn)` in the `defaultValue` property instead.
|
|
1189
|
+
*
|
|
1190
|
+
* @example
|
|
1191
|
+
* field('a').customClientEvaluation((aValue, ctx) =>
|
|
1192
|
+
* Number(aValue) + Number(ctx.$form.b)
|
|
1193
|
+
* )
|
|
1194
|
+
*/
|
|
1195
|
+
customClientEvaluation(computationFn: (fieldValue: unknown, context: ClientFunctionContext) => unknown): CodeToEvaluate;
|
|
852
1196
|
};
|
|
853
1197
|
export {};
|
|
854
1198
|
//# sourceMappingURL=conditionals.d.ts.map
|
|
@@ -12,6 +12,54 @@ import { ActionType } from '../events/ActionType';
|
|
|
12
12
|
import { EventConfig } from '../events/EventConfig';
|
|
13
13
|
import { EventDocument } from '../events/EventDocument';
|
|
14
14
|
import { EventIndex } from '../events/EventIndex';
|
|
15
|
+
import { Location } from '../events/locations';
|
|
16
|
+
import { SystemVariables } from '../events/TemplateConfig';
|
|
17
|
+
/** Returns today's date as an ISO date string (YYYY-MM-DD). */
|
|
18
|
+
export declare function todayISO(): string;
|
|
19
|
+
/**
|
|
20
|
+
* Context passed to every serialised client-side function ({@link runClientFunction}).
|
|
21
|
+
*
|
|
22
|
+
* `$user` (full {@link ITokenPayload}, validator paths) and `user` (a
|
|
23
|
+
* {@link SystemVariables} subset for template substitution, default-value
|
|
24
|
+
* path) are distinct sources, not duplicates.
|
|
25
|
+
*/
|
|
26
|
+
export type ClientFunctionContext = {
|
|
27
|
+
$form: EventState | ActionUpdate;
|
|
28
|
+
$now: string;
|
|
29
|
+
$online: boolean;
|
|
30
|
+
$user?: ITokenPayload;
|
|
31
|
+
$event?: EventDocument;
|
|
32
|
+
$leafAdminStructureLocationIds: Array<{
|
|
33
|
+
id: UUID;
|
|
34
|
+
}>;
|
|
35
|
+
user?: SystemVariables['user'];
|
|
36
|
+
$window?: SystemVariables['$window'];
|
|
37
|
+
locations?: Location[];
|
|
38
|
+
adminLevelIds?: string[];
|
|
39
|
+
$flags?: string[];
|
|
40
|
+
$status?: string;
|
|
41
|
+
};
|
|
42
|
+
type CompiledClientFunction = (data: FieldValue | undefined, context: ClientFunctionContext) => unknown;
|
|
43
|
+
/**
|
|
44
|
+
* Deserialises a serialised function string (produced by `.toString()`) into a callable.
|
|
45
|
+
* Results are cached by code string so each unique function body is compiled at most once.
|
|
46
|
+
* Runs in a clean scope — no access to outer closures or external imports.
|
|
47
|
+
*/
|
|
48
|
+
export declare function compileClientFunction(code: string): CompiledClientFunction;
|
|
49
|
+
export declare function buildClientFunctionContext(input: {
|
|
50
|
+
form: EventState | ActionUpdate;
|
|
51
|
+
validatorContext?: ValidatorContext;
|
|
52
|
+
systemVariables?: SystemVariables;
|
|
53
|
+
/**
|
|
54
|
+
* In real use cases, there can be hundreds of thousands of locations.
|
|
55
|
+
* Make sure that the context contains only the locations that are needed for validation.
|
|
56
|
+
* E.g. if the user is a leaf admin, only the leaf locations under their admin structure are needed.
|
|
57
|
+
* Loading few megabytes of locations to memory just for validation is not efficient and will choke the application.
|
|
58
|
+
*/
|
|
59
|
+
locations?: Location[];
|
|
60
|
+
adminLevelIds?: string[];
|
|
61
|
+
}): ClientFunctionContext;
|
|
62
|
+
export declare function runClientFunction(code: string, data: FieldValue | undefined, context: ClientFunctionContext): unknown;
|
|
15
63
|
/**
|
|
16
64
|
* Precompiles action conditional schemas from the event configurations to improve performance of condition validation later on.
|
|
17
65
|
* Best called once on application startup before any condition validation is done.
|
|
@@ -20,8 +68,8 @@ export declare function precompileActionSchemas(eventConfigurations: EventConfig
|
|
|
20
68
|
export declare function validate(schema: JSONSchema, data: ConditionalParameters): boolean;
|
|
21
69
|
export declare function validateValue(schema: JSONSchema, data: unknown): boolean;
|
|
22
70
|
export declare function isOnline(): boolean;
|
|
23
|
-
export declare function isConditionMet(conditional: JSONSchema, values: EventState | ActionUpdate, context: ValidatorContext
|
|
24
|
-
export declare function areConditionsMet(conditions: FieldConditional[], values: Record<string, FieldValue>, context: ValidatorContext,
|
|
71
|
+
export declare function isConditionMet(conditional: JSONSchema, values: EventState | ActionUpdate, context: ValidatorContext): boolean;
|
|
72
|
+
export declare function areConditionsMet(conditions: FieldConditional[], values: Record<string, FieldValue>, context: ValidatorContext, _event: EventIndex): boolean;
|
|
25
73
|
export type ValidatorContext = {
|
|
26
74
|
user?: ITokenPayload;
|
|
27
75
|
leafAdminStructureLocationIds?: Array<{
|
|
@@ -113,4 +161,5 @@ export declare function runFieldValidations({ field: config, form, value, contex
|
|
|
113
161
|
}>>;
|
|
114
162
|
export declare function getValidatorsForField(fieldId: FieldConfig['id'], validations: NonNullable<FieldConfig['validation']>): NonNullable<FieldConfig['validation']>;
|
|
115
163
|
export declare function areCertificateConditionsMet(conditions: FieldConditional[], values: ConditionalParameters): boolean;
|
|
164
|
+
export {};
|
|
116
165
|
//# sourceMappingURL=validate.d.ts.map
|