@mittwald/api-client-commons 4.2.0-alpha.9 → 4.2.1-alpha.0
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/LICENSE +21 -0
- package/dist/esm/axios.js +1 -0
- package/dist/esm/core/ApiClientBase.js +13 -0
- package/dist/esm/core/ApiClientError.js +12 -0
- package/dist/esm/core/OpenAPIPath.js +20 -0
- package/dist/esm/core/Request.js +76 -0
- package/dist/esm/core/Request.test.js +53 -0
- package/dist/esm/core/index.js +4 -0
- package/dist/esm/index.js +3 -0
- package/dist/esm/react/ApiCallAsyncResourceFactory.js +35 -0
- package/dist/esm/react/ApiCallAsyncResourceFactory.test-types.js +36 -0
- package/dist/esm/react/ApiCallAsyncResourceFactory.test.js +46 -0
- package/dist/esm/react/index.js +1 -0
- package/dist/esm/react/types.js +1 -0
- package/dist/esm/types/NullableOnNoRequiredKeysDeep.js +1 -0
- package/dist/esm/types/OpenAPIOperation.js +1 -0
- package/dist/esm/types/RequestFunction.js +1 -0
- package/dist/esm/types/RequestFunction.test-types.js +29 -0
- package/dist/esm/types/RequestType.js +1 -0
- package/dist/esm/types/RequestType.test-types.js +146 -0
- package/dist/esm/types/Response.js +1 -0
- package/dist/esm/types/Response.test-types.js +70 -0
- package/dist/esm/types/assertStatus.js +7 -0
- package/dist/esm/types/assertStatus.test-types.js +8 -0
- package/dist/esm/types/http.js +1 -0
- package/dist/esm/types/index.js +7 -0
- package/dist/esm/types/simplify.js +1 -0
- package/dist/types/axios.d.ts +1 -0
- package/dist/types/core/ApiClientBase.d.ts +9 -0
- package/dist/types/core/ApiClientError.d.ts +7 -0
- package/dist/types/core/OpenAPIPath.d.ts +9 -0
- package/dist/types/core/Request.d.ts +13 -0
- package/dist/types/core/Request.test.d.ts +1 -0
- package/dist/types/core/index.d.ts +4 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/react/ApiCallAsyncResourceFactory.d.ts +12 -0
- package/dist/types/react/ApiCallAsyncResourceFactory.test-types.d.ts +1 -0
- package/dist/types/react/ApiCallAsyncResourceFactory.test.d.ts +1 -0
- package/dist/types/react/index.d.ts +1 -0
- package/dist/types/react/types.d.ts +3 -0
- package/dist/types/types/NullableOnNoRequiredKeysDeep.d.ts +6 -0
- package/dist/types/types/OpenAPIOperation.d.ts +20 -0
- package/dist/types/types/RequestFunction.d.ts +11 -0
- package/dist/types/types/RequestFunction.test-types.d.ts +1 -0
- package/dist/types/types/RequestType.d.ts +21 -0
- package/dist/types/types/RequestType.test-types.d.ts +1 -0
- package/dist/types/types/Response.d.ts +7 -0
- package/dist/types/types/Response.test-types.d.ts +1 -0
- package/dist/types/types/assertStatus.d.ts +5 -0
- package/dist/types/types/assertStatus.test-types.d.ts +1 -0
- package/dist/types/types/http.d.ts +13 -0
- package/dist/types/types/index.d.ts +7 -0
- package/dist/types/types/simplify.d.ts +3 -0
- package/package.json +52 -45
- package/dist/RequestFunction-b1412636.d.ts +0 -71
- package/dist/chunk-PEYA5TMK.js +0 -154
- package/dist/index.cjs +0 -196
- package/dist/index.d.cts +0 -49
- package/dist/index.d.ts +0 -49
- package/dist/index.js +0 -48
- package/dist/react.cjs +0 -185
- package/dist/react.d.cts +0 -19
- package/dist/react.d.ts +0 -19
- package/dist/react.js +0 -45
package/dist/index.cjs
DELETED
|
@@ -1,196 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
-
for (let key of __getOwnPropNames(from))
|
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
21
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
22
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
23
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
24
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
25
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
26
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
27
|
-
mod
|
|
28
|
-
));
|
|
29
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
30
|
-
|
|
31
|
-
// src/index.ts
|
|
32
|
-
var src_exports = {};
|
|
33
|
-
__export(src_exports, {
|
|
34
|
-
ApiClientBase: () => ApiClientBase,
|
|
35
|
-
ApiClientError: () => ApiClientError,
|
|
36
|
-
OpenAPIPath: () => OpenAPIPath,
|
|
37
|
-
Request: () => Request,
|
|
38
|
-
assertOneOfStatus: () => assertOneOfStatus,
|
|
39
|
-
assertStatus: () => assertStatus
|
|
40
|
-
});
|
|
41
|
-
module.exports = __toCommonJS(src_exports);
|
|
42
|
-
|
|
43
|
-
// src/core/ApiClientBase.ts
|
|
44
|
-
var import_axios = __toESM(require("axios"), 1);
|
|
45
|
-
|
|
46
|
-
// src/core/OpenAPIPath.ts
|
|
47
|
-
var OpenAPIPath = class _OpenAPIPath {
|
|
48
|
-
constructor(rawPath, params) {
|
|
49
|
-
this.rawPath = rawPath;
|
|
50
|
-
this.params = params;
|
|
51
|
-
}
|
|
52
|
-
buildUrl() {
|
|
53
|
-
return _OpenAPIPath.setPathParams(this.rawPath, this.params);
|
|
54
|
-
}
|
|
55
|
-
static setPathParams(path, params) {
|
|
56
|
-
const asEntries = Object.entries(params ?? {});
|
|
57
|
-
const finalPath = asEntries.reduce((path2, entry) => {
|
|
58
|
-
const [key, value] = entry;
|
|
59
|
-
return path2.replace(`{${key}}`, encodeURIComponent(value));
|
|
60
|
-
}, path);
|
|
61
|
-
return finalPath.startsWith("/") ? finalPath.substring(1) : finalPath;
|
|
62
|
-
}
|
|
63
|
-
};
|
|
64
|
-
var OpenAPIPath_default = OpenAPIPath;
|
|
65
|
-
|
|
66
|
-
// src/core/Request.ts
|
|
67
|
-
var Request = class {
|
|
68
|
-
constructor(operationDescriptor, requestObject) {
|
|
69
|
-
this.operationDescriptor = operationDescriptor;
|
|
70
|
-
this.requestObject = requestObject;
|
|
71
|
-
this.requestConfig = Object.freeze(this.buildAxiosConfig());
|
|
72
|
-
}
|
|
73
|
-
execute(axios2) {
|
|
74
|
-
return axios2.request(this.requestConfig);
|
|
75
|
-
}
|
|
76
|
-
buildAxiosConfig() {
|
|
77
|
-
const { method, path } = this.operationDescriptor;
|
|
78
|
-
const pathParameters = this.requestObject;
|
|
79
|
-
const openApiPath = new OpenAPIPath_default(path, pathParameters);
|
|
80
|
-
const url = openApiPath.buildUrl();
|
|
81
|
-
const data = this.requestObject && "data" in this.requestObject ? this.requestObject.data : void 0;
|
|
82
|
-
const headersConfig = this.requestObject && "headers" in this.requestObject ? this.requestObject.headers : void 0;
|
|
83
|
-
const headers = headersConfig ? this.makeAxiosHeaders(headersConfig) : void 0;
|
|
84
|
-
const queryParametersConfig = this.requestObject && "queryParameters" in this.requestObject ? this.requestObject.queryParameters : void 0;
|
|
85
|
-
const params = this.convertQueryToUrlSearchParams(queryParametersConfig);
|
|
86
|
-
return {
|
|
87
|
-
url,
|
|
88
|
-
method,
|
|
89
|
-
headers,
|
|
90
|
-
// Must be a plain object or an URLSearchParams object
|
|
91
|
-
params,
|
|
92
|
-
data,
|
|
93
|
-
validateStatus: () => true
|
|
94
|
-
};
|
|
95
|
-
}
|
|
96
|
-
makeAxiosHeaders(headers) {
|
|
97
|
-
return Object.fromEntries(
|
|
98
|
-
Object.entries(headers).map(([key, value]) => [key, value?.toString()])
|
|
99
|
-
);
|
|
100
|
-
}
|
|
101
|
-
convertQueryToUrlSearchParams(query) {
|
|
102
|
-
if (query === void 0 || query === null) {
|
|
103
|
-
return void 0;
|
|
104
|
-
}
|
|
105
|
-
if (query instanceof URLSearchParams) {
|
|
106
|
-
return query;
|
|
107
|
-
}
|
|
108
|
-
if (typeof query === "string") {
|
|
109
|
-
return new URLSearchParams(query);
|
|
110
|
-
}
|
|
111
|
-
if (typeof query === "object") {
|
|
112
|
-
const searchParams = new URLSearchParams();
|
|
113
|
-
for (const [key, value] of Object.entries(query)) {
|
|
114
|
-
if (Array.isArray(value)) {
|
|
115
|
-
for (const arrayItem of value) {
|
|
116
|
-
searchParams.append(key, arrayItem);
|
|
117
|
-
}
|
|
118
|
-
} else {
|
|
119
|
-
searchParams.append(
|
|
120
|
-
key,
|
|
121
|
-
typeof value === "string" || typeof value === "number" || typeof value === "boolean" ? value.toString() : JSON.stringify(value)
|
|
122
|
-
);
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
return searchParams;
|
|
126
|
-
}
|
|
127
|
-
throw new Error(`Unexpected query parameter type (${typeof query})`);
|
|
128
|
-
}
|
|
129
|
-
};
|
|
130
|
-
var Request_default = Request;
|
|
131
|
-
|
|
132
|
-
// src/core/ApiClientBase.ts
|
|
133
|
-
var ApiClientBase = class {
|
|
134
|
-
constructor(axiosConfig = import_axios.default) {
|
|
135
|
-
this.axios = axiosConfig instanceof import_axios.Axios ? axiosConfig : import_axios.default.create(axiosConfig);
|
|
136
|
-
}
|
|
137
|
-
requestFunctionFactory(operation) {
|
|
138
|
-
return (conf) => new Request_default(operation, conf).execute(this.axios);
|
|
139
|
-
}
|
|
140
|
-
};
|
|
141
|
-
|
|
142
|
-
// src/core/ApiClientError.ts
|
|
143
|
-
var import_axios2 = require("axios");
|
|
144
|
-
var ApiClientError = class _ApiClientError extends import_axios2.AxiosError {
|
|
145
|
-
constructor(message, code, config, request, response) {
|
|
146
|
-
super(message, code, config, request, response);
|
|
147
|
-
Object.setPrototypeOf(this, _ApiClientError.prototype);
|
|
148
|
-
this.name = "ApiClientError";
|
|
149
|
-
}
|
|
150
|
-
static fromResponse(message, response) {
|
|
151
|
-
return new _ApiClientError(
|
|
152
|
-
message,
|
|
153
|
-
void 0,
|
|
154
|
-
response.config,
|
|
155
|
-
response.request,
|
|
156
|
-
response
|
|
157
|
-
);
|
|
158
|
-
}
|
|
159
|
-
};
|
|
160
|
-
var ApiClientError_default = ApiClientError;
|
|
161
|
-
|
|
162
|
-
// src/types/assertStatus.ts
|
|
163
|
-
function assertStatus(response, expectedStatus) {
|
|
164
|
-
if (response.status !== expectedStatus) {
|
|
165
|
-
throw ApiClientError_default.fromResponse(
|
|
166
|
-
`Unexpected response status (expected ${expectedStatus}, got: ${response.status})`,
|
|
167
|
-
response
|
|
168
|
-
);
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
// src/types/assertOneOfStatus.ts
|
|
173
|
-
function assertOneOfStatus(response, expectedStatus) {
|
|
174
|
-
if (!expectedStatus.includes(response.status)) {
|
|
175
|
-
throw ApiClientError_default.fromResponse(
|
|
176
|
-
`Unexpected response status (expected ${expectedStatus}, got: ${response.status})`,
|
|
177
|
-
response
|
|
178
|
-
);
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
// src/axios.ts
|
|
183
|
-
var axios_exports = {};
|
|
184
|
-
__reExport(axios_exports, require("axios"));
|
|
185
|
-
|
|
186
|
-
// src/index.ts
|
|
187
|
-
__reExport(src_exports, axios_exports, module.exports);
|
|
188
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
189
|
-
0 && (module.exports = {
|
|
190
|
-
ApiClientBase,
|
|
191
|
-
ApiClientError,
|
|
192
|
-
OpenAPIPath,
|
|
193
|
-
Request,
|
|
194
|
-
assertOneOfStatus,
|
|
195
|
-
assertStatus
|
|
196
|
-
});
|
package/dist/index.d.cts
DELETED
|
@@ -1,49 +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 './RequestFunction-b1412636.js';
|
|
4
|
-
export { e as AnyRequest, l as HttpHeaders, j as HttpMediaType, k as HttpMethod, H as HttpPayload, i as HttpStatus, I as InferredRequestType, f as InferredResponseType, Q as QueryParameters, h as RequestData, d as RequestType, g as ResponseData } from './RequestFunction-b1412636.js';
|
|
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 function assertOneOfStatus<T extends Response, S extends T["status"]>(response: T, expectedStatus: S[]): asserts response is T & {
|
|
16
|
-
status: S;
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
declare abstract class ApiClientBase {
|
|
20
|
-
axios: AxiosInstance;
|
|
21
|
-
constructor(axiosConfig?: AxiosInstance | CreateAxiosDefaults);
|
|
22
|
-
protected requestFunctionFactory<TOp extends OpenAPIOperation>(operation: TOp): RequestFunction<TOp>;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
declare class ApiClientError<T = unknown, D = unknown> extends AxiosError<T, D> {
|
|
26
|
-
constructor(message?: string, code?: string, config?: InternalAxiosRequestConfig<D>, request?: unknown, response?: AxiosResponse<T, D>);
|
|
27
|
-
static fromResponse(message: string, response: AnyResponse): ApiClientError;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
declare class OpenAPIPath {
|
|
31
|
-
private readonly rawPath;
|
|
32
|
-
private readonly params?;
|
|
33
|
-
constructor(rawPath: string, params?: PathParameters);
|
|
34
|
-
buildUrl(): string;
|
|
35
|
-
private static setPathParams;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
declare class Request<TOp extends OpenAPIOperation> {
|
|
39
|
-
private readonly operationDescriptor;
|
|
40
|
-
private readonly requestObject?;
|
|
41
|
-
readonly requestConfig: AxiosRequestConfig;
|
|
42
|
-
constructor(operationDescriptor: TOp, requestObject?: RequestObject<TOp>);
|
|
43
|
-
execute(axios: AxiosInstance): ResponsePromise<TOp>;
|
|
44
|
-
private buildAxiosConfig;
|
|
45
|
-
private makeAxiosHeaders;
|
|
46
|
-
private convertQueryToUrlSearchParams;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
export { AnyResponse, ApiClientBase, ApiClientError, OpenAPIOperation, OpenAPIPath, PathParameters, Request, RequestFunction, RequestObject, Response, ResponsePromise, Simplify, assertOneOfStatus, assertStatus };
|
package/dist/index.d.ts
DELETED
|
@@ -1,49 +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 './RequestFunction-b1412636.js';
|
|
4
|
-
export { e as AnyRequest, l as HttpHeaders, j as HttpMediaType, k as HttpMethod, H as HttpPayload, i as HttpStatus, I as InferredRequestType, f as InferredResponseType, Q as QueryParameters, h as RequestData, d as RequestType, g as ResponseData } from './RequestFunction-b1412636.js';
|
|
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 function assertOneOfStatus<T extends Response, S extends T["status"]>(response: T, expectedStatus: S[]): asserts response is T & {
|
|
16
|
-
status: S;
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
declare abstract class ApiClientBase {
|
|
20
|
-
axios: AxiosInstance;
|
|
21
|
-
constructor(axiosConfig?: AxiosInstance | CreateAxiosDefaults);
|
|
22
|
-
protected requestFunctionFactory<TOp extends OpenAPIOperation>(operation: TOp): RequestFunction<TOp>;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
declare class ApiClientError<T = unknown, D = unknown> extends AxiosError<T, D> {
|
|
26
|
-
constructor(message?: string, code?: string, config?: InternalAxiosRequestConfig<D>, request?: unknown, response?: AxiosResponse<T, D>);
|
|
27
|
-
static fromResponse(message: string, response: AnyResponse): ApiClientError;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
declare class OpenAPIPath {
|
|
31
|
-
private readonly rawPath;
|
|
32
|
-
private readonly params?;
|
|
33
|
-
constructor(rawPath: string, params?: PathParameters);
|
|
34
|
-
buildUrl(): string;
|
|
35
|
-
private static setPathParams;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
declare class Request<TOp extends OpenAPIOperation> {
|
|
39
|
-
private readonly operationDescriptor;
|
|
40
|
-
private readonly requestObject?;
|
|
41
|
-
readonly requestConfig: AxiosRequestConfig;
|
|
42
|
-
constructor(operationDescriptor: TOp, requestObject?: RequestObject<TOp>);
|
|
43
|
-
execute(axios: AxiosInstance): ResponsePromise<TOp>;
|
|
44
|
-
private buildAxiosConfig;
|
|
45
|
-
private makeAxiosHeaders;
|
|
46
|
-
private convertQueryToUrlSearchParams;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
export { AnyResponse, ApiClientBase, ApiClientError, OpenAPIOperation, OpenAPIPath, PathParameters, Request, RequestFunction, RequestObject, Response, ResponsePromise, Simplify, assertOneOfStatus, assertStatus };
|
package/dist/index.js
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
ApiClientError,
|
|
3
|
-
OpenAPIPath,
|
|
4
|
-
Request,
|
|
5
|
-
Request_default,
|
|
6
|
-
__export,
|
|
7
|
-
__reExport,
|
|
8
|
-
assertOneOfStatus,
|
|
9
|
-
assertStatus
|
|
10
|
-
} from "./chunk-PEYA5TMK.js";
|
|
11
|
-
|
|
12
|
-
// src/index.ts
|
|
13
|
-
var src_exports = {};
|
|
14
|
-
__export(src_exports, {
|
|
15
|
-
ApiClientBase: () => ApiClientBase,
|
|
16
|
-
ApiClientError: () => ApiClientError,
|
|
17
|
-
OpenAPIPath: () => OpenAPIPath,
|
|
18
|
-
Request: () => Request,
|
|
19
|
-
assertOneOfStatus: () => assertOneOfStatus,
|
|
20
|
-
assertStatus: () => assertStatus
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
// src/core/ApiClientBase.ts
|
|
24
|
-
import axios, { Axios } from "axios";
|
|
25
|
-
var ApiClientBase = class {
|
|
26
|
-
constructor(axiosConfig = axios) {
|
|
27
|
-
this.axios = axiosConfig instanceof Axios ? axiosConfig : axios.create(axiosConfig);
|
|
28
|
-
}
|
|
29
|
-
requestFunctionFactory(operation) {
|
|
30
|
-
return (conf) => new Request_default(operation, conf).execute(this.axios);
|
|
31
|
-
}
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
// src/axios.ts
|
|
35
|
-
var axios_exports = {};
|
|
36
|
-
__reExport(axios_exports, axios_star);
|
|
37
|
-
import * as axios_star from "axios";
|
|
38
|
-
|
|
39
|
-
// src/index.ts
|
|
40
|
-
__reExport(src_exports, axios_exports);
|
|
41
|
-
export {
|
|
42
|
-
ApiClientBase,
|
|
43
|
-
ApiClientError,
|
|
44
|
-
OpenAPIPath,
|
|
45
|
-
Request,
|
|
46
|
-
assertOneOfStatus,
|
|
47
|
-
assertStatus
|
|
48
|
-
};
|
package/dist/react.cjs
DELETED
|
@@ -1,185 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// src/react.ts
|
|
21
|
-
var react_exports = {};
|
|
22
|
-
__export(react_exports, {
|
|
23
|
-
ApiCallAsyncResourceFactory: () => ApiCallAsyncResourceFactory
|
|
24
|
-
});
|
|
25
|
-
module.exports = __toCommonJS(react_exports);
|
|
26
|
-
|
|
27
|
-
// src/react/ApiCallAsyncResourceFactory.ts
|
|
28
|
-
var import_react_use_promise = require("@mittwald/react-use-promise");
|
|
29
|
-
|
|
30
|
-
// src/core/ApiClientError.ts
|
|
31
|
-
var import_axios = require("axios");
|
|
32
|
-
var ApiClientError = class _ApiClientError extends import_axios.AxiosError {
|
|
33
|
-
constructor(message, code, config, request, response) {
|
|
34
|
-
super(message, code, config, request, response);
|
|
35
|
-
Object.setPrototypeOf(this, _ApiClientError.prototype);
|
|
36
|
-
this.name = "ApiClientError";
|
|
37
|
-
}
|
|
38
|
-
static fromResponse(message, response) {
|
|
39
|
-
return new _ApiClientError(
|
|
40
|
-
message,
|
|
41
|
-
void 0,
|
|
42
|
-
response.config,
|
|
43
|
-
response.request,
|
|
44
|
-
response
|
|
45
|
-
);
|
|
46
|
-
}
|
|
47
|
-
};
|
|
48
|
-
var ApiClientError_default = ApiClientError;
|
|
49
|
-
|
|
50
|
-
// src/types/assertStatus.ts
|
|
51
|
-
function assertStatus(response, expectedStatus) {
|
|
52
|
-
if (response.status !== expectedStatus) {
|
|
53
|
-
throw ApiClientError_default.fromResponse(
|
|
54
|
-
`Unexpected response status (expected ${expectedStatus}, got: ${response.status})`,
|
|
55
|
-
response
|
|
56
|
-
);
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
// src/core/OpenAPIPath.ts
|
|
61
|
-
var OpenAPIPath = class _OpenAPIPath {
|
|
62
|
-
constructor(rawPath, params) {
|
|
63
|
-
this.rawPath = rawPath;
|
|
64
|
-
this.params = params;
|
|
65
|
-
}
|
|
66
|
-
buildUrl() {
|
|
67
|
-
return _OpenAPIPath.setPathParams(this.rawPath, this.params);
|
|
68
|
-
}
|
|
69
|
-
static setPathParams(path, params) {
|
|
70
|
-
const asEntries = Object.entries(params ?? {});
|
|
71
|
-
const finalPath = asEntries.reduce((path2, entry) => {
|
|
72
|
-
const [key, value] = entry;
|
|
73
|
-
return path2.replace(`{${key}}`, encodeURIComponent(value));
|
|
74
|
-
}, path);
|
|
75
|
-
return finalPath.startsWith("/") ? finalPath.substring(1) : finalPath;
|
|
76
|
-
}
|
|
77
|
-
};
|
|
78
|
-
var OpenAPIPath_default = OpenAPIPath;
|
|
79
|
-
|
|
80
|
-
// src/core/Request.ts
|
|
81
|
-
var Request = class {
|
|
82
|
-
constructor(operationDescriptor, requestObject) {
|
|
83
|
-
this.operationDescriptor = operationDescriptor;
|
|
84
|
-
this.requestObject = requestObject;
|
|
85
|
-
this.requestConfig = Object.freeze(this.buildAxiosConfig());
|
|
86
|
-
}
|
|
87
|
-
execute(axios) {
|
|
88
|
-
return axios.request(this.requestConfig);
|
|
89
|
-
}
|
|
90
|
-
buildAxiosConfig() {
|
|
91
|
-
const { method, path } = this.operationDescriptor;
|
|
92
|
-
const pathParameters = this.requestObject;
|
|
93
|
-
const openApiPath = new OpenAPIPath_default(path, pathParameters);
|
|
94
|
-
const url = openApiPath.buildUrl();
|
|
95
|
-
const data = this.requestObject && "data" in this.requestObject ? this.requestObject.data : void 0;
|
|
96
|
-
const headersConfig = this.requestObject && "headers" in this.requestObject ? this.requestObject.headers : void 0;
|
|
97
|
-
const headers = headersConfig ? this.makeAxiosHeaders(headersConfig) : void 0;
|
|
98
|
-
const queryParametersConfig = this.requestObject && "queryParameters" in this.requestObject ? this.requestObject.queryParameters : void 0;
|
|
99
|
-
const params = this.convertQueryToUrlSearchParams(queryParametersConfig);
|
|
100
|
-
return {
|
|
101
|
-
url,
|
|
102
|
-
method,
|
|
103
|
-
headers,
|
|
104
|
-
// Must be a plain object or an URLSearchParams object
|
|
105
|
-
params,
|
|
106
|
-
data,
|
|
107
|
-
validateStatus: () => true
|
|
108
|
-
};
|
|
109
|
-
}
|
|
110
|
-
makeAxiosHeaders(headers) {
|
|
111
|
-
return Object.fromEntries(
|
|
112
|
-
Object.entries(headers).map(([key, value]) => [key, value?.toString()])
|
|
113
|
-
);
|
|
114
|
-
}
|
|
115
|
-
convertQueryToUrlSearchParams(query) {
|
|
116
|
-
if (query === void 0 || query === null) {
|
|
117
|
-
return void 0;
|
|
118
|
-
}
|
|
119
|
-
if (query instanceof URLSearchParams) {
|
|
120
|
-
return query;
|
|
121
|
-
}
|
|
122
|
-
if (typeof query === "string") {
|
|
123
|
-
return new URLSearchParams(query);
|
|
124
|
-
}
|
|
125
|
-
if (typeof query === "object") {
|
|
126
|
-
const searchParams = new URLSearchParams();
|
|
127
|
-
for (const [key, value] of Object.entries(query)) {
|
|
128
|
-
if (Array.isArray(value)) {
|
|
129
|
-
for (const arrayItem of value) {
|
|
130
|
-
searchParams.append(key, arrayItem);
|
|
131
|
-
}
|
|
132
|
-
} else {
|
|
133
|
-
searchParams.append(
|
|
134
|
-
key,
|
|
135
|
-
typeof value === "string" || typeof value === "number" || typeof value === "boolean" ? value.toString() : JSON.stringify(value)
|
|
136
|
-
);
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
return searchParams;
|
|
140
|
-
}
|
|
141
|
-
throw new Error(`Unexpected query parameter type (${typeof query})`);
|
|
142
|
-
}
|
|
143
|
-
};
|
|
144
|
-
var Request_default = Request;
|
|
145
|
-
|
|
146
|
-
// src/react/ApiCallAsyncResourceFactory.ts
|
|
147
|
-
var _ApiCallAsyncResourceFactory = class _ApiCallAsyncResourceFactory {
|
|
148
|
-
constructor(operation, requestFn) {
|
|
149
|
-
this.getApiResource = (requestObj) => {
|
|
150
|
-
const request = new Request_default(this.operation, requestObj);
|
|
151
|
-
return (0, import_react_use_promise.getAsyncResource)(
|
|
152
|
-
(requestObj2) => this.executeRequest(requestObj2),
|
|
153
|
-
[requestObj],
|
|
154
|
-
{
|
|
155
|
-
tags: this.getAsyncResourceTags(request),
|
|
156
|
-
loaderId: this.getAsyncResourceId()
|
|
157
|
-
}
|
|
158
|
-
);
|
|
159
|
-
};
|
|
160
|
-
this.operation = operation;
|
|
161
|
-
this.requestFn = requestFn;
|
|
162
|
-
}
|
|
163
|
-
getAsyncResourceId() {
|
|
164
|
-
return `${_ApiCallAsyncResourceFactory.namespace}/${this.operation.operationId}`;
|
|
165
|
-
}
|
|
166
|
-
getAsyncResourceTags(request) {
|
|
167
|
-
const url = request.requestConfig.url ?? "";
|
|
168
|
-
return [
|
|
169
|
-
this.getAsyncResourceId(),
|
|
170
|
-
`${_ApiCallAsyncResourceFactory.namespace}/${this.operation.method}`,
|
|
171
|
-
`${_ApiCallAsyncResourceFactory.namespace}/${url}`
|
|
172
|
-
];
|
|
173
|
-
}
|
|
174
|
-
async executeRequest(requestObj) {
|
|
175
|
-
const response = await this.requestFn(requestObj);
|
|
176
|
-
assertStatus(response, 200);
|
|
177
|
-
return response.data;
|
|
178
|
-
}
|
|
179
|
-
};
|
|
180
|
-
_ApiCallAsyncResourceFactory.namespace = "@mittwald/api-client";
|
|
181
|
-
var ApiCallAsyncResourceFactory = _ApiCallAsyncResourceFactory;
|
|
182
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
183
|
-
0 && (module.exports = {
|
|
184
|
-
ApiCallAsyncResourceFactory
|
|
185
|
-
});
|
package/dist/react.d.cts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { O as OpenAPIOperation, b as RequestObject, g as ResponseData, a as RequestFunction } from './RequestFunction-b1412636.js';
|
|
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<ResponseData<TOp>> : (conf: RequestObject<TOp>) => AsyncResource<ResponseData<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, GetApiResourceFn };
|
package/dist/react.d.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { O as OpenAPIOperation, b as RequestObject, g as ResponseData, a as RequestFunction } from './RequestFunction-b1412636.js';
|
|
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<ResponseData<TOp>> : (conf: RequestObject<TOp>) => AsyncResource<ResponseData<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, GetApiResourceFn };
|
package/dist/react.js
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Request_default,
|
|
3
|
-
assertStatus
|
|
4
|
-
} from "./chunk-PEYA5TMK.js";
|
|
5
|
-
|
|
6
|
-
// src/react/ApiCallAsyncResourceFactory.ts
|
|
7
|
-
import { getAsyncResource } from "@mittwald/react-use-promise";
|
|
8
|
-
var _ApiCallAsyncResourceFactory = class _ApiCallAsyncResourceFactory {
|
|
9
|
-
constructor(operation, requestFn) {
|
|
10
|
-
this.getApiResource = (requestObj) => {
|
|
11
|
-
const request = new Request_default(this.operation, requestObj);
|
|
12
|
-
return getAsyncResource(
|
|
13
|
-
(requestObj2) => this.executeRequest(requestObj2),
|
|
14
|
-
[requestObj],
|
|
15
|
-
{
|
|
16
|
-
tags: this.getAsyncResourceTags(request),
|
|
17
|
-
loaderId: this.getAsyncResourceId()
|
|
18
|
-
}
|
|
19
|
-
);
|
|
20
|
-
};
|
|
21
|
-
this.operation = operation;
|
|
22
|
-
this.requestFn = requestFn;
|
|
23
|
-
}
|
|
24
|
-
getAsyncResourceId() {
|
|
25
|
-
return `${_ApiCallAsyncResourceFactory.namespace}/${this.operation.operationId}`;
|
|
26
|
-
}
|
|
27
|
-
getAsyncResourceTags(request) {
|
|
28
|
-
const url = request.requestConfig.url ?? "";
|
|
29
|
-
return [
|
|
30
|
-
this.getAsyncResourceId(),
|
|
31
|
-
`${_ApiCallAsyncResourceFactory.namespace}/${this.operation.method}`,
|
|
32
|
-
`${_ApiCallAsyncResourceFactory.namespace}/${url}`
|
|
33
|
-
];
|
|
34
|
-
}
|
|
35
|
-
async executeRequest(requestObj) {
|
|
36
|
-
const response = await this.requestFn(requestObj);
|
|
37
|
-
assertStatus(response, 200);
|
|
38
|
-
return response.data;
|
|
39
|
-
}
|
|
40
|
-
};
|
|
41
|
-
_ApiCallAsyncResourceFactory.namespace = "@mittwald/api-client";
|
|
42
|
-
var ApiCallAsyncResourceFactory = _ApiCallAsyncResourceFactory;
|
|
43
|
-
export {
|
|
44
|
-
ApiCallAsyncResourceFactory
|
|
45
|
-
};
|