@opencrvs/toolkit 2.0.0-rc.0f51ec5 → 2.0.0-rc.0fb1707
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 +32 -44
- package/dist/commons/api/router.d.ts +15 -15
- package/dist/commons/application-config/index.d.ts +0 -1
- package/dist/commons/conditionals/conditionals.d.ts +4 -348
- package/dist/commons/conditionals/validate.d.ts +2 -51
- package/dist/commons/events/FieldConfig.d.ts +50 -377
- package/dist/commons/events/FieldValue.d.ts +0 -6
- package/dist/commons/events/field.d.ts +1 -47
- package/dist/commons/events/utils.d.ts +1 -1
- package/dist/conditionals/index.js +1 -48
- package/dist/events/index.js +77 -187
- package/dist/notification/index.js +34 -145
- package/opencrvs-toolkit-2.0.0-rc.0fb1707.tgz +0 -0
- package/package.json +1 -1
- package/opencrvs-toolkit-2.0.0-rc.0f51ec5.tgz +0 -0
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import { EventDocument } from '../events/EventDocument';
|
|
2
|
-
import {
|
|
2
|
+
import { 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 {
|
|
10
|
-
import type { ClientFunctionContext } from './validate';
|
|
9
|
+
import { FieldReference } from '../events/FieldConfig';
|
|
11
10
|
/** @knipignore */
|
|
12
11
|
export type JSONSchema = {
|
|
13
12
|
$id: string;
|
|
@@ -26,7 +25,7 @@ export type EventConditionalParameters = CommonConditionalParameters & {
|
|
|
26
25
|
$event: EventDocument;
|
|
27
26
|
};
|
|
28
27
|
export type FormConditionalParameters = CommonConditionalParameters & {
|
|
29
|
-
$form: EventState |
|
|
28
|
+
$form: EventState | Record<string, unknown>;
|
|
30
29
|
$leafAdminStructureLocationIds?: Array<{
|
|
31
30
|
id: UUID;
|
|
32
31
|
}>;
|
|
@@ -108,9 +107,7 @@ export declare const user: typeof userSerializer & {
|
|
|
108
107
|
};
|
|
109
108
|
};
|
|
110
109
|
export declare function isFieldReference(value: unknown): value is FieldReference;
|
|
111
|
-
export declare function isEventFieldReference(value: unknown): value is
|
|
112
|
-
$$event: string;
|
|
113
|
-
};
|
|
110
|
+
export declare function isEventFieldReference(value: unknown): value is FieldReference;
|
|
114
111
|
/** Check if an event flag is present */
|
|
115
112
|
export declare function flag(flagvalue: string): JSONSchema;
|
|
116
113
|
/** Check if an event flag is present */
|
|
@@ -205,37 +202,6 @@ export declare function createFieldConditionals(fieldId: string): {
|
|
|
205
202
|
* )
|
|
206
203
|
*/
|
|
207
204
|
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;
|
|
239
205
|
};
|
|
240
206
|
asDob(): any;
|
|
241
207
|
asAge(): any;
|
|
@@ -295,37 +261,6 @@ export declare function createFieldConditionals(fieldId: string): {
|
|
|
295
261
|
* )
|
|
296
262
|
*/
|
|
297
263
|
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;
|
|
329
264
|
};
|
|
330
265
|
getByPath(fieldPath: string[]): {
|
|
331
266
|
$$subfield: string[];
|
|
@@ -399,37 +334,6 @@ export declare function createFieldConditionals(fieldId: string): {
|
|
|
399
334
|
* )
|
|
400
335
|
*/
|
|
401
336
|
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;
|
|
433
337
|
};
|
|
434
338
|
getByPath(fieldPath: string[]): any;
|
|
435
339
|
asDob(): {
|
|
@@ -498,37 +402,6 @@ export declare function createFieldConditionals(fieldId: string): {
|
|
|
498
402
|
* )
|
|
499
403
|
*/
|
|
500
404
|
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;
|
|
532
405
|
};
|
|
533
406
|
asAge(): {
|
|
534
407
|
$$subfield: string[];
|
|
@@ -596,37 +469,6 @@ export declare function createFieldConditionals(fieldId: string): {
|
|
|
596
469
|
* )
|
|
597
470
|
*/
|
|
598
471
|
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;
|
|
630
472
|
};
|
|
631
473
|
isAfter(): {
|
|
632
474
|
days: (days: number) => {
|
|
@@ -684,37 +526,6 @@ export declare function createFieldConditionals(fieldId: string): {
|
|
|
684
526
|
* )
|
|
685
527
|
*/
|
|
686
528
|
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;
|
|
718
529
|
};
|
|
719
530
|
asDob(): {
|
|
720
531
|
$$subfield: string[];
|
|
@@ -789,37 +600,6 @@ export declare function createFieldConditionals(fieldId: string): {
|
|
|
789
600
|
* )
|
|
790
601
|
*/
|
|
791
602
|
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;
|
|
823
603
|
};
|
|
824
604
|
asDob(): any;
|
|
825
605
|
asAge(): any;
|
|
@@ -879,37 +659,6 @@ export declare function createFieldConditionals(fieldId: string): {
|
|
|
879
659
|
* )
|
|
880
660
|
*/
|
|
881
661
|
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;
|
|
913
662
|
};
|
|
914
663
|
asAge(): {
|
|
915
664
|
$$subfield: string[];
|
|
@@ -984,37 +733,6 @@ export declare function createFieldConditionals(fieldId: string): {
|
|
|
984
733
|
* )
|
|
985
734
|
*/
|
|
986
735
|
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;
|
|
1018
736
|
};
|
|
1019
737
|
asDob(): any;
|
|
1020
738
|
asAge(): any;
|
|
@@ -1074,37 +792,6 @@ export declare function createFieldConditionals(fieldId: string): {
|
|
|
1074
792
|
* )
|
|
1075
793
|
*/
|
|
1076
794
|
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;
|
|
1108
795
|
};
|
|
1109
796
|
isAfter(): {
|
|
1110
797
|
days: (days: number) => {
|
|
@@ -1162,37 +849,6 @@ export declare function createFieldConditionals(fieldId: string): {
|
|
|
1162
849
|
* )
|
|
1163
850
|
*/
|
|
1164
851
|
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;
|
|
1196
852
|
};
|
|
1197
853
|
export {};
|
|
1198
854
|
//# sourceMappingURL=conditionals.d.ts.map
|
|
@@ -12,54 +12,6 @@ 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;
|
|
63
15
|
/**
|
|
64
16
|
* Precompiles action conditional schemas from the event configurations to improve performance of condition validation later on.
|
|
65
17
|
* Best called once on application startup before any condition validation is done.
|
|
@@ -68,8 +20,8 @@ export declare function precompileActionSchemas(eventConfigurations: EventConfig
|
|
|
68
20
|
export declare function validate(schema: JSONSchema, data: ConditionalParameters): boolean;
|
|
69
21
|
export declare function validateValue(schema: JSONSchema, data: unknown): boolean;
|
|
70
22
|
export declare function isOnline(): boolean;
|
|
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,
|
|
23
|
+
export declare function isConditionMet(conditional: JSONSchema, values: EventState | ActionUpdate, context: ValidatorContext, eventIndex?: EventIndex): boolean;
|
|
24
|
+
export declare function areConditionsMet(conditions: FieldConditional[], values: Record<string, FieldValue>, context: ValidatorContext, event: EventIndex): boolean;
|
|
73
25
|
export type ValidatorContext = {
|
|
74
26
|
user?: ITokenPayload;
|
|
75
27
|
leafAdminStructureLocationIds?: Array<{
|
|
@@ -161,5 +113,4 @@ export declare function runFieldValidations({ field: config, form, value, contex
|
|
|
161
113
|
}>>;
|
|
162
114
|
export declare function getValidatorsForField(fieldId: FieldConfig['id'], validations: NonNullable<FieldConfig['validation']>): NonNullable<FieldConfig['validation']>;
|
|
163
115
|
export declare function areCertificateConditionsMet(conditions: FieldConditional[], values: ConditionalParameters): boolean;
|
|
164
|
-
export {};
|
|
165
116
|
//# sourceMappingURL=validate.d.ts.map
|