@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/index.d.ts CHANGED
@@ -914,6 +914,7 @@ Endpoint extends string, Adapter extends AdapterInstance = AdapterType, HasData
914
914
  dataMapper?: PayloadMapperType<Payload>;
915
915
  mock?: Generator<GeneratorReturnMockTypes<Response, this>, GeneratorReturnMockTypes<Response, this>, GeneratorReturnMockTypes<Response, this>>;
916
916
  mockData?: RequestDataMockTypes<Response, this>;
917
+ isMockEnabled: boolean;
917
918
  requestMapper?: RequestMapper<this, any>;
918
919
  responseMapper?: ResponseMapper<this, any, any>;
919
920
  private updatedAbortKey;
@@ -944,6 +945,7 @@ Endpoint extends string, Adapter extends AdapterInstance = AdapterType, HasData
944
945
  setOffline: (offline: boolean) => Request<Response, Payload, QueryParams, GlobalError, LocalError, Endpoint, Adapter, HasData, HasParams, HasQuery>;
945
946
  setMock: (mockData: RequestDataMockTypes<Response, this>) => this;
946
947
  removeMock: () => this;
948
+ setEnableMocking: (isMockEnabled: boolean) => this;
947
949
  /**
948
950
  * Mappers
949
951
  */
package/dist/index.esm.js CHANGED
@@ -306,6 +306,7 @@ var Request = class {
306
306
  this.client = client;
307
307
  this.requestOptions = requestOptions;
308
308
  this.requestJSON = requestJSON;
309
+ this.isMockEnabled = false;
309
310
  this.setHeaders = (headers) => {
310
311
  return this.clone({ headers });
311
312
  };
@@ -391,11 +392,17 @@ var Request = class {
391
392
  };
392
393
  this.mockData = mockData;
393
394
  this.mock = mockGenerator(mockData);
395
+ this.isMockEnabled = true;
394
396
  return this;
395
397
  };
396
398
  this.removeMock = () => {
397
399
  this.mockData = null;
398
400
  this.mock = null;
401
+ this.isMockEnabled = false;
402
+ return this;
403
+ };
404
+ this.setEnableMocking = (isMockEnabled) => {
405
+ this.isMockEnabled = isMockEnabled;
399
406
  return this;
400
407
  };
401
408
  this.setDataMapper = (dataMapper) => {
@@ -551,6 +558,7 @@ var Request = class {
551
558
  cloned.requestMapper = this.requestMapper;
552
559
  cloned.mockData = this.mockData;
553
560
  cloned.mock = this.mock;
561
+ cloned.isMockEnabled = this.isMockEnabled;
554
562
  return cloned;
555
563
  }
556
564
  };
@@ -1138,13 +1146,17 @@ var mocker = (_0, _1) => __async(void 0, [_0, _1], function* (request, {
1138
1146
  onRequestStart,
1139
1147
  onSuccess
1140
1148
  }) {
1141
- var _a, _b;
1142
- const timeout = ((_a = request.requestOptions.options) == null ? void 0 : _a.timeout) || ((_b = request.options) == null ? void 0 : _b.timeout);
1143
1149
  const mock = request.mock.next();
1144
1150
  const result = mock.value instanceof Function ? yield mock.value(request) : mock.value;
1145
1151
  return new Promise((resolve) => {
1146
1152
  const { data, status = 200, success = true, extra, config } = result;
1147
- const { requestTime = 20, responseTime = 20, totalUploaded = 1, totalDownloaded = 1 } = config || {};
1153
+ const {
1154
+ requestTime = 20,
1155
+ responseTime = 20,
1156
+ totalUploaded = 1,
1157
+ totalDownloaded = 1,
1158
+ timeout = false
1159
+ } = config || {};
1148
1160
  createAbortListener(0, {}, () => {
1149
1161
  }, resolve);
1150
1162
  onBeforeRequest();
@@ -1392,7 +1404,7 @@ var getAdapterBindings = (req, requestId, systemErrorStatus, systemErrorExtra) =
1392
1404
  if (processingError) {
1393
1405
  return onError(processingError, systemErrorStatus, systemErrorExtra, () => null);
1394
1406
  }
1395
- if (req.mock) {
1407
+ if (req.mock && req.isMockEnabled) {
1396
1408
  return mocker(request, {
1397
1409
  onError,
1398
1410
  onResponseEnd,