@orval/zod 6.17.0 → 6.18.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +5 -5
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }var _core = require('@orval/core');var _lodashuniq = require('lodash.uniq'); var _lodashuniq2 = _interopRequireDefault(_lodashuniq);var
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }var _core = require('@orval/core');var _lodashuniq = require('lodash.uniq'); var _lodashuniq2 = _interopRequireDefault(_lodashuniq);var _=[{exports:[{name:"z",alias:"zod",values:!0}],dependency:"zod"}],N= exports.getZodDependencies =()=>_,T=e=>{switch(e){case"integer":return"number";case"null":return"mixed";default:return e!=null?e:"any"}},D=(e,d,t)=>{var Z,k,x,O,q,G,W,$,g,h,z,y;if(!e)return{functions:[],consts:[]};let b=[],n=[],r=T(e.type),i=e.default!==void 0?!1:d!=null?d:!1,s=(Z=e.nullable)!=null?Z:!1,u=(q=(O=(x=(k=e.minimum)!=null?k:e.exclusiveMinimum)!=null?x:e.minLength)!=null?O:e.minItems)!=null?q:void 0,f=(g=($=(W=(G=e.maximum)!=null?G:e.exclusiveMaximum)!=null?W:e.maxLength)!=null?$:e.maxItems)!=null?g:void 0,a=(h=e.pattern)!=null?h:void 0;switch(r){case"array":let m=e.items;n.push(["array",D(m,!0,_core.camel.call(void 0, t))]);break;case"string":{if(e.enum&&r==="string")break;if(n.push([r,void 0]),e.format==="date"){n.push(["regex","new RegExp(/^[0-9]{4}-[0-9]{2}-[0-9]{2}$/)"]);break}if(e.format==="date-time"){n.push(["datetime",void 0]);break}if(e.format==="email"){n.push(["email",void 0]);break}if(e.format==="uri"||e.format==="hostname"){n.push(["url",void 0]);break}if(e.format==="uuid"){n.push(["uuid",void 0]);break}break}case"object":default:{if(e.allOf||e.oneOf||e.anyOf){let p=e.allOf?"allOf":e.oneOf?"oneOf":"anyOf",l=(y=(z=e.allOf)!=null?z:e.oneOf)!=null?y:e.anyOf;n.push([p,l.map(P=>D(P,!0,_core.camel.call(void 0, t)))]);break}if(e.properties){n.push(["object",Object.keys(e.properties).map(p=>{var l,P;return{[p]:D((l=e.properties)==null?void 0:l[p],(P=e.required)==null?void 0:P.includes(p),_core.camel.call(void 0, `${t}-${p}`))}}).reduce((p,l)=>({...p,...l}),{})]);break}if(e.additionalProperties){n.push(["additionalProperties",_core.isBoolean.call(void 0, e.additionalProperties)?e.additionalProperties:D(e.additionalProperties,!0,t)]);break}n.push([r,void 0]);break}}if(u!==void 0&&(u===1?n.push(["min",`${u}`]):(b.push(`export const ${t}Min = ${u};`),n.push(["min",`${t}Min`]))),f!==void 0&&(b.push(`export const ${t}Max = ${f};`),n.push(["max",`${t}Max`])),a){let m=a.startsWith("/"),p=a.endsWith("/"),l=`new RegExp('${_core.jsStringEscape.call(void 0, a.slice(m?1:0,p?-1:void 0))}')`;b.push(`export const ${t}RegExp = ${l};`),n.push(["regex",`${t}RegExp`])}return e.enum&&r!=="number"&&n.push(["enum",[`[${e.enum.map(m=>_core.isString.call(void 0, m)?`'${_core.escape.call(void 0, m)}'`:`${m}`).join(", ")}]`]]),!i&&s?n.push(["nullish",void 0]):s?n.push(["nullable",void 0]):i||n.push(["optional",void 0]),{functions:n,consts:_lodashuniq2.default.call(void 0, b)}},B=e=>{if(!Object.keys(e).length)return{zod:"",consts:""};let d="",t=n=>{let[r,i=""]=n;if(r==="allOf")return i.reduce((s,{functions:u})=>{let f=u.map(t).join(""),a=`${f.startsWith(".")?"zod":""}${f}`;return s?(s+=`.and(${a})`,s):(s+=a,s)},"");if(r==="oneOf"||r==="anyOf")return i.reduce((s,{functions:u})=>{let f=u.map(t).join(""),a=`${f.startsWith(".")?"zod":""}${f}`;return s?(s+=`.or(${a})`,s):(s+=a,s)},"");if(r==="additionalProperties"){let s=i.functions.map(t).join(""),u=`${s.startsWith(".")?"zod":""}${s}`;return d+=i.consts,`zod.record(zod.string(), ${u})`}if(r==="object"){let s=B(i);return d+=s.consts,` ${s.zod}`}if(r==="array"){let s=i.functions.map(t).join("");return d+=i.consts,`.array(${s.startsWith(".")?"zod":""}${s})`}return`.${r}(${i})`};return d+=Object.entries(e).reduce((n,[r,i])=>n+i.consts.join(`
|
|
2
2
|
`),""),{zod:`zod.object({
|
|
3
|
-
${Object.entries(e).map(([n,
|
|
4
|
-
})`,consts:d}},
|
|
3
|
+
${Object.entries(e).map(([n,r])=>{let i=r.functions.map(t).join("");return`"${n}": ${i.startsWith(".")?"zod":""}${i}`}).join(",")}
|
|
4
|
+
})`,consts:d}},K=(e,d)=>_core.isObject.call(void 0, e)?I(e,d):Array.isArray(e)?e.map(t=>K(t,d)):e,I=(e,d)=>{var r;let t="$ref"in e?e.$ref:void 0;if(t&&((r=d.parents)==null?void 0:r.includes(t)))return{};let b={...d,...t?{parents:[...d.parents||[],t]}:void 0},{schema:n}=_core.resolveRef.call(void 0, e,b);return Object.entries(n).reduce((i,[s,u])=>(i[s]=K(u,b),i),{})},J=({operationName:e,body:d,verb:t},{pathRoute:b,context:n})=>{var m,p,l,P,M,w,A,H,L,Q;let r=n.specs[n.specKey].paths[b],i=(m=r==null?void 0:r[t])==null?void 0:m.parameters,s=(p=r==null?void 0:r[t])==null?void 0:p.requestBody,u=(P=(l=r==null?void 0:r[t])==null?void 0:l.responses)==null?void 0:P["200"],f=u?_core.resolveRef.call(void 0, u,n).schema:void 0,a=(w=(M=f==null?void 0:f.content)==null?void 0:M["application/json"])!=null&&w.schema?_core.resolveRef.call(void 0, f.content["application/json"].schema,n).schema:void 0,Z=(A=a==null?void 0:a.properties)!=null?A:{},k=Object.entries(Z).map(([o,j])=>{var S;let c=I(j,n);return{[o]:D(c,!!((S=a==null?void 0:a.required)!=null&&S.find(R=>R===o)),_core.camel.call(void 0, `${e}-response-${o}`))}}).reduce((o,j)=>({...o,...j}),{}),x=s?_core.resolveRef.call(void 0, s,n).schema:void 0,O=(L=(H=x==null?void 0:x.content)==null?void 0:H["application/json"])!=null&&L.schema?_core.resolveRef.call(void 0, x.content["application/json"].schema,n).schema:void 0,q=(Q=O==null?void 0:O.properties)!=null?Q:{},G=Object.entries(q).map(([o,j])=>{var S;let c=I(j,n);return{[o]:D(c,!!((S=O==null?void 0:O.required)!=null&&S.find(R=>R===o)),_core.camel.call(void 0, `${e}-body-${o}`))}}).reduce((o,j)=>({...o,...j}),{}),W=(i!=null?i:[]).reduce((o,j)=>{let{schema:c}=_core.resolveRef.call(void 0, j,n);if(!c.schema)return o;let S=I(c.schema,n),R=D(S,c.required,_core.camel.call(void 0, `${e}-${c.in}-${c.name}`));return c.in==="header"?{...o,headers:{...o.headers,[c.name]:R}}:c.in==="query"?{...o,queryParams:{...o.queryParams,[c.name]:R}}:c.in==="path"?{...o,params:{...o.params,[c.name]:R}}:o},{headers:{},queryParams:{},params:{}}),$=B(W.params),g=B(W.queryParams),h=B(W.headers),z=B(G),y=B(k);return!$.zod&&!g.zod&&!h.zod&&!z.zod&&!y.zod?"":[...$.consts?[$.consts]:[],...$.zod?[`export const ${e}Params = ${$.zod}`]:[],...g.consts?[g.consts]:[],...g.zod?[`export const ${e}QueryParams = ${g.zod}`]:[],...h.consts?[h.consts]:[],...h.zod?[`export const ${e}Header = ${h.zod}`]:[],...z.consts?[z.consts]:[],...z.zod?[`export const ${e}Body = ${z.zod}`]:[],...y.consts?[y.consts]:[],...y.zod?[`export const ${e}Response = ${y.zod}`]:[]].join(`
|
|
5
5
|
|
|
6
|
-
`)},
|
|
6
|
+
`)},ee= exports.generateZod =(e,d)=>{let t=J(e,d);return{implementation:t?`${t}
|
|
7
7
|
|
|
8
|
-
`:"",imports:[]}},
|
|
8
|
+
`:"",imports:[]}},ne={client:ee,dependencies:N},te= exports.builder =()=>()=>ne,fe= exports.default =te;exports.builder = te; exports.default = fe; exports.generateZod = ee; exports.getZodDependencies = N;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@orval/zod",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.18.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"lint": "eslint src/**/*.ts"
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@orval/core": "6.
|
|
16
|
+
"@orval/core": "6.18.0",
|
|
17
17
|
"lodash.uniq": "^4.5.0"
|
|
18
18
|
},
|
|
19
19
|
"devDependencies": {
|