@tapis/tapis-typescript-systems 0.0.6 → 0.0.7
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/.openapi-generator/FILES +3 -0
- package/.openapi-generator/VERSION +1 -1
- package/README.md +5 -4
- package/dist/apis/ChildSystemsApi.d.ts +10 -10
- package/dist/apis/ChildSystemsApi.js +84 -65
- package/dist/apis/CredentialsApi.d.ts +25 -24
- package/dist/apis/CredentialsApi.js +172 -138
- package/dist/apis/GeneralApi.d.ts +6 -6
- package/dist/apis/GeneralApi.js +18 -11
- package/dist/apis/PermissionsApi.d.ts +10 -10
- package/dist/apis/PermissionsApi.js +112 -89
- package/dist/apis/SchedulerProfilesApi.d.ts +10 -10
- package/dist/apis/SchedulerProfilesApi.js +95 -72
- package/dist/apis/SharingApi.d.ts +12 -12
- package/dist/apis/SharingApi.js +122 -95
- package/dist/apis/SystemsApi.d.ts +61 -46
- package/dist/apis/SystemsApi.js +473 -341
- package/dist/apis/index.js +21 -10
- package/dist/index.d.ts +2 -2
- package/dist/index.js +17 -6
- package/dist/models/AuthnEnum.d.ts +12 -9
- package/dist/models/AuthnEnum.js +28 -13
- package/dist/models/Capability.d.ts +9 -3
- package/dist/models/Capability.js +37 -22
- package/dist/models/CategoryEnum.d.ts +14 -12
- package/dist/models/CategoryEnum.js +30 -16
- package/dist/models/Credential.d.ts +26 -3
- package/dist/models/Credential.js +47 -33
- package/dist/models/DatatypeEnum.d.ts +11 -9
- package/dist/models/DatatypeEnum.js +27 -13
- package/dist/models/JobRuntime.d.ts +8 -3
- package/dist/models/JobRuntime.js +27 -17
- package/dist/models/KeyValueInputModeEnum.d.ts +10 -8
- package/dist/models/KeyValueInputModeEnum.js +26 -12
- package/dist/models/KeyValuePair.d.ts +8 -3
- package/dist/models/KeyValuePair.js +32 -22
- package/dist/models/ListTypeEnum.d.ts +9 -7
- package/dist/models/ListTypeEnum.js +25 -11
- package/dist/models/LogicalQueue.d.ts +13 -2
- package/dist/models/LogicalQueue.js +48 -34
- package/dist/models/ModuleLoadSpec.d.ts +7 -2
- package/dist/models/ModuleLoadSpec.js +25 -15
- package/dist/models/OperationTypeEnum.d.ts +20 -18
- package/dist/models/OperationTypeEnum.js +36 -22
- package/dist/models/ReqMatchConstraints.d.ts +7 -2
- package/dist/models/ReqMatchConstraints.js +23 -12
- package/dist/models/ReqPatchSystem.d.ts +13 -3
- package/dist/models/ReqPatchSystem.js +76 -63
- package/dist/models/ReqPerms.d.ts +7 -2
- package/dist/models/ReqPerms.js +23 -12
- package/dist/models/ReqPostChildSystem.d.ts +7 -2
- package/dist/models/ReqPostChildSystem.js +28 -16
- package/dist/models/ReqPostPutCredential.d.ts +7 -2
- package/dist/models/ReqPostPutCredential.js +36 -28
- package/dist/models/ReqPostSchedulerProfile.d.ts +9 -3
- package/dist/models/ReqPostSchedulerProfile.js +33 -22
- package/dist/models/ReqPostSystem.d.ts +15 -3
- package/dist/models/ReqPostSystem.js +101 -76
- package/dist/models/ReqPutSystem.d.ts +13 -3
- package/dist/models/ReqPutSystem.js +74 -61
- package/dist/models/ReqSearchSystems.d.ts +7 -2
- package/dist/models/ReqSearchSystems.js +23 -12
- package/dist/models/ReqShareUpdate.d.ts +7 -2
- package/dist/models/ReqShareUpdate.js +23 -12
- package/dist/models/ReqUnlinkChildren.d.ts +7 -2
- package/dist/models/ReqUnlinkChildren.js +22 -14
- package/dist/models/ReqUpdateCredential.d.ts +7 -2
- package/dist/models/ReqUpdateCredential.js +38 -30
- package/dist/models/RespBasic.d.ts +7 -2
- package/dist/models/RespBasic.js +34 -26
- package/dist/models/RespBoolean.d.ts +8 -3
- package/dist/models/RespBoolean.js +35 -27
- package/dist/models/RespChangeCount.d.ts +8 -3
- package/dist/models/RespChangeCount.js +35 -27
- package/dist/models/RespCredential.d.ts +8 -3
- package/dist/models/RespCredential.js +35 -27
- package/dist/models/RespGlobusAuthUrl.d.ts +8 -3
- package/dist/models/RespGlobusAuthUrl.js +35 -27
- package/dist/models/RespName.d.ts +69 -0
- package/dist/models/RespName.js +62 -0
- package/dist/models/RespNameArray.d.ts +8 -3
- package/dist/models/RespNameArray.js +35 -27
- package/dist/models/RespResourceUrl.d.ts +8 -3
- package/dist/models/RespResourceUrl.js +35 -27
- package/dist/models/RespSchedulerProfile.d.ts +8 -3
- package/dist/models/RespSchedulerProfile.js +35 -27
- package/dist/models/RespSchedulerProfiles.d.ts +8 -3
- package/dist/models/RespSchedulerProfiles.js +35 -27
- package/dist/models/RespShareInfo.d.ts +8 -3
- package/dist/models/RespShareInfo.js +35 -27
- package/dist/models/RespSystem.d.ts +8 -3
- package/dist/models/RespSystem.js +35 -27
- package/dist/models/RespSystemHistory.d.ts +8 -3
- package/dist/models/RespSystemHistory.js +35 -27
- package/dist/models/RespSystems.d.ts +9 -3
- package/dist/models/RespSystems.js +36 -27
- package/dist/models/RespSystemsMetadata.d.ts +7 -2
- package/dist/models/RespSystemsMetadata.js +32 -24
- package/dist/models/ResultBoolean.d.ts +7 -2
- package/dist/models/ResultBoolean.js +22 -14
- package/dist/models/ResultChangeCount.d.ts +7 -2
- package/dist/models/ResultChangeCount.js +22 -14
- package/dist/models/ResultGlobusAuthUrl.d.ts +7 -2
- package/dist/models/ResultGlobusAuthUrl.js +26 -18
- package/dist/models/ResultName.d.ts +32 -0
- package/dist/models/ResultName.js +49 -0
- package/dist/models/ResultNameArray.d.ts +7 -2
- package/dist/models/ResultNameArray.js +22 -14
- package/dist/models/ResultResourceUrl.d.ts +7 -2
- package/dist/models/ResultResourceUrl.js +22 -14
- package/dist/models/RuntimeTypeEnum.d.ts +9 -7
- package/dist/models/RuntimeTypeEnum.js +25 -11
- package/dist/models/SchedulerHiddenOptionEnum.d.ts +8 -5
- package/dist/models/SchedulerHiddenOptionEnum.js +24 -9
- package/dist/models/SchedulerProfile.d.ts +9 -3
- package/dist/models/SchedulerProfile.js +35 -24
- package/dist/models/SchedulerTypeEnum.d.ts +12 -10
- package/dist/models/SchedulerTypeEnum.js +28 -14
- package/dist/models/ShareInfo.d.ts +14 -2
- package/dist/models/ShareInfo.js +29 -13
- package/dist/models/SkShareRecord.d.ts +86 -0
- package/dist/models/SkShareRecord.js +67 -0
- package/dist/models/SystemHistory.d.ts +8 -3
- package/dist/models/SystemHistory.js +35 -27
- package/dist/models/SystemTypeEnum.d.ts +10 -8
- package/dist/models/SystemTypeEnum.js +26 -12
- package/dist/models/TapisSystem.d.ts +39 -21
- package/dist/models/TapisSystem.js +114 -97
- package/dist/models/index.d.ts +3 -0
- package/dist/models/index.js +68 -54
- package/dist/runtime.d.ts +79 -37
- package/dist/runtime.js +311 -169
- package/package.json +6 -2
- package/src/apis/ChildSystemsApi.ts +47 -33
- package/src/apis/CredentialsApi.ts +124 -75
- package/src/apis/GeneralApi.ts +9 -7
- package/src/apis/PermissionsApi.ts +80 -45
- package/src/apis/SchedulerProfilesApi.ts +40 -29
- package/src/apis/SharingApi.ts +64 -41
- package/src/apis/SystemsApi.ts +306 -189
- package/src/index.ts +2 -2
- package/src/models/AuthnEnum.ts +26 -8
- package/src/models/Capability.ts +37 -19
- package/src/models/CategoryEnum.ts +28 -11
- package/src/models/Credential.ts +67 -31
- package/src/models/DatatypeEnum.ts +25 -8
- package/src/models/JobRuntime.ts +27 -14
- package/src/models/KeyValueInputModeEnum.ts +24 -7
- package/src/models/KeyValuePair.ts +33 -20
- package/src/models/ListTypeEnum.ts +23 -6
- package/src/models/LogicalQueue.ts +50 -31
- package/src/models/ModuleLoadSpec.ts +22 -12
- package/src/models/OperationTypeEnum.ts +34 -17
- package/src/models/ReqMatchConstraints.ts +20 -10
- package/src/models/ReqPatchSystem.ts +96 -69
- package/src/models/ReqPerms.ts +20 -10
- package/src/models/ReqPostChildSystem.ts +24 -13
- package/src/models/ReqPostPutCredential.ts +34 -25
- package/src/models/ReqPostSchedulerProfile.ts +38 -24
- package/src/models/ReqPostSystem.ts +123 -85
- package/src/models/ReqPutSystem.ts +94 -67
- package/src/models/ReqSearchSystems.ts +20 -10
- package/src/models/ReqShareUpdate.ts +20 -10
- package/src/models/ReqUnlinkChildren.ts +20 -11
- package/src/models/ReqUpdateCredential.ts +36 -27
- package/src/models/RespBasic.ts +32 -23
- package/src/models/RespBoolean.ts +35 -25
- package/src/models/RespChangeCount.ts +35 -25
- package/src/models/RespCredential.ts +35 -25
- package/src/models/RespGlobusAuthUrl.ts +35 -25
- package/src/models/RespName.ts +121 -0
- package/src/models/RespNameArray.ts +35 -25
- package/src/models/RespResourceUrl.ts +35 -25
- package/src/models/RespSchedulerProfile.ts +35 -25
- package/src/models/RespSchedulerProfiles.ts +35 -25
- package/src/models/RespShareInfo.ts +35 -25
- package/src/models/RespSystem.ts +35 -25
- package/src/models/RespSystemHistory.ts +35 -25
- package/src/models/RespSystems.ts +42 -29
- package/src/models/RespSystemsMetadata.ts +30 -21
- package/src/models/ResultBoolean.ts +20 -11
- package/src/models/ResultChangeCount.ts +20 -11
- package/src/models/ResultGlobusAuthUrl.ts +24 -15
- package/src/models/ResultName.ts +65 -0
- package/src/models/ResultNameArray.ts +20 -11
- package/src/models/ResultResourceUrl.ts +20 -11
- package/src/models/RuntimeTypeEnum.ts +23 -6
- package/src/models/SchedulerHiddenOptionEnum.ts +22 -4
- package/src/models/SchedulerProfile.ts +40 -26
- package/src/models/SchedulerTypeEnum.ts +26 -9
- package/src/models/ShareInfo.ts +38 -11
- package/src/models/SkShareRecord.ts +137 -0
- package/src/models/SystemHistory.ts +37 -25
- package/src/models/SystemTypeEnum.ts +24 -7
- package/src/models/TapisSystem.ts +167 -126
- package/src/models/index.ts +3 -0
- package/src/runtime.ts +217 -106
package/src/runtime.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* Tapis Systems API
|
|
5
5
|
* The Tapis Systems API provides for management of Tapis Systems including permissions, credentials and Scheduler Profiles.
|
|
6
6
|
*
|
|
7
|
-
* The version of the OpenAPI document:
|
|
7
|
+
* The version of the OpenAPI document: 25Q4.2
|
|
8
8
|
* Contact: cicsupport@tacc.utexas.edu
|
|
9
9
|
*
|
|
10
10
|
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
|
@@ -15,16 +15,86 @@
|
|
|
15
15
|
|
|
16
16
|
export const BASE_PATH = "http://localhost:8080".replace(/\/+$/, "");
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
export interface ConfigurationParameters {
|
|
19
|
+
basePath?: string; // override base path
|
|
20
|
+
fetchApi?: FetchAPI; // override for fetch implementation
|
|
21
|
+
middleware?: Middleware[]; // middleware to apply before/after fetch requests
|
|
22
|
+
queryParamsStringify?: (params: HTTPQuery) => string; // stringify function for query strings
|
|
23
|
+
username?: string; // parameter for basic security
|
|
24
|
+
password?: string; // parameter for basic security
|
|
25
|
+
apiKey?: string | Promise<string> | ((name: string) => string | Promise<string>); // parameter for apiKey security
|
|
26
|
+
accessToken?: string | Promise<string> | ((name?: string, scopes?: string[]) => string | Promise<string>); // parameter for oauth2 security
|
|
27
|
+
headers?: HTTPHeaders; //header params we want to use on every request
|
|
28
|
+
credentials?: RequestCredentials; //value for the credentials param we want to use on each request
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export class Configuration {
|
|
32
|
+
constructor(private configuration: ConfigurationParameters = {}) {}
|
|
33
|
+
|
|
34
|
+
set config(configuration: Configuration) {
|
|
35
|
+
this.configuration = configuration;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
get basePath(): string {
|
|
39
|
+
return this.configuration.basePath != null ? this.configuration.basePath : BASE_PATH;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
get fetchApi(): FetchAPI | undefined {
|
|
43
|
+
return this.configuration.fetchApi;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
get middleware(): Middleware[] {
|
|
47
|
+
return this.configuration.middleware || [];
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
get queryParamsStringify(): (params: HTTPQuery) => string {
|
|
51
|
+
return this.configuration.queryParamsStringify || querystring;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
get username(): string | undefined {
|
|
55
|
+
return this.configuration.username;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
get password(): string | undefined {
|
|
59
|
+
return this.configuration.password;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
get apiKey(): ((name: string) => string | Promise<string>) | undefined {
|
|
63
|
+
const apiKey = this.configuration.apiKey;
|
|
64
|
+
if (apiKey) {
|
|
65
|
+
return typeof apiKey === 'function' ? apiKey : () => apiKey;
|
|
66
|
+
}
|
|
67
|
+
return undefined;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
get accessToken(): ((name?: string, scopes?: string[]) => string | Promise<string>) | undefined {
|
|
71
|
+
const accessToken = this.configuration.accessToken;
|
|
72
|
+
if (accessToken) {
|
|
73
|
+
return typeof accessToken === 'function' ? accessToken : async () => accessToken;
|
|
74
|
+
}
|
|
75
|
+
return undefined;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
get headers(): HTTPHeaders | undefined {
|
|
79
|
+
return this.configuration.headers;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
get credentials(): RequestCredentials | undefined {
|
|
83
|
+
return this.configuration.credentials;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export const DefaultConfig = new Configuration();
|
|
19
88
|
|
|
20
89
|
/**
|
|
21
90
|
* This is the base class for all generated API classes.
|
|
22
91
|
*/
|
|
23
92
|
export class BaseAPI {
|
|
24
93
|
|
|
94
|
+
private static readonly jsonRegex = new RegExp('^(:?application\/json|[^;/ \t]+\/[^;/ \t]+[+]json)[ \t]*(:?;.*)?$', 'i');
|
|
25
95
|
private middleware: Middleware[];
|
|
26
96
|
|
|
27
|
-
constructor(protected configuration =
|
|
97
|
+
constructor(protected configuration = DefaultConfig) {
|
|
28
98
|
this.middleware = configuration.middleware;
|
|
29
99
|
}
|
|
30
100
|
|
|
@@ -44,16 +114,33 @@ export class BaseAPI {
|
|
|
44
114
|
return this.withMiddleware<T>(...middlewares);
|
|
45
115
|
}
|
|
46
116
|
|
|
47
|
-
|
|
48
|
-
|
|
117
|
+
/**
|
|
118
|
+
* Check if the given MIME is a JSON MIME.
|
|
119
|
+
* JSON MIME examples:
|
|
120
|
+
* application/json
|
|
121
|
+
* application/json; charset=UTF8
|
|
122
|
+
* APPLICATION/JSON
|
|
123
|
+
* application/vnd.company+json
|
|
124
|
+
* @param mime - MIME (Multipurpose Internet Mail Extensions)
|
|
125
|
+
* @return True if the given MIME is JSON, false otherwise.
|
|
126
|
+
*/
|
|
127
|
+
protected isJsonMime(mime: string | null | undefined): boolean {
|
|
128
|
+
if (!mime) {
|
|
129
|
+
return false;
|
|
130
|
+
}
|
|
131
|
+
return BaseAPI.jsonRegex.test(mime);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
protected async request(context: RequestOpts, initOverrides?: RequestInit | InitOverrideFunction): Promise<Response> {
|
|
135
|
+
const { url, init } = await this.createFetchParams(context, initOverrides);
|
|
49
136
|
const response = await this.fetchApi(url, init);
|
|
50
|
-
if (response.status >= 200 && response.status < 300) {
|
|
137
|
+
if (response && (response.status >= 200 && response.status < 300)) {
|
|
51
138
|
return response;
|
|
52
139
|
}
|
|
53
|
-
throw response;
|
|
140
|
+
throw new ResponseError(response, 'Response returned an error code');
|
|
54
141
|
}
|
|
55
142
|
|
|
56
|
-
private createFetchParams(context: RequestOpts, initOverrides?: RequestInit) {
|
|
143
|
+
private async createFetchParams(context: RequestOpts, initOverrides?: RequestInit | InitOverrideFunction) {
|
|
57
144
|
let url = this.configuration.basePath + context.path;
|
|
58
145
|
if (context.query !== undefined && Object.keys(context.query).length !== 0) {
|
|
59
146
|
// only add the querystring to the URL if there are query parameters.
|
|
@@ -61,18 +148,46 @@ export class BaseAPI {
|
|
|
61
148
|
// do not handle correctly sometimes.
|
|
62
149
|
url += '?' + this.configuration.queryParamsStringify(context.query);
|
|
63
150
|
}
|
|
64
|
-
const body = ((typeof FormData !== "undefined" && context.body instanceof FormData) || context.body instanceof URLSearchParams || isBlob(context.body))
|
|
65
|
-
? context.body
|
|
66
|
-
: JSON.stringify(context.body);
|
|
67
151
|
|
|
68
152
|
const headers = Object.assign({}, this.configuration.headers, context.headers);
|
|
69
|
-
|
|
153
|
+
Object.keys(headers).forEach(key => headers[key] === undefined ? delete headers[key] : {});
|
|
154
|
+
|
|
155
|
+
const initOverrideFn =
|
|
156
|
+
typeof initOverrides === "function"
|
|
157
|
+
? initOverrides
|
|
158
|
+
: async () => initOverrides;
|
|
159
|
+
|
|
160
|
+
const initParams = {
|
|
70
161
|
method: context.method,
|
|
71
|
-
headers
|
|
72
|
-
body,
|
|
162
|
+
headers,
|
|
163
|
+
body: context.body,
|
|
73
164
|
credentials: this.configuration.credentials,
|
|
74
|
-
...initOverrides
|
|
75
165
|
};
|
|
166
|
+
|
|
167
|
+
const overriddenInit: RequestInit = {
|
|
168
|
+
...initParams,
|
|
169
|
+
...(await initOverrideFn({
|
|
170
|
+
init: initParams,
|
|
171
|
+
context,
|
|
172
|
+
}))
|
|
173
|
+
};
|
|
174
|
+
|
|
175
|
+
let body: any;
|
|
176
|
+
if (isFormData(overriddenInit.body)
|
|
177
|
+
|| (overriddenInit.body instanceof URLSearchParams)
|
|
178
|
+
|| isBlob(overriddenInit.body)) {
|
|
179
|
+
body = overriddenInit.body;
|
|
180
|
+
} else if (this.isJsonMime(headers['Content-Type'])) {
|
|
181
|
+
body = JSON.stringify(overriddenInit.body);
|
|
182
|
+
} else {
|
|
183
|
+
body = overriddenInit.body;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
const init: RequestInit = {
|
|
187
|
+
...overriddenInit,
|
|
188
|
+
body
|
|
189
|
+
};
|
|
190
|
+
|
|
76
191
|
return { url, init };
|
|
77
192
|
}
|
|
78
193
|
|
|
@@ -86,7 +201,29 @@ export class BaseAPI {
|
|
|
86
201
|
}) || fetchParams;
|
|
87
202
|
}
|
|
88
203
|
}
|
|
89
|
-
let response
|
|
204
|
+
let response: Response | undefined = undefined;
|
|
205
|
+
try {
|
|
206
|
+
response = await (this.configuration.fetchApi || fetch)(fetchParams.url, fetchParams.init);
|
|
207
|
+
} catch (e) {
|
|
208
|
+
for (const middleware of this.middleware) {
|
|
209
|
+
if (middleware.onError) {
|
|
210
|
+
response = await middleware.onError({
|
|
211
|
+
fetch: this.fetchApi,
|
|
212
|
+
url: fetchParams.url,
|
|
213
|
+
init: fetchParams.init,
|
|
214
|
+
error: e,
|
|
215
|
+
response: response ? response.clone() : undefined,
|
|
216
|
+
}) || response;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
if (response === undefined) {
|
|
220
|
+
if (e instanceof Error) {
|
|
221
|
+
throw new FetchError(e, 'The request failed and the interceptors did not return an alternative response');
|
|
222
|
+
} else {
|
|
223
|
+
throw e;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
}
|
|
90
227
|
for (const middleware of this.middleware) {
|
|
91
228
|
if (middleware.post) {
|
|
92
229
|
response = await middleware.post({
|
|
@@ -112,8 +249,30 @@ export class BaseAPI {
|
|
|
112
249
|
}
|
|
113
250
|
};
|
|
114
251
|
|
|
252
|
+
function isBlob(value: any): value is Blob {
|
|
253
|
+
return typeof Blob !== 'undefined' && value instanceof Blob;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
function isFormData(value: any): value is FormData {
|
|
257
|
+
return typeof FormData !== "undefined" && value instanceof FormData;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
export class ResponseError extends Error {
|
|
261
|
+
override name: "ResponseError" = "ResponseError";
|
|
262
|
+
constructor(public response: Response, msg?: string) {
|
|
263
|
+
super(msg);
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
export class FetchError extends Error {
|
|
268
|
+
override name: "FetchError" = "FetchError";
|
|
269
|
+
constructor(public cause: Error, msg?: string) {
|
|
270
|
+
super(msg);
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
|
|
115
274
|
export class RequiredError extends Error {
|
|
116
|
-
name: "RequiredError" = "RequiredError";
|
|
275
|
+
override name: "RequiredError" = "RequiredError";
|
|
117
276
|
constructor(public field: string, msg?: string) {
|
|
118
277
|
super(msg);
|
|
119
278
|
}
|
|
@@ -126,80 +285,18 @@ export const COLLECTION_FORMATS = {
|
|
|
126
285
|
pipes: "|",
|
|
127
286
|
};
|
|
128
287
|
|
|
129
|
-
export type FetchAPI =
|
|
130
|
-
|
|
131
|
-
export interface ConfigurationParameters {
|
|
132
|
-
basePath?: string; // override base path
|
|
133
|
-
fetchApi?: FetchAPI; // override for fetch implementation
|
|
134
|
-
middleware?: Middleware[]; // middleware to apply before/after fetch requests
|
|
135
|
-
queryParamsStringify?: (params: HTTPQuery) => string; // stringify function for query strings
|
|
136
|
-
username?: string; // parameter for basic security
|
|
137
|
-
password?: string; // parameter for basic security
|
|
138
|
-
apiKey?: string | ((name: string) => string); // parameter for apiKey security
|
|
139
|
-
accessToken?: string | Promise<string> | ((name?: string, scopes?: string[]) => string | Promise<string>); // parameter for oauth2 security
|
|
140
|
-
headers?: HTTPHeaders; //header params we want to use on every request
|
|
141
|
-
credentials?: RequestCredentials; //value for the credentials param we want to use on each request
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
export class Configuration {
|
|
145
|
-
constructor(private configuration: ConfigurationParameters = {}) {}
|
|
146
|
-
|
|
147
|
-
get basePath(): string {
|
|
148
|
-
return this.configuration.basePath != null ? this.configuration.basePath : BASE_PATH;
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
get fetchApi(): FetchAPI | undefined {
|
|
152
|
-
return this.configuration.fetchApi;
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
get middleware(): Middleware[] {
|
|
156
|
-
return this.configuration.middleware || [];
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
get queryParamsStringify(): (params: HTTPQuery) => string {
|
|
160
|
-
return this.configuration.queryParamsStringify || querystring;
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
get username(): string | undefined {
|
|
164
|
-
return this.configuration.username;
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
get password(): string | undefined {
|
|
168
|
-
return this.configuration.password;
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
get apiKey(): ((name: string) => string) | undefined {
|
|
172
|
-
const apiKey = this.configuration.apiKey;
|
|
173
|
-
if (apiKey) {
|
|
174
|
-
return typeof apiKey === 'function' ? apiKey : () => apiKey;
|
|
175
|
-
}
|
|
176
|
-
return undefined;
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
get accessToken(): ((name?: string, scopes?: string[]) => string | Promise<string>) | undefined {
|
|
180
|
-
const accessToken = this.configuration.accessToken;
|
|
181
|
-
if (accessToken) {
|
|
182
|
-
return typeof accessToken === 'function' ? accessToken : async () => accessToken;
|
|
183
|
-
}
|
|
184
|
-
return undefined;
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
get headers(): HTTPHeaders | undefined {
|
|
188
|
-
return this.configuration.headers;
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
get credentials(): RequestCredentials | undefined {
|
|
192
|
-
return this.configuration.credentials;
|
|
193
|
-
}
|
|
194
|
-
}
|
|
288
|
+
export type FetchAPI = WindowOrWorkerGlobalScope['fetch'];
|
|
195
289
|
|
|
196
290
|
export type Json = any;
|
|
197
291
|
export type HTTPMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'OPTIONS' | 'HEAD';
|
|
198
292
|
export type HTTPHeaders = { [key: string]: string };
|
|
199
|
-
export type HTTPQuery = { [key: string]: string | number | null | boolean | Array<string | number | null | boolean> | HTTPQuery };
|
|
293
|
+
export type HTTPQuery = { [key: string]: string | number | null | boolean | Array<string | number | null | boolean> | Set<string | number | null | boolean> | HTTPQuery };
|
|
200
294
|
export type HTTPBody = Json | FormData | URLSearchParams;
|
|
295
|
+
export type HTTPRequestInit = { headers?: HTTPHeaders; method: HTTPMethod; credentials?: RequestCredentials; body?: HTTPBody };
|
|
201
296
|
export type ModelPropertyNaming = 'camelCase' | 'snake_case' | 'PascalCase' | 'original';
|
|
202
297
|
|
|
298
|
+
export type InitOverrideFunction = (requestContext: { init: HTTPRequestInit, context: RequestOpts }) => Promise<RequestInit>
|
|
299
|
+
|
|
203
300
|
export interface FetchParams {
|
|
204
301
|
url: string;
|
|
205
302
|
init: RequestInit;
|
|
@@ -213,33 +310,38 @@ export interface RequestOpts {
|
|
|
213
310
|
body?: HTTPBody;
|
|
214
311
|
}
|
|
215
312
|
|
|
216
|
-
export function exists(json: any, key: string) {
|
|
217
|
-
const value = json[key];
|
|
218
|
-
return value !== null && value !== undefined;
|
|
219
|
-
}
|
|
220
|
-
|
|
221
313
|
export function querystring(params: HTTPQuery, prefix: string = ''): string {
|
|
222
314
|
return Object.keys(params)
|
|
223
|
-
.map(
|
|
224
|
-
const fullKey = prefix + (prefix.length ? `[${key}]` : key);
|
|
225
|
-
const value = params[key];
|
|
226
|
-
if (value instanceof Array) {
|
|
227
|
-
const multiValue = value.map(singleValue => encodeURIComponent(String(singleValue)))
|
|
228
|
-
.join(`&${encodeURIComponent(fullKey)}=`);
|
|
229
|
-
return `${encodeURIComponent(fullKey)}=${multiValue}`;
|
|
230
|
-
}
|
|
231
|
-
if (value instanceof Date) {
|
|
232
|
-
return `${encodeURIComponent(fullKey)}=${encodeURIComponent(value.toISOString())}`;
|
|
233
|
-
}
|
|
234
|
-
if (value instanceof Object) {
|
|
235
|
-
return querystring(value as HTTPQuery, fullKey);
|
|
236
|
-
}
|
|
237
|
-
return `${encodeURIComponent(fullKey)}=${encodeURIComponent(String(value))}`;
|
|
238
|
-
})
|
|
315
|
+
.map(key => querystringSingleKey(key, params[key], prefix))
|
|
239
316
|
.filter(part => part.length > 0)
|
|
240
317
|
.join('&');
|
|
241
318
|
}
|
|
242
319
|
|
|
320
|
+
function querystringSingleKey(key: string, value: string | number | null | undefined | boolean | Array<string | number | null | boolean> | Set<string | number | null | boolean> | HTTPQuery, keyPrefix: string = ''): string {
|
|
321
|
+
const fullKey = keyPrefix + (keyPrefix.length ? `[${key}]` : key);
|
|
322
|
+
if (value instanceof Array) {
|
|
323
|
+
const multiValue = value.map(singleValue => encodeURIComponent(String(singleValue)))
|
|
324
|
+
.join(`&${encodeURIComponent(fullKey)}=`);
|
|
325
|
+
return `${encodeURIComponent(fullKey)}=${multiValue}`;
|
|
326
|
+
}
|
|
327
|
+
if (value instanceof Set) {
|
|
328
|
+
const valueAsArray = Array.from(value);
|
|
329
|
+
return querystringSingleKey(key, valueAsArray, keyPrefix);
|
|
330
|
+
}
|
|
331
|
+
if (value instanceof Date) {
|
|
332
|
+
return `${encodeURIComponent(fullKey)}=${encodeURIComponent(value.toISOString())}`;
|
|
333
|
+
}
|
|
334
|
+
if (value instanceof Object) {
|
|
335
|
+
return querystring(value as HTTPQuery, fullKey);
|
|
336
|
+
}
|
|
337
|
+
return `${encodeURIComponent(fullKey)}=${encodeURIComponent(String(value))}`;
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
export function exists(json: any, key: string) {
|
|
341
|
+
const value = json[key];
|
|
342
|
+
return value !== null && value !== undefined;
|
|
343
|
+
}
|
|
344
|
+
|
|
243
345
|
export function mapValues(data: any, fn: (item: any) => any) {
|
|
244
346
|
return Object.keys(data).reduce(
|
|
245
347
|
(acc, key) => ({ ...acc, [key]: fn(data[key]) }),
|
|
@@ -257,7 +359,7 @@ export function canConsumeForm(consumes: Consume[]): boolean {
|
|
|
257
359
|
}
|
|
258
360
|
|
|
259
361
|
export interface Consume {
|
|
260
|
-
contentType: string
|
|
362
|
+
contentType: string;
|
|
261
363
|
}
|
|
262
364
|
|
|
263
365
|
export interface RequestContext {
|
|
@@ -273,9 +375,18 @@ export interface ResponseContext {
|
|
|
273
375
|
response: Response;
|
|
274
376
|
}
|
|
275
377
|
|
|
378
|
+
export interface ErrorContext {
|
|
379
|
+
fetch: FetchAPI;
|
|
380
|
+
url: string;
|
|
381
|
+
init: RequestInit;
|
|
382
|
+
error: unknown;
|
|
383
|
+
response?: Response;
|
|
384
|
+
}
|
|
385
|
+
|
|
276
386
|
export interface Middleware {
|
|
277
387
|
pre?(context: RequestContext): Promise<FetchParams | void>;
|
|
278
388
|
post?(context: ResponseContext): Promise<Response | void>;
|
|
389
|
+
onError?(context: ErrorContext): Promise<Response | void>;
|
|
279
390
|
}
|
|
280
391
|
|
|
281
392
|
export interface ApiResponse<T> {
|