@peter.naydenov/walk-async 7.0.1 → 7.0.2
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 +11 -0
- package/README.md +3 -0
- package/dist/walk-async.cjs +1 -1
- package/dist/walk-async.esm.mjs +396 -1
- package/dist/walk-async.umd.js +1 -1
- package/package.json +5 -9
- package/skills/README.md +108 -0
- package/skills/walk-async/SKILL.md +83 -0
- package/skills/walk-async/references/callbacks.md +135 -0
- package/skills/walk-async/references/control-flow.md +94 -0
- package/skills/walk-async/references/examples.md +252 -0
- package/skills/walk-async/references/settings.md +60 -0
- package/src/copyObject.js +7 -3
- package/src/main.js +21 -13
- package/src/runCallback.js +14 -7
- package/src/runTask.js +34 -0
- package/types/copyObject.d.ts +1 -6
- package/types/copyObject.d.ts.map +1 -1
- package/types/main.d.ts.map +1 -1
- package/types/runCallback.d.ts.map +1 -1
- package/types/runTask.d.ts +3 -0
- package/types/runTask.d.ts.map +1 -0
package/Changelog.md
CHANGED
|
@@ -2,6 +2,17 @@
|
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
|
|
5
|
+
### 7.0.2 (2026-10-31)
|
|
6
|
+
- [x] Dependency updates. Ask-for-promise to version 3.2.2;
|
|
7
|
+
- [x] Restore `ask-for-promise` for traversal and callback settlement, replacing the library's internal async/await implementation while keeping the current callback and error behavior;
|
|
8
|
+
- [x] Build: The build moved from Rollup to Vite. Vite builds with Rolldown and resolves the modules on its own. The 'rollup' and the three '@rollup/plugin-*' dev dependencies are gone;
|
|
9
|
+
- [x] Fix: '@rollup/plugin-node-resolve' was removed from the build. It was not needed, and its 'deepmerge' dependency had a prototype poisoning advisory with no fixed version;
|
|
10
|
+
- [x] Build: The build target is pinned to ES2015. The bundles carried the syntax of the source, so the output level was an accident. The target makes it a guarantee;
|
|
11
|
+
- [x] The UMD bundle calls the AMD loader with the standard 'define ( dependencies, factory )' signature. The AMD mock of the distribution test follows the signature now;
|
|
12
|
+
- [x] Test: The examples of the skill are run against the source and the shipped bundle. A change in the bundle that breaks a documented example fails the suite now;
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
5
16
|
### 7.0.1 (2026-10-16)
|
|
6
17
|
- [x] Dependency updates. Ask-for-promise to version 3.2.1;
|
|
7
18
|
|
package/README.md
CHANGED
|
@@ -66,6 +66,9 @@ The [benchmark script](https://github.com/PeterNaydenov/walk-async/blob/main/ben
|
|
|
66
66
|
|
|
67
67
|
## Installation
|
|
68
68
|
|
|
69
|
+
Walk Async uses `ask-for-promise` and requires a JavaScript runtime with
|
|
70
|
+
`WeakRef` support, including when using the bundled browser distributions.
|
|
71
|
+
|
|
69
72
|
```sh
|
|
70
73
|
npm install @peter.naydenov/walk-async
|
|
71
74
|
```
|
package/dist/walk-async.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";function e(e){return null
|
|
1
|
+
"use strict";function e(e){return e==null||e.nodeType?`simple`:Array.isArray(e)?`array`:typeof e==`object`?e instanceof Date||e instanceof RegExp||e instanceof Map||e instanceof Set||e instanceof WeakMap||e instanceof WeakSet||e instanceof ArrayBuffer||e instanceof DataView||ArrayBuffer.isView(e)?`simple`:`object`:`simple`}function t(e,t){if(!Array.isArray(t))return!1;let n=Number(e);return Number.isInteger(n)&&n>=0&&n<4294967295&&String(n)===e}function n(e,t,n){t===`__proto__`?Object.defineProperty(e,t,{value:n,enumerable:!0,writable:!0,configurable:!0}):e[t]=n}var r=new WeakSet;function i(e){let t=Object.freeze({value:e,hasValue:arguments.length>0});return r.add(t),t}function a(e){return r.has(e)}function o(e,t,n,r,a,o){return o.breadcrumbs&&o.parentPath?{value:e,key:t,breadcrumbs:r,parentPath:a,IGNORE:n,FINISH:i}:o.breadcrumbs?{value:e,key:t,breadcrumbs:r,IGNORE:n,FINISH:i}:o.parentPath?{value:e,key:t,parentPath:a,IGNORE:n,FINISH:i}:{value:e,key:t,IGNORE:n,FINISH:i}}var s=new WeakSet;function c(e){let t=Object.freeze({value:e,hasValue:arguments.length>0});return s.add(t),t}function l(e){return s.has(e)}var u=Symbol(`ignore___`);function d(){return u}function f(e){return e===u}function p(e){return e?h(e):m()}p.sequence=function(e,...t){let n=p(),r=[];function*i(e){for(let t of e)yield t}let a=i(e);function o(e,...t){e.done?n.done(r):Promise.resolve().then(()=>e.value(...t)).then(e=>{r.push(e),o(a.next(),...t,e)},e=>{n.cancel(e)})}try{o(a.next(),...t)}catch(e){n.cancel(e)}return n},p.all=function(e,...t){let n=p(),r=[],i;try{i=e.map((e,n)=>Promise.resolve().then(()=>typeof e==`function`?e(...t):e).then(e=>r[n]=e,e=>{throw e}))}catch(e){return n.cancel(e),n}return Promise.all(i).then(()=>n.done(r),e=>n.cancel(e)),n};function m(){let e,t,n=new Promise((n,r)=>{e=n,t=r}),r={promise:n,promises:null,_activeTimer:null,done:()=>{},cancel:()=>{},each:()=>{},onComplete:g(n),timeout:_()};return r.done=function(t){r._activeTimer!==null&&(clearTimeout(r._activeTimer),r._activeTimer=null),e(t)},r.cancel=function(e){r._activeTimer!==null&&(clearTimeout(r._activeTimer),r._activeTimer=null),t(e)},r.each=function(e,...t){e({value:null,done:r.done,cancel:r.cancel,timeout:(e,t)=>this.timeout(e,t)},void 0,...t)},r}function h(e){let t=e.map(e=>m()),n=t.map(e=>e.promise),r=Promise.all(n),i={promise:r,promises:t,_list:e,_activeTimer:null,done:()=>{},cancel:()=>{},each:()=>{},onComplete:g(r),timeout:_()};return i.done=function(e){this._activeTimer!==null&&(clearTimeout(this._activeTimer),this._activeTimer=null),this.promises.forEach(t=>t.done(e))},i.cancel=function(e){this._activeTimer!==null&&(clearTimeout(this._activeTimer),this._activeTimer=null),this.promises.forEach(t=>t.cancel(e))},i.each=function(e,...t){this.promises.forEach((n,r)=>e({value:this._list[r],done:n.done,cancel:n.cancel,timeout:(e,t)=>n.timeout(e,t)},r,...t))},i}function g(e){return function(t,n=null){n===null?e.then(e=>t(e)):e.then(e=>t(e),e=>n(e))}}function _(){return function(e,t){let n=this;n._activeTimer!==null&&clearTimeout(n._activeTimer);let r=setTimeout(()=>n.done(t),e);n._activeTimer=r;let i=()=>{clearTimeout(r),n._activeTimer===r&&(n._activeTimer=null)};return n.promise.then(i,i),n}}function v(e){let t=p();function n(r,i){let a;try{a=e[r](i)}catch(e){t.cancel(e);return}if(a.done){t.done(a.value);return}let o=p();o.done(a.value),o.promise.then(e=>n(`next`,e),e=>n(`throw`,e))}return n(`next`),t.promise}function y(e,t,n,r,...o){return v(s());function*s(){var s;let u,f,m=`${r} at '${(s=t.breadcrumbs)==null?t.key:s}'`;function h(){u||(u=p(),f=u.done,u.promise.catch(()=>{}))}Object.defineProperties(t,{resolve:{enumerable:!0,get:()=>(h(),f)},reject:{enumerable:!0,get:()=>(h(),()=>f(d()))}}),n.add(m);try{let n=yield e(t,...o),s=u?yield u.promise:n;return r===`objectCallback`&&l(s)&&s.hasValue?c(yield s.value):a(s)&&s.hasValue?i(yield s.value):s}finally{n.delete(m)}}}function b(r,i,s,u,p,m,h,g,_,b,w,T,...E){return v(D());function*D(){let[v,D]=u,O=Object.keys(r),k=m.detectCycles?{data:r,location:i,parent:b,depth:b?b.depth+1:0}:void 0,A=!1;w&&w.set(r,k);for(let u=0;u<O.length&&!A;u++){let b=O[u],j=r[b],M=e(j),N=m.copy&&t(b,i),P=m.breadcrumbs&&(M!==`simple`||!_&&v)?`${p}/${b}`:void 0,F=!1;if(M!==`simple`&&D&&!h.isFinished){let t=o(j,b,d,P,g,m);t.PASS=c;let n=yield y(D,t,T,`objectCallback`,...E);if(a(n)){if(!n.hasValue||!v)return x(n,i,b,N,m,h),k;s.length=0,h.restart=!0,h.isFinished=!0,A=!0,j=n.value}else if(f(n))continue;else l(n)?(F=!0,n.hasValue&&(j=n.value)):j=n;M=e(j)}if(M===`simple`){if(F||_&&!h.isFinished||!v){if(!m.copy)continue;N?i.push(j):n(i,b,j);continue}let t=o(j,b,d,P,g,m);t.isFinished=h.isFinished;let r=yield y(v,t,T,`keyCallback`,...E);if(a(r))return x(r,i,b,N,m,h),k;if(f(r))continue;let s=e(r);if(s===`simple`){if(!m.copy)continue;N?i.push(r):n(i,b,r);continue}j=r,M=s}let I=m.detectCycles?C(j,k,w):void 0;if(I){if(!m.copy)continue;N?i.push(I.location):n(i,b,I.location)}else{if(M===`object`){let e=m.copy?{}:void 0;m.copy&&(N?i.push(e):n(i,b,e)),s.push(S(j,e,P,g,b,F,k))}if(M===`array`){let e=m.copy?[]:void 0;m.copy&&(N?i.push(e):n(i,b,e)),s.push(S(j,e,P,g,b,F,k))}}}return k}}function x(e,t,r,i,a,o){o.finished=!0,a.copy&&e.hasValue&&(i?t.push(e.value):n(t,r,e.value))}function S(e,t,n,r,i,a,o){return{data:e,location:t,breadcrumbs:n,parentPath:r,key:i,pass:a,parent:o}}function C(e,t,n){if(n)return n.get(e);for(let n=t;n;n=n.parent)if(n.data===e)return n}function w(e,...t){return v(n());function*n(){let n=new Set,r=T(e,n,...t);if(e.timeout==null)return yield r;let i=p(),a=setTimeout(()=>{let t=[...n].map(e=>`\n - ${e}`).join(``);i.cancel(Error(`walk-async: timed out after ${e.timeout}ms; callbacks still pending:${t}`))},e.timeout);r.then(i.done,i.cancel);try{return yield i.promise}finally{clearTimeout(a)}}}function T(t,n,...r){return v(i());function*i(){let{data:i,keyCallback:s,objectCallback:u,settings:p}=t,m=e(i),h,g=[],_,v,x=!!(s||u),S={copy:(p==null?void 0:p.copy)!==!1,breadcrumbs:x&&(p==null?void 0:p.breadcrumbs)!==!1,parentPath:x&&(p==null?void 0:p.parentPath)!==!1,detectCycles:(p==null?void 0:p.detectCycles)!==!1},C=S.breadcrumbs?`root`:void 0,w=S.parentPath&&m!==`simple`?Object.freeze([`root`]):void 0,T=!1,D={finished:!1,isFinished:!1,restart:!1},O=[s,u];if(m!==`simple`&&u){let t=S.parentPath?Object.freeze([]):void 0,p=o(i,`root`,d,C,t,S);p.PASS=c;let h=yield y(u,p,n,`objectCallback`,...r);if(a(h)){if(!h.hasValue)return S.copy?m===`array`?[]:{}:void 0;if(!s)return S.copy?h.value:void 0;D.isFinished=!0,i=h.value}else if(f(h))return S.copy?m===`array`?[]:{}:void 0;else l(h)?(T=!0,h.hasValue&&(i=h.value)):i=h;m=e(i)}switch(m){case`array`:h=S.copy?[]:void 0,v=yield b(i,h,g,O,C,S,D,w,T,void 0,_,n,...r);break;case`object`:h=S.copy?{}:void 0,v=yield b(i,h,g,O,C,S,D,w,T,void 0,_,n,...r);break;case`simple`:return S.copy?i:void 0}for(let e=0;e<g.length&&!D.finished;){let t=g[e];g[e]=void 0,D.restart=!1,S.detectCycles&&(_=E(v,t.parent,_));let i=S.parentPath?Object.freeze([...t.parentPath,t.key]):void 0;v=yield b(t.data,t.location,g,O,t.breadcrumbs,S,D,i,t.pass,t.parent,_,n,...r),e=D.restart?0:e+1}return h}}function E(e,t,n){if(!n){if(t.depth<32)return;n=new WeakMap;for(let e=t;e;e=e.parent)n.set(e.data,e);return n}let r=[];for(;e!==t;)e.depth>=t.depth?(n.delete(e.data),e=e.parent):(r.push(t),t=t.parent);for(let e=r.length-1;e>=0;e--){let t=r[e];n.set(t.data,t)}return n}module.exports=w;
|
package/dist/walk-async.esm.mjs
CHANGED
|
@@ -1 +1,396 @@
|
|
|
1
|
-
|
|
1
|
+
//#region src/findType.js
|
|
2
|
+
function e(e) {
|
|
3
|
+
return e == null || e.nodeType ? "simple" : Array.isArray(e) ? "array" : typeof e == "object" ? e instanceof Date || e instanceof RegExp || e instanceof Map || e instanceof Set || e instanceof WeakMap || e instanceof WeakSet || e instanceof ArrayBuffer || e instanceof DataView || ArrayBuffer.isView(e) ? "simple" : "object" : "simple";
|
|
4
|
+
}
|
|
5
|
+
//#endregion
|
|
6
|
+
//#region src/validateForInsertion.js
|
|
7
|
+
function t(e, t) {
|
|
8
|
+
if (!Array.isArray(t)) return !1;
|
|
9
|
+
let n = Number(e);
|
|
10
|
+
return Number.isInteger(n) && n >= 0 && n < 4294967295 && String(n) === e;
|
|
11
|
+
}
|
|
12
|
+
//#endregion
|
|
13
|
+
//#region src/setKey.js
|
|
14
|
+
function n(e, t, n) {
|
|
15
|
+
t === "__proto__" ? Object.defineProperty(e, t, {
|
|
16
|
+
value: n,
|
|
17
|
+
enumerable: !0,
|
|
18
|
+
writable: !0,
|
|
19
|
+
configurable: !0
|
|
20
|
+
}) : e[t] = n;
|
|
21
|
+
}
|
|
22
|
+
//#endregion
|
|
23
|
+
//#region src/finish.js
|
|
24
|
+
var r = /* @__PURE__ */ new WeakSet();
|
|
25
|
+
function i(e) {
|
|
26
|
+
let t = Object.freeze({
|
|
27
|
+
value: e,
|
|
28
|
+
hasValue: arguments.length > 0
|
|
29
|
+
});
|
|
30
|
+
return r.add(t), t;
|
|
31
|
+
}
|
|
32
|
+
function a(e) {
|
|
33
|
+
return r.has(e);
|
|
34
|
+
}
|
|
35
|
+
//#endregion
|
|
36
|
+
//#region src/createCallbackArgs.js
|
|
37
|
+
function o(e, t, n, r, a, o) {
|
|
38
|
+
return o.breadcrumbs && o.parentPath ? {
|
|
39
|
+
value: e,
|
|
40
|
+
key: t,
|
|
41
|
+
breadcrumbs: r,
|
|
42
|
+
parentPath: a,
|
|
43
|
+
IGNORE: n,
|
|
44
|
+
FINISH: i
|
|
45
|
+
} : o.breadcrumbs ? {
|
|
46
|
+
value: e,
|
|
47
|
+
key: t,
|
|
48
|
+
breadcrumbs: r,
|
|
49
|
+
IGNORE: n,
|
|
50
|
+
FINISH: i
|
|
51
|
+
} : o.parentPath ? {
|
|
52
|
+
value: e,
|
|
53
|
+
key: t,
|
|
54
|
+
parentPath: a,
|
|
55
|
+
IGNORE: n,
|
|
56
|
+
FINISH: i
|
|
57
|
+
} : {
|
|
58
|
+
value: e,
|
|
59
|
+
key: t,
|
|
60
|
+
IGNORE: n,
|
|
61
|
+
FINISH: i
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
//#endregion
|
|
65
|
+
//#region src/pass.js
|
|
66
|
+
var s = /* @__PURE__ */ new WeakSet();
|
|
67
|
+
function c(e) {
|
|
68
|
+
let t = Object.freeze({
|
|
69
|
+
value: e,
|
|
70
|
+
hasValue: arguments.length > 0
|
|
71
|
+
});
|
|
72
|
+
return s.add(t), t;
|
|
73
|
+
}
|
|
74
|
+
function l(e) {
|
|
75
|
+
return s.has(e);
|
|
76
|
+
}
|
|
77
|
+
//#endregion
|
|
78
|
+
//#region src/ignore.js
|
|
79
|
+
var u = Symbol("ignore___");
|
|
80
|
+
function d() {
|
|
81
|
+
return u;
|
|
82
|
+
}
|
|
83
|
+
function f(e) {
|
|
84
|
+
return e === u;
|
|
85
|
+
}
|
|
86
|
+
//#endregion
|
|
87
|
+
//#region node_modules/ask-for-promise/src/askForPromise.js
|
|
88
|
+
function p(e) {
|
|
89
|
+
return e ? h(e) : m();
|
|
90
|
+
}
|
|
91
|
+
p.sequence = function(e, ...t) {
|
|
92
|
+
let n = p(), r = [];
|
|
93
|
+
function* i(e) {
|
|
94
|
+
for (let t of e) yield t;
|
|
95
|
+
}
|
|
96
|
+
let a = i(e);
|
|
97
|
+
function o(e, ...t) {
|
|
98
|
+
e.done ? n.done(r) : Promise.resolve().then(() => e.value(...t)).then((e) => {
|
|
99
|
+
r.push(e), o(a.next(), ...t, e);
|
|
100
|
+
}, (e) => {
|
|
101
|
+
n.cancel(e);
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
try {
|
|
105
|
+
o(a.next(), ...t);
|
|
106
|
+
} catch (e) {
|
|
107
|
+
n.cancel(e);
|
|
108
|
+
}
|
|
109
|
+
return n;
|
|
110
|
+
}, p.all = function(e, ...t) {
|
|
111
|
+
let n = p(), r = [], i;
|
|
112
|
+
try {
|
|
113
|
+
i = e.map((e, n) => Promise.resolve().then(() => typeof e == "function" ? e(...t) : e).then((e) => r[n] = e, (e) => {
|
|
114
|
+
throw e;
|
|
115
|
+
}));
|
|
116
|
+
} catch (e) {
|
|
117
|
+
return n.cancel(e), n;
|
|
118
|
+
}
|
|
119
|
+
return Promise.all(i).then(() => n.done(r), (e) => n.cancel(e)), n;
|
|
120
|
+
};
|
|
121
|
+
function m() {
|
|
122
|
+
let e, t, n = new Promise((n, r) => {
|
|
123
|
+
e = n, t = r;
|
|
124
|
+
}), r = {
|
|
125
|
+
promise: n,
|
|
126
|
+
promises: null,
|
|
127
|
+
_activeTimer: null,
|
|
128
|
+
done: () => {},
|
|
129
|
+
cancel: () => {},
|
|
130
|
+
each: () => {},
|
|
131
|
+
onComplete: g(n),
|
|
132
|
+
timeout: _()
|
|
133
|
+
};
|
|
134
|
+
return r.done = function(t) {
|
|
135
|
+
r._activeTimer !== null && (clearTimeout(r._activeTimer), r._activeTimer = null), e(t);
|
|
136
|
+
}, r.cancel = function(e) {
|
|
137
|
+
r._activeTimer !== null && (clearTimeout(r._activeTimer), r._activeTimer = null), t(e);
|
|
138
|
+
}, r.each = function(e, ...t) {
|
|
139
|
+
e({
|
|
140
|
+
value: null,
|
|
141
|
+
done: r.done,
|
|
142
|
+
cancel: r.cancel,
|
|
143
|
+
timeout: (e, t) => this.timeout(e, t)
|
|
144
|
+
}, void 0, ...t);
|
|
145
|
+
}, r;
|
|
146
|
+
}
|
|
147
|
+
function h(e) {
|
|
148
|
+
let t = e.map((e) => m()), n = t.map((e) => e.promise), r = Promise.all(n), i = {
|
|
149
|
+
promise: r,
|
|
150
|
+
promises: t,
|
|
151
|
+
_list: e,
|
|
152
|
+
_activeTimer: null,
|
|
153
|
+
done: () => {},
|
|
154
|
+
cancel: () => {},
|
|
155
|
+
each: () => {},
|
|
156
|
+
onComplete: g(r),
|
|
157
|
+
timeout: _()
|
|
158
|
+
};
|
|
159
|
+
return i.done = function(e) {
|
|
160
|
+
this._activeTimer !== null && (clearTimeout(this._activeTimer), this._activeTimer = null), this.promises.forEach((t) => t.done(e));
|
|
161
|
+
}, i.cancel = function(e) {
|
|
162
|
+
this._activeTimer !== null && (clearTimeout(this._activeTimer), this._activeTimer = null), this.promises.forEach((t) => t.cancel(e));
|
|
163
|
+
}, i.each = function(e, ...t) {
|
|
164
|
+
this.promises.forEach((n, r) => e({
|
|
165
|
+
value: this._list[r],
|
|
166
|
+
done: n.done,
|
|
167
|
+
cancel: n.cancel,
|
|
168
|
+
timeout: (e, t) => n.timeout(e, t)
|
|
169
|
+
}, r, ...t));
|
|
170
|
+
}, i;
|
|
171
|
+
}
|
|
172
|
+
function g(e) {
|
|
173
|
+
return function(t, n = null) {
|
|
174
|
+
n === null ? e.then((e) => t(e)) : e.then((e) => t(e), (e) => n(e));
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
function _() {
|
|
178
|
+
return function(e, t) {
|
|
179
|
+
let n = this;
|
|
180
|
+
n._activeTimer !== null && clearTimeout(n._activeTimer);
|
|
181
|
+
let r = setTimeout(() => n.done(t), e);
|
|
182
|
+
n._activeTimer = r;
|
|
183
|
+
let i = () => {
|
|
184
|
+
clearTimeout(r), n._activeTimer === r && (n._activeTimer = null);
|
|
185
|
+
};
|
|
186
|
+
return n.promise.then(i, i), n;
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
//#endregion
|
|
190
|
+
//#region src/runTask.js
|
|
191
|
+
function v(e) {
|
|
192
|
+
let t = p();
|
|
193
|
+
function n(r, i) {
|
|
194
|
+
let a;
|
|
195
|
+
try {
|
|
196
|
+
a = e[r](i);
|
|
197
|
+
} catch (e) {
|
|
198
|
+
t.cancel(e);
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
201
|
+
if (a.done) {
|
|
202
|
+
t.done(a.value);
|
|
203
|
+
return;
|
|
204
|
+
}
|
|
205
|
+
let o = p();
|
|
206
|
+
o.done(a.value), o.promise.then((e) => n("next", e), (e) => n("throw", e));
|
|
207
|
+
}
|
|
208
|
+
return n("next"), t.promise;
|
|
209
|
+
}
|
|
210
|
+
//#endregion
|
|
211
|
+
//#region src/runCallback.js
|
|
212
|
+
function y(e, t, n, r, ...o) {
|
|
213
|
+
return v(s());
|
|
214
|
+
function* s() {
|
|
215
|
+
var s;
|
|
216
|
+
let u, f, m = `${r} at '${(s = t.breadcrumbs) == null ? t.key : s}'`;
|
|
217
|
+
function h() {
|
|
218
|
+
u || (u = p(), f = u.done, u.promise.catch(() => {}));
|
|
219
|
+
}
|
|
220
|
+
Object.defineProperties(t, {
|
|
221
|
+
resolve: {
|
|
222
|
+
enumerable: !0,
|
|
223
|
+
get: () => (h(), f)
|
|
224
|
+
},
|
|
225
|
+
reject: {
|
|
226
|
+
enumerable: !0,
|
|
227
|
+
get: () => (h(), () => f(d()))
|
|
228
|
+
}
|
|
229
|
+
}), n.add(m);
|
|
230
|
+
try {
|
|
231
|
+
let n = yield e(t, ...o), s = u ? yield u.promise : n;
|
|
232
|
+
return r === "objectCallback" && l(s) && s.hasValue ? c(yield s.value) : a(s) && s.hasValue ? i(yield s.value) : s;
|
|
233
|
+
} finally {
|
|
234
|
+
n.delete(m);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
//#endregion
|
|
239
|
+
//#region src/copyObject.js
|
|
240
|
+
function b(r, i, s, u, p, m, h, g, _, b, w, T, ...E) {
|
|
241
|
+
return v(D());
|
|
242
|
+
function* D() {
|
|
243
|
+
let [v, D] = u, O = Object.keys(r), k = m.detectCycles ? {
|
|
244
|
+
data: r,
|
|
245
|
+
location: i,
|
|
246
|
+
parent: b,
|
|
247
|
+
depth: b ? b.depth + 1 : 0
|
|
248
|
+
} : void 0, A = !1;
|
|
249
|
+
w && w.set(r, k);
|
|
250
|
+
for (let u = 0; u < O.length && !A; u++) {
|
|
251
|
+
let b = O[u], j = r[b], M = e(j), N = m.copy && t(b, i), P = m.breadcrumbs && (M !== "simple" || !_ && v) ? `${p}/${b}` : void 0, F = !1;
|
|
252
|
+
if (M !== "simple" && D && !h.isFinished) {
|
|
253
|
+
let t = o(j, b, d, P, g, m);
|
|
254
|
+
t.PASS = c;
|
|
255
|
+
let n = yield y(D, t, T, "objectCallback", ...E);
|
|
256
|
+
if (a(n)) {
|
|
257
|
+
if (!n.hasValue || !v) return x(n, i, b, N, m, h), k;
|
|
258
|
+
s.length = 0, h.restart = !0, h.isFinished = !0, A = !0, j = n.value;
|
|
259
|
+
} else if (f(n)) continue;
|
|
260
|
+
else l(n) ? (F = !0, n.hasValue && (j = n.value)) : j = n;
|
|
261
|
+
M = e(j);
|
|
262
|
+
}
|
|
263
|
+
if (M === "simple") {
|
|
264
|
+
if (F || _ && !h.isFinished || !v) {
|
|
265
|
+
if (!m.copy) continue;
|
|
266
|
+
N ? i.push(j) : n(i, b, j);
|
|
267
|
+
continue;
|
|
268
|
+
}
|
|
269
|
+
let t = o(j, b, d, P, g, m);
|
|
270
|
+
t.isFinished = h.isFinished;
|
|
271
|
+
let r = yield y(v, t, T, "keyCallback", ...E);
|
|
272
|
+
if (a(r)) return x(r, i, b, N, m, h), k;
|
|
273
|
+
if (f(r)) continue;
|
|
274
|
+
let s = e(r);
|
|
275
|
+
if (s === "simple") {
|
|
276
|
+
if (!m.copy) continue;
|
|
277
|
+
N ? i.push(r) : n(i, b, r);
|
|
278
|
+
continue;
|
|
279
|
+
}
|
|
280
|
+
j = r, M = s;
|
|
281
|
+
}
|
|
282
|
+
let I = m.detectCycles ? C(j, k, w) : void 0;
|
|
283
|
+
if (I) {
|
|
284
|
+
if (!m.copy) continue;
|
|
285
|
+
N ? i.push(I.location) : n(i, b, I.location);
|
|
286
|
+
} else {
|
|
287
|
+
if (M === "object") {
|
|
288
|
+
let e = m.copy ? {} : void 0;
|
|
289
|
+
m.copy && (N ? i.push(e) : n(i, b, e)), s.push(S(j, e, P, g, b, F, k));
|
|
290
|
+
}
|
|
291
|
+
if (M === "array") {
|
|
292
|
+
let e = m.copy ? [] : void 0;
|
|
293
|
+
m.copy && (N ? i.push(e) : n(i, b, e)), s.push(S(j, e, P, g, b, F, k));
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
return k;
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
function x(e, t, r, i, a, o) {
|
|
301
|
+
o.finished = !0, a.copy && e.hasValue && (i ? t.push(e.value) : n(t, r, e.value));
|
|
302
|
+
}
|
|
303
|
+
function S(e, t, n, r, i, a, o) {
|
|
304
|
+
return {
|
|
305
|
+
data: e,
|
|
306
|
+
location: t,
|
|
307
|
+
breadcrumbs: n,
|
|
308
|
+
parentPath: r,
|
|
309
|
+
key: i,
|
|
310
|
+
pass: a,
|
|
311
|
+
parent: o
|
|
312
|
+
};
|
|
313
|
+
}
|
|
314
|
+
function C(e, t, n) {
|
|
315
|
+
if (n) return n.get(e);
|
|
316
|
+
for (let n = t; n; n = n.parent) if (n.data === e) return n;
|
|
317
|
+
}
|
|
318
|
+
//#endregion
|
|
319
|
+
//#region src/main.js
|
|
320
|
+
function w(e, ...t) {
|
|
321
|
+
return v(n());
|
|
322
|
+
function* n() {
|
|
323
|
+
let n = /* @__PURE__ */ new Set(), r = T(e, n, ...t);
|
|
324
|
+
if (e.timeout == null) return yield r;
|
|
325
|
+
let i = p(), a = setTimeout(() => {
|
|
326
|
+
let t = [...n].map((e) => `\n - ${e}`).join("");
|
|
327
|
+
i.cancel(/* @__PURE__ */ Error(`walk-async: timed out after ${e.timeout}ms; callbacks still pending:${t}`));
|
|
328
|
+
}, e.timeout);
|
|
329
|
+
r.then(i.done, i.cancel);
|
|
330
|
+
try {
|
|
331
|
+
return yield i.promise;
|
|
332
|
+
} finally {
|
|
333
|
+
clearTimeout(a);
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
function T(t, n, ...r) {
|
|
338
|
+
return v(i());
|
|
339
|
+
function* i() {
|
|
340
|
+
let { data: i, keyCallback: s, objectCallback: u, settings: p } = t, m = e(i), h, g = [], _, v, x = !!(s || u), S = {
|
|
341
|
+
copy: (p == null ? void 0 : p.copy) !== !1,
|
|
342
|
+
breadcrumbs: x && (p == null ? void 0 : p.breadcrumbs) !== !1,
|
|
343
|
+
parentPath: x && (p == null ? void 0 : p.parentPath) !== !1,
|
|
344
|
+
detectCycles: (p == null ? void 0 : p.detectCycles) !== !1
|
|
345
|
+
}, C = S.breadcrumbs ? "root" : void 0, w = S.parentPath && m !== "simple" ? Object.freeze(["root"]) : void 0, T = !1, D = {
|
|
346
|
+
finished: !1,
|
|
347
|
+
isFinished: !1,
|
|
348
|
+
restart: !1
|
|
349
|
+
}, O = [s, u];
|
|
350
|
+
if (m !== "simple" && u) {
|
|
351
|
+
let t = S.parentPath ? Object.freeze([]) : void 0, p = o(i, "root", d, C, t, S);
|
|
352
|
+
p.PASS = c;
|
|
353
|
+
let h = yield y(u, p, n, "objectCallback", ...r);
|
|
354
|
+
if (a(h)) {
|
|
355
|
+
if (!h.hasValue) return S.copy ? m === "array" ? [] : {} : void 0;
|
|
356
|
+
if (!s) return S.copy ? h.value : void 0;
|
|
357
|
+
D.isFinished = !0, i = h.value;
|
|
358
|
+
} else if (f(h)) return S.copy ? m === "array" ? [] : {} : void 0;
|
|
359
|
+
else l(h) ? (T = !0, h.hasValue && (i = h.value)) : i = h;
|
|
360
|
+
m = e(i);
|
|
361
|
+
}
|
|
362
|
+
switch (m) {
|
|
363
|
+
case "array":
|
|
364
|
+
h = S.copy ? [] : void 0, v = yield b(i, h, g, O, C, S, D, w, T, void 0, _, n, ...r);
|
|
365
|
+
break;
|
|
366
|
+
case "object":
|
|
367
|
+
h = S.copy ? {} : void 0, v = yield b(i, h, g, O, C, S, D, w, T, void 0, _, n, ...r);
|
|
368
|
+
break;
|
|
369
|
+
case "simple": return S.copy ? i : void 0;
|
|
370
|
+
}
|
|
371
|
+
for (let e = 0; e < g.length && !D.finished;) {
|
|
372
|
+
let t = g[e];
|
|
373
|
+
g[e] = void 0, D.restart = !1, S.detectCycles && (_ = E(v, t.parent, _));
|
|
374
|
+
let i = S.parentPath ? Object.freeze([...t.parentPath, t.key]) : void 0;
|
|
375
|
+
v = yield b(t.data, t.location, g, O, t.breadcrumbs, S, D, i, t.pass, t.parent, _, n, ...r), e = D.restart ? 0 : e + 1;
|
|
376
|
+
}
|
|
377
|
+
return h;
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
function E(e, t, n) {
|
|
381
|
+
if (!n) {
|
|
382
|
+
if (t.depth < 32) return;
|
|
383
|
+
n = /* @__PURE__ */ new WeakMap();
|
|
384
|
+
for (let e = t; e; e = e.parent) n.set(e.data, e);
|
|
385
|
+
return n;
|
|
386
|
+
}
|
|
387
|
+
let r = [];
|
|
388
|
+
for (; e !== t;) e.depth >= t.depth ? (n.delete(e.data), e = e.parent) : (r.push(t), t = t.parent);
|
|
389
|
+
for (let e = r.length - 1; e >= 0; e--) {
|
|
390
|
+
let t = r[e];
|
|
391
|
+
n.set(t.data, t);
|
|
392
|
+
}
|
|
393
|
+
return n;
|
|
394
|
+
}
|
|
395
|
+
//#endregion
|
|
396
|
+
export { w as default };
|
package/dist/walk-async.umd.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";(function(e,t){typeof exports==`object`&&typeof module<`u`?module.exports=t():typeof define==`function`&&define.amd?define([],t):(e=typeof globalThis<`u`?globalThis:e||self,e.walkAsync=t())})(this,function(){function e(e){return e==null||e.nodeType?`simple`:Array.isArray(e)?`array`:typeof e==`object`?e instanceof Date||e instanceof RegExp||e instanceof Map||e instanceof Set||e instanceof WeakMap||e instanceof WeakSet||e instanceof ArrayBuffer||e instanceof DataView||ArrayBuffer.isView(e)?`simple`:`object`:`simple`}function t(e,t){if(!Array.isArray(t))return!1;let n=Number(e);return Number.isInteger(n)&&n>=0&&n<4294967295&&String(n)===e}function n(e,t,n){t===`__proto__`?Object.defineProperty(e,t,{value:n,enumerable:!0,writable:!0,configurable:!0}):e[t]=n}var r=new WeakSet;function i(e){let t=Object.freeze({value:e,hasValue:arguments.length>0});return r.add(t),t}function a(e){return r.has(e)}function o(e,t,n,r,a,o){return o.breadcrumbs&&o.parentPath?{value:e,key:t,breadcrumbs:r,parentPath:a,IGNORE:n,FINISH:i}:o.breadcrumbs?{value:e,key:t,breadcrumbs:r,IGNORE:n,FINISH:i}:o.parentPath?{value:e,key:t,parentPath:a,IGNORE:n,FINISH:i}:{value:e,key:t,IGNORE:n,FINISH:i}}var s=new WeakSet;function c(e){let t=Object.freeze({value:e,hasValue:arguments.length>0});return s.add(t),t}function l(e){return s.has(e)}var u=Symbol(`ignore___`);function d(){return u}function f(e){return e===u}function p(e){return e?h(e):m()}p.sequence=function(e,...t){let n=p(),r=[];function*i(e){for(let t of e)yield t}let a=i(e);function o(e,...t){e.done?n.done(r):Promise.resolve().then(()=>e.value(...t)).then(e=>{r.push(e),o(a.next(),...t,e)},e=>{n.cancel(e)})}try{o(a.next(),...t)}catch(e){n.cancel(e)}return n},p.all=function(e,...t){let n=p(),r=[],i;try{i=e.map((e,n)=>Promise.resolve().then(()=>typeof e==`function`?e(...t):e).then(e=>r[n]=e,e=>{throw e}))}catch(e){return n.cancel(e),n}return Promise.all(i).then(()=>n.done(r),e=>n.cancel(e)),n};function m(){let e,t,n=new Promise((n,r)=>{e=n,t=r}),r={promise:n,promises:null,_activeTimer:null,done:()=>{},cancel:()=>{},each:()=>{},onComplete:g(n),timeout:_()};return r.done=function(t){r._activeTimer!==null&&(clearTimeout(r._activeTimer),r._activeTimer=null),e(t)},r.cancel=function(e){r._activeTimer!==null&&(clearTimeout(r._activeTimer),r._activeTimer=null),t(e)},r.each=function(e,...t){e({value:null,done:r.done,cancel:r.cancel,timeout:(e,t)=>this.timeout(e,t)},void 0,...t)},r}function h(e){let t=e.map(e=>m()),n=t.map(e=>e.promise),r=Promise.all(n),i={promise:r,promises:t,_list:e,_activeTimer:null,done:()=>{},cancel:()=>{},each:()=>{},onComplete:g(r),timeout:_()};return i.done=function(e){this._activeTimer!==null&&(clearTimeout(this._activeTimer),this._activeTimer=null),this.promises.forEach(t=>t.done(e))},i.cancel=function(e){this._activeTimer!==null&&(clearTimeout(this._activeTimer),this._activeTimer=null),this.promises.forEach(t=>t.cancel(e))},i.each=function(e,...t){this.promises.forEach((n,r)=>e({value:this._list[r],done:n.done,cancel:n.cancel,timeout:(e,t)=>n.timeout(e,t)},r,...t))},i}function g(e){return function(t,n=null){n===null?e.then(e=>t(e)):e.then(e=>t(e),e=>n(e))}}function _(){return function(e,t){let n=this;n._activeTimer!==null&&clearTimeout(n._activeTimer);let r=setTimeout(()=>n.done(t),e);n._activeTimer=r;let i=()=>{clearTimeout(r),n._activeTimer===r&&(n._activeTimer=null)};return n.promise.then(i,i),n}}function v(e){let t=p();function n(r,i){let a;try{a=e[r](i)}catch(e){t.cancel(e);return}if(a.done){t.done(a.value);return}let o=p();o.done(a.value),o.promise.then(e=>n(`next`,e),e=>n(`throw`,e))}return n(`next`),t.promise}function y(e,t,n,r,...o){return v(s());function*s(){var s;let u,f,m=`${r} at '${(s=t.breadcrumbs)==null?t.key:s}'`;function h(){u||(u=p(),f=u.done,u.promise.catch(()=>{}))}Object.defineProperties(t,{resolve:{enumerable:!0,get:()=>(h(),f)},reject:{enumerable:!0,get:()=>(h(),()=>f(d()))}}),n.add(m);try{let n=yield e(t,...o),s=u?yield u.promise:n;return r===`objectCallback`&&l(s)&&s.hasValue?c(yield s.value):a(s)&&s.hasValue?i(yield s.value):s}finally{n.delete(m)}}}function b(r,i,s,u,p,m,h,g,_,b,w,T,...E){return v(D());function*D(){let[v,D]=u,O=Object.keys(r),k=m.detectCycles?{data:r,location:i,parent:b,depth:b?b.depth+1:0}:void 0,A=!1;w&&w.set(r,k);for(let u=0;u<O.length&&!A;u++){let b=O[u],j=r[b],M=e(j),N=m.copy&&t(b,i),P=m.breadcrumbs&&(M!==`simple`||!_&&v)?`${p}/${b}`:void 0,F=!1;if(M!==`simple`&&D&&!h.isFinished){let t=o(j,b,d,P,g,m);t.PASS=c;let n=yield y(D,t,T,`objectCallback`,...E);if(a(n)){if(!n.hasValue||!v)return x(n,i,b,N,m,h),k;s.length=0,h.restart=!0,h.isFinished=!0,A=!0,j=n.value}else if(f(n))continue;else l(n)?(F=!0,n.hasValue&&(j=n.value)):j=n;M=e(j)}if(M===`simple`){if(F||_&&!h.isFinished||!v){if(!m.copy)continue;N?i.push(j):n(i,b,j);continue}let t=o(j,b,d,P,g,m);t.isFinished=h.isFinished;let r=yield y(v,t,T,`keyCallback`,...E);if(a(r))return x(r,i,b,N,m,h),k;if(f(r))continue;let s=e(r);if(s===`simple`){if(!m.copy)continue;N?i.push(r):n(i,b,r);continue}j=r,M=s}let I=m.detectCycles?C(j,k,w):void 0;if(I){if(!m.copy)continue;N?i.push(I.location):n(i,b,I.location)}else{if(M===`object`){let e=m.copy?{}:void 0;m.copy&&(N?i.push(e):n(i,b,e)),s.push(S(j,e,P,g,b,F,k))}if(M===`array`){let e=m.copy?[]:void 0;m.copy&&(N?i.push(e):n(i,b,e)),s.push(S(j,e,P,g,b,F,k))}}}return k}}function x(e,t,r,i,a,o){o.finished=!0,a.copy&&e.hasValue&&(i?t.push(e.value):n(t,r,e.value))}function S(e,t,n,r,i,a,o){return{data:e,location:t,breadcrumbs:n,parentPath:r,key:i,pass:a,parent:o}}function C(e,t,n){if(n)return n.get(e);for(let n=t;n;n=n.parent)if(n.data===e)return n}function w(e,...t){return v(n());function*n(){let n=new Set,r=T(e,n,...t);if(e.timeout==null)return yield r;let i=p(),a=setTimeout(()=>{let t=[...n].map(e=>`\n - ${e}`).join(``);i.cancel(Error(`walk-async: timed out after ${e.timeout}ms; callbacks still pending:${t}`))},e.timeout);r.then(i.done,i.cancel);try{return yield i.promise}finally{clearTimeout(a)}}}function T(t,n,...r){return v(i());function*i(){let{data:i,keyCallback:s,objectCallback:u,settings:p}=t,m=e(i),h,g=[],_,v,x=!!(s||u),S={copy:(p==null?void 0:p.copy)!==!1,breadcrumbs:x&&(p==null?void 0:p.breadcrumbs)!==!1,parentPath:x&&(p==null?void 0:p.parentPath)!==!1,detectCycles:(p==null?void 0:p.detectCycles)!==!1},C=S.breadcrumbs?`root`:void 0,w=S.parentPath&&m!==`simple`?Object.freeze([`root`]):void 0,T=!1,D={finished:!1,isFinished:!1,restart:!1},O=[s,u];if(m!==`simple`&&u){let t=S.parentPath?Object.freeze([]):void 0,p=o(i,`root`,d,C,t,S);p.PASS=c;let h=yield y(u,p,n,`objectCallback`,...r);if(a(h)){if(!h.hasValue)return S.copy?m===`array`?[]:{}:void 0;if(!s)return S.copy?h.value:void 0;D.isFinished=!0,i=h.value}else if(f(h))return S.copy?m===`array`?[]:{}:void 0;else l(h)?(T=!0,h.hasValue&&(i=h.value)):i=h;m=e(i)}switch(m){case`array`:h=S.copy?[]:void 0,v=yield b(i,h,g,O,C,S,D,w,T,void 0,_,n,...r);break;case`object`:h=S.copy?{}:void 0,v=yield b(i,h,g,O,C,S,D,w,T,void 0,_,n,...r);break;case`simple`:return S.copy?i:void 0}for(let e=0;e<g.length&&!D.finished;){let t=g[e];g[e]=void 0,D.restart=!1,S.detectCycles&&(_=E(v,t.parent,_));let i=S.parentPath?Object.freeze([...t.parentPath,t.key]):void 0;v=yield b(t.data,t.location,g,O,t.breadcrumbs,S,D,i,t.pass,t.parent,_,n,...r),e=D.restart?0:e+1}return h}}function E(e,t,n){if(!n){if(t.depth<32)return;n=new WeakMap;for(let e=t;e;e=e.parent)n.set(e.data,e);return n}let r=[];for(;e!==t;)e.depth>=t.depth?(n.delete(e.data),e=e.parent):(r.push(t),t=t.parent);for(let e=r.length-1;e>=0;e--){let t=r[e];n.set(t.data,t)}return n}return w});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@peter.naydenov/walk-async",
|
|
3
|
-
"version": "7.0.
|
|
3
|
+
"version": "7.0.2",
|
|
4
4
|
"description": "Deep copy with fine control during the process. Can be used also as a deep forEach function",
|
|
5
5
|
"main": "./dist/walk-async.umd.js",
|
|
6
6
|
"type": "module",
|
|
@@ -24,13 +24,13 @@
|
|
|
24
24
|
"Changelog.md",
|
|
25
25
|
"Migration.guide.md",
|
|
26
26
|
"LICENSE",
|
|
27
|
-
"
|
|
27
|
+
"skills"
|
|
28
28
|
],
|
|
29
29
|
"scripts": {
|
|
30
30
|
"test": "vitest run",
|
|
31
31
|
"test:watch": "vitest",
|
|
32
32
|
"cover": "vitest run --coverage",
|
|
33
|
-
"build": "
|
|
33
|
+
"build": "vite build",
|
|
34
34
|
"postbuild": "tsc -p tsconfig.json"
|
|
35
35
|
},
|
|
36
36
|
"repository": {
|
|
@@ -40,16 +40,12 @@
|
|
|
40
40
|
"author": "Peter Naydenov",
|
|
41
41
|
"license": "MIT",
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"ask-for-promise": "^3.2.
|
|
43
|
+
"ask-for-promise": "^3.2.2"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
|
-
"@rollup/plugin-commonjs": "^29.0.3",
|
|
47
|
-
"@rollup/plugin-node-resolve": "^16.0.3",
|
|
48
|
-
"@rollup/plugin-terser": "^1.0.0",
|
|
49
46
|
"@vitest/coverage-v8": "5.0.5",
|
|
50
|
-
"rollup": "^4.64.0",
|
|
51
47
|
"typescript": "^7.0.2",
|
|
52
|
-
"vite": "^8.3.
|
|
48
|
+
"vite": "^8.3.5",
|
|
53
49
|
"vitest": "5.0.5"
|
|
54
50
|
},
|
|
55
51
|
"vitest": {
|