@ndriadev/futurable 2.3.2 → 2.3.5
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 +52 -0
- package/README.md +194 -549
- package/dist/index.cjs +1 -0
- package/dist/index.d.cts +255 -0
- package/dist/index.d.mts +255 -0
- package/dist/index.d.ts +10 -9
- package/dist/index.mjs +1 -0
- package/package.json +41 -39
- package/dist/example/index.d.ts +0 -2
- package/dist/example/index.d.ts.map +0 -1
- package/dist/futurable.cjs +0 -1
- package/dist/futurable.mjs +0 -437
- package/dist/index.d.ts.map +0 -1
- package/dist/index.test.d.ts +0 -2
- package/dist/index.test.d.ts.map +0 -1
- package/scripts/copy-resources.js +0 -37
- package/scripts/preInstall.js +0 -17
- package/scripts/server.js +0 -16
package/package.json
CHANGED
|
@@ -1,51 +1,39 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ndriadev/futurable",
|
|
3
|
-
"description": "
|
|
3
|
+
"description": "JavaScript's Promise and Fetch APIs with superpowers!",
|
|
4
4
|
"private": false,
|
|
5
|
-
"version": "2.3.
|
|
5
|
+
"version": "2.3.5",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"files": [
|
|
8
8
|
"dist/",
|
|
9
|
-
"
|
|
9
|
+
"README.md",
|
|
10
|
+
"LICENSE",
|
|
11
|
+
"CHANGELOG.md"
|
|
10
12
|
],
|
|
11
13
|
"exports": {
|
|
12
14
|
".": {
|
|
13
15
|
"types": "./dist/index.d.ts",
|
|
14
|
-
"import": "./dist/
|
|
15
|
-
"require": "./dist/
|
|
16
|
+
"import": "./dist/index.mjs",
|
|
17
|
+
"require": "./dist/index.cjs"
|
|
16
18
|
}
|
|
17
19
|
},
|
|
18
|
-
"main": "./dist/
|
|
19
|
-
"module": "./dist/
|
|
20
|
+
"main": "./dist/index.cjs",
|
|
21
|
+
"module": "./dist/index.mjs",
|
|
20
22
|
"types": "./dist/index.d.ts",
|
|
21
|
-
"//scripts": {
|
|
22
|
-
"preinstall": "node ./scripts/preinstall.js --foreground-script",
|
|
23
|
-
"postinstall": "echo 'postinstall executed'"
|
|
24
|
-
},
|
|
25
23
|
"devDependencies": {
|
|
26
|
-
"@
|
|
24
|
+
"@eslint/eslintrc": "^3.3.0",
|
|
25
|
+
"@eslint/js": "^9.21.0",
|
|
27
26
|
"@jest/globals": "^29.7.0",
|
|
28
27
|
"@types/node": "^20.11.16",
|
|
29
|
-
"
|
|
30
|
-
"@typescript-eslint/parser": "^6.21.0",
|
|
31
|
-
"eslint": "^8.56.0",
|
|
32
|
-
"eslint-config-prettier": "^9.1.0",
|
|
33
|
-
"eslint-plugin-import": "^2.29.1",
|
|
34
|
-
"eslint-plugin-prettier": "^5.1.3",
|
|
35
|
-
"express": "^4.19.2",
|
|
28
|
+
"globals": "^16.0.0",
|
|
36
29
|
"jest": "^29.7.0",
|
|
37
30
|
"prettier": "^3.2.5",
|
|
31
|
+
"rimraf": "^6.1.2",
|
|
38
32
|
"ts-jest": "^29.1.2",
|
|
39
|
-
"ts-node": "^10.9.2",
|
|
40
|
-
"typedoc": "^0.25.7",
|
|
41
|
-
"typedoc-material-theme": "^1.0.2",
|
|
42
|
-
"typedoc-plugin-extras": "^3.0.0",
|
|
43
|
-
"typedoc-plugin-keywords": "^1.6.0",
|
|
44
33
|
"typescript": "^5.3.3",
|
|
45
|
-
"
|
|
46
|
-
"
|
|
47
|
-
"
|
|
48
|
-
"vite-tsconfig-paths": "^4.3.1"
|
|
34
|
+
"typescript-eslint": "^8.26.0",
|
|
35
|
+
"unbuild": "^2.0.0",
|
|
36
|
+
"vitepress": "^1.0.0"
|
|
49
37
|
},
|
|
50
38
|
"keywords": [
|
|
51
39
|
"promise",
|
|
@@ -63,7 +51,11 @@
|
|
|
63
51
|
"sleep",
|
|
64
52
|
"abortable",
|
|
65
53
|
"cancelable",
|
|
66
|
-
"
|
|
54
|
+
"cancellable",
|
|
55
|
+
"futurable",
|
|
56
|
+
"fetch",
|
|
57
|
+
"polling",
|
|
58
|
+
"timeout"
|
|
67
59
|
],
|
|
68
60
|
"repository": {
|
|
69
61
|
"type": "git",
|
|
@@ -78,18 +70,28 @@
|
|
|
78
70
|
"bugs": {
|
|
79
71
|
"url": "https://github.com/nDriaDev/futurable/issues"
|
|
80
72
|
},
|
|
81
|
-
"homepage": "https://
|
|
73
|
+
"homepage": "https://futurable.ndria.dev",
|
|
82
74
|
"license": "MIT",
|
|
83
75
|
"scripts": {
|
|
84
|
-
"
|
|
76
|
+
"dev": "unbuild --stub",
|
|
85
77
|
"test": "NODE_OPTIONS=--experimental-vm-modules jest",
|
|
86
|
-
"
|
|
87
|
-
"
|
|
88
|
-
"
|
|
89
|
-
"
|
|
90
|
-
"
|
|
91
|
-
"
|
|
92
|
-
"
|
|
93
|
-
"preview": "
|
|
78
|
+
"test:coverage": "NODE_OPTIONS=--experimental-vm-modules jest --coverage",
|
|
79
|
+
"test:run": "NODE_OPTIONS=--experimental-vm-modules jest",
|
|
80
|
+
"lint": "eslint .",
|
|
81
|
+
"lint:fix": "eslint . --fix",
|
|
82
|
+
"typecheck": "tsc --noEmit",
|
|
83
|
+
"docs:dev": "vitepress dev docs",
|
|
84
|
+
"docs:build": "vitepress build docs",
|
|
85
|
+
"docs:preview": "vitepress preview docs",
|
|
86
|
+
"clean": "rimraf dist coverage docs/.vitepress/dist docs/.vitepress/cache",
|
|
87
|
+
"prebuild": "pnpm run clean",
|
|
88
|
+
"build": "unbuild",
|
|
89
|
+
"postbuild": "node scripts/verify-build.js",
|
|
90
|
+
"changelog": "node scripts/generate-changelog.js",
|
|
91
|
+
"release:patch": "bash scripts/release.sh patch",
|
|
92
|
+
"release:minor": "bash scripts/release.sh minor",
|
|
93
|
+
"release:major": "bash scripts/release.sh major",
|
|
94
|
+
"postversion": "git push && git push --tags",
|
|
95
|
+
"version": "pnpm run changelog && git add CHANGELOG.md"
|
|
94
96
|
}
|
|
95
97
|
}
|
package/dist/example/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/example/index.ts"],"names":[],"mappings":""}
|
package/dist/futurable.cjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";var T=Object.defineProperty;var C=(u,m,t)=>m in u?T(u,m,{enumerable:!0,configurable:!0,writable:!0,value:t}):u[m]=t;var S=(u,m,t)=>(C(u,typeof m!="symbol"?m+"":m,t),t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});class l extends Promise{constructor(t,e){const c=e?null:new AbortController,n=e||c.signal,o=[],r=()=>{for(const s of o)clearTimeout(s)};let i;const a={signal:n,cancel:()=>{var s;return(s=this.controller)==null?void 0:s.abort()},onCancel:s=>{i=s},delay:(s,f)=>new l(w=>{o.push(setTimeout(()=>{w(s())},f))},n),sleep:s=>a.delay(()=>{},s),fetch:(s,f)=>new l((w,j)=>{fetch(s,{...f||{},signal:n}).then(y=>w(y)).catch(y=>{y.name!=="AbortError"&&j(y)})},n),futurizable:s=>new l((f,w)=>{s.then(f).catch(w)},n)};let d="pending";const g=new Promise((s,f)=>{if(n.aborted){r();return}else{const w=typeof n.onabort=="function"?n.onabort:()=>{};n.onabort=()=>{w(),r(),d==="pending"&&i&&i()},t(p=>{d="fulfilled",s(p)},p=>{d="rejected",f(p)},a)}});super((s,f)=>{g.then(w=>s(w)).catch(f)});S(this,"controller");S(this,"internalSignal");S(this,"idsTimeout");this.controller=c,this.internalSignal=n,this.idsTimeout=o}static get[Symbol.species](){return this}get[Symbol.toStringTag](){return"Futurable"}get signal(){return this.internalSignal}clearTimeout(){for(const t of this.idsTimeout)clearTimeout(t)}then(t,e){let c,n;const o=new l((r,i)=>{c=r,n=i},this.internalSignal);return o.controller=this.controller,super.then(r=>{var i;if((i=this.internalSignal)!=null&&i.aborted){this.clearTimeout();return}try{c(t?t(r):r)}catch(h){n(h)}},r=>{var i;if((i=this.internalSignal)!=null&&i.aborted){this.clearTimeout();return}try{e?c(e(r)):n(r)}catch(h){n(h)}}),o}catch(t){return this.then(null,t)}finally(t){return this.then(e=>(t(),e),e=>{if(t(),e instanceof Error)throw e;return e})}cancel(){var t,e;!((t=this.internalSignal)!=null&&t.aborted)&&((e=this.controller)==null||e.abort())}delay(t,e){let c,n;const o=new l((r,i)=>{c=r,n=i},this.internalSignal);return o.controller=this.controller,this.then(r=>{this.idsTimeout.push(setTimeout(()=>c(t(r)),e))},r=>{n(r)}),o}sleep(t){return this.delay(e=>e,t)}fetch(t,e){let c,n;const o=new l((r,i)=>{c=r,n=i},this.internalSignal);return o.controller=this.controller,this.then(r=>{const i=typeof t=="function"?t(r):t,h={...typeof e=="function"?e(r):e,signal:this.internalSignal};fetch(i,h).then(a=>c(a)).catch(a=>{a.name!=="AbortError"&&n(a)})}),o}onCancel(t){let e,c;const n=new l((o,r,i)=>{i.onCancel(t),e=o,c=r},this.internalSignal);return n.controller=this.controller,this.then(o=>e(o),o=>c(o)),n}futurizable(t){let e,c;const n=new l((o,r)=>{e=o,c=r},this.internalSignal);return n.controller=this.controller,this.then(o=>{(typeof t=="function"?t(o):t).then(e).catch(c)}),n}static resolve(t,e){return t?new l(c=>c(t),e):new l(c=>c(),e)}static reject(t,e){return new l((c,n)=>n(t),e)}static onCancel({cb:t,signal:e}){return new l((c,n,o)=>{o.onCancel(()=>c(t()))},e)}static delay({cb:t,timer:e,signal:c}){return new l((n,o,r)=>{r.delay(t,e).then(n,o)},c)}static sleep({timer:t,signal:e}){return l.delay({cb:()=>{},timer:t,signal:e})}static fetch(t,e){const c=(e==null?void 0:e.signal)||void 0;return e!=null&&e.signal&&delete e.signal,new l((n,o,r)=>{r.fetch(t,e).then(n).catch(o)},c)}static futurizable({promise:t,signal:e}){return new l((c,n)=>{t.then(c).catch(n)},e)}static handleValues(t,e){const c=[];for(const n in t)t[n]instanceof l?c.push(t[n]):t[n]instanceof Promise?c.push(new l((o,r)=>{t[n].then(i=>o(i)).catch(r)},e)):c.push(new l(o=>o(t[n]),e));return c}static all(t,e){let c,n;const o=new l((i,h,a)=>{c=i,n=h,a.onCancel(()=>{for(const d of r)d.cancel()})},e);e||(e=o.internalSignal);const r=l.handleValues(t,e);return super.all(r).then(i=>c(i)).catch(i=>n(i)),o}static allSettled(t,e){let c;const n=new l((r,i,h)=>{c=r,h.onCancel(()=>{for(const a of o)a.cancel()})},e);e||(e=n.internalSignal);const o=l.handleValues(t,e);return super.allSettled(o).then(r=>c(r)),n}static race(t,e){let c,n;const o=new l((i,h,a)=>{c=i,n=h,a.onCancel(()=>{for(const d of r)d.cancel()})},e);e||(e=o.internalSignal);const r=l.handleValues(t,e);return super.race(r).then(i=>c(i)).catch(i=>n(i)),o}static any(t,e){let c,n;const o=new l((i,h,a)=>{c=i,n=h,a.onCancel(()=>{for(const d of r)d.cancel()})},e);e||(e=o.internalSignal);const r=l.handleValues(t,e);return super.any(r).then(i=>c(i)).catch(i=>n(i)),o}static polling(t,{interval:e,signal:c,immediate:n}){let o,r,i;n&&(o=new l((a,d,g)=>{g.onCancel(()=>{r&&r instanceof l&&r.cancel()});const s=t();(s instanceof l||s instanceof Promise)&&(r=s.then(()=>a()).catch(f=>i&&i(f)))},c));const h=setInterval(()=>{o&&o.cancel(),o=new l((a,d,g)=>{g.onCancel(()=>{r&&r instanceof l&&r.cancel()});const s=t();(s instanceof l||s instanceof Promise)&&(r=s.then(()=>a()).catch(f=>i&&i(f)))},c)},e);return{cancel:()=>{h&&clearInterval(h),o&&o.cancel()},catch:a=>{i=a}}}static withResolvers(t){let e,c,n;const o=new l((i,h,a)=>{e=i,c=h,n=a},t),r=o.cancel;return{resolve:e,reject:c,utils:n,cancel:r,promise:o}}}exports.Futurable=l;
|
package/dist/futurable.mjs
DELETED
|
@@ -1,437 +0,0 @@
|
|
|
1
|
-
var T = Object.defineProperty;
|
|
2
|
-
var C = (g, m, t) => m in g ? T(g, m, { enumerable: !0, configurable: !0, writable: !0, value: t }) : g[m] = t;
|
|
3
|
-
var S = (g, m, t) => (C(g, typeof m != "symbol" ? m + "" : m, t), t);
|
|
4
|
-
class s extends Promise {
|
|
5
|
-
constructor(t, e) {
|
|
6
|
-
const c = e ? null : new AbortController(), n = e || c.signal, o = [], r = () => {
|
|
7
|
-
for (const l of o)
|
|
8
|
-
clearTimeout(l);
|
|
9
|
-
};
|
|
10
|
-
let i;
|
|
11
|
-
const a = {
|
|
12
|
-
signal: n,
|
|
13
|
-
cancel: () => {
|
|
14
|
-
var l;
|
|
15
|
-
return (l = this.controller) == null ? void 0 : l.abort();
|
|
16
|
-
},
|
|
17
|
-
onCancel: (l) => {
|
|
18
|
-
i = l;
|
|
19
|
-
},
|
|
20
|
-
delay: (l, f) => new s((w) => {
|
|
21
|
-
o.push(setTimeout(() => {
|
|
22
|
-
w(l());
|
|
23
|
-
}, f));
|
|
24
|
-
}, n),
|
|
25
|
-
sleep: (l) => a.delay(() => {
|
|
26
|
-
}, l),
|
|
27
|
-
fetch: (l, f) => new s((w, j) => {
|
|
28
|
-
fetch(l, { ...f || {}, signal: n }).then((u) => w(u)).catch((u) => {
|
|
29
|
-
u.name !== "AbortError" && j(u);
|
|
30
|
-
});
|
|
31
|
-
}, n),
|
|
32
|
-
futurizable: (l) => new s((f, w) => {
|
|
33
|
-
l.then(f).catch(w);
|
|
34
|
-
}, n)
|
|
35
|
-
};
|
|
36
|
-
let d = "pending";
|
|
37
|
-
const y = new Promise((l, f) => {
|
|
38
|
-
if (n.aborted) {
|
|
39
|
-
r();
|
|
40
|
-
return;
|
|
41
|
-
} else {
|
|
42
|
-
const w = typeof n.onabort == "function" ? n.onabort : () => {
|
|
43
|
-
};
|
|
44
|
-
n.onabort = () => {
|
|
45
|
-
w(), r(), d === "pending" && i && i();
|
|
46
|
-
}, t((p) => {
|
|
47
|
-
d = "fulfilled", l(p);
|
|
48
|
-
}, (p) => {
|
|
49
|
-
d = "rejected", f(p);
|
|
50
|
-
}, a);
|
|
51
|
-
}
|
|
52
|
-
});
|
|
53
|
-
super((l, f) => {
|
|
54
|
-
y.then((w) => l(w)).catch(f);
|
|
55
|
-
});
|
|
56
|
-
S(this, "controller");
|
|
57
|
-
S(this, "internalSignal");
|
|
58
|
-
S(this, "idsTimeout");
|
|
59
|
-
this.controller = c, this.internalSignal = n, this.idsTimeout = o;
|
|
60
|
-
}
|
|
61
|
-
static get [Symbol.species]() {
|
|
62
|
-
return this;
|
|
63
|
-
}
|
|
64
|
-
get [Symbol.toStringTag]() {
|
|
65
|
-
return "Futurable";
|
|
66
|
-
}
|
|
67
|
-
/**
|
|
68
|
-
* Return internal futurable signal
|
|
69
|
-
* @returns {AbortSignal}
|
|
70
|
-
*/
|
|
71
|
-
get signal() {
|
|
72
|
-
return this.internalSignal;
|
|
73
|
-
}
|
|
74
|
-
clearTimeout() {
|
|
75
|
-
for (const t of this.idsTimeout)
|
|
76
|
-
clearTimeout(t);
|
|
77
|
-
}
|
|
78
|
-
/**
|
|
79
|
-
* Attaches callbacks for the resolution and/or rejection of the Futurable.
|
|
80
|
-
* @param {((value: T) => TResult1 | PromiseLike<TResult1> | FuturableLike<TResult1>) | undefined | null} onfulfilled
|
|
81
|
-
* @param {((reason: any) => TResult2 | PromiseLike<TResult2> | FuturableLike<TResult2>) | undefined | null} onrejected
|
|
82
|
-
* @returns {Futurable<TResult1 | TResult2>}
|
|
83
|
-
*/
|
|
84
|
-
then(t, e) {
|
|
85
|
-
let c, n;
|
|
86
|
-
const o = new s((r, i) => {
|
|
87
|
-
c = r, n = i;
|
|
88
|
-
}, this.internalSignal);
|
|
89
|
-
return o.controller = this.controller, super.then((r) => {
|
|
90
|
-
var i;
|
|
91
|
-
if ((i = this.internalSignal) != null && i.aborted) {
|
|
92
|
-
this.clearTimeout();
|
|
93
|
-
return;
|
|
94
|
-
}
|
|
95
|
-
try {
|
|
96
|
-
c(t ? t(r) : r);
|
|
97
|
-
} catch (h) {
|
|
98
|
-
n(h);
|
|
99
|
-
}
|
|
100
|
-
}, (r) => {
|
|
101
|
-
var i;
|
|
102
|
-
if ((i = this.internalSignal) != null && i.aborted) {
|
|
103
|
-
this.clearTimeout();
|
|
104
|
-
return;
|
|
105
|
-
}
|
|
106
|
-
try {
|
|
107
|
-
e ? c(e(r)) : n(r);
|
|
108
|
-
} catch (h) {
|
|
109
|
-
n(h);
|
|
110
|
-
}
|
|
111
|
-
}), o;
|
|
112
|
-
}
|
|
113
|
-
/**
|
|
114
|
-
* Attaches a callback for only the rejection of the Futurable.
|
|
115
|
-
* @param {((reason: any) => TResult2 | PromiseLike<TResult2> | FuturableLike<TResult2>) | undefined | null} onRejected
|
|
116
|
-
* @returns {Futurable<T | TResult2>}
|
|
117
|
-
*/
|
|
118
|
-
catch(t) {
|
|
119
|
-
return this.then(null, t);
|
|
120
|
-
}
|
|
121
|
-
/**
|
|
122
|
-
* Attaches a callback that is invoked when the Futurable is settled (fulfilled or rejected).
|
|
123
|
-
* The resolved value cannot be modified from the callback.
|
|
124
|
-
* @param {() => void | undefined | null} onfinally
|
|
125
|
-
* @returns {Futurable<T>}
|
|
126
|
-
*/
|
|
127
|
-
finally(t) {
|
|
128
|
-
return this.then(
|
|
129
|
-
(e) => (t(), e),
|
|
130
|
-
(e) => {
|
|
131
|
-
if (t(), e instanceof Error)
|
|
132
|
-
throw e;
|
|
133
|
-
return e;
|
|
134
|
-
}
|
|
135
|
-
);
|
|
136
|
-
}
|
|
137
|
-
/**
|
|
138
|
-
* Cancel the futurable if it is to be executed or if it is still executing.
|
|
139
|
-
*/
|
|
140
|
-
cancel() {
|
|
141
|
-
var t, e;
|
|
142
|
-
!((t = this.internalSignal) != null && t.aborted) && ((e = this.controller) == null || e.abort());
|
|
143
|
-
}
|
|
144
|
-
/**
|
|
145
|
-
* Waits for timer, then executes callback with the futurable value and returns the result obtained from the invocation.
|
|
146
|
-
* @param {(val: T) => TResult1 | PromiseLike<TResult1> | FuturableLike<TResult1>} cb - callback executed after timer with futurable chain value as parameter
|
|
147
|
-
* @param {number} timer - timer to wait (in milliseconds)
|
|
148
|
-
*/
|
|
149
|
-
delay(t, e) {
|
|
150
|
-
let c, n;
|
|
151
|
-
const o = new s((r, i) => {
|
|
152
|
-
c = r, n = i;
|
|
153
|
-
}, this.internalSignal);
|
|
154
|
-
return o.controller = this.controller, this.then(
|
|
155
|
-
(r) => {
|
|
156
|
-
this.idsTimeout.push(setTimeout(() => c(t(r)), e));
|
|
157
|
-
},
|
|
158
|
-
(r) => {
|
|
159
|
-
n(r);
|
|
160
|
-
}
|
|
161
|
-
), o;
|
|
162
|
-
}
|
|
163
|
-
/**
|
|
164
|
-
* Waits for timer parameter (in milliseconds) before returning the value.
|
|
165
|
-
* @param {number} timer - timer to wait (in milliseconds)
|
|
166
|
-
* @returns {Futurable<T>}
|
|
167
|
-
*/
|
|
168
|
-
sleep(t) {
|
|
169
|
-
return this.delay((e) => e, t);
|
|
170
|
-
}
|
|
171
|
-
/**
|
|
172
|
-
* Extension of the fetch API with cancellation support. Url parameter can be a string or a function with receive value from futurable chaining as paremeter.
|
|
173
|
-
* @param {string| ((val?:T)=>string)} url - url to fetch or function with futurable chaining value that returns url to fetch
|
|
174
|
-
* @param {object | RequestInit | ((val?: T) => RequestInit)} opts - fetch options or function with futurable chaining value that return fetch options
|
|
175
|
-
* @returns {Futurable<Response>}
|
|
176
|
-
*/
|
|
177
|
-
fetch(t, e) {
|
|
178
|
-
let c, n;
|
|
179
|
-
const o = new s((r, i) => {
|
|
180
|
-
c = r, n = i;
|
|
181
|
-
}, this.internalSignal);
|
|
182
|
-
return o.controller = this.controller, this.then((r) => {
|
|
183
|
-
const i = typeof t == "function" ? t(r) : t, h = { ...typeof e == "function" ? e(r) : e, signal: this.internalSignal };
|
|
184
|
-
fetch(i, h).then((a) => c(a)).catch((a) => {
|
|
185
|
-
a.name !== "AbortError" && n(a);
|
|
186
|
-
});
|
|
187
|
-
}), o;
|
|
188
|
-
}
|
|
189
|
-
/**
|
|
190
|
-
* Executes the callback passed as a parameter when the futurable is cancelled.
|
|
191
|
-
* @param {()=>void} cb
|
|
192
|
-
* @returns {Futurable<TResult1 | TResult2>}
|
|
193
|
-
*/
|
|
194
|
-
onCancel(t) {
|
|
195
|
-
let e, c;
|
|
196
|
-
const n = new s((o, r, i) => {
|
|
197
|
-
i.onCancel(t), e = o, c = r;
|
|
198
|
-
}, this.internalSignal);
|
|
199
|
-
return n.controller = this.controller, this.then(
|
|
200
|
-
(o) => e(o),
|
|
201
|
-
(o) => c(o)
|
|
202
|
-
), n;
|
|
203
|
-
}
|
|
204
|
-
/**
|
|
205
|
-
* Takes a promise and transforms it into a futurizable. Promise can be also a function that receives value from futurable chaining as parameter.
|
|
206
|
-
* @param {Promise<TResult1> | ((val?: T) => Promise<TResult1>)} promise - Promise to futurize or function that return promise with futurable chaining value as parameter
|
|
207
|
-
* @returns {Futurable<TResult1 | TResult2>}
|
|
208
|
-
*/
|
|
209
|
-
futurizable(t) {
|
|
210
|
-
let e, c;
|
|
211
|
-
const n = new s((o, r) => {
|
|
212
|
-
e = o, c = r;
|
|
213
|
-
}, this.internalSignal);
|
|
214
|
-
return n.controller = this.controller, this.then((o) => {
|
|
215
|
-
(typeof t == "function" ? t(o) : t).then(e).catch(c);
|
|
216
|
-
}), n;
|
|
217
|
-
}
|
|
218
|
-
/**
|
|
219
|
-
* @param {T | PromiseLike<T> | FuturableLike<T>} [value]
|
|
220
|
-
* @param {AbortSignal} [signal]
|
|
221
|
-
* @returns {Futurable<T|void>}
|
|
222
|
-
*/
|
|
223
|
-
static resolve(t, e) {
|
|
224
|
-
return t ? new s((c) => c(t), e) : new s((c) => c(), e);
|
|
225
|
-
}
|
|
226
|
-
/**
|
|
227
|
-
* Creates a new rejected futurable for the provided reason.
|
|
228
|
-
* @param {any} [reason]
|
|
229
|
-
* @param {AbortSignal} [signal]
|
|
230
|
-
* @returns {Futurable<T>}
|
|
231
|
-
*/
|
|
232
|
-
static reject(t, e) {
|
|
233
|
-
return new s((c, n) => n(t), e);
|
|
234
|
-
}
|
|
235
|
-
/**
|
|
236
|
-
* OnCancel static method. It accepts a callback or a object with cb property and an optional signal.
|
|
237
|
-
* @param {{cb: () => T, signal: AbortSignal|undefined}} options
|
|
238
|
-
* @returns {Futurable<T>}
|
|
239
|
-
*/
|
|
240
|
-
static onCancel({ cb: t, signal: e }) {
|
|
241
|
-
return new s((c, n, o) => {
|
|
242
|
-
o.onCancel(() => c(t()));
|
|
243
|
-
}, e);
|
|
244
|
-
}
|
|
245
|
-
/**
|
|
246
|
-
* Delay static method. It accepts a object with timer and cb properties and an optional signal property.
|
|
247
|
-
* @param {{cb: () => T, timer: number, signal: AbortSignal|undefined}} options
|
|
248
|
-
* @returns {Futurable<T|TResult2>}
|
|
249
|
-
*/
|
|
250
|
-
static delay({ cb: t, timer: e, signal: c }) {
|
|
251
|
-
return new s((n, o, r) => {
|
|
252
|
-
r.delay(t, e).then(n, o);
|
|
253
|
-
}, c);
|
|
254
|
-
}
|
|
255
|
-
/**
|
|
256
|
-
* Sleep static method. It accepts a timer or a object with timer property and an optional signal.
|
|
257
|
-
* @param {{timer: number, signal: AbortSignal|undefined}} options
|
|
258
|
-
* @returns {Futurable<void>}
|
|
259
|
-
*/
|
|
260
|
-
static sleep({ timer: t, signal: e }) {
|
|
261
|
-
return s.delay({
|
|
262
|
-
cb: () => {
|
|
263
|
-
},
|
|
264
|
-
timer: t,
|
|
265
|
-
signal: e
|
|
266
|
-
});
|
|
267
|
-
}
|
|
268
|
-
/**
|
|
269
|
-
* Fetch static method.
|
|
270
|
-
* @param {string} url
|
|
271
|
-
* @param {RequestInit} [opts]
|
|
272
|
-
* @returns {Futurable<Response>}
|
|
273
|
-
*/
|
|
274
|
-
static fetch(t, e) {
|
|
275
|
-
const c = (e == null ? void 0 : e.signal) || void 0;
|
|
276
|
-
return e != null && e.signal && delete e.signal, new s((n, o, r) => {
|
|
277
|
-
r.fetch(t, e).then(n).catch(o);
|
|
278
|
-
}, c);
|
|
279
|
-
}
|
|
280
|
-
/**
|
|
281
|
-
* Futurizable static method.
|
|
282
|
-
* @param {{promise: Promise<TResult1>, signal: AbortSignal|undefined}} options
|
|
283
|
-
* @returns {Futurable<TResult1 | TResult2>}
|
|
284
|
-
*/
|
|
285
|
-
static futurizable({ promise: t, signal: e }) {
|
|
286
|
-
return new s((c, n) => {
|
|
287
|
-
t.then(c).catch(n);
|
|
288
|
-
}, e);
|
|
289
|
-
}
|
|
290
|
-
static handleValues(t, e) {
|
|
291
|
-
const c = [];
|
|
292
|
-
for (const n in t)
|
|
293
|
-
t[n] instanceof s ? c.push(t[n]) : t[n] instanceof Promise ? c.push(
|
|
294
|
-
new s(
|
|
295
|
-
(o, r) => {
|
|
296
|
-
t[n].then((i) => o(i)).catch(r);
|
|
297
|
-
},
|
|
298
|
-
e
|
|
299
|
-
)
|
|
300
|
-
) : c.push(
|
|
301
|
-
new s(
|
|
302
|
-
(o) => o(t[n]),
|
|
303
|
-
e
|
|
304
|
-
)
|
|
305
|
-
);
|
|
306
|
-
return c;
|
|
307
|
-
}
|
|
308
|
-
/**
|
|
309
|
-
* Creates a Futurable with cancellation support that is resolved with an array of results when all of the provided Futurables resolve, or rejected when any Futurable is rejected.
|
|
310
|
-
* @param {T} values
|
|
311
|
-
* @param {AbortSignal} [signal]
|
|
312
|
-
* @returns {Futurable<{ -readonly [P in keyof T]: Awaited<T[P]>; }>}
|
|
313
|
-
*/
|
|
314
|
-
static all(t, e) {
|
|
315
|
-
let c, n;
|
|
316
|
-
const o = new s((i, h, a) => {
|
|
317
|
-
c = i, n = h, a.onCancel(() => {
|
|
318
|
-
for (const d of r)
|
|
319
|
-
d.cancel();
|
|
320
|
-
});
|
|
321
|
-
}, e);
|
|
322
|
-
e || (e = o.internalSignal);
|
|
323
|
-
const r = s.handleValues(t, e);
|
|
324
|
-
return super.all(r).then((i) => c(i)).catch((i) => n(i)), o;
|
|
325
|
-
}
|
|
326
|
-
/**
|
|
327
|
-
* Creates a Futurable with cancellation support that is resolved with an array of results when all of the provided Futurables resolve or reject.
|
|
328
|
-
* @param {T} values
|
|
329
|
-
* @param {AbortSignal} [signal]
|
|
330
|
-
* @returns {Futurable<{ -readonly [P in keyof T]: PromiseSettledResult<Awaited<T[P]>> }>}
|
|
331
|
-
*/
|
|
332
|
-
static allSettled(t, e) {
|
|
333
|
-
let c;
|
|
334
|
-
const n = new s((r, i, h) => {
|
|
335
|
-
c = r, h.onCancel(() => {
|
|
336
|
-
for (const a of o)
|
|
337
|
-
a.cancel();
|
|
338
|
-
});
|
|
339
|
-
}, e);
|
|
340
|
-
e || (e = n.internalSignal);
|
|
341
|
-
const o = s.handleValues(t, e);
|
|
342
|
-
return super.allSettled(o).then((r) => c(r)), n;
|
|
343
|
-
}
|
|
344
|
-
/**
|
|
345
|
-
* Creates a Futurable with cancellation support that is resolved or rejected when any of the provided Futurables are resolved or rejected.
|
|
346
|
-
* @param {T} values
|
|
347
|
-
* @param {AbortSignal} [signal]
|
|
348
|
-
* @returns {Futurable<Awaited<T[number]>>}
|
|
349
|
-
*/
|
|
350
|
-
static race(t, e) {
|
|
351
|
-
let c, n;
|
|
352
|
-
const o = new s((i, h, a) => {
|
|
353
|
-
c = i, n = h, a.onCancel(() => {
|
|
354
|
-
for (const d of r)
|
|
355
|
-
d.cancel();
|
|
356
|
-
});
|
|
357
|
-
}, e);
|
|
358
|
-
e || (e = o.internalSignal);
|
|
359
|
-
const r = s.handleValues(t, e);
|
|
360
|
-
return super.race(r).then((i) => c(i)).catch((i) => n(i)), o;
|
|
361
|
-
}
|
|
362
|
-
/**
|
|
363
|
-
* The any function returns a futurable with cancellation support that is fulfilled by the first given futurable to be fulfilled,
|
|
364
|
-
* or rejected with an AggregateError containing an array of rejection reasons if all of the
|
|
365
|
-
* given futurables are rejected. It resolves all elements of the passed iterable to futurables as
|
|
366
|
-
* it runs this algorithm.
|
|
367
|
-
* @param {T} values
|
|
368
|
-
* @param {AbortSignal} [signal]
|
|
369
|
-
* @returns {Futurable<Awaited<T[number]>>}
|
|
370
|
-
*/
|
|
371
|
-
static any(t, e) {
|
|
372
|
-
let c, n;
|
|
373
|
-
const o = new s((i, h, a) => {
|
|
374
|
-
c = i, n = h, a.onCancel(() => {
|
|
375
|
-
for (const d of r)
|
|
376
|
-
d.cancel();
|
|
377
|
-
});
|
|
378
|
-
}, e);
|
|
379
|
-
e || (e = o.internalSignal);
|
|
380
|
-
const r = s.handleValues(t, e);
|
|
381
|
-
return super.any(r).then((i) => c(i)).catch((i) => n(i)), o;
|
|
382
|
-
}
|
|
383
|
-
/**
|
|
384
|
-
* Creates a polling service with cancellation support and possibility to handle error. An optional param __immediate__ can be set _true_ if __fun__ must to be invoke immediatly.
|
|
385
|
-
* @param {()=> Futurable<T>} fun
|
|
386
|
-
* @param {{interval: number, signal?: AbortSignal, immediate?: boolean}} options
|
|
387
|
-
* @returns {{cancel: () => void, catch: (onrejected:(reason: unknown)=>void)=>void }}
|
|
388
|
-
*/
|
|
389
|
-
static polling(t, { interval: e, signal: c, immediate: n }) {
|
|
390
|
-
let o, r, i;
|
|
391
|
-
n && (o = new s((a, d, y) => {
|
|
392
|
-
y.onCancel(() => {
|
|
393
|
-
r && r instanceof s && r.cancel();
|
|
394
|
-
});
|
|
395
|
-
const l = t();
|
|
396
|
-
(l instanceof s || l instanceof Promise) && (r = l.then(() => a()).catch((f) => i && i(f)));
|
|
397
|
-
}, c));
|
|
398
|
-
const h = setInterval(() => {
|
|
399
|
-
o && o.cancel(), o = new s((a, d, y) => {
|
|
400
|
-
y.onCancel(() => {
|
|
401
|
-
r && r instanceof s && r.cancel();
|
|
402
|
-
});
|
|
403
|
-
const l = t();
|
|
404
|
-
(l instanceof s || l instanceof Promise) && (r = l.then(() => a()).catch((f) => i && i(f)));
|
|
405
|
-
}, c);
|
|
406
|
-
}, e);
|
|
407
|
-
return {
|
|
408
|
-
cancel: () => {
|
|
409
|
-
h && clearInterval(h), o && o.cancel();
|
|
410
|
-
},
|
|
411
|
-
catch: (a) => {
|
|
412
|
-
i = a;
|
|
413
|
-
}
|
|
414
|
-
};
|
|
415
|
-
}
|
|
416
|
-
/**
|
|
417
|
-
* Extension of _Promise.withResolvers_ static method. Creates a new Futurable and returns it in an object, along with its resolve, reject and cancel functions and utils object.
|
|
418
|
-
* @param {AbortSignal} [signal]
|
|
419
|
-
* @returns {{ resolve: null | FuturableResolve<T>, reject: null | FuturableReject, utils: null | FuturableUtils<T>, futurable: Futurable<T>, cancel: null | (() => void) }}
|
|
420
|
-
*/
|
|
421
|
-
static withResolvers(t) {
|
|
422
|
-
let e, c, n;
|
|
423
|
-
const o = new s((i, h, a) => {
|
|
424
|
-
e = i, c = h, n = a;
|
|
425
|
-
}, t), r = o.cancel;
|
|
426
|
-
return {
|
|
427
|
-
resolve: e,
|
|
428
|
-
reject: c,
|
|
429
|
-
utils: n,
|
|
430
|
-
cancel: r,
|
|
431
|
-
promise: o
|
|
432
|
-
};
|
|
433
|
-
}
|
|
434
|
-
}
|
|
435
|
-
export {
|
|
436
|
-
s as Futurable
|
|
437
|
-
};
|
package/dist/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,aAAa,CAAC,CAAC;IAC/B;;;;;OAKG;IACH,IAAI,CAAC,QAAQ,GAAG,CAAC,EAAE,QAAQ,GAAG,KAAK,EAClC,WAAW,CAAC,EAAE,CAAC,CAAC,KAAK,EAAE,CAAC,KAAK,QAAQ,GAAG,WAAW,CAAC,QAAQ,CAAC,GAAG,aAAa,CAAC,QAAQ,CAAC,CAAC,GAAG,SAAS,GAAG,IAAI,EAC3G,UAAU,CAAC,EAAE,CAAC,CAAC,MAAM,EAAE,GAAG,KAAK,QAAQ,GAAG,WAAW,CAAC,QAAQ,CAAC,GAAG,aAAa,CAAC,QAAQ,CAAC,CAAC,GAAG,SAAS,GAAG,IAAI,GAC3G,aAAa,CAAC,QAAQ,GAAG,QAAQ,CAAC,CAAC;CACtC;AACD,MAAM,WAAW,gBAAgB,CAAC,CAAC;IAClC,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,EAAE,WAAW,GAAG,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC;IAmB9G;;;;;;;;OAQG;IACH,MAAM,CAAC,GAAG,CAAC,CAAC,SAAS,SAAS,OAAO,EAAE,GAAG,EAAE,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC;IAmB7G;;;;;OAKG;IACH,MAAM,CAAC,OAAO,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,SAAS,CAAC,CAAC,CAAC,GAAC,OAAO,CAAC,CAAC,CAAC,GAAC,CAAC,EAAE,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,EAAE;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,WAAW,CAAC;QAAC,SAAS,CAAC,EAAE,OAAO,CAAA;KAAE,GAAG;QAAE,MAAM,EAAE,MAAM,IAAI,CAAC;QAAC,KAAK,EAAE,CAAC,UAAU,EAAE,CAAC,MAAM,EAAE,OAAO,KAAK,IAAI,KAAK,IAAI,CAAA;KAAE;IAgCzO;;;;OAIG;IACH,MAAM,CAAC,aAAa,CAAC,CAAC,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,sBAAsB,CAAC,CAAC,CAAC;CAkBxE"}
|
package/dist/index.test.d.ts
DELETED
package/dist/index.test.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.test.d.ts","sourceRoot":"","sources":["../src/index.test.ts"],"names":[],"mappings":""}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { readFile, readdir, writeFile } from 'fs/promises';
|
|
2
|
-
import path from 'path';
|
|
3
|
-
|
|
4
|
-
const __dirname = new URL('.', import.meta.url).pathname;
|
|
5
|
-
const IMAGES_PATH = path.join(__dirname, "..", "resources", "images");
|
|
6
|
-
const SEO_PATH = path.join(__dirname, "..", "resources", "seo");
|
|
7
|
-
const DOCS_PATH = path.join(__dirname, "..", "docs");
|
|
8
|
-
|
|
9
|
-
async function copy() {
|
|
10
|
-
try {
|
|
11
|
-
const [dir, dirSeo] = await Promise.all([
|
|
12
|
-
readdir(IMAGES_PATH),
|
|
13
|
-
readdir(SEO_PATH)
|
|
14
|
-
]);
|
|
15
|
-
for (const file of dir) {
|
|
16
|
-
const asset = await readFile(path.join(IMAGES_PATH, file));
|
|
17
|
-
await writeFile(path.join(DOCS_PATH, file), asset);
|
|
18
|
-
}
|
|
19
|
-
for (const file of dirSeo) {
|
|
20
|
-
if (file === "meta-tags.html") {
|
|
21
|
-
const asset = await readFile(path.join(SEO_PATH, file), { encoding: "utf8" });
|
|
22
|
-
let indexFile = await readFile(path.join(DOCS_PATH, "index.html"), {
|
|
23
|
-
encoding: "utf8"
|
|
24
|
-
});
|
|
25
|
-
indexFile = indexFile.split("<head>")[0] + "<head>" + asset.split("\n").filter((_, index, arr) => index !== 0 && index !== arr.length - 1).join("") + indexFile.split("<head>")[1];
|
|
26
|
-
await writeFile(path.join(DOCS_PATH, "index.html"), indexFile);
|
|
27
|
-
} else {
|
|
28
|
-
const asset = await readFile(path.join(SEO_PATH, file));
|
|
29
|
-
await writeFile(path.join(DOCS_PATH, file), asset);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
} catch (error) {
|
|
33
|
-
console.error(error);
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
copy();
|
package/scripts/preInstall.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
// import { exec } from 'child_process';
|
|
2
|
-
|
|
3
|
-
// const result = process.versions;
|
|
4
|
-
|
|
5
|
-
// if (result && result.node && parseInt(result.node) < 16) {
|
|
6
|
-
// exec("npm install node-fetch", (err, stdout, sterr) => {
|
|
7
|
-
// if (err) {
|
|
8
|
-
// console.log("err", err.message);
|
|
9
|
-
// process.exit(1);
|
|
10
|
-
// } else if (sterr) {
|
|
11
|
-
// console.log("stderr", sterr);
|
|
12
|
-
// process.exit(1);
|
|
13
|
-
// }
|
|
14
|
-
// console.log("stdout", stdout);
|
|
15
|
-
// process.exit(0);
|
|
16
|
-
// });
|
|
17
|
-
// }
|
package/scripts/server.js
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import express from 'express';
|
|
2
|
-
import path from 'path';
|
|
3
|
-
|
|
4
|
-
const __dirname = new URL('.', import.meta.url).pathname;
|
|
5
|
-
|
|
6
|
-
const app = express();
|
|
7
|
-
|
|
8
|
-
app.use(express.static(path.join((__dirname, "..", "docs"))));
|
|
9
|
-
|
|
10
|
-
app.get('/', (req, res) => {
|
|
11
|
-
return res.sendFile(path.join(__dirname, '..', 'docs', 'index.html'))
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
app.listen(4173, () => {
|
|
15
|
-
console.log("run");
|
|
16
|
-
});
|