typed-openapi 2.2.0 → 2.2.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.
|
@@ -1364,7 +1364,7 @@ var generateTanstackQueryFile = async (ctx) => {
|
|
|
1364
1364
|
const endpointMethods = new Set(ctx.endpointList.map((endpoint) => endpoint.method.toLowerCase()));
|
|
1365
1365
|
const file = `
|
|
1366
1366
|
import { queryOptions } from "@tanstack/react-query"
|
|
1367
|
-
import type { EndpointByMethod, ApiClient, SuccessStatusCode, ErrorStatusCode, InferResponseByStatus } from "${ctx.relativeApiClientPath}"
|
|
1367
|
+
import type { EndpointByMethod, ApiClient, SuccessStatusCode, ErrorStatusCode, InferResponseByStatus, TypedSuccessResponse } from "${ctx.relativeApiClientPath}"
|
|
1368
1368
|
import { errorStatusCodes, TypedResponseError } from "${ctx.relativeApiClientPath}"
|
|
1369
1369
|
|
|
1370
1370
|
type EndpointQueryKey<TOptions extends EndpointParameters> = [
|
|
@@ -1416,6 +1416,11 @@ var generateTanstackQueryFile = async (ctx) => {
|
|
|
1416
1416
|
|
|
1417
1417
|
type MaybeOptionalArg<T> = RequiredKeys<T> extends never ? [config?: T] : [config: T];
|
|
1418
1418
|
|
|
1419
|
+
type InferResponseData<TEndpoint, TStatusCode> = TypedSuccessResponse<any, any, any> extends
|
|
1420
|
+
InferResponseByStatus<TEndpoint, TStatusCode>
|
|
1421
|
+
? Extract<InferResponseByStatus<TEndpoint, TStatusCode>, { data: {}}>["data"]
|
|
1422
|
+
: Extract<InferResponseByStatus<TEndpoint, TStatusCode>["data"], {}>;
|
|
1423
|
+
|
|
1419
1424
|
// </ApiClientTypes>
|
|
1420
1425
|
|
|
1421
1426
|
// <ApiClient>
|
|
@@ -1447,7 +1452,7 @@ var generateTanstackQueryFile = async (ctx) => {
|
|
|
1447
1452
|
withResponse: false as const
|
|
1448
1453
|
};
|
|
1449
1454
|
const res = await this.client.${method}(path, requestParams as never);
|
|
1450
|
-
return res as
|
|
1455
|
+
return res as InferResponseData<TEndpoint, SuccessStatusCode>;
|
|
1451
1456
|
},
|
|
1452
1457
|
queryKey: queryKey
|
|
1453
1458
|
}),
|
|
@@ -1471,7 +1476,7 @@ var generateTanstackQueryFile = async (ctx) => {
|
|
|
1471
1476
|
TWithResponse extends boolean = false,
|
|
1472
1477
|
TSelection = TWithResponse extends true
|
|
1473
1478
|
? InferResponseByStatus<TEndpoint, SuccessStatusCode>
|
|
1474
|
-
:
|
|
1479
|
+
: InferResponseData<TEndpoint, SuccessStatusCode>,
|
|
1475
1480
|
TError = TEndpoint extends { responses: infer TResponses }
|
|
1476
1481
|
? TResponses extends Record<string | number, unknown>
|
|
1477
1482
|
? InferResponseByStatus<TEndpoint, ErrorStatusCode>
|
|
@@ -1481,7 +1486,7 @@ var generateTanstackQueryFile = async (ctx) => {
|
|
|
1481
1486
|
withResponse?: TWithResponse;
|
|
1482
1487
|
selectFn?: (res: TWithResponse extends true
|
|
1483
1488
|
? InferResponseByStatus<TEndpoint, SuccessStatusCode>
|
|
1484
|
-
:
|
|
1489
|
+
: InferResponseData<TEndpoint, SuccessStatusCode>
|
|
1485
1490
|
) => TSelection;
|
|
1486
1491
|
throwOnStatusError?: boolean
|
|
1487
1492
|
throwOnError?: boolean | ((error: TError) => boolean)
|
|
@@ -1489,7 +1494,7 @@ var generateTanstackQueryFile = async (ctx) => {
|
|
|
1489
1494
|
const mutationKey = [{ method, path }] as const;
|
|
1490
1495
|
const mutationFn = async <TLocalWithResponse extends boolean = TWithResponse, TLocalSelection = TLocalWithResponse extends true
|
|
1491
1496
|
? InferResponseByStatus<TEndpoint, SuccessStatusCode>
|
|
1492
|
-
:
|
|
1497
|
+
: InferResponseData<TEndpoint, SuccessStatusCode>>
|
|
1493
1498
|
(params: (TEndpoint extends { parameters: infer Parameters } ? Parameters : {}) & {
|
|
1494
1499
|
withResponse?: TLocalWithResponse;
|
|
1495
1500
|
throwOnStatusError?: boolean;
|
package/dist/cli.js
CHANGED
package/dist/index.js
CHANGED
package/dist/node.export.js
CHANGED
package/package.json
CHANGED
|
@@ -12,7 +12,7 @@ export const generateTanstackQueryFile = async (ctx: GeneratorContext & { relati
|
|
|
12
12
|
|
|
13
13
|
const file = `
|
|
14
14
|
import { queryOptions } from "@tanstack/react-query"
|
|
15
|
-
import type { EndpointByMethod, ApiClient, SuccessStatusCode, ErrorStatusCode, InferResponseByStatus } from "${ctx.relativeApiClientPath}"
|
|
15
|
+
import type { EndpointByMethod, ApiClient, SuccessStatusCode, ErrorStatusCode, InferResponseByStatus, TypedSuccessResponse } from "${ctx.relativeApiClientPath}"
|
|
16
16
|
import { errorStatusCodes, TypedResponseError } from "${ctx.relativeApiClientPath}"
|
|
17
17
|
|
|
18
18
|
type EndpointQueryKey<TOptions extends EndpointParameters> = [
|
|
@@ -66,6 +66,11 @@ export const generateTanstackQueryFile = async (ctx: GeneratorContext & { relati
|
|
|
66
66
|
|
|
67
67
|
type MaybeOptionalArg<T> = RequiredKeys<T> extends never ? [config?: T] : [config: T];
|
|
68
68
|
|
|
69
|
+
type InferResponseData<TEndpoint, TStatusCode> = TypedSuccessResponse<any, any, any> extends
|
|
70
|
+
InferResponseByStatus<TEndpoint, TStatusCode>
|
|
71
|
+
? Extract<InferResponseByStatus<TEndpoint, TStatusCode>, { data: {}}>["data"]
|
|
72
|
+
: Extract<InferResponseByStatus<TEndpoint, TStatusCode>["data"], {}>;
|
|
73
|
+
|
|
69
74
|
// </ApiClientTypes>
|
|
70
75
|
|
|
71
76
|
// <ApiClient>
|
|
@@ -98,7 +103,7 @@ export const generateTanstackQueryFile = async (ctx: GeneratorContext & { relati
|
|
|
98
103
|
withResponse: false as const
|
|
99
104
|
};
|
|
100
105
|
const res = await this.client.${method}(path, requestParams as never);
|
|
101
|
-
return res as
|
|
106
|
+
return res as InferResponseData<TEndpoint, SuccessStatusCode>;
|
|
102
107
|
},
|
|
103
108
|
queryKey: queryKey
|
|
104
109
|
}),
|
|
@@ -123,7 +128,7 @@ export const generateTanstackQueryFile = async (ctx: GeneratorContext & { relati
|
|
|
123
128
|
TWithResponse extends boolean = false,
|
|
124
129
|
TSelection = TWithResponse extends true
|
|
125
130
|
? InferResponseByStatus<TEndpoint, SuccessStatusCode>
|
|
126
|
-
:
|
|
131
|
+
: InferResponseData<TEndpoint, SuccessStatusCode>,
|
|
127
132
|
TError = TEndpoint extends { responses: infer TResponses }
|
|
128
133
|
? TResponses extends Record<string | number, unknown>
|
|
129
134
|
? InferResponseByStatus<TEndpoint, ErrorStatusCode>
|
|
@@ -133,7 +138,7 @@ export const generateTanstackQueryFile = async (ctx: GeneratorContext & { relati
|
|
|
133
138
|
withResponse?: TWithResponse;
|
|
134
139
|
selectFn?: (res: TWithResponse extends true
|
|
135
140
|
? InferResponseByStatus<TEndpoint, SuccessStatusCode>
|
|
136
|
-
:
|
|
141
|
+
: InferResponseData<TEndpoint, SuccessStatusCode>
|
|
137
142
|
) => TSelection;
|
|
138
143
|
throwOnStatusError?: boolean
|
|
139
144
|
throwOnError?: boolean | ((error: TError) => boolean)
|
|
@@ -141,7 +146,7 @@ export const generateTanstackQueryFile = async (ctx: GeneratorContext & { relati
|
|
|
141
146
|
const mutationKey = [{ method, path }] as const;
|
|
142
147
|
const mutationFn = async <TLocalWithResponse extends boolean = TWithResponse, TLocalSelection = TLocalWithResponse extends true
|
|
143
148
|
? InferResponseByStatus<TEndpoint, SuccessStatusCode>
|
|
144
|
-
:
|
|
149
|
+
: InferResponseData<TEndpoint, SuccessStatusCode>>
|
|
145
150
|
(params: (TEndpoint extends { parameters: infer Parameters } ? Parameters : {}) & {
|
|
146
151
|
withResponse?: TLocalWithResponse;
|
|
147
152
|
throwOnStatusError?: boolean;
|