@opencrvs/toolkit 1.8.0-rc.faeb298 → 1.8.0-rc.fb0e687
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/README.md +1 -1
- package/dist/commons/api/router.d.ts +6658 -9554
- package/dist/commons/conditionals/conditionals.d.ts +26 -3
- package/dist/commons/conditionals/validate-address.test.d.ts +2 -0
- package/dist/commons/conditionals/validate.d.ts +39 -11
- package/dist/commons/conditionals/validate.test.d.ts +2 -0
- package/dist/commons/events/ActionConfig.d.ts +1047 -3208
- package/dist/commons/events/ActionDocument.d.ts +9482 -312
- package/dist/commons/events/ActionInput.d.ts +5244 -477
- package/dist/commons/events/ActionType.d.ts +25 -12
- package/dist/commons/events/CompositeFieldValue.d.ts +152 -2
- package/dist/commons/events/Conditional.d.ts +21 -5
- package/dist/commons/events/Draft.d.ts +348 -48
- package/dist/commons/events/EventConfig.d.ts +715 -2746
- package/dist/commons/events/EventConfigInput.d.ts +6 -3
- package/dist/commons/events/EventDocument.d.ts +3340 -429
- package/dist/commons/events/EventIndex.d.ts +6 -3
- package/dist/commons/events/EventMetadata.d.ts +3 -0
- package/dist/commons/events/FieldConfig.d.ts +384 -104
- package/dist/commons/events/FieldTypeMapping.d.ts +136 -5
- package/dist/commons/events/FieldValue.d.ts +76 -2
- package/dist/commons/events/FormConfig.d.ts +534 -201
- package/dist/commons/events/PageConfig.d.ts +335 -0
- package/dist/commons/events/TemplateConfig.d.ts +2 -2
- package/dist/commons/events/defineConfig.d.ts +72 -421
- package/dist/commons/events/index.d.ts +2 -1
- package/dist/commons/events/test.utils.d.ts +140 -213
- package/dist/commons/events/utils.d.ts +190 -125
- package/dist/conditionals/index.js +166 -81
- package/dist/events/index.js +1372 -826
- package/package.json +1 -1
@@ -1,146 +1,57 @@
|
|
1
|
-
import {
|
2
|
-
import { ActionType } from './ActionType';
|
1
|
+
import { ActionType, DeclarationActionType } from './ActionType';
|
3
2
|
import { EventConfig } from './EventConfig';
|
4
|
-
import { EventConfigInput } from './EventConfigInput';
|
5
|
-
import { EventMetadataKeys } from './EventMetadata';
|
6
3
|
import { FieldConfig } from './FieldConfig';
|
7
4
|
import { WorkqueueConfig } from './WorkqueueConfig';
|
8
|
-
import { EventState } from './ActionDocument';
|
5
|
+
import { ActionUpdate, EventState } from './ActionDocument';
|
6
|
+
import { PageConfig, VerificationPageConfig } from './PageConfig';
|
7
|
+
import { Draft } from './Draft';
|
8
|
+
import { EventDocument } from './EventDocument';
|
9
|
+
import { ActionConfig } from './ActionConfig';
|
9
10
|
import { FormConfig } from './FormConfig';
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
export declare const findInputPageFields: (config: EventConfigInput) => {
|
11
|
+
export declare function getDeclarationFields(configuration: EventConfig): FieldConfig[];
|
12
|
+
export declare function getDeclarationPages(configuration: EventConfig): {
|
13
|
+
type: "FORM";
|
14
14
|
id: string;
|
15
|
-
|
15
|
+
title: import("./TranslationConfig").TranslationConfig;
|
16
|
+
fields: import("./FieldConfig").Inferred[];
|
17
|
+
conditional?: import(".").JSONSchema | undefined;
|
16
18
|
}[];
|
19
|
+
export declare function getDeclaration(configuration: EventConfig): {
|
20
|
+
label: import("./TranslationConfig").TranslationConfig;
|
21
|
+
pages: {
|
22
|
+
type: "FORM";
|
23
|
+
id: string;
|
24
|
+
title: import("./TranslationConfig").TranslationConfig;
|
25
|
+
fields: import("./FieldConfig").Inferred[];
|
26
|
+
conditional?: import(".").JSONSchema | undefined;
|
27
|
+
}[];
|
28
|
+
};
|
29
|
+
export declare const getActionAnnotationFields: (actionConfig: ActionConfig) => import("./FieldConfig").Inferred[];
|
30
|
+
export declare const getAllAnnotationFields: (config: EventConfig) => FieldConfig[];
|
17
31
|
/**
|
18
32
|
* @returns All the fields in the event configuration.
|
19
33
|
*/
|
20
|
-
export declare const
|
34
|
+
export declare const findAllFields: (config: EventConfig) => FieldConfig[];
|
21
35
|
/**
|
22
|
-
*
|
23
|
-
* @param pageFields - All the fields in the event configuration
|
24
|
-
* @param refFields - The fields referencing values within the event configuration (e.g. summary fields) or within system provided metadata fields (e.g. createdAt, updatedBy)
|
25
|
-
* @returns referenced fields with populated labels
|
36
|
+
* @TODO: Request correction should have same format as print certificate
|
26
37
|
*/
|
27
|
-
export declare const
|
28
|
-
|
29
|
-
|
30
|
-
label: TranslationConfig;
|
31
|
-
}[];
|
32
|
-
refFields: {
|
33
|
-
id: EventMetadataKeys | string;
|
34
|
-
label?: TranslationConfig;
|
35
|
-
}[];
|
36
|
-
}) => {
|
37
|
-
id: EventMetadataKeys | string;
|
38
|
-
label?: TranslationConfig;
|
39
|
-
}[];
|
40
|
-
export declare function getAllFields(configuration: EventConfig): import("./FieldConfig").Inferred[];
|
41
|
-
export declare function getAllPages(configuration: EventConfig): ({
|
42
|
-
id: string;
|
43
|
-
title: TranslationConfig;
|
44
|
-
fields: import("./FieldConfig").Inferred[];
|
45
|
-
type?: "FORM" | undefined;
|
46
|
-
} | {
|
47
|
-
type: "VERIFICATION";
|
48
|
-
id: string;
|
49
|
-
title: TranslationConfig;
|
50
|
-
actions: {
|
51
|
-
verify: {
|
52
|
-
label: TranslationConfig;
|
53
|
-
};
|
54
|
-
cancel: {
|
55
|
-
label: TranslationConfig;
|
56
|
-
confirmation: {
|
57
|
-
title: TranslationConfig;
|
58
|
-
body: TranslationConfig;
|
59
|
-
};
|
60
|
-
};
|
61
|
-
};
|
38
|
+
export declare const findRecordActionPages: (config: EventConfig, actionType: ActionType) => PageConfig[];
|
39
|
+
export declare function getActionReview(configuration: EventConfig, actionType: ActionType): {
|
40
|
+
title: import("./TranslationConfig").TranslationConfig;
|
62
41
|
fields: import("./FieldConfig").Inferred[];
|
63
|
-
}
|
42
|
+
};
|
43
|
+
export declare function getActionReviewFields(configuration: EventConfig, actionType: DeclarationActionType): import("./FieldConfig").Inferred[];
|
64
44
|
export declare function validateWorkqueueConfig(workqueueConfigs: WorkqueueConfig[]): void;
|
65
|
-
export declare
|
66
|
-
|
67
|
-
|
68
|
-
id: string;
|
69
|
-
label: TranslationConfig;
|
70
|
-
};
|
71
|
-
label: TranslationConfig;
|
72
|
-
pages: ({
|
73
|
-
id: string;
|
74
|
-
title: TranslationConfig;
|
75
|
-
fields: import("./FieldConfig").Inferred[];
|
76
|
-
type?: "FORM" | undefined;
|
77
|
-
} | {
|
78
|
-
type: "VERIFICATION";
|
79
|
-
id: string;
|
80
|
-
title: TranslationConfig;
|
81
|
-
actions: {
|
82
|
-
verify: {
|
83
|
-
label: TranslationConfig;
|
84
|
-
};
|
85
|
-
cancel: {
|
86
|
-
label: TranslationConfig;
|
87
|
-
confirmation: {
|
88
|
-
title: TranslationConfig;
|
89
|
-
body: TranslationConfig;
|
90
|
-
};
|
91
|
-
};
|
92
|
-
};
|
93
|
-
fields: import("./FieldConfig").Inferred[];
|
94
|
-
})[];
|
95
|
-
review: {
|
96
|
-
title: TranslationConfig;
|
97
|
-
fields: import("./FieldConfig").Inferred[];
|
98
|
-
};
|
99
|
-
} | undefined;
|
100
|
-
export declare const findActiveActionFormPages: (configuration: EventConfig, action: ActionType) => ({
|
101
|
-
id: string;
|
102
|
-
title: TranslationConfig;
|
103
|
-
fields: import("./FieldConfig").Inferred[];
|
104
|
-
type?: "FORM" | undefined;
|
105
|
-
} | {
|
106
|
-
type: "VERIFICATION";
|
107
|
-
id: string;
|
108
|
-
title: TranslationConfig;
|
109
|
-
actions: {
|
110
|
-
verify: {
|
111
|
-
label: TranslationConfig;
|
112
|
-
};
|
113
|
-
cancel: {
|
114
|
-
label: TranslationConfig;
|
115
|
-
confirmation: {
|
116
|
-
title: TranslationConfig;
|
117
|
-
body: TranslationConfig;
|
118
|
-
};
|
119
|
-
};
|
120
|
-
};
|
121
|
-
fields: import("./FieldConfig").Inferred[];
|
122
|
-
})[] | undefined;
|
123
|
-
export declare const getFormFields: (formConfig: FormConfig) => import("./FieldConfig").Inferred[];
|
124
|
-
/**
|
125
|
-
* Returns only form fields for the action type, if any, excluding review fields.
|
126
|
-
*/
|
127
|
-
export declare const findActiveActionFormFields: (configuration: EventConfig, action: ActionType) => FieldConfig[] | undefined;
|
128
|
-
/**
|
129
|
-
* Returns all fields for the action type, including review fields, if any.
|
130
|
-
*/
|
131
|
-
export declare const findActiveActionFields: (configuration: EventConfig, action: ActionType) => FieldConfig[] | undefined;
|
132
|
-
/**
|
133
|
-
* Returns all fields for the action type, including review fields, or throws
|
134
|
-
*/
|
135
|
-
export declare function getActiveActionFields(configuration: EventConfig, action: ActionType): FieldConfig[];
|
136
|
-
export declare function getEventConfiguration(eventConfigurations: EventConfig[], type: string): EventConfig;
|
137
|
-
export declare function stripHiddenFields(fields: FieldConfig[], data: EventState): import("lodash").Dictionary<string | number | boolean | {
|
45
|
+
export declare function isPageVisible(page: PageConfig, formValues: ActionUpdate): boolean;
|
46
|
+
export declare const getVisiblePagesFormFields: (formConfig: FormConfig, formData: ActionUpdate) => import("./FieldConfig").Inferred[];
|
47
|
+
export declare function stripHiddenFields(fields: FieldConfig[], declaration: EventState): import("lodash").Dictionary<string | number | boolean | {
|
138
48
|
type: string;
|
139
49
|
filename: string;
|
140
50
|
originalFilename: string;
|
141
51
|
} | {
|
142
52
|
country: string;
|
143
53
|
district: string;
|
54
|
+
addressType: "DOMESTIC";
|
144
55
|
province: string;
|
145
56
|
urbanOrRural: "URBAN";
|
146
57
|
number?: string | undefined;
|
@@ -151,13 +62,167 @@ export declare function stripHiddenFields(fields: FieldConfig[], data: EventStat
|
|
151
62
|
} | {
|
152
63
|
country: string;
|
153
64
|
district: string;
|
65
|
+
addressType: "DOMESTIC";
|
154
66
|
province: string;
|
155
67
|
urbanOrRural: "RURAL";
|
156
68
|
village?: string | undefined;
|
69
|
+
} | {
|
70
|
+
country: string;
|
71
|
+
state: string;
|
72
|
+
addressType: "INTERNATIONAL";
|
73
|
+
district2: string;
|
74
|
+
cityOrTown?: string | undefined;
|
75
|
+
addressLine1?: string | undefined;
|
76
|
+
addressLine2?: string | undefined;
|
77
|
+
addressLine3?: string | undefined;
|
78
|
+
postcodeOrZip?: string | undefined;
|
79
|
+
} | {
|
80
|
+
type: string;
|
81
|
+
option: string;
|
82
|
+
filename: string;
|
83
|
+
originalFilename: string;
|
84
|
+
}[] | undefined>;
|
85
|
+
export declare function findActiveDrafts(event: EventDocument, drafts: Draft[]): {
|
86
|
+
id: string;
|
87
|
+
createdAt: string;
|
88
|
+
eventId: string;
|
89
|
+
transactionId: string;
|
90
|
+
action: {
|
91
|
+
type: "DECLARE" | "REGISTER" | "VALIDATE" | "DELETE" | "CREATE" | "NOTIFY" | "DETECT_DUPLICATE" | "REJECT" | "MARKED_AS_DUPLICATE" | "ARCHIVE" | "PRINT_CERTIFICATE" | "REQUEST_CORRECTION" | "REJECT_CORRECTION" | "APPROVE_CORRECTION" | "READ" | "ASSIGN" | "UNASSIGN";
|
92
|
+
status: "Rejected" | "Requested" | "Accepted";
|
93
|
+
createdAt: string;
|
94
|
+
createdBy: string;
|
95
|
+
declaration: Record<string, string | number | boolean | {
|
96
|
+
type: string;
|
97
|
+
filename: string;
|
98
|
+
originalFilename: string;
|
99
|
+
} | {
|
100
|
+
country: string;
|
101
|
+
district: string;
|
102
|
+
addressType: "DOMESTIC";
|
103
|
+
province: string;
|
104
|
+
urbanOrRural: "URBAN";
|
105
|
+
number?: string | null | undefined;
|
106
|
+
town?: string | null | undefined;
|
107
|
+
residentialArea?: string | null | undefined;
|
108
|
+
street?: string | null | undefined;
|
109
|
+
zipCode?: string | null | undefined;
|
110
|
+
} | {
|
111
|
+
country: string;
|
112
|
+
district: string;
|
113
|
+
addressType: "DOMESTIC";
|
114
|
+
province: string;
|
115
|
+
urbanOrRural: "RURAL";
|
116
|
+
village?: string | null | undefined;
|
117
|
+
} | {
|
118
|
+
country: string;
|
119
|
+
state: string;
|
120
|
+
addressType: "INTERNATIONAL";
|
121
|
+
district2: string;
|
122
|
+
cityOrTown?: string | null | undefined;
|
123
|
+
addressLine1?: string | null | undefined;
|
124
|
+
addressLine2?: string | null | undefined;
|
125
|
+
addressLine3?: string | null | undefined;
|
126
|
+
postcodeOrZip?: string | null | undefined;
|
127
|
+
} | {
|
128
|
+
type: string;
|
129
|
+
option: string;
|
130
|
+
filename: string;
|
131
|
+
originalFilename: string;
|
132
|
+
}[] | undefined>;
|
133
|
+
createdAtLocation: string;
|
134
|
+
annotation?: Record<string, string | number | boolean | {
|
135
|
+
type: string;
|
136
|
+
filename: string;
|
137
|
+
originalFilename: string;
|
138
|
+
} | {
|
139
|
+
country: string;
|
140
|
+
district: string;
|
141
|
+
addressType: "DOMESTIC";
|
142
|
+
province: string;
|
143
|
+
urbanOrRural: "URBAN";
|
144
|
+
number?: string | null | undefined;
|
145
|
+
town?: string | null | undefined;
|
146
|
+
residentialArea?: string | null | undefined;
|
147
|
+
street?: string | null | undefined;
|
148
|
+
zipCode?: string | null | undefined;
|
149
|
+
} | {
|
150
|
+
country: string;
|
151
|
+
district: string;
|
152
|
+
addressType: "DOMESTIC";
|
153
|
+
province: string;
|
154
|
+
urbanOrRural: "RURAL";
|
155
|
+
village?: string | null | undefined;
|
156
|
+
} | {
|
157
|
+
country: string;
|
158
|
+
state: string;
|
159
|
+
addressType: "INTERNATIONAL";
|
160
|
+
district2: string;
|
161
|
+
cityOrTown?: string | null | undefined;
|
162
|
+
addressLine1?: string | null | undefined;
|
163
|
+
addressLine2?: string | null | undefined;
|
164
|
+
addressLine3?: string | null | undefined;
|
165
|
+
postcodeOrZip?: string | null | undefined;
|
166
|
+
} | {
|
167
|
+
type: string;
|
168
|
+
option: string;
|
169
|
+
filename: string;
|
170
|
+
originalFilename: string;
|
171
|
+
}[] | undefined> | undefined;
|
172
|
+
originalActionId?: string | undefined;
|
173
|
+
};
|
174
|
+
}[];
|
175
|
+
export declare function createEmptyDraft(eventId: string, draftId: string, actionType: ActionType): {
|
176
|
+
id: string;
|
177
|
+
eventId: string;
|
178
|
+
createdAt: string;
|
179
|
+
transactionId: import("../uuid").UUID;
|
180
|
+
action: {
|
181
|
+
type: ActionType;
|
182
|
+
declaration: {};
|
183
|
+
annotation: {};
|
184
|
+
createdAt: string;
|
185
|
+
createdBy: string;
|
186
|
+
createdAtLocation: string;
|
187
|
+
};
|
188
|
+
};
|
189
|
+
export declare function isVerificationPage(page: PageConfig): page is VerificationPageConfig;
|
190
|
+
export declare function deepMerge(currentDocument: ActionUpdate, actionDocument: ActionUpdate): Record<string, string | number | boolean | {
|
191
|
+
type: string;
|
192
|
+
filename: string;
|
193
|
+
originalFilename: string;
|
194
|
+
} | {
|
195
|
+
country: string;
|
196
|
+
district: string;
|
197
|
+
addressType: "DOMESTIC";
|
198
|
+
province: string;
|
199
|
+
urbanOrRural: "URBAN";
|
200
|
+
number?: string | null | undefined;
|
201
|
+
town?: string | null | undefined;
|
202
|
+
residentialArea?: string | null | undefined;
|
203
|
+
street?: string | null | undefined;
|
204
|
+
zipCode?: string | null | undefined;
|
205
|
+
} | {
|
206
|
+
country: string;
|
207
|
+
district: string;
|
208
|
+
addressType: "DOMESTIC";
|
209
|
+
province: string;
|
210
|
+
urbanOrRural: "RURAL";
|
211
|
+
village?: string | null | undefined;
|
212
|
+
} | {
|
213
|
+
country: string;
|
214
|
+
state: string;
|
215
|
+
addressType: "INTERNATIONAL";
|
216
|
+
district2: string;
|
217
|
+
cityOrTown?: string | null | undefined;
|
218
|
+
addressLine1?: string | null | undefined;
|
219
|
+
addressLine2?: string | null | undefined;
|
220
|
+
addressLine3?: string | null | undefined;
|
221
|
+
postcodeOrZip?: string | null | undefined;
|
157
222
|
} | {
|
158
223
|
type: string;
|
159
224
|
option: string;
|
160
225
|
filename: string;
|
161
226
|
originalFilename: string;
|
162
|
-
}[]>;
|
227
|
+
}[] | undefined>;
|
163
228
|
//# sourceMappingURL=utils.d.ts.map
|
@@ -23,8 +23,10 @@ __export(conditionals_exports, {
|
|
23
23
|
alwaysTrue: () => alwaysTrue,
|
24
24
|
and: () => and,
|
25
25
|
defineConditional: () => defineConditional,
|
26
|
+
defineFormConditional: () => defineFormConditional,
|
26
27
|
event: () => event,
|
27
28
|
field: () => field,
|
29
|
+
never: () => never,
|
28
30
|
not: () => not,
|
29
31
|
or: () => or,
|
30
32
|
user: () => user
|
@@ -35,6 +37,16 @@ module.exports = __toCommonJS(conditionals_exports);
|
|
35
37
|
function defineConditional(schema) {
|
36
38
|
return schema;
|
37
39
|
}
|
40
|
+
function defineFormConditional(schema) {
|
41
|
+
const schemaWithForm = {
|
42
|
+
type: "object",
|
43
|
+
properties: {
|
44
|
+
$form: schema
|
45
|
+
},
|
46
|
+
required: ["$form"]
|
47
|
+
};
|
48
|
+
return defineConditional(schemaWithForm);
|
49
|
+
}
|
38
50
|
function alwaysTrue() {
|
39
51
|
return {};
|
40
52
|
}
|
@@ -59,6 +71,9 @@ function not(condition) {
|
|
59
71
|
required: []
|
60
72
|
});
|
61
73
|
}
|
74
|
+
function never() {
|
75
|
+
return not(alwaysTrue());
|
76
|
+
}
|
62
77
|
var user = {
|
63
78
|
hasScope: (scope) => defineConditional({
|
64
79
|
type: "object",
|
@@ -106,69 +121,120 @@ var event = {
|
|
106
121
|
required: ["$event"]
|
107
122
|
})
|
108
123
|
};
|
124
|
+
function getDateFromNow(days) {
|
125
|
+
return new Date(Date.now() - days * 24 * 60 * 60 * 1e3).toISOString().split("T")[0];
|
126
|
+
}
|
127
|
+
function getDateRangeToFieldReference(fieldId, comparedFieldId, clause) {
|
128
|
+
return {
|
129
|
+
type: "object",
|
130
|
+
properties: {
|
131
|
+
[fieldId]: {
|
132
|
+
type: "string",
|
133
|
+
format: "date",
|
134
|
+
[clause]: { $data: `1/${comparedFieldId}` }
|
135
|
+
},
|
136
|
+
[comparedFieldId]: { type: "string", format: "date" }
|
137
|
+
},
|
138
|
+
required: [fieldId]
|
139
|
+
};
|
140
|
+
}
|
141
|
+
function isFieldReference(value) {
|
142
|
+
return typeof value === "object" && value !== null && "_fieldId" in value;
|
143
|
+
}
|
109
144
|
function field(fieldId) {
|
110
|
-
const getDateFromNow = (days) => new Date(Date.now() - days * 24 * 60 * 60 * 1e3).toISOString().split("T")[0];
|
111
145
|
const getDateRange = (date, clause) => ({
|
112
146
|
type: "object",
|
113
147
|
properties: {
|
114
|
-
|
115
|
-
type: "
|
116
|
-
|
117
|
-
|
118
|
-
type: "string",
|
119
|
-
format: "date",
|
120
|
-
[clause]: date
|
121
|
-
}
|
122
|
-
},
|
123
|
-
required: [fieldId]
|
148
|
+
[fieldId]: {
|
149
|
+
type: "string",
|
150
|
+
format: "date",
|
151
|
+
[clause]: date
|
124
152
|
}
|
125
153
|
},
|
126
|
-
required: [
|
154
|
+
required: [fieldId]
|
127
155
|
});
|
128
156
|
return {
|
157
|
+
/**
|
158
|
+
* @private Internal property used for field reference tracking.
|
159
|
+
*/
|
160
|
+
_fieldId: fieldId,
|
129
161
|
isAfter: () => ({
|
130
162
|
days: (days) => ({
|
131
|
-
inPast: () =>
|
163
|
+
inPast: () => defineFormConditional(
|
132
164
|
getDateRange(getDateFromNow(days), "formatMinimum")
|
133
165
|
),
|
134
|
-
inFuture: () =>
|
166
|
+
inFuture: () => defineFormConditional(
|
135
167
|
getDateRange(getDateFromNow(-days), "formatMinimum")
|
136
168
|
)
|
137
169
|
}),
|
138
|
-
date: (date) =>
|
139
|
-
|
170
|
+
date: (date) => {
|
171
|
+
if (isFieldReference(date)) {
|
172
|
+
const comparedFieldId = date._fieldId;
|
173
|
+
return defineFormConditional(
|
174
|
+
getDateRangeToFieldReference(
|
175
|
+
fieldId,
|
176
|
+
comparedFieldId,
|
177
|
+
"formatMinimum"
|
178
|
+
)
|
179
|
+
);
|
180
|
+
}
|
181
|
+
return defineFormConditional(getDateRange(date, "formatMinimum"));
|
182
|
+
},
|
183
|
+
now: () => defineFormConditional(getDateRange(getDateFromNow(0), "formatMinimum"))
|
140
184
|
}),
|
141
185
|
isBefore: () => ({
|
142
186
|
days: (days) => ({
|
143
|
-
inPast: () =>
|
187
|
+
inPast: () => defineFormConditional(
|
144
188
|
getDateRange(getDateFromNow(days), "formatMaximum")
|
145
189
|
),
|
146
|
-
inFuture: () =>
|
190
|
+
inFuture: () => defineFormConditional(
|
147
191
|
getDateRange(getDateFromNow(-days), "formatMaximum")
|
148
192
|
)
|
149
193
|
}),
|
150
|
-
date: (date) =>
|
151
|
-
|
194
|
+
date: (date) => {
|
195
|
+
if (isFieldReference(date)) {
|
196
|
+
const comparedFieldId = date._fieldId;
|
197
|
+
return defineFormConditional(
|
198
|
+
getDateRangeToFieldReference(
|
199
|
+
fieldId,
|
200
|
+
comparedFieldId,
|
201
|
+
"formatMaximum"
|
202
|
+
)
|
203
|
+
);
|
204
|
+
}
|
205
|
+
return defineFormConditional(getDateRange(date, "formatMaximum"));
|
206
|
+
},
|
207
|
+
now: () => defineFormConditional(getDateRange(getDateFromNow(0), "formatMaximum"))
|
152
208
|
}),
|
153
|
-
isEqualTo: (value) =>
|
154
|
-
|
155
|
-
|
156
|
-
|
209
|
+
isEqualTo: (value) => {
|
210
|
+
if (isFieldReference(value)) {
|
211
|
+
const comparedFieldId = value._fieldId;
|
212
|
+
return defineFormConditional({
|
157
213
|
type: "object",
|
158
214
|
properties: {
|
159
215
|
[fieldId]: {
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
const: value
|
165
|
-
}
|
216
|
+
type: ["string", "boolean"],
|
217
|
+
const: { $data: `1/${comparedFieldId}` }
|
218
|
+
},
|
219
|
+
[comparedFieldId]: { type: ["string", "boolean"] }
|
166
220
|
},
|
167
|
-
required: [fieldId]
|
168
|
-
}
|
169
|
-
}
|
170
|
-
|
171
|
-
|
221
|
+
required: [fieldId, comparedFieldId]
|
222
|
+
});
|
223
|
+
}
|
224
|
+
return defineFormConditional({
|
225
|
+
type: "object",
|
226
|
+
properties: {
|
227
|
+
[fieldId]: {
|
228
|
+
oneOf: [
|
229
|
+
{ type: "string", const: value },
|
230
|
+
{ type: "boolean", const: value }
|
231
|
+
],
|
232
|
+
const: value
|
233
|
+
}
|
234
|
+
},
|
235
|
+
required: [fieldId]
|
236
|
+
});
|
237
|
+
},
|
172
238
|
/**
|
173
239
|
* Use case: Some fields are rendered when selection is not made, or boolean false is explicitly selected.
|
174
240
|
* @example field('recommender.none').isFalsy() vs not(field('recommender.none').isEqualTo(true))
|
@@ -177,68 +243,87 @@ function field(fieldId) {
|
|
177
243
|
* NOTE: For now, this only works with string, boolean, and null types. 0 is still allowed.
|
178
244
|
*
|
179
245
|
*/
|
180
|
-
isFalsy: () =>
|
246
|
+
isFalsy: () => defineFormConditional({
|
181
247
|
type: "object",
|
182
248
|
properties: {
|
183
|
-
|
184
|
-
type: "object",
|
185
|
-
properties: {
|
186
|
-
[fieldId]: {
|
187
|
-
anyOf: [
|
188
|
-
{ const: "undefined" },
|
189
|
-
{ const: false },
|
190
|
-
{ const: null },
|
191
|
-
{ const: "" }
|
192
|
-
]
|
193
|
-
}
|
194
|
-
},
|
249
|
+
[fieldId]: {
|
195
250
|
anyOf: [
|
196
|
-
{
|
197
|
-
|
198
|
-
},
|
199
|
-
{
|
200
|
-
not: {
|
201
|
-
required: [fieldId]
|
202
|
-
}
|
203
|
-
}
|
251
|
+
{ const: "undefined" },
|
252
|
+
{ const: false },
|
253
|
+
{ const: null },
|
254
|
+
{ const: "" }
|
204
255
|
]
|
205
256
|
}
|
206
257
|
},
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
$form: {
|
213
|
-
type: "object",
|
214
|
-
properties: {
|
215
|
-
[fieldId]: {
|
216
|
-
type: "string",
|
217
|
-
enum: ["undefined"]
|
218
|
-
}
|
219
|
-
},
|
258
|
+
anyOf: [
|
259
|
+
{
|
260
|
+
required: [fieldId]
|
261
|
+
},
|
262
|
+
{
|
220
263
|
not: {
|
221
264
|
required: [fieldId]
|
222
265
|
}
|
223
266
|
}
|
267
|
+
]
|
268
|
+
}),
|
269
|
+
isUndefined: () => defineFormConditional({
|
270
|
+
type: "object",
|
271
|
+
properties: {
|
272
|
+
[fieldId]: {
|
273
|
+
type: "string",
|
274
|
+
enum: ["undefined"]
|
275
|
+
}
|
224
276
|
},
|
225
|
-
|
277
|
+
not: {
|
278
|
+
required: [fieldId]
|
279
|
+
}
|
226
280
|
}),
|
227
|
-
inArray: (values) =>
|
281
|
+
inArray: (values) => defineFormConditional({
|
228
282
|
type: "object",
|
229
283
|
properties: {
|
230
|
-
|
231
|
-
type: "
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
284
|
+
[fieldId]: {
|
285
|
+
type: "string",
|
286
|
+
enum: values
|
287
|
+
}
|
288
|
+
},
|
289
|
+
required: [fieldId]
|
290
|
+
}),
|
291
|
+
isValidEnglishName: () => defineFormConditional({
|
292
|
+
type: "object",
|
293
|
+
properties: {
|
294
|
+
[fieldId]: {
|
295
|
+
type: "string",
|
296
|
+
pattern: "^[\\p{Script=Latin}0-9'._-]*(\\([\\p{Script=Latin}0-9'._-]+\\))?[\\p{Script=Latin}0-9'._-]*( [\\p{Script=Latin}0-9'._-]*(\\([\\p{Script=Latin}0-9'._-]+\\))?[\\p{Script=Latin}0-9'._-]*)*$",
|
297
|
+
description: "Name must contain only letters, numbers, and allowed special characters ('._-). No double spaces."
|
298
|
+
}
|
299
|
+
},
|
300
|
+
required: [fieldId]
|
301
|
+
}),
|
302
|
+
/**
|
303
|
+
* Checks if the field value matches a given regular expression pattern.
|
304
|
+
* @param pattern - The regular expression pattern to match the field value against.
|
305
|
+
* @returns A JSONSchema conditional that validates the field value against the pattern.
|
306
|
+
*/
|
307
|
+
matches: (pattern) => defineFormConditional({
|
308
|
+
type: "object",
|
309
|
+
properties: {
|
310
|
+
[fieldId]: {
|
311
|
+
type: "string",
|
312
|
+
pattern
|
313
|
+
}
|
314
|
+
},
|
315
|
+
required: [fieldId]
|
316
|
+
}),
|
317
|
+
isBetween: (min, max) => defineFormConditional({
|
318
|
+
type: "object",
|
319
|
+
properties: {
|
320
|
+
[fieldId]: {
|
321
|
+
type: "number",
|
322
|
+
minimum: min,
|
323
|
+
maximum: max
|
239
324
|
}
|
240
325
|
},
|
241
|
-
required: [
|
326
|
+
required: [fieldId]
|
242
327
|
})
|
243
328
|
};
|
244
329
|
}
|