@sebspark/retry 1.0.17 → 1.0.19
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 +137 -0
- package/dist/index.cjs +2 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +5 -6
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +5 -6
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +2 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +9 -4
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
# @sebspark/retry
|
|
2
|
+
|
|
3
|
+
## 1.0.19
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 66ac832: * Upgraded to TypeScript 7
|
|
8
|
+
- Replaced tsup with tsdown for package builds
|
|
9
|
+
- Fixed cli-tester stdout parsing, resolving flaky e2e tests across the repo
|
|
10
|
+
- Patched vulnerable transitive dependencies (uuid, socket.io-parser, and others)
|
|
11
|
+
|
|
12
|
+
## 1.0.18
|
|
13
|
+
|
|
14
|
+
### Patch Changes
|
|
15
|
+
|
|
16
|
+
- eefb531: Updated dependencies
|
|
17
|
+
|
|
18
|
+
## 1.0.17
|
|
19
|
+
|
|
20
|
+
### Patch Changes
|
|
21
|
+
|
|
22
|
+
- 612a407: Implement maxDelay option
|
|
23
|
+
|
|
24
|
+
## 1.0.16
|
|
25
|
+
|
|
26
|
+
### Patch Changes
|
|
27
|
+
|
|
28
|
+
- e0eda57: Updated dependencies
|
|
29
|
+
|
|
30
|
+
## 1.0.15
|
|
31
|
+
|
|
32
|
+
### Patch Changes
|
|
33
|
+
|
|
34
|
+
- 97fe7da: Updated dependencies
|
|
35
|
+
|
|
36
|
+
## 1.0.14
|
|
37
|
+
|
|
38
|
+
### Patch Changes
|
|
39
|
+
|
|
40
|
+
- c5e9c99: Resolve protobufjs CVE by pinning to `8.3.0` across all affected packages via root resolutions. Upgraded OpenTelemetry packages to `0.218.0` (which also eliminates the previous hardpin on `protobufjs@8.0.1`), `axios` to `1.16.1`, `ws` to `8.20.1`, `qs` to `6.15.2`, and `@opentelemetry/semantic-conventions` to `1.41.1`.
|
|
41
|
+
|
|
42
|
+
## 1.0.13
|
|
43
|
+
|
|
44
|
+
### Patch Changes
|
|
45
|
+
|
|
46
|
+
- 7d8cc98: Dependabot dependency updates
|
|
47
|
+
|
|
48
|
+
## 1.0.12
|
|
49
|
+
|
|
50
|
+
### Patch Changes
|
|
51
|
+
|
|
52
|
+
- 8a120f6: Updated dependencies for all and docs for emulator
|
|
53
|
+
|
|
54
|
+
## 1.0.11
|
|
55
|
+
|
|
56
|
+
### Patch Changes
|
|
57
|
+
|
|
58
|
+
- e9a7a28: Updated dependencies
|
|
59
|
+
|
|
60
|
+
## 1.0.10
|
|
61
|
+
|
|
62
|
+
### Patch Changes
|
|
63
|
+
|
|
64
|
+
- 4124516: Updated dependencies
|
|
65
|
+
- 4e12590: Updated dependencies
|
|
66
|
+
|
|
67
|
+
## 1.0.9
|
|
68
|
+
|
|
69
|
+
### Patch Changes
|
|
70
|
+
|
|
71
|
+
- 91aed80: Updated dependencies
|
|
72
|
+
|
|
73
|
+
## 1.0.8
|
|
74
|
+
|
|
75
|
+
### Patch Changes
|
|
76
|
+
|
|
77
|
+
- 736a0b3: No bundling of packages in packages
|
|
78
|
+
|
|
79
|
+
## 1.0.7
|
|
80
|
+
|
|
81
|
+
### Patch Changes
|
|
82
|
+
|
|
83
|
+
- 063d384: Updated dependencies
|
|
84
|
+
|
|
85
|
+
## 1.0.6
|
|
86
|
+
|
|
87
|
+
### Patch Changes
|
|
88
|
+
|
|
89
|
+
- 11a11ce: Updated dependencies
|
|
90
|
+
|
|
91
|
+
## 1.0.4
|
|
92
|
+
|
|
93
|
+
### Patch Changes
|
|
94
|
+
|
|
95
|
+
- c7886fc: retry should still support cjs
|
|
96
|
+
|
|
97
|
+
## 1.0.3
|
|
98
|
+
|
|
99
|
+
### Patch Changes
|
|
100
|
+
|
|
101
|
+
- e0cb5ee: Updated build from tsup to tsdown
|
|
102
|
+
|
|
103
|
+
## 1.0.2
|
|
104
|
+
|
|
105
|
+
### Patch Changes
|
|
106
|
+
|
|
107
|
+
- cacbaf5: chore: upgrade dependencies
|
|
108
|
+
|
|
109
|
+
## 1.0.1
|
|
110
|
+
|
|
111
|
+
### Patch Changes
|
|
112
|
+
|
|
113
|
+
- 7e5c2e9: Switched to new tsconfig with moduleResolution=bundler
|
|
114
|
+
|
|
115
|
+
## 1.0.0
|
|
116
|
+
|
|
117
|
+
### Major Changes
|
|
118
|
+
|
|
119
|
+
- 0864ec2: Minimum node version 22
|
|
120
|
+
|
|
121
|
+
## 0.1.2
|
|
122
|
+
|
|
123
|
+
### Patch Changes
|
|
124
|
+
|
|
125
|
+
- 3a40e49: Cleaned up dependencies
|
|
126
|
+
|
|
127
|
+
## 0.1.1
|
|
128
|
+
|
|
129
|
+
### Patch Changes
|
|
130
|
+
|
|
131
|
+
- 93a37b3: Patch dependencies
|
|
132
|
+
|
|
133
|
+
## 0.1.0
|
|
134
|
+
|
|
135
|
+
### Minor Changes
|
|
136
|
+
|
|
137
|
+
- fc423aa: Split retry into a separate package
|
package/dist/index.cjs
CHANGED
|
@@ -15,7 +15,8 @@ const retry = async (func, ...settings) => {
|
|
|
15
15
|
} catch (error) {
|
|
16
16
|
if (mergedSettings && mergedSettings.retryCondition(error) && retries < mergedSettings.maxRetries) {
|
|
17
17
|
const computedDelay = mergedSettings.interval(retries + 1);
|
|
18
|
-
|
|
18
|
+
const delay = mergedSettings.maxDelay !== void 0 ? Math.min(computedDelay, mergedSettings.maxDelay) : computedDelay;
|
|
19
|
+
await wait(delay);
|
|
19
20
|
return makeCall(retries + 1);
|
|
20
21
|
}
|
|
21
22
|
throw error;
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":[],"sources":["../src/retry.ts"],"sourcesContent":["// biome-ignore lint/suspicious/noExplicitAny: Errors can be anything\nexport type RetryConditionFunction = (error: any) => boolean\n\nexport interface RetrySettings {\n maxRetries: number\n interval: (retryCount: number) => number\n retryCondition?: RetryConditionFunction\n maxDelay?: number\n}\n\nconst defaultSettings: Partial<RetrySettings> = {\n retryCondition: () => true,\n}\nconst mergeSettings = (\n ...settings: Array<RetrySettings | undefined>\n): RetrySettings | undefined => {\n // remove undefineds, return if no settings passed\n const s = settings.filter((s) => s) as RetrySettings[]\n if (!s.length) return undefined\n\n // merge settings with priority to the latest\n const merged: RetrySettings = Object.assign({}, defaultSettings, ...s)\n\n return merged\n}\n\nconst wait = (ms: number) =>\n new Promise<void>((resolve) => setTimeout(() => resolve(), ms))\n\nexport const retry = async <T>(\n func: () => Promise<T>,\n ...settings: Array<RetrySettings | undefined>\n): Promise<T> => {\n const mergedSettings = mergeSettings(...settings)\n\n const makeCall = async <T>(retries = 0): Promise<T> => {\n try {\n const response = await func()\n return response as T\n } catch (error) {\n if (\n mergedSettings &&\n // biome-ignore lint/style/noNonNullAssertion: Will be set by defaultSettings\n mergedSettings.retryCondition!(error) &&\n retries < mergedSettings.maxRetries\n ) {\n const computedDelay = mergedSettings.interval(retries + 1)\n const delay =\n mergedSettings.maxDelay !== undefined\n ? Math.min(computedDelay, mergedSettings.maxDelay)\n : computedDelay\n await wait(delay)\n return makeCall(retries + 1)\n }\n\n throw error\n }\n }\n return makeCall(0)\n}\n\nexport const interval = {\n fixed: (delay: number) => (_retries: number) => delay,\n linear: (delay: number) => (retries: number) => retries * delay,\n exponential:\n (delay: number, base = 2) =>\n (retries: number) =>\n base ** (retries - 1) * delay,\n}\n\nconst clientErrorCodes = [\n 400, 401, 402, 403, 404, 405, 406, 407, 408, 409, 410, 411, 412, 413, 414,\n 415, 416, 417, 418, 421, 422, 423, 424, 425, 426, 428, 429, 431, 451,\n] as const\ntype ClientErrorCode = (typeof clientErrorCodes)[number]\n\nconst serverErrorCodes = [\n 500, 501, 502, 503, 504, 505, 506, 507, 508, 510, 511,\n] as const\ntype ServerErrorCode = (typeof serverErrorCodes)[number]\n\ntype ErrorType = 'server' | 'client' | ServerErrorCode | ClientErrorCode\n\ntype HttpError = {\n status?: number\n statusCode?: number\n response?: {\n status?: number\n statusCode?: number\n }\n}\n\nexport const retryCondition = {\n always: (_error: unknown) => true,\n httpErrors:\n (...codes: ErrorType[]) =>\n (error: HttpError) => {\n const captureCodes = codes\n .flatMap((code) => {\n if (typeof code === 'number') return code\n /* istanbul ignore else */\n if (code === 'client') return clientErrorCodes\n /* istanbul ignore next */\n if (code === 'server') return serverErrorCodes\n /* istanbul ignore next */\n return 500\n })\n .filter((code) => !!code) as number[]\n const status =\n error.status ||\n error.statusCode ||\n error.response?.status ||\n error.response?.statusCode ||\n 0\n return captureCodes.includes(status)\n },\n serverErrors: (error: HttpError) =>\n retryCondition.httpErrors('server')(error),\n // biome-ignore lint/suspicious/noExplicitAny: Errors can be anything\n custom: (func: (error: any) => boolean) => func,\n}\n"],"mappings":";;AAUA,MAAM,kBAA0C,EAC9C,sBAAsB,KACxB;AACA,MAAM,iBACJ,GAAG,aAC2B;CAE9B,MAAM,IAAI,SAAS,QAAQ,MAAM,CAAC;CAClC,IAAI,CAAC,EAAE,QAAQ,OAAO,KAAA;CAKtB,OAF8B,OAAO,OAAO,CAAC,GAAG,iBAAiB,GAAG,CAExD;AACd;AAEA,MAAM,QAAQ,OACZ,IAAI,SAAe,YAAY,iBAAiB,QAAQ,GAAG,EAAE,CAAC;AAEhE,MAAa,QAAQ,OACnB,MACA,GAAG,aACY;CACf,MAAM,iBAAiB,cAAc,GAAG,QAAQ;CAEhD,MAAM,WAAW,OAAU,UAAU,MAAkB;EACrD,IAAI;GAEF,OAAO,MADgB,KAAK;EAE9B,SAAS,OAAO;GACd,IACE,kBAEA,eAAe,eAAgB,KAAK,KACpC,UAAU,eAAe,YACzB;IACA,MAAM,gBAAgB,eAAe,SAAS,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"index.cjs","names":[],"sources":["../src/retry.ts"],"sourcesContent":["// biome-ignore lint/suspicious/noExplicitAny: Errors can be anything\nexport type RetryConditionFunction = (error: any) => boolean\n\nexport interface RetrySettings {\n maxRetries: number\n interval: (retryCount: number) => number\n retryCondition?: RetryConditionFunction\n maxDelay?: number\n}\n\nconst defaultSettings: Partial<RetrySettings> = {\n retryCondition: () => true,\n}\nconst mergeSettings = (\n ...settings: Array<RetrySettings | undefined>\n): RetrySettings | undefined => {\n // remove undefineds, return if no settings passed\n const s = settings.filter((s) => s) as RetrySettings[]\n if (!s.length) return undefined\n\n // merge settings with priority to the latest\n const merged: RetrySettings = Object.assign({}, defaultSettings, ...s)\n\n return merged\n}\n\nconst wait = (ms: number) =>\n new Promise<void>((resolve) => setTimeout(() => resolve(), ms))\n\nexport const retry = async <T>(\n func: () => Promise<T>,\n ...settings: Array<RetrySettings | undefined>\n): Promise<T> => {\n const mergedSettings = mergeSettings(...settings)\n\n const makeCall = async <T>(retries = 0): Promise<T> => {\n try {\n const response = await func()\n return response as T\n } catch (error) {\n if (\n mergedSettings &&\n // biome-ignore lint/style/noNonNullAssertion: Will be set by defaultSettings\n mergedSettings.retryCondition!(error) &&\n retries < mergedSettings.maxRetries\n ) {\n const computedDelay = mergedSettings.interval(retries + 1)\n const delay =\n mergedSettings.maxDelay !== undefined\n ? Math.min(computedDelay, mergedSettings.maxDelay)\n : computedDelay\n await wait(delay)\n return makeCall(retries + 1)\n }\n\n throw error\n }\n }\n return makeCall(0)\n}\n\nexport const interval = {\n fixed: (delay: number) => (_retries: number) => delay,\n linear: (delay: number) => (retries: number) => retries * delay,\n exponential:\n (delay: number, base = 2) =>\n (retries: number) =>\n base ** (retries - 1) * delay,\n}\n\nconst clientErrorCodes = [\n 400, 401, 402, 403, 404, 405, 406, 407, 408, 409, 410, 411, 412, 413, 414,\n 415, 416, 417, 418, 421, 422, 423, 424, 425, 426, 428, 429, 431, 451,\n] as const\ntype ClientErrorCode = (typeof clientErrorCodes)[number]\n\nconst serverErrorCodes = [\n 500, 501, 502, 503, 504, 505, 506, 507, 508, 510, 511,\n] as const\ntype ServerErrorCode = (typeof serverErrorCodes)[number]\n\ntype ErrorType = 'server' | 'client' | ServerErrorCode | ClientErrorCode\n\ntype HttpError = {\n status?: number\n statusCode?: number\n response?: {\n status?: number\n statusCode?: number\n }\n}\n\nexport const retryCondition = {\n always: (_error: unknown) => true,\n httpErrors:\n (...codes: ErrorType[]) =>\n (error: HttpError) => {\n const captureCodes = codes\n .flatMap((code) => {\n if (typeof code === 'number') return code\n /* istanbul ignore else */\n if (code === 'client') return clientErrorCodes\n /* istanbul ignore next */\n if (code === 'server') return serverErrorCodes\n /* istanbul ignore next */\n return 500\n })\n .filter((code) => !!code) as number[]\n const status =\n error.status ||\n error.statusCode ||\n error.response?.status ||\n error.response?.statusCode ||\n 0\n return captureCodes.includes(status)\n },\n serverErrors: (error: HttpError) =>\n retryCondition.httpErrors('server')(error),\n // biome-ignore lint/suspicious/noExplicitAny: Errors can be anything\n custom: (func: (error: any) => boolean) => func,\n}\n"],"mappings":";;AAUA,MAAM,kBAA0C,EAC9C,sBAAsB,KACxB;AACA,MAAM,iBACJ,GAAG,aAC2B;CAE9B,MAAM,IAAI,SAAS,QAAQ,MAAM,CAAC;CAClC,IAAI,CAAC,EAAE,QAAQ,OAAO,KAAA;CAKtB,OAF8B,OAAO,OAAO,CAAC,GAAG,iBAAiB,GAAG,CAExD;AACd;AAEA,MAAM,QAAQ,OACZ,IAAI,SAAe,YAAY,iBAAiB,QAAQ,GAAG,EAAE,CAAC;AAEhE,MAAa,QAAQ,OACnB,MACA,GAAG,aACY;CACf,MAAM,iBAAiB,cAAc,GAAG,QAAQ;CAEhD,MAAM,WAAW,OAAU,UAAU,MAAkB;EACrD,IAAI;GAEF,OAAO,MADgB,KAAK;EAE9B,SAAS,OAAO;GACd,IACE,kBAEA,eAAe,eAAgB,KAAK,KACpC,UAAU,eAAe,YACzB;IACA,MAAM,gBAAgB,eAAe,SAAS,UAAU,CAAC;IACzD,MAAM,QACJ,eAAe,aAAa,KAAA,IACxB,KAAK,IAAI,eAAe,eAAe,QAAQ,IAC/C;IACN,MAAM,KAAK,KAAK;IAChB,OAAO,SAAS,UAAU,CAAC;GAC7B;GAEA,MAAM;EACR;CACF;CACA,OAAO,SAAS,CAAC;AACnB;AAEA,MAAa,WAAW;CACtB,QAAQ,WAAmB,aAAqB;CAChD,SAAS,WAAmB,YAAoB,UAAU;CAC1D,cACG,OAAe,OAAO,OACtB,YACC,SAAS,UAAU,KAAK;AAC9B;AAEA,MAAM,mBAAmB;CACvB;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CACtE;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;AACnE;AAGA,MAAM,mBAAmB;CACvB;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;AACpD;AAcA,MAAa,iBAAiB;CAC5B,SAAS,WAAoB;CAC7B,aACG,GAAG,WACH,UAAqB;EACpB,MAAM,eAAe,MAClB,SAAS,SAAS;GACjB,IAAI,OAAO,SAAS,UAAU,OAAO;;GAErC,IAAI,SAAS,UAAU,OAAO;;GAE9B,IAAI,SAAS,UAAU,OAAO;;GAE9B,OAAO;EACT,CAAC,CAAC,CACD,QAAQ,SAAS,CAAC,CAAC,IAAI;EAC1B,MAAM,SACJ,MAAM,UACN,MAAM,cACN,MAAM,UAAU,UAChB,MAAM,UAAU,cAChB;EACF,OAAO,aAAa,SAAS,MAAM;CACrC;CACF,eAAe,UACb,eAAe,WAAW,QAAQ,CAAC,CAAC,KAAK;CAE3C,SAAS,SAAkC;AAC7C"}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
//#region src/retry.d.ts
|
|
2
|
-
type RetryConditionFunction = (error: any) => boolean;
|
|
3
|
-
interface RetrySettings {
|
|
2
|
+
export type RetryConditionFunction = (error: any) => boolean;
|
|
3
|
+
export interface RetrySettings {
|
|
4
4
|
maxRetries: number;
|
|
5
5
|
interval: (retryCount: number) => number;
|
|
6
6
|
retryCondition?: RetryConditionFunction;
|
|
7
7
|
maxDelay?: number;
|
|
8
8
|
}
|
|
9
|
-
declare const retry: <T>(func: () => Promise<T>, ...settings: Array<RetrySettings | undefined>) => Promise<T>;
|
|
10
|
-
declare const interval: {
|
|
9
|
+
export declare const retry: <T>(func: () => Promise<T>, ...settings: Array<RetrySettings | undefined>) => Promise<T>;
|
|
10
|
+
export declare const interval: {
|
|
11
11
|
fixed: (delay: number) => (_retries: number) => number;
|
|
12
12
|
linear: (delay: number) => (retries: number) => number;
|
|
13
13
|
exponential: (delay: number, base?: number) => (retries: number) => number;
|
|
@@ -25,12 +25,11 @@ type HttpError = {
|
|
|
25
25
|
statusCode?: number;
|
|
26
26
|
};
|
|
27
27
|
};
|
|
28
|
-
declare const retryCondition: {
|
|
28
|
+
export declare const retryCondition: {
|
|
29
29
|
always: (_error: unknown) => boolean;
|
|
30
30
|
httpErrors: (...codes: ErrorType[]) => (error: HttpError) => boolean;
|
|
31
31
|
serverErrors: (error: HttpError) => boolean;
|
|
32
32
|
custom: (func: (error: any) => boolean) => (error: any) => boolean;
|
|
33
33
|
};
|
|
34
34
|
//#endregion
|
|
35
|
-
export { RetryConditionFunction, RetrySettings, interval, retry, retryCondition };
|
|
36
35
|
//# sourceMappingURL=index.d.cts.map
|
package/dist/index.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/retry.ts"],"mappings":";
|
|
1
|
+
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/retry.ts"],"mappings":";YACY,0BAA0B;iBAErB;EACf;EACA,WAAW;EACX,iBAAiB;EACjB;;qBAsBW,QAAe,GAAC,YACf,QAAQ,OAAE,UACT,MAAM,+BAClB,QAAQ;qBA6BE;EACX,QAAK,mBAAgB;EACrB,SAAM,mBAAgB;EACtB,cAAW,eACK,mBAAA;;cAKZ;KAID,0BAA0B;cAEzB;KAGD,0BAA0B;KAE1B,kCAAkC,kBAAkB;KAEpD;EACH;EACA;EACA;IACE;IACA;;;qBAIS;EACX,SAAM;EACN,gBAAU,OACG,iBAAW,OACd;EAoBV,eAAY,OAAU;EAGtB,SAAM,OAAU,4BAAsB"}
|
package/dist/index.d.mts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
//#region src/retry.d.ts
|
|
2
|
-
type RetryConditionFunction = (error: any) => boolean;
|
|
3
|
-
interface RetrySettings {
|
|
2
|
+
export type RetryConditionFunction = (error: any) => boolean;
|
|
3
|
+
export interface RetrySettings {
|
|
4
4
|
maxRetries: number;
|
|
5
5
|
interval: (retryCount: number) => number;
|
|
6
6
|
retryCondition?: RetryConditionFunction;
|
|
7
7
|
maxDelay?: number;
|
|
8
8
|
}
|
|
9
|
-
declare const retry: <T>(func: () => Promise<T>, ...settings: Array<RetrySettings | undefined>) => Promise<T>;
|
|
10
|
-
declare const interval: {
|
|
9
|
+
export declare const retry: <T>(func: () => Promise<T>, ...settings: Array<RetrySettings | undefined>) => Promise<T>;
|
|
10
|
+
export declare const interval: {
|
|
11
11
|
fixed: (delay: number) => (_retries: number) => number;
|
|
12
12
|
linear: (delay: number) => (retries: number) => number;
|
|
13
13
|
exponential: (delay: number, base?: number) => (retries: number) => number;
|
|
@@ -25,12 +25,11 @@ type HttpError = {
|
|
|
25
25
|
statusCode?: number;
|
|
26
26
|
};
|
|
27
27
|
};
|
|
28
|
-
declare const retryCondition: {
|
|
28
|
+
export declare const retryCondition: {
|
|
29
29
|
always: (_error: unknown) => boolean;
|
|
30
30
|
httpErrors: (...codes: ErrorType[]) => (error: HttpError) => boolean;
|
|
31
31
|
serverErrors: (error: HttpError) => boolean;
|
|
32
32
|
custom: (func: (error: any) => boolean) => (error: any) => boolean;
|
|
33
33
|
};
|
|
34
34
|
//#endregion
|
|
35
|
-
export { RetryConditionFunction, RetrySettings, interval, retry, retryCondition };
|
|
36
35
|
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/retry.ts"],"mappings":";
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/retry.ts"],"mappings":";YACY,0BAA0B;iBAErB;EACf;EACA,WAAW;EACX,iBAAiB;EACjB;;qBAsBW,QAAe,GAAC,YACf,QAAQ,OAAE,UACT,MAAM,+BAClB,QAAQ;qBA6BE;EACX,QAAK,mBAAgB;EACrB,SAAM,mBAAgB;EACtB,cAAW,eACK,mBAAA;;cAKZ;KAID,0BAA0B;cAEzB;KAGD,0BAA0B;KAE1B,kCAAkC,kBAAkB;KAEpD;EACH;EACA;EACA;IACE;IACA;;;qBAIS;EACX,SAAM;EACN,gBAAU,OACG,iBAAW,OACd;EAoBV,eAAY,OAAU;EAGtB,SAAM,OAAU,4BAAsB"}
|
package/dist/index.mjs
CHANGED
|
@@ -14,7 +14,8 @@ const retry = async (func, ...settings) => {
|
|
|
14
14
|
} catch (error) {
|
|
15
15
|
if (mergedSettings && mergedSettings.retryCondition(error) && retries < mergedSettings.maxRetries) {
|
|
16
16
|
const computedDelay = mergedSettings.interval(retries + 1);
|
|
17
|
-
|
|
17
|
+
const delay = mergedSettings.maxDelay !== void 0 ? Math.min(computedDelay, mergedSettings.maxDelay) : computedDelay;
|
|
18
|
+
await wait(delay);
|
|
18
19
|
return makeCall(retries + 1);
|
|
19
20
|
}
|
|
20
21
|
throw error;
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../src/retry.ts"],"sourcesContent":["// biome-ignore lint/suspicious/noExplicitAny: Errors can be anything\nexport type RetryConditionFunction = (error: any) => boolean\n\nexport interface RetrySettings {\n maxRetries: number\n interval: (retryCount: number) => number\n retryCondition?: RetryConditionFunction\n maxDelay?: number\n}\n\nconst defaultSettings: Partial<RetrySettings> = {\n retryCondition: () => true,\n}\nconst mergeSettings = (\n ...settings: Array<RetrySettings | undefined>\n): RetrySettings | undefined => {\n // remove undefineds, return if no settings passed\n const s = settings.filter((s) => s) as RetrySettings[]\n if (!s.length) return undefined\n\n // merge settings with priority to the latest\n const merged: RetrySettings = Object.assign({}, defaultSettings, ...s)\n\n return merged\n}\n\nconst wait = (ms: number) =>\n new Promise<void>((resolve) => setTimeout(() => resolve(), ms))\n\nexport const retry = async <T>(\n func: () => Promise<T>,\n ...settings: Array<RetrySettings | undefined>\n): Promise<T> => {\n const mergedSettings = mergeSettings(...settings)\n\n const makeCall = async <T>(retries = 0): Promise<T> => {\n try {\n const response = await func()\n return response as T\n } catch (error) {\n if (\n mergedSettings &&\n // biome-ignore lint/style/noNonNullAssertion: Will be set by defaultSettings\n mergedSettings.retryCondition!(error) &&\n retries < mergedSettings.maxRetries\n ) {\n const computedDelay = mergedSettings.interval(retries + 1)\n const delay =\n mergedSettings.maxDelay !== undefined\n ? Math.min(computedDelay, mergedSettings.maxDelay)\n : computedDelay\n await wait(delay)\n return makeCall(retries + 1)\n }\n\n throw error\n }\n }\n return makeCall(0)\n}\n\nexport const interval = {\n fixed: (delay: number) => (_retries: number) => delay,\n linear: (delay: number) => (retries: number) => retries * delay,\n exponential:\n (delay: number, base = 2) =>\n (retries: number) =>\n base ** (retries - 1) * delay,\n}\n\nconst clientErrorCodes = [\n 400, 401, 402, 403, 404, 405, 406, 407, 408, 409, 410, 411, 412, 413, 414,\n 415, 416, 417, 418, 421, 422, 423, 424, 425, 426, 428, 429, 431, 451,\n] as const\ntype ClientErrorCode = (typeof clientErrorCodes)[number]\n\nconst serverErrorCodes = [\n 500, 501, 502, 503, 504, 505, 506, 507, 508, 510, 511,\n] as const\ntype ServerErrorCode = (typeof serverErrorCodes)[number]\n\ntype ErrorType = 'server' | 'client' | ServerErrorCode | ClientErrorCode\n\ntype HttpError = {\n status?: number\n statusCode?: number\n response?: {\n status?: number\n statusCode?: number\n }\n}\n\nexport const retryCondition = {\n always: (_error: unknown) => true,\n httpErrors:\n (...codes: ErrorType[]) =>\n (error: HttpError) => {\n const captureCodes = codes\n .flatMap((code) => {\n if (typeof code === 'number') return code\n /* istanbul ignore else */\n if (code === 'client') return clientErrorCodes\n /* istanbul ignore next */\n if (code === 'server') return serverErrorCodes\n /* istanbul ignore next */\n return 500\n })\n .filter((code) => !!code) as number[]\n const status =\n error.status ||\n error.statusCode ||\n error.response?.status ||\n error.response?.statusCode ||\n 0\n return captureCodes.includes(status)\n },\n serverErrors: (error: HttpError) =>\n retryCondition.httpErrors('server')(error),\n // biome-ignore lint/suspicious/noExplicitAny: Errors can be anything\n custom: (func: (error: any) => boolean) => func,\n}\n"],"mappings":";AAUA,MAAM,kBAA0C,EAC9C,sBAAsB,KACxB;AACA,MAAM,iBACJ,GAAG,aAC2B;CAE9B,MAAM,IAAI,SAAS,QAAQ,MAAM,CAAC;CAClC,IAAI,CAAC,EAAE,QAAQ,OAAO,KAAA;CAKtB,OAF8B,OAAO,OAAO,CAAC,GAAG,iBAAiB,GAAG,CAExD;AACd;AAEA,MAAM,QAAQ,OACZ,IAAI,SAAe,YAAY,iBAAiB,QAAQ,GAAG,EAAE,CAAC;AAEhE,MAAa,QAAQ,OACnB,MACA,GAAG,aACY;CACf,MAAM,iBAAiB,cAAc,GAAG,QAAQ;CAEhD,MAAM,WAAW,OAAU,UAAU,MAAkB;EACrD,IAAI;GAEF,OAAO,MADgB,KAAK;EAE9B,SAAS,OAAO;GACd,IACE,kBAEA,eAAe,eAAgB,KAAK,KACpC,UAAU,eAAe,YACzB;IACA,MAAM,gBAAgB,eAAe,SAAS,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../src/retry.ts"],"sourcesContent":["// biome-ignore lint/suspicious/noExplicitAny: Errors can be anything\nexport type RetryConditionFunction = (error: any) => boolean\n\nexport interface RetrySettings {\n maxRetries: number\n interval: (retryCount: number) => number\n retryCondition?: RetryConditionFunction\n maxDelay?: number\n}\n\nconst defaultSettings: Partial<RetrySettings> = {\n retryCondition: () => true,\n}\nconst mergeSettings = (\n ...settings: Array<RetrySettings | undefined>\n): RetrySettings | undefined => {\n // remove undefineds, return if no settings passed\n const s = settings.filter((s) => s) as RetrySettings[]\n if (!s.length) return undefined\n\n // merge settings with priority to the latest\n const merged: RetrySettings = Object.assign({}, defaultSettings, ...s)\n\n return merged\n}\n\nconst wait = (ms: number) =>\n new Promise<void>((resolve) => setTimeout(() => resolve(), ms))\n\nexport const retry = async <T>(\n func: () => Promise<T>,\n ...settings: Array<RetrySettings | undefined>\n): Promise<T> => {\n const mergedSettings = mergeSettings(...settings)\n\n const makeCall = async <T>(retries = 0): Promise<T> => {\n try {\n const response = await func()\n return response as T\n } catch (error) {\n if (\n mergedSettings &&\n // biome-ignore lint/style/noNonNullAssertion: Will be set by defaultSettings\n mergedSettings.retryCondition!(error) &&\n retries < mergedSettings.maxRetries\n ) {\n const computedDelay = mergedSettings.interval(retries + 1)\n const delay =\n mergedSettings.maxDelay !== undefined\n ? Math.min(computedDelay, mergedSettings.maxDelay)\n : computedDelay\n await wait(delay)\n return makeCall(retries + 1)\n }\n\n throw error\n }\n }\n return makeCall(0)\n}\n\nexport const interval = {\n fixed: (delay: number) => (_retries: number) => delay,\n linear: (delay: number) => (retries: number) => retries * delay,\n exponential:\n (delay: number, base = 2) =>\n (retries: number) =>\n base ** (retries - 1) * delay,\n}\n\nconst clientErrorCodes = [\n 400, 401, 402, 403, 404, 405, 406, 407, 408, 409, 410, 411, 412, 413, 414,\n 415, 416, 417, 418, 421, 422, 423, 424, 425, 426, 428, 429, 431, 451,\n] as const\ntype ClientErrorCode = (typeof clientErrorCodes)[number]\n\nconst serverErrorCodes = [\n 500, 501, 502, 503, 504, 505, 506, 507, 508, 510, 511,\n] as const\ntype ServerErrorCode = (typeof serverErrorCodes)[number]\n\ntype ErrorType = 'server' | 'client' | ServerErrorCode | ClientErrorCode\n\ntype HttpError = {\n status?: number\n statusCode?: number\n response?: {\n status?: number\n statusCode?: number\n }\n}\n\nexport const retryCondition = {\n always: (_error: unknown) => true,\n httpErrors:\n (...codes: ErrorType[]) =>\n (error: HttpError) => {\n const captureCodes = codes\n .flatMap((code) => {\n if (typeof code === 'number') return code\n /* istanbul ignore else */\n if (code === 'client') return clientErrorCodes\n /* istanbul ignore next */\n if (code === 'server') return serverErrorCodes\n /* istanbul ignore next */\n return 500\n })\n .filter((code) => !!code) as number[]\n const status =\n error.status ||\n error.statusCode ||\n error.response?.status ||\n error.response?.statusCode ||\n 0\n return captureCodes.includes(status)\n },\n serverErrors: (error: HttpError) =>\n retryCondition.httpErrors('server')(error),\n // biome-ignore lint/suspicious/noExplicitAny: Errors can be anything\n custom: (func: (error: any) => boolean) => func,\n}\n"],"mappings":";AAUA,MAAM,kBAA0C,EAC9C,sBAAsB,KACxB;AACA,MAAM,iBACJ,GAAG,aAC2B;CAE9B,MAAM,IAAI,SAAS,QAAQ,MAAM,CAAC;CAClC,IAAI,CAAC,EAAE,QAAQ,OAAO,KAAA;CAKtB,OAF8B,OAAO,OAAO,CAAC,GAAG,iBAAiB,GAAG,CAExD;AACd;AAEA,MAAM,QAAQ,OACZ,IAAI,SAAe,YAAY,iBAAiB,QAAQ,GAAG,EAAE,CAAC;AAEhE,MAAa,QAAQ,OACnB,MACA,GAAG,aACY;CACf,MAAM,iBAAiB,cAAc,GAAG,QAAQ;CAEhD,MAAM,WAAW,OAAU,UAAU,MAAkB;EACrD,IAAI;GAEF,OAAO,MADgB,KAAK;EAE9B,SAAS,OAAO;GACd,IACE,kBAEA,eAAe,eAAgB,KAAK,KACpC,UAAU,eAAe,YACzB;IACA,MAAM,gBAAgB,eAAe,SAAS,UAAU,CAAC;IACzD,MAAM,QACJ,eAAe,aAAa,KAAA,IACxB,KAAK,IAAI,eAAe,eAAe,QAAQ,IAC/C;IACN,MAAM,KAAK,KAAK;IAChB,OAAO,SAAS,UAAU,CAAC;GAC7B;GAEA,MAAM;EACR;CACF;CACA,OAAO,SAAS,CAAC;AACnB;AAEA,MAAa,WAAW;CACtB,QAAQ,WAAmB,aAAqB;CAChD,SAAS,WAAmB,YAAoB,UAAU;CAC1D,cACG,OAAe,OAAO,OACtB,YACC,SAAS,UAAU,KAAK;AAC9B;AAEA,MAAM,mBAAmB;CACvB;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CACtE;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;AACnE;AAGA,MAAM,mBAAmB;CACvB;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;AACpD;AAcA,MAAa,iBAAiB;CAC5B,SAAS,WAAoB;CAC7B,aACG,GAAG,WACH,UAAqB;EACpB,MAAM,eAAe,MAClB,SAAS,SAAS;GACjB,IAAI,OAAO,SAAS,UAAU,OAAO;;GAErC,IAAI,SAAS,UAAU,OAAO;;GAE9B,IAAI,SAAS,UAAU,OAAO;;GAE9B,OAAO;EACT,CAAC,CAAC,CACD,QAAQ,SAAS,CAAC,CAAC,IAAI;EAC1B,MAAM,SACJ,MAAM,UACN,MAAM,cACN,MAAM,UAAU,UAChB,MAAM,UAAU,cAChB;EACF,OAAO,aAAa,SAAS,MAAM;CACrC;CACF,eAAe,UACb,eAAe,WAAW,QAAQ,CAAC,CAAC,KAAK;CAE3C,SAAS,SAAkC;AAC7C"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sebspark/retry",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.19",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"main": "dist/index.cjs",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -25,13 +25,18 @@
|
|
|
25
25
|
"dev": "tsc --watch --noEmit",
|
|
26
26
|
"lint": "biome lint .",
|
|
27
27
|
"test": "vitest run --passWithNoTests --coverage",
|
|
28
|
-
"typecheck": "vitest --typecheck.only --passWithNoTests"
|
|
28
|
+
"typecheck": "vitest --typecheck.only --passWithNoTests --run"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
|
-
"
|
|
31
|
+
"@biomejs/biome": "2.5.12",
|
|
32
|
+
"@sebspark/tsconfig": "*",
|
|
33
|
+
"axios": "1.20.0",
|
|
34
|
+
"typescript": "7.0.2",
|
|
35
|
+
"vite": "8.2.2",
|
|
36
|
+
"vitest": "5.0.0"
|
|
32
37
|
},
|
|
33
38
|
"repository": {
|
|
34
39
|
"type": "git",
|
|
35
40
|
"url": "https://github.com/seb-oss/Spark-packages.git"
|
|
36
41
|
}
|
|
37
|
-
}
|
|
42
|
+
}
|