@ahoo-wang/fetcher-generator 2.3.6 → 2.5.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/cli.cjs +1 -1
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +18 -17
- package/dist/cli.js.map +1 -1
- package/dist/client/apiClientGenerator.d.ts +97 -0
- package/dist/client/apiClientGenerator.d.ts.map +1 -0
- package/dist/client/clientGenerator.d.ts +4 -3
- package/dist/client/clientGenerator.d.ts.map +1 -1
- package/dist/client/commandClientGenerator.d.ts +3 -4
- package/dist/client/commandClientGenerator.d.ts.map +1 -1
- package/dist/client/decorators.d.ts +54 -0
- package/dist/client/decorators.d.ts.map +1 -0
- package/dist/client/index.d.ts +5 -0
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/queryClientGenerator.d.ts +3 -3
- package/dist/client/queryClientGenerator.d.ts.map +1 -1
- package/dist/client/utils.d.ts +1 -0
- package/dist/client/utils.d.ts.map +1 -1
- package/dist/{baseCodeGenerator.d.ts → generateContext.d.ts} +13 -10
- package/dist/generateContext.d.ts.map +1 -0
- package/dist/index.cjs +7 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +864 -398
- package/dist/index.js.map +1 -1
- package/dist/model/modelGenerator.d.ts +5 -3
- package/dist/model/modelGenerator.d.ts.map +1 -1
- package/dist/model/modelInfo.d.ts +2 -0
- package/dist/model/modelInfo.d.ts.map +1 -1
- package/dist/types.d.ts +17 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/clis.d.ts.map +1 -1
- package/dist/utils/index.d.ts +1 -1
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/naming.d.ts.map +1 -1
- package/dist/utils/{openAPIParser.d.ts → parsers.d.ts} +3 -1
- package/dist/utils/parsers.d.ts.map +1 -0
- package/dist/utils/responses.d.ts +5 -2
- package/dist/utils/responses.d.ts.map +1 -1
- package/package.json +1 -1
- package/dist/baseCodeGenerator.d.ts.map +0 -1
- package/dist/utils/openAPIParser.d.ts.map +0 -1
package/dist/cli.cjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("commander"),
|
|
2
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("commander"),l=require("./index.cjs"),d=require("ts-morph");require("yaml");require("fs");require("@ahoo-wang/fetcher");require("path");class f{getTimestamp(){return new Date().toISOString().slice(11,19)}info(e,...t){const o=this.getTimestamp();t.length>0?console.log(`[${o}] ℹ️ ${e}`,...t):console.log(`[${o}] ℹ️ ${e}`)}success(e,...t){const o=this.getTimestamp();t.length>0?console.log(`[${o}] ✅ ${e}`,...t):console.log(`[${o}] ✅ ${e}`)}error(e,...t){const o=this.getTimestamp();t.length>0?console.error(`[${o}] ❌ ${e}`,...t):console.error(`[${o}] ❌ ${e}`)}progress(e,t=0,...o){const n=this.getTimestamp(),i=" ".repeat(t);o.length>0?console.log(`[${n}] 🔄 ${i}${e}`,...o):console.log(`[${n}] 🔄 ${i}${e}`)}progressWithCount(e,t,o,n=0,...i){const s=this.getTimestamp(),p=" ".repeat(n),a=`[${e}/${t}]`;i.length>0?console.log(`[${s}] 🔄 ${p}${a} ${o}`,...i):console.log(`[${s}] 🔄 ${p}${a} ${o}`)}}function h(r){if(!r)return!1;try{const e=new URL(r);return e.protocol==="http:"||e.protocol==="https:"}catch{return r.length>0}}async function $(r){const e=new f;process.on("SIGINT",()=>{e.error("Generation interrupted by user"),process.exit(130)}),h(r.input)||(e.error("Invalid input: must be a valid file path or HTTP/HTTPS URL"),process.exit(2));try{e.info("Starting code generation...");const t=new d.Project,o={inputPath:r.input,outputDir:r.output,configPath:r.config,project:t,logger:e};await new l.CodeGenerator(o).generate(),e.success(`Code generation completed successfully! Files generated in: ${r.output}`)}catch(t){e.error(`Error during code generation: ${t}`),process.exit(1)}}const m="2.5.0",T={version:m};function u(){return c.program.name("fetcher-generator").description("OpenAPI Specification TypeScript code generator for Wow").version(T.version),c.program.command("generate").description("Generate TypeScript code from OpenAPI specification").requiredOption("-i, --input <path>","Input OpenAPI specification file path or URL (http/https)").option("-o, --output <path>","Output directory path","src/generated").option("-c, --config <file>","Configuration file path",l.DEFAULT_CONFIG_PATH).option("-v, --verbose","Enable verbose logging").option("--dry-run","Show what would be generated without writing files").action($),c.program}function g(){u().parse()}g();exports.runCLI=g;exports.setupCLI=u;
|
|
3
3
|
//# sourceMappingURL=cli.cjs.map
|
package/dist/cli.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.cjs","sources":["../src/utils/logger.ts","../src/utils/clis.ts","../src/cli.ts"],"sourcesContent":["/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { Logger } from '../types';\n\n/**\n * Default console-based logger implementation.\n * Provides friendly colored output for different log levels.\n */\nexport class ConsoleLogger implements Logger {\n private getTimestamp(): string {\n return new Date().toISOString().slice(11, 19); // HH:MM:SS format\n }\n\n info(message: string, ...params: any[]): void {\n const timestamp = this.getTimestamp();\n if (params.length > 0) {\n console.log(`[${timestamp}] ℹ️ ${message}`, ...params);\n } else {\n console.log(`[${timestamp}] ℹ️ ${message}`);\n }\n }\n\n success(message: string, ...params: any[]): void {\n const timestamp = this.getTimestamp();\n if (params.length > 0) {\n console.log(`[${timestamp}] ✅ ${message}`, ...params);\n } else {\n console.log(`[${timestamp}] ✅ ${message}`);\n }\n }\n\n error(message: string, ...params: any[]): void {\n const timestamp = this.getTimestamp();\n if (params.length > 0) {\n console.error(`[${timestamp}] ❌ ${message}`, ...params);\n } else {\n console.error(`[${timestamp}] ❌ ${message}`);\n }\n }\n\n progress(message: string, level = 0, ...params: any[]): void {\n const timestamp = this.getTimestamp();\n const indent = ' '.repeat(level);\n if (params.length > 0) {\n console.log(`[${timestamp}] 🔄 ${indent}${message}`, ...params);\n } else {\n console.log(`[${timestamp}] 🔄 ${indent}${message}`);\n }\n }\n\n progressWithCount(\n current: number,\n total: number,\n message: string,\n level = 0,\n ...params: any[]\n ): void {\n const timestamp = this.getTimestamp();\n const indent = ' '.repeat(level);\n const countStr = `[${current}/${total}]`;\n if (params.length > 0) {\n console.log(\n `[${timestamp}] 🔄 ${indent}${countStr} ${message}`,\n ...params,\n );\n } else {\n console.log(`[${timestamp}] 🔄 ${indent}${countStr} ${message}`);\n }\n }\n}\n\n/**\n * Silent logger that suppresses all output.\n */\nexport class SilentLogger implements Logger {\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n info(_message: string, ...params: any[]): void {\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n success(_message: string, ...params: any[]): void {\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n error(_message: string, ...params: any[]): void {\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n progress(_message: string, ...params: any[]): void {\n }\n\n /* eslint-disable @typescript-eslint/no-unused-vars */\n progressWithCount(\n _current: number,\n _total: number,\n _message: string,\n _level = 0,\n ..._params: any[]\n ): void {\n }\n\n /* eslint-enable @typescript-eslint/no-unused-vars */\n}\n","/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { ConsoleLogger } from './logger';\nimport { GeneratorOptions } from '../types';\nimport { CodeGenerator } from '../index';\nimport { Project } from 'ts-morph';\n\n/**\n * Validates the input path or URL.\n * @param input - Input path or URL\n * @returns true if valid\n */\nexport function validateInput(input: string): boolean {\n if (!input) return false;\n\n // Check if it's a URL\n try {\n const url = new URL(input);\n return url.protocol === 'http:' || url.protocol === 'https:';\n } catch {\n // Not a URL, check if it's a file path\n // For file paths, we'll let parseOpenAPI handle it\n return input.length > 0;\n }\n}\n\n/**\n * Action handler for the generate command.\n * @param options - Command options\n */\nexport async function generateAction(options: {\n input: string;\n output: string;\n config?: string;\n verbose?: boolean;\n dryRun?: boolean;\n}) {\n const logger = new ConsoleLogger();\n\n // Handle signals\n process.on('SIGINT', () => {\n logger.error('Generation interrupted by user');\n process.exit(130);\n });\n\n // Validate input\n if (!validateInput(options.input)) {\n logger.error('Invalid input: must be a valid file path or HTTP/HTTPS URL');\n process.exit(2);\n }\n\n try {\n logger.info('Starting code generation...');\n const project = new Project();\n const generatorOptions: GeneratorOptions = {\n inputPath: options.input,\n outputDir: options.output,\n project,\n logger,\n };\n const codeGenerator = new CodeGenerator(generatorOptions);\n await codeGenerator.generate();\n logger.success(\n `Code generation completed successfully! Files generated in: ${options.output}`,\n );\n } catch (error) {\n logger.error(`Error during code generation: ${error}`);\n process.exit(1);\n }\n}\n","#!/usr/bin/env node\n\n/**\n * CLI entry point for the Fetcher OpenAPI code generator.\n * Sets up the commander program with generate command and handles execution.\n */\n\nimport { program } from 'commander';\nimport { generateAction } from './utils';\nimport packageJson from '../package.json';\n\n/**\n * Sets up the CLI program with all commands and options.\n * @returns The configured commander program instance\n */\nexport function setupCLI() {\n program\n .name('fetcher-generator')\n .description('OpenAPI Specification TypeScript code generator for Wow')\n .version(packageJson.version);\n\n program\n .command('generate')\n .description('Generate TypeScript code from OpenAPI specification')\n .requiredOption(\n '-i, --input <path>',\n 'Input OpenAPI specification file path or URL (http/https)',\n )\n .option('-o, --output <path>', 'Output directory path', 'src/generated')\n .option('-c, --config <file>', 'Configuration file path')\n .option('-v, --verbose', 'Enable verbose logging')\n .option('--dry-run', 'Show what would be generated without writing files')\n .action(generateAction);\n\n return program;\n}\n\n/**\n * Runs the CLI program by parsing command line arguments.\n * Only executes when this file is run directly (not imported).\n */\nexport function runCLI() {\n setupCLI().parse();\n}\n\nrunCLI();\n"],"names":["ConsoleLogger","message","params","timestamp","level","indent","current","total","countStr","validateInput","input","url","generateAction","options","logger","project","Project","generatorOptions","CodeGenerator","error","setupCLI","program","packageJson","runCLI"],"mappings":";wOAmBO,MAAMA,CAAgC,CACnC,cAAuB,CAC7B,WAAW,OAAO,cAAc,MAAM,GAAI,EAAE,CAC9C,CAEA,KAAKC,KAAoBC,EAAqB,CAC5C,MAAMC,EAAY,KAAK,aAAA,EACnBD,EAAO,OAAS,EAClB,QAAQ,IAAI,IAAIC,CAAS,SAASF,CAAO,GAAI,GAAGC,CAAM,EAEtD,QAAQ,IAAI,IAAIC,CAAS,SAASF,CAAO,EAAE,CAE/C,CAEA,QAAQA,KAAoBC,EAAqB,CAC/C,MAAMC,EAAY,KAAK,aAAA,EACnBD,EAAO,OAAS,EAClB,QAAQ,IAAI,IAAIC,CAAS,OAAOF,CAAO,GAAI,GAAGC,CAAM,EAEpD,QAAQ,IAAI,IAAIC,CAAS,OAAOF,CAAO,EAAE,CAE7C,CAEA,MAAMA,KAAoBC,EAAqB,CAC7C,MAAMC,EAAY,KAAK,aAAA,EACnBD,EAAO,OAAS,EAClB,QAAQ,MAAM,IAAIC,CAAS,OAAOF,CAAO,GAAI,GAAGC,CAAM,EAEtD,QAAQ,MAAM,IAAIC,CAAS,OAAOF,CAAO,EAAE,CAE/C,CAEA,SAASA,EAA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A,cAAcD,CAAgB,EACpC,SAAA,EACpBH,EAAO,QACL,+DAA+DD,EAAQ,MAAM,EAAA,CAEjF,OAASM,EAAO,CACdL,EAAO,MAAM,iCAAiCK,CAAK,EAAE,EACrD,QAAQ,KAAK,CAAC,CAChB,CACF,+BCjEO,SAASC,GAAW,CACzBC,OAAAA,UACG,KAAK,mBAAmB,EACxB,YAAY,yDAAyD,EACrE,QAAQC,EAAY,OAAO,EAE9BD,EAAAA,QACG,QAAQ,UAAU,EAClB,YAAY,qDAAqD,EACjE,eACC,qBACA,2DAAA,EAED,OAAO,sBAAuB,wBAAyB,eAAe,EACtE,OAAO,sBAAuB,yBAAyB,EACvD,OAAO,gBAAiB,wBAAwB,EAChD,OAAO,YAAa,oDAAoD,EACxE,OAAOT,CAAc,EAEjBS,EAAAA,OACT,CAMO,SAASE,GAAS,CACvBH,EAAA,EAAW,MAAA,CACb,CAEAG,EAAA"}
|
|
1
|
+
{"version":3,"file":"cli.cjs","sources":["../src/utils/logger.ts","../src/utils/clis.ts","../src/cli.ts"],"sourcesContent":["/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { Logger } from '../types';\n\n/**\n * Default console-based logger implementation.\n * Provides friendly colored output for different log levels.\n */\nexport class ConsoleLogger implements Logger {\n private getTimestamp(): string {\n return new Date().toISOString().slice(11, 19); // HH:MM:SS format\n }\n\n info(message: string, ...params: any[]): void {\n const timestamp = this.getTimestamp();\n if (params.length > 0) {\n console.log(`[${timestamp}] ℹ️ ${message}`, ...params);\n } else {\n console.log(`[${timestamp}] ℹ️ ${message}`);\n }\n }\n\n success(message: string, ...params: any[]): void {\n const timestamp = this.getTimestamp();\n if (params.length > 0) {\n console.log(`[${timestamp}] ✅ ${message}`, ...params);\n } else {\n console.log(`[${timestamp}] ✅ ${message}`);\n }\n }\n\n error(message: string, ...params: any[]): void {\n const timestamp = this.getTimestamp();\n if (params.length > 0) {\n console.error(`[${timestamp}] ❌ ${message}`, ...params);\n } else {\n console.error(`[${timestamp}] ❌ ${message}`);\n }\n }\n\n progress(message: string, level = 0, ...params: any[]): void {\n const timestamp = this.getTimestamp();\n const indent = ' '.repeat(level);\n if (params.length > 0) {\n console.log(`[${timestamp}] 🔄 ${indent}${message}`, ...params);\n } else {\n console.log(`[${timestamp}] 🔄 ${indent}${message}`);\n }\n }\n\n progressWithCount(\n current: number,\n total: number,\n message: string,\n level = 0,\n ...params: any[]\n ): void {\n const timestamp = this.getTimestamp();\n const indent = ' '.repeat(level);\n const countStr = `[${current}/${total}]`;\n if (params.length > 0) {\n console.log(\n `[${timestamp}] 🔄 ${indent}${countStr} ${message}`,\n ...params,\n );\n } else {\n console.log(`[${timestamp}] 🔄 ${indent}${countStr} ${message}`);\n }\n }\n}\n\n/**\n * Silent logger that suppresses all output.\n */\nexport class SilentLogger implements Logger {\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n info(_message: string, ...params: any[]): void {\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n success(_message: string, ...params: any[]): void {\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n error(_message: string, ...params: any[]): void {\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n progress(_message: string, ...params: any[]): void {\n }\n\n /* eslint-disable @typescript-eslint/no-unused-vars */\n progressWithCount(\n _current: number,\n _total: number,\n _message: string,\n _level = 0,\n ..._params: any[]\n ): void {\n }\n\n /* eslint-enable @typescript-eslint/no-unused-vars */\n}\n","/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { ConsoleLogger } from './logger';\nimport { GeneratorOptions } from '../types';\nimport { CodeGenerator } from '../index';\nimport { Project } from 'ts-morph';\n\n/**\n * Validates the input path or URL.\n * @param input - Input path or URL\n * @returns true if valid\n */\nexport function validateInput(input: string): boolean {\n if (!input) return false;\n\n // Check if it's a URL\n try {\n const url = new URL(input);\n return url.protocol === 'http:' || url.protocol === 'https:';\n } catch {\n // Not a URL, check if it's a file path\n // For file paths, we'll let parseOpenAPI handle it\n return input.length > 0;\n }\n}\n\n/**\n * Action handler for the generate command.\n * @param options - Command options\n */\nexport async function generateAction(options: {\n input: string;\n output: string;\n config?: string,\n verbose?: boolean;\n dryRun?: boolean;\n}) {\n const logger = new ConsoleLogger();\n\n // Handle signals\n process.on('SIGINT', () => {\n logger.error('Generation interrupted by user');\n process.exit(130);\n });\n\n // Validate input\n if (!validateInput(options.input)) {\n logger.error('Invalid input: must be a valid file path or HTTP/HTTPS URL');\n process.exit(2);\n }\n\n try {\n logger.info('Starting code generation...');\n const project = new Project();\n const generatorOptions: GeneratorOptions = {\n inputPath: options.input,\n outputDir: options.output,\n configPath: options.config,\n project,\n logger,\n };\n const codeGenerator = new CodeGenerator(generatorOptions);\n await codeGenerator.generate();\n logger.success(\n `Code generation completed successfully! Files generated in: ${options.output}`,\n );\n } catch (error) {\n logger.error(`Error during code generation: ${error}`);\n process.exit(1);\n }\n}\n","#!/usr/bin/env node\n\n/**\n * CLI entry point for the Fetcher OpenAPI code generator.\n * Sets up the commander program with generate command and handles execution.\n */\n\nimport { program } from 'commander';\nimport { generateAction } from './utils';\nimport packageJson from '../package.json';\nimport { DEFAULT_CONFIG_PATH } from './index';\n\n/**\n * Sets up the CLI program with all commands and options.\n * @returns The configured commander program instance\n */\nexport function setupCLI() {\n program\n .name('fetcher-generator')\n .description('OpenAPI Specification TypeScript code generator for Wow')\n .version(packageJson.version);\n\n program\n .command('generate')\n .description('Generate TypeScript code from OpenAPI specification')\n .requiredOption(\n '-i, --input <path>',\n 'Input OpenAPI specification file path or URL (http/https)',\n )\n .option('-o, --output <path>', 'Output directory path', 'src/generated')\n .option('-c, --config <file>', 'Configuration file path', DEFAULT_CONFIG_PATH)\n .option('-v, --verbose', 'Enable verbose logging')\n .option('--dry-run', 'Show what would be generated without writing files')\n .action(generateAction);\n\n return program;\n}\n\n/**\n * Runs the CLI program by parsing command line arguments.\n * Only executes when this file is run directly (not imported).\n */\nexport function runCLI() {\n setupCLI().parse();\n}\n\nrunCLI();\n"],"names":["ConsoleLogger","message","params","timestamp","level","indent","current","total","countStr","validateInput","input","url","generateAction","options","logger","project","Project","generatorOptions","CodeGenerator","error","setupCLI","program","packageJson","DEFAULT_CONFIG_PATH","runCLI"],"mappings":";wOAmBO,MAAMA,CAAgC,CACnC,cAAuB,CAC7B,WAAW,OAAO,cAAc,MAAM,GAAI,EAAE,CAC9C,CAEA,KAAKC,KAAoBC,EAAqB,CAC5C,MAAMC,EAAY,KAAK,aAAA,EACnBD,EAAO,OAAS,EAClB,QAAQ,IAAI,IAAIC,CAAS,SAASF,CAAO,GAAI,GAAGC,CAAM,EAEtD,QAAQ,IAAI,IAAIC,CAAS,SAASF,CAAO,EAAE,CAE/C,CAEA,QAAQA,KAAoBC,EAAqB,CAC/C,MAAMC,EAAY,KAAK,aAAA,EACnBD,EAAO,OAAS,EAClB,QAAQ,IAAI,IAAIC,CAAS,OAAOF,CAAO,GAAI,GAAGC,CAAM,EAEpD,QAAQ,IAAI,IAAIC,CAAS,OAAOF,CAAO,EAAE,CAE7C,CAEA,MAAMA,KAAoBC,EAAqB,CAC7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KAAK,CAAC,GAGhB,GAAI,CACFA,EAAO,KAAK,6BAA6B,EACzC,MAAMC,EAAU,IAAIC,UACdC,EAAqC,CACzC,UAAWJ,EAAQ,MACnB,UAAWA,EAAQ,OACnB,WAAYA,EAAQ,OACpB,QAAAE,EACA,OAAAD,CAAA,EAGF,MADsB,IAAII,EAAAA,cAAcD,CAAgB,EACpC,SAAA,EACpBH,EAAO,QACL,+DAA+DD,EAAQ,MAAM,EAAA,CAEjF,OAASM,EAAO,CACdL,EAAO,MAAM,iCAAiCK,CAAK,EAAE,EACrD,QAAQ,KAAK,CAAC,CAChB,CACF,+BCjEO,SAASC,GAAW,CACzBC,OAAAA,UACG,KAAK,mBAAmB,EACxB,YAAY,yDAAyD,EACrE,QAAQC,EAAY,OAAO,EAE9BD,EAAAA,QACG,QAAQ,UAAU,EAClB,YAAY,qDAAqD,EACjE,eACC,qBACA,2DAAA,EAED,OAAO,sBAAuB,wBAAyB,eAAe,EACtE,OAAO,sBAAuB,0BAA2BE,EAAAA,mBAAmB,EAC5E,OAAO,gBAAiB,wBAAwB,EAChD,OAAO,YAAa,oDAAoD,EACxE,OAAOX,CAAc,EAEjBS,EAAAA,OACT,CAMO,SAASG,GAAS,CACvBJ,EAAA,EAAW,MAAA,CACb,CAEAI,EAAA"}
|
package/dist/cli.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AAEA;;;GAGG;
|
|
1
|
+
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AAEA;;;GAGG;AAOH;;;GAGG;AACH,wBAAgB,QAAQ,gCAoBvB;AAED;;;GAGG;AACH,wBAAgB,MAAM,SAErB"}
|
package/dist/cli.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { program as c } from "commander";
|
|
3
|
-
import { CodeGenerator as a } from "./index.js";
|
|
4
|
-
import { Project as
|
|
3
|
+
import { CodeGenerator as a, DEFAULT_CONFIG_PATH as g } from "./index.js";
|
|
4
|
+
import { Project as u } from "ts-morph";
|
|
5
5
|
import "yaml";
|
|
6
6
|
import "fs";
|
|
7
7
|
import "@ahoo-wang/fetcher";
|
|
8
8
|
import "path";
|
|
9
|
-
class
|
|
9
|
+
class f {
|
|
10
10
|
getTimestamp() {
|
|
11
11
|
return (/* @__PURE__ */ new Date()).toISOString().slice(11, 19);
|
|
12
12
|
}
|
|
@@ -34,7 +34,7 @@ class u {
|
|
|
34
34
|
) : console.log(`[${s}] 🔄 ${p}${l} ${o}`);
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
|
-
function
|
|
37
|
+
function h(n) {
|
|
38
38
|
if (!n) return !1;
|
|
39
39
|
try {
|
|
40
40
|
const e = new URL(n);
|
|
@@ -44,15 +44,16 @@ function f(n) {
|
|
|
44
44
|
}
|
|
45
45
|
}
|
|
46
46
|
async function $(n) {
|
|
47
|
-
const e = new
|
|
47
|
+
const e = new f();
|
|
48
48
|
process.on("SIGINT", () => {
|
|
49
49
|
e.error("Generation interrupted by user"), process.exit(130);
|
|
50
|
-
}),
|
|
50
|
+
}), h(n.input) || (e.error("Invalid input: must be a valid file path or HTTP/HTTPS URL"), process.exit(2));
|
|
51
51
|
try {
|
|
52
52
|
e.info("Starting code generation...");
|
|
53
|
-
const t = new
|
|
53
|
+
const t = new u(), o = {
|
|
54
54
|
inputPath: n.input,
|
|
55
55
|
outputDir: n.output,
|
|
56
|
+
configPath: n.config,
|
|
56
57
|
project: t,
|
|
57
58
|
logger: e
|
|
58
59
|
};
|
|
@@ -63,21 +64,21 @@ async function $(n) {
|
|
|
63
64
|
e.error(`Error during code generation: ${t}`), process.exit(1);
|
|
64
65
|
}
|
|
65
66
|
}
|
|
66
|
-
const
|
|
67
|
-
version:
|
|
67
|
+
const m = "2.5.0", d = {
|
|
68
|
+
version: m
|
|
68
69
|
};
|
|
69
|
-
function
|
|
70
|
-
return c.name("fetcher-generator").description("OpenAPI Specification TypeScript code generator for Wow").version(
|
|
70
|
+
function T() {
|
|
71
|
+
return c.name("fetcher-generator").description("OpenAPI Specification TypeScript code generator for Wow").version(d.version), c.command("generate").description("Generate TypeScript code from OpenAPI specification").requiredOption(
|
|
71
72
|
"-i, --input <path>",
|
|
72
73
|
"Input OpenAPI specification file path or URL (http/https)"
|
|
73
|
-
).option("-o, --output <path>", "Output directory path", "src/generated").option("-c, --config <file>", "Configuration file path").option("-v, --verbose", "Enable verbose logging").option("--dry-run", "Show what would be generated without writing files").action($), c;
|
|
74
|
+
).option("-o, --output <path>", "Output directory path", "src/generated").option("-c, --config <file>", "Configuration file path", g).option("-v, --verbose", "Enable verbose logging").option("--dry-run", "Show what would be generated without writing files").action($), c;
|
|
74
75
|
}
|
|
75
|
-
function
|
|
76
|
-
|
|
76
|
+
function w() {
|
|
77
|
+
T().parse();
|
|
77
78
|
}
|
|
78
|
-
|
|
79
|
+
w();
|
|
79
80
|
export {
|
|
80
|
-
|
|
81
|
-
|
|
81
|
+
w as runCLI,
|
|
82
|
+
T as setupCLI
|
|
82
83
|
};
|
|
83
84
|
//# sourceMappingURL=cli.js.map
|
package/dist/cli.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.js","sources":["../src/utils/logger.ts","../src/utils/clis.ts","../src/cli.ts"],"sourcesContent":["/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { Logger } from '../types';\n\n/**\n * Default console-based logger implementation.\n * Provides friendly colored output for different log levels.\n */\nexport class ConsoleLogger implements Logger {\n private getTimestamp(): string {\n return new Date().toISOString().slice(11, 19); // HH:MM:SS format\n }\n\n info(message: string, ...params: any[]): void {\n const timestamp = this.getTimestamp();\n if (params.length > 0) {\n console.log(`[${timestamp}] ℹ️ ${message}`, ...params);\n } else {\n console.log(`[${timestamp}] ℹ️ ${message}`);\n }\n }\n\n success(message: string, ...params: any[]): void {\n const timestamp = this.getTimestamp();\n if (params.length > 0) {\n console.log(`[${timestamp}] ✅ ${message}`, ...params);\n } else {\n console.log(`[${timestamp}] ✅ ${message}`);\n }\n }\n\n error(message: string, ...params: any[]): void {\n const timestamp = this.getTimestamp();\n if (params.length > 0) {\n console.error(`[${timestamp}] ❌ ${message}`, ...params);\n } else {\n console.error(`[${timestamp}] ❌ ${message}`);\n }\n }\n\n progress(message: string, level = 0, ...params: any[]): void {\n const timestamp = this.getTimestamp();\n const indent = ' '.repeat(level);\n if (params.length > 0) {\n console.log(`[${timestamp}] 🔄 ${indent}${message}`, ...params);\n } else {\n console.log(`[${timestamp}] 🔄 ${indent}${message}`);\n }\n }\n\n progressWithCount(\n current: number,\n total: number,\n message: string,\n level = 0,\n ...params: any[]\n ): void {\n const timestamp = this.getTimestamp();\n const indent = ' '.repeat(level);\n const countStr = `[${current}/${total}]`;\n if (params.length > 0) {\n console.log(\n `[${timestamp}] 🔄 ${indent}${countStr} ${message}`,\n ...params,\n );\n } else {\n console.log(`[${timestamp}] 🔄 ${indent}${countStr} ${message}`);\n }\n }\n}\n\n/**\n * Silent logger that suppresses all output.\n */\nexport class SilentLogger implements Logger {\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n info(_message: string, ...params: any[]): void {\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n success(_message: string, ...params: any[]): void {\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n error(_message: string, ...params: any[]): void {\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n progress(_message: string, ...params: any[]): void {\n }\n\n /* eslint-disable @typescript-eslint/no-unused-vars */\n progressWithCount(\n _current: number,\n _total: number,\n _message: string,\n _level = 0,\n ..._params: any[]\n ): void {\n }\n\n /* eslint-enable @typescript-eslint/no-unused-vars */\n}\n","/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { ConsoleLogger } from './logger';\nimport { GeneratorOptions } from '../types';\nimport { CodeGenerator } from '../index';\nimport { Project } from 'ts-morph';\n\n/**\n * Validates the input path or URL.\n * @param input - Input path or URL\n * @returns true if valid\n */\nexport function validateInput(input: string): boolean {\n if (!input) return false;\n\n // Check if it's a URL\n try {\n const url = new URL(input);\n return url.protocol === 'http:' || url.protocol === 'https:';\n } catch {\n // Not a URL, check if it's a file path\n // For file paths, we'll let parseOpenAPI handle it\n return input.length > 0;\n }\n}\n\n/**\n * Action handler for the generate command.\n * @param options - Command options\n */\nexport async function generateAction(options: {\n input: string;\n output: string;\n config?: string;\n verbose?: boolean;\n dryRun?: boolean;\n}) {\n const logger = new ConsoleLogger();\n\n // Handle signals\n process.on('SIGINT', () => {\n logger.error('Generation interrupted by user');\n process.exit(130);\n });\n\n // Validate input\n if (!validateInput(options.input)) {\n logger.error('Invalid input: must be a valid file path or HTTP/HTTPS URL');\n process.exit(2);\n }\n\n try {\n logger.info('Starting code generation...');\n const project = new Project();\n const generatorOptions: GeneratorOptions = {\n inputPath: options.input,\n outputDir: options.output,\n project,\n logger,\n };\n const codeGenerator = new CodeGenerator(generatorOptions);\n await codeGenerator.generate();\n logger.success(\n `Code generation completed successfully! Files generated in: ${options.output}`,\n );\n } catch (error) {\n logger.error(`Error during code generation: ${error}`);\n process.exit(1);\n }\n}\n","#!/usr/bin/env node\n\n/**\n * CLI entry point for the Fetcher OpenAPI code generator.\n * Sets up the commander program with generate command and handles execution.\n */\n\nimport { program } from 'commander';\nimport { generateAction } from './utils';\nimport packageJson from '../package.json';\n\n/**\n * Sets up the CLI program with all commands and options.\n * @returns The configured commander program instance\n */\nexport function setupCLI() {\n program\n .name('fetcher-generator')\n .description('OpenAPI Specification TypeScript code generator for Wow')\n .version(packageJson.version);\n\n program\n .command('generate')\n .description('Generate TypeScript code from OpenAPI specification')\n .requiredOption(\n '-i, --input <path>',\n 'Input OpenAPI specification file path or URL (http/https)',\n )\n .option('-o, --output <path>', 'Output directory path', 'src/generated')\n .option('-c, --config <file>', 'Configuration file path')\n .option('-v, --verbose', 'Enable verbose logging')\n .option('--dry-run', 'Show what would be generated without writing files')\n .action(generateAction);\n\n return program;\n}\n\n/**\n * Runs the CLI program by parsing command line arguments.\n * Only executes when this file is run directly (not imported).\n */\nexport function runCLI() {\n setupCLI().parse();\n}\n\nrunCLI();\n"],"names":["ConsoleLogger","message","params","timestamp","level","indent","current","total","countStr","validateInput","input","url","generateAction","options","logger","project","Project","generatorOptions","CodeGenerator","error","setupCLI","program","packageJson","runCLI"],"mappings":";;;;;;;;AAmBO,MAAMA,EAAgC;AAAA,EACnC,eAAuB;AAC7B,gCAAW,QAAO,cAAc,MAAM,IAAI,EAAE;AAAA,EAC9C;AAAA,EAEA,KAAKC,MAAoBC,GAAqB;AAC5C,UAAMC,IAAY,KAAK,aAAA;AACvB,IAAID,EAAO,SAAS,IAClB,QAAQ,IAAI,IAAIC,CAAS,SAASF,CAAO,IAAI,GAAGC,CAAM,IAEtD,QAAQ,IAAI,IAAIC,CAAS,SAASF,CAAO,EAAE;AAAA,EAE/C;AAAA,EAEA,QAAQA,MAAoBC,GAAqB;AAC/C,UAAMC,IAAY,KAAK,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EACtD,QAAQ;AAGN,WAAOD,EAAM,SAAS;AAAA,EACxB;AACF;AAMA,eAAsBE,EAAeC,GAMlC;AACD,QAAMC,IAAS,IAAId,EAAA;AAGnB,UAAQ,GAAG,UAAU,MAAM;AACzB,IAAAc,EAAO,MAAM,gCAAgC,GAC7C,QAAQ,KAAK,GAAG;AAAA,EAClB,CAAC,GAGIL,EAAcI,EAAQ,KAAK,MAC9BC,EAAO,MAAM,4DAA4D,GACzE,QAAQ,KAAK,CAAC;AAGhB,MAAI;AACF,IAAAA,EAAO,KAAK,6BAA6B;AACzC,UAAMC,IAAU,IAAIC,EAAA,GACdC,IAAqC;AAAA,MACzC,WAAWJ,EAAQ;AAAA,MACnB,WAAWA,EAAQ;AAAA,MACnB,SAAAE;AAAA,MACA,QAAAD;AAAA,IAAA;AAGF,UADsB,IAAII,EAAcD,CAAgB,EACpC,SAAA,GACpBH,EAAO;AAAA,MACL,+DAA+DD,EAAQ,MAAM;AAAA,IAAA;AAAA,EAEjF,SAASM,GAAO;AACd,IAAAL,EAAO,MAAM,iCAAiCK,CAAK,EAAE,GACrD,QAAQ,KAAK,CAAC;AAAA,EAChB;AACF;;;;ACjEO,SAASC,IAAW;AACzB,SAAAC,EACG,KAAK,mBAAmB,EACxB,YAAY,yDAAyD,EACrE,QAAQC,EAAY,OAAO,GAE9BD,EACG,QAAQ,UAAU,EAClB,YAAY,qDAAqD,EACjE;AAAA,IACC;AAAA,IACA;AAAA,EAAA,EAED,OAAO,uBAAuB,yBAAyB,eAAe,EACtE,OAAO,uBAAuB,yBAAyB,EACvD,OAAO,iBAAiB,wBAAwB,EAChD,OAAO,aAAa,oDAAoD,EACxE,OAAOT,CAAc,GAEjBS;AACT;AAMO,SAASE,IAAS;AACvB,EAAAH,EAAA,EAAW,MAAA;AACb;AAEAG,EAAA;"}
|
|
1
|
+
{"version":3,"file":"cli.js","sources":["../src/utils/logger.ts","../src/utils/clis.ts","../src/cli.ts"],"sourcesContent":["/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { Logger } from '../types';\n\n/**\n * Default console-based logger implementation.\n * Provides friendly colored output for different log levels.\n */\nexport class ConsoleLogger implements Logger {\n private getTimestamp(): string {\n return new Date().toISOString().slice(11, 19); // HH:MM:SS format\n }\n\n info(message: string, ...params: any[]): void {\n const timestamp = this.getTimestamp();\n if (params.length > 0) {\n console.log(`[${timestamp}] ℹ️ ${message}`, ...params);\n } else {\n console.log(`[${timestamp}] ℹ️ ${message}`);\n }\n }\n\n success(message: string, ...params: any[]): void {\n const timestamp = this.getTimestamp();\n if (params.length > 0) {\n console.log(`[${timestamp}] ✅ ${message}`, ...params);\n } else {\n console.log(`[${timestamp}] ✅ ${message}`);\n }\n }\n\n error(message: string, ...params: any[]): void {\n const timestamp = this.getTimestamp();\n if (params.length > 0) {\n console.error(`[${timestamp}] ❌ ${message}`, ...params);\n } else {\n console.error(`[${timestamp}] ❌ ${message}`);\n }\n }\n\n progress(message: string, level = 0, ...params: any[]): void {\n const timestamp = this.getTimestamp();\n const indent = ' '.repeat(level);\n if (params.length > 0) {\n console.log(`[${timestamp}] 🔄 ${indent}${message}`, ...params);\n } else {\n console.log(`[${timestamp}] 🔄 ${indent}${message}`);\n }\n }\n\n progressWithCount(\n current: number,\n total: number,\n message: string,\n level = 0,\n ...params: any[]\n ): void {\n const timestamp = this.getTimestamp();\n const indent = ' '.repeat(level);\n const countStr = `[${current}/${total}]`;\n if (params.length > 0) {\n console.log(\n `[${timestamp}] 🔄 ${indent}${countStr} ${message}`,\n ...params,\n );\n } else {\n console.log(`[${timestamp}] 🔄 ${indent}${countStr} ${message}`);\n }\n }\n}\n\n/**\n * Silent logger that suppresses all output.\n */\nexport class SilentLogger implements Logger {\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n info(_message: string, ...params: any[]): void {\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n success(_message: string, ...params: any[]): void {\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n error(_message: string, ...params: any[]): void {\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n progress(_message: string, ...params: any[]): void {\n }\n\n /* eslint-disable @typescript-eslint/no-unused-vars */\n progressWithCount(\n _current: number,\n _total: number,\n _message: string,\n _level = 0,\n ..._params: any[]\n ): void {\n }\n\n /* eslint-enable @typescript-eslint/no-unused-vars */\n}\n","/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { ConsoleLogger } from './logger';\nimport { GeneratorOptions } from '../types';\nimport { CodeGenerator } from '../index';\nimport { Project } from 'ts-morph';\n\n/**\n * Validates the input path or URL.\n * @param input - Input path or URL\n * @returns true if valid\n */\nexport function validateInput(input: string): boolean {\n if (!input) return false;\n\n // Check if it's a URL\n try {\n const url = new URL(input);\n return url.protocol === 'http:' || url.protocol === 'https:';\n } catch {\n // Not a URL, check if it's a file path\n // For file paths, we'll let parseOpenAPI handle it\n return input.length > 0;\n }\n}\n\n/**\n * Action handler for the generate command.\n * @param options - Command options\n */\nexport async function generateAction(options: {\n input: string;\n output: string;\n config?: string,\n verbose?: boolean;\n dryRun?: boolean;\n}) {\n const logger = new ConsoleLogger();\n\n // Handle signals\n process.on('SIGINT', () => {\n logger.error('Generation interrupted by user');\n process.exit(130);\n });\n\n // Validate input\n if (!validateInput(options.input)) {\n logger.error('Invalid input: must be a valid file path or HTTP/HTTPS URL');\n process.exit(2);\n }\n\n try {\n logger.info('Starting code generation...');\n const project = new Project();\n const generatorOptions: GeneratorOptions = {\n inputPath: options.input,\n outputDir: options.output,\n configPath: options.config,\n project,\n logger,\n };\n const codeGenerator = new CodeGenerator(generatorOptions);\n await codeGenerator.generate();\n logger.success(\n `Code generation completed successfully! Files generated in: ${options.output}`,\n );\n } catch (error) {\n logger.error(`Error during code generation: ${error}`);\n process.exit(1);\n }\n}\n","#!/usr/bin/env node\n\n/**\n * CLI entry point for the Fetcher OpenAPI code generator.\n * Sets up the commander program with generate command and handles execution.\n */\n\nimport { program } from 'commander';\nimport { generateAction } from './utils';\nimport packageJson from '../package.json';\nimport { DEFAULT_CONFIG_PATH } from './index';\n\n/**\n * Sets up the CLI program with all commands and options.\n * @returns The configured commander program instance\n */\nexport function setupCLI() {\n program\n .name('fetcher-generator')\n .description('OpenAPI Specification TypeScript code generator for Wow')\n .version(packageJson.version);\n\n program\n .command('generate')\n .description('Generate TypeScript code from OpenAPI specification')\n .requiredOption(\n '-i, --input <path>',\n 'Input OpenAPI specification file path or URL (http/https)',\n )\n .option('-o, --output <path>', 'Output directory path', 'src/generated')\n .option('-c, --config <file>', 'Configuration file path', DEFAULT_CONFIG_PATH)\n .option('-v, --verbose', 'Enable verbose logging')\n .option('--dry-run', 'Show what would be generated without writing files')\n .action(generateAction);\n\n return program;\n}\n\n/**\n * Runs the CLI program by parsing command line arguments.\n * Only executes when this file is run directly (not imported).\n */\nexport function runCLI() {\n setupCLI().parse();\n}\n\nrunCLI();\n"],"names":["ConsoleLogger","message","params","timestamp","level","indent","current","total","countStr","validateInput","input","url","generateAction","options","logger","project","Project","generatorOptions","CodeGenerator","error","setupCLI","program","packageJson","DEFAULT_C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D,EACrE,QAAQC,EAAY,OAAO,GAE9BD,EACG,QAAQ,UAAU,EAClB,YAAY,qDAAqD,EACjE;AAAA,IACC;AAAA,IACA;AAAA,EAAA,EAED,OAAO,uBAAuB,yBAAyB,eAAe,EACtE,OAAO,uBAAuB,2BAA2BE,CAAmB,EAC5E,OAAO,iBAAiB,wBAAwB,EAChD,OAAO,aAAa,oDAAoD,EACxE,OAAOX,CAAc,GAEjBS;AACT;AAMO,SAASG,IAAS;AACvB,EAAAJ,EAAA,EAAW,MAAA;AACb;AAEAI,EAAA;"}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { GenerateContext, Generator } from '../generateContext';
|
|
2
|
+
/**
|
|
3
|
+
* Generator for creating TypeScript API client classes from OpenAPI specifications.
|
|
4
|
+
* Generates client classes with proper decorators, type annotations, and method signatures.
|
|
5
|
+
*/
|
|
6
|
+
export declare class ApiClientGenerator implements Generator {
|
|
7
|
+
readonly context: GenerateContext;
|
|
8
|
+
private defaultParameterRequestType;
|
|
9
|
+
private defaultReturnType;
|
|
10
|
+
private readonly apiMetadataCtorInitializer;
|
|
11
|
+
/**
|
|
12
|
+
* Creates a new ApiClientGenerator instance.
|
|
13
|
+
* @param context - The generation context containing OpenAPI spec and configuration
|
|
14
|
+
*/
|
|
15
|
+
constructor(context: GenerateContext);
|
|
16
|
+
/**
|
|
17
|
+
* Generates API client classes for all valid tags in the OpenAPI specification.
|
|
18
|
+
* Processes tags, groups operations, and creates client classes with methods.
|
|
19
|
+
*/
|
|
20
|
+
generate(): void;
|
|
21
|
+
/**
|
|
22
|
+
* Generates API client classes for each tag group.
|
|
23
|
+
* @param apiClientTags - Map of valid API client tags
|
|
24
|
+
* @param groupOperations - Map of operations grouped by tag
|
|
25
|
+
*/
|
|
26
|
+
private generateApiClients;
|
|
27
|
+
/**
|
|
28
|
+
* Creates a new source file for the API client.
|
|
29
|
+
* @param modelInfo - The model information for the client
|
|
30
|
+
* @returns The created source file
|
|
31
|
+
*/
|
|
32
|
+
private createApiClientFile;
|
|
33
|
+
/**
|
|
34
|
+
* Generates a single API client class for the given tag and operations.
|
|
35
|
+
* @param tag - The OpenAPI tag for the client
|
|
36
|
+
* @param operations - Set of operations for this client
|
|
37
|
+
*/
|
|
38
|
+
private generateApiClient;
|
|
39
|
+
/**
|
|
40
|
+
* Generates a unique method name for the operation.
|
|
41
|
+
* @param apiClientClass - The client class to check for existing methods
|
|
42
|
+
* @param operation - The operation to generate a name for
|
|
43
|
+
* @returns A unique camelCase method name
|
|
44
|
+
*/
|
|
45
|
+
private getMethodName;
|
|
46
|
+
/**
|
|
47
|
+
* Resolves the request type for an operation based on its request body.
|
|
48
|
+
* @param sourceFile - The source file to add imports to
|
|
49
|
+
* @param operation - The operation to resolve the request type for
|
|
50
|
+
* @returns The resolved request type string
|
|
51
|
+
*/
|
|
52
|
+
private resolveRequestType;
|
|
53
|
+
/**
|
|
54
|
+
* Resolves method parameters for an operation.
|
|
55
|
+
* @param tag - The tag for parameter filtering
|
|
56
|
+
* @param sourceFile - The source file to add imports to
|
|
57
|
+
* @param operation - The operation to resolve parameters for
|
|
58
|
+
* @returns Array of parameter declarations
|
|
59
|
+
*/
|
|
60
|
+
private resolveParameters;
|
|
61
|
+
/**
|
|
62
|
+
* Resolves the return type for a schema.
|
|
63
|
+
* @param sourceFile - The source file to add imports to
|
|
64
|
+
* @param schema - The schema to resolve the return type for
|
|
65
|
+
* @returns The resolved return type string
|
|
66
|
+
*/
|
|
67
|
+
private resolveSchemaReturnType;
|
|
68
|
+
/**
|
|
69
|
+
* Resolves the return type for an operation based on its responses.
|
|
70
|
+
* @param sourceFile - The source file to add imports to
|
|
71
|
+
* @param operation - The operation to resolve the return type for
|
|
72
|
+
* @returns Object containing type and optional stream flag
|
|
73
|
+
*/
|
|
74
|
+
private resolveReturnType;
|
|
75
|
+
/**
|
|
76
|
+
* Processes a single operation and adds it as a method to the client class.
|
|
77
|
+
* @param tag - The tag for parameter filtering
|
|
78
|
+
* @param sourceFile - The source file containing the client
|
|
79
|
+
* @param apiClientClass - The client class to add the method to
|
|
80
|
+
* @param operation - The operation to process
|
|
81
|
+
*/
|
|
82
|
+
private processOperation;
|
|
83
|
+
/**
|
|
84
|
+
* Groups operations by their tags for client generation.
|
|
85
|
+
* @param apiClientTags - Map of valid API client tags
|
|
86
|
+
* @returns Map of operations grouped by tag name
|
|
87
|
+
*/
|
|
88
|
+
private groupOperations;
|
|
89
|
+
/**
|
|
90
|
+
* Resolves valid API client tags from the OpenAPI specification.
|
|
91
|
+
* Filters out system tags like 'wow' and 'Actuator' and aggregate tags.
|
|
92
|
+
* @returns Map of valid API client tags
|
|
93
|
+
*/
|
|
94
|
+
private resolveApiTags;
|
|
95
|
+
private isAggregateTag;
|
|
96
|
+
}
|
|
97
|
+
//# sourceMappingURL=apiClientGenerator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"apiClientGenerator.d.ts","sourceRoot":"","sources":["../../src/client/apiClientGenerator.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAqDhE;;;GAGG;AACH,qBAAa,kBAAmB,YAAW,SAAS;aAUtB,OAAO,EAAE,eAAe;IATpD,OAAO,CAAC,2BAA2B,CAAsB;IACzD,OAAO,CAAC,iBAAiB,CAA4B;IAErD,OAAO,CAAC,QAAQ,CAAC,0BAA0B,CAAqB;IAEhE;;;OAGG;gBACyB,OAAO,EAAE,eAAe;IAMpD;;;OAGG;IACH,QAAQ;IAgBR;;;;OAIG;IACH,OAAO,CAAC,kBAAkB;IAoB1B;;;;OAIG;IACH,OAAO,CAAC,mBAAmB;IAU3B;;;;OAIG;IACH,OAAO,CAAC,iBAAiB;IAwBzB;;;;;OAKG;IACH,OAAO,CAAC,aAAa;IAerB;;;;;OAKG;IACH,OAAO,CAAC,kBAAkB;IAuD1B;;;;;;OAMG;IACH,OAAO,CAAC,iBAAiB;IAuEzB;;;;;OAKG;IACH,OAAO,CAAC,uBAAuB;IAgC/B;;;;;OAKG;IACH,OAAO,CAAC,iBAAiB;IAqEzB;;;;;;OAMG;IACH,OAAO,CAAC,gBAAgB;IA8CxB;;;;OAIG;IACH,OAAO,CAAC,eAAe;IA4CvB;;;;OAIG;IACH,OAAO,CAAC,cAAc;IA4BtB,OAAO,CAAC,cAAc;CAUvB"}
|
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { GenerateContext } from '../types';
|
|
1
|
+
import { GenerateContext, Generator } from '../generateContext';
|
|
3
2
|
/**
|
|
4
3
|
* Generates TypeScript client classes for aggregates.
|
|
5
4
|
* Creates query clients and command clients based on aggregate definitions.
|
|
6
5
|
*/
|
|
7
|
-
export declare class ClientGenerator
|
|
6
|
+
export declare class ClientGenerator implements Generator {
|
|
7
|
+
readonly context: GenerateContext;
|
|
8
8
|
private readonly queryClientGenerator;
|
|
9
9
|
private readonly commandClientGenerator;
|
|
10
|
+
private readonly apiClientGenerator;
|
|
10
11
|
/**
|
|
11
12
|
* Creates a new ClientGenerator instance.
|
|
12
13
|
* @param context - The generation context containing OpenAPI spec and project details
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"clientGenerator.d.ts","sourceRoot":"","sources":["../../src/client/clientGenerator.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"clientGenerator.d.ts","sourceRoot":"","sources":["../../src/client/clientGenerator.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAKhE;;;GAGG;AACH,qBAAa,eAAgB,YAAW,SAAS;aASnB,OAAO,EAAE,eAAe;IARpD,OAAO,CAAC,QAAQ,CAAC,oBAAoB,CAAuB;IAC5D,OAAO,CAAC,QAAQ,CAAC,sBAAsB,CAAyB;IAChE,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAAqB;IAExD;;;OAGG;gBACyB,OAAO,EAAE,eAAe;IAMpD;;OAEG;IACH,QAAQ,IAAI,IAAI;IAsBhB;;;OAGG;IACH,qBAAqB,CAAC,YAAY,EAAE,MAAM;CAc3C"}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { GenerateContext } from '../types';
|
|
1
|
+
import { GenerateContext, Generator } from '../generateContext';
|
|
3
2
|
import { ClassDeclaration, SourceFile } from 'ts-morph';
|
|
4
3
|
import { AggregateDefinition, CommandDefinition } from '../aggregate';
|
|
5
4
|
/**
|
|
6
5
|
* Generates TypeScript command client classes for aggregates.
|
|
7
6
|
* Creates command clients that can send commands to aggregates.
|
|
8
7
|
*/
|
|
9
|
-
export declare class CommandClientGenerator
|
|
8
|
+
export declare class CommandClientGenerator implements Generator {
|
|
9
|
+
readonly context: GenerateContext;
|
|
10
10
|
private readonly commandEndpointPathsName;
|
|
11
11
|
private readonly defaultCommandClientOptionsName;
|
|
12
12
|
/**
|
|
@@ -26,7 +26,6 @@ export declare class CommandClientGenerator extends BaseCodeGenerator {
|
|
|
26
26
|
processCommandEndpointPaths(clientFile: SourceFile, aggregateDefinition: AggregateDefinition): void;
|
|
27
27
|
getEndpointPath(command: CommandDefinition): string;
|
|
28
28
|
processCommandClient(clientFile: SourceFile, aggregateDefinition: AggregateDefinition, isStream?: boolean): void;
|
|
29
|
-
private methodToDecorator;
|
|
30
29
|
/**
|
|
31
30
|
* Processes and generates a command method for the command client.
|
|
32
31
|
* @param sourceFile - The source file containing the client
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"commandClientGenerator.d.ts","sourceRoot":"","sources":["../../src/client/commandClientGenerator.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"commandClientGenerator.d.ts","sourceRoot":"","sources":["../../src/client/commandClientGenerator.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAChE,OAAO,EACL,gBAAgB,EAChB,UAAU,EAEX,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAiBtE;;;GAGG;AACH,qBAAa,sBAAuB,YAAW,SAAS;aAS1B,OAAO,EAAE,eAAe;IARpD,OAAO,CAAC,QAAQ,CAAC,wBAAwB,CAA4B;IACrE,OAAO,CAAC,QAAQ,CAAC,+BAA+B,CACb;IAEnC;;;OAGG;gBACyB,OAAO,EAAE,eAAe;IAGpD;;OAEG;IACH,QAAQ,IAAI,IAAI;IAwBhB;;;OAGG;IACH,gBAAgB,CAAC,SAAS,EAAE,mBAAmB;IA6E/C,2BAA2B,CACzB,UAAU,EAAE,UAAU,EACtB,mBAAmB,EAAE,mBAAmB;IAsB1C,eAAe,CAAC,OAAO,EAAE,iBAAiB,GAAG,MAAM;IAInD,oBAAoB,CAClB,UAAU,EAAE,UAAU,EACtB,mBAAmB,EAAE,mBAAmB,EACxC,QAAQ,GAAE,OAAe;IAyB3B;;;;;OAKG;IACH,oBAAoB,CAClB,UAAU,EAAE,UAAU,EACtB,MAAM,EAAE,gBAAgB,EACxB,UAAU,EAAE,iBAAiB,EAC7B,UAAU,EAAE,MAAM;CAwFrB"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { ClassDeclaration, SourceFile } from 'ts-morph';
|
|
2
|
+
/**
|
|
3
|
+
* The module specifier for the fetcher-decorator package.
|
|
4
|
+
*/
|
|
5
|
+
export declare const DECORATOR_MODULE_SPECIFIER = "@ahoo-wang/fetcher-decorator";
|
|
6
|
+
/**
|
|
7
|
+
* Named imports from the fetcher-decorator package.
|
|
8
|
+
*/
|
|
9
|
+
export declare const DECORATOR_NAMED_IMPORTS: string[];
|
|
10
|
+
/**
|
|
11
|
+
* Metadata configuration for stream result extraction.
|
|
12
|
+
*/
|
|
13
|
+
export declare const STREAM_RESULT_EXTRACTOR_METADATA = "{\n headers: { Accept: ContentTypeValues.TEXT_EVENT_STREAM },\n resultExtractor: JsonEventStreamResultExtractor,\n}";
|
|
14
|
+
/**
|
|
15
|
+
* Adds the necessary imports for decorator functionality to the source file.
|
|
16
|
+
*
|
|
17
|
+
* @param sourceFile - The source file to add imports to
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```typescript
|
|
21
|
+
* const sourceFile = project.createSourceFile('api.ts');
|
|
22
|
+
* addImportDecorator(sourceFile);
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
export declare function addImportDecorator(sourceFile: SourceFile): void;
|
|
26
|
+
/**
|
|
27
|
+
* Creates a new class declaration with the @api decorator.
|
|
28
|
+
*
|
|
29
|
+
* @param className - The name of the class to create
|
|
30
|
+
* @param sourceFile - The source file to add the class to
|
|
31
|
+
* @param apiArgs - Optional arguments for the @api decorator
|
|
32
|
+
* @returns The created class declaration
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```typescript
|
|
36
|
+
* const sourceFile = project.createSourceFile('UserApi.ts');
|
|
37
|
+
* const classDecl = createDecoratorClass('UserApi', sourceFile, ['baseUrl']);
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
export declare function createDecoratorClass(className: string, sourceFile: SourceFile, apiArgs?: string[]): ClassDeclaration;
|
|
41
|
+
/**
|
|
42
|
+
* Adds the ApiMetadataCapable interface implementation and constructor to a class declaration.
|
|
43
|
+
*
|
|
44
|
+
* @param classDeclaration - The class declaration to modify
|
|
45
|
+
* @param initializer - Optional initializer for the apiMetadata parameter
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```typescript
|
|
49
|
+
* const classDecl = createDecoratorClass('UserApi', sourceFile);
|
|
50
|
+
* addApiMetadataCtor(classDecl, '{}');
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
export declare function addApiMetadataCtor(classDeclaration: ClassDeclaration, initializer?: string): void;
|
|
54
|
+
//# sourceMappingURL=decorators.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decorators.d.ts","sourceRoot":"","sources":["../../src/client/decorators.ts"],"names":[],"mappings":"AAaA,OAAO,EACL,gBAAgB,EAIhB,UAAU,EACX,MAAM,UAAU,CAAC;AAGlB;;GAEG;AACH,eAAO,MAAM,0BAA0B,iCAAiC,CAAC;AAEzE;;GAEG;AACH,eAAO,MAAM,uBAAuB,UAYnC,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,gCAAgC,0HAG3C,CAAC;AAEH;;;;;;;;;;GAUG;AACH,wBAAgB,kBAAkB,CAAC,UAAU,EAAE,UAAU,QAExD;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,oBAAoB,CAClC,SAAS,EAAE,MAAM,EACjB,UAAU,EAAE,UAAU,EACtB,OAAO,GAAE,MAAM,EAAO,GACrB,gBAAgB,CAWlB;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,kBAAkB,CAChC,gBAAgB,EAAE,gBAAgB,EAClC,WAAW,CAAC,EAAE,MAAM,QAerB"}
|
package/dist/client/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AAaA,cAAc,mBAAmB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AAaA,cAAc,mBAAmB,CAAC;AAClC,cAAc,sBAAsB,CAAC;AACrC,cAAc,0BAA0B,CAAC;AACzC,cAAc,cAAc,CAAC;AAC7B,cAAc,wBAAwB,CAAC;AACvC,cAAc,SAAS,CAAC"}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { SourceFile } from 'ts-morph';
|
|
2
|
-
import { GenerateContext } from '../
|
|
3
|
-
import { BaseCodeGenerator } from '../baseCodeGenerator';
|
|
2
|
+
import { GenerateContext, Generator } from '../generateContext';
|
|
4
3
|
import { AggregateDefinition, TagAliasAggregate } from '../aggregate';
|
|
5
4
|
/**
|
|
6
5
|
* Generates TypeScript query client classes for aggregates.
|
|
7
6
|
* Creates query clients that can perform state queries and event streaming.
|
|
8
7
|
*/
|
|
9
|
-
export declare class QueryClientGenerator
|
|
8
|
+
export declare class QueryClientGenerator implements Generator {
|
|
9
|
+
readonly context: GenerateContext;
|
|
10
10
|
/**
|
|
11
11
|
* Creates a new QueryClientGenerator instance.
|
|
12
12
|
* @param context - The generation context containing OpenAPI spec and project details
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"queryClientGenerator.d.ts","sourceRoot":"","sources":["../../src/client/queryClientGenerator.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,UAAU,EAA2B,MAAM,UAAU,CAAC;AAC/D,OAAO,EAAE,eAAe,EAAE,
|
|
1
|
+
{"version":3,"file":"queryClientGenerator.d.ts","sourceRoot":"","sources":["../../src/client/queryClientGenerator.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,UAAU,EAA2B,MAAM,UAAU,CAAC;AAC/D,OAAO,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAChE,OAAO,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAKtE;;;GAGG;AACH,qBAAa,oBAAqB,YAAW,SAAS;aAKxB,OAAO,EAAE,eAAe;IAJpD;;;OAGG;gBACyB,OAAO,EAAE,eAAe;IAGpD;;OAEG;IACH,QAAQ,IAAI,IAAI;IAwBhB;;;;;OAKG;IACH,oBAAoB,CAClB,SAAS,EAAE,iBAAiB,EAC5B,QAAQ,EAAE,MAAM,GACf,UAAU;IASb;;;OAGG;IACH,kBAAkB,CAAC,SAAS,EAAE,mBAAmB;CA6FlD"}
|
package/dist/client/utils.d.ts
CHANGED
|
@@ -9,4 +9,5 @@ export declare function createClientFilePath(project: Project, outputDir: string
|
|
|
9
9
|
* @returns The generated client class name
|
|
10
10
|
*/
|
|
11
11
|
export declare function getClientName(aggregate: TagAliasAggregate, suffix: string): string;
|
|
12
|
+
export declare function methodToDecorator(method: string): string;
|
|
12
13
|
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/client/utils.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAC/C,OAAO,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAGtE,wBAAgB,iBAAiB,CAC/B,mBAAmB,EAAE,mBAAmB,GACvC,MAAM,CAiBR;AAED,wBAAgB,oBAAoB,CAClC,OAAO,EAAE,OAAO,EAChB,SAAS,EAAE,MAAM,EACjB,SAAS,EAAE,iBAAiB,EAC5B,QAAQ,EAAE,MAAM,GACf,UAAU,CAGZ;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAC3B,SAAS,EAAE,iBAAiB,EAC5B,MAAM,EAAE,MAAM,GACb,MAAM,CAER"}
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/client/utils.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAC/C,OAAO,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAGtE,wBAAgB,iBAAiB,CAC/B,mBAAmB,EAAE,mBAAmB,GACvC,MAAM,CAiBR;AAED,wBAAgB,oBAAoB,CAClC,OAAO,EAAE,OAAO,EAChB,SAAS,EAAE,MAAM,EACjB,SAAS,EAAE,iBAAiB,EAC5B,QAAQ,EAAE,MAAM,GACf,UAAU,CAGZ;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAC3B,SAAS,EAAE,iBAAiB,EAC5B,MAAM,EAAE,MAAM,GACb,MAAM,CAER;AAGD,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAKxD"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { Project } from 'ts-morph';
|
|
1
|
+
import { Project, SourceFile } from 'ts-morph';
|
|
2
2
|
import { OpenAPI } from '@ahoo-wang/fetcher-openapi';
|
|
3
|
-
import {
|
|
3
|
+
import { GenerateContextInit, GeneratorConfiguration, Logger } from './types';
|
|
4
4
|
import { BoundedContextAggregates } from './aggregate';
|
|
5
|
-
export declare
|
|
5
|
+
export declare class GenerateContext implements GenerateContextInit {
|
|
6
6
|
/** The ts-morph project instance used for code generation */
|
|
7
7
|
readonly project: Project;
|
|
8
8
|
/** The OpenAPI specification object */
|
|
@@ -13,15 +13,18 @@ export declare abstract class BaseCodeGenerator implements GenerateContext {
|
|
|
13
13
|
readonly contextAggregates: BoundedContextAggregates;
|
|
14
14
|
/** Optional logger for generation progress and errors */
|
|
15
15
|
readonly logger: Logger;
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
16
|
+
readonly config: GeneratorConfiguration;
|
|
17
|
+
private readonly defaultIgnorePathParameters;
|
|
18
|
+
readonly currentContextAlias: string | undefined;
|
|
19
|
+
constructor(context: GenerateContextInit);
|
|
20
|
+
getOrCreateSourceFile(filePath: string): SourceFile;
|
|
21
|
+
isIgnoreApiClientPathParameters(tagName: string, parameterName: string): boolean;
|
|
22
|
+
}
|
|
23
|
+
export interface Generator {
|
|
21
24
|
/**
|
|
22
25
|
* Generates code based on the provided context.
|
|
23
26
|
* Subclasses must implement this method to define their specific generation logic.
|
|
24
27
|
*/
|
|
25
|
-
|
|
28
|
+
generate(): void;
|
|
26
29
|
}
|
|
27
|
-
//# sourceMappingURL=
|
|
30
|
+
//# sourceMappingURL=generateContext.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generateContext.d.ts","sourceRoot":"","sources":["../src/generateContext.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAC/C,OAAO,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAC;AACrD,OAAO,EAAE,mBAAmB,EAAE,sBAAsB,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAC9E,OAAO,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAC;AAGvD,qBAAa,eAAgB,YAAW,mBAAmB;IACzD,6DAA6D;IAC7D,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,uCAAuC;IACvC,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,oDAAoD;IACpD,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,4DAA4D;IAC5D,QAAQ,CAAC,iBAAiB,EAAE,wBAAwB,CAAC;IACrD,yDAAyD;IACzD,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,MAAM,EAAE,sBAAsB,CAAC;IACxC,OAAO,CAAC,QAAQ,CAAC,2BAA2B,CAA2B;IACvE,QAAQ,CAAC,mBAAmB,EAAE,MAAM,GAAG,SAAS,CAAC;gBAErC,OAAO,EAAE,mBAAmB;IAUxC,qBAAqB,CAAC,QAAQ,EAAE,MAAM,GAAG,UAAU;IAInD,+BAA+B,CAAC,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,GAAG,OAAO;CAIjF;AAED,MAAM,WAAW,SAAS;IACxB;;;OAGG;IACH,QAAQ,IAAI,IAAI,CAAC;CAClB"}
|