@opencrvs/toolkit 1.8.0-rc.f876361 → 1.8.0-rc.f8a9481

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.
@@ -8,6 +8,7 @@ export type JSONSchema = {
8
8
  readonly __nominal__type: 'JSONSchema';
9
9
  };
10
10
  export declare function defineConditional(schema: any): JSONSchema;
11
+ export declare function defineFormConditional(schema: Record<string, unknown>): JSONSchema;
11
12
  export type UserConditionalParameters = {
12
13
  $now: string;
13
14
  $user: TokenPayload;
@@ -47,6 +48,12 @@ export declare function or(...conditions: AjvJSONSchema[]): JSONSchema;
47
48
  * @example not(field('foo').isEqualTo('bar'))
48
49
  */
49
50
  export declare function not(condition: AjvJSONSchema): JSONSchema;
51
+ /**
52
+ * Returns an JSON Schema object, which is treated as always invalid.
53
+ *
54
+ * @returns {JSONSchema} An schema object that always evaluates to false.
55
+ */
56
+ export declare function never(): JSONSchema;
50
57
  /**
51
58
  *
52
59
  * Generate conditional rules for user.
@@ -61,6 +68,10 @@ export declare const user: {
61
68
  export declare const event: {
62
69
  hasAction: (action: ActionType) => JSONSchema;
63
70
  };
71
+ type FieldReference = {
72
+ _fieldId: string;
73
+ [key: string]: unknown;
74
+ };
64
75
  /**
65
76
  * Generate conditional rules for a form field.
66
77
  *
@@ -73,13 +84,13 @@ export declare function field(fieldId: string): {
73
84
  /**
74
85
  * @private Internal property used for field reference tracking.
75
86
  */
76
- _returning: string;
87
+ _fieldId: string;
77
88
  isAfter: () => {
78
89
  days: (days: number) => {
79
90
  inPast: () => JSONSchema;
80
91
  inFuture: () => JSONSchema;
81
92
  };
82
- date: (date: string) => JSONSchema;
93
+ date: (date: string | FieldReference) => JSONSchema;
83
94
  now: () => JSONSchema;
84
95
  };
85
96
  isBefore: () => {
@@ -87,13 +98,10 @@ export declare function field(fieldId: string): {
87
98
  inPast: () => JSONSchema;
88
99
  inFuture: () => JSONSchema;
89
100
  };
90
- date: (date: string) => JSONSchema;
101
+ date: (date: string | FieldReference) => JSONSchema;
91
102
  now: () => JSONSchema;
92
103
  };
93
- isEqualTo: (value: string | boolean | {
94
- _returning: string;
95
- [key: string]: unknown;
96
- }) => JSONSchema;
104
+ isEqualTo: (value: string | boolean | FieldReference) => JSONSchema;
97
105
  /**
98
106
  * Use case: Some fields are rendered when selection is not made, or boolean false is explicitly selected.
99
107
  * @example field('recommender.none').isFalsy() vs not(field('recommender.none').isEqualTo(true))
@@ -106,7 +114,6 @@ export declare function field(fieldId: string): {
106
114
  isUndefined: () => JSONSchema;
107
115
  inArray: (values: string[]) => JSONSchema;
108
116
  isValidEnglishName: () => JSONSchema;
109
- isValidNationalId: () => JSONSchema;
110
117
  /**
111
118
  * Checks if the field value matches a given regular expression pattern.
112
119
  * @param pattern - The regular expression pattern to match the field value against.
@@ -3,9 +3,13 @@ import { EventState, ActionUpdate } from '../events/ActionDocument';
3
3
  import { FieldConfig } from '../events/FieldConfig';
4
4
  import { FieldUpdateValue } from '../events/FieldValue';
5
5
  import { TranslationConfig } from '../events/TranslationConfig';
6
+ import { FieldConditional } from '../events/Conditional';
6
7
  export declare function validate(schema: JSONSchema, data: ConditionalParameters): boolean;
8
+ export declare function isConditionMet(conditional: JSONSchema, values: Record<string, unknown>): boolean;
9
+ export declare function areConditionsMet(conditions: FieldConditional[], values: Record<string, unknown>): boolean;
7
10
  export declare function isFieldVisible(field: FieldConfig, form: ActionUpdate | EventState): boolean;
8
11
  export declare function isFieldEnabled(field: FieldConfig, form: ActionUpdate | EventState): boolean;
12
+ export declare function isFieldDisplayedOnReview(field: FieldConfig, form: ActionUpdate | EventState): boolean;
9
13
  export declare const errorMessages: {
10
14
  hiddenField: {
11
15
  id: string;
@@ -43,23 +47,6 @@ export type CustomZodToIntlErrorMap = {
43
47
  message: TranslationConfig;
44
48
  };
45
49
  };
46
- /**
47
- * Checks if a field has validation errors based on its type and custom conditionals.
48
- *
49
- * @returns an array of error messages for the field
50
- */
51
- export declare function getFieldValidationErrors({ field, values }: {
52
- field: FieldConfig;
53
- values: ActionUpdate;
54
- }): {
55
- errors: {
56
- message: {
57
- id: string;
58
- defaultMessage: string;
59
- description: string;
60
- };
61
- }[];
62
- };
63
50
  /**
64
51
  * Validates primitive fields defined by the FieldConfig type.
65
52
  * e.g. email is proper format, date is a valid date, etc.
@@ -71,4 +58,12 @@ export declare function validateFieldInput({ field, value }: {
71
58
  }): {
72
59
  message: TranslationConfig;
73
60
  }[];
61
+ export declare function runFieldValidations({ field, values }: {
62
+ field: FieldConfig;
63
+ values: ActionUpdate;
64
+ }): {
65
+ errors: {
66
+ message: TranslationConfig;
67
+ }[];
68
+ };
74
69
  //# sourceMappingURL=validate.d.ts.map