json-schema-compatibility-checker 1.1.3 → 1.1.4

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.
@@ -18,4 +18,4 @@ import type { ConstraintValidatorRegistry, SchemaError } from "./types.js";
18
18
  * @param path - The current property path (for error reporting)
19
19
  * @returns Array of schema errors (empty if all constraints pass)
20
20
  */
21
- export declare function validateSchemaConstraints(schema: JSONSchema7Definition, data: unknown, registry: ConstraintValidatorRegistry, path?: string): SchemaError[];
21
+ export declare function validateSchemaConstraints(schema: JSONSchema7Definition, data: unknown, registry: ConstraintValidatorRegistry, path?: string): Promise<SchemaError[]>;
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:true});Object.defineProperty(exports,"validateSchemaConstraints",{enumerable:true,get:function(){return validateSchemaConstraints}});const _utilsts=require("./utils.js");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=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}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(...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(...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(...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(...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(...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(...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(...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 _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}
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 */\nfunction validateValue(\n\tconstraints: Constraint[],\n\tvalue: unknown,\n\tregistry: ConstraintValidatorRegistry,\n\tpath: string,\n): 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 = 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 function validateSchemaConstraints(\n\tschema: JSONSchema7Definition,\n\tdata: unknown,\n\tregistry: ConstraintValidatorRegistry,\n\tpath = \"\",\n): 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(...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...validateSchemaConstraints(propSchema, propValue, registry, propPath),\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...validateSchemaConstraints(itemSchema, data[i], registry, itemPath),\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...validateSchemaConstraints(itemSchema, data[i], registry, itemPath),\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...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...validateSchemaConstraints(apSchema, dataValue, registry, apPath),\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(...validateSchemaConstraints(depValue, data, registry, path));\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":"oGAyFgBA,mEAAAA,oDAnFsC,cAmBtD,SAASC,cACRC,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,OAASL,UAAUR,MAAOM,QAChC,GAAI,CAACO,OAAOC,KAAK,CAAE,CAClBX,OAAOM,IAAI,CAAC,CACXC,IAAKR,MAAQ,QACbS,SAAU,CAAC,YAAY,EAAEN,KAAK,CAAC,CAC/BO,SAAUC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AI,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,IAAIZ,0BAA0BgE,SAAU1C,KAAMlB,SAAUC,MACpE,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 { 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,QACtC,GAAI,CAACO,OAAOC,KAAK,CAAE,CAClBX,OAAOM,IAAI,CAAC,CACXC,IAAKR,MAAQ,QACbS,SAAU,CAAC,YAAY,EAAEN,KAAK,CAAC,CAC/BO,SAAUC,OAAOE,OAAO,EAAI,8BAC7B,EACD,CACD,CAAE,MAAOC,IAAK,CACbb,OAAOM,IAAI,CAAC,CACXC,IAAKR,MAAQ,QACbS,SAAU,CAAC,YAAY,EAAEN,KAAK,CAAC,CAC/BO,SACCI,eAAeC,MAAQD,IAAID,OAAO,CAAG,6BACvC,EACD,CACD,CAEA,OAAOZ,MACR,CAoBO,eAAeN,0BACrBqB,MAA6B,CAC7BC,IAAa,CACblB,QAAqC,CACrCC,KAAO,EAAE,EAGT,GAAI,OAAOgB,SAAW,UAAW,MAAO,EAAE,CAE1C,MAAMf,OAAwB,EAAE,CAGhC,MAAMJ,YAAcqB,GAAAA,0BAAiB,EAACF,OAAOnB,WAAW,EACxD,GAAIA,YAAYsB,MAAM,CAAG,EAAG,CAC3BlB,OAAOM,IAAI,IAAK,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ACJ,OAAOqB,iBAAiB,EAAG,CACzC,IAAK,MAAME,WAAWf,OAAOC,IAAI,CAChCT,OAAOqB,iBAAiB,EACtB,CACF,GAAI,CACHc,WAAW5C,IAAI,CAAC,IAAImC,OAAOH,SAC5B,CAAE,KAAM,CAER,CACD,CACD,CAEA,IAAK,MAAMI,WAAWnB,OAAOC,IAAI,CAACF,SAAU,CAE3C,GAAI0B,aAAaG,GAAG,CAACT,SAAU,SAG/B,GAAIQ,WAAWE,IAAI,CAAC,AAACC,IAAOA,GAAGV,IAAI,CAACD,UAAW,SAE/C,MAAME,UAAYtB,OAAO,CAACoB,QAAQ,CAClC,MAAMY,OAASvD,KAAO,CAAC,EAAEA,KAAK,CAAC,EAAE2C,QAAQ,CAAC,CAAGA,QAC7C1C,OAAOM,IAAI,IACN,MAAMZ,0BACTqD,SACAH,UACA9C,SACAwD,QAGH,CACD,CAGA,GAAInC,GAAAA,mBAAU,EAACJ,OAAOwC,YAAY,GAAKpC,GAAAA,mBAAU,EAACH,MAAO,CACxD,MAAMwC,KAAOzC,OAAOwC,YAAY,CAIhC,MAAMjC,QAAUN,KAEhB,IAAK,MAAMyC,UAAUlC,OAAOC,IAAI,CAACgC,MAAO,CAEvC,GAAI,CAAC7B,GAAAA,eAAM,EAACL,QAASmC,QAAS,SAE9B,MAAMC,SAAWF,IAAI,CAACC,OAAO,CAC7B,GAAIC,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"}
@@ -53,7 +53,7 @@ export declare class JsonSchemaCompatibilityChecker {
53
53
  * checker.check(sub, sup, { data: { kind: "text", value: "hello" }, validate: true });
54
54
  * ```
55
55
  */
56
- check(sub: JSONSchema7Definition, sup: JSONSchema7Definition, options: CheckRuntimeOptions): ResolvedSubsetResult;
56
+ check(sub: JSONSchema7Definition, sup: JSONSchema7Definition, options: CheckRuntimeOptions): Promise<ResolvedSubsetResult>;
57
57
  check(sub: JSONSchema7Definition, sup: JSONSchema7Definition): SubsetResult;
58
58
  /**
59
59
  * Checks structural equality between two schemas.
@@ -85,6 +85,12 @@ export declare class JsonSchemaCompatibilityChecker {
85
85
  * @returns The resolved schema with branch info and discriminants
86
86
  */
87
87
  resolveConditions(schema: JSONSchema7, data: Record<string, unknown>): ResolvedConditionResult;
88
+ /**
89
+ * Internal runtime-aware check logic. Extracted as an async method
90
+ * so that `check()` without options stays synchronous while the
91
+ * runtime path can `await` async constraint validators.
92
+ */
93
+ private checkWithOptions;
88
94
  private prefixRuntimeErrors;
89
95
  /**
90
96
  * Internal check logic without condition resolution.
@@ -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");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){const data=options.data;const shouldValidate=options.validate===true;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(shouldValidate&&data!==undefined){const runtimeErrors=[];runtimeErrors.push(...this.prefixRuntimeErrors((0,_runtimevalidatorts.getRuntimeValidationErrors)(narrowedSubResolved,data),"$sub"));runtimeErrors.push(...this.prefixRuntimeErrors((0,_runtimevalidatorts.getRuntimeValidationErrors)(narrowedSupResolved,data),"$sup"));runtimeErrors.push(...this.prefixRuntimeErrors((0,_constraintvalidatorts.validateSchemaConstraints)(narrowedSubResolved,data,this.constraintValidators),"$sub"));runtimeErrors.push(...this.prefixRuntimeErrors((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}}}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)}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 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");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 shouldValidate=options.validate===true;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(shouldValidate&&data!==undefined){const runtimeErrors=[];runtimeErrors.push(...this.prefixRuntimeErrors((0,_runtimevalidatorts.getRuntimeValidationErrors)(narrowedSubResolved,data),"$sub"));runtimeErrors.push(...this.prefixRuntimeErrors((0,_runtimevalidatorts.getRuntimeValidationErrors)(narrowedSupResolved,data),"$sup"));runtimeErrors.push(...this.prefixRuntimeErrors(await (0,_constraintvalidatorts.validateSchemaConstraints)(narrowedSubResolved,data,this.constraintValidators),"$sub"));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\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} from \"./types.ts\";\nimport { deepEqual, isPlainObj } from \"./utils.ts\";\n\n// ─── Re-exports ──────────────────────────────────────────────────────────────\n\nexport type {\n\tSchemaError,\n\tSubsetResult,\n\tResolvedConditionResult,\n\tResolvedSubsetResult,\n\tCheckRuntimeOptions,\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: true` is set in options, two additional runtime steps\n\t * run **after** the static check passes:\n\t * 4. `data` is validated against both resolved schemas via AJV\n\t * 5. Custom constraints are validated against `data`\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): 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 | ResolvedSubsetResult {\n\t\t// ── Runtime-aware path ──\n\t\tif (options) {\n\t\t\tconst data = options.data;\n\t\t\tconst shouldValidate = options.validate === true;\n\n\t\t\t// resolveConditions expects Record<string, unknown> for property access;\n\t\t\t// coerce non-object / undefined data to empty object so conditions\n\t\t\t// are always resolved (v1.0.11 compat: subData: undefined → {})\n\t\t\tconst dataForConditions: Record<string, unknown> = isPlainObj(data)\n\t\t\t\t? data\n\t\t\t\t: {};\n\n\t\t\tconst resolvedSub = resolveConditions(\n\t\t\t\tsub as JSONSchema7,\n\t\t\t\tdataForConditions,\n\t\t\t\tthis.engine,\n\t\t\t);\n\t\t\tconst resolvedSup = resolveConditions(\n\t\t\t\tsup as JSONSchema7,\n\t\t\t\tdataForConditions,\n\t\t\t\tthis.engine,\n\t\t\t);\n\n\t\t\t// ── Runtime-aware data narrowing ──\n\t\t\t// Apply narrowing only when concrete data is available.\n\t\t\t// When data is undefined there is nothing to narrow with.\n\t\t\t// Boolean schemas (true/false) cannot be narrowed — skip narrowing\n\t\t\t// to avoid passing a non-object to narrowSchemaWithData.\n\t\t\tconst canNarrow = data !== undefined;\n\t\t\tconst canNarrowSub = canNarrow && isPlainObj(resolvedSub.resolved);\n\t\t\tconst canNarrowSup = canNarrow && isPlainObj(resolvedSup.resolved);\n\n\t\t\tconst narrowedSubResolved = canNarrowSub\n\t\t\t\t? narrowSchemaWithData(resolvedSub.resolved, data, resolvedSup.resolved)\n\t\t\t\t: resolvedSub.resolved;\n\n\t\t\tconst narrowedSupResolved = canNarrowSup\n\t\t\t\t? narrowSchemaWithData(resolvedSup.resolved, data, resolvedSub.resolved)\n\t\t\t\t: resolvedSup.resolved;\n\n\t\t\t// ── Static subset check ──\n\t\t\t// Structural incompatibilities are schema-level problems — they are\n\t\t\t// permanent regardless of the concrete data. Run this before runtime\n\t\t\t// validation so that static errors always surface with higher priority.\n\t\t\tconst staticResult = this.checkInternal(\n\t\t\t\tnarrowedSubResolved,\n\t\t\t\tnarrowedSupResolved,\n\t\t\t);\n\n\t\t\tif (!staticResult.isSubset) {\n\t\t\t\treturn {\n\t\t\t\t\t...staticResult,\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\n\t\t\t// ── Runtime validation (opt-in) ──\n\t\t\t// Only runs when `validate: true` is explicitly set.\n\t\t\t// Validates the concrete data against both resolved/narrowed schemas\n\t\t\t// via AJV, then runs custom constraint validators if registered.\n\t\t\tif (shouldValidate && data !== undefined) {\n\t\t\t\tconst runtimeErrors: SchemaError[] = [];\n\n\t\t\t\truntimeErrors.push(\n\t\t\t\t\t...this.prefixRuntimeErrors(\n\t\t\t\t\t\tgetRuntimeValidationErrors(narrowedSubResolved, data),\n\t\t\t\t\t\t\"$sub\",\n\t\t\t\t\t),\n\t\t\t\t);\n\n\t\t\t\truntimeErrors.push(\n\t\t\t\t\t...this.prefixRuntimeErrors(\n\t\t\t\t\t\tgetRuntimeValidationErrors(narrowedSupResolved, data),\n\t\t\t\t\t\t\"$sup\",\n\t\t\t\t\t),\n\t\t\t\t);\n\n\t\t\t\t// ── Constraint validation ──\n\t\t\t\t// Validate runtime data against custom constraints in both schemas.\n\t\t\t\t// Always runs when validate: true — if a schema declares constraints\n\t\t\t\t// that are not registered in the registry, validateSchemaConstraints\n\t\t\t\t// will report them as \"unknown constraint (not registered)\" errors.\n\t\t\t\truntimeErrors.push(\n\t\t\t\t\t...this.prefixRuntimeErrors(\n\t\t\t\t\t\tvalidateSchemaConstraints(\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\n\t\t\t\truntimeErrors.push(\n\t\t\t\t\t...this.prefixRuntimeErrors(\n\t\t\t\t\t\tvalidateSchemaConstraints(\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\n\t\t\t\tif (runtimeErrors.length > 0) {\n\t\t\t\t\treturn {\n\t\t\t\t\t\tisSubset: false,\n\t\t\t\t\t\tmerged: null,\n\t\t\t\t\t\terrors: runtimeErrors,\n\t\t\t\t\t\tresolvedSub: { ...resolvedSub, resolved: narrowedSubResolved },\n\t\t\t\t\t\tresolvedSup: { ...resolvedSup, resolved: narrowedSupResolved },\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t}\n\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// ── 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\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","data","shouldValidate","validate","dataForConditions","isPlainObj","resolvedSub","resolvedSup","canNarrow","undefined","canNarrowSub","resolved","canNarrowSup","narrowedSubResolved","narrowSchemaWithData","narrowedSupResolved","staticResult","checkInternal","runtimeErrors","push","prefixRuntimeErrors","getRuntimeValidationErrors","validateSchemaConstraints","constraintValidators","merged","errors","isEqual","a","b","intersect","nA","nB","merge","def","label","result","schema","rootKey","map","error","key","type","subBranchType","supBranches","supBranchType","checkBranchedSub","checkBranchedSup","checkAtomic","clearCache","clearAllValidatorCaches","constraints"],"mappings":"mPA8EaA,wCAAAA,oCA3BZC,qBAAAA,0BAAW,MAEXC,+BAAAA,sCAAqB,MAHrBC,sBAAAA,yBAAY,MAEZC,yBAAAA,gCAAe,MAEfC,0BAAAA,iCAAgB,MANhBC,mBAAAA,uBAAS,MACTC,2BAAAA,sCAAiB,uCAhDgB,gEACQ,4DACL,kDACR,+CACD,iDACF,kDAKnB,yDAIA,yDAQA,8CAU+B,kMA6C/B,MAAMP,+BAkBZQ,SAASC,GAA0B,CAAEC,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sBAAiBuB,uBAAjB,KAAA,GACA,sBAAiBzB,SAAjB,KAAA,EAGC,CAAA,IAAI,CAACA,MAAM,CAAG,IAAIpB,0BAAW,AAC7B,CAAA,IAAI,CAAC6C,oBAAoB,CAAGvB,SAASkD,aAAe,CAAC,CACtD,CA4XD"}
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\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} from \"./types.ts\";\nimport { deepEqual, isPlainObj } from \"./utils.ts\";\n\n// ─── Re-exports ──────────────────────────────────────────────────────────────\n\nexport type {\n\tSchemaError,\n\tSubsetResult,\n\tResolvedConditionResult,\n\tResolvedSubsetResult,\n\tCheckRuntimeOptions,\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: true` is set in options, two additional runtime steps\n\t * run **after** the static check passes:\n\t * 4. `data` is validated against both resolved schemas via AJV\n\t * 5. Custom constraints are validated against `data`\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 shouldValidate = options.validate === true;\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// Only runs when `validate: true` is explicitly set.\n\t\t// Validates the concrete data against both resolved/narrowed schemas\n\t\t// via AJV, then runs custom constraint validators if registered.\n\t\tif (shouldValidate && data !== undefined) {\n\t\t\tconst runtimeErrors: SchemaError[] = [];\n\n\t\t\truntimeErrors.push(\n\t\t\t\t...this.prefixRuntimeErrors(\n\t\t\t\t\tgetRuntimeValidationErrors(narrowedSubResolved, data),\n\t\t\t\t\t\"$sub\",\n\t\t\t\t),\n\t\t\t);\n\n\t\t\truntimeErrors.push(\n\t\t\t\t...this.prefixRuntimeErrors(\n\t\t\t\t\tgetRuntimeValidationErrors(narrowedSupResolved, data),\n\t\t\t\t\t\"$sup\",\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 both schemas.\n\t\t\t// Always runs when validate: true — if a schema declares constraints\n\t\t\t// that are not registered in the registry, validateSchemaConstraints\n\t\t\t// will report them as \"unknown constraint (not registered)\" errors.\n\t\t\t// Constraint validators may be async, so we await the results.\n\t\t\truntimeErrors.push(\n\t\t\t\t...this.prefixRuntimeErrors(\n\t\t\t\t\tawait validateSchemaConstraints(\n\t\t\t\t\t\tnarrowedSubResolved,\n\t\t\t\t\t\tdata,\n\t\t\t\t\t\tthis.constraintValidators,\n\t\t\t\t\t),\n\t\t\t\t\t\"$sub\",\n\t\t\t\t),\n\t\t\t);\n\n\t\t\truntimeErrors.push(\n\t\t\t\t...this.prefixRuntimeErrors(\n\t\t\t\t\tawait validateSchemaConstraints(\n\t\t\t\t\t\tnarrowedSupResolved,\n\t\t\t\t\t\tdata,\n\t\t\t\t\t\tthis.constraintValidators,\n\t\t\t\t\t),\n\t\t\t\t\t\"$sup\",\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","shouldValidate","validate","dataForConditions","isPlainObj","resolvedSub","resolvedSup","canNarrow","undefined","canNarrowSub","resolved","canNarrowSup","narrowedSubResolved","narrowSchemaWithData","narrowedSupResolved","staticResult","runtimeErrors","push","prefixRuntimeErrors","getRuntimeValidationErrors","validateSchemaConstraints","constraintValidators","errors","rootKey","map","error","key","type","subBranchType","supBranches","supBranchType","checkBranchedSub","checkBranchedSup","checkAtomic","clearCache","clearAllValidatorCaches","constraints"],"mappings":"mPA8EaA,wCAAAA,oCA3BZC,qBAAAA,0BAAW,MAEXC,+BAAAA,sCAAqB,MAHrBC,sBAAAA,yBAAY,MAEZC,yBAAAA,gCAAe,MAEfC,0BAAAA,iCAAgB,MANhBC,mBAAAA,uBAAS,MACTC,2BAAAA,sCAAiB,uCAhDgB,gEACQ,4DACL,kDACR,+CACD,iDACF,kDAKnB,yDAIA,yDAQA,8CAU+B,kMA6C/B,MAAMP,+BAkBZQ,SAASC,GAA0B,CAAEC,GAA0B,CAAW,CAIzE,GAAID,MAAQC,IAAK,OAAO,KAOxB,GAAIC,GAAAA,kBAAS,EAACF,IAAKC,KAAM,OAAO,KAEhC,MAAME,KAAON,GAAAA,uBAAS,EAACG,KACvB,MAAMI,KAAOP,GAAAA,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AAiBtC,SAAjB,KAAA,EAGC,CAAA,IAAI,CAACA,MAAM,CAAG,IAAIpB,0BAAW,AAC7B,CAAA,IAAI,CAAC0D,oBAAoB,CAAGpC,SAASmD,aAAe,CAAC,CACtD,CA0YD"}
@@ -90,27 +90,34 @@ export interface ConstraintValidationResult {
90
90
  * Receives the value to validate and optional params defined
91
91
  * in the schema's constraint definition.
92
92
  *
93
- * Must be synchronous async validation is out of scope
94
- * for this library. Wrap async checks in your application layer.
93
+ * Can be synchronous or asynchronous. When async validators are used,
94
+ * `check()` with runtime options returns a `Promise`.
95
95
  *
96
96
  * @param value - The runtime value to validate
97
97
  * @param params - The `params` object from the constraint definition, if any
98
- * @returns The validation result
98
+ * @returns The validation result, or a Promise resolving to it
99
99
  *
100
100
  * @example
101
101
  * ```ts
102
+ * // Synchronous validator
102
103
  * const isUuid: ConstraintValidator = (value) => ({
103
104
  * valid: typeof value === "string" && /^[0-9a-f]{8}-/.test(value),
104
105
  * message: "Value must be a valid UUID",
105
106
  * });
106
107
  *
108
+ * // Async validator
109
+ * const isUniqueEmail: ConstraintValidator = async (value) => ({
110
+ * valid: await checkEmailUniqueness(value as string),
111
+ * message: "Email must be unique",
112
+ * });
113
+ *
107
114
  * const minAge: ConstraintValidator = (value, params) => ({
108
115
  * valid: typeof value === "number" && value >= (params?.min ?? 0),
109
116
  * message: `Value must be at least ${params?.min}`,
110
117
  * });
111
118
  * ```
112
119
  */
113
- export type ConstraintValidator = (value: unknown, params?: Record<string, unknown>) => ConstraintValidationResult;
120
+ export type ConstraintValidator = (value: unknown, params?: Record<string, unknown>) => ConstraintValidationResult | Promise<ConstraintValidationResult>;
114
121
  /**
115
122
  * Registry mapping constraint names to their validator functions.
116
123
  *
@@ -18,4 +18,4 @@ import type { ConstraintValidatorRegistry, SchemaError } from "./types.js";
18
18
  * @param path - The current property path (for error reporting)
19
19
  * @returns Array of schema errors (empty if all constraints pass)
20
20
  */
21
- export declare function validateSchemaConstraints(schema: JSONSchema7Definition, data: unknown, registry: ConstraintValidatorRegistry, path?: string): SchemaError[];
21
+ export declare function validateSchemaConstraints(schema: JSONSchema7Definition, data: unknown, registry: ConstraintValidatorRegistry, path?: string): Promise<SchemaError[]>;
@@ -1,2 +1,2 @@
1
- import{hasOwn,isPlainObj,toConstraintArray}from"./utils.js";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=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}export function validateSchemaConstraints(schema,data,registry,path=""){if(typeof schema==="boolean")return[];const errors=[];const constraints=toConstraintArray(schema.constraints);if(constraints.length>0){errors.push(...validateValue(constraints,data,registry,path))}if(isPlainObj(schema.properties)&&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&&!hasOwn(dataObj,key))continue;const propPath=path?`${path}.${key}`:key;errors.push(...validateSchemaConstraints(propSchema,propValue,registry,propPath))}}if(isPlainObj(schema.items)&&Array.isArray(data)){const itemSchema=schema.items;const itemPath=path?`${path}[]`:"[]";for(let i=0;i<data.length;i++){errors.push(...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(...validateSchemaConstraints(itemSchema,data[i],registry,itemPath))}}if(isPlainObj(schema.patternProperties)&&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(...validateSchemaConstraints(patternSchema,dataValue,registry,ppPath))}}}if(isPlainObj(schema.additionalProperties)&&typeof schema.additionalProperties!=="boolean"&&isPlainObj(data)){const apSchema=schema.additionalProperties;const dataObj=data;const definedProps=isPlainObj(schema.properties)?new Set(Object.keys(schema.properties)):new Set;const ppPatterns=[];if(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(...validateSchemaConstraints(apSchema,dataValue,registry,apPath))}}if(isPlainObj(schema.dependencies)&&isPlainObj(data)){const deps=schema.dependencies;const dataObj=data;for(const depKey of Object.keys(deps)){if(!hasOwn(dataObj,depKey))continue;const depValue=deps[depKey];if(depValue===undefined)continue;if(Array.isArray(depValue))continue;if(typeof depValue==="boolean")continue;errors.push(...validateSchemaConstraints(depValue,data,registry,path))}}return errors}
1
+ import{hasOwn,isPlainObj,toConstraintArray}from"./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}export async function validateSchemaConstraints(schema,data,registry,path=""){if(typeof schema==="boolean")return[];const errors=[];const constraints=toConstraintArray(schema.constraints);if(constraints.length>0){errors.push(...await validateValue(constraints,data,registry,path))}if(isPlainObj(schema.properties)&&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&&!hasOwn(dataObj,key))continue;const propPath=path?`${path}.${key}`:key;errors.push(...await validateSchemaConstraints(propSchema,propValue,registry,propPath))}}if(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(isPlainObj(schema.patternProperties)&&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(isPlainObj(schema.additionalProperties)&&typeof schema.additionalProperties!=="boolean"&&isPlainObj(data)){const apSchema=schema.additionalProperties;const dataObj=data;const definedProps=isPlainObj(schema.properties)?new Set(Object.keys(schema.properties)):new Set;const ppPatterns=[];if(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(isPlainObj(schema.dependencies)&&isPlainObj(data)){const deps=schema.dependencies;const dataObj=data;for(const depKey of Object.keys(deps)){if(!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 */\nfunction validateValue(\n\tconstraints: Constraint[],\n\tvalue: unknown,\n\tregistry: ConstraintValidatorRegistry,\n\tpath: string,\n): 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 = 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 function validateSchemaConstraints(\n\tschema: JSONSchema7Definition,\n\tdata: unknown,\n\tregistry: ConstraintValidatorRegistry,\n\tpath = \"\",\n): 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(...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...validateSchemaConstraints(propSchema, propValue, registry, propPath),\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...validateSchemaConstraints(itemSchema, data[i], registry, itemPath),\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...validateSchemaConstraints(itemSchema, data[i], registry, itemPath),\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...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...validateSchemaConstraints(apSchema, dataValue, registry, apPath),\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(...validateSchemaConstraints(depValue, data, registry, path));\n\t\t}\n\t}\n\n\treturn errors;\n}\n"],"names":["hasOwn","isPlainObj","toConstraintArray","validateValue","constraints","value","registry","path","errors","constraint","name","params","undefined","validator","push","key","expected","received","result","valid","message","err","Error","validateSchemaConstraints","schema","data","length","properties","props","dataObj","Object","keys","propSchema","propValue","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":"AAMA,OAASA,MAAM,CAAEC,UAAU,CAAEC,iBAAiB,KAAQ,YAAa,CAmBnE,SAASC,cACRC,WAAyB,CACzBC,KAAc,CACdC,QAAqC,CACrCC,IAAY,EAEZ,MAAMC,OAAwB,EAAE,CAEhC,IAA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AAYrB,OAAO,CAACmB,QAAQ,CAClC,MAAMY,OAASrD,KAAO,CAAC,EAAEA,KAAK,CAAC,EAAEyC,QAAQ,CAAC,CAAGA,QAC7CxC,OAAOM,IAAI,IACPS,0BAA0B8B,SAAUH,UAAW5C,SAAUsD,QAE9D,CACD,CAGA,GAAI3D,WAAWuB,OAAOqC,YAAY,GAAK5D,WAAWwB,MAAO,CACxD,MAAMqC,KAAOtC,OAAOqC,YAAY,CAIhC,MAAMhC,QAAUJ,KAEhB,IAAK,MAAMsC,UAAUjC,OAAOC,IAAI,CAAC+B,MAAO,CAEvC,GAAI,CAAC9D,OAAO6B,QAASkC,QAAS,SAE9B,MAAMC,SAAWF,IAAI,CAACC,OAAO,CAC7B,GAAIC,WAAapD,UAAW,SAG5B,GAAIwB,MAAMC,OAAO,CAAC2B,UAAW,SAG7B,GAAI,OAAOA,WAAa,UAAW,SAInCxD,OAAOM,IAAI,IAAIS,0BAA0ByC,SAAUvC,KAAMnB,SAAUC,MACpE,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 { 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":["hasOwn","isPlainObj","toConstraintArray","validateValue","constraints","value","registry","path","errors","constraint","name","params","undefined","validator","push","key","expected","received","result","valid","message","err","Error","validateSchemaConstraints","schema","data","length","properties","props","dataObj","Object","keys","propSchema","propValue","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":"AAMA,OAASA,MAAM,CAAEC,UAAU,CAAEC,iBAAiB,KAAQ,YAAa,CAmBnE,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,QACtC,GAAI,CAACO,OAAOC,KAAK,CAAE,CAClBX,OAAOM,IAAI,CAAC,CACXC,IAAKR,MAAQ,QACbS,SAAU,CAAC,YAAY,EAAEN,KAAK,CAAC,CAC/BO,SAAUC,OAAOE,OAAO,EAAI,8BAC7B,EACD,CACD,CAAE,MAAOC,IAAK,CACbb,OAAOM,IAAI,CAAC,CACXC,IAAKR,MAAQ,QACbS,SAAU,CAAC,YAAY,EAAEN,KAAK,CA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"}
@@ -53,7 +53,7 @@ export declare class JsonSchemaCompatibilityChecker {
53
53
  * checker.check(sub, sup, { data: { kind: "text", value: "hello" }, validate: true });
54
54
  * ```
55
55
  */
56
- check(sub: JSONSchema7Definition, sup: JSONSchema7Definition, options: CheckRuntimeOptions): ResolvedSubsetResult;
56
+ check(sub: JSONSchema7Definition, sup: JSONSchema7Definition, options: CheckRuntimeOptions): Promise<ResolvedSubsetResult>;
57
57
  check(sub: JSONSchema7Definition, sup: JSONSchema7Definition): SubsetResult;
58
58
  /**
59
59
  * Checks structural equality between two schemas.
@@ -85,6 +85,12 @@ export declare class JsonSchemaCompatibilityChecker {
85
85
  * @returns The resolved schema with branch info and discriminants
86
86
  */
87
87
  resolveConditions(schema: JSONSchema7, data: Record<string, unknown>): ResolvedConditionResult;
88
+ /**
89
+ * Internal runtime-aware check logic. Extracted as an async method
90
+ * so that `check()` without options stays synchronous while the
91
+ * runtime path can `await` async constraint validators.
92
+ */
93
+ private checkWithOptions;
88
94
  private prefixRuntimeErrors;
89
95
  /**
90
96
  * Internal check logic without condition resolution.
@@ -1,2 +1,2 @@
1
- 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}import{resolveConditions}from"./condition-resolver.js";import{validateSchemaConstraints}from"./constraint-validator.js";import{narrowSchemaWithData}from"./data-narrowing.js";import{formatResult}from"./formatter.js";import{MergeEngine}from"./merge-engine.js";import{normalize}from"./normalizer.js";import{arePatternsEquivalent,isPatternSubset,isTrivialPattern}from"./pattern-subset.js";import{clearAllValidatorCaches,getRuntimeValidationErrors}from"./runtime-validator.js";import{checkAtomic,checkBranchedSub,checkBranchedSup,getBranchesTyped,isAtomicSubsetOf}from"./subset-checker.js";import{deepEqual,isPlainObj}from"./utils.js";export{normalize,resolveConditions,formatResult,MergeEngine,isPatternSubset,arePatternsEquivalent,isTrivialPattern};export class JsonSchemaCompatibilityChecker{isSubset(sub,sup){if(sub===sup)return true;if(deepEqual(sub,sup))return true;const nSub=normalize(sub);const nSup=normalize(sup);if(nSub!==sub&&nSup!==sup&&deepEqual(nSub,nSup))return true;if(nSub!==nSup&&deepEqual(nSub,nSup))return true;const{branches:subBranches}=getBranchesTyped(nSub);if(subBranches.length>1||subBranches[0]!==nSub){return subBranches.every(branch=>isAtomicSubsetOf(branch,nSup,this.engine))}return isAtomicSubsetOf(nSub,nSup,this.engine)}check(sub,sup,options){if(options){const data=options.data;const shouldValidate=options.validate===true;const dataForConditions=isPlainObj(data)?data:{};const resolvedSub=resolveConditions(sub,dataForConditions,this.engine);const resolvedSup=resolveConditions(sup,dataForConditions,this.engine);const canNarrow=data!==undefined;const canNarrowSub=canNarrow&&isPlainObj(resolvedSub.resolved);const canNarrowSup=canNarrow&&isPlainObj(resolvedSup.resolved);const narrowedSubResolved=canNarrowSub?narrowSchemaWithData(resolvedSub.resolved,data,resolvedSup.resolved):resolvedSub.resolved;const narrowedSupResolved=canNarrowSup?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(shouldValidate&&data!==undefined){const runtimeErrors=[];runtimeErrors.push(...this.prefixRuntimeErrors(getRuntimeValidationErrors(narrowedSubResolved,data),"$sub"));runtimeErrors.push(...this.prefixRuntimeErrors(getRuntimeValidationErrors(narrowedSupResolved,data),"$sup"));runtimeErrors.push(...this.prefixRuntimeErrors(validateSchemaConstraints(narrowedSubResolved,data,this.constraintValidators),"$sub"));runtimeErrors.push(...this.prefixRuntimeErrors(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}}}return this.checkInternal(sub,sup)}isEqual(a,b){return this.engine.isEqual(normalize(a),normalize(b))}intersect(a,b){if(a===b||deepEqual(a,b))return normalize(a);const nA=normalize(a);const nB=normalize(b);if(deepEqual(nA,nB))return nA;const merged=this.engine.merge(nA,nB);if(merged===null)return null;if(deepEqual(merged,nA)||deepEqual(merged,nB))return merged;return normalize(merged)}normalize(def){return normalize(def)}formatResult(label,result){return formatResult(label,result)}resolveConditions(schema,data){return resolveConditions(schema,data,this.engine)}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(deepEqual(sub,sup)){return{isSubset:true,merged:sub,errors:[]}}const nSub=normalize(sub);const nSup=normalize(sup);if(deepEqual(nSub,nSup)){return{isSubset:true,merged:nSub,errors:[]}}const{branches:subBranches,type:subBranchType}=getBranchesTyped(nSub);const{branches:supBranches,type:supBranchType}=getBranchesTyped(nSup);if(subBranches.length>1||subBranches[0]!==nSub){return checkBranchedSub(subBranches,nSup,this.engine,subBranchType)}if(supBranches.length>1||supBranches[0]!==nSup){return checkBranchedSup(nSub,supBranches,this.engine,supBranchType)}return checkAtomic(nSub,nSup,this.engine)}static clearCache(){clearAllValidatorCaches()}constructor(options){_define_property(this,"constraintValidators",void 0);_define_property(this,"engine",void 0);this.engine=new MergeEngine;this.constraintValidators=options?.constraints??{}}}
1
+ 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}import{resolveConditions}from"./condition-resolver.js";import{validateSchemaConstraints}from"./constraint-validator.js";import{narrowSchemaWithData}from"./data-narrowing.js";import{formatResult}from"./formatter.js";import{MergeEngine}from"./merge-engine.js";import{normalize}from"./normalizer.js";import{arePatternsEquivalent,isPatternSubset,isTrivialPattern}from"./pattern-subset.js";import{clearAllValidatorCaches,getRuntimeValidationErrors}from"./runtime-validator.js";import{checkAtomic,checkBranchedSub,checkBranchedSup,getBranchesTyped,isAtomicSubsetOf}from"./subset-checker.js";import{deepEqual,isPlainObj}from"./utils.js";export{normalize,resolveConditions,formatResult,MergeEngine,isPatternSubset,arePatternsEquivalent,isTrivialPattern};export class JsonSchemaCompatibilityChecker{isSubset(sub,sup){if(sub===sup)return true;if(deepEqual(sub,sup))return true;const nSub=normalize(sub);const nSup=normalize(sup);if(nSub!==sub&&nSup!==sup&&deepEqual(nSub,nSup))return true;if(nSub!==nSup&&deepEqual(nSub,nSup))return true;const{branches:subBranches}=getBranchesTyped(nSub);if(subBranches.length>1||subBranches[0]!==nSub){return subBranches.every(branch=>isAtomicSubsetOf(branch,nSup,this.engine))}return 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(normalize(a),normalize(b))}intersect(a,b){if(a===b||deepEqual(a,b))return normalize(a);const nA=normalize(a);const nB=normalize(b);if(deepEqual(nA,nB))return nA;const merged=this.engine.merge(nA,nB);if(merged===null)return null;if(deepEqual(merged,nA)||deepEqual(merged,nB))return merged;return normalize(merged)}normalize(def){return normalize(def)}formatResult(label,result){return formatResult(label,result)}resolveConditions(schema,data){return resolveConditions(schema,data,this.engine)}async checkWithOptions(sub,sup,options){const data=options.data;const shouldValidate=options.validate===true;const dataForConditions=isPlainObj(data)?data:{};const resolvedSub=resolveConditions(sub,dataForConditions,this.engine);const resolvedSup=resolveConditions(sup,dataForConditions,this.engine);const canNarrow=data!==undefined;const canNarrowSub=canNarrow&&isPlainObj(resolvedSub.resolved);const canNarrowSup=canNarrow&&isPlainObj(resolvedSup.resolved);const narrowedSubResolved=canNarrowSub?narrowSchemaWithData(resolvedSub.resolved,data,resolvedSup.resolved):resolvedSub.resolved;const narrowedSupResolved=canNarrowSup?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(shouldValidate&&data!==undefined){const runtimeErrors=[];runtimeErrors.push(...this.prefixRuntimeErrors(getRuntimeValidationErrors(narrowedSubResolved,data),"$sub"));runtimeErrors.push(...this.prefixRuntimeErrors(getRuntimeValidationErrors(narrowedSupResolved,data),"$sup"));runtimeErrors.push(...this.prefixRuntimeErrors(await validateSchemaConstraints(narrowedSubResolved,data,this.constraintValidators),"$sub"));runtimeErrors.push(...this.prefixRuntimeErrors(await 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(deepEqual(sub,sup)){return{isSubset:true,merged:sub,errors:[]}}const nSub=normalize(sub);const nSup=normalize(sup);if(deepEqual(nSub,nSup)){return{isSubset:true,merged:nSub,errors:[]}}const{branches:subBranches,type:subBranchType}=getBranchesTyped(nSub);const{branches:supBranches,type:supBranchType}=getBranchesTyped(nSup);if(subBranches.length>1||subBranches[0]!==nSub){return checkBranchedSub(subBranches,nSup,this.engine,subBranchType)}if(supBranches.length>1||supBranches[0]!==nSup){return checkBranchedSup(nSub,supBranches,this.engine,supBranchType)}return checkAtomic(nSub,nSup,this.engine)}static clearCache(){clearAllValidatorCaches()}constructor(options){_define_property(this,"constraintValidators",void 0);_define_property(this,"engine",void 0);this.engine=new 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\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} from \"./types.ts\";\nimport { deepEqual, isPlainObj } from \"./utils.ts\";\n\n// ─── Re-exports ──────────────────────────────────────────────────────────────\n\nexport type {\n\tSchemaError,\n\tSubsetResult,\n\tResolvedConditionResult,\n\tResolvedSubsetResult,\n\tCheckRuntimeOptions,\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: true` is set in options, two additional runtime steps\n\t * run **after** the static check passes:\n\t * 4. `data` is validated against both resolved schemas via AJV\n\t * 5. Custom constraints are validated against `data`\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): 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 | ResolvedSubsetResult {\n\t\t// ── Runtime-aware path ──\n\t\tif (options) {\n\t\t\tconst data = options.data;\n\t\t\tconst shouldValidate = options.validate === true;\n\n\t\t\t// resolveConditions expects Record<string, unknown> for property access;\n\t\t\t// coerce non-object / undefined data to empty object so conditions\n\t\t\t// are always resolved (v1.0.11 compat: subData: undefined → {})\n\t\t\tconst dataForConditions: Record<string, unknown> = isPlainObj(data)\n\t\t\t\t? data\n\t\t\t\t: {};\n\n\t\t\tconst resolvedSub = resolveConditions(\n\t\t\t\tsub as JSONSchema7,\n\t\t\t\tdataForConditions,\n\t\t\t\tthis.engine,\n\t\t\t);\n\t\t\tconst resolvedSup = resolveConditions(\n\t\t\t\tsup as JSONSchema7,\n\t\t\t\tdataForConditions,\n\t\t\t\tthis.engine,\n\t\t\t);\n\n\t\t\t// ── Runtime-aware data narrowing ──\n\t\t\t// Apply narrowing only when concrete data is available.\n\t\t\t// When data is undefined there is nothing to narrow with.\n\t\t\t// Boolean schemas (true/false) cannot be narrowed — skip narrowing\n\t\t\t// to avoid passing a non-object to narrowSchemaWithData.\n\t\t\tconst canNarrow = data !== undefined;\n\t\t\tconst canNarrowSub = canNarrow && isPlainObj(resolvedSub.resolved);\n\t\t\tconst canNarrowSup = canNarrow && isPlainObj(resolvedSup.resolved);\n\n\t\t\tconst narrowedSubResolved = canNarrowSub\n\t\t\t\t? narrowSchemaWithData(resolvedSub.resolved, data, resolvedSup.resolved)\n\t\t\t\t: resolvedSub.resolved;\n\n\t\t\tconst narrowedSupResolved = canNarrowSup\n\t\t\t\t? narrowSchemaWithData(resolvedSup.resolved, data, resolvedSub.resolved)\n\t\t\t\t: resolvedSup.resolved;\n\n\t\t\t// ── Static subset check ──\n\t\t\t// Structural incompatibilities are schema-level problems — they are\n\t\t\t// permanent regardless of the concrete data. Run this before runtime\n\t\t\t// validation so that static errors always surface with higher priority.\n\t\t\tconst staticResult = this.checkInternal(\n\t\t\t\tnarrowedSubResolved,\n\t\t\t\tnarrowedSupResolved,\n\t\t\t);\n\n\t\t\tif (!staticResult.isSubset) {\n\t\t\t\treturn {\n\t\t\t\t\t...staticResult,\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\n\t\t\t// ── Runtime validation (opt-in) ──\n\t\t\t// Only runs when `validate: true` is explicitly set.\n\t\t\t// Validates the concrete data against both resolved/narrowed schemas\n\t\t\t// via AJV, then runs custom constraint validators if registered.\n\t\t\tif (shouldValidate && data !== undefined) {\n\t\t\t\tconst runtimeErrors: SchemaError[] = [];\n\n\t\t\t\truntimeErrors.push(\n\t\t\t\t\t...this.prefixRuntimeErrors(\n\t\t\t\t\t\tgetRuntimeValidationErrors(narrowedSubResolved, data),\n\t\t\t\t\t\t\"$sub\",\n\t\t\t\t\t),\n\t\t\t\t);\n\n\t\t\t\truntimeErrors.push(\n\t\t\t\t\t...this.prefixRuntimeErrors(\n\t\t\t\t\t\tgetRuntimeValidationErrors(narrowedSupResolved, data),\n\t\t\t\t\t\t\"$sup\",\n\t\t\t\t\t),\n\t\t\t\t);\n\n\t\t\t\t// ── Constraint validation ──\n\t\t\t\t// Validate runtime data against custom constraints in both schemas.\n\t\t\t\t// Always runs when validate: true — if a schema declares constraints\n\t\t\t\t// that are not registered in the registry, validateSchemaConstraints\n\t\t\t\t// will report them as \"unknown constraint (not registered)\" errors.\n\t\t\t\truntimeErrors.push(\n\t\t\t\t\t...this.prefixRuntimeErrors(\n\t\t\t\t\t\tvalidateSchemaConstraints(\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\n\t\t\t\truntimeErrors.push(\n\t\t\t\t\t...this.prefixRuntimeErrors(\n\t\t\t\t\t\tvalidateSchemaConstraints(\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\n\t\t\t\tif (runtimeErrors.length > 0) {\n\t\t\t\t\treturn {\n\t\t\t\t\t\tisSubset: false,\n\t\t\t\t\t\tmerged: null,\n\t\t\t\t\t\terrors: runtimeErrors,\n\t\t\t\t\t\tresolvedSub: { ...resolvedSub, resolved: narrowedSubResolved },\n\t\t\t\t\t\tresolvedSup: { ...resolvedSup, resolved: narrowedSupResolved },\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t}\n\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// ── 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\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":["resolveConditions","validateSchemaConstraints","narrowSchemaWithData","formatResult","MergeEngine","normalize","arePatternsEquivalent","isPatternSubset","isTrivialPattern","clearAllValidatorCaches","getRuntimeValidationErrors","checkAtomic","checkBranchedSub","checkBranchedSup","getBranchesTyped","isAtomicSubsetOf","deepEqual","isPlainObj","JsonSchemaCompatibilityChecker","isSubset","sub","sup","nSub","nSup","branches","subBranches","length","every","branch","engine","check","options","data","shouldValidate","validate","dataForConditions","resolvedSub","resolvedSup","canNarrow","undefined","canNarrowSub","resolved","canNarrowSup","narrowedSubResolved","narrowedSupResolved","staticResult","checkInternal","runtimeErrors","push","prefixRuntimeErrors","constraintValidators","merged","errors","isEqual","a","b","intersect","nA","nB","merge","def","label","result","schema","rootKey","map","error","key","type","subBranchType","supBranches","supBranchType","clearCache","constraints"],"mappings":"oLACA,OAASA,iBAAiB,KAAQ,yBAA0B,AAC5D,QAASC,yBAAyB,KAAQ,2BAA4B,AACtE,QAASC,oBAAoB,KAAQ,qBAAsB,AAC3D,QAASC,YAAY,KAAQ,gBAAiB,AAC9C,QAASC,WAAW,KAAQ,mBAAoB,AAChD,QAASC,SAAS,KAAQ,iBAAkB,AAC5C,QACCC,qBAAqB,CACrBC,eAAe,CACfC,gBAAgB,KACV,qBAAsB,AAC7B,QACCC,uBAAuB,CACvBC,0BAA0B,KACpB,wBAAyB,AAEhC,QACCC,WAAW,CACXC,gBAAgB,CAChBC,gBAAgB,CAChBC,gBAAgB,CAChBC,gBAAgB,KACV,qBAAsB,AAU7B,QAASC,SAAS,CAAEC,UAAU,KAAQ,YAAa,AAcnD,QACCZ,SAAS,CACTL,iBAAiB,CACjBG,YAAY,CACZC,WAAW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B,IAAKgC,OAAQ,EAAE,AAAC,CAClD,CAEA,MAAM9B,KAAOjB,UAAUe,KACvB,MAAMG,KAAOlB,UAAUgB,KAIvB,GAAIL,UAAUM,KAAMC,MAAO,CAC1B,MAAO,CAAEJ,SAAU,KAAMgC,OAAQ7B,KAAM8B,OAAQ,EAAE,AAAC,CACnD,CAEA,KAAM,CAAE5B,SAAUC,WAAW,CAAE2C,KAAMC,aAAa,CAAE,CACnDvD,iBAAiBQ,MAClB,KAAM,CAAEE,SAAU8C,WAAW,CAAEF,KAAMG,aAAa,CAAE,CACnDzD,iBAAiBS,MAGlB,GAAIE,YAAYC,MAAM,CAAG,GAAKD,WAAW,CAAC,EAAE,GAAKH,KAAM,CACtD,OAAOV,iBAAiBa,YAAaF,KAAM,IAAI,CAACM,MAAM,CAAEwC,cACzD,CAGA,GAAIC,YAAY5C,MAAM,CAAG,GAAK4C,WAAW,CAAC,EAAE,GAAK/C,KAAM,CACtD,OAAOV,iBAAiBS,KAAMgD,YAAa,IAAI,CAACzC,MAAM,CAAE0C,cACzD,CAGA,OAAO5D,YAAYW,KAAMC,KAAM,IAAI,CAACM,MAAM,CAC3C,CAuBA,OAAO2C,YAAmB,CACzB/D,yBACD,CA9XA,YAAYsB,OAAwB,CAAE,CAHtC,sBAAiBmB,uBAAjB,KAAA,GACA,sBAAiBrB,SAAjB,KAAA,EAGC,CAAA,IAAI,CAACA,MAAM,CAAG,IAAIzB,WAClB,CAAA,IAAI,CAAC8C,oBAAoB,CAAGnB,SAAS0C,aAAe,CAAC,CACtD,CA4XD"}
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\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} from \"./types.ts\";\nimport { deepEqual, isPlainObj } from \"./utils.ts\";\n\n// ─── Re-exports ──────────────────────────────────────────────────────────────\n\nexport type {\n\tSchemaError,\n\tSubsetResult,\n\tResolvedConditionResult,\n\tResolvedSubsetResult,\n\tCheckRuntimeOptions,\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: true` is set in options, two additional runtime steps\n\t * run **after** the static check passes:\n\t * 4. `data` is validated against both resolved schemas via AJV\n\t * 5. Custom constraints are validated against `data`\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 shouldValidate = options.validate === true;\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// Only runs when `validate: true` is explicitly set.\n\t\t// Validates the concrete data against both resolved/narrowed schemas\n\t\t// via AJV, then runs custom constraint validators if registered.\n\t\tif (shouldValidate && data !== undefined) {\n\t\t\tconst runtimeErrors: SchemaError[] = [];\n\n\t\t\truntimeErrors.push(\n\t\t\t\t...this.prefixRuntimeErrors(\n\t\t\t\t\tgetRuntimeValidationErrors(narrowedSubResolved, data),\n\t\t\t\t\t\"$sub\",\n\t\t\t\t),\n\t\t\t);\n\n\t\t\truntimeErrors.push(\n\t\t\t\t...this.prefixRuntimeErrors(\n\t\t\t\t\tgetRuntimeValidationErrors(narrowedSupResolved, data),\n\t\t\t\t\t\"$sup\",\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 both schemas.\n\t\t\t// Always runs when validate: true — if a schema declares constraints\n\t\t\t// that are not registered in the registry, validateSchemaConstraints\n\t\t\t// will report them as \"unknown constraint (not registered)\" errors.\n\t\t\t// Constraint validators may be async, so we await the results.\n\t\t\truntimeErrors.push(\n\t\t\t\t...this.prefixRuntimeErrors(\n\t\t\t\t\tawait validateSchemaConstraints(\n\t\t\t\t\t\tnarrowedSubResolved,\n\t\t\t\t\t\tdata,\n\t\t\t\t\t\tthis.constraintValidators,\n\t\t\t\t\t),\n\t\t\t\t\t\"$sub\",\n\t\t\t\t),\n\t\t\t);\n\n\t\t\truntimeErrors.push(\n\t\t\t\t...this.prefixRuntimeErrors(\n\t\t\t\t\tawait validateSchemaConstraints(\n\t\t\t\t\t\tnarrowedSupResolved,\n\t\t\t\t\t\tdata,\n\t\t\t\t\t\tthis.constraintValidators,\n\t\t\t\t\t),\n\t\t\t\t\t\"$sup\",\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":["resolveConditions","validateSchemaConstraints","narrowSchemaWithData","formatResult","MergeEngine","normalize","arePatternsEquivalent","isPatternSubset","isTrivialPattern","clearAllValidatorCaches","getRuntimeValidationErrors","checkAtomic","checkBranchedSub","checkBranchedSup","getBranchesTyped","isAtomicSubsetOf","deepEqual","isPlainObj","JsonSchemaCompatibilityChecker","isSubset","sub","sup","nSub","nSup","branches","subBranches","length","every","branch","engine","check","options","checkWithOptions","checkInternal","isEqual","a","b","intersect","nA","nB","merged","merge","def","label","result","schema","data","shouldValidate","validate","dataForConditions","resolvedSub","resolvedSup","canNarrow","undefined","canNarrowSub","resolved","canNarrowSup","narrowedSubResolved","narrowedSupResolved","staticResult","runtimeErrors","push","prefixRuntimeErrors","constraintValidators","errors","rootKey","map","error","key","type","subBranchType","supBranches","supBranchType","clearCache","constraints"],"mappings":"oLACA,OAASA,iBAAiB,KAAQ,yBAA0B,AAC5D,QAASC,yBAAyB,KAAQ,2BAA4B,AACtE,QAASC,oBAAoB,KAAQ,qBAAsB,AAC3D,QAASC,YAAY,KAAQ,gBAAiB,AAC9C,QAASC,WAAW,KAAQ,mBAAoB,AAChD,QAASC,SAAS,KAAQ,iBAAkB,AAC5C,QACCC,qBAAqB,CACrBC,eAAe,CACfC,gBAAgB,KACV,qBAAsB,AAC7B,QACCC,uBAAuB,CACvBC,0BAA0B,KACpB,wBAAyB,AAEhC,QACCC,WAAW,CACXC,gBAAgB,CAChBC,gBAAgB,CAChBC,gBAAgB,CAChBC,gBAAgB,KACV,qBAAsB,AAU7B,QAASC,SAAS,CAAEC,UAAU,KAAQ,YAAa,AAcnD,QACCZ,SAAS,CACTL,iBAAiB,CACjBG,YAAY,CACZC,WAAW,CACXG,eAAe,CACfD,qBAAqB,CACrBE,gBAAgB,CACf,AAuBF,QAAO,MAAMU,+BAkBZC,SAASC,GAA0B,CAAEC,GAA0B,CAAW,CAIzE,GAAID,MAAQC,IAAK,OAAO,KAOxB,GAAIL,UAAUI,IAAKC,KAAM,OAAO,KAEhC,MAAMC,KAAOjB,UAAUe,KACvB,MAAMG,KAAOlB,UAAUgB,KAMvB,GAAIC,OAASF,KAAOG,OAASF,KAAOL,UAAUM,KAAMC,MAAO,OAAO,KAClE,GAAID,OAASC,MAAQP,UAAUM,KAAMC,MAAO,OAAO,KAEnD,KAAM,CAAEC,SAAUC,WAA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AE,CACnDxD,iBAAiBQ,MAClB,KAAM,CAAEE,SAAU+C,WAAW,CAAEF,KAAMG,aAAa,CAAE,CACnD1D,iBAAiBS,MAGlB,GAAIE,YAAYC,MAAM,CAAG,GAAKD,WAAW,CAAC,EAAE,GAAKH,KAAM,CACtD,OAAOV,iBAAiBa,YAAaF,KAAM,IAAI,CAACM,MAAM,CAAEyC,cACzD,CAGA,GAAIC,YAAY7C,MAAM,CAAG,GAAK6C,WAAW,CAAC,EAAE,GAAKhD,KAAM,CACtD,OAAOV,iBAAiBS,KAAMiD,YAAa,IAAI,CAAC1C,MAAM,CAAE2C,cACzD,CAGA,OAAO7D,YAAYW,KAAMC,KAAM,IAAI,CAACM,MAAM,CAC3C,CAuBA,OAAO4C,YAAmB,CACzBhE,yBACD,CA5YA,YAAYsB,OAAwB,CAAE,CAHtC,sBAAiBgC,uBAAjB,KAAA,GACA,sBAAiBlC,SAAjB,KAAA,EAGC,CAAA,IAAI,CAACA,MAAM,CAAG,IAAIzB,WAClB,CAAA,IAAI,CAAC2D,oBAAoB,CAAGhC,SAAS2C,aAAe,CAAC,CACtD,CA0YD"}
@@ -90,27 +90,34 @@ export interface ConstraintValidationResult {
90
90
  * Receives the value to validate and optional params defined
91
91
  * in the schema's constraint definition.
92
92
  *
93
- * Must be synchronous async validation is out of scope
94
- * for this library. Wrap async checks in your application layer.
93
+ * Can be synchronous or asynchronous. When async validators are used,
94
+ * `check()` with runtime options returns a `Promise`.
95
95
  *
96
96
  * @param value - The runtime value to validate
97
97
  * @param params - The `params` object from the constraint definition, if any
98
- * @returns The validation result
98
+ * @returns The validation result, or a Promise resolving to it
99
99
  *
100
100
  * @example
101
101
  * ```ts
102
+ * // Synchronous validator
102
103
  * const isUuid: ConstraintValidator = (value) => ({
103
104
  * valid: typeof value === "string" && /^[0-9a-f]{8}-/.test(value),
104
105
  * message: "Value must be a valid UUID",
105
106
  * });
106
107
  *
108
+ * // Async validator
109
+ * const isUniqueEmail: ConstraintValidator = async (value) => ({
110
+ * valid: await checkEmailUniqueness(value as string),
111
+ * message: "Email must be unique",
112
+ * });
113
+ *
107
114
  * const minAge: ConstraintValidator = (value, params) => ({
108
115
  * valid: typeof value === "number" && value >= (params?.min ?? 0),
109
116
  * message: `Value must be at least ${params?.min}`,
110
117
  * });
111
118
  * ```
112
119
  */
113
- export type ConstraintValidator = (value: unknown, params?: Record<string, unknown>) => ConstraintValidationResult;
120
+ export type ConstraintValidator = (value: unknown, params?: Record<string, unknown>) => ConstraintValidationResult | Promise<ConstraintValidationResult>;
114
121
  /**
115
122
  * Registry mapping constraint names to their validator functions.
116
123
  *
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/types.ts"],"sourcesContent":["import type { JSONSchema7, JSONSchema7Definition } from \"json-schema\";\n\n// ─── Module augmentation ─────────────────────────────────────────────────────\n// Extends JSONSchema7 with the custom `constraints` keyword so that consumers\n// of this package see the property on every JSONSchema7 without needing a\n// separate ambient file or `/// <reference>` directive.\n\ndeclare module \"json-schema\" {\n\tinterface JSONSchema7 {\n\t\tconstraints?: Constraints;\n\t}\n}\n\n// ─── Public types ────────────────────────────────────────────────────────────\n\nexport interface SchemaError {\n\t/** Normalized path to the concerned property (e.g. \"user.name\", \"users[].name\", \"accountId\") */\n\tkey: string;\n\t/** Type or value expected by the target schema (sup) */\n\texpected: string;\n\t/** Type or value received from the source schema (sub) */\n\treceived: string;\n}\n\nexport interface SubsetResult {\n\t/** true if sub ⊆ sup (every value valid for sub is also valid for sup) */\n\tisSubset: boolean;\n\t/** The schema resulting from the intersection allOf(sub, sup), or null if incompatible */\n\tmerged: JSONSchema7Definition | null;\n\t/** Semantic errors describing incompatibilities between the two schemas */\n\terrors: SchemaError[];\n}\n\n/**\n * Options for runtime-aware subset checking.\n *\n * When `data` is provided, the checker:\n * 1. Resolves `if/then/else` conditions in both `sub` and `sup` using `data`\n * (if `data` is `undefined`, conditions are resolved with `{}`)\n * 2. Narrows schemas using runtime values (e.g. enum materialization)\n * 3. Performs the static subset check on the resolved/narrowed schemas\n *\n * When `validate` is `true`, two additional runtime steps run **after** the\n * static check passes:\n * 4. `data` is validated against both resolved schemas via AJV\n * 5. Custom constraints are validated against `data`\n *\n * `data` can be a partial discriminant (e.g. `{ kind: \"text\" }`) used solely\n * for condition resolution and narrowing. It does **not** need to be a complete\n * instance of the schemas unless `validate: true` is set.\n */\nexport interface CheckRuntimeOptions {\n\t/** Runtime data used for condition resolution, narrowing, and optionally runtime validation */\n\tdata: unknown;\n\n\t/**\n\t * When `true`, enables runtime validation of `data` against both resolved\n\t * schemas via AJV, and custom constraint validation if a registry was\n\t * provided at construction time.\n\t *\n\t * When `false` or omitted (default), `data` is used only for condition\n\t * resolution (`if/then/else`) and schema narrowing — no AJV validation\n\t * or constraint validation is performed.\n\t *\n\t * @default false\n\t */\n\tvalidate?: boolean;\n}\n\n/**\n * Extended result from `check()` when runtime options are provided.\n * Includes resolution results for sub and sup in addition to the SubsetResult.\n */\nexport interface ResolvedSubsetResult extends SubsetResult {\n\tresolvedSub: ResolvedConditionResult;\n\tresolvedSup: ResolvedConditionResult;\n}\n\nexport interface ResolvedConditionResult {\n\t/** The schema with if/then/else resolved (flattened) */\n\tresolved: JSONSchema7;\n\t/** The branch that was applied (\"then\" | \"else\" | null if no condition) */\n\tbranch: \"then\" | \"else\" | null;\n\t/** The discriminant used for resolution */\n\tdiscriminant: Record<string, unknown>;\n}\n\nexport type Constraint =\n\t| string\n\t| {\n\t\t\tname: string;\n\t\t\tparams?: Record<string, unknown>;\n\t };\n\nexport type Constraints = Constraint | Constraint[];\n\n// ─── Constraint Validator types ──────────────────────────────────────────────\n\n/**\n * Result of a constraint validation.\n */\nexport interface ConstraintValidationResult {\n\t/** Whether the value satisfies the constraint */\n\tvalid: boolean;\n\t/** Human-readable message when `valid` is `false` */\n\tmessage?: string;\n}\n\n/**\n * A constraint validator function.\n *\n * Receives the value to validate and optional params defined\n * in the schema's constraint definition.\n *\n * Must be synchronous async validation is out of scope\n * for this library. Wrap async checks in your application layer.\n *\n * @param value - The runtime value to validate\n * @param params - The `params` object from the constraint definition, if any\n * @returns The validation result\n *\n * @example\n * ```ts\n * const isUuid: ConstraintValidator = (value) => ({\n * valid: typeof value === \"string\" && /^[0-9a-f]{8}-/.test(value),\n * message: \"Value must be a valid UUID\",\n * });\n *\n * const minAge: ConstraintValidator = (value, params) => ({\n * valid: typeof value === \"number\" && value >= (params?.min ?? 0),\n * message: `Value must be at least ${params?.min}`,\n * });\n * ```\n */\nexport type ConstraintValidator = (\n\tvalue: unknown,\n\tparams?: Record<string, unknown>,\n) => ConstraintValidationResult;\n\n/**\n * Registry mapping constraint names to their validator functions.\n *\n * Keys are constraint names as they appear in schema definitions\n * (e.g. `\"IsUuid\"`, `\"MinAge\"`).\n */\nexport type ConstraintValidatorRegistry = Record<string, ConstraintValidator>;\n\n/**\n * Options for the JsonSchemaCompatibilityChecker constructor.\n */\nexport interface CheckerOptions {\n\t/**\n\t * Registry of custom constraint validators.\n\t *\n\t * When provided, the checker can validate runtime data against\n\t * custom constraints defined in schemas via the `constraints` keyword.\n\t *\n\t * Constraint names must match those used in schema definitions.\n\t * Unknown constraints (present in a schema but absent from the registry)\n\t * will be reported as errors during runtime validation.\n\t */\n\tconstraints?: ConstraintValidatorRegistry;\n}\n"],"names":[],"mappings":"AAsJA,QAYC"}
1
+ {"version":3,"sources":["../../src/types.ts"],"sourcesContent":["import type { JSONSchema7, JSONSchema7Definition } from \"json-schema\";\n\n// ─── Module augmentation ─────────────────────────────────────────────────────\n// Extends JSONSchema7 with the custom `constraints` keyword so that consumers\n// of this package see the property on every JSONSchema7 without needing a\n// separate ambient file or `/// <reference>` directive.\n\ndeclare module \"json-schema\" {\n\tinterface JSONSchema7 {\n\t\tconstraints?: Constraints;\n\t}\n}\n\n// ─── Public types ────────────────────────────────────────────────────────────\n\nexport interface SchemaError {\n\t/** Normalized path to the concerned property (e.g. \"user.name\", \"users[].name\", \"accountId\") */\n\tkey: string;\n\t/** Type or value expected by the target schema (sup) */\n\texpected: string;\n\t/** Type or value received from the source schema (sub) */\n\treceived: string;\n}\n\nexport interface SubsetResult {\n\t/** true if sub ⊆ sup (every value valid for sub is also valid for sup) */\n\tisSubset: boolean;\n\t/** The schema resulting from the intersection allOf(sub, sup), or null if incompatible */\n\tmerged: JSONSchema7Definition | null;\n\t/** Semantic errors describing incompatibilities between the two schemas */\n\terrors: SchemaError[];\n}\n\n/**\n * Options for runtime-aware subset checking.\n *\n * When `data` is provided, the checker:\n * 1. Resolves `if/then/else` conditions in both `sub` and `sup` using `data`\n * (if `data` is `undefined`, conditions are resolved with `{}`)\n * 2. Narrows schemas using runtime values (e.g. enum materialization)\n * 3. Performs the static subset check on the resolved/narrowed schemas\n *\n * When `validate` is `true`, two additional runtime steps run **after** the\n * static check passes:\n * 4. `data` is validated against both resolved schemas via AJV\n * 5. Custom constraints are validated against `data`\n *\n * `data` can be a partial discriminant (e.g. `{ kind: \"text\" }`) used solely\n * for condition resolution and narrowing. It does **not** need to be a complete\n * instance of the schemas unless `validate: true` is set.\n */\nexport interface CheckRuntimeOptions {\n\t/** Runtime data used for condition resolution, narrowing, and optionally runtime validation */\n\tdata: unknown;\n\n\t/**\n\t * When `true`, enables runtime validation of `data` against both resolved\n\t * schemas via AJV, and custom constraint validation if a registry was\n\t * provided at construction time.\n\t *\n\t * When `false` or omitted (default), `data` is used only for condition\n\t * resolution (`if/then/else`) and schema narrowing — no AJV validation\n\t * or constraint validation is performed.\n\t *\n\t * @default false\n\t */\n\tvalidate?: boolean;\n}\n\n/**\n * Extended result from `check()` when runtime options are provided.\n * Includes resolution results for sub and sup in addition to the SubsetResult.\n */\nexport interface ResolvedSubsetResult extends SubsetResult {\n\tresolvedSub: ResolvedConditionResult;\n\tresolvedSup: ResolvedConditionResult;\n}\n\nexport interface ResolvedConditionResult {\n\t/** The schema with if/then/else resolved (flattened) */\n\tresolved: JSONSchema7;\n\t/** The branch that was applied (\"then\" | \"else\" | null if no condition) */\n\tbranch: \"then\" | \"else\" | null;\n\t/** The discriminant used for resolution */\n\tdiscriminant: Record<string, unknown>;\n}\n\nexport type Constraint =\n\t| string\n\t| {\n\t\t\tname: string;\n\t\t\tparams?: Record<string, unknown>;\n\t };\n\nexport type Constraints = Constraint | Constraint[];\n\n// ─── Constraint Validator types ──────────────────────────────────────────────\n\n/**\n * Result of a constraint validation.\n */\nexport interface ConstraintValidationResult {\n\t/** Whether the value satisfies the constraint */\n\tvalid: boolean;\n\t/** Human-readable message when `valid` is `false` */\n\tmessage?: string;\n}\n\n/**\n * A constraint validator function.\n *\n * Receives the value to validate and optional params defined\n * in the schema's constraint definition.\n *\n * Can be synchronous or asynchronous. When async validators are used,\n * `check()` with runtime options returns a `Promise`.\n *\n * @param value - The runtime value to validate\n * @param params - The `params` object from the constraint definition, if any\n * @returns The validation result, or a Promise resolving to it\n *\n * @example\n * ```ts\n * // Synchronous validator\n * const isUuid: ConstraintValidator = (value) => ({\n * valid: typeof value === \"string\" && /^[0-9a-f]{8}-/.test(value),\n * message: \"Value must be a valid UUID\",\n * });\n *\n * // Async validator\n * const isUniqueEmail: ConstraintValidator = async (value) => ({\n * valid: await checkEmailUniqueness(value as string),\n * message: \"Email must be unique\",\n * });\n *\n * const minAge: ConstraintValidator = (value, params) => ({\n * valid: typeof value === \"number\" && value >= (params?.min ?? 0),\n * message: `Value must be at least ${params?.min}`,\n * });\n * ```\n */\nexport type ConstraintValidator = (\n\tvalue: unknown,\n\tparams?: Record<string, unknown>,\n) => ConstraintValidationResult | Promise<ConstraintValidationResult>;\n\n/**\n * Registry mapping constraint names to their validator functions.\n *\n * Keys are constraint names as they appear in schema definitions\n * (e.g. `\"IsUuid\"`, `\"MinAge\"`).\n */\nexport type ConstraintValidatorRegistry = Record<string, ConstraintValidator>;\n\n/**\n * Options for the JsonSchemaCompatibilityChecker constructor.\n */\nexport interface CheckerOptions {\n\t/**\n\t * Registry of custom constraint validators.\n\t *\n\t * When provided, the checker can validate runtime data against\n\t * custom constraints defined in schemas via the `constraints` keyword.\n\t *\n\t * Constraint names must match those used in schema definitions.\n\t * Unknown constraints (present in a schema but absent from the registry)\n\t * will be reported as errors during runtime validation.\n\t */\n\tconstraints?: ConstraintValidatorRegistry;\n}\n"],"names":[],"mappings":"AA6JA,QAYC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "json-schema-compatibility-checker",
3
- "version": "1.1.3",
3
+ "version": "1.1.4",
4
4
  "license": "MIT",
5
5
  "description": "A tool to check compatibility between two JSON Schemas.",
6
6
  "author": {