@xylabs/retry 5.1.2 → 5.1.3

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.
@@ -25,4 +25,4 @@ var retry = async (func, config) => {
25
25
  export {
26
26
  retry
27
27
  };
28
- //# sourceMappingURL=index.mjs.map
28
+ //# sourceMappingURL=index.mjs.map
@@ -1 +1,7 @@
1
- {"version":3,"sources":["../../src/retry.ts"],"sourcesContent":["import { delay } from '@xylabs/delay'\nimport type { Promisable } from '@xylabs/promise'\n\n/** Configuration for retry behavior. */\nexport interface RetryConfig {\n /** Multiplier applied to the interval after each retry. Defaults to 2. */\n backoff?: number\n /** Initial delay in milliseconds between retries. Defaults to 100. */\n interval?: number\n /** Maximum number of retry attempts. Defaults to 0 (no retries). */\n retries?: number\n}\n\n/** Retry configuration extended with a custom completion check. */\nexport interface RetryConfigWithComplete<T = unknown> extends RetryConfig {\n /** Determines whether the result is considered complete. Defaults to checking for a defined value. */\n complete?: (result?: T) => boolean\n}\n\n/**\n * Retries an async function with exponential backoff until it completes or retries are exhausted.\n * @param func - The function to retry.\n * @param config - Optional retry configuration including backoff, interval, retries, and completion check.\n * @returns The result of the function, or undefined if all retries were exhausted.\n */\nexport const retry = async <T = unknown>(func: () => Promisable<T | undefined>, config?: RetryConfigWithComplete<T>): Promise<T | undefined> => {\n const {\n complete = (value: T | undefined) => value !== undefined, retries = 0, interval = 100, backoff = 2,\n } = 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, {\n backoff, complete, interval: interval * backoff, retries: retries - 1,\n })\n}\n"],"mappings":";AAAA,SAAS,aAAa;AAyBf,IAAM,QAAQ,OAAoB,MAAuC,WAAgE;AAC9I,QAAM;AAAA,IACJ,WAAW,CAAC,UAAyB,UAAU;AAAA,IAAW,UAAU;AAAA,IAAG,WAAW;AAAA,IAAK,UAAU;AAAA,EACnG,IAAI,UAAU,CAAC;AACf,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;AAAA,IACjB;AAAA,IAAS;AAAA,IAAU,UAAU,WAAW;AAAA,IAAS,SAAS,UAAU;AAAA,EACtE,CAAC;AACH;","names":[]}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/retry.ts"],
4
+ "sourcesContent": ["import { delay } from '@xylabs/delay'\nimport type { Promisable } from '@xylabs/promise'\n\n/** Configuration for retry behavior. */\nexport interface RetryConfig {\n /** Multiplier applied to the interval after each retry. Defaults to 2. */\n backoff?: number\n /** Initial delay in milliseconds between retries. Defaults to 100. */\n interval?: number\n /** Maximum number of retry attempts. Defaults to 0 (no retries). */\n retries?: number\n}\n\n/** Retry configuration extended with a custom completion check. */\nexport interface RetryConfigWithComplete<T = unknown> extends RetryConfig {\n /** Determines whether the result is considered complete. Defaults to checking for a defined value. */\n complete?: (result?: T) => boolean\n}\n\n/**\n * Retries an async function with exponential backoff until it completes or retries are exhausted.\n * @param func - The function to retry.\n * @param config - Optional retry configuration including backoff, interval, retries, and completion check.\n * @returns The result of the function, or undefined if all retries were exhausted.\n */\nexport const retry = async <T = unknown>(func: () => Promisable<T | undefined>, config?: RetryConfigWithComplete<T>): Promise<T | undefined> => {\n const {\n complete = (value: T | undefined) => value !== undefined, retries = 0, interval = 100, backoff = 2,\n } = 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, {\n backoff, complete, interval: interval * backoff, retries: retries - 1,\n })\n}\n"],
5
+ "mappings": ";AAAA,SAAS,aAAa;AAyBf,IAAM,QAAQ,OAAoB,MAAuC,WAAgE;AAC9I,QAAM;AAAA,IACJ,WAAW,CAAC,UAAyB,UAAU;AAAA,IAAW,UAAU;AAAA,IAAG,WAAW;AAAA,IAAK,UAAU;AAAA,EACnG,IAAI,UAAU,CAAC;AACf,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;AAAA,IACjB;AAAA,IAAS;AAAA,IAAU,UAAU,WAAW;AAAA,IAAS,SAAS,UAAU;AAAA,EACtE,CAAC;AACH;",
6
+ "names": []
7
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xylabs/retry",
3
- "version": "5.1.2",
3
+ "version": "5.1.3",
4
4
  "description": "Base functionality used throughout XY Labs TypeScript/JavaScript libraries",
5
5
  "keywords": [
6
6
  "delay",
@@ -41,16 +41,16 @@
41
41
  "README.md"
42
42
  ],
43
43
  "dependencies": {
44
- "@xylabs/delay": "~5.1.2",
45
- "@xylabs/promise": "~5.1.2"
44
+ "@xylabs/delay": "~5.1.3",
45
+ "@xylabs/promise": "~5.1.3"
46
46
  },
47
47
  "devDependencies": {
48
- "@xylabs/toolchain": "~7.13.15",
49
- "@xylabs/tsconfig": "~7.13.15",
48
+ "@xylabs/toolchain": "~8.0.4",
49
+ "@xylabs/tsconfig": "~8.0.4",
50
50
  "eslint": "^10.3.0",
51
- "typescript": "^5.9.3",
52
- "vite": "^8.0.10",
53
- "vitest": "^4.1.5"
51
+ "typescript": "^6.0.3",
52
+ "vite": "^8.0.13",
53
+ "vitest": "^4.1.6"
54
54
  },
55
55
  "engines": {
56
56
  "node": ">=18"