@opencrvs/toolkit 1.9.12 → 1.9.13-rc.00bb36c
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/commons/api/router.d.ts +2508 -185
- package/dist/commons/conditionals/conditionals.d.ts +348 -4
- package/dist/commons/conditionals/validate.d.ts +42 -0
- package/dist/commons/events/ActionConfig.d.ts +28 -28
- package/dist/commons/events/ActionInput.d.ts +204 -0
- package/dist/commons/events/AdvancedSearchConfig.d.ts +48 -48
- package/dist/commons/events/CountryConfigQueryInput.d.ts +240 -240
- package/dist/commons/events/DeduplicationConfig.d.ts +2 -2
- package/dist/commons/events/Draft.d.ts +6 -0
- package/dist/commons/events/EventConfig.d.ts +61 -54
- package/dist/commons/events/EventIndex.d.ts +88 -88
- package/dist/commons/events/FieldConfig.d.ts +1619 -227
- package/dist/commons/events/WorkqueueConfig.d.ts +488 -488
- package/dist/commons/events/defineConfig.d.ts +8 -7
- package/dist/commons/events/field.d.ts +47 -1
- package/dist/commons/events/utils.d.ts +10 -178
- package/dist/conditionals/index.js +48 -1
- package/dist/events/index.js +189 -85
- package/dist/notification/index.js +150 -39
- package/package.json +11 -7
|
@@ -1,11 +1,12 @@
|
|
|
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, 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
7
|
import { todayDateTimeValueSerializer } from '../events/serializers/date/serializer';
|
|
8
|
-
import { FieldReference } from '../events/FieldConfig';
|
|
8
|
+
import { CodeToEvaluate, FieldReference } from '../events/FieldConfig';
|
|
9
|
+
import type { ClientFunctionContext } from './validate';
|
|
9
10
|
/** @knipignore */
|
|
10
11
|
export type JSONSchema = {
|
|
11
12
|
$id: string;
|
|
@@ -24,7 +25,7 @@ export type EventConditionalParameters = CommonConditionalParameters & {
|
|
|
24
25
|
$event: EventDocument;
|
|
25
26
|
};
|
|
26
27
|
export type FormConditionalParameters = CommonConditionalParameters & {
|
|
27
|
-
$form: EventState |
|
|
28
|
+
$form: EventState | ActionUpdate;
|
|
28
29
|
$leafAdminStructureLocationIds?: Array<{
|
|
29
30
|
id: UUID;
|
|
30
31
|
}>;
|
|
@@ -81,7 +82,9 @@ export declare const user: typeof userSerializer & {
|
|
|
81
82
|
};
|
|
82
83
|
};
|
|
83
84
|
export declare function isFieldReference(value: unknown): value is FieldReference;
|
|
84
|
-
export declare function isEventFieldReference(value: unknown): value is
|
|
85
|
+
export declare function isEventFieldReference(value: unknown): value is {
|
|
86
|
+
$$event: string;
|
|
87
|
+
};
|
|
85
88
|
/**
|
|
86
89
|
* Generate conditional rules for a form field.
|
|
87
90
|
*
|
|
@@ -172,6 +175,37 @@ export declare function createFieldConditionals(fieldId: string): {
|
|
|
172
175
|
* )
|
|
173
176
|
*/
|
|
174
177
|
object: (options: Record<string, any>) => JSONSchema;
|
|
178
|
+
/**
|
|
179
|
+
* Custom client-side validator. The provided function is serialised and executed
|
|
180
|
+
* just-in-time on the client only. External references (e.g. lodash) are not
|
|
181
|
+
* available inside the function body — all logic must be self-contained.
|
|
182
|
+
*
|
|
183
|
+
* @example
|
|
184
|
+
* field('nid').customClientValidator((value) => {
|
|
185
|
+
* // LUHN check — all logic must be inline
|
|
186
|
+
* const digits = String(value).split('').map(Number)
|
|
187
|
+
* // ...
|
|
188
|
+
* return isValid
|
|
189
|
+
* })
|
|
190
|
+
*/
|
|
191
|
+
customClientValidator(validationFn: (fieldValue: unknown, context: ClientFunctionContext) => boolean): JSONSchema;
|
|
192
|
+
/**
|
|
193
|
+
* Custom client-side evaluation. Returns a {@link FieldReference} descriptor
|
|
194
|
+
* that can be used as the `value` property or a DATA component entry.
|
|
195
|
+
* The function receives the referenced field's value as the first argument and
|
|
196
|
+
* the full form context as the second; its return value replaces the field reference.
|
|
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
|
+
* For computing a default value without referencing a specific field, use
|
|
201
|
+
* `evaluate(fn)` in the `defaultValue` property instead.
|
|
202
|
+
*
|
|
203
|
+
* @example
|
|
204
|
+
* field('a').customClientEvaluation((aValue, ctx) =>
|
|
205
|
+
* Number(aValue) + Number(ctx.$form.b)
|
|
206
|
+
* )
|
|
207
|
+
*/
|
|
208
|
+
customClientEvaluation(computationFn: (fieldValue: unknown, context: ClientFunctionContext) => unknown): CodeToEvaluate;
|
|
175
209
|
};
|
|
176
210
|
asDob(): any;
|
|
177
211
|
asAge(): any;
|
|
@@ -231,6 +265,37 @@ export declare function createFieldConditionals(fieldId: string): {
|
|
|
231
265
|
* )
|
|
232
266
|
*/
|
|
233
267
|
object: (options: Record<string, any>) => JSONSchema;
|
|
268
|
+
/**
|
|
269
|
+
* Custom client-side validator. The provided function is serialised and executed
|
|
270
|
+
* just-in-time on the client only. External references (e.g. lodash) are not
|
|
271
|
+
* available inside the function body — all logic must be self-contained.
|
|
272
|
+
*
|
|
273
|
+
* @example
|
|
274
|
+
* field('nid').customClientValidator((value) => {
|
|
275
|
+
* // LUHN check — all logic must be inline
|
|
276
|
+
* const digits = String(value).split('').map(Number)
|
|
277
|
+
* // ...
|
|
278
|
+
* return isValid
|
|
279
|
+
* })
|
|
280
|
+
*/
|
|
281
|
+
customClientValidator(validationFn: (fieldValue: unknown, context: ClientFunctionContext) => boolean): JSONSchema;
|
|
282
|
+
/**
|
|
283
|
+
* Custom client-side evaluation. Returns a {@link FieldReference} descriptor
|
|
284
|
+
* that can be used as the `value` property or a DATA component entry.
|
|
285
|
+
* The function receives the referenced field's value as the first argument and
|
|
286
|
+
* the full form context as the second; its return value replaces the field reference.
|
|
287
|
+
* The function is serialised and executed just-in-time on the client only.
|
|
288
|
+
* External references (e.g. lodash) are not available inside the function body.
|
|
289
|
+
*
|
|
290
|
+
* For computing a default value without referencing a specific field, use
|
|
291
|
+
* `evaluate(fn)` in the `defaultValue` property instead.
|
|
292
|
+
*
|
|
293
|
+
* @example
|
|
294
|
+
* field('a').customClientEvaluation((aValue, ctx) =>
|
|
295
|
+
* Number(aValue) + Number(ctx.$form.b)
|
|
296
|
+
* )
|
|
297
|
+
*/
|
|
298
|
+
customClientEvaluation(computationFn: (fieldValue: unknown, context: ClientFunctionContext) => unknown): CodeToEvaluate;
|
|
234
299
|
};
|
|
235
300
|
getByPath(fieldPath: string[]): {
|
|
236
301
|
$$subfield: string[];
|
|
@@ -304,6 +369,37 @@ export declare function createFieldConditionals(fieldId: string): {
|
|
|
304
369
|
* )
|
|
305
370
|
*/
|
|
306
371
|
object: (options: Record<string, any>) => JSONSchema;
|
|
372
|
+
/**
|
|
373
|
+
* Custom client-side validator. The provided function is serialised and executed
|
|
374
|
+
* just-in-time on the client only. External references (e.g. lodash) are not
|
|
375
|
+
* available inside the function body — all logic must be self-contained.
|
|
376
|
+
*
|
|
377
|
+
* @example
|
|
378
|
+
* field('nid').customClientValidator((value) => {
|
|
379
|
+
* // LUHN check — all logic must be inline
|
|
380
|
+
* const digits = String(value).split('').map(Number)
|
|
381
|
+
* // ...
|
|
382
|
+
* return isValid
|
|
383
|
+
* })
|
|
384
|
+
*/
|
|
385
|
+
customClientValidator(validationFn: (fieldValue: unknown, context: ClientFunctionContext) => boolean): JSONSchema;
|
|
386
|
+
/**
|
|
387
|
+
* Custom client-side evaluation. Returns a {@link FieldReference} descriptor
|
|
388
|
+
* that can be used as the `value` property or a DATA component entry.
|
|
389
|
+
* The function receives the referenced field's value as the first argument and
|
|
390
|
+
* the full form context as the second; its return value replaces the field reference.
|
|
391
|
+
* The function is serialised and executed just-in-time on the client only.
|
|
392
|
+
* External references (e.g. lodash) are not available inside the function body.
|
|
393
|
+
*
|
|
394
|
+
* For computing a default value without referencing a specific field, use
|
|
395
|
+
* `evaluate(fn)` in the `defaultValue` property instead.
|
|
396
|
+
*
|
|
397
|
+
* @example
|
|
398
|
+
* field('a').customClientEvaluation((aValue, ctx) =>
|
|
399
|
+
* Number(aValue) + Number(ctx.$form.b)
|
|
400
|
+
* )
|
|
401
|
+
*/
|
|
402
|
+
customClientEvaluation(computationFn: (fieldValue: unknown, context: ClientFunctionContext) => unknown): CodeToEvaluate;
|
|
307
403
|
};
|
|
308
404
|
getByPath(fieldPath: string[]): any;
|
|
309
405
|
asDob(): {
|
|
@@ -372,6 +468,37 @@ export declare function createFieldConditionals(fieldId: string): {
|
|
|
372
468
|
* )
|
|
373
469
|
*/
|
|
374
470
|
object: (options: Record<string, any>) => JSONSchema;
|
|
471
|
+
/**
|
|
472
|
+
* Custom client-side validator. The provided function is serialised and executed
|
|
473
|
+
* just-in-time on the client only. External references (e.g. lodash) are not
|
|
474
|
+
* available inside the function body — all logic must be self-contained.
|
|
475
|
+
*
|
|
476
|
+
* @example
|
|
477
|
+
* field('nid').customClientValidator((value) => {
|
|
478
|
+
* // LUHN check — all logic must be inline
|
|
479
|
+
* const digits = String(value).split('').map(Number)
|
|
480
|
+
* // ...
|
|
481
|
+
* return isValid
|
|
482
|
+
* })
|
|
483
|
+
*/
|
|
484
|
+
customClientValidator(validationFn: (fieldValue: unknown, context: ClientFunctionContext) => boolean): JSONSchema;
|
|
485
|
+
/**
|
|
486
|
+
* Custom client-side evaluation. Returns a {@link FieldReference} descriptor
|
|
487
|
+
* that can be used as the `value` property or a DATA component entry.
|
|
488
|
+
* The function receives the referenced field's value as the first argument and
|
|
489
|
+
* the full form context as the second; its return value replaces the field reference.
|
|
490
|
+
* The function is serialised and executed just-in-time on the client only.
|
|
491
|
+
* External references (e.g. lodash) are not available inside the function body.
|
|
492
|
+
*
|
|
493
|
+
* For computing a default value without referencing a specific field, use
|
|
494
|
+
* `evaluate(fn)` in the `defaultValue` property instead.
|
|
495
|
+
*
|
|
496
|
+
* @example
|
|
497
|
+
* field('a').customClientEvaluation((aValue, ctx) =>
|
|
498
|
+
* Number(aValue) + Number(ctx.$form.b)
|
|
499
|
+
* )
|
|
500
|
+
*/
|
|
501
|
+
customClientEvaluation(computationFn: (fieldValue: unknown, context: ClientFunctionContext) => unknown): CodeToEvaluate;
|
|
375
502
|
};
|
|
376
503
|
asAge(): {
|
|
377
504
|
$$subfield: string[];
|
|
@@ -439,6 +566,37 @@ export declare function createFieldConditionals(fieldId: string): {
|
|
|
439
566
|
* )
|
|
440
567
|
*/
|
|
441
568
|
object: (options: Record<string, any>) => JSONSchema;
|
|
569
|
+
/**
|
|
570
|
+
* Custom client-side validator. The provided function is serialised and executed
|
|
571
|
+
* just-in-time on the client only. External references (e.g. lodash) are not
|
|
572
|
+
* available inside the function body — all logic must be self-contained.
|
|
573
|
+
*
|
|
574
|
+
* @example
|
|
575
|
+
* field('nid').customClientValidator((value) => {
|
|
576
|
+
* // LUHN check — all logic must be inline
|
|
577
|
+
* const digits = String(value).split('').map(Number)
|
|
578
|
+
* // ...
|
|
579
|
+
* return isValid
|
|
580
|
+
* })
|
|
581
|
+
*/
|
|
582
|
+
customClientValidator(validationFn: (fieldValue: unknown, context: ClientFunctionContext) => boolean): JSONSchema;
|
|
583
|
+
/**
|
|
584
|
+
* Custom client-side evaluation. Returns a {@link FieldReference} descriptor
|
|
585
|
+
* that can be used as the `value` property or a DATA component entry.
|
|
586
|
+
* The function receives the referenced field's value as the first argument and
|
|
587
|
+
* the full form context as the second; its return value replaces the field reference.
|
|
588
|
+
* The function is serialised and executed just-in-time on the client only.
|
|
589
|
+
* External references (e.g. lodash) are not available inside the function body.
|
|
590
|
+
*
|
|
591
|
+
* For computing a default value without referencing a specific field, use
|
|
592
|
+
* `evaluate(fn)` in the `defaultValue` property instead.
|
|
593
|
+
*
|
|
594
|
+
* @example
|
|
595
|
+
* field('a').customClientEvaluation((aValue, ctx) =>
|
|
596
|
+
* Number(aValue) + Number(ctx.$form.b)
|
|
597
|
+
* )
|
|
598
|
+
*/
|
|
599
|
+
customClientEvaluation(computationFn: (fieldValue: unknown, context: ClientFunctionContext) => unknown): CodeToEvaluate;
|
|
442
600
|
};
|
|
443
601
|
isAfter(): {
|
|
444
602
|
days: (days: number) => {
|
|
@@ -496,6 +654,37 @@ export declare function createFieldConditionals(fieldId: string): {
|
|
|
496
654
|
* )
|
|
497
655
|
*/
|
|
498
656
|
object: (options: Record<string, any>) => JSONSchema;
|
|
657
|
+
/**
|
|
658
|
+
* Custom client-side validator. The provided function is serialised and executed
|
|
659
|
+
* just-in-time on the client only. External references (e.g. lodash) are not
|
|
660
|
+
* available inside the function body — all logic must be self-contained.
|
|
661
|
+
*
|
|
662
|
+
* @example
|
|
663
|
+
* field('nid').customClientValidator((value) => {
|
|
664
|
+
* // LUHN check — all logic must be inline
|
|
665
|
+
* const digits = String(value).split('').map(Number)
|
|
666
|
+
* // ...
|
|
667
|
+
* return isValid
|
|
668
|
+
* })
|
|
669
|
+
*/
|
|
670
|
+
customClientValidator(validationFn: (fieldValue: unknown, context: ClientFunctionContext) => boolean): JSONSchema;
|
|
671
|
+
/**
|
|
672
|
+
* Custom client-side evaluation. Returns a {@link FieldReference} descriptor
|
|
673
|
+
* that can be used as the `value` property or a DATA component entry.
|
|
674
|
+
* The function receives the referenced field's value as the first argument and
|
|
675
|
+
* the full form context as the second; its return value replaces the field reference.
|
|
676
|
+
* The function is serialised and executed just-in-time on the client only.
|
|
677
|
+
* External references (e.g. lodash) are not available inside the function body.
|
|
678
|
+
*
|
|
679
|
+
* For computing a default value without referencing a specific field, use
|
|
680
|
+
* `evaluate(fn)` in the `defaultValue` property instead.
|
|
681
|
+
*
|
|
682
|
+
* @example
|
|
683
|
+
* field('a').customClientEvaluation((aValue, ctx) =>
|
|
684
|
+
* Number(aValue) + Number(ctx.$form.b)
|
|
685
|
+
* )
|
|
686
|
+
*/
|
|
687
|
+
customClientEvaluation(computationFn: (fieldValue: unknown, context: ClientFunctionContext) => unknown): CodeToEvaluate;
|
|
499
688
|
};
|
|
500
689
|
asDob(): {
|
|
501
690
|
$$subfield: string[];
|
|
@@ -570,6 +759,37 @@ export declare function createFieldConditionals(fieldId: string): {
|
|
|
570
759
|
* )
|
|
571
760
|
*/
|
|
572
761
|
object: (options: Record<string, any>) => JSONSchema;
|
|
762
|
+
/**
|
|
763
|
+
* Custom client-side validator. The provided function is serialised and executed
|
|
764
|
+
* just-in-time on the client only. External references (e.g. lodash) are not
|
|
765
|
+
* available inside the function body — all logic must be self-contained.
|
|
766
|
+
*
|
|
767
|
+
* @example
|
|
768
|
+
* field('nid').customClientValidator((value) => {
|
|
769
|
+
* // LUHN check — all logic must be inline
|
|
770
|
+
* const digits = String(value).split('').map(Number)
|
|
771
|
+
* // ...
|
|
772
|
+
* return isValid
|
|
773
|
+
* })
|
|
774
|
+
*/
|
|
775
|
+
customClientValidator(validationFn: (fieldValue: unknown, context: ClientFunctionContext) => boolean): JSONSchema;
|
|
776
|
+
/**
|
|
777
|
+
* Custom client-side evaluation. Returns a {@link FieldReference} descriptor
|
|
778
|
+
* that can be used as the `value` property or a DATA component entry.
|
|
779
|
+
* The function receives the referenced field's value as the first argument and
|
|
780
|
+
* the full form context as the second; its return value replaces the field reference.
|
|
781
|
+
* The function is serialised and executed just-in-time on the client only.
|
|
782
|
+
* External references (e.g. lodash) are not available inside the function body.
|
|
783
|
+
*
|
|
784
|
+
* For computing a default value without referencing a specific field, use
|
|
785
|
+
* `evaluate(fn)` in the `defaultValue` property instead.
|
|
786
|
+
*
|
|
787
|
+
* @example
|
|
788
|
+
* field('a').customClientEvaluation((aValue, ctx) =>
|
|
789
|
+
* Number(aValue) + Number(ctx.$form.b)
|
|
790
|
+
* )
|
|
791
|
+
*/
|
|
792
|
+
customClientEvaluation(computationFn: (fieldValue: unknown, context: ClientFunctionContext) => unknown): CodeToEvaluate;
|
|
573
793
|
};
|
|
574
794
|
asDob(): any;
|
|
575
795
|
asAge(): any;
|
|
@@ -629,6 +849,37 @@ export declare function createFieldConditionals(fieldId: string): {
|
|
|
629
849
|
* )
|
|
630
850
|
*/
|
|
631
851
|
object: (options: Record<string, any>) => JSONSchema;
|
|
852
|
+
/**
|
|
853
|
+
* Custom client-side validator. The provided function is serialised and executed
|
|
854
|
+
* just-in-time on the client only. External references (e.g. lodash) are not
|
|
855
|
+
* available inside the function body — all logic must be self-contained.
|
|
856
|
+
*
|
|
857
|
+
* @example
|
|
858
|
+
* field('nid').customClientValidator((value) => {
|
|
859
|
+
* // LUHN check — all logic must be inline
|
|
860
|
+
* const digits = String(value).split('').map(Number)
|
|
861
|
+
* // ...
|
|
862
|
+
* return isValid
|
|
863
|
+
* })
|
|
864
|
+
*/
|
|
865
|
+
customClientValidator(validationFn: (fieldValue: unknown, context: ClientFunctionContext) => boolean): JSONSchema;
|
|
866
|
+
/**
|
|
867
|
+
* Custom client-side evaluation. Returns a {@link FieldReference} descriptor
|
|
868
|
+
* that can be used as the `value` property or a DATA component entry.
|
|
869
|
+
* The function receives the referenced field's value as the first argument and
|
|
870
|
+
* the full form context as the second; its return value replaces the field reference.
|
|
871
|
+
* The function is serialised and executed just-in-time on the client only.
|
|
872
|
+
* External references (e.g. lodash) are not available inside the function body.
|
|
873
|
+
*
|
|
874
|
+
* For computing a default value without referencing a specific field, use
|
|
875
|
+
* `evaluate(fn)` in the `defaultValue` property instead.
|
|
876
|
+
*
|
|
877
|
+
* @example
|
|
878
|
+
* field('a').customClientEvaluation((aValue, ctx) =>
|
|
879
|
+
* Number(aValue) + Number(ctx.$form.b)
|
|
880
|
+
* )
|
|
881
|
+
*/
|
|
882
|
+
customClientEvaluation(computationFn: (fieldValue: unknown, context: ClientFunctionContext) => unknown): CodeToEvaluate;
|
|
632
883
|
};
|
|
633
884
|
asAge(): {
|
|
634
885
|
$$subfield: string[];
|
|
@@ -703,6 +954,37 @@ export declare function createFieldConditionals(fieldId: string): {
|
|
|
703
954
|
* )
|
|
704
955
|
*/
|
|
705
956
|
object: (options: Record<string, any>) => JSONSchema;
|
|
957
|
+
/**
|
|
958
|
+
* Custom client-side validator. The provided function is serialised and executed
|
|
959
|
+
* just-in-time on the client only. External references (e.g. lodash) are not
|
|
960
|
+
* available inside the function body — all logic must be self-contained.
|
|
961
|
+
*
|
|
962
|
+
* @example
|
|
963
|
+
* field('nid').customClientValidator((value) => {
|
|
964
|
+
* // LUHN check — all logic must be inline
|
|
965
|
+
* const digits = String(value).split('').map(Number)
|
|
966
|
+
* // ...
|
|
967
|
+
* return isValid
|
|
968
|
+
* })
|
|
969
|
+
*/
|
|
970
|
+
customClientValidator(validationFn: (fieldValue: unknown, context: ClientFunctionContext) => boolean): JSONSchema;
|
|
971
|
+
/**
|
|
972
|
+
* Custom client-side evaluation. Returns a {@link FieldReference} descriptor
|
|
973
|
+
* that can be used as the `value` property or a DATA component entry.
|
|
974
|
+
* The function receives the referenced field's value as the first argument and
|
|
975
|
+
* the full form context as the second; its return value replaces the field reference.
|
|
976
|
+
* The function is serialised and executed just-in-time on the client only.
|
|
977
|
+
* External references (e.g. lodash) are not available inside the function body.
|
|
978
|
+
*
|
|
979
|
+
* For computing a default value without referencing a specific field, use
|
|
980
|
+
* `evaluate(fn)` in the `defaultValue` property instead.
|
|
981
|
+
*
|
|
982
|
+
* @example
|
|
983
|
+
* field('a').customClientEvaluation((aValue, ctx) =>
|
|
984
|
+
* Number(aValue) + Number(ctx.$form.b)
|
|
985
|
+
* )
|
|
986
|
+
*/
|
|
987
|
+
customClientEvaluation(computationFn: (fieldValue: unknown, context: ClientFunctionContext) => unknown): CodeToEvaluate;
|
|
706
988
|
};
|
|
707
989
|
asDob(): any;
|
|
708
990
|
asAge(): any;
|
|
@@ -762,6 +1044,37 @@ export declare function createFieldConditionals(fieldId: string): {
|
|
|
762
1044
|
* )
|
|
763
1045
|
*/
|
|
764
1046
|
object: (options: Record<string, any>) => JSONSchema;
|
|
1047
|
+
/**
|
|
1048
|
+
* Custom client-side validator. The provided function is serialised and executed
|
|
1049
|
+
* just-in-time on the client only. External references (e.g. lodash) are not
|
|
1050
|
+
* available inside the function body — all logic must be self-contained.
|
|
1051
|
+
*
|
|
1052
|
+
* @example
|
|
1053
|
+
* field('nid').customClientValidator((value) => {
|
|
1054
|
+
* // LUHN check — all logic must be inline
|
|
1055
|
+
* const digits = String(value).split('').map(Number)
|
|
1056
|
+
* // ...
|
|
1057
|
+
* return isValid
|
|
1058
|
+
* })
|
|
1059
|
+
*/
|
|
1060
|
+
customClientValidator(validationFn: (fieldValue: unknown, context: ClientFunctionContext) => boolean): JSONSchema;
|
|
1061
|
+
/**
|
|
1062
|
+
* Custom client-side evaluation. Returns a {@link FieldReference} descriptor
|
|
1063
|
+
* that can be used as the `value` property or a DATA component entry.
|
|
1064
|
+
* The function receives the referenced field's value as the first argument and
|
|
1065
|
+
* the full form context as the second; its return value replaces the field reference.
|
|
1066
|
+
* The function is serialised and executed just-in-time on the client only.
|
|
1067
|
+
* External references (e.g. lodash) are not available inside the function body.
|
|
1068
|
+
*
|
|
1069
|
+
* For computing a default value without referencing a specific field, use
|
|
1070
|
+
* `evaluate(fn)` in the `defaultValue` property instead.
|
|
1071
|
+
*
|
|
1072
|
+
* @example
|
|
1073
|
+
* field('a').customClientEvaluation((aValue, ctx) =>
|
|
1074
|
+
* Number(aValue) + Number(ctx.$form.b)
|
|
1075
|
+
* )
|
|
1076
|
+
*/
|
|
1077
|
+
customClientEvaluation(computationFn: (fieldValue: unknown, context: ClientFunctionContext) => unknown): CodeToEvaluate;
|
|
765
1078
|
};
|
|
766
1079
|
isAfter(): {
|
|
767
1080
|
days: (days: number) => {
|
|
@@ -819,6 +1132,37 @@ export declare function createFieldConditionals(fieldId: string): {
|
|
|
819
1132
|
* )
|
|
820
1133
|
*/
|
|
821
1134
|
object: (options: Record<string, any>) => JSONSchema;
|
|
1135
|
+
/**
|
|
1136
|
+
* Custom client-side validator. The provided function is serialised and executed
|
|
1137
|
+
* just-in-time on the client only. External references (e.g. lodash) are not
|
|
1138
|
+
* available inside the function body — all logic must be self-contained.
|
|
1139
|
+
*
|
|
1140
|
+
* @example
|
|
1141
|
+
* field('nid').customClientValidator((value) => {
|
|
1142
|
+
* // LUHN check — all logic must be inline
|
|
1143
|
+
* const digits = String(value).split('').map(Number)
|
|
1144
|
+
* // ...
|
|
1145
|
+
* return isValid
|
|
1146
|
+
* })
|
|
1147
|
+
*/
|
|
1148
|
+
customClientValidator(validationFn: (fieldValue: unknown, context: ClientFunctionContext) => boolean): JSONSchema;
|
|
1149
|
+
/**
|
|
1150
|
+
* Custom client-side evaluation. Returns a {@link FieldReference} descriptor
|
|
1151
|
+
* that can be used as the `value` property or a DATA component entry.
|
|
1152
|
+
* The function receives the referenced field's value as the first argument and
|
|
1153
|
+
* the full form context as the second; its return value replaces the field reference.
|
|
1154
|
+
* The function is serialised and executed just-in-time on the client only.
|
|
1155
|
+
* External references (e.g. lodash) are not available inside the function body.
|
|
1156
|
+
*
|
|
1157
|
+
* For computing a default value without referencing a specific field, use
|
|
1158
|
+
* `evaluate(fn)` in the `defaultValue` property instead.
|
|
1159
|
+
*
|
|
1160
|
+
* @example
|
|
1161
|
+
* field('a').customClientEvaluation((aValue, ctx) =>
|
|
1162
|
+
* Number(aValue) + Number(ctx.$form.b)
|
|
1163
|
+
* )
|
|
1164
|
+
*/
|
|
1165
|
+
customClientEvaluation(computationFn: (fieldValue: unknown, context: ClientFunctionContext) => unknown): CodeToEvaluate;
|
|
822
1166
|
};
|
|
823
1167
|
export {};
|
|
824
1168
|
//# sourceMappingURL=conditionals.d.ts.map
|
|
@@ -9,6 +9,46 @@ 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
|
+
import { Location } from '../events/locations';
|
|
13
|
+
import { SystemVariables } from '../events/TemplateConfig';
|
|
14
|
+
/** Returns today's date as an ISO date string (YYYY-MM-DD). */
|
|
15
|
+
export declare function todayISO(): string;
|
|
16
|
+
/**
|
|
17
|
+
* Context passed to every serialised client-side function ({@link runClientFunction}).
|
|
18
|
+
*
|
|
19
|
+
* `$user` (full {@link ITokenPayload}, validator paths) and `user` (a
|
|
20
|
+
* {@link SystemVariables} subset for template substitution, default-value
|
|
21
|
+
* path) are distinct sources, not duplicates.
|
|
22
|
+
*/
|
|
23
|
+
export type ClientFunctionContext = {
|
|
24
|
+
$form: EventState | ActionUpdate;
|
|
25
|
+
$now: string;
|
|
26
|
+
$online: boolean;
|
|
27
|
+
$user?: ITokenPayload;
|
|
28
|
+
$event?: EventDocument;
|
|
29
|
+
$leafAdminStructureLocationIds: Array<{
|
|
30
|
+
id: UUID;
|
|
31
|
+
}>;
|
|
32
|
+
user?: SystemVariables['user'];
|
|
33
|
+
$window?: SystemVariables['$window'];
|
|
34
|
+
locations?: Location[];
|
|
35
|
+
adminLevelIds?: string[];
|
|
36
|
+
};
|
|
37
|
+
type CompiledClientFunction = (data: FieldValue | undefined, context: ClientFunctionContext) => unknown;
|
|
38
|
+
/**
|
|
39
|
+
* Deserialises a serialised function string (produced by `.toString()`) into a callable.
|
|
40
|
+
* Results are cached by code string so each unique function body is compiled at most once.
|
|
41
|
+
* Runs in a clean scope — no access to outer closures or external imports.
|
|
42
|
+
*/
|
|
43
|
+
export declare function compileClientFunction(code: string): CompiledClientFunction;
|
|
44
|
+
export declare function buildClientFunctionContext(input: {
|
|
45
|
+
form: EventState | ActionUpdate;
|
|
46
|
+
validatorContext?: ValidatorContext;
|
|
47
|
+
systemVariables?: SystemVariables;
|
|
48
|
+
locations?: Location[];
|
|
49
|
+
adminLevelIds?: string[];
|
|
50
|
+
}): ClientFunctionContext;
|
|
51
|
+
export declare function runClientFunction(code: string, data: FieldValue | undefined, context: ClientFunctionContext): unknown;
|
|
12
52
|
export declare function validate(schema: JSONSchema, data: ConditionalParameters): boolean;
|
|
13
53
|
export declare function validateValue(schema: JSONSchema, data: unknown): boolean;
|
|
14
54
|
export declare function isOnline(): boolean;
|
|
@@ -20,6 +60,7 @@ export type ValidatorContext = {
|
|
|
20
60
|
id: UUID;
|
|
21
61
|
}>;
|
|
22
62
|
event?: EventDocument;
|
|
63
|
+
baseFormState?: EventState;
|
|
23
64
|
};
|
|
24
65
|
export declare function isFieldVisible(field: FieldConfig, form: Partial<ActionUpdate | EventState>, context: ValidatorContext): boolean;
|
|
25
66
|
export declare function isFieldEnabled(field: FieldConfig, form: ActionUpdate | EventState, context: ValidatorContext): boolean;
|
|
@@ -101,4 +142,5 @@ export declare function runFieldValidations({ field: config, form, value, contex
|
|
|
101
142
|
}>>;
|
|
102
143
|
export declare function getValidatorsForField(fieldId: FieldConfig['id'], validations: NonNullable<FieldConfig['validation']>): NonNullable<FieldConfig['validation']>;
|
|
103
144
|
export declare function areCertificateConditionsMet(conditions: FieldConditional[], values: ConditionalParameters): boolean;
|
|
145
|
+
export {};
|
|
104
146
|
//# sourceMappingURL=validate.d.ts.map
|