mutts 1.0.7 → 1.0.8
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/README.md +61 -23
- package/dist/async/browser.d.ts +2 -0
- package/dist/async/browser.d.ts.map +1 -0
- package/dist/async/index.d.ts +18 -0
- package/dist/async/index.d.ts.map +1 -0
- package/dist/async/node.d.ts +2 -0
- package/dist/async/node.d.ts.map +1 -0
- package/dist/{chunks/index-BFYK02LG.js → browser.cjs} +169 -60
- package/dist/browser.cjs.map +1 -0
- package/dist/browser.d.ts +1654 -1
- package/dist/browser.esm.js +260 -25
- package/dist/browser.esm.js.map +1 -1
- package/dist/chunks/async-browser-CA0jPWIi.cjs +304 -0
- package/dist/chunks/async-browser-CA0jPWIi.cjs.map +1 -0
- package/dist/chunks/async-core-UqHzvJ-S.cjs +25 -0
- package/dist/chunks/async-core-UqHzvJ-S.cjs.map +1 -0
- package/dist/chunks/async-node-BYHuGTni.cjs +103 -0
- package/dist/chunks/async-node-BYHuGTni.cjs.map +1 -0
- package/dist/chunks/{index-CNR6QRUl.esm.js → index-DhaOVusv.esm.js} +173 -53
- package/dist/chunks/index-DhaOVusv.esm.js.map +1 -0
- package/dist/decorator.d.ts +106 -0
- package/dist/decorator.d.ts.map +1 -0
- package/dist/destroyable.d.ts +87 -0
- package/dist/destroyable.d.ts.map +1 -0
- package/dist/devtools/devtool/devtools.d.ts +1 -0
- package/dist/devtools/devtool/devtools.d.ts.map +1 -0
- package/dist/devtools/devtool/panel.d.ts +2 -0
- package/dist/devtools/devtool/panel.d.ts.map +1 -0
- package/dist/entry-browser.d.ts +3 -0
- package/dist/entry-browser.d.ts.map +1 -0
- package/dist/entry-node.d.ts +3 -0
- package/dist/entry-node.d.ts.map +1 -0
- package/dist/eventful.d.ts +18 -0
- package/dist/eventful.d.ts.map +1 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/indexable.d.ts +243 -0
- package/dist/indexable.d.ts.map +1 -0
- package/dist/introspection.d.ts +27 -0
- package/dist/introspection.d.ts.map +1 -0
- package/dist/iterableWeak.d.ts +53 -0
- package/dist/iterableWeak.d.ts.map +1 -0
- package/dist/mixins.d.ts +25 -0
- package/dist/mixins.d.ts.map +1 -0
- package/dist/mutts.umd.js +1 -1
- package/dist/mutts.umd.js.map +1 -1
- package/dist/mutts.umd.min.js +1 -1
- package/dist/mutts.umd.min.js.map +1 -1
- package/dist/node.cjs +105 -0
- package/dist/node.cjs.map +1 -0
- package/dist/node.d.ts +1 -2
- package/dist/node.esm.js +91 -32
- package/dist/node.esm.js.map +1 -1
- package/dist/promiseChain.d.ts +20 -0
- package/dist/promiseChain.d.ts.map +1 -0
- package/dist/reactive/array.d.ts +49 -0
- package/dist/reactive/array.d.ts.map +1 -0
- package/dist/reactive/buffer.d.ts +44 -0
- package/dist/reactive/buffer.d.ts.map +1 -0
- package/dist/reactive/change.d.ts +29 -0
- package/dist/reactive/change.d.ts.map +1 -0
- package/dist/reactive/debug.d.ts +111 -0
- package/dist/reactive/debug.d.ts.map +1 -0
- package/dist/reactive/deep-touch.d.ts +28 -0
- package/dist/reactive/deep-touch.d.ts.map +1 -0
- package/dist/reactive/deep-watch-state.d.ts +25 -0
- package/dist/reactive/deep-watch-state.d.ts.map +1 -0
- package/dist/reactive/deep-watch.d.ts +19 -0
- package/dist/reactive/deep-watch.d.ts.map +1 -0
- package/dist/reactive/effect-context.d.ts +7 -0
- package/dist/reactive/effect-context.d.ts.map +1 -0
- package/dist/reactive/effects.d.ts +151 -0
- package/dist/reactive/effects.d.ts.map +1 -0
- package/dist/reactive/index.d.ts +20 -0
- package/dist/reactive/index.d.ts.map +1 -0
- package/dist/reactive/interface.d.ts +64 -0
- package/dist/reactive/interface.d.ts.map +1 -0
- package/dist/reactive/map.d.ts +30 -0
- package/dist/reactive/map.d.ts.map +1 -0
- package/dist/reactive/memoize.d.ts +5 -0
- package/dist/reactive/memoize.d.ts.map +1 -0
- package/dist/reactive/non-reactive-state.d.ts +9 -0
- package/dist/reactive/non-reactive-state.d.ts.map +1 -0
- package/dist/reactive/non-reactive.d.ts +11 -0
- package/dist/reactive/non-reactive.d.ts.map +1 -0
- package/dist/reactive/project.d.ts +41 -0
- package/dist/reactive/project.d.ts.map +1 -0
- package/dist/reactive/proxy-state.d.ts +8 -0
- package/dist/reactive/proxy-state.d.ts.map +1 -0
- package/dist/reactive/proxy.d.ts +23 -0
- package/dist/reactive/proxy.d.ts.map +1 -0
- package/dist/reactive/record.d.ts +116 -0
- package/dist/reactive/record.d.ts.map +1 -0
- package/dist/reactive/register.d.ts +64 -0
- package/dist/reactive/register.d.ts.map +1 -0
- package/dist/reactive/registry.d.ts +20 -0
- package/dist/reactive/registry.d.ts.map +1 -0
- package/dist/reactive/set.d.ts +28 -0
- package/dist/reactive/set.d.ts.map +1 -0
- package/dist/reactive/tracking.d.ts +7 -0
- package/dist/reactive/tracking.d.ts.map +1 -0
- package/dist/reactive/types.d.ts +376 -0
- package/dist/reactive/types.d.ts.map +1 -0
- package/dist/std-decorators.d.ts +50 -0
- package/dist/std-decorators.d.ts.map +1 -0
- package/dist/utils.d.ts +49 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/zone.d.ts +40 -0
- package/dist/zone.d.ts.map +1 -0
- package/docs/std-decorators.md +69 -1
- package/docs/zone.md +7 -0
- package/package.json +39 -27
- package/src/async/browser.ts +266 -34
- package/src/async/index.ts +17 -2
- package/src/async/node.ts +89 -31
- package/src/entry-browser.ts +5 -0
- package/src/entry-node.ts +5 -0
- package/src/index.d.ts +12 -9
- package/src/index.ts +1 -0
- package/src/reactive/array.ts +139 -52
- package/src/reactive/effect-context.ts +3 -3
- package/src/reactive/index.ts +2 -1
- package/src/reactive/map.ts +1 -1
- package/src/reactive/set.ts +1 -1
- package/src/utils.ts +1 -1
- package/src/zone.ts +19 -8
- package/dist/browser.js +0 -161
- package/dist/browser.js.map +0 -1
- package/dist/chunks/index-BFYK02LG.js.map +0 -1
- package/dist/chunks/index-CNR6QRUl.esm.js.map +0 -1
- package/dist/node.js +0 -136
- package/dist/node.js.map +0 -1
|
@@ -0,0 +1,304 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var asyncCore = require('./async-core-UqHzvJ-S.cjs');
|
|
4
|
+
|
|
5
|
+
const hooks = new Set();
|
|
6
|
+
const promiseContexts = new WeakMap();
|
|
7
|
+
asyncCore.asyncHooks.addHook = function (hook) {
|
|
8
|
+
hooks.add(hook);
|
|
9
|
+
return () => {
|
|
10
|
+
hooks.delete(hook);
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
// [HACK]: Sanitization
|
|
14
|
+
// If a Promise is created inside the zone, it carries the "Sticky" zone context.
|
|
15
|
+
// If returned to the outer scope, that context leaks. We wrap it in a new Promise
|
|
16
|
+
// created here (in the outer scope) to break the chain and sanitize the return value.
|
|
17
|
+
// See BROWSER_ASYNC_POLYFILL.md for full details.
|
|
18
|
+
asyncCore.asyncHooks.sanitizePromise = (res) => {
|
|
19
|
+
if (res && typeof res.then === 'function') {
|
|
20
|
+
return new Promise((resolve, reject) => {
|
|
21
|
+
setTimeout(() => {
|
|
22
|
+
res.then(resolve, reject);
|
|
23
|
+
}, 0);
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
return res;
|
|
27
|
+
};
|
|
28
|
+
function captureRestorers() {
|
|
29
|
+
const restorers = new Set();
|
|
30
|
+
for (const hook of hooks) {
|
|
31
|
+
const restorer = hook();
|
|
32
|
+
if (restorer)
|
|
33
|
+
restorers.add(restorer);
|
|
34
|
+
}
|
|
35
|
+
return restorers;
|
|
36
|
+
}
|
|
37
|
+
function wrap(fn, capturedRestorers) {
|
|
38
|
+
if (typeof fn !== 'function')
|
|
39
|
+
return fn;
|
|
40
|
+
const restorers = capturedRestorers || captureRestorers();
|
|
41
|
+
return function (...args) {
|
|
42
|
+
const undoers = [];
|
|
43
|
+
for (const restore of restorers)
|
|
44
|
+
undoers.push(restore());
|
|
45
|
+
try {
|
|
46
|
+
return fn.apply(this, args);
|
|
47
|
+
}
|
|
48
|
+
finally {
|
|
49
|
+
if (originals.queueMicrotask) {
|
|
50
|
+
// Double microtask ensures we run after the first await resumption microtask
|
|
51
|
+
originals.queueMicrotask.call(globalThis, () => {
|
|
52
|
+
originals.queueMicrotask.call(globalThis, () => {
|
|
53
|
+
originals.queueMicrotask.call(globalThis, () => {
|
|
54
|
+
for (let i = undoers.length - 1; i >= 0; i--)
|
|
55
|
+
undoers[i]();
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
for (let i = undoers.length - 1; i >= 0; i--)
|
|
62
|
+
undoers[i]();
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
const targetWrappers = new WeakMap();
|
|
68
|
+
function patchEventTarget(proto) {
|
|
69
|
+
if (!proto || !proto.addEventListener || !proto.removeEventListener)
|
|
70
|
+
return;
|
|
71
|
+
const nativeAdd = proto.addEventListener;
|
|
72
|
+
const nativeRemove = proto.removeEventListener;
|
|
73
|
+
proto.addEventListener = function (type, listener, options) {
|
|
74
|
+
if (typeof listener !== 'function') {
|
|
75
|
+
return nativeAdd.call(this, type, listener, options);
|
|
76
|
+
}
|
|
77
|
+
let types = targetWrappers.get(this);
|
|
78
|
+
if (!types) {
|
|
79
|
+
types = new Map();
|
|
80
|
+
targetWrappers.set(this, types);
|
|
81
|
+
}
|
|
82
|
+
let listeners = types.get(type);
|
|
83
|
+
if (!listeners) {
|
|
84
|
+
listeners = new WeakMap();
|
|
85
|
+
types.set(type, listeners);
|
|
86
|
+
}
|
|
87
|
+
let wrapped = listeners.get(listener);
|
|
88
|
+
if (!wrapped) {
|
|
89
|
+
wrapped = wrap(listener);
|
|
90
|
+
listeners.set(listener, wrapped);
|
|
91
|
+
}
|
|
92
|
+
return nativeAdd.call(this, type, wrapped, options);
|
|
93
|
+
};
|
|
94
|
+
proto.removeEventListener = function (type, listener, options) {
|
|
95
|
+
if (typeof listener !== 'function') {
|
|
96
|
+
return nativeRemove.call(this, type, listener, options);
|
|
97
|
+
}
|
|
98
|
+
const types = targetWrappers.get(this);
|
|
99
|
+
if (types) {
|
|
100
|
+
const listeners = types.get(type);
|
|
101
|
+
if (listeners) {
|
|
102
|
+
const wrapped = listeners.get(listener);
|
|
103
|
+
if (wrapped) {
|
|
104
|
+
return nativeRemove.call(this, type, wrapped, options);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
return nativeRemove.call(this, type, listener, options);
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
function patchOnProperties(proto) {
|
|
112
|
+
if (!proto)
|
|
113
|
+
return;
|
|
114
|
+
for (const prop of Object.getOwnPropertyNames(proto)) {
|
|
115
|
+
if (prop.startsWith('on')) {
|
|
116
|
+
const desc = Object.getOwnPropertyDescriptor(proto, prop);
|
|
117
|
+
if (desc && desc.set && desc.configurable) {
|
|
118
|
+
const nativeSet = desc.set;
|
|
119
|
+
Object.defineProperty(proto, prop, {
|
|
120
|
+
...desc,
|
|
121
|
+
set: function (fn) {
|
|
122
|
+
nativeSet.call(this, wrap(fn));
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
if (typeof EventTarget !== 'undefined') {
|
|
130
|
+
patchEventTarget(EventTarget.prototype);
|
|
131
|
+
}
|
|
132
|
+
const prototypesToPatch = [
|
|
133
|
+
typeof EventTarget !== 'undefined' && EventTarget.prototype,
|
|
134
|
+
typeof HTMLElement !== 'undefined' && HTMLElement.prototype,
|
|
135
|
+
typeof Window !== 'undefined' && Window.prototype,
|
|
136
|
+
typeof Document !== 'undefined' && Document.prototype,
|
|
137
|
+
typeof MessagePort !== 'undefined' && MessagePort.prototype,
|
|
138
|
+
typeof XMLHttpRequest !== 'undefined' && XMLHttpRequest.prototype,
|
|
139
|
+
typeof IDBRequest !== 'undefined' && IDBRequest.prototype,
|
|
140
|
+
typeof IDBTransaction !== 'undefined' && IDBTransaction.prototype,
|
|
141
|
+
typeof IDBDatabase !== 'undefined' && IDBDatabase.prototype,
|
|
142
|
+
typeof FileReader !== 'undefined' && FileReader.prototype,
|
|
143
|
+
typeof AbortSignal !== 'undefined' && AbortSignal.prototype,
|
|
144
|
+
];
|
|
145
|
+
for (const proto of prototypesToPatch) {
|
|
146
|
+
if (proto) {
|
|
147
|
+
patchOnProperties(proto);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
const GLOBAL_ORIGINALS = Symbol.for('mutts.originals');
|
|
151
|
+
const GLOBAL_PROMISE = Symbol.for('mutts.OriginalPromise');
|
|
152
|
+
let originals;
|
|
153
|
+
let OriginalPromise;
|
|
154
|
+
if (globalThis[GLOBAL_ORIGINALS]) {
|
|
155
|
+
originals = globalThis[GLOBAL_ORIGINALS];
|
|
156
|
+
OriginalPromise = globalThis[GLOBAL_PROMISE];
|
|
157
|
+
}
|
|
158
|
+
else {
|
|
159
|
+
OriginalPromise = globalThis.Promise;
|
|
160
|
+
originals = {
|
|
161
|
+
then: OriginalPromise.prototype.then,
|
|
162
|
+
catch: OriginalPromise.prototype.catch,
|
|
163
|
+
finally: OriginalPromise.prototype.finally,
|
|
164
|
+
resolve: OriginalPromise.resolve,
|
|
165
|
+
reject: OriginalPromise.reject,
|
|
166
|
+
all: OriginalPromise.all,
|
|
167
|
+
allSettled: OriginalPromise.allSettled,
|
|
168
|
+
race: OriginalPromise.race,
|
|
169
|
+
any: OriginalPromise.any,
|
|
170
|
+
setTimeout: globalThis.setTimeout,
|
|
171
|
+
setInterval: globalThis.setInterval,
|
|
172
|
+
setImmediate: globalThis.setImmediate,
|
|
173
|
+
requestAnimationFrame: globalThis.requestAnimationFrame,
|
|
174
|
+
queueMicrotask: globalThis.queueMicrotask,
|
|
175
|
+
};
|
|
176
|
+
globalThis[GLOBAL_ORIGINALS] = originals;
|
|
177
|
+
globalThis[GLOBAL_PROMISE] = OriginalPromise;
|
|
178
|
+
}
|
|
179
|
+
// Ensure modern statics are captured even if originals was cached from an older version
|
|
180
|
+
if (!originals.allSettled)
|
|
181
|
+
originals.allSettled = OriginalPromise.allSettled;
|
|
182
|
+
if (!originals.any)
|
|
183
|
+
originals.any = OriginalPromise.any;
|
|
184
|
+
if (!originals.race)
|
|
185
|
+
originals.race = OriginalPromise.race;
|
|
186
|
+
function patchedThen(onFulfilled, onRejected) {
|
|
187
|
+
const context = promiseContexts.get(this) || captureRestorers();
|
|
188
|
+
const nextPromise = originals.then.call(this, wrap(onFulfilled, context), wrap(onRejected, context));
|
|
189
|
+
if (context.size > 0)
|
|
190
|
+
promiseContexts.set(nextPromise, context);
|
|
191
|
+
return nextPromise;
|
|
192
|
+
}
|
|
193
|
+
function patchedCatch(onRejected) {
|
|
194
|
+
const context = promiseContexts.get(this) || captureRestorers();
|
|
195
|
+
const nextPromise = originals.catch.call(this, wrap(onRejected, context));
|
|
196
|
+
if (context.size > 0)
|
|
197
|
+
promiseContexts.set(nextPromise, context);
|
|
198
|
+
return nextPromise;
|
|
199
|
+
}
|
|
200
|
+
function patchedFinally(onFinally) {
|
|
201
|
+
const context = promiseContexts.get(this) || captureRestorers();
|
|
202
|
+
const nextPromise = originals.finally.call(this, wrap(onFinally, context));
|
|
203
|
+
if (context.size > 0)
|
|
204
|
+
promiseContexts.set(nextPromise, context);
|
|
205
|
+
return nextPromise;
|
|
206
|
+
}
|
|
207
|
+
function PatchedPromise(executor) {
|
|
208
|
+
if (typeof executor === 'function') {
|
|
209
|
+
const p = new OriginalPromise((resolve, reject) => {
|
|
210
|
+
const wrappedResolve = wrap(resolve);
|
|
211
|
+
const wrappedReject = wrap(reject);
|
|
212
|
+
executor(wrappedResolve, wrappedReject);
|
|
213
|
+
});
|
|
214
|
+
const context = captureRestorers();
|
|
215
|
+
promiseContexts.set(p, context); // Always set, even if empty (Sticky Root)
|
|
216
|
+
return p;
|
|
217
|
+
}
|
|
218
|
+
return new OriginalPromise(executor);
|
|
219
|
+
}
|
|
220
|
+
// Copy statics
|
|
221
|
+
Object.assign(PatchedPromise, OriginalPromise);
|
|
222
|
+
// Inherit prototype for instanceof checks
|
|
223
|
+
PatchedPromise.prototype = OriginalPromise.prototype;
|
|
224
|
+
PatchedPromise.resolve = function (value) {
|
|
225
|
+
const p = originals.resolve.call(OriginalPromise, value);
|
|
226
|
+
const context = captureRestorers();
|
|
227
|
+
// Ensure we don't overwrite if it already has context (e.g. from constructor)
|
|
228
|
+
if (context.size > 0 && !promiseContexts.has(p))
|
|
229
|
+
promiseContexts.set(p, context);
|
|
230
|
+
return p;
|
|
231
|
+
};
|
|
232
|
+
PatchedPromise.reject = function (reason) {
|
|
233
|
+
const p = originals.reject.call(OriginalPromise, reason);
|
|
234
|
+
const context = captureRestorers();
|
|
235
|
+
if (context.size > 0)
|
|
236
|
+
promiseContexts.set(p, context);
|
|
237
|
+
return p;
|
|
238
|
+
};
|
|
239
|
+
PatchedPromise.all = function (values) {
|
|
240
|
+
const p = originals.all.call(OriginalPromise, values);
|
|
241
|
+
const context = captureRestorers();
|
|
242
|
+
if (context.size > 0)
|
|
243
|
+
promiseContexts.set(p, context);
|
|
244
|
+
return p;
|
|
245
|
+
};
|
|
246
|
+
PatchedPromise.allSettled = function (values) {
|
|
247
|
+
const p = originals.allSettled.call(OriginalPromise, values);
|
|
248
|
+
const context = captureRestorers();
|
|
249
|
+
if (context.size > 0)
|
|
250
|
+
promiseContexts.set(p, context);
|
|
251
|
+
return p;
|
|
252
|
+
};
|
|
253
|
+
PatchedPromise.race = function (values) {
|
|
254
|
+
const p = originals.race.call(OriginalPromise, values);
|
|
255
|
+
const context = captureRestorers();
|
|
256
|
+
if (context.size > 0)
|
|
257
|
+
promiseContexts.set(p, context);
|
|
258
|
+
return p;
|
|
259
|
+
};
|
|
260
|
+
PatchedPromise.any = function (values) {
|
|
261
|
+
const p = originals.any.call(OriginalPromise, values);
|
|
262
|
+
const context = captureRestorers();
|
|
263
|
+
if (context.size > 0)
|
|
264
|
+
promiseContexts.set(p, context);
|
|
265
|
+
return p;
|
|
266
|
+
};
|
|
267
|
+
// Only apply patches if not already applied (or re-apply safely)
|
|
268
|
+
// Note: OriginalPromise.prototype might be shared if we used the global one.
|
|
269
|
+
// We must ensure we don't patch it twice if it's the SAME object.
|
|
270
|
+
if (OriginalPromise.prototype.then !== patchedThen) {
|
|
271
|
+
OriginalPromise.prototype.then = patchedThen;
|
|
272
|
+
OriginalPromise.prototype.catch = patchedCatch;
|
|
273
|
+
OriginalPromise.prototype.finally = patchedFinally;
|
|
274
|
+
}
|
|
275
|
+
try {
|
|
276
|
+
Object.defineProperty(OriginalPromise, Symbol.species, {
|
|
277
|
+
get: () => PatchedPromise,
|
|
278
|
+
configurable: true
|
|
279
|
+
});
|
|
280
|
+
}
|
|
281
|
+
catch (e) { }
|
|
282
|
+
globalThis.Promise = PatchedPromise;
|
|
283
|
+
globalThis.setTimeout = ((callback, ...args) => {
|
|
284
|
+
return originals.setTimeout.call(globalThis, wrap(callback), ...args);
|
|
285
|
+
});
|
|
286
|
+
globalThis.setInterval = ((callback, ...args) => {
|
|
287
|
+
return originals.setInterval.call(globalThis, wrap(callback), ...args);
|
|
288
|
+
});
|
|
289
|
+
if (originals.setImmediate) {
|
|
290
|
+
globalThis.setImmediate = ((callback, ...args) => {
|
|
291
|
+
return originals.setImmediate.call(globalThis, wrap(callback), ...args);
|
|
292
|
+
});
|
|
293
|
+
}
|
|
294
|
+
if (originals.requestAnimationFrame) {
|
|
295
|
+
globalThis.requestAnimationFrame = (callback) => {
|
|
296
|
+
return originals.requestAnimationFrame.call(globalThis, wrap(callback));
|
|
297
|
+
};
|
|
298
|
+
}
|
|
299
|
+
if (originals.queueMicrotask) {
|
|
300
|
+
globalThis.queueMicrotask = (callback) => {
|
|
301
|
+
originals.queueMicrotask.call(globalThis, wrap(callback));
|
|
302
|
+
};
|
|
303
|
+
}
|
|
304
|
+
//# sourceMappingURL=async-browser-CA0jPWIi.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"async-browser-CA0jPWIi.cjs","sources":["../../src/async/browser.ts"],"sourcesContent":["import { Hook, Restorer, asyncHooks } from '.'\n\nconst hooks = new Set<Hook>()\nconst promiseContexts = new WeakMap<Promise<any>, Set<Restorer>>()\n\nasyncHooks.addHook = function (hook: Hook) {\n\thooks.add(hook)\n\treturn () => {\n\t\thooks.delete(hook)\n\t}\n}\n\n// [HACK]: Sanitization\n// If a Promise is created inside the zone, it carries the \"Sticky\" zone context.\n// If returned to the outer scope, that context leaks. We wrap it in a new Promise\n// created here (in the outer scope) to break the chain and sanitize the return value.\n// See BROWSER_ASYNC_POLYFILL.md for full details.\nasyncHooks.sanitizePromise = (res: any) => {\n if (res && typeof (res as any).then === 'function') {\n return new Promise((resolve, reject) => {\n setTimeout(() => {\n (res as any).then(resolve, reject)\n }, 0)\n })\n }\n return res\n}\n\nfunction captureRestorers() {\n\tconst restorers = new Set<Restorer>()\n\tfor (const hook of hooks) {\n\t\tconst restorer = hook()\n\t\tif (restorer) restorers.add(restorer)\n\t}\n\treturn restorers\n}\n\nfunction wrap<Args extends any[], R>(fn: ((...args: Args) => R) | null | undefined, capturedRestorers?: Set<Restorer>) {\n\tif (typeof fn !== 'function') return fn\n\tconst restorers = capturedRestorers || captureRestorers()\n\treturn function (this: any, ...args: Args) {\n\t\tconst undoers: (() => void)[] = []\n\t\tfor (const restore of restorers) undoers.push(restore())\n\t\ttry {\n\t\t\treturn fn.apply(this, args)\n\t\t} finally {\n\t\t\tif (originals.queueMicrotask) {\n\t\t\t\t// Double microtask ensures we run after the first await resumption microtask\n\t\t\t\toriginals.queueMicrotask.call(globalThis, () => {\n\t\t\t\t\toriginals.queueMicrotask.call(globalThis, () => {\n\t\t\t\t\t\toriginals.queueMicrotask.call(globalThis, () => {\n\t\t\t\t\t\t\tfor (let i = undoers.length - 1; i >= 0; i--) undoers[i]()\n\t\t\t\t\t\t})\n\t\t\t\t\t})\n\t\t\t\t})\n\t\t\t} else {\n\t\t\t\tfor (let i = undoers.length - 1; i >= 0; i--) undoers[i]()\n\t\t\t}\n\t\t}\n\t}\n}\n\nconst targetWrappers = new WeakMap<any, Map<string, WeakMap<Function, Function>>>()\n\nfunction patchEventTarget(proto: any) {\n\tif (!proto || !proto.addEventListener || !proto.removeEventListener) return\n\tconst nativeAdd = proto.addEventListener\n\tconst nativeRemove = proto.removeEventListener\n\n\tproto.addEventListener = function (this: any, type: string, listener: any, options: any) {\n\t\tif (typeof listener !== 'function') {\n\t\t\treturn nativeAdd.call(this, type, listener, options)\n\t\t}\n\n\t\tlet types = targetWrappers.get(this)\n\t\tif (!types) {\n\t\t\ttypes = new Map()\n\t\t\ttargetWrappers.set(this, types)\n\t\t}\n\t\tlet listeners = types.get(type)\n\t\tif (!listeners) {\n\t\t\tlisteners = new WeakMap()\n\t\t\ttypes.set(type, listeners)\n\t\t}\n\n\t\tlet wrapped = listeners.get(listener)\n\t\tif (!wrapped) {\n\t\t\twrapped = wrap(listener)\n\t\t\tlisteners.set(listener, wrapped)\n\t\t}\n\t\t\n\t\treturn nativeAdd.call(this, type, wrapped, options)\n\t}\n\n\tproto.removeEventListener = function (this: any, type: string, listener: any, options: any) {\n\t\tif (typeof listener !== 'function') {\n\t\t\treturn nativeRemove.call(this, type, listener, options)\n\t\t}\n\n\t\tconst types = targetWrappers.get(this)\n\t\tif (types) {\n\t\t\tconst listeners = types.get(type)\n\t\t\tif (listeners) {\n\t\t\t\tconst wrapped = listeners.get(listener)\n\t\t\t\tif (wrapped) {\n\t\t\t\t\treturn nativeRemove.call(this, type, wrapped, options)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\treturn nativeRemove.call(this, type, listener, options)\n\t}\n}\n\nfunction patchOnProperties(proto: any) {\n\tif (!proto) return\n\tfor (const prop of Object.getOwnPropertyNames(proto)) {\n\t\tif (prop.startsWith('on')) {\n\t\t\tconst desc = Object.getOwnPropertyDescriptor(proto, prop)\n\t\t\tif (desc && desc.set && desc.configurable) {\n\t\t\t\tconst nativeSet = desc.set\n\t\t\t\tObject.defineProperty(proto, prop, {\n\t\t\t\t\t...desc,\n\t\t\t\t\tset: function (this: any, fn: any) {\n\t\t\t\t\t\tnativeSet.call(this, wrap(fn))\n\t\t\t\t\t}\n\t\t\t\t})\n\t\t\t}\n\t\t}\n\t}\n}\n\nif (typeof EventTarget !== 'undefined') {\n\tpatchEventTarget(EventTarget.prototype)\n}\n\nconst prototypesToPatch = [\n\ttypeof EventTarget !== 'undefined' && EventTarget.prototype,\n\ttypeof HTMLElement !== 'undefined' && HTMLElement.prototype,\n\ttypeof Window !== 'undefined' && Window.prototype,\n\ttypeof Document !== 'undefined' && Document.prototype,\n\ttypeof MessagePort !== 'undefined' && MessagePort.prototype,\n\ttypeof XMLHttpRequest !== 'undefined' && XMLHttpRequest.prototype,\n\ttypeof IDBRequest !== 'undefined' && IDBRequest.prototype,\n\ttypeof IDBTransaction !== 'undefined' && IDBTransaction.prototype,\n\ttypeof IDBDatabase !== 'undefined' && IDBDatabase.prototype,\n\ttypeof FileReader !== 'undefined' && FileReader.prototype,\n\ttypeof AbortSignal !== 'undefined' && AbortSignal.prototype,\n]\n\nfor (const proto of prototypesToPatch) {\n\tif (proto) {\n\t\tpatchOnProperties(proto)\n\t}\n}\n\nconst GLOBAL_ORIGINALS = Symbol.for('mutts.originals');\nconst GLOBAL_PROMISE = Symbol.for('mutts.OriginalPromise');\n\nlet originals: any;\nlet OriginalPromise: any;\n\nif ((globalThis as any)[GLOBAL_ORIGINALS]) {\n originals = (globalThis as any)[GLOBAL_ORIGINALS];\n OriginalPromise = (globalThis as any)[GLOBAL_PROMISE];\n} else {\n OriginalPromise = globalThis.Promise;\n originals = {\n then: OriginalPromise.prototype.then,\n catch: OriginalPromise.prototype.catch,\n finally: OriginalPromise.prototype.finally,\n resolve: OriginalPromise.resolve,\n reject: OriginalPromise.reject,\n all: OriginalPromise.all,\n allSettled: (OriginalPromise as any).allSettled,\n race: OriginalPromise.race,\n any: (OriginalPromise as any).any,\n setTimeout: globalThis.setTimeout,\n setInterval: globalThis.setInterval,\n setImmediate: (globalThis as any).setImmediate,\n requestAnimationFrame: (globalThis as any).requestAnimationFrame,\n queueMicrotask: globalThis.queueMicrotask,\n };\n (globalThis as any)[GLOBAL_ORIGINALS] = originals;\n (globalThis as any)[GLOBAL_PROMISE] = OriginalPromise;\n}\n\n// Ensure modern statics are captured even if originals was cached from an older version\nif (!originals.allSettled) originals.allSettled = (OriginalPromise as any).allSettled\nif (!originals.any) originals.any = (OriginalPromise as any).any\nif (!originals.race) originals.race = OriginalPromise.race\n\nfunction patchedThen(this: any, onFulfilled: any, onRejected: any) {\n\tconst context = promiseContexts.get(this) || captureRestorers()\n\tconst nextPromise = originals.then.call(this, wrap(onFulfilled, context), wrap(onRejected, context))\n\tif (context.size > 0) promiseContexts.set(nextPromise, context)\n\treturn nextPromise\n}\n\nfunction patchedCatch(this: any, onRejected: any) {\n\tconst context = promiseContexts.get(this) || captureRestorers()\n\tconst nextPromise = originals.catch.call(this, wrap(onRejected, context))\n\tif (context.size > 0) promiseContexts.set(nextPromise, context)\n\treturn nextPromise\n}\n\nfunction patchedFinally(this: any, onFinally: any) {\n\tconst context = promiseContexts.get(this) || captureRestorers()\n\tconst nextPromise = originals.finally.call(this, wrap(onFinally, context))\n\tif (context.size > 0) promiseContexts.set(nextPromise, context)\n\treturn nextPromise\n}\n\nfunction PatchedPromise<T>(this: any, executor: (resolve: (value: T | PromiseLike<T>) => void, reject: (reason?: any) => void) => void) {\n if (typeof executor === 'function') {\n const p = new OriginalPromise((resolve, reject) => {\n const wrappedResolve = wrap(resolve)\n const wrappedReject = wrap(reject)\n executor(wrappedResolve, wrappedReject)\n })\n const context = captureRestorers()\n promiseContexts.set(p, context) // Always set, even if empty (Sticky Root)\n return p\n }\n return new OriginalPromise(executor)\n}\n\n// Copy statics\nObject.assign(PatchedPromise, (OriginalPromise as any))\n\n// Inherit prototype for instanceof checks\nPatchedPromise.prototype = OriginalPromise.prototype\n\nPatchedPromise.resolve = function<T>(value?: T | PromiseLike<T>): Promise<T> {\n const p = originals.resolve.call(OriginalPromise, value) as Promise<T>\n const context = captureRestorers()\n // Ensure we don't overwrite if it already has context (e.g. from constructor)\n if (context.size > 0 && !promiseContexts.has(p)) promiseContexts.set(p, context)\n return p\n} as any\n\nPatchedPromise.reject = function<T = never>(reason?: any): Promise<T> {\n const p = originals.reject.call(OriginalPromise, reason) as Promise<T>\n const context = captureRestorers()\n if (context.size > 0) promiseContexts.set(p, context)\n return p\n} as any\n\nPatchedPromise.all = function<T>(values: Iterable<T | PromiseLike<T>>): Promise<Awaited<T>[]> {\n const p = originals.all.call(OriginalPromise, values) as Promise<Awaited<T>[]>\n const context = captureRestorers()\n if (context.size > 0) promiseContexts.set(p, context)\n return p\n} as any\n\nPatchedPromise.allSettled = function<T>(values: Iterable<T | PromiseLike<T>>): Promise<PromiseSettledResult<Awaited<T>>[]> {\n const p = (originals.allSettled as any).call(OriginalPromise, values)\n const context = captureRestorers()\n if (context.size > 0) promiseContexts.set(p, context)\n return p\n} as any\n\nPatchedPromise.race = function<T>(values: Iterable<T | PromiseLike<T>>): Promise<Awaited<T>> {\n const p = originals.race.call(OriginalPromise, values) as Promise<Awaited<T>>\n const context = captureRestorers()\n if (context.size > 0) promiseContexts.set(p, context)\n return p\n} as any\n\nPatchedPromise.any = function<T>(values: Iterable<T | PromiseLike<T>>): Promise<Awaited<T>> {\n const p = (originals.any as any).call(OriginalPromise, values)\n const context = captureRestorers()\n if (context.size > 0) promiseContexts.set(p, context)\n return p\n} as any\n\n// Only apply patches if not already applied (or re-apply safely)\n// Note: OriginalPromise.prototype might be shared if we used the global one.\n// We must ensure we don't patch it twice if it's the SAME object.\nif (OriginalPromise.prototype.then !== patchedThen) {\n OriginalPromise.prototype.then = patchedThen as any\n OriginalPromise.prototype.catch = patchedCatch as any\n OriginalPromise.prototype.finally = patchedFinally as any\n}\n\ntry {\n\tObject.defineProperty(OriginalPromise, Symbol.species, {\n\t\tget: () => PatchedPromise,\n\t\tconfigurable: true\n\t})\n} catch (e) {}\n\n;(globalThis as any).Promise = PatchedPromise\n\nglobalThis.setTimeout = ((callback: Function, ...args: any[]) => {\n\treturn originals.setTimeout.call(globalThis, wrap(callback as any), ...args)\n}) as any\n\nglobalThis.setInterval = ((callback: Function, ...args: any[]) => {\n\treturn originals.setInterval.call(globalThis, wrap(callback as any), ...args)\n}) as any\n\nif (originals.setImmediate) {\n\t;(globalThis as any).setImmediate = ((callback: Function, ...args: any[]) => {\n\t\treturn originals.setImmediate.call(globalThis, wrap(callback as any), ...args)\n\t}) as any\n}\n\nif (originals.requestAnimationFrame) {\n\tglobalThis.requestAnimationFrame = (callback: FrameRequestCallback) => {\n\t\treturn originals.requestAnimationFrame.call(globalThis, wrap(callback))\n\t}\n}\n\nif (originals.queueMicrotask) {\n\tglobalThis.queueMicrotask = (callback: VoidFunction): void => {\n\t\toriginals.queueMicrotask.call(globalThis, wrap(callback))\n\t}\n}\n"],"names":["asyncHooks"],"mappings":";;;;AAEA,MAAM,KAAK,GAAG,IAAI,GAAG,EAAQ;AAC7B,MAAM,eAAe,GAAG,IAAI,OAAO,EAA+B;AAElEA,oBAAU,CAAC,OAAO,GAAG,UAAU,IAAU,EAAA;AACxC,IAAA,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC;AACf,IAAA,OAAO,MAAK;AACX,QAAA,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC;AACnB,IAAA,CAAC;AACF,CAAC;AAED;AACA;AACA;AACA;AACA;AACAA,oBAAU,CAAC,eAAe,GAAG,CAAC,GAAQ,KAAI;IACtC,IAAI,GAAG,IAAI,OAAQ,GAAW,CAAC,IAAI,KAAK,UAAU,EAAE;QAChD,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,KAAI;YACnC,UAAU,CAAC,MAAK;AACX,gBAAA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AAY,EAAE;IACzB,UAAkB,CAAC,YAAY,IAAI,CAAC,QAAkB,EAAE,GAAG,IAAW,KAAI;AAC3E,QAAA,OAAO,SAAS,CAAC,YAAY,CAAC,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,QAAe,CAAC,EAAE,GAAG,IAAI,CAAC;AAC/E,IAAA,CAAC,CAAQ;AACV;AAEA,IAAI,SAAS,CAAC,qBAAqB,EAAE;AACpC,IAAA,UAAU,CAAC,qBAAqB,GAAG,CAAC,QAA8B,KAAI;AACrE,QAAA,OAAO,SAAS,CAAC,qBAAqB,CAAC,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;AACxE,IAAA,CAAC;AACF;AAEA,IAAI,SAAS,CAAC,cAAc,EAAE;AAC7B,IAAA,UAAU,CAAC,cAAc,GAAG,CAAC,QAAsB,KAAU;AAC5D,QAAA,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;AAC1D,IAAA,CAAC;AACF;;"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const asyncHooks = {
|
|
4
|
+
addHook(_hook) {
|
|
5
|
+
throw 'One must import the library from the server or the client side';
|
|
6
|
+
},
|
|
7
|
+
/**
|
|
8
|
+
* [Hack] Sanitize a promise (or value) to prevent context leaks.
|
|
9
|
+
* Default: Identity function.
|
|
10
|
+
* Browser: Uses Macrotask wrapping to break microtask chains.
|
|
11
|
+
*/
|
|
12
|
+
sanitizePromise(p) {
|
|
13
|
+
return p;
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Register a hook that will be called whenever an asynchronous operation is initiated.
|
|
18
|
+
* The hook should return a restorer function which will be called just before the async callback runs.
|
|
19
|
+
* That restorer should in turn return an undoer function which will be called just after the async callback finishes.
|
|
20
|
+
*/
|
|
21
|
+
const asyncHook = (hook) => asyncHooks.addHook(hook);
|
|
22
|
+
|
|
23
|
+
exports.asyncHook = asyncHook;
|
|
24
|
+
exports.asyncHooks = asyncHooks;
|
|
25
|
+
//# sourceMappingURL=async-core-UqHzvJ-S.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"async-core-UqHzvJ-S.cjs","sources":["../../src/async/index.ts"],"sourcesContent":["export type Restorer = () => () => void\nexport type Hook = () => Restorer\n\nexport const asyncHooks = {\n\taddHook(_hook: Hook): () => void {\n\t\tthrow 'One must import the library from the server or the client side'\n\t},\n /** \n * [Hack] Sanitize a promise (or value) to prevent context leaks. \n * Default: Identity function.\n * Browser: Uses Macrotask wrapping to break microtask chains.\n */\n sanitizePromise(p: any): any {\n return p\n }\n}\n\n/**\n * Register a hook that will be called whenever an asynchronous operation is initiated.\n * The hook should return a restorer function which will be called just before the async callback runs.\n * That restorer should in turn return an undoer function which will be called just after the async callback finishes.\n */\nexport const asyncHook = (hook: Hook) => asyncHooks.addHook(hook)"],"names":[],"mappings":";;AAGO,MAAM,UAAU,GAAG;AACzB,IAAA,OAAO,CAAC,KAAW,EAAA;AAClB,QAAA,MAAM,gEAAgE;IACvE,CAAC;AACE;;;;AAIG;AACH,IAAA,eAAe,CAAC,CAAM,EAAA;AAClB,QAAA,OAAO,CAAC;IACZ;;AAGJ;;;;AAIG;AACI,MAAM,SAAS,GAAG,CAAC,IAAU,KAAK,UAAU,CAAC,OAAO,CAAC,IAAI;;;;;"}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var node_async_hooks = require('node:async_hooks');
|
|
4
|
+
var asyncCore = require('./async-core-UqHzvJ-S.cjs');
|
|
5
|
+
|
|
6
|
+
// 1. Generic async_hooks implementation for Hooks
|
|
7
|
+
// This maintains support for 'asyncHooks.addHook' for generic use cases.
|
|
8
|
+
const hooks = new Set();
|
|
9
|
+
asyncCore.asyncHooks.addHook = function (hook) {
|
|
10
|
+
hooks.add(hook);
|
|
11
|
+
return () => {
|
|
12
|
+
hooks.delete(hook);
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
const contexts = new Map();
|
|
16
|
+
const activeUndoers = new Map();
|
|
17
|
+
// Helper to capture current hooks state
|
|
18
|
+
function captureRestorers() {
|
|
19
|
+
if (hooks.size === 0)
|
|
20
|
+
return [];
|
|
21
|
+
const restorers = [];
|
|
22
|
+
for (const h of hooks) {
|
|
23
|
+
const r = h();
|
|
24
|
+
if (r)
|
|
25
|
+
restorers.push(r);
|
|
26
|
+
}
|
|
27
|
+
return restorers;
|
|
28
|
+
}
|
|
29
|
+
// Manual Wrap function to handle Promise callbacks
|
|
30
|
+
function wrap(fn) {
|
|
31
|
+
if (typeof fn !== 'function')
|
|
32
|
+
return fn;
|
|
33
|
+
const restorers = captureRestorers();
|
|
34
|
+
if (restorers.length === 0)
|
|
35
|
+
return fn;
|
|
36
|
+
return function (...args) {
|
|
37
|
+
const undoers = [];
|
|
38
|
+
for (const restore of restorers) {
|
|
39
|
+
const u = restore();
|
|
40
|
+
if (u)
|
|
41
|
+
undoers.push(u);
|
|
42
|
+
}
|
|
43
|
+
try {
|
|
44
|
+
return fn.apply(this, args);
|
|
45
|
+
}
|
|
46
|
+
finally {
|
|
47
|
+
for (let i = undoers.length - 1; i >= 0; i--)
|
|
48
|
+
undoers[i]();
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
const hook = node_async_hooks.createHook({
|
|
53
|
+
init(asyncId, type, triggerId, resource) {
|
|
54
|
+
// Used for native resources like Timers
|
|
55
|
+
const restorers = captureRestorers();
|
|
56
|
+
if (restorers.length > 0)
|
|
57
|
+
contexts.set(asyncId, restorers);
|
|
58
|
+
},
|
|
59
|
+
before(asyncId) {
|
|
60
|
+
const restorers = contexts.get(asyncId);
|
|
61
|
+
if (!restorers)
|
|
62
|
+
return;
|
|
63
|
+
const undoers = [];
|
|
64
|
+
for (const restore of restorers) {
|
|
65
|
+
const u = restore();
|
|
66
|
+
if (u)
|
|
67
|
+
undoers.push(u);
|
|
68
|
+
}
|
|
69
|
+
if (undoers.length > 0)
|
|
70
|
+
activeUndoers.set(asyncId, undoers);
|
|
71
|
+
},
|
|
72
|
+
after(asyncId) {
|
|
73
|
+
const undoers = activeUndoers.get(asyncId);
|
|
74
|
+
if (!undoers)
|
|
75
|
+
return;
|
|
76
|
+
for (let i = undoers.length - 1; i >= 0; i--)
|
|
77
|
+
undoers[i]();
|
|
78
|
+
activeUndoers.delete(asyncId);
|
|
79
|
+
},
|
|
80
|
+
destroy(asyncId) {
|
|
81
|
+
contexts.delete(asyncId);
|
|
82
|
+
activeUndoers.delete(asyncId);
|
|
83
|
+
},
|
|
84
|
+
});
|
|
85
|
+
hook.enable();
|
|
86
|
+
// 2. Shadow Promise Implementation
|
|
87
|
+
// Ensures V8 await resumptions are visible as .then callbacks, wrapping them to restore context.
|
|
88
|
+
const OriginalPromise = globalThis.Promise;
|
|
89
|
+
const originalMethods = {
|
|
90
|
+
then: OriginalPromise.prototype.then,
|
|
91
|
+
catch: OriginalPromise.prototype.catch,
|
|
92
|
+
finally: OriginalPromise.prototype.finally};
|
|
93
|
+
// Patch prototype
|
|
94
|
+
OriginalPromise.prototype.then = function (onFulfilled, onRejected) {
|
|
95
|
+
return originalMethods.then.call(this, wrap(onFulfilled), wrap(onRejected));
|
|
96
|
+
};
|
|
97
|
+
OriginalPromise.prototype.catch = function (onRejected) {
|
|
98
|
+
return originalMethods.catch.call(this, wrap(onRejected));
|
|
99
|
+
};
|
|
100
|
+
OriginalPromise.prototype.finally = function (onFinally) {
|
|
101
|
+
return originalMethods.finally.call(this, wrap(onFinally));
|
|
102
|
+
};
|
|
103
|
+
//# sourceMappingURL=async-node-BYHuGTni.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"async-node-BYHuGTni.cjs","sources":["../../src/async/node.ts"],"sourcesContent":["import { createHook } from 'node:async_hooks'\nimport { Hook, Restorer, asyncHooks } from '.'\n\n// 1. Generic async_hooks implementation for Hooks\n// This maintains support for 'asyncHooks.addHook' for generic use cases.\n\nconst hooks = new Set<Hook>()\nasyncHooks.addHook = function (hook: Hook) {\n\thooks.add(hook)\n\treturn () => {\n\t\thooks.delete(hook)\n\t}\n}\n\nconst contexts = new Map<number, Restorer[]>()\nconst activeUndoers = new Map<number, (() => void)[]>()\n\n// Helper to capture current hooks state\nfunction captureRestorers() {\n\tif (hooks.size === 0) return []\n\tconst restorers: Restorer[] = []\n\tfor (const h of hooks) {\n\t\tconst r = h()\n\t\tif (r) restorers.push(r)\n\t}\n\treturn restorers\n}\n\n// Manual Wrap function to handle Promise callbacks\nfunction wrap<Args extends any[], R>(fn: ((...args: Args) => R) | null | undefined) {\n\tif (typeof fn !== 'function') return fn\n\tconst restorers = captureRestorers()\n\tif (restorers.length === 0) return fn\n\n\treturn function (this: any, ...args: Args) {\n\t\tconst undoers: (() => void)[] = []\n\t\tfor (const restore of restorers) {\n\t\t\tconst u = restore()\n\t\t\tif (u) undoers.push(u)\n\t\t}\n\t\ttry {\n\t\t\treturn fn.apply(this, args)\n\t\t} finally {\n\t\t\tfor (let i = undoers.length - 1; i >= 0; i--) undoers[i]()\n\t\t}\n\t}\n}\n\nconst hook = createHook({\n\tinit(asyncId, type, triggerId, resource) {\n\t\t// Used for native resources like Timers\n\t\tconst restorers = captureRestorers()\n\t\tif (restorers.length > 0) contexts.set(asyncId, restorers)\n\t},\n\tbefore(asyncId) {\n\t\tconst restorers = contexts.get(asyncId)\n\t\tif (!restorers) return\n\t\tconst undoers: (() => void)[] = []\n\t\tfor (const restore of restorers) {\n\t\t\tconst u = restore()\n\t\t\tif (u) undoers.push(u)\n\t\t}\n\t\tif (undoers.length > 0) activeUndoers.set(asyncId, undoers)\n\t},\n\tafter(asyncId) {\n\t\tconst undoers = activeUndoers.get(asyncId)\n\t\tif (!undoers) return\n\t\tfor (let i = undoers.length - 1; i >= 0; i--) undoers[i]()\n\t\tactiveUndoers.delete(asyncId)\n\t},\n\tdestroy(asyncId) {\n\t\tcontexts.delete(asyncId)\n\t\tactiveUndoers.delete(asyncId)\n\t},\n})\nhook.enable()\n\n// 2. Shadow Promise Implementation\n// Ensures V8 await resumptions are visible as .then callbacks, wrapping them to restore context.\n\nconst OriginalPromise = globalThis.Promise\nconst originalMethods = {\n\tthen: OriginalPromise.prototype.then,\n\tcatch: OriginalPromise.prototype.catch,\n\tfinally: OriginalPromise.prototype.finally,\n\tresolve: OriginalPromise.resolve,\n\treject: OriginalPromise.reject,\n\tall: OriginalPromise.all,\n}\n\n\n\n// Patch prototype\nOriginalPromise.prototype.then = function(onFulfilled, onRejected) {\n\treturn originalMethods.then.call(this, wrap(onFulfilled), wrap(onRejected))\n} as any\nOriginalPromise.prototype.catch = function(onRejected) {\n\treturn originalMethods.catch.call(this, wrap(onRejected))\n} as any\nOriginalPromise.prototype.finally = function(onFinally) {\n\treturn originalMethods.finally.call(this, wrap(onFinally))\n} as any\n\n\n"],"names":["asyncHooks","createHook"],"mappings":";;;;;AAGA;AACA;AAEA,MAAM,KAAK,GAAG,IAAI,GAAG,EAAQ;AAC7BA,oBAAU,CAAC,OAAO,GAAG,UAAU,IAAU,EAAA;AACxC,IAAA,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC;AACf,IAAA,OAAO,MAAK;AACX,QAAA,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC;AACnB,IAAA,CAAC;AACF,CAAC;AAED,MAAM,QAAQ,GAAG,IAAI,GAAG,EAAsB;AAC9C,MAAM,aAAa,GAAG,IAAI,GAAG,EAA0B;AAEvD;AACA,SAAS,gBAAgB,GAAA;AACxB,IAAA,IAAI,KAAK,CAAC,IAAI,KAAK,CAAC;AAAE,QAAA,OAAO,EAAE;IAC/B,MAAM,SAAS,GAAe,EAAE;AAChC,IAAA,KAAK,MAAM,CAAC,IAAI,KAAK,EAAE;AACtB,QAAA,MAAM,CAAC,GAAG,CAAC,EAAE;AACb,QAAA,IAAI,CAA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