@readme/api-core 7.0.0-beta.1 → 7.0.0-beta.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.
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -16
- package/dist/index.d.ts +2 -16
- package/dist/index.js.map +1 -1
- package/dist/types.cjs +1 -0
- package/dist/types.cjs.map +1 -0
- package/dist/types.d.cts +20 -0
- package/dist/types.d.ts +20 -0
- package/dist/types.js +1 -0
- package/dist/types.js.map +1 -0
- package/package.json +7 -3
- package/src/index.ts +1 -22
- package/src/types.ts +23 -0
- package/tsup.config.ts +1 -1
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;AAKA,OAAO,cAAc;AACrB,OAAO,cAAc;AACrB,OAAO,SAAS;AAKhB,IAAqB,UAArB,MAA6B;AAAA,EAC3B;AAAA,EAEQ,OAA4B,CAAC;AAAA,EAE7B,SAKA;AAAA,EAEA,SAAwB,CAAC;AAAA,EAEzB;AAAA,EAER,YAAY,YAAoD,WAAoB;AAClF,QAAI;AAAY,WAAK,OAAO,IAAI,KAAK,UAAU;AAC/C,QAAI;AAAW,WAAK,YAAY;AAAA,EAClC;AAAA,EAEA,QAAQ,MAAW;AACjB,SAAK,OAAO;AAAA,EACd;AAAA,EAEA,UAAU,QAAuB;AAC/B,SAAK,SAAS;AACd,WAAO;AAAA,EACT;AAAA,EAEA,aAAa,WAAmB;AAC9B,SAAK,YAAY;AACjB,WAAO;AAAA,EACT;AAAA,EAEA,WAAW,QAA6B;AACtC,SAAK,OAAO;AACZ,WAAO;AAAA,EACT;AAAA,EAEA,UAAU,KAAa,YAA6C,CAAC,GAAG;AACtE,SAAK,SAAS,EAAE,KAAK,UAAU;AAC/B,WAAO;AAAA,EACT;AAAA,EAEA,MAAM,MACJ,MACA,QACA,MACA,UACA;AACA,UAAM,YAAY,KAAK,KAAK,UAAU,MAAM,MAAM;AAElD,WAAO,KAAK,eAA2B,WAAW,MAAM,QAAQ;AAAA,EAClE;AAAA,EAEA,MAAM,eACJ,WACA,MACA,UACA;AACA,WAAO,cAAc,WAAW,MAAM,QAAQ,EAAE,KAAK,YAAU;AAC7D,YAAM,OAAO,EAAE,GAAG,OAAO;AAKzB,UAAI,KAAK,QAAQ;AACf,cAAM,iBAAiB,cAAc,KAAK,MAAM,KAAK,OAAO,KAAK,KAAK,OAAO,SAAS;AACtF,YAAI,gBAAgB;AAClB,eAAK,SAAS;AAAA,QAChB;AAAA,MACF;AAGA,YAAM,MAAM,SAAS,KAAK,MAAM,WAAW,MAAM,YAAY,KAAK,MAAM,SAAS,CAAC;AAElF,UAAI;AACJ,YAAM,OAAoB,CAAC;AAC3B,UAAI,KAAK,OAAO,SAAS;AACvB,cAAM,aAAa,IAAI,gBAAgB;AACvC,wBAAgB,WAAW,MAAM,WAAW,MAAM,GAAG,KAAK,OAAO,OAAO;AACxE,aAAK,SAAS,WAAW;AAAA,MAC3B;AAEA,aAAO,SAAS,KAAY;AAAA,QAC1B,OAAO,KAAK,SAAS,CAAC;AAAA,QACtB;AAAA,QACA,WAAW,KAAK;AAAA,MAClB,CAAC,EACE,KAAK,OAAO,QAAkB;AAC7B,cAAM,SAAS,MAAM,cAA0B,GAAG;AAElD,YAAI,IAAI,UAAU,OAAO,IAAI,UAAU,KAAK;AAC1C,gBAAM,IAAI;AAAA,YACR,OAAO;AAAA,YACP,OAAO;AAAA,YACP,OAAO;AAAA,YACP,OAAO;AAAA,UACT;AAAA,QACF;AAEA,eAAO;AAAA,MACT,CAAC,EACA,QAAQ,MAAM;AACb,YAAI,KAAK,OAAO,SAAS;AACvB,uBAAa,aAAa;AAAA,QAC5B;AAAA,MACF,CAAC;AAAA,IACL,CAAC;AAAA,EACH;AACF","sourcesContent":["import type { ConfigOptions } from './types.js';\nimport type { Har } from 'har-format';\nimport type Operation from 'oas/operation';\nimport type { HttpMethods, OASDocument } from 'oas/rmoas.types';\n\nimport oasToHar from '@readme/oas-to-har';\nimport fetchHar from 'fetch-har';\nimport Oas from 'oas';\n\nimport FetchError from './errors/fetchError.js';\nimport { parseResponse, prepareAuth, prepareParams, prepareServer } from './lib/index.js';\n\nexport default class APICore {\n spec!: Oas;\n\n private auth: (number | string)[] = [];\n\n private server:\n | false\n | {\n url: string;\n variables?: Record<string, string | number>;\n } = false;\n\n private config: ConfigOptions = {};\n\n private userAgent!: string;\n\n constructor(definition?: Record<string, unknown> | OASDocument, userAgent?: string) {\n if (definition) this.spec = Oas.init(definition);\n if (userAgent) this.userAgent = userAgent;\n }\n\n setSpec(spec: Oas) {\n this.spec = spec;\n }\n\n setConfig(config: ConfigOptions) {\n this.config = config;\n return this;\n }\n\n setUserAgent(userAgent: string) {\n this.userAgent = userAgent;\n return this;\n }\n\n setAuth(...values: string[] | number[]) {\n this.auth = values;\n return this;\n }\n\n setServer(url: string, variables: Record<string, string | number> = {}) {\n this.server = { url, variables };\n return this;\n }\n\n async fetch<HTTPStatus extends number = number>(\n path: string,\n method: HttpMethods,\n body?: unknown,\n metadata?: Record<string, unknown>,\n ) {\n const operation = this.spec.operation(path, method);\n\n return this.fetchOperation<HTTPStatus>(operation, body, metadata);\n }\n\n async fetchOperation<HTTPStatus extends number = number>(\n operation: Operation,\n body?: unknown,\n metadata?: Record<string, unknown>,\n ) {\n return prepareParams(operation, body, metadata).then(params => {\n const data = { ...params };\n\n // If `sdk.server()` has been issued data then we need to do some extra work to figure out\n // how to use that supplied server, and also handle any server variables that were sent\n // alongside it.\n if (this.server) {\n const preparedServer = prepareServer(this.spec, this.server.url, this.server.variables);\n if (preparedServer) {\n data.server = preparedServer;\n }\n }\n\n // @ts-expect-error `this.auth` typing is off. FIXME\n const har = oasToHar(this.spec, operation, data, prepareAuth(this.auth, operation));\n\n let timeoutSignal: NodeJS.Timeout;\n const init: RequestInit = {};\n if (this.config.timeout) {\n const controller = new AbortController();\n timeoutSignal = setTimeout(() => controller.abort(), this.config.timeout);\n init.signal = controller.signal;\n }\n\n return fetchHar(har as Har, {\n files: data.files || {},\n init,\n userAgent: this.userAgent,\n })\n .then(async (res: Response) => {\n const parsed = await parseResponse<HTTPStatus>(res);\n\n if (res.status >= 400 && res.status <= 599) {\n throw new FetchError<typeof parsed.status, typeof parsed.data>(\n parsed.status,\n parsed.data,\n parsed.headers,\n parsed.res,\n );\n }\n\n return parsed;\n })\n .finally(() => {\n if (this.config.timeout) {\n clearTimeout(timeoutSignal);\n }\n });\n });\n }\n}\n"]}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,22 +1,8 @@
|
|
|
1
|
+
import { ConfigOptions } from './types.cjs';
|
|
1
2
|
import Operation from 'oas/operation';
|
|
2
3
|
import { OASDocument, HttpMethods } from 'oas/rmoas.types';
|
|
3
4
|
import Oas from 'oas';
|
|
4
5
|
|
|
5
|
-
interface ConfigOptions {
|
|
6
|
-
/**
|
|
7
|
-
* Override the default `fetch` request timeout of 30 seconds. This number should be represented
|
|
8
|
-
* in milliseconds.
|
|
9
|
-
*/
|
|
10
|
-
timeout?: number;
|
|
11
|
-
}
|
|
12
|
-
interface FetchResponse<HTTPStatus, Data> {
|
|
13
|
-
data: Data;
|
|
14
|
-
headers: Headers;
|
|
15
|
-
res: Response;
|
|
16
|
-
status: HTTPStatus;
|
|
17
|
-
}
|
|
18
|
-
type Enumerate<N extends number, Acc extends number[] = []> = Acc['length'] extends N ? Acc[number] : Enumerate<N, [...Acc, Acc['length']]>;
|
|
19
|
-
type HTTPMethodRange<F extends number, T extends number> = Exclude<Enumerate<T>, Enumerate<F>>;
|
|
20
6
|
declare class APICore {
|
|
21
7
|
spec: Oas;
|
|
22
8
|
private auth;
|
|
@@ -43,4 +29,4 @@ declare class APICore {
|
|
|
43
29
|
}>;
|
|
44
30
|
}
|
|
45
31
|
|
|
46
|
-
export
|
|
32
|
+
export = APICore;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,22 +1,8 @@
|
|
|
1
|
+
import { ConfigOptions } from './types.js';
|
|
1
2
|
import Operation from 'oas/operation';
|
|
2
3
|
import { OASDocument, HttpMethods } from 'oas/rmoas.types';
|
|
3
4
|
import Oas from 'oas';
|
|
4
5
|
|
|
5
|
-
interface ConfigOptions {
|
|
6
|
-
/**
|
|
7
|
-
* Override the default `fetch` request timeout of 30 seconds. This number should be represented
|
|
8
|
-
* in milliseconds.
|
|
9
|
-
*/
|
|
10
|
-
timeout?: number;
|
|
11
|
-
}
|
|
12
|
-
interface FetchResponse<HTTPStatus, Data> {
|
|
13
|
-
data: Data;
|
|
14
|
-
headers: Headers;
|
|
15
|
-
res: Response;
|
|
16
|
-
status: HTTPStatus;
|
|
17
|
-
}
|
|
18
|
-
type Enumerate<N extends number, Acc extends number[] = []> = Acc['length'] extends N ? Acc[number] : Enumerate<N, [...Acc, Acc['length']]>;
|
|
19
|
-
type HTTPMethodRange<F extends number, T extends number> = Exclude<Enumerate<T>, Enumerate<F>>;
|
|
20
6
|
declare class APICore {
|
|
21
7
|
spec: Oas;
|
|
22
8
|
private auth;
|
|
@@ -43,4 +29,4 @@ declare class APICore {
|
|
|
43
29
|
}>;
|
|
44
30
|
}
|
|
45
31
|
|
|
46
|
-
export {
|
|
32
|
+
export { APICore as default };
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { Har } from 'har-format';\nimport type Operation from 'oas/operation';\nimport type { HttpMethods, OASDocument } from 'oas/rmoas.types';\n\nimport oasToHar from '@readme/oas-to-har';\nimport fetchHar from 'fetch-har';\nimport Oas from 'oas';\n\nimport FetchError from './errors/fetchError.js';\nimport { parseResponse, prepareAuth, prepareParams, prepareServer } from './lib/index.js';\n\nexport
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { ConfigOptions } from './types.js';\nimport type { Har } from 'har-format';\nimport type Operation from 'oas/operation';\nimport type { HttpMethods, OASDocument } from 'oas/rmoas.types';\n\nimport oasToHar from '@readme/oas-to-har';\nimport fetchHar from 'fetch-har';\nimport Oas from 'oas';\n\nimport FetchError from './errors/fetchError.js';\nimport { parseResponse, prepareAuth, prepareParams, prepareServer } from './lib/index.js';\n\nexport default class APICore {\n spec!: Oas;\n\n private auth: (number | string)[] = [];\n\n private server:\n | false\n | {\n url: string;\n variables?: Record<string, string | number>;\n } = false;\n\n private config: ConfigOptions = {};\n\n private userAgent!: string;\n\n constructor(definition?: Record<string, unknown> | OASDocument, userAgent?: string) {\n if (definition) this.spec = Oas.init(definition);\n if (userAgent) this.userAgent = userAgent;\n }\n\n setSpec(spec: Oas) {\n this.spec = spec;\n }\n\n setConfig(config: ConfigOptions) {\n this.config = config;\n return this;\n }\n\n setUserAgent(userAgent: string) {\n this.userAgent = userAgent;\n return this;\n }\n\n setAuth(...values: string[] | number[]) {\n this.auth = values;\n return this;\n }\n\n setServer(url: string, variables: Record<string, string | number> = {}) {\n this.server = { url, variables };\n return this;\n }\n\n async fetch<HTTPStatus extends number = number>(\n path: string,\n method: HttpMethods,\n body?: unknown,\n metadata?: Record<string, unknown>,\n ) {\n const operation = this.spec.operation(path, method);\n\n return this.fetchOperation<HTTPStatus>(operation, body, metadata);\n }\n\n async fetchOperation<HTTPStatus extends number = number>(\n operation: Operation,\n body?: unknown,\n metadata?: Record<string, unknown>,\n ) {\n return prepareParams(operation, body, metadata).then(params => {\n const data = { ...params };\n\n // If `sdk.server()` has been issued data then we need to do some extra work to figure out\n // how to use that supplied server, and also handle any server variables that were sent\n // alongside it.\n if (this.server) {\n const preparedServer = prepareServer(this.spec, this.server.url, this.server.variables);\n if (preparedServer) {\n data.server = preparedServer;\n }\n }\n\n // @ts-expect-error `this.auth` typing is off. FIXME\n const har = oasToHar(this.spec, operation, data, prepareAuth(this.auth, operation));\n\n let timeoutSignal: NodeJS.Timeout;\n const init: RequestInit = {};\n if (this.config.timeout) {\n const controller = new AbortController();\n timeoutSignal = setTimeout(() => controller.abort(), this.config.timeout);\n init.signal = controller.signal;\n }\n\n return fetchHar(har as Har, {\n files: data.files || {},\n init,\n userAgent: this.userAgent,\n })\n .then(async (res: Response) => {\n const parsed = await parseResponse<HTTPStatus>(res);\n\n if (res.status >= 400 && res.status <= 599) {\n throw new FetchError<typeof parsed.status, typeof parsed.data>(\n parsed.status,\n parsed.data,\n parsed.headers,\n parsed.res,\n );\n }\n\n return parsed;\n })\n .finally(() => {\n if (this.config.timeout) {\n clearTimeout(timeoutSignal);\n }\n });\n });\n }\n}\n"],"mappings":";;;;;;;;;;;AAKA,OAAO,cAAc;AACrB,OAAO,cAAc;AACrB,OAAO,SAAS;AAKhB,IAAqB,UAArB,MAA6B;AAAA,EAC3B;AAAA,EAEQ,OAA4B,CAAC;AAAA,EAE7B,SAKA;AAAA,EAEA,SAAwB,CAAC;AAAA,EAEzB;AAAA,EAER,YAAY,YAAoD,WAAoB;AAClF,QAAI;AAAY,WAAK,OAAO,IAAI,KAAK,UAAU;AAC/C,QAAI;AAAW,WAAK,YAAY;AAAA,EAClC;AAAA,EAEA,QAAQ,MAAW;AACjB,SAAK,OAAO;AAAA,EACd;AAAA,EAEA,UAAU,QAAuB;AAC/B,SAAK,SAAS;AACd,WAAO;AAAA,EACT;AAAA,EAEA,aAAa,WAAmB;AAC9B,SAAK,YAAY;AACjB,WAAO;AAAA,EACT;AAAA,EAEA,WAAW,QAA6B;AACtC,SAAK,OAAO;AACZ,WAAO;AAAA,EACT;AAAA,EAEA,UAAU,KAAa,YAA6C,CAAC,GAAG;AACtE,SAAK,SAAS,EAAE,KAAK,UAAU;AAC/B,WAAO;AAAA,EACT;AAAA,EAEA,MAAM,MACJ,MACA,QACA,MACA,UACA;AACA,UAAM,YAAY,KAAK,KAAK,UAAU,MAAM,MAAM;AAElD,WAAO,KAAK,eAA2B,WAAW,MAAM,QAAQ;AAAA,EAClE;AAAA,EAEA,MAAM,eACJ,WACA,MACA,UACA;AACA,WAAO,cAAc,WAAW,MAAM,QAAQ,EAAE,KAAK,YAAU;AAC7D,YAAM,OAAO,EAAE,GAAG,OAAO;AAKzB,UAAI,KAAK,QAAQ;AACf,cAAM,iBAAiB,cAAc,KAAK,MAAM,KAAK,OAAO,KAAK,KAAK,OAAO,SAAS;AACtF,YAAI,gBAAgB;AAClB,eAAK,SAAS;AAAA,QAChB;AAAA,MACF;AAGA,YAAM,MAAM,SAAS,KAAK,MAAM,WAAW,MAAM,YAAY,KAAK,MAAM,SAAS,CAAC;AAElF,UAAI;AACJ,YAAM,OAAoB,CAAC;AAC3B,UAAI,KAAK,OAAO,SAAS;AACvB,cAAM,aAAa,IAAI,gBAAgB;AACvC,wBAAgB,WAAW,MAAM,WAAW,MAAM,GAAG,KAAK,OAAO,OAAO;AACxE,aAAK,SAAS,WAAW;AAAA,MAC3B;AAEA,aAAO,SAAS,KAAY;AAAA,QAC1B,OAAO,KAAK,SAAS,CAAC;AAAA,QACtB;AAAA,QACA,WAAW,KAAK;AAAA,MAClB,CAAC,EACE,KAAK,OAAO,QAAkB;AAC7B,cAAM,SAAS,MAAM,cAA0B,GAAG;AAElD,YAAI,IAAI,UAAU,OAAO,IAAI,UAAU,KAAK;AAC1C,gBAAM,IAAI;AAAA,YACR,OAAO;AAAA,YACP,OAAO;AAAA,YACP,OAAO;AAAA,YACP,OAAO;AAAA,UACT;AAAA,QACF;AAEA,eAAO;AAAA,MACT,CAAC,EACA,QAAQ,MAAM;AACb,YAAI,KAAK,OAAO,SAAS;AACvB,uBAAa,aAAa;AAAA,QAC5B;AAAA,MACF,CAAC;AAAA,IACL,CAAC;AAAA,EACH;AACF;","names":[]}
|
package/dist/types.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";//# sourceMappingURL=types.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":""}
|
package/dist/types.d.cts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
interface ConfigOptions {
|
|
2
|
+
/**
|
|
3
|
+
* Override the default `fetch` request timeout of 30 seconds. This number should be represented
|
|
4
|
+
* in milliseconds.
|
|
5
|
+
*/
|
|
6
|
+
timeout?: number;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* @see {@link https://stackoverflow.com/a/39495173}
|
|
10
|
+
*/
|
|
11
|
+
type Enumerate<N extends number, Acc extends number[] = []> = Acc['length'] extends N ? Acc[number] : Enumerate<N, [...Acc, Acc['length']]>;
|
|
12
|
+
type HTTPMethodRange<F extends number, T extends number> = Exclude<Enumerate<T>, Enumerate<F>>;
|
|
13
|
+
interface FetchResponse<HTTPStatus, Data> {
|
|
14
|
+
data: Data;
|
|
15
|
+
headers: Headers;
|
|
16
|
+
res: Response;
|
|
17
|
+
status: HTTPStatus;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export { ConfigOptions, FetchResponse, HTTPMethodRange };
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
interface ConfigOptions {
|
|
2
|
+
/**
|
|
3
|
+
* Override the default `fetch` request timeout of 30 seconds. This number should be represented
|
|
4
|
+
* in milliseconds.
|
|
5
|
+
*/
|
|
6
|
+
timeout?: number;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* @see {@link https://stackoverflow.com/a/39495173}
|
|
10
|
+
*/
|
|
11
|
+
type Enumerate<N extends number, Acc extends number[] = []> = Acc['length'] extends N ? Acc[number] : Enumerate<N, [...Acc, Acc['length']]>;
|
|
12
|
+
type HTTPMethodRange<F extends number, T extends number> = Exclude<Enumerate<T>, Enumerate<F>>;
|
|
13
|
+
interface FetchResponse<HTTPStatus, Data> {
|
|
14
|
+
data: Data;
|
|
15
|
+
headers: Headers;
|
|
16
|
+
res: Response;
|
|
17
|
+
status: HTTPStatus;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export { ConfigOptions, FetchResponse, HTTPMethodRange };
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@readme/api-core",
|
|
3
|
-
"version": "7.0.0-beta.
|
|
3
|
+
"version": "7.0.0-beta.2",
|
|
4
4
|
"description": "The magic behind `api` 🧙",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"type": "module",
|
|
@@ -17,6 +17,10 @@
|
|
|
17
17
|
"require": "./dist/lib/index.cjs",
|
|
18
18
|
"import": "./dist/lib/index.js"
|
|
19
19
|
},
|
|
20
|
+
"./types": {
|
|
21
|
+
"require": "./dist/types.d.cjs",
|
|
22
|
+
"import": "./dist/types.d.js"
|
|
23
|
+
},
|
|
20
24
|
"./package.json": "./package.json"
|
|
21
25
|
},
|
|
22
26
|
"main": "dist/index.cjs",
|
|
@@ -56,7 +60,7 @@
|
|
|
56
60
|
"remove-undefined-objects": "^5.0.0"
|
|
57
61
|
},
|
|
58
62
|
"devDependencies": {
|
|
59
|
-
"@api/test-utils": "^7.0.0-beta.
|
|
63
|
+
"@api/test-utils": "^7.0.0-beta.2",
|
|
60
64
|
"@readme/oas-examples": "^5.12.0",
|
|
61
65
|
"@types/caseless": "^0.12.3",
|
|
62
66
|
"@types/lodash.merge": "^4.6.7",
|
|
@@ -67,5 +71,5 @@
|
|
|
67
71
|
"vitest": "^0.34.5"
|
|
68
72
|
},
|
|
69
73
|
"prettier": "@readme/eslint-config/prettier",
|
|
70
|
-
"gitHead": "
|
|
74
|
+
"gitHead": "39cdeb7b430a1a63f273715b79d76b5b652c3638"
|
|
71
75
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { ConfigOptions } from './types.js';
|
|
1
2
|
import type { Har } from 'har-format';
|
|
2
3
|
import type Operation from 'oas/operation';
|
|
3
4
|
import type { HttpMethods, OASDocument } from 'oas/rmoas.types';
|
|
@@ -9,28 +10,6 @@ import Oas from 'oas';
|
|
|
9
10
|
import FetchError from './errors/fetchError.js';
|
|
10
11
|
import { parseResponse, prepareAuth, prepareParams, prepareServer } from './lib/index.js';
|
|
11
12
|
|
|
12
|
-
export interface ConfigOptions {
|
|
13
|
-
/**
|
|
14
|
-
* Override the default `fetch` request timeout of 30 seconds. This number should be represented
|
|
15
|
-
* in milliseconds.
|
|
16
|
-
*/
|
|
17
|
-
timeout?: number;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export interface FetchResponse<HTTPStatus, Data> {
|
|
21
|
-
data: Data;
|
|
22
|
-
headers: Headers;
|
|
23
|
-
res: Response;
|
|
24
|
-
status: HTTPStatus;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
// https://stackoverflow.com/a/39495173
|
|
28
|
-
type Enumerate<N extends number, Acc extends number[] = []> = Acc['length'] extends N
|
|
29
|
-
? Acc[number]
|
|
30
|
-
: Enumerate<N, [...Acc, Acc['length']]>;
|
|
31
|
-
|
|
32
|
-
export type HTTPMethodRange<F extends number, T extends number> = Exclude<Enumerate<T>, Enumerate<F>>;
|
|
33
|
-
|
|
34
13
|
export default class APICore {
|
|
35
14
|
spec!: Oas;
|
|
36
15
|
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export interface ConfigOptions {
|
|
2
|
+
/**
|
|
3
|
+
* Override the default `fetch` request timeout of 30 seconds. This number should be represented
|
|
4
|
+
* in milliseconds.
|
|
5
|
+
*/
|
|
6
|
+
timeout?: number;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @see {@link https://stackoverflow.com/a/39495173}
|
|
11
|
+
*/
|
|
12
|
+
type Enumerate<N extends number, Acc extends number[] = []> = Acc['length'] extends N
|
|
13
|
+
? Acc[number]
|
|
14
|
+
: Enumerate<N, [...Acc, Acc['length']]>;
|
|
15
|
+
|
|
16
|
+
export type HTTPMethodRange<F extends number, T extends number> = Exclude<Enumerate<T>, Enumerate<F>>;
|
|
17
|
+
|
|
18
|
+
export interface FetchResponse<HTTPStatus, Data> {
|
|
19
|
+
data: Data;
|
|
20
|
+
headers: Headers;
|
|
21
|
+
res: Response;
|
|
22
|
+
status: HTTPStatus;
|
|
23
|
+
}
|
package/tsup.config.ts
CHANGED
|
@@ -10,7 +10,7 @@ export default defineConfig((options: Options) => ({
|
|
|
10
10
|
...options,
|
|
11
11
|
...config,
|
|
12
12
|
|
|
13
|
-
entry: ['src/errors/fetchError.ts', 'src/lib/index.ts', 'src/index.ts'],
|
|
13
|
+
entry: ['src/errors/fetchError.ts', 'src/lib/index.ts', 'src/index.ts', 'src/types.ts'],
|
|
14
14
|
noExternal: [
|
|
15
15
|
// `get-stream` is ESM-only and we need to build for CommonJS,
|
|
16
16
|
// so including it here means that its (tree-shaken!) source code
|