@ecrvs/opencrvs-toolkit 1.8.1-rc.a7ee8fb → 1.8.1-rc.b48c48d
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.
|
@@ -121,6 +121,8 @@ export declare function createFieldConditionals(fieldId: string): {
|
|
|
121
121
|
isGreaterThan: (value: number | FieldReference) => JSONSchema;
|
|
122
122
|
isLessThan: (value: number | FieldReference) => JSONSchema;
|
|
123
123
|
isEqualTo(value: string | boolean | FieldReference): JSONSchema;
|
|
124
|
+
isEqualToSumOf(val1: FieldReference, val2: FieldReference): JSONSchema;
|
|
125
|
+
isGreaterThanOrEqualTo(value: number | string | FieldReference): JSONSchema;
|
|
124
126
|
/**
|
|
125
127
|
* Use case: Some fields are rendered when selection is not made, or boolean false is explicitly selected.
|
|
126
128
|
* @example field('recommender.none').isFalsy() vs not(field('recommender.none').isEqualTo(true))
|
|
@@ -165,6 +167,8 @@ export declare function createFieldConditionals(fieldId: string): {
|
|
|
165
167
|
isGreaterThan: (value: number | FieldReference) => JSONSchema;
|
|
166
168
|
isLessThan: (value: number | FieldReference) => JSONSchema;
|
|
167
169
|
isEqualTo(value: string | boolean | FieldReference): JSONSchema;
|
|
170
|
+
isEqualToSumOf(val1: FieldReference, val2: FieldReference): JSONSchema;
|
|
171
|
+
isGreaterThanOrEqualTo(value: number | string | FieldReference): JSONSchema;
|
|
168
172
|
/**
|
|
169
173
|
* Use case: Some fields are rendered when selection is not made, or boolean false is explicitly selected.
|
|
170
174
|
* @example field('recommender.none').isFalsy() vs not(field('recommender.none').isEqualTo(true))
|
|
@@ -95,6 +95,14 @@ export declare function field(fieldId: string, options?: {
|
|
|
95
95
|
isEqualTo(value: string | boolean | {
|
|
96
96
|
$$field: string;
|
|
97
97
|
}): import("../conditionals/conditionals").JSONSchema;
|
|
98
|
+
isEqualToSumOf(val1: {
|
|
99
|
+
$$field: string;
|
|
100
|
+
}, val2: {
|
|
101
|
+
$$field: string;
|
|
102
|
+
}): import("../conditionals/conditionals").JSONSchema;
|
|
103
|
+
isGreaterThanOrEqualTo(value: number | string | {
|
|
104
|
+
$$field: string;
|
|
105
|
+
}): import("../conditionals/conditionals").JSONSchema;
|
|
98
106
|
isFalsy(): import("../conditionals/conditionals").JSONSchema;
|
|
99
107
|
isUndefined(): import("../conditionals/conditionals").JSONSchema;
|
|
100
108
|
inArray: (values: string[]) => import("../conditionals/conditionals").JSONSchema;
|
|
@@ -136,6 +144,14 @@ export declare function field(fieldId: string, options?: {
|
|
|
136
144
|
isEqualTo(value: string | boolean | {
|
|
137
145
|
$$field: string;
|
|
138
146
|
}): import("../conditionals/conditionals").JSONSchema;
|
|
147
|
+
isEqualToSumOf(val1: {
|
|
148
|
+
$$field: string;
|
|
149
|
+
}, val2: {
|
|
150
|
+
$$field: string;
|
|
151
|
+
}): import("../conditionals/conditionals").JSONSchema;
|
|
152
|
+
isGreaterThanOrEqualTo(value: number | string | {
|
|
153
|
+
$$field: string;
|
|
154
|
+
}): import("../conditionals/conditionals").JSONSchema;
|
|
139
155
|
isFalsy(): import("../conditionals/conditionals").JSONSchema;
|
|
140
156
|
isUndefined(): import("../conditionals/conditionals").JSONSchema;
|
|
141
157
|
inArray: (values: string[]) => import("../conditionals/conditionals").JSONSchema;
|
|
@@ -355,6 +355,48 @@ function createFieldConditionals(fieldId) {
|
|
|
355
355
|
required: [fieldId]
|
|
356
356
|
});
|
|
357
357
|
},
|
|
358
|
+
isEqualToSumOf(val1, val2) {
|
|
359
|
+
const field1Id = val1.$$field;
|
|
360
|
+
const field2Id = val2.$$field;
|
|
361
|
+
return defineFormConditional({
|
|
362
|
+
type: "object",
|
|
363
|
+
properties: {
|
|
364
|
+
[fieldId]: { type: "number" },
|
|
365
|
+
[field1Id]: { type: "number" },
|
|
366
|
+
[field2Id]: { type: "number" }
|
|
367
|
+
},
|
|
368
|
+
required: [fieldId, field1Id, field2Id],
|
|
369
|
+
sumOf: {
|
|
370
|
+
sum: { $data: `/$form/${fieldId}` },
|
|
371
|
+
field1: { $data: `/$form/${field1Id}` },
|
|
372
|
+
field2: { $data: `/$form/${field2Id}` }
|
|
373
|
+
}
|
|
374
|
+
});
|
|
375
|
+
},
|
|
376
|
+
isGreaterThanOrEqualTo(value) {
|
|
377
|
+
const fieldSchema = { type: "number" };
|
|
378
|
+
const properties = {};
|
|
379
|
+
const required = [fieldId];
|
|
380
|
+
if (typeof value === "number") {
|
|
381
|
+
fieldSchema.minimum = value;
|
|
382
|
+
} else {
|
|
383
|
+
let refField = "";
|
|
384
|
+
if (isFieldReference(value)) {
|
|
385
|
+
refField = value.$$field;
|
|
386
|
+
} else {
|
|
387
|
+
refField = value;
|
|
388
|
+
}
|
|
389
|
+
fieldSchema.minimum = { $data: `/$form/${refField}` };
|
|
390
|
+
properties[refField] = { type: "number" };
|
|
391
|
+
required.push(refField);
|
|
392
|
+
}
|
|
393
|
+
properties[fieldId] = fieldSchema;
|
|
394
|
+
return defineFormConditional({
|
|
395
|
+
type: "object",
|
|
396
|
+
properties,
|
|
397
|
+
required
|
|
398
|
+
});
|
|
399
|
+
},
|
|
358
400
|
/**
|
|
359
401
|
* Use case: Some fields are rendered when selection is not made, or boolean false is explicitly selected.
|
|
360
402
|
* @example field('recommender.none').isFalsy() vs not(field('recommender.none').isEqualTo(true))
|
package/dist/events/index.js
CHANGED
|
@@ -2540,6 +2540,30 @@ ajv.addKeyword({
|
|
|
2540
2540
|
return locations.some((location) => location.id === locationIdInput);
|
|
2541
2541
|
}
|
|
2542
2542
|
});
|
|
2543
|
+
ajv.addKeyword({
|
|
2544
|
+
keyword: "sumOf",
|
|
2545
|
+
type: "object",
|
|
2546
|
+
schemaType: "object",
|
|
2547
|
+
errors: true,
|
|
2548
|
+
$data: true,
|
|
2549
|
+
validate(schema, data) {
|
|
2550
|
+
const { sum, field1, field2: field22 } = schema;
|
|
2551
|
+
console.log(schema, data);
|
|
2552
|
+
const getRefPath = (ref) => typeof ref === "object" && "$data" in ref ? ref.$data : ref;
|
|
2553
|
+
const sumKey = getRefPath(sum);
|
|
2554
|
+
const field1Key = getRefPath(field1);
|
|
2555
|
+
const field2Key = getRefPath(field22);
|
|
2556
|
+
const total = data?.$form?.[sumKey];
|
|
2557
|
+
const num1 = data?.$form?.[field1Key];
|
|
2558
|
+
const num2 = data?.$form?.[field2Key];
|
|
2559
|
+
console.log(total, num1, num2);
|
|
2560
|
+
if (typeof total !== "number" || typeof num1 !== "number" || typeof num2 !== "number") {
|
|
2561
|
+
return true;
|
|
2562
|
+
}
|
|
2563
|
+
const valid = total === num1 + num2;
|
|
2564
|
+
return valid;
|
|
2565
|
+
}
|
|
2566
|
+
});
|
|
2543
2567
|
function validate(schema, data) {
|
|
2544
2568
|
const validator = ajv.getSchema(schema.$id) || ajv.compile(schema);
|
|
2545
2569
|
const result = validator(data);
|
|
@@ -3516,6 +3540,48 @@ function createFieldConditionals(fieldId) {
|
|
|
3516
3540
|
required: [fieldId]
|
|
3517
3541
|
});
|
|
3518
3542
|
},
|
|
3543
|
+
isEqualToSumOf(val1, val2) {
|
|
3544
|
+
const field1Id = val1.$$field;
|
|
3545
|
+
const field2Id = val2.$$field;
|
|
3546
|
+
return defineFormConditional({
|
|
3547
|
+
type: "object",
|
|
3548
|
+
properties: {
|
|
3549
|
+
[fieldId]: { type: "number" },
|
|
3550
|
+
[field1Id]: { type: "number" },
|
|
3551
|
+
[field2Id]: { type: "number" }
|
|
3552
|
+
},
|
|
3553
|
+
required: [fieldId, field1Id, field2Id],
|
|
3554
|
+
sumOf: {
|
|
3555
|
+
sum: { $data: `/$form/${fieldId}` },
|
|
3556
|
+
field1: { $data: `/$form/${field1Id}` },
|
|
3557
|
+
field2: { $data: `/$form/${field2Id}` }
|
|
3558
|
+
}
|
|
3559
|
+
});
|
|
3560
|
+
},
|
|
3561
|
+
isGreaterThanOrEqualTo(value) {
|
|
3562
|
+
const fieldSchema = { type: "number" };
|
|
3563
|
+
const properties = {};
|
|
3564
|
+
const required = [fieldId];
|
|
3565
|
+
if (typeof value === "number") {
|
|
3566
|
+
fieldSchema.minimum = value;
|
|
3567
|
+
} else {
|
|
3568
|
+
let refField = "";
|
|
3569
|
+
if (isFieldReference(value)) {
|
|
3570
|
+
refField = value.$$field;
|
|
3571
|
+
} else {
|
|
3572
|
+
refField = value;
|
|
3573
|
+
}
|
|
3574
|
+
fieldSchema.minimum = { $data: `/$form/${refField}` };
|
|
3575
|
+
properties[refField] = { type: "number" };
|
|
3576
|
+
required.push(refField);
|
|
3577
|
+
}
|
|
3578
|
+
properties[fieldId] = fieldSchema;
|
|
3579
|
+
return defineFormConditional({
|
|
3580
|
+
type: "object",
|
|
3581
|
+
properties,
|
|
3582
|
+
required
|
|
3583
|
+
});
|
|
3584
|
+
},
|
|
3519
3585
|
/**
|
|
3520
3586
|
* Use case: Some fields are rendered when selection is not made, or boolean false is explicitly selected.
|
|
3521
3587
|
* @example field('recommender.none').isFalsy() vs not(field('recommender.none').isEqualTo(true))
|
|
@@ -1946,6 +1946,30 @@ ajv.addKeyword({
|
|
|
1946
1946
|
return locations.some((location) => location.id === locationIdInput);
|
|
1947
1947
|
}
|
|
1948
1948
|
});
|
|
1949
|
+
ajv.addKeyword({
|
|
1950
|
+
keyword: "sumOf",
|
|
1951
|
+
type: "object",
|
|
1952
|
+
schemaType: "object",
|
|
1953
|
+
errors: true,
|
|
1954
|
+
$data: true,
|
|
1955
|
+
validate(schema, data) {
|
|
1956
|
+
const { sum, field1, field2: field22 } = schema;
|
|
1957
|
+
console.log(schema, data);
|
|
1958
|
+
const getRefPath = (ref) => typeof ref === "object" && "$data" in ref ? ref.$data : ref;
|
|
1959
|
+
const sumKey = getRefPath(sum);
|
|
1960
|
+
const field1Key = getRefPath(field1);
|
|
1961
|
+
const field2Key = getRefPath(field22);
|
|
1962
|
+
const total = data?.$form?.[sumKey];
|
|
1963
|
+
const num1 = data?.$form?.[field1Key];
|
|
1964
|
+
const num2 = data?.$form?.[field2Key];
|
|
1965
|
+
console.log(total, num1, num2);
|
|
1966
|
+
if (typeof total !== "number" || typeof num1 !== "number" || typeof num2 !== "number") {
|
|
1967
|
+
return true;
|
|
1968
|
+
}
|
|
1969
|
+
const valid = total === num1 + num2;
|
|
1970
|
+
return valid;
|
|
1971
|
+
}
|
|
1972
|
+
});
|
|
1949
1973
|
|
|
1950
1974
|
// ../commons/src/utils.ts
|
|
1951
1975
|
var z24 = __toESM(require("zod"));
|
|
@@ -2335,6 +2359,48 @@ function createFieldConditionals(fieldId) {
|
|
|
2335
2359
|
required: [fieldId]
|
|
2336
2360
|
});
|
|
2337
2361
|
},
|
|
2362
|
+
isEqualToSumOf(val1, val2) {
|
|
2363
|
+
const field1Id = val1.$$field;
|
|
2364
|
+
const field2Id = val2.$$field;
|
|
2365
|
+
return defineFormConditional({
|
|
2366
|
+
type: "object",
|
|
2367
|
+
properties: {
|
|
2368
|
+
[fieldId]: { type: "number" },
|
|
2369
|
+
[field1Id]: { type: "number" },
|
|
2370
|
+
[field2Id]: { type: "number" }
|
|
2371
|
+
},
|
|
2372
|
+
required: [fieldId, field1Id, field2Id],
|
|
2373
|
+
sumOf: {
|
|
2374
|
+
sum: { $data: `/$form/${fieldId}` },
|
|
2375
|
+
field1: { $data: `/$form/${field1Id}` },
|
|
2376
|
+
field2: { $data: `/$form/${field2Id}` }
|
|
2377
|
+
}
|
|
2378
|
+
});
|
|
2379
|
+
},
|
|
2380
|
+
isGreaterThanOrEqualTo(value) {
|
|
2381
|
+
const fieldSchema = { type: "number" };
|
|
2382
|
+
const properties = {};
|
|
2383
|
+
const required = [fieldId];
|
|
2384
|
+
if (typeof value === "number") {
|
|
2385
|
+
fieldSchema.minimum = value;
|
|
2386
|
+
} else {
|
|
2387
|
+
let refField = "";
|
|
2388
|
+
if (isFieldReference(value)) {
|
|
2389
|
+
refField = value.$$field;
|
|
2390
|
+
} else {
|
|
2391
|
+
refField = value;
|
|
2392
|
+
}
|
|
2393
|
+
fieldSchema.minimum = { $data: `/$form/${refField}` };
|
|
2394
|
+
properties[refField] = { type: "number" };
|
|
2395
|
+
required.push(refField);
|
|
2396
|
+
}
|
|
2397
|
+
properties[fieldId] = fieldSchema;
|
|
2398
|
+
return defineFormConditional({
|
|
2399
|
+
type: "object",
|
|
2400
|
+
properties,
|
|
2401
|
+
required
|
|
2402
|
+
});
|
|
2403
|
+
},
|
|
2338
2404
|
/**
|
|
2339
2405
|
* Use case: Some fields are rendered when selection is not made, or boolean false is explicitly selected.
|
|
2340
2406
|
* @example field('recommender.none').isFalsy() vs not(field('recommender.none').isEqualTo(true))
|