typedapi-client-helpers 0.3.0 → 0.3.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.
- package/CHANGELOG.md +71 -68
- package/README.md +24 -15
- package/dist/cjs/index.js +0 -4
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/utils/handleApiResponse.js +19 -7
- package/dist/cjs/utils/handleApiResponse.js.map +1 -1
- package/dist/esm/index.js +0 -4
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/utils/handleApiResponse.js +18 -7
- package/dist/esm/utils/handleApiResponse.js.map +1 -1
- package/dist/types/index.d.ts +0 -4
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/interfaces/ApiResult.d.ts +10 -1
- package/dist/types/interfaces/ApiResult.d.ts.map +1 -1
- package/dist/types/types/ApiMethodOptions.d.ts +2 -2
- package/dist/types/types/ApiMethodOptions.d.ts.map +1 -1
- package/dist/types/utils/handleApiResponse.d.ts +4 -2
- package/dist/types/utils/handleApiResponse.d.ts.map +1 -1
- package/package.json +2 -1
- package/scripts/generate-api-minimal.mjs +30 -1
- package/scripts/openapi-generator/index.mjs +7 -35
- package/scripts/openapi-generator/method-template.mjs +379 -397
- package/scripts/openapi-generator/openapi-utils.mjs +411 -411
- package/scripts/openapi-generator/schema.mjs +581 -735
- package/dist/cjs/types/ApiMethodArguments.js +0 -3
- package/dist/cjs/types/ApiMethodArguments.js.map +0 -1
- package/dist/cjs/types/HttpResponse.js +0 -3
- package/dist/cjs/types/HttpResponse.js.map +0 -1
- package/dist/cjs/utils/extractArgsCallbacksAndParams.js +0 -51
- package/dist/cjs/utils/extractArgsCallbacksAndParams.js.map +0 -1
- package/dist/cjs/utils/extractArgsToastsAndParams.js +0 -49
- package/dist/cjs/utils/extractArgsToastsAndParams.js.map +0 -1
- package/dist/cjs/utils/wireMapping.js +0 -123
- package/dist/cjs/utils/wireMapping.js.map +0 -1
- package/dist/esm/types/ApiMethodArguments.js +0 -2
- package/dist/esm/types/ApiMethodArguments.js.map +0 -1
- package/dist/esm/types/HttpResponse.js +0 -2
- package/dist/esm/types/HttpResponse.js.map +0 -1
- package/dist/esm/utils/extractArgsCallbacksAndParams.js +0 -48
- package/dist/esm/utils/extractArgsCallbacksAndParams.js.map +0 -1
- package/dist/esm/utils/extractArgsToastsAndParams.js +0 -46
- package/dist/esm/utils/extractArgsToastsAndParams.js.map +0 -1
- package/dist/esm/utils/wireMapping.js +0 -119
- package/dist/esm/utils/wireMapping.js.map +0 -1
- package/dist/types/types/ApiMethodArguments.d.ts +0 -6
- package/dist/types/types/ApiMethodArguments.d.ts.map +0 -1
- package/dist/types/types/HttpResponse.d.ts +0 -2
- package/dist/types/types/HttpResponse.d.ts.map +0 -1
- package/dist/types/utils/extractArgsCallbacksAndParams.d.ts +0 -22
- package/dist/types/utils/extractArgsCallbacksAndParams.d.ts.map +0 -1
- package/dist/types/utils/extractArgsToastsAndParams.d.ts +0 -20
- package/dist/types/utils/extractArgsToastsAndParams.d.ts.map +0 -1
- package/dist/types/utils/wireMapping.d.ts +0 -30
- package/dist/types/utils/wireMapping.d.ts.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,68 +1,71 @@
|
|
|
1
|
-
# Changelog
|
|
2
|
-
|
|
3
|
-
All notable changes to `typedapi-client-helpers` are documented in this file.
|
|
4
|
-
|
|
5
|
-
## [0.3.0] - 2026-07-10
|
|
6
|
-
|
|
7
|
-
### Added
|
|
8
|
-
|
|
9
|
-
* Added serializer-aware wire mapping through `toWireValue()` and `fromWireValue()`.
|
|
10
|
-
* Added support for exact OpenAPI property names in JSON bodies, multipart forms, query parameters, headers, cookies, path parameters, responses, and documented error bodies.
|
|
11
|
-
* Added support for path, query, header, cookie, and request-body inputs in the same operation.
|
|
12
|
-
* Added typed unions for documented non-success response bodies.
|
|
13
|
-
* Added structured client errors for network failures, aborted requests, and malformed responses.
|
|
14
|
-
* Added
|
|
15
|
-
* Added support for `
|
|
16
|
-
* Added
|
|
17
|
-
* Added
|
|
18
|
-
* Added controller-
|
|
19
|
-
* Added
|
|
20
|
-
* Added
|
|
21
|
-
* Added
|
|
22
|
-
* Added
|
|
23
|
-
* Added
|
|
24
|
-
* Added
|
|
25
|
-
* Added
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
* Generated
|
|
31
|
-
*
|
|
32
|
-
* Missing operation IDs
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
* Generated
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
*
|
|
51
|
-
* Added
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
-
*
|
|
56
|
-
* Fixed
|
|
57
|
-
* Fixed
|
|
58
|
-
* Fixed
|
|
59
|
-
* Fixed
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
*
|
|
66
|
-
*
|
|
67
|
-
*
|
|
68
|
-
*
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to `typedapi-client-helpers` are documented in this file.
|
|
4
|
+
|
|
5
|
+
## [0.3.0] - 2026-07-10
|
|
6
|
+
|
|
7
|
+
### Added
|
|
8
|
+
|
|
9
|
+
* Added serializer-aware wire mapping through `toWireValue()` and `fromWireValue()`.
|
|
10
|
+
* Added support for exact OpenAPI property names in JSON bodies, multipart forms, query parameters, headers, cookies, path parameters, responses, and documented error bodies.
|
|
11
|
+
* Added support for path, query, header, cookie, and request-body inputs in the same operation.
|
|
12
|
+
* Added typed unions for documented non-success response bodies.
|
|
13
|
+
* Added structured client errors for network failures, aborted requests, and malformed responses.
|
|
14
|
+
* Added `ApiHttpError` for operations without a documented OpenAPI error schema.
|
|
15
|
+
* Added support for local OpenAPI `$ref` values in schemas, parameters, path items, request bodies, and responses.
|
|
16
|
+
* Added support for `allOf` schemas with additional local properties.
|
|
17
|
+
* Added configurable frontend method naming through `typedApiMethodNameStyle`.
|
|
18
|
+
* Added `typedApiPrefixMethodNamesWithController` for controller-prefixed action names.
|
|
19
|
+
* Added controller-name fallback detection from TypedApi metadata, OpenAPI tags, and route paths.
|
|
20
|
+
* Added `--check`, `--strict`, `--offline`, and `--verbose` generator modes.
|
|
21
|
+
* Added configurable Swagger download timeouts.
|
|
22
|
+
* Added global and per-request timeout support.
|
|
23
|
+
* Added support for external `AbortSignal` values and combined cancellation signals.
|
|
24
|
+
* Added header and cookie utilities through `mergeHeaders()`, `toRequestHeaders()`, and `toCookieHeader()`.
|
|
25
|
+
* Added automated generator and runtime tests.
|
|
26
|
+
|
|
27
|
+
### Changed
|
|
28
|
+
|
|
29
|
+
* Generated TypeScript property names now lowercase only the first character while preserving the remainder of the OpenAPI name.
|
|
30
|
+
* Generated operation IDs and TypeScript identifiers are validated and sanitized before files are written.
|
|
31
|
+
* Missing operation IDs now cause a clear error by default.
|
|
32
|
+
* Missing operation IDs can optionally be generated with `typedApiGenerateMissingOperationIds`.
|
|
33
|
+
* Action-based names can include the controller name by default, preventing collisions between actions with the same name in different controllers.
|
|
34
|
+
* Controller prefixes are not duplicated when an action name already begins with the controller name.
|
|
35
|
+
* Generated method signatures now keep non-body parameters, request bodies, and request options in predictable argument groups.
|
|
36
|
+
* Generated methods now use `ApiHttpError` instead of `unknown` when no backend error schema is documented.
|
|
37
|
+
* Generated API output no longer contains a root `index.ts`; methods and contracts are imported directly from their generated files.
|
|
38
|
+
* Body-only operations now accept their payload directly without an additional request wrapper.
|
|
39
|
+
* Query-only and paginated operations now use more specific generated query types.
|
|
40
|
+
* Documented backend errors are returned alongside structured TypedApi client errors.
|
|
41
|
+
* Malformed JSON is now returned as a structured parse error instead of being cast to the expected response type.
|
|
42
|
+
* Exceptions thrown by consumer `onSuccess` and `onError` callbacks now propagate normally.
|
|
43
|
+
* Fetch header merging now uses the native `Headers` implementation.
|
|
44
|
+
* File, Blob, FormData, and multipart handling is safer in SSR and Node.js environments.
|
|
45
|
+
* Binary image, PDF, and octet-stream responses are handled as blobs.
|
|
46
|
+
* The package build now uses a deterministic TypeScript-only ESM, CommonJS, and declaration build instead of a bundler-dependent build.
|
|
47
|
+
|
|
48
|
+
### Fixed
|
|
49
|
+
|
|
50
|
+
* Fixed generated-output replacement failures caused by transient Windows filesystem locks.
|
|
51
|
+
* Added retries for filesystem errors encountered while replacing generated output.
|
|
52
|
+
* Added rollback-protected managed-file synchronization when `src/api` cannot be renamed because an editor, TypeScript watcher, antivirus scanner, or development server holds a directory handle.
|
|
53
|
+
* Preserved unmanaged files during fallback synchronization.
|
|
54
|
+
* Removed stale TypedApi-generated files during fallback synchronization.
|
|
55
|
+
* Removed previously generated root `index.ts` files during regeneration.
|
|
56
|
+
* Fixed handling of cancel token `0`.
|
|
57
|
+
* Fixed abort-controller cleanup after completed requests.
|
|
58
|
+
* Fixed URLs that already contain query strings.
|
|
59
|
+
* Fixed absolute URL handling.
|
|
60
|
+
* Fixed duplicate generated method and type names after TypeScript normalization.
|
|
61
|
+
* Fixed property-name collisions caused by first-character normalization.
|
|
62
|
+
|
|
63
|
+
### Migration notes
|
|
64
|
+
|
|
65
|
+
* OpenAPI 3.x is now required. Swagger 2.0 documents are rejected.
|
|
66
|
+
* Regenerated method names, parameter types, property names, and method signatures may differ from version `0.2.1`.
|
|
67
|
+
* Projects using `typedApiMethodNameStyle: "action"` receive controller-prefixed names by default.
|
|
68
|
+
* Set `typedApiPrefixMethodNamesWithController` to `false` to generate action-only names.
|
|
69
|
+
* Set `typedApiGenerateMissingOperationIds` to `true` only when operation IDs cannot be supplied by the backend.
|
|
70
|
+
* Import methods from `src/api/methods/*.api.ts` and contracts from `src/api/generated/data-contracts.ts` instead of using `src/api/index.ts`.
|
|
71
|
+
* Regenerate and review committed API files after upgrading; regeneration removes the old generated root `index.ts`.
|
package/README.md
CHANGED
|
@@ -4,14 +4,15 @@ A small Fetch runtime and OpenAPI 3 TypeScript generator designed to work with `
|
|
|
4
4
|
|
|
5
5
|
## Version 0.3 highlights
|
|
6
6
|
|
|
7
|
-
- Lowercases only the first character of generated TypeScript members
|
|
7
|
+
- Lowercases only the first character of generated TypeScript members.
|
|
8
8
|
- Sanitizes operation IDs and rejects duplicates before writing output.
|
|
9
9
|
- Can name frontend functions from either the unique OpenAPI operation ID or the original ASP.NET controller action name.
|
|
10
10
|
- Supports path, query, header, cookie, and request-body inputs in the same operation.
|
|
11
11
|
- Resolves local OpenAPI references for schemas, parameters, request bodies, and responses.
|
|
12
12
|
- Supports `allOf` composition with local properties.
|
|
13
13
|
- Generates typed unions for documented non-success responses.
|
|
14
|
-
-
|
|
14
|
+
- Uses a structured `ApiHttpError` when an operation has no documented error schema.
|
|
15
|
+
- Generates API contracts and controller method files without creating a root API barrel file.
|
|
15
16
|
- Writes generated output transactionally, with a Windows-safe in-place fallback when directory renames are blocked by editors or file watchers.
|
|
16
17
|
- Adds `--check`, `--strict`, `--offline`, and `--verbose` CLI modes.
|
|
17
18
|
- Improves cancellation, timeouts, header merging, SSR safety, and malformed-response handling.
|
|
@@ -60,13 +61,18 @@ src/api/
|
|
|
60
61
|
├── generated/
|
|
61
62
|
│ ├── data-contracts.ts
|
|
62
63
|
│ └── http-client.ts
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
├── index.ts
|
|
66
|
-
└── typedapi.manifest.json
|
|
64
|
+
└── methods/
|
|
65
|
+
└── Products.api.ts
|
|
67
66
|
```
|
|
68
67
|
|
|
69
|
-
The
|
|
68
|
+
The generator intentionally does not create `src/api/index.ts`. Import generated methods and contracts directly from their files:
|
|
69
|
+
|
|
70
|
+
```ts
|
|
71
|
+
import { getProducts } from "./api/methods/Product.api";
|
|
72
|
+
import type { ProductModel } from "./api/generated/data-contracts";
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
When upgrading from an earlier 0.3.0 build, the next generation removes the old generated `src/api/index.ts`. The Swagger backup belongs to the consuming project, not this npm package.
|
|
70
76
|
|
|
71
77
|
## Frontend method names
|
|
72
78
|
|
|
@@ -150,8 +156,8 @@ The generated signature is:
|
|
|
150
156
|
export async function updateWarehouse(
|
|
151
157
|
pathParams: UpdateWarehouseParams,
|
|
152
158
|
data: WarehouseRequest,
|
|
153
|
-
options: ApiMethodOptions<WarehouseModel,
|
|
154
|
-
): Promise<ApiResult<WarehouseModel,
|
|
159
|
+
options: ApiMethodOptions<WarehouseModel, ApiHttpError, RequestParams> = {},
|
|
160
|
+
): Promise<ApiResult<WarehouseModel, ApiHttpError>>;
|
|
155
161
|
```
|
|
156
162
|
|
|
157
163
|
Path operations without a body use only the params object:
|
|
@@ -184,15 +190,18 @@ await updateWarehouse(pathParams, data, {
|
|
|
184
190
|
|
|
185
191
|
## Typed errors
|
|
186
192
|
|
|
187
|
-
When the OpenAPI document describes error response bodies, generated methods expose their union
|
|
193
|
+
When the OpenAPI document describes error response bodies, generated methods expose their generated type or union. When no error schema is documented, the method uses `ApiHttpError` instead of `unknown`:
|
|
188
194
|
|
|
189
195
|
```ts
|
|
190
|
-
const result = await
|
|
196
|
+
const result = await cancelOrder({ id, reason });
|
|
191
197
|
|
|
192
198
|
if (!result.ok) {
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
199
|
+
if (result.error.kind === "http") {
|
|
200
|
+
console.error(result.error.status, result.error.body);
|
|
201
|
+
} else {
|
|
202
|
+
// Structured TypedApi client error: network, aborted, or parse.
|
|
203
|
+
console.error(result.error);
|
|
204
|
+
}
|
|
196
205
|
}
|
|
197
206
|
```
|
|
198
207
|
|
|
@@ -214,7 +223,7 @@ configureApiClient({
|
|
|
214
223
|
setSecurityData("access-token");
|
|
215
224
|
```
|
|
216
225
|
|
|
217
|
-
The runtime also exports `createApiClient`, `request`, `abortRequest`, `mergeHeaders`, `toRequestHeaders`, `toCookieHeader`, `handleApiResponse`, `buildQuery`, `toFormData
|
|
226
|
+
The runtime also exports `createApiClient`, `request`, `abortRequest`, `mergeHeaders`, `toRequestHeaders`, `toCookieHeader`, `handleApiResponse`, `buildQuery`, `toFormData`.
|
|
218
227
|
|
|
219
228
|
## Backend pairing
|
|
220
229
|
|
package/dist/cjs/index.js
CHANGED
|
@@ -21,12 +21,8 @@ __exportStar(require("./interfaces/SortType"), exports);
|
|
|
21
21
|
__exportStar(require("./types/ApiMethodTypes"), exports);
|
|
22
22
|
__exportStar(require("./types/ApiCallOptions"), exports);
|
|
23
23
|
__exportStar(require("./types/ApiMethodOptions"), exports);
|
|
24
|
-
__exportStar(require("./types/ApiMethodArguments"), exports);
|
|
25
24
|
__exportStar(require("./utils/buildQuery"), exports);
|
|
26
|
-
__exportStar(require("./utils/extractArgsToastsAndParams"), exports);
|
|
27
|
-
__exportStar(require("./utils/extractArgsCallbacksAndParams"), exports);
|
|
28
25
|
__exportStar(require("./utils/handleApiResponse"), exports);
|
|
29
26
|
__exportStar(require("./utils/SortTypeFromSortDirection"), exports);
|
|
30
27
|
__exportStar(require("./utils/toFormData"), exports);
|
|
31
|
-
__exportStar(require("./utils/wireMapping"), exports);
|
|
32
28
|
//# sourceMappingURL=index.js.map
|
package/dist/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,+CAA6B;AAE7B,yDAAuC;AACvC,sDAAoC;AACpC,wDAAsC;AAEtC,yDAAuC;AACvC,yDAAuC;AACvC,2DAAyC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,+CAA6B;AAE7B,yDAAuC;AACvC,sDAAoC;AACpC,wDAAsC;AAEtC,yDAAuC;AACvC,yDAAuC;AACvC,2DAAyC;AAEzC,qDAAmC;AACnC,4DAA0C;AAC1C,oEAAkD;AAClD,qDAAmC"}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createApiHttpError = createApiHttpError;
|
|
3
4
|
exports.handleApiResponse = handleApiResponse;
|
|
5
|
+
const defaultUnknownErrorMessage = "An unknown error occurred.";
|
|
4
6
|
class ResponseParseError extends Error {
|
|
5
7
|
constructor(status, rawBody, parseCause) {
|
|
6
8
|
super(`Could not parse JSON response with status ${status}.`);
|
|
@@ -40,7 +42,14 @@ function isResponseLike(value) {
|
|
|
40
42
|
"headers" in value &&
|
|
41
43
|
typeof value.text === "function");
|
|
42
44
|
}
|
|
43
|
-
function
|
|
45
|
+
function createApiHttpError(status, body) {
|
|
46
|
+
return {
|
|
47
|
+
kind: "http",
|
|
48
|
+
status,
|
|
49
|
+
body: body,
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
function clientError(error, fallbackErrorMessage) {
|
|
44
53
|
if (error instanceof ResponseParseError) {
|
|
45
54
|
return {
|
|
46
55
|
kind: "parse",
|
|
@@ -55,7 +64,7 @@ function clientError(error) {
|
|
|
55
64
|
if (name === "AbortError" || name === "TimeoutError") {
|
|
56
65
|
return { kind: "aborted", cause: error };
|
|
57
66
|
}
|
|
58
|
-
return
|
|
67
|
+
return fallbackErrorMessage ?? defaultUnknownErrorMessage;
|
|
59
68
|
}
|
|
60
69
|
async function handleApiResponse(call, options) {
|
|
61
70
|
let result;
|
|
@@ -77,7 +86,7 @@ async function handleApiResponse(call, options) {
|
|
|
77
86
|
ok: false,
|
|
78
87
|
status: response.status,
|
|
79
88
|
response: undefined,
|
|
80
|
-
error: clientError(error),
|
|
89
|
+
error: clientError(error, options?.fallbackErrorMessage),
|
|
81
90
|
};
|
|
82
91
|
}
|
|
83
92
|
}
|
|
@@ -85,9 +94,12 @@ async function handleApiResponse(call, options) {
|
|
|
85
94
|
if (isResponseLike(error)) {
|
|
86
95
|
try {
|
|
87
96
|
const rawErrorData = await readResponseBody(error.clone());
|
|
88
|
-
const
|
|
89
|
-
? options.transformError(rawErrorData)
|
|
97
|
+
const transformedError = options?.transformError
|
|
98
|
+
? options.transformError(rawErrorData, error)
|
|
90
99
|
: rawErrorData;
|
|
100
|
+
const errorData = transformedError === undefined
|
|
101
|
+
? options?.fallbackErrorMessage ?? defaultUnknownErrorMessage
|
|
102
|
+
: transformedError;
|
|
91
103
|
result = {
|
|
92
104
|
ok: false,
|
|
93
105
|
status: error.status,
|
|
@@ -100,7 +112,7 @@ async function handleApiResponse(call, options) {
|
|
|
100
112
|
ok: false,
|
|
101
113
|
status: error.status,
|
|
102
114
|
response: undefined,
|
|
103
|
-
error: clientError(parseError),
|
|
115
|
+
error: clientError(parseError, options?.fallbackErrorMessage),
|
|
104
116
|
};
|
|
105
117
|
}
|
|
106
118
|
}
|
|
@@ -109,7 +121,7 @@ async function handleApiResponse(call, options) {
|
|
|
109
121
|
ok: false,
|
|
110
122
|
status: 0,
|
|
111
123
|
response: undefined,
|
|
112
|
-
error: clientError(error),
|
|
124
|
+
error: clientError(error, options?.fallbackErrorMessage),
|
|
113
125
|
};
|
|
114
126
|
}
|
|
115
127
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handleApiResponse.js","sourceRoot":"","sources":["../../../src/utils/handleApiResponse.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"handleApiResponse.js","sourceRoot":"","sources":["../../../src/utils/handleApiResponse.ts"],"names":[],"mappings":";;AAgEA,gDAMC;AAwBD,8CAkEC;AA5JD,MAAM,0BAA0B,GAAG,4BAA4B,CAAC;AAUhE,MAAM,kBAAmB,SAAQ,KAAK;IACpC,YACW,MAAc,EACd,OAAe,EACf,UAAmB;QAE5B,KAAK,CAAC,6CAA6C,MAAM,GAAG,CAAC,CAAC;QAJrD,WAAM,GAAN,MAAM,CAAQ;QACd,YAAO,GAAP,OAAO,CAAQ;QAC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E,KAAK;gBACT,MAAM,EAAE,CAAC;gBACT,QAAQ,EAAE,SAAS;gBACnB,KAAK,EAAE,WAAW,CAAC,KAAK,EAAE,OAAO,EAAE,oBAAoB,CAAC;aACzD,CAAC;QACJ,CAAC;IACH,CAAC;IAED,+EAA+E;IAC/E,uFAAuF;IACvF,IAAI,MAAM,CAAC,EAAE;QAAE,MAAM,OAAO,EAAE,SAAS,EAAE,CAAC,MAAM,CAAC,CAAC;;QAC7C,MAAM,OAAO,EAAE,OAAO,EAAE,CAAC,MAAM,CAAC,CAAC;IAEtC,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
package/dist/esm/index.js
CHANGED
|
@@ -5,12 +5,8 @@ export * from "./interfaces/SortType.js";
|
|
|
5
5
|
export * from "./types/ApiMethodTypes.js";
|
|
6
6
|
export * from "./types/ApiCallOptions.js";
|
|
7
7
|
export * from "./types/ApiMethodOptions.js";
|
|
8
|
-
export * from "./types/ApiMethodArguments.js";
|
|
9
8
|
export * from "./utils/buildQuery.js";
|
|
10
|
-
export * from "./utils/extractArgsToastsAndParams.js";
|
|
11
|
-
export * from "./utils/extractArgsCallbacksAndParams.js";
|
|
12
9
|
export * from "./utils/handleApiResponse.js";
|
|
13
10
|
export * from "./utils/SortTypeFromSortDirection.js";
|
|
14
11
|
export * from "./utils/toFormData.js";
|
|
15
|
-
export * from "./utils/wireMapping.js";
|
|
16
12
|
//# sourceMappingURL=index.js.map
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAE7B,cAAc,wBAAwB,CAAC;AACvC,cAAc,qBAAqB,CAAC;AACpC,cAAc,uBAAuB,CAAC;AAEtC,cAAc,wBAAwB,CAAC;AACvC,cAAc,wBAAwB,CAAC;AACvC,cAAc,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAE7B,cAAc,wBAAwB,CAAC;AACvC,cAAc,qBAAqB,CAAC;AACpC,cAAc,uBAAuB,CAAC;AAEtC,cAAc,wBAAwB,CAAC;AACvC,cAAc,wBAAwB,CAAC;AACvC,cAAc,0BAA0B,CAAC;AAEzC,cAAc,oBAAoB,CAAC;AACnC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,mCAAmC,CAAC;AAClD,cAAc,oBAAoB,CAAC"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
const defaultUnknownErrorMessage = "An unknown error occurred.";
|
|
1
2
|
class ResponseParseError extends Error {
|
|
2
3
|
constructor(status, rawBody, parseCause) {
|
|
3
4
|
super(`Could not parse JSON response with status ${status}.`);
|
|
@@ -37,7 +38,14 @@ function isResponseLike(value) {
|
|
|
37
38
|
"headers" in value &&
|
|
38
39
|
typeof value.text === "function");
|
|
39
40
|
}
|
|
40
|
-
function
|
|
41
|
+
export function createApiHttpError(status, body) {
|
|
42
|
+
return {
|
|
43
|
+
kind: "http",
|
|
44
|
+
status,
|
|
45
|
+
body: body,
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
function clientError(error, fallbackErrorMessage) {
|
|
41
49
|
if (error instanceof ResponseParseError) {
|
|
42
50
|
return {
|
|
43
51
|
kind: "parse",
|
|
@@ -52,7 +60,7 @@ function clientError(error) {
|
|
|
52
60
|
if (name === "AbortError" || name === "TimeoutError") {
|
|
53
61
|
return { kind: "aborted", cause: error };
|
|
54
62
|
}
|
|
55
|
-
return
|
|
63
|
+
return fallbackErrorMessage ?? defaultUnknownErrorMessage;
|
|
56
64
|
}
|
|
57
65
|
export async function handleApiResponse(call, options) {
|
|
58
66
|
let result;
|
|
@@ -74,7 +82,7 @@ export async function handleApiResponse(call, options) {
|
|
|
74
82
|
ok: false,
|
|
75
83
|
status: response.status,
|
|
76
84
|
response: undefined,
|
|
77
|
-
error: clientError(error),
|
|
85
|
+
error: clientError(error, options?.fallbackErrorMessage),
|
|
78
86
|
};
|
|
79
87
|
}
|
|
80
88
|
}
|
|
@@ -82,9 +90,12 @@ export async function handleApiResponse(call, options) {
|
|
|
82
90
|
if (isResponseLike(error)) {
|
|
83
91
|
try {
|
|
84
92
|
const rawErrorData = await readResponseBody(error.clone());
|
|
85
|
-
const
|
|
86
|
-
? options.transformError(rawErrorData)
|
|
93
|
+
const transformedError = options?.transformError
|
|
94
|
+
? options.transformError(rawErrorData, error)
|
|
87
95
|
: rawErrorData;
|
|
96
|
+
const errorData = transformedError === undefined
|
|
97
|
+
? options?.fallbackErrorMessage ?? defaultUnknownErrorMessage
|
|
98
|
+
: transformedError;
|
|
88
99
|
result = {
|
|
89
100
|
ok: false,
|
|
90
101
|
status: error.status,
|
|
@@ -97,7 +108,7 @@ export async function handleApiResponse(call, options) {
|
|
|
97
108
|
ok: false,
|
|
98
109
|
status: error.status,
|
|
99
110
|
response: undefined,
|
|
100
|
-
error: clientError(parseError),
|
|
111
|
+
error: clientError(parseError, options?.fallbackErrorMessage),
|
|
101
112
|
};
|
|
102
113
|
}
|
|
103
114
|
}
|
|
@@ -106,7 +117,7 @@ export async function handleApiResponse(call, options) {
|
|
|
106
117
|
ok: false,
|
|
107
118
|
status: 0,
|
|
108
119
|
response: undefined,
|
|
109
|
-
error: clientError(error),
|
|
120
|
+
error: clientError(error, options?.fallbackErrorMessage),
|
|
110
121
|
};
|
|
111
122
|
}
|
|
112
123
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handleApiResponse.js","sourceRoot":"","sources":["../../../src/utils/handleApiResponse.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"handleApiResponse.js","sourceRoot":"","sources":["../../../src/utils/handleApiResponse.ts"],"names":[],"mappings":"AAIA,MAAM,0BAA0B,GAAG,4BAA4B,CAAC;AAUhE,MAAM,kBAAmB,SAAQ,KAAK;IACpC,YACW,MAAc,EACd,OAAe,EACf,UAAmB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,WAAW,CAAC,UAAU,EAAE,OAAO,EAAE,oBAAoB,CAAC;iBAC9D,CAAC;YACJ,CAAC;QACH,CAAC;aAAM,CAAC;YACN,MAAM,GAAG;gBACP,EAAE,EAAE,KAAK;gBACT,MAAM,EAAE,CAAC;gBACT,QAAQ,EAAE,SAAS;gBACnB,KAAK,EAAE,WAAW,CAAC,KAAK,EAAE,OAAO,EAAE,oBAAoB,CAAC;aACzD,CAAC;QACJ,CAAC;IACH,CAAC;IAED,+EAA+E;IAC/E,uFAAuF;IACvF,IAAI,MAAM,CAAC,EAAE;QAAE,MAAM,OAAO,EAAE,SAAS,EAAE,CAAC,MAAM,CAAC,CAAC;;QAC7C,MAAM,OAAO,EAAE,OAAO,EAAE,CAAC,MAAM,CAAC,CAAC;IAEtC,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -5,12 +5,8 @@ export * from "./interfaces/SortType";
|
|
|
5
5
|
export * from "./types/ApiMethodTypes";
|
|
6
6
|
export * from "./types/ApiCallOptions";
|
|
7
7
|
export * from "./types/ApiMethodOptions";
|
|
8
|
-
export * from "./types/ApiMethodArguments";
|
|
9
8
|
export * from "./utils/buildQuery";
|
|
10
|
-
export * from "./utils/extractArgsToastsAndParams";
|
|
11
|
-
export * from "./utils/extractArgsCallbacksAndParams";
|
|
12
9
|
export * from "./utils/handleApiResponse";
|
|
13
10
|
export * from "./utils/SortTypeFromSortDirection";
|
|
14
11
|
export * from "./utils/toFormData";
|
|
15
|
-
export * from "./utils/wireMapping";
|
|
16
12
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAE7B,cAAc,wBAAwB,CAAC;AACvC,cAAc,qBAAqB,CAAC;AACpC,cAAc,uBAAuB,CAAC;AAEtC,cAAc,wBAAwB,CAAC;AACvC,cAAc,wBAAwB,CAAC;AACvC,cAAc,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAE7B,cAAc,wBAAwB,CAAC;AACvC,cAAc,qBAAqB,CAAC;AACpC,cAAc,uBAAuB,CAAC;AAEtC,cAAc,wBAAwB,CAAC;AACvC,cAAc,wBAAwB,CAAC;AACvC,cAAc,0BAA0B,CAAC;AAEzC,cAAc,oBAAoB,CAAC;AACnC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,mCAAmC,CAAC;AAClD,cAAc,oBAAoB,CAAC"}
|
|
@@ -1,3 +1,12 @@
|
|
|
1
|
+
export type ApiHttpErrorBody = string | number | boolean | null | Blob | undefined | ApiHttpErrorBody[] | {
|
|
2
|
+
[key: string]: ApiHttpErrorBody;
|
|
3
|
+
};
|
|
4
|
+
/** An HTTP error response without a documented OpenAPI error schema. */
|
|
5
|
+
export type ApiHttpError = {
|
|
6
|
+
kind: "http";
|
|
7
|
+
status: number;
|
|
8
|
+
body: ApiHttpErrorBody;
|
|
9
|
+
};
|
|
1
10
|
/** Errors created by the TypedApi runtime before a typed HTTP error body is available. */
|
|
2
11
|
export type ApiClientError = {
|
|
3
12
|
kind: "network";
|
|
@@ -21,7 +30,7 @@ export type ApiResult<TResponse, TError = unknown> = {
|
|
|
21
30
|
ok: false;
|
|
22
31
|
status: number;
|
|
23
32
|
response?: undefined;
|
|
24
|
-
error: TError | ApiClientError;
|
|
33
|
+
error: TError | ApiClientError | string;
|
|
25
34
|
};
|
|
26
35
|
export type ApiSuccessResult<TResponse, TError = unknown> = Extract<ApiResult<TResponse, TError>, {
|
|
27
36
|
ok: true;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ApiResult.d.ts","sourceRoot":"","sources":["../../../src/interfaces/ApiResult.ts"],"names":[],"mappings":"AAAA,0FAA0F;AAC1F,MAAM,MAAM,cAAc,GACtB;IACE,IAAI,EAAE,SAAS,CAAC;IAChB,KAAK,EAAE,OAAO,CAAC;CAChB,GACD;IACE,IAAI,EAAE,SAAS,CAAC;IAChB,KAAK,EAAE,OAAO,CAAC;CAChB,GACD;IACE,IAAI,EAAE,OAAO,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,OAAO,CAAC;CAChB,CAAC;AAEN,yEAAyE;AACzE,MAAM,MAAM,SAAS,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,IAC7C;IACE,EAAE,EAAE,IAAI,CAAC;IACT,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,SAAS,CAAC;IACpB,KAAK,CAAC,EAAE,KAAK,CAAC;CACf,GACD;IACE,EAAE,EAAE,KAAK,CAAC;IACV,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,SAAS,CAAC;IACrB,KAAK,EAAE,MAAM,GAAG,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"ApiResult.d.ts","sourceRoot":"","sources":["../../../src/interfaces/ApiResult.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,gBAAgB,GACxB,MAAM,GACN,MAAM,GACN,OAAO,GACP,IAAI,GACJ,IAAI,GACJ,SAAS,GACT,gBAAgB,EAAE,GAClB;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,gBAAgB,CAAA;CAAE,CAAC;AAExC,wEAAwE;AACxE,MAAM,MAAM,YAAY,GAAG;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,gBAAgB,CAAC;CACxB,CAAC;AAEF,0FAA0F;AAC1F,MAAM,MAAM,cAAc,GACtB;IACE,IAAI,EAAE,SAAS,CAAC;IAChB,KAAK,EAAE,OAAO,CAAC;CAChB,GACD;IACE,IAAI,EAAE,SAAS,CAAC;IAChB,KAAK,EAAE,OAAO,CAAC;CAChB,GACD;IACE,IAAI,EAAE,OAAO,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,OAAO,CAAC;CAChB,CAAC;AAEN,yEAAyE;AACzE,MAAM,MAAM,SAAS,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,IAC7C;IACE,EAAE,EAAE,IAAI,CAAC;IACT,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,SAAS,CAAC;IACpB,KAAK,CAAC,EAAE,KAAK,CAAC;CACf,GACD;IACE,EAAE,EAAE,KAAK,CAAC;IACV,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,SAAS,CAAC;IACrB,KAAK,EAAE,MAAM,GAAG,cAAc,GAAG,MAAM,CAAC;CACzC,CAAC;AAEN,MAAM,MAAM,gBAAgB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,IAAI,OAAO,CACjE,SAAS,CAAC,SAAS,EAAE,MAAM,CAAC,EAC5B;IAAE,EAAE,EAAE,IAAI,CAAA;CAAE,CACb,CAAC;AAEF,MAAM,MAAM,cAAc,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,IAAI,OAAO,CAC/D,SAAS,CAAC,SAAS,EAAE,MAAM,CAAC,EAC5B;IAAE,EAAE,EAAE,KAAK,CAAA;CAAE,CACd,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ApiErrorHandler, ApiSuccessHandler } from "./ApiCallOptions";
|
|
2
|
-
import { RuntimeRequestParams } from "./
|
|
1
|
+
import type { ApiErrorHandler, ApiSuccessHandler } from "./ApiCallOptions";
|
|
2
|
+
import type { RuntimeRequestParams } from "./httpClientTypes";
|
|
3
3
|
export type ApiMethodOptions<TResponse, TError = unknown, TRequestParams = RuntimeRequestParams> = {
|
|
4
4
|
onSuccess?: ApiSuccessHandler<TResponse>;
|
|
5
5
|
onError?: ApiErrorHandler<TResponse, TError>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ApiMethodOptions.d.ts","sourceRoot":"","sources":["../../../src/types/ApiMethodOptions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"ApiMethodOptions.d.ts","sourceRoot":"","sources":["../../../src/types/ApiMethodOptions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAC3E,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAE9D,MAAM,MAAM,gBAAgB,CAC1B,SAAS,EACT,MAAM,GAAG,OAAO,EAChB,cAAc,GAAG,oBAAoB,IACnC;IACF,SAAS,CAAC,EAAE,iBAAiB,CAAC,SAAS,CAAC,CAAC;IACzC,OAAO,CAAC,EAAE,eAAe,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;IAC7C,MAAM,CAAC,EAAE,cAAc,CAAC;CACzB,CAAC"}
|
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
import type { ApiResult } from "../interfaces/ApiResult";
|
|
1
|
+
import type { ApiHttpError, ApiResult } from "../interfaces/ApiResult";
|
|
2
2
|
import type { ApiErrorHandler, ApiSuccessHandler } from "../types/ApiCallOptions";
|
|
3
3
|
import type { HttpResponse } from "../httpClient";
|
|
4
4
|
export type HandleApiResponseOptions<TResponse, TError = unknown> = {
|
|
5
5
|
onSuccess?: ApiSuccessHandler<TResponse>;
|
|
6
6
|
onError?: ApiErrorHandler<TResponse, TError>;
|
|
7
7
|
transformResponse?: (value: unknown) => TResponse;
|
|
8
|
-
transformError?: (value: unknown) => TError;
|
|
8
|
+
transformError?: (value: unknown, response: Response) => TError;
|
|
9
|
+
fallbackErrorMessage?: string;
|
|
9
10
|
};
|
|
11
|
+
export declare function createApiHttpError(status: number, body: unknown): ApiHttpError;
|
|
10
12
|
export declare function handleApiResponse<TResponse, TError = unknown>(call: () => Promise<HttpResponse<TResponse, TError>>, options?: HandleApiResponseOptions<TResponse, TError>): Promise<ApiResult<TResponse, TError>>;
|
|
11
13
|
//# sourceMappingURL=handleApiResponse.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handleApiResponse.d.ts","sourceRoot":"","sources":["../../../src/utils/handleApiResponse.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAkB,SAAS,EAAE,MAAM,yBAAyB,CAAC;
|
|
1
|
+
{"version":3,"file":"handleApiResponse.d.ts","sourceRoot":"","sources":["../../../src/utils/handleApiResponse.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAkB,YAAY,EAAoB,SAAS,EAAE,MAAM,yBAAyB,CAAC;AACzG,OAAO,KAAK,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAClF,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAIlD,MAAM,MAAM,wBAAwB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,IAAI;IAClE,SAAS,CAAC,EAAE,iBAAiB,CAAC,SAAS,CAAC,CAAC;IACzC,OAAO,CAAC,EAAE,eAAe,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;IAC7C,iBAAiB,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,SAAS,CAAC;IAClD,cAAc,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,QAAQ,KAAK,MAAM,CAAC;IAChE,oBAAoB,CAAC,EAAE,MAAM,CAAC;CAC/B,CAAC;AAoDF,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,GAAG,YAAY,CAM9E;AAwBD,wBAAsB,iBAAiB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,EACjE,IAAI,EAAE,MAAM,OAAO,CAAC,YAAY,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC,EACpD,OAAO,CAAC,EAAE,wBAAwB,CAAC,SAAS,EAAE,MAAM,CAAC,GACpD,OAAO,CAAC,SAAS,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC,CA+DvC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "typedapi-client-helpers",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.2",
|
|
4
4
|
"description": "Reusable typed OpenAPI client helpers.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"keywords": [
|
|
@@ -66,6 +66,7 @@
|
|
|
66
66
|
"typedApiDefaultFunctionsPath": "src/defaultApiFunctions",
|
|
67
67
|
"typedApiDefaultSuccessHandler": "handleGoodResult",
|
|
68
68
|
"typedApiDefaultErrorHandler": "handleErrors",
|
|
69
|
+
"typedApiDefaultErrorMessage": "unknownErrorMessage",
|
|
69
70
|
"typedApiDefaultResponseAsSuccess": false,
|
|
70
71
|
"typedApiGenerateUnionEnums": false,
|
|
71
72
|
"typedApiEnumNamesAsValues": false,
|