json-schema-compatibility-checker 1.1.6 → 1.1.7

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.
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:true});Object.defineProperty(exports,"validateSchemaConstraints",{enumerable:true,get:function(){return validateSchemaConstraints}});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({key:path||"$root",expected:`constraint: ${name}`,received:"unknown constraint (not registered)"});continue}try{const result=await validator(value,params);if(!result.valid){errors.push({key:path||"$root",expected:`constraint: ${name}`,received:result.message??"constraint validation failed"})}}catch(err){errors.push({key:path||"$root",expected:`constraint: ${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){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}
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 { 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\tkey: path || \"$root\",\n\t\t\t\texpected: `constraint: ${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\tkey: path || \"$root\",\n\t\t\t\t\texpected: `constraint: ${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\tkey: path || \"$root\",\n\t\t\t\texpected: `constraint: ${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","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":"oGAyFsBA,mEAAAA,oDAnFgC,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,WAAaA,WAAWC,IAAI,CAC1E,MAAMC,OACL,OAAOF,aAAe,SAAWG,UAAYH,WAAWE,MAAM,CAE/D,MAAME,UAAYP,QAAQ,CAACI,KAAK,CAEhC,GAAI,CAACG,UAAW,CACfL,OAAOM,IAAI,CAAC,CACXC,IAAKR,MAAQ,QACbS,SAAU,CAAC,YAAY,EAAEN,KAAK,CAAC,CAC/BO,SAAU,qCACX,GACA,QACD,CAEA,GAAI,CACH,MAAMC,OAAS,MAAML,UAAUR,MAAOM,QAC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AAOwC,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,WAAatD,UAAW,SAG5B,GAAI0B,MAAMC,OAAO,CAAC2B,UAAW,SAG7B,GAAI,OAAOA,WAAa,UAAW,SAInC1D,OAAOM,IAAI,IACN,MAAMZ,0BAA0BgE,SAAU1C,KAAMlB,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\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,WAAaA,WAAWC,IAAI,CAC1E,MAAMC,OACL,OAAOF,aAAe,SAAWG,UAAYH,WAAWE,MAAM,CAE/D,MAAME,UAAYP,QAAQ,CAACI,KAAK,CAEhC,GAAI,CAACG,UAAW,CACfL,OAAOM,IAAI,CAAC,CACXC,KAAMC,wBAAe,CAACC,gBAAgB,CACtCC,IAAKX,MAAQ,QACbY,SAAUT,KACVU,SAAU,qCACX,GACA,QACD,CAEA,GAAI,CACH,MAAMC,OAAS,MAAMR,UAAUR,MAAOM,QACtC,GAAI,CAACU,OAAOC,KAAK,CAAE,CAClBd,OAAOM,IAAI,CAAC,CACXC,KAAMC,wBAAe,CAACC,gBAAgB,CACtCC,IAAKX,MAAQ,QACbY,SAAUT,KACVU,SAAUC,OAAOE,OAAO,EAAI,8BAC7B,EACD,CACD,CAAE,MAAOC,IAAK,CACbhB,OAAOM,IAAI,CAAC,CACXC,KAAMC,wBAAe,CAACC,gBAAgB,CACtCC,IAAKX,MAAQ,QACbY,SAAUT,KACVU,SACCI,eAAeC,MAAQD,IAAID,OAAO,CAAG,6BACvC,EACD,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I,OAAOA,WAAa,UAAW,SAInC7D,OAAOM,IAAI,IACN,MAAMZ,0BAA0BmE,SAAU1C,KAAMrB,SAAUC,MAEhE,CACD,CAEA,OAAOC,MACR"}
@@ -4,3 +4,4 @@ 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
6
  export type { CheckerOptions, CheckRuntimeOptions, Constraint, Constraints, ConstraintValidationResult, ConstraintValidator, ConstraintValidatorRegistry, ResolvedConditionResult, ResolvedSubsetResult, SchemaError, SubsetResult, ValidateTargetOptions, ValidateTargets, } from "./types.js";
7
+ export { SchemaErrorType } from "./types.js";
package/dist/cjs/index.js CHANGED
@@ -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 _jsonschemacompatibilitycheckerts.JsonSchemaCompatibilityChecker},get MergeEngine(){return _mergeenginets.MergeEngine},get arePatternsEquivalent(){return _patternsubsetts.arePatternsEquivalent},get formatSchemaType(){return _semanticerrorsts.formatSchemaType},get isPatternSubset(){return _patternsubsetts.isPatternSubset},get isTrivialPattern(){return _patternsubsetts.isTrivialPattern},get resolveConditions(){return _conditionresolverts.resolveConditions}});const _conditionresolverts=require("./condition-resolver.js");const _jsonschemacompatibilitycheckerts=require("./json-schema-compatibility-checker.js");const _mergeenginets=require("./merge-engine.js");const _patternsubsetts=require("./pattern-subset.js");const _semanticerrorsts=require("./semantic-errors.js");
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 _jsonschemacompatibilitycheckerts.JsonSchemaCompatibilityChecker},get MergeEngine(){return _mergeenginets.MergeEngine},get SchemaErrorType(){return _typests.SchemaErrorType},get arePatternsEquivalent(){return _patternsubsetts.arePatternsEquivalent},get formatSchemaType(){return _semanticerrorsts.formatSchemaType},get isPatternSubset(){return _patternsubsetts.isPatternSubset},get isTrivialPattern(){return _patternsubsetts.isTrivialPattern},get resolveConditions(){return _conditionresolverts.resolveConditions}});const _conditionresolverts=require("./condition-resolver.js");const _jsonschemacompatibilitycheckerts=require("./json-schema-compatibility-checker.js");const _mergeenginets=require("./merge-engine.js");const _patternsubsetts=require("./pattern-subset.js");const _semanticerrorsts=require("./semantic-errors.js");const _typests=require("./types.js");
2
2
  //# sourceMappingURL=index.js.map
@@ -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\";\n"],"names":["JsonSchemaCompatibilityChecker","MergeEngine","arePatternsEquivalent","formatSchemaType","isPatternSubset","isTrivialPattern","resolveConditions"],"mappings":"mPACSA,wCAAAA,gEAA8B,MAC9BC,qBAAAA,0BAAW,MAEnBC,+BAAAA,sCAAqB,MAIbC,0BAAAA,kCAAgB,MAHxBC,yBAAAA,gCAAe,MACfC,0BAAAA,iCAAgB,MANRC,2BAAAA,sCAAiB,uCAAQ,2EACa,uEACnB,oDAKrB,uDAC0B"}
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,MAsBXC,yBAAAA,wBAAe,MApBvBC,+BAAAA,sCAAqB,MAIbC,0BAAAA,kCAAgB,MAHxBC,yBAAAA,gCAAe,MACfC,0BAAAA,iCAAgB,MANRC,2BAAAA,sCAAiB,uCAAQ,2EACa,uEACnB,oDAKrB,uDAC0B,+CAgBD"}
@@ -6,8 +6,9 @@ import { normalize } from "./normalizer.js";
6
6
  import { arePatternsEquivalent, isPatternSubset, isTrivialPattern } from "./pattern-subset.js";
7
7
  import type { BranchResult, BranchType } from "./subset-checker.js";
8
8
  import type { CheckerOptions, CheckRuntimeOptions, ResolvedConditionResult, ResolvedSubsetResult, SchemaError, SubsetResult, ValidateTargets } from "./types.js";
9
+ import { SchemaErrorType } from "./types.js";
9
10
  export type { SchemaError, SubsetResult, ResolvedConditionResult, ResolvedSubsetResult, CheckRuntimeOptions, ValidateTargets, BranchType, BranchResult, };
10
- export { normalize, resolveConditions, formatResult, MergeEngine, isPatternSubset, arePatternsEquivalent, isTrivialPattern, };
11
+ export { SchemaErrorType, normalize, resolveConditions, formatResult, MergeEngine, isPatternSubset, arePatternsEquivalent, isTrivialPattern, };
11
12
  export declare class JsonSchemaCompatibilityChecker {
12
13
  private readonly constraintValidators;
13
14
  private readonly engine;
@@ -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 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 _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{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??{}}}
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 { 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\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","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":"mPAkFaA,wCAAAA,oCA3BZC,qBAAAA,0BAAW,MAEXC,+BAAAA,sCAAqB,MAHrBC,sBAAAA,yBAAY,MAEZC,yBAAAA,gCAAe,MAEfC,0BAAAA,iCAAgB,MANhBC,mBAAAA,uBAAS,MACTC,2BAAAA,sCAAiB,uCApDgB,gEACQ,4DACL,kDACR,+CACD,iDACF,kDAKnB,yDAKA,yDAQA,8CAW+B,+CACC,6MA8ChC,MAAMP,+BAkBZQ,SAASC,GAA0B,CAAEC,GAA0B,CAAW,CAIzE,GAAID,MAAQC,IAAK,O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AAAA,iCAAgB,EAAC5D,YAAaF,KAAM,IAAI,CAACQ,MAAM,CAAEmD,cACzD,CAGA,GAAIC,YAAYxD,MAAM,CAAG,GAAKwD,WAAW,CAAC,EAAE,GAAK5D,KAAM,CACtD,MAAO+D,GAAAA,iCAAgB,EAAChE,KAAM6D,YAAa,IAAI,CAACpD,MAAM,CAAEqD,cACzD,CAGA,MAAOG,GAAAA,4BAAW,EAACjE,KAAMC,KAAM,IAAI,CAACQ,MAAM,CAC3C,CAuBA,OAAOyD,YAAmB,CACzBC,GAAAA,2CAAuB,GACxB,CA1aA,YAAYxD,OAAwB,CAAE,CAHtC,sBAAiB0C,uBAAjB,KAAA,GACA,sBAAiB5C,SAAjB,KAAA,EAGC,CAAA,IAAI,CAACA,MAAM,CAAG,IAAIpB,0BAAW,AAC7B,CAAA,IAAI,CAACgE,oBAAoB,CAAG1C,SAASyD,aAAe,CAAC,CACtD,CAwaD"}
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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CACtD,MAAO+D,GAAAA,iCAAgB,EAAC5D,YAAaF,KAAM,IAAI,CAACQ,MAAM,CAAEmD,cACzD,CAGA,GAAIC,YAAYxD,MAAM,CAAG,GAAKwD,WAAW,CAAC,EAAE,GAAK5D,KAAM,CACtD,MAAO+D,GAAAA,iCAAgB,EAAChE,KAAM6D,YAAa,IAAI,CAACpD,MAAM,CAAEqD,cACzD,CAGA,MAAOG,GAAAA,4BAAW,EAACjE,KAAMC,KAAM,IAAI,CAACQ,MAAM,CAC3C,CAuBA,OAAOyD,YAAmB,CACzBC,GAAAA,2CAAuB,GACxB,CA1aA,YAAYxD,OAAwB,CAAE,CAHtC,sBAAiB0C,uBAAjB,KAAA,GACA,sBAAiB5C,SAAjB,KAAA,EAGC,CAAA,IAAI,CAACA,MAAM,CAAG,IAAIrB,0BAAW,AAC7B,CAAA,IAAI,CAACiE,oBAAoB,CAAG1C,SAASyD,aAAe,CAAC,CACtD,CAwaD"}
@@ -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 clearAllValidatorCaches(){return clearAllValidatorCaches},get getPartialRuntimeValidationErrors(){return getPartialRuntimeValidationErrors},get getRuntimeValidationErrors(){return getRuntimeValidationErrors},get isDataValidForSchema(){return isDataValidForSchema},get stripRequiredRecursive(){return stripRequiredRecursive}});const _ajv=/*#__PURE__*/_interop_require_default(require("ajv"));const _ajvformats=/*#__PURE__*/_interop_require_default(require("ajv-formats"));const _utilsts=require("./utils.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}function _interop_require_default(obj){return obj&&obj.__esModule?obj:{default:obj}}const ajv=new _ajv.default({allErrors:true,strict:false,validateFormats:true,allowUnionTypes:true,messages:true});(0,_ajvformats.default)(ajv);const validatorCache=new WeakMap;class LRUCache{get(key){const value=this.cache.get(key);if(value===undefined)return undefined;this.cache.delete(key);this.cache.set(key,value);return value}set(key,value){if(this.cache.has(key)){this.cache.delete(key)}else if(this.cache.size>=this.max){const firstKey=this.cache.keys().next().value;if(firstKey!==undefined){this.cache.delete(firstKey)}}this.cache.set(key,value)}clear(){this.cache.clear()}constructor(maxSize){_define_property(this,"max",void 0);_define_property(this,"cache",new Map);this.max=maxSize}}const validatorStringCache=new LRUCache(500);function isObjectLike(value){return typeof value==="object"&&value!==null}function stableStringify(value){if(value===null||typeof value!=="object"){return JSON.stringify(value)}if(Array.isArray(value)){return`[${value.map(entry=>stableStringify(entry)).join(",")}]`}const entries=Object.entries(value).sort(([a],[b])=>a.localeCompare(b));return`{${entries.map(([key,entryValue])=>`${JSON.stringify(key)}:${stableStringify(entryValue)}`).join(",")}}`}function getSchemaTypeName(schema){if(schema.type===undefined)return"value";if(Array.isArray(schema.type)){return schema.type.join(" | ")}return schema.type}function stringifyValue(value){if(value===undefined)return"undefined";if(typeof value==="string")return value;return JSON.stringify(value)}function normalizeInstancePath(instancePath){if(instancePath==="")return"$root";const parts=instancePath.split("/").filter(Boolean);if(parts.length===0)return"$root";let path="";for(const rawPart of parts){const part=rawPart.replace(/~1/g,"/").replace(/~0/g,"~");const isArrayIndex=/^\d+$/.test(part);if(isArrayIndex){path+="[]";continue}path=path.length===0?part:`${path}.${part}`}return path||"$root"}function formatAllowedValues(values){if(values.length===0)return"no allowed values";const rendered=values.map(value=>typeof value==="string"?value:JSON.stringify(value));if(rendered.length===1)return rendered[0]??"";if(rendered.length===2)return`${rendered[0]} or ${rendered[1]}`;return`${rendered.slice(0,-1).join(", ")}, or ${rendered[rendered.length-1]}`}function formatExpected(error,schema){switch(error.keyword){case"type":{const expectedType=typeof error.params==="object"&&error.params!==null&&"type"in error.params?String(error.params.type):getSchemaTypeName(schema);return expectedType}case"enum":{return Array.isArray(schema.enum)?formatAllowedValues(schema.enum):"allowed enum value"}case"const":{return stringifyValue(schema.const)}case"required":{const missingProperty=typeof error.params==="object"&&error.params!==null&&"missingProperty"in error.params?String(error.params.missingProperty):"unknown";const targetSchema=schema.properties?.[missingProperty]&&typeof schema.properties[missingProperty]!=="boolean"?schema.properties[missingProperty]:undefined;if(targetSchema?.type!==undefined){const prefix=normalizeInstancePath(error.instancePath);const key=prefix==="$root"?missingProperty:`${prefix}.${missingProperty}`;return`${key}: ${getSchemaTypeName(targetSchema)}`}return`required property: ${missingProperty}`}case"minimum":return`>= ${String(schema.minimum)}`;case"maximum":return`<= ${String(schema.maximum)}`;case"exclusiveMinimum":return`> ${String(schema.exclusiveMinimum)}`;case"exclusiveMaximum":return`< ${String(schema.exclusiveMaximum)}`;case"multipleOf":return`multipleOf ${String(schema.multipleOf)}`;case"minLength":return`minLength: ${String(schema.minLength)}`;case"maxLength":return`maxLength: ${String(schema.maxLength)}`;case"pattern":return`pattern: ${String(schema.pattern)}`;case"format":return`format: ${String(schema.format)}`;case"minItems":return`minItems: ${String(schema.minItems)}`;case"maxItems":return`maxItems: ${String(schema.maxItems)}`;case"uniqueItems":return"uniqueItems: true";case"minProperties":return`minProperties: ${String(schema.minProperties)}`;case"maxProperties":return`maxProperties: ${String(schema.maxProperties)}`;case"additionalProperties":return"not allowed (additionalProperties: false)";case"propertyNames":return"valid property names";case"contains":return"contains at least one matching item";case"allOf":return"allOf constraints";case"anyOf":return"anyOf constraints";case"oneOf":return"oneOf constraints";case"not":return"not matching forbidden schema";default:return error.message??error.keyword}}function buildSchemaError(error,schema,data){const baseKey=normalizeInstancePath(error.instancePath);if(error.keyword==="required"){const missingProperty=typeof error.params==="object"&&error.params!==null&&"missingProperty"in error.params?String(error.params.missingProperty):"unknown";return{key:baseKey==="$root"?missingProperty:`${baseKey}.${missingProperty}`,expected:formatExpected(error,schema),received:"undefined"}}if(error.keyword==="additionalProperties"){const additionalProperty=typeof error.params==="object"&&error.params!==null&&"additionalProperty"in error.params?String(error.params.additionalProperty):"unknown";return{key:baseKey==="$root"?additionalProperty:`${baseKey}.${additionalProperty}`,expected:formatExpected(error,schema),received:"present"}}return{key:baseKey,expected:formatExpected(error,schema),received:stringifyValue(data)}}function compileValidator(schema){if(isObjectLike(schema)){const cached=validatorCache.get(schema);if(cached!==undefined)return cached}const serialized=stableStringify(schema);const cachedByString=validatorStringCache.get(serialized);if(cachedByString!==undefined){if(isObjectLike(schema)){validatorCache.set(schema,cachedByString)}return cachedByString}const validate=ajv.compile(schema);if(isObjectLike(schema)){validatorCache.set(schema,validate)}validatorStringCache.set(serialized,validate);return validate}function isDataValidForSchema(schema,data){if(typeof schema==="boolean"){return schema}const validate=compileValidator(schema);return validate(data)===true}function getRuntimeValidationErrors(schema,data){if(typeof schema==="boolean"){if(schema)return[];return[{key:"$root",expected:"never",received:stringifyValue(data)}]}const validate=compileValidator(schema);const isValid=validate(data);if(isValid===true||validate.errors===null||validate.errors===undefined){return[]}return validate.errors.map(error=>buildSchemaError(error,schema,data))}function stripRequiredRecursive(schema){if(!(0,_utilsts.isPlainObj)(schema))return schema;const result={...schema};delete result.required;delete result.additionalProperties;if((0,_utilsts.isPlainObj)(result.properties)){const props={};for(const[key,value]of Object.entries(result.properties)){props[key]=typeof value==="object"&&value!==null?stripRequiredRecursive(value):value}result.properties=props}if((0,_utilsts.isPlainObj)(result.items)&&!Array.isArray(result.items)){result.items=stripRequiredRecursive(result.items)}if(Array.isArray(result.items)){result.items=result.items.map(item=>typeof item==="object"&&item!==null?stripRequiredRecursive(item):item)}for(const keyword of["oneOf","anyOf","allOf"]){if(Array.isArray(result[keyword])){result[keyword]=result[keyword].map(branch=>typeof branch==="object"&&branch!==null?stripRequiredRecursive(branch):branch)}}if((0,_utilsts.isPlainObj)(result.then)){result.then=stripRequiredRecursive(result.then)}if((0,_utilsts.isPlainObj)(result.else)){result.else=stripRequiredRecursive(result.else)}return result}function getPartialRuntimeValidationErrors(schema,data){if(typeof schema==="boolean"){return getRuntimeValidationErrors(schema,data)}const stripped=stripRequiredRecursive(schema);return getRuntimeValidationErrors(stripped,data)}function clearAllValidatorCaches(){validatorStringCache.clear();ajv.removeSchema()}
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 clearAllValidatorCaches(){return clearAllValidatorCaches},get getPartialRuntimeValidationErrors(){return getPartialRuntimeValidationErrors},get getRuntimeValidationErrors(){return getRuntimeValidationErrors},get isDataValidForSchema(){return isDataValidForSchema},get stripRequiredRecursive(){return stripRequiredRecursive}});const _ajv=/*#__PURE__*/_interop_require_default(require("ajv"));const _ajvformats=/*#__PURE__*/_interop_require_default(require("ajv-formats"));const _typests=require("./types.js");const _utilsts=require("./utils.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}function _interop_require_default(obj){return obj&&obj.__esModule?obj:{default:obj}}const ajv=new _ajv.default({allErrors:true,strict:false,validateFormats:true,allowUnionTypes:true,messages:true});(0,_ajvformats.default)(ajv);const validatorCache=new WeakMap;class LRUCache{get(key){const value=this.cache.get(key);if(value===undefined)return undefined;this.cache.delete(key);this.cache.set(key,value);return value}set(key,value){if(this.cache.has(key)){this.cache.delete(key)}else if(this.cache.size>=this.max){const firstKey=this.cache.keys().next().value;if(firstKey!==undefined){this.cache.delete(firstKey)}}this.cache.set(key,value)}clear(){this.cache.clear()}constructor(maxSize){_define_property(this,"max",void 0);_define_property(this,"cache",new Map);this.max=maxSize}}const validatorStringCache=new LRUCache(500);function isObjectLike(value){return typeof value==="object"&&value!==null}function stableStringify(value){if(value===null||typeof value!=="object"){return JSON.stringify(value)}if(Array.isArray(value)){return`[${value.map(entry=>stableStringify(entry)).join(",")}]`}const entries=Object.entries(value).sort(([a],[b])=>a.localeCompare(b));return`{${entries.map(([key,entryValue])=>`${JSON.stringify(key)}:${stableStringify(entryValue)}`).join(",")}}`}function getSchemaTypeName(schema){if(schema.type===undefined)return"value";if(Array.isArray(schema.type)){return schema.type.join(" | ")}return schema.type}function stringifyValue(value){if(value===undefined)return"undefined";if(typeof value==="string")return value;return JSON.stringify(value)}function normalizeInstancePath(instancePath){if(instancePath==="")return"$root";const parts=instancePath.split("/").filter(Boolean);if(parts.length===0)return"$root";let path="";for(const rawPart of parts){const part=rawPart.replace(/~1/g,"/").replace(/~0/g,"~");const isArrayIndex=/^\d+$/.test(part);if(isArrayIndex){path+="[]";continue}path=path.length===0?part:`${path}.${part}`}return path||"$root"}function formatAllowedValues(values){if(values.length===0)return"no allowed values";const rendered=values.map(value=>typeof value==="string"?value:JSON.stringify(value));if(rendered.length===1)return rendered[0]??"";if(rendered.length===2)return`${rendered[0]} or ${rendered[1]}`;return`${rendered.slice(0,-1).join(", ")}, or ${rendered[rendered.length-1]}`}function formatExpected(error,schema){switch(error.keyword){case"type":{const expectedType=typeof error.params==="object"&&error.params!==null&&"type"in error.params?String(error.params.type):getSchemaTypeName(schema);return expectedType}case"enum":{return Array.isArray(schema.enum)?formatAllowedValues(schema.enum):"allowed enum value"}case"const":{return stringifyValue(schema.const)}case"required":{const missingProperty=typeof error.params==="object"&&error.params!==null&&"missingProperty"in error.params?String(error.params.missingProperty):"unknown";const targetSchema=schema.properties?.[missingProperty]&&typeof schema.properties[missingProperty]!=="boolean"?schema.properties[missingProperty]:undefined;if(targetSchema?.type!==undefined){const prefix=normalizeInstancePath(error.instancePath);const key=prefix==="$root"?missingProperty:`${prefix}.${missingProperty}`;return`${key}: ${getSchemaTypeName(targetSchema)}`}return`required property: ${missingProperty}`}case"minimum":return`>= ${String(schema.minimum)}`;case"maximum":return`<= ${String(schema.maximum)}`;case"exclusiveMinimum":return`> ${String(schema.exclusiveMinimum)}`;case"exclusiveMaximum":return`< ${String(schema.exclusiveMaximum)}`;case"multipleOf":return`multipleOf ${String(schema.multipleOf)}`;case"minLength":return`minLength: ${String(schema.minLength)}`;case"maxLength":return`maxLength: ${String(schema.maxLength)}`;case"pattern":return`pattern: ${String(schema.pattern)}`;case"format":return`format: ${String(schema.format)}`;case"minItems":return`minItems: ${String(schema.minItems)}`;case"maxItems":return`maxItems: ${String(schema.maxItems)}`;case"uniqueItems":return"uniqueItems: true";case"minProperties":return`minProperties: ${String(schema.minProperties)}`;case"maxProperties":return`maxProperties: ${String(schema.maxProperties)}`;case"additionalProperties":return"not allowed (additionalProperties: false)";case"propertyNames":return"valid property names";case"contains":return"contains at least one matching item";case"allOf":return"allOf constraints";case"anyOf":return"anyOf constraints";case"oneOf":return"oneOf constraints";case"not":return"not matching forbidden schema";default:return error.message??error.keyword}}function buildSchemaError(error,schema,data){const type=_typests.SchemaErrorType.RuntimeValidation;const baseKey=normalizeInstancePath(error.instancePath);if(error.keyword==="required"){const missingProperty=typeof error.params==="object"&&error.params!==null&&"missingProperty"in error.params?String(error.params.missingProperty):"unknown";return{type,key:baseKey==="$root"?missingProperty:`${baseKey}.${missingProperty}`,expected:formatExpected(error,schema),received:"undefined"}}if(error.keyword==="additionalProperties"){const additionalProperty=typeof error.params==="object"&&error.params!==null&&"additionalProperty"in error.params?String(error.params.additionalProperty):"unknown";return{type,key:baseKey==="$root"?additionalProperty:`${baseKey}.${additionalProperty}`,expected:formatExpected(error,schema),received:"present"}}return{type,key:baseKey,expected:formatExpected(error,schema),received:stringifyValue(data)}}function compileValidator(schema){if(isObjectLike(schema)){const cached=validatorCache.get(schema);if(cached!==undefined)return cached}const serialized=stableStringify(schema);const cachedByString=validatorStringCache.get(serialized);if(cachedByString!==undefined){if(isObjectLike(schema)){validatorCache.set(schema,cachedByString)}return cachedByString}const validate=ajv.compile(schema);if(isObjectLike(schema)){validatorCache.set(schema,validate)}validatorStringCache.set(serialized,validate);return validate}function isDataValidForSchema(schema,data){if(typeof schema==="boolean"){return schema}const validate=compileValidator(schema);return validate(data)===true}function getRuntimeValidationErrors(schema,data){if(typeof schema==="boolean"){if(schema)return[];return[{type:_typests.SchemaErrorType.RuntimeValidation,key:"$root",expected:"never",received:stringifyValue(data)}]}const validate=compileValidator(schema);const isValid=validate(data);if(isValid===true||validate.errors===null||validate.errors===undefined){return[]}return validate.errors.map(error=>buildSchemaError(error,schema,data))}function stripRequiredRecursive(schema){if(!(0,_utilsts.isPlainObj)(schema))return schema;const result={...schema};delete result.required;delete result.additionalProperties;if((0,_utilsts.isPlainObj)(result.properties)){const props={};for(const[key,value]of Object.entries(result.properties)){props[key]=typeof value==="object"&&value!==null?stripRequiredRecursive(value):value}result.properties=props}if((0,_utilsts.isPlainObj)(result.items)&&!Array.isArray(result.items)){result.items=stripRequiredRecursive(result.items)}if(Array.isArray(result.items)){result.items=result.items.map(item=>typeof item==="object"&&item!==null?stripRequiredRecursive(item):item)}for(const keyword of["oneOf","anyOf","allOf"]){if(Array.isArray(result[keyword])){result[keyword]=result[keyword].map(branch=>typeof branch==="object"&&branch!==null?stripRequiredRecursive(branch):branch)}}if((0,_utilsts.isPlainObj)(result.then)){result.then=stripRequiredRecursive(result.then)}if((0,_utilsts.isPlainObj)(result.else)){result.else=stripRequiredRecursive(result.else)}return result}function getPartialRuntimeValidationErrors(schema,data){if(typeof schema==="boolean"){return getRuntimeValidationErrors(schema,data)}const stripped=stripRequiredRecursive(schema);return getRuntimeValidationErrors(stripped,data)}function clearAllValidatorCaches(){validatorStringCache.clear();ajv.removeSchema()}
2
2
  //# sourceMappingURL=runtime-validator.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/runtime-validator.ts"],"sourcesContent":["import Ajv, { type ErrorObject, type ValidateFunction } from \"ajv\";\nimport addFormats from \"ajv-formats\";\nimport type { JSONSchema7, JSONSchema7Definition } from \"json-schema\";\nimport type { SchemaError } from \"./types.ts\";\nimport { isPlainObj } from \"./utils.ts\";\n\n/**\n * ─── Runtime Validator ────────────────────────────────────────────────────────\n *\n * Centralizes runtime validation of JSON Schema Draft-07 schemas using AJV.\n *\n * Goals:\n * - Validate concrete runtime data against resolved schemas\n * - Reuse the same runtime engine for `check(..., { data })`\n * - Reuse the same runtime engine for `if/then/else` condition evaluation\n * - Keep the static subset-checking pipeline unchanged when no runtime data is provided\n *\n * Architecture — Singleton AJV instance:\n * The `ajv` constant below is a module-level singleton shared by every\n * `JsonSchemaCompatibilityChecker` instance in the same process. This is\n * intentional:\n * - Compiled validators are reused across checker instances, avoiding\n * redundant schema compilation and reducing memory usage.\n * - The WeakMap and LRU caches for `ValidateFunction` objects are valid\n * only for a single AJV instance; per-instance AJV would break caching.\n * - `ajv-formats` is registered once at module load; all standard Draft-07\n * formats are available globally.\n * - In worker-thread environments, each worker loads its own module scope\n * and gets its own AJV instance — no cross-worker sharing occurs.\n * - Custom AJV configuration or format registration is not supported\n * per-checker-instance. If needed in the future, the singleton could be\n * replaced with a factory, but this is intentionally deferred (YAGNI).\n *\n * Notes:\n * - AJV is configured in non-strict mode because this library intentionally\n * supports partially-specified / pragmatic schemas and some unsupported\n * keywords may appear in user input.\n * - Standard JSON Schema formats are enabled through `ajv-formats` so runtime\n * validation can influence condition resolution and `check(..., { data })`\n * consistently for supported formats.\n * - Unknown formats are still ignored in practice by the non-strict runtime\n * configuration instead of crashing the whole check pipeline.\n */\n\n// Singleton AJV instance — shared across all checker instances (see module JSDoc above)\nconst ajv = new Ajv({\n\tallErrors: true,\n\tstrict: false,\n\tvalidateFormats: true,\n\tallowUnionTypes: true,\n\tmessages: true,\n});\n\naddFormats(ajv);\n\n/**\n * Cache compiled validators by schema object reference.\n *\n * This mirrors the codebase's preference for WeakMap-based caching and avoids\n * recompiling validators for the same resolved schema instances.\n */\nconst validatorCache = new WeakMap<object, ValidateFunction>();\n\n/**\n * Minimal LRU cache using Map insertion-order guarantees for O(1) eviction.\n *\n * On `get`, the entry is moved to the end (most recently used).\n * On `set`, if the cache is full, the first entry (least recently used) is evicted.\n */\nclass LRUCache<K, V> {\n\tprivate readonly max: number;\n\tprivate readonly cache = new Map<K, V>();\n\n\tconstructor(maxSize: number) {\n\t\tthis.max = maxSize;\n\t}\n\n\tget(key: K): V | undefined {\n\t\tconst value = this.cache.get(key);\n\t\tif (value === undefined) return undefined;\n\n\t\t// Move to end (most recently used)\n\t\tthis.cache.delete(key);\n\t\tthis.cache.set(key, value);\n\t\treturn value;\n\t}\n\n\tset(key: K, value: V): void {\n\t\tif (this.cache.has(key)) {\n\t\t\tthis.cache.delete(key);\n\t\t} else if (this.cache.size >= this.max) {\n\t\t\t// Evict least recently used (first key in iteration order)\n\t\t\tconst firstKey = this.cache.keys().next().value;\n\t\t\tif (firstKey !== undefined) {\n\t\t\t\tthis.cache.delete(firstKey);\n\t\t\t}\n\t\t}\n\t\tthis.cache.set(key, value);\n\t}\n\n\tclear(): void {\n\t\tthis.cache.clear();\n\t}\n}\n\n/**\n * LRU cache for compiled validators keyed by deterministic schema serialization.\n *\n * This is a fallback for schemas that are not stable object references (e.g.\n * freshly constructed schemas that are structurally identical to previously\n * seen ones). Bounded to 500 entries to prevent unbounded memory growth in\n * long-running processes. The WeakMap-based `validatorCache` remains the\n * primary cache for the hot path.\n */\nconst validatorStringCache = new LRUCache<string, ValidateFunction>(500);\n\nfunction isObjectLike(value: unknown): value is object {\n\treturn typeof value === \"object\" && value !== null;\n}\n\nfunction stableStringify(value: unknown): string {\n\tif (value === null || typeof value !== \"object\") {\n\t\treturn JSON.stringify(value);\n\t}\n\n\tif (Array.isArray(value)) {\n\t\treturn `[${value.map((entry) => stableStringify(entry)).join(\",\")}]`;\n\t}\n\n\tconst entries = Object.entries(value as Record<string, unknown>).sort(\n\t\t([a], [b]) => a.localeCompare(b),\n\t);\n\n\treturn `{${entries\n\t\t.map(\n\t\t\t([key, entryValue]) =>\n\t\t\t\t`${JSON.stringify(key)}:${stableStringify(entryValue)}`,\n\t\t)\n\t\t.join(\",\")}}`;\n}\n\nfunction getSchemaTypeName(schema: JSONSchema7): string {\n\tif (schema.type === undefined) return \"value\";\n\n\tif (Array.isArray(schema.type)) {\n\t\treturn schema.type.join(\" | \");\n\t}\n\n\treturn schema.type;\n}\n\nfunction stringifyValue(value: unknown): string {\n\tif (value === undefined) return \"undefined\";\n\tif (typeof value === \"string\") return value;\n\treturn JSON.stringify(value);\n}\n\nfunction normalizeInstancePath(instancePath: string): string {\n\tif (instancePath === \"\") return \"$root\";\n\n\tconst parts = instancePath.split(\"/\").filter(Boolean);\n\tif (parts.length === 0) return \"$root\";\n\n\tlet path = \"\";\n\n\tfor (const rawPart of parts) {\n\t\tconst part = rawPart.replace(/~1/g, \"/\").replace(/~0/g, \"~\");\n\t\tconst isArrayIndex = /^\\d+$/.test(part);\n\n\t\tif (isArrayIndex) {\n\t\t\tpath += \"[]\";\n\t\t\tcontinue;\n\t\t}\n\n\t\tpath = path.length === 0 ? part : `${path}.${part}`;\n\t}\n\n\treturn path || \"$root\";\n}\n\nfunction formatAllowedValues(values: unknown[]): string {\n\tif (values.length === 0) return \"no allowed values\";\n\n\tconst rendered = values.map((value) =>\n\t\ttypeof value === \"string\" ? value : JSON.stringify(value),\n\t);\n\n\tif (rendered.length === 1) return rendered[0] ?? \"\";\n\tif (rendered.length === 2) return `${rendered[0]} or ${rendered[1]}`;\n\n\treturn `${rendered.slice(0, -1).join(\", \")}, or ${rendered[rendered.length - 1]}`;\n}\n\nfunction formatExpected(error: ErrorObject, schema: JSONSchema7): string {\n\tswitch (error.keyword) {\n\t\tcase \"type\": {\n\t\t\tconst expectedType =\n\t\t\t\ttypeof error.params === \"object\" &&\n\t\t\t\terror.params !== null &&\n\t\t\t\t\"type\" in error.params\n\t\t\t\t\t? String(error.params.type)\n\t\t\t\t\t: getSchemaTypeName(schema);\n\n\t\t\treturn expectedType;\n\t\t}\n\n\t\tcase \"enum\": {\n\t\t\treturn Array.isArray(schema.enum)\n\t\t\t\t? formatAllowedValues(schema.enum)\n\t\t\t\t: \"allowed enum value\";\n\t\t}\n\n\t\tcase \"const\": {\n\t\t\treturn stringifyValue(schema.const);\n\t\t}\n\n\t\tcase \"required\": {\n\t\t\tconst missingProperty =\n\t\t\t\ttypeof error.params === \"object\" &&\n\t\t\t\terror.params !== null &&\n\t\t\t\t\"missingProperty\" in error.params\n\t\t\t\t\t? String(error.params.missingProperty)\n\t\t\t\t\t: \"unknown\";\n\n\t\t\tconst targetSchema =\n\t\t\t\tschema.properties?.[missingProperty] &&\n\t\t\t\ttypeof schema.properties[missingProperty] !== \"boolean\"\n\t\t\t\t\t? (schema.properties[missingProperty] as JSONSchema7)\n\t\t\t\t\t: undefined;\n\n\t\t\tif (targetSchema?.type !== undefined) {\n\t\t\t\tconst prefix = normalizeInstancePath(error.instancePath);\n\t\t\t\tconst key =\n\t\t\t\t\tprefix === \"$root\" ? missingProperty : `${prefix}.${missingProperty}`;\n\t\t\t\treturn `${key}: ${getSchemaTypeName(targetSchema)}`;\n\t\t\t}\n\n\t\t\treturn `required property: ${missingProperty}`;\n\t\t}\n\n\t\tcase \"minimum\":\n\t\t\treturn `>= ${String((schema as JSONSchema7).minimum)}`;\n\n\t\tcase \"maximum\":\n\t\t\treturn `<= ${String((schema as JSONSchema7).maximum)}`;\n\n\t\tcase \"exclusiveMinimum\":\n\t\t\treturn `> ${String((schema as JSONSchema7).exclusiveMinimum)}`;\n\n\t\tcase \"exclusiveMaximum\":\n\t\t\treturn `< ${String((schema as JSONSchema7).exclusiveMaximum)}`;\n\n\t\tcase \"multipleOf\":\n\t\t\treturn `multipleOf ${String((schema as JSONSchema7).multipleOf)}`;\n\n\t\tcase \"minLength\":\n\t\t\treturn `minLength: ${String((schema as JSONSchema7).minLength)}`;\n\n\t\tcase \"maxLength\":\n\t\t\treturn `maxLength: ${String((schema as JSONSchema7).maxLength)}`;\n\n\t\tcase \"pattern\":\n\t\t\treturn `pattern: ${String((schema as JSONSchema7).pattern)}`;\n\n\t\tcase \"format\":\n\t\t\treturn `format: ${String((schema as JSONSchema7).format)}`;\n\n\t\tcase \"minItems\":\n\t\t\treturn `minItems: ${String((schema as JSONSchema7).minItems)}`;\n\n\t\tcase \"maxItems\":\n\t\t\treturn `maxItems: ${String((schema as JSONSchema7).maxItems)}`;\n\n\t\tcase \"uniqueItems\":\n\t\t\treturn \"uniqueItems: true\";\n\n\t\tcase \"minProperties\":\n\t\t\treturn `minProperties: ${String((schema as JSONSchema7).minProperties)}`;\n\n\t\tcase \"maxProperties\":\n\t\t\treturn `maxProperties: ${String((schema as JSONSchema7).maxProperties)}`;\n\n\t\tcase \"additionalProperties\":\n\t\t\treturn \"not allowed (additionalProperties: false)\";\n\n\t\tcase \"propertyNames\":\n\t\t\treturn \"valid property names\";\n\n\t\tcase \"contains\":\n\t\t\treturn \"contains at least one matching item\";\n\n\t\tcase \"allOf\":\n\t\t\treturn \"allOf constraints\";\n\n\t\tcase \"anyOf\":\n\t\t\treturn \"anyOf constraints\";\n\n\t\tcase \"oneOf\":\n\t\t\treturn \"oneOf constraints\";\n\n\t\tcase \"not\":\n\t\t\treturn \"not matching forbidden schema\";\n\n\t\tdefault:\n\t\t\treturn error.message ?? error.keyword;\n\t}\n}\n\nfunction buildSchemaError(\n\terror: ErrorObject,\n\tschema: JSONSchema7,\n\tdata: unknown,\n): SchemaError {\n\tconst baseKey = normalizeInstancePath(error.instancePath);\n\n\tif (error.keyword === \"required\") {\n\t\tconst missingProperty =\n\t\t\ttypeof error.params === \"object\" &&\n\t\t\terror.params !== null &&\n\t\t\t\"missingProperty\" in error.params\n\t\t\t\t? String(error.params.missingProperty)\n\t\t\t\t: \"unknown\";\n\n\t\treturn {\n\t\t\tkey:\n\t\t\t\tbaseKey === \"$root\" ? missingProperty : `${baseKey}.${missingProperty}`,\n\t\t\texpected: formatExpected(error, schema),\n\t\t\treceived: \"undefined\",\n\t\t};\n\t}\n\n\tif (error.keyword === \"additionalProperties\") {\n\t\tconst additionalProperty =\n\t\t\ttypeof error.params === \"object\" &&\n\t\t\terror.params !== null &&\n\t\t\t\"additionalProperty\" in error.params\n\t\t\t\t? String(error.params.additionalProperty)\n\t\t\t\t: \"unknown\";\n\n\t\treturn {\n\t\t\tkey:\n\t\t\t\tbaseKey === \"$root\"\n\t\t\t\t\t? additionalProperty\n\t\t\t\t\t: `${baseKey}.${additionalProperty}`,\n\t\t\texpected: formatExpected(error, schema),\n\t\t\treceived: \"present\",\n\t\t};\n\t}\n\n\treturn {\n\t\tkey: baseKey,\n\t\texpected: formatExpected(error, schema),\n\t\treceived: stringifyValue(data),\n\t};\n}\n\nfunction compileValidator(schema: JSONSchema7): ValidateFunction {\n\tif (isObjectLike(schema)) {\n\t\tconst cached = validatorCache.get(schema);\n\t\tif (cached !== undefined) return cached;\n\t}\n\n\tconst serialized = stableStringify(schema);\n\tconst cachedByString = validatorStringCache.get(serialized);\n\tif (cachedByString !== undefined) {\n\t\tif (isObjectLike(schema)) {\n\t\t\tvalidatorCache.set(schema, cachedByString);\n\t\t}\n\t\treturn cachedByString;\n\t}\n\n\tconst validate = ajv.compile(schema);\n\n\tif (isObjectLike(schema)) {\n\t\tvalidatorCache.set(schema, validate);\n\t}\n\tvalidatorStringCache.set(serialized, validate);\n\n\treturn validate;\n}\n\n/**\n * Validates runtime data against a schema using AJV.\n *\n * @param schema - The schema to validate against\n * @param data - The runtime data to validate\n * @returns true when valid, false otherwise\n */\nexport function isDataValidForSchema(\n\tschema: JSONSchema7Definition,\n\tdata: unknown,\n): boolean {\n\tif (typeof schema === \"boolean\") {\n\t\treturn schema;\n\t}\n\n\tconst validate = compileValidator(schema);\n\treturn validate(data) === true;\n}\n\n/**\n * Returns AJV validation errors converted to the library's `SchemaError` shape.\n *\n * @param schema - The schema used for validation\n * @param data - The runtime data that failed validation\n * @returns Normalized runtime validation errors\n */\nexport function getRuntimeValidationErrors(\n\tschema: JSONSchema7Definition,\n\tdata: unknown,\n): SchemaError[] {\n\tif (typeof schema === \"boolean\") {\n\t\tif (schema) return [];\n\n\t\treturn [\n\t\t\t{\n\t\t\t\tkey: \"$root\",\n\t\t\t\texpected: \"never\",\n\t\t\t\treceived: stringifyValue(data),\n\t\t\t},\n\t\t];\n\t}\n\n\tconst validate = compileValidator(schema);\n\tconst isValid = validate(data);\n\n\tif (\n\t\tisValid === true ||\n\t\tvalidate.errors === null ||\n\t\tvalidate.errors === undefined\n\t) {\n\t\treturn [];\n\t}\n\n\treturn validate.errors.map((error) => buildSchemaError(error, schema, data));\n}\n\n// ─── Partial Validation ──────────────────────────────────────────────────────\n//\n// Strips `required` and `additionalProperties` from a schema recursively so\n// that AJV only validates the properties **present** in the data — without\n// reporting missing required properties or unexpected additional properties.\n//\n// This is used by the \"partial\" runtime validation mode: the caller has\n// partial data (e.g. only some properties known at design-time) and wants to\n// validate those values against the schema without false negatives for\n// properties that will be provided later by another source.\n\n/**\n * Recursively strips `required` and `additionalProperties` from an\n * object-typed JSON Schema so that AJV validates only the properties\n * present in the data.\n *\n * Recurses into: `properties`, `items` (single + tuple), `oneOf`, `anyOf`,\n * `allOf`, `then`, `else`.\n *\n * @param schema - The schema to strip (not mutated — returns a new object)\n * @returns A new schema without `required` or `additionalProperties` at any level\n */\nexport function stripRequiredRecursive(schema: JSONSchema7): JSONSchema7 {\n\tif (!isPlainObj(schema)) return schema;\n\n\tconst result: JSONSchema7 = { ...schema };\n\tdelete result.required;\n\tdelete result.additionalProperties;\n\n\t// ── Recurse into properties ──\n\tif (isPlainObj(result.properties)) {\n\t\tconst props: Record<string, JSONSchema7Definition> = {};\n\t\tfor (const [key, value] of Object.entries(\n\t\t\tresult.properties as Record<string, JSONSchema7Definition>,\n\t\t)) {\n\t\t\tprops[key] =\n\t\t\t\ttypeof value === \"object\" && value !== null\n\t\t\t\t\t? stripRequiredRecursive(value)\n\t\t\t\t\t: value;\n\t\t}\n\t\tresult.properties = props;\n\t}\n\n\t// ── Recurse into items (single schema) ──\n\tif (isPlainObj(result.items) && !Array.isArray(result.items)) {\n\t\tresult.items = stripRequiredRecursive(result.items as JSONSchema7);\n\t}\n\n\t// ── Recurse into tuple items ──\n\tif (Array.isArray(result.items)) {\n\t\tresult.items = (result.items as JSONSchema7Definition[]).map((item) =>\n\t\t\ttypeof item === \"object\" && item !== null\n\t\t\t\t? stripRequiredRecursive(item)\n\t\t\t\t: item,\n\t\t);\n\t}\n\n\t// ── Recurse into branching keywords ──\n\tfor (const keyword of [\"oneOf\", \"anyOf\", \"allOf\"] as const) {\n\t\tif (Array.isArray(result[keyword])) {\n\t\t\tresult[keyword] = (result[keyword] as JSONSchema7Definition[]).map(\n\t\t\t\t(branch) =>\n\t\t\t\t\ttypeof branch === \"object\" && branch !== null\n\t\t\t\t\t\t? stripRequiredRecursive(branch)\n\t\t\t\t\t\t: branch,\n\t\t\t);\n\t\t}\n\t}\n\n\t// ── Recurse into conditional keywords ──\n\tif (isPlainObj(result.then)) {\n\t\tresult.then = stripRequiredRecursive(result.then as JSONSchema7);\n\t}\n\tif (isPlainObj(result.else)) {\n\t\tresult.else = stripRequiredRecursive(result.else as JSONSchema7);\n\t}\n\n\treturn result;\n}\n\n/**\n * Returns AJV validation errors for partial data — strips `required` and\n * `additionalProperties` before compilation so that only the properties\n * **present** in `data` are validated.\n *\n * @param schema - The schema to validate against (not mutated)\n * @param data - The partial runtime data\n * @returns Normalized runtime validation errors for present properties only\n */\nexport function getPartialRuntimeValidationErrors(\n\tschema: JSONSchema7Definition,\n\tdata: unknown,\n): SchemaError[] {\n\tif (typeof schema === \"boolean\") {\n\t\treturn getRuntimeValidationErrors(schema, data);\n\t}\n\n\tconst stripped = stripRequiredRecursive(schema);\n\treturn getRuntimeValidationErrors(stripped, data);\n}\n\n/**\n * Clears all compiled validator caches (WeakMap, LRU, and AJV internal).\n *\n * Useful for:\n * - Long-running processes where schemas evolve over time\n * - Test isolation (ensuring no cross-test cache pollution)\n * - Memory pressure situations where cached validators are no longer needed\n *\n * After calling this, the next validation call will recompile validators\n * from scratch — there is a one-time performance cost per unique schema.\n */\nexport function clearAllValidatorCaches(): void {\n\t// The WeakMap cannot be \"cleared\" via API — we replace the reference.\n\t// However, since it's a module-level const, we clear it by removing\n\t// AJV's internal schema cache which is the primary memory consumer.\n\t// The WeakMap entries will be garbage-collected when their schema keys\n\t// are no longer referenced.\n\n\t// Clear the LRU string-keyed cache\n\tvalidatorStringCache.clear();\n\n\t// Clear AJV's internal compiled schema cache\n\tajv.removeSchema();\n}\n"],"names":["clearAllValidatorCaches","getPartialRuntimeValidationErrors","getRuntimeValidationErrors","isDataValidForSchema","stripRequiredRecursive","ajv","Ajv","allErrors","strict","validateFormats","allowUnionTypes","messages","addFormats","validatorCache","WeakMap","LRUCache","get","key","value","cache","undefined","delete","set","has","size","max","firstKey","keys","next","clear","maxSize","Map","validatorStringCache","isObjectLike","stableStringify","JSON","stringify","Array","isArray","map","entry","join","entries","Object","sort","a","b","localeCompare","entryValue","getSchemaTypeName","schema","type","stringifyValue","normalizeInstancePath","instancePath","parts","split","filter","Boolean","length","path","rawPart","part","replace","isArrayIndex","test","formatAllowedValues","values","rendered","slice","formatExpected","error","keyword","expectedType","params","String","enum","const","missingProperty","targetSchema","properties","prefix","minimum","maximum","exclusiveMinimum","exclusiveMaximum","multipleOf","minLength","maxLength","pattern","format","minItems","maxItems","minProperties","maxProperties","message","buildSchemaError","data","baseKey","expected","received","additionalProperty","compileValidator","cached","serialized","cachedByString","validate","compile","isValid","errors","isPlainObj","result","required","additionalProperties","props","items","item","branch","then","else","stripped","removeSchema"],"mappings":"mPAqiBgBA,iCAAAA,6BAvBAC,2CAAAA,uCAvHAC,oCAAAA,gCAnBAC,8BAAAA,0BAuEAC,gCAAAA,mFA3c6C,wEACtC,uCAGI,sRAyC3B,MAAMC,IAAM,IAAIC,YAAG,CAAC,CACnBC,UAAW,KACXC,OAAQ,MACRC,gBAAiB,KACjBC,gBAAiB,KACjBC,SAAU,IACX,GAEAC,GAAAA,mBAAU,EAACP,KAQX,MAAMQ,eAAiB,IAAIC,OAQ3B,OAAMC,SAQLC,IAAIC,GAAM,CAAiB,CAC1B,MAAMC,MAAQ,IAAI,CAACC,KAAK,CAACH,GAAG,CAACC,KAC7B,GAAIC,QAAUE,UAAW,OAAOA,UAGhC,IAAI,CAACD,KAAK,CAACE,MAAM,CAACJ,KAClB,IAAI,CAACE,KAAK,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WO,SAAS9G,kCACfiD,MAA6B,CAC7B+C,IAAa,EAEb,GAAI,OAAO/C,SAAW,UAAW,CAChC,OAAOhD,2BAA2BgD,OAAQ+C,KAC3C,CAEA,MAAMuB,SAAWpH,uBAAuB8C,QACxC,OAAOhD,2BAA2BsH,SAAUvB,KAC7C,CAaO,SAASjG,0BAQfgC,qBAAqBH,KAAK,GAG1BxB,IAAIoH,YAAY,EACjB"}
1
+ {"version":3,"sources":["../../src/runtime-validator.ts"],"sourcesContent":["import Ajv, { type ErrorObject, type ValidateFunction } from \"ajv\";\nimport addFormats from \"ajv-formats\";\nimport type { JSONSchema7, JSONSchema7Definition } from \"json-schema\";\nimport type { SchemaError } from \"./types.ts\";\nimport { SchemaErrorType } from \"./types.ts\";\nimport { isPlainObj } from \"./utils.ts\";\n\n/**\n * ─── Runtime Validator ────────────────────────────────────────────────────────\n *\n * Centralizes runtime validation of JSON Schema Draft-07 schemas using AJV.\n *\n * Goals:\n * - Validate concrete runtime data against resolved schemas\n * - Reuse the same runtime engine for `check(..., { data })`\n * - Reuse the same runtime engine for `if/then/else` condition evaluation\n * - Keep the static subset-checking pipeline unchanged when no runtime data is provided\n *\n * Architecture — Singleton AJV instance:\n * The `ajv` constant below is a module-level singleton shared by every\n * `JsonSchemaCompatibilityChecker` instance in the same process. This is\n * intentional:\n * - Compiled validators are reused across checker instances, avoiding\n * redundant schema compilation and reducing memory usage.\n * - The WeakMap and LRU caches for `ValidateFunction` objects are valid\n * only for a single AJV instance; per-instance AJV would break caching.\n * - `ajv-formats` is registered once at module load; all standard Draft-07\n * formats are available globally.\n * - In worker-thread environments, each worker loads its own module scope\n * and gets its own AJV instance — no cross-worker sharing occurs.\n * - Custom AJV configuration or format registration is not supported\n * per-checker-instance. If needed in the future, the singleton could be\n * replaced with a factory, but this is intentionally deferred (YAGNI).\n *\n * Notes:\n * - AJV is configured in non-strict mode because this library intentionally\n * supports partially-specified / pragmatic schemas and some unsupported\n * keywords may appear in user input.\n * - Standard JSON Schema formats are enabled through `ajv-formats` so runtime\n * validation can influence condition resolution and `check(..., { data })`\n * consistently for supported formats.\n * - Unknown formats are still ignored in practice by the non-strict runtime\n * configuration instead of crashing the whole check pipeline.\n */\n\n// Singleton AJV instance — shared across all checker instances (see module JSDoc above)\nconst ajv = new Ajv({\n\tallErrors: true,\n\tstrict: false,\n\tvalidateFormats: true,\n\tallowUnionTypes: true,\n\tmessages: true,\n});\n\naddFormats(ajv);\n\n/**\n * Cache compiled validators by schema object reference.\n *\n * This mirrors the codebase's preference for WeakMap-based caching and avoids\n * recompiling validators for the same resolved schema instances.\n */\nconst validatorCache = new WeakMap<object, ValidateFunction>();\n\n/**\n * Minimal LRU cache using Map insertion-order guarantees for O(1) eviction.\n *\n * On `get`, the entry is moved to the end (most recently used).\n * On `set`, if the cache is full, the first entry (least recently used) is evicted.\n */\nclass LRUCache<K, V> {\n\tprivate readonly max: number;\n\tprivate readonly cache = new Map<K, V>();\n\n\tconstructor(maxSize: number) {\n\t\tthis.max = maxSize;\n\t}\n\n\tget(key: K): V | undefined {\n\t\tconst value = this.cache.get(key);\n\t\tif (value === undefined) return undefined;\n\n\t\t// Move to end (most recently used)\n\t\tthis.cache.delete(key);\n\t\tthis.cache.set(key, value);\n\t\treturn value;\n\t}\n\n\tset(key: K, value: V): void {\n\t\tif (this.cache.has(key)) {\n\t\t\tthis.cache.delete(key);\n\t\t} else if (this.cache.size >= this.max) {\n\t\t\t// Evict least recently used (first key in iteration order)\n\t\t\tconst firstKey = this.cache.keys().next().value;\n\t\t\tif (firstKey !== undefined) {\n\t\t\t\tthis.cache.delete(firstKey);\n\t\t\t}\n\t\t}\n\t\tthis.cache.set(key, value);\n\t}\n\n\tclear(): void {\n\t\tthis.cache.clear();\n\t}\n}\n\n/**\n * LRU cache for compiled validators keyed by deterministic schema serialization.\n *\n * This is a fallback for schemas that are not stable object references (e.g.\n * freshly constructed schemas that are structurally identical to previously\n * seen ones). Bounded to 500 entries to prevent unbounded memory growth in\n * long-running processes. The WeakMap-based `validatorCache` remains the\n * primary cache for the hot path.\n */\nconst validatorStringCache = new LRUCache<string, ValidateFunction>(500);\n\nfunction isObjectLike(value: unknown): value is object {\n\treturn typeof value === \"object\" && value !== null;\n}\n\nfunction stableStringify(value: unknown): string {\n\tif (value === null || typeof value !== \"object\") {\n\t\treturn JSON.stringify(value);\n\t}\n\n\tif (Array.isArray(value)) {\n\t\treturn `[${value.map((entry) => stableStringify(entry)).join(\",\")}]`;\n\t}\n\n\tconst entries = Object.entries(value as Record<string, unknown>).sort(\n\t\t([a], [b]) => a.localeCompare(b),\n\t);\n\n\treturn `{${entries\n\t\t.map(\n\t\t\t([key, entryValue]) =>\n\t\t\t\t`${JSON.stringify(key)}:${stableStringify(entryValue)}`,\n\t\t)\n\t\t.join(\",\")}}`;\n}\n\nfunction getSchemaTypeName(schema: JSONSchema7): string {\n\tif (schema.type === undefined) return \"value\";\n\n\tif (Array.isArray(schema.type)) {\n\t\treturn schema.type.join(\" | \");\n\t}\n\n\treturn schema.type;\n}\n\nfunction stringifyValue(value: unknown): string {\n\tif (value === undefined) return \"undefined\";\n\tif (typeof value === \"string\") return value;\n\treturn JSON.stringify(value);\n}\n\nfunction normalizeInstancePath(instancePath: string): string {\n\tif (instancePath === \"\") return \"$root\";\n\n\tconst parts = instancePath.split(\"/\").filter(Boolean);\n\tif (parts.length === 0) return \"$root\";\n\n\tlet path = \"\";\n\n\tfor (const rawPart of parts) {\n\t\tconst part = rawPart.replace(/~1/g, \"/\").replace(/~0/g, \"~\");\n\t\tconst isArrayIndex = /^\\d+$/.test(part);\n\n\t\tif (isArrayIndex) {\n\t\t\tpath += \"[]\";\n\t\t\tcontinue;\n\t\t}\n\n\t\tpath = path.length === 0 ? part : `${path}.${part}`;\n\t}\n\n\treturn path || \"$root\";\n}\n\nfunction formatAllowedValues(values: unknown[]): string {\n\tif (values.length === 0) return \"no allowed values\";\n\n\tconst rendered = values.map((value) =>\n\t\ttypeof value === \"string\" ? value : JSON.stringify(value),\n\t);\n\n\tif (rendered.length === 1) return rendered[0] ?? \"\";\n\tif (rendered.length === 2) return `${rendered[0]} or ${rendered[1]}`;\n\n\treturn `${rendered.slice(0, -1).join(\", \")}, or ${rendered[rendered.length - 1]}`;\n}\n\nfunction formatExpected(error: ErrorObject, schema: JSONSchema7): string {\n\tswitch (error.keyword) {\n\t\tcase \"type\": {\n\t\t\tconst expectedType =\n\t\t\t\ttypeof error.params === \"object\" &&\n\t\t\t\terror.params !== null &&\n\t\t\t\t\"type\" in error.params\n\t\t\t\t\t? String(error.params.type)\n\t\t\t\t\t: getSchemaTypeName(schema);\n\n\t\t\treturn expectedType;\n\t\t}\n\n\t\tcase \"enum\": {\n\t\t\treturn Array.isArray(schema.enum)\n\t\t\t\t? formatAllowedValues(schema.enum)\n\t\t\t\t: \"allowed enum value\";\n\t\t}\n\n\t\tcase \"const\": {\n\t\t\treturn stringifyValue(schema.const);\n\t\t}\n\n\t\tcase \"required\": {\n\t\t\tconst missingProperty =\n\t\t\t\ttypeof error.params === \"object\" &&\n\t\t\t\terror.params !== null &&\n\t\t\t\t\"missingProperty\" in error.params\n\t\t\t\t\t? String(error.params.missingProperty)\n\t\t\t\t\t: \"unknown\";\n\n\t\t\tconst targetSchema =\n\t\t\t\tschema.properties?.[missingProperty] &&\n\t\t\t\ttypeof schema.properties[missingProperty] !== \"boolean\"\n\t\t\t\t\t? (schema.properties[missingProperty] as JSONSchema7)\n\t\t\t\t\t: undefined;\n\n\t\t\tif (targetSchema?.type !== undefined) {\n\t\t\t\tconst prefix = normalizeInstancePath(error.instancePath);\n\t\t\t\tconst key =\n\t\t\t\t\tprefix === \"$root\" ? missingProperty : `${prefix}.${missingProperty}`;\n\t\t\t\treturn `${key}: ${getSchemaTypeName(targetSchema)}`;\n\t\t\t}\n\n\t\t\treturn `required property: ${missingProperty}`;\n\t\t}\n\n\t\tcase \"minimum\":\n\t\t\treturn `>= ${String((schema as JSONSchema7).minimum)}`;\n\n\t\tcase \"maximum\":\n\t\t\treturn `<= ${String((schema as JSONSchema7).maximum)}`;\n\n\t\tcase \"exclusiveMinimum\":\n\t\t\treturn `> ${String((schema as JSONSchema7).exclusiveMinimum)}`;\n\n\t\tcase \"exclusiveMaximum\":\n\t\t\treturn `< ${String((schema as JSONSchema7).exclusiveMaximum)}`;\n\n\t\tcase \"multipleOf\":\n\t\t\treturn `multipleOf ${String((schema as JSONSchema7).multipleOf)}`;\n\n\t\tcase \"minLength\":\n\t\t\treturn `minLength: ${String((schema as JSONSchema7).minLength)}`;\n\n\t\tcase \"maxLength\":\n\t\t\treturn `maxLength: ${String((schema as JSONSchema7).maxLength)}`;\n\n\t\tcase \"pattern\":\n\t\t\treturn `pattern: ${String((schema as JSONSchema7).pattern)}`;\n\n\t\tcase \"format\":\n\t\t\treturn `format: ${String((schema as JSONSchema7).format)}`;\n\n\t\tcase \"minItems\":\n\t\t\treturn `minItems: ${String((schema as JSONSchema7).minItems)}`;\n\n\t\tcase \"maxItems\":\n\t\t\treturn `maxItems: ${String((schema as JSONSchema7).maxItems)}`;\n\n\t\tcase \"uniqueItems\":\n\t\t\treturn \"uniqueItems: true\";\n\n\t\tcase \"minProperties\":\n\t\t\treturn `minProperties: ${String((schema as JSONSchema7).minProperties)}`;\n\n\t\tcase \"maxProperties\":\n\t\t\treturn `maxProperties: ${String((schema as JSONSchema7).maxProperties)}`;\n\n\t\tcase \"additionalProperties\":\n\t\t\treturn \"not allowed (additionalProperties: false)\";\n\n\t\tcase \"propertyNames\":\n\t\t\treturn \"valid property names\";\n\n\t\tcase \"contains\":\n\t\t\treturn \"contains at least one matching item\";\n\n\t\tcase \"allOf\":\n\t\t\treturn \"allOf constraints\";\n\n\t\tcase \"anyOf\":\n\t\t\treturn \"anyOf constraints\";\n\n\t\tcase \"oneOf\":\n\t\t\treturn \"oneOf constraints\";\n\n\t\tcase \"not\":\n\t\t\treturn \"not matching forbidden schema\";\n\n\t\tdefault:\n\t\t\treturn error.message ?? error.keyword;\n\t}\n}\n\nfunction buildSchemaError(\n\terror: ErrorObject,\n\tschema: JSONSchema7,\n\tdata: unknown,\n): SchemaError {\n\tconst type = SchemaErrorType.RuntimeValidation;\n\tconst baseKey = normalizeInstancePath(error.instancePath);\n\n\tif (error.keyword === \"required\") {\n\t\tconst missingProperty =\n\t\t\ttypeof error.params === \"object\" &&\n\t\t\terror.params !== null &&\n\t\t\t\"missingProperty\" in error.params\n\t\t\t\t? String(error.params.missingProperty)\n\t\t\t\t: \"unknown\";\n\n\t\treturn {\n\t\t\ttype,\n\t\t\tkey:\n\t\t\t\tbaseKey === \"$root\" ? missingProperty : `${baseKey}.${missingProperty}`,\n\t\t\texpected: formatExpected(error, schema),\n\t\t\treceived: \"undefined\",\n\t\t};\n\t}\n\n\tif (error.keyword === \"additionalProperties\") {\n\t\tconst additionalProperty =\n\t\t\ttypeof error.params === \"object\" &&\n\t\t\terror.params !== null &&\n\t\t\t\"additionalProperty\" in error.params\n\t\t\t\t? String(error.params.additionalProperty)\n\t\t\t\t: \"unknown\";\n\n\t\treturn {\n\t\t\ttype,\n\t\t\tkey:\n\t\t\t\tbaseKey === \"$root\"\n\t\t\t\t\t? additionalProperty\n\t\t\t\t\t: `${baseKey}.${additionalProperty}`,\n\t\t\texpected: formatExpected(error, schema),\n\t\t\treceived: \"present\",\n\t\t};\n\t}\n\n\treturn {\n\t\ttype,\n\t\tkey: baseKey,\n\t\texpected: formatExpected(error, schema),\n\t\treceived: stringifyValue(data),\n\t};\n}\n\nfunction compileValidator(schema: JSONSchema7): ValidateFunction {\n\tif (isObjectLike(schema)) {\n\t\tconst cached = validatorCache.get(schema);\n\t\tif (cached !== undefined) return cached;\n\t}\n\n\tconst serialized = stableStringify(schema);\n\tconst cachedByString = validatorStringCache.get(serialized);\n\tif (cachedByString !== undefined) {\n\t\tif (isObjectLike(schema)) {\n\t\t\tvalidatorCache.set(schema, cachedByString);\n\t\t}\n\t\treturn cachedByString;\n\t}\n\n\tconst validate = ajv.compile(schema);\n\n\tif (isObjectLike(schema)) {\n\t\tvalidatorCache.set(schema, validate);\n\t}\n\tvalidatorStringCache.set(serialized, validate);\n\n\treturn validate;\n}\n\n/**\n * Validates runtime data against a schema using AJV.\n *\n * @param schema - The schema to validate against\n * @param data - The runtime data to validate\n * @returns true when valid, false otherwise\n */\nexport function isDataValidForSchema(\n\tschema: JSONSchema7Definition,\n\tdata: unknown,\n): boolean {\n\tif (typeof schema === \"boolean\") {\n\t\treturn schema;\n\t}\n\n\tconst validate = compileValidator(schema);\n\treturn validate(data) === true;\n}\n\n/**\n * Returns AJV validation errors converted to the library's `SchemaError` shape.\n *\n * @param schema - The schema used for validation\n * @param data - The runtime data that failed validation\n * @returns Normalized runtime validation errors\n */\nexport function getRuntimeValidationErrors(\n\tschema: JSONSchema7Definition,\n\tdata: unknown,\n): SchemaError[] {\n\tif (typeof schema === \"boolean\") {\n\t\tif (schema) return [];\n\n\t\treturn [\n\t\t\t{\n\t\t\t\ttype: SchemaErrorType.RuntimeValidation,\n\t\t\t\tkey: \"$root\",\n\t\t\t\texpected: \"never\",\n\t\t\t\treceived: stringifyValue(data),\n\t\t\t},\n\t\t];\n\t}\n\n\tconst validate = compileValidator(schema);\n\tconst isValid = validate(data);\n\n\tif (\n\t\tisValid === true ||\n\t\tvalidate.errors === null ||\n\t\tvalidate.errors === undefined\n\t) {\n\t\treturn [];\n\t}\n\n\treturn validate.errors.map((error) => buildSchemaError(error, schema, data));\n}\n\n// ─── Partial Validation ──────────────────────────────────────────────────────\n//\n// Strips `required` and `additionalProperties` from a schema recursively so\n// that AJV only validates the properties **present** in the data — without\n// reporting missing required properties or unexpected additional properties.\n//\n// This is used by the \"partial\" runtime validation mode: the caller has\n// partial data (e.g. only some properties known at design-time) and wants to\n// validate those values against the schema without false negatives for\n// properties that will be provided later by another source.\n\n/**\n * Recursively strips `required` and `additionalProperties` from an\n * object-typed JSON Schema so that AJV validates only the properties\n * present in the data.\n *\n * Recurses into: `properties`, `items` (single + tuple), `oneOf`, `anyOf`,\n * `allOf`, `then`, `else`.\n *\n * @param schema - The schema to strip (not mutated — returns a new object)\n * @returns A new schema without `required` or `additionalProperties` at any level\n */\nexport function stripRequiredRecursive(schema: JSONSchema7): JSONSchema7 {\n\tif (!isPlainObj(schema)) return schema;\n\n\tconst result: JSONSchema7 = { ...schema };\n\tdelete result.required;\n\tdelete result.additionalProperties;\n\n\t// ── Recurse into properties ──\n\tif (isPlainObj(result.properties)) {\n\t\tconst props: Record<string, JSONSchema7Definition> = {};\n\t\tfor (const [key, value] of Object.entries(\n\t\t\tresult.properties as Record<string, JSONSchema7Definition>,\n\t\t)) {\n\t\t\tprops[key] =\n\t\t\t\ttypeof value === \"object\" && value !== null\n\t\t\t\t\t? stripRequiredRecursive(value)\n\t\t\t\t\t: value;\n\t\t}\n\t\tresult.properties = props;\n\t}\n\n\t// ── Recurse into items (single schema) ──\n\tif (isPlainObj(result.items) && !Array.isArray(result.items)) {\n\t\tresult.items = stripRequiredRecursive(result.items as JSONSchema7);\n\t}\n\n\t// ── Recurse into tuple items ──\n\tif (Array.isArray(result.items)) {\n\t\tresult.items = (result.items as JSONSchema7Definition[]).map((item) =>\n\t\t\ttypeof item === \"object\" && item !== null\n\t\t\t\t? stripRequiredRecursive(item)\n\t\t\t\t: item,\n\t\t);\n\t}\n\n\t// ── Recurse into branching keywords ──\n\tfor (const keyword of [\"oneOf\", \"anyOf\", \"allOf\"] as const) {\n\t\tif (Array.isArray(result[keyword])) {\n\t\t\tresult[keyword] = (result[keyword] as JSONSchema7Definition[]).map(\n\t\t\t\t(branch) =>\n\t\t\t\t\ttypeof branch === \"object\" && branch !== null\n\t\t\t\t\t\t? stripRequiredRecursive(branch)\n\t\t\t\t\t\t: branch,\n\t\t\t);\n\t\t}\n\t}\n\n\t// ── Recurse into conditional keywords ──\n\tif (isPlainObj(result.then)) {\n\t\tresult.then = stripRequiredRecursive(result.then as JSONSchema7);\n\t}\n\tif (isPlainObj(result.else)) {\n\t\tresult.else = stripRequiredRecursive(result.else as JSONSchema7);\n\t}\n\n\treturn result;\n}\n\n/**\n * Returns AJV validation errors for partial data — strips `required` and\n * `additionalProperties` before compilation so that only the properties\n * **present** in `data` are validated.\n *\n * @param schema - The schema to validate against (not mutated)\n * @param data - The partial runtime data\n * @returns Normalized runtime validation errors for present properties only\n */\nexport function getPartialRuntimeValidationErrors(\n\tschema: JSONSchema7Definition,\n\tdata: unknown,\n): SchemaError[] {\n\tif (typeof schema === \"boolean\") {\n\t\treturn getRuntimeValidationErrors(schema, data);\n\t}\n\n\tconst stripped = stripRequiredRecursive(schema);\n\treturn getRuntimeValidationErrors(stripped, data);\n}\n\n/**\n * Clears all compiled validator caches (WeakMap, LRU, and AJV internal).\n *\n * Useful for:\n * - Long-running processes where schemas evolve over time\n * - Test isolation (ensuring no cross-test cache pollution)\n * - Memory pressure situations where cached validators are no longer needed\n *\n * After calling this, the next validation call will recompile validators\n * from scratch — there is a one-time performance cost per unique schema.\n */\nexport function clearAllValidatorCaches(): void {\n\t// The WeakMap cannot be \"cleared\" via API — we replace the reference.\n\t// However, since it's a module-level const, we clear it by removing\n\t// AJV's internal schema cache which is the primary memory consumer.\n\t// The WeakMap entries will be garbage-collected when their schema keys\n\t// are no longer referenced.\n\n\t// Clear the LRU string-keyed cache\n\tvalidatorStringCache.clear();\n\n\t// Clear AJV's internal compiled schema cache\n\tajv.removeSchema();\n}\n"],"names":["clearAllValidatorCaches","getPartialRuntimeValidationErrors","getRuntimeValidationErrors","isDataValidForSchema","stripRequiredRecursive","ajv","Ajv","allErrors","strict","validateFormats","allowUnionTypes","messages","addFormats","validatorCache","WeakMap","LRUCache","get","key","value","cache","undefined","delete","set","has","size","max","firstKey","keys","next","clear","maxSize","Map","validatorStringCache","isObjectLike","stableStringify","JSON","stringify","Array","isArray","map","entry","join","entries","Object","sort","a","b","localeCompare","entryValue","getSchemaTypeName","schema","type","stringifyValue","normalizeInstancePath","instancePath","parts","split","filter","Boolean","length","path","rawPart","part","replace","isArrayIndex","test","formatAllowedValues","values","rendered","slice","formatExpected","error","keyword","expectedType","params","String","enum","const","missingProperty","targetSchema","properties","prefix","minimum","maximum","exclusiveMinimum","exclusiveMaximum","multipleOf","minLength","maxLength","pattern","format","minItems","maxItems","minProperties","maxProperties","message","buildSchemaError","data","SchemaErrorType","RuntimeValidation","baseKey","expected","received","additionalProperty","compileValidator","cached","serialized","cachedByString","validate","compile","isValid","errors","isPlainObj","result","required","additionalProperties","props","items","item","branch","then","else","stripped","removeSchema"],"mappings":"mPA2iBgBA,iCAAAA,6BAvBAC,2CAAAA,uCAxHAC,oCAAAA,gCAnBAC,8BAAAA,0BAwEAC,gCAAAA,mFAjd6C,wEACtC,uCAGS,qCACL,sRAyC3B,MAAMC,IAAM,IAAIC,YAAG,CAAC,CACnBC,UAAW,KACXC,OAAQ,MACRC,gBAAiB,KACjBC,gBAAiB,KACjBC,SAAU,IACX,GAEAC,GAAAA,mBAAU,EAACP,KAQX,MAAMQ,eAAiB,IAAIC,OAQ3B,OAAMC,SAQLC,IAAIC,GAAM,CAAiB,CAC1B,MAAMC,MAAQ,IAAI,CAACC,KAAK,CAACH,GAAG,CAACC,KAC7B,GAAIC,QAAUE,UAAW,OAAOA,UAGhC,IAAI,CAACD,KAAK,CAACE,MAAM,CAACJ,KAClB,IAAI,CAACE,KAAK,CAACG,GAAG,CAACL,IAAKC,OACpB,OAAOA,KACR,CAEAI,IAAIL,GAAM,CAAEC,KAAQ,CAAQ,CAC3B,GAAI,IAAI,CAACC,KAAK,CAACI,GAAG,CAACN,KAAM,CACxB,IAAI,CAACE,KAAK,CAACE,MAAM,CAACJ,IACnB,MAAO,GAAI,IAAI,CAACE,KAAK,CAACK,IAAI,EAAI,IAAI,CAACC,GAAG,CAAE,CAEvC,MAAMC,SAAW,IAAI,CAACP,KAAK,CAACQ,IAAI,GAAGC,IAAI,GAAGV,KAAK,CAC/C,GAAIQ,WAAaN,UAAW,CAC3B,IAAI,CAACD,KAAK,CAACE,MAAM,CAACK,SACnB,CACD,CACA,IAAI,C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