json-schema-describes-subset
Version:
Tools for static JSON schema analysis, including functions to determine if one schema describes a subset of another or if a schema describes the empty set or to convert a schema to its disjunctive normal form (DNF).
25 lines • 1.27 kB
JavaScript
import { ConstAtomicSchema } from './const.js';
export function getNegatedConstValuesFromNegatedAtomicSchemasByConstructor(negatedAtomicSchemasByConstructor, filterPredicate) {
return negatedAtomicSchemasByConstructor
.get(ConstAtomicSchema)
.map((schema) => schema.const)
.filter(filterPredicate);
}
export function getUniqueNegatedConstSchemas(schemaDescribesEmptySet, negatedConstValues) {
return negatedConstValues
.filter((constValue, index, array) => {
const previousConstValues = array.slice(0, index);
const constValuesAreEqual = previousConstValues.some((previousConstValue) => schemaDescribesEmptySet({
const: constValue,
not: { const: previousConstValue },
}));
return !constValuesAreEqual;
})
.map((constValue) => ({
not: { const: constValue },
}));
}
export function getUniqueNegatedConstSchemasFromNegatedAtomicSchemasByConstructor(schemaDescribesEmptySet, negatedAtomicSchemasByConstructor, filterPredicate) {
return getUniqueNegatedConstSchemas(schemaDescribesEmptySet, getNegatedConstValuesFromNegatedAtomicSchemasByConstructor(negatedAtomicSchemasByConstructor, filterPredicate));
}
//# sourceMappingURL=negated-const-helpers.js.map