@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
|
@@ -321,6 +321,7 @@ var Request = class {
|
|
|
321
321
|
this.client = client;
|
|
322
322
|
this.requestOptions = requestOptions;
|
|
323
323
|
this.requestJSON = requestJSON;
|
|
324
|
+
this.isMockEnabled = false;
|
|
324
325
|
this.setHeaders = (headers) => {
|
|
325
326
|
return this.clone({ headers });
|
|
326
327
|
};
|
|
@@ -406,11 +407,17 @@ var Request = class {
|
|
|
406
407
|
};
|
|
407
408
|
this.mockData = mockData;
|
|
408
409
|
this.mock = mockGenerator(mockData);
|
|
410
|
+
this.isMockEnabled = true;
|
|
409
411
|
return this;
|
|
410
412
|
};
|
|
411
413
|
this.removeMock = () => {
|
|
412
414
|
this.mockData = null;
|
|
413
415
|
this.mock = null;
|
|
416
|
+
this.isMockEnabled = false;
|
|
417
|
+
return this;
|
|
418
|
+
};
|
|
419
|
+
this.setEnableMocking = (isMockEnabled) => {
|
|
420
|
+
this.isMockEnabled = isMockEnabled;
|
|
414
421
|
return this;
|
|
415
422
|
};
|
|
416
423
|
this.setDataMapper = (dataMapper) => {
|
|
@@ -566,6 +573,7 @@ var Request = class {
|
|
|
566
573
|
cloned.requestMapper = this.requestMapper;
|
|
567
574
|
cloned.mockData = this.mockData;
|
|
568
575
|
cloned.mock = this.mock;
|
|
576
|
+
cloned.isMockEnabled = this.isMockEnabled;
|
|
569
577
|
return cloned;
|
|
570
578
|
}
|
|
571
579
|
};
|
|
@@ -1163,13 +1171,17 @@ var mocker = (_0, _1) => __async(void 0, [_0, _1], function* (request, {
|
|
|
1163
1171
|
onRequestStart,
|
|
1164
1172
|
onSuccess
|
|
1165
1173
|
}) {
|
|
1166
|
-
var _a, _b;
|
|
1167
|
-
const timeout = ((_a = request.requestOptions.options) == null ? void 0 : _a.timeout) || ((_b = request.options) == null ? void 0 : _b.timeout);
|
|
1168
1174
|
const mock = request.mock.next();
|
|
1169
1175
|
const result = mock.value instanceof Function ? yield mock.value(request) : mock.value;
|
|
1170
1176
|
return new Promise((resolve) => {
|
|
1171
1177
|
const { data, status = 200, success = true, extra, config } = result;
|
|
1172
|
-
const {
|
|
1178
|
+
const {
|
|
1179
|
+
requestTime = 20,
|
|
1180
|
+
responseTime = 20,
|
|
1181
|
+
totalUploaded = 1,
|
|
1182
|
+
totalDownloaded = 1,
|
|
1183
|
+
timeout = false
|
|
1184
|
+
} = config || {};
|
|
1173
1185
|
createAbortListener(0, {}, () => {
|
|
1174
1186
|
}, resolve);
|
|
1175
1187
|
onBeforeRequest();
|
|
@@ -1417,7 +1429,7 @@ var getAdapterBindings = (req, requestId, systemErrorStatus, systemErrorExtra) =
|
|
|
1417
1429
|
if (processingError) {
|
|
1418
1430
|
return onError(processingError, systemErrorStatus, systemErrorExtra, () => null);
|
|
1419
1431
|
}
|
|
1420
|
-
if (req.mock) {
|
|
1432
|
+
if (req.mock && req.isMockEnabled) {
|
|
1421
1433
|
return mocker(request, {
|
|
1422
1434
|
onError,
|
|
1423
1435
|
onResponseEnd,
|