@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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hyper-fetch/core",
3
- "version": "5.0.1",
3
+ "version": "5.1.0",
4
4
  "private": false,
5
5
  "description": "Cache, Queue and Persist your requests no matter if you are online or offline!",
6
6
  "author": "Maciej Pyrc <m.pyrc@interia.pl>",
@@ -31,7 +31,6 @@
31
31
  "./package.json": "./package.json"
32
32
  },
33
33
  "scripts": {
34
- "prepublishOnly": "yarn build",
35
34
  "clean": "npx rimraf dist",
36
35
  "test": "jest --watchAll --maxWorkers=3",
37
36
  "test-pipeline": "jest --watchAll=false --maxWorkers=1 --no-cache",
@@ -337,7 +337,7 @@ export const getAdapterBindings = async <T extends AdapterInstance = AdapterType
337
337
  if (processingError) {
338
338
  return onError(processingError, systemErrorStatus, systemErrorExtra, () => null);
339
339
  }
340
- if (req.mock) {
340
+ if (req.mock && req.isMockEnabled) {
341
341
  return mocker(request, {
342
342
  onError,
343
343
  onResponseEnd,
@@ -30,13 +30,18 @@ export const mocker = async <T extends AdapterInstance = AdapterType>(
30
30
  | "onSuccess"
31
31
  >,
32
32
  ) => {
33
- const timeout = request.requestOptions.options?.timeout || request.options?.timeout;
34
33
  const mock = request.mock.next();
35
34
  const result = mock.value instanceof Function ? await mock.value(request) : mock.value;
36
35
 
37
36
  return new Promise<ResponseReturnType<any, any, any>>((resolve) => {
38
37
  const { data, status = 200, success = true, extra, config } = result;
39
- const { requestTime = 20, responseTime = 20, totalUploaded = 1, totalDownloaded = 1 } = config || {};
38
+ const {
39
+ requestTime = 20,
40
+ responseTime = 20,
41
+ totalUploaded = 1,
42
+ totalDownloaded = 1,
43
+ timeout = false,
44
+ } = config || {};
40
45
 
41
46
  createAbortListener(0 as any, {} as any, () => {}, resolve);
42
47
 
@@ -79,6 +79,7 @@ export class Request<
79
79
  GeneratorReturnMockTypes<Response, this>
80
80
  >;
81
81
  mockData?: RequestDataMockTypes<Response, this>;
82
+ isMockEnabled = false;
82
83
  requestMapper?: RequestMapper<this, any>;
83
84
  responseMapper?: ResponseMapper<this, any, any>;
84
85
 
@@ -285,12 +286,19 @@ export class Request<
285
286
  };
286
287
  this.mockData = mockData;
287
288
  this.mock = mockGenerator(mockData);
289
+ this.isMockEnabled = true;
288
290
  return this;
289
291
  };
290
292
 
291
293
  public removeMock = () => {
292
294
  this.mockData = null;
293
295
  this.mock = null;
296
+ this.isMockEnabled = false;
297
+ return this;
298
+ };
299
+
300
+ public setEnableMocking = (isMockEnabled: boolean) => {
301
+ this.isMockEnabled = isMockEnabled;
294
302
  return this;
295
303
  };
296
304
 
@@ -439,6 +447,7 @@ export class Request<
439
447
 
440
448
  cloned.mockData = this.mockData;
441
449
  cloned.mock = this.mock;
450
+ cloned.isMockEnabled = this.isMockEnabled;
442
451
 
443
452
  return cloned;
444
453
  }