@hey-api/openapi-ts 0.89.0 → 0.89.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,13 +0,0 @@
1
- import{createRequire as e}from"node:module";import{Project as t,fromRef as n,isNode as r,isRef as i,isSymbol as a,isSymbolRef as o,nodeBrand as s,ref as c,refs as l}from"@hey-api/codegen-core";import u from"ansi-colors";import d from"node:fs";import f from"node:path";import{fileURLToPath as p}from"node:url";import m from"typescript";import{EOL as h}from"node:os";import*as g from"semver";import{getResolvedInput as ee,sendRequest as te}from"@hey-api/json-schema-ref-parser";var ne=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),re=e(import.meta.url);const ie=p(import.meta.url),ae=f.dirname(ie),oe=()=>{let e=ae;for(;e!==f.dirname(e);){let t=d.readdirSync(e).filter(e=>e===`package.json`);if(t[0]){let n=f.join(e,t[0]);return JSON.parse(d.readFileSync(n,{encoding:`utf8`}))}e=f.dirname(e)}},se=()=>{let e=oe(),t={bugs:{url:``},name:``,version:``};return e&&typeof e==`object`&&(`name`in e&&typeof e.name==`string`&&(t.name=e.name),`version`in e&&typeof e.version==`string`&&(t.version=e.version),`bugs`in e&&e.bugs&&typeof e.bugs==`object`&&`url`in e.bugs&&typeof e.bugs.url==`string`&&(t.bugs.url=e.bugs.url,t.bugs.url&&!t.bugs.url.endsWith(`/`)&&(t.bugs.url+=`/`))),t},ce=e=>{if(e===null)return null;if(e){let t=f.isAbsolute(e)?e:f.resolve(ae,e);return d.existsSync(t)?t:null}let t=ae;for(;t!==f.dirname(t);){let e=d.readdirSync(t).filter(e=>e.startsWith(`tsconfig`)&&e.endsWith(`.json`)).sort(e=>e===`tsconfig.json`?-1:1);if(e[0])return f.join(t,e[0]);t=f.dirname(t)}return null},le=e=>{if(!e)return null;let t=m.readConfigFile(e,m.sys.readFile);if(t.error)throw Error(`Couldn't read tsconfig from path: ${e}`);return m.parseJsonConfigFileContent(t.config,m.sys,f.dirname(e))},ue=e=>{d.existsSync(e)||d.mkdirSync(e,{recursive:!0})};var de=class extends Error{constructor(e){super(e),this.name=`ConfigError`}},fe=class extends Error{errors;constructor(e){super(`Found ${e.length} configuration ${e.length===1?`error`:`errors`}.`),this.name=`ConfigValidationError`,this.errors=e}},pe=class extends Error{originalError;constructor(e,t){super(e),this.name=`JobError`,this.originalError=t}},me=class extends Error{args;event;pluginName;constructor({args:e,error:t,event:n,name:r,pluginName:i}){let a=t instanceof Error?t.message:`Unknown error`;super(a),this.args=e,this.cause=t.cause,this.event=n,this.name=r||t.name,this.pluginName=i,this.stack=t.stack}};const he=(e,t)=>{if(e instanceof de||e instanceof fe)return;e instanceof pe&&(e=e.originalError.error);let n=`openapi-ts-error-${Date.now()}.log`,r=f.resolve(process.cwd(),t);ue(r);let i=f.resolve(r,n),a=`[${new Date().toISOString()}] `;e instanceof me&&(a+=`${e.name} during event "${e.event}"\n`,e.pluginName&&(a+=`Plugin: ${e.pluginName}\n`),a+=`Arguments: ${JSON.stringify(e.args,null,2)}\n\n`);let o=e instanceof Error?e.message:String(e),s=e instanceof Error?e.stack:void 0;return a+=`Error: ${o}\n`,s&&(a+=`Stack:\n${s}\n`),d.writeFileSync(i,a),i},ge=async e=>{let t=se();if(!t.bugs.url)return;e instanceof pe&&(e=e.originalError.error);let n=``;e instanceof me&&(e.pluginName&&(n+=`**Plugin**: \`${e.pluginName}\`\n`),n+=`**Event**: \`${e.event}\`\n`,n+=`**Arguments**:\n\`\`\`ts\n${JSON.stringify(e.args,null,2)}\n\`\`\`\n\n`);let r=e instanceof Error?e.message:String(e),i=e instanceof Error?e.stack:void 0;n+=`**Error**: \`${r}\`\n`,i&&(n+=`\n**Stack Trace**:\n\`\`\`\n${i}\n\`\`\``);let a=new URLSearchParams({body:n,labels:`bug 🔥`,title:`Crash Report`}),o=`${t.bugs.url}new?${a.toString()}`,s=(await import(`open`)).default;await s(o)},_e=({error:e,logPath:t})=>{if(e instanceof fe&&e.errors.length){let t=new Map;for(let{error:n,jobIndex:r}of e.errors)t.has(r)||t.set(r,[]),t.get(r).push(n);for(let[e,n]of t.entries()){let t=u.gray(`[Job ${e+1}] `),r=n.length,i=u.red(`Found ${r} configuration ${r===1?`error`:`errors`}:`);console.error(`${t}❗️ ${i}`),n.forEach((e,n)=>{let r=` [${n+1}] `,i=u.red(r);console.error(`${t}${i}${u.white(e.message)}`)})}}else{let t=u.gray(`[root] `);e instanceof pe&&(t=u.gray(`[Job ${e.originalError.jobIndex+1}] `),e=e.originalError.error);let n=u.red(`Failed with the message:`);console.error(`${t}❌ ${n}`);let r=u.red(` `);console.error(`${t}${r}${typeof e==`string`?e:e instanceof Error?e.message:`Unknown error`}`)}if(t){let e=u.gray(`[root] `);console.error(`${e}${u.cyan(`📄 Crash log saved to:`)} ${u.gray(t)}`)}},ve=async({error:e,isInteractive:t})=>!t||e instanceof de||e instanceof fe?!1:new Promise(e=>{let t=u.gray(`[root] `);console.log(`${t}${u.yellow(`📢 Open a GitHub issue with crash details? (y/N):`)}`),process.stdin.setEncoding(`utf8`),process.stdin.once(`data`,t=>{e(t.trim().toLowerCase()===`y`)})}),ye=/^([\w-]+)\/([\w-]+)(?:\?([\w=&.-]*))?$/,be=`https://get.heyapi.dev`,xe=(e,t,n)=>`${be}/${e}/${t}${n?`?${n}`:``}`,Se=e=>{let t=e.organization,n=e.project,r;if(e.path){let i=e.path.match(ye);if(!i)throw Error(`Invalid Hey API shorthand format. Expected "organization/project?queryParams" or "organization/project", received: ${e.path}`);t=i[1],n=i[2],r=i[3]}if(!t)throw Error(`The Hey API organization cannot be empty.`);if(!n)throw Error(`The Hey API project cannot be empty.`);return{organization:t,project:n,queryParams:r}},Ce=e=>{let t=Se(e);return{path:xe(t.organization,t.project,t.queryParams),registry:`hey-api`}},we=/^(@([\w-]+)\/([\w\-.]+)#)?([\w-]+)$/,Te=e=>`https://dash.readme.com/api/v1/api-registry/${e}`,Ee=`readme`,De=e=>{let t=e.match(we);if(!t)throw Error(`Invalid ReadMe shorthand format. Expected "${Ee}:@organization/project#uuid" or "${Ee}:uuid", received: ${Ee}:${e}`);let[,,n,r,i]=t;if(!i)throw Error(`The ReadMe UUID cannot be empty.`);return{organization:n,project:r,uuid:i}},Oe=e=>{let t=De(e.slice(`${Ee}:`.length));return{...t,path:Te(t.uuid),registry:`readme`}},ke=/^(@[\w-]+)\/([\w.-]+)$/,Ae=(e,t)=>`https://registry.scalar.com/${e}/apis/${t}/latest?format=json`,je=`scalar`,Me=e=>{let t=e.match(ke);if(!t)throw Error(`Invalid Scalar shorthand format. Expected "${je}:@organization/project", received: ${je}:${e}`);let[,n,r]=t;if(!n)throw Error(`The Scalar organization cannot be empty.`);if(!r)throw Error(`The Scalar project cannot be empty.`);return{organization:n,project:r}},Ne=e=>{let t=Me(e.slice(`${je}:`.length));return{...t,path:Ae(t.organization,t.project),registry:`scalar`}},Pe=e=>{if(e.path.startsWith(`readme:`)){Object.assign(e,Oe(e.path));return}if(e.path.startsWith(`scalar:`)){Object.assign(e,Ne(e.path));return}if(e.path.startsWith(`.`))return;if(e.path.startsWith(be)){e.path=e.path.slice(23),Object.assign(e,Ce(e));return}let t=e.path.split(`/`);if(t.length===2&&t.filter(Boolean).length===2){Object.assign(e,Ce(e));return}},Fe={enabled:!1,interval:1e3,timeout:6e4},Ie=e=>{let t={...Fe};return typeof e.path==`string`&&(typeof e.watch==`boolean`?t.enabled=e.watch:typeof e.watch==`number`?(t.enabled=!0,t.interval=e.watch):e.watch&&(t={...t,...e.watch})),t},Le=e=>{let t=e.input instanceof Array?e.input:[e.input],n=[];for(let r of t){let t={path:``,watch:Fe};typeof r==`string`?t.path=r:r&&(r.path!==void 0||r.organization!==void 0)?(t={...t,path:be,...r},t.watch!==void 0&&(t.watch=Ie(t))):t={...t,path:r},typeof t.path==`string`&&Pe(t),e.watch!==void 0&&t.watch.enabled===Fe.enabled&&t.watch.interval===Fe.interval&&t.watch.timeout===Fe.timeout&&(t.watch=Ie({path:t.path,watch:e.watch})),t.path&&n.push(t)}return n},Re=e=>{let t={file:!0,level:`info`,path:process.cwd()};return typeof e?.logs==`string`?t.path=e.logs:t={...t,...e?.logs},t},ze=(e,t)=>{let n=e||{},r=t||{};return{...n,...r}},Be=(e,t)=>{let n=e||{},r=t||{},i={...n,...r};return typeof i.logs==`object`&&(i.logs=ze(n.logs,r.logs)),i},Ve=e=>typeof e==`object`&&!!e&&!Array.isArray(e)&&typeof e!=`function`,He=(e,t)=>{for(let[n,r]of Object.entries(t))r!==void 0&&r!==``&&(e[n]=r);return e},_=({defaultValue:e,mappers:t,value:n})=>{let r={...e};switch(typeof n){case`boolean`:if(t&&`boolean`in t){let e=t.boolean;r=He(r,e(n))}break;case`function`:if(t&&`function`in t){let e=t.function;r=He(r,e(n))}break;case`number`:if(t&&`number`in t){let e=t.number;r=He(r,e(n))}break;case`string`:if(t&&`string`in t){let e=t.string;r=He(r,e(n))}break;case`object`:if(Ve(n))if(t&&`object`in t&&typeof t.object==`function`){let i=t.object;r=He(r,i(n,e))}else r=He(r,n);break}return r},Ue=e=>{if(e.output instanceof Array)throw Error(`Unexpected array of outputs in user configuration. This should have been expanded already.`);let t=_({defaultValue:{clean:!0,fileName:{case:`preserve`,name:`{{name}}`,suffix:`.gen`},format:null,indexFile:!0,lint:null,path:``,preferExportAll:!1},mappers:{object:(e,t)=>({...e,fileName:_({defaultValue:{...t.fileName},mappers:{function:e=>({name:e}),string:e=>({name:e})},value:e.fileName})}),string:e=>({path:e})},value:e.output});return t.tsConfig=le(ce(t.tsConfigPath)),t.importFileExtension===void 0&&t.tsConfig?.options.moduleResolution===m.ModuleResolutionKind.NodeNext&&(t.importFileExtension=`.js`),t.importFileExtension&&!t.importFileExtension.startsWith(`.`)&&(t.importFileExtension=`.${t.importFileExtension}`),t},We=e=>{let t=e?f.dirname(e):process.cwd();for(;t!==f.dirname(t);){let e=f.join(t,`package.json`);if(d.existsSync(e))try{let t=JSON.parse(d.readFileSync(e,`utf8`));return{...t.dependencies,...t.devDependencies,...t.peerDependencies,...t.optionalDependencies}}catch{}let n=f.dirname(t);if(n===t)break;t=n}return{}},Ge=[`after`,`before`,`cursor`,`offset`,`page`,`start`],Ke=e=>_({defaultValue:{hooks:{},pagination:{keywords:Ge},transforms:{enums:{case:`PascalCase`,enabled:!1,mode:`root`,name:`{{name}}Enum`},propertiesRequiredByDefault:!1,readWrite:{enabled:!0,requests:{case:`preserve`,name:`{{name}}Writable`},responses:{case:`preserve`,name:`{{name}}`}}},validate_EXPERIMENTAL:!1},mappers:{object:(e,t)=>({...e,pagination:_({defaultValue:{...t.pagination},value:e.pagination}),transforms:_({defaultValue:{...t.transforms},mappers:{object:(e,t)=>({...e,enums:_({defaultValue:{...t.enums,enabled:e.enums===void 0?t.enums.enabled:!!e.enums},mappers:{boolean:e=>({enabled:e}),string:e=>({mode:e})},value:e.enums}),propertiesRequiredByDefault:e.propertiesRequiredByDefault===void 0?t.propertiesRequiredByDefault:e.propertiesRequiredByDefault,readWrite:_({defaultValue:{...t.readWrite,enabled:e.readWrite===void 0?t.readWrite.enabled:!!e.readWrite},mappers:{boolean:e=>({enabled:e}),object:(e,t)=>({...e,requests:_({defaultValue:{...t.requests},mappers:{function:e=>({name:e}),string:e=>({name:e})},value:e.requests}),responses:_({defaultValue:{...t.responses},mappers:{function:e=>({name:e}),string:e=>({name:e})},value:e.responses})})},value:e.readWrite})})},value:e.transforms}),validate_EXPERIMENTAL:e.validate_EXPERIMENTAL===!0?`warn`:e.validate_EXPERIMENTAL})},value:e.parser}),qe=e=>t=>({...e,config:{...e.config,...t}}),v={boolean:e=>({enabled:e}),function:e=>({name:e}),string:e=>({name:e})},Je=/[\p{Lu}]/u,Ye=/[\p{Ll}]/u,Xe=/([\p{Alpha}\p{N}_]|$)/u,Ze=/[_.\- `\\[\]{}\\/]+/,Qe=RegExp(`^${Ze.source}`),$e=RegExp(`${Ze.source}${Xe.source}`,`gu`),et=RegExp(`\\d+${Xe.source}`,`gu`),tt=({case:e,string:t})=>{let n=!1,r=!1,i=!1,a=!1,o=e===`snake_case`||e===`SCREAMING_SNAKE_CASE`?`_`:`-`;for(let e=0;e<t.length;e++){let s=t[e];a=e>2?t[e-3]===o:!0;let c=e+1,l=t[c];for(Ze.lastIndex=0;l&&Ze.test(l);)c+=1,l=t[c];let u=c!==e+1;if(Ye.lastIndex=0,Je.lastIndex=0,Je.test(s)&&(n||l&&!u&&l!==`s`&&Ye.test(l)))t=`${t.slice(0,e)}${o}${t.slice(e)}`,e++,i=r,n=!1,r=!0;else if(r&&i&&Ye.test(s)&&!a&&!(s===`s`&&(!l||l.toLocaleLowerCase()!==l)))t=`${t.slice(0,e-1)}${o}${t.slice(e-1)}`,i=r,n=!0,r=!1;else{let e=s.toLocaleLowerCase(),t=s.toLocaleUpperCase();i=r,n=e===s&&t!==s,r=t===s&&e!==s}}return t},y=({case:e,stripLeadingSeparators:t=!0,value:n})=>{let r=n.trim();return r.length?!e||e===`preserve`?r:r.length===1?(Ze.lastIndex=0,Ze.test(r)?``:e===`PascalCase`||e===`SCREAMING_SNAKE_CASE`?r.toLocaleUpperCase():r.toLocaleLowerCase()):(r!==r.toLocaleLowerCase()&&(r=tt({case:e,string:r})),(t||r[0]!==n[0])&&(r=r.replace(Qe,``)),r=e===`SCREAMING_SNAKE_CASE`?r.toLocaleUpperCase():r.toLocaleLowerCase(),e===`PascalCase`&&(r=`${r.charAt(0).toLocaleUpperCase()}${r.slice(1)}`),e===`snake_case`||e===`SCREAMING_SNAKE_CASE`?(r=r.replaceAll($e,(e,n,r)=>r===0&&!t?e:`_${n}`),r[r.length-1]===`_`&&(r=r.slice(0,r.length-1))):($e.lastIndex=0,et.lastIndex=0,r=r.replaceAll(et,(e,t,n)=>[`_`,`-`,`.`].includes(r.charAt(n+e.length))?e:e.toLocaleUpperCase()),r=r.replaceAll($e,(e,r,i)=>i===0&&!t&&e[0]&&n.startsWith(e[0])?e:r.toLocaleUpperCase())),r):``},b=({config:e,name:t})=>{if(typeof e.name==`function`)t=e.name(t);else if(e.name){let n=e.case===`preserve`?``:`-`;t=e.name.replace(`{{name}}`,`${n}${t}${n}`)}return y({case:e.case,value:t})},nt=({context:e,parameter:t})=>{if(!t.pagination)return;if(t.pagination===!0)return t.schema;let n=t.schema;return n.$ref&&(n=e.resolveIrRef(n.$ref)),n.properties[t.pagination]},rt=e=>{for(let t in e)if(e[t].required)return!0;return!1},it=e=>e?!!(rt(e.cookie)||rt(e.header)||rt(e.path)||rt(e.query)):!1,at=({context:e,parameters:t})=>{if(t){for(let n in t.cookie){let r=t.cookie[n];if(r.pagination)return{in:r.location,name:r.pagination===!0?r.name:`${r.name}.${r.pagination}`,schema:nt({context:e,parameter:r})}}for(let n in t.header){let r=t.header[n];if(r.pagination)return{in:r.location,name:r.pagination===!0?r.name:`${r.name}.${r.pagination}`,schema:nt({context:e,parameter:r})}}for(let n in t.path){let r=t.path[n];if(r.pagination)return{in:r.location,name:r.pagination===!0?r.name:`${r.name}.${r.pagination}`,schema:nt({context:e,parameter:r})}}for(let n in t.query){let r=t.query[n];if(r.pagination)return{in:r.location,name:r.pagination===!0?r.name:`${r.name}.${r.pagination}`,schema:nt({context:e,parameter:r})}}}},x=({detectFormat:e=!0,schema:t})=>{if(!t.items)return t;let n=[],r=[];for(let i of t.items){if(!i.type&&i.items||t.type===`tuple`){n.push(i);continue}if(!i.type||i.type===`boolean`||i.type===`integer`||i.type===`null`||i.type===`number`||i.type===`string`||i.type===`unknown`||i.type===`void`){let t=i.const===void 0?``:`const-${i.const}`,a=i.format!==void 0&&e?`format-${i.format}`:``,o=[i.minLength===void 0?``:`minLength-${i.minLength}`,i.maxLength===void 0?``:`maxLength-${i.maxLength}`,i.minimum===void 0?``:`minimum-${i.minimum}`,i.maximum===void 0?``:`maximum-${i.maximum}`,i.exclusiveMinimum===void 0?``:`exclusiveMinimum-${i.exclusiveMinimum}`,i.exclusiveMaximum===void 0?``:`exclusiveMaximum-${i.exclusiveMaximum}`,i.minItems===void 0?``:`minItems-${i.minItems}`,i.maxItems===void 0?``:`maxItems-${i.maxItems}`,i.pattern===void 0?``:`pattern-${i.pattern}`].join(``),s=`${i.$ref??``}${i.type??``}${t}${a}${o}`;r.includes(s)||(r.push(s),n.push(i));continue}n.push(i)}let i={...t};if(i.items=n,i.items.length<=1&&i.type!==`array`&&i.type!==`enum`&&i.type!==`tuple`){let e=i.items[0];delete i.logicalOperator,delete i.items,i={...i,...e}}return i.type===`unknown`?{}:i},S=({items:e,logicalOperator:t=`or`,mutateSchemaOneItem:n=!1,schema:r})=>e.length?r.type===`tuple`?(r.items=e,r):e.length===1?n?(r={...r,...e[0]},r):(r.items=e,r):(r.items=e,r.logicalOperator=t,r):r,ot=e=>!!(it(e.parameters)||e.body?.required),C=({method:e,path:t})=>`${e.toUpperCase()} ${t}`,st=({context:e,operation:t})=>{let n=t.body;if(!n||!n.pagination)return at({context:e,parameters:t.parameters});if(n.pagination===!0)return{in:`body`,name:`body`,schema:n.schema};let r=n.schema,i=r.$ref?e.resolveIrRef(r.$ref):r,a=(`schema`in i?i.schema:i)?.properties?.[n.pagination];return a?{in:`body`,name:n.pagination,schema:a}:at({context:e,parameters:t.parameters})},ct=({statusCode:e})=>{switch(e){case`1XX`:return`1XX`;case`2XX`:return`2XX`;case`3XX`:return`3XX`;case`4XX`:return`4XX`;case`5XX`:return`5XX`;case`default`:return`default`;default:return`${e[0]}XX`}},lt=e=>{let t={};if(!e.responses)return t;let n={properties:{},type:`object`},r={properties:{},type:`object`},i;for(let t in e.responses){let a=e.responses[t];switch(ct({statusCode:t})){case`1XX`:case`3XX`:break;case`2XX`:r.properties[t]=a.schema;break;case`4XX`:case`5XX`:n.properties[t]=a.schema;break;case`default`:i=a;break}}if(i){let e=!1;Object.keys(r.properties).length||(r.properties.default=i.schema,e=!0);let t=(i.schema.description??``).toLocaleLowerCase(),a=(i.schema.$ref??``).toLocaleLowerCase();[`success`].some(e=>t.includes(e)||a.includes(e))&&(r.properties.default=i.schema,e=!0),[`error`,`problem`].some(e=>t.includes(e)||a.includes(e))&&(n.properties.default=i.schema,e=!0),e||(n.properties.default=i.schema)}let a=Object.keys(n.properties);if(a.length){n.required=a,t.errors=n;let e=S({items:Object.values(n.properties),mutateSchemaOneItem:!0,schema:{}});e=x({schema:e}),Object.keys(e).length&&e.type!==`unknown`&&(t.error=e)}let o=Object.keys(r.properties);if(o.length){r.required=o,t.responses=r;let e=S({items:Object.values(r.properties),mutateSchemaOneItem:!0,schema:{}});e=x({schema:e}),Object.keys(e).length&&e.type!==`unknown`&&(t.response=e)}return t},ut=e=>e.replace(/^[^\p{ID_Start}]+/u,``).replace(/[^$\u200c\u200d\p{ID_Continue}]/gu,`-`).replace(/[$+]/g,`-`),dt=e=>{let t=w(e);return t.name===`@hey-api/client-axios`||t.name===`@hey-api/client-nuxt`?`baseURL`:`baseUrl`},w=e=>{for(let t of e.pluginOrder){let n=e.plugins[t];if(n?.tags?.includes(`client`))return n}return{config:{name:``},name:``}};var T=class{analyze(e){}exported;file;language=`typescript`;parent;root;symbol;toAst(){}"~brand"=s;$if(e,t,n){if(e){let n;try{n=t?.(this,e)}catch{}if(n===void 0)try{n=t?.(e)}catch{}if(n===void 0)try{n=t?.()}catch{}return n??this}if(n){let t;try{t=n?.(this,e)}catch{}if(t===void 0)try{t=n?.(e)}catch{}if(t===void 0)try{t=n?.()}catch{}return t??this}return this}$maybeId(e){return typeof e==`string`?m.factory.createIdentifier(e):e}$node(e){if(e!==void 0)return i(e)&&(e=n(e)),a(e)?this.$maybeId(e.finalName):typeof e==`string`?this.$maybeId(e):e instanceof Array?e.map(e=>(i(e)&&(e=n(e)),this.unwrap(e))):this.unwrap(e)}$type(e,t){if(e!==void 0){if(i(e)&&(e=n(e)),a(e))return m.factory.createTypeReferenceNode(e.finalName,t);if(typeof e==`string`)return m.factory.createTypeReferenceNode(e,t);if(typeof e==`boolean`){let t=e?m.factory.createTrue():m.factory.createFalse();return m.factory.createLiteralTypeNode(t)}return typeof e==`number`?m.factory.createLiteralTypeNode(m.factory.createNumericLiteral(e)):e instanceof Array?e.map(e=>this.$type(e,t)):this.unwrap(e)}}unwrap(e){return r(e)?e.toAst():e}},E=class extends T{};const ft=T;var pt=class extends ft{"~dsl"=`IdTsDsl`;name;constructor(e){super(),this.name=e}analyze(e){super.analyze(e)}toAst(){return m.factory.createIdentifier(this.name)}},mt=class extends T{"~dsl"=`NewlineTsDsl`;analyze(e){super.analyze(e)}toAst(){return this.$node(new pt(`
2
- `))}};function ht(e){class t extends e{_args=[];analyze(e){super.analyze(e);for(let t of this._args)e.analyze(t)}arg(e){return e!==void 0&&this._args.push(c(e)),this}args(...e){return this._args.push(...e.filter(e=>e!==void 0).map(e=>c(e))),this}$args(){return this.$node(this._args).map(e=>this.$node(e))}}return t}const gt=T;var _t=class extends gt{"~dsl"=`PrefixTsDsl`;_expr;_op;constructor(e,t){super(),this._expr=e,this._op=t}analyze(e){super.analyze(e),e.analyze(this._expr)}expr(e){return this._expr=e,this}neg(){return this._op=m.SyntaxKind.MinusToken,this}not(){return this._op=m.SyntaxKind.ExclamationToken,this}op(e){return this._op=e,this}toAst(){if(!this._expr)throw Error(`Missing expression for prefix unary expression`);if(!this._op)throw Error(`Missing operator for prefix unary expression`);return m.factory.createPrefixUnaryExpression(this._op,this.$node(this._expr))}};let vt;function yt(e){vt=e}function bt(e){class t extends e{analyze(e){super.analyze(e)}as(e){return vt(this,e)}}return t}const xt=bt(T);var D=class extends xt{"~dsl"=`LiteralTsDsl`;value;constructor(e){super(),this.value=e}analyze(e){super.analyze(e)}toAst(){if(typeof this.value==`boolean`)return this.value?m.factory.createTrue():m.factory.createFalse();if(typeof this.value==`number`){let e=m.factory.createNumericLiteral(Math.abs(this.value));return this.value<0?this.$node(new _t(e).neg()):e}if(typeof this.value==`string`)return m.factory.createStringLiteral(this.value,!0);if(this.value===null)return m.factory.createNull();throw Error(`Unsupported literal: ${String(this.value)}`)}};const O={illegalStartCharacters:/^[^$_\p{ID_Start}]+/u,number:/^-?\d+(\.\d+)?$/,typeScriptIdentifier:/^[$_\p{ID_Start}][$\u200c\u200d\p{ID_Continue}]*$/u},St={browserGlobals:[`document`,`history`,`location`,`navigator`,`window`],javaScriptGlobals:[`console`,`Array`,`Date`,`Error`,`Function`,`JSON`,`Map`,`Math`,`Object`,`Promise`,`RegExp`,`Set`,`WeakMap`,`WeakSet`],javaScriptKeywords:`arguments.async.await.break.case.catch.class.const.continue.debugger.default.delete.do.else.enum.eval.export.extends.false.finally.for.from.function.if.implements.import.in.instanceof.interface.let.new.null.package.private.protected.public.return.static.super.switch.this.throw.true.try.typeof.var.void.while.with.yield`.split(`.`),nodeGlobals:[`global`,`process`,`Buffer`],typeScriptKeywords:[`any`,`as`,`bigint`,`boolean`,`namespace`,`never`,`null`,`number`,`string`,`symbol`,`type`,`undefined`,`unknown`,`void`]};var Ct=class{_array;_set;constructor(e){this._array=e,this._set=new Set(e)}get"~values"(){return this._set}set(e){let t=typeof e==`function`?e(this._array):e;this._array=t,this._set=new Set(t)}};const wt={runtime:new Ct([...St.browserGlobals,...St.javaScriptGlobals,...St.javaScriptKeywords,...St.nodeGlobals,...St.typeScriptKeywords]),type:new Ct([...St.javaScriptKeywords,...St.typeScriptKeywords])},Tt=e=>(O.typeScriptIdentifier.lastIndex=0,O.typeScriptIdentifier.test(e)?new pt(e):new D(e)),Et=e=>(O.number.lastIndex=0,O.number.test(e)?e.startsWith(`-`)?new D(e):new D(Number(e)):(O.typeScriptIdentifier.lastIndex=0,O.typeScriptIdentifier.test(e)?new pt(e):new D(e))),Dt=(e,t)=>{let n=``,r,i=e[0];for(O.illegalStartCharacters.lastIndex=0,O.illegalStartCharacters.test(i)?(n+=`_`,r=0):(n+=i,r=1);r<e.length;){let t=e[r];n+=/^[\u200c\u200d\p{ID_Continue}]$/u.test(t)?t:`_`,r+=1}return t[`~values`].has(n)&&(n=`_${n}`),n||`_`},Ot=e=>Dt(e,wt.runtime),kt=e=>Dt(e,wt.type),At=ht(T);var jt=class extends At{"~dsl"=`DecoratorTsDsl`;name;constructor(e,...t){super(),this.name=c(e),a(e)&&e.setNameSanitizer(Ot),this.args(...t)}analyze(e){super.analyze(e),e.analyze(this.name)}toAst(){let e=this.$node(this.name),t=this.$args();return m.factory.createDecorator(t.length?m.factory.createCallExpression(e,void 0,t):e)}};function Mt(e){class t extends e{decorators=[];analyze(e){super.analyze(e);for(let t of this.decorators)e.analyze(t)}decorator(e,...t){return this.decorators.push(new jt(e,...t)),this}$decorators(){return this.$node(this.decorators)}}return t}var Nt=class extends T{"~dsl"=`DocTsDsl`;_lines=[];constructor(e,t){super(),e&&(typeof e==`string`?this.add(e):this.add(...e)),t?.(this)}analyze(e){super.analyze(e)}add(...e){return this._lines.push(...e),this}apply(e){let t=this._lines.filter(e=>!!e||e===``);if(!t.length)return e;let n=t.map(e=>m.factory.createJSDocText(`${e}\n`)),r=m.factory.createJSDocComment(m.factory.createNodeArray(n),void 0),i=m.createPrinter().printNode(m.EmitHint.Unspecified,r,e.getSourceFile?.()??m.createSourceFile(``,``,m.ScriptTarget.Latest)).replace(`/*`,``).replace(`* */`,``);return m.addSyntheticLeadingComment(e,m.SyntaxKind.MultiLineCommentTrivia,i,!0),e}toAst(){return this.$node(new pt(``))}};function k(e){class t extends e{_doc;analyze(e){super.analyze(e)}doc(e,t){return this._doc=new Nt(e,t),this}$docs(e){return this._doc?this._doc.apply(e):e}}return t}function A(e){class t extends e{modifiers=[];analyze(e){super.analyze(e)}_m(e,t){return t&&this.modifiers.push(m.factory.createModifier(e)),this}}return t}function Pt(e){let t=A(e);class n extends t{abstract(e){let t=arguments.length===0?!0:!!e;return this._m(m.SyntaxKind.AbstractKeyword,t)}}return n}function Ft(e){let t=A(e);class n extends t{async(e){let t=arguments.length===0?!0:!!e;return this._m(m.SyntaxKind.AsyncKeyword,t)}}return n}function It(e){let t=A(e);class n extends t{const(e){let t=arguments.length===0?!0:!!e;return this._m(m.SyntaxKind.ConstKeyword,t)}}return n}function Lt(e){let t=A(e);class n extends t{default(e){let t=arguments.length===0?!0:!!e;return this._m(m.SyntaxKind.DefaultKeyword,t)}}return n}function Rt(e){let t=A(e);class n extends t{export(e){let t=arguments.length===0?!0:!!e;return this.exported=t,this.symbol&&this.symbol.setExported(t),this._m(m.SyntaxKind.ExportKeyword,t)}}return n}function zt(e){let t=A(e);class n extends t{private(e){let t=arguments.length===0?!0:!!e;return this._m(m.SyntaxKind.PrivateKeyword,t)}}return n}function Bt(e){let t=A(e);class n extends t{protected(e){let t=arguments.length===0?!0:!!e;return this._m(m.SyntaxKind.ProtectedKeyword,t)}}return n}function Vt(e){let t=A(e);class n extends t{public(e){let t=arguments.length===0?!0:!!e;return this._m(m.SyntaxKind.PublicKeyword,t)}}return n}function Ht(e){let t=A(e);class n extends t{readonly(e){let t=arguments.length===0?!0:!!e;return this._m(m.SyntaxKind.ReadonlyKeyword,t)}}return n}function Ut(e){let t=A(e);class n extends t{static(e){let t=arguments.length===0?!0:!!e;return this._m(m.SyntaxKind.StaticKeyword,t)}}return n}const Wt=E;var Gt=class extends Wt{"~dsl"=`TypeParamTsDsl`;constraint;defaultValue;name;constructor(e,t){super(),e&&(this.name=c(e)),t?.(this)}analyze(e){super.analyze(e),e.analyze(this.name),e.analyze(this.constraint),e.analyze(this.defaultValue)}default(e){return this.defaultValue=c(e),this}extends(e){return this.constraint=c(e),this}toAst(){if(!this.name)throw Error(`Missing type name`);return m.factory.createTypeParameterDeclaration(void 0,this.$node(this.name),this.$type(this.constraint),this.$type(this.defaultValue))}};function Kt(e){class t extends e{_generics=[];analyze(e){super.analyze(e);for(let t of this._generics)e.analyze(t)}generic(...e){let t=new Gt(...e);return this._generics.push(t),this}generics(...e){for(let t of e)(typeof t==`string`||a(t))&&(t=new Gt(t)),this._generics.push(t);return this}$generics(){return this.$node(this._generics)}}return t}function qt(e){class t extends e{value;analyze(e){super.analyze(e),e.analyze(this.value)}assign(e){return this.value=e,this}$value(){return this.$node(this.value)}}return t}function Jt(e){class t extends e{_generics=[];analyze(e){super.analyze(e);for(let t of this._generics)e.analyze(t)}generic(e){return this._generics.push(c(e)),this}generics(...e){return this._generics.push(...e.map(e=>c(e))),this}$generics(){return this.$type(this._generics)}}return t}let Yt;function Xt(e){Yt=e}let Zt;function Qt(e){Zt=e}let $t;function en(e){$t=e}let tn;function nn(e){tn=e}let rn;function an(e){rn=e}function on(e){class t extends e{analyze(e){super.analyze(e)}idx(e){return Zt(this,e)}keyof(){return tn().keyof(this)}readonly(){return tn().readonly(this)}returnType(){return Yt(`ReturnType`).generic(rn(this))}typeofExpr(){return $t(this)}typeofType(){return rn(this)}unique(){return tn().unique(this)}}return t}const sn=on(E);var cn=class extends sn{"~dsl"=`TypeAttrTsDsl`;_base;_right;constructor(e,t){super(),t?(this.base(e),this.right(t)):(this.base(),this.right(e))}analyze(e){super.analyze(e),e.analyze(this._base),e.analyze(this._right)}base(e){return i(e)?this._base=e:this._base=e?c(e):void 0,this}right(e){return this._right=c(e),this}toAst(){if(!this._base)throw Error(`TypeAttrTsDsl: missing base for qualified name`);let e=this.$node(this._base);if(!m.isEntityName(e))throw Error(`TypeAttrTsDsl: base must be an EntityName`);return m.factory.createQualifiedName(e,this.$node(this._right))}};const ln=Jt(on(E));var un=class extends ln{"~dsl"=`TypeExprTsDsl`;_exprInput;constructor(e,t){super(),typeof e==`function`?e(this):(this._exprInput=e?c(e):void 0,t?.(this))}analyze(e){super.analyze(e),e.analyze(this._exprInput)}attr(e){return this._exprInput=r(e)?c(e.base(this._exprInput)):c(new cn(this._exprInput,e)),this}toAst(){if(!this._exprInput)throw Error(`TypeExpr must have an expression`);return m.factory.createTypeReferenceNode(this.$type(this._exprInput),this.$generics())}};Xt((...e)=>new un(...e));const dn=Mt(k(zt(Bt(Vt(Ht(Ut(qt(T))))))));var fn=class extends dn{"~dsl"=`FieldTsDsl`;name;_type;constructor(e,t){super(),this.name=e,t?.(this)}analyze(e){super.analyze(e),e.analyze(this._type)}type(e){return this._type=e instanceof E?e:new un(e),this}toAst(){let e=m.factory.createPropertyDeclaration([...this.$decorators(),...this.modifiers],this.name,void 0,this.$type(this._type),this.$value());return this.$docs(e)}};const pn=T;var mn=class extends pn{"~dsl"=`StmtTsDsl`;_inner;constructor(e){super(),this._inner=e}analyze(e){super.analyze(e),e.analyze(this._inner)}toAst(){let e=this.$node(this._inner);return m.isStatement(e)?e:m.factory.createExpressionStatement(e)}};function hn(e){class t extends e{_do=[];analyze(e){super.analyze(e),e.pushScope();try{for(let t of this._do)e.analyze(t)}finally{e.popScope()}}do(...e){return this._do.push(...e),this}$do(){return this.$node(this._do.map(e=>new mn(e)))}}return t}function gn(e){class t extends e{_optional;analyze(e){super.analyze(e)}optional(e){return this._optional=arguments.length===0?!0:!!e,this}required(e){return this._optional=arguments.length===0?!1:!e,this}}return t}var j=class extends T{"~dsl"=`TokenTsDsl`;_kind;kind(e){return this._kind=e,this}minus(){return this.kind(m.SyntaxKind.MinusToken)}optional(){return this.kind(m.SyntaxKind.QuestionToken)}plus(){return this.kind(m.SyntaxKind.PlusToken)}questionDot(){return this.kind(m.SyntaxKind.QuestionDotToken)}readonly(){return this.kind(m.SyntaxKind.ReadonlyKeyword)}spread(){return this.kind(m.SyntaxKind.DotDotDotToken)}toAst(){if(!this._kind)throw Error("Token missing `.kind(kind)`");return m.factory.createToken(this._kind)}};const _n=T;var vn=class extends _n{"~dsl"=`PatternTsDsl`;pattern;_spread;analyze(e){super.analyze(e)}array(...e){return this.pattern={kind:`array`,values:e[0]instanceof Array?[...e[0]]:e},this}object(...e){let t={};for(let n of e)if(typeof n==`string`)t[n]=n;else if(n instanceof Array)for(let e of n)t[e]=e;else Object.assign(t,n);return this.pattern={kind:`object`,values:t},this}spread(e){return this._spread=e,this}toAst(){if(!this.pattern)throw Error(`PatternTsDsl requires object() or array() pattern`);if(this.pattern.kind===`object`){let e=Object.entries(this.pattern.values).map(([e,t])=>e===t?m.factory.createBindingElement(void 0,void 0,e,void 0):m.factory.createBindingElement(void 0,e,t,void 0)),t=this.createSpread();return t&&e.push(t),m.factory.createObjectBindingPattern(e)}if(this.pattern.kind===`array`){let e=this.pattern.values.map(e=>m.factory.createBindingElement(void 0,void 0,e,void 0)),t=this.createSpread();return t&&e.push(t),m.factory.createArrayBindingPattern(e)}throw Error(`PatternTsDsl requires object() or array() pattern`)}createSpread(){return this._spread?m.factory.createBindingElement(this.$node(new j().spread()),void 0,this.$node(new pt(this._spread))):void 0}};function yn(e){class t extends e{pattern;analyze(e){super.analyze(e),e.analyze(this.pattern)}array(...e){return(this.pattern??=new vn).array(...e),this}object(...e){return(this.pattern??=new vn).object(...e),this}spread(e){return(this.pattern??=new vn).spread(e),this}$pattern(){if(this.pattern)return this.$node(this.pattern)}}return t}const bn=Mt(gn(yn(qt(T))));var xn=class extends bn{"~dsl"=`ParamTsDsl`;name;_type;constructor(e,t){super(),typeof e==`function`?e(this):(this.name=c(e),t?.(this))}analyze(e){super.analyze(e),e.analyze(this.name),e.analyze(this._type)}type(e){return this._type=e instanceof E?e:new un(e),this}toAst(){let e=this.$pattern();if(!e&&this.name&&(e=o(this.name)?n(this.name).finalName:n(this.name)),!e)throw Error(`Param must have either a name or a destructuring pattern`);return m.factory.createParameterDeclaration(this.$decorators(),void 0,e,this._optional?this.$node(new j().optional()):void 0,this.$type(this._type),this.$value())}};function Sn(e){class t extends e{_params=[];analyze(e){super.analyze(e);for(let t of this._params)e.analyze(t)}param(e,t){let n=new xn(e,t);return this._params.push(n),this}params(...e){return this._params.push(...e),this}$params(){return this.$node(this._params)}}return t}function Cn(e){class t extends e{static DEFAULT_THRESHOLD=3;layout;analyze(e){super.analyze(e)}auto(e=t.DEFAULT_THRESHOLD){return this.layout=e,this}inline(){return this.layout=!1,this}pretty(){return this.layout=!0,this}$multiline(e){return this.layout===void 0&&(this.layout=t.DEFAULT_THRESHOLD),e===0?!1:typeof this.layout==`number`?e>=this.layout:this.layout}}return t}const wn=hn(Cn(T));var M=class extends wn{"~dsl"=`BlockTsDsl`;constructor(...e){super(),this.do(...e)}analyze(e){super.analyze(e)}toAst(){let e=this.$do();return m.factory.createBlock(e,this.$multiline(e.length))}};const Tn=Mt(hn(k(Sn(zt(Bt(Vt(T)))))));var En=class extends Tn{"~dsl"=`InitTsDsl`;constructor(e){super(),e?.(this)}analyze(e){e.pushScope();try{super.analyze(e)}finally{e.popScope()}}toAst(){let e=m.factory.createConstructorDeclaration([...this.$decorators(),...this.modifiers],this.$params(),this.$node(new M(...this._do).pretty()));return this.$docs(e)}};const Dn=Pt(Ft(Mt(hn(k(gn(Sn(zt(Bt(Vt(Ut(Kt(T))))))))))));var On=class extends Dn{"~dsl"=`MethodTsDsl`;name;_returns;constructor(e,t){super(),this.name=e,t?.(this)}analyze(e){e.pushScope();try{super.analyze(e),e.analyze(this._returns)}finally{e.popScope()}}returns(e){return this._returns=e instanceof E?e:new un(e),this}toAst(){let e=m.factory.createMethodDeclaration([...this.$decorators(),...this.modifiers],void 0,this.name,this._optional?this.$node(new j().optional()):void 0,this.$generics(),this.$params(),this.$type(this._returns),this.$node(new M(...this._do).pretty()));return this.$docs(e)}};const kn=Pt(Mt(Lt(k(Rt(Kt(T))))));var An=class extends kn{"~dsl"=`ClassTsDsl`;baseClass;body=[];name;constructor(e){super(),this.name=c(e),a(e)&&(e.setKind(`class`),e.setNameSanitizer(Ot),e.setNode(this))}analyze(e){super.analyze(e),e.analyze(this.baseClass),e.analyze(this.name),e.pushScope();try{for(let t of this.body)e.analyze(t)}finally{e.popScope()}}do(...e){return this.body.push(...e),this}extends(e){return this.baseClass=e?c(e):void 0,this}field(e,t){let n=new fn(e,t);return this.body.push(n),this}init(e){let t=new En(e);return this.body.push(t),this}method(e,t){let n=new On(e,t);return this.body.push(n),this}newline(){return this.body.push(new mt),this}toAst(){let e=this.$node(this.body),t=m.factory.createClassDeclaration([...this.$decorators(),...this.modifiers],this.$node(this.name),this.$generics(),this._heritage(),e);return this.$docs(t)}_heritage(){let e=this.$node(this.baseClass);return e?[m.factory.createHeritageClause(m.SyntaxKind.ExtendsKeyword,[m.factory.createExpressionWithTypeArguments(e,void 0)])]:[]}};const jn=k(T);var Mn=class extends jn{"~dsl"=`EnumMemberTsDsl`;_name;_value;constructor(e,t){super(),this._name=e,typeof t==`function`?t(this):this.value(t)}analyze(e){super.analyze(e),e.analyze(this._value)}value(e){return this._value=e,this}toAst(){let e=m.factory.createEnumMember(this.$node(Tt(this._name)),this.$node(this._value));return this.$docs(e)}};const Nn=It(k(Rt(T)));var Pn=class extends Nn{"~dsl"=`EnumTsDsl`;_members=[];_name;constructor(e,t){super(),this._name=c(e),a(e)&&(e.setKind(`enum`),e.setNameSanitizer(Ot),e.setNode(this)),t?.(this)}analyze(e){super.analyze(e),e.analyze(this._name),e.pushScope();try{for(let t of this._members)e.analyze(t)}finally{e.popScope()}}member(e,t){let n=new Mn(e,t);return this._members.push(n),this}members(...e){return this._members.push(...e),this}toAst(){let e=m.factory.createEnumDeclaration(this.modifiers,this.$node(this._name),this.$node(this._members));return this.$docs(e)}};const Fn=Pt(bt(Ft(Mt(hn(k(Sn(zt(Bt(Vt(Ut(Kt(T)))))))))))),In=class extends Fn{"~dsl"=`FuncTsDsl`;mode;name;_returns;constructor(e,t){super(),typeof e==`function`?(this.mode=`arrow`,e(this)):e&&(this.mode=`decl`,this.name=c(e),a(e)&&(e.setKind(`function`),e.setNameSanitizer(Ot),e.setNode(this)),t?.(this))}analyze(e){e.pushScope();try{super.analyze(e),e.analyze(this.name),e.analyze(this._returns)}finally{e.popScope()}}arrow(){return this.mode=`arrow`,this}decl(){return this.mode=`decl`,this}expr(){return this.mode=`expr`,this}returns(e){return this._returns=e instanceof E?e:new un(e),this}toAst(){let e=this.$node(new M(...this._do).pretty());if(this.mode===`decl`){if(!this.name)throw Error(`Function declaration requires a name`);let t=m.factory.createFunctionDeclaration([...this.$decorators(),...this.modifiers],void 0,this.$node(this.name),this.$generics(),this.$params(),this.$type(this._returns),e);return this.$docs(t)}if(this.mode===`expr`){let t=m.factory.createFunctionExpression(this.modifiers,void 0,this.$node(this.name),this.$generics(),this.$params(),this.$type(this._returns),e);return this.$docs(t)}let t=m.factory.createArrowFunction(this.modifiers,this.$generics(),this.$params(),this.$type(this._returns),void 0,e.statements.length===1&&m.isReturnStatement(e.statements[0])&&e.statements[0].expression?e.statements[0].expression:e);return this.$docs(t)}},Ln=Pt(Ft(Mt(hn(k(Sn(zt(Bt(Vt(Ut(T))))))))));var Rn=class extends Ln{"~dsl"=`GetterTsDsl`;name;constructor(e,t){super(),this.name=e,t?.(this)}analyze(e){e.pushScope();try{super.analyze(e)}finally{e.popScope()}}toAst(){let e=m.factory.createGetAccessorDeclaration([...this.$decorators(),...this.modifiers],this.name,this.$params(),void 0,this.$node(new M(...this._do).pretty()));return this.$docs(e)}};const zn=Pt(Ft(Mt(hn(k(Sn(zt(Bt(Vt(Ut(T))))))))));var Bn=class extends zn{"~dsl"=`SetterTsDsl`;name;constructor(e,t){super(),this.name=e,t?.(this)}analyze(e){e.pushScope();try{super.analyze(e)}finally{e.popScope()}}toAst(){let e=m.factory.createSetAccessorDeclaration([...this.$decorators(),...this.modifiers],this.name,this.$params(),this.$node(new M(...this._do).pretty()));return this.$docs(e)}};const Vn=bt(Cn(T));var Hn=class extends Vn{"~dsl"=`ArrayTsDsl`;_elements=[];constructor(...e){super(),this.elements(...e)}analyze(e){super.analyze(e);for(let t of this._elements)e.analyze(t.expr)}element(e){let t=typeof e==`string`||typeof e==`number`||typeof e==`boolean`?new D(e):e;return this._elements.push({expr:t,kind:`element`}),this}elements(...e){for(let t of e)this.element(t);return this}spread(e){return this._elements.push({expr:e,kind:`spread`}),this}toAst(){let e=this._elements.map(e=>{let t=this.$node(e.expr);return e.kind===`spread`?m.factory.createSpreadElement(t):t});return m.factory.createArrayLiteralExpression(e,this.$multiline(this._elements.length))}};let Un;function Wn(e){Un=e}let Gn;function Kn(e){Gn=e}let qn;function Jn(e){qn=e}let Yn;function Xn(e){Yn=e}function Zn(e){class t extends e{analyze(e){super.analyze(e)}attr(e){return Un(this,e)}await(){return Gn(this)}call(...e){return qn(this,...e)}return(){return Yn(this)}}return t}const Qn=bt(Zn(T));var $n=class extends Qn{"~dsl"=`AsTsDsl`;expr;type;constructor(e,t){super(),this.expr=c(e),this.type=c(t)}analyze(e){super.analyze(e),e.analyze(this.expr),e.analyze(this.type)}toAst(){return m.factory.createAsExpression(this.$node(this.expr),this.$type(this.type))}};yt((...e)=>new $n(...e));const er=bt(Zn(T));var N=class extends er{"~dsl"=`BinaryTsDsl`;_base;_expr;_op;constructor(e,t,n){super(),this._base=c(e),this._op=t,n&&(this._expr=c(n))}analyze(e){super.analyze(e),e.analyze(this._base),e.analyze(this._expr)}and(e){return this.opAndExpr(`&&`,e)}assign(e){return this.opAndExpr(`=`,e)}coalesce(e){return this.opAndExpr(`??`,e)}div(e){return this.opAndExpr(`/`,e)}eq(e){return this.opAndExpr(`===`,e)}gt(e){return this.opAndExpr(`>`,e)}gte(e){return this.opAndExpr(`>=`,e)}looseEq(e){return this.opAndExpr(`==`,e)}looseNeq(e){return this.opAndExpr(`!=`,e)}lt(e){return this.opAndExpr(`<`,e)}lte(e){return this.opAndExpr(`<=`,e)}minus(e){return this.opAndExpr(`-`,e)}neq(e){return this.opAndExpr(`!==`,e)}or(e){return this.opAndExpr(`||`,e)}plus(e){return this.opAndExpr(`+`,e)}times(e){return this.opAndExpr(`*`,e)}toAst(){if(!this._op)throw Error(`BinaryTsDsl: missing operator`);let e=this.$node(this._expr);if(!e)throw Error(`BinaryTsDsl: missing right-hand expression`);let t=this.$node(this._base),n=typeof this._op==`string`?this.opToToken(this._op):this._op;return m.factory.createBinaryExpression(t,n,e)}opAndExpr(e,t){return this._expr=c(t),this._op=e,this}opToToken(e){let t={"!=":m.SyntaxKind.ExclamationEqualsToken,"!==":m.SyntaxKind.ExclamationEqualsEqualsToken,"&&":m.SyntaxKind.AmpersandAmpersandToken,"*":m.SyntaxKind.AsteriskToken,"+":m.SyntaxKind.PlusToken,"-":m.SyntaxKind.MinusToken,"/":m.SyntaxKind.SlashToken,"<":m.SyntaxKind.LessThanToken,"<=":m.SyntaxKind.LessThanEqualsToken,"=":m.SyntaxKind.EqualsToken,"==":m.SyntaxKind.EqualsEqualsToken,"===":m.SyntaxKind.EqualsEqualsEqualsToken,">":m.SyntaxKind.GreaterThanToken,">=":m.SyntaxKind.GreaterThanEqualsToken,"??":m.SyntaxKind.QuestionQuestionToken,"||":m.SyntaxKind.BarBarToken}[e];if(!t)throw Error(`Unsupported operator: ${e}`);return t}};function tr(e){class t extends e{analyze(e){super.analyze(e)}and(e){return new N(this).and(e)}assign(e){return new N(this,`=`,e)}coalesce(e){return new N(this).coalesce(e)}div(e){return new N(this).div(e)}eq(e){return new N(this).eq(e)}gt(e){return new N(this).gt(e)}gte(e){return new N(this).gte(e)}looseEq(e){return new N(this).looseEq(e)}looseNeq(e){return new N(this).looseNeq(e)}lt(e){return new N(this).lt(e)}lte(e){return new N(this).lte(e)}minus(e){return new N(this).minus(e)}neq(e){return new N(this).neq(e)}or(e){return new N(this).or(e)}plus(e){return new N(this).plus(e)}times(e){return new N(this).times(e)}}return t}const nr=bt(Zn(tr(gn(T))));var rr=class extends nr{"~dsl"=`AttrTsDsl`;left;right;constructor(e,t){super(),this.left=c(e),this.right=c(t)}analyze(e){super.analyze(e),e.analyze(this.left),e.analyze(this.right)}toAst(){let e=this.$node(this.left);return O.typeScriptIdentifier.lastIndex=0,typeof n(this.right)==`number`||typeof n(this.right)==`string`&&!O.typeScriptIdentifier.test(n(this.right))?this._optional?m.factory.createElementAccessChain(e,this.$node(new j().questionDot()),this.$node(new D(n(this.right)))):m.factory.createElementAccessExpression(e,this.$node(new D(n(this.right)))):this._optional?m.factory.createPropertyAccessChain(e,this.$node(new j().questionDot()),this.$node(this.right)):m.factory.createPropertyAccessExpression(e,this.$node(this.right))}};Wn((...e)=>new rr(...e));const ir=Zn(T);var ar=class extends ir{"~dsl"=`AwaitTsDsl`;_awaitExpr;constructor(e){super(),this._awaitExpr=c(e)}analyze(e){super.analyze(e),e.analyze(this._awaitExpr)}toAst(){return m.factory.createAwaitExpression(this.$node(this._awaitExpr))}};Kn((...e)=>new ar(...e));const or=ht(bt(Zn(Jt(T))));var sr=class extends or{"~dsl"=`CallTsDsl`;_callee;constructor(e,...t){super(),this._callee=e,this.args(...t)}analyze(e){super.analyze(e),e.analyze(this._callee)}toAst(){return m.factory.createCallExpression(this.$node(this._callee),this.$generics(),this.$args())}};Jn((...e)=>new sr(...e));const cr=bt(Zn(tr(on(T))));var lr=class extends cr{"~dsl"=`ExprTsDsl`;_exprInput;constructor(e){super(),this._exprInput=c(e)}analyze(e){super.analyze(e),e.analyze(this._exprInput)}toAst(){return this.$node(this._exprInput)}},ur=class extends T{"~dsl"=`HintTsDsl`;_lines=[];constructor(e,t){super(),e&&(typeof e==`string`?this.add(e):this.add(...e)),t?.(this)}analyze(e){super.analyze(e)}add(...e){return this._lines.push(...e),this}apply(e){let t=this._lines.filter(e=>!!e||e===``);if(!t.length)return e;for(let n of t)m.addSyntheticLeadingComment(e,m.SyntaxKind.SingleLineCommentTrivia,` ${n}`,!1);return e}toAst(){return this.$node(new pt(``))}};function dr(e){class t extends e{_hint;analyze(e){super.analyze(e)}hint(e,t){return this._hint=new ur(e,t),this}$hint(e){return this._hint?this._hint.apply(e):e}}return t}const fr=k(T);var pr=class extends fr{"~dsl"=`ObjectPropTsDsl`;_value;meta;constructor(e){super(),this.meta=e}analyze(e){super.analyze(e),e.analyze(this._value)}get isValid(){return this.missingRequiredCalls().length===0}value(e){return typeof e==`function`?e(this):this._value=c(e),this}toAst(){this.$validate();let e=this.$node(this._value);if(this.meta.kind===`spread`){if(m.isStatement(e))throw Error(`Invalid spread: object spread must be an expression, not a statement.`);let t=m.factory.createSpreadAssignment(e);return this.$docs(t)}if(this.meta.kind===`getter`){let t=new Rn(this.$node(Et(this.meta.name))).do(e),n=this.$node(t);return this.$docs(n)}if(this.meta.kind===`setter`){let t=new Bn(this.$node(Et(this.meta.name))).do(e),n=this.$node(t);return this.$docs(n)}if(m.isIdentifier(e)&&e.text===this.meta.name){let e=m.factory.createShorthandPropertyAssignment(this.meta.name);return this.$docs(e)}if(m.isStatement(e))throw Error(`Invalid property: object property value must be an expression, not a statement.`);let t=m.factory.createPropertyAssignment(this.meta.kind===`computed`?m.factory.createComputedPropertyName(this.$node(new pt(this.meta.name))):this.$node(Et(this.meta.name)),e);return this.$docs(t)}$validate(){let e=this.missingRequiredCalls();if(e.length!==0)throw Error(`Object property${this.meta.name?` "${this.meta.name}"`:``} missing ${e.join(` and `)}`)}missingRequiredCalls(){let e=[];return this._value||e.push(`.value()`),e}};const mr=bt(Zn(dr(Cn(T))));var hr=class extends mr{"~dsl"=`ObjectTsDsl`;_props=[];constructor(...e){super(),this.props(...e)}analyze(e){super.analyze(e);for(let t of this._props)e.analyze(t)}computed(e,t){return this._props.push(new pr({kind:`computed`,name:e}).value(t)),this}getter(e,t){return this._props.push(new pr({kind:`getter`,name:e}).value(t)),this}hasProps(){return this._props.length>0}get isEmpty(){return this._props.length===0}prop(e,t){return this._props.push(new pr({kind:`prop`,name:e}).value(t)),this}props(...e){return this._props.push(...e),this}setter(e,t){return this._props.push(new pr({kind:`setter`,name:e}).value(t)),this}spread(e){return this._props.push(new pr({kind:`spread`}).value(e)),this}toAst(){let e=m.factory.createObjectLiteralExpression(this.$node(this._props),this.$multiline(this._props.length));return this.$hint(e)}};const gr=(e,t)=>{if(r(e))return e;if(e===null||typeof e==`number`||typeof e==`boolean`||typeof e==`string`)return new D(e);if(e instanceof Array){let n=new Hn(...e.map(e=>gr(e,t)));return t?.layout===`pretty`&&n.pretty(),n}if(typeof e==`object`){let n=new hr;for(let[r,i]of Object.entries(e)){let e=gr(i,t);n.prop(r,e)}return t?.layout===`pretty`&&n.pretty(),n}throw Error(`$.fromValue(): Unsupported input type ${String(e)}`)},_r=ht(Zn(Jt(T)));var vr=class extends _r{"~dsl"=`NewTsDsl`;classExpr;constructor(e,...t){super(),this.classExpr=c(e),this.args(...t)}analyze(e){super.analyze(e),e.analyze(this.classExpr)}toAst(){return m.factory.createNewExpression(this.$node(this.classExpr),this.$generics(),this.$args())}};const yr=T;var br=class extends yr{"~dsl"=`RegExpTsDsl`;pattern;flags;constructor(e,t){super(),this.pattern=e,this.flags=t}analyze(e){super.analyze(e)}toAst(){let e=`/${(this.pattern.startsWith(`/`)&&this.pattern.endsWith(`/`)?this.pattern.slice(1,-1):this.pattern).replace(/(?<!\\)\//g,`\\/`)}/${this.flags??``}`;return m.factory.createRegularExpressionLiteral(e)}};const xr=T;var Sr=class extends xr{"~dsl"=`TemplateTsDsl`;parts=[];constructor(e){super(),e!==void 0&&this.add(e)}analyze(e){super.analyze(e);for(let t of this.parts)e.analyze(t)}add(e){return this.parts.push(c(e)),this}toAst(){let e=this.$node(this.parts.map(e=>{let t=n(e);return a(t)?t.finalName:t})),t=[];for(let n=0;n<e.length;n++){let r=e[n];if(typeof r==`string`){let i=r;for(;n+1<e.length&&typeof e[n+1]==`string`;)i+=e[n+1],n++;t.push(i)}else t.push(r)}if((t.length===0||typeof t[0]!=`string`)&&t.unshift(``),t.length===1&&typeof t[0]==`string`)return m.factory.createNoSubstitutionTemplateLiteral(t[0]);if(t.length===2&&typeof t[0]==`string`&&typeof t[1]!=`string`)return m.factory.createTemplateExpression(m.factory.createTemplateHead(t[0]),[m.factory.createTemplateSpan(t[1],m.factory.createTemplateTail(``))]);let r=m.factory.createTemplateHead(t.shift()),i=[];for(;t.length;){let e=t.shift(),n=typeof t[0]==`string`?t.shift():``,r=t.length===0;i.push(m.factory.createTemplateSpan(e,r?m.factory.createTemplateTail(n):m.factory.createTemplateMiddle(n)))}return m.factory.createTemplateExpression(r,i)}};const Cr=T;var wr=class extends Cr{"~dsl"=`TernaryTsDsl`;_condition;_then;_else;constructor(e){super(),e&&this.condition(e)}analyze(e){super.analyze(e),e.analyze(this._condition),e.analyze(this._then),e.analyze(this._else)}condition(e){return this._condition=e,this}do(e){return this._then=e,this}otherwise(e){return this._else=e,this}toAst(){if(!this._condition)throw Error(`Missing condition in ternary`);if(!this._then)throw Error(`Missing then expression in ternary`);if(!this._else)throw Error(`Missing else expression in ternary`);return m.factory.createConditionalExpression(this.$node(this._condition),void 0,this.$node(this._then),void 0,this.$node(this._else))}};const Tr=tr(T);var Er=class extends Tr{"~dsl"=`TypeOfExprTsDsl`;_expr;constructor(e){super(),this._expr=e}analyze(e){super.analyze(e),e.analyze(this._expr)}toAst(){return m.factory.createTypeOfExpression(this.$node(this._expr))}};en((...e)=>new Er(...e));var Dr=class extends T{"~dsl"=`NoteTsDsl`;_lines=[];constructor(e,t){super(),e&&(typeof e==`string`?this.add(e):this.add(...e)),t?.(this)}analyze(e){super.analyze(e)}add(...e){return this._lines.push(...e),this}apply(e){let t=this._lines.filter(e=>!!e||e===``);return t.length&&m.addSyntheticLeadingComment(e,m.SyntaxKind.MultiLineCommentTrivia,`\n${t.join(`
3
- `)}\n`,!0),e}toAst(){return this.$node(new pt(``))}};const Or=hn(T);var kr=class extends Or{"~dsl"=`IfTsDsl`;_condition;_else;constructor(e){super(),e&&this.condition(e)}analyze(e){if(super.analyze(e),e.analyze(this._condition),this._else){e.pushScope();try{for(let t of this._else)e.analyze(t)}finally{e.popScope()}}}condition(e){return this._condition=e,this}otherwise(...e){return this._else=e,this}toAst(){if(!this._condition)throw Error(`Missing condition in if`);if(!this._do)throw Error(`Missing then block in if`);return m.factory.createIfStatement(this.$node(this._condition),this.$node(new M(...this._do).pretty()),this._else?this.$node(new M(...this._else).pretty()):void 0)}};const Ar=T;var jr=class extends Ar{"~dsl"=`ReturnTsDsl`;_returnExpr;constructor(e){super(),e&&(this._returnExpr=c(e))}analyze(e){super.analyze(e),e.analyze(this._returnExpr)}toAst(){return m.factory.createReturnStatement(this.$node(this._returnExpr))}};Xn((...e)=>new jr(...e));const Mr=T;var Nr=class extends Mr{"~dsl"=`ThrowTsDsl`;error;msg;useNew;constructor(e,t=!0){super(),this.error=e,this.useNew=t}analyze(e){super.analyze(e),e.analyze(this.error),e.analyze(this.msg)}message(e){return this.msg=e,this}toAst(){let e=this.$node(this.error),t=this.$node(this.msg?[this.msg]:[]).map(e=>typeof e==`string`?this.$node(new D(e)):e);if(this.useNew)return m.factory.createThrowStatement(m.factory.createNewExpression(e,void 0,t));let n=t.length?[m.factory.createCallExpression(e,void 0,t)]:[e];return m.factory.createThrowStatement(n[0])}};const Pr=T;var Fr=class extends Pr{"~dsl"=`TryTsDsl`;_catch;_catchArg;_finally;_try;constructor(...e){super(),this.try(...e)}analyze(e){if(super.analyze(e),this._try){e.pushScope();try{for(let t of this._try)e.analyze(t)}finally{e.popScope()}}if(this._catch||this._catchArg){e.pushScope();try{if(e.analyze(this._catchArg),this._catch)for(let t of this._catch)e.analyze(t)}finally{e.popScope()}}if(this._finally){e.pushScope();try{for(let t of this._finally)e.analyze(t)}finally{e.popScope()}}}catch(...e){return this._catch=e,this}catchArg(e){return this._catchArg=e,this}finally(...e){return this._finally=e,this}try(...e){return this._try=e,this}toAst(){if(!this._try?.length)throw Error(`Missing try block`);let e=this._catchArg?this.$node(this._catchArg):void 0;return m.factory.createTryStatement(this.$node(new M(...this._try).pretty()),m.factory.createCatchClause(e?m.factory.createVariableDeclaration(e):void 0,this.$node(new M(...this._catch??[]).pretty())),this._finally?this.$node(new M(...this._finally).pretty()):void 0)}};const Ir=Lt(k(Rt(dr(yn(qt(T))))));var Lr=class extends Ir{"~dsl"=`VarTsDsl`;kind=m.NodeFlags.None;name;_type;constructor(e){super(),e&&(this.name=c(e)),a(e)&&(e.setKind(`var`),e.setNameSanitizer(Ot),e.setNode(this))}analyze(e){super.analyze(e),e.analyze(this.name),e.analyze(this._type)}const(){return this.kind=m.NodeFlags.Const,this}let(){return this.kind=m.NodeFlags.Let,this}type(e){return this._type=e instanceof E?e:new un(e),this}var(){return this.kind=m.NodeFlags.None,this}toAst(){let e=this.$pattern()??this.$node(this.name);if(!e)throw Error(`Var must have either a name or a destructuring pattern`);let t=m.factory.createVariableStatement(this.modifiers,m.factory.createVariableDeclarationList([m.factory.createVariableDeclaration(e,void 0,this.$type(this._type),this.$value())],this.kind));return this.$docs(this.$hint(t))}};const Rr=k(Rt(Kt(T)));var zr=class extends Rr{"~dsl"=`TypeAliasTsDsl`;name;value;constructor(e,t){super(),this.name=c(e),a(e)&&(e.setKind(`type`),e.setNameSanitizer(kt),e.setNode(this)),t?.(this)}analyze(e){super.analyze(e),e.analyze(this.name),e.analyze(this.value)}type(e){return this.value=e,this}toAst(){if(!this.value)throw Error(`Type alias '${n(this.name)}' is missing a type definition`);let e=m.factory.createTypeAliasDeclaration(this.modifiers,this.$node(this.name),this.$generics(),this.$type(this.value));return this.$docs(e)}};const Br=E;var Vr=class extends Br{"~dsl"=`TypeAndTsDsl`;_types=[];constructor(...e){super(),this.types(...e)}analyze(e){super.analyze(e);for(let t of this._types)e.analyze(t)}types(...e){return this._types.push(...e.map(e=>c(e))),this}toAst(){let e=[];for(let t of this._types){let n=this.$type(t);m.isIntersectionTypeNode(n)?e.push(...n.types):e.push(n)}return m.factory.createIntersectionTypeNode(e)}};const Hr=E;var Ur=class extends Hr{"~dsl"=`TypeLiteralTsDsl`;value;constructor(e){super(),this.value=e}analyze(e){super.analyze(e)}toAst(){return m.factory.createLiteralTypeNode(this.$node(new D(this.value)))}};const Wr=k(Ht(E));var Gr=class extends Wr{"~dsl"=`TypeIdxSigTsDsl`;_key;_name;_type;constructor(e,t){super(),this._name=e,t?.(this)}analyze(e){super.analyze(e),e.analyze(this._key),e.analyze(this._type)}get isValid(){return this.missingRequiredCalls().length===0}key(e){return this._key=e,this}type(e){return this._type=e,this}toAst(){this.$validate();let e=m.factory.createIndexSignature(this.modifiers,[m.factory.createParameterDeclaration(void 0,void 0,this._name,void 0,this.$type(this._key))],this.$type(this._type));return this.$docs(e)}$validate(){let e=this.missingRequiredCalls();if(e.length!==0)throw Error(`Index signature${this._name?` "${this._name}"`:``} missing ${e.join(` and `)}`)}missingRequiredCalls(){let e=[];return this._key||e.push(`.key()`),this._name||e.push(`.name()`),this._type||e.push(`.​type()`),e}};const Kr=k(gn(Ht(E)));var qr=class extends Kr{"~dsl"=`TypePropTsDsl`;name;_type;constructor(e,t){super(),this.name=e,t(this)}analyze(e){super.analyze(e),e.analyze(this._type)}type(e){return this._type=c(e),this}toAst(){if(!this._type)throw Error(`Type not specified for property '${this.name}'`);let e=m.factory.createPropertySignature(this.modifiers,this.$node(Et(this.name)),this._optional?this.$node(new j().optional()):void 0,this.$type(this._type));return this.$docs(e)}};const Jr=E;var Yr=class extends Jr{"~dsl"=`TypeObjectTsDsl`;props=[];analyze(e){super.analyze(e);for(let t of this.props)e.analyze(t)}hasProps(){return this.props.length>0}idxSig(e,t){let n=new Gr(e,t);return this.props.push(n),this}get isEmpty(){return!this.props.length}prop(e,t){let n=new qr(e,t);return this.props.push(n),this}toAst(){return m.factory.createTypeLiteralNode(this.$node(this.props))}};const Xr=E;var Zr=class extends Xr{"~dsl"=`TypeTupleTsDsl`;_elements=[];constructor(...e){super(),this.elements(...e)}analyze(e){super.analyze(e);for(let t of this._elements)e.analyze(t)}elements(...e){return this._elements.push(...e),this}toAst(){return m.factory.createTupleTypeNode(this._elements.map(e=>this.$type(e)))}};const Qr=e=>{if(r(e))return e;if(e===null||typeof e==`number`||typeof e==`boolean`||typeof e==`string`)return new Ur(e);if(e instanceof Array)return new Zr(...e.map(e=>Qr(e)));if(typeof e==`object`){let t=new Yr;for(let[n,r]of Object.entries(e)){let e=Qr(r);t.prop(n,t=>t.type(e))}return t}throw Error(`$.type.fromValue(): Unsupported input type ${String(e)}`)},$r=k(Sn(Kt(E)));var ei=class extends $r{"~dsl"=`TypeFuncTsDsl`;_returns;analyze(e){super.analyze(e),e.analyze(this._returns)}returns(e){return this._returns=e instanceof E?e:new un(e),this}toAst(){if(this._returns===void 0)throw Error(`Missing return type in function type DSL`);let e=m.factory.createFunctionTypeNode(this.$generics(),this.$params(),this.$type(this._returns));return this.$docs(e)}};const ti=on(E);var ni=class extends ti{"~dsl"=`TypeIdxTsDsl`;_base;_index;constructor(e,t){super(),this.base(e),this.index(t)}analyze(e){super.analyze(e),e.analyze(this._base),e.analyze(this._index)}base(e){return this._base=e,this}index(e){return this._index=e,this}toAst(){return m.factory.createIndexedAccessTypeNode(this.$type(this._base),this.$type(this._index))}};Qt((...e)=>new ni(...e));const ri=E;var ii=class extends ri{"~dsl"=`TypeMappedTsDsl`;questionToken;readonlyToken;_key;_name;_type;constructor(e){super(),this.name(e)}analyze(e){super.analyze(e),e.analyze(this.questionToken),e.analyze(this.readonlyToken),e.analyze(this._key),e.analyze(this._type)}get isValid(){return this.missingRequiredCalls().length===0}key(e){return this._key=e,this}mutable(){return this.readonlyToken=new j().minus(),this}name(e){return this._name=e,this}optional(){return this.questionToken=new j().optional(),this}readonly(){return this.readonlyToken=new j().readonly(),this}required(){return this.questionToken=new j().minus(),this}type(e){return this._type=e,this}toAst(){return this.$validate(),m.factory.createMappedTypeNode(this.$node(this.readonlyToken),m.factory.createTypeParameterDeclaration(void 0,this._name,this.$type(this._key),void 0),void 0,this.$node(this.questionToken),this.$type(this._type),void 0)}$validate(){let e=this.missingRequiredCalls();if(e.length!==0)throw Error(`Mapped type${this._name?` "${this._name}"`:``} missing ${e.join(` and `)}`)}missingRequiredCalls(){let e=[];return this._key||e.push(`.key()`),this._name||e.push(`.name()`),this._type||e.push(`.​type()`),e}};const ai=E;var oi=class extends ai{"~dsl"=`TypeOperatorTsDsl`;_op;_type;analyze(e){super.analyze(e),e.analyze(this._type)}keyof(e){return this.operator(m.SyntaxKind.KeyOfKeyword),this.type(e),this}operator(e){return this._op=e,this}readonly(e){return this.operator(m.SyntaxKind.ReadonlyKeyword),this.type(e),this}type(e){return this._type=e,this}unique(e){return this.operator(m.SyntaxKind.UniqueKeyword),this.type(e),this}toAst(){return this.$validate(),m.factory.createTypeOperatorNode(this._op,this.$type(this._type))}$validate(){let e=this.missingRequiredCalls();if(e.length!==0)throw Error(`Type operator missing ${e.join(` and `)}`)}missingRequiredCalls(){let e=[];return this._op||e.push(`.operator()`),this._type||e.push(`.​type()`),e}};nn((...e)=>new oi(...e));const si=E;var ci=class extends si{"~dsl"=`TypeOrTsDsl`;_types=[];constructor(...e){super(),this.types(...e)}analyze(e){super.analyze(e);for(let t of this._types)e.analyze(t)}types(...e){return this._types.push(...e.map(e=>c(e))),this}toAst(){let e=[];for(let t of this._types){let n=this.$type(t);m.isUnionTypeNode(n)?e.push(...n.types):e.push(n)}return m.factory.createUnionTypeNode(e)}};const li=on(E);var ui=class extends li{"~dsl"=`TypeQueryTsDsl`;_expr;constructor(e){super(),this._expr=e}analyze(e){super.analyze(e),e.analyze(this._expr)}toAst(){let e=this.$node(this._expr);return m.factory.createTypeQueryNode(e)}};an((...e)=>new ui(...e));const di=E;var fi=class extends di{"~dsl"=`TypeTemplateTsDsl`;parts=[];constructor(e){super(),e!==void 0&&this.add(e)}analyze(e){super.analyze(e);for(let t of this.parts)e.analyze(t)}add(e){return this.parts.push(e),this}toAst(){let e=this.$node(this.parts),t=[];for(let n=0;n<e.length;n++){let r=e[n];if(typeof r==`string`){let i=r;for(;n+1<e.length&&typeof e[n+1]==`string`;)i+=e[n+1],n++;t.push(i)}else t.push(r)}if((t.length===0||typeof t[0]!=`string`)&&t.unshift(``),t.length===1&&typeof t[0]==`string`)return m.factory.createTemplateLiteralType(m.factory.createTemplateHead(t[0]),[]);if(t.length===2&&typeof t[0]==`string`&&typeof t[1]!=`string`)return m.factory.createTemplateLiteralType(m.factory.createTemplateHead(t[0]),[m.factory.createTemplateLiteralTypeSpan(t[1],m.factory.createTemplateTail(``))]);let n=m.factory.createTemplateHead(t.shift()),r=[];for(;t.length;){let e=t.shift(),n=typeof t[0]==`string`?t.shift():``,i=t.length===0;r.push(m.factory.createTemplateLiteralTypeSpan(e,i?m.factory.createTemplateTail(n):m.factory.createTemplateMiddle(n)))}return m.factory.createTemplateLiteralType(n,r)}};const pi=m.createPrinter({newLine:m.NewLineKind.LineFeed,removeComments:!1}),mi=m.createSourceFile(``,``,m.ScriptTarget.ESNext,!1,m.ScriptKind.TS);function hi(e){let t=pi.printNode(m.EmitHint.Unspecified,e,mi);try{return t.replace(/\\u([0-9a-fA-F]{4})/g,(e,t)=>String.fromCharCode(Number.parseInt(t,16)))}catch{return t}}const gi=({file:e,fromFile:t,preferFileExtension:n,root:r})=>{let i=e.finalPath.split(f.sep).join(`/`),a=t.finalPath.split(f.sep).join(`/`);if(t.external&&!f.isAbsolute(a))return[0,0,a];if(!a.startsWith(r.split(f.sep).join(`/`)))return[1,0,a];let o=f.relative(f.dirname(i),f.dirname(a)).split(f.sep).join(`/`),s;return o.startsWith(`..`)?(a=`${o}/${t.name}${t.extension??``}`,s=o.split(f.sep).filter(e=>e===`..`).length):(a=`./${o?`${o}/`:``}${t.name}${t.extension??``}`,s=0),a.endsWith(`.ts`)&&(a=a.slice(0,-3)),n?a+=n:a.endsWith(`/index`)&&(a=a.slice(0,-6)),[2,s,a]};var _i=class{preferExportAll;preferFileExtension;resolveModuleName;constructor(e={}){this.preferExportAll=e.preferExportAll??!1,this.preferFileExtension=e.preferFileExtension??``,this.resolveModuleName=e.resolveModuleName}render(e){let t=``;t+=`// This file is auto-generated by @hey-api/openapi-ts
4
- `;let n=``;for(let t of this.getImports(e)){n&&(n+=`
5
- `);for(let e of t)n+=`${hi(this.renderImport(e))}\n`}t=`${t}${t&&n?`
6
- `:``}${n}`;let r=``;for(let t of e.file.nodes)r&&(r+=`
7
- `),r+=`${hi(t.toAst())}\n`;t=`${t}${t&&r?`
8
- `:``}${r}`;let i=``;for(let t of this.getExports(e)){(!i&&r||i)&&(i+=`
9
- `);for(let e of t)i+=`${hi(this.renderExport(e))}\n`}return t=`${t}${t&&i?`
10
- `:``}${i}`,t}supports(e){return e.file.language===`typescript`}getExports(e){let t=new Map;for(let n of e.file.exports){let r=gi({file:e.file,fromFile:n.from,preferFileExtension:this.preferFileExtension,root:e.project.root}),i=this.resolveModuleName?.(r[2])??r[2],[a]=r;t.has(a)||t.set(a,new Map);let o=t.get(a);o.has(i)||o.set(i,{group:{canExportAll:n.canExportAll,exports:n.exports,isTypeOnly:n.isTypeOnly,modulePath:i,namespaceExport:n.namespaceExport},sortKey:r})}return Array.from(t.entries()).sort((e,t)=>e[0]-t[0]).map(([,e])=>{let t=Array.from(e.values());return t.sort((e,t)=>{let n=e.sortKey[1]-t.sortKey[1];return n===0?e.group.modulePath.localeCompare(t.group.modulePath):n}),t.map(e=>{let t=e.group;if(t.namespaceExport)t.exports=[];else{if(!t.exports.find(e=>!e.isTypeOnly)){t.isTypeOnly=!0;for(let e of t.exports)e.isTypeOnly=!1}t.exports.sort((e,t)=>e.exportedName.localeCompare(t.exportedName))}return t})})}getImports(e){let t=new Map;for(let n of e.file.imports){let r=gi({file:e.file,fromFile:n.from,preferFileExtension:this.preferFileExtension,root:e.project.root}),i=this.resolveModuleName?.(r[2])??r[2],[a]=r;t.has(a)||t.set(a,new Map);let o=t.get(a);o.has(i)||o.set(i,{group:{imports:[],isTypeOnly:!1,modulePath:i},sortKey:r});let s=o.get(i).group;n.namespaceImport?(s.isTypeOnly=n.isTypeOnly,s.namespaceImport=n.namespaceImport):s.imports.push(...n.imports)}return Array.from(t.entries()).sort((e,t)=>e[0]-t[0]).map(([,e])=>{let t=Array.from(e.values());return t.sort((e,t)=>{let n=e.sortKey[1]-t.sortKey[1];return n===0?e.group.modulePath.localeCompare(t.group.modulePath):n}),t.map(e=>{let t=e.group;if(t.namespaceImport)t.imports=[];else{if(!t.imports.find(e=>!e.isTypeOnly)){t.isTypeOnly=!0;for(let e of t.imports)e.isTypeOnly=!1}t.imports.sort((e,t)=>e.localName.localeCompare(t.localName))}return t})})}renderExport(e){let t=e.exports.map(e=>m.factory.createExportSpecifier(e.isTypeOnly,e.sourceName===e.exportedName?void 0:P.id(e.sourceName).toAst(),P.id(e.exportedName).toAst())),n=e.namespaceExport?m.factory.createNamespaceExport(P.id(e.namespaceExport).toAst()):(!e.canExportAll||!this.preferExportAll)&&t.length?m.factory.createNamedExports(t):void 0;return m.factory.createExportDeclaration(void 0,e.isTypeOnly,n,P.literal(e.modulePath).toAst())}renderImport(e){let t=e.imports.map(e=>m.factory.createImportSpecifier(e.isTypeOnly,e.sourceName===e.localName?void 0:P.id(e.sourceName).toAst(),P.id(e.localName).toAst())),n=m.factory.createImportClause(e.isTypeOnly,void 0,e.namespaceImport?m.factory.createNamespaceImport(P.id(e.namespaceImport).toAst()):m.factory.createNamedImports(t));return m.factory.createImportDeclaration(void 0,n,P.literal(e.modulePath).toAst())}};const vi={array:(...e)=>new Hn(...e),as:(...e)=>new $n(...e),attr:(...e)=>new rr(...e),await:(...e)=>new ar(...e),binary:(...e)=>new N(...e),block:(...e)=>new M(...e),call:(...e)=>new sr(...e),class:(...e)=>new An(...e),const:(...e)=>new Lr(...e).const(),decorator:(...e)=>new jt(...e),doc:(...e)=>new Nt(...e),enum:(...e)=>new Pn(...e),expr:(...e)=>new lr(...e),field:(...e)=>new fn(...e),fromValue:(...e)=>gr(...e),func:((e,t)=>e===void 0?new In:typeof e!=`string`||t===void 0?new In(e):new In(e,t)),getter:(...e)=>new Rn(...e),hint:(...e)=>new ur(...e),id:(...e)=>new pt(...e),if:(...e)=>new kr(...e),init:(...e)=>new En(...e),let:(...e)=>new Lr(...e).let(),literal:(...e)=>new D(...e),member:(...e)=>new Mn(...e),method:(...e)=>new On(...e),neg:(...e)=>new _t(...e).neg(),new:(...e)=>new vr(...e),newline:(...e)=>new mt(...e),not:(...e)=>new _t(...e).not(),note:(...e)=>new Dr(...e),object:(...e)=>new hr(...e),param:(...e)=>new xn(...e),pattern:(...e)=>new vn(...e),prefix:(...e)=>new _t(...e),prop:(...e)=>new pr(...e),regexp:(...e)=>new br(...e),return:(...e)=>new jr(...e),setter:(...e)=>new Bn(...e),stmt:(...e)=>new mn(...e),template:(...e)=>new Sr(...e),ternary:(...e)=>new wr(...e),throw:(...e)=>new Nr(...e),token:(...e)=>new j(...e),try:(...e)=>new Fr(...e),type:Object.assign((...e)=>new un(...e),{alias:(...e)=>new zr(...e),and:(...e)=>new Vr(...e),attr:(...e)=>new cn(...e),expr:(...e)=>new un(...e),fromValue:(...e)=>Qr(...e),func:(...e)=>new ei(...e),idx:(...e)=>new ni(...e),literal:(...e)=>new Ur(...e),mapped:(...e)=>new ii(...e),object:(...e)=>new Yr(...e),operator:(...e)=>new oi(...e),or:(...e)=>new ci(...e),param:(...e)=>new Gt(...e),query:(...e)=>new ui(...e),template:(...e)=>new fi(...e),tuple:(...e)=>new Zr(...e)}),typeofExpr:(...e)=>new Er(...e),var:(...e)=>new Lr(...e)},P=Object.assign((...e)=>new lr(...e),vi),yi=({config:e,name:t})=>{let n=e.plugins[`@hey-api/sdk`];if(n?.config.classNameBuilder){let e=``;return e=typeof n.config.classNameBuilder==`function`?n.config.classNameBuilder(t):n.config.classNameBuilder.replace(`{{name}}`,t),e}return t},bi=({securitySchemeObject:e})=>{if(e.type===`openIdConnect`)return{scheme:`bearer`,type:`http`};if(e.type===`oauth2`)return e.flows.password||e.flows.authorizationCode||e.flows.clientCredentials||e.flows.implicit?{scheme:`bearer`,type:`http`}:void 0;if(e.type===`apiKey`)return e.in===`header`?{name:e.name,type:`apiKey`}:e.in===`query`||e.in==`cookie`?{in:e.in,name:e.name,type:`apiKey`}:void 0;if(e.type===`http`){let t=e.scheme.toLowerCase();return t===`bearer`||t===`basic`?{scheme:t,type:`http`}:void 0}},xi=({operation:e,plugin:t})=>{if(!e.security||!t.config.auth)return[];let n=[];for(let t of e.security){let e=bi({securitySchemeObject:t});e?n.push(e):console.warn(`❗️ SDK warning: unsupported security scheme. Please open an issue if you'd like it added https://github.com/hey-api/openapi-ts/issues\n${JSON.stringify(t,null,2)}`)}return n},Si=`TComposable`,Ci=`DefaultT`,wi=`ResT`,Ti=/^(arguments|async|await|break|case|catch|class|const|continue|debugger|default|delete|do|else|enum|eval|export|extends|false|finally|for|from|function|if|implements|import|in|instanceof|interface|let|new|null|package|private|protected|public|return|static|super|switch|this|throw|true|try|typeof|var|void|while|with|yield)$/g,Ei=/~1/g,Di=/~0/g,F=e=>{let t=ki(e),n=t[t.length-1];return decodeURI(n)},Oi=e=>String(e).replace(/~/g,`~0`).replace(/\//g,`~1`),ki=e=>{let t=e.trim();return t.startsWith(`#`)&&(t=t.slice(1)),t.startsWith(`/`)&&(t=t.slice(1)),t?t.split(`/`).map(e=>e.replace(Ei,`/`).replace(Di,`~`)):[]},Ai=e=>{let t=e.trim();return t.startsWith(`#`)||(t=`#${t}`),t.length>1&&t.endsWith(`/`)&&(t=t.slice(0,-1)),t=t.replace(/\/+/g,`/`),t},ji=e=>{let t=e.map(Oi).join(`/`);return`#`+(t?`/${t}`:``)},Mi=({$ref:e,spec:t})=>{let n=ki(decodeURI(e)),r=t;for(let t of n){let n=t;if(r[n]===void 0)throw Error(`Reference not found: ${e}`);r=r[n]}return r},Ni=({operation:e})=>{let t=[`header`,`path`,`query`],n={},r=(e,t)=>{n[e]||(n[e]=new Set),n[e].add(t)};for(let n of t){let t=e.parameters?.[n];if(t)for(let e in t){let i=t[e];r(i.name,n)}}if(e.body)if(!e.body.schema.logicalOperator&&e.body.schema.type===`object`&&e.body.schema.properties){let t=e.body.schema.properties;for(let e in t)r(e,`body`)}else e.body.schema.$ref?r(y({case:`camelCase`,value:F(e.body.schema.$ref)}),`body`):r(`body`,`body`);let i=new Set;for(let e in n)n[e].size>1&&i.add(e);let a={},o=[];for(let n of t){let t=e.parameters?.[n];if(t)for(let e in t){let r=t[e],s=r.name,c=i.has(s)?`${n}_${s}`:s,l={isRequired:r.required??!1,name:c,schema:r.schema};c!==s&&(l.originalName=s),a[c]=l,o.push({in:n===`header`?`headers`:n,key:c,...c===s?{}:{map:s}})}}if(e.body){let t=`body`;if(!e.body.schema.logicalOperator&&e.body.schema.type===`object`&&e.body.schema.properties){let n=e.body.schema.properties;for(let e in n){let r=n[e],s=i.has(e)?`${t}_${e}`:e,c={isRequired:r.required?.includes(e)??!1,name:s,schema:r};s!==e&&(c.originalName=e),a[s]=c,o.push({in:t,key:s,...s===e?{}:{map:e}})}}else if(e.body.schema.$ref){let n=y({case:`camelCase`,value:F(e.body.schema.$ref)}),r=i.has(n)?`${t}_${n}`:n,s={isRequired:e.body.required??!1,name:r,schema:e.body.schema};r!==n&&(s.originalName=n),a[r]=s,o.push({key:r,map:`body`})}else a.body={isRequired:e.body.required??!1,name:`body`,schema:e.body.schema},o.push({in:`body`})}if(Object.keys(a).length)return{fields:o,parameters:a}},Pi=({operation:e,plugin:t})=>{if(!t.config.validator.request)return;let n=t.getPluginOrThrow(t.config.validator.request);if(n.api.createRequestValidator)return n.api.createRequestValidator({operation:e,plugin:n})},Fi=({operation:e,plugin:t})=>{if(!t.config.validator.response)return;let n=t.getPluginOrThrow(t.config.validator.response);if(n.api.createResponseValidator)return n.api.createResponseValidator({operation:e,plugin:n})},Ii=({context:e,value:t})=>{let n=y({case:`PascalCase`,value:ut(t)});return yi({config:e.config,name:n})},Li=({operation:e,plugin:t})=>t.config.methodNameBuilder?t.config.methodNameBuilder(e):!t.config.asClass&&e.id.match(Ti)?`${e.id}_`:e.id,Ri=({context:e,operation:t,plugin:n})=>{let r=new Map,i,a,o=[];n.config.classStructure===`auto`&&t.operationId&&(o=t.operationId.split(/[./]/).filter(Boolean),o.length>1&&(a=y({case:`camelCase`,value:ut(o.pop())}),i=o.pop()));let s=n.config.instance?[n.config.instance]:t.tags??[`default`];for(let c of s){let s=Ii({context:e,value:i||c}),l=[c];i&&(l=o.includes(c)||c===i?[...o,i]:[c,...o,i]),r.set(c,{className:s,methodName:a||Li({operation:t,plugin:n}),path:l.map(t=>Ii({context:e,value:t}))})}return r},zi=({isDataAllowed:e=!0,operation:t,plugin:n,throwOnError:r})=>{let i=w(n.context.config).name===`@hey-api/client-nuxt`,a=e?n.querySymbol({category:`type`,resource:`operation`,resourceId:t.id,role:`data`,tool:`typescript`}):void 0,o=n.referenceSymbol({category:`type`,resource:`client-options`,tool:`sdk`});if(i){let r=n.querySymbol({category:`type`,resource:`operation`,resourceId:t.id,role:`response`});return P.type(o).generic(Si).generic(e?a??`unknown`:`never`).generic(r??`unknown`).generic(Ci)}return r?P.type(o).generic(e?a??`unknown`:`never`).generic(r):P.type(o).$if(!e||a,t=>t.generic(e?a:`never`))},Bi=({isRequiredOptions:e,operation:t,plugin:n})=>{let r={argNames:[],fields:[],parameters:[]},i=n.getPluginOrThrow(`@hey-api/typescript`),a=w(n.context.config).name===`@hey-api/client-nuxt`;if(n.config.paramsStructure===`flat`){let e=Ni({operation:t,plugin:n}),a=P.type.object();if(e){let t=!1;for(let n in e.parameters){let r=e.parameters[n];r.isRequired&&(t=!0),a.prop(r.name,e=>e.required(r.isRequired).type(i.api.schemaToType({plugin:i,schema:r.schema,state:l({path:[]})})))}r.argNames.push(`parameters`);for(let t of e.fields)r.fields.push(t);r.parameters.push(P.param(`parameters`,e=>e.required(t).type(a)))}}return r.parameters.push(P.param(`options`,r=>r.required(e).type(zi({isDataAllowed:n.config.paramsStructure===`grouped`,operation:t,plugin:n,throwOnError:a?void 0:`ThrowOnError`})))),r},Vi=e=>{if(!e)return;let t=e.split(`;`)[0]?.trim();if(t){if(t.startsWith(`application/json`)||t.endsWith(`+json`))return`json`;if([`application/`,`audio/`,`image/`,`video/`].some(e=>t.startsWith(e)))return`blob`;if(t.startsWith(`text/`))return`text`}},Hi=({isRequiredOptions:e,opParameters:t,operation:n,plugin:r})=>{let i=w(r.context.config),a=i.name===`@hey-api/client-nuxt`,o=r.querySymbol({category:`type`,resource:`operation`,resourceId:n.id,role:a?`response`:`responses`}),s=r.querySymbol({category:`type`,resource:`operation`,resourceId:n.id,role:a?`error`:`errors`}),c=P.object();if(n.body)switch(n.body.type){case`form-data`:{let e=r.referenceSymbol({category:`external`,resource:`client.formDataBodySerializer`});c.spread(e);break}case`json`:break;case`text`:case`octet-stream`:c.prop(`bodySerializer`,P.literal(null));break;case`url-search-params`:{let e=r.referenceSymbol({category:`external`,resource:`client.urlSearchParamsBodySerializer`});c.spread(e);break}}let l=P.object();for(let e in n.parameters?.query){let t=n.parameters.query[e];t.schema.type===`array`||t.schema.type===`tuple`?(t.style!==`form`||!t.explode)&&l.prop(t.name,P.object().prop(`array`,P.object().$if(t.explode===!1,e=>e.prop(`explode`,P.literal(t.explode))).$if(t.style!==`form`,e=>e.prop(`style`,P.literal(t.style))))):t.schema.type===`object`&&(t.style!==`deepObject`||!t.explode)&&l.prop(t.name,P.object().prop(`object`,P.object().$if(t.explode===!1,e=>e.prop(`explode`,P.literal(t.explode))).$if(t.style!==`deepObject`,e=>e.prop(`style`,P.literal(t.style)))))}l.hasProps()&&c.prop(`querySerializer`,P.object().prop(`parameters`,l));let u=Pi({operation:n,plugin:r}),d=Fi({operation:n,plugin:r});if(u&&c.prop(`requestValidator`,u.arrow()),r.config.transformer){let e={category:`transform`,resource:`operation`,resourceId:n.id,role:`response`};if(r.isSymbolRegistered(e)){let t=r.referenceSymbol(e);c.prop(`responseTransformer`,P(t))}}let f=!1,p;for(let e in n.responses){let t=n.responses[e];!p&&i.name===`@hey-api/client-axios`&&ct({statusCode:e})===`2XX`&&(p=Vi(t.mediaType),p&&c.prop(`responseType`,P.literal(p))),t.mediaType===`text/event-stream`&&(f=!0)}d&&c.prop(`responseValidator`,d.arrow()),r.config.responseStyle===`data`&&c.prop(`responseStyle`,P.literal(r.config.responseStyle));let m=xi({context:r.context,operation:n,plugin:r});m.length&&c.prop(`security`,P.fromValue(m)),c.prop(`url`,P.literal(n.path)),c.spread(`options`);let h=[],g=t.argNames.length;if(g){let e=[],n=[];for(let n of t.argNames)e.push(P(n));for(let e of t.fields){let t=P.object();`in`in e&&t.prop(`in`,P.literal(e.in)),`key`in e&&(e.key&&t.prop(`key`,P.literal(e.key)),e.map&&t.prop(`map`,P.literal(e.map))),n.push(t)}let i=r.referenceSymbol({category:`external`,resource:`client.buildClientParams`});h.push(P.const(`params`).assign(P(i).call(P.array(...e),P.array(P.object().prop(`args`,P.array(...n)))))),c.spread(`params`)}if(n.body){let t=n.parameters?.header?.[`content-type`];if(!t?.required){let r=P.object().pretty().prop(t?.name??`Content-Type`,P.literal(n.body.type===`form-data`?null:n.body.mediaType)).spread(P(`options`).attr(`headers`).required(e));g&&r.spread(P(`params`).attr(`headers`)),c.prop(`headers`,r)}}let ee=r.config.client?r.getSymbol({category:`client`}):void 0,te,ne=P(`options`).attr(`client`).required(e);te=r.config.instance?ne.coalesce(P(`this`).attr(`client`)):ee?ne.coalesce(ee):ne;let re=f?te.attr(`sse`):te;return re=re.attr(n.method),h.push(P.return(re.call(c).$if(a,e=>e.generic(Si).generic(P.type.or(o??`unknown`,Ci)).generic(s??`unknown`).generic(Ci),e=>e.generic(o??`unknown`).generic(s??`unknown`).generic(`ThrowOnError`)).$if(r.config.responseStyle===`data`,e=>e.generic(P.type.literal(r.config.responseStyle))))),h},Ui=e=>e.replace(/\*\//g,`*`).replace(/\/\*/g,`*`).replace(/\r?\n(.*)/g,(e,t)=>h+t.trim()),I=e=>{let t=[];return e.summary&&t.push(Ui(e.summary)),e.description&&(t.length&&t.push(``),t.push(Ui(e.description))),e.deprecated&&(t.length&&t.push(``),t.push(`@deprecated`)),t.length?t:void 0},L=({context:e,operation:t})=>{let n=w(e.config).name===`@hey-api/client-nuxt`,r=e.config.plugins[`@hey-api/sdk`];if(r){if(!r.config.client&&!r.config.instance)return!0;if(r.config.paramsStructure===`flat`)return!1}return n||ot(t)},Wi=({operation:e})=>{for(let t in e.responses)if(e.responses[t].mediaType===`text/event-stream`)return!0;return!1},Gi=({plugin:e})=>{let t=new Map,n=new Set,r=e.getPluginOrThrow(`@hey-api/sdk`);e.forEach(`operation`,({operation:n})=>{let i=L({context:e.context,operation:n}),a=Ri({context:e.context,operation:n,plugin:r});for(let r of a.values())r.path.forEach((a,o)=>{t.has(a)||t.set(a,{className:a,classes:new Set,methods:new Set,nodes:[],root:!o});let s=r.path[o-1];if(s&&s!==a){let e=t.get(s);e.classes.add(a),t.set(s,e)}if(r.path.length!==o+1)return;let c=t.get(a),l=e.config.httpRequests.methodNameBuilder(n);if(c.methods.has(l))return;let u=Ji({isRequiredOptions:i,methodName:l,operation:n,plugin:e});c.nodes.length?c.nodes.push(P.newline(),u):c.nodes.push(u),c.methods.add(l),t.set(a,c)})},{order:`declarations`});let i=r=>{if(n.has(r.className))return;if(r.classes.size)for(let n of r.classes){let a=t.get(n);i(a),r.nodes.push(P.field(y({case:`camelCase`,value:a.className})).assign(P.new(b({config:{case:`preserve`,name:e.config.httpRequests.classNameBuilder},name:a.className}))))}let a=e.referenceSymbol({category:`external`,resource:`@angular/core.Injectable`}),o=e.registerSymbol({meta:{category:`utility`,resource:`class`,resourceId:r.className,tool:`angular`},name:b({config:{case:`preserve`,name:e.config.httpRequests.classNameBuilder},name:r.className})}),s=P.class(o).export().$if(r.root,e=>e.decorator(a,P.object().prop(`providedIn`,P.literal(`root`)))).do(...r.nodes);e.addNode(s),n.add(r.className)};for(let e of t.values())i(e)},Ki=({plugin:e})=>{e.forEach(`operation`,({operation:t})=>{let n=Yi({isRequiredOptions:L({context:e.context,operation:t}),operation:t,plugin:e,symbol:e.registerSymbol({meta:{category:`utility`,resource:`operation`,resourceId:t.id,role:`data`,tool:`angular`},name:e.config.httpRequests.methodNameBuilder(t)})});e.addNode(n)},{order:`declarations`})},qi=({operation:e,plugin:t})=>{let n=t.getSymbol({category:`client`});return P(`options`).attr(`client`).optional().$if(n,(e,t)=>e.coalesce(t)).attr(`requestOptions`).call(P.object().prop(`responseStyle`,P.literal(`data`)).prop(`method`,P.literal(e.method.toUpperCase())).prop(`url`,P.literal(e.path)).spread(`options`))},Ji=({isRequiredOptions:e,methodName:t,operation:n,plugin:r})=>{let i=r.referenceSymbol({category:`external`,resource:`@angular/common/http.HttpRequest`}),a=r.referenceSymbol({category:`type`,resource:`client-options`,tool:`sdk`}),o=r.querySymbol({category:`type`,resource:`operation`,resourceId:n.id,role:`data`,tool:`typescript`});return P.method(t).public().$if(I(n),(e,t)=>e.doc(t)).param(`options`,t=>t.required(e).type(P.type(a).generic(o??`unknown`).generic(`ThrowOnError`))).generic(`ThrowOnError`,e=>e.extends(`boolean`).default(!1)).returns(P.type(i).generic(`unknown`)).do(P.return(qi({operation:n,plugin:r})))},Yi=({isRequiredOptions:e,operation:t,plugin:n,symbol:r})=>{let i=n.referenceSymbol({category:`external`,resource:`@angular/common/http.HttpRequest`}),a=n.referenceSymbol({category:`type`,resource:`client-options`,tool:`sdk`}),o=n.querySymbol({category:`type`,resource:`operation`,resourceId:t.id,role:`data`,tool:`typescript`});return P.const(r).export().$if(I(t),(e,t)=>e.doc(t)).assign(P.func().param(`options`,t=>t.required(e).type(P.type(a).generic(o??`unknown`).generic(`ThrowOnError`))).generic(`ThrowOnError`,e=>e.extends(`boolean`).default(!1)).returns(P.type(i).generic(`unknown`)).do(P.return(qi({operation:t,plugin:n}))))},Xi=({plugin:e})=>{e.config.httpRequests.asClass?Gi({plugin:e}):Ki({plugin:e})},Zi=({plugin:e})=>{let t=new Map,n=new Set,r=e.getPluginOrThrow(`@hey-api/sdk`);e.forEach(`operation`,({operation:n})=>{let i=L({context:e.context,operation:n}),a=Ri({context:e.context,operation:n,plugin:r});for(let r of a.values())r.path.forEach((a,o)=>{t.has(a)||t.set(a,{className:a,classes:new Set,methods:new Set,nodes:[],root:!o});let s=r.path[o-1];if(s&&s!==a){let e=t.get(s);e.classes.add(a),t.set(s,e)}if(r.path.length!==o+1)return;let c=t.get(a),l=e.config.httpResources.methodNameBuilder(n);if(c.methods.has(l))return;let u=ea({isRequiredOptions:i,methodName:l,operation:n,plugin:e});c.nodes.length?c.nodes.push(P.newline(),u):c.nodes.push(u),c.methods.add(l),t.set(a,c)})},{order:`declarations`});let i=r=>{if(n.has(r.className))return;if(r.classes.size)for(let n of r.classes){let a=t.get(n);i(a),r.nodes.push(P.field(y({case:`camelCase`,value:a.className})).assign(P.new(b({config:{case:`preserve`,name:e.config.httpResources.classNameBuilder},name:a.className}))))}let a=e.referenceSymbol({category:`external`,resource:`@angular/core.Injectable`}),o=e.registerSymbol({name:b({config:{case:`preserve`,name:e.config.httpResources.classNameBuilder},name:r.className})}),s=P.class(o).export().$if(r.root,e=>e.decorator(a,P.object().prop(`providedIn`,P.literal(`root`)))).do(...r.nodes);e.addNode(s),n.add(r.className)};for(let e of t.values())i(e)},Qi=({plugin:e})=>{e.forEach(`operation`,({operation:t})=>{let n=ta({isRequiredOptions:L({context:e.context,operation:t}),operation:t,plugin:e,symbol:e.registerSymbol({name:e.config.httpResources.methodNameBuilder(t)})});e.addNode(n)},{order:`declarations`})},$i=({operation:e,plugin:t})=>{let n=t.getPluginOrThrow(`@hey-api/sdk`),r=t.referenceSymbol({category:`external`,resource:`@angular/common/http.httpResource`}),i=t.querySymbol({category:`type`,resource:`operation`,resourceId:e.id,role:`response`});if(t.config.httpRequests.asClass){let a=Ri({context:t.context,operation:e,plugin:n}),o=Array.from(a.values())[0];if(o){let n=o.path[0],a=t.referenceSymbol({category:`utility`,resource:`class`,resourceId:n,tool:`angular`}),s=P(t.referenceSymbol({category:`external`,resource:`@angular/core.inject`})).call(a);for(let e=1;e<o.path.length;e++){let t=o.path[e];t&&(s=s.attr(y({case:`camelCase`,value:t})))}return s=s.attr(t.config.httpRequests.methodNameBuilder(e)),P(r).call(P.func().do(P.const(`opts`).assign(P.ternary(`options`).do(P(`options`).call()).otherwise(P.id(`undefined`))),P.return(P.ternary(`opts`).do(s.call(`opts`)).otherwise(P.id(`undefined`))))).generic(i??`unknown`)}}else{let n=t.referenceSymbol({category:`utility`,resource:`operation`,resourceId:e.id,role:`data`,tool:`angular`});return P(r).call(P.func().do(P.const(`opts`).assign(P.ternary(`options`).do(P(`options`).call()).otherwise(P.id(`undefined`))),P.return(P.ternary(`opts`).do(P(n).call(`opts`)).otherwise(P.id(`undefined`))))).generic(i??`unknown`)}return P(r).call(P.func().do(P.return(P.id(`undefined`))).generic(i??`unknown`))},ea=({isRequiredOptions:e,methodName:t,operation:n,plugin:r})=>{let i=r.referenceSymbol({category:`type`,resource:`client-options`,tool:`sdk`}),a=r.querySymbol({category:`type`,resource:`operation`,resourceId:n.id,role:`data`,tool:`typescript`});return P.method(t).public().$if(I(n),(e,t)=>e.doc(t)).param(`options`,t=>t.required(e).type(P.type.func().returns(P.type.or(P.type(i).generic(a??`unknown`).generic(`ThrowOnError`),P.type(`undefined`))))).generic(`ThrowOnError`,e=>e.extends(`boolean`).default(!1)).do(P.return($i({operation:n,plugin:r})))},ta=({isRequiredOptions:e,operation:t,plugin:n,symbol:r})=>{let i=n.referenceSymbol({category:`type`,resource:`client-options`,tool:`sdk`}),a=n.querySymbol({category:`type`,resource:`operation`,resourceId:t.id,role:`data`,tool:`typescript`});return P.const(r).export().$if(I(t),(e,t)=>e.doc(t)).assign(P.func().param(`options`,t=>t.required(e).type(P.type.func().returns(P.type.or(P.type(i).generic(a??`unknown`).generic(`ThrowOnError`),P.type(`undefined`))))).generic(`ThrowOnError`,e=>e.extends(`boolean`).default(!1)).do(P.return($i({operation:t,plugin:n}))))},na=({plugin:e})=>{e.config.httpResources.asClass?Zi({plugin:e}):Qi({plugin:e})},ra={config:{exportFromIndex:!1},dependencies:[`@hey-api/client-angular`,`@hey-api/sdk`],handler:({plugin:e})=>{e.registerSymbol({external:`@angular/common/http`,kind:`type`,meta:{category:`external`,resource:`@angular/common/http.HttpRequest`},name:`HttpRequest`}),e.registerSymbol({external:`@angular/core`,meta:{category:`external`,resource:`@angular/core.inject`},name:`inject`}),e.registerSymbol({external:`@angular/core`,meta:{category:`external`,resource:`@angular/core.Injectable`},name:`Injectable`}),e.registerSymbol({external:`@angular/common/http`,meta:{category:`external`,resource:`@angular/common/http.httpResource`},name:`httpResource`}),e.config.httpRequests.enabled&&Xi({plugin:e}),e.config.httpResources.enabled&&na({plugin:e})},name:`@angular/common`,resolveConfig:(e,t)=>{if(e.config.httpRequests=t.valueToObject({defaultValue:{asClass:!1,classNameBuilder:`{{name}}Requests`,enabled:!0},mappers:{boolean:e=>({enabled:e})},value:e.config.httpRequests}),!e.config.httpRequests.methodNameBuilder){let{asClass:t}=e.config.httpRequests;e.config.httpRequests.methodNameBuilder=e=>t?String(e.id):`${String(e.id)}Request`}if(e.config.httpResources=t.valueToObject({defaultValue:{asClass:!1,classNameBuilder:`{{name}}Resources`,enabled:!0},mappers:{boolean:e=>({enabled:e})},value:e.config.httpResources}),!e.config.httpResources.methodNameBuilder){let{asClass:t}=e.config.httpResources;e.config.httpResources.methodNameBuilder=e=>t?String(e.id):`${String(e.id)}Resource`}}},ia={baseUrl:!0,bundle:!0,exportFromIndex:!1},aa={dependencies:[`@hey-api/typescript`],tags:[`client`]},oa=p(import.meta.url),sa=f.dirname(oa),ca=e=>{let t=w(e);if(`bundle`in t.config&&t.config.bundle){let t=e._FRAGILE_CLIENT_BUNDLE_RENAMED;return f.resolve(e.output.path,`client`,`${t?.get(`index`)??`index`}.ts`)}return t.name},la=(e,t)=>{if(d.statSync(e).isDirectory()){d.existsSync(t)||d.mkdirSync(t,{recursive:!0});let n=d.readdirSync(e);for(let r of n)la(f.join(e,r),f.join(t,r))}else{let n=d.readFileSync(e);d.writeFileSync(t,n)}},ua=({filePath:e,project:t,renamed:n})=>{let r=f.extname(e),i=f.basename(e,r),a=t.fileName?.(i)||i;if(a!==i){let t=f.dirname(e);d.renameSync(e,f.resolve(t,`${a}${r}`)),n.set(i,a)}},da=({filePath:e,meta:t,renamed:n})=>{let r=d.readFileSync(e,`utf8`);r=r.replace(/from\s+['"](\.\.?\/[^'"]*?)['"]/g,(e,r)=>{let i=e.indexOf(r),a=f.extname(r),o=f.basename(r,a),s=f.dirname(r),c=(n.get(o)??o)+(t.importFileExtension?t.importFileExtension:a);return e.slice(0,i)+[s,c].filter(Boolean).join(`/`)+e.slice(i+r.length)}),r=`// This file is auto-generated by @hey-api/openapi-ts
11
-
12
- ${r}`,d.writeFileSync(e,r,`utf8`)},fa=({meta:e,outputPath:t,plugin:n,project:r})=>{let i=new Map;if(n.name.startsWith(`@hey-api/client-`)){let a=f.resolve(t,`core`);ue(a),la(f.resolve(sa,`clients`,`core`),a);let o=f.resolve(t,`client`);ue(o);let s=n.name.slice(16);if(la(f.resolve(sa,`clients`,s),o),r){let e=d.readdirSync(a);for(let t of e)ua({filePath:f.resolve(a,t),project:r,renamed:i});let t=d.readdirSync(o);for(let e of t)ua({filePath:f.resolve(o,e),project:r,renamed:i})}let c=d.readdirSync(a);for(let t of c)da({filePath:f.resolve(a,t),meta:e,renamed:i});let l=d.readdirSync(o);for(let t of l)da({filePath:f.resolve(o,t),meta:e,renamed:i});return i}let a=f.isAbsolute(n.name)?f.dirname(n.name):void 0;if(a){let e=f.resolve(t,`client`);ue(e),la(a,e);return}let o=f.normalize(re.resolve(n.name)).split(f.sep),s=o.slice(0,o.indexOf(`dist`)+1).join(f.sep),c=[o[o.length-1],`index.d.mts`,`index.d.cts`],l=f.resolve(t,`client`);ue(l);for(let e of c)d.copyFileSync(f.resolve(s,e),f.resolve(l,e))},pa=/^(([^:/?#]+):)?((\/\/)?([^:/?#]*)(:?([^/?#]*)))?([^?#]*)(\?([^#]*))?(#(.*))?/,ma=e=>{let t={host:``,path:``,port:``,protocol:``};pa.lastIndex=0;let n=e.match(pa);if(!n)return t;let r=n[5]||``;if(r===`.`||r===`..`)return t;let i=n[8]||``,a=n[2]||``;return a.length===1?t:{host:r,path:i===`/`?``:i,port:n[7]||``,protocol:a}},ha=({plugin:e})=>{let{baseUrl:t}=e.config;if(t===!1)return;if(typeof t==`string`)return t;let{servers:n}=e.context.ir;if(n)return n[typeof t==`number`?t:0]?.url},ga=({plugin:e})=>{let t=ca(e.context.config),n=e.registerSymbol({external:t,name:`createClient`}),r=e.registerSymbol({external:t,name:`createConfig`}),i=e.referenceSymbol({category:`type`,resource:`client`,role:`options`}),{runtimeConfigPath:a}=e.config,o=a?e.registerSymbol({external:a,name:`createClientConfig`}):void 0,s=P.object(),c=ha({plugin:e});if(c){let t=ma(c);if(t.protocol&&t.host&&!c.includes(`{`))s.prop(dt(e.context.config),P.literal(c));else if(c!==`/`&&c.startsWith(`/`)){let t=c.endsWith(`/`)?c.slice(0,-1):c;s.prop(dt(e.context.config),P.literal(t))}}`throwOnError`in e.config&&e.config.throwOnError&&s.prop(`throwOnError`,P.literal(!0));let l=[P(r).call(s.hasProps()?s:void 0).generic(i)],u=e.registerSymbol({meta:{category:`client`},name:`client`}),d=P.const(u).export().assign(P(n).$if(o,(e,t)=>e.call(P(t).call(...l)),e=>e.call(...l)));e.addNode(d)},_a=({plugin:e})=>{let t=ca(e.context.config),n=e.referenceSymbol({category:`type`,resource:`client`,role:`options`}),r=e.registerSymbol({external:t,kind:`type`,name:`Config`}),i=e.registerSymbol({external:t,kind:`type`,name:`ClientOptions`}),a=e.registerSymbol({name:`CreateClientConfig`}),o=P.type.alias(a).export().doc(["The `createClientConfig()` function will be called on client initialization",`and the returned object will become the client's initial configuration.`,``,`You may want to initialize your client this way instead of calling`,"`setConfig()`. This is useful for example if you're using Next.js",`to ensure your client always has the correct values.`]).generic(`T`,e=>e.extends(i).default(n)).type(P.type.func().param(`override`,e=>e.optional().type(P.type(r).generic(P.type.and(i,`T`)))).returns(P.type(r).generic(P.type.and(P.type(`Required`).generic(i),`T`))));e.addNode(o)},va=({plugin:e})=>{_a({plugin:e}),ga({plugin:e})},ya={...aa,config:{...ia,throwOnError:!1},handler:va,name:`@hey-api/client-angular`},ba={...aa,config:{...ia,throwOnError:!1},handler:va,name:`@hey-api/client-axios`},xa={...aa,config:{...ia,throwOnError:!1},handler:va,name:`@hey-api/client-fetch`},Sa={...aa,config:{...ia,throwOnError:!1},handler:va,name:`@hey-api/client-ky`},Ca={...aa,config:{...ia,throwOnError:!1},handler:va,name:`@hey-api/client-next`},wa={...aa,config:ia,handler:va,name:`@hey-api/client-nuxt`},Ta={...aa,config:{...ia,throwOnError:!1},handler:va,name:`@hey-api/client-ofetch`},Ea=(...e)=>g.satisfies(...e),Da=e=>({getVersion:t=>{let n=e[t];if(n)try{let e=g.parse(n);if(e)return e;let t=g.minVersion(n);if(t)return t;if(e=g.coerce(n),e)return e}catch{}},isInstalled:t=>!!e[t],satisfies:(t,n,r)=>{let i=typeof t==`string`?e[t]:t;return i?Ea(i,n,r):!1}}),Oa=({plugin:e,schema:t})=>{e.config.type===`form`&&(t.description&&delete t.description,t[`x-enum-descriptions`]&&delete t[`x-enum-descriptions`],t[`x-enum-varnames`]&&delete t[`x-enum-varnames`],t[`x-enumNames`]&&delete t[`x-enumNames`],t.title&&delete t.title)},ka=({context:e,plugin:t,schema:n})=>{if(Array.isArray(n))return n.map(n=>ka({context:e,plugin:t,schema:n}));let r=structuredClone(n);if(r.$ref)return r.$ref=decodeURI(r.$ref),r;if(Oa({plugin:t,schema:r}),r.additionalProperties&&typeof r.additionalProperties!=`boolean`&&(r.additionalProperties=ka({context:e,plugin:t,schema:r.additionalProperties})),r.allOf&&=r.allOf.map(n=>ka({context:e,plugin:t,schema:n})),r.items&&=ka({context:e,plugin:t,schema:r.items}),r.properties)for(let n in r.properties){let i=r.properties[n];typeof i!=`boolean`&&(r.properties[n]=ka({context:e,plugin:t,schema:i}))}return r},Aa=({context:e,plugin:t,schema:n})=>{if(Array.isArray(n))return n.map(n=>Aa({context:e,plugin:t,schema:n}));let r=structuredClone(n);if(`$ref`in r)return r.$ref=decodeURI(r.$ref),r;if(Oa({plugin:t,schema:r}),r.additionalProperties&&typeof r.additionalProperties!=`boolean`&&(r.additionalProperties=Aa({context:e,plugin:t,schema:r.additionalProperties})),r.allOf&&=r.allOf.map(n=>Aa({context:e,plugin:t,schema:n})),r.anyOf&&=r.anyOf.map(n=>Aa({context:e,plugin:t,schema:n})),r.items&&=Aa({context:e,plugin:t,schema:r.items}),r.oneOf&&=r.oneOf.map(n=>Aa({context:e,plugin:t,schema:n})),r.properties)for(let n in r.properties){let i=r.properties[n];typeof i!=`boolean`&&(r.properties[n]=Aa({context:e,plugin:t,schema:i}))}return r},ja=({context:e,plugin:t,schema:n})=>{if(Array.isArray(n))return n.map(n=>ja({context:e,plugin:t,schema:n}));let r=structuredClone(n);if(Oa({plugin:t,schema:r}),r.$ref&&=decodeURI(r.$ref),r.additionalProperties&&typeof r.additionalProperties!=`boolean`&&(r.additionalProperties=ja({context:e,plugin:t,schema:r.additionalProperties})),r.allOf&&=r.allOf.map(n=>ja({context:e,plugin:t,schema:n})),r.anyOf&&=r.anyOf.map(n=>ja({context:e,plugin:t,schema:n})),r.items&&=ja({context:e,plugin:t,schema:r.items}),r.oneOf&&=r.oneOf.map(n=>ja({context:e,plugin:t,schema:n})),r.prefixItems&&=r.prefixItems.map(n=>ja({context:e,plugin:t,schema:n})),r.properties)for(let n in r.properties){let i=r.properties[n];typeof i!=`boolean`&&(r.properties[n]=ja({context:e,plugin:t,schema:i}))}return r},Ma=({name:e,plugin:t,schema:n})=>{let r=``;return t.config.nameBuilder&&(r=typeof t.config.nameBuilder==`function`?t.config.nameBuilder(e,n):t.config.nameBuilder.replace(`{{name}}`,e)),r||=`${e}Schema`,r},Na=({context:e,plugin:t})=>{if(e.spec.definitions)for(let n in e.spec.definitions){let r=e.spec.definitions[n],i=t.registerSymbol({meta:{category:`schema`,resource:`definition`,resourceId:n,tool:`json-schema`},name:Ma({name:n,plugin:t,schema:r})}),a=ka({context:e,plugin:t,schema:r}),o=P.const(i).export().assign(P(P.fromValue(a,{layout:`pretty`})).as(`const`));t.addNode(o)}},Pa=({context:e,plugin:t})=>{if(e.spec.components)for(let n in e.spec.components.schemas){let r=e.spec.components.schemas[n],i=t.registerSymbol({meta:{category:`schema`,resource:`definition`,resourceId:n,tool:`json-schema`},name:Ma({name:n,plugin:t,schema:r})}),a=Aa({context:e,plugin:t,schema:r}),o=P.const(i).export().assign(P(P.fromValue(a,{layout:`pretty`})).as(`const`));t.addNode(o)}},Fa=({context:e,plugin:t})=>{if(e.spec.components)for(let n in e.spec.components.schemas){let r=e.spec.components.schemas[n],i=t.registerSymbol({meta:{category:`schema`,resource:`definition`,resourceId:n,tool:`json-schema`},name:Ma({name:n,plugin:t,schema:r})}),a=ja({context:e,plugin:t,schema:r}),o=P.const(i).export().assign(P(P.fromValue(a,{layout:`pretty`})).as(`const`));t.addNode(o)}},Ia={config:{exportFromIndex:!1,nameBuilder:e=>`${e}Schema`,type:`json`},handler:({plugin:e})=>{if(`swagger`in e.context.spec){Na({context:e.context,plugin:e});return}if(Ea(e.context.spec.openapi,`>=3.0.0 <3.1.0`)){Pa({context:e.context,plugin:e});return}if(Ea(e.context.spec.openapi,`>=3.1.0`)){Fa({context:e.context,plugin:e});return}throw Error(`Unsupported OpenAPI specification`)},name:`@hey-api/schemas`},La=`__registry`,Ra=({sdkSymbol:e,symbol:t})=>{let n=`defaultKey`,r=`instances`;return P.class(t).generic(`T`).field(n,e=>e.private().readonly().assign(P.literal(`default`))).newline().field(r,e=>e.private().readonly().type(P.type(`Map`).generics(`string`,`T`)).assign(P.new(`Map`))).newline().method(`get`,t=>t.returns(`T`).param(`key`,e=>e.type(`string`).optional()).do(P.const(`instance`).assign(P(`this`).attr(`instances`).attr(`get`).call(P(`key`).coalesce(P(`this`).attr(n)))),P.if(P.not(`instance`)).do(P.throw(`Error`).message(P.template(`No SDK client found. Create one with "new `).add(e).add(`()" to fix this error.`))),P.return(`instance`))).newline().method(`set`,e=>e.returns(`void`).param(`value`,e=>e.type(`T`)).param(`key`,e=>e.type(`string`).optional()).do(P(`this`).attr(r).attr(`set`).call(P(`key`).coalesce(P(`this`).attr(n)),`value`)))},za=({plugin:e,symbol:t})=>{let n=e.getSymbol({category:`client`}),r=!!(e.config.client&&n),i=e.referenceSymbol({category:`external`,resource:`client.Client`});return P.class(t).field(`client`,e=>e.protected().type(i)).newline().init(e=>e.param(`args`,e=>e.optional(r).type(P.type.object().prop(`client`,e=>e.optional(r).type(i)))).do(P(`this`).attr(`client`).assign(P(`args`).attr(`client`).optional(r).$if(r,e=>e.coalesce(n)))))},Ba=({plugin:e})=>{let t=w(e.context.config),n=t.name===`@hey-api/client-angular`,r=t.name===`@hey-api/client-nuxt`,i=new Map,a=new Set;e.forEach(`operation`,({operation:a})=>{let o=L({context:e.context,operation:a}),s=r?e.querySymbol({category:`type`,resource:`operation`,resourceId:a.id,role:`response`}):void 0,c=Ri({context:e.context,operation:a,plugin:e});for(let l of c.values())l.path.forEach((c,u)=>{let d=e.referenceSymbol({category:`utility`,resource:`class`,resourceId:c,tool:`sdk`});i.has(d.meta.resourceId)||i.set(d.meta.resourceId,{className:d.meta.resourceId,classes:new Set,id:d.id,methods:new Set,nodes:[],root:!u});let f=l.path[u-1];if(f){let t=e.referenceSymbol({category:`utility`,resource:`class`,resourceId:f,tool:`sdk`});if(t.meta?.resourceId!==d.meta?.resourceId){let e=i.get(t.meta.resourceId);e.classes.add(d.meta.resourceId),i.set(t.meta.resourceId,e)}}if(l.path.length!==u+1)return;let p=i.get(d.meta.resourceId);if(p.methods.has(l.methodName))return;let m=Bi({isRequiredOptions:o,operation:a,plugin:e}),h=Hi({isRequiredOptions:o,opParameters:m,operation:a,plugin:e}),g=P.method(l.methodName,i=>i.$if(I(a),(e,t)=>e.doc(t)).public().static(!n&&!e.config.instance).$if(r,t=>t.generic(Si,t=>t.extends(e.referenceSymbol({category:`external`,resource:`client.Composable`})).default(P.type.literal(`$fetch`))).generic(Ci,e=>e.$if(s,(e,t)=>e.extends(t).default(t))),e=>e.generic(`ThrowOnError`,e=>e.extends(`boolean`).default((`throwOnError`in t.config?t.config.throwOnError:!1)??!1))).params(...m.parameters).do(...h));p.nodes.length?p.nodes.push(P.newline(),g):p.nodes.push(g),p.methods.add(l.methodName),i.set(d.meta.resourceId,p)})},{order:`declarations`});let o=e.config.instance?e.addNode(null):void 0,s=o===void 0?void 0:e.symbol(`HeyApiClient`,{meta:{category:`utility`,resource:`class`,resourceId:`HeyApiClient`,tool:`sdk`}}),c=e.config.instance?e.addNode(null):void 0,l=t=>{if(a.has(t.className))return;let r=t.className;if(a.add(r),t.classes.size)for(let n of t.classes){let r=i.get(n);l(r);let a=e.referenceSymbol({category:`utility`,resource:`class`,resourceId:r.className,tool:`sdk`}),o=y({case:`camelCase`,value:a.meta.resourceId});if(t.methods.has(o)){let e=2,n=`${o}${e}`;for(;t.methods.has(n);)n=`${o}${e++}`;o=n}t.methods.add(o);let s=e.isSymbolRegistered(a.id)?P.field(o,t=>t.static(!e.config.instance).assign(e.config.instance?P.new(a).args(P.object().prop(`client`,P(`this`).attr(`client`))):P(a))):P.getter(o,t=>t.$if(!e.config.instance,e=>e.public().static()).do(P.return(e.config.instance?P.new(a).args(P.object().prop(`client`,P(`this`).attr(`client`))):a)));t.nodes.length?t.nodes.push(P.newline(),s):t.nodes.push(s)}if(o!==void 0&&s&&!s.node){let t=za({plugin:e,symbol:s});e.updateNode(o,t)}let u=e.symbol(r,{meta:{category:`utility`,resource:`class`,resourceId:r,tool:`sdk`}});if(t.root&&c!==void 0){let n=e.getSymbol({category:`client`}),r=!e.config.client||!n,i=e.referenceSymbol({category:`external`,resource:`client.Client`}),a=P.init(e=>e.param(`args`,e=>e.required(r).type(P.type.object().prop(`client`,e=>e.required(r).type(i)).prop(`key`,e=>e.optional().type(`string`)))).do(P(`super`).call(`args`),P(u).attr(La).attr(`set`).call(`this`,P(`args`).attr(`key`).required(r))));t.nodes.length?t.nodes.unshift(a,P.newline()):t.nodes.unshift(a);let o=e.symbol(`HeyApiRegistry`,{meta:{category:`utility`,resource:`class`,resourceId:`HeyApiRegistry`,tool:`sdk`}}),s=Ra({plugin:e,sdkSymbol:u,symbol:o});e.updateNode(c,s);let l=P.field(La,e=>e.public().static().readonly().assign(P.new(o).generic(u)));t.nodes.unshift(l,P.newline())}let d=P.class(u).export().extends(s).$if(t.root&&n,t=>t.decorator(e.referenceSymbol({category:`external`,resource:`@angular/core.Injectable`}),P.object().prop(`providedIn`,P.literal(`root`)))).do(...t.nodes);e.addNode(d)};for(let e of i.values())l(e)},Va=({id:e,operation:t,plugin:n})=>n.config.methodNameBuilder?n.config.methodNameBuilder(t):e.match(Ti)?`${e}_`:e,Ha=({plugin:e})=>{let t=w(e.context.config),n=t.name===`@hey-api/client-nuxt`;e.forEach(`operation`,r=>{let{operation:i}=r,a=L({context:e.context,operation:i}),o=n?e.querySymbol({category:`type`,resource:`operation`,resourceId:i.id,role:`response`}):void 0,s=Bi({isRequiredOptions:a,operation:i,plugin:e}),c=Hi({isRequiredOptions:a,opParameters:s,operation:i,plugin:e}),l=e.registerSymbol({meta:{category:`sdk`,path:r._path,resource:`operation`,resourceId:i.id,tags:r.tags,tool:`sdk`},name:Va({id:i.id,operation:i,plugin:e})}),u=P.const(l).export().$if(I(i),(e,t)=>e.doc(t)).assign(P.func().params(...s.parameters).$if(n,t=>t.generic(Si,t=>t.extends(e.referenceSymbol({category:`external`,resource:`client.Composable`})).default(P.type.literal(`$fetch`))).generic(Ci,e=>e.$if(o,(e,t)=>e.extends(t).default(t),e=>e.default(`undefined`))),e=>e.generic(`ThrowOnError`,e=>e.extends(`boolean`).default((`throwOnError`in t.config?t.config.throwOnError:!1)??!1))).do(...c));e.addNode(u)},{order:`declarations`})},Ua=({plugin:e})=>{let t=ca(e.context.config),n=w(e.context.config),r=n.name===`@hey-api/client-nuxt`,i=e.registerSymbol({external:t,kind:`type`,name:`TDataShape`}),a=e.registerSymbol({external:t,kind:`type`,meta:{category:`external`,resource:`client.Client`,tool:n.name},name:`Client`}),o=e.registerSymbol({external:t,kind:`type`,name:`Options`}),s=e.registerSymbol({meta:{category:`type`,resource:`client-options`,tool:`sdk`},name:`Options`}),c=P.type.alias(s).export().$if(r,t=>t.generic(`TComposable`,t=>t.extends(e.referenceSymbol({category:`external`,resource:`client.Composable`})).default(P.type.literal(`$fetch`))).generic(`TData`,e=>e.extends(i).default(i)).generic(wi,e=>e.default(`unknown`)).generic(Ci,e=>e.default(`undefined`)),e=>e.generic(`TData`,e=>e.extends(i).default(i)).generic(`ThrowOnError`,e=>e.extends(`boolean`).default(`boolean`))).type(P.type.and(P.type(o).$if(r,e=>e.generic(`TComposable`).generic(`TData`).generic(wi).generic(Ci),e=>e.generic(`TData`).generic(`ThrowOnError`)),P.type.object().prop(`client`,t=>t.doc(["You can provide a client instance returned by `createClient()` instead of",`individual options. This might be also useful if you want to implement a`,`custom client.`]).required(!e.config.client&&!e.config.instance).type(a)).prop(`meta`,e=>e.doc(["You can pass arbitrary values through the `meta` object. This can be",`used to access values that aren't defined as part of the SDK function.`]).optional().type(P.type(`Record`).generics(`string`,`unknown`)))));e.addNode(c)},Wa=({plugin:e})=>{let t=ca(e.context.config),n=w(e.context.config),r=n.name===`@hey-api/client-angular`,i=n.name===`@hey-api/client-nuxt`;e.registerSymbol({external:t,meta:{category:`external`,resource:`client.formDataBodySerializer`,tool:n.name},name:`formDataBodySerializer`}),e.registerSymbol({external:t,meta:{category:`external`,resource:`client.urlSearchParamsBodySerializer`,tool:n.name},name:`urlSearchParamsBodySerializer`}),e.registerSymbol({external:t,meta:{category:`external`,resource:`client.buildClientParams`,tool:n.name},name:`buildClientParams`}),i&&e.registerSymbol({external:t,kind:`type`,meta:{category:`external`,resource:`client.Composable`,tool:n.name},name:`Composable`}),r&&e.config.asClass&&e.registerSymbol({external:`@angular/core`,meta:{category:`external`,resource:`@angular/core.Injectable`},name:`Injectable`}),Ua({plugin:e}),e.config.asClass?Ba({plugin:e}):Ha({plugin:e})},Ga={config:{asClass:!1,auth:!0,classNameBuilder:`{{name}}`,classStructure:`auto`,client:!0,exportFromIndex:!0,instance:!1,operationId:!0,paramsStructure:`grouped`,response:`body`,responseStyle:`fields`,transformer:!1,validator:!1},dependencies:[`@hey-api/typescript`],handler:e=>Wa(e),name:`@hey-api/sdk`,resolveConfig:(e,t)=>{e.config.client?(typeof e.config.client==`boolean`&&(e.config.client=t.pluginByTag(`client`,{defaultPlugin:`@hey-api/client-fetch`})),e.dependencies.add(e.config.client)):e.config.client=!1,e.config.transformer?(typeof e.config.transformer==`boolean`&&(e.config.transformer=t.pluginByTag(`transformer`)),e.dependencies.add(e.config.transformer)):e.config.transformer=!1,typeof e.config.validator!=`object`&&(e.config.validator={request:e.config.validator,response:e.config.validator}),e.config.validator.request?(typeof e.config.validator.request==`boolean`&&(e.config.validator.request=t.pluginByTag(`validator`)),e.dependencies.add(e.config.validator.request)):e.config.validator.request=!1,e.config.validator.response?(typeof e.config.validator.response==`boolean`&&(e.config.validator.response=t.pluginByTag(`validator`)),e.dependencies.add(e.config.validator.response)):e.config.validator.response=!1,e.config.instance?(typeof e.config.instance!=`string`&&(e.config.instance=`Sdk`),e.config.asClass=!0):e.config.instance=!1,e.config.classNameBuilder===`{{name}}`&&e.config.client===`@hey-api/client-angular`&&(e.config.classNameBuilder=`{{name}}Service`)}},Ka=({dataExpression:e,schema:t})=>{if(t.type!==`integer`||t.format!==`int64`)return;let n=e===void 0?void 0:P(`BigInt`).call(P.expr(e).attr(`toString`).call());if(n){if(typeof e==`string`)return[n];if(e)return[P.expr(e).assign(n)]}},qa=({dataExpression:e,schema:t})=>{if(!(t.type!==`string`||!(t.format===`date`||t.format===`date-time`))){if(typeof e==`string`)return[P.new(`Date`).arg(e)];if(e)return[P.expr(e).assign(P.new(`Date`).arg(e))]}},Ja=`data`,Ya=new Set,Xa=e=>e[`~dsl`]===`ReturnTsDsl`,Za=({plugin:e,schema:t})=>{let n=Qa({dataExpression:P(Ja),plugin:e,schema:t});if(n.length){let e=n[n.length-1];Xa(e)||n.push(P.return(Ja))}return n},Qa=({dataExpression:e,plugin:t,schema:n})=>{if(n.$ref){let r={category:`transform`,resource:`definition`,resourceId:n.$ref},i=t.getSymbol(r)??t.symbol(b({config:{case:`camelCase`,name:`{{name}}SchemaResponseTransformer`},name:F(n.$ref)}),{meta:r});if(!i.node&&!Ya.has(i.id)){Ya.add(i.id);try{let e=Za({plugin:t,schema:t.context.resolveIrRef(n.$ref)});if(e.length){let n=P.const(i).assign(P.func().param(Ja,e=>e.type(`any`)).do(...e));t.addNode(n)}}finally{Ya.delete(i.id)}}if(i.node||Ya.has(i.id)){let n=P(t.referenceSymbol(r)).call(e);if(e)return typeof e==`string`&&e===`item`?[P.return(n)]:[typeof e==`string`?n:P(e).assign(n)]}return[]}if(n.type===`array`){if(!e||typeof e==`string`)return[];let r=n.items?Qa({dataExpression:`item`,plugin:t,schema:n.items?.[0]?n.items[0]:{...n,type:void 0}}):[];if(!r.length)return[];let i=r;return i.some(e=>Xa(e))||i.push(P.return(`item`)),[P(e).assign(P(e).attr(`map`).call(P.func().param(`item`,e=>e.type(`any`)).do(...i)))]}if(n.type===`object`){let r=[],i=n.required??[];for(let a in n.properties){let o=n.properties[a],s=P(e||Ja).attr(a),c=Qa({dataExpression:s,plugin:t,schema:o});if(!c.length)continue;let l=!o.items?.find(e=>e.type===`null`);i.includes(a)&&l?r=r.concat(c):r.push(P.if(s).do(...c))}return r}if(n.items){if(n.items.length===1)return Qa({dataExpression:`item`,plugin:t,schema:n.items[0]});let r=[];if(n.logicalOperator===`and`||n.items.length===2&&n.items.find(e=>e.type===`null`||e.type===`void`)){for(let i of n.items){let n=Qa({dataExpression:e||`item`,plugin:t,schema:i});n.length&&(e?r=r.concat(n):r.push(P.if(`item`).do(...n),P.return(`item`)))}return r}n.type!==`enum`&&((n.items??[]).every(e=>[`boolean`,`integer`,`null`,`number`,`string`].includes(e.type))||console.warn(`❗️ Transformers warning: schema ${JSON.stringify(n)} is too complex and won't be currently processed. This will likely produce an incomplete transformer which is not what you want. Please open an issue if you'd like this improved https://github.com/hey-api/openapi-ts/issues`))}for(let r of t.config.transformers){let i=r({config:t.config,dataExpression:e,schema:n});if(i)return i}return[]},$a={config:{bigInt:!0,dates:!0,exportFromIndex:!1,transformers:[],typeTransformers:[]},dependencies:[`@hey-api/typescript`],handler:({plugin:e})=>{e.forEach(`operation`,({operation:t})=>{let{response:n}=lt(t);if(!n)return;if(n.items&&n.items.length>1){e.context.config.logs.level===`debug`&&console.warn(`❗️ Transformers warning: route ${C(t)} has ${n.items.length} non-void success responses. This is currently not handled and we will not generate a response transformer. Please open an issue if you'd like this feature https://github.com/hey-api/openapi-ts/issues`);return}let r=e.querySymbol({category:`type`,resource:`operation`,resourceId:t.id,role:`response`});if(!r)return;let i=Za({plugin:e,schema:n});if(!i.length)return;let a=e.registerSymbol({meta:{category:`transform`,resource:`operation`,resourceId:t.id,role:`response`},name:b({config:{case:`camelCase`,name:`{{name}}ResponseTransformer`},name:t.id})}),o=P.const(a).export().assign(P.func().async().param(Ja,e=>e.type(`any`)).returns(P.type(`Promise`).generic(r)).do(...i));e.addNode(o)},{order:`declarations`})},name:`@hey-api/transformers`,resolveConfig:e=>{e.config.transformers||(e.config.transformers=[]),e.config.dates&&(e.config.transformers=[...e.config.transformers,qa]),e.config.bigInt&&(e.config.transformers=[...e.config.transformers,Ka])},tags:[`transformer`]},eo=({server:e})=>{let t=ma(e.url);return t.protocol&&t.host?P.type.literal(e.url):P.type.template().add(t.protocol||P.type(`string`)).add(`://`).add(t.host||P.type(`string`)).add(t.port?`:${t.port}`:``).add(t.path||``)},to=({nodeIndex:e,plugin:t,servers:n})=>{let r=w(t.context.config),i=n.map(e=>eo({server:e}));n.length?`strictBaseUrl`in r.config&&r.config.strictBaseUrl||i.push(P.type.and(P.type(`string`),P.type.object())):i.push(P.type(`string`));let a=t.symbol(b({config:{case:t.config.case},name:`ClientOptions`}),{meta:{category:`type`,resource:`client`,role:`options`,tool:`typescript`}}),o=P.type.alias(a).export().type(P.type.object().prop(dt(t.context.config),e=>e.type(P.type.or(...i))));t.updateNode(e,o)},R=e=>{let t=[];return e.title&&t.push(Ui(e.title)),e.description&&(t.length&&t.push(``),t.push(Ui(e.description))),e.deprecated&&(t.length&&t.push(``),t.push(`@deprecated`)),t.length?t:void 0},no=({plugin:e,schema:t})=>{let n=[];return{obj:(t.items??[]).map((t,r)=>{let i=typeof t.const;n.includes(i)||n.push(i);let a;return a=t.title?t.title:i===`number`||i===`string`?`${t.const}`:i===`boolean`?t.const?`true`:`false`:t.const===null?`null`:`${r}`,a&&(a=y({case:e.config.enums.case,stripLeadingSeparators:!1,value:a}),O.number.lastIndex=0,O.number.test(a)&&e.config.enums.enabled&&(e.config.enums.mode===`typescript`||e.config.enums.mode===`typescript-const`)&&(a=`_${a}`)),{key:a,schema:t}}),typeofItems:n}},ro=({plugin:e,schema:t,state:r,type:i})=>{let a=ji(n(r.path));if(t.type===`enum`&&e.config.enums.enabled){let i=no({plugin:e,schema:t});if(e.config.enums.mode===`javascript`){e.config.enums.constantsIgnoreNull&&i.typeofItems.includes(`object`)&&(i.obj=i.obj.filter(e=>e.schema.const!==null));let o=e.registerSymbol({meta:{category:`utility`,path:n(r.path),resource:`definition`,resourceId:a,tags:n(r.tags),tool:`typescript`},name:b({config:e.config.definitions,name:F(a)})}),s=P.const(o).export().$if(R(t),(e,t)=>e.doc(t)).assign(P.object(...i.obj.map(e=>P.prop({kind:`prop`,name:e.key}).$if(R(e.schema),(e,t)=>e.doc(t)).value(P.fromValue(e.schema.const)))).as(`const`));e.addNode(s);let c=e.registerSymbol({meta:{category:`type`,path:n(r.path),resource:`definition`,resourceId:a,tags:n(r.tags),tool:`typescript`},name:b({config:e.config.definitions,name:F(a)})}),l=P.type.alias(c).export().$if(R(t),(e,t)=>e.doc(t)).type(P.type(c).idx(P.type(c).typeofType().keyof()).typeofType());e.addNode(l);return}else if((e.config.enums.mode===`typescript`||e.config.enums.mode===`typescript-const`)&&!i.typeofItems.some(e=>e!==`number`&&e!==`string`)){let o=e.registerSymbol({meta:{category:`type`,path:n(r.path),resource:`definition`,resourceId:a,tags:n(r.tags),tool:`typescript`},name:b({config:e.config.definitions,name:F(a)})}),s=P.enum(o).export().$if(R(t),(e,t)=>e.doc(t)).const(e.config.enums.mode===`typescript-const`).members(...i.obj.map(e=>P.member(e.key).$if(R(e.schema),(e,t)=>e.doc(t)).value(P.fromValue(e.schema.const))));e.addNode(s);return}}let o=e.registerSymbol({meta:{category:`type`,path:n(r.path),resource:`definition`,resourceId:a,tags:n(r.tags),tool:`typescript`},name:b({config:e.config.definitions,name:F(a)})}),s=P.type.alias(o).export().$if(R(t),(e,t)=>e.doc(t)).type(i);e.addNode(s)},io=({parameters:e})=>{let t={type:`object`};if(e){let n={},r=[];for(let t in e){let i=e[t];n[i.name]=x({detectFormat:!1,schema:i.schema}),i.required&&r.push(i.name)}t.properties=n,r.length&&(t.required=r)}return t},ao=({operation:e,plugin:t,state:r})=>{let i={type:`object`},a=[];i.properties||={},e.body?(i.properties.body=e.body.schema,e.body.required&&a.push(`body`)):i.properties.body={type:`never`},e.parameters?.header&&(i.properties.headers=io({parameters:e.parameters.header}),i.properties.headers.required&&a.push(`headers`)),e.parameters?.path?(i.properties.path=io({parameters:e.parameters.path}),i.properties.path.required&&a.push(`path`)):i.properties.path={type:`never`},e.parameters?.query?(i.properties.query=io({parameters:e.parameters.query}),i.properties.query.required&&a.push(`query`)):i.properties.query={type:`never`},i.properties.url={const:e.path,type:`string`},a.push(`url`),i.required=a;let o=t.registerSymbol({meta:{category:`type`,path:n(r.path),resource:`operation`,resourceId:e.id,role:`data`,tags:n(r.tags),tool:`typescript`},name:b({config:t.config.requests,name:e.id})}),s=P.type.alias(o).export().type(z({plugin:t,schema:i,state:r}));t.addNode(s)},oo=({operation:e,plugin:t,state:r})=>{ao({operation:e,plugin:t,state:r});let{error:i,errors:a,response:o,responses:s}=lt(e);if(a){let o=t.registerSymbol({meta:{category:`type`,path:n(r.path),resource:`operation`,resourceId:e.id,role:`errors`,tags:n(r.tags),tool:`typescript`},name:b({config:t.config.errors,name:e.id})}),s=P.type.alias(o).export().type(z({plugin:t,schema:a,state:r}));if(t.addNode(s),i){let i=t.registerSymbol({meta:{category:`type`,path:n(r.path),resource:`operation`,resourceId:e.id,role:`error`,tags:n(r.tags),tool:`typescript`},name:b({config:{case:t.config.errors.case,name:t.config.errors.error},name:e.id})}),a=P.type.alias(i).export().type(P.type(o).idx(P.type(o).keyof()));t.addNode(a)}}if(s){let i=t.registerSymbol({meta:{category:`type`,path:n(r.path),resource:`operation`,resourceId:e.id,role:`responses`,tags:n(r.tags),tool:`typescript`},name:b({config:t.config.responses,name:e.id})}),a=P.type.alias(i).export().type(z({plugin:t,schema:s,state:r}));if(t.addNode(a),o){let a=t.registerSymbol({meta:{category:`type`,path:n(r.path),resource:`operation`,resourceId:e.id,role:`response`,tags:n(r.tags),tool:`typescript`},name:b({config:{case:t.config.responses.case,name:t.config.responses.response},name:e.id})}),o=P.type.alias(a).export().type(P.type(i).idx(P.type(i).keyof()));t.addNode(o)}}},so=({operation:e,plugin:t,state:r})=>{let i={type:`object`},a=[];if(i.properties||={},e.body){let o=t.registerSymbol({meta:{category:`type`,path:n(r.path),resource:`webhook`,resourceId:e.id,role:`data`,tags:n(r.tags),tool:`typescript`},name:b({config:{case:t.config.webhooks.case,name:t.config.webhooks.payload},name:e.id})}),s=P.type.alias(o).export().$if(R(e.body.schema),(e,t)=>e.doc(t)).type(z({plugin:t,schema:e.body.schema,state:r}));t.addNode(s),i.properties.body={symbolRef:o},a.push(`body`)}else i.properties.body={type:`never`};i.properties.key={const:e.path,type:`string`},a.push(`key`),i.properties.path={type:`never`},i.properties.query={type:`never`},i.required=a;let o=t.registerSymbol({meta:{category:`type`,path:n(r.path),resource:`webhook`,resourceId:e.id,role:`data`,tags:n(r.tags),tool:`typescript`},name:b({config:t.config.webhooks,name:e.id})}),s=P.type.alias(o).export().type(z({plugin:t,schema:i,state:r}));return t.addNode(s),o},co=({operation:e,plugin:t,state:n})=>so({operation:e,plugin:t,state:n}),lo=({plugin:e,schema:t,state:r})=>{if(!t.items)return P.type(`Array`).generic(P.type(e.config.topType));t=x({detectFormat:!0,schema:t});let i=[];return t.items&&t.items.forEach((t,a)=>{let o=z({plugin:e,schema:t,state:{...r,path:c([...n(r.path),`items`,a])}});i.push(o)}),i.length===1?P.type(`Array`).generic(i[0]):t.logicalOperator===`and`?P.type(`Array`).generic(P.type.and(...i)):P.type(`Array`).generic(P.type.or(...i))},uo=({schema:e})=>e.const===void 0?P.type(`boolean`):P.type.literal(e.const),fo=({plugin:e,schema:t,state:n})=>z({plugin:e,schema:{...t,type:void 0},state:n}),po=e=>P.type(`never`),mo=e=>P.type.literal(null),ho=({plugin:e,schema:t})=>t.const===void 0?t.type===`integer`&&t.format===`int64`&&e.getPlugin(`@hey-api/transformers`)?.config.bigInt?P.type(`bigint`):P.type(`number`):P.type.literal(t.const),go=({plugin:e,schema:t,state:r})=>{let i=P.type.object(),a=t.required??[],o=[],s=!1;for(let l in t.properties){let u=t.properties[l],d=z({plugin:e,schema:u,state:{...r,path:c([...n(r.path),`properties`,l])}}),f=a.includes(l);i.prop(l,e=>e.$if(R(u),(e,t)=>e.doc(t)).readonly(u.accessScope===`read`).required(f).type(d)),o.push(u),f||(s=!0)}if(t.patternProperties)for(let e in t.patternProperties){let n=t.patternProperties[e];o.unshift(n)}let l=!!t.patternProperties&&Object.keys(t.patternProperties).length>0,u=t.additionalProperties,d=u!==!1&&u?u:void 0;if(l||d&&(d.type!==`never`||!o.length)){let n=d;n&&n.type!==`never`?o.unshift(n):!l&&!o.length&&n&&n.type===`never`&&(o=[n]),s&&o.push({type:`undefined`});let a=o.length===1?z({plugin:e,schema:o[0],state:r}):z({plugin:e,schema:{items:o,logicalOperator:`or`},state:r});if(t.propertyNames?.$ref)return P.type.mapped(`key`).key(z({plugin:e,schema:{$ref:t.propertyNames.$ref},state:r})).optional().type(a);i.idxSig(`key`,e=>e.key(`string`).type(a))}return i},_o=({plugin:e,schema:t})=>{if(t.const!==void 0)return P.type.literal(t.const);if(t.format){if(t.format===`binary`)return P.type.or(P.type(`Blob`),P.type(`File`));if((t.format===`date-time`||t.format===`date`)&&e.getPlugin(`@hey-api/transformers`)?.config.dates)return P.type(`Date`);if(t.format===`typeid`&&typeof t.example==`string`){let n=String(t.example).split(`_`);n.pop();let r=n.join(`_`),i={category:`type`,resource:`type-id`,resourceId:r,tool:`typescript`};if(!e.getSymbol(i)){let t={category:`type`,resource:`type-id`,tool:`typescript`,variant:`container`};if(!e.getSymbol(t)){let n=e.registerSymbol({meta:t,name:`TypeID`}),r=P.type.alias(n).export().generic(`T`,e=>e.extends(`string`)).type(P.type.template().add(P.type(`T`)).add(`_`).add(P.type(`string`)));e.addNode(r)}let n=e.referenceSymbol(t),a=e.registerSymbol({meta:i,name:y({case:e.config.case,value:`${r}_id`})}),o=P.type.alias(a).export().type(P.type(n).generic(P.type.literal(r)));e.addNode(o)}let a=e.referenceSymbol(i);return P.type(a)}}return P.type(`string`)},vo=({plugin:e,schema:t,state:r})=>{let i=[];return t.const&&Array.isArray(t.const)?i=t.const.map(e=>P.type.fromValue(e)):t.items&&t.items.forEach((t,a)=>{let o=z({plugin:e,schema:t,state:{...r,path:c([...n(r.path),`items`,a])}});i.push(o)}),P.type.tuple(...i)},yo=e=>P.type(`undefined`),bo=({plugin:e})=>P.type(e.config.topType),xo=e=>P.type(`void`),So=({schema:e,...t})=>{let n=t.plugin.getPlugin(`@hey-api/transformers`);if(n?.config.typeTransformers)for(let t of n.config.typeTransformers){let n=t({schema:e});if(n)return n}switch(e.type){case`array`:return lo({...t,schema:e});case`boolean`:return uo({...t,schema:e});case`enum`:return fo({...t,schema:e});case`integer`:case`number`:return ho({...t,schema:e});case`never`:return po({...t,schema:e});case`null`:return mo({...t,schema:e});case`object`:return go({...t,schema:e});case`string`:return _o({...t,schema:e});case`tuple`:return vo({...t,schema:e});case`undefined`:return yo({...t,schema:e});case`unknown`:return bo({...t,schema:e});case`void`:return xo({...t,schema:e})}},z=({plugin:e,schema:t,state:n})=>{if(t.symbolRef)return P.type(t.symbolRef);if(t.$ref){let n=e.referenceSymbol({category:`type`,resource:`definition`,resourceId:t.$ref});return P.type(n)}if(t.type)return So({plugin:e,schema:t,state:n});if(t.items){if(t=x({detectFormat:!1,schema:t}),t.items){let r=t.items.map(t=>z({plugin:e,schema:t,state:n}));return t.logicalOperator===`and`?P.type.and(...r):P.type.or(...r)}return z({plugin:e,schema:t,state:n})}return So({plugin:e,schema:{type:`unknown`},state:n})},Co=({plugin:e,schema:t,state:n})=>{ro({plugin:e,schema:t,state:n,type:z({plugin:e,schema:t,state:n})})},wo=({plugin:e})=>{let t=e.addNode(null),n=e.addNode(null),r=[],i=[];if(e.forEach(`operation`,`parameter`,`requestBody`,`schema`,`server`,`webhook`,t=>{let n=l({path:t._path,tags:t.tags});switch(t.type){case`operation`:oo({operation:t.operation,plugin:e,state:n});break;case`parameter`:Co({plugin:e,schema:t.parameter.schema,state:n});break;case`requestBody`:Co({plugin:e,schema:t.requestBody.schema,state:n});break;case`schema`:Co({plugin:e,schema:t.schema,state:n});break;case`server`:r.push(t.server);break;case`webhook`:i.push(co({operation:t.operation,plugin:e,state:n}));break}},{order:`declarations`}),to({nodeIndex:t,plugin:e,servers:r}),i.length>0){let t=e.symbol(b({config:{case:e.config.case},name:`Webhooks`}),{meta:{category:`type`,resource:`webhook`,tool:`typescript`,variant:`container`}}),r=P.type.alias(t).export().type(P.type.or(...i));e.updateNode(n,r)}},To={api:new class{schemaToType(e){return z(e)}},config:{case:`PascalCase`,exportFromIndex:!0,topType:`unknown`},handler:e=>wo(e),name:`@hey-api/typescript`,resolveConfig:(e,t)=>{e.config.definitions=t.valueToObject({defaultValue:{case:e.config.case??`PascalCase`,name:`{{name}}`},mappers:{function:e=>({name:e}),string:e=>({name:e})},value:e.config.definitions}),e.config.enums=t.valueToObject({defaultValue:{case:`SCREAMING_SNAKE_CASE`,constantsIgnoreNull:!1,enabled:!!e.config.enums,mode:`javascript`},mappers:{boolean:e=>({enabled:e}),string:e=>({mode:e})},value:e.config.enums}),e.config.errors=t.valueToObject({defaultValue:{case:e.config.case??`PascalCase`,error:`{{name}}Error`,name:`{{name}}Errors`},mappers:{function:e=>({name:e}),string:e=>({name:e})},value:e.config.errors}),e.config.requests=t.valueToObject({defaultValue:{case:e.config.case??`PascalCase`,name:`{{name}}Data`},mappers:{function:e=>({name:e}),string:e=>({name:e})},value:e.config.requests}),e.config.responses=t.valueToObject({defaultValue:{case:e.config.case??`PascalCase`,name:`{{name}}Responses`,response:`{{name}}Response`},mappers:{function:e=>({name:e}),string:e=>({name:e})},value:e.config.responses}),e.config.webhooks=t.valueToObject({defaultValue:{case:e.config.case??`PascalCase`,name:`{{name}}WebhookRequest`,payload:`{{name}}WebhookPayload`},mappers:{function:e=>({name:e}),string:e=>({name:e})},value:e.config.webhooks})}},Eo=(e,t,n)=>{let r=e.config[n].meta;if(!r)return;let i=r(t);if(Object.keys(i).length)return P.fromValue(i)},Do=({operation:e,plugin:t})=>zi({operation:e,plugin:t.getPluginOrThrow(`@hey-api/sdk`)}),Oo=({operation:e,plugin:t})=>{let n=w(t.context.config),r=t.querySymbol({category:`type`,resource:`operation`,resourceId:e.id,role:`error`})||`Error`;if(n.name===`@hey-api/client-axios`){let e=t.referenceSymbol({category:`external`,resource:`axios.AxiosError`});return P.type(e).generic(r)}return P.type(r)},ko=({operation:e,plugin:t})=>{let n=t.querySymbol({category:`type`,resource:`operation`,resourceId:e.id,role:`response`});return P.type(n??`unknown`)},Ao=({isNuxtClient:e,operation:t,plugin:n})=>{let r=Do({operation:t,plugin:n});return e?P.type(`Omit`).generic(r).generic(`composable`):r},jo=({operation:e,plugin:t,queryFn:n})=>{let r=t.referenceSymbol({category:`external`,resource:`${t.name}.UseMutationOptions`}),i=w(t.context.config).name===`@hey-api/client-nuxt`,a=Ao({isNuxtClient:i,operation:e,plugin:t}),o=t.symbol(`options`),s=t.symbol(`vars`),c=P(n).call(P.object().pretty().spread(o).spread(s).prop(`throwOnError`,P.literal(!0))).await(),l=[];t.getPluginOrThrow(`@hey-api/sdk`).config.responseStyle===`data`?l.push(P.return(c)):l.push(P.const().object(`data`).assign(c),P.return(`data`));let u=P.object().pretty().prop(`mutation`,P.func().async().param(s,e=>e.$if(i,e=>e.type(P.type(`Partial`).generic(a)))).do(...l)).$if(Eo(t,e,`mutationOptions`),(e,t)=>e.prop(`meta`,t)),d=t.registerSymbol({name:b({config:t.config.mutationOptions,name:e.id})}),f=P.const(d).export().$if(t.config.comments&&I(e),(e,t)=>e.doc(t)).assign(P.func().param(o,e=>e.optional().type(P.type(`Partial`).generic(a))).returns(P.type(r).generic(ko({operation:e,plugin:t})).generic(a).generic(Oo({operation:e,plugin:t}))).do(P.return(u)));t.addNode(f)},Mo=`TOptions`,No=({plugin:e})=>{let t=e.registerSymbol({meta:{category:`utility`,resource:`createQueryKey`,tool:e.name},name:b({config:{case:e.config.case},name:`createQueryKey`})}),n=e.referenceSymbol({category:`type`,resource:`QueryKey`,tool:e.name}),r=e.referenceSymbol({category:`external`,resource:`${e.name}._JSONValue`}),i=P.type(n).generic(Mo).idx(0),a=dt(e.context.config),o=e.referenceSymbol({category:`type`,resource:`client-options`,tool:`sdk`}),s=e.getSymbol({category:`client`}),c=ca(e.context.config),l=e.registerSymbol({external:c,meta:{category:`external`,resource:`${c}.serializeQueryKeyValue`},name:`serializeQueryKeyValue`}),u=P.const(t).assign(P.func().param(`id`,e=>e.type(`string`)).param(`options`,e=>e.optional().type(Mo)).param(`tags`,e=>e.optional().type(`ReadonlyArray<string>`)).returns(P.type.tuple(i)).generic(Mo,e=>e.extends(o)).do(P.const(`params`).type(i).assign(P.object().prop(`_id`,`id`).prop(a,P(`options`).attr(a).optional().or(P(`options`).attr(`client`).optional().$if(s,(e,t)=>e.coalesce(t)).attr(`getConfig`).call().attr(a))).as(i)),P.if(`tags`).do(P(`params`).attr(`tags`).assign(P(`tags`).as(`unknown`).as(r))),P.if(P(`options`).attr(`body`).optional().neq(P.id(`undefined`))).do(P.const(`normalizedBody`).assign(P(l).call(P(`options`).attr(`body`))),P.if(P(`normalizedBody`).neq(P.id(`undefined`))).do(P(`params`).attr(`body`).assign(`normalizedBody`))),P.if(P(`options`).attr(`path`).optional()).do(P(`params`).attr(`path`).assign(P(`options`).attr(`path`))),P.if(P(`options`).attr(`query`).optional().neq(P.id(`undefined`))).do(P.const(`normalizedQuery`).assign(P(l).call(P(`options`).attr(`query`))),P.if(P(`normalizedQuery`).neq(P.id(`undefined`))).do(P(`params`).attr(`query`).assign(`normalizedQuery`))),P.return(P.array(P(`params`)))));e.addNode(u)},Po=({id:e,operation:t,plugin:n})=>{let r=n.config.queryKeys,i;return r.tags&&t.tags&&t.tags.length>0&&(i=P.array(...t.tags.map(e=>P.literal(e)))),P(n.referenceSymbol({category:`utility`,resource:`createQueryKey`,tool:n.name})).call(P.literal(e),`options`,i)},Fo=({plugin:e})=>{let t=e.referenceSymbol({category:`external`,resource:`${e.name}._JSONValue`}),n=e.referenceSymbol({category:`type`,resource:`client-options`,tool:`sdk`}),r=e.registerSymbol({meta:{category:`type`,resource:`QueryKey`,tool:e.name},name:`QueryKey`}),i=P.type.alias(r).export().generic(Mo,e=>e.extends(P.type(n))).type(P.type.tuple(P.type.and(P.type(`Pick<${Mo}, 'path'>`),P.type.object().prop(`_id`,e=>e.type(`string`)).prop(dt(e.context.config),e=>e.optional().type(t)).prop(`body`,e=>e.optional().type(t)).prop(`query`,e=>e.optional().type(t)).prop(`tags`,e=>e.optional().type(t)))));e.addNode(i)},Io=({operation:e,plugin:t,symbol:n})=>{let r=w(t.context.config).name===`@hey-api/client-nuxt`;return P.const(n).export().assign(P.func().param(`options`,n=>n.required(ot(e)).type(Ao({isNuxtClient:r,operation:e,plugin:t}))).do(Po({id:e.id,operation:e,plugin:t}).return()))},Lo=`options`,Ro=`context`,zo=({operation:e,plugin:t,queryFn:n})=>{if(Wi({operation:e}))return;let r=L({context:t.context,operation:e});t.getSymbol({category:`utility`,resource:`createQueryKey`,tool:t.name})||(Fo({plugin:t}),No({plugin:t}));let i;if(t.config.queryKeys.enabled){let n=t.registerSymbol({name:b({config:t.config.queryKeys,name:e.id})}),r=Io({operation:e,plugin:t,symbol:n});t.addNode(r),i=P(n).call(Lo)}else{let n=t.referenceSymbol({category:`utility`,resource:`createQueryKey`,tool:t.name}),r;t.config.queryKeys.tags&&e.tags&&e.tags.length>0&&(r=P.array(...e.tags.map(e=>P.literal(e)))),i=P(n).call(P.literal(e.id),Lo,r)}let a=Ao({isNuxtClient:w(t.context.config).name===`@hey-api/client-nuxt`,operation:e,plugin:t}),o=P(n).call(P.object().spread(Lo).spread(Ro).prop(`throwOnError`,P.literal(!0))).await(),s=[];t.getPluginOrThrow(`@hey-api/sdk`).config.responseStyle===`data`?s.push(P.return(o)):s.push(P.const().object(`data`).assign(o),P.return(`data`));let c=P.object().pretty().prop(`key`,i).prop(`query`,P.func().async().param(Ro).do(...s)).$if(Eo(t,e,`queryOptions`),(e,t)=>e.prop(`meta`,t)),l=t.registerSymbol({meta:{category:`hook`,resource:`operation`,resourceId:e.id,role:`queryOptions`,tool:t.name},name:b({config:t.config.queryOptions,name:e.id})}),u=t.referenceSymbol({category:`external`,resource:`${t.name}.defineQueryOptions`}),d=P.const(l).export().$if(t.config.comments&&I(e),(e,t)=>e.doc(t)).assign(P(u).call(P.func().param(Lo,e=>e.required(r).type(a)).do(P.return(c))));t.addNode(d)},Bo=({plugin:e})=>{e.registerSymbol({external:e.name,meta:{category:`external`,resource:`${e.name}.defineQueryOptions`},name:`defineQueryOptions`}),e.registerSymbol({external:e.name,kind:`type`,meta:{category:`external`,resource:`${e.name}.UseMutationOptions`},name:`UseMutationOptions`}),e.registerSymbol({external:e.name,kind:`type`,meta:{category:`external`,resource:`${e.name}.UseQueryOptions`},name:`UseQueryOptions`}),e.registerSymbol({external:e.name,kind:`type`,meta:{category:`external`,resource:`${e.name}._JSONValue`},name:`_JSONValue`}),e.registerSymbol({external:`axios`,kind:`type`,meta:{category:`external`,resource:`axios.AxiosError`},name:`AxiosError`});let t=e.getPluginOrThrow(`@hey-api/sdk`);e.forEach(`operation`,({operation:n})=>{let r=t.config.asClass?Ri({context:e.context,operation:n,plugin:t}):void 0,i=r?r.values().next().value:void 0,a;if(i){a=P(e.referenceSymbol({category:`utility`,resource:`class`,resourceId:i.path[0],tool:`sdk`})).$if(t.config.instance,e=>e.attr(La).attr(`get`).call());for(let e of i.path.slice(1)){let t=y({case:`camelCase`,value:e});a=a.attr(t)}a=a.attr(i.methodName)}else a=P(e.referenceSymbol({category:`sdk`,resource:`operation`,resourceId:n.id}));e.hooks.operation.isQuery(n)&&e.config.queryOptions.enabled&&zo({operation:n,plugin:e,queryFn:a}),e.hooks.operation.isMutation(n)&&e.config.mutationOptions.enabled&&jo({operation:n,plugin:e,queryFn:a})},{order:`declarations`})},Vo={config:{case:`camelCase`,comments:!0,exportFromIndex:!1},dependencies:[`@hey-api/typescript`,`@hey-api/sdk`],handler:e=>Bo(e),name:`@pinia/colada`,resolveConfig:(e,t)=>{e.config.mutationOptions=t.valueToObject({defaultValue:{case:e.config.case??`camelCase`,enabled:!0,name:`{{name}}Mutation`},mappers:{boolean:e=>({enabled:e}),function:e=>({name:e}),string:e=>({name:e})},value:e.config.mutationOptions}),e.config.queryKeys=t.valueToObject({defaultValue:{case:e.config.case??`camelCase`,enabled:!0,name:`{{name}}QueryKey`,tags:!1},mappers:{boolean:e=>({enabled:e}),function:e=>({name:e}),string:e=>({name:e})},value:e.config.queryKeys}),e.config.queryOptions=t.valueToObject({defaultValue:{case:e.config.case??`camelCase`,enabled:!0,name:`{{name}}Query`},mappers:{boolean:e=>({enabled:e}),function:e=>({name:e}),string:e=>({name:e})},value:e.config.queryOptions})}},Ho=({operation:e,plugin:t})=>zi({operation:e,plugin:t.getPluginOrThrow(`@hey-api/sdk`)}),Uo=({operation:e,plugin:t})=>{let n=w(t.context.config),r=t.querySymbol({category:`type`,resource:`operation`,resourceId:e.id,role:`error`})||t.referenceSymbol({category:`external`,resource:`${t.name}.DefaultError`});if(n.name===`@hey-api/client-axios`){let e=t.referenceSymbol({category:`external`,resource:`axios.AxiosError`});return P.type(e).generic(r)}return P.type(r)},Wo=({operation:e,plugin:t})=>{let n=t.querySymbol({category:`type`,resource:`operation`,resourceId:e.id,role:`response`});return P.type(n??`unknown`)},Go=`TOptions`,Ko=({plugin:e})=>{let t=e.registerSymbol({meta:{category:`utility`,resource:`createQueryKey`,tool:e.name},name:b({config:{case:e.config.case},name:`createQueryKey`})}),n=e.referenceSymbol({category:`type`,resource:`QueryKey`,tool:e.name}),r=dt(e.context.config),i=e.getSymbol({category:`client`}),a=e.referenceSymbol({category:`type`,resource:`client-options`,tool:`sdk`}),o=P.type(n).generic(Go).idx(0),s=P.const(t).assign(P.func().param(`id`,e=>e.type(`string`)).param(`options`,e=>e.optional().type(Go)).param(`infinite`,e=>e.optional().type(`boolean`)).param(`tags`,e=>e.optional().type(`ReadonlyArray<string>`)).generic(Go,e=>e.extends(a)).returns(P.type.tuple(o)).do(P.const(`params`).type(o).assign(P.object().prop(`_id`,`id`).prop(r,P(`options`).attr(r).optional().or(P(`options`).attr(`client`).optional().$if(i,(e,t)=>e.coalesce(t)).attr(`getConfig`).call().attr(r))).as(o)),P.if(`infinite`).do(P(`params`).attr(`_infinite`).assign(`infinite`)),P.if(`tags`).do(P(`params`).attr(`tags`).assign(`tags`)),P.if(P(`options`).attr(`body`).optional()).do(P(`params`).attr(`body`).assign(P(`options`).attr(`body`))),P.if(P(`options`).attr(`headers`).optional()).do(P(`params`).attr(`headers`).assign(P(`options`).attr(`headers`))),P.if(P(`options`).attr(`path`).optional()).do(P(`params`).attr(`path`).assign(P(`options`).attr(`path`))),P.if(P(`options`).attr(`query`).optional()).do(P(`params`).attr(`query`).assign(P(`options`).attr(`query`))),P.return(P.array().element(P(`params`)))));e.addNode(s)},qo=({id:e,isInfinite:t,operation:n,plugin:r})=>{let i=t?r.config.infiniteQueryKeys:r.config.queryKeys,a;return i.tags&&n.tags&&n.tags.length>0&&(a=P.array().elements(...n.tags)),P(r.referenceSymbol({category:`utility`,resource:`createQueryKey`,tool:r.name})).call(P.literal(e),`options`,t||a?P.literal(!!t):void 0,a)},Jo=({plugin:e})=>{let t=e.referenceSymbol({category:`type`,resource:`client-options`,tool:`sdk`}),n=e.registerSymbol({meta:{category:`type`,resource:`QueryKey`,tool:e.name},name:`QueryKey`}),r=P.type.alias(n).export().generic(Go,e=>e.extends(t)).type(P.type.tuple(P.type.and(P.type(`Pick<${Go}, '${dt(e.context.config)}' | 'body' | 'headers' | 'path' | 'query'>`),P.type.object().prop(`_id`,e=>e.type(`string`)).prop(`_infinite`,e=>e.optional().type(`boolean`)).prop(`tags`,e=>e.optional().type(`ReadonlyArray<string>`)))));e.addNode(r)},Yo=({isInfinite:e,operation:t,plugin:n,symbol:r,typeQueryKey:i})=>{let a=Ho({operation:t,plugin:n});return P.const(r).export().assign(P.func().param(`options`,e=>e.required(ot(t)).type(a)).$if(e&&i,(e,t)=>e.returns(t)).do(qo({id:t.id,isInfinite:e,operation:t,plugin:n}).return()))},Xo=(e,t,n)=>{let r=e.config[n].meta;if(!r)return;let i=r(t);if(Object.keys(i).length)return P.fromValue(i)},Zo=({plugin:e})=>{let t=e.registerSymbol({meta:{category:`utility`,resource:`createInfiniteParams`,tool:e.name},name:b({config:{case:e.config.case},name:`createInfiniteParams`})}),n=P.const(t).assign(P.func().generic(`K`,e=>e.extends(P.type(`Pick`).generics(P.type(`QueryKey`).generic(`Options`).idx(0),P.type.or(P.type.literal(`body`),P.type.literal(`headers`),P.type.literal(`path`),P.type.literal(`query`))))).param(`queryKey`,e=>e.type(`QueryKey<Options>`)).param(`page`,e=>e.type(`K`)).do(P.const(`params`).assign(P.object().spread(P(`queryKey`).attr(0))),P.if(P(`page`).attr(`body`)).do(P(`params`).attr(`body`).assign(P.object().pretty().spread(P(`queryKey`).attr(0).attr(`body`).as(`any`)).spread(P(`page`).attr(`body`).as(`any`)))),P.if(P(`page`).attr(`headers`)).do(P(`params`).attr(`headers`).assign(P.object().pretty().spread(P(`queryKey`).attr(0).attr(`headers`)).spread(P(`page`).attr(`headers`)))),P.if(P(`page`).attr(`path`)).do(P(`params`).attr(`path`).assign(P.object().pretty().spread(P(`queryKey`).attr(0).attr(`path`).as(`any`)).spread(P(`page`).attr(`path`).as(`any`)))),P.if(P(`page`).attr(`query`)).do(P(`params`).attr(`query`).assign(P.object().pretty().spread(P(`queryKey`).attr(0).attr(`query`).as(`any`)).spread(P(`page`).attr(`query`).as(`any`)))),P.return(P(`params`).as(`unknown`).as(P(`page`).typeofType()))));e.addNode(n)},Qo=({operation:e,plugin:t,queryFn:n})=>{let r=st({context:t.context,operation:e});if(!r)return;let i=L({context:t.context,operation:e});t.getSymbol({category:`utility`,resource:`createQueryKey`,tool:t.name})||(Jo({plugin:t}),Ko({plugin:t})),t.getSymbol({category:`utility`,resource:`createInfiniteParams`,tool:t.name})||Zo({plugin:t});let a=t.referenceSymbol({category:`external`,resource:`${t.name}.infiniteQueryOptions`}),o=t.referenceSymbol({category:`external`,resource:`${t.name}.InfiniteData`}),s=Ho({operation:e,plugin:t}),l=Wo({operation:e,plugin:t}),u=t.referenceSymbol({category:`type`,resource:`QueryKey`,tool:t.name}),d=P.type(u).generic(s),f=P.type(`Pick`).generics(d.idx(0),P.type.or(P.type.literal(`body`),P.type.literal(`headers`),P.type.literal(`path`),P.type.literal(`query`))),p=t.getPluginOrThrow(`@hey-api/typescript`),m=p.api.schemaToType({plugin:p,schema:r.schema,state:{path:c([])}}),h=t.registerSymbol({name:b({config:t.config.infiniteQueryKeys,name:e.id})}),g=Yo({isInfinite:!0,operation:e,plugin:t,symbol:h,typeQueryKey:d});t.addNode(g);let ee=P(n).call(P.object().spread(`options`).spread(`params`).prop(`signal`,P(`signal`)).prop(`throwOnError`,P.literal(!0))).await(),te=t.referenceSymbol({category:`utility`,resource:`createInfiniteParams`,tool:t.name}),ne=[P.const(`page`).type(f).hint(`@ts-ignore`).assign(P.ternary(P(`pageParam`).typeofExpr().eq(P.literal(`object`))).do(`pageParam`).otherwise(P.object().pretty().prop(r.in,P.object().pretty().prop(r.name,P(`pageParam`))))),P.const(`params`).assign(P(te).call(`queryKey`,`page`))];t.getPluginOrThrow(`@hey-api/sdk`).config.responseStyle===`data`?ne.push(P.return(ee)):ne.push(P.const().object(`data`).assign(ee),P.return(`data`));let re=t.registerSymbol({name:b({config:t.config.infiniteQueryOptions,name:e.id})}),ie=P.const(re).export().$if(t.config.comments&&I(e),(e,t)=>e.doc(t)).assign(P.func().param(`options`,e=>e.required(i).type(s)).do(P.return(P(a).call(P.object().pretty().hint(`@ts-ignore`).prop(`queryFn`,P.func().async().param(e=>e.object(`pageParam`,`queryKey`,`signal`)).do(...ne)).prop(`queryKey`,P(h).call(`options`)).$if(Xo(t,e,`infiniteQueryOptions`),(e,t)=>e.prop(`meta`,t))).generics(l,Uo({operation:e,plugin:t}),P.type(o).generic(l),d,P.type.or(m,f)))));t.addNode(ie)},$o=({operation:e,plugin:t,queryFn:n})=>{let r=t.referenceSymbol({category:`external`,resource:`${t.name}.MutationOptions`}),i=Ho({operation:e,plugin:t}),a=P.type(r).generic(Wo({operation:e,plugin:t})).generic(Uo({operation:e,plugin:t})).generic(i),o=`fnOptions`,s=P(n).call(P.object().spread(`options`).spread(o).prop(`throwOnError`,P.literal(!0))).await(),c=[];t.getPluginOrThrow(`@hey-api/sdk`).config.responseStyle===`data`?c.push(P.return(s)):c.push(P.const().object(`data`).assign(s),P.return(`data`));let l=`mutationOptions`,u=t.registerSymbol({name:b({config:t.config.mutationOptions,name:e.id})}),d=P.const(u).export().$if(t.config.comments&&I(e),(e,t)=>e.doc(t)).assign(P.func().param(`options`,e=>e.optional().type(P.type(`Partial`).generic(i))).returns(a).do(P.const(l).type(a).assign(P.object().pretty().prop(`mutationFn`,P.func().async().param(o).do(...c)).$if(Xo(t,e,`mutationOptions`),(e,t)=>e.prop(`meta`,t))),P(l).return()));t.addNode(d)},es=`options`,ts=({operation:e,plugin:t,queryFn:n})=>{if(Wi({operation:e}))return;let r=L({context:t.context,operation:e});t.getSymbol({category:`utility`,resource:`createQueryKey`,tool:t.name})||(Jo({plugin:t}),Ko({plugin:t}));let i=t.referenceSymbol({category:`external`,resource:`${t.name}.queryOptions`}),a=t.registerSymbol({name:b({config:t.config.queryKeys,name:e.id})}),o=Yo({isInfinite:!1,operation:e,plugin:t,symbol:a});t.addNode(o);let s=Wo({operation:e,plugin:t}),c=P(n).call(P.object().spread(es).spread(P(`queryKey`).attr(0)).prop(`signal`,P(`signal`)).prop(`throwOnError`,P.literal(!0))).await(),l=[];t.getPluginOrThrow(`@hey-api/sdk`).config.responseStyle===`data`?l.push(P.return(c)):l.push(P.const().object(`data`).assign(c),P.return(`data`));let u=P.object().pretty().prop(`queryFn`,P.func().async().param(e=>e.object(`queryKey`,`signal`)).do(...l)).prop(`queryKey`,P(a).call(es)).$if(Xo(t,e,`queryOptions`),(e,t)=>e.prop(`meta`,t)),d=t.registerSymbol({meta:{category:`hook`,resource:`operation`,resourceId:e.id,role:`queryOptions`,tool:t.name},name:b({config:t.config.queryOptions,name:e.id})}),f=P.const(d).export(t.config.queryOptions.exported).$if(t.config.comments&&I(e),(e,t)=>e.doc(t)).assign(P.func().param(es,n=>n.required(r).type(Ho({operation:e,plugin:t}))).do(P(i).call(u).generics(s,Uo({operation:e,plugin:t}),s,P(a).returnType()).return()));t.addNode(f)},ns=`options`,rs=({operation:e,plugin:t})=>{if(Wi({operation:e})||!(`useQuery`in t.config))return;let n=t.registerSymbol({name:b({config:t.config.useQuery,name:e.id})}),r=t.referenceSymbol({category:`external`,resource:`${t.name}.useQuery`}),i=L({context:t.context,operation:e}),a=Ho({operation:e,plugin:t}),o=t.referenceSymbol({category:`hook`,resource:`operation`,resourceId:e.id,role:`queryOptions`,tool:t.name}),s=P.const(n).export().$if(t.config.comments&&I(e),(e,t)=>e.doc(t)).assign(P.func().param(ns,e=>e.required(i).type(a)).do(P(r).call(P(o).call(ns)).return()));t.addNode(s)},is=({plugin:e})=>{e.registerSymbol({external:e.name,kind:`type`,meta:{category:`external`,resource:`${e.name}.DefaultError`},name:`DefaultError`}),e.registerSymbol({external:e.name,kind:`type`,meta:{category:`external`,resource:`${e.name}.InfiniteData`},name:`InfiniteData`});let t=e.name===`@tanstack/angular-query-experimental`||e.name===`@tanstack/svelte-query`||e.name===`@tanstack/solid-query`?`MutationOptions`:`UseMutationOptions`;e.registerSymbol({external:e.name,kind:`type`,meta:{category:`external`,resource:`${e.name}.MutationOptions`},name:t}),e.registerSymbol({external:e.name,meta:{category:`external`,resource:`${e.name}.infiniteQueryOptions`},name:`infiniteQueryOptions`}),e.registerSymbol({external:e.name,meta:{category:`external`,resource:`${e.name}.queryOptions`},name:`queryOptions`}),e.registerSymbol({external:e.name,meta:{category:`external`,resource:`${e.name}.useQuery`},name:`useQuery`}),e.registerSymbol({external:`axios`,kind:`type`,meta:{category:`external`,resource:`axios.AxiosError`},name:`AxiosError`});let n=e.getPluginOrThrow(`@hey-api/sdk`);e.forEach(`operation`,({operation:t})=>{let r=n.config.asClass?Ri({context:e.context,operation:t,plugin:n}):void 0,i=r?r.values().next().value:void 0,a;if(i){a=P(e.referenceSymbol({category:`utility`,resource:`class`,resourceId:i.path[0],tool:`sdk`})).$if(n.config.instance,e=>e.attr(La).attr(`get`).call());for(let e of i.path.slice(1)){let t=y({case:`camelCase`,value:e});a=a.attr(t)}a=a.attr(i.methodName)}else a=P(e.referenceSymbol({category:`sdk`,resource:`operation`,resourceId:t.id}));e.hooks.operation.isQuery(t)&&(e.config.queryOptions.enabled&&ts({operation:t,plugin:e,queryFn:a}),e.config.infiniteQueryOptions.enabled&&Qo({operation:t,plugin:e,queryFn:a}),`useQuery`in e.config&&e.config.useQuery.enabled&&rs({operation:t,plugin:e})),e.hooks.operation.isMutation(t)&&e.config.mutationOptions.enabled&&$o({operation:t,plugin:e,queryFn:a})},{order:`declarations`})},as=e=>is(e),os={config:{case:`camelCase`,comments:!0,exportFromIndex:!1},dependencies:[`@hey-api/sdk`,`@hey-api/typescript`],handler:as,name:`@tanstack/angular-query-experimental`,resolveConfig:(e,t)=>{e.config.infiniteQueryKeys=t.valueToObject({defaultValue:{case:e.config.case??`camelCase`,enabled:!0,name:`{{name}}InfiniteQueryKey`,tags:!1},mappers:{boolean:e=>({enabled:e}),function:e=>({name:e}),string:e=>({name:e})},value:e.config.infiniteQueryKeys}),e.config.infiniteQueryOptions=t.valueToObject({defaultValue:{case:e.config.case??`camelCase`,enabled:!0,name:`{{name}}InfiniteOptions`},mappers:{boolean:e=>({enabled:e}),function:e=>({name:e}),string:e=>({name:e})},value:e.config.infiniteQueryOptions}),e.config.mutationOptions=t.valueToObject({defaultValue:{case:e.config.case??`camelCase`,enabled:!0,name:`{{name}}Mutation`},mappers:{boolean:e=>({enabled:e}),function:e=>({name:e}),string:e=>({name:e})},value:e.config.mutationOptions}),e.config.queryKeys=t.valueToObject({defaultValue:{case:e.config.case??`camelCase`,enabled:!0,name:`{{name}}QueryKey`,tags:!1},mappers:{boolean:e=>({enabled:e}),function:e=>({name:e}),string:e=>({name:e})},value:e.config.queryKeys}),e.config.queryOptions=t.valueToObject({defaultValue:{case:e.config.case??`camelCase`,enabled:!0,exported:!0,name:`{{name}}Options`},mappers:{boolean:e=>({enabled:e}),function:e=>({name:e}),string:e=>({name:e})},value:e.config.queryOptions})}},ss={config:{case:`camelCase`,comments:!0,exportFromIndex:!1},dependencies:[`@hey-api/sdk`,`@hey-api/typescript`],handler:as,name:`@tanstack/react-query`,resolveConfig:(e,t)=>{e.config.infiniteQueryKeys=t.valueToObject({defaultValue:{case:e.config.case??`camelCase`,enabled:!0,name:`{{name}}InfiniteQueryKey`,tags:!1},mappers:{boolean:e=>({enabled:e}),function:e=>({name:e}),string:e=>({name:e})},value:e.config.infiniteQueryKeys}),e.config.infiniteQueryOptions=t.valueToObject({defaultValue:{case:e.config.case??`camelCase`,enabled:!0,name:`{{name}}InfiniteOptions`},mappers:{boolean:e=>({enabled:e}),function:e=>({name:e}),string:e=>({name:e})},value:e.config.infiniteQueryOptions}),e.config.mutationOptions=t.valueToObject({defaultValue:{case:e.config.case??`camelCase`,enabled:!0,name:`{{name}}Mutation`},mappers:{boolean:e=>({enabled:e}),function:e=>({name:e}),string:e=>({name:e})},value:e.config.mutationOptions}),e.config.queryKeys=t.valueToObject({defaultValue:{case:e.config.case??`camelCase`,enabled:!0,name:`{{name}}QueryKey`,tags:!1},mappers:{boolean:e=>({enabled:e}),function:e=>({name:e}),string:e=>({name:e})},value:e.config.queryKeys}),e.config.queryOptions=t.valueToObject({defaultValue:{case:e.config.case??`camelCase`,enabled:!0,exported:!0,name:`{{name}}Options`},mappers:{boolean:e=>({enabled:e}),function:e=>({name:e}),string:e=>({name:e})},value:e.config.queryOptions}),e.config.useQuery=t.valueToObject({defaultValue:{case:e.config.case??`camelCase`,enabled:!1,name:`use{{name}}Query`},mappers:{boolean:e=>({enabled:e}),function:e=>({enabled:!0,name:e}),object:e=>({enabled:!0,...e}),string:e=>({enabled:!0,name:e})},value:e.config.useQuery}),e.config.useQuery.enabled&&(e.config.queryOptions.enabled||(e.config.queryOptions.enabled=!0,e.config.queryOptions.exported=!1))}},cs={config:{case:`camelCase`,comments:!0,exportFromIndex:!1},dependencies:[`@hey-api/sdk`,`@hey-api/typescript`],handler:as,name:`@tanstack/solid-query`,resolveConfig:(e,t)=>{e.config.infiniteQueryKeys=t.valueToObject({defaultValue:{case:e.config.case??`camelCase`,enabled:!0,name:`{{name}}InfiniteQueryKey`,tags:!1},mappers:{boolean:e=>({enabled:e}),function:e=>({name:e}),string:e=>({name:e})},value:e.config.infiniteQueryKeys}),e.config.infiniteQueryOptions=t.valueToObject({defaultValue:{case:e.config.case??`camelCase`,enabled:!0,name:`{{name}}InfiniteOptions`},mappers:{boolean:e=>({enabled:e}),function:e=>({name:e}),string:e=>({name:e})},value:e.config.infiniteQueryOptions}),e.config.mutationOptions=t.valueToObject({defaultValue:{case:e.config.case??`camelCase`,enabled:!0,name:`{{name}}Mutation`},mappers:{boolean:e=>({enabled:e}),function:e=>({name:e}),string:e=>({name:e})},value:e.config.mutationOptions}),e.config.queryKeys=t.valueToObject({defaultValue:{case:e.config.case??`camelCase`,enabled:!0,name:`{{name}}QueryKey`,tags:!1},mappers:{boolean:e=>({enabled:e}),function:e=>({name:e}),string:e=>({name:e})},value:e.config.queryKeys}),e.config.queryOptions=t.valueToObject({defaultValue:{case:e.config.case??`camelCase`,enabled:!0,exported:!0,name:`{{name}}Options`},mappers:{boolean:e=>({enabled:e}),function:e=>({name:e}),string:e=>({name:e})},value:e.config.queryOptions})}},ls={config:{case:`camelCase`,comments:!0,exportFromIndex:!1},dependencies:[`@hey-api/sdk`,`@hey-api/typescript`],handler:as,name:`@tanstack/svelte-query`,resolveConfig:(e,t)=>{e.config.infiniteQueryKeys=t.valueToObject({defaultValue:{case:e.config.case??`camelCase`,enabled:!0,name:`{{name}}InfiniteQueryKey`,tags:!1},mappers:{boolean:e=>({enabled:e}),function:e=>({name:e}),string:e=>({name:e})},value:e.config.infiniteQueryKeys}),e.config.infiniteQueryOptions=t.valueToObject({defaultValue:{case:e.config.case??`camelCase`,enabled:!0,name:`{{name}}InfiniteOptions`},mappers:{boolean:e=>({enabled:e}),function:e=>({name:e}),string:e=>({name:e})},value:e.config.infiniteQueryOptions}),e.config.mutationOptions=t.valueToObject({defaultValue:{case:e.config.case??`camelCase`,enabled:!0,name:`{{name}}Mutation`},mappers:{boolean:e=>({enabled:e}),function:e=>({name:e}),string:e=>({name:e})},value:e.config.mutationOptions}),e.config.queryKeys=t.valueToObject({defaultValue:{case:e.config.case??`camelCase`,enabled:!0,name:`{{name}}QueryKey`,tags:!1},mappers:{boolean:e=>({enabled:e}),function:e=>({name:e}),string:e=>({name:e})},value:e.config.queryKeys}),e.config.queryOptions=t.valueToObject({defaultValue:{case:e.config.case??`camelCase`,enabled:!0,exported:!0,name:`{{name}}Options`},mappers:{boolean:e=>({enabled:e}),function:e=>({name:e}),string:e=>({name:e})},value:e.config.queryOptions})}},us={config:{case:`camelCase`,comments:!0,exportFromIndex:!1},dependencies:[`@hey-api/sdk`,`@hey-api/typescript`],handler:as,name:`@tanstack/vue-query`,resolveConfig:(e,t)=>{e.config.infiniteQueryKeys=t.valueToObject({defaultValue:{case:e.config.case??`camelCase`,enabled:!0,name:`{{name}}InfiniteQueryKey`,tags:!1},mappers:{boolean:e=>({enabled:e}),function:e=>({name:e}),string:e=>({name:e})},value:e.config.infiniteQueryKeys}),e.config.infiniteQueryOptions=t.valueToObject({defaultValue:{case:e.config.case??`camelCase`,enabled:!0,name:`{{name}}InfiniteOptions`},mappers:{boolean:e=>({enabled:e}),function:e=>({name:e}),string:e=>({name:e})},value:e.config.infiniteQueryOptions}),e.config.mutationOptions=t.valueToObject({defaultValue:{case:e.config.case??`camelCase`,enabled:!0,name:`{{name}}Mutation`},mappers:{boolean:e=>({enabled:e}),function:e=>({name:e}),string:e=>({name:e})},value:e.config.mutationOptions}),e.config.queryKeys=t.valueToObject({defaultValue:{case:e.config.case??`camelCase`,enabled:!0,name:`{{name}}QueryKey`,tags:!1},mappers:{boolean:e=>({enabled:e}),function:e=>({name:e}),string:e=>({name:e})},value:e.config.queryKeys}),e.config.queryOptions=t.valueToObject({defaultValue:{case:e.config.case??`camelCase`,enabled:!0,exported:!0,name:`{{name}}Options`},mappers:{boolean:e=>({enabled:e}),function:e=>({name:e}),string:e=>({name:e})},value:e.config.queryOptions})}},ds=({operation:e,plugin:t})=>{let n=t.getSymbol({category:`schema`,resource:`operation`,resourceId:e.id,role:`data`,tool:`arktype`});if(!n)return;let r=`data`;return P.func().async().param(r).do(P(n).attr(`parseAsync`).call(r).await().return())},fs=({operation:e,plugin:t})=>{let n=t.getSymbol({category:`schema`,resource:`operation`,resourceId:e.id,role:`responses`,tool:`arktype`});if(!n)return;let r=`data`;return P.func().async().param(r).do(P(n).attr(`parseAsync`).call(r).await().return())};var ps=class{createRequestValidator(e){return ds(e)}createResponseValidator(e){return fs(e)}};const B={keywords:{false:`false`,true:`true`},number:{Infinity:`Infinity`,NaN:`NaN`,NegativeInfinity:`NegativeInfinity`,epoch:`epoch`,integer:`integer`,safe:`safe`},primitives:{bigint:`bigint`,boolean:`boolean`,keywords:`keywords`,null:`null`,number:`number`,string:`string`,symbol:`symbol`,undefined:`undefined`,unit:`unit`},string:{NFC:`NFC`,NFD:`NFD`,NFKC:`NFKC`,NFKD:`NFKD`,alpha:`alpha`,alphanumeric:`alphanumeric`,base64:`base64`,capitalize:`capitalize`,creditCard:`creditCard`,date:`date`,digits:`digits`,email:`email`,epoch:`epoch`,hex:`hex`,integer:`integer`,ip:`ip`,iso:`iso`,json:`json`,lower:`lower`,normalize:`normalize`,numeric:`numeric`,parse:`parse`,preformatted:`preformatted`,regex:`regex`,semver:`semver`,trim:`trim`,upper:`upper`,url:`url`,uuid:`uuid`,v1:`v1`,v2:`v2`,v3:`v3`,v4:`v4`,v5:`v5`,v6:`v6`,v7:`v7`,v8:`v8`},type:{$:`$`,allows:`allows`,and:`and`,array:`array`,as:`as`,assert:`assert`,brand:`brand`,configure:`configure`,default:`default`,describe:`describe`,description:`description`,equals:`equals`,exclude:`exclude`,expression:`expression`,extends:`extends`,extract:`extract`,filter:`filter`,from:`from`,ifEquals:`ifEquals`,ifExtends:`ifExtends`,infer:`infer`,inferIn:`inferIn`,intersect:`intersect`,json:`json`,meta:`meta`,narrow:`narrow`,onDeepUndeclaredKey:`onDeepUndeclaredKey`,onUndeclaredKey:`onUndeclaredKey`,optional:`optional`,or:`or`,overlaps:`overlaps`,pipe:`pipe`,select:`select`,to:`to`,toJsonSchema:`toJsonSchema`}},ms=({ast:e,plugin:t,schema:n,symbol:r,typeInferSymbol:i})=>{let a=t.referenceSymbol({category:`external`,resource:`arktype.type`}),o=P.const(r).export().$if(t.config.comments&&R(n),(e,t)=>e.doc(t)).assign(P(a).call(e.def?P.literal(e.def):e.expression));if(t.addNode(o),i){let e=P.type.alias(i).export().type(P.type(r).attr(B.type.infer).typeofType());t.addNode(e)}},hs=e=>{let t={};return t.def=B.primitives.null,t},gs=({plugin:e,schema:t,state:r})=>{let i={},a=P.object().pretty(),o=t.required??[];for(let s in t.properties){let l=t.properties[s],u=o.includes(s),d=ys({optional:!u,plugin:e,schema:l,state:{...r,path:c([...n(r.path),`properties`,s])}});d.hasLazyExpression&&(i.hasLazyExpression=!0),a.prop(u?s:`${s}?`,d.expression)}if(t.additionalProperties&&(!t.properties||!Object.keys(t.properties).length)){let a=ys({plugin:e,schema:t.additionalProperties,state:{...r,path:c([...n(r.path),`additionalProperties`])}});return i.expression=P(`TODO`).attr(`record`).call(P(`TODO`).attr(`string`).call(),a.expression),a.hasLazyExpression&&(i.hasLazyExpression=!0),i.hasLazyExpression?{...i,typeName:`TODO`}:i}return i.expression=a,i.hasLazyExpression?{...i,typeName:`TODO`}:i},_s=({schema:e})=>{let t={};if(typeof e.const==`string`)return t.def=e.const,t;let n=B.primitives.string;if(e.format)switch(e.format){case`date`:case`date-time`:case`time`:n=`${n}.${B.string.date}.${B.string.iso}`;break;case`email`:n=`${n}.${B.string.email}`;break;case`ipv4`:n=`${n}.${B.string.ip}.${B.string.v4}`;break;case`ipv6`:n=`${n}.${B.string.ip}.${B.string.v6}`;break;case`uri`:n=`${n}.${B.string.url}`;break;case`uuid`:n=`${n}.${B.string.uuid}`;break}return e.minLength===e.maxLength&&e.minLength!==void 0?n=`${e.minLength} <= ${n} <= ${e.maxLength}`:e.maxLength===void 0?e.minLength!==void 0&&(n=`${n} >= ${e.minLength}`):(n=`${n} <= ${e.maxLength}`,e.minLength!==void 0&&(n=`${e.minLength} <= ${n}`)),e.pattern&&(n=`/${e.pattern}/`),t.def=n,t},vs=({schema:e,...t})=>{switch(e.type){case`null`:return hs({...t,schema:e});case`object`:return gs({...t,schema:e});case`string`:return _s({...t,schema:e})}return{def:``,expression:P(t.plugin.referenceSymbol({category:`external`,resource:`arktype.type`})).call(P.object().prop(`name`,P.literal(`string`)).prop(`platform`,P.literal(`'android' | 'ios'`)).prop(`versions?`,P.literal(`(number | string)[]`))),hasLazyExpression:!1}},ys=({plugin:e,schema:t,state:n})=>{let r={};if(t.$ref){let i={category:`schema`,resource:`definition`,resourceId:t.$ref,tool:`arktype`},a=e.referenceSymbol(i);e.isSymbolRegistered(i)?r.expression=P(a):(r.expression=P(`TODO`).attr(`TODO`).call(P.func().returns(`any`).do(P.return(a))),r.hasLazyExpression=!0,n.hasLazyExpression[`~ref`]=!0)}else if(t.type){let i=vs({plugin:e,schema:t,state:n});r.def=i.def,r.expression=i.expression,r.hasLazyExpression=i.hasLazyExpression,e.config.metadata&&t.description}else if(t.items)t=x({schema:t}),t.items||(r=ys({plugin:e,schema:t,state:n}));else{let t=vs({plugin:e,schema:{type:`unknown`},state:n});r.def=t.def,r.expression=t.expression}return r.expression||=vs({plugin:e,schema:{type:`unknown`},state:n}).expression,r},bs=({plugin:e,schema:t,state:r})=>{let i=ji(n(r.path)),a=ys({plugin:e,schema:t,state:r}),o=F(i);ms({ast:a,plugin:e,schema:t,symbol:e.registerSymbol({meta:{category:`schema`,path:n(r.path),resource:`definition`,resourceId:i,tags:n(r.tags),tool:`arktype`},name:b({config:e.config.definitions,name:o})}),typeInferSymbol:e.config.definitions.types.infer.enabled?e.registerSymbol({meta:{category:`type`,path:n(r.path),resource:`definition`,resourceId:i,tool:`arktype`,variant:`infer`},name:b({config:e.config.definitions.types.infer,name:o})}):void 0})},xs=({plugin:e})=>{e.registerSymbol({external:`arktype`,meta:{category:`external`,resource:`arktype.type`},name:`type`}),e.forEach(`operation`,`parameter`,`requestBody`,`schema`,`webhook`,t=>{let n=l({hasLazyExpression:!1,path:t._path,tags:t.tags});switch(t.type){case`parameter`:bs({plugin:e,schema:t.parameter.schema,state:n});break;case`requestBody`:bs({plugin:e,schema:t.requestBody.schema,state:n});break;case`schema`:bs({plugin:e,schema:t.schema,state:n});break}})},Ss={api:new ps,config:{case:`PascalCase`,comments:!0,exportFromIndex:!1,metadata:!1},handler:e=>xs(e),name:`arktype`,resolveConfig:(e,t)=>{e.config.types=t.valueToObject({defaultValue:{infer:{case:`PascalCase`,enabled:!1}},mappers:{object:(e,n)=>({...e,infer:t.valueToObject({defaultValue:{...n.infer,enabled:e.infer===void 0?n.infer.enabled:!!e.infer},mappers:v,value:e.infer})})},value:e.config.types}),e.config.definitions=t.valueToObject({defaultValue:{case:e.config.case??`PascalCase`,enabled:!0,name:`{{name}}`,types:{...e.config.types,infer:{...e.config.types.infer,name:`{{name}}`}}},mappers:{...v,object:(e,n)=>({...e,types:t.valueToObject({defaultValue:n.types,mappers:{object:(e,n)=>({...e,infer:t.valueToObject({defaultValue:{...n.infer,enabled:e.infer===void 0?n.infer.enabled:!!e.infer},mappers:v,value:e.infer})})},value:e.types})})},value:e.config.definitions}),e.config.requests=t.valueToObject({defaultValue:{case:e.config.case??`PascalCase`,enabled:!0,name:`{{name}}Data`,types:{...e.config.types,infer:{...e.config.types.infer,name:`{{name}}Data`}}},mappers:{...v,object:(e,n)=>({...e,types:t.valueToObject({defaultValue:n.types,mappers:{object:(e,n)=>({...e,infer:t.valueToObject({defaultValue:{...n.infer,enabled:e.infer===void 0?n.infer.enabled:!!e.infer},mappers:v,value:e.infer})})},value:e.types})})},value:e.config.requests}),e.config.responses=t.valueToObject({defaultValue:{case:e.config.case??`PascalCase`,enabled:!0,name:`{{name}}Response`,types:{...e.config.types,infer:{...e.config.types.infer,name:`{{name}}Response`}}},mappers:{...v,object:(e,n)=>({...e,types:t.valueToObject({defaultValue:n.types,mappers:{object:(e,n)=>({...e,infer:t.valueToObject({defaultValue:{...n.infer,enabled:e.infer===void 0?n.infer.enabled:!!e.infer},mappers:v,value:e.infer})})},value:e.types})})},value:e.config.responses}),e.config.webhooks=t.valueToObject({defaultValue:{case:e.config.case??`PascalCase`,enabled:!0,name:`{{name}}WebhookRequest`,types:{...e.config.types,infer:{...e.config.types.infer,name:`{{name}}WebhookRequest`}}},mappers:{...v,object:(e,n)=>({...e,types:t.valueToObject({defaultValue:n.types,mappers:{object:(e,n)=>({...e,infer:t.valueToObject({defaultValue:{...n.infer,enabled:e.infer===void 0?n.infer.enabled:!!e.infer},mappers:v,value:e.infer})})},value:e.types})})},value:e.config.webhooks})},tags:[`validator`]},Cs=({operation:e,plugin:t})=>{let n=P.type.object(),r=t.querySymbol({category:`type`,resource:`operation`,resourceId:e.id,role:`data`,tool:`typescript`});r&&(e.body&&n.prop(`Body`,t=>t.required(e.body.required).type(P.type(r).idx(P.type.literal(`body`)))),e.parameters&&(e.parameters.header&&n.prop(`Headers`,t=>t.required(rt(e.parameters.header)).type(P.type(r).idx(P.type.literal(`headers`)))),e.parameters.path&&n.prop(`Params`,t=>t.required(rt(e.parameters.path)).type(P.type(r).idx(P.type.literal(`path`)))),e.parameters.query&&n.prop(`Querystring`,t=>t.required(rt(e.parameters.query)).type(P.type(r).idx(P.type.literal(`query`))))));let{errors:i,responses:a}=lt(e),o,s=t.querySymbol({category:`type`,resource:`operation`,resourceId:e.id,role:`errors`});if(s&&i&&i.properties){let e=Object.keys(i.properties);e.length&&(e.includes(`default`)?e.length>1&&(o=P.type(`Omit`,e=>e.generics(P.type(s),P.type.literal(`default`)))):o=P.type(s))}let c,l=t.querySymbol({category:`type`,resource:`operation`,resourceId:e.id,role:`responses`});if(l&&a&&a.properties){let e=Object.keys(a.properties);e.length&&(e.includes(`default`)?e.length>1&&(c=P.type(`Omit`,e=>e.generics(P.type(l),P.type.literal(`default`)))):c=P.type(l))}let u=[o,c].filter(e=>e!==void 0);if(u.length&&n.prop(`Reply`,e=>e.type(P.type.and(...u))),n.isEmpty)return;let d=t.referenceSymbol({category:`type`,resource:`route-handler`,tool:`fastify`});return{name:e.id,type:P.type(d,e=>e.generic(n))}},ws={config:{exportFromIndex:!1},dependencies:[`@hey-api/typescript`],handler:({plugin:e})=>{e.registerSymbol({external:`fastify`,kind:`type`,meta:{category:`type`,resource:`route-handler`,tool:`fastify`},name:`RouteHandler`});let t=e.registerSymbol({name:`RouteHandlers`}),n=P.type.object();e.forEach(`operation`,({operation:t})=>{let r=Cs({operation:t,plugin:e});r&&n.prop(r.name,e=>e.type(r.type))},{order:`declarations`});let r=P.type.alias(t).export().type(n);e.addNode(r)},name:`fastify`},Ts=({operation:e,plugin:t,queryFn:n})=>{if(Wi({operation:e}))return;let r=t.referenceSymbol({category:`external`,resource:`swr`}),i=t.registerSymbol({name:b({config:t.config.useSwr,name:e.id})}),a=P(n).call(P.object().prop(`throwOnError`,P.literal(!0))).await(),o=[];t.getPluginOrThrow(`@hey-api/sdk`).config.responseStyle===`data`?o.push(P.return(a)):o.push(P.const().object(`data`).assign(a),P.return(`data`));let s=P.const(i).export().$if(t.config.comments&&I(e),(e,t)=>e.doc(t)).assign(P.func().do(P(r).call(P.literal(e.path),P.func().async().do(...o)).return()));t.addNode(s)},Es=({plugin:e})=>{e.registerSymbol({external:`swr`,importKind:`default`,kind:`function`,meta:{category:`external`,resource:`swr`},name:`useSWR`});let t=e.getPluginOrThrow(`@hey-api/sdk`);e.forEach(`operation`,({operation:n})=>{let r=t.config.asClass?Ri({context:e.context,operation:n,plugin:t}):void 0,i=r?r.values().next().value:void 0,a;if(i){a=P(e.referenceSymbol({category:`utility`,resource:`class`,resourceId:i.path[0],tool:`sdk`})).$if(t.config.instance,e=>e.attr(La).attr(`get`).call());for(let e of i.path.slice(1)){let t=y({case:`camelCase`,value:e});a=a.attr(t)}a=a.attr(i.methodName)}else a=P(e.referenceSymbol({category:`sdk`,resource:`operation`,resourceId:n.id}));e.hooks.operation.isQuery(n)&&e.config.useSwr.enabled&&Ts({operation:n,plugin:e,queryFn:a})},{order:`declarations`})},Ds={config:{case:`camelCase`,comments:!0,exportFromIndex:!1},dependencies:[`@hey-api/sdk`,`@hey-api/typescript`],handler:e=>Es(e),name:`swr`,resolveConfig:(e,t)=>{e.config.infiniteQueryKeys=t.valueToObject({defaultValue:{case:e.config.case??`camelCase`,enabled:!0,name:`{{name}}InfiniteQueryKey`,tags:!1},mappers:{boolean:e=>({enabled:e}),function:e=>({name:e}),string:e=>({name:e})},value:e.config.infiniteQueryKeys}),e.config.infiniteQueryOptions=t.valueToObject({defaultValue:{case:e.config.case??`camelCase`,enabled:!0,name:`{{name}}InfiniteOptions`},mappers:{boolean:e=>({enabled:e}),function:e=>({name:e}),string:e=>({name:e})},value:e.config.infiniteQueryOptions}),e.config.mutationOptions=t.valueToObject({defaultValue:{case:e.config.case??`camelCase`,enabled:!0,name:`{{name}}Mutation`},mappers:{boolean:e=>({enabled:e}),function:e=>({name:e}),string:e=>({name:e})},value:e.config.mutationOptions}),e.config.queryKeys=t.valueToObject({defaultValue:{case:e.config.case??`camelCase`,enabled:!0,name:`{{name}}QueryKey`,tags:!1},mappers:{boolean:e=>({enabled:e}),function:e=>({name:e}),string:e=>({name:e})},value:e.config.queryKeys}),e.config.queryOptions=t.valueToObject({defaultValue:{case:e.config.case??`camelCase`,enabled:!0,exported:!0,name:`{{name}}Options`},mappers:{boolean:e=>({enabled:e}),function:e=>({name:e}),string:e=>({name:e})},value:e.config.queryOptions}),e.config.useSwr=t.valueToObject({defaultValue:{case:e.config.case??`camelCase`,enabled:!0,name:`use{{name}}`},mappers:{boolean:e=>({enabled:e}),function:e=>({enabled:!0,name:e}),object:e=>({enabled:!0,...e}),string:e=>({enabled:!0,name:e})},value:e.config.useSwr}),e.config.useSwr.enabled&&(e.config.queryOptions.enabled||(e.config.queryOptions.enabled=!0,e.config.queryOptions.exported=!1))}},V={actions:{args:`args`,base64:`base64`,bic:`bic`,brand:`brand`,bytes:`bytes`,check:`check`,checkItems:`checkItems`,creditCard:`creditCard`,cuid2:`cuid2`,decimal:`decimal`,description:`description`,digits:`digits`,email:`email`,emoji:`emoji`,empty:`empty`,endsWith:`endsWith`,entries:`entries`,everyItem:`everyItem`,excludes:`excludes`,filterItems:`filterItems`,findItem:`findItem`,finite:`finite`,flavor:`flavor`,graphemes:`graphemes`,gtValue:`gtValue`,hash:`hash`,hexColor:`hexColor`,hexadecimal:`hexadecimal`,imei:`imei`,includes:`includes`,integer:`integer`,ip:`ip`,ipv4:`ipv4`,ipv6:`ipv6`,isoDate:`isoDate`,isoDateTime:`isoDateTime`,isoTime:`isoTime`,isoTimeSecond:`isoTimeSecond`,isoTimestamp:`isoTimestamp`,isoWeek:`isoWeek`,length:`length`,ltValue:`ltValue`,mac:`mac`,mac48:`mac48`,mac64:`mac64`,mapItems:`mapItems`,maxBytes:`maxBytes`,maxEntries:`maxEntries`,maxGraphemes:`maxGraphemes`,maxLength:`maxLength`,maxSize:`maxSize`,maxValue:`maxValue`,maxWords:`maxWords`,metadata:`metadata`,mimeType:`mimeType`,minBytes:`minBytes`,minEntries:`minEntries`,minGraphemes:`minGraphemes`,minLength:`minLength`,minSize:`minSize`,minValue:`minValue`,minWords:`minWords`,multipleOf:`multipleOf`,nanoid:`nanoid`,nonEmpty:`nonEmpty`,normalize:`normalize`,notBytes:`notBytes`,notEntries:`notEntries`,notGraphemes:`notGraphemes`,notLength:`notLength`,notSize:`notSize`,notValue:`notValue`,notValues:`notValues`,notWords:`notWords`,octal:`octal`,parseJson:`parseJson`,partialCheck:`partialCheck`,rawCheck:`rawCheck`,rawTransform:`rawTransform`,readonly:`readonly`,reduceItems:`reduceItems`,regex:`regex`,returns:`returns`,rfcEmail:`rfcEmail`,safeInteger:`safeInteger`,size:`size`,slug:`slug`,someItem:`someItem`,sortItems:`sortItems`,startsWith:`startsWith`,stringifyJson:`stringifyJson`,title:`title`,toLowerCase:`toLowerCase`,toMaxValue:`toMaxValue`,toMinValue:`toMinValue`,toUpperCase:`toUpperCase`,transform:`transform`,trim:`trim`,trimEnd:`trimEnd`,trimStart:`trimStart`,ulid:`ulid`,url:`url`,uuid:`uuid`,value:`value`,values:`values`,words:`words`},async:{argsAsync:`argsAsync`,arrayAsync:`arrayAsync`,awaitAsync:`awaitAsync`,checkAsync:`checkAsync`,checkItemsAsync:`checkItemsAsync`,customAsync:`customAsync`,exactOptionalAsync:`exactOptionalAsync`,fallbackAsync:`fallbackAsync`,forwardAsync:`forwardAsync`,getDefaultsAsync:`getDefaultsAsync`,getFallbacksAsync:`getFallbacksAsync`,intersectAsync:`intersectAsync`,lazyAsync:`lazyAsync`,looseObjectAsync:`looseObjectAsync`,looseTupleAsync:`looseTupleAsync`,mapAsync:`mapAsync`,nonNullableAsync:`nonNullableAsync`,nonNullishAsync:`nonNullishAsync`,nonOptionalAsync:`nonOptionalAsync`,nullableAsync:`nullableAsync`,nullishAsync:`nullishAsync`,objectAsync:`objectAsync`,objectWithRestAsync:`objectWithRestAsync`,optionalAsync:`optionalAsync`,parseAsync:`parseAsync`,parserAsync:`parserAsync`,partialAsync:`partialAsync`,partialCheckAsync:`partialCheckAsync`,pipeAsync:`pipeAsync`,rawCheckAsync:`rawCheckAsync`,rawTransformAsync:`rawTransformAsync`,recordAsync:`recordAsync`,requiredAsync:`requiredAsync`,returnsAsync:`returnsAsync`,safeParseAsync:`safeParseAsync`,safeParserAsync:`safeParserAsync`,setAsync:`setAsync`,strictObjectAsync:`strictObjectAsync`,strictTupleAsync:`strictTupleAsync`,transformAsync:`transformAsync`,tupleAsync:`tupleAsync`,tupleWithRestAsync:`tupleWithRestAsync`,undefinedableAsync:`undefinedableAsync`,unionAsync:`unionAsync`,variantAsync:`variantAsync`},methods:{assert:`assert`,config:`config`,fallback:`fallback`,flatten:`flatten`,forward:`forward`,getDefault:`getDefault`,getDefaults:`getDefaults`,getDescription:`getDescription`,getFallback:`getFallback`,getFallbacks:`getFallbacks`,getMetadata:`getMetadata`,getTitle:`getTitle`,is:`is`,keyof:`keyof`,message:`message`,omit:`omit`,parse:`parse`,parser:`parser`,partial:`partial`,pick:`pick`,pipe:`pipe`,required:`required`,safeParse:`safeParse`,safeParser:`safeParser`,summarize:`summarize`,unwrap:`unwrap`},schemas:{any:`any`,array:`array`,bigInt:`bigint`,blob:`blob`,boolean:`boolean`,custom:`custom`,date:`date`,enum:`enum`,exactOptional:`exactOptional`,file:`file`,function:`function`,instance:`instance`,intersect:`intersect`,lazy:`lazy`,literal:`literal`,looseObject:`looseObject`,looseTuple:`looseTuple`,map:`map`,nan:`nan`,never:`never`,nonNullable:`nonNullable`,nonNullish:`nonNullish`,nonOptional:`nonOptional`,null:`null`,nullable:`nullable`,nullish:`nullish`,number:`number`,object:`object`,objectWithRest:`objectWithRest`,optional:`optional`,picklist:`picklist`,promise:`promise`,record:`record`,set:`set`,strictObject:`strictObject`,strictTuple:`strictTuple`,string:`string`,symbol:`symbol`,tuple:`tuple`,tupleWithRest:`tupleWithRest`,undefined:`undefined`,undefinedable:`undefinedable`,union:`union`,unknown:`unknown`,variant:`variant`,void:`void`},storages:{},types:{GenericSchema:`GenericSchema`},utils:{}},Os=({schema:e,v:t})=>P(t).attr(V.async.parseAsync).call(e,`data`).await().return(),ks=({operation:e,plugin:t})=>{let n=t.getSymbol({category:`schema`,resource:`operation`,resourceId:e.id,role:`data`,tool:`valibot`});if(!n)return;let r={$:P,operation:e,pipes:[],plugin:t,schema:n,v:t.referenceSymbol({category:`external`,resource:`valibot.v`})},i=t.config[`~resolvers`]?.validator,a=[typeof i==`function`?i:i?.request,Os];for(let e of a){let t=e?.(r);if(t===null)return;if(t!==void 0)return P.func().async().param(`data`).do(...t instanceof Array?t:[t])}},As=({operation:e,plugin:t})=>{let n=t.getSymbol({category:`schema`,resource:`operation`,resourceId:e.id,role:`responses`,tool:`valibot`});if(!n)return;let r={$:P,operation:e,pipes:[],plugin:t,schema:n,v:t.referenceSymbol({category:`external`,resource:`valibot.v`})},i=t.config[`~resolvers`]?.validator,a=[typeof i==`function`?i:i?.response,Os];for(let e of a){let t=e?.(r);if(t===null)return;if(t!==void 0)return P.func().async().param(`data`).do(...t instanceof Array?t:[t])}};var js=class{createRequestValidator(e){return ks(e)}createResponseValidator(e){return As(e)}};const H=({pipes:e,plugin:t})=>e.length===1?e[0]:P(t.referenceSymbol({category:`external`,resource:`valibot.v`})).attr(V.methods.pipe).call(...e),Ms=({ast:e,plugin:t,schema:n,state:r,symbol:i})=>{let a=t.referenceSymbol({category:`external`,resource:`valibot.v`}),o=P.const(i).export().$if(t.config.comments&&R(n),(e,t)=>e.doc(t)).$if(r.hasLazyExpression[`~ref`],t=>t.type(P.type(a).attr(e.typeName||V.types.GenericSchema))).assign(H({pipes:e.pipes,plugin:t}));t.addNode(o)},Ns={int16:{max:32767,maxError:`Invalid value: Expected int16 to be <= 2^15-1`,min:-32768,minError:`Invalid value: Expected int16 to be >= -2^15`,needsBigInt:!1},int32:{max:2147483647,maxError:`Invalid value: Expected int32 to be <= 2^31-1`,min:-2147483648,minError:`Invalid value: Expected int32 to be >= -2^31`,needsBigInt:!1},int64:{max:`9223372036854775807`,maxError:`Invalid value: Expected int64 to be <= 2^63-1`,min:`-9223372036854775808`,minError:`Invalid value: Expected int64 to be >= -2^63`,needsBigInt:!0},int8:{max:127,maxError:`Invalid value: Expected int8 to be <= 2^7-1`,min:-128,minError:`Invalid value: Expected int8 to be >= -2^7`,needsBigInt:!1},uint16:{max:65535,maxError:`Invalid value: Expected uint16 to be <= 2^16-1`,min:0,minError:`Invalid value: Expected uint16 to be >= 0`,needsBigInt:!1},uint32:{max:4294967295,maxError:`Invalid value: Expected uint32 to be <= 2^32-1`,min:0,minError:`Invalid value: Expected uint32 to be >= 0`,needsBigInt:!1},uint64:{max:`18446744073709551615`,maxError:`Invalid value: Expected uint64 to be <= 2^64-1`,min:`0`,minError:`Invalid value: Expected uint64 to be >= 0`,needsBigInt:!0},uint8:{max:255,maxError:`Invalid value: Expected uint8 to be <= 2^8-1`,min:0,minError:`Invalid value: Expected uint8 to be >= 0`,needsBigInt:!1}},Ps=e=>e!==void 0&&e in Ns,Fs=e=>Ps(e)&&Ns[e].needsBigInt,Is=({isBigInt:e,value:t})=>{let n=P.fromValue(t);return e&&(typeof t==`bigint`||typeof t==`number`||typeof t==`string`||typeof t==`boolean`)?P(`BigInt`).call(n):n},Ls=({getAst:e,operation:t,plugin:r,state:i})=>{if(r.config.requests.enabled){let a=new Set,o={properties:{body:{type:`never`},path:{type:`never`},query:{type:`never`}},type:`object`};if(t.parameters){if(t.parameters.header){let e={},n=[];for(let r in t.parameters.header){let i=t.parameters.header[r];e[i.name]=i.schema,i.required&&(n.push(i.name),a.add(`headers`))}Object.keys(e).length&&(o.properties.headers={properties:e,required:n,type:`object`})}if(t.parameters.path){let e={},n=[];for(let r in t.parameters.path){let i=t.parameters.path[r];e[i.name]=i.schema,i.required&&(n.push(i.name),a.add(`path`))}Object.keys(e).length&&(o.properties.path={properties:e,required:n,type:`object`})}if(t.parameters.query){let e={},n=[];for(let r in t.parameters.query){let i=t.parameters.query[r];e[i.name]=i.schema,i.required&&(n.push(i.name),a.add(`query`))}Object.keys(e).length&&(o.properties.query={properties:e,required:n,type:`object`})}}t.body&&(o.properties.body=t.body.schema,t.body.required&&a.add(`body`)),o.required=[...a],Ms({ast:e(o,n(i.path)),plugin:r,schema:o,state:i,symbol:r.registerSymbol({meta:{category:`schema`,path:n(i.path),resource:`operation`,resourceId:t.id,role:`data`,tags:n(i.tags),tool:`valibot`},name:b({config:r.config.requests,name:t.id})})})}if(r.config.responses.enabled&&t.responses){let{response:a}=lt(t);if(a){let o=[...n(i.path),`responses`];Ms({ast:e(a,o),plugin:r,schema:a,state:i,symbol:r.registerSymbol({meta:{category:`schema`,path:o,resource:`operation`,resourceId:t.id,role:`responses`,tags:n(i.tags),tool:`valibot`},name:b({config:r.config.responses,name:t.id})})})}}},Rs=({getAst:e,operation:t,plugin:r,state:i})=>{if(r.config.webhooks.enabled){let a=new Set,o={properties:{body:{type:`never`},path:{type:`never`},query:{type:`never`}},type:`object`};if(t.parameters){if(t.parameters.header){let e={},n=[];for(let r in t.parameters.header){let i=t.parameters.header[r];e[i.name]=i.schema,i.required&&(n.push(i.name),a.add(`headers`))}Object.keys(e).length&&(o.properties.headers={properties:e,required:n,type:`object`})}if(t.parameters.path){let e={},n=[];for(let r in t.parameters.path){let i=t.parameters.path[r];e[i.name]=i.schema,i.required&&(n.push(i.name),a.add(`path`))}Object.keys(e).length&&(o.properties.path={properties:e,required:n,type:`object`})}if(t.parameters.query){let e={},n=[];for(let r in t.parameters.query){let i=t.parameters.query[r];e[i.name]=i.schema,i.required&&(n.push(i.name),a.add(`query`))}Object.keys(e).length&&(o.properties.query={properties:e,required:n,type:`object`})}}t.body&&(o.properties.body=t.body.schema,t.body.required&&a.add(`body`)),o.required=[...a],Ms({ast:e(o,n(i.path)),plugin:r,schema:o,state:i,symbol:r.registerSymbol({meta:{category:`schema`,path:n(i.path),resource:`webhook`,resourceId:t.id,role:`data`,tags:n(i.tags),tool:`valibot`},name:b({config:r.config.webhooks,name:t.id})})})}},zs=({plugin:e})=>P(e.referenceSymbol({category:`external`,resource:`valibot.v`})).attr(V.schemas.unknown).call(),Bs=({plugin:e,schema:t,state:r})=>{let i={pipes:[]},a=e.referenceSymbol({category:`external`,resource:`valibot.v`}),o=P(a).attr(V.schemas.array);if(t.items){t=x({schema:t});let a=t.items.map((t,a)=>{let o=ec({plugin:e,schema:t,state:{...r,path:c([...n(r.path),`items`,a])}});return o.hasLazyExpression&&(i.hasLazyExpression=!0),H({pipes:o.pipes,plugin:e})});if(a.length===1){let e=o.call(...a);i.pipes.push(e)}else{t.logicalOperator;let n=o.call(zs({plugin:e,schema:{type:`unknown`},state:r}));i.pipes.push(n)}}else{let t=o.call(zs({plugin:e,schema:{type:`unknown`},state:r}));i.pipes.push(t)}if(t.minItems===t.maxItems&&t.minItems!==void 0){let e=P(a).attr(V.actions.length).call(P.fromValue(t.minItems));i.pipes.push(e)}else{if(t.minItems!==void 0){let e=P(a).attr(V.actions.minLength).call(P.fromValue(t.minItems));i.pipes.push(e)}if(t.maxItems!==void 0){let e=P(a).attr(V.actions.maxLength).call(P.fromValue(t.maxItems));i.pipes.push(e)}}return i},Vs=({plugin:e,schema:t})=>{let n=[],r=e.referenceSymbol({category:`external`,resource:`valibot.v`});return typeof t.const==`boolean`?(n.push(P(r).attr(V.schemas.literal).call(P.literal(t.const))),H({pipes:n,plugin:e})):(n.push(P(r).attr(V.schemas.boolean).call()),H({pipes:n,plugin:e}))},Hs=({plugin:e,schema:t,state:n})=>{let r=[],i=!1;for(let e of t.items??[])e.type===`string`&&typeof e.const==`string`?r.push(P.literal(e.const)):(e.type===`null`||e.const===null)&&(i=!0);if(!r.length)return zs({plugin:e,schema:{type:`unknown`},state:n});let a=e.referenceSymbol({category:`external`,resource:`valibot.v`}),o=P(a).attr(V.schemas.picklist).call(P.array(...r));return i&&(o=P(a).attr(V.schemas.nullable).call(o)),o},Us=({plugin:e})=>P(e.referenceSymbol({category:`external`,resource:`valibot.v`})).attr(V.schemas.never).call(),Ws=({plugin:e})=>P(e.referenceSymbol({category:`external`,resource:`valibot.v`})).attr(V.schemas.null).call(),Gs=({plugin:e,schema:t})=>{let n=t.format,r=t.type===`integer`,i=Fs(n),a=Ps(n)?Ns[n]:null,o=e.referenceSymbol({category:`external`,resource:`valibot.v`});if(t.const!==void 0&&t.const!==null){let e=t.const,r;if(typeof e==`number`&&!n)r=P.literal(e);else if(typeof e==`number`&&n)r=i?P(`BigInt`).call(P.literal(e)):P.literal(e);else if(typeof e==`string`&&i){let t=e.endsWith(`n`)?e.slice(0,-1):e;r=P(`BigInt`).call(P.literal(t))}else if(typeof e==`bigint`){let t=e.toString(),n=t.endsWith(`n`)?t.slice(0,-1):t;r=P(`BigInt`).call(P.literal(n))}else r=P.fromValue(e);return P(o).attr(V.schemas.literal).call(r)}let s=[];if(i){let e=P(o).attr(V.schemas.union).call(P.array(P(o).attr(V.schemas.number).call(),P(o).attr(V.schemas.string).call(),P(o).attr(V.schemas.bigInt).call()));s.push(e);let t=P(o).attr(V.actions.transform).call(P.func().param(`x`).do(P(`BigInt`).call(`x`).return()));s.push(t)}else{let e=P(o).attr(V.schemas.number).call();s.push(e)}if(!i&&r){let e=P(o).attr(V.actions.integer).call();s.push(e)}if(a){let e=a.min,t=a.max,n=a.minError,r=a.maxError,c=P(o).attr(V.actions.minValue).call(i?P(`BigInt`).call(P.literal(e)):P.literal(e),P.literal(n));s.push(c);let l=P(o).attr(V.actions.maxValue).call(i?P(`BigInt`).call(P.literal(t)):P.literal(t),P.literal(r));s.push(l)}if(t.exclusiveMinimum!==void 0){let e=P(o).attr(V.actions.gtValue).call(Is({isBigInt:i,value:t.exclusiveMinimum}));s.push(e)}else if(t.minimum!==void 0){let e=P(o).attr(V.actions.minValue).call(Is({isBigInt:i,value:t.minimum}));s.push(e)}if(t.exclusiveMaximum!==void 0){let e=P(o).attr(V.actions.ltValue).call(Is({isBigInt:i,value:t.exclusiveMaximum}));s.push(e)}else if(t.maximum!==void 0){let e=P(o).attr(V.actions.maxValue).call(Is({isBigInt:i,value:t.maximum}));s.push(e)}return H({pipes:s,plugin:e})};function Ks({additional:e,pipes:t,plugin:n,shape:r}){let i=n.referenceSymbol({category:`external`,resource:`valibot.v`});return e===null?t.push(P(i).attr(V.schemas.strictObject).call(r)):e?r.isEmpty?t.push(P(i).attr(V.schemas.record).call(P(i).attr(V.schemas.string).call(),e)):t.push(P(i).attr(V.schemas.objectWithRest).call(r,e)):t.push(P(i).attr(V.schemas.object).call(r))}const qs=({plugin:e,schema:t,state:r})=>{let i={},a=[],o=P.object().pretty(),s=t.required??[];for(let a in t.properties){let l=t.properties[a],u=ec({optional:!s.includes(a),plugin:e,schema:l,state:{...r,path:c([...n(r.path),`properties`,a])}});u.hasLazyExpression&&(i.hasLazyExpression=!0),o.prop(a,H({pipes:u.pipes,plugin:e}))}let l;if(t.additionalProperties&&t.additionalProperties.type)if(t.additionalProperties.type===`never`)l=null;else{let a=ec({plugin:e,schema:t.additionalProperties,state:{...r,path:c([...n(r.path),`additionalProperties`])}});a.hasLazyExpression&&(i.hasLazyExpression=!0),l=H({pipes:a.pipes,plugin:e})}let u={$:P,additional:l,pipes:a,plugin:e,schema:t,shape:o},d=e.config[`~resolvers`]?.object?.base;return d?.(u)||Ks(u),i.pipes=[H({pipes:a,plugin:e})],i},Js=({pipes:e,plugin:t,schema:n})=>{let r=t.referenceSymbol({category:`external`,resource:`valibot.v`});switch(n.format){case`date`:return e.push(P(r).attr(V.actions.isoDate).call());case`date-time`:return e.push(P(r).attr(V.actions.isoTimestamp).call());case`email`:return e.push(P(r).attr(V.actions.email).call());case`ipv4`:case`ipv6`:return e.push(P(r).attr(V.actions.ip).call());case`time`:return e.push(P(r).attr(V.actions.isoTimeSecond).call());case`uri`:return e.push(P(r).attr(V.actions.url).call());case`uuid`:return e.push(P(r).attr(V.actions.uuid).call())}return!0},Ys=({plugin:e,schema:t})=>{let n=[],r=e.referenceSymbol({category:`external`,resource:`valibot.v`});if(typeof t.const==`string`)return n.push(P(r).attr(V.schemas.literal).call(P.literal(t.const))),H({pipes:n,plugin:e});if(n.push(P(r).attr(V.schemas.string).call()),t.format){let r={$:P,pipes:n,plugin:e,schema:t},i=e.config[`~resolvers`]?.string?.formats?.[t.format];i?.(r)||Js(r)}return t.minLength===t.maxLength&&t.minLength!==void 0?n.push(P(r).attr(V.actions.length).call(P.literal(t.minLength))):(t.minLength!==void 0&&n.push(P(r).attr(V.actions.minLength).call(P.literal(t.minLength))),t.maxLength!==void 0&&n.push(P(r).attr(V.actions.maxLength).call(P.literal(t.maxLength)))),t.pattern&&n.push(P(r).attr(V.actions.regex).call(P.regexp(t.pattern))),H({pipes:n,plugin:e})},Xs=({plugin:e,schema:t,state:r})=>{let i={},a=e.referenceSymbol({category:`external`,resource:`valibot.v`});if(t.const&&Array.isArray(t.const)){let e=t.const.map(e=>P(a).attr(V.schemas.literal).call(P.fromValue(e)));return i.pipes=[P(a).attr(V.schemas.tuple).call(P.array(...e))],i}if(t.items){let o=t.items.map((t,a)=>{let o=ec({plugin:e,schema:t,state:{...r,path:c([...n(r.path),`items`,a])}});return o.hasLazyExpression&&(i.hasLazyExpression=!0),H({pipes:o.pipes,plugin:e})});return i.pipes=[P(a).attr(V.schemas.tuple).call(P.array(...o))],i}return{pipes:[zs({plugin:e,schema:{type:`unknown`},state:r})]}},Zs=({plugin:e})=>P(e.referenceSymbol({category:`external`,resource:`valibot.v`})).attr(V.schemas.undefined).call(),Qs=({plugin:e})=>P(e.referenceSymbol({category:`external`,resource:`valibot.v`})).attr(V.schemas.void).call(),$s=({schema:e,...t})=>{switch(e.type){case`array`:return{expression:H({pipes:Bs({...t,schema:e}).pipes,plugin:t.plugin})};case`boolean`:return{expression:Vs({...t,schema:e})};case`enum`:return{expression:Hs({...t,schema:e})};case`integer`:case`number`:return{expression:Gs({...t,schema:e})};case`never`:return{expression:Us({...t,schema:e})};case`null`:return{expression:Ws({...t,schema:e})};case`object`:return{expression:H({pipes:qs({...t,schema:e}).pipes,plugin:t.plugin})};case`string`:return e.format===`int64`||e.format===`uint64`?{expression:Gs({...t,schema:e})}:{expression:Ys({...t,schema:e})};case`tuple`:return{expression:H({pipes:Xs({...t,schema:e}).pipes,plugin:t.plugin})};case`undefined`:return{expression:Zs({...t,schema:e})};case`unknown`:return{expression:zs({...t,schema:e})};case`void`:return{expression:Qs({...t,schema:e})}}},ec=({optional:e,plugin:t,schema:r,state:i})=>{let a={pipes:[]},o=t.referenceSymbol({category:`external`,resource:`valibot.v`});if(r.$ref){let e={category:`schema`,resource:`definition`,resourceId:r.$ref,tool:`valibot`},n=t.referenceSymbol(e);if(t.isSymbolRegistered(e)){let e=P(n);a.pipes.push(e)}else{let e=P(o).attr(V.schemas.lazy).call(P.func().do(P(n).return()));a.pipes.push(e),i.hasLazyExpression[`~ref`]=!0}}else if(r.type){let e=$s({plugin:t,schema:r,state:i});if(a.typeName=e.anyType,a.pipes.push(e.expression),t.config.metadata&&r.description){let e=P(o).attr(V.actions.metadata).call(P.object().prop(`description`,P.literal(r.description)));a.pipes.push(e)}}else if(r.items)if(r=x({schema:r}),r.items){let e=r.items.map((e,r)=>H({pipes:ec({plugin:t,schema:e,state:{...i,path:c([...n(i.path),`items`,r])}}).pipes,plugin:t}));if(r.logicalOperator===`and`){let t=P(o).attr(V.schemas.intersect).call(P.array(...e));a.pipes.push(t)}else{let t=P(o).attr(V.schemas.union).call(P.array(...e));a.pipes.push(t)}}else{let e=ec({plugin:t,schema:r,state:i});a.pipes.push(...e.pipes)}else{let e=$s({plugin:t,schema:{type:`unknown`},state:i});a.typeName=e.anyType,a.pipes.push(e.expression)}if(a.pipes.length){if(r.accessScope===`read`){let e=P(o).attr(V.actions.readonly).call();a.pipes.push(e)}let n;r.default!==void 0&&(n=Is({isBigInt:r.type===`integer`&&r.format===`int64`,value:r.default}),a.pipes=[P(o).attr(V.schemas.optional).call(H({pipes:a.pipes,plugin:t}),n)]),e&&!n&&(a.pipes=[P(o).attr(V.schemas.optional).call(H({pipes:a.pipes,plugin:t}))])}return a},tc=({plugin:e,schema:t,state:r})=>{let i=ji(n(r.path)),a=ec({plugin:e,schema:t,state:r}),o=F(i);Ms({ast:a,plugin:e,schema:t,state:r,symbol:e.registerSymbol({meta:{category:`schema`,path:n(r.path),resource:`definition`,resourceId:i,tags:n(r.tags),tool:`valibot`},name:b({config:e.config.definitions,name:o})})})},nc=({plugin:e})=>{e.registerSymbol({external:`valibot`,importKind:`namespace`,meta:{category:`external`,resource:`valibot.v`},name:`v`}),e.forEach(`operation`,`parameter`,`requestBody`,`schema`,`webhook`,t=>{let n=l({hasLazyExpression:!1,path:t._path,tags:t.tags});switch(t.type){case`operation`:Ls({getAst:(n,r)=>ec({plugin:e,schema:n,state:l({hasLazyExpression:!1,path:r,tags:t.tags})}),operation:t.operation,plugin:e,state:n});break;case`parameter`:tc({plugin:e,schema:t.parameter.schema,state:n});break;case`requestBody`:tc({plugin:e,schema:t.requestBody.schema,state:n});break;case`schema`:tc({plugin:e,schema:t.schema,state:n});break;case`webhook`:Rs({getAst:(n,r)=>ec({plugin:e,schema:n,state:l({hasLazyExpression:!1,path:r,tags:t.tags})}),operation:t.operation,plugin:e,state:n});break}})},rc={api:new js,config:{case:`camelCase`,comments:!0,exportFromIndex:!1,metadata:!1},handler:e=>nc(e),name:`valibot`,resolveConfig:(e,t)=>{e.config.definitions=t.valueToObject({defaultValue:{case:e.config.case??`camelCase`,enabled:!0,name:`v{{name}}`},mappers:{boolean:e=>({enabled:e}),function:e=>({name:e}),string:e=>({name:e})},value:e.config.definitions}),e.config.requests=t.valueToObject({defaultValue:{case:e.config.case??`camelCase`,enabled:!0,name:`v{{name}}Data`},mappers:{boolean:e=>({enabled:e}),function:e=>({name:e}),string:e=>({name:e})},value:e.config.requests}),e.config.responses=t.valueToObject({defaultValue:{case:e.config.case??`camelCase`,enabled:!0,name:`v{{name}}Response`},mappers:{boolean:e=>({enabled:e}),function:e=>({name:e}),string:e=>({name:e})},value:e.config.responses}),e.config.webhooks=t.valueToObject({defaultValue:{case:e.config.case??`camelCase`,enabled:!0,name:`v{{name}}WebhookRequest`},mappers:{boolean:e=>({enabled:e}),function:e=>({name:e}),string:e=>({name:e})},value:e.config.webhooks})},tags:[`validator`]},U={ZodMiniOptional:`ZodMiniOptional`,ZodOptional:`ZodOptional`,_default:`_default`,and:`and`,array:`array`,bigint:`bigint`,boolean:`boolean`,check:`check`,coerce:`coerce`,date:`date`,datetime:`datetime`,default:`default`,describe:`describe`,email:`email`,enum:`enum`,globalRegistry:`globalRegistry`,gt:`gt`,gte:`gte`,infer:`infer`,int:`int`,intersection:`intersection`,ip:`ip`,ipv4:`ipv4`,ipv6:`ipv6`,iso:`iso`,lazy:`lazy`,length:`length`,literal:`literal`,lt:`lt`,lte:`lte`,max:`max`,maxLength:`maxLength`,min:`min`,minLength:`minLength`,never:`never`,null:`null`,nullable:`nullable`,number:`number`,object:`object`,optional:`optional`,parseAsync:`parseAsync`,readonly:`readonly`,record:`record`,regex:`regex`,register:`register`,string:`string`,time:`time`,tuple:`tuple`,undefined:`undefined`,union:`union`,unknown:`unknown`,url:`url`,uuid:`uuid`,void:`void`},ic=({schema:e})=>P(e).attr(U.parseAsync).call(`data`).await().return(),ac=({operation:e,plugin:t})=>{let n=t.getSymbol({category:`schema`,resource:`operation`,resourceId:e.id,role:`data`,tool:`zod`});if(!n)return;let r={$:P,chain:void 0,operation:e,plugin:t,schema:n},i=t.config[`~resolvers`]?.validator,a=[typeof i==`function`?i:i?.request,ic];for(let e of a){let t=e?.(r);if(t===null)return;if(t!==void 0)return P.func().async().param(`data`).do(...t instanceof Array?t:[t])}},oc=({operation:e,plugin:t})=>{let n=t.getSymbol({category:`schema`,resource:`operation`,resourceId:e.id,role:`responses`,tool:`zod`});if(!n)return;let r={$:P,chain:void 0,operation:e,plugin:t,schema:n},i=t.config[`~resolvers`]?.validator,a=[typeof i==`function`?i:i?.response,ic];for(let e of a){let t=e?.(r);if(t===null)return;if(t!==void 0)return P.func().async().param(`data`).do(...t instanceof Array?t:[t])}},sc=({schema:e})=>P(e).attr(U.parseAsync).call(`data`).await().return(),cc=({operation:e,plugin:t})=>{let n=t.getSymbol({category:`schema`,resource:`operation`,resourceId:e.id,role:`data`,tool:`zod`});if(!n)return;let r={$:P,chain:void 0,operation:e,plugin:t,schema:n},i=t.config[`~resolvers`]?.validator,a=[typeof i==`function`?i:i?.request,sc];for(let e of a){let t=e?.(r);if(t===null)return;if(t!==void 0)return P.func().async().param(`data`).do(...t instanceof Array?t:[t])}},lc=({operation:e,plugin:t})=>{let n=t.getSymbol({category:`schema`,resource:`operation`,resourceId:e.id,role:`responses`,tool:`zod`});if(!n)return;let r={$:P,chain:void 0,operation:e,plugin:t,schema:n},i=t.config[`~resolvers`]?.validator,a=[typeof i==`function`?i:i?.response,sc];for(let e of a){let t=e?.(r);if(t===null)return;if(t!==void 0)return P.func().async().param(`data`).do(...t instanceof Array?t:[t])}},uc=({schema:e})=>P(e).attr(U.parseAsync).call(`data`).await().return(),dc=({operation:e,plugin:t})=>{let n=t.getSymbol({category:`schema`,resource:`operation`,resourceId:e.id,role:`data`,tool:`zod`});if(!n)return;let r={$:P,chain:void 0,operation:e,plugin:t,schema:n},i=t.config[`~resolvers`]?.validator,a=[typeof i==`function`?i:i?.request,uc];for(let e of a){let t=e?.(r);if(t===null)return;if(t!==void 0)return P.func().async().param(`data`).do(...t instanceof Array?t:[t])}},fc=({operation:e,plugin:t})=>{let n=t.getSymbol({category:`schema`,resource:`operation`,resourceId:e.id,role:`responses`,tool:`zod`});if(!n)return;let r={$:P,chain:void 0,operation:e,plugin:t,schema:n},i=t.config[`~resolvers`]?.validator,a=[typeof i==`function`?i:i?.response,uc];for(let e of a){let t=e?.(r);if(t===null)return;if(t!==void 0)return P.func().async().param(`data`).do(...t instanceof Array?t:[t])}};var pc=class{createRequestValidator(e){let{plugin:t}=e;switch(t.config.compatibilityVersion){case 3:return cc(e);case`mini`:return ac(e);case 4:default:return dc(e)}}createResponseValidator(e){let{plugin:t}=e;switch(t.config.compatibilityVersion){case 3:return lc(e);case`mini`:return oc(e);case 4:default:return fc(e)}}};const mc=({ast:e,plugin:t,schema:n,symbol:r,typeInferSymbol:i})=>{let a=t.referenceSymbol({category:`external`,resource:`zod.z`}),o=P.const(r).export().$if(t.config.comments&&R(n),(e,t)=>e.doc(t)).$if(e.typeName,(e,t)=>e.type(P.type(a).attr(t))).assign(e.expression);if(t.addNode(o),i){let e=P.type.alias(i).export().type(P.type(a).attr(U.infer).generic(P(r).typeofType()));t.addNode(e)}},hc=({plugin:e})=>{let t=e.package.getVersion(`zod`);if(t&&e.package.satisfies(t,`<4.0.0`))switch(e.config.compatibilityVersion){case 3:default:return`zod`;case 4:return`zod/v4`;case`mini`:return`zod/v4-mini`}switch(e.config.compatibilityVersion){case 3:return`zod/v3`;case 4:default:return`zod`;case`mini`:return`zod/mini`}},W=({isBigInt:e,value:t})=>{let n=P.fromValue(t);return e&&(typeof t==`bigint`||typeof t==`number`||typeof t==`string`||typeof t==`boolean`)?P(`BigInt`).call(n):n},gc=({getAst:e,operation:t,plugin:r,state:i})=>{if(r.config.requests.enabled){let a=new Set,o={properties:{body:{type:`never`},path:{type:`never`},query:{type:`never`}},type:`object`};if(t.parameters){if(t.parameters.header){let e={},n=[];for(let r in t.parameters.header){let i=t.parameters.header[r];e[i.name]=i.schema,i.required&&(n.push(i.name),a.add(`headers`))}Object.keys(e).length&&(o.properties.headers={properties:e,required:n,type:`object`})}if(t.parameters.path){let e={},n=[];for(let r in t.parameters.path){let i=t.parameters.path[r];e[i.name]=i.schema,i.required&&(n.push(i.name),a.add(`path`))}Object.keys(e).length&&(o.properties.path={properties:e,required:n,type:`object`})}if(t.parameters.query){let e={},n=[];for(let r in t.parameters.query){let i=t.parameters.query[r];e[i.name]=i.schema,i.required&&(n.push(i.name),a.add(`query`))}Object.keys(e).length&&(o.properties.query={properties:e,required:n,type:`object`})}}t.body&&(o.properties.body=t.body.schema,t.body.required&&a.add(`body`)),o.required=[...a],mc({ast:e(o,n(i.path)),plugin:r,schema:o,symbol:r.symbol(b({config:r.config.requests,name:t.id}),{meta:{category:`schema`,path:n(i.path),resource:`operation`,resourceId:t.id,role:`data`,tags:n(i.tags),tool:`zod`}}),typeInferSymbol:r.config.requests.types.infer.enabled?r.symbol(b({config:r.config.requests.types.infer,name:t.id}),{meta:{category:`type`,path:n(i.path),resource:`operation`,resourceId:t.id,role:`data`,tags:n(i.tags),tool:`zod`,variant:`infer`}}):void 0})}if(r.config.responses.enabled&&t.responses){let{response:a}=lt(t);if(a){let o=[...n(i.path),`responses`];mc({ast:e(a,o),plugin:r,schema:a,symbol:r.symbol(b({config:r.config.responses,name:t.id}),{meta:{category:`schema`,path:o,resource:`operation`,resourceId:t.id,role:`responses`,tags:n(i.tags),tool:`zod`}}),typeInferSymbol:r.config.responses.types.infer.enabled?r.symbol(b({config:r.config.responses.types.infer,name:t.id}),{meta:{category:`type`,path:o,resource:`operation`,resourceId:t.id,role:`responses`,tags:n(i.tags),tool:`zod`,variant:`infer`}}):void 0})}}},_c=({getAst:e,operation:t,plugin:r,state:i})=>{if(r.config.webhooks.enabled){let a=new Set,o={properties:{body:{type:`never`},path:{type:`never`},query:{type:`never`}},type:`object`};if(t.parameters){if(t.parameters.header){let e={},n=[];for(let r in t.parameters.header){let i=t.parameters.header[r];e[i.name]=i.schema,i.required&&(n.push(i.name),a.add(`headers`))}Object.keys(e).length&&(o.properties.headers={properties:e,required:n,type:`object`})}if(t.parameters.path){let e={},n=[];for(let r in t.parameters.path){let i=t.parameters.path[r];e[i.name]=i.schema,i.required&&(n.push(i.name),a.add(`path`))}Object.keys(e).length&&(o.properties.path={properties:e,required:n,type:`object`})}if(t.parameters.query){let e={},n=[];for(let r in t.parameters.query){let i=t.parameters.query[r];e[i.name]=i.schema,i.required&&(n.push(i.name),a.add(`query`))}Object.keys(e).length&&(o.properties.query={properties:e,required:n,type:`object`})}}t.body&&(o.properties.body=t.body.schema,t.body.required&&a.add(`body`)),o.required=[...a],mc({ast:e(o,n(i.path)),plugin:r,schema:o,symbol:r.registerSymbol({meta:{category:`schema`,path:n(i.path),resource:`webhook`,resourceId:t.id,role:`data`,tags:n(i.tags),tool:`zod`},name:b({config:r.config.webhooks,name:t.id})}),typeInferSymbol:r.config.webhooks.types.infer.enabled?r.registerSymbol({meta:{category:`type`,path:n(i.path),resource:`webhook`,resourceId:t.id,role:`data`,tags:n(i.tags),tool:`zod`,variant:`infer`},name:b({config:r.config.webhooks.types.infer,name:t.id})}):void 0})}},vc=({plugin:e})=>{let t=e.referenceSymbol({category:`external`,resource:`zod.z`}),n={};return n.expression=P(t).attr(U.unknown).call(),n},yc=({plugin:e,schema:t,state:r})=>{let i=e.referenceSymbol({category:`external`,resource:`zod.z`}),a={},o=P(i).attr(U.array);if(!t.items)a.expression=o.call(vc({plugin:e,schema:{type:`unknown`},state:r}).expression);else{t=x({schema:t});let s=t.items.map((t,i)=>{let o=Nc({plugin:e,schema:t,state:{...r,path:c([...n(r.path),`items`,i])}});return o.hasLazyExpression&&(a.hasLazyExpression=!0),o.expression});if(s.length===1)a.expression=o.call(...s);else if(t.logicalOperator===`and`){let e=t.items[0],n;if(e.logicalOperator===`or`||e.type&&e.type!==`object`)n=P(i).attr(U.intersection).call(...s);else{n=s[0];for(let e=1;e<s.length;e++)n=P(i).attr(U.intersection).call(n,s[e])}a.expression=o.call(n)}else a.expression=P(i).attr(U.array).call(P(i).attr(U.union).call(P.array(...s)))}let s=[];return t.minItems===t.maxItems&&t.minItems!==void 0?s.push(P(i).attr(U.length).call(P.fromValue(t.minItems))):(t.minItems!==void 0&&s.push(P(i).attr(U.minLength).call(P.fromValue(t.minItems))),t.maxItems!==void 0&&s.push(P(i).attr(U.maxLength).call(P.fromValue(t.maxItems)))),s.length&&(a.expression=a.expression.attr(U.check).call(...s)),a},bc=({plugin:e,schema:t})=>{let n={},r,i=e.referenceSymbol({category:`external`,resource:`zod.z`});return typeof t.const==`boolean`?(r=P(i).attr(U.literal).call(P.literal(t.const)),n.expression=r,n):(r=P(i).attr(U.boolean).call(),n.expression=r,n)},xc=({plugin:e,schema:t,state:n})=>{let r=e.referenceSymbol({category:`external`,resource:`zod.z`}),i={},a=[],o=[],s=!1,c=!0;for(let e of t.items??[])if(e.type===`string`&&typeof e.const==`string`){let t=P.literal(e.const);a.push(t),o.push(P(r).attr(U.literal).call(t))}else if((e.type===`number`||e.type===`integer`)&&typeof e.const==`number`){c=!1;let t=P.literal(e.const);o.push(P(r).attr(U.literal).call(t))}else if(e.type===`boolean`&&typeof e.const==`boolean`){c=!1;let t=P.literal(e.const);o.push(P(r).attr(U.literal).call(t))}else (e.type===`null`||e.const===null)&&(s=!0);return o.length?(c&&a.length>0?i.expression=P(r).attr(U.enum).call(P.array(...a)):o.length===1?i.expression=o[0]:i.expression=P(r).attr(U.union).call(P.array(...o)),s&&(i.expression=P(r).attr(U.nullable).call(i.expression)),i):vc({plugin:e,schema:{type:`unknown`},state:n})},Sc=({plugin:e})=>{let t=e.referenceSymbol({category:`external`,resource:`zod.z`}),n={};return n.expression=P(t).attr(U.never).call(),n},Cc=({plugin:e})=>{let t=e.referenceSymbol({category:`external`,resource:`zod.z`}),n={};return n.expression=P(t).attr(U.null).call(),n},wc=({plugin:e,schema:t})=>{let n=e.referenceSymbol({category:`external`,resource:`zod.z`}),r={},i=t.type===`integer`&&t.format===`int64`;if(typeof t.const==`number`)return r.expression=P(n).attr(U.literal).call(P.literal(t.const)),r;r.expression=i?P(n).attr(U.coerce).attr(U.bigint).call():P(n).attr(U.number).call(),!i&&t.type===`integer`&&(r.expression=P(n).attr(U.int).call());let a=[];return t.exclusiveMinimum===void 0?t.minimum!==void 0&&a.push(P(n).attr(U.gte).call(W({isBigInt:i,value:t.minimum}))):a.push(P(n).attr(U.gt).call(W({isBigInt:i,value:t.exclusiveMinimum}))),t.exclusiveMaximum===void 0?t.maximum!==void 0&&a.push(P(n).attr(U.lte).call(W({isBigInt:i,value:t.maximum}))):a.push(P(n).attr(U.lt).call(W({isBigInt:i,value:t.exclusiveMaximum}))),a.length&&(r.expression=r.expression.attr(U.check).call(...a)),r};function Tc({additional:e,plugin:t,shape:n}){let r=t.referenceSymbol({category:`external`,resource:`zod.z`});return e?P(r).attr(U.record).call(P(r).attr(U.string).call(),e):P(r).attr(U.object).call(n)}const Ec=({plugin:e,schema:t,state:r})=>{let i={},a=P.object().pretty(),o=t.required??[];for(let s in t.properties){let l=t.properties[s],u=Nc({optional:!o.includes(s),plugin:e,schema:l,state:{...r,path:c([...n(r.path),`properties`,s])}});u.hasLazyExpression&&(i.hasLazyExpression=!0),u.hasLazyExpression?a.getter(s,u.expression.return()):a.prop(s,u.expression)}let s;if(t.additionalProperties&&(!t.properties||!Object.keys(t.properties).length)){let a=Nc({plugin:e,schema:t.additionalProperties,state:{...r,path:c([...n(r.path),`additionalProperties`])}});a.hasLazyExpression&&(i.hasLazyExpression=!0),s=a.expression}let l={$:P,additional:s,chain:void 0,plugin:e,schema:t,shape:a},u=e.config[`~resolvers`]?.object?.base;return i.expression=u?.(l)??Tc(l),i},Dc=({chain:e,plugin:t,schema:n})=>{let r=t.referenceSymbol({category:`external`,resource:`zod.z`});switch(n.format){case`date`:return P(r).attr(U.iso).attr(U.date).call();case`date-time`:{let e=P.object().$if(t.config.dates.offset,e=>e.prop(`offset`,P.literal(!0))).$if(t.config.dates.local,e=>e.prop(`local`,P.literal(!0)));return P(r).attr(U.iso).attr(U.datetime).call(e.hasProps()?e:void 0)}case`email`:return P(r).attr(U.email).call();case`ipv4`:return P(r).attr(U.ipv4).call();case`ipv6`:return P(r).attr(U.ipv6).call();case`time`:return P(r).attr(U.iso).attr(U.time).call();case`uri`:return P(r).attr(U.url).call();case`uuid`:return P(r).attr(U.uuid).call();default:return e}},Oc=({plugin:e,schema:t})=>{let n={},r,i=e.referenceSymbol({category:`external`,resource:`zod.z`});if(typeof t.const==`string`)return r=P(i).attr(U.literal).call(P.literal(t.const)),n.expression=r,n;if(r=P(i).attr(U.string).call(),t.format){let n={$:P,chain:r,plugin:e,schema:t},i=e.config[`~resolvers`]?.string?.formats?.[t.format];r=i?.(n)??Dc(n)}let a=[];return t.minLength===t.maxLength&&t.minLength!==void 0?a.push(P(i).attr(U.length).call(P.literal(t.minLength))):(t.minLength!==void 0&&a.push(P(i).attr(U.minLength).call(P.literal(t.minLength))),t.maxLength!==void 0&&a.push(P(i).attr(U.maxLength).call(P.literal(t.maxLength)))),t.pattern&&a.push(P(i).attr(U.regex).call(P.regexp(t.pattern))),a.length&&(r=r.attr(U.check).call(...a)),n.expression=r,n},kc=({plugin:e,schema:t,state:r})=>{let i=e.referenceSymbol({category:`external`,resource:`zod.z`}),a={};if(t.const&&Array.isArray(t.const)){let e=t.const.map(e=>P(i).attr(U.literal).call(P.fromValue(e)));return a.expression=P(i).attr(U.tuple).call(P.array(...e)),a}let o=[];return t.items&&t.items.forEach((t,i)=>{let s=Nc({plugin:e,schema:t,state:{...r,path:c([...n(r.path),`items`,i])}});o.push(s.expression),s.hasLazyExpression&&(a.hasLazyExpression=!0)}),a.expression=P(i).attr(U.tuple).call(P.array(...o)),a},Ac=({plugin:e})=>{let t=e.referenceSymbol({category:`external`,resource:`zod.z`}),n={};return n.expression=P(t).attr(U.undefined).call(),n},jc=({plugin:e})=>{let t=e.referenceSymbol({category:`external`,resource:`zod.z`}),n={};return n.expression=P(t).attr(U.void).call(),n},Mc=({schema:e,...t})=>{switch(e.type){case`array`:return yc({...t,schema:e});case`boolean`:return bc({...t,schema:e});case`enum`:return xc({...t,schema:e});case`integer`:case`number`:return wc({...t,schema:e});case`never`:return Sc({...t,schema:e});case`null`:return Cc({...t,schema:e});case`object`:return Ec({...t,schema:e});case`string`:return Oc({...t,schema:e});case`tuple`:return kc({...t,schema:e});case`undefined`:return Ac({...t,schema:e});case`unknown`:return vc({...t,schema:e});case`void`:return jc({...t,schema:e})}},Nc=({optional:e,plugin:t,schema:r,state:i})=>{let a={},o=t.referenceSymbol({category:`external`,resource:`zod.z`});if(r.$ref){let e={category:`schema`,resource:`definition`,resourceId:r.$ref,tool:`zod`},n=t.referenceSymbol(e);t.isSymbolRegistered(e)?a.expression=P(n):(a.expression=P(o).attr(U.lazy).call(P.func().returns(`any`).do(P(n).return())),a.hasLazyExpression=!0,i.hasLazyExpression[`~ref`]=!0)}else if(r.type){let e=Mc({plugin:t,schema:r,state:i});a.expression=e.expression,a.hasLazyExpression=e.hasLazyExpression,t.config.metadata&&r.description&&(a.expression=a.expression.attr(U.register).call(P(o).attr(U.globalRegistry),P.object().pretty().prop(`description`,P.literal(r.description))))}else if(r.items)if(r=x({schema:r}),r.items){let e=r.items.map((e,r)=>Nc({plugin:t,schema:e,state:{...i,path:c([...n(i.path),`items`,r])}}));if(r.logicalOperator===`and`){let t=r.items[0];t.logicalOperator===`or`||t.type&&t.type!==`object`?a.expression=P(o).attr(U.intersection).call(...e.map(e=>e.expression)):(a.expression=e[0].expression,e.slice(1).forEach(e=>{a.expression=P(o).attr(U.intersection).call(a.expression,e.hasLazyExpression?P(o).attr(U.lazy).call(P.func().do(e.expression.return())):e.expression)}))}else a.expression=P(o).attr(U.union).call(P.array().pretty().elements(...e.map(e=>e.expression)))}else a=Nc({plugin:t,schema:r,state:i});else a.expression=Mc({plugin:t,schema:{type:`unknown`},state:i}).expression;if(a.expression&&(r.accessScope===`read`&&(a.expression=P(o).attr(U.readonly).call(a.expression)),e&&(a.expression=P(o).attr(U.optional).call(a.expression),a.typeName=U.ZodMiniOptional),r.default!==void 0)){let e=r.type===`integer`&&r.format===`int64`;a.expression=P(o).attr(U._default).call(a.expression,W({isBigInt:e,value:r.default}))}return a},Pc=({plugin:e,schema:t,state:r})=>{let i=ji(n(r.path)),a=Nc({plugin:e,schema:t,state:r}),o=F(i);mc({ast:a,plugin:e,schema:t,symbol:e.registerSymbol({meta:{category:`schema`,path:n(r.path),resource:`definition`,resourceId:i,tags:n(r.tags),tool:`zod`},name:b({config:e.config.definitions,name:o})}),typeInferSymbol:e.config.definitions.types.infer.enabled?e.registerSymbol({meta:{category:`type`,path:n(r.path),resource:`definition`,resourceId:i,tags:n(r.tags),tool:`zod`,variant:`infer`},name:b({config:e.config.definitions.types.infer,name:o})}):void 0})},Fc=({plugin:e})=>{e.registerSymbol({external:hc({plugin:e}),importKind:`namespace`,meta:{category:`external`,resource:`zod.z`},name:`z`}),e.forEach(`operation`,`parameter`,`requestBody`,`schema`,`webhook`,t=>{let n=l({hasLazyExpression:!1,path:t._path,tags:t.tags});switch(t.type){case`operation`:gc({getAst:(n,r)=>Nc({plugin:e,schema:n,state:l({hasLazyExpression:!1,path:r,tags:t.tags})}),operation:t.operation,plugin:e,state:n});break;case`parameter`:Pc({plugin:e,schema:t.parameter.schema,state:n});break;case`requestBody`:Pc({plugin:e,schema:t.requestBody.schema,state:n});break;case`schema`:Pc({plugin:e,schema:t.schema,state:n});break;case`webhook`:_c({getAst:(n,r)=>Nc({plugin:e,schema:n,state:l({hasLazyExpression:!1,path:r,tags:t.tags})}),operation:t.operation,plugin:e,state:n});break}})},Ic=({plugin:e})=>P(e.referenceSymbol({category:`external`,resource:`zod.z`})).attr(U.unknown).call(),Lc=({plugin:e,schema:t,state:r})=>{let i=e.referenceSymbol({category:`external`,resource:`zod.z`}),a=P(i).attr(U.array),o,s=!1;if(!t.items)o=a.call(Ic({plugin:e,schema:{type:`unknown`},state:r}));else{t=x({schema:t});let l=t.items.map((t,i)=>{let a=Zc({plugin:e,schema:t,state:{...r,path:c([...n(r.path),`items`,i])}});return a.hasLazyExpression&&(s=!0),a.expression});if(l.length===1)o=a.call(...l);else if(t.logicalOperator===`and`){let e=t.items[0],n;if(e.logicalOperator===`or`||e.type&&e.type!==`object`)n=P(i).attr(U.intersection).call(...l);else{n=l[0];for(let e=1;e<l.length;e++)n=n.attr(U.and).call(l[e])}o=a.call(n)}else o=P(i).attr(U.array).call(P(i).attr(U.union).call(P.array(...l)))}return t.minItems===t.maxItems&&t.minItems!==void 0?o=o.attr(U.length).call(P.fromValue(t.minItems)):(t.minItems!==void 0&&(o=o.attr(U.min).call(P.fromValue(t.minItems))),t.maxItems!==void 0&&(o=o.attr(U.max).call(P.fromValue(t.maxItems)))),{expression:o,hasLazyExpression:s}},Rc=({plugin:e,schema:t})=>{let n,r=e.referenceSymbol({category:`external`,resource:`zod.z`});return typeof t.const==`boolean`?(n=P(r).attr(U.literal).call(P.literal(t.const)),n):(n=P(r).attr(U.boolean).call(),n)},zc=({plugin:e,schema:t,state:n})=>{let r=e.referenceSymbol({category:`external`,resource:`zod.z`}),i=[],a=[],o=!1,s=!0;for(let e of t.items??[])if(e.type===`string`&&typeof e.const==`string`){let t=P.literal(e.const);i.push(t),a.push(P(r).attr(U.literal).call(t))}else if((e.type===`number`||e.type===`integer`)&&typeof e.const==`number`){s=!1;let t=P.literal(e.const);a.push(P(r).attr(U.literal).call(t))}else if(e.type===`boolean`&&typeof e.const==`boolean`){s=!1;let t=P.literal(e.const);a.push(P(r).attr(U.literal).call(t))}else (e.type===`null`||e.const===null)&&(o=!0);if(!a.length)return Ic({plugin:e,schema:{type:`unknown`},state:n});let c;return c=s&&i.length>0?P(r).attr(U.enum).call(P.array(...i)):a.length===1?a[0]:P(r).attr(U.union).call(P.array(...a)),o&&(c=c.attr(U.nullable).call()),c},Bc=({plugin:e})=>P(e.referenceSymbol({category:`external`,resource:`zod.z`})).attr(U.never).call(),Vc=({plugin:e})=>P(e.referenceSymbol({category:`external`,resource:`zod.z`})).attr(U.null).call(),Hc=({plugin:e,schema:t})=>{let n=e.referenceSymbol({category:`external`,resource:`zod.z`}),r=t.type===`integer`&&t.format===`int64`;if(typeof t.const==`number`)return P(n).attr(U.literal).call(P.literal(t.const));let i=r?P(n).attr(U.coerce).attr(U.bigint).call():P(n).attr(U.number).call();return!r&&t.type===`integer`&&(i=i.attr(U.int).call()),t.exclusiveMinimum===void 0?t.minimum!==void 0&&(i=i.attr(U.gte).call(W({isBigInt:r,value:t.minimum}))):i=i.attr(U.gt).call(W({isBigInt:r,value:t.exclusiveMinimum})),t.exclusiveMaximum===void 0?t.maximum!==void 0&&(i=i.attr(U.lte).call(W({isBigInt:r,value:t.maximum}))):i=i.attr(U.lt).call(W({isBigInt:r,value:t.exclusiveMaximum})),i};function Uc({additional:e,plugin:t,shape:n}){let r=t.referenceSymbol({category:`external`,resource:`zod.z`});return e?P(r).attr(U.record).call(e):P(r).attr(U.object).call(n)}const Wc=({plugin:e,schema:t,state:r})=>{let i=!1,a=P.object().pretty(),o=t.required??[];for(let s in t.properties){let l=t.properties[s],u=Zc({optional:!o.includes(s),plugin:e,schema:l,state:{...r,path:c([...n(r.path),`properties`,s])}});u.hasLazyExpression&&(i=!0),a.prop(s,u.expression)}let s,l={};if(t.additionalProperties&&(!t.properties||!Object.keys(t.properties).length)){let a=Zc({plugin:e,schema:t.additionalProperties,state:{...r,path:c([...n(r.path),`additionalProperties`])}});i=a.hasLazyExpression||i,s=a.expression}let u={$:P,additional:s,chain:void 0,plugin:e,schema:t,shape:a},d=e.config[`~resolvers`]?.object?.base;return l.expression=d?.(u)??Uc(u),{anyType:`AnyZodObject`,expression:l.expression,hasLazyExpression:i}},Gc=({chain:e,plugin:t,schema:n})=>{switch(n.format){case`date`:return e.attr(U.date).call();case`date-time`:{let n=P.object().$if(t.config.dates.offset,e=>e.prop(`offset`,P.literal(!0))).$if(t.config.dates.local,e=>e.prop(`local`,P.literal(!0)));return e.attr(U.datetime).call(n.hasProps()?n:void 0)}case`email`:return e.attr(U.email).call();case`ipv4`:case`ipv6`:return e.attr(U.ip).call();case`time`:return e.attr(U.time).call();case`uri`:return e.attr(U.url).call();case`uuid`:return e.attr(U.uuid).call();default:return e}},Kc=({plugin:e,schema:t})=>{let n,r=e.referenceSymbol({category:`external`,resource:`zod.z`});if(typeof t.const==`string`)return n=P(r).attr(U.literal).call(P.literal(t.const)),n;if(n=P(r).attr(U.string).call(),t.format){let r={$:P,chain:n,plugin:e,schema:t},i=e.config[`~resolvers`]?.string?.formats?.[t.format];n=i?.(r)??Gc(r)}return t.minLength===t.maxLength&&t.minLength!==void 0?n=n.attr(U.length).call(P.literal(t.minLength)):(t.minLength!==void 0&&(n=n.attr(U.min).call(P.literal(t.minLength))),t.maxLength!==void 0&&(n=n.attr(U.max).call(P.literal(t.maxLength)))),t.pattern&&(n=n.attr(U.regex).call(P.regexp(t.pattern))),n},qc=({plugin:e,schema:t,state:r})=>{let i=e.referenceSymbol({category:`external`,resource:`zod.z`}),a=!1;if(t.const&&Array.isArray(t.const)){let e=t.const.map(e=>P(i).attr(U.literal).call(P.fromValue(e)));return{expression:P(i).attr(U.tuple).call(P.array(...e)),hasLazyExpression:a}}let o=[];return t.items&&t.items.forEach((t,i)=>{let s=Zc({plugin:e,schema:t,state:{...r,path:c([...n(r.path),`items`,i])}});o.push(s.expression),s.hasLazyExpression&&(a=!0)}),{expression:P(i).attr(U.tuple).call(P.array(...o)),hasLazyExpression:a}},Jc=({plugin:e})=>P(e.referenceSymbol({category:`external`,resource:`zod.z`})).attr(U.undefined).call(),Yc=({plugin:e})=>P(e.referenceSymbol({category:`external`,resource:`zod.z`})).attr(U.void).call(),Xc=({schema:e,...t})=>{switch(e.type){case`array`:return Lc({...t,schema:e});case`boolean`:return{expression:Rc({...t,schema:e})};case`enum`:return{expression:zc({...t,schema:e})};case`integer`:case`number`:return{expression:Hc({...t,schema:e})};case`never`:return{expression:Bc({...t,schema:e})};case`null`:return{expression:Vc({...t,schema:e})};case`object`:return Wc({...t,schema:e});case`string`:return{expression:Kc({...t,schema:e})};case`tuple`:return qc({...t,schema:e});case`undefined`:return{expression:Jc({...t,schema:e})};case`unknown`:return{expression:Ic({...t,schema:e})};case`void`:return{expression:Yc({...t,schema:e})}}},Zc=({optional:e,plugin:t,schema:r,state:i})=>{let a={},o=t.referenceSymbol({category:`external`,resource:`zod.z`});if(r.$ref){let e={category:`schema`,resource:`definition`,resourceId:r.$ref,tool:`zod`},n=t.referenceSymbol(e);t.isSymbolRegistered(e)?a.expression=P(n):(a.expression=P(o).attr(U.lazy).call(P.func().do(P(n).return())),a.hasLazyExpression=!0,i.hasLazyExpression[`~ref`]=!0)}else if(r.type){let e=Xc({plugin:t,schema:r,state:i});a.expression=e.expression,a.typeName=e.anyType,t.config.metadata&&r.description&&(a.expression=a.expression.attr(U.describe).call(P.literal(r.description)))}else if(r.items)if(r=x({schema:r}),r.items){let e=r.items.map((e,r)=>Zc({plugin:t,schema:e,state:{...i,path:c([...n(i.path),`items`,r])}}).expression);if(r.logicalOperator===`and`){let t=r.items[0];t.logicalOperator===`or`||t.type&&t.type!==`object`?a.expression=P(o).attr(U.intersection).call(...e):(a.expression=e[0],e.slice(1).forEach(e=>{a.expression=a.expression.attr(U.and).call(e)}))}else a.expression=P(o).attr(U.union).call(P.array().pretty().elements(...e))}else a=Zc({plugin:t,schema:r,state:i});else{let e=Xc({plugin:t,schema:{type:`unknown`},state:i});a.expression=e.expression,a.typeName=e.anyType}if(a.expression&&(r.accessScope===`read`&&(a.expression=a.expression.attr(U.readonly).call()),e&&(a.expression=a.expression.attr(U.optional).call()),r.default!==void 0)){let e=r.type===`integer`&&r.format===`int64`;a.expression=a.expression.attr(U.default).call(W({isBigInt:e,value:r.default}))}return i.hasLazyExpression[`~ref`]?a.typeName||=`ZodTypeAny`:a.typeName&&=void 0,a},Qc=({plugin:e,schema:t,state:r})=>{let i=ji(n(r.path)),a=Zc({plugin:e,schema:t,state:r}),o=F(i);mc({ast:a,plugin:e,schema:t,symbol:e.registerSymbol({meta:{category:`schema`,path:n(r.path),resource:`definition`,resourceId:i,tags:n(r.tags),tool:`zod`},name:b({config:e.config.definitions,name:o})}),typeInferSymbol:e.config.definitions.types.infer.enabled?e.registerSymbol({meta:{category:`type`,path:n(r.path),resource:`definition`,resourceId:i,tags:n(r.tags),tool:`zod`,variant:`infer`},name:b({config:e.config.definitions.types.infer,name:o})}):void 0})},$c=({plugin:e})=>{e.registerSymbol({external:hc({plugin:e}),meta:{category:`external`,resource:`zod.z`},name:`z`}),e.forEach(`operation`,`parameter`,`requestBody`,`schema`,`webhook`,t=>{let n=l({hasLazyExpression:!1,path:t._path,tags:t.tags});switch(t.type){case`operation`:gc({getAst:(n,r)=>Zc({plugin:e,schema:n,state:l({hasLazyExpression:!1,path:r,tags:t.tags})}),operation:t.operation,plugin:e,state:n});break;case`parameter`:Qc({plugin:e,schema:t.parameter.schema,state:n});break;case`requestBody`:Qc({plugin:e,schema:t.requestBody.schema,state:n});break;case`schema`:Qc({plugin:e,schema:t.schema,state:n});break;case`webhook`:_c({getAst:(n,r)=>Zc({plugin:e,schema:n,state:l({hasLazyExpression:!1,path:r,tags:t.tags})}),operation:t.operation,plugin:e,state:n});break}})},el=({plugin:e})=>{let t={};return t.expression=P(e.referenceSymbol({category:`external`,resource:`zod.z`})).attr(U.unknown).call(),t},tl=({plugin:e,schema:t,state:r})=>{let i={},a=e.referenceSymbol({category:`external`,resource:`zod.z`}),o=P(a).attr(U.array);if(!t.items)i.expression=o.call(el({plugin:e,schema:{type:`unknown`},state:r}).expression);else{t=x({schema:t});let s=t.items.map((t,a)=>{let o=hl({plugin:e,schema:t,state:{...r,path:c([...n(r.path),`items`,a])}});return o.hasLazyExpression&&(i.hasLazyExpression=!0),o.expression});if(s.length===1)i.expression=o.call(...s);else if(t.logicalOperator===`and`){let e=t.items[0],n;if(e.logicalOperator===`or`||e.type&&e.type!==`object`)n=P(a).attr(U.intersection).call(...s);else{n=s[0];for(let e=1;e<s.length;e++)n=n.attr(U.and).call(s[e])}i.expression=o.call(n)}else i.expression=P(a).attr(U.array).call(P(a).attr(U.union).call(P.array(...s)))}return t.minItems===t.maxItems&&t.minItems!==void 0?i.expression=i.expression.attr(U.length).call(P.fromValue(t.minItems)):(t.minItems!==void 0&&(i.expression=i.expression.attr(U.min).call(P.fromValue(t.minItems))),t.maxItems!==void 0&&(i.expression=i.expression.attr(U.max).call(P.fromValue(t.maxItems)))),i},nl=({plugin:e,schema:t})=>{let n={},r,i=e.referenceSymbol({category:`external`,resource:`zod.z`});return typeof t.const==`boolean`?(r=P(i).attr(U.literal).call(P.literal(t.const)),n.expression=r,n):(r=P(i).attr(U.boolean).call(),n.expression=r,n)},rl=({plugin:e,schema:t,state:n})=>{let r={},i=e.referenceSymbol({category:`external`,resource:`zod.z`}),a=[],o=[],s=!1,c=!0;for(let e of t.items??[])if(e.type===`string`&&typeof e.const==`string`){let t=P.literal(e.const);a.push(t),o.push(P(i).attr(U.literal).call(t))}else if((e.type===`number`||e.type===`integer`)&&typeof e.const==`number`){c=!1;let t=P.literal(e.const);o.push(P(i).attr(U.literal).call(t))}else if(e.type===`boolean`&&typeof e.const==`boolean`){c=!1;let t=P.literal(e.const);o.push(P(i).attr(U.literal).call(t))}else (e.type===`null`||e.const===null)&&(s=!0);return o.length?(c&&a.length>0?r.expression=P(i).attr(U.enum).call(P.array(...a)):o.length===1?r.expression=o[0]:r.expression=P(i).attr(U.union).call(P.array(...o)),s&&(r.expression=P(i).attr(U.nullable).call(r.expression)),r):el({plugin:e,schema:{type:`unknown`},state:n})},il=({plugin:e})=>{let t={};return t.expression=P(e.referenceSymbol({category:`external`,resource:`zod.z`})).attr(U.never).call(),t},al=({plugin:e})=>{let t={};return t.expression=P(e.referenceSymbol({category:`external`,resource:`zod.z`})).attr(U.null).call(),t},ol=({plugin:e,schema:t})=>{let n={},r=t.type===`integer`&&t.format===`int64`,i=e.referenceSymbol({category:`external`,resource:`zod.z`});return typeof t.const==`number`?(n.expression=P(i).attr(U.literal).call(P.literal(t.const)),n):(n.expression=r?P(i).attr(U.coerce).attr(U.bigint).call():P(i).attr(U.number).call(),!r&&t.type===`integer`&&(n.expression=P(i).attr(U.int).call()),t.exclusiveMinimum===void 0?t.minimum!==void 0&&(n.expression=n.expression.attr(U.gte).call(W({isBigInt:r,value:t.minimum}))):n.expression=n.expression.attr(U.gt).call(W({isBigInt:r,value:t.exclusiveMinimum})),t.exclusiveMaximum===void 0?t.maximum!==void 0&&(n.expression=n.expression.attr(U.lte).call(W({isBigInt:r,value:t.maximum}))):n.expression=n.expression.attr(U.lt).call(W({isBigInt:r,value:t.exclusiveMaximum})),n)};function sl({additional:e,plugin:t,shape:n}){let r=t.referenceSymbol({category:`external`,resource:`zod.z`});return e?P(r).attr(U.record).call(P(r).attr(U.string).call(),e):P(r).attr(U.object).call(n)}const cl=({plugin:e,schema:t,state:r})=>{let i={},a=P.object().pretty(),o=t.required??[];for(let s in t.properties){let l=t.properties[s],u=hl({optional:!o.includes(s),plugin:e,schema:l,state:{...r,path:c([...n(r.path),`properties`,s])}});u.hasLazyExpression&&(i.hasLazyExpression=!0),u.hasLazyExpression?a.getter(s,u.expression.return()):a.prop(s,u.expression)}let s;if(t.additionalProperties&&(!t.properties||!Object.keys(t.properties).length)){let a=hl({plugin:e,schema:t.additionalProperties,state:{...r,path:c([...n(r.path),`additionalProperties`])}});a.hasLazyExpression&&(i.hasLazyExpression=!0),s=a.expression}let l={$:P,additional:s,chain:void 0,plugin:e,schema:t,shape:a},u=e.config[`~resolvers`]?.object?.base;return i.expression=u?.(l)??sl(l),i.hasLazyExpression?{...i,typeName:`ZodType`}:i},ll=({chain:e,plugin:t,schema:n})=>{let r=t.referenceSymbol({category:`external`,resource:`zod.z`});switch(n.format){case`date`:return P(r).attr(U.iso).attr(U.date).call();case`date-time`:{let e=P.object().$if(t.config.dates.offset,e=>e.prop(`offset`,P.literal(!0))).$if(t.config.dates.local,e=>e.prop(`local`,P.literal(!0)));return P(r).attr(U.iso).attr(U.datetime).call(e.hasProps()?e:void 0)}case`email`:return P(r).attr(U.email).call();case`ipv4`:return P(r).attr(U.ipv4).call();case`ipv6`:return P(r).attr(U.ipv6).call();case`time`:return P(r).attr(U.iso).attr(U.time).call();case`uri`:return P(r).attr(U.url).call();case`uuid`:return P(r).attr(U.uuid).call();default:return e}},ul=({plugin:e,schema:t})=>{let n={},r,i=e.referenceSymbol({category:`external`,resource:`zod.z`});if(typeof t.const==`string`)return r=P(i).attr(U.literal).call(P.literal(t.const)),n.expression=r,n;if(r=P(i).attr(U.string).call(),t.format){let n={$:P,chain:r,plugin:e,schema:t},i=e.config[`~resolvers`]?.string?.formats?.[t.format];r=i?.(n)??ll(n)}return t.minLength===t.maxLength&&t.minLength!==void 0?r=r.attr(U.length).call(P.literal(t.minLength)):(t.minLength!==void 0&&(r=r.attr(U.min).call(P.literal(t.minLength))),t.maxLength!==void 0&&(r=r.attr(U.max).call(P.literal(t.maxLength)))),t.pattern&&(r=r.attr(U.regex).call(P.regexp(t.pattern))),n.expression=r,n},dl=({plugin:e,schema:t,state:r})=>{let i={},a=e.referenceSymbol({category:`external`,resource:`zod.z`});if(t.const&&Array.isArray(t.const)){let e=t.const.map(e=>P(a).attr(U.literal).call(P.fromValue(e)));return i.expression=P(a).attr(U.tuple).call(P.array(...e)),i}let o=[];return t.items&&t.items.forEach((t,a)=>{let s=hl({plugin:e,schema:t,state:{...r,path:c([...n(r.path),`items`,a])}});o.push(s.expression),s.hasLazyExpression&&(i.hasLazyExpression=!0)}),i.expression=P(a).attr(U.tuple).call(P.array(...o)),i},fl=({plugin:e})=>{let t={};return t.expression=P(e.referenceSymbol({category:`external`,resource:`zod.z`})).attr(U.undefined).call(),t},pl=({plugin:e})=>{let t={};return t.expression=P(e.referenceSymbol({category:`external`,resource:`zod.z`})).attr(U.void).call(),t},ml=({schema:e,...t})=>{switch(e.type){case`array`:return tl({...t,schema:e});case`boolean`:return nl({...t,schema:e});case`enum`:return rl({...t,schema:e});case`integer`:case`number`:return ol({...t,schema:e});case`never`:return il({...t,schema:e});case`null`:return al({...t,schema:e});case`object`:return cl({...t,schema:e});case`string`:return ul({...t,schema:e});case`tuple`:return dl({...t,schema:e});case`undefined`:return fl({...t,schema:e});case`unknown`:return el({...t,schema:e});case`void`:return pl({...t,schema:e})}},hl=({optional:e,plugin:t,schema:r,state:i})=>{let a={},o=t.referenceSymbol({category:`external`,resource:`zod.z`});if(r.$ref){let e={category:`schema`,resource:`definition`,resourceId:r.$ref,tool:`zod`},n=t.referenceSymbol(e);t.isSymbolRegistered(e)?a.expression=P(n):(a.expression=P(o).attr(U.lazy).call(P.func().returns(`any`).do(P(n).return())),a.hasLazyExpression=!0,i.hasLazyExpression[`~ref`]=!0)}else if(r.type){let e=ml({plugin:t,schema:r,state:i});a.expression=e.expression,a.hasLazyExpression=e.hasLazyExpression,t.config.metadata&&r.description&&(a.expression=a.expression.attr(U.register).call(P(o).attr(U.globalRegistry),P.object().pretty().prop(`description`,P.literal(r.description))))}else if(r.items)if(r=x({schema:r}),r.items){let e=r.items.map((e,r)=>hl({plugin:t,schema:e,state:{...i,path:c([...n(i.path),`items`,r])}}));if(r.logicalOperator===`and`){let t=r.items[0];t.logicalOperator===`or`||t.type&&t.type!==`object`?a.expression=P(o).attr(U.intersection).call(...e.map(e=>e.expression)):(a.expression=e[0].expression,e.slice(1).forEach(e=>{a.expression=a.expression.attr(U.and).call(e.hasLazyExpression?P(o).attr(U.lazy).call(P.func().do(e.expression.return())):e.expression)}))}else a.expression=P(o).attr(U.union).call(P.array().pretty().elements(...e.map(e=>e.expression)))}else a=hl({plugin:t,schema:r,state:i});else a.expression=ml({plugin:t,schema:{type:`unknown`},state:i}).expression;if(a.expression&&(r.accessScope===`read`&&(a.expression=a.expression.attr(U.readonly).call()),e&&(a.expression=P(o).attr(U.optional).call(a.expression),a.typeName=U.ZodOptional),r.default!==void 0)){let e=r.type===`integer`&&r.format===`int64`;a.expression=a.expression.attr(U.default).call(W({isBigInt:e,value:r.default}))}return a},gl=({plugin:e,schema:t,state:r})=>{let i=ji(n(r.path)),a=hl({plugin:e,schema:t,state:r}),o=F(i);mc({ast:a,plugin:e,schema:t,symbol:e.registerSymbol({meta:{category:`schema`,path:n(r.path),resource:`definition`,resourceId:i,tags:n(r.tags),tool:`zod`},name:b({config:e.config.definitions,name:o})}),typeInferSymbol:e.config.definitions.types.infer.enabled?e.registerSymbol({meta:{category:`type`,path:n(r.path),resource:`definition`,resourceId:i,tags:n(r.tags),tool:`zod`,variant:`infer`},name:b({config:e.config.definitions.types.infer,name:o})}):void 0})},_l=({plugin:e})=>{e.registerSymbol({external:hc({plugin:e}),meta:{category:`external`,resource:`zod.z`},name:`z`}),e.forEach(`operation`,`parameter`,`requestBody`,`schema`,`webhook`,t=>{let n=l({hasLazyExpression:!1,path:t._path,tags:t.tags});switch(t.type){case`operation`:gc({getAst:(n,r)=>hl({plugin:e,schema:n,state:l({hasLazyExpression:!1,path:r,tags:t.tags})}),operation:t.operation,plugin:e,state:n});break;case`parameter`:gl({plugin:e,schema:t.parameter.schema,state:n});break;case`requestBody`:gl({plugin:e,schema:t.requestBody.schema,state:n});break;case`schema`:gl({plugin:e,schema:t.schema,state:n});break;case`webhook`:_c({getAst:(n,r)=>hl({plugin:e,schema:n,state:l({hasLazyExpression:!1,path:r,tags:t.tags})}),operation:t.operation,plugin:e,state:n});break}})},vl={api:new pc,config:{case:`camelCase`,comments:!0,exportFromIndex:!1,metadata:!1},handler:e=>{let{plugin:t}=e;switch(t.config.compatibilityVersion){case 3:return $c(e);case`mini`:return Fc(e);case 4:default:return _l(e)}},name:`zod`,resolveConfig:(e,t)=>{let n=t.package.getVersion(`zod`),r=()=>n&&(n.major===4||n.major===3)?n.major:4,i=e=>{if(!e)return r();if(!n)return e;if((e===4||e===3||e===`mini`)&&!t.package.satisfies(n,`>=3.25.0 <5.0.0`)){let t=r();return console.warn(`🔌 ${u.yellow(`Warning:`)} Installed ${u.cyan(`zod`)} ${u.cyan(`v${n.version}`)} does not support compatibility version ${u.yellow(String(e))}, using ${u.yellow(String(t))}.`),t}return e};e.config.compatibilityVersion=i(e.config.compatibilityVersion),e.config.dates=t.valueToObject({defaultValue:{local:!1,offset:!1},value:e.config.dates}),e.config.types=t.valueToObject({defaultValue:{infer:{case:`PascalCase`,enabled:!1}},mappers:{object:(e,n)=>({...e,infer:t.valueToObject({defaultValue:{...n.infer,enabled:e.infer===void 0?n.infer.enabled:!!e.infer},mappers:v,value:e.infer})})},value:e.config.types}),e.config.definitions=t.valueToObject({defaultValue:{case:e.config.case??`camelCase`,enabled:!0,name:`z{{name}}`,types:{...e.config.types,infer:{...e.config.types.infer,name:`{{name}}ZodType`}}},mappers:{...v,object:(e,n)=>({...e,types:t.valueToObject({defaultValue:n.types,mappers:{object:(e,n)=>({...e,infer:t.valueToObject({defaultValue:{...n.infer,enabled:e.infer===void 0?n.infer.enabled:!!e.infer},mappers:v,value:e.infer})})},value:e.types})})},value:e.config.definitions}),e.config.requests=t.valueToObject({defaultValue:{case:e.config.case??`camelCase`,enabled:!0,name:`z{{name}}Data`,types:{...e.config.types,infer:{...e.config.types.infer,name:`{{name}}DataZodType`}}},mappers:{...v,object:(e,n)=>({...e,types:t.valueToObject({defaultValue:n.types,mappers:{object:(e,n)=>({...e,infer:t.valueToObject({defaultValue:{...n.infer,enabled:e.infer===void 0?n.infer.enabled:!!e.infer},mappers:v,value:e.infer})})},value:e.types})})},value:e.config.requests}),e.config.responses=t.valueToObject({defaultValue:{case:e.config.case??`camelCase`,enabled:!0,name:`z{{name}}Response`,types:{...e.config.types,infer:{...e.config.types.infer,name:`{{name}}ResponseZodType`}}},mappers:{...v,object:(e,n)=>({...e,types:t.valueToObject({defaultValue:n.types,mappers:{object:(e,n)=>({...e,infer:t.valueToObject({defaultValue:{...n.infer,enabled:e.infer===void 0?n.infer.enabled:!!e.infer},mappers:v,value:e.infer})})},value:e.types})})},value:e.config.responses}),e.config.webhooks=t.valueToObject({defaultValue:{case:e.config.case??`camelCase`,enabled:!0,name:`z{{name}}WebhookRequest`,types:{...e.config.types,infer:{...e.config.types.infer,name:`{{name}}WebhookRequestZodType`}}},mappers:{...v,object:(e,n)=>({...e,types:t.valueToObject({defaultValue:n.types,mappers:{object:(e,n)=>({...e,infer:t.valueToObject({defaultValue:{...n.infer,enabled:e.infer===void 0?n.infer.enabled:!!e.infer},mappers:v,value:e.infer})})},value:e.types})})},value:e.config.webhooks})},tags:[`validator`]},yl={"@angular/common":ra,"@hey-api/client-angular":ya,"@hey-api/client-axios":ba,"@hey-api/client-fetch":xa,"@hey-api/client-ky":Sa,"@hey-api/client-next":Ca,"@hey-api/client-nuxt":wa,"@hey-api/client-ofetch":Ta,"@hey-api/schemas":Ia,"@hey-api/sdk":Ga,"@hey-api/transformers":$a,"@hey-api/typescript":To,"@pinia/colada":Vo,"@tanstack/angular-query-experimental":os,"@tanstack/react-query":ss,"@tanstack/solid-query":cs,"@tanstack/svelte-query":ls,"@tanstack/vue-query":us,arktype:Ss,fastify:ws,swr:Ds,valibot:rc,zod:vl},bl=[`@hey-api/typescript`,`@hey-api/sdk`],xl=({dependencies:e,userPlugins:t,userPluginsConfig:n})=>{let r=new Set,i=new Set,a={},o=s=>{if(r.has(s))throw Error(`Circular reference detected at '${s}'`);if(i.has(s))return;r.add(s);let c=yl[s],l=n[s];if(!c&&!l)throw Error(`unknown plugin dependency "${s}" - do you need to register a custom plugin with this name?`);let u={...c,...l,config:{...c?.config,...l?.config},dependencies:new Set([...c?.dependencies||[],...l?.dependencies||[]])};if(u.resolveConfig){let r={package:Da(e),pluginByTag:(e,r={})=>{let{defaultPlugin:i,errorMessage:a}=r;for(let r of t){let t=yl[r]||n[r];if(t&&t.tags?.includes(e)&&r!==s)return r}if(i){let t=yl[i]||n[i];if(t&&t.tags?.includes(e)&&i!==s)return i}throw Error(a||`missing plugin - no plugin with tag "${e}" found`)},valueToObject:_};u.resolveConfig(u,r)}for(let e of u.dependencies)o(e);r.delete(s),i.add(s),a[s]=u};for(let e of t)o(e);return{pluginOrder:Array.from(i),plugins:a}},Sl=e=>typeof e==`string`?e.startsWith(`@hey-api/client`):e.name.startsWith(`@hey-api/client`)||e.tags&&e.tags.includes(`client`),Cl=({dependencies:e,userConfig:t})=>{let n={},r=bl;return t.plugins&&(t.plugins=t.plugins.filter(e=>typeof e==`string`&&e||typeof e!=`string`&&e.name),r=t.plugins.length===1&&Sl(t.plugins[0])?[...bl,...t.plugins]:t.plugins),xl({dependencies:e,userPlugins:r.map(e=>{if(typeof e==`string`)return e;let t=e.name;return t&&(e.handler?n[t]=e:(n[t]={config:{...e}},delete n[t].config.name)),t}).filter(Boolean),userPluginsConfig:n})},wl=()=>!!(process.stdin.isTTY&&process.stdout.isTTY&&!process.env.CI&&!process.env.NO_INTERACTIVE&&!process.env.NO_INTERACTION),Tl=async({logger:e,userConfigs:t})=>{let n=[],r={},i=e.timeEvent(`load`);for(let i of t){let t;if(i?.configFile){let e=i.configFile.split(`.`);t=e.slice(0,e.length-1).join(`.`)}let a=e.timeEvent(`c12`),{loadConfig:o}=await import(`c12`),{config:s,configFile:c}=await o({configFile:t,name:`openapi-ts`});a.timeEnd(),Object.keys(r).length||(r=We(Object.keys(s).length?c:void 0));let l=s instanceof Array?s.map(e=>Be(e,i)):[Be(s,i)];for(let e of l){let t=Le(e);if(e.output instanceof Array){let r=t.length,i=e.output.length;if(i>1)if(r!==i){console.warn(`⚙️ ${u.yellow(`Warning:`)} You provided ${u.cyan(String(r))} ${u.cyan(r===1?`input`:`inputs`)} and ${u.yellow(String(i))} ${u.yellow(`outputs`)}. This is probably not what you want as it will produce identical output in multiple locations. You most likely want to provide a single output or the same number of outputs as inputs.`);for(let r of e.output)n.push({...e,input:t,output:r})}else e.output.forEach((r,i)=>{n.push({...e,input:t[i],output:r})});else n.push({...e,input:t,output:e.output[0]??``})}else n.push({...e,input:t})}}i.timeEnd();let a=[],o=e.timeEvent(`build`);for(let e of n){let t=Re(e),n=Le(e),i=Ue(e),o=Ke(e),s=[];n.length||s.push(new de(`missing input - which OpenAPI specification should we use to generate your output?`)),i.path||s.push(new de(`missing output - where should we generate your output?`)),i.path=f.resolve(process.cwd(),i.path);let c;try{c=Cl({dependencies:r,userConfig:e})}catch(e){s.push(e),c={pluginOrder:[],plugins:{}}}let l={configFile:e.configFile??``,dryRun:e.dryRun??!1,input:n,interactive:e.interactive??wl(),logs:t,output:i,parser:o,pluginOrder:c.pluginOrder,plugins:c.plugins},d=a.length;if(t.level===`debug`){let e=u.gray(`[Job ${d+1}] `);console.warn(`${e}${u.cyan(`config:`)}`,l)}a.push({config:l,errors:s,jobIndex:d})}return o.timeEnd(),{dependencies:r,results:a}};Object.entries({$body_:`body`,$headers_:`headers`,$path_:`path`,$query_:`query`});const El=e=>{switch(e){case`label`:return`.`;case`matrix`:return`;`;case`simple`:return`,`;default:return`&`}},Dl=e=>{switch(e){case`form`:return`,`;case`pipeDelimited`:return`|`;case`spaceDelimited`:return`%20`;default:return`,`}},Ol=e=>{switch(e){case`label`:return`.`;case`matrix`:return`;`;case`simple`:return`,`;default:return`&`}},kl=({allowReserved:e,explode:t,name:n,style:r,value:i})=>{if(!t){let t=(e?i:i.map(e=>encodeURIComponent(e))).join(Dl(r));switch(r){case`label`:return`.${t}`;case`matrix`:return`;${n}=${t}`;case`simple`:return t;default:return`${n}=${t}`}}let a=El(r),o=i.map(t=>r===`label`||r===`simple`?e?t:encodeURIComponent(t):Al({allowReserved:e,name:n,value:t})).join(a);return r===`label`||r===`matrix`?a+o:o},Al=({allowReserved:e,name:t,value:n})=>{if(n==null)return``;if(typeof n==`object`)throw Error("Deeply-nested arrays/objects aren’t supported. Provide your own `querySerializer()` to handle these.");return`${t}=${e?n:encodeURIComponent(n)}`},jl=({allowReserved:e,explode:t,name:n,style:r,value:i,valueOnly:a})=>{if(i instanceof Date)return a?i.toISOString():`${n}=${i.toISOString()}`;if(r!==`deepObject`&&!t){let t=[];Object.entries(i).forEach(([n,r])=>{t=[...t,n,e?r:encodeURIComponent(r)]});let a=t.join(`,`);switch(r){case`form`:return`${n}=${a}`;case`label`:return`.${a}`;case`matrix`:return`;${n}=${a}`;default:return a}}let o=Ol(r),s=Object.entries(i).map(([t,i])=>Al({allowReserved:e,name:r===`deepObject`?`${n}[${t}]`:t,value:i})).join(o);return r===`label`||r===`matrix`?o+s:s},Ml=({parameters:e={},...t}={})=>n=>{let r=[];if(n&&typeof n==`object`)for(let i in n){let a=n[i];if(a==null)continue;let o=e[i]||t;if(Array.isArray(a)){let e=kl({allowReserved:o.allowReserved,explode:!0,name:i,style:`form`,value:a,...o.array});e&&r.push(e)}else if(typeof a==`object`){let e=jl({allowReserved:o.allowReserved,explode:!0,name:i,style:`deepObject`,value:a,...o.object});e&&r.push(e)}else{let e=Al({allowReserved:o.allowReserved,name:i,value:a});e&&r.push(e)}}return r.join(`&`)},Nl=e=>{let t=[];return e.forEach((e,n)=>{t.push([n,e])}),t},Pl=(...e)=>{let t=new Headers;for(let n of e){if(!n)continue;let e=n instanceof Headers?Nl(n):Object.entries(n);for(let[n,r]of e)if(r===null)t.delete(n);else if(Array.isArray(r))for(let e of r)t.append(n,e);else r!==void 0&&t.set(n,typeof r==`object`?JSON.stringify(r):r)}return t};Ml({allowReserved:!1,array:{explode:!0,style:`form`},object:{explode:!0,style:`deepObject`}});const Fl=async({fetchOptions:e,inputPath:t,timeout:n,watch:r})=>{let i=ee({pathOrUrlOrSchema:t}),a,o,s;if(i.type===`url`){if(r.lastValue&&r.isHeadMethodSupported!==!1){try{let t=await te({fetchOptions:{method:`HEAD`,...e,headers:Pl(e?.headers,r.headers)},timeout:n,url:i.path});if(t.response.status>=300)return{error:`not-ok`,response:t.response};s=t.response}catch(e){return{error:`not-ok`,response:new Response(e.message)}}if(!s.ok&&r.isHeadMethodSupported)return{error:`not-ok`,response:s};if(r.isHeadMethodSupported===void 0&&(r.isHeadMethodSupported=s.ok),s.status===304)return{error:`not-modified`,response:s};if(o===void 0){let e=s.headers.get(`ETag`);e&&(o=e!==r.headers.get(`If-None-Match`),o&&r.headers.set(`If-None-Match`,e))}if(o===void 0){let e=s.headers.get(`Last-Modified`);e&&(o=e!==r.headers.get(`If-Modified-Since`),o&&r.headers.set(`If-Modified-Since`,e))}if(o===!1)return{error:`not-modified`,response:s}}try{let t=await te({fetchOptions:{method:`GET`,...e},timeout:n,url:i.path});if(t.response.status>=300)return{error:`not-ok`,response:t.response};s=t.response}catch(e){return{error:`not-ok`,response:new Response(e.message)}}if(!s.ok)return{error:`not-ok`,response:s};if(a=s.body?await s.arrayBuffer():new ArrayBuffer(0),o===void 0){let e=new TextDecoder().decode(a);o=e!==r.lastValue,r.lastValue=e}}else r.lastValue?o=!1:r.lastValue=i.type;return o===!1?{error:`not-modified`,response:s}:{arrayBuffer:a,resolvedInput:i}};var Il=class{heap=[];constructor(e){this.declIndex=e}isEmpty(){return!this.heap.length}pop(){let[e]=this.heap;if(!this.heap.length)return;let t=this.heap.pop();return this.heap.length?(this.heap[0]=t,this.sinkDown(0),e):e}push(e){this.heap.push(e),this.bubbleUp(this.heap.length-1)}bubbleUp(e){let t=this.heap;for(;e>0;){let n=Math.floor((e-1)/2),r=t[n],i=t[e];if(this.declIndex.get(r)<=this.declIndex.get(i))break;t[n]=i,t[e]=r,e=n}}sinkDown(e){let t=this.heap,n=t.length;for(;;){let r=2*e+1,i=2*e+2,a=e;if(r<n){let e=t[r],n=t[a];this.declIndex.get(e)<this.declIndex.get(n)&&(a=r)}if(i<n){let e=t[i],n=t[a];this.declIndex.get(e)<this.declIndex.get(n)&&(a=i)}if(a===e)break;let o=t[a];t[a]=t[e],t[e]=o,e=a}}};const Ll=(e,t,n)=>{let r=Array.from(e.nodes.keys());if(n?.preferGroups&&n.preferGroups.length>0){let i=new Set;if(n.matchPointerToGroup)for(let a of n.preferGroups)for(let o of r){let r=n.matchPointerToGroup(o);r.matched&&r.kind===a&&(i.add(o),t(o,e.nodes.get(o)))}for(let n of r)i.has(n)||t(n,e.nodes.get(n));return}for(let n of r)t(n,e.nodes.get(n))},Rl=(e,t,n)=>{let r=Array.from(e.nodes.keys()),i=new Map;r.forEach((e,t)=>i.set(e,t));let a=new Map;for(let e of r){let t=(n?.getPointerPriority?.(e)??10)*1e6+(i.get(e)??0);a.set(e,t)}let o=new Map;for(let t of r){let n=e.subtreeDependencies?.get(t)??new Set,r=new Set;for(let i of n)i!==t&&e.nodes.has(i)&&r.add(i);o.set(t,r)}let s=new Map,c=new Map;for(let e of r)s.set(e,0);for(let[e,t]of o){s.set(e,t.size);for(let n of t)c.has(n)||c.set(n,new Set),c.get(n).add(e)}let l=e=>e.sort((e,t)=>a.get(e)-a.get(t)),u=new Il(a);for(let e of r)(s.get(e)??0)===0&&u.push(e);let d=new Set,f=[];for(;!u.isEmpty();){let e=u.pop();if(d.has(e))continue;d.add(e),f.push(e);let t=c.get(e);if(t)for(let e of t){let t=(s.get(e)??0)-1;s.set(e,t),t===0&&u.push(e)}}let p=r.filter(e=>!d.has(e));l(p);for(let e of p)d.add(e),f.push(e);let m=f;if(n?.preferGroups&&n.preferGroups.length>0){let e=new Map;for(let t=0;t<n.preferGroups.length;t++){let r=n.preferGroups[t];r&&e.set(r,t)}let t=t=>{if(n.matchPointerToGroup){let r=n.matchPointerToGroup(t);if(r.matched)return e.has(r.kind)?e.get(r.kind):n.preferGroups.length}return n.preferGroups.length},r=[...f].sort((e,n)=>{let r=t(e),i=t(n);return r===i?f.indexOf(e)-f.indexOf(n):r-i}),i=new Map;for(let e=0;e<r.length;e++)i.set(r[e],e);(()=>{for(let[e,n]of o)for(let r of n)if(!(t(r)<=t(e))&&i.get(r)>=i.get(e))return!0;return!1})()||(m=r)}for(let n of m)t(n,e.nodes.get(n))},zl=(e,t,n)=>n?.order===`topological`?Rl(e,t,n):Ll(e,t,n),Bl=[`operation`,`parameter`,`requestBody`,`schema`,`server`,`webhook`],Vl=(e,t)=>{let n={operation:/^#\/paths\/[^/]+\/(get|put|post|delete|options|head|patch|trace)$/,parameter:/^#\/components\/parameters\/[^/]+$/,requestBody:/^#\/components\/requestBodies\/[^/]+$/,schema:/^#\/components\/schemas\/[^/]+$/,server:/^#\/servers\/(\d+|[^/]+)$/,webhook:/^#\/webhooks\/[^/]+\/(get|put|post|delete|options|head|patch|trace)$/};if(t)return n[t].test(e)?{kind:t,matched:!0}:{matched:!1};for(let t of Object.keys(n)){let r=t;if(n[r].test(e))return{kind:r,matched:!0}}return{matched:!1}},Hl=[`server`,`schema`,`parameter`,`requestBody`,`operation`,`webhook`],Ul=(()=>{let e={};for(let t=0;t<Hl.length;t++){let n=Hl[t];n&&(e[n]=t)}for(let t of Bl)e[t]===void 0&&(e[t]=Hl.length);return e})(),Wl=e=>{let t=Vl(e);return t.matched?Ul[t.kind]??10:10},Gl=e=>{if(!(!e.meta?.pluginName||typeof e.meta.pluginName!=`string`))return e.meta.pluginName.startsWith(`@hey-api/client-`)?`client`:e.meta.pluginName===`@hey-api/typescript`?`types`:e.meta.pluginName.startsWith(`@hey-api/`)?e.meta.pluginName.split(`/`)[1]:e.meta.pluginName},Kl=e=>{switch(e.method){case`delete`:case`patch`:case`post`:case`put`:return[`mutation`];case`get`:return[`query`];default:return}};var ql=class{api;config;context;dependencies=[];eventHooks;gen;handler;name;package;constructor(e){this.api=e.api??{},this.config=e.config,this.context=e.context,this.dependencies=e.dependencies,this.eventHooks=this.buildEventHooks(),this.gen=e.gen,this.handler=e.handler,this.name=e.name,this.package=e.context.package}addNode(e){for(let t of this.eventHooks[`node:set:before`])t({node:e,plugin:this});let t=this.gen.nodes.add(e);for(let t of this.eventHooks[`node:set:after`])t({node:e,plugin:this});return t}updateNode(e,t){for(let e of this.eventHooks[`node:set:before`])e({node:t,plugin:this});let n=this.gen.nodes.update(e,t);for(let e of this.eventHooks[`node:set:after`])e({node:t,plugin:this});return n}forEach(...e){if(!this.context.graph)throw Error(`No graph available in context`);let t,n,r={getPointerPriority:Wl,matchPointerToGroup:Vl,order:`topological`,preferGroups:Hl};typeof e[e.length-1]==`function`?(n=e.slice(0,-1),t=e[e.length-1]):(n=e.slice(0,-2),t=e[e.length-2],r={...r,...e[e.length-1]});let i=new Set(n.length?n:Bl);zl(this.context.graph,(e,n)=>{let r=Vl(e);if(!r.matched||!i.has(r.kind))return;let a,o={_path:ki(e),pointer:e,tags:n.tags?Array.from(n.tags):void 0};switch(r.kind){case`operation`:a={...o,method:n.key,operation:n.node,path:o._path[1],type:r.kind};break;case`parameter`:a={...o,name:n.key,parameter:n.node,type:r.kind};break;case`requestBody`:a={...o,name:n.key,requestBody:n.node,type:r.kind};break;case`schema`:a={...o,name:n.key,schema:n.node,type:r.kind};break;case`server`:a={...o,server:n.node,type:r.kind};break;case`webhook`:a={...o,key:o._path[1],method:n.key,operation:n.node,type:r.kind};break}if(a)try{t(a)}catch(e){this.forEachError(e,a)}},r)}getPlugin(e){return this.context.plugins[e]}getPluginOrThrow(e){let t=this.getPlugin(e);if(!t)throw Error(`plugin not found ${e}`);return t}getSymbol(e){return this.gen.symbols.get(e)}hooks={operation:{isMutation:e=>this.isOperationKind(e,`mutation`),isQuery:e=>this.isOperationKind(e,`query`)}};isSymbolRegistered(e){return this.gen.symbols.isRegistered(e)}querySymbol(e){return this.gen.symbols.query(e)[0]}referenceSymbol(e){return this.gen.symbols.reference(e)}registerSymbol(e){return this.symbol(e.name,e)}async run(){for(let e of this.eventHooks[`plugin:handler:before`])e({plugin:this});await this.handler({plugin:this});for(let e of this.eventHooks[`plugin:handler:after`])e({plugin:this})}symbol(e,t){let n={...t,exportFrom:t?.exportFrom??(!t?.external&&this.context.config.output.indexFile&&this.config.exportFromIndex?[`index`]:void 0),getFilePath:t?.getFilePath??this.getSymbolFilePath.bind(this),meta:{pluginName:f.isAbsolute(this.name)?`custom`:this.name,...t?.meta},name:e};for(let e of this.eventHooks[`symbol:register:before`])e({plugin:this,symbol:n});let r=this.gen.symbols.register(n);for(let e of this.eventHooks[`symbol:register:after`])e({plugin:this,symbol:r});return r}buildEventHooks(){let e={"node:set:after":[],"node:set:before":[],"plugin:handler:after":[],"plugin:handler:before":[],"symbol:register:after":[],"symbol:register:before":[]},t=[this.config[`~hooks`]?.events,this.context.config.parser.hooks.events];for(let n of t)if(n)for(let[t,r]of Object.entries(n))r&&e[t].push(r.bind(n));return e}forEachError(e,t){let n=e instanceof Error?e:Error(String(e));throw new me({args:[t],error:n,event:t.type,name:`Error`,pluginName:this.name})}getSymbolFilePath(e){let t=[this.config[`~hooks`]?.symbols,this.context.config.parser.hooks.symbols];for(let n of t){let t=n?.getFilePath?.(e);if(t!==void 0)return t}return Gl(e)}isOperationKind(e,t){let n=t===`query`?`isQuery`:`isMutation`,r=[this.config[`~hooks`]?.operations?.[n],this.config[`~hooks`]?.operations?.getKind,this.context.config.parser.hooks.operations?.[n],this.context.config.parser.hooks.operations?.getKind,Kl];for(let n of r)if(n){let r=n(e);if(r!==void 0)return typeof r==`boolean`?r:r.includes(t)}return!1}},Jl=class{config;gen;graph;ir={};logger;package;plugins={};spec;constructor({config:e,dependencies:n,logger:r,spec:i}){this.config=e,this.gen=new t({defaultFileName:`index`,fileName:t=>{let n=b({config:e.output.fileName,name:t}),{suffix:r}=e.output.fileName;return r?n===`index`||n.endsWith(r)?n:`${n}${r}`:n},nameConflictResolvers:e.output.nameConflictResolver?{typescript:e.output.nameConflictResolver}:void 0,renderers:[new _i({preferExportAll:e.output.preferExportAll,preferFileExtension:e.output.importFileExtension||void 0,resolveModuleName:e.output.resolveModuleName})],root:e.output.path}),this.logger=r,this.package=Da(n),this.spec=i}dereference(e){let t=this.resolveRef(e.$ref),n={...e,...t};return delete n.$ref,n}registerPlugin(e){let t=this.config.plugins[e],n=new ql({api:t.api,config:t.config,context:this,dependencies:t.dependencies??[],gen:this.gen,handler:t.handler,name:t.name});return this.plugins[n.name]=n,n}registerPlugins(){return this.config.pluginOrder.map(e=>this.registerPlugin(e))}resolveIrRef(e){return Mi({$ref:e,spec:this.ir})}resolveRef(e){return Mi({$ref:e,spec:this.spec})}};const G=[`delete`,`get`,`head`,`options`,`patch`,`post`,`put`,`trace`],Yl=({context:e,count:t=1,id:n,method:r,path:i,state:a})=>{let o,{output:s}=e.config,c=(s!==void 0&&typeof s==`object`&&`case`in s?s.case:void 0)??`camelCase`;return o=n&&(!e.config.plugins[`@hey-api/sdk`]||e.config.plugins[`@hey-api/sdk`].config.operationId)?y({case:c,value:ut(n)}):y({case:c,value:`${r}-${i.replace(/{(.*?)}/g,`by-$1`).replace(/[/:+]/g,`-`)}`}),t>1&&(o=`${o}${t}`),a.ids.has(o)?Yl({context:e,count:t+1,id:n,method:r,path:i,state:a}):(a.ids.set(o,C({method:r,path:i})),o)},K=(e,t=``)=>`${e}/${t}`,q=e=>{let t=e.indexOf(`/`);return{name:e.slice(t+1),namespace:e.slice(0,t)}},Xl=e=>{switch(e){case`parameters`:return`parameter`;case`requestBodies`:return`body`;case`responses`:return`response`;case`definitions`:case`schemas`:return`schema`;default:return`unknown`}},J=(e,t)=>{let n=[],r=[];if(t)for(let i of t)i.startsWith(`/`)&&i.endsWith(`/`)?r.push(new RegExp(i.slice(1,i.length-1))):n.push(K(e,i));return{regexps:r,set:new Set(n)}},Zl=({excludeOperations:e,excludeSchemas:t,includeOperations:n,includeSchemas:r,spec:i})=>{if((e.regexps.length||n.regexps.length)&&i.paths)for(let t of Object.entries(i.paths)){let r=t[0],i=t[1];for(let t of G){if(!i[t])continue;let a=C({method:t,path:r});e.regexps.some(e=>e.test(a))&&e.set.add(K(`operation`,a)),n.regexps.some(e=>e.test(a))&&n.set.add(K(`operation`,a))}}if(i.definitions&&(t.regexps.length||r.regexps.length))for(let e of Object.keys(i.definitions))t.regexps.some(t=>t.test(e))&&t.set.add(K(`schema`,e)),r.regexps.some(t=>t.test(e))&&r.set.add(K(`schema`,e))},Ql=({excludeOperations:e,excludeParameters:t,excludeRequestBodies:n,excludeResponses:r,excludeSchemas:i,includeOperations:a,includeParameters:o,includeRequestBodies:s,includeResponses:c,includeSchemas:l,spec:u})=>{if((e.regexps.length||a.regexps.length)&&u.paths)for(let t of Object.entries(u.paths)){let n=t[0],r=t[1];for(let t of G){if(!r[t])continue;let i=C({method:t,path:n});e.regexps.some(e=>e.test(i))&&e.set.add(K(`operation`,i)),a.regexps.some(e=>e.test(i))&&a.set.add(K(`operation`,i))}}if(u.components){if((t.regexps.length||o.regexps.length)&&u.components.parameters)for(let e of Object.keys(u.components.parameters))t.regexps.some(t=>t.test(e))&&t.set.add(K(`parameter`,e)),o.regexps.some(t=>t.test(e))&&o.set.add(K(`parameter`,e));if((n.regexps.length||s.regexps.length)&&u.components.requestBodies)for(let e of Object.keys(u.components.requestBodies))n.regexps.some(t=>t.test(e))&&n.set.add(K(`body`,e)),s.regexps.some(t=>t.test(e))&&s.set.add(K(`body`,e));if((r.regexps.length||c.regexps.length)&&u.components.responses)for(let e of Object.keys(u.components.responses))r.regexps.some(t=>t.test(e))&&r.set.add(K(`response`,e)),c.regexps.some(t=>t.test(e))&&c.set.add(K(`response`,e));if((i.regexps.length||l.regexps.length)&&u.components.schemas)for(let e of Object.keys(u.components.schemas))i.regexps.some(t=>t.test(e))&&i.set.add(K(`schema`,e)),l.regexps.some(t=>t.test(e))&&l.set.add(K(`schema`,e))}},$l=({spec:e,...t})=>{`swagger`in e?Zl({...t,spec:e}):Ql({...t,spec:e})},eu=(e,t,n)=>{let r=n.timeEvent(`create-filters`),i=J(`operation`,e?.operations?.exclude),a=J(`operation`,e?.operations?.include),o=J(`parameter`,e?.parameters?.exclude),s=J(`parameter`,e?.parameters?.include),c=J(`body`,e?.requestBodies?.exclude),l=J(`body`,e?.requestBodies?.include),u=J(`response`,e?.responses?.exclude),d=J(`response`,e?.responses?.include),f=J(`schema`,e?.schemas?.exclude),p=J(`schema`,e?.schemas?.include);$l({excludeOperations:i,excludeParameters:o,excludeRequestBodies:c,excludeResponses:u,excludeSchemas:f,includeOperations:a,includeParameters:s,includeRequestBodies:l,includeResponses:d,includeSchemas:p,spec:t});let m={deprecated:e?.deprecated??!0,operations:{exclude:i.set,include:a.set},orphans:e?.orphans??!1,parameters:{exclude:o.set,include:s.set},preserveOrder:e?.preserveOrder??!1,requestBodies:{exclude:c.set,include:l.set},responses:{exclude:u.set,include:d.set},schemas:{exclude:f.set,include:p.set},tags:{exclude:new Set(e?.tags?.exclude),include:new Set(e?.tags?.include)}};return r.timeEnd(),m},tu=e=>e?e.orphans===!1||e.deprecated===!1?!0:!!(e.operations?.exclude?.length||e.operations?.include?.length||e.parameters?.exclude?.length||e.parameters?.include?.length||e.requestBodies?.exclude?.length||e.requestBodies?.include?.length||e.responses?.exclude?.length||e.responses?.include?.length||e.schemas?.exclude?.length||e.schemas?.include?.length||e.tags?.exclude?.length||e.tags?.include?.length):!1,nu=({filters:e,parameters:t,requestBodies:n,resourceMetadata:r,responses:i,schemas:a})=>{let o=new Set,s=[...e.operations.include.size?e.operations.include:new Set(r.operations.keys())];for(;s.length;){let c=s.pop();if(e.operations.exclude.has(c)||o.has(c))continue;let l=r.operations.get(c);l&&(!e.deprecated&&l.deprecated||e.tags.exclude.size&&l.tags.size&&[...e.tags.exclude].some(e=>l.tags.has(e))||e.tags.include.size&&!new Set([...e.tags.include].filter(e=>l.tags.has(e))).size||[...l.dependencies].some(e=>{let{namespace:r}=q(e);switch(r){case`body`:return!n.has(e);case`parameter`:return!t.has(e);case`response`:return!i.has(e);case`schema`:return!a.has(e);default:return!1}})||o.add(c))}return{operations:o}},ru=({filters:e,resourceMetadata:t,schemas:n})=>{let r=new Set,i=[...e.parameters.include.size?e.parameters.include:new Set(t.parameters.keys())];for(;i.length;){let a=i.pop();if(e.parameters.exclude.has(a)||r.has(a))continue;let o=t.parameters.get(a);if(o&&!(!e.deprecated&&o.deprecated)&&(r.add(a),o.dependencies.size))for(let t of o.dependencies){let{namespace:o}=q(t);switch(o){case`body`:e.requestBodies.exclude.has(t)?r.delete(a):r.has(t)||i.push(t);break;case`schema`:e.schemas.exclude.has(t)?r.delete(a):n.has(t)||n.add(t);break}}}return{parameters:r}},iu=({filters:e,resourceMetadata:t,schemas:n})=>{let r=new Set,i=[...e.requestBodies.include.size?e.requestBodies.include:new Set(t.requestBodies.keys())];for(;i.length;){let a=i.pop();if(e.requestBodies.exclude.has(a)||r.has(a))continue;let o=t.requestBodies.get(a);if(o&&!(!e.deprecated&&o.deprecated)&&(r.add(a),o.dependencies.size))for(let t of o.dependencies){let{namespace:o}=q(t);switch(o){case`body`:e.requestBodies.exclude.has(t)?r.delete(a):r.has(t)||i.push(t);break;case`schema`:e.schemas.exclude.has(t)?r.delete(a):n.has(t)||n.add(t);break}}}return{requestBodies:r}},au=({filters:e,resourceMetadata:t,schemas:n})=>{let r=new Set,i=[...e.responses.include.size?e.responses.include:new Set(t.responses.keys())];for(;i.length;){let a=i.pop();if(e.responses.exclude.has(a)||r.has(a))continue;let o=t.responses.get(a);if(o&&!(!e.deprecated&&o.deprecated)&&(r.add(a),o.dependencies.size))for(let t of o.dependencies){let{namespace:o}=q(t);switch(o){case`body`:e.requestBodies.exclude.has(t)?r.delete(a):r.has(t)||i.push(t);break;case`schema`:e.schemas.exclude.has(t)?r.delete(a):n.has(t)||n.add(t);break}}}return{responses:r}},ou=({filters:e,resourceMetadata:t})=>{let n=new Set,r=[...e.schemas.include.size?e.schemas.include:new Set(t.schemas.keys())];for(;r.length;){let i=r.pop();if(e.schemas.exclude.has(i)||n.has(i))continue;let a=t.schemas.get(i);if(a&&!(!e.deprecated&&a.deprecated)&&(n.add(i),a.dependencies.size))for(let t of a.dependencies){let{namespace:i}=q(t);switch(i){case`schema`:!n.has(t)&&!e.schemas.exclude.has(t)&&r.push(t);break}}}return{schemas:n}},su=({filters:e,parameters:t,resourceMetadata:n})=>{if(e.parameters.exclude.size)for(let r of t){let i=n.parameters.get(r);if(i?.dependencies.size){for(let n of e.parameters.exclude)if(i.dependencies.has(n)){t.delete(r);break}}}},cu=({filters:e,requestBodies:t,resourceMetadata:n})=>{if(e.requestBodies.exclude.size)for(let r of t){let i=n.requestBodies.get(r);if(i?.dependencies.size){for(let n of e.requestBodies.exclude)if(i.dependencies.has(n)){t.delete(r);break}}}},lu=({filters:e,resourceMetadata:t,responses:n})=>{if(e.responses.exclude.size)for(let r of n){let i=t.responses.get(r);if(i?.dependencies.size){for(let t of e.responses.exclude)if(i.dependencies.has(t)){n.delete(r);break}}}},uu=({filters:e,resourceMetadata:t,schemas:n})=>{if(e.schemas.exclude.size)for(let r of n){let i=t.schemas.get(r);if(i?.dependencies.size){for(let t of e.schemas.exclude)if(i.dependencies.has(t)){n.delete(r);break}}}},du=({operationDependencies:e,parameters:t,requestBodies:n,responses:r,schemas:i})=>{for(let t of i)e.has(t)||i.delete(t);for(let n of t)e.has(n)||t.delete(n);for(let t of n)e.has(t)||n.delete(t);for(let t of r)e.has(t)||r.delete(t)},fu=({operations:e,resourceMetadata:t})=>{let n=new Set,r=[...new Set([...e].flatMap(e=>[...t.operations.get(e)?.dependencies??[]]))];for(;r.length;){let e=r.pop();if(n.has(e))continue;n.add(e);let{namespace:i}=q(e),a;if(i===`body`?a=t.requestBodies.get(e)?.dependencies:i===`operation`?a=t.operations.get(e)?.dependencies:i===`parameter`?a=t.parameters.get(e)?.dependencies:i===`response`?a=t.responses.get(e)?.dependencies:i===`schema`&&(a=t.schemas.get(e)?.dependencies),a?.size)for(let e of a)n.has(e)||r.push(e)}return{operationDependencies:n}},pu=({filters:e,logger:t,resourceMetadata:n})=>{let r=t.timeEvent(`create-filtered-dependencies`),{schemas:i}=ou({filters:e,resourceMetadata:n}),{parameters:a}=ru({filters:e,resourceMetadata:n,schemas:i}),{requestBodies:o}=iu({filters:e,resourceMetadata:n,schemas:i}),{responses:s}=au({filters:e,resourceMetadata:n,schemas:i});uu({filters:e,resourceMetadata:n,schemas:i}),su({filters:e,parameters:a,resourceMetadata:n}),cu({filters:e,requestBodies:o,resourceMetadata:n}),lu({filters:e,resourceMetadata:n,responses:s});let{operations:c}=nu({filters:e,parameters:a,requestBodies:o,resourceMetadata:n,responses:s,schemas:i});if(!e.orphans&&c.size){let{operationDependencies:e}=fu({operations:c,resourceMetadata:n});du({operationDependencies:e,parameters:a,requestBodies:o,responses:s,schemas:i})}return r.timeEnd(),{operations:c,parameters:a,requestBodies:o,responses:s,schemas:i}},mu=(e,t)=>{let n=t.timeEvent(`build-resource-metadata`),r={operations:new Map,parameters:new Map,requestBodies:new Map,responses:new Map,schemas:new Map},i=t=>{let n=new Set,r=e.transitiveDependencies.get(t);if(r?.size)for(let e of r){let t=ki(e),r=t[t.length-2],i=t[t.length-1];if(r&&i){let e=Xl(r);e===`unknown`&&console.warn(`unsupported type: ${r}`),n.add(K(e,i))}}return n};for(let[t,n]of e.nodes){let e=ki(t);if(e[0]===`components`){if(e.length===3){if(e[1]===`schemas`){let a=e[e.length-1];r.schemas.set(K(`schema`,a),{dependencies:i(t),deprecated:n.deprecated??!1})}else if(e[1]===`parameters`){let a=e[e.length-1];r.parameters.set(K(`parameter`,a),{dependencies:i(t),deprecated:n.deprecated??!1})}else if(e[1]===`requestBodies`){let a=e[e.length-1];r.requestBodies.set(K(`body`,a),{dependencies:i(t),deprecated:n.deprecated??!1})}else if(e[1]===`responses`){let a=e[e.length-1];r.responses.set(K(`response`,a),{dependencies:i(t),deprecated:n.deprecated??!1})}}continue}if(e[0]===`paths`){if(e.length===3&&G.includes(e[2])){let a=e[e.length-1],o=C({method:a,path:e.slice(1,-1).join(`/`)});r.operations.set(K(`operation`,o),{dependencies:i(t),deprecated:n.deprecated??!1,tags:n.tags??new Set})}continue}if(e[0]===`definitions`){if(e.length===2){let a=e[e.length-1];r.schemas.set(K(`schema`,a),{dependencies:i(t),deprecated:n.deprecated??!1})}continue}}return n.timeEnd(),{resourceMetadata:r}},hu=e=>JSON.parse(JSON.stringify(e)),gu=[[`additionalProperties`,`single`],[`allOf`,`array`],[`anyOf`,`array`],[`contains`,`single`],[`dependentSchemas`,`objectMap`],[`else`,`single`],[`if`,`single`],[`items`,`singleOrArray`],[`oneOf`,`array`],[`patternProperties`,`objectMap`],[`properties`,`objectMap`],[`propertyNames`,`single`],[`then`,`single`]],_u=e=>{if(vu(e))return e.components.schemas;if(yu(e))return e.definitions},vu=e=>typeof e==`object`&&!!e&&`components`in e&&typeof e.components==`object`&&e.components!==null&&`schemas`in e.components&&typeof e.components.schemas==`object`&&e.components.schemas!==null,yu=e=>typeof e==`object`&&!!e&&`definitions`in e&&typeof e.definitions==`object`&&e.definitions!==null,bu=(e,t)=>e instanceof Set?e.has(t):e instanceof Array?e.includes(t):t in e,xu=({base:e,components:t,extraComponents:n})=>{let r=2,i=e;for(;bu(t,i)||n&&bu(n,i);)i=`${e}${r}`,r+=1;return i},Su=e=>e.length===3&&e[0]===`components`&&e[1]===`schemas`||e.length===2&&e[0]===`definitions`,Cu=e=>{if(e&&typeof e==`object`){if(`swagger`in e)return`#/definitions/`;if(`openapi`in e)return`#/components/schemas/`}return``},wu=e=>{if(!e||typeof e!=`object`||!(`enum`in e)||!(e.enum instanceof Array))return;let t=(`type`in e?e.type:void 0)||``,n=[...e.enum].sort();return JSON.stringify({type:t,values:n})},Tu=({key:e,node:t,parent:n,path:r,visitor:i})=>{if(!t||typeof t!=`object`||t instanceof Array)return;let a=t;(`type`in a||`enum`in a||gu.some(([e])=>e in a))&&i({key:e,node:t,parent:n,path:r});for(let[e,n]of Object.entries(a))typeof n==`object`&&n&&(n instanceof Array?n.forEach((t,a)=>Tu({key:a,node:t,parent:n,path:[...r,e,a],visitor:i})):Tu({key:e,node:n,parent:t,path:[...r,e],visitor:i}))},Eu=({spec:e})=>{let t=_u(e);if(!t)return;let n=Cu(e),r={};for(let[e,i]of Object.entries(t))wu(i)&&(r[`${n}${e}`]=i);let i=e=>{if(e instanceof Array)e.forEach(i);else if(e&&typeof e==`object`)for(let[t,n]of Object.entries(e))t===`$ref`&&typeof n==`string`&&n in r?(Object.assign(e,hu(r[n])),delete e.$ref):i(n)};i(e);for(let e of Object.keys(r)){let n=ki(e),r=n[n.length-1];r&&delete t[r]}},Du=({config:e,spec:t})=>{let n=_u(t);if(!n)return;let r={};for(let[e,t]of Object.entries(n)){let n=wu(t);n&&(r[n]=e)}let i=[];Tu({key:null,node:t,parent:null,path:[],visitor:e=>{if(!Su(e.path)){let t=wu(e.node);t&&i.push({...e,signature:t})}}});let a={},o={};for(let{key:t,node:s,signature:c}of i)if(!(c in a)){if(c in r){a[c]=r[c];continue}a[c]=xu({base:b({config:e,name:typeof s==`object`&&s&&`title`in s&&typeof s.title==`string`?s.title:String(t)}),components:n,extraComponents:Object.values(a)}),o[c]=s}for(let[e,t]of Object.entries(a)){let r=o[e];t&&!(t in n)&&r&&typeof r==`object`&&(n[t]=r)}let s=Cu(t);for(let{key:e,parent:t,signature:n}of i){let r=a[n];r&&e!=null&&t&&typeof t==`object`&&(t[e]={$ref:`${s}${r}`})}},Ou=({config:e,spec:t})=>{if(e.mode===`inline`){Eu({spec:t});return}if(e.mode===`root`){Du({config:e,spec:t});return}},ku=({key:e,node:t,parent:n,path:r,visitor:i})=>{if(!t||typeof t!=`object`||t instanceof Array)return;let a=t;(`type`in a||gu.some(([e])=>e in a))&&i({key:e,node:t,parent:n,path:r});for(let[e,n]of Object.entries(a))typeof n==`object`&&n&&(n instanceof Array?n.forEach((t,a)=>ku({key:a,node:t,parent:n,path:[...r,e,a],visitor:i})):ku({key:e,node:n,parent:t,path:[...r,e],visitor:i}))},Au=({spec:e})=>{ku({key:null,node:e,parent:null,path:[],visitor:e=>{if(e.node&&typeof e.node==`object`&&`type`in e.node&&e.node.type===`object`&&`properties`in e.node&&e.node.properties&&typeof e.node.properties==`object`&&!(`required`in e.node)){let t=Object.keys(e.node.properties);t.length>0&&(e.node.required=t)}}})},ju=(e,t)=>{if(e===t)return!0;if(e===null||t===null)return e===t;let n=typeof e;if(n!==typeof t||n!==`object`)return!1;if(Array.isArray(e)||Array.isArray(t)){if(!Array.isArray(e)||!Array.isArray(t)||e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(!ju(e[n],t[n]))return!1;return!0}let r=e,i=t,a=Object.keys(r).sort(),o=Object.keys(i).sort();if(a.length!==o.length)return!1;for(let e=0;e<a.length;e++)if(a[e]!==o[e])return!1;for(let e of a)if(!ju(r[e],i[e]))return!1;return!0};var Mu=ju;const Nu=e=>{for(let[,t]of e)if(!t.scopes&&t.parentPointer){let n=e.get(t.parentPointer);n?.scopes&&(t.scopes=new Set(n.scopes))}},Pu=({cache:e,graph:t,pointer:n,visited:r})=>{let i=e.transitiveDependencies.get(n);if(i)return{subtreeDependencies:e.subtreeDependencies.get(n),transitiveDependencies:i};if(r.has(n)||(r.add(n),!t.nodes.get(n)))return{subtreeDependencies:new Set,transitiveDependencies:new Set};let a=new Set,o=new Set,s=t.nodeDependencies.get(n);if(s)for(let n of s){a.add(n),o.add(n);let i=Pu({cache:e,graph:t,pointer:n,visited:r});for(let e of i.transitiveDependencies)a.add(e)}let c=e.parentToChildren.get(n)??[];for(let n of c){let i={subtreeDependencies:e.subtreeDependencies.get(n),transitiveDependencies:e.transitiveDependencies.get(n)};(!i.subtreeDependencies||!i.transitiveDependencies)&&(i=Pu({cache:e,graph:t,pointer:n,visited:r}),e.transitiveDependencies.set(n,i.transitiveDependencies),e.subtreeDependencies.set(n,i.subtreeDependencies));for(let e of i.transitiveDependencies)a.add(e);for(let e of i.subtreeDependencies)o.add(e)}return e.transitiveDependencies.set(n,a),e.subtreeDependencies.set(n,o),{subtreeDependencies:o,transitiveDependencies:a}},Fu=e=>{let t=new Set(Array.from(e.nodes.entries()).filter(([,e])=>e.scopes&&e.scopes.size>0).map(([e])=>e)),n=(n,r,i)=>{r.parentPointer&&t.add(r.parentPointer);let a=e.reverseNodeDependencies.get(n);if(a)for(let e of a)t.add(e);if(i){let e=i.match(/(.*)\/(allOf|anyOf|oneOf)\/\d+$/);if(e){let n=e[1];n&&t.add(n)}}},r=(t,r,i)=>{if(!r?.scopes)return;let a=e.nodes.get(i);a?.scopes&&Iu(a,r)&&n(t,r,i)};for(;t.size>0;){let i=t.values().next().value;t.delete(i);let a=e.nodes.get(i);if(!a)continue;a.scopes||=new Set;let o=a.node;for(let[e,t]of gu){if(!o||typeof o!=`object`||!(e in o))continue;let n=o[e];if(t===`array`&&n instanceof Array)for(let t=0;t<n.length;t++)r(i,a,`${i}/${e}/${t}`);else if(t===`objectMap`&&typeof n==`object`&&n&&!(n instanceof Array))for(let t of Object.keys(n))r(i,a,`${i}/${e}/${t}`);else if(t===`single`&&typeof n==`object`&&n)r(i,a,`${i}/${e}`);else if(t===`singleOrArray`)if(n instanceof Array)for(let t=0;t<n.length;t++)r(i,a,`${i}/${e}/${t}`);else typeof n==`object`&&n&&r(i,a,`${i}/${e}`)}let s=e.nodeDependencies.get(i);if(s)for(let t of s){let r=e.nodes.get(t);r?.scopes&&Iu(r,a)&&n(i,a)}if(a.parentPointer){let t=e.nodes.get(a.parentPointer);t&&Iu(a,t)&&n(a.parentPointer,t)}}},Iu=(e,t)=>{if(!e.scopes)return!1;t.scopes||=new Set;let n=!1;for(let r of e.scopes)t.scopes.has(r)||(t.scopes.add(r),n=!0);return n},Lu=e=>{for(let[t,n]of e){let{node:e}=n;typeof e!=`object`||!e||e instanceof Array||(`readOnly`in e&&e.readOnly===!0?n.scopes=new Set([`read`]):`writeOnly`in e&&e.writeOnly===!0?n.scopes=new Set([`write`]):t.match(/\/properties\/[^/]+$/)&&(n.scopes=new Set([`normal`])))}},Ru=(e,t)=>{let n=t.timeEvent(`build-graph`),r={nodeDependencies:new Map,nodes:new Map,reverseNodeDependencies:new Map,subtreeDependencies:new Map,transitiveDependencies:new Map},i=({key:e,node:t,parentPointer:n,path:a})=>{if(typeof t!=`object`||!t)return;let o=ji(a),s,c;if(typeof t==`object`&&t){if(`deprecated`in t&&typeof t.deprecated==`boolean`&&(s=!!t.deprecated),`$ref`in t&&typeof t.$ref==`string`){let e=Ai(t.$ref);r.nodeDependencies.has(o)||r.nodeDependencies.set(o,new Set),r.nodeDependencies.get(o).add(e)}`tags`in t&&t.tags instanceof Array&&(c=new Set(t.tags.filter(e=>typeof e==`string`)))}if(r.nodes.set(o,{deprecated:s,key:e,node:t,parentPointer:n,tags:c}),t instanceof Array)t.forEach((e,t)=>i({key:t,node:e,parentPointer:o,path:[...a,t]}));else for(let[e,n]of Object.entries(t))i({key:e,node:n,parentPointer:o,path:[...a,e]})};i({key:null,node:e,parentPointer:null,path:[]});let a={parentToChildren:new Map,subtreeDependencies:new Map,transitiveDependencies:new Map};for(let[e,t]of r.nodes){let n=t.parentPointer;n&&(a.parentToChildren.has(n)||a.parentToChildren.set(n,[]),a.parentToChildren.get(n).push(e))}for(let[e,t]of r.nodeDependencies)for(let n of t)r.reverseNodeDependencies.has(n)||r.reverseNodeDependencies.set(n,new Set),r.reverseNodeDependencies.get(n).add(e);Lu(r.nodes),Fu(r),Nu(r.nodes);for(let e of r.nodes.keys()){let t=Pu({cache:a,graph:r,pointer:e,visited:new Set});r.transitiveDependencies.set(e,t.transitiveDependencies),r.subtreeDependencies.set(e,t.subtreeDependencies)}return n.timeEnd(),{graph:r}},zu=new Set([`additionalProperties`,`allOf`,`anyOf`,`items`,`not`,`oneOf`,`patternProperties`,`properties`,`schema`]),Bu=e=>{if(e.length===3&&e[0]===`components`){let t=e[1];if(t===`parameters`||t===`requestBodies`)return`write`;if(t===`responses`||t===`headers`)return`read`}if(e.length===2){let t=e[0];if(t===`parameters`)return`write`;if(t===`responses`)return`read`}},Vu=(e,t)=>{let n=t.timeEvent(`capture-original-schemas`),r={};if(vu(e))for(let[t,n]of Object.entries(e.components.schemas))r[`#/components/schemas/${t}`]=n;else if(yu(e))for(let[t,n]of Object.entries(e.definitions))r[`#/definitions/${t}`]=n;return n.timeEnd(),r},Hu=({logger:e,spec:t,split:n})=>{let r=e.timeEvent(`insert-split-schemas-into-spec`);vu(t)?Object.assign(t.components.schemas,n.schemas):yu(t)&&Object.assign(t.definitions,n.schemas),r.timeEnd()},Uu=(e,t,n)=>{if(t&&typeof t==`object`){if(`$ref`in t&&typeof t.$ref==`string`){let r=e.nodes.get(t.$ref);if(r?.scopes&&(n===`writeOnly`&&r.scopes.size===1&&r.scopes.has(`write`)||n===`readOnly`&&r.scopes.size===1&&r.scopes.has(`read`))&&(delete t.$ref,!gu.some(([e])=>e in t)))return!0}for(let[r,i]of gu){if(!(r in t))continue;let a=t[r];if(i===`array`&&a instanceof Array){for(let t=a.length-1;t>=0;t--){let r=a[t];(r&&typeof r==`object`&&r[n]===!0||Uu(e,r,n))&&a.splice(t,1)}a.length||delete t[r]}else if(i===`objectMap`&&typeof a==`object`&&a&&!(a instanceof Array)){let i=a,o=new Set;for(let t of Object.keys(i)){let a=i[t];(a&&typeof a==`object`&&a[n]===!0||Uu(e,a,n))&&(delete i[t],r===`properties`&&o.add(t))}if(o.size>0&&r===`properties`&&`required`in t&&Array.isArray(t.required)){let e=t.required.filter(e=>!o.has(e));e.length?t.required=e:delete t.required}Object.keys(i).length||delete t[r]}else if(i===`single`&&typeof a==`object`&&a)(a[n]===!0||Uu(e,a,n))&&delete t[r];else if(i===`singleOrArray`)if(a instanceof Array){for(let t=a.length-1;t>=0;t--){let r=a[t];(r&&typeof r==`object`&&r[n]===!0||Uu(e,r,n))&&a.splice(t,1)}a.length||delete t[r]}else typeof a==`object`&&a&&(a[n]===!0||Uu(e,a,n))&&delete t[r]}if(t.type===`object`&&!gu.some(([e])=>e in t))return!0}return!1},Wu=({logger:e,originalSchemas:t,spec:n,split:r})=>{let i=e.timeEvent(`remove-original-split-schemas`),a=_u(n);for(let e of Object.keys(r.mapping)){let n=ki(e),r=n[n.length-1];typeof r==`string`&&a&&Object.prototype.hasOwnProperty.call(a,r)&&a[r]===t[e]&&delete a[r]}i.timeEnd()},Gu=({config:e,graph:t,logger:n,spec:r})=>{let i=n.timeEvent(`split-schemas`),a=new Set,o={mapping:{},reverseMapping:{},schemas:{}},s=Cu(r),c=s.split(`/`).length-1,l=e=>{if(e.startsWith(s)){let t=ki(e);if(t.length===c)return t[c-1]||``}return``};for(let e of t.nodes.keys()){let t=l(e);t&&a.add(t)}for(let[n,r]of t.nodes){let i=l(n);if(!i||!(r.scopes?.has(`read`)||r.scopes?.has(`write`))||!r.scopes?.has(`normal`))continue;let c=hu(r.node);Uu(t,c,`writeOnly`);let u=b({config:e.responses,name:i}),d=u===i?u:xu({base:u,components:a});a.add(d),o.schemas[d]=c;let f=`${s}${d}`,p=hu(r.node);Uu(t,p,`readOnly`);let m=t.transitiveDependencies.get(n)||new Set;if(!Array.from(m).some(e=>{let n=t.nodes.get(e);return n?.scopes?.has(`normal`)&&(n.scopes.has(`read`)||n.scopes.has(`write`))})&&Mu(c,p)&&Mu(c,r.node))continue;let h=b({config:e.requests,name:i}),g=h===i&&h!==d?h:xu({base:h,components:a});a.add(g),o.schemas[g]=p;let ee=`${s}${g}`;o.mapping[n]={read:f,write:ee},o.reverseMapping[f]=n,o.reverseMapping[ee]=n}return i.timeEnd(),o},Ku=({logger:e,spec:t,split:n})=>{let r=e.timeEvent(`update-refs-in-spec`),i=Cu(t),a=({context:e,currentPointer:t,inSchema:r,node:o,path:s,visited:c=new Set})=>{if(o instanceof Array)o.forEach((n,i)=>a({context:e,currentPointer:t,inSchema:r,node:n,path:[...s,i],visited:c}));else if(o&&typeof o==`object`){let l=t,u=e;if(Su(s)){l=`${i}${s[s.length-1]}`;let e=n.reverseMapping[l];if(e){let t=n.mapping[e];t?.read===l?u=`read`:t?.write===l&&(u=`write`)}}let d=Bu(s);if(d!==void 0){for(let e in o)Object.prototype.hasOwnProperty.call(o,e)&&a({context:d,currentPointer:l,inSchema:!1,node:o[e],path:[...s,e],visited:c});return}for(let e in o){if(!Object.prototype.hasOwnProperty.call(o,e))continue;let t=o[e];if(!r){if(e===`requestBody`){a({context:`write`,currentPointer:l,inSchema:!1,node:t,path:[...s,e],visited:c});continue}if(e===`responses`){a({context:`read`,currentPointer:l,inSchema:!1,node:t,path:[...s,e],visited:c});continue}if(e===`parameters`&&Array.isArray(t)){t.forEach((t,n)=>{t&&typeof t==`object`&&`schema`in t&&a({context:`write`,currentPointer:l,inSchema:!0,node:t.schema,path:[...s,e,n,`schema`],visited:c}),t&&typeof t==`object`&&`content`in t&&a({context:`write`,currentPointer:l,inSchema:!1,node:t.content,path:[...s,e,n,`content`],visited:c})});continue}if(e===`headers`&&typeof t==`object`&&t){for(let n in t)Object.prototype.hasOwnProperty.call(t,n)&&a({context:`read`,currentPointer:l,inSchema:!1,node:t[n],path:[...s,e,n],visited:c});continue}}if(zu.has(e))a({context:u,currentPointer:l,inSchema:!0,node:t,path:[...s,e],visited:c});else if(e===`$ref`&&typeof t==`string`){let r=n.mapping[t];r&&(u===`read`&&r.read?o[e]=r.read:u===`write`&&r.write?o[e]=r.write:!u&&r.read&&(o[e]=r.read))}else a({context:u,currentPointer:l,inSchema:r,node:t,path:[...s,e],visited:c})}}};a({context:null,currentPointer:null,inSchema:!1,node:t,path:[]}),r.timeEnd()},qu=({config:e,logger:t,spec:n})=>{let{graph:r}=Ru(n,t),i=Vu(n,t),a=Gu({config:e,graph:r,logger:t,spec:n});Hu({logger:t,spec:n,split:a}),Ku({logger:t,spec:n,split:a}),Wu({logger:t,originalSchemas:i,spec:n,split:a})},Ju=({context:e})=>{let{logger:t}=e,n=t.timeEvent(`transform-openapi-spec`);e.config.parser.transforms.enums.enabled&&Ou({config:e.config.parser.transforms.enums,spec:e.spec}),e.config.parser.transforms.propertiesRequiredByDefault&&Au({spec:e.spec}),e.config.parser.transforms.readWrite.enabled&&qu({config:e.config.parser.transforms.readWrite,logger:t,spec:e.spec}),n.timeEnd()},Y=({source:e,target:t})=>{let n={...t};if(e&&(e.cookie&&(n.cookie?n.cookie={...n.cookie,...e.cookie}:n.cookie=e.cookie),e.header&&(n.header?n.header={...n.header,...e.header}:n.header=e.header),e.path&&(n.path?n.path={...n.path,...e.path}:n.path=e.path),e.query&&(n.query?n.query={...n.query,...e.query}:n.query=e.query)),Object.keys(n).length)return n},Yu=e=>/^[A-Za-z_$][A-Za-z0-9_$]*$/.test(e),Xu=e=>e.map((e,t)=>typeof e==`number`?`[${e}]`:t===0?e:Yu(e)?`.${e}`:`['${e.replace(/"/g,`\\'`)}']`).join(``),Zu=e=>{let t=Xu(e.path),n=e.severity===`error`?u.bold.red:u.bold.yellow,r=e.message.replace(/`([^`]+)`/g,(e,t)=>u.yellow(`\`${t}\``));return`${n(`[${e.severity.toUpperCase()}]`)} ${u.cyan(t)}: ${r}`},Qu=({context:e,issue:t})=>e.config.logs.level===`silent`?!1:t.severity===`error`?e.config.logs.level!==`warn`:!0,$u=({context:e,result:t})=>{for(let n of t.issues)Qu({context:e,issue:n})&&console.log(Zu(n));t.valid||process.exit(1)},ed=({logger:e,operations:t,preserveOrder:n,schemas:r,spec:i})=>{let a=e.timeEvent(`filter-spec`);if(i.definitions){let e={};if(n)for(let[t,n]of Object.entries(i.definitions))r.has(K(`schema`,t))&&(e[t]=n);else for(let t of r){let{name:n}=q(t),r=i.definitions[n];r&&(e[n]=r)}i.definitions=e}if(i.paths)for(let e of Object.entries(i.paths)){let n=e[0],r=e[1];for(let e of G){if(!r[e])continue;let i=K(`operation`,C({method:e,path:n}));t.has(i)||delete r[e]}Object.keys(r).length||delete i.paths[n]}a.timeEnd()},td=/^(application\/(pdf|rtf|msword|vnd\.(ms-|openxmlformats-officedocument\.)|zip|x-(7z|tar|rar|zip|iso)|octet-stream|gzip|x-msdownload|json\+download|xml|x-yaml|x-7z-compressed|x-tar)|text\/(yaml|css|javascript)|audio\/(mpeg|wav)|video\/(mp4|x-matroska)|image\/(vnd\.adobe\.photoshop|svg\+xml))(; ?charset=[^;]+)?$/i,nd=/^application\/(.*\+)?json(;.*)?$/i,rd=/^multipart\/form-data(;.*)?$/i,id=/^text\/[a-z0-9.+-]+(;.*)?$/i,ad=/^application\/x-www-form-urlencoded(;.*)?$/i,od=/^application\/octet-stream(;.*)?$/i,sd=({mediaType:e})=>(td.lastIndex=0,td.test(e)),cd=({mediaType:e})=>{if(nd.lastIndex=0,nd.test(e))return`json`;if(rd.lastIndex=0,rd.test(e))return`form-data`;if(id.lastIndex=0,id.test(e))return`text`;if(ad.lastIndex=0,ad.test(e))return`url-search-params`;if(od.lastIndex=0,od.test(e))return`octet-stream`},ld=({content:e})=>{let{mediaType:t,schema:n}=e;return n&&`$ref`in n?{allOf:[{...n}]}:n?n.type===`string`&&!n.format&&sd({mediaType:t})?{...n,format:`binary`}:n:sd({mediaType:t})?{format:`binary`,type:`string`}:void 0},ud=({mimeTypes:e,response:t})=>{let n=[];for(let r of e??[])n.push({mediaType:r,schema:t.schema,type:cd({mediaType:r})});return n};function dd(e){let t=`^(${e.keywords.join(`|`)})$`;return new RegExp(t)}const fd=(e,t,n)=>{let r=[];for(let n in t)t[n]===e&&r.push(n);return!r.length&&(!n||n())?[F(e)]:r},pd=({schema:e})=>{if(e.type)return e.type;if(e.properties)return`object`},md=({irSchema:e,schema:t})=>{t.example&&(e.example=t.example),t.description&&(e.description=t.description),t.title&&(e.title=t.title)},hd=({irSchema:e,schema:t})=>{t.default!==void 0&&(e.default=t.default),t.exclusiveMaximum?t.maximum!==void 0&&(e.exclusiveMaximum=t.maximum):t.maximum!==void 0&&(e.maximum=t.maximum),t.exclusiveMinimum?t.minimum!==void 0&&(e.exclusiveMinimum=t.minimum):t.minimum!==void 0&&(e.minimum=t.minimum),t.format&&(e.format=t.format),t.maxItems!==void 0&&(e.maxItems=t.maxItems),t.maxLength!==void 0&&(e.maxLength=t.maxLength),t.minItems!==void 0&&(e.minItems=t.minItems),t.minLength!==void 0&&(e.minLength=t.minLength),t.pattern&&(e.pattern=t.pattern),t.readOnly&&(e.accessScope=`read`)},gd=({context:e,irSchema:t={},schema:n,state:r})=>{n.maxItems&&n.maxItems===n.minItems?t.type=`tuple`:t.type=`array`;let i=[];if(n.items){let a=X({context:e,schema:n.items,state:r});if(!i.length&&n.maxItems&&n.maxItems===n.minItems)i=Array(n.maxItems).fill(a);else if(`$ref`in n.items)i.push(a);else{let e=n.items.allOf;e&&e.length>1&&!n.items[`x-nullable`]?t={...t,...a}:i.push(a)}}return t=S({items:i,schema:t}),t},_d=({irSchema:e={}})=>(e.type=`boolean`,e),vd=({irSchema:e={},schema:t})=>(e.type=t.type,e),yd=({context:e,irSchema:t={},schema:n,state:r})=>{t.type=`object`;let i={};for(let t in n.properties){let a=n.properties[t];typeof a==`boolean`||(i[t]=X({context:e,schema:a,state:r}))}return Object.keys(i).length&&(t.properties=i),n.additionalProperties===void 0?t.properties||(t.additionalProperties={type:`unknown`}):typeof n.additionalProperties==`boolean`?r.inAllOf&&n.additionalProperties===!1&&(!n.properties||!Object.keys(n.properties).length)||(t.additionalProperties={type:n.additionalProperties?`unknown`:`never`}):t.additionalProperties=X({context:e,schema:n.additionalProperties,state:r}),n.required&&(t.required=n.required),t},bd=({irSchema:e={}})=>(e.type=`string`,e),xd=({schema:e})=>{let t={};return md({irSchema:t,schema:e}),t},Sd=({context:e,schema:t,state:n})=>{let r=xd({schema:t}),i=[],a=pd({schema:t}),o=t.allOf;for(let r of o){let a=n.inAllOf;`$ref`in r||(n.inAllOf=!0);let o=X({context:e,schema:r,state:n});if(n.inAllOf=a,n.inAllOf===void 0&&delete n.inAllOf,t.required&&(o.required?o.required=[...o.required,...t.required]:o.required=t.required),i.push(o),r.$ref){let t=e.resolveRef(r.$ref);if(t.discriminator&&n.$ref){let e=fd(n.$ref).map(e=>({const:e,type:`string`})),r={properties:{[t.discriminator]:e.length>1?{items:e,logicalOperator:`or`}:e[0]},type:`object`};t.required?.includes(t.discriminator)&&(r.required=[t.discriminator]),i.push(r)}}}if(a===`object`){let r=Dd({context:e,schema:{...t,type:`object`},state:n});if(r.properties){for(let t of r.required??[])if(!r.properties[t])for(let i of o){let a=i.$ref?e.resolveRef(i.$ref):i;if(pd({schema:a})===`object`){let i=Dd({context:e,schema:{...a,type:`object`},state:n});if(i.properties?.[t]){r.properties[t]=i.properties[t];break}}}i.push(r)}}if(r=S({items:i,logicalOperator:`and`,mutateSchemaOneItem:!0,schema:r}),t[`x-nullable`]){let e=[{type:`null`}];i.length&&e.unshift(r),r={items:e,logicalOperator:`or`},e[0].deprecated&&(r.deprecated=e[0].deprecated),e[0].description&&(r.description=e[0].description)}return r},Cd=({context:e,schema:t,state:n})=>{let r=xd({schema:t});r.type=`enum`;let i=[];for(let[r,a]of t.enum.entries()){let o=typeof a,s;if(o===`string`||o===`number`||o===`boolean`?s=o:o===`object`&&Array.isArray(a)?s=`array`:a===null?t[`x-nullable`]&&(s=`null`):console.warn(`🚨`,`unhandled "${o}" typeof value "${a}" for enum`,t.enum),!s)continue;let c=Dd({context:e,schema:{description:t[`x-enum-descriptions`]?.[r],title:t[`x-enum-varnames`]?.[r]??t[`x-enumNames`]?.[r],type:s===`null`?`string`:s},state:n});c.const=a,s===`null`&&(c.type=s),c.type===`array`&&(c.type=`tuple`),i.push(c)}return r=S({items:i,schema:r}),r},wd=({context:e,schema:t,state:n})=>{let r={};if(!t.$ref.startsWith(`#/definitions/`)&&!n.circularReferenceTracker.has(t.$ref)){let r=e.resolveRef(t.$ref),i=n.$ref;n.$ref=t.$ref;let a=X({context:e,schema:r,state:n});return n.$ref=i,a}if(r.$ref=decodeURI(t.$ref),r.$ref=r.$ref.replace(/#\/definitions\/([^/]+)/g,`#/components/schemas/$1`),!n.circularReferenceTracker.has(t.$ref)){let r=e.resolveRef(t.$ref),i=n.$ref;n.$ref=t.$ref,X({context:e,schema:r,state:n}),n.$ref=i}return r},Td=({context:e,irSchema:t,schema:n,state:r})=>{t||=xd({schema:n});let i={};return hd({irSchema:i,schema:n}),i.default===null&&delete i.default,t=S({items:[Dd({context:e,irSchema:i,schema:n,state:r}),{type:`null`}],schema:t}),t},Ed=({context:e,schema:t,state:n})=>{let r=xd({schema:t});hd({irSchema:r,schema:t});let i=pd({schema:t});return i?t[`x-nullable`]?Td({context:e,irSchema:r,schema:{...t,type:i},state:n}):Dd({context:e,irSchema:r,schema:{...t,type:i},state:n}):r},Dd=({context:e,irSchema:t,schema:n,state:r})=>{switch(t||(t=xd({schema:n}),hd({irSchema:t,schema:n})),n.type){case`array`:return gd({context:e,irSchema:t,schema:n,state:r});case`boolean`:return _d({context:e,irSchema:t,schema:n,state:r});case`integer`:case`number`:return vd({context:e,irSchema:t,schema:n,state:r});case`object`:return yd({context:e,irSchema:t,schema:n,state:r});case`string`:return bd({context:e,irSchema:t,schema:n,state:r});default:return Od({context:e,irSchema:t,schema:n})}},Od=({irSchema:e,schema:t})=>(e||=xd({schema:t}),e.type=`unknown`,hd({irSchema:e,schema:t}),e),X=({context:e,schema:t,state:n})=>(n||={circularReferenceTracker:new Set},n.$ref&&n.circularReferenceTracker.add(n.$ref),t.$ref?wd({context:e,schema:t,state:n}):t.enum?Cd({context:e,schema:t,state:n}):t.allOf?Sd({context:e,schema:t,state:n}):t.type||t.properties?Ed({context:e,schema:t,state:n}):Od({context:e,schema:t})),kd=({$ref:e,context:t,schema:n})=>{t.ir.components||(t.ir.components={}),t.ir.components.schemas||(t.ir.components.schemas={}),t.ir.components.schemas[F(e)]=X({context:t,schema:n,state:{$ref:e,circularReferenceTracker:new Set}})},Ad=e=>e===`boolean`||e===`integer`||e===`number`||e===`string`,jd=({context:e,name:t,schema:n})=>{if(dd(e.config.parser.pagination).test(t))return!0;if(`$ref`in n){let r=e.resolveRef(n.$ref??``);return`in`in r&&r.in?jd({context:e,name:t,schema:`schema`in r?r.schema:{...r,in:void 0}}):jd({context:e,name:t,schema:r})}if(`in`in n)return n.in?jd({context:e,name:t,schema:`schema`in n?n.schema:{...n,in:void 0}}):!1;for(let t in n.properties)if(dd(e.config.parser.pagination).test(t)){let e=n.properties[t];if(typeof e!=`boolean`&&!(`$ref`in e)&&Ad(pd({schema:e})))return t}for(let r of n.allOf??[]){let n=jd({context:e,name:t,schema:r});if(n)return n}return!1},Md=({irOperation:e,operation:t})=>{t.deprecated!==void 0&&(e.deprecated=t.deprecated),t.description&&(e.description=t.description),t.summary&&(e.summary=t.summary),t.tags?.length&&(e.tags=t.tags)},Nd=({context:e,method:t,operation:n,path:r,state:i})=>{let a={id:Yl({context:e,id:n.operationId,method:t,path:r,state:i}),method:t,path:r};return n.operationId&&(a.operationId=n.operationId),Md({irOperation:a,operation:n}),a},Pd=({context:e,method:t,operation:n,path:r,securitySchemesMap:i,state:a})=>{let o=Nd({context:e,method:t,operation:n,path:r,state:a});n.parameters&&(o.parameters=n.parameters);let s=!1,c={mediaType:``,schema:{properties:{},required:[],type:`object`}},l=[],u=n.requestBody?.some(t=>(`$ref`in t?e.resolveRef(t.$ref):t).in===`body`);for(let t of n.requestBody??[]){let r=`$ref`in t?e.resolveRef(t.$ref):t,i=r.in===`body`?r.schema:{...r,format:r.type===`file`?`binary`:r.format,required:void 0,type:r.type===`file`?`string`:r.type},a=n.consumes;!a&&u&&r.in===`body`&&(a=[`application/json`]);let o=ud({mimeTypes:a,response:{schema:i}}),d=o.find(e=>e.type===`json`)||o[0];if(d){let t=jd({context:e,name:``,schema:d.schema&&`$ref`in d.schema?{allOf:[{...d.schema}],description:r.description}:{description:r.description,...d.schema}}),n=X({context:e,schema:`$ref`in r?{allOf:[{...r,$ref:r.$ref,required:[],type:`string`}],description:r.description}:d.schema&&`$ref`in d.schema?{allOf:[{...d.schema}],description:r.description}:{description:r.description,...d.schema},state:void 0});c.mediaType=d.mediaType,r.in===`body`?c.schema=n:(c.schema.properties[r.name]=n,r.required&&l.push(r.name)),t&&(c.pagination=t),d.type&&(c.type=d.type)}r.required&&(s=!0)}for(let t in c.mediaType&&(l.length&&(c.schema.required=l),o.body=c,s&&(o.body.required=s)),n.responses){o.responses||={};let r=n.responses[t],i=`$ref`in r?e.resolveRef(r.$ref):r,a=ud({mimeTypes:n.produces?n.produces:[`application/json`],response:i}),s=a.find(e=>e.type===`json`)||a[0];s?o.responses[t]={mediaType:s.mediaType,schema:X({context:e,schema:{description:i.description,...ld({content:s})},state:void 0})}:o.responses[t]={schema:{description:i.description,type:t===`204`?`void`:`unknown`}}}if(n.security){let e=new Map;for(let t of n.security)for(let n in t){let t=i.get(n);if(!t)continue;let r;if(t.type===`apiKey`&&(r=t),t.type===`basic`&&(r={description:t.description,scheme:`basic`,type:`http`}),t.type===`oauth2`)switch(r={description:t.description,flows:{},type:`oauth2`},t.flow){case`accessCode`:r.flows.authorizationCode={authorizationUrl:t.authorizationUrl,scopes:t.scopes,tokenUrl:t.tokenUrl};break;case`application`:r.flows.clientCredentials={scopes:t.scopes,tokenUrl:t.tokenUrl};break;case`implicit`:r.flows.implicit={authorizationUrl:t.authorizationUrl,scopes:t.scopes};break;case`password`:r.flows.password={scopes:t.scopes,tokenUrl:t.tokenUrl};break}r&&e.set(n,r)}e.size&&(o.security=Array.from(e.values()))}return o},Fd=({context:e,method:t,operation:n,path:r,securitySchemesMap:i,state:a})=>{e.ir.paths||(e.ir.paths={}),e.ir.paths[r]||(e.ir.paths[r]={}),e.ir.paths[r][t]=Pd({context:e,method:t,operation:n,path:r,securitySchemesMap:i,state:a})},Id=e=>{switch(e){case`multi`:return!0;case`csv`:case`pipes`:case`ssv`:case`tsv`:default:return!1}},Ld=e=>{switch(e){case`header`:case`path`:return`simple`;case`query`:default:return`form`}},Rd=({context:e,operation:t,parameters:n})=>{if(!n||!Object.keys(n).length)return;let r={};for(let i of n){let n=`$ref`in i?e.dereference(i):i;if(n.in===`body`||n.in===`formData`){t.requestBody||=[],t.requestBody.push(n);continue}r[n.in]||(r[n.in]={}),r[n.in][n.name.toLocaleLowerCase()]=zd({$ref:`#/todo/real/path/to/parameter/${n.name}`,context:e,parameter:n})}return r},zd=({$ref:e,context:t,parameter:n})=>{let r=n,i=r&&`$ref`in r?{allOf:[{...r,$ref:r.$ref,required:Array.isArray(r.required)?r.required:[],type:r.type}],description:n.description}:{description:n.description,...r,required:Array.isArray(r.required)?r.required:[],type:r.type},a=jd({context:t,name:n.name,schema:i}),o=Ld(n.in),s={allowReserved:!1,explode:Id(n.collectionFormat),location:n.in,name:n.name,schema:X({context:t,schema:i,state:{$ref:e,circularReferenceTracker:new Set}}),style:o};return n.description&&(s.description=n.description),a&&(s.pagination=a),n.required&&(s.required=n.required),s},Bd=({context:e})=>{let t=e.spec.schemes??[],n=e.spec.host??``,r=e.spec.basePath??``;for(let r of e.config.input)if(typeof r.path==`string`){let e=ma(r.path);t.length||e.protocol&&(t=[e.protocol]),n||=`${e.host}${e.port?`:${e.port}`:``}`}t.length||(t=[``]);let i=t.map(e=>`${e?`${e}://`:``}${n}${r}`).filter(Boolean);i.length&&(e.ir.servers=i.map(e=>({url:e})))},Vd=(e,t)=>{let n=t.timeEvent(`validate`),r=[],i=new Map;if(e.paths)for(let t of Object.entries(e.paths)){let e=t[0],n=t[1];for(let t of G){if(t===`trace`)continue;let a=n[t];if(!a)continue;let o=C({method:t,path:e});a.operationId&&(i.has(a.operationId)?r.push({code:`duplicate_key`,context:{key:`operationId`,value:a.operationId},message:"Duplicate `operationId` found. Each `operationId` must be unique.",path:[`paths`,e,t,`operationId`],severity:`error`}):i.set(a.operationId,o))}}return n.timeEnd(),{issues:r,valid:!r.some(e=>e.severity===`error`)}},Hd=e=>{if(e.config.parser.validate_EXPERIMENTAL&&$u({context:e,result:Vd(e.spec,e.logger)}),tu(e.config.parser.filters)){let t=eu(e.config.parser.filters,e.spec,e.logger),{graph:n}=Ru(e.spec,e.logger),{resourceMetadata:r}=mu(n,e.logger);ed({...pu({filters:t,logger:e.logger,resourceMetadata:r}),logger:e.logger,preserveOrder:t.preserveOrder,spec:e.spec})}Ju({context:e});let t={ids:new Map},n=new Map;for(let t in e.spec.securityDefinitions){let r=e.spec.securityDefinitions[t];n.set(t,r)}if(e.spec.definitions)for(let t in e.spec.definitions){let n=`#/definitions/${t}`,r=e.spec.definitions[t];kd({$ref:n,context:e,schema:r})}for(let r in Bd({context:e}),e.spec.paths){if(r.startsWith(`x-`))continue;let i=e.spec.paths[r],a=i.$ref?{...e.resolveRef(i.$ref),...i}:i,o={consumes:e.spec.consumes,produces:e.spec.produces,responses:{},security:e.spec.security},s={context:e,operation:{...o,parameters:Rd({context:e,operation:o,parameters:a.parameters})},path:r,securitySchemesMap:n,state:t};if(a.delete){let t=Y({source:Rd({context:e,operation:a.delete,parameters:a.delete.parameters}),target:s.operation.parameters});Fd({...s,method:`delete`,operation:{...s.operation,...a.delete,parameters:t}})}if(a.get){let t=Y({source:Rd({context:e,operation:a.get,parameters:a.get.parameters}),target:s.operation.parameters});Fd({...s,method:`get`,operation:{...s.operation,...a.get,parameters:t}})}if(a.head){let t=Y({source:Rd({context:e,operation:a.head,parameters:a.head.parameters}),target:s.operation.parameters});Fd({...s,method:`head`,operation:{...s.operation,...a.head,parameters:t}})}if(a.options){let t=Y({source:Rd({context:e,operation:a.options,parameters:a.options.parameters}),target:s.operation.parameters});Fd({...s,method:`options`,operation:{...s.operation,...a.options,parameters:t}})}if(a.patch){let t=Y({source:Rd({context:e,operation:a.patch,parameters:a.patch.parameters}),target:s.operation.parameters});Fd({...s,method:`patch`,operation:{...s.operation,...a.patch,parameters:t}})}if(a.post){let t=Y({source:Rd({context:e,operation:a.post,parameters:a.post.parameters}),target:s.operation.parameters});Fd({...s,method:`post`,operation:{...s.operation,...a.post,parameters:t}})}if(a.put){let t=Y({source:Rd({context:e,operation:a.put,parameters:a.put.parameters}),target:s.operation.parameters});Fd({...s,method:`put`,operation:{...s.operation,...a.put,parameters:t}})}}},Ud=({logger:e,operations:t,parameters:n,preserveOrder:r,requestBodies:i,responses:a,schemas:o,spec:s})=>{let c=e.timeEvent(`filter-spec`);if(s.components){if(s.components.parameters){let e={};if(r)for(let[t,r]of Object.entries(s.components.parameters))n.has(K(`parameter`,t))&&(e[t]=r);else for(let t of n){let{name:n}=q(t),r=s.components.parameters[n];r&&(e[n]=r)}s.components.parameters=e}if(s.components.requestBodies){let e={};if(r)for(let[t,n]of Object.entries(s.components.requestBodies))i.has(K(`body`,t))&&(e[t]=n);else for(let t of i){let{name:n}=q(t),r=s.components.requestBodies[n];r&&(e[n]=r)}s.components.requestBodies=e}if(s.components.responses){let e={};if(r)for(let[t,n]of Object.entries(s.components.responses))a.has(K(`response`,t))&&(e[t]=n);else for(let t of a){let{name:n}=q(t),r=s.components.responses[n];r&&(e[n]=r)}s.components.responses=e}if(s.components.schemas){let e={};if(r)for(let[t,n]of Object.entries(s.components.schemas))o.has(K(`schema`,t))&&(e[t]=n);else for(let t of o){let{name:n}=q(t),r=s.components.schemas[n];r&&(e[n]=r)}s.components.schemas=e}}if(s.paths)for(let e of Object.entries(s.paths)){let n=e[0],r=e[1];for(let e of G){if(!r[e])continue;let i=K(`operation`,C({method:e,path:n}));t.has(i)||delete r[e]}Object.keys(r).length||delete s.paths[n]}c.timeEnd()},Wd=({content:e})=>{let{mediaType:t,schema:n}=e;return n&&`$ref`in n?{allOf:[{...n}]}:n?n.type===`string`&&!n.format&&sd({mediaType:t})?{...n,format:`binary`}:n:sd({mediaType:t})?{format:`binary`,type:`string`}:void 0},Gd=({content:e})=>{let t=[];for(let n in e)t.push({mediaType:n,schema:e[n].schema,type:cd({mediaType:n})});return t},Kd=({schema:e})=>{if(e.type)return e.type;if(e.properties)return`object`},qd=({irSchema:e,schema:t})=>{t.deprecated!==void 0&&(e.deprecated=t.deprecated),t.example&&(e.example=t.example),t.description&&(e.description=t.description),t.title&&(e.title=t.title)},Jd=({irSchema:e,schema:t})=>{t.default!==void 0&&(e.default=t.default),t.exclusiveMaximum?t.maximum!==void 0&&(e.exclusiveMaximum=t.maximum):t.maximum!==void 0&&(e.maximum=t.maximum),t.exclusiveMinimum?t.minimum!==void 0&&(e.exclusiveMinimum=t.minimum):t.minimum!==void 0&&(e.minimum=t.minimum),t.format&&(e.format=t.format),t.maxItems!==void 0&&(e.maxItems=t.maxItems),t.maxLength!==void 0&&(e.maxLength=t.maxLength),t.minItems!==void 0&&(e.minItems=t.minItems),t.minLength!==void 0&&(e.minLength=t.minLength),t.pattern&&(e.pattern=t.pattern),t.readOnly?e.accessScope=`read`:t.writeOnly&&(e.accessScope=`write`)},Yd=({context:e,irSchema:t={},schema:n,state:r})=>{n.maxItems&&n.maxItems===n.minItems?t.type=`tuple`:t.type=`array`;let i=[];if(n.items){let a=Z({context:e,schema:n.items,state:r});if(!i.length&&n.maxItems&&n.maxItems===n.minItems)i=Array(n.maxItems).fill(a);else if(`$ref`in n.items)i.push(a);else{let e=n.items.allOf||n.items.anyOf||n.items.oneOf;e&&e.length>1&&!n.items.nullable?t={...t,...a}:i.push(a)}}return t=S({items:i,schema:t}),t},Xd=({irSchema:e={}})=>(e.type=`boolean`,e),Zd=({irSchema:e={},schema:t})=>(e.type=t.type,e),Qd=({context:e,irSchema:t={},schema:n,state:r})=>{t.type=`object`;let i={};for(let t in n.properties){let a=n.properties[t];typeof a==`boolean`||(i[t]=Z({context:e,schema:a,state:r}))}return Object.keys(i).length&&(t.properties=i),n.additionalProperties===void 0?t.properties||(t.additionalProperties={type:`unknown`}):typeof n.additionalProperties==`boolean`?r.inAllOf&&n.additionalProperties===!1&&(!n.properties||!Object.keys(n.properties).length)||(t.additionalProperties={type:n.additionalProperties?`unknown`:`never`}):t.additionalProperties=Z({context:e,schema:n.additionalProperties,state:r}),n.required&&(t.required=n.required),t},$d=({irSchema:e={}})=>(e.type=`string`,e),ef=({schema:e})=>{let t={};return qd({irSchema:t,schema:e}),t},tf=({context:e,schema:t,state:n})=>{let r=ef({schema:t}),i=[],a=Kd({schema:t}),o=t.allOf;for(let r of o){let a=n.inAllOf;`$ref`in r||(n.inAllOf=!0);let o=Z({context:e,schema:r,state:n});if(n.inAllOf=a,n.inAllOf===void 0&&delete n.inAllOf,t.required&&(o.required?o.required=[...o.required,...t.required]:o.required=t.required),i.push(o),`$ref`in r){let t=e.resolveRef(r.$ref);if(t.discriminator&&n.$ref){let e=fd(n.$ref,t.discriminator.mapping,t.oneOf?()=>t.oneOf.some(e=>`$ref`in e&&e.$ref===n.$ref):void 0);if(e.length>0){let n=e.map(e=>({const:e,type:`string`})),r={properties:{[t.discriminator.propertyName]:n.length>1?{items:n,logicalOperator:`or`}:n[0]},type:`object`};t.required?.includes(t.discriminator.propertyName)&&(r.required=[t.discriminator.propertyName]),i.push(r)}}}}if(a===`object`){let r=lf({context:e,schema:{...t,type:`object`},state:n});if(r.properties){for(let t of r.required??[])if(!r.properties[t])for(let i of o){let a=`$ref`in i?e.resolveRef(i.$ref):i;if(Kd({schema:a})===`object`){let i=lf({context:e,schema:{...a,type:`object`},state:n});if(i.properties?.[t]){r.properties[t]=i.properties[t];break}}}i.push(r)}}if(r=S({items:i,logicalOperator:`and`,mutateSchemaOneItem:!0,schema:r}),t.nullable){let e=[{type:`null`}];i.length&&e.unshift(r),r={items:e,logicalOperator:`or`},e[0].deprecated&&(r.deprecated=e[0].deprecated),e[0].description&&(r.description=e[0].description)}return r},nf=({context:e,schema:t,state:n})=>{let r=ef({schema:t}),i=[],a=Kd({schema:t}),o=t.anyOf;for(let r of o){let a=Z({context:e,schema:r,state:n});if(t.discriminator&&a.$ref!=null){let e=fd(a.$ref,t.discriminator.mapping).map(e=>({const:e,type:`string`}));a={items:[{properties:{[t.discriminator.propertyName]:e.length>1?{items:e,logicalOperator:`or`}:e[0]},type:`object`},a],logicalOperator:`and`}}i.push(a)}if(t.nullable&&i.push({type:`null`}),r=S({items:i,mutateSchemaOneItem:!0,schema:r}),a===`object`){let i=lf({context:e,schema:{...t,type:`object`},state:n});i.properties&&(r={items:[r,i],logicalOperator:`and`})}return r},rf=({context:e,schema:t,state:n})=>{let r=ef({schema:t});r.type=`enum`;let i=[];for(let[r,a]of t.enum.entries()){let o=typeof a,s;if(o===`string`||o===`number`||o===`boolean`?s=o:o===`object`&&Array.isArray(a)?s=`array`:a===null?t.nullable&&(s=`null`):console.warn(`🚨`,`unhandled "${o}" typeof value "${a}" for enum`,t.enum),!s)continue;let c=lf({context:e,schema:{description:t[`x-enum-descriptions`]?.[r],title:t[`x-enum-varnames`]?.[r]??t[`x-enumNames`]?.[r],type:s===`null`?`string`:s},state:n});c.const=a,s===`null`&&(c.type=s),c.type===`array`&&(c.type=`tuple`),i.push(c)}return r=S({items:i,schema:r}),r},af=({context:e,schema:t,state:n})=>{let r=ef({schema:t}),i=[],a=Kd({schema:t}),o=t.oneOf;for(let r of o){let a=Z({context:e,schema:r,state:n});if(t.discriminator&&a.$ref!=null){let e=fd(a.$ref,t.discriminator.mapping).map(e=>({const:e,type:`string`}));a={items:[{properties:{[t.discriminator.propertyName]:e.length>1?{items:e,logicalOperator:`or`}:e[0]},required:[t.discriminator.propertyName],type:`object`},a],logicalOperator:`and`}}a.logicalOperator===`or`&&a.type!==`array`&&a.items?i=i.concat(a.items):i.push(a)}if(t.nullable&&i.push({type:`null`}),r=S({items:i,mutateSchemaOneItem:!0,schema:r}),a===`object`){let i=lf({context:e,schema:{...t,type:`object`},state:n});i.properties&&(r={items:[r,i],logicalOperator:`and`})}return r},of=({context:e,schema:t,state:n})=>{if(!t.$ref.startsWith(`#/components/`)&&!n.circularReferenceTracker.has(t.$ref)){let r=e.resolveRef(t.$ref),i=n.$ref;n.$ref=t.$ref;let a=Z({context:e,schema:r,state:n});return n.$ref=i,a}let r={};if(r.$ref=decodeURI(t.$ref),!n.circularReferenceTracker.has(t.$ref)){let r=e.resolveRef(t.$ref),i=n.$ref;n.$ref=t.$ref,Z({context:e,schema:r,state:n}),n.$ref=i}return r},sf=({context:e,irSchema:t,schema:n,state:r})=>{t||=ef({schema:n});let i={};return Jd({irSchema:i,schema:n}),i.default===null&&delete i.default,t=S({items:[lf({context:e,irSchema:i,schema:n,state:r}),{type:`null`}],schema:t}),t},cf=({context:e,schema:t,state:n})=>{let r=ef({schema:t});Jd({irSchema:r,schema:t});let i=Kd({schema:t});return i?t.nullable?sf({context:e,irSchema:r,schema:{...t,type:i},state:n}):lf({context:e,irSchema:r,schema:{...t,type:i},state:n}):r},lf=({context:e,irSchema:t,schema:n,state:r})=>{switch(t||(t=ef({schema:n}),Jd({irSchema:t,schema:n})),n.type){case`array`:return Yd({context:e,irSchema:t,schema:n,state:r});case`boolean`:return Xd({context:e,irSchema:t,schema:n,state:r});case`integer`:case`number`:return Zd({context:e,irSchema:t,schema:n,state:r});case`object`:return Qd({context:e,irSchema:t,schema:n,state:r});case`string`:return $d({context:e,irSchema:t,schema:n,state:r});default:return uf({context:e,irSchema:t,schema:n})}},uf=({irSchema:e,schema:t})=>(e||=ef({schema:t}),e.type=`unknown`,Jd({irSchema:e,schema:t}),e),Z=({context:e,schema:t,state:n})=>(n||={circularReferenceTracker:new Set},n.$ref&&n.circularReferenceTracker.add(n.$ref),`$ref`in t?of({context:e,schema:t,state:n}):t.enum?rf({context:e,schema:t,state:n}):t.allOf?tf({context:e,schema:t,state:n}):t.anyOf?nf({context:e,schema:t,state:n}):t.oneOf?af({context:e,schema:t,state:n}):t.type||t.properties?cf({context:e,schema:t,state:n}):uf({context:e,schema:t})),df=({$ref:e,context:t,schema:n})=>{t.ir.components||(t.ir.components={}),t.ir.components.schemas||(t.ir.components.schemas={}),t.ir.components.schemas[F(e)]=Z({context:t,schema:n,state:{$ref:e,circularReferenceTracker:new Set}})},ff=e=>e===`boolean`||e===`integer`||e===`number`||e===`string`,pf=({context:e,name:t,schema:n})=>{if(dd(e.config.parser.pagination).test(t))return!0;if(`$ref`in n){let r=e.resolveRef(n.$ref);if(`content`in r||`in`in r){let n;if(`in`in r&&(n=r.schema),!n){let e=Gd({content:r.content}),t=e.find(e=>e.type===`json`)||e[0];t?.schema&&(n=t.schema)}return n?pf({context:e,name:t,schema:n}):!1}return pf({context:e,name:t,schema:r})}for(let t in n.properties)if(dd(e.config.parser.pagination).test(t)){let e=n.properties[t];if(typeof e!=`boolean`&&!(`$ref`in e)&&ff(Kd({schema:e})))return t}for(let r of n.allOf??[]){let n=pf({context:e,name:t,schema:r});if(n)return n}return!1},mf=({irOperation:e,operation:t})=>{t.deprecated!==void 0&&(e.deprecated=t.deprecated),t.description&&(e.description=t.description),t.summary&&(e.summary=t.summary),t.tags?.length&&(e.tags=t.tags)},hf=({context:e,method:t,operation:n,path:r,state:i})=>{let a={id:Yl({context:e,id:n.operationId,method:t,path:r,state:i}),method:t,path:r};return n.operationId&&(a.operationId=n.operationId),mf({irOperation:a,operation:n}),a},gf=({context:e,method:t,operation:n,path:r,securitySchemesMap:i,state:a})=>{let o=hf({context:e,method:t,operation:n,path:r,state:a});if(n.parameters&&(o.parameters=n.parameters),n.requestBody){let t=`$ref`in n.requestBody?e.resolveRef(n.requestBody.$ref):n.requestBody,r=Gd({content:t.content}),i=r.find(e=>e.type===`json`)||r[0];if(i){let r=pf({context:e,name:``,schema:i.schema&&`$ref`in i.schema?{allOf:[{...i.schema}],description:t.description}:{description:t.description,...i.schema}});o.body={mediaType:i.mediaType,schema:Z({context:e,schema:`$ref`in n.requestBody?{allOf:[{...n.requestBody}],description:t.description}:i.schema&&`$ref`in i.schema?{allOf:[{...i.schema}],description:t.description}:{description:t.description,...i.schema},state:void 0})},r&&(o.body.pagination=r),t.required&&(o.body.required=t.required),i.type&&(o.body.type=i.type)}}for(let t in n.responses){o.responses||={};let r=n.responses[t],i=`$ref`in r?e.resolveRef(r.$ref):r,a=Gd({content:i.content}),s=a.find(e=>e.type===`json`)||a[0];s?o.responses[t]={mediaType:s.mediaType,schema:Z({context:e,schema:{description:i.description,...Wd({content:s})},state:void 0})}:o.responses[t]={schema:{description:i.description,type:t===`204`?`void`:`unknown`}}}if(n.security){let e=new Map;for(let t of n.security)for(let n in t){let t=i.get(n);t&&e.set(n,t)}e.size&&(o.security=Array.from(e.values()))}return o},_f=({context:e,method:t,operation:n,path:r,securitySchemesMap:i,state:a})=>{e.ir.paths||(e.ir.paths={}),e.ir.paths[r]||(e.ir.paths[r]={}),n.servers&&(e.ir.servers=[...e.ir.servers??[],...n.servers]),e.ir.paths[r][t]=gf({context:e,method:t,operation:n,path:r,securitySchemesMap:i,state:a})},vf=e=>{switch(e){case`query`:return!1;default:return}},yf=e=>{switch(e){case`deepObject`:case`form`:return!0;default:return!1}},bf=e=>{switch(e){case`header`:case`path`:return`simple`;case`cookie`:case`query`:return`form`}},xf=({context:e,parameters:t})=>{if(!t||!Object.keys(t).length)return;let n={};for(let r of t){let t=`$ref`in r?e.dereference(r):r;n[t.in]||(n[t.in]={}),n[t.in][t.name.toLocaleLowerCase()]=Sf({$ref:`#/todo/real/path/to/parameter/${t.name}`,context:e,parameter:t})}return n},Sf=({$ref:e,context:t,parameter:n})=>{let r=n.schema;if(!r){let e=Gd({content:n.content}),t=e.find(e=>e.type===`json`)||e[0];t&&(r=t.schema)}let i=r&&`$ref`in r?{allOf:[{...r}],deprecated:n.deprecated,description:n.description}:{deprecated:n.deprecated,description:n.description,...r},a=pf({context:t,name:n.name,schema:i}),o=n.style||bf(n.in),s=n.explode===void 0?yf(o):n.explode,c={allowReserved:n.allowReserved===void 0?vf(n.in):n.allowReserved,explode:s,location:n.in,name:n.name,schema:Z({context:t,schema:i,state:{$ref:e,circularReferenceTracker:new Set}}),style:o};return n.deprecated&&(c.deprecated=n.deprecated),n.description&&(c.description=n.description),a&&(c.pagination=a),n.required&&(c.required=n.required),c},Cf=({$ref:e,context:t,parameter:n})=>{t.ir.components||(t.ir.components={}),t.ir.components.parameters||(t.ir.components.parameters={}),t.ir.components.parameters[F(e)]=Sf({$ref:e,context:t,parameter:n})},wf=({$ref:e,context:t,requestBody:n})=>{let r=Gd({content:n.content}),i=r.find(e=>e.type===`json`)||r[0],a=i?i.schema:void 0,o={schema:Z({context:t,schema:{description:n.description,...a},state:{$ref:e,circularReferenceTracker:new Set}})};return n.description&&(o.description=n.description),n.required&&(o.required=n.required),o},Tf=({$ref:e,context:t,requestBody:n})=>{t.ir.components||(t.ir.components={}),t.ir.components.requestBodies||(t.ir.components.requestBodies={}),t.ir.components.requestBodies[F(e)]=wf({$ref:e,context:t,requestBody:n})},Ef=({context:e})=>{if(e.spec.servers){e.ir.servers=e.spec.servers;return}for(let t of e.config.input)if(typeof t.path==`string`){let n=ma(t.path);e.ir.servers=[{url:`${n.protocol?`${n.protocol}://`:``}${n.host}${n.port?`:${n.port}`:``}`}]}e.ir.servers||(e.ir.servers=[{url:`/`}])},Df=(e,t)=>{let n=t.timeEvent(`validate`),r=[],i=new Map;if(e.paths)for(let t of Object.entries(e.paths)){let e=t[0],n=t[1];for(let t of G){let a=n[t];if(!a)continue;let o=C({method:t,path:e});a.operationId&&(i.has(a.operationId)?r.push({code:`duplicate_key`,context:{key:`operationId`,value:a.operationId},message:"Duplicate `operationId` found. Each `operationId` must be unique.",path:[`paths`,e,t,`operationId`],severity:`error`}):i.set(a.operationId,o))}}if(e.servers){(typeof e.servers!=`object`||!Array.isArray(e.servers))&&r.push({code:`invalid_type`,message:"`servers` must be an array.",path:[],severity:`error`});for(let t=0;t<e.servers.length;t++){let n=e.servers[t];!n||typeof n!=`object`?r.push({code:`invalid_type`,context:{actual:typeof n,expected:`object`},message:"Each entry in `servers` must be an object.",path:[`servers`,t],severity:`error`}):n.url||r.push({code:`missing_required_field`,context:{field:`url`},message:"Missing required field `url` in server object.",path:[`servers`,t],severity:`error`})}}return n.timeEnd(),{issues:r,valid:!r.some(e=>e.severity===`error`)}},Of=e=>{if(e.config.parser.validate_EXPERIMENTAL&&$u({context:e,result:Df(e.spec,e.logger)}),tu(e.config.parser.filters)){let t=eu(e.config.parser.filters,e.spec,e.logger),{graph:n}=Ru(e.spec,e.logger),{resourceMetadata:r}=mu(n,e.logger);Ud({...pu({filters:t,logger:e.logger,resourceMetadata:r}),logger:e.logger,preserveOrder:t.preserveOrder,spec:e.spec})}Ju({context:e});let t={ids:new Map},n=new Map;if(e.spec.components){for(let t in e.spec.components.securitySchemes){let r=e.spec.components.securitySchemes[t],i=`$ref`in r?e.resolveRef(r.$ref):r;n.set(t,i)}for(let t in e.spec.components.parameters){let n=`#/components/parameters/${t}`,r=e.spec.components.parameters[t];Cf({$ref:n,context:e,parameter:`$ref`in r?e.resolveRef(r.$ref):r})}for(let t in e.spec.components.requestBodies){let n=`#/components/requestBodies/${t}`,r=e.spec.components.requestBodies[t];Tf({$ref:n,context:e,requestBody:`$ref`in r?e.resolveRef(r.$ref):r})}for(let t in e.spec.components.schemas){let n=`#/components/schemas/${t}`,r=e.spec.components.schemas[t];df({$ref:n,context:e,schema:r})}}for(let r in Ef({context:e}),e.spec.paths){let i=e.spec.paths[r],a=i.$ref?{...e.resolveRef(i.$ref),...i}:i,o={context:e,operation:{description:a.description,parameters:xf({context:e,parameters:a.parameters}),security:e.spec.security,servers:a.servers,summary:a.summary},path:r,securitySchemesMap:n,state:t};a.delete&&_f({...o,method:`delete`,operation:{...o.operation,...a.delete,parameters:Y({source:xf({context:e,parameters:a.delete.parameters}),target:o.operation.parameters})}}),a.get&&_f({...o,method:`get`,operation:{...o.operation,...a.get,parameters:Y({source:xf({context:e,parameters:a.get.parameters}),target:o.operation.parameters})}}),a.head&&_f({...o,method:`head`,operation:{...o.operation,...a.head,parameters:Y({source:xf({context:e,parameters:a.head.parameters}),target:o.operation.parameters})}}),a.options&&_f({...o,method:`options`,operation:{...o.operation,...a.options,parameters:Y({source:xf({context:e,parameters:a.options.parameters}),target:o.operation.parameters})}}),a.patch&&_f({...o,method:`patch`,operation:{...o.operation,...a.patch,parameters:Y({source:xf({context:e,parameters:a.patch.parameters}),target:o.operation.parameters})}}),a.post&&_f({...o,method:`post`,operation:{...o.operation,...a.post,parameters:Y({source:xf({context:e,parameters:a.post.parameters}),target:o.operation.parameters})}}),a.put&&_f({...o,method:`put`,operation:{...o.operation,...a.put,parameters:Y({source:xf({context:e,parameters:a.put.parameters}),target:o.operation.parameters})}}),a.trace&&_f({...o,method:`trace`,operation:{...o.operation,...a.trace,parameters:Y({source:xf({context:e,parameters:a.trace.parameters}),target:o.operation.parameters})}})}},kf=({logger:e,operations:t,parameters:n,preserveOrder:r,requestBodies:i,responses:a,schemas:o,spec:s})=>{let c=e.timeEvent(`filter-spec`);if(s.components){if(s.components.parameters){let e={};if(r)for(let[t,r]of Object.entries(s.components.parameters))n.has(K(`parameter`,t))&&(e[t]=r);else for(let t of n){let{name:n}=q(t),r=s.components.parameters[n];r&&(e[n]=r)}s.components.parameters=e}if(s.components.requestBodies){let e={};if(r)for(let[t,n]of Object.entries(s.components.requestBodies))i.has(K(`body`,t))&&(e[t]=n);else for(let t of i){let{name:n}=q(t),r=s.components.requestBodies[n];r&&(e[n]=r)}s.components.requestBodies=e}if(s.components.responses){let e={};if(r)for(let[t,n]of Object.entries(s.components.responses))a.has(K(`response`,t))&&(e[t]=n);else for(let t of a){let{name:n}=q(t),r=s.components.responses[n];r&&(e[n]=r)}s.components.responses=e}if(s.components.schemas){let e={};if(r)for(let[t,n]of Object.entries(s.components.schemas))o.has(K(`schema`,t))&&(e[t]=n);else for(let t of o){let{name:n}=q(t),r=s.components.schemas[n];r&&(e[n]=r)}s.components.schemas=e}}if(s.paths)for(let e of Object.entries(s.paths)){let n=e[0],r=e[1];for(let e of G){if(!r[e])continue;let i=K(`operation`,C({method:e,path:n}));t.has(i)||delete r[e]}Object.keys(r).length||delete s.paths[n]}c.timeEnd()},Af=({content:e})=>{let{mediaType:t,schema:n}=e;return n?n.type===`string`&&!n.format&&sd({mediaType:t})?{...n,format:`binary`}:n:sd({mediaType:t})?{format:`binary`,type:`string`}:void 0},jf=({content:e})=>{let t=[];for(let n in e)t.push({mediaType:n,schema:e[n].schema,type:cd({mediaType:n})});return t},Mf=({schema:e})=>typeof e.type==`string`?[e.type]:e.type?e.type:e.properties?[`object`]:[],Nf=({irSchema:e,schema:t})=>{t.deprecated!==void 0&&(e.deprecated=t.deprecated),t.example&&(e.example=t.example),t.description&&(e.description=t.description),t.title&&(e.title=t.title)},Pf=({irSchema:e,schema:t})=>{if(t.const!==void 0&&(e.const=t.const,!t.type))if(t.const===null)e.type=`null`;else switch(typeof t.const){case`bigint`:case`number`:e.type=`number`;break;case`boolean`:e.type=`boolean`;break;case`string`:e.type=`string`;break}t.default!==void 0&&(e.default=t.default),t.exclusiveMaximum!==void 0&&(e.exclusiveMaximum=t.exclusiveMaximum),t.exclusiveMinimum!==void 0&&(e.exclusiveMinimum=t.exclusiveMinimum),t.format&&(e.format=t.format),t.maximum!==void 0&&(e.maximum=t.maximum),t.maxItems!==void 0&&(e.maxItems=t.maxItems),t.maxLength!==void 0&&(e.maxLength=t.maxLength),t.minimum!==void 0&&(e.minimum=t.minimum),t.minItems!==void 0&&(e.minItems=t.minItems),t.minLength!==void 0&&(e.minLength=t.minLength),t.pattern&&(e.pattern=t.pattern),t.readOnly?e.accessScope=`read`:t.writeOnly&&(e.accessScope=`write`)},Ff=({context:e,irSchema:t={},schema:n,state:r})=>{n.prefixItems&&n.prefixItems.length||n.maxItems&&n.maxItems===n.minItems||n.const!==void 0?t.type=`tuple`:t.type=`array`;let i=[];for(let t of n.prefixItems??[]){let n=Q({context:e,schema:t,state:r});i.push(n)}if(n.items){let a=Q({context:e,schema:n.items,state:r});if(!i.length&&n.maxItems&&n.maxItems===n.minItems)i=Array(n.maxItems).fill(a);else{let e=n.items.allOf||n.items.anyOf||n.items.oneOf;e&&e.length>1&&!Mf({schema:n.items}).includes(`null`)?t={...t,...a}:i.push(a)}}return t=S({items:i,schema:t}),t},If=({irSchema:e={}})=>(e.type=`boolean`,e),Lf=({irSchema:e={}})=>(e.type=`null`,e),Rf=({irSchema:e={},schema:t})=>(e.type=t.type,e),zf=({context:e,irSchema:t={},schema:n,state:r})=>{t.type=`object`;let i={};for(let t in n.properties){let a=n.properties[t];typeof a==`boolean`||(i[t]=Q({context:e,schema:a,state:r}))}if(Object.keys(i).length&&(t.properties=i),n.additionalProperties===void 0?t.properties||(t.additionalProperties={type:`unknown`}):typeof n.additionalProperties==`boolean`?r.inAllOf&&n.additionalProperties===!1&&(!n.properties||!Object.keys(n.properties).length)&&(!n.patternProperties||!Object.keys(n.patternProperties).length)||(t.additionalProperties={type:n.additionalProperties?`unknown`:`never`}):t.additionalProperties=Q({context:e,schema:n.additionalProperties,state:r}),n.patternProperties){let i={};for(let t in n.patternProperties){let a=n.patternProperties[t];i[t]=Q({context:e,schema:a,state:r})}Object.keys(i).length&&(t.patternProperties=i)}return n.propertyNames&&(t.propertyNames=Q({context:e,schema:n.propertyNames,state:r})),n.required&&(t.required=n.required),t},Bf=({irSchema:e={}})=>(e.type=`string`,e),Vf=({schema:e})=>{let t={};return Nf({irSchema:t,schema:e}),t},Hf=({context:e,schema:t,state:n})=>{let r=Vf({schema:t});Pf({irSchema:r,schema:t});let i=[],a=Mf({schema:t}),o=t.allOf;for(let r of o){let a=n.inAllOf;`$ref`in r||(n.inAllOf=!0);let o=Q({context:e,schema:r,state:n});if(n.inAllOf=a,n.inAllOf===void 0&&delete n.inAllOf,t.required&&(o.required?o.required=[...o.required,...t.required]:o.required=t.required),i.push(o),r.$ref){let t=e.resolveRef(r.$ref);if(t.discriminator&&n.$ref){let e=fd(n.$ref,t.discriminator.mapping,t.oneOf?()=>t.oneOf.some(e=>`$ref`in e&&e.$ref===n.$ref):void 0);if(e.length>0){let n=e.map(e=>({const:e,type:`string`})),r={properties:{[t.discriminator.propertyName]:n.length>1?{items:n,logicalOperator:`or`}:n[0]},type:`object`};t.required?.includes(t.discriminator.propertyName)&&(r.required=[t.discriminator.propertyName]),i.push(r)}}}}if(a.includes(`object`)){let r=qf({context:e,schema:{...t,type:`object`},state:n});if(r.properties){for(let t of r.required??[])if(!r.properties[t])for(let i of o){let a=i.$ref?e.resolveRef(i.$ref):i;if(Mf({schema:a}).includes(`object`)){let i=qf({context:e,schema:{...a,type:`object`},state:n});if(i.properties?.[t]){r.properties[t]=i.properties[t];break}}}i.push(r)}}if(r=S({items:i,logicalOperator:`and`,mutateSchemaOneItem:!0,schema:r}),a.includes(`null`)){let e=[{type:`null`}];i.length&&e.unshift(r),r={items:e,logicalOperator:`or`}}return r},Uf=({context:e,schema:t,state:n})=>{let r=Vf({schema:t});Pf({irSchema:r,schema:t});let i=[],a=Mf({schema:t}),o=t.anyOf;for(let r of o){let a=Q({context:e,schema:r,state:n});if(t.discriminator&&a.$ref!=null){let e=fd(a.$ref,t.discriminator.mapping).map(e=>({const:e,type:`string`}));a={items:[{properties:{[t.discriminator.propertyName]:e.length>1?{items:e,logicalOperator:`or`}:e[0]},type:`object`},a],logicalOperator:`and`}}i.push(a)}if(a.includes(`null`)&&i.push({type:`null`}),r=S({items:i,mutateSchemaOneItem:!0,schema:r}),a.includes(`object`)){let i=qf({context:e,schema:{...t,type:`object`},state:n});i.properties&&(r={items:[r,i],logicalOperator:`and`})}return r},Wf=({context:e,schema:t,state:n})=>{let r=Vf({schema:t});r.type=`enum`;let i=[],a=Mf({schema:t});for(let[r,o]of t.enum.entries()){let s=typeof o,c;if(s===`string`||s===`number`||s===`boolean`?c=s:s===`object`&&Array.isArray(o)?c=`array`:o===null?a.includes(`null`)&&(c=`null`):console.warn(`🚨`,`unhandled "${s}" typeof value "${o}" for enum`,t.enum),!c)continue;let l=qf({context:e,schema:{const:o,description:t[`x-enum-descriptions`]?.[r],title:t[`x-enum-varnames`]?.[r]??t[`x-enumNames`]?.[r],type:c},state:n});i.push(l)}return r=S({items:i,schema:r}),r},Gf=({context:e,schema:t,state:n})=>{let r=Vf({schema:t});Pf({irSchema:r,schema:t});let i=[],a=Mf({schema:t}),o=t.oneOf;for(let r of o){let a=Q({context:e,schema:r,state:n});if(t.discriminator&&a.$ref!=null){let e=fd(a.$ref,t.discriminator.mapping).map(e=>({const:e,type:`string`}));a={items:[{properties:{[t.discriminator.propertyName]:e.length>1?{items:e,logicalOperator:`or`}:e[0]},required:[t.discriminator.propertyName],type:`object`},a],logicalOperator:`and`}}a.logicalOperator===`or`&&a.type!==`array`&&a.items?i=i.concat(a.items):i.push(a)}if(a.includes(`null`)&&i.push({type:`null`}),r=S({items:i,mutateSchemaOneItem:!0,schema:r}),a.includes(`object`)){let i=qf({context:e,schema:{...t,type:`object`},state:n});i.properties&&(r={items:[r,i],logicalOperator:`and`})}return r},Kf=({context:e,schema:t,state:n})=>{if(!t.$ref.startsWith(`#/components/`)&&!n.circularReferenceTracker.has(t.$ref)){let r=e.resolveRef(t.$ref),i=n.$ref;n.$ref=t.$ref;let a=Q({context:e,schema:r,state:n});return n.$ref=i,a}let r=Vf({schema:t});Pf({irSchema:r,schema:t});let i={};if(i.$ref=decodeURI(t.$ref),!n.circularReferenceTracker.has(t.$ref)){let r=e.resolveRef(t.$ref),i=n.$ref;n.$ref=t.$ref,Q({context:e,schema:r,state:n}),n.$ref=i}let a=[];return a.push(i),t.type&&typeof t.type!=`string`&&t.type.includes(`null`)&&a.push({type:`null`}),r=S({items:a,mutateSchemaOneItem:!0,schema:r}),r},qf=({context:e,irSchema:t,schema:n,state:r})=>{switch(t||(t=Vf({schema:n}),Pf({irSchema:t,schema:n})),n.type){case`array`:return Ff({context:e,irSchema:t,schema:n,state:r});case`boolean`:return If({context:e,irSchema:t,schema:n});case`integer`:case`number`:return Rf({context:e,irSchema:t,schema:n});case`null`:return Lf({context:e,irSchema:t,schema:n});case`object`:return zf({context:e,irSchema:t,schema:n,state:r});case`string`:return Bf({context:e,irSchema:t,schema:n});default:return Xf({context:e,irSchema:t,schema:n})}},Jf=({context:e,irSchema:t,schema:n,state:r})=>{t||=Vf({schema:n});let i={};Pf({irSchema:i,schema:n}),n.type.includes(`null`)&&i.default===null&&delete i.default;let a=[];for(let t of n.type)if(t===`null`)a.push({type:`null`});else{let o=qf({context:e,irSchema:{...i},schema:{...n,type:t},state:r});a.push(o)}return t=S({items:a,schema:t}),t},Yf=({context:e,schema:t,state:n})=>{let r=Vf({schema:t});Pf({irSchema:r,schema:t});let i=Mf({schema:t});return i.length===1?qf({context:e,irSchema:r,schema:{...t,type:i[0]},state:n}):Jf({context:e,irSchema:r,schema:{...t,type:i},state:n})},Xf=({irSchema:e,schema:t})=>(e||=Vf({schema:t}),e.type=`unknown`,Pf({irSchema:e,schema:t}),e),Q=({context:e,schema:t,state:n})=>(n||={circularReferenceTracker:new Set},n.$ref&&n.circularReferenceTracker.add(n.$ref),t.$ref?Kf({context:e,schema:t,state:n}):t.enum?Wf({context:e,schema:t,state:n}):t.allOf?Hf({context:e,schema:t,state:n}):t.anyOf?Uf({context:e,schema:t,state:n}):t.oneOf?Gf({context:e,schema:t,state:n}):t.type||t.properties?Yf({context:e,schema:t,state:n}):Xf({context:e,schema:t})),Zf=({$ref:e,context:t,schema:n})=>{t.ir.components||(t.ir.components={}),t.ir.components.schemas||(t.ir.components.schemas={}),t.ir.components.schemas[F(e)]=Q({context:t,schema:n,state:{$ref:e,circularReferenceTracker:new Set}})},Qf=e=>e.includes(`boolean`)||e.includes(`integer`)||e.includes(`number`)||e.includes(`string`),$f=({context:e,name:t,schema:n})=>{if(dd(e.config.parser.pagination).test(t))return!0;if(n.$ref){let r=e.resolveRef(n.$ref);if(`content`in r||`in`in r){let n;if(`in`in r&&(n=r.schema),!n){let e=jf({content:r.content}),t=e.find(e=>e.type===`json`)||e[0];t?.schema&&(n=t.schema)}return n?$f({context:e,name:t,schema:n}):!1}return $f({context:e,name:t,schema:r})}for(let t in n.properties)if(dd(e.config.parser.pagination).test(t)){let e=n.properties[t];if(typeof e!=`boolean`){let n=Mf({schema:e});if(!n.length){let n=(e.anyOf??e.oneOf??[]).filter(e=>e.type!==`null`);if(n.length===1&&Qf(Mf({schema:n[0]})))return t}if(Qf(n))return t}}for(let r of n.allOf??[]){let n=$f({context:e,name:t,schema:r});if(n)return n}return!1},ep=({irOperation:e,operation:t})=>{t.deprecated!==void 0&&(e.deprecated=t.deprecated),t.description&&(e.description=t.description),t.summary&&(e.summary=t.summary),t.tags?.length&&(e.tags=t.tags)},tp=({context:e,method:t,operation:n,path:r,state:i})=>{let a={id:Yl({context:e,id:n.operationId,method:t,path:r,state:i}),method:t,path:r};return n.operationId&&(a.operationId=n.operationId),ep({irOperation:a,operation:n}),a},np=({context:e,method:t,operation:n,path:r,securitySchemesMap:i,state:a})=>{let o=tp({context:e,method:t,operation:n,path:r,state:a});if(n.parameters&&(o.parameters=n.parameters),n.requestBody){let t=`$ref`in n.requestBody?e.resolveRef(n.requestBody.$ref):n.requestBody,r=jf({content:t.content}),i=r.find(e=>e.type===`json`)||r[0];if(i){let r=$f({context:e,name:``,schema:{description:t.description,...i.schema}});o.body={mediaType:i.mediaType,schema:Q({context:e,schema:{description:t.description,...`$ref`in n.requestBody?n.requestBody:i.schema},state:void 0})},r&&(o.body.pagination=r),t.required&&(o.body.required=t.required),i.type&&(o.body.type=i.type)}}for(let t in n.responses){o.responses||={};let r=n.responses[t],i=`$ref`in r?e.resolveRef(r.$ref):r,a=jf({content:i.content}),s=a.find(e=>e.type===`json`)||a[0];s?o.responses[t]={mediaType:s.mediaType,schema:Q({context:e,schema:{description:i.description,...Af({content:s})},state:void 0})}:o.responses[t]={schema:{description:i.description,type:t===`204`?`void`:`unknown`}}}if(n.security){let e=new Map;for(let t of n.security)for(let n in t){let t=i.get(n);t&&e.set(n,t)}e.size&&(o.security=Array.from(e.values()))}return o},rp=({context:e,method:t,operation:n,path:r,securitySchemesMap:i,state:a})=>(n.servers&&(e.ir.servers=[...e.ir.servers??[],...n.servers]),{parsed:np({context:e,method:t,operation:n,path:r,securitySchemesMap:i,state:a})}),ip=({context:e,method:t,path:n,...r})=>{e.ir.paths||(e.ir.paths={}),e.ir.paths[n]||(e.ir.paths[n]={});let{parsed:i}=rp({context:e,method:t,path:n,...r});e.ir.paths[n][t]=i},ap=({context:e,key:t,method:n,...r})=>{e.ir.webhooks||(e.ir.webhooks={}),e.ir.webhooks[t]||(e.ir.webhooks[t]={});let{parsed:i}=rp({context:e,method:n,path:t,...r});e.ir.webhooks[t][n]=i},op=e=>{switch(e){case`query`:return!1;default:return}},sp=e=>{switch(e){case`deepObject`:case`form`:return!0;default:return!1}},cp=e=>{switch(e){case`header`:case`path`:return`simple`;case`cookie`:case`query`:return`form`}},$=({context:e,parameters:t})=>{if(!t||!Object.keys(t).length)return;let n={};for(let r of t){let t=`$ref`in r?e.dereference(r):r;n[t.in]||(n[t.in]={}),n[t.in][t.name.toLocaleLowerCase()]=lp({$ref:`#/todo/real/path/to/parameter/${t.name}`,context:e,parameter:t})}return n},lp=({$ref:e,context:t,parameter:n})=>{let r=n.schema;if(!r){let e=jf({content:n.content}),t=e.find(e=>e.type===`json`)||e[0];t&&(r=t.schema)}let i={deprecated:n.deprecated,description:n.description,...r},a=$f({context:t,name:n.name,schema:i}),o=n.style||cp(n.in),s=n.explode===void 0?sp(o):n.explode,c={allowReserved:n.allowReserved===void 0?op(n.in):n.allowReserved,explode:s,location:n.in,name:n.name,schema:Q({context:t,schema:i,state:{$ref:e,circularReferenceTracker:new Set}}),style:o};return n.deprecated&&(c.deprecated=n.deprecated),n.description&&(c.description=n.description),a&&(c.pagination=a),n.required&&(c.required=n.required),c},up=({$ref:e,context:t,parameter:n})=>{t.ir.components||(t.ir.components={}),t.ir.components.parameters||(t.ir.components.parameters={}),t.ir.components.parameters[F(e)]=lp({$ref:e,context:t,parameter:n})},dp=({$ref:e,context:t,requestBody:n})=>{let r=jf({content:n.content}),i=r.find(e=>e.type===`json`)||r[0],a=i?i.schema:void 0,o={schema:Q({context:t,schema:{description:n.description,...a},state:{$ref:e,circularReferenceTracker:new Set}})};return n.description&&(o.description=n.description),n.required&&(o.required=n.required),o},fp=({$ref:e,context:t,requestBody:n})=>{t.ir.components||(t.ir.components={}),t.ir.components.requestBodies||(t.ir.components.requestBodies={}),t.ir.components.requestBodies[F(e)]=dp({$ref:e,context:t,requestBody:n})},pp=({context:e})=>{if(e.spec.servers){e.ir.servers=e.spec.servers;return}for(let t of e.config.input)if(typeof t.path==`string`){let n=ma(t.path);e.ir.servers=[{url:`${n.protocol?`${n.protocol}://`:``}${n.host}${n.port?`:${n.port}`:``}`}]}e.ir.servers||(e.ir.servers=[{url:`/`}])},mp=(e,t)=>{let n=t.timeEvent(`validate`),r=[],i=new Map;if(e.paths)for(let t of Object.entries(e.paths)){let e=t[0],n=t[1];for(let t of G){let a=n[t];if(!a)continue;let o=C({method:t,path:e});a.operationId&&(i.has(a.operationId)?r.push({code:`duplicate_key`,context:{key:`operationId`,value:a.operationId},message:"Duplicate `operationId` found. Each `operationId` must be unique.",path:[`paths`,e,t,`operationId`],severity:`error`}):i.set(a.operationId,o))}}if(e.servers){(typeof e.servers!=`object`||!Array.isArray(e.servers))&&r.push({code:`invalid_type`,message:"`servers` must be an array.",path:[],severity:`error`});for(let t=0;t<e.servers.length;t++){let n=e.servers[t];!n||typeof n!=`object`?r.push({code:`invalid_type`,context:{actual:typeof n,expected:`object`},message:"Each entry in `servers` must be an object.",path:[`servers`,t],severity:`error`}):n.url||r.push({code:`missing_required_field`,context:{field:`url`},message:"Missing required field `url` in server object.",path:[`servers`,t],severity:`error`})}}return n.timeEnd(),{issues:r,valid:!r.some(e=>e.severity===`error`)}},hp=({context:e,securitySchemesMap:t})=>{let n={ids:new Map};for(let r in e.spec.webhooks){let i=e.spec.webhooks[r],a=`$ref`in i?{...e.resolveRef(i.$ref),...i}:i,o={context:e,key:r,operation:{description:a.description,parameters:$({context:e,parameters:a.parameters}),security:e.spec.security,servers:a.servers,summary:a.summary},securitySchemesMap:t,state:n};a.delete&&ap({...o,method:`delete`,operation:{...o.operation,...a.delete,parameters:Y({source:$({context:e,parameters:a.delete.parameters}),target:o.operation.parameters})}}),a.get&&ap({...o,method:`get`,operation:{...o.operation,...a.get,parameters:Y({source:$({context:e,parameters:a.get.parameters}),target:o.operation.parameters})}}),a.head&&ap({...o,method:`head`,operation:{...o.operation,...a.head,parameters:Y({source:$({context:e,parameters:a.head.parameters}),target:o.operation.parameters})}}),a.options&&ap({...o,method:`options`,operation:{...o.operation,...a.options,parameters:Y({source:$({context:e,parameters:a.options.parameters}),target:o.operation.parameters})}}),a.patch&&ap({...o,method:`patch`,operation:{...o.operation,...a.patch,parameters:Y({source:$({context:e,parameters:a.patch.parameters}),target:o.operation.parameters})}}),a.post&&ap({...o,method:`post`,operation:{...o.operation,...a.post,parameters:Y({source:$({context:e,parameters:a.post.parameters}),target:o.operation.parameters})}}),a.put&&ap({...o,method:`put`,operation:{...o.operation,...a.put,parameters:Y({source:$({context:e,parameters:a.put.parameters}),target:o.operation.parameters})}}),a.trace&&ap({...o,method:`trace`,operation:{...o.operation,...a.trace,parameters:Y({source:$({context:e,parameters:a.trace.parameters}),target:o.operation.parameters})}})}},gp=e=>{if(e.config.parser.validate_EXPERIMENTAL&&$u({context:e,result:mp(e.spec,e.logger)}),tu(e.config.parser.filters)){let t=eu(e.config.parser.filters,e.spec,e.logger),{graph:n}=Ru(e.spec,e.logger),{resourceMetadata:r}=mu(n,e.logger);kf({...pu({filters:t,logger:e.logger,resourceMetadata:r}),logger:e.logger,preserveOrder:t.preserveOrder,spec:e.spec})}Ju({context:e});let t={ids:new Map},n=new Map;if(e.spec.components){for(let t in e.spec.components.securitySchemes){let r=e.spec.components.securitySchemes[t],i=`$ref`in r?e.resolveRef(r.$ref):r;n.set(t,i)}for(let t in e.spec.components.parameters){let n=`#/components/parameters/${t}`,r=e.spec.components.parameters[t];up({$ref:n,context:e,parameter:`$ref`in r?e.resolveRef(r.$ref):r})}for(let t in e.spec.components.requestBodies){let n=`#/components/requestBodies/${t}`,r=e.spec.components.requestBodies[t];fp({$ref:n,context:e,requestBody:`$ref`in r?e.resolveRef(r.$ref):r})}for(let t in e.spec.components.schemas){let n=`#/components/schemas/${t}`,r=e.spec.components.schemas[t];Zf({$ref:n,context:e,schema:r})}}for(let r in pp({context:e}),e.spec.paths){let i=e.spec.paths[r],a=i.$ref?{...e.resolveRef(i.$ref),...i}:i,o={context:e,operation:{description:a.description,parameters:$({context:e,parameters:a.parameters}),security:e.spec.security,servers:a.servers,summary:a.summary},path:r,securitySchemesMap:n,state:t};a.delete&&ip({...o,method:`delete`,operation:{...o.operation,...a.delete,parameters:Y({source:$({context:e,parameters:a.delete.parameters}),target:o.operation.parameters})}}),a.get&&ip({...o,method:`get`,operation:{...o.operation,...a.get,parameters:Y({source:$({context:e,parameters:a.get.parameters}),target:o.operation.parameters})}}),a.head&&ip({...o,method:`head`,operation:{...o.operation,...a.head,parameters:Y({source:$({context:e,parameters:a.head.parameters}),target:o.operation.parameters})}}),a.options&&ip({...o,method:`options`,operation:{...o.operation,...a.options,parameters:Y({source:$({context:e,parameters:a.options.parameters}),target:o.operation.parameters})}}),a.patch&&ip({...o,method:`patch`,operation:{...o.operation,...a.patch,parameters:Y({source:$({context:e,parameters:a.patch.parameters}),target:o.operation.parameters})}}),a.post&&ip({...o,method:`post`,operation:{...o.operation,...a.post,parameters:Y({source:$({context:e,parameters:a.post.parameters}),target:o.operation.parameters})}}),a.put&&ip({...o,method:`put`,operation:{...o.operation,...a.put,parameters:Y({source:$({context:e,parameters:a.put.parameters}),target:o.operation.parameters})}}),a.trace&&ip({...o,method:`trace`,operation:{...o.operation,...a.trace,parameters:Y({source:$({context:e,parameters:a.trace.parameters}),target:o.operation.parameters})}})}hp({context:e,securitySchemesMap:n})},_p=({config:e,dependencies:t,logger:n,spec:r})=>{let i=new Jl({config:e,dependencies:t,logger:n,spec:r});if(`swagger`in i.spec)return Hd(i),i;if(Ea(i.spec.openapi,`>=3.0.0 <3.1.0`))return Of(i),i;if(Ea(i.spec.openapi,`>=3.1.0`))return gp(i),i;throw Error(`Unsupported OpenAPI specification`)};export{re as A,pe as C,ve as D,_e as E,se as O,fe as S,ge as T,y as _,bl as a,Re as b,ia as c,_i as d,wt as f,w as g,T as h,Tl as i,ne as k,aa as l,O as m,Ru as n,va as o,St as p,Fl as r,fa as s,_p as t,P as u,qe as v,he as w,de as x,Ge as y};
13
- //# sourceMappingURL=openApi-AbaojA3X.mjs.map