@bitstack/ng-query-codegen-openapi 0.0.36 → 0.0.38-alpha.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/lib/bin/cli.mjs +18 -28
- package/lib/bin/cli.mjs.map +1 -1
- package/lib/index.js +17 -16
- package/lib/index.js.map +1 -1
- package/lib/index.mjs +17 -16
- package/lib/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/generators/rtk-query-generator.ts +6 -16
- package/src/generators/types-generator.ts +15 -0
|
@@ -81,21 +81,11 @@ export function generateRtkQueryFile(
|
|
|
81
81
|
/**
|
|
82
82
|
* ${info.summary}
|
|
83
83
|
*/
|
|
84
|
-
${info.operationName}LazyQuery(): {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
const { skipCache = true } = options;
|
|
90
|
-
if (!skipCache) {
|
|
91
|
-
const cachedResult = this.ntkQuery.getQueryCache<${info.responseTypeName}>([ECacheTagTypes.${info.queryKeyName}${!info.isVoidArg ? ', args.variables' : ''}]);
|
|
92
|
-
if (cachedResult) {
|
|
93
|
-
return cachedResult;
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
return this.apiService.${info.operationName}(args);
|
|
97
|
-
}
|
|
98
|
-
};
|
|
84
|
+
${info.operationName}LazyQuery(): LazyQueryResult<${info.responseTypeName}, IRestFulEndpointsQueryReturn<${info.argTypeName}>> {
|
|
85
|
+
return this.ntkQuery.lazyQuery<${info.responseTypeName}, IRestFulEndpointsQueryReturn<${info.argTypeName}>(
|
|
86
|
+
ECacheTagTypes.${info.queryKeyName},
|
|
87
|
+
(args) => this.apiService.${info.operationName}(args),
|
|
88
|
+
);
|
|
99
89
|
}`
|
|
100
90
|
)
|
|
101
91
|
.join('');
|
|
@@ -106,7 +96,7 @@ export function generateRtkQueryFile(
|
|
|
106
96
|
import {Injectable, inject} from '@angular/core';
|
|
107
97
|
import {Observable} from 'rxjs';
|
|
108
98
|
import {HttpErrorResponse} from '@angular/common/http';
|
|
109
|
-
import {NtkQueryService, MutationState, QueryState, MutationResponse} from '@core/ntk-query';
|
|
99
|
+
import {NtkQueryService, MutationState, QueryState, MutationResponse, LazyQueryResult, LazyQueryTriggerOptions} from '@core/ntk-query';
|
|
110
100
|
import {ECacheTagTypes} from '../tagTypes';
|
|
111
101
|
import {${apiServiceName}} from './enhanceEndpoints';
|
|
112
102
|
import {IRestFulEndpointsQueryReturn, RequestOptions} from '../common-types';
|
|
@@ -294,6 +294,21 @@ function getTypeFromSchema(schema: any, schemaTypeMap: Record<string, string> =
|
|
|
294
294
|
}
|
|
295
295
|
}
|
|
296
296
|
|
|
297
|
+
// 處理 oneOf / anyOf -> 聯合類型 (A | B)
|
|
298
|
+
if (schema.oneOf || schema.anyOf) {
|
|
299
|
+
const variants: any[] = schema.oneOf || schema.anyOf;
|
|
300
|
+
const types = variants.map((s: any) => getTypeFromSchema(s, schemaTypeMap, indentLevel));
|
|
301
|
+
const baseType = types.join(' | ');
|
|
302
|
+
return schema.nullable ? `${baseType} | null` : baseType;
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
// 處理 allOf -> 交叉類型 (A & B)
|
|
306
|
+
if (schema.allOf) {
|
|
307
|
+
const types = schema.allOf.map((s: any) => getTypeFromSchema(s, schemaTypeMap, indentLevel));
|
|
308
|
+
const baseType = types.join(' & ');
|
|
309
|
+
return schema.nullable ? `(${baseType}) | null` : baseType;
|
|
310
|
+
}
|
|
311
|
+
|
|
297
312
|
let baseType: string;
|
|
298
313
|
|
|
299
314
|
switch (schema.type) {
|