@isdk/json-repair 0.1.3 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";var t,s=Object.create,i=Object.defineProperty,e=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,h=Object.getPrototypeOf,n=Object.prototype.hasOwnProperty,o=(t,s,h,o)=>{if(s&&"object"==typeof s||"function"==typeof s)for(let u of r(s))n.call(t,u)||u===h||i(t,u,{get:()=>s[u],enumerable:!(o=e(s,u))||o.enumerable});return t},u={};((t,s)=>{for(var e in s)i(t,e,{get:s[e],enumerable:!0})})(u,{RepairParser:()=>f,SchemaWalker:()=>a,jsonRepair:()=>d}),module.exports=(t=u,o(i({},"__esModule",{value:!0}),t));var c=((t,e,r)=>(r=null!=t?s(h(t)):{},o(!e&&t&&t.__esModule?r:i(r,"default",{value:t,enumerable:!0}),t)))(require("@apidevtools/json-schema-ref-parser"),1),l=require("lodash-es"),a=class t{dereferencedSchema;options;constructor(t,s={}){this.dereferencedSchema=t,this.options=s}static async create(s,i={}){if(!s)return new t({},i);const e=new c.default,r=await e.dereference((0,l.cloneDeep)(s));return new t(r,i)}getSchemaForPath(t){let s=this.dereferencedSchema;for(const i of t){if(!s)return;if("object"===s.type||s.properties)s=s.properties?.[i]||s.additionalProperties;else{if("array"!==s.type&&!s.items)return 0===Object.keys(s).length?{}:void 0;s=Array.isArray(s.items)?s.items[i]||s.additionalItems:s.items}}return s}isValidProperty(t,s){const i=this.getSchemaForPath(t);return!i||(0===Object.keys(i).length||(!i.type||"object"===i.type)&&(i.properties&&null!==this.matchProperty(t,s)||!1!==i.additionalProperties))}matchProperty(s,i){const e=this.declaredPropertyNames(s);if(e.includes(i))return i;const r=this.options.keyMatching;if(!r||0===e.length)return null;if("function"==typeof r){const t=r(i,e);return"string"==typeof t&&""!==t?t:null}const h=t.normalizeName(i);return e.find(s=>t.normalizeName(s)===h)??null}declaredPropertyNames(t){const s=this.getSchemaForPath(t)?.properties;return s?Object.keys(s):[]}static normalizeName(t){return t.replace(/[\s_\-.]/g,"").toLowerCase()}isDeclaredProperty(t,s){const i=this.getSchemaForPath(t);return!!i?.properties&&Object.prototype.hasOwnProperty.call(i.properties,s)}hasDeclaredProperties(t){const s=this.getSchemaForPath(t);return!!s?.properties&&Object.keys(s.properties).length>0}getExpectedTypes(t,s){const i=this.getSchemaForPath(t),e=i?.properties?.[s];return e?Array.isArray(e.type)?e.type:e.type?[e.type]:[]:[]}},f=class t{input="";pos=0;pathStack=[];walker;options;constructor(t,s={}){this.walker=t,this.options={coerceTypes:!0,...s}}parse(t){return this.input=t.trim(),this.pos=0,this.pathStack=[],this.cachedPath=null,this.cachedDeclaredKeys=[],this.consumeValue()}consumeValue(){if(this.skipWhitespace(),this.pos>=this.input.length)return;const s=this.peek(),i=this.walker.getSchemaForPath(this.pathStack);if("{"===s||t.declaresObject(i)&&this.isLookingAtKey(this.pathStack))return this.consumeObject();if("["===s)return this.consumeArray();const e=this.pos,r=this.tryConsumeStrictValue(s);if(r.ok)return this.options.coerceTypes&&i?this.coerceValue(r.value,i,r.raw):r.value;this.pos=e;const h=this.consumeGreedyString();return this.options.coerceTypes&&i?this.coerceValue(h,i):h}tryConsumeStrictValue(t){const s=this.pos;let i=null;if('"'===t||"'"===t?i=()=>this.consumeString():this.isDigit(t)||"-"===t||"+"===t?i=()=>this.consumeNumber():"t"!==t&&"f"!==t&&"n"!==t||(i=()=>"n"===t?this.consumeNull():this.consumeBoolean()),!i)return{ok:!1,value:void 0};try{const t=i(),e=this.input.slice(s,this.pos);if(this.skipWhitespace(),this.isAtDelimiter("structural")||this.pos>=this.input.length)return{ok:!0,value:t,raw:e}}catch(t){}return this.pos=s,{ok:!1,value:void 0}}static declaresObject(t){return!!t&&(Array.isArray(t.type)?t.type.includes("object"):"object"===t.type||!!t.properties)}consumeObject(){const s={},i="{"===this.peek();for(i&&this.consumeChar("{"),this.skipWhitespace();this.pos<this.input.length&&"}"!==this.peek();){const e=this.pos;if(!i&&("]"===this.peek()||","===this.peek()&&!this.isLookingAtKey(this.pathStack.slice(0,-1),this.pos+1)))break;const r=this.consumeKey(this.pathStack);if(null===r)break;const h=[...this.pathStack],n=this.walker.matchProperty(h,r)??r;if(!i&&Object.prototype.hasOwnProperty.call(s,n)){this.pos=e;break}this.skipWhitespace(),":"===this.peek()&&this.consumeChar(":"),this.pathStack.push(n);try{const i=this.consumeValue();(this.pos!==e||void 0!==i&&""!==i)&&this.isKeptProperty(h,n)&&t.setOwn(s,n,i)}finally{this.pathStack.pop()}if(this.skipWhitespace(),","===this.peek()){if(this.isLookingAtKey(this.pathStack,this.pos+1)||i&&/^\s*[}]/.test(this.input.slice(this.pos+1)))this.consumeChar(","),this.skipWhitespace();else{if(!i)break;this.consumeChar(","),this.skipWhitespace()}}else"}"!==this.peek()&&this.isLookingAtKey(this.pathStack)&&this.skipWhitespace();if(this.pos===e)break}return i&&"}"===this.peek()&&this.consumeChar("}"),s}isKeptProperty(t,s){return"remove"!==this.options.additionalProperties||(!this.walker.hasDeclaredProperties(t)||this.walker.isDeclaredProperty(t,s))}static setOwn(t,s,i){Object.defineProperty(t,s,{value:i,enumerable:!0,writable:!0,configurable:!0})}consumeArray(){const t=[];this.consumeChar("["),this.skipWhitespace();let s=0;for(;this.pos<this.input.length&&"]"!==this.peek()&&"}"!==this.peek();){const i=this.pos;this.pathStack.push(s);try{const e=this.consumeValue();this.pos!==i&&(t.push(e),s++)}finally{this.pathStack.pop()}if(this.skipWhitespace(),","===this.peek()&&(this.consumeChar(","),this.skipWhitespace()),this.pos===i)break}return"]"===this.peek()&&this.consumeChar("]"),t}consumeKey(t=this.pathStack){if(this.skipWhitespace(),this.pos>=this.input.length)return null;if('"'===this.peek()||"'"===this.peek())return this.consumeString();const s=this.matchDeclaredKey(this.pos,t);if(s)return this.pos+=s.length,s.key;let i="";for(;this.pos<this.input.length&&!this.isWhitespace(this.peek())&&":"!==this.peek()&&","!==this.peek()&&"}"!==this.peek()&&"]"!==this.peek()&&'"'!==this.peek()&&"'"!==this.peek();)i+=this.next();return i}consumeGreedyString(){let t="";const s=[];let i=!1,e="";for(;this.pos<this.input.length;){const r=this.peek();if(0===s.length&&this.isAtDelimiter("greedy"))break;if(i){if(r===e){let t=0,s=this.pos-1;for(;s>=0&&"\\"===this.input[s];)t++,s--;t%2==0&&(i=!1)}}else if('"'===r||"'"===r)i=!0,e=r;else if("("===r||"["===r||"{"===r)s.push(r);else if(")"===r||"]"===r||"}"===r){const t=s[s.length-1];(")"===r&&"("===t||"]"===r&&"["===t||"}"===r&&"{"===t)&&s.pop()}t+=this.next()}let r=t.trim();if(r.length>=2){const t=r[0],s=r[r.length-1];if(('"'===t||"'"===t)&&t===s){const s=r.slice(1,-1);let i=0;for(let e=0;e<s.length;e++)s[e]!==t||0!==e&&"\\"===s[e-1]||i++;if(i%2==1||0===i)return s}}return r}static WORD_CHAR=/[\p{L}\p{N}_]/u;static declaredKeyPatterns=new Map;cachedPath=null;cachedDeclaredKeys=[];declaredMultiWordKeys(s){if(this.cachedPath&&this.cachedPath.length===s.length&&this.cachedPath.every((t,i)=>t===s[i]))return this.cachedDeclaredKeys;const i=!0===this.options.keyMatching,e=this.walker.declaredPropertyNames(s).filter(t=>/\s/.test(t.trim())).map(s=>{const e=`${i?"i":""}:${s}`;let r=t.declaredKeyPatterns.get(e);if(!r){const h=s.trim().replace(/[.*+?^${}()|[\]\\]/g,"\\$&").replace(/\s+/g,"\\s+");r=new RegExp(`^${h}(?=\\s*:)`,i?"i":""),t.declaredKeyPatterns.set(e,r)}return{name:s,pattern:r}}).sort((t,s)=>s.name.length-t.name.length);return this.cachedPath=[...s],this.cachedDeclaredKeys=e,e}matchDeclaredKey(s,i=this.pathStack){let e=s;for(;e<this.input.length&&this.isWhitespace(this.input[e]);)e++;if(e>0&&t.WORD_CHAR.test(this.input[e-1]))return null;const r=this.declaredMultiWordKeys(i);if(0===r.length)return null;const h=this.input.slice(e);let n=null;for(const{name:t,pattern:s}of r){const i=h.match(s);i&&(!n||i[0].length>n.length)&&(n={key:t,length:i[0].length})}return n}isAtDelimiter(t="greedy"){if(this.pos>=this.input.length)return!0;const s=this.peek();if("}"===s||"]"===s)return!0;const i="number"==typeof this.pathStack[this.pathStack.length-1];if(","===s){if(i)return!0;const s=this.input.slice(this.pos+1);return!!/^\s*[}\]]/.test(s)||(!!/^\s*$/.test(s)||this.isBoundaryAhead(this.pos+1,t))}if(this.isBoundaryAhead(this.pos,t))return!0;if(this.isWhitespace(s)){const s=this.pos;this.skipWhitespace();const i=this.peek(),e="}"===i||"]"===i||","===i||this.isBoundaryAhead(this.pos,t);return this.pos=s,e}return!1}isLookingAtKey(t,s=this.pos){if(null!==this.matchDeclaredKey(s,t))return!0;const i=this.matchKey(s);return null!==i&&this.walker.isValidProperty(t,i)}matchKey(t=this.pos){const s=this.input.slice(t).match(/^\s*(?:"((?:\\.|[^"\\])*)"|'((?:\\.|[^'\\])*)'|([^\s"',:{}\[\]]+))\s*:/);if(!s)return null;const i=void 0!==s[1]||void 0!==s[2];let e=s[1]??s[2]??s[3];return i&&(e=e.replace(/\\(["'\\])/g,"$1")),e}isBoundaryAhead(t,s){const i=this.pathStack.slice(0,-1);if(null!==this.matchDeclaredKey(t,i))return!0;const e=this.matchKey(t);return null!==e&&("structural"===s||("conservative"===this.options.stringCaptureStrategy||(this.walker.hasDeclaredProperties(i)?null!==this.walker.matchProperty(i,e):this.walker.isValidProperty(i,e))))}coerceValue(t,s,i){const e=Array.isArray(s.type)?s.type:s.type?[s.type]:[],r=String(t).trim();if(s.enum){const t=r.toLowerCase().replace(/[^a-z0-9]/g,"");for(const i of s.enum){if(t===String(i).toLowerCase().replace(/[^a-z0-9]/g,""))return i}}const h=null===t?"null":typeof t;if(e.length>0&&e.includes(h))return t;if(e.includes("string"))return null===t||"object"==typeof t||"string"==typeof t?t:void 0!==i?i.trim():String(t);if(e.includes("number")||e.includes("integer")){const t=r.replace(/(?<=\d)[,,](?=\d)/g,"").match(/-?(?:\d+(?:\.\d+)?|\.\d+)(?:[eE][+-]?\d+)?/),s=t?parseFloat(t[0]):NaN;if(!isNaN(s))return e.includes("integer")?Math.round(s):s}if(e.includes("boolean")){const t=r.toLowerCase(),s=["false","no","off","0","取消","否","n","f"];if(["true","yes","on","1","ok","确定","是","y","t"].includes(t))return!0;if(s.includes(t))return!1}return e.includes("null")&&"null"===r.toLowerCase()?null:t}consumeString(){const t=this.next();let s="";for(;this.pos<this.input.length&&this.peek()!==t;)"\\"===this.peek()?(this.next(),this.pos<this.input.length&&(s+=this.next())):s+=this.next();return this.peek()===t&&this.next(),s}static NUMBER_PATTERN=/^[+-]?(?:\d+\.\d*|\.\d+|\d+)(?:[eE][+-]?\d+)?/;consumeNumber(){const s=this.input.slice(this.pos).match(t.NUMBER_PATTERN);return s?(this.pos+=s[0].length,parseFloat(s[0])):NaN}consumeBoolean(){const t=this.input.slice(this.pos);return t.startsWith("true")?(this.pos+=4,!0):!!t.startsWith("false")&&(this.pos+=5,!1)}consumeNull(){return this.pos+=4,null}peek(){return this.input[this.pos]}next(){return this.input[this.pos++]}consumeChar(t){this.peek()===t&&this.next()}isWhitespace(t){return/\s/.test(t)}isDigit(t){return/[0-9]/.test(t)}skipWhitespace(){for(;this.pos<this.input.length&&this.isWhitespace(this.peek());)this.pos++}};async function d(t,s,i={}){const e=s instanceof a?s:await a.create(s,i);return new f(e,i).parse(t)}
1
+ "use strict";var t,e=Object.defineProperty,s=Object.getOwnPropertyDescriptor,i=Object.getOwnPropertyNames,r=Object.prototype.hasOwnProperty,n={};((t,s)=>{for(var i in s)e(t,i,{get:s[i],enumerable:!0})})(n,{KEY_SEPARATORS:()=>p,RepairParser:()=>$,SchemaWalker:()=>g,compareScores:()=>K,discardedText:()=>P,expectsArrayRoot:()=>j,findImplicitRecordRegion:()=>A,jsonRepair:()=>H,jsonRepairResult:()=>V,locateJsonCandidates:()=>w,looksLikeSchemaEcho:()=>M,renderValidatorErrors:()=>L,scoreCandidate:()=>R,validateValue:()=>I}),module.exports=(t=n,((t,n,o,h)=>{if(n&&"object"==typeof n||"function"==typeof n)for(let c of i(n))r.call(t,c)||c===o||e(t,c,{get:()=>n[c],enumerable:!(h=s(n,c))||h.enumerable});return t})(e({},"__esModule",{value:!0}),t));var o=require("@apidevtools/json-schema-ref-parser"),h=require("lodash-es"),c=class{constructor(t){this.max=t}max;entries=new Map;compute(t,e){const s=this.entries.get(t);if(void 0!==s)return s;const i=e(t);return this.entries.set(t,i),this.entries.size>this.max&&this.entries.delete(this.entries.keys().next().value),i}get size(){return this.entries.size}},a=2e3;function u(t,e,s=e){return void 0===t?[...s]:"boolean"==typeof t?t?[...e]:[]:[...t]}var f=["js","python"],l=["line","block","hash"],d=[],p=[" ","\t","\n","\r","_","-","."];var m=new Map;function y(t,e){let s=t;if(e.separators){const t=e.separators.join("");let i=m.get(t);i||(i=new RegExp(`[${e.separators.map(t=>t.replace(/[\\\]^-]/g,"\\$&")).join("")}]`,"g"),m.set(t,i)),s=s.replace(i,"")}return e.foldCase?s.toLowerCase():s}var g=class t{dereferencedSchema;options;resolvedKeyMatching;constructor(t,e={}){this.dereferencedSchema=t,this.options=e}static async create(e,s={}){if(!e)return new t({},s);const i=await(0,o.dereference)((0,h.cloneDeep)(e));return new t(t.flatten(i),s)}static COMBINATORS=["allOf","anyOf","oneOf"];static SCHEMA_MAPS=["properties","patternProperties","$defs","definitions"];static SCHEMA_NODES=["items","additionalItems","additionalProperties","contains","not","propertyNames"];static SHARED_KEYWORDS=["type","properties","patternProperties","items","additionalItems","enum"];static flatten(e){return t.flattenNode(e,{nodes:new Map,merged:new Map})}static flattenMap(e,s){if(!e||"object"!=typeof e)return e;const i={};for(const[r,n]of Object.entries(e))i[r]=t.flattenNode(n,s);return i}static flattenNode(e,s){if(!e||"object"!=typeof e)return e;const i=s.nodes.get(e);if(i)return i;const r={};s.nodes.set(e,r);for(const[i,n]of Object.entries(e))t.COMBINATORS.includes(i)||(t.SCHEMA_MAPS.includes(i)?r[i]=t.flattenMap(n,s):t.SCHEMA_NODES.includes(i)?r[i]=Array.isArray(n)?n.map(e=>t.flattenNode(e,s)):t.flattenNode(n,s):r[i]=n);for(const i of t.COMBINATORS){const n=e[i];if(!Array.isArray(n))continue;const o="allOf"===i;for(const e of n){const i=t.flattenNode(e,s);i&&"object"==typeof i&&t.mergeInto(r,i,o,s)}}return r}static mergeInto(e,s,i,r){let n=r.merged.get(e);if(n||(n=new Set,r.merged.set(e,n)),!n.has(s)){n.add(s);for(const[n,o]of Object.entries(s))if(i||t.SHARED_KEYWORDS.includes(n))if("type"===n){const s=t.unique(e.type,o);e.type=1===s.length?s[0]:s}else if("enum"===n)e.enum=t.unique(e.enum,o);else if("required"===n)i&&(e.required=t.unique(e.required,o));else if("properties"===n||"patternProperties"===n){const s=e[n]??={};for(const[e,n]of Object.entries(o))s[e]?t.mergeInto(s[e],n,i,r):s[e]=n}else n in e||(e[n]=o)}}static unique(t,e){const s=Array.isArray(t)?t:void 0===t?[]:[t];for(const t of Array.isArray(e)?e:void 0===e?[]:[e])s.includes(t)||s.push(t);return s}getSchemaForPath(t){let e=this.dereferencedSchema;for(const s of t){if(!e)return;if("object"===e.type||e.properties||e.patternProperties)e=e.properties?.[s]??this.patternSchemaForNode(e,s)??this.valueSchemaOf(e);else{if("array"!==e.type&&!e.items)return 0===Object.keys(e).length?{}:void 0;e=Array.isArray(e.items)?e.items[s]||e.additionalItems:e.items}}return e}additionalPropertiesAt(t){return this.effectiveAdditionalProperties(this.getSchemaForPath(t))}effectiveAdditionalProperties(t){const e=t?.additionalProperties;return void 0!==e?e:this.options.additionalProperties??!0}valueSchemaOf(t){const e=this.effectiveAdditionalProperties(t);return"object"==typeof e&&null!==e?e:void 0}patternSchemaFor(t,e){return this.patternSchemaForNode(this.getSchemaForPath(t),e)}patternSchemaForNode(e,s){if("string"==typeof s)for(const[i,r]of t.patternEntries(e))if(t.patternOf(i)?.test(s))return r}matchesKeyPattern(e,s){const i=this.getSchemaForPath(e);return void 0!==this.patternSchemaForNode(i,s)||t.patternEntries(i).some(([e])=>null===t.patternOf(e))}hasKeyPatterns(e){return t.patternEntries(this.getSchemaForPath(e)).length>0}static patternEntries(t){const e=t?.patternProperties;return e&&"object"==typeof e?Object.entries(e):[]}static patterns=new c(a);static patternOf(e){return t.patterns.compute(e,t=>{try{return new RegExp(t)}catch{return null}})}isValidProperty(t,e){const s=this.getSchemaForPath(t);return!s||(0===Object.keys(s).length||(!s.type||"object"===s.type)&&this.allowsProperty(t,e))}allowsProperty(t,e){return null!==this.matchProperty(t,e)||(!!this.matchesKeyPattern(t,e)||(!1!==this.additionalPropertiesAt(t)||!(this.hasDeclaredProperties(t)||this.hasKeyPatterns(t))))}matchProperty(t,e){const s=this.declaredPropertyNames(t);if(s.includes(e))return e;const i=this.keyMatching;if(i.matcher){const t=i.matcher(e,s);return"string"==typeof t&&""!==t?t:null}if(0===s.length)return null;const r=y(e,i),n=i.foldCase||null!==i.separators;for(const[t,e]of Object.entries(i.aliases))if(s.includes(t)&&e.some(t=>y(t,i)===r))return t;return n?s.find(t=>y(t,i)===r)??null:null}get keyMatching(){return this.resolvedKeyMatching||(this.resolvedKeyMatching=function(t){if("function"==typeof t)return{foldCase:!1,separators:null,aliases:{},matcher:t};if(void 0===t||!1===t)return{foldCase:!1,separators:null,aliases:{},matcher:null};const e=!0===t?{}:t,s=u(e.forms,["case","separators"]);return{foldCase:s.includes("case"),separators:s.includes("separators")?e.separators??p:null,aliases:e.aliases??{},matcher:null}}(this.options.keyMatching)),this.resolvedKeyMatching}declaredPropertyNames(t){const e=this.getSchemaForPath(t)?.properties;return e?Object.keys(e):[]}isDeclaredProperty(t,e){const s=this.getSchemaForPath(t);return!!s?.properties&&Object.prototype.hasOwnProperty.call(s.properties,e)}hasDeclaredProperties(t){const e=this.getSchemaForPath(t);return!!e?.properties&&Object.keys(e.properties).length>0}getExpectedTypes(t,e){const s=this.getSchemaForPath(t),i=s?.properties?.[e]??this.patternSchemaForNode(s,e)??this.valueSchemaOf(s);return i?Array.isArray(i.type)?i.type:i.type?[i.type]:[]:[]}},b=512,v=new RegExp(String.raw`^\s*(?:"((?:\\.|[^"\\]){0,${b}})"|'((?:\\.|[^'\\]){0,${b}})'|([^\s"',:{}\[\]]{1,${b}}))\s*:`),$=class t{input="";pos=0;pathStack=[];walker;options;readFlags=new Set;dropped=[];commentStyles;literalDialects;constructor(t,e={}){this.walker=t,this.options={coerceTypes:!0,...e},this.commentStyles=u(this.options.comments,l,d),this.literalDialects=u(this.options.literals,f,f)}get consumed(){return this.pos}get droppedText(){return this.dropped}get flags(){return this.readFlags}get remainder(){return this.input.slice(this.pos)}parse(t){return this.input=t.trim(),this.pos=0,this.pathStack=[],this.cachedPath=null,this.cachedDeclaredKeys=[],this.readFlags.clear(),this.dropped=[],this.consumeValue()}consumeValue(){if(this.skipWhitespace(),this.pos>=this.input.length)return;const e=this.peek(),s=this.walker.getSchemaForPath(this.pathStack);if(this.pathStack.length>=t.MAX_NESTING&&("["===e||"{"===e||!1!==this.options.wrapArrays&&t.declaresArray(s)&&this.isLookingAtKey([...this.pathStack,0])||t.declaresObject(s)&&this.isLookingAtKey(this.pathStack)))return void this.readFlags.add("nesting-limited");if("["===e)return this.consumeArray();if(!1!==this.options.wrapArrays&&t.declaresArray(s)&&("{"===e||this.isLookingAtKey([...this.pathStack,0])))return this.consumeArray(!0);if("{"===e||t.declaresObject(s)&&this.isLookingAtKey(this.pathStack))return this.consumeObject();const i=this.pos,r=this.tryConsumeStrictValue(e);if(r.ok)return this.options.coerceTypes&&s?this.coerceValue(r.value,s,r.raw):r.value;this.pos=i;const n=this.consumeUnterminatedString()??this.consumeGreedyString();this.swallowedComment(this.input.slice(i,this.pos))&&this.readFlags.add("comment-in-value");let o=t.guidesScalar(s)?void 0:this.dialectLiteral(n);if(!o&&s){const e=this.dialectLiteral(n);e&&t.allows(s,e.value)&&(o=e)}return o?(this.readFlags.add("non-json-literal"),o.value):this.options.coerceTypes&&s?this.coerceValue(n,s):n}static allows(t,e){return t.enum?t.enum.some(t=>t===e):"const"in t&&t.const===e}static guidesScalar(t){return!!t&&(void 0!==t.type||void 0!==t.enum||void 0!==t.const)}dialectLiteral(e){return this.literalDialects.includes("python")&&t.PYTHON_LITERALS.has(e)?{value:t.PYTHON_LITERALS.get(e)}:this.literalDialects.includes("js")&&t.JS_LITERALS.has(e)?{value:t.JS_LITERALS.get(e)}:void 0}static PYTHON_LITERALS=new Map([["True",!0],["False",!1],["None",null]]);static JS_LITERALS=new Map([["undefined",null]]);consumeUnterminatedString(){const t=this.options.unescapedQuotes??"keep";if("keep"===t||'"'!==this.peek())return;const e="declared"===t;for(let t=this.pos+1;t<this.input.length;t++){if("\\"===this.input[t]){t++;continue}if('"'!==this.input[t]||!this.closesValueAt(t,e))continue;this.next();let s="";for(;this.pos<t;)s+="\\"===this.peek()&&this.pos+1<t?this.consumeEscape():this.next();return this.next(),this.readFlags.add("unescaped-quote-inferred"),s}}closesValueAt(t,e){const s=this.pos;this.pos=t+1;const i=this.isAtDelimiter("structural");if(this.pos=s,!i)return!1;if(!e)return!0;const r=this.nextMemberPos(t+1);if(r>=this.input.length)return!0;if("}"===this.input[r]||"]"===this.input[r])return!0;const n=this.pathStack.slice(0,-1),o=this.matchKey(r+(","===this.input[r]?1:0));return null!==o&&null!==this.walker.matchProperty(n,o)}skipMemberGap(){if(this.skipWhitespace(),0===this.commentStyles.length)return;let t=!1;for(;this.skipOneComment();)t=!0,this.skipWhitespace();t&&this.readFlags.add("comment-skipped")}skipOneComment(){const t=this.input.slice(this.pos,this.pos+2);if("/*"===t&&this.commentStyles.includes("block")){const t=this.input.indexOf("*/",this.pos+2);return-1!==t&&(this.pos=t+2,!0)}return("//"===t&&this.commentStyles.includes("line")||!("#"!==t[0]||!this.commentStyles.includes("hash")))&&this.skipToLineEnd()}static COMMENT_GAP=/[\s{[,]/;swallowedComment(e){let s=null,i=!1;for(let r=0;r<e.length;r++){const n=e[r];if(s){i?i=!1:"\\"===n?i=!0:n===s&&(s=null);continue}if('"'===n||"'"===n){s=n;continue}if(0===r||!t.COMMENT_GAP.test(e[r-1]))continue;const o="#"===n?"hash":"/"===n&&"/"===e[r+1]?"line":"/"===n&&"*"===e[r+1]?"block":null;if(null!==o&&!this.commentStyles.includes(o))return!0}return!1}nextMemberPos(t){const e=this.pos;this.pos=t,this.skipMemberGap();const s=this.pos;return this.pos=e,s}skipToLineEnd(){const t=this.input.indexOf("\n",this.pos);return this.pos=-1===t?this.input.length:t,!0}tryConsumeStrictValue(e){const s=this.pos;let i=null;if('"'===e||"'"===e?i=()=>this.consumeString():this.isDigit(e)||"-"===e||"+"===e?i=()=>this.consumeNumber():"t"!==e&&"f"!==e&&"n"!==e||(i=()=>"n"===e?this.consumeNull():this.consumeBoolean()),!i)return{ok:!1,value:void 0};try{const r=i(),n=this.input.slice(s,this.pos);this.skipMemberGap();const o='"'!==e&&"'"!==e||t.closesString(n);if(this.isAtDelimiter("structural",o)||this.pos>=this.input.length)return{ok:!0,value:r,raw:n}}catch(t){}return this.pos=s,{ok:!1,value:void 0}}static MAX_NESTING=1e3;static declaresObject(t){return!!t&&(Array.isArray(t.type)?t.type.includes("object"):"object"===t.type||!!t.properties||!!t.patternProperties)}consumeObject(){const e={},s="{"===this.peek();for(s&&this.consumeChar("{"),this.skipMemberGap();this.pos<this.input.length&&"}"!==this.peek();){this.skipMemberGap();const i=this.danglingTail();if(i){this.dropped.push(i.text),this.readFlags.add("dangling-dropped"),this.pos=i.end;break}const r=this.pos;if(!s&&("]"===this.peek()||","===this.peek()&&!this.isLookingAtKey(this.pathStack.slice(0,-1),this.pos+1)))break;const n=this.consumeKey(this.pathStack);if(null===n)break;const o=[...this.pathStack],h=this.walker.matchProperty(o,n)??n;if(!s&&Object.prototype.hasOwnProperty.call(e,h)){this.pos=r;break}this.skipWhitespace(),":"===this.peek()&&this.consumeChar(":"),this.pathStack.push(h);try{const s=this.consumeValue();(this.pos!==r||void 0!==s&&""!==s)&&(this.walker.allowsProperty(o,h)?t.setOwn(e,h,s):(this.dropped.push(this.input.slice(r,this.pos).trim()),this.readFlags.add("undeclared-keys-dropped")))}finally{this.pathStack.pop()}if(this.skipMemberGap(),","===this.peek()){const t=this.nextMemberPos(this.pos+1);if(this.isLookingAtKey(this.pathStack,t)||s&&"}"===this.input[t])this.consumeChar(","),this.skipMemberGap();else{if(!s)break;this.consumeChar(","),this.skipMemberGap()}}else"}"!==this.peek()&&this.isLookingAtKey(this.pathStack)&&this.skipWhitespace();if(this.pos===r)break}return s&&"}"===this.peek()&&this.consumeChar("}"),e}static setOwn(t,e,s){Object.defineProperty(t,e,{value:s,enumerable:!0,writable:!0,configurable:!0})}static declaresArray(t){return!!t&&(Array.isArray(t.type)?t.type.includes("array"):"array"===t.type||!!t.items)}consumeArray(t=!1){const e=[];t||this.consumeChar("["),this.skipMemberGap();let s=0;for(;this.pos<this.input.length;){if(this.skipMemberGap(),"]"===this.peek()){if(this.consumeChar("]"),this.skipWhitespace(),!this.startsAnotherRecord())break;continue}if("}"===this.peek())break;const t=this.pos;this.pathStack.push(s);try{const i=this.consumeValue();this.pos!==t&&(e.push(i),s++)}finally{this.pathStack.pop()}if(this.skipMemberGap(),","===this.peek()&&(this.consumeChar(","),this.skipMemberGap()),this.pos===t)break}return e}startsAnotherRecord(){const t=[...this.pathStack,0],e=this.walker.getSchemaForPath(t);if(!e)return!1;if("object"!==e.type&&!e.properties)return!1;if("{"===this.peek())return!0;if(this.matchDeclaredKey(this.pos,t))return!0;const s=this.matchKey(this.pos);return null!==s&&null!==this.walker.matchProperty(t,s)}consumeKey(t=this.pathStack){if(this.skipWhitespace(),this.pos>=this.input.length)return null;if('"'===this.peek()||"'"===this.peek())return this.consumeString();if("{"===this.peek()||"["===this.peek())return null;const e=this.matchDeclaredKey(this.pos,t);if(e)return this.pos+=e.length,e.key;let s="";for(;this.pos<this.input.length&&!this.isWhitespace(this.peek())&&":"!==this.peek()&&","!==this.peek()&&"}"!==this.peek()&&"]"!==this.peek()&&'"'!==this.peek()&&"'"!==this.peek();)s+=this.next();return s}consumeGreedyString(){let t="";const e=[];let s=!1,i="";for(;this.pos<this.input.length;){const r=this.peek();if(0===e.length&&this.isAtDelimiter("greedy",!s))break;if(s){if(r===i){let t=0,e=this.pos-1;for(;e>=0&&"\\"===this.input[e];)t++,e--;t%2==0&&(s=!1)}}else if('"'===r||"'"===r)s=!0,i=r;else if("("===r||"["===r||"{"===r)e.push(r);else if(")"===r||"]"===r||"}"===r){const t=e[e.length-1];(")"===r&&"("===t||"]"===r&&"["===t||"}"===r&&"{"===t)&&e.pop()}t+=this.next()}let r=t.trim();if(r.length>=2){const t=r[0],e=r[r.length-1];if(('"'===t||"'"===t)&&t===e){const e=r.slice(1,-1);let s=0;for(let i=0;i<e.length;i++)e[i]!==t||0!==i&&"\\"===e[i-1]||s++;if(s%2==1||0===s)return e}}return r}static WORD_CHAR=/[\p{L}\p{N}_]/u;static declaredKeyPatterns=new c(a);cachedPath=null;cachedDeclaredKeys=[];declaredMultiWordKeys(e){if(this.cachedPath&&this.cachedPath.length===e.length&&this.cachedPath.every((t,s)=>t===e[s]))return this.cachedDeclaredKeys;const s=this.walker.keyMatching,i=this.walker.declaredPropertyNames(e),r=[...i,...Object.entries(s.aliases).filter(([t])=>i.includes(t)).flatMap(([,t])=>t)].filter(t=>/\s/.test(t.trim())).map(e=>{const i=`${s.foldCase?"i":""}:${e}`,r=t.declaredKeyPatterns.compute(i,()=>{const t=e.trim().replace(/[.*+?^${}()|[\]\\]/g,"\\$&").replace(/\s+/g,"\\s+");return new RegExp(`^${t}(?=\\s*:)`,s.foldCase?"i":"")});return{name:e,pattern:r}}).sort((t,e)=>e.name.length-t.name.length);return this.cachedPath=[...e],this.cachedDeclaredKeys=r,r}matchDeclaredKey(e,s=this.pathStack){let i=e;for(;i<this.input.length&&this.isWhitespace(this.input[i]);)i++;if(i>0&&t.WORD_CHAR.test(this.input[i-1]))return null;const r=this.declaredMultiWordKeys(s);if(0===r.length)return null;const n=this.input.slice(i);let o=null;for(const{name:t,pattern:e}of r){const s=n.match(e);s&&(!o||s[0].length>o.length)&&(o={key:t,length:s[0].length})}return o}isAtDelimiter(t="greedy",e=!0){if(this.pos>=this.input.length)return!0;const s=this.peek();if("}"===s||"]"===s)return!0;const i="number"==typeof this.pathStack[this.pathStack.length-1];if(","===s){if(i)return!0;const s=this.nextMemberPos(this.pos+1),r=this.input.slice(s);return!!/^[}\]]/.test(r)||(""===r.trimEnd()||(!(!e||!this.isDanglingTail(s))||this.isBoundaryAhead(s,t)))}if(this.isBoundaryAhead(this.pos,t))return!0;if(this.isWhitespace(s)){const e=this.pos;this.skipMemberGap();const s=this.peek(),i="}"===s||"]"===s||","===s||this.isBoundaryAhead(this.pos,t);return this.pos=e,i}return!1}isLookingAtKey(t,e=this.pos){if(null!==this.matchDeclaredKey(e,t))return!0;const s=this.matchKey(e);return null!==s&&this.walker.isValidProperty(t,s)}matchKey(e=this.pos){if(e>0&&t.WORD_CHAR.test(this.input[e-1]))return null;const s=this.input.slice(e).match(v);if(!s)return null;const i=void 0!==s[1]||void 0!==s[2];let r=s[1]??s[2]??s[3];return i&&(r=r.replace(/\\(["'\\])/g,"$1")),r}static DANGLING_TAIL=new RegExp(String.raw`^\s*("(?:\\.|[^"\\]){0,${b}}"?|'(?:\\.|[^'\\]){0,${b}}'?|[^\s"',:{}\[\]]{1,${b}})\s*[}\]]*\s*(?:\{|\[|$)`);danglingTail(e=this.pos){if(!1===this.options.dangling)return;const s=this.input.slice(e),i=t.DANGLING_TAIL.exec(s);if(!i)return;const r=i[1];return'"'!==r[0]&&"'"!==r[0]&&/^[\d.+-]+$/.test(r)?void 0:{text:r,end:e+i.index+r.length}}isDanglingTail(t=this.pos){return void 0!==this.danglingTail(t)}static closesString(t){const e=t[0];if(t.length<2||t[t.length-1]!==e)return!1;let s=0;for(let e=t.length-2;e>=0&&"\\"===t[e];e--)s++;return s%2==0}static PATH_NOT_KEY=/^\s*[^\s"',:{}\[\]]+:[/\\]/;isBoundaryAhead(e,s){const i=this.pathStack.slice(0,-1);if(null!==this.matchDeclaredKey(e,i))return!0;const r=this.matchKey(e);return null!==r&&(!t.PATH_NOT_KEY.test(this.input.slice(e))&&("structural"===s||("conservative"===this.options.stringCaptureStrategy||(this.walker.hasDeclaredProperties(i)?null!==this.walker.matchProperty(i,r)||void 0!==this.walker.patternSchemaFor(i,r):this.walker.isValidProperty(i,r)))))}coerceValue(e,s,i){const r=Array.isArray(s.type)?s.type:s.type?[s.type]:[],n=String(e).trim();if(s.enum){const i=t.enumSpelling(e);if(null!==i)for(const e of s.enum)if(t.enumSpelling(e)===i)return e}const o=null===e?"null":typeof e;if(r.length>0&&r.includes(o))return e;if(r.includes("string"))return null===e||"object"==typeof e||"string"==typeof e?e:void 0!==i?i.trim():String(e);if(r.includes("number")||r.includes("integer")){const t=n.replace(/(?<=\d)[,,](?=\d)/g,""),e=t.match(/-?(?:\d+(?:\.\d+)?|\.\d+)(?:[eE][+-]?\d+)?/),s=e?parseFloat(e[0]):NaN;if(!isNaN(s))return e&&this.reportNumberCoercion(t,e),r.includes("integer")?Math.round(s):s}if(r.includes("boolean")){const t=n.toLowerCase(),e=["false","no","off","0","取消","否","n","f"];if(["true","yes","on","1","ok","确定","是","y","t"].includes(t))return!0;if(e.includes(t))return!1}return r.includes("null")&&"null"===n.toLowerCase()?null:e}reportNumberCoercion(e,s){const i=s.index??0,r=(e.slice(0,i)+e.slice(i+s[0].length)).replace(t.COERCED_EDGE,"");""!==r&&(this.readFlags.add("coerced-text-dropped"),(r.split(/\s+/).length>=3||r.length>=20)&&this.dropped.push(r))}static COERCED_EDGE=/^[\s,]+|[\s,]+$/g;static enumSpelling(t){if("string"!=typeof t&&"number"!=typeof t)return null;const e=String(t).toLowerCase().replace(/[^a-z0-9]/g,"");return""===e?null:e}static ESCAPE_MAP={'"':'"',"\\":"\\","/":"/",b:"\b",f:"\f",n:"\n",r:"\r",t:"\t"};consumeEscape(){const e=this.options.escapes??"json5";if(this.next(),this.pos>=this.input.length)return"\\";const s=this.next(),i=t.ESCAPE_MAP[s],r="raw"===e||void 0!==i?0:"u"===s?4:"x"===s&&"json5"===e?2:0,n=r>0?this.readHex(r):null;return void 0!==i||null!==n&&"u"===s||this.readFlags.add("invalid-escape"),"raw"===e?`\\${s}`:void 0!==i?i:null!==n?String.fromCharCode(n):0===r&&"json5"===e?s:`\\${s}`}readHex(t){let e=0;for(let s=0;s<t;s++){const t=parseInt(this.input[this.pos+s],16);if(Number.isNaN(t))return null;e=16*e+t}return this.pos+=t,e}consumeString(){const t=this.next();let e="";for(;this.pos<this.input.length&&this.peek()!==t;)"\\"===this.peek()?e+=this.consumeEscape():e+=this.next();return this.peek()===t&&this.next(),e}static NUMBER_PATTERN=/^[+-]?(?:\d+\.\d*|\.\d+|\d+)(?:[eE][+-]?\d+)?/;consumeNumber(){const e=this.input.slice(this.pos).match(t.NUMBER_PATTERN);return e?(this.pos+=e[0].length,parseFloat(e[0])):NaN}consumeKeyword(e){const s=this.pos+e.length;if(this.input.slice(this.pos,s)!==e)return!1;const i=this.input[s];return(void 0===i||!t.WORD_CHAR.test(i))&&(this.pos=s,!0)}consumeBoolean(){return!!this.consumeKeyword("true")||(this.consumeKeyword("false"),!1)}consumeNull(){return this.consumeKeyword("null"),null}peek(){return this.input[this.pos]}next(){return this.input[this.pos++]}consumeChar(t){this.peek()===t&&this.next()}isWhitespace(t){return/\s/.test(t)}isDigit(t){return/[0-9]/.test(t)}skipWhitespace(){for(;this.pos<this.input.length&&this.isWhitespace(this.peek());)this.pos++}},O=/(?:```|~~~)[ \t]*[A-Za-z0-9+_-]*\s*$/,S=/^\s*(?:```|~~~)/;function j(t){const e=t.getSchemaForPath([]);return!!e&&(Array.isArray(e.type)?e.type.includes("array"):"array"===e.type||!!e.items)}function w(t,e){const s=function(t){const e=[];let s=0,i=-1,r=!1,n=!1;for(let o=0;o<t.length;o++){const h=t[o];r?n?n=!1:"\\"===h?n=!0:('"'===h||"\n"===h)&&(r=!1):'"'!==h?"{"!==h&&"["!==h?("}"===h||"]"===h)&&s>0&&(s--,0===s&&(e.push(k(t,i,o+1)),i=-1)):(0===s&&(i=o),s++):r=!0}s>0&&i>=0&&e.push(k(t,i,t.length,["truncated-candidate"]));return e}(t),i=e?A(t,e):void 0;if(i&&(0===s.length||i.start<s[0].start)){const e=s.filter(t=>t.end>i.end||t.start<i.start);return[i,...e].map(e=>x(t,e))}const r=e&&j(e)&&function(t){const e=t.getSchemaForPath([0]);return!(!e||"object"!==e.type&&!e.properties)}(e)?function(t,e){const s=[];for(const i of e){const e=s[s.length-1];e&&/^[\s,]*$/.test(t.slice(e.end,i.start))?s[s.length-1]=k(t,e.start,i.end,[...e.flags.filter(t=>"truncated-candidate"!==t),...i.flags,"sibling-objects-merged"]):s.push(i)}return s}(t,s):s;return r.map(e=>x(t,e))}function A(t,e){const s=[...e.declaredPropertyNames([]),...j(e)?e.declaredPropertyNames([0]):[]];if(0===s.length)return;let i;for(const e of s){const s=E(e).exec(t),r=s?.indices?.[1]?.[0];void 0!==r&&(void 0===i||r<i)&&(i=r)}return void 0!==i?k(t,i,t.length,["implicit-structure"]):void 0}var N=new c(a);function E(t){return N.compute(t,()=>{return new RegExp(`(?:^|[{[,\\s])(${e=t,e.replace(/[.*+?^${}()|[\\]\\]/g,"\\$&")})\\s*:`,"id");var e})}function k(t,e,s,i=[]){return{start:e,end:s,text:t.slice(e,s),flags:i}}function x(t,e){const s=[...e.flags],i=t.slice(0,e.start),r=t.slice(e.end);return!O.test(i)||!S.test(r)&&r.trim()||s.unshift("markdown-fence"),{...e,flags:s}}function P(t,e,s){const i=s.map(t=>t.text),r=[e,...s].sort((t,e)=>t.start-e.start),n=[];let o=0;for(const e of r){const s=t.slice(o,e.start).trim();s&&n.push({text:s,start:o}),o=Math.max(o,e.end)}const h=t.slice(o).trim();return h&&n.push({text:h,start:o}),{prose:n,fragments:i}}function R(t,e){const s={errors:0,requiredCovered:0,declaredCovered:0,undeclaredKeys:0,schemaEchoKeys:0},i=new Set;let r=0;const n=(t,o)=>{const h=e.getSchemaForPath(o);if(h){if(null!==t&&"object"==typeof t&&!Array.isArray(t)){const c=h.properties,a=new Set(Array.isArray(h.required)?h.required:[]);if(c)for(const e of Object.keys(c))Object.hasOwn(t,e)&&void 0!==t[e]&&(_(t[e],c[e])?(s.declaredCovered++,a.has(e)&&s.requiredCovered++):a.has(e)&&"string"==typeof t[e]&&""===t[e].trim()&&i.add("empty-required"));for(const i of Object.keys(t)){const h=e.declaredPropertyNames(o);!c&&!e.hasKeyPatterns(o)||h.includes(i)||void 0!==e.patternSchemaFor(o,i)||(s.undeclaredKeys++,D.has(i)&&(s.schemaEchoKeys++,r++)),n(t[i],[...o,i])}return}Array.isArray(t)&&t.forEach((e,s)=>n(t[s],[...o,s]))}};return n(t,[]),r>=2&&i.add("schema-echo-detected"),{score:s,flags:[...i]}}function M(t){return"string"==typeof t?(t.match(C)?.length??0)>=2:!(!t||"object"!=typeof t||Array.isArray(t))&&Object.keys(t).filter(t=>T.has(t)).length>=2}var C=/(?:^|[{,]\s*)["']?(?:\$schema|\$id|\$ref|\$defs|additionalProperties|properties|required|definitions|enum|anyOf|allOf|oneOf|items)["']?\s*:/g,T=new Set("$schema $id $ref $defs additionalProperties properties required definitions enum anyOf allOf oneOf items".split(" "));function _(t,e){if(void 0===t)return!1;if(null===t){return(Array.isArray(e?.type)?e.type:e?.type?[e.type]:[]).includes("null")}return"string"!=typeof t||""!==t.trim()}function K(t,e){return t.errors-e.errors||e.requiredCovered-t.requiredCovered||e.declaredCovered-t.declaredCovered||t.schemaEchoKeys-e.schemaEchoKeys}var D=new Set(["type","properties","required","additionalProperties","items","enum","allOf","anyOf","oneOf","not","format","pattern","minimum","maximum","minLength","maxLength","minItems","maxItems","definitions","$defs","$schema","$id","$ref","title","description","default"]);function I(t,e){const s=[];return q(t,[],e,s),s}function L(t,e=6){return t.slice(0,e).map(t=>{return`- ${e=t.path,0===e.length?"<root>":e.join(".")}: ${t.message}`;var e}).join("\n")}function q(t,e,s,i){const r=s.getSchemaForPath(e);if(r&&0!==Object.keys(r).length)if(function(t,e,s,i){const r=function(t){return null===t?"null":Array.isArray(t)?"array":void 0===t?"undefined":typeof t}(t);if(void 0!==e.type){const n=Array.isArray(e.type)?e.type:[e.type];n.some(e=>function(t,e,s){return e===s||"integer"===e&&("number"===s&&Number.isInteger(t))}(t,e,r))||i.push({path:s,message:`expected ${n.join(" or ")}, got ${r}`})}"const"in e&&!J(t,e.const)&&i.push({path:s,message:`expected the constant ${JSON.stringify(e.const)}`});if(Array.isArray(e.enum)){e.enum.some(e=>J(t,e))||i.push({path:s,message:`expected one of ${e.enum.map(t=>JSON.stringify(t)).join(", ")}, got ${JSON.stringify(t)}`})}"string"==typeof t&&("string"!=typeof e.pattern||function(t,e){try{return new RegExp(e).test(t)}catch{return!0}}(t,e.pattern)||i.push({path:s,message:`does not match pattern ${e.pattern}`}),"string"!=typeof e.format||function(t,e){const s=G[e];return!s||s.test(t)}(t,e.format)||i.push({path:s,message:`does not match format ${e.format}`}),"number"==typeof e.minLength&&t.length<e.minLength&&i.push({path:s,message:`shorter than minLength ${e.minLength}`}),"number"==typeof e.maxLength&&t.length>e.maxLength&&i.push({path:s,message:`longer than maxLength ${e.maxLength}`}));"number"==typeof t&&("number"==typeof e.minimum&&t<e.minimum&&i.push({path:s,message:`below minimum ${e.minimum}`}),"number"==typeof e.maximum&&t>e.maximum&&i.push({path:s,message:`above maximum ${e.maximum}`}),!0===e.exclusiveMinimum&&"number"==typeof e.minimum&&t===e.minimum&&i.push({path:s,message:`must be above minimum ${e.minimum}`}),!0===e.exclusiveMaximum&&"number"==typeof e.maximum&&t===e.maximum&&i.push({path:s,message:`must be below maximum ${e.maximum}`}));Array.isArray(t)&&("number"==typeof e.minItems&&t.length<e.minItems&&i.push({path:s,message:`fewer than minItems ${e.minItems}`}),"number"==typeof e.maxItems&&t.length>e.maxItems&&i.push({path:s,message:`more than maxItems ${e.maxItems}`}))}(t,r,e,i),Array.isArray(t))r.items&&t.forEach((r,n)=>q(t[n],[...e,n],s,i));else if(null!==t&&"object"==typeof t){const n=Array.isArray(r.required)?r.required:[];for(const s of n)Object.hasOwn(t,s)&&void 0!==t[s]||i.push({path:[...e,s],message:"missing required property"});for(const r of function(t){return Object.keys(t)}(t))s.allowsProperty(e,r)||i.push({path:[...e,r],message:"property is not declared by the Schema"}),q(t[r],[...e,r],s,i)}}function J(t,e){return function(t,e){if(t===e)return!0;if(null===t||null===e)return!1;if("object"!=typeof t||"object"!=typeof e)return!1;try{return JSON.stringify(t)===JSON.stringify(e)}catch{return!1}}(t,e)||function(t,e){const s=F(t),i=F(e);return null!==s&&null!==i&&s===i}(t,e)}function F(t){if("number"==typeof t)return Number.isFinite(t)?String(t):null;if("string"!=typeof t)return null;const e=t.trim();if(!/^[+-]?(?:\d+(?:\.\d+)?|\.\d+)(?:[eE][+-]?\d+)?$/.test(e))return null;const s=Number(e);return Number.isFinite(s)?String(s):null}var G={date:/^\d{4}-\d{2}-\d{2}$/,"date-time":/^\d{4}-\d{2}-\d{2}[T ]\d{2}:\d{2}(:\d{2}(\.\d+)?)?(Z|[+-]\d{2}:?\d{2})?$/,time:/^\d{2}:\d{2}(:\d{2}(\.\d+)?)?$/,email:/^[^@\s]+@[^@\s]+\.[^@\s]+$/,uri:/^[a-z][a-z0-9+.-]*:\S*/i,uuid:/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i};async function H(t,e,s={}){return(await V(t,e,s)).value}async function V(t,e,s={}){const i=e instanceof g?e:await g.create(e,s),r=t.trim();if(!1===s.locate||function(t){try{return JSON.parse(t),!0}catch{return!1}}(r)){const t=W(r,i,s),e=[...t.dropped,...t.leftover?[t.leftover]:[]];z(e,s);const n=[...t.flags];return M(t.value)&&n.push("schema-echo-detected"),{value:t.value,flags:n,errors:I(t.value,i),candidates:[],discarded:"ignore"===s.onDiscard?[]:e}}const n=w(r,i);if(0===n.length){const t=new $(i,s),e=t.parse(r),n=new Set(t.flags),o=[];null!==e&&"object"==typeof e&&n.add("implicit-structure");const h=t.remainder.trim();return h&&(n.add("trailing-chatter"),o.push(h)),z(o,s),{value:e,flags:[...n],errors:I(e,i),candidates:[],discarded:"ignore"===s.onDiscard?[]:o}}const o=n.map(t=>{const e=W(t.text,i,s),{score:r,flags:n}=R(e.value,i),o=I(e.value,i);return r.errors=o.length,M(t.text)&&n.push("schema-echo-detected"),{region:{...t,score:r},value:e.value,errors:o,read:e.flags,leftover:[...e.dropped,...e.leftover?[e.leftover]:[]],suspicion:n}}),{ordered:h,duplicates:c}=function(t,e){const s=new Set;if(t.length>1){const e=new Map;for(const s of t)e.set(B(s.value),s);for(const i of t)e.get(B(i.value))!==i&&s.add(i.region);t=t.filter(t=>!s.has(t.region))}if(t.length>1&&"throw"===e)throw new Error(`Found ${t.length} JSON candidates where one was expected: ${t.map((t,e)=>`#${e+1} ${JSON.stringify(t.region.text.slice(0,60))} {errors: ${t.region.score.errors}, requiredCovered: ${t.region.score.requiredCovered}}`).join("; ")}`);if("last"===e)return{ordered:[...t].sort((t,e)=>e.region.start-t.region.start),duplicates:s};if("first"===e)return{ordered:[...t].sort((t,e)=>t.region.start-e.region.start),duplicates:s};const i=[...t].sort((t,e)=>K(t.region.score,e.region.score)||e.region.start-t.region.start);return{ordered:i,duplicates:s}}(o,s.onMultiple??"best"),a=h[0],u=h.slice(1),f="best"===(s.onMultiple??"best")&&u.length>0&&0===K(a.region.score,u[0].region.score),{prose:l,fragments:d}=P(r,a.region,o.filter(t=>t!==a).map(t=>t.region)),p=new Set([...a.region.flags,...a.read]);l.some(t=>t.start<a.region.start)&&p.add("prose-prefix"),l.some(t=>t.start>=a.region.end)&&p.add("trailing-chatter"),u.length>0&&p.add("extra-fragments-dropped"),c.size>0&&p.add("duplicate-candidates"),f&&p.add("ambiguous-candidates");for(const t of o)for(const e of t.suspicion)p.add(e);const m=[...l.map(t=>t.text),...d,...a.leftover];return z(m,s),{value:a.value,flags:[...p],errors:a.errors,candidates:o.map(t=>t.region),discarded:"ignore"===s.onDiscard?[]:m}}function W(t,e,s){const i=new $(e,s);let r=i.parse(t);!1!==s.wrapArrays&&j(e)&&void 0!==r&&!Array.isArray(r)&&(r=[r]);const n=i.remainder.trim(),o=[...i.flags];return n&&!o.includes("dangling-dropped")&&o.push("unparsed-tail"),{value:r,flags:o,dropped:[...i.droppedText],leftover:n}}function z(t,e){if("throw"===e.onDiscard&&0!==t.length)throw new Error(`Repair discarded ${t.length} piece(s) of the input: ${JSON.stringify(t)}`)}function B(t){return JSON.stringify(t)??String(t)}