@ahoo-wang/fetcher-generator 2.3.6 → 2.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +84 -6
- package/README.zh-CN.md +82 -6
- 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 +860 -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/README.md
CHANGED
|
@@ -96,9 +96,10 @@ The generator creates the following structure in your output directory:
|
|
|
96
96
|
```
|
|
97
97
|
output/
|
|
98
98
|
├── {bounded-context}/
|
|
99
|
-
│ ├── index.ts # Auto-generated index file exporting all aggregates
|
|
99
|
+
│ ├── index.ts # Auto-generated index file exporting all aggregates and API clients
|
|
100
100
|
│ ├── boundedContext.ts # Bounded context alias constant
|
|
101
101
|
│ ├── types.ts # Shared types for the bounded context
|
|
102
|
+
│ ├── {Tag}ApiClient.ts # API client classes for custom endpoints (one per OpenAPI tag)
|
|
102
103
|
│ └── {aggregate}/ # Aggregate-specific files
|
|
103
104
|
│ ├── index.ts # Auto-generated index file for aggregate
|
|
104
105
|
│ ├── types.ts # Aggregate-specific types, models, and enums
|
|
@@ -113,20 +114,20 @@ output/
|
|
|
113
114
|
The generator automatically creates `index.ts` files in all directories to provide convenient module exports:
|
|
114
115
|
|
|
115
116
|
- **Root index.ts**: Exports all bounded contexts
|
|
116
|
-
- **Bounded context index.ts**: Exports all aggregates within the context
|
|
117
|
+
- **Bounded context index.ts**: Exports all aggregates and API clients (based on OpenAPI tags) within the context
|
|
117
118
|
- **Aggregate index.ts**: Exports all files within the aggregate
|
|
118
119
|
|
|
119
120
|
This allows for clean imports like:
|
|
120
121
|
|
|
121
122
|
```typescript
|
|
122
123
|
// Import everything from a bounded context
|
|
123
|
-
import * as
|
|
124
|
+
import * as example from './generated/example';
|
|
124
125
|
|
|
125
|
-
// Import specific aggregates
|
|
126
|
-
import {
|
|
126
|
+
// Import specific aggregates and API clients (API clients are generated per OpenAPI tag)
|
|
127
|
+
import { cart, CartApiClient } from './generated/example';
|
|
127
128
|
|
|
128
129
|
// Import specific files
|
|
129
|
-
import {
|
|
130
|
+
import { CartState } from './generated/example/cart';
|
|
130
131
|
```
|
|
131
132
|
|
|
132
133
|
## 🎯 Generated Code Examples
|
|
@@ -307,6 +308,78 @@ export class CartStreamCommandClient implements ApiMetadataCapable {
|
|
|
307
308
|
}
|
|
308
309
|
```
|
|
309
310
|
|
|
311
|
+
### API Clients
|
|
312
|
+
|
|
313
|
+
The generator also creates API client classes for custom endpoints that don't follow the domain-driven command pattern.
|
|
314
|
+
These are generated based on OpenAPI tags (one client class per tag):
|
|
315
|
+
|
|
316
|
+
```typescript
|
|
317
|
+
// Generated API client for custom endpoints
|
|
318
|
+
import {
|
|
319
|
+
type ApiMetadata,
|
|
320
|
+
type ApiMetadataCapable,
|
|
321
|
+
ParameterRequest,
|
|
322
|
+
api,
|
|
323
|
+
attribute,
|
|
324
|
+
autoGeneratedError,
|
|
325
|
+
get,
|
|
326
|
+
path,
|
|
327
|
+
post,
|
|
328
|
+
request,
|
|
329
|
+
} from '@ahoo-wang/fetcher-decorator';
|
|
330
|
+
import { CommandResult } from '@ahoo-wang/fetcher-wow';
|
|
331
|
+
import { CartData } from './cart/types';
|
|
332
|
+
import { ContentTypeValues } from '@ahoo-wang/fetcher';
|
|
333
|
+
import {
|
|
334
|
+
JsonEventStreamResultExtractor,
|
|
335
|
+
JsonServerSentEventStream,
|
|
336
|
+
} from '@ahoo-wang/fetcher-eventstream';
|
|
337
|
+
|
|
338
|
+
/** Shopping Cart */
|
|
339
|
+
@api()
|
|
340
|
+
export class CartApiClient implements ApiMetadataCapable {
|
|
341
|
+
constructor(
|
|
342
|
+
public readonly apiMetadata: ApiMetadata = { basePath: 'example' },
|
|
343
|
+
) {
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
/** Custom command sending */
|
|
347
|
+
@post('/cart/{userId}/customize-send-cmd')
|
|
348
|
+
customizeSendCmd(
|
|
349
|
+
@path('userId') userId: string,
|
|
350
|
+
@request() httpRequest?: ParameterRequest,
|
|
351
|
+
@attribute() attributes?: Record<string, any>,
|
|
352
|
+
): Promise<CommandResult> {
|
|
353
|
+
throw autoGeneratedError(userId, httpRequest, attributes);
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
/** Add cart item with event streaming */
|
|
357
|
+
@post('/cart/{userId}/add-cart-item', {
|
|
358
|
+
headers: { Accept: ContentTypeValues.TEXT_EVENT_STREAM },
|
|
359
|
+
resultExtractor: JsonEventStreamResultExtractor,
|
|
360
|
+
})
|
|
361
|
+
addCartItem(
|
|
362
|
+
@path('userId') userId: string,
|
|
363
|
+
@request() httpRequest?: ParameterRequest,
|
|
364
|
+
@attribute() attributes?: Record<string, any>,
|
|
365
|
+
): Promise<JsonServerSentEventStream<CommandResult>> {
|
|
366
|
+
throw autoGeneratedError(userId, httpRequest, attributes);
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
/** Get current user's cart */
|
|
370
|
+
@get('/cart/me')
|
|
371
|
+
me(): Promise<CartData> {
|
|
372
|
+
throw autoGeneratedError();
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
/** Get current user's cart (sync) */
|
|
376
|
+
@get('/cart/me/sync')
|
|
377
|
+
meSync(): Promise<CartData> {
|
|
378
|
+
throw autoGeneratedError();
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
```
|
|
382
|
+
|
|
310
383
|
## 🔧 Integration with Fetcher
|
|
311
384
|
|
|
312
385
|
The generated code is designed to work seamlessly with the Fetcher ecosystem:
|
|
@@ -315,6 +388,7 @@ The generated code is designed to work seamlessly with the Fetcher ecosystem:
|
|
|
315
388
|
import { Fetcher } from '@ahoo-wang/fetcher';
|
|
316
389
|
import { cartQueryClientFactory } from './generated/example/cart/queryClient';
|
|
317
390
|
import { CartCommandClient } from './generated/example/cart/commandClient';
|
|
391
|
+
import { CartApiClient } from './generated/example/CartApiClient';
|
|
318
392
|
|
|
319
393
|
// Create a fetcher instance
|
|
320
394
|
const fetcher = new Fetcher({
|
|
@@ -341,6 +415,10 @@ const result = await commandClient.addCartItem(
|
|
|
341
415
|
ownerId: 'user-456',
|
|
342
416
|
},
|
|
343
417
|
);
|
|
418
|
+
|
|
419
|
+
// Use the generated API client for custom endpoints (based on OpenAPI tag "cart")
|
|
420
|
+
const apiClient = new CartApiClient();
|
|
421
|
+
const cartData = await apiClient.me();
|
|
344
422
|
```
|
|
345
423
|
|
|
346
424
|
## 📋 OpenAPI Specification Requirements
|
package/README.zh-CN.md
CHANGED
|
@@ -90,9 +90,10 @@ fetcher-generator generate -i http://localhost:8080/api-spec.yaml -o ./src/gener
|
|
|
90
90
|
```
|
|
91
91
|
output/
|
|
92
92
|
├── {bounded-context}/
|
|
93
|
-
│ ├── index.ts #
|
|
93
|
+
│ ├── index.ts # 自动生成的索引文件,导出所有聚合和 API 客户端
|
|
94
94
|
│ ├── boundedContext.ts # 有界上下文别名常量
|
|
95
95
|
│ ├── types.ts # 有界上下文的共享类型
|
|
96
|
+
│ ├── {Tag}ApiClient.ts # API 客户端类,用于自定义端点(每个 OpenAPI 标签一个)
|
|
96
97
|
│ └── {aggregate}/ # 聚合特定文件
|
|
97
98
|
│ ├── index.ts # 聚合的自动生成索引文件
|
|
98
99
|
│ ├── types.ts # 聚合特定类型、模型和枚举
|
|
@@ -107,20 +108,20 @@ output/
|
|
|
107
108
|
生成器自动创建 `index.ts` 文件,为便捷的模块导出提供支持:
|
|
108
109
|
|
|
109
110
|
- **根 index.ts**:导出所有有界上下文
|
|
110
|
-
- **有界上下文 index.ts
|
|
111
|
+
- **有界上下文 index.ts**:导出上下文中的所有聚合和 API 客户端
|
|
111
112
|
- **聚合 index.ts**:导出聚合中的所有文件
|
|
112
113
|
|
|
113
114
|
这允许干净的导入,例如:
|
|
114
115
|
|
|
115
116
|
```typescript
|
|
116
117
|
// 导入有界上下文的所有内容
|
|
117
|
-
import * as
|
|
118
|
+
import * as example from './generated/example';
|
|
118
119
|
|
|
119
|
-
//
|
|
120
|
-
import {
|
|
120
|
+
// 导入特定聚合和 API 客户端
|
|
121
|
+
import { cart, CartApiClient } from './generated/example';
|
|
121
122
|
|
|
122
123
|
// 导入特定文件
|
|
123
|
-
import {
|
|
124
|
+
import { CartState } from './generated/example/cart';
|
|
124
125
|
```
|
|
125
126
|
|
|
126
127
|
## 🎯 生成的代码示例
|
|
@@ -301,6 +302,76 @@ export class CartStreamCommandClient implements ApiMetadataCapable {
|
|
|
301
302
|
}
|
|
302
303
|
```
|
|
303
304
|
|
|
305
|
+
### API 客户端
|
|
306
|
+
|
|
307
|
+
生成器还为不遵循领域驱动命令模式的自定义端点创建 API 客户端类。这些基于 OpenAPI 标签生成(每个标签一个客户端类):
|
|
308
|
+
|
|
309
|
+
```typescript
|
|
310
|
+
// 生成的 API 客户端,用于自定义端点
|
|
311
|
+
import {
|
|
312
|
+
type ApiMetadata,
|
|
313
|
+
type ApiMetadataCapable,
|
|
314
|
+
ParameterRequest,
|
|
315
|
+
api,
|
|
316
|
+
attribute,
|
|
317
|
+
autoGeneratedError,
|
|
318
|
+
get,
|
|
319
|
+
path,
|
|
320
|
+
post,
|
|
321
|
+
request,
|
|
322
|
+
} from '@ahoo-wang/fetcher-decorator';
|
|
323
|
+
import { CommandResult } from '@ahoo-wang/fetcher-wow';
|
|
324
|
+
import { CartData } from './cart/types';
|
|
325
|
+
import { ContentTypeValues } from '@ahoo-wang/fetcher';
|
|
326
|
+
import {
|
|
327
|
+
JsonEventStreamResultExtractor,
|
|
328
|
+
JsonServerSentEventStream,
|
|
329
|
+
} from '@ahoo-wang/fetcher-eventstream';
|
|
330
|
+
|
|
331
|
+
/** 购物车 */
|
|
332
|
+
@api()
|
|
333
|
+
export class CartApiClient implements ApiMetadataCapable {
|
|
334
|
+
constructor(
|
|
335
|
+
public readonly apiMetadata: ApiMetadata = { basePath: 'example' },
|
|
336
|
+
) {}
|
|
337
|
+
|
|
338
|
+
/** 自定义发送命令 */
|
|
339
|
+
@post('/cart/{userId}/customize-send-cmd')
|
|
340
|
+
customizeSendCmd(
|
|
341
|
+
@path('userId') userId: string,
|
|
342
|
+
@request() httpRequest?: ParameterRequest,
|
|
343
|
+
@attribute() attributes?: Record<string, any>,
|
|
344
|
+
): Promise<CommandResult> {
|
|
345
|
+
throw autoGeneratedError(userId, httpRequest, attributes);
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
/** 加入购物车(带事件流) */
|
|
349
|
+
@post('/cart/{userId}/add-cart-item', {
|
|
350
|
+
headers: { Accept: ContentTypeValues.TEXT_EVENT_STREAM },
|
|
351
|
+
resultExtractor: JsonEventStreamResultExtractor,
|
|
352
|
+
})
|
|
353
|
+
addCartItem(
|
|
354
|
+
@path('userId') userId: string,
|
|
355
|
+
@request() httpRequest?: ParameterRequest,
|
|
356
|
+
@attribute() attributes?: Record<string, any>,
|
|
357
|
+
): Promise<JsonServerSentEventStream<CommandResult>> {
|
|
358
|
+
throw autoGeneratedError(userId, httpRequest, attributes);
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
/** 获取当前用户的购物车 */
|
|
362
|
+
@get('/cart/me')
|
|
363
|
+
me(): Promise<CartData> {
|
|
364
|
+
throw autoGeneratedError();
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
/** 获取当前用户的购物车(同步) */
|
|
368
|
+
@get('/cart/me/sync')
|
|
369
|
+
meSync(): Promise<CartData> {
|
|
370
|
+
throw autoGeneratedError();
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
```
|
|
374
|
+
|
|
304
375
|
## 🔧 与 Fetcher 集成
|
|
305
376
|
|
|
306
377
|
生成的代码设计为与 Fetcher 生态系统无缝集成:
|
|
@@ -309,6 +380,7 @@ export class CartStreamCommandClient implements ApiMetadataCapable {
|
|
|
309
380
|
import { Fetcher } from '@ahoo-wang/fetcher';
|
|
310
381
|
import { cartQueryClientFactory } from './generated/example/cart/queryClient';
|
|
311
382
|
import { CartCommandClient } from './generated/example/cart/commandClient';
|
|
383
|
+
import { CartApiClient } from './generated/example/CartApiClient';
|
|
312
384
|
|
|
313
385
|
// 创建 fetcher 实例
|
|
314
386
|
const fetcher = new Fetcher({
|
|
@@ -335,6 +407,10 @@ const result = await commandClient.addCartItem(
|
|
|
335
407
|
ownerId: 'user-456',
|
|
336
408
|
},
|
|
337
409
|
);
|
|
410
|
+
|
|
411
|
+
// 使用生成的 API 客户端用于自定义端点(基于 OpenAPI 标签 "cart")
|
|
412
|
+
const apiClient = new CartApiClient();
|
|
413
|
+
const cartData = await apiClient.me();
|
|
338
414
|
```
|
|
339
415
|
|
|
340
416
|
## 📋 OpenAPI 规范要求
|
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.1",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,EA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E,QAAQ,KAAK,CAAC,GAGhB,GAAI,CACFA,EAAO,KAAK,6BAA6B,EACzC,MAAMC,EAAU,IAAIC,UACdC,EAAqC,CACzC,UAAWJ,EAAQ,MACnB,UAAWA,EAAQ,OACnB,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,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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MlC,CACD,MAAMC,EAAS,IAAId,EAGnB,QAAQ,GAAG,SAAU,IAAM,CACzBc,EAAO,MAAM,gCAAgC,EAC7C,QAAQ,KAAK,GAAG,CAClB,CAAC,EAGIL,EAAcI,EAAQ,KAAK,IAC9BC,EAAO,MAAM,4DAA4D,EACzE,QAAQ,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.1", 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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T,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_CONFIG_PATH","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,aAAA;AACvB,IAAID,EAAO,SAAS,IAClB,QAAQ,IAAI,IAAIC,CAAS,OAAOF,CAAO,IAAI,GAAGC,CAAM,IAEpD,QAAQ,IAAI,IAAIC,CAAS,OAAOF,CAAO,EAAE;AAAA,EAE7C;AAAA,EAEA,MAAMA,MAAoBC,GAAqB;AAC7C,UAAMC,IAAY,KAAK,aAAA;AACvB,IAAID,EAAO,SAAS,IAClB,QAAQ,MAAM,IAAIC,CAAS,OAAOF,CAAO,IAAI,GAAGC,CAAM,IAEtD,QAAQ,MAAM,IAAIC,CAAS,OAAOF,CAAO,EAAE;AAAA,EAE/C;AAAA,EAEA,SAASA,GAAiBG,IAAQ,MAAMF,GAAqB;AAC3D,UAAMC,IAAY,KAAK,aAAA,GACjBE,IAAS,KAAK,OAAOD,CAAK;AAChC,IAAIF,EAAO,SAAS,IAClB,QAAQ,IAAI,IAAIC,CAAS,QAAQE,CAAM,GAAGJ,CAAO,IAAI,GAAGC,CAAM,IAE9D,QAAQ,IAAI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AAA,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,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;IAiEzB;;;;;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"}
|