@ahoo-wang/fetcher-generator 3.15.0 → 3.15.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- let e=require(`ts-morph`),t=require(`@ahoo-wang/fetcher`),n=require(`yaml`),r=require(`fs`),i=require(`path`),a=require(`@ahoo-wang/fetcher-wow`);var o=class{getTimestamp(){return new Date().toTimeString().slice(0,8)}info(e,...t){let n=this.getTimestamp();t.length>0?console.log(`[${n}] ℹ️ ${e}`,...t):console.log(`[${n}] ℹ️ ${e}`)}success(e,...t){let n=this.getTimestamp();t.length>0?console.log(`[${n}] ✅ ${e}`,...t):console.log(`[${n}] ✅ ${e}`)}error(e,...t){let n=this.getTimestamp();t.length>0?console.error(`[${n}] ❌ ${e}`,...t):console.error(`[${n}] ❌ ${e}`)}progress(e,t=0,...n){let r=this.getTimestamp(),i=` `.repeat(t);n.length>0?console.log(`[${r}] 🔄 ${i}${e}`,...n):console.log(`[${r}] 🔄 ${i}${e}`)}progressWithCount(e,t,n,r=0,...i){let a=this.getTimestamp(),o=` `.repeat(r),s=`[${e}/${t}]`;i.length>0?console.log(`[${a}] 🔄 ${o}${s} ${n}`,...i):console.log(`[${a}] 🔄 ${o}${s} ${n}`)}},s={name:`@ahoo-wang/fetcher-generator`,version:`3.15.0`,description:`A powerful TypeScript code generation tool that automatically generates type-safe API client code based on OpenAPI specifications. It is designed for general use cases and is also deeply optimized for the [Wow](https://github.com/Ahoo-Wang/Wow) Domain-Driven Design framework, providing native support for the CQRS architectural pattern.`,keywords:[`fetch`,`http`,`client`,`openapi`,`openapi3`,`swagger`,`generator`,`typescript`,`codegen`,`api`,`rest`],author:`Ahoo-Wang`,license:`Apache-2.0`,homepage:`https://github.com/Ahoo-Wang/fetcher/tree/master/packages/generator`,repository:{type:`git`,url:`https://github.com/Ahoo-Wang/fetcher.git`,directory:`packages/generator`},bugs:{url:`https://github.com/Ahoo-Wang/fetcher/issues`},type:`module`,main:`./dist/index.umd.js`,module:`./dist/index.es.js`,types:`./dist/index.d.ts`,bin:{"fetcher-generator":`./dist/cli.js`},exports:{".":{types:`./dist/index.d.ts`,import:`./dist/index.es.js`,require:`./dist/index.umd.js`}},files:[`dist`,`README.md`,`README.zh-CN.md`],scripts:{build:`vite build`,"test:ui":`vitest --ui`,test:`vitest run --coverage --testTimeout=15000`,lint:`eslint . --fix`,clean:`rm -rf dist`,analyze:`npx vite-bundle-analyzer -p auto`,generate:`node dist/cli.js generate -i test/demo.spec.json -o test-output -t tsconfig.json`},peerDependencies:{"@ahoo-wang/fetcher":`workspace:^3.0.0`,"@ahoo-wang/fetcher-eventstream":`workspace:^3.0.0`,"@ahoo-wang/fetcher-decorator":`workspace:^3.0.0`,"@ahoo-wang/fetcher-openapi":`workspace:^3.0.0`,"@ahoo-wang/fetcher-wow":`workspace:^3.0.0`},dependencies:{"ts-morph":`catalog:`,commander:`catalog:`,yaml:`catalog:`},devDependencies:{"@eslint/js":`catalog:`,"@types/node":`catalog:`,"@vitest/coverage-v8":`catalog:`,"@vitest/ui":`catalog:`,eslint:`catalog:`,globals:`catalog:`,prettier:`catalog:`,typescript:`catalog:`,"typescript-eslint":`catalog:`,"unplugin-dts":`catalog:`,vite:`catalog:`,"vite-bundle-analyzer":`catalog:`,vitest:`catalog:`}};function c(e){if(!e)return!1;try{let t=new URL(e);return t.protocol===`http:`||t.protocol===`https:`}catch{return e.length>0}}async function l(e){let t=new o;process.on(`SIGINT`,()=>{t.error(`Generation interrupted by user`),process.exit(130)}),c(e.input)||(t.error(`Invalid input: must be a valid file path or HTTP/HTTPS URL`),process.exit(2));try{t.info(`Fetcher Generator v${s.version}`),t.info(`Starting code generation...`),await new ft({inputPath:e.input,outputDir:e.output,configPath:e.config,tsConfigFilePath:e.tsConfigFilePath,logger:t}).generate(),t.success(`Code generation completed successfully! Files generated in: ${e.output}`)}catch(e){t.error(`Error during code generation:
1
+ let e=require(`ts-morph`),t=require(`@ahoo-wang/fetcher`),n=require(`yaml`),r=require(`fs`),i=require(`path`),a=require(`@ahoo-wang/fetcher-wow`);var o=class{getTimestamp(){return new Date().toTimeString().slice(0,8)}info(e,...t){let n=this.getTimestamp();t.length>0?console.log(`[${n}] ℹ️ ${e}`,...t):console.log(`[${n}] ℹ️ ${e}`)}success(e,...t){let n=this.getTimestamp();t.length>0?console.log(`[${n}] ✅ ${e}`,...t):console.log(`[${n}] ✅ ${e}`)}error(e,...t){let n=this.getTimestamp();t.length>0?console.error(`[${n}] ❌ ${e}`,...t):console.error(`[${n}] ❌ ${e}`)}progress(e,t=0,...n){let r=this.getTimestamp(),i=` `.repeat(t);n.length>0?console.log(`[${r}] 🔄 ${i}${e}`,...n):console.log(`[${r}] 🔄 ${i}${e}`)}progressWithCount(e,t,n,r=0,...i){let a=this.getTimestamp(),o=` `.repeat(r),s=`[${e}/${t}]`;i.length>0?console.log(`[${a}] 🔄 ${o}${s} ${n}`,...i):console.log(`[${a}] 🔄 ${o}${s} ${n}`)}},s={name:`@ahoo-wang/fetcher-generator`,version:`3.15.2`,description:`A powerful TypeScript code generation tool that automatically generates type-safe API client code based on OpenAPI specifications. It is designed for general use cases and is also deeply optimized for the [Wow](https://github.com/Ahoo-Wang/Wow) Domain-Driven Design framework, providing native support for the CQRS architectural pattern.`,keywords:[`fetch`,`http`,`client`,`openapi`,`openapi3`,`swagger`,`generator`,`typescript`,`codegen`,`api`,`rest`],author:`Ahoo-Wang`,license:`Apache-2.0`,homepage:`https://github.com/Ahoo-Wang/fetcher/tree/master/packages/generator`,repository:{type:`git`,url:`https://github.com/Ahoo-Wang/fetcher.git`,directory:`packages/generator`},bugs:{url:`https://github.com/Ahoo-Wang/fetcher/issues`},type:`module`,main:`./dist/index.umd.js`,module:`./dist/index.es.js`,types:`./dist/index.d.ts`,bin:{"fetcher-generator":`./dist/cli.js`},exports:{".":{types:`./dist/index.d.ts`,import:`./dist/index.es.js`,require:`./dist/index.umd.js`}},files:[`dist`,`README.md`,`README.zh-CN.md`],scripts:{build:`vite build`,"test:ui":`vitest --ui`,test:`vitest run --coverage --testTimeout=15000`,lint:`eslint . --fix`,clean:`rm -rf dist`,analyze:`npx vite-bundle-analyzer -p auto`,generate:`node dist/cli.js generate -i test/demo.spec.json -o test-output -t tsconfig.json`},peerDependencies:{"@ahoo-wang/fetcher":`workspace:^3.0.0`,"@ahoo-wang/fetcher-eventstream":`workspace:^3.0.0`,"@ahoo-wang/fetcher-decorator":`workspace:^3.0.0`,"@ahoo-wang/fetcher-openapi":`workspace:^3.0.0`,"@ahoo-wang/fetcher-wow":`workspace:^3.0.0`},dependencies:{"ts-morph":`catalog:`,commander:`catalog:`,yaml:`catalog:`},devDependencies:{"@eslint/js":`catalog:`,"@types/node":`catalog:`,"@vitest/coverage-v8":`catalog:`,"@vitest/ui":`catalog:`,eslint:`catalog:`,globals:`catalog:`,prettier:`catalog:`,typescript:`catalog:`,"typescript-eslint":`catalog:`,"unplugin-dts":`catalog:`,vite:`catalog:`,"vite-bundle-analyzer":`catalog:`,vitest:`catalog:`}};function c(e){if(!e)return!1;try{let t=new URL(e);return t.protocol===`http:`||t.protocol===`https:`}catch{return e.length>0}}async function l(e){let t=new o;process.on(`SIGINT`,()=>{t.error(`Generation interrupted by user`),process.exit(130)}),c(e.input)||(t.error(`Invalid input: must be a valid file path or HTTP/HTTPS URL`),process.exit(2));try{t.info(`Fetcher Generator v${s.version}`),t.info(`Starting code generation...`),await new ft({inputPath:e.input,outputDir:e.output,configPath:e.config,tsConfigFilePath:e.tsConfigFilePath,logger:t}).generate(),t.success(`Code generation completed successfully! Files generated in: ${e.output}`)}catch(e){t.error(`Error during code generation:
2
2
  `,e),process.exit(1)}}var u=`#/components/`;`${u}`,`${u}`,`${u}`,`${u}`,`${u}`;function d(e){return e.$ref.split(`/`).pop()}function f(e,t){let n=d(e);return t.schemas?.[n]}function p(e,t){let n=d(e);return t.requestBodies?.[n]}function ee(e,t){let n=d(e);return t.parameters?.[n]}function m(e,t){return{key:d(e),schema:f(e,t)}}var te=/[-_'\s./?;:,()[\]{}|\\]+/;function h(e){return e.split(te)}function g(e){return Array.isArray(e)?e.flatMap(e=>ne(h(e))):ne(h(e))}function ne(e){return e.flatMap(e=>{if(e.length===0)return[];let t=[],n=``;for(let r=0;r<e.length;r++){let i=e[r],a=/[A-Z]/.test(i),o=r>0&&/[a-z]/.test(e[r-1]);a&&o&&n?(t.push(n),n=i):n+=i}return n&&t.push(n),t})}function _(e){return e===``||e.length===0?``:g(e).filter(e=>e.length>0).map(e=>{let t=e.charAt(0),n=e.slice(1);return(/[a-zA-Z]/.test(t)?t.toUpperCase():t)+n.toLowerCase()}).join(``)}function v(e){let t=_(e);return t.charAt(0).toLowerCase()+t.slice(1)}function y(e){return e===``||Array.isArray(e)&&e.length===0?``:g(e).filter(e=>e.length>0).map(e=>e.toUpperCase()).join(`_`)}function b(e){return/^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(e)?e:`'${e}'`}function x(e){return/^\d+$/.test(e)?`NUM_${e}`:b(y(e))}function S(e){return!!(e&&typeof e==`object`&&`$ref`in e)}function C(e,t){if(t&&!S(t)&&t.content)return t.content[e]?.schema}function re(e){return C(t.ContentTypeValues.APPLICATION_JSON,e)}function ie(e){return C(t.ContentTypeValues.TEXT_EVENT_STREAM,e)}function ae(e){return C(`*/*`,e)}var oe=[`string`,`number`,`integer`,`boolean`,`null`];function se(e){return Array.isArray(e)?!0:oe.includes(e)}function ce(e){return Array.isArray(e.enum)&&e.enum.length>0}var le=`x-enum-text`;function ue(e){return e[le]}function w(e){return e.type===`object`&&!!e.properties}function T(e){return e.type===`array`&&!!e.items}function de(e){return Array.isArray(e.anyOf)&&e.anyOf.length>0}function fe(e){return Array.isArray(e.oneOf)&&e.oneOf.length>0}function E(e){return Array.isArray(e.allOf)&&e.allOf.length>0}function D(e){return de(e)||fe(e)||E(e)}function O(e){return e.includes(`|`)||e.includes(`&`)?`(${e})[]`:`${e}[]`}function k(e){return e.type===`object`&&!e.properties&&e.additionalProperties!==void 0}var pe=`x-map-key-schema`;function me(e){return e[pe]}function he(e){return e.type===`object`?e.properties?Object.keys(e.properties).length===0:!0:!1}function ge(e){return e.readOnly===!0}function A(e){if(Array.isArray(e))return e.map(e=>A(e)).join(` | `);switch(e){case`string`:return`string`;case`number`:case`integer`:return`number`;case`boolean`:return`boolean`;case`null`:return`null`;default:return`any`}}function _e(e){if(!w(e))return[];let t=e.required||[];return Object.keys(e.properties).filter(e=>!t.includes(e))}function ve(e,t){return e.operation.operationId&&t.operation.operationId?e.operation.operationId.localeCompare(t.operation.operationId):e.path&&t.path?e.path.localeCompare(t.path):e.method&&t.method?e.method.localeCompare(t.method):0}function j(e){let t=[];for(let[n,r]of Object.entries(e))M(r).forEach(e=>{t.push({method:e.method,operation:e.operation,path:n})});return t.sort(ve)}function M(e){return[{method:`get`,operation:e.get},{method:`put`,operation:e.put},{method:`post`,operation:e.post},{method:`delete`,operation:e.delete},{method:`options`,operation:e.options},{method:`head`,operation:e.head},{method:`patch`,operation:e.patch},{method:`trace`,operation:e.trace}].filter(({operation:e})=>e!==void 0)}function N(e){return e.responses[200]}function P(e){return re(N(e))}function ye(e,t){return e.parameters?e.parameters.map(e=>S(e)?ee(e,t):e).filter(e=>e.in===`path`):[]}var be=`string`;function F(e){return!e.schema||S(e.schema)||!e.schema.type||!se(e.schema.type)?be:A(e.schema.type)}function I(e){return e.startsWith(`http://`)||e.startsWith(`https://`)?xe(e):Se(e)}async function xe(e){return await(await fetch(e)).text()}function Se(e){return new Promise((t,n)=>{(0,r.readFile)(e,`utf-8`,(e,r)=>{e?n(e):t(r)})})}async function Ce(e){let t=await I(e);switch(R(t)){case L.JSON:return JSON.parse(t);case L.YAML:return(0,n.parse)(t);default:throw Error(`Unsupported file format: ${e}`)}}async function we(e){let t=await I(e);switch(R(t)){case L.JSON:return JSON.parse(t);case L.YAML:return(0,n.parse)(t);default:throw Error(`Unsupported file format: ${e}`)}}var L=function(e){return e.JSON=`json`,e.YAML=`yaml`,e}({});function R(e){let t=e.trimStart();if(t.startsWith(`{`)||t.startsWith(`[`))return L.JSON;if(t.startsWith(`-`)||t.startsWith(`%YAML`))return L.YAML;try{return JSON.parse(t),L.JSON}catch{if(t.length>0)return L.YAML}throw Error(`Unable to infer file format`)}var z=`types.ts`,Te=`@`;function Ee(e){return(0,t.combineURLs)(e.path,z)}function B(e,n,r){let i=(0,t.combineURLs)(n,r);return e.getSourceFile(i)||e.createSourceFile(i,``,{overwrite:!0})}function V(e,t,n){let r=e.getImportDeclaration(e=>e.getModuleSpecifierValue()===t);r||=e.addImportDeclaration({moduleSpecifier:t}),n.forEach(e=>{r.getNamedImports().some(t=>t.getName()===e)||r.addNamedImport(e)})}function H(e,t,n){if(n.path.startsWith(Te)){V(e,n.path,[n.name]);return}let r=(0,i.relative)(e.getDirectoryPath(),(0,i.join)(t,n.path,z));r=r.replace(/\.ts$/,``),r=r.split(i.sep).join(`/`),r.startsWith(`.`)||(r=`./`+r),V(e,r,[n.name])}function De(e,t,n,r){e.path!==r.path&&H(t,n,r)}function Oe(e,t=`
3
3
  `){if(!Array.isArray(e))return;let n=e.filter(e=>typeof e==`string`&&e.length>0);return n.length>0?n.join(t):void 0}function U(e,t){let n=Oe(t);n&&e.addJsDoc(n)}function W(e,t){let n=[e.title,e.description];return t&&n.push(`- key: ${t}`),e.format&&n.push(`- format: ${e.format}`),je(n,e,`default`),je(n,e,`example`),Ne(n,e),Pe(n,e),Fe(n,e),n}function ke(e,t,n){U(e,W(t,n))}function Ae(e,t,n){let r=W(t,n);Me(r,`schema`,t),U(e,r)}function je(e,t,n){let r=t[n];if(r){if(typeof r!=`object`){e.push(`- ${n}: \`${r}\``);return}Me(e,n,r)}}function Me(e,t,n){e.push(`- ${t}: `),e.push("```json"),e.push(JSON.stringify(n,null,2)),e.push("```")}function Ne(e,t){let n=[`- Numeric Constraints`];t.minimum!==void 0&&n.push(` - minimum: ${t.minimum}`),t.maximum!==void 0&&n.push(` - maximum: ${t.maximum}`),t.exclusiveMinimum!==void 0&&n.push(` - exclusiveMinimum: ${t.exclusiveMinimum}`),t.exclusiveMaximum!==void 0&&n.push(` - exclusiveMaximum: ${t.exclusiveMaximum}`),t.multipleOf!==void 0&&n.push(` - multipleOf: ${t.multipleOf}`),n.length!==1&&e.push(...n)}function Pe(e,t){let n=[`- String Constraints`];t.minLength!==void 0&&n.push(` - minLength: ${t.minLength}`),t.maxLength!==void 0&&n.push(` - maxLength: ${t.maxLength}`),t.pattern!==void 0&&n.push(` - pattern: ${t.pattern}`),n.length!==1&&e.push(...n)}function Fe(e,t){let n=[`- Array Constraints`];t.minItems!==void 0&&n.push(` - minItems: ${t.minItems}`),t.maxItems!==void 0&&n.push(` - maxItems: ${t.maxItems}`),t.uniqueItems!==void 0&&n.push(` - uniqueItems: ${t.uniqueItems}`),n.length!==1&&e.push(...n)}function Ie(e){let t=e.split(`.`);return t.length!=2||t[0].length===0||t[1].length===0?null:t}function Le(e){let t=Ie(e.name);return t?{tag:e,contextAlias:t[0],aggregateName:t[1]}:null}function Re(e){let t=e?.map(e=>Le(e)).filter(e=>e!==null);if(!t)return new Map;let n=new Map;return t.forEach(e=>{n.set(e.tag.name,{aggregate:e,commands:new Map,events:new Map})}),n}function ze(e){if(!e)return null;let t=e.split(`.`);return t.length==3?t[2]:null}var Be=`#/components/responses/wow.CommandOk`,Ve=`#/components/parameters/wow.id`,He=class{aggregates;constructor(e){this.openAPI=e,this.aggregates=Re(e.tags),this.build()}build(){let e=j(this.openAPI.paths);for(let t of e)this.commands(t.path,t),this.state(t.operation),this.events(t.operation),this.fields(t.operation)}resolve(){let e=new Map;for(let t of this.aggregates.values()){if(!t.state||!t.fields)continue;let n=t.aggregate.contextAlias,r=e.get(n);r||(r=new Set,e.set(n,r)),r.add(t)}return e}commands(e,n){let r=n.operation;if(r.operationId===`wow.command.send`)return;let i=ze(r.operationId);if(!i)return;let a=N(r);if(!a||!S(a)||a.$ref!==Be||!r.requestBody)return;let o=r.parameters??[],s=o.filter(e=>S(e)&&e.$ref===Ve).at(0),c=o.filter(e=>!S(e)&&e.in===`path`);if(s){let e=ee(s,this.openAPI.components);c.push(e)}let l=r.requestBody.content[t.ContentTypeValues.APPLICATION_JSON].schema,u=m(l,this.openAPI.components);u.schema.title=u.schema.title||r.summary,u.schema.description=u.schema.description||r.description;let d={name:i,method:n.method,path:e,pathParameters:c,summary:r.summary,description:r.description,schema:u,operation:r};r.tags?.forEach(e=>{let t=this.aggregates.get(e);t&&t.commands.set(i,d)})}state(e){if(!e.operationId?.endsWith(`.snapshot_state.single`))return;let t=P(e);if(!S(t))return;let n=m(t,this.openAPI.components);e.tags?.forEach(e=>{let t=this.aggregates.get(e);t&&(t.state=n)})}events(e){if(!this.openAPI.components||!e.operationId?.endsWith(`.event.list_query`))return;let t=P(e);if(S(t))return;let n=t?.items;if(!S(n))return;let r=f(n,this.openAPI.components).properties.body.items.anyOf.map(e=>{let t=e.title,n=e.properties.name.const,r=e.properties.body,i=m(r,this.openAPI.components);return i.schema.title=i.schema.title||e.title,{title:t,name:n,schema:i}});e.tags?.forEach(e=>{let t=this.aggregates.get(e);t&&r.forEach(e=>{t.events.set(e.name,e)})})}fields(e){if(!this.openAPI.components||!e.operationId?.endsWith(`.snapshot.count`))return;let n=p(e.requestBody,this.openAPI.components).content[t.ContentTypeValues.APPLICATION_JSON].schema,r=f(n,this.openAPI.components).properties?.field,i=m(r,this.openAPI.components);e.tags?.forEach(e=>{let t=this.aggregates.get(e);t&&(t.fields=i)})}},G=`@ahoo-wang/fetcher-wow`,Ue={"wow.command.CommandResult":`CommandResult`,"wow.command.CommandResultArray":`CommandResultArray`,"wow.MessageHeaderSqlType":`MessageHeaderSqlType`,"wow.api.BindingError":`BindingError`,"wow.api.DefaultErrorInfo":`ErrorInfo`,"wow.api.RecoverableType":`RecoverableType`,"wow.api.command.DefaultDeleteAggregate":`DeleteAggregate`,"wow.api.command.DefaultRecoverAggregate":`RecoverAggregate`,"wow.api.abac.DefaultApplyResourceTags":`ApplyResourceTags`,"wow.api.messaging.FunctionInfoData":`FunctionInfo`,"wow.api.messaging.FunctionKind":`FunctionKind`,"wow.api.modeling.AggregateId":`AggregateId`,"wow.api.query.Condition":`Condition`,"wow.api.query.ConditionOptions":`ConditionOptions`,"wow.api.query.ListQuery":`ListQuery`,"wow.api.query.Operator":`Operator`,"wow.api.query.PagedQuery":`PagedQuery`,"wow.api.query.Pagination":`Pagination`,"wow.api.query.Projection":`Projection`,"wow.api.query.Sort":`FieldSort`,"wow.api.query.Sort.Direction":`SortDirection`,"wow.api.query.DynamicDocument":`DynamicDocument`,"wow.api.query.DynamicDocumentArray":`DynamicDocumentArray`,"wow.command.CommandStage":`CommandStage`,"wow.command.SimpleWaitSignal":`WaitSignal`,"wow.configuration.Aggregate":`Aggregate`,"wow.configuration.BoundedContext":`BoundedContext`,"wow.configuration.WowMetadata":`WowMetadata`,"wow.modeling.DomainEvent":`DomainEvent`,"wow.openapi.BatchResult":`BatchResult`,"wow.messaging.CompensationTarget":`CompensationTarget`};function K(e){if(!e)return{name:``,path:`/`};let t=Ue[e];if(t)return{name:t,path:G};let n=e.split(`.`),r=-1;for(let e=0;e<n.length;e++)if(n[e]&&/^[A-Z]/.test(n[e])){r=e;break}let i=n.slice(0,r),a=i.length>0?`/${i.join(`/`)}`:`/`;return{name:_(n.slice(r)),path:a}}function q(e){return K(d(e))}function J(e){return`${y(e)}_BOUNDED_CONTEXT_ALIAS`}var We=class{constructor(e,t,n,r){this.modelInfo=e,this.sourceFile=t,this.keySchema=n,this.outputDir=r}generate(){let e=this.process();e&&Ae(e,this.keySchema.schema,this.keySchema.key)}process(){let{schema:e}=this.keySchema;return ce(e)?this.processEnum(e):w(e)?this.processInterface(e):T(e)?this.processArray(e):E(e)?this.processIntersection(e):D(e)?this.processComposition(e):this.processTypeAlias(e)}resolveReference(e){let t=q(e);return De(this.modelInfo,this.sourceFile,this.outputDir,t),t}resolveAdditionalProperties(e){return e.additionalProperties===void 0||e.additionalProperties===!1?``:e.additionalProperties===!0?`[key: string]: any`:`[key: string]: ${this.resolveType(e.additionalProperties)}`}resolvePropertyDefinitions(e){let{properties:t}=e;return Object.entries(t).map(([e,t])=>{let n=this.resolveType(t),r=b(e);if(!S(t)){let e=Oe(W(t),`
4
4
  * `);if(e)return`
@@ -17,4 +17,4 @@ let e=require(`ts-morph`),t=require(`@ahoo-wang/fetcher`),n=require(`yaml`),r=re
17
17
  aggregateName: '${t.aggregate.aggregateName}',
18
18
  resourceAttribution: ${nt(t)},
19
19
  }`}],isExported:!1}),this.processAggregateDomainEventTypes(t,n);let i=this.processAggregateDomainEventType(t,n),a=`${v(t.aggregate.aggregateName)}QueryClientFactory`,o=K(t.state.key),s=K(t.fields.key);this.context.logger.info(`Adding import for state model: ${o.name} from path: ${o.path}`),H(n,this.context.outputDir,o),this.context.logger.info(`Adding import for fields model: ${s.name} from path: ${s.path}`),H(n,this.context.outputDir,s),this.context.logger.info(`Creating query client factory: ${a}`),n.addVariableStatement({declarationKind:e.VariableDeclarationKind.Const,declarations:[{name:a,initializer:`new QueryClientFactory<${o.name}, ${s.name} | string, ${i}>(${r})`}],isExported:!0}),this.context.logger.success(`Query client generation completed for aggregate: ${t.aggregate.aggregateName}`)}processAggregateDomainEventType(e,t){let n=[];this.context.logger.info(`Processing ${e.events.size} domain events for aggregate: ${e.aggregate.aggregateName}`);for(let r of e.events.values()){let e=K(r.schema.key);this.context.logger.info(`Adding import for event model: ${e.name} from path: ${e.path}`),H(t,this.context.outputDir,e),n.push(e)}let r=Q(e.aggregate,this.domainEventTypeSuffix),i=n.map(e=>e.name).join(` | `);return this.context.logger.info(`Creating domain event types union: ${r} = ${i}`),t.addTypeAlias({isExported:!0,name:r,type:i}),r}processAggregateDomainEventTypes(e,t){let n=Q(e.aggregate,this.domainEventTypeMapTitleSuffix),r=t.addEnum({name:n,isExported:!0});for(let t of e.events.values())r.addMember({name:t.name,initializer:`'${t.title}'`})}},lt=class{queryClientGenerator;commandClientGenerator;apiClientGenerator;constructor(e){this.context=e,this.queryClientGenerator=new ct(e),this.commandClientGenerator=new st(e),this.apiClientGenerator=new ot(e)}generate(){this.context.logger.info(`--- Generating Clients ---`),this.context.logger.progress(`Generating clients for ${this.context.contextAggregates.size} bounded contexts`);let e=0;for(let[t]of this.context.contextAggregates)e++,this.context.logger.progressWithCount(e,this.context.contextAggregates.size,`Processing bounded context: ${t}`,1);this.queryClientGenerator.generate(),this.commandClientGenerator.generate(),this.apiClientGenerator.generate(),this.context.logger.success(`Client generation completed`)}},ut=class{project;openAPI;outputDir;contextAggregates;logger;config;defaultIgnorePathParameters=[`tenantId`,`ownerId`];currentContextAlias;constructor(e){this.project=e.project,this.openAPI=e.openAPI,this.outputDir=e.outputDir,this.contextAggregates=e.contextAggregates,this.logger=e.logger,this.config=e.config??{},this.currentContextAlias=this.openAPI.info[`x-wow-context-alias`]}getOrCreateSourceFile(e){return B(this.project,this.outputDir,e)}isIgnoreApiClientPathParameters(e,t){return(this.config.apiClients?.[e]?.ignorePathParameters??this.defaultIgnorePathParameters).includes(t)}isIgnoreCommandClientPathParameters(e,t){return this.defaultIgnorePathParameters.includes(t)}},dt=`./fetcher-generator.config.json`,ft=class{project;constructor(t){this.options=t,this.project=new e.Project(t),this.options.logger.info(`Project instance created with tsConfigFilePath: ${this.options.tsConfigFilePath}`)}async generate(){this.options.logger.info(`Starting code generation from OpenAPI specification`);let e=process.cwd();this.options.logger.info(`Work directory: ${e}`),this.options.logger.info(`Input path: ${this.options.inputPath}`),this.options.logger.info(`Output directory: ${this.options.outputDir}`),this.options.logger.info(`Parsing OpenAPI specification`);let t=await Ce(this.options.inputPath);this.options.logger.info(`OpenAPI specification parsed successfully`),this.options.logger.info(`Resolving bounded context aggregates`);let n=new He(t).resolve();this.options.logger.info(`Resolved ${n.size} bounded context aggregates`);let r=this.options.configPath??`./fetcher-generator.config.json`,i={};try{this.options.logger.info(`Parsing configuration file: ${r}`),i=await we(r)}catch(e){this.options.logger.info(`Configuration file parsing failed: ${e}`)}let a=new ut({openAPI:t,project:this.project,outputDir:this.options.outputDir,contextAggregates:n,logger:this.options.logger,config:i});this.options.logger.info(`Generating models`),new Ge(a).generate(),this.options.logger.info(`Models generated successfully`),this.options.logger.info(`Generating clients`),new lt(a).generate(),this.options.logger.info(`Clients generated successfully`);let o=this.project.getDirectory(this.options.outputDir);if(!o){this.options.logger.info(`Output directory not found.`);return}this.options.logger.info(`Generating index files`),this.generateIndex(o),this.options.logger.info(`Index files generated successfully`),this.options.logger.info(`Optimizing source files`),this.optimizeSourceFiles(o),this.options.logger.info(`Source files optimized successfully`),this.options.logger.info(`Saving project to disk`),await this.project.save(),this.options.logger.info(`Code generation completed successfully`)}generateIndex(e){this.options.logger.info(`Generating index files for output directory: ${this.options.outputDir}`),this.processDirectory(e),this.generateIndexForDirectory(e),this.options.logger.info(`Index file generation completed`)}processDirectory(e){let t=e.getDirectories();this.options.logger.info(`Processing ${t.length} subdirectories`);for(let e of t)this.options.logger.info(`Processing subdirectory: ${e.getPath()}`),this.generateIndexForDirectory(e),this.processDirectory(e)}generateIndexForDirectory(e){let t=e.getPath();this.options.logger.info(`Generating index for directory: ${t}`);let n=e.getSourceFiles().filter(e=>e.getBaseName().endsWith(`.ts`)&&e.getBaseName()!==`index.ts`),r=e.getDirectories();if(this.options.logger.info(`Found ${n.length} TypeScript files and ${r.length} subdirectories in ${t}`),n.length===0&&r.length===0){this.options.logger.info(`No files or subdirectories to export in ${t}, skipping index generation`);return}let i=`${t}/index.ts`,a=this.project.getSourceFile(i)||this.project.createSourceFile(i,``,{overwrite:!0});a.removeText();for(let e of n){let t=`./${e.getBaseNameWithoutExtension()}`;a.addExportDeclaration({moduleSpecifier:t,isTypeOnly:!1,namedExports:[]})}for(let e of r){let t=`./${e.getBaseName()}`;a.addExportDeclaration({moduleSpecifier:t,isTypeOnly:!1,namedExports:[]})}this.options.logger.info(`Index file generated for ${t} with ${n.length+r.length} exports`)}optimizeSourceFiles(e){let t=e.getDescendantSourceFiles();this.options.logger.info(`Optimizing ${t.length} source files in ${e.getPath()}`),t.forEach((e,n)=>{this.options.logger.info(`Optimizing file [${e.getFilePath()}] - ${n+1}/${t.length}`),e.formatText(),e.organizeImports(),e.fixMissingImports()}),this.options.logger.info(`All source files optimized`)}};Object.defineProperty(exports,`i`,{enumerable:!0,get:function(){return s}}),Object.defineProperty(exports,`n`,{enumerable:!0,get:function(){return dt}}),Object.defineProperty(exports,`r`,{enumerable:!0,get:function(){return l}}),Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return ft}});
20
- //# sourceMappingURL=src-swpb5H7t.cjs.map
20
+ //# sourceMappingURL=src-DY8hKMiY.cjs.map