@hyper-fetch/core 5.0.1 → 5.1.0
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/browser/index.cjs.js +16 -4
- package/dist/browser/index.cjs.js.map +2 -2
- package/dist/browser/index.esm.js +16 -4
- package/dist/browser/index.esm.js.map +2 -2
- package/dist/index.cjs.js +16 -4
- package/dist/index.cjs.js.map +2 -2
- package/dist/index.d.ts +2 -0
- package/dist/index.esm.js +16 -4
- package/dist/index.esm.js.map +2 -2
- package/package.json +1 -2
- package/src/adapter/adapter.bindings.ts +1 -1
- package/src/mocker/mocker.ts +7 -2
- package/src/request/request.ts +9 -0
|
@@ -217,6 +217,7 @@ var Request = class {
|
|
|
217
217
|
this.client = client;
|
|
218
218
|
this.requestOptions = requestOptions;
|
|
219
219
|
this.requestJSON = requestJSON;
|
|
220
|
+
this.isMockEnabled = false;
|
|
220
221
|
this.setHeaders = (headers) => {
|
|
221
222
|
return this.clone({ headers });
|
|
222
223
|
};
|
|
@@ -302,11 +303,17 @@ var Request = class {
|
|
|
302
303
|
};
|
|
303
304
|
this.mockData = mockData;
|
|
304
305
|
this.mock = mockGenerator(mockData);
|
|
306
|
+
this.isMockEnabled = true;
|
|
305
307
|
return this;
|
|
306
308
|
};
|
|
307
309
|
this.removeMock = () => {
|
|
308
310
|
this.mockData = null;
|
|
309
311
|
this.mock = null;
|
|
312
|
+
this.isMockEnabled = false;
|
|
313
|
+
return this;
|
|
314
|
+
};
|
|
315
|
+
this.setEnableMocking = (isMockEnabled) => {
|
|
316
|
+
this.isMockEnabled = isMockEnabled;
|
|
310
317
|
return this;
|
|
311
318
|
};
|
|
312
319
|
this.setDataMapper = (dataMapper) => {
|
|
@@ -462,6 +469,7 @@ var Request = class {
|
|
|
462
469
|
cloned.requestMapper = this.requestMapper;
|
|
463
470
|
cloned.mockData = this.mockData;
|
|
464
471
|
cloned.mock = this.mock;
|
|
472
|
+
cloned.isMockEnabled = this.isMockEnabled;
|
|
465
473
|
return cloned;
|
|
466
474
|
}
|
|
467
475
|
};
|
|
@@ -1059,13 +1067,17 @@ var mocker = (_0, _1) => __async(void 0, [_0, _1], function* (request, {
|
|
|
1059
1067
|
onRequestStart,
|
|
1060
1068
|
onSuccess
|
|
1061
1069
|
}) {
|
|
1062
|
-
var _a, _b;
|
|
1063
|
-
const timeout = ((_a = request.requestOptions.options) == null ? void 0 : _a.timeout) || ((_b = request.options) == null ? void 0 : _b.timeout);
|
|
1064
1070
|
const mock = request.mock.next();
|
|
1065
1071
|
const result = mock.value instanceof Function ? yield mock.value(request) : mock.value;
|
|
1066
1072
|
return new Promise((resolve) => {
|
|
1067
1073
|
const { data, status = 200, success = true, extra, config } = result;
|
|
1068
|
-
const {
|
|
1074
|
+
const {
|
|
1075
|
+
requestTime = 20,
|
|
1076
|
+
responseTime = 20,
|
|
1077
|
+
totalUploaded = 1,
|
|
1078
|
+
totalDownloaded = 1,
|
|
1079
|
+
timeout = false
|
|
1080
|
+
} = config || {};
|
|
1069
1081
|
createAbortListener(0, {}, () => {
|
|
1070
1082
|
}, resolve);
|
|
1071
1083
|
onBeforeRequest();
|
|
@@ -1313,7 +1325,7 @@ var getAdapterBindings = (req, requestId, systemErrorStatus, systemErrorExtra) =
|
|
|
1313
1325
|
if (processingError) {
|
|
1314
1326
|
return onError(processingError, systemErrorStatus, systemErrorExtra, () => null);
|
|
1315
1327
|
}
|
|
1316
|
-
if (req.mock) {
|
|
1328
|
+
if (req.mock && req.isMockEnabled) {
|
|
1317
1329
|
return mocker(request, {
|
|
1318
1330
|
onError,
|
|
1319
1331
|
onResponseEnd,
|