UNPKG

@hey-api/openapi-ts

Version:

🚀 The OpenAPI to TypeScript codegen. Generate clients, SDKs, validators, and more.

3 lines 351 kB
import{r as e}from"./chunk-C-EqMg7d.js";import{Project as t,createBinding as n,mergeBindings as r,renderIds as i}from"@hey-api/codegen-core";import a from"ansi-colors";import o from"node:fs";import s from"node:path";import{fileURLToPath as c}from"node:url";import l from"typescript";import{EOL as u}from"node:os";import*as d from"semver";import{getResolvedInput as f,sendRequest as p}from"@hey-api/json-schema-ref-parser";const m=c(import.meta.url),h=s.dirname(m),g=()=>{let e=h;for(;e!==s.dirname(e);){let t=o.readdirSync(e).filter(e=>e===`package.json`);if(t[0]){let n=s.join(e,t[0]);return JSON.parse(o.readFileSync(n,{encoding:`utf8`}))}e=s.dirname(e)}},ee=()=>{let e=g(),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},te=e=>{if(e===null)return null;if(e){let t=s.isAbsolute(e)?e:s.resolve(h,e);return o.existsSync(t)?t:null}let t=h;for(;t!==s.dirname(t);){let e=o.readdirSync(t).filter(e=>e.startsWith(`tsconfig`)&&e.endsWith(`.json`)).sort(e=>e===`tsconfig.json`?-1:1);if(e[0])return s.join(t,e[0]);t=s.dirname(t)}return null},ne=e=>{if(!e)return null;let t=l.readConfigFile(e,l.sys.readFile);if(t.error)throw Error(`Couldn't read tsconfig from path: ${e}`);return l.parseJsonConfigFileContent(t.config,l.sys,s.dirname(e))},_=e=>{o.existsSync(e)||o.mkdirSync(e,{recursive:!0})};var v=class extends Error{constructor(e){super(e),this.name=`ConfigError`}},re=class extends Error{errors;constructor(e){super(`Found ${e.length} configuration ${e.length===1?`error`:`errors`}.`),this.name=`ConfigValidationError`,this.errors=e}},ie=class extends Error{originalError;constructor(e,t){super(e),this.name=`JobError`,this.originalError=t}},ae=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 oe=(e,t)=>{if(e instanceof v||e instanceof re)return;e instanceof ie&&(e=e.originalError.error);let n=`openapi-ts-error-${Date.now()}.log`,r=s.resolve(process.cwd(),t);_(r);let i=s.resolve(r,n),a=`[${new Date().toISOString()}] `;e instanceof ae&&(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 c=e instanceof Error?e.message:String(e),l=e instanceof Error?e.stack:void 0;return a+=`Error: ${c}\n`,l&&(a+=`Stack:\n${l}\n`),o.writeFileSync(i,a),i},se=async e=>{let t=ee();if(!t.bugs.url)return;e instanceof ie&&(e=e.originalError.error);let n=``;e instanceof ae&&(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)},ce=({error:e,logPath:t})=>{if(e instanceof re&&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=a.gray(`[Job ${e+1}] `),r=n.length,i=a.red(`Found ${r} configuration ${r===1?`error`:`errors`}:`);console.error(`${t}❗️ ${i}`),n.forEach((e,n)=>{let r=` [${n+1}] `,i=a.red(r);console.error(`${t}${i}${a.white(e.message)}`)})}}else{let t=a.gray(`[root] `);e instanceof ie&&(t=a.gray(`[Job ${e.originalError.jobIndex+1}] `),e=e.originalError.error);let n=a.red(`Failed with the message:`);console.error(`${t}❌ ${n}`);let r=a.red(` `);console.error(`${t}${r}${typeof e==`string`?e:e instanceof Error?e.message:`Unknown error`}`)}if(t){let e=a.gray(`[root] `);console.error(`${e}${a.cyan(`📄 Crash log saved to:`)} ${a.gray(t)}`)}},le=async({error:e,isInteractive:t})=>!t||e instanceof v||e instanceof re?!1:new Promise(e=>{let t=a.gray(`[root] `);console.log(`${t}${a.yellow(`📢 Open a GitHub issue with crash details? (y/N):`)}`),process.stdin.setEncoding(`utf8`),process.stdin.once(`data`,t=>{e(t.trim().toLowerCase()===`y`)})}),ue=/^([\w-]+)\/([\w-]+)(?:\?([\w=&.-]*))?$/,de=`https://get.heyapi.dev`,fe=(e,t,n)=>`${de}/${e}/${t}${n?`?${n}`:``}`,pe=e=>{let t=e.organization,n=e.project,r;if(e.path){let i=e.path.match(ue);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}},me=e=>{let t=pe(e);return{path:fe(t.organization,t.project,t.queryParams),registry:`hey-api`}},he=/^(@([\w-]+)\/([\w\-.]+)#)?([\w-]+)$/,ge=e=>`https://dash.readme.com/api/v1/api-registry/${e}`,_e=`readme`,ve=e=>{let t=e.match(he);if(!t)throw Error(`Invalid ReadMe shorthand format. Expected "${_e}:@organization/project#uuid" or "${_e}:uuid", received: ${_e}:${e}`);let[,,n,r,i]=t;if(!i)throw Error(`The ReadMe UUID cannot be empty.`);return{organization:n,project:r,uuid:i}},ye=e=>{let t=ve(e.slice(`${_e}:`.length));return{...t,path:ge(t.uuid),registry:`readme`}},be=/^(@[\w-]+)\/([\w.-]+)$/,xe=(e,t)=>`https://registry.scalar.com/${e}/apis/${t}/latest?format=json`,Se=`scalar`,Ce=e=>{let t=e.match(be);if(!t)throw Error(`Invalid Scalar shorthand format. Expected "${Se}:@organization/project", received: ${Se}:${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}},we=e=>{let t=Ce(e.slice(`${Se}:`.length));return{...t,path:xe(t.organization,t.project),registry:`scalar`}},Te=e=>{if(e.path.startsWith(`readme:`)){Object.assign(e,ye(e.path));return}if(e.path.startsWith(`scalar:`)){Object.assign(e,we(e.path));return}if(e.path.startsWith(`.`))return;if(e.path.startsWith(de)){e.path=e.path.slice(23),Object.assign(e,me(e));return}let t=e.path.split(`/`);if(t.length===2&&t.filter(Boolean).length===2){Object.assign(e,me(e));return}},Ee={enabled:!1,interval:1e3,timeout:6e4},De=e=>{let t={...Ee};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},Oe=e=>{let t=e.input instanceof Array?e.input:[e.input],n=[];for(let r of t){let t={path:``,watch:Ee};typeof r==`string`?t.path=r:r&&(r.path!==void 0||r.organization!==void 0)?(t={...t,path:de,...r},t.watch!==void 0&&(t.watch=De(t))):t={...t,path:r},typeof t.path==`string`&&Te(t),e.watch!==void 0&&t.watch.enabled===Ee.enabled&&t.watch.interval===Ee.interval&&t.watch.timeout===Ee.timeout&&(t.watch=De({path:t.path,watch:e.watch})),t.path&&n.push(t)}return n},ke=e=>{let t={file:!0,level:`info`,path:process.cwd()};return typeof e?.logs==`string`?t.path=e.logs:t={...t,...e?.logs},t},Ae=(e,t)=>{let n=e||{},r=t||{};return{...n,...r}},je=(e,t)=>{let n=e||{},r=t||{},i={...n,...r};return typeof i.logs==`object`&&(i.logs=Ae(n.logs,r.logs)),i},Me=e=>typeof e==`object`&&!!e&&!Array.isArray(e)&&typeof e!=`function`,Ne=(e,t)=>{for(let[n,r]of Object.entries(t))r!==void 0&&r!==``&&(e[n]=r);return e},y=({defaultValue:e,mappers:t,value:n})=>{let r={...e};switch(typeof n){case`boolean`:if(t&&`boolean`in t){let e=t.boolean;r=Ne(r,e(n))}break;case`function`:if(t&&`function`in t){let e=t.function;r=Ne(r,e(n))}break;case`number`:if(t&&`number`in t){let e=t.number;r=Ne(r,e(n))}break;case`string`:if(t&&`string`in t){let e=t.string;r=Ne(r,e(n))}break;case`object`:if(Me(n))if(t&&`object`in t&&typeof t.object==`function`){let i=t.object;r=Ne(r,i(n,e))}else r=Ne(r,n);break}return r},Pe=e=>{if(e.output instanceof Array)throw Error(`Unexpected array of outputs in user configuration. This should have been expanded already.`);let t=y({defaultValue:{clean:!0,fileName:{case:`preserve`,name:`{{name}}`,suffix:`.gen`},format:null,indexFile:!0,lint:null,path:``},mappers:{object:(e,t)=>({...e,fileName:y({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=ne(te(t.tsConfigPath)),t.importFileExtension===void 0&&t.tsConfig?.options.moduleResolution===l.ModuleResolutionKind.NodeNext&&(t.importFileExtension=`.js`),t.importFileExtension&&!t.importFileExtension.startsWith(`.`)&&(t.importFileExtension=`.${t.importFileExtension}`),t},Fe=e=>{let t=e?s.dirname(e):process.cwd();for(;t!==s.dirname(t);){let e=s.join(t,`package.json`);if(o.existsSync(e))try{let t=JSON.parse(o.readFileSync(e,`utf8`));return{...t.dependencies,...t.devDependencies,...t.peerDependencies,...t.optionalDependencies}}catch{}let n=s.dirname(t);if(n===t)break;t=n}return{}},Ie=[`after`,`before`,`cursor`,`offset`,`page`,`start`],Le=e=>y({defaultValue:{hooks:{},pagination:{keywords:Ie},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:y({defaultValue:{...t.pagination},value:e.pagination}),transforms:y({defaultValue:{...t.transforms},mappers:{object:(e,t)=>({...e,enums:y({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:y({defaultValue:{...t.readWrite,enabled:e.readWrite===void 0?t.readWrite.enabled:!!e.readWrite},mappers:{boolean:e=>({enabled:e}),object:(e,t)=>({...e,requests:y({defaultValue:{...t.requests},mappers:{function:e=>({name:e}),string:e=>({name:e})},value:e.requests}),responses:y({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}),Re=e=>t=>({...e,config:{...e.config,...t}}),b={boolean:e=>({enabled:e}),function:e=>({name:e}),string:e=>({name:e})};var ze=class{};const Be=/[\p{Lu}]/u,Ve=/[\p{Ll}]/u,He=/([\p{Alpha}\p{N}_]|$)/u,Ue=/[_.\- `\\[\]{}\\/]+/,We=RegExp(`^${Ue.source}`),Ge=RegExp(`${Ue.source}${He.source}`,`gu`),Ke=RegExp(`\\d+${He.source}`,`gu`),qe=({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(Ue.lastIndex=0;l&&Ue.test(l);)c+=1,l=t[c];let u=c!==e+1;if(Ve.lastIndex=0,Be.lastIndex=0,Be.test(s)&&(n||l&&!u&&l!==`s`&&Ve.test(l)))t=`${t.slice(0,e)}${o}${t.slice(e)}`,e++,i=r,n=!1,r=!0;else if(r&&i&&Ve.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},x=({case:e,stripLeadingSeparators:t=!0,value:n})=>{let r=n.trim();return r.length?!e||e===`preserve`?r:r.length===1?(Ue.lastIndex=0,Ue.test(r)?``:e===`PascalCase`||e===`SCREAMING_SNAKE_CASE`?r.toLocaleUpperCase():r.toLocaleLowerCase()):(r!==r.toLocaleLowerCase()&&(r=qe({case:e,string:r})),(t||r[0]!==n[0])&&(r=r.replace(We,``)),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(Ge,(e,n,r)=>r===0&&!t?e:`_${n}`),r[r.length-1]===`_`&&(r=r.slice(0,r.length-1))):(Ge.lastIndex=0,Ke.lastIndex=0,r=r.replaceAll(Ke,(e,t,n)=>[`_`,`-`,`.`].includes(r.charAt(n+e.length))?e:e.toLocaleUpperCase()),r=r.replaceAll(Ge,(e,r,i)=>i===0&&!t&&e[0]&&n.startsWith(e[0])?e:r.toLocaleUpperCase())),r):``},S=({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 x({case:e.case,value:t})},Je=({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]},Ye=e=>{for(let t in e)if(e[t].required)return!0;return!1},Xe=e=>e?!!(Ye(e.cookie)||Ye(e.header)||Ye(e.path)||Ye(e.query)):!1,Ze=({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:Je({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:Je({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:Je({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:Je({context:e,parameter:r})}}}},C=({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},w=({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,Qe=e=>!!(Xe(e.parameters)||e.body?.required),T=({method:e,path:t})=>`${e.toUpperCase()} ${t}`,$e=({context:e,operation:t})=>{let n=t.body;if(!n||!n.pagination)return Ze({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}:Ze({context:e,parameters:t.parameters})},et=({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`}},tt=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(et({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=w({items:Object.values(n.properties),mutateSchemaOneItem:!0,schema:{}});e=C({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=w({items:Object.values(r.properties),mutateSchemaOneItem:!0,schema:{}});e=C({schema:e}),Object.keys(e).length&&e.type!==`unknown`&&(t.response=e)}return t},nt=e=>e.replace(/^[^\p{ID_Start}]+/u,``).replace(/[^$\u200c\u200d\p{ID_Continue}]/gu,`-`).replace(/[$+]/g,`-`),rt=e=>{let t=E(e);return t.name===`@hey-api/client-axios`||t.name===`@hey-api/client-nuxt`?`baseURL`:`baseUrl`},E=e=>{for(let t of e.pluginOrder){let n=e.plugins[t];if(n?.tags?.includes(`client`))return n}return{config:{name:``},name:``}},D=e=>({value:e}),O=e=>{let t={};for(let n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=D(e[n]));return t},it=/^[^$_\p{ID_Start}]+/u,k=/^-?\d+(\.\d+)?$/,at=/^(document|history|location|navigator|window)$/g,ot=/^(console|Array|Date|Error|Function|JSON|Map|Math|Object|Promise|RegExp|Set|WeakMap|WeakSet)$/g,st=/^(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,ct=/^(global|process|Buffer)$/g,lt=/^(any|as|bigint|boolean|namespace|never|null|number|string|symbol|type|undefined|unknown|void)$/g,ut=/^[$_\p{ID_Start}][$\u200c\u200d\p{ID_Continue}]*$/u,dt=e=>(e||e===``)&&(ut.lastIndex=0,!ut.test(e))?`'${e}'`:e,ft=e=>e&&e.startsWith(`'`)&&e.endsWith(`'`)?e.slice(1,e.length-1):e,pt=e=>e.replace(/\*\//g,`*`).replace(/\/\*/g,`*`).replace(/\r?\n(.*)/g,(e,t)=>u+t.trim()),mt=l.createPrinter({newLine:l.NewLineKind.LineFeed,removeComments:!1}),ht=(e=>l.createSourceFile(``,e,l.ScriptTarget.ESNext,!1,l.ScriptKind.TS))(``),gt=e=>e.replace(/\\u([0-9a-fA-F]{4})/g,(e,t)=>String.fromCharCode(Number.parseInt(t,16)));function _t({node:e,unescape:t=!1}){let n=mt.printNode(l.EmitHint.Unspecified,e,ht);if(!t)return n;try{return gt(n)}catch{return n}}const A=({text:e})=>l.factory.createIdentifier(e),vt=()=>l.factory.createThis(),j=({keyword:e})=>{let t=Ot({keyword:e});return l.factory.createModifier(t)},yt=({initializer:e,modifier:t,name:n,type:r})=>l.factory.createPropertyDeclaration(t?[j({keyword:t})]:void 0,n,void 0,r,e),M={boolean:e=>e?l.factory.createTrue():l.factory.createFalse(),export:({alias:e,asType:t=!1,name:n})=>{let r=A({text:n});if(e){let n=A({text:e});return l.factory.createExportSpecifier(t,r,n)}return l.factory.createExportSpecifier(t,void 0,r)},import:({alias:e,asType:t=!1,name:n})=>{let r=A({text:n});if(e){let n=A({text:e});return l.factory.createImportSpecifier(t,r,n)}return l.factory.createImportSpecifier(t,void 0,r)},number:e=>e<0?l.factory.createPrefixUnaryExpression(l.SyntaxKind.MinusToken,l.factory.createNumericLiteral(Math.abs(e))):l.factory.createNumericLiteral(e),string:(e,t=!1)=>{let n=e;t&&(n=ft(n));let r=n.includes(`'`)&&n.includes(`"`),i=n.includes(` `),a=n.startsWith("`"),o=n.startsWith("\\`")&&n.endsWith("\\`");return(i||r||a)&&!o&&(n=`\`${n.replace(/(?<!\\)`/g,"\\`").replace(/\${/g,"\\${")}\``),n.startsWith("`")?A({text:n}):Kt({text:n})}},bt=e=>typeof e==`object`&&!!e&&typeof e.kind==`number`&&typeof e.flags==`number`&&typeof e.pos==`number`&&typeof e.end==`number`,xt=e=>e!==void 0,St=({commentObject:e,node:t})=>{let n=e.lines.filter(e=>!!e||e===``);if(!n.length)return;if(!e.jsdoc){for(let e of n)l.addSyntheticLeadingComment(t,l.SyntaxKind.SingleLineCommentTrivia,` ${e}`,!0);return}let r=n.map((e,t)=>{let r=e;return t!==n.length&&(r=`${r}\n`),l.factory.createJSDocText(r)}),i=_t({node:l.factory.createJSDocComment(l.factory.createNodeArray(r),void 0),unescape:!0}).replace(`/*`,``).replace(`* */`,``);l.addSyntheticLeadingComment(t,l.SyntaxKind.MultiLineCommentTrivia,i,!0)},N=({comments:e=[],node:t})=>{let n=!!e.find(e=>typeof e==`object`&&e),r=e;n||(r=[{jsdoc:!0,lines:e}]);for(let e of r)St({commentObject:e,node:t})},P=(e,t)=>l.isTypeNode(e)?e:typeof e==`number`?l.factory.createLiteralTypeNode(M.number(e)):Xt({typeArguments:t?.map(e=>P(e)),typeName:l.isIdentifier(e)?e.text:e}),Ct=({expression:e,name:t})=>l.factory.createPropertyAccessChain(e,l.factory.createToken(l.SyntaxKind.QuestionDotToken),t),wt=({expression:e,isOptional:t,name:n})=>{let r=typeof e==`string`?A({text:e}):e;if(t&&typeof n!=`number`)return Ct({expression:r,name:n});if(typeof n==`string`){if(ut.lastIndex=0,!ut.test(n)){!n.startsWith(`'`)&&!n.endsWith(`'`)&&(n=`\'${n}\'`);let e=A({text:n});return l.factory.createElementAccessExpression(r,e)}let e=A({text:n});return l.factory.createPropertyAccessExpression(r,e)}if(typeof n==`number`){let e=l.factory.createNumericLiteral(n);return l.factory.createElementAccessExpression(r,e)}return l.factory.createPropertyAccessExpression(r,n)},Tt=()=>l.factory.createNull(),Et=({identifiers:e=[],isValueAccess:t,shorthand:n,unescape:r,value:i})=>{if(i===null)return Tt();if(Array.isArray(i))return Lt({elements:i});if(typeof i==`object`)return Bt({identifiers:e,obj:i,shorthand:n});if(typeof i==`number`)return M.number(i);if(typeof i==`boolean`)return M.boolean(i);if(typeof i==`string`){if(t){let e=i.split(`.`);return wt({expression:e[0],name:e[1]})}return M.string(i,r)}},Dt=e=>e.map(e=>{if(`destructure`in e)return Qt({name:l.factory.createObjectBindingPattern(e.destructure.map(e=>{if(!(`destructure`in e))return l.factory.createBindingElement(void 0,void 0,A({text:e.name}),void 0)}).filter(Boolean)),type:e.type===void 0?void 0:P(e.type)});let t=e.accessLevel?[j({keyword:e.accessLevel})]:[];return e.isReadOnly&&t.push(j({keyword:`readonly`})),Qt({initializer:e.default===void 0?void 0:Et({value:e.default}),modifiers:t,name:A({text:e.name}),required:e.isRequired!==!1,type:e.type===void 0?void 0:P(e.type)})}),Ot=({keyword:e})=>{switch(e){case`any`:return l.SyntaxKind.AnyKeyword;case`async`:return l.SyntaxKind.AsyncKeyword;case`boolean`:return l.SyntaxKind.BooleanKeyword;case`export`:return l.SyntaxKind.ExportKeyword;case`never`:return l.SyntaxKind.NeverKeyword;case`number`:return l.SyntaxKind.NumberKeyword;case`private`:return l.SyntaxKind.PrivateKeyword;case`protected`:return l.SyntaxKind.ProtectedKeyword;case`public`:return l.SyntaxKind.PublicKeyword;case`readonly`:return l.SyntaxKind.ReadonlyKeyword;case`static`:return l.SyntaxKind.StaticKeyword;case`string`:return l.SyntaxKind.StringKeyword;case`undefined`:return l.SyntaxKind.UndefinedKeyword;case`unknown`:return l.SyntaxKind.UnknownKeyword;case`void`:return l.SyntaxKind.VoidKeyword;default:throw Error(`unsupported syntax kind keyword "${e}"`)}},kt=({keyword:e})=>{let t=Ot({keyword:e});return l.factory.createKeywordTypeNode(t)},At=e=>e.map(e=>l.isTypeParameterDeclaration(e)?e:Mt({constraint:e.extends?typeof e.extends==`string`?kt({keyword:`boolean`}):e.extends:void 0,defaultType:e.default===void 0?void 0:bt(e.default)?e.default:l.factory.createLiteralTypeNode(e.default?l.factory.createTrue():l.factory.createFalse()),name:e.name})),jt=({operator:e,type:t})=>{let n=e===`keyof`?l.SyntaxKind.KeyOfKeyword:e===`readonly`?l.SyntaxKind.ReadonlyKeyword:l.SyntaxKind.UniqueKeyword;return l.factory.createTypeOperatorNode(n,t)},Mt=({constraint:e,defaultType:t,modifiers:n,name:r})=>l.factory.createTypeParameterDeclaration(n,r,e,t),Nt=({members:e,nameType:t,questionToken:n,readonlyToken:r,type:i,typeParameter:a})=>l.factory.createMappedTypeNode(r,a,t,n,i,e),Pt=({literal:e})=>l.factory.createLiteralTypeNode(e),Ft=({async:e,comment:t,multiLine:n,parameters:r=[],returnType:i,statements:a=[],types:o=[]})=>{let s=l.factory.createArrowFunction(e?[j({keyword:`async`})]:void 0,o?At(o):void 0,Dt(r),i?P(i):void 0,void 0,Array.isArray(a)?F({multiLine:n,statements:a}):a);return N({comments:t,node:s}),s},It=({async:e,comment:t,multiLine:n,parameters:r=[],returnType:i,statements:a=[],types:o=[]})=>{let s=l.factory.createFunctionExpression(e?[j({keyword:`async`})]:void 0,void 0,void 0,o?At(o):void 0,Dt(r),i?P(i):void 0,F({multiLine:n,statements:a}));return N({comments:t,node:s}),s},Lt=({elements:e,multiLine:t=!1})=>l.factory.createArrayLiteralExpression(e.map(e=>bt(e)?e:Et({value:e})).filter(xt),t||!Array.isArray(e[0])&&typeof e[0]==`object`),Rt=({expression:e})=>l.factory.createAwaitExpression(e),zt=({parameters:e=[],returnType:t,typeParameters:n})=>l.factory.createFunctionTypeNode(n,e,t),Bt=({comments:e,identifiers:t=[],multiLine:n=!0,obj:r,shorthand:i,unescape:a=!1})=>{let o=Array.isArray(r)?r.map(e=>{let r=!1;if(`key`in e){let{key:t}=e;r=t===e.value,(t.match(/^[0-9]/)&&t.match(/\D+/g)||t.match(/\W/g)||t===``)&&!t.startsWith(`'`)&&!t.endsWith(`'`)&&(e.key=`'${t}'`)}let o;if(`spread`in e){let t=bt(e.spread)?e.spread:A({text:e.spread});o=l.factory.createSpreadAssignment(e.assertion?an({expression:t,type:typeof e.assertion==`string`?kt({keyword:e.assertion}):e.assertion}):t)}else if(e.shorthand||i&&r)o=l.factory.createShorthandPropertyAssignment(e.value);else{let r=bt(e.value)?e.value:Array.isArray(e.value)&&(!e.value.length||typeof e.value[0]==`object`)?Bt({multiLine:n,obj:e.value,shorthand:i,unescape:a}):Et({identifiers:t.includes(e.key)?Object.keys(e.value):[],isValueAccess:e.isValueAccess,shorthand:i,unescape:a,value:e.value});if(!r)return;t.includes(e.key)&&!l.isObjectLiteralExpression(r)&&(r=A({text:e.value})),o=nn({initializer:r,name:e.key})}return N({comments:e.comments,node:o}),o}).filter(xt):Object.entries(r).map(([e,n])=>{let r=Et({identifiers:t.includes(e)?Object.keys(n):[],shorthand:i,unescape:a,value:n});if(!r)return;t.includes(e)&&!l.isObjectLiteralExpression(r)&&(r=A({text:n}));let o=e===n;return e.match(/^[0-9]/)&&e.match(/\D+/g)&&!e.startsWith(`'`)&&!e.endsWith(`'`)&&(e=`'${e}'`),e.match(/\W/g)&&!e.startsWith(`'`)&&!e.endsWith(`'`)&&(e=`'${e}'`),i&&o?l.factory.createShorthandPropertyAssignment(n):nn({initializer:r,name:e})}).filter(xt),s=l.factory.createObjectLiteralExpression(o,n);return N({comments:e,node:s}),s},Vt=({asConst:e,comments:t={},leadingComment:n,name:r,obj:i})=>{let a=Array.isArray(i)?i.map(e=>{let t=Ht({initializer:Et({value:e.value}),name:e.key});return N({comments:e.comments,node:t}),t}):Object.entries(i).map(([e,n])=>{let r=l.factory.createEnumMember(e,Et({unescape:!0,value:n}));return N({comments:t[e],node:r}),r}),o=[j({keyword:`export`})],s=e?[l.factory.createToken(l.SyntaxKind.ConstKeyword)]:[],c=[...o,...s],u=l.factory.createEnumDeclaration(c,typeof r==`string`?A({text:r}):r,a);return N({comments:n,node:u}),u},Ht=({initializer:e,name:t})=>{let n=t;return typeof n==`string`&&(n=n.includes(`'`)?Kt({isSingleQuote:!1,text:n}):dt(n)),l.factory.createEnumMember(n,e)},Ut=({name:e,statements:t})=>l.factory.createModuleDeclaration([j({keyword:`export`})],A({text:e}),l.factory.createModuleBlock(t),l.NodeFlags.Namespace),Wt=({indexType:e,objectType:t})=>l.factory.createIndexedAccessTypeNode(t,e),Gt=({modifiers:e,name:t,returnType:n,statements:r})=>{let i=Array.isArray(e)?e:[e];return l.factory.createGetAccessorDeclaration(e?i.map(e=>j({keyword:e})):void 0,t,[],n?Xt({typeName:n}):void 0,F({statements:r}))},Kt=({isSingleQuote:e,text:t})=>(e===void 0&&(e=!t.includes(`'`)),l.factory.createStringLiteral(t,e)),qt=({condition:e,whenFalse:t,whenTrue:n})=>l.factory.createConditionalExpression(e,l.factory.createToken(l.SyntaxKind.QuestionToken),n,l.factory.createToken(l.SyntaxKind.ColonToken),t),Jt=({text:e})=>l.factory.createTypeOfExpression(typeof e==`string`?A({text:e}):e),Yt=({comment:e,exportType:t,name:n,type:r,typeParameters:i=[]})=>{let a=l.factory.createTypeAliasDeclaration(t?[j({keyword:`export`})]:void 0,typeof n==`string`?A({text:n}):n,At(i),P(r));return N({comments:e,node:a}),a},Xt=({typeArguments:e,typeName:t})=>l.factory.createTypeReferenceNode(t,e),Zt=({type:e})=>l.factory.createParenthesizedType(e),Qt=({initializer:e,modifiers:t,name:n,required:r=!0,type:i})=>l.factory.createParameterDeclaration(t,void 0,n,r?void 0:l.factory.createToken(l.SyntaxKind.QuestionToken),i,e),$t=({argumentsArray:e,expression:t,typeArguments:n})=>l.factory.createNewExpression(t,n,e),en=({awaitModifier:e,expression:t,initializer:n,statement:r})=>l.factory.createForOfStatement(e,n,t,r),tn=({left:e,right:t})=>l.factory.createAssignment(e,t),F=({multiLine:e=!0,statements:t})=>l.factory.createBlock(t,e),nn=({initializer:e,name:t})=>l.factory.createPropertyAssignment(t,e),rn=({flags:e=[],text:t})=>{let n=`/${(t.startsWith(`/`)&&t.endsWith(`/`)?t.slice(1,-1):t).replace(/(?<!\\)\//g,`\\/`)}/`;return l.factory.createRegularExpressionLiteral(`${n}${e.join(``)}`)},an=({expression:e,type:t})=>l.factory.createAsExpression(e,t),on=({value:e})=>{let t=[],n=``;for(let r of e.slice(0).reverse())if(typeof r==`string`)n=`${r}${n}`;else{let e=t.length?l.factory.createTemplateMiddle(n):l.factory.createTemplateTail(n),i=l.factory.createTemplateLiteralTypeSpan(r,e);t.push(i),n=``}return l.factory.createTemplateLiteralType(l.factory.createTemplateHead(n),t.reverse())},sn=({module:e,shouldAppendJs:t})=>l.factory.createExportDeclaration(void 0,!1,void 0,M.string(t?`${e}.js`:e)),cn=({functionName:e,parameters:t=[],types:n})=>{let r=typeof e==`string`?A({text:e}):e,i=t.filter(e=>e!==void 0).map(e=>typeof e==`string`?A({text:e}):e);return l.factory.createCallExpression(r,n,i)},ln=({exports:e,module:t})=>{let n=Array.isArray(e)?e:[e],r=n.some(e=>typeof e!=`object`||!e.asType),i=n.map(e=>{let t=typeof e==`string`?{name:e}:e;return M.export({alias:t.alias,asType:r&&t.asType,name:t.name})}),a=l.factory.createNamedExports(i),o=M.string(t);return l.factory.createExportDeclaration(void 0,!r,a,o)},un=({assertion:e,comment:t,destructure:n,exportConst:r,expression:i,name:a,typeName:o})=>{let s=e?an({expression:i,type:typeof e==`string`?Xt({typeName:e}):e}):i,c=typeof a==`string`?A({text:a}):a,u=l.factory.createVariableDeclaration(n?l.factory.createObjectBindingPattern([l.factory.createBindingElement(void 0,void 0,c,void 0)]):c,void 0,o?typeof o==`string`?Xt({typeName:o}):o:void 0,s),d=l.factory.createVariableStatement(r?[j({keyword:`export`})]:void 0,l.factory.createVariableDeclarationList([u],l.NodeFlags.Const));return N({comments:t,node:d}),d},dn=({imports:e,module:t})=>{let n=Array.isArray(e)?e:[e],r=n.some(e=>typeof e!=`object`||!e.asType),i,a=[];n.forEach(e=>{let t=typeof e==`string`?{name:e}:e;t.name===`*`&&t.alias?i=t:a.push(M.import({alias:t.alias,asType:r&&t.asType,name:t.name}))});let o=i?l.factory.createNamespaceImport(A({text:i.alias})):l.factory.createNamedImports(a),s=l.factory.createImportClause(!r,void 0,o),c=M.string(t);return l.factory.createImportDeclaration(void 0,s,c)},fn=({accessLevel:e,comment:t,multiLine:n=!0,parameters:r=[],statements:i=[]})=>{let a=e?[j({keyword:e})]:void 0,o=l.factory.createConstructorDeclaration(a,Dt(r),F({multiLine:n,statements:i}));return N({comments:t,node:o}),o},pn=({accessLevel:e,comment:t,isStatic:n=!1,multiLine:r=!0,name:i,parameters:a=[],returnType:o,statements:s=[],types:c=[]})=>{let u=e?[j({keyword:e})]:[];n&&u.push(j({keyword:`static`}));let d=l.factory.createMethodDeclaration(u,void 0,A({text:i}),void 0,c?At(c):void 0,Dt(a),o?P(o):void 0,F({multiLine:r,statements:s}));return N({comments:t,node:d}),d},mn=({decorator:e,exportClass:t,extendedClasses:n,name:r,nodes:i})=>{let a=[];t&&a.push(j({keyword:`export`})),e&&a.unshift(l.factory.createDecorator(cn({functionName:e.name,parameters:e.args.map(e=>Et({value:e})).filter(xt)})));let o=[];if(n)for(let e of n)o.push(l.factory.createHeritageClause(l.SyntaxKind.ExtendsKeyword,[l.factory.createExpressionWithTypeArguments(A({text:e}),void 0)]));return l.factory.createClassDeclaration(a,A({text:r}),void 0,o,i)},hn=({expression:e})=>l.factory.createExpressionStatement(e),gn=({expression:e})=>l.factory.createReturnStatement(e),_n=({args:e=[],name:t,types:n=[]})=>{let r=n.map(e=>Xt({typeName:e}));return gn({expression:cn({functionName:t,parameters:e.map(e=>l.isExpression(e)?e:A({text:e})).filter(xt),types:r})})},vn=({expression:e})=>gn({expression:typeof e==`string`?A({text:e}):e}),yn=e=>e.slice(1).reduce((e,t)=>(ut.lastIndex=0,ut.test(t)?Ct({expression:e,name:t}):l.factory.createElementAccessChain(e,l.factory.createToken(l.SyntaxKind.QuestionDotToken),A({text:t}))),A({text:e[0]})),bn=e=>e.slice(1).reduce((e,t)=>wt({expression:e,name:t}),A({text:e[0]})),xn=({expressions:e})=>e.reduce((e,t)=>wt({expression:e,name:t})),Sn=({left:e,operator:t=`=`,right:n})=>l.factory.createBinaryExpression(e,t===`=`?l.SyntaxKind.EqualsToken:t===`===`?l.SyntaxKind.EqualsEqualsEqualsToken:t===`!==`?l.SyntaxKind.ExclamationEqualsEqualsToken:t===`??`?l.SyntaxKind.QuestionQuestionToken:l.SyntaxKind.InKeyword,typeof n==`string`?A({text:n}):n),Cn=({elseStatement:e,expression:t,thenStatement:n})=>l.factory.createIfStatement(t,n,e),wn=({path:e})=>{let t=yn(e),n=bn(e);return Cn({expression:t,thenStatement:F({statements:[hn({expression:Sn({left:n,right:$t({argumentsArray:[n],expression:A({text:`Date`})})})})]})})},Tn=({path:e,transformerName:t})=>[Cn({expression:yn(e),thenStatement:F({statements:[hn({expression:cn({functionName:t,parameters:[bn(e)]})})]})})],En=({path:e,transformerName:t})=>{let n=yn(e),r=bn(e);return Cn({expression:cn({functionName:wt({expression:`Array`,name:`isArray`}),parameters:[n]}),thenStatement:F({statements:[hn({expression:l.factory.createCallChain(wt({expression:r,name:`forEach`}),void 0,void 0,[A({text:t})])})]})})},Dn=({parameterName:e})=>{let t=A({text:`Date`});return $t({argumentsArray:[A({text:e})],expression:t})},On=({path:e,transformExpression:t})=>{let n=yn(e),r=bn(e);return Cn({expression:cn({functionName:wt({expression:`Array`,name:`isArray`}),parameters:[n]}),thenStatement:F({statements:[hn({expression:Sn({left:r,right:l.factory.createCallChain(wt({expression:r,name:`map`}),void 0,void 0,[Ft({parameters:[{name:`item`}],statements:t})])})})]})})},kn=Xt({typeName:`null`}),An=({isNullable:e,node:t})=>e?l.factory.createUnionTypeNode([t,kn]):t,jn=({indexKey:e,indexProperty:t,isNullable:n,properties:r,useLegacyResolution:i})=>{let a=[],o=r.map(e=>{let t=e.isReadOnly?[j({keyword:`readonly`})]:void 0,n=e.isRequired===!1?l.factory.createToken(l.SyntaxKind.QuestionToken):void 0,r=P(e.type);a.push(r);let o=l.factory.createPropertySignature(t,i||typeof e.name==`string`&&e.name.match(ut)||typeof e.name!=`string`&&l.isPropertyName(e.name)?e.name:Kt({text:e.name}),n,r);return N({comments:e.comment,node:o}),o}),s=!1;if(t)if(!r.length&&e){let n=Nt({questionToken:l.factory.createToken(l.SyntaxKind.QuestionToken),type:t.type??kt({keyword:`string`}),typeParameter:Mt({constraint:e,name:A({text:String(t.name)})})});o.push(n),s=!0}else{let e=t.isReadOnly?[j({keyword:`readonly`})]:void 0,n=l.factory.createIndexSignature(e,[Qt({name:A({text:String(t.name)}),type:kt({keyword:`string`})})],P(t.type));o.push(n)}return An({isNullable:n,node:s?o[0]:l.factory.createTypeLiteralNode(o)})},Mn=({isNullable:e,types:t})=>{let n=[];for(let e of t){let t=P(e);l.isUnionTypeNode(t)?n.push(...t.types):n.push(t)}return An({isNullable:e,node:l.factory.createUnionTypeNode(n)})},I={anonymousFunction:It,arrayLiteralExpression:Lt,arrowFunction:Ft,asExpression:an,assignment:tn,awaitExpression:Rt,binaryExpression:Sn,block:F,callExpression:cn,classDeclaration:mn,conditionalExpression:qt,constVariable:un,constructorDeclaration:fn,enumDeclaration:Vt,exportAllDeclaration:sn,exportNamedDeclaration:ln,expressionToStatement:hn,forOfStatement:en,functionTypeNode:zt,getAccessorDeclaration:Gt,identifier:A,ifStatement:Cn,indexedAccessTypeNode:Wt,isTsNode:bt,keywordTypeNode:kt,literalTypeNode:Pt,mappedTypeNode:Nt,methodDeclaration:pn,namedImportDeclarations:dn,namespaceDeclaration:Ut,newExpression:$t,nodeToString:_t,null:Tt,objectExpression:Bt,ots:M,parameterDeclaration:Qt,propertyAccessExpression:wt,propertyAccessExpressions:xn,propertyAssignment:nn,propertyDeclaration:yt,regularExpressionLiteral:rn,returnFunctionCall:_n,returnStatement:gn,returnVariable:vn,safeAccessExpression:yn,stringLiteral:Kt,templateLiteralType:on,this:vt,transformArrayMap:On,transformArrayMutation:En,transformDateMutation:wn,transformFunctionMutation:Tn,transformNewDate:Dn,typeAliasDeclaration:Yt,typeArrayNode:(e,t=!1)=>An({isNullable:t,node:Xt({typeArguments:[Array.isArray(e)?Mn({types:e}):e],typeName:`Array`})}),typeInterfaceNode:jn,typeIntersectionNode:({isNullable:e,types:t})=>{let n=[];for(let e of t){let t=P(e);l.isIntersectionTypeNode(t)?n.push(...t.types):n.push(t)}return An({isNullable:e,node:l.factory.createIntersectionTypeNode(n)})},typeNode:P,typeOfExpression:Jt,typeOperatorNode:jt,typeParameterDeclaration:Mt,typeParenthesizedNode:Zt,typeRecordNode:(e,t,n=!1,r=!0)=>{let i=Mn({types:e}),a=Mn({types:t});return An({isNullable:n,node:jn({properties:[{name:`[key: ${_t({node:i,unescape:!0})}]`,type:a}],useLegacyResolution:r})})},typeReferenceNode:Xt,typeTupleNode:({isNullable:e=!1,types:t})=>{let n=t.map(e=>P(e));return An({isNullable:e,node:l.factory.createTupleTypeNode(n)})},typeUnionNode:Mn,valueToExpression:Et},Nn=I,Pn=({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},Fn=({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}},In=({operation:e,plugin:t})=>{if(!e.security||!t.config.auth)return[];let n=[];for(let t of e.security){let e=Fn({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},Ln=`TComposable`,Rn=`DefaultT`,zn=`ResT`,Bn=/~1/g,Vn=/~0/g,L=e=>{let t=Un(e),n=t[t.length-1];return decodeURI(n)},Hn=e=>String(e).replace(/~/g,`~0`).replace(/\//g,`~1`),Un=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(Bn,`/`).replace(Vn,`~`)):[]},Wn=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},Gn=e=>{let t=e.map(Hn).join(`/`);return`#`+(t?`/${t}`:``)},Kn=({$ref:e,spec:t})=>{let n=Un(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},qn=({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(x({case:`camelCase`,value:L(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=x({case:`camelCase`,value:L(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}},Jn=({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})},Yn=({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})},Xn=({context:e,value:t})=>{let n=x({case:`PascalCase`,value:nt(t)});return Pn({config:e.config,name:n})},Zn=({operation:e,plugin:t})=>t.config.methodNameBuilder?t.config.methodNameBuilder(e):!t.config.asClass&&e.id.match(st)?`${e.id}_`:e.id,Qn=({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=x({case:`camelCase`,value:nt(o.pop())}),i=o.pop()));let s=n.config.instance?[n.config.instance]:t.tags??[`default`];for(let c of s){let s=Xn({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||Zn({operation:t,plugin:n}),path:l.map(t=>Xn({context:e,value:t}))})}return r},$n=({isDataAllowed:e=!0,operation:t,plugin:n,throwOnError:r})=>{let i=E(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`}),i=e?a?.placeholder||`unknown`:`never`,s=r?.placeholder||`unknown`;return`${o.placeholder}<${Ln}, ${i}, ${s}, ${Rn}>`}if(r){let t=e?a?.placeholder||`unknown`:`never`;return`${o.placeholder}<${t}, ${r}>`}let s=e?a?.placeholder:`never`;return s?`${o.placeholder}<${s}>`:o.placeholder},er=({isRequiredOptions:e,operation:t,plugin:n})=>{let r={argNames:[],fields:[],parameters:[]},i=n.getPluginOrThrow(`@hey-api/typescript`),a=E(n.context.config).name===`@hey-api/client-nuxt`;if(n.config.paramsStructure===`flat`){let e=qn({operation:t,plugin:n}),a=[];if(e){let t=!1;for(let n in e.parameters){let r=e.parameters[n];r.isRequired&&(t=!0),a.push({isRequired:r.isRequired,name:r.name,type:i.api.schemaToType({plugin:i,schema:r.schema,state:O({path:[]})})})}r.argNames.push(`parameters`);for(let t of e.fields)r.fields.push(t);r.parameters.push({isRequired:t,name:`parameters`,type:I.typeInterfaceNode({properties:a,useLegacyResolution:!1})})}}return r.parameters.push({isRequired:e,name:`options`,type:$n({isDataAllowed:n.config.paramsStructure===`grouped`,operation:t,plugin:n,throwOnError:a?void 0:`ThrowOnError`})}),r},tr=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`}},nr=({isRequiredOptions:e,opParameters:t,operation:n,plugin:r})=>{let i=E(r.context.config),a=i.name===`@hey-api/client-nuxt`,o=r.querySymbol({category:`type`,resource:`operation`,resourceId:n.id,role:a?`response`:`responses`})?.placeholder||`unknown`,s=r.querySymbol({category:`type`,resource:`operation`,resourceId:n.id,role:a?`error`:`errors`})?.placeholder||`unknown`,c=[];if(n.body)switch(n.body.type){case`form-data`:{let e=r.referenceSymbol({category:`external`,resource:`client.formDataBodySerializer`});c.push({spread:e.placeholder});break}case`json`:break;case`text`:case`octet-stream`:c.push({key:`bodySerializer`,value:null});break;case`url-search-params`:{let e=r.referenceSymbol({category:`external`,resource:`client.urlSearchParamsBodySerializer`});c.push({spread:e.placeholder});break}}let l=[];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.push({key:t.name,value:[{key:`array`,value:[{key:`explode`,value:t.explode===!0?void 0:t.explode},{key:`style`,value:t.style===`form`?void 0:t.style}].filter(({value:e})=>e!==void 0)}]}):t.schema.type===`object`&&(t.style!==`deepObject`||!t.explode)&&l.push({key:t.name,value:[{key:`object`,value:[{key:`explode`,value:t.explode===!0?void 0:t.explode},{key:`style`,value:t.style===`deepObject`?void 0:t.style}].filter(({value:e})=>e!==void 0)}]})}l.length&&c.push({key:`querySerializer`,value:[{key:`parameters`,value:l}]});let u=Jn({operation:n,plugin:r});if(u&&c.push({key:`requestValidator`,value:u}),r.config.transformer){let e={category:`transform`,resource:`operation`,resourceId:n.id,role:`response`};if(r.isSymbolRegistered(e)){let t=r.referenceSymbol(e);c.push({key:`responseTransformer`,value:t.placeholder})}}let d=!1,f;for(let e in n.responses){let t=n.responses[e];!f&&i.name===`@hey-api/client-axios`&&et({statusCode:e})===`2XX`&&(f=tr(t.mediaType),f&&c.push({key:`responseType`,value:f})),t.mediaType===`text/event-stream`&&(d=!0)}let p=Yn({operation:n,plugin:r});p&&c.push({key:`responseValidator`,value:p}),r.config.responseStyle===`data`&&c.push({key:`responseStyle`,value:r.config.responseStyle});let m=In({context:r.context,operation:n,plugin:r});m.length&&c.push({key:`security`,value:I.arrayLiteralExpression({elements:m})}),c.push({key:`url`,value:n.path}),c.push({spread:`options`});let h=[],g=t.argNames.length;if(g){let e=[],n=[];for(let n of t.argNames)e.push(I.identifier({text:n}));for(let e of t.fields){let t=[];`in`in e&&(t.push({key:`in`,value:e.in}),e.key&&t.push({key:`key`,value:e.key}),e.map&&t.push({key:`map`,value:e.map})),n.push(I.objectExpression({obj:t}))}let i=r.referenceSymbol({category:`external`,resource:`client.buildClientParams`});h.push(I.constVariable({expression:I.callExpression({functionName:i.placeholder,parameters:[I.arrayLiteralExpression({elements:e}),I.arrayLiteralExpression({elements:n})]}),name:`params`})),c.push({spread:`params`})}if(n.body){let t=n.parameters?.header?.[`content-type`];if(!t?.required){let r=[{key:t?.name??`Content-Type`,value:n.body.type===`form-data`?null:n.body.mediaType},{spread:I.propertyAccessExpression({expression:I.identifier({text:`options`}),isOptional:!e,name:`headers`})}];g&&r.push({spread:I.propertyAccessExpression({expression:I.identifier({text:`params`}),name:`headers`})}),c.push({key:`headers`,value:r})}}let ee=r.config.client?r.getSymbol({category:`client`}):void 0,te=I.propertyAccessExpression({expression:I.identifier({text:`options`}),isOptional:!e,name:`client`}),ne;ne=r.config.instance?I.binaryExpression({left:te,operator:`??`,right:I.propertyAccessExpression({expression:I.this(),name:`_client`})}):ee?I.binaryExpression({left:te,operator:`??`,right:ee.placeholder}):te;let _=[];a?_.push(Ln,`${o} | ${Rn}`,s,Rn):_.push(o,s,`ThrowOnError`),r.config.responseStyle===`data`&&_.push(I.stringLiteral({text:r.config.responseStyle}));let v=d?I.propertyAccessExpression({expression:ne,name:I.identifier({text:`sse`})}):ne;return v=I.propertyAccessExpression({expression:v,name:I.identifier({text:n.method})}),h.push(I.returnFunctionCall({args:[I.objectExpression({identifiers:[`responseTransformer`],obj:c})],name:v,types:_})),h},R=({operation:e})=>{let t=[];if(e.summary&&t.push(pt(e.summary)),e.description&&(t.length&&t.push(``),t.push(pt(e.description))),e.deprecated&&(t.length&&t.push(``),t.push(`@deprecated`)),t.length)return t},z=({context:e,operation:t})=>{let n=E(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||Qe(t)},rr=({operation:e})=>{for(let t in e.responses)if(e.responses[t].mediaType===`text/event-stream`)return!0;return!1},ir=({plugin:e})=>{let t=new Map,n=new Set,r=e.getPluginOrThrow(`@hey-api/sdk`);e.forEach(`operation`,({operation:n})=>{let i=z({context:e.context,operation:n}),a=Qn({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=sr({isRequiredOptions:i,methodName:l,operation:n,plugin:e});c.nodes.length?c.nodes.push(I.identifier({text:` `}),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(I.propertyDeclaration({initializer:I.newExpression({argumentsArray:[],expression:I.identifier({text:S({config:{case:`preserve`,name:e.config.httpRequests.classNameBuilder},name:a.className})})}),name:x({case:`camelCase`,value:a.className})}))}let a=e.referenceSymbol({category:`external`,resource:`@angular/core.Injectable`}),o=e.registerSymbol({exported:!0,meta:{category:`utility`,resource:`class`,resourceId:r.className,tool:`angular`},name:S({config:{case:`preserve`,name:e.config.httpRequests.classNameBuilder},name:r.className})}),s=I.classDeclaration({decorator:r.root?{args:[{providedIn:`root`}],name:a.placeholder}:void 0,exportClass:o.exported,name:o.placeholder,nodes:r.nodes});e.setSymbolValue(o,s),n.add(r.className)};for(let e of t.values())i(e)},ar=({plugin:e})=>{e.forEach(`operation`,({operation:t})=>{let n=z({context:e.context,operation:t}),