airi / assets /core-DLGqGxHa.js
nekomeowww's picture
release: build afef299dbc0fe1fc1074c6b7e796eb67f9c2025b
d1d75e5
function e(e,t,n){function r(n,r){var i;for(let a in Object.defineProperty(n,`_zod`,{value:n._zod??{},enumerable:!1}),(i=n._zod).traits??(i.traits=new Set),n._zod.traits.add(e),t(n,r),o.prototype)a in n||Object.defineProperty(n,a,{value:o.prototype[a].bind(n)});n._zod.constr=o,n._zod.def=r}let i=n?.Parent??Object;class a extends i{}Object.defineProperty(a,`name`,{value:e});function o(e){var t;let i=n?.Parent?new a:this;r(i,e),(t=i._zod).deferred??(t.deferred=[]);for(let e of i._zod.deferred)e();return i}return Object.defineProperty(o,`init`,{value:r}),Object.defineProperty(o,Symbol.hasInstance,{value:t=>{var r;return n?.Parent&&t instanceof n.Parent?!0:t==null||(r=t._zod)==null||(r=r.traits)==null?void 0:r.has(e)}}),Object.defineProperty(o,`name`,{value:e}),o}const t=Symbol(`zod_brand`);var n=class extends Error{constructor(){super(`Encountered Promise during synchronous parse. Use .parseAsync() instead.`)}};const r={};function i(e){return e&&Object.assign(r,e),r}function a(e){let t=Object.values(e).filter(e=>typeof e==`number`),n=Object.entries(e).filter(([e,n])=>t.indexOf(+e)===-1).map(([e,t])=>t);return n}function o(e,t){return typeof t==`bigint`?t.toString():t}function s(e){let t=!1;return{get value(){if(!t){let t=e();return Object.defineProperty(this,`value`,{value:t}),t}throw Error(`cached value already set`)}}}const c=Error.captureStackTrace?Error.captureStackTrace:(...e)=>{},l=s(()=>{var e;if(typeof navigator<`u`&&!((e=navigator)==null||(e=e.userAgent)==null)&&e.includes(`Cloudflare`))return!1;try{let e=Function;return new e(``),!0}catch{return!1}}),u={safeint:[-(2**53-1),2**53-1],int32:[-2147483648,2147483647],uint32:[0,4294967295],float32:[-34028234663852886e22,34028234663852886e22],float64:[-Number.MAX_VALUE,Number.MAX_VALUE]};function d(e){return typeof e==`string`?e:e?.message}function f(e,t,n){let r={...e,path:e.path??[]};if(!e.message){var i,a,o,s,c;let l=d((i=e.inst)==null||(i=i._zod.def)==null||(a=i.error)==null?void 0:a.call(i,e))??d(t==null||(o=t.error)==null?void 0:o.call(t,e))??d((s=n.customError)?.call(n,e))??d((c=n.localeError)?.call(n,e))??`Invalid input`;r.message=l}return delete r.inst,delete r.continue,t?.reportInput||delete r.input,r}const p=(e,t)=>{e.name=`$ZodError`,Object.defineProperty(e,`_zod`,{value:e._zod,enumerable:!1}),Object.defineProperty(e,`issues`,{value:t,enumerable:!1}),Object.defineProperty(e,`message`,{get(){return JSON.stringify(t,o,2)},enumerable:!0})},m=e(`$ZodError`,p),h=e(`$ZodError`,p,{Parent:Error}),g=e=>(t,r,a,o)=>{let s=a?Object.assign(a,{async:!1}):{async:!1},l=t._zod.run({value:r,issues:[]},s);if(l instanceof Promise)throw new n;if(l.issues.length){let t=new(o?.Err??e)(l.issues.map(e=>f(e,s,i())));throw c(t,o?.callee),t}return l.value},_=g(h),v=e=>async(t,n,r,a)=>{let o=r?Object.assign(r,{async:!0}):{async:!0},s=t._zod.run({value:n,issues:[]},o);if(s instanceof Promise&&(s=await s),s.issues.length){let t=new(a?.Err??e)(s.issues.map(e=>f(e,o,i())));throw c(t,a?.callee),t}return s.value},y=v(h),b=e=>(t,r,a)=>{let o=a?{...a,async:!1}:{async:!1},s=t._zod.run({value:r,issues:[]},o);if(s instanceof Promise)throw new n;return s.issues.length?{success:!1,error:new(e??m)(s.issues.map(e=>f(e,o,i())))}:{success:!0,data:s.value}},x=b(h),S=e=>async(t,n,r)=>{let a=r?Object.assign(r,{async:!0}):{async:!0},o=t._zod.run({value:n,issues:[]},a);return o instanceof Promise&&(o=await o),o.issues.length?{success:!1,error:new e(o.issues.map(e=>f(e,a,i())))}:{success:!0,data:o.value}},C=S(h),w=`(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))`,T=RegExp(`^${w}$`),E=Symbol(`ZodOutput`),D=Symbol(`ZodInput`);var O=class{constructor(){this._map=new WeakMap,this._idmap=new Map}add(e,...t){let n=t[0];if(this._map.set(e,n),n&&typeof n==`object`&&`id`in n){if(this._idmap.has(n.id))throw Error(`ID ${n.id} already exists in the registry`);this._idmap.set(n.id,e)}return this}remove(e){return this._map.delete(e),this}get(e){let t=e._zod.parent;if(t){let n={...this.get(t)??{}};return delete n.id,{...n,...this._map.get(e)}}return this._map.get(e)}has(e){return this._map.has(e)}};function k(){return new O}const A=k();var j=class{constructor(e){this.counter=0,this.metadataRegistry=e?.metadata??A,this.target=e?.target??`draft-2020-12`,this.unrepresentable=e?.unrepresentable??`throw`,this.override=e?.override??(()=>{}),this.io=e?.io??`output`,this.seen=new Map}process(e,t={path:[],schemaPath:[]}){var n,r,i;let o=e._zod.def,s={guid:`uuid`,url:`uri`,datetime:`date-time`,json_string:`json-string`,regex:``},c=this.seen.get(e);if(c){c.count++;let n=t.schemaPath.includes(e);return n&&(c.cycle=t.path),c.schema}let l={schema:{},count:1,cycle:void 0};this.seen.set(e,l);let u=(n=(r=e._zod).toJSONSchema)?.call(r);if(u)l.schema=u;else{let n={...t,schemaPath:[...t.schemaPath,e],path:t.path},r=e._zod.parent;if(r)l.ref=r,this.process(r,n),this.seen.get(r).isParent=!0;else{let t=l.schema;switch(o.type){case`string`:{let n=t;n.type=`string`;let{minimum:r,maximum:i,format:a,patterns:o,contentEncoding:c}=e._zod.bag;if(typeof r==`number`&&(n.minLength=r),typeof i==`number`&&(n.maxLength=i),a&&(n.format=s[a]??a,n.format===``&&delete n.format),c&&(n.contentEncoding=c),o&&o.size>0){let e=[...o];e.length===1?n.pattern=e[0].source:e.length>1&&(l.schema.allOf=[...e.map(e=>({...this.target===`draft-7`?{type:`string`}:{},pattern:e.source}))])}break}case`number`:{let n=t,{minimum:r,maximum:i,format:a,multipleOf:o,exclusiveMaximum:s,exclusiveMinimum:c}=e._zod.bag;typeof a==`string`&&a.includes(`int`)?n.type=`integer`:n.type=`number`,typeof c==`number`&&(n.exclusiveMinimum=c),typeof r==`number`&&(n.minimum=r,typeof c==`number`&&(c>=r?delete n.minimum:delete n.exclusiveMinimum)),typeof s==`number`&&(n.exclusiveMaximum=s),typeof i==`number`&&(n.maximum=i,typeof s==`number`&&(s<=i?delete n.maximum:delete n.exclusiveMaximum)),typeof o==`number`&&(n.multipleOf=o);break}case`boolean`:{let e=t;e.type=`boolean`;break}case`bigint`:if(this.unrepresentable===`throw`)throw Error(`BigInt cannot be represented in JSON Schema`);break;case`symbol`:if(this.unrepresentable===`throw`)throw Error(`Symbols cannot be represented in JSON Schema`);break;case`undefined`:{let e=t;e.type=`null`;break}case`null`:t.type=`null`;break;case`any`:break;case`unknown`:break;case`never`:t.not={};break;case`void`:if(this.unrepresentable===`throw`)throw Error(`Void cannot be represented in JSON Schema`);break;case`date`:if(this.unrepresentable===`throw`)throw Error(`Date cannot be represented in JSON Schema`);break;case`array`:{let r=t,{minimum:i,maximum:a}=e._zod.bag;typeof i==`number`&&(r.minItems=i),typeof a==`number`&&(r.maxItems=a),r.type=`array`,r.items=this.process(o.element,{...n,path:[...n.path,`items`]});break}case`object`:{var d;let e=t;e.type=`object`,e.properties={};let r=o.shape;for(let t in r)e.properties[t]=this.process(r[t],{...n,path:[...n.path,`properties`,t]});let i=new Set(Object.keys(r)),a=new Set([...i].filter(e=>{let t=o.shape[e]._zod;return this.io===`input`?t.optin===void 0:t.optout===void 0}));a.size>0&&(e.required=Array.from(a)),(d=o.catchall)?._zod.def.type===`never`?e.additionalProperties=!1:o.catchall?o.catchall&&(e.additionalProperties=this.process(o.catchall,{...n,path:[...n.path,`additionalProperties`]})):this.io===`output`&&(e.additionalProperties=!1);break}case`union`:{let e=t;e.anyOf=o.options.map((e,t)=>this.process(e,{...n,path:[...n.path,`anyOf`,t]}));break}case`intersection`:{let e=t,r=this.process(o.left,{...n,path:[...n.path,`allOf`,0]}),i=this.process(o.right,{...n,path:[...n.path,`allOf`,1]}),a=e=>`allOf`in e&&Object.keys(e).length===1,s=[...a(r)?r.allOf:[r],...a(i)?i.allOf:[i]];e.allOf=s;break}case`tuple`:{let r=t;r.type=`array`;let i=o.items.map((e,t)=>this.process(e,{...n,path:[...n.path,`prefixItems`,t]}));if(this.target===`draft-2020-12`?r.prefixItems=i:r.items=i,o.rest){let e=this.process(o.rest,{...n,path:[...n.path,`items`]});this.target===`draft-2020-12`?r.items=e:r.additionalItems=e}o.rest&&(r.items=this.process(o.rest,{...n,path:[...n.path,`items`]}));let{minimum:a,maximum:s}=e._zod.bag;typeof a==`number`&&(r.minItems=a),typeof s==`number`&&(r.maxItems=s);break}case`record`:{let e=t;e.type=`object`,e.propertyNames=this.process(o.keyType,{...n,path:[...n.path,`propertyNames`]}),e.additionalProperties=this.process(o.valueType,{...n,path:[...n.path,`additionalProperties`]});break}case`map`:if(this.unrepresentable===`throw`)throw Error(`Map cannot be represented in JSON Schema`);break;case`set`:if(this.unrepresentable===`throw`)throw Error(`Set cannot be represented in JSON Schema`);break;case`enum`:{let e=t,n=a(o.entries);n.every(e=>typeof e==`number`)&&(e.type=`number`),n.every(e=>typeof e==`string`)&&(e.type=`string`),e.enum=n;break}case`literal`:{let e=t,n=[];for(let e of o.values)if(e===void 0){if(this.unrepresentable===`throw`)throw Error("Literal `undefined` cannot be represented in JSON Schema")}else if(typeof e==`bigint`){if(this.unrepresentable===`throw`)throw Error(`BigInt literals cannot be represented in JSON Schema`);n.push(Number(e))}else n.push(e);if(n.length!==0)if(n.length===1){let t=n[0];e.type=t===null?`null`:typeof t,e.const=t}else n.every(e=>typeof e==`number`)&&(e.type=`number`),n.every(e=>typeof e==`string`)&&(e.type=`string`),n.every(e=>typeof e==`boolean`)&&(e.type=`string`),n.every(e=>e===null)&&(e.type=`null`),e.enum=n;break}case`file`:{let n=t,r={type:`string`,format:`binary`,contentEncoding:`binary`},{minimum:i,maximum:a,mime:o}=e._zod.bag;i!==void 0&&(r.minLength=i),a!==void 0&&(r.maxLength=a),o?o.length===1?(r.contentMediaType=o[0],Object.assign(n,r)):n.anyOf=o.map(e=>{let t={...r,contentMediaType:e};return t}):Object.assign(n,r);break}case`transform`:if(this.unrepresentable===`throw`)throw Error(`Transforms cannot be represented in JSON Schema`);break;case`nullable`:{let e=this.process(o.innerType,n);t.anyOf=[e,{type:`null`}];break}case`nonoptional`:this.process(o.innerType,n),l.ref=o.innerType;break;case`success`:{let e=t;e.type=`boolean`;break}case`default`:this.process(o.innerType,n),l.ref=o.innerType,t.default=JSON.parse(JSON.stringify(o.defaultValue));break;case`prefault`:this.process(o.innerType,n),l.ref=o.innerType,this.io===`input`&&(t._prefault=JSON.parse(JSON.stringify(o.defaultValue)));break;case`catch`:{this.process(o.innerType,n),l.ref=o.innerType;let e;try{e=o.catchValue(void 0)}catch{throw Error(`Dynamic catch values are not supported in JSON Schema`)}t.default=e;break}case`nan`:if(this.unrepresentable===`throw`)throw Error(`NaN cannot be represented in JSON Schema`);break;case`template_literal`:{let n=t,r=e._zod.pattern;if(!r)throw Error(`Pattern not found in template literal`);n.type=`string`,n.pattern=r.source;break}case`pipe`:{let e=this.io===`input`?o.in._zod.def.type===`transform`?o.out:o.in:o.out;this.process(e,n),l.ref=e;break}case`readonly`:this.process(o.innerType,n),l.ref=o.innerType,t.readOnly=!0;break;case`promise`:this.process(o.innerType,n),l.ref=o.innerType;break;case`optional`:this.process(o.innerType,n),l.ref=o.innerType;break;case`lazy`:{let t=e._zod.innerType;this.process(t,n),l.ref=t;break}case`custom`:if(this.unrepresentable===`throw`)throw Error(`Custom types cannot be represented in JSON Schema`);break;default:}}}let f=this.metadataRegistry.get(e);f&&Object.assign(l.schema,f),this.io===`input`&&N(e)&&(delete l.schema.examples,delete l.schema.default),this.io===`input`&&l.schema._prefault&&((i=l.schema).default??(i.default=l.schema._prefault)),delete l.schema._prefault;let p=this.seen.get(e);return p.schema}emit(e,t){var n;let r={cycles:t?.cycles??`ref`,reused:t?.reused??`inline`,external:t?.external??void 0},i=this.seen.get(e);if(!i)throw Error(`Unprocessed schema. This is a bug in Zod.`);let a=e=>{let t=this.target===`draft-2020-12`?`$defs`:`definitions`;if(r.external){var n;let i=(n=r.external.registry.get(e[0]))?.id;if(i)return{ref:r.external.uri(i)};let a=e[1].defId??e[1].schema.id??`schema${this.counter++}`;return e[1].defId=a,{defId:a,ref:`${r.external.uri(`__shared`)}#/${t}/${a}`}}if(e[1]===i)return{ref:`#`};let a=`#`,o=`${a}/${t}/`,s=e[1].schema.id??`__schema${this.counter++}`;return{defId:s,ref:o+s}},o=e=>{if(e[1].schema.$ref)return;let t=e[1],{ref:n,defId:r}=a(e);t.def={...t.schema},r&&(t.defId=r);let i=t.schema;for(let e in i)delete i[e];i.$ref=n};for(let t of this.seen.entries()){var s;let n=t[1];if(e===t[0]){o(t);continue}if(r.external){var c;let n=(c=r.external.registry.get(t[0]))?.id;if(e!==t[0]&&n){o(t);continue}}let i=(s=this.metadataRegistry.get(t[0]))?.id;if(i){o(t);continue}if(n.cycle){var l;if(r.cycles===`throw`)throw Error(`Cycle detected: #/${(l=n.cycle)?.join(`/`)}/<root>
Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.`);r.cycles===`ref`&&o(t);continue}if(n.count>1&&r.reused===`ref`){o(t);continue}}let u=(e,t)=>{let n=this.seen.get(e),r=n.def??n.schema,i={...r};if(n.ref===null)return;let a=n.ref;if(n.ref=null,a){u(a,t);let e=this.seen.get(a).schema;e.$ref&&t.target===`draft-7`?(r.allOf=r.allOf??[],r.allOf.push(e)):(Object.assign(r,e),Object.assign(r,i))}n.isParent||this.override({zodSchema:e,jsonSchema:r})};for(let e of[...this.seen.entries()].reverse())u(e[0],{target:this.target});let d={};this.target===`draft-2020-12`?d.$schema=`https://json-schema.org/draft/2020-12/schema`:this.target===`draft-7`?d.$schema=`http://json-schema.org/draft-07/schema#`:console.warn(`Invalid target: ${this.target}`),Object.assign(d,i.def);let f=(n=r.external)?.defs??{};for(let e of this.seen.entries()){let t=e[1];t.def&&t.defId&&(f[t.defId]=t.def)}!r.external&&Object.keys(f).length>0&&(this.target===`draft-2020-12`?d.$defs=f:d.definitions=f);try{return JSON.parse(JSON.stringify(d))}catch{throw Error(`Error converting schema to JSON.`)}}};function M(e,t){if(e instanceof O){let n=new j(t),r={};for(let t of e._idmap.entries()){let[e,r]=t;n.process(r)}let i={},a={registry:e,uri:t?.uri||(e=>e),defs:r};for(let r of e._idmap.entries()){let[e,o]=r;i[e]=n.emit(o,{...t,external:a})}if(Object.keys(r).length>0){let e=n.target===`draft-2020-12`?`$defs`:`definitions`;i.__shared={[e]:r}}return{schemas:i}}let n=new j(t);return n.process(e),n.emit(e,t)}function N(e,t){let n=t??{seen:new Set};if(n.seen.has(e))return!1;n.seen.add(e);let r=e,i=r._zod.def;switch(i.type){case`string`:case`number`:case`bigint`:case`boolean`:case`date`:case`symbol`:case`undefined`:case`null`:case`any`:case`unknown`:case`never`:case`void`:case`literal`:case`enum`:case`nan`:case`file`:case`template_literal`:return!1;case`array`:return N(i.element,n);case`object`:for(let e in i.shape)if(N(i.shape[e],n))return!0;return!1;case`union`:for(let e of i.options)if(N(e,n))return!0;return!1;case`intersection`:return N(i.left,n)||N(i.right,n);case`tuple`:for(let e of i.items)if(N(e,n))return!0;return!!(i.rest&&N(i.rest,n));case`record`:return N(i.keyType,n)||N(i.valueType,n);case`map`:return N(i.keyType,n)||N(i.valueType,n);case`set`:return N(i.valueType,n);case`promise`:case`optional`:case`nonoptional`:case`nullable`:case`readonly`:return N(i.innerType,n);case`lazy`:return N(i.getter(),n);case`default`:return N(i.innerType,n);case`prefault`:return N(i.innerType,n);case`custom`:return!1;case`transform`:return!0;case`pipe`:return N(i.in,n)||N(i.out,n);case`success`:return!1;case`catch`:return!1;default:}throw Error(`Unknown schema type: ${i.type}`)}export{M as toJSONSchema};