typed-openapi 2.2.1 → 2.2.2

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.
@@ -5,7 +5,7 @@ import {
5
5
  generateFile,
6
6
  generateTanstackQueryFile,
7
7
  mapOpenApiEndpoints
8
- } from "./chunk-ISAFCW3H.js";
8
+ } from "./chunk-L5G4LNMY.js";
9
9
  import {
10
10
  prettify
11
11
  } from "./chunk-KAEXXJ7X.js";
@@ -668,18 +668,18 @@ type NotNever<T> = [T] extends [never] ? false : true;
668
668
  const infer = inferByRuntime[ctx.runtime];
669
669
  const InferTEndpoint = match(ctx.runtime).with("zod", "yup", () => infer(`TEndpoint`)).with("arktype", "io-ts", "typebox", "valibot", () => infer(`TEndpoint`)).otherwise(() => `TEndpoint`);
670
670
  const apiClient = `
671
- // <TypedResponseError>
672
- export class TypedResponseError extends Error {
673
- response: TypedErrorResponse<unknown, ErrorStatusCode, unknown>;
671
+ // <TypedStatusError>
672
+ export class TypedStatusError<TData = unknown> extends Error {
673
+ response: TypedErrorResponse<TData, ErrorStatusCode, unknown>;
674
674
  status: number;
675
- constructor(response: TypedErrorResponse<unknown, ErrorStatusCode, unknown>) {
675
+ constructor(response: TypedErrorResponse<TData, ErrorStatusCode, unknown>) {
676
676
  super(\`HTTP \${response.status}: \${response.statusText}\`);
677
- this.name = 'TypedResponseError';
677
+ this.name = 'TypedStatusError';
678
678
  this.response = response;
679
679
  this.status = response.status;
680
680
  }
681
681
  }
682
- // </TypedResponseError>
682
+ // </TypedStatusError>
683
683
 
684
684
  // <ApiClient>
685
685
  export class ApiClient {
@@ -851,7 +851,7 @@ export class ApiClient {
851
851
  }) as SafeApiResponse<TEndpoint>;
852
852
 
853
853
  if (throwOnStatusError && errorStatusCodes.includes(response.status as never)) {
854
- throw new TypedResponseError(typedResponse as never);
854
+ throw new TypedStatusError(typedResponse as never);
855
855
  }
856
856
 
857
857
  return withResponse ? typedResponse : data;
@@ -1365,7 +1365,7 @@ var generateTanstackQueryFile = async (ctx) => {
1365
1365
  const file = `
1366
1366
  import { queryOptions } from "@tanstack/react-query"
1367
1367
  import type { EndpointByMethod, ApiClient, SuccessStatusCode, ErrorStatusCode, InferResponseByStatus, TypedSuccessResponse } from "${ctx.relativeApiClientPath}"
1368
- import { errorStatusCodes, TypedResponseError } from "${ctx.relativeApiClientPath}"
1368
+ import { errorStatusCodes, TypedStatusError } from "${ctx.relativeApiClientPath}"
1369
1369
 
1370
1370
  type EndpointQueryKey<TOptions extends EndpointParameters> = [
1371
1371
  TOptions & {
@@ -1479,7 +1479,7 @@ var generateTanstackQueryFile = async (ctx) => {
1479
1479
  : InferResponseData<TEndpoint, SuccessStatusCode>,
1480
1480
  TError = TEndpoint extends { responses: infer TResponses }
1481
1481
  ? TResponses extends Record<string | number, unknown>
1482
- ? InferResponseByStatus<TEndpoint, ErrorStatusCode>
1482
+ ? TypedStatusError<InferResponseData<TEndpoint, ErrorStatusCode>>
1483
1483
  : Error
1484
1484
  : Error
1485
1485
  >(method: TMethod, path: TPath, options?: {
@@ -1492,15 +1492,11 @@ var generateTanstackQueryFile = async (ctx) => {
1492
1492
  throwOnError?: boolean | ((error: TError) => boolean)
1493
1493
  }) {
1494
1494
  const mutationKey = [{ method, path }] as const;
1495
- const mutationFn = async <TLocalWithResponse extends boolean = TWithResponse, TLocalSelection = TLocalWithResponse extends true
1496
- ? InferResponseByStatus<TEndpoint, SuccessStatusCode>
1497
- : InferResponseData<TEndpoint, SuccessStatusCode>>
1498
- (params: (TEndpoint extends { parameters: infer Parameters } ? Parameters : {}) & {
1499
- withResponse?: TLocalWithResponse;
1495
+ const mutationFn = async (params: (TEndpoint extends { parameters: infer Parameters } ? Parameters : {}) & {
1500
1496
  throwOnStatusError?: boolean;
1501
1497
  overrides?: RequestInit;
1502
- }): Promise<TLocalSelection> => {
1503
- const withResponse = params.withResponse ??options?.withResponse ?? false;
1498
+ }): Promise<TSelection> => {
1499
+ const withResponse = options?.withResponse ?? false;
1504
1500
  const throwOnStatusError = params.throwOnStatusError ?? options?.throwOnStatusError ?? (withResponse ? false : true);
1505
1501
  const selectFn = options?.selectFn;
1506
1502
  const response = await (this.client as any)[method](path, {
@@ -1510,7 +1506,7 @@ var generateTanstackQueryFile = async (ctx) => {
1510
1506
  });
1511
1507
 
1512
1508
  if (throwOnStatusError && errorStatusCodes.includes(response.status as never)) {
1513
- throw new TypedResponseError(response as never);
1509
+ throw new TypedStatusError(response as never);
1514
1510
  }
1515
1511
 
1516
1512
  // Return just the data if withResponse is false, otherwise return the full response
@@ -1531,8 +1527,8 @@ var generateTanstackQueryFile = async (ctx) => {
1531
1527
  TSelection,
1532
1528
  TError,
1533
1529
  (TEndpoint extends { parameters: infer Parameters } ? Parameters : {}) & {
1534
- withResponse?: boolean;
1535
- throwOnStatusError?: boolean;
1530
+ withResponse?: boolean;
1531
+ throwOnStatusError?: boolean;
1536
1532
  }
1537
1533
  >, "mutationFn"> & {
1538
1534
  mutationFn: typeof mutationFn
package/dist/cli.js CHANGED
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  generateClientFiles
3
- } from "./chunk-TC2ECJEG.js";
3
+ } from "./chunk-4VZOXNI4.js";
4
4
  import {
5
5
  allowedRuntimes
6
- } from "./chunk-ISAFCW3H.js";
6
+ } from "./chunk-L5G4LNMY.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-ISAFCW3H.js";
11
+ } from "./chunk-L5G4LNMY.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-TC2ECJEG.js";
4
- import "./chunk-ISAFCW3H.js";
3
+ } from "./chunk-4VZOXNI4.js";
4
+ import "./chunk-L5G4LNMY.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.1",
4
+ "version": "2.2.2",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",
7
7
  "exports": {
package/src/generator.ts CHANGED
@@ -424,18 +424,18 @@ type NotNever<T> = [T] extends [never] ? false : true;
424
424
  .otherwise(() => `TEndpoint`);
425
425
 
426
426
  const apiClient = `
427
- // <TypedResponseError>
428
- export class TypedResponseError extends Error {
429
- response: TypedErrorResponse<unknown, ErrorStatusCode, unknown>;
427
+ // <TypedStatusError>
428
+ export class TypedStatusError<TData = unknown> extends Error {
429
+ response: TypedErrorResponse<TData, ErrorStatusCode, unknown>;
430
430
  status: number;
431
- constructor(response: TypedErrorResponse<unknown, ErrorStatusCode, unknown>) {
431
+ constructor(response: TypedErrorResponse<TData, ErrorStatusCode, unknown>) {
432
432
  super(\`HTTP \${response.status}: \${response.statusText}\`);
433
- this.name = 'TypedResponseError';
433
+ this.name = 'TypedStatusError';
434
434
  this.response = response;
435
435
  this.status = response.status;
436
436
  }
437
437
  }
438
- // </TypedResponseError>
438
+ // </TypedStatusError>
439
439
 
440
440
  // <ApiClient>
441
441
  export class ApiClient {
@@ -612,7 +612,7 @@ export class ApiClient {
612
612
  }) as SafeApiResponse<TEndpoint>;
613
613
 
614
614
  if (throwOnStatusError && errorStatusCodes.includes(response.status as never)) {
615
- throw new TypedResponseError(typedResponse as never);
615
+ throw new TypedStatusError(typedResponse as never);
616
616
  }
617
617
 
618
618
  return withResponse ? typedResponse : data;
@@ -13,7 +13,7 @@ export const generateTanstackQueryFile = async (ctx: GeneratorContext & { relati
13
13
  const file = `
14
14
  import { queryOptions } from "@tanstack/react-query"
15
15
  import type { EndpointByMethod, ApiClient, SuccessStatusCode, ErrorStatusCode, InferResponseByStatus, TypedSuccessResponse } from "${ctx.relativeApiClientPath}"
16
- import { errorStatusCodes, TypedResponseError } from "${ctx.relativeApiClientPath}"
16
+ import { errorStatusCodes, TypedStatusError } from "${ctx.relativeApiClientPath}"
17
17
 
18
18
  type EndpointQueryKey<TOptions extends EndpointParameters> = [
19
19
  TOptions & {
@@ -131,7 +131,7 @@ export const generateTanstackQueryFile = async (ctx: GeneratorContext & { relati
131
131
  : InferResponseData<TEndpoint, SuccessStatusCode>,
132
132
  TError = TEndpoint extends { responses: infer TResponses }
133
133
  ? TResponses extends Record<string | number, unknown>
134
- ? InferResponseByStatus<TEndpoint, ErrorStatusCode>
134
+ ? TypedStatusError<InferResponseData<TEndpoint, ErrorStatusCode>>
135
135
  : Error
136
136
  : Error
137
137
  >(method: TMethod, path: TPath, options?: {
@@ -144,15 +144,11 @@ export const generateTanstackQueryFile = async (ctx: GeneratorContext & { relati
144
144
  throwOnError?: boolean | ((error: TError) => boolean)
145
145
  }) {
146
146
  const mutationKey = [{ method, path }] as const;
147
- const mutationFn = async <TLocalWithResponse extends boolean = TWithResponse, TLocalSelection = TLocalWithResponse extends true
148
- ? InferResponseByStatus<TEndpoint, SuccessStatusCode>
149
- : InferResponseData<TEndpoint, SuccessStatusCode>>
150
- (params: (TEndpoint extends { parameters: infer Parameters } ? Parameters : {}) & {
151
- withResponse?: TLocalWithResponse;
147
+ const mutationFn = async (params: (TEndpoint extends { parameters: infer Parameters } ? Parameters : {}) & {
152
148
  throwOnStatusError?: boolean;
153
149
  overrides?: RequestInit;
154
- }): Promise<TLocalSelection> => {
155
- const withResponse = params.withResponse ??options?.withResponse ?? false;
150
+ }): Promise<TSelection> => {
151
+ const withResponse = options?.withResponse ?? false;
156
152
  const throwOnStatusError = params.throwOnStatusError ?? options?.throwOnStatusError ?? (withResponse ? false : true);
157
153
  const selectFn = options?.selectFn;
158
154
  const response = await (this.client as any)[method](path, {
@@ -162,7 +158,7 @@ export const generateTanstackQueryFile = async (ctx: GeneratorContext & { relati
162
158
  });
163
159
 
164
160
  if (throwOnStatusError && errorStatusCodes.includes(response.status as never)) {
165
- throw new TypedResponseError(response as never);
161
+ throw new TypedStatusError(response as never);
166
162
  }
167
163
 
168
164
  // Return just the data if withResponse is false, otherwise return the full response
@@ -183,8 +179,8 @@ export const generateTanstackQueryFile = async (ctx: GeneratorContext & { relati
183
179
  TSelection,
184
180
  TError,
185
181
  (TEndpoint extends { parameters: infer Parameters } ? Parameters : {}) & {
186
- withResponse?: boolean;
187
- throwOnStatusError?: boolean;
182
+ withResponse?: boolean;
183
+ throwOnStatusError?: boolean;
188
184
  }
189
185
  >, "mutationFn"> & {
190
186
  mutationFn: typeof mutationFn