@mittwald/api-client-commons 4.3.0 → 4.4.0-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/dist/axios.d.ts +1 -0
- package/dist/axios.js +1 -0
- package/dist/core/ApiClientBase.d.ts +9 -0
- package/dist/core/ApiClientBase.js +13 -0
- package/dist/core/ApiClientError.d.ts +7 -0
- package/dist/core/ApiClientError.js +12 -0
- package/dist/core/OpenAPIPath.d.ts +9 -0
- package/dist/core/OpenAPIPath.js +20 -0
- package/dist/core/Request.d.ts +13 -0
- package/dist/core/Request.js +76 -0
- package/dist/core/Request.test.d.ts +1 -0
- package/dist/core/Request.test.js +53 -0
- package/dist/core/index.d.ts +4 -0
- package/dist/core/index.js +4 -0
- package/dist/index.d.ts +3 -45
- package/dist/index.js +3 -0
- package/dist/react/ApiCallAsyncResourceFactory.d.ts +12 -0
- package/dist/react/ApiCallAsyncResourceFactory.js +35 -0
- package/dist/react/ApiCallAsyncResourceFactory.test-types.d.ts +1 -0
- package/dist/react/ApiCallAsyncResourceFactory.test-types.js +36 -0
- package/dist/react/ApiCallAsyncResourceFactory.test.d.ts +1 -0
- package/dist/react/ApiCallAsyncResourceFactory.test.js +46 -0
- package/dist/react/index.d.ts +1 -19
- package/dist/react/index.js +1 -0
- package/dist/react/types.d.ts +3 -0
- package/dist/react/types.js +1 -0
- package/dist/types/NullableOnNoRequiredKeysDeep.d.ts +6 -0
- package/dist/types/NullableOnNoRequiredKeysDeep.js +1 -0
- package/dist/types/OpenAPIOperation.d.ts +20 -0
- package/dist/types/OpenAPIOperation.js +1 -0
- package/dist/types/RequestFunction.d.ts +11 -0
- package/dist/types/RequestFunction.js +1 -0
- package/dist/types/RequestFunction.test-types.d.ts +1 -0
- package/dist/types/RequestFunction.test-types.js +29 -0
- package/dist/types/RequestType.d.ts +21 -0
- package/dist/types/RequestType.js +1 -0
- package/dist/types/RequestType.test-types.d.ts +1 -0
- package/dist/types/RequestType.test-types.js +146 -0
- package/dist/types/Response.d.ts +7 -0
- package/dist/types/Response.js +1 -0
- package/dist/types/Response.test-types.d.ts +1 -0
- package/dist/types/Response.test-types.js +70 -0
- package/dist/types/assertStatus.d.ts +5 -0
- package/dist/types/assertStatus.js +7 -0
- package/dist/types/assertStatus.test-types.d.ts +1 -0
- package/dist/types/assertStatus.test-types.js +8 -0
- package/dist/types/http.d.ts +13 -0
- package/dist/types/http.js +1 -0
- package/dist/types/index.d.ts +7 -0
- package/dist/types/index.js +7 -0
- package/dist/types/simplify.d.ts +3 -0
- package/dist/types/simplify.js +1 -0
- package/package.json +24 -26
- package/dist/index.d.mts +0 -45
- package/dist/index.mjs +0 -22
- package/dist/react/index.d.mts +0 -19
- package/dist/react/index.mjs +0 -49
- package/dist/shared/api-client-commons.2a6e3962.mjs +0 -128
- package/dist/shared/api-client-commons.8b686095.d.mts +0 -75
- package/dist/shared/api-client-commons.8b686095.d.ts +0 -75
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import { expectAssignable } from "tsd";
|
|
2
|
+
function ignoredTestEmptyRequestTypes() {
|
|
3
|
+
expectAssignable({});
|
|
4
|
+
// @ts-expect-error Not assignable
|
|
5
|
+
expectAssignable({ extra: true });
|
|
6
|
+
// @ts-expect-error Not assignable
|
|
7
|
+
expectAssignable({ data: {} });
|
|
8
|
+
// @ts-expect-error Not assignable
|
|
9
|
+
expectAssignable({ data: null });
|
|
10
|
+
// @ts-expect-error Not assignable
|
|
11
|
+
expectAssignable({ pathParameters: {} });
|
|
12
|
+
}
|
|
13
|
+
function ignoredTestRequestTypesWithDataType() {
|
|
14
|
+
expectAssignable({ data: { foo: "" } });
|
|
15
|
+
// @ts-expect-error Not assignable
|
|
16
|
+
expectAssignable({});
|
|
17
|
+
expectAssignable({
|
|
18
|
+
// @ts-expect-error Not assignable
|
|
19
|
+
data: { foo: "", extra: "" },
|
|
20
|
+
});
|
|
21
|
+
// @ts-expect-error Not assignable
|
|
22
|
+
expectAssignable({ data: { noFoo: "" } });
|
|
23
|
+
}
|
|
24
|
+
function ignoredTestRequestTypesWithPathParameters() {
|
|
25
|
+
expectAssignable({
|
|
26
|
+
data: { foo: "" },
|
|
27
|
+
pathParameters: { bar: "" },
|
|
28
|
+
});
|
|
29
|
+
expectAssignable({
|
|
30
|
+
pathParameters: { bar: "" },
|
|
31
|
+
});
|
|
32
|
+
// @ts-expect-error Not assignable
|
|
33
|
+
expectAssignable({});
|
|
34
|
+
expectAssignable({
|
|
35
|
+
// @ts-expect-error Not assignable
|
|
36
|
+
pathParameters: {},
|
|
37
|
+
});
|
|
38
|
+
expectAssignable({
|
|
39
|
+
// @ts-expect-error Not assignable
|
|
40
|
+
pathParameters: { foo: "", extra: "" },
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
function ignoredTestRequestTypesWithHeader() {
|
|
44
|
+
expectAssignable({
|
|
45
|
+
data: {
|
|
46
|
+
foo: "",
|
|
47
|
+
},
|
|
48
|
+
pathParameters: { bar: "" },
|
|
49
|
+
headers: { baz: "" },
|
|
50
|
+
});
|
|
51
|
+
expectAssignable({
|
|
52
|
+
pathParameters: { bar: "" },
|
|
53
|
+
headers: { baz: "" },
|
|
54
|
+
});
|
|
55
|
+
expectAssignable({
|
|
56
|
+
headers: { baz: "" },
|
|
57
|
+
});
|
|
58
|
+
// @ts-expect-error Not assignable
|
|
59
|
+
expectAssignable({});
|
|
60
|
+
expectAssignable({
|
|
61
|
+
headers: {
|
|
62
|
+
// @ts-expect-error Not assignable
|
|
63
|
+
baz: 42,
|
|
64
|
+
},
|
|
65
|
+
});
|
|
66
|
+
expectAssignable({
|
|
67
|
+
// @ts-expect-error Not assignable
|
|
68
|
+
headers: {},
|
|
69
|
+
});
|
|
70
|
+
expectAssignable({
|
|
71
|
+
// @ts-expect-error Not assignable
|
|
72
|
+
data: {},
|
|
73
|
+
headers: {
|
|
74
|
+
baz: "",
|
|
75
|
+
},
|
|
76
|
+
});
|
|
77
|
+
expectAssignable({
|
|
78
|
+
// @ts-expect-error Not assignable
|
|
79
|
+
pathParameters: {},
|
|
80
|
+
headers: {
|
|
81
|
+
baz: "",
|
|
82
|
+
},
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
function ignoredTestRequestTypesWithQuery() {
|
|
86
|
+
expectAssignable({
|
|
87
|
+
data: {
|
|
88
|
+
foo: "",
|
|
89
|
+
},
|
|
90
|
+
pathParameters: { bar: "" },
|
|
91
|
+
headers: { baz: "" },
|
|
92
|
+
queryParameters: {
|
|
93
|
+
whut: "",
|
|
94
|
+
},
|
|
95
|
+
});
|
|
96
|
+
expectAssignable({
|
|
97
|
+
pathParameters: { bar: "" },
|
|
98
|
+
headers: { baz: "" },
|
|
99
|
+
queryParameters: {
|
|
100
|
+
whut: "",
|
|
101
|
+
},
|
|
102
|
+
});
|
|
103
|
+
expectAssignable({
|
|
104
|
+
queryParameters: {
|
|
105
|
+
whut: "",
|
|
106
|
+
},
|
|
107
|
+
});
|
|
108
|
+
// @ts-expect-error Not assignable
|
|
109
|
+
expectAssignable({});
|
|
110
|
+
expectAssignable({
|
|
111
|
+
queryParameters: {
|
|
112
|
+
// @ts-expect-error Not assignable
|
|
113
|
+
whut: 42,
|
|
114
|
+
},
|
|
115
|
+
});
|
|
116
|
+
expectAssignable({
|
|
117
|
+
// @ts-expect-error Not assignable
|
|
118
|
+
queryParameters: {},
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
function ignoredTestAdditionalHeadersCanAlwaysBeSet() {
|
|
122
|
+
expectAssignable({
|
|
123
|
+
headers: { extra: true },
|
|
124
|
+
});
|
|
125
|
+
expectAssignable({
|
|
126
|
+
headers: { extra: true },
|
|
127
|
+
});
|
|
128
|
+
expectAssignable({
|
|
129
|
+
headers: { extra: true },
|
|
130
|
+
});
|
|
131
|
+
expectAssignable({
|
|
132
|
+
data: {
|
|
133
|
+
foo: "",
|
|
134
|
+
},
|
|
135
|
+
headers: { extra: true },
|
|
136
|
+
});
|
|
137
|
+
expectAssignable({
|
|
138
|
+
pathParameters: {
|
|
139
|
+
bar: "",
|
|
140
|
+
},
|
|
141
|
+
headers: { extra: true },
|
|
142
|
+
});
|
|
143
|
+
expectAssignable({
|
|
144
|
+
headers: { extra: true, baz: "" },
|
|
145
|
+
});
|
|
146
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { HttpMediaType, HttpPayload, HttpStatus } from "./http.js";
|
|
2
|
+
import { AxiosResponse } from "axios";
|
|
3
|
+
export type Response<TContent extends HttpPayload = HttpPayload, TStatus extends HttpStatus = HttpStatus, TMediaType extends HttpMediaType | null = HttpMediaType> = AxiosResponse<TContent> & {
|
|
4
|
+
status: TStatus;
|
|
5
|
+
mediaType: TMediaType;
|
|
6
|
+
};
|
|
7
|
+
export type AnyResponse = Response<any, any, any>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { expectAssignable, expectNotAssignable, expectType } from "tsd";
|
|
2
|
+
const additionalAxiosResponseData = {
|
|
3
|
+
statusText: "",
|
|
4
|
+
headers: {},
|
|
5
|
+
config: {},
|
|
6
|
+
mediaType: "application/json",
|
|
7
|
+
};
|
|
8
|
+
expectAssignable({
|
|
9
|
+
data: { a: "" },
|
|
10
|
+
status: 200,
|
|
11
|
+
...additionalAxiosResponseData,
|
|
12
|
+
});
|
|
13
|
+
expectNotAssignable({
|
|
14
|
+
data: { a: "", extra: "!" },
|
|
15
|
+
status: 200,
|
|
16
|
+
...additionalAxiosResponseData,
|
|
17
|
+
});
|
|
18
|
+
expectAssignable({
|
|
19
|
+
data: {
|
|
20
|
+
b: "",
|
|
21
|
+
},
|
|
22
|
+
status: 201,
|
|
23
|
+
...additionalAxiosResponseData,
|
|
24
|
+
});
|
|
25
|
+
expectAssignable({
|
|
26
|
+
data: null,
|
|
27
|
+
status: 400,
|
|
28
|
+
...additionalAxiosResponseData,
|
|
29
|
+
});
|
|
30
|
+
expectNotAssignable({
|
|
31
|
+
data: null,
|
|
32
|
+
status: 42,
|
|
33
|
+
...additionalAxiosResponseData,
|
|
34
|
+
});
|
|
35
|
+
expectNotAssignable({
|
|
36
|
+
data: null,
|
|
37
|
+
status: 42,
|
|
38
|
+
extra: "!",
|
|
39
|
+
...additionalAxiosResponseData,
|
|
40
|
+
});
|
|
41
|
+
expectNotAssignable({
|
|
42
|
+
data: { extraContent: "" },
|
|
43
|
+
status: 400,
|
|
44
|
+
...additionalAxiosResponseData,
|
|
45
|
+
});
|
|
46
|
+
function ignoredTestRequestTypesWithDataPathParameters() {
|
|
47
|
+
const someResponse = {};
|
|
48
|
+
expectType(someResponse.status);
|
|
49
|
+
if (someResponse.status === 200) {
|
|
50
|
+
// @ts-expect-error > a is not in data
|
|
51
|
+
someResponse.data.a;
|
|
52
|
+
// @ts-expect-error > b is not in data
|
|
53
|
+
someResponse.data.b;
|
|
54
|
+
if (someResponse.mediaType === "text/plain") {
|
|
55
|
+
// @ts-expect-error > a is not in data
|
|
56
|
+
someResponse.data.a;
|
|
57
|
+
expectType(someResponse.data.text);
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
// @ts-expect-error > text is not in data
|
|
61
|
+
someResponse.data.text;
|
|
62
|
+
expectType(someResponse.data.a);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
else if (someResponse.status === 201) {
|
|
66
|
+
expectType(someResponse.data.b);
|
|
67
|
+
// @ts-expect-error > a is not in data
|
|
68
|
+
someResponse.data.a;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import ApiClientError from "../core/ApiClientError.js";
|
|
2
|
+
export function assertStatus(response, expectedStatus) {
|
|
3
|
+
if (response.status !== expectedStatus) {
|
|
4
|
+
throw ApiClientError.fromResponse(`Unexpected response status (expected ${expectedStatus}, got: ${response.status})`, response);
|
|
5
|
+
}
|
|
6
|
+
}
|
|
7
|
+
export default assertStatus;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { expectAssignable } from "tsd";
|
|
2
|
+
import assertStatus from "./assertStatus.js";
|
|
3
|
+
function ignoredTestAssertStatusAssertsAlsoTheCorrectResponseType() {
|
|
4
|
+
assertStatus(someResponse, 200);
|
|
5
|
+
expectAssignable(someResponse);
|
|
6
|
+
// @ts-expect-error Not assignable
|
|
7
|
+
expectAssignable(someResponse);
|
|
8
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export type HttpPayload = unknown;
|
|
2
|
+
export type HttpStatus = number | "default";
|
|
3
|
+
export type HttpMediaType = string;
|
|
4
|
+
type SafeHttpMethod = "GET" | "HEAD" | "OPTIONS";
|
|
5
|
+
type UnsafeHttpMethod = "PUT" | "DELETE" | "POST" | "PATCH";
|
|
6
|
+
export type HttpMethod = SafeHttpMethod | UnsafeHttpMethod;
|
|
7
|
+
type HeaderValue = string | number | boolean;
|
|
8
|
+
export type HttpHeaders = Partial<{
|
|
9
|
+
[TKey: string]: HeaderValue | HeaderValue[];
|
|
10
|
+
}>;
|
|
11
|
+
export type PathParameters = Record<string, string | number>;
|
|
12
|
+
export type QueryParameters = Record<string, unknown>;
|
|
13
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mittwald/api-client-commons",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.4.0-alpha.1",
|
|
4
4
|
"author": "Mittwald CM Service GmbH & Co. KG <opensource@mittwald.de>",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "Common types and utilities for mittwald API clients",
|
|
@@ -17,50 +17,51 @@
|
|
|
17
17
|
"license": "MIT",
|
|
18
18
|
"exports": {
|
|
19
19
|
".": {
|
|
20
|
-
"types": "./dist/index.d.
|
|
21
|
-
"default": "./dist/index.
|
|
20
|
+
"types": "./dist/index.d.ts",
|
|
21
|
+
"default": "./dist/index.js"
|
|
22
22
|
},
|
|
23
23
|
"./react": {
|
|
24
|
-
"types": "./dist/react/index.d.
|
|
25
|
-
"default": "./dist/react/index.
|
|
24
|
+
"types": "./dist/react/index.d.ts",
|
|
25
|
+
"default": "./dist/react/index.js"
|
|
26
26
|
}
|
|
27
27
|
},
|
|
28
28
|
"files": [
|
|
29
29
|
"dist"
|
|
30
30
|
],
|
|
31
31
|
"scripts": {
|
|
32
|
-
"build": "
|
|
33
|
-
"
|
|
34
|
-
"
|
|
32
|
+
"build": "run build:clean && run tsc",
|
|
33
|
+
"build:clean": "rimraf dist",
|
|
34
|
+
"format": "run prettier --write '**/*.{ts,tsx,yaml,yml,json,md,mdx,js}'",
|
|
35
|
+
"lint": "run eslint .",
|
|
35
36
|
"test": "node --experimental-vm-modules $(yarn bin jest)"
|
|
36
37
|
},
|
|
37
38
|
"dependencies": {
|
|
38
39
|
"@types/parse-path": "^7.0.3",
|
|
39
|
-
"axios": "^1.6.
|
|
40
|
+
"axios": "^1.6.7",
|
|
40
41
|
"parse-path": "^7.0.0",
|
|
41
42
|
"path-to-regexp": "^6.2.1",
|
|
42
|
-
"type-fest": "^4.
|
|
43
|
+
"type-fest": "^4.10.3"
|
|
43
44
|
},
|
|
44
45
|
"devDependencies": {
|
|
45
46
|
"@jest/globals": "^29.7.0",
|
|
46
|
-
"@mittwald/react-use-promise": "^2.
|
|
47
|
-
"@types/jest": "^29.5.
|
|
48
|
-
"@typescript-eslint/eslint-plugin": "^
|
|
49
|
-
"@typescript-eslint/parser": "^
|
|
50
|
-
"eslint": "^8.
|
|
51
|
-
"eslint-config-prettier": "^9.
|
|
47
|
+
"@mittwald/react-use-promise": "^2.3.12",
|
|
48
|
+
"@types/jest": "^29.5.12",
|
|
49
|
+
"@typescript-eslint/eslint-plugin": "^7.0.2",
|
|
50
|
+
"@typescript-eslint/parser": "^7.0.2",
|
|
51
|
+
"eslint": "^8.56.0",
|
|
52
|
+
"eslint-config-prettier": "^9.1.0",
|
|
52
53
|
"eslint-plugin-json": "^3.1.0",
|
|
53
|
-
"eslint-plugin-prettier": "^5.
|
|
54
|
+
"eslint-plugin-prettier": "^5.1.3",
|
|
54
55
|
"jest": "^29.7.0",
|
|
55
|
-
"prettier": "^3.
|
|
56
|
-
"prettier-plugin-jsdoc": "^1.
|
|
56
|
+
"prettier": "^3.2.5",
|
|
57
|
+
"prettier-plugin-jsdoc": "^1.3.0",
|
|
57
58
|
"prettier-plugin-pkgsort": "^0.2.1",
|
|
58
59
|
"prettier-plugin-sort-json": "^3.1.0",
|
|
59
60
|
"react": "^18.2.0",
|
|
60
|
-
"
|
|
61
|
-
"
|
|
62
|
-
"
|
|
63
|
-
"
|
|
61
|
+
"rimraf": "^5.0.5",
|
|
62
|
+
"ts-jest": "^29.1.2",
|
|
63
|
+
"tsd": "^0.30.5",
|
|
64
|
+
"typescript": "^5.3.3"
|
|
64
65
|
},
|
|
65
66
|
"peerDependencies": {
|
|
66
67
|
"@mittwald/react-use-promise": "^2.1.0"
|
|
@@ -69,8 +70,5 @@
|
|
|
69
70
|
"@mittwald/react-use-promise": {
|
|
70
71
|
"optional": true
|
|
71
72
|
}
|
|
72
|
-
},
|
|
73
|
-
"unbuild": {
|
|
74
|
-
"declaration": true
|
|
75
73
|
}
|
|
76
74
|
}
|
package/dist/index.d.mts
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { AxiosInstance, CreateAxiosDefaults, AxiosError, InternalAxiosRequestConfig, AxiosResponse, AxiosRequestConfig } from 'axios';
|
|
2
|
-
export * from 'axios';
|
|
3
|
-
import { R as Response, O as OpenAPIOperation, a as RequestFunction, A as AnyResponse, P as PathParameters, b as RequestObject, c as ResponsePromise } from './shared/api-client-commons.8b686095.mjs';
|
|
4
|
-
export { e as AnyRequest, n as HttpHeaders, l as HttpMediaType, m as HttpMethod, H as HttpPayload, k as HttpStatus, h as InferredRequestData, I as InferredRequestType, g as InferredResponseData, f as InferredResponseType, Q as QueryParameters, j as RequestData, d as RequestType, i as ResponseData } from './shared/api-client-commons.8b686095.mjs';
|
|
5
|
-
import 'type-fest';
|
|
6
|
-
|
|
7
|
-
type Simplify<T> = {
|
|
8
|
-
[KeyType in keyof T]: T[KeyType];
|
|
9
|
-
} & {};
|
|
10
|
-
|
|
11
|
-
declare function assertStatus<T extends Response, S extends T["status"]>(response: T, expectedStatus: S): asserts response is T & {
|
|
12
|
-
status: S;
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
declare abstract class ApiClientBase {
|
|
16
|
-
axios: AxiosInstance;
|
|
17
|
-
constructor(axiosConfig?: AxiosInstance | CreateAxiosDefaults);
|
|
18
|
-
protected requestFunctionFactory<TOp extends OpenAPIOperation>(operation: TOp): RequestFunction<TOp>;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
declare class ApiClientError<T = unknown, D = unknown> extends AxiosError<T, D> {
|
|
22
|
-
constructor(message?: string, code?: string, config?: InternalAxiosRequestConfig<D>, request?: unknown, response?: AxiosResponse<T, D>);
|
|
23
|
-
static fromResponse(message: string, response: AnyResponse): ApiClientError;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
declare class OpenAPIPath {
|
|
27
|
-
private readonly rawPath;
|
|
28
|
-
private readonly params?;
|
|
29
|
-
constructor(rawPath: string, params?: PathParameters);
|
|
30
|
-
buildUrl(): string;
|
|
31
|
-
private static setPathParams;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
declare class Request<TOp extends OpenAPIOperation> {
|
|
35
|
-
private readonly operationDescriptor;
|
|
36
|
-
private readonly requestObject?;
|
|
37
|
-
readonly requestConfig: AxiosRequestConfig;
|
|
38
|
-
constructor(operationDescriptor: TOp, requestObject?: RequestObject<TOp>);
|
|
39
|
-
execute(axios: AxiosInstance): ResponsePromise<TOp>;
|
|
40
|
-
private buildAxiosConfig;
|
|
41
|
-
private makeAxiosHeaders;
|
|
42
|
-
private convertQueryToUrlSearchParams;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export { AnyResponse, ApiClientBase, ApiClientError, OpenAPIOperation, OpenAPIPath, PathParameters, Request, RequestFunction, RequestObject, Response, ResponsePromise, type Simplify, assertStatus };
|
package/dist/index.mjs
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import axios__default, { Axios } from 'axios';
|
|
2
|
-
export * from 'axios';
|
|
3
|
-
import { R as Request } from './shared/api-client-commons.2a6e3962.mjs';
|
|
4
|
-
export { A as ApiClientError, O as OpenAPIPath, a as assertStatus } from './shared/api-client-commons.2a6e3962.mjs';
|
|
5
|
-
|
|
6
|
-
var __defProp = Object.defineProperty;
|
|
7
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
-
var __publicField = (obj, key, value) => {
|
|
9
|
-
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
10
|
-
return value;
|
|
11
|
-
};
|
|
12
|
-
class ApiClientBase {
|
|
13
|
-
constructor(axiosConfig = axios__default) {
|
|
14
|
-
__publicField(this, "axios");
|
|
15
|
-
this.axios = axiosConfig instanceof Axios ? axiosConfig : axios__default.create(axiosConfig);
|
|
16
|
-
}
|
|
17
|
-
requestFunctionFactory(operation) {
|
|
18
|
-
return (conf) => new Request(operation, conf).execute(this.axios);
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export { ApiClientBase, Request };
|
package/dist/react/index.d.mts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { O as OpenAPIOperation, b as RequestObject, g as InferredResponseData, a as RequestFunction } from '../shared/api-client-commons.8b686095.mjs';
|
|
2
|
-
import { AsyncResource } from '@mittwald/react-use-promise';
|
|
3
|
-
import 'axios';
|
|
4
|
-
import 'type-fest';
|
|
5
|
-
|
|
6
|
-
type GetApiResourceFn<TOp extends OpenAPIOperation> = null extends RequestObject<TOp> ? (conf?: RequestObject<TOp>) => AsyncResource<InferredResponseData<TOp>> : (conf: RequestObject<TOp>) => AsyncResource<InferredResponseData<TOp>>;
|
|
7
|
-
|
|
8
|
-
declare class ApiCallAsyncResourceFactory<TOp extends OpenAPIOperation> {
|
|
9
|
-
private static namespace;
|
|
10
|
-
private readonly operation;
|
|
11
|
-
private readonly requestFn;
|
|
12
|
-
constructor(operation: TOp, requestFn: RequestFunction<TOp>);
|
|
13
|
-
private getAsyncResourceId;
|
|
14
|
-
private getAsyncResourceTags;
|
|
15
|
-
private executeRequest;
|
|
16
|
-
getApiResource: GetApiResourceFn<TOp>;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export { ApiCallAsyncResourceFactory };
|
package/dist/react/index.mjs
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import { getAsyncResource } from '@mittwald/react-use-promise';
|
|
2
|
-
import { R as Request, a as assertStatus } from '../shared/api-client-commons.2a6e3962.mjs';
|
|
3
|
-
import 'axios';
|
|
4
|
-
|
|
5
|
-
var __defProp = Object.defineProperty;
|
|
6
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
7
|
-
var __publicField = (obj, key, value) => {
|
|
8
|
-
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
9
|
-
return value;
|
|
10
|
-
};
|
|
11
|
-
const _ApiCallAsyncResourceFactory = class _ApiCallAsyncResourceFactory {
|
|
12
|
-
constructor(operation, requestFn) {
|
|
13
|
-
__publicField(this, "operation");
|
|
14
|
-
__publicField(this, "requestFn");
|
|
15
|
-
__publicField(this, "getApiResource", (requestObj) => {
|
|
16
|
-
const request = new Request(this.operation, requestObj);
|
|
17
|
-
return getAsyncResource(
|
|
18
|
-
(requestObj2) => this.executeRequest(requestObj2),
|
|
19
|
-
[requestObj],
|
|
20
|
-
{
|
|
21
|
-
tags: this.getAsyncResourceTags(request),
|
|
22
|
-
loaderId: this.getAsyncResourceId()
|
|
23
|
-
}
|
|
24
|
-
);
|
|
25
|
-
});
|
|
26
|
-
this.operation = operation;
|
|
27
|
-
this.requestFn = requestFn;
|
|
28
|
-
}
|
|
29
|
-
getAsyncResourceId() {
|
|
30
|
-
return `${_ApiCallAsyncResourceFactory.namespace}/${this.operation.operationId}`;
|
|
31
|
-
}
|
|
32
|
-
getAsyncResourceTags(request) {
|
|
33
|
-
const url = request.requestConfig.url ?? "";
|
|
34
|
-
return [
|
|
35
|
-
this.getAsyncResourceId(),
|
|
36
|
-
`${_ApiCallAsyncResourceFactory.namespace}/${this.operation.method}`,
|
|
37
|
-
`${_ApiCallAsyncResourceFactory.namespace}/${url}`
|
|
38
|
-
];
|
|
39
|
-
}
|
|
40
|
-
async executeRequest(requestObj) {
|
|
41
|
-
const response = await this.requestFn(requestObj);
|
|
42
|
-
assertStatus(response, 200);
|
|
43
|
-
return response.data;
|
|
44
|
-
}
|
|
45
|
-
};
|
|
46
|
-
__publicField(_ApiCallAsyncResourceFactory, "namespace", "@mittwald/api-client");
|
|
47
|
-
let ApiCallAsyncResourceFactory = _ApiCallAsyncResourceFactory;
|
|
48
|
-
|
|
49
|
-
export { ApiCallAsyncResourceFactory };
|
|
@@ -1,128 +0,0 @@
|
|
|
1
|
-
import { AxiosError } from 'axios';
|
|
2
|
-
|
|
3
|
-
var __defProp$1 = Object.defineProperty;
|
|
4
|
-
var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
5
|
-
var __publicField$1 = (obj, key, value) => {
|
|
6
|
-
__defNormalProp$1(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
7
|
-
return value;
|
|
8
|
-
};
|
|
9
|
-
class OpenAPIPath {
|
|
10
|
-
constructor(rawPath, params) {
|
|
11
|
-
__publicField$1(this, "rawPath");
|
|
12
|
-
__publicField$1(this, "params");
|
|
13
|
-
this.rawPath = rawPath;
|
|
14
|
-
this.params = params;
|
|
15
|
-
}
|
|
16
|
-
buildUrl() {
|
|
17
|
-
return OpenAPIPath.setPathParams(this.rawPath, this.params);
|
|
18
|
-
}
|
|
19
|
-
static setPathParams(path, params) {
|
|
20
|
-
const asEntries = Object.entries(params ?? {});
|
|
21
|
-
const finalPath = asEntries.reduce((path2, entry) => {
|
|
22
|
-
const [key, value] = entry;
|
|
23
|
-
return path2.replace(`{${key}}`, encodeURIComponent(value));
|
|
24
|
-
}, path);
|
|
25
|
-
return finalPath.startsWith("/") ? finalPath.substring(1) : finalPath;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
var __defProp = Object.defineProperty;
|
|
30
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
31
|
-
var __publicField = (obj, key, value) => {
|
|
32
|
-
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
33
|
-
return value;
|
|
34
|
-
};
|
|
35
|
-
class Request {
|
|
36
|
-
constructor(operationDescriptor, requestObject) {
|
|
37
|
-
__publicField(this, "operationDescriptor");
|
|
38
|
-
__publicField(this, "requestObject");
|
|
39
|
-
__publicField(this, "requestConfig");
|
|
40
|
-
this.operationDescriptor = operationDescriptor;
|
|
41
|
-
this.requestObject = requestObject;
|
|
42
|
-
this.requestConfig = Object.freeze(this.buildAxiosConfig());
|
|
43
|
-
}
|
|
44
|
-
execute(axios) {
|
|
45
|
-
return axios.request(this.requestConfig);
|
|
46
|
-
}
|
|
47
|
-
buildAxiosConfig() {
|
|
48
|
-
const { method, path } = this.operationDescriptor;
|
|
49
|
-
const pathParameters = this.requestObject;
|
|
50
|
-
const openApiPath = new OpenAPIPath(path, pathParameters);
|
|
51
|
-
const url = openApiPath.buildUrl();
|
|
52
|
-
const data = this.requestObject && "data" in this.requestObject ? this.requestObject.data : void 0;
|
|
53
|
-
const headersConfig = this.requestObject && "headers" in this.requestObject ? this.requestObject.headers : void 0;
|
|
54
|
-
const headers = headersConfig ? this.makeAxiosHeaders(headersConfig) : void 0;
|
|
55
|
-
const queryParametersConfig = this.requestObject && "queryParameters" in this.requestObject ? this.requestObject.queryParameters : void 0;
|
|
56
|
-
const params = this.convertQueryToUrlSearchParams(queryParametersConfig);
|
|
57
|
-
return {
|
|
58
|
-
url,
|
|
59
|
-
method,
|
|
60
|
-
headers,
|
|
61
|
-
// Must be a plain object or an URLSearchParams object
|
|
62
|
-
params,
|
|
63
|
-
data,
|
|
64
|
-
validateStatus: () => true
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
makeAxiosHeaders(headers) {
|
|
68
|
-
return Object.fromEntries(
|
|
69
|
-
Object.entries(headers).map(([key, value]) => [key, value?.toString()])
|
|
70
|
-
);
|
|
71
|
-
}
|
|
72
|
-
convertQueryToUrlSearchParams(query) {
|
|
73
|
-
if (query === void 0 || query === null) {
|
|
74
|
-
return void 0;
|
|
75
|
-
}
|
|
76
|
-
if (query instanceof URLSearchParams) {
|
|
77
|
-
return query;
|
|
78
|
-
}
|
|
79
|
-
if (typeof query === "string") {
|
|
80
|
-
return new URLSearchParams(query);
|
|
81
|
-
}
|
|
82
|
-
if (typeof query === "object") {
|
|
83
|
-
const searchParams = new URLSearchParams();
|
|
84
|
-
for (const [key, value] of Object.entries(query)) {
|
|
85
|
-
if (Array.isArray(value)) {
|
|
86
|
-
for (const arrayItem of value) {
|
|
87
|
-
searchParams.append(key, arrayItem);
|
|
88
|
-
}
|
|
89
|
-
} else {
|
|
90
|
-
searchParams.append(
|
|
91
|
-
key,
|
|
92
|
-
typeof value === "string" || typeof value === "number" || typeof value === "boolean" ? value.toString() : JSON.stringify(value)
|
|
93
|
-
);
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
return searchParams;
|
|
97
|
-
}
|
|
98
|
-
throw new Error(`Unexpected query parameter type (${typeof query})`);
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
class ApiClientError extends AxiosError {
|
|
103
|
-
constructor(message, code, config, request, response) {
|
|
104
|
-
super(message, code, config, request, response);
|
|
105
|
-
Object.setPrototypeOf(this, ApiClientError.prototype);
|
|
106
|
-
this.name = "ApiClientError";
|
|
107
|
-
}
|
|
108
|
-
static fromResponse(message, response) {
|
|
109
|
-
return new ApiClientError(
|
|
110
|
-
message,
|
|
111
|
-
void 0,
|
|
112
|
-
response.config,
|
|
113
|
-
response.request,
|
|
114
|
-
response
|
|
115
|
-
);
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
function assertStatus(response, expectedStatus) {
|
|
120
|
-
if (response.status !== expectedStatus) {
|
|
121
|
-
throw ApiClientError.fromResponse(
|
|
122
|
-
`Unexpected response status (expected ${expectedStatus}, got: ${response.status})`,
|
|
123
|
-
response
|
|
124
|
-
);
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
export { ApiClientError as A, OpenAPIPath as O, Request as R, assertStatus as a };
|