@vielzeug/ledger 2.2.0 → 2.2.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/dist/ledger.cjs CHANGED
@@ -1,2 +1,2 @@
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 extends Error{constructor(e,t){super(e,t),this.name=new.target.name,Object.setPrototypeOf(this,new.target.prototype)}},r=class extends n{},i=class extends n{},a=class extends n{},o=class extends n{},s=class extends Error{constructor(e,t){super(e,t),this.name=new.target.name,Object.setPrototypeOf(this,new.target.prototype)}},c=class extends s{},l=class extends s{},u=class extends s{},d=class extends s{},f=Symbol.for(`@vielzeug/ripple/reactive`),p=100,m=Symbol(`ripple.unset`),h=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()}},g=class extends h{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}update(e){this.value=e(this.current)}},_=class extends h{dependencies=new Set;computing=!1;disposed=!1;dirty=!0;current=m;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===m||!this.equals(this.current,e);return this.current=e,this.dirty=!1,t}finally{this.computing=!1}}},v=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()}},y=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 v(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})}}},b=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 v(this,`runtime`),this.activeScope=this.rootScope}get disposed(){return this.isDisposed}signal=(e,t)=>(this.assertActive(),new g(this,e,t));computed=(e,t)=>{this.assertActive();let n=new _(this,e,t);return(this.activeEffectScope??this.activeScope).owned.add(n),n};effect=(e,t)=>{this.assertActive();let n=new y(this,e,t);return(this.activeEffectScope??this.activeScope).owned.add(n),n.run(),n};createScope=e=>{this.assertActive();let t=new v(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>p)throw new d(`infinite reactive flush (>${p} 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}}},x=e=>(t,n,r)=>{let i=e.signal({status:`pending`},{name:r?.name}),a=e.signal(0),o,s=!1,c=()=>{a.value,o?.abort();let e=i.peek(),r=e.status===`success`?e.value:`previous`in e?e.previous:void 0,c;try{c=t()}catch(e){i.value=r===void 0?{error:e,status:`error`}:{error:e,previous:r,status:`error`};return}let l=new AbortController;o=l,i.value=r===void 0?{status:`pending`}:{previous:r,status:`pending`};let u;try{u=Promise.resolve(n(c,{signal:l.signal}))}catch(e){u=Promise.reject(e)}u.then(e=>{!s&&!l.signal.aborted&&(i.value={status:`success`,value:e})},e=>{!s&&!l.signal.aborted&&(i.value=r===void 0?{error:e,status:`error`}:{error:e,previous:r,status:`error`})})},l=e.effect(()=>(c(),()=>o?.abort()),{name:r?.name});l.disposalSignal.addEventListener(`abort`,()=>{s=!0},{once:!0});let u={get disposalSignal(){return l.disposalSignal},dispose:()=>l.dispose(),get disposed(){return s},get name(){return i.name},peek:()=>i.peek(),reload:()=>{s||(a.value=a.peek()+1)},subscribe:e=>i.subscribe(e),[Symbol.dispose](){this.dispose()},get value(){return i.value}};return Object.defineProperty(u,f,{value:!0}),u},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),r?.once&&(c=!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 b(e),n=x(t);return{batch:t.batch,computed:t.computed,createScope:t.createScope,dispose:()=>t.dispose(),get disposed(){return t.disposed},effect:t.effect,resource:n,signal:t.signal,untrack:t.untrack,watch:S(t)}})(),w=C.signal;C.computed,C.effect,C.batch,C.createScope,C.untrack,C.watch,C.resource;function T(e){return e instanceof Error?e.message:String(e)}function E(e){let{apply:t,label:n,meta:r,revert:i}=e;return{apply:t,entry:Object.freeze({label:n,meta:r}),revert:i}}function D(e){return Object.freeze({...e,redo:Object.freeze([...e.redo]),undo:Object.freeze([...e.undo])})}function O(e,t){return t?new i(`Cannot call ${e}() on a disposed ledger.`):new r(`${e}() was cancelled before it started.`)}function k(e={}){let{maxHistory:t=100}=e;if(!Number.isSafeInteger(t)||t<0)throw RangeError(`maxHistory must be a non-negative safe integer`);let i=w(D({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=D(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(O(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,O(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,O(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(T(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(T(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(T(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,O(`operation`,!0));p(e=>({...e,accepting:!1,queued:0,redo:[],undo:[]}))},get disposed(){return d},do(e,t){let n=E(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=k;
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 extends Error{constructor(e,t){super(e,t),this.name=new.target.name,Object.setPrototypeOf(this,new.target.prototype)}},r=class extends n{},i=class extends n{},a=class extends n{},o=class extends n{},s=class extends Error{constructor(e,t){super(e,t),this.name=new.target.name,Object.setPrototypeOf(this,new.target.prototype)}},c=class extends s{},l=class extends s{},u=class extends s{},d=class extends s{},f=Symbol.for(`@vielzeug/ripple/reactive`),p=100,m=Symbol(`ripple.unset`),h=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()}},g=class extends h{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}update(e){this.value=e(this.current)}},_=class extends h{dependencies=new Set;computing=!1;disposed=!1;dirty=!0;current=m;derive;equals;constructor(e,t,n){super(e,n?.name),this.derive=t,this.equals=n?.equals??Object.is}get value(){return this.runtime.track(this),this.refresh(),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===m||!this.equals(this.current,e);return this.current=e,this.dirty=!1,t}finally{this.computing=!1}}},v=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()}},y=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 v(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})}}},b=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 v(this,`runtime`),this.activeScope=this.rootScope}get disposed(){return this.isDisposed}signal=(e,t)=>(this.assertActive(),new g(this,e,t));computed=(e,t)=>{this.assertActive();let n=new _(this,e,t);return(this.activeEffectScope??this.activeScope).owned.add(n),n};effect=(e,t)=>{this.assertActive();let n=new y(this,e,t);return(this.activeEffectScope??this.activeScope).owned.add(n),n.run(),n};createScope=e=>{this.assertActive();let t=new v(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,e.dependencies.size===0)}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>p)throw new d(`infinite reactive flush (>${p} 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}}},x=e=>(t,n,r)=>{let i=e.signal({status:`pending`},{name:r?.name}),a=e.signal(0),o,s=!1,c=()=>{a.value,o?.abort();let e=i.peek(),r=e.status===`success`?e.value:`previous`in e?e.previous:void 0,c;try{c=t()}catch(e){i.value=r===void 0?{error:e,status:`error`}:{error:e,previous:r,status:`error`};return}let l=new AbortController;o=l,i.value=r===void 0?{status:`pending`}:{previous:r,status:`pending`};let u;try{u=Promise.resolve(n(c,{signal:l.signal}))}catch(e){u=Promise.reject(e)}u.then(e=>{!s&&!l.signal.aborted&&(i.value={status:`success`,value:e})},e=>{!s&&!l.signal.aborted&&(i.value=r===void 0?{error:e,status:`error`}:{error:e,previous:r,status:`error`})})},l=e.effect(()=>(c(),()=>o?.abort()),{name:r?.name});l.disposalSignal.addEventListener(`abort`,()=>{s=!0},{once:!0});let u={get disposalSignal(){return l.disposalSignal},dispose:()=>l.dispose(),get disposed(){return s},get name(){return i.name},peek:()=>i.peek(),reload:()=>{s||(a.value=a.peek()+1)},subscribe:e=>i.subscribe(e),[Symbol.dispose](){this.dispose()},get value(){return i.value}};return Object.defineProperty(u,f,{value:!0}),u},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),r?.once&&(c=!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 b(e),n=x(t);return{batch:t.batch,computed:t.computed,createScope:t.createScope,dispose:()=>t.dispose(),get disposed(){return t.disposed},effect:t.effect,resource:n,signal:t.signal,untrack:t.untrack,watch:S(t)}})(),w=C.signal;C.computed,C.effect,C.batch,C.createScope,C.untrack,C.watch,C.resource;function T(e){return e instanceof Error?e.message:String(e)}function E(e){let{apply:t,label:n,meta:r,revert:i}=e;return{apply:t,entry:Object.freeze({label:n,meta:r}),revert:i}}function D(e){return Object.freeze({...e,redo:Object.freeze([...e.redo]),undo:Object.freeze([...e.undo])})}function O(e,t){return t?new i(`Cannot call ${e}() on a disposed ledger.`):new r(`${e}() was cancelled before it started.`)}function k(e={}){let{maxHistory:t=100}=e;if(!Number.isSafeInteger(t)||t<0)throw RangeError(`maxHistory must be a non-negative safe integer`);let i=w(D({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=D(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(O(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,O(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,O(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(T(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(T(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(T(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,O(`operation`,!0));p(e=>({...e,accepting:!1,queued:0,redo:[],undo:[]}))},get disposed(){return d},do(e,t){let n=E(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=k;
2
2
  //# sourceMappingURL=ledger.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"ledger.cjs","names":["e","t","r","i","i","c","l","e","u","n","d","f","t","r","e","e","n","s"],"sources":["../src/compose.ts","../src/errors.ts","../../ripple/dist/errors.js","../../ripple/dist/runtime.js","../../ripple/dist/_async.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\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 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}, 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.for(\"@vielzeug/ripple/reactive\"), a = 100, o = Symbol(\"ripple.unset\"), s = 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}, c = class extends s {\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\tupdate(e) {\n\t\tthis.value = e(this.current);\n\t}\n}, l = class extends s {\n\tdependencies = /* @__PURE__ */ new Set();\n\tcomputing = !1;\n\tdisposed = !1;\n\tdirty = !0;\n\tcurrent = o;\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 === o || !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}, u = 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}, d = 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 u(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}, f = 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 u(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 c(this, e, t));\n\tcomputed = (e, t) => {\n\t\tthis.assertActive();\n\t\tlet n = new l(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 d(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 u(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 > a) throw new r(`infinite reactive flush (>${a} 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}, p = (e) => {\n\tif (typeof e != \"object\" || !e || !(i in e)) return !1;\n\tlet t = e;\n\treturn typeof t.peek == \"function\" && typeof t.subscribe == \"function\";\n};\n//#endregion\nexport { i as REACTIVE, f as ReactiveRuntime, p as isReactive };\n\n//# sourceMappingURL=runtime.js.map","import { REACTIVE as e } from \"./runtime.js\";\n//#region src/_async.ts\nvar t = (t) => (n, r, i) => {\n\tlet a = t.signal({ status: \"pending\" }, { name: i?.name }), o = t.signal(0), s, c = !1, l = () => {\n\t\to.value, s?.abort();\n\t\tlet e = a.peek(), t = e.status === \"success\" ? e.value : \"previous\" in e ? e.previous : void 0, i;\n\t\ttry {\n\t\t\ti = n();\n\t\t} catch (e) {\n\t\t\ta.value = t === 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: t,\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, a.value = t === void 0 ? { status: \"pending\" } : {\n\t\t\tprevious: t,\n\t\t\tstatus: \"pending\"\n\t\t};\n\t\tlet u;\n\t\ttry {\n\t\t\tu = Promise.resolve(r(i, { 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 && (a.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 && (a.value = t === 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: t,\n\t\t\t\tstatus: \"error\"\n\t\t\t});\n\t\t});\n\t}, u = t.effect(() => (l(), () => s?.abort()), { name: i?.name });\n\tu.disposalSignal.addEventListener(\"abort\", () => {\n\t\tc = !0;\n\t}, { once: !0 });\n\tlet d = {\n\t\tget disposalSignal() {\n\t\t\treturn u.disposalSignal;\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 a.name;\n\t\t},\n\t\tpeek: () => a.peek(),\n\t\treload: () => {\n\t\t\tc || (o.value = o.peek() + 1);\n\t\t},\n\t\tsubscribe: (e) => a.subscribe(e),\n\t\t[Symbol.dispose]() {\n\t\t\tthis.dispose();\n\t\t},\n\t\tget value() {\n\t\t\treturn a.value;\n\t\t}\n\t};\n\treturn Object.defineProperty(d, e, { value: !0 }), d;\n};\n//#endregion\nexport { t as createResource };\n\n//# sourceMappingURL=_async.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), r?.once && (c = !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 { ReactiveRuntime as e } from \"./runtime.js\";\nimport { createResource as t } from \"./_async.js\";\nimport { createWatch as n } from \"./_watch.js\";\n//#region src/_default.ts\nvar r = (r) => {\n\tlet i = new e(r), a = t(i);\n\treturn {\n\t\tbatch: i.batch,\n\t\tcomputed: i.computed,\n\t\tcreateScope: i.createScope,\n\t\tdispose: () => i.dispose(),\n\t\tget disposed() {\n\t\t\treturn i.disposed;\n\t\t},\n\t\teffect: i.effect,\n\t\tresource: a,\n\t\tsignal: i.signal,\n\t\tuntrack: i.untrack,\n\t\twatch: n(i)\n\t};\n}, i = r();\n//#endregion\nexport { r as createRipple, i 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, m = s.watch, h = s.resource;\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, h as resource, c as signal, p as untrack, m as watch };\n\n//# sourceMappingURL=index.js.map","import { signal } from '@vielzeug/ripple';\nimport {\n LedgerCancelledError,\n LedgerDisposedError,\n LedgerError,\n LedgerExecutionError,\n LedgerRollbackError,\n} from './errors';\nimport type {\n CommandContext,\n HistoryEntry,\n Ledger,\n LedgerCallOptions,\n LedgerOptions,\n LedgerState,\n ReversibleCommand,\n} from './types';\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 abortSignal = 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: () => abortSignal.removeEventListener('abort', onAbort),\n reject,\n resolve,\n settled: false,\n start: async () => {\n if (operation.settled) return;\n\n if (disposed || abortSignal.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: abortSignal });\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 abortSignal.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,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,KAA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AEA,UAA0B,CAGxB,OAFI,EAAM,MAAM,SAAW,GAAK,EAAM,MAAM,UAAY,EAAU,QAAQ,QAAQ,EAE3E,IAAI,QAAS,GAAY,EAAY,IAAI,CAAO,CAAC,CAC1D,CACF,CACF"}
1
+ {"version":3,"file":"ledger.cjs","names":["e","t","r","i","i","c","l","e","u","n","d","f","t","r","e","e","n","s"],"sources":["../src/compose.ts","../src/errors.ts","../../ripple/dist/errors.js","../../ripple/dist/runtime.js","../../ripple/dist/_async.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\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 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}, 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.for(\"@vielzeug/ripple/reactive\"), a = 100, o = Symbol(\"ripple.unset\"), s = 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}, c = class extends s {\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\tupdate(e) {\n\t\tthis.value = e(this.current);\n\t}\n}, l = class extends s {\n\tdependencies = /* @__PURE__ */ new Set();\n\tcomputing = !1;\n\tdisposed = !1;\n\tdirty = !0;\n\tcurrent = o;\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.runtime.track(this), this.refresh(), 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 === o || !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}, u = 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}, d = 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 u(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}, f = 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 u(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 c(this, e, t));\n\tcomputed = (e, t) => {\n\t\tthis.assertActive();\n\t\tlet n = new l(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 d(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 u(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, e.dependencies.size === 0);\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 > a) throw new r(`infinite reactive flush (>${a} 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}, p = (e) => {\n\tif (typeof e != \"object\" || !e || !(i in e)) return !1;\n\tlet t = e;\n\treturn typeof t.peek == \"function\" && typeof t.subscribe == \"function\";\n};\n//#endregion\nexport { i as REACTIVE, f as ReactiveRuntime, p as isReactive };\n\n//# sourceMappingURL=runtime.js.map","import { REACTIVE as e } from \"./runtime.js\";\n//#region src/_async.ts\nvar t = (t) => (n, r, i) => {\n\tlet a = t.signal({ status: \"pending\" }, { name: i?.name }), o = t.signal(0), s, c = !1, l = () => {\n\t\to.value, s?.abort();\n\t\tlet e = a.peek(), t = e.status === \"success\" ? e.value : \"previous\" in e ? e.previous : void 0, i;\n\t\ttry {\n\t\t\ti = n();\n\t\t} catch (e) {\n\t\t\ta.value = t === 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: t,\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, a.value = t === void 0 ? { status: \"pending\" } : {\n\t\t\tprevious: t,\n\t\t\tstatus: \"pending\"\n\t\t};\n\t\tlet u;\n\t\ttry {\n\t\t\tu = Promise.resolve(r(i, { 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 && (a.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 && (a.value = t === 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: t,\n\t\t\t\tstatus: \"error\"\n\t\t\t});\n\t\t});\n\t}, u = t.effect(() => (l(), () => s?.abort()), { name: i?.name });\n\tu.disposalSignal.addEventListener(\"abort\", () => {\n\t\tc = !0;\n\t}, { once: !0 });\n\tlet d = {\n\t\tget disposalSignal() {\n\t\t\treturn u.disposalSignal;\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 a.name;\n\t\t},\n\t\tpeek: () => a.peek(),\n\t\treload: () => {\n\t\t\tc || (o.value = o.peek() + 1);\n\t\t},\n\t\tsubscribe: (e) => a.subscribe(e),\n\t\t[Symbol.dispose]() {\n\t\t\tthis.dispose();\n\t\t},\n\t\tget value() {\n\t\t\treturn a.value;\n\t\t}\n\t};\n\treturn Object.defineProperty(d, e, { value: !0 }), d;\n};\n//#endregion\nexport { t as createResource };\n\n//# sourceMappingURL=_async.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), r?.once && (c = !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 { ReactiveRuntime as e } from \"./runtime.js\";\nimport { createResource as t } from \"./_async.js\";\nimport { createWatch as n } from \"./_watch.js\";\n//#region src/_default.ts\nvar r = (r) => {\n\tlet i = new e(r), a = t(i);\n\treturn {\n\t\tbatch: i.batch,\n\t\tcomputed: i.computed,\n\t\tcreateScope: i.createScope,\n\t\tdispose: () => i.dispose(),\n\t\tget disposed() {\n\t\t\treturn i.disposed;\n\t\t},\n\t\teffect: i.effect,\n\t\tresource: a,\n\t\tsignal: i.signal,\n\t\tuntrack: i.untrack,\n\t\twatch: n(i)\n\t};\n}, i = r();\n//#endregion\nexport { r as createRipple, i 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, m = s.watch, h = s.resource;\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, h as resource, c as signal, p as untrack, m as watch };\n\n//# sourceMappingURL=index.js.map","import { signal } from '@vielzeug/ripple';\nimport {\n LedgerCancelledError,\n LedgerDisposedError,\n LedgerError,\n LedgerExecutionError,\n LedgerRollbackError,\n} from './errors';\nimport type {\n CommandContext,\n HistoryEntry,\n Ledger,\n LedgerCallOptions,\n LedgerOptions,\n LedgerState,\n ReversibleCommand,\n} from './types';\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 abortSignal = 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: () => abortSignal.removeEventListener('abort', onAbort),\n reject,\n resolve,\n settled: false,\n start: async () => {\n if (operation.settled) return;\n\n if (disposed || abortSignal.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: abortSignal });\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 abortSignal.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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,EAAU,OAAO,EAEvE,IAAK,IAAM,KAAa,EAAQ,EAAO,EAAW,EAAe,YAAa,EAAI,CAAC,EAEnF,EAAa,IAAa,CAAE,GAAG,EAAS,UAAW,GAAO,OAAQ,EAAG,KAAM,CAAC,EAAG,KAAM,CAAC,CAAE,EAAE,CAC5F,EAEA,IAAI,UAAoB,CACtB,OAAO,CACT,EAEA,GAAG,EAAmC,EAAgD,CACpF,IAAM,EAAW,EAAgB,CAAO,EAExC,OAAO,EAAQ,KAAM,GAAa,OAAS,GAAY,EAAM,EAAU,CAAO,CAAC,CACjF,EAEA,KAAK,EAAgD,CACnD,OAAO,EAAQ,OAAQ,GAAa,OAAQ,CAAO,CACrD,EAEA,IAAI,OAAQ,CACV,OAAO,CACT,EAEA,CAAC,OAAO,UAAiB,CACvB,KAAK,QAAQ,CACf,EAEA,KAAK,EAAgD,CACnD,OAAO,EAAQ,OAAQ,GAAa,OAAQ,CAAO,CACrD,EAEA,UAA0B,CAGxB,OAFI,EAAM,MAAM,SAAW,GAAK,EAAM,MAAM,UAAY,EAAU,QAAQ,QAAQ,EAE3E,IAAI,QAAS,GAAY,EAAY,IAAI,CAAO,CAAC,CAC1D,CACF,CACF"}
@@ -1,2 +1,2 @@
1
- var Ledger=(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});function t(e){let{apply:t,label:n,meta:r,revert:i}=e;return{apply:t,label:n,meta:r,revert:i}}function n(e,n){let r=e.map(t);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 r=class extends Error{constructor(e,t){super(e,t),this.name=new.target.name,Object.setPrototypeOf(this,new.target.prototype)}},i=class extends r{},a=class extends r{},o=class extends r{},s=class extends r{},c=class extends Error{constructor(e,t){super(e,t),this.name=new.target.name,Object.setPrototypeOf(this,new.target.prototype)}},l=class extends c{},u=class extends c{},d=class extends c{},f=class extends c{},p=Symbol.for(`@vielzeug/ripple/reactive`),m=100,h=Symbol(`ripple.unset`),g=class{[p]=!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()}},_=class extends g{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}update(e){this.value=e(this.current)}},v=class extends g{dependencies=new Set;computing=!1;disposed=!1;dirty=!0;current=h;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 l(`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===h||!this.equals(this.current,e);return this.current=e,this.dirty=!1,t}finally{this.computing=!1}}},y=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 d(`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()}},b=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 y(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})}}},x=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 y(this,`runtime`),this.activeScope=this.rootScope}get disposed(){return this.isDisposed}signal=(e,t)=>(this.assertActive(),new _(this,e,t));computed=(e,t)=>{this.assertActive();let n=new v(this,e,t);return(this.activeEffectScope??this.activeScope).owned.add(n),n};effect=(e,t)=>{this.assertActive();let n=new b(this,e,t);return(this.activeEffectScope??this.activeScope).owned.add(n),n.run(),n};createScope=e=>{this.assertActive();let t=new y(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 u(`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>m)throw new f(`infinite reactive flush (>${m} 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}}},S=e=>(t,n,r)=>{let i=e.signal({status:`pending`},{name:r?.name}),a=e.signal(0),o,s=!1,c=()=>{a.value,o?.abort();let e=i.peek(),r=e.status===`success`?e.value:`previous`in e?e.previous:void 0,c;try{c=t()}catch(e){i.value=r===void 0?{error:e,status:`error`}:{error:e,previous:r,status:`error`};return}let l=new AbortController;o=l,i.value=r===void 0?{status:`pending`}:{previous:r,status:`pending`};let u;try{u=Promise.resolve(n(c,{signal:l.signal}))}catch(e){u=Promise.reject(e)}u.then(e=>{!s&&!l.signal.aborted&&(i.value={status:`success`,value:e})},e=>{!s&&!l.signal.aborted&&(i.value=r===void 0?{error:e,status:`error`}:{error:e,previous:r,status:`error`})})},l=e.effect(()=>(c(),()=>o?.abort()),{name:r?.name});l.disposalSignal.addEventListener(`abort`,()=>{s=!0},{once:!0});let u={get disposalSignal(){return l.disposalSignal},dispose:()=>l.dispose(),get disposed(){return s},get name(){return i.name},peek:()=>i.peek(),reload:()=>{s||(a.value=a.peek()+1)},subscribe:e=>i.subscribe(e),[Symbol.dispose](){this.dispose()},get value(){return i.value}};return Object.defineProperty(u,p,{value:!0}),u},C=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),r?.once&&(c=!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},w=(e=>{let t=new x(e),n=S(t);return{batch:t.batch,computed:t.computed,createScope:t.createScope,dispose:()=>t.dispose(),get disposed(){return t.disposed},effect:t.effect,resource:n,signal:t.signal,untrack:t.untrack,watch:C(t)}})(),T=w.signal;w.computed,w.effect,w.batch,w.createScope,w.untrack,w.watch,w.resource;function E(e){return e instanceof Error?e.message:String(e)}function D(e){let{apply:t,label:n,meta:r,revert:i}=e;return{apply:t,entry:Object.freeze({label:n,meta:r}),revert:i}}function O(e){return Object.freeze({...e,redo:Object.freeze([...e.redo]),undo:Object.freeze([...e.undo])})}function k(e,t){return t?new a(`Cannot call ${e}() on a disposed ledger.`):new i(`${e}() was cancelled before it started.`)}function A(e={}){let{maxHistory:t=100}=e;if(!Number.isSafeInteger(t)||t<0)throw RangeError(`maxHistory must be a non-negative safe integer`);let n=T(O({accepting:!0,queued:0,redo:[],running:0,undo:[]}),{name:`ledger:state`}),a=new WeakMap,c=new AbortController,l=new Set,u=new Set,d=!1,f=Promise.resolve();function p(e){if(n.value=O(e(n.value)),n.value.queued===0&&n.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(k(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,k(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,k(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 i(`do() was cancelled while running.`,{cause:e}):new o(E(e),{cause:e})}if(d||n.signal.aborted)throw new i(`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}}),a.set(e.entry,e)}async function _(e){let t=n.value.undo[n.value.undo.length-1];if(!t)return;let o=a.get(t);if(!o)throw new r(`Undo history is corrupted.`);try{await o.revert(e)}catch(t){throw e.signal.aborted?new i(`undo() was cancelled while running.`,{cause:t}):new s(E(t),{cause:t})}if(d||e.signal.aborted)throw new i(`undo() was cancelled while running.`);p(e=>({...e,redo:[...e.redo,t],undo:e.undo.slice(0,-1)}))}async function v(e){let t=n.value.redo[n.value.redo.length-1];if(!t)return;let s=a.get(t);if(!s)throw new r(`Redo history is corrupted.`);try{await s.apply(e)}catch(t){throw e.signal.aborted?new i(`redo() was cancelled while running.`,{cause:t}):new o(E(t),{cause:t})}if(d||e.signal.aborted)throw new i(`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,k(`operation`,!0));p(e=>({...e,accepting:!1,queued:0,redo:[],undo:[]}))},get disposed(){return d},do(e,t){let n=D(e);return h(`do`,t?.signal,e=>g(n,e))},redo(e){return h(`redo`,e?.signal,v)},get state(){return n},[Symbol.dispose](){this.dispose()},undo(e){return h(`undo`,e?.signal,_)},whenIdle(){return n.value.queued===0&&n.value.running===0?Promise.resolve():new Promise(e=>l.add(e))}}}return e.LedgerCancelledError=i,e.LedgerDisposedError=a,e.LedgerError=r,e.LedgerExecutionError=o,e.LedgerRollbackError=s,e.compose=n,e.createLedger=A,e})({});
1
+ var Ledger=(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});function t(e){let{apply:t,label:n,meta:r,revert:i}=e;return{apply:t,label:n,meta:r,revert:i}}function n(e,n){let r=e.map(t);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 r=class extends Error{constructor(e,t){super(e,t),this.name=new.target.name,Object.setPrototypeOf(this,new.target.prototype)}},i=class extends r{},a=class extends r{},o=class extends r{},s=class extends r{},c=class extends Error{constructor(e,t){super(e,t),this.name=new.target.name,Object.setPrototypeOf(this,new.target.prototype)}},l=class extends c{},u=class extends c{},d=class extends c{},f=class extends c{},p=Symbol.for(`@vielzeug/ripple/reactive`),m=100,h=Symbol(`ripple.unset`),g=class{[p]=!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()}},_=class extends g{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}update(e){this.value=e(this.current)}},v=class extends g{dependencies=new Set;computing=!1;disposed=!1;dirty=!0;current=h;derive;equals;constructor(e,t,n){super(e,n?.name),this.derive=t,this.equals=n?.equals??Object.is}get value(){return this.runtime.track(this),this.refresh(),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 l(`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===h||!this.equals(this.current,e);return this.current=e,this.dirty=!1,t}finally{this.computing=!1}}},y=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 d(`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()}},b=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 y(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})}}},x=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 y(this,`runtime`),this.activeScope=this.rootScope}get disposed(){return this.isDisposed}signal=(e,t)=>(this.assertActive(),new _(this,e,t));computed=(e,t)=>{this.assertActive();let n=new v(this,e,t);return(this.activeEffectScope??this.activeScope).owned.add(n),n};effect=(e,t)=>{this.assertActive();let n=new b(this,e,t);return(this.activeEffectScope??this.activeScope).owned.add(n),n.run(),n};createScope=e=>{this.assertActive();let t=new y(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 u(`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,e.dependencies.size===0)}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>m)throw new f(`infinite reactive flush (>${m} 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}}},S=e=>(t,n,r)=>{let i=e.signal({status:`pending`},{name:r?.name}),a=e.signal(0),o,s=!1,c=()=>{a.value,o?.abort();let e=i.peek(),r=e.status===`success`?e.value:`previous`in e?e.previous:void 0,c;try{c=t()}catch(e){i.value=r===void 0?{error:e,status:`error`}:{error:e,previous:r,status:`error`};return}let l=new AbortController;o=l,i.value=r===void 0?{status:`pending`}:{previous:r,status:`pending`};let u;try{u=Promise.resolve(n(c,{signal:l.signal}))}catch(e){u=Promise.reject(e)}u.then(e=>{!s&&!l.signal.aborted&&(i.value={status:`success`,value:e})},e=>{!s&&!l.signal.aborted&&(i.value=r===void 0?{error:e,status:`error`}:{error:e,previous:r,status:`error`})})},l=e.effect(()=>(c(),()=>o?.abort()),{name:r?.name});l.disposalSignal.addEventListener(`abort`,()=>{s=!0},{once:!0});let u={get disposalSignal(){return l.disposalSignal},dispose:()=>l.dispose(),get disposed(){return s},get name(){return i.name},peek:()=>i.peek(),reload:()=>{s||(a.value=a.peek()+1)},subscribe:e=>i.subscribe(e),[Symbol.dispose](){this.dispose()},get value(){return i.value}};return Object.defineProperty(u,p,{value:!0}),u},C=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),r?.once&&(c=!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},w=(e=>{let t=new x(e),n=S(t);return{batch:t.batch,computed:t.computed,createScope:t.createScope,dispose:()=>t.dispose(),get disposed(){return t.disposed},effect:t.effect,resource:n,signal:t.signal,untrack:t.untrack,watch:C(t)}})(),T=w.signal;w.computed,w.effect,w.batch,w.createScope,w.untrack,w.watch,w.resource;function E(e){return e instanceof Error?e.message:String(e)}function D(e){let{apply:t,label:n,meta:r,revert:i}=e;return{apply:t,entry:Object.freeze({label:n,meta:r}),revert:i}}function O(e){return Object.freeze({...e,redo:Object.freeze([...e.redo]),undo:Object.freeze([...e.undo])})}function k(e,t){return t?new a(`Cannot call ${e}() on a disposed ledger.`):new i(`${e}() was cancelled before it started.`)}function A(e={}){let{maxHistory:t=100}=e;if(!Number.isSafeInteger(t)||t<0)throw RangeError(`maxHistory must be a non-negative safe integer`);let n=T(O({accepting:!0,queued:0,redo:[],running:0,undo:[]}),{name:`ledger:state`}),a=new WeakMap,c=new AbortController,l=new Set,u=new Set,d=!1,f=Promise.resolve();function p(e){if(n.value=O(e(n.value)),n.value.queued===0&&n.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(k(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,k(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,k(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 i(`do() was cancelled while running.`,{cause:e}):new o(E(e),{cause:e})}if(d||n.signal.aborted)throw new i(`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}}),a.set(e.entry,e)}async function _(e){let t=n.value.undo[n.value.undo.length-1];if(!t)return;let o=a.get(t);if(!o)throw new r(`Undo history is corrupted.`);try{await o.revert(e)}catch(t){throw e.signal.aborted?new i(`undo() was cancelled while running.`,{cause:t}):new s(E(t),{cause:t})}if(d||e.signal.aborted)throw new i(`undo() was cancelled while running.`);p(e=>({...e,redo:[...e.redo,t],undo:e.undo.slice(0,-1)}))}async function v(e){let t=n.value.redo[n.value.redo.length-1];if(!t)return;let s=a.get(t);if(!s)throw new r(`Redo history is corrupted.`);try{await s.apply(e)}catch(t){throw e.signal.aborted?new i(`redo() was cancelled while running.`,{cause:t}):new o(E(t),{cause:t})}if(d||e.signal.aborted)throw new i(`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,k(`operation`,!0));p(e=>({...e,accepting:!1,queued:0,redo:[],undo:[]}))},get disposed(){return d},do(e,t){let n=D(e);return h(`do`,t?.signal,e=>g(n,e))},redo(e){return h(`redo`,e?.signal,v)},get state(){return n},[Symbol.dispose](){this.dispose()},undo(e){return h(`undo`,e?.signal,_)},whenIdle(){return n.value.queued===0&&n.value.running===0?Promise.resolve():new Promise(e=>l.add(e))}}}return e.LedgerCancelledError=i,e.LedgerDisposedError=a,e.LedgerError=r,e.LedgerExecutionError=o,e.LedgerRollbackError=s,e.compose=n,e.createLedger=A,e})({});
2
2
  //# sourceMappingURL=ledger.iife.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"ledger.iife.js","names":["e","t","r","i","i","c","l","e","u","n","d","f","t","r","e","e","n","s"],"sources":["../src/compose.ts","../src/errors.ts","../../ripple/dist/errors.js","../../ripple/dist/runtime.js","../../ripple/dist/_async.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\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 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}, 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.for(\"@vielzeug/ripple/reactive\"), a = 100, o = Symbol(\"ripple.unset\"), s = 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}, c = class extends s {\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\tupdate(e) {\n\t\tthis.value = e(this.current);\n\t}\n}, l = class extends s {\n\tdependencies = /* @__PURE__ */ new Set();\n\tcomputing = !1;\n\tdisposed = !1;\n\tdirty = !0;\n\tcurrent = o;\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 === o || !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}, u = 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}, d = 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 u(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}, f = 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 u(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 c(this, e, t));\n\tcomputed = (e, t) => {\n\t\tthis.assertActive();\n\t\tlet n = new l(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 d(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 u(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 > a) throw new r(`infinite reactive flush (>${a} 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}, p = (e) => {\n\tif (typeof e != \"object\" || !e || !(i in e)) return !1;\n\tlet t = e;\n\treturn typeof t.peek == \"function\" && typeof t.subscribe == \"function\";\n};\n//#endregion\nexport { i as REACTIVE, f as ReactiveRuntime, p as isReactive };\n\n//# sourceMappingURL=runtime.js.map","import { REACTIVE as e } from \"./runtime.js\";\n//#region src/_async.ts\nvar t = (t) => (n, r, i) => {\n\tlet a = t.signal({ status: \"pending\" }, { name: i?.name }), o = t.signal(0), s, c = !1, l = () => {\n\t\to.value, s?.abort();\n\t\tlet e = a.peek(), t = e.status === \"success\" ? e.value : \"previous\" in e ? e.previous : void 0, i;\n\t\ttry {\n\t\t\ti = n();\n\t\t} catch (e) {\n\t\t\ta.value = t === 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: t,\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, a.value = t === void 0 ? { status: \"pending\" } : {\n\t\t\tprevious: t,\n\t\t\tstatus: \"pending\"\n\t\t};\n\t\tlet u;\n\t\ttry {\n\t\t\tu = Promise.resolve(r(i, { 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 && (a.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 && (a.value = t === 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: t,\n\t\t\t\tstatus: \"error\"\n\t\t\t});\n\t\t});\n\t}, u = t.effect(() => (l(), () => s?.abort()), { name: i?.name });\n\tu.disposalSignal.addEventListener(\"abort\", () => {\n\t\tc = !0;\n\t}, { once: !0 });\n\tlet d = {\n\t\tget disposalSignal() {\n\t\t\treturn u.disposalSignal;\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 a.name;\n\t\t},\n\t\tpeek: () => a.peek(),\n\t\treload: () => {\n\t\t\tc || (o.value = o.peek() + 1);\n\t\t},\n\t\tsubscribe: (e) => a.subscribe(e),\n\t\t[Symbol.dispose]() {\n\t\t\tthis.dispose();\n\t\t},\n\t\tget value() {\n\t\t\treturn a.value;\n\t\t}\n\t};\n\treturn Object.defineProperty(d, e, { value: !0 }), d;\n};\n//#endregion\nexport { t as createResource };\n\n//# sourceMappingURL=_async.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), r?.once && (c = !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 { ReactiveRuntime as e } from \"./runtime.js\";\nimport { createResource as t } from \"./_async.js\";\nimport { createWatch as n } from \"./_watch.js\";\n//#region src/_default.ts\nvar r = (r) => {\n\tlet i = new e(r), a = t(i);\n\treturn {\n\t\tbatch: i.batch,\n\t\tcomputed: i.computed,\n\t\tcreateScope: i.createScope,\n\t\tdispose: () => i.dispose(),\n\t\tget disposed() {\n\t\t\treturn i.disposed;\n\t\t},\n\t\teffect: i.effect,\n\t\tresource: a,\n\t\tsignal: i.signal,\n\t\tuntrack: i.untrack,\n\t\twatch: n(i)\n\t};\n}, i = r();\n//#endregion\nexport { r as createRipple, i 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, m = s.watch, h = s.resource;\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, h as resource, c as signal, p as untrack, m as watch };\n\n//# sourceMappingURL=index.js.map","import { signal } from '@vielzeug/ripple';\nimport {\n LedgerCancelledError,\n LedgerDisposedError,\n LedgerError,\n LedgerExecutionError,\n LedgerRollbackError,\n} from './errors';\nimport type {\n CommandContext,\n HistoryEntry,\n Ledger,\n LedgerCallOptions,\n LedgerOptions,\n LedgerState,\n ReversibleCommand,\n} from './types';\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 abortSignal = 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: () => abortSignal.removeEventListener('abort', onAbort),\n reject,\n resolve,\n settled: false,\n start: async () => {\n if (operation.settled) return;\n\n if (disposed || abortSignal.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: abortSignal });\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 abortSignal.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":"qFAEA,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,CCrEA,IAAa,EAAb,cAAiC,KAAM,CACrC,YAAY,EAAiB,EAAqB,CAChD,MAAM,EAAS,CAAI,EACnB,KAAK,KAAO,WAAW,KACvB,OAAO,eAAe,KAAM,WAAW,SAAS,CAClD,CACF,EAGa,EAAb,cAA0C,CAAY,CAAC,EAG1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,GAAG,CAAU,CAAC,CAAC,OAAQ,GAAc,CAAC,EAAU,OAAO,EAEvE,IAAK,IAAM,KAAa,EAAQ,EAAO,EAAW,EAAe,YAAa,EAAI,CAAC,EAEnF,EAAa,IAAa,CAAE,GAAG,EAAS,UAAW,GAAO,OAAQ,EAAG,KAAM,CAAC,EAAG,KAAM,CAAC,CAAE,EAAE,CAC5F,EAEA,IAAI,UAAoB,CACtB,OAAO,CACT,EAEA,GAAG,EAAmC,EAAgD,CACpF,IAAM,EAAW,EAAgB,CAAO,EAExC,OAAO,EAAQ,KAAM,GAAa,OAAS,GAAY,EAAM,EAAU,CAAO,CAAC,CACjF,EAEA,KAAK,EAAgD,CACnD,OAAO,EAAQ,OAAQ,GAAa,OAAQ,CAAO,CACrD,EAEA,IAAI,OAAQ,CACV,OAAO,CACT,EAEA,CAAC,OAAO,UAAiB,CACvB,KAAK,QAAQ,CACf,EAEA,KAAK,EAAgD,CACnD,OAAO,EAAQ,OAAQ,GAAa,OAAQ,CAAO,CACrD,EAEA,UAA0B,CAGxB,OAFI,EAAM,MAAM,SAAW,GAAK,EAAM,MAAM,UAAY,EAAU,QAAQ,QAAQ,EAE3E,IAAI,QAAS,GAAY,EAAY,IAAI,CAAO,CAAC,CAC1D,CACF,CACF"}
1
+ {"version":3,"file":"ledger.iife.js","names":["e","t","r","i","i","c","l","e","u","n","d","f","t","r","e","e","n","s"],"sources":["../src/compose.ts","../src/errors.ts","../../ripple/dist/errors.js","../../ripple/dist/runtime.js","../../ripple/dist/_async.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\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 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}, 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.for(\"@vielzeug/ripple/reactive\"), a = 100, o = Symbol(\"ripple.unset\"), s = 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}, c = class extends s {\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\tupdate(e) {\n\t\tthis.value = e(this.current);\n\t}\n}, l = class extends s {\n\tdependencies = /* @__PURE__ */ new Set();\n\tcomputing = !1;\n\tdisposed = !1;\n\tdirty = !0;\n\tcurrent = o;\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.runtime.track(this), this.refresh(), 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 === o || !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}, u = 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}, d = 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 u(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}, f = 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 u(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 c(this, e, t));\n\tcomputed = (e, t) => {\n\t\tthis.assertActive();\n\t\tlet n = new l(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 d(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 u(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, e.dependencies.size === 0);\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 > a) throw new r(`infinite reactive flush (>${a} 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}, p = (e) => {\n\tif (typeof e != \"object\" || !e || !(i in e)) return !1;\n\tlet t = e;\n\treturn typeof t.peek == \"function\" && typeof t.subscribe == \"function\";\n};\n//#endregion\nexport { i as REACTIVE, f as ReactiveRuntime, p as isReactive };\n\n//# sourceMappingURL=runtime.js.map","import { REACTIVE as e } from \"./runtime.js\";\n//#region src/_async.ts\nvar t = (t) => (n, r, i) => {\n\tlet a = t.signal({ status: \"pending\" }, { name: i?.name }), o = t.signal(0), s, c = !1, l = () => {\n\t\to.value, s?.abort();\n\t\tlet e = a.peek(), t = e.status === \"success\" ? e.value : \"previous\" in e ? e.previous : void 0, i;\n\t\ttry {\n\t\t\ti = n();\n\t\t} catch (e) {\n\t\t\ta.value = t === 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: t,\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, a.value = t === void 0 ? { status: \"pending\" } : {\n\t\t\tprevious: t,\n\t\t\tstatus: \"pending\"\n\t\t};\n\t\tlet u;\n\t\ttry {\n\t\t\tu = Promise.resolve(r(i, { 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 && (a.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 && (a.value = t === 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: t,\n\t\t\t\tstatus: \"error\"\n\t\t\t});\n\t\t});\n\t}, u = t.effect(() => (l(), () => s?.abort()), { name: i?.name });\n\tu.disposalSignal.addEventListener(\"abort\", () => {\n\t\tc = !0;\n\t}, { once: !0 });\n\tlet d = {\n\t\tget disposalSignal() {\n\t\t\treturn u.disposalSignal;\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 a.name;\n\t\t},\n\t\tpeek: () => a.peek(),\n\t\treload: () => {\n\t\t\tc || (o.value = o.peek() + 1);\n\t\t},\n\t\tsubscribe: (e) => a.subscribe(e),\n\t\t[Symbol.dispose]() {\n\t\t\tthis.dispose();\n\t\t},\n\t\tget value() {\n\t\t\treturn a.value;\n\t\t}\n\t};\n\treturn Object.defineProperty(d, e, { value: !0 }), d;\n};\n//#endregion\nexport { t as createResource };\n\n//# sourceMappingURL=_async.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), r?.once && (c = !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 { ReactiveRuntime as e } from \"./runtime.js\";\nimport { createResource as t } from \"./_async.js\";\nimport { createWatch as n } from \"./_watch.js\";\n//#region src/_default.ts\nvar r = (r) => {\n\tlet i = new e(r), a = t(i);\n\treturn {\n\t\tbatch: i.batch,\n\t\tcomputed: i.computed,\n\t\tcreateScope: i.createScope,\n\t\tdispose: () => i.dispose(),\n\t\tget disposed() {\n\t\t\treturn i.disposed;\n\t\t},\n\t\teffect: i.effect,\n\t\tresource: a,\n\t\tsignal: i.signal,\n\t\tuntrack: i.untrack,\n\t\twatch: n(i)\n\t};\n}, i = r();\n//#endregion\nexport { r as createRipple, i 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, m = s.watch, h = s.resource;\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, h as resource, c as signal, p as untrack, m as watch };\n\n//# sourceMappingURL=index.js.map","import { signal } from '@vielzeug/ripple';\nimport {\n LedgerCancelledError,\n LedgerDisposedError,\n LedgerError,\n LedgerExecutionError,\n LedgerRollbackError,\n} from './errors';\nimport type {\n CommandContext,\n HistoryEntry,\n Ledger,\n LedgerCallOptions,\n LedgerOptions,\n LedgerState,\n ReversibleCommand,\n} from './types';\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 abortSignal = 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: () => abortSignal.removeEventListener('abort', onAbort),\n reject,\n resolve,\n settled: false,\n start: async () => {\n if (operation.settled) return;\n\n if (disposed || abortSignal.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: abortSignal });\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 abortSignal.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":"qFAEA,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,M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,CAGxB,OAFI,EAAM,MAAM,SAAW,GAAK,EAAM,MAAM,UAAY,EAAU,QAAQ,QAAQ,EAE3E,IAAI,QAAS,GAAY,EAAY,IAAI,CAAO,CAAC,CAC1D,CACF,CACF"}
package/dist/ledger.js CHANGED
@@ -1,2 +1,2 @@
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`)}}}var n=class extends Error{constructor(e,t){super(e,t),this.name=new.target.name,Object.setPrototypeOf(this,new.target.prototype)}},r=class extends n{},i=class extends n{},a=class extends n{},o=class extends n{},s=class extends Error{constructor(e,t){super(e,t),this.name=new.target.name,Object.setPrototypeOf(this,new.target.prototype)}},c=class extends s{},l=class extends s{},u=class extends s{},d=class extends s{},f=Symbol.for(`@vielzeug/ripple/reactive`),p=100,m=Symbol(`ripple.unset`),h=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()}},g=class extends h{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}update(e){this.value=e(this.current)}},_=class extends h{dependencies=new Set;computing=!1;disposed=!1;dirty=!0;current=m;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===m||!this.equals(this.current,e);return this.current=e,this.dirty=!1,t}finally{this.computing=!1}}},v=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()}},y=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 v(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})}}},b=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 v(this,`runtime`),this.activeScope=this.rootScope}get disposed(){return this.isDisposed}signal=(e,t)=>(this.assertActive(),new g(this,e,t));computed=(e,t)=>{this.assertActive();let n=new _(this,e,t);return(this.activeEffectScope??this.activeScope).owned.add(n),n};effect=(e,t)=>{this.assertActive();let n=new y(this,e,t);return(this.activeEffectScope??this.activeScope).owned.add(n),n.run(),n};createScope=e=>{this.assertActive();let t=new v(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>p)throw new d(`infinite reactive flush (>${p} 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}}},x=e=>(t,n,r)=>{let i=e.signal({status:`pending`},{name:r?.name}),a=e.signal(0),o,s=!1,c=()=>{a.value,o?.abort();let e=i.peek(),r=e.status===`success`?e.value:`previous`in e?e.previous:void 0,c;try{c=t()}catch(e){i.value=r===void 0?{error:e,status:`error`}:{error:e,previous:r,status:`error`};return}let l=new AbortController;o=l,i.value=r===void 0?{status:`pending`}:{previous:r,status:`pending`};let u;try{u=Promise.resolve(n(c,{signal:l.signal}))}catch(e){u=Promise.reject(e)}u.then(e=>{!s&&!l.signal.aborted&&(i.value={status:`success`,value:e})},e=>{!s&&!l.signal.aborted&&(i.value=r===void 0?{error:e,status:`error`}:{error:e,previous:r,status:`error`})})},l=e.effect(()=>(c(),()=>o?.abort()),{name:r?.name});l.disposalSignal.addEventListener(`abort`,()=>{s=!0},{once:!0});let u={get disposalSignal(){return l.disposalSignal},dispose:()=>l.dispose(),get disposed(){return s},get name(){return i.name},peek:()=>i.peek(),reload:()=>{s||(a.value=a.peek()+1)},subscribe:e=>i.subscribe(e),[Symbol.dispose](){this.dispose()},get value(){return i.value}};return Object.defineProperty(u,f,{value:!0}),u},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),r?.once&&(c=!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 b(e),n=x(t);return{batch:t.batch,computed:t.computed,createScope:t.createScope,dispose:()=>t.dispose(),get disposed(){return t.disposed},effect:t.effect,resource:n,signal:t.signal,untrack:t.untrack,watch:S(t)}})(),w=C.signal;C.computed,C.effect,C.batch,C.createScope,C.untrack,C.watch,C.resource;function T(e){return e instanceof Error?e.message:String(e)}function E(e){let{apply:t,label:n,meta:r,revert:i}=e;return{apply:t,entry:Object.freeze({label:n,meta:r}),revert:i}}function D(e){return Object.freeze({...e,redo:Object.freeze([...e.redo]),undo:Object.freeze([...e.undo])})}function O(e,t){return t?new i(`Cannot call ${e}() on a disposed ledger.`):new r(`${e}() was cancelled before it started.`)}function k(e={}){let{maxHistory:t=100}=e;if(!Number.isSafeInteger(t)||t<0)throw RangeError(`maxHistory must be a non-negative safe integer`);let i=w(D({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=D(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(O(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,O(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,O(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(T(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(T(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(T(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,O(`operation`,!0));p(e=>({...e,accepting:!1,queued:0,redo:[],undo:[]}))},get disposed(){return d},do(e,t){let n=E(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))}}}export{r as LedgerCancelledError,i as LedgerDisposedError,n as LedgerError,a as LedgerExecutionError,o as LedgerRollbackError,t as compose,k as createLedger};
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`)}}}var n=class extends Error{constructor(e,t){super(e,t),this.name=new.target.name,Object.setPrototypeOf(this,new.target.prototype)}},r=class extends n{},i=class extends n{},a=class extends n{},o=class extends n{},s=class extends Error{constructor(e,t){super(e,t),this.name=new.target.name,Object.setPrototypeOf(this,new.target.prototype)}},c=class extends s{},l=class extends s{},u=class extends s{},d=class extends s{},f=Symbol.for(`@vielzeug/ripple/reactive`),p=100,m=Symbol(`ripple.unset`),h=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()}},g=class extends h{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}update(e){this.value=e(this.current)}},_=class extends h{dependencies=new Set;computing=!1;disposed=!1;dirty=!0;current=m;derive;equals;constructor(e,t,n){super(e,n?.name),this.derive=t,this.equals=n?.equals??Object.is}get value(){return this.runtime.track(this),this.refresh(),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===m||!this.equals(this.current,e);return this.current=e,this.dirty=!1,t}finally{this.computing=!1}}},v=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()}},y=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 v(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})}}},b=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 v(this,`runtime`),this.activeScope=this.rootScope}get disposed(){return this.isDisposed}signal=(e,t)=>(this.assertActive(),new g(this,e,t));computed=(e,t)=>{this.assertActive();let n=new _(this,e,t);return(this.activeEffectScope??this.activeScope).owned.add(n),n};effect=(e,t)=>{this.assertActive();let n=new y(this,e,t);return(this.activeEffectScope??this.activeScope).owned.add(n),n.run(),n};createScope=e=>{this.assertActive();let t=new v(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,e.dependencies.size===0)}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>p)throw new d(`infinite reactive flush (>${p} 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}}},x=e=>(t,n,r)=>{let i=e.signal({status:`pending`},{name:r?.name}),a=e.signal(0),o,s=!1,c=()=>{a.value,o?.abort();let e=i.peek(),r=e.status===`success`?e.value:`previous`in e?e.previous:void 0,c;try{c=t()}catch(e){i.value=r===void 0?{error:e,status:`error`}:{error:e,previous:r,status:`error`};return}let l=new AbortController;o=l,i.value=r===void 0?{status:`pending`}:{previous:r,status:`pending`};let u;try{u=Promise.resolve(n(c,{signal:l.signal}))}catch(e){u=Promise.reject(e)}u.then(e=>{!s&&!l.signal.aborted&&(i.value={status:`success`,value:e})},e=>{!s&&!l.signal.aborted&&(i.value=r===void 0?{error:e,status:`error`}:{error:e,previous:r,status:`error`})})},l=e.effect(()=>(c(),()=>o?.abort()),{name:r?.name});l.disposalSignal.addEventListener(`abort`,()=>{s=!0},{once:!0});let u={get disposalSignal(){return l.disposalSignal},dispose:()=>l.dispose(),get disposed(){return s},get name(){return i.name},peek:()=>i.peek(),reload:()=>{s||(a.value=a.peek()+1)},subscribe:e=>i.subscribe(e),[Symbol.dispose](){this.dispose()},get value(){return i.value}};return Object.defineProperty(u,f,{value:!0}),u},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),r?.once&&(c=!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 b(e),n=x(t);return{batch:t.batch,computed:t.computed,createScope:t.createScope,dispose:()=>t.dispose(),get disposed(){return t.disposed},effect:t.effect,resource:n,signal:t.signal,untrack:t.untrack,watch:S(t)}})(),w=C.signal;C.computed,C.effect,C.batch,C.createScope,C.untrack,C.watch,C.resource;function T(e){return e instanceof Error?e.message:String(e)}function E(e){let{apply:t,label:n,meta:r,revert:i}=e;return{apply:t,entry:Object.freeze({label:n,meta:r}),revert:i}}function D(e){return Object.freeze({...e,redo:Object.freeze([...e.redo]),undo:Object.freeze([...e.undo])})}function O(e,t){return t?new i(`Cannot call ${e}() on a disposed ledger.`):new r(`${e}() was cancelled before it started.`)}function k(e={}){let{maxHistory:t=100}=e;if(!Number.isSafeInteger(t)||t<0)throw RangeError(`maxHistory must be a non-negative safe integer`);let i=w(D({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=D(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(O(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,O(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,O(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(T(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(T(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(T(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,O(`operation`,!0));p(e=>({...e,accepting:!1,queued:0,redo:[],undo:[]}))},get disposed(){return d},do(e,t){let n=E(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))}}}export{r as LedgerCancelledError,i as LedgerDisposedError,n as LedgerError,a as LedgerExecutionError,o as LedgerRollbackError,t as compose,k as createLedger};
2
2
  //# sourceMappingURL=ledger.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"ledger.js","names":["e","t","r","i","i","c","l","e","u","n","d","f","t","r","e","e","n","s"],"sources":["../src/compose.ts","../src/errors.ts","../../ripple/dist/errors.js","../../ripple/dist/runtime.js","../../ripple/dist/_async.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\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 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}, 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.for(\"@vielzeug/ripple/reactive\"), a = 100, o = Symbol(\"ripple.unset\"), s = 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}, c = class extends s {\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\tupdate(e) {\n\t\tthis.value = e(this.current);\n\t}\n}, l = class extends s {\n\tdependencies = /* @__PURE__ */ new Set();\n\tcomputing = !1;\n\tdisposed = !1;\n\tdirty = !0;\n\tcurrent = o;\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 === o || !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}, u = 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}, d = 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 u(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}, f = 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 u(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 c(this, e, t));\n\tcomputed = (e, t) => {\n\t\tthis.assertActive();\n\t\tlet n = new l(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 d(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 u(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 > a) throw new r(`infinite reactive flush (>${a} 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}, p = (e) => {\n\tif (typeof e != \"object\" || !e || !(i in e)) return !1;\n\tlet t = e;\n\treturn typeof t.peek == \"function\" && typeof t.subscribe == \"function\";\n};\n//#endregion\nexport { i as REACTIVE, f as ReactiveRuntime, p as isReactive };\n\n//# sourceMappingURL=runtime.js.map","import { REACTIVE as e } from \"./runtime.js\";\n//#region src/_async.ts\nvar t = (t) => (n, r, i) => {\n\tlet a = t.signal({ status: \"pending\" }, { name: i?.name }), o = t.signal(0), s, c = !1, l = () => {\n\t\to.value, s?.abort();\n\t\tlet e = a.peek(), t = e.status === \"success\" ? e.value : \"previous\" in e ? e.previous : void 0, i;\n\t\ttry {\n\t\t\ti = n();\n\t\t} catch (e) {\n\t\t\ta.value = t === 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: t,\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, a.value = t === void 0 ? { status: \"pending\" } : {\n\t\t\tprevious: t,\n\t\t\tstatus: \"pending\"\n\t\t};\n\t\tlet u;\n\t\ttry {\n\t\t\tu = Promise.resolve(r(i, { 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 && (a.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 && (a.value = t === 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: t,\n\t\t\t\tstatus: \"error\"\n\t\t\t});\n\t\t});\n\t}, u = t.effect(() => (l(), () => s?.abort()), { name: i?.name });\n\tu.disposalSignal.addEventListener(\"abort\", () => {\n\t\tc = !0;\n\t}, { once: !0 });\n\tlet d = {\n\t\tget disposalSignal() {\n\t\t\treturn u.disposalSignal;\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 a.name;\n\t\t},\n\t\tpeek: () => a.peek(),\n\t\treload: () => {\n\t\t\tc || (o.value = o.peek() + 1);\n\t\t},\n\t\tsubscribe: (e) => a.subscribe(e),\n\t\t[Symbol.dispose]() {\n\t\t\tthis.dispose();\n\t\t},\n\t\tget value() {\n\t\t\treturn a.value;\n\t\t}\n\t};\n\treturn Object.defineProperty(d, e, { value: !0 }), d;\n};\n//#endregion\nexport { t as createResource };\n\n//# sourceMappingURL=_async.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), r?.once && (c = !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 { ReactiveRuntime as e } from \"./runtime.js\";\nimport { createResource as t } from \"./_async.js\";\nimport { createWatch as n } from \"./_watch.js\";\n//#region src/_default.ts\nvar r = (r) => {\n\tlet i = new e(r), a = t(i);\n\treturn {\n\t\tbatch: i.batch,\n\t\tcomputed: i.computed,\n\t\tcreateScope: i.createScope,\n\t\tdispose: () => i.dispose(),\n\t\tget disposed() {\n\t\t\treturn i.disposed;\n\t\t},\n\t\teffect: i.effect,\n\t\tresource: a,\n\t\tsignal: i.signal,\n\t\tuntrack: i.untrack,\n\t\twatch: n(i)\n\t};\n}, i = r();\n//#endregion\nexport { r as createRipple, i 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, m = s.watch, h = s.resource;\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, h as resource, c as signal, p as untrack, m as watch };\n\n//# sourceMappingURL=index.js.map","import { signal } from '@vielzeug/ripple';\nimport {\n LedgerCancelledError,\n LedgerDisposedError,\n LedgerError,\n LedgerExecutionError,\n LedgerRollbackError,\n} from './errors';\nimport type {\n CommandContext,\n HistoryEntry,\n Ledger,\n LedgerCallOptions,\n LedgerOptions,\n LedgerState,\n ReversibleCommand,\n} from './types';\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 abortSignal = 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: () => abortSignal.removeEventListener('abort', onAbort),\n reject,\n resolve,\n settled: false,\n start: async () => {\n if (operation.settled) return;\n\n if (disposed || abortSignal.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: abortSignal });\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 abortSignal.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":"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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AAI,QAAS,GAAY,EAAY,IAAI,CAAO,CAAC,CAC1D,CACF,CACF"}
1
+ {"version":3,"file":"ledger.js","names":["e","t","r","i","i","c","l","e","u","n","d","f","t","r","e","e","n","s"],"sources":["../src/compose.ts","../src/errors.ts","../../ripple/dist/errors.js","../../ripple/dist/runtime.js","../../ripple/dist/_async.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\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 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}, 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.for(\"@vielzeug/ripple/reactive\"), a = 100, o = Symbol(\"ripple.unset\"), s = 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}, c = class extends s {\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\tupdate(e) {\n\t\tthis.value = e(this.current);\n\t}\n}, l = class extends s {\n\tdependencies = /* @__PURE__ */ new Set();\n\tcomputing = !1;\n\tdisposed = !1;\n\tdirty = !0;\n\tcurrent = o;\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.runtime.track(this), this.refresh(), 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 === o || !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}, u = 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}, d = 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 u(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}, f = 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 u(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 c(this, e, t));\n\tcomputed = (e, t) => {\n\t\tthis.assertActive();\n\t\tlet n = new l(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 d(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 u(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, e.dependencies.size === 0);\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 > a) throw new r(`infinite reactive flush (>${a} 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}, p = (e) => {\n\tif (typeof e != \"object\" || !e || !(i in e)) return !1;\n\tlet t = e;\n\treturn typeof t.peek == \"function\" && typeof t.subscribe == \"function\";\n};\n//#endregion\nexport { i as REACTIVE, f as ReactiveRuntime, p as isReactive };\n\n//# sourceMappingURL=runtime.js.map","import { REACTIVE as e } from \"./runtime.js\";\n//#region src/_async.ts\nvar t = (t) => (n, r, i) => {\n\tlet a = t.signal({ status: \"pending\" }, { name: i?.name }), o = t.signal(0), s, c = !1, l = () => {\n\t\to.value, s?.abort();\n\t\tlet e = a.peek(), t = e.status === \"success\" ? e.value : \"previous\" in e ? e.previous : void 0, i;\n\t\ttry {\n\t\t\ti = n();\n\t\t} catch (e) {\n\t\t\ta.value = t === 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: t,\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, a.value = t === void 0 ? { status: \"pending\" } : {\n\t\t\tprevious: t,\n\t\t\tstatus: \"pending\"\n\t\t};\n\t\tlet u;\n\t\ttry {\n\t\t\tu = Promise.resolve(r(i, { 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 && (a.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 && (a.value = t === 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: t,\n\t\t\t\tstatus: \"error\"\n\t\t\t});\n\t\t});\n\t}, u = t.effect(() => (l(), () => s?.abort()), { name: i?.name });\n\tu.disposalSignal.addEventListener(\"abort\", () => {\n\t\tc = !0;\n\t}, { once: !0 });\n\tlet d = {\n\t\tget disposalSignal() {\n\t\t\treturn u.disposalSignal;\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 a.name;\n\t\t},\n\t\tpeek: () => a.peek(),\n\t\treload: () => {\n\t\t\tc || (o.value = o.peek() + 1);\n\t\t},\n\t\tsubscribe: (e) => a.subscribe(e),\n\t\t[Symbol.dispose]() {\n\t\t\tthis.dispose();\n\t\t},\n\t\tget value() {\n\t\t\treturn a.value;\n\t\t}\n\t};\n\treturn Object.defineProperty(d, e, { value: !0 }), d;\n};\n//#endregion\nexport { t as createResource };\n\n//# sourceMappingURL=_async.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), r?.once && (c = !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 { ReactiveRuntime as e } from \"./runtime.js\";\nimport { createResource as t } from \"./_async.js\";\nimport { createWatch as n } from \"./_watch.js\";\n//#region src/_default.ts\nvar r = (r) => {\n\tlet i = new e(r), a = t(i);\n\treturn {\n\t\tbatch: i.batch,\n\t\tcomputed: i.computed,\n\t\tcreateScope: i.createScope,\n\t\tdispose: () => i.dispose(),\n\t\tget disposed() {\n\t\t\treturn i.disposed;\n\t\t},\n\t\teffect: i.effect,\n\t\tresource: a,\n\t\tsignal: i.signal,\n\t\tuntrack: i.untrack,\n\t\twatch: n(i)\n\t};\n}, i = r();\n//#endregion\nexport { r as createRipple, i 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, m = s.watch, h = s.resource;\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, h as resource, c as signal, p as untrack, m as watch };\n\n//# sourceMappingURL=index.js.map","import { signal } from '@vielzeug/ripple';\nimport {\n LedgerCancelledError,\n LedgerDisposedError,\n LedgerError,\n LedgerExecutionError,\n LedgerRollbackError,\n} from './errors';\nimport type {\n CommandContext,\n HistoryEntry,\n Ledger,\n LedgerCallOptions,\n LedgerOptions,\n LedgerState,\n ReversibleCommand,\n} from './types';\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 abortSignal = 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: () => abortSignal.removeEventListener('abort', onAbort),\n reject,\n resolve,\n settled: false,\n start: async () => {\n if (operation.settled) return;\n\n if (disposed || abortSignal.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: abortSignal });\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 abortSignal.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":"AAEA,SAAS,EAAuB,EAA6D,CAC3F,GAAM,CAAE,QAAO,Q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,CAAE,GAAG,EAAS,UAAW,GAAO,OAAQ,EAAG,KAAM,CAAC,EAAG,KAAM,CAAC,CAAE,EAAE,CAC5F,EAEA,IAAI,UAAoB,CACtB,OAAO,CACT,EAEA,GAAG,EAAmC,EAAgD,CACpF,IAAM,EAAW,EAAgB,CAAO,EAExC,OAAO,EAAQ,KAAM,GAAa,OAAS,GAAY,EAAM,EAAU,CAAO,CAAC,CACjF,EAEA,KAAK,EAAgD,CACnD,OAAO,EAAQ,OAAQ,GAAa,OAAQ,CAAO,CACrD,EAEA,IAAI,OAAQ,CACV,OAAO,CACT,EAEA,CAAC,OAAO,UAAiB,CACvB,KAAK,QAAQ,CACf,EAEA,KAAK,EAAgD,CACnD,OAAO,EAAQ,OAAQ,GAAa,OAAQ,CAAO,CACrD,EAEA,UAA0B,CAGxB,OAFI,EAAM,MAAM,SAAW,GAAK,EAAM,MAAM,UAAY,EAAU,QAAQ,QAAQ,EAE3E,IAAI,QAAS,GAAY,EAAY,IAAI,CAAO,CAAC,CAC1D,CACF,CACF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vielzeug/ledger",
3
- "version": "2.2.0",
3
+ "version": "2.2.1",
4
4
  "description": "Serialized reversible command history with atomic Ripple state and cancellation ownership",
5
5
  "repository": {
6
6
  "type": "git",
@@ -38,7 +38,7 @@
38
38
  "test": "vitest"
39
39
  },
40
40
  "dependencies": {
41
- "@vielzeug/ripple": "2.2.1"
41
+ "@vielzeug/ripple": "2.2.2"
42
42
  },
43
43
  "devDependencies": {
44
44
  "@types/node": "^26.2.0",