foxts 5.3.0 → 5.4.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/dist/async-retry/index.js +1 -1
- package/dist/async-retry/index.mjs +1 -1
- package/dist/is-network-error/index.js +1 -1
- package/dist/is-network-error/index.mjs +1 -1
- package/dist/literal/index.d.ts +9 -5
- package/dist/wait/index.d.ts +2 -2
- package/dist/wait/index.js +1 -1
- package/dist/wait/index.mjs +1 -1
- package/package.json +13 -13
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var t=require("../abort-error/index.js"),e=require("../extract-error-message/index.js"),r=require("../is-network-error/index.js"),o=require("../noop/index.js"),i=require("../wait/index.js");const{round:n}=Math,a=Error,s=TypeError;function c(t,e,r=0,o=!1){if(Number.isNaN(e))throw new s(`Expected \`${t}\` to be a valid number${o?" or Infinity":""}, got NaN.`);if(!o&&!Number.isFinite(e))throw new s(`Expected \`${t}\` to be a finite number.`);if(e<r)throw new s(`Expected \`${t}\` to be \u2265 ${r}.`)}class u extends a{name="AsyncRetryAbortError";cause;constructor(t){if(super("string"==typeof t?t:e.extractErrorMessage(t,!1)??"Aborted"),"string"==typeof t){const e=new a(t);e.stack=this.stack,this.cause=e}else t instanceof a?(this.cause=t,this.message=t.message):this.cause=t}}async function m(e,o,a,c,m){if(e instanceof u)throw e.cause;if(e instanceof s&&!r.isNetworkError(e)||t.isAbortErrorLike(e))throw e;const f=a.retries-(o-1),w={error:e,attemptNumber:o,retriesLeft:f};await a.onFailedAttempt(w),o>1&&await a.onRetry(e,o-1);const h=Date.now();if(h-c>=m||o>=a.retries+1||!await a.shouldRetry(w))throw e;let d=n((a.randomize?Math.random()+1:1)*a.minTimeout*a.factor**(o-1));d>a.maxTimeout&&(d=a.maxTimeout);const b=m-(h-c);if(b<=0)throw e;let x=d;d>b&&(x=b),x>0&&await i.waitWithAbort(x,a.signal,a.unref),a.signal?.throwIfAborted()}function f(t){throw new u(t??"Aborted")}async function w(t,e={}){e.signal?.throwIfAborted();const r={...e};r.retries??=10,r.forever??=!1,r.factor??=2,r.minTimeout??=1e3,r.maxTimeout??=1/0,r.randomize??=!0,r.onFailedAttempt??=o.noop,r.onRetry??=o.noop,r.shouldRetry??=o.trueFn,r.forever&&(r.retries=1/0),c("retries",r.retries,0,!0),c("factor",r.factor,0,!1),c("minTimeout",r.minTimeout,0,!1),c("maxTimeout",r.maxTimeout,0,!0);const i=r.maxRetryTime??1/0;c("maxRetryTime",i,0,!0),r.minTimeout<1&&(r.minTimeout=1),r.factor<=0&&(r.factor=1);let n=0;const s=Date.now();for(;n<r.retries+1;){n++;try{r.signal?.throwIfAborted();const e=await t(f,n);return r.signal?.throwIfAborted(),e}catch(e){let t=e;"object"==typeof e&&e&&"bail"in e&&e.bail&&(t=new u(e)),await m(t,n,r,s,i)}}throw new a("Retry attempts exhausted without throwing an error.")}exports.AsyncRetryAbortError=u,exports.asyncRetry=w,exports.makeRetriable=function(t,e){return function(...r){return w(()=>t.apply(this,r),e)}};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{isAbortErrorLike as t}from"../abort-error/index.mjs";import{extractErrorMessage as e}from"../extract-error-message/index.mjs";import{isNetworkError as r}from"../is-network-error/index.mjs";import{noop as o,trueFn as
|
|
1
|
+
import{isAbortErrorLike as t}from"../abort-error/index.mjs";import{extractErrorMessage as e}from"../extract-error-message/index.mjs";import{isNetworkError as r}from"../is-network-error/index.mjs";import{noop as o,trueFn as i}from"../noop/index.mjs";import{waitWithAbort as n}from"../wait/index.mjs";const{round:a}=Math,s=Error,m=TypeError;function c(t,e,r=0,o=!1){if(Number.isNaN(e))throw new m(`Expected \`${t}\` to be a valid number${o?" or Infinity":""}, got NaN.`);if(!o&&!Number.isFinite(e))throw new m(`Expected \`${t}\` to be a finite number.`);if(e<r)throw new m(`Expected \`${t}\` to be \u2265 ${r}.`)}class f extends s{name="AsyncRetryAbortError";cause;constructor(t){if(super("string"==typeof t?t:e(t,!1)??"Aborted"),"string"==typeof t){const e=new s(t);e.stack=this.stack,this.cause=e}else t instanceof s?(this.cause=t,this.message=t.message):this.cause=t}}async function u(e,o,i,s,c){if(e instanceof f)throw e.cause;if(e instanceof m&&!r(e)||t(e))throw e;const u=i.retries-(o-1),w={error:e,attemptNumber:o,retriesLeft:u};await i.onFailedAttempt(w),o>1&&await i.onRetry(e,o-1);const h=Date.now();if(h-s>=c||o>=i.retries+1||!await i.shouldRetry(w))throw e;let d=a((i.randomize?Math.random()+1:1)*i.minTimeout*i.factor**(o-1));d>i.maxTimeout&&(d=i.maxTimeout);const y=c-(h-s);if(y<=0)throw e;let b=d;d>y&&(b=y),b>0&&await n(b,i.signal,i.unref),i.signal?.throwIfAborted()}function w(t){throw new f(t??"Aborted")}async function h(t,e={}){e.signal?.throwIfAborted();const r={...e};r.retries??=10,r.forever??=!1,r.factor??=2,r.minTimeout??=1e3,r.maxTimeout??=1/0,r.randomize??=!0,r.onFailedAttempt??=o,r.onRetry??=o,r.shouldRetry??=i,r.forever&&(r.retries=1/0),c("retries",r.retries,0,!0),c("factor",r.factor,0,!1),c("minTimeout",r.minTimeout,0,!1),c("maxTimeout",r.maxTimeout,0,!0);const n=r.maxRetryTime??1/0;c("maxRetryTime",n,0,!0),r.minTimeout<1&&(r.minTimeout=1),r.factor<=0&&(r.factor=1);let a=0;const m=Date.now();for(;a<r.retries+1;){a++;try{r.signal?.throwIfAborted();const e=await t(w,a);return r.signal?.throwIfAborted(),e}catch(e){let t=e;"object"==typeof e&&e&&"bail"in e&&e.bail&&(t=new f(e)),await u(t,a,r,m,n)}}throw new s("Retry attempts exhausted without throwing an error.")}function d(t,e){return function(...r){return h(()=>t.apply(this,r),e)}}export{f as AsyncRetryAbortError,h as asyncRetry,d as makeRetriable};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const e=Object.prototype.toString,
|
|
1
|
+
"use strict";const e=Object.prototype.toString,t=new Set(["network error","NetworkError when attempting to fetch resource.","The Internet connection appears to be offline.","Network request failed","fetch failed","terminated"," A network error occurred.","Network connection lost"]),r=new Set(["ETIMEDOUT","ECONNRESET","ECONNREFUSED","ENOTFOUND","ENETDOWN","ENETUNREACH","EHOSTDOWN","EHOSTUNREACH","EPIPE","UND_ERR_SOCKET","UND_ERR_HEADERS_TIMEOUT"]);exports.isNetworkError=function(o){if("object"!=typeof o||null==o)return!1;if("code"in o&&"string"==typeof o.code){if("ERR_UNESCAPED_CHARACTERS"===o.code)return!1;if(r.has(o.code))return!0}if(!(o&&"[object Error]"===e.call(o)&&"TypeError"===o.name&&"string"==typeof o.message))return!1;const{message:n,stack:E}=o;return"Load failed"===n?void 0===E||"__sentry_captured__"in o:!!(n.startsWith("error sending request for url")||"Failed to fetch"===n||n.startsWith("Failed to fetch (")&&n.endsWith(")"))||t.has(n)};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=Object.prototype.toString,
|
|
1
|
+
const e=Object.prototype.toString,t=new Set(["network error","NetworkError when attempting to fetch resource.","The Internet connection appears to be offline.","Network request failed","fetch failed","terminated"," A network error occurred.","Network connection lost"]),r=new Set(["ETIMEDOUT","ECONNRESET","ECONNREFUSED","ENOTFOUND","ENETDOWN","ENETUNREACH","EHOSTDOWN","EHOSTUNREACH","EPIPE","UND_ERR_SOCKET","UND_ERR_HEADERS_TIMEOUT"]);function o(o){if("object"!=typeof o||null==o)return!1;if("code"in o&&"string"==typeof o.code){if("ERR_UNESCAPED_CHARACTERS"===o.code)return!1;if(r.has(o.code))return!0}if(!(o&&"[object Error]"===e.call(o)&&"TypeError"===o.name&&"string"==typeof o.message))return!1;const{message:n,stack:E}=o;return"Load failed"===n?void 0===E||"__sentry_captured__"in o:!!(n.startsWith("error sending request for url")||"Failed to fetch"===n||n.startsWith("Failed to fetch (")&&n.endsWith(")"))||t.has(n)}export{o as isNetworkError};
|
package/dist/literal/index.d.ts
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Resolve mapped types and show the derived keys and their types when hovering in
|
|
3
|
+
* VS Code, instead of just showing the names those mapped types are defined with.
|
|
4
|
+
*/
|
|
5
|
+
type DeepMutableWithPrettify<T> = {
|
|
6
|
+
-readonly [P in keyof T]: DeepMutableWithPrettify<T[P]>;
|
|
7
|
+
} & {};
|
|
4
8
|
/**
|
|
5
9
|
* When you are returning some object/array literal from a function,
|
|
6
10
|
* TypeScript automatically widens the array to be more general, like
|
|
@@ -12,8 +16,8 @@ type DeepMutable<T> = {
|
|
|
12
16
|
* You can use `foxts/literal` to wrap your array to prevent TypeScript
|
|
13
17
|
* from widening the type in function return values.
|
|
14
18
|
*
|
|
15
|
-
* Playground Link: https://www.typescriptlang.org/play/?declaration=false&jsx=0#code/
|
|
19
|
+
* Playground Link: https://www.typescriptlang.org/play/?declaration=false&jsx=0#code/C4TwDgpgBAIhFgLIFdgEMBGAbCB1AlsABYAKAThMMPgGYgA8AKgHxQC8UA3gFBRQC0FNABMA9gDssIKAG0SUfOKgBrCCFE0ojALoAuWPCSpMOAsXKVqdJnO3MA3NwC+UAGRcnjiAA8wossBQAMYSAM6BWIQQZGhY7FD0IeLhWswAFABu+owAlPpwCCjo2HiEpBRUtAws7KwZjtygkFAAyujAyKEA8hgAVhBBgRycUOFoHaH6AIJkMQwA5KLK81AAPlCLomCh86ye3DTI4oP4EsFEA8ppimCo+m3jnT39gzlcwWGiOAB0WKIA5tdxLdgG99twAPQQhSSRTQUR9AaBADu+CwcQw8OU3CCFyCVxGYwm+hki2W2igThyDShUARL0CNDIogAtlBDsdqGcKsgyEpUej2Wg0TiwoEMPE0m82Kw0oT2p0SWT5hSqY5cZc0hgpdTuJDoRhUFBiPhQnTxNABRisaLkoEgpLpbL5Y9JlBIsBorE0qSliqwbqNfi0kEdTToSazRJLWjrXTlAAaY2iUS2lLCR21d1RGJYOWjBVu33kymBvFXYRhoA
|
|
16
20
|
*/
|
|
17
|
-
declare const literal: <const T>(v: T) =>
|
|
21
|
+
declare const literal: <const T extends object>(v: T) => DeepMutableWithPrettify<T>;
|
|
18
22
|
|
|
19
23
|
export { literal };
|
package/dist/wait/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
declare function wait(ms: number): Promise<void>;
|
|
2
|
-
declare function waitWithAbort(ms: number, signal: AbortSignal): Promise<void>;
|
|
1
|
+
declare function wait(ms: number, timerUnref?: boolean): Promise<void>;
|
|
2
|
+
declare function waitWithAbort(ms: number, signal: AbortSignal | undefined | null, timerUnref?: boolean): Promise<void>;
|
|
3
3
|
|
|
4
4
|
export { wait, waitWithAbort };
|
package/dist/wait/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";function e(t,n=!1){return new Promise(e=>{const o=setTimeout(e,t);n&&"object"==typeof o&&"unref"in o&&"function"==typeof o.unref&&o.unref()})}exports.wait=e,exports.waitWithAbort=function(t,n,o=!1){return n?new Promise((e,r)=>{if(n.aborted)return void r(n.reason);const i=setTimeout(()=>{n.removeEventListener("abort",u),e(),o&&"object"==typeof i&&"unref"in i&&"function"==typeof i.unref&&i.unref()},t);function u(){clearTimeout(i),n?.removeEventListener("abort",u),r(n?.reason)}n.addEventListener("abort",u,{once:!0})}):e(t,o)};
|
package/dist/wait/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
function e(
|
|
1
|
+
function e(t,n=!1){return new Promise(e=>{const o=setTimeout(e,t);n&&"object"==typeof o&&"unref"in o&&"function"==typeof o.unref&&o.unref()})}function t(n,o,r=!1){return o?new Promise((e,t)=>{if(o.aborted)return void t(o.reason);const i=setTimeout(()=>{o.removeEventListener("abort",u),e(),r&&"object"==typeof i&&"unref"in i&&"function"==typeof i.unref&&i.unref()},n);function u(){clearTimeout(i),o?.removeEventListener("abort",u),t(o?.reason)}o.addEventListener("abort",u,{once:!0})}):e(n,r)}export{e as wait,t as waitWithAbort};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "foxts",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.4.0",
|
|
4
4
|
"description": "Opinionated collection of common TypeScript utils by @SukkaW",
|
|
5
5
|
"repository": {
|
|
6
6
|
"url": "https://github.com/SukkaW/foxts"
|
|
@@ -332,31 +332,31 @@
|
|
|
332
332
|
"author": "SukkaW <https://skk.moe>",
|
|
333
333
|
"license": "MIT",
|
|
334
334
|
"devDependencies": {
|
|
335
|
-
"@eslint-sukka/node": "^8.
|
|
336
|
-
"@happy-dom/global-registrator": "^20.
|
|
335
|
+
"@eslint-sukka/node": "^8.7.0",
|
|
336
|
+
"@happy-dom/global-registrator": "^20.7.0",
|
|
337
337
|
"@istanbuljs/nyc-config-typescript": "^1.0.2",
|
|
338
338
|
"@mitata/counters": "^0.0.8",
|
|
339
|
-
"@monyone/aho-corasick": "^1.1.
|
|
339
|
+
"@monyone/aho-corasick": "^1.1.6",
|
|
340
340
|
"@package-json/types": "^0.0.12",
|
|
341
341
|
"@swc-node/register": "^1.11.1",
|
|
342
|
-
"@swc/core": "^1.15.
|
|
342
|
+
"@swc/core": "^1.15.17",
|
|
343
343
|
"@types/mocha": "^10.0.10",
|
|
344
|
-
"@types/node": "^22.19.
|
|
344
|
+
"@types/node": "^22.19.13",
|
|
345
345
|
"@types/sinon": "^21.0.0",
|
|
346
|
-
"bumpp": "^10.4.
|
|
346
|
+
"bumpp": "^10.4.1",
|
|
347
347
|
"earl": "^2.0.0",
|
|
348
|
-
"eslint": "^9.39.
|
|
349
|
-
"eslint-config-sukka": "^8.
|
|
350
|
-
"eslint-formatter-sukka": "^8.
|
|
348
|
+
"eslint": "^9.39.3",
|
|
349
|
+
"eslint-config-sukka": "^8.7.0",
|
|
350
|
+
"eslint-formatter-sukka": "^8.7.0",
|
|
351
351
|
"fastscan": "^1.0.6",
|
|
352
|
-
"happy-dom": "^20.
|
|
352
|
+
"happy-dom": "^20.7.0",
|
|
353
353
|
"is-ci": "^4.1.0",
|
|
354
|
-
"is-network-error": "^1.3.
|
|
354
|
+
"is-network-error": "^1.3.1",
|
|
355
355
|
"mitata": "^1.0.34",
|
|
356
356
|
"mocha": "^11.7.5",
|
|
357
357
|
"modern-ahocorasick": "^2.0.4",
|
|
358
358
|
"nyc": "^17.1.0",
|
|
359
|
-
"rollup": "^4.
|
|
359
|
+
"rollup": "^4.59.0",
|
|
360
360
|
"rollup-plugin-dts": "^6.3.0",
|
|
361
361
|
"rollup-plugin-oxc-resolve": "^0.0.5",
|
|
362
362
|
"rollup-plugin-swc3": "^0.12.1",
|