json-schema-compatibility-checker 1.1.12 → 1.1.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/constraint-validator.d.ts +2 -2
- package/dist/cjs/constraint-validator.js +1 -1
- package/dist/cjs/constraint-validator.js.map +1 -1
- package/dist/cjs/index.d.ts +1 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/json-schema-compatibility-checker.js +1 -1
- package/dist/cjs/json-schema-compatibility-checker.js.map +1 -1
- package/dist/cjs/subset-checker.js +1 -1
- package/dist/cjs/subset-checker.js.map +1 -1
- package/dist/cjs/types.d.ts +36 -3
- package/dist/cjs/types.js.map +1 -1
- package/dist/esm/constraint-validator.d.ts +2 -2
- package/dist/esm/constraint-validator.js +1 -1
- package/dist/esm/constraint-validator.js.map +1 -1
- package/dist/esm/index.d.ts +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/json-schema-compatibility-checker.js +1 -1
- package/dist/esm/json-schema-compatibility-checker.js.map +1 -1
- package/dist/esm/subset-checker.js +1 -1
- package/dist/esm/subset-checker.js.map +1 -1
- package/dist/esm/types.d.ts +36 -3
- package/dist/esm/types.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { JSONSchema7Definition } from "json-schema";
|
|
2
|
-
import type { ConstraintValidatorRegistry, SchemaError } from "./types.js";
|
|
2
|
+
import type { ConstraintExecutionContext, ConstraintValidatorRegistry, SchemaError } from "./types.js";
|
|
3
3
|
/**
|
|
4
4
|
* Recursively validates runtime data against all `constraints` found
|
|
5
5
|
* in a schema, using the provided validator registry.
|
|
@@ -18,4 +18,4 @@ import type { ConstraintValidatorRegistry, SchemaError } from "./types.js";
|
|
|
18
18
|
* @param path - The current property path (for error reporting)
|
|
19
19
|
* @returns Array of schema errors (empty if all constraints pass)
|
|
20
20
|
*/
|
|
21
|
-
export declare function validateSchemaConstraints(schema: JSONSchema7Definition, data: unknown, registry: ConstraintValidatorRegistry, path?: string): Promise<SchemaError[]>;
|
|
21
|
+
export declare function validateSchemaConstraints(schema: JSONSchema7Definition, data: unknown, registry: ConstraintValidatorRegistry, context?: ConstraintExecutionContext, path?: string): Promise<SchemaError[]>;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:true});Object.defineProperty(exports,"validateSchemaConstraints",{enumerable:true,get:function(){return validateSchemaConstraints}});const _typests=require("./types.js");const _utilsts=require("./utils.js");async function validateValue(constraints,value,registry,path){const errors=[];for(const constraint of constraints){const name=typeof constraint==="string"?constraint:constraint.name;const params=typeof constraint==="string"?undefined:constraint.params;const validator=registry[name];if(!validator){errors.push({type:_typests.SchemaErrorType.CustomConstraint,key:path||"$root",expected:name,received:"unknown constraint (not registered)"});continue}try{const result=await validator(value,params);if(!result.valid){errors.push({type:_typests.SchemaErrorType.CustomConstraint,key:path||"$root",expected:name,received:result.message??"constraint validation failed"})}}catch(err){errors.push({type:_typests.SchemaErrorType.CustomConstraint,key:path||"$root",expected:name,received:err instanceof Error?err.message:"constraint validation error"})}}return errors}async function validateSchemaConstraints(schema,data,registry,path=""){if(typeof schema==="boolean")return[];const errors=[];const constraints=(0,_utilsts.toConstraintArray)(schema.constraints);if(constraints.length>0){errors.push(...await validateValue(constraints,data,registry,path))}if((0,_utilsts.isPlainObj)(schema.properties)&&(0,_utilsts.isPlainObj)(data)){const props=schema.properties;const dataObj=data;for(const key of Object.keys(props)){const propSchema=props[key];if(propSchema===undefined)continue;const propValue=dataObj[key];if(propValue===undefined&&!(0,_utilsts.hasOwn)(dataObj,key))continue;const propPath=path?`${path}.${key}`:key;errors.push(...await validateSchemaConstraints(propSchema,propValue,registry,propPath))}}if((0,_utilsts.isPlainObj)(schema.items)&&Array.isArray(data)){const itemSchema=schema.items;const itemPath=path?`${path}[]`:"[]";for(let i=0;i<data.length;i++){errors.push(...await validateSchemaConstraints(itemSchema,data[i],registry,itemPath))}}if(Array.isArray(schema.items)&&Array.isArray(data)){const tupleSchemas=schema.items;for(let i=0;i<tupleSchemas.length&&i<data.length;i++){const itemSchema=tupleSchemas[i];if(itemSchema===undefined)continue;const itemPath=path?`${path}[${i}]`:`[${i}]`;errors.push(...await validateSchemaConstraints(itemSchema,data[i],registry,itemPath))}}if((0,_utilsts.isPlainObj)(schema.patternProperties)&&(0,_utilsts.isPlainObj)(data)){const pp=schema.patternProperties;const dataObj=data;for(const pattern of Object.keys(pp)){const patternSchema=pp[pattern];if(patternSchema===undefined||typeof patternSchema==="boolean")continue;let regex;try{regex=new RegExp(pattern)}catch{continue}for(const dataKey of Object.keys(dataObj)){if(!regex.test(dataKey))continue;const dataValue=dataObj[dataKey];const ppPath=path?`${path}.${dataKey}`:dataKey;errors.push(...await validateSchemaConstraints(patternSchema,dataValue,registry,ppPath))}}}if((0,_utilsts.isPlainObj)(schema.additionalProperties)&&typeof schema.additionalProperties!=="boolean"&&(0,_utilsts.isPlainObj)(data)){const apSchema=schema.additionalProperties;const dataObj=data;const definedProps=(0,_utilsts.isPlainObj)(schema.properties)?new Set(Object.keys(schema.properties)):new Set;const ppPatterns=[];if((0,_utilsts.isPlainObj)(schema.patternProperties)){for(const pattern of Object.keys(schema.patternProperties)){try{ppPatterns.push(new RegExp(pattern))}catch{}}}for(const dataKey of Object.keys(dataObj)){if(definedProps.has(dataKey))continue;if(ppPatterns.some(re=>re.test(dataKey)))continue;const dataValue=dataObj[dataKey];const apPath=path?`${path}.${dataKey}`:dataKey;errors.push(...await validateSchemaConstraints(apSchema,dataValue,registry,apPath))}}if((0,_utilsts.isPlainObj)(schema.dependencies)&&(0,_utilsts.isPlainObj)(data)){const deps=schema.dependencies;const dataObj=data;for(const depKey of Object.keys(deps)){if(!(0,_utilsts.hasOwn)(dataObj,depKey))continue;const depValue=deps[depKey];if(depValue===undefined)continue;if(Array.isArray(depValue))continue;if(typeof depValue==="boolean")continue;errors.push(...await validateSchemaConstraints(depValue,data,registry,path))}}return errors}
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});Object.defineProperty(exports,"validateSchemaConstraints",{enumerable:true,get:function(){return validateSchemaConstraints}});const _typests=require("./types.js");const _utilsts=require("./utils.js");async function validateValue(constraints,value,registry,path,context){const errors=[];for(const constraint of constraints){const name=typeof constraint==="string"?constraint:constraint.name;const params=typeof constraint==="string"?undefined:constraint.params;const validator=registry[name];if(!validator){errors.push({type:_typests.SchemaErrorType.CustomConstraint,key:path||"$root",expected:name,received:"unknown constraint (not registered)"});continue}try{const result=await validator(value,params,context);if(!result.valid){errors.push({type:_typests.SchemaErrorType.CustomConstraint,key:path||"$root",expected:name,received:result.message??"constraint validation failed"})}}catch(err){errors.push({type:_typests.SchemaErrorType.CustomConstraint,key:path||"$root",expected:name,received:err instanceof Error?err.message:"constraint validation error"})}}return errors}async function validateSchemaConstraints(schema,data,registry,context,path=""){if(typeof schema==="boolean")return[];const errors=[];const constraints=(0,_utilsts.toConstraintArray)(schema.constraints);if(constraints.length>0){errors.push(...await validateValue(constraints,data,registry,path,context))}if((0,_utilsts.isPlainObj)(schema.properties)&&(0,_utilsts.isPlainObj)(data)){const props=schema.properties;const dataObj=data;for(const key of Object.keys(props)){const propSchema=props[key];if(propSchema===undefined)continue;const propValue=dataObj[key];if(propValue===undefined&&!(0,_utilsts.hasOwn)(dataObj,key))continue;const propPath=path?`${path}.${key}`:key;errors.push(...await validateSchemaConstraints(propSchema,propValue,registry,context,propPath))}}if((0,_utilsts.isPlainObj)(schema.items)&&Array.isArray(data)){const itemSchema=schema.items;const itemPath=path?`${path}[]`:"[]";for(let i=0;i<data.length;i++){errors.push(...await validateSchemaConstraints(itemSchema,data[i],registry,context,itemPath))}}if(Array.isArray(schema.items)&&Array.isArray(data)){const tupleSchemas=schema.items;for(let i=0;i<tupleSchemas.length&&i<data.length;i++){const itemSchema=tupleSchemas[i];if(itemSchema===undefined)continue;const itemPath=path?`${path}[${i}]`:`[${i}]`;errors.push(...await validateSchemaConstraints(itemSchema,data[i],registry,context,itemPath))}}if((0,_utilsts.isPlainObj)(schema.patternProperties)&&(0,_utilsts.isPlainObj)(data)){const pp=schema.patternProperties;const dataObj=data;for(const pattern of Object.keys(pp)){const patternSchema=pp[pattern];if(patternSchema===undefined||typeof patternSchema==="boolean")continue;let regex;try{regex=new RegExp(pattern)}catch{continue}for(const dataKey of Object.keys(dataObj)){if(!regex.test(dataKey))continue;const dataValue=dataObj[dataKey];const ppPath=path?`${path}.${dataKey}`:dataKey;errors.push(...await validateSchemaConstraints(patternSchema,dataValue,registry,context,ppPath))}}}if((0,_utilsts.isPlainObj)(schema.additionalProperties)&&typeof schema.additionalProperties!=="boolean"&&(0,_utilsts.isPlainObj)(data)){const apSchema=schema.additionalProperties;const dataObj=data;const definedProps=(0,_utilsts.isPlainObj)(schema.properties)?new Set(Object.keys(schema.properties)):new Set;const ppPatterns=[];if((0,_utilsts.isPlainObj)(schema.patternProperties)){for(const pattern of Object.keys(schema.patternProperties)){try{ppPatterns.push(new RegExp(pattern))}catch{}}}for(const dataKey of Object.keys(dataObj)){if(definedProps.has(dataKey))continue;if(ppPatterns.some(re=>re.test(dataKey)))continue;const dataValue=dataObj[dataKey];const apPath=path?`${path}.${dataKey}`:dataKey;errors.push(...await validateSchemaConstraints(apSchema,dataValue,registry,context,apPath))}}if((0,_utilsts.isPlainObj)(schema.dependencies)&&(0,_utilsts.isPlainObj)(data)){const deps=schema.dependencies;const dataObj=data;for(const depKey of Object.keys(deps)){if(!(0,_utilsts.hasOwn)(dataObj,depKey))continue;const depValue=deps[depKey];if(depValue===undefined)continue;if(Array.isArray(depValue))continue;if(typeof depValue==="boolean")continue;errors.push(...await validateSchemaConstraints(depValue,data,registry,context,path))}}return errors}
|
|
2
2
|
//# sourceMappingURL=constraint-validator.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/constraint-validator.ts"],"sourcesContent":["import type { JSONSchema7Definition } from \"json-schema\";\nimport type {\n\tConstraint,\n\tConstraintValidatorRegistry,\n\tSchemaError,\n} from \"./types.ts\";\nimport { SchemaErrorType } from \"./types.ts\";\nimport { hasOwn, isPlainObj, toConstraintArray } from \"./utils.ts\";\n\n// ─── Constraint Validator ────────────────────────────────────────────────────\n//\n// Validates runtime data against custom `constraints` found in a schema,\n// using the provided validator registry.\n//\n// This module is separate from `runtime-validator.ts` (which wraps AJV)\n// and from `format-validator.ts` (which handles the `format` keyword).\n\n/**\n * Validates a single value against a list of constraints using the registry.\n *\n * @param constraints - The constraints to validate against\n * @param value - The runtime value\n * @param registry - The constraint validator registry\n * @param path - The property path for error reporting\n * @returns Array of errors (empty if all constraints pass)\n */\nasync function validateValue(\n\tconstraints: Constraint[],\n\tvalue: unknown,\n\tregistry: ConstraintValidatorRegistry,\n\tpath: string,\n): Promise<SchemaError[]> {\n\tconst errors: SchemaError[] = [];\n\n\tfor (const constraint of constraints) {\n\t\tconst name = typeof constraint === \"string\" ? constraint : constraint.name;\n\t\tconst params =\n\t\t\ttypeof constraint === \"string\" ? undefined : constraint.params;\n\n\t\tconst validator = registry[name];\n\n\t\tif (!validator) {\n\t\t\terrors.push({\n\t\t\t\ttype: SchemaErrorType.CustomConstraint,\n\t\t\t\tkey: path || \"$root\",\n\t\t\t\texpected: name,\n\t\t\t\treceived: \"unknown constraint (not registered)\",\n\t\t\t});\n\t\t\tcontinue;\n\t\t}\n\n\t\ttry {\n\t\t\tconst result = await validator(value, params);\n\t\t\tif (!result.valid) {\n\t\t\t\terrors.push({\n\t\t\t\t\ttype: SchemaErrorType.CustomConstraint,\n\t\t\t\t\tkey: path || \"$root\",\n\t\t\t\t\texpected: name,\n\t\t\t\t\treceived: result.message ?? \"constraint validation failed\",\n\t\t\t\t});\n\t\t\t}\n\t\t} catch (err) {\n\t\t\terrors.push({\n\t\t\t\ttype: SchemaErrorType.CustomConstraint,\n\t\t\t\tkey: path || \"$root\",\n\t\t\t\texpected: name,\n\t\t\t\treceived:\n\t\t\t\t\terr instanceof Error ? err.message : \"constraint validation error\",\n\t\t\t});\n\t\t}\n\t}\n\n\treturn errors;\n}\n\n/**\n * Recursively validates runtime data against all `constraints` found\n * in a schema, using the provided validator registry.\n *\n * Walks into: root-level constraints, `properties`, `patternProperties`,\n * `items` (single schema and tuple form), `additionalProperties` (schema form),\n * `dependencies` (schema form).\n *\n * When a schema declares a constraint that is not present in the registry,\n * an \"unknown constraint (not registered)\" error is produced. This ensures\n * that unregistered constraints are never silently ignored at runtime.\n *\n * @param schema - The resolved/narrowed schema containing constraints\n * @param data - The runtime data to validate\n * @param registry - The constraint validator registry (may be empty)\n * @param path - The current property path (for error reporting)\n * @returns Array of schema errors (empty if all constraints pass)\n */\nexport async function validateSchemaConstraints(\n\tschema: JSONSchema7Definition,\n\tdata: unknown,\n\tregistry: ConstraintValidatorRegistry,\n\tpath = \"\",\n): Promise<SchemaError[]> {\n\t// Boolean schemas → nothing to validate\n\tif (typeof schema === \"boolean\") return [];\n\n\tconst errors: SchemaError[] = [];\n\n\t// ── Root-level constraints ──\n\tconst constraints = toConstraintArray(schema.constraints);\n\tif (constraints.length > 0) {\n\t\terrors.push(...(await validateValue(constraints, data, registry, path)));\n\t}\n\n\t// ── Recurse into properties ──\n\tif (isPlainObj(schema.properties) && isPlainObj(data)) {\n\t\tconst props = schema.properties as Record<string, JSONSchema7Definition>;\n\t\tconst dataObj = data as Record<string, unknown>;\n\n\t\tfor (const key of Object.keys(props)) {\n\t\t\tconst propSchema = props[key];\n\t\t\tif (propSchema === undefined) continue;\n\n\t\t\tconst propValue = dataObj[key];\n\t\t\t// Only validate if the property exists in the data\n\t\t\tif (propValue === undefined && !hasOwn(dataObj, key)) continue;\n\n\t\t\tconst propPath = path ? `${path}.${key}` : key;\n\t\t\terrors.push(\n\t\t\t\t...(await validateSchemaConstraints(\n\t\t\t\t\tpropSchema,\n\t\t\t\t\tpropValue,\n\t\t\t\t\tregistry,\n\t\t\t\t\tpropPath,\n\t\t\t\t)),\n\t\t\t);\n\t\t}\n\t}\n\n\t// ── Recurse into items (single schema) ──\n\tif (isPlainObj(schema.items) && Array.isArray(data)) {\n\t\tconst itemSchema = schema.items as JSONSchema7Definition;\n\t\tconst itemPath = path ? `${path}[]` : \"[]\";\n\n\t\tfor (let i = 0; i < data.length; i++) {\n\t\t\terrors.push(\n\t\t\t\t...(await validateSchemaConstraints(\n\t\t\t\t\titemSchema,\n\t\t\t\t\tdata[i],\n\t\t\t\t\tregistry,\n\t\t\t\t\titemPath,\n\t\t\t\t)),\n\t\t\t);\n\t\t}\n\t}\n\n\t// ── Recurse into tuple items ──\n\tif (Array.isArray(schema.items) && Array.isArray(data)) {\n\t\tconst tupleSchemas = schema.items as JSONSchema7Definition[];\n\t\tfor (let i = 0; i < tupleSchemas.length && i < data.length; i++) {\n\t\t\tconst itemSchema = tupleSchemas[i];\n\t\t\tif (itemSchema === undefined) continue;\n\t\t\tconst itemPath = path ? `${path}[${i}]` : `[${i}]`;\n\t\t\terrors.push(\n\t\t\t\t...(await validateSchemaConstraints(\n\t\t\t\t\titemSchema,\n\t\t\t\t\tdata[i],\n\t\t\t\t\tregistry,\n\t\t\t\t\titemPath,\n\t\t\t\t)),\n\t\t\t);\n\t\t}\n\t}\n\n\t// ── Recurse into patternProperties ──\n\tif (isPlainObj(schema.patternProperties) && isPlainObj(data)) {\n\t\tconst pp = schema.patternProperties as Record<\n\t\t\tstring,\n\t\t\tJSONSchema7Definition\n\t\t>;\n\t\tconst dataObj = data as Record<string, unknown>;\n\n\t\tfor (const pattern of Object.keys(pp)) {\n\t\t\tconst patternSchema = pp[pattern];\n\t\t\tif (patternSchema === undefined || typeof patternSchema === \"boolean\")\n\t\t\t\tcontinue;\n\n\t\t\tlet regex: RegExp;\n\t\t\ttry {\n\t\t\t\tregex = new RegExp(pattern);\n\t\t\t} catch {\n\t\t\t\t// Invalid regex pattern — skip silently (same approach as AJV)\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tfor (const dataKey of Object.keys(dataObj)) {\n\t\t\t\tif (!regex.test(dataKey)) continue;\n\n\t\t\t\tconst dataValue = dataObj[dataKey];\n\t\t\t\tconst ppPath = path ? `${path}.${dataKey}` : dataKey;\n\t\t\t\terrors.push(\n\t\t\t\t\t...(await validateSchemaConstraints(\n\t\t\t\t\t\tpatternSchema,\n\t\t\t\t\t\tdataValue,\n\t\t\t\t\t\tregistry,\n\t\t\t\t\t\tppPath,\n\t\t\t\t\t)),\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t}\n\n\t// ── Recurse into additionalProperties (schema form) ──\n\tif (\n\t\tisPlainObj(schema.additionalProperties) &&\n\t\ttypeof schema.additionalProperties !== \"boolean\" &&\n\t\tisPlainObj(data)\n\t) {\n\t\tconst apSchema = schema.additionalProperties as JSONSchema7Definition;\n\t\tconst dataObj = data as Record<string, unknown>;\n\t\tconst definedProps = isPlainObj(schema.properties)\n\t\t\t? new Set(Object.keys(schema.properties as Record<string, unknown>))\n\t\t\t: new Set<string>();\n\n\t\t// Collect patternProperties regexes to exclude matching keys\n\t\tconst ppPatterns: RegExp[] = [];\n\t\tif (isPlainObj(schema.patternProperties)) {\n\t\t\tfor (const pattern of Object.keys(\n\t\t\t\tschema.patternProperties as Record<string, unknown>,\n\t\t\t)) {\n\t\t\t\ttry {\n\t\t\t\t\tppPatterns.push(new RegExp(pattern));\n\t\t\t\t} catch {\n\t\t\t\t\t// Invalid pattern — skip\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tfor (const dataKey of Object.keys(dataObj)) {\n\t\t\t// Skip keys defined in properties\n\t\t\tif (definedProps.has(dataKey)) continue;\n\n\t\t\t// Skip keys matching any patternProperties pattern\n\t\t\tif (ppPatterns.some((re) => re.test(dataKey))) continue;\n\n\t\t\tconst dataValue = dataObj[dataKey];\n\t\t\tconst apPath = path ? `${path}.${dataKey}` : dataKey;\n\t\t\terrors.push(\n\t\t\t\t...(await validateSchemaConstraints(\n\t\t\t\t\tapSchema,\n\t\t\t\t\tdataValue,\n\t\t\t\t\tregistry,\n\t\t\t\t\tapPath,\n\t\t\t\t)),\n\t\t\t);\n\t\t}\n\t}\n\n\t// ── Recurse into dependencies (schema form) ──\n\tif (isPlainObj(schema.dependencies) && isPlainObj(data)) {\n\t\tconst deps = schema.dependencies as Record<\n\t\t\tstring,\n\t\t\tJSONSchema7Definition | string[]\n\t\t>;\n\t\tconst dataObj = data as Record<string, unknown>;\n\n\t\tfor (const depKey of Object.keys(deps)) {\n\t\t\t// Dependency only applies if the trigger key is present in data\n\t\t\tif (!hasOwn(dataObj, depKey)) continue;\n\n\t\t\tconst depValue = deps[depKey];\n\t\t\tif (depValue === undefined) continue;\n\n\t\t\t// Skip array-form dependencies (property deps, not schema deps)\n\t\t\tif (Array.isArray(depValue)) continue;\n\n\t\t\t// Skip boolean schemas\n\t\t\tif (typeof depValue === \"boolean\") continue;\n\n\t\t\t// Schema-form dependency: validate the entire data object against it\n\t\t\t// The dependency schema applies to the whole object, not just the dep key\n\t\t\terrors.push(\n\t\t\t\t...(await validateSchemaConstraints(depValue, data, registry, path)),\n\t\t\t);\n\t\t}\n\t}\n\n\treturn errors;\n}\n"],"names":["validateSchemaConstraints","validateValue","constraints","value","registry","path","errors","constraint","name","params","undefined","validator","push","type","SchemaErrorType","CustomConstraint","key","expected","received","result","valid","message","err","Error","schema","data","toConstraintArray","length","isPlainObj","properties","props","dataObj","Object","keys","propSchema","propValue","hasOwn","propPath","items","Array","isArray","itemSchema","itemPath","i","tupleSchemas","patternProperties","pp","pattern","patternSchema","regex","RegExp","dataKey","test","dataValue","ppPath","additionalProperties","apSchema","definedProps","Set","ppPatterns","has","some","re","apPath","dependencies","deps","depKey","depValue"],"mappings":"oGA6FsBA,mEAAAA,oDAvFU,qCACsB,cAmBtD,eAAeC,cACdC,WAAyB,CACzBC,KAAc,CACdC,QAAqC,CACrCC,IAAY,EAEZ,MAAMC,OAAwB,EAAE,CAEhC,IAAK,MAAMC,cAAcL,YAAa,CACrC,MAAMM,KAAO,OAAOD,aAAe,SAAWA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B,aAAaG,GAAG,CAACT,SAAU,SAG/B,GAAIQ,WAAWE,IAAI,CAAC,AAACC,IAAOA,GAAGV,IAAI,CAACD,UAAW,SAE/C,MAAME,UAAYtB,OAAO,CAACoB,QAAQ,CAClC,MAAMY,OAAS1D,KAAO,CAAC,EAAEA,KAAK,CAAC,EAAE8C,QAAQ,CAAC,CAAGA,QAC7C7C,OAAOM,IAAI,IACN,MAAMZ,0BACTwD,SACAH,UACAjD,SACA2D,QAGH,CACD,CAGA,GAAInC,GAAAA,mBAAU,EAACJ,OAAOwC,YAAY,GAAKpC,GAAAA,mBAAU,EAACH,MAAO,CACxD,MAAMwC,KAAOzC,OAAOwC,YAAY,CAIhC,MAAMjC,QAAUN,KAEhB,IAAK,MAAMyC,UAAUlC,OAAOC,IAAI,CAACgC,MAAO,CAEvC,GAAI,CAAC7B,GAAAA,eAAM,EAACL,QAASmC,QAAS,SAE9B,MAAMC,SAAWF,IAAI,CAACC,OAAO,CAC7B,GAAIC,WAAazD,UAAW,SAG5B,GAAI6B,MAAMC,OAAO,CAAC2B,UAAW,SAG7B,GAAI,OAAOA,WAAa,UAAW,SAInC7D,OAAOM,IAAI,IACN,MAAMZ,0BAA0BmE,SAAU1C,KAAMrB,SAAUC,MAEhE,CACD,CAEA,OAAOC,MACR"}
|
|
1
|
+
{"version":3,"sources":["../../src/constraint-validator.ts"],"sourcesContent":["import type { JSONSchema7Definition } from \"json-schema\";\nimport type {\n\tConstraint,\n\tConstraintExecutionContext,\n\tConstraintValidatorRegistry,\n\tSchemaError,\n} from \"./types.ts\";\nimport { SchemaErrorType } from \"./types.ts\";\nimport { hasOwn, isPlainObj, toConstraintArray } from \"./utils.ts\";\n\n// ─── Constraint Validator ────────────────────────────────────────────────────\n//\n// Validates runtime data against custom `constraints` found in a schema,\n// using the provided validator registry.\n//\n// This module is separate from `runtime-validator.ts` (which wraps AJV)\n// and from `format-validator.ts` (which handles the `format` keyword).\n\n/**\n * Validates a single value against a list of constraints using the registry.\n *\n * @param constraints - The constraints to validate against\n * @param value - The runtime value\n * @param registry - The constraint validator registry\n * @param path - The property path for error reporting\n * @returns Array of errors (empty if all constraints pass)\n */\nasync function validateValue(\n\tconstraints: Constraint[],\n\tvalue: unknown,\n\tregistry: ConstraintValidatorRegistry,\n\tpath: string,\n\tcontext: ConstraintExecutionContext | undefined,\n): Promise<SchemaError[]> {\n\tconst errors: SchemaError[] = [];\n\n\tfor (const constraint of constraints) {\n\t\tconst name = typeof constraint === \"string\" ? constraint : constraint.name;\n\t\tconst params =\n\t\t\ttypeof constraint === \"string\" ? undefined : constraint.params;\n\n\t\tconst validator = registry[name];\n\n\t\tif (!validator) {\n\t\t\terrors.push({\n\t\t\t\ttype: SchemaErrorType.CustomConstraint,\n\t\t\t\tkey: path || \"$root\",\n\t\t\t\texpected: name,\n\t\t\t\treceived: \"unknown constraint (not registered)\",\n\t\t\t});\n\t\t\tcontinue;\n\t\t}\n\n\t\ttry {\n\t\t\tconst result = await validator(value, params, context);\n\t\t\tif (!result.valid) {\n\t\t\t\terrors.push({\n\t\t\t\t\ttype: SchemaErrorType.CustomConstraint,\n\t\t\t\t\tkey: path || \"$root\",\n\t\t\t\t\texpected: name,\n\t\t\t\t\treceived: result.message ?? \"constraint validation failed\",\n\t\t\t\t});\n\t\t\t}\n\t\t} catch (err) {\n\t\t\terrors.push({\n\t\t\t\ttype: SchemaErrorType.CustomConstraint,\n\t\t\t\tkey: path || \"$root\",\n\t\t\t\texpected: name,\n\t\t\t\treceived:\n\t\t\t\t\terr instanceof Error ? err.message : \"constraint validation error\",\n\t\t\t});\n\t\t}\n\t}\n\n\treturn errors;\n}\n\n/**\n * Recursively validates runtime data against all `constraints` found\n * in a schema, using the provided validator registry.\n *\n * Walks into: root-level constraints, `properties`, `patternProperties`,\n * `items` (single schema and tuple form), `additionalProperties` (schema form),\n * `dependencies` (schema form).\n *\n * When a schema declares a constraint that is not present in the registry,\n * an \"unknown constraint (not registered)\" error is produced. This ensures\n * that unregistered constraints are never silently ignored at runtime.\n *\n * @param schema - The resolved/narrowed schema containing constraints\n * @param data - The runtime data to validate\n * @param registry - The constraint validator registry (may be empty)\n * @param path - The current property path (for error reporting)\n * @returns Array of schema errors (empty if all constraints pass)\n */\nexport async function validateSchemaConstraints(\n\tschema: JSONSchema7Definition,\n\tdata: unknown,\n\tregistry: ConstraintValidatorRegistry,\n\tcontext?: ConstraintExecutionContext,\n\tpath = \"\",\n): Promise<SchemaError[]> {\n\t// Boolean schemas → nothing to validate\n\tif (typeof schema === \"boolean\") return [];\n\n\tconst errors: SchemaError[] = [];\n\n\t// ── Root-level constraints ──\n\tconst constraints = toConstraintArray(schema.constraints);\n\tif (constraints.length > 0) {\n\t\terrors.push(\n\t\t\t...(await validateValue(constraints, data, registry, path, context)),\n\t\t);\n\t}\n\n\t// ── Recurse into properties ──\n\tif (isPlainObj(schema.properties) && isPlainObj(data)) {\n\t\tconst props = schema.properties as Record<string, JSONSchema7Definition>;\n\t\tconst dataObj = data as Record<string, unknown>;\n\n\t\tfor (const key of Object.keys(props)) {\n\t\t\tconst propSchema = props[key];\n\t\t\tif (propSchema === undefined) continue;\n\n\t\t\tconst propValue = dataObj[key];\n\t\t\t// Only validate if the property exists in the data\n\t\t\tif (propValue === undefined && !hasOwn(dataObj, key)) continue;\n\n\t\t\tconst propPath = path ? `${path}.${key}` : key;\n\t\t\terrors.push(\n\t\t\t\t...(await validateSchemaConstraints(\n\t\t\t\t\tpropSchema,\n\t\t\t\t\tpropValue,\n\t\t\t\t\tregistry,\n\t\t\t\t\tcontext,\n\t\t\t\t\tpropPath,\n\t\t\t\t)),\n\t\t\t);\n\t\t}\n\t}\n\n\t// ── Recurse into items (single schema) ──\n\tif (isPlainObj(schema.items) && Array.isArray(data)) {\n\t\tconst itemSchema = schema.items as JSONSchema7Definition;\n\t\tconst itemPath = path ? `${path}[]` : \"[]\";\n\n\t\tfor (let i = 0; i < data.length; i++) {\n\t\t\terrors.push(\n\t\t\t\t...(await validateSchemaConstraints(\n\t\t\t\t\titemSchema,\n\t\t\t\t\tdata[i],\n\t\t\t\t\tregistry,\n\t\t\t\t\tcontext,\n\t\t\t\t\titemPath,\n\t\t\t\t)),\n\t\t\t);\n\t\t}\n\t}\n\n\t// ── Recurse into tuple items ──\n\tif (Array.isArray(schema.items) && Array.isArray(data)) {\n\t\tconst tupleSchemas = schema.items as JSONSchema7Definition[];\n\t\tfor (let i = 0; i < tupleSchemas.length && i < data.length; i++) {\n\t\t\tconst itemSchema = tupleSchemas[i];\n\t\t\tif (itemSchema === undefined) continue;\n\t\t\tconst itemPath = path ? `${path}[${i}]` : `[${i}]`;\n\t\t\terrors.push(\n\t\t\t\t...(await validateSchemaConstraints(\n\t\t\t\t\titemSchema,\n\t\t\t\t\tdata[i],\n\t\t\t\t\tregistry,\n\t\t\t\t\tcontext,\n\t\t\t\t\titemPath,\n\t\t\t\t)),\n\t\t\t);\n\t\t}\n\t}\n\n\t// ── Recurse into patternProperties ──\n\tif (isPlainObj(schema.patternProperties) && isPlainObj(data)) {\n\t\tconst pp = schema.patternProperties as Record<\n\t\t\tstring,\n\t\t\tJSONSchema7Definition\n\t\t>;\n\t\tconst dataObj = data as Record<string, unknown>;\n\n\t\tfor (const pattern of Object.keys(pp)) {\n\t\t\tconst patternSchema = pp[pattern];\n\t\t\tif (patternSchema === undefined || typeof patternSchema === \"boolean\")\n\t\t\t\tcontinue;\n\n\t\t\tlet regex: RegExp;\n\t\t\ttry {\n\t\t\t\tregex = new RegExp(pattern);\n\t\t\t} catch {\n\t\t\t\t// Invalid regex pattern — skip silently (same approach as AJV)\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tfor (const dataKey of Object.keys(dataObj)) {\n\t\t\t\tif (!regex.test(dataKey)) continue;\n\n\t\t\t\tconst dataValue = dataObj[dataKey];\n\t\t\t\tconst ppPath = path ? `${path}.${dataKey}` : dataKey;\n\t\t\t\terrors.push(\n\t\t\t\t\t...(await validateSchemaConstraints(\n\t\t\t\t\t\tpatternSchema,\n\t\t\t\t\t\tdataValue,\n\t\t\t\t\t\tregistry,\n\t\t\t\t\t\tcontext,\n\t\t\t\t\t\tppPath,\n\t\t\t\t\t)),\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t}\n\n\t// ── Recurse into additionalProperties (schema form) ──\n\tif (\n\t\tisPlainObj(schema.additionalProperties) &&\n\t\ttypeof schema.additionalProperties !== \"boolean\" &&\n\t\tisPlainObj(data)\n\t) {\n\t\tconst apSchema = schema.additionalProperties as JSONSchema7Definition;\n\t\tconst dataObj = data as Record<string, unknown>;\n\t\tconst definedProps = isPlainObj(schema.properties)\n\t\t\t? new Set(Object.keys(schema.properties as Record<string, unknown>))\n\t\t\t: new Set<string>();\n\n\t\t// Collect patternProperties regexes to exclude matching keys\n\t\tconst ppPatterns: RegExp[] = [];\n\t\tif (isPlainObj(schema.patternProperties)) {\n\t\t\tfor (const pattern of Object.keys(\n\t\t\t\tschema.patternProperties as Record<string, unknown>,\n\t\t\t)) {\n\t\t\t\ttry {\n\t\t\t\t\tppPatterns.push(new RegExp(pattern));\n\t\t\t\t} catch {\n\t\t\t\t\t// Invalid pattern — skip\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tfor (const dataKey of Object.keys(dataObj)) {\n\t\t\t// Skip keys defined in properties\n\t\t\tif (definedProps.has(dataKey)) continue;\n\n\t\t\t// Skip keys matching any patternProperties pattern\n\t\t\tif (ppPatterns.some((re) => re.test(dataKey))) continue;\n\n\t\t\tconst dataValue = dataObj[dataKey];\n\t\t\tconst apPath = path ? `${path}.${dataKey}` : dataKey;\n\t\t\terrors.push(\n\t\t\t\t...(await validateSchemaConstraints(\n\t\t\t\t\tapSchema,\n\t\t\t\t\tdataValue,\n\t\t\t\t\tregistry,\n\t\t\t\t\tcontext,\n\t\t\t\t\tapPath,\n\t\t\t\t)),\n\t\t\t);\n\t\t}\n\t}\n\n\t// ── Recurse into dependencies (schema form) ──\n\tif (isPlainObj(schema.dependencies) && isPlainObj(data)) {\n\t\tconst deps = schema.dependencies as Record<\n\t\t\tstring,\n\t\t\tJSONSchema7Definition | string[]\n\t\t>;\n\t\tconst dataObj = data as Record<string, unknown>;\n\n\t\tfor (const depKey of Object.keys(deps)) {\n\t\t\t// Dependency only applies if the trigger key is present in data\n\t\t\tif (!hasOwn(dataObj, depKey)) continue;\n\n\t\t\tconst depValue = deps[depKey];\n\t\t\tif (depValue === undefined) continue;\n\n\t\t\t// Skip array-form dependencies (property deps, not schema deps)\n\t\t\tif (Array.isArray(depValue)) continue;\n\n\t\t\t// Skip boolean schemas\n\t\t\tif (typeof depValue === \"boolean\") continue;\n\n\t\t\t// Schema-form dependency: validate the entire data object against it\n\t\t\t// The dependency schema applies to the whole object, not just the dep key\n\t\t\terrors.push(\n\t\t\t\t...(await validateSchemaConstraints(\n\t\t\t\t\tdepValue,\n\t\t\t\t\tdata,\n\t\t\t\t\tregistry,\n\t\t\t\t\tcontext,\n\t\t\t\t\tpath,\n\t\t\t\t)),\n\t\t\t);\n\t\t}\n\t}\n\n\treturn errors;\n}\n"],"names":["validateSchemaConstraints","validateValue","constraints","value","registry","path","context","errors","constraint","name","params","undefined","validator","push","type","SchemaErrorType","CustomConstraint","key","expected","received","result","valid","message","err","Error","schema","data","toConstraintArray","length","isPlainObj","properties","props","dataObj","Object","keys","propSchema","propValue","hasOwn","propPath","items","Array","isArray","itemSchema","itemPath","i","tupleSchemas","patternProperties","pp","pattern","patternSchema","regex","RegExp","dataKey","test","dataValue","ppPath","additionalProperties","apSchema","definedProps","Set","ppPatterns","has","some","re","apPath","dependencies","deps","depKey","depValue"],"mappings":"oGA+FsBA,mEAAAA,oDAxFU,qCACsB,cAmBtD,eAAeC,cACdC,WAAyB,CACzBC,KAAc,CACdC,QAAqC,CACrCC,IAAY,CACZC,OAA+C,EAE/C,MAAMC,OAAwB,EAAE,CAEhC,IAAK,MAAMC,cAAcN,YAAa,CACrC,MAAMO,KAAO,OAAOD,aAAe,SAAWA,WAAaA,WAAWC,IAAI,CAC1E,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SAAU,CAE3C,GAAI0B,aAAaG,GAAG,CAACT,SAAU,SAG/B,GAAIQ,WAAWE,IAAI,CAAC,AAACC,IAAOA,GAAGV,IAAI,CAACD,UAAW,SAE/C,MAAME,UAAYtB,OAAO,CAACoB,QAAQ,CAClC,MAAMY,OAAS3D,KAAO,CAAC,EAAEA,KAAK,CAAC,EAAE+C,QAAQ,CAAC,CAAGA,QAC7C7C,OAAOM,IAAI,IACN,MAAMb,0BACTyD,SACAH,UACAlD,SACAE,QACA0D,QAGH,CACD,CAGA,GAAInC,GAAAA,mBAAU,EAACJ,OAAOwC,YAAY,GAAKpC,GAAAA,mBAAU,EAACH,MAAO,CACxD,MAAMwC,KAAOzC,OAAOwC,YAAY,CAIhC,MAAMjC,QAAUN,KAEhB,IAAK,MAAMyC,UAAUlC,OAAOC,IAAI,CAACgC,MAAO,CAEvC,GAAI,CAAC7B,GAAAA,eAAM,EAACL,QAASmC,QAAS,SAE9B,MAAMC,SAAWF,IAAI,CAACC,OAAO,CAC7B,GAAIC,WAAazD,UAAW,SAG5B,GAAI6B,MAAMC,OAAO,CAAC2B,UAAW,SAG7B,GAAI,OAAOA,WAAa,UAAW,SAInC7D,OAAOM,IAAI,IACN,MAAMb,0BACToE,SACA1C,KACAtB,SACAE,QACAD,MAGH,CACD,CAEA,OAAOE,MACR"}
|
package/dist/cjs/index.d.ts
CHANGED
|
@@ -3,5 +3,5 @@ export { JsonSchemaCompatibilityChecker } from "./json-schema-compatibility-chec
|
|
|
3
3
|
export { MergeEngine } from "./merge-engine.js";
|
|
4
4
|
export { arePatternsEquivalent, isPatternSubset, isTrivialPattern, } from "./pattern-subset.js";
|
|
5
5
|
export { formatSchemaType } from "./semantic-errors.js";
|
|
6
|
-
export type { CheckerOptions, CheckRuntimeOptions, Constraint, Constraints, ConstraintValidationResult, ConstraintValidator, ConstraintValidatorRegistry, ResolvedConditionResult, ResolvedSubsetResult, SchemaError, SubsetResult, ValidateTargetOptions, ValidateTargets, } from "./types.js";
|
|
6
|
+
export type { CheckerOptions, CheckRuntimeOptions, Constraint, ConstraintExecutionContext, Constraints, ConstraintValidationResult, ConstraintValidator, ConstraintValidatorRegistry, ResolvedConditionResult, ResolvedSubsetResult, SchemaError, SubsetResult, ValidateTargetOptions, ValidateTargets, } from "./types.js";
|
|
7
7
|
export { SchemaErrorType } from "./types.js";
|
package/dist/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.ts"],"sourcesContent":["export { resolveConditions } from \"./condition-resolver.ts\";\nexport { JsonSchemaCompatibilityChecker } from \"./json-schema-compatibility-checker.ts\";\nexport { MergeEngine } from \"./merge-engine.ts\";\nexport {\n\tarePatternsEquivalent,\n\tisPatternSubset,\n\tisTrivialPattern,\n} from \"./pattern-subset.ts\";\nexport { formatSchemaType } from \"./semantic-errors.ts\";\nexport type {\n\tCheckerOptions,\n\tCheckRuntimeOptions,\n\tConstraint,\n\tConstraints,\n\tConstraintValidationResult,\n\tConstraintValidator,\n\tConstraintValidatorRegistry,\n\tResolvedConditionResult,\n\tResolvedSubsetResult,\n\tSchemaError,\n\tSubsetResult,\n\tValidateTargetOptions,\n\tValidateTargets,\n} from \"./types.ts\";\nexport { SchemaErrorType } from \"./types.ts\";\n"],"names":["JsonSchemaCompatibilityChecker","MergeEngine","SchemaErrorType","arePatternsEquivalent","formatSchemaType","isPatternSubset","isTrivialPattern","resolveConditions"],"mappings":"mPACSA,wCAAAA,gEAA8B,MAC9BC,qBAAAA,0BAAW,
|
|
1
|
+
{"version":3,"sources":["../../src/index.ts"],"sourcesContent":["export { resolveConditions } from \"./condition-resolver.ts\";\nexport { JsonSchemaCompatibilityChecker } from \"./json-schema-compatibility-checker.ts\";\nexport { MergeEngine } from \"./merge-engine.ts\";\nexport {\n\tarePatternsEquivalent,\n\tisPatternSubset,\n\tisTrivialPattern,\n} from \"./pattern-subset.ts\";\nexport { formatSchemaType } from \"./semantic-errors.ts\";\nexport type {\n\tCheckerOptions,\n\tCheckRuntimeOptions,\n\tConstraint,\n\tConstraintExecutionContext,\n\tConstraints,\n\tConstraintValidationResult,\n\tConstraintValidator,\n\tConstraintValidatorRegistry,\n\tResolvedConditionResult,\n\tResolvedSubsetResult,\n\tSchemaError,\n\tSubsetResult,\n\tValidateTargetOptions,\n\tValidateTargets,\n} from \"./types.ts\";\nexport { SchemaErrorType } from \"./types.ts\";\n"],"names":["JsonSchemaCompatibilityChecker","MergeEngine","SchemaErrorType","arePatternsEquivalent","formatSchemaType","isPatternSubset","isTrivialPattern","resolveConditions"],"mappings":"mPACSA,wCAAAA,gEAA8B,MAC9BC,qBAAAA,0BAAW,MAuBXC,yBAAAA,wBAAe,MArBvBC,+BAAAA,sCAAqB,MAIbC,0BAAAA,kCAAgB,MAHxBC,yBAAAA,gCAAe,MACfC,0BAAAA,iCAAgB,MANRC,2BAAAA,sCAAiB,uCAAQ,2EACa,uEACnB,oDAKrB,uDAC0B,+CAiBD"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:true});function _export(target,all){for(var name in all)Object.defineProperty(target,name,{enumerable:true,get:Object.getOwnPropertyDescriptor(all,name).get})}_export(exports,{get JsonSchemaCompatibilityChecker(){return JsonSchemaCompatibilityChecker},get MergeEngine(){return _mergeenginets.MergeEngine},get SchemaErrorType(){return _typests.SchemaErrorType},get arePatternsEquivalent(){return _patternsubsetts.arePatternsEquivalent},get formatResult(){return _formatterts.formatResult},get isPatternSubset(){return _patternsubsetts.isPatternSubset},get isTrivialPattern(){return _patternsubsetts.isTrivialPattern},get normalize(){return _normalizerts.normalize},get resolveConditions(){return _conditionresolverts.resolveConditions}});const _conditionresolverts=require("./condition-resolver.js");const _constraintvalidatorts=require("./constraint-validator.js");const _datanarrowingts=require("./data-narrowing.js");const _formatterts=require("./formatter.js");const _mergeenginets=require("./merge-engine.js");const _normalizerts=require("./normalizer.js");const _patternsubsetts=require("./pattern-subset.js");const _runtimevalidatorts=require("./runtime-validator.js");const _subsetcheckerts=require("./subset-checker.js");const _typests=require("./types.js");const _utilsts=require("./utils.js");const _validatetargetsts=require("./validate-targets.js");function _define_property(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true})}else{obj[key]=value}return obj}class JsonSchemaCompatibilityChecker{isSubset(sub,sup){if(sub===sup)return true;if((0,_utilsts.deepEqual)(sub,sup))return true;const nSub=(0,_normalizerts.normalize)(sub);const nSup=(0,_normalizerts.normalize)(sup);if(nSub!==sub&&nSup!==sup&&(0,_utilsts.deepEqual)(nSub,nSup))return true;if(nSub!==nSup&&(0,_utilsts.deepEqual)(nSub,nSup))return true;const{branches:subBranches}=(0,_subsetcheckerts.getBranchesTyped)(nSub);if(subBranches.length>1||subBranches[0]!==nSub){return subBranches.every(branch=>(0,_subsetcheckerts.isAtomicSubsetOf)(branch,nSup,this.engine))}return(0,_subsetcheckerts.isAtomicSubsetOf)(nSub,nSup,this.engine)}check(sub,sup,options){if(options){return this.checkWithOptions(sub,sup,options)}return this.checkInternal(sub,sup)}isEqual(a,b){return this.engine.isEqual((0,_normalizerts.normalize)(a),(0,_normalizerts.normalize)(b))}intersect(a,b){if(a===b||(0,_utilsts.deepEqual)(a,b))return(0,_normalizerts.normalize)(a);const nA=(0,_normalizerts.normalize)(a);const nB=(0,_normalizerts.normalize)(b);if((0,_utilsts.deepEqual)(nA,nB))return nA;const merged=this.engine.merge(nA,nB);if(merged===null)return null;if((0,_utilsts.deepEqual)(merged,nA)||(0,_utilsts.deepEqual)(merged,nB))return merged;return(0,_normalizerts.normalize)(merged)}normalize(def){return(0,_normalizerts.normalize)(def)}formatResult(label,result){return(0,_formatterts.formatResult)(label,result)}resolveConditions(schema,data){return(0,_conditionresolverts.resolveConditions)(schema,data,this.engine)}async checkWithOptions(sub,sup,options){const data=options.data;const{sub:validateSub,sup:validateSup,partialSub,partialSup}=(0,_validatetargetsts.resolveValidateTargets)(options.validate);const dataForConditions=(0,_utilsts.isPlainObj)(data)?data:{};const resolvedSub=(0,_conditionresolverts.resolveConditions)(sub,dataForConditions,this.engine);const resolvedSup=(0,_conditionresolverts.resolveConditions)(sup,dataForConditions,this.engine);const canNarrow=data!==undefined;const canNarrowSub=canNarrow&&(0,_utilsts.isPlainObj)(resolvedSub.resolved);const canNarrowSup=canNarrow&&(0,_utilsts.isPlainObj)(resolvedSup.resolved);const narrowedSubResolved=canNarrowSub?(0,_datanarrowingts.narrowSchemaWithData)(resolvedSub.resolved,data,resolvedSup.resolved):resolvedSub.resolved;const narrowedSupResolved=canNarrowSup?(0,_datanarrowingts.narrowSchemaWithData)(resolvedSup.resolved,data,resolvedSub.resolved):resolvedSup.resolved;const staticResult=this.checkInternal(narrowedSubResolved,narrowedSupResolved);if(!staticResult.isSubset){return{...staticResult,resolvedSub:{...resolvedSub,resolved:narrowedSubResolved},resolvedSup:{...resolvedSup,resolved:narrowedSupResolved}}}if((validateSub||validateSup)&&data!==undefined){const runtimeErrors=[];if(validateSub){const getErrors=partialSub?_runtimevalidatorts.getPartialRuntimeValidationErrors:_runtimevalidatorts.getRuntimeValidationErrors;runtimeErrors.push(...this.prefixRuntimeErrors(getErrors(narrowedSubResolved,data),"$sub"))}if(validateSup){const getErrors=partialSup?_runtimevalidatorts.getPartialRuntimeValidationErrors:_runtimevalidatorts.getRuntimeValidationErrors;runtimeErrors.push(...this.prefixRuntimeErrors(getErrors(narrowedSupResolved,data),"$sup"))}if(validateSub){runtimeErrors.push(...this.prefixRuntimeErrors(await (0,_constraintvalidatorts.validateSchemaConstraints)(narrowedSubResolved,data,this.constraintValidators),"$sub"))}if(validateSup){runtimeErrors.push(...this.prefixRuntimeErrors(await (0,_constraintvalidatorts.validateSchemaConstraints)(narrowedSupResolved,data,this.constraintValidators),"$sup"))}if(runtimeErrors.length>0){return{isSubset:false,merged:null,errors:runtimeErrors,resolvedSub:{...resolvedSub,resolved:narrowedSubResolved},resolvedSup:{...resolvedSup,resolved:narrowedSupResolved}}}}return{...staticResult,resolvedSub:{...resolvedSub,resolved:narrowedSubResolved},resolvedSup:{...resolvedSup,resolved:narrowedSupResolved}}}prefixRuntimeErrors(errors,rootKey){return errors.map(error=>({...error,key:error.key==="$root"?rootKey:`${rootKey}.${error.key}`}))}checkInternal(sub,sup){if(sub===sup){return{isSubset:true,merged:sub,errors:[]}}if((0,_utilsts.deepEqual)(sub,sup)){return{isSubset:true,merged:sub,errors:[]}}const nSub=(0,_normalizerts.normalize)(sub);const nSup=(0,_normalizerts.normalize)(sup);if((0,_utilsts.deepEqual)(nSub,nSup)){return{isSubset:true,merged:nSub,errors:[]}}const{branches:subBranches,type:subBranchType}=(0,_subsetcheckerts.getBranchesTyped)(nSub);const{branches:supBranches,type:supBranchType}=(0,_subsetcheckerts.getBranchesTyped)(nSup);if(subBranches.length>1||subBranches[0]!==nSub){return(0,_subsetcheckerts.checkBranchedSub)(subBranches,nSup,this.engine,subBranchType)}if(supBranches.length>1||supBranches[0]!==nSup){return(0,_subsetcheckerts.checkBranchedSup)(nSub,supBranches,this.engine,supBranchType)}return(0,_subsetcheckerts.checkAtomic)(nSub,nSup,this.engine)}static clearCache(){(0,_runtimevalidatorts.clearAllValidatorCaches)()}constructor(options){_define_property(this,"constraintValidators",void 0);_define_property(this,"engine",void 0);this.engine=new _mergeenginets.MergeEngine;this.constraintValidators=options?.constraints??{}}}
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});function _export(target,all){for(var name in all)Object.defineProperty(target,name,{enumerable:true,get:Object.getOwnPropertyDescriptor(all,name).get})}_export(exports,{get JsonSchemaCompatibilityChecker(){return JsonSchemaCompatibilityChecker},get MergeEngine(){return _mergeenginets.MergeEngine},get SchemaErrorType(){return _typests.SchemaErrorType},get arePatternsEquivalent(){return _patternsubsetts.arePatternsEquivalent},get formatResult(){return _formatterts.formatResult},get isPatternSubset(){return _patternsubsetts.isPatternSubset},get isTrivialPattern(){return _patternsubsetts.isTrivialPattern},get normalize(){return _normalizerts.normalize},get resolveConditions(){return _conditionresolverts.resolveConditions}});const _conditionresolverts=require("./condition-resolver.js");const _constraintvalidatorts=require("./constraint-validator.js");const _datanarrowingts=require("./data-narrowing.js");const _formatterts=require("./formatter.js");const _mergeenginets=require("./merge-engine.js");const _normalizerts=require("./normalizer.js");const _patternsubsetts=require("./pattern-subset.js");const _runtimevalidatorts=require("./runtime-validator.js");const _subsetcheckerts=require("./subset-checker.js");const _typests=require("./types.js");const _utilsts=require("./utils.js");const _validatetargetsts=require("./validate-targets.js");function _define_property(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true})}else{obj[key]=value}return obj}class JsonSchemaCompatibilityChecker{isSubset(sub,sup){if(sub===sup)return true;if((0,_utilsts.deepEqual)(sub,sup))return true;const nSub=(0,_normalizerts.normalize)(sub);const nSup=(0,_normalizerts.normalize)(sup);if(nSub!==sub&&nSup!==sup&&(0,_utilsts.deepEqual)(nSub,nSup))return true;if(nSub!==nSup&&(0,_utilsts.deepEqual)(nSub,nSup))return true;const{branches:subBranches}=(0,_subsetcheckerts.getBranchesTyped)(nSub);if(subBranches.length>1||subBranches[0]!==nSub){return subBranches.every(branch=>(0,_subsetcheckerts.isAtomicSubsetOf)(branch,nSup,this.engine))}return(0,_subsetcheckerts.isAtomicSubsetOf)(nSub,nSup,this.engine)}check(sub,sup,options){if(options){return this.checkWithOptions(sub,sup,options)}return this.checkInternal(sub,sup)}isEqual(a,b){return this.engine.isEqual((0,_normalizerts.normalize)(a),(0,_normalizerts.normalize)(b))}intersect(a,b){if(a===b||(0,_utilsts.deepEqual)(a,b))return(0,_normalizerts.normalize)(a);const nA=(0,_normalizerts.normalize)(a);const nB=(0,_normalizerts.normalize)(b);if((0,_utilsts.deepEqual)(nA,nB))return nA;const merged=this.engine.merge(nA,nB);if(merged===null)return null;if((0,_utilsts.deepEqual)(merged,nA)||(0,_utilsts.deepEqual)(merged,nB))return merged;return(0,_normalizerts.normalize)(merged)}normalize(def){return(0,_normalizerts.normalize)(def)}formatResult(label,result){return(0,_formatterts.formatResult)(label,result)}resolveConditions(schema,data){return(0,_conditionresolverts.resolveConditions)(schema,data,this.engine)}async checkWithOptions(sub,sup,options){const data=options.data;const constraintContext=options.constraintContext;const{sub:validateSub,sup:validateSup,partialSub,partialSup}=(0,_validatetargetsts.resolveValidateTargets)(options.validate);const dataForConditions=(0,_utilsts.isPlainObj)(data)?data:{};const resolvedSub=(0,_conditionresolverts.resolveConditions)(sub,dataForConditions,this.engine);const resolvedSup=(0,_conditionresolverts.resolveConditions)(sup,dataForConditions,this.engine);const canNarrow=data!==undefined;const canNarrowSub=canNarrow&&(0,_utilsts.isPlainObj)(resolvedSub.resolved);const canNarrowSup=canNarrow&&(0,_utilsts.isPlainObj)(resolvedSup.resolved);const narrowedSubResolved=canNarrowSub?(0,_datanarrowingts.narrowSchemaWithData)(resolvedSub.resolved,data,resolvedSup.resolved):resolvedSub.resolved;const narrowedSupResolved=canNarrowSup?(0,_datanarrowingts.narrowSchemaWithData)(resolvedSup.resolved,data,resolvedSub.resolved):resolvedSup.resolved;const staticResult=this.checkInternal(narrowedSubResolved,narrowedSupResolved);if(!staticResult.isSubset){return{...staticResult,resolvedSub:{...resolvedSub,resolved:narrowedSubResolved},resolvedSup:{...resolvedSup,resolved:narrowedSupResolved}}}if((validateSub||validateSup)&&data!==undefined){const runtimeErrors=[];if(validateSub){const getErrors=partialSub?_runtimevalidatorts.getPartialRuntimeValidationErrors:_runtimevalidatorts.getRuntimeValidationErrors;runtimeErrors.push(...this.prefixRuntimeErrors(getErrors(narrowedSubResolved,data),"$sub"))}if(validateSup){const getErrors=partialSup?_runtimevalidatorts.getPartialRuntimeValidationErrors:_runtimevalidatorts.getRuntimeValidationErrors;runtimeErrors.push(...this.prefixRuntimeErrors(getErrors(narrowedSupResolved,data),"$sup"))}if(validateSub){runtimeErrors.push(...this.prefixRuntimeErrors(await (0,_constraintvalidatorts.validateSchemaConstraints)(narrowedSubResolved,data,this.constraintValidators,constraintContext),"$sub"))}if(validateSup){runtimeErrors.push(...this.prefixRuntimeErrors(await (0,_constraintvalidatorts.validateSchemaConstraints)(narrowedSupResolved,data,this.constraintValidators,constraintContext),"$sup"))}if(runtimeErrors.length>0){return{isSubset:false,merged:null,errors:runtimeErrors,resolvedSub:{...resolvedSub,resolved:narrowedSubResolved},resolvedSup:{...resolvedSup,resolved:narrowedSupResolved}}}}return{...staticResult,resolvedSub:{...resolvedSub,resolved:narrowedSubResolved},resolvedSup:{...resolvedSup,resolved:narrowedSupResolved}}}prefixRuntimeErrors(errors,rootKey){return errors.map(error=>({...error,key:error.key==="$root"?rootKey:`${rootKey}.${error.key}`}))}checkInternal(sub,sup){if(sub===sup){return{isSubset:true,merged:sub,errors:[]}}if((0,_utilsts.deepEqual)(sub,sup)){return{isSubset:true,merged:sub,errors:[]}}const nSub=(0,_normalizerts.normalize)(sub);const nSup=(0,_normalizerts.normalize)(sup);if((0,_utilsts.deepEqual)(nSub,nSup)){return{isSubset:true,merged:nSub,errors:[]}}const{branches:subBranches,type:subBranchType}=(0,_subsetcheckerts.getBranchesTyped)(nSub);const{branches:supBranches,type:supBranchType}=(0,_subsetcheckerts.getBranchesTyped)(nSup);if(subBranches.length>1||subBranches[0]!==nSub){return(0,_subsetcheckerts.checkBranchedSub)(subBranches,nSup,this.engine,subBranchType)}if(supBranches.length>1||supBranches[0]!==nSup){return(0,_subsetcheckerts.checkBranchedSup)(nSub,supBranches,this.engine,supBranchType)}return(0,_subsetcheckerts.checkAtomic)(nSub,nSup,this.engine)}static clearCache(){(0,_runtimevalidatorts.clearAllValidatorCaches)()}constructor(options){_define_property(this,"constraintValidators",void 0);_define_property(this,"engine",void 0);this.engine=new _mergeenginets.MergeEngine;this.constraintValidators=options?.constraints??{}}}
|
|
2
2
|
//# sourceMappingURL=json-schema-compatibility-checker.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/json-schema-compatibility-checker.ts"],"sourcesContent":["import type { JSONSchema7, JSONSchema7Definition } from \"json-schema\";\nimport { resolveConditions } from \"./condition-resolver.ts\";\nimport { validateSchemaConstraints } from \"./constraint-validator.ts\";\nimport { narrowSchemaWithData } from \"./data-narrowing.ts\";\nimport { formatResult } from \"./formatter.ts\";\nimport { MergeEngine } from \"./merge-engine.ts\";\nimport { normalize } from \"./normalizer.ts\";\nimport {\n\tarePatternsEquivalent,\n\tisPatternSubset,\n\tisTrivialPattern,\n} from \"./pattern-subset.ts\";\nimport {\n\tclearAllValidatorCaches,\n\tgetPartialRuntimeValidationErrors,\n\tgetRuntimeValidationErrors,\n} from \"./runtime-validator.ts\";\nimport type { BranchResult, BranchType } from \"./subset-checker.ts\";\nimport {\n\tcheckAtomic,\n\tcheckBranchedSub,\n\tcheckBranchedSup,\n\tgetBranchesTyped,\n\tisAtomicSubsetOf,\n} from \"./subset-checker.ts\";\nimport type {\n\tCheckerOptions,\n\tCheckRuntimeOptions,\n\tConstraintValidatorRegistry,\n\tResolvedConditionResult,\n\tResolvedSubsetResult,\n\tSchemaError,\n\tSubsetResult,\n\tValidateTargets,\n} from \"./types.ts\";\nimport { SchemaErrorType } from \"./types.ts\";\nimport { deepEqual, isPlainObj } from \"./utils.ts\";\nimport { resolveValidateTargets } from \"./validate-targets.ts\";\n\n// ─── Re-exports ──────────────────────────────────────────────────────────────\n\nexport type {\n\tSchemaError,\n\tSubsetResult,\n\tResolvedConditionResult,\n\tResolvedSubsetResult,\n\tCheckRuntimeOptions,\n\tValidateTargets,\n\tBranchType,\n\tBranchResult,\n};\n\nexport {\n\tSchemaErrorType,\n\tnormalize,\n\tresolveConditions,\n\tformatResult,\n\tMergeEngine,\n\tisPatternSubset,\n\tarePatternsEquivalent,\n\tisTrivialPattern,\n};\n\n// ─── Main Class ──────────────────────────────────────────────────────────────\n//\n// Lightweight facade that orchestrates sub-modules to verify compatibility\n// between JSON Schemas (Draft-07).\n//\n// Mathematical principle:\n// A ⊆ B ⟺ A ∩ B ≡ A\n//\n// In JSON Schema terms:\n// - A ∩ B = allOf([A, B]) resolved via merge\n// - ≡ = structural comparison\n//\n// @example\n// ```ts\n// const checker = new JsonSchemaCompatibilityChecker();\n//\n// checker.isSubset(strict, loose); // true\n// checker.check(loose, strict); // { isSubset: false, diffs: [...] }\n// checker.check(sub, sup, { data: {...} }); // resolves conditions then checks\n// ```\n\nexport class JsonSchemaCompatibilityChecker {\n\tprivate readonly constraintValidators: ConstraintValidatorRegistry;\n\tprivate readonly engine: MergeEngine;\n\n\tconstructor(options?: CheckerOptions) {\n\t\tthis.engine = new MergeEngine();\n\t\tthis.constraintValidators = options?.constraints ?? {};\n\t}\n\n\t// ── Subset check (boolean) ─────────────────────────────────────────────\n\n\t/**\n\t * Checks whether `sub ⊆ sup`.\n\t * Is every value valid for sub also valid for sup?\n\t *\n\t * Uses `getBranchesTyped` to distinguish `anyOf` from `oneOf`\n\t * internally, although the boolean result does not reflect the distinction.\n\t */\n\tisSubset(sub: JSONSchema7Definition, sup: JSONSchema7Definition): boolean {\n\t\t// ── Identity short-circuit ──\n\t\t// If sub and sup are the same reference, sub ⊆ sup is trivially true.\n\t\t// This avoids the entire normalize + merge + compare pipeline.\n\t\tif (sub === sup) return true;\n\n\t\t// ── Pre-normalize structural equality ──\n\t\t// If sub and sup are structurally identical before normalization,\n\t\t// they represent the same schema → sub ⊆ sup trivially.\n\t\t// This avoids the WeakMap overhead of normalize() for common cases\n\t\t// like {} ⊆ {} or identical schema objects with different references.\n\t\tif (deepEqual(sub, sup)) return true;\n\n\t\tconst nSub = normalize(sub);\n\t\tconst nSup = normalize(sup);\n\n\t\t// ── Post-normalize structural identity ──\n\t\t// After normalization, schemas that were syntactically different\n\t\t// but semantically equivalent become structurally equal\n\t\t// (e.g. {const:1} vs {const:1, type:\"integer\"}).\n\t\tif (nSub !== sub && nSup !== sup && deepEqual(nSub, nSup)) return true;\n\t\tif (nSub !== nSup && deepEqual(nSub, nSup)) return true;\n\n\t\tconst { branches: subBranches } = getBranchesTyped(nSub);\n\n\t\tif (subBranches.length > 1 || subBranches[0] !== nSub) {\n\t\t\treturn subBranches.every((branch) =>\n\t\t\t\tisAtomicSubsetOf(branch, nSup, this.engine),\n\t\t\t);\n\t\t}\n\n\t\treturn isAtomicSubsetOf(nSub, nSup, this.engine);\n\t}\n\n\t// ── Subset check (detailed) ────────────────────────────────────────────\n\n\t/**\n\t * Checks `sub ⊆ sup` and returns a detailed diagnostic\n\t * with human-readable semantic errors.\n\t *\n\t * When `options` is provided, both schemas go through runtime-aware\n\t * processing before the static check:\n\t * 1. Conditions (`if/then/else`) are resolved using `data`\n\t * (if `data` is `undefined`, conditions are resolved with `{}`)\n\t * 2. Schemas are narrowed using runtime values (enum materialization)\n\t * 3. The static subset check runs on the resolved/narrowed schemas\n\t *\n\t * When `validate` is enabled, additional runtime steps run **after** the\n\t * static check passes:\n\t * 4. `data` is validated against the targeted resolved schema(s) via AJV\n\t * 5. Custom constraints are validated against `data` for the targeted schema(s)\n\t *\n\t * `validate` accepts:\n\t * - `true` — validate against **both** sub and sup\n\t * - `{ sub: true }` — validate only against the sub schema\n\t * - `{ sup: true }` — validate only against the sup schema\n\t * - `{ sub: true, sup: true }` — equivalent to `true`\n\t *\n\t * @param sub - The source schema (subset candidate)\n\t * @param sup - The target schema (expected superset)\n\t * @param options - Runtime options with `data` and optional `validate` flag\n\t * @returns SubsetResult if no options, ResolvedSubsetResult if options provided\n\t *\n\t * @example\n\t * ```ts\n\t * // Static check (no runtime data)\n\t * checker.check(sub, sup);\n\t *\n\t * // Resolve conditions + narrowing + static check (no runtime validation)\n\t * checker.check(sub, sup, { data: { kind: \"text\", value: \"hello\" } });\n\t *\n\t * // Full pipeline including AJV + constraint runtime validation\n\t * checker.check(sub, sup, { data: { kind: \"text\", value: \"hello\" }, validate: true });\n\t * ```\n\t */\n\tcheck(\n\t\tsub: JSONSchema7Definition,\n\t\tsup: JSONSchema7Definition,\n\t\toptions: CheckRuntimeOptions,\n\t): Promise<ResolvedSubsetResult>;\n\tcheck(sub: JSONSchema7Definition, sup: JSONSchema7Definition): SubsetResult;\n\tcheck(\n\t\tsub: JSONSchema7Definition,\n\t\tsup: JSONSchema7Definition,\n\t\toptions?: CheckRuntimeOptions,\n\t): SubsetResult | Promise<ResolvedSubsetResult> {\n\t\t// ── Runtime-aware path ──\n\t\tif (options) {\n\t\t\treturn this.checkWithOptions(sub, sup, options);\n\t\t}\n\n\t\t// ── Standard path (no condition resolution) ──\n\t\treturn this.checkInternal(sub, sup);\n\t}\n\n\t// ── Equality ───────────────────────────────────────────────────────────\n\n\t/**\n\t * Checks structural equality between two schemas.\n\t */\n\tisEqual(a: JSONSchema7Definition, b: JSONSchema7Definition): boolean {\n\t\treturn this.engine.isEqual(normalize(a), normalize(b));\n\t}\n\n\t// ── Intersection ───────────────────────────────────────────────────────\n\n\t/**\n\t * Computes the intersection of two schemas (allOf merge).\n\t * Returns null if the schemas are incompatible.\n\t *\n\t * The result is normalized to eliminate structural artifacts\n\t * from the merge (e.g. redundant `enum` when `const` is present).\n\t */\n\tintersect(\n\t\ta: JSONSchema7Definition,\n\t\tb: JSONSchema7Definition,\n\t): JSONSchema7Definition | null {\n\t\t// ── Identity short-circuit ──\n\t\t// If a and b are the same reference or structurally equal,\n\t\t// intersection is just normalize(a) — skip the merge entirely.\n\t\tif (a === b || deepEqual(a, b)) return normalize(a);\n\n\t\tconst nA = normalize(a);\n\t\tconst nB = normalize(b);\n\n\t\t// ── Post-normalize identity ──\n\t\tif (deepEqual(nA, nB)) return nA;\n\n\t\tconst merged = this.engine.merge(nA, nB);\n\t\tif (merged === null) return null;\n\t\t// Fast path: if merge result equals one of the normalized inputs,\n\t\t// it's already normalized — skip redundant normalize call.\n\t\tif (deepEqual(merged, nA) || deepEqual(merged, nB)) return merged;\n\t\treturn normalize(merged);\n\t}\n\n\t// ── Normalization ──────────────────────────────────────────────────────\n\n\t/**\n\t * Normalizes a schema: infers `type` from `const`/`enum`,\n\t * and recursively normalizes all sub-schemas.\n\t */\n\tnormalize(def: JSONSchema7Definition): JSONSchema7Definition {\n\t\treturn normalize(def);\n\t}\n\n\t// ── Formatting ─────────────────────────────────────────────────────────\n\n\t/**\n\t * Formats a SubsetResult into a readable string (useful for logs/debug).\n\t */\n\tformatResult(label: string, result: SubsetResult): string {\n\t\treturn formatResult(label, result);\n\t}\n\n\t// ── Condition Resolution ────────────────────────────────────────────────\n\n\t/**\n\t * Resolves `if/then/else` conditions in a schema by evaluating the `if`\n\t * against runtime data.\n\t *\n\t * @param schema - The schema containing conditions to resolve\n\t * @param data - The runtime data used to evaluate conditions\n\t * @returns The resolved schema with branch info and discriminants\n\t */\n\tresolveConditions(\n\t\tschema: JSONSchema7,\n\t\tdata: Record<string, unknown>,\n\t): ResolvedConditionResult {\n\t\treturn resolveConditions(schema, data, this.engine);\n\t}\n\n\t// ── Private ────────────────────────────────────────────────────────────\n\n\t/**\n\t * Internal runtime-aware check logic. Extracted as an async method\n\t * so that `check()` without options stays synchronous while the\n\t * runtime path can `await` async constraint validators.\n\t */\n\tprivate async checkWithOptions(\n\t\tsub: JSONSchema7Definition,\n\t\tsup: JSONSchema7Definition,\n\t\toptions: CheckRuntimeOptions,\n\t): Promise<ResolvedSubsetResult> {\n\t\tconst data = options.data;\n\t\tconst {\n\t\t\tsub: validateSub,\n\t\t\tsup: validateSup,\n\t\t\tpartialSub,\n\t\t\tpartialSup,\n\t\t} = resolveValidateTargets(options.validate);\n\n\t\t// resolveConditions expects Record<string, unknown> for property access;\n\t\t// coerce non-object / undefined data to empty object so conditions\n\t\t// are always resolved (v1.0.11 compat: subData: undefined → {})\n\t\tconst dataForConditions: Record<string, unknown> = isPlainObj(data)\n\t\t\t? data\n\t\t\t: {};\n\n\t\tconst resolvedSub = resolveConditions(\n\t\t\tsub as JSONSchema7,\n\t\t\tdataForConditions,\n\t\t\tthis.engine,\n\t\t);\n\t\tconst resolvedSup = resolveConditions(\n\t\t\tsup as JSONSchema7,\n\t\t\tdataForConditions,\n\t\t\tthis.engine,\n\t\t);\n\n\t\t// ── Runtime-aware data narrowing ──\n\t\t// Apply narrowing only when concrete data is available.\n\t\t// When data is undefined there is nothing to narrow with.\n\t\t// Boolean schemas (true/false) cannot be narrowed — skip narrowing\n\t\t// to avoid passing a non-object to narrowSchemaWithData.\n\t\tconst canNarrow = data !== undefined;\n\t\tconst canNarrowSub = canNarrow && isPlainObj(resolvedSub.resolved);\n\t\tconst canNarrowSup = canNarrow && isPlainObj(resolvedSup.resolved);\n\n\t\tconst narrowedSubResolved = canNarrowSub\n\t\t\t? narrowSchemaWithData(resolvedSub.resolved, data, resolvedSup.resolved)\n\t\t\t: resolvedSub.resolved;\n\n\t\tconst narrowedSupResolved = canNarrowSup\n\t\t\t? narrowSchemaWithData(resolvedSup.resolved, data, resolvedSub.resolved)\n\t\t\t: resolvedSup.resolved;\n\n\t\t// ── Static subset check ──\n\t\t// Structural incompatibilities are schema-level problems — they are\n\t\t// permanent regardless of the concrete data. Run this before runtime\n\t\t// validation so that static errors always surface with higher priority.\n\t\tconst staticResult = this.checkInternal(\n\t\t\tnarrowedSubResolved,\n\t\t\tnarrowedSupResolved,\n\t\t);\n\n\t\tif (!staticResult.isSubset) {\n\t\t\treturn {\n\t\t\t\t...staticResult,\n\t\t\t\tresolvedSub: { ...resolvedSub, resolved: narrowedSubResolved },\n\t\t\t\tresolvedSup: { ...resolvedSup, resolved: narrowedSupResolved },\n\t\t\t};\n\t\t}\n\n\t\t// ── Runtime validation (opt-in) ──\n\t\t// Runs when `validate` is truthy (boolean or object with sub/sup flags).\n\t\t// Validates the concrete data against the targeted resolved/narrowed\n\t\t// schema(s) via AJV, then runs custom constraint validators if registered.\n\t\tif ((validateSub || validateSup) && data !== undefined) {\n\t\t\tconst runtimeErrors: SchemaError[] = [];\n\n\t\t\t// ── AJV validation ──\n\t\t\t// When partial mode is active for a target, use\n\t\t\t// getPartialRuntimeValidationErrors which strips `required` and\n\t\t\t// `additionalProperties` before AJV compilation so that only\n\t\t\t// the properties present in data are validated.\n\t\t\tif (validateSub) {\n\t\t\t\tconst getErrors = partialSub\n\t\t\t\t\t? getPartialRuntimeValidationErrors\n\t\t\t\t\t: getRuntimeValidationErrors;\n\t\t\t\truntimeErrors.push(\n\t\t\t\t\t...this.prefixRuntimeErrors(\n\t\t\t\t\t\tgetErrors(narrowedSubResolved, data),\n\t\t\t\t\t\t\"$sub\",\n\t\t\t\t\t),\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tif (validateSup) {\n\t\t\t\tconst getErrors = partialSup\n\t\t\t\t\t? getPartialRuntimeValidationErrors\n\t\t\t\t\t: getRuntimeValidationErrors;\n\t\t\t\truntimeErrors.push(\n\t\t\t\t\t...this.prefixRuntimeErrors(\n\t\t\t\t\t\tgetErrors(narrowedSupResolved, data),\n\t\t\t\t\t\t\"$sup\",\n\t\t\t\t\t),\n\t\t\t\t);\n\t\t\t}\n\n\t\t\t// ── Constraint validation ──\n\t\t\t// Validate runtime data against custom constraints in the targeted\n\t\t\t// schema(s). If a schema declares constraints that are not registered\n\t\t\t// in the registry, validateSchemaConstraints will report them as\n\t\t\t// \"unknown constraint (not registered)\" errors.\n\t\t\t// Constraint validators may be async, so we await the results.\n\t\t\tif (validateSub) {\n\t\t\t\truntimeErrors.push(\n\t\t\t\t\t...this.prefixRuntimeErrors(\n\t\t\t\t\t\tawait validateSchemaConstraints(\n\t\t\t\t\t\t\tnarrowedSubResolved,\n\t\t\t\t\t\t\tdata,\n\t\t\t\t\t\t\tthis.constraintValidators,\n\t\t\t\t\t\t),\n\t\t\t\t\t\t\"$sub\",\n\t\t\t\t\t),\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tif (validateSup) {\n\t\t\t\truntimeErrors.push(\n\t\t\t\t\t...this.prefixRuntimeErrors(\n\t\t\t\t\t\tawait validateSchemaConstraints(\n\t\t\t\t\t\t\tnarrowedSupResolved,\n\t\t\t\t\t\t\tdata,\n\t\t\t\t\t\t\tthis.constraintValidators,\n\t\t\t\t\t\t),\n\t\t\t\t\t\t\"$sup\",\n\t\t\t\t\t),\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tif (runtimeErrors.length > 0) {\n\t\t\t\treturn {\n\t\t\t\t\tisSubset: false,\n\t\t\t\t\tmerged: null,\n\t\t\t\t\terrors: runtimeErrors,\n\t\t\t\t\tresolvedSub: { ...resolvedSub, resolved: narrowedSubResolved },\n\t\t\t\t\tresolvedSup: { ...resolvedSup, resolved: narrowedSupResolved },\n\t\t\t\t};\n\t\t\t}\n\t\t}\n\n\t\treturn {\n\t\t\t...staticResult,\n\t\t\tresolvedSub: { ...resolvedSub, resolved: narrowedSubResolved },\n\t\t\tresolvedSup: { ...resolvedSup, resolved: narrowedSupResolved },\n\t\t};\n\t}\n\n\tprivate prefixRuntimeErrors(\n\t\terrors: SchemaError[],\n\t\trootKey: \"$sub\" | \"$sup\",\n\t): SchemaError[] {\n\t\treturn errors.map((error) => ({\n\t\t\t...error,\n\t\t\tkey: error.key === \"$root\" ? rootKey : `${rootKey}.${error.key}`,\n\t\t}));\n\t}\n\n\t/**\n\t * Internal check logic without condition resolution.\n\t * Factorizes the normalize → branch → atomic pipeline to avoid\n\t * duplication between the two paths of `check()`.\n\t */\n\tprivate checkInternal(\n\t\tsub: JSONSchema7Definition,\n\t\tsup: JSONSchema7Definition,\n\t): SubsetResult {\n\t\t// ── Identity short-circuit ──\n\t\t// Same reference → no errors, no merge needed.\n\t\tif (sub === sup) {\n\t\t\treturn { isSubset: true, merged: sub, errors: [] };\n\t\t}\n\n\t\t// ── Pre-normalize structural equality ──\n\t\t// Avoids WeakMap overhead for identical schemas ({} ⊆ {}, etc.).\n\t\tif (deepEqual(sub, sup)) {\n\t\t\treturn { isSubset: true, merged: sub, errors: [] };\n\t\t}\n\n\t\tconst nSub = normalize(sub);\n\t\tconst nSup = normalize(sup);\n\n\t\t// ── Post-normalize structural identity ──\n\t\t// Catches semantically equivalent schemas after normalization.\n\t\tif (deepEqual(nSub, nSup)) {\n\t\t\treturn { isSubset: true, merged: nSub, errors: [] };\n\t\t}\n\n\t\tconst { branches: subBranches, type: subBranchType } =\n\t\t\tgetBranchesTyped(nSub);\n\t\tconst { branches: supBranches, type: supBranchType } =\n\t\t\tgetBranchesTyped(nSup);\n\n\t\t// anyOf/oneOf in sub\n\t\tif (subBranches.length > 1 || subBranches[0] !== nSub) {\n\t\t\treturn checkBranchedSub(subBranches, nSup, this.engine, subBranchType);\n\t\t}\n\n\t\t// anyOf/oneOf in sup only\n\t\tif (supBranches.length > 1 || supBranches[0] !== nSup) {\n\t\t\treturn checkBranchedSup(nSub, supBranches, this.engine, supBranchType);\n\t\t}\n\n\t\t// Standard case\n\t\treturn checkAtomic(nSub, nSup, this.engine);\n\t}\n\n\t// ── Cache management ───────────────────────────────────────────────────\n\n\t/**\n\t * Clears all compiled AJV validator caches (WeakMap, LRU, and AJV internal).\n\t *\n\t * Useful for:\n\t * - Long-running processes where schemas evolve over time\n\t * - Test isolation (ensuring no cross-test cache pollution)\n\t * - Memory pressure situations where cached validators are no longer needed\n\t *\n\t * After calling this, the next validation call will recompile validators\n\t * from scratch — there is a one-time performance cost per unique schema.\n\t *\n\t * This is a static method because the AJV instance is a module-level\n\t * singleton shared across all `JsonSchemaCompatibilityChecker` instances.\n\t *\n\t * @example\n\t * ```ts\n\t * JsonSchemaCompatibilityChecker.clearCache();\n\t * ```\n\t */\n\tstatic clearCache(): void {\n\t\tclearAllValidatorCaches();\n\t}\n}\n"],"names":["JsonSchemaCompatibilityChecker","MergeEngine","SchemaErrorType","arePatternsEquivalent","formatResult","isPatternSubset","isTrivialPattern","normalize","resolveConditions","isSubset","sub","sup","deepEqual","nSub","nSup","branches","subBranches","getBranchesTyped","length","every","branch","isAtomicSubsetOf","engine","check","options","checkWithOptions","checkInternal","isEqual","a","b","intersect","nA","nB","merged","merge","def","label","result","schema","data","validateSub","validateSup","partialSub","partialSup","resolveValidateTargets","validate","dataForConditions","isPlainObj","resolvedSub","resolvedSup","canNarrow","undefined","canNarrowSub","resolved","canNarrowSup","narrowedSubResolved","narrowSchemaWithData","narrowedSupResolved","staticResult","runtimeErrors","getErrors","getPartialRuntimeValidationErrors","getRuntimeValidationErrors","push","prefixRuntimeErrors","validateSchemaConstraints","constraintValidators","errors","rootKey","map","error","key","type","subBranchType","supBranches","supBranchType","checkBranchedSub","checkBranchedSup","checkAtomic","clearCache","clearAllValidatorCaches","constraints"],"mappings":"mPAoFaA,wCAAAA,oCA3BZC,qBAAAA,0BAAW,MAJXC,yBAAAA,wBAAe,MAMfC,+BAAAA,sCAAqB,MAHrBC,sBAAAA,yBAAY,MAEZC,yBAAAA,gCAAe,MAEfC,0BAAAA,iCAAgB,MANhBC,mBAAAA,uBAAS,MACTC,2BAAAA,sCAAiB,uCAtDgB,gEACQ,4DACL,kDACR,+CACD,iDACF,kDAKnB,yDAKA,yDAQA,8CAWyB,qCACM,+CACC,6MA+ChC,MAAMR,+BAkBZS,SAASC,GAA0B,CAAEC,GAA0B,CAAW,CAIzE,GAAID,MAAQC,IAAK,OAAO,KAOxB,GAAIC,GAAAA,kBAAS,EAACF,IAAKC,KAAM,OAAO,KAEhC,MAAME,KAAON,GAAAA,uBAAS,EAACG,KACvB,MAAMI,KAAOP,GAAAA,uBAAS,EAACI,KAMvB,GAAIE,OAASH,KAAOI,OAASH,KAAOC,GAAAA,kBAAS,EAACC,KAAMC,MAAO,OAAO,KAClE,GAAID,OAASC,MAAQF,GAAAA,kBAAS,EAACC,KAAMC,MAAO,OAAO,KAEnD,KAAM,CAAEC,SAAUC,WAAW,CAAE,CAAGC,GAAAA,iCAAgB,EAACJ,MAEnD,GAAIG,YAAYE,MAAM,CAAG,GAAKF,WAAW,CAAC,EAAE,GAAKH,KAAM,CACtD,OAAOG,YAAYG,KAAK,CAAC,AAACC,QACzBC,GAAAA,iCAAgB,EAACD,OAAQN,KAAM,IAAI,CAACQ,MAAM,EAE5C,CAEA,MAAOD,GAAAA,iCAAgB,EAACR,KAAMC,KAAM,IAAI,CAACQ,MAAM,CAChD,CAiDAC,MACCb,GAA0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"sourcesContent":["import type { JSONSchema7, JSONSchema7Definition } from \"json-schema\";\nimport { resolveConditions } from \"./condition-resolver.ts\";\nimport { validateSchemaConstraints } from \"./constraint-validator.ts\";\nimport { narrowSchemaWithData } from \"./data-narrowing.ts\";\nimport { formatResult } from \"./formatter.ts\";\nimport { MergeEngine } from \"./merge-engine.ts\";\nimport { normalize } from \"./normalizer.ts\";\nimport {\n\tarePatternsEquivalent,\n\tisPatternSubset,\n\tisTrivialPattern,\n} from \"./pattern-subset.ts\";\nimport {\n\tclearAllValidatorCaches,\n\tgetPartialRuntimeValidationErrors,\n\tgetRuntimeValidationErrors,\n} from \"./runtime-validator.ts\";\nimport type { BranchResult, BranchType } from \"./subset-checker.ts\";\nimport {\n\tcheckAtomic,\n\tcheckBranchedSub,\n\tcheckBranchedSup,\n\tgetBranchesTyped,\n\tisAtomicSubsetOf,\n} from \"./subset-checker.ts\";\nimport type {\n\tCheckerOptions,\n\tCheckRuntimeOptions,\n\tConstraintExecutionContext,\n\tConstraintValidatorRegistry,\n\tResolvedConditionResult,\n\tResolvedSubsetResult,\n\tSchemaError,\n\tSubsetResult,\n\tValidateTargets,\n} from \"./types.ts\";\nimport { SchemaErrorType } from \"./types.ts\";\nimport { deepEqual, isPlainObj } from \"./utils.ts\";\nimport { resolveValidateTargets } from \"./validate-targets.ts\";\n\n// ─── Re-exports ──────────────────────────────────────────────────────────────\n\nexport type {\n\tSchemaError,\n\tSubsetResult,\n\tResolvedConditionResult,\n\tResolvedSubsetResult,\n\tCheckRuntimeOptions,\n\tValidateTargets,\n\tBranchType,\n\tBranchResult,\n};\n\nexport {\n\tSchemaErrorType,\n\tnormalize,\n\tresolveConditions,\n\tformatResult,\n\tMergeEngine,\n\tisPatternSubset,\n\tarePatternsEquivalent,\n\tisTrivialPattern,\n};\n\n// ─── Main Class ──────────────────────────────────────────────────────────────\n//\n// Lightweight facade that orchestrates sub-modules to verify compatibility\n// between JSON Schemas (Draft-07).\n//\n// Mathematical principle:\n// A ⊆ B ⟺ A ∩ B ≡ A\n//\n// In JSON Schema terms:\n// - A ∩ B = allOf([A, B]) resolved via merge\n// - ≡ = structural comparison\n//\n// @example\n// ```ts\n// const checker = new JsonSchemaCompatibilityChecker();\n//\n// checker.isSubset(strict, loose); // true\n// checker.check(loose, strict); // { isSubset: false, diffs: [...] }\n// checker.check(sub, sup, { data: {...} }); // resolves conditions then checks\n// ```\n\nexport class JsonSchemaCompatibilityChecker {\n\tprivate readonly constraintValidators: ConstraintValidatorRegistry;\n\tprivate readonly engine: MergeEngine;\n\n\tconstructor(options?: CheckerOptions) {\n\t\tthis.engine = new MergeEngine();\n\t\tthis.constraintValidators = options?.constraints ?? {};\n\t}\n\n\t// ── Subset check (boolean) ─────────────────────────────────────────────\n\n\t/**\n\t * Checks whether `sub ⊆ sup`.\n\t * Is every value valid for sub also valid for sup?\n\t *\n\t * Uses `getBranchesTyped` to distinguish `anyOf` from `oneOf`\n\t * internally, although the boolean result does not reflect the distinction.\n\t */\n\tisSubset(sub: JSONSchema7Definition, sup: JSONSchema7Definition): boolean {\n\t\t// ── Identity short-circuit ──\n\t\t// If sub and sup are the same reference, sub ⊆ sup is trivially true.\n\t\t// This avoids the entire normalize + merge + compare pipeline.\n\t\tif (sub === sup) return true;\n\n\t\t// ── Pre-normalize structural equality ──\n\t\t// If sub and sup are structurally identical before normalization,\n\t\t// they represent the same schema → sub ⊆ sup trivially.\n\t\t// This avoids the WeakMap overhead of normalize() for common cases\n\t\t// like {} ⊆ {} or identical schema objects with different references.\n\t\tif (deepEqual(sub, sup)) return true;\n\n\t\tconst nSub = normalize(sub);\n\t\tconst nSup = normalize(sup);\n\n\t\t// ── Post-normalize structural identity ──\n\t\t// After normalization, schemas that were syntactically different\n\t\t// but semantically equivalent become structurally equal\n\t\t// (e.g. {const:1} vs {const:1, type:\"integer\"}).\n\t\tif (nSub !== sub && nSup !== sup && deepEqual(nSub, nSup)) return true;\n\t\tif (nSub !== nSup && deepEqual(nSub, nSup)) return true;\n\n\t\tconst { branches: subBranches } = getBranchesTyped(nSub);\n\n\t\tif (subBranches.length > 1 || subBranches[0] !== nSub) {\n\t\t\treturn subBranches.every((branch) =>\n\t\t\t\tisAtomicSubsetOf(branch, nSup, this.engine),\n\t\t\t);\n\t\t}\n\n\t\treturn isAtomicSubsetOf(nSub, nSup, this.engine);\n\t}\n\n\t// ── Subset check (detailed) ────────────────────────────────────────────\n\n\t/**\n\t * Checks `sub ⊆ sup` and returns a detailed diagnostic\n\t * with human-readable semantic errors.\n\t *\n\t * When `options` is provided, both schemas go through runtime-aware\n\t * processing before the static check:\n\t * 1. Conditions (`if/then/else`) are resolved using `data`\n\t * (if `data` is `undefined`, conditions are resolved with `{}`)\n\t * 2. Schemas are narrowed using runtime values (enum materialization)\n\t * 3. The static subset check runs on the resolved/narrowed schemas\n\t *\n\t * When `validate` is enabled, additional runtime steps run **after** the\n\t * static check passes:\n\t * 4. `data` is validated against the targeted resolved schema(s) via AJV\n\t * 5. Custom constraints are validated against `data` for the targeted schema(s)\n\t *\n\t * `validate` accepts:\n\t * - `true` — validate against **both** sub and sup\n\t * - `{ sub: true }` — validate only against the sub schema\n\t * - `{ sup: true }` — validate only against the sup schema\n\t * - `{ sub: true, sup: true }` — equivalent to `true`\n\t *\n\t * @param sub - The source schema (subset candidate)\n\t * @param sup - The target schema (expected superset)\n\t * @param options - Runtime options with `data` and optional `validate` flag\n\t * @returns SubsetResult if no options, ResolvedSubsetResult if options provided\n\t *\n\t * @example\n\t * ```ts\n\t * // Static check (no runtime data)\n\t * checker.check(sub, sup);\n\t *\n\t * // Resolve conditions + narrowing + static check (no runtime validation)\n\t * checker.check(sub, sup, { data: { kind: \"text\", value: \"hello\" } });\n\t *\n\t * // Full pipeline including AJV + constraint runtime validation\n\t * checker.check(sub, sup, { data: { kind: \"text\", value: \"hello\" }, validate: true });\n\t * ```\n\t */\n\tcheck(\n\t\tsub: JSONSchema7Definition,\n\t\tsup: JSONSchema7Definition,\n\t\toptions: CheckRuntimeOptions,\n\t): Promise<ResolvedSubsetResult>;\n\tcheck(sub: JSONSchema7Definition, sup: JSONSchema7Definition): SubsetResult;\n\tcheck(\n\t\tsub: JSONSchema7Definition,\n\t\tsup: JSONSchema7Definition,\n\t\toptions?: CheckRuntimeOptions,\n\t): SubsetResult | Promise<ResolvedSubsetResult> {\n\t\t// ── Runtime-aware path ──\n\t\tif (options) {\n\t\t\treturn this.checkWithOptions(sub, sup, options);\n\t\t}\n\n\t\t// ── Standard path (no condition resolution) ──\n\t\treturn this.checkInternal(sub, sup);\n\t}\n\n\t// ── Equality ───────────────────────────────────────────────────────────\n\n\t/**\n\t * Checks structural equality between two schemas.\n\t */\n\tisEqual(a: JSONSchema7Definition, b: JSONSchema7Definition): boolean {\n\t\treturn this.engine.isEqual(normalize(a), normalize(b));\n\t}\n\n\t// ── Intersection ───────────────────────────────────────────────────────\n\n\t/**\n\t * Computes the intersection of two schemas (allOf merge).\n\t * Returns null if the schemas are incompatible.\n\t *\n\t * The result is normalized to eliminate structural artifacts\n\t * from the merge (e.g. redundant `enum` when `const` is present).\n\t */\n\tintersect(\n\t\ta: JSONSchema7Definition,\n\t\tb: JSONSchema7Definition,\n\t): JSONSchema7Definition | null {\n\t\t// ── Identity short-circuit ──\n\t\t// If a and b are the same reference or structurally equal,\n\t\t// intersection is just normalize(a) — skip the merge entirely.\n\t\tif (a === b || deepEqual(a, b)) return normalize(a);\n\n\t\tconst nA = normalize(a);\n\t\tconst nB = normalize(b);\n\n\t\t// ── Post-normalize identity ──\n\t\tif (deepEqual(nA, nB)) return nA;\n\n\t\tconst merged = this.engine.merge(nA, nB);\n\t\tif (merged === null) return null;\n\t\t// Fast path: if merge result equals one of the normalized inputs,\n\t\t// it's already normalized — skip redundant normalize call.\n\t\tif (deepEqual(merged, nA) || deepEqual(merged, nB)) return merged;\n\t\treturn normalize(merged);\n\t}\n\n\t// ── Normalization ──────────────────────────────────────────────────────\n\n\t/**\n\t * Normalizes a schema: infers `type` from `const`/`enum`,\n\t * and recursively normalizes all sub-schemas.\n\t */\n\tnormalize(def: JSONSchema7Definition): JSONSchema7Definition {\n\t\treturn normalize(def);\n\t}\n\n\t// ── Formatting ─────────────────────────────────────────────────────────\n\n\t/**\n\t * Formats a SubsetResult into a readable string (useful for logs/debug).\n\t */\n\tformatResult(label: string, result: SubsetResult): string {\n\t\treturn formatResult(label, result);\n\t}\n\n\t// ── Condition Resolution ────────────────────────────────────────────────\n\n\t/**\n\t * Resolves `if/then/else` conditions in a schema by evaluating the `if`\n\t * against runtime data.\n\t *\n\t * @param schema - The schema containing conditions to resolve\n\t * @param data - The runtime data used to evaluate conditions\n\t * @returns The resolved schema with branch info and discriminants\n\t */\n\tresolveConditions(\n\t\tschema: JSONSchema7,\n\t\tdata: Record<string, unknown>,\n\t): ResolvedConditionResult {\n\t\treturn resolveConditions(schema, data, this.engine);\n\t}\n\n\t// ── Private ────────────────────────────────────────────────────────────\n\n\t/**\n\t * Internal runtime-aware check logic. Extracted as an async method\n\t * so that `check()` without options stays synchronous while the\n\t * runtime path can `await` async constraint validators.\n\t */\n\tprivate async checkWithOptions(\n\t\tsub: JSONSchema7Definition,\n\t\tsup: JSONSchema7Definition,\n\t\toptions: CheckRuntimeOptions,\n\t): Promise<ResolvedSubsetResult> {\n\t\tconst data = options.data;\n\t\tconst constraintContext: ConstraintExecutionContext | undefined =\n\t\t\toptions.constraintContext;\n\t\tconst {\n\t\t\tsub: validateSub,\n\t\t\tsup: validateSup,\n\t\t\tpartialSub,\n\t\t\tpartialSup,\n\t\t} = resolveValidateTargets(options.validate);\n\n\t\t// resolveConditions expects Record<string, unknown> for property access;\n\t\t// coerce non-object / undefined data to empty object so conditions\n\t\t// are always resolved (v1.0.11 compat: subData: undefined → {})\n\t\tconst dataForConditions: Record<string, unknown> = isPlainObj(data)\n\t\t\t? data\n\t\t\t: {};\n\n\t\tconst resolvedSub = resolveConditions(\n\t\t\tsub as JSONSchema7,\n\t\t\tdataForConditions,\n\t\t\tthis.engine,\n\t\t);\n\t\tconst resolvedSup = resolveConditions(\n\t\t\tsup as JSONSchema7,\n\t\t\tdataForConditions,\n\t\t\tthis.engine,\n\t\t);\n\n\t\t// ── Runtime-aware data narrowing ──\n\t\t// Apply narrowing only when concrete data is available.\n\t\t// When data is undefined there is nothing to narrow with.\n\t\t// Boolean schemas (true/false) cannot be narrowed — skip narrowing\n\t\t// to avoid passing a non-object to narrowSchemaWithData.\n\t\tconst canNarrow = data !== undefined;\n\t\tconst canNarrowSub = canNarrow && isPlainObj(resolvedSub.resolved);\n\t\tconst canNarrowSup = canNarrow && isPlainObj(resolvedSup.resolved);\n\n\t\tconst narrowedSubResolved = canNarrowSub\n\t\t\t? narrowSchemaWithData(resolvedSub.resolved, data, resolvedSup.resolved)\n\t\t\t: resolvedSub.resolved;\n\n\t\tconst narrowedSupResolved = canNarrowSup\n\t\t\t? narrowSchemaWithData(resolvedSup.resolved, data, resolvedSub.resolved)\n\t\t\t: resolvedSup.resolved;\n\n\t\t// ── Static subset check ──\n\t\t// Structural incompatibilities are schema-level problems — they are\n\t\t// permanent regardless of the concrete data. Run this before runtime\n\t\t// validation so that static errors always surface with higher priority.\n\t\tconst staticResult = this.checkInternal(\n\t\t\tnarrowedSubResolved,\n\t\t\tnarrowedSupResolved,\n\t\t);\n\n\t\tif (!staticResult.isSubset) {\n\t\t\treturn {\n\t\t\t\t...staticResult,\n\t\t\t\tresolvedSub: { ...resolvedSub, resolved: narrowedSubResolved },\n\t\t\t\tresolvedSup: { ...resolvedSup, resolved: narrowedSupResolved },\n\t\t\t};\n\t\t}\n\n\t\t// ── Runtime validation (opt-in) ──\n\t\t// Runs when `validate` is truthy (boolean or object with sub/sup flags).\n\t\t// Validates the concrete data against the targeted resolved/narrowed\n\t\t// schema(s) via AJV, then runs custom constraint validators if registered.\n\t\tif ((validateSub || validateSup) && data !== undefined) {\n\t\t\tconst runtimeErrors: SchemaError[] = [];\n\n\t\t\t// ── AJV validation ──\n\t\t\t// When partial mode is active for a target, use\n\t\t\t// getPartialRuntimeValidationErrors which strips `required` and\n\t\t\t// `additionalProperties` before AJV compilation so that only\n\t\t\t// the properties present in data are validated.\n\t\t\tif (validateSub) {\n\t\t\t\tconst getErrors = partialSub\n\t\t\t\t\t? getPartialRuntimeValidationErrors\n\t\t\t\t\t: getRuntimeValidationErrors;\n\t\t\t\truntimeErrors.push(\n\t\t\t\t\t...this.prefixRuntimeErrors(\n\t\t\t\t\t\tgetErrors(narrowedSubResolved, data),\n\t\t\t\t\t\t\"$sub\",\n\t\t\t\t\t),\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tif (validateSup) {\n\t\t\t\tconst getErrors = partialSup\n\t\t\t\t\t? getPartialRuntimeValidationErrors\n\t\t\t\t\t: getRuntimeValidationErrors;\n\t\t\t\truntimeErrors.push(\n\t\t\t\t\t...this.prefixRuntimeErrors(\n\t\t\t\t\t\tgetErrors(narrowedSupResolved, data),\n\t\t\t\t\t\t\"$sup\",\n\t\t\t\t\t),\n\t\t\t\t);\n\t\t\t}\n\n\t\t\t// ── Constraint validation ──\n\t\t\t// Validate runtime data against custom constraints in the targeted\n\t\t\t// schema(s). If a schema declares constraints that are not registered\n\t\t\t// in the registry, validateSchemaConstraints will report them as\n\t\t\t// \"unknown constraint (not registered)\" errors.\n\t\t\t// Constraint validators may be async, so we await the results.\n\t\t\tif (validateSub) {\n\t\t\t\truntimeErrors.push(\n\t\t\t\t\t...this.prefixRuntimeErrors(\n\t\t\t\t\t\tawait validateSchemaConstraints(\n\t\t\t\t\t\t\tnarrowedSubResolved,\n\t\t\t\t\t\t\tdata,\n\t\t\t\t\t\t\tthis.constraintValidators,\n\t\t\t\t\t\t\tconstraintContext,\n\t\t\t\t\t\t),\n\t\t\t\t\t\t\"$sub\",\n\t\t\t\t\t),\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tif (validateSup) {\n\t\t\t\truntimeErrors.push(\n\t\t\t\t\t...this.prefixRuntimeErrors(\n\t\t\t\t\t\tawait validateSchemaConstraints(\n\t\t\t\t\t\t\tnarrowedSupResolved,\n\t\t\t\t\t\t\tdata,\n\t\t\t\t\t\t\tthis.constraintValidators,\n\t\t\t\t\t\t\tconstraintContext,\n\t\t\t\t\t\t),\n\t\t\t\t\t\t\"$sup\",\n\t\t\t\t\t),\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tif (runtimeErrors.length > 0) {\n\t\t\t\treturn {\n\t\t\t\t\tisSubset: false,\n\t\t\t\t\tmerged: null,\n\t\t\t\t\terrors: runtimeErrors,\n\t\t\t\t\tresolvedSub: { ...resolvedSub, resolved: narrowedSubResolved },\n\t\t\t\t\tresolvedSup: { ...resolvedSup, resolved: narrowedSupResolved },\n\t\t\t\t};\n\t\t\t}\n\t\t}\n\n\t\treturn {\n\t\t\t...staticResult,\n\t\t\tresolvedSub: { ...resolvedSub, resolved: narrowedSubResolved },\n\t\t\tresolvedSup: { ...resolvedSup, resolved: narrowedSupResolved },\n\t\t};\n\t}\n\n\tprivate prefixRuntimeErrors(\n\t\terrors: SchemaError[],\n\t\trootKey: \"$sub\" | \"$sup\",\n\t): SchemaError[] {\n\t\treturn errors.map((error) => ({\n\t\t\t...error,\n\t\t\tkey: error.key === \"$root\" ? rootKey : `${rootKey}.${error.key}`,\n\t\t}));\n\t}\n\n\t/**\n\t * Internal check logic without condition resolution.\n\t * Factorizes the normalize → branch → atomic pipeline to avoid\n\t * duplication between the two paths of `check()`.\n\t */\n\tprivate checkInternal(\n\t\tsub: JSONSchema7Definition,\n\t\tsup: JSONSchema7Definition,\n\t): SubsetResult {\n\t\t// ── Identity short-circuit ──\n\t\t// Same reference → no errors, no merge needed.\n\t\tif (sub === sup) {\n\t\t\treturn { isSubset: true, merged: sub, errors: [] };\n\t\t}\n\n\t\t// ── Pre-normalize structural equality ──\n\t\t// Avoids WeakMap overhead for identical schemas ({} ⊆ {}, etc.).\n\t\tif (deepEqual(sub, sup)) {\n\t\t\treturn { isSubset: true, merged: sub, errors: [] };\n\t\t}\n\n\t\tconst nSub = normalize(sub);\n\t\tconst nSup = normalize(sup);\n\n\t\t// ── Post-normalize structural identity ──\n\t\t// Catches semantically equivalent schemas after normalization.\n\t\tif (deepEqual(nSub, nSup)) {\n\t\t\treturn { isSubset: true, merged: nSub, errors: [] };\n\t\t}\n\n\t\tconst { branches: subBranches, type: subBranchType } =\n\t\t\tgetBranchesTyped(nSub);\n\t\tconst { branches: supBranches, type: supBranchType } =\n\t\t\tgetBranchesTyped(nSup);\n\n\t\t// anyOf/oneOf in sub\n\t\tif (subBranches.length > 1 || subBranches[0] !== nSub) {\n\t\t\treturn checkBranchedSub(subBranches, nSup, this.engine, subBranchType);\n\t\t}\n\n\t\t// anyOf/oneOf in sup only\n\t\tif (supBranches.length > 1 || supBranches[0] !== nSup) {\n\t\t\treturn checkBranchedSup(nSub, supBranches, this.engine, supBranchType);\n\t\t}\n\n\t\t// Standard case\n\t\treturn checkAtomic(nSub, nSup, this.engine);\n\t}\n\n\t// ── Cache management ───────────────────────────────────────────────────\n\n\t/**\n\t * Clears all compiled AJV validator caches (WeakMap, LRU, and AJV internal).\n\t *\n\t * Useful for:\n\t * - Long-running processes where schemas evolve over time\n\t * - Test isolation (ensuring no cross-test cache pollution)\n\t * - Memory pressure situations where cached validators are no longer needed\n\t *\n\t * After calling this, the next validation call will recompile validators\n\t * from scratch — there is a one-time performance cost per unique schema.\n\t *\n\t * This is a static method because the AJV instance is a module-level\n\t * singleton shared across all `JsonSchemaCompatibilityChecker` instances.\n\t *\n\t * @example\n\t * ```ts\n\t * JsonSchemaCompatibilityChecker.clearCache();\n\t * ```\n\t */\n\tstatic clearCache(): void {\n\t\tclearAllValidatorCaches();\n\t}\n}\n"],"names":["JsonSchemaCompatibilityChecker","MergeEngine","SchemaErrorType","arePatternsEquivalent","formatResult","isPatternSubset","isTrivialPattern","normalize","resolveConditions","isSubset","sub","sup","deepEqual","nSub","nSup","branches","subBranches","getBranchesTyped","length","every","branch","isAtomicSubsetOf","engine","check","options","checkWithOptions","checkInternal","isEqual","a","b","intersect","nA","nB","merged","merge","def","label","result","schema","data","constraintContext","validateSub","validateSup","partialSub","partialSup","resolveValidateTargets","validate","dataForConditions","isPlainObj","resolvedSub","resolvedSup","canNarrow","undefined","canNarrowSub","resolved","canNarrowSup","narrowedSubResolved","narrowSchemaWithData","narrowedSupResolved","staticResult","runtimeErrors","getErrors","getPartialRuntimeValidationErrors","getRuntimeValidationErrors","push","prefixRuntimeErrors","validateSchemaConstraints","constraintValidators","errors","rootKey","map","error","key","type","subBranchType","supBranches","supBranchType","checkBranchedSub","checkBranchedSup","checkAtomic","clearCache","clearAllValidatorCaches","constraints"],"mappings":"mPAqFaA,wCAAAA,oCA3BZC,qBAAAA,0BAAW,MAJXC,yBAAAA,wBAAe,MAMfC,+BAAAA,sCAAqB,MAHrBC,sBAAAA,yBAAY,MAEZC,yBAAAA,gCAAe,MAEfC,0BAAAA,iCAAgB,MANhBC,mBAAAA,uBAAS,MACTC,2BAAAA,sCAAiB,uCAvDgB,gEACQ,4DACL,kDACR,+CACD,iDACF,kDAKnB,yDAKA,yDAQA,8CAYyB,qCACM,+CACC,6MA+ChC,MAAMR,+BAkBZS,SAASC,GAA0B,CAAEC,GAA0B,CAAW,CAIzE,GAAID,MAAQC,IAAK,OAAO,KAOxB,GAAIC,GAAAA,kBAAS,EAACF,IAAKC,KAAM,OAAO,KAEhC,MAAME,KAAON,GAAAA,uBAAS,EAACG,KACvB,MAAMI,KAAOP,GAAAA,uBAAS,EAACI,KAMvB,GAAIE,OAASH,KAAOI,OAASH,KAAOC,GAAAA,kBAAS,EAACC,KAAMC,MAAO,OAAO,KAClE,GAAID,OAASC,MAAQF,GAAAA,kBAAS,EAACC,KAAMC,MAAO,OAAO,KAEnD,KAAM,CAAEC,SAAUC,WAAW,CAAE,CAAGC,GAAAA,iCAAgB,EAACJ,MAEnD,GAAIG,YAAYE,MAAM,CAAG,GAAKF,WAAW,CAAC,EAAE,GAAKH,KAAM,CACtD,OAAOG,YAAYG,KAAK,CAAC,AAACC,Q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KAAA,GACA,sBAAiB7C,SAAjB,KAAA,EAGC,CAAA,IAAI,CAACA,MAAM,CAAG,IAAIrB,0BAAW,AAC7B,CAAA,IAAI,CAACkE,oBAAoB,CAAG3C,SAAS0D,aAAe,CAAC,CACtD,CA4aD"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:true});function _export(target,all){for(var name in all)Object.defineProperty(target,name,{enumerable:true,get:Object.getOwnPropertyDescriptor(all,name).get})}_export(exports,{get checkAtomic(){return checkAtomic},get checkBranchedSub(){return checkBranchedSub},get checkBranchedSup(){return checkBranchedSup},get getBranchesTyped(){return getBranchesTyped},get isAtomicSubsetOf(){return isAtomicSubsetOf}});const _formatvalidatorts=require("./format-validator.js");const _normalizerts=require("./normalizer.js");const _patternsubsetts=require("./pattern-subset.js");const _semanticerrorsts=require("./semantic-errors.js");const _utilsts=require("./utils.js");const BRANCH_TRUE={branches:[true],type:"none"};const BRANCH_FALSE={branches:[false],type:"none"};const atomicBranchCache=new WeakMap;function getBranchesTyped(def){if(typeof def==="boolean"){return def?BRANCH_TRUE:BRANCH_FALSE}if((0,_utilsts.hasOwn)(def,"anyOf")&&Array.isArray(def.anyOf)){return{branches:def.anyOf,type:"anyOf"}}if((0,_utilsts.hasOwn)(def,"oneOf")&&Array.isArray(def.oneOf)){return{branches:def.oneOf,type:"oneOf"}}let cached=atomicBranchCache.get(def);if(cached===undefined){cached={branches:[def],type:"none"};atomicBranchCache.set(def,cached)}return cached}function evaluateNot(sub,sup){if(typeof sub==="boolean"||typeof sup==="boolean")return null;if((0,_utilsts.hasOwn)(sup,"not")&&(0,_utilsts.isPlainObj)(sup.not)){const notSchema=sup.not;if((0,_utilsts.isPlainObj)(notSchema.properties)&&Array.isArray(notSchema.required)){const notProps=notSchema.properties;const notRequired=notSchema.required;if((0,_utilsts.isPlainObj)(sub.properties)){const subProps=sub.properties;const subRequired=Array.isArray(sub.required)?sub.required:[];const notPropKeys=Object.keys(notProps);const hasIncompatibleProp=notPropKeys.some(key=>{const notPropDef=notProps[key];if(typeof notPropDef==="boolean")return false;const notProp=notPropDef;if(notRequired.includes(key)&&!subRequired.includes(key)&&!(0,_utilsts.hasOwn)(subProps,key)){return true}if(!(0,_utilsts.hasOwn)(subProps,key))return false;const subPropDef=subProps[key];if(typeof subPropDef==="boolean")return false;const subProp=subPropDef;if((0,_utilsts.hasOwn)(notProp,"const")&&(0,_utilsts.hasOwn)(subProp,"const")){if(!(0,_utilsts.deepEqual)(notProp.const,subProp.const)){return true}}if((0,_utilsts.hasOwn)(notProp,"enum")&&Array.isArray(notProp.enum)){if((0,_utilsts.hasOwn)(subProp,"const")){const inNotEnum=notProp.enum.some(v=>(0,_utilsts.deepEqual)(v,subProp.const));if(!inNotEnum)return true}if((0,_utilsts.hasOwn)(subProp,"enum")&&Array.isArray(subProp.enum)){const noneInNotEnum=subProp.enum.every(v=>!notProp.enum?.some(nv=>(0,_utilsts.deepEqual)(v,nv)));if(noneInNotEnum)return true}}return false});if(hasIncompatibleProp)return true;const allPropsMatch=notPropKeys.every(key=>{const notPropDef=notProps[key];if(typeof notPropDef==="boolean")return true;const notProp=notPropDef;if(notRequired.includes(key)&&!subRequired.includes(key))return false;if(!(0,_utilsts.hasOwn)(subProps,key))return false;const subPropDef=subProps[key];if(typeof subPropDef==="boolean")return true;const subProp=subPropDef;if((0,_utilsts.hasOwn)(notProp,"const")&&(0,_utilsts.hasOwn)(subProp,"const")){return(0,_utilsts.deepEqual)(notProp.const,subProp.const)}if((0,_utilsts.hasOwn)(notProp,"enum")&&Array.isArray(notProp.enum)){if((0,_utilsts.hasOwn)(subProp,"const")){return notProp.enum.some(v=>(0,_utilsts.deepEqual)(v,subProp.const))}if((0,_utilsts.hasOwn)(subProp,"enum")&&Array.isArray(subProp.enum)){return subProp.enum.every(v=>notProp.enum?.some(nv=>(0,_utilsts.deepEqual)(v,nv)))}}return false});if(allPropsMatch)return false}}if((0,_utilsts.hasOwn)(notSchema,"const")&&(0,_utilsts.hasOwn)(sub,"const")){const notConst=notSchema.const;const subConst=sub.const;if((0,_utilsts.deepEqual)(subConst,notConst))return false;return true}if((0,_utilsts.hasOwn)(notSchema,"const")&&Array.isArray(sub.enum)){const notConst=notSchema.const;const allDisjoint=sub.enum.every(v=>!(0,_utilsts.deepEqual)(v,notConst));if(allDisjoint)return true;return false}if((0,_utilsts.hasOwn)(notSchema,"enum")&&Array.isArray(notSchema.enum)&&(0,_utilsts.hasOwn)(sub,"enum")&&Array.isArray(sub.enum)){const allExcluded=sub.enum.every(val=>!notSchema.enum?.some(notVal=>(0,_utilsts.deepEqual)(val,notVal)));if(allExcluded)return true}if((0,_utilsts.hasOwn)(notSchema,"enum")&&Array.isArray(notSchema.enum)&&(0,_utilsts.hasOwn)(sub,"const")){const inNotEnum=notSchema.enum.some(v=>(0,_utilsts.deepEqual)(v,sub.const));if(!inNotEnum)return true;return false}if((0,_utilsts.hasOwn)(notSchema,"type")&&(0,_utilsts.hasOwn)(sub,"type")){const notType=notSchema.type;const subType=sub.type;if(typeof notType==="string"&&typeof subType==="string"){if(!(0,_utilsts.hasOwn)(notSchema,"const")&&!(0,_utilsts.hasOwn)(notSchema,"enum")&&!(0,_utilsts.isPlainObj)(notSchema.properties)){if(subType===notType)return false;return true}}if(Array.isArray(notType)&&typeof subType==="string"){if(notType.includes(subType))return false;return true}}if((0,_utilsts.hasOwn)(notSchema,"anyOf")&&Array.isArray(notSchema.anyOf)){const branches=notSchema.anyOf;const allIncompatible=branches.every(branch=>{if(typeof branch==="boolean")return!branch;const result=evaluateNot(sub,{not:branch});return result===true});if(allIncompatible)return true;const anyBranchMatches=branches.some(branch=>{if(typeof branch==="boolean")return branch;const result=evaluateNot(sub,{not:branch});return result===false});if(anyBranchMatches)return false}if((0,_utilsts.hasOwn)(notSchema,"oneOf")&&Array.isArray(notSchema.oneOf)){const branches=notSchema.oneOf;const allIncompatible=branches.every(branch=>{if(typeof branch==="boolean")return!branch;const result=evaluateNot(sub,{not:branch});return result===true});if(allIncompatible)return true;const anyBranchMatches=branches.some(branch=>{if(typeof branch==="boolean")return branch;const result=evaluateNot(sub,{not:branch});return result===false});if(anyBranchMatches)return false}if((0,_utilsts.hasOwn)(notSchema,"format")&&(0,_utilsts.hasOwn)(sub,"format")){const subFormat=sub.format;const notFormat=notSchema.format;if(subFormat===notFormat)return false;return true}}if((0,_utilsts.hasOwn)(sub,"not")&&(0,_utilsts.hasOwn)(sup,"not")){if((0,_utilsts.deepEqual)(sub.not,sup.not))return true}return null}function stripNotFromSup(sub,sup,stripTopLevel=true){if(typeof sup==="boolean"||typeof sub==="boolean")return sup;let result=sup;if(stripTopLevel&&(0,_utilsts.hasOwn)(result,"not")){result=(0,_utilsts.omitKeys)(result,["not"])}if((0,_utilsts.isPlainObj)(result.properties)&&(0,_utilsts.isPlainObj)(sub.properties)){const subProps=sub.properties;const supProps=result.properties;let newProps;for(const key of Object.keys(supProps)){const supPropDef=supProps[key];const subPropDef=subProps[key];if(supPropDef===undefined||subPropDef===undefined||typeof supPropDef==="boolean"||typeof subPropDef==="boolean"){continue}let strippedProp=supPropDef;if((0,_utilsts.hasOwn)(supPropDef,"not")){const propNotResult=evaluateNot(subPropDef,supPropDef);if(propNotResult===true){strippedProp=(0,_utilsts.omitKeys)(supPropDef,["not"])}}const recursed=stripNotFromSup(subPropDef,strippedProp,false);if(recursed!==supPropDef){if(!newProps)newProps={...supProps};newProps[key]=recursed}}if(newProps){result={...result,properties:newProps}}}return result}function stripPatternFromSup(sub,sup){if(typeof sub==="boolean"||typeof sup==="boolean")return sup;const supObj=sup;let result=supObj;let copied=false;function ensureCopy(){if(!copied){result={...supObj};copied=true}return result}if((0,_utilsts.hasOwn)(result,"pattern")&&(0,_utilsts.hasOwn)(sub,"pattern")&&result.pattern!==sub.pattern){const patResult=(0,_patternsubsetts.isPatternSubset)(sub.pattern,result.pattern);if(patResult===true){result=(0,_utilsts.omitKeys)(ensureCopy(),["pattern"]);copied=true}}if((0,_utilsts.isPlainObj)(result.properties)&&(0,_utilsts.isPlainObj)(sub.properties)){const subProps=sub.properties;const supProps=result.properties;let propsModified=false;let newProps;for(const key of Object.keys(supProps)){const supPropDef=supProps[key];const subPropDef=subProps[key];if(supPropDef!==undefined&&subPropDef!==undefined&&typeof supPropDef!=="boolean"&&typeof subPropDef!=="boolean"&&(0,_utilsts.hasOwn)(supPropDef,"pattern")&&(0,_utilsts.hasOwn)(subPropDef,"pattern")&&supPropDef.pattern!==subPropDef.pattern){const propPatResult=(0,_patternsubsetts.isPatternSubset)(subPropDef.pattern,supPropDef.pattern);if(propPatResult===true){if(!newProps)newProps={...supProps};newProps[key]=(0,_utilsts.omitKeys)(supPropDef,["pattern"]);propsModified=true}}}if(propsModified&&newProps){ensureCopy().properties=newProps}}if((0,_utilsts.isPlainObj)(result.items)&&typeof result.items!=="boolean"&&(0,_utilsts.isPlainObj)(sub.items)&&typeof sub.items!=="boolean"){const subItems=sub.items;const supItems=result.items;if((0,_utilsts.hasOwn)(supItems,"pattern")&&(0,_utilsts.hasOwn)(subItems,"pattern")&&supItems.pattern!==subItems.pattern){const itemsPatResult=(0,_patternsubsetts.isPatternSubset)(subItems.pattern,supItems.pattern);if(itemsPatResult===true){ensureCopy().items=(0,_utilsts.omitKeys)(supItems,["pattern"])}}}return result}function stripRedundantBoundsFromSup(sub,sup){if(typeof sub==="boolean"||typeof sup==="boolean")return sup;const keysToStrip=[];if(sup.minimum!==undefined&&sub.minimum===undefined&&sub.exclusiveMinimum!==undefined&&sub.exclusiveMinimum>=sup.minimum){keysToStrip.push("minimum")}if(sup.maximum!==undefined&&sub.maximum===undefined&&sub.exclusiveMaximum!==undefined&&sub.exclusiveMaximum<=sup.maximum){keysToStrip.push("maximum")}if(sup.exclusiveMinimum!==undefined&&sub.exclusiveMinimum===undefined&&sub.minimum!==undefined&&sub.minimum>sup.exclusiveMinimum){keysToStrip.push("exclusiveMinimum")}if(sup.exclusiveMaximum!==undefined&&sub.exclusiveMaximum===undefined&&sub.maximum!==undefined&&sub.maximum<sup.exclusiveMaximum){keysToStrip.push("exclusiveMaximum")}if(keysToStrip.length>0){return(0,_utilsts.omitKeys)(sup,keysToStrip)}return sup}function stripDependenciesFromSup(sub,sup){if(typeof sub==="boolean"||typeof sup==="boolean")return sup;if(!(0,_utilsts.isPlainObj)(sup.dependencies))return sup;const supDeps=sup.dependencies;const subRequired=Array.isArray(sub.required)?sub.required:[];const subProps=(0,_utilsts.isPlainObj)(sub.properties)?sub.properties:{};const subHasAdditionalPropsFalse=sub.additionalProperties===false;for(const key of Object.keys(supDeps)){const dep=supDeps[key];if(Array.isArray(dep)){const triggerAlwaysPresent=subRequired.includes(key)||(0,_utilsts.hasOwn)(subProps,key);const triggerNeverProduced=!(0,_utilsts.hasOwn)(subProps,key)&&!subRequired.includes(key)&&subHasAdditionalPropsFalse;if(triggerNeverProduced)continue;if(triggerAlwaysPresent){const allDepsRequired=dep.every(d=>subRequired.includes(d));if(allDepsRequired)continue}return sup}if((0,_utilsts.isPlainObj)(dep)){const triggerNeverProduced=!(0,_utilsts.hasOwn)(subProps,key)&&!subRequired.includes(key)&&subHasAdditionalPropsFalse;if(triggerNeverProduced)continue;const depSchema=dep;const depRequired=Array.isArray(depSchema.required)?depSchema.required:[];const depProps=(0,_utilsts.isPlainObj)(depSchema.properties)?depSchema.properties:{};const allDepRequiredSatisfied=depRequired.every(r=>subRequired.includes(r));if(!allDepRequiredSatisfied)return sup;const allDepPropsSatisfied=Object.keys(depProps).every(propKey=>{if(!(0,_utilsts.hasOwn)(subProps,propKey))return false;const subPropDef=subProps[propKey];const depPropDef=depProps[propKey];if(subPropDef===undefined||depPropDef===undefined)return false;if(typeof subPropDef==="boolean"||typeof depPropDef==="boolean"){return subPropDef===depPropDef}const depPropKeys=Object.keys(depPropDef);return depPropKeys.every(dk=>{const depVal=depPropDef[dk];const subVal=subPropDef[dk];if(subVal===undefined)return false;if(typeof depVal==="number"&&typeof subVal==="number"){if(dk==="minLength"||dk==="minimum"||dk==="exclusiveMinimum"||dk==="minItems"||dk==="minProperties"){return subVal>=depVal}if(dk==="maxLength"||dk==="maximum"||dk==="exclusiveMaximum"||dk==="maxItems"||dk==="maxProperties"){return subVal<=depVal}}return(0,_utilsts.deepEqual)(depVal,subVal)})});if(!allDepPropsSatisfied)return sup;continue}return sup}return(0,_utilsts.omitKeys)(sup,["dependencies"])}function stripVacuousFalseProperties(merged,sub){if(typeof merged==="boolean"||typeof sub==="boolean")return merged;if(!(0,_utilsts.isPlainObj)(merged.properties))return merged;const mergedProps=merged.properties;const subProps=(0,_utilsts.isPlainObj)(sub.properties)?sub.properties:{};let strippedProps=null;for(const key of Object.keys(mergedProps)){if(mergedProps[key]===false&&!(0,_utilsts.hasOwn)(subProps,key)){if(strippedProps===null){strippedProps={...mergedProps}}delete strippedProps[key]}}if(strippedProps===null)return merged;const result={...merged,properties:strippedProps};if(Object.keys(strippedProps).length===0&&!(0,_utilsts.isPlainObj)(sub.properties)){delete result.properties}return result}function hasNestedBranching(schema){if(typeof schema==="boolean")return false;if((0,_utilsts.isPlainObj)(schema.properties)){const props=schema.properties;for(const key of Object.keys(props)){const prop=props[key];if(prop===undefined||typeof prop==="boolean")continue;if((0,_utilsts.hasOwn)(prop,"oneOf")||(0,_utilsts.hasOwn)(prop,"anyOf"))return true;if(hasNestedBranching(prop))return true}}if((0,_utilsts.isPlainObj)(schema.items)&&typeof schema.items!=="boolean"){const items=schema.items;if((0,_utilsts.hasOwn)(items,"oneOf")||(0,_utilsts.hasOwn)(items,"anyOf"))return true;if(hasNestedBranching(items))return true}return false}function isPropertySubsetOf(sub,sup,engine){const{branches:subBranches}=getBranchesTyped(sub);if(subBranches.length>1||subBranches[0]!==sub){for(const branch of subBranches){if(branch===undefined)continue;if(!isAtomicSubsetOf(branch,sup,engine))return false}return true}return isAtomicSubsetOf(sub,sup,engine)}function isArrayConstraintsSubset(sub,sup){if(sup.minItems!==undefined){if(sub.minItems===undefined||sub.minItems<sup.minItems){return false}}if(sup.maxItems!==undefined){if(sub.maxItems===undefined||sub.maxItems>sup.maxItems){return false}}if(sup.uniqueItems===true&&sub.uniqueItems!==true){return false}return true}function isObjectSubsetByProperties(sub,sup,engine){const subIsObj=sub.type==="object"||(0,_utilsts.isPlainObj)(sub.properties);const supIsObj=sup.type==="object"||(0,_utilsts.isPlainObj)(sup.properties);if(!subIsObj&&!supIsObj){if(sub.type==="array"&&sup.type==="array"&&(0,_utilsts.isPlainObj)(sub.items)&&(0,_utilsts.isPlainObj)(sup.items)){if(!isPropertySubsetOf(sub.items,sup.items,engine)){return false}return isArrayConstraintsSubset(sub,sup)}return false}if(!subIsObj||!supIsObj)return false;if((0,_utilsts.hasOwn)(sub,"type")&&(0,_utilsts.hasOwn)(sup,"type")&&sub.type!==sup.type){return false}const subProps=(0,_utilsts.isPlainObj)(sub.properties)?sub.properties:{};const supProps=(0,_utilsts.isPlainObj)(sup.properties)?sup.properties:{};const subRequired=Array.isArray(sub.required)?sub.required:[];const supRequired=Array.isArray(sup.required)?sup.required:[];for(const key of supRequired){if(!subRequired.includes(key))return false}if(sup.additionalProperties===false){for(const key of Object.keys(subProps)){if(!(0,_utilsts.hasOwn)(supProps,key))return false}}for(const key of Object.keys(supProps)){const supProp=supProps[key];const subProp=subProps[key];if(supProp===undefined||subProp===undefined)continue;if(!isPropertySubsetOf(subProp,supProp,engine)){return false}}if((0,_utilsts.isPlainObj)(sup.additionalProperties)&&typeof sup.additionalProperties!=="boolean"){const addPropSchema=sup.additionalProperties;for(const key of Object.keys(subProps)){if((0,_utilsts.hasOwn)(supProps,key))continue;const subProp=subProps[key];if(subProp===undefined)continue;if(!isPropertySubsetOf(subProp,addPropSchema,engine)){return false}}}if((0,_utilsts.isPlainObj)(sub.items)&&(0,_utilsts.isPlainObj)(sup.items)){if(!isPropertySubsetOf(sub.items,sup.items,engine)){return false}if(!isArrayConstraintsSubset(sub,sup)){return false}}return true}function tryNestedBranchingFallback(sub,sup,engine){if(typeof sub==="boolean"||typeof sup==="boolean")return null;if(!hasNestedBranching(sub)&&!hasNestedBranching(sup))return null;return isObjectSubsetByProperties(sub,sup,engine)}function resolveSupAllOf(sup,engine){if(typeof sup==="boolean")return sup;if(!Array.isArray(sup.allOf)||sup.allOf.length===0)return sup;const{allOf:_allOf,...sibling}=sup;const branches=sup.allOf;let resolved=Object.keys(sibling).length>0?sibling:null;for(const branch of branches){if(resolved===null){resolved=branch}else{resolved=engine.merge(resolved,branch);if(resolved===null){return sup}}}return resolved??sup}function isAtomicSubsetOf(sub,sup,engine){sup=resolveSupAllOf(sup,engine);const{branches:supBranches}=getBranchesTyped(sup);if(supBranches.length===1&&supBranches[0]===sup){const notResult=evaluateNot(sub,sup);if(notResult===false)return false;if(typeof sub!=="boolean"&&typeof sup!=="boolean"&&(0,_utilsts.hasOwn)(sub,"format")&&(0,_utilsts.hasOwn)(sup,"format")&&sub.format!==sup.format){const fmtResult=(0,_formatvalidatorts.isFormatSubset)(sub.format,sup.format);if(fmtResult!==true)return false}if(typeof sub!=="boolean"&&typeof sup!=="boolean"&&(0,_utilsts.hasOwn)(sub,"pattern")&&(0,_utilsts.hasOwn)(sup,"pattern")&&sub.pattern!==sup.pattern){const patResult=(0,_patternsubsetts.isPatternSubset)(sub.pattern,sup.pattern);if(patResult===false)return false}let effectiveSup=sup;if(typeof sup!=="boolean"){if(notResult===true){effectiveSup=stripNotFromSup(sub,sup,true);if(typeof effectiveSup!=="boolean"&&Object.keys(effectiveSup).length===0){return true}}else{effectiveSup=stripNotFromSup(sub,sup,false)}effectiveSup=stripPatternFromSup(sub,effectiveSup);effectiveSup=stripRedundantBoundsFromSup(sub,effectiveSup);effectiveSup=stripDependenciesFromSup(sub,effectiveSup)}const merged=engine.merge(sub,effectiveSup);if(merged===null){return tryNestedBranchingFallback(sub,effectiveSup,engine)??false}if((0,_utilsts.deepEqual)(merged,sub))return true;const strippedMerged=stripVacuousFalseProperties(merged,sub);if(strippedMerged!==merged&&(0,_utilsts.deepEqual)(strippedMerged,sub)){return true}const normalizedMerged=(0,_normalizerts.normalize)(strippedMerged);if((0,_utilsts.deepEqual)(normalizedMerged,sub)||engine.isEqual(normalizedMerged,sub)){return true}return tryNestedBranchingFallback(sub,effectiveSup,engine)??false}return supBranches.some(branch=>{const notResult=evaluateNot(sub,branch);if(notResult===false)return false;if(typeof sub!=="boolean"&&typeof branch!=="boolean"&&(0,_utilsts.hasOwn)(sub,"pattern")&&(0,_utilsts.hasOwn)(branch,"pattern")&&sub.pattern!==branch.pattern){const patResult=(0,_patternsubsetts.isPatternSubset)(sub.pattern,branch.pattern);if(patResult===false)return false}let effectiveBranch=branch;if(typeof branch!=="boolean"){if(notResult===true){effectiveBranch=stripNotFromSup(sub,branch,true);if(typeof effectiveBranch!=="boolean"&&Object.keys(effectiveBranch).length===0){return true}}else{effectiveBranch=stripNotFromSup(sub,branch,false)}effectiveBranch=stripPatternFromSup(sub,effectiveBranch);effectiveBranch=stripRedundantBoundsFromSup(sub,effectiveBranch);effectiveBranch=stripDependenciesFromSup(sub,effectiveBranch)}const merged=engine.merge(sub,effectiveBranch);if(merged===null){return tryNestedBranchingFallback(sub,effectiveBranch,engine)===true}if((0,_utilsts.deepEqual)(merged,sub))return true;const strippedBranch=stripVacuousFalseProperties(merged,sub);if(strippedBranch!==merged&&(0,_utilsts.deepEqual)(strippedBranch,sub)){return true}const normalizedBranch=(0,_normalizerts.normalize)(strippedBranch);if((0,_utilsts.deepEqual)(normalizedBranch,sub)||engine.isEqual(normalizedBranch,sub)){return true}return tryNestedBranchingFallback(sub,effectiveBranch,engine)===true})}function checkBranchedSub(subBranches,sup,engine,branchType="anyOf"){const allErrors=[];let allSubset=true;for(let i=0;i<subBranches.length;i++){const branch=subBranches[i];if(branch===undefined)continue;if(!isAtomicSubsetOf(branch,sup,engine)){allSubset=false;const branchErrors=(0,_semanticerrorsts.computeSemanticErrors)(branch,sup,"");allErrors.push(...branchErrors)}}return{isSubset:allSubset,merged:allSubset?branchType==="oneOf"?{oneOf:subBranches}:{anyOf:subBranches}:null,errors:allErrors}}function checkBranchedSup(sub,supBranches,engine,_branchType="anyOf"){for(const branch of supBranches){let effectiveBranch=branch;if(typeof sub!=="boolean"&&typeof branch!=="boolean"){const notResult=evaluateNot(sub,branch);if(notResult===false)continue;if(notResult===true){effectiveBranch=stripNotFromSup(sub,branch,true);if(typeof effectiveBranch!=="boolean"&&Object.keys(effectiveBranch).length===0){return{isSubset:true,merged:sub,errors:[]}}}else{effectiveBranch=stripNotFromSup(sub,branch,false)}effectiveBranch=stripPatternFromSup(sub,effectiveBranch);effectiveBranch=stripRedundantBoundsFromSup(sub,effectiveBranch);effectiveBranch=stripDependenciesFromSup(sub,effectiveBranch)}const merged=engine.merge(sub,effectiveBranch);if(merged!==null){if((0,_utilsts.deepEqual)(merged,sub)){return{isSubset:true,merged,errors:[]}}const normalizedMerged=(0,_normalizerts.normalize)(merged);if((0,_utilsts.deepEqual)(normalizedMerged,sub)||engine.isEqual(normalizedMerged,sub)){return{isSubset:true,merged,errors:[]}}}}const semanticErrors=(0,_semanticerrorsts.computeSemanticErrors)(sub,{anyOf:supBranches},"");return{isSubset:false,merged:null,errors:semanticErrors}}function checkAtomic(sub,sup,engine){sup=resolveSupAllOf(sup,engine);const notResult=typeof sub!=="boolean"&&typeof sup!=="boolean"?evaluateNot(sub,sup):null;if(notResult===false){const errors=(0,_semanticerrorsts.computeSemanticErrors)(sub,sup,"");return{isSubset:false,merged:null,errors}}let effectiveSup=sup;if(typeof sub!=="boolean"&&typeof sup!=="boolean"){if(notResult===true){effectiveSup=stripNotFromSup(sub,sup,true);if(typeof effectiveSup!=="boolean"&&Object.keys(effectiveSup).length===0){return{isSubset:true,merged:sub,errors:[]}}}else{effectiveSup=stripNotFromSup(sub,sup,false)}effectiveSup=stripPatternFromSup(sub,effectiveSup);effectiveSup=stripRedundantBoundsFromSup(sub,effectiveSup);effectiveSup=stripDependenciesFromSup(sub,effectiveSup)}try{const merged=engine.mergeOrThrow(sub,effectiveSup);if((0,_utilsts.deepEqual)(merged,sub)){return{isSubset:true,merged,errors:[]}}const strippedMerged=stripVacuousFalseProperties(merged,sub);if(strippedMerged!==merged&&(0,_utilsts.deepEqual)(strippedMerged,sub)){return{isSubset:true,merged:strippedMerged,errors:[]}}const normalizedMerged=(0,_normalizerts.normalize)(strippedMerged);if((0,_utilsts.deepEqual)(normalizedMerged,sub)||engine.isEqual(normalizedMerged,sub)){return{isSubset:true,merged:normalizedMerged,errors:[]}}if(tryNestedBranchingFallback(sub,effectiveSup,engine)===true){return{isSubset:true,merged:sub,errors:[]}}const errors=(0,_semanticerrorsts.computeSemanticErrors)(sub,sup,"");return{isSubset:false,merged:normalizedMerged,errors}}catch(_e){if(tryNestedBranchingFallback(sub,effectiveSup,engine)===true){return{isSubset:true,merged:sub,errors:[]}}const errors=(0,_semanticerrorsts.computeSemanticErrors)(sub,sup,"");return{isSubset:false,merged:null,errors}}}
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});function _export(target,all){for(var name in all)Object.defineProperty(target,name,{enumerable:true,get:Object.getOwnPropertyDescriptor(all,name).get})}_export(exports,{get checkAtomic(){return checkAtomic},get checkBranchedSub(){return checkBranchedSub},get checkBranchedSup(){return checkBranchedSup},get getBranchesTyped(){return getBranchesTyped},get isAtomicSubsetOf(){return isAtomicSubsetOf}});const _formatvalidatorts=require("./format-validator.js");const _normalizerts=require("./normalizer.js");const _patternsubsetts=require("./pattern-subset.js");const _semanticerrorsts=require("./semantic-errors.js");const _utilsts=require("./utils.js");const BRANCH_TRUE={branches:[true],type:"none"};const BRANCH_FALSE={branches:[false],type:"none"};const atomicBranchCache=new WeakMap;function getBranchesTyped(def){if(typeof def==="boolean"){return def?BRANCH_TRUE:BRANCH_FALSE}if((0,_utilsts.hasOwn)(def,"anyOf")&&Array.isArray(def.anyOf)){return{branches:def.anyOf,type:"anyOf"}}if((0,_utilsts.hasOwn)(def,"oneOf")&&Array.isArray(def.oneOf)){return{branches:def.oneOf,type:"oneOf"}}let cached=atomicBranchCache.get(def);if(cached===undefined){cached={branches:[def],type:"none"};atomicBranchCache.set(def,cached)}return cached}function evaluateNot(sub,sup){if(typeof sub==="boolean"||typeof sup==="boolean")return null;if((0,_utilsts.hasOwn)(sup,"not")&&(0,_utilsts.isPlainObj)(sup.not)){const notSchema=sup.not;if((0,_utilsts.isPlainObj)(notSchema.properties)&&Array.isArray(notSchema.required)){const notProps=notSchema.properties;const notRequired=notSchema.required;if((0,_utilsts.isPlainObj)(sub.properties)){const subProps=sub.properties;const subRequired=Array.isArray(sub.required)?sub.required:[];const notPropKeys=Object.keys(notProps);const hasIncompatibleProp=notPropKeys.some(key=>{const notPropDef=notProps[key];if(typeof notPropDef==="boolean")return false;const notProp=notPropDef;if(notRequired.includes(key)&&!subRequired.includes(key)&&!(0,_utilsts.hasOwn)(subProps,key)){return true}if(!(0,_utilsts.hasOwn)(subProps,key))return false;const subPropDef=subProps[key];if(typeof subPropDef==="boolean")return false;const subProp=subPropDef;if((0,_utilsts.hasOwn)(notProp,"const")&&(0,_utilsts.hasOwn)(subProp,"const")){if(!(0,_utilsts.deepEqual)(notProp.const,subProp.const)){return true}}if((0,_utilsts.hasOwn)(notProp,"enum")&&Array.isArray(notProp.enum)){if((0,_utilsts.hasOwn)(subProp,"const")){const inNotEnum=notProp.enum.some(v=>(0,_utilsts.deepEqual)(v,subProp.const));if(!inNotEnum)return true}if((0,_utilsts.hasOwn)(subProp,"enum")&&Array.isArray(subProp.enum)){const noneInNotEnum=subProp.enum.every(v=>!notProp.enum?.some(nv=>(0,_utilsts.deepEqual)(v,nv)));if(noneInNotEnum)return true}}return false});if(hasIncompatibleProp)return true;const allPropsMatch=notPropKeys.every(key=>{const notPropDef=notProps[key];if(typeof notPropDef==="boolean")return true;const notProp=notPropDef;if(notRequired.includes(key)&&!subRequired.includes(key))return false;if(!(0,_utilsts.hasOwn)(subProps,key))return false;const subPropDef=subProps[key];if(typeof subPropDef==="boolean")return true;const subProp=subPropDef;if((0,_utilsts.hasOwn)(notProp,"const")&&(0,_utilsts.hasOwn)(subProp,"const")){return(0,_utilsts.deepEqual)(notProp.const,subProp.const)}if((0,_utilsts.hasOwn)(notProp,"enum")&&Array.isArray(notProp.enum)){if((0,_utilsts.hasOwn)(subProp,"const")){return notProp.enum.some(v=>(0,_utilsts.deepEqual)(v,subProp.const))}if((0,_utilsts.hasOwn)(subProp,"enum")&&Array.isArray(subProp.enum)){return subProp.enum.every(v=>notProp.enum?.some(nv=>(0,_utilsts.deepEqual)(v,nv)))}}return false});if(allPropsMatch)return false}}if((0,_utilsts.hasOwn)(notSchema,"const")&&(0,_utilsts.hasOwn)(sub,"const")){const notConst=notSchema.const;const subConst=sub.const;if((0,_utilsts.deepEqual)(subConst,notConst))return false;return true}if((0,_utilsts.hasOwn)(notSchema,"const")&&Array.isArray(sub.enum)){const notConst=notSchema.const;const allDisjoint=sub.enum.every(v=>!(0,_utilsts.deepEqual)(v,notConst));if(allDisjoint)return true;return false}if((0,_utilsts.hasOwn)(notSchema,"enum")&&Array.isArray(notSchema.enum)&&(0,_utilsts.hasOwn)(sub,"enum")&&Array.isArray(sub.enum)){const allExcluded=sub.enum.every(val=>!notSchema.enum?.some(notVal=>(0,_utilsts.deepEqual)(val,notVal)));if(allExcluded)return true}if((0,_utilsts.hasOwn)(notSchema,"enum")&&Array.isArray(notSchema.enum)&&(0,_utilsts.hasOwn)(sub,"const")){const inNotEnum=notSchema.enum.some(v=>(0,_utilsts.deepEqual)(v,sub.const));if(!inNotEnum)return true;return false}if((0,_utilsts.hasOwn)(notSchema,"type")&&(0,_utilsts.hasOwn)(sub,"type")){const notType=notSchema.type;const subType=sub.type;if(typeof notType==="string"&&typeof subType==="string"){if(!(0,_utilsts.hasOwn)(notSchema,"const")&&!(0,_utilsts.hasOwn)(notSchema,"enum")&&!(0,_utilsts.isPlainObj)(notSchema.properties)){if(subType===notType)return false;return true}}if(Array.isArray(notType)&&typeof subType==="string"){if(notType.includes(subType))return false;return true}}if((0,_utilsts.hasOwn)(notSchema,"anyOf")&&Array.isArray(notSchema.anyOf)){const branches=notSchema.anyOf;const allIncompatible=branches.every(branch=>{if(typeof branch==="boolean")return!branch;const result=evaluateNot(sub,{not:branch});return result===true});if(allIncompatible)return true;const anyBranchMatches=branches.some(branch=>{if(typeof branch==="boolean")return branch;const result=evaluateNot(sub,{not:branch});return result===false});if(anyBranchMatches)return false}if((0,_utilsts.hasOwn)(notSchema,"oneOf")&&Array.isArray(notSchema.oneOf)){const branches=notSchema.oneOf;const allIncompatible=branches.every(branch=>{if(typeof branch==="boolean")return!branch;const result=evaluateNot(sub,{not:branch});return result===true});if(allIncompatible)return true;const anyBranchMatches=branches.some(branch=>{if(typeof branch==="boolean")return branch;const result=evaluateNot(sub,{not:branch});return result===false});if(anyBranchMatches)return false}if((0,_utilsts.hasOwn)(notSchema,"format")&&(0,_utilsts.hasOwn)(sub,"format")){const subFormat=sub.format;const notFormat=notSchema.format;if(subFormat===notFormat)return false;return true}}if((0,_utilsts.hasOwn)(sub,"not")&&(0,_utilsts.hasOwn)(sup,"not")){if((0,_utilsts.deepEqual)(sub.not,sup.not))return true}return null}function stripNotFromSup(sub,sup,stripTopLevel=true){if(typeof sup==="boolean"||typeof sub==="boolean")return sup;let result=sup;if(stripTopLevel&&(0,_utilsts.hasOwn)(result,"not")){result=(0,_utilsts.omitKeys)(result,["not"])}if((0,_utilsts.isPlainObj)(result.properties)&&(0,_utilsts.isPlainObj)(sub.properties)){const subProps=sub.properties;const supProps=result.properties;let newProps;for(const key of Object.keys(supProps)){const supPropDef=supProps[key];const subPropDef=subProps[key];if(supPropDef===undefined||subPropDef===undefined||typeof supPropDef==="boolean"||typeof subPropDef==="boolean"){continue}let strippedProp=supPropDef;if((0,_utilsts.hasOwn)(supPropDef,"not")){const propNotResult=evaluateNot(subPropDef,supPropDef);if(propNotResult===true){strippedProp=(0,_utilsts.omitKeys)(supPropDef,["not"])}}const recursed=stripNotFromSup(subPropDef,strippedProp,false);if(recursed!==supPropDef){if(!newProps)newProps={...supProps};newProps[key]=recursed}}if(newProps){result={...result,properties:newProps}}}return result}function stripPatternFromSup(sub,sup){if(typeof sub==="boolean"||typeof sup==="boolean")return sup;const supObj=sup;let result=supObj;let copied=false;function ensureCopy(){if(!copied){result={...supObj};copied=true}return result}if((0,_utilsts.hasOwn)(result,"pattern")&&(0,_utilsts.hasOwn)(sub,"pattern")&&result.pattern!==sub.pattern){const patResult=(0,_patternsubsetts.isPatternSubset)(sub.pattern,result.pattern);if(patResult===true){result=(0,_utilsts.omitKeys)(ensureCopy(),["pattern"]);copied=true}}if((0,_utilsts.isPlainObj)(result.properties)&&(0,_utilsts.isPlainObj)(sub.properties)){const subProps=sub.properties;const supProps=result.properties;let propsModified=false;let newProps;for(const key of Object.keys(supProps)){const supPropDef=supProps[key];const subPropDef=subProps[key];if(supPropDef!==undefined&&subPropDef!==undefined&&typeof supPropDef!=="boolean"&&typeof subPropDef!=="boolean"&&(0,_utilsts.hasOwn)(supPropDef,"pattern")&&(0,_utilsts.hasOwn)(subPropDef,"pattern")&&supPropDef.pattern!==subPropDef.pattern){const propPatResult=(0,_patternsubsetts.isPatternSubset)(subPropDef.pattern,supPropDef.pattern);if(propPatResult===true){if(!newProps)newProps={...supProps};newProps[key]=(0,_utilsts.omitKeys)(supPropDef,["pattern"]);propsModified=true}}}if(propsModified&&newProps){ensureCopy().properties=newProps}}if((0,_utilsts.isPlainObj)(result.items)&&typeof result.items!=="boolean"&&(0,_utilsts.isPlainObj)(sub.items)&&typeof sub.items!=="boolean"){const subItems=sub.items;const supItems=result.items;if((0,_utilsts.hasOwn)(supItems,"pattern")&&(0,_utilsts.hasOwn)(subItems,"pattern")&&supItems.pattern!==subItems.pattern){const itemsPatResult=(0,_patternsubsetts.isPatternSubset)(subItems.pattern,supItems.pattern);if(itemsPatResult===true){ensureCopy().items=(0,_utilsts.omitKeys)(supItems,["pattern"])}}}return result}function stripRedundantBoundsFromSup(sub,sup){if(typeof sub==="boolean"||typeof sup==="boolean")return sup;const keysToStrip=[];if(sup.minimum!==undefined&&sub.minimum===undefined&&sub.exclusiveMinimum!==undefined&&sub.exclusiveMinimum>=sup.minimum){keysToStrip.push("minimum")}if(sup.maximum!==undefined&&sub.maximum===undefined&&sub.exclusiveMaximum!==undefined&&sub.exclusiveMaximum<=sup.maximum){keysToStrip.push("maximum")}if(sup.exclusiveMinimum!==undefined&&sub.exclusiveMinimum===undefined&&sub.minimum!==undefined&&sub.minimum>sup.exclusiveMinimum){keysToStrip.push("exclusiveMinimum")}if(sup.exclusiveMaximum!==undefined&&sub.exclusiveMaximum===undefined&&sub.maximum!==undefined&&sub.maximum<sup.exclusiveMaximum){keysToStrip.push("exclusiveMaximum")}let result=keysToStrip.length>0?(0,_utilsts.omitKeys)(sup,keysToStrip):sup;const resultObj=result;if((0,_utilsts.isPlainObj)(resultObj.properties)&&(0,_utilsts.isPlainObj)(sub.properties)){const subProps=sub.properties;const supProps=resultObj.properties;let newProps;for(const key of Object.keys(supProps)){const supProp=supProps[key];const subProp=subProps[key];if(supProp!==undefined&&subProp!==undefined&&typeof supProp!=="boolean"&&typeof subProp!=="boolean"){const stripped=stripRedundantBoundsFromSup(subProp,supProp);if(stripped!==supProp){if(!newProps)newProps={...supProps};newProps[key]=stripped}}}if(newProps){result={...resultObj,properties:newProps}}}return result}function stripDependenciesFromSup(sub,sup){if(typeof sub==="boolean"||typeof sup==="boolean")return sup;if(!(0,_utilsts.isPlainObj)(sup.dependencies))return sup;const supDeps=sup.dependencies;const subRequired=Array.isArray(sub.required)?sub.required:[];const subProps=(0,_utilsts.isPlainObj)(sub.properties)?sub.properties:{};const subHasAdditionalPropsFalse=sub.additionalProperties===false;for(const key of Object.keys(supDeps)){const dep=supDeps[key];if(Array.isArray(dep)){const triggerAlwaysPresent=subRequired.includes(key)||(0,_utilsts.hasOwn)(subProps,key);const triggerNeverProduced=!(0,_utilsts.hasOwn)(subProps,key)&&!subRequired.includes(key)&&subHasAdditionalPropsFalse;if(triggerNeverProduced)continue;if(triggerAlwaysPresent){const allDepsRequired=dep.every(d=>subRequired.includes(d));if(allDepsRequired)continue}return sup}if((0,_utilsts.isPlainObj)(dep)){const triggerNeverProduced=!(0,_utilsts.hasOwn)(subProps,key)&&!subRequired.includes(key)&&subHasAdditionalPropsFalse;if(triggerNeverProduced)continue;const depSchema=dep;const depRequired=Array.isArray(depSchema.required)?depSchema.required:[];const depProps=(0,_utilsts.isPlainObj)(depSchema.properties)?depSchema.properties:{};const allDepRequiredSatisfied=depRequired.every(r=>subRequired.includes(r));if(!allDepRequiredSatisfied)return sup;const allDepPropsSatisfied=Object.keys(depProps).every(propKey=>{if(!(0,_utilsts.hasOwn)(subProps,propKey))return false;const subPropDef=subProps[propKey];const depPropDef=depProps[propKey];if(subPropDef===undefined||depPropDef===undefined)return false;if(typeof subPropDef==="boolean"||typeof depPropDef==="boolean"){return subPropDef===depPropDef}const depPropKeys=Object.keys(depPropDef);return depPropKeys.every(dk=>{const depVal=depPropDef[dk];const subVal=subPropDef[dk];if(subVal===undefined)return false;if(typeof depVal==="number"&&typeof subVal==="number"){if(dk==="minLength"||dk==="minimum"||dk==="exclusiveMinimum"||dk==="minItems"||dk==="minProperties"){return subVal>=depVal}if(dk==="maxLength"||dk==="maximum"||dk==="exclusiveMaximum"||dk==="maxItems"||dk==="maxProperties"){return subVal<=depVal}}return(0,_utilsts.deepEqual)(depVal,subVal)})});if(!allDepPropsSatisfied)return sup;continue}return sup}return(0,_utilsts.omitKeys)(sup,["dependencies"])}function stripVacuousFalseProperties(merged,sub){if(typeof merged==="boolean"||typeof sub==="boolean")return merged;if(!(0,_utilsts.isPlainObj)(merged.properties))return merged;const mergedProps=merged.properties;const subProps=(0,_utilsts.isPlainObj)(sub.properties)?sub.properties:{};let strippedProps=null;for(const key of Object.keys(mergedProps)){if(mergedProps[key]===false&&!(0,_utilsts.hasOwn)(subProps,key)){if(strippedProps===null){strippedProps={...mergedProps}}delete strippedProps[key]}}if(strippedProps===null)return merged;const result={...merged,properties:strippedProps};if(Object.keys(strippedProps).length===0&&!(0,_utilsts.isPlainObj)(sub.properties)){delete result.properties}return result}function hasNestedBranching(schema){if(typeof schema==="boolean")return false;if((0,_utilsts.isPlainObj)(schema.properties)){const props=schema.properties;for(const key of Object.keys(props)){const prop=props[key];if(prop===undefined||typeof prop==="boolean")continue;if((0,_utilsts.hasOwn)(prop,"oneOf")||(0,_utilsts.hasOwn)(prop,"anyOf"))return true;if(hasNestedBranching(prop))return true}}if((0,_utilsts.isPlainObj)(schema.items)&&typeof schema.items!=="boolean"){const items=schema.items;if((0,_utilsts.hasOwn)(items,"oneOf")||(0,_utilsts.hasOwn)(items,"anyOf"))return true;if(hasNestedBranching(items))return true}return false}function isPropertySubsetOf(sub,sup,engine){const{branches:subBranches}=getBranchesTyped(sub);if(subBranches.length>1||subBranches[0]!==sub){for(const branch of subBranches){if(branch===undefined)continue;if(!isAtomicSubsetOf(branch,sup,engine))return false}return true}return isAtomicSubsetOf(sub,sup,engine)}function isArrayConstraintsSubset(sub,sup){if(sup.minItems!==undefined){if(sub.minItems===undefined||sub.minItems<sup.minItems){return false}}if(sup.maxItems!==undefined){if(sub.maxItems===undefined||sub.maxItems>sup.maxItems){return false}}if(sup.uniqueItems===true&&sub.uniqueItems!==true){return false}return true}function isObjectSubsetByProperties(sub,sup,engine){const subIsObj=sub.type==="object"||(0,_utilsts.isPlainObj)(sub.properties);const supIsObj=sup.type==="object"||(0,_utilsts.isPlainObj)(sup.properties);if(!subIsObj&&!supIsObj){if(sub.type==="array"&&sup.type==="array"&&(0,_utilsts.isPlainObj)(sub.items)&&(0,_utilsts.isPlainObj)(sup.items)){if(!isPropertySubsetOf(sub.items,sup.items,engine)){return false}return isArrayConstraintsSubset(sub,sup)}return false}if(!subIsObj||!supIsObj)return false;if((0,_utilsts.hasOwn)(sub,"type")&&(0,_utilsts.hasOwn)(sup,"type")&&sub.type!==sup.type){return false}const subProps=(0,_utilsts.isPlainObj)(sub.properties)?sub.properties:{};const supProps=(0,_utilsts.isPlainObj)(sup.properties)?sup.properties:{};const subRequired=Array.isArray(sub.required)?sub.required:[];const supRequired=Array.isArray(sup.required)?sup.required:[];for(const key of supRequired){if(!subRequired.includes(key))return false}if(sup.additionalProperties===false){for(const key of Object.keys(subProps)){if(!(0,_utilsts.hasOwn)(supProps,key))return false}}for(const key of Object.keys(supProps)){const supProp=supProps[key];const subProp=subProps[key];if(supProp===undefined||subProp===undefined)continue;if(!isPropertySubsetOf(subProp,supProp,engine)){return false}}if((0,_utilsts.isPlainObj)(sup.additionalProperties)&&typeof sup.additionalProperties!=="boolean"){const addPropSchema=sup.additionalProperties;for(const key of Object.keys(subProps)){if((0,_utilsts.hasOwn)(supProps,key))continue;const subProp=subProps[key];if(subProp===undefined)continue;if(!isPropertySubsetOf(subProp,addPropSchema,engine)){return false}}}if((0,_utilsts.isPlainObj)(sub.items)&&(0,_utilsts.isPlainObj)(sup.items)){if(!isPropertySubsetOf(sub.items,sup.items,engine)){return false}if(!isArrayConstraintsSubset(sub,sup)){return false}}return true}function tryNestedBranchingFallback(sub,sup,engine){if(typeof sub==="boolean"||typeof sup==="boolean")return null;if(!hasNestedBranching(sub)&&!hasNestedBranching(sup))return null;return isObjectSubsetByProperties(sub,sup,engine)}function resolveSupAllOf(sup,engine){if(typeof sup==="boolean")return sup;if(!Array.isArray(sup.allOf)||sup.allOf.length===0)return sup;const{allOf:_allOf,...sibling}=sup;const branches=sup.allOf;let resolved=Object.keys(sibling).length>0?sibling:null;for(const branch of branches){if(resolved===null){resolved=branch}else{resolved=engine.merge(resolved,branch);if(resolved===null){return sup}}}return resolved??sup}function isAtomicSubsetOf(sub,sup,engine){sup=resolveSupAllOf(sup,engine);const{branches:supBranches}=getBranchesTyped(sup);if(supBranches.length===1&&supBranches[0]===sup){const notResult=evaluateNot(sub,sup);if(notResult===false)return false;if(typeof sub!=="boolean"&&typeof sup!=="boolean"&&(0,_utilsts.hasOwn)(sub,"format")&&(0,_utilsts.hasOwn)(sup,"format")&&sub.format!==sup.format){const fmtResult=(0,_formatvalidatorts.isFormatSubset)(sub.format,sup.format);if(fmtResult!==true)return false}if(typeof sub!=="boolean"&&typeof sup!=="boolean"&&(0,_utilsts.hasOwn)(sub,"pattern")&&(0,_utilsts.hasOwn)(sup,"pattern")&&sub.pattern!==sup.pattern){const patResult=(0,_patternsubsetts.isPatternSubset)(sub.pattern,sup.pattern);if(patResult===false)return false}let effectiveSup=sup;if(typeof sup!=="boolean"){if(notResult===true){effectiveSup=stripNotFromSup(sub,sup,true);if(typeof effectiveSup!=="boolean"&&Object.keys(effectiveSup).length===0){return true}}else{effectiveSup=stripNotFromSup(sub,sup,false)}effectiveSup=stripPatternFromSup(sub,effectiveSup);effectiveSup=stripRedundantBoundsFromSup(sub,effectiveSup);effectiveSup=stripDependenciesFromSup(sub,effectiveSup)}const merged=engine.merge(sub,effectiveSup);if(merged===null){return tryNestedBranchingFallback(sub,effectiveSup,engine)??false}if((0,_utilsts.deepEqual)(merged,sub))return true;const strippedMerged=stripVacuousFalseProperties(merged,sub);if(strippedMerged!==merged&&(0,_utilsts.deepEqual)(strippedMerged,sub)){return true}const normalizedMerged=(0,_normalizerts.normalize)(strippedMerged);if((0,_utilsts.deepEqual)(normalizedMerged,sub)||engine.isEqual(normalizedMerged,sub)){return true}return tryNestedBranchingFallback(sub,effectiveSup,engine)??false}return supBranches.some(branch=>{const notResult=evaluateNot(sub,branch);if(notResult===false)return false;if(typeof sub!=="boolean"&&typeof branch!=="boolean"&&(0,_utilsts.hasOwn)(sub,"pattern")&&(0,_utilsts.hasOwn)(branch,"pattern")&&sub.pattern!==branch.pattern){const patResult=(0,_patternsubsetts.isPatternSubset)(sub.pattern,branch.pattern);if(patResult===false)return false}let effectiveBranch=branch;if(typeof branch!=="boolean"){if(notResult===true){effectiveBranch=stripNotFromSup(sub,branch,true);if(typeof effectiveBranch!=="boolean"&&Object.keys(effectiveBranch).length===0){return true}}else{effectiveBranch=stripNotFromSup(sub,branch,false)}effectiveBranch=stripPatternFromSup(sub,effectiveBranch);effectiveBranch=stripRedundantBoundsFromSup(sub,effectiveBranch);effectiveBranch=stripDependenciesFromSup(sub,effectiveBranch)}const merged=engine.merge(sub,effectiveBranch);if(merged===null){return tryNestedBranchingFallback(sub,effectiveBranch,engine)===true}if((0,_utilsts.deepEqual)(merged,sub))return true;const strippedBranch=stripVacuousFalseProperties(merged,sub);if(strippedBranch!==merged&&(0,_utilsts.deepEqual)(strippedBranch,sub)){return true}const normalizedBranch=(0,_normalizerts.normalize)(strippedBranch);if((0,_utilsts.deepEqual)(normalizedBranch,sub)||engine.isEqual(normalizedBranch,sub)){return true}return tryNestedBranchingFallback(sub,effectiveBranch,engine)===true})}function checkBranchedSub(subBranches,sup,engine,branchType="anyOf"){const allErrors=[];let allSubset=true;for(let i=0;i<subBranches.length;i++){const branch=subBranches[i];if(branch===undefined)continue;if(!isAtomicSubsetOf(branch,sup,engine)){allSubset=false;const branchErrors=(0,_semanticerrorsts.computeSemanticErrors)(branch,sup,"");allErrors.push(...branchErrors)}}return{isSubset:allSubset,merged:allSubset?branchType==="oneOf"?{oneOf:subBranches}:{anyOf:subBranches}:null,errors:allErrors}}function checkBranchedSup(sub,supBranches,engine,_branchType="anyOf"){for(const branch of supBranches){let effectiveBranch=branch;if(typeof sub!=="boolean"&&typeof branch!=="boolean"){const notResult=evaluateNot(sub,branch);if(notResult===false)continue;if(notResult===true){effectiveBranch=stripNotFromSup(sub,branch,true);if(typeof effectiveBranch!=="boolean"&&Object.keys(effectiveBranch).length===0){return{isSubset:true,merged:sub,errors:[]}}}else{effectiveBranch=stripNotFromSup(sub,branch,false)}effectiveBranch=stripPatternFromSup(sub,effectiveBranch);effectiveBranch=stripRedundantBoundsFromSup(sub,effectiveBranch);effectiveBranch=stripDependenciesFromSup(sub,effectiveBranch)}const merged=engine.merge(sub,effectiveBranch);if(merged!==null){if((0,_utilsts.deepEqual)(merged,sub)){return{isSubset:true,merged,errors:[]}}const normalizedMerged=(0,_normalizerts.normalize)(merged);if((0,_utilsts.deepEqual)(normalizedMerged,sub)||engine.isEqual(normalizedMerged,sub)){return{isSubset:true,merged,errors:[]}}}}const semanticErrors=(0,_semanticerrorsts.computeSemanticErrors)(sub,{anyOf:supBranches},"");return{isSubset:false,merged:null,errors:semanticErrors}}function checkAtomic(sub,sup,engine){sup=resolveSupAllOf(sup,engine);const notResult=typeof sub!=="boolean"&&typeof sup!=="boolean"?evaluateNot(sub,sup):null;if(notResult===false){const errors=(0,_semanticerrorsts.computeSemanticErrors)(sub,sup,"");return{isSubset:false,merged:null,errors}}let effectiveSup=sup;if(typeof sub!=="boolean"&&typeof sup!=="boolean"){if(notResult===true){effectiveSup=stripNotFromSup(sub,sup,true);if(typeof effectiveSup!=="boolean"&&Object.keys(effectiveSup).length===0){return{isSubset:true,merged:sub,errors:[]}}}else{effectiveSup=stripNotFromSup(sub,sup,false)}effectiveSup=stripPatternFromSup(sub,effectiveSup);effectiveSup=stripRedundantBoundsFromSup(sub,effectiveSup);effectiveSup=stripDependenciesFromSup(sub,effectiveSup)}try{const merged=engine.mergeOrThrow(sub,effectiveSup);if((0,_utilsts.deepEqual)(merged,sub)){return{isSubset:true,merged,errors:[]}}const strippedMerged=stripVacuousFalseProperties(merged,sub);if(strippedMerged!==merged&&(0,_utilsts.deepEqual)(strippedMerged,sub)){return{isSubset:true,merged:strippedMerged,errors:[]}}const normalizedMerged=(0,_normalizerts.normalize)(strippedMerged);if((0,_utilsts.deepEqual)(normalizedMerged,sub)||engine.isEqual(normalizedMerged,sub)){return{isSubset:true,merged:normalizedMerged,errors:[]}}if(tryNestedBranchingFallback(sub,effectiveSup,engine)===true){return{isSubset:true,merged:sub,errors:[]}}const errors=(0,_semanticerrorsts.computeSemanticErrors)(sub,sup,"");return{isSubset:false,merged:normalizedMerged,errors}}catch(_e){if(tryNestedBranchingFallback(sub,effectiveSup,engine)===true){return{isSubset:true,merged:sub,errors:[]}}const errors=(0,_semanticerrorsts.computeSemanticErrors)(sub,sup,"");return{isSubset:false,merged:null,errors}}}
|
|
2
2
|
//# sourceMappingURL=subset-checker.js.map
|