@blimu/codegen 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/main.js CHANGED
@@ -1,8 +1,8 @@
1
1
  #!/usr/bin/env node
2
- "use strict";var Qe=Object.create;var pe=Object.defineProperty;var Ye=Object.getOwnPropertyDescriptor;var Xe=Object.getOwnPropertyNames;var et=Object.getPrototypeOf,tt=Object.prototype.hasOwnProperty;var c=(n,e)=>pe(n,"name",{value:e,configurable:!0});var rt=(n,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of Xe(e))!tt.call(n,o)&&o!==t&&pe(n,o,{get:()=>e[o],enumerable:!(r=Ye(e,o))||r.enumerable});return n};var k=(n,e,t)=>(t=n!=null?Qe(et(n)):{},rt(e||!n||!n.__esModule?pe(t,"default",{value:n,enumerable:!0}):t,n));var Je=require("nest-commander");var Ke=require("@nestjs/common");var se=require("@nestjs/common"),P=require("nest-commander");var te=require("@nestjs/common"),xe=k(require("fs")),S=k(require("path"));var ve=require("url"),ee=k(require("path"));var m=require("zod"),nt=m.z.object({moduleName:m.z.string().optional(),namespace:m.z.string().optional(),typeNames:m.z.array(m.z.string()).optional(),outputFileName:m.z.string().optional()}),we=["client.ts.hbs","index.ts.hbs","package.json.hbs","README.md.hbs","schema.ts.hbs","schema.zod.ts.hbs","service.ts.hbs","tsconfig.json.hbs","utils.ts.hbs"],st=m.z.object({type:m.z.string().min(1,"Type is required"),outDir:m.z.string().min(1,"OutDir is required"),name:m.z.string().min(1,"Name is required"),includeTags:m.z.array(m.z.string()).optional(),excludeTags:m.z.array(m.z.string()).optional(),operationIdParser:m.z.custom().optional(),preCommand:m.z.array(m.z.string()).optional(),postCommand:m.z.array(m.z.string()).optional(),defaultBaseURL:m.z.string().optional(),exclude:m.z.array(m.z.string()).optional(),typeAugmentation:nt.optional()}),ot=st.extend({type:m.z.literal("typescript"),packageName:m.z.string().min(1,"PackageName is required"),moduleName:m.z.string().optional(),includeQueryKeys:m.z.boolean().optional(),templates:m.z.record(m.z.string(),m.z.string()).refine(n=>Object.keys(n).every(e=>we.includes(e)),{message:`Template names must be one of: ${we.join(", ")}`}).optional()}),at=m.z.discriminatedUnion("type",[ot]),Te=m.z.object({spec:m.z.string().min(1,"Spec is required"),name:m.z.string().optional(),clients:m.z.array(at).min(1,"At least one client is required")});async function Oe(n){try{let e=ee.isAbsolute(n)?n:ee.resolve(n),r=await import((0,ve.pathToFileURL)(e).href),o=r.default||r;if(!o)throw new Error(`Config file must export a default export or named export: ${n}`);return Te.parse(o)}catch(e){throw e instanceof Error?new Error(`Failed to load MJS config from ${n}: ${e.message}`):e}}c(Oe,"loadMjsConfig");function it(n,e,t,r){var o=arguments.length,s=o<3?e:r===null?r=Object.getOwnPropertyDescriptor(e,t):r,a;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")s=Reflect.decorate(n,e,t,r);else for(var i=n.length-1;i>=0;i--)(a=n[i])&&(s=(o<3?a(s):o>3?a(e,t,s):a(e,t))||s);return o>3&&s&&Object.defineProperty(e,t,s),s}c(it,"_ts_decorate");var C=class n{static{c(this,"ConfigService")}logger=new te.Logger(n.name);DEFAULT_CONFIG_FILE="chunkflow-codegen.config.mjs";async findDefaultConfig(){let e=process.cwd(),t=S.parse(e).root;for(;e!==t;){let r=S.join(e,this.DEFAULT_CONFIG_FILE);try{return await xe.promises.access(r),r}catch{}e=S.dirname(e)}return null}async load(e){try{let t=await Oe(e);return this.normalizePaths(t,e)}catch(t){throw t instanceof Error?new Error(`Failed to load config from ${e}: ${t.message}`):t}}normalizePaths(e,t){let r=S.dirname(S.resolve(t)),o=e.spec;this.isUrl(o)||S.isAbsolute(o)||(o=S.resolve(r,o));let s=e.clients.map(a=>{let i=a.outDir;return S.isAbsolute(i)||(i=S.resolve(r,i)),{...a,outDir:i}});return{...e,spec:o,clients:s}}isUrl(e){try{let t=new URL(e);return t.protocol==="http:"||t.protocol==="https:"}catch{return!1}}getPreCommand(e){return e.preCommand||[]}getPostCommand(e){return e.postCommand||[]}shouldExcludeFile(e,t){if(!e.exclude||e.exclude.length===0)return!1;let r;try{r=S.relative(e.outDir,t)}catch{return!1}r=S.posix.normalize(r),r==="."&&(r="");for(let o of e.exclude){let s=S.posix.normalize(o);if(r===s||s!==""&&r.startsWith(s+"/"))return!0}return!1}};C=it([(0,te.Injectable)()],C);var ne=require("@nestjs/common");var Ie=require("@nestjs/common");var Re=require("@nestjs/common");var p=(function(n){return n.Unknown="unknown",n.String="string",n.Number="number",n.Integer="integer",n.Boolean="boolean",n.Null="null",n.Array="array",n.Object="object",n.Enum="enum",n.Ref="ref",n.OneOf="oneOf",n.AnyOf="anyOf",n.AllOf="allOf",n.Not="not",n})({});function je(n){let e=n.openapi;return typeof e!="string"?"unknown":e.startsWith("3.1")?"3.1":e.startsWith("3.0")?"3.0":"unknown"}c(je,"detectOpenAPIVersion");function Pe(n){return n==="3.0"||n==="3.1"}c(Pe,"isSupportedVersion");function fe(n,e){if(!(!e||typeof e!="object")){if("$ref"in e&&e.$ref){let t=e.$ref;if(t.startsWith("#/components/schemas/")){let r=t.replace("#/components/schemas/","");if(n.components?.schemas?.[r]){let o=n.components.schemas[r];return"$ref"in o?fe(n,o):o}}return}return e}}c(fe,"getSchemaFromRef");function Ce(n){return n?"nullable"in n&&n.nullable===!0?!0:"type"in n&&Array.isArray(n.type)?n.type.includes("null"):!1:!1}c(Ce,"isSchemaNullable");function ue(n){if(!(!n||!("type"in n)))return n.type}c(ue,"getSchemaType");function ct(n,e,t,r){var o=arguments.length,s=o<3?e:r===null?r=Object.getOwnPropertyDescriptor(e,t):r,a;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")s=Reflect.decorate(n,e,t,r);else for(var i=n.length-1;i>=0;i--)(a=n[i])&&(s=(o<3?a(s):o>3?a(e,t,s):a(e,t))||s);return o>3&&s&&Object.defineProperty(e,t,s),s}c(ct,"_ts_decorate");var H=class{static{c(this,"SchemaConverterService")}schemaRefToIR(e,t){if(!t)return{kind:p.Unknown,nullable:!1};if("$ref"in t&&t.$ref){let l=t.$ref;if(l.startsWith("#/components/schemas/")){let u=l.replace("#/components/schemas/","");return{kind:p.Ref,ref:u,nullable:!1}}let f=l.split("/");if(f.length>0){let u=f[f.length-1];if(u)return{kind:p.Ref,ref:u,nullable:!1}}return{kind:p.Unknown,nullable:!1}}let r=fe(e,t);if(!r)return{kind:p.Unknown,nullable:!1};let o=Ce(r),s;if(r.discriminator&&(s={propertyName:r.discriminator.propertyName,mapping:r.discriminator.mapping}),r.oneOf&&r.oneOf.length>0){let l=r.oneOf.map(f=>this.schemaRefToIR(e,f));return{kind:p.OneOf,oneOf:l,nullable:o,discriminator:s}}if(r.anyOf&&r.anyOf.length>0){let l=r.anyOf.map(f=>this.schemaRefToIR(e,f));return{kind:p.AnyOf,anyOf:l,nullable:o,discriminator:s}}if(r.allOf&&r.allOf.length>0){let l=r.allOf.map(f=>this.schemaRefToIR(e,f));return{kind:p.AllOf,allOf:l,nullable:o,discriminator:s}}if(r.not){let l=this.schemaRefToIR(e,r.not);return{kind:p.Not,not:l,nullable:o,discriminator:s}}if(r.enum&&r.enum.length>0){let l=r.enum.map(u=>String(u)),f=this.inferEnumBaseKind(r);return{kind:p.Enum,enumValues:l,enumRaw:r.enum,enumBase:f,nullable:o,discriminator:s}}let a=ue(r),i=Array.isArray(a)?a.filter(l=>l!=="null")[0]:a;if(i)switch(i){case"string":return{kind:p.String,nullable:o,format:r.format,discriminator:s};case"integer":return{kind:p.Integer,nullable:o,discriminator:s};case"number":return{kind:p.Number,nullable:o,discriminator:s};case"boolean":return{kind:p.Boolean,nullable:o,discriminator:s};case"array":let l=r,f=this.schemaRefToIR(e,l.items);return{kind:p.Array,items:f,nullable:o,discriminator:s};case"object":let u=[];if(r.properties){let b=Object.keys(r.properties).sort();for(let T of b){let j=r.properties[T],B=this.schemaRefToIR(e,j),Z=r.required?.includes(T)||!1;u.push({name:T,type:B,required:Z,annotations:this.extractAnnotations(j)})}}let y;return r.additionalProperties&&typeof r.additionalProperties=="object"&&(y=this.schemaRefToIR(e,r.additionalProperties)),{kind:p.Object,properties:u,additionalProperties:y,nullable:o,discriminator:s}}return{kind:p.Unknown,nullable:o,discriminator:s}}extractAnnotations(e){if(!e||"$ref"in e)return{};let t=e;return{title:t.title,description:t.description,deprecated:t.deprecated,readOnly:t.readOnly,writeOnly:t.writeOnly,default:t.default,examples:t.example?Array.isArray(t.example)?t.example:[t.example]:void 0}}inferEnumBaseKind(e){let t=ue(e);if(t){let r=Array.isArray(t)?t.filter(o=>o!=="null")[0]:t;if(r)switch(r){case"string":return p.String;case"integer":return p.Integer;case"number":return p.Number;case"boolean":return p.Boolean}}if(e.enum&&e.enum.length>0){let r=e.enum[0];if(typeof r=="string")return p.String;if(typeof r=="number")return Number.isInteger(r)?p.Integer:p.Number;if(typeof r=="boolean")return p.Boolean}return p.Unknown}};H=ct([(0,Re.Injectable)()],H);function O(n){if(n=n.trim(),n==="")return"";let e=n.split(/[^A-Za-z0-9]+/).filter(r=>r!==""),t=[];for(let r of e){let o=de(r);t.push(...o)}return t.filter(r=>r!=="").map(r=>r.charAt(0).toUpperCase()+r.slice(1).toLowerCase()).join("")}c(O,"toPascalCase");function N(n){let e=O(n);return e===""?"":e.charAt(0).toLowerCase()+e.slice(1)}c(N,"toCamelCase");function W(n){if(n=n.trim(),n==="")return"";let e=n.split(/[^A-Za-z0-9]+/).filter(r=>r!==""),t=[];for(let r of e){let o=de(r);t.push(...o)}return t.filter(r=>r!=="").map(r=>r.toLowerCase()).join("_")}c(W,"toSnakeCase");function ke(n){if(n=n.trim(),n==="")return"";let e=n.split(/[^A-Za-z0-9]+/).filter(r=>r!==""),t=[];for(let r of e){let o=de(r);t.push(...o)}return t.filter(r=>r!=="").map(r=>r.toLowerCase()).join("-")}c(ke,"toKebabCase");function de(n){if(n==="")return[];let e=[],t="",r=Array.from(n);for(let o=0;o<r.length;o++){let s=r[o],a=!1;o>0&&me(s)&&(me(r[o-1])?o<r.length-1&&!me(r[o+1])&&(a=!0):a=!0),a&&t.length>0&&(e.push(t),t=""),t+=s}return t.length>0&&e.push(t),e}c(de,"splitCamelCase");function me(n){return n>="A"&&n<="Z"}c(me,"isUppercase");function lt(n,e,t,r){var o=arguments.length,s=o<3?e:r===null?r=Object.getOwnPropertyDescriptor(e,t):r,a;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")s=Reflect.decorate(n,e,t,r);else for(var i=n.length-1;i>=0;i--)(a=n[i])&&(s=(o<3?a(s):o>3?a(e,t,s):a(e,t))||s);return o>3&&s&&Object.defineProperty(e,t,s),s}c(lt,"_ts_decorate");function $e(n,e){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(n,e)}c($e,"_ts_metadata");var A=class{static{c(this,"IrBuilderService")}schemaConverter;constructor(e){this.schemaConverter=e}buildIR(e){let t=this.collectTags(e),r=this.collectSecuritySchemes(e),o=this.buildStructuredModels(e),s={};for(let i of t)s[i]=!0;let a=this.buildIRFromDoc(e,s);return a.securitySchemes=r,a.modelDefs=[...o,...a.modelDefs],a}filterIR(e,t){let r=this.compileTagFilters(t.includeTags||[]),o=this.compileTagFilters(t.excludeTags||[]),s=[];for(let i of e.services){let l=[];for(let f of i.operations)this.shouldIncludeOperation(f.originalTags,r,o)&&l.push(f);l.length>0&&s.push({...i,operations:l})}let a={services:s,models:e.models,securitySchemes:e.securitySchemes,modelDefs:e.modelDefs};return a.modelDefs=this.filterUnusedModelDefs(a,e.modelDefs),a}detectStreamingContentType(e){let t=e.toLowerCase().split(";")[0].trim();return t==="text/event-stream"?{isStreaming:!0,format:"sse"}:t==="application/x-ndjson"||t==="application/x-jsonlines"||t==="application/jsonl"?{isStreaming:!0,format:"ndjson"}:t.includes("stream")||t.includes("chunked")?{isStreaming:!0,format:"chunked"}:{isStreaming:!1}}collectTags(e){let t=new Set;if(t.add("misc"),e.paths)for(let[r,o]of Object.entries(e.paths)){if(!o)continue;let s=[o.get,o.post,o.put,o.patch,o.delete,o.options,o.head,o.trace];for(let a of s)if(!(!a||!a.tags))for(let i of a.tags)t.add(i)}return Array.from(t).sort()}compileTagFilters(e){return e.map(t=>{try{return new RegExp(t)}catch(r){throw new Error(`Invalid tag filter pattern "${t}": ${r instanceof Error?r.message:String(r)}`)}})}shouldIncludeOperation(e,t,r){let o=t.length===0;if(t.length>0)for(let s of e){for(let a of t)if(a.test(s)){o=!0;break}if(o)break}if(!o)return!1;if(r.length>0){for(let s of e)for(let a of r)if(a.test(s))return!1}return!0}buildIRFromDoc(e,t){let r={};r.misc={tag:"misc",operations:[]};let o=[],s=new Set,a=c((l,f,u,y)=>{r[l]||(r[l]={tag:l,operations:[]});let b=f.operationId||"",{pathParams:T,queryParams:j}=this.collectParams(e,f),{requestBody:B,extractedTypes:Z}=this.extractRequestBodyWithTypes(e,f,l,b,u,s);o.push(...Z);let{response:le,extractedTypes:Y}=this.extractResponseWithTypes(e,f,l,b,u,s);o.push(...Y);let z=f.tags&&f.tags.length>0?[...f.tags]:["misc"];r[l].operations.push({operationID:b,method:u,path:y,tag:l,originalTags:z,summary:f.summary||"",description:f.description||"",deprecated:f.deprecated||!1,pathParams:T,queryParams:j,requestBody:B,response:le})},"addOp");if(e.paths)for(let[l,f]of Object.entries(e.paths)){if(!f)continue;let u=[{op:f.get,method:"GET"},{op:f.post,method:"POST"},{op:f.put,method:"PUT"},{op:f.patch,method:"PATCH"},{op:f.delete,method:"DELETE"},{op:f.options,method:"OPTIONS"},{op:f.head,method:"HEAD"},{op:f.trace,method:"TRACE"}];for(let{op:y,method:b}of u){if(!y)continue;let T=this.firstAllowedTag(y.tags||[],t);T&&a(T,y,b,l)}}let i=Object.values(r);for(let l of i)l.operations.sort((f,u)=>f.path===u.path?f.method.localeCompare(u.method):f.path.localeCompare(u.path));return i.sort((l,f)=>l.tag.localeCompare(f.tag)),{services:i,models:[],securitySchemes:[],modelDefs:o}}deriveMethodName(e,t,r){if(e)return N(e);let o=r.includes("{")&&r.includes("}");switch(t){case"GET":return o?"get":"list";case"POST":return"create";case"PUT":case"PATCH":return"update";case"DELETE":return"delete";default:return t.toLowerCase()}}firstAllowedTag(e,t){for(let r of e)if(t[r])return r;return e.length===0&&t.misc?"misc":""}collectSecuritySchemes(e){if(!e.components?.securitySchemes)return[];let t=Object.keys(e.components.securitySchemes).sort(),r=[];for(let o of t){let s=e.components.securitySchemes[o];if(!s||"$ref"in s)continue;let a={key:o,type:s.type};switch(s.type){case"http":a.scheme=s.scheme,a.bearerFormat=s.bearerFormat;break;case"apiKey":a.in=s.in,a.name=s.name;break;case"oauth2":case"openIdConnect":break}r.push(a)}return r}collectParams(e,t){let r=[],o=[];if(t.parameters)for(let s of t.parameters){if(!s||"$ref"in s)continue;let a=s,i=this.schemaConverter.schemaRefToIR(e,a.schema),l={name:a.name,required:a.required||!1,schema:i,description:a.description||""};a.in==="path"?r.push(l):a.in==="query"&&o.push(l)}return r.sort((s,a)=>s.name.localeCompare(a.name)),o.sort((s,a)=>s.name.localeCompare(a.name)),{pathParams:r,queryParams:o}}extractRequestBodyWithTypes(e,t,r,o,s,a){let i=[];if(!t.requestBody||"$ref"in t.requestBody)return{requestBody:null,extractedTypes:[]};let l=t.requestBody,f=this.deriveMethodName(o,s,t.path),u=`${O(r)}${O(f)}RequestBody`;if(l.content?.["application/json"]){let b=l.content["application/json"],T=this.schemaConverter.schemaRefToIR(e,b.schema);return T.kind===p.Object&&!a.has(u)?(a.add(u),i.push({name:u,schema:T,annotations:this.schemaConverter.extractAnnotations(b.schema)}),{requestBody:{contentType:"application/json",typeTS:"",schema:{kind:p.Ref,ref:u,nullable:!1},required:l.required||!1},extractedTypes:i}):{requestBody:{contentType:"application/json",typeTS:"",schema:T,required:l.required||!1},extractedTypes:[]}}return{requestBody:this.extractRequestBody(e,t),extractedTypes:[]}}extractRequestBody(e,t){if(!t.requestBody||"$ref"in t.requestBody)return null;let r=t.requestBody;if(r.content?.["application/json"]){let o=r.content["application/json"];return{contentType:"application/json",typeTS:"",schema:this.schemaConverter.schemaRefToIR(e,o.schema),required:r.required||!1}}if(r.content?.["application/x-www-form-urlencoded"]){let o=r.content["application/x-www-form-urlencoded"];return{contentType:"application/x-www-form-urlencoded",typeTS:"",schema:this.schemaConverter.schemaRefToIR(e,o.schema),required:r.required||!1}}if(r.content?.["multipart/form-data"])return{contentType:"multipart/form-data",typeTS:"",schema:{kind:"unknown",nullable:!1},required:r.required||!1};if(r.content){let o=Object.keys(r.content)[0],s=r.content[o];return{contentType:o,typeTS:"",schema:this.schemaConverter.schemaRefToIR(e,s.schema),required:r.required||!1}}return null}extractResponseWithTypes(e,t,r,o,s,a){let i=[];if(!t.responses)return{response:{typeTS:"unknown",schema:{kind:p.Unknown,nullable:!1},description:"",isStreaming:!1,contentType:""},extractedTypes:[]};let l=this.deriveMethodName(o,s,t.path),f=`${O(r)}${O(l)}Response`,u=["200","201"];for(let b of u){let T=t.responses[b];if(T&&!("$ref"in T)){let j=T;if(j.content){for(let[z,be]of Object.entries(j.content)){let Se=this.detectStreamingContentType(z),X=this.schemaConverter.schemaRefToIR(e,be.schema);if(Se.isStreaming)return{response:{typeTS:"",schema:X,description:j.description||"",isStreaming:!0,contentType:z,streamingFormat:Se.format},extractedTypes:[]};if(z==="application/json")return X.kind===p.Object&&!a.has(f)?(a.add(f),i.push({name:f,schema:X,annotations:this.schemaConverter.extractAnnotations(be.schema)}),{response:{typeTS:"",schema:{kind:p.Ref,ref:f,nullable:!1},description:j.description||"",isStreaming:!1,contentType:z},extractedTypes:i}):{response:{typeTS:"",schema:X,description:j.description||"",isStreaming:!1,contentType:z},extractedTypes:[]}}let B=Object.keys(j.content)[0],Z=j.content[B],le=this.schemaConverter.schemaRefToIR(e,Z.schema),Y=this.detectStreamingContentType(B);return{response:{typeTS:"",schema:le,description:j.description||"",isStreaming:Y.isStreaming,contentType:B,streamingFormat:Y.format},extractedTypes:[]}}return{response:{typeTS:"void",schema:{kind:p.Unknown,nullable:!1},description:j.description||"",isStreaming:!1,contentType:""},extractedTypes:[]}}}return{response:this.extractResponse(e,t),extractedTypes:[]}}extractResponse(e,t){if(!t.responses)return{typeTS:"unknown",schema:{kind:p.Unknown,nullable:!1},description:"",isStreaming:!1,contentType:""};let r=["200","201"];for(let o of r){let s=t.responses[o];if(s&&!("$ref"in s)){let a=s;if(a.content){for(let[u,y]of Object.entries(a.content)){let b=this.detectStreamingContentType(u);if(b.isStreaming)return{typeTS:"",schema:this.schemaConverter.schemaRefToIR(e,y.schema),description:a.description||"",isStreaming:!0,contentType:u,streamingFormat:b.format}}if(a.content["application/json"]){let u=a.content["application/json"];return{typeTS:"",schema:this.schemaConverter.schemaRefToIR(e,u.schema),description:a.description||"",isStreaming:!1,contentType:"application/json"}}let i=Object.keys(a.content)[0],l=a.content[i],f=this.detectStreamingContentType(i);return{typeTS:"",schema:this.schemaConverter.schemaRefToIR(e,l.schema),description:a.description||"",isStreaming:f.isStreaming,contentType:i,streamingFormat:f.format}}return{typeTS:"void",schema:{kind:p.Unknown,nullable:!1},description:a.description||"",isStreaming:!1,contentType:""}}}for(let[o,s]of Object.entries(t.responses))if(o.length===3&&o[0]==="2"&&s&&!("$ref"in s)){let a=s;if(o==="204")return{typeTS:"void",schema:{kind:p.Unknown,nullable:!1},description:a.description||"",isStreaming:!1,contentType:""};if(a.content){for(let[u,y]of Object.entries(a.content)){let b=this.detectStreamingContentType(u);if(b.isStreaming)return{typeTS:"",schema:this.schemaConverter.schemaRefToIR(e,y.schema),description:a.description||"",isStreaming:!0,contentType:u,streamingFormat:b.format}}if(a.content["application/json"]){let u=a.content["application/json"];return{typeTS:"",schema:this.schemaConverter.schemaRefToIR(e,u.schema),description:a.description||"",isStreaming:!1,contentType:"application/json"}}let i=Object.keys(a.content)[0],l=a.content[i],f=this.detectStreamingContentType(i);return{typeTS:"",schema:this.schemaConverter.schemaRefToIR(e,l.schema),description:a.description||"",isStreaming:f.isStreaming,contentType:i,streamingFormat:f.format}}}return{typeTS:"unknown",schema:{kind:p.Unknown,nullable:!1},description:"",isStreaming:!1,contentType:""}}buildStructuredModels(e){let t=[];if(!e.components?.schemas)return t;let r=Object.keys(e.components.schemas).sort(),o=new Set;for(let s of r)o.add(s);for(let s of r){let a=e.components.schemas[s],i=this.schemaConverter.schemaRefToIR(e,a);t.push({name:s,schema:i,annotations:this.schemaConverter.extractAnnotations(a)})}return t}filterUnusedModelDefs(e,t){let r=new Map;for(let i of t)r.set(i.name,i);let o=new Set,s=new Set,a=c(i=>{if(i.kind==="ref"&&i.ref){let l=i.ref;if(o.add(l),!s.has(l)){s.add(l);let f=r.get(l);f&&a(f.schema)}}if(i.items&&a(i.items),i.additionalProperties&&a(i.additionalProperties),i.oneOf)for(let l of i.oneOf)a(l);if(i.anyOf)for(let l of i.anyOf)a(l);if(i.allOf)for(let l of i.allOf)a(l);if(i.not&&a(i.not),i.properties)for(let l of i.properties)a(l.type)},"collectRefs");for(let i of e.services)for(let l of i.operations){for(let f of l.pathParams)a(f.schema);for(let f of l.queryParams)a(f.schema);l.requestBody&&a(l.requestBody.schema),a(l.response.schema)}return t.filter(i=>o.has(i.name))}};A=lt([(0,Ie.Injectable)(),$e("design:type",Function),$e("design:paramtypes",[typeof H>"u"?Object:H])],A);var re=require("@nestjs/common"),K=k(require("@apidevtools/swagger-parser")),ge=k(require("fs")),he=k(require("path"));function pt(n,e,t,r){var o=arguments.length,s=o<3?e:r===null?r=Object.getOwnPropertyDescriptor(e,t):r,a;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")s=Reflect.decorate(n,e,t,r);else for(var i=n.length-1;i>=0;i--)(a=n[i])&&(s=(o<3?a(s):o>3?a(e,t,s):a(e,t))||s);return o>3&&s&&Object.defineProperty(e,t,s),s}c(pt,"_ts_decorate");var R=class n{static{c(this,"OpenApiService")}logger=new re.Logger(n.name);async loadDocument(e){try{let t=null;try{t=new URL(e)}catch{}let r;if(t&&(t.protocol==="http:"||t.protocol==="https:"))this.logger.debug(`Loading OpenAPI spec from URL: ${e}`),r=await K.default.dereference(e);else{let s=he.resolve(e);if(!ge.existsSync(s))throw new Error(`OpenAPI spec file not found: ${s}`);this.logger.debug(`Loading OpenAPI spec from file: ${s}`),r=await K.default.dereference(s)}let o=je(r);if(!Pe(o))throw new Error(`Unsupported OpenAPI version: ${r.openapi}. Only versions 3.0.x and 3.1.0 are supported.`);return this.logger.log(`Detected OpenAPI version: ${o} (${r.openapi})`),r}catch(t){throw t instanceof Error?new Error(`Failed to load OpenAPI document from ${e}: ${t.message}`):t}}async validateDocument(e){try{let t=null;try{t=new URL(e)}catch{}if(t&&(t.protocol==="http:"||t.protocol==="https:"))await K.default.validate(e);else{let r=he.resolve(e);if(!ge.existsSync(r))throw new Error(`OpenAPI spec file not found: ${r}`);await K.default.validate(r)}}catch(t){throw t instanceof Error?new Error(`Invalid OpenAPI document: ${t.message}`):t}}};R=pt([(0,re.Injectable)()],R);function ft(n,e,t,r){var o=arguments.length,s=o<3?e:r===null?r=Object.getOwnPropertyDescriptor(e,t):r,a;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")s=Reflect.decorate(n,e,t,r);else for(var i=n.length-1;i>=0;i--)(a=n[i])&&(s=(o<3?a(s):o>3?a(e,t,s):a(e,t))||s);return o>3&&s&&Object.defineProperty(e,t,s),s}c(ft,"_ts_decorate");function He(n,e){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(n,e)}c(He,"_ts_metadata");var $=class n{static{c(this,"GeneratorService")}irBuilder;openApiService;logger=new ne.Logger(n.name);generators=new Map;constructor(e,t){this.irBuilder=e,this.openApiService=t}register(e){this.generators.set(e.getType(),e),this.logger.debug(`Registered generator: ${e.getType()}`)}getGenerator(e){return this.generators.get(e)}getAvailableTypes(){return Array.from(this.generators.keys())}async generate(e,t){let r=this.getGenerator(t.type);if(!r)throw new Error(`Unsupported client type: ${t.type}`);let o=await this.openApiService.loadDocument(e),s=this.irBuilder.buildIR(o),a=this.irBuilder.filterIR(s,t);await r.generate(t,a)}};$=ft([(0,ne.Injectable)(),He("design:type",Function),He("design:paramtypes",[typeof A>"u"?Object:A,typeof R>"u"?Object:R])],$);var Ae=require("child_process"),Ee=require("util"),J=k(require("path")),qe=k(require("fs"));function E(n,e,t,r){var o=arguments.length,s=o<3?e:r===null?r=Object.getOwnPropertyDescriptor(e,t):r,a;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")s=Reflect.decorate(n,e,t,r);else for(var i=n.length-1;i>=0;i--)(a=n[i])&&(s=(o<3?a(s):o>3?a(e,t,s):a(e,t))||s);return o>3&&s&&Object.defineProperty(e,t,s),s}c(E,"_ts_decorate");function d(n,e){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(n,e)}c(d,"_ts_metadata");var ut=(0,Ee.promisify)(Ae.exec),x=class n extends P.CommandRunner{static{c(this,"GenerateCommand")}generatorService;configService;logger=new se.Logger(n.name);constructor(e,t){super(),this.generatorService=e,this.configService=t}async run(e,t){try{let r=null,o=null;if(this.logger.debug(`Received options: ${JSON.stringify(t)}`),t.config)o=t.config,r=await this.configService.load(o);else{let s=await this.configService.findDefaultConfig();s&&(this.logger.debug(`Found default config file: ${s}`),o=s,r=await this.configService.load(s))}if(t.input&&t.type&&t.out&&(t["package-name"]||t.packageName)&&(t["client-name"]||t.clientName)){let s=t["package-name"]||t.packageName,a=t["client-name"]||t.clientName;if(r)if(r.spec=t.input,r.clients.length>0){let i=r.clients[0];t.type==="typescript"?r.clients[0]={...i,type:"typescript",outDir:J.resolve(t.out),packageName:s,name:a,includeTags:t["include-tags"]||t.includeTags,excludeTags:t["exclude-tags"]||t.excludeTags}:r.clients[0]={...i,type:t.type,outDir:J.resolve(t.out),name:a,includeTags:t["include-tags"]||t.includeTags,excludeTags:t["exclude-tags"]||t.excludeTags}}else if(t.type==="typescript")r.clients.push({type:"typescript",outDir:J.resolve(t.out),packageName:s,name:a,includeTags:t["include-tags"]||t.includeTags,excludeTags:t["exclude-tags"]||t.excludeTags});else throw new Error(`Unsupported client type: ${t.type}`);else if(t.type==="typescript")r={spec:t.input,name:a,clients:[{type:"typescript",outDir:J.resolve(t.out),packageName:s,name:a,includeTags:t["include-tags"]||t.includeTags,excludeTags:t["exclude-tags"]||t.excludeTags}]};else throw new Error(`Unsupported client type: ${t.type}`)}else r||(this.logger.error("\u274C Error: Either --config, chunkflow-codegen.config.mjs, or all fallback options (--input, --type, --out, --package-name, --client-name) must be provided"),process.exit(1));for(let s of r.clients)t.client&&s.name!==t.client||(await qe.promises.mkdir(s.outDir,{recursive:!0}),await this.executePreCommands(s),this.logger.log(`Generating ${s.type} SDK for ${s.name}...`),await this.generatorService.generate(r.spec,s),await this.executePostGenCommands(s),this.logger.log(`\u2705 SDK generated successfully for ${s.name}`))}catch(r){let o=r instanceof Error?r.message:String(r);this.logger.error(`\u274C Error during SDK generation: ${o}`),r instanceof Error&&r.stack&&this.logger.error(r.stack),process.exit(1)}}parseConfig(e){return e}parseClient(e){return e}parseInput(e){return e}parseType(e){return e}parseOut(e){return e}parsePackageName(e){return e}parseClientName(e){return e}parseIncludeTags(e,t=[]){return[...t,e]}parseExcludeTags(e,t=[]){return[...t,e]}async executePreCommands(e){let t=this.configService.getPreCommand(e);t.length!==0&&await this.executeCommand(t,e.outDir,"pre-command")}async executePostGenCommands(e){let t=this.configService.getPostCommand(e);t.length!==0&&await this.executeCommand(t,e.outDir,"post-command")}async executeCommand(e,t,r){try{let[o,...s]=e;this.logger.debug(`Executing ${r}: ${o} ${s.join(" ")}`);let{stdout:a,stderr:i}=await ut(`${o} ${s.map(l=>`"${l}"`).join(" ")}`,{cwd:t,maxBuffer:10*1024*1024});a&&this.logger.debug(a),i&&!i.includes("warning")&&this.logger.warn(i)}catch(o){let s=o instanceof Error?o.message:String(o);throw new Error(`${r} failed: ${s}`)}}};E([(0,P.Option)({flags:"-c, --config <path>",description:"Path to chunkflow-codegen.config.mjs config file"}),d("design:type",Function),d("design:paramtypes",[String]),d("design:returntype",String)],x.prototype,"parseConfig",null);E([(0,P.Option)({flags:"--client <name>",description:"Generate only the named client from config"}),d("design:type",Function),d("design:paramtypes",[String]),d("design:returntype",String)],x.prototype,"parseClient",null);E([(0,P.Option)({flags:"--input <path>",description:"OpenAPI spec file or URL (yaml/json)"}),d("design:type",Function),d("design:paramtypes",[String]),d("design:returntype",String)],x.prototype,"parseInput",null);E([(0,P.Option)({flags:"--type <type>",description:"Client type (e.g., typescript)"}),d("design:type",Function),d("design:paramtypes",[String]),d("design:returntype",String)],x.prototype,"parseType",null);E([(0,P.Option)({flags:"--out <dir>",description:"Output directory"}),d("design:type",Function),d("design:paramtypes",[String]),d("design:returntype",String)],x.prototype,"parseOut",null);E([(0,P.Option)({flags:"--package-name <name>",description:"Package name"}),d("design:type",Function),d("design:paramtypes",[String]),d("design:returntype",String)],x.prototype,"parsePackageName",null);E([(0,P.Option)({flags:"--client-name <name>",description:"Client class name"}),d("design:type",Function),d("design:paramtypes",[String]),d("design:returntype",String)],x.prototype,"parseClientName",null);E([(0,P.Option)({flags:"--include-tags <tags>",description:"Regex patterns for tags to include (can be specified multiple times)"}),d("design:type",Function),d("design:paramtypes",[String,Array]),d("design:returntype",Array)],x.prototype,"parseIncludeTags",null);E([(0,P.Option)({flags:"--exclude-tags <tags>",description:"Regex patterns for tags to exclude (can be specified multiple times)"}),d("design:type",Function),d("design:paramtypes",[String,Array]),d("design:returntype",Array)],x.prototype,"parseExcludeTags",null);x=E([(0,se.Injectable)(),(0,P.Command)({name:"generate",description:"Generate client SDKs from OpenAPI specifications",aliases:["gen"]}),d("design:type",Function),d("design:paramtypes",[typeof $>"u"?Object:$,typeof C>"u"?Object:C])],x);var oe=require("@nestjs/common"),U=require("nest-commander");function Ne(n,e,t,r){var o=arguments.length,s=o<3?e:r===null?r=Object.getOwnPropertyDescriptor(e,t):r,a;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")s=Reflect.decorate(n,e,t,r);else for(var i=n.length-1;i>=0;i--)(a=n[i])&&(s=(o<3?a(s):o>3?a(e,t,s):a(e,t))||s);return o>3&&s&&Object.defineProperty(e,t,s),s}c(Ne,"_ts_decorate");function Q(n,e){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(n,e)}c(Q,"_ts_metadata");var M=class n extends U.CommandRunner{static{c(this,"ValidateCommand")}openApiService;logger=new oe.Logger(n.name);constructor(e){super(),this.openApiService=e}async run(e,t){try{t.input||(this.logger.error("\u274C Error: --input is required"),process.exit(1)),this.logger.log(`Validating OpenAPI spec: ${t.input}`),await this.openApiService.validateDocument(t.input),this.logger.log("\u2705 OpenAPI spec is valid")}catch(r){let o=r instanceof Error?r.message:String(r);this.logger.error(`\u274C Invalid OpenAPI spec: ${o}`),r instanceof Error&&r.stack&&this.logger.error(r.stack),process.exit(1)}}parseInput(e){return e}};Ne([(0,U.Option)({flags:"--input <path>",description:"OpenAPI spec file or URL (yaml/json)",required:!0}),Q("design:type",Function),Q("design:paramtypes",[String]),Q("design:returntype",String)],M.prototype,"parseInput",null);M=Ne([(0,oe.Injectable)(),(0,U.Command)({name:"validate",description:"Validate an OpenAPI spec"}),Q("design:type",Function),Q("design:paramtypes",[typeof R>"u"?Object:R])],M);var We=require("@nestjs/common");var De=require("@nestjs/common");function mt(n,e,t,r){var o=arguments.length,s=o<3?e:r===null?r=Object.getOwnPropertyDescriptor(e,t):r,a;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")s=Reflect.decorate(n,e,t,r);else for(var i=n.length-1;i>=0;i--)(a=n[i])&&(s=(o<3?a(s):o>3?a(e,t,s):a(e,t))||s);return o>3&&s&&Object.defineProperty(e,t,s),s}c(mt,"_ts_decorate");var D=class{static{c(this,"OpenApiModule")}};D=mt([(0,De.Module)({providers:[R],exports:[R]})],D);var Fe=require("@nestjs/common");function dt(n,e,t,r){var o=arguments.length,s=o<3?e:r===null?r=Object.getOwnPropertyDescriptor(e,t):r,a;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")s=Reflect.decorate(n,e,t,r);else for(var i=n.length-1;i>=0;i--)(a=n[i])&&(s=(o<3?a(s):o>3?a(e,t,s):a(e,t))||s);return o>3&&s&&Object.defineProperty(e,t,s),s}c(dt,"_ts_decorate");var F=class{static{c(this,"ConfigModule")}};F=dt([(0,Fe.Module)({providers:[C],exports:[C]})],F);var ce=require("@nestjs/common"),w=k(require("fs")),v=k(require("path")),h=k(require("handlebars"));var g=k(require("handlebars"));function _e(){g.registerHelper("pascal",n=>O(n)),g.registerHelper("camel",n=>N(n)),g.registerHelper("kebab",n=>ke(n)),g.registerHelper("snake",n=>W(n)),g.registerHelper("serviceName",n=>O(n)+"Service"),g.registerHelper("serviceProp",n=>N(n)),g.registerHelper("fileBase",n=>W(n).toLowerCase()),g.registerHelper("eq",(n,e)=>n===e),g.registerHelper("ne",(n,e)=>n!==e),g.registerHelper("gt",(n,e)=>n>e),g.registerHelper("lt",(n,e)=>n<e),g.registerHelper("sub",(n,e)=>n-e),g.registerHelper("len",n=>Array.isArray(n)?n.length:0),g.registerHelper("or",function(...n){let e=n[n.length-1];return e&&e.fn?n.slice(0,-1).some(t=>t)?e.fn(this):e.inverse(this):n.slice(0,-1).some(t=>t)}),g.registerHelper("and",function(...n){let e=n[n.length-1];return e&&e.fn?n.slice(0,-1).every(t=>t)?e.fn(this):e.inverse(this):n.slice(0,-1).every(t=>t)}),g.registerHelper("replace",(n,e,t)=>typeof n!="string"?n:n.replace(new RegExp(e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),"g"),t)),g.registerHelper("index",(n,e)=>n?.[e]),g.registerHelper("getServiceName",n=>{let e=n.split(".");return e.length>1?e[1]:n}),g.registerHelper("groupByNamespace",n=>{let e={};for(let t of n){let r=t.tag.split(".");if(r.length===1)e[""]||(e[""]=[]),e[""].push(t);else{let o=r[0];e[o]||(e[o]=[]),e[o].push(t)}}return e}),g.registerHelper("getRootServices",n=>n.filter(e=>!e.tag.includes("."))),g.registerHelper("dict",()=>({})),g.registerHelper("setVar",(n,e,t)=>(t&&t.data&&t.data.root&&(t.data.root[`_${n}`]=e),"")),g.registerHelper("set",(n,e,t)=>(n&&typeof n=="object"&&(n[e]=t),"")),g.registerHelper("hasKey",(n,e)=>n&&typeof n=="object"&&e in n),g.registerHelper("lookup",(n,e)=>n&&typeof n=="object"?n[e]:void 0),g.registerHelper("reMatch",(n,e)=>{try{return new RegExp(n).test(e)}catch{return!1}})}c(_e,"registerCommonHandlebarsHelpers");function q(n,e=""){let t=e+" ",r;switch(n.kind){case p.String:r="z.string()",n.format==="date"||n.format==="date-time"?r+=".datetime()":n.format==="email"?r+=".email()":n.format==="uri"||n.format==="url"?r+=".url()":n.format==="uuid"&&(r+=".uuid()");break;case p.Number:r="z.number()";break;case p.Integer:r="z.number().int()";break;case p.Boolean:r="z.boolean()";break;case p.Null:r="z.null()";break;case p.Ref:n.ref?r=`Schema.${n.ref}Schema`:r="z.unknown()";break;case p.Array:n.items?r=`z.array(${q(n.items,t)})`:r="z.array(z.unknown())";break;case p.Object:if(!n.properties||n.properties.length===0)n.additionalProperties?r=`z.record(z.string(), ${q(n.additionalProperties,t)})`:r="z.record(z.string(), z.unknown())";else{let o=[];for(let s of n.properties){let a=q(s.type,t),i=ae(s.name);s.required?o.push(`${t}${i}: ${a}`):o.push(`${t}${i}: ${a}.optional()`)}if(n.additionalProperties){let s=q(n.additionalProperties,t);o.push(`${t}...z.record(z.string(), ${s}).shape`)}r=`z.object({
3
- ${o.join(`,
2
+ "use strict";var et=Object.create;var fe=Object.defineProperty;var tt=Object.getOwnPropertyDescriptor;var rt=Object.getOwnPropertyNames;var nt=Object.getPrototypeOf,st=Object.prototype.hasOwnProperty;var l=(s,e)=>fe(s,"name",{value:e,configurable:!0});var ot=(s,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of rt(e))!st.call(s,o)&&o!==t&&fe(s,o,{get:()=>e[o],enumerable:!(n=tt(e,o))||n.enumerable});return s};var k=(s,e,t)=>(t=s!=null?et(nt(s)):{},ot(e||!s||!s.__esModule?fe(t,"default",{value:s,enumerable:!0}):t,s));var Xe=require("nest-commander");var Ye=require("@nestjs/common");var ae=require("@nestjs/common"),P=require("nest-commander");var ne=require("@nestjs/common"),Pe=k(require("fs")),T=k(require("path"));var Oe=require("url"),re=k(require("path"));var m=require("zod"),at=m.z.object({type:m.z.string().min(1,"Type name is required"),package:m.z.string().min(1,"Package name is required"),importPath:m.z.string().optional()}),Te=["client.ts.hbs","index.ts.hbs","package.json.hbs","README.md.hbs","schema.ts.hbs","schema.zod.ts.hbs","service.ts.hbs","tsconfig.json.hbs","utils.ts.hbs"],it=m.z.object({type:m.z.string().min(1,"Type is required"),outDir:m.z.string().min(1,"OutDir is required"),name:m.z.string().min(1,"Name is required"),includeTags:m.z.array(m.z.string()).optional(),excludeTags:m.z.array(m.z.string()).optional(),operationIdParser:m.z.custom().optional(),preCommand:m.z.array(m.z.string()).optional(),postCommand:m.z.array(m.z.string()).optional(),defaultBaseURL:m.z.string().optional(),exclude:m.z.array(m.z.string()).optional()}),ct=it.extend({type:m.z.literal("typescript"),packageName:m.z.string().min(1,"PackageName is required"),moduleName:m.z.string().optional(),includeQueryKeys:m.z.boolean().optional(),predefinedTypes:m.z.array(at).optional(),dependencies:m.z.record(m.z.string(),m.z.string()).optional(),devDependencies:m.z.record(m.z.string(),m.z.string()).optional(),templates:m.z.record(m.z.string(),m.z.string()).refine(s=>Object.keys(s).every(e=>Te.includes(e)),{message:`Template names must be one of: ${Te.join(", ")}`}).optional()}),lt=m.z.discriminatedUnion("type",[ct]),we=m.z.object({spec:m.z.string().min(1,"Spec is required"),name:m.z.string().optional(),clients:m.z.array(lt).min(1,"At least one client is required")});async function ve(s){try{let e=re.isAbsolute(s)?s:re.resolve(s),n=await import((0,Oe.pathToFileURL)(e).href),o=n.default||n;if(!o)throw new Error(`Config file must export a default export or named export: ${s}`);return we.parse(o)}catch(e){throw e instanceof Error?new Error(`Failed to load MJS config from ${s}: ${e.message}`):e}}l(ve,"loadMjsConfig");function pt(s,e,t,n){var o=arguments.length,r=o<3?e:n===null?n=Object.getOwnPropertyDescriptor(e,t):n,a;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")r=Reflect.decorate(s,e,t,n);else for(var i=s.length-1;i>=0;i--)(a=s[i])&&(r=(o<3?a(r):o>3?a(e,t,r):a(e,t))||r);return o>3&&r&&Object.defineProperty(e,t,r),r}l(pt,"_ts_decorate");var x=class s{static{l(this,"ConfigService")}logger=new ne.Logger(s.name);DEFAULT_CONFIG_FILE="chunkflow-codegen.config.mjs";async findDefaultConfig(){let e=process.cwd(),t=T.parse(e).root;for(;e!==t;){let n=T.join(e,this.DEFAULT_CONFIG_FILE);try{return await Pe.promises.access(n),n}catch{}e=T.dirname(e)}return null}async load(e){try{let t=await ve(e);return this.normalizePaths(t,e)}catch(t){throw t instanceof Error?new Error(`Failed to load config from ${e}: ${t.message}`):t}}normalizePaths(e,t){let n=T.dirname(T.resolve(t)),o=e.spec;this.isUrl(o)||T.isAbsolute(o)||(o=T.resolve(n,o));let r=e.clients.map(a=>{let i=a.outDir;return T.isAbsolute(i)||(i=T.resolve(n,i)),{...a,outDir:i}});return{...e,spec:o,clients:r}}isUrl(e){try{let t=new URL(e);return t.protocol==="http:"||t.protocol==="https:"}catch{return!1}}getPreCommand(e){return e.preCommand||[]}getPostCommand(e){return e.postCommand||[]}shouldExcludeFile(e,t){if(!e.exclude||e.exclude.length===0)return!1;let n;try{n=T.relative(e.outDir,t)}catch{return!1}n=T.posix.normalize(n),n==="."&&(n="");for(let o of e.exclude){let r=T.posix.normalize(o);if(n===r||r!==""&&n.startsWith(r+"/"))return!0}return!1}};x=pt([(0,ne.Injectable)()],x);var oe=require("@nestjs/common");var Ie=require("@nestjs/common");var ke=require("@nestjs/common");var p=(function(s){return s.Unknown="unknown",s.String="string",s.Number="number",s.Integer="integer",s.Boolean="boolean",s.Null="null",s.Array="array",s.Object="object",s.Enum="enum",s.Ref="ref",s.OneOf="oneOf",s.AnyOf="anyOf",s.AllOf="allOf",s.Not="not",s})({});function xe(s){let e=s.openapi;return typeof e!="string"?"unknown":e.startsWith("3.1")?"3.1":e.startsWith("3.0")?"3.0":"unknown"}l(xe,"detectOpenAPIVersion");function je(s){return s==="3.0"||s==="3.1"}l(je,"isSupportedVersion");function ue(s,e){if(!(!e||typeof e!="object")){if("$ref"in e&&e.$ref){let t=e.$ref;if(t.startsWith("#/components/schemas/")){let n=t.replace("#/components/schemas/","");if(s.components?.schemas?.[n]){let o=s.components.schemas[n];return"$ref"in o?ue(s,o):o}}return}return e}}l(ue,"getSchemaFromRef");function Re(s){return s?"nullable"in s&&s.nullable===!0?!0:"type"in s&&Array.isArray(s.type)?s.type.includes("null"):!1:!1}l(Re,"isSchemaNullable");function de(s){if(!(!s||!("type"in s)))return s.type}l(de,"getSchemaType");function ft(s,e,t,n){var o=arguments.length,r=o<3?e:n===null?n=Object.getOwnPropertyDescriptor(e,t):n,a;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")r=Reflect.decorate(s,e,t,n);else for(var i=s.length-1;i>=0;i--)(a=s[i])&&(r=(o<3?a(r):o>3?a(e,t,r):a(e,t))||r);return o>3&&r&&Object.defineProperty(e,t,r),r}l(ft,"_ts_decorate");var I=class{static{l(this,"SchemaConverterService")}schemaRefToIR(e,t){if(!t)return{kind:p.Unknown,nullable:!1};if("$ref"in t&&t.$ref){let c=t.$ref;if(c.startsWith("#/components/schemas/")){let d=c.replace("#/components/schemas/","");return{kind:p.Ref,ref:d,nullable:!1}}let f=c.split("/");if(f.length>0){let d=f[f.length-1];if(d)return{kind:p.Ref,ref:d,nullable:!1}}return{kind:p.Unknown,nullable:!1}}let n=ue(e,t);if(!n)return{kind:p.Unknown,nullable:!1};let o=Re(n),r;if(n.discriminator&&(r={propertyName:n.discriminator.propertyName,mapping:n.discriminator.mapping}),n.oneOf&&n.oneOf.length>0){let c=n.oneOf.map(f=>this.schemaRefToIR(e,f));return{kind:p.OneOf,oneOf:c,nullable:o,discriminator:r}}if(n.anyOf&&n.anyOf.length>0){let c=n.anyOf.map(f=>this.schemaRefToIR(e,f));return{kind:p.AnyOf,anyOf:c,nullable:o,discriminator:r}}if(n.allOf&&n.allOf.length>0){let c=n.allOf.map(f=>this.schemaRefToIR(e,f));return{kind:p.AllOf,allOf:c,nullable:o,discriminator:r}}if(n.not){let c=this.schemaRefToIR(e,n.not);return{kind:p.Not,not:c,nullable:o,discriminator:r}}if(n.enum&&n.enum.length>0){let c=n.enum.map(d=>String(d)),f=this.inferEnumBaseKind(n);return{kind:p.Enum,enumValues:c,enumRaw:n.enum,enumBase:f,nullable:o,discriminator:r}}let a=de(n),i=Array.isArray(a)?a.filter(c=>c!=="null")[0]:a;if(i)switch(i){case"string":return{kind:p.String,nullable:o,format:n.format,discriminator:r};case"integer":return{kind:p.Integer,nullable:o,discriminator:r};case"number":return{kind:p.Number,nullable:o,discriminator:r};case"boolean":return{kind:p.Boolean,nullable:o,discriminator:r};case"array":let c=n,f=this.schemaRefToIR(e,c.items);return{kind:p.Array,items:f,nullable:o,discriminator:r};case"object":let d=[];if(n.properties){let g=Object.keys(n.properties).sort();for(let S of g){let D=n.properties[S],z=this.schemaRefToIR(e,D),L=n.required?.includes(S)||!1;d.push({name:S,type:z,required:L,annotations:this.extractAnnotations(D)})}}let b;return n.additionalProperties&&typeof n.additionalProperties=="object"&&(b=this.schemaRefToIR(e,n.additionalProperties)),{kind:p.Object,properties:d,additionalProperties:b,nullable:o,discriminator:r}}return{kind:p.Unknown,nullable:o,discriminator:r}}extractAnnotations(e){if(!e||"$ref"in e)return{};let t=e;return{title:t.title,description:t.description,deprecated:t.deprecated,readOnly:t.readOnly,writeOnly:t.writeOnly,default:t.default,examples:t.example?Array.isArray(t.example)?t.example:[t.example]:void 0}}inferEnumBaseKind(e){let t=de(e);if(t){let n=Array.isArray(t)?t.filter(o=>o!=="null")[0]:t;if(n)switch(n){case"string":return p.String;case"integer":return p.Integer;case"number":return p.Number;case"boolean":return p.Boolean}}if(e.enum&&e.enum.length>0){let n=e.enum[0];if(typeof n=="string")return p.String;if(typeof n=="number")return Number.isInteger(n)?p.Integer:p.Number;if(typeof n=="boolean")return p.Boolean}return p.Unknown}};I=ft([(0,ke.Injectable)()],I);function j(s){if(s=s.trim(),s==="")return"";let e=s.split(/[^A-Za-z0-9]+/).filter(n=>n!==""),t=[];for(let n of e){let o=ge(n);t.push(...o)}return t.filter(n=>n!=="").map(n=>n.charAt(0).toUpperCase()+n.slice(1).toLowerCase()).join("")}l(j,"toPascalCase");function q(s){let e=j(s);return e===""?"":e.charAt(0).toLowerCase()+e.slice(1)}l(q,"toCamelCase");function Q(s){if(s=s.trim(),s==="")return"";let e=s.split(/[^A-Za-z0-9]+/).filter(n=>n!==""),t=[];for(let n of e){let o=ge(n);t.push(...o)}return t.filter(n=>n!=="").map(n=>n.toLowerCase()).join("_")}l(Q,"toSnakeCase");function Ce(s){if(s=s.trim(),s==="")return"";let e=s.split(/[^A-Za-z0-9]+/).filter(n=>n!==""),t=[];for(let n of e){let o=ge(n);t.push(...o)}return t.filter(n=>n!=="").map(n=>n.toLowerCase()).join("-")}l(Ce,"toKebabCase");function ge(s){if(s==="")return[];let e=[],t="",n=Array.from(s);for(let o=0;o<n.length;o++){let r=n[o],a=!1;o>0&&me(r)&&(me(n[o-1])?o<n.length-1&&!me(n[o+1])&&(a=!0):a=!0),a&&t.length>0&&(e.push(t),t=""),t+=r}return t.length>0&&e.push(t),e}l(ge,"splitCamelCase");function me(s){return s>="A"&&s<="Z"}l(me,"isUppercase");function ut(s,e,t,n){var o=arguments.length,r=o<3?e:n===null?n=Object.getOwnPropertyDescriptor(e,t):n,a;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")r=Reflect.decorate(s,e,t,n);else for(var i=s.length-1;i>=0;i--)(a=s[i])&&(r=(o<3?a(r):o>3?a(e,t,r):a(e,t))||r);return o>3&&r&&Object.defineProperty(e,t,r),r}l(ut,"_ts_decorate");function He(s,e){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(s,e)}l(He,"_ts_metadata");var $=class{static{l(this,"IrBuilderService")}schemaConverter;constructor(e){this.schemaConverter=e}buildIR(e){let t=this.collectTags(e),n=this.collectSecuritySchemes(e),o=this.buildStructuredModels(e),r={};for(let i of t)r[i]=!0;let a=this.buildIRFromDoc(e,r);return a.securitySchemes=n,a.modelDefs=[...o,...a.modelDefs],a.openApiDocument=e,a}filterIR(e,t){let n=this.compileTagFilters(t.includeTags||[]),o=this.compileTagFilters(t.excludeTags||[]),r=[];for(let i of e.services){let c=[];for(let f of i.operations)this.shouldIncludeOperation(f.originalTags,n,o)&&c.push(f);c.length>0&&r.push({...i,operations:c})}let a={services:r,models:e.models,securitySchemes:e.securitySchemes,modelDefs:e.modelDefs,openApiDocument:e.openApiDocument};return a.modelDefs=this.filterUnusedModelDefs(a,e.modelDefs),a}detectStreamingContentType(e){let t=e.toLowerCase().split(";")[0].trim();return t==="text/event-stream"?{isStreaming:!0,format:"sse"}:t==="application/x-ndjson"||t==="application/x-jsonlines"||t==="application/jsonl"?{isStreaming:!0,format:"ndjson"}:t.includes("stream")||t.includes("chunked")?{isStreaming:!0,format:"chunked"}:{isStreaming:!1}}collectTags(e){let t=new Set;if(t.add("misc"),e.paths)for(let[n,o]of Object.entries(e.paths)){if(!o)continue;let r=[o.get,o.post,o.put,o.patch,o.delete,o.options,o.head,o.trace];for(let a of r)if(!(!a||!a.tags))for(let i of a.tags)t.add(i)}return Array.from(t).sort()}compileTagFilters(e){return e.map(t=>{try{return new RegExp(t)}catch(n){throw new Error(`Invalid tag filter pattern "${t}": ${n instanceof Error?n.message:String(n)}`)}})}shouldIncludeOperation(e,t,n){let o=t.length===0;if(t.length>0)for(let r of e){for(let a of t)if(a.test(r)){o=!0;break}if(o)break}if(!o)return!1;if(n.length>0){for(let r of e)for(let a of n)if(a.test(r))return!1}return!0}buildIRFromDoc(e,t){let n={};n.misc={tag:"misc",operations:[]};let o=[],r=new Set;if(e.components?.schemas)for(let c of Object.keys(e.components.schemas))r.add(c);let a=l((c,f,d,b)=>{n[c]||(n[c]={tag:c,operations:[]});let g=f.operationId||"",{pathParams:S,queryParams:D}=this.collectParams(e,f),{requestBody:z,extractedTypes:L}=this.extractRequestBodyWithTypes(e,f,c,g,d,r);o.push(...L);let{response:F,extractedTypes:J}=this.extractResponseWithTypes(e,f,c,g,d,r);o.push(...J);let ee=f.tags&&f.tags.length>0?[...f.tags]:["misc"];n[c].operations.push({operationID:g,method:d,path:b,tag:c,originalTags:ee,summary:f.summary||"",description:f.description||"",deprecated:f.deprecated||!1,pathParams:S,queryParams:D,requestBody:z,response:F})},"addOp");if(e.paths)for(let[c,f]of Object.entries(e.paths)){if(!f)continue;let d=[{op:f.get,method:"GET"},{op:f.post,method:"POST"},{op:f.put,method:"PUT"},{op:f.patch,method:"PATCH"},{op:f.delete,method:"DELETE"},{op:f.options,method:"OPTIONS"},{op:f.head,method:"HEAD"},{op:f.trace,method:"TRACE"}];for(let{op:b,method:g}of d){if(!b)continue;let S=this.firstAllowedTag(b.tags||[],t);S&&a(S,b,g,c)}}let i=Object.values(n);for(let c of i)c.operations.sort((f,d)=>f.path===d.path?f.method.localeCompare(d.method):f.path.localeCompare(d.path));return i.sort((c,f)=>c.tag.localeCompare(f.tag)),{services:i,models:[],securitySchemes:[],modelDefs:o}}deriveMethodName(e,t,n){if(e){let r=e.indexOf("Controller_"),a=r>=0?e.substring(r+11):e;return q(a)}let o=n.includes("{")&&n.includes("}");switch(t){case"GET":return o?"get":"list";case"POST":return"create";case"PUT":case"PATCH":return"update";case"DELETE":return"delete";default:return t.toLowerCase()}}firstAllowedTag(e,t){for(let n of e)if(t[n])return n;return e.length===0&&t.misc?"misc":""}collectSecuritySchemes(e){if(!e.components?.securitySchemes)return[];let t=Object.keys(e.components.securitySchemes).sort(),n=[];for(let o of t){let r=e.components.securitySchemes[o];if(!r||"$ref"in r)continue;let a={key:o,type:r.type};switch(r.type){case"http":a.scheme=r.scheme,a.bearerFormat=r.bearerFormat;break;case"apiKey":a.in=r.in,a.name=r.name;break;case"oauth2":case"openIdConnect":break}n.push(a)}return n}collectParams(e,t){let n=[],o=[];if(t.parameters)for(let r of t.parameters){if(!r||"$ref"in r)continue;let a=r,i=this.schemaConverter.schemaRefToIR(e,a.schema),c={name:a.name,required:a.required||!1,schema:i,description:a.description||""};a.in==="path"?n.push(c):a.in==="query"&&o.push(c)}return n.sort((r,a)=>r.name.localeCompare(a.name)),o.sort((r,a)=>r.name.localeCompare(a.name)),{pathParams:n,queryParams:o}}findMatchingComponentSchema(e,t){if(!t||!e.components?.schemas)return null;if("$ref"in t&&t.$ref){let o=t.$ref;if(o.startsWith("#/components/schemas/")){let r=o.replace("#/components/schemas/","");if(e.components.schemas[r])return r}}let n=this.schemaConverter.schemaRefToIR(e,t);for(let[o,r]of Object.entries(e.components.schemas)){let a=this.schemaConverter.schemaRefToIR(e,r);if(this.compareSchemas(n,a))return o}return null}compareSchemas(e,t){if(e.kind!==t.kind)return!1;if(e.kind===p.Ref&&t.kind===p.Ref)return e.ref===t.ref;if(e.kind===p.Object&&t.kind===p.Object){let n=e.properties||[],o=t.properties||[];if(n.length!==o.length)return!1;let r=new Map(n.map(i=>[i.name,{type:i.type,required:i.required}])),a=new Map(o.map(i=>[i.name,{type:i.type,required:i.required}]));if(r.size!==a.size)return!1;for(let[i,c]of r){let f=a.get(i);if(!f||c.required!==f.required||!this.compareSchemas(c.type,f.type))return!1}return!0}return e.kind===p.Array&&t.kind===p.Array?!e.items||!t.items?e.items===t.items:this.compareSchemas(e.items,t.items):!0}extractModelNameFromSchema(e){return e.kind===p.Ref&&e.ref?e.ref:e.kind===p.Array&&e.items&&e.items.kind===p.Ref&&e.items.ref?e.items.ref:null}generateTypeName(e,t,n,o,r,a){let i=this.extractModelNameFromSchema(e);if(i)return i;let c=this.deriveMethodName(n,o,r);return`${j(t)}${j(c)}${a}`}extractRequestBodyWithTypes(e,t,n,o,r,a){let i=[];if(!t.requestBody||"$ref"in t.requestBody)return{requestBody:null,extractedTypes:[]};let c=t.requestBody;if(c.content?.["application/json"]){let d=c.content["application/json"],b=this.schemaConverter.schemaRefToIR(e,d.schema),g=this.findMatchingComponentSchema(e,d.schema);if(g)return{requestBody:{contentType:"application/json",typeTS:"",schema:{kind:p.Ref,ref:g,nullable:!1},required:c.required||!1},extractedTypes:[]};let S=this.generateTypeName(b,n,o,r,t.path,"RequestBody");return b.kind===p.Object&&!a.has(S)?(a.add(S),i.push({name:S,schema:b,annotations:this.schemaConverter.extractAnnotations(d.schema)}),{requestBody:{contentType:"application/json",typeTS:"",schema:{kind:p.Ref,ref:S,nullable:!1},required:c.required||!1},extractedTypes:i}):{requestBody:{contentType:"application/json",typeTS:"",schema:b,required:c.required||!1},extractedTypes:[]}}return{requestBody:this.extractRequestBody(e,t),extractedTypes:[]}}extractRequestBody(e,t){if(!t.requestBody||"$ref"in t.requestBody)return null;let n=t.requestBody;if(n.content?.["application/json"]){let o=n.content["application/json"];return{contentType:"application/json",typeTS:"",schema:this.schemaConverter.schemaRefToIR(e,o.schema),required:n.required||!1}}if(n.content?.["application/x-www-form-urlencoded"]){let o=n.content["application/x-www-form-urlencoded"];return{contentType:"application/x-www-form-urlencoded",typeTS:"",schema:this.schemaConverter.schemaRefToIR(e,o.schema),required:n.required||!1}}if(n.content?.["multipart/form-data"])return{contentType:"multipart/form-data",typeTS:"",schema:{kind:"unknown",nullable:!1},required:n.required||!1};if(n.content){let o=Object.keys(n.content)[0],r=n.content[o];return{contentType:o,typeTS:"",schema:this.schemaConverter.schemaRefToIR(e,r.schema),required:n.required||!1}}return null}extractResponseWithTypes(e,t,n,o,r,a){let i=[];if(!t.responses)return{response:{typeTS:"unknown",schema:{kind:p.Unknown,nullable:!1},description:"",isStreaming:!1,contentType:""},extractedTypes:[]};let c=["200","201"];for(let d of c){let b=t.responses[d];if(b&&!("$ref"in b)){let g=b;if(g.content){for(let[F,J]of Object.entries(g.content)){let ee=this.detectStreamingContentType(F),K=this.schemaConverter.schemaRefToIR(e,J.schema);if(ee.isStreaming)return{response:{typeTS:"",schema:K,description:g.description||"",isStreaming:!0,contentType:F,streamingFormat:ee.format},extractedTypes:[]};if(F==="application/json"){let Se=this.findMatchingComponentSchema(e,J.schema);if(Se)return{response:{typeTS:"",schema:{kind:p.Ref,ref:Se,nullable:!1},description:g.description||"",isStreaming:!1,contentType:F},extractedTypes:[]};let te=this.generateTypeName(K,n,o,r,t.path,"Response");return K.kind===p.Object&&!a.has(te)?(a.add(te),i.push({name:te,schema:K,annotations:this.schemaConverter.extractAnnotations(J.schema)}),{response:{typeTS:"",schema:{kind:p.Ref,ref:te,nullable:!1},description:g.description||"",isStreaming:!1,contentType:F},extractedTypes:i}):{response:{typeTS:"",schema:K,description:g.description||"",isStreaming:!1,contentType:F},extractedTypes:[]}}}let S=Object.keys(g.content)[0],D=g.content[S],z=this.schemaConverter.schemaRefToIR(e,D.schema),L=this.detectStreamingContentType(S);return{response:{typeTS:"",schema:z,description:g.description||"",isStreaming:L.isStreaming,contentType:S,streamingFormat:L.format},extractedTypes:[]}}return{response:{typeTS:"void",schema:{kind:p.Unknown,nullable:!1},description:g.description||"",isStreaming:!1,contentType:""},extractedTypes:[]}}}return{response:this.extractResponse(e,t),extractedTypes:[]}}extractResponse(e,t){if(!t.responses)return{typeTS:"unknown",schema:{kind:p.Unknown,nullable:!1},description:"",isStreaming:!1,contentType:""};let n=["200","201"];for(let o of n){let r=t.responses[o];if(r&&!("$ref"in r)){let a=r;if(a.content){for(let[d,b]of Object.entries(a.content)){let g=this.detectStreamingContentType(d);if(g.isStreaming)return{typeTS:"",schema:this.schemaConverter.schemaRefToIR(e,b.schema),description:a.description||"",isStreaming:!0,contentType:d,streamingFormat:g.format}}if(a.content["application/json"]){let d=a.content["application/json"];return{typeTS:"",schema:this.schemaConverter.schemaRefToIR(e,d.schema),description:a.description||"",isStreaming:!1,contentType:"application/json"}}let i=Object.keys(a.content)[0],c=a.content[i],f=this.detectStreamingContentType(i);return{typeTS:"",schema:this.schemaConverter.schemaRefToIR(e,c.schema),description:a.description||"",isStreaming:f.isStreaming,contentType:i,streamingFormat:f.format}}return{typeTS:"void",schema:{kind:p.Unknown,nullable:!1},description:a.description||"",isStreaming:!1,contentType:""}}}for(let[o,r]of Object.entries(t.responses))if(o.length===3&&o[0]==="2"&&r&&!("$ref"in r)){let a=r;if(o==="204")return{typeTS:"void",schema:{kind:p.Unknown,nullable:!1},description:a.description||"",isStreaming:!1,contentType:""};if(a.content){for(let[d,b]of Object.entries(a.content)){let g=this.detectStreamingContentType(d);if(g.isStreaming)return{typeTS:"",schema:this.schemaConverter.schemaRefToIR(e,b.schema),description:a.description||"",isStreaming:!0,contentType:d,streamingFormat:g.format}}if(a.content["application/json"]){let d=a.content["application/json"];return{typeTS:"",schema:this.schemaConverter.schemaRefToIR(e,d.schema),description:a.description||"",isStreaming:!1,contentType:"application/json"}}let i=Object.keys(a.content)[0],c=a.content[i],f=this.detectStreamingContentType(i);return{typeTS:"",schema:this.schemaConverter.schemaRefToIR(e,c.schema),description:a.description||"",isStreaming:f.isStreaming,contentType:i,streamingFormat:f.format}}}return{typeTS:"unknown",schema:{kind:p.Unknown,nullable:!1},description:"",isStreaming:!1,contentType:""}}buildStructuredModels(e){let t=[];if(!e.components?.schemas)return t;let n=Object.keys(e.components.schemas).sort(),o=new Set;for(let r of n)o.add(r);for(let r of n){let a=e.components.schemas[r],i=this.schemaConverter.schemaRefToIR(e,a);t.push({name:r,schema:i,annotations:this.schemaConverter.extractAnnotations(a)})}return t}filterUnusedModelDefs(e,t){let n=new Map;for(let i of t)n.set(i.name,i);let o=new Set,r=new Set,a=l(i=>{if(i.kind==="ref"&&i.ref){let c=i.ref;if(o.add(c),!r.has(c)){r.add(c);let f=n.get(c);f&&a(f.schema)}}if(i.items&&a(i.items),i.additionalProperties&&a(i.additionalProperties),i.oneOf)for(let c of i.oneOf)a(c);if(i.anyOf)for(let c of i.anyOf)a(c);if(i.allOf)for(let c of i.allOf)a(c);if(i.not&&a(i.not),i.properties)for(let c of i.properties)a(c.type)},"collectRefs");for(let i of e.services)for(let c of i.operations){for(let f of c.pathParams)a(f.schema);for(let f of c.queryParams)a(f.schema);c.requestBody&&a(c.requestBody.schema),a(c.response.schema)}return t.filter(i=>o.has(i.name))}};$=ut([(0,Ie.Injectable)(),He("design:type",Function),He("design:paramtypes",[typeof I>"u"?Object:I])],$);var se=require("@nestjs/common"),N=k(require("@apidevtools/swagger-parser")),he=k(require("fs")),ye=k(require("path"));function dt(s,e,t,n){var o=arguments.length,r=o<3?e:n===null?n=Object.getOwnPropertyDescriptor(e,t):n,a;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")r=Reflect.decorate(s,e,t,n);else for(var i=s.length-1;i>=0;i--)(a=s[i])&&(r=(o<3?a(r):o>3?a(e,t,r):a(e,t))||r);return o>3&&r&&Object.defineProperty(e,t,r),r}l(dt,"_ts_decorate");var R=class s{static{l(this,"OpenApiService")}logger=new se.Logger(s.name);async loadDocument(e){try{let t=null;try{t=new URL(e)}catch{}let n;if(t&&(t.protocol==="http:"||t.protocol==="https:")){this.logger.debug(`Loading OpenAPI spec from URL: ${e}`);let r=await fetch(e,{signal:AbortSignal.timeout(1e4)});if(!r.ok)throw new Error(`Failed to fetch OpenAPI spec: HTTP ${r.status} ${r.statusText}`);let a=await r.text(),i;try{i=JSON.parse(a)}catch{throw new Error("OpenAPI spec is not valid JSON")}try{let c=await N.default.parse(i);n=await N.default.bundle(c)}catch(c){this.logger.debug(`Bundle failed: ${c instanceof Error?c.message:String(c)}`),this.logger.debug("Attempting dereference directly");try{let f=await N.default.parse(i);n=await N.default.dereference(f)}catch(f){throw f}}}else{let r=ye.resolve(e);if(!he.existsSync(r))throw new Error(`OpenAPI spec file not found: ${r}`);this.logger.debug(`Loading OpenAPI spec from file: ${r}`);try{n=await N.default.bundle(r)}catch(a){this.logger.debug(`Bundle failed: ${a instanceof Error?a.message:String(a)}`),this.logger.debug("Attempting dereference directly"),n=await N.default.dereference(r)}}let o=xe(n);if(!je(o))throw new Error(`Unsupported OpenAPI version: ${n.openapi}. Only versions 3.0.x and 3.1.0 are supported.`);return this.logger.log(`Detected OpenAPI version: ${o} (${n.openapi})`),n}catch(t){throw t instanceof Error?new Error(`Failed to load OpenAPI document from ${e}: ${t.message}`):t}}async validateDocument(e){try{let t=null;try{t=new URL(e)}catch{}if(t&&(t.protocol==="http:"||t.protocol==="https:"))await N.default.validate(e);else{let n=ye.resolve(e);if(!he.existsSync(n))throw new Error(`OpenAPI spec file not found: ${n}`);await N.default.validate(n)}}catch(t){throw t instanceof Error?new Error(`Invalid OpenAPI document: ${t.message}`):t}}};R=dt([(0,se.Injectable)()],R);function mt(s,e,t,n){var o=arguments.length,r=o<3?e:n===null?n=Object.getOwnPropertyDescriptor(e,t):n,a;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")r=Reflect.decorate(s,e,t,n);else for(var i=s.length-1;i>=0;i--)(a=s[i])&&(r=(o<3?a(r):o>3?a(e,t,r):a(e,t))||r);return o>3&&r&&Object.defineProperty(e,t,r),r}l(mt,"_ts_decorate");function $e(s,e){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(s,e)}l($e,"_ts_metadata");var C=class s{static{l(this,"GeneratorService")}irBuilder;openApiService;logger=new oe.Logger(s.name);generators=new Map;constructor(e,t){this.irBuilder=e,this.openApiService=t}register(e){this.generators.set(e.getType(),e),this.logger.debug(`Registered generator: ${e.getType()}`)}getGenerator(e){return this.generators.get(e)}getAvailableTypes(){return Array.from(this.generators.keys())}async generate(e,t){let n=this.getGenerator(t.type);if(!n)throw new Error(`Unsupported client type: ${t.type}`);let o=await this.openApiService.loadDocument(e),r=this.irBuilder.buildIR(o),a=this.irBuilder.filterIR(r,t);await n.generate(t,a)}};C=mt([(0,oe.Injectable)(),$e("design:type",Function),$e("design:paramtypes",[typeof $>"u"?Object:$,typeof R>"u"?Object:R])],C);var Ae=require("child_process"),Ee=require("util"),Y=k(require("path")),qe=k(require("fs"));function A(s,e,t,n){var o=arguments.length,r=o<3?e:n===null?n=Object.getOwnPropertyDescriptor(e,t):n,a;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")r=Reflect.decorate(s,e,t,n);else for(var i=s.length-1;i>=0;i--)(a=s[i])&&(r=(o<3?a(r):o>3?a(e,t,r):a(e,t))||r);return o>3&&r&&Object.defineProperty(e,t,r),r}l(A,"_ts_decorate");function h(s,e){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(s,e)}l(h,"_ts_metadata");var gt=(0,Ee.promisify)(Ae.exec),v=class s extends P.CommandRunner{static{l(this,"GenerateCommand")}generatorService;configService;logger=new ae.Logger(s.name);constructor(e,t){super(),this.generatorService=e,this.configService=t}async run(e,t){try{let n=null,o=null;if(this.logger.debug(`Received options: ${JSON.stringify(t)}`),t.config)o=t.config,n=await this.configService.load(o);else{let r=await this.configService.findDefaultConfig();r&&(this.logger.debug(`Found default config file: ${r}`),o=r,n=await this.configService.load(r))}if(t.input&&t.type&&t.out&&(t["package-name"]||t.packageName)&&(t["client-name"]||t.clientName)){let r=t["package-name"]||t.packageName,a=t["client-name"]||t.clientName;if(n)if(n.spec=t.input,n.clients.length>0){let i=n.clients[0];t.type==="typescript"?n.clients[0]={...i,type:"typescript",outDir:Y.resolve(t.out),packageName:r,name:a,includeTags:t["include-tags"]||t.includeTags,excludeTags:t["exclude-tags"]||t.excludeTags}:n.clients[0]={...i,type:t.type,outDir:Y.resolve(t.out),name:a,includeTags:t["include-tags"]||t.includeTags,excludeTags:t["exclude-tags"]||t.excludeTags}}else if(t.type==="typescript")n.clients.push({type:"typescript",outDir:Y.resolve(t.out),packageName:r,name:a,includeTags:t["include-tags"]||t.includeTags,excludeTags:t["exclude-tags"]||t.excludeTags});else throw new Error(`Unsupported client type: ${t.type}`);else if(t.type==="typescript")n={spec:t.input,name:a,clients:[{type:"typescript",outDir:Y.resolve(t.out),packageName:r,name:a,includeTags:t["include-tags"]||t.includeTags,excludeTags:t["exclude-tags"]||t.excludeTags}]};else throw new Error(`Unsupported client type: ${t.type}`)}else n||(this.logger.error("\u274C Error: Either --config, chunkflow-codegen.config.mjs, or all fallback options (--input, --type, --out, --package-name, --client-name) must be provided"),process.exit(1));for(let r of n.clients)t.client&&r.name!==t.client||(await qe.promises.mkdir(r.outDir,{recursive:!0}),await this.executePreCommands(r),this.logger.log(`Generating ${r.type} SDK for ${r.name}...`),await this.generatorService.generate(n.spec,r),await this.executePostGenCommands(r),this.logger.log(`\u2705 SDK generated successfully for ${r.name}`))}catch(n){let o=n instanceof Error?n.message:String(n);this.logger.error(`\u274C Error during SDK generation: ${o}`),n instanceof Error&&n.stack&&this.logger.error(n.stack),process.exit(1)}}parseConfig(e){return e}parseClient(e){return e}parseInput(e){return e}parseType(e){return e}parseOut(e){return e}parsePackageName(e){return e}parseClientName(e){return e}parseIncludeTags(e,t=[]){return[...t,e]}parseExcludeTags(e,t=[]){return[...t,e]}async executePreCommands(e){let t=this.configService.getPreCommand(e);t.length!==0&&await this.executeCommand(t,e.outDir,"pre-command")}async executePostGenCommands(e){let t=this.configService.getPostCommand(e);t.length!==0&&await this.executeCommand(t,e.outDir,"post-command")}async executeCommand(e,t,n){try{let[o,...r]=e;this.logger.debug(`Executing ${n}: ${o} ${r.join(" ")}`);let{stdout:a,stderr:i}=await gt(`${o} ${r.map(c=>`"${c}"`).join(" ")}`,{cwd:t,maxBuffer:10*1024*1024});a&&this.logger.debug(a),i&&!i.includes("warning")&&this.logger.warn(i)}catch(o){let r=o instanceof Error?o.message:String(o);throw new Error(`${n} failed: ${r}`)}}};A([(0,P.Option)({flags:"-c, --config <path>",description:"Path to chunkflow-codegen.config.mjs config file"}),h("design:type",Function),h("design:paramtypes",[String]),h("design:returntype",String)],v.prototype,"parseConfig",null);A([(0,P.Option)({flags:"--client <name>",description:"Generate only the named client from config"}),h("design:type",Function),h("design:paramtypes",[String]),h("design:returntype",String)],v.prototype,"parseClient",null);A([(0,P.Option)({flags:"--input <path>",description:"OpenAPI spec file or URL (yaml/json)"}),h("design:type",Function),h("design:paramtypes",[String]),h("design:returntype",String)],v.prototype,"parseInput",null);A([(0,P.Option)({flags:"--type <type>",description:"Client type (e.g., typescript)"}),h("design:type",Function),h("design:paramtypes",[String]),h("design:returntype",String)],v.prototype,"parseType",null);A([(0,P.Option)({flags:"--out <dir>",description:"Output directory"}),h("design:type",Function),h("design:paramtypes",[String]),h("design:returntype",String)],v.prototype,"parseOut",null);A([(0,P.Option)({flags:"--package-name <name>",description:"Package name"}),h("design:type",Function),h("design:paramtypes",[String]),h("design:returntype",String)],v.prototype,"parsePackageName",null);A([(0,P.Option)({flags:"--client-name <name>",description:"Client class name"}),h("design:type",Function),h("design:paramtypes",[String]),h("design:returntype",String)],v.prototype,"parseClientName",null);A([(0,P.Option)({flags:"--include-tags <tags>",description:"Regex patterns for tags to include (can be specified multiple times)"}),h("design:type",Function),h("design:paramtypes",[String,Array]),h("design:returntype",Array)],v.prototype,"parseIncludeTags",null);A([(0,P.Option)({flags:"--exclude-tags <tags>",description:"Regex patterns for tags to exclude (can be specified multiple times)"}),h("design:type",Function),h("design:paramtypes",[String,Array]),h("design:returntype",Array)],v.prototype,"parseExcludeTags",null);v=A([(0,ae.Injectable)(),(0,P.Command)({name:"generate",description:"Generate client SDKs from OpenAPI specifications",aliases:["gen"]}),h("design:type",Function),h("design:paramtypes",[typeof C>"u"?Object:C,typeof x>"u"?Object:x])],v);var ie=require("@nestjs/common"),G=require("nest-commander");function Ne(s,e,t,n){var o=arguments.length,r=o<3?e:n===null?n=Object.getOwnPropertyDescriptor(e,t):n,a;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")r=Reflect.decorate(s,e,t,n);else for(var i=s.length-1;i>=0;i--)(a=s[i])&&(r=(o<3?a(r):o>3?a(e,t,r):a(e,t))||r);return o>3&&r&&Object.defineProperty(e,t,r),r}l(Ne,"_ts_decorate");function X(s,e){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(s,e)}l(X,"_ts_metadata");var U=class s extends G.CommandRunner{static{l(this,"ValidateCommand")}openApiService;logger=new ie.Logger(s.name);constructor(e){super(),this.openApiService=e}async run(e,t){try{t.input||(this.logger.error("\u274C Error: --input is required"),process.exit(1)),this.logger.log(`Validating OpenAPI spec: ${t.input}`),await this.openApiService.validateDocument(t.input),this.logger.log("\u2705 OpenAPI spec is valid")}catch(n){let o=n instanceof Error?n.message:String(n);this.logger.error(`\u274C Invalid OpenAPI spec: ${o}`),n instanceof Error&&n.stack&&this.logger.error(n.stack),process.exit(1)}}parseInput(e){return e}};Ne([(0,G.Option)({flags:"--input <path>",description:"OpenAPI spec file or URL (yaml/json)",required:!0}),X("design:type",Function),X("design:paramtypes",[String]),X("design:returntype",String)],U.prototype,"parseInput",null);U=Ne([(0,ie.Injectable)(),(0,G.Command)({name:"validate",description:"Validate an OpenAPI spec"}),X("design:type",Function),X("design:paramtypes",[typeof R>"u"?Object:R])],U);var Qe=require("@nestjs/common");var De=require("@nestjs/common");function ht(s,e,t,n){var o=arguments.length,r=o<3?e:n===null?n=Object.getOwnPropertyDescriptor(e,t):n,a;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")r=Reflect.decorate(s,e,t,n);else for(var i=s.length-1;i>=0;i--)(a=s[i])&&(r=(o<3?a(r):o>3?a(e,t,r):a(e,t))||r);return o>3&&r&&Object.defineProperty(e,t,r),r}l(ht,"_ts_decorate");var _=class{static{l(this,"OpenApiModule")}};_=ht([(0,De.Module)({providers:[R],exports:[R]})],_);var Fe=require("@nestjs/common");function yt(s,e,t,n){var o=arguments.length,r=o<3?e:n===null?n=Object.getOwnPropertyDescriptor(e,t):n,a;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")r=Reflect.decorate(s,e,t,n);else for(var i=s.length-1;i>=0;i--)(a=s[i])&&(r=(o<3?a(r):o>3?a(e,t,r):a(e,t))||r);return o>3&&r&&Object.defineProperty(e,t,r),r}l(yt,"_ts_decorate");var B=class{static{l(this,"ConfigModule")}};B=yt([(0,Fe.Module)({providers:[x],exports:[x]})],B);var pe=require("@nestjs/common"),w=k(require("fs")),O=k(require("path")),u=k(require("handlebars"));var y=k(require("handlebars"));function _e(){y.registerHelper("pascal",s=>j(s)),y.registerHelper("camel",s=>q(s)),y.registerHelper("kebab",s=>Ce(s)),y.registerHelper("snake",s=>Q(s)),y.registerHelper("serviceName",s=>j(s)+"Service"),y.registerHelper("serviceProp",s=>q(s)),y.registerHelper("fileBase",s=>Q(s).toLowerCase()),y.registerHelper("eq",(s,e)=>s===e),y.registerHelper("ne",(s,e)=>s!==e),y.registerHelper("gt",(s,e)=>s>e),y.registerHelper("lt",(s,e)=>s<e),y.registerHelper("sub",(s,e)=>s-e),y.registerHelper("len",s=>Array.isArray(s)?s.length:0),y.registerHelper("or",function(...s){let e=s[s.length-1];return e&&e.fn?s.slice(0,-1).some(t=>t)?e.fn(this):e.inverse(this):s.slice(0,-1).some(t=>t)}),y.registerHelper("and",function(...s){let e=s[s.length-1];return e&&e.fn?s.slice(0,-1).every(t=>t)?e.fn(this):e.inverse(this):s.slice(0,-1).every(t=>t)}),y.registerHelper("replace",(s,e,t)=>typeof s!="string"?s:s.replace(new RegExp(e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),"g"),t)),y.registerHelper("index",(s,e)=>s?.[e]),y.registerHelper("getServiceName",s=>{let e=s.split(".");return e.length>1?e[1]:s}),y.registerHelper("groupByNamespace",s=>{let e={};for(let t of s){let n=t.tag.split(".");if(n.length===1)e[""]||(e[""]=[]),e[""].push(t);else{let o=n[0];e[o]||(e[o]=[]),e[o].push(t)}}return e}),y.registerHelper("getRootServices",s=>s.filter(e=>!e.tag.includes("."))),y.registerHelper("dict",()=>({})),y.registerHelper("setVar",(s,e,t)=>(t&&t.data&&t.data.root&&(t.data.root[`_${s}`]=e),"")),y.registerHelper("getVar",(s,e)=>e&&e.data&&e.data.root&&e.data.root[`_${s}`]||!1),y.registerHelper("set",(s,e,t)=>(s&&typeof s=="object"&&(s[e]=t),"")),y.registerHelper("hasKey",(s,e)=>s&&typeof s=="object"&&e in s),y.registerHelper("lookup",(s,e)=>s&&typeof s=="object"?s[e]:void 0),y.registerHelper("reMatch",(s,e)=>{try{return new RegExp(s).test(e)}catch{return!1}})}l(_e,"registerCommonHandlebarsHelpers");function E(s,e="",t,n=!1){let o=e+" ",r;switch(s.kind){case p.String:r="z.string()",s.format==="date"||s.format==="date-time"?r+=".datetime()":s.format==="email"?r+=".email()":s.format==="uri"||s.format==="url"?r+=".url()":s.format==="uuid"&&(r+=".uuid()");break;case p.Number:r="z.number()";break;case p.Integer:r="z.number().int()";break;case p.Boolean:r="z.boolean()";break;case p.Null:r="z.null()";break;case p.Ref:s.ref?r=n?`${s.ref}Schema`:`Schema.${s.ref}Schema`:r="z.unknown()";break;case p.Array:s.items?r=`z.array(${E(s.items,o,t,n)})`:r="z.array(z.unknown())";break;case p.Object:if(!s.properties||s.properties.length===0)s.additionalProperties?r=`z.record(z.string(), ${E(s.additionalProperties,o,t,n)})`:r="z.record(z.string(), z.unknown())";else{let a=[];for(let c of s.properties){let f=E(c.type,o,t,n),d=ce(c.name);c.required?a.push(`${o}${d}: ${f}`):a.push(`${o}${d}: ${f}.optional()`)}let i=`z.object({
3
+ ${a.join(`,
4
4
  `)}
5
- ${e}})`}break;case p.Enum:n.enumValues&&n.enumValues.length>0?r=`z.enum([${n.enumValues.map(s=>s==="true"||s==="false"||/^-?[0-9]+(\.[0-9]+)?$/.test(s)?s:JSON.stringify(s)).join(", ")}])`:r="z.string()";break;case p.OneOf:n.oneOf&&n.oneOf.length>0?r=`z.union([${n.oneOf.map(s=>q(s,t)).join(", ")}])`:r="z.unknown()";break;case p.AnyOf:n.anyOf&&n.anyOf.length>0?r=`z.union([${n.anyOf.map(s=>q(s,t)).join(", ")}])`:r="z.unknown()";break;case p.AllOf:if(n.allOf&&n.allOf.length>0){let o=n.allOf.map(s=>q(s,t));r=o.join(".and(")+")".repeat(o.length-1)}else r="z.unknown()";break;default:r="z.unknown()"}return n.nullable&&r!=="z.null()"&&(r=`${r}.nullable()`),r}c(q,"schemaToZodSchema");function gt(n){return n.replace(/&quot;/g,'"').replace(/&lt;/g,"<").replace(/&gt;/g,">").replace(/&#x60;/g,"`").replace(/&#96;/g,"`").replace(/&amp;/g,"&")}c(gt,"decodeHtmlEntities");function I(n){let e;switch(n.kind){case p.String:n.format==="binary"?e="Blob":e="string";break;case p.Number:case p.Integer:e="number";break;case p.Boolean:e="boolean";break;case p.Null:e="null";break;case p.Ref:n.ref?e="Schema."+n.ref:e="unknown";break;case p.Array:if(n.items){let t=I(n.items);t.includes(" | ")||t.includes(" & ")?e=`Array<(${t})>`:e=`Array<${t}>`}else e="Array<unknown>";break;case p.OneOf:n.oneOf?e=n.oneOf.map(r=>I(r)).join(" | "):e="unknown";break;case p.AnyOf:n.anyOf?e=n.anyOf.map(r=>I(r)).join(" | "):e="unknown";break;case p.AllOf:n.allOf?e=n.allOf.map(r=>I(r)).join(" & "):e="unknown";break;case p.Enum:if(n.enumValues&&n.enumValues.length>0){let t=[];switch(n.enumBase){case p.Number:case p.Integer:for(let r of n.enumValues)t.push(r);break;case p.Boolean:for(let r of n.enumValues)r==="true"||r==="false"?t.push(r):t.push(`"${r}"`);break;default:for(let r of n.enumValues)t.push(`"${r}"`)}e=t.join(" | ")}else e="unknown";break;case p.Object:if(!n.properties||n.properties.length===0)e="Record<string, unknown>";else{let t=[];for(let r of n.properties){let o=I(r.type);r.required?t.push(`${r.name}: ${o}`):t.push(`${r.name}?: ${o}`)}e="{ "+t.join("; ")+" }"}break;default:e="unknown"}return n.nullable&&e!=="null"&&(e+=" | null"),gt(e)}c(I,"schemaToTSType");function L(n){let e=n.path,t=e.includes("{")&&e.includes("}");if(n.operationID)return N(n.operationID);switch(n.method){case"GET":return t?"get":"list";case"POST":return"create";case"PUT":case"PATCH":return"update";case"DELETE":return"delete";default:return n.method.toLowerCase()}}c(L,"deriveMethodName");async function Be(n,e){if(n.operationIdParser)try{let r=await n.operationIdParser(e.operationID,e.method,e.path);if(r)return N(r)}catch{}let t=ht(e.operationID);return t?N(t):L(e)}c(Be,"resolveMethodName");function ht(n){if(!n)return"";let e=n.indexOf("Controller_");return e>=0?n.substring(e+11):n}c(ht,"defaultParseOperationID");function ze(n){let e=n.path,t="`";for(let r=0;r<e.length;r++){if(e[r]==="{"){let o=r+1;for(;o<e.length&&e[o]!=="}";)o++;if(o<e.length){let s=e.substring(r+1,o);t+=`\${encodeURIComponent(${s})}`,r=o;continue}}t+=e[r]}return t+="`",t}c(ze,"buildPathTemplate");function Me(n){let t=n.path.split("/"),r=[];for(let s of t)s!==""&&(s.startsWith("{")&&s.endsWith("}")||r.push(s));return`'${r.join("/")}'`}c(Me,"buildQueryKeyBase");function ie(n){let e=[],t=new Map;for(let o=0;o<n.pathParams.length;o++)t.set(n.pathParams[o].name,o);let r=n.path;for(let o=0;o<r.length;o++)if(r[o]==="{"){let s=o+1;for(;s<r.length&&r[s]!=="}";)s++;if(s<r.length){let a=r.substring(o+1,s),i=t.get(a);i!==void 0&&e.push(n.pathParams[i]),o=s;continue}}return e}c(ie,"orderPathParams");function ye(n,e){let t=[];for(let r of ie(n))t.push(`${r.name}: ${I(r.schema)}`);if(n.queryParams.length>0){let r=O(n.tag)+O(e)+"Query";t.push(`query?: Schema.${r}`)}if(n.requestBody){let r=n.requestBody.required?"":"?";t.push(`body${r}: ${I(n.requestBody.schema)}`)}return t.push('init?: Omit<RequestInit, "method" | "body">'),t}c(ye,"buildMethodSignature");function Ue(n){let e=[];for(let t of ie(n))e.push(t.name);return n.queryParams.length>0&&e.push("query"),n.requestBody&&e.push("body"),e}c(Ue,"queryKeyArgs");function ae(n){let e=!1;for(let t of n)if(!(t>="a"&&t<="z"||t>="A"&&t<="Z"||t>="0"&&t<="9"||t==="_"||t==="$")){e=!0;break}return n.length>0&&n[0]>="0"&&n[0]<="9"&&(e=!0),e?`"${n}"`:n}c(ae,"quoteTSPropertyName");function Le(n){return n.response.isStreaming===!0}c(Le,"isStreamingOperation");function Ge(n){let e=n.response.schema;return e.kind===p.Array&&e.items?I(e.items):n.response.streamingFormat==="sse"?"string":I(e)}c(Ge,"getStreamingItemType");function yt(n,e,t,r){var o=arguments.length,s=o<3?e:r===null?r=Object.getOwnPropertyDescriptor(e,t):r,a;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")s=Reflect.decorate(n,e,t,r);else for(var i=n.length-1;i>=0;i--)(a=n[i])&&(s=(o<3?a(s):o>3?a(e,t,s):a(e,t))||s);return o>3&&s&&Object.defineProperty(e,t,s),s}c(yt,"_ts_decorate");function Ve(n,e){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(n,e)}c(Ve,"_ts_metadata");var _=class n{static{c(this,"TypeScriptGeneratorService")}configService;logger=new ce.Logger(n.name);constructor(e){this.configService=e}getType(){return"typescript"}async generate(e,t){let r=v.join(e.outDir,"src"),o=v.join(r,"services");await w.promises.mkdir(o,{recursive:!0});let s=await this.preprocessIR(e,t);this.registerHandlebarsHelpers(e),await this.generateClient(e,s,r),await this.generateIndex(e,s,r),await this.generateUtils(e,s,r),await this.generateServices(e,s,o),await this.generateSchema(e,s,r),await this.generateZodSchema(e,s,r),await this.generatePackageJson(e),await this.generateTsConfig(e),await this.generateReadme(e,s)}async preprocessIR(e,t){let r=await Promise.all(t.services.map(async o=>({...o,operations:await Promise.all(o.operations.map(async s=>{let a=await Be(e,s);return{...s,_resolvedMethodName:a}}))})));return{...t,services:r}}registerHandlebarsHelpers(e){_e(),h.registerHelper("methodName",t=>t._resolvedMethodName||L(t)),h.registerHelper("queryTypeName",t=>{let r=t._resolvedMethodName||L(t);return O(t.tag)+O(r)+"Query"}),h.registerHelper("pathTemplate",t=>{let r=ze(t);return new h.SafeString(r)}),h.registerHelper("queryKeyBase",t=>Me(t)),h.registerHelper("pathParamsInOrder",t=>ie(t)),h.registerHelper("methodSignature",t=>{let r=t._resolvedMethodName||L(t);return ye(t,r).map(s=>new h.SafeString(s))}),h.registerHelper("methodSignatureNoInit",t=>{let r=t._resolvedMethodName||L(t);return ye(t,r).slice(0,-1)}),h.registerHelper("queryKeyArgs",t=>Ue(t)),h.registerHelper("tsType",t=>t&&typeof t=="object"&&"kind"in t?I(t):"unknown"),h.registerHelper("stripSchemaNs",t=>t.replace(/^Schema\./,"")),h.registerHelper("tsTypeStripNs",t=>{if(t&&typeof t=="object"&&"kind"in t){let o=I(t).replace(/^Schema\./,"");return new h.SafeString(o)}return"unknown"}),h.registerHelper("decodeHtml",t=>typeof t!="string"?t:t.replace(/&quot;/g,'"').replace(/&lt;/g,"<").replace(/&gt;/g,">").replace(/&#x60;/g,"`").replace(/&amp;/g,"&")),h.registerHelper("quotePropName",t=>ae(t)),h.registerHelper("zodSchema",t=>t&&typeof t=="object"&&"kind"in t?new h.SafeString(q(t)):"z.unknown()"),h.registerHelper("isStreaming",t=>Le(t)),h.registerHelper("streamingItemType",t=>new h.SafeString(Ge(t)))}async renderTemplate(e,t,r,o){let s=o.templates?.[e];if(s){this.logger.debug(`Using template override for ${e}: ${s}`);try{await w.promises.access(s,w.constants.R_OK);let y=await w.promises.readFile(s,"utf-8"),T=h.compile(y)(t);await w.promises.writeFile(r,T,"utf-8");return}catch(y){let b=y instanceof Error?y.message:String(y);throw this.logger.error(`Template override file not found or not readable: ${s}. Error: ${b}`),new Error(`Template override file not found or not readable: ${s}`)}}let a=[v.join(__dirname,"generator/typescript/templates",e),v.join(__dirname,"templates",e),v.join(__dirname,"../typescript/templates",e),v.join(process.cwd(),"src/generator/typescript/templates",e)],i=null;for(let y of a)try{await w.promises.access(y),i=y,this.logger.debug(`Found template at: ${i}`);break}catch{this.logger.debug(`Template not found at: ${y}`)}if(!i)throw this.logger.error(`Template not found: ${e}`),this.logger.error(`Checked paths: ${a.join(", ")}`),this.logger.error(`__dirname: ${__dirname}`),new Error(`Template not found: ${e}`);let l=await w.promises.readFile(i,"utf-8"),u=h.compile(l)(t);await w.promises.writeFile(r,u,"utf-8")}async generateClient(e,t,r){let o=v.join(r,"client.ts");if(!this.configService.shouldExcludeFile(e,o))try{await this.renderTemplate("client.ts.hbs",{Client:e,IR:t},o,e)}catch(s){let a=s instanceof Error?s.message:String(s);this.logger.warn(`Template client.ts.hbs not found: ${a}, using placeholder`),await w.promises.writeFile(o,"// Generated client - template rendering to be implemented","utf-8")}}async generateIndex(e,t,r){let o=v.join(r,"index.ts");if(!this.configService.shouldExcludeFile(e,o))try{await this.renderTemplate("index.ts.hbs",{Client:e,IR:t},o,e)}catch{this.logger.warn("Template index.ts.hbs not found, using placeholder"),await w.promises.writeFile(o,"// Generated index - template rendering to be implemented","utf-8")}}async generateUtils(e,t,r){let o=v.join(r,"utils.ts");if(!this.configService.shouldExcludeFile(e,o))try{await this.renderTemplate("utils.ts.hbs",{Client:e,IR:t},o,e)}catch{this.logger.warn("Template utils.ts.hbs not found, using placeholder"),await w.promises.writeFile(o,"// Generated utils - template rendering to be implemented","utf-8")}}async generateServices(e,t,r){for(let o of t.services){let s=v.join(r,`${W(o.tag).toLowerCase()}.ts`);if(!this.configService.shouldExcludeFile(e,s))try{await this.renderTemplate("service.ts.hbs",{Client:e,Service:o,IR:t},s,e)}catch{this.logger.warn("Template service.ts.hbs not found, using placeholder");let i=`// Generated service ${o.tag} - template rendering to be implemented`;await w.promises.writeFile(s,i,"utf-8")}}}async generateSchema(e,t,r){let o=v.join(r,"schema.ts");if(!this.configService.shouldExcludeFile(e,o))try{await this.renderTemplate("schema.ts.hbs",{Client:e,IR:t},o,e)}catch(s){let a=s instanceof Error?s.message:String(s);this.logger.warn(`Template schema.ts.hbs error: ${a}, using placeholder`),await w.promises.writeFile(o,"// Generated schema - template rendering to be implemented","utf-8")}}async generateZodSchema(e,t,r){let o=v.join(r,"schema.zod.ts");if(!this.configService.shouldExcludeFile(e,o))try{await this.renderTemplate("schema.zod.ts.hbs",{Client:e,IR:t},o,e)}catch(s){let a=s instanceof Error?s.message:String(s);this.logger.warn(`Template schema.zod.ts.hbs error: ${a}, using placeholder`),await w.promises.writeFile(o,"// Generated Zod schemas - template rendering to be implemented","utf-8")}}async generatePackageJson(e){let t=v.join(e.outDir,"package.json");if(!this.configService.shouldExcludeFile(e,t))try{await this.renderTemplate("package.json.hbs",{Client:e},t,e)}catch{this.logger.warn("Template package.json.hbs not found, using fallback");let o=JSON.stringify({name:e.packageName,version:"0.0.1",main:"dist/index.js",types:"dist/index.d.ts"},null,2);await w.promises.writeFile(t,o,"utf-8")}}async generateTsConfig(e){let t=v.join(e.outDir,"tsconfig.json");if(!this.configService.shouldExcludeFile(e,t))try{await this.renderTemplate("tsconfig.json.hbs",{Client:e},t,e)}catch{this.logger.warn("Template tsconfig.json.hbs not found, using fallback");let o=JSON.stringify({compilerOptions:{target:"ES2020",module:"commonjs",lib:["ES2020"],declaration:!0,outDir:"./dist",rootDir:"./src",strict:!0,esModuleInterop:!0,skipLibCheck:!0,forceConsistentCasingInFileNames:!0},include:["src/**/*"]},null,2);await w.promises.writeFile(t,o,"utf-8")}}async generateReadme(e,t){let r=v.join(e.outDir,"README.md");if(!this.configService.shouldExcludeFile(e,r))try{await this.renderTemplate("README.md.hbs",{Client:e,IR:t},r,e)}catch{this.logger.warn("Template README.md.hbs not found, using fallback");let s=`# ${e.name}
5
+ ${e}})`;if(s.additionalProperties){let c=E(s.additionalProperties,o,t,n);r=`${i}.catchall(${c})`}else r=i}break;case p.Enum:s.enumValues&&s.enumValues.length>0?r=`z.enum([${s.enumValues.map(i=>i==="true"||i==="false"||/^-?[0-9]+(\.[0-9]+)?$/.test(i)?i:JSON.stringify(i)).join(", ")}])`:r="z.string()";break;case p.OneOf:s.oneOf&&s.oneOf.length>0?r=`z.union([${s.oneOf.map(i=>E(i,o,t,n)).join(", ")}])`:r="z.unknown()";break;case p.AnyOf:s.anyOf&&s.anyOf.length>0?r=`z.union([${s.anyOf.map(i=>E(i,o,t,n)).join(", ")}])`:r="z.unknown()";break;case p.AllOf:if(s.allOf&&s.allOf.length>0){let a=s.allOf.map(i=>E(i,o,t,n));r=a.join(".and(")+")".repeat(a.length-1)}else r="z.unknown()";break;default:r="z.unknown()"}return s.nullable&&r!=="z.null()"&&(r=`${r}.nullable()`),r}l(E,"schemaToZodSchema");function bt(s){return s.replace(/&quot;/g,'"').replace(/&lt;/g,"<").replace(/&gt;/g,">").replace(/&#x60;/g,"`").replace(/&#96;/g,"`").replace(/&amp;/g,"&")}l(bt,"decodeHtmlEntities");function H(s,e,t,n=!1){let o;switch(s.kind){case p.String:s.format==="binary"?o="Blob":o="string";break;case p.Number:case p.Integer:o="number";break;case p.Boolean:o="boolean";break;case p.Null:o="null";break;case p.Ref:s.ref?e?.some(r=>r.type===s.ref)||n&&t&&t.find(a=>a.name===s.ref)?o=s.ref:o="Schema."+s.ref:o="unknown";break;case p.Array:if(s.items){let r=H(s.items,e,t);r.includes(" | ")||r.includes(" & ")?o=`Array<(${r})>`:o=`Array<${r}>`}else o="Array<unknown>";break;case p.OneOf:s.oneOf?o=s.oneOf.map(a=>H(a,e,t)).join(" | "):o="unknown";break;case p.AnyOf:s.anyOf?o=s.anyOf.map(a=>H(a,e,t)).join(" | "):o="unknown";break;case p.AllOf:s.allOf?o=s.allOf.map(a=>H(a,e,t)).join(" & "):o="unknown";break;case p.Enum:if(s.enumValues&&s.enumValues.length>0){let r=[];switch(s.enumBase){case p.Number:case p.Integer:for(let a of s.enumValues)r.push(a);break;case p.Boolean:for(let a of s.enumValues)a==="true"||a==="false"?r.push(a):r.push(`"${a}"`);break;default:for(let a of s.enumValues)r.push(`"${a}"`)}o=r.join(" | ")}else o="unknown";break;case p.Object:if(!s.properties||s.properties.length===0)o="Record<string, unknown>";else{let r=[];for(let a of s.properties){let i=H(a.type,e,t,n);a.required?r.push(`${a.name}: ${i}`):r.push(`${a.name}?: ${i}`)}o="{ "+r.join("; ")+" }"}break;default:o="unknown"}return s.nullable&&o!=="null"&&(o+=" | null"),bt(o)}l(H,"schemaToTSType");function V(s){let e=s.path,t=e.includes("{")&&e.includes("}");if(s.operationID)return q(s.operationID);switch(s.method){case"GET":return t?"get":"list";case"POST":return"create";case"PUT":case"PATCH":return"update";case"DELETE":return"delete";default:return s.method.toLowerCase()}}l(V,"deriveMethodName");async function Me(s,e){if(s.operationIdParser)try{let n=await s.operationIdParser(e.operationID,e.method,e.path);if(n)return q(n)}catch{}let t=St(e.operationID);return t?q(t):V(e)}l(Me,"resolveMethodName");function St(s){if(!s)return"";let e=s.indexOf("Controller_");return e>=0?s.substring(e+11):s}l(St,"defaultParseOperationID");function ze(s){let e=s.path,t="`";for(let n=0;n<e.length;n++){if(e[n]==="{"){let o=n+1;for(;o<e.length&&e[o]!=="}";)o++;if(o<e.length){let r=e.substring(n+1,o);t+=`\${encodeURIComponent(${r})}`,n=o;continue}}t+=e[n]}return t+="`",t}l(ze,"buildPathTemplate");function Ue(s){let t=s.path.split("/"),n=[];for(let r of t)r!==""&&(r.startsWith("{")&&r.endsWith("}")||n.push(r));return`'${n.join("/")}'`}l(Ue,"buildQueryKeyBase");function le(s){let e=[],t=new Map;for(let o=0;o<s.pathParams.length;o++)t.set(s.pathParams[o].name,o);let n=s.path;for(let o=0;o<n.length;o++)if(n[o]==="{"){let r=o+1;for(;r<n.length&&n[r]!=="}";)r++;if(r<n.length){let a=n.substring(o+1,r),i=t.get(a);i!==void 0&&e.push(s.pathParams[i]),o=r;continue}}return e}l(le,"orderPathParams");function Be(s,e,t,n=!1){return H(s,t,e,n)}l(Be,"schemaToTSTypeWithSimpleTypes");function be(s,e,t,n,o=!1){let r=[];for(let a of le(s))r.push(`${a.name}: ${Be(a.schema,t,n,o)}`);if(s.queryParams.length>0){let a=j(s.tag)+j(e)+"Query";r.push(`query?: Schema.${a}`)}if(s.requestBody){let a=s.requestBody.required===!0?"":"?";r.push(`body${a}: ${Be(s.requestBody.schema,t,n,o)}`)}return r.push('init?: Omit<RequestInit, "method" | "body">'),r}l(be,"buildMethodSignature");function Le(s,e){if(!e||e.length===0)return[];let t=new Set,n=l(r=>{let a=s.find(i=>i.name===r);return a?a.schema:null},"resolveRef"),o=l(r=>{if(r.kind==="ref"&&r.ref)if(e.some(i=>i.type===r.ref))t.add(r.ref);else{let i=n(r.ref);i&&o(i)}else if(r.kind==="array"&&r.items)o(r.items);else if(r.kind==="object"&&r.properties)for(let a of r.properties)o(a.type);else if(r.kind==="oneOf"&&r.oneOf)for(let a of r.oneOf)o(a);else if(r.kind==="anyOf"&&r.anyOf)for(let a of r.anyOf)o(a);else if(r.kind==="allOf"&&r.allOf)for(let a of r.allOf)o(a)},"checkSchema");for(let r of s)o(r.schema);return e.filter(r=>t.has(r.type))}l(Le,"collectPredefinedTypesUsedInSchema");function Ge(s,e,t){if(!e||e.length===0)return[];let n=new Set,o=l(a=>{if(!t)return null;let i=t.find(c=>c.name===a);return i?i.schema:null},"resolveRef"),r=l(a=>{if(a.kind==="ref"&&a.ref)if(e.some(c=>c.type===a.ref))n.add(a.ref);else{let c=o(a.ref);c&&r(c)}else if(a.kind==="array"&&a.items)r(a.items);else if(a.kind==="object"&&a.properties)for(let i of a.properties)r(i.type);else if(a.kind==="oneOf"&&a.oneOf)for(let i of a.oneOf)r(i);else if(a.kind==="anyOf"&&a.anyOf)for(let i of a.anyOf)r(i);else if(a.kind==="allOf"&&a.allOf)for(let i of a.allOf)r(i)},"checkSchema");for(let a of s.operations)for(let i of a.pathParams)r(i.schema);return e.filter(a=>n.has(a.type))}l(Ge,"collectPredefinedTypesUsedInService");function Ve(s){let e=[];for(let t of le(s))e.push(t.name);return s.queryParams.length>0&&e.push("query"),s.requestBody&&e.push("body"),e}l(Ve,"queryKeyArgs");function ce(s){let e=!1;for(let t of s)if(!(t>="a"&&t<="z"||t>="A"&&t<="Z"||t>="0"&&t<="9"||t==="_"||t==="$")){e=!0;break}return s.length>0&&s[0]>="0"&&s[0]<="9"&&(e=!0),e?`"${s}"`:s}l(ce,"quoteTSPropertyName");function Ze(s){return s.response.isStreaming===!0}l(Ze,"isStreamingOperation");function We(s){let e=s.response.schema;return e.kind===p.Array&&e.items?H(e.items):s.response.streamingFormat==="sse"?"string":H(e)}l(We,"getStreamingItemType");function Tt(s,e,t,n){var o=arguments.length,r=o<3?e:n===null?n=Object.getOwnPropertyDescriptor(e,t):n,a;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")r=Reflect.decorate(s,e,t,n);else for(var i=s.length-1;i>=0;i--)(a=s[i])&&(r=(o<3?a(r):o>3?a(e,t,r):a(e,t))||r);return o>3&&r&&Object.defineProperty(e,t,r),r}l(Tt,"_ts_decorate");function Je(s,e){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(s,e)}l(Je,"_ts_metadata");var M=class s{static{l(this,"TypeScriptGeneratorService")}configService;logger=new pe.Logger(s.name);constructor(e){this.configService=e}getType(){return"typescript"}async generate(e,t){let n=O.join(e.outDir,"src"),o=O.join(n,"services");await w.promises.mkdir(o,{recursive:!0});let r=await this.preprocessIR(e,t);this.registerHandlebarsHelpers(e),await this.generateClient(e,r,n),await this.generateIndex(e,r,n),await this.generateUtils(e,r,n),await this.generateServices(e,r,o),await this.generateSchema(e,r,n),await this.generateZodSchema(e,r,n),await this.generatePackageJson(e),await this.generateTsConfig(e),await this.generateReadme(e,r)}async preprocessIR(e,t){let n=await Promise.all(t.services.map(async o=>({...o,operations:await Promise.all(o.operations.map(async r=>{let a=await Me(e,r);return{...r,_resolvedMethodName:a}}))})));return{...t,services:n}}registerHandlebarsHelpers(e){_e(),u.registerHelper("methodName",t=>t._resolvedMethodName||V(t)),u.registerHelper("queryTypeName",t=>{let n=t._resolvedMethodName||V(t);return j(t.tag)+j(n)+"Query"}),u.registerHelper("pathTemplate",t=>{let n=ze(t);return new u.SafeString(n)}),u.registerHelper("queryKeyBase",t=>{let n=Ue(t);return new u.SafeString(n)}),u.registerHelper("pathParamsInOrder",t=>le(t)),u.registerHelper("methodSignature",(t,n)=>{let o=t._resolvedMethodName||V(t),r=n?.data?.root?.IR?.modelDefs||[],a=n?.data?.root?.PredefinedTypes||[],i=n?.data?.root?.isSameFile||!1;return be(t,o,r,a,i).map(f=>new u.SafeString(f))}),u.registerHelper("methodSignatureNoInit",(t,n)=>{let o=t._resolvedMethodName||V(t),r=n?.data?.root?.IR?.modelDefs||[],a=n?.data?.root?.PredefinedTypes||[],i=n?.data?.root?.isSameFile||!1;return be(t,o,r,a,i).slice(0,-1)}),u.registerHelper("queryKeyArgs",t=>Ve(t).map(o=>new u.SafeString(o))),u.registerHelper("tsType",(t,n)=>{if(t&&typeof t=="object"&&"kind"in t){let o=n?.data?.root?.PredefinedTypes||[],r=n?.data?.root?.IR?.modelDefs||[],a=n?.data?.root?.isSameFile||!1;return H(t,o,r,a)}return"unknown"}),u.registerHelper("stripSchemaNs",t=>t.replace(/^Schema\./,"")),u.registerHelper("tsTypeStripNs",(t,n)=>{let o=n?.data?.root?.PredefinedTypes||[],r=n?.data?.root?.IR?.modelDefs||[],a=n?.data?.root?.isSameFile||!1;if(t&&typeof t=="object"&&"kind"in t){let c=H(t,o,r,a).replace(/Schema\./g,"");return new u.SafeString(c)}if(typeof t=="string"){if(t.startsWith("Schema.")){let i=t.replace(/^Schema\./,"");return o.find(f=>f.type===i)?new u.SafeString(i):new u.SafeString(i)}return new u.SafeString(t)}return"unknown"}),u.registerHelper("isPredefinedType",(t,n)=>(n?.data?.root?.PredefinedTypes||[]).some(r=>r.type===t)),u.registerHelper("getPredefinedType",(t,n)=>(n?.data?.root?.PredefinedTypes||[]).find(r=>r.type===t)),u.registerHelper("groupByPackage",t=>{let n={};for(let o of t||[])n[o.package]||(n[o.package]={package:o.package,types:[]}),n[o.package].types.push(o.type);return Object.values(n)}),u.registerHelper("getServicePredefinedTypes",(t,n)=>{let o=n?.data?.root?.PredefinedTypes||[],r=n?.data?.root?.IR?.modelDefs||[];return Ge(t,o,r)}),u.registerHelper("getSchemaPredefinedTypes",t=>{let n=t?.data?.root?.PredefinedTypes||[],o=t?.data?.root?.IR?.modelDefs||[];return Le(o,n)}),u.registerHelper("joinTypes",t=>t.join(", ")),u.registerHelper("uniquePackages",t=>{let n=new Set;for(let o of t||[])o.package&&n.add(o.package);return Array.from(n)}),u.registerHelper("isPredefinedPackage",(t,n)=>n?n.some(o=>o.package===t):!1),u.registerHelper("getAllDependencies",t=>{let n={zod:"^4.3.5"};if(t.predefinedTypes)for(let o of t.predefinedTypes)o.package&&!n[o.package]&&(n[o.package]=t.dependencies?.[o.package]||"*");if(t.dependencies)for(let[o,r]of Object.entries(t.dependencies))o!=="zod"&&!n[o]&&(n[o]=r);return n}),u.registerHelper("decodeHtml",t=>{if(typeof t!="string")return t;let n=t.replace(/&amp;#x60;/g,"&#x60;").replace(/&amp;#96;/g,"&#96;").replace(/&amp;quot;/g,"&quot;").replace(/&amp;lt;/g,"&lt;").replace(/&amp;gt;/g,"&gt;");return n=n.replace(/&quot;/g,'"').replace(/&lt;/g,"<").replace(/&gt;/g,">").replace(/&#x60;/g,"`").replace(/&#96;/g,"`").replace(/&amp;/g,"&"),new u.SafeString(n)}),u.registerHelper("quotePropName",t=>ce(t)),u.registerHelper("zodSchema",(t,n)=>{if(t&&typeof t=="object"&&"kind"in t){let o=n?.data?.root?.IR?.modelDefs||[],r=n?.data?.root?._templateName==="schema.zod.ts.hbs";return new u.SafeString(E(t,"",o,r))}return"z.unknown()"}),u.registerHelper("isStreaming",t=>Ze(t)),u.registerHelper("streamingItemType",t=>new u.SafeString(We(t)))}async renderTemplate(e,t,n,o){let r=o.templates?.[e];if(r){this.logger.debug(`Using template override for ${e}: ${r}`);try{await w.promises.access(r,w.constants.R_OK);let g=await w.promises.readFile(r,"utf-8"),S=u.compile(g),D={...t,_templateName:e},z=S(D);await w.promises.writeFile(n,z,"utf-8");return}catch(g){let S=g instanceof Error?g.message:String(g);throw this.logger.error(`Template override file not found or not readable: ${r}. Error: ${S}`),new Error(`Template override file not found or not readable: ${r}`)}}let a=[O.join(__dirname,"generator/typescript/templates",e),O.join(__dirname,"templates",e),O.join(__dirname,"../typescript/templates",e),O.join(process.cwd(),"src/generator/typescript/templates",e)],i=null;for(let g of a)try{await w.promises.access(g),i=g,this.logger.debug(`Found template at: ${i}`);break}catch{this.logger.debug(`Template not found at: ${g}`)}if(!i)throw this.logger.error(`Template not found: ${e}`),this.logger.error(`Checked paths: ${a.join(", ")}`),this.logger.error(`__dirname: ${__dirname}`),new Error(`Template not found: ${e}`);let c=await w.promises.readFile(i,"utf-8"),f=u.compile(c),d={...t,_templateName:e},b=f(d);await w.promises.writeFile(n,b,"utf-8")}async generateClient(e,t,n){let o=O.join(n,"client.ts");if(!this.configService.shouldExcludeFile(e,o))try{await this.renderTemplate("client.ts.hbs",{Client:e,IR:t},o,e)}catch(r){let a=r instanceof Error?r.message:String(r);this.logger.warn(`Template client.ts.hbs not found: ${a}, using placeholder`),await w.promises.writeFile(o,"// Generated client - template rendering to be implemented","utf-8")}}async generateIndex(e,t,n){let o=O.join(n,"index.ts");if(!this.configService.shouldExcludeFile(e,o))try{await this.renderTemplate("index.ts.hbs",{Client:e,IR:t},o,e)}catch{this.logger.warn("Template index.ts.hbs not found, using placeholder"),await w.promises.writeFile(o,"// Generated index - template rendering to be implemented","utf-8")}}async generateUtils(e,t,n){let o=O.join(n,"utils.ts");if(!this.configService.shouldExcludeFile(e,o))try{await this.renderTemplate("utils.ts.hbs",{Client:e,IR:t},o,e)}catch{this.logger.warn("Template utils.ts.hbs not found, using placeholder"),await w.promises.writeFile(o,"// Generated utils - template rendering to be implemented","utf-8")}}async generateServices(e,t,n){for(let o of t.services){let r=O.join(n,`${Q(o.tag).toLowerCase()}.ts`);if(!this.configService.shouldExcludeFile(e,r))try{await this.renderTemplate("service.ts.hbs",{Client:e,Service:o,IR:t,PredefinedTypes:e.predefinedTypes||[],isSameFile:!1},r,e)}catch{this.logger.warn("Template service.ts.hbs not found, using placeholder");let i=`// Generated service ${o.tag} - template rendering to be implemented`;await w.promises.writeFile(r,i,"utf-8")}}}async generateSchema(e,t,n){let o=O.join(n,"schema.ts");if(!this.configService.shouldExcludeFile(e,o))try{await this.renderTemplate("schema.ts.hbs",{Client:e,IR:t,PredefinedTypes:e.predefinedTypes||[],isSameFile:!0},o,e)}catch(r){let a=r instanceof Error?r.message:String(r);this.logger.warn(`Template schema.ts.hbs error: ${a}, using placeholder`),await w.promises.writeFile(o,"// Generated schema - template rendering to be implemented","utf-8")}}async generateZodSchema(e,t,n){let o=O.join(n,"schema.zod.ts");if(!this.configService.shouldExcludeFile(e,o))try{await this.renderTemplate("schema.zod.ts.hbs",{Client:e,IR:t},o,e)}catch(r){let a=r instanceof Error?r.message:String(r);this.logger.warn(`Template schema.zod.ts.hbs error: ${a}, using placeholder`),await w.promises.writeFile(o,"// Generated Zod schemas - template rendering to be implemented","utf-8")}}async generatePackageJson(e){let t=O.join(e.outDir,"package.json");if(!this.configService.shouldExcludeFile(e,t))try{await this.renderTemplate("package.json.hbs",{Client:e},t,e)}catch{this.logger.warn("Template package.json.hbs not found, using fallback");let o=JSON.stringify({name:e.packageName,version:"0.0.1",main:"dist/index.js",types:"dist/index.d.ts"},null,2);await w.promises.writeFile(t,o,"utf-8")}}async generateTsConfig(e){let t=O.join(e.outDir,"tsconfig.json");if(!this.configService.shouldExcludeFile(e,t))try{await this.renderTemplate("tsconfig.json.hbs",{Client:e},t,e)}catch{this.logger.warn("Template tsconfig.json.hbs not found, using fallback");let o=JSON.stringify({compilerOptions:{target:"ES2020",module:"commonjs",lib:["ES2020"],declaration:!0,outDir:"./dist",rootDir:"./src",strict:!0,esModuleInterop:!0,skipLibCheck:!0,forceConsistentCasingInFileNames:!0},include:["src/**/*"]},null,2);await w.promises.writeFile(t,o,"utf-8")}}async generateReadme(e,t){let n=O.join(e.outDir,"README.md");if(!this.configService.shouldExcludeFile(e,n))try{await this.renderTemplate("README.md.hbs",{Client:e,IR:t},n,e)}catch{this.logger.warn("Template README.md.hbs not found, using fallback");let r=`# ${e.name}
6
6
 
7
- Generated SDK from OpenAPI specification.`;await w.promises.writeFile(r,s,"utf-8")}}};_=yt([(0,ce.Injectable)(),Ve("design:type",Function),Ve("design:paramtypes",[typeof C>"u"?Object:C])],_);function bt(n,e,t,r){var o=arguments.length,s=o<3?e:r===null?r=Object.getOwnPropertyDescriptor(e,t):r,a;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")s=Reflect.decorate(n,e,t,r);else for(var i=n.length-1;i>=0;i--)(a=n[i])&&(s=(o<3?a(s):o>3?a(e,t,s):a(e,t))||s);return o>3&&s&&Object.defineProperty(e,t,s),s}c(bt,"_ts_decorate");function Ze(n,e){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(n,e)}c(Ze,"_ts_metadata");var G=class{static{c(this,"GeneratorModule")}generatorService;typeScriptGenerator;constructor(e,t){this.generatorService=e,this.typeScriptGenerator=t,this.generatorService.register(this.typeScriptGenerator)}};G=bt([(0,We.Module)({imports:[D,F],providers:[$,A,H,_],exports:[$,A,H]}),Ze("design:type",Function),Ze("design:paramtypes",[typeof $>"u"?Object:$,typeof _>"u"?Object:_])],G);function St(n,e,t,r){var o=arguments.length,s=o<3?e:r===null?r=Object.getOwnPropertyDescriptor(e,t):r,a;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")s=Reflect.decorate(n,e,t,r);else for(var i=n.length-1;i>=0;i--)(a=n[i])&&(s=(o<3?a(s):o>3?a(e,t,s):a(e,t))||s);return o>3&&s&&Object.defineProperty(e,t,s),s}c(St,"_ts_decorate");var V=class{static{c(this,"CliModule")}};V=St([(0,Ke.Module)({imports:[F,G,D],providers:[x,M]})],V);async function wt(){await Je.CommandFactory.run(V,{logger:["error","warn","log"]})}c(wt,"bootstrap");wt().catch(n=>{console.error("CLI Error:",n),process.exit(1)});
7
+ Generated SDK from OpenAPI specification.`;await w.promises.writeFile(n,r,"utf-8")}}};M=Tt([(0,pe.Injectable)(),Je("design:type",Function),Je("design:paramtypes",[typeof x>"u"?Object:x])],M);function wt(s,e,t,n){var o=arguments.length,r=o<3?e:n===null?n=Object.getOwnPropertyDescriptor(e,t):n,a;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")r=Reflect.decorate(s,e,t,n);else for(var i=s.length-1;i>=0;i--)(a=s[i])&&(r=(o<3?a(r):o>3?a(e,t,r):a(e,t))||r);return o>3&&r&&Object.defineProperty(e,t,r),r}l(wt,"_ts_decorate");function Ke(s,e){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(s,e)}l(Ke,"_ts_metadata");var Z=class{static{l(this,"GeneratorModule")}generatorService;typeScriptGenerator;constructor(e,t){this.generatorService=e,this.typeScriptGenerator=t,this.generatorService.register(this.typeScriptGenerator)}};Z=wt([(0,Qe.Module)({imports:[_,B],providers:[C,$,I,M],exports:[C,$,I]}),Ke("design:type",Function),Ke("design:paramtypes",[typeof C>"u"?Object:C,typeof M>"u"?Object:M])],Z);function Ot(s,e,t,n){var o=arguments.length,r=o<3?e:n===null?n=Object.getOwnPropertyDescriptor(e,t):n,a;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")r=Reflect.decorate(s,e,t,n);else for(var i=s.length-1;i>=0;i--)(a=s[i])&&(r=(o<3?a(r):o>3?a(e,t,r):a(e,t))||r);return o>3&&r&&Object.defineProperty(e,t,r),r}l(Ot,"_ts_decorate");var W=class{static{l(this,"CliModule")}};W=Ot([(0,Ye.Module)({imports:[B,Z,_],providers:[v,U]})],W);async function vt(){await Xe.CommandFactory.run(W,{logger:["error","warn","log"]})}l(vt,"bootstrap");vt().catch(s=>{console.error("CLI Error:",s),process.exit(1)});
8
8
  //# sourceMappingURL=main.js.map