@hey-api/openapi-ts
Version:
🌀 OpenAPI to TypeScript codegen. Production-ready SDKs, Zod schemas, TanStack Query hooks, and 20+ plugins. Used by Vercel, OpenCode, and PayPal.
3 lines (2 loc) • 351 kB
JavaScript
import{createRequire as e}from"node:module";import{Project as t,StructureModel as n,fromRef as r,isNode as i,isRef as a,isSymbol as o,log as s,nodeBrand as c,ref as l,refs as u}from"@hey-api/codegen-core";import d from"ansi-colors";import f from"node:fs";import p from"node:path";import{fileURLToPath as m}from"node:url";import h from"typescript";import{EOL as ee}from"node:os";import*as te from"semver";import{getResolvedInput as ne,sendRequest as re}from"@hey-api/json-schema-ref-parser";var g=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),ie=e(import.meta.url);const ae=m(import.meta.url),oe=p.dirname(ae),se=()=>{let e=oe;for(;e!==p.dirname(e);){let t=f.readdirSync(e).filter(e=>e===`package.json`);if(t[0]){let n=p.join(e,t[0]);return JSON.parse(f.readFileSync(n,{encoding:`utf8`}))}e=p.dirname(e)}},ce=()=>{let e=se(),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},le=e=>{if(e===null)return null;if(e){let t=p.isAbsolute(e)?e:p.resolve(oe,e);return f.existsSync(t)?t:null}let t=oe;for(;t!==p.dirname(t);){let e=f.readdirSync(t).filter(e=>e.startsWith(`tsconfig`)&&e.endsWith(`.json`)).sort(e=>e===`tsconfig.json`?-1:1);if(e[0])return p.join(t,e[0]);t=p.dirname(t)}return null},ue=e=>{if(!e)return null;let t=h.readConfigFile(e,h.sys.readFile);if(t.error)throw Error(`Couldn't read tsconfig from path: ${e}`);return h.parseJsonConfigFileContent(t.config,h.sys,p.dirname(e))},de=e=>{f.existsSync(e)||f.mkdirSync(e,{recursive:!0})};var fe=class extends Error{constructor(e){super(e),this.name=`ConfigError`}},pe=class extends Error{errors;constructor(e){super(`Found ${e.length} configuration ${e.length===1?`error`:`errors`}.`),this.name=`ConfigValidationError`,this.errors=e}},me=class extends Error{originalError;constructor(e,t){super(e),this.name=`JobError`,this.originalError=t}},he=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 ge=(e,t)=>{if(e instanceof fe||e instanceof pe)return;e instanceof me&&(e=e.originalError.error);let n=`openapi-ts-error-${Date.now()}.log`,r=p.resolve(process.cwd(),t);de(r);let i=p.resolve(r,n),a=`[${new Date().toISOString()}] `;e instanceof he&&(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`),f.writeFileSync(i,a),i},_e=async e=>{let t=ce();if(!t.bugs.url)return;e instanceof me&&(e=e.originalError.error);let n=``;e instanceof he&&(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)},ve=({error:e,logPath:t})=>{if(e instanceof pe&&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=d.gray(`[Job ${e+1}] `),r=n.length,i=d.red(`Found ${r} configuration ${r===1?`error`:`errors`}:`);console.error(`${t}❗️ ${i}`),n.forEach((e,n)=>{let r=` [${n+1}] `,i=d.red(r);console.error(`${t}${i}${d.white(e.message)}`)})}}else{let t=d.gray(`[root] `);e instanceof me&&(t=d.gray(`[Job ${e.originalError.jobIndex+1}] `),e=e.originalError.error);let n=d.red(`Failed with the message:`);console.error(`${t}❌ ${n}`);let r=d.red(` `);console.error(`${t}${r}${typeof e==`string`?e:e instanceof Error?e.message:`Unknown error`}`)}if(t){let e=d.gray(`[root] `);console.error(`${e}${d.cyan(`📄 Crash log saved to:`)} ${d.gray(t)}`)}},ye=async({error:e,isInteractive:t})=>!t||e instanceof fe||e instanceof pe?!1:new Promise(e=>{let t=d.gray(`[root] `);console.log(`${t}${d.yellow(`📢 Open a GitHub issue with crash details? (y/N):`)}`),process.stdin.setEncoding(`utf8`),process.stdin.once(`data`,t=>{e(t.trim().toLowerCase()===`y`)})}),be=/^([\w-]+)\/([\w-]+)(?:\?([\w=&.-]*))?$/,xe=`https://get.heyapi.dev`,Se=(e,t,n)=>`${xe}/${e}/${t}${n?`?${n}`:``}`,Ce=e=>{let t=e.organization,n=e.project,r;if(e.path){let i=e.path.match(be);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}},we=e=>{let t=Ce(e);return{path:Se(t.organization,t.project,t.queryParams),registry:`hey-api`}},Te=/^(@([\w-]+)\/([\w\-.]+)#)?([\w-]+)$/,Ee=e=>`https://dash.readme.com/api/v1/api-registry/${e}`,De=`readme`,Oe=e=>{let t=e.match(Te);if(!t)throw Error(`Invalid ReadMe shorthand format. Expected "${De}:@organization/project#uuid" or "${De}:uuid", received: ${De}:${e}`);let[,,n,r,i]=t;if(!i)throw Error(`The ReadMe UUID cannot be empty.`);return{organization:n,project:r,uuid:i}},ke=e=>{let t=Oe(e.slice(`${De}:`.length));return{...t,path:Ee(t.uuid),registry:`readme`}},Ae=/^(@[\w-]+)\/([\w.-]+)$/,je=(e,t)=>`https://registry.scalar.com/${e}/apis/${t}/latest?format=json`,Me=`scalar`,Ne=e=>{let t=e.match(Ae);if(!t)throw Error(`Invalid Scalar shorthand format. Expected "${Me}:@organization/project", received: ${Me}:${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}},Pe=e=>{let t=Ne(e.slice(`${Me}:`.length));return{...t,path:je(t.organization,t.project),registry:`scalar`}},Fe=e=>{if(e.path.startsWith(`readme:`)){Object.assign(e,ke(e.path));return}if(e.path.startsWith(`scalar:`)){Object.assign(e,Pe(e.path));return}if(e.path.startsWith(`.`))return;if(e.path.startsWith(xe)){e.path=e.path.slice(23),Object.assign(e,we(e));return}let t=e.path.split(`/`);if(t.length===2&&t.filter(Boolean).length===2){Object.assign(e,we(e));return}},Ie={enabled:!1,interval:1e3,timeout:6e4},Le=e=>{let t={...Ie};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},Re=e=>{let t=e.input instanceof Array?e.input:[e.input],n=[];for(let r of t){let t={path:``,watch:Ie};typeof r==`string`?t.path=r:r&&(r.path!==void 0||r.organization!==void 0)?(t={...t,path:xe,...r},t.watch!==void 0&&(t.watch=Le(t))):t={...t,path:r},typeof t.path==`string`&&Fe(t),e.watch!==void 0&&t.watch.enabled===Ie.enabled&&t.watch.interval===Ie.interval&&t.watch.timeout===Ie.timeout&&(t.watch=Le({path:t.path,watch:e.watch})),t.path&&n.push(t)}return n},ze=e=>{let t={file:!0,level:`info`,path:process.cwd()};return typeof e?.logs==`string`?t.path=e.logs:t={...t,...e?.logs},t},Be=(e,t)=>{let n=e||{},r=t||{};return{...n,...r}},Ve=(e,t)=>{let n=e||{},r=t||{},i={...n,...r};return typeof i.logs==`object`&&(i.logs=Be(n.logs,r.logs)),i},He=e=>typeof e==`object`&&!!e&&!Array.isArray(e)&&typeof e!=`function`,Ue=(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=Ue(r,e(n))}break;case`function`:if(t&&`function`in t){let e=t.function;r=Ue(r,e(n))}break;case`number`:if(t&&`number`in t){let e=t.number;r=Ue(r,e(n))}break;case`string`:if(t&&`string`in t){let e=t.string;r=Ue(r,e(n))}break;case`object`:if(He(n))if(t&&`object`in t&&typeof t.object==`function`){let i=t.object;r=Ue(r,i(n,e))}else r=Ue(r,n);break}return r};function We(e){let t=_({defaultValue:{enabled:!!e.source,extension:`json`,fileName:`source`,serialize:e=>JSON.stringify(e,null,2)},mappers:{boolean:e=>({enabled:e})},value:e.source});return t.path===void 0||t.path===!0?t.path=``:t.path===!1&&(t.path=null),t}function Ge(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,header:`// This file is auto-generated by @hey-api/openapi-ts`,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=ue(le(t.tsConfigPath)),t.importFileExtension===void 0&&(t.tsConfig?.options.moduleResolution===h.ModuleResolutionKind.NodeNext||t.tsConfig?.options.moduleResolution===h.ModuleResolutionKind.Node16)&&(t.importFileExtension=`.js`),t.importFileExtension&&!t.importFileExtension.startsWith(`.`)&&(t.importFileExtension=`.${t.importFileExtension}`),t.source=We(t),t}var Ke=g(((e,t)=>{t.exports=a,a.sync=o;var n=ie(`fs`);function r(e,t){var n=t.pathExt===void 0?process.env.PATHEXT:t.pathExt;if(!n||(n=n.split(`;`),n.indexOf(``)!==-1))return!0;for(var r=0;r<n.length;r++){var i=n[r].toLowerCase();if(i&&e.substr(-i.length).toLowerCase()===i)return!0}return!1}function i(e,t,n){return!e.isSymbolicLink()&&!e.isFile()?!1:r(t,n)}function a(e,t,r){n.stat(e,function(n,a){r(n,n?!1:i(a,e,t))})}function o(e,t){return i(n.statSync(e),e,t)}})),qe=g(((e,t)=>{t.exports=r,r.sync=i;var n=ie(`fs`);function r(e,t,r){n.stat(e,function(e,n){r(e,e?!1:a(n,t))})}function i(e,t){return a(n.statSync(e),t)}function a(e,t){return e.isFile()&&o(e,t)}function o(e,t){var n=e.mode,r=e.uid,i=e.gid,a=t.uid===void 0?process.getuid&&process.getuid():t.uid,o=t.gid===void 0?process.getgid&&process.getgid():t.gid,s=64,c=8,l=1,u=s|c;return n&l||n&c&&i===o||n&s&&r===a||n&u&&a===0}})),Je=g(((e,t)=>{ie(`fs`);var n=process.platform===`win32`||global.TESTING_WINDOWS?Ke():qe();t.exports=r,r.sync=i;function r(e,t,i){if(typeof t==`function`&&(i=t,t={}),!i){if(typeof Promise!=`function`)throw TypeError(`callback not provided`);return new Promise(function(n,i){r(e,t||{},function(e,t){e?i(e):n(t)})})}n(e,t||{},function(e,n){e&&(e.code===`EACCES`||t&&t.ignoreErrors)&&(e=null,n=!1),i(e,n)})}function i(e,t){try{return n.sync(e,t||{})}catch(e){if(t&&t.ignoreErrors||e.code===`EACCES`)return!1;throw e}}})),Ye=g(((e,t)=>{let n=process.platform===`win32`||process.env.OSTYPE===`cygwin`||process.env.OSTYPE===`msys`,r=ie(`path`),i=n?`;`:`:`,a=Je(),o=e=>Object.assign(Error(`not found: ${e}`),{code:`ENOENT`}),s=(e,t)=>{let r=t.colon||i,a=e.match(/\//)||n&&e.match(/\\/)?[``]:[...n?[process.cwd()]:[],...(t.path||process.env.PATH||``).split(r)],o=n?t.pathExt||process.env.PATHEXT||`.EXE;.CMD;.BAT;.COM`:``,s=n?o.split(r):[``];return n&&e.indexOf(`.`)!==-1&&s[0]!==``&&s.unshift(``),{pathEnv:a,pathExt:s,pathExtExe:o}},c=(e,t,n)=>{typeof t==`function`&&(n=t,t={}),t||={};let{pathEnv:i,pathExt:c,pathExtExe:l}=s(e,t),u=[],d=n=>new Promise((a,s)=>{if(n===i.length)return t.all&&u.length?a(u):s(o(e));let c=i[n],l=/^".*"$/.test(c)?c.slice(1,-1):c,d=r.join(l,e);a(f(!l&&/^\.[\\\/]/.test(e)?e.slice(0,2)+d:d,n,0))}),f=(e,n,r)=>new Promise((i,o)=>{if(r===c.length)return i(d(n+1));let s=c[r];a(e+s,{pathExt:l},(a,o)=>{if(!a&&o)if(t.all)u.push(e+s);else return i(e+s);return i(f(e,n,r+1))})});return n?d(0).then(e=>n(null,e),n):d(0)};t.exports=c,c.sync=(e,t)=>{t||={};let{pathEnv:n,pathExt:i,pathExtExe:c}=s(e,t),l=[];for(let o=0;o<n.length;o++){let s=n[o],u=/^".*"$/.test(s)?s.slice(1,-1):s,d=r.join(u,e),f=!u&&/^\.[\\\/]/.test(e)?e.slice(0,2)+d:d;for(let e=0;e<i.length;e++){let n=f+i[e];try{if(a.sync(n,{pathExt:c}))if(t.all)l.push(n);else return n}catch{}}}if(t.all&&l.length)return l;if(t.nothrow)return null;throw o(e)}})),Xe=g(((e,t)=>{let n=(e={})=>{let t=e.env||process.env;return(e.platform||process.platform)===`win32`?Object.keys(t).reverse().find(e=>e.toUpperCase()===`PATH`)||`Path`:`PATH`};t.exports=n,t.exports.default=n})),Ze=g(((e,t)=>{let n=ie(`path`),r=Ye(),i=Xe();function a(e,t){let a=e.options.env||process.env,o=process.cwd(),s=e.options.cwd!=null,c=s&&process.chdir!==void 0&&!process.chdir.disabled;if(c)try{process.chdir(e.options.cwd)}catch{}let l;try{l=r.sync(e.command,{path:a[i({env:a})],pathExt:t?n.delimiter:void 0})}catch{}finally{c&&process.chdir(o)}return l&&=n.resolve(s?e.options.cwd:``,l),l}function o(e){return a(e)||a(e,!0)}t.exports=o})),Qe=g(((e,t)=>{let n=/([()\][%!^"`<>&|;, *?])/g;function r(e){return e=e.replace(n,`^$1`),e}function i(e,t){return e=`${e}`,e=e.replace(/(?=(\\+?)?)\1"/g,`$1$1\\"`),e=e.replace(/(?=(\\+?)?)\1$/,`$1$1`),e=`"${e}"`,e=e.replace(n,`^$1`),t&&(e=e.replace(n,`^$1`)),e}t.exports.command=r,t.exports.argument=i})),$e=g(((e,t)=>{t.exports=/^#!(.*)/})),et=g(((e,t)=>{let n=$e();t.exports=(e=``)=>{let t=e.match(n);if(!t)return null;let[r,i]=t[0].replace(/#! ?/,``).split(` `),a=r.split(`/`).pop();return a===`env`?i:i?`${a} ${i}`:a}})),tt=g(((e,t)=>{let n=ie(`fs`),r=et();function i(e){let t=Buffer.alloc(150),i;try{i=n.openSync(e,`r`),n.readSync(i,t,0,150,0),n.closeSync(i)}catch{}return r(t.toString())}t.exports=i})),nt=g(((e,t)=>{let n=ie(`path`),r=Ze(),i=Qe(),a=tt(),o=process.platform===`win32`,s=/\.(?:com|exe)$/i,c=/node_modules[\\/].bin[\\/][^\\/]+\.cmd$/i;function l(e){e.file=r(e);let t=e.file&&a(e.file);return t?(e.args.unshift(e.file),e.command=t,r(e)):e.file}function u(e){if(!o)return e;let t=l(e),r=!s.test(t);if(e.options.forceShell||r){let r=c.test(t);e.command=n.normalize(e.command),e.command=i.command(e.command),e.args=e.args.map(e=>i.argument(e,r)),e.args=[`/d`,`/s`,`/c`,`"${[e.command].concat(e.args).join(` `)}"`],e.command=process.env.comspec||`cmd.exe`,e.options.windowsVerbatimArguments=!0}return e}function d(e,t,n){t&&!Array.isArray(t)&&(n=t,t=null),t=t?t.slice(0):[],n=Object.assign({},n);let r={command:e,args:t,options:n,file:void 0,original:{command:e,args:t}};return n.shell?r:u(r)}t.exports=d})),rt=g(((e,t)=>{let n=process.platform===`win32`;function r(e,t){return Object.assign(Error(`${t} ${e.command} ENOENT`),{code:`ENOENT`,errno:`ENOENT`,syscall:`${t} ${e.command}`,path:e.command,spawnargs:e.args})}function i(e,t){if(!n)return;let r=e.emit;e.emit=function(n,i){if(n===`exit`){let n=a(i,t);if(n)return r.call(e,`error`,n)}return r.apply(e,arguments)}}function a(e,t){return n&&e===1&&!t.file?r(t.original,`spawn`):null}function o(e,t){return n&&e===1&&!t.file?r(t.original,`spawnSync`):null}t.exports={hookChildProcess:i,verifyENOENT:a,verifyENOENTSync:o,notFoundError:r}})),it=g(((e,t)=>{let n=ie(`child_process`),r=nt(),i=rt();function a(e,t,a){let o=r(e,t,a),s=n.spawn(o.command,o.args,o.options);return i.hookChildProcess(s,o),s}function o(e,t,a){let o=r(e,t,a),s=n.spawnSync(o.command,o.args,o.options);return s.error=s.error||i.verifyENOENTSync(s.status,o),s}t.exports=a,t.exports.spawn=a,t.exports.sync=o,t.exports._parse=r,t.exports._enoent=i}))();const at={biome:{args:e=>[`format`,`--write`,e],command:`biome`,name:`Biome (Format)`},prettier:{args:e=>[`--ignore-unknown`,e,`--write`,`--ignore-path`,`./.prettierignore`],command:`prettier`,name:`Prettier`}},ot={biome:{args:e=>[`lint`,`--apply`,e],command:`biome`,name:`Biome (Lint)`},eslint:{args:e=>[e,`--fix`],command:`eslint`,name:`ESLint`},oxlint:{args:e=>[`--fix`,e],command:`oxlint`,name:`oxlint`}},st=e=>{if(e.lint){let t=ot[e.lint];console.log(`✨ Running ${t.name}`),(0,it.sync)(t.command,t.args(e.path))}if(e.format){let t=at[e.format];console.log(`✨ Running ${t.name}`),(0,it.sync)(t.command,t.args(e.path))}},ct=e=>{let t=e?p.dirname(e):process.cwd();for(;t!==p.dirname(t);){let e=p.join(t,`package.json`);if(f.existsSync(e))try{let t=JSON.parse(f.readFileSync(e,`utf8`));return{...t.dependencies,...t.devDependencies,...t.peerDependencies,...t.optionalDependencies}}catch{}let n=p.dirname(t);if(n===t)break;t=n}return{}},lt=[`after`,`before`,`cursor`,`offset`,`page`,`start`],ut=e=>_({defaultValue:{hooks:{},pagination:{keywords:lt},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}),dt=e=>t=>({...e,config:{...e.config,...t}}),v={boolean:e=>({enabled:e}),function:e=>({name:e}),string:e=>({name:e})};function ft(e,t){let n=e.httpRequests;typeof n==`string`||typeof n==`function`?n={strategy:n}:(typeof n==`boolean`||!n)&&(n={enabled:!!n});let r=n.strategy??`flat`;return t.valueToObject({defaultValue:{container:`class`,enabled:!0,methods:`instance`,nesting:`operationId`,nestingDelimiters:/[./]/,strategy:r,strategyDefaultTag:`default`},mappers:{object(e){return e.containerName=t.valueToObject({defaultValue:r===`single`?{casing:`PascalCase`,name:`HttpRequests`}:{casing:`PascalCase`},mappers:{function:e=>({name:e}),string:e=>({name:e})},value:e.containerName}),e.methodName=t.valueToObject({defaultValue:r===`flat`?{casing:`camelCase`,name:`{{name}}Request`}:{casing:`camelCase`},mappers:{function:e=>({name:e}),string:e=>({name:e})},value:e.methodName}),e.segmentName=t.valueToObject({defaultValue:{casing:`PascalCase`,name:`{{name}}Requests`},mappers:{function:e=>({name:e}),string:e=>({name:e})},value:e.segmentName}),e}},value:n})}const y={byTags:e=>t=>{let n=t.tags&&t.tags.length>0?t.tags:[e.fallback],r=(e.path??b.id())(t);return n.map(e=>[e,...r])},flat:e=>t=>{let n=(e?.path??b.id())(t);return[[n[n.length-1]]]},single:e=>t=>{let n=(e.path??b.id())(t);return[[e.root,...n]]}},b={fromOperationId:e=>t=>{let n=e?.fallback??b.id();if(!t.operationId)return n(t);let r=e?.delimiters??/[./]/,i=t.operationId.split(r).filter(Boolean);return i.length===0?n(t):i},fromPath:e=>t=>{let n=e?.delimiters??/[./]/,r=t.path.split(n).filter(Boolean);switch(e?.methodPosition){case`prefix`:r.unshift(t.method.toLowerCase());break;case`suffix`:r.push(t.method.toLowerCase());break;default:break}return r},id:()=>e=>[e.id]};function pt(e){return e.config.httpRequests.nesting===`id`?b.id():e.config.httpRequests.nesting===`operationId`?b.fromOperationId({delimiters:e.config.httpRequests.nestingDelimiters,fallback:b.id()}):e.config.httpRequests.nesting}function mt(e){if(e.config.httpRequests.strategy===`flat`)return y.flat({path:t=>[pt(e)(t).join(`.`)]});if(e.config.httpRequests.strategy===`single`){let t=e.config.httpRequests.containerName;return y.single({path:pt(e),root:typeof t.name==`string`?t.name:t.name?.(``)??``})}return e.config.httpRequests.strategy===`byTags`?y.byTags({fallback:e.config.httpRequests.strategyDefaultTag,path:pt(e)}):e.config.httpRequests.strategy}function ht(e,t){let n=e.httpResources;typeof n==`string`||typeof n==`function`?n={strategy:n}:(typeof n==`boolean`||!n)&&(n={enabled:!!n});let r=n.strategy??`flat`;return t.valueToObject({defaultValue:{container:`class`,enabled:!0,methods:`instance`,nesting:`operationId`,nestingDelimiters:/[./]/,strategy:r,strategyDefaultTag:`default`},mappers:{object(e){return e.containerName=t.valueToObject({defaultValue:r===`single`?{casing:`PascalCase`,name:`HttpResources`}:{casing:`PascalCase`},mappers:{function:e=>({name:e}),string:e=>({name:e})},value:e.containerName}),e.methodName=t.valueToObject({defaultValue:r===`flat`?{casing:`camelCase`,name:`{{name}}Resource`}:{casing:`camelCase`},mappers:{function:e=>({name:e}),string:e=>({name:e})},value:e.methodName}),e.segmentName=t.valueToObject({defaultValue:{casing:`PascalCase`,name:`{{name}}Resources`},mappers:{function:e=>({name:e}),string:e=>({name:e})},value:e.segmentName}),e}},value:n})}function gt(e){return e.config.httpResources.nesting===`id`?b.id():e.config.httpResources.nesting===`operationId`?b.fromOperationId({delimiters:e.config.httpResources.nestingDelimiters,fallback:b.id()}):e.config.httpResources.nesting}function _t(e){if(e.config.httpResources.strategy===`flat`)return y.flat({path:t=>[gt(e)(t).join(`.`)]});if(e.config.httpResources.strategy===`single`){let t=e.config.httpResources.containerName;return y.single({path:gt(e),root:typeof t.name==`string`?t.name:t.name?.(``)??``})}return e.config.httpResources.strategy===`byTags`?y.byTags({fallback:e.config.httpResources.strategyDefaultTag,path:gt(e)}):e.config.httpResources.strategy}const vt=e=>{let t=x(e);return t.name===`@hey-api/client-axios`||t.name===`@hey-api/client-nuxt`?`baseURL`:`baseUrl`},x=e=>{for(let t of e.pluginOrder){let n=e.plugins[t];if(n?.tags?.includes(`client`))return n}return{config:{name:``},name:``}},yt=({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]},bt=e=>{for(let t in e)if(e[t].required)return!0;return!1},xt=e=>e?!!(bt(e.cookie)||bt(e.header)||bt(e.path)||bt(e.query)):!1,St=({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:yt({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:yt({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:yt({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:yt({context:e,parameter:r})}}}},S=({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},C=({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,Ct=e=>!!(xt(e.parameters)||e.body?.required),w=({method:e,path:t})=>`${e.toUpperCase()} ${t}`,wt=({context:e,operation:t})=>{let n=t.body;if(!n||!n.pagination)return St({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}:St({context:e,parameters:t.parameters})},Tt=({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`}},Et=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(Tt({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=C({items:Object.values(n.properties),mutateSchemaOneItem:!0,schema:{}});e=S({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=C({items:Object.values(r.properties),mutateSchemaOneItem:!0,schema:{}});e=S({schema:e}),Object.keys(e).length&&e.type!==`unknown`&&(t.response=e)}return t};var T=class{analyze(e){}clone(){let e=Object.create(Object.getPrototypeOf(this));return Object.assign(e,this),e}exported;file;get name(){return{...this._name,set:e=>{this._name=l(e),o(e)&&e.setNode(this)},toString:()=>this._name?this.$name(this._name):``}}nameSanitizer;language=`typescript`;parent;root=!1;scope=`value`;structuralChildren;structuralParents;symbol;toAst(){}"~brand"=c;$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`?h.factory.createIdentifier(e):e}$name(e){let t=r(e);if(o(t))try{return t.finalName}catch{return t.name}return String(t)}$node(e){if(e!==void 0)return a(e)&&(e=r(e)),o(e)?this.$maybeId(e.finalName):typeof e==`string`?this.$maybeId(e):e instanceof Array?e.map(e=>(a(e)&&(e=r(e)),this.unwrap(e))):this.unwrap(e)}$type(e,t){if(e!==void 0){if(a(e)&&(e=r(e)),o(e))return h.factory.createTypeReferenceNode(e.finalName,t);if(typeof e==`string`)return h.factory.createTypeReferenceNode(e,t);if(typeof e==`boolean`){let t=e?h.factory.createTrue():h.factory.createFalse();return h.factory.createLiteralTypeNode(t)}return typeof e==`number`?h.factory.createLiteralTypeNode(h.factory.createNumericLiteral(e)):e instanceof Array?e.map(e=>this.$type(e,t)):this.unwrap(e)}}_name;unwrap(e){return i(e)?e.toAst():e}},Dt=class extends T{};const Ot=T;var kt=class extends Ot{"~dsl"=`IdTsDsl`;constructor(e){super(),this.name.set(e)}analyze(e){super.analyze(e)}toAst(){return h.factory.createIdentifier(this.name.toString())}},At=class extends T{"~dsl"=`NewlineTsDsl`;analyze(e){super.analyze(e)}toAst(){return this.$node(new kt(`
`))}};function jt(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(l(e)),this}args(...e){return this._args.push(...e.filter(e=>e!==void 0).map(e=>l(e))),this}$args(){return this.$node(this._args).map(e=>this.$node(e))}}return t}const Mt=T;var Nt=class extends Mt{"~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=h.SyntaxKind.MinusToken,this}not(){return this._op=h.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 h.factory.createPrefixUnaryExpression(this._op,this.$node(this._expr))}};function E(e){let t,n=((...n)=>{if(!t)throw Error(`${e} factory not registered`);return t(...n)});return n.set=e=>{t=e},n}const D={as:E(`as`),attr:E(`attr`),await:E(`await`),call:E(`call`),new:E(`new`),return:E(`return`),type:{expr:E(`type.expr`),idx:E(`type.idx`),operator:E(`type.operator`),query:E(`type.query`)},typeofExpr:E(`typeofExpr`)};function O(e){class t extends e{analyze(e){super.analyze(e)}as(...e){return D.as(this,...e)}}return t}const Pt=O(T);var k=class extends Pt{"~dsl"=`LiteralTsDsl`;value;constructor(e){super(),this.value=e}analyze(e){super.analyze(e)}toAst(){if(typeof this.value==`boolean`)return this.value?h.factory.createTrue():h.factory.createFalse();if(typeof this.value==`number`){let e=h.factory.createNumericLiteral(Math.abs(this.value));return this.value<0?this.$node(new Nt(e).neg()):e}if(typeof this.value==`string`)return h.factory.createStringLiteral(this.value,!0);if(typeof this.value==`bigint`)return h.factory.createBigIntLiteral(this.value.toString());if(this.value===null)return h.factory.createNull();throw Error(`Unsupported literal: ${String(this.value)}`)}};const A={illegalStartCharacters:/^[^$_\p{ID_Start}]+/u,number:/^-?\d+(\.\d+)?$/,typeScriptIdentifier:/^[$_\p{ID_Start}][$\u200c\u200d\p{ID_Continue}]*$/u},Ft={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 It=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 Lt={runtime:new It([...Ft.browserGlobals,...Ft.javaScriptGlobals,...Ft.javaScriptKeywords,...Ft.nodeGlobals,...Ft.typeScriptKeywords]),type:new It([...Ft.javaScriptKeywords,...Ft.typeScriptKeywords])},Rt=e=>(A.number.lastIndex=0,A.number.test(e)?e.startsWith(`-`)?`'${e}'`:e:(A.typeScriptIdentifier.lastIndex=0,A.typeScriptIdentifier.test(e)?e:`'${e}'`)),zt=e=>(A.typeScriptIdentifier.lastIndex=0,A.typeScriptIdentifier.test(e)?new kt(e):new k(e)),Bt=e=>(A.number.lastIndex=0,A.number.test(e)?e.startsWith(`-`)?new k(e):new k(Number(e)):(A.typeScriptIdentifier.lastIndex=0,A.typeScriptIdentifier.test(e)?new kt(e):new k(e))),Vt=(e,t)=>{let n=``,r,i=e[0];for(A.illegalStartCharacters.lastIndex=0,A.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||`_`},Ht=e=>Vt(e,Lt.runtime),Ut=e=>Vt(e,Lt.type),Wt=jt(T);var Gt=class extends Wt{"~dsl"=`DecoratorTsDsl`;nameSanitizer=Ht;constructor(e,...t){super(),this.name.set(e),this.args(...t)}analyze(e){super.analyze(e),e.analyze(this.name)}toAst(){let e=this.$node(this.name),t=this.$args();return h.factory.createDecorator(t.length?h.factory.createCallExpression(e,void 0,t):e)}};function Kt(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 Gt(e,...t)),this}$decorators(){return this.$node(this.decorators)}}return t}function qt(e){let t;return e.forEach((e,n)=>{t=n===0?e:t.attr(e.name)}),t}function Jt(e){let t=$t([...Xt(e,new Set)]);return t.length===0?[e.clone()]:t.map(e=>e.clone())}function Yt(e){return e.scope??`value`}function Xt(e,t){if(t.has(e)||(t.add(e),Qt(e)))return[];if(e.structuralParents)for(let[n]of e.structuralParents){if(Yt(n)!==Yt(e))continue;let r=Xt(n,t);if(r.length>0)return[...r,e]}return e.root?[e]:[]}function Zt(e){return e[`~dsl`]===`FieldTsDsl`||e[`~dsl`]===`GetterTsDsl`||e[`~dsl`]===`MethodTsDsl`}function Qt(e){return e[`~dsl`]===`FuncTsDsl`||e[`~dsl`]===`TemplateTsDsl`}function $t(e){let t=[];return e.forEach((e,n)=>{(n===0||Zt(e))&&t.push(e)}),t}function en(e,t={}){return e.map((n,r)=>{let i=t.transform?.(n,r,e);if(i)return i;let a=n.toAccessNode?.(n,t,{chain:e,index:r,isLeaf:r===e.length-1,isRoot:r===0,length:e.length});if(a)return a;if(r===0){if(n[`~dsl`]===`ClassTsDsl`){let t=e[r+1];return t&&Zt(t)&&t.hasModifier(`static`)?I(n.name):I.new(n.name).args()}return I(n.name)}return n})}var tn=class{access(e,t){let n=o(e)?e.node:e;if(!n)throw Error(`Symbol ${e.name} is not resolved to a node.`);return qt(en(Jt(n),t))}example(e,t,n){if(n)return Di.astToString(n);t||={};let r=Jt(e);t.importName&&r[0].name.set(t.importName);let i=I(r[0].name.toString()),a=en(r,{context:`example`}),o=t.importSetup?typeof t.importSetup==`function`?t.importSetup({$:I,node:i}):t.importSetup:a[0],s=t.setupName,c=typeof t.payload==`function`?t.payload({$:I}):t.payload;c=c instanceof Array?c:c?[c]:[];let l=[];l=s?[I.const(s).assign(o),I.await(qt([I(s),...a.slice(1)]).call(...c))]:[I.await(qt([o,...a.slice(1)]).call(...c))];let u=i.name.toString();return Di.astToString({imports:[[{imports:!t.importKind||t.importKind===`named`?[{isTypeOnly:!1,localName:u,sourceName:u}]:[],isTypeOnly:!1,kind:t.importKind??`named`,localName:t.importKind===`named`?void 0:u,modulePath:t.moduleName??`your-package`}]],nodes:l,trailingNewline:!1})}};const nn=new tn;var rn=class extends T{"~dsl"=`DocTsDsl`;_lines=[];constructor(e,t){super(),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.reduce((e,t)=>{typeof t==`function`&&(t=t(nn));for(let n of typeof t==`string`?[t]:t)(n||n===``)&&e.push(n);return e},[]);if(!t.length)return e;let n=t.map(e=>h.factory.createJSDocText(`${e}\n`)),r=h.factory.createJSDocComment(h.factory.createNodeArray(n),void 0),i=h.createPrinter().printNode(h.EmitHint.Unspecified,r,e.getSourceFile?.()??h.createSourceFile(``,``,h.ScriptTarget.Latest)).replace(`/*`,``).replace(`* */`,``);return h.addSyntheticLeadingComment(e,h.SyntaxKind.MultiLineCommentTrivia,i,!0),e}toAst(){return this.$node(new kt(``))}};function j(e){class t extends e{_doc;analyze(e){super.analyze(e)}doc(e,t){return this._doc=new rn(e,t),this}$docs(e){return this._doc?this._doc.apply(e):e}}return t}function an(e){switch(e){case`abstract`:return h.SyntaxKind.AbstractKeyword;case`async`:return h.SyntaxKind.AsyncKeyword;case`const`:return h.SyntaxKind.ConstKeyword;case`declare`:return h.SyntaxKind.DeclareKeyword;case`default`:return h.SyntaxKind.DefaultKeyword;case`export`:return h.SyntaxKind.ExportKeyword;case`override`:return h.SyntaxKind.OverrideKeyword;case`private`:return h.SyntaxKind.PrivateKeyword;case`protected`:return h.SyntaxKind.ProtectedKeyword;case`public`:return h.SyntaxKind.PublicKeyword;case`readonly`:return h.SyntaxKind.ReadonlyKeyword;case`static`:return h.SyntaxKind.StaticKeyword}}function M(e){class t extends e{modifiers=[];analyze(e){super.analyze(e)}hasModifier(e){let t=an(e);return!!this.modifiers.find(e=>e.kind===t)}_m(e,t){if(t){let t=an(e);this.modifiers.push(h.factory.createModifier(t))}return this}}return t}function on(e){let t=M(e);class n extends t{abstract(e){let t=arguments.length===0?!0:!!e;return this._m(`abstract`,t)}}return n}function sn(e){let t=M(e);class n extends t{async(e){let t=arguments.length===0?!0:!!e;return this._m(`async`,t)}}return n}function cn(e){let t=M(e);class n extends t{const(e){let t=arguments.length===0?!0:!!e;return this._m(`const`,t)}}return n}function ln(e){let t=M(e);class n extends t{default(e){let t=arguments.length===0?!0:!!e;return this._m(`default`,t)}}return n}function un(e){let t=M(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(`export`,t)}}return n}function dn(e){let t=M(e);class n extends t{private(e){let t=arguments.length===0?!0:!!e;return this._m(`private`,t)}}return n}function fn(e){let t=M(e);class n extends t{protected(e){let t=arguments.length===0?!0:!!e;return this._m(`protected`,t)}}return n}function pn(e){let t=M(e);class n extends t{public(e){let t=arguments.length===0?!0:!!e;return this._m(`public`,t)}}return n}function mn(e){let t=M(e);class n extends t{readonly(e){let t=arguments.length===0?!0:!!e;return this._m(`readonly`,t)}}return n}function hn(e){let t=M(e);class n extends t{static(e){let t=arguments.length===0?!0:!!e;return this._m(`static`,t)}}return n}const gn=T;var _n=class extends gn{"~dsl"=`TypeParamTsDsl`;scope=`type`;constraint;defaultValue;constructor(e,t){super(),e&&this.name.set(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=l(e),this}extends(e){return this.constraint=l(e),this}toAst(){if(!this.name.toString())throw Error(`Missing type name`);return h.factory.createTypeParameterDeclaration(void 0,this.$node(this.name),this.$type(this.constraint),this.$type(this.defaultValue))}};function vn(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 _n(...e);return this._generics.push(t),this}generics(...e){for(let t of e)(typeof t==`string`||typeof t==`number`||o(t)||a(t))&&(t=new _n(t)),this._generics.push(t);return this}$generics(){return this.$node(this._generics)}}return t}function yn(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}function bn(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}var N=class extends T{"~dsl"=`TokenTsDsl`;_kind;kind(e){return this._kind=e,this}minus(){return this.kind(h.SyntaxKind.MinusToken)}optional(){return this.kind(h.SyntaxKind.QuestionToken)}plus(){return this.kind(h.SyntaxKind.PlusToken)}questionDot(){return this.kind(h.SyntaxKind.QuestionDotToken)}readonly(){return this.kind(h.SyntaxKind.ReadonlyKeyword)}spread(){return this.kind(h.SyntaxKind.DotDotDotToken)}toAst(){if(!this._kind)throw Error("Token missing `.kind(kind)`");return h.factory.createToken(this._kind)}};function xn(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(l(e)),this}generics(...e){return this._generics.push(...e.map(e=>l(e))),this}$generics(){return this.$type(this._generics)}}return t}function Sn(e){class t extends e{analyze(e){super.analyze(e)}idx(...e){return D.type.idx(this,...e)}keyof(){return D.type.operator().keyof(this)}readonly(){return D.type.operator().readonly(this)}returnType(...e){return D.type.expr(`ReturnType`).generic(D.type.query(this,...e))}typeofExpr(...e){return D.typeofExpr(this,...e)}typeofType(...e){return D.type.query(this,...e)}unique(){return D.type.operator().unique(this)}}return t}const Cn=Sn(T);var wn=class extends Cn{"~dsl"=`TypeAttrTsDsl`;scope=`type`;_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 a(e)?this._base=e:this._base=e?l(e):void 0,this}right(e){return this._right=l(e),this}toAst(){if(!this._base)throw Error(`TypeAttrTsDsl: missing base for qualified name`);let e=this.$node(this._base);if(!h.isEntityName(e))throw Error(`TypeAttrTsDsl: base must be an EntityName`);return h.factory.createQualifiedName(e,this.$node(this._right))}};const Tn=xn(Sn(T));var En=class extends Tn{"~dsl"=`TypeExprTsDsl`;scope=`type`;_exprInput;constructor(e,t){super(),typeof e==`function`?e(this):(this._exprInput=e?l(e):void 0,t?.(this))}analyze(e){super.analyze(e),e.analyze(this._exprInput)}attr(e){return this._exprInput=i(e)?l(e.base(this._exprInput)):l(new wn(this._exprInput,e)),this}toAst(){if(!this._exprInput)throw Error(`TypeExpr must have an expression`);return h.factory.createTypeReferenceNode(this.$type(this._exprInput),this.$generics())}};D.type.expr.set((...e)=>new En(...e));const Dn=Kt(j(yn(dn(fn(pn(mn(hn(bn(T)))))))));var On=class extends Dn{"~dsl"=`FieldTsDsl`;nameSanitizer=Rt;_type;constructor(e,t){super(),this.name.set(e),t?.(this)}analyze(e){super.analyze(e),e.analyze(this.name),e.analyze(this._type)}type(e){return this._type=e instanceof Dt?e:new En(e),this}toAst(){let e=h.factory.createPropertyDeclaration([...this.$decorators(),...this.modifiers],this.$node(this.name),this._optional?this.$node(new N().optional()):void 0,this.$type(this._type),this.$value());return this.$docs(e)}};const kn=T;var An=class extends kn{"~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 h.isStatement(e)?e:h.factory.createExpressionStatement(e)}};function jn(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 An(e)))}}return t}const Mn=T;var Nn=class extends Mn{"~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?h.factory.createBindingElement(void 0,void 0,e,void 0):h.factory.createBindingElement(void 0,e,t,void 0)),t=this.createSpread();return t&&e.push(t),h.factory.createObjectBindingPattern(e)}if(this.pattern.kind===`array`){let e=this.pattern.values.map(e=>h.factory.createBindingElement(void 0,void 0,e,void 0)),t=this.createSpread();return t&&e.push(t),h.factory.createArrayBindingPattern(e)}throw Error(`PatternTsDsl requires object() or array() pattern`)}createSpread(){return this._spread?h.factory.createBindingElement(this.$node(new N().spread()),void 0,this.$node(new kt(this._spread))):void 0}};function Pn(e){class t extends e{pattern;analyze(e){super.analyze(e),e.analyze(this.pattern)}array(...e){return(this.pattern??=new Nn).array(...e),this}object(...e){return(this.pattern??=new Nn).object(...e),this}spread(e){return(this.pattern??=new Nn).spread(e),this}$pattern(){if(this.pattern)return this.$node(this.pattern)}}return t}const Fn=Kt(yn(Pn(bn(T))));var In=class extends Fn{"~dsl"=`ParamTsDsl`;_type;constructor(e,t){super(),typeof e==`function`?e(this):(this.name.set(e),t?.(this))}analyze(e){super.analyze(e),e.analyze(this.name),e.analyze(this._type)}type(e){return this._type=e instanceof Dt?e:new En(e),this}toAst(){let e=this.$pattern()||this.name.toString();if(!e)throw Error(`Param must have either a name or a destructuring pattern`);return h.factory.createParameterDeclaration(this.$decorators(),void 0,e,this._optional?this.$node(new N().optional()):void 0,this.$type(this._type),this.$value())}};function Ln(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 In(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 Rn(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 zn=jn(Rn(T));var P=class extends zn{"~dsl"=`BlockTsDsl`;constructor(...e){super(),this.do(...e)}analyze(e){super.analyze(e)}toAst(){let e=this.$do();return h.factory.createBlock(e,this.$multiline(e.length))}};const Bn=Kt(jn(j(Ln(dn(fn(pn(T)))))));var Vn=class extends Bn{"~dsl"=`InitTsDsl`;constructor(e){super(),e?.(this)}analyze(e){e.pushScope();try{super.analyze(e)}finally{e.popScope()}}toAst(){let e=h.factory.createConstructorDeclaration([...this.$decorators(),...this.modifiers],this.$params(),this.$node(new P(...this._do).pretty()));return this.$docs(e)}};function Hn(e){class t extends e{_returns;analyze(e){super.analyze(e),e.analyze(this._returns)}returns(e){return this._returns=e instanceof Dt?e:new En(e),this}$returns(){return this.$type(this._returns)}}return t}const Un=on(sn(Kt(jn(j(yn(Ln(dn(fn(pn(hn(vn(Hn(T)))))))))))));var Wn=class extends Un{"~dsl"=`MethodTsDsl`;nameSanitizer=Rt;constructor(e,t){super(),this.name.set(e),t?.(this)}analyze(e){e.analyze(this.name),e.pushScope();try{super.analyze(e)}finally{e.popScope()}}toAst(){let e=h.factory.createMethodDeclaration([...this.$decorators(),...this.modifiers],void 0,this.$node(this.name),this._optional?this.$node(new N().optional()):void 0,this.$generics(),this.$params(),this.$returns(),this.$node(new P(...this._do).pretty()));return this.$docs(e)}};const Gn=on(Kt(ln(j(un(vn(T))))));var Kn=class extends Gn{"~dsl"=`ClassTsDsl`;nameSanitizer=Ht;baseClass;body=[];constructor(e){super(),this.name.set(e),o(e)&&e.setKind(`class`)}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()}}get hasBody(){return this.body.length>0}do(...e){return this.body.push(...e),this}extends(e){return this.baseClass=e?l(e):void 0,this}field(e,t){let n=new On(e,t);return this.body.push(n),this}init(e){let t=typeof e==`function`?new Vn(e):e||new Vn;return this.body.push(t),this}method(e,t){let n=new Wn(e,t);return this.body.push(n),this}newline(){return this.body.push(new At),this}toAst(){let e=this.$node(this.body),t=h.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?[h.factory.createHeritageClause(h.SyntaxKind.ExtendsKeyword,[h.factory.createExpressionWithTypeArguments(e,void 0)])]:[]}};const qn=j(T);var Jn=class extends qn{"~dsl"=`EnumMemberTsDsl`;_value;constructor(e,t){super(),this.name.set(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=h.factory.createEnumMember(this.$node(zt(this.name.toString())),this.$node(this._value));return this.$docs(e)}};const Yn=cn(j(un(T)));var Xn=class extends Yn{"~dsl"=`EnumTsDsl`;nameSanitizer=Ht;_members=[];constructor(e,t){super(),this.name.set(e),o(e)&&e.setKind(`enum`),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 Jn(e,t);return this._members.push(n),this}members(...e){return this._members.push(...e),this}toAst(){let e=h.factory.createEnumDeclaration(this.modifiers,this.$node(this.name),this.$node(this._members));return this.$docs(e)}};const Zn=on(O(sn(Kt(jn(j(Ln(dn(fn(pn(hn(vn(Hn(T))))))))))))),Qn=class extends Zn{"~dsl"=`FuncTsDsl`;nameSanitizer=Ht;mode;constructor(e,t){super(),typeof e==`function`?(this.mode=`arrow`,e(this)):e&&(this.mode=`decl`,this.name.set(e),o(e)&&e.setKind(`function`),t?.(this))}analyze(e){e.pushScope();try{super.analyze(e),e.analyze(this.name)}finally{e.popScope()}}arrow(){return this.mode=`arrow`,this}decl(){return this.mode=`decl`,this}expr(){return this.mode=`expr`,this}toAst(){let e=this.$node(new P(...this._do).pretty());if(this.mode===`decl`){if(!this.name.toString())throw Error(`Function declaration requires a name`);let t=h.factory.createFunctionDeclaration([...this.$decorators(),...this.modifiers],void 0,this.$node(this.name),this.$generics(),this.$params(),this.$returns(),e);return this.$docs(t)}if(this.mode===`expr`){let t=h.factory.createFunctionExpression(this.modifiers,void 0,this.$node(this.name),this.$generics(),this.$params(),this.$returns(),e);return this.$docs(t)}let t=h.factory.createArrowFunction(this.modifiers,this.$generics(),this.$params(),this.$returns(),void 0,e.statements.length===1&&h.isReturnStatement(e.statements[0])&&e.statements[0].expression?e.statements[0].expression:e);return this.$docs(t)}},$n=on(sn(Kt(jn(j(Ln(dn(fn(pn(hn(Hn(T)))))))))));var er=class extends $n{"~dsl"=`GetterTsDsl`;nameSanitizer=Rt;constructor(e,t){super(),this.name.set(e),t?.(this)}analyze(e){e.analyze(this.name),e.pushScope();try{super.analyze(e)}finally{e.popScope()}}toAst(){let e=h.factory.createGetAccessorDeclaration([...this.$decorators(),...this.modi