@mittwald/api-client-commons 4.2.0-alpha.3 → 4.2.0-alpha.4

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.
Files changed (119) hide show
  1. package/dist/RequestFunction-b1412636.d.ts +71 -0
  2. package/dist/chunk-PEYA5TMK.js +154 -0
  3. package/dist/index.cjs +196 -0
  4. package/dist/index.d.cts +49 -0
  5. package/dist/index.d.ts +49 -0
  6. package/dist/index.js +48 -0
  7. package/dist/react.cjs +185 -0
  8. package/dist/react.d.cts +19 -0
  9. package/dist/react.d.ts +19 -0
  10. package/dist/react.js +45 -0
  11. package/package.json +21 -29
  12. package/dist/cjs/axios.d.ts +0 -1
  13. package/dist/cjs/axios.js +0 -17
  14. package/dist/cjs/core/ApiClientBase.d.ts +0 -9
  15. package/dist/cjs/core/ApiClientBase.js +0 -42
  16. package/dist/cjs/core/ApiClientError.d.ts +0 -7
  17. package/dist/cjs/core/ApiClientError.js +0 -16
  18. package/dist/cjs/core/OpenAPIPath.d.ts +0 -9
  19. package/dist/cjs/core/OpenAPIPath.js +0 -22
  20. package/dist/cjs/core/Request.d.ts +0 -13
  21. package/dist/cjs/core/Request.js +0 -80
  22. package/dist/cjs/core/Request.test.d.ts +0 -1
  23. package/dist/cjs/core/Request.test.js +0 -58
  24. package/dist/cjs/core/index.d.ts +0 -4
  25. package/dist/cjs/core/index.js +0 -20
  26. package/dist/cjs/index.d.ts +0 -3
  27. package/dist/cjs/index.js +0 -19
  28. package/dist/cjs/react/ApiCallAsyncResourceFactory.d.ts +0 -12
  29. package/dist/cjs/react/ApiCallAsyncResourceFactory.js +0 -52
  30. package/dist/cjs/react/ApiCallAsyncResourceFactory.test-types.d.ts +0 -1
  31. package/dist/cjs/react/ApiCallAsyncResourceFactory.test-types.js +0 -38
  32. package/dist/cjs/react/ApiCallAsyncResourceFactory.test.d.ts +0 -1
  33. package/dist/cjs/react/ApiCallAsyncResourceFactory.test.js +0 -57
  34. package/dist/cjs/react/index.d.ts +0 -1
  35. package/dist/cjs/react/index.js +0 -17
  36. package/dist/cjs/react/types.d.ts +0 -3
  37. package/dist/cjs/react/types.js +0 -2
  38. package/dist/cjs/types/NullableOnNoRequiredKeysDeep.d.ts +0 -6
  39. package/dist/cjs/types/NullableOnNoRequiredKeysDeep.js +0 -2
  40. package/dist/cjs/types/OpenAPIOperation.d.ts +0 -16
  41. package/dist/cjs/types/OpenAPIOperation.js +0 -2
  42. package/dist/cjs/types/RequestFunction.d.ts +0 -11
  43. package/dist/cjs/types/RequestFunction.js +0 -2
  44. package/dist/cjs/types/RequestFunction.test-types.d.ts +0 -1
  45. package/dist/cjs/types/RequestFunction.test-types.js +0 -30
  46. package/dist/cjs/types/RequestType.d.ts +0 -21
  47. package/dist/cjs/types/RequestType.js +0 -2
  48. package/dist/cjs/types/RequestType.test-types.d.ts +0 -1
  49. package/dist/cjs/types/RequestType.test-types.js +0 -148
  50. package/dist/cjs/types/Response.d.ts +0 -7
  51. package/dist/cjs/types/Response.js +0 -2
  52. package/dist/cjs/types/Response.test-types.d.ts +0 -1
  53. package/dist/cjs/types/Response.test-types.js +0 -43
  54. package/dist/cjs/types/assertOneOfStatus.d.ts +0 -4
  55. package/dist/cjs/types/assertOneOfStatus.js +0 -13
  56. package/dist/cjs/types/assertStatus.d.ts +0 -5
  57. package/dist/cjs/types/assertStatus.js +0 -14
  58. package/dist/cjs/types/assertStatus.test-types.d.ts +0 -1
  59. package/dist/cjs/types/assertStatus.test-types.js +0 -13
  60. package/dist/cjs/types/http.d.ts +0 -13
  61. package/dist/cjs/types/http.js +0 -2
  62. package/dist/cjs/types/index.d.ts +0 -8
  63. package/dist/cjs/types/index.js +0 -24
  64. package/dist/cjs/types/simplify.d.ts +0 -3
  65. package/dist/cjs/types/simplify.js +0 -2
  66. package/dist/esm/axios.d.ts +0 -1
  67. package/dist/esm/axios.js +0 -1
  68. package/dist/esm/core/ApiClientBase.d.ts +0 -9
  69. package/dist/esm/core/ApiClientBase.js +0 -13
  70. package/dist/esm/core/ApiClientError.d.ts +0 -7
  71. package/dist/esm/core/ApiClientError.js +0 -12
  72. package/dist/esm/core/OpenAPIPath.d.ts +0 -9
  73. package/dist/esm/core/OpenAPIPath.js +0 -20
  74. package/dist/esm/core/Request.d.ts +0 -13
  75. package/dist/esm/core/Request.js +0 -76
  76. package/dist/esm/core/Request.test.d.ts +0 -1
  77. package/dist/esm/core/Request.test.js +0 -53
  78. package/dist/esm/core/index.d.ts +0 -4
  79. package/dist/esm/core/index.js +0 -4
  80. package/dist/esm/index.d.ts +0 -3
  81. package/dist/esm/index.js +0 -3
  82. package/dist/esm/react/ApiCallAsyncResourceFactory.d.ts +0 -12
  83. package/dist/esm/react/ApiCallAsyncResourceFactory.js +0 -35
  84. package/dist/esm/react/ApiCallAsyncResourceFactory.test-types.d.ts +0 -1
  85. package/dist/esm/react/ApiCallAsyncResourceFactory.test-types.js +0 -36
  86. package/dist/esm/react/ApiCallAsyncResourceFactory.test.d.ts +0 -1
  87. package/dist/esm/react/ApiCallAsyncResourceFactory.test.js +0 -46
  88. package/dist/esm/react/index.d.ts +0 -1
  89. package/dist/esm/react/index.js +0 -1
  90. package/dist/esm/react/types.d.ts +0 -3
  91. package/dist/esm/react/types.js +0 -1
  92. package/dist/esm/types/NullableOnNoRequiredKeysDeep.d.ts +0 -6
  93. package/dist/esm/types/NullableOnNoRequiredKeysDeep.js +0 -1
  94. package/dist/esm/types/OpenAPIOperation.d.ts +0 -16
  95. package/dist/esm/types/OpenAPIOperation.js +0 -1
  96. package/dist/esm/types/RequestFunction.d.ts +0 -11
  97. package/dist/esm/types/RequestFunction.js +0 -1
  98. package/dist/esm/types/RequestFunction.test-types.d.ts +0 -1
  99. package/dist/esm/types/RequestFunction.test-types.js +0 -29
  100. package/dist/esm/types/RequestType.d.ts +0 -21
  101. package/dist/esm/types/RequestType.js +0 -1
  102. package/dist/esm/types/RequestType.test-types.d.ts +0 -1
  103. package/dist/esm/types/RequestType.test-types.js +0 -146
  104. package/dist/esm/types/Response.d.ts +0 -7
  105. package/dist/esm/types/Response.js +0 -1
  106. package/dist/esm/types/Response.test-types.d.ts +0 -1
  107. package/dist/esm/types/Response.test-types.js +0 -70
  108. package/dist/esm/types/assertOneOfStatus.d.ts +0 -4
  109. package/dist/esm/types/assertOneOfStatus.js +0 -6
  110. package/dist/esm/types/assertStatus.d.ts +0 -5
  111. package/dist/esm/types/assertStatus.js +0 -7
  112. package/dist/esm/types/assertStatus.test-types.d.ts +0 -1
  113. package/dist/esm/types/assertStatus.test-types.js +0 -8
  114. package/dist/esm/types/http.d.ts +0 -13
  115. package/dist/esm/types/http.js +0 -1
  116. package/dist/esm/types/index.d.ts +0 -8
  117. package/dist/esm/types/index.js +0 -8
  118. package/dist/esm/types/simplify.d.ts +0 -3
  119. package/dist/esm/types/simplify.js +0 -1
@@ -0,0 +1,71 @@
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 };
@@ -0,0 +1,154 @@
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
+ };
package/dist/index.cjs ADDED
@@ -0,0 +1,196 @@
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
+ });
@@ -0,0 +1,49 @@
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 };
@@ -0,0 +1,49 @@
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 ADDED
@@ -0,0 +1,48 @@
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
+ };