api-def 0.9.1 → 0.9.3
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/README.md +1 -1
- 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 +203 -202
- 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 -136
- 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 +19 -34
package/cjs/Endpoint.js
CHANGED
|
@@ -1,108 +1,104 @@
|
|
|
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
|
-
var Requester = require("./Requester");
|
|
40
|
-
var RequestConfig_1 = require("./RequestConfig");
|
|
41
|
-
var Endpoint = /** @class */ (function () {
|
|
42
|
-
function Endpoint(api, info) {
|
|
43
|
-
this.api = api;
|
|
44
|
-
this.id = info.id;
|
|
45
|
-
this.method = info.method;
|
|
46
|
-
this.name = info.name || info.id;
|
|
47
|
-
this.description = info.description;
|
|
48
|
-
this.path = info.path;
|
|
49
|
-
this.config = info.config;
|
|
50
|
-
this.responseType = info.responseType;
|
|
51
|
-
this.mocking = info.mocking;
|
|
52
|
-
this.validation = info.validation || {};
|
|
53
|
-
}
|
|
54
|
-
Endpoint.prototype.submit = function (config) {
|
|
55
|
-
var _a, _b;
|
|
56
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
57
|
-
var mock, apiMocking, mockingEnabled;
|
|
58
|
-
return __generator(this, function (_c) {
|
|
59
|
-
mock = false;
|
|
60
|
-
apiMocking = this.api.mocking;
|
|
61
|
-
if (apiMocking) {
|
|
62
|
-
mockingEnabled = (_a = (typeof apiMocking.enabled === "function" ? apiMocking.enabled() : apiMocking.enabled)) !== null && _a !== void 0 ? _a : false;
|
|
63
|
-
if (mockingEnabled) {
|
|
64
|
-
if (!((_b = this.mocking) === null || _b === void 0 ? void 0 : _b.handler)) {
|
|
65
|
-
throw new Error("[api-def] Endpoint for '".concat(this.path, "' has no mocking"));
|
|
66
|
-
}
|
|
67
|
-
mock = true;
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
return [2 /*return*/, Requester.submit(this, config, mock ? this.mocking : null)];
|
|
71
|
-
});
|
|
72
|
-
});
|
|
73
|
-
};
|
|
74
|
-
Endpoint.prototype.computePath = function (path, request) {
|
|
75
|
-
var computedPath = path.startsWith("/") ? path : "/".concat(path);
|
|
76
|
-
if (request.params) {
|
|
77
|
-
var keys = Object.keys(request.params);
|
|
78
|
-
for (var i = 0; i < keys.length; i++) {
|
|
79
|
-
var argName = keys[i];
|
|
80
|
-
computedPath = computedPath.replace(":".concat(argName), request.params[argName]);
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
if (computedPath.includes(":")) {
|
|
84
|
-
throw new Error("[api-def] Not all path params have been resolved: '".concat(computedPath, "'"));
|
|
85
|
-
}
|
|
86
|
-
return computedPath;
|
|
87
|
-
};
|
|
88
|
-
Object.defineProperty(Endpoint.prototype, "baseUrl", {
|
|
89
|
-
get: function () {
|
|
90
|
-
return this.api.baseUrl;
|
|
91
|
-
},
|
|
92
|
-
enumerable: false,
|
|
93
|
-
configurable: true
|
|
94
|
-
});
|
|
95
|
-
Endpoint.prototype.computeConfig = function (config) {
|
|
96
|
-
var apiDefaults = this.api.getConfig();
|
|
97
|
-
return (0, RequestConfig_1.computeRequestConfig)([
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
};
|
|
106
|
-
return Endpoint;
|
|
107
|
-
}());
|
|
108
|
-
exports.default = Endpoint;
|
|
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
|
+
var Requester = require("./Requester");
|
|
40
|
+
var RequestConfig_1 = require("./RequestConfig");
|
|
41
|
+
var Endpoint = /** @class */ (function () {
|
|
42
|
+
function Endpoint(api, info) {
|
|
43
|
+
this.api = api;
|
|
44
|
+
this.id = info.id;
|
|
45
|
+
this.method = info.method;
|
|
46
|
+
this.name = info.name || info.id;
|
|
47
|
+
this.description = info.description;
|
|
48
|
+
this.path = info.path;
|
|
49
|
+
this.config = info.config;
|
|
50
|
+
this.responseType = info.responseType;
|
|
51
|
+
this.mocking = info.mocking;
|
|
52
|
+
this.validation = info.validation || {};
|
|
53
|
+
}
|
|
54
|
+
Endpoint.prototype.submit = function (config) {
|
|
55
|
+
var _a, _b;
|
|
56
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
57
|
+
var mock, apiMocking, mockingEnabled;
|
|
58
|
+
return __generator(this, function (_c) {
|
|
59
|
+
mock = false;
|
|
60
|
+
apiMocking = this.api.mocking;
|
|
61
|
+
if (apiMocking) {
|
|
62
|
+
mockingEnabled = (_a = (typeof apiMocking.enabled === "function" ? apiMocking.enabled() : apiMocking.enabled)) !== null && _a !== void 0 ? _a : false;
|
|
63
|
+
if (mockingEnabled) {
|
|
64
|
+
if (!((_b = this.mocking) === null || _b === void 0 ? void 0 : _b.handler)) {
|
|
65
|
+
throw new Error("[api-def] Endpoint for '".concat(this.path, "' has no mocking"));
|
|
66
|
+
}
|
|
67
|
+
mock = true;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return [2 /*return*/, Requester.submit(this, config, mock ? this.mocking : null)];
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
};
|
|
74
|
+
Endpoint.prototype.computePath = function (path, request) {
|
|
75
|
+
var computedPath = path.startsWith("/") ? path : "/".concat(path);
|
|
76
|
+
if (request.params) {
|
|
77
|
+
var keys = Object.keys(request.params);
|
|
78
|
+
for (var i = 0; i < keys.length; i++) {
|
|
79
|
+
var argName = keys[i];
|
|
80
|
+
computedPath = computedPath.replace(":".concat(argName), request.params[argName]);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
if (computedPath.includes(":")) {
|
|
84
|
+
throw new Error("[api-def] Not all path params have been resolved: '".concat(computedPath, "'"));
|
|
85
|
+
}
|
|
86
|
+
return computedPath;
|
|
87
|
+
};
|
|
88
|
+
Object.defineProperty(Endpoint.prototype, "baseUrl", {
|
|
89
|
+
get: function () {
|
|
90
|
+
return this.api.baseUrl;
|
|
91
|
+
},
|
|
92
|
+
enumerable: false,
|
|
93
|
+
configurable: true
|
|
94
|
+
});
|
|
95
|
+
Endpoint.prototype.computeConfig = function (config) {
|
|
96
|
+
var apiDefaults = this.api.getConfig();
|
|
97
|
+
return (0, RequestConfig_1.computeRequestConfig)([apiDefaults, this.config, config]);
|
|
98
|
+
};
|
|
99
|
+
Endpoint.prototype.getRequestBackend = function () {
|
|
100
|
+
return this.api.getRequestBackend();
|
|
101
|
+
};
|
|
102
|
+
return Endpoint;
|
|
103
|
+
}());
|
|
104
|
+
exports.default = Endpoint;
|
package/cjs/EndpointBuilder.d.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
5
|
-
export default class EndpointBuilder<R = any, P extends Params | undefined = undefined, Q extends Query | undefined = undefined, B extends Body | undefined = undefined> {
|
|
6
|
-
private api;
|
|
7
|
-
private readonly validation;
|
|
8
|
-
constructor(api: Api);
|
|
9
|
-
queryOf<Q extends Query>(schema?: zod.Schema<Q>): EndpointBuilder<R, P, Q, B>;
|
|
10
|
-
paramsOf<P extends Params>(): EndpointBuilder<R, P, Q, B>;
|
|
11
|
-
bodyOf<B extends Body>(schema?: zod.Schema<B>): EndpointBuilder<R, P, Q, B>;
|
|
12
|
-
responseOf<R>(schema?: zod.Schema<R>): EndpointBuilder<R, P, Q, B>;
|
|
13
|
-
build<Path extends string>(config: Omit<EndpointConfig<R, P, Q, B, Path>, "validation">): Endpoint<R, P, Q, B>;
|
|
14
|
-
}
|
|
1
|
+
import * as zod from "zod";
|
|
2
|
+
import { Api } from "./Api";
|
|
3
|
+
import { Body, Params, Query } from "./ApiTypes";
|
|
4
|
+
import Endpoint, { EndpointConfig } from "./Endpoint";
|
|
5
|
+
export default class EndpointBuilder<R = any, P extends Params | undefined = undefined, Q extends Query | undefined = undefined, B extends Body | undefined = undefined> {
|
|
6
|
+
private api;
|
|
7
|
+
private readonly validation;
|
|
8
|
+
constructor(api: Api);
|
|
9
|
+
queryOf<Q extends Query>(schema?: zod.Schema<Q>): EndpointBuilder<R, P, Q, B>;
|
|
10
|
+
paramsOf<P extends Params>(): EndpointBuilder<R, P, Q, B>;
|
|
11
|
+
bodyOf<B extends Body>(schema?: zod.Schema<B>): EndpointBuilder<R, P, Q, B>;
|
|
12
|
+
responseOf<R>(schema?: zod.Schema<R>): EndpointBuilder<R, P, Q, B>;
|
|
13
|
+
build<Path extends string>(config: Omit<EndpointConfig<R, P, Q, B, Path>, "validation">): Endpoint<R, P, Q, B>;
|
|
14
|
+
}
|
package/cjs/EndpointBuilder.js
CHANGED
|
@@ -1,46 +1,46 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __assign = (this && this.__assign) || function () {
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
-
var Endpoint_1 = require("./Endpoint");
|
|
15
|
-
/*type ExtractParams<Path> = Path extends `${infer Segment}/${infer Rest}`
|
|
16
|
-
? Segment extends `:${infer Param}` ? Param | ExtractParams<Rest> : ExtractParams<Rest>
|
|
17
|
-
: Path extends `:${infer Param}` ? Param : undefined;
|
|
18
|
-
*/
|
|
19
|
-
var EndpointBuilder = /** @class */ (function () {
|
|
20
|
-
function EndpointBuilder(api) {
|
|
21
|
-
this.validation = {};
|
|
22
|
-
this.api = api;
|
|
23
|
-
}
|
|
24
|
-
EndpointBuilder.prototype.queryOf = function (schema) {
|
|
25
|
-
this.validation.query = schema;
|
|
26
|
-
return this;
|
|
27
|
-
};
|
|
28
|
-
EndpointBuilder.prototype.paramsOf = function () {
|
|
29
|
-
return this;
|
|
30
|
-
};
|
|
31
|
-
EndpointBuilder.prototype.bodyOf = function (schema) {
|
|
32
|
-
this.validation.body = schema;
|
|
33
|
-
return this;
|
|
34
|
-
};
|
|
35
|
-
EndpointBuilder.prototype.responseOf = function (schema) {
|
|
36
|
-
this.validation.response = schema;
|
|
37
|
-
return this;
|
|
38
|
-
};
|
|
39
|
-
EndpointBuilder.prototype.build = function (config) {
|
|
40
|
-
var endpoint = new Endpoint_1.default(this.api, __assign(__assign({}, config), { validation: this.validation }));
|
|
41
|
-
this.api.endpoints[endpoint.id] = endpoint;
|
|
42
|
-
return endpoint;
|
|
43
|
-
};
|
|
44
|
-
return EndpointBuilder;
|
|
45
|
-
}());
|
|
46
|
-
exports.default = EndpointBuilder;
|
|
1
|
+
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
var Endpoint_1 = require("./Endpoint");
|
|
15
|
+
/*type ExtractParams<Path> = Path extends `${infer Segment}/${infer Rest}`
|
|
16
|
+
? Segment extends `:${infer Param}` ? Param | ExtractParams<Rest> : ExtractParams<Rest>
|
|
17
|
+
: Path extends `:${infer Param}` ? Param : undefined;
|
|
18
|
+
*/
|
|
19
|
+
var EndpointBuilder = /** @class */ (function () {
|
|
20
|
+
function EndpointBuilder(api) {
|
|
21
|
+
this.validation = {};
|
|
22
|
+
this.api = api;
|
|
23
|
+
}
|
|
24
|
+
EndpointBuilder.prototype.queryOf = function (schema) {
|
|
25
|
+
this.validation.query = schema;
|
|
26
|
+
return this;
|
|
27
|
+
};
|
|
28
|
+
EndpointBuilder.prototype.paramsOf = function () {
|
|
29
|
+
return this;
|
|
30
|
+
};
|
|
31
|
+
EndpointBuilder.prototype.bodyOf = function (schema) {
|
|
32
|
+
this.validation.body = schema;
|
|
33
|
+
return this;
|
|
34
|
+
};
|
|
35
|
+
EndpointBuilder.prototype.responseOf = function (schema) {
|
|
36
|
+
this.validation.response = schema;
|
|
37
|
+
return this;
|
|
38
|
+
};
|
|
39
|
+
EndpointBuilder.prototype.build = function (config) {
|
|
40
|
+
var endpoint = new Endpoint_1.default(this.api, __assign(__assign({}, config), { validation: this.validation }));
|
|
41
|
+
this.api.endpoints[endpoint.id] = endpoint;
|
|
42
|
+
return endpoint;
|
|
43
|
+
};
|
|
44
|
+
return EndpointBuilder;
|
|
45
|
+
}());
|
|
46
|
+
exports.default = EndpointBuilder;
|
package/cjs/MockingTypes.d.ts
CHANGED
|
@@ -1,30 +1,30 @@
|
|
|
1
|
-
import { ApiResponse, Body, Headers, Params, Query } from "./ApiTypes";
|
|
2
|
-
export interface ApiMockingConfig {
|
|
3
|
-
enabled: boolean | (() => boolean);
|
|
4
|
-
}
|
|
5
|
-
export interface MockRequest<R = any, P extends Params | undefined = Params | undefined, Q extends Query | undefined = Query | undefined, B extends Body | undefined = Body | undefined> {
|
|
6
|
-
params: P extends Params ? Record<P, string> : {};
|
|
7
|
-
body: B;
|
|
8
|
-
query: Q;
|
|
9
|
-
headers: Readonly<Headers>;
|
|
10
|
-
url: string;
|
|
11
|
-
}
|
|
12
|
-
export interface MockResponse<R = any, P extends Params | undefined = Params | undefined, Q extends Query | undefined = Query | undefined, B extends Body | undefined = Body | undefined> {
|
|
13
|
-
statusCode: number;
|
|
14
|
-
response: R | undefined;
|
|
15
|
-
headers: Headers;
|
|
16
|
-
status(statusCode: number): this;
|
|
17
|
-
send(response: R): this;
|
|
18
|
-
}
|
|
19
|
-
export
|
|
20
|
-
response?: ApiResponse;
|
|
21
|
-
};
|
|
22
|
-
export
|
|
23
|
-
export interface EndpointMockingConfig<R = any, P extends Params | undefined = Params | undefined, Q extends Query | undefined = Query | undefined, B extends Body | undefined = Body | undefined> {
|
|
24
|
-
/**-
|
|
25
|
-
* The range supplied will be used to simulate the lag in obtaining a response
|
|
26
|
-
* your endpoint. If no values are supplied, a response will be returned immediately
|
|
27
|
-
*/
|
|
28
|
-
delay?: number | [minMs: number, maxMs: number];
|
|
29
|
-
handler: EndpointMockingFunction<R, P, Q, B>;
|
|
30
|
-
}
|
|
1
|
+
import { ApiResponse, Body, Headers, Params, Query } from "./ApiTypes";
|
|
2
|
+
export interface ApiMockingConfig {
|
|
3
|
+
enabled: boolean | (() => boolean);
|
|
4
|
+
}
|
|
5
|
+
export interface MockRequest<R = any, P extends Params | undefined = Params | undefined, Q extends Query | undefined = Query | undefined, B extends Body | undefined = Body | undefined> {
|
|
6
|
+
params: P extends Params ? Record<P, string> : {};
|
|
7
|
+
body: B;
|
|
8
|
+
query: Q;
|
|
9
|
+
headers: Readonly<Headers>;
|
|
10
|
+
url: string;
|
|
11
|
+
}
|
|
12
|
+
export interface MockResponse<R = any, P extends Params | undefined = Params | undefined, Q extends Query | undefined = Query | undefined, B extends Body | undefined = Body | undefined> {
|
|
13
|
+
statusCode: number;
|
|
14
|
+
response: R | undefined;
|
|
15
|
+
headers: Headers;
|
|
16
|
+
status(statusCode: number): this;
|
|
17
|
+
send(response: R): this;
|
|
18
|
+
}
|
|
19
|
+
export type MockRequestError = Error & {
|
|
20
|
+
response?: ApiResponse;
|
|
21
|
+
};
|
|
22
|
+
export type EndpointMockingFunction<R = any, P extends Params | undefined = Params | undefined, Q extends Query | undefined = Query | undefined, B extends Body | undefined = Body | undefined> = (req: MockRequest<R, P, Q, B>, res: MockResponse<R, P, Q, B>) => Promise<MockResponse<R, P, Q, B>> | MockResponse<R, P, Q, B>;
|
|
23
|
+
export interface EndpointMockingConfig<R = any, P extends Params | undefined = Params | undefined, Q extends Query | undefined = Query | undefined, B extends Body | undefined = Body | undefined> {
|
|
24
|
+
/**-
|
|
25
|
+
* The range supplied will be used to simulate the lag in obtaining a response
|
|
26
|
+
* your endpoint. If no values are supplied, a response will be returned immediately
|
|
27
|
+
*/
|
|
28
|
+
delay?: number | [minMs: number, maxMs: number];
|
|
29
|
+
handler: EndpointMockingFunction<R, P, Q, B>;
|
|
30
|
+
}
|
package/cjs/MockingTypes.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
package/cjs/QueryHandling.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { QueryStringify } from "./ApiTypes";
|
|
2
|
-
export declare const DEFAULT_QUERY_STRINGIFY: QueryStringify;
|
|
3
|
-
export declare const DEFAULT_QUERY_PARSE: (queryString: string) => Record<string, any>;
|
|
1
|
+
import { QueryStringify } from "./ApiTypes";
|
|
2
|
+
export declare const DEFAULT_QUERY_STRINGIFY: QueryStringify;
|
|
3
|
+
export declare const DEFAULT_QUERY_PARSE: (queryString: string) => Record<string, any>;
|
package/cjs/QueryHandling.js
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DEFAULT_QUERY_PARSE = exports.DEFAULT_QUERY_STRINGIFY = void 0;
|
|
4
|
-
var DEFAULT_QUERY_STRINGIFY = function (query) {
|
|
5
|
-
var _a, _b;
|
|
6
|
-
var queryStrings = [];
|
|
7
|
-
var queryKeys = Object.keys(query);
|
|
8
|
-
for (var i = 0; i < queryKeys.length; i++) {
|
|
9
|
-
var key = queryKeys[i];
|
|
10
|
-
queryStrings.push("".concat(key, "=").concat((_b = (_a = query[key]) === null || _a === void 0 ? void 0 : _a.toString()) !== null && _b !== void 0 ? _b : ""));
|
|
11
|
-
}
|
|
12
|
-
return queryStrings.join("&");
|
|
13
|
-
};
|
|
14
|
-
exports.DEFAULT_QUERY_STRINGIFY = DEFAULT_QUERY_STRINGIFY;
|
|
15
|
-
var DEFAULT_QUERY_PARSE = function (queryString) {
|
|
16
|
-
var query = {};
|
|
17
|
-
var queryStrings = queryString.split("&");
|
|
18
|
-
for (var i = 0; i < queryStrings.length; i++) {
|
|
19
|
-
var _a = queryStrings[i].split("="), key = _a[0], value = _a[1];
|
|
20
|
-
query[key] = !(value === null || value === void 0 ? void 0 : value.length) ? true : value;
|
|
21
|
-
}
|
|
22
|
-
return query;
|
|
23
|
-
};
|
|
24
|
-
exports.DEFAULT_QUERY_PARSE = DEFAULT_QUERY_PARSE;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DEFAULT_QUERY_PARSE = exports.DEFAULT_QUERY_STRINGIFY = void 0;
|
|
4
|
+
var DEFAULT_QUERY_STRINGIFY = function (query) {
|
|
5
|
+
var _a, _b;
|
|
6
|
+
var queryStrings = [];
|
|
7
|
+
var queryKeys = Object.keys(query);
|
|
8
|
+
for (var i = 0; i < queryKeys.length; i++) {
|
|
9
|
+
var key = queryKeys[i];
|
|
10
|
+
queryStrings.push("".concat(key, "=").concat((_b = (_a = query[key]) === null || _a === void 0 ? void 0 : _a.toString()) !== null && _b !== void 0 ? _b : ""));
|
|
11
|
+
}
|
|
12
|
+
return queryStrings.join("&");
|
|
13
|
+
};
|
|
14
|
+
exports.DEFAULT_QUERY_STRINGIFY = DEFAULT_QUERY_STRINGIFY;
|
|
15
|
+
var DEFAULT_QUERY_PARSE = function (queryString) {
|
|
16
|
+
var query = {};
|
|
17
|
+
var queryStrings = queryString.split("&");
|
|
18
|
+
for (var i = 0; i < queryStrings.length; i++) {
|
|
19
|
+
var _a = queryStrings[i].split("="), key = _a[0], value = _a[1];
|
|
20
|
+
query[key] = !(value === null || value === void 0 ? void 0 : value.length) ? true : value;
|
|
21
|
+
}
|
|
22
|
+
return query;
|
|
23
|
+
};
|
|
24
|
+
exports.DEFAULT_QUERY_PARSE = DEFAULT_QUERY_PARSE;
|
package/cjs/RequestConfig.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { BaseRequestConfig, Body, ComputedRequestConfig, Query, RequestConfig } from "./ApiTypes";
|
|
2
|
-
export declare const computeRequestConfig: <P extends string | undefined, Q extends Query, B extends Body | undefined>(configs: (BaseRequestConfig | RequestConfig<P, Q, B> | undefined)[]) => ComputedRequestConfig<P, Q, B>;
|
|
1
|
+
import { BaseRequestConfig, Body, ComputedRequestConfig, Query, RequestConfig } from "./ApiTypes";
|
|
2
|
+
export declare const computeRequestConfig: <P extends string | undefined, Q extends Query, B extends Body | undefined>(configs: (BaseRequestConfig | RequestConfig<P, Q, B> | undefined)[]) => ComputedRequestConfig<P, Q, B>;
|
package/cjs/RequestConfig.js
CHANGED
|
@@ -1,74 +1,74 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
3
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
4
|
-
if (ar || !(i in from)) {
|
|
5
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
6
|
-
ar[i] = from[i];
|
|
7
|
-
}
|
|
8
|
-
}
|
|
9
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.computeRequestConfig = void 0;
|
|
13
|
-
var ApiTypes_1 = require("./ApiTypes");
|
|
14
|
-
var
|
|
15
|
-
var
|
|
16
|
-
var MERGED_CONFIG_KEYS = ["headers"];
|
|
17
|
-
var computeRequestConfig = function (configs) {
|
|
18
|
-
var _a;
|
|
19
|
-
var _b, _c;
|
|
20
|
-
var computedConfig = Utils.assign.apply(Utils, __spreadArray([(_a = {},
|
|
21
|
-
_a[ApiTypes_1.COMPUTED_CONFIG_SYMBOL] = true,
|
|
22
|
-
_a)], configs, false));
|
|
23
|
-
var _loop_1 = function (key) {
|
|
24
|
-
computedConfig[key] = Utils.assign.apply(Utils, __spreadArray([{}], configs.reduce(function (acc, config) {
|
|
25
|
-
if (config === null || config === void 0 ? void 0 : config[key]) {
|
|
26
|
-
acc.push(config[key]);
|
|
27
|
-
}
|
|
28
|
-
return acc;
|
|
29
|
-
}, []), false));
|
|
30
|
-
};
|
|
31
|
-
// merge other values
|
|
32
|
-
for (var _i = 0, MERGED_CONFIG_KEYS_1 = MERGED_CONFIG_KEYS; _i < MERGED_CONFIG_KEYS_1.length; _i++) {
|
|
33
|
-
var key = MERGED_CONFIG_KEYS_1[_i];
|
|
34
|
-
_loop_1(key);
|
|
35
|
-
}
|
|
36
|
-
computedConfig.queryHandling = {
|
|
37
|
-
parse: ((_b = computedConfig.queryHandling) === null || _b === void 0 ? void 0 : _b.parse) || QueryHandling_1.DEFAULT_QUERY_PARSE,
|
|
38
|
-
stringify: ((_c = computedConfig.queryHandling) === null || _c === void 0 ? void 0 : _c.stringify) || computedConfig.queryParser || QueryHandling_1.DEFAULT_QUERY_STRINGIFY,
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
var query = computedConfig.query;
|
|
42
|
-
var queryString;
|
|
43
|
-
var queryObject;
|
|
44
|
-
if (query) {
|
|
45
|
-
Object.defineProperty(computedConfig, "queryString", {
|
|
46
|
-
get: function () {
|
|
47
|
-
if (queryString) {
|
|
48
|
-
return queryString;
|
|
49
|
-
}
|
|
50
|
-
if (typeof query === "string") {
|
|
51
|
-
return queryString = query;
|
|
52
|
-
}
|
|
53
|
-
return queryString = computedConfig.queryHandling.stringify(query);
|
|
54
|
-
},
|
|
55
|
-
});
|
|
56
|
-
Object.defineProperty(computedConfig, "queryObject", {
|
|
57
|
-
get: function () {
|
|
58
|
-
if (queryObject) {
|
|
59
|
-
return queryObject;
|
|
60
|
-
}
|
|
61
|
-
if (typeof query === "string") {
|
|
62
|
-
return queryObject = computedConfig.queryHandling.parse(query);
|
|
63
|
-
}
|
|
64
|
-
return queryObject = query;
|
|
65
|
-
},
|
|
66
|
-
set: function (value) {
|
|
67
|
-
queryObject = value;
|
|
68
|
-
queryString = computedConfig.queryHandling.stringify(value);
|
|
69
|
-
},
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
return computedConfig;
|
|
73
|
-
};
|
|
74
|
-
exports.computeRequestConfig = computeRequestConfig;
|
|
1
|
+
"use strict";
|
|
2
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
3
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
4
|
+
if (ar || !(i in from)) {
|
|
5
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
6
|
+
ar[i] = from[i];
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.computeRequestConfig = void 0;
|
|
13
|
+
var ApiTypes_1 = require("./ApiTypes");
|
|
14
|
+
var QueryHandling_1 = require("./QueryHandling");
|
|
15
|
+
var Utils = require("./Utils");
|
|
16
|
+
var MERGED_CONFIG_KEYS = ["headers"];
|
|
17
|
+
var computeRequestConfig = function (configs) {
|
|
18
|
+
var _a;
|
|
19
|
+
var _b, _c;
|
|
20
|
+
var computedConfig = Utils.assign.apply(Utils, __spreadArray([(_a = {},
|
|
21
|
+
_a[ApiTypes_1.COMPUTED_CONFIG_SYMBOL] = true,
|
|
22
|
+
_a)], configs, false));
|
|
23
|
+
var _loop_1 = function (key) {
|
|
24
|
+
computedConfig[key] = Utils.assign.apply(Utils, __spreadArray([{}], configs.reduce(function (acc, config) {
|
|
25
|
+
if (config === null || config === void 0 ? void 0 : config[key]) {
|
|
26
|
+
acc.push(config[key]);
|
|
27
|
+
}
|
|
28
|
+
return acc;
|
|
29
|
+
}, []), false));
|
|
30
|
+
};
|
|
31
|
+
// merge other values
|
|
32
|
+
for (var _i = 0, MERGED_CONFIG_KEYS_1 = MERGED_CONFIG_KEYS; _i < MERGED_CONFIG_KEYS_1.length; _i++) {
|
|
33
|
+
var key = MERGED_CONFIG_KEYS_1[_i];
|
|
34
|
+
_loop_1(key);
|
|
35
|
+
}
|
|
36
|
+
computedConfig.queryHandling = {
|
|
37
|
+
parse: ((_b = computedConfig.queryHandling) === null || _b === void 0 ? void 0 : _b.parse) || QueryHandling_1.DEFAULT_QUERY_PARSE,
|
|
38
|
+
stringify: ((_c = computedConfig.queryHandling) === null || _c === void 0 ? void 0 : _c.stringify) || computedConfig.queryParser || QueryHandling_1.DEFAULT_QUERY_STRINGIFY,
|
|
39
|
+
};
|
|
40
|
+
computedConfig.queryParser = undefined;
|
|
41
|
+
var query = computedConfig.query;
|
|
42
|
+
var queryString;
|
|
43
|
+
var queryObject;
|
|
44
|
+
if (query) {
|
|
45
|
+
Object.defineProperty(computedConfig, "queryString", {
|
|
46
|
+
get: function () {
|
|
47
|
+
if (queryString) {
|
|
48
|
+
return queryString;
|
|
49
|
+
}
|
|
50
|
+
if (typeof query === "string") {
|
|
51
|
+
return (queryString = query);
|
|
52
|
+
}
|
|
53
|
+
return (queryString = computedConfig.queryHandling.stringify(query));
|
|
54
|
+
},
|
|
55
|
+
});
|
|
56
|
+
Object.defineProperty(computedConfig, "queryObject", {
|
|
57
|
+
get: function () {
|
|
58
|
+
if (queryObject) {
|
|
59
|
+
return queryObject;
|
|
60
|
+
}
|
|
61
|
+
if (typeof query === "string") {
|
|
62
|
+
return (queryObject = computedConfig.queryHandling.parse(query));
|
|
63
|
+
}
|
|
64
|
+
return (queryObject = query);
|
|
65
|
+
},
|
|
66
|
+
set: function (value) {
|
|
67
|
+
queryObject = value;
|
|
68
|
+
queryString = computedConfig.queryHandling.stringify(value);
|
|
69
|
+
},
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
return computedConfig;
|
|
73
|
+
};
|
|
74
|
+
exports.computeRequestConfig = computeRequestConfig;
|