@blimu/codegen 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/main.js ADDED
@@ -0,0 +1,8 @@
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(`,
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}
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)});
8
+ //# sourceMappingURL=main.js.map