@vielzeug/ledger 2.0.1 → 2.1.1

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 CHANGED
@@ -1,14 +1,15 @@
1
1
  # @vielzeug/ledger
2
2
 
3
- Async undo/redo command history with Ripple signals for reactive `canUndo`/`canRedo` state.
3
+ Serialized reversible command history with cancellation ownership and atomic reactive state.
4
4
 
5
5
  ## Features
6
6
 
7
- - **Async commands** — `execute` and `rollback` can return `Promise<void>`; operations are serialised
8
- - **Reactive state** — `canUndo`, `canRedo`, `historySize`, `isProcessing`, `historySnapshot` are Ripple `Computed` values
9
- - **Batch** — group multiple commands into one undo step
10
- - **Max history** — configurable cap; oldest entries evicted automatically
11
- - **Disposable** — `dispose()` + `[Symbol.dispose]` for `using` declarations
7
+ - **Reversible commands** — every recorded command has `apply()` and `revert()`
8
+ - **Atomic state** — one `Readable<LedgerState>` for queue and history observation
9
+ - **Composition** — `compose()` combines reversible commands into one history entry
10
+ - **Cancellation** — queued cancelled work never starts; active work receives `AbortSignal`
11
+ - **Idle ownership** — `whenIdle()` waits for queued and active work to settle
12
+ - **History cap** — non-negative safe-integer retained depth
12
13
 
13
14
  ## Install
14
15
 
@@ -16,35 +17,27 @@ Async undo/redo command history with Ripple signals for reactive `canUndo`/`canR
16
17
  pnpm add @vielzeug/ledger
17
18
  ```
18
19
 
19
- ## Quick start
20
+ ## Quick Start
20
21
 
21
- ```typescript
22
- import { compose, createLedger } from '@vielzeug/ledger';
23
- import { effect } from '@vielzeug/ripple';
22
+ Submit reversible state transitions and dispose the owner at teardown.
24
23
 
25
- const ledger = createLedger({ maxHistory: 50 });
24
+ ```ts
25
+ import { createLedger } from '@vielzeug/ledger';
26
+
27
+ let value = 'before';
28
+ const ledger = createLedger();
26
29
 
27
- // Execute a command
28
30
  await ledger.do({
29
- execute: async () => { item.name = newName; },
30
- rollback: async () => { item.name = oldName; },
31
- label: 'Rename item',
31
+ apply: () => { value = 'after'; },
32
+ label: 'Rename value',
33
+ revert: () => { value = 'before'; },
32
34
  });
33
35
 
34
- // Undo / redo
35
36
  await ledger.undo();
36
- await ledger.redo();
37
-
38
- // Batch — compose multiple commands into one undo step
39
- await ledger.do(compose([cmd1, cmd2, cmd3], 'Multi-edit'));
40
-
41
- // Bind to UI
42
- effect(() => {
43
- undoButton.disabled = !ledger.canUndo.value;
44
- redoButton.disabled = !ledger.canRedo.value;
45
- });
46
-
47
- ledger.dispose(); // or: using ledger = createLedger()
37
+ console.log(ledger.state.value.undo.length); // 0
38
+ ledger.dispose();
48
39
  ```
49
40
 
50
- [Full docs →](https://vielzeug.dev/ledger/)
41
+ Keep irreversible side effects outside Ledger commands. Catch operation failures at your application boundary.
42
+
43
+ [Full documentation](https://vielzeug.dev/ledger/)
package/dist/compose.cjs CHANGED
@@ -1,2 +1,2 @@
1
- function e(e,t){return{execute:async t=>{let n=[];try{for(let r of e)await r.execute(t),n.push(r)}catch(e){for(let e of[...n].reverse())try{await e.rollback?.(t)}catch{}throw e}},label:t,rollback:e.some(e=>e.rollback!=null)?async t=>{let n,r=!1;for(let i of[...e].reverse())try{await i.rollback?.(t)}catch(e){r||=(n=e,!0)}if(r)throw n}:void 0}}exports.compose=e;
1
+ function e(e){let{apply:t,label:n,meta:r,revert:i}=e;return{apply:t,label:n,meta:r,revert:i}}function t(t,n){let r=t.map(e);return{apply:async e=>{let t=[];try{for(let n of r)await n.apply(e),t.push(n)}catch(n){let r=[];for(let n of[...t].reverse())try{await n.revert(e)}catch(e){r.push(e)}throw r.length>0?AggregateError([n,...r],`Command application and compensation failed`,{cause:n}):n}},label:n,revert:async e=>{let t=[];for(let n of[...r].reverse())try{await n.revert(e)}catch(e){t.push(e)}if(t.length>0)throw AggregateError(t,`Command reversion failed`)}}}exports.compose=t;
2
2
  //# sourceMappingURL=compose.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"compose.cjs","names":[],"sources":["../src/compose.ts"],"sourcesContent":["import type { Command } from './types';\n\n/**\n * Composes multiple commands into a single reversible command.\n *\n * `execute` runs all sub-commands in order. `rollback` runs them in reverse,\n * skipping any that have no rollback defined. The composed command counts as\n * one undo step.\n *\n * @example\n * await ledger.do(compose([\n * { execute: () => { node.x = newX; }, rollback: () => { node.x = oldX; } },\n * { execute: () => { node.y = newY; }, rollback: () => { node.y = oldY; } },\n * ], 'Move node'));\n */\nexport function compose<TData = unknown>(commands: Command<TData>[], label?: string): Command<TData> {\n const anyHasRollback = commands.some((c) => c.rollback != null);\n\n return {\n execute: async (signal) => {\n const done: Command<TData>[] = [];\n\n try {\n for (const c of commands) {\n await c.execute(signal);\n done.push(c);\n }\n } catch (err) {\n for (const c of [...done].reverse()) {\n try {\n await c.rollback?.(signal);\n } catch {\n // best-effort: suppress compensation errors\n }\n }\n\n throw err;\n }\n },\n label,\n rollback: anyHasRollback\n ? async (signal) => {\n let firstError: unknown;\n let hasError = false;\n\n for (const c of [...commands].reverse()) {\n try {\n await c.rollback?.(signal);\n } catch (err) {\n if (!hasError) {\n firstError = err;\n hasError = true;\n }\n }\n }\n\n if (hasError) throw firstError;\n }\n : undefined,\n };\n}\n"],"mappings":"AAeA,SAAgB,EAAyB,EAA4B,EAAgC,CAGnG,MAAO,CACL,QAAS,KAAO,IAAW,CACzB,IAAM,EAAyB,CAAC,EAEhC,GAAI,CACF,IAAK,IAAM,KAAK,EACd,MAAM,EAAE,QAAQ,CAAM,EACtB,EAAK,KAAK,CAAC,CAEf,OAAS,EAAK,CACZ,IAAK,IAAM,IAAK,CAAC,GAAG,CAAI,CAAC,CAAC,QAAQ,EAChC,GAAI,CACF,MAAM,EAAE,WAAW,CAAM,CAC3B,MAAQ,CAER,CAGF,MAAM,CACR,CACF,EACA,QACA,SAxBqB,EAAS,KAAM,GAAM,EAAE,UAAY,IAwB9C,EACN,KAAO,IAAW,CAChB,IAAI,EACA,EAAW,GAEf,IAAK,IAAM,IAAK,CAAC,GAAG,CAAQ,CAAC,CAAC,QAAQ,EACpC,GAAI,CACF,MAAM,EAAE,WAAW,CAAM,CAC3B,OAAS,EAAK,CACZ,AAEE,KADA,EAAa,EACF,GAEf,CAGF,GAAI,EAAU,MAAM,CACtB,EACA,IAAA,EACN,CACF"}
1
+ {"version":3,"file":"compose.cjs","names":[],"sources":["../src/compose.ts"],"sourcesContent":["import type { CommandContext, ReversibleCommand } from './types';\n\nfunction snapshotCommand<TMeta>(command: ReversibleCommand<TMeta>): ReversibleCommand<TMeta> {\n const { apply, label, meta, revert } = command;\n\n return { apply, label, meta, revert };\n}\n\n/**\n * Composes reversible commands into one reversible command.\n *\n * `apply` runs each child in order. `revert` runs children in reverse order.\n * A failed child application compensates completed children before rethrowing.\n *\n * @example\n * await ledger.do(compose([\n * { apply: () => { node.x = newX; }, revert: () => { node.x = oldX; } },\n * { apply: () => { node.y = newY; }, revert: () => { node.y = oldY; } },\n * ], 'Move node'));\n */\nexport function compose<TMeta = undefined>(\n commands: readonly ReversibleCommand<TMeta>[],\n label?: string,\n): ReversibleCommand<TMeta> {\n const steps = commands.map(snapshotCommand);\n\n return {\n apply: async (context: CommandContext) => {\n const applied: ReversibleCommand<TMeta>[] = [];\n\n try {\n for (const command of steps) {\n await command.apply(context);\n applied.push(command);\n }\n } catch (error) {\n const compensationFailures: unknown[] = [];\n\n for (const command of [...applied].reverse()) {\n try {\n await command.revert(context);\n } catch (compensationError) {\n compensationFailures.push(compensationError);\n }\n }\n\n if (compensationFailures.length > 0) {\n throw new AggregateError([error, ...compensationFailures], 'Command application and compensation failed', {\n cause: error,\n });\n }\n\n throw error;\n }\n },\n label,\n revert: async (context: CommandContext) => {\n const failures: unknown[] = [];\n\n for (const command of [...steps].reverse()) {\n try {\n await command.revert(context);\n } catch (error) {\n failures.push(error);\n }\n }\n\n if (failures.length > 0) throw new AggregateError(failures, 'Command reversion failed');\n },\n };\n}\n"],"mappings":"AAEA,SAAS,EAAuB,EAA6D,CAC3F,GAAM,CAAE,QAAO,QAAO,OAAM,UAAW,EAEvC,MAAO,CAAE,QAAO,QAAO,OAAM,QAAO,CACtC,CAcA,SAAgB,EACd,EACA,EAC0B,CAC1B,IAAM,EAAQ,EAAS,IAAI,CAAe,EAE1C,MAAO,CACL,MAAO,KAAO,IAA4B,CACxC,IAAM,EAAsC,CAAC,EAE7C,GAAI,CACF,IAAK,IAAM,KAAW,EACpB,MAAM,EAAQ,MAAM,CAAO,EAC3B,EAAQ,KAAK,CAAO,CAExB,OAAS,EAAO,CACd,IAAM,EAAkC,CAAC,EAEzC,IAAK,IAAM,IAAW,CAAC,GAAG,CAAO,CAAC,CAAC,QAAQ,EACzC,GAAI,CACF,MAAM,EAAQ,OAAO,CAAO,CAC9B,OAAS,EAAmB,CAC1B,EAAqB,KAAK,CAAiB,CAC7C,CASF,MANI,EAAqB,OAAS,EACtB,eAAe,CAAC,EAAO,GAAG,CAAoB,EAAG,8CAA+C,CACxG,MAAO,CACT,CAAC,EAGG,CACR,CACF,EACA,QACA,OAAQ,KAAO,IAA4B,CACzC,IAAM,EAAsB,CAAC,EAE7B,IAAK,IAAM,IAAW,CAAC,GAAG,CAAK,CAAC,CAAC,QAAQ,EACvC,GAAI,CACF,MAAM,EAAQ,OAAO,CAAO,CAC9B,OAAS,EAAO,CACd,EAAS,KAAK,CAAK,CACrB,CAGF,GAAI,EAAS,OAAS,EAAG,MAAU,eAAe,EAAU,0BAA0B,CACxF,CACF,CACF"}
package/dist/compose.d.ts CHANGED
@@ -1,16 +1,15 @@
1
- import type { Command } from './types';
1
+ import type { ReversibleCommand } from './types';
2
2
  /**
3
- * Composes multiple commands into a single reversible command.
3
+ * Composes reversible commands into one reversible command.
4
4
  *
5
- * `execute` runs all sub-commands in order. `rollback` runs them in reverse,
6
- * skipping any that have no rollback defined. The composed command counts as
7
- * one undo step.
5
+ * `apply` runs each child in order. `revert` runs children in reverse order.
6
+ * A failed child application compensates completed children before rethrowing.
8
7
  *
9
8
  * @example
10
9
  * await ledger.do(compose([
11
- * { execute: () => { node.x = newX; }, rollback: () => { node.x = oldX; } },
12
- * { execute: () => { node.y = newY; }, rollback: () => { node.y = oldY; } },
10
+ * { apply: () => { node.x = newX; }, revert: () => { node.x = oldX; } },
11
+ * { apply: () => { node.y = newY; }, revert: () => { node.y = oldY; } },
13
12
  * ], 'Move node'));
14
13
  */
15
- export declare function compose<TData = unknown>(commands: Command<TData>[], label?: string): Command<TData>;
14
+ export declare function compose<TMeta = undefined>(commands: readonly ReversibleCommand<TMeta>[], label?: string): ReversibleCommand<TMeta>;
16
15
  //# sourceMappingURL=compose.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"compose.d.ts","sourceRoot":"","sources":["../src/compose.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAEvC;;;;;;;;;;;;GAYG;AACH,wBAAgB,OAAO,CAAC,KAAK,GAAG,OAAO,EAAE,QAAQ,EAAE,OAAO,CAAC,KAAK,CAAC,EAAE,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC,CA6CnG"}
1
+ {"version":3,"file":"compose.d.ts","sourceRoot":"","sources":["../src/compose.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAkB,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAQjE;;;;;;;;;;;GAWG;AACH,wBAAgB,OAAO,CAAC,KAAK,GAAG,SAAS,EACvC,QAAQ,EAAE,SAAS,iBAAiB,CAAC,KAAK,CAAC,EAAE,EAC7C,KAAK,CAAC,EAAE,MAAM,GACb,iBAAiB,CAAC,KAAK,CAAC,CA+C1B"}
package/dist/compose.js CHANGED
@@ -1,30 +1,43 @@
1
1
  //#region src/compose.ts
2
- function e(e, t) {
2
+ function e(e) {
3
+ let { apply: t, label: n, meta: r, revert: i } = e;
3
4
  return {
4
- execute: async (t) => {
5
- let n = [];
5
+ apply: t,
6
+ label: n,
7
+ meta: r,
8
+ revert: i
9
+ };
10
+ }
11
+ function t(t, n) {
12
+ let r = t.map(e);
13
+ return {
14
+ apply: async (e) => {
15
+ let t = [];
6
16
  try {
7
- for (let r of e) await r.execute(t), n.push(r);
8
- } catch (e) {
9
- for (let e of [...n].reverse()) try {
10
- await e.rollback?.(t);
11
- } catch {}
12
- throw e;
17
+ for (let n of r) await n.apply(e), t.push(n);
18
+ } catch (n) {
19
+ let r = [];
20
+ for (let n of [...t].reverse()) try {
21
+ await n.revert(e);
22
+ } catch (e) {
23
+ r.push(e);
24
+ }
25
+ throw r.length > 0 ? AggregateError([n, ...r], "Command application and compensation failed", { cause: n }) : n;
13
26
  }
14
27
  },
15
- label: t,
16
- rollback: e.some((e) => e.rollback != null) ? async (t) => {
17
- let n, r = !1;
18
- for (let i of [...e].reverse()) try {
19
- await i.rollback?.(t);
28
+ label: n,
29
+ revert: async (e) => {
30
+ let t = [];
31
+ for (let n of [...r].reverse()) try {
32
+ await n.revert(e);
20
33
  } catch (e) {
21
- r ||= (n = e, !0);
34
+ t.push(e);
22
35
  }
23
- if (r) throw n;
24
- } : void 0
36
+ if (t.length > 0) throw AggregateError(t, "Command reversion failed");
37
+ }
25
38
  };
26
39
  }
27
40
  //#endregion
28
- export { e as compose };
41
+ export { t as compose };
29
42
 
30
43
  //# sourceMappingURL=compose.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"compose.js","names":[],"sources":["../src/compose.ts"],"sourcesContent":["import type { Command } from './types';\n\n/**\n * Composes multiple commands into a single reversible command.\n *\n * `execute` runs all sub-commands in order. `rollback` runs them in reverse,\n * skipping any that have no rollback defined. The composed command counts as\n * one undo step.\n *\n * @example\n * await ledger.do(compose([\n * { execute: () => { node.x = newX; }, rollback: () => { node.x = oldX; } },\n * { execute: () => { node.y = newY; }, rollback: () => { node.y = oldY; } },\n * ], 'Move node'));\n */\nexport function compose<TData = unknown>(commands: Command<TData>[], label?: string): Command<TData> {\n const anyHasRollback = commands.some((c) => c.rollback != null);\n\n return {\n execute: async (signal) => {\n const done: Command<TData>[] = [];\n\n try {\n for (const c of commands) {\n await c.execute(signal);\n done.push(c);\n }\n } catch (err) {\n for (const c of [...done].reverse()) {\n try {\n await c.rollback?.(signal);\n } catch {\n // best-effort: suppress compensation errors\n }\n }\n\n throw err;\n }\n },\n label,\n rollback: anyHasRollback\n ? async (signal) => {\n let firstError: unknown;\n let hasError = false;\n\n for (const c of [...commands].reverse()) {\n try {\n await c.rollback?.(signal);\n } catch (err) {\n if (!hasError) {\n firstError = err;\n hasError = true;\n }\n }\n }\n\n if (hasError) throw firstError;\n }\n : undefined,\n };\n}\n"],"mappings":";AAeA,SAAgB,EAAyB,GAA4B,GAAgC;CAGnG,OAAO;EACL,SAAS,OAAO,MAAW;GACzB,IAAM,IAAyB,CAAC;GAEhC,IAAI;IACF,KAAK,IAAM,KAAK,GAEd,AADA,MAAM,EAAE,QAAQ,CAAM,GACtB,EAAK,KAAK,CAAC;GAEf,SAAS,GAAK;IACZ,KAAK,IAAM,KAAK,CAAC,GAAG,CAAI,CAAC,CAAC,QAAQ,GAChC,IAAI;KACF,MAAM,EAAE,WAAW,CAAM;IAC3B,QAAQ,CAER;IAGF,MAAM;GACR;EACF;EACA;EACA,UAxBqB,EAAS,MAAM,MAAM,EAAE,YAAY,IAwB9C,IACN,OAAO,MAAW;GAChB,IAAI,GACA,IAAW;GAEf,KAAK,IAAM,KAAK,CAAC,GAAG,CAAQ,CAAC,CAAC,QAAQ,GACpC,IAAI;IACF,MAAM,EAAE,WAAW,CAAM;GAC3B,SAAS,GAAK;IACZ,AAEE,OADA,IAAa,GACF;GAEf;GAGF,IAAI,GAAU,MAAM;EACtB,IACA,KAAA;CACN;AACF"}
1
+ {"version":3,"file":"compose.js","names":[],"sources":["../src/compose.ts"],"sourcesContent":["import type { CommandContext, ReversibleCommand } from './types';\n\nfunction snapshotCommand<TMeta>(command: ReversibleCommand<TMeta>): ReversibleCommand<TMeta> {\n const { apply, label, meta, revert } = command;\n\n return { apply, label, meta, revert };\n}\n\n/**\n * Composes reversible commands into one reversible command.\n *\n * `apply` runs each child in order. `revert` runs children in reverse order.\n * A failed child application compensates completed children before rethrowing.\n *\n * @example\n * await ledger.do(compose([\n * { apply: () => { node.x = newX; }, revert: () => { node.x = oldX; } },\n * { apply: () => { node.y = newY; }, revert: () => { node.y = oldY; } },\n * ], 'Move node'));\n */\nexport function compose<TMeta = undefined>(\n commands: readonly ReversibleCommand<TMeta>[],\n label?: string,\n): ReversibleCommand<TMeta> {\n const steps = commands.map(snapshotCommand);\n\n return {\n apply: async (context: CommandContext) => {\n const applied: ReversibleCommand<TMeta>[] = [];\n\n try {\n for (const command of steps) {\n await command.apply(context);\n applied.push(command);\n }\n } catch (error) {\n const compensationFailures: unknown[] = [];\n\n for (const command of [...applied].reverse()) {\n try {\n await command.revert(context);\n } catch (compensationError) {\n compensationFailures.push(compensationError);\n }\n }\n\n if (compensationFailures.length > 0) {\n throw new AggregateError([error, ...compensationFailures], 'Command application and compensation failed', {\n cause: error,\n });\n }\n\n throw error;\n }\n },\n label,\n revert: async (context: CommandContext) => {\n const failures: unknown[] = [];\n\n for (const command of [...steps].reverse()) {\n try {\n await command.revert(context);\n } catch (error) {\n failures.push(error);\n }\n }\n\n if (failures.length > 0) throw new AggregateError(failures, 'Command reversion failed');\n },\n };\n}\n"],"mappings":";AAEA,SAAS,EAAuB,GAA6D;CAC3F,IAAM,EAAE,UAAO,UAAO,SAAM,cAAW;CAEvC,OAAO;EAAE;EAAO;EAAO;EAAM;CAAO;AACtC;AAcA,SAAgB,EACd,GACA,GAC0B;CAC1B,IAAM,IAAQ,EAAS,IAAI,CAAe;CAE1C,OAAO;EACL,OAAO,OAAO,MAA4B;GACxC,IAAM,IAAsC,CAAC;GAE7C,IAAI;IACF,KAAK,IAAM,KAAW,GAEpB,AADA,MAAM,EAAQ,MAAM,CAAO,GAC3B,EAAQ,KAAK,CAAO;GAExB,SAAS,GAAO;IACd,IAAM,IAAkC,CAAC;IAEzC,KAAK,IAAM,KAAW,CAAC,GAAG,CAAO,CAAC,CAAC,QAAQ,GACzC,IAAI;KACF,MAAM,EAAQ,OAAO,CAAO;IAC9B,SAAS,GAAmB;KAC1B,EAAqB,KAAK,CAAiB;IAC7C;IASF,MANI,EAAqB,SAAS,IACtB,eAAe,CAAC,GAAO,GAAG,CAAoB,GAAG,+CAA+C,EACxG,OAAO,EACT,CAAC,IAGG;GACR;EACF;EACA;EACA,QAAQ,OAAO,MAA4B;GACzC,IAAM,IAAsB,CAAC;GAE7B,KAAK,IAAM,KAAW,CAAC,GAAG,CAAK,CAAC,CAAC,QAAQ,GACvC,IAAI;IACF,MAAM,EAAQ,OAAO,CAAO;GAC9B,SAAS,GAAO;IACd,EAAS,KAAK,CAAK;GACrB;GAGF,IAAI,EAAS,SAAS,GAAG,MAAU,eAAe,GAAU,0BAA0B;EACxF;CACF;AACF"}
package/dist/errors.cjs CHANGED
@@ -1,2 +1,2 @@
1
- var e=class e extends Error{constructor(e,t){super(e,t),this.name=new.target.name,Object.setPrototypeOf(this,new.target.prototype)}static is(t){return t instanceof e}},t=class extends e{},n=class extends e{},r=class extends e{};exports.LedgerDisposedError=t,exports.LedgerError=e,exports.LedgerExecutionError=n,exports.LedgerRollbackError=r;
1
+ var e=class e extends Error{constructor(e,t){super(e,t),this.name=new.target.name,Object.setPrototypeOf(this,new.target.prototype)}static is(t){return t instanceof e}},t=class extends e{},n=class extends e{},r=class extends e{},i=class extends e{};exports.LedgerCancelledError=t,exports.LedgerDisposedError=n,exports.LedgerError=e,exports.LedgerExecutionError=r,exports.LedgerRollbackError=i;
2
2
  //# sourceMappingURL=errors.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"errors.cjs","names":[],"sources":["../src/errors.ts"],"sourcesContent":["/** Base class for all ledger errors. Use `instanceof LedgerError` to catch any ledger-originated error. */\nexport class LedgerError extends Error {\n constructor(message: string, opts?: ErrorOptions) {\n super(message, opts);\n this.name = new.target.name;\n Object.setPrototypeOf(this, new.target.prototype);\n }\n\n static is(err: unknown): err is LedgerError {\n return err instanceof LedgerError;\n }\n}\n\n/** Thrown when a method is called on a disposed ledger instance. */\nexport class LedgerDisposedError extends LedgerError {}\n\n/** Thrown when a command's `execute()` function throws. The original error is available via `.cause`. */\nexport class LedgerExecutionError extends LedgerError {}\n\n/** Passed to `onRollbackError` when a command's `rollback()` function throws during an undo operation. The original error is available via `.cause`. */\nexport class LedgerRollbackError extends LedgerError {}\n"],"mappings":"AACA,IAAa,EAAb,MAAa,UAAoB,KAAM,CACrC,YAAY,EAAiB,EAAqB,CAChD,MAAM,EAAS,CAAI,EACnB,KAAK,KAAO,WAAW,KACvB,OAAO,eAAe,KAAM,WAAW,SAAS,CAClD,CAEA,OAAO,GAAG,EAAkC,CAC1C,OAAO,aAAe,CACxB,CACF,EAGa,EAAb,cAAyC,CAAY,CAAC,EAGzC,EAAb,cAA0C,CAAY,CAAC,EAG1C,EAAb,cAAyC,CAAY,CAAC"}
1
+ {"version":3,"file":"errors.cjs","names":[],"sources":["../src/errors.ts"],"sourcesContent":["/** Base class for all ledger errors. Use `instanceof LedgerError` to catch any ledger-originated error. */\nexport class LedgerError extends Error {\n constructor(message: string, opts?: ErrorOptions) {\n super(message, opts);\n this.name = new.target.name;\n Object.setPrototypeOf(this, new.target.prototype);\n }\n\n static is(err: unknown): err is LedgerError {\n return err instanceof LedgerError;\n }\n}\n\n/** Thrown when a queued operation is cancelled before user code starts, or an active operation cooperatively stops. */\nexport class LedgerCancelledError extends LedgerError {}\n\n/** Thrown when a method is called on a disposed ledger instance. */\nexport class LedgerDisposedError extends LedgerError {}\n\n/** Thrown when a command's `apply()` function throws. The original error is available via `.cause`. */\nexport class LedgerExecutionError extends LedgerError {}\n\n/** Thrown when a command's `revert()` function throws during an undo operation. The original error is available via `.cause`. */\nexport class LedgerRollbackError extends LedgerError {}\n"],"mappings":"AACA,IAAa,EAAb,MAAa,UAAoB,KAAM,CACrC,YAAY,EAAiB,EAAqB,CAChD,MAAM,EAAS,CAAI,EACnB,KAAK,KAAO,WAAW,KACvB,OAAO,eAAe,KAAM,WAAW,SAAS,CAClD,CAEA,OAAO,GAAG,EAAkC,CAC1C,OAAO,aAAe,CACxB,CACF,EAGa,EAAb,cAA0C,CAAY,CAAC,EAG1C,EAAb,cAAyC,CAAY,CAAC,EAGzC,EAAb,cAA0C,CAAY,CAAC,EAG1C,EAAb,cAAyC,CAAY,CAAC"}
package/dist/errors.d.ts CHANGED
@@ -3,13 +3,16 @@ export declare class LedgerError extends Error {
3
3
  constructor(message: string, opts?: ErrorOptions);
4
4
  static is(err: unknown): err is LedgerError;
5
5
  }
6
+ /** Thrown when a queued operation is cancelled before user code starts, or an active operation cooperatively stops. */
7
+ export declare class LedgerCancelledError extends LedgerError {
8
+ }
6
9
  /** Thrown when a method is called on a disposed ledger instance. */
7
10
  export declare class LedgerDisposedError extends LedgerError {
8
11
  }
9
- /** Thrown when a command's `execute()` function throws. The original error is available via `.cause`. */
12
+ /** Thrown when a command's `apply()` function throws. The original error is available via `.cause`. */
10
13
  export declare class LedgerExecutionError extends LedgerError {
11
14
  }
12
- /** Passed to `onRollbackError` when a command's `rollback()` function throws during an undo operation. The original error is available via `.cause`. */
15
+ /** Thrown when a command's `revert()` function throws during an undo operation. The original error is available via `.cause`. */
13
16
  export declare class LedgerRollbackError extends LedgerError {
14
17
  }
15
18
  //# sourceMappingURL=errors.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,2GAA2G;AAC3G,qBAAa,WAAY,SAAQ,KAAK;gBACxB,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,YAAY;IAMhD,MAAM,CAAC,EAAE,CAAC,GAAG,EAAE,OAAO,GAAG,GAAG,IAAI,WAAW;CAG5C;AAED,oEAAoE;AACpE,qBAAa,mBAAoB,SAAQ,WAAW;CAAG;AAEvD,yGAAyG;AACzG,qBAAa,oBAAqB,SAAQ,WAAW;CAAG;AAExD,wJAAwJ;AACxJ,qBAAa,mBAAoB,SAAQ,WAAW;CAAG"}
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,2GAA2G;AAC3G,qBAAa,WAAY,SAAQ,KAAK;gBACxB,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,YAAY;IAMhD,MAAM,CAAC,EAAE,CAAC,GAAG,EAAE,OAAO,GAAG,GAAG,IAAI,WAAW;CAG5C;AAED,uHAAuH;AACvH,qBAAa,oBAAqB,SAAQ,WAAW;CAAG;AAExD,oEAAoE;AACpE,qBAAa,mBAAoB,SAAQ,WAAW;CAAG;AAEvD,uGAAuG;AACvG,qBAAa,oBAAqB,SAAQ,WAAW;CAAG;AAExD,iIAAiI;AACjI,qBAAa,mBAAoB,SAAQ,WAAW;CAAG"}
package/dist/errors.js CHANGED
@@ -6,8 +6,8 @@ var e = class e extends Error {
6
6
  static is(t) {
7
7
  return t instanceof e;
8
8
  }
9
- }, t = class extends e {}, n = class extends e {}, r = class extends e {};
9
+ }, t = class extends e {}, n = class extends e {}, r = class extends e {}, i = class extends e {};
10
10
  //#endregion
11
- export { t as LedgerDisposedError, e as LedgerError, n as LedgerExecutionError, r as LedgerRollbackError };
11
+ export { t as LedgerCancelledError, n as LedgerDisposedError, e as LedgerError, r as LedgerExecutionError, i as LedgerRollbackError };
12
12
 
13
13
  //# sourceMappingURL=errors.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"errors.js","names":[],"sources":["../src/errors.ts"],"sourcesContent":["/** Base class for all ledger errors. Use `instanceof LedgerError` to catch any ledger-originated error. */\nexport class LedgerError extends Error {\n constructor(message: string, opts?: ErrorOptions) {\n super(message, opts);\n this.name = new.target.name;\n Object.setPrototypeOf(this, new.target.prototype);\n }\n\n static is(err: unknown): err is LedgerError {\n return err instanceof LedgerError;\n }\n}\n\n/** Thrown when a method is called on a disposed ledger instance. */\nexport class LedgerDisposedError extends LedgerError {}\n\n/** Thrown when a command's `execute()` function throws. The original error is available via `.cause`. */\nexport class LedgerExecutionError extends LedgerError {}\n\n/** Passed to `onRollbackError` when a command's `rollback()` function throws during an undo operation. The original error is available via `.cause`. */\nexport class LedgerRollbackError extends LedgerError {}\n"],"mappings":";AACA,IAAa,IAAb,MAAa,UAAoB,MAAM;CACrC,YAAY,GAAiB,GAAqB;EAGhD,AAFA,MAAM,GAAS,CAAI,GACnB,KAAK,OAAO,WAAW,MACvB,OAAO,eAAe,MAAM,WAAW,SAAS;CAClD;CAEA,OAAO,GAAG,GAAkC;EAC1C,OAAO,aAAe;CACxB;AACF,GAGa,IAAb,cAAyC,EAAY,CAAC,GAGzC,IAAb,cAA0C,EAAY,CAAC,GAG1C,IAAb,cAAyC,EAAY,CAAC"}
1
+ {"version":3,"file":"errors.js","names":[],"sources":["../src/errors.ts"],"sourcesContent":["/** Base class for all ledger errors. Use `instanceof LedgerError` to catch any ledger-originated error. */\nexport class LedgerError extends Error {\n constructor(message: string, opts?: ErrorOptions) {\n super(message, opts);\n this.name = new.target.name;\n Object.setPrototypeOf(this, new.target.prototype);\n }\n\n static is(err: unknown): err is LedgerError {\n return err instanceof LedgerError;\n }\n}\n\n/** Thrown when a queued operation is cancelled before user code starts, or an active operation cooperatively stops. */\nexport class LedgerCancelledError extends LedgerError {}\n\n/** Thrown when a method is called on a disposed ledger instance. */\nexport class LedgerDisposedError extends LedgerError {}\n\n/** Thrown when a command's `apply()` function throws. The original error is available via `.cause`. */\nexport class LedgerExecutionError extends LedgerError {}\n\n/** Thrown when a command's `revert()` function throws during an undo operation. The original error is available via `.cause`. */\nexport class LedgerRollbackError extends LedgerError {}\n"],"mappings":";AACA,IAAa,IAAb,MAAa,UAAoB,MAAM;CACrC,YAAY,GAAiB,GAAqB;EAGhD,AAFA,MAAM,GAAS,CAAI,GACnB,KAAK,OAAO,WAAW,MACvB,OAAO,eAAe,MAAM,WAAW,SAAS;CAClD;CAEA,OAAO,GAAG,GAAkC;EAC1C,OAAO,aAAe;CACxB;AACF,GAGa,IAAb,cAA0C,EAAY,CAAC,GAG1C,IAAb,cAAyC,EAAY,CAAC,GAGzC,IAAb,cAA0C,EAAY,CAAC,GAG1C,IAAb,cAAyC,EAAY,CAAC"}
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./compose.cjs"),t=require("./errors.cjs"),n=require("./ledger.cjs");exports.LedgerDisposedError=t.LedgerDisposedError,exports.LedgerError=t.LedgerError,exports.LedgerExecutionError=t.LedgerExecutionError,exports.LedgerRollbackError=t.LedgerRollbackError,exports.compose=e.compose,exports.createLedger=n.createLedger;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./compose.cjs"),t=require("./errors.cjs"),n=require("./ledger.cjs");exports.LedgerCancelledError=t.LedgerCancelledError,exports.LedgerDisposedError=t.LedgerDisposedError,exports.LedgerError=t.LedgerError,exports.LedgerExecutionError=t.LedgerExecutionError,exports.LedgerRollbackError=t.LedgerRollbackError,exports.compose=e.compose,exports.createLedger=n.createLedger;
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  export { compose } from './compose';
2
- export { LedgerDisposedError, LedgerError, LedgerExecutionError, LedgerRollbackError } from './errors';
2
+ export { LedgerCancelledError, LedgerDisposedError, LedgerError, LedgerExecutionError, LedgerRollbackError, } from './errors';
3
3
  export { createLedger } from './ledger';
4
- export type { Command, CommandMeta, Ledger, LedgerCallOptions, LedgerOptions } from './types';
4
+ export type { CommandContext, HistoryEntry, Ledger, LedgerCallOptions, LedgerOptions, LedgerState, ReversibleCommand, } from './types';
5
5
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,mBAAmB,EAAE,WAAW,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AACvG,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AACxC,YAAY,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EACL,oBAAoB,EACpB,mBAAmB,EACnB,WAAW,EACX,oBAAoB,EACpB,mBAAmB,GACpB,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AACxC,YAAY,EACV,cAAc,EACd,YAAY,EACZ,MAAM,EACN,iBAAiB,EACjB,aAAa,EACb,WAAW,EACX,iBAAiB,GAClB,MAAM,SAAS,CAAC"}
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
1
  import { compose as e } from "./compose.js";
2
- import { LedgerDisposedError as t, LedgerError as n, LedgerExecutionError as r, LedgerRollbackError as i } from "./errors.js";
3
- import { createLedger as a } from "./ledger.js";
4
- export { t as LedgerDisposedError, n as LedgerError, r as LedgerExecutionError, i as LedgerRollbackError, e as compose, a as createLedger };
2
+ import { LedgerCancelledError as t, LedgerDisposedError as n, LedgerError as r, LedgerExecutionError as i, LedgerRollbackError as a } from "./errors.js";
3
+ import { createLedger as o } from "./ledger.js";
4
+ export { t as LedgerCancelledError, n as LedgerDisposedError, r as LedgerError, i as LedgerExecutionError, a as LedgerRollbackError, e as compose, o as createLedger };
package/dist/ledger.cjs CHANGED
@@ -1,2 +1,2 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});function e(e,t){return{execute:async t=>{let n=[];try{for(let r of e)await r.execute(t),n.push(r)}catch(e){for(let e of[...n].reverse())try{await e.rollback?.(t)}catch{}throw e}},label:t,rollback:e.some(e=>e.rollback!=null)?async t=>{let n,r=!1;for(let i of[...e].reverse())try{await i.rollback?.(t)}catch(e){r||=(n=e,!0)}if(r)throw n}:void 0}}var t=class e extends Error{constructor(e,t){super(e,t),this.name=new.target.name,Object.setPrototypeOf(this,new.target.prototype)}static is(t){return t instanceof e}},n=class extends t{},r=class extends t{},i=class extends t{},a=class e extends Error{constructor(e,t){super(e,t),this.name=new.target.name,Object.setPrototypeOf(this,new.target.prototype)}static is(t){return t instanceof e}},o=class extends a{},s=class extends a{},c=class extends a{},l=Symbol(`ripple.reactive`),u=Symbol(`ripple.signal`),d=Symbol(`ripple.computed`),f=100,p=Symbol(`ripple.unset`),m=class{[l]=!0;dependents=new Set;name;runtime;constructor(e,t){this.runtime=e,this.name=t}subscribe(e){this.peek();let t={dependencies:new Set,onDependencyChanged:()=>this.runtime.enqueueListener(e)};return this.dependents.add(t),()=>this.dependents.delete(t)}notify(){for(let e of[...this.dependents])e.onDependencyChanged()}},h=class extends m{[u]=!0;current;equals;constructor(e,t,n){super(e,n?.name),this.current=t,this.equals=n?.equals??Object.is}get value(){return this.runtime.track(this),this.current}set value(e){if(this.equals(this.current,e))return;let t=this.current;this.current=e,this.runtime.emit({kind:`write`,name:this.name,next:e,previous:t}),this.runtime.propagate(()=>this.notify())}peek(){return this.current}},g=class extends m{[d]=!0;dependencies=new Set;computing=!1;disposed=!1;dirty=!0;current=p;derive;equals;constructor(e,t,n){super(e,n?.name),this.derive=t,this.equals=n?.equals??Object.is}get value(){return this.refresh(),this.runtime.track(this),this.current}peek(){return this.refresh(),this.current}onDependencyChanged(){this.disposed||(this.dirty||=!0,this.dependents.size>0&&this.refresh()&&this.notify())}dispose(){this.disposed||(this.disposed=!0,this.runtime.clearDependencies(this),this.dependents.clear())}refresh(){if(!this.dirty||this.disposed)return!1;if(this.computing)throw new o(`computed cycle detected${this.name===void 0?``:` "${this.name}"`}`);this.computing=!0,this.runtime.emit({kind:`compute`,name:this.name});try{let e=this.runtime.collect(this,this.derive),t=this.current===p||!this.equals(this.current,e);return this.current=e,this.dirty=!1,t}finally{this.computing=!1}}},_=class{disposalController=new AbortController;owned=new Set;name;isDisposed=!1;runtime;constructor(e,t){this.runtime=e,this.name=t}get disposed(){return this.isDisposed}get disposalSignal(){return this.disposalController.signal}run(e){if(this.isDisposed)throw new s(`Cannot run a disposed scope.`);return this.runtime.withScope(this,e)}dispose(){if(!this.isDisposed){this.isDisposed=!0;for(let e of[...this.owned].reverse())e.dispose();this.owned.clear(),this.disposalController.abort(),this.runtime.emit({kind:`dispose`,name:this.name,node:`scope`})}}[Symbol.dispose](){this.dispose()}},v=class{dependencies=new Set;disposalController=new AbortController;cleanup;isDisposed=!1;owner;scheduled=!1;callback;options;runtime;constructor(e,t,n){this.runtime=e,this.callback=t,this.options=n}get disposed(){return this.isDisposed}get disposalSignal(){return this.disposalController.signal}onDependencyChanged(){if(!this.isDisposed){if(this.options?.scheduler===`microtask`){if(this.scheduled)return;this.scheduled=!0,queueMicrotask(()=>{this.scheduled=!1,this.isDisposed||this.runtime.enqueue(this)});return}this.runtime.enqueue(this)}}run(){if(this.isDisposed)return;this.owner?.dispose(),this.owner=void 0,this.runCleanup(),this.runtime.emit({kind:`effect`,name:this.options?.name});let e=new _(this.runtime);try{let t=this.runtime.withEffectScope(e,()=>this.runtime.collectEffect(this,this.callback));this.owner=e,this.cleanup=typeof t==`function`?t:void 0}catch(t){e.dispose(),this.runtime.report(t,{kind:`effect`,name:this.options?.name})}}dispose(){this.isDisposed||(this.isDisposed=!0,this.owner?.dispose(),this.owner=void 0,this.runtime.clearDependencies(this),this.runCleanup(),this.disposalController.abort(),this.runtime.emit({kind:`dispose`,name:this.options?.name,node:`effect`}))}[Symbol.dispose](){this.dispose()}runCleanup(){let e=this.cleanup;if(this.cleanup=void 0,e!==void 0)try{e()}catch(e){this.runtime.report(e,{kind:`cleanup`,name:this.options?.name})}}},y=class{activeEffectScope;activeObserver;activeScope;flushDepth=0;flushing=!1;pending=new Set;listeners=new Set;rootScope;observer;onError;constructor(e){this.observer=e?.observer,this.onError=e?.onError??(e=>{queueMicrotask(()=>{throw e})}),this.rootScope=new _(this,`runtime`),this.activeScope=this.rootScope}signal=(e,t)=>new h(this,e,t);computed=(e,t)=>{let n=new g(this,e,t);return(this.activeEffectScope??this.activeScope).owned.add(n),n};effect=(e,t)=>{let n=new v(this,e,t);return(this.activeEffectScope??this.activeScope).owned.add(n),n.run(),n};createScope=e=>{let t=new _(this,e);return this.activeScope.owned.add(t),t};batch=e=>this.propagate(e);untrack=e=>this.withObserver(void 0,e);dispose(){this.rootScope.dispose()}track(e){let t=this.activeObserver;t?.collecting!==void 0&&t.collecting.add(e)}clearDependencies(e){for(let t of e.dependencies)t.dependents.delete(e);e.dependencies.clear()}collect(e,t){return this.collectWith(e,t,!1)}collectEffect(e,t){return this.collectWith(e,t,!0)}withEffectScope(e,t){let n=this.activeEffectScope;this.activeEffectScope=e;try{return t()}finally{this.activeEffectScope=n}}withObserver(e,t){let n=this.activeObserver;this.activeObserver=e;try{return t()}finally{this.activeObserver=n}}withScope(e,t){let n=this.activeEffectScope,r=this.activeScope;this.activeEffectScope=void 0,this.activeScope=e;try{return t()}finally{this.activeEffectScope=n,this.activeScope=r}}enqueue(e){this.pending.add(e),this.flushDepth===0&&this.flush()}enqueueListener(e){this.listeners.add(e),this.flushDepth===0&&this.flush()}propagate(e){this.flushDepth++;try{return e()}finally{this.flushDepth--,this.flushDepth===0&&this.flush()}}emit(e){try{this.observer?.(e)}catch(t){this.report(t,{kind:`observer`,name:e.name})}}report(e,t){try{this.onError(e,t)}catch(e){queueMicrotask(()=>{throw e})}}collectWith(e,t,n){let r=this.activeObserver,i=new Set;e.collecting=i,this.activeObserver=e;try{let n=t();return this.commitDependencies(e,i),n}catch(t){throw n&&this.commitDependencies(e,i),t}finally{e.collecting=void 0,this.activeObserver=r}}commitDependencies(e,t){for(let n of e.dependencies)t.has(n)||n.dependents.delete(e);for(let n of t)e.dependencies.has(n)||n.dependents.add(e);e.dependencies.clear();for(let n of t)e.dependencies.add(n)}flush(){if(this.flushing)return;this.flushing=!0;let e=0;try{for(;this.pending.size>0||this.listeners.size>0;){if(++e>f)throw new c(`infinite reactive flush (>${f} iterations)`);let t=[...this.pending],n=[...this.listeners];this.pending.clear(),this.listeners.clear();for(let e of t)e.run();for(let e of n)try{e()}catch(e){this.report(e,{kind:`listener`})}}}finally{this.flushing=!1}}},b=e=>(t,n,r)=>{let i=e.signal({status:`pending`},{name:r?.name}),a=e.signal(0),o=new AbortController,s,c=!1,l=()=>{a.value,s?.abort();let e=i.peek(),r=e.status===`success`?e.value:`previous`in e?e.previous:void 0,o;try{o=t()}catch(e){i.value=r===void 0?{error:e,status:`error`}:{error:e,previous:r,status:`error`};return}let l=new AbortController;s=l,i.value=r===void 0?{status:`pending`}:{previous:r,status:`pending`};let u;try{u=Promise.resolve(n(o,{signal:l.signal}))}catch(e){u=Promise.reject(e)}u.then(e=>{!c&&!l.signal.aborted&&(i.value={status:`success`,value:e})},e=>{!c&&!l.signal.aborted&&(i.value=r===void 0?{error:e,status:`error`}:{error:e,previous:r,status:`error`})})},u=e.effect(()=>(l(),()=>s?.abort()),{name:r?.name});return u.disposalSignal.addEventListener(`abort`,()=>{c=!0,o.abort()},{once:!0}),{get disposalSignal(){return o.signal},dispose:()=>u.dispose(),get disposed(){return c},get name(){return i.name},peek:()=>i.peek(),reload:()=>{c||(a.value=a.peek()+1)},subscribe:e=>i.subscribe(e),[Symbol.dispose](){this.dispose()},get value(){return i.value}}},x=e=>(t,n)=>{let r=e.signal(t,{name:n?.name});return{get name(){return r.name},peek:()=>r.peek(),set:e=>{r.value=e},subscribe:e=>r.subscribe(e),update:e=>{r.value=e(r.peek())},get value(){return r.value}}},S=e=>(t,n,r)=>{let i=typeof t==`function`?t:()=>t.value,a=r?.equals??Object.is,o=!0,s,c=!1,l=e.effect(()=>{let e=i();if(o){o=!1,s=e,r?.immediate&&n(e,void 0),c=r?.once===!0&&r.immediate===!0;return}if(a(s,e))return;let t=s;s=e,n(e,t),r?.once&&l.dispose()},{name:r?.name});return c&&l.dispose(),l},C=(e=>{let t=new y(e),n=b(t),r=x(t);return{batch:t.batch,computed:t.computed,createScope:t.createScope,createStore:r,dispose:()=>t.dispose(),effect:t.effect,resource:n,signal:t.signal,untrack:t.untrack,watch:S(t)}})(),w=C.signal,T=C.computed;C.effect,C.batch,C.createScope,C.createStore,C.resource,C.untrack,C.watch;function E(e){return e instanceof Error?e.message:String(e)}function D(e){let{rollback:t}=e;return{execute:async t=>e.execute(t),meta:{data:e.data,label:e.label},rollback:t==null?void 0:async e=>t(e)}}function O(e={}){let{maxHistory:t=100,onRollbackError:a}=e,o=w([],{name:`ledger:undoStack`}),s=w([],{name:`ledger:redoStack`}),c=w(0,{name:`ledger:pending`}),l=w(!1,{name:`ledger:processing`}),u=T(()=>o.value.length>0,{name:`ledger:canUndo`}),d=T(()=>s.value.length>0,{name:`ledger:canRedo`}),f=T(()=>o.value.length,{name:`ledger:historySize`}),p=T(()=>l.value,{name:`ledger:isProcessing`}),m=T(()=>c.value,{name:`ledger:pendingCount`}),h=T(()=>[...o.value].reverse().map(e=>e.meta),{name:`ledger:historySnapshot`}),g=!1,_=Promise.resolve(),v=new AbortController;function y(e){return e?AbortSignal.any([e,v.signal]):v.signal}function b(e,t){if(g)return Promise.reject(new n(`Cannot call ${e}() on a disposed ledger.`));c.value++;let r=_.then(t).finally(()=>{g||c.value--});return _=r.catch(()=>{}),r}async function x(e){l.value=!0;try{await e()}finally{g||(l.value=!1)}}async function S(e,n){await x(async()=>{try{await e.execute(n)}catch(e){throw new r(E(e),{cause:e})}if(g)return;let i=[...o.value,e];i.length>t&&i.shift(),o.value=i,s.value=[]})}async function C(e){let t=o.value;if(t.length===0)return;let n=t[t.length-1];await x(async()=>{if(n.rollback)try{await n.rollback(e)}catch(e){`${n.meta.label??`(unlabelled)`}`,a?.(new i(E(e),{cause:e}),n.meta);return}g||(o.value=t.slice(0,-1),s.value=[...s.value,n])})}async function O(e){let t=s.value;if(t.length===0)return;let n=t[t.length-1];await x(async()=>{try{await n.execute(e)}catch(e){throw new r(E(e),{cause:e})}g||(s.value=t.slice(0,-1),o.value=[...o.value,n])})}function k(){return b(`clear`,async()=>{g||(o.value=[],s.value=[])})}function A(){g=!0,v.abort(),o.value=[],s.value=[]}return{canRedo:d,canUndo:u,clear:k,get disposalSignal(){return v.signal},dispose:A,get disposed(){return g},do(e,t){return b(`do`,()=>S(D(e),y(t?.signal)))},historySize:f,historySnapshot:h,isProcessing:p,pendingCount:m,redo(e){return b(`redo`,()=>O(y(e?.signal)))},[Symbol.dispose](){A()},undo(e){return b(`undo`,()=>C(y(e?.signal)))}}}exports.LedgerDisposedError=n,exports.LedgerError=t,exports.LedgerExecutionError=r,exports.LedgerRollbackError=i,exports.compose=e,exports.createLedger=O;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});function e(e){let{apply:t,label:n,meta:r,revert:i}=e;return{apply:t,label:n,meta:r,revert:i}}function t(t,n){let r=t.map(e);return{apply:async e=>{let t=[];try{for(let n of r)await n.apply(e),t.push(n)}catch(n){let r=[];for(let n of[...t].reverse())try{await n.revert(e)}catch(e){r.push(e)}throw r.length>0?AggregateError([n,...r],`Command application and compensation failed`,{cause:n}):n}},label:n,revert:async e=>{let t=[];for(let n of[...r].reverse())try{await n.revert(e)}catch(e){t.push(e)}if(t.length>0)throw AggregateError(t,`Command reversion failed`)}}}var n=class e extends Error{constructor(e,t){super(e,t),this.name=new.target.name,Object.setPrototypeOf(this,new.target.prototype)}static is(t){return t instanceof e}},r=class extends n{},i=class extends n{},a=class extends n{},o=class extends n{},s=class e extends Error{constructor(e,t){super(e,t),this.name=new.target.name,Object.setPrototypeOf(this,new.target.prototype)}static is(t){return t instanceof e}},c=class extends s{},l=class extends s{},u=class extends s{},d=class extends s{},f=Symbol(`ripple.reactive`),p=Symbol(`ripple.signal`),m=Symbol(`ripple.computed`),h=100,g=Symbol(`ripple.unset`),_=class{[f]=!0;dependents=new Set;name;runtime;constructor(e,t){this.runtime=e,this.name=t}subscribe(e){this.runtime.assertActive(),this.peek();let t={dependencies:new Set,onDependencyChanged:()=>this.runtime.enqueueListener(e)};return this.dependents.add(t),()=>this.dependents.delete(t)}notify(){for(let e of[...this.dependents])e.onDependencyChanged()}},v=class extends _{[p]=!0;current;equals;constructor(e,t,n){super(e,n?.name),this.current=t,this.equals=n?.equals??Object.is}get value(){return this.runtime.track(this),this.current}set value(e){if(this.runtime.assertActive(),this.equals(this.current,e))return;let t=this.current;this.current=e,this.runtime.emit({kind:`write`,name:this.name,next:e,previous:t}),this.runtime.propagate(()=>this.notify())}peek(){return this.current}},y=class extends _{[m]=!0;dependencies=new Set;computing=!1;disposed=!1;dirty=!0;current=g;derive;equals;constructor(e,t,n){super(e,n?.name),this.derive=t,this.equals=n?.equals??Object.is}get value(){return this.refresh(),this.runtime.track(this),this.current}peek(){return this.refresh(),this.current}onDependencyChanged(){this.disposed||(this.dirty||=!0,this.dependents.size>0&&this.refresh()&&this.notify())}dispose(){this.disposed||(this.disposed=!0,this.runtime.clearDependencies(this),this.dependents.clear())}refresh(){if(!this.dirty||this.disposed)return!1;if(this.computing)throw new c(`computed cycle detected${this.name===void 0?``:` "${this.name}"`}`);this.computing=!0,this.runtime.emit({kind:`compute`,name:this.name});try{let e=this.runtime.collect(this,this.derive),t=this.current===g||!this.equals(this.current,e);return this.current=e,this.dirty=!1,t}finally{this.computing=!1}}},b=class{disposalController=new AbortController;owned=new Set;name;isDisposed=!1;runtime;constructor(e,t){this.runtime=e,this.name=t}get disposed(){return this.isDisposed}get disposalSignal(){return this.disposalController.signal}run(e){if(this.isDisposed)throw new u(`Cannot run a disposed scope.`);return this.runtime.withScope(this,e)}dispose(){if(!this.isDisposed){this.isDisposed=!0;for(let e of[...this.owned].reverse())e.dispose();this.owned.clear(),this.disposalController.abort(),this.runtime.emit({kind:`dispose`,name:this.name,node:`scope`})}}[Symbol.dispose](){this.dispose()}},x=class{dependencies=new Set;disposalController=new AbortController;cleanup;isDisposed=!1;owner;scheduled=!1;callback;options;runtime;constructor(e,t,n){this.runtime=e,this.callback=t,this.options=n}get disposed(){return this.isDisposed}get disposalSignal(){return this.disposalController.signal}onDependencyChanged(){if(!this.isDisposed){if(this.options?.scheduler===`microtask`){if(this.scheduled)return;this.scheduled=!0,queueMicrotask(()=>{this.scheduled=!1,this.isDisposed||this.runtime.enqueue(this)});return}this.runtime.enqueue(this)}}run(){if(this.isDisposed)return;this.owner?.dispose(),this.owner=void 0,this.runCleanup(),this.runtime.emit({kind:`effect`,name:this.options?.name});let e=new b(this.runtime);try{let t=this.runtime.withEffectScope(e,()=>this.runtime.collectEffect(this,this.callback));this.owner=e,this.cleanup=typeof t==`function`?t:void 0}catch(t){e.dispose(),this.runtime.report(t,{kind:`effect`,name:this.options?.name})}}dispose(){this.isDisposed||(this.isDisposed=!0,this.owner?.dispose(),this.owner=void 0,this.runtime.clearDependencies(this),this.runCleanup(),this.disposalController.abort(),this.runtime.emit({kind:`dispose`,name:this.options?.name,node:`effect`}))}[Symbol.dispose](){this.dispose()}runCleanup(){let e=this.cleanup;if(this.cleanup=void 0,e!==void 0)try{e()}catch(e){this.runtime.report(e,{kind:`cleanup`,name:this.options?.name})}}},S=class{activeEffectScope;activeObserver;activeScope;isDisposed=!1;flushDepth=0;flushing=!1;pending=new Set;listeners=new Set;rootScope;observer;onError;constructor(e){this.observer=e?.observer,this.onError=e?.onError??(e=>{queueMicrotask(()=>{throw e})}),this.rootScope=new b(this,`runtime`),this.activeScope=this.rootScope}get disposed(){return this.isDisposed}signal=(e,t)=>(this.assertActive(),new v(this,e,t));computed=(e,t)=>{this.assertActive();let n=new y(this,e,t);return(this.activeEffectScope??this.activeScope).owned.add(n),n};effect=(e,t)=>{this.assertActive();let n=new x(this,e,t);return(this.activeEffectScope??this.activeScope).owned.add(n),n.run(),n};createScope=e=>{this.assertActive();let t=new b(this,e);return this.activeScope.owned.add(t),t};batch=e=>(this.assertActive(),this.propagate(e));untrack=e=>(this.assertActive(),this.withObserver(void 0,e));dispose(){this.isDisposed||(this.isDisposed=!0,this.rootScope.dispose())}assertActive(){if(this.isDisposed)throw new l(`Cannot use a disposed Ripple runtime.`)}track(e){let t=this.activeObserver;t?.collecting!==void 0&&t.collecting.add(e)}clearDependencies(e){for(let t of e.dependencies)t.dependents.delete(e);e.dependencies.clear()}collect(e,t){return this.collectWith(e,t,!1)}collectEffect(e,t){return this.collectWith(e,t,!0)}withEffectScope(e,t){let n=this.activeEffectScope;this.activeEffectScope=e;try{return t()}finally{this.activeEffectScope=n}}withObserver(e,t){let n=this.activeObserver;this.activeObserver=e;try{return t()}finally{this.activeObserver=n}}withScope(e,t){let n=this.activeEffectScope,r=this.activeScope;this.activeEffectScope=void 0,this.activeScope=e;try{return t()}finally{this.activeEffectScope=n,this.activeScope=r}}enqueue(e){this.pending.add(e),this.flushDepth===0&&this.flush()}enqueueListener(e){this.listeners.add(e),this.flushDepth===0&&this.flush()}propagate(e){this.flushDepth++;try{return e()}finally{this.flushDepth--,this.flushDepth===0&&this.flush()}}emit(e){try{this.observer?.(e)}catch(t){this.report(t,{kind:`observer`,name:e.name})}}report(e,t){try{this.onError(e,t)}catch(e){queueMicrotask(()=>{throw e})}}collectWith(e,t,n){let r=this.activeObserver,i=new Set;e.collecting=i,this.activeObserver=e;try{let n=t();return this.commitDependencies(e,i),n}catch(t){throw n&&this.commitDependencies(e,i),t}finally{e.collecting=void 0,this.activeObserver=r}}commitDependencies(e,t){for(let n of e.dependencies)t.has(n)||n.dependents.delete(e);for(let n of t)e.dependencies.has(n)||n.dependents.add(e);e.dependencies.clear();for(let n of t)e.dependencies.add(n)}flush(){if(this.flushing)return;this.flushing=!0;let e=0;try{for(;this.pending.size>0||this.listeners.size>0;){if(++e>h)throw new d(`infinite reactive flush (>${h} iterations)`);let t=[...this.pending],n=[...this.listeners];this.pending.clear(),this.listeners.clear();for(let e of t)e.run();for(let e of n)try{e()}catch(e){this.report(e,{kind:`listener`})}}}finally{this.flushing=!1}}},C=e=>(t,n,r)=>{let i=e.signal({status:`pending`},{name:r?.name}),a=e.signal(0),o=new AbortController,s,c=!1,l=()=>{a.value,s?.abort();let e=i.peek(),r=e.status===`success`?e.value:`previous`in e?e.previous:void 0,o;try{o=t()}catch(e){i.value=r===void 0?{error:e,status:`error`}:{error:e,previous:r,status:`error`};return}let l=new AbortController;s=l,i.value=r===void 0?{status:`pending`}:{previous:r,status:`pending`};let u;try{u=Promise.resolve(n(o,{signal:l.signal}))}catch(e){u=Promise.reject(e)}u.then(e=>{!c&&!l.signal.aborted&&(i.value={status:`success`,value:e})},e=>{!c&&!l.signal.aborted&&(i.value=r===void 0?{error:e,status:`error`}:{error:e,previous:r,status:`error`})})},u=e.effect(()=>(l(),()=>s?.abort()),{name:r?.name});return u.disposalSignal.addEventListener(`abort`,()=>{c=!0,o.abort()},{once:!0}),{get disposalSignal(){return o.signal},dispose:()=>u.dispose(),get disposed(){return c},get name(){return i.name},peek:()=>i.peek(),reload:()=>{c||(a.value=a.peek()+1)},subscribe:e=>i.subscribe(e),[Symbol.dispose](){this.dispose()},get value(){return i.value}}},w=e=>(t,n)=>{let r=e.signal(t,{name:n?.name});return{get name(){return r.name},peek:()=>r.peek(),set:e=>{r.value=e},subscribe:e=>r.subscribe(e),update:e=>{r.value=e(r.peek())},get value(){return r.value}}},T=e=>(t,n,r)=>{let i=typeof t==`function`?t:()=>t.value,a=r?.equals??Object.is,o=!0,s,c=!1,l=e.effect(()=>{let e=i();if(o){o=!1,s=e,r?.immediate&&n(e,void 0),c=r?.once===!0&&r.immediate===!0;return}if(a(s,e))return;let t=s;s=e,n(e,t),r?.once&&l.dispose()},{name:r?.name});return c&&l.dispose(),l},E=(e=>{let t=new S(e),n=C(t),r=w(t);return{batch:t.batch,computed:t.computed,createScope:t.createScope,createStore:r,dispose:()=>t.dispose(),get disposed(){return t.disposed},effect:t.effect,resource:n,signal:t.signal,untrack:t.untrack,watch:T(t)}})(),D=E.signal;E.computed,E.effect,E.batch,E.createScope,E.untrack;function O(e){return e instanceof Error?e.message:String(e)}function k(e){let{apply:t,label:n,meta:r,revert:i}=e;return{apply:t,entry:Object.freeze({label:n,meta:r}),revert:i}}function A(e){return Object.freeze({...e,redo:Object.freeze([...e.redo]),undo:Object.freeze([...e.undo])})}function j(e,t){return t?new i(`Cannot call ${e}() on a disposed ledger.`):new r(`${e}() was cancelled before it started.`)}function M(e={}){let{maxHistory:t=100}=e;if(!Number.isSafeInteger(t)||t<0)throw RangeError(`maxHistory must be a non-negative safe integer`);let i=D(A({accepting:!0,queued:0,redo:[],running:0,undo:[]}),{name:`ledger:state`}),s=new WeakMap,c=new AbortController,l=new Set,u=new Set,d=!1,f=Promise.resolve();function p(e){if(i.value=A(e(i.value)),i.value.queued===0&&i.value.running===0){for(let e of l)e();l.clear()}}function m(e,t){e.settled||(e.settled=!0,u.delete(e),e.cancel(),t===void 0?e.resolve():e.reject(t))}function h(e,t,n){if(d)return Promise.reject(j(e,!0));let r=t?AbortSignal.any([t,c.signal]):c.signal;return new Promise((t,i)=>{let a={},o=()=>{a.started||a.settled||d||(p(e=>({...e,queued:e.queued-1})),m(a,j(e,!1)))};Object.assign(a,{cancel:()=>r.removeEventListener(`abort`,o),reject:i,resolve:t,settled:!1,start:async()=>{if(!a.settled){if(d||r.aborted){p(e=>({...e,queued:e.queued-1})),m(a,j(e,d));return}a.started=!0,p(e=>({...e,queued:e.queued-1,running:e.running+1}));try{await n({signal:r}),m(a)}catch(e){m(a,e)}finally{p(e=>({...e,running:e.running-1}))}}},started:!1}),r.addEventListener(`abort`,o,{once:!0}),u.add(a),p(e=>({...e,queued:e.queued+1})),f=f.then(a.start,a.start)})}async function g(e,n){try{await e.apply(n)}catch(e){throw n.signal.aborted?new r(`do() was cancelled while running.`,{cause:e}):new a(O(e),{cause:e})}if(d||n.signal.aborted)throw new r(`do() was cancelled while running.`);p(n=>{if(t===0)return{...n,redo:[]};let r=[...n.undo,e.entry];return r.length>t&&r.shift(),{...n,redo:[],undo:r}}),s.set(e.entry,e)}async function _(e){let t=i.value.undo[i.value.undo.length-1];if(!t)return;let a=s.get(t);if(!a)throw new n(`Undo history is corrupted.`);try{await a.revert(e)}catch(t){throw e.signal.aborted?new r(`undo() was cancelled while running.`,{cause:t}):new o(O(t),{cause:t})}if(d||e.signal.aborted)throw new r(`undo() was cancelled while running.`);p(e=>({...e,redo:[...e.redo,t],undo:e.undo.slice(0,-1)}))}async function v(e){let t=i.value.redo[i.value.redo.length-1];if(!t)return;let o=s.get(t);if(!o)throw new n(`Redo history is corrupted.`);try{await o.apply(e)}catch(t){throw e.signal.aborted?new r(`redo() was cancelled while running.`,{cause:t}):new a(O(t),{cause:t})}if(d||e.signal.aborted)throw new r(`redo() was cancelled while running.`);p(e=>({...e,redo:e.redo.slice(0,-1),undo:[...e.undo,t]}))}return{clear(){return h(`clear`,void 0,async()=>{p(e=>({...e,redo:[],undo:[]}))})},get disposalSignal(){return c.signal},dispose(){if(d)return;d=!0,c.abort();let e=[...u].filter(e=>!e.started);for(let t of e)m(t,j(`operation`,!0));p(e=>({...e,accepting:!1,queued:0,redo:[],undo:[]}))},get disposed(){return d},do(e,t){let n=k(e);return h(`do`,t?.signal,e=>g(n,e))},redo(e){return h(`redo`,e?.signal,v)},get state(){return i},[Symbol.dispose](){this.dispose()},undo(e){return h(`undo`,e?.signal,_)},whenIdle(){return i.value.queued===0&&i.value.running===0?Promise.resolve():new Promise(e=>l.add(e))}}}exports.LedgerCancelledError=r,exports.LedgerDisposedError=i,exports.LedgerError=n,exports.LedgerExecutionError=a,exports.LedgerRollbackError=o,exports.compose=t,exports.createLedger=M;
2
2
  //# sourceMappingURL=ledger.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"ledger.cjs","names":["e","r","l","u","t","e","d","f","p","n","e","e","i","e","o","s","c"],"sources":["../src/compose.ts","../src/errors.ts","../../ripple/dist/errors.js","../../ripple/dist/runtime.js","../../ripple/dist/_async.js","../../ripple/dist/_store.js","../../ripple/dist/_watch.js","../../ripple/dist/index.js","../src/_dev.ts","../src/ledger.ts"],"sourcesContent":["import type { Command } from './types';\n\n/**\n * Composes multiple commands into a single reversible command.\n *\n * `execute` runs all sub-commands in order. `rollback` runs them in reverse,\n * skipping any that have no rollback defined. The composed command counts as\n * one undo step.\n *\n * @example\n * await ledger.do(compose([\n * { execute: () => { node.x = newX; }, rollback: () => { node.x = oldX; } },\n * { execute: () => { node.y = newY; }, rollback: () => { node.y = oldY; } },\n * ], 'Move node'));\n */\nexport function compose<TData = unknown>(commands: Command<TData>[], label?: string): Command<TData> {\n const anyHasRollback = commands.some((c) => c.rollback != null);\n\n return {\n execute: async (signal) => {\n const done: Command<TData>[] = [];\n\n try {\n for (const c of commands) {\n await c.execute(signal);\n done.push(c);\n }\n } catch (err) {\n for (const c of [...done].reverse()) {\n try {\n await c.rollback?.(signal);\n } catch {\n // best-effort: suppress compensation errors\n }\n }\n\n throw err;\n }\n },\n label,\n rollback: anyHasRollback\n ? async (signal) => {\n let firstError: unknown;\n let hasError = false;\n\n for (const c of [...commands].reverse()) {\n try {\n await c.rollback?.(signal);\n } catch (err) {\n if (!hasError) {\n firstError = err;\n hasError = true;\n }\n }\n }\n\n if (hasError) throw firstError;\n }\n : undefined,\n };\n}\n","/** Base class for all ledger errors. Use `instanceof LedgerError` to catch any ledger-originated error. */\nexport class LedgerError extends Error {\n constructor(message: string, opts?: ErrorOptions) {\n super(message, opts);\n this.name = new.target.name;\n Object.setPrototypeOf(this, new.target.prototype);\n }\n\n static is(err: unknown): err is LedgerError {\n return err instanceof LedgerError;\n }\n}\n\n/** Thrown when a method is called on a disposed ledger instance. */\nexport class LedgerDisposedError extends LedgerError {}\n\n/** Thrown when a command's `execute()` function throws. The original error is available via `.cause`. */\nexport class LedgerExecutionError extends LedgerError {}\n\n/** Passed to `onRollbackError` when a command's `rollback()` function throws during an undo operation. The original error is available via `.cause`. */\nexport class LedgerRollbackError extends LedgerError {}\n","//#region src/errors.ts\nvar e = class e extends Error {\n\tconstructor(e, t) {\n\t\tsuper(e, t), this.name = new.target.name, Object.setPrototypeOf(this, new.target.prototype);\n\t}\n\tstatic is(t) {\n\t\treturn t instanceof e;\n\t}\n}, t = class extends e {}, n = class extends e {}, r = class extends e {};\n//#endregion\nexport { t as RippleComputedCycleError, n as RippleDisposedScopeError, e as RippleError, r as RippleInfiniteLoopError };\n\n//# sourceMappingURL=errors.js.map","import { RippleComputedCycleError as e, RippleDisposedScopeError as t, RippleInfiniteLoopError as n } from \"./errors.js\";\n//#region src/runtime.ts\nvar r = Symbol(\"ripple.reactive\"), i = Symbol(\"ripple.signal\"), a = Symbol(\"ripple.computed\"), o = 100, s = Symbol(\"ripple.unset\"), c = class {\n\t[r] = !0;\n\tdependents = /* @__PURE__ */ new Set();\n\tname;\n\truntime;\n\tconstructor(e, t) {\n\t\tthis.runtime = e, this.name = t;\n\t}\n\tsubscribe(e) {\n\t\tthis.peek();\n\t\tlet t = {\n\t\t\tdependencies: /* @__PURE__ */ new Set(),\n\t\t\tonDependencyChanged: () => this.runtime.enqueueListener(e)\n\t\t};\n\t\treturn this.dependents.add(t), () => this.dependents.delete(t);\n\t}\n\tnotify() {\n\t\tfor (let e of [...this.dependents]) e.onDependencyChanged();\n\t}\n}, l = class extends c {\n\t[i] = !0;\n\tcurrent;\n\tequals;\n\tconstructor(e, t, n) {\n\t\tsuper(e, n?.name), this.current = t, this.equals = n?.equals ?? Object.is;\n\t}\n\tget value() {\n\t\treturn this.runtime.track(this), this.current;\n\t}\n\tset value(e) {\n\t\tif (this.equals(this.current, e)) return;\n\t\tlet t = this.current;\n\t\tthis.current = e, this.runtime.emit({\n\t\t\tkind: \"write\",\n\t\t\tname: this.name,\n\t\t\tnext: e,\n\t\t\tprevious: t\n\t\t}), this.runtime.propagate(() => this.notify());\n\t}\n\tpeek() {\n\t\treturn this.current;\n\t}\n}, u = class extends c {\n\t[a] = !0;\n\tdependencies = /* @__PURE__ */ new Set();\n\tcomputing = !1;\n\tdisposed = !1;\n\tdirty = !0;\n\tcurrent = s;\n\tderive;\n\tequals;\n\tconstructor(e, t, n) {\n\t\tsuper(e, n?.name), this.derive = t, this.equals = n?.equals ?? Object.is;\n\t}\n\tget value() {\n\t\treturn this.refresh(), this.runtime.track(this), this.current;\n\t}\n\tpeek() {\n\t\treturn this.refresh(), this.current;\n\t}\n\tonDependencyChanged() {\n\t\tthis.disposed || (this.dirty ||= !0, this.dependents.size > 0 && this.refresh() && this.notify());\n\t}\n\tdispose() {\n\t\tthis.disposed || (this.disposed = !0, this.runtime.clearDependencies(this), this.dependents.clear());\n\t}\n\trefresh() {\n\t\tif (!this.dirty || this.disposed) return !1;\n\t\tif (this.computing) {\n\t\t\tlet t = this.name === void 0 ? \"\" : ` \"${this.name}\"`;\n\t\t\tthrow new e(`computed cycle detected${t}`);\n\t\t}\n\t\tthis.computing = !0, this.runtime.emit({\n\t\t\tkind: \"compute\",\n\t\t\tname: this.name\n\t\t});\n\t\ttry {\n\t\t\tlet e = this.runtime.collect(this, this.derive), t = this.current === s || !this.equals(this.current, e);\n\t\t\treturn this.current = e, this.dirty = !1, t;\n\t\t} finally {\n\t\t\tthis.computing = !1;\n\t\t}\n\t}\n}, d = class {\n\tdisposalController = new AbortController();\n\towned = /* @__PURE__ */ new Set();\n\tname;\n\tisDisposed = !1;\n\truntime;\n\tconstructor(e, t) {\n\t\tthis.runtime = e, this.name = t;\n\t}\n\tget disposed() {\n\t\treturn this.isDisposed;\n\t}\n\tget disposalSignal() {\n\t\treturn this.disposalController.signal;\n\t}\n\trun(e) {\n\t\tif (this.isDisposed) throw new t(\"Cannot run a disposed scope.\");\n\t\treturn this.runtime.withScope(this, e);\n\t}\n\tdispose() {\n\t\tif (!this.isDisposed) {\n\t\t\tthis.isDisposed = !0;\n\t\t\tfor (let e of [...this.owned].reverse()) e.dispose();\n\t\t\tthis.owned.clear(), this.disposalController.abort(), this.runtime.emit({\n\t\t\t\tkind: \"dispose\",\n\t\t\t\tname: this.name,\n\t\t\t\tnode: \"scope\"\n\t\t\t});\n\t\t}\n\t}\n\t[Symbol.dispose]() {\n\t\tthis.dispose();\n\t}\n}, f = class {\n\tdependencies = /* @__PURE__ */ new Set();\n\tdisposalController = new AbortController();\n\tcleanup;\n\tisDisposed = !1;\n\towner;\n\tscheduled = !1;\n\tcallback;\n\toptions;\n\truntime;\n\tconstructor(e, t, n) {\n\t\tthis.runtime = e, this.callback = t, this.options = n;\n\t}\n\tget disposed() {\n\t\treturn this.isDisposed;\n\t}\n\tget disposalSignal() {\n\t\treturn this.disposalController.signal;\n\t}\n\tonDependencyChanged() {\n\t\tif (!this.isDisposed) {\n\t\t\tif (this.options?.scheduler === \"microtask\") {\n\t\t\t\tif (this.scheduled) return;\n\t\t\t\tthis.scheduled = !0, queueMicrotask(() => {\n\t\t\t\t\tthis.scheduled = !1, this.isDisposed || this.runtime.enqueue(this);\n\t\t\t\t});\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tthis.runtime.enqueue(this);\n\t\t}\n\t}\n\trun() {\n\t\tif (this.isDisposed) return;\n\t\tthis.owner?.dispose(), this.owner = void 0, this.runCleanup(), this.runtime.emit({\n\t\t\tkind: \"effect\",\n\t\t\tname: this.options?.name\n\t\t});\n\t\tlet e = new d(this.runtime);\n\t\ttry {\n\t\t\tlet t = this.runtime.withEffectScope(e, () => this.runtime.collectEffect(this, this.callback));\n\t\t\tthis.owner = e, this.cleanup = typeof t == \"function\" ? t : void 0;\n\t\t} catch (t) {\n\t\t\te.dispose(), this.runtime.report(t, {\n\t\t\t\tkind: \"effect\",\n\t\t\t\tname: this.options?.name\n\t\t\t});\n\t\t}\n\t}\n\tdispose() {\n\t\tthis.isDisposed || (this.isDisposed = !0, this.owner?.dispose(), this.owner = void 0, this.runtime.clearDependencies(this), this.runCleanup(), this.disposalController.abort(), this.runtime.emit({\n\t\t\tkind: \"dispose\",\n\t\t\tname: this.options?.name,\n\t\t\tnode: \"effect\"\n\t\t}));\n\t}\n\t[Symbol.dispose]() {\n\t\tthis.dispose();\n\t}\n\trunCleanup() {\n\t\tlet e = this.cleanup;\n\t\tif (this.cleanup = void 0, e !== void 0) try {\n\t\t\te();\n\t\t} catch (e) {\n\t\t\tthis.runtime.report(e, {\n\t\t\t\tkind: \"cleanup\",\n\t\t\t\tname: this.options?.name\n\t\t\t});\n\t\t}\n\t}\n}, p = class {\n\tactiveEffectScope;\n\tactiveObserver;\n\tactiveScope;\n\tflushDepth = 0;\n\tflushing = !1;\n\tpending = /* @__PURE__ */ new Set();\n\tlisteners = /* @__PURE__ */ new Set();\n\trootScope;\n\tobserver;\n\tonError;\n\tconstructor(e) {\n\t\tthis.observer = e?.observer, this.onError = e?.onError ?? ((e) => {\n\t\t\tqueueMicrotask(() => {\n\t\t\t\tthrow e;\n\t\t\t});\n\t\t}), this.rootScope = new d(this, \"runtime\"), this.activeScope = this.rootScope;\n\t}\n\tsignal = (e, t) => new l(this, e, t);\n\tcomputed = (e, t) => {\n\t\tlet n = new u(this, e, t);\n\t\treturn (this.activeEffectScope ?? this.activeScope).owned.add(n), n;\n\t};\n\teffect = (e, t) => {\n\t\tlet n = new f(this, e, t);\n\t\treturn (this.activeEffectScope ?? this.activeScope).owned.add(n), n.run(), n;\n\t};\n\tcreateScope = (e) => {\n\t\tlet t = new d(this, e);\n\t\treturn this.activeScope.owned.add(t), t;\n\t};\n\tbatch = (e) => this.propagate(e);\n\tuntrack = (e) => this.withObserver(void 0, e);\n\tdispose() {\n\t\tthis.rootScope.dispose();\n\t}\n\ttrack(e) {\n\t\tlet t = this.activeObserver;\n\t\tt?.collecting !== void 0 && t.collecting.add(e);\n\t}\n\tclearDependencies(e) {\n\t\tfor (let t of e.dependencies) t.dependents.delete(e);\n\t\te.dependencies.clear();\n\t}\n\tcollect(e, t) {\n\t\treturn this.collectWith(e, t, !1);\n\t}\n\tcollectEffect(e, t) {\n\t\treturn this.collectWith(e, t, !0);\n\t}\n\twithEffectScope(e, t) {\n\t\tlet n = this.activeEffectScope;\n\t\tthis.activeEffectScope = e;\n\t\ttry {\n\t\t\treturn t();\n\t\t} finally {\n\t\t\tthis.activeEffectScope = n;\n\t\t}\n\t}\n\twithObserver(e, t) {\n\t\tlet n = this.activeObserver;\n\t\tthis.activeObserver = e;\n\t\ttry {\n\t\t\treturn t();\n\t\t} finally {\n\t\t\tthis.activeObserver = n;\n\t\t}\n\t}\n\twithScope(e, t) {\n\t\tlet n = this.activeEffectScope, r = this.activeScope;\n\t\tthis.activeEffectScope = void 0, this.activeScope = e;\n\t\ttry {\n\t\t\treturn t();\n\t\t} finally {\n\t\t\tthis.activeEffectScope = n, this.activeScope = r;\n\t\t}\n\t}\n\tenqueue(e) {\n\t\tthis.pending.add(e), this.flushDepth === 0 && this.flush();\n\t}\n\tenqueueListener(e) {\n\t\tthis.listeners.add(e), this.flushDepth === 0 && this.flush();\n\t}\n\tpropagate(e) {\n\t\tthis.flushDepth++;\n\t\ttry {\n\t\t\treturn e();\n\t\t} finally {\n\t\t\tthis.flushDepth--, this.flushDepth === 0 && this.flush();\n\t\t}\n\t}\n\temit(e) {\n\t\ttry {\n\t\t\tthis.observer?.(e);\n\t\t} catch (t) {\n\t\t\tthis.report(t, {\n\t\t\t\tkind: \"observer\",\n\t\t\t\tname: e.name\n\t\t\t});\n\t\t}\n\t}\n\treport(e, t) {\n\t\ttry {\n\t\t\tthis.onError(e, t);\n\t\t} catch (e) {\n\t\t\tqueueMicrotask(() => {\n\t\t\t\tthrow e;\n\t\t\t});\n\t\t}\n\t}\n\tcollectWith(e, t, n) {\n\t\tlet r = this.activeObserver, i = /* @__PURE__ */ new Set();\n\t\te.collecting = i, this.activeObserver = e;\n\t\ttry {\n\t\t\tlet n = t();\n\t\t\treturn this.commitDependencies(e, i), n;\n\t\t} catch (t) {\n\t\t\tthrow n && this.commitDependencies(e, i), t;\n\t\t} finally {\n\t\t\te.collecting = void 0, this.activeObserver = r;\n\t\t}\n\t}\n\tcommitDependencies(e, t) {\n\t\tfor (let n of e.dependencies) t.has(n) || n.dependents.delete(e);\n\t\tfor (let n of t) e.dependencies.has(n) || n.dependents.add(e);\n\t\te.dependencies.clear();\n\t\tfor (let n of t) e.dependencies.add(n);\n\t}\n\tflush() {\n\t\tif (this.flushing) return;\n\t\tthis.flushing = !0;\n\t\tlet e = 0;\n\t\ttry {\n\t\t\tfor (; this.pending.size > 0 || this.listeners.size > 0;) {\n\t\t\t\tif (++e > o) throw new n(`infinite reactive flush (>${o} iterations)`);\n\t\t\t\tlet t = [...this.pending], r = [...this.listeners];\n\t\t\t\tthis.pending.clear(), this.listeners.clear();\n\t\t\t\tfor (let e of t) e.run();\n\t\t\t\tfor (let e of r) try {\n\t\t\t\t\te();\n\t\t\t\t} catch (e) {\n\t\t\t\t\tthis.report(e, { kind: \"listener\" });\n\t\t\t\t}\n\t\t\t}\n\t\t} finally {\n\t\t\tthis.flushing = !1;\n\t\t}\n\t}\n}, m = (e) => typeof e == \"object\" && !!e && r in e;\n//#endregion\nexport { p as ReactiveRuntime, m as isReactive };\n\n//# sourceMappingURL=runtime.js.map","//#region src/_async.ts\nvar e = (e) => (t, n, r) => {\n\tlet i = e.signal({ status: \"pending\" }, { name: r?.name }), a = e.signal(0), o = new AbortController(), s, c = !1, l = () => {\n\t\ta.value, s?.abort();\n\t\tlet e = i.peek(), r = e.status === \"success\" ? e.value : \"previous\" in e ? e.previous : void 0, o;\n\t\ttry {\n\t\t\to = t();\n\t\t} catch (e) {\n\t\t\ti.value = r === void 0 ? {\n\t\t\t\terror: e,\n\t\t\t\tstatus: \"error\"\n\t\t\t} : {\n\t\t\t\terror: e,\n\t\t\t\tprevious: r,\n\t\t\t\tstatus: \"error\"\n\t\t\t};\n\t\t\treturn;\n\t\t}\n\t\tlet l = new AbortController();\n\t\ts = l, i.value = r === void 0 ? { status: \"pending\" } : {\n\t\t\tprevious: r,\n\t\t\tstatus: \"pending\"\n\t\t};\n\t\tlet u;\n\t\ttry {\n\t\t\tu = Promise.resolve(n(o, { signal: l.signal }));\n\t\t} catch (e) {\n\t\t\tu = Promise.reject(e);\n\t\t}\n\t\tu.then((e) => {\n\t\t\t!c && !l.signal.aborted && (i.value = {\n\t\t\t\tstatus: \"success\",\n\t\t\t\tvalue: e\n\t\t\t});\n\t\t}, (e) => {\n\t\t\t!c && !l.signal.aborted && (i.value = r === void 0 ? {\n\t\t\t\terror: e,\n\t\t\t\tstatus: \"error\"\n\t\t\t} : {\n\t\t\t\terror: e,\n\t\t\t\tprevious: r,\n\t\t\t\tstatus: \"error\"\n\t\t\t});\n\t\t});\n\t}, u = e.effect(() => (l(), () => s?.abort()), { name: r?.name });\n\treturn u.disposalSignal.addEventListener(\"abort\", () => {\n\t\tc = !0, o.abort();\n\t}, { once: !0 }), {\n\t\tget disposalSignal() {\n\t\t\treturn o.signal;\n\t\t},\n\t\tdispose: () => u.dispose(),\n\t\tget disposed() {\n\t\t\treturn c;\n\t\t},\n\t\tget name() {\n\t\t\treturn i.name;\n\t\t},\n\t\tpeek: () => i.peek(),\n\t\treload: () => {\n\t\t\tc || (a.value = a.peek() + 1);\n\t\t},\n\t\tsubscribe: (e) => i.subscribe(e),\n\t\t[Symbol.dispose]() {\n\t\t\tthis.dispose();\n\t\t},\n\t\tget value() {\n\t\t\treturn i.value;\n\t\t}\n\t};\n};\n//#endregion\nexport { e as createResource };\n\n//# sourceMappingURL=_async.js.map","//#region src/_store.ts\nvar e = (e) => (t, n) => {\n\tlet r = e.signal(t, { name: n?.name });\n\treturn {\n\t\tget name() {\n\t\t\treturn r.name;\n\t\t},\n\t\tpeek: () => r.peek(),\n\t\tset: (e) => {\n\t\t\tr.value = e;\n\t\t},\n\t\tsubscribe: (e) => r.subscribe(e),\n\t\tupdate: (e) => {\n\t\t\tr.value = e(r.peek());\n\t\t},\n\t\tget value() {\n\t\t\treturn r.value;\n\t\t}\n\t};\n};\n//#endregion\nexport { e as createStore };\n\n//# sourceMappingURL=_store.js.map","//#region src/_watch.ts\nvar e = (e) => (t, n, r) => {\n\tlet i = typeof t == \"function\" ? t : () => t.value, a = r?.equals ?? Object.is, o = !0, s, c = !1, l = e.effect(() => {\n\t\tlet e = i();\n\t\tif (o) {\n\t\t\to = !1, s = e, r?.immediate && n(e, void 0), c = r?.once === !0 && r.immediate === !0;\n\t\t\treturn;\n\t\t}\n\t\tif (a(s, e)) return;\n\t\tlet t = s;\n\t\ts = e, n(e, t), r?.once && l.dispose();\n\t}, { name: r?.name });\n\treturn c && l.dispose(), l;\n};\n//#endregion\nexport { e as createWatch };\n\n//# sourceMappingURL=_watch.js.map","import { RippleComputedCycleError as e, RippleDisposedScopeError as t, RippleError as n, RippleInfiniteLoopError as r } from \"./errors.js\";\nimport { ReactiveRuntime as i, isReactive as a } from \"./runtime.js\";\nimport { createResource as o } from \"./_async.js\";\nimport { createStore as s } from \"./_store.js\";\nimport { createWatch as c } from \"./_watch.js\";\n//#region src/index.ts\nvar l = (e) => {\n\tlet t = new i(e), n = o(t), r = s(t);\n\treturn {\n\t\tbatch: t.batch,\n\t\tcomputed: t.computed,\n\t\tcreateScope: t.createScope,\n\t\tcreateStore: r,\n\t\tdispose: () => t.dispose(),\n\t\teffect: t.effect,\n\t\tresource: n,\n\t\tsignal: t.signal,\n\t\tuntrack: t.untrack,\n\t\twatch: c(t)\n\t};\n}, u = l(), d = u.signal, f = u.computed, p = u.effect, m = u.batch, h = u.createScope, g = u.createStore, _ = u.resource, v = u.untrack, y = u.watch;\n//#endregion\nexport { e as RippleComputedCycleError, t as RippleDisposedScopeError, n as RippleError, r as RippleInfiniteLoopError, m as batch, f as computed, l as createRipple, h as createScope, g as createStore, p as effect, a as isReactive, _ as resource, d as signal, v as untrack, y as watch };\n\n//# sourceMappingURL=index.js.map","const isDev = !(globalThis as { __LEDGER_PROD__?: boolean }).__LEDGER_PROD__;\n\n/** @internal @security Messages may include user data. */\nexport function warn(msg: string): void {\n if (isDev) console.warn(`[@vielzeug/ledger] ${msg}`);\n}\n\n/** @internal — Run fn only in dev builds. Use when dev-only logic goes beyond a single warn() / error() call. */\nexport function devOnly(fn: () => void): void {\n if (isDev) fn();\n}\n","import { computed, signal } from '@vielzeug/ripple';\n\nimport type { Command, CommandMeta, Ledger, LedgerCallOptions, LedgerOptions } from './types';\n\nimport { warn } from './_dev';\nimport { LedgerDisposedError, LedgerExecutionError, LedgerRollbackError } from './errors';\n\nfunction toMessage(err: unknown): string {\n return err instanceof Error ? err.message : String(err);\n}\n\ntype StackEntry<TData = unknown> = {\n execute: (signal?: AbortSignal) => Promise<void>;\n meta: CommandMeta<TData>;\n rollback?: (signal?: AbortSignal) => Promise<void>;\n};\n\nfunction entryFromCommand<TData>(command: Command<TData>): StackEntry<TData> {\n const { rollback } = command;\n\n return {\n execute: async (signal) => command.execute(signal),\n meta: { data: command.data, label: command.label },\n rollback: rollback != null ? async (signal) => rollback(signal) : undefined,\n };\n}\n\n/**\n * Creates an async undo/redo command history.\n *\n * Each command is `{ execute, rollback? }`. `rollback` is optional — commands\n * without one are still tracked in history but undo skips the reversal step.\n * Operations are serialised — concurrent calls queue behind each other.\n * All state signals are Ripple `Computed` values for zero-glue UI binding.\n *\n * `execute`/`rollback` receive an `AbortSignal` — merged from the ledger's own\n * `disposalSignal` and any `signal` passed to `do()`/`undo()`/`redo()` — so long-running\n * commands can observe cancellation or disposal.\n *\n * @example\n * const ledger = createLedger({ maxHistory: 50 });\n * await ledger.do({ execute: () => { item.name = next; }, rollback: () => { item.name = prev; } });\n * await ledger.undo();\n * await ledger.redo();\n * using ledger = createLedger();\n */\nexport function createLedger<TData = unknown>(options: LedgerOptions<TData> = {}): Ledger<TData> {\n const { maxHistory = 100, onRollbackError } = options;\n\n if (maxHistory < 1) warn('maxHistory must be >= 1; history tracking is disabled for this ledger.');\n\n const undoStack = signal<StackEntry<TData>[]>([], { name: 'ledger:undoStack' });\n const redoStack = signal<StackEntry<TData>[]>([], { name: 'ledger:redoStack' });\n const pending = signal(0, { name: 'ledger:pending' });\n const processing = signal(false, { name: 'ledger:processing' });\n\n const canUndo = computed(() => undoStack.value.length > 0, { name: 'ledger:canUndo' });\n const canRedo = computed(() => redoStack.value.length > 0, { name: 'ledger:canRedo' });\n const historySize = computed(() => undoStack.value.length, { name: 'ledger:historySize' });\n const isProcessing = computed(() => processing.value, { name: 'ledger:isProcessing' });\n const pendingCount = computed(() => pending.value, { name: 'ledger:pendingCount' });\n const historySnapshot = computed(\n (): readonly CommandMeta<TData>[] => [...undoStack.value].reverse().map((e) => e.meta),\n { name: 'ledger:historySnapshot' },\n );\n\n let isDisposed = false;\n let queue = Promise.resolve();\n\n const ac = new AbortController();\n\n function operationSignal(external?: AbortSignal): AbortSignal {\n return external ? AbortSignal.any([external, ac.signal]) : ac.signal;\n }\n\n function enqueue(method: string, task: () => Promise<void>): Promise<void> {\n if (isDisposed) return Promise.reject(new LedgerDisposedError(`Cannot call ${method}() on a disposed ledger.`));\n\n pending.value++;\n\n const current = queue.then(task).finally(() => {\n if (!isDisposed) pending.value--;\n });\n\n queue = current.catch(() => {});\n\n return current;\n }\n\n async function withProcessing(fn: () => Promise<void>): Promise<void> {\n processing.value = true;\n\n try {\n await fn();\n } finally {\n if (!isDisposed) processing.value = false;\n }\n }\n\n async function runDo(entry: StackEntry<TData>, signal: AbortSignal): Promise<void> {\n await withProcessing(async () => {\n try {\n await entry.execute(signal);\n } catch (err) {\n throw new LedgerExecutionError(toMessage(err), { cause: err });\n }\n\n if (isDisposed) return;\n\n const next = [...undoStack.value, entry];\n\n if (next.length > maxHistory) next.shift();\n\n undoStack.value = next;\n redoStack.value = [];\n });\n }\n\n async function runUndo(signal: AbortSignal): Promise<void> {\n const stack = undoStack.value;\n\n if (stack.length === 0) return;\n\n const entry = stack[stack.length - 1];\n\n await withProcessing(async () => {\n if (entry.rollback) {\n try {\n await entry.rollback(signal);\n } catch (err) {\n warn(`rollback() threw for \"${entry.meta.label ?? '(unlabelled)'}\". Stack position unchanged.`);\n onRollbackError?.(new LedgerRollbackError(toMessage(err), { cause: err }), entry.meta);\n\n return;\n }\n }\n\n if (isDisposed) return;\n\n undoStack.value = stack.slice(0, -1);\n redoStack.value = [...redoStack.value, entry];\n });\n }\n\n async function runRedo(signal: AbortSignal): Promise<void> {\n const stack = redoStack.value;\n\n if (stack.length === 0) return;\n\n const entry = stack[stack.length - 1];\n\n await withProcessing(async () => {\n try {\n await entry.execute(signal);\n } catch (err) {\n throw new LedgerExecutionError(toMessage(err), { cause: err });\n }\n\n if (isDisposed) return;\n\n redoStack.value = stack.slice(0, -1);\n undoStack.value = [...undoStack.value, entry];\n });\n }\n\n function clear(): Promise<void> {\n return enqueue('clear', async () => {\n if (isDisposed) return;\n\n undoStack.value = [];\n redoStack.value = [];\n });\n }\n\n function dispose(): void {\n isDisposed = true;\n ac.abort();\n\n undoStack.value = [];\n redoStack.value = [];\n }\n\n return {\n canRedo,\n canUndo,\n\n clear,\n\n get disposalSignal(): AbortSignal {\n return ac.signal;\n },\n dispose,\n get disposed(): boolean {\n return isDisposed;\n },\n\n do(command: Command<TData>, callOptions?: LedgerCallOptions): Promise<void> {\n return enqueue('do', () => runDo(entryFromCommand<TData>(command), operationSignal(callOptions?.signal)));\n },\n\n historySize,\n historySnapshot,\n isProcessing,\n pendingCount,\n\n redo(callOptions?: LedgerCallOptions): Promise<void> {\n return enqueue('redo', () => runRedo(operationSignal(callOptions?.signal)));\n },\n\n [Symbol.dispose](): void {\n dispose();\n },\n\n undo(callOptions?: LedgerCallOptions): Promise<void> {\n return enqueue('undo', () => runUndo(operationSignal(callOptions?.signal)));\n },\n };\n}\n"],"mappings":"mEAeA,SAAgB,EAAyB,EAA4B,EAAgC,CAGnG,MAAO,CACL,QAAS,KAAO,IAAW,CACzB,IAAM,EAAyB,CAAC,EAEhC,GAAI,CACF,IAAK,IAAM,KAAK,EACd,MAAM,EAAE,QAAQ,CAAM,EACtB,EAAK,KAAK,CAAC,CAEf,OAAS,EAAK,CACZ,IAAK,IAAM,IAAK,CAAC,GAAG,CAAI,CAAC,CAAC,QAAQ,EAChC,GAAI,CACF,MAAM,EAAE,WAAW,CAAM,CAC3B,MAAQ,CAER,CAGF,MAAM,CACR,CACF,EACA,QACA,SAxBqB,EAAS,KAAM,GAAM,EAAE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AQ,QAAS,SAAY,CAC9B,IAEJ,EAAU,MAAQ,CAAC,EACnB,EAAU,MAAQ,CAAC,EACrB,CAAC,CACH,CAEA,SAAS,GAAgB,CACvB,EAAa,GACb,EAAG,MAAM,EAET,EAAU,MAAQ,CAAC,EACnB,EAAU,MAAQ,CAAC,CACrB,CAEA,MAAO,CACL,UACA,UAEA,QAEA,IAAI,gBAA8B,CAChC,OAAO,EAAG,MACZ,EACA,UACA,IAAI,UAAoB,CACtB,OAAO,CACT,EAEA,GAAG,EAAyB,EAAgD,CAC1E,OAAO,EAAQ,SAAY,EAAM,EAAwB,CAAO,EAAG,EAAgB,GAAa,MAAM,CAAC,CAAC,CAC1G,EAEA,cACA,kBACA,eACA,eAEA,KAAK,EAAgD,CACnD,OAAO,EAAQ,WAAc,EAAQ,EAAgB,GAAa,MAAM,CAAC,CAAC,CAC5E,EAEA,CAAC,OAAO,UAAiB,CACvB,EAAQ,CACV,EAEA,KAAK,EAAgD,CACnD,OAAO,EAAQ,WAAc,EAAQ,EAAgB,GAAa,MAAM,CAAC,CAAC,CAC5E,CACF,CACF"}
1
+ {"version":3,"file":"ledger.cjs","names":["e","i","i","a","c","l","u","d","t","e","f","n","p","r","e","e","r","e","t","n","s"],"sources":["../src/compose.ts","../src/errors.ts","../../ripple/dist/errors.js","../../ripple/dist/runtime.js","../../ripple/dist/_async.js","../../ripple/dist/_store.js","../../ripple/dist/_watch.js","../../ripple/dist/_default.js","../../ripple/dist/index.js","../src/ledger.ts"],"sourcesContent":["import type { CommandContext, ReversibleCommand } from './types';\n\nfunction snapshotCommand<TMeta>(command: ReversibleCommand<TMeta>): ReversibleCommand<TMeta> {\n const { apply, label, meta, revert } = command;\n\n return { apply, label, meta, revert };\n}\n\n/**\n * Composes reversible commands into one reversible command.\n *\n * `apply` runs each child in order. `revert` runs children in reverse order.\n * A failed child application compensates completed children before rethrowing.\n *\n * @example\n * await ledger.do(compose([\n * { apply: () => { node.x = newX; }, revert: () => { node.x = oldX; } },\n * { apply: () => { node.y = newY; }, revert: () => { node.y = oldY; } },\n * ], 'Move node'));\n */\nexport function compose<TMeta = undefined>(\n commands: readonly ReversibleCommand<TMeta>[],\n label?: string,\n): ReversibleCommand<TMeta> {\n const steps = commands.map(snapshotCommand);\n\n return {\n apply: async (context: CommandContext) => {\n const applied: ReversibleCommand<TMeta>[] = [];\n\n try {\n for (const command of steps) {\n await command.apply(context);\n applied.push(command);\n }\n } catch (error) {\n const compensationFailures: unknown[] = [];\n\n for (const command of [...applied].reverse()) {\n try {\n await command.revert(context);\n } catch (compensationError) {\n compensationFailures.push(compensationError);\n }\n }\n\n if (compensationFailures.length > 0) {\n throw new AggregateError([error, ...compensationFailures], 'Command application and compensation failed', {\n cause: error,\n });\n }\n\n throw error;\n }\n },\n label,\n revert: async (context: CommandContext) => {\n const failures: unknown[] = [];\n\n for (const command of [...steps].reverse()) {\n try {\n await command.revert(context);\n } catch (error) {\n failures.push(error);\n }\n }\n\n if (failures.length > 0) throw new AggregateError(failures, 'Command reversion failed');\n },\n };\n}\n","/** Base class for all ledger errors. Use `instanceof LedgerError` to catch any ledger-originated error. */\nexport class LedgerError extends Error {\n constructor(message: string, opts?: ErrorOptions) {\n super(message, opts);\n this.name = new.target.name;\n Object.setPrototypeOf(this, new.target.prototype);\n }\n\n static is(err: unknown): err is LedgerError {\n return err instanceof LedgerError;\n }\n}\n\n/** Thrown when a queued operation is cancelled before user code starts, or an active operation cooperatively stops. */\nexport class LedgerCancelledError extends LedgerError {}\n\n/** Thrown when a method is called on a disposed ledger instance. */\nexport class LedgerDisposedError extends LedgerError {}\n\n/** Thrown when a command's `apply()` function throws. The original error is available via `.cause`. */\nexport class LedgerExecutionError extends LedgerError {}\n\n/** Thrown when a command's `revert()` function throws during an undo operation. The original error is available via `.cause`. */\nexport class LedgerRollbackError extends LedgerError {}\n","//#region src/errors.ts\nvar e = class e extends Error {\n\tconstructor(e, t) {\n\t\tsuper(e, t), this.name = new.target.name, Object.setPrototypeOf(this, new.target.prototype);\n\t}\n\tstatic is(t) {\n\t\treturn t instanceof e;\n\t}\n}, t = class extends e {}, n = class extends e {}, r = class extends e {}, i = class extends e {};\n//#endregion\nexport { t as RippleComputedCycleError, n as RippleDisposedRuntimeError, r as RippleDisposedScopeError, e as RippleError, i as RippleInfiniteLoopError };\n\n//# sourceMappingURL=errors.js.map","import { RippleComputedCycleError as e, RippleDisposedRuntimeError as t, RippleDisposedScopeError as n, RippleInfiniteLoopError as r } from \"./errors.js\";\n//#region src/runtime.ts\nvar i = Symbol(\"ripple.reactive\"), a = Symbol(\"ripple.signal\"), o = Symbol(\"ripple.computed\"), s = 100, c = Symbol(\"ripple.unset\"), l = class {\n\t[i] = !0;\n\tdependents = /* @__PURE__ */ new Set();\n\tname;\n\truntime;\n\tconstructor(e, t) {\n\t\tthis.runtime = e, this.name = t;\n\t}\n\tsubscribe(e) {\n\t\tthis.runtime.assertActive(), this.peek();\n\t\tlet t = {\n\t\t\tdependencies: /* @__PURE__ */ new Set(),\n\t\t\tonDependencyChanged: () => this.runtime.enqueueListener(e)\n\t\t};\n\t\treturn this.dependents.add(t), () => this.dependents.delete(t);\n\t}\n\tnotify() {\n\t\tfor (let e of [...this.dependents]) e.onDependencyChanged();\n\t}\n}, u = class extends l {\n\t[a] = !0;\n\tcurrent;\n\tequals;\n\tconstructor(e, t, n) {\n\t\tsuper(e, n?.name), this.current = t, this.equals = n?.equals ?? Object.is;\n\t}\n\tget value() {\n\t\treturn this.runtime.track(this), this.current;\n\t}\n\tset value(e) {\n\t\tif (this.runtime.assertActive(), this.equals(this.current, e)) return;\n\t\tlet t = this.current;\n\t\tthis.current = e, this.runtime.emit({\n\t\t\tkind: \"write\",\n\t\t\tname: this.name,\n\t\t\tnext: e,\n\t\t\tprevious: t\n\t\t}), this.runtime.propagate(() => this.notify());\n\t}\n\tpeek() {\n\t\treturn this.current;\n\t}\n}, d = class extends l {\n\t[o] = !0;\n\tdependencies = /* @__PURE__ */ new Set();\n\tcomputing = !1;\n\tdisposed = !1;\n\tdirty = !0;\n\tcurrent = c;\n\tderive;\n\tequals;\n\tconstructor(e, t, n) {\n\t\tsuper(e, n?.name), this.derive = t, this.equals = n?.equals ?? Object.is;\n\t}\n\tget value() {\n\t\treturn this.refresh(), this.runtime.track(this), this.current;\n\t}\n\tpeek() {\n\t\treturn this.refresh(), this.current;\n\t}\n\tonDependencyChanged() {\n\t\tthis.disposed || (this.dirty ||= !0, this.dependents.size > 0 && this.refresh() && this.notify());\n\t}\n\tdispose() {\n\t\tthis.disposed || (this.disposed = !0, this.runtime.clearDependencies(this), this.dependents.clear());\n\t}\n\trefresh() {\n\t\tif (!this.dirty || this.disposed) return !1;\n\t\tif (this.computing) {\n\t\t\tlet t = this.name === void 0 ? \"\" : ` \"${this.name}\"`;\n\t\t\tthrow new e(`computed cycle detected${t}`);\n\t\t}\n\t\tthis.computing = !0, this.runtime.emit({\n\t\t\tkind: \"compute\",\n\t\t\tname: this.name\n\t\t});\n\t\ttry {\n\t\t\tlet e = this.runtime.collect(this, this.derive), t = this.current === c || !this.equals(this.current, e);\n\t\t\treturn this.current = e, this.dirty = !1, t;\n\t\t} finally {\n\t\t\tthis.computing = !1;\n\t\t}\n\t}\n}, f = class {\n\tdisposalController = new AbortController();\n\towned = /* @__PURE__ */ new Set();\n\tname;\n\tisDisposed = !1;\n\truntime;\n\tconstructor(e, t) {\n\t\tthis.runtime = e, this.name = t;\n\t}\n\tget disposed() {\n\t\treturn this.isDisposed;\n\t}\n\tget disposalSignal() {\n\t\treturn this.disposalController.signal;\n\t}\n\trun(e) {\n\t\tif (this.isDisposed) throw new n(\"Cannot run a disposed scope.\");\n\t\treturn this.runtime.withScope(this, e);\n\t}\n\tdispose() {\n\t\tif (!this.isDisposed) {\n\t\t\tthis.isDisposed = !0;\n\t\t\tfor (let e of [...this.owned].reverse()) e.dispose();\n\t\t\tthis.owned.clear(), this.disposalController.abort(), this.runtime.emit({\n\t\t\t\tkind: \"dispose\",\n\t\t\t\tname: this.name,\n\t\t\t\tnode: \"scope\"\n\t\t\t});\n\t\t}\n\t}\n\t[Symbol.dispose]() {\n\t\tthis.dispose();\n\t}\n}, p = class {\n\tdependencies = /* @__PURE__ */ new Set();\n\tdisposalController = new AbortController();\n\tcleanup;\n\tisDisposed = !1;\n\towner;\n\tscheduled = !1;\n\tcallback;\n\toptions;\n\truntime;\n\tconstructor(e, t, n) {\n\t\tthis.runtime = e, this.callback = t, this.options = n;\n\t}\n\tget disposed() {\n\t\treturn this.isDisposed;\n\t}\n\tget disposalSignal() {\n\t\treturn this.disposalController.signal;\n\t}\n\tonDependencyChanged() {\n\t\tif (!this.isDisposed) {\n\t\t\tif (this.options?.scheduler === \"microtask\") {\n\t\t\t\tif (this.scheduled) return;\n\t\t\t\tthis.scheduled = !0, queueMicrotask(() => {\n\t\t\t\t\tthis.scheduled = !1, this.isDisposed || this.runtime.enqueue(this);\n\t\t\t\t});\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tthis.runtime.enqueue(this);\n\t\t}\n\t}\n\trun() {\n\t\tif (this.isDisposed) return;\n\t\tthis.owner?.dispose(), this.owner = void 0, this.runCleanup(), this.runtime.emit({\n\t\t\tkind: \"effect\",\n\t\t\tname: this.options?.name\n\t\t});\n\t\tlet e = new f(this.runtime);\n\t\ttry {\n\t\t\tlet t = this.runtime.withEffectScope(e, () => this.runtime.collectEffect(this, this.callback));\n\t\t\tthis.owner = e, this.cleanup = typeof t == \"function\" ? t : void 0;\n\t\t} catch (t) {\n\t\t\te.dispose(), this.runtime.report(t, {\n\t\t\t\tkind: \"effect\",\n\t\t\t\tname: this.options?.name\n\t\t\t});\n\t\t}\n\t}\n\tdispose() {\n\t\tthis.isDisposed || (this.isDisposed = !0, this.owner?.dispose(), this.owner = void 0, this.runtime.clearDependencies(this), this.runCleanup(), this.disposalController.abort(), this.runtime.emit({\n\t\t\tkind: \"dispose\",\n\t\t\tname: this.options?.name,\n\t\t\tnode: \"effect\"\n\t\t}));\n\t}\n\t[Symbol.dispose]() {\n\t\tthis.dispose();\n\t}\n\trunCleanup() {\n\t\tlet e = this.cleanup;\n\t\tif (this.cleanup = void 0, e !== void 0) try {\n\t\t\te();\n\t\t} catch (e) {\n\t\t\tthis.runtime.report(e, {\n\t\t\t\tkind: \"cleanup\",\n\t\t\t\tname: this.options?.name\n\t\t\t});\n\t\t}\n\t}\n}, m = class {\n\tactiveEffectScope;\n\tactiveObserver;\n\tactiveScope;\n\tisDisposed = !1;\n\tflushDepth = 0;\n\tflushing = !1;\n\tpending = /* @__PURE__ */ new Set();\n\tlisteners = /* @__PURE__ */ new Set();\n\trootScope;\n\tobserver;\n\tonError;\n\tconstructor(e) {\n\t\tthis.observer = e?.observer, this.onError = e?.onError ?? ((e) => {\n\t\t\tqueueMicrotask(() => {\n\t\t\t\tthrow e;\n\t\t\t});\n\t\t}), this.rootScope = new f(this, \"runtime\"), this.activeScope = this.rootScope;\n\t}\n\tget disposed() {\n\t\treturn this.isDisposed;\n\t}\n\tsignal = (e, t) => (this.assertActive(), new u(this, e, t));\n\tcomputed = (e, t) => {\n\t\tthis.assertActive();\n\t\tlet n = new d(this, e, t);\n\t\treturn (this.activeEffectScope ?? this.activeScope).owned.add(n), n;\n\t};\n\teffect = (e, t) => {\n\t\tthis.assertActive();\n\t\tlet n = new p(this, e, t);\n\t\treturn (this.activeEffectScope ?? this.activeScope).owned.add(n), n.run(), n;\n\t};\n\tcreateScope = (e) => {\n\t\tthis.assertActive();\n\t\tlet t = new f(this, e);\n\t\treturn this.activeScope.owned.add(t), t;\n\t};\n\tbatch = (e) => (this.assertActive(), this.propagate(e));\n\tuntrack = (e) => (this.assertActive(), this.withObserver(void 0, e));\n\tdispose() {\n\t\tthis.isDisposed || (this.isDisposed = !0, this.rootScope.dispose());\n\t}\n\tassertActive() {\n\t\tif (this.isDisposed) throw new t(\"Cannot use a disposed Ripple runtime.\");\n\t}\n\ttrack(e) {\n\t\tlet t = this.activeObserver;\n\t\tt?.collecting !== void 0 && t.collecting.add(e);\n\t}\n\tclearDependencies(e) {\n\t\tfor (let t of e.dependencies) t.dependents.delete(e);\n\t\te.dependencies.clear();\n\t}\n\tcollect(e, t) {\n\t\treturn this.collectWith(e, t, !1);\n\t}\n\tcollectEffect(e, t) {\n\t\treturn this.collectWith(e, t, !0);\n\t}\n\twithEffectScope(e, t) {\n\t\tlet n = this.activeEffectScope;\n\t\tthis.activeEffectScope = e;\n\t\ttry {\n\t\t\treturn t();\n\t\t} finally {\n\t\t\tthis.activeEffectScope = n;\n\t\t}\n\t}\n\twithObserver(e, t) {\n\t\tlet n = this.activeObserver;\n\t\tthis.activeObserver = e;\n\t\ttry {\n\t\t\treturn t();\n\t\t} finally {\n\t\t\tthis.activeObserver = n;\n\t\t}\n\t}\n\twithScope(e, t) {\n\t\tlet n = this.activeEffectScope, r = this.activeScope;\n\t\tthis.activeEffectScope = void 0, this.activeScope = e;\n\t\ttry {\n\t\t\treturn t();\n\t\t} finally {\n\t\t\tthis.activeEffectScope = n, this.activeScope = r;\n\t\t}\n\t}\n\tenqueue(e) {\n\t\tthis.pending.add(e), this.flushDepth === 0 && this.flush();\n\t}\n\tenqueueListener(e) {\n\t\tthis.listeners.add(e), this.flushDepth === 0 && this.flush();\n\t}\n\tpropagate(e) {\n\t\tthis.flushDepth++;\n\t\ttry {\n\t\t\treturn e();\n\t\t} finally {\n\t\t\tthis.flushDepth--, this.flushDepth === 0 && this.flush();\n\t\t}\n\t}\n\temit(e) {\n\t\ttry {\n\t\t\tthis.observer?.(e);\n\t\t} catch (t) {\n\t\t\tthis.report(t, {\n\t\t\t\tkind: \"observer\",\n\t\t\t\tname: e.name\n\t\t\t});\n\t\t}\n\t}\n\treport(e, t) {\n\t\ttry {\n\t\t\tthis.onError(e, t);\n\t\t} catch (e) {\n\t\t\tqueueMicrotask(() => {\n\t\t\t\tthrow e;\n\t\t\t});\n\t\t}\n\t}\n\tcollectWith(e, t, n) {\n\t\tlet r = this.activeObserver, i = /* @__PURE__ */ new Set();\n\t\te.collecting = i, this.activeObserver = e;\n\t\ttry {\n\t\t\tlet n = t();\n\t\t\treturn this.commitDependencies(e, i), n;\n\t\t} catch (t) {\n\t\t\tthrow n && this.commitDependencies(e, i), t;\n\t\t} finally {\n\t\t\te.collecting = void 0, this.activeObserver = r;\n\t\t}\n\t}\n\tcommitDependencies(e, t) {\n\t\tfor (let n of e.dependencies) t.has(n) || n.dependents.delete(e);\n\t\tfor (let n of t) e.dependencies.has(n) || n.dependents.add(e);\n\t\te.dependencies.clear();\n\t\tfor (let n of t) e.dependencies.add(n);\n\t}\n\tflush() {\n\t\tif (this.flushing) return;\n\t\tthis.flushing = !0;\n\t\tlet e = 0;\n\t\ttry {\n\t\t\tfor (; this.pending.size > 0 || this.listeners.size > 0;) {\n\t\t\t\tif (++e > s) throw new r(`infinite reactive flush (>${s} iterations)`);\n\t\t\t\tlet t = [...this.pending], n = [...this.listeners];\n\t\t\t\tthis.pending.clear(), this.listeners.clear();\n\t\t\t\tfor (let e of t) e.run();\n\t\t\t\tfor (let e of n) try {\n\t\t\t\t\te();\n\t\t\t\t} catch (e) {\n\t\t\t\t\tthis.report(e, { kind: \"listener\" });\n\t\t\t\t}\n\t\t\t}\n\t\t} finally {\n\t\t\tthis.flushing = !1;\n\t\t}\n\t}\n}, h = (e) => typeof e == \"object\" && !!e && i in e;\n//#endregion\nexport { m as ReactiveRuntime, h as isReactive };\n\n//# sourceMappingURL=runtime.js.map","//#region src/_async.ts\nvar e = (e) => (t, n, r) => {\n\tlet i = e.signal({ status: \"pending\" }, { name: r?.name }), a = e.signal(0), o = new AbortController(), s, c = !1, l = () => {\n\t\ta.value, s?.abort();\n\t\tlet e = i.peek(), r = e.status === \"success\" ? e.value : \"previous\" in e ? e.previous : void 0, o;\n\t\ttry {\n\t\t\to = t();\n\t\t} catch (e) {\n\t\t\ti.value = r === void 0 ? {\n\t\t\t\terror: e,\n\t\t\t\tstatus: \"error\"\n\t\t\t} : {\n\t\t\t\terror: e,\n\t\t\t\tprevious: r,\n\t\t\t\tstatus: \"error\"\n\t\t\t};\n\t\t\treturn;\n\t\t}\n\t\tlet l = new AbortController();\n\t\ts = l, i.value = r === void 0 ? { status: \"pending\" } : {\n\t\t\tprevious: r,\n\t\t\tstatus: \"pending\"\n\t\t};\n\t\tlet u;\n\t\ttry {\n\t\t\tu = Promise.resolve(n(o, { signal: l.signal }));\n\t\t} catch (e) {\n\t\t\tu = Promise.reject(e);\n\t\t}\n\t\tu.then((e) => {\n\t\t\t!c && !l.signal.aborted && (i.value = {\n\t\t\t\tstatus: \"success\",\n\t\t\t\tvalue: e\n\t\t\t});\n\t\t}, (e) => {\n\t\t\t!c && !l.signal.aborted && (i.value = r === void 0 ? {\n\t\t\t\terror: e,\n\t\t\t\tstatus: \"error\"\n\t\t\t} : {\n\t\t\t\terror: e,\n\t\t\t\tprevious: r,\n\t\t\t\tstatus: \"error\"\n\t\t\t});\n\t\t});\n\t}, u = e.effect(() => (l(), () => s?.abort()), { name: r?.name });\n\treturn u.disposalSignal.addEventListener(\"abort\", () => {\n\t\tc = !0, o.abort();\n\t}, { once: !0 }), {\n\t\tget disposalSignal() {\n\t\t\treturn o.signal;\n\t\t},\n\t\tdispose: () => u.dispose(),\n\t\tget disposed() {\n\t\t\treturn c;\n\t\t},\n\t\tget name() {\n\t\t\treturn i.name;\n\t\t},\n\t\tpeek: () => i.peek(),\n\t\treload: () => {\n\t\t\tc || (a.value = a.peek() + 1);\n\t\t},\n\t\tsubscribe: (e) => i.subscribe(e),\n\t\t[Symbol.dispose]() {\n\t\t\tthis.dispose();\n\t\t},\n\t\tget value() {\n\t\t\treturn i.value;\n\t\t}\n\t};\n};\n//#endregion\nexport { e as createResource };\n\n//# sourceMappingURL=_async.js.map","//#region src/_store.ts\nvar e = (e) => (t, n) => {\n\tlet r = e.signal(t, { name: n?.name });\n\treturn {\n\t\tget name() {\n\t\t\treturn r.name;\n\t\t},\n\t\tpeek: () => r.peek(),\n\t\tset: (e) => {\n\t\t\tr.value = e;\n\t\t},\n\t\tsubscribe: (e) => r.subscribe(e),\n\t\tupdate: (e) => {\n\t\t\tr.value = e(r.peek());\n\t\t},\n\t\tget value() {\n\t\t\treturn r.value;\n\t\t}\n\t};\n};\n//#endregion\nexport { e as createStore };\n\n//# sourceMappingURL=_store.js.map","//#region src/_watch.ts\nvar e = (e) => (t, n, r) => {\n\tlet i = typeof t == \"function\" ? t : () => t.value, a = r?.equals ?? Object.is, o = !0, s, c = !1, l = e.effect(() => {\n\t\tlet e = i();\n\t\tif (o) {\n\t\t\to = !1, s = e, r?.immediate && n(e, void 0), c = r?.once === !0 && r.immediate === !0;\n\t\t\treturn;\n\t\t}\n\t\tif (a(s, e)) return;\n\t\tlet t = s;\n\t\ts = e, n(e, t), r?.once && l.dispose();\n\t}, { name: r?.name });\n\treturn c && l.dispose(), l;\n};\n//#endregion\nexport { e as createWatch };\n\n//# sourceMappingURL=_watch.js.map","import { createResource as e } from \"./_async.js\";\nimport { createStore as t } from \"./_store.js\";\nimport { createWatch as n } from \"./_watch.js\";\nimport { ReactiveRuntime as r } from \"./runtime.js\";\n//#region src/_default.ts\nvar i = (i) => {\n\tlet a = new r(i), o = e(a), s = t(a);\n\treturn {\n\t\tbatch: a.batch,\n\t\tcomputed: a.computed,\n\t\tcreateScope: a.createScope,\n\t\tcreateStore: s,\n\t\tdispose: () => a.dispose(),\n\t\tget disposed() {\n\t\t\treturn a.disposed;\n\t\t},\n\t\teffect: a.effect,\n\t\tresource: o,\n\t\tsignal: a.signal,\n\t\tuntrack: a.untrack,\n\t\twatch: n(a)\n\t};\n}, a = i();\n//#endregion\nexport { i as createRipple, a as defaultRipple };\n\n//# sourceMappingURL=_default.js.map","import { RippleComputedCycleError as e, RippleDisposedRuntimeError as t, RippleDisposedScopeError as n, RippleError as r, RippleInfiniteLoopError as i } from \"./errors.js\";\nimport { isReactive as a } from \"./runtime.js\";\nimport { createRipple as o, defaultRipple as s } from \"./_default.js\";\n//#region src/index.ts\nvar c = s.signal, l = s.computed, u = s.effect, d = s.batch, f = s.createScope, p = s.untrack;\n//#endregion\nexport { e as RippleComputedCycleError, t as RippleDisposedRuntimeError, n as RippleDisposedScopeError, r as RippleError, i as RippleInfiniteLoopError, d as batch, l as computed, o as createRipple, f as createScope, u as effect, a as isReactive, c as signal, p as untrack };\n\n//# sourceMappingURL=index.js.map","import { signal } from '@vielzeug/ripple';\n\nimport type {\n CommandContext,\n HistoryEntry,\n Ledger,\n LedgerCallOptions,\n LedgerOptions,\n LedgerState,\n ReversibleCommand,\n} from './types';\n\nimport {\n LedgerCancelledError,\n LedgerDisposedError,\n LedgerError,\n LedgerExecutionError,\n LedgerRollbackError,\n} from './errors';\n\ntype StoredCommand<TMeta> = {\n apply: (context: CommandContext) => Promise<void> | void;\n entry: HistoryEntry<TMeta>;\n revert: (context: CommandContext) => Promise<void> | void;\n};\n\ntype Operation = {\n cancel: () => void;\n reject: (reason?: unknown) => void;\n resolve: () => void;\n settled: boolean;\n start: () => Promise<void>;\n started: boolean;\n};\n\nfunction toMessage(error: unknown): string {\n return error instanceof Error ? error.message : String(error);\n}\n\nfunction snapshotCommand<TMeta>(command: ReversibleCommand<TMeta>): StoredCommand<TMeta> {\n const { apply, label, meta, revert } = command;\n\n return { apply, entry: Object.freeze({ label, meta }), revert };\n}\n\nfunction snapshotState<TMeta>(state: LedgerState<TMeta>): LedgerState<TMeta> {\n return Object.freeze({\n ...state,\n redo: Object.freeze([...state.redo]),\n undo: Object.freeze([...state.undo]),\n });\n}\n\nfunction operationError(method: string, disposed: boolean): LedgerCancelledError | LedgerDisposedError {\n return disposed\n ? new LedgerDisposedError(`Cannot call ${method}() on a disposed ledger.`)\n : new LedgerCancelledError(`${method}() was cancelled before it started.`);\n}\n\n/**\n * Creates a serialized history of reversible commands.\n *\n * Commands are snapshotted when submitted. Queued commands cancelled before their queue turn do\n * not invoke user code. Active commands receive an abort signal and stop cooperatively.\n *\n * @example\n * const ledger = createLedger({ maxHistory: 50 });\n * await ledger.do({\n * apply: () => { item.name = next; },\n * revert: () => { item.name = previous; },\n * });\n * await ledger.undo();\n * await ledger.redo();\n * using ledger = createLedger();\n */\nexport function createLedger<TMeta = undefined>(options: LedgerOptions = {}): Ledger<TMeta> {\n const { maxHistory = 100 } = options;\n\n if (!Number.isSafeInteger(maxHistory) || maxHistory < 0) {\n throw new RangeError('maxHistory must be a non-negative safe integer');\n }\n\n const state = signal<LedgerState<TMeta>>(\n snapshotState({ accepting: true, queued: 0, redo: [], running: 0, undo: [] }),\n { name: 'ledger:state' },\n );\n const commandStore = new WeakMap<HistoryEntry<TMeta>, StoredCommand<TMeta>>();\n const disposalController = new AbortController();\n const idleWaiters = new Set<() => void>();\n const operations = new Set<Operation>();\n let disposed = false;\n let queue = Promise.resolve();\n\n function updateState(update: (current: LedgerState<TMeta>) => LedgerState<TMeta>): void {\n state.value = snapshotState(update(state.value));\n\n if (state.value.queued === 0 && state.value.running === 0) {\n for (const resolve of idleWaiters) resolve();\n idleWaiters.clear();\n }\n }\n\n function settle(operation: Operation, error?: unknown): void {\n if (operation.settled) return;\n\n operation.settled = true;\n operations.delete(operation);\n operation.cancel();\n\n if (error === undefined) operation.resolve();\n else operation.reject(error);\n }\n\n function enqueue(\n method: string,\n externalSignal: AbortSignal | undefined,\n task: (context: CommandContext) => Promise<void>,\n ): Promise<void> {\n if (disposed) return Promise.reject(operationError(method, true));\n\n const signal = externalSignal\n ? AbortSignal.any([externalSignal, disposalController.signal])\n : disposalController.signal;\n\n return new Promise<void>((resolve, reject) => {\n const operation = {} as Operation;\n const onAbort = (): void => {\n if (operation.started || operation.settled || disposed) return;\n\n updateState((current) => ({ ...current, queued: current.queued - 1 }));\n settle(operation, operationError(method, false));\n };\n\n Object.assign(operation, {\n cancel: () => signal.removeEventListener('abort', onAbort),\n reject,\n resolve,\n settled: false,\n start: async () => {\n if (operation.settled) return;\n\n if (disposed || signal.aborted) {\n updateState((current) => ({ ...current, queued: current.queued - 1 }));\n settle(operation, operationError(method, disposed));\n\n return;\n }\n\n operation.started = true;\n updateState((current) => ({ ...current, queued: current.queued - 1, running: current.running + 1 }));\n\n try {\n await task({ signal });\n settle(operation);\n } catch (error) {\n settle(operation, error);\n } finally {\n updateState((current) => ({ ...current, running: current.running - 1 }));\n }\n },\n started: false,\n });\n\n signal.addEventListener('abort', onAbort, { once: true });\n operations.add(operation);\n updateState((current) => ({ ...current, queued: current.queued + 1 }));\n queue = queue.then(operation.start, operation.start);\n });\n }\n\n async function runDo(command: StoredCommand<TMeta>, context: CommandContext): Promise<void> {\n try {\n await command.apply(context);\n } catch (error) {\n throw context.signal.aborted\n ? new LedgerCancelledError('do() was cancelled while running.', { cause: error })\n : new LedgerExecutionError(toMessage(error), { cause: error });\n }\n\n if (disposed || context.signal.aborted) {\n throw new LedgerCancelledError('do() was cancelled while running.');\n }\n\n updateState((current) => {\n if (maxHistory === 0) return { ...current, redo: [] };\n\n const undo = [...current.undo, command.entry];\n\n if (undo.length > maxHistory) undo.shift();\n\n return { ...current, redo: [], undo };\n });\n commandStore.set(command.entry, command);\n }\n\n async function runUndo(context: CommandContext): Promise<void> {\n const entry = state.value.undo[state.value.undo.length - 1];\n\n if (!entry) return;\n\n const command = commandStore.get(entry);\n\n if (!command) throw new LedgerError('Undo history is corrupted.');\n\n try {\n await command.revert(context);\n } catch (error) {\n throw context.signal.aborted\n ? new LedgerCancelledError('undo() was cancelled while running.', { cause: error })\n : new LedgerRollbackError(toMessage(error), { cause: error });\n }\n\n if (disposed || context.signal.aborted) {\n throw new LedgerCancelledError('undo() was cancelled while running.');\n }\n\n updateState((current) => ({ ...current, redo: [...current.redo, entry], undo: current.undo.slice(0, -1) }));\n }\n\n async function runRedo(context: CommandContext): Promise<void> {\n const entry = state.value.redo[state.value.redo.length - 1];\n\n if (!entry) return;\n\n const command = commandStore.get(entry);\n\n if (!command) throw new LedgerError('Redo history is corrupted.');\n\n try {\n await command.apply(context);\n } catch (error) {\n throw context.signal.aborted\n ? new LedgerCancelledError('redo() was cancelled while running.', { cause: error })\n : new LedgerExecutionError(toMessage(error), { cause: error });\n }\n\n if (disposed || context.signal.aborted) {\n throw new LedgerCancelledError('redo() was cancelled while running.');\n }\n\n updateState((current) => ({ ...current, redo: current.redo.slice(0, -1), undo: [...current.undo, entry] }));\n }\n\n return {\n clear(): Promise<void> {\n return enqueue('clear', undefined, async () => {\n updateState((current) => ({ ...current, redo: [], undo: [] }));\n });\n },\n\n get disposalSignal(): AbortSignal {\n return disposalController.signal;\n },\n\n dispose(): void {\n if (disposed) return;\n\n disposed = true;\n disposalController.abort();\n\n const queued = [...operations].filter((operation) => !operation.started);\n\n for (const operation of queued) settle(operation, operationError('operation', true));\n\n updateState((current) => ({ ...current, accepting: false, queued: 0, redo: [], undo: [] }));\n },\n\n get disposed(): boolean {\n return disposed;\n },\n\n do(command: ReversibleCommand<TMeta>, callOptions?: LedgerCallOptions): Promise<void> {\n const snapshot = snapshotCommand(command);\n\n return enqueue('do', callOptions?.signal, (context) => runDo(snapshot, context));\n },\n\n redo(callOptions?: LedgerCallOptions): Promise<void> {\n return enqueue('redo', callOptions?.signal, runRedo);\n },\n\n get state() {\n return state;\n },\n\n [Symbol.dispose](): void {\n this.dispose();\n },\n\n undo(callOptions?: LedgerCallOptions): Promise<void> {\n return enqueue('undo', callOptions?.signal, runUndo);\n },\n\n whenIdle(): Promise<void> {\n if (state.value.queued === 0 && state.value.running === 0) return Promise.resolve();\n\n return new Promise((resolve) => idleWaiters.add(resolve));\n },\n };\n}\n"],"mappings":"mEAEA,SAAS,EAAuB,EAA6D,CAC3F,GAAM,CAAE,QAAO,QAAO,OAAM,UAAW,EAEvC,MAAO,CAAE,QAAO,QAAO,OAAM,QAAO,CACtC,CAcA,SAAgB,EACd,EACA,EAC0B,CAC1B,IAAM,EAAQ,EAAS,IAAI,CAAe,EAE1C,MAAO,CACL,MAAO,KAAO,IAA4B,CACxC,IAAM,EAAsC,CAAC,EAE7C,GAAI,CACF,IAAK,IAAM,KAAW,EACpB,MAAM,EAAQ,MAAM,CAAO,EAC3B,EA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