@opencrvs/toolkit
Advanced tools
Comparing version 0.0.25-events-ml to 0.0.26-events-ml
@@ -776,44 +776,97 @@ "use strict"; | ||
properties: { | ||
[fieldId]: { | ||
$form: { | ||
type: "object", | ||
properties: { | ||
[fieldId]: { | ||
type: "string", | ||
format: "date", | ||
formatMaximum: { $data: "2/$now" } | ||
} | ||
}, | ||
required: [fieldId] | ||
}, | ||
$now: { | ||
type: "string", | ||
format: "date", | ||
formatMaximum: { $data: "2/$now" } | ||
format: "date" | ||
} | ||
}, | ||
required: [fieldId, "$now"], | ||
$now: { | ||
type: "string", | ||
format: "date" | ||
} | ||
required: ["$form", "$now"] | ||
}), | ||
isEqualTo: (value) => addCondition({ | ||
[fieldId]: { | ||
const: value | ||
} | ||
type: "object", | ||
properties: { | ||
$form: { | ||
type: "object", | ||
properties: { | ||
[fieldId]: { | ||
const: value | ||
} | ||
}, | ||
required: [fieldId] | ||
} | ||
}, | ||
required: ["$form"] | ||
}), | ||
isUndefined: () => addCondition({ | ||
not: { | ||
type: "object", | ||
required: [fieldId] | ||
} | ||
type: "object", | ||
properties: { | ||
$form: { | ||
type: "object", | ||
not: { | ||
type: "object", | ||
required: [fieldId] | ||
} | ||
} | ||
}, | ||
required: ["$form"] | ||
}), | ||
inArray: (values) => addCondition({ | ||
[fieldId]: { | ||
enum: values | ||
} | ||
type: "object", | ||
properties: { | ||
$form: { | ||
type: "object", | ||
properties: { | ||
[fieldId]: { | ||
enum: values | ||
} | ||
}, | ||
required: [fieldId] | ||
} | ||
}, | ||
required: ["$form"] | ||
}), | ||
not: { | ||
inArray: (values) => addCondition({ | ||
[fieldId]: { | ||
not: { | ||
enum: values | ||
type: "object", | ||
properties: { | ||
$form: { | ||
type: "object", | ||
properties: { | ||
[fieldId]: { | ||
not: { | ||
enum: values | ||
} | ||
} | ||
}, | ||
required: [fieldId] | ||
} | ||
} | ||
}, | ||
required: ["$form"] | ||
}), | ||
equalTo: (value) => addCondition({ | ||
[fieldId]: { | ||
not: { | ||
const: value | ||
type: "object", | ||
properties: { | ||
$form: { | ||
type: "object", | ||
properties: { | ||
[fieldId]: { | ||
not: { | ||
const: value | ||
} | ||
} | ||
}, | ||
required: [fieldId] | ||
} | ||
} | ||
}, | ||
required: ["$form"] | ||
}) | ||
@@ -823,17 +876,10 @@ }, | ||
const nestedConditions = callback(field2(fieldId))._apply(); | ||
return addCondition({ | ||
type: "object", | ||
anyOf: nestedConditions | ||
}); | ||
return addCondition(ensureWrapper(nestedConditions, "or")); | ||
}, | ||
_apply: () => conditions, | ||
apply: () => { | ||
if (conditions.length === 1) { | ||
return { | ||
type: "object", | ||
properties: { $form: { properties: conditions[0] } }, | ||
required: ["$form", fieldId] | ||
}; | ||
if (conditions.length === 0) { | ||
throw new Error("No conditions applied"); | ||
} | ||
return { type: "object", allOf: conditions, required: ["$form", fieldId] }; | ||
return ensureWrapper(conditions, "and"); | ||
} | ||
@@ -843,1 +889,19 @@ }; | ||
} | ||
var ensureWrapper = (conditions, booleanConnector) => { | ||
const conditionsWithConnector = (conditions2, connector) => connector === "and" ? { allOf: conditions2 } : { anyOf: conditions2 }; | ||
const needsWrapper = conditions.some( | ||
(condition) => !(condition.type === "object" && condition.properties && condition.properties.$form) | ||
); | ||
if (needsWrapper) { | ||
return { | ||
type: "object", | ||
properties: { | ||
$form: { | ||
type: "object", | ||
...conditionsWithConnector(conditions, booleanConnector) | ||
} | ||
} | ||
}; | ||
} | ||
return conditionsWithConnector(conditions, booleanConnector); | ||
}; |
{ | ||
"name": "@opencrvs/toolkit", | ||
"version": "0.0.25-events-ml", | ||
"version": "0.0.26-events-ml", | ||
"description": "OpenCRVS toolkit for building country configurations", | ||
@@ -5,0 +5,0 @@ "license": "MPL-2.0", |
Sorry, the diff of this file is not supported yet
3459627
90899