ajv-json-logic
Version:
JSON Logic integration for Ajv validator
39 lines (34 loc) • 1.11 kB
JavaScript
;
Object.defineProperty(exports, '__esModule', { value: true });
var conditionalSchema = require('../schemas/conditional-schema.json.cjs');
function getDef() {
return {
keyword: 'conditionalSchema',
macro: function (schema) {
if (!schema) {
return {};
}
const allOf = [];
if (!Array.isArray(schema))
schema = [schema];
if (schema && Array.isArray(schema)) {
schema.forEach(({ rule, schema: childSchema }) => {
allOf.push({
if: { jsonLogic: rule },
then: childSchema,
});
});
return { allOf };
}
return {};
},
metaSchema: conditionalSchema.default,
};
}
// For CommonJS compatibility
if (typeof module !== 'undefined' && typeof module.exports !== 'undefined') {
module.exports = getDef;
module.exports.default = getDef;
}
exports.default = getDef;
//# sourceMappingURL=conditionalSchema.cjs.map