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/Api.d.ts
CHANGED
|
@@ -1,35 +1,35 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
export declare const getRequestBackend: () => RequestBackend | null;
|
|
7
|
-
export declare const isRequestBackendDefault: () => boolean;
|
|
8
|
-
export declare const setRequestBackend: (backend: RequestBackend) => void;
|
|
9
|
-
export interface ApiInfo {
|
|
10
|
-
readonly name: string;
|
|
11
|
-
readonly baseUrl: string;
|
|
12
|
-
readonly middleware?: RequestMiddleware[];
|
|
13
|
-
readonly config?: BaseRequestConfig | (() => BaseRequestConfig);
|
|
14
|
-
readonly mocking?: ApiMockingConfig;
|
|
15
|
-
readonly requestBackend?: RequestBackend;
|
|
16
|
-
}
|
|
17
|
-
export declare class Api implements ApiInfo {
|
|
18
|
-
readonly baseUrl: string;
|
|
19
|
-
readonly name: string;
|
|
20
|
-
readonly middleware: RequestMiddleware[];
|
|
21
|
-
readonly config?: BaseRequestConfig | (() => BaseRequestConfig);
|
|
22
|
-
readonly mocking?: ApiMockingConfig;
|
|
23
|
-
readonly requestBackend: RequestBackend;
|
|
24
|
-
protected readonly endpoints: Record<string, Endpoint>;
|
|
25
|
-
constructor(info: ApiInfo);
|
|
26
|
-
endpoint(): EndpointBuilder;
|
|
27
|
-
getRequestBackend(): RequestBackend;
|
|
28
|
-
getConfig(): BaseRequestConfig;
|
|
29
|
-
private hotRequest;
|
|
30
|
-
get: <R = unknown>(path: string, config: RequestConfig) => Promise<ApiResponse<R>>;
|
|
31
|
-
post: <R = unknown>(path: string, config: RequestConfig) => Promise<ApiResponse<R>>;
|
|
32
|
-
put: <R = unknown>(path: string, config: RequestConfig) => Promise<ApiResponse<R>>;
|
|
33
|
-
delete: <R = unknown>(path: string, config: RequestConfig) => Promise<ApiResponse<R>>;
|
|
34
|
-
patch: <R = unknown>(path: string, config: RequestConfig) => Promise<ApiResponse<R>>;
|
|
35
|
-
}
|
|
1
|
+
import { ApiResponse, BaseRequestConfig, RequestConfig, RequestMiddleware } from "./ApiTypes";
|
|
2
|
+
import Endpoint from "./Endpoint";
|
|
3
|
+
import EndpointBuilder from "./EndpointBuilder";
|
|
4
|
+
import { ApiMockingConfig } from "./MockingTypes";
|
|
5
|
+
import RequestBackend from "./backend/RequestBackend";
|
|
6
|
+
export declare const getRequestBackend: () => RequestBackend | null;
|
|
7
|
+
export declare const isRequestBackendDefault: () => boolean;
|
|
8
|
+
export declare const setRequestBackend: (backend: RequestBackend) => void;
|
|
9
|
+
export interface ApiInfo {
|
|
10
|
+
readonly name: string;
|
|
11
|
+
readonly baseUrl: string;
|
|
12
|
+
readonly middleware?: RequestMiddleware[];
|
|
13
|
+
readonly config?: BaseRequestConfig | (() => BaseRequestConfig);
|
|
14
|
+
readonly mocking?: ApiMockingConfig;
|
|
15
|
+
readonly requestBackend?: RequestBackend;
|
|
16
|
+
}
|
|
17
|
+
export declare class Api implements ApiInfo {
|
|
18
|
+
readonly baseUrl: string;
|
|
19
|
+
readonly name: string;
|
|
20
|
+
readonly middleware: RequestMiddleware[];
|
|
21
|
+
readonly config?: BaseRequestConfig | (() => BaseRequestConfig);
|
|
22
|
+
readonly mocking?: ApiMockingConfig;
|
|
23
|
+
readonly requestBackend: RequestBackend;
|
|
24
|
+
protected readonly endpoints: Record<string, Endpoint>;
|
|
25
|
+
constructor(info: ApiInfo);
|
|
26
|
+
endpoint(): EndpointBuilder;
|
|
27
|
+
getRequestBackend(): RequestBackend;
|
|
28
|
+
getConfig(): BaseRequestConfig;
|
|
29
|
+
private hotRequest;
|
|
30
|
+
get: <R = unknown>(path: string, config: RequestConfig) => Promise<ApiResponse<R>>;
|
|
31
|
+
post: <R = unknown>(path: string, config: RequestConfig) => Promise<ApiResponse<R>>;
|
|
32
|
+
put: <R = unknown>(path: string, config: RequestConfig) => Promise<ApiResponse<R>>;
|
|
33
|
+
delete: <R = unknown>(path: string, config: RequestConfig) => Promise<ApiResponse<R>>;
|
|
34
|
+
patch: <R = unknown>(path: string, config: RequestConfig) => Promise<ApiResponse<R>>;
|
|
35
|
+
}
|
package/cjs/Api.js
CHANGED
|
@@ -1,144 +1,140 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
-
function step(op) {
|
|
16
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (_) try {
|
|
18
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
-
switch (op[0]) {
|
|
21
|
-
case 0: case 1: t = op; break;
|
|
22
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
-
default:
|
|
26
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
-
if (t[2]) _.ops.pop();
|
|
31
|
-
_.trys.pop(); continue;
|
|
32
|
-
}
|
|
33
|
-
op = body.call(thisArg, _);
|
|
34
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.Api = exports.setRequestBackend = exports.isRequestBackendDefault = exports.getRequestBackend = void 0;
|
|
40
|
-
var
|
|
41
|
-
var EndpointBuilder_1 = require("./EndpointBuilder");
|
|
42
|
-
var
|
|
43
|
-
var
|
|
44
|
-
var
|
|
45
|
-
var
|
|
46
|
-
// use fetch as default if it is present
|
|
47
|
-
var requestBackend = Utils.getGlobalFetch() ? new FetchRequestBackend_1.default() : null;
|
|
48
|
-
var requestBackendIsDefault = true;
|
|
49
|
-
var getRequestBackend = function () {
|
|
50
|
-
return requestBackend;
|
|
51
|
-
};
|
|
52
|
-
exports.getRequestBackend = getRequestBackend;
|
|
53
|
-
var isRequestBackendDefault = function () {
|
|
54
|
-
return requestBackendIsDefault;
|
|
55
|
-
};
|
|
56
|
-
exports.isRequestBackendDefault = isRequestBackendDefault;
|
|
57
|
-
var setRequestBackend = function (backend) {
|
|
58
|
-
requestBackendIsDefault = false;
|
|
59
|
-
requestBackend = backend;
|
|
60
|
-
};
|
|
61
|
-
exports.setRequestBackend = setRequestBackend;
|
|
62
|
-
var HotRequestHost = /** @class */ (function () {
|
|
63
|
-
function HotRequestHost(api, path, method) {
|
|
64
|
-
this.responseType = undefined;
|
|
65
|
-
this.validation = {};
|
|
66
|
-
this.api = api;
|
|
67
|
-
this.method = method;
|
|
68
|
-
this.path = path;
|
|
69
|
-
}
|
|
70
|
-
Object.defineProperty(HotRequestHost.prototype, "baseUrl", {
|
|
71
|
-
get: function () {
|
|
72
|
-
return this.api.baseUrl;
|
|
73
|
-
},
|
|
74
|
-
enumerable: false,
|
|
75
|
-
configurable: true
|
|
76
|
-
});
|
|
77
|
-
HotRequestHost.prototype.computeConfig = function (config) {
|
|
78
|
-
var apiDefaults = this.api.getConfig();
|
|
79
|
-
return (0, RequestConfig_1.computeRequestConfig)([
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
};
|
|
84
|
-
HotRequestHost.prototype.
|
|
85
|
-
return
|
|
86
|
-
};
|
|
87
|
-
HotRequestHost
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
var
|
|
93
|
-
var
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
this.
|
|
107
|
-
this.
|
|
108
|
-
this.
|
|
109
|
-
this.
|
|
110
|
-
this.
|
|
111
|
-
this.
|
|
112
|
-
this.
|
|
113
|
-
this.
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
}
|
|
132
|
-
Api.prototype.
|
|
133
|
-
return
|
|
134
|
-
};
|
|
135
|
-
Api.prototype.
|
|
136
|
-
return this.
|
|
137
|
-
};
|
|
138
|
-
Api
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
};
|
|
142
|
-
return Api;
|
|
143
|
-
}());
|
|
144
|
-
exports.Api = Api;
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.Api = exports.setRequestBackend = exports.isRequestBackendDefault = exports.getRequestBackend = void 0;
|
|
40
|
+
var ApiConstants_1 = require("./ApiConstants");
|
|
41
|
+
var EndpointBuilder_1 = require("./EndpointBuilder");
|
|
42
|
+
var RequestConfig_1 = require("./RequestConfig");
|
|
43
|
+
var Requester = require("./Requester");
|
|
44
|
+
var Utils = require("./Utils");
|
|
45
|
+
var FetchRequestBackend_1 = require("./backend/FetchRequestBackend");
|
|
46
|
+
// use fetch as default if it is present
|
|
47
|
+
var requestBackend = Utils.getGlobalFetch() ? new FetchRequestBackend_1.default() : null;
|
|
48
|
+
var requestBackendIsDefault = true;
|
|
49
|
+
var getRequestBackend = function () {
|
|
50
|
+
return requestBackend;
|
|
51
|
+
};
|
|
52
|
+
exports.getRequestBackend = getRequestBackend;
|
|
53
|
+
var isRequestBackendDefault = function () {
|
|
54
|
+
return requestBackendIsDefault;
|
|
55
|
+
};
|
|
56
|
+
exports.isRequestBackendDefault = isRequestBackendDefault;
|
|
57
|
+
var setRequestBackend = function (backend) {
|
|
58
|
+
requestBackendIsDefault = false;
|
|
59
|
+
requestBackend = backend;
|
|
60
|
+
};
|
|
61
|
+
exports.setRequestBackend = setRequestBackend;
|
|
62
|
+
var HotRequestHost = /** @class */ (function () {
|
|
63
|
+
function HotRequestHost(api, path, method) {
|
|
64
|
+
this.responseType = undefined;
|
|
65
|
+
this.validation = {};
|
|
66
|
+
this.api = api;
|
|
67
|
+
this.method = method;
|
|
68
|
+
this.path = path;
|
|
69
|
+
}
|
|
70
|
+
Object.defineProperty(HotRequestHost.prototype, "baseUrl", {
|
|
71
|
+
get: function () {
|
|
72
|
+
return this.api.baseUrl;
|
|
73
|
+
},
|
|
74
|
+
enumerable: false,
|
|
75
|
+
configurable: true
|
|
76
|
+
});
|
|
77
|
+
HotRequestHost.prototype.computeConfig = function (config) {
|
|
78
|
+
var apiDefaults = this.api.getConfig();
|
|
79
|
+
return (0, RequestConfig_1.computeRequestConfig)([apiDefaults, config]);
|
|
80
|
+
};
|
|
81
|
+
HotRequestHost.prototype.computePath = function (path, config) {
|
|
82
|
+
return path.startsWith("/") ? path : "/".concat(path);
|
|
83
|
+
};
|
|
84
|
+
HotRequestHost.prototype.getRequestBackend = function () {
|
|
85
|
+
return this.api.getRequestBackend();
|
|
86
|
+
};
|
|
87
|
+
return HotRequestHost;
|
|
88
|
+
}());
|
|
89
|
+
var defaultBackendMessageShown = false;
|
|
90
|
+
var Api = /** @class */ (function () {
|
|
91
|
+
function Api(info) {
|
|
92
|
+
var _this = this;
|
|
93
|
+
var _a, _b;
|
|
94
|
+
this.endpoints = {};
|
|
95
|
+
this.hotRequest = function (requestMethod) {
|
|
96
|
+
return function (path, config) { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {
|
|
97
|
+
switch (_a.label) {
|
|
98
|
+
case 0: return [4 /*yield*/, Requester.submit(new HotRequestHost(this, path, requestMethod), config, null)];
|
|
99
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
100
|
+
}
|
|
101
|
+
}); }); };
|
|
102
|
+
};
|
|
103
|
+
this.get = this.hotRequest(ApiConstants_1.RequestMethod.GET);
|
|
104
|
+
this.post = this.hotRequest(ApiConstants_1.RequestMethod.POST);
|
|
105
|
+
this.put = this.hotRequest(ApiConstants_1.RequestMethod.PUT);
|
|
106
|
+
this.delete = this.hotRequest(ApiConstants_1.RequestMethod.DELETE);
|
|
107
|
+
this.patch = this.hotRequest(ApiConstants_1.RequestMethod.PATCH);
|
|
108
|
+
this.name = info.name;
|
|
109
|
+
this.baseUrl = info.baseUrl;
|
|
110
|
+
this.middleware = info.middleware || [];
|
|
111
|
+
this.endpoints = {};
|
|
112
|
+
this.config = info.config;
|
|
113
|
+
this.mocking = (_a = info.mocking) !== null && _a !== void 0 ? _a : undefined;
|
|
114
|
+
var requestBackend = (_b = info.requestBackend) !== null && _b !== void 0 ? _b : (0, exports.getRequestBackend)();
|
|
115
|
+
if (!requestBackend) {
|
|
116
|
+
throw new Error("[api-def] No request backend provided in either Api options or globally, use `setRequestBackend()` to set one or pass one via `requestBackend`");
|
|
117
|
+
}
|
|
118
|
+
this.requestBackend = requestBackend;
|
|
119
|
+
if (!info.requestBackend) {
|
|
120
|
+
if (process.env.NODE_ENV === "development") {
|
|
121
|
+
if ((0, exports.isRequestBackendDefault)() && !defaultBackendMessageShown) {
|
|
122
|
+
defaultBackendMessageShown = true;
|
|
123
|
+
// eslint-disable-next-line
|
|
124
|
+
console.warn("[api-def] Using default fetch backend, you can use a different one with 'setRequestBackend()' (dev only message)");
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
Api.prototype.endpoint = function () {
|
|
130
|
+
return new EndpointBuilder_1.default(this);
|
|
131
|
+
};
|
|
132
|
+
Api.prototype.getRequestBackend = function () {
|
|
133
|
+
return this.requestBackend;
|
|
134
|
+
};
|
|
135
|
+
Api.prototype.getConfig = function () {
|
|
136
|
+
return (typeof this.config === "function" ? this.config() : this.config) || {};
|
|
137
|
+
};
|
|
138
|
+
return Api;
|
|
139
|
+
}());
|
|
140
|
+
exports.Api = Api;
|
package/cjs/ApiConstants.d.ts
CHANGED
|
@@ -1,58 +1,58 @@
|
|
|
1
|
-
import { EnumOf } from "./Utils";
|
|
2
|
-
export declare const RequestMethod: {
|
|
3
|
-
/** @deprecated use 'POST' */
|
|
4
|
-
readonly Post: "post";
|
|
5
|
-
/** @deprecated use 'GET' */
|
|
6
|
-
readonly Get: "get";
|
|
7
|
-
readonly POST: "post";
|
|
8
|
-
readonly GET: "get";
|
|
9
|
-
readonly PUT: "put";
|
|
10
|
-
readonly DELETE: "delete";
|
|
11
|
-
readonly PATCH: "patch";
|
|
12
|
-
};
|
|
13
|
-
export
|
|
14
|
-
export declare const RequestEvent: {
|
|
15
|
-
/** @deprecated use 'BEFORE_SEND' */
|
|
16
|
-
readonly BeforeSend: "beforeSend";
|
|
17
|
-
/** @deprecated use 'SUCCESS' */
|
|
18
|
-
readonly Success: "success";
|
|
19
|
-
/** @deprecated use 'ERROR' */
|
|
20
|
-
readonly Error: "error";
|
|
21
|
-
/** @deprecated use 'UNRECOVERABLE_ERROR' */
|
|
22
|
-
readonly UnrecoverableError: "unrecoverableError";
|
|
23
|
-
readonly BEFORE_SEND: "beforeSend";
|
|
24
|
-
readonly SUCCESS: "success";
|
|
25
|
-
readonly ERROR: "error";
|
|
26
|
-
readonly UNRECOVERABLE_ERROR: "unrecoverableError";
|
|
27
|
-
};
|
|
28
|
-
export
|
|
29
|
-
export declare const EventResultType: {
|
|
30
|
-
/** @deprecated use 'RESPOND' */
|
|
31
|
-
readonly Respond: "respond";
|
|
32
|
-
/** @deprecated use 'RETRY' */
|
|
33
|
-
readonly Retry: "retry";
|
|
34
|
-
readonly RESPOND: "respond";
|
|
35
|
-
readonly RETRY: "retry";
|
|
36
|
-
};
|
|
37
|
-
export
|
|
38
|
-
export declare const CacheSource: {
|
|
39
|
-
/** @deprecated use 'API' */
|
|
40
|
-
readonly Api: "api";
|
|
41
|
-
/** @deprecated use 'LOCAL' */
|
|
42
|
-
readonly Local: "local";
|
|
43
|
-
readonly API: "api";
|
|
44
|
-
readonly LOCAL: "local";
|
|
45
|
-
};
|
|
46
|
-
export
|
|
47
|
-
export declare const ResponseType: {
|
|
48
|
-
/** @deprecated use 'JSON' */
|
|
49
|
-
readonly Json: "json";
|
|
50
|
-
/** @deprecated use 'TEXT' */
|
|
51
|
-
readonly Text: "text";
|
|
52
|
-
/** @deprecated use 'ARRAY_BUFFER' */
|
|
53
|
-
readonly ArrayBuffer: "arraybuffer";
|
|
54
|
-
readonly JSON: "json";
|
|
55
|
-
readonly TEXT: "text";
|
|
56
|
-
readonly ARRAY_BUFFER: "arraybuffer";
|
|
57
|
-
};
|
|
58
|
-
export
|
|
1
|
+
import { EnumOf } from "./Utils";
|
|
2
|
+
export declare const RequestMethod: {
|
|
3
|
+
/** @deprecated use 'POST' */
|
|
4
|
+
readonly Post: "post";
|
|
5
|
+
/** @deprecated use 'GET' */
|
|
6
|
+
readonly Get: "get";
|
|
7
|
+
readonly POST: "post";
|
|
8
|
+
readonly GET: "get";
|
|
9
|
+
readonly PUT: "put";
|
|
10
|
+
readonly DELETE: "delete";
|
|
11
|
+
readonly PATCH: "patch";
|
|
12
|
+
};
|
|
13
|
+
export type RequestMethod = EnumOf<typeof RequestMethod>;
|
|
14
|
+
export declare const RequestEvent: {
|
|
15
|
+
/** @deprecated use 'BEFORE_SEND' */
|
|
16
|
+
readonly BeforeSend: "beforeSend";
|
|
17
|
+
/** @deprecated use 'SUCCESS' */
|
|
18
|
+
readonly Success: "success";
|
|
19
|
+
/** @deprecated use 'ERROR' */
|
|
20
|
+
readonly Error: "error";
|
|
21
|
+
/** @deprecated use 'UNRECOVERABLE_ERROR' */
|
|
22
|
+
readonly UnrecoverableError: "unrecoverableError";
|
|
23
|
+
readonly BEFORE_SEND: "beforeSend";
|
|
24
|
+
readonly SUCCESS: "success";
|
|
25
|
+
readonly ERROR: "error";
|
|
26
|
+
readonly UNRECOVERABLE_ERROR: "unrecoverableError";
|
|
27
|
+
};
|
|
28
|
+
export type RequestEvent = EnumOf<typeof RequestEvent>;
|
|
29
|
+
export declare const EventResultType: {
|
|
30
|
+
/** @deprecated use 'RESPOND' */
|
|
31
|
+
readonly Respond: "respond";
|
|
32
|
+
/** @deprecated use 'RETRY' */
|
|
33
|
+
readonly Retry: "retry";
|
|
34
|
+
readonly RESPOND: "respond";
|
|
35
|
+
readonly RETRY: "retry";
|
|
36
|
+
};
|
|
37
|
+
export type EventResultType = EnumOf<typeof EventResultType>;
|
|
38
|
+
export declare const CacheSource: {
|
|
39
|
+
/** @deprecated use 'API' */
|
|
40
|
+
readonly Api: "api";
|
|
41
|
+
/** @deprecated use 'LOCAL' */
|
|
42
|
+
readonly Local: "local";
|
|
43
|
+
readonly API: "api";
|
|
44
|
+
readonly LOCAL: "local";
|
|
45
|
+
};
|
|
46
|
+
export type CacheSource = EnumOf<typeof CacheSource>;
|
|
47
|
+
export declare const ResponseType: {
|
|
48
|
+
/** @deprecated use 'JSON' */
|
|
49
|
+
readonly Json: "json";
|
|
50
|
+
/** @deprecated use 'TEXT' */
|
|
51
|
+
readonly Text: "text";
|
|
52
|
+
/** @deprecated use 'ARRAY_BUFFER' */
|
|
53
|
+
readonly ArrayBuffer: "arraybuffer";
|
|
54
|
+
readonly JSON: "json";
|
|
55
|
+
readonly TEXT: "text";
|
|
56
|
+
readonly ARRAY_BUFFER: "arraybuffer";
|
|
57
|
+
};
|
|
58
|
+
export type ResponseType = EnumOf<typeof ResponseType>;
|
package/cjs/ApiConstants.js
CHANGED
|
@@ -1,55 +1,55 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ResponseType = exports.CacheSource = exports.EventResultType = exports.RequestEvent = exports.RequestMethod = void 0;
|
|
4
|
-
exports.RequestMethod = {
|
|
5
|
-
/** @deprecated use 'POST' */
|
|
6
|
-
Post: "post",
|
|
7
|
-
/** @deprecated use 'GET' */
|
|
8
|
-
Get: "get",
|
|
9
|
-
POST: "post",
|
|
10
|
-
GET: "get",
|
|
11
|
-
PUT: "put",
|
|
12
|
-
DELETE: "delete",
|
|
13
|
-
PATCH: "patch",
|
|
14
|
-
};
|
|
15
|
-
exports.RequestEvent = {
|
|
16
|
-
/** @deprecated use 'BEFORE_SEND' */
|
|
17
|
-
BeforeSend: "beforeSend",
|
|
18
|
-
/** @deprecated use 'SUCCESS' */
|
|
19
|
-
Success: "success",
|
|
20
|
-
/** @deprecated use 'ERROR' */
|
|
21
|
-
Error: "error",
|
|
22
|
-
/** @deprecated use 'UNRECOVERABLE_ERROR' */
|
|
23
|
-
UnrecoverableError: "unrecoverableError",
|
|
24
|
-
BEFORE_SEND: "beforeSend",
|
|
25
|
-
SUCCESS: "success",
|
|
26
|
-
ERROR: "error",
|
|
27
|
-
UNRECOVERABLE_ERROR: "unrecoverableError",
|
|
28
|
-
};
|
|
29
|
-
exports.EventResultType = {
|
|
30
|
-
/** @deprecated use 'RESPOND' */
|
|
31
|
-
Respond: "respond",
|
|
32
|
-
/** @deprecated use 'RETRY' */
|
|
33
|
-
Retry: "retry",
|
|
34
|
-
RESPOND: "respond",
|
|
35
|
-
RETRY: "retry",
|
|
36
|
-
};
|
|
37
|
-
exports.CacheSource = {
|
|
38
|
-
/** @deprecated use 'API' */
|
|
39
|
-
Api: "api",
|
|
40
|
-
/** @deprecated use 'LOCAL' */
|
|
41
|
-
Local: "local",
|
|
42
|
-
API: "api",
|
|
43
|
-
LOCAL: "local",
|
|
44
|
-
};
|
|
45
|
-
exports.ResponseType = {
|
|
46
|
-
/** @deprecated use 'JSON' */
|
|
47
|
-
Json: "json",
|
|
48
|
-
/** @deprecated use 'TEXT' */
|
|
49
|
-
Text: "text",
|
|
50
|
-
/** @deprecated use 'ARRAY_BUFFER' */
|
|
51
|
-
ArrayBuffer: "arraybuffer",
|
|
52
|
-
JSON: "json",
|
|
53
|
-
TEXT: "text",
|
|
54
|
-
ARRAY_BUFFER: "arraybuffer",
|
|
55
|
-
};
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ResponseType = exports.CacheSource = exports.EventResultType = exports.RequestEvent = exports.RequestMethod = void 0;
|
|
4
|
+
exports.RequestMethod = {
|
|
5
|
+
/** @deprecated use 'POST' */
|
|
6
|
+
Post: "post",
|
|
7
|
+
/** @deprecated use 'GET' */
|
|
8
|
+
Get: "get",
|
|
9
|
+
POST: "post",
|
|
10
|
+
GET: "get",
|
|
11
|
+
PUT: "put",
|
|
12
|
+
DELETE: "delete",
|
|
13
|
+
PATCH: "patch",
|
|
14
|
+
};
|
|
15
|
+
exports.RequestEvent = {
|
|
16
|
+
/** @deprecated use 'BEFORE_SEND' */
|
|
17
|
+
BeforeSend: "beforeSend",
|
|
18
|
+
/** @deprecated use 'SUCCESS' */
|
|
19
|
+
Success: "success",
|
|
20
|
+
/** @deprecated use 'ERROR' */
|
|
21
|
+
Error: "error",
|
|
22
|
+
/** @deprecated use 'UNRECOVERABLE_ERROR' */
|
|
23
|
+
UnrecoverableError: "unrecoverableError",
|
|
24
|
+
BEFORE_SEND: "beforeSend",
|
|
25
|
+
SUCCESS: "success",
|
|
26
|
+
ERROR: "error",
|
|
27
|
+
UNRECOVERABLE_ERROR: "unrecoverableError",
|
|
28
|
+
};
|
|
29
|
+
exports.EventResultType = {
|
|
30
|
+
/** @deprecated use 'RESPOND' */
|
|
31
|
+
Respond: "respond",
|
|
32
|
+
/** @deprecated use 'RETRY' */
|
|
33
|
+
Retry: "retry",
|
|
34
|
+
RESPOND: "respond",
|
|
35
|
+
RETRY: "retry",
|
|
36
|
+
};
|
|
37
|
+
exports.CacheSource = {
|
|
38
|
+
/** @deprecated use 'API' */
|
|
39
|
+
Api: "api",
|
|
40
|
+
/** @deprecated use 'LOCAL' */
|
|
41
|
+
Local: "local",
|
|
42
|
+
API: "api",
|
|
43
|
+
LOCAL: "local",
|
|
44
|
+
};
|
|
45
|
+
exports.ResponseType = {
|
|
46
|
+
/** @deprecated use 'JSON' */
|
|
47
|
+
Json: "json",
|
|
48
|
+
/** @deprecated use 'TEXT' */
|
|
49
|
+
Text: "text",
|
|
50
|
+
/** @deprecated use 'ARRAY_BUFFER' */
|
|
51
|
+
ArrayBuffer: "arraybuffer",
|
|
52
|
+
JSON: "json",
|
|
53
|
+
TEXT: "text",
|
|
54
|
+
ARRAY_BUFFER: "arraybuffer",
|
|
55
|
+
};
|