@abliteration/sdk 0.1.0 → 0.1.2

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 (114) hide show
  1. package/.openapi-generator/FILES +76 -0
  2. package/.openapi-generator/VERSION +1 -0
  3. package/.openapi-generator-ignore +23 -0
  4. package/README.md +140 -49
  5. package/dist/apis/AuthorsApi.d.ts +11 -3
  6. package/dist/apis/AuthorsApi.js +8 -0
  7. package/dist/apis/DatasetsApi.d.ts +9 -3
  8. package/dist/apis/DatasetsApi.js +6 -0
  9. package/dist/apis/IndicesApi.d.ts +9 -3
  10. package/dist/apis/IndicesApi.js +6 -0
  11. package/dist/apis/ModelsApi.d.ts +9 -3
  12. package/dist/apis/ModelsApi.js +6 -0
  13. package/dist/esm/apis/AuthorsApi.d.ts +11 -3
  14. package/dist/esm/apis/AuthorsApi.js +8 -0
  15. package/dist/esm/apis/DatasetsApi.d.ts +9 -3
  16. package/dist/esm/apis/DatasetsApi.js +6 -0
  17. package/dist/esm/apis/IndicesApi.d.ts +9 -3
  18. package/dist/esm/apis/IndicesApi.js +6 -0
  19. package/dist/esm/apis/ModelsApi.d.ts +9 -3
  20. package/dist/esm/apis/ModelsApi.js +6 -0
  21. package/dist/esm/models/Author.d.ts +4 -0
  22. package/dist/esm/models/Author.js +2 -0
  23. package/dist/esm/models/AuthorDetail.d.ts +4 -0
  24. package/dist/esm/models/AuthorDetail.js +2 -0
  25. package/dist/esm/models/Dataset.d.ts +45 -1
  26. package/dist/esm/models/Dataset.js +22 -0
  27. package/dist/esm/models/DatasetDetail.d.ts +85 -2
  28. package/dist/esm/models/DatasetDetail.js +52 -2
  29. package/dist/esm/models/ModelDetail.d.ts +173 -1
  30. package/dist/esm/models/ModelDetail.js +2 -2
  31. package/dist/models/Author.d.ts +4 -0
  32. package/dist/models/Author.js +2 -0
  33. package/dist/models/AuthorDetail.d.ts +4 -0
  34. package/dist/models/AuthorDetail.js +2 -0
  35. package/dist/models/Dataset.d.ts +45 -1
  36. package/dist/models/Dataset.js +22 -0
  37. package/dist/models/DatasetDetail.d.ts +85 -2
  38. package/dist/models/DatasetDetail.js +52 -2
  39. package/dist/models/ModelDetail.d.ts +173 -1
  40. package/dist/models/ModelDetail.js +2 -2
  41. package/docs/Author.md +44 -0
  42. package/docs/AuthorDetail.md +46 -0
  43. package/docs/AuthorsApi.md +167 -0
  44. package/docs/DaiPoint.md +38 -0
  45. package/docs/Dataset.md +76 -0
  46. package/docs/DatasetDetail.md +80 -0
  47. package/docs/DatasetsApi.md +176 -0
  48. package/docs/Envelope.md +48 -0
  49. package/docs/Event.md +46 -0
  50. package/docs/GetAuthor200Response.md +48 -0
  51. package/docs/GetDataset200Response.md +48 -0
  52. package/docs/GetIndex200Response.md +48 -0
  53. package/docs/GetMethod200Response.md +48 -0
  54. package/docs/GetModel200Response.md +48 -0
  55. package/docs/IndexDetail.md +54 -0
  56. package/docs/IndicesApi.md +153 -0
  57. package/docs/ListAuthors200Response.md +48 -0
  58. package/docs/ListDatasets200Response.md +48 -0
  59. package/docs/ListIndices200Response.md +48 -0
  60. package/docs/ListMethods200Response.md +48 -0
  61. package/docs/ListModels200Response.md +48 -0
  62. package/docs/ListTimeline200Response.md +48 -0
  63. package/docs/Method.md +44 -0
  64. package/docs/MethodDetail.md +50 -0
  65. package/docs/MethodDetailAllOfTopAuthors.md +36 -0
  66. package/docs/MethodsApi.md +153 -0
  67. package/docs/ModelDetail.md +131 -0
  68. package/docs/ModelError.md +42 -0
  69. package/docs/ModelIndex.md +52 -0
  70. package/docs/ModelSummary.md +58 -0
  71. package/docs/ModelsApi.md +191 -0
  72. package/docs/Passport.md +38 -0
  73. package/docs/TimelineApi.md +93 -0
  74. package/openapi-generator-config.json +10 -0
  75. package/package.json +14 -16
  76. package/src/apis/AuthorsApi.ts +248 -0
  77. package/src/apis/DatasetsApi.ts +278 -0
  78. package/src/apis/IndicesApi.ts +213 -0
  79. package/src/apis/MethodsApi.ts +214 -0
  80. package/src/apis/ModelsApi.ts +328 -0
  81. package/src/apis/TimelineApi.ts +148 -0
  82. package/src/apis/index.ts +8 -0
  83. package/src/index.ts +5 -0
  84. package/src/models/Author.ts +93 -0
  85. package/src/models/AuthorDetail.ts +107 -0
  86. package/src/models/DaiPoint.ts +75 -0
  87. package/src/models/Dataset.ts +189 -0
  88. package/src/models/DatasetDetail.ts +209 -0
  89. package/src/models/Envelope.ts +124 -0
  90. package/src/models/Event.ts +99 -0
  91. package/src/models/GetAuthor200Response.ts +132 -0
  92. package/src/models/GetDataset200Response.ts +132 -0
  93. package/src/models/GetIndex200Response.ts +132 -0
  94. package/src/models/GetMethod200Response.ts +132 -0
  95. package/src/models/GetModel200Response.ts +132 -0
  96. package/src/models/IndexDetail.ts +153 -0
  97. package/src/models/ListAuthors200Response.ts +132 -0
  98. package/src/models/ListDatasets200Response.ts +132 -0
  99. package/src/models/ListIndices200Response.ts +132 -0
  100. package/src/models/ListMethods200Response.ts +132 -0
  101. package/src/models/ListModels200Response.ts +132 -0
  102. package/src/models/ListTimeline200Response.ts +132 -0
  103. package/src/models/Method.ts +106 -0
  104. package/src/models/MethodDetail.ts +139 -0
  105. package/src/models/MethodDetailAllOfTopAuthors.ts +69 -0
  106. package/src/models/ModelDetail.ts +362 -0
  107. package/src/models/ModelError.ts +89 -0
  108. package/src/models/ModelIndex.ts +147 -0
  109. package/src/models/ModelSummary.ts +135 -0
  110. package/src/models/Passport.ts +75 -0
  111. package/src/models/index.ts +29 -0
  112. package/src/runtime.ts +505 -0
  113. package/tsconfig.esm.json +7 -0
  114. 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
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "compilerOptions": {
4
+ "module": "esnext",
5
+ "outDir": "dist/esm"
6
+ }
7
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,16 @@
1
+ {
2
+ "compilerOptions": {
3
+ "declaration": true,
4
+ "target": "es6",
5
+ "module": "commonjs",
6
+ "outDir": "dist",
7
+ "rootDir": "src",
8
+ "typeRoots": [
9
+ "node_modules/@types"
10
+ ]
11
+ },
12
+ "exclude": [
13
+ "dist",
14
+ "node_modules"
15
+ ]
16
+ }