keq 2.5.3 → 2.5.4

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/CHANGELOG.md CHANGED
@@ -2,6 +2,13 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4
4
 
5
+ ## [2.5.4](https://github.com/keq-request/keq/compare/v2.5.3...v2.5.4) (2024-05-23)
6
+
7
+
8
+ ### Performance Improvements
9
+
10
+ * retryOn and retryDelay support return Promise ([398c262](https://github.com/keq-request/keq/commit/398c26294aa303feb5b14ab17d3ff96036bfdde2))
11
+
5
12
  ## [2.5.3](https://github.com/keq-request/keq/compare/v2.5.2...v2.5.3) (2024-05-23)
6
13
 
7
14
 
@@ -7,7 +7,7 @@ export function retryMiddleware() {
7
7
  const retryTimes = Number.isInteger(ctx.options.retryTimes)
8
8
  ? ctx.options.retryTimes + 1
9
9
  : 1;
10
- const retryDelay = (attempt, error, ctx) => {
10
+ const retryDelay = async (attempt, error, ctx) => {
11
11
  if (typeof ctx.options.retryDelay === 'function') {
12
12
  return ctx.options.retryDelay(attempt, error, ctx);
13
13
  }
@@ -41,12 +41,12 @@ export function retryMiddleware() {
41
41
  throw err;
42
42
  break;
43
43
  }
44
- if (retryOn(i, err, ctx) === false) {
44
+ if (await retryOn(i, err, ctx) === false) {
45
45
  if (err)
46
46
  throw err;
47
47
  break;
48
48
  }
49
- const delay = retryDelay(i, err, ctx);
49
+ const delay = await retryDelay(i, err, ctx);
50
50
  if (delay > 0)
51
51
  await sleep(delay);
52
52
  }
@@ -1,2 +1,2 @@
1
1
  import { KeqContext } from './keq-context';
2
- export type KeqRetryDelay = number | ((attempt: number, error: unknown | null, ctx: KeqContext) => number);
2
+ export type KeqRetryDelay = number | ((attempt: number, error: unknown | null, ctx: KeqContext) => number | Promise<number>);
@@ -1,2 +1,2 @@
1
1
  import { KeqContext } from './keq-context';
2
- export type KeqRetryOn = (attempt: number, error: unknown | null, ctx: KeqContext) => boolean;
2
+ export type KeqRetryOn = (attempt: number, error: unknown | null, ctx: KeqContext) => (boolean | Promise<boolean>);
@@ -19,7 +19,7 @@
19
19
  const retryTimes = Number.isInteger(ctx.options.retryTimes)
20
20
  ? ctx.options.retryTimes + 1
21
21
  : 1;
22
- const retryDelay = (attempt, error, ctx) => {
22
+ const retryDelay = async (attempt, error, ctx) => {
23
23
  if (typeof ctx.options.retryDelay === 'function') {
24
24
  return ctx.options.retryDelay(attempt, error, ctx);
25
25
  }
@@ -53,12 +53,12 @@
53
53
  throw err;
54
54
  break;
55
55
  }
56
- if (retryOn(i, err, ctx) === false) {
56
+ if (await retryOn(i, err, ctx) === false) {
57
57
  if (err)
58
58
  throw err;
59
59
  break;
60
60
  }
61
- const delay = retryDelay(i, err, ctx);
61
+ const delay = await retryDelay(i, err, ctx);
62
62
  if (delay > 0)
63
63
  await sleep(delay);
64
64
  }
@@ -1,2 +1,2 @@
1
1
  import { KeqContext } from './keq-context';
2
- export type KeqRetryDelay = number | ((attempt: number, error: unknown | null, ctx: KeqContext) => number);
2
+ export type KeqRetryDelay = number | ((attempt: number, error: unknown | null, ctx: KeqContext) => number | Promise<number>);
@@ -1,2 +1,2 @@
1
1
  import { KeqContext } from './keq-context';
2
- export type KeqRetryOn = (attempt: number, error: unknown | null, ctx: KeqContext) => boolean;
2
+ export type KeqRetryOn = (attempt: number, error: unknown | null, ctx: KeqContext) => (boolean | Promise<boolean>);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "keq",
3
- "version": "2.5.3",
3
+ "version": "2.5.4",
4
4
  "description": "Request API write by Typescript for flexibility, readability, and a low learning curve.",
5
5
  "keywords": [
6
6
  "request",
@@ -40,7 +40,7 @@
40
40
  "test": "jest"
41
41
  },
42
42
  "dependencies": {
43
- "@types/whatwg-url": "^11.0.4",
43
+ "@types/whatwg-url": "^11.0.5",
44
44
  "clone": "^2.1.2",
45
45
  "fastq": "^1.17.1",
46
46
  "minimatch": "^9.0.4",
@@ -53,19 +53,19 @@
53
53
  "@commitlint/cli": "^19.3.0",
54
54
  "@commitlint/config-conventional": "^19.2.2",
55
55
  "@jest/globals": "^29.7.0",
56
- "@rushstack/eslint-patch": "^1.10.2",
56
+ "@rushstack/eslint-patch": "^1.10.3",
57
57
  "@types/clone": "^2.1.4",
58
58
  "@types/minimatch": "^5.1.2",
59
- "@types/node": "^20.12.7",
60
- "@typescript-eslint/eslint-plugin": "^7.7.1",
61
- "@typescript-eslint/parser": "^7.7.1",
59
+ "@types/node": "^20.12.12",
60
+ "@typescript-eslint/eslint-plugin": "^7.10.0",
61
+ "@typescript-eslint/parser": "^7.10.0",
62
62
  "eslint": "^8.57.0",
63
63
  "husky": "^9.0.11",
64
64
  "is-ci": "^3.0.1",
65
65
  "jest": "^29.7.0",
66
66
  "jest-mock": "^29.7.0",
67
67
  "standard-version": "^9.5.0",
68
- "ts-jest": "^29.1.2",
68
+ "ts-jest": "^29.1.3",
69
69
  "ts-node": "^10.9.2",
70
70
  "ts-patch": "^3.1.2",
71
71
  "typescript": "^5.4.5",