UNPKG

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).

39 lines (38 loc) 1.64 kB
import type { JSONSchema } from '../json-schema/index.js'; export declare abstract class AtomicSchemaObject { abstract negate(): LogicalCombinationOfLiterals; abstract toJSONSchema(): JSONSchema; } export type AtomicSchema = boolean | AtomicSchemaObject; export declare function isAtomicSchema(schema: unknown): schema is AtomicSchema; export type LogicLiteral = AtomicSchema | NotSchema<AtomicSchemaObject>; export declare function isLogicLiteral(schema: unknown): schema is LogicLiteral; export type LogicalCombination = AtomicSchema | NotSchema | AllOfSchema | AnyOfSchema; export declare function toJSONSchema(schema: LogicalCombination): JSONSchema; /** * Like {@link LogicalCombination}, but `NOT`s are exclusively in the literals * */ export type LogicalCombinationOfLiterals = LogicLiteral | AllOfSchema<LogicalCombinationOfLiterals> | AnyOfSchema<LogicalCombinationOfLiterals>; export declare function negateAtomicSchema(schema: AtomicSchema): LogicalCombinationOfLiterals; export declare class NotSchema<Schema extends LogicalCombination = LogicalCombination> { readonly not: Schema; constructor(not: Schema); toJSONSchema(): { not: JSONSchema; }; } export declare class AllOfSchema<Schema extends LogicalCombination = LogicalCombination> { readonly allOf: readonly Schema[]; constructor(allOf: Schema[]); toJSONSchema(): { allOf: JSONSchema[]; }; } export declare class AnyOfSchema<Schema extends LogicalCombination = LogicalCombination> { readonly anyOf: readonly Schema[]; constructor(anyOf: Schema[]); toJSONSchema(): { anyOf: JSONSchema[]; }; }