@versionzero/schema 1.4.0 → 1.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,2 +1,2 @@
1
1
  /* @versionzero/schema | Apache-2.0 | github.com/argh */
2
- var ua=Object.defineProperty;var m=(e,r)=>()=>(e&&(r=e(e=0)),r);var h=(e,r)=>{for(var t in r)ua(e,t,{get:r[t],enumerable:!0})};function Me(e){if(e==="")return["",void 0];let r=e.indexOf(".");return r===-1?[e,""]:[e.slice(0,r),e.slice(r+1)]}function ma(e){let r=e.lastIndexOf(".");return r===-1?e:e.slice(r+1)}var nr=m(()=>{"use strict"});var j,qe=m(()=>{"use strict";nr();j=class e{#e=new Map;#r;#t;#n;constructor(r,t,n){this.#t=r,t!==void 0&&n!==void 0?(this.#r=t,this.#n=t.path?`${t.path}.${n}`:`${n}`):this.#n=""}get path(){return this.#n}toString(){return this.#n}get name(){let r=this.#n.lastIndexOf(".");return r===-1?this.#n:this.#n.slice(r+1)}get schema(){return this.#t}set schema(r){if(!(r===void 0||r===this.#t)){for(let[t,n]of this.#e){let i=r.getPropertySchema(t);i!==void 0?n.schema=i:this.#e.delete(t)}this.#t=r}}get parent(){return this.#r}get root(){return this.parent===void 0?this:this.parent.root}relative(r){if(!r||r===""||r===".")return this;if(r.charAt(0)==="^")return this.parent?.relative(r.slice(1));if(r.charAt(0)==="/")return this.root.relative(r.slice(1));if(r.charAt(0)===".")return this.relative(r.slice(1));let[t,n]=Me(r),i=this.#e.get(t);if(i===void 0){let o=this.schema.getPropertySchema(t);if(o===void 0)return;let s=this.path?`${this.path}.${t}`:`${t}`;i=new e(o),i.#n=s,i.#r=this,this.#e.set(t,i)}return n===void 0?i:i.relative(n)}absolute(r){return this.root.relative(r)}sibling(r){return r?this.parent?.relative(r):this}union(r){if(r===this.#t)return this;if(!this.schema||!this.schema.isUnion||!this.schema.findUnionKey(r))return;let n=new e(r);return n.#n=this.#n,n.#r=this.#r,n}findPropertyLocation(r){if(this.#t!==void 0)for(let[t]of this.#t.propertyEntries){if(t==="*")continue;let n=this.relative(t);if(n!==void 0?r(n):void 0)return n}}}});function we(e,r={}){let{space:t=0,maxDepth:n=100,useDelimiters:i=!0,delimiterOpen:o="\xAB",delimiterClose:s="\xBB"}=r,a=new WeakMap,c=new WeakMap,d=(E,p=null)=>i?p!==null?`${o}${E}: ${p}${s}`:`${o}${E}${s}`:null,g=E=>{let p=E.description;return p!==void 0?p:(c.has(E)||c.set(E,pa()),c.get(E))},S=(E,p="$",b=0)=>{if(b>n)return d("MaxDepth");if(E===null)return null;if(E===void 0)return d("undefined");if(typeof E=="number")return Number.isNaN(E)?d("NaN"):E===1/0?d("Infinity"):E===-1/0?d("-Infinity"):E;if(typeof E=="boolean"||typeof E=="string")return E;if(typeof E=="symbol")return d("Symbol",g(E));if(typeof E=="function")return E.name?d("Function",E.name):d("undefined");if(typeof E=="bigint")return d("BigInt",E.toString());if(E instanceof Date){let R=d("Date",E.toISOString());return R!==null?R:E.toISOString()}if(Array.isArray(E)){if(a.has(E))return d("Circular",a.get(E));a.set(E,p);let R=E.map((U,W)=>S(U,`${p}[${W}]`,b+1)).filter(U=>U!==null||E.includes(null));return a.delete(E),R}if(typeof E=="object"){if(a.has(E))return d("Circular",a.get(E));a.set(E,p);let R=Object.keys(E).sort(),U={};for(let W of R){let Se=/^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(W)?`${p}.${W}`:`${p}[${JSON.stringify(W)}]`,Zr=S(E[W],Se,b+1);(Zr!==null||E[W]===null)&&(U[W]=Zr)}return a.delete(E),U}return null},A=S(e);return JSON.stringify(A,null,t)}function Fe(e,r={}){let{delimiterOpen:t="\xAB",delimiterClose:n="\xBB"}=r,i=JSON.parse(e),o=new Map,s=[],a=A=>A.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),c=new RegExp(`^${a(t)}([^:${a(n)}]+)(?::\\s*(.+?))?${a(n)}$`),d=A=>{if(typeof A!="string")return null;let E=A.match(c);return E?{type:E[1],value:E[2]}:null},g=(A,E="$")=>{let p=d(A);if(p)switch(p.type){case"undefined":return;case"NaN":return NaN;case"Infinity":return 1/0;case"-Infinity":return-1/0;case"BigInt":return BigInt(p.value);case"Date":return new Date(p.value);case"Symbol":return Symbol.for(p.value);case"Function":return null;case"MaxDepth":return null;case"Circular":return s.push({targetPath:E,sourcePath:p.value}),null}if(A===null||typeof A!="object")return A;if(Array.isArray(A)){let R=[];return o.set(E,R),A.forEach((U,W)=>{let Se=`${E}[${W}]`;R[W]=g(U,Se)}),R}let b={};o.set(E,b);for(let[R,U]of Object.entries(A)){let W=/^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(R)?`${E}.${R}`:`${E}[${JSON.stringify(R)}]`;b[R]=g(U,W)}return b},S=g(i);for(let{targetPath:A,sourcePath:E}of s){let p=da(S,A),b=o.get(E);p&&b&&la(p.obj,p.key,b)}return S}function da(e,r){if(r==="$")return null;let t=ha(r),n=e;for(let i=0;i<t.length-1;i++)if(n=n[t[i]],n==null)return null;return{obj:n,key:t[t.length-1]}}function la(e,r,t){e[r]=t}function ha(e){let r=[],t="",n=!1;for(let i=0;i<e.length;i++){let o=e[i];if(!(o==="$"&&i===0))if(o==="."&&!n)t&&r.push(t),t="";else if(o==="[")t&&r.push(t),t="",n=!0;else if(o==="]"){if(n){let s=t.trim();s.startsWith('"')&&s.endsWith('"')?r.push(JSON.parse(s)):r.push(Number(s)),t="",n=!1}}else t+=o}return t&&r.push(t),r}var pa,xe=m(()=>{"use strict";pa=()=>crypto.randomUUID()});function L(e){if(e==null||typeof e!="object")return!1;let r=Object.getPrototypeOf(e);return r===Object.prototype||r===null}function Ce(e){return e&&typeof e=="object"&&!Array.isArray(e)}function H(e){return e==null||Array.isArray(e)&&e.length===0||L(e)&&Object.keys(e).length===0}function He(e){if(e==null)return!1;let r=typeof e;return r!=="object"&&r!=="function"}function wa(e){if(typeof e!="function")return!1;if(e.prototype?.constructor===e)return!0;try{class r extends e{}}catch{return!1}return!0}function ya(e){if(typeof e!="function")return!1;try{return Reflect.construct(Function,[],e),!0}catch{return!1}}function yr(e){if(typeof e!="function")return!1;let r=Function.prototype.toString.call(e);return/^class\s/.test(r)||/\[native code\]/.test(r)&&e.prototype?.constructor===e}function K(e,r){return Array.isArray(e)?e.map(r):L(e)?Object.fromEntries(Object.entries(e).map(([t,n])=>[t,r(n)])):[r(e)]}var M=m(()=>{"use strict"});function ir(e){if(e.metadata.valueDescription)return e.metadata.valueDescription;let r;return e.isArray&&e.hasChildren?(r=Array.from(e.propertyEntries).sort((n,i)=>n[0]==="*"?1:i[0]==="*"?-1:n[0].localeCompare(i[0],void 0,{numeric:!0})).map(n=>n[1]).map(n=>{let i=ir(n);return!n.required&&i.length>2&&i.charAt(0)==="["&&i.charAt(i.length-1)==="]"&&(i=i.slice(1,i.length-1)),i}).join(", "),e.hasWildcard&&(r+="..."),e.metadata.validatorDescription&&r&&!r.includes(e.metadata.validatorDescription)&&(r+=` {${e.metadata.validatorDescription}}`)):(Array.isArray(e.options.values)&&e.options.values.length>0?r=e.options.values.map(t=>`${typeof t=="string"?`"${t}"`:we(t)}`).sort((t,n)=>t.localeCompare(n,void 0,{numeric:!0})).join("|"):(r=e.metadata.valueName??(e.isArray?"":e.options.type),e.metadata.validatorDescription&&(!r||r===e.options.type?r=e.metadata.validatorDescription:r=`${r} {${e.metadata.validatorDescription}}`)),r===void 0&&(r="value"),e.isArray&&!r.includes("...")&&(r+="...")),r}function w(e,r={}){let{delimiterOpen:t="\xAB",delimiterClose:n="\xBB",maxLength:i=40}=r;try{if(e===null)return`${t}null${n}`;if(e===void 0)return`${t}undefined${n}`;let o;if(typeof e=="function"&&e.name?o=`${t}${e.name}()${n}`:typeof e=="object"&&!L(e)&&e.constructor?.name?o=`${t}${e.constructor.name}${n}`:o=we(e,{delimiterOpen:t,delimiterClose:n}),typeof e!="string"&&(o.startsWith('"')&&o.endsWith('"')||o.startsWith("'")&&o.endsWith("'"))&&(o=o.slice(1,-1)),ga.test(o)||(o=`${t}${o}${n}`),o.length>40){let s=o.charAt(o.length-1);o=o.slice(0,40)+`...${s}`}return o}catch{return"\uFFFD"}}var ga,_=m(()=>{"use strict";xe();M();ga=/^[^A-Za-z0-9_].+[^A-Za-z0-9_]$/});function Xr(e,r,t,n="at"){r===""?r="(root)":r&&(r=`"${r}"`),t&&(r=r?`${r} property "${t}"`:`property "${t}"`);let i=e;return r&&(i+=` ${n} ${r}`),i}function Ea(e,r,t,n,i){let o=w(r);return o?.length&&(e=`${e} with value ${o}`),Xr(e,t,n,i)}function Aa(e,r,t,n){n===void 0&&(n=new Error("message not found in cause chain"));let i=e?.message??"";if(t=t?`${t} \xAB${i}\xBB`:`\xAB${i}\xBB`,r instanceof RegExp&&r.test(i))return!0;if(i.toLowerCase()===`${r}`.toLowerCase())return!0;if(e.cause instanceof Error)return Aa(e.cause,r,t,n);throw n.message=`\xAB${r}\xBB not found in cause chain ${t}`,n}var u,f,z,fe,Z,Q,be,de,$,O,l=m(()=>{"use strict";_();u=class e extends Error{constructor(r,t,n=!1){let i=t?.cause?t.cause instanceof Error?t.cause:new e(t.cause,void 0,!1):void 0,o=t?.path??t?.location?.path??t?.cause?.path??t?.cause?.location?.path,s=t?.property;!r?.length&&i?.message&&(r=i.message),(!o||r.indexOf(o)===-1)&&(t?.hasOwnProperty("value")?r=Ea(r,t?.value,o,s):r=Xr(r,o,s)),super(r,i?{cause:i}:void 0),t&&(this.data={...t,cause:i});let a=new.target.prototype;Object.setPrototypeOf?Object.setPrototypeOf(this,a):this.__proto__=a,n||delete this.stack,t?.cause&&!super.cause&&(this.cause=t.cause)}get name(){return this.constructor.name}get stack(){return""}set stack(r){}toString(){return this.message?`${this.name}: ${this.message}`:this.cause?.message?`${this.name}: ${this.cause.message}`:this.name}};f=class extends u{},z=class extends u{},fe=class extends u{},Z=class extends u{},Q=class extends u{},be=class extends u{},de=class extends u{},$=class extends u{},O=class extends u{}});function Ke(e,...r){if(!r.length)return e;let t=r.shift();if(Ce(e)&&Ce(t))for(let n in t)L(t[n])?(e[n]||Object.assign(e,{[n]:{}}),Ke(e[n],t[n])):Object.assign(e,{[n]:t[n]});return Ke(e,...r)}function v(e,r){if(e===r)return!0;if(e==null||r==null||typeof e!=typeof r)return!1;if(Array.isArray(e)&&Array.isArray(r)){if(e.length!==r.length)return!1;for(let t=0;t<e.length;++t)if(!v(e[t],r[t]))return!1;return!0}if(typeof e=="object"&&typeof r=="object"){if(Array.isArray(e)||Array.isArray(r))return!1;let t=Object.keys(e);if(t.length!==Object.keys(r).length)return!1;for(let n of t)if(!r.hasOwnProperty(n)||!v(e[n],r[n]))return!1;return!0}return!1}function Sa(e,r,t){if(r===""&&e)throw new Error("Top level path but target is already set");if(r==="")return Array.isArray(t)?[...t]:L(t)?{...t}:t;if(!r||typeof r!="string")throw new Error("Path must be a non-empty string");let n=r.split(".").filter(a=>a!=="");if(n.length===0)throw new Error("Path must contain at least one valid segment");if(e!=null&&typeof e!="object")throw new Error("Target must be an object, an array, or null/undefined");if(e==null){let a=n[0];e=/^\d+$/.test(a)?[]:{}}let i=e;for(let a=0;a<n.length-1;a++){let c=n[a],d=n[a+1],g=/^\d+$/.test(c),S=/^\d+$/.test(d);if(g){let A=parseInt(c,10);if(!Array.isArray(i))throw new Error(`Expected array at path segment '${n.slice(0,a).join(".")}', but found ${typeof i}`);for(;i.length<=A;)i.push(void 0);(i[A]===void 0||i[A]===null)&&(i[A]=S?[]:{}),i=i[A]}else(i[c]===void 0||i[c]===null)&&(i[c]=S?[]:{}),i=i[c]}let o=n[n.length-1];if(/^\d+$/.test(o)){let a=parseInt(o,10);if(!Array.isArray(i))throw new Error(`Expected array at path segment '${n.slice(0,-1).join(".")}', but found ${typeof i}`);for(;i.length<=a;)i.push(void 0);i[a]=t}else i[o]=t;return e}function ee(e,r){if(r==="")return e;if(!e||typeof e!="object"||typeof r!="string")return;let t=r.split(".").filter(i=>i.length>0);if(t.length===0)return;let n=e;for(let i of t){if(!n||typeof n!="object")return;/^\d+$/.test(i)?n=n[Number(i)]:n=n[i]}return n}function Be(e){if(e!=null)if(L(e)){for(let r of Object.keys(e))Be(e[r])===void 0&&delete e[r];return Object.keys(e).length?e:void 0}else if(Array.isArray(e)){for(let r=e.length-1;r>=0;r--){let t=Be(e[r]);t===void 0?r===e.length-1?e.pop():delete e[r]:t!==e[r]&&(e[r]=t)}return e.length?e:void 0}else return e}var re=m(()=>{"use strict";M()});var x,D,G=m(()=>{"use strict";or();te();l();re();x=class e{#e;#r={};#t={};#n={};#i={};#s={};constructor(r,t,n){typeof r=="string"?(this.base=r,t&&this._setAttributes(t),n&&this.addMetadata(n)):r instanceof e||r instanceof C?(this.extend(r),r instanceof e&&(this.base=r.base),t&&this._setAttributes(t),n&&this.addMetadata(n)):typeof r=="object"&&r!==null&&this.extend(r)}get base(){return this.#e}set base(r){this.#e=r}get properties(){return this.#r}get handlers(){return this.#t}get options(){return this.#n}get metadata(){return this.#i}get unionSchemas(){return this.#s}toData(){return Ne(this)}_setAttribute(r,t){if(r==="base")return this.base=t,this;if(r==="metadata")return this.addMetadata(t);if(r==="options")return this.addOptions(t??{});if(r==="handlers")return this.addHandlers(t??{});if(r==="properties")return this.addProperties(t??{});if(r==="unionSchemas")return this.addUnionSchemas(t??{});if(Object.getPrototypeOf(this)?.hasOwnProperty(r)){if(typeof this[r]!="function")throw new u("Unknown attribute!");try{return this[r].call(this,t)}catch{}}return r.startsWith("_")?this.meta(r.slice(1),t):this.option(r,t)}_setAttributes(r={}){if(typeof r!="object")throw new u("Expected an object containing options and metadata attributes");for(let[t,n]of Object.entries(r))this._setAttribute(t,n);return this}property(r,t){if(typeof r!="string")throw new u("Properties must be associated with a valid name");if(t==="string"&&(t=new e(t)),!(t instanceof e)&&!(t instanceof C)){if(t===void 0)return delete this.properties[r],this;throw new u("Property value must be a schema")}return this.properties[r]=t,this.base===void 0&&this.options.type,this.options.container??=!0,this}addProperties(r,t=D.INITIALIZE){if(typeof r!="object")throw new u("Invalid properties definition");for(let[n,i]of Object.entries(r))(t===D.OVERWRITE||this.properties[n]===void 0)&&this.property(n,e.createFromModel(i));return this}option(r,t){if(typeof r!="string")throw new u("Options must be associated with a valid key");if(r.startsWith("_"))throw new u("Option keys cannot have a leading underscore");return t===void 0&&(t=!0),t===null?delete this.options[r]:this.options[r]=t,this}addOptions(r,t=D.INITIALIZE){if(t!==D.INITIALIZE&&t!==D.OVERWRITE)throw new u("Unsupported policy");if(typeof r!="object")throw new u("Options definition must be an object");for(let[n,i]of Object.entries(r))(t===D.OVERWRITE||this.options[n]===void 0)&&this.option(n,i);return this}handler(r,t=[],n=D.APPEND){if(typeof r!="string")throw new u("Handlers must be associated with a valid key");if(!Object.values(D).includes(n))throw new u("Unknown policy");return t===void 0?(n===D.OVERWRITE&&delete this.handlers[r],this):(Array.isArray(t)||(t=[t]),t=t.map(i=>i===void 0?"$undefined":i===null?"$null":i),n===D.INITIALIZE&&Array.isArray(this.handlers[r])?this:n===D.OVERWRITE||n===D.INITIALIZE?(this.handlers[r]=t,this):(Array.isArray(this.handlers[r])||(this.handlers[r]=[]),n===D.PREPEND?this.handlers[r].unshift(...t):this.handlers[r].push(...t),this))}addHandlers(r,t=D.INITIALIZE){if(typeof r!="object")throw new u("Handlers definition must be an object");for(let[n,i]of Object.entries(r))this.handler(n,i,t);return this}meta(r,t){if(typeof r!="string")throw new u("Metadata must be associated with a valid key");return t===void 0&&(t=!0),t===null?delete this.metadata[r]:(r.startsWith("_")&&(r=r.slice(1)),this.metadata[r]=t),this}addMetadata(r,t=D.INITIALIZE){if(typeof r!="object")throw new u("Invalid metadata definition");for(let[n,i]of Object.entries(r))(t===D.OVERWRITE||this.metadata[n]===void 0)&&this.meta(n,i);return this}unionDiscriminator(r){return this.unionDiscriminators(r)}unionDiscriminators(r,t){return this.handler("discriminators",r,t)}unionSchema(r,t){if(!(t instanceof e||t instanceof C))throw new u(`Invalid schema for union member ${r}`);return this.unionSchemas[r]=t,this}addUnionSchemas(r,t=D.INITIALIZE){if(t!==D.INITIALIZE&&t!==D.OVERWRITE)throw new u("Unsupported policy");if(typeof r!="object")throw new u("Invalid union schemas object");for(let[n,i]of Object.entries(r))(t===D.OVERWRITE||this.unionSchemas[n]===void 0)&&this.unionSchema(n,e.createFromModel(i));return this}unionKey(r){return this.options.unionKey=!!(r??!0),this}selector(r){return this.options.selector=!!(r??!0),this}selection(r){return this.options.selection=r??!0,this.condition(async(t,n,i)=>{if(!i.schema.isSelection)throw new u("Conditional expected a selection schema!",{location:i});let o=this.options.selection===!0?i.name:this.options.selection,s=i.parent?.findPropertyLocation(a=>a.schema.isSelector);if(s){let a=s.schema,c=ee(n,s.path);return await a.normalizeValue(c,n,s)===await a.normalizeValue(o,n,s)}return!1}),this}required(r){return this.options.required=r??!0,this}optional(r){return this.options.required=!r,this}default(r){return this.options.default=r,this}deep(r){return this.options.deep=r??!0,this}allowEmpty(r){return this.options.allowEmpty=r??!0,this}allowIncremental(r){return this.options.allowIncremental=r??!0,this}opaque(r=!0){return this.options.allowIncremental=!r,this}strict(r){return this.options.strict=r??!0,this}lax(r){return this.options.strict=r===void 0?!1:!r,this}implicit(r){return this.options.implicit=r??!0,this}value(r){return this.values([r])}values(r=[],t=D.APPEND){return t===D.INITIALIZE&&Array.isArray(this.options.values)?this:((t===D.OVERWRITE||!Array.isArray(this.options.values))&&(this.options.values=[]),Array.isArray(r)||(r=[r]),t===D.PREPEND?this.options.values.unshift(...r):this.options.values.push(...r),this)}condition(r){return this.conditions(r)}conditions(r,t){return this.handler("conditions",r,t)}normalizer(r){return this.normalizers(r)}normalizers(r,t){return this.handler("normalizers",r,t)}transformer(r){return this.transformers(r)}transformers(r,t){return this.handler("transformers",r,t)}finalizer(r){return this.finalizers(r)}finalizers(r,t){return this.handler("finalizers",r,t)}validator(r){return this.validators(r)}validators(r,t){return this.handler("validators",r,t)}serializer(r){return this.serializers(r)}serializers(r,t){return this.handler("serializers",r,t)}extend(r,t=new Map){if(typeof r!="object")throw new u("Invalid schema to extend");return!this.base&&r.base&&(this.base=r.base),this.addProperties(Object.fromEntries(Object.entries(r.properties??{}).map(([n,i])=>[n,e.createFromModel(i,t)]))),this.addUnionSchemas(Object.fromEntries(Object.entries(r.unionSchemas??{}).map(([n,i])=>[n,e.createFromModel(i,t)]))),this.addOptions(r.options??{}),this.addMetadata(r.metadata??{}),this.addHandlers(r.handlers??{}),this}clone(){return e.createFromModel(this)}static createFromModel(r,t=new Map){if(typeof r=="string")return new e(r);if(t.has(r))return t.get(r);let n=new e;return t.set(r,n),r.base&&(n.base=r.base),n.extend(r,t)}static create(r,t,n){return new e(r,t,n)}static literal(r,t,n){let i="any";typeof r=="string"?i="string":typeof r=="number"?i="number":typeof r=="boolean"&&(i="boolean");let o=new e(i).option("values",[r]).option("default",r).option("compileHook",(s,a)=>{if(s==="finalize"){if(a.options.values?.length!==1)throw new u("Literal schema needs one value defined");if(a.hasChildren)throw new u("Literal schema should not have child properties");if(a.isUnion)throw new u("Literal schema should not be a union")}}).transformer(()=>r);return t&&o._setAttributes(t),n&&o.addMetadata(n),o}static inherit(r){return new e().option("reference",!0).transformer((t,n,i,o)=>{let s=r??i.name;if(i.parent===void 0){if(i.schema.strict!==!1)throw new u("A top-level schema cannot have an inherited value");return}let a=i.parent?.parent;for(;a!==void 0;){let c=a.relative(s);if(c!==void 0)return ee(n,c.path);a=a.parent}if(i.schema.strict!==!1)throw new u(`Inherited property "${s}" not found in any ancestor of "${i}"`)}).serializer(()=>{}).default((t,n,i)=>r??i.name).meta("omitFromSerialize").meta("internal")}static reference(r,t=!1){let n=r?.charAt(0);return(n==="^"||n==="/"||n===".")&&(t=!0),new e().option("reference",!0).default(r).normalizer(()=>r).transformer((i,o,s,a)=>{let c=t?s.relative(r):s.absolute(r);if(c===void 0)throw new u(`Reference path ${r} not found`);if(c.schema===void 0){if(a?.context?.final)throw new u(`Schema for reference path ${r} not found`);return}return ee(o,c.path)}).validator((i,o,s,a)=>{let c=t?s.relative(r):s.absolute(r);if(c===void 0)throw new u(`Reference path ${r} not found`);let d=c.schema;if(d===void 0){if(a?.context?.final)throw new u(`Schema for reference path ${r} not found`);return}if(ee(o,c.path)===i)return i;if(!d?.hasChildren||d.isOpaque)throw new u(`Reference is not exactly the same as ${r}`);return i}).serializer(()=>{}).meta("omitFromSerialize").meta("internal")}},D=Object.freeze({INITIALIZE:Symbol("INITIALIZE"),OVERWRITE:Symbol("OVERWRITE"),APPEND:Symbol("APPEND"),PREPEND:Symbol("PREPEND")})});function Ne(e,r=new WeakMap){if(typeof e!="object")throw new u("Not a schema!");if(r.has(e))return r.get(e);let t={};r.set(e,t),!(e instanceof C)&&e.base&&(t.base=e.base);for(let n of["properties","unionSchemas","metadata","options","handlers"])if(e[n])for(let[i,o]of Object.entries(e[n])){t[n]===void 0&&(t[n]={});let s=o instanceof x||o instanceof C,a=o;s?a=Ne(o,r):n==="handlers"&&Array.isArray(o)&&(a=o.map(c=>c===null?"$null":c===void 0?"$undefined":typeof c=="object"&&c.spec!==void 0?c.spec:c)),t[n][i]=a}return t}var or=m(()=>{"use strict";te();G();l()});function q(e){return e instanceof T?e:typeof e=="function"?new We(e):new B(e)}var T,We,B,gr,Ue,vr,Gr,Y=m(()=>{"use strict";T=class{execute(r,...t){return r}get isConstant(){return!1}},We=class extends T{#e;constructor(r){super(),this.#e=r}execute(r,...t){return this.#e(r,...t)}},B=class extends T{#e;constructor(r){super(),this.#e=r}execute(){return this.#e}get isConstant(){return!0}},gr=new B(null),Ue=new B(void 0),vr=new B(!0),Gr=new B(!1)});var F,oe=m(()=>{"use strict";F=Symbol("EMPTY")});var sr,Jr=m(()=>{"use strict";l();oe();re();M();sr=class{#e;#r;#t;#n;#i;#s;#o=new Map;#u;#a=void 0;#h=new Set;#w=void 0;#m=void 0;#c;#d=!1;#y=!1;#f=void 0;#g=!1;#p=void 0;#l;executorCache={};constructor(r,t){if(this.#e=r,this.#r=t,this.#i=r.root.absolute(t),this.#r==="")this.#t="";else{let n=this.#r.lastIndexOf("."),i=n===-1?"":this.#r.slice(0,n);this.#s=this.#e.getState(i),this.#t=n===-1?this.#r:this.#r.slice(n+1),this.#s.#o.set(this.#t,this)}this.#n=/^\d+$/.test(this.#t)?Number(this.#t):this.#t,this.#i?.schema!==void 0&&!this.#i.schema.hasConditions&&(this.#c=!0),this.completed=!1}get context(){return this.#e}get parent(){return this.#s}get path(){return this.#r}get name(){return this.#t}get key(){return this.#n}get location(){return this.#i===void 0&&(this.#i=this.context.root.absolute(this.path)),this.#i}set location(r){this.#i=r}get schema(){return this.location?.schema}set schema(r){if(this.location===void 0||r===void 0)throw new u("Inconsistent traversal state",{location:this.location});let t=this.schema;if(t&&t!==r){if(t.isUnion){if(this.unionKey=t.findUnionKey(r),!this.unionKey)throw new u("Union resolved to an unknown schema");this.executorCache={},this.location.schema=r,this.invalidate(),this.invalidateChildren()}this.context.update()}this.location.schema=r,r.hasConditions||(this.#c=!0)}get condition(){return this.#c}set condition(r){if(this.#c!==r){if(r===!1&&this.#c===!0)return;this.context.update()}this.#c=r}get unionKey(){return this.#p?this.#p[0]:void 0}set unionKey(r){r===void 0?this.#p=void 0:(this.#p??=[],this.#p.unshift(r))}getChildState(r){return r===""?this:this.#o.get(r)??this.context.getState(this.path?`${this.path}.${r}`:`${r}`)}getRelativeState(r){let t=this.location?.relative(r);return t?this.context.getState(t):void 0}get assignedInput(){return this.#u}set assignedInput(r){if(r===null){this.value=null;return}v(r,this.#u)||(this.context.update(),this.processed=!1,this.completed=!1,this.#u=r)}get input(){return this.#a}set input(r){if(r===null){this.value=null;return}if(!v(r,this.#a)&&(this.context.update(),this.processed=!1,this.completed=!1,this.#a=r,this.schema!==void 0)){if(!this.schema?.hasChildren&&r!==void 0&&(this.mandatory=!0),this.schema.hasChildren){if(L(r)||typeof r=="object"&&this.isIncremental){for(let[t,n]of Object.entries(r))if(n!=null){let i=this.getChildState(t);i.assignedInput=n}}else if(Array.isArray(r))for(let t=0;t<r.length;++t){let n=r[t];if(n!=null){let i=this.getChildState(`${t}`);i.assignedInput=n}}}this.schema?.hasChildren&&!this.schema.isUnion&&r!==F&&(!H(r)||this.schema.options.allowEmpty)&&(this.mandatory=!0)}}get pending(){return this.#w}set pending(r){r===null&&(this.value=null,this.#w=void 0),this.#w=r}get value(){return this.#m}set value(r){if(this.#m!==void 0&&r===void 0)throw new u("Cannot unset value",{location:this.location});if(this.#m!==r){if(this.isPruned)throw new u(`Cannot set value at ${this.path} - node is pruned`);if(He(r)&&this.schema?.hasChildren&&!this.schema?.isImplicit&&!this.schema?.isOpaque)throw new u("Container processing resulted in unexpected primitive",{value:r,location:this.location});this.#m=r,this.context.update(),r===void 0&&(this.completed=!1),this.path===""&&(this.processed=!0),r!==void 0&&this.#h.add(this.assignedInput),r===null&&!this.processed&&(this.processed=!0,this.completed=!0)}}copyPendingChildValues(r,t){if(t!==void 0&&!this.isOpaque&&this.hasChildren&&t!==r&&Ce(t)&&Ce(r))for(let[n,i]of Object.entries(r)){if(i===void 0)continue;let o=this.#o.get(n);o?.schema&&!o.schema.isImplicit&&(o.isPruned?t[n]!==void 0&&delete t[n]:t[n]!==i&&(t[n]=i))}}invalidate(){this.#c=this.location?.schema&&!this.location.schema.hasConditions?!0:void 0,this.#m=void 0,this.#d=!1,this.#l=void 0,this.#f=void 0,this.context.update()}get mandatory(){return this.#g}set mandatory(r){this.#g=!!r}get processed(){return this.#d}set processed(r){this.#d=!!r,this.#d&&this.hasChildren}get isRequired(){if(this.#f!==void 0)return this.#f;if(this.schema?.required)this.#f=!0;else if(!this.hasChildren)this.#f=!1;else if(this.isDeep){for(let r of this.#o.values())if(r.isRequired){this.#f=!0;break}}return this.#f??!1}get isComplete(){return this.completed||this.isPruned||!this.condition&&this.context.final?!0:this.value===void 0&&(this.isRequired||this.schema?.default!==void 0&&(typeof this.schema.default!="function"||this.schema.options.dynamic===!1))||this.hasIncompleteDescendents||this.hasWorkInProgress||this.isUnion?!1:this.processed||this.schema?.isImplicit||this.value!==void 0?!0:this.schema?.isReference&&!this.context.final||this.mandatory?!1:typeof this.assignedInput=="function"&&this.schema?.options.dynamic!==!1&&this.input===void 0?this.context.final:this.assignedInput!==void 0&&!this.#h.has(this.assignedInput)?!1:this.assignedInput===void 0&&this.context.traversals>0?!0:!!(this.assignedInput===void 0&&this.context.final)}get completed(){return this.#y}set completed(r){this.#y=!!r,!this.#y&&this.parent?.completed&&(this.parent.completed=!1)}get hasProcessedInput(){return this.value!==void 0&&this.assignedInput!==void 0&&this.input!==void 0&&this.#h.has(this.assignedInput)}get isPlaceholder(){return this.schema?.default!==void 0?!1:!this.mandatory&&this.value===void 0}get hasChildren(){return this.schema?.hasChildren??!1}get isContainer(){return this.schema?.isContainer??!1}get isPruned(){return this.#m===null||!!this.#s?.isPruned}get isDeep(){return this.schema?.deep??this.context.deep}get isOpaque(){return this.schema===void 0?!0:!this.hasChildren||this.schema.isOpaque}get isIncremental(){return this.schema===void 0?!1:this.hasChildren&&!this.schema.isOpaque}get isStrict(){return this.schema===void 0?this.parent?.isStrict??this.context.strict:this.schema.strict??this.context.strict}get allowUnknown(){return!this.isStrict}get isUnion(){return this.schema?.isUnion??!1}get isUnresolved(){return this.schema===void 0||this.schema.isUnion}get treatAsExplicit(){return this.schema===void 0?!0:this.schema.isImplicit?!1:!(this.hasChildren&&this.isIncremental)}get hasDescendentStates(){return this.hasChildren?this.#o.size>0:!1}get hasDescendentsToTraverse(){if(!this.hasChildren)return!1;let r=typeof this.#a=="object"&&!H(this.#a);return this.hasDescendentStates||r}get hasIncompleteDescendents(){return this.hasChildren?[...this.#o.values()].some(r=>!r.completed):!1}get incompleteDescendents(){if(!this.hasChildren)return[];let r=this.path?`${this.path}.`:"";return Array.from(this.#e.stateMap.values()).filter(t=>t.path!==this.path&&t.path.startsWith(r)&&!t.isComplete)}findIncompleteChildNames(r=new Set){for(let t of this.#o.values())t.completed||r.add(t.name);return r}listIncompleteChildren(){return[...this.#o.values()].filter(r=>!r.isComplete).map(r=>r.name)}listPendingChildren(){return[...this.#o.values()].filter(r=>r.hasWorkInProgress||r.needsInputProcessing).map(r=>r.name)}invalidateChildren(){for(let r of this.#o.values())r.value!==null&&r.invalidate()}get isEmptyPlaceholder(){return!this.schema?.hasChildren||!this.isPlaceholder?!1:!this.hasDescendentsToTraverse}get needsInputProcessing(){return this.value!==void 0?!1:typeof this.assignedInput!==void 0&&(this.input===void 0||this.pending===void 0)}get hasWorkInProgress(){return this.isPruned||this.pending===void 0||this.schema?.isImplicit?!1:this.hasChildren&&H(this.pending)?this.schema?.options.allowEmpty?!0:this.processed?!1:!!this.mandatory:!0}get activePropertyStates(){if(this.completed)return[];if(this.schema===void 0)return[];if(this.isOpaque&&this.processed)return[];if(!this.condition)return[];if(this.pending===void 0&&this.value===void 0&&!this.schema.options.allowUndefined&&!this.schema.options.deep)return[];if(!this.schema.hasChildren)return[];let r=new Set,t=this.input;if((L(t)||Array.isArray(t)||t&&this.isIncremental)&&Object.keys(t).forEach(o=>{r.add(o)}),this.findIncompleteChildNames(r),this.isIncremental||this.value===void 0)for(let[o,s]of this.schema.propertyEntries)o!=="*"&&(this.context.final||this.isDeep||s.required||s.default!==void 0||s.isReference)&&r.add(o);let n=this.pending??(this.isIncremental?this.value:void 0),i=Array.isArray(n)&&n.length||L(n)&&Object.keys(n).length;return!i&&!this.mandatory&&this.input===void 0&&!this.isDeep&&!this.hasIncompleteDescendents?[]:(i&&this.context.final&&Object.keys(n).forEach(o=>{(this.isStrict||this.schema?.getPropertySchema(o))&&r.add(o)}),[...r].map(o=>this.getChildState(o)))}get target(){return this.context.getValue()}get options(){return this.#l===void 0&&(this.#l={...this.context.options,deep:this.isDeep,strict:this.isStrict,state:this,context:this.context}),this.#l}}});function Er(...e){(globalThis[xa]??console.log)?.(...e)}var xa,Ar=m(()=>{"use strict";xa=Symbol.for("@versionzero/debug-sink")});var ue,Sr=m(()=>{"use strict";qe();Jr();Ar();nr();te();oe();l();ue=class{constructor(r,t={}){this.root=r instanceof C?new j(r):r,this._final=!1,this._options={...t,deep:t.deep??!1,strict:t.strict??!0,debug:t.debug??!1,stats:t.stats??{}},this.traversals=0,this.counter=0,this.stateMap=new Map,this._debugEnabled=t?.debug??!1,this.compiling=!1}get options(){return this._options}get deep(){return this._options.deep}get strict(){return this._options.strict}get stats(){return this._options.stats}update(){this.counter++,this.final=!1}_finalizeCount=0;set final(r){if(this._final&&!r&&this._finalizeCount++>100)throw new u("Unable to finalize a stable output value");this._final=r??!0}get final(){return!!this._final}finalize(){return this._final=!0,this}get isComplete(){for(let r of this.stateMap.values())if(!r.isComplete)return!1;return!0}get incomplete(){let r=new Set;for(let t of this.stateMap.values())t.isComplete||r.add(t.path);return r}setValue(r){this._value=r}getValue(){return this._value!==void 0?this._value:this.getState("")?.value}setAssignedInput(r,t=""){if(r===void 0)return;let n=this.getState("");for(;t;){let[i,o]=Me(t),s=n.getChildState(i);n.assignedInput??=F,n=s,t=o,n.mandatory=!0}n.assignedInput=r,n.mandatory=!0}getState(r){r instanceof j&&(r=r.path);let t=this.stateMap.get(r);if(t===void 0){let n=this;t=new sr(n,r),n._value,this.stateMap.set(r,t)}return t}_debug(...r){this._debugEnabled&&Er({contextName:"context"},...r)}traverse(r){let t=this.getState(""),n=!1,i=s=>(this.traversals++,this.stats.traversals=this.traversals,this.stats.updates=this.counter,this.isComplete?n=!0:this.counter===s?this.final?n=!0:this.final=!0:this.final=!1,n),o=()=>{let s;for(;!n;){let a=this.counter;if(s=r.execute(t),s instanceof Promise)return s.then(c=>i(a)?c:o(),c=>{throw c});i(a)}return s};return o()}}});var ae,Ye=m(()=>{"use strict";Y();ae=class extends T{#e;constructor(r=[]){Array.isArray(r)||(r=[r]),super(),this.#e=r.map(t=>q(t))}execute(r,...t){let n=0,i=this.#e;for(;n<i.length;)if(r=i[n++].execute(r,...t),r instanceof Promise)return r.then(o=>this.#r(o,t,n));return r}async#r(r,t,n){for(;n<this.#e.length;){let i=r;r=await this.#e[n++].execute(r,...t)}return r}}});var N,se=m(()=>{"use strict";Y();N=class extends T{#e;#r;constructor(r,t){super(),this.#r=r,this.#e=t}get description(){return this.#e}set description(r){this.#e=r}get spec(){return this.#r}set spec(r){this.#r=r}execute(r,t,n,i){return r}}});var me,Qr=m(()=>{"use strict";Y();me=class extends T{#e;constructor(r=[]){Array.isArray(r)||(r=[r]),super(),this.#e=r.map(t=>q(t))}execute(r,...t){if(r==null)return r;let n=0,i=this.#e;for(;n<i.length;){if(r=i[n++].execute(r,...t),r==null)return r;if(r instanceof Promise)return r.then(o=>this.#r(o,t,n))}return r}async#r(r,t,n){for(;n<this.#e.length;){if(r==null)return r;r=await this.#e[n++].execute(r,...t)}return r}}});function xr(e){let r=e.parent;if(r){if(e.assignedInput===void 0||e.assignedInput===F){let t=r.input?.[e.key];t!==void 0&&(e.assignedInput=t)}e.schema?.isImplicit&&!e.isPruned&&(e.value??=r.value?.[e.key])}if(e.isPruned)return null;if(!e.completed)return e}var et=m(()=>{"use strict";oe()});function Cr(e){if(e.schema!==void 0)return e;let r=e.parent;if(r===void 0)throw new z("invariant: root path schema must be defined");if(r.schema===void 0)throw new z("invariant: cannot process a child if parent schema is undefined");if(!r.schema.isUnion||e.context.final)if(r?.schema?.strict??r?.context.strict){let i=e.context.root.schema?.isValidPath(e.path)?"Unexpected property":"Unknown property";throw new z(i,{path:e.path})}else return e.value=null,null}var rt=m(()=>{"use strict";l()});function tt(e){return e.assignedInput===void 0&&e.pending===void 0&&e.value===void 0&&(e.schema?.default!==void 0?(e.assignedInput=e.schema.default,e.mandatory=!0):e.isDeep&&e.isContainer&&(e.assignedInput=F)),e}var nt=m(()=>{"use strict";oe()});function it(e){if(e.processed&&e.hasProcessedInput)return e;if(e.assignedInput===null)return null;if(e.assignedInput===void 0)return e;if(e.location===void 0)return;let t=e.location.schema._normalizeValue(e.assignedInput,e.target,e.location,e.options),n=i=>(e.input=i,i===null?null:e);return t instanceof Promise?t.then(n):n(t)}var ot=m(()=>{"use strict"});function st(e){if(e.input===null)return null;if(e.schema!==void 0)return e.schema.isImplicit||e.input===void 0||e.schema.ensureAccepts(e.input),e}var at=m(()=>{"use strict"});function Ze(e){if(!e.schema?.isUnion||!e.location)return e;let r=e.pending??e.input??e.value,t=e.schema._discriminateUnion(r,e.target,e.location,{...e.options,strict:e.context.final}),n=i=>{if(i){if(e.schema=i,i.isUnion)return Ze(e)}else if(e.context.final)throw new de("Unable to resolve union",{location:e.location});return e};return t instanceof Promise?t.then(i=>n(i)):n(t)}var ct=m(()=>{"use strict";l()});function ar(e){if(e.condition===!0)return e;if(e.schema===void 0)return;let r=e.schema._checkCondition(e.input,e.context.getValue(),e.location,e.options),t=n=>(e.condition=n,!n&&e.context.final&&(e.value=null),n?e:e.context.final?null:void 0);return r instanceof Promise?r.then(n=>t(n)):t(r)}var ft=m(()=>{"use strict"});function ut(e){if(e.location===void 0)return;let r=e.location.schema;if(e.input===void 0&&!r.options.allowUndefined)return e;if(e.hasChildren){if(e.pending!==void 0)return e;if(e.value!==void 0){if(e.isIncremental)return e.pending=e.value,e;throw new u("Value already processed",{location:e.location})}let t=r._normalizeValue(F,e.target,e.location,e.options);return t instanceof Promise?t.then(n=>(e.pending=n,e)):(e.pending=t,e)}else return e.pending=e.input,e}var mt=m(()=>{"use strict";oe();l()});function pt(e){if(e.value!==void 0&&(e.value===e.pending||e.hasChildren&&e.isIncremental&&v(e.pending,e.value)))return e.pending=void 0,e;if(e.pending===void 0||e.schema===void 0||e.isUnion||e.schema.isImplicit||e.hasChildren&&e.isOpaque||e.hasChildren&&!e.mandatory&&H(e.pending))return e;let r=e.schema._transformValue(e.pending,e.target,e.location,e.options),t=n=>(n!==void 0&&(n!==e.value&&e.hasChildren&&e.copyPendingChildValues(e.pending,n),e.pending=void 0,e.value=n),e.value===null?null:e);return r instanceof Promise?r.then(t):t(r)}var dt=m(()=>{"use strict";re();M()});function lt(e){if(e.isPruned)return null;if(e.isComplete)return e;if(!e.condition)return;if(e.schema===void 0||e.isUnion)return e;if(e.value!==void 0&&(e.value===e.pending||e.hasChildren&&e.isIncremental&&v(e.pending,e.value)))return e.pending=void 0,e;if(e.pending===void 0||e.schema?.isImplicit||!e.hasWorkInProgress||e.hasChildren&&e.isOpaque&&e.hasIncompleteDescendents||e.hasChildren&&e.isIncremental&&!e.mandatory&&H(e.pending)&&!e.schema.options.allowEmpty)return e;let r=e.schema._transformValue(e.pending,e.target,e.location,e.options),t=n=>(n!==void 0&&(n!==e.value&&e.hasChildren&&e.copyPendingChildValues(e.pending,n),e.pending=void 0,e.value=n),e.value===null?null:e);return r instanceof Promise?r.then(t):t(r)}var ht=m(()=>{"use strict";re();M()});function br(e){if(!e.condition)return e;if(e.context.final&&e.isRequired&&e.value===void 0)throw new z("Undefined required value",{path:e.path});return e}var wt=m(()=>{"use strict";l()});function Rr(e){if(e.completed)return e;if(!(e.context.final||e.isComplete)){let i=e.isComplete;return e}if(e.schema===void 0){if(e.allowUnknown)return e;throw new z("Unknown value",{path:e.path})}if(e.schema.isUnion)throw new z("Unable to resolve union",{path:e.path});if(e.value===void 0&&e.schema.isReference&&!e.isRequired)return e;if(e.hasWorkInProgress){if(e.value===void 0&&!e.isRequired)return e;let i=e.hasWorkInProgress;throw new z("Incomplete assignment",{value:e.pending,path:e.path})}if(e.value===void 0)return e;let t=e.schema._validateValue(e.value,e.target,e.location,e.options),n=i=>(i!==e.value&&(e.value=i),e);return t instanceof Promise?t.then(n):n(t)}var yt=m(()=>{"use strict";l()});function Xe(e){if(e.value===null||e.value===void 0&&e.input!==void 0)return e;if(e.completed)return;let r=e.parent;if(e.completed=e.isComplete,r===void 0)return e.isUnion||(e.processed=!0),e;let t=r.pending??r.value;if(t===null)return null;if(t===void 0||typeof t!="object"){let i=`${t}`;i.length>20&&(i=i.slice(0,20)+"...");let o=i.length?`\xAB${i}\xBB is not a valid container (set opaque option?)`:"Not a valid container (set opaque option?)";throw new u(o,{path:r.path})}let n=e.key;return e.schema?.isImplicit?(e.value??=t[n],e.processed=!0):(t[n]!==e.value&&(t[n]=e.value,e.context.update()),e.isUnion||(e.processed=!0)),e}var gt=m(()=>{"use strict";l()});function $r(e){if(e.assignedInput===void 0&&e.parent&&(e.assignedInput=e.parent.input?.[e.key]),e.isPruned)return null;if(!e.completed)return e.input=e.assignedInput,e.schema!==void 0&&(e.pending=e.input),e}var Et=m(()=>{"use strict"});function Pr(e){if(e.schema!==void 0)return e.input===void 0&&!e.schema.options.allowUndefined||(e.isUnion?e.pending??=e.input:(e.value=e.pending??e.input,e.pending=void 0)),e}var At=m(()=>{"use strict"});function Tr(e){return e==="true"||e==="1"||e==="yes"||e==="enabled"||e==="active"||e==="on"}function Or(e){return e==="false"||e==="0"||e==="no"||e==="disabled"||e==="inactive"||e==="off"||e===""||e==="undefined"||e==="null"||e==="none"}function J(e){if(typeof e=="boolean")return e;if(typeof e=="string"){let r=e.toLowerCase().trim();if(Tr(r))return!0;if(Or(r))return!1}return e instanceof Error?!1:!!e}function Ir(e){if(typeof e=="boolean")return!e;if(typeof e=="string"){let r=e.toLowerCase().trim();if(Tr(r))return!1;if(Or(r))return!0}return e instanceof Error?!0:!e}var le=m(()=>{"use strict"});function St(e){if(e.schema===void 0)return;let r=e.schema;if(e.assignedInput===null||r.isImplicit||J(r.metadata.omitFromSerialize))return null;if(e.assignedInput===void 0)return e;let t=r._serializeValue(e.assignedInput,e.target,e.location,e.options),n=i=>i===null?(e.value=null,null):(e.pending??=e.hasChildren?r.isArray||Array.isArray(t)?[]:{}:i,e.isUnion||(e.value=e.pending),e.input=i,e);return t instanceof Promise?t.then(n):n(t)}var xt=m(()=>{"use strict";le()});function Ct(e){if(e.completed)return e;if(e.schema===void 0){if(e.allowUnknown)return e;throw new Q("Unknown value",{path:e.path})}if(!e.schema.requiresFinalization)return e;if(!(e.context.final||e.isComplete))return;if(e.schema.isUnion)throw new Q("Unable to resolve union",{path:e.path});if(e.value===void 0&&e.schema.isReference&&!e.isRequired)return e;if(e.hasWorkInProgress){if(e.value===void 0&&!e.isRequired)return e;let i=e.hasWorkInProgress;throw new Q("Incomplete assignment",{value:e.pending,path:e.path})}if(e.value===void 0)return e;let t=e.schema._finalizeValue(e.value,e.target,e.location,e.options),n=i=>(i!==e.value&&(e.value=i),e);return t instanceof Promise?t.then(n):n(t)}var bt=m(()=>{"use strict";l()});var ne,Re=m(()=>{"use strict";Y();ne=class extends T{#e;#r;#t;constructor(r,t,n){super(),this.#e=q(r),this.#r=t,this.#t=n}execute(r,...t){let n=this.#r?this.#r(r):r;if(!n)return r;Array.isArray(n)||(n=[n]);let i=!0,o=n.map(s=>{let a=this.#e.execute(s,...t);return i&&a instanceof Promise&&(i=!1),a});return i?this.#t?this.#t(o,r):o:Promise.all(o).then(s=>this.#t?this.#t(s,r):s)}}});var I,_r=m(()=>{"use strict";Y();le();I=class e extends T{#e;#r;#t;#n;#i;constructor(r=[],t=[]){Array.isArray(r)||(r=[r]),super(),this.#e=r.map(n=>q(n));for(let n of t)if(n===e.ALL_CRITERIA)this.#r=n;else if(n===e.ANY_CRITERIA)this.#r=n;else if(n===e.EXCLUSIVE_CRITERIA)this.#r=n;else if(n===e.SUCCESS_CHECK)this.#t=n;else if(n===e.DEFINED_CHECK)this.#t=n;else if(n===e.TRUTHY_CHECK)this.#t=n;else if(n===e.INPUT_RETURN)this.#n=n;else if(n===e.RESULT_RETURN)this.#n=n;else if(n===e.RETHROW_ERRORS)this.#i=n;else if(n===e.CAPTURE_ERRORS)this.#i=n;else throw new Error("Unknown flag");this.#r??=e.ALL_CRITERIA,this.#t??=e.SUCCESS_CHECK,this.#n??=e.INPUT_RETURN,this.#i??=e.RETHROW_ERRORS}execute(r,...t){let n,i=0,o=0,s=0,a=()=>{switch(this.#r){case e.ANY_CRITERIA:return i>0;case e.EXCLUSIVE_CRITERIA:return i===1&&s===this.#e.length;case e.ALL_CRITERIA:return i===this.#e.length}return!1},c=()=>{switch(this.#r){case e.ANY_CRITERIA:return i===0&&s===this.#e.length;case e.EXCLUSIVE_CRITERIA:return i>1;case e.ALL_CRITERIA:return o>0}return!1},d=async()=>{for(;s<this.#e.length&&!(c()||a());)try{let p=await this.#e[s++].execute(r,...t);g(p)}catch(p){if(this.#t===e.SUCCESS_CHECK)return;S(p)}return A()},g=p=>{(this.#t===e.TRUTHY_CHECK?J(p):this.#t===e.DEFINED_CHECK?p!==void 0:!0)?i++:o++,c()||(n=p)},S=p=>{if(this.#i===e.RETHROW_ERRORS)throw p;o++},A=()=>{if(a())return this.#n===e.RESULT_RETURN?n:r},E=this.#e;for(;s<E.length;){let p;try{if(p=E[s++].execute(r,...t),p instanceof Promise)return p.then(b=>(g(b),d()),b=>(S(b),d()));g(p)}catch(b){if(S(b),this.#t===e.SUCCESS_CHECK)return}if(c()||a())break}return A()}static ANY_CRITERIA=Symbol("ANY-CRITERIA");static ALL_CRITERIA=Symbol("ALL-CRITERIA");static EXCLUSIVE_CRITERIA=Symbol("EXCLUSIVE-CRITERIA");static TRUTHY_CHECK=Symbol("TRUTHY-CHECK");static DEFINED_CHECK=Symbol("DEFINED-CHECK");static SUCCESS_CHECK=Symbol("SUCCESS-CHECK");static RESULT_RETURN=Symbol("RESULT-RETURN");static INPUT_RETURN=Symbol("INPUT-RETURN");static RETHROW_ERRORS=Symbol("RETHROW-ERRORS");static CAPTURE_ERRORS=Symbol("CAPTURE-ERRORS")}});var ve,Rt=m(()=>{"use strict";_r();ve=class extends I{constructor(r=[]){Array.isArray(r)||(r=[r]),super(r)}}});var $e,$t=m(()=>{"use strict";Y();Re();Rt();$e=class extends T{#e;constructor(r,t){super();let n=q(r),i=q(t),o=new ve(new ne(this,(s=>s?.activePropertyStates??[])));this.#e=new ve([n,o,i])}execute(r){return this.#e.execute(r)}}});var Ca,ba,Pt,Ra,$a,Tt,Pa,Ta,Ot,Oa,Ia,kr,It=m(()=>{"use strict";Qr();et();rt();nt();ot();at();ct();ft();mt();dt();ht();wt();yt();gt();Et();At();xt();bt();$t();Ca=new me([xr,Cr,tt,it,st,Ze,ar,ut,pt]),ba=new me([lt,Ct,br,Rr,Xe]),Pt=new $e(Ca,ba),Ra=new me([$r,Ze,ar,Pr]),$a=new me([br,Rr,Xe]),Tt=new $e(Ra,$a),Pa=new me([xr,Cr,St,Ze,ar]),Ta=new me([Xe]),Ot=new $e(Pa,Ta),Oa=new me([$r,Pr]),Ia=new me([Xe]),kr=new $e(Oa,Ia)});var C,te=m(()=>{"use strict";or();qe();Sr();Ye();se();oe();It();l();re();le();M();_();C=class e{static __TOKEN=Symbol("CONSTRUCT_USING_COMPILER");#e=new Map;#r;#t=new Map;#n;#i=new Map;#s={};#o={};#u={};#a=!1;constructor(r){if(r!==e.__TOKEN)throw new u("CompiledSchema must be created via compilation")}get options(){return this.#o}get metadata(){return this.#u}get properties(){return this.#r??=Object.freeze(Object.fromEntries(this.#e))}get propertyEntries(){return this.#e.entries()}get handlers(){return this.#s}getValueProcessor(r){return this.#i.get(r)}_setValueProcessor(r,t){return this.#i.set(r,t),t}get unionSchemas(){return this.#n??=Object.freeze(Object.fromEntries(this.#t))}get unionSchemaEntries(){return this.#t.entries()}toData(){return Ne(this)}get hasChildren(){return this.#e.size>0}get isContainer(){return this.hasChildren||!!this.options.container}get hasWildcard(){return this.#e.has("*")}get isArray(){return this.options.type==="array"}get isFunction(){return this.options.type==="function"}get isUnion(){return this.#t.size>0}get isUnionKey(){return!!this.options.unionKey}get isSelector(){return!!this.options.selector}get hasChildSelector(){for(let r of this.#e.values())if(r.isSelector)return!0;return!1}get isSelection(){return this.options.selection!==void 0&&this.options.selection!==!1}get hasChildSelection(){for(let r of this.#e.values())if(r.isSelection)return!0;return!1}get selection(){return this.options.selection}get values(){return this.options.values}get hasValues(){let r=this.options.values;return Array.isArray(r)&&r.length>0}get strict(){return this.options.strict}get required(){return this.options.required??!1}get default(){return this.options.default}get deep(){if(this.options.deep!==void 0)return this.options.deep;if(this.hasChildren&&this.required)return!0}get isReference(){return this.options.reference??!1}get isImplicit(){return this.options.implicit??!1}get allowIncremental(){return this.options.allowIncremental??this.hasChildren}get isOpaque(){return!this.hasChildren||this.options.allowIncremental===!1}_checkCondition(r,t,n=new j(this),i){if(n.schema!==this)return n.schema._checkCondition(r,t,n,i);if(r instanceof Error&&!this.options.allowErrors)return!1;let o=this.getValueProcessor("conditions");if(!o)return!0;try{let s=o.execute(r,t,n,i);return s instanceof Promise?s.then(a=>a instanceof Error&&!this.options.allowErrors?!1:J(a),a=>!1):s instanceof Error&&!this.options.allowErrors?!1:J(s)}catch{return!1}}async checkCondition(r,t,n=new j(this),i){return this._checkCondition(r,t,n,i)}get hasConditions(){let r=this.handlers.conditions;return!!(r&&Array.isArray(r)&&r.length)}get requiresFinalization(){let r=this.handlers.finalizers;return!!(r&&Array.isArray(r)&&r.length)}_checkValue(r,t){if(r instanceof Error&&!this.options.allowErrors){if(t&&r instanceof t)throw r;{let n=new t(r.message,{cause:r});throw Error?.captureStackTrace(n,this._checkValue),n}}return r}_discriminateUnion(r,t,n=new j(this),i={}){if(n.schema!==this)return n.schema._discriminateUnion(r,t,n,i);let o=this.getValueProcessor("discriminators");if(!this.isUnion||!o)return;if(r instanceof Error&&!this.options.allowErrors){if(i?.strict)throw r;return}let s;try{s=o.execute(r,t,n,i)}catch(a){if(i?.strict)throw a;return}return s instanceof Promise?s.then(a=>this.getUnionSchema(a),a=>{if(i.strict)throw a}):this.getUnionSchema(s)}async discriminateUnion(r,t,n=new j(this),i){return this._discriminateUnion(r,t,n,i)}_normalizeValue(r,t,n=new j(this),i={}){if(n.schema!==this)return n.schema._normalizeValue(r,t,n,i);if(r instanceof Error&&!this.options.allowErrors)throw new fe(r.message,{cause:r});let o=i?.sync??!1,s=i?.dynamic??this.options?.dynamic??!0;if((typeof r=="function"||r instanceof N)&&s&&!i.compiling){let d=r instanceof N?r.execute(!0,t,n,i):r(!0,t,n,i);if(d instanceof Promise){if(o)throw new fe("Encountered an async value function during a forced-sync normalization",{location:n});return d.then(g=>g==null?g:this._normalizeValue(g,t,n,{...i,dynamic:!1}))}r=d}if(r===null||r===void 0&&!this.options.allowUndefined)return r;let a=this.getValueProcessor("normalizers");if(a===void 0)return this.isContainer&&r===F?this.isArray?[]:{}:r;let c;try{c=a.execute(r,t,n,i)}catch(d){throw new fe("Unable to normalize",{location:n,cause:d})}if(c instanceof Promise){if(o)throw new fe("Encountered an async processor during a forced-sync normalization",{location:n});return c.then(d=>this._checkValue(d,fe),d=>{throw new fe("Unable to normalize",{value:r,location:n,cause:d})})}return this._checkValue(c)}async normalizeValue(r,t,n=new j(this),i){return this._normalizeValue(r,t,n,i)}_transformValue(r,t,n=new j(this),i={}){if(n.schema!==this)return n.schema._transformValue(r,t,n,i);if(r instanceof Error&&!this.options.allowErrors)throw new Z(r.message,{cause:r});if(this.isImplicit)throw new Z("Cannot transform a value for an implicit schema",{location:n});if(r===null||r===void 0&&!this.options.allowUndefined)return r;let o;try{this.ensureAccepts(r);let s=this.getValueProcessor("transformers");if(s===void 0)return r;o=s.execute(r,t,n,i)}catch(s){throw new Z("Unable to transform",{value:r,location:n,cause:s})}return o instanceof Promise?o.then(s=>this._checkValue(s,Z),s=>{throw new Z("Unable to transform",{value:r,location:n,cause:s})}):this._checkValue(o,Z)}async transformValue(r,t,n=new j(this),i){return this._transformValue(r,t,n,i)}_finalizeValue(r,t,n=new j(this),i={}){if(n.schema!==this)return n.schema._finalizeValue(r,t,n,i);if(r instanceof Error&&!this.options.allowErrors)throw new Q(r.message,{cause:r});if(this.isImplicit)throw new Z("Cannot finalize a value for an implicit schema",{location:n});if(r===null||r===void 0&&!this.options.allowUndefined)return r;let o;try{let s=this.getValueProcessor("finalizers");if(s===void 0)return r;o=s.execute(r,t,n,i)}catch(s){throw new Q("Unable to finalize",{value:r,location:n,cause:s})}return o instanceof Promise?o.then(s=>this._checkValue(s,Q),s=>{throw new Q("Unable to finalize",{value:r,location:n,cause:s})}):this._checkValue(o,Q)}async finalizeValue(r,t,n=new j(this),i){return this._finalizeValue(r,t,n,i)}_validateValue(r,t,n=new j(this),i={}){if(n.schema!==this)return n.schema._validateValue(r,t,n,i);if(this.required===!0&&r===void 0)throw new z("Missing required value",{location:n});if(r==null)return r;if(r instanceof Error&&!this.options.allowErrors)throw new z(r.message,{cause:r});let o=this.getValueProcessor("validators");if(!o)return r;let s=i?.revalidate??n.schema.options?.revalidate??!0,a;try{a=o.execute(r,t,n,i)}catch(c){throw c instanceof z?c:new z("Validation failed",{value:r,location:n,cause:c})}return a instanceof Promise?a.then(c=>c!==r&&c!==void 0&&s?this._validateValue(c,t,n,{...i,revalidate:!1}):c===void 0?r:this._checkValue(c,z),c=>{throw c instanceof z?c:new z("Validation failed",{value:r,location:n,cause:c})}):a!==r&&a!==void 0&&s?this._validateValue(a,t,n,{...i,revalidate:!1}):a===void 0?r:this._checkValue(a,z)}async validateValue(r,t,n,i){return this._validateValue(r,t,n,i)}_serializeValue(r,t,n=new j(this),i={}){if(n.schema!==this)return n.schema._serializeValue(r,t,n,i);if(r==null||this.isImplicit||J(this.metadata.omitFromSerialize))return null;let o=this.getValueProcessor("serializers")??this.getValueProcessor("normalizers");if(!o)return r;let s;try{s=o.execute(r,t,n,i)}catch(a){if(i?.strict)throw new be("Unable to serialize",{value:r,location:n,cause:a});return}return s instanceof Promise?s.then(a=>i?.strict?this._checkValue(a,be):a,a=>{if(i?.strict)throw new be("Unable to serialize",{value:r,location:n,cause:a})}):i?.strict?this._checkValue(s,be):s}async serializeValue(r,t,n=new j(this),i){return this._serializeValue(r,t,n,i)}ensureAccepts(r){if(r===void 0){if(this.options.allowUndefined)return;throw new z("Schema does not accept an undefined input")}if(!Array.isArray(this.values)||this.values.length===0||this.options.allowUnknownValues)return;if(!this.values.some(n=>v(n,r))){let n=this.metadata.valueDescription??`{${this.values.map(w).join("|")}}`,i=n.length>80?'not found in schema "values" option':`expected one of ${n}`;throw new z(`Invalid value ${w(r)}, ${i}`)}}checkAccepts(r){try{return this.ensureAccepts(r),!0}catch{return!1}}_validate(r,t={}){let n=t.location??new j(this),i=t.context instanceof ue?t.context:new ue(n,t),o=[()=>(i.setAssignedInput(r,""),i.traverse(kr)),()=>{for(let s of i.stateMap.values())s.completed=!1;return i.traverse(Tt)},()=>i.getValue()];return new ae(o).execute(i)}async validate(r,t){return this._validate(r,t)}_process(r,t,n={}){let i=n?.location??new j(this),o=n.context instanceof ue?n.context:new ue(i,{strict:n?.strict,deep:n?.deep,debug:n?.debug,stats:n?.stats}),s=[];return t!==void 0&&s.push(()=>(o.setAssignedInput(t,""),o.traverse(kr))),s.push(()=>{if(o.setAssignedInput(r,n?.inputPath),n?.assignments)for(let[a,c]of n.assignments)o.setAssignedInput(c,a);return o.traverse(Pt)}),s.push(()=>o.getValue()),new ae(s).execute(o)}async process(r,t,n={}){return this._process(r,t,n)}async processAssignments(r,t,n={}){return this._process(void 0,t,{...n,assignments:r})}async serialize(r,t={}){let n=t?.location??new j(this),i=t.context instanceof ue?t.context:new ue(n,{strict:t?.strict,deep:t?.deep,debug:t?.debug}),o=[()=>(i.setAssignedInput(r,""),i.traverse(Ot)),()=>Be(i.getValue())];return new ae(o).execute(i)}findUnionKey(r){if(!this.isUnion)throw new u("Cannot find union key because schema is not a union");for(let[t,n]of this.unionSchemaEntries)if(n===r)return t}getUnionSchema(r){if(r){if(typeof r=="string"){if(!this.isUnion)throw new u(`Cannot get union schema with key "${r}" because schema is not a union`);if(this.#t.has(r))return this.#t.get(r);throw new u(`Unknown union schema key "${r}"`)}if(r instanceof e){if(!this.isUnion)throw new u("Schema is not a union");if(this.findUnionKey(r))return r;throw new u("Schema is not a union member")}throw new u("Unable to get union schema with provided data")}}_setUnionSchema(r,t){if(!r)throw new u("Unable to set a union schema without a valid key");if(!(t instanceof e))throw new u("Union schema must be a CompiledSchema instance");if(this.#a)throw new u(`Cannot add union schema "${r}" to a frozen CompiledSchema`);return this.#n=void 0,this.#t.set(r,t),t}find(r){if(!r||r===""||r===".")return this;let t=r.split("."),n=this;for(let i of t)if(n=n?.getPropertySchema(i),!n)return;return n}toAssignments(r,t=""){if(typeof r!="object")return new Map([["",r]]);let n=new Map;function i(o,s,a){let c=Array.isArray(s)||L(s),d=o?.allowIncremental??!0;if(c&&o?.hasChildren){let g=Array.isArray(s)?s.entries():Object.entries(s);for(let[S,A]of g){let E=o?.getPropertySchema(`${S}`);i(E,A,a?`${a}.${S}`:`${S}`)}}else n.set(a,s)}return i(this,r,t),n}visitSchema(r,t){let n=new Set,i=t?.onlySerializable??!1;function o(s,a){if(!n.has(s)&&(n.add(s),!(s.metadata.omitFromSerialize&&i))){if(s.hasChildren)for(let[c,d]of s.propertyEntries){let g=a?`${a}.${c}`:`${c}`;if(o(d,g)===!1)return!1}if(s.isUnion){for(let[c,d]of s.unionSchemaEntries)if(o(d,a)===!1)return}return r(s,a)}}return o(this,"")??!0}getPropertyPaths(){let r=new Set;return this.visitSchema((t,n)=>{n&&r.add(n)}),r}getPropertySchema(r){if(!r)throw new u("Unable to retrieve an unnamed property");return this.#e.get(r)??this.#e.get("*")}_setPropertySchema(r,t){if(!r)throw new u("Unable to set an unnamed property");if(!(t instanceof e))throw new u("Property schema must be a CompiledSchema instance");if(this.#a)throw new u(`Cannot add property ${r} to a frozen CompiledSchema`);return this.#r=void 0,this.#e.set(r,t),this.#o.container??=!0,t}getTagged(r){let t=[];for(let n of this.#e.values())n.options[r]&&t.push(n);return t}getFirstTagged(r){for(let t of this.#e.values())if(t.options[r])return t}isValidPath(r){if(r==="")return!0;let t=r.split(".");function n(i,o=0){if(o>=t.length)return i!==void 0;let s=t[o],a=i.getPropertySchema(s);if(a)return n(a,o+1);if(i.isUnion){for(let c of i.#t.values())if(n(c,o))return!0}return!1}return n(this)}_freeze(r=new Set){if(!(this.#a||r.has(this))){this.#a=!0,r.add(this);for(let t of this.#e.values())t._freeze(r);Object.freeze(this.#e);for(let t of this.#t.values())t._freeze(r);Object.freeze(this.#t),Object.freeze(this.#o),Object.freeze(this.#u),Object.freeze(this)}}}});var k,X=m(()=>{"use strict";se();l();k=class extends N{#e;#r;constructor(r,t){if(super(),t){if(!(t instanceof N))throw new u("FunctionValueProcessor args must be a ValueProcessor");this.#e=t}this.#r=r,this.spec=r}execute(r,t,n,i){if(this.#e){let o=this.#e.execute(r,t,n,i);return o instanceof Promise?o.then(s=>this.#r(r,t,n,{...i,args:s})):this.#r(r,t,n,{...i,args:o})}return this.#r(r,t,n,i)}}});var y,V=m(()=>{"use strict";xe();se();M();y=class extends N{#e;constructor(r,t,n){if(r instanceof N&&(n=r.description),!n&&r.isConstant){let i=r.execute(!0);n=He(i)?`${i}`:we(i)}super(t,n),this.#e=r}execute(r,t,n,i){return this.#e.execute(r,t,n,i)}get isConstant(){return this.#e.isConstant}}});var ce,ze=m(()=>{"use strict";Y();l();ce=class extends T{#e=[];#r;#t;constructor(r={},t){super();let n=!0;for(let[i,o]of Object.entries(r)){if(o===void 0)continue;let s=q(o);this.#e.push([i,s]),n&&=s.isConstant}if(this.#r=t,n){if(t)throw new u("Cannot use a preprocessor with a constant object executor");this.#t=Object.fromEntries(this.#e.map(([i,o])=>[i,o.execute(!0)]))}}execute(r,...t){if(this.#t!==void 0)return this.#t;let n={},i=0,o=this.#e;for(;i<o.length;){let s=o[i][0],a=this.#r?this.#r(r):r,c=o[i++][1].execute(a,...t);if(c instanceof Promise)return c.then(d=>(n[s]=d,this.#n(r,t,i,n)));n[s]=c}return n}async#n(r,t,n,i){let o=this.#e;for(;n<o.length;){let s=o[n][0],a=this.#r?this.#r(r):r;i[s]=await o[n++][1].execute(a,...t)}return i}get isConstant(){return this.#t!==void 0}}});var ie,Pe=m(()=>{"use strict";Y();ie=class extends T{#e=[];#r;constructor(r=[]){Array.isArray(r)||(r=[r]),super();let t=!0;for(let n of r){let i=q(n);t&&=i.isConstant,this.#e.push(i)}this.#r=t?this.#e.map(n=>n.execute(!0)):void 0}execute(r,...t){if(this.#r!==void 0)return this.#r;let n=[],i=0,o=this.#e;for(;i<o.length;){let s=o[i++].execute(r,...t);if(s instanceof Promise)return s.then(a=>(n.push(a),this.#t(r,t,i,n)));n.push(s)}return n}async#t(r,t,n,i){for(;n<this.#e.length;)i.push(await this.#e[n++].execute(r,...t));return i}get isConstant(){return this.#r!==void 0}}});var De,Ur=m(()=>{"use strict";Y();ze();se();V();l();M();De=class extends N{#e;#r;#t;constructor(r=[],t={}){super();let n={};if(Array.isArray(t)){if(t.length>r.length)throw new u("Too many arguments");for(let s=0;s<r.length;++s)s<t.length&&(n[r[s].parameter]=t[s])}else{if(Object.keys(t).length>r.length)throw new u("Too many arguments");for(let s=0;s<r.length;++s){let a=t[r[s].parameter];a&&(n[r[s].parameter]=a)}for(let s of Object.keys(t))if(n[s]===void 0)throw new u(`Unknown parameter ${s}`)}let i=!0,o=!1;for(let s=0;s<r.length;++s){let a=r[s].hasOwnProperty("default");if(r[s].required){if(o)throw new u(`Required parameter ${r[s].parameter} cannot follow optional parameter`)}else a||(o&&(i=!1),o=!0);if(n[r[s].parameter]===void 0&&a&&(n[r[s].parameter]=new y(new B(r[s].default),r[s].default)),n[r[s].parameter]===void 0){if(r[s].required)throw new u(`Missing required argument for parameter ${r[s].parameter}`);o&&i&&!a&&(n[r[s].parameter]=new y(new T,"$input"),i=!1)}if(n[r[s].parameter]?.isConstant&&r[s].type!==void 0){let c=n[r[s].parameter].execute(!0);if(r[s].type!==void 0&&c!==void 0&&typeof c!==r[s].type)throw new u(`Invalid ${r[s].type} type for parameter "${r[s].parameter}"`,{value:c})}}if(this.#e=new ce(n),this.#r=r,this.#e.isConstant){let s=this.#e.execute(!0);this.#t=this.#n(s);let a="";for(let[c,d]of Object.entries(s))a.length&&(a+=","),a+=`${c}=${d}`;this.description=`[${a}]`}this.spec=K(n,s=>s.spec)}#n(r){for(let t of this.#r)if(r[t.parameter]!==void 0&&t.type&&typeof r[t.parameter]!==t.type)throw new u(`Invalid type for parameter ${t.parameter}, expected ${t.type}`);return r}execute(r,t,n,i){if(this.#t!==void 0)return this.#t;let o=this.#e.execute(r,t,n,i);return o instanceof Promise?o.then(s=>this.#n(s)):this.#n(o)}get isConstant(){return this.#t!==void 0}}});var ge,fr=m(()=>{"use strict";se();ge=class extends N{#e;#r;constructor(r,t,n,i){super(n,i),this.#e=r,this.#r=t}execute(r,t,n,i){if(this.#r){let o=this.#r.execute(r,t,n,i);return o instanceof Promise?o.then(s=>this.#e.execute(r,t,n,{...i,args:s})):this.#e.execute(r,t,n,{...i,args:o})}return this.#e.execute(r,t,n,i)}}});function Je(e){return!e||typeof e!="string"?[]:e.split(/[^a-zA-Z0-9]+/).flatMap(r=>r.split(/(?<=[a-z])(?=[A-Z])/)).flatMap(r=>r.split(/(?<=[0-9])(?=[A-Za-z])/)).filter(r=>r.length>0).map(r=>r.toLowerCase())}function Na(e){return e.length===0?"":e[0]+e.slice(1).map(r=>r.charAt(0).toUpperCase()+r.slice(1)).join("")}function Ua(e){return e.length===0?"":e.map(r=>r.charAt(0).toUpperCase()+r.slice(1)).join("")}function Va(e){return e.length===0?"":e.map(r=>r.charAt(0).toUpperCase()+r.slice(1)).join(" ")}function za(e){return e.map(r=>r.toUpperCase()).join("_")}function Da(e){return e.map(r=>r.toLowerCase()).join("-")}function Vr(e){return Na(Je(e))}function jr(e){return Ua(Je(e))}function zr(e){return za(Je(e))}function Te(e){return Da(Je(e))}function Dr(e){return Va(Je(e))}function Lr(e){if(!e||typeof e!="string")return"";let r=e.trim().replace(/\s+/g," "),t=0,n=r.search(/\b\w(?=[^]*$)/);return r.replace(/\b(\w)(\w*)\b/g,(i,o,s,a)=>t++!==0&&a!==n&&ja.has(i.toLowerCase())?i.toLowerCase():o.toUpperCase()+s.toLowerCase())}var ja,he=m(()=>{"use strict";ja=new Set(["a","an","the","and","but","or","nor","for","so","yet","at","by","in","of","on","to","up","as","via"])});function Oe(e){if(e instanceof RegExp)return e;if(typeof e=="string"&&e.startsWith("/")&&e.lastIndexOf("/")>0){let r=e.lastIndexOf("/");return new RegExp(e.slice(1,r),e.slice(r+1))}throw new u("Unable to parse RegExp",{value:e})}var Qe=m(()=>{"use strict";l()});var rn={};h(rn,{MAX_OPERATOR:()=>Fa,MIN_OPERATOR:()=>qa,SUM_OPERATOR:()=>Ma});var Ma,qa,Fa,tn=m(()=>{"use strict";l();_();Ma={keyword:"sum",process:(e,r,t)=>{if(!Array.isArray(e))throw new f(`$sum requires an array, got ${w(e)}`,{location:t});let n=0;for(let i=0;i<e.length;i++){if(typeof e[i]!="number"||!Number.isFinite(e[i]))throw new f(`$sum requires an array of finite numbers, got ${w(e[i])} at index ${i}`,{location:t});n+=e[i]}return n}},qa={keyword:"min",process:(e,r,t)=>{if(!Array.isArray(e))throw new f(`$min requires an array, got ${w(e)}`,{location:t});if(e.length!==0){for(let n=0;n<e.length;n++)if(typeof e[n]!="number"||!Number.isFinite(e[n]))throw new f(`$min requires an array of finite numbers, got ${w(e[n])} at index ${n}`,{location:t});return Math.min(...e)}}},Fa={keyword:"max",process:(e,r,t)=>{if(!Array.isArray(e))throw new f(`$max requires an array, got ${w(e)}`,{location:t});if(e.length!==0){for(let n=0;n<e.length;n++)if(typeof e[n]!="number"||!Number.isFinite(e[n]))throw new f(`$max requires an array of finite numbers, got ${w(e[n])} at index ${n}`,{location:t});return Math.max(...e)}}}});var nn={};h(nn,{ALPHA_CONSTRAINT:()=>Ha});var Ha,on=m(()=>{"use strict";l();Ha={keyword:"alpha",process:e=>{if(!/^[a-zA-Z]+$/.test(e))throw new f("Must contain only letters");return e}}});var sn={};h(sn,{ALPHANUM_CONSTRAINT:()=>Ka});var Ka,an=m(()=>{"use strict";l();Ka={keyword:"alphanum",process:e=>{if(!/^[a-zA-Z0-9]+$/.test(e))throw new f("Must contain only alphanumeric characters");return e}}});var cn={};h(cn,{ARRAY_OPERATOR:()=>Ba});var Ba,fn=m(()=>{"use strict";xe();oe();l();Ba={keyword:"array",process:(e,r,t)=>{if(e===F)e=[];else if(e==="*"){let n=t?.schema.getPropertySchema("*")?.values;if(n!==void 0)e=[...n];else throw new f("Schema must define values in order to expand wildcard array")}if(typeof e=="string")if(e=e.trim(),e.length>0&&e[0]==="["&&e[e.length-1]==="]")try{e=Fe(e)}catch{throw new f(`Invalid input string for array: ${e}`)}else e=e.split(",").map(n=>n.trim()).filter(n=>n.length>0);if(Array.isArray(e))return e;throw new f(`Invalid input for array: ${e}`)}}});var P,Ee=m(()=>{"use strict";Y();le();P=class e extends T{#e;#r;#t;#n=!1;#i=!1;#s=!1;#o=!1;constructor(r,t={},n=[]){super(),this.#e=q(r??new T),this.#r=q(t.success??new T),this.#t=q(t.failure??Ue);for(let i of n)if(i===e.CHECK_TRUTHY)this.#s=!0;else if(i===e.CHECK_DEFINED)this.#o=!0;else if(i===e.PASS_RESULT)this.#n=!0;else if(i===e.PASS_ERROR)this.#i=!0;else throw new Error("Unknown flag")}execute(r,...t){let n=(o,s)=>{let a,c=this.#n?s:r,d=this.#i?o:c;return o?a=!1:this.#s?a=J(s):this.#o?a=s!==void 0:a=!0,a?this.#r.execute(c,...t):this.#t.execute(d,...t)},i;try{i=this.#e.execute(r,...t)}catch(o){return n(o)}return i instanceof Promise?i.then(o=>n(void 0,o),o=>n(o)):n(void 0,i)}static CHECK_TRUTHY=Symbol("CHECK-TRUTHY");static CHECK_DEFINED=Symbol("CHECK-DEFINED");static PASS_RESULT=Symbol("PASS-RESULT");static PASS_ERROR=Symbol("PASS-ERROR")}});var un={};h(un,{ASSERT_CONSTRAINT:()=>Wa});var Wa,mn=m(()=>{"use strict";se();V();Ee();Y();l();Wa={keyword:"assert",build:e=>{let r;if(Array.isArray(e))if(e.length===1)r=e[0];else if(e.length===0)r=new y(new T,[]);else throw new u("$assert requires a single processor argument");else typeof e=="object"&&(r=e.processor);if(!(r instanceof N))throw new u("$assert requires a processor argument");let t=e.length===0?"$assert":{$assert:r.spec},n=r.description;return new y(new P(r,{failure:i=>{throw i instanceof f?i:new f("Processed value was not truthy",{cause:i})}},[P.CHECK_TRUTHY,P.PASS_ERROR]),t,n)}}});var pn={};h(pn,{BASE64_CONSTRAINT:()=>Ya});var Ya,dn=m(()=>{"use strict";l();Ya={keyword:"base64",process:e=>{if(!/^[A-Za-z0-9+/]*={0,2}$/.test(e))throw new f("Invalid base64 format");if(e.includes("=")&&e.length%4!==0)throw new f("Invalid base64 format");return e}}});var ln={};h(ln,{CAMEL_CASE_OPERATOR:()=>Za});var Za,hn=m(()=>{"use strict";he();Za={keyword:"camel-case",process:e=>Vr(String(e))}});var wn={};h(wn,{CAPITALIZE_OPERATOR:()=>Xa});var Xa,yn=m(()=>{"use strict";he();Xa={keyword:"capitalize",process:e=>Dr(String(e))}});var En={};h(En,{CARDNUM_CONSTRAINT:()=>Qa});function Ja(e){let r=0,t=!1;for(let n=e.length-1;n>=0;n--){let i=+e[n];t&&(i*=2,i>9&&(i-=9)),r+=i,t=!t}return r%10===0}function gn(e,r){let t=[],n=0;for(let i of r){if(n>=e.length)break;t.push(e.slice(n,n+i)),n+=i}return n<e.length&&t.push(e.slice(n)),t.join(" ")}var va,Ga,Qa,An=m(()=>{"use strict";l();va=[{name:"amex",match:e=>e.startsWith("34")||e.startsWith("37"),groups:[4,6,5]},{name:"diners",match:e=>{let r=+e.slice(0,3);return r>=300&&r<=305||e.startsWith("36")||e.startsWith("38")},groups:[4,6,4]},{name:"jcb",match:e=>{let r=+e.slice(0,4);return r>=3528&&r<=3589},groups:[4,4,4,4]},{name:"discover",match:e=>{let r=+e.slice(0,3),t=+e.slice(0,6);return e.startsWith("6011")||e.startsWith("65")||r>=644&&r<=649||t>=622126&&t<=622925},groups:[4,4,4,4]},{name:"mastercard",match:e=>{let r=+e.slice(0,2),t=+e.slice(0,4);return r>=51&&r<=55||t>=2221&&t<=2720},groups:[4,4,4,4]},{name:"visa",match:e=>e.startsWith("4"),groups:[4,4,4,4]}],Ga=[4,4,4,4];Qa={keyword:"cardnum",parameters:[{parameter:"mask",default:!1},{parameter:"reveal",default:4}],process:(e,r,t,n)=>{let{mask:i,reveal:o}=n.args,s=e.replace(/[\s\-.]/g,"");if(!/^\d+$/.test(s))throw new f("Invalid card number format");if(s.length<12||s.length>19)throw new f("Invalid card number length");if(!Ja(s))throw new f("Invalid card number (checksum failed)");let a=Ga;for(let c of va)if(c.match(s)){a=c.groups;break}if(i){let c=(typeof i=="string"?i[0]:null)||"\u2022",d=Math.min(Math.max(0,o),s.length),g=c.repeat(s.length-d)+s.slice(s.length-d);return gn(g,a)}return gn(s,a)}}});var Sn={};h(Sn,{CEIL_OPERATOR:()=>ec});var ec,xn=m(()=>{"use strict";ec={keyword:"ceil",parameters:[{parameter:"precision",default:0}],process:(e,r,t,n)=>{let i=Number(e);if(!Number.isFinite(i))return e;let o=n.args.precision,s=Math.pow(10,o);return Math.ceil(i*s)/s}}});var Cn={};h(Cn,{COLLAPSE_OPERATOR:()=>rc});var rc,bn=m(()=>{"use strict";rc={keyword:"collapse",process:e=>String(e).replace(/\s+/g," ").trim()}});var Rn={};h(Rn,{COMPACT_OPERATOR:()=>tc});var tc,$n=m(()=>{"use strict";tc={keyword:"compact",process:e=>String(e).replace(/[\s()\-./]/g,"")}});var Tn={};h(Tn,{COMPILE_OPERATOR:()=>Pn});var Pn,On=m(()=>{"use strict";Ur();fr();X();l();_();Pn={keyword:"compile",parameters:[{parameter:"schema",required:!1},{parameter:"compiler",required:!1}],build:(e,r)=>{let t=r.compiler,n=new De(Pn.parameters,e);return new ge(new k((i,o,s,a)=>{let c=a.args.compiler??t;if(typeof c?.compile!="function")throw new u(`Invalid compiler provided to $compile ${w(c)}`,{location:s});return a.args.schema!==void 0&&(i=a.args.schema),c.compile(i)}),n,{$compile:n.spec})}}});var In={};h(In,{CONCAT_OPERATOR:()=>nc});var nc,_n=m(()=>{"use strict";V();X();Pe();M();l();nc={keyword:"concat",build:e=>{if(!Array.isArray(e)||e.length===0)throw new u("$concat requires a non-empty array of values to append");let r=K(e,t=>t.spec);return new k((t,n,i,o)=>{let s=Array.isArray(o.args)?o.args:[];if(!Array.isArray(t))throw new f(`$concat requires an array input, got ${t}`,{location:i});return[...t,...s]},new y(new ie(e),r))}}});var kn={};h(kn,{CHECK_OPERATOR:()=>sc,GATE_OPERATOR:()=>oc,IF_OPERATOR:()=>ic,TRY_OPERATOR:()=>cc,WHEN_OPERATOR:()=>ac});function er(e,r){return t=>{let n,i,o;if(Array.isArray(t)){if(t.length>3)throw new $(`${e} array requires 0-3 processors [predicate, success, failure]`);n=t[0],i=t[1],o=t[2]}else if(typeof t=="object"&&t!==null)n=t.predicate??t.condition??t.cond,i=t.success,o=t.failure;else if(t!==void 0)throw new $(`${e} requires predicate/success/failure processors specified as an array or object`);n??=new y(new T,[]),i??=new y(new T,[]),o??=new y(Ue,"$undefined");let s={[`${e}`]:[n.spec,i?.spec,o?.spec]},a=`(${n.description??""})?`;return i.description&&(a+=`(${i.description})`),o.description&&(a+=`:(${o.description})`),new y(new P(n,{success:i,failure:o},r),s,a)}}var ic,oc,sc,ac,cc,Nn=m(()=>{"use strict";Y();Ee();V();l();ic={keyword:"if",build:er("$if",[P.CHECK_TRUTHY])},oc={keyword:"gate",build:er("$gate",[P.CHECK_DEFINED])},sc={keyword:"check",build:er("$check",[P.CHECK_TRUTHY,P.PASS_RESULT])},ac={keyword:"when",build:er("$when",[P.CHECK_DEFINED,P.PASS_RESULT])},cc={keyword:"try",build:er("$try",[P.PASS_ERROR,P.PASS_RESULT])}});var Un={};h(Un,{CONSTANT_CASE_OPERATOR:()=>fc});var fc,Vn=m(()=>{"use strict";he();fc={keyword:"constant-case",process:e=>zr(String(e))}});function Kr(e,r){if(typeof e=="number"){if(!Number.isFinite(e)||e<0)throw new u(`Invalid data size: ${e}`);return e}if(typeof e!="string")throw new u(`Invalid data size: expected string or number, got ${typeof e}`);let t=e.match(pc);if(!t)throw new u(`Invalid data size: "${e}"`);let[,n,i]=t,o=parseFloat(n);if(!i)return o;let s=i.toLowerCase(),a=Hr.get(s);if(a===void 0)throw new u(`Unknown data size unit: "${i}"`);if(r){let c=r.toLowerCase();if(c==="iec"&&!uc.has(s))throw new u(`Unit "${i}" is not an IEC unit (expected B, KiB, MiB, GiB, TiB, PiB)`);if(c==="si"&&!mc.has(s))throw new u(`Unit "${i}" is not an SI unit (expected B, KB, MB, GB, TB, PB)`)}return o*a}function Br(e,r="iec"){if(!Number.isFinite(e)||e<0)throw new u(`Invalid byte count: ${e}`);let t=r.toLowerCase()==="si"?Fr:qr;for(let n=t.length-1;n>=0;n--){let[i,o]=t[n];if(e>=o||n===0){let s=e/o;return`${s%1===0?String(s):parseFloat(s.toFixed(2)).toString()} ${i}`}}}var qr,Fr,Hr,uc,mc,pc,Wr=m(()=>{"use strict";l();qr=[["B",1],["KiB",1024],["MiB",1024**2],["GiB",1024**3],["TiB",1024**4],["PiB",1024**5]],Fr=[["B",1],["KB",1e3],["MB",1e3**2],["GB",1e3**3],["TB",1e3**4],["PB",1e3**5]],Hr=new Map;for(let[e,r]of qr)Hr.set(e.toLowerCase(),r);for(let[e,r]of Fr)Hr.set(e.toLowerCase(),r);uc=new Set(qr.map(([e])=>e.toLowerCase())),mc=new Set(Fr.map(([e])=>e.toLowerCase())),pc=/^\s*(\d+(?:\.\d+)?)\s*([a-z]*)\s*$/i});var jn={};h(jn,{DATA_SIZE_OPERATOR:()=>hc});var dc,lc,hc,zn=m(()=>{"use strict";l();Wr();dc=new Set(["iec","si","any"]),lc=new Set(["iec","si"]),hc={keyword:"data-size",parameters:[{parameter:"standard",default:"any",type:"string"},{parameter:"format",default:void 0,type:"string"}],process:(e,r,t,n)=>{let{standard:i,format:o}=n?.args??{};if(i!==void 0&&!dc.has(i))throw new $(`$data-size: unknown standard "${i}" (expected iec, si, or any)`);if(o!==void 0&&!lc.has(o))throw new $(`$data-size: unknown format "${o}" (expected iec or si)`);if(typeof e=="number"&&o===void 0){if(!Number.isFinite(e)||e<0)throw new f(`Invalid data size: ${e}`);return e}let s=Kr(e,i==="any"?void 0:i);return o!==void 0?Br(s,o):s},describe:e=>{if(!e)return;let r=Array.isArray(e)?e[0]:e.standard,t=Array.isArray(e)?e[1]:e.format,n=r?.description,i=t?.description,o=[];return n!==void 0&&n!=="any"&&o.push(n.toUpperCase()),i!==void 0&&o.push(`\u2192 ${i.toUpperCase()}`),o.length?o.join(", "):void 0}}});var Dn={};h(Dn,{DATE_OBJECT_OPERATOR:()=>wc});var wc,Ln=m(()=>{"use strict";l();_();wc={keyword:"date-object",parameters:[{parameter:"zone"}],process:(e,r,t,n)=>{if(!(e instanceof Date))throw new f(`$date-object requires a Date, got ${w(e)}`,{location:t});let i=n.args.zone??"utc";if(i!=="utc"&&i!=="local")throw new f(`$date-object zone must be 'utc' or 'local', got ${w(i)}`,{location:t});return i==="local"?{year:e.getFullYear(),month:e.getMonth()+1,day:e.getDate(),hour:e.getHours(),minute:e.getMinutes(),second:e.getSeconds(),ms:e.getMilliseconds(),zone:"local"}:{year:e.getUTCFullYear(),month:e.getUTCMonth()+1,day:e.getUTCDate(),hour:e.getUTCHours(),minute:e.getUTCMinutes(),second:e.getUTCSeconds(),ms:e.getUTCMilliseconds(),zone:"utc"}}}});function Ie(e){if(e==="now")return new Date;if(typeof e=="string"){let r=e.match(/^([+-])(\d+(?:\.\d+)?)(ms|s|m|h|d|w)$/);if(r){let[,i,o,s]=r,a=i==="+"?1:-1,c=parseFloat(o)*a,d={ms:1,s:1e3,m:60*1e3,h:3600*1e3,d:1440*60*1e3,w:10080*60*1e3};return new Date(Date.now()+c*d[s])}let t=parseFloat(e);if(!isNaN(t)&&isFinite(t)&&/^\d+(\.\d+)?$/.test(e.trim())){let i=t;t>0&&t<2524608e3&&t<1e12&&(i=t*1e3);let o=new Date(i);if(isNaN(o.getTime()))throw new Z(`Invalid date: ${e}`);return o}let n=new Date(e);if(isNaN(n.getTime()))throw new Z(`Invalid date: ${e}`);return n}if(typeof e=="number"){let r=new Date(Math.abs(e)<2e8?e*1e3:e);if(isNaN(r.getTime()))throw new Z(`Invalid date: ${e}`);return r}if(e instanceof Date){if(isNaN(e.getTime()))throw new Z(`Invalid date: ${e}`);return new Date(e.getTime())}throw new Z(`Invalid date: ${e} (${typeof e})`)}var mr=m(()=>{"use strict";l()});var Mn={};h(Mn,{DATE_OPERATOR:()=>gc});function yc(e){let{year:r,month:t,day:n,hour:i=0,minute:o=0,second:s=0,ms:a=0,zone:c="utc"}=e;return c==="local"?new Date(r,t-1,n,i,o,s,a):new Date(Date.UTC(r,t-1,n,i,o,s,a))}var gc,qn=m(()=>{"use strict";mr();l();gc={keyword:"date",process:(e,r,t)=>{if(typeof e=="object"&&e!==null&&!(e instanceof Date)&&Number.isInteger(e.year)&&Number.isInteger(e.month)){let i=yc(e);if(isNaN(i.getTime()))throw new f(`Invalid date object: ${JSON.stringify(e)}`);return t.schema.options.type==="string"?i.toISOString():t.schema.options.type==="number"?i.getTime():i}if(typeof e!="string"&&typeof e!="number"&&!(e instanceof Date))throw new f(`Invalid input for date: ${e}`);let n=Ie(e);return t.schema.options.type==="string"?n.toISOString():t.schema.options.type==="number"?n.getTime():n}}});var Fn={};h(Fn,{DATE_RANGE_CONSTRAINT:()=>Ec});var Ec,Hn=m(()=>{"use strict";l();mr();Ec={keyword:"date-range",parameters:[{parameter:"min",default:void 0},{parameter:"max",default:void 0}],process:(e,r,t,n)=>{let{min:i,max:o}=n.args,s=(e instanceof Date?e:Ie(e)).getTime();if(i!==void 0){let a=(i instanceof Date?i:Ie(i)).getTime();if(s<a)throw new f(`Date must not be before ${new Date(a).toISOString()}`)}if(o!==void 0){let a=(o instanceof Date?o:Ie(o)).getTime();if(s>a)throw new f(`Date must not be after ${new Date(a).toISOString()}`)}return e},describe:e=>{if(!e)return;let r=Array.isArray(e)?e[0]:e.min,t=Array.isArray(e)?e[1]:e.max,n=r?.description,i=t?.description;return n!==void 0&&i!==void 0?`${n}..${i}`:n!==void 0?`>=${n}`:i!==void 0?`<=${i}`:void 0}}});var Kn={};h(Kn,{DEFINED_CONSTRAINT:()=>Ac});var Ac,Bn=m(()=>{"use strict";l();Ac={keyword:"defined",process:e=>{if(e===void 0)throw new f("Must be defined");return e}}});var Wn={};h(Wn,{EACH_OPERATOR:()=>Sc});var Sc,Yn=m(()=>{"use strict";Re();V();Y();Ye();Sc={keyword:"each",parameters:[{parameter:"processor",required:!0}],build:e=>{let r=(Array.isArray(e)?e[0]:e.processor)??new T,t=(Array.isArray(e)?e[1]:e.values)??new T,n={$each:r.spec},i=r.description?`[${r.description}]...`:"values...";return new y(new ae([t,new ne(r)]),n,i)}}});var Zn={};h(Zn,{EMAIL_CONSTRAINT:()=>bc});var xc,Cc,bc,Xn=m(()=>{"use strict";l();le();xc=/^[a-zA-Z0-9_%+-](?:[a-zA-Z0-9_%+.-]*[a-zA-Z0-9_%+-])?@(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?\.)+[a-zA-Z]{2,}$/,Cc=/\.\./,bc={keyword:"email",parameters:[{parameter:"case",default:"lower"},{parameter:"case-sensitive",type:"boolean",default:!1},{parameter:"filter",type:"boolean",default:!1}],process:(e,r,t,n)=>{let{case:i,"case-sensitive":o,filter:s}=n.args;if(!xc.test(e))throw new f("Invalid email format");let a=e.lastIndexOf("@"),c=e.slice(0,a),d=e.slice(a+1);if(Cc.test(c))throw new f("Invalid email format");if(s){let S=c.indexOf("+");S!==-1&&(c=c.slice(0,S)),d.toLowerCase()==="gmail.com"&&(c=c.replace(/\./g,""))}let g=Ir(i)?S=>S:i==="upper"?S=>S.toUpperCase():S=>S.toLowerCase();return d=g(d),o||(c=g(c)),`${c}@${d}`}}});var vn={};h(vn,{ENTRIES_OPERATOR:()=>Rc});var Rc,Gn=m(()=>{"use strict";M();l();_();Rc={keyword:"entries",process:(e,r,t)=>{if(!L(e))throw new f(`$entries requires a plain object, got ${w(e)}`,{location:t});return Object.entries(e)}}});var Jn={};h(Jn,{EQ_CONSTRAINT:()=>$c});var $c,Qn=m(()=>{"use strict";re();l();_();$c={keyword:"eq",parameters:[{parameter:"value",required:!0},{parameter:"compare"}],process:(e,r,t,n)=>{let i=n.args.value,o=n.args.compare??e;if(!v(i,o))throw new f(`Value ${w(e)} was not equal to constraint`,{value:e,location:t});return e}}});var ei={};h(ei,{FILTER_OPERATOR:()=>Pc});var Pc,ri=m(()=>{"use strict";V();Ee();X();Re();l();Pc={keyword:"filter",parameters:[{parameter:"processor",required:!1}],build:e=>{let r;if(Array.isArray(e)){if(e.length>1)throw new u("Expected exactly one argument for $filter operator");r=e[0]}else if(typeof e=="object"){if(Object.keys(e).length!==1)throw new u('Expected only "processor" argument for $filter operator');r=e.processor}return r??=new k(t=>t??void 0),new y(new ne(new P(r,{},[P.CHECK_DEFINED,P.PASS_RESULT]),t=>Array.isArray(t)?t:[],t=>Array.isArray(t)?t.filter(n=>n!==void 0):[]),{$filter:r.spec})}}});var ti={};h(ti,{FIND_SCHEMA_OPERATOR:()=>Tc});var Tc,ni=m(()=>{"use strict";l();_();Tc={keyword:"find-schema",parameters:[{parameter:"path",required:!1}],process:(e,r,t,n)=>{let i=n.args?.path??e??".";if(typeof i!="string")throw new u(`$find-schema "path" must be a string, got ${w(i)}`,{location:t});return t.relative(i)?.schema}}});var ii={};h(ii,{FLATTEN_OPERATOR:()=>Oc});var Oc,oi=m(()=>{"use strict";l();_();Oc={keyword:"flatten",parameters:[{parameter:"depth",default:1}],process:(e,r,t,n)=>{if(!Array.isArray(e))throw new f(`$flatten requires an array, got ${w(e)}`,{location:t});let i=n.args?.depth??1;return e.flat(i)}}});var si={};h(si,{FLOOR_OPERATOR:()=>Ic});var Ic,ai=m(()=>{"use strict";Ic={keyword:"floor",parameters:[{parameter:"precision",default:0}],process:(e,r,t,n)=>{let i=Number(e);if(!Number.isFinite(i))return e;let o=n.args.precision,s=Math.pow(10,o);return Math.floor(i*s)/s}}});var ci={};h(ci,{GET_OPERATOR:()=>_c});var _c,fi=m(()=>{"use strict";re();_c={keyword:"get",parameters:[{parameter:"path",required:!0}],process:(e,r,t,n)=>{let i=n.args?.path;return typeof i=="number"?Array.isArray(e)?e[i]:void 0:ee(e,i)}}});var ui={};h(ui,{GROUP_BY_OPERATOR:()=>kc});var kc,mi=m(()=>{"use strict";X();V();Re();l();_();kc={keyword:"group-by",build:e=>{if(!Array.isArray(e)||e.length!==1)throw new u("$group-by requires a single key or processor argument");let r=e[0],t=r?.spec,n=typeof t=="string"&&!t.startsWith("$")?new k(i=>i?.[t]):r;return new y(new ne(n,i=>{if(!Array.isArray(i))throw new f(`$group-by requires an array, got ${w(i)}`);return i},(i,o)=>{let s={};for(let a=0;a<o.length;a++){let c=i[a];if(c===void 0)continue;let d=String(c);s[d]||(s[d]=[]),s[d].push(o[a])}return s}),{"$group-by":t})}}});var pi={};h(pi,{HAS_PREFIX_CONSTRAINT:()=>Nc});var Nc,di=m(()=>{"use strict";l();_();Nc={keyword:"has-prefix",parameters:[{parameter:"match",required:!0}],process:(e,r,t,n)=>{let i=n.args.match;if(!`${e}`.startsWith(i))throw new f(`Value ${w(e)} did not start with prefix ${w(i)}`,{location:t});return e}}});var li={};h(li,{HAS_SUFFIX_CONSTRAINT:()=>Uc});var Uc,hi=m(()=>{"use strict";l();_();Uc={keyword:"has-suffix",parameters:[{parameter:"match",required:!0}],process:(e,r,t,n)=>{let i=n.args.match;if(!`${e}`.endsWith(i))throw new f(`Value ${w(e)} did not end with suffix ${w(i)}`,{location:t});return e}}});var wi={};h(wi,{HEX_CONSTRAINT:()=>Vc});var Vc,yi=m(()=>{"use strict";l();Vc={keyword:"hex",process:e=>{if(!/^[0-9a-fA-F]+$/.test(e))throw new f("Must contain only hexadecimal characters");return e}}});var gi={};h(gi,{HOSTNAME_CONSTRAINT:()=>jc});var jc,Ei=m(()=>{"use strict";l();jc={keyword:"hostname",process:e=>{if(!/^[a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(\.[a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/.test(e))throw new f("Invalid hostname format");return e}}});var Ai={};h(Ai,{HTTP_URL_CONSTRAINT:()=>zc});var zc,Si=m(()=>{"use strict";l();zc={keyword:"http-url",process:e=>{try{let r=new URL(e);if(!["http:","https:"].includes(r.protocol))throw new f("URL must use HTTP or HTTPS protocol");return e}catch(r){throw r instanceof f?r:new f("Invalid HTTP URL format",{cause:r})}}}});var xi={};h(xi,{IN_CONSTRAINT:()=>Dc});var Dc,Ci=m(()=>{"use strict";M();V();X();Pe();l();Dc={keyword:"in",build:e=>{let r=Array.isArray(e)?e:e?.values;if(H(e))throw new u("Must define at least one value for $in");let t=Array.isArray(r)?r.map(s=>s.description).join("|"):"[?]",n=K(r,s=>s.spec),i={$in:n},o=new k((s,a,c,d)=>{let g=(Array.isArray(d.args)?d.args:e.values)??[];if(!g.includes(s))throw new f(`Value must be one of {${g.join("|")}}`,{location:c});return s},new y(new ie(r),n));return o.spec=i,o.description=t,o}}});var bi={};h(bi,{INSTANCEOF_CONSTRAINT:()=>Lc});var Lc,Ri=m(()=>{"use strict";l();_();Lc={keyword:"instanceof",parameters:[{parameter:"clazz",type:"function",required:!0}],process:(e,r,t,n)=>{let i=n.args.clazz;if(!(e instanceof i)){let o=i.name||"anonymous";throw new f(`Expected instance of ${o}, got ${w(e)}`,{location:t})}return e}}});var $i={};h($i,{INDEX_BY_OPERATOR:()=>Mc});var Mc,Pi=m(()=>{"use strict";X();V();Re();l();_();Mc={keyword:"index-by",parameters:[{parameter:"processor",required:!0}],build:e=>{let r,t;if(Array.isArray(e)){if(e.length!==1)throw new u("$index-by requires only a single key, or extended arguments with a processor");t=e[0]}else typeof e=="object"&&(t=e.key,r=e.processor);if(t){if(r)throw new u("$index-by requires only a key or a processor, not both");r=new k((n,i,o,s)=>{let a=t.execute(n,i,o,{...s,input:n});return a instanceof Promise?a.then(c=>c!==void 0?n?.[c]:void 0):a!==void 0?n?.[a]:void 0})}if(!r)throw new u("$index-by requires a key or processor argument");return new y(new ne(r,n=>{if(!Array.isArray(n))throw new f(`$index-by requires an array, got ${w(n)}`);return n},(n,i)=>{let o={};for(let s=0;s<i.length;s++){let a=n[s];if(a!==void 0){if(o[String(a)]!==void 0)throw new f(`$index-by requires unique keys, got duplicate key ${a}`);o[String(a)]=i[s]}}return o}),{"$index-by":e})}}});var Ti={};h(Ti,{INPUT_OPERATOR:()=>qc});var qc,Oi=m(()=>{"use strict";qc={keyword:"input",process:e=>e}});var Ii={};h(Ii,{INTEGER_CONSTRAINT:()=>Fc});var Fc,_i=m(()=>{"use strict";l();Fc={keyword:"integer",process:e=>{if(typeof e!="number"||!Number.isFinite(e))throw new f("Must be a finite number");if(!Number.isInteger(e))throw new f("Must be an integer");return e}}});var ki={};h(ki,{INVOKE_OPERATOR:()=>Hc});var Hc,Ni=m(()=>{"use strict";V();Ye();fr();Hc={keyword:"invoke",parameters:[{parameter:"processor",required:!0},{parameter:"arguments",required:!1}],build:e=>{let r=Array.isArray(e)?e[0]:e.processor,t=new y(new ae([r,i=>i]),r.spec),n=Array.isArray(e)?e[1]:e.arguments;return new ge(t,n,{$invoke:{processor:r?.spec,arguments:n?.spec}})}}});var Ui={};h(Ui,{IPV4_CONSTRAINT:()=>Wc});function dr(e){let[r,t,n,i]=e.split(".").map(Number);return(r<<24|t<<16|n<<8|i)>>>0}function Ae(e){let[r,t]=e.split("/"),n=Number(t);if(!pr.test(r)||!Number.isInteger(n)||n<0||n>32)throw new $(`Invalid CIDR notation: ${e}`);let i=n===0?0:-1<<32-n>>>0;return{network:dr(r)&i,mask:i}}function Kc(e,r){return(e&r.mask)===r.network}function Bc(e){let r=_e[e.toLowerCase()];if(r)return r;if(e.includes("/"))return[Ae(e)];throw new $(`Unknown IPv4 range: "${e}" (expected CIDR or one of: ${Object.keys(_e).join(", ")})`)}var pr,_e,Wc,Vi=m(()=>{"use strict";l();pr=/^((25[0-5]|(2[0-4]|1\d|[1-9]|)\d)\.?\b){4}$/;_e={rfc1918:[Ae("10.0.0.0/8"),Ae("172.16.0.0/12"),Ae("192.168.0.0/16")],loopback:[Ae("127.0.0.0/8")],"link-local":[Ae("169.254.0.0/16")],rfc6598:[Ae("100.64.0.0/10")],multicast:[Ae("224.0.0.0/4")]};_e["non-routable"]=[..._e.rfc1918,..._e.loopback,..._e["link-local"],..._e.rfc6598];Wc={keyword:"ipv4",parameters:[{parameter:"in",default:void 0,type:"string"},{parameter:"min",default:void 0,type:"string"},{parameter:"max",default:void 0,type:"string"},{parameter:"format",default:void 0,type:"string"}],process:(e,r,t,n)=>{if(!pr.test(e))throw new f("Invalid IPv4 address");let{in:i,min:o,max:s,format:a}=n?.args??{};if(i!==void 0&&(o!==void 0||s!==void 0))throw new $('$ipv4: "in" and "min"/"max" are mutually exclusive');if(o!==void 0&&!pr.test(o))throw new $(`$ipv4: invalid "min" address: ${o}`);if(s!==void 0&&!pr.test(s))throw new $(`$ipv4: invalid "max" address: ${s}`);let c=dr(e);if(i!==void 0&&!Bc(i).some(g=>Kc(c,g)))throw new f(`IPv4 address not in range "${i}"`);if(o!==void 0&&c<dr(o))throw new f(`IPv4 address below minimum ${o}`);if(s!==void 0&&c>dr(s))throw new f(`IPv4 address above maximum ${s}`);return a==="integer"?c:e},describe:e=>{if(!e)return;let r=Array.isArray(e)?e[0]:e.in,t=Array.isArray(e)?e[1]:e.min,n=Array.isArray(e)?e[2]:e.max,i=r?.description,o=t?.description,s=n?.description;if(i!==void 0)return`in ${i}`;if(o!==void 0&&s!==void 0)return`${o}\u2013${s}`;if(o!==void 0)return`\u2265${o}`;if(s!==void 0)return`\u2264${s}`}}});var ji={};h(ji,{IPV6_CONSTRAINT:()=>vc});function hr(e){let r=e.replace(/%.*$/,""),t=Yc.exec(r);if(t){let[o,s,a,c]=[t[1],t[2],t[3],t[4]].map(Number),d=(o<<8|s).toString(16),g=(a<<8|c).toString(16);r=r.slice(0,t.index)+`${d}:${g}`}if(r.includes("::")){let[o,s]=r.split("::"),a=o?o.split(":"):[],c=s?s.split(":"):[],d=8-a.length-c.length,g=Array(d).fill("0");r=[...a,...g,...c].join(":")}let n=r.split(":"),i=0n;for(let o of n)i=i<<16n|BigInt(parseInt(o,16));return i}function rr(e){let r=e.lastIndexOf("/");if(r===-1)throw new $(`Invalid IPv6 CIDR notation: ${e}`);let t=e.slice(0,r),n=Number(e.slice(r+1));if(!lr.test(t)||!Number.isInteger(n)||n<0||n>128)throw new $(`Invalid IPv6 CIDR notation: ${e}`);let i=n===0?0n:(1n<<128n)-1n<<BigInt(128-n);return{network:hr(t)&i,mask:i}}function Zc(e,r){return(e&r.mask)===r.network}function Xc(e){let r=Le[e.toLowerCase()];if(r)return r;if(e.includes("/"))return[rr(e)];throw new $(`Unknown IPv6 range: "${e}" (expected CIDR or one of: ${Object.keys(Le).join(", ")})`)}var lr,Yc,Le,vc,zi=m(()=>{"use strict";l();lr=/^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$/,Yc=/(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/;Le={loopback:[rr("::1/128")],"link-local":[rr("fe80::/10")],"unique-local":[rr("fc00::/7")],multicast:[rr("ff00::/8")]};Le["non-routable"]=[...Le.loopback,...Le["link-local"],...Le["unique-local"]];vc={keyword:"ipv6",parameters:[{parameter:"in",default:void 0,type:"string"},{parameter:"min",default:void 0,type:"string"},{parameter:"max",default:void 0,type:"string"}],process:(e,r,t,n)=>{if(!lr.test(e))throw new f("Invalid IPv6 address");let{in:i,min:o,max:s}=n?.args??{};if(i!==void 0&&(o!==void 0||s!==void 0))throw new $('$ipv6: "in" and "min"/"max" are mutually exclusive');if(o!==void 0&&!lr.test(o))throw new $(`$ipv6: invalid "min" address: ${o}`);if(s!==void 0&&!lr.test(s))throw new $(`$ipv6: invalid "max" address: ${s}`);let a=hr(e);if(i!==void 0&&!Xc(i).some(d=>Zc(a,d)))throw new f(`IPv6 address not in range "${i}"`);if(o!==void 0&&a<hr(o))throw new f(`IPv6 address below minimum ${o}`);if(s!==void 0&&a>hr(s))throw new f(`IPv6 address above maximum ${s}`);return e},describe:e=>{if(!e)return;let r=Array.isArray(e)?e[0]:e.in,t=Array.isArray(e)?e[1]:e.min,n=Array.isArray(e)?e[2]:e.max,i=r?.description,o=t?.description,s=n?.description;if(i!==void 0)return`in ${i}`;if(o!==void 0&&s!==void 0)return`${o}\u2013${s}`;if(o!==void 0)return`\u2265${o}`;if(s!==void 0)return`\u2264${s}`}}});var Di={};h(Di,{IS_ARRAY_CONSTRAINT:()=>Gc});var Gc,Li=m(()=>{"use strict";l();Gc={keyword:"is-array",process:(e,r,t)=>{if(!Array.isArray(e))throw new f("Must be an array");return e},description:""}});var Mi={};h(Mi,{IS_DATE_CONSTRAINT:()=>Jc});var Jc,qi=m(()=>{"use strict";l();_();Jc={keyword:"is-date",process:e=>{if(e instanceof Date&&!isNaN(e.getTime()))return e;throw new f(`Invalid date: ${w(e)}`)},description:""}});var Fi={};h(Fi,{IS_NUMBER_CONSTRAINT:()=>Qc});var Qc,Hi=m(()=>{"use strict";l();Qc={keyword:"is-number",process:e=>{if(typeof e!="number"||Number.isNaN(e)||!Number.isFinite(e))throw new f("Must be a number");return e},description:""}});var Ki={};h(Ki,{IS_OBJECT_CONSTRAINT:()=>ef});var ef,Bi=m(()=>{"use strict";l();ef={keyword:"is-object",process:(e,r,t)=>{if(typeof e=="object"&&e!==null)return e;throw new f("Must be an object")},description:""}});var Wi={};h(Wi,{IS_STRING_CONSTRAINT:()=>rf});var rf,Yi=m(()=>{"use strict";l();rf={keyword:"is-string",process:e=>{if(typeof e=="string")return e;throw new f("Must be a string")},description:""}});var Zi={};h(Zi,{JOIN_OPERATOR:()=>tf});var tf,Xi=m(()=>{"use strict";tf={keyword:"join",parameters:[{parameter:"separator",default:","}],process:(e,r,t,n)=>{let i=n.args?.separator;return Array.isArray(e)?e.join(i):`${e}`}}});var vi={};h(vi,{JSON_CONSTRAINT:()=>nf});var nf,Gi=m(()=>{"use strict";l();nf={keyword:"json",process:e=>{try{return JSON.parse(e),e}catch{throw new f("Invalid JSON format")}}}});var Ji={};h(Ji,{JSON_DECODE_OPERATOR:()=>of});var of,Qi=m(()=>{"use strict";l();_();of={keyword:"json-decode",process:(e,r,t)=>{if(typeof e!="string")throw new f(`$json-decode requires a string, got ${w(e)}`,{location:t});try{return JSON.parse(e)}catch(n){throw new f(`$json-decode: invalid JSON \u2014 ${n.message}`,{location:t,cause:n})}}}});var eo={};h(eo,{JSON_ENCODE_OPERATOR:()=>sf});var sf,ro=m(()=>{"use strict";sf={keyword:"json-encode",parameters:[{parameter:"indent",default:0}],process:(e,r,t,n)=>{let i=n.args?.indent||0;return JSON.stringify(e,null,i||void 0)}}});var to={};h(to,{KEBAB_CASE_OPERATOR:()=>af});var af,no=m(()=>{"use strict";he();af={keyword:"kebab-case",process:e=>Te(String(e))}});var io={};h(io,{KEYS_OPERATOR:()=>cf});var cf,oo=m(()=>{"use strict";l();_();cf={keyword:"keys",process:(e,r,t)=>{if(typeof e!="object"||e===null||Array.isArray(e))throw new f(`$keys requires a plain object, got ${w(e)}`,{location:t});return Object.keys(e)}}});var so={};h(so,{LENGTH_CONSTRAINT:()=>ff});var ff,ao=m(()=>{"use strict";l();ff={keyword:"length",parameters:[{parameter:"exact",default:void 0,type:"number"},{parameter:"min",default:void 0,type:"number"},{parameter:"max",default:void 0,type:"number"}],process:(e,r,t,n)=>{let{min:i,max:o,exact:s}=n.args,a=Array.isArray(e)?e.length:String(e).length,c=Array.isArray(e)?"elements":"characters";if(s!==void 0){if(a!==s)throw new f(`Length must be exactly ${s} ${c}`);return e}if(i!==void 0&&a<i)throw new f(`Length must be at least ${i} ${c}`);if(o!==void 0&&a>o)throw new f(`Length must be at most ${o} ${c}`);return e},describe:e=>{if(!e)return;let r=Array.isArray(e)?e[0]:e.min,t=Array.isArray(e)?e[1]:e.max,n=Array.isArray(e)?e[2]:e.exact,i=r?.description,o=t?.description,s=n?.description;return s!==void 0?`len=${s}`:i!==void 0&&o!==void 0?`len=${i}-${o}`:i!==void 0?`len\u2265${i}`:o!==void 0?`len\u2264${o}`:void 0}}});var co={};h(co,{LOOKUP_OPERATOR:()=>uf});var uf,fo=m(()=>{"use strict";l();re();uf={keyword:"lookup",parameters:[{parameter:"from",required:!0,type:"object"},{parameter:"path",type:"string"}],process:(e,r,t,n)=>{let{from:i,path:o}=n.args;if(!(i===void 0||o===void 0)){if(typeof i!="object")throw new u('$lookup requires an object argument for "from"',{location:t});if(typeof o!="string")throw new u('$lookup requires a string argument for "path"',{location:t});return ee(i,o)}}}});var uo={};h(uo,{LOWERCASE_OPERATOR:()=>mf});var mf,mo=m(()=>{"use strict";mf={keyword:"lowercase",process:e=>String(e).toLowerCase()}});var po={};h(po,{MAP_OPERATOR:()=>pf});var pf,lo=m(()=>{"use strict";V();X();Re();M();l();_();pf={keyword:"map",parameters:[{parameter:"processor",required:!0}],build:e=>{let r;if(Array.isArray(e)){if(e.length>1)throw new u("Expected exactly one argument for $map operator");r=e[0]}else if(typeof e=="object"){if(Object.keys(e).length!==1)throw new u('Expected only "processor" argument for $map operator');r=e.processor}return r??=new k(t=>t??void 0),new y(new ne(r,t=>{if(Array.isArray(t))return t;if(L(t))return Object.values(t);throw new f(`$map requires an array or plain object, got ${w(t)}`)},(t,n)=>{if(Array.isArray(n))return t;if(L(n))return Object.fromEntries(Object.keys(n).map((i,o)=>[i,t[o]]))}),{$map:r.spec})}}});var ho={};h(ho,{MATCH_OPERATOR:()=>df});var df,wo=m(()=>{"use strict";X();V();l();Qe();df={keyword:"match",build:e=>{let r=(Array.isArray(e)?e[0]:e)?.spec;if(typeof r=="string"&&(r=Oe(r)),!(r instanceof RegExp))throw new u("$match requires a RegExp argument");return new y(new k((t,n,i)=>{if(typeof t!="string")throw new f("$match requires a string input",{location:i});let o=t.match(r);if(o!==null)return o.groups&&Object.keys(o.groups).length>0?{...o.groups}:[...o]}),{$match:r},`${r}`)}}});var yo={};h(yo,{MATCHES_CONSTRAINT:()=>lf});var lf,go=m(()=>{"use strict";X();V();l();Qe();lf={keyword:"matches",build:e=>{let r=(Array.isArray(e)?e[0]:e)?.spec;if(typeof r=="string"&&(r=Oe(r)),!(r instanceof RegExp))throw new u("$matches requires a RegExp argument");let t=new k((n,i,o)=>{if(!r.test(String(n)))throw new f(`Value does not match pattern ${r}`,{location:o});return n});return t.description=`${r}`,new y(t,{$matches:r})}}});var Eo={};h(Eo,{ABS_OPERATOR:()=>hf,CLAMP_OPERATOR:()=>gf,POW_OPERATOR:()=>wf,SQRT_OPERATOR:()=>yf});var hf,wf,yf,gf,Ao=m(()=>{"use strict";l();_();hf={keyword:"abs",process:(e,r,t)=>{if(typeof e!="number"||!Number.isFinite(e))throw new f(`$abs requires a finite number, got ${w(e)}`,{location:t});return Math.abs(e)}},wf={keyword:"pow",parameters:[{parameter:"exponent",required:!0},{parameter:"base"}],process:(e,r,t,n)=>{let i=n.args.exponent,o=n.args.base!==void 0?n.args.base:e;if(typeof o!="number"||!Number.isFinite(o))throw new f(`$pow requires a finite number base, got ${w(o)}`,{location:t});return Math.pow(o,i)}},yf={keyword:"sqrt",process:(e,r,t)=>{if(typeof e!="number"||!Number.isFinite(e)||e<0)throw new f(`$sqrt requires a non-negative finite number, got ${w(e)}`,{location:t});return Math.sqrt(e)}},gf={keyword:"clamp",parameters:[{parameter:"min"},{parameter:"max"}],process:(e,r,t,n)=>{let i=n.args.min,o=n.args.max;if(typeof e!="number"||!Number.isFinite(e))throw new f(`$clamp requires a finite number, got ${w(e)}`,{location:t});if(i!==void 0&&(typeof i!="number"||!Number.isFinite(i)))throw new f(`$clamp min must be a finite number, got ${w(i)}`,{location:t});if(o!==void 0&&(typeof o!="number"||!Number.isFinite(o)))throw new f(`$clamp max must be a finite number, got ${w(o)}`,{location:t});let s=e;return i!==void 0&&(s=Math.max(i,s)),o!==void 0&&(s=Math.min(o,s)),s}}});var So={};h(So,{MERGE_DEEP_OPERATOR:()=>Ef});var Ef,xo=m(()=>{"use strict";V();X();ze();re();l();Ef={keyword:"merge-deep",build:e=>{if(typeof e!="object"||e===null||Array.isArray(e))throw new u("$merge-deep requires an object argument");let r=Object.fromEntries(Object.entries(e).map(([t,n])=>[t,n?.spec??n]));return new k((t,n,i,o)=>{if(typeof t!="object"||t===null||Array.isArray(t))throw new f("$merge-deep requires a plain object input",{location:i});return Ke({},t,o.args)},new y(new ce(e),{"$merge-deep":r}))}}});var Co={};h(Co,{MERGE_OPERATOR:()=>Af});var Af,bo=m(()=>{"use strict";V();X();ze();l();Af={keyword:"merge",build:e=>{if(typeof e!="object"||e===null||Array.isArray(e))throw new u("$merge requires an object argument");let r=Object.fromEntries(Object.entries(e).map(([t,n])=>[t,n?.spec??n]));return new k((t,n,i,o)=>{if(typeof t!="object"||t===null||Array.isArray(t))throw new f("$merge requires a plain object input",{location:i});return{...t,...o.args}},new y(new ce(e),{$merge:r}))}}});var Ro={};h(Ro,{METADATA_OPERATOR:()=>Sf});var Sf,$o=m(()=>{"use strict";te();l();_();Sf={keyword:"metadata",parameters:[{parameter:"name",required:!0,type:"string"},{parameter:"schema",required:!1,default:void 0},{parameter:"inherit",required:!1,default:!0}],process:(e,r,t,n)=>{let i=n.args.name,o=n.args.schema,s=n.args.inherit;if(o!==void 0){if(o instanceof C)return o.metadata[i];if(typeof o=="string"){let c=t.relative(o);if(c===void 0)throw new u(`$metadata was unable to retrieve a schema at ${w(o)}`);t=c}else throw new u(`$metadata expects a valid schema, got ${w(o)}`,{location:t})}let a=t;for(;a!==void 0;){if(a.schema.metadata[i]!==void 0)return a.schema.metadata[i];if(!s)break;a=a.parent}}}});var Po={};h(Po,{NEGATIVE_CONSTRAINT:()=>xf});var xf,To=m(()=>{"use strict";l();xf={keyword:"negative",process:e=>{if(typeof e!="number"||!Number.isFinite(e)||e>=0)throw new f("Must be a negative number");return e}}});var Oo={};h(Oo,{NEVER_CONSTRAINT:()=>Cf});var Cf,Io=m(()=>{"use strict";se();V();Ee();Y();l();Cf={keyword:"never",build:e=>{let r;if(Array.isArray(e))if(e.length===1)r=e[0];else if(e.length===0)r=new y(new T,[]);else throw new u("$never requires no more than a single value argument");else typeof e=="object"&&(r=e.processor);if(!(r instanceof N))throw new u("$never requires a value argument");let t=r.description&&/[|&>∧· ]/.test(r.description),n=r.description?t?`!(${r.description})`:`!${r.description}`:void 0,i={$never:r.spec};return new y(new P(r,{success:()=>{throw new f("Value must not match the specified condition")},failure:o=>o},[P.CHECK_DEFINED]),i,n)}}});var _o={};h(_o,{NON_EMPTY_CONSTRAINT:()=>bf});var bf,ko=m(()=>{"use strict";l();bf={keyword:"non-empty",process:(e,r,t)=>{if(typeof e=="string"){if(e.trim().length===0)throw new f("String cannot be empty or whitespace only")}else if(Array.isArray(e)){if(e.length===0)throw new f("Array cannot be empty")}else if(typeof e=="object"&&e!==null){if(Object.keys(e).length===0)throw new f("Object cannot be empty")}else{if(e===void 0)throw new f("Value cannot be undefined");if(e===null)throw new f("Value cannot be null")}return e}}});var No={};h(No,{NOT_CONSTRAINT:()=>Rf});var Rf,Uo=m(()=>{"use strict";se();V();Ee();Y();l();Rf={keyword:"not",build:e=>{let r;if(Array.isArray(e))if(e.length===1)r=e[0];else if(e.length===0)r=new y(new T,[]);else throw new u("$not requires no more than a single value argument");else typeof e=="object"&&(r=e.processor);if(!(r instanceof N))throw new u("$not requires a value argument");let t=r.description&&/[|&>∧· ]/.test(r.description),n=r.description?t?`!(${r.description})`:`!${r.description}`:void 0,i={$not:r.spec};return new y(new P(r,{success:()=>{throw new f("Value must not match the specified condition")},failure:()=>!0},[P.CHECK_TRUTHY]),i,n)}}});var Vo={};h(Vo,{NUMBER_OPERATOR:()=>$f});var $f,jo=m(()=>{"use strict";oe();l();$f={keyword:"number",process:e=>{if(e===F)return 0;let r=Number(e);if(Number.isNaN(r)||!Number.isFinite(r))throw new f("Must be a number or convertible to a number");return r}}});var zo={};h(zo,{NUMERIC_CONSTRAINT:()=>Pf});var Pf,Do=m(()=>{"use strict";l();Pf={keyword:"numeric",process:e=>{let r=`${e}`;if(!/^[0-9]+$/.test(r))throw new f("Must contain only digits");return e}}});var Lo={};h(Lo,{OBJECT_OPERATOR:()=>Tf});var Tf,Mo=m(()=>{"use strict";xe();oe();l();_();Tf={keyword:"object",process:e=>{if(e===F&&(e={}),typeof e=="string")try{e=Fe(e)}catch(r){throw new f(`Invalid input string for object: ${w(e)}`,{cause:r})}if(Array.isArray(e)&&e.every(r=>Array.isArray(r)&&r.length===2))return Object.fromEntries(e);if(typeof e=="object")return e;throw new f(`Invalid input for object: ${w(e)}`)}}});var qo={};h(qo,{OMIT_OPERATOR:()=>Of});var Of,Fo=m(()=>{"use strict";V();X();Pe();M();l();Of={keyword:"omit",build:e=>{if(!Array.isArray(e)||e.length===0)throw new u("$omit requires a non-empty array of key names");let r=K(e,t=>t.spec);return new k((t,n,i,o)=>{let s=Array.isArray(o.args)?o.args:[];if(typeof t!="object"||t===null)throw new f("$omit requires an object or array input",{location:i});return Array.isArray(t)?t.filter((a,c)=>!s.includes(c)):Object.fromEntries(Object.entries(t).filter(([a])=>!s.includes(a)))},new y(new ie(e),r))}}});var wr,Ho=m(()=>{"use strict";Y();wr=class extends T{#e;constructor(r=[]){super(),this.#e=r.map(t=>q(t))}execute(r,...t){let n=!1,i=this.#e.map(o=>{let s=o.execute(r,...t);return s instanceof Promise&&(n=!0),s});return n?Promise.all(i):i}}});var Ko={};h(Ko,{PARALLEL_OPERATOR:()=>If});var If,Bo=m(()=>{"use strict";Ho();V();l();M();If={keyword:"parallel",build:e=>{if(!Array.isArray(e))throw new u("$parallel requires an array of processors");let r={$parallel:K(e,i=>i.spec)},t=e.map(i=>i.description).filter(i=>i!==void 0),n=t.length>0?t.map(i=>/[|&>·∧ ]/.test(i)?`(${i})`:i).join(" \u2297 "):void 0;return new y(new wr(e),r,n)}}});var Wo={};h(Wo,{PASCAL_CASE_OPERATOR:()=>_f});var _f,Yo=m(()=>{"use strict";he();_f={keyword:"pascal-case",process:e=>jr(String(e))}});var Zo={};h(Zo,{PICK_OPERATOR:()=>kf});var kf,Xo=m(()=>{"use strict";V();X();Pe();M();l();kf={keyword:"pick",build:e=>{if(!Array.isArray(e)||e.length===0)throw new u("$pick requires a non-empty array of key names");let r=K(e,t=>t.spec);return new k((t,n,i,o)=>{let s=Array.isArray(o.args)?o.args:[];if(typeof t!="object"||t===null)throw new f("$pick requires an object or array input",{location:i});if(Array.isArray(t))return s.filter(c=>c>=0&&c<t.length).map(c=>t[c]);let a={};for(let c of s)c in t&&(a[c]=t[c]);return a},new y(new ie(e),r))}}});var Jo={};h(Jo,{PHONE_CONSTRAINT:()=>Uf});function Nf(e){let r=e.trim();return r.startsWith("+")?"+"+r.slice(1).replace(/\D/g,""):r.replace(/\D/g,"")}function Go(e,r){let t=0;return r.replace(/#/g,()=>e[t++]??"")}var vo,Uf,Qo=m(()=>{"use strict";l();vo={1:{lengths:[10],validate:/^[2-9]\d{2}[2-9]\d{6}$/,national:"(###) ###-####",international:"### ### ####"}};Uf={keyword:"phone",parameters:[{parameter:"international",type:"boolean",default:!1},{parameter:"country",default:"1"},{parameter:"countries",default:null}],process:(e,r,t,n)=>{let{international:i,country:o,countries:s}=n.args,a=s?{...vo,...s}:vo,c=Nf(e);if(!c||!/^\+?\d+$/.test(c))throw new f("Invalid phone number format");let d,g="";if(c.startsWith("+")){let A=c.slice(1),E=!1;for(let p of[1,2,3]){if(p>A.length)break;let b=A.slice(0,p);if(a[b]){d=b,g=A.slice(p),E=!0;break}}if(!E){if(!i)throw new f(`Phone number country code does not match +${o}`);if(A.length<7||A.length>15)throw new f("Invalid phone number length");return"+"+A}}else{let A=a[o];if(d=o,A)if(A.lengths.map(p=>p+o.length).includes(c.length)&&c.startsWith(o))g=c.slice(o.length);else if(A.lengths.includes(c.length))g=c;else throw new f(`Invalid phone number length for country code +${o}`);else g=c}if(!i&&d!==o)throw new f(`International numbers not accepted; expected country code +${o}`);let S=a[d];if(S){if(!S.lengths.includes(g.length))throw new f(`Invalid phone number length for country code +${d}`);if(S.validate&&!S.validate.test(g))throw new f(`Invalid phone number for country code +${d}`)}else{let A=d.length+g.length;if(A<7||A>15)throw new f("Invalid phone number length")}return i?S?.international?`+${d} ${Go(g,S.international)}`:`+${d}${g}`:S?.national?Go(g,S.national):g}}});var es={};h(es,{PIPELINE_OPERATOR:()=>Vf});var Vf,rs=m(()=>{"use strict";Ye();V();M();l();Vf={keyword:"pipeline",build:e=>{if(!Array.isArray(e))throw new $("$pipeline requires an array of processors");let r=e.map(i=>i.description??"").filter(Boolean),t=r.length>1?r.map(i=>i.includes("|")||i.includes("&")?`(${i})`:i).join(" >> "):r[0],n={$pipeline:K(e,i=>i.spec)};return new y(new ae(e),n,t)}}});var ts={};h(ts,{PORT_CONSTRAINT:()=>jf});var jf,ns=m(()=>{"use strict";l();jf={keyword:"port",process:(e,r,t)=>{let n=Number(e);if(!(Number.isInteger(n)&&n>=1&&n<=65535))throw new f("Port must be between 1 and 65535");return t.schema.options.type==="string"?`${n}`:n}}});var is={};h(is,{POSITIVE_CONSTRAINT:()=>zf});var zf,os=m(()=>{"use strict";l();zf={keyword:"positive",process:e=>{if(typeof e!="number"||!Number.isFinite(e)||e<=0)throw new f("Must be a positive number");return e}}});var ss={};h(ss,{PROCESS_OPERATOR:()=>Df});var Df,as=m(()=>{"use strict";te();l();_();Df={keyword:"process",parameters:[{parameter:"schema",required:!0}],process:(e,r,t,n)=>{let i=n.args.schema;if(!(i instanceof C))throw new u(`Schema argument must be an instance of CompiledSchema, got ${w(i)})`,{location:t});return i._process(e)}}});var cs={};h(cs,{PROPERTY_OPERATOR:()=>Lf});var Lf,fs=m(()=>{"use strict";l();Lf={keyword:"property",parameters:[{parameter:"name",required:!0}],process:(e,r,t,n)=>{let i=n.args.name;if(i===void 0)throw new u("$property expects a property name",{location:t});if(t.schema.getPropertySchema(i)===void 0)throw new u(`Unknown $property ${i}`,{location:t});return typeof e=="object"&&e!==null?e[i]:void 0}}});var us={};h(us,{RANGE_CONSTRAINT:()=>Mf});var Mf,ms=m(()=>{"use strict";l();Mf={keyword:"range",parameters:[{parameter:"min",type:"number",default:void 0},{parameter:"max",type:"number",default:void 0}],process:(e,r,t,n)=>{let{min:i,max:o}=n.args,s=Number(e);if(!Number.isFinite(s))throw new f("Value must be a number");if(i!==void 0&&s<i)throw new f(`Value must be at least ${i}`);if(o!==void 0&&s>o)throw new f(`Value must be at most ${o}`);return e},describe:e=>{if(!e)return;let r=Array.isArray(e)?e[0]:e.min,t=Array.isArray(e)?e[1]:e.max,n=r?.description,i=t?.description;return n!==void 0&&i!==void 0?`${n}-${i}`:n!==void 0?`\u2265${n}`:i!==void 0?`\u2264${i}`:void 0}}});var ps={};h(ps,{REFERENCE_OPERATOR:()=>qf});var qf,ds=m(()=>{"use strict";re();l();qf={keyword:"reference",parameters:[{parameter:"path",required:!0},{parameter:"pending",required:!1,default:!1},{parameter:"completed",required:!1,type:"boolean",default:!1}],process:(e,r,t,n)=>{let i=n.args.path;if(i===void 0)throw new u("$reference expects a path");let o=n.state.getRelativeState(i),s=n.args.completed;if(o===void 0){if(s)return;let a=t.relative(i);return a?ee(r,a.path):void 0}if(!(s&&!o.completed)){if(o.value!==void 0)return o.value;if(n.args.pending)return o.pending}}}});var ls={};h(ls,{REQUIRE_CONSTRAINT:()=>Ff});var Ff,hs=m(()=>{"use strict";se();V();Ee();Y();l();Ff={keyword:"require",build:e=>{let r;if(Array.isArray(e))if(e.length===1)r=e[0];else if(e.length===0)r=new y(new T,[]);else throw new u("$require requires no more than a single processor argument");else typeof e=="object"&&(r=e.processor);if(!(r instanceof N))throw new u("$require requires a processor argument");let t=e.length===0?"$require":{$require:r.spec},n=r.description;return new y(new P(r,{failure:i=>{throw i instanceof f?i:new f("Processed value was undefined",{cause:i})}},[P.CHECK_DEFINED,P.PASS_ERROR]),t,n)}}});var ws={};h(ws,{REVERSE_OPERATOR:()=>Hf});var Hf,ys=m(()=>{"use strict";l();_();Hf={keyword:"reverse",process:(e,r,t)=>{if(!Array.isArray(e))throw new f(`$reverse requires an array, got ${w(e)}`,{location:t});return[...e].reverse()}}});var gs={};h(gs,{ROUND_OPERATOR:()=>Kf});var Kf,Es=m(()=>{"use strict";Kf={keyword:"round",parameters:[{parameter:"precision",default:0}],process:(e,r,t,n)=>{let i=n.args.precision,o=Math.pow(10,i),s=Number(e);return Number.isFinite(s)?Math.round(s*o)/o:e}}});var As={};h(As,{NORMALIZE_OPERATOR:()=>Bf});var Bf,Ss=m(()=>{"use strict";te();l();_();Bf={keyword:"normalize",parameters:[{parameter:"schema",required:!0},{parameter:"value",required:!1}],process:(e,r,t,n={})=>{let i=n.args.schema;if(!(i instanceof C))throw new u(`Schema argument must be an instance of CompiledSchema, got ${w(i)})`,{location:t});let o=n.cycleCheck??new Set;if(o.has(t.schema))throw new u("Cycle detected while processing $normalize",{location:t,value:e});o.add(t.schema);let s=n.args.value??e;return i._normalizeValue(s,r,void 0,{cycleCheck:o})}}});var bs={};h(bs,{SEMVER_CONSTRAINT:()=>Gf});function tr(e){let r=Cs.exec(e.trim());if(!r)throw new $(`Invalid semver: "${e}"`);return{major:Number(r[1]),minor:Number(r[2]),patch:Number(r[3]),prerelease:r[4]?r[4].split("."):[],build:r[5]?r[5].split("."):[]}}function Wf(e,r){if(e.length===0&&r.length===0)return 0;if(e.length===0)return 1;if(r.length===0)return-1;let t=Math.max(e.length,r.length);for(let n=0;n<t;n++){if(n>=e.length)return-1;if(n>=r.length)return 1;let i=e[n],o=r[n];if(i===o)continue;let s=/^\d+$/.test(i),a=/^\d+$/.test(o);if(s&&!a)return-1;if(!s&&a)return 1;if(s&&a){let c=Number(i)-Number(o);if(c!==0)return c}else{if(i<o)return-1;if(i>o)return 1}}return 0}function pe(e,r){return e.major-r.major||e.minor-r.minor||e.patch-r.patch||Wf(e.prerelease,r.prerelease)}function xs(e){let r=Yf.exec(e.trim());if(!r)throw new $(`Invalid semver comparator: "${e}"`);let t=r[1]||"=",n=tr(r[2]);switch(t){case"=":return i=>pe(i,n)===0;case">":return i=>pe(i,n)>0;case">=":return i=>pe(i,n)>=0;case"<":return i=>pe(i,n)<0;case"<=":return i=>pe(i,n)<=0;default:throw new $(`Unknown semver operator: "${t}"`)}}function Zf(e){let r=tr(e),t;return r.major>0?t={major:r.major+1,minor:0,patch:0,prerelease:[],build:[]}:r.minor>0?t={major:0,minor:r.minor+1,patch:0,prerelease:[],build:[]}:t={major:0,minor:0,patch:r.patch+1,prerelease:[],build:[]},n=>pe(n,r)>=0&&pe(n,t)<0}function Xf(e){let r=tr(e),t={major:r.major,minor:r.minor+1,patch:0,prerelease:[],build:[]};return n=>pe(n,r)>=0&&pe(n,t)<0}function vf(e){let r=e.trim();if(r.startsWith("^"))return Zf(r.slice(1));if(r.startsWith("~"))return Xf(r.slice(1));let t=r.split(/\s+/);if(t.length===1)return xs(t[0]);let n=t.map(xs);return i=>n.every(o=>o(i))}var Cs,Yf,Gf,Rs=m(()=>{"use strict";l();Cs=/^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/;Yf=/^(>=|<=|>|<|=)?\s*((?:0|[1-9]\d*)\.(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)(?:-(?:(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+(?:[0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?)$/;Gf={keyword:"semver",parameters:[{parameter:"in",default:void 0,type:"string"},{parameter:"min",default:void 0,type:"string"},{parameter:"max",default:void 0,type:"string"}],process:(e,r,t,n)=>{let i=Cs.exec(e);if(!i)throw new f("Invalid semver");let{in:o,min:s,max:a}=n?.args??{};if(o!==void 0&&(s!==void 0||a!==void 0))throw new $('$semver: "in" and "min"/"max" are mutually exclusive');let c={major:Number(i[1]),minor:Number(i[2]),patch:Number(i[3]),prerelease:i[4]?i[4].split("."):[],build:i[5]?i[5].split("."):[]};if(o!==void 0&&!vf(o)(c))throw new f(`Version not in range "${o}"`);if(s!==void 0&&pe(c,tr(s))<0)throw new f(`Version below minimum ${s}`);if(a!==void 0&&pe(c,tr(a))>0)throw new f(`Version above maximum ${a}`);return e},describe:e=>{if(!e)return;let r=Array.isArray(e)?e[0]:e.in,t=Array.isArray(e)?e[1]:e.min,n=Array.isArray(e)?e[2]:e.max,i=r?.description,o=t?.description,s=n?.description;if(i!==void 0)return`in ${i}`;if(o!==void 0&&s!==void 0)return`${o}\u2013${s}`;if(o!==void 0)return`\u2265${o}`;if(s!==void 0)return`\u2264${s}`}}});var $s={};h($s,{ALL_CONSTRAINT:()=>ru,AND_CONSTRAINT:()=>Qf,ANY_CONSTRAINT:()=>eu,EXCLUSIVE_CONSTRAINT:()=>tu,FIRST_OPERATOR:()=>iu,ONE_CONSTRAINT:()=>nu,OR_CONSTRAINT:()=>Jf});function ke(e,r,t){return n=>{let i;if(Array.isArray(n)?i=n:typeof n=="object"&&n!==null&&(i=Object.values(n)),!Array.isArray(i))throw new $(`${e} requires an array of processors`);let o={[e]:i.map(c=>c.spec)},s=i.map(c=>c.description).filter(c=>c!==void 0),a=s.length>1?s.map(c=>c.includes("&")?`(${c})`:c).join(r):s[0];return t(i,o,a)}}var Jf,Qf,eu,ru,tu,nu,iu,Ps=m(()=>{"use strict";Ee();V();_r();l();_();Jf={keyword:"or",build:ke("$or"," | ",(e,r,t)=>new y(new P(new I(e,[I.TRUTHY_CHECK,I.ANY_CRITERIA,I.RESULT_RETURN,I.CAPTURE_ERRORS]),{failure:n=>{throw new f(`None of the $or conditions ${w(t)} matched`,{value:n})}},[P.CHECK_TRUTHY]),r,t))},Qf={keyword:"and",build:ke("$and"," & ",(e,r,t)=>new y(new P(new I(e,[I.TRUTHY_CHECK,I.ALL_CRITERIA,I.RESULT_RETURN,I.CAPTURE_ERRORS]),{failure:n=>{throw new f(`Not all $and conditions ${w(t)} matched`,{value:n})}},[P.CHECK_TRUTHY]),r,t))},eu={keyword:"any",build:ke("$any"," \u2227 ",(e,r,t)=>new y(new P(new I(e,[I.DEFINED_CHECK,I.ANY_CRITERIA,I.RESULT_RETURN,I.CAPTURE_ERRORS]),{failure:n=>{throw new f(`None of the $any conditions ${w(t)} succeeded`,{value:n})}},[P.CHECK_DEFINED]),r,t))},ru={keyword:"all",build:ke("$all"," \xB7 ",(e,r,t)=>new y(new P(new I(e,[I.DEFINED_CHECK,I.ALL_CRITERIA,I.RESULT_RETURN,I.CAPTURE_ERRORS]),{failure:n=>{throw new f(`Not all $all conditions ${w(t)} succeeded`,{value:n})}},[P.CHECK_DEFINED]),r,t))},tu={keyword:"exclusive",build:ke("$exclusive"," \u2295 ",(e,r,t)=>new y(new P(new I(e,[I.TRUTHY_CHECK,I.EXCLUSIVE_CRITERIA,I.RESULT_RETURN,I.CAPTURE_ERRORS]),{failure:n=>{throw new f(`Exactly one of the $exclusive conditions ${w(t)} must match`,{value:n})}},[P.CHECK_TRUTHY]),r,t))},nu={keyword:"one",build:ke("$one"," \u2295 ",(e,r,t)=>new y(new P(new I(e,[I.DEFINED_CHECK,I.EXCLUSIVE_CRITERIA,I.RESULT_RETURN,I.CAPTURE_ERRORS]),{failure:n=>{throw new f(`Exactly one of the $one conditions ${w(t)} must succeed`,{value:n})}},[P.CHECK_DEFINED]),r,t))},iu={keyword:"first",build:ke("$first"," ?? ",(e,r,t)=>new y(new P(new I(e,[I.DEFINED_CHECK,I.ANY_CRITERIA,I.RESULT_RETURN,I.CAPTURE_ERRORS]),{},[P.CHECK_DEFINED,P.PASS_RESULT]),r,t))}});var Ts={};h(Ts,{SORT_OPERATOR:()=>ou});var ou,Os=m(()=>{"use strict";l();_();ou={keyword:"sort",parameters:[{parameter:"key",default:null},{parameter:"direction",default:"asc"}],process:(e,r,t,n)=>{if(!Array.isArray(e))throw new f(`$sort requires an array, got ${w(e)}`,{location:t});let i=n.args?.key??null,o=n.args?.direction??"asc",s=(c,d)=>typeof c=="number"&&typeof d=="number"?c-d:String(c)<String(d)?-1:String(c)>String(d)?1:0,a=[...e].sort(i?(c,d)=>s(c[i],d[i]):s);return o==="desc"?a.reverse():a}}});var Is={};h(Is,{SPLIT_OPERATOR:()=>su});var su,_s=m(()=>{"use strict";su={keyword:"split",parameters:[{parameter:"separator",default:","},{parameter:"limit",default:void 0}],process:(e,r,t,n)=>{let i=n.args?.separator,o=n.args?.limit;return`${e}`.split(i,o)}}});var ks={};h(ks,{PAD_OPERATOR:()=>fu,REPLACE_OPERATOR:()=>au,SUBSTRING_OPERATOR:()=>cu});var au,cu,fu,Ns=m(()=>{"use strict";l();_();au={keyword:"replace",parameters:[{parameter:"pattern",required:!0},{parameter:"replacement",required:!0,type:"string"}],process:(e,r,t,n)=>{let{pattern:i,replacement:o}=n.args;if(typeof i!="string"&&!(i instanceof RegExp))throw new u(`$replace pattern must be a string or RegExp, got ${w(i)}`);if(typeof o!="string")throw new u(`$replace replacement must be a string, got ${w(o)}`);if(typeof e!="string")throw new f(`$replace requires a string input, got ${w(e)}`,{location:t});return typeof i=="string"?e.replaceAll(i,o):e.replace(i,o)}},cu={keyword:"substring",parameters:[{parameter:"start",required:!0,type:"number"},{parameter:"length",type:"number",default:void 0}],process:(e,r,t,n)=>{if(typeof e!="string")throw new f(`$substring requires a string input, got ${w(e)}`,{location:t});let i=n.args.start,o=n.args.length;return o!==void 0?e.substring(i,i+o):e.substring(i)}},fu={keyword:"pad",parameters:[{parameter:"width",required:!0},{parameter:"char",default:" "},{parameter:"side",default:"left"}],process:(e,r,t,n)=>{if(typeof e!="string")throw new f(`$pad requires a string input, got ${w(e)}`,{location:t});let i=n.args.width,o=n.args.char;return n.args.side==="right"?e.padEnd(i,o):e.padStart(i,o)}}});var Us={};h(Us,{STRING_OPERATOR:()=>uu});var uu,Vs=m(()=>{"use strict";xe();oe();l();uu={keyword:"string",process:e=>{if(typeof e=="string")return e;if(e==null)throw new f("Invalid string",{value:e});return e===F?"":typeof e=="object"?e instanceof Date?e.toISOString():we(e):String(e)}}});var js={};h(js,{TARGET_OPERATOR:()=>mu});var mu,zs=m(()=>{"use strict";mu={keyword:"target",process:(e,r)=>r}});var Ds={};h(Ds,{TEMPLATE_OPERATOR:()=>pu});var pu,Ls=m(()=>{"use strict";X();V();l();pu={keyword:"template",build:e=>{let r=(Array.isArray(e)?e[0]:e)?.spec;if(typeof r!="string")throw new u("$template requires a string argument");let t=new k((n,i,o)=>{if(typeof n!="object"||n===null)throw new f("$template requires an object input",{location:o});return r.replace(/\{\{/g,"\0").replace(/\}\}/g,"").replace(/\{([^}]+)\}/g,(s,a)=>{let c=n[a];return c===void 0?"":String(c)}).replace(/\x00/g,"{").replace(/\x01/g,"}")});return t.description=r,new y(t,{$template:r})}}});var Ms={};h(Ms,{TITLE_CASE_OPERATOR:()=>du});var du,qs=m(()=>{"use strict";he();du={keyword:"title-case",process:e=>Lr(String(e))}});var Fs={};h(Fs,{TYPE_OPERATOR:()=>lu});var lu,Hs=m(()=>{"use strict";te();lu={keyword:"type",process:e=>e===null?"null":e===void 0?"undefined":e instanceof Date?"date":Array.isArray(e)?"array":e instanceof C?"schema":typeof e}});var Ks={};h(Ks,{TRIM_OPERATOR:()=>hu});var hu,Bs=m(()=>{"use strict";hu={keyword:"trim",process:e=>String(e).trim()}});var Ws={};h(Ws,{TRUTHY_CONSTRAINT:()=>wu});var wu,Ys=m(()=>{"use strict";le();l();wu={keyword:"truthy",process:e=>{if(J(e))return e;throw new f("Must be truthy")}}});var Zs={};h(Zs,{UNIQUE_OPERATOR:()=>yu});var yu,Xs=m(()=>{"use strict";l();_();yu={keyword:"unique",process:(e,r,t)=>{if(!Array.isArray(e))throw new f(`$unique requires an array, got ${w(e)}`,{location:t});return[...new Set(e)]}}});var vs={};h(vs,{UPPERCASE_OPERATOR:()=>gu});var gu,Gs=m(()=>{"use strict";gu={keyword:"uppercase",process:e=>String(e).toUpperCase()}});var Js={};h(Js,{URL_CONSTRAINT:()=>Eu});var Eu,Qs=m(()=>{"use strict";l();Eu={keyword:"url",process:e=>{try{return new URL(e).toString()}catch{throw new f("Invalid URL format")}}}});var ea={};h(ea,{URL_DECODE_OPERATOR:()=>Au});var Au,ra=m(()=>{"use strict";l();_();Au={keyword:"url-decode",parameters:[{parameter:"full",default:!1}],process:(e,r,t,n)=>{if(typeof e!="string")throw new f(`$url-decode requires a string, got ${w(e)}`,{location:t});let i=n.args?.full??!1;try{return i?decodeURI(e):decodeURIComponent(e)}catch(o){throw new f(`$url-decode: malformed URI sequence \u2014 ${o.message}`,{location:t,cause:o})}}}});var ta={};h(ta,{URL_ENCODE_OPERATOR:()=>Su});var Su,na=m(()=>{"use strict";Su={keyword:"url-encode",parameters:[{parameter:"full",default:!1}],process:(e,r,t,n)=>n.args?.full??!1?encodeURI(`${e}`):encodeURIComponent(`${e}`)}});var ia={};h(ia,{UUID_CONSTRAINT:()=>xu});var xu,oa=m(()=>{"use strict";l();xu={keyword:"uuid",process:e=>{if(!/^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(e))throw new f("Invalid UUID format");return e}}});var sa={};h(sa,{VALUES_OPERATOR:()=>Cu});var Cu,aa=m(()=>{"use strict";l();_();Cu={keyword:"values",process:(e,r,t)=>{if(typeof e!="object"||e===null||Array.isArray(e))throw new f(`$values requires a plain object, got ${w(e)}`,{location:t});return Object.values(e)}}});te();G();te();G();qe();Sr();se();l();se();l();M();function Ve(e){if(typeof e=="string"&&e.charAt(0)==="$")return!0;if(typeof e=="object"&&e!==null){let r=Object.keys(e);if(r.length===1&&r[0].charAt(0)==="$")return!0}return!1}function _t(e){let r,t=[];if(typeof e=="string"&&e.charAt(0)==="$")r=e.slice(1);else if(typeof e=="object"&&e!==null){let n=Object.keys(e);n.length===1&&n[0].charAt(0)==="$"&&(r=n[0].slice(1),t=e[n[0]])}if(!r)throw new u("Not a keyword operation");return[r,t]}function cr(e){if(e==null)return!1;if(e instanceof N)return!0;if(Array.isArray(e)){for(let r=0;r<e.length;++r)if(!cr(e[r]))return!1;return!0}if(L(e)){let r=0;for(let t of Object.keys(e))if(t.charAt(0)==="$"&&r++,r>1||t!=="$literal"&&!cr(e[t]))return!1;return!0}return!0}G();l();re();_();function kt(e,r,t){if(!e.isUnion)return e;let n=Array.from(e.propertyEntries).filter(A=>A[1].isUnionKey);if(n.length===0)return e;if(n.length>1)throw new O(`Union schema has multiple properties marked as union keys: ${n.map(A=>A[0]).join(", ")}`,{location:t});let i=n[0][0],o=n[0][1],s=t.relative(i),a=[...e.unionSchemaEntries],c=new Set;for(let[A]of a)c.add(o._normalizeValue(A,void 0,void 0,{sync:!0}));if(c.size!==a.length)throw new O("Union keys must not collide after normalization with the unionKey property schema",{location:t});let d=(o.values??[]).sort(),g=[...c].sort();if(d.length>0){if(!v(d,g))throw new O(`Union key schema values {${d.join("|")}} do not include all possible union keys {${g.join("|")}}`,{location:s})}else{if(o.isSelector)throw new O("Cannot populate values for a schema that is both a selector and a union key",{location:s});o.options.values=g}if(Array.isArray(e.handlers.discriminators)&&e.handlers.discriminators.length>0)return e;let S=this;return e.handlers.discriminators=[S.resolver.compileValueProcessorSpec(S,ka(e,i))],e}function Nt(e,r,t,n){if(!e.isUnion||Array.isArray(e.handlers.discriminators)&&e.handlers.discriminators.length>0||e.hasValues)return e;let i=this,o=jt(e);for(let[s,a]of o){if(e.getPropertySchema(s))continue;if(a.size===1){let[b]=a,R=b.getPropertySchema(s);if(R&&!R.hasConditions&&!R.required&&R.default===void 0){e._setPropertySchema(s,R);continue}}let c,d=new Set,g=!0,S,A=!0;for(let b of a){let R=b.getPropertySchema(s);if(R){if(S||(S=R.handlers.normalizers),R.metadata.parserTypeHint&&(c===void 0?c=R.metadata.parserTypeHint:c&&c!==R.metadata.parserTypeHint&&(c="any",g=!1)),!R.hasValues){A=!1;continue}for(let U of R.values??[]){let W=R._normalizeValue(U,void 0,void 0,{sync:!0});g&&W!==U&&(g=!1),d.add(W),c===void 0&&i.resolver.hasSchema(typeof U)&&(c=typeof U)}}}let E=g&&S,p=new x(c??"any");if(E&&S)for(let b of S)p.normalizer(b);d.size>0&&(p.values(Array.from(d)),A||p.option("allowUnknownValues",!0)),e._setPropertySchema(s,this.compile(p))}return e.handlers.discriminators=[i.resolver.compileValueProcessorSpec(i,_a(e))],e}function Ut(e){if(!e.isUnion||e.hasValues)return e;let r=new Set,t=!0;for(let[,n]of e.unionSchemaEntries){if(!n.hasValues){t=!1;continue}for(let i of n.values)r.add(i)}return r.size===0||(e.options.values=[...r],t||(e.options.allowUnknownValues=!0)),e}function Vt(e){if(!e.isUnion)return e;for(let[r,t]of e.unionSchemaEntries){let n=["values","type","default"];for(let[i,o]of Object.entries(e.options??{}))n.includes(i)||o!==void 0&&t.options[i]===void 0&&(t.options[i]=o)}return e}function jt(e){let r=Array.from(e.unionSchemaEntries).map(s=>s[1]),t=new Map;for(let s of r){let a=!1;for(let[c,d]of s.propertyEntries)Array.isArray(d.values)&&d.values.length>0&&(t.has(c)||t.set(c,new Set),t.get(c).add(s),a=!0);if(!a){let c=e.findUnionKey(s)}}let n=new Set,i=new Set;for(let s=0;s<r.length;s++){let a=r[s];for(let[c,d]of a.propertyEntries){if(t.has(c)||i.has(c)||n.has(c))continue;if(d.default!==void 0){n.add(c);continue}let g=!0;for(let S=s+1;S<r.length;S++)if(r[S].getPropertySchema(c)){i.add(c),g=!1;break}g&&t.set(c,new Set([a]))}}for(let s of t.keys())n.has(s)&&t.delete(s);let o=new Set;for(let s=0;s<r.length;s++)for(let a=s+1;a<r.length;a++){let c=r[s],d=r[a],g=!1,S=!0;for(let[A,E]of t){if(E.forEach(Se=>o.add(Se)),!E.has(c)||!E.has(d))continue;S=!1;let p=c.getPropertySchema(A),b=d.getPropertySchema(A),R=p?.values??[],U=b?.values??[];if(!R.some(Se=>U.includes(Se))){g=!0;break}}if(!g&&!S)throw new O("Union members are indistinguishable (cannot discriminate between schemas)")}if(r.length>1&&o.size!==r.length){for(let s of r)if(!o.has(s))throw new O(`Union member ${w(e.findUnionKey(s))} cannot be uniquely discriminated`)}return t}function _a(e){if(!e.isUnion)throw new O("Can only generate a discriminator for a union");let r=Array.from(e.unionSchemaEntries).map(i=>i[1]),t=jt(e);function n(i,o,s,a){let c=new Set(r),d=!1;for(let[g,S]of t){let A=i?.[g];if(A!==void 0){if(S.size===1){let[E]=S;if(c.has(E))c=new Set([E]);else if(c=new Set,c.size===0)throw new de("Union resolution conflict with",{property:g,location:s,value:A})}for(let E of S){if(!c.has(E))continue;let p=s.union(E)?.relative(g);if(p!==void 0){if(p.schema.checkAccepts(A))d=!0;else if(c.delete(E),c.size===0)throw new de("Union resolution conflict with",{property:g,value:A,location:s})}}}}if(c.size===1&&d)return Array.from(c)[0];if(c.size<=1){if(a?.strict||a?.context?.final)throw new de("Union resolution failure (no matches)",{location:s});return}else{if(a?.strict||a?.context?.final){let g=Array.from(c).map(S=>e.findUnionKey(S)).join("|");throw new de(`Union resolution ambiguity (could be ${g})`,{location:s})}return}}return n}function ka(e,r){if(!e.getPropertySchema(r))throw new u(`Discriminator property ${r} not found`);function n(i,o,s){return i?.[r]}return n}l();function zt(e,r,t){let n=[],i=[];for(let g of e.propertyEntries)g[1].isSelector&&n.push(g),g[1].isSelection&&i.push(g);if(n.length===0&&i.length===0)return e;if(n.length>1)throw new O(`Schema multiple properties marked as selectors: ${n.map(g=>g[0]).join(", ")}`,{location:t});let o=n[0][0],s=n[0][1],a=t.relative(`properties.${o}`);if(i.length===0)throw new O(`Schema has selector at property ${o} but no selections`,{location:t});let c=new Set([...s.values??[]]),d=new Set;for(let g of i){let S=g[0],A=g[1],E=t.relative(`properties.${S}`),p=A.selection;p===!0&&(p=S);let b=s._normalizeValue(p,void 0,void 0,{sync:!0});if(c.size&&!c.has(b))throw new O(`Existing selector schema values {${[...c].join("|")}} are missing selection`,{value:p,location:a});d.add(b)}if(!s.hasValues){if(s.isUnionKey)throw new O("Cannot populate values for a schema that is both a selector and a union key",{location:a});s.options.values=[...d].sort()}return e}_();function Dt(e){if(!e.metadata.validatorDescription&&e.handlers.validators?.length){let r=e.handlers.validators.map(t=>t.description??"").filter(Boolean);e.metadata.validatorDescription=r.length>1?r.map(t=>t.includes("|")||t.includes("&")?`(${t})`:t).join(" >> "):r[0]}if(!e.metadata.valueDescription){let r=ir(e);e.metadata.valueDescription=e.required?`<${r}>`:`[${r}]`}return e.metadata.valueName||(e.metadata.valueName=e.metadata.parserTypeHint??"value"),e.options.default!==void 0&&e.metadata.defaultValueDescription===void 0&&(typeof e.options.default=="function"?e.metadata.defaultValueDescription="":e.metadata.defaultValueDescription=w(e.options.default)),e}te();l();function Nr(e,r,t){if(e===!0)return{};if(e instanceof C)return e;if(this.normalizeCache.has(e))return this.normalizeCache.get(e);let n={};this.normalizeCache.set(e,n),e=this.resolver.resolve(e,!1);for(let i of["properties","unionSchemas","metadata","options","handlers"])if(e[i])for(let[o,s]of Object.entries(e[i])){if(s===void 0)continue;n[i]===void 0&&(n[i]={});let a=s;i==="handlers"&&s===null&&(a="$null"),n[i][o]=a}return n}function Lt(e,r,t,n){if(e instanceof C)return e;let i=new C(C.__TOKEN);this.compileCache.set(n.state.assignedInput,i);for(let[o,s]of Object.entries(e.properties??{}))if(s instanceof C)i._setPropertySchema(o,s);else throw new O(`Failed to compile property "${o}" schema`,{location:t});for(let[o,s]of Object.entries(e.unionSchemas??{}))if(s instanceof C)i._setUnionSchema(o,s);else throw new O(`Failed to compile union "${o}" schema `,{location:t});return Object.assign(i.handlers,e.handlers),Object.assign(i.metadata,e.metadata),Object.assign(i.options,e.options),i}function Mt(e,r,t){if(!(e instanceof C))throw new O("Not a schema",{location:t});if(e.isUnion&&!e.handlers.discriminators)throw new O("No discriminator defined for union",{location:t});if(e.hasChildren&&(!e.options.container||e.options.type!=="object"&&e.options.type!=="array"&&e.options.type!=="any"))throw new O("Schema defines child properties but does not identify as a container",{location:t});if(e.isUnion&&e.hasWildcard)throw new O("Wildcard properties cannot be set on a union",{location:t});if(e.hasChildSelector!==e.hasChildSelection)throw new O("Inconsistently defined selector/selections in properties",{location:t});if(t.path===""){if(e.isSelector)throw new O("The root schema cannot be a selector",{location:t});if(e.isSelection)throw new O("The root schema cannot be a selection",{location:t});if(e.isUnionKey)throw new O("The root schema cannot be a union key",{location:t})}return e}M();function qt(e,r,t,n){let i=this;for(let o of Object.keys(e.handlers)){let s=e.handlers[o];H(s)||e._setValueProcessor(o,this.resolver.compileValueProcessorSpec(i,s.length===1?s[0]:{$pipeline:s},!0))}return e}l();M();function Ft(e,r,t){let n=e.options.values??[];if(H(e.options.values))return e;let i=new Set,o=0;for(;o<n.length;){let s=e._normalizeValue(n[o++],void 0,void 0,{sync:!0});if(s===void 0)throw new O("Undefined after normalizing",{value:s,location:t});i.add(s)}return i.size&&(e.options.values=[...i]),e}M();var ye=class extends C{constructor(r){super(C.__TOKEN),this.schema=r}},je=class extends C{constructor(r){super(C.__TOKEN),this.resolver=r,this.normalizeCache=new Map,this.compileSeen=new Map,this.compileCache=new Map;let t=this,n=new x("any").option("dynamic",!1).opaque().validator((p,b,R)=>{if(!(p instanceof N))throw new O("Failed to compile to a value processor",{location:R});return p}),i=new x(n).transformer(p=>r.compileKeywordValueProcessorSpec(this,p)),o=new x(n).property("$literal",new x("any")).transformer(p=>r.compileKeywordValueProcessorSpec(this,p)),s=new x(n).transformer(p=>r.compileValueProcessorSpec(this,p)),a=new x(n).normalizer(p=>p===null?"$null":p).unionDiscriminator(p=>{if(p instanceof N||p==null)return"general";if(!H(p))return Ve(p)?typeof p=="string"?"keyword":"keyword+args":"general"}).unionSchema("keyword",i).unionSchema("keyword+args",o).unionSchema("general",s),c=new x("any").option("dynamic",!1).unionDiscriminator(p=>{if(Array.isArray(p))return"array";if(Ve(p))return"spec";if(!H(p))return L(p)?"object":"spec"}).unionSchema("spec",a).unionSchema("array",new x("array").allowEmpty().transformer(p=>p).property("*",a)).unionSchema("object",new x("object").allowEmpty().transformer(p=>p).property("*",a));o.property("*",c);let d=new x("array").property("*",a),g=new x().meta("compiler","root").required().normalizer((p,b,R)=>this.compileSeen.has(p)&&this.compileSeen.get(p)!==R.path?new ye(p):(p instanceof C||this.compileSeen.set(p,R.path),p)).normalizer(Nr.bind(this)).unionDiscriminator((p,b,R,U)=>p instanceof ye||this.compileSeen.has(p)?"cache":p instanceof C?"reference":typeof p=="object"?"schema":void 0).unionSchema("reference",new x().meta("compiler","reference").required().normalizer(p=>{if(!(p instanceof C))throw new O("Not a CompiledSchema reference!");return p})).unionSchema("cache",new x().meta("compiler","cache").required().normalizer(p=>{if(p instanceof ye)return p;if(!(p instanceof x))throw new O("Can only cache references to schemas");return new ye(p)})),S=new x("object").meta("compiler","schema").opaque().required().normalizer(Nr.bind(this)).normalizer((p,b,R,U)=>{if(p instanceof C)return p;if(typeof p=="object"){if(p instanceof x)throw new O("Internal compiler error");return p}else throw new u("not a schema")}).transformer(Lt.bind(this)).finalizer({$if:[(p=>p.isUnion),{$pipeline:[Ut,kt,Nt,Vt].map(p=>p.bind(this))},"$input"]}).finalizer(qt.bind(this)).finalizer({$if:[(p=>!H(p.options.values)),Ft.bind(this),"$defined"]}).finalizer({$if:[(p=>p.hasChildSelector||p.hasChildSelection),zt,"$defined"]}).finalizer(Dt).finalizer((p,b,R)=>{if(R.path!=="")return p;if(!(p instanceof C))throw new O("Schema failed to compile!");return this._replaceCachedReferences(p),p._freeze(),p}).validator(Mt.bind(this)).property("properties",new x("object").property("*",g)).property("unionSchemas",new x("object").property("*",g)).property("metadata",new x("object").property("*",new x("string"))).property("options",new x("object").property("compileHook",new x("function")).property("default",new x("any").option("dynamic",!1)).property("values",new x("array")).property("*",new x("any"))).property("handlers",new x("object").property("normalizers",d).property("transformers",d).property("finalizers",d).property("validators",d).property("serializers",d).property("conditions",d).property("discriminators",d));g.unionSchema("schema",S);let A=new Map;function E(p,b){if(A.has(p))return A.get(p);if(p instanceof C)return p;b===void 0&&(b=new C(C.__TOKEN)),A.set(p,b),A.set(b,b),Object.assign(b.options,p.options),Object.assign(b.metadata,p.metadata);for(let[R,U]of Object.entries(p.handlers))b.handlers[R]=U.map(W=>r.compileValueProcessorSpec(t,W,!0)),b._setValueProcessor(R,r.compileValueProcessorSpec(t,{$pipeline:b.handlers[R]}));for(let[R,U]of Object.entries(p.properties))(U instanceof x||U instanceof C)&&b._setPropertySchema(R,E(U));for(let[R,U]of Object.entries(p.unionSchemas))(U instanceof x||U instanceof C)&&b._setUnionSchema(R,E(U));return b}E(r.resolve(g),this)}get hasChildren(){return!0}_replaceCachedReferences(r,t="",n=new Set){if(!n.has(r)){n.add(r);for(let[i,o]of r.propertyEntries){let s=t?`${t}.${i}`:i,a=o instanceof ye?this.compileCache.get(o.schema):o;if(a===void 0)throw new O("Unable to find cached CompiledSchema",{path:s});a!==o&&(a.metadata.references??="",a.metadata.references+=`[${s}]`,r._setPropertySchema(i,a)),this._replaceCachedReferences(a,s,n)}for(let[i,o]of r.unionSchemaEntries){let s=o instanceof ye?this.compileCache.get(o.schema):o;if(s===void 0)throw new O(`Unable to find cached CompiledSchema for unionSchema "${i}"`,{path:t});s!==o&&(s.metadata.references??="",s.metadata.references+=`[${t}:${i}]`,r._setUnionSchema(i,s)),this._replaceCachedReferences(s,t,n)}}}compile(r){try{let t=new ue(new j(this));t.compiling=!0;let n=this._process(r,void 0,{context:t});if(n instanceof Promise)throw new O("Encountered an async processor during compilation");return n}catch(t){throw t instanceof O?t:(t instanceof fe||t instanceof Z||t instanceof Q||t instanceof z)&&t.cause?new O(t.cause.message,{...t.data,...t.cause.data,cause:t.cause}):new O("Error during compilation",{cause:t})}}};Y();X();V();se();ze();Pe();V();Pe();ze();Ur();X();fr();l();M();te();var Ge=class extends ge{constructor(r,t){if(!r.keyword)throw new u("No keyword found in processor definition");if(!r.process)throw new u("No process function found in processor definition");if(r.build)throw new O("Internal compiler error: factory definitions unsupported by DefinedValueProcessor");if(r instanceof C)throw new O("Internal compiler error: a CompiledSchema was incorrectly identified as a DefinedValueProcessor");let n,i;if(r.parameters!==void 0)n=new De(r.parameters,t),i={[`$${r.keyword}`]:n.spec};else if(H(t))i=`$${r.keyword}`;else{let s=K(t,a=>a.spec);if(Array.isArray(t))n=new y(new ie(t),s);else if(typeof t=="object")n=new y(new ce(t),s);else throw new O("Internal compiler error: unsupported keyword arguments type");i={[`$${r.keyword}`]:n.spec}}let o=r.description??r.describe?.(t)??`${r.keyword}`;super(new k(r.process),n,i,o)}};l();he();M();Qe();var Ht=[];function Kt(e){Ht.push(e)}var Mr=class{#e=new Map;#r=new Map;#t=new Map;constructor(){for(let r of Ht)this.use(r,{sync:!0})}registerSchema(r,t){if(!(t instanceof x))throw new $("Registry can only store Schema instances");let n=Te(r);return this.#e.set(n,{name:n,schema:t}),this}getSchema(r){let t=Te(r),n=this.#e.get(t);if(!n)throw new $(`Unable to resolve "${r}"`);return n.schema}hasSchema(r){let t=Te(r);return this.#e.has(t)}listRegisteredSchemas(){return[...this.#e.values()]}registerValueProcessorDefinition(r){let{keyword:t,process:n,description:i,build:o}=r;if(!t||typeof t!="string")throw new $("Missing keyword in processor definition");if(n&&o)throw new $(`Processor definition for '$${t}' cannot define both process and build functions`);if(!n&&!o)throw new $(`Processor definition for '$${t}' must have define a process or build function`);if(i&&typeof i!="string")throw new $(`Processor definition description for '$${t}' must be a string`);if(this.#n[`${t}`])throw new $(`Processor keyword conflict with builtin literal '$${t}'`);return this.#r.set(t,r),this}registerValueProcessor(r,t,n){if(typeof t!="function")throw new $(`Processor for keyword '${r}' must be a function`);return this.registerValueProcessorDefinition({keyword:r,parameters:[],process:t,description:n??r})}registerValueProcessorBuilder(r,t){if(typeof t!="function")throw new $(`Processor builder for keyword '${r}' must be a function`);return this.registerValueProcessorDefinition({keyword:r,build:t})}listValueProcessorDefinitions(){return[...Object.entries(this.#n).map(([r,t])=>({keyword:r,build:(()=>t),spec:`$${r}`,reserved:!0})),...this.#r.values()]}async use(r,t={}){try{let n=r(this,t);if(n instanceof Promise&&t.sync)throw new $("Cannot load async library");return await n}catch(n){throw n instanceof $?n:new $("Error loading library",{cause:n})}}#n={null:new y(gr,"$null"),undefined:new y(Ue,"$undefined"),true:new y(vr,"$true"),false:new y(Gr,"$false")};compileKeywordValueProcessorSpec(r,t,n){if(!Ve(t))throw new $("Not a keyword processor spec");let[i,o]=_t(t);if(this.#n[i])return this.#n[i];if(i==="literal")return new y(new B(o),t);let s=this.#r.get(i);if(!s)throw new $(`Unknown processor keyword: $${i}`);let a=K(o,c=>this.compileValueProcessorSpec(r,c,n));if(s.build){let c=s.build(a,{compiler:r});if(c?.process)return this.compileValueProcessorSpec(r,c,n);if(!(c instanceof N))throw new u(`ValueProcessor builder for $${i} returned invalid`,{value:c});return c}return new Ge(s,a)}compileSchemaValueProcessorSpec(r,t){let n;return r.compileCache.has(t)?new y(new B(r.compileCache.get(t)),t):new y(new We(async()=>r.compileCache.has(t)?r.compileCache.get(t):(n??=t instanceof C?t:await r.compile(t),n)),t)}compileValueProcessorSpecObject(r,t,n=!1){if(typeof t!="object")throw new $("not a spec object");let i={};for(let[o,s]of Object.entries(t))i[o]=this.compileValueProcessorSpec(r,s,n);return new y(new ce(i),K(i,o=>o.spec))}compileValueProcessorSpecArray(r,t,n=!1){if(!Array.isArray(t))throw new $("not a spec array");let i=[];for(let o=0;o<t.length;++o)i[o]=this.compileValueProcessorSpec(r,t[o],n);return new y(new ie(i),K(i,o=>o.spec))}compileValueProcessorSpec(r,t,n=!1){if(!cr(t))throw new u("Invalid value processor specification",{value:t});let i;if(t===void 0)i=new N;else if(t===null)t="$null",i=new y(gr,"$null");else if(t==="$resolver")i=new y(new B(this),t);else if(t==="$compiler")i=new y(new B(r),t);else if(t instanceof N)i=t;else if(t instanceof x)i=this.compileSchemaValueProcessorSpec(r,t);else if(t instanceof C)i=new y(new B(t),t);else if(Ve(t))i=this.compileKeywordValueProcessorSpec(r,t,n);else if(t instanceof T)i=new y(t,t);else if(t instanceof RegExp)i=new y(new B(t),t,`${t}`);else if(t instanceof Date)i=new y(new B(t),t,t.toISOString());else if(typeof t=="string"&&t.startsWith("/")&&t.lastIndexOf("/")>0)try{let o=Oe(t);i=new y(new B(o),o,`${o}`)}catch{throw new u("Invalid regex pattern",{value:t})}else t instanceof je?i=new y(new B(t),t):typeof t=="object"&&typeof t.process=="function"?i=new Ge(t):yr(t)?i=new y(new B(t),t,t.name):typeof t=="function"?i=new k(t):Array.isArray(t)?i=this.compileValueProcessorSpecArray(r,t,n):typeof t=="object"?i=this.compileValueProcessorSpecObject(r,t,n):i=new y(q(t),t);return i.spec===void 0&&(i.spec=t),i}compiler(){return new je(this)}compile(r){return r instanceof C?r:new je(this).compile(r)}resolve(r,t=!0){if(r instanceof C)return r;if(typeof r=="string"&&(this.hasSchema(r)?r=this.getSchema(r):r=new x(r)),this.#t.has(r))return this.#t.get(r);let n=new x;this.#t.set(r,n),this.#t.set(n,n);let i=r,o,s=!1;for(;i!==void 0;){for(let[a,c]of Object.entries(i.properties??{}))if(!n.properties.hasOwnProperty(a)){let d=t||!(c instanceof x||c instanceof C);n.properties[a]=d?this.resolve(c):c}for(let[a,c]of Object.entries(i.metadata??{}))n.metadata.hasOwnProperty(a)||(n.metadata[a]=c);for(let[a,c]of Object.entries(i.unionSchemas??{}))if(!n.unionSchemas.hasOwnProperty(a)){let d=t||!(c instanceof x||c instanceof C);n.unionSchemas[a]=d?this.resolve(c):c}for(let[a,c]of Object.entries(i.handlers??{}))n.handlers.hasOwnProperty(a)||(n.handlers[a]=[]),n.handlers[a].unshift(...c);for(let[a,c]of Object.entries(i.options??{}))n.options.hasOwnProperty(a)||(n.options[a]=c,a==="type"&&(s=!0));if(i instanceof C)i=void 0;else if(i.base===void 0&&!s&&(i.base="any"),i.base)if(this.hasSchema(i.base))i=this.getSchema(i.base);else{let a=`${i.base}`;o=new $(`Unable to resolve "${a}"`),n.normalizer((c,d,g,S)=>{if((g.schema?.strict??S?.strict)!==!1)throw o}),i=void 0}else i=void 0}if(!(r instanceof C)&&r.base&&!n.metadata.parserTypeHint&&(n.metadata.parserTypeHint=r.base),n.options.strict!==!1&&o)throw o;return n}};G();te();var La=/^[\d*]/;function ur(e){let r=e instanceof C?e.propertyEntries:Object.entries(e.properties??{});for(let[n]of r)if(!La.test(n))return!0;let t=e instanceof C?e.unionSchemaEntries:Object.entries(e.unionSchemas??{});for(let[n,i]of t)if(ur(i))return!0;return!1}oe();function Bt(e,r,t){let n=t.schema;return e===F&&n.isContainer?!n.isArray&&ur(n)?{}:[]:e}var Wt=new x().option("type","any").normalizer(Bt).transformer(Bt);G();var Yt=new x().option("type","string").meta("valueName","string").normalizer("$string").validator("$is-string");G();var Zt=new x().option("type","number").meta("valueName","number").normalizer("$number").validator("$is-number");G();le();var Xt=new x().option("type","boolean").meta("valueName","boolean").normalizer(J).validator({$in:[!0,!1]});G();var vt=new x().option("type","object").option("container",!0).meta("valueName","object").normalizer("$object").validator("$is-object");G();var Gt=new x().option("type","array").option("container",!0).normalizer("$array").validator("$is-array");G();var Jt=new x().option("type","date").meta("parserTypeHint","string").meta("valueName","date").meta("valueDescription",'ms|iso date|"now"|[+|-]offset[d|h|m|s|ms]').normalizer("$date").transformer("$date").validator("$is-date").serializer("$is-date").serializer("$string");G();re();l();var Qt=new x().option("type","function").meta("parserTypeHint","string").meta("hidden").meta("internal").meta("omitFromSerialize").option("dynamic",!1).normalizer(e=>{if(typeof e=="function"||typeof e=="string")return e;throw new f("Invalid function",{value:e})}).transformer((e,r)=>{if(typeof e=="string"&&(e=ee(r,e)),typeof e=="function")return e;throw new f("Invalid function",{value:e})}).validator(e=>{if(typeof e=="function")return e;throw new f("Invalid function",{value:e})}).serializer(e=>{if(typeof e=="function")return e.name;throw new f("Invalid function",{value:e})});G();var en=new x().default(!0).meta("hidden").meta("internal").meta("omitFromSerialize").normalizer(()=>"root-schema").transformer((e,r,t)=>{for(;t?.parent;)t=t.parent;return t?.schema}).serializer((e,r,t)=>{for(;t?.parent;)t=t.parent;return t?.schema.toData()});var ca;try{ca??=await Promise.all([Promise.resolve().then(()=>(tn(),rn)),Promise.resolve().then(()=>(on(),nn)),Promise.resolve().then(()=>(an(),sn)),Promise.resolve().then(()=>(fn(),cn)),Promise.resolve().then(()=>(mn(),un)),Promise.resolve().then(()=>(dn(),pn)),Promise.resolve().then(()=>(hn(),ln)),Promise.resolve().then(()=>(yn(),wn)),Promise.resolve().then(()=>(An(),En)),Promise.resolve().then(()=>(xn(),Sn)),Promise.resolve().then(()=>(bn(),Cn)),Promise.resolve().then(()=>($n(),Rn)),Promise.resolve().then(()=>(On(),Tn)),Promise.resolve().then(()=>(_n(),In)),Promise.resolve().then(()=>(Nn(),kn)),Promise.resolve().then(()=>(Vn(),Un)),Promise.resolve().then(()=>(zn(),jn)),Promise.resolve().then(()=>(Ln(),Dn)),Promise.resolve().then(()=>(qn(),Mn)),Promise.resolve().then(()=>(Hn(),Fn)),Promise.resolve().then(()=>(Bn(),Kn)),Promise.resolve().then(()=>(Yn(),Wn)),Promise.resolve().then(()=>(Xn(),Zn)),Promise.resolve().then(()=>(Gn(),vn)),Promise.resolve().then(()=>(Qn(),Jn)),Promise.resolve().then(()=>(ri(),ei)),Promise.resolve().then(()=>(ni(),ti)),Promise.resolve().then(()=>(oi(),ii)),Promise.resolve().then(()=>(ai(),si)),Promise.resolve().then(()=>(fi(),ci)),Promise.resolve().then(()=>(mi(),ui)),Promise.resolve().then(()=>(di(),pi)),Promise.resolve().then(()=>(hi(),li)),Promise.resolve().then(()=>(yi(),wi)),Promise.resolve().then(()=>(Ei(),gi)),Promise.resolve().then(()=>(Si(),Ai)),Promise.resolve().then(()=>(Ci(),xi)),Promise.resolve().then(()=>(Ri(),bi)),Promise.resolve().then(()=>(Pi(),$i)),Promise.resolve().then(()=>(Oi(),Ti)),Promise.resolve().then(()=>(_i(),Ii)),Promise.resolve().then(()=>(Ni(),ki)),Promise.resolve().then(()=>(Vi(),Ui)),Promise.resolve().then(()=>(zi(),ji)),Promise.resolve().then(()=>(Li(),Di)),Promise.resolve().then(()=>(qi(),Mi)),Promise.resolve().then(()=>(Hi(),Fi)),Promise.resolve().then(()=>(Bi(),Ki)),Promise.resolve().then(()=>(Yi(),Wi)),Promise.resolve().then(()=>(Xi(),Zi)),Promise.resolve().then(()=>(Gi(),vi)),Promise.resolve().then(()=>(Qi(),Ji)),Promise.resolve().then(()=>(ro(),eo)),Promise.resolve().then(()=>(no(),to)),Promise.resolve().then(()=>(oo(),io)),Promise.resolve().then(()=>(ao(),so)),Promise.resolve().then(()=>(fo(),co)),Promise.resolve().then(()=>(mo(),uo)),Promise.resolve().then(()=>(lo(),po)),Promise.resolve().then(()=>(wo(),ho)),Promise.resolve().then(()=>(go(),yo)),Promise.resolve().then(()=>(Ao(),Eo)),Promise.resolve().then(()=>(xo(),So)),Promise.resolve().then(()=>(bo(),Co)),Promise.resolve().then(()=>($o(),Ro)),Promise.resolve().then(()=>(To(),Po)),Promise.resolve().then(()=>(Io(),Oo)),Promise.resolve().then(()=>(ko(),_o)),Promise.resolve().then(()=>(Uo(),No)),Promise.resolve().then(()=>(jo(),Vo)),Promise.resolve().then(()=>(Do(),zo)),Promise.resolve().then(()=>(Mo(),Lo)),Promise.resolve().then(()=>(Fo(),qo)),Promise.resolve().then(()=>(Bo(),Ko)),Promise.resolve().then(()=>(Yo(),Wo)),Promise.resolve().then(()=>(Xo(),Zo)),Promise.resolve().then(()=>(Qo(),Jo)),Promise.resolve().then(()=>(rs(),es)),Promise.resolve().then(()=>(ns(),ts)),Promise.resolve().then(()=>(os(),is)),Promise.resolve().then(()=>(as(),ss)),Promise.resolve().then(()=>(fs(),cs)),Promise.resolve().then(()=>(ms(),us)),Promise.resolve().then(()=>(ds(),ps)),Promise.resolve().then(()=>(hs(),ls)),Promise.resolve().then(()=>(ys(),ws)),Promise.resolve().then(()=>(Es(),gs)),Promise.resolve().then(()=>(Ss(),As)),Promise.resolve().then(()=>(Rs(),bs)),Promise.resolve().then(()=>(Ps(),$s)),Promise.resolve().then(()=>(Os(),Ts)),Promise.resolve().then(()=>(_s(),Is)),Promise.resolve().then(()=>(Ns(),ks)),Promise.resolve().then(()=>(Vs(),Us)),Promise.resolve().then(()=>(zs(),js)),Promise.resolve().then(()=>(Ls(),Ds)),Promise.resolve().then(()=>(qs(),Ms)),Promise.resolve().then(()=>(Hs(),Fs)),Promise.resolve().then(()=>(Bs(),Ks)),Promise.resolve().then(()=>(Ys(),Ws)),Promise.resolve().then(()=>(Xs(),Zs)),Promise.resolve().then(()=>(Gs(),vs)),Promise.resolve().then(()=>(Qs(),Js)),Promise.resolve().then(()=>(ra(),ea)),Promise.resolve().then(()=>(na(),ta)),Promise.resolve().then(()=>(oa(),ia)),Promise.resolve().then(()=>(aa(),sa))])}catch(e){throw new Error("Failed to load built-in processors",{cause:e})}var bu=ca.flatMap(e=>Object.values(e).filter(r=>r&&typeof r.keyword=="string"));function fa(){return bu}function Yr(e,r){e.registerSchema("root-schema",en),e.registerSchema("any",Wt),e.registerSchema("string",Yt),e.registerSchema("number",Zt),e.registerSchema("boolean",Xt),e.registerSchema("object",vt),e.registerSchema("array",Gt),e.registerSchema("date",Jt),e.registerSchema("function",Qt);for(let t of fa())e.registerValueProcessorDefinition(t)}te();G();qe();oe();l();he();Ar();re();_();M();mr();nr();Qe();xe();or();le();Wr();l();Kt(Yr);export{C as CompiledSchema,f as ConstraintError,F as EMPTY,Q as FinalizeError,fe as NormalizeError,$ as ResolverError,x as Schema,O as SchemaCompilationError,u as SchemaError,j as SchemaLocation,D as SchemaPolicy,Mr as SchemaResolver,be as SerializeError,Z as TransformError,de as UnionResolutionError,z as ValidationError,Aa as assertErrorMessageInCauseChain,Me as behead,Er as debug,Sa as deepAssign,v as deepEquals,Ke as deepMerge,Be as deepPrune,ee as deepValue,ir as formatArgumentType,Br as formatDataSize,w as formatValue,ur as hasStringProperties,ya as isConstructible,wa as isConstructor,H as isEmpty,Ir as isFalsey,Or as isFalseyKeyword,yr as isNativeClass,Ce as isObject,L as isPlainObject,He as isPrimitive,J as isTruthy,Tr as isTruthyKeyword,K as map,Fe as parse,Kr as parseDataSize,Ie as parseDate,Oe as parseRegExp,ma as propertyName,we as stringify,Vr as toCamelCase,Dr as toCapitalize,zr as toConstantCase,Ne as toData,Te as toKebabCase,jr as toPascalCase,Lr as toTitleCase};
2
+ var vr=Object.defineProperty;var s=(e,r)=>vr(e,"name",{value:r,configurable:!0});var p=(e,r)=>()=>(e&&(r=e(e=0)),r);var w=(e,r)=>{for(var t in r)vr(e,t,{get:r[t],enumerable:!0})};function qe(e){if(e==="")return["",void 0];let r=e.indexOf(".");return r===-1?[e,""]:[e.slice(0,r),e.slice(r+1)]}function pa(e){let r=e.lastIndexOf(".");return r===-1?e:e.slice(r+1)}var ir=p(()=>{"use strict";s(qe,"behead");s(pa,"propertyName")});var z,Fe=p(()=>{"use strict";ir();z=class e{static{s(this,"SchemaLocation")}#e=new Map;#r;#t;#n;constructor(r,t,n){this.#t=r,t!==void 0&&n!==void 0?(this.#r=t,this.#n=t.path?`${t.path}.${n}`:`${n}`):this.#n=""}get path(){return this.#n}toString(){return this.#n}get name(){let r=this.#n.lastIndexOf(".");return r===-1?this.#n:this.#n.slice(r+1)}get schema(){return this.#t}set schema(r){if(!(r===void 0||r===this.#t)){for(let[t,n]of this.#e){let i=r.getPropertySchema(t);i!==void 0?n.schema=i:this.#e.delete(t)}this.#t=r}}get parent(){return this.#r}get root(){return this.parent===void 0?this:this.parent.root}relative(r){if(!r||r===""||r===".")return this;if(r.charAt(0)==="^")return this.parent?.relative(r.slice(1));if(r.charAt(0)==="/")return this.root.relative(r.slice(1));if(r.charAt(0)===".")return this.relative(r.slice(1));let[t,n]=qe(r),i=this.#e.get(t);if(i===void 0){let o=this.schema.getPropertySchema(t);if(o===void 0)return;let a=this.path?`${this.path}.${t}`:`${t}`;i=new e(o),i.#n=a,i.#r=this,this.#e.set(t,i)}return n===void 0?i:i.relative(n)}absolute(r){return this.root.relative(r)}sibling(r){return r?this.parent?.relative(r):this}union(r){if(r===this.#t)return this;if(!this.schema||!this.schema.isUnion||!this.schema.findUnionKey(r))return;let n=new e(r);return n.#n=this.#n,n.#r=this.#r,n}findPropertyLocation(r){if(this.#t!==void 0)for(let[t]of this.#t.propertyEntries){if(t==="*")continue;let n=this.relative(t);if(n!==void 0?r(n):void 0)return n}}}});function ye(e,r={}){let{space:t=0,maxDepth:n=100,useDelimiters:i=!0,delimiterOpen:o="\xAB",delimiterClose:a="\xBB"}=r,c=new WeakMap,f=new WeakMap,l=s((A,d=null)=>i?d!==null?`${o}${A}: ${d}${a}`:`${o}${A}${a}`:null,"makeMarker"),E=s(A=>{let d=A.description;return d!==void 0?d:(f.has(A)||f.set(A,da()),f.get(A))},"getSymbolId"),x=s((A,d="$",R=0)=>{if(R>n)return l("MaxDepth");if(A===null)return null;if(A===void 0)return l("undefined");if(typeof A=="number")return Number.isNaN(A)?l("NaN"):A===1/0?l("Infinity"):A===-1/0?l("-Infinity"):A;if(typeof A=="boolean"||typeof A=="string")return A;if(typeof A=="symbol")return l("Symbol",E(A));if(typeof A=="function")return A.name?l("Function",A.name):l("undefined");if(typeof A=="bigint")return l("BigInt",A.toString());if(A instanceof Date){let $=l("Date",A.toISOString());return $!==null?$:A.toISOString()}if(Array.isArray(A)){if(c.has(A))return l("Circular",c.get(A));c.set(A,d);let $=A.map((V,Y)=>x(V,`${d}[${Y}]`,R+1)).filter(V=>V!==null||A.includes(null));return c.delete(A),$}if(typeof A=="object"){if(c.has(A))return l("Circular",c.get(A));c.set(A,d);let $=Object.keys(A).sort(),V={};for(let Y of $){let xe=/^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(Y)?`${d}.${Y}`:`${d}[${JSON.stringify(Y)}]`,Xr=x(A[Y],xe,R+1);(Xr!==null||A[Y]===null)&&(V[Y]=Xr)}return c.delete(A),V}return null},"stringifyValue"),S=x(e);return JSON.stringify(S,null,t)}function He(e,r={}){let{delimiterOpen:t="\xAB",delimiterClose:n="\xBB"}=r,i=JSON.parse(e),o=new Map,a=[],c=s(S=>S.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),"escapeRegex"),f=new RegExp(`^${c(t)}([^:${c(n)}]+)(?::\\s*(.+?))?${c(n)}$`),l=s(S=>{if(typeof S!="string")return null;let A=S.match(f);return A?{type:A[1],value:A[2]}:null},"parseMarker"),E=s((S,A="$")=>{let d=l(S);if(d)switch(d.type){case"undefined":return;case"NaN":return NaN;case"Infinity":return 1/0;case"-Infinity":return-1/0;case"BigInt":return BigInt(d.value);case"Date":return new Date(d.value);case"Symbol":return Symbol.for(d.value);case"Function":return null;case"MaxDepth":return null;case"Circular":return a.push({targetPath:A,sourcePath:d.value}),null}if(S===null||typeof S!="object")return S;if(Array.isArray(S)){let $=[];return o.set(A,$),S.forEach((V,Y)=>{let xe=`${A}[${Y}]`;$[Y]=E(V,xe)}),$}let R={};o.set(A,R);for(let[$,V]of Object.entries(S)){let Y=/^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test($)?`${A}.${$}`:`${A}[${JSON.stringify($)}]`;R[$]=E(V,Y)}return R},"revive"),x=E(i);for(let{targetPath:S,sourcePath:A}of a){let d=la(x,S),R=o.get(A);d&&R&&ha(d.obj,d.key,R)}return x}function la(e,r){if(r==="$")return null;let t=wa(r),n=e;for(let i=0;i<t.length-1;i++)if(n=n[t[i]],n==null)return null;return{obj:n,key:t[t.length-1]}}function ha(e,r,t){e[r]=t}function wa(e){let r=[],t="",n=!1;for(let i=0;i<e.length;i++){let o=e[i];if(!(o==="$"&&i===0))if(o==="."&&!n)t&&r.push(t),t="";else if(o==="[")t&&r.push(t),t="",n=!0;else if(o==="]"){if(n){let a=t.trim();a.startsWith('"')&&a.endsWith('"')?r.push(JSON.parse(a)):r.push(Number(a)),t="",n=!1}}else t+=o}return t&&r.push(t),r}var da,Ce=p(()=>{"use strict";da=s(()=>crypto.randomUUID(),"randomUUID");s(ye,"stringify");s(He,"parse");s(la,"resolvePath");s(ha,"setPath");s(wa,"parsePath")});function M(e){if(e==null||typeof e!="object")return!1;let r=Object.getPrototypeOf(e);return r===Object.prototype||r===null}function be(e){return e&&typeof e=="object"&&!Array.isArray(e)}function K(e){return e==null||Array.isArray(e)&&e.length===0||M(e)&&Object.keys(e).length===0}function Ke(e){if(e==null)return!1;let r=typeof e;return r!=="object"&&r!=="function"}function ya(e){if(typeof e!="function")return!1;if(e.prototype?.constructor===e)return!0;try{class r extends e{static{s(this,"test")}}}catch{return!1}return!0}function ga(e){if(typeof e!="function")return!1;try{return Reflect.construct(Function,[],e),!0}catch{return!1}}function gr(e){if(typeof e!="function")return!1;let r=Function.prototype.toString.call(e);return/^class\s/.test(r)||/\[native code\]/.test(r)&&e.prototype?.constructor===e}function B(e,r){return Array.isArray(e)?e.map(r):M(e)?Object.fromEntries(Object.entries(e).map(([t,n])=>[t,r(n)])):[r(e)]}var q=p(()=>{"use strict";s(M,"isPlainObject");s(be,"isObject");s(K,"isEmpty");s(Ke,"isPrimitive");s(ya,"isConstructor");s(ga,"isConstructible");s(gr,"isNativeClass");s(B,"map")});function or(e){if(e.metadata.valueDescription)return e.metadata.valueDescription;let r;return e.isArray&&e.hasChildren?(r=Array.from(e.propertyEntries).sort((n,i)=>n[0]==="*"?1:i[0]==="*"?-1:n[0].localeCompare(i[0],void 0,{numeric:!0})).map(n=>n[1]).map(n=>{let i=or(n);return!n.required&&i.length>2&&i.charAt(0)==="["&&i.charAt(i.length-1)==="]"&&(i=i.slice(1,i.length-1)),i}).join(", "),e.hasWildcard&&(r+="..."),e.metadata.validatorDescription&&r&&!r.includes(e.metadata.validatorDescription)&&(r+=` {${e.metadata.validatorDescription}}`)):(Array.isArray(e.options.values)&&e.options.values.length>0?r=e.options.values.map(t=>`${typeof t=="string"?`"${t}"`:ye(t)}`).sort((t,n)=>t.localeCompare(n,void 0,{numeric:!0})).join("|"):(r=e.metadata.valueName??(e.isArray?"":e.options.type),e.metadata.validatorDescription&&(!r||r===e.options.type?r=e.metadata.validatorDescription:r=`${r} {${e.metadata.validatorDescription}}`)),r===void 0&&(r="value"),e.isArray&&!r.includes("...")&&(r+="...")),r}function y(e,r={}){let{delimiterOpen:t="\xAB",delimiterClose:n="\xBB",maxLength:i=40}=r;try{if(e===null)return`${t}null${n}`;if(e===void 0)return`${t}undefined${n}`;let o;if(typeof e=="function"&&e.name?o=`${t}${e.name}()${n}`:typeof e=="object"&&!M(e)&&e.constructor?.name?o=`${t}${e.constructor.name}${n}`:o=ye(e,{delimiterOpen:t,delimiterClose:n}),typeof e!="string"&&(o.startsWith('"')&&o.endsWith('"')||o.startsWith("'")&&o.endsWith("'"))&&(o=o.slice(1,-1)),Ea.test(o)||(o=`${t}${o}${n}`),o.length>40){let a=o.charAt(o.length-1);o=o.slice(0,40)+`...${a}`}return o}catch{return"\uFFFD"}}var Ea,k=p(()=>{"use strict";Ce();q();s(or,"formatArgumentType");Ea=/^[^A-Za-z0-9_].+[^A-Za-z0-9_]$/;s(y,"formatValue")});function Gr(e,r,t,n="at"){r===""?r="(root)":r&&(r=`"${r}"`),t&&(r=r?`${r} property "${t}"`:`property "${t}"`);let i=e;return r&&(i+=` ${n} ${r}`),i}function Aa(e,r,t,n,i){let o=y(r);return o?.length&&(e=`${e} with value ${o}`),Gr(e,t,n,i)}function Sa(e,r,t,n){n===void 0&&(n=new Error("message not found in cause chain"));let i=e?.message??"";if(t=t?`${t} \xAB${i}\xBB`:`\xAB${i}\xBB`,r instanceof RegExp&&r.test(i))return!0;if(i.toLowerCase()===`${r}`.toLowerCase())return!0;if(e.cause instanceof Error)return Sa(e.cause,r,t,n);throw n.message=`\xAB${r}\xBB not found in cause chain ${t}`,n}var m,u,D,ue,X,ee,Re,le,P,I,h=p(()=>{"use strict";k();s(Gr,"fpm");s(Aa,"fpvm");m=class e extends Error{static{s(this,"SchemaError")}constructor(r,t,n=!1){let i=t?.cause?t.cause instanceof Error?t.cause:new e(t.cause,void 0,!1):void 0,o=t?.path??t?.location?.path??t?.cause?.path??t?.cause?.location?.path,a=t?.property;!r?.length&&i?.message&&(r=i.message),(!o||r.indexOf(o)===-1)&&(t?.hasOwnProperty("value")?r=Aa(r,t?.value,o,a):r=Gr(r,o,a)),super(r,i?{cause:i}:void 0),t&&(this.data={...t,cause:i});let c=new.target.prototype;Object.setPrototypeOf?Object.setPrototypeOf(this,c):this.__proto__=c,n||delete this.stack,t?.cause&&!super.cause&&(this.cause=t.cause)}get name(){return this.constructor.name}get stack(){return""}set stack(r){}toString(){return this.message?`${this.name}: ${this.message}`:this.cause?.message?`${this.name}: ${this.cause.message}`:this.name}};s(Sa,"assertErrorMessageInCauseChain");u=class extends m{static{s(this,"ConstraintError")}},D=class extends m{static{s(this,"ValidationError")}},ue=class extends m{static{s(this,"NormalizeError")}},X=class extends m{static{s(this,"TransformError")}},ee=class extends m{static{s(this,"FinalizeError")}},Re=class extends m{static{s(this,"SerializeError")}},le=class extends m{static{s(this,"UnionResolutionError")}},P=class extends m{static{s(this,"ResolverError")}},I=class extends m{static{s(this,"SchemaCompilationError")}}});function Be(e,...r){if(!r.length)return e;let t=r.shift();if(be(e)&&be(t))for(let n in t)M(t[n])?(e[n]||Object.assign(e,{[n]:{}}),Be(e[n],t[n])):Object.assign(e,{[n]:t[n]});return Be(e,...r)}function G(e,r){if(e===r)return!0;if(e==null||r==null||typeof e!=typeof r)return!1;if(Array.isArray(e)&&Array.isArray(r)){if(e.length!==r.length)return!1;for(let t=0;t<e.length;++t)if(!G(e[t],r[t]))return!1;return!0}if(typeof e=="object"&&typeof r=="object"){if(Array.isArray(e)||Array.isArray(r))return!1;let t=Object.keys(e);if(t.length!==Object.keys(r).length)return!1;for(let n of t)if(!r.hasOwnProperty(n)||!G(e[n],r[n]))return!1;return!0}return!1}function xa(e,r,t){if(r===""&&e)throw new Error("Top level path but target is already set");if(r==="")return Array.isArray(t)?[...t]:M(t)?{...t}:t;if(!r||typeof r!="string")throw new Error("Path must be a non-empty string");let n=r.split(".").filter(c=>c!=="");if(n.length===0)throw new Error("Path must contain at least one valid segment");if(e!=null&&typeof e!="object")throw new Error("Target must be an object, an array, or null/undefined");if(e==null){let c=n[0];e=/^\d+$/.test(c)?[]:{}}let i=e;for(let c=0;c<n.length-1;c++){let f=n[c],l=n[c+1],E=/^\d+$/.test(f),x=/^\d+$/.test(l);if(E){let S=parseInt(f,10);if(!Array.isArray(i))throw new Error(`Expected array at path segment '${n.slice(0,c).join(".")}', but found ${typeof i}`);for(;i.length<=S;)i.push(void 0);(i[S]===void 0||i[S]===null)&&(i[S]=x?[]:{}),i=i[S]}else(i[f]===void 0||i[f]===null)&&(i[f]=x?[]:{}),i=i[f]}let o=n[n.length-1];if(/^\d+$/.test(o)){let c=parseInt(o,10);if(!Array.isArray(i))throw new Error(`Expected array at path segment '${n.slice(0,-1).join(".")}', but found ${typeof i}`);for(;i.length<=c;)i.push(void 0);i[c]=t}else i[o]=t;return e}function re(e,r){if(r==="")return e;if(!e||typeof e!="object"||typeof r!="string")return;let t=r.split(".").filter(i=>i.length>0);if(t.length===0)return;let n=e;for(let i of t){if(!n||typeof n!="object")return;/^\d+$/.test(i)?n=n[Number(i)]:n=n[i]}return n}function We(e){if(e!=null)if(M(e)){for(let r of Object.keys(e))We(e[r])===void 0&&delete e[r];return Object.keys(e).length?e:void 0}else if(Array.isArray(e)){for(let r=e.length-1;r>=0;r--){let t=We(e[r]);t===void 0?r===e.length-1?e.pop():delete e[r]:t!==e[r]&&(e[r]=t)}return e.length?e:void 0}else return e}var te=p(()=>{"use strict";q();s(Be,"deepMerge");s(G,"deepEquals");s(xa,"deepAssign");s(re,"deepValue");s(We,"deepPrune")});var C,L,J=p(()=>{"use strict";sr();ne();h();te();C=class e{static{s(this,"Schema")}#e;#r={};#t={};#n={};#i={};#s={};constructor(r,t,n){typeof r=="string"?(this.base=r,t&&this._setAttributes(t),n&&this.addMetadata(n)):r instanceof e||r instanceof b?(this.extend(r),r instanceof e&&(this.base=r.base),t&&this._setAttributes(t),n&&this.addMetadata(n)):typeof r=="object"&&r!==null&&this.extend(r)}get base(){return this.#e}set base(r){this.#e=r}get properties(){return this.#r}get handlers(){return this.#t}get options(){return this.#n}get metadata(){return this.#i}get unionSchemas(){return this.#s}toData(){return Ue(this)}_setAttribute(r,t){if(r==="base")return this.base=t,this;if(r==="metadata")return this.addMetadata(t);if(r==="options")return this.addOptions(t??{});if(r==="handlers")return this.addHandlers(t??{});if(r==="properties")return this.addProperties(t??{});if(r==="unionSchemas")return this.addUnionSchemas(t??{});if(Object.getPrototypeOf(this)?.hasOwnProperty(r)){if(typeof this[r]!="function")throw new m("Unknown attribute!");try{return this[r].call(this,t)}catch{}}return r.startsWith("_")?this.meta(r.slice(1),t):this.option(r,t)}_setAttributes(r={}){if(typeof r!="object")throw new m("Expected an object containing options and metadata attributes");for(let[t,n]of Object.entries(r))this._setAttribute(t,n);return this}property(r,t){if(typeof r!="string")throw new m("Properties must be associated with a valid name");if(t==="string"&&(t=new e(t)),!(t instanceof e)&&!(t instanceof b)){if(t===void 0)return delete this.properties[r],this;throw new m("Property value must be a schema")}return this.properties[r]=t,this.base===void 0&&this.options.type,this.options.container??=!0,this}addProperties(r,t=L.INITIALIZE){if(typeof r!="object")throw new m("Invalid properties definition");for(let[n,i]of Object.entries(r))(t===L.OVERWRITE||this.properties[n]===void 0)&&this.property(n,e.createFromModel(i));return this}option(r,t){if(typeof r!="string")throw new m("Options must be associated with a valid key");if(r.startsWith("_"))throw new m("Option keys cannot have a leading underscore");return t===void 0&&(t=!0),t===null?delete this.options[r]:this.options[r]=t,this}addOptions(r,t=L.INITIALIZE){if(t!==L.INITIALIZE&&t!==L.OVERWRITE)throw new m("Unsupported policy");if(typeof r!="object")throw new m("Options definition must be an object");for(let[n,i]of Object.entries(r))(t===L.OVERWRITE||this.options[n]===void 0)&&this.option(n,i);return this}handler(r,t=[],n=L.APPEND){if(typeof r!="string")throw new m("Handlers must be associated with a valid key");if(!Object.values(L).includes(n))throw new m("Unknown policy");return t===void 0?(n===L.OVERWRITE&&delete this.handlers[r],this):(Array.isArray(t)||(t=[t]),t=t.map(i=>i===void 0?"$undefined":i===null?"$null":i),n===L.INITIALIZE&&Array.isArray(this.handlers[r])?this:n===L.OVERWRITE||n===L.INITIALIZE?(this.handlers[r]=t,this):(Array.isArray(this.handlers[r])||(this.handlers[r]=[]),n===L.PREPEND?this.handlers[r].unshift(...t):this.handlers[r].push(...t),this))}addHandlers(r,t=L.INITIALIZE){if(typeof r!="object")throw new m("Handlers definition must be an object");for(let[n,i]of Object.entries(r))this.handler(n,i,t);return this}meta(r,t){if(typeof r!="string")throw new m("Metadata must be associated with a valid key");return t===void 0&&(t=!0),t===null?delete this.metadata[r]:(r.startsWith("_")&&(r=r.slice(1)),this.metadata[r]=t),this}addMetadata(r,t=L.INITIALIZE){if(typeof r!="object")throw new m("Invalid metadata definition");for(let[n,i]of Object.entries(r))(t===L.OVERWRITE||this.metadata[n]===void 0)&&this.meta(n,i);return this}unionDiscriminator(r){return this.unionDiscriminators(r)}unionDiscriminators(r,t){return this.handler("discriminators",r,t)}unionSchema(r,t){if(!(t instanceof e||t instanceof b))throw new m(`Invalid schema for union member ${r}`);return this.unionSchemas[r]=t,this}addUnionSchemas(r,t=L.INITIALIZE){if(t!==L.INITIALIZE&&t!==L.OVERWRITE)throw new m("Unsupported policy");if(typeof r!="object")throw new m("Invalid union schemas object");for(let[n,i]of Object.entries(r))(t===L.OVERWRITE||this.unionSchemas[n]===void 0)&&this.unionSchema(n,e.createFromModel(i));return this}unionKey(r){return this.options.unionKey=!!(r??!0),this}selector(r){return this.options.selector=!!(r??!0),this}selection(r){return this.options.selection=r??!0,this.condition(async(t,n,i)=>{if(!i.schema.isSelection)throw new m("Conditional expected a selection schema!",{location:i});let o=this.options.selection===!0?i.name:this.options.selection,a=i.parent?.findPropertyLocation(c=>c.schema.isSelector);if(a){let c=a.schema,f=re(n,a.path);return await c.normalizeValue(f,n,a)===await c.normalizeValue(o,n,a)}return!1}),this}required(r){return this.options.required=r??!0,this}optional(r){return this.options.required=!r,this}default(r){return this.options.default=r,this}deep(r){return this.options.deep=r??!0,this}allowEmpty(r){return this.options.allowEmpty=r??!0,this}allowIncremental(r){return this.options.allowIncremental=r??!0,this}opaque(r=!0){return this.options.allowIncremental=!r,this}strict(r){return this.options.strict=r??!0,this}lax(r){return this.options.strict=r===void 0?!1:!r,this}implicit(r){return this.options.implicit=r??!0,this}value(r){return this.values([r])}values(r=[],t=L.APPEND){return t===L.INITIALIZE&&Array.isArray(this.options.values)?this:((t===L.OVERWRITE||!Array.isArray(this.options.values))&&(this.options.values=[]),Array.isArray(r)||(r=[r]),t===L.PREPEND?this.options.values.unshift(...r):this.options.values.push(...r),this)}condition(r){return this.conditions(r)}conditions(r,t){return this.handler("conditions",r,t)}normalizer(r){return this.normalizers(r)}normalizers(r,t){return this.handler("normalizers",r,t)}transformer(r){return this.transformers(r)}transformers(r,t){return this.handler("transformers",r,t)}finalizer(r){return this.finalizers(r)}finalizers(r,t){return this.handler("finalizers",r,t)}validator(r){return this.validators(r)}validators(r,t){return this.handler("validators",r,t)}serializer(r){return this.serializers(r)}serializers(r,t){return this.handler("serializers",r,t)}extend(r,t=new Map){if(typeof r!="object")throw new m("Invalid schema to extend");return!this.base&&r.base&&(this.base=r.base),this.addProperties(Object.fromEntries(Object.entries(r.properties??{}).map(([n,i])=>[n,e.createFromModel(i,t)]))),this.addUnionSchemas(Object.fromEntries(Object.entries(r.unionSchemas??{}).map(([n,i])=>[n,e.createFromModel(i,t)]))),this.addOptions(r.options??{}),this.addMetadata(r.metadata??{}),this.addHandlers(r.handlers??{}),this}clone(){return e.createFromModel(this)}static createFromModel(r,t=new Map){if(typeof r=="string")return new e(r);if(t.has(r))return t.get(r);let n=new e;return t.set(r,n),r.base&&(n.base=r.base),n.extend(r,t)}static create(r,t,n){return new e(r,t,n)}static literal(r,t,n){let i="any";typeof r=="string"?i="string":typeof r=="number"?i="number":typeof r=="boolean"&&(i="boolean");let o=new e(i).option("values",[r]).option("default",r).option("compileHook",(a,c)=>{if(a==="finalize"){if(c.options.values?.length!==1)throw new m("Literal schema needs one value defined");if(c.hasChildren)throw new m("Literal schema should not have child properties");if(c.isUnion)throw new m("Literal schema should not be a union")}}).transformer(()=>r);return t&&o._setAttributes(t),n&&o.addMetadata(n),o}static inherit(r){return new e().option("reference",!0).transformer((t,n,i,o)=>{let a=r??i.name;if(i.parent===void 0){if(i.schema.strict!==!1)throw new m("A top-level schema cannot have an inherited value");return}let c=i.parent?.parent;for(;c!==void 0;){let f=c.relative(a);if(f!==void 0)return re(n,f.path);c=c.parent}if(i.schema.strict!==!1)throw new m(`Inherited property "${a}" not found in any ancestor of "${i}"`)}).serializer(()=>{}).default((t,n,i)=>r??i.name).meta("omitFromSerialize").meta("internal")}static reference(r,t=!1){let n=r?.charAt(0);return(n==="^"||n==="/"||n===".")&&(t=!0),new e().option("reference",!0).default(r).normalizer(()=>r).transformer((i,o,a,c)=>{let f=t?a.relative(r):a.absolute(r);if(f===void 0)throw new m(`Reference path ${r} not found`);if(f.schema===void 0){if(c?.context?.final)throw new m(`Schema for reference path ${r} not found`);return}return re(o,f.path)}).validator((i,o,a,c)=>{let f=t?a.relative(r):a.absolute(r);if(f===void 0)throw new m(`Reference path ${r} not found`);let l=f.schema;if(l===void 0){if(c?.context?.final)throw new m(`Schema for reference path ${r} not found`);return}if(re(o,f.path)===i)return i;if(!l?.hasChildren||l.isOpaque)throw new m(`Reference is not exactly the same as ${r}`);return i}).serializer(()=>{}).meta("omitFromSerialize").meta("internal")}},L=Object.freeze({INITIALIZE:Symbol("INITIALIZE"),OVERWRITE:Symbol("OVERWRITE"),APPEND:Symbol("APPEND"),PREPEND:Symbol("PREPEND")})});function Ue(e,r=new WeakMap){if(typeof e!="object")throw new m("Not a schema!");if(r.has(e))return r.get(e);let t={};r.set(e,t),!(e instanceof b)&&e.base&&(t.base=e.base);for(let n of["properties","unionSchemas","metadata","options","handlers"])if(e[n])for(let[i,o]of Object.entries(e[n])){t[n]===void 0&&(t[n]={});let a=o instanceof C||o instanceof b,c=o;a?c=Ue(o,r):n==="handlers"&&Array.isArray(o)&&(c=o.map(f=>f===null?"$null":f===void 0?"$undefined":typeof f=="object"&&f.spec!==void 0?f.spec:f)),t[n][i]=c}return t}var sr=p(()=>{"use strict";ne();J();h();s(Ue,"toData")});function F(e){return e instanceof O?e:typeof e=="function"?new Ye(e):new W(e)}var O,Ye,W,Er,Ve,Jr,Qr,Z=p(()=>{"use strict";O=class{static{s(this,"Executor")}execute(r,...t){return r}get isConstant(){return!1}},Ye=class extends O{static{s(this,"FunctionExecutor")}#e;constructor(r){super(),this.#e=r}execute(r,...t){return this.#e(r,...t)}},W=class extends O{static{s(this,"ConstantExecutor")}#e;constructor(r){super(),this.#e=r}execute(){return this.#e}get isConstant(){return!0}},Er=new W(null),Ve=new W(void 0),Jr=new W(!0),Qr=new W(!1);s(F,"toExecutor")});var H,se=p(()=>{"use strict";H=Symbol("EMPTY")});var ar,et=p(()=>{"use strict";h();se();te();q();ar=class{static{s(this,"TraversalState")}#e;#r;#t;#n;#i;#s;#o=new Map;#u;#a=void 0;#h=new Set;#w=void 0;#m=void 0;#c;#d=!1;#y=!1;#f=void 0;#g=!1;#p=void 0;#l;executorCache={};constructor(r,t){if(this.#e=r,this.#r=t,this.#i=r.root.absolute(t),this.#r==="")this.#t="";else{let n=this.#r.lastIndexOf("."),i=n===-1?"":this.#r.slice(0,n);this.#s=this.#e.getState(i),this.#t=n===-1?this.#r:this.#r.slice(n+1),this.#s.#o.set(this.#t,this)}this.#n=/^\d+$/.test(this.#t)?Number(this.#t):this.#t,this.#i?.schema!==void 0&&!this.#i.schema.hasConditions&&(this.#c=!0),this.completed=!1}get context(){return this.#e}get parent(){return this.#s}get path(){return this.#r}get name(){return this.#t}get key(){return this.#n}get location(){return this.#i===void 0&&(this.#i=this.context.root.absolute(this.path)),this.#i}set location(r){this.#i=r}get schema(){return this.location?.schema}set schema(r){if(this.location===void 0||r===void 0)throw new m("Inconsistent traversal state",{location:this.location});let t=this.schema;if(t&&t!==r){if(t.isUnion){if(this.unionKey=t.findUnionKey(r),!this.unionKey)throw new m("Union resolved to an unknown schema");this.executorCache={},this.location.schema=r,this.invalidate(),this.invalidateChildren()}this.context.update()}this.location.schema=r,r.hasConditions||(this.#c=!0)}get condition(){return this.#c}set condition(r){if(this.#c!==r){if(r===!1&&this.#c===!0)return;this.context.update()}this.#c=r}get unionKey(){return this.#p?this.#p[0]:void 0}set unionKey(r){r===void 0?this.#p=void 0:(this.#p??=[],this.#p.unshift(r))}getChildState(r){return r===""?this:this.#o.get(r)??this.context.getState(this.path?`${this.path}.${r}`:`${r}`)}getRelativeState(r){let t=this.location?.relative(r);return t?this.context.getState(t):void 0}get assignedInput(){return this.#u}set assignedInput(r){if(r===null){this.value=null;return}G(r,this.#u)||(this.context.update(),this.processed=!1,this.completed=!1,this.#u=r)}get input(){return this.#a}set input(r){if(r===null){this.value=null;return}if(!G(r,this.#a)&&(this.context.update(),this.processed=!1,this.completed=!1,this.#a=r,this.schema!==void 0)){if(!this.schema?.hasChildren&&r!==void 0&&(this.mandatory=!0),this.schema.hasChildren){if(M(r)||typeof r=="object"&&this.isIncremental){for(let[t,n]of Object.entries(r))if(n!=null){let i=this.getChildState(t);i.assignedInput=n}}else if(Array.isArray(r))for(let t=0;t<r.length;++t){let n=r[t];if(n!=null){let i=this.getChildState(`${t}`);i.assignedInput=n}}}this.schema?.hasChildren&&!this.schema.isUnion&&r!==H&&(!K(r)||this.schema.options.allowEmpty)&&(this.mandatory=!0)}}get pending(){return this.#w}set pending(r){r===null&&(this.value=null,this.#w=void 0),this.#w=r}get value(){return this.#m}set value(r){if(this.#m!==void 0&&r===void 0)throw new m("Cannot unset value",{location:this.location});if(this.#m!==r){if(this.isPruned)throw new m(`Cannot set value at ${this.path} - node is pruned`);if(Ke(r)&&this.schema?.hasChildren&&!this.schema?.isImplicit&&!this.schema?.isOpaque)throw new m("Container processing resulted in unexpected primitive",{value:r,location:this.location});this.#m=r,this.context.update(),r===void 0&&(this.completed=!1),this.path===""&&(this.processed=!0),r!==void 0&&this.#h.add(this.assignedInput),r===null&&!this.processed&&(this.processed=!0,this.completed=!0)}}copyPendingChildValues(r,t){if(t!==void 0&&!this.isOpaque&&this.hasChildren&&t!==r&&be(t)&&be(r))for(let[n,i]of Object.entries(r)){if(i===void 0)continue;let o=this.#o.get(n);o?.schema&&!o.schema.isImplicit&&(o.isPruned?t[n]!==void 0&&delete t[n]:t[n]!==i&&(t[n]=i))}}invalidate(){this.#c=this.location?.schema&&!this.location.schema.hasConditions?!0:void 0,this.#m=void 0,this.#d=!1,this.#l=void 0,this.#f=void 0,this.context.update()}get mandatory(){return this.#g}set mandatory(r){this.#g=!!r}get processed(){return this.#d}set processed(r){this.#d=!!r,this.#d&&this.hasChildren}get isRequired(){if(this.#f!==void 0)return this.#f;if(this.schema?.required)this.#f=!0;else if(!this.hasChildren)this.#f=!1;else if(this.isDeep){for(let r of this.#o.values())if(r.isRequired){this.#f=!0;break}}return this.#f??!1}get isComplete(){return this.completed||this.isPruned||!this.condition&&this.context.final?!0:this.value===void 0&&(this.isRequired||this.schema?.default!==void 0&&(typeof this.schema.default!="function"||this.schema.options.dynamic===!1))||this.hasIncompleteDescendents||this.hasWorkInProgress||this.isUnion?!1:this.processed||this.schema?.isImplicit||this.value!==void 0?!0:this.schema?.isReference&&!this.context.final||this.mandatory?!1:typeof this.assignedInput=="function"&&this.schema?.options.dynamic!==!1&&this.input===void 0?this.context.final:this.assignedInput!==void 0&&!this.#h.has(this.assignedInput)?!1:this.assignedInput===void 0&&this.context.traversals>0?!0:!!(this.assignedInput===void 0&&this.context.final)}get completed(){return this.#y}set completed(r){this.#y=!!r,!this.#y&&this.parent?.completed&&(this.parent.completed=!1)}get hasProcessedInput(){return this.value!==void 0&&this.assignedInput!==void 0&&this.input!==void 0&&this.#h.has(this.assignedInput)}get isPlaceholder(){return this.schema?.default!==void 0?!1:!this.mandatory&&this.value===void 0}get hasChildren(){return this.schema?.hasChildren??!1}get isContainer(){return this.schema?.isContainer??!1}get isPruned(){return this.#m===null||!!this.#s?.isPruned}get isDeep(){return this.schema?.deep??this.context.deep}get isOpaque(){return this.schema===void 0?!0:!this.hasChildren||this.schema.isOpaque}get isIncremental(){return this.schema===void 0?!1:this.hasChildren&&!this.schema.isOpaque}get isStrict(){return this.schema===void 0?this.parent?.isStrict??this.context.strict:this.schema.strict??this.context.strict}get allowUnknown(){return!this.isStrict}get isUnion(){return this.schema?.isUnion??!1}get isUnresolved(){return this.schema===void 0||this.schema.isUnion}get treatAsExplicit(){return this.schema===void 0?!0:this.schema.isImplicit?!1:!(this.hasChildren&&this.isIncremental)}get hasDescendentStates(){return this.hasChildren?this.#o.size>0:!1}get hasDescendentsToTraverse(){if(!this.hasChildren)return!1;let r=typeof this.#a=="object"&&!K(this.#a);return this.hasDescendentStates||r}get hasIncompleteDescendents(){return this.hasChildren?[...this.#o.values()].some(r=>!r.completed):!1}get incompleteDescendents(){if(!this.hasChildren)return[];let r=this.path?`${this.path}.`:"";return Array.from(this.#e.stateMap.values()).filter(t=>t.path!==this.path&&t.path.startsWith(r)&&!t.isComplete)}findIncompleteChildNames(r=new Set){for(let t of this.#o.values())t.completed||r.add(t.name);return r}listIncompleteChildren(){return[...this.#o.values()].filter(r=>!r.isComplete).map(r=>r.name)}listPendingChildren(){return[...this.#o.values()].filter(r=>r.hasWorkInProgress||r.needsInputProcessing).map(r=>r.name)}invalidateChildren(){for(let r of this.#o.values())r.value!==null&&r.invalidate()}get isEmptyPlaceholder(){return!this.schema?.hasChildren||!this.isPlaceholder?!1:!this.hasDescendentsToTraverse}get needsInputProcessing(){return this.value!==void 0?!1:typeof this.assignedInput!==void 0&&(this.input===void 0||this.pending===void 0)}get hasWorkInProgress(){return this.isPruned||this.pending===void 0||this.schema?.isImplicit?!1:this.hasChildren&&K(this.pending)?this.schema?.options.allowEmpty?!0:this.processed?!1:!!this.mandatory:!0}get activePropertyStates(){if(this.completed)return[];if(this.schema===void 0)return[];if(this.isOpaque&&this.processed)return[];if(!this.condition)return[];if(this.pending===void 0&&this.value===void 0&&!this.schema.options.allowUndefined&&!this.schema.options.deep)return[];if(!this.schema.hasChildren)return[];let r=new Set,t=this.input;if((M(t)||Array.isArray(t)||t&&this.isIncremental)&&Object.keys(t).forEach(o=>{r.add(o)}),this.findIncompleteChildNames(r),this.isIncremental||this.value===void 0)for(let[o,a]of this.schema.propertyEntries)o!=="*"&&(this.context.final||this.isDeep||a.required||a.default!==void 0||a.isReference)&&r.add(o);let n=this.pending??(this.isIncremental?this.value:void 0),i=Array.isArray(n)&&n.length||M(n)&&Object.keys(n).length;return!i&&!this.mandatory&&this.input===void 0&&!this.isDeep&&!this.hasIncompleteDescendents?[]:(i&&this.context.final&&Object.keys(n).forEach(o=>{(this.isStrict||this.schema?.getPropertySchema(o))&&r.add(o)}),[...r].map(o=>this.getChildState(o)))}get target(){return this.context.getValue()}get options(){return this.#l===void 0&&(this.#l={...this.context.options,deep:this.isDeep,strict:this.isStrict,state:this,context:this.context}),this.#l}}});function Ar(...e){(globalThis[Ca]??console.log)?.(...e)}var Ca,Sr=p(()=>{"use strict";Ca=Symbol.for("@versionzero/debug-sink");s(Ar,"debug")});var me,xr=p(()=>{"use strict";Fe();et();Sr();ir();ne();se();h();me=class{static{s(this,"TraversalContext")}constructor(r,t={}){this.root=r instanceof b?new z(r):r,this._final=!1,this._options={...t,deep:t.deep??!1,strict:t.strict??!0,debug:t.debug??!1,stats:t.stats??{}},this.traversals=0,this.counter=0,this.stateMap=new Map,this._debugEnabled=t?.debug??!1,this.compiling=!1}get options(){return this._options}get deep(){return this._options.deep}get strict(){return this._options.strict}get stats(){return this._options.stats}update(){this.counter++,this.final=!1}_finalizeCount=0;set final(r){if(this._final&&!r&&this._finalizeCount++>100)throw new m("Unable to finalize a stable output value");this._final=r??!0}get final(){return!!this._final}finalize(){return this._final=!0,this}get isComplete(){for(let r of this.stateMap.values())if(!r.isComplete)return!1;return!0}get incomplete(){let r=new Set;for(let t of this.stateMap.values())t.isComplete||r.add(t.path);return r}setValue(r){this._value=r}getValue(){return this._value!==void 0?this._value:this.getState("")?.value}setAssignedInput(r,t=""){if(r===void 0)return;let n=this.getState("");for(;t;){let[i,o]=qe(t),a=n.getChildState(i);n.assignedInput??=H,n=a,t=o,n.mandatory=!0}n.assignedInput=r,n.mandatory=!0}getState(r){r instanceof z&&(r=r.path);let t=this.stateMap.get(r);if(t===void 0){let n=this;t=new ar(n,r),n._value,this.stateMap.set(r,t)}return t}_debug(...r){this._debugEnabled&&Ar({contextName:"context"},...r)}traverse(r){let t=this.getState(""),n=!1,i=s(a=>(this.traversals++,this.stats.traversals=this.traversals,this.stats.updates=this.counter,this.isComplete?n=!0:this.counter===a?this.final?n=!0:this.final=!0:this.final=!1,n),"updateDone"),o=s(()=>{let a;for(;!n;){let c=this.counter;if(a=r.execute(t),a instanceof Promise)return a.then(f=>i(c)?f:o(),f=>{throw f});i(c)}return a},"loop");return o()}}});var ce,Ze=p(()=>{"use strict";Z();ce=class extends O{static{s(this,"PipelineExecutor")}#e;constructor(r=[]){Array.isArray(r)||(r=[r]),super(),this.#e=r.map(t=>F(t))}execute(r,...t){let n=0,i=this.#e;for(;n<i.length;)if(r=i[n++].execute(r,...t),r instanceof Promise)return r.then(o=>this.#r(o,t,n));return r}async#r(r,t,n){for(;n<this.#e.length;){let i=r;r=await this.#e[n++].execute(r,...t)}return r}}});var U,ae=p(()=>{"use strict";Z();U=class extends O{static{s(this,"ValueProcessor")}#e;#r;constructor(r,t){super(),this.#r=r,this.#e=t}get description(){return this.#e}set description(r){this.#e=r}get spec(){return this.#r}set spec(r){this.#r=r}execute(r,t,n,i){return r}}});var pe,rt=p(()=>{"use strict";Z();pe=class extends O{static{s(this,"StepExecutor")}#e;constructor(r=[]){Array.isArray(r)||(r=[r]),super(),this.#e=r.map(t=>F(t))}execute(r,...t){if(r==null)return r;let n=0,i=this.#e;for(;n<i.length;){if(r=i[n++].execute(r,...t),r==null)return r;if(r instanceof Promise)return r.then(o=>this.#r(o,t,n))}return r}async#r(r,t,n){for(;n<this.#e.length;){if(r==null)return r;r=await this.#e[n++].execute(r,...t)}return r}}});function Cr(e){let r=e.parent;if(r){if(e.assignedInput===void 0||e.assignedInput===H){let t=r.input?.[e.key];t!==void 0&&(e.assignedInput=t)}e.schema?.isImplicit&&!e.isPruned&&(e.value??=r.value?.[e.key])}if(e.isPruned)return null;if(!e.completed)return e}var tt=p(()=>{"use strict";se();s(Cr,"enter")});function br(e){if(e.schema!==void 0)return e;let r=e.parent;if(r===void 0)throw new D("invariant: root path schema must be defined");if(r.schema===void 0)throw new D("invariant: cannot process a child if parent schema is undefined");if(!r.schema.isUnion||e.context.final)if(r?.schema?.strict??r?.context.strict){let i=e.context.root.schema?.isValidPath(e.path)?"Unexpected property":"Unknown property";throw new D(i,{path:e.path})}else return e.value=null,null}var nt=p(()=>{"use strict";h();s(br,"checkSchema")});function it(e){return e.assignedInput===void 0&&e.pending===void 0&&e.value===void 0&&(e.schema?.default!==void 0?(e.assignedInput=e.schema.default,e.mandatory=!0):e.isDeep&&e.isContainer&&(e.assignedInput=H)),e}var ot=p(()=>{"use strict";se();s(it,"defaults")});function st(e){if(e.processed&&e.hasProcessedInput)return e;if(e.assignedInput===null)return null;if(e.assignedInput===void 0)return e;if(e.location===void 0)return;let t=e.location.schema._normalizeValue(e.assignedInput,e.target,e.location,e.options),n=s(i=>(e.input=i,i===null?null:e),"updateState");return t instanceof Promise?t.then(n):n(t)}var at=p(()=>{"use strict";s(st,"normalize")});function ct(e){if(e.input===null)return null;if(e.schema!==void 0)return e.schema.isImplicit||e.input===void 0||e.schema.ensureAccepts(e.input),e}var ft=p(()=>{"use strict";s(ct,"checkInput")});function Xe(e){if(!e.schema?.isUnion||!e.location)return e;let r=e.pending??e.input??e.value,t=e.schema._discriminateUnion(r,e.target,e.location,{...e.options,strict:e.context.final}),n=s(i=>{if(i){if(e.schema=i,i.isUnion)return Xe(e)}else if(e.context.final)throw new le("Unable to resolve union",{location:e.location});return e},"handleUnionSchema");return t instanceof Promise?t.then(i=>n(i)):n(t)}var ut=p(()=>{"use strict";h();s(Xe,"resolveUnion")});function cr(e){if(e.condition===!0)return e;if(e.schema===void 0)return;let r=e.schema._checkCondition(e.input,e.context.getValue(),e.location,e.options),t=s(n=>(e.condition=n,!n&&e.context.final&&(e.value=null),n?e:e.context.final?null:void 0),"handleConditionResult");return r instanceof Promise?r.then(n=>t(n)):t(r)}var mt=p(()=>{"use strict";s(cr,"checkCondition")});function pt(e){if(e.location===void 0)return;let r=e.location.schema;if(e.input===void 0&&!r.options.allowUndefined)return e;if(e.hasChildren){if(e.pending!==void 0)return e;if(e.value!==void 0){if(e.isIncremental)return e.pending=e.value,e;throw new m("Value already processed",{location:e.location})}let t=r._normalizeValue(H,e.target,e.location,e.options);return t instanceof Promise?t.then(n=>(e.pending=n,e)):(e.pending=t,e)}else return e.pending=e.input,e}var dt=p(()=>{"use strict";se();h();s(pt,"preparePending")});function lt(e){if(e.value!==void 0&&(e.value===e.pending||e.hasChildren&&e.isIncremental&&G(e.pending,e.value)))return e.pending=void 0,e;if(e.pending===void 0||e.schema===void 0||e.isUnion||e.schema.isImplicit||e.hasChildren&&e.isOpaque||e.hasChildren&&!e.mandatory&&K(e.pending))return e;let r=e.schema._transformValue(e.pending,e.target,e.location,e.options),t=s(n=>(n!==void 0&&(n!==e.value&&e.hasChildren&&e.copyPendingChildValues(e.pending,n),e.pending=void 0,e.value=n),e.value===null?null:e),"updateState");return r instanceof Promise?r.then(t):t(r)}var ht=p(()=>{"use strict";te();q();s(lt,"transformEarly")});function wt(e){if(e.isPruned)return null;if(e.isComplete)return e;if(!e.condition)return;if(e.schema===void 0||e.isUnion)return e;if(e.value!==void 0&&(e.value===e.pending||e.hasChildren&&e.isIncremental&&G(e.pending,e.value)))return e.pending=void 0,e;if(e.pending===void 0||e.schema?.isImplicit||!e.hasWorkInProgress||e.hasChildren&&e.isOpaque&&e.hasIncompleteDescendents||e.hasChildren&&e.isIncremental&&!e.mandatory&&K(e.pending)&&!e.schema.options.allowEmpty)return e;let r=e.schema._transformValue(e.pending,e.target,e.location,e.options),t=s(n=>(n!==void 0&&(n!==e.value&&e.hasChildren&&e.copyPendingChildValues(e.pending,n),e.pending=void 0,e.value=n),e.value===null?null:e),"updateState");return r instanceof Promise?r.then(t):t(r)}var yt=p(()=>{"use strict";te();q();s(wt,"transform")});function Rr(e){if(!e.condition)return e;if(e.context.final&&e.isRequired&&e.value===void 0)throw new D("Undefined required value",{path:e.path});return e}var gt=p(()=>{"use strict";h();s(Rr,"checkRequired")});function $r(e){if(e.completed)return e;if(!(e.context.final||e.isComplete)){let i=e.isComplete;return e}if(e.schema===void 0){if(e.allowUnknown)return e;throw new D("Unknown value",{path:e.path})}if(e.schema.isUnion)throw new D("Unable to resolve union",{path:e.path});if(e.value===void 0&&e.schema.isReference&&!e.isRequired)return e;if(e.hasWorkInProgress){if(e.value===void 0&&!e.isRequired)return e;let i=e.hasWorkInProgress;throw new D("Incomplete assignment",{value:e.pending,path:e.path})}if(e.value===void 0)return e;let t=e.schema._validateValue(e.value,e.target,e.location,e.options),n=s(i=>(i!==e.value&&(e.value=i),e),"updateState");return t instanceof Promise?t.then(n):n(t)}var Et=p(()=>{"use strict";h();s($r,"validate")});function ve(e){if(e.value===null||e.value===void 0&&e.input!==void 0)return e;if(e.completed)return;let r=e.parent;if(e.completed=e.isComplete,r===void 0)return e.isUnion||(e.processed=!0),e;let t=r.pending??r.value;if(t===null)return null;if(t===void 0||typeof t!="object"){let i=`${t}`;i.length>20&&(i=i.slice(0,20)+"...");let o=i.length?`\xAB${i}\xBB is not a valid container (set opaque option?)`:"Not a valid container (set opaque option?)";throw new m(o,{path:r.path})}let n=e.key;return e.schema?.isImplicit?(e.value??=t[n],e.processed=!0):(t[n]!==e.value&&(t[n]=e.value,e.context.update()),e.isUnion||(e.processed=!0)),e}var At=p(()=>{"use strict";h();s(ve,"exit")});function Pr(e){if(e.assignedInput===void 0&&e.parent&&(e.assignedInput=e.parent.input?.[e.key]),e.isPruned)return null;if(!e.completed)return e.input=e.assignedInput,e.schema!==void 0&&(e.pending=e.input),e}var St=p(()=>{"use strict";s(Pr,"enterExisting")});function Tr(e){if(e.schema!==void 0)return e.input===void 0&&!e.schema.options.allowUndefined||(e.isUnion?e.pending??=e.input:(e.value=e.pending??e.input,e.pending=void 0)),e}var xt=p(()=>{"use strict";s(Tr,"prepareExisting")});function Or(e){return e==="true"||e==="1"||e==="yes"||e==="enabled"||e==="active"||e==="on"}function Ir(e){return e==="false"||e==="0"||e==="no"||e==="disabled"||e==="inactive"||e==="off"||e===""||e==="undefined"||e==="null"||e==="none"}function Q(e){if(typeof e=="boolean")return e;if(typeof e=="string"){let r=e.toLowerCase().trim();if(Or(r))return!0;if(Ir(r))return!1}return e instanceof Error?!1:!!e}function _r(e){if(typeof e=="boolean")return!e;if(typeof e=="string"){let r=e.toLowerCase().trim();if(Or(r))return!1;if(Ir(r))return!0}return e instanceof Error?!0:!e}var he=p(()=>{"use strict";s(Or,"isTruthyKeyword");s(Ir,"isFalseyKeyword");s(Q,"isTruthy");s(_r,"isFalsey")});function Ct(e){if(e.schema===void 0)return;let r=e.schema;if(e.assignedInput===null||r.isImplicit||Q(r.metadata.omitFromSerialize))return null;if(e.assignedInput===void 0)return e;let t=r._serializeValue(e.assignedInput,e.target,e.location,e.options),n=s(i=>i===null?(e.value=null,null):(e.pending??=e.hasChildren?r.isArray||Array.isArray(t)?[]:{}:i,e.isUnion||(e.value=e.pending),e.input=i,e),"updateState");return t instanceof Promise?t.then(n):n(t)}var bt=p(()=>{"use strict";he();s(Ct,"serialize")});function Rt(e){if(e.completed)return e;if(e.schema===void 0){if(e.allowUnknown)return e;throw new ee("Unknown value",{path:e.path})}if(!e.schema.requiresFinalization)return e;if(!(e.context.final||e.isComplete))return;if(e.schema.isUnion)throw new ee("Unable to resolve union",{path:e.path});if(e.value===void 0&&e.schema.isReference&&!e.isRequired)return e;if(e.hasWorkInProgress){if(e.value===void 0&&!e.isRequired)return e;let i=e.hasWorkInProgress;throw new ee("Incomplete assignment",{value:e.pending,path:e.path})}if(e.value===void 0)return e;let t=e.schema._finalizeValue(e.value,e.target,e.location,e.options),n=s(i=>(i!==e.value&&(e.value=i),e),"updateState");return t instanceof Promise?t.then(n):n(t)}var $t=p(()=>{"use strict";h();s(Rt,"finalize")});var ie,$e=p(()=>{"use strict";Z();ie=class extends O{static{s(this,"EachExecutor")}#e;#r;#t;constructor(r,t,n){super(),this.#e=F(r),this.#r=t,this.#t=n}execute(r,...t){let n=this.#r?this.#r(r):r;if(!n)return r;Array.isArray(n)||(n=[n]);let i=!0,o=n.map(a=>{let c=this.#e.execute(a,...t);return i&&c instanceof Promise&&(i=!1),c});return i?this.#t?this.#t(o,r):o:Promise.all(o).then(a=>this.#t?this.#t(a,r):a)}}});var _,kr=p(()=>{"use strict";Z();he();_=class e extends O{static{s(this,"SequenceExecutor")}#e;#r;#t;#n;#i;constructor(r=[],t=[]){Array.isArray(r)||(r=[r]),super(),this.#e=r.map(n=>F(n));for(let n of t)if(n===e.ALL_CRITERIA)this.#r=n;else if(n===e.ANY_CRITERIA)this.#r=n;else if(n===e.EXCLUSIVE_CRITERIA)this.#r=n;else if(n===e.SUCCESS_CHECK)this.#t=n;else if(n===e.DEFINED_CHECK)this.#t=n;else if(n===e.TRUTHY_CHECK)this.#t=n;else if(n===e.INPUT_RETURN)this.#n=n;else if(n===e.RESULT_RETURN)this.#n=n;else if(n===e.RETHROW_ERRORS)this.#i=n;else if(n===e.CAPTURE_ERRORS)this.#i=n;else throw new Error("Unknown flag");this.#r??=e.ALL_CRITERIA,this.#t??=e.SUCCESS_CHECK,this.#n??=e.INPUT_RETURN,this.#i??=e.RETHROW_ERRORS}execute(r,...t){let n,i=0,o=0,a=0,c=s(()=>{switch(this.#r){case e.ANY_CRITERIA:return i>0;case e.EXCLUSIVE_CRITERIA:return i===1&&a===this.#e.length;case e.ALL_CRITERIA:return i===this.#e.length}return!1},"criteriaSatisfied"),f=s(()=>{switch(this.#r){case e.ANY_CRITERIA:return i===0&&a===this.#e.length;case e.EXCLUSIVE_CRITERIA:return i>1;case e.ALL_CRITERIA:return o>0}return!1},"criteriaFailed"),l=s(async()=>{for(;a<this.#e.length&&!(f()||c());)try{let d=await this.#e[a++].execute(r,...t);E(d)}catch(d){if(this.#t===e.SUCCESS_CHECK)return;x(d)}return S()},"resume"),E=s(d=>{(this.#t===e.TRUTHY_CHECK?Q(d):this.#t===e.DEFINED_CHECK?d!==void 0:!0)?i++:o++,f()||(n=d)},"handleResult"),x=s(d=>{if(this.#i===e.RETHROW_ERRORS)throw d;o++},"handleFailure"),S=s(()=>{if(c())return this.#n===e.RESULT_RETURN?n:r},"finalResult"),A=this.#e;for(;a<A.length;){let d;try{if(d=A[a++].execute(r,...t),d instanceof Promise)return d.then(R=>(E(R),l()),R=>(x(R),l()));E(d)}catch(R){if(x(R),this.#t===e.SUCCESS_CHECK)return}if(f()||c())break}return S()}static ANY_CRITERIA=Symbol("ANY-CRITERIA");static ALL_CRITERIA=Symbol("ALL-CRITERIA");static EXCLUSIVE_CRITERIA=Symbol("EXCLUSIVE-CRITERIA");static TRUTHY_CHECK=Symbol("TRUTHY-CHECK");static DEFINED_CHECK=Symbol("DEFINED-CHECK");static SUCCESS_CHECK=Symbol("SUCCESS-CHECK");static RESULT_RETURN=Symbol("RESULT-RETURN");static INPUT_RETURN=Symbol("INPUT-RETURN");static RETHROW_ERRORS=Symbol("RETHROW-ERRORS");static CAPTURE_ERRORS=Symbol("CAPTURE-ERRORS")}});var Ge,Pt=p(()=>{"use strict";kr();Ge=class extends _{static{s(this,"SerialExecutor")}constructor(r=[]){Array.isArray(r)||(r=[r]),super(r)}}});var Pe,Tt=p(()=>{"use strict";Z();$e();Pt();Pe=class extends O{static{s(this,"TraversalStateExecutor")}#e;constructor(r,t){super();let n=F(r),i=F(t),o=new Ge(new ie(this,(a=>a?.activePropertyStates??[])));this.#e=new Ge([n,o,i])}execute(r){return this.#e.execute(r)}}});var ba,Ra,Ot,$a,Pa,It,Ta,Oa,_t,Ia,_a,Nr,kt=p(()=>{"use strict";rt();tt();nt();ot();at();ft();ut();mt();dt();ht();yt();gt();Et();At();St();xt();bt();$t();Tt();ba=new pe([Cr,br,it,st,ct,Xe,cr,pt,lt]),Ra=new pe([wt,Rt,Rr,$r,ve]),Ot=new Pe(ba,Ra),$a=new pe([Pr,Xe,cr,Tr]),Pa=new pe([Rr,$r,ve]),It=new Pe($a,Pa),Ta=new pe([Cr,br,Ct,Xe,cr]),Oa=new pe([ve]),_t=new Pe(Ta,Oa),Ia=new pe([Pr,Tr]),_a=new pe([ve]),Nr=new Pe(Ia,_a)});var b,ne=p(()=>{"use strict";sr();Fe();xr();Ze();ae();se();kt();h();te();he();q();k();b=class e{static{s(this,"CompiledSchema")}static __TOKEN=Symbol("CONSTRUCT_USING_COMPILER");#e=new Map;#r;#t=new Map;#n;#i=new Map;#s={};#o={};#u={};#a=!1;constructor(r){if(r!==e.__TOKEN)throw new m("CompiledSchema must be created via compilation")}get options(){return this.#o}get metadata(){return this.#u}get properties(){return this.#r??=Object.freeze(Object.fromEntries(this.#e))}get propertyEntries(){return this.#e.entries()}get handlers(){return this.#s}getValueProcessor(r){return this.#i.get(r)}_setValueProcessor(r,t){return this.#i.set(r,t),t}get unionSchemas(){return this.#n??=Object.freeze(Object.fromEntries(this.#t))}get unionSchemaEntries(){return this.#t.entries()}toData(){return Ue(this)}get hasChildren(){return this.#e.size>0}get isContainer(){return this.hasChildren||!!this.options.container}get hasWildcard(){return this.#e.has("*")}get isArray(){return this.options.type==="array"}get isFunction(){return this.options.type==="function"}get isUnion(){return this.#t.size>0}get isUnionKey(){return!!this.options.unionKey}get isSelector(){return!!this.options.selector}get hasChildSelector(){for(let r of this.#e.values())if(r.isSelector)return!0;return!1}get isSelection(){return this.options.selection!==void 0&&this.options.selection!==!1}get hasChildSelection(){for(let r of this.#e.values())if(r.isSelection)return!0;return!1}get selection(){return this.options.selection}get values(){return this.options.values}get hasValues(){let r=this.options.values;return Array.isArray(r)&&r.length>0}get strict(){return this.options.strict}get required(){return this.options.required??!1}get default(){return this.options.default}get deep(){if(this.options.deep!==void 0)return this.options.deep;if(this.hasChildren&&this.required)return!0}get isReference(){return this.options.reference??!1}get isImplicit(){return this.options.implicit??!1}get allowIncremental(){return this.options.allowIncremental??this.hasChildren}get isOpaque(){return!this.hasChildren||this.options.allowIncremental===!1}_checkCondition(r,t,n=new z(this),i){if(n.schema!==this)return n.schema._checkCondition(r,t,n,i);if(r instanceof Error&&!this.options.allowErrors)return!1;let o=this.getValueProcessor("conditions");if(!o)return!0;try{let a=o.execute(r,t,n,i);return a instanceof Promise?a.then(c=>c instanceof Error&&!this.options.allowErrors?!1:Q(c),c=>!1):a instanceof Error&&!this.options.allowErrors?!1:Q(a)}catch{return!1}}async checkCondition(r,t,n=new z(this),i){return this._checkCondition(r,t,n,i)}get hasConditions(){let r=this.handlers.conditions;return!!(r&&Array.isArray(r)&&r.length)}get requiresFinalization(){let r=this.handlers.finalizers;return!!(r&&Array.isArray(r)&&r.length)}_checkValue(r,t){if(r instanceof Error&&!this.options.allowErrors){if(t&&r instanceof t)throw r;{let n=new t(r.message,{cause:r});throw Error?.captureStackTrace(n,this._checkValue),n}}return r}_discriminateUnion(r,t,n=new z(this),i={}){if(n.schema!==this)return n.schema._discriminateUnion(r,t,n,i);let o=this.getValueProcessor("discriminators");if(!this.isUnion||!o)return;if(r instanceof Error&&!this.options.allowErrors){if(i?.strict)throw r;return}let a;try{a=o.execute(r,t,n,i)}catch(c){if(i?.strict)throw c;return}return a instanceof Promise?a.then(c=>this.getUnionSchema(c),c=>{if(i.strict)throw c}):this.getUnionSchema(a)}async discriminateUnion(r,t,n=new z(this),i){return this._discriminateUnion(r,t,n,i)}_normalizeValue(r,t,n=new z(this),i={}){if(n.schema!==this)return n.schema._normalizeValue(r,t,n,i);if(r instanceof Error&&!this.options.allowErrors)throw new ue(r.message,{cause:r});let o=i?.sync??!1,a=i?.dynamic??this.options?.dynamic??!0;if((typeof r=="function"||r instanceof U)&&a&&!i.compiling){let l=r instanceof U?r.execute(!0,t,n,i):r(!0,t,n,i);if(l instanceof Promise){if(o)throw new ue("Encountered an async value function during a forced-sync normalization",{location:n});return l.then(E=>E==null?E:this._normalizeValue(E,t,n,{...i,dynamic:!1}))}r=l}if(r===null||r===void 0&&!this.options.allowUndefined)return r;let c=this.getValueProcessor("normalizers");if(c===void 0)return this.isContainer&&r===H?this.isArray?[]:{}:r;let f;try{f=c.execute(r,t,n,i)}catch(l){throw new ue("Unable to normalize",{location:n,cause:l})}if(f instanceof Promise){if(o)throw new ue("Encountered an async processor during a forced-sync normalization",{location:n});return f.then(l=>this._checkValue(l,ue),l=>{throw new ue("Unable to normalize",{value:r,location:n,cause:l})})}return this._checkValue(f)}async normalizeValue(r,t,n=new z(this),i){return this._normalizeValue(r,t,n,i)}_transformValue(r,t,n=new z(this),i={}){if(n.schema!==this)return n.schema._transformValue(r,t,n,i);if(r instanceof Error&&!this.options.allowErrors)throw new X(r.message,{cause:r});if(this.isImplicit)throw new X("Cannot transform a value for an implicit schema",{location:n});if(r===null||r===void 0&&!this.options.allowUndefined)return r;let o;try{this.ensureAccepts(r);let a=this.getValueProcessor("transformers");if(a===void 0)return r;o=a.execute(r,t,n,i)}catch(a){throw new X("Unable to transform",{value:r,location:n,cause:a})}return o instanceof Promise?o.then(a=>this._checkValue(a,X),a=>{throw new X("Unable to transform",{value:r,location:n,cause:a})}):this._checkValue(o,X)}async transformValue(r,t,n=new z(this),i){return this._transformValue(r,t,n,i)}_finalizeValue(r,t,n=new z(this),i={}){if(n.schema!==this)return n.schema._finalizeValue(r,t,n,i);if(r instanceof Error&&!this.options.allowErrors)throw new ee(r.message,{cause:r});if(this.isImplicit)throw new X("Cannot finalize a value for an implicit schema",{location:n});if(r===null||r===void 0&&!this.options.allowUndefined)return r;let o;try{let a=this.getValueProcessor("finalizers");if(a===void 0)return r;o=a.execute(r,t,n,i)}catch(a){throw new ee("Unable to finalize",{value:r,location:n,cause:a})}return o instanceof Promise?o.then(a=>this._checkValue(a,ee),a=>{throw new ee("Unable to finalize",{value:r,location:n,cause:a})}):this._checkValue(o,ee)}async finalizeValue(r,t,n=new z(this),i){return this._finalizeValue(r,t,n,i)}_validateValue(r,t,n=new z(this),i={}){if(n.schema!==this)return n.schema._validateValue(r,t,n,i);if(this.required===!0&&r===void 0)throw new D("Missing required value",{location:n});if(r==null)return r;if(r instanceof Error&&!this.options.allowErrors)throw new D(r.message,{cause:r});let o=this.getValueProcessor("validators");if(!o)return r;let a=i?.revalidate??n.schema.options?.revalidate??!0,c;try{c=o.execute(r,t,n,i)}catch(f){throw f instanceof D?f:new D("Validation failed",{value:r,location:n,cause:f})}return c instanceof Promise?c.then(f=>f!==r&&f!==void 0&&a?this._validateValue(f,t,n,{...i,revalidate:!1}):f===void 0?r:this._checkValue(f,D),f=>{throw f instanceof D?f:new D("Validation failed",{value:r,location:n,cause:f})}):c!==r&&c!==void 0&&a?this._validateValue(c,t,n,{...i,revalidate:!1}):c===void 0?r:this._checkValue(c,D)}async validateValue(r,t,n,i){return this._validateValue(r,t,n,i)}_serializeValue(r,t,n=new z(this),i={}){if(n.schema!==this)return n.schema._serializeValue(r,t,n,i);if(r==null||this.isImplicit||Q(this.metadata.omitFromSerialize))return null;let o=this.getValueProcessor("serializers")??this.getValueProcessor("normalizers");if(!o)return r;let a;try{a=o.execute(r,t,n,i)}catch(c){if(i?.strict)throw new Re("Unable to serialize",{value:r,location:n,cause:c});return}return a instanceof Promise?a.then(c=>i?.strict?this._checkValue(c,Re):c,c=>{if(i?.strict)throw new Re("Unable to serialize",{value:r,location:n,cause:c})}):i?.strict?this._checkValue(a,Re):a}async serializeValue(r,t,n=new z(this),i){return this._serializeValue(r,t,n,i)}ensureAccepts(r){if(r===void 0){if(this.options.allowUndefined)return;throw new D("Schema does not accept an undefined input")}if(!Array.isArray(this.values)||this.values.length===0||this.options.allowUnknownValues)return;if(!this.values.some(n=>G(n,r))){let n=this.metadata.valueDescription??`{${this.values.map(y).join("|")}}`,i=n.length>80?'not found in schema "values" option':`expected one of ${n}`;throw new D(`Invalid value ${y(r)}, ${i}`)}}checkAccepts(r){try{return this.ensureAccepts(r),!0}catch{return!1}}_validate(r,t={}){let n=t.location??new z(this),i=t.context instanceof me?t.context:new me(n,t),o=[()=>(i.setAssignedInput(r,""),i.traverse(Nr)),()=>{for(let a of i.stateMap.values())a.completed=!1;return i.traverse(It)},()=>i.getValue()];return new ce(o).execute(i)}async validate(r,t){return this._validate(r,t)}_process(r,t,n={}){let i=n?.location??new z(this),o=n.context instanceof me?n.context:new me(i,{strict:n?.strict,deep:n?.deep,debug:n?.debug,stats:n?.stats}),a=[];return t!==void 0&&a.push(()=>(o.setAssignedInput(t,""),o.traverse(Nr))),a.push(()=>{if(o.setAssignedInput(r,n?.inputPath),n?.assignments)for(let[c,f]of n.assignments)o.setAssignedInput(f,c);return o.traverse(Ot)}),a.push(()=>o.getValue()),new ce(a).execute(o)}async process(r,t,n={}){return this._process(r,t,n)}async processAssignments(r,t,n={}){return this._process(void 0,t,{...n,assignments:r})}async serialize(r,t={}){let n=t?.location??new z(this),i=t.context instanceof me?t.context:new me(n,{strict:t?.strict,deep:t?.deep,debug:t?.debug}),o=[()=>(i.setAssignedInput(r,""),i.traverse(_t)),()=>We(i.getValue())];return new ce(o).execute(i)}findUnionKey(r){if(!this.isUnion)throw new m("Cannot find union key because schema is not a union");for(let[t,n]of this.unionSchemaEntries)if(n===r)return t}getUnionSchema(r){if(r){if(typeof r=="string"){if(!this.isUnion)throw new m(`Cannot get union schema with key "${r}" because schema is not a union`);if(this.#t.has(r))return this.#t.get(r);throw new m(`Unknown union schema key "${r}"`)}if(r instanceof e){if(!this.isUnion)throw new m("Schema is not a union");if(this.findUnionKey(r))return r;throw new m("Schema is not a union member")}throw new m("Unable to get union schema with provided data")}}_setUnionSchema(r,t){if(!r)throw new m("Unable to set a union schema without a valid key");if(!(t instanceof e))throw new m("Union schema must be a CompiledSchema instance");if(this.#a)throw new m(`Cannot add union schema "${r}" to a frozen CompiledSchema`);return this.#n=void 0,this.#t.set(r,t),t}find(r){if(!r||r===""||r===".")return this;let t=r.split("."),n=this;for(let i of t)if(n=n?.getPropertySchema(i),!n)return;return n}toAssignments(r,t=""){if(typeof r!="object")return new Map([["",r]]);let n=new Map;function i(o,a,c){let f=Array.isArray(a)||M(a),l=o?.allowIncremental??!0;if(f&&o?.hasChildren){let E=Array.isArray(a)?a.entries():Object.entries(a);for(let[x,S]of E){let A=o?.getPropertySchema(`${x}`);i(A,S,c?`${c}.${x}`:`${x}`)}}else n.set(c,a)}return s(i,"walk"),i(this,r,t),n}visitSchema(r,t){let n=new Set,i=t?.onlySerializable??!1;function o(a,c){if(!n.has(a)&&(n.add(a),!(a.metadata.omitFromSerialize&&i))){if(a.hasChildren)for(let[f,l]of a.propertyEntries){let E=c?`${c}.${f}`:`${f}`;if(o(l,E)===!1)return!1}if(a.isUnion){for(let[f,l]of a.unionSchemaEntries)if(o(l,c)===!1)return}return r(a,c)}}return s(o,"walk"),o(this,"")??!0}getPropertyPaths(){let r=new Set;return this.visitSchema((t,n)=>{n&&r.add(n)}),r}getPropertySchema(r){if(!r)throw new m("Unable to retrieve an unnamed property");return this.#e.get(r)??this.#e.get("*")}_setPropertySchema(r,t){if(!r)throw new m("Unable to set an unnamed property");if(!(t instanceof e))throw new m("Property schema must be a CompiledSchema instance");if(this.#a)throw new m(`Cannot add property ${r} to a frozen CompiledSchema`);return this.#r=void 0,this.#e.set(r,t),this.#o.container??=!0,t}getTagged(r){let t=[];for(let n of this.#e.values())n.options[r]&&t.push(n);return t}getFirstTagged(r){for(let t of this.#e.values())if(t.options[r])return t}isValidPath(r){if(r==="")return!0;let t=r.split(".");function n(i,o=0){if(o>=t.length)return i!==void 0;let a=t[o],c=i.getPropertySchema(a);if(c)return n(c,o+1);if(i.isUnion){for(let f of i.#t.values())if(n(f,o))return!0}return!1}return s(n,"check"),n(this)}_freeze(r=new Set){if(!(this.#a||r.has(this))){this.#a=!0,r.add(this);for(let t of this.#e.values())t._freeze(r);Object.freeze(this.#e);for(let t of this.#t.values())t._freeze(r);Object.freeze(this.#t),Object.freeze(this.#o),Object.freeze(this.#u),Object.freeze(this)}}}});var N,v=p(()=>{"use strict";ae();h();N=class extends U{static{s(this,"FunctionValueProcessor")}#e;#r;constructor(r,t){if(super(),t){if(!(t instanceof U))throw new m("FunctionValueProcessor args must be a ValueProcessor");this.#e=t}this.#r=r,this.spec=r}execute(r,t,n,i){if(this.#e){let o=this.#e.execute(r,t,n,i);return o instanceof Promise?o.then(a=>this.#r(r,t,n,{...i,args:a})):this.#r(r,t,n,{...i,args:o})}return this.#r(r,t,n,i)}}});var g,j=p(()=>{"use strict";Ce();ae();q();g=class extends U{static{s(this,"ComposedValueProcessor")}#e;constructor(r,t,n){if(r instanceof U&&(n=r.description),!n&&r.isConstant){let i=r.execute(!0);n=Ke(i)?`${i}`:ye(i)}super(t,n),this.#e=r}execute(r,t,n,i){return this.#e.execute(r,t,n,i)}get isConstant(){return this.#e.isConstant}}});var fe,De=p(()=>{"use strict";Z();h();fe=class extends O{static{s(this,"ObjectExecutor")}#e=[];#r;#t;constructor(r={},t){super();let n=!0;for(let[i,o]of Object.entries(r)){if(o===void 0)continue;let a=F(o);this.#e.push([i,a]),n&&=a.isConstant}if(this.#r=t,n){if(t)throw new m("Cannot use a preprocessor with a constant object executor");this.#t=Object.fromEntries(this.#e.map(([i,o])=>[i,o.execute(!0)]))}}execute(r,...t){if(this.#t!==void 0)return this.#t;let n={},i=0,o=this.#e;for(;i<o.length;){let a=o[i][0],c=this.#r?this.#r(r):r,f=o[i++][1].execute(c,...t);if(f instanceof Promise)return f.then(l=>(n[a]=l,this.#n(r,t,i,n)));n[a]=f}return n}async#n(r,t,n,i){let o=this.#e;for(;n<o.length;){let a=o[n][0],c=this.#r?this.#r(r):r;i[a]=await o[n++][1].execute(c,...t)}return i}get isConstant(){return this.#t!==void 0}}});var oe,Te=p(()=>{"use strict";Z();oe=class extends O{static{s(this,"ArrayExecutor")}#e=[];#r;constructor(r=[]){Array.isArray(r)||(r=[r]),super();let t=!0;for(let n of r){let i=F(n);t&&=i.isConstant,this.#e.push(i)}this.#r=t?this.#e.map(n=>n.execute(!0)):void 0}execute(r,...t){if(this.#r!==void 0)return this.#r;let n=[],i=0,o=this.#e;for(;i<o.length;){let a=o[i++].execute(r,...t);if(a instanceof Promise)return a.then(c=>(n.push(c),this.#t(r,t,i,n)));n.push(a)}return n}async#t(r,t,n,i){for(;n<this.#e.length;)i.push(await this.#e[n++].execute(r,...t));return i}get isConstant(){return this.#r!==void 0}}});var Le,Vr=p(()=>{"use strict";Z();De();ae();j();h();q();Le=class extends U{static{s(this,"ParametersValueProcessor")}#e;#r;#t;constructor(r=[],t={}){super();let n={};if(Array.isArray(t)){if(t.length>r.length)throw new m("Too many arguments");for(let a=0;a<r.length;++a)a<t.length&&(n[r[a].parameter]=t[a])}else{if(Object.keys(t).length>r.length)throw new m("Too many arguments");for(let a=0;a<r.length;++a){let c=t[r[a].parameter];c&&(n[r[a].parameter]=c)}for(let a of Object.keys(t))if(n[a]===void 0)throw new m(`Unknown parameter ${a}`)}let i=!0,o=!1;for(let a=0;a<r.length;++a){let c=r[a].hasOwnProperty("default");if(r[a].required){if(o)throw new m(`Required parameter ${r[a].parameter} cannot follow optional parameter`)}else c||(o&&(i=!1),o=!0);if(n[r[a].parameter]===void 0&&c&&(n[r[a].parameter]=new g(new W(r[a].default),r[a].default)),n[r[a].parameter]===void 0){if(r[a].required)throw new m(`Missing required argument for parameter ${r[a].parameter}`);o&&i&&!c&&(n[r[a].parameter]=new g(new O,"$input"),i=!1)}if(n[r[a].parameter]?.isConstant&&r[a].type!==void 0){let f=n[r[a].parameter].execute(!0);if(r[a].type!==void 0&&f!==void 0&&typeof f!==r[a].type)throw new m(`Invalid ${r[a].type} type for parameter "${r[a].parameter}"`,{value:f})}}if(this.#e=new fe(n),this.#r=r,this.#e.isConstant){let a=this.#e.execute(!0);this.#t=this.#n(a);let c="";for(let[f,l]of Object.entries(a))c.length&&(c+=","),c+=`${f}=${l}`;this.description=`[${c}]`}this.spec=B(n,a=>a.spec)}#n(r){for(let t of this.#r)if(r[t.parameter]!==void 0&&t.type&&typeof r[t.parameter]!==t.type)throw new m(`Invalid type for parameter ${t.parameter}, expected ${t.type}`);return r}execute(r,t,n,i){if(this.#t!==void 0)return this.#t;let o=this.#e.execute(r,t,n,i);return o instanceof Promise?o.then(a=>this.#n(a)):this.#n(o)}get isConstant(){return this.#t!==void 0}}});var Ee,ur=p(()=>{"use strict";ae();Ee=class extends U{static{s(this,"ParameterizedValueProcessor")}#e;#r;constructor(r,t,n,i){super(n,i),this.#e=r,this.#r=t}execute(r,t,n,i){if(this.#r){let o=this.#r.execute(r,t,n,i);return o instanceof Promise?o.then(a=>this.#e.execute(r,t,n,{...i,args:a})):this.#e.execute(r,t,n,{...i,args:o})}return this.#e.execute(r,t,n,i)}}});function Qe(e){return!e||typeof e!="string"?[]:e.split(/[^a-zA-Z0-9]+/).flatMap(r=>r.split(/(?<=[a-z])(?=[A-Z])/)).flatMap(r=>r.split(/(?<=[0-9])(?=[A-Za-z])/)).filter(r=>r.length>0).map(r=>r.toLowerCase())}function Ua(e){return e.length===0?"":e[0]+e.slice(1).map(r=>r.charAt(0).toUpperCase()+r.slice(1)).join("")}function Va(e){return e.length===0?"":e.map(r=>r.charAt(0).toUpperCase()+r.slice(1)).join("")}function ja(e){return e.length===0?"":e.map(r=>r.charAt(0).toUpperCase()+r.slice(1)).join(" ")}function Da(e){return e.map(r=>r.toUpperCase()).join("_")}function La(e){return e.map(r=>r.toLowerCase()).join("-")}function jr(e){return Ua(Qe(e))}function zr(e){return Va(Qe(e))}function Dr(e){return Da(Qe(e))}function Oe(e){return La(Qe(e))}function Lr(e){return ja(Qe(e))}function Mr(e){if(!e||typeof e!="string")return"";let r=e.trim().replace(/\s+/g," "),t=0,n=r.search(/\b\w(?=[^]*$)/);return r.replace(/\b(\w)(\w*)\b/g,(i,o,a,c)=>t++!==0&&c!==n&&za.has(i.toLowerCase())?i.toLowerCase():o.toUpperCase()+a.toLowerCase())}var za,we=p(()=>{"use strict";s(Qe,"normalizeToWords");s(Ua,"wordsToCamelCase");s(Va,"wordsToPascalCase");s(ja,"wordsToCapitalize");za=new Set(["a","an","the","and","but","or","nor","for","so","yet","at","by","in","of","on","to","up","as","via"]);s(Da,"wordsToConstantCase");s(La,"wordsToKebabCase");s(jr,"toCamelCase");s(zr,"toPascalCase");s(Dr,"toConstantCase");s(Oe,"toKebabCase");s(Lr,"toCapitalize");s(Mr,"toTitleCase")});function Ie(e){if(e instanceof RegExp)return e;if(typeof e=="string"&&e.startsWith("/")&&e.lastIndexOf("/")>0){let r=e.lastIndexOf("/");return new RegExp(e.slice(1,r),e.slice(r+1))}throw new m("Unable to parse RegExp",{value:e})}var er=p(()=>{"use strict";h();s(Ie,"parseRegExp")});var nn={};w(nn,{MAX_OPERATOR:()=>Ha,MIN_OPERATOR:()=>Fa,SUM_OPERATOR:()=>qa});var qa,Fa,Ha,on=p(()=>{"use strict";h();k();qa={keyword:"sum",process:s((e,r,t)=>{if(!Array.isArray(e))throw new u(`$sum requires an array, got ${y(e)}`,{location:t});let n=0;for(let i=0;i<e.length;i++){if(typeof e[i]!="number"||!Number.isFinite(e[i]))throw new u(`$sum requires an array of finite numbers, got ${y(e[i])} at index ${i}`,{location:t});n+=e[i]}return n},"process")},Fa={keyword:"min",process:s((e,r,t)=>{if(!Array.isArray(e))throw new u(`$min requires an array, got ${y(e)}`,{location:t});if(e.length!==0){for(let n=0;n<e.length;n++)if(typeof e[n]!="number"||!Number.isFinite(e[n]))throw new u(`$min requires an array of finite numbers, got ${y(e[n])} at index ${n}`,{location:t});return Math.min(...e)}},"process")},Ha={keyword:"max",process:s((e,r,t)=>{if(!Array.isArray(e))throw new u(`$max requires an array, got ${y(e)}`,{location:t});if(e.length!==0){for(let n=0;n<e.length;n++)if(typeof e[n]!="number"||!Number.isFinite(e[n]))throw new u(`$max requires an array of finite numbers, got ${y(e[n])} at index ${n}`,{location:t});return Math.max(...e)}},"process")}});var sn={};w(sn,{ALPHA_CONSTRAINT:()=>Ka});var Ka,an=p(()=>{"use strict";h();Ka={keyword:"alpha",process:s(e=>{if(!/^[a-zA-Z]+$/.test(e))throw new u("Must contain only letters");return e},"process")}});var cn={};w(cn,{ALPHANUM_CONSTRAINT:()=>Ba});var Ba,fn=p(()=>{"use strict";h();Ba={keyword:"alphanum",process:s(e=>{if(!/^[a-zA-Z0-9]+$/.test(e))throw new u("Must contain only alphanumeric characters");return e},"process")}});var un={};w(un,{ARRAY_OPERATOR:()=>Wa});var Wa,mn=p(()=>{"use strict";Ce();se();h();Wa={keyword:"array",process:s((e,r,t)=>{if(e===H)e=[];else if(e==="*"){let n=t?.schema.getPropertySchema("*")?.values;if(n!==void 0)e=[...n];else throw new u("Schema must define values in order to expand wildcard array")}if(typeof e=="string")if(e=e.trim(),e.length>0&&e[0]==="["&&e[e.length-1]==="]")try{e=He(e)}catch{throw new u(`Invalid input string for array: ${e}`)}else e=e.split(",").map(n=>n.trim()).filter(n=>n.length>0);if(Array.isArray(e))return e;throw new u(`Invalid input for array: ${e}`)},"process")}});var T,Ae=p(()=>{"use strict";Z();he();T=class e extends O{static{s(this,"ConditionalExecutor")}#e;#r;#t;#n=!1;#i=!1;#s=!1;#o=!1;constructor(r,t={},n=[]){super(),this.#e=F(r??new O),this.#r=F(t.success??new O),this.#t=F(t.failure??Ve);for(let i of n)if(i===e.CHECK_TRUTHY)this.#s=!0;else if(i===e.CHECK_DEFINED)this.#o=!0;else if(i===e.PASS_RESULT)this.#n=!0;else if(i===e.PASS_ERROR)this.#i=!0;else throw new Error("Unknown flag")}execute(r,...t){let n=s((o,a)=>{let c,f=this.#n?a:r,l=this.#i?o:f;return o?c=!1:this.#s?c=Q(a):this.#o?c=a!==void 0:c=!0,c?this.#r.execute(f,...t):this.#t.execute(l,...t)},"handle"),i;try{i=this.#e.execute(r,...t)}catch(o){return n(o)}return i instanceof Promise?i.then(o=>n(void 0,o),o=>n(o)):n(void 0,i)}static CHECK_TRUTHY=Symbol("CHECK-TRUTHY");static CHECK_DEFINED=Symbol("CHECK-DEFINED");static PASS_RESULT=Symbol("PASS-RESULT");static PASS_ERROR=Symbol("PASS-ERROR")}});var pn={};w(pn,{ASSERT_CONSTRAINT:()=>Ya});var Ya,dn=p(()=>{"use strict";ae();j();Ae();Z();h();Ya={keyword:"assert",build:s(e=>{let r;if(Array.isArray(e))if(e.length===1)r=e[0];else if(e.length===0)r=new g(new O,[]);else throw new m("$assert requires a single processor argument");else typeof e=="object"&&(r=e.processor);if(!(r instanceof U))throw new m("$assert requires a processor argument");let t=e.length===0?"$assert":{$assert:r.spec},n=r.description;return new g(new T(r,{failure:s(i=>{throw i instanceof u?i:new u("Processed value was not truthy",{cause:i})},"failure")},[T.CHECK_TRUTHY,T.PASS_ERROR]),t,n)},"build")}});var ln={};w(ln,{BASE64_CONSTRAINT:()=>Za});var Za,hn=p(()=>{"use strict";h();Za={keyword:"base64",process:s(e=>{if(!/^[A-Za-z0-9+/]*={0,2}$/.test(e))throw new u("Invalid base64 format");if(e.includes("=")&&e.length%4!==0)throw new u("Invalid base64 format");return e},"process")}});var wn={};w(wn,{CAMEL_CASE_OPERATOR:()=>Xa});var Xa,yn=p(()=>{"use strict";we();Xa={keyword:"camel-case",process:s(e=>jr(String(e)),"process")}});var gn={};w(gn,{CAPITALIZE_OPERATOR:()=>va});var va,En=p(()=>{"use strict";we();va={keyword:"capitalize",process:s(e=>Lr(String(e)),"process")}});var Sn={};w(Sn,{CARDNUM_CONSTRAINT:()=>ec});function Qa(e){let r=0,t=!1;for(let n=e.length-1;n>=0;n--){let i=+e[n];t&&(i*=2,i>9&&(i-=9)),r+=i,t=!t}return r%10===0}function An(e,r){let t=[],n=0;for(let i of r){if(n>=e.length)break;t.push(e.slice(n,n+i)),n+=i}return n<e.length&&t.push(e.slice(n)),t.join(" ")}var Ga,Ja,ec,xn=p(()=>{"use strict";h();Ga=[{name:"amex",match:s(e=>e.startsWith("34")||e.startsWith("37"),"match"),groups:[4,6,5]},{name:"diners",match:s(e=>{let r=+e.slice(0,3);return r>=300&&r<=305||e.startsWith("36")||e.startsWith("38")},"match"),groups:[4,6,4]},{name:"jcb",match:s(e=>{let r=+e.slice(0,4);return r>=3528&&r<=3589},"match"),groups:[4,4,4,4]},{name:"discover",match:s(e=>{let r=+e.slice(0,3),t=+e.slice(0,6);return e.startsWith("6011")||e.startsWith("65")||r>=644&&r<=649||t>=622126&&t<=622925},"match"),groups:[4,4,4,4]},{name:"mastercard",match:s(e=>{let r=+e.slice(0,2),t=+e.slice(0,4);return r>=51&&r<=55||t>=2221&&t<=2720},"match"),groups:[4,4,4,4]},{name:"visa",match:s(e=>e.startsWith("4"),"match"),groups:[4,4,4,4]}],Ja=[4,4,4,4];s(Qa,"luhnCheck");s(An,"formatWithGroups");ec={keyword:"cardnum",parameters:[{parameter:"mask",default:!1},{parameter:"reveal",default:4}],process:s((e,r,t,n)=>{let{mask:i,reveal:o}=n.args,a=e.replace(/[\s\-.]/g,"");if(!/^\d+$/.test(a))throw new u("Invalid card number format");if(a.length<12||a.length>19)throw new u("Invalid card number length");if(!Qa(a))throw new u("Invalid card number (checksum failed)");let c=Ja;for(let f of Ga)if(f.match(a)){c=f.groups;break}if(i){let f=(typeof i=="string"?i[0]:null)||"\u2022",l=Math.min(Math.max(0,o),a.length),E=f.repeat(a.length-l)+a.slice(a.length-l);return An(E,c)}return An(a,c)},"process")}});var Cn={};w(Cn,{CEIL_OPERATOR:()=>rc});var rc,bn=p(()=>{"use strict";rc={keyword:"ceil",parameters:[{parameter:"precision",default:0}],process:s((e,r,t,n)=>{let i=Number(e);if(!Number.isFinite(i))return e;let o=n.args.precision,a=Math.pow(10,o);return Math.ceil(i*a)/a},"process")}});var Rn={};w(Rn,{COLLAPSE_OPERATOR:()=>tc});var tc,$n=p(()=>{"use strict";tc={keyword:"collapse",process:s(e=>String(e).replace(/\s+/g," ").trim(),"process")}});var Pn={};w(Pn,{COMPACT_OPERATOR:()=>nc});var nc,Tn=p(()=>{"use strict";nc={keyword:"compact",process:s(e=>String(e).replace(/[\s()\-./]/g,""),"process")}});var In={};w(In,{COMPILE_OPERATOR:()=>On});var On,_n=p(()=>{"use strict";Vr();ur();v();h();k();On={keyword:"compile",parameters:[{parameter:"schema",required:!1},{parameter:"compiler",required:!1}],build:s((e,r)=>{let t=r.compiler,n=new Le(On.parameters,e);return new Ee(new N((i,o,a,c)=>{let f=c.args.compiler??t;if(typeof f?.compile!="function")throw new m(`Invalid compiler provided to $compile ${y(f)}`,{location:a});return c.args.schema!==void 0&&(i=c.args.schema),f.compile(i)}),n,{$compile:n.spec})},"build")}});var kn={};w(kn,{CONCAT_OPERATOR:()=>ic});var ic,Nn=p(()=>{"use strict";j();v();Te();q();h();ic={keyword:"concat",build:s(e=>{if(!Array.isArray(e)||e.length===0)throw new m("$concat requires a non-empty array of values to append");let r=B(e,t=>t.spec);return new N((t,n,i,o)=>{let a=Array.isArray(o.args)?o.args:[];if(!Array.isArray(t))throw new u(`$concat requires an array input, got ${t}`,{location:i});return[...t,...a]},new g(new oe(e),r))},"build")}});var Un={};w(Un,{CHECK_OPERATOR:()=>ac,GATE_OPERATOR:()=>sc,IF_OPERATOR:()=>oc,TRY_OPERATOR:()=>fc,WHEN_OPERATOR:()=>cc});function rr(e,r){return t=>{let n,i,o;if(Array.isArray(t)){if(t.length>3)throw new P(`${e} array requires 0-3 processors [predicate, success, failure]`);n=t[0],i=t[1],o=t[2]}else if(typeof t=="object"&&t!==null)n=t.predicate??t.condition??t.cond,i=t.success,o=t.failure;else if(t!==void 0)throw new P(`${e} requires predicate/success/failure processors specified as an array or object`);n??=new g(new O,[]),i??=new g(new O,[]),o??=new g(Ve,"$undefined");let a={[`${e}`]:[n.spec,i?.spec,o?.spec]},c=`(${n.description??""})?`;return i.description&&(c+=`(${i.description})`),o.description&&(c+=`:(${o.description})`),new g(new T(n,{success:i,failure:o},r),a,c)}}var oc,sc,ac,cc,fc,Vn=p(()=>{"use strict";Z();Ae();j();h();s(rr,"generateBuilderFunction");oc={keyword:"if",build:rr("$if",[T.CHECK_TRUTHY])},sc={keyword:"gate",build:rr("$gate",[T.CHECK_DEFINED])},ac={keyword:"check",build:rr("$check",[T.CHECK_TRUTHY,T.PASS_RESULT])},cc={keyword:"when",build:rr("$when",[T.CHECK_DEFINED,T.PASS_RESULT])},fc={keyword:"try",build:rr("$try",[T.PASS_ERROR,T.PASS_RESULT])}});var jn={};w(jn,{CONSTANT_CASE_OPERATOR:()=>uc});var uc,zn=p(()=>{"use strict";we();uc={keyword:"constant-case",process:s(e=>Dr(String(e)),"process")}});function Br(e,r){if(typeof e=="number"){if(!Number.isFinite(e)||e<0)throw new m(`Invalid data size: ${e}`);return e}if(typeof e!="string")throw new m(`Invalid data size: expected string or number, got ${typeof e}`);let t=e.match(dc);if(!t)throw new m(`Invalid data size: "${e}"`);let[,n,i]=t,o=parseFloat(n);if(!i)return o;let a=i.toLowerCase(),c=Kr.get(a);if(c===void 0)throw new m(`Unknown data size unit: "${i}"`);if(r){let f=r.toLowerCase();if(f==="iec"&&!mc.has(a))throw new m(`Unit "${i}" is not an IEC unit (expected B, KiB, MiB, GiB, TiB, PiB)`);if(f==="si"&&!pc.has(a))throw new m(`Unit "${i}" is not an SI unit (expected B, KB, MB, GB, TB, PB)`)}return o*c}function Wr(e,r="iec"){if(!Number.isFinite(e)||e<0)throw new m(`Invalid byte count: ${e}`);let t=r.toLowerCase()==="si"?Hr:Fr;for(let n=t.length-1;n>=0;n--){let[i,o]=t[n];if(e>=o||n===0){let a=e/o;return`${a%1===0?String(a):parseFloat(a.toFixed(2)).toString()} ${i}`}}}var Fr,Hr,Kr,mc,pc,dc,Yr=p(()=>{"use strict";h();Fr=[["B",1],["KiB",1024],["MiB",1024**2],["GiB",1024**3],["TiB",1024**4],["PiB",1024**5]],Hr=[["B",1],["KB",1e3],["MB",1e3**2],["GB",1e3**3],["TB",1e3**4],["PB",1e3**5]],Kr=new Map;for(let[e,r]of Fr)Kr.set(e.toLowerCase(),r);for(let[e,r]of Hr)Kr.set(e.toLowerCase(),r);mc=new Set(Fr.map(([e])=>e.toLowerCase())),pc=new Set(Hr.map(([e])=>e.toLowerCase())),dc=/^\s*(\d+(?:\.\d+)?)\s*([a-z]*)\s*$/i;s(Br,"parseDataSize");s(Wr,"formatDataSize")});var Dn={};w(Dn,{DATA_SIZE_OPERATOR:()=>wc});var lc,hc,wc,Ln=p(()=>{"use strict";h();Yr();lc=new Set(["iec","si","any"]),hc=new Set(["iec","si"]),wc={keyword:"data-size",parameters:[{parameter:"standard",default:"any",type:"string"},{parameter:"format",default:void 0,type:"string"}],process:s((e,r,t,n)=>{let{standard:i,format:o}=n?.args??{};if(i!==void 0&&!lc.has(i))throw new P(`$data-size: unknown standard "${i}" (expected iec, si, or any)`);if(o!==void 0&&!hc.has(o))throw new P(`$data-size: unknown format "${o}" (expected iec or si)`);if(typeof e=="number"&&o===void 0){if(!Number.isFinite(e)||e<0)throw new u(`Invalid data size: ${e}`);return e}let a=Br(e,i==="any"?void 0:i);return o!==void 0?Wr(a,o):a},"process"),describe:s(e=>{if(!e)return;let r=Array.isArray(e)?e[0]:e.standard,t=Array.isArray(e)?e[1]:e.format,n=r?.description,i=t?.description,o=[];return n!==void 0&&n!=="any"&&o.push(n.toUpperCase()),i!==void 0&&o.push(`\u2192 ${i.toUpperCase()}`),o.length?o.join(", "):void 0},"describe")}});var Mn={};w(Mn,{DATE_OBJECT_OPERATOR:()=>yc});var yc,qn=p(()=>{"use strict";h();k();yc={keyword:"date-object",parameters:[{parameter:"zone"}],process:s((e,r,t,n)=>{if(!(e instanceof Date))throw new u(`$date-object requires a Date, got ${y(e)}`,{location:t});let i=n.args.zone??"utc";if(i!=="utc"&&i!=="local")throw new u(`$date-object zone must be 'utc' or 'local', got ${y(i)}`,{location:t});return i==="local"?{year:e.getFullYear(),month:e.getMonth()+1,day:e.getDate(),hour:e.getHours(),minute:e.getMinutes(),second:e.getSeconds(),ms:e.getMilliseconds(),zone:"local"}:{year:e.getUTCFullYear(),month:e.getUTCMonth()+1,day:e.getUTCDate(),hour:e.getUTCHours(),minute:e.getUTCMinutes(),second:e.getUTCSeconds(),ms:e.getUTCMilliseconds(),zone:"utc"}},"process")}});function _e(e){if(e==="now")return new Date;if(typeof e=="string"){let r=e.match(/^([+-])(\d+(?:\.\d+)?)(ms|s|m|h|d|w)$/);if(r){let[,i,o,a]=r,c=i==="+"?1:-1,f=parseFloat(o)*c,l={ms:1,s:1e3,m:60*1e3,h:3600*1e3,d:1440*60*1e3,w:10080*60*1e3};return new Date(Date.now()+f*l[a])}let t=parseFloat(e);if(!isNaN(t)&&isFinite(t)&&/^\d+(\.\d+)?$/.test(e.trim())){let i=t;t>0&&t<2524608e3&&t<1e12&&(i=t*1e3);let o=new Date(i);if(isNaN(o.getTime()))throw new X(`Invalid date: ${e}`);return o}let n=new Date(e);if(isNaN(n.getTime()))throw new X(`Invalid date: ${e}`);return n}if(typeof e=="number"){let r=new Date(Math.abs(e)<2e8?e*1e3:e);if(isNaN(r.getTime()))throw new X(`Invalid date: ${e}`);return r}if(e instanceof Date){if(isNaN(e.getTime()))throw new X(`Invalid date: ${e}`);return new Date(e.getTime())}throw new X(`Invalid date: ${e} (${typeof e})`)}var pr=p(()=>{"use strict";h();s(_e,"parseDate")});var Fn={};w(Fn,{DATE_OPERATOR:()=>Ec});function gc(e){let{year:r,month:t,day:n,hour:i=0,minute:o=0,second:a=0,ms:c=0,zone:f="utc"}=e;return f==="local"?new Date(r,t-1,n,i,o,a,c):new Date(Date.UTC(r,t-1,n,i,o,a,c))}var Ec,Hn=p(()=>{"use strict";pr();h();s(gc,"fromDateObject");Ec={keyword:"date",process:s((e,r,t)=>{if(typeof e=="object"&&e!==null&&!(e instanceof Date)&&Number.isInteger(e.year)&&Number.isInteger(e.month)){let i=gc(e);if(isNaN(i.getTime()))throw new u(`Invalid date object: ${JSON.stringify(e)}`);return t.schema.options.type==="string"?i.toISOString():t.schema.options.type==="number"?i.getTime():i}if(typeof e!="string"&&typeof e!="number"&&!(e instanceof Date))throw new u(`Invalid input for date: ${e}`);let n=_e(e);return t.schema.options.type==="string"?n.toISOString():t.schema.options.type==="number"?n.getTime():n},"process")}});var Kn={};w(Kn,{DATE_RANGE_CONSTRAINT:()=>Ac});var Ac,Bn=p(()=>{"use strict";h();pr();Ac={keyword:"date-range",parameters:[{parameter:"min",default:void 0},{parameter:"max",default:void 0}],process:s((e,r,t,n)=>{let{min:i,max:o}=n.args,a=(e instanceof Date?e:_e(e)).getTime();if(i!==void 0){let c=(i instanceof Date?i:_e(i)).getTime();if(a<c)throw new u(`Date must not be before ${new Date(c).toISOString()}`)}if(o!==void 0){let c=(o instanceof Date?o:_e(o)).getTime();if(a>c)throw new u(`Date must not be after ${new Date(c).toISOString()}`)}return e},"process"),describe:s(e=>{if(!e)return;let r=Array.isArray(e)?e[0]:e.min,t=Array.isArray(e)?e[1]:e.max,n=r?.description,i=t?.description;return n!==void 0&&i!==void 0?`${n}..${i}`:n!==void 0?`>=${n}`:i!==void 0?`<=${i}`:void 0},"describe")}});var Wn={};w(Wn,{DEFINED_CONSTRAINT:()=>Sc});var Sc,Yn=p(()=>{"use strict";h();Sc={keyword:"defined",process:s(e=>{if(e===void 0)throw new u("Must be defined");return e},"process")}});var Zn={};w(Zn,{EACH_OPERATOR:()=>xc});var xc,Xn=p(()=>{"use strict";$e();j();Z();Ze();xc={keyword:"each",parameters:[{parameter:"processor",required:!0}],build:s(e=>{let r=(Array.isArray(e)?e[0]:e.processor)??new O,t=(Array.isArray(e)?e[1]:e.values)??new O,n={$each:r.spec},i=r.description?`[${r.description}]...`:"values...";return new g(new ce([t,new ie(r)]),n,i)},"build")}});var vn={};w(vn,{EMAIL_CONSTRAINT:()=>Rc});var Cc,bc,Rc,Gn=p(()=>{"use strict";h();he();Cc=/^[a-zA-Z0-9_%+-](?:[a-zA-Z0-9_%+.-]*[a-zA-Z0-9_%+-])?@(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?\.)+[a-zA-Z]{2,}$/,bc=/\.\./,Rc={keyword:"email",parameters:[{parameter:"case",default:"lower"},{parameter:"case-sensitive",type:"boolean",default:!1},{parameter:"filter",type:"boolean",default:!1}],process:s((e,r,t,n)=>{let{case:i,"case-sensitive":o,filter:a}=n.args;if(!Cc.test(e))throw new u("Invalid email format");let c=e.lastIndexOf("@"),f=e.slice(0,c),l=e.slice(c+1);if(bc.test(f))throw new u("Invalid email format");if(a){let x=f.indexOf("+");x!==-1&&(f=f.slice(0,x)),l.toLowerCase()==="gmail.com"&&(f=f.replace(/\./g,""))}let E=_r(i)?x=>x:i==="upper"?x=>x.toUpperCase():x=>x.toLowerCase();return l=E(l),o||(f=E(f)),`${f}@${l}`},"process")}});var Jn={};w(Jn,{ENTRIES_OPERATOR:()=>$c});var $c,Qn=p(()=>{"use strict";q();h();k();$c={keyword:"entries",process:s((e,r,t)=>{if(!M(e))throw new u(`$entries requires a plain object, got ${y(e)}`,{location:t});return Object.entries(e)},"process")}});var ei={};w(ei,{EQ_CONSTRAINT:()=>Pc});var Pc,ri=p(()=>{"use strict";te();h();k();Pc={keyword:"eq",parameters:[{parameter:"value",required:!0},{parameter:"compare"}],process:s((e,r,t,n)=>{let i=n.args.value,o=n.args.compare??e;if(!G(i,o))throw new u(`Value ${y(e)} was not equal to constraint`,{value:e,location:t});return e},"process")}});var ti={};w(ti,{FILTER_OPERATOR:()=>Tc});var Tc,ni=p(()=>{"use strict";j();Ae();v();$e();h();Tc={keyword:"filter",parameters:[{parameter:"processor",required:!1}],build:s(e=>{let r;if(Array.isArray(e)){if(e.length>1)throw new m("Expected exactly one argument for $filter operator");r=e[0]}else if(typeof e=="object"){if(Object.keys(e).length!==1)throw new m('Expected only "processor" argument for $filter operator');r=e.processor}return r??=new N(t=>t??void 0),new g(new ie(new T(r,{},[T.CHECK_DEFINED,T.PASS_RESULT]),t=>Array.isArray(t)?t:[],t=>Array.isArray(t)?t.filter(n=>n!==void 0):[]),{$filter:r.spec})},"build")}});var ii={};w(ii,{FIND_SCHEMA_OPERATOR:()=>Oc});var Oc,oi=p(()=>{"use strict";h();k();Oc={keyword:"find-schema",parameters:[{parameter:"path",required:!1}],process:s((e,r,t,n)=>{let i=n.args?.path??e??".";if(typeof i!="string")throw new m(`$find-schema "path" must be a string, got ${y(i)}`,{location:t});return t.relative(i)?.schema},"process")}});var si={};w(si,{FLATTEN_OPERATOR:()=>Ic});var Ic,ai=p(()=>{"use strict";h();k();Ic={keyword:"flatten",parameters:[{parameter:"depth",default:1}],process:s((e,r,t,n)=>{if(!Array.isArray(e))throw new u(`$flatten requires an array, got ${y(e)}`,{location:t});let i=n.args?.depth??1;return e.flat(i)},"process")}});var ci={};w(ci,{FLOOR_OPERATOR:()=>_c});var _c,fi=p(()=>{"use strict";_c={keyword:"floor",parameters:[{parameter:"precision",default:0}],process:s((e,r,t,n)=>{let i=Number(e);if(!Number.isFinite(i))return e;let o=n.args.precision,a=Math.pow(10,o);return Math.floor(i*a)/a},"process")}});var ui={};w(ui,{GET_OPERATOR:()=>kc});var kc,mi=p(()=>{"use strict";te();kc={keyword:"get",parameters:[{parameter:"path",required:!0}],process:s((e,r,t,n)=>{let i=n.args?.path;return typeof i=="number"?Array.isArray(e)?e[i]:void 0:re(e,i)},"process")}});var pi={};w(pi,{GROUP_BY_OPERATOR:()=>Nc});var Nc,di=p(()=>{"use strict";v();j();$e();h();k();Nc={keyword:"group-by",build:s(e=>{if(!Array.isArray(e)||e.length!==1)throw new m("$group-by requires a single key or processor argument");let r=e[0],t=r?.spec,n=typeof t=="string"&&!t.startsWith("$")?new N(i=>i?.[t]):r;return new g(new ie(n,i=>{if(!Array.isArray(i))throw new u(`$group-by requires an array, got ${y(i)}`);return i},(i,o)=>{let a={};for(let c=0;c<o.length;c++){let f=i[c];if(f===void 0)continue;let l=String(f);a[l]||(a[l]=[]),a[l].push(o[c])}return a}),{"$group-by":t})},"build")}});var li={};w(li,{HAS_PREFIX_CONSTRAINT:()=>Uc});var Uc,hi=p(()=>{"use strict";h();k();Uc={keyword:"has-prefix",parameters:[{parameter:"match",required:!0}],process:s((e,r,t,n)=>{let i=n.args.match;if(!`${e}`.startsWith(i))throw new u(`Value ${y(e)} did not start with prefix ${y(i)}`,{location:t});return e},"process")}});var wi={};w(wi,{HAS_SUFFIX_CONSTRAINT:()=>Vc});var Vc,yi=p(()=>{"use strict";h();k();Vc={keyword:"has-suffix",parameters:[{parameter:"match",required:!0}],process:s((e,r,t,n)=>{let i=n.args.match;if(!`${e}`.endsWith(i))throw new u(`Value ${y(e)} did not end with suffix ${y(i)}`,{location:t});return e},"process")}});var gi={};w(gi,{HEX_CONSTRAINT:()=>jc});var jc,Ei=p(()=>{"use strict";h();jc={keyword:"hex",process:s(e=>{if(!/^[0-9a-fA-F]+$/.test(e))throw new u("Must contain only hexadecimal characters");return e},"process")}});var Ai={};w(Ai,{HOSTNAME_CONSTRAINT:()=>zc});var zc,Si=p(()=>{"use strict";h();zc={keyword:"hostname",process:s(e=>{if(!/^[a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(\.[a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/.test(e))throw new u("Invalid hostname format");return e},"process")}});var xi={};w(xi,{HTTP_URL_CONSTRAINT:()=>Dc});var Dc,Ci=p(()=>{"use strict";h();Dc={keyword:"http-url",process:s(e=>{try{let r=new URL(e);if(!["http:","https:"].includes(r.protocol))throw new u("URL must use HTTP or HTTPS protocol");return e}catch(r){throw r instanceof u?r:new u("Invalid HTTP URL format",{cause:r})}},"process")}});var bi={};w(bi,{IN_CONSTRAINT:()=>Lc});var Lc,Ri=p(()=>{"use strict";q();j();v();Te();h();Lc={keyword:"in",build:s(e=>{let r=Array.isArray(e)?e:e?.values;if(K(e))throw new m("Must define at least one value for $in");let t=Array.isArray(r)?r.map(a=>a.description).join("|"):"[?]",n=B(r,a=>a.spec),i={$in:n},o=new N((a,c,f,l)=>{let E=(Array.isArray(l.args)?l.args:e.values)??[];if(!E.includes(a))throw new u(`Value must be one of {${E.join("|")}}`,{location:f});return a},new g(new oe(r),n));return o.spec=i,o.description=t,o},"build")}});var $i={};w($i,{INSTANCEOF_CONSTRAINT:()=>Mc});var Mc,Pi=p(()=>{"use strict";h();k();Mc={keyword:"instanceof",parameters:[{parameter:"clazz",type:"function",required:!0}],process:s((e,r,t,n)=>{let i=n.args.clazz;if(!(e instanceof i)){let o=i.name||"anonymous";throw new u(`Expected instance of ${o}, got ${y(e)}`,{location:t})}return e},"process")}});var Ti={};w(Ti,{INDEX_BY_OPERATOR:()=>qc});var qc,Oi=p(()=>{"use strict";v();j();$e();h();k();qc={keyword:"index-by",parameters:[{parameter:"processor",required:!0}],build:s(e=>{let r,t;if(Array.isArray(e)){if(e.length!==1)throw new m("$index-by requires only a single key, or extended arguments with a processor");t=e[0]}else typeof e=="object"&&(t=e.key,r=e.processor);if(t){if(r)throw new m("$index-by requires only a key or a processor, not both");r=new N((n,i,o,a)=>{let c=t.execute(n,i,o,{...a,input:n});return c instanceof Promise?c.then(f=>f!==void 0?n?.[f]:void 0):c!==void 0?n?.[c]:void 0})}if(!r)throw new m("$index-by requires a key or processor argument");return new g(new ie(r,n=>{if(!Array.isArray(n))throw new u(`$index-by requires an array, got ${y(n)}`);return n},(n,i)=>{let o={};for(let a=0;a<i.length;a++){let c=n[a];if(c!==void 0){if(o[String(c)]!==void 0)throw new u(`$index-by requires unique keys, got duplicate key ${c}`);o[String(c)]=i[a]}}return o}),{"$index-by":e})},"build")}});var Ii={};w(Ii,{INPUT_OPERATOR:()=>Fc});var Fc,_i=p(()=>{"use strict";Fc={keyword:"input",process:s(e=>e,"process")}});var ki={};w(ki,{INTEGER_CONSTRAINT:()=>Hc});var Hc,Ni=p(()=>{"use strict";h();Hc={keyword:"integer",process:s(e=>{if(typeof e!="number"||!Number.isFinite(e))throw new u("Must be a finite number");if(!Number.isInteger(e))throw new u("Must be an integer");return e},"process")}});var Ui={};w(Ui,{INVOKE_OPERATOR:()=>Kc});var Kc,Vi=p(()=>{"use strict";j();Ze();ur();Kc={keyword:"invoke",parameters:[{parameter:"processor",required:!0},{parameter:"arguments",required:!1}],build:s(e=>{let r=Array.isArray(e)?e[0]:e.processor,t=new g(new ce([r,i=>i]),r.spec),n=Array.isArray(e)?e[1]:e.arguments;return new Ee(t,n,{$invoke:{processor:r?.spec,arguments:n?.spec}})},"build")}});var ji={};w(ji,{IPV4_CONSTRAINT:()=>Yc});function lr(e){let[r,t,n,i]=e.split(".").map(Number);return(r<<24|t<<16|n<<8|i)>>>0}function Se(e){let[r,t]=e.split("/"),n=Number(t);if(!dr.test(r)||!Number.isInteger(n)||n<0||n>32)throw new P(`Invalid CIDR notation: ${e}`);let i=n===0?0:-1<<32-n>>>0;return{network:lr(r)&i,mask:i}}function Bc(e,r){return(e&r.mask)===r.network}function Wc(e){let r=ke[e.toLowerCase()];if(r)return r;if(e.includes("/"))return[Se(e)];throw new P(`Unknown IPv4 range: "${e}" (expected CIDR or one of: ${Object.keys(ke).join(", ")})`)}var dr,ke,Yc,zi=p(()=>{"use strict";h();dr=/^((25[0-5]|(2[0-4]|1\d|[1-9]|)\d)\.?\b){4}$/;s(lr,"ipToUint32");s(Se,"parseCIDR");s(Bc,"isInCIDR");ke={rfc1918:[Se("10.0.0.0/8"),Se("172.16.0.0/12"),Se("192.168.0.0/16")],loopback:[Se("127.0.0.0/8")],"link-local":[Se("169.254.0.0/16")],rfc6598:[Se("100.64.0.0/10")],multicast:[Se("224.0.0.0/4")]};ke["non-routable"]=[...ke.rfc1918,...ke.loopback,...ke["link-local"],...ke.rfc6598];s(Wc,"resolveRange");Yc={keyword:"ipv4",parameters:[{parameter:"in",default:void 0,type:"string"},{parameter:"min",default:void 0,type:"string"},{parameter:"max",default:void 0,type:"string"},{parameter:"format",default:void 0,type:"string"}],process:s((e,r,t,n)=>{if(!dr.test(e))throw new u("Invalid IPv4 address");let{in:i,min:o,max:a,format:c}=n?.args??{};if(i!==void 0&&(o!==void 0||a!==void 0))throw new P('$ipv4: "in" and "min"/"max" are mutually exclusive');if(o!==void 0&&!dr.test(o))throw new P(`$ipv4: invalid "min" address: ${o}`);if(a!==void 0&&!dr.test(a))throw new P(`$ipv4: invalid "max" address: ${a}`);let f=lr(e);if(i!==void 0&&!Wc(i).some(E=>Bc(f,E)))throw new u(`IPv4 address not in range "${i}"`);if(o!==void 0&&f<lr(o))throw new u(`IPv4 address below minimum ${o}`);if(a!==void 0&&f>lr(a))throw new u(`IPv4 address above maximum ${a}`);return c==="integer"?f:e},"process"),describe:s(e=>{if(!e)return;let r=Array.isArray(e)?e[0]:e.in,t=Array.isArray(e)?e[1]:e.min,n=Array.isArray(e)?e[2]:e.max,i=r?.description,o=t?.description,a=n?.description;if(i!==void 0)return`in ${i}`;if(o!==void 0&&a!==void 0)return`${o}\u2013${a}`;if(o!==void 0)return`\u2265${o}`;if(a!==void 0)return`\u2264${a}`},"describe")}});var Di={};w(Di,{IPV6_CONSTRAINT:()=>Gc});function wr(e){let r=e.replace(/%.*$/,""),t=Zc.exec(r);if(t){let[o,a,c,f]=[t[1],t[2],t[3],t[4]].map(Number),l=(o<<8|a).toString(16),E=(c<<8|f).toString(16);r=r.slice(0,t.index)+`${l}:${E}`}if(r.includes("::")){let[o,a]=r.split("::"),c=o?o.split(":"):[],f=a?a.split(":"):[],l=8-c.length-f.length,E=Array(l).fill("0");r=[...c,...E,...f].join(":")}let n=r.split(":"),i=0n;for(let o of n)i=i<<16n|BigInt(parseInt(o,16));return i}function tr(e){let r=e.lastIndexOf("/");if(r===-1)throw new P(`Invalid IPv6 CIDR notation: ${e}`);let t=e.slice(0,r),n=Number(e.slice(r+1));if(!hr.test(t)||!Number.isInteger(n)||n<0||n>128)throw new P(`Invalid IPv6 CIDR notation: ${e}`);let i=n===0?0n:(1n<<128n)-1n<<BigInt(128-n);return{network:wr(t)&i,mask:i}}function Xc(e,r){return(e&r.mask)===r.network}function vc(e){let r=Me[e.toLowerCase()];if(r)return r;if(e.includes("/"))return[tr(e)];throw new P(`Unknown IPv6 range: "${e}" (expected CIDR or one of: ${Object.keys(Me).join(", ")})`)}var hr,Zc,Me,Gc,Li=p(()=>{"use strict";h();hr=/^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$/,Zc=/(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/;s(wr,"ipv6ToBigInt");s(tr,"parseCIDR");s(Xc,"isInCIDR");Me={loopback:[tr("::1/128")],"link-local":[tr("fe80::/10")],"unique-local":[tr("fc00::/7")],multicast:[tr("ff00::/8")]};Me["non-routable"]=[...Me.loopback,...Me["link-local"],...Me["unique-local"]];s(vc,"resolveRange");Gc={keyword:"ipv6",parameters:[{parameter:"in",default:void 0,type:"string"},{parameter:"min",default:void 0,type:"string"},{parameter:"max",default:void 0,type:"string"}],process:s((e,r,t,n)=>{if(!hr.test(e))throw new u("Invalid IPv6 address");let{in:i,min:o,max:a}=n?.args??{};if(i!==void 0&&(o!==void 0||a!==void 0))throw new P('$ipv6: "in" and "min"/"max" are mutually exclusive');if(o!==void 0&&!hr.test(o))throw new P(`$ipv6: invalid "min" address: ${o}`);if(a!==void 0&&!hr.test(a))throw new P(`$ipv6: invalid "max" address: ${a}`);let c=wr(e);if(i!==void 0&&!vc(i).some(l=>Xc(c,l)))throw new u(`IPv6 address not in range "${i}"`);if(o!==void 0&&c<wr(o))throw new u(`IPv6 address below minimum ${o}`);if(a!==void 0&&c>wr(a))throw new u(`IPv6 address above maximum ${a}`);return e},"process"),describe:s(e=>{if(!e)return;let r=Array.isArray(e)?e[0]:e.in,t=Array.isArray(e)?e[1]:e.min,n=Array.isArray(e)?e[2]:e.max,i=r?.description,o=t?.description,a=n?.description;if(i!==void 0)return`in ${i}`;if(o!==void 0&&a!==void 0)return`${o}\u2013${a}`;if(o!==void 0)return`\u2265${o}`;if(a!==void 0)return`\u2264${a}`},"describe")}});var Mi={};w(Mi,{IS_ARRAY_CONSTRAINT:()=>Jc});var Jc,qi=p(()=>{"use strict";h();Jc={keyword:"is-array",process:s((e,r,t)=>{if(!Array.isArray(e))throw new u("Must be an array");return e},"process"),description:""}});var Fi={};w(Fi,{IS_DATE_CONSTRAINT:()=>Qc});var Qc,Hi=p(()=>{"use strict";h();k();Qc={keyword:"is-date",process:s(e=>{if(e instanceof Date&&!isNaN(e.getTime()))return e;throw new u(`Invalid date: ${y(e)}`)},"process"),description:""}});var Ki={};w(Ki,{IS_NUMBER_CONSTRAINT:()=>ef});var ef,Bi=p(()=>{"use strict";h();ef={keyword:"is-number",process:s(e=>{if(typeof e!="number"||Number.isNaN(e)||!Number.isFinite(e))throw new u("Must be a number");return e},"process"),description:""}});var Wi={};w(Wi,{IS_OBJECT_CONSTRAINT:()=>rf});var rf,Yi=p(()=>{"use strict";h();rf={keyword:"is-object",process:s((e,r,t)=>{if(typeof e=="object"&&e!==null)return e;throw new u("Must be an object")},"process"),description:""}});var Zi={};w(Zi,{IS_STRING_CONSTRAINT:()=>tf});var tf,Xi=p(()=>{"use strict";h();tf={keyword:"is-string",process:s(e=>{if(typeof e=="string")return e;throw new u("Must be a string")},"process"),description:""}});var vi={};w(vi,{JOIN_OPERATOR:()=>nf});var nf,Gi=p(()=>{"use strict";nf={keyword:"join",parameters:[{parameter:"separator",default:","}],process:s((e,r,t,n)=>{let i=n.args?.separator;return Array.isArray(e)?e.join(i):`${e}`},"process")}});var Ji={};w(Ji,{JSON_CONSTRAINT:()=>of});var of,Qi=p(()=>{"use strict";h();of={keyword:"json",process:s(e=>{try{return JSON.parse(e),e}catch{throw new u("Invalid JSON format")}},"process")}});var eo={};w(eo,{JSON_DECODE_OPERATOR:()=>sf});var sf,ro=p(()=>{"use strict";h();k();sf={keyword:"json-decode",process:s((e,r,t)=>{if(typeof e!="string")throw new u(`$json-decode requires a string, got ${y(e)}`,{location:t});try{return JSON.parse(e)}catch(n){throw new u(`$json-decode: invalid JSON \u2014 ${n.message}`,{location:t,cause:n})}},"process")}});var to={};w(to,{JSON_ENCODE_OPERATOR:()=>af});var af,no=p(()=>{"use strict";af={keyword:"json-encode",parameters:[{parameter:"indent",default:0}],process:s((e,r,t,n)=>{let i=n.args?.indent||0;return JSON.stringify(e,null,i||void 0)},"process")}});var io={};w(io,{KEBAB_CASE_OPERATOR:()=>cf});var cf,oo=p(()=>{"use strict";we();cf={keyword:"kebab-case",process:s(e=>Oe(String(e)),"process")}});var so={};w(so,{KEYS_OPERATOR:()=>ff});var ff,ao=p(()=>{"use strict";h();k();ff={keyword:"keys",process:s((e,r,t)=>{if(typeof e!="object"||e===null||Array.isArray(e))throw new u(`$keys requires a plain object, got ${y(e)}`,{location:t});return Object.keys(e)},"process")}});var co={};w(co,{LENGTH_CONSTRAINT:()=>uf});var uf,fo=p(()=>{"use strict";h();uf={keyword:"length",parameters:[{parameter:"exact",default:void 0,type:"number"},{parameter:"min",default:void 0,type:"number"},{parameter:"max",default:void 0,type:"number"}],process:s((e,r,t,n)=>{let{min:i,max:o,exact:a}=n.args,c=Array.isArray(e)?e.length:String(e).length,f=Array.isArray(e)?"elements":"characters";if(a!==void 0){if(c!==a)throw new u(`Length must be exactly ${a} ${f}`);return e}if(i!==void 0&&c<i)throw new u(`Length must be at least ${i} ${f}`);if(o!==void 0&&c>o)throw new u(`Length must be at most ${o} ${f}`);return e},"process"),describe:s(e=>{if(!e)return;let r=Array.isArray(e)?e[0]:e.min,t=Array.isArray(e)?e[1]:e.max,n=Array.isArray(e)?e[2]:e.exact,i=r?.description,o=t?.description,a=n?.description;return a!==void 0?`len=${a}`:i!==void 0&&o!==void 0?`len=${i}-${o}`:i!==void 0?`len\u2265${i}`:o!==void 0?`len\u2264${o}`:void 0},"describe")}});var uo={};w(uo,{LOOKUP_OPERATOR:()=>mf});var mf,mo=p(()=>{"use strict";h();te();mf={keyword:"lookup",parameters:[{parameter:"from",required:!0,type:"object"},{parameter:"path",type:"string"}],process:s((e,r,t,n)=>{let{from:i,path:o}=n.args;if(!(i===void 0||o===void 0)){if(typeof i!="object")throw new m('$lookup requires an object argument for "from"',{location:t});if(typeof o!="string")throw new m('$lookup requires a string argument for "path"',{location:t});return re(i,o)}},"process")}});var po={};w(po,{LOWERCASE_OPERATOR:()=>pf});var pf,lo=p(()=>{"use strict";pf={keyword:"lowercase",process:s(e=>String(e).toLowerCase(),"process")}});var ho={};w(ho,{MAP_OPERATOR:()=>df});var df,wo=p(()=>{"use strict";j();v();$e();q();h();k();df={keyword:"map",parameters:[{parameter:"processor",required:!0}],build:s(e=>{let r;if(Array.isArray(e)){if(e.length>1)throw new m("Expected exactly one argument for $map operator");r=e[0]}else if(typeof e=="object"){if(Object.keys(e).length!==1)throw new m('Expected only "processor" argument for $map operator');r=e.processor}return r??=new N(t=>t??void 0),new g(new ie(r,t=>{if(Array.isArray(t))return t;if(M(t))return Object.values(t);throw new u(`$map requires an array or plain object, got ${y(t)}`)},(t,n)=>{if(Array.isArray(n))return t;if(M(n))return Object.fromEntries(Object.keys(n).map((i,o)=>[i,t[o]]))}),{$map:r.spec})},"build")}});var yo={};w(yo,{MATCH_OPERATOR:()=>lf});var lf,go=p(()=>{"use strict";v();j();h();er();lf={keyword:"match",build:s(e=>{let r=(Array.isArray(e)?e[0]:e)?.spec;if(typeof r=="string"&&(r=Ie(r)),!(r instanceof RegExp))throw new m("$match requires a RegExp argument");return new g(new N((t,n,i)=>{if(typeof t!="string")throw new u("$match requires a string input",{location:i});let o=t.match(r);if(o!==null)return o.groups&&Object.keys(o.groups).length>0?{...o.groups}:[...o]}),{$match:r},`${r}`)},"build")}});var Eo={};w(Eo,{MATCHES_CONSTRAINT:()=>hf});var hf,Ao=p(()=>{"use strict";v();j();h();er();hf={keyword:"matches",build:s(e=>{let r=(Array.isArray(e)?e[0]:e)?.spec;if(typeof r=="string"&&(r=Ie(r)),!(r instanceof RegExp))throw new m("$matches requires a RegExp argument");let t=new N((n,i,o)=>{if(!r.test(String(n)))throw new u(`Value does not match pattern ${r}`,{location:o});return n});return t.description=`${r}`,new g(t,{$matches:r})},"build")}});var So={};w(So,{ABS_OPERATOR:()=>wf,CLAMP_OPERATOR:()=>Ef,POW_OPERATOR:()=>yf,SQRT_OPERATOR:()=>gf});var wf,yf,gf,Ef,xo=p(()=>{"use strict";h();k();wf={keyword:"abs",process:s((e,r,t)=>{if(typeof e!="number"||!Number.isFinite(e))throw new u(`$abs requires a finite number, got ${y(e)}`,{location:t});return Math.abs(e)},"process")},yf={keyword:"pow",parameters:[{parameter:"exponent",required:!0},{parameter:"base"}],process:s((e,r,t,n)=>{let i=n.args.exponent,o=n.args.base!==void 0?n.args.base:e;if(typeof o!="number"||!Number.isFinite(o))throw new u(`$pow requires a finite number base, got ${y(o)}`,{location:t});return Math.pow(o,i)},"process")},gf={keyword:"sqrt",process:s((e,r,t)=>{if(typeof e!="number"||!Number.isFinite(e)||e<0)throw new u(`$sqrt requires a non-negative finite number, got ${y(e)}`,{location:t});return Math.sqrt(e)},"process")},Ef={keyword:"clamp",parameters:[{parameter:"min"},{parameter:"max"}],process:s((e,r,t,n)=>{let i=n.args.min,o=n.args.max;if(typeof e!="number"||!Number.isFinite(e))throw new u(`$clamp requires a finite number, got ${y(e)}`,{location:t});if(i!==void 0&&(typeof i!="number"||!Number.isFinite(i)))throw new u(`$clamp min must be a finite number, got ${y(i)}`,{location:t});if(o!==void 0&&(typeof o!="number"||!Number.isFinite(o)))throw new u(`$clamp max must be a finite number, got ${y(o)}`,{location:t});let a=e;return i!==void 0&&(a=Math.max(i,a)),o!==void 0&&(a=Math.min(o,a)),a},"process")}});var Co={};w(Co,{MERGE_DEEP_OPERATOR:()=>Af});var Af,bo=p(()=>{"use strict";j();v();De();te();h();Af={keyword:"merge-deep",build:s(e=>{if(typeof e!="object"||e===null||Array.isArray(e))throw new m("$merge-deep requires an object argument");let r=Object.fromEntries(Object.entries(e).map(([t,n])=>[t,n?.spec??n]));return new N((t,n,i,o)=>{if(typeof t!="object"||t===null||Array.isArray(t))throw new u("$merge-deep requires a plain object input",{location:i});return Be({},t,o.args)},new g(new fe(e),{"$merge-deep":r}))},"build")}});var Ro={};w(Ro,{MERGE_OPERATOR:()=>Sf});var Sf,$o=p(()=>{"use strict";j();v();De();h();Sf={keyword:"merge",build:s(e=>{if(typeof e!="object"||e===null||Array.isArray(e))throw new m("$merge requires an object argument");let r=Object.fromEntries(Object.entries(e).map(([t,n])=>[t,n?.spec??n]));return new N((t,n,i,o)=>{if(typeof t!="object"||t===null||Array.isArray(t))throw new u("$merge requires a plain object input",{location:i});return{...t,...o.args}},new g(new fe(e),{$merge:r}))},"build")}});var Po={};w(Po,{METADATA_OPERATOR:()=>xf});var xf,To=p(()=>{"use strict";ne();h();k();xf={keyword:"metadata",parameters:[{parameter:"name",required:!0,type:"string"},{parameter:"schema",required:!1,default:void 0},{parameter:"inherit",required:!1,default:!0}],process:s((e,r,t,n)=>{let i=n.args.name,o=n.args.schema,a=n.args.inherit;if(o!==void 0){if(o instanceof b)return o.metadata[i];if(typeof o=="string"){let f=t.relative(o);if(f===void 0)throw new m(`$metadata was unable to retrieve a schema at ${y(o)}`);t=f}else throw new m(`$metadata expects a valid schema, got ${y(o)}`,{location:t})}let c=t;for(;c!==void 0;){if(c.schema.metadata[i]!==void 0)return c.schema.metadata[i];if(!a)break;c=c.parent}},"process")}});var Oo={};w(Oo,{NEGATIVE_CONSTRAINT:()=>Cf});var Cf,Io=p(()=>{"use strict";h();Cf={keyword:"negative",process:s(e=>{if(typeof e!="number"||!Number.isFinite(e)||e>=0)throw new u("Must be a negative number");return e},"process")}});var _o={};w(_o,{NEVER_CONSTRAINT:()=>bf});var bf,ko=p(()=>{"use strict";ae();j();Ae();Z();h();bf={keyword:"never",build:s(e=>{let r;if(Array.isArray(e))if(e.length===1)r=e[0];else if(e.length===0)r=new g(new O,[]);else throw new m("$never requires no more than a single value argument");else typeof e=="object"&&(r=e.processor);if(!(r instanceof U))throw new m("$never requires a value argument");let t=r.description&&/[|&>∧· ]/.test(r.description),n=r.description?t?`!(${r.description})`:`!${r.description}`:void 0,i={$never:r.spec};return new g(new T(r,{success:s(()=>{throw new u("Value must not match the specified condition")},"success"),failure:s(o=>o,"failure")},[T.CHECK_DEFINED]),i,n)},"build")}});var No={};w(No,{NON_EMPTY_CONSTRAINT:()=>Rf});var Rf,Uo=p(()=>{"use strict";h();Rf={keyword:"non-empty",process:s((e,r,t)=>{if(typeof e=="string"){if(e.trim().length===0)throw new u("String cannot be empty or whitespace only")}else if(Array.isArray(e)){if(e.length===0)throw new u("Array cannot be empty")}else if(typeof e=="object"&&e!==null){if(Object.keys(e).length===0)throw new u("Object cannot be empty")}else{if(e===void 0)throw new u("Value cannot be undefined");if(e===null)throw new u("Value cannot be null")}return e},"process")}});var Vo={};w(Vo,{NOT_CONSTRAINT:()=>$f});var $f,jo=p(()=>{"use strict";ae();j();Ae();Z();h();$f={keyword:"not",build:s(e=>{let r;if(Array.isArray(e))if(e.length===1)r=e[0];else if(e.length===0)r=new g(new O,[]);else throw new m("$not requires no more than a single value argument");else typeof e=="object"&&(r=e.processor);if(!(r instanceof U))throw new m("$not requires a value argument");let t=r.description&&/[|&>∧· ]/.test(r.description),n=r.description?t?`!(${r.description})`:`!${r.description}`:void 0,i={$not:r.spec};return new g(new T(r,{success:s(()=>{throw new u("Value must not match the specified condition")},"success"),failure:s(()=>!0,"failure")},[T.CHECK_TRUTHY]),i,n)},"build")}});var zo={};w(zo,{NUMBER_OPERATOR:()=>Pf});var Pf,Do=p(()=>{"use strict";se();h();Pf={keyword:"number",process:s(e=>{if(e===H)return 0;let r=Number(e);if(Number.isNaN(r)||!Number.isFinite(r))throw new u("Must be a number or convertible to a number");return r},"process")}});var Lo={};w(Lo,{NUMERIC_CONSTRAINT:()=>Tf});var Tf,Mo=p(()=>{"use strict";h();Tf={keyword:"numeric",process:s(e=>{let r=`${e}`;if(!/^[0-9]+$/.test(r))throw new u("Must contain only digits");return e},"process")}});var qo={};w(qo,{OBJECT_OPERATOR:()=>Of});var Of,Fo=p(()=>{"use strict";Ce();se();h();k();Of={keyword:"object",process:s(e=>{if(e===H&&(e={}),typeof e=="string")try{e=He(e)}catch(r){throw new u(`Invalid input string for object: ${y(e)}`,{cause:r})}if(Array.isArray(e)&&e.every(r=>Array.isArray(r)&&r.length===2))return Object.fromEntries(e);if(typeof e=="object")return e;throw new u(`Invalid input for object: ${y(e)}`)},"process")}});var Ho={};w(Ho,{OMIT_OPERATOR:()=>If});var If,Ko=p(()=>{"use strict";j();v();Te();q();h();If={keyword:"omit",build:s(e=>{if(!Array.isArray(e)||e.length===0)throw new m("$omit requires a non-empty array of key names");let r=B(e,t=>t.spec);return new N((t,n,i,o)=>{let a=Array.isArray(o.args)?o.args:[];if(typeof t!="object"||t===null)throw new u("$omit requires an object or array input",{location:i});return Array.isArray(t)?t.filter((c,f)=>!a.includes(f)):Object.fromEntries(Object.entries(t).filter(([c])=>!a.includes(c)))},new g(new oe(e),r))},"build")}});var yr,Bo=p(()=>{"use strict";Z();yr=class extends O{static{s(this,"ParallelExecutor")}#e;constructor(r=[]){super(),this.#e=r.map(t=>F(t))}execute(r,...t){let n=!1,i=this.#e.map(o=>{let a=o.execute(r,...t);return a instanceof Promise&&(n=!0),a});return n?Promise.all(i):i}}});var Wo={};w(Wo,{PARALLEL_OPERATOR:()=>_f});var _f,Yo=p(()=>{"use strict";Bo();j();h();q();_f={keyword:"parallel",build:s(e=>{if(!Array.isArray(e))throw new m("$parallel requires an array of processors");let r={$parallel:B(e,i=>i.spec)},t=e.map(i=>i.description).filter(i=>i!==void 0),n=t.length>0?t.map(i=>/[|&>·∧ ]/.test(i)?`(${i})`:i).join(" \u2297 "):void 0;return new g(new yr(e),r,n)},"build")}});var Zo={};w(Zo,{PASCAL_CASE_OPERATOR:()=>kf});var kf,Xo=p(()=>{"use strict";we();kf={keyword:"pascal-case",process:s(e=>zr(String(e)),"process")}});var vo={};w(vo,{PICK_OPERATOR:()=>Nf});var Nf,Go=p(()=>{"use strict";j();v();Te();q();h();Nf={keyword:"pick",build:s(e=>{if(!Array.isArray(e)||e.length===0)throw new m("$pick requires a non-empty array of key names");let r=B(e,t=>t.spec);return new N((t,n,i,o)=>{let a=Array.isArray(o.args)?o.args:[];if(typeof t!="object"||t===null)throw new u("$pick requires an object or array input",{location:i});if(Array.isArray(t))return a.filter(f=>f>=0&&f<t.length).map(f=>t[f]);let c={};for(let f of a)f in t&&(c[f]=t[f]);return c},new g(new oe(e),r))},"build")}});var es={};w(es,{PHONE_CONSTRAINT:()=>Vf});function Uf(e){let r=e.trim();return r.startsWith("+")?"+"+r.slice(1).replace(/\D/g,""):r.replace(/\D/g,"")}function Qo(e,r){let t=0;return r.replace(/#/g,()=>e[t++]??"")}var Jo,Vf,rs=p(()=>{"use strict";h();Jo={1:{lengths:[10],validate:/^[2-9]\d{2}[2-9]\d{6}$/,national:"(###) ###-####",international:"### ### ####"}};s(Uf,"stripFormatting");s(Qo,"applyTemplate");Vf={keyword:"phone",parameters:[{parameter:"international",type:"boolean",default:!1},{parameter:"country",default:"1"},{parameter:"countries",default:null}],process:s((e,r,t,n)=>{let{international:i,country:o,countries:a}=n.args,c=a?{...Jo,...a}:Jo,f=Uf(e);if(!f||!/^\+?\d+$/.test(f))throw new u("Invalid phone number format");let l,E="";if(f.startsWith("+")){let S=f.slice(1),A=!1;for(let d of[1,2,3]){if(d>S.length)break;let R=S.slice(0,d);if(c[R]){l=R,E=S.slice(d),A=!0;break}}if(!A){if(!i)throw new u(`Phone number country code does not match +${o}`);if(S.length<7||S.length>15)throw new u("Invalid phone number length");return"+"+S}}else{let S=c[o];if(l=o,S)if(S.lengths.map(d=>d+o.length).includes(f.length)&&f.startsWith(o))E=f.slice(o.length);else if(S.lengths.includes(f.length))E=f;else throw new u(`Invalid phone number length for country code +${o}`);else E=f}if(!i&&l!==o)throw new u(`International numbers not accepted; expected country code +${o}`);let x=c[l];if(x){if(!x.lengths.includes(E.length))throw new u(`Invalid phone number length for country code +${l}`);if(x.validate&&!x.validate.test(E))throw new u(`Invalid phone number for country code +${l}`)}else{let S=l.length+E.length;if(S<7||S>15)throw new u("Invalid phone number length")}return i?x?.international?`+${l} ${Qo(E,x.international)}`:`+${l}${E}`:x?.national?Qo(E,x.national):E},"process")}});var ts={};w(ts,{PIPELINE_OPERATOR:()=>jf});var jf,ns=p(()=>{"use strict";Ze();j();q();h();jf={keyword:"pipeline",build:s(e=>{if(!Array.isArray(e))throw new P("$pipeline requires an array of processors");let r=e.map(i=>i.description??"").filter(Boolean),t=r.length>1?r.map(i=>i.includes("|")||i.includes("&")?`(${i})`:i).join(" >> "):r[0],n={$pipeline:B(e,i=>i.spec)};return new g(new ce(e),n,t)},"build")}});var is={};w(is,{PORT_CONSTRAINT:()=>zf});var zf,os=p(()=>{"use strict";h();zf={keyword:"port",process:s((e,r,t)=>{let n=Number(e);if(!(Number.isInteger(n)&&n>=1&&n<=65535))throw new u("Port must be between 1 and 65535");return t.schema.options.type==="string"?`${n}`:n},"process")}});var ss={};w(ss,{POSITIVE_CONSTRAINT:()=>Df});var Df,as=p(()=>{"use strict";h();Df={keyword:"positive",process:s(e=>{if(typeof e!="number"||!Number.isFinite(e)||e<=0)throw new u("Must be a positive number");return e},"process")}});var cs={};w(cs,{PROCESS_OPERATOR:()=>Lf});var Lf,fs=p(()=>{"use strict";ne();h();k();Lf={keyword:"process",parameters:[{parameter:"schema",required:!0}],process:s((e,r,t,n)=>{let i=n.args.schema;if(!(i instanceof b))throw new m(`Schema argument must be an instance of CompiledSchema, got ${y(i)})`,{location:t});return i._process(e)},"process")}});var us={};w(us,{PROPERTY_OPERATOR:()=>Mf});var Mf,ms=p(()=>{"use strict";h();Mf={keyword:"property",parameters:[{parameter:"name",required:!0}],process:s((e,r,t,n)=>{let i=n.args.name;if(i===void 0)throw new m("$property expects a property name",{location:t});if(t.schema.getPropertySchema(i)===void 0)throw new m(`Unknown $property ${i}`,{location:t});return typeof e=="object"&&e!==null?e[i]:void 0},"process")}});var ps={};w(ps,{RANGE_CONSTRAINT:()=>qf});var qf,ds=p(()=>{"use strict";h();qf={keyword:"range",parameters:[{parameter:"min",type:"number",default:void 0},{parameter:"max",type:"number",default:void 0}],process:s((e,r,t,n)=>{let{min:i,max:o}=n.args,a=Number(e);if(!Number.isFinite(a))throw new u("Value must be a number");if(i!==void 0&&a<i)throw new u(`Value must be at least ${i}`);if(o!==void 0&&a>o)throw new u(`Value must be at most ${o}`);return e},"process"),describe:s(e=>{if(!e)return;let r=Array.isArray(e)?e[0]:e.min,t=Array.isArray(e)?e[1]:e.max,n=r?.description,i=t?.description;return n!==void 0&&i!==void 0?`${n}-${i}`:n!==void 0?`\u2265${n}`:i!==void 0?`\u2264${i}`:void 0},"describe")}});var ls={};w(ls,{REFERENCE_OPERATOR:()=>Ff});var Ff,hs=p(()=>{"use strict";te();h();Ff={keyword:"reference",parameters:[{parameter:"path",required:!0},{parameter:"pending",required:!1,default:!1},{parameter:"completed",required:!1,type:"boolean",default:!1}],process:s((e,r,t,n)=>{let i=n.args.path;if(i===void 0)throw new m("$reference expects a path");let o=n.state.getRelativeState(i),a=n.args.completed;if(o===void 0){if(a)return;let c=t.relative(i);return c?re(r,c.path):void 0}if(!(a&&!o.completed)){if(o.value!==void 0)return o.value;if(n.args.pending)return o.pending}},"process")}});var ws={};w(ws,{REQUIRE_CONSTRAINT:()=>Hf});var Hf,ys=p(()=>{"use strict";ae();j();Ae();Z();h();Hf={keyword:"require",build:s(e=>{let r;if(Array.isArray(e))if(e.length===1)r=e[0];else if(e.length===0)r=new g(new O,[]);else throw new m("$require requires no more than a single processor argument");else typeof e=="object"&&(r=e.processor);if(!(r instanceof U))throw new m("$require requires a processor argument");let t=e.length===0?"$require":{$require:r.spec},n=r.description;return new g(new T(r,{failure:s(i=>{throw i instanceof u?i:new u("Processed value was undefined",{cause:i})},"failure")},[T.CHECK_DEFINED,T.PASS_ERROR]),t,n)},"build")}});var gs={};w(gs,{REVERSE_OPERATOR:()=>Kf});var Kf,Es=p(()=>{"use strict";h();k();Kf={keyword:"reverse",process:s((e,r,t)=>{if(!Array.isArray(e))throw new u(`$reverse requires an array, got ${y(e)}`,{location:t});return[...e].reverse()},"process")}});var As={};w(As,{ROUND_OPERATOR:()=>Bf});var Bf,Ss=p(()=>{"use strict";Bf={keyword:"round",parameters:[{parameter:"precision",default:0}],process:s((e,r,t,n)=>{let i=n.args.precision,o=Math.pow(10,i),a=Number(e);return Number.isFinite(a)?Math.round(a*o)/o:e},"process")}});var xs={};w(xs,{NORMALIZE_OPERATOR:()=>Wf});var Wf,Cs=p(()=>{"use strict";ne();h();k();Wf={keyword:"normalize",parameters:[{parameter:"schema",required:!0},{parameter:"value",required:!1}],process:s((e,r,t,n={})=>{let i=n.args.schema;if(!(i instanceof b))throw new m(`Schema argument must be an instance of CompiledSchema, got ${y(i)})`,{location:t});let o=n.cycleCheck??new Set;if(o.has(t.schema))throw new m("Cycle detected while processing $normalize",{location:t,value:e});o.add(t.schema);let a=n.args.value??e;return i._normalizeValue(a,r,void 0,{cycleCheck:o})},"process")}});var $s={};w($s,{SEMVER_CONSTRAINT:()=>Jf});function nr(e){let r=Rs.exec(e.trim());if(!r)throw new P(`Invalid semver: "${e}"`);return{major:Number(r[1]),minor:Number(r[2]),patch:Number(r[3]),prerelease:r[4]?r[4].split("."):[],build:r[5]?r[5].split("."):[]}}function Yf(e,r){if(e.length===0&&r.length===0)return 0;if(e.length===0)return 1;if(r.length===0)return-1;let t=Math.max(e.length,r.length);for(let n=0;n<t;n++){if(n>=e.length)return-1;if(n>=r.length)return 1;let i=e[n],o=r[n];if(i===o)continue;let a=/^\d+$/.test(i),c=/^\d+$/.test(o);if(a&&!c)return-1;if(!a&&c)return 1;if(a&&c){let f=Number(i)-Number(o);if(f!==0)return f}else{if(i<o)return-1;if(i>o)return 1}}return 0}function de(e,r){return e.major-r.major||e.minor-r.minor||e.patch-r.patch||Yf(e.prerelease,r.prerelease)}function bs(e){let r=Zf.exec(e.trim());if(!r)throw new P(`Invalid semver comparator: "${e}"`);let t=r[1]||"=",n=nr(r[2]);switch(t){case"=":return i=>de(i,n)===0;case">":return i=>de(i,n)>0;case">=":return i=>de(i,n)>=0;case"<":return i=>de(i,n)<0;case"<=":return i=>de(i,n)<=0;default:throw new P(`Unknown semver operator: "${t}"`)}}function Xf(e){let r=nr(e),t;return r.major>0?t={major:r.major+1,minor:0,patch:0,prerelease:[],build:[]}:r.minor>0?t={major:0,minor:r.minor+1,patch:0,prerelease:[],build:[]}:t={major:0,minor:0,patch:r.patch+1,prerelease:[],build:[]},n=>de(n,r)>=0&&de(n,t)<0}function vf(e){let r=nr(e),t={major:r.major,minor:r.minor+1,patch:0,prerelease:[],build:[]};return n=>de(n,r)>=0&&de(n,t)<0}function Gf(e){let r=e.trim();if(r.startsWith("^"))return Xf(r.slice(1));if(r.startsWith("~"))return vf(r.slice(1));let t=r.split(/\s+/);if(t.length===1)return bs(t[0]);let n=t.map(bs);return i=>n.every(o=>o(i))}var Rs,Zf,Jf,Ps=p(()=>{"use strict";h();Rs=/^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/;s(nr,"parseSemVer");s(Yf,"comparePrerelease");s(de,"compareSemVer");Zf=/^(>=|<=|>|<|=)?\s*((?:0|[1-9]\d*)\.(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)(?:-(?:(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+(?:[0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?)$/;s(bs,"parseComparator");s(Xf,"parseCaret");s(vf,"parseTilde");s(Gf,"parseRange");Jf={keyword:"semver",parameters:[{parameter:"in",default:void 0,type:"string"},{parameter:"min",default:void 0,type:"string"},{parameter:"max",default:void 0,type:"string"}],process:s((e,r,t,n)=>{let i=Rs.exec(e);if(!i)throw new u("Invalid semver");let{in:o,min:a,max:c}=n?.args??{};if(o!==void 0&&(a!==void 0||c!==void 0))throw new P('$semver: "in" and "min"/"max" are mutually exclusive');let f={major:Number(i[1]),minor:Number(i[2]),patch:Number(i[3]),prerelease:i[4]?i[4].split("."):[],build:i[5]?i[5].split("."):[]};if(o!==void 0&&!Gf(o)(f))throw new u(`Version not in range "${o}"`);if(a!==void 0&&de(f,nr(a))<0)throw new u(`Version below minimum ${a}`);if(c!==void 0&&de(f,nr(c))>0)throw new u(`Version above maximum ${c}`);return e},"process"),describe:s(e=>{if(!e)return;let r=Array.isArray(e)?e[0]:e.in,t=Array.isArray(e)?e[1]:e.min,n=Array.isArray(e)?e[2]:e.max,i=r?.description,o=t?.description,a=n?.description;if(i!==void 0)return`in ${i}`;if(o!==void 0&&a!==void 0)return`${o}\u2013${a}`;if(o!==void 0)return`\u2265${o}`;if(a!==void 0)return`\u2264${a}`},"describe")}});var Ts={};w(Ts,{ALL_CONSTRAINT:()=>tu,AND_CONSTRAINT:()=>eu,ANY_CONSTRAINT:()=>ru,EXCLUSIVE_CONSTRAINT:()=>nu,FIRST_OPERATOR:()=>ou,ONE_CONSTRAINT:()=>iu,OR_CONSTRAINT:()=>Qf});function Ne(e,r,t){return n=>{let i;if(Array.isArray(n)?i=n:typeof n=="object"&&n!==null&&(i=Object.values(n)),!Array.isArray(i))throw new P(`${e} requires an array of processors`);let o={[e]:i.map(f=>f.spec)},a=i.map(f=>f.description).filter(f=>f!==void 0),c=a.length>1?a.map(f=>f.includes("&")?`(${f})`:f).join(r):a[0];return t(i,o,c)}}var Qf,eu,ru,tu,nu,iu,ou,Os=p(()=>{"use strict";Ae();j();kr();h();k();s(Ne,"generateBuilderFunction");Qf={keyword:"or",build:Ne("$or"," | ",(e,r,t)=>new g(new T(new _(e,[_.TRUTHY_CHECK,_.ANY_CRITERIA,_.RESULT_RETURN,_.CAPTURE_ERRORS]),{failure:s(n=>{throw new u(`None of the $or conditions ${y(t)} matched`,{value:n})},"failure")},[T.CHECK_TRUTHY]),r,t))},eu={keyword:"and",build:Ne("$and"," & ",(e,r,t)=>new g(new T(new _(e,[_.TRUTHY_CHECK,_.ALL_CRITERIA,_.RESULT_RETURN,_.CAPTURE_ERRORS]),{failure:s(n=>{throw new u(`Not all $and conditions ${y(t)} matched`,{value:n})},"failure")},[T.CHECK_TRUTHY]),r,t))},ru={keyword:"any",build:Ne("$any"," \u2227 ",(e,r,t)=>new g(new T(new _(e,[_.DEFINED_CHECK,_.ANY_CRITERIA,_.RESULT_RETURN,_.CAPTURE_ERRORS]),{failure:s(n=>{throw new u(`None of the $any conditions ${y(t)} succeeded`,{value:n})},"failure")},[T.CHECK_DEFINED]),r,t))},tu={keyword:"all",build:Ne("$all"," \xB7 ",(e,r,t)=>new g(new T(new _(e,[_.DEFINED_CHECK,_.ALL_CRITERIA,_.RESULT_RETURN,_.CAPTURE_ERRORS]),{failure:s(n=>{throw new u(`Not all $all conditions ${y(t)} succeeded`,{value:n})},"failure")},[T.CHECK_DEFINED]),r,t))},nu={keyword:"exclusive",build:Ne("$exclusive"," \u2295 ",(e,r,t)=>new g(new T(new _(e,[_.TRUTHY_CHECK,_.EXCLUSIVE_CRITERIA,_.RESULT_RETURN,_.CAPTURE_ERRORS]),{failure:s(n=>{throw new u(`Exactly one of the $exclusive conditions ${y(t)} must match`,{value:n})},"failure")},[T.CHECK_TRUTHY]),r,t))},iu={keyword:"one",build:Ne("$one"," \u2295 ",(e,r,t)=>new g(new T(new _(e,[_.DEFINED_CHECK,_.EXCLUSIVE_CRITERIA,_.RESULT_RETURN,_.CAPTURE_ERRORS]),{failure:s(n=>{throw new u(`Exactly one of the $one conditions ${y(t)} must succeed`,{value:n})},"failure")},[T.CHECK_DEFINED]),r,t))},ou={keyword:"first",build:Ne("$first"," ?? ",(e,r,t)=>new g(new T(new _(e,[_.DEFINED_CHECK,_.ANY_CRITERIA,_.RESULT_RETURN,_.CAPTURE_ERRORS]),{},[T.CHECK_DEFINED,T.PASS_RESULT]),r,t))}});var Is={};w(Is,{SORT_OPERATOR:()=>su});var su,_s=p(()=>{"use strict";h();k();su={keyword:"sort",parameters:[{parameter:"key",default:null},{parameter:"direction",default:"asc"}],process:s((e,r,t,n)=>{if(!Array.isArray(e))throw new u(`$sort requires an array, got ${y(e)}`,{location:t});let i=n.args?.key??null,o=n.args?.direction??"asc",a=s((f,l)=>typeof f=="number"&&typeof l=="number"?f-l:String(f)<String(l)?-1:String(f)>String(l)?1:0,"cmp"),c=[...e].sort(i?(f,l)=>a(f[i],l[i]):a);return o==="desc"?c.reverse():c},"process")}});var ks={};w(ks,{SPLIT_OPERATOR:()=>au});var au,Ns=p(()=>{"use strict";au={keyword:"split",parameters:[{parameter:"separator",default:","},{parameter:"limit",default:void 0}],process:s((e,r,t,n)=>{let i=n.args?.separator,o=n.args?.limit;return`${e}`.split(i,o)},"process")}});var Us={};w(Us,{PAD_OPERATOR:()=>uu,REPLACE_OPERATOR:()=>cu,SUBSTRING_OPERATOR:()=>fu});var cu,fu,uu,Vs=p(()=>{"use strict";h();k();cu={keyword:"replace",parameters:[{parameter:"pattern",required:!0},{parameter:"replacement",required:!0,type:"string"}],process:s((e,r,t,n)=>{let{pattern:i,replacement:o}=n.args;if(typeof i!="string"&&!(i instanceof RegExp))throw new m(`$replace pattern must be a string or RegExp, got ${y(i)}`);if(typeof o!="string")throw new m(`$replace replacement must be a string, got ${y(o)}`);if(typeof e!="string")throw new u(`$replace requires a string input, got ${y(e)}`,{location:t});return typeof i=="string"?e.replaceAll(i,o):e.replace(i,o)},"process")},fu={keyword:"substring",parameters:[{parameter:"start",required:!0,type:"number"},{parameter:"length",type:"number",default:void 0}],process:s((e,r,t,n)=>{if(typeof e!="string")throw new u(`$substring requires a string input, got ${y(e)}`,{location:t});let i=n.args.start,o=n.args.length;return o!==void 0?e.substring(i,i+o):e.substring(i)},"process")},uu={keyword:"pad",parameters:[{parameter:"width",required:!0},{parameter:"char",default:" "},{parameter:"side",default:"left"}],process:s((e,r,t,n)=>{if(typeof e!="string")throw new u(`$pad requires a string input, got ${y(e)}`,{location:t});let i=n.args.width,o=n.args.char;return n.args.side==="right"?e.padEnd(i,o):e.padStart(i,o)},"process")}});var js={};w(js,{STRING_OPERATOR:()=>mu});var mu,zs=p(()=>{"use strict";Ce();se();h();mu={keyword:"string",process:s(e=>{if(typeof e=="string")return e;if(e==null)throw new u("Invalid string",{value:e});return e===H?"":typeof e=="object"?e instanceof Date?e.toISOString():ye(e):String(e)},"process")}});var Ds={};w(Ds,{TARGET_OPERATOR:()=>pu});var pu,Ls=p(()=>{"use strict";pu={keyword:"target",process:s((e,r)=>r,"process")}});var Ms={};w(Ms,{TEMPLATE_OPERATOR:()=>du});var du,qs=p(()=>{"use strict";v();j();h();du={keyword:"template",build:s(e=>{let r=(Array.isArray(e)?e[0]:e)?.spec;if(typeof r!="string")throw new m("$template requires a string argument");let t=new N((n,i,o)=>{if(typeof n!="object"||n===null)throw new u("$template requires an object input",{location:o});return r.replace(/\{\{/g,"\0").replace(/\}\}/g,"").replace(/\{([^}]+)\}/g,(a,c)=>{let f=n[c];return f===void 0?"":String(f)}).replace(/\x00/g,"{").replace(/\x01/g,"}")});return t.description=r,new g(t,{$template:r})},"build")}});var Fs={};w(Fs,{TITLE_CASE_OPERATOR:()=>lu});var lu,Hs=p(()=>{"use strict";we();lu={keyword:"title-case",process:s(e=>Mr(String(e)),"process")}});var Ks={};w(Ks,{TYPE_OPERATOR:()=>hu});var hu,Bs=p(()=>{"use strict";ne();hu={keyword:"type",process:s(e=>e===null?"null":e===void 0?"undefined":e instanceof Date?"date":Array.isArray(e)?"array":e instanceof b?"schema":typeof e,"process")}});var Ws={};w(Ws,{TRIM_OPERATOR:()=>wu});var wu,Ys=p(()=>{"use strict";wu={keyword:"trim",process:s(e=>String(e).trim(),"process")}});var Zs={};w(Zs,{TRUTHY_CONSTRAINT:()=>yu});var yu,Xs=p(()=>{"use strict";he();h();yu={keyword:"truthy",process:s(e=>{if(Q(e))return e;throw new u("Must be truthy")},"process")}});var vs={};w(vs,{UNIQUE_OPERATOR:()=>gu});var gu,Gs=p(()=>{"use strict";h();k();gu={keyword:"unique",process:s((e,r,t)=>{if(!Array.isArray(e))throw new u(`$unique requires an array, got ${y(e)}`,{location:t});return[...new Set(e)]},"process")}});var Js={};w(Js,{UPPERCASE_OPERATOR:()=>Eu});var Eu,Qs=p(()=>{"use strict";Eu={keyword:"uppercase",process:s(e=>String(e).toUpperCase(),"process")}});var ea={};w(ea,{URL_CONSTRAINT:()=>Au});var Au,ra=p(()=>{"use strict";h();Au={keyword:"url",process:s(e=>{try{return new URL(e).toString()}catch{throw new u("Invalid URL format")}},"process")}});var ta={};w(ta,{URL_DECODE_OPERATOR:()=>Su});var Su,na=p(()=>{"use strict";h();k();Su={keyword:"url-decode",parameters:[{parameter:"full",default:!1}],process:s((e,r,t,n)=>{if(typeof e!="string")throw new u(`$url-decode requires a string, got ${y(e)}`,{location:t});let i=n.args?.full??!1;try{return i?decodeURI(e):decodeURIComponent(e)}catch(o){throw new u(`$url-decode: malformed URI sequence \u2014 ${o.message}`,{location:t,cause:o})}},"process")}});var ia={};w(ia,{URL_ENCODE_OPERATOR:()=>xu});var xu,oa=p(()=>{"use strict";xu={keyword:"url-encode",parameters:[{parameter:"full",default:!1}],process:s((e,r,t,n)=>n.args?.full??!1?encodeURI(`${e}`):encodeURIComponent(`${e}`),"process")}});var sa={};w(sa,{UUID_CONSTRAINT:()=>Cu});var Cu,aa=p(()=>{"use strict";h();Cu={keyword:"uuid",process:s(e=>{if(!/^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(e))throw new u("Invalid UUID format");return e},"process")}});var ca={};w(ca,{VALUES_OPERATOR:()=>bu});var bu,fa=p(()=>{"use strict";h();k();bu={keyword:"values",process:s((e,r,t)=>{if(typeof e!="object"||e===null||Array.isArray(e))throw new u(`$values requires a plain object, got ${y(e)}`,{location:t});return Object.values(e)},"process")}});ne();J();ne();J();Fe();xr();ae();h();ae();h();q();function je(e){if(typeof e=="string"&&e.charAt(0)==="$")return!0;if(typeof e=="object"&&e!==null){let r=Object.keys(e);if(r.length===1&&r[0].charAt(0)==="$")return!0}return!1}s(je,"isKeywordValueProcessorSpec");function Nt(e){let r,t=[];if(typeof e=="string"&&e.charAt(0)==="$")r=e.slice(1);else if(typeof e=="object"&&e!==null){let n=Object.keys(e);n.length===1&&n[0].charAt(0)==="$"&&(r=n[0].slice(1),t=e[n[0]])}if(!r)throw new m("Not a keyword operation");return[r,t]}s(Nt,"extractKeywordValueProcessorSpec");function fr(e){if(e==null)return!1;if(e instanceof U)return!0;if(Array.isArray(e)){for(let r=0;r<e.length;++r)if(!fr(e[r]))return!1;return!0}if(M(e)){let r=0;for(let t of Object.keys(e))if(t.charAt(0)==="$"&&r++,r>1||t!=="$literal"&&!fr(e[t]))return!1;return!0}return!0}s(fr,"isLegalValueProcessorSpec");J();h();te();k();function Ut(e,r,t){if(!e.isUnion)return e;let n=Array.from(e.propertyEntries).filter(S=>S[1].isUnionKey);if(n.length===0)return e;if(n.length>1)throw new I(`Union schema has multiple properties marked as union keys: ${n.map(S=>S[0]).join(", ")}`,{location:t});let i=n[0][0],o=n[0][1],a=t.relative(i),c=[...e.unionSchemaEntries],f=new Set;for(let[S]of c)f.add(o._normalizeValue(S,void 0,void 0,{sync:!0}));if(f.size!==c.length)throw new I("Union keys must not collide after normalization with the unionKey property schema",{location:t});let l=(o.values??[]).sort(),E=[...f].sort();if(l.length>0){if(!G(l,E))throw new I(`Union key schema values {${l.join("|")}} do not include all possible union keys {${E.join("|")}}`,{location:a})}else{if(o.isSelector)throw new I("Cannot populate values for a schema that is both a selector and a union key",{location:a});o.options.values=E}if(Array.isArray(e.handlers.discriminators)&&e.handlers.discriminators.length>0)return e;let x=this;return e.handlers.discriminators=[x.resolver.compileValueProcessorSpec(x,Na(e,i))],e}s(Ut,"synthesizeKeyDiscrimination");function Vt(e,r,t,n){if(!e.isUnion||Array.isArray(e.handlers.discriminators)&&e.handlers.discriminators.length>0||e.hasValues)return e;let i=this,o=Dt(e);for(let[a,c]of o){if(e.getPropertySchema(a))continue;if(c.size===1){let[R]=c,$=R.getPropertySchema(a);if($&&!$.hasConditions&&!$.required&&$.default===void 0){e._setPropertySchema(a,$);continue}}let f,l=new Set,E=!0,x,S=!0;for(let R of c){let $=R.getPropertySchema(a);if($){if(x||(x=$.handlers.normalizers),$.metadata.parserTypeHint&&(f===void 0?f=$.metadata.parserTypeHint:f&&f!==$.metadata.parserTypeHint&&(f="any",E=!1)),!$.hasValues){S=!1;continue}for(let V of $.values??[]){let Y=$._normalizeValue(V,void 0,void 0,{sync:!0});E&&Y!==V&&(E=!1),l.add(Y),f===void 0&&i.resolver.hasSchema(typeof V)&&(f=typeof V)}}}let A=E&&x,d=new C(f??"any");if(A&&x)for(let R of x)d.normalizer(R);l.size>0&&(d.values(Array.from(l)),S||d.option("allowUnknownValues",!0)),e._setPropertySchema(a,this.compile(d))}return e.handlers.discriminators=[i.resolver.compileValueProcessorSpec(i,ka(e))],e}s(Vt,"synthesizeAutoDiscrimination");function jt(e){if(!e.isUnion||e.hasValues)return e;let r=new Set,t=!0;for(let[,n]of e.unionSchemaEntries){if(!n.hasValues){t=!1;continue}for(let i of n.values)r.add(i)}return r.size===0||(e.options.values=[...r],t||(e.options.allowUnknownValues=!0)),e}s(jt,"synthesizeUnionValues");function zt(e){if(!e.isUnion)return e;for(let[r,t]of e.unionSchemaEntries){let n=["values","type","default"];for(let[i,o]of Object.entries(e.options??{}))n.includes(i)||o!==void 0&&t.options[i]===void 0&&(t.options[i]=o)}return e}s(zt,"copyUnionOptions");function Dt(e){let r=Array.from(e.unionSchemaEntries).map(a=>a[1]),t=new Map;for(let a of r){let c=!1;for(let[f,l]of a.propertyEntries)Array.isArray(l.values)&&l.values.length>0&&(t.has(f)||t.set(f,new Set),t.get(f).add(a),c=!0);if(!c){let f=e.findUnionKey(a)}}let n=new Set,i=new Set;for(let a=0;a<r.length;a++){let c=r[a];for(let[f,l]of c.propertyEntries){if(t.has(f)||i.has(f)||n.has(f))continue;if(l.default!==void 0){n.add(f);continue}let E=!0;for(let x=a+1;x<r.length;x++)if(r[x].getPropertySchema(f)){i.add(f),E=!1;break}E&&t.set(f,new Set([c]))}}for(let a of t.keys())n.has(a)&&t.delete(a);let o=new Set;for(let a=0;a<r.length;a++)for(let c=a+1;c<r.length;c++){let f=r[a],l=r[c],E=!1,x=!0;for(let[S,A]of t){if(A.forEach(xe=>o.add(xe)),!A.has(f)||!A.has(l))continue;x=!1;let d=f.getPropertySchema(S),R=l.getPropertySchema(S),$=d?.values??[],V=R?.values??[];if(!$.some(xe=>V.includes(xe))){E=!0;break}}if(!E&&!x)throw new I("Union members are indistinguishable (cannot discriminate between schemas)")}if(r.length>1&&o.size!==r.length){for(let a of r)if(!o.has(a))throw new I(`Union member ${y(e.findUnionKey(a))} cannot be uniquely discriminated`)}return t}s(Dt,"findDiscriminatorProperties");function ka(e){if(!e.isUnion)throw new I("Can only generate a discriminator for a union");let r=Array.from(e.unionSchemaEntries).map(i=>i[1]),t=Dt(e);function n(i,o,a,c){let f=new Set(r),l=!1;for(let[E,x]of t){let S=i?.[E];if(S!==void 0){if(x.size===1){let[A]=x;if(f.has(A))f=new Set([A]);else if(f=new Set,f.size===0)throw new le("Union resolution conflict with",{property:E,location:a,value:S})}for(let A of x){if(!f.has(A))continue;let d=a.union(A)?.relative(E);if(d!==void 0){if(d.schema.checkAccepts(S))l=!0;else if(f.delete(A),f.size===0)throw new le("Union resolution conflict with",{property:E,value:S,location:a})}}}}if(f.size===1&&l)return Array.from(f)[0];if(f.size<=1){if(c?.strict||c?.context?.final)throw new le("Union resolution failure (no matches)",{location:a});return}else{if(c?.strict||c?.context?.final){let E=Array.from(f).map(x=>e.findUnionKey(x)).join("|");throw new le(`Union resolution ambiguity (could be ${E})`,{location:a})}return}}return s(n,"discriminator"),n}s(ka,"generateAutomaticDiscriminatorFunction");function Na(e,r){if(!e.getPropertySchema(r))throw new m(`Discriminator property ${r} not found`);function n(i,o,a){return i?.[r]}return s(n,"discriminator"),n}s(Na,"generatePropertyValueDiscriminatorFunction");h();function Lt(e,r,t){let n=[],i=[];for(let E of e.propertyEntries)E[1].isSelector&&n.push(E),E[1].isSelection&&i.push(E);if(n.length===0&&i.length===0)return e;if(n.length>1)throw new I(`Schema multiple properties marked as selectors: ${n.map(E=>E[0]).join(", ")}`,{location:t});let o=n[0][0],a=n[0][1],c=t.relative(`properties.${o}`);if(i.length===0)throw new I(`Schema has selector at property ${o} but no selections`,{location:t});let f=new Set([...a.values??[]]),l=new Set;for(let E of i){let x=E[0],S=E[1],A=t.relative(`properties.${x}`),d=S.selection;d===!0&&(d=x);let R=a._normalizeValue(d,void 0,void 0,{sync:!0});if(f.size&&!f.has(R))throw new I(`Existing selector schema values {${[...f].join("|")}} are missing selection`,{value:d,location:c});l.add(R)}if(!a.hasValues){if(a.isUnionKey)throw new I("Cannot populate values for a schema that is both a selector and a union key",{location:c});a.options.values=[...l].sort()}return e}s(Lt,"populateChildSelectorValues");k();function Mt(e){if(!e.metadata.validatorDescription&&e.handlers.validators?.length){let r=e.handlers.validators.map(t=>t.description??"").filter(Boolean);e.metadata.validatorDescription=r.length>1?r.map(t=>t.includes("|")||t.includes("&")?`(${t})`:t).join(" >> "):r[0]}if(!e.metadata.valueDescription){let r=or(e);e.metadata.valueDescription=e.required?`<${r}>`:`[${r}]`}return e.metadata.valueName||(e.metadata.valueName=e.metadata.parserTypeHint??"value"),e.options.default!==void 0&&e.metadata.defaultValueDescription===void 0&&(typeof e.options.default=="function"?e.metadata.defaultValueDescription="":e.metadata.defaultValueDescription=y(e.options.default)),e}s(Mt,"populateMetadata");ne();h();function Ur(e,r,t){if(e===!0)return{};if(e instanceof b)return e;if(this.normalizeCache.has(e))return this.normalizeCache.get(e);let n={};this.normalizeCache.set(e,n),e=this.resolver.resolve(e,!1);for(let i of["properties","unionSchemas","metadata","options","handlers"])if(e[i])for(let[o,a]of Object.entries(e[i])){if(a===void 0)continue;n[i]===void 0&&(n[i]={});let c=a;i==="handlers"&&a===null&&(c="$null"),n[i][o]=c}return n}s(Ur,"normalizeSchema");function qt(e,r,t,n){if(e instanceof b)return e;let i=new b(b.__TOKEN);this.compileCache.set(n.state.assignedInput,i);for(let[o,a]of Object.entries(e.properties??{}))if(a instanceof b)i._setPropertySchema(o,a);else throw new I(`Failed to compile property "${o}" schema`,{location:t});for(let[o,a]of Object.entries(e.unionSchemas??{}))if(a instanceof b)i._setUnionSchema(o,a);else throw new I(`Failed to compile union "${o}" schema `,{location:t});return Object.assign(i.handlers,e.handlers),Object.assign(i.metadata,e.metadata),Object.assign(i.options,e.options),i}s(qt,"transformSchema");function Ft(e,r,t){if(!(e instanceof b))throw new I("Not a schema",{location:t});if(e.isUnion&&!e.handlers.discriminators)throw new I("No discriminator defined for union",{location:t});if(e.hasChildren&&(!e.options.container||e.options.type!=="object"&&e.options.type!=="array"&&e.options.type!=="any"))throw new I("Schema defines child properties but does not identify as a container",{location:t});if(e.isUnion&&e.hasWildcard)throw new I("Wildcard properties cannot be set on a union",{location:t});if(e.hasChildSelector!==e.hasChildSelection)throw new I("Inconsistently defined selector/selections in properties",{location:t});if(t.path===""){if(e.isSelector)throw new I("The root schema cannot be a selector",{location:t});if(e.isSelection)throw new I("The root schema cannot be a selection",{location:t});if(e.isUnionKey)throw new I("The root schema cannot be a union key",{location:t})}return e}s(Ft,"validateSchema");q();function Ht(e,r,t,n){let i=this;for(let o of Object.keys(e.handlers)){let a=e.handlers[o];K(a)||e._setValueProcessor(o,this.resolver.compileValueProcessorSpec(i,a.length===1?a[0]:{$pipeline:a},!0))}return e}s(Ht,"compileHandlers");h();q();function Kt(e,r,t){let n=e.options.values??[];if(K(e.options.values))return e;let i=new Set,o=0;for(;o<n.length;){let a=e._normalizeValue(n[o++],void 0,void 0,{sync:!0});if(a===void 0)throw new I("Undefined after normalizing",{value:a,location:t});i.add(a)}return i.size&&(e.options.values=[...i]),e}s(Kt,"normalizeValues");q();var ge=class extends b{static{s(this,"CachedSchemaReference")}constructor(r){super(b.__TOKEN),this.schema=r}},ze=class extends b{static{s(this,"SchemaCompiler")}constructor(r){super(b.__TOKEN),this.resolver=r,this.normalizeCache=new Map,this.compileSeen=new Map,this.compileCache=new Map;let t=this,n=new C("any").option("dynamic",!1).opaque().validator((d,R,$)=>{if(!(d instanceof U))throw new I("Failed to compile to a value processor",{location:$});return d}),i=new C(n).transformer(d=>r.compileKeywordValueProcessorSpec(this,d)),o=new C(n).property("$literal",new C("any")).transformer(d=>r.compileKeywordValueProcessorSpec(this,d)),a=new C(n).transformer(d=>r.compileValueProcessorSpec(this,d)),c=new C(n).normalizer(d=>d===null?"$null":d).unionDiscriminator(d=>{if(d instanceof U||d==null)return"general";if(!K(d))return je(d)?typeof d=="string"?"keyword":"keyword+args":"general"}).unionSchema("keyword",i).unionSchema("keyword+args",o).unionSchema("general",a),f=new C("any").option("dynamic",!1).unionDiscriminator(d=>{if(Array.isArray(d))return"array";if(je(d))return"spec";if(!K(d))return M(d)?"object":"spec"}).unionSchema("spec",c).unionSchema("array",new C("array").allowEmpty().transformer(d=>d).property("*",c)).unionSchema("object",new C("object").allowEmpty().transformer(d=>d).property("*",c));o.property("*",f);let l=new C("array").property("*",c),E=new C().meta("compiler","root").required().normalizer((d,R,$)=>this.compileSeen.has(d)&&this.compileSeen.get(d)!==$.path?new ge(d):(d instanceof b||this.compileSeen.set(d,$.path),d)).normalizer(Ur.bind(this)).unionDiscriminator((d,R,$,V)=>d instanceof ge||this.compileSeen.has(d)?"cache":d instanceof b?"reference":typeof d=="object"?"schema":void 0).unionSchema("reference",new C().meta("compiler","reference").required().normalizer(d=>{if(!(d instanceof b))throw new I("Not a CompiledSchema reference!");return d})).unionSchema("cache",new C().meta("compiler","cache").required().normalizer(d=>{if(d instanceof ge)return d;if(!(d instanceof C))throw new I("Can only cache references to schemas");return new ge(d)})),x=new C("object").meta("compiler","schema").opaque().required().normalizer(Ur.bind(this)).normalizer((d,R,$,V)=>{if(d instanceof b)return d;if(typeof d=="object"){if(d instanceof C)throw new I("Internal compiler error");return d}else throw new m("not a schema")}).transformer(qt.bind(this)).finalizer({$if:[(d=>d.isUnion),{$pipeline:[jt,Ut,Vt,zt].map(d=>d.bind(this))},"$input"]}).finalizer(Ht.bind(this)).finalizer({$if:[(d=>!K(d.options.values)),Kt.bind(this),"$defined"]}).finalizer({$if:[(d=>d.hasChildSelector||d.hasChildSelection),Lt,"$defined"]}).finalizer(Mt).finalizer((d,R,$)=>{if($.path!=="")return d;if(!(d instanceof b))throw new I("Schema failed to compile!");return this._replaceCachedReferences(d),d._freeze(),d}).validator(Ft.bind(this)).property("properties",new C("object").property("*",E)).property("unionSchemas",new C("object").property("*",E)).property("metadata",new C("object").property("*",new C("string"))).property("options",new C("object").property("compileHook",new C("function")).property("default",new C("any").option("dynamic",!1)).property("values",new C("array")).property("*",new C("any"))).property("handlers",new C("object").property("normalizers",l).property("transformers",l).property("finalizers",l).property("validators",l).property("serializers",l).property("conditions",l).property("discriminators",l));E.unionSchema("schema",x);let S=new Map;function A(d,R){if(S.has(d))return S.get(d);if(d instanceof b)return d;R===void 0&&(R=new b(b.__TOKEN)),S.set(d,R),S.set(R,R),Object.assign(R.options,d.options),Object.assign(R.metadata,d.metadata);for(let[$,V]of Object.entries(d.handlers))R.handlers[$]=V.map(Y=>r.compileValueProcessorSpec(t,Y,!0)),R._setValueProcessor($,r.compileValueProcessorSpec(t,{$pipeline:R.handlers[$]}));for(let[$,V]of Object.entries(d.properties))(V instanceof C||V instanceof b)&&R._setPropertySchema($,A(V));for(let[$,V]of Object.entries(d.unionSchemas))(V instanceof C||V instanceof b)&&R._setUnionSchema($,A(V));return R}s(A,"compileSchemaCompiler"),A(r.resolve(E),this)}get hasChildren(){return!0}_replaceCachedReferences(r,t="",n=new Set){if(!n.has(r)){n.add(r);for(let[i,o]of r.propertyEntries){let a=t?`${t}.${i}`:i,c=o instanceof ge?this.compileCache.get(o.schema):o;if(c===void 0)throw new I("Unable to find cached CompiledSchema",{path:a});c!==o&&(c.metadata.references??="",c.metadata.references+=`[${a}]`,r._setPropertySchema(i,c)),this._replaceCachedReferences(c,a,n)}for(let[i,o]of r.unionSchemaEntries){let a=o instanceof ge?this.compileCache.get(o.schema):o;if(a===void 0)throw new I(`Unable to find cached CompiledSchema for unionSchema "${i}"`,{path:t});a!==o&&(a.metadata.references??="",a.metadata.references+=`[${t}:${i}]`,r._setUnionSchema(i,a)),this._replaceCachedReferences(a,t,n)}}}compile(r){try{let t=new me(new z(this));t.compiling=!0;let n=this._process(r,void 0,{context:t});if(n instanceof Promise)throw new I("Encountered an async processor during compilation");return n}catch(t){throw t instanceof I?t:(t instanceof ue||t instanceof X||t instanceof ee||t instanceof D)&&t.cause?new I(t.cause.message,{...t.data,...t.cause.data,cause:t.cause}):new I("Error during compilation",{cause:t})}}};Z();v();j();ae();De();Te();j();Te();De();Vr();v();ur();h();q();ne();var Je=class extends Ee{static{s(this,"DefinedValueProcessor")}constructor(r,t){if(!r.keyword)throw new m("No keyword found in processor definition");if(!r.process)throw new m("No process function found in processor definition");if(r.build)throw new I("Internal compiler error: factory definitions unsupported by DefinedValueProcessor");if(r instanceof b)throw new I("Internal compiler error: a CompiledSchema was incorrectly identified as a DefinedValueProcessor");let n,i;if(r.parameters!==void 0)n=new Le(r.parameters,t),i={[`$${r.keyword}`]:n.spec};else if(K(t))i=`$${r.keyword}`;else{let a=B(t,c=>c.spec);if(Array.isArray(t))n=new g(new oe(t),a);else if(typeof t=="object")n=new g(new fe(t),a);else throw new I("Internal compiler error: unsupported keyword arguments type");i={[`$${r.keyword}`]:n.spec}}let o=r.description??r.describe?.(t)??`${r.keyword}`;super(new N(r.process),n,i,o)}};h();we();q();er();var Bt=[];function Wt(e){Bt.push(e)}s(Wt,"registerCoreLibrary");var qr=class{static{s(this,"SchemaResolver")}#e=new Map;#r=new Map;#t=new Map;constructor(){for(let r of Bt)this.use(r,{sync:!0})}registerSchema(r,t){if(!(t instanceof C))throw new P("Registry can only store Schema instances");let n=Oe(r);return this.#e.set(n,{name:n,schema:t}),this}getSchema(r){let t=Oe(r),n=this.#e.get(t);if(!n)throw new P(`Unable to resolve "${r}"`);return n.schema}hasSchema(r){let t=Oe(r);return this.#e.has(t)}listRegisteredSchemas(){return[...this.#e.values()]}registerValueProcessorDefinition(r){let{keyword:t,process:n,description:i,build:o}=r;if(!t||typeof t!="string")throw new P("Missing keyword in processor definition");if(n&&o)throw new P(`Processor definition for '$${t}' cannot define both process and build functions`);if(!n&&!o)throw new P(`Processor definition for '$${t}' must have define a process or build function`);if(i&&typeof i!="string")throw new P(`Processor definition description for '$${t}' must be a string`);if(this.#n[`${t}`])throw new P(`Processor keyword conflict with builtin literal '$${t}'`);return this.#r.set(t,r),this}registerValueProcessor(r,t,n){if(typeof t!="function")throw new P(`Processor for keyword '${r}' must be a function`);return this.registerValueProcessorDefinition({keyword:r,parameters:[],process:t,description:n??r})}registerValueProcessorBuilder(r,t){if(typeof t!="function")throw new P(`Processor builder for keyword '${r}' must be a function`);return this.registerValueProcessorDefinition({keyword:r,build:t})}listValueProcessorDefinitions(){return[...Object.entries(this.#n).map(([r,t])=>({keyword:r,build:s((()=>t),"build"),spec:`$${r}`,reserved:!0})),...this.#r.values()]}async use(r,t={}){try{let n=r(this,t);if(n instanceof Promise&&t.sync)throw new P("Cannot load async library");return await n}catch(n){throw n instanceof P?n:new P("Error loading library",{cause:n})}}#n={null:new g(Er,"$null"),undefined:new g(Ve,"$undefined"),true:new g(Jr,"$true"),false:new g(Qr,"$false")};compileKeywordValueProcessorSpec(r,t,n){if(!je(t))throw new P("Not a keyword processor spec");let[i,o]=Nt(t);if(this.#n[i])return this.#n[i];if(i==="literal")return new g(new W(o),t);let a=this.#r.get(i);if(!a)throw new P(`Unknown processor keyword: $${i}`);let c=B(o,f=>this.compileValueProcessorSpec(r,f,n));if(a.build){let f=a.build(c,{compiler:r});if(f?.process)return this.compileValueProcessorSpec(r,f,n);if(!(f instanceof U))throw new m(`ValueProcessor builder for $${i} returned invalid`,{value:f});return f}return new Je(a,c)}compileSchemaValueProcessorSpec(r,t){let n;return r.compileCache.has(t)?new g(new W(r.compileCache.get(t)),t):new g(new Ye(async()=>r.compileCache.has(t)?r.compileCache.get(t):(n??=t instanceof b?t:await r.compile(t),n)),t)}compileValueProcessorSpecObject(r,t,n=!1){if(typeof t!="object")throw new P("not a spec object");let i={};for(let[o,a]of Object.entries(t))i[o]=this.compileValueProcessorSpec(r,a,n);return new g(new fe(i),B(i,o=>o.spec))}compileValueProcessorSpecArray(r,t,n=!1){if(!Array.isArray(t))throw new P("not a spec array");let i=[];for(let o=0;o<t.length;++o)i[o]=this.compileValueProcessorSpec(r,t[o],n);return new g(new oe(i),B(i,o=>o.spec))}compileValueProcessorSpec(r,t,n=!1){if(!fr(t))throw new m("Invalid value processor specification",{value:t});let i;if(t===void 0)i=new U;else if(t===null)t="$null",i=new g(Er,"$null");else if(t==="$resolver")i=new g(new W(this),t);else if(t==="$compiler")i=new g(new W(r),t);else if(t instanceof U)i=t;else if(t instanceof C)i=this.compileSchemaValueProcessorSpec(r,t);else if(t instanceof b)i=new g(new W(t),t);else if(je(t))i=this.compileKeywordValueProcessorSpec(r,t,n);else if(t instanceof O)i=new g(t,t);else if(t instanceof RegExp)i=new g(new W(t),t,`${t}`);else if(t instanceof Date)i=new g(new W(t),t,t.toISOString());else if(typeof t=="string"&&t.startsWith("/")&&t.lastIndexOf("/")>0)try{let o=Ie(t);i=new g(new W(o),o,`${o}`)}catch{throw new m("Invalid regex pattern",{value:t})}else t instanceof ze?i=new g(new W(t),t):typeof t=="object"&&typeof t.process=="function"?i=new Je(t):gr(t)?i=new g(new W(t),t,t.name):typeof t=="function"?i=new N(t):Array.isArray(t)?i=this.compileValueProcessorSpecArray(r,t,n):typeof t=="object"?i=this.compileValueProcessorSpecObject(r,t,n):i=new g(F(t),t);return i.spec===void 0&&(i.spec=t),i}compiler(){return new ze(this)}compile(r){return r instanceof b?r:new ze(this).compile(r)}resolve(r,t=!0){if(r instanceof b)return r;if(typeof r=="string"&&(this.hasSchema(r)?r=this.getSchema(r):r=new C(r)),this.#t.has(r))return this.#t.get(r);let n=new C;this.#t.set(r,n),this.#t.set(n,n);let i=r,o,a=!1;for(;i!==void 0;){for(let[c,f]of Object.entries(i.properties??{}))if(!n.properties.hasOwnProperty(c)){let l=t||!(f instanceof C||f instanceof b);n.properties[c]=l?this.resolve(f):f}for(let[c,f]of Object.entries(i.metadata??{}))n.metadata.hasOwnProperty(c)||(n.metadata[c]=f);for(let[c,f]of Object.entries(i.unionSchemas??{}))if(!n.unionSchemas.hasOwnProperty(c)){let l=t||!(f instanceof C||f instanceof b);n.unionSchemas[c]=l?this.resolve(f):f}for(let[c,f]of Object.entries(i.handlers??{}))n.handlers.hasOwnProperty(c)||(n.handlers[c]=[]),n.handlers[c].unshift(...f);for(let[c,f]of Object.entries(i.options??{}))n.options.hasOwnProperty(c)||(n.options[c]=f,c==="type"&&(a=!0));if(i instanceof b)i=void 0;else if(i.base===void 0&&!a&&(i.base="any"),i.base)if(this.hasSchema(i.base))i=this.getSchema(i.base);else{let c=`${i.base}`;o=new P(`Unable to resolve "${c}"`),n.normalizer((f,l,E,x)=>{if((E.schema?.strict??x?.strict)!==!1)throw o}),i=void 0}else i=void 0}if(!(r instanceof b)&&r.base&&!n.metadata.parserTypeHint&&(n.metadata.parserTypeHint=r.base),n.options.strict!==!1&&o)throw o;return n}};J();ne();var Ma=/^[\d*]/;function mr(e){let r=e instanceof b?e.propertyEntries:Object.entries(e.properties??{});for(let[n]of r)if(!Ma.test(n))return!0;let t=e instanceof b?e.unionSchemaEntries:Object.entries(e.unionSchemas??{});for(let[n,i]of t)if(mr(i))return!0;return!1}s(mr,"hasStringProperties");se();function Yt(e,r,t){let n=t.schema;return e===H&&n.isContainer?!n.isArray&&mr(n)?{}:[]:e}s(Yt,"anyValueProcessor");var Zt=new C().option("type","any").normalizer(Yt).transformer(Yt);J();var Xt=new C().option("type","string").meta("valueName","string").normalizer("$string").validator("$is-string");J();var vt=new C().option("type","number").meta("valueName","number").normalizer("$number").validator("$is-number");J();he();var Gt=new C().option("type","boolean").meta("valueName","boolean").normalizer(Q).validator({$in:[!0,!1]});J();var Jt=new C().option("type","object").option("container",!0).meta("valueName","object").normalizer("$object").validator("$is-object");J();var Qt=new C().option("type","array").option("container",!0).normalizer("$array").validator("$is-array");J();var en=new C().option("type","date").meta("parserTypeHint","string").meta("valueName","date").meta("valueDescription",'ms|iso date|"now"|[+|-]offset[d|h|m|s|ms]').normalizer("$date").transformer("$date").validator("$is-date").serializer("$is-date").serializer("$string");J();te();h();var rn=new C().option("type","function").meta("parserTypeHint","string").meta("hidden").meta("internal").meta("omitFromSerialize").option("dynamic",!1).normalizer(e=>{if(typeof e=="function"||typeof e=="string")return e;throw new u("Invalid function",{value:e})}).transformer((e,r)=>{if(typeof e=="string"&&(e=re(r,e)),typeof e=="function")return e;throw new u("Invalid function",{value:e})}).validator(e=>{if(typeof e=="function")return e;throw new u("Invalid function",{value:e})}).serializer(e=>{if(typeof e=="function")return e.name;throw new u("Invalid function",{value:e})});J();var tn=new C().default(!0).meta("hidden").meta("internal").meta("omitFromSerialize").normalizer(()=>"root-schema").transformer((e,r,t)=>{for(;t?.parent;)t=t.parent;return t?.schema}).serializer((e,r,t)=>{for(;t?.parent;)t=t.parent;return t?.schema.toData()});var ua;try{ua??=await Promise.all([Promise.resolve().then(()=>(on(),nn)),Promise.resolve().then(()=>(an(),sn)),Promise.resolve().then(()=>(fn(),cn)),Promise.resolve().then(()=>(mn(),un)),Promise.resolve().then(()=>(dn(),pn)),Promise.resolve().then(()=>(hn(),ln)),Promise.resolve().then(()=>(yn(),wn)),Promise.resolve().then(()=>(En(),gn)),Promise.resolve().then(()=>(xn(),Sn)),Promise.resolve().then(()=>(bn(),Cn)),Promise.resolve().then(()=>($n(),Rn)),Promise.resolve().then(()=>(Tn(),Pn)),Promise.resolve().then(()=>(_n(),In)),Promise.resolve().then(()=>(Nn(),kn)),Promise.resolve().then(()=>(Vn(),Un)),Promise.resolve().then(()=>(zn(),jn)),Promise.resolve().then(()=>(Ln(),Dn)),Promise.resolve().then(()=>(qn(),Mn)),Promise.resolve().then(()=>(Hn(),Fn)),Promise.resolve().then(()=>(Bn(),Kn)),Promise.resolve().then(()=>(Yn(),Wn)),Promise.resolve().then(()=>(Xn(),Zn)),Promise.resolve().then(()=>(Gn(),vn)),Promise.resolve().then(()=>(Qn(),Jn)),Promise.resolve().then(()=>(ri(),ei)),Promise.resolve().then(()=>(ni(),ti)),Promise.resolve().then(()=>(oi(),ii)),Promise.resolve().then(()=>(ai(),si)),Promise.resolve().then(()=>(fi(),ci)),Promise.resolve().then(()=>(mi(),ui)),Promise.resolve().then(()=>(di(),pi)),Promise.resolve().then(()=>(hi(),li)),Promise.resolve().then(()=>(yi(),wi)),Promise.resolve().then(()=>(Ei(),gi)),Promise.resolve().then(()=>(Si(),Ai)),Promise.resolve().then(()=>(Ci(),xi)),Promise.resolve().then(()=>(Ri(),bi)),Promise.resolve().then(()=>(Pi(),$i)),Promise.resolve().then(()=>(Oi(),Ti)),Promise.resolve().then(()=>(_i(),Ii)),Promise.resolve().then(()=>(Ni(),ki)),Promise.resolve().then(()=>(Vi(),Ui)),Promise.resolve().then(()=>(zi(),ji)),Promise.resolve().then(()=>(Li(),Di)),Promise.resolve().then(()=>(qi(),Mi)),Promise.resolve().then(()=>(Hi(),Fi)),Promise.resolve().then(()=>(Bi(),Ki)),Promise.resolve().then(()=>(Yi(),Wi)),Promise.resolve().then(()=>(Xi(),Zi)),Promise.resolve().then(()=>(Gi(),vi)),Promise.resolve().then(()=>(Qi(),Ji)),Promise.resolve().then(()=>(ro(),eo)),Promise.resolve().then(()=>(no(),to)),Promise.resolve().then(()=>(oo(),io)),Promise.resolve().then(()=>(ao(),so)),Promise.resolve().then(()=>(fo(),co)),Promise.resolve().then(()=>(mo(),uo)),Promise.resolve().then(()=>(lo(),po)),Promise.resolve().then(()=>(wo(),ho)),Promise.resolve().then(()=>(go(),yo)),Promise.resolve().then(()=>(Ao(),Eo)),Promise.resolve().then(()=>(xo(),So)),Promise.resolve().then(()=>(bo(),Co)),Promise.resolve().then(()=>($o(),Ro)),Promise.resolve().then(()=>(To(),Po)),Promise.resolve().then(()=>(Io(),Oo)),Promise.resolve().then(()=>(ko(),_o)),Promise.resolve().then(()=>(Uo(),No)),Promise.resolve().then(()=>(jo(),Vo)),Promise.resolve().then(()=>(Do(),zo)),Promise.resolve().then(()=>(Mo(),Lo)),Promise.resolve().then(()=>(Fo(),qo)),Promise.resolve().then(()=>(Ko(),Ho)),Promise.resolve().then(()=>(Yo(),Wo)),Promise.resolve().then(()=>(Xo(),Zo)),Promise.resolve().then(()=>(Go(),vo)),Promise.resolve().then(()=>(rs(),es)),Promise.resolve().then(()=>(ns(),ts)),Promise.resolve().then(()=>(os(),is)),Promise.resolve().then(()=>(as(),ss)),Promise.resolve().then(()=>(fs(),cs)),Promise.resolve().then(()=>(ms(),us)),Promise.resolve().then(()=>(ds(),ps)),Promise.resolve().then(()=>(hs(),ls)),Promise.resolve().then(()=>(ys(),ws)),Promise.resolve().then(()=>(Es(),gs)),Promise.resolve().then(()=>(Ss(),As)),Promise.resolve().then(()=>(Cs(),xs)),Promise.resolve().then(()=>(Ps(),$s)),Promise.resolve().then(()=>(Os(),Ts)),Promise.resolve().then(()=>(_s(),Is)),Promise.resolve().then(()=>(Ns(),ks)),Promise.resolve().then(()=>(Vs(),Us)),Promise.resolve().then(()=>(zs(),js)),Promise.resolve().then(()=>(Ls(),Ds)),Promise.resolve().then(()=>(qs(),Ms)),Promise.resolve().then(()=>(Hs(),Fs)),Promise.resolve().then(()=>(Bs(),Ks)),Promise.resolve().then(()=>(Ys(),Ws)),Promise.resolve().then(()=>(Xs(),Zs)),Promise.resolve().then(()=>(Gs(),vs)),Promise.resolve().then(()=>(Qs(),Js)),Promise.resolve().then(()=>(ra(),ea)),Promise.resolve().then(()=>(na(),ta)),Promise.resolve().then(()=>(oa(),ia)),Promise.resolve().then(()=>(aa(),sa)),Promise.resolve().then(()=>(fa(),ca))])}catch(e){throw new Error("Failed to load built-in processors",{cause:e})}var Ru=ua.flatMap(e=>Object.values(e).filter(r=>r&&typeof r.keyword=="string"));function ma(){return Ru}s(ma,"getBuiltinProcessors");function Zr(e,r){e.registerSchema("root-schema",tn),e.registerSchema("any",Zt),e.registerSchema("string",Xt),e.registerSchema("number",vt),e.registerSchema("boolean",Gt),e.registerSchema("object",Jt),e.registerSchema("array",Qt),e.registerSchema("date",en),e.registerSchema("function",rn);for(let t of ma())e.registerValueProcessorDefinition(t)}s(Zr,"coreLibrary");ne();J();Fe();se();h();we();Sr();te();k();q();pr();ir();er();Ce();sr();he();Yr();h();Wt(Zr);export{b as CompiledSchema,u as ConstraintError,H as EMPTY,ee as FinalizeError,ue as NormalizeError,P as ResolverError,C as Schema,I as SchemaCompilationError,m as SchemaError,z as SchemaLocation,L as SchemaPolicy,qr as SchemaResolver,Re as SerializeError,X as TransformError,le as UnionResolutionError,D as ValidationError,Sa as assertErrorMessageInCauseChain,qe as behead,Ar as debug,xa as deepAssign,G as deepEquals,Be as deepMerge,We as deepPrune,re as deepValue,or as formatArgumentType,Wr as formatDataSize,y as formatValue,mr as hasStringProperties,ga as isConstructible,ya as isConstructor,K as isEmpty,_r as isFalsey,Ir as isFalseyKeyword,gr as isNativeClass,be as isObject,M as isPlainObject,Ke as isPrimitive,Q as isTruthy,Or as isTruthyKeyword,B as map,He as parse,Br as parseDataSize,_e as parseDate,Ie as parseRegExp,pa as propertyName,ye as stringify,jr as toCamelCase,Lr as toCapitalize,Dr as toConstantCase,Ue as toData,Oe as toKebabCase,zr as toPascalCase,Mr as toTitleCase};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@versionzero/schema",
3
- "version": "1.4.0",
3
+ "version": "1.4.1",
4
4
  "description": "A composable schema library that supports asynchronous processing",
5
5
  "license": "Apache-2.0",
6
6
  "publishConfig": {