@bitstack/ng-query-codegen-openapi 0.0.31-alpha.0 → 0.0.31-alpha.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/lib/bin/cli.mjs +21 -16
- package/lib/bin/cli.mjs.map +1 -1
- package/lib/index.d.mts +5 -0
- package/lib/index.d.ts +5 -0
- package/lib/index.js +13 -20
- package/lib/index.js.map +1 -1
- package/lib/index.mjs +13 -20
- package/lib/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/generators/common-types-generator.ts +2 -2
- package/src/generators/rtk-enhance-endpoints-generator.ts +17 -17
- package/src/types.ts +5 -0
package/lib/index.d.mts
CHANGED
|
@@ -127,6 +127,11 @@ interface CommonOptions {
|
|
|
127
127
|
* File path for importing IRestFulEndpointsQueryReturn type
|
|
128
128
|
*/
|
|
129
129
|
endpointsQueryReturnTypeFile?: string;
|
|
130
|
+
/**
|
|
131
|
+
* defaults to 60 (seconds)
|
|
132
|
+
* Number of seconds to wait before refetching data when component mounts or args change
|
|
133
|
+
*/
|
|
134
|
+
refetchOnMountOrArgChange?: number;
|
|
130
135
|
}
|
|
131
136
|
type TextMatcher = string | RegExp | (string | RegExp)[];
|
|
132
137
|
type EndpointMatcherFunction = (operationName: string, operationDefinition: OperationDefinition) => boolean;
|
package/lib/index.d.ts
CHANGED
|
@@ -127,6 +127,11 @@ interface CommonOptions {
|
|
|
127
127
|
* File path for importing IRestFulEndpointsQueryReturn type
|
|
128
128
|
*/
|
|
129
129
|
endpointsQueryReturnTypeFile?: string;
|
|
130
|
+
/**
|
|
131
|
+
* defaults to 60 (seconds)
|
|
132
|
+
* Number of seconds to wait before refetching data when component mounts or args change
|
|
133
|
+
*/
|
|
134
|
+
refetchOnMountOrArgChange?: number;
|
|
130
135
|
}
|
|
131
136
|
type TextMatcher = string | RegExp | (string | RegExp)[];
|
|
132
137
|
type EndpointMatcherFunction = (operationName: string, operationDefinition: OperationDefinition) => boolean;
|
package/lib/index.js
CHANGED
|
@@ -491,12 +491,12 @@ export interface QueryConfig {
|
|
|
491
491
|
keepUnusedDataFor?: number,
|
|
492
492
|
}
|
|
493
493
|
|
|
494
|
-
export interface IRequestConfig extends RequestOptions {
|
|
494
|
+
export interface IRequestConfig extends RequestOptions {
|
|
495
495
|
timeout?: number;
|
|
496
496
|
}
|
|
497
497
|
|
|
498
498
|
export type IRestFulEndpointsQueryReturn<TVariables> = TVariables extends void ?
|
|
499
|
-
void | {fetchOptions?: IRequestConfig;}:
|
|
499
|
+
(void | {fetchOptions?: IRequestConfig;}):
|
|
500
500
|
{
|
|
501
501
|
variables: TVariables;
|
|
502
502
|
fetchOptions?: IRequestConfig;
|
|
@@ -1005,7 +1005,7 @@ function generateRtkEnhanceEndpointsFile(endpointInfos, options) {
|
|
|
1005
1005
|
return `/* eslint-disable */
|
|
1006
1006
|
// [Warning] Generated automatically - do not edit manually
|
|
1007
1007
|
|
|
1008
|
-
import { ${httpClient.
|
|
1008
|
+
import { ${httpClient.importReturnTypeName} } from '${httpClient.file}';
|
|
1009
1009
|
import { Injectable, inject } from '@angular/core';
|
|
1010
1010
|
import { Observable } from 'rxjs';
|
|
1011
1011
|
import { ${apiConfiguration.importName} } from '${apiConfiguration.file}';
|
|
@@ -1018,7 +1018,7 @@ import {${endpointInfos.map((info) => ` ${info.argTypeName}, ${info.responseType
|
|
|
1018
1018
|
})
|
|
1019
1019
|
export class ${apiServiceClassName} {
|
|
1020
1020
|
private config = inject(${apiConfiguration.importName});
|
|
1021
|
-
private http = inject(${httpClient.
|
|
1021
|
+
private http = inject(${httpClient.importReturnTypeName});
|
|
1022
1022
|
|
|
1023
1023
|
${endpointInfos.map((info) => {
|
|
1024
1024
|
const isGet = info.verb.toUpperCase() === "GET";
|
|
@@ -1036,17 +1036,16 @@ ${endpointInfos.map((info) => {
|
|
|
1036
1036
|
const hasQueryParams = info.queryParams.length > 0;
|
|
1037
1037
|
const hasBody = !isGet && hasArgs;
|
|
1038
1038
|
const generateRequestOptions = () => {
|
|
1039
|
-
|
|
1040
|
-
if (
|
|
1041
|
-
|
|
1039
|
+
let paramsSection = "";
|
|
1040
|
+
if (info.queryParams && info.queryParams.length > 0) {
|
|
1041
|
+
const paramsLines = info.queryParams.map((param) => `${param.name}: args.variables.${param.name},`).join("\n");
|
|
1042
|
+
paramsSection = `params: {${paramsLines}},`;
|
|
1042
1043
|
}
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
}
|
|
1049
|
-
return options2.length > 0 ? `{ ${options2.join(", ")} }` : "{}";
|
|
1044
|
+
return `{
|
|
1045
|
+
...args.fetchOptions,
|
|
1046
|
+
headers: { 'Content-Type': '${info.contentType}', ...args.fetchOptions?.headers },
|
|
1047
|
+
${paramsSection}${info.hasRequestBody ? `body: args.variables.body,` : ""}
|
|
1048
|
+
}`;
|
|
1050
1049
|
};
|
|
1051
1050
|
return `
|
|
1052
1051
|
/**
|
|
@@ -1062,12 +1061,6 @@ ${endpointInfos.map((info) => {
|
|
|
1062
1061
|
}
|
|
1063
1062
|
`;
|
|
1064
1063
|
}
|
|
1065
|
-
function generateQueryParams(queryParams) {
|
|
1066
|
-
const paramEntries = queryParams.map(
|
|
1067
|
-
(param) => `${param.name}: args.variables.${param.name}`
|
|
1068
|
-
).join(", ");
|
|
1069
|
-
return `params: withoutUndefined({ ${paramEntries} })`;
|
|
1070
|
-
}
|
|
1071
1064
|
|
|
1072
1065
|
// src/services/api-code-generator.ts
|
|
1073
1066
|
var ApiCodeGenerator = class {
|