@mittwald/api-client-commons 4.2.0-alpha.6 → 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
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { OpenAPIOperation, RequestObject, ResponsePromise } from "../types/index.js";
|
|
2
|
+
import { AxiosInstance, AxiosRequestConfig } from "axios";
|
|
3
|
+
export declare class Request<TOp extends OpenAPIOperation> {
|
|
4
|
+
private readonly operationDescriptor;
|
|
5
|
+
private readonly requestObject?;
|
|
6
|
+
readonly requestConfig: AxiosRequestConfig;
|
|
7
|
+
constructor(operationDescriptor: TOp, requestObject?: RequestObject<TOp>);
|
|
8
|
+
execute(axios: AxiosInstance): ResponsePromise<TOp>;
|
|
9
|
+
private buildAxiosConfig;
|
|
10
|
+
private makeAxiosHeaders;
|
|
11
|
+
private convertQueryToUrlSearchParams;
|
|
12
|
+
}
|
|
13
|
+
export default Request;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { OpenAPIOperation, RequestFunction } from "../types/index.js";
|
|
2
|
+
import { GetApiResourceFn } from "./types.js";
|
|
3
|
+
export declare class ApiCallAsyncResourceFactory<TOp extends OpenAPIOperation> {
|
|
4
|
+
private static namespace;
|
|
5
|
+
private readonly operation;
|
|
6
|
+
private readonly requestFn;
|
|
7
|
+
constructor(operation: TOp, requestFn: RequestFunction<TOp>);
|
|
8
|
+
private getAsyncResourceId;
|
|
9
|
+
private getAsyncResourceTags;
|
|
10
|
+
private executeRequest;
|
|
11
|
+
getApiResource: GetApiResourceFn<TOp>;
|
|
12
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./ApiCallAsyncResourceFactory.js";
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { OpenAPIOperation, RequestObject, InferredResponseData } from "../types/index.js";
|
|
2
|
+
import { AsyncResource } from "@mittwald/react-use-promise";
|
|
3
|
+
export type GetApiResourceFn<TOp extends OpenAPIOperation> = null extends RequestObject<TOp> ? (conf?: RequestObject<TOp>) => AsyncResource<InferredResponseData<TOp>> : (conf: RequestObject<TOp>) => AsyncResource<InferredResponseData<TOp>>;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { HasRequiredKeys, OmitIndexSignature, PartialOnUndefinedDeep } from "type-fest";
|
|
2
|
+
type PartialOnNoRequiredKeysDeep<T> = PartialOnUndefinedDeep<OmitIndexSignature<{
|
|
3
|
+
[TKey in keyof T]: HasRequiredKeys<PartialOnNoRequiredKeysDeep<T[TKey]>> extends true ? T[TKey] : T[TKey] | undefined;
|
|
4
|
+
}>>;
|
|
5
|
+
export type NullableOnNoRequiredKeysDeep<T> = HasRequiredKeys<PartialOnNoRequiredKeysDeep<T>> extends true ? PartialOnNoRequiredKeysDeep<T> : PartialOnNoRequiredKeysDeep<T> | null;
|
|
6
|
+
export {};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { AnyResponse, Response } from "./Response.js";
|
|
2
|
+
import { AnyRequest, RequestType } from "./RequestType.js";
|
|
3
|
+
import { HttpMethod, HttpStatus } from "./http.js";
|
|
4
|
+
export interface OpenAPIOperation<TIgnoredRequest extends AnyRequest = RequestType, IgnoredResponse extends AnyResponse = Response> {
|
|
5
|
+
operationId: string;
|
|
6
|
+
path: string;
|
|
7
|
+
method: HttpMethod;
|
|
8
|
+
}
|
|
9
|
+
export type InferredRequestType<TOp> = TOp extends OpenAPIOperation<infer TReq> ? TReq : never;
|
|
10
|
+
export type InferredResponseType<TOp> = TOp extends OpenAPIOperation<RequestType, infer TRes> ? TRes : never;
|
|
11
|
+
export type InferredResponseData<TOp, TStatus extends HttpStatus = 200> = Extract<InferredResponseType<TOp>, {
|
|
12
|
+
status: TStatus;
|
|
13
|
+
}>["data"];
|
|
14
|
+
export type InferredRequestData<TOp> = TOp extends OpenAPIOperation ? InferredRequestType<TOp> extends {
|
|
15
|
+
data: infer TData;
|
|
16
|
+
} ? TData : never : never;
|
|
17
|
+
/** @deprecated Use InferredResponseData */
|
|
18
|
+
export type ResponseData<TOp> = InferredResponseData<TOp>;
|
|
19
|
+
/** @deprecated Use InferredRequestData */
|
|
20
|
+
export type RequestData<TOp> = InferredRequestData<TOp>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { InferredRequestType, InferredResponseType, OpenAPIOperation } from "./OpenAPIOperation.js";
|
|
2
|
+
import { NullableOnNoRequiredKeysDeep } from "./NullableOnNoRequiredKeysDeep.js";
|
|
3
|
+
type UnboxPathParameters<T> = T extends {
|
|
4
|
+
pathParameters: infer TPath;
|
|
5
|
+
} ? Omit<T, "pathParameters"> & TPath : T;
|
|
6
|
+
export type RequestObject<TOp extends OpenAPIOperation> = NullableOnNoRequiredKeysDeep<UnboxPathParameters<InferredRequestType<TOp>>>;
|
|
7
|
+
export type ResponsePromise<TOp extends OpenAPIOperation> = Promise<InferredResponseType<TOp>>;
|
|
8
|
+
type RequestFunctionWithOptionalRequest<TOp extends OpenAPIOperation> = (request?: RequestObject<TOp>) => ResponsePromise<TOp>;
|
|
9
|
+
type RequestFunctionWithRequiredRequest<TOp extends OpenAPIOperation> = (request: RequestObject<TOp>) => ResponsePromise<TOp>;
|
|
10
|
+
export type RequestFunction<TOp extends OpenAPIOperation> = null extends RequestObject<TOp> ? RequestFunctionWithOptionalRequest<TOp> : RequestFunctionWithRequiredRequest<TOp>;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { HttpHeaders, HttpPayload, PathParameters, QueryParameters } from "./http.js";
|
|
2
|
+
type EmptyObject = Record<string, never>;
|
|
3
|
+
type EmptyRequestComponent = EmptyObject | null;
|
|
4
|
+
type RequestWithOptionalHeaders = {
|
|
5
|
+
headers?: HttpHeaders;
|
|
6
|
+
};
|
|
7
|
+
type RequestWithData<TData> = TData extends EmptyRequestComponent ? RequestWithOptionalHeaders : {
|
|
8
|
+
data: TData;
|
|
9
|
+
};
|
|
10
|
+
type RequestWithPathParameters<TPathParameters> = TPathParameters extends EmptyRequestComponent ? RequestWithOptionalHeaders : {
|
|
11
|
+
pathParameters: TPathParameters;
|
|
12
|
+
};
|
|
13
|
+
type RequestWithHeaders<THeaders> = THeaders extends EmptyRequestComponent ? RequestWithOptionalHeaders : {
|
|
14
|
+
headers: THeaders & HttpHeaders;
|
|
15
|
+
};
|
|
16
|
+
type RequestWithQueryParameters<TQuery> = TQuery extends EmptyRequestComponent ? RequestWithOptionalHeaders : {
|
|
17
|
+
queryParameters: TQuery & HttpHeaders;
|
|
18
|
+
};
|
|
19
|
+
export type RequestType<TData extends HttpPayload = EmptyRequestComponent, TPathParameters extends PathParameters | EmptyRequestComponent = EmptyRequestComponent, TQueryParameters extends QueryParameters | EmptyRequestComponent = EmptyRequestComponent, THeader extends HttpHeaders | EmptyRequestComponent = EmptyRequestComponent> = TData | TPathParameters | THeader | TQueryParameters extends EmptyRequestComponent ? RequestWithOptionalHeaders : RequestWithData<TData> & RequestWithPathParameters<TPathParameters> & RequestWithQueryParameters<TQueryParameters> & RequestWithHeaders<THeader>;
|
|
20
|
+
export type AnyRequest = RequestType<any, any, any, any>;
|
|
21
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -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,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 {};
|
package/package.json
CHANGED
|
@@ -1,68 +1,75 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mittwald/api-client-commons",
|
|
3
|
-
"version": "4.2.
|
|
3
|
+
"version": "4.2.1-alpha.0",
|
|
4
|
+
"author": "Mittwald CM Service GmbH & Co. KG <opensource@mittwald.de>",
|
|
5
|
+
"type": "module",
|
|
4
6
|
"description": "Common types and utilities for mittwald API clients",
|
|
5
|
-
"
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
"
|
|
9
|
-
"
|
|
10
|
-
|
|
7
|
+
"keywords": [
|
|
8
|
+
"api",
|
|
9
|
+
"client",
|
|
10
|
+
"mittwald",
|
|
11
|
+
"rest",
|
|
12
|
+
"sdk"
|
|
13
|
+
],
|
|
11
14
|
"homepage": "https://developer.mittwald.de",
|
|
15
|
+
"repository": "https://github.com/mittwald/api-client-js.git",
|
|
12
16
|
"bugs": "https://github.com/mittwald/api-client-js/issues",
|
|
13
|
-
"
|
|
14
|
-
"module": "./dist/index.js",
|
|
15
|
-
"type": "module",
|
|
17
|
+
"license": "MIT",
|
|
16
18
|
"exports": {
|
|
17
19
|
".": {
|
|
18
|
-
"
|
|
19
|
-
"
|
|
20
|
-
"types": "./dist/index.d.ts"
|
|
20
|
+
"types": "./dist/types/index.d.ts",
|
|
21
|
+
"default": "./dist/esm/index.js"
|
|
21
22
|
},
|
|
22
23
|
"./react": {
|
|
23
|
-
"
|
|
24
|
-
"
|
|
25
|
-
"types": "./dist/react.d.ts"
|
|
24
|
+
"types": "./dist/types/react/index.d.ts",
|
|
25
|
+
"default": "./dist/esm/react/index.js"
|
|
26
26
|
}
|
|
27
27
|
},
|
|
28
|
-
"scripts": {
|
|
29
|
-
"compile": "tsup src/index.ts src/react.ts --format esm,cjs --dts --clean",
|
|
30
|
-
"test": "node --experimental-vm-modules $(yarn bin jest)"
|
|
31
|
-
},
|
|
32
28
|
"files": [
|
|
33
|
-
"dist
|
|
29
|
+
"dist"
|
|
34
30
|
],
|
|
35
|
-
"
|
|
36
|
-
"
|
|
37
|
-
"
|
|
38
|
-
"
|
|
39
|
-
"
|
|
40
|
-
"
|
|
41
|
-
],
|
|
42
|
-
"peerDependencies": {
|
|
43
|
-
"@mittwald/react-use-promise": "^1.3.6"
|
|
44
|
-
},
|
|
45
|
-
"peerDependenciesMeta": {
|
|
46
|
-
"@mittwald/react-use-promise": {
|
|
47
|
-
"optional": true
|
|
48
|
-
}
|
|
31
|
+
"scripts": {
|
|
32
|
+
"build": "run build:clean && run tsc",
|
|
33
|
+
"build:clean": "run rimraf dist",
|
|
34
|
+
"format": "run prettier --write '**/*.{ts,tsx,yaml,yml,json,md,mdx,js}'",
|
|
35
|
+
"lint": "run eslint .",
|
|
36
|
+
"test": "node --experimental-vm-modules $(yarn bin jest)"
|
|
49
37
|
},
|
|
50
38
|
"dependencies": {
|
|
51
|
-
"@types/parse-path": "^7.0.
|
|
52
|
-
"axios": "^1.6.
|
|
39
|
+
"@types/parse-path": "^7.0.3",
|
|
40
|
+
"axios": "^1.6.7",
|
|
53
41
|
"parse-path": "^7.0.0",
|
|
54
42
|
"path-to-regexp": "^6.2.1",
|
|
55
|
-
"type-fest": "^4.
|
|
43
|
+
"type-fest": "^4.10.3"
|
|
56
44
|
},
|
|
57
45
|
"devDependencies": {
|
|
58
46
|
"@jest/globals": "^29.7.0",
|
|
59
|
-
"@mittwald/react-use-promise": "^
|
|
60
|
-
"@types/jest": "^29.5.
|
|
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",
|
|
53
|
+
"eslint-plugin-json": "^3.1.0",
|
|
54
|
+
"eslint-plugin-prettier": "^5.1.3",
|
|
61
55
|
"jest": "^29.7.0",
|
|
56
|
+
"prettier": "^3.2.5",
|
|
57
|
+
"prettier-plugin-jsdoc": "^1.3.0",
|
|
58
|
+
"prettier-plugin-pkgsort": "^0.2.1",
|
|
59
|
+
"prettier-plugin-sort-json": "^3.1.0",
|
|
62
60
|
"react": "^18.2.0",
|
|
63
|
-
"
|
|
64
|
-
"
|
|
65
|
-
"
|
|
61
|
+
"rimraf": "^5.0.5",
|
|
62
|
+
"ts-jest": "^29.1.2",
|
|
63
|
+
"tsd": "^0.30.6",
|
|
64
|
+
"typescript": "^5.3.3"
|
|
65
|
+
},
|
|
66
|
+
"peerDependencies": {
|
|
67
|
+
"@mittwald/react-use-promise": "^2.1.0"
|
|
68
|
+
},
|
|
69
|
+
"peerDependenciesMeta": {
|
|
70
|
+
"@mittwald/react-use-promise": {
|
|
71
|
+
"optional": true
|
|
72
|
+
}
|
|
66
73
|
},
|
|
67
|
-
"
|
|
68
|
-
}
|
|
74
|
+
"gitHead": "6af0f63d14186cf75a69b2a87227b1cfc1f84379"
|
|
75
|
+
}
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import { AxiosResponse } from 'axios';
|
|
2
|
-
import { HasRequiredKeys, PartialOnUndefinedDeep, OmitIndexSignature } from 'type-fest';
|
|
3
|
-
|
|
4
|
-
type HttpPayload = unknown;
|
|
5
|
-
type HttpStatus = number | "default";
|
|
6
|
-
type HttpMediaType = string;
|
|
7
|
-
type SafeHttpMethod = "GET" | "HEAD" | "OPTIONS";
|
|
8
|
-
type UnsafeHttpMethod = "PUT" | "DELETE" | "POST" | "PATCH";
|
|
9
|
-
type HttpMethod = SafeHttpMethod | UnsafeHttpMethod;
|
|
10
|
-
type HeaderValue = string | number | boolean;
|
|
11
|
-
type HttpHeaders = Partial<{
|
|
12
|
-
[TKey: string]: HeaderValue | HeaderValue[];
|
|
13
|
-
}>;
|
|
14
|
-
type PathParameters = Record<string, string | number>;
|
|
15
|
-
type QueryParameters = Record<string, unknown>;
|
|
16
|
-
|
|
17
|
-
type EmptyObject = Record<string, never>;
|
|
18
|
-
type EmptyRequestComponent = EmptyObject | null;
|
|
19
|
-
type RequestWithOptionalHeaders = {
|
|
20
|
-
headers?: HttpHeaders;
|
|
21
|
-
};
|
|
22
|
-
type RequestWithData<TData> = TData extends EmptyRequestComponent ? RequestWithOptionalHeaders : {
|
|
23
|
-
data: TData;
|
|
24
|
-
};
|
|
25
|
-
type RequestWithPathParameters<TPathParameters> = TPathParameters extends EmptyRequestComponent ? RequestWithOptionalHeaders : {
|
|
26
|
-
pathParameters: TPathParameters;
|
|
27
|
-
};
|
|
28
|
-
type RequestWithHeaders<THeaders> = THeaders extends EmptyRequestComponent ? RequestWithOptionalHeaders : {
|
|
29
|
-
headers: THeaders & HttpHeaders;
|
|
30
|
-
};
|
|
31
|
-
type RequestWithQueryParameters<TQuery> = TQuery extends EmptyRequestComponent ? RequestWithOptionalHeaders : {
|
|
32
|
-
queryParameters: TQuery & HttpHeaders;
|
|
33
|
-
};
|
|
34
|
-
type RequestType<TData extends HttpPayload = EmptyRequestComponent, TPathParameters extends PathParameters | EmptyRequestComponent = EmptyRequestComponent, TQueryParameters extends QueryParameters | EmptyRequestComponent = EmptyRequestComponent, THeader extends HttpHeaders | EmptyRequestComponent = EmptyRequestComponent> = TData | TPathParameters | THeader | TQueryParameters extends EmptyRequestComponent ? RequestWithOptionalHeaders : RequestWithData<TData> & RequestWithPathParameters<TPathParameters> & RequestWithQueryParameters<TQueryParameters> & RequestWithHeaders<THeader>;
|
|
35
|
-
type AnyRequest = RequestType<any, any, any, any>;
|
|
36
|
-
|
|
37
|
-
type Response<TContent extends HttpPayload = HttpPayload, TStatus extends HttpStatus = HttpStatus, TMediaType extends HttpMediaType | null = HttpMediaType> = AxiosResponse<TContent> & {
|
|
38
|
-
status: TStatus;
|
|
39
|
-
mediaType: TMediaType;
|
|
40
|
-
};
|
|
41
|
-
type AnyResponse = Response<any, any, any>;
|
|
42
|
-
|
|
43
|
-
interface OpenAPIOperation<TIgnoredRequest extends AnyRequest = RequestType, IgnoredResponse extends AnyResponse = Response> {
|
|
44
|
-
operationId: string;
|
|
45
|
-
path: string;
|
|
46
|
-
method: HttpMethod;
|
|
47
|
-
}
|
|
48
|
-
type InferredRequestType<TOp> = TOp extends OpenAPIOperation<infer TReq> ? TReq : never;
|
|
49
|
-
type InferredResponseType<TOp> = TOp extends OpenAPIOperation<RequestType, infer TRes> ? TRes : never;
|
|
50
|
-
type ResponseData<TOp, TStatus extends HttpStatus = 200> = Extract<InferredResponseType<TOp>, {
|
|
51
|
-
status: TStatus;
|
|
52
|
-
}>["data"];
|
|
53
|
-
type RequestData<TOp> = TOp extends OpenAPIOperation ? InferredRequestType<TOp> extends {
|
|
54
|
-
data: infer TData;
|
|
55
|
-
} ? TData : never : never;
|
|
56
|
-
|
|
57
|
-
type PartialOnNoRequiredKeysDeep<T> = PartialOnUndefinedDeep<OmitIndexSignature<{
|
|
58
|
-
[TKey in keyof T]: HasRequiredKeys<PartialOnNoRequiredKeysDeep<T[TKey]>> extends true ? T[TKey] : T[TKey] | undefined;
|
|
59
|
-
}>>;
|
|
60
|
-
type NullableOnNoRequiredKeysDeep<T> = HasRequiredKeys<PartialOnNoRequiredKeysDeep<T>> extends true ? PartialOnNoRequiredKeysDeep<T> : PartialOnNoRequiredKeysDeep<T> | null;
|
|
61
|
-
|
|
62
|
-
type UnboxPathParameters<T> = T extends {
|
|
63
|
-
pathParameters: infer TPath;
|
|
64
|
-
} ? Omit<T, "pathParameters"> & TPath : T;
|
|
65
|
-
type RequestObject<TOp extends OpenAPIOperation> = NullableOnNoRequiredKeysDeep<UnboxPathParameters<InferredRequestType<TOp>>>;
|
|
66
|
-
type ResponsePromise<TOp extends OpenAPIOperation> = Promise<InferredResponseType<TOp>>;
|
|
67
|
-
type RequestFunctionWithOptionalRequest<TOp extends OpenAPIOperation> = (request?: RequestObject<TOp>) => ResponsePromise<TOp>;
|
|
68
|
-
type RequestFunctionWithRequiredRequest<TOp extends OpenAPIOperation> = (request: RequestObject<TOp>) => ResponsePromise<TOp>;
|
|
69
|
-
type RequestFunction<TOp extends OpenAPIOperation> = null extends RequestObject<TOp> ? RequestFunctionWithOptionalRequest<TOp> : RequestFunctionWithRequiredRequest<TOp>;
|
|
70
|
-
|
|
71
|
-
export { AnyResponse as A, HttpPayload as H, InferredRequestType as I, OpenAPIOperation as O, PathParameters as P, QueryParameters as Q, Response as R, RequestFunction as a, RequestObject as b, ResponsePromise as c, RequestType as d, AnyRequest as e, InferredResponseType as f, ResponseData as g, RequestData as h, HttpStatus as i, HttpMediaType as j, HttpMethod as k, HttpHeaders as l };
|
package/dist/chunk-PEYA5TMK.js
DELETED
|
@@ -1,154 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
-
var __export = (target, all) => {
|
|
6
|
-
for (var name in all)
|
|
7
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
-
};
|
|
9
|
-
var __copyProps = (to, from, except, desc) => {
|
|
10
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
-
for (let key of __getOwnPropNames(from))
|
|
12
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
-
}
|
|
15
|
-
return to;
|
|
16
|
-
};
|
|
17
|
-
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
18
|
-
|
|
19
|
-
// src/core/OpenAPIPath.ts
|
|
20
|
-
var OpenAPIPath = class _OpenAPIPath {
|
|
21
|
-
constructor(rawPath, params) {
|
|
22
|
-
this.rawPath = rawPath;
|
|
23
|
-
this.params = params;
|
|
24
|
-
}
|
|
25
|
-
buildUrl() {
|
|
26
|
-
return _OpenAPIPath.setPathParams(this.rawPath, this.params);
|
|
27
|
-
}
|
|
28
|
-
static setPathParams(path, params) {
|
|
29
|
-
const asEntries = Object.entries(params ?? {});
|
|
30
|
-
const finalPath = asEntries.reduce((path2, entry) => {
|
|
31
|
-
const [key, value] = entry;
|
|
32
|
-
return path2.replace(`{${key}}`, encodeURIComponent(value));
|
|
33
|
-
}, path);
|
|
34
|
-
return finalPath.startsWith("/") ? finalPath.substring(1) : finalPath;
|
|
35
|
-
}
|
|
36
|
-
};
|
|
37
|
-
var OpenAPIPath_default = OpenAPIPath;
|
|
38
|
-
|
|
39
|
-
// src/core/Request.ts
|
|
40
|
-
var Request = class {
|
|
41
|
-
constructor(operationDescriptor, requestObject) {
|
|
42
|
-
this.operationDescriptor = operationDescriptor;
|
|
43
|
-
this.requestObject = requestObject;
|
|
44
|
-
this.requestConfig = Object.freeze(this.buildAxiosConfig());
|
|
45
|
-
}
|
|
46
|
-
execute(axios) {
|
|
47
|
-
return axios.request(this.requestConfig);
|
|
48
|
-
}
|
|
49
|
-
buildAxiosConfig() {
|
|
50
|
-
const { method, path } = this.operationDescriptor;
|
|
51
|
-
const pathParameters = this.requestObject;
|
|
52
|
-
const openApiPath = new OpenAPIPath_default(path, pathParameters);
|
|
53
|
-
const url = openApiPath.buildUrl();
|
|
54
|
-
const data = this.requestObject && "data" in this.requestObject ? this.requestObject.data : void 0;
|
|
55
|
-
const headersConfig = this.requestObject && "headers" in this.requestObject ? this.requestObject.headers : void 0;
|
|
56
|
-
const headers = headersConfig ? this.makeAxiosHeaders(headersConfig) : void 0;
|
|
57
|
-
const queryParametersConfig = this.requestObject && "queryParameters" in this.requestObject ? this.requestObject.queryParameters : void 0;
|
|
58
|
-
const params = this.convertQueryToUrlSearchParams(queryParametersConfig);
|
|
59
|
-
return {
|
|
60
|
-
url,
|
|
61
|
-
method,
|
|
62
|
-
headers,
|
|
63
|
-
// Must be a plain object or an URLSearchParams object
|
|
64
|
-
params,
|
|
65
|
-
data,
|
|
66
|
-
validateStatus: () => true
|
|
67
|
-
};
|
|
68
|
-
}
|
|
69
|
-
makeAxiosHeaders(headers) {
|
|
70
|
-
return Object.fromEntries(
|
|
71
|
-
Object.entries(headers).map(([key, value]) => [key, value?.toString()])
|
|
72
|
-
);
|
|
73
|
-
}
|
|
74
|
-
convertQueryToUrlSearchParams(query) {
|
|
75
|
-
if (query === void 0 || query === null) {
|
|
76
|
-
return void 0;
|
|
77
|
-
}
|
|
78
|
-
if (query instanceof URLSearchParams) {
|
|
79
|
-
return query;
|
|
80
|
-
}
|
|
81
|
-
if (typeof query === "string") {
|
|
82
|
-
return new URLSearchParams(query);
|
|
83
|
-
}
|
|
84
|
-
if (typeof query === "object") {
|
|
85
|
-
const searchParams = new URLSearchParams();
|
|
86
|
-
for (const [key, value] of Object.entries(query)) {
|
|
87
|
-
if (Array.isArray(value)) {
|
|
88
|
-
for (const arrayItem of value) {
|
|
89
|
-
searchParams.append(key, arrayItem);
|
|
90
|
-
}
|
|
91
|
-
} else {
|
|
92
|
-
searchParams.append(
|
|
93
|
-
key,
|
|
94
|
-
typeof value === "string" || typeof value === "number" || typeof value === "boolean" ? value.toString() : JSON.stringify(value)
|
|
95
|
-
);
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
return searchParams;
|
|
99
|
-
}
|
|
100
|
-
throw new Error(`Unexpected query parameter type (${typeof query})`);
|
|
101
|
-
}
|
|
102
|
-
};
|
|
103
|
-
var Request_default = Request;
|
|
104
|
-
|
|
105
|
-
// src/core/ApiClientError.ts
|
|
106
|
-
import { AxiosError } from "axios";
|
|
107
|
-
var ApiClientError = class _ApiClientError extends AxiosError {
|
|
108
|
-
constructor(message, code, config, request, response) {
|
|
109
|
-
super(message, code, config, request, response);
|
|
110
|
-
Object.setPrototypeOf(this, _ApiClientError.prototype);
|
|
111
|
-
this.name = "ApiClientError";
|
|
112
|
-
}
|
|
113
|
-
static fromResponse(message, response) {
|
|
114
|
-
return new _ApiClientError(
|
|
115
|
-
message,
|
|
116
|
-
void 0,
|
|
117
|
-
response.config,
|
|
118
|
-
response.request,
|
|
119
|
-
response
|
|
120
|
-
);
|
|
121
|
-
}
|
|
122
|
-
};
|
|
123
|
-
var ApiClientError_default = ApiClientError;
|
|
124
|
-
|
|
125
|
-
// src/types/assertStatus.ts
|
|
126
|
-
function assertStatus(response, expectedStatus) {
|
|
127
|
-
if (response.status !== expectedStatus) {
|
|
128
|
-
throw ApiClientError_default.fromResponse(
|
|
129
|
-
`Unexpected response status (expected ${expectedStatus}, got: ${response.status})`,
|
|
130
|
-
response
|
|
131
|
-
);
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
// src/types/assertOneOfStatus.ts
|
|
136
|
-
function assertOneOfStatus(response, expectedStatus) {
|
|
137
|
-
if (!expectedStatus.includes(response.status)) {
|
|
138
|
-
throw ApiClientError_default.fromResponse(
|
|
139
|
-
`Unexpected response status (expected ${expectedStatus}, got: ${response.status})`,
|
|
140
|
-
response
|
|
141
|
-
);
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
export {
|
|
146
|
-
__export,
|
|
147
|
-
__reExport,
|
|
148
|
-
OpenAPIPath,
|
|
149
|
-
Request,
|
|
150
|
-
Request_default,
|
|
151
|
-
ApiClientError,
|
|
152
|
-
assertStatus,
|
|
153
|
-
assertOneOfStatus
|
|
154
|
-
};
|