@kingbri1/standard-json 0.2.1-pre1 → 0.2.1-pre2

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 +1 @@
1
- var r=Object.defineProperty;var e=(t,o)=>r(t,"name",{value:o,configurable:!0});import{t as a}from"./index-I9ikUX_B.js";const m=e(async()=>{const{JSONSchema:t}=await a(import("effect"),"effect");return o=>t.make(o)},"getToJsonSchemaFn");export{m as getToJsonSchemaFn};
1
+ var r=Object.defineProperty;var e=(t,o)=>r(t,"name",{value:o,configurable:!0});import{t as a}from"./index-Dfd7JFus.js";const m=e(async()=>{const{JSONSchema:t}=await a(import("effect"),"effect");return o=>t.make(o)},"getToJsonSchemaFn");export{m as getToJsonSchemaFn};
@@ -1 +1 @@
1
- "use strict";var s=Object.create;var a=Object.defineProperty;var m=Object.getOwnPropertyDescriptor;var i=Object.getOwnPropertyNames;var S=Object.getPrototypeOf,h=Object.prototype.hasOwnProperty;var o=(e,t)=>a(e,"name",{value:t,configurable:!0});var u=(e,t,n,c)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of i(t))!h.call(e,r)&&r!==n&&a(e,r,{get:()=>t[r],enumerable:!(c=m(t,r))||c.enumerable});return e};var J=(e,t,n)=>(n=e!=null?s(S(e)):{},u(t||!e||!e.__esModule?a(n,"default",{value:e,enumerable:!0}):n,e));var f=require("./index-CD6qJBQN.cjs");const g=o(async()=>{const{JSONSchema:e}=await f.tryImport(import("effect"),"effect");return t=>e.make(t)},"getToJsonSchemaFn");exports.getToJsonSchemaFn=g;
1
+ "use strict";var s=Object.create;var a=Object.defineProperty;var m=Object.getOwnPropertyDescriptor;var i=Object.getOwnPropertyNames;var S=Object.getPrototypeOf,h=Object.prototype.hasOwnProperty;var o=(e,t)=>a(e,"name",{value:t,configurable:!0});var u=(e,t,n,c)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of i(t))!h.call(e,r)&&r!==n&&a(e,r,{get:()=>t[r],enumerable:!(c=m(t,r))||c.enumerable});return e};var J=(e,t,n)=>(n=e!=null?s(S(e)):{},u(t||!e||!e.__esModule?a(n,"default",{value:e,enumerable:!0}):n,e));var f=require("./index-CbaUBnzA.cjs");const g=o(async()=>{const{JSONSchema:e}=await f.tryImport(import("effect"),"effect");return t=>e.make(t)},"getToJsonSchemaFn");exports.getToJsonSchemaFn=g;
@@ -1 +1 @@
1
- "use strict";var t=Object.defineProperty;var r=(n,e)=>t(n,"name",{value:e,configurable:!0});const s=r(async(n,e)=>{try{return await n}catch{throw new Error(`standard-json: Missing dependencies "${e}".`)}},"tryImport"),o=r(async n=>{switch(n){case"arktype":return Promise.resolve().then(function(){return require("./arktype-Dl6TXwAj.cjs")}).then(async({getToJsonSchemaFn:e})=>e());case"effect":return Promise.resolve().then(function(){return require("./effect-CjGTzXSx.cjs")}).then(async({getToJsonSchemaFn:e})=>e());case"valibot":return Promise.resolve().then(function(){return require("./valibot-Bj3vthVP.cjs")}).then(async({getToJsonSchemaFn:e})=>e());case"zod":return Promise.resolve().then(function(){return require("./zod-CCbk5bPB.cjs")}).then(async({getToJsonSchemaFn:e})=>e());default:throw new Error(`standard-json: Unsupported schema vendor "${n}"`)}},"getToJsonSchemaFn"),a=r(async n=>o(n["~standard"].vendor).then(async e=>await e(n)),"toJsonSchema");exports.toJsonSchema=a,exports.tryImport=s;
1
+ "use strict";var t=Object.defineProperty;var r=(n,e)=>t(n,"name",{value:e,configurable:!0});const s=r(async(n,e)=>{try{return await n}catch{throw new Error(`standard-json: Missing dependencies "${e}".`)}},"tryImport"),o=r(async n=>{switch(n){case"arktype":return Promise.resolve().then(function(){return require("./arktype-Dl6TXwAj.cjs")}).then(async({getToJsonSchemaFn:e})=>e());case"effect":return Promise.resolve().then(function(){return require("./effect-yIOCghne.cjs")}).then(async({getToJsonSchemaFn:e})=>e());case"valibot":return Promise.resolve().then(function(){return require("./valibot-DS2B6crW.cjs")}).then(async({getToJsonSchemaFn:e})=>e());case"zod":return Promise.resolve().then(function(){return require("./zod-dYtHTk3p.cjs")}).then(async({getToJsonSchemaFn:e})=>e());default:throw new Error(`standard-json: Unsupported schema vendor "${n}"`)}},"getToJsonSchemaFn"),a=r(async n=>o(n["~standard"].vendor).then(async e=>await e(n)),"toJsonSchema");exports.toJsonSchema=a,exports.tryImport=s;
@@ -1 +1 @@
1
- var a=Object.defineProperty;var e=(t,n)=>a(t,"name",{value:n,configurable:!0});const s=e(async(t,n)=>{try{return await t}catch{throw new Error(`standard-json: Missing dependencies "${n}".`)}},"tryImport"),r=e(async t=>{switch(t){case"arktype":return import("./arktype-rPtBJvA_.js").then(async({getToJsonSchemaFn:n})=>n());case"effect":return import("./effect-CW3DGCIF.js").then(async({getToJsonSchemaFn:n})=>n());case"valibot":return import("./valibot-DoNv6iQ4.js").then(async({getToJsonSchemaFn:n})=>n());case"zod":return import("./zod-w00sr6hq.js").then(async({getToJsonSchemaFn:n})=>n());default:throw new Error(`standard-json: Unsupported schema vendor "${t}"`)}},"getToJsonSchemaFn"),o=e(async t=>r(t["~standard"].vendor).then(async n=>await n(t)),"toJsonSchema");export{o as a,s as t};
1
+ var a=Object.defineProperty;var e=(t,n)=>a(t,"name",{value:n,configurable:!0});const s=e(async(t,n)=>{try{return await t}catch{throw new Error(`standard-json: Missing dependencies "${n}".`)}},"tryImport"),r=e(async t=>{switch(t){case"arktype":return import("./arktype-rPtBJvA_.js").then(async({getToJsonSchemaFn:n})=>n());case"effect":return import("./effect-Bmzbe2LN.js").then(async({getToJsonSchemaFn:n})=>n());case"valibot":return import("./valibot-CouuIoLn.js").then(async({getToJsonSchemaFn:n})=>n());case"zod":return import("./zod-m66mQ-ir.js").then(async({getToJsonSchemaFn:n})=>n());default:throw new Error(`standard-json: Unsupported schema vendor "${t}"`)}},"getToJsonSchemaFn"),o=e(async t=>r(t["~standard"].vendor).then(async n=>await n(t)),"toJsonSchema");export{o as a,s as t};
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";var e=require("./index-CD6qJBQN.cjs");exports.toJsonSchema=e.toJsonSchema;
1
+ "use strict";var e=require("./index-CbaUBnzA.cjs");exports.toJsonSchema=e.toJsonSchema;
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- import{a as e}from"./index-I9ikUX_B.js";export{e as toJsonSchema};
1
+ import{a as e}from"./index-Dfd7JFus.js";export{e as toJsonSchema};
@@ -1 +1 @@
1
- var r=Object.defineProperty;var a=(o,t)=>r(o,"name",{value:t,configurable:!0});import{t as s}from"./index-I9ikUX_B.js";const m=a(async()=>{const{toJsonSchema:o}=await s(import("@valibot/to-json-schema"),"@valibot/to-json-schema");return(t,n)=>o(t,n)},"getToJsonSchemaFn");export{m as getToJsonSchemaFn};
1
+ var r=Object.defineProperty;var a=(o,t)=>r(o,"name",{value:t,configurable:!0});import{t as s}from"./index-Dfd7JFus.js";const m=a(async()=>{const{toJsonSchema:o}=await s(import("@valibot/to-json-schema"),"@valibot/to-json-schema");return(t,n)=>o(t,n)},"getToJsonSchemaFn");export{m as getToJsonSchemaFn};
@@ -1 +1 @@
1
- "use strict";var c=Object.create;var s=Object.defineProperty;var i=Object.getOwnPropertyDescriptor;var m=Object.getOwnPropertyNames;var h=Object.getPrototypeOf,u=Object.prototype.hasOwnProperty;var r=(t,o)=>s(t,"name",{value:o,configurable:!0});var J=(t,o,e,a)=>{if(o&&typeof o=="object"||typeof o=="function")for(let n of m(o))!u.call(t,n)&&n!==e&&s(t,n,{get:()=>o[n],enumerable:!(a=i(o,n))||a.enumerable});return t};var S=(t,o,e)=>(e=t!=null?c(h(t)):{},J(o||!t||!t.__esModule?s(e,"default",{value:t,enumerable:!0}):e,t));var g=require("./index-CD6qJBQN.cjs");const p=r(async()=>{const{toJsonSchema:t}=await g.tryImport(import("@valibot/to-json-schema"),"@valibot/to-json-schema");return(o,e)=>t(o,e)},"getToJsonSchemaFn");exports.getToJsonSchemaFn=p;
1
+ "use strict";var c=Object.create;var s=Object.defineProperty;var i=Object.getOwnPropertyDescriptor;var m=Object.getOwnPropertyNames;var h=Object.getPrototypeOf,u=Object.prototype.hasOwnProperty;var r=(t,o)=>s(t,"name",{value:o,configurable:!0});var J=(t,o,e,a)=>{if(o&&typeof o=="object"||typeof o=="function")for(let n of m(o))!u.call(t,n)&&n!==e&&s(t,n,{get:()=>o[n],enumerable:!(a=i(o,n))||a.enumerable});return t};var S=(t,o,e)=>(e=t!=null?c(h(t)):{},J(o||!t||!t.__esModule?s(e,"default",{value:t,enumerable:!0}):e,t));var g=require("./index-CbaUBnzA.cjs");const p=r(async()=>{const{toJsonSchema:t}=await g.tryImport(import("@valibot/to-json-schema"),"@valibot/to-json-schema");return(o,e)=>t(o,e)},"getToJsonSchemaFn");exports.getToJsonSchemaFn=p;
@@ -1,3 +1,3 @@
1
- "use strict";var O=Object.create;var S=Object.defineProperty;var _=Object.getOwnPropertyDescriptor;var j=Object.getOwnPropertyNames;var v=Object.getPrototypeOf,T=Object.prototype.hasOwnProperty;var g=(l,t)=>S(l,"name",{value:t,configurable:!0});var N=(l,t,h,a)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of j(t))!T.call(l,r)&&r!==h&&S(l,r,{get:()=>t[r],enumerable:!(a=_(t,r))||a.enumerable});return l};var I=(l,t,h)=>(h=l!=null?O(v(l)):{},N(t||!l||!l.__esModule?S(h,"default",{value:l,enumerable:!0}):h,l));var J=require("./index-CD6qJBQN.cjs");class k{static{g(this,"$ZodRegistry")}constructor(){this._map=new WeakMap,this._idmap=new Map}add(t,...h){const a=h[0];if(this._map.set(t,a),a&&typeof a=="object"&&"id"in a){if(this._idmap.has(a.id))throw new Error(`ID ${a.id} already exists in the registry`);this._idmap.set(a.id,t)}return this}remove(t){return this._map.delete(t),this}get(t){const h=t._zod.parent;if(h){const a={...this.get(h)??{}};return delete a.id,{...a,...this._map.get(t)}}return this._map.get(t)}has(t){return this._map.has(t)}}function E(){return new k}g(E,"registry");const $=E(),z={guid:"uuid",url:"uri",datetime:"date-time",json_string:"json-string"};class x{static{g(this,"JSONSchemaGenerator")}constructor(t){this.counter=0,this.metadataRegistry=t?.metadata??$,this.target=t?.target??"draft-2020-12",this.unrepresentable=t?.unrepresentable??"throw",this.override=t?.override??(()=>{}),this.io=t?.io??"output",this.seen=new Map}process(t,h={path:[],schemaPath:[]}){var a;const r=t._zod.def,y=this.seen.get(t);if(y)return y.count++,h.schemaPath.includes(t)&&(y.cycle=h.path),y.count++,y.schema;const c={schema:{},count:1,cycle:void 0};this.seen.set(t,c),t._zod.toJSONSchema&&(c.schema=t._zod.toJSONSchema());const s={...h,schemaPath:[...h.schemaPath,t],path:h.path},m=t._zod.parent;if(m)c.ref=m,this.process(m,s),this.seen.get(m).isParent=!0;else{const i=c.schema;switch(r.type){case"string":{const e=i;e.type="string";const{minimum:n,maximum:o,format:d,pattern:p,contentEncoding:u}=t._zod.bag;typeof n=="number"&&(e.minLength=n),typeof o=="number"&&(e.maxLength=o),d&&(e.format=z[d]??d),p&&(e.pattern=p.source),u&&(e.contentEncoding=u);break}case"number":{const e=i,{minimum:n,maximum:o,format:d,multipleOf:p,exclusiveMaximum:u,exclusiveMinimum:w}=t._zod.bag;typeof d=="string"&&d.includes("int")?e.type="integer":e.type="number",typeof w=="number"&&(e.exclusiveMinimum=w),typeof n=="number"&&(e.minimum=n,typeof w=="number"&&(w>=n?delete e.minimum:delete e.exclusiveMinimum)),typeof u=="number"&&(e.exclusiveMaximum=u),typeof o=="number"&&(e.maximum=o,typeof u=="number"&&(u<=o?delete e.maximum:delete e.exclusiveMaximum)),typeof p=="number"&&(e.multipleOf=p);break}case"boolean":{const e=i;e.type="boolean";break}case"bigint":{if(this.unrepresentable==="throw")throw new Error("BigInt cannot be represented in JSON Schema");break}case"symbol":{if(this.unrepresentable==="throw")throw new Error("Symbols cannot be represented in JSON Schema");break}case"undefined":{const e=i;e.type="null";break}case"null":{i.type="null";break}case"any":break;case"unknown":break;case"never":{i.not={};break}case"void":{if(this.unrepresentable==="throw")throw new Error("Void cannot be represented in JSON Schema");break}case"date":{if(this.unrepresentable==="throw")throw new Error("Date cannot be represented in JSON Schema");break}case"array":{const e=i,{minimum:n,maximum:o}=t._zod.bag;typeof n=="number"&&(e.minItems=n),typeof o=="number"&&(e.maxItems=o),e.type="array",e.items=this.process(r.element,{...s,path:[...s.path,"items"]});break}case"object":{const e=i;e.type="object",e.properties={};const n=r.shape;for(const p in n)e.properties[p]=this.process(n[p],{...s,path:[...s.path,"properties",p]});const o=new Set(Object.keys(n)),d=new Set([...o].filter(p=>{const u=r.shape[p]._zod;return this.io==="input"?u.optin===void 0:u.optout===void 0}));e.required=Array.from(d),r.catchall?._zod.def.type==="never"?e.additionalProperties=!1:r.catchall&&(e.additionalProperties=this.process(r.catchall,{...s,path:[...s.path,"additionalProperties"]}));break}case"union":{const e=i;e.anyOf=r.options.map((n,o)=>this.process(n,{...s,path:[...s.path,"anyOf",o]}));break}case"intersection":{const e=i;e.allOf=[this.process(r.left,{...s,path:[...s.path,"allOf",0]}),this.process(r.right,{...s,path:[...s.path,"allOf",1]})];break}case"tuple":{const e=i;e.type="array";const n=r.items.map((p,u)=>this.process(p,{...s,path:[...s.path,"prefixItems",u]}));if(this.target==="draft-2020-12"?e.prefixItems=n:e.items=n,r.rest){const p=this.process(r.rest,{...s,path:[...s.path,"items"]});this.target==="draft-2020-12"?e.items=p:e.additionalItems=p}r.rest&&(e.items=this.process(r.rest,{...s,path:[...s.path,"items"]}));const{minimum:o,maximum:d}=t._zod.bag;typeof o=="number"&&(e.minItems=o),typeof d=="number"&&(e.maxItems=d);break}case"record":{const e=i;e.type="object",e.propertyNames=this.process(r.keyType,{...s,path:[...s.path,"propertyNames"]}),e.additionalProperties=this.process(r.valueType,{...s,path:[...s.path,"additionalProperties"]});break}case"map":{if(this.unrepresentable==="throw")throw new Error("Map cannot be represented in JSON Schema");break}case"set":{if(this.unrepresentable==="throw")throw new Error("Set cannot be represented in JSON Schema");break}case"enum":{const e=i;e.enum=Object.values(r.entries);break}case"literal":{const e=i,n=[];for(const o of r.values)if(o===void 0){if(this.unrepresentable==="throw")throw new Error("Literal `undefined` cannot be represented in JSON Schema")}else if(typeof o=="bigint"){if(this.unrepresentable==="throw")throw new Error("BigInt literals cannot be represented in JSON Schema");n.push(Number(o))}else n.push(o);if(n.length!==0)if(n.length===1){const o=n[0];e.const=o}else e.enum=n;break}case"file":{if(this.unrepresentable==="throw")throw new Error("File cannot be represented in JSON Schema");break}case"transform":{if(this.unrepresentable==="throw")throw new Error("Transforms cannot be represented in JSON Schema");break}case"nullable":{const e=this.process(r.innerType,s);i.anyOf=[e,{type:"null"}];break}case"nonoptional":{this.process(r.innerType,s),c.ref=r.innerType;break}case"success":{const e=i;e.type="boolean";break}case"default":{this.process(r.innerType,s),c.ref=r.innerType,i.default=r.defaultValue;break}case"prefault":{this.process(r.innerType,s),c.ref=r.innerType,this.io==="input"&&(i._prefault=r.defaultValue);break}case"catch":{this.process(r.innerType,s),c.ref=r.innerType;let e;try{e=r.catchValue(void 0)}catch{throw new Error("Dynamic catch values are not supported in JSON Schema")}i.default=e;break}case"nan":{if(this.unrepresentable==="throw")throw new Error("NaN cannot be represented in JSON Schema");break}case"template_literal":{const e=i,n=t._zod.pattern;if(!n)throw new Error("Pattern not found in template literal");e.type="string",e.pattern=n.source;break}case"pipe":{const e=this.io==="input"?r.in:r.out;this.process(e,s),c.ref=e;break}case"readonly":{this.process(r.innerType,s),c.ref=r.innerType,i.readOnly=!0;break}case"promise":{this.process(r.innerType,s),c.ref=r.innerType;break}case"optional":{this.process(r.innerType,s),c.ref=r.innerType;break}case"lazy":{const e=t._zod.innerType;this.process(e,s),c.ref=e;break}case"custom":{if(this.unrepresentable==="throw")throw new Error("Custom types cannot be represented in JSON Schema");break}}}const b=this.metadataRegistry.get(t);return b&&Object.assign(c.schema,b),this.io==="input"&&r.type==="pipe"&&(delete c.schema.examples,delete c.schema.default,c.schema._prefault&&(c.schema.default=c.schema._prefault)),this.io==="input"&&c.schema._prefault&&((a=c.schema).default??(a.default=c.schema._prefault)),delete c.schema._prefault,this.seen.get(t).schema}emit(t,h){const a={cycles:h?.cycles??"ref",reused:h?.reused??"inline",external:h?.external??void 0},r=this.seen.get(t);if(!r)throw new Error("Unprocessed schema. This is a bug in Zod.");const y=g(f=>{const i=this.target==="draft-2020-12"?"$defs":"definitions";if(a.external){const d=a.external.registry.get(f[0])?.id;if(d)return{ref:a.external.uri(d)};const p=f[1].defId??f[1].schema.id??`schema${this.counter++}`;return f[1].defId=p,{defId:p,ref:`${a.external.uri("__shared")}#/${i}/${p}`}}if(f[1]===r)return{ref:"#"};const n=`#/${i}/`,o=f[1].schema.id??`__schema${this.counter++}`;return{defId:o,ref:n+o}},"makeURI"),c=g(f=>{if(f[1].schema.$ref)return;const i=f[1],{ref:e,defId:n}=y(f);i.def={...i.schema},n&&(i.defId=n);const o=i.schema;for(const d in o)delete o[d],o.$ref=e},"extractToDef");for(const f of this.seen.entries()){const i=f[1];if(t===f[0]){c(f);continue}if(a.external){const n=a.external.registry.get(f[0])?.id;if(t!==f[0]&&n){c(f);continue}}if(this.metadataRegistry.get(f[0])?.id){c(f);continue}if(i.cycle){if(a.cycles==="throw")throw new Error(`Cycle detected: #/${i.cycle?.join("/")}/<root>
1
+ "use strict";var O=Object.create;var S=Object.defineProperty;var _=Object.getOwnPropertyDescriptor;var j=Object.getOwnPropertyNames;var v=Object.getPrototypeOf,T=Object.prototype.hasOwnProperty;var g=(l,t)=>S(l,"name",{value:t,configurable:!0});var N=(l,t,h,a)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of j(t))!T.call(l,r)&&r!==h&&S(l,r,{get:()=>t[r],enumerable:!(a=_(t,r))||a.enumerable});return l};var I=(l,t,h)=>(h=l!=null?O(v(l)):{},N(t||!l||!l.__esModule?S(h,"default",{value:l,enumerable:!0}):h,l));var J=require("./index-CbaUBnzA.cjs");class k{static{g(this,"$ZodRegistry")}constructor(){this._map=new WeakMap,this._idmap=new Map}add(t,...h){const a=h[0];if(this._map.set(t,a),a&&typeof a=="object"&&"id"in a){if(this._idmap.has(a.id))throw new Error(`ID ${a.id} already exists in the registry`);this._idmap.set(a.id,t)}return this}remove(t){return this._map.delete(t),this}get(t){const h=t._zod.parent;if(h){const a={...this.get(h)??{}};return delete a.id,{...a,...this._map.get(t)}}return this._map.get(t)}has(t){return this._map.has(t)}}function E(){return new k}g(E,"registry");const $=E(),z={guid:"uuid",url:"uri",datetime:"date-time",json_string:"json-string"};class x{static{g(this,"JSONSchemaGenerator")}constructor(t){this.counter=0,this.metadataRegistry=t?.metadata??$,this.target=t?.target??"draft-2020-12",this.unrepresentable=t?.unrepresentable??"throw",this.override=t?.override??(()=>{}),this.io=t?.io??"output",this.seen=new Map}process(t,h={path:[],schemaPath:[]}){var a;const r=t._zod.def,y=this.seen.get(t);if(y)return y.count++,h.schemaPath.includes(t)&&(y.cycle=h.path),y.count++,y.schema;const c={schema:{},count:1,cycle:void 0};this.seen.set(t,c),t._zod.toJSONSchema&&(c.schema=t._zod.toJSONSchema());const s={...h,schemaPath:[...h.schemaPath,t],path:h.path},m=t._zod.parent;if(m)c.ref=m,this.process(m,s),this.seen.get(m).isParent=!0;else{const i=c.schema;switch(r.type){case"string":{const e=i;e.type="string";const{minimum:n,maximum:o,format:d,pattern:p,contentEncoding:u}=t._zod.bag;typeof n=="number"&&(e.minLength=n),typeof o=="number"&&(e.maxLength=o),d&&(e.format=z[d]??d),p&&(e.pattern=p.source),u&&(e.contentEncoding=u);break}case"number":{const e=i,{minimum:n,maximum:o,format:d,multipleOf:p,exclusiveMaximum:u,exclusiveMinimum:w}=t._zod.bag;typeof d=="string"&&d.includes("int")?e.type="integer":e.type="number",typeof w=="number"&&(e.exclusiveMinimum=w),typeof n=="number"&&(e.minimum=n,typeof w=="number"&&(w>=n?delete e.minimum:delete e.exclusiveMinimum)),typeof u=="number"&&(e.exclusiveMaximum=u),typeof o=="number"&&(e.maximum=o,typeof u=="number"&&(u<=o?delete e.maximum:delete e.exclusiveMaximum)),typeof p=="number"&&(e.multipleOf=p);break}case"boolean":{const e=i;e.type="boolean";break}case"bigint":{if(this.unrepresentable==="throw")throw new Error("BigInt cannot be represented in JSON Schema");break}case"symbol":{if(this.unrepresentable==="throw")throw new Error("Symbols cannot be represented in JSON Schema");break}case"undefined":{const e=i;e.type="null";break}case"null":{i.type="null";break}case"any":break;case"unknown":break;case"never":{i.not={};break}case"void":{if(this.unrepresentable==="throw")throw new Error("Void cannot be represented in JSON Schema");break}case"date":{if(this.unrepresentable==="throw")throw new Error("Date cannot be represented in JSON Schema");break}case"array":{const e=i,{minimum:n,maximum:o}=t._zod.bag;typeof n=="number"&&(e.minItems=n),typeof o=="number"&&(e.maxItems=o),e.type="array",e.items=this.process(r.element,{...s,path:[...s.path,"items"]});break}case"object":{const e=i;e.type="object",e.properties={};const n=r.shape;for(const p in n)e.properties[p]=this.process(n[p],{...s,path:[...s.path,"properties",p]});const o=new Set(Object.keys(n)),d=new Set([...o].filter(p=>{const u=r.shape[p]._zod;return this.io==="input"?u.optin===void 0:u.optout===void 0}));e.required=Array.from(d),r.catchall?._zod.def.type==="never"?e.additionalProperties=!1:r.catchall&&(e.additionalProperties=this.process(r.catchall,{...s,path:[...s.path,"additionalProperties"]}));break}case"union":{const e=i;e.anyOf=r.options.map((n,o)=>this.process(n,{...s,path:[...s.path,"anyOf",o]}));break}case"intersection":{const e=i;e.allOf=[this.process(r.left,{...s,path:[...s.path,"allOf",0]}),this.process(r.right,{...s,path:[...s.path,"allOf",1]})];break}case"tuple":{const e=i;e.type="array";const n=r.items.map((p,u)=>this.process(p,{...s,path:[...s.path,"prefixItems",u]}));if(this.target==="draft-2020-12"?e.prefixItems=n:e.items=n,r.rest){const p=this.process(r.rest,{...s,path:[...s.path,"items"]});this.target==="draft-2020-12"?e.items=p:e.additionalItems=p}r.rest&&(e.items=this.process(r.rest,{...s,path:[...s.path,"items"]}));const{minimum:o,maximum:d}=t._zod.bag;typeof o=="number"&&(e.minItems=o),typeof d=="number"&&(e.maxItems=d);break}case"record":{const e=i;e.type="object",e.propertyNames=this.process(r.keyType,{...s,path:[...s.path,"propertyNames"]}),e.additionalProperties=this.process(r.valueType,{...s,path:[...s.path,"additionalProperties"]});break}case"map":{if(this.unrepresentable==="throw")throw new Error("Map cannot be represented in JSON Schema");break}case"set":{if(this.unrepresentable==="throw")throw new Error("Set cannot be represented in JSON Schema");break}case"enum":{const e=i;e.enum=Object.values(r.entries);break}case"literal":{const e=i,n=[];for(const o of r.values)if(o===void 0){if(this.unrepresentable==="throw")throw new Error("Literal `undefined` cannot be represented in JSON Schema")}else if(typeof o=="bigint"){if(this.unrepresentable==="throw")throw new Error("BigInt literals cannot be represented in JSON Schema");n.push(Number(o))}else n.push(o);if(n.length!==0)if(n.length===1){const o=n[0];e.const=o}else e.enum=n;break}case"file":{if(this.unrepresentable==="throw")throw new Error("File cannot be represented in JSON Schema");break}case"transform":{if(this.unrepresentable==="throw")throw new Error("Transforms cannot be represented in JSON Schema");break}case"nullable":{const e=this.process(r.innerType,s);i.anyOf=[e,{type:"null"}];break}case"nonoptional":{this.process(r.innerType,s),c.ref=r.innerType;break}case"success":{const e=i;e.type="boolean";break}case"default":{this.process(r.innerType,s),c.ref=r.innerType,i.default=r.defaultValue;break}case"prefault":{this.process(r.innerType,s),c.ref=r.innerType,this.io==="input"&&(i._prefault=r.defaultValue);break}case"catch":{this.process(r.innerType,s),c.ref=r.innerType;let e;try{e=r.catchValue(void 0)}catch{throw new Error("Dynamic catch values are not supported in JSON Schema")}i.default=e;break}case"nan":{if(this.unrepresentable==="throw")throw new Error("NaN cannot be represented in JSON Schema");break}case"template_literal":{const e=i,n=t._zod.pattern;if(!n)throw new Error("Pattern not found in template literal");e.type="string",e.pattern=n.source;break}case"pipe":{const e=this.io==="input"?r.in:r.out;this.process(e,s),c.ref=e;break}case"readonly":{this.process(r.innerType,s),c.ref=r.innerType,i.readOnly=!0;break}case"promise":{this.process(r.innerType,s),c.ref=r.innerType;break}case"optional":{this.process(r.innerType,s),c.ref=r.innerType;break}case"lazy":{const e=t._zod.innerType;this.process(e,s),c.ref=e;break}case"custom":{if(this.unrepresentable==="throw")throw new Error("Custom types cannot be represented in JSON Schema");break}}}const b=this.metadataRegistry.get(t);return b&&Object.assign(c.schema,b),this.io==="input"&&r.type==="pipe"&&(delete c.schema.examples,delete c.schema.default,c.schema._prefault&&(c.schema.default=c.schema._prefault)),this.io==="input"&&c.schema._prefault&&((a=c.schema).default??(a.default=c.schema._prefault)),delete c.schema._prefault,this.seen.get(t).schema}emit(t,h){const a={cycles:h?.cycles??"ref",reused:h?.reused??"inline",external:h?.external??void 0},r=this.seen.get(t);if(!r)throw new Error("Unprocessed schema. This is a bug in Zod.");const y=g(f=>{const i=this.target==="draft-2020-12"?"$defs":"definitions";if(a.external){const d=a.external.registry.get(f[0])?.id;if(d)return{ref:a.external.uri(d)};const p=f[1].defId??f[1].schema.id??`schema${this.counter++}`;return f[1].defId=p,{defId:p,ref:`${a.external.uri("__shared")}#/${i}/${p}`}}if(f[1]===r)return{ref:"#"};const n=`#/${i}/`,o=f[1].schema.id??`__schema${this.counter++}`;return{defId:o,ref:n+o}},"makeURI"),c=g(f=>{if(f[1].schema.$ref)return;const i=f[1],{ref:e,defId:n}=y(f);i.def={...i.schema},n&&(i.defId=n);const o=i.schema;for(const d in o)delete o[d],o.$ref=e},"extractToDef");for(const f of this.seen.entries()){const i=f[1];if(t===f[0]){c(f);continue}if(a.external){const n=a.external.registry.get(f[0])?.id;if(t!==f[0]&&n){c(f);continue}}if(this.metadataRegistry.get(f[0])?.id){c(f);continue}if(i.cycle){if(a.cycles==="throw")throw new Error(`Cycle detected: #/${i.cycle?.join("/")}/<root>
2
2
 
3
- Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.`);a.cycles==="ref"&&c(f);continue}if(i.count>1&&a.reused==="ref"){c(f);continue}}const s=g((f,i)=>{const e=this.seen.get(f),n=e.def??e.schema,o={...n};if(e.ref===null)return;const d=e.ref;if(e.ref=null,d){s(d,i);const p=this.seen.get(d).schema;p.$ref&&i.target==="draft-7"?(n.allOf=n.allOf??[],n.allOf.push(p)):(Object.assign(n,p),Object.assign(n,o))}e.isParent||this.override({zodSchema:f,jsonSchema:n})},"flattenRef");for(const f of[...this.seen.entries()].reverse())s(f[0],{target:this.target});const m={...r.def},b=a.external?.defs??{};for(const f of this.seen.entries()){const i=f[1];i.def&&i.defId&&(b[i.defId]=i.def)}!a.external&&Object.keys(b).length>0&&(this.target==="draft-2020-12"?m.$defs=b:m.definitions=b),this.target==="draft-2020-12"?m.$schema="https://json-schema.org/draft-2020-12/schema":this.target==="draft-7"?m.$schema="https://json-schema.org/draft-07/schema":console.warn(`Invalid target: ${this.target}`);try{return JSON.parse(JSON.stringify(m))}catch{throw new Error("Error converting schema to JSON.")}}}function P(l,t){if(l instanceof k){const a=new x(t),r={};for(const s of l._idmap.entries()){const[m,b]=s;a.process(b)}const y={},c={registry:l,uri:t?.uri||(s=>s),defs:r};for(const s of l._idmap.entries()){const[m,b]=s;y[m]=a.emit(b,{...t,external:c})}if(Object.keys(r).length>0){const s=a.target==="draft-2020-12"?"$defs":"definitions";y.__shared={[s]:r}}return{schemas:y}}const h=new x(t);return h.process(l),h.emit(l,t)}g(P,"toJSONSchema");const M=g(async()=>async(l,t)=>{const h=l;if("_zod"in h)return P(h,{target:"draft-7"});{const{zodToJsonSchema:a}=await J.tryImport(import("zod-to-json-schema"),"zod-to-json-schema");return a(h,t)}},"getToJsonSchemaFn");exports.getToJsonSchemaFn=M;
3
+ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.`);a.cycles==="ref"&&c(f);continue}if(i.count>1&&a.reused==="ref"){c(f);continue}}const s=g((f,i)=>{const e=this.seen.get(f),n=e.def??e.schema,o={...n};if(e.ref===null)return;const d=e.ref;if(e.ref=null,d){s(d,i);const p=this.seen.get(d).schema;p.$ref&&i.target==="draft-7"?(n.allOf=n.allOf??[],n.allOf.push(p)):(Object.assign(n,p),Object.assign(n,o))}e.isParent||this.override({zodSchema:f,jsonSchema:n})},"flattenRef");for(const f of[...this.seen.entries()].reverse())s(f[0],{target:this.target});const m={...r.def},b=a.external?.defs??{};for(const f of this.seen.entries()){const i=f[1];i.def&&i.defId&&(b[i.defId]=i.def)}!a.external&&Object.keys(b).length>0&&(this.target==="draft-2020-12"?m.$defs=b:m.definitions=b),this.target==="draft-2020-12"?m.$schema="https://json-schema.org/draft-2020-12/schema":this.target==="draft-7"?m.$schema="https://json-schema.org/draft-07/schema":console.warn(`Invalid target: ${this.target}`);try{return JSON.parse(JSON.stringify(m))}catch{throw new Error("Error converting schema to JSON.")}}}function P(l,t){if(l instanceof k){const a=new x(t),r={};for(const s of l._idmap.entries()){const[m,b]=s;a.process(b)}const y={},c={registry:l,uri:t?.uri||(s=>s),defs:r};for(const s of l._idmap.entries()){const[m,b]=s;y[m]=a.emit(b,{...t,external:c})}if(Object.keys(r).length>0){const s=a.target==="draft-2020-12"?"$defs":"definitions";y.__shared={[s]:r}}return{schemas:y}}const h=new x(t);return h.process(l),h.emit(l,t)}g(P,"toJSONSchema");const M=g(async()=>async(l,t)=>{const h=l;if("_zod"in h)return P(h,{target:"draft-7",unrepresentable:"any"});{const{zodToJsonSchema:a}=await J.tryImport(import("zod-to-json-schema"),"zod-to-json-schema");return a(h,t)}},"getToJsonSchemaFn");exports.getToJsonSchemaFn=M;
@@ -1,3 +1,3 @@
1
- var x=Object.defineProperty;var g=(d,r)=>x(d,"name",{value:r,configurable:!0});import{t as O}from"./index-I9ikUX_B.js";class k{static{g(this,"$ZodRegistry")}constructor(){this._map=new WeakMap,this._idmap=new Map}add(r,...p){const o=p[0];if(this._map.set(r,o),o&&typeof o=="object"&&"id"in o){if(this._idmap.has(o.id))throw new Error(`ID ${o.id} already exists in the registry`);this._idmap.set(o.id,r)}return this}remove(r){return this._map.delete(r),this}get(r){const p=r._zod.parent;if(p){const o={...this.get(p)??{}};return delete o.id,{...o,...this._map.get(r)}}return this._map.get(r)}has(r){return this._map.has(r)}}function _(){return new k}g(_,"registry");const j=_(),v={guid:"uuid",url:"uri",datetime:"date-time",json_string:"json-string"};class S{static{g(this,"JSONSchemaGenerator")}constructor(r){this.counter=0,this.metadataRegistry=r?.metadata??j,this.target=r?.target??"draft-2020-12",this.unrepresentable=r?.unrepresentable??"throw",this.override=r?.override??(()=>{}),this.io=r?.io??"output",this.seen=new Map}process(r,p={path:[],schemaPath:[]}){var o;const t=r._zod.def,y=this.seen.get(r);if(y)return y.count++,p.schemaPath.includes(r)&&(y.cycle=p.path),y.count++,y.schema;const c={schema:{},count:1,cycle:void 0};this.seen.set(r,c),r._zod.toJSONSchema&&(c.schema=r._zod.toJSONSchema());const s={...p,schemaPath:[...p.schemaPath,r],path:p.path},m=r._zod.parent;if(m)c.ref=m,this.process(m,s),this.seen.get(m).isParent=!0;else{const i=c.schema;switch(t.type){case"string":{const e=i;e.type="string";const{minimum:n,maximum:a,format:l,pattern:h,contentEncoding:u}=r._zod.bag;typeof n=="number"&&(e.minLength=n),typeof a=="number"&&(e.maxLength=a),l&&(e.format=v[l]??l),h&&(e.pattern=h.source),u&&(e.contentEncoding=u);break}case"number":{const e=i,{minimum:n,maximum:a,format:l,multipleOf:h,exclusiveMaximum:u,exclusiveMinimum:w}=r._zod.bag;typeof l=="string"&&l.includes("int")?e.type="integer":e.type="number",typeof w=="number"&&(e.exclusiveMinimum=w),typeof n=="number"&&(e.minimum=n,typeof w=="number"&&(w>=n?delete e.minimum:delete e.exclusiveMinimum)),typeof u=="number"&&(e.exclusiveMaximum=u),typeof a=="number"&&(e.maximum=a,typeof u=="number"&&(u<=a?delete e.maximum:delete e.exclusiveMaximum)),typeof h=="number"&&(e.multipleOf=h);break}case"boolean":{const e=i;e.type="boolean";break}case"bigint":{if(this.unrepresentable==="throw")throw new Error("BigInt cannot be represented in JSON Schema");break}case"symbol":{if(this.unrepresentable==="throw")throw new Error("Symbols cannot be represented in JSON Schema");break}case"undefined":{const e=i;e.type="null";break}case"null":{i.type="null";break}case"any":break;case"unknown":break;case"never":{i.not={};break}case"void":{if(this.unrepresentable==="throw")throw new Error("Void cannot be represented in JSON Schema");break}case"date":{if(this.unrepresentable==="throw")throw new Error("Date cannot be represented in JSON Schema");break}case"array":{const e=i,{minimum:n,maximum:a}=r._zod.bag;typeof n=="number"&&(e.minItems=n),typeof a=="number"&&(e.maxItems=a),e.type="array",e.items=this.process(t.element,{...s,path:[...s.path,"items"]});break}case"object":{const e=i;e.type="object",e.properties={};const n=t.shape;for(const h in n)e.properties[h]=this.process(n[h],{...s,path:[...s.path,"properties",h]});const a=new Set(Object.keys(n)),l=new Set([...a].filter(h=>{const u=t.shape[h]._zod;return this.io==="input"?u.optin===void 0:u.optout===void 0}));e.required=Array.from(l),t.catchall?._zod.def.type==="never"?e.additionalProperties=!1:t.catchall&&(e.additionalProperties=this.process(t.catchall,{...s,path:[...s.path,"additionalProperties"]}));break}case"union":{const e=i;e.anyOf=t.options.map((n,a)=>this.process(n,{...s,path:[...s.path,"anyOf",a]}));break}case"intersection":{const e=i;e.allOf=[this.process(t.left,{...s,path:[...s.path,"allOf",0]}),this.process(t.right,{...s,path:[...s.path,"allOf",1]})];break}case"tuple":{const e=i;e.type="array";const n=t.items.map((h,u)=>this.process(h,{...s,path:[...s.path,"prefixItems",u]}));if(this.target==="draft-2020-12"?e.prefixItems=n:e.items=n,t.rest){const h=this.process(t.rest,{...s,path:[...s.path,"items"]});this.target==="draft-2020-12"?e.items=h:e.additionalItems=h}t.rest&&(e.items=this.process(t.rest,{...s,path:[...s.path,"items"]}));const{minimum:a,maximum:l}=r._zod.bag;typeof a=="number"&&(e.minItems=a),typeof l=="number"&&(e.maxItems=l);break}case"record":{const e=i;e.type="object",e.propertyNames=this.process(t.keyType,{...s,path:[...s.path,"propertyNames"]}),e.additionalProperties=this.process(t.valueType,{...s,path:[...s.path,"additionalProperties"]});break}case"map":{if(this.unrepresentable==="throw")throw new Error("Map cannot be represented in JSON Schema");break}case"set":{if(this.unrepresentable==="throw")throw new Error("Set cannot be represented in JSON Schema");break}case"enum":{const e=i;e.enum=Object.values(t.entries);break}case"literal":{const e=i,n=[];for(const a of t.values)if(a===void 0){if(this.unrepresentable==="throw")throw new Error("Literal `undefined` cannot be represented in JSON Schema")}else if(typeof a=="bigint"){if(this.unrepresentable==="throw")throw new Error("BigInt literals cannot be represented in JSON Schema");n.push(Number(a))}else n.push(a);if(n.length!==0)if(n.length===1){const a=n[0];e.const=a}else e.enum=n;break}case"file":{if(this.unrepresentable==="throw")throw new Error("File cannot be represented in JSON Schema");break}case"transform":{if(this.unrepresentable==="throw")throw new Error("Transforms cannot be represented in JSON Schema");break}case"nullable":{const e=this.process(t.innerType,s);i.anyOf=[e,{type:"null"}];break}case"nonoptional":{this.process(t.innerType,s),c.ref=t.innerType;break}case"success":{const e=i;e.type="boolean";break}case"default":{this.process(t.innerType,s),c.ref=t.innerType,i.default=t.defaultValue;break}case"prefault":{this.process(t.innerType,s),c.ref=t.innerType,this.io==="input"&&(i._prefault=t.defaultValue);break}case"catch":{this.process(t.innerType,s),c.ref=t.innerType;let e;try{e=t.catchValue(void 0)}catch{throw new Error("Dynamic catch values are not supported in JSON Schema")}i.default=e;break}case"nan":{if(this.unrepresentable==="throw")throw new Error("NaN cannot be represented in JSON Schema");break}case"template_literal":{const e=i,n=r._zod.pattern;if(!n)throw new Error("Pattern not found in template literal");e.type="string",e.pattern=n.source;break}case"pipe":{const e=this.io==="input"?t.in:t.out;this.process(e,s),c.ref=e;break}case"readonly":{this.process(t.innerType,s),c.ref=t.innerType,i.readOnly=!0;break}case"promise":{this.process(t.innerType,s),c.ref=t.innerType;break}case"optional":{this.process(t.innerType,s),c.ref=t.innerType;break}case"lazy":{const e=r._zod.innerType;this.process(e,s),c.ref=e;break}case"custom":{if(this.unrepresentable==="throw")throw new Error("Custom types cannot be represented in JSON Schema");break}}}const b=this.metadataRegistry.get(r);return b&&Object.assign(c.schema,b),this.io==="input"&&t.type==="pipe"&&(delete c.schema.examples,delete c.schema.default,c.schema._prefault&&(c.schema.default=c.schema._prefault)),this.io==="input"&&c.schema._prefault&&((o=c.schema).default??(o.default=c.schema._prefault)),delete c.schema._prefault,this.seen.get(r).schema}emit(r,p){const o={cycles:p?.cycles??"ref",reused:p?.reused??"inline",external:p?.external??void 0},t=this.seen.get(r);if(!t)throw new Error("Unprocessed schema. This is a bug in Zod.");const y=g(f=>{const i=this.target==="draft-2020-12"?"$defs":"definitions";if(o.external){const l=o.external.registry.get(f[0])?.id;if(l)return{ref:o.external.uri(l)};const h=f[1].defId??f[1].schema.id??`schema${this.counter++}`;return f[1].defId=h,{defId:h,ref:`${o.external.uri("__shared")}#/${i}/${h}`}}if(f[1]===t)return{ref:"#"};const n=`#/${i}/`,a=f[1].schema.id??`__schema${this.counter++}`;return{defId:a,ref:n+a}},"makeURI"),c=g(f=>{if(f[1].schema.$ref)return;const i=f[1],{ref:e,defId:n}=y(f);i.def={...i.schema},n&&(i.defId=n);const a=i.schema;for(const l in a)delete a[l],a.$ref=e},"extractToDef");for(const f of this.seen.entries()){const i=f[1];if(r===f[0]){c(f);continue}if(o.external){const n=o.external.registry.get(f[0])?.id;if(r!==f[0]&&n){c(f);continue}}if(this.metadataRegistry.get(f[0])?.id){c(f);continue}if(i.cycle){if(o.cycles==="throw")throw new Error(`Cycle detected: #/${i.cycle?.join("/")}/<root>
1
+ var x=Object.defineProperty;var g=(d,r)=>x(d,"name",{value:r,configurable:!0});import{t as O}from"./index-Dfd7JFus.js";class k{static{g(this,"$ZodRegistry")}constructor(){this._map=new WeakMap,this._idmap=new Map}add(r,...p){const o=p[0];if(this._map.set(r,o),o&&typeof o=="object"&&"id"in o){if(this._idmap.has(o.id))throw new Error(`ID ${o.id} already exists in the registry`);this._idmap.set(o.id,r)}return this}remove(r){return this._map.delete(r),this}get(r){const p=r._zod.parent;if(p){const o={...this.get(p)??{}};return delete o.id,{...o,...this._map.get(r)}}return this._map.get(r)}has(r){return this._map.has(r)}}function _(){return new k}g(_,"registry");const j=_(),v={guid:"uuid",url:"uri",datetime:"date-time",json_string:"json-string"};class S{static{g(this,"JSONSchemaGenerator")}constructor(r){this.counter=0,this.metadataRegistry=r?.metadata??j,this.target=r?.target??"draft-2020-12",this.unrepresentable=r?.unrepresentable??"throw",this.override=r?.override??(()=>{}),this.io=r?.io??"output",this.seen=new Map}process(r,p={path:[],schemaPath:[]}){var o;const t=r._zod.def,y=this.seen.get(r);if(y)return y.count++,p.schemaPath.includes(r)&&(y.cycle=p.path),y.count++,y.schema;const c={schema:{},count:1,cycle:void 0};this.seen.set(r,c),r._zod.toJSONSchema&&(c.schema=r._zod.toJSONSchema());const s={...p,schemaPath:[...p.schemaPath,r],path:p.path},m=r._zod.parent;if(m)c.ref=m,this.process(m,s),this.seen.get(m).isParent=!0;else{const i=c.schema;switch(t.type){case"string":{const e=i;e.type="string";const{minimum:n,maximum:a,format:l,pattern:h,contentEncoding:u}=r._zod.bag;typeof n=="number"&&(e.minLength=n),typeof a=="number"&&(e.maxLength=a),l&&(e.format=v[l]??l),h&&(e.pattern=h.source),u&&(e.contentEncoding=u);break}case"number":{const e=i,{minimum:n,maximum:a,format:l,multipleOf:h,exclusiveMaximum:u,exclusiveMinimum:w}=r._zod.bag;typeof l=="string"&&l.includes("int")?e.type="integer":e.type="number",typeof w=="number"&&(e.exclusiveMinimum=w),typeof n=="number"&&(e.minimum=n,typeof w=="number"&&(w>=n?delete e.minimum:delete e.exclusiveMinimum)),typeof u=="number"&&(e.exclusiveMaximum=u),typeof a=="number"&&(e.maximum=a,typeof u=="number"&&(u<=a?delete e.maximum:delete e.exclusiveMaximum)),typeof h=="number"&&(e.multipleOf=h);break}case"boolean":{const e=i;e.type="boolean";break}case"bigint":{if(this.unrepresentable==="throw")throw new Error("BigInt cannot be represented in JSON Schema");break}case"symbol":{if(this.unrepresentable==="throw")throw new Error("Symbols cannot be represented in JSON Schema");break}case"undefined":{const e=i;e.type="null";break}case"null":{i.type="null";break}case"any":break;case"unknown":break;case"never":{i.not={};break}case"void":{if(this.unrepresentable==="throw")throw new Error("Void cannot be represented in JSON Schema");break}case"date":{if(this.unrepresentable==="throw")throw new Error("Date cannot be represented in JSON Schema");break}case"array":{const e=i,{minimum:n,maximum:a}=r._zod.bag;typeof n=="number"&&(e.minItems=n),typeof a=="number"&&(e.maxItems=a),e.type="array",e.items=this.process(t.element,{...s,path:[...s.path,"items"]});break}case"object":{const e=i;e.type="object",e.properties={};const n=t.shape;for(const h in n)e.properties[h]=this.process(n[h],{...s,path:[...s.path,"properties",h]});const a=new Set(Object.keys(n)),l=new Set([...a].filter(h=>{const u=t.shape[h]._zod;return this.io==="input"?u.optin===void 0:u.optout===void 0}));e.required=Array.from(l),t.catchall?._zod.def.type==="never"?e.additionalProperties=!1:t.catchall&&(e.additionalProperties=this.process(t.catchall,{...s,path:[...s.path,"additionalProperties"]}));break}case"union":{const e=i;e.anyOf=t.options.map((n,a)=>this.process(n,{...s,path:[...s.path,"anyOf",a]}));break}case"intersection":{const e=i;e.allOf=[this.process(t.left,{...s,path:[...s.path,"allOf",0]}),this.process(t.right,{...s,path:[...s.path,"allOf",1]})];break}case"tuple":{const e=i;e.type="array";const n=t.items.map((h,u)=>this.process(h,{...s,path:[...s.path,"prefixItems",u]}));if(this.target==="draft-2020-12"?e.prefixItems=n:e.items=n,t.rest){const h=this.process(t.rest,{...s,path:[...s.path,"items"]});this.target==="draft-2020-12"?e.items=h:e.additionalItems=h}t.rest&&(e.items=this.process(t.rest,{...s,path:[...s.path,"items"]}));const{minimum:a,maximum:l}=r._zod.bag;typeof a=="number"&&(e.minItems=a),typeof l=="number"&&(e.maxItems=l);break}case"record":{const e=i;e.type="object",e.propertyNames=this.process(t.keyType,{...s,path:[...s.path,"propertyNames"]}),e.additionalProperties=this.process(t.valueType,{...s,path:[...s.path,"additionalProperties"]});break}case"map":{if(this.unrepresentable==="throw")throw new Error("Map cannot be represented in JSON Schema");break}case"set":{if(this.unrepresentable==="throw")throw new Error("Set cannot be represented in JSON Schema");break}case"enum":{const e=i;e.enum=Object.values(t.entries);break}case"literal":{const e=i,n=[];for(const a of t.values)if(a===void 0){if(this.unrepresentable==="throw")throw new Error("Literal `undefined` cannot be represented in JSON Schema")}else if(typeof a=="bigint"){if(this.unrepresentable==="throw")throw new Error("BigInt literals cannot be represented in JSON Schema");n.push(Number(a))}else n.push(a);if(n.length!==0)if(n.length===1){const a=n[0];e.const=a}else e.enum=n;break}case"file":{if(this.unrepresentable==="throw")throw new Error("File cannot be represented in JSON Schema");break}case"transform":{if(this.unrepresentable==="throw")throw new Error("Transforms cannot be represented in JSON Schema");break}case"nullable":{const e=this.process(t.innerType,s);i.anyOf=[e,{type:"null"}];break}case"nonoptional":{this.process(t.innerType,s),c.ref=t.innerType;break}case"success":{const e=i;e.type="boolean";break}case"default":{this.process(t.innerType,s),c.ref=t.innerType,i.default=t.defaultValue;break}case"prefault":{this.process(t.innerType,s),c.ref=t.innerType,this.io==="input"&&(i._prefault=t.defaultValue);break}case"catch":{this.process(t.innerType,s),c.ref=t.innerType;let e;try{e=t.catchValue(void 0)}catch{throw new Error("Dynamic catch values are not supported in JSON Schema")}i.default=e;break}case"nan":{if(this.unrepresentable==="throw")throw new Error("NaN cannot be represented in JSON Schema");break}case"template_literal":{const e=i,n=r._zod.pattern;if(!n)throw new Error("Pattern not found in template literal");e.type="string",e.pattern=n.source;break}case"pipe":{const e=this.io==="input"?t.in:t.out;this.process(e,s),c.ref=e;break}case"readonly":{this.process(t.innerType,s),c.ref=t.innerType,i.readOnly=!0;break}case"promise":{this.process(t.innerType,s),c.ref=t.innerType;break}case"optional":{this.process(t.innerType,s),c.ref=t.innerType;break}case"lazy":{const e=r._zod.innerType;this.process(e,s),c.ref=e;break}case"custom":{if(this.unrepresentable==="throw")throw new Error("Custom types cannot be represented in JSON Schema");break}}}const b=this.metadataRegistry.get(r);return b&&Object.assign(c.schema,b),this.io==="input"&&t.type==="pipe"&&(delete c.schema.examples,delete c.schema.default,c.schema._prefault&&(c.schema.default=c.schema._prefault)),this.io==="input"&&c.schema._prefault&&((o=c.schema).default??(o.default=c.schema._prefault)),delete c.schema._prefault,this.seen.get(r).schema}emit(r,p){const o={cycles:p?.cycles??"ref",reused:p?.reused??"inline",external:p?.external??void 0},t=this.seen.get(r);if(!t)throw new Error("Unprocessed schema. This is a bug in Zod.");const y=g(f=>{const i=this.target==="draft-2020-12"?"$defs":"definitions";if(o.external){const l=o.external.registry.get(f[0])?.id;if(l)return{ref:o.external.uri(l)};const h=f[1].defId??f[1].schema.id??`schema${this.counter++}`;return f[1].defId=h,{defId:h,ref:`${o.external.uri("__shared")}#/${i}/${h}`}}if(f[1]===t)return{ref:"#"};const n=`#/${i}/`,a=f[1].schema.id??`__schema${this.counter++}`;return{defId:a,ref:n+a}},"makeURI"),c=g(f=>{if(f[1].schema.$ref)return;const i=f[1],{ref:e,defId:n}=y(f);i.def={...i.schema},n&&(i.defId=n);const a=i.schema;for(const l in a)delete a[l],a.$ref=e},"extractToDef");for(const f of this.seen.entries()){const i=f[1];if(r===f[0]){c(f);continue}if(o.external){const n=o.external.registry.get(f[0])?.id;if(r!==f[0]&&n){c(f);continue}}if(this.metadataRegistry.get(f[0])?.id){c(f);continue}if(i.cycle){if(o.cycles==="throw")throw new Error(`Cycle detected: #/${i.cycle?.join("/")}/<root>
2
2
 
3
- Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.`);o.cycles==="ref"&&c(f);continue}if(i.count>1&&o.reused==="ref"){c(f);continue}}const s=g((f,i)=>{const e=this.seen.get(f),n=e.def??e.schema,a={...n};if(e.ref===null)return;const l=e.ref;if(e.ref=null,l){s(l,i);const h=this.seen.get(l).schema;h.$ref&&i.target==="draft-7"?(n.allOf=n.allOf??[],n.allOf.push(h)):(Object.assign(n,h),Object.assign(n,a))}e.isParent||this.override({zodSchema:f,jsonSchema:n})},"flattenRef");for(const f of[...this.seen.entries()].reverse())s(f[0],{target:this.target});const m={...t.def},b=o.external?.defs??{};for(const f of this.seen.entries()){const i=f[1];i.def&&i.defId&&(b[i.defId]=i.def)}!o.external&&Object.keys(b).length>0&&(this.target==="draft-2020-12"?m.$defs=b:m.definitions=b),this.target==="draft-2020-12"?m.$schema="https://json-schema.org/draft-2020-12/schema":this.target==="draft-7"?m.$schema="https://json-schema.org/draft-07/schema":console.warn(`Invalid target: ${this.target}`);try{return JSON.parse(JSON.stringify(m))}catch{throw new Error("Error converting schema to JSON.")}}}function N(d,r){if(d instanceof k){const o=new S(r),t={};for(const s of d._idmap.entries()){const[m,b]=s;o.process(b)}const y={},c={registry:d,uri:r?.uri||(s=>s),defs:t};for(const s of d._idmap.entries()){const[m,b]=s;y[m]=o.emit(b,{...r,external:c})}if(Object.keys(t).length>0){const s=o.target==="draft-2020-12"?"$defs":"definitions";y.__shared={[s]:t}}return{schemas:y}}const p=new S(r);return p.process(d),p.emit(d,r)}g(N,"toJSONSchema");const T=g(async()=>async(d,r)=>{const p=d;if("_zod"in p)return N(p,{target:"draft-7"});{const{zodToJsonSchema:o}=await O(import("zod-to-json-schema"),"zod-to-json-schema");return o(p,r)}},"getToJsonSchemaFn");export{T as getToJsonSchemaFn};
3
+ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.`);o.cycles==="ref"&&c(f);continue}if(i.count>1&&o.reused==="ref"){c(f);continue}}const s=g((f,i)=>{const e=this.seen.get(f),n=e.def??e.schema,a={...n};if(e.ref===null)return;const l=e.ref;if(e.ref=null,l){s(l,i);const h=this.seen.get(l).schema;h.$ref&&i.target==="draft-7"?(n.allOf=n.allOf??[],n.allOf.push(h)):(Object.assign(n,h),Object.assign(n,a))}e.isParent||this.override({zodSchema:f,jsonSchema:n})},"flattenRef");for(const f of[...this.seen.entries()].reverse())s(f[0],{target:this.target});const m={...t.def},b=o.external?.defs??{};for(const f of this.seen.entries()){const i=f[1];i.def&&i.defId&&(b[i.defId]=i.def)}!o.external&&Object.keys(b).length>0&&(this.target==="draft-2020-12"?m.$defs=b:m.definitions=b),this.target==="draft-2020-12"?m.$schema="https://json-schema.org/draft-2020-12/schema":this.target==="draft-7"?m.$schema="https://json-schema.org/draft-07/schema":console.warn(`Invalid target: ${this.target}`);try{return JSON.parse(JSON.stringify(m))}catch{throw new Error("Error converting schema to JSON.")}}}function N(d,r){if(d instanceof k){const o=new S(r),t={};for(const s of d._idmap.entries()){const[m,b]=s;o.process(b)}const y={},c={registry:d,uri:r?.uri||(s=>s),defs:t};for(const s of d._idmap.entries()){const[m,b]=s;y[m]=o.emit(b,{...r,external:c})}if(Object.keys(t).length>0){const s=o.target==="draft-2020-12"?"$defs":"definitions";y.__shared={[s]:t}}return{schemas:y}}const p=new S(r);return p.process(d),p.emit(d,r)}g(N,"toJSONSchema");const T=g(async()=>async(d,r)=>{const p=d;if("_zod"in p)return N(p,{target:"draft-7",unrepresentable:"any"});{const{zodToJsonSchema:o}=await O(import("zod-to-json-schema"),"zod-to-json-schema");return o(p,r)}},"getToJsonSchemaFn");export{T as getToJsonSchemaFn};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kingbri1/standard-json",
3
- "version": "0.2.1-pre1",
3
+ "version": "0.2.1-pre2",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.cjs",