mutts 1.0.11 → 1.0.13

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.
Files changed (59) hide show
  1. package/README.md +5 -2
  2. package/dist/browser.cjs +237 -2596
  3. package/dist/browser.cjs.map +1 -1
  4. package/dist/browser.d.ts +1407 -2
  5. package/dist/browser.dev.cjs +44 -43
  6. package/dist/browser.dev.cjs.map +1 -1
  7. package/dist/browser.dev.d.ts +2 -2
  8. package/dist/browser.dev.esm.js +2 -2
  9. package/dist/browser.esm.js +3 -3
  10. package/dist/chunks/index-CAdnMJev.cjs +2735 -0
  11. package/dist/chunks/index-CAdnMJev.cjs.map +1 -0
  12. package/dist/chunks/{index-Sf74wXTV.esm.js → index-XsYTUhHx.esm.js} +200 -77
  13. package/dist/chunks/index-XsYTUhHx.esm.js.map +1 -0
  14. package/dist/chunks/{async-node-3PrbVAbB.cjs → node-DrrphEPf.cjs} +4 -4
  15. package/dist/chunks/node-DrrphEPf.cjs.map +1 -0
  16. package/dist/chunks/{node-Bo7WU5S2.esm.js → node-NEZvVo4M.esm.js} +2 -2
  17. package/dist/chunks/{node-Bo7WU5S2.esm.js.map → node-NEZvVo4M.esm.js.map} +1 -1
  18. package/dist/chunks/{proxy-D2C49sXH.esm.js → proxy-BtmPFjSr.esm.js} +307 -66
  19. package/dist/chunks/proxy-BtmPFjSr.esm.js.map +1 -0
  20. package/dist/chunks/{proxy-Cc79Lrzj.cjs → proxy-DBHj3kGK.cjs} +341 -70
  21. package/dist/chunks/proxy-DBHj3kGK.cjs.map +1 -0
  22. package/dist/debug.cjs +537 -167
  23. package/dist/debug.cjs.map +1 -1
  24. package/dist/debug.d.ts +96 -80
  25. package/dist/debug.esm.js +533 -166
  26. package/dist/debug.esm.js.map +1 -1
  27. package/dist/devtools/panel.js.map +1 -1
  28. package/dist/mutts.umd.js +508 -140
  29. package/dist/mutts.umd.js.map +1 -1
  30. package/dist/mutts.umd.min.js +1 -1
  31. package/dist/mutts.umd.min.js.map +1 -1
  32. package/dist/node.cjs +44 -42
  33. package/dist/node.cjs.map +1 -1
  34. package/dist/node.d.ts +2 -2
  35. package/dist/node.dev.cjs +44 -42
  36. package/dist/node.dev.cjs.map +1 -1
  37. package/dist/node.dev.d.ts +2 -2
  38. package/dist/node.dev.esm.js +3 -3
  39. package/dist/node.esm.js +3 -3
  40. package/dist/{types-Bx2PhORg.d.ts → types.d.ts} +12 -0
  41. package/docs/ai/api-reference.md +102 -12
  42. package/docs/ai/manual.md +60 -24
  43. package/docs/debug-getReason.md +161 -0
  44. package/docs/flavored.md +98 -1
  45. package/docs/reactive/advanced.md +15 -2
  46. package/docs/reactive/attend.md +32 -0
  47. package/docs/reactive/core.md +40 -6
  48. package/docs/reactive/debugging.md +25 -2
  49. package/docs/reactive.md +2 -0
  50. package/package.json +2 -3
  51. package/dist/chunks/async-browser-Dgr5CreQ.cjs +0 -218
  52. package/dist/chunks/async-browser-Dgr5CreQ.cjs.map +0 -1
  53. package/dist/chunks/async-core-CRLKP3l-.cjs +0 -29
  54. package/dist/chunks/async-core-CRLKP3l-.cjs.map +0 -1
  55. package/dist/chunks/async-node-3PrbVAbB.cjs.map +0 -1
  56. package/dist/chunks/index-Sf74wXTV.esm.js.map +0 -1
  57. package/dist/chunks/proxy-Cc79Lrzj.cjs.map +0 -1
  58. package/dist/chunks/proxy-D2C49sXH.esm.js.map +0 -1
  59. package/dist/index.d.ts +0 -1322
@@ -212,6 +212,8 @@ import 'mutts/debug';
212
212
 
213
213
  When an effect or watcher re-runs, it receives a `reaction` property (in `EffectAccess`) that describes *why* it was triggered. This is also passed to the `cleanup` function.
214
214
 
215
+ Reasons may be chained. For example, a `propChange` can carry an `external` chain entry when the reactive work ultimately originated from a captioned `root` or `untracked` call such as ``root`event:click`(...)``.
216
+
215
217
  ```typescript
216
218
  effect(({ reaction }) => {
217
219
  if (reaction && typeof reaction === 'object') {
@@ -246,10 +248,11 @@ effect(()=> {
246
248
 
247
249
  Lineage tracking allows you to see the "causal path" of an effect—not just the current stack trace, but the stack traces of all parent effects that created the current execution.
248
250
 
249
- When an effect is created, it is assigned a `lineage` property that contains the stack traces of all parent effects that lead to its creation.
251
+ When an effect is created, it is assigned a lineage signature. The raw stack/effect data is captured up front, but digestion into human-readable segments is deferred until display.
250
252
 
251
253
  - **`logLineage()`**: Prints a formatted, interactive tree of the current effect's lineage to the console.
252
254
  - **`captureLineage()`**: Captures the current lineage as a structured object.
255
+ - **`digestLineage()`**: Converts a captured lineage signature into display-ready segments on demand.
253
256
 
254
257
  #### Lineage Options
255
258
 
@@ -266,8 +269,28 @@ When `mutts/debug` is active (or after calling `enableDevTools()`), a global `__
266
269
  This object provides low-level access to the graph, lineage capture, and renaming utilities:
267
270
  - `__MUTTS_DEBUG__.getGraph()`: Returns the full reactivity graph.
268
271
  - `__MUTTS_DEBUG__.logLineage()`: logs the current lineage.
269
- - `__MUTTS_DEBUG__.browserLineage`: captures lineage for the DevTools panel.
272
+ - `__MUTTS_DEBUG__.logReason()`: logs the current reasons chain.
273
+ - `__MUTTS_DEBUG__.reason`: the current `CleanupReason` for the active effect re-run, if any.
274
+ - `__MUTTS_DEBUG__.lineage`: the current execution lineage, already digested into user-facing segments.
270
275
 
271
276
  ### Custom DevTools Formatters
272
277
 
273
278
  `mutts/debug` automatically registers [Custom Formatters](https://bit.ly/chrome-extension-custom-formatters) in Chrome. This makes lineage objects and reactive proxies appear as clean, structured trees in the console instead of opaque Proxy objects.
279
+
280
+ #### Debugger / DevTools how-to
281
+
282
+ To inspect reactive debugging data directly in Chrome DevTools:
283
+
284
+ 1. Allow **Custom formatters** in DevTools settings.
285
+ 2. Import `mutts/debug` somewhere in your application source during development:
286
+
287
+ ```typescript
288
+ import 'mutts/debug'
289
+ ```
290
+
291
+ 3. Open DevTools and inspect the global `__MUTTS_DEBUG__` helper.
292
+
293
+ The most useful live entry points you can keep on watch are:
294
+
295
+ - `__MUTTS_DEBUG__.lineage`: Gives you the static "call stack" that produced this effect (without the cuts of batching)
296
+ - `__MUTTS_DEBUG__.reason`: Gives you the chain of reasons who lead the code who is run to be run - starting from initialization or events
package/docs/reactive.md CHANGED
@@ -5,6 +5,7 @@ The Mutts Reactive System documentation has been split into focused sections for
5
5
  ## [Core Concepts](./reactive/core.md)
6
6
  * **[Core API](./reactive/core.md#core-api)**: `reactive`, `effect`, `unwrap`
7
7
  * **[Effect System](./reactive/core.md#effect-system)**: Dependency tracking, cleanups, async effects
8
+ * **[Captioned Calls](./reactive/core.md#effect)**: tagged-template naming for callback-first APIs such as `effect`
8
9
  * **[Class Reactivity](./reactive/core.md#class-reactivity)**: Decorators and functional syntax
9
10
 
10
11
  ## [Collections](./reactive/collections.md)
@@ -12,6 +13,7 @@ The Mutts Reactive System documentation has been split into focused sections for
12
13
  * **[Reactive Arrays](./reactive/collections.md#reactivearray)**: Full array method support
13
14
  * **[Morphing](./reactive/collections.md#morph)**: `morph`, `organized`
14
15
  * **[Attend](./reactive/attend.md)**: Reactive enumeration (`attend`)
16
+ * **[Captioned Collection Callbacks](./reactive/attend.md#captioned-callback-form)**: tagged-template naming for second-argument callbacks like `attend`
15
17
  * **[Resource](./reactive/resource.md)**: Async state tracking (`resource`)
16
18
 
17
19
  ## [Advanced Topics](./reactive/advanced.md)
package/package.json CHANGED
@@ -1,10 +1,9 @@
1
1
  {
2
2
  "name": "mutts",
3
3
  "description": "Modern UTility TS: A collection of TypeScript utilities",
4
- "version": "1.0.11",
4
+ "version": "1.0.13",
5
5
  "main": "dist/browser.cjs",
6
6
  "module": "dist/browser.esm.js",
7
- "types": "./dist/index.d.ts",
8
7
  "exports": {
9
8
  ".": {
10
9
  "node": {
@@ -160,7 +159,7 @@
160
159
  "@rollup/plugin-commonjs": "^28.0.6",
161
160
  "@rollup/plugin-json": "^6.1.0",
162
161
  "@rollup/plugin-node-resolve": "^16.0.1",
163
- "@rollup/plugin-terser": "^0.4.4",
162
+ "@rollup/plugin-terser": "^1.0.0",
164
163
  "@rollup/plugin-typescript": "^12.1.4",
165
164
  "@types/node": "^22.10.10",
166
165
  "@vitest/browser": "^4.0.18",
@@ -1,218 +0,0 @@
1
- 'use strict';
2
-
3
- var asyncCore = require('./async-core-CRLKP3l-.cjs');
4
-
5
- const promiseContexts = new WeakMap();
6
- // [HACK]: Sanitization
7
- // If a Promise is created inside the zone, it carries the "Sticky" zone context.
8
- // If returned to the outer scope, that context leaks. We wrap it in a new Promise
9
- // created here (in the outer scope) to break the chain and sanitize the return value.
10
- // See BROWSER_ASYNC_POLYFILL.md for full details.
11
- asyncCore.asyncHooks.sanitizePromise = (res) => {
12
- if (res && typeof res.then === 'function') {
13
- return new Promise((resolve, reject) => {
14
- setTimeout(() => {
15
- res.then(resolve, reject);
16
- }, 0);
17
- });
18
- }
19
- return res;
20
- };
21
- function captureRestorers() {
22
- const restorers = new Set();
23
- for (const hook of asyncCore.hooks) {
24
- const restorer = hook();
25
- if (restorer)
26
- restorers.add(restorer);
27
- }
28
- return restorers;
29
- }
30
- function wrap(fn, capturedRestorers) {
31
- if (typeof fn !== 'function')
32
- return fn;
33
- const restorers = capturedRestorers || captureRestorers();
34
- return function (...args) {
35
- const undoers = [];
36
- for (const restore of restorers)
37
- undoers.push(restore());
38
- try {
39
- return fn.apply(this, args);
40
- }
41
- finally {
42
- /* cf BROWSER_ASYNC_POLYFILL.md
43
- // Note: my fear about this code: in between 2~3~4 microtask waits, some other microtasks might have started, stopped, ...
44
- // We might be in the middle of another promise hook trying to setup the zone
45
- // TODO We might wish to have a flag :asyncZone.acquired - like a semaphore - that we falsify here and set back when we setup the zone
46
- // - but this might perhaps be an overkill creating more problems than it solves
47
- if (originals.queueMicrotask) {
48
- // Double microtask ensures we run after the first await resumption microtask
49
- originals.queueMicrotask.call(globalThis, () => {
50
- originals.queueMicrotask.call(globalThis, () => {
51
- originals.queueMicrotask.call(globalThis, () => {
52
- for (let i = undoers.length - 1; i >= 0; i--) undoers[i]()
53
- })
54
- })
55
- })
56
- } else {
57
- for (let i = undoers.length - 1; i >= 0; i--) undoers[i]()
58
- }*/
59
- }
60
- };
61
- }
62
- const GLOBAL_ORIGINALS = Symbol.for('mutts.originals');
63
- const GLOBAL_PROMISE = Symbol.for('mutts.OriginalPromise');
64
- let originals;
65
- let OriginalPromise;
66
- if (globalThis[GLOBAL_ORIGINALS]) {
67
- originals = globalThis[GLOBAL_ORIGINALS];
68
- OriginalPromise = globalThis[GLOBAL_PROMISE];
69
- }
70
- else {
71
- OriginalPromise = globalThis.Promise;
72
- originals = {
73
- // biome-ignore lint/suspicious/noThenProperty: Intentional Promise.prototype patching
74
- then: OriginalPromise.prototype.then,
75
- catch: OriginalPromise.prototype.catch,
76
- finally: OriginalPromise.prototype.finally,
77
- resolve: OriginalPromise.resolve,
78
- reject: OriginalPromise.reject,
79
- all: OriginalPromise.all,
80
- allSettled: OriginalPromise.allSettled,
81
- race: OriginalPromise.race,
82
- any: OriginalPromise.any,
83
- setTimeout: globalThis.setTimeout,
84
- setInterval: globalThis.setInterval,
85
- setImmediate: globalThis.setImmediate,
86
- requestAnimationFrame: globalThis.requestAnimationFrame,
87
- queueMicrotask: globalThis.queueMicrotask,
88
- };
89
- globalThis[GLOBAL_ORIGINALS] = originals;
90
- globalThis[GLOBAL_PROMISE] = OriginalPromise;
91
- }
92
- // Ensure modern statics are captured even if originals was cached from an older version
93
- if (!originals.allSettled)
94
- originals.allSettled = OriginalPromise.allSettled;
95
- if (!originals.any)
96
- originals.any = OriginalPromise.any;
97
- if (!originals.race)
98
- originals.race = OriginalPromise.race;
99
- function patchedThen(onFulfilled, onRejected) {
100
- const context = promiseContexts.get(this) || captureRestorers();
101
- const nextPromise = originals.then.call(this, wrap(onFulfilled, context), wrap(onRejected, context));
102
- if (context.size > 0)
103
- promiseContexts.set(nextPromise, context);
104
- return nextPromise;
105
- }
106
- function patchedCatch(onRejected) {
107
- const context = promiseContexts.get(this) || captureRestorers();
108
- const nextPromise = originals.catch.call(this, wrap(onRejected, context));
109
- if (context.size > 0)
110
- promiseContexts.set(nextPromise, context);
111
- return nextPromise;
112
- }
113
- function patchedFinally(onFinally) {
114
- const context = promiseContexts.get(this) || captureRestorers();
115
- const nextPromise = originals.finally.call(this, wrap(onFinally, context));
116
- if (context.size > 0)
117
- promiseContexts.set(nextPromise, context);
118
- return nextPromise;
119
- }
120
- function PatchedPromise(executor) {
121
- if (typeof executor === 'function') {
122
- const p = new OriginalPromise((resolve, reject) => {
123
- const wrappedResolve = wrap(resolve);
124
- const wrappedReject = wrap(reject);
125
- executor(wrappedResolve, wrappedReject);
126
- });
127
- const context = captureRestorers();
128
- promiseContexts.set(p, context); // Always set, even if empty (Sticky Root)
129
- return p;
130
- }
131
- return new OriginalPromise(executor);
132
- }
133
- // Copy statics
134
- Object.assign(PatchedPromise, OriginalPromise);
135
- // Inherit prototype for instanceof checks
136
- PatchedPromise.prototype = OriginalPromise.prototype;
137
- PatchedPromise.resolve = ((value) => {
138
- const p = originals.resolve.call(OriginalPromise, value);
139
- const context = captureRestorers();
140
- // Ensure we don't overwrite if it already has context (e.g. from constructor)
141
- if (context.size > 0 && !promiseContexts.has(p))
142
- promiseContexts.set(p, context);
143
- return p;
144
- });
145
- PatchedPromise.reject = ((reason) => {
146
- const p = originals.reject.call(OriginalPromise, reason);
147
- const context = captureRestorers();
148
- if (context.size > 0)
149
- promiseContexts.set(p, context);
150
- return p;
151
- });
152
- PatchedPromise.all = ((values) => {
153
- const p = originals.all.call(OriginalPromise, values);
154
- const context = captureRestorers();
155
- if (context.size > 0)
156
- promiseContexts.set(p, context);
157
- return p;
158
- });
159
- PatchedPromise.allSettled = ((values) => {
160
- const p = originals.allSettled.call(OriginalPromise, values);
161
- const context = captureRestorers();
162
- if (context.size > 0)
163
- promiseContexts.set(p, context);
164
- return p;
165
- });
166
- PatchedPromise.race = ((values) => {
167
- const p = originals.race.call(OriginalPromise, values);
168
- const context = captureRestorers();
169
- if (context.size > 0)
170
- promiseContexts.set(p, context);
171
- return p;
172
- });
173
- PatchedPromise.any = ((values) => {
174
- const p = originals.any.call(OriginalPromise, values);
175
- const context = captureRestorers();
176
- if (context.size > 0)
177
- promiseContexts.set(p, context);
178
- return p;
179
- });
180
- // Only apply patches if not already applied (or re-apply safely)
181
- // Note: OriginalPromise.prototype might be shared if we used the global one.
182
- // We must ensure we don't patch it twice if it's the SAME object.
183
- if (OriginalPromise.prototype.then !== patchedThen) {
184
- // biome-ignore lint/suspicious/noThenProperty: Intentional Promise.prototype patching
185
- OriginalPromise.prototype.then = patchedThen;
186
- OriginalPromise.prototype.catch = patchedCatch;
187
- OriginalPromise.prototype.finally = patchedFinally;
188
- }
189
- try {
190
- Object.defineProperty(OriginalPromise, Symbol.species, {
191
- get: () => PatchedPromise,
192
- configurable: true,
193
- });
194
- }
195
- catch (_e) { }
196
- globalThis.Promise = PatchedPromise;
197
- globalThis.setTimeout = ((callback, ...args) => {
198
- return originals.setTimeout.call(globalThis, wrap(callback), ...args);
199
- });
200
- globalThis.setInterval = ((callback, ...args) => {
201
- return originals.setInterval.call(globalThis, wrap(callback), ...args);
202
- });
203
- if (originals.setImmediate) {
204
- globalThis.setImmediate = ((callback, ...args) => {
205
- return originals.setImmediate.call(globalThis, wrap(callback), ...args);
206
- });
207
- }
208
- if (originals.requestAnimationFrame) {
209
- globalThis.requestAnimationFrame = (callback) => {
210
- return originals.requestAnimationFrame.call(globalThis, wrap(callback));
211
- };
212
- }
213
- if (originals.queueMicrotask) {
214
- globalThis.queueMicrotask = (callback) => {
215
- originals.queueMicrotask.call(globalThis, wrap(callback));
216
- };
217
- }
218
- //# sourceMappingURL=async-browser-Dgr5CreQ.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"async-browser-Dgr5CreQ.cjs","sources":["../../src/async/browser.ts"],"sourcesContent":["import { asyncHooks, hooks, type Restorer } from '.'\n\nconst promiseContexts = new WeakMap<Promise<any>, Set<Restorer>>()\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\tif (res && typeof (res as any).then === 'function') {\n\t\treturn new Promise((resolve, reject) => {\n\t\t\tsetTimeout(() => {\n\t\t\t\t;(res as any).then(resolve, reject)\n\t\t\t}, 0)\n\t\t})\n\t}\n\treturn 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>(\n\tfn: ((...args: Args) => R) | null | undefined,\n\tcapturedRestorers?: Set<Restorer>\n) {\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\t/* cf BROWSER_ASYNC_POLYFILL.md\n\t\t\t// Note: my fear about this code: in between 2~3~4 microtask waits, some other microtasks might have started, stopped, ...\n\t\t\t// We might be in the middle of another promise hook trying to setup the zone\n\t\t\t// TODO We might wish to have a flag :asyncZone.acquired - like a semaphore - that we falsify here and set back when we setup the zone\n\t\t\t// - but this might perhaps be an overkill creating more problems than it solves\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 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\toriginals = (globalThis as any)[GLOBAL_ORIGINALS]\n\tOriginalPromise = (globalThis as any)[GLOBAL_PROMISE]\n} else {\n\tOriginalPromise = globalThis.Promise\n\toriginals = {\n\t\t// biome-ignore lint/suspicious/noThenProperty: Intentional Promise.prototype patching\n\t\tthen: OriginalPromise.prototype.then,\n\t\tcatch: OriginalPromise.prototype.catch,\n\t\tfinally: OriginalPromise.prototype.finally,\n\t\tresolve: OriginalPromise.resolve,\n\t\treject: OriginalPromise.reject,\n\t\tall: OriginalPromise.all,\n\t\tallSettled: (OriginalPromise as any).allSettled,\n\t\trace: OriginalPromise.race,\n\t\tany: (OriginalPromise as any).any,\n\t\tsetTimeout: globalThis.setTimeout,\n\t\tsetInterval: globalThis.setInterval,\n\t\tsetImmediate: (globalThis as any).setImmediate,\n\t\trequestAnimationFrame: (globalThis as any).requestAnimationFrame,\n\t\tqueueMicrotask: globalThis.queueMicrotask,\n\t}\n\t;(globalThis as any)[GLOBAL_ORIGINALS] = originals\n\t;(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(\n\t\tthis,\n\t\twrap(onFulfilled, context),\n\t\twrap(onRejected, context)\n\t)\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>(\n\tthis: any,\n\texecutor: (resolve: (value: T | PromiseLike<T>) => void, reject: (reason?: any) => void) => void\n) {\n\tif (typeof executor === 'function') {\n\t\tconst p = new OriginalPromise((resolve, reject) => {\n\t\t\tconst wrappedResolve = wrap(resolve)\n\t\t\tconst wrappedReject = wrap(reject)\n\t\t\texecutor(wrappedResolve, wrappedReject)\n\t\t})\n\t\tconst context = captureRestorers()\n\t\tpromiseContexts.set(p, context) // Always set, even if empty (Sticky Root)\n\t\treturn p\n\t}\n\treturn 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 = (<T>(value?: T | PromiseLike<T>): Promise<T> => {\n\tconst p = originals.resolve.call(OriginalPromise, value) as Promise<T>\n\tconst context = captureRestorers()\n\t// Ensure we don't overwrite if it already has context (e.g. from constructor)\n\tif (context.size > 0 && !promiseContexts.has(p)) promiseContexts.set(p, context)\n\treturn p\n}) as any\n\nPatchedPromise.reject = (<T = never>(reason?: any): Promise<T> => {\n\tconst p = originals.reject.call(OriginalPromise, reason) as Promise<T>\n\tconst context = captureRestorers()\n\tif (context.size > 0) promiseContexts.set(p, context)\n\treturn p\n}) as any\n\nPatchedPromise.all = (<T>(values: Iterable<T | PromiseLike<T>>): Promise<Awaited<T>[]> => {\n\tconst p = originals.all.call(OriginalPromise, values) as Promise<Awaited<T>[]>\n\tconst context = captureRestorers()\n\tif (context.size > 0) promiseContexts.set(p, context)\n\treturn p\n}) as any\n\nPatchedPromise.allSettled = (<T>(\n\tvalues: Iterable<T | PromiseLike<T>>\n): Promise<PromiseSettledResult<Awaited<T>>[]> => {\n\tconst p = (originals.allSettled as any).call(OriginalPromise, values)\n\tconst context = captureRestorers()\n\tif (context.size > 0) promiseContexts.set(p, context)\n\treturn p\n}) as any\n\nPatchedPromise.race = (<T>(values: Iterable<T | PromiseLike<T>>): Promise<Awaited<T>> => {\n\tconst p = originals.race.call(OriginalPromise, values) as Promise<Awaited<T>>\n\tconst context = captureRestorers()\n\tif (context.size > 0) promiseContexts.set(p, context)\n\treturn p\n}) as any\n\nPatchedPromise.any = (<T>(values: Iterable<T | PromiseLike<T>>): Promise<Awaited<T>> => {\n\tconst p = (originals.any as any).call(OriginalPromise, values)\n\tconst context = captureRestorers()\n\tif (context.size > 0) promiseContexts.set(p, context)\n\treturn 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\t// biome-ignore lint/suspicious/noThenProperty: Intentional Promise.prototype patching\n\tOriginalPromise.prototype.then = patchedThen as any\n\tOriginalPromise.prototype.catch = patchedCatch as any\n\tOriginalPromise.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","hooks"],"mappings":";;;;AAEA,MAAM,eAAe,GAAG,IAAI,OAAO,EAA+B;AAElE;AACA;AACA;AACA;AACA;AACAA,oBAAU,CAAC,eAAe,GAAG,CAAC,GAAQ,KAAI;IACzC,IAAI,GAAG,IAAI,OAAQ,GAAW,CAAC,IAAI,KAAK,UAAU,EAAE;QACnD,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,KAAI;YACtC,UAAU,CAAC,MAAK;AACb,gBAAA,GAAW,CAAC,IAAI,CAAC,OAAO,EAAE,MAAM,CAAC;YACpC,CAAC,EAAE,CAAC,CAAC;AACN,QAAA,CAAC,CAAC;IACH;AACA,IAAA,OAAO,GAAG;AACX,CAAC;AAED,SAAS,gBAAgB,GAAA;AACxB,IAAA,MAAM,SAAS,GAAG,IAAI,GAAG,EAAY;AACrC,IAAA,KAAK,MAAM,IAAI,IAAIC,eAAK,EAAE;AACzB,QAAA,MAAM,QAAQ,GAAG,IAAI,EAAE;AACvB,QAAA,IAAI,QAAQ;AAAE,YAAA,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC;IACtC;AACA,IAAA,OAAO,SAAS;AACjB;AAEA,SAAS,IAAI,CACZ,EAA6C,EAC7C,iBAAiC,EAAA;IAEjC,IAAI,OAAO,EAAE,KAAK,UAAU;AAAE,QAAA,OAAO,EAAE;AACvC,IAAA,MAAM,SAAS,GAAG,iBAAiB,IAAI,gBAAgB,EAAE;IACzD,OAAO,UAAqB,GAAG,IAAU,EAAA;QACxC,MAAM,OAAO,GAAmB,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AC;AAC7E,CAAC,CAAQ;AAET,UAAU,CAAC,WAAW,IAAI,CAAC,QAAkB,EAAE,GAAG,IAAW,KAAI;AAChE,IAAA,OAAO,SAAS,CAAC,WAAW,CAAC,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,QAAe,CAAC,EAAE,GAAG,IAAI,CAAC;AAC9E,CAAC,CAAQ;AAET,IAAI,SAAS,CAAC,YAAY,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;;"}
@@ -1,29 +0,0 @@
1
- 'use strict';
2
-
3
- // Queue for hooks registered before the environment is ready (circular dependency fix)
4
- const hooks = new Set();
5
- const asyncHooks = {
6
- addHook(hook) {
7
- hooks.add(hook);
8
- return () => hooks.delete(hook);
9
- },
10
- /**
11
- * [Hack] Sanitize a promise (or value) to prevent context leaks.
12
- * Default: Identity function.
13
- * Browser: Uses Macrotask wrapping to break microtask chains.
14
- */
15
- sanitizePromise(p) {
16
- return p;
17
- },
18
- };
19
- /**
20
- * Register a hook that will be called whenever an asynchronous operation is initiated.
21
- * The hook should return a restorer function which will be called just before the async callback runs.
22
- * That restorer should in turn return an undoer function which will be called just after the async callback finishes.
23
- */
24
- const asyncHook = (hook) => asyncHooks.addHook(hook);
25
-
26
- exports.asyncHook = asyncHook;
27
- exports.asyncHooks = asyncHooks;
28
- exports.hooks = hooks;
29
- //# sourceMappingURL=async-core-CRLKP3l-.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"async-core-CRLKP3l-.cjs","sources":["../../src/async/index.ts"],"sourcesContent":["export type Restorer = () => () => void\nexport type Hook = () => Restorer\n\n// Queue for hooks registered before the environment is ready (circular dependency fix)\nexport const hooks = new Set<Hook>()\n\nexport const asyncHooks = {\n\taddHook(hook: Hook): () => void {\n\t\thooks.add(hook)\n\t\treturn () => hooks.delete(hook)\n\t},\n\t/**\n\t * [Hack] Sanitize a promise (or value) to prevent context leaks.\n\t * Default: Identity function.\n\t * Browser: Uses Macrotask wrapping to break microtask chains.\n\t */\n\tsanitizePromise(p: any): any {\n\t\treturn p\n\t},\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)\n"],"names":[],"mappings":";;AAGA;AACO,MAAM,KAAK,GAAG,IAAI,GAAG;AAErB,MAAM,UAAU,GAAG;AACzB,IAAA,OAAO,CAAC,IAAU,EAAA;AACjB,QAAA,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC;QACf,OAAO,MAAM,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC;IAChC,CAAC;AACD;;;;AAIG;AACH,IAAA,eAAe,CAAC,CAAM,EAAA;AACrB,QAAA,OAAO,CAAC;IACT,CAAC;;AAGF;;;;AAIG;AACI,MAAM,SAAS,GAAG,CAAC,IAAU,KAAK,UAAU,CAAC,OAAO,CAAC,IAAI;;;;;;"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"async-node-3PrbVAbB.cjs","sources":["../../src/async/node.ts"],"sourcesContent":["import { createHook } from 'node:async_hooks'\nimport { hooks, type Restorer } from '.'\n\n// 1. Generic async_hooks implementation for Hooks\n// This maintains support for 'asyncHooks.addHook' for generic use cases.\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\t// biome-ignore lint/suspicious/noThenProperty: Intentional Promise.prototype patching\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// Patch prototype\n// biome-ignore lint/suspicious/noThenProperty: Intentional Promise.prototype patching\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"],"names":["hooks","createHook"],"mappings":";;;;;AAGA;AACA;AAEA,MAAM,QAAQ,GAAG,IAAI,GAAG,EAAsB;AAC9C,MAAM,aAAa,GAAG,IAAI,GAAG,EAA0B;AAEvD;AACA,SAAS,gBAAgB,GAAA;AACxB,IAAA,IAAIA,eAAK,CAAC,IAAI,KAAK,CAAC;AAAE,QAAA,OAAO,EAAE;IAC/B,MAAM,SAAS,GAAe,EAAE;AAChC,IAAA,KAAK,MAAM,CAAC,IAAIA,eAAK,EAAE;AACtB,QAAA,MAAM,CAAC,GAAG,CAAC,EAAE;AACb,QAAA,IAAI,CAAC;AAAE,YAAA,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC;IACzB;AACA,IAAA,OAAO,SAAS;AACjB;AAEA;AACA,SAAS,IAAI,CAAwB,EAA6C,EAAA;IACjF,IAAI,OAAO,EAAE,KAAK,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