@ahoo-wang/fetcher-generator 2.5.6 → 2.5.8
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 +6 -8
- package/README.zh-CN.md +5 -7
- package/dist/cli.cjs +1 -1
- package/dist/cli.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -385,7 +385,8 @@ export class CartApiClient implements ApiMetadataCapable {
|
|
|
385
385
|
The generated code is designed to work seamlessly with the Fetcher ecosystem:
|
|
386
386
|
|
|
387
387
|
```typescript
|
|
388
|
-
import { Fetcher } from '@ahoo-wang/fetcher';
|
|
388
|
+
import { fetcher, Fetcher } from '@ahoo-wang/fetcher';
|
|
389
|
+
import { all } from '@ahoo-wang/fetcher-wow';
|
|
389
390
|
import { cartQueryClientFactory } from './generated/example/cart/queryClient';
|
|
390
391
|
import { CartCommandClient } from './generated/example/cart/commandClient';
|
|
391
392
|
import { CartApiClient } from './generated/example/CartApiClient';
|
|
@@ -395,15 +396,12 @@ const fetcher = new Fetcher({
|
|
|
395
396
|
baseURL: 'https://api.example.com',
|
|
396
397
|
});
|
|
397
398
|
|
|
398
|
-
// Register the fetcher (if using named fetchers)
|
|
399
|
-
Fetcher.register('api', fetcher);
|
|
400
|
-
|
|
401
399
|
// Use the generated query client factory
|
|
402
|
-
const
|
|
403
|
-
const cartState = await
|
|
400
|
+
const snapshotClient = cartQueryClientFactory.createSnapshotQueryClient({ fetcher: fetcher });
|
|
401
|
+
const cartState = await snapshotClient.singleState({ condition: all() });
|
|
404
402
|
|
|
405
403
|
// Use the generated command client
|
|
406
|
-
const commandClient = new CartCommandClient();
|
|
404
|
+
const commandClient = new CartCommandClient({ fetcher: fetcher });
|
|
407
405
|
const result = await commandClient.addCartItem(
|
|
408
406
|
{
|
|
409
407
|
command: {
|
|
@@ -417,7 +415,7 @@ const result = await commandClient.addCartItem(
|
|
|
417
415
|
);
|
|
418
416
|
|
|
419
417
|
// Use the generated API client for custom endpoints (based on OpenAPI tag "cart")
|
|
420
|
-
const apiClient = new CartApiClient();
|
|
418
|
+
const apiClient = new CartApiClient({ fetcher: fetcher });
|
|
421
419
|
const cartData = await apiClient.me();
|
|
422
420
|
```
|
|
423
421
|
|
package/README.zh-CN.md
CHANGED
|
@@ -378,6 +378,7 @@ export class CartApiClient implements ApiMetadataCapable {
|
|
|
378
378
|
|
|
379
379
|
```typescript
|
|
380
380
|
import { Fetcher } from '@ahoo-wang/fetcher';
|
|
381
|
+
import { all } from '@ahoo-wang/fetcher-wow';
|
|
381
382
|
import { cartQueryClientFactory } from './generated/example/cart/queryClient';
|
|
382
383
|
import { CartCommandClient } from './generated/example/cart/commandClient';
|
|
383
384
|
import { CartApiClient } from './generated/example/CartApiClient';
|
|
@@ -387,15 +388,12 @@ const fetcher = new Fetcher({
|
|
|
387
388
|
baseURL: 'https://api.example.com',
|
|
388
389
|
});
|
|
389
390
|
|
|
390
|
-
// 注册 fetcher(如果使用命名 fetcher)
|
|
391
|
-
Fetcher.register('api', fetcher);
|
|
392
|
-
|
|
393
391
|
// 使用生成的查询客户端工厂
|
|
394
|
-
const
|
|
395
|
-
const cartState = await
|
|
392
|
+
const snapshotClient = cartQueryClientFactory.createSnapshotQueryClient({ fetcher: fetcher });
|
|
393
|
+
const cartState = await snapshotClient.singleState({ condition: all() });
|
|
396
394
|
|
|
397
395
|
// 使用生成的命令客户端
|
|
398
|
-
const commandClient = new CartCommandClient();
|
|
396
|
+
const commandClient = new CartCommandClient({ fetcher: fetcher });
|
|
399
397
|
const result = await commandClient.addCartItem(
|
|
400
398
|
{
|
|
401
399
|
command: {
|
|
@@ -409,7 +407,7 @@ const result = await commandClient.addCartItem(
|
|
|
409
407
|
);
|
|
410
408
|
|
|
411
409
|
// 使用生成的 API 客户端用于自定义端点(基于 OpenAPI 标签 "cart")
|
|
412
|
-
const apiClient = new CartApiClient();
|
|
410
|
+
const apiClient = new CartApiClient({ fetcher: fetcher });
|
|
413
411
|
const cartData = await apiClient.me();
|
|
414
412
|
```
|
|
415
413
|
|
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"),a=require("./index.cjs");require("@ahoo-wang/fetcher");require("yaml");require("fs");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 i=this.getTimestamp(),r=" ".repeat(t);o.length>0?console.log(`[${i}] 🔄 ${r}${e}`,...o):console.log(`[${i}] 🔄 ${r}${e}`)}progressWithCount(e,t,o,i=0,...r){const s=this.getTimestamp(),p=" ".repeat(i),l=`[${e}/${t}]`;r.length>0?console.log(`[${s}] 🔄 ${p}${l} ${o}`,...r):console.log(`[${s}] 🔄 ${p}${l} ${o}`)}}function h(n){if(!n)return!1;try{const e=new URL(n);return e.protocol==="http:"||e.protocol==="https:"}catch{return n.length>0}}async function d(n){const e=new f;process.on("SIGINT",()=>{e.error("Generation interrupted by user"),process.exit(130)}),h(n.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={inputPath:n.input,outputDir:n.output,configPath:n.config,tsConfigFilePath:n.tsConfigFilePath,logger:e};await new a.CodeGenerator(t).generate(),e.success(`Code generation completed successfully! Files generated in: ${n.output}`)}catch(t){e.error(`Error during code generation: ${t}`),process.exit(1)}}const $="2.5.
|
|
2
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("commander"),a=require("./index.cjs");require("@ahoo-wang/fetcher");require("yaml");require("fs");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 i=this.getTimestamp(),r=" ".repeat(t);o.length>0?console.log(`[${i}] 🔄 ${r}${e}`,...o):console.log(`[${i}] 🔄 ${r}${e}`)}progressWithCount(e,t,o,i=0,...r){const s=this.getTimestamp(),p=" ".repeat(i),l=`[${e}/${t}]`;r.length>0?console.log(`[${s}] 🔄 ${p}${l} ${o}`,...r):console.log(`[${s}] 🔄 ${p}${l} ${o}`)}}function h(n){if(!n)return!1;try{const e=new URL(n);return e.protocol==="http:"||e.protocol==="https:"}catch{return n.length>0}}async function d(n){const e=new f;process.on("SIGINT",()=>{e.error("Generation interrupted by user"),process.exit(130)}),h(n.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={inputPath:n.input,outputDir:n.output,configPath:n.config,tsConfigFilePath:n.tsConfigFilePath,logger:e};await new a.CodeGenerator(t).generate(),e.success(`Code generation completed successfully! Files generated in: ${n.output}`)}catch(t){e.error(`Error during code generation: ${t}`),process.exit(1)}}const $="2.5.8",m={version:$};function u(){return c.program.name("fetcher-generator").description("OpenAPI Specification TypeScript code generator for Wow").version(m.version),c.program.command("generate").description("Generate TypeScript code from OpenAPI specification").requiredOption("-i, --input <file>","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",a.DEFAULT_CONFIG_PATH).option("-t, --ts-config-file-path <file>","TypeScript configuration file path").option("-v, --verbose","Enable verbose logging").option("--dry-run","Show what would be generated without writing files").action(d),c.program}function g(){u().parse()}g();exports.runCLI=g;exports.setupCLI=u;
|
|
3
3
|
//# sourceMappingURL=cli.cjs.map
|
package/dist/cli.js
CHANGED