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

114 lines (113 loc) 5 kB
import { type JSONSchema } from '../../json-schema/index.js'; import { AtomicSchemaObject, type LogicalCombinationOfLiterals } from '../../atomic-schema/index.js'; import type { ExtractionPlugin, ConjunctionSchema } from '../../plugin/index.js'; import { type ValidateFunction } from '../../validate/index.js'; export declare class RequiredAtomicSchema extends AtomicSchemaObject { readonly requiredKey: string; constructor(requiredKey: string); negate(): LogicalCombinationOfLiterals; toJSONSchema(): { required: [string]; }; } export declare class MinPropertiesAtomicSchema extends AtomicSchemaObject { readonly minProperties: number; constructor(minProperties: number); negate(): LogicalCombinationOfLiterals; toJSONSchema(): { minProperties: number; }; } export declare class MaxPropertiesAtomicSchema extends AtomicSchemaObject { readonly maxProperties: number; constructor(maxProperties: number); negate(): LogicalCombinationOfLiterals; toJSONSchema(): { maxProperties: number; }; } export declare class PropertyAtomicSchema extends AtomicSchemaObject { readonly key: string; readonly schema: JSONSchema; constructor(key: string, schema: JSONSchema); negate(): LogicalCombinationOfLiterals; toJSONSchema(): { properties: Record<string, JSONSchema>; }; } export type PatternPropertiesAtomicSchemaJSON = { patternProperties: Record<string, JSONSchema>; }; export declare class PatternPropertyAtomicSchema extends AtomicSchemaObject { readonly keyPattern: string; readonly schema: JSONSchema; constructor(keyPattern: string, schema: JSONSchema); negate(): LogicalCombinationOfLiterals; toJSONSchema(): PatternPropertiesAtomicSchemaJSON; } export type AdditionalPropertiesAtomicSchemaJSON = { additionalProperties: JSONSchema; properties?: Record<string, true>; patternProperties?: Record<string, true>; }; export declare class AdditionalPropertiesAtomicSchema extends AtomicSchemaObject { readonly additionalProperties: JSONSchema; readonly propertyKeys: readonly string[]; readonly propertyKeyPatterns: readonly string[]; constructor(additionalProperties: JSONSchema, propertyKeys: string[], propertyKeyPatterns: string[]); negate(): LogicalCombinationOfLiterals; toJSONSchema(): AdditionalPropertiesAtomicSchemaJSON; } export declare class PropertyNamesAtomicSchema extends AtomicSchemaObject { readonly propertyNames: JSONSchema; constructor(propertyNames: JSONSchema); negate(): LogicalCombinationOfLiterals; toJSONSchema(): { propertyNames: JSONSchema; }; } export declare class UnevaluatedPropertiesAtomicSchema extends AtomicSchemaObject { negate(): LogicalCombinationOfLiterals; toJSONSchema(): JSONSchema; } export declare const objectExtraction: ExtractionPlugin; export declare function createGetPropertyValueSchemaByKey({ validate, propertyNames, propertyAtomicSchemasByKey, patternPropertyAtomicSchemasByKeyPatternEntries, additionalPropertiesAtomicSchemas, }: { validate: ValidateFunction; propertyNames: JSONSchema; propertyAtomicSchemasByKey: Record<string, JSONSchema[]>; patternPropertyAtomicSchemasByKeyPatternEntries: [string, JSONSchema[]][]; additionalPropertiesAtomicSchemas: AdditionalPropertiesAtomicSchema[]; }): (key: string) => JSONSchema; export declare function createGetPropertyValueSchemaByKeyPattern({ validate, schemaDescribesEmptySet, propertyNames, patternPropertyAtomicSchemasByKeyPattern, additionalPropertiesAtomicSchemas, }: { validate: ValidateFunction; schemaDescribesEmptySet: (schema: JSONSchema) => boolean | null; propertyNames: JSONSchema; patternPropertyAtomicSchemasByKeyPattern: Record<string, JSONSchema[]>; additionalPropertiesAtomicSchemas: AdditionalPropertiesAtomicSchema[]; }): (keyPattern: string) => JSONSchema; export type ObjectConjunctionSchema = { properties?: Record<string, JSONSchema>; patternProperties?: Record<string, JSONSchema>; required?: string[]; propertyNames?: JSONSchema; minProperties?: number; maxProperties?: number; allOf?: ({ not: { const: Record<string, unknown>; }; } | AdditionalPropertiesAtomicSchemaJSON | { not: PatternPropertiesAtomicSchemaJSON; } | { not: AdditionalPropertiesAtomicSchemaJSON; } | { not: { propertyNames: JSONSchema; }; })[]; }; export declare const objectSimplification: { readonly appliesToJSONSchemaType: "object"; readonly mergeableKeywords: ["properties", "patternProperties", "required", "propertyNames", "minProperties", "maxProperties"]; readonly simplify: ({ atomicSchemasByConstructor, negatedAtomicSchemasByConstructor, schemaDescribesEmptySet, options, splitToRawDNF, validateConst, }: import("../../plugin/plugin.js").SimplificationPluginArguments) => ConjunctionSchema<ObjectConjunctionSchema>; };