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 Extract<InferResponseByStatus<TEndpoint, SuccessStatusCode>, { data: {} }>["data"];
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
- : Extract<InferResponseByStatus<TEndpoint, SuccessStatusCode>, { data: {} }>["data"],
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
- : Extract<InferResponseByStatus<TEndpoint, SuccessStatusCode>, { data: {} }>["data"]
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
- : Extract<InferResponseByStatus<TEndpoint, SuccessStatusCode>, { data: {} }>["data"]>
1497
+ : InferResponseData<TEndpoint, SuccessStatusCode>>
1493
1498
  (params: (TEndpoint extends { parameters: infer Parameters } ? Parameters : {}) & {
1494
1499
  withResponse?: TLocalWithResponse;
1495
1500
  throwOnStatusError?: boolean;
@@ -5,7 +5,7 @@ import {
5
5
  generateFile,
6
6
  generateTanstackQueryFile,
7
7
  mapOpenApiEndpoints
8
- } from "./chunk-QGMS7IBQ.js";
8
+ } from "./chunk-ISAFCW3H.js";
9
9
  import {
10
10
  prettify
11
11
  } from "./chunk-KAEXXJ7X.js";
package/dist/cli.js CHANGED
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  generateClientFiles
3
- } from "./chunk-IB6GEWS7.js";
3
+ } from "./chunk-TC2ECJEG.js";
4
4
  import {
5
5
  allowedRuntimes
6
- } from "./chunk-QGMS7IBQ.js";
6
+ } from "./chunk-ISAFCW3H.js";
7
7
  import "./chunk-KAEXXJ7X.js";
8
8
 
9
9
  // src/cli.ts
package/dist/index.js CHANGED
@@ -8,7 +8,7 @@ import {
8
8
  openApiSchemaToTs,
9
9
  tsFactory,
10
10
  unwrap
11
- } from "./chunk-QGMS7IBQ.js";
11
+ } from "./chunk-ISAFCW3H.js";
12
12
  import "./chunk-KAEXXJ7X.js";
13
13
  export {
14
14
  createBoxFactory,
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  generateClientFiles
3
- } from "./chunk-IB6GEWS7.js";
4
- import "./chunk-QGMS7IBQ.js";
3
+ } from "./chunk-TC2ECJEG.js";
4
+ import "./chunk-ISAFCW3H.js";
5
5
  import "./chunk-KAEXXJ7X.js";
6
6
  export {
7
7
  generateClientFiles
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "typed-openapi",
3
3
  "type": "module",
4
- "version": "2.2.0",
4
+ "version": "2.2.1",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",
7
7
  "exports": {
@@ -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 Extract<InferResponseByStatus<TEndpoint, SuccessStatusCode>, { data: {} }>["data"];
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
- : Extract<InferResponseByStatus<TEndpoint, SuccessStatusCode>, { data: {} }>["data"],
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
- : Extract<InferResponseByStatus<TEndpoint, SuccessStatusCode>, { data: {} }>["data"]
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
- : Extract<InferResponseByStatus<TEndpoint, SuccessStatusCode>, { data: {} }>["data"]>
149
+ : InferResponseData<TEndpoint, SuccessStatusCode>>
145
150
  (params: (TEndpoint extends { parameters: infer Parameters } ? Parameters : {}) & {
146
151
  withResponse?: TLocalWithResponse;
147
152
  throwOnStatusError?: boolean;