api-def 0.9.0 → 0.9.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/cjs/Api.d.ts +35 -35
- package/cjs/Api.js +140 -144
- package/cjs/ApiConstants.d.ts +58 -58
- package/cjs/ApiConstants.js +55 -55
- package/cjs/ApiTypes.d.ts +103 -103
- package/cjs/ApiTypes.js +4 -4
- package/cjs/ApiUtils.d.ts +6 -6
- package/cjs/ApiUtils.js +51 -53
- package/cjs/Endpoint.d.ts +52 -52
- package/cjs/Endpoint.js +104 -108
- package/cjs/EndpointBuilder.d.ts +14 -14
- package/cjs/EndpointBuilder.js +46 -46
- package/cjs/MockingTypes.d.ts +30 -30
- package/cjs/MockingTypes.js +2 -2
- package/cjs/QueryHandling.d.ts +3 -3
- package/cjs/QueryHandling.js +24 -24
- package/cjs/RequestConfig.d.ts +2 -2
- package/cjs/RequestConfig.js +74 -74
- package/cjs/RequestContext.d.ts +48 -48
- package/cjs/RequestContext.js +235 -238
- package/cjs/RequestError.d.ts +30 -30
- package/cjs/RequestError.js +47 -47
- package/cjs/Requester.d.ts +3 -3
- package/cjs/Requester.js +335 -336
- package/cjs/TextDecoding.d.ts +1 -1
- package/cjs/TextDecoding.js +152 -139
- package/cjs/UtilTypes.d.ts +5 -5
- package/cjs/UtilTypes.js +2 -2
- package/cjs/Utils.d.ts +15 -15
- package/cjs/Utils.js +79 -77
- package/cjs/Validation.d.ts +8 -8
- package/cjs/Validation.js +2 -2
- package/cjs/backend/AxiosRequestBackend.d.ts +13 -13
- package/cjs/backend/AxiosRequestBackend.js +99 -99
- package/cjs/backend/FetchRequestBackend.d.ts +15 -15
- package/cjs/backend/FetchRequestBackend.js +202 -197
- package/cjs/backend/MockRequestBackend.d.ts +11 -11
- package/cjs/backend/MockRequestBackend.js +164 -164
- package/cjs/backend/RequestBackend.d.ts +19 -19
- package/cjs/backend/RequestBackend.js +2 -2
- package/cjs/cache/CacheBackend.d.ts +6 -6
- package/cjs/cache/CacheBackend.js +2 -2
- package/cjs/cache/Caching.d.ts +10 -10
- package/cjs/cache/Caching.js +88 -88
- package/cjs/cache/LocalForageCacheBackend.d.ts +9 -9
- package/cjs/cache/LocalForageCacheBackend.js +24 -24
- package/cjs/cache/LocalStorageCacheBackend.d.ts +7 -7
- package/cjs/cache/LocalStorageCacheBackend.js +77 -77
- package/cjs/index.d.ts +13 -13
- package/cjs/index.js +41 -41
- package/cjs/middleware/CacheMiddleware.d.ts +7 -7
- package/cjs/middleware/CacheMiddleware.js +107 -107
- package/cjs/middleware/LoggingMiddleware.d.ts +6 -6
- package/cjs/middleware/LoggingMiddleware.js +82 -88
- package/cjs/util/retry/index.d.ts +3 -3
- package/cjs/util/retry/index.js +52 -52
- package/cjs/util/retry/lib/retry.d.ts +3 -3
- package/cjs/util/retry/lib/retry.js +50 -54
- package/cjs/util/retry/lib/retryOperation.d.ts +27 -27
- package/cjs/util/retry/lib/retryOperation.js +130 -134
- package/esm/Api.d.ts +35 -35
- package/esm/Api.js +92 -98
- package/esm/ApiConstants.d.ts +58 -58
- package/esm/ApiConstants.js +52 -52
- package/esm/ApiTypes.d.ts +103 -103
- package/esm/ApiTypes.js +1 -1
- package/esm/ApiUtils.d.ts +6 -6
- package/esm/ApiUtils.js +43 -45
- package/esm/Endpoint.d.ts +52 -52
- package/esm/Endpoint.js +66 -70
- package/esm/EndpointBuilder.d.ts +14 -14
- package/esm/EndpointBuilder.js +31 -31
- package/esm/MockingTypes.d.ts +30 -30
- package/esm/MockingTypes.js +1 -1
- package/esm/QueryHandling.d.ts +3 -3
- package/esm/QueryHandling.js +19 -19
- package/esm/RequestConfig.d.ts +2 -2
- package/esm/RequestConfig.js +56 -56
- package/esm/RequestContext.d.ts +48 -48
- package/esm/RequestContext.js +167 -170
- package/esm/RequestError.d.ts +30 -30
- package/esm/RequestError.js +42 -42
- package/esm/Requester.d.ts +3 -3
- package/esm/Requester.js +252 -253
- package/esm/TextDecoding.d.ts +1 -1
- package/esm/TextDecoding.js +148 -135
- package/esm/UtilTypes.d.ts +5 -5
- package/esm/UtilTypes.js +1 -1
- package/esm/Utils.d.ts +15 -15
- package/esm/Utils.js +66 -68
- package/esm/Validation.d.ts +8 -8
- package/esm/Validation.js +1 -1
- package/esm/backend/AxiosRequestBackend.d.ts +13 -13
- package/esm/backend/AxiosRequestBackend.js +62 -62
- package/esm/backend/FetchRequestBackend.d.ts +15 -15
- package/esm/backend/FetchRequestBackend.js +136 -126
- package/esm/backend/MockRequestBackend.d.ts +11 -11
- package/esm/backend/MockRequestBackend.js +116 -116
- package/esm/backend/RequestBackend.d.ts +19 -19
- package/esm/backend/RequestBackend.js +1 -1
- package/esm/cache/CacheBackend.d.ts +6 -6
- package/esm/cache/CacheBackend.js +1 -1
- package/esm/cache/Caching.d.ts +10 -10
- package/esm/cache/Caching.js +39 -39
- package/esm/cache/LocalForageCacheBackend.d.ts +9 -9
- package/esm/cache/LocalForageCacheBackend.js +20 -20
- package/esm/cache/LocalStorageCacheBackend.d.ts +7 -7
- package/esm/cache/LocalStorageCacheBackend.js +32 -32
- package/esm/index.d.ts +13 -13
- package/esm/index.js +14 -15
- package/esm/middleware/CacheMiddleware.d.ts +7 -7
- package/esm/middleware/CacheMiddleware.js +58 -58
- package/esm/middleware/LoggingMiddleware.d.ts +6 -6
- package/esm/middleware/LoggingMiddleware.js +77 -83
- package/esm/util/retry/index.d.ts +3 -3
- package/esm/util/retry/index.js +50 -50
- package/esm/util/retry/lib/retry.d.ts +3 -3
- package/esm/util/retry/lib/retry.js +35 -39
- package/esm/util/retry/lib/retryOperation.d.ts +27 -27
- package/esm/util/retry/lib/retryOperation.js +126 -132
- package/package.json +12 -32
package/cjs/ApiTypes.d.ts
CHANGED
|
@@ -1,103 +1,103 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
export
|
|
7
|
-
export
|
|
8
|
-
export
|
|
9
|
-
export
|
|
10
|
-
export
|
|
11
|
-
export interface ApiResponse<T = any> {
|
|
12
|
-
readonly method: RequestMethod;
|
|
13
|
-
readonly url: string;
|
|
14
|
-
readonly status: number;
|
|
15
|
-
readonly data: T;
|
|
16
|
-
readonly headers: Record<string, string>;
|
|
17
|
-
}
|
|
18
|
-
export
|
|
19
|
-
export
|
|
20
|
-
export
|
|
21
|
-
interface QueryHandling {
|
|
22
|
-
parse: QueryParse;
|
|
23
|
-
stringify: QueryStringify;
|
|
24
|
-
}
|
|
25
|
-
export interface RetryOptions {
|
|
26
|
-
maxAttempts: number;
|
|
27
|
-
shouldRetry?: (error: Error) => boolean;
|
|
28
|
-
minDelay?: number;
|
|
29
|
-
maxDelay?: number;
|
|
30
|
-
}
|
|
31
|
-
export interface BaseRequestConfig {
|
|
32
|
-
cache?: number | boolean;
|
|
33
|
-
lock?: RequestLock;
|
|
34
|
-
retry?: number | false | RetryOptions;
|
|
35
|
-
headers?: Readonly<Headers>;
|
|
36
|
-
acceptableStatus?: AcceptableStatus[];
|
|
37
|
-
/**
|
|
38
|
-
* @deprecated use `queryHandling.stringify` instead
|
|
39
|
-
**/
|
|
40
|
-
queryParser?: QueryStringify;
|
|
41
|
-
queryHandling?: Partial<QueryHandling>;
|
|
42
|
-
}
|
|
43
|
-
export
|
|
44
|
-
params?: never;
|
|
45
|
-
} : {
|
|
46
|
-
params: Record<P extends Params ? P : never, string>;
|
|
47
|
-
}) & (Q extends undefined ? {
|
|
48
|
-
query?: never;
|
|
49
|
-
} : {
|
|
50
|
-
query: Q;
|
|
51
|
-
}) & (B extends undefined ? {
|
|
52
|
-
body?: never;
|
|
53
|
-
} : {
|
|
54
|
-
body: B;
|
|
55
|
-
}) & BaseRequestConfig;
|
|
56
|
-
export declare const COMPUTED_CONFIG_SYMBOL: unique symbol;
|
|
57
|
-
export
|
|
58
|
-
[COMPUTED_CONFIG_SYMBOL]: true;
|
|
59
|
-
queryObject: Record<string, any> | undefined;
|
|
60
|
-
queryString: string | undefined;
|
|
61
|
-
queryHandling: QueryHandling;
|
|
62
|
-
};
|
|
63
|
-
interface BaseEventResult<T extends EventResultType> {
|
|
64
|
-
type: T;
|
|
65
|
-
}
|
|
66
|
-
export
|
|
67
|
-
response: ApiResponse<R>;
|
|
68
|
-
};
|
|
69
|
-
export
|
|
70
|
-
export
|
|
71
|
-
export
|
|
72
|
-
export
|
|
73
|
-
[key in RequestEvent]?: Array<RequestEventHandler<R>>;
|
|
74
|
-
};
|
|
75
|
-
export
|
|
76
|
-
[key in RequestEvent]?: RequestEventHandler<any> | undefined | false;
|
|
77
|
-
};
|
|
78
|
-
export interface RequestContextStats {
|
|
79
|
-
cached: false | {
|
|
80
|
-
is: true;
|
|
81
|
-
by: "local" | "api";
|
|
82
|
-
};
|
|
83
|
-
attempt: number;
|
|
84
|
-
}
|
|
85
|
-
export interface RequestHost {
|
|
86
|
-
readonly method: RequestMethod;
|
|
87
|
-
readonly api: Api;
|
|
88
|
-
readonly baseUrl: string;
|
|
89
|
-
readonly path: string;
|
|
90
|
-
readonly responseType: ResponseType | undefined;
|
|
91
|
-
readonly validation: Validation;
|
|
92
|
-
computeConfig<P extends Params | undefined, Q extends Query | undefined, B extends Body | undefined>(config: RequestConfig<P, Q, B>): ComputedRequestConfig<P, Q, B>;
|
|
93
|
-
computePath(path: string, config: RequestConfig): string;
|
|
94
|
-
getRequestBackend(): RequestBackend;
|
|
95
|
-
}
|
|
96
|
-
export interface CancelledRequestError extends Error {
|
|
97
|
-
isCancelledRequest: true;
|
|
98
|
-
}
|
|
99
|
-
export interface RequestCacheInfo {
|
|
100
|
-
cached: boolean;
|
|
101
|
-
source: CacheSource | null;
|
|
102
|
-
}
|
|
103
|
-
export {};
|
|
1
|
+
import { Api } from "./Api";
|
|
2
|
+
import { CacheSource, EventResultType, RequestEvent, RequestMethod, ResponseType } from "./ApiConstants";
|
|
3
|
+
import RequestContext from "./RequestContext";
|
|
4
|
+
import { Validation } from "./Validation";
|
|
5
|
+
import RequestBackend from "./backend/RequestBackend";
|
|
6
|
+
export type AcceptableStatus = number | [min: number, max: number];
|
|
7
|
+
export type Headers = Record<string, string | number | boolean | null | undefined>;
|
|
8
|
+
export type Params = string;
|
|
9
|
+
export type Query = string | undefined | Record<string, any>;
|
|
10
|
+
export type Body = string | number | Record<string, any>;
|
|
11
|
+
export interface ApiResponse<T = any> {
|
|
12
|
+
readonly method: RequestMethod;
|
|
13
|
+
readonly url: string;
|
|
14
|
+
readonly status: number;
|
|
15
|
+
readonly data: T;
|
|
16
|
+
readonly headers: Record<string, string>;
|
|
17
|
+
}
|
|
18
|
+
export type RequestLock = string | false;
|
|
19
|
+
export type QueryStringify = (query: any) => string;
|
|
20
|
+
export type QueryParse = (query: string) => any;
|
|
21
|
+
interface QueryHandling {
|
|
22
|
+
parse: QueryParse;
|
|
23
|
+
stringify: QueryStringify;
|
|
24
|
+
}
|
|
25
|
+
export interface RetryOptions {
|
|
26
|
+
maxAttempts: number;
|
|
27
|
+
shouldRetry?: (error: Error) => boolean;
|
|
28
|
+
minDelay?: number;
|
|
29
|
+
maxDelay?: number;
|
|
30
|
+
}
|
|
31
|
+
export interface BaseRequestConfig {
|
|
32
|
+
cache?: number | boolean;
|
|
33
|
+
lock?: RequestLock;
|
|
34
|
+
retry?: number | false | RetryOptions;
|
|
35
|
+
headers?: Readonly<Headers>;
|
|
36
|
+
acceptableStatus?: AcceptableStatus[];
|
|
37
|
+
/**
|
|
38
|
+
* @deprecated use `queryHandling.stringify` instead
|
|
39
|
+
**/
|
|
40
|
+
queryParser?: QueryStringify;
|
|
41
|
+
queryHandling?: Partial<QueryHandling>;
|
|
42
|
+
}
|
|
43
|
+
export type RequestConfig<P extends Params | undefined = Params | undefined, Q extends Query | undefined = Query | undefined, B extends Body | undefined = Body | undefined> = (P extends undefined ? {
|
|
44
|
+
params?: never;
|
|
45
|
+
} : {
|
|
46
|
+
params: Record<P extends Params ? P : never, string>;
|
|
47
|
+
}) & (Q extends undefined ? {
|
|
48
|
+
query?: never;
|
|
49
|
+
} : {
|
|
50
|
+
query: Q;
|
|
51
|
+
}) & (B extends undefined ? {
|
|
52
|
+
body?: never;
|
|
53
|
+
} : {
|
|
54
|
+
body: B;
|
|
55
|
+
}) & BaseRequestConfig;
|
|
56
|
+
export declare const COMPUTED_CONFIG_SYMBOL: unique symbol;
|
|
57
|
+
export type ComputedRequestConfig<P extends Params | undefined = Params | undefined, Q extends Query | undefined = Query | undefined, B extends Body | undefined = Body | undefined> = Omit<RequestConfig<P, Q, B>, "queryParser" | "query" | "queryHandling"> & {
|
|
58
|
+
[COMPUTED_CONFIG_SYMBOL]: true;
|
|
59
|
+
queryObject: Record<string, any> | undefined;
|
|
60
|
+
queryString: string | undefined;
|
|
61
|
+
queryHandling: QueryHandling;
|
|
62
|
+
};
|
|
63
|
+
interface BaseEventResult<T extends EventResultType> {
|
|
64
|
+
type: T;
|
|
65
|
+
}
|
|
66
|
+
export type ResponseEventResult<R> = BaseEventResult<"respond"> & {
|
|
67
|
+
response: ApiResponse<R>;
|
|
68
|
+
};
|
|
69
|
+
export type RetryEventResult<R> = BaseEventResult<"retry">;
|
|
70
|
+
export type EventResult<R> = ResponseEventResult<R> | RetryEventResult<R>;
|
|
71
|
+
export type RequestEventHandler<R> = (context: RequestContext<R>) => EventResult<R> | void | Promise<EventResult<R> | void>;
|
|
72
|
+
export type RequestEventHandlers<R> = {
|
|
73
|
+
[key in RequestEvent]?: Array<RequestEventHandler<R>>;
|
|
74
|
+
};
|
|
75
|
+
export type RequestMiddleware<O = undefined> = {
|
|
76
|
+
[key in RequestEvent]?: RequestEventHandler<any> | undefined | false;
|
|
77
|
+
};
|
|
78
|
+
export interface RequestContextStats {
|
|
79
|
+
cached: false | {
|
|
80
|
+
is: true;
|
|
81
|
+
by: "local" | "api";
|
|
82
|
+
};
|
|
83
|
+
attempt: number;
|
|
84
|
+
}
|
|
85
|
+
export interface RequestHost {
|
|
86
|
+
readonly method: RequestMethod;
|
|
87
|
+
readonly api: Api;
|
|
88
|
+
readonly baseUrl: string;
|
|
89
|
+
readonly path: string;
|
|
90
|
+
readonly responseType: ResponseType | undefined;
|
|
91
|
+
readonly validation: Validation;
|
|
92
|
+
computeConfig<P extends Params | undefined, Q extends Query | undefined, B extends Body | undefined>(config: RequestConfig<P, Q, B>): ComputedRequestConfig<P, Q, B>;
|
|
93
|
+
computePath(path: string, config: RequestConfig): string;
|
|
94
|
+
getRequestBackend(): RequestBackend;
|
|
95
|
+
}
|
|
96
|
+
export interface CancelledRequestError extends Error {
|
|
97
|
+
isCancelledRequest: true;
|
|
98
|
+
}
|
|
99
|
+
export interface RequestCacheInfo {
|
|
100
|
+
cached: boolean;
|
|
101
|
+
source: CacheSource | null;
|
|
102
|
+
}
|
|
103
|
+
export {};
|
package/cjs/ApiTypes.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.COMPUTED_CONFIG_SYMBOL = void 0;
|
|
4
|
-
exports.COMPUTED_CONFIG_SYMBOL = Symbol("computed");
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.COMPUTED_CONFIG_SYMBOL = void 0;
|
|
4
|
+
exports.COMPUTED_CONFIG_SYMBOL = Symbol("computed");
|
package/cjs/ApiUtils.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
export declare const isCancelledError: (error: Error) => error is CancelledRequestError;
|
|
4
|
-
export declare const isNetworkError: (error: Error) => boolean;
|
|
5
|
-
export declare const isAcceptableStatus: (status: number, acceptableStatus?: AcceptableStatus[]) => boolean;
|
|
6
|
-
export declare const inferResponseType: (contentType: string | null | undefined) => ResponseType;
|
|
1
|
+
import { ResponseType } from "./ApiConstants";
|
|
2
|
+
import { AcceptableStatus, CancelledRequestError } from "./ApiTypes";
|
|
3
|
+
export declare const isCancelledError: (error: Error) => error is CancelledRequestError;
|
|
4
|
+
export declare const isNetworkError: (error: Error) => boolean;
|
|
5
|
+
export declare const isAcceptableStatus: (status: number, acceptableStatus?: AcceptableStatus[]) => boolean;
|
|
6
|
+
export declare const inferResponseType: (contentType: string | null | undefined) => ResponseType;
|
package/cjs/ApiUtils.js
CHANGED
|
@@ -1,53 +1,51 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.inferResponseType = exports.isAcceptableStatus = exports.isNetworkError = exports.isCancelledError = void 0;
|
|
4
|
-
var isCancelledError = function (error) {
|
|
5
|
-
return "isCancelledRequest" in error;
|
|
6
|
-
};
|
|
7
|
-
exports.isCancelledError = isCancelledError;
|
|
8
|
-
var isNetworkError = function (error) {
|
|
9
|
-
var _a;
|
|
10
|
-
return
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
var
|
|
16
|
-
var
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
var
|
|
36
|
-
var
|
|
37
|
-
var
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
};
|
|
53
|
-
exports.inferResponseType = inferResponseType;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.inferResponseType = exports.isAcceptableStatus = exports.isNetworkError = exports.isCancelledError = void 0;
|
|
4
|
+
var isCancelledError = function (error) {
|
|
5
|
+
return "isCancelledRequest" in error;
|
|
6
|
+
};
|
|
7
|
+
exports.isCancelledError = isCancelledError;
|
|
8
|
+
var isNetworkError = function (error) {
|
|
9
|
+
var _a;
|
|
10
|
+
return error.name === "NetworkError" || error.message === "Network Error" || ((_a = error.constructor) === null || _a === void 0 ? void 0 : _a.name) === "NetworkError";
|
|
11
|
+
};
|
|
12
|
+
exports.isNetworkError = isNetworkError;
|
|
13
|
+
var DEFAULT_ACCEPTABLE_STATUS = [[200, 299], 304];
|
|
14
|
+
var isAcceptableStatus = function (status, acceptableStatus) {
|
|
15
|
+
var acceptable = acceptableStatus !== null && acceptableStatus !== void 0 ? acceptableStatus : DEFAULT_ACCEPTABLE_STATUS;
|
|
16
|
+
for (var _i = 0, acceptable_1 = acceptable; _i < acceptable_1.length; _i++) {
|
|
17
|
+
var cmpStatus = acceptable_1[_i];
|
|
18
|
+
if (Array.isArray(cmpStatus)) {
|
|
19
|
+
var min = cmpStatus[0], max = cmpStatus[1];
|
|
20
|
+
if (status >= min && status <= max) {
|
|
21
|
+
return true;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
else if (!Number.isNaN(cmpStatus)) {
|
|
25
|
+
if (status === cmpStatus) {
|
|
26
|
+
return true;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return false;
|
|
31
|
+
};
|
|
32
|
+
exports.isAcceptableStatus = isAcceptableStatus;
|
|
33
|
+
var TEXT_CONTENT_TYPES = ["text/plain", "text/html", "text/xml", "application/xml"];
|
|
34
|
+
var JSON_CONTENT_TYPES = ["text/json", "application/json"];
|
|
35
|
+
var ARRAY_BUFFER_CONTENT_TYPES = ["application/octet-stream"];
|
|
36
|
+
var inferResponseType = function (contentType) {
|
|
37
|
+
var contentTypePart = contentType === null || contentType === void 0 ? void 0 : contentType.split(";")[0].trim();
|
|
38
|
+
if (contentTypePart) {
|
|
39
|
+
if (TEXT_CONTENT_TYPES.includes(contentTypePart)) {
|
|
40
|
+
return "text";
|
|
41
|
+
}
|
|
42
|
+
if (JSON_CONTENT_TYPES.includes(contentTypePart)) {
|
|
43
|
+
return "json";
|
|
44
|
+
}
|
|
45
|
+
if (ARRAY_BUFFER_CONTENT_TYPES.includes(contentTypePart)) {
|
|
46
|
+
return "arraybuffer";
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return "text";
|
|
50
|
+
};
|
|
51
|
+
exports.inferResponseType = inferResponseType;
|
package/cjs/Endpoint.d.ts
CHANGED
|
@@ -1,52 +1,52 @@
|
|
|
1
|
-
import { Api } from "./Api";
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
export interface EndpointConfig<R, P extends Params | undefined, Q extends Query | undefined, B extends Body | undefined, Path extends string = string> {
|
|
8
|
-
readonly id: string;
|
|
9
|
-
readonly method: RequestMethod;
|
|
10
|
-
readonly path: Path;
|
|
11
|
-
/**
|
|
12
|
-
* Name your endpoint to help with debugging and documentation
|
|
13
|
-
* @default `id` is used as the name if no name is supplied
|
|
14
|
-
*/
|
|
15
|
-
readonly name?: string;
|
|
16
|
-
/**
|
|
17
|
-
* Describe your endpoint to help with debugging and documentation
|
|
18
|
-
*/
|
|
19
|
-
readonly description?: string;
|
|
20
|
-
readonly config?: BaseRequestConfig;
|
|
21
|
-
/**
|
|
22
|
-
* Let the backend requestor (fetch, axios, etc.) know what type of response
|
|
23
|
-
* you are expecting from this endpoint
|
|
24
|
-
* @default `application/json`
|
|
25
|
-
*/
|
|
26
|
-
readonly responseType?: ResponseType;
|
|
27
|
-
/**
|
|
28
|
-
* Specify mocking for your endpoint upfront to help with disconnected dev,
|
|
29
|
-
* and testing.
|
|
30
|
-
* Enable/disable mocked returns for all endpoints on your API object.
|
|
31
|
-
*/
|
|
32
|
-
readonly mocking?: Mocking.EndpointMockingConfig<R, P, Q, B>;
|
|
33
|
-
readonly validation?: Validation<R, P, Q, B>;
|
|
34
|
-
}
|
|
35
|
-
export default class Endpoint<R = any, P extends Params | undefined = Params | undefined, Q extends Query | undefined = Query | undefined, B extends Body | undefined = Body | undefined> implements EndpointConfig<R, P, Q, B>, RequestHost {
|
|
36
|
-
readonly api: Api;
|
|
37
|
-
readonly id: string;
|
|
38
|
-
readonly method: RequestMethod;
|
|
39
|
-
readonly name: string;
|
|
40
|
-
readonly description?: string;
|
|
41
|
-
readonly path: string;
|
|
42
|
-
readonly config?: BaseRequestConfig;
|
|
43
|
-
readonly responseType: ResponseType | undefined;
|
|
44
|
-
readonly mocking?: Mocking.EndpointMockingConfig<R, P, Q, B>;
|
|
45
|
-
readonly validation: Validation<R, P, Q, B>;
|
|
46
|
-
constructor(api: Api, info: EndpointConfig<R, P, Q, B>);
|
|
47
|
-
submit(config: RequestConfig<P, Q, B>): Promise<ApiResponse<R>>;
|
|
48
|
-
computePath(path: string, request: RequestConfig): string;
|
|
49
|
-
get baseUrl(): string;
|
|
50
|
-
computeConfig<P extends Params | undefined, Q extends Query | undefined, B extends Body | undefined>(config: RequestConfig<P, Q, B>): ComputedRequestConfig<P, Q, B>;
|
|
51
|
-
getRequestBackend(): RequestBackend;
|
|
52
|
-
}
|
|
1
|
+
import { Api } from "./Api";
|
|
2
|
+
import { RequestMethod, ResponseType } from "./ApiConstants";
|
|
3
|
+
import { ApiResponse, BaseRequestConfig, Body, ComputedRequestConfig, Params, Query, RequestConfig, RequestHost } from "./ApiTypes";
|
|
4
|
+
import * as Mocking from "./MockingTypes";
|
|
5
|
+
import { Validation } from "./Validation";
|
|
6
|
+
import RequestBackend from "./backend/RequestBackend";
|
|
7
|
+
export interface EndpointConfig<R, P extends Params | undefined, Q extends Query | undefined, B extends Body | undefined, Path extends string = string> {
|
|
8
|
+
readonly id: string;
|
|
9
|
+
readonly method: RequestMethod;
|
|
10
|
+
readonly path: Path;
|
|
11
|
+
/**
|
|
12
|
+
* Name your endpoint to help with debugging and documentation
|
|
13
|
+
* @default `id` is used as the name if no name is supplied
|
|
14
|
+
*/
|
|
15
|
+
readonly name?: string;
|
|
16
|
+
/**
|
|
17
|
+
* Describe your endpoint to help with debugging and documentation
|
|
18
|
+
*/
|
|
19
|
+
readonly description?: string;
|
|
20
|
+
readonly config?: BaseRequestConfig;
|
|
21
|
+
/**
|
|
22
|
+
* Let the backend requestor (fetch, axios, etc.) know what type of response
|
|
23
|
+
* you are expecting from this endpoint
|
|
24
|
+
* @default `application/json`
|
|
25
|
+
*/
|
|
26
|
+
readonly responseType?: ResponseType;
|
|
27
|
+
/**
|
|
28
|
+
* Specify mocking for your endpoint upfront to help with disconnected dev,
|
|
29
|
+
* and testing.
|
|
30
|
+
* Enable/disable mocked returns for all endpoints on your API object.
|
|
31
|
+
*/
|
|
32
|
+
readonly mocking?: Mocking.EndpointMockingConfig<R, P, Q, B>;
|
|
33
|
+
readonly validation?: Validation<R, P, Q, B>;
|
|
34
|
+
}
|
|
35
|
+
export default class Endpoint<R = any, P extends Params | undefined = Params | undefined, Q extends Query | undefined = Query | undefined, B extends Body | undefined = Body | undefined> implements EndpointConfig<R, P, Q, B>, RequestHost {
|
|
36
|
+
readonly api: Api;
|
|
37
|
+
readonly id: string;
|
|
38
|
+
readonly method: RequestMethod;
|
|
39
|
+
readonly name: string;
|
|
40
|
+
readonly description?: string;
|
|
41
|
+
readonly path: string;
|
|
42
|
+
readonly config?: BaseRequestConfig;
|
|
43
|
+
readonly responseType: ResponseType | undefined;
|
|
44
|
+
readonly mocking?: Mocking.EndpointMockingConfig<R, P, Q, B>;
|
|
45
|
+
readonly validation: Validation<R, P, Q, B>;
|
|
46
|
+
constructor(api: Api, info: EndpointConfig<R, P, Q, B>);
|
|
47
|
+
submit(config: RequestConfig<P, Q, B>): Promise<ApiResponse<R>>;
|
|
48
|
+
computePath(path: string, request: RequestConfig): string;
|
|
49
|
+
get baseUrl(): string;
|
|
50
|
+
computeConfig<P extends Params | undefined, Q extends Query | undefined, B extends Body | undefined>(config: RequestConfig<P, Q, B>): ComputedRequestConfig<P, Q, B>;
|
|
51
|
+
getRequestBackend(): RequestBackend;
|
|
52
|
+
}
|