@abliteration/sdk 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.openapi-generator/FILES +76 -0
- package/.openapi-generator/VERSION +1 -0
- package/.openapi-generator-ignore +23 -0
- package/README.md +140 -49
- package/dist/apis/AuthorsApi.d.ts +11 -3
- package/dist/apis/AuthorsApi.js +8 -0
- package/dist/apis/DatasetsApi.d.ts +9 -3
- package/dist/apis/DatasetsApi.js +6 -0
- package/dist/apis/IndicesApi.d.ts +9 -3
- package/dist/apis/IndicesApi.js +6 -0
- package/dist/apis/ModelsApi.d.ts +9 -3
- package/dist/apis/ModelsApi.js +6 -0
- package/dist/esm/apis/AuthorsApi.d.ts +11 -3
- package/dist/esm/apis/AuthorsApi.js +8 -0
- package/dist/esm/apis/DatasetsApi.d.ts +9 -3
- package/dist/esm/apis/DatasetsApi.js +6 -0
- package/dist/esm/apis/IndicesApi.d.ts +9 -3
- package/dist/esm/apis/IndicesApi.js +6 -0
- package/dist/esm/apis/ModelsApi.d.ts +9 -3
- package/dist/esm/apis/ModelsApi.js +6 -0
- package/dist/esm/models/Author.d.ts +4 -0
- package/dist/esm/models/Author.js +2 -0
- package/dist/esm/models/AuthorDetail.d.ts +4 -0
- package/dist/esm/models/AuthorDetail.js +2 -0
- package/dist/models/Author.d.ts +4 -0
- package/dist/models/Author.js +2 -0
- package/dist/models/AuthorDetail.d.ts +4 -0
- package/dist/models/AuthorDetail.js +2 -0
- package/docs/Author.md +44 -0
- package/docs/AuthorDetail.md +46 -0
- package/docs/AuthorsApi.md +167 -0
- package/docs/DaiPoint.md +38 -0
- package/docs/Dataset.md +54 -0
- package/docs/DatasetDetail.md +39 -0
- package/docs/DatasetsApi.md +176 -0
- package/docs/Envelope.md +48 -0
- package/docs/Event.md +46 -0
- package/docs/GetAuthor200Response.md +48 -0
- package/docs/GetDataset200Response.md +48 -0
- package/docs/GetIndex200Response.md +48 -0
- package/docs/GetMethod200Response.md +48 -0
- package/docs/GetModel200Response.md +48 -0
- package/docs/IndexDetail.md +54 -0
- package/docs/IndicesApi.md +153 -0
- package/docs/ListAuthors200Response.md +48 -0
- package/docs/ListDatasets200Response.md +48 -0
- package/docs/ListIndices200Response.md +48 -0
- package/docs/ListMethods200Response.md +48 -0
- package/docs/ListModels200Response.md +48 -0
- package/docs/ListTimeline200Response.md +48 -0
- package/docs/Method.md +44 -0
- package/docs/MethodDetail.md +50 -0
- package/docs/MethodDetailAllOfTopAuthors.md +36 -0
- package/docs/MethodsApi.md +153 -0
- package/docs/ModelDetail.md +45 -0
- package/docs/ModelError.md +42 -0
- package/docs/ModelIndex.md +52 -0
- package/docs/ModelSummary.md +58 -0
- package/docs/ModelsApi.md +191 -0
- package/docs/Passport.md +38 -0
- package/docs/TimelineApi.md +93 -0
- package/openapi-generator-config.json +10 -0
- package/package.json +14 -16
- package/src/apis/AuthorsApi.ts +248 -0
- package/src/apis/DatasetsApi.ts +278 -0
- package/src/apis/IndicesApi.ts +213 -0
- package/src/apis/MethodsApi.ts +214 -0
- package/src/apis/ModelsApi.ts +328 -0
- package/src/apis/TimelineApi.ts +148 -0
- package/src/apis/index.ts +8 -0
- package/src/index.ts +5 -0
- package/src/models/Author.ts +93 -0
- package/src/models/AuthorDetail.ts +107 -0
- package/src/models/DaiPoint.ts +75 -0
- package/src/models/Dataset.ts +123 -0
- package/src/models/DatasetDetail.ts +86 -0
- package/src/models/Envelope.ts +124 -0
- package/src/models/Event.ts +99 -0
- package/src/models/GetAuthor200Response.ts +132 -0
- package/src/models/GetDataset200Response.ts +132 -0
- package/src/models/GetIndex200Response.ts +132 -0
- package/src/models/GetMethod200Response.ts +132 -0
- package/src/models/GetModel200Response.ts +132 -0
- package/src/models/IndexDetail.ts +153 -0
- package/src/models/ListAuthors200Response.ts +132 -0
- package/src/models/ListDatasets200Response.ts +132 -0
- package/src/models/ListIndices200Response.ts +132 -0
- package/src/models/ListMethods200Response.ts +132 -0
- package/src/models/ListModels200Response.ts +132 -0
- package/src/models/ListTimeline200Response.ts +132 -0
- package/src/models/Method.ts +106 -0
- package/src/models/MethodDetail.ts +139 -0
- package/src/models/MethodDetailAllOfTopAuthors.ts +69 -0
- package/src/models/ModelDetail.ts +104 -0
- package/src/models/ModelError.ts +89 -0
- package/src/models/ModelIndex.ts +147 -0
- package/src/models/ModelSummary.ts +135 -0
- package/src/models/Passport.ts +75 -0
- package/src/models/index.ts +29 -0
- package/src/runtime.ts +505 -0
- package/tsconfig.esm.json +7 -0
- package/tsconfig.json +16 -0
package/src/runtime.ts
ADDED
|
@@ -0,0 +1,505 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
/**
|
|
4
|
+
* abliteration.org Public API
|
|
5
|
+
* Read access to the abliteration.org catalog: models and their method classification, alignment datasets and their passports, the M-code taxonomy, the four flagship indices and the curated field timeline. Every call is authenticated with a bearer key and metered in credits against the same wallet the Research Agent spends from. There is no free tier for machine traffic and no separate billing. Responses report `cost` and `credits_remaining` on every success. While `metering` reads `preview`, the cost shown is what the call will bill once metering is enabled and nothing is actually deducted; when it reads `billed`, it was.
|
|
6
|
+
*
|
|
7
|
+
* The version of the OpenAPI document: 1.0.0
|
|
8
|
+
*
|
|
9
|
+
*
|
|
10
|
+
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
|
11
|
+
* https://openapi-generator.tech
|
|
12
|
+
* Do not edit the class manually.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
export const BASE_PATH = "https://abliteration.org".replace(/\/+$/, "");
|
|
16
|
+
|
|
17
|
+
export interface ConfigurationParameters {
|
|
18
|
+
basePath?: string; // override base path
|
|
19
|
+
fetchApi?: FetchAPI; // override for fetch implementation
|
|
20
|
+
middleware?: Middleware[]; // middleware to apply before/after fetch requests
|
|
21
|
+
queryParamsStringify?: (params: HTTPQuery) => string; // stringify function for query strings
|
|
22
|
+
username?: string; // parameter for basic security
|
|
23
|
+
password?: string; // parameter for basic security
|
|
24
|
+
apiKey?: string | Promise<string> | ((name: string) => string | Promise<string>); // parameter for apiKey security
|
|
25
|
+
accessToken?: string | Promise<string> | ((name?: string, scopes?: string[]) => string | Promise<string>); // parameter for oauth2 security
|
|
26
|
+
headers?: HTTPHeaders; //header params we want to use on every request
|
|
27
|
+
credentials?: RequestCredentials; //value for the credentials param we want to use on each request
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export class Configuration {
|
|
31
|
+
constructor(private configuration: ConfigurationParameters = {}) {}
|
|
32
|
+
|
|
33
|
+
set config(configuration: Configuration) {
|
|
34
|
+
this.configuration = configuration;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
get basePath(): string {
|
|
38
|
+
return this.configuration.basePath != null ? this.configuration.basePath : BASE_PATH;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
get fetchApi(): FetchAPI | undefined {
|
|
42
|
+
return this.configuration.fetchApi;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
get middleware(): Middleware[] {
|
|
46
|
+
return this.configuration.middleware || [];
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
get queryParamsStringify(): (params: HTTPQuery) => string {
|
|
50
|
+
return this.configuration.queryParamsStringify || querystring;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
get username(): string | undefined {
|
|
54
|
+
return this.configuration.username;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
get password(): string | undefined {
|
|
58
|
+
return this.configuration.password;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
get apiKey(): ((name: string) => string | Promise<string>) | undefined {
|
|
62
|
+
const apiKey = this.configuration.apiKey;
|
|
63
|
+
if (apiKey) {
|
|
64
|
+
return typeof apiKey === 'function' ? apiKey : () => apiKey;
|
|
65
|
+
}
|
|
66
|
+
return undefined;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
get accessToken(): ((name?: string, scopes?: string[]) => string | Promise<string>) | undefined {
|
|
70
|
+
const accessToken = this.configuration.accessToken;
|
|
71
|
+
if (accessToken) {
|
|
72
|
+
return typeof accessToken === 'function' ? accessToken : async () => accessToken;
|
|
73
|
+
}
|
|
74
|
+
return undefined;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
get headers(): HTTPHeaders | undefined {
|
|
78
|
+
return this.configuration.headers;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
get credentials(): RequestCredentials | undefined {
|
|
82
|
+
return this.configuration.credentials;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export const DefaultConfig = new Configuration();
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* This is the base class for all generated API classes.
|
|
90
|
+
*/
|
|
91
|
+
export class BaseAPI {
|
|
92
|
+
|
|
93
|
+
private static readonly jsonRegex = /^(:?application\/json|[^;/ \t]+\/[^;/ \t]+[+]json)[ \t]*(:?;.*)?$/i;
|
|
94
|
+
private middleware: Middleware[];
|
|
95
|
+
|
|
96
|
+
constructor(protected configuration = DefaultConfig) {
|
|
97
|
+
this.middleware = configuration.middleware;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
withMiddleware<T extends BaseAPI>(this: T, ...middlewares: Middleware[]) {
|
|
101
|
+
const next = this.clone<T>();
|
|
102
|
+
next.middleware = next.middleware.concat(...middlewares);
|
|
103
|
+
return next;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
withPreMiddleware<T extends BaseAPI>(this: T, ...preMiddlewares: Array<Middleware['pre']>) {
|
|
107
|
+
const middlewares = preMiddlewares.map((pre) => ({ pre }));
|
|
108
|
+
return this.withMiddleware<T>(...middlewares);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
withPostMiddleware<T extends BaseAPI>(this: T, ...postMiddlewares: Array<Middleware['post']>) {
|
|
112
|
+
const middlewares = postMiddlewares.map((post) => ({ post }));
|
|
113
|
+
return this.withMiddleware<T>(...middlewares);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Check if the given MIME is a JSON MIME.
|
|
118
|
+
* JSON MIME examples:
|
|
119
|
+
* application/json
|
|
120
|
+
* application/json; charset=UTF8
|
|
121
|
+
* APPLICATION/JSON
|
|
122
|
+
* application/vnd.company+json
|
|
123
|
+
* @param mime - MIME (Multipurpose Internet Mail Extensions)
|
|
124
|
+
* @return True if the given MIME is JSON, false otherwise.
|
|
125
|
+
*/
|
|
126
|
+
protected isJsonMime(mime: string | null | undefined): boolean {
|
|
127
|
+
if (!mime) {
|
|
128
|
+
return false;
|
|
129
|
+
}
|
|
130
|
+
return BaseAPI.jsonRegex.test(mime);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
protected async request(context: RequestOpts, initOverrides?: RequestInit | InitOverrideFunction): Promise<Response> {
|
|
134
|
+
const { url, init } = await this.createFetchParams(context, initOverrides);
|
|
135
|
+
const response = await this.fetchApi(url, init);
|
|
136
|
+
if (response && (response.status >= 200 && response.status < 300)) {
|
|
137
|
+
return response;
|
|
138
|
+
}
|
|
139
|
+
throw new ResponseError(response, 'Response returned an error code');
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
private async createFetchParams(context: RequestOpts, initOverrides?: RequestInit | InitOverrideFunction) {
|
|
143
|
+
let url = this.configuration.basePath + context.path;
|
|
144
|
+
if (context.query !== undefined && Object.keys(context.query).length !== 0) {
|
|
145
|
+
// only add the querystring to the URL if there are query parameters.
|
|
146
|
+
// this is done to avoid urls ending with a "?" character which buggy webservers
|
|
147
|
+
// do not handle correctly sometimes.
|
|
148
|
+
url += '?' + this.configuration.queryParamsStringify(context.query);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
const headers = Object.assign({}, this.configuration.headers, context.headers);
|
|
152
|
+
Object.keys(headers).forEach(key => headers[key] === undefined ? delete headers[key] : {});
|
|
153
|
+
|
|
154
|
+
const initOverrideFn =
|
|
155
|
+
typeof initOverrides === "function"
|
|
156
|
+
? initOverrides
|
|
157
|
+
: async () => initOverrides;
|
|
158
|
+
|
|
159
|
+
const initParams = {
|
|
160
|
+
method: context.method,
|
|
161
|
+
headers,
|
|
162
|
+
body: context.body,
|
|
163
|
+
credentials: this.configuration.credentials,
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
const overriddenInit: RequestInit = {
|
|
167
|
+
...initParams,
|
|
168
|
+
...(await initOverrideFn({
|
|
169
|
+
init: initParams,
|
|
170
|
+
context,
|
|
171
|
+
}))
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
let body: any;
|
|
175
|
+
if (isFormData(overriddenInit.body)
|
|
176
|
+
|| (overriddenInit.body instanceof URLSearchParams)
|
|
177
|
+
|| isBlob(overriddenInit.body)) {
|
|
178
|
+
body = overriddenInit.body;
|
|
179
|
+
} else if (this.isJsonMime(headers['Content-Type'])) {
|
|
180
|
+
body = JSON.stringify(overriddenInit.body);
|
|
181
|
+
} else {
|
|
182
|
+
body = overriddenInit.body;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
const init: RequestInit = {
|
|
186
|
+
...overriddenInit,
|
|
187
|
+
body
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
return { url, init };
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
private fetchApi = async (url: string, init: RequestInit) => {
|
|
194
|
+
let fetchParams = { url, init };
|
|
195
|
+
for (const middleware of this.middleware) {
|
|
196
|
+
if (middleware.pre) {
|
|
197
|
+
fetchParams = await middleware.pre({
|
|
198
|
+
fetch: this.fetchApi,
|
|
199
|
+
...fetchParams,
|
|
200
|
+
}) || fetchParams;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
let response: Response | undefined = undefined;
|
|
204
|
+
try {
|
|
205
|
+
response = await (this.configuration.fetchApi || fetch)(fetchParams.url, fetchParams.init);
|
|
206
|
+
} catch (e) {
|
|
207
|
+
for (const middleware of this.middleware) {
|
|
208
|
+
if (middleware.onError) {
|
|
209
|
+
response = await middleware.onError({
|
|
210
|
+
fetch: this.fetchApi,
|
|
211
|
+
url: fetchParams.url,
|
|
212
|
+
init: fetchParams.init,
|
|
213
|
+
error: e,
|
|
214
|
+
response: response ? response.clone() : undefined,
|
|
215
|
+
}) || response;
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
if (response === undefined) {
|
|
219
|
+
if (e instanceof Error) {
|
|
220
|
+
throw new FetchError(e, 'The request failed and the interceptors did not return an alternative response');
|
|
221
|
+
} else {
|
|
222
|
+
throw e;
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
for (const middleware of this.middleware) {
|
|
227
|
+
if (middleware.post) {
|
|
228
|
+
response = await middleware.post({
|
|
229
|
+
fetch: this.fetchApi,
|
|
230
|
+
url: fetchParams.url,
|
|
231
|
+
init: fetchParams.init,
|
|
232
|
+
response: response.clone(),
|
|
233
|
+
}) || response;
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
return response;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
/**
|
|
240
|
+
* Create a shallow clone of `this` by constructing a new instance
|
|
241
|
+
* and then shallow cloning data members.
|
|
242
|
+
*/
|
|
243
|
+
private clone<T extends BaseAPI>(this: T): T {
|
|
244
|
+
const constructor = this.constructor as any;
|
|
245
|
+
const next = new constructor(this.configuration);
|
|
246
|
+
next.middleware = this.middleware.slice();
|
|
247
|
+
return next;
|
|
248
|
+
}
|
|
249
|
+
};
|
|
250
|
+
|
|
251
|
+
function isBlob(value: any): value is Blob {
|
|
252
|
+
return typeof Blob !== 'undefined' && value instanceof Blob;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
function isFormData(value: any): value is FormData {
|
|
256
|
+
return typeof FormData !== "undefined" && value instanceof FormData;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
export class ResponseError extends Error {
|
|
260
|
+
override name: "ResponseError" = "ResponseError";
|
|
261
|
+
constructor(public response: Response, msg?: string) {
|
|
262
|
+
super(msg);
|
|
263
|
+
|
|
264
|
+
// restore prototype chain
|
|
265
|
+
const actualProto = new.target.prototype;
|
|
266
|
+
if (Object.setPrototypeOf) {
|
|
267
|
+
Object.setPrototypeOf(this, actualProto);
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
export class FetchError extends Error {
|
|
273
|
+
override name: "FetchError" = "FetchError";
|
|
274
|
+
constructor(public cause: Error, msg?: string) {
|
|
275
|
+
super(msg);
|
|
276
|
+
|
|
277
|
+
// restore prototype chain
|
|
278
|
+
const actualProto = new.target.prototype;
|
|
279
|
+
if (Object.setPrototypeOf) {
|
|
280
|
+
Object.setPrototypeOf(this, actualProto);
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
export class RequiredError extends Error {
|
|
286
|
+
override name: "RequiredError" = "RequiredError";
|
|
287
|
+
constructor(public field: string, msg?: string) {
|
|
288
|
+
super(msg);
|
|
289
|
+
|
|
290
|
+
// restore prototype chain
|
|
291
|
+
const actualProto = new.target.prototype;
|
|
292
|
+
if (Object.setPrototypeOf) {
|
|
293
|
+
Object.setPrototypeOf(this, actualProto);
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
export const COLLECTION_FORMATS = {
|
|
299
|
+
csv: ",",
|
|
300
|
+
ssv: " ",
|
|
301
|
+
tsv: "\t",
|
|
302
|
+
pipes: "|",
|
|
303
|
+
};
|
|
304
|
+
|
|
305
|
+
export type FetchAPI = WindowOrWorkerGlobalScope['fetch'];
|
|
306
|
+
|
|
307
|
+
export type Json = any;
|
|
308
|
+
export type HTTPMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'OPTIONS' | 'HEAD';
|
|
309
|
+
export type HTTPHeaders = { [key: string]: string };
|
|
310
|
+
export type HTTPQuery = { [key: string]: string | number | null | boolean | Array<string | number | null | boolean> | Set<string | number | null | boolean> | HTTPQuery };
|
|
311
|
+
export type HTTPBody = Json | FormData | URLSearchParams;
|
|
312
|
+
export type HTTPRequestInit = { headers?: HTTPHeaders; method: HTTPMethod; credentials?: RequestCredentials; body?: HTTPBody };
|
|
313
|
+
export type ModelPropertyNaming = 'camelCase' | 'snake_case' | 'PascalCase' | 'original';
|
|
314
|
+
|
|
315
|
+
export type InitOverrideFunction = (requestContext: { init: HTTPRequestInit, context: RequestOpts }) => Promise<RequestInit>
|
|
316
|
+
|
|
317
|
+
export interface FetchParams {
|
|
318
|
+
url: string;
|
|
319
|
+
init: RequestInit;
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
export interface RequestOpts {
|
|
323
|
+
path: string;
|
|
324
|
+
method: HTTPMethod;
|
|
325
|
+
headers: HTTPHeaders;
|
|
326
|
+
query?: HTTPQuery;
|
|
327
|
+
body?: HTTPBody;
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
export function querystring(params: HTTPQuery, prefix: string = ''): string {
|
|
331
|
+
return Object.keys(params)
|
|
332
|
+
.map(key => querystringSingleKey(key, params[key], prefix))
|
|
333
|
+
.filter(part => part.length > 0)
|
|
334
|
+
.join('&');
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
function querystringSingleKey(key: string, value: string | number | null | undefined | boolean | Array<string | number | null | boolean> | Set<string | number | null | boolean> | HTTPQuery, keyPrefix: string = ''): string {
|
|
338
|
+
const fullKey = keyPrefix + (keyPrefix.length ? `[${key}]` : key);
|
|
339
|
+
if (value instanceof Array) {
|
|
340
|
+
const multiValue = value.map(singleValue => encodeURIComponent(String(singleValue)))
|
|
341
|
+
.join(`&${encodeURIComponent(fullKey)}=`);
|
|
342
|
+
return `${encodeURIComponent(fullKey)}=${multiValue}`;
|
|
343
|
+
}
|
|
344
|
+
if (value instanceof Set) {
|
|
345
|
+
const valueAsArray = Array.from(value);
|
|
346
|
+
return querystringSingleKey(key, valueAsArray, keyPrefix);
|
|
347
|
+
}
|
|
348
|
+
if (value instanceof Date) {
|
|
349
|
+
return `${encodeURIComponent(fullKey)}=${encodeURIComponent(serializeDateTime(value))}`;
|
|
350
|
+
}
|
|
351
|
+
if (value instanceof Object) {
|
|
352
|
+
return querystring(value as HTTPQuery, fullKey);
|
|
353
|
+
}
|
|
354
|
+
return `${encodeURIComponent(fullKey)}=${encodeURIComponent(String(value))}`;
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
export function exists(json: any, key: string) {
|
|
358
|
+
const value = json[key];
|
|
359
|
+
return value !== null && value !== undefined;
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
/**
|
|
363
|
+
* Every generated date call site routes through these.
|
|
364
|
+
*
|
|
365
|
+
* `format: date` is a calendar date, with no time and no offset, so it is converted
|
|
366
|
+
* against the local calendar on both ends: they have to agree or the date shifts by
|
|
367
|
+
* a day. `format: date-time` is an instant and uses UTC.
|
|
368
|
+
*/
|
|
369
|
+
export function serializeDateTime(value: Date): string {
|
|
370
|
+
return value.toISOString();
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
export function serializeDate(value: Date): string {
|
|
374
|
+
if (isNaN(value.getTime())) {
|
|
375
|
+
throw new RangeError('Invalid time value');
|
|
376
|
+
}
|
|
377
|
+
const year = ('000' + value.getFullYear()).slice(-4);
|
|
378
|
+
const month = ('0' + (value.getMonth() + 1)).slice(-2);
|
|
379
|
+
const day = ('0' + value.getDate()).slice(-2);
|
|
380
|
+
return `${year}-${month}-${day}`;
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
|
|
384
|
+
export function parseDate(value: Date | string): Date {
|
|
385
|
+
if (value instanceof Date) {
|
|
386
|
+
return value;
|
|
387
|
+
}
|
|
388
|
+
// `new Date("2026-08-05")` would parse as UTC midnight: a different day west of UTC.
|
|
389
|
+
// Local midnight is the stated day everywhere. setFullYear avoids the 1900 offset the
|
|
390
|
+
// multi-argument constructor applies to years 0-99.
|
|
391
|
+
const fullDate = /^(\d{4})-(\d{2})-(\d{2})$/.exec(String(value));
|
|
392
|
+
if (fullDate) {
|
|
393
|
+
const year = Number(fullDate[1]);
|
|
394
|
+
const month = Number(fullDate[2]) - 1;
|
|
395
|
+
const day = Number(fullDate[3]);
|
|
396
|
+
const date = new Date(0);
|
|
397
|
+
date.setFullYear(year, month, day);
|
|
398
|
+
date.setHours(0, 0, 0, 0);
|
|
399
|
+
// Out-of-range components (or a day the local zone skipped) silently roll over,
|
|
400
|
+
// which would hand back a date the server never sent.
|
|
401
|
+
if (date.getFullYear() !== year || date.getMonth() !== month || date.getDate() !== day) {
|
|
402
|
+
return new Date(NaN);
|
|
403
|
+
}
|
|
404
|
+
return date;
|
|
405
|
+
}
|
|
406
|
+
return new Date(value);
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
export function parseDateTime(value: any): Date {
|
|
410
|
+
return new Date(value);
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
export function mapValues(data: any, fn: (item: any) => any) {
|
|
414
|
+
const result: { [key: string]: any } = {};
|
|
415
|
+
for (const key of Object.keys(data)) {
|
|
416
|
+
result[key] = fn(data[key]);
|
|
417
|
+
}
|
|
418
|
+
return result;
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
// Pass-through serializer for `any`-typed properties in form data. See #1877.
|
|
422
|
+
export function anyToJSON(value: any): any {
|
|
423
|
+
return value;
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
export function canConsumeForm(consumes: Consume[]): boolean {
|
|
427
|
+
for (const consume of consumes) {
|
|
428
|
+
if (consume.contentType?.startsWith('multipart/form-data') == true) {
|
|
429
|
+
return true;
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
return false;
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
export interface Consume {
|
|
436
|
+
contentType: string;
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
export interface RequestContext {
|
|
440
|
+
fetch: FetchAPI;
|
|
441
|
+
url: string;
|
|
442
|
+
init: RequestInit;
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
export interface ResponseContext {
|
|
446
|
+
fetch: FetchAPI;
|
|
447
|
+
url: string;
|
|
448
|
+
init: RequestInit;
|
|
449
|
+
response: Response;
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
export interface ErrorContext {
|
|
453
|
+
fetch: FetchAPI;
|
|
454
|
+
url: string;
|
|
455
|
+
init: RequestInit;
|
|
456
|
+
error: unknown;
|
|
457
|
+
response?: Response;
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
export interface Middleware {
|
|
461
|
+
pre?(context: RequestContext): Promise<FetchParams | void>;
|
|
462
|
+
post?(context: ResponseContext): Promise<Response | void>;
|
|
463
|
+
onError?(context: ErrorContext): Promise<Response | void>;
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
export interface ApiResponse<T> {
|
|
467
|
+
raw: Response;
|
|
468
|
+
value(): Promise<T>;
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
export interface ResponseTransformer<T> {
|
|
472
|
+
(json: any): T;
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
export class JSONApiResponse<T> {
|
|
476
|
+
constructor(public raw: Response, private transformer: ResponseTransformer<T> = (jsonValue: any) => jsonValue) {}
|
|
477
|
+
|
|
478
|
+
async value(): Promise<T> {
|
|
479
|
+
return this.transformer(await this.raw.json());
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
export class VoidApiResponse {
|
|
484
|
+
constructor(public raw: Response) {}
|
|
485
|
+
|
|
486
|
+
async value(): Promise<void> {
|
|
487
|
+
return undefined;
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
export class BlobApiResponse {
|
|
492
|
+
constructor(public raw: Response) {}
|
|
493
|
+
|
|
494
|
+
async value(): Promise<Blob> {
|
|
495
|
+
return await this.raw.blob();
|
|
496
|
+
};
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
export class TextApiResponse {
|
|
500
|
+
constructor(public raw: Response) {}
|
|
501
|
+
|
|
502
|
+
async value(): Promise<string> {
|
|
503
|
+
return await this.raw.text();
|
|
504
|
+
};
|
|
505
|
+
}
|
package/tsconfig.json
ADDED