@xylabs/retry 3.1.13 → 3.3.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.
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var src_exports = {};
22
+ __export(src_exports, {
23
+ retry: () => retry
24
+ });
25
+ module.exports = __toCommonJS(src_exports);
26
+
27
+ // src/retry.ts
28
+ var import_delay = require("@xylabs/delay");
29
+ var retry = async (func, config) => {
30
+ const { complete = (value) => value !== void 0, retries = 0, interval = 100, backoff = 2 } = config ?? {};
31
+ const result = await func();
32
+ if (complete(result)) {
33
+ return result;
34
+ }
35
+ if (retries <= 0) {
36
+ return void 0;
37
+ }
38
+ await (0, import_delay.delay)(interval);
39
+ return retry(func, { backoff, complete, interval: interval * backoff, retries: retries - 1 });
40
+ };
41
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/index.ts","../../src/retry.ts"],"sourcesContent":["export * from './retry'\n","import { delay } from '@xylabs/delay'\nimport { Promisable } from '@xylabs/promise'\n\nexport interface RetryConfig {\n backoff?: number\n interval?: number\n retries?: number\n}\n\nexport interface RetryConfigWithComplete<T = unknown> extends RetryConfig {\n complete?: (result?: T) => boolean\n}\n\nexport const retry = async <T = unknown>(func: () => Promisable<T | undefined>, config?: RetryConfigWithComplete<T>): Promise<T | undefined> => {\n const { complete = (value: T | undefined) => value !== undefined, retries = 0, interval = 100, backoff = 2 } = config ?? {}\n const result = await func()\n if (complete(result)) {\n return result\n }\n if (retries <= 0) {\n return undefined\n }\n await delay(interval)\n return retry(func, { backoff, complete, interval: interval * backoff, retries: retries - 1 })\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,mBAAsB;AAaf,IAAM,QAAQ,OAAoB,MAAuC,WAAgE;AAC9I,QAAM,EAAE,WAAW,CAAC,UAAyB,UAAU,QAAW,UAAU,GAAG,WAAW,KAAK,UAAU,EAAE,IAAI,UAAU,CAAC;AAC1H,QAAM,SAAS,MAAM,KAAK;AAC1B,MAAI,SAAS,MAAM,GAAG;AACpB,WAAO;AAAA,EACT;AACA,MAAI,WAAW,GAAG;AAChB,WAAO;AAAA,EACT;AACA,YAAM,oBAAM,QAAQ;AACpB,SAAO,MAAM,MAAM,EAAE,SAAS,UAAU,UAAU,WAAW,SAAS,SAAS,UAAU,EAAE,CAAC;AAC9F;","names":[]}
@@ -0,0 +1,2 @@
1
+ export * from './retry';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAA"}
@@ -0,0 +1,2 @@
1
+ export * from './retry';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAA"}
@@ -0,0 +1,2 @@
1
+ export * from './retry';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAA"}
@@ -0,0 +1,18 @@
1
+ // src/retry.ts
2
+ import { delay } from "@xylabs/delay";
3
+ var retry = async (func, config) => {
4
+ const { complete = (value) => value !== void 0, retries = 0, interval = 100, backoff = 2 } = config ?? {};
5
+ const result = await func();
6
+ if (complete(result)) {
7
+ return result;
8
+ }
9
+ if (retries <= 0) {
10
+ return void 0;
11
+ }
12
+ await delay(interval);
13
+ return retry(func, { backoff, complete, interval: interval * backoff, retries: retries - 1 });
14
+ };
15
+ export {
16
+ retry
17
+ };
18
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/retry.ts"],"sourcesContent":["import { delay } from '@xylabs/delay'\nimport { Promisable } from '@xylabs/promise'\n\nexport interface RetryConfig {\n backoff?: number\n interval?: number\n retries?: number\n}\n\nexport interface RetryConfigWithComplete<T = unknown> extends RetryConfig {\n complete?: (result?: T) => boolean\n}\n\nexport const retry = async <T = unknown>(func: () => Promisable<T | undefined>, config?: RetryConfigWithComplete<T>): Promise<T | undefined> => {\n const { complete = (value: T | undefined) => value !== undefined, retries = 0, interval = 100, backoff = 2 } = config ?? {}\n const result = await func()\n if (complete(result)) {\n return result\n }\n if (retries <= 0) {\n return undefined\n }\n await delay(interval)\n return retry(func, { backoff, complete, interval: interval * backoff, retries: retries - 1 })\n}\n"],"mappings":";AAAA,SAAS,aAAa;AAaf,IAAM,QAAQ,OAAoB,MAAuC,WAAgE;AAC9I,QAAM,EAAE,WAAW,CAAC,UAAyB,UAAU,QAAW,UAAU,GAAG,WAAW,KAAK,UAAU,EAAE,IAAI,UAAU,CAAC;AAC1H,QAAM,SAAS,MAAM,KAAK;AAC1B,MAAI,SAAS,MAAM,GAAG;AACpB,WAAO;AAAA,EACT;AACA,MAAI,WAAW,GAAG;AAChB,WAAO;AAAA,EACT;AACA,QAAM,MAAM,QAAQ;AACpB,SAAO,MAAM,MAAM,EAAE,SAAS,UAAU,UAAU,WAAW,SAAS,SAAS,UAAU,EAAE,CAAC;AAC9F;","names":[]}
@@ -0,0 +1,11 @@
1
+ import { Promisable } from '@xylabs/promise';
2
+ export interface RetryConfig {
3
+ backoff?: number;
4
+ interval?: number;
5
+ retries?: number;
6
+ }
7
+ export interface RetryConfigWithComplete<T = unknown> extends RetryConfig {
8
+ complete?: (result?: T) => boolean;
9
+ }
10
+ export declare const retry: <T = unknown>(func: () => Promisable<T | undefined>, config?: RetryConfigWithComplete<T>) => Promise<T | undefined>;
11
+ //# sourceMappingURL=retry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"retry.d.ts","sourceRoot":"","sources":["../../src/retry.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAE5C,MAAM,WAAW,WAAW;IAC1B,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB;AAED,MAAM,WAAW,uBAAuB,CAAC,CAAC,GAAG,OAAO,CAAE,SAAQ,WAAW;IACvE,QAAQ,CAAC,EAAE,CAAC,MAAM,CAAC,EAAE,CAAC,KAAK,OAAO,CAAA;CACnC;AAED,eAAO,MAAM,KAAK,sBAA6B,MAAM,WAAW,CAAC,GAAG,SAAS,CAAC,WAAW,wBAAwB,CAAC,CAAC,KAAG,QAAQ,CAAC,GAAG,SAAS,CAW1I,CAAA"}
@@ -0,0 +1,11 @@
1
+ import { Promisable } from '@xylabs/promise';
2
+ export interface RetryConfig {
3
+ backoff?: number;
4
+ interval?: number;
5
+ retries?: number;
6
+ }
7
+ export interface RetryConfigWithComplete<T = unknown> extends RetryConfig {
8
+ complete?: (result?: T) => boolean;
9
+ }
10
+ export declare const retry: <T = unknown>(func: () => Promisable<T | undefined>, config?: RetryConfigWithComplete<T>) => Promise<T | undefined>;
11
+ //# sourceMappingURL=retry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"retry.d.ts","sourceRoot":"","sources":["../../src/retry.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAE5C,MAAM,WAAW,WAAW;IAC1B,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB;AAED,MAAM,WAAW,uBAAuB,CAAC,CAAC,GAAG,OAAO,CAAE,SAAQ,WAAW;IACvE,QAAQ,CAAC,EAAE,CAAC,MAAM,CAAC,EAAE,CAAC,KAAK,OAAO,CAAA;CACnC;AAED,eAAO,MAAM,KAAK,sBAA6B,MAAM,WAAW,CAAC,GAAG,SAAS,CAAC,WAAW,wBAAwB,CAAC,CAAC,KAAG,QAAQ,CAAC,GAAG,SAAS,CAW1I,CAAA"}
@@ -0,0 +1,11 @@
1
+ import { Promisable } from '@xylabs/promise';
2
+ export interface RetryConfig {
3
+ backoff?: number;
4
+ interval?: number;
5
+ retries?: number;
6
+ }
7
+ export interface RetryConfigWithComplete<T = unknown> extends RetryConfig {
8
+ complete?: (result?: T) => boolean;
9
+ }
10
+ export declare const retry: <T = unknown>(func: () => Promisable<T | undefined>, config?: RetryConfigWithComplete<T>) => Promise<T | undefined>;
11
+ //# sourceMappingURL=retry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"retry.d.ts","sourceRoot":"","sources":["../../src/retry.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAE5C,MAAM,WAAW,WAAW;IAC1B,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB;AAED,MAAM,WAAW,uBAAuB,CAAC,CAAC,GAAG,OAAO,CAAE,SAAQ,WAAW;IACvE,QAAQ,CAAC,EAAE,CAAC,MAAM,CAAC,EAAE,CAAC,KAAK,OAAO,CAAA;CACnC;AAED,eAAO,MAAM,KAAK,sBAA6B,MAAM,WAAW,CAAC,GAAG,SAAS,CAAC,WAAW,wBAAwB,CAAC,CAAC,KAAG,QAAQ,CAAC,GAAG,SAAS,CAW1I,CAAA"}
package/package.json CHANGED
@@ -14,19 +14,19 @@
14
14
  "exports": {
15
15
  ".": {
16
16
  "require": {
17
- "types": "./dist/node/index.d.cts",
18
- "default": "./dist/node/index.cjs"
17
+ "types": "./dist/neutral/index.d.cts",
18
+ "default": "./dist/neutral/index.cjs"
19
19
  },
20
20
  "import": {
21
- "types": "./dist/node/index.d.mts",
22
- "default": "./dist/node/index.js"
21
+ "types": "./dist/neutral/index.d.mts",
22
+ "default": "./dist/neutral/index.js"
23
23
  }
24
24
  },
25
25
  "./package.json": "./package.json"
26
26
  },
27
- "main": "./dist/node/index.cjs",
28
- "types": "./dist/node/index.d.ts",
29
- "module": "./dist/node/index.js",
27
+ "main": "./dist/neutral/index.cjs",
28
+ "types": "./dist/neutral/index.d.ts",
29
+ "module": "./dist/neutral/index.js",
30
30
  "homepage": "https://xylabs.com",
31
31
  "keywords": [
32
32
  "delay",
@@ -36,13 +36,13 @@
36
36
  "esm"
37
37
  ],
38
38
  "dependencies": {
39
- "@xylabs/delay": "~3.1.13",
40
- "@xylabs/promise": "~3.1.13"
39
+ "@xylabs/delay": "~3.3.0",
40
+ "@xylabs/promise": "~3.3.0"
41
41
  },
42
42
  "devDependencies": {
43
- "@xylabs/ts-scripts-yarn3": "^3.9.1",
44
- "@xylabs/tsconfig": "^3.9.1",
45
- "@xylabs/tsconfig-dom": "^3.9.1",
43
+ "@xylabs/ts-scripts-yarn3": "^3.10.0",
44
+ "@xylabs/tsconfig": "^3.10.0",
45
+ "@xylabs/tsconfig-dom": "^3.10.0",
46
46
  "typescript": "^5.4.5"
47
47
  },
48
48
  "engines": {
@@ -56,6 +56,6 @@
56
56
  "url": "https://github.com/xylabs/sdk-js.git"
57
57
  },
58
58
  "sideEffects": false,
59
- "version": "3.1.13",
59
+ "version": "3.3.0",
60
60
  "type": "module"
61
61
  }