@callbag-recharge/callbag-recharge 0.20.0 → 0.22.0
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/chunk-5PWKJDS3.js +1 -0
- package/dist/chunk-DHPPL5V6.js +1 -0
- package/dist/chunk-VCD3MXHY.js +1 -0
- package/dist/data/index.d.cts +92 -2
- package/dist/data/index.d.ts +92 -2
- package/dist/executionLog-CREljpYk.d.cts +104 -0
- package/dist/executionLog-cGvVp5Ha.d.ts +104 -0
- package/dist/index.js +1 -1
- package/dist/memory/index.cjs +4 -4
- package/dist/memory/index.d.cts +74 -4
- package/dist/memory/index.d.ts +74 -4
- package/dist/memory/index.js +1 -1
- package/dist/messaging/index.d.cts +1 -1
- package/dist/messaging/index.d.ts +1 -1
- package/dist/orchestrate/executionLogAdapters.node.cjs +6 -0
- package/dist/orchestrate/executionLogAdapters.node.d.cts +37 -0
- package/dist/orchestrate/executionLogAdapters.node.d.ts +37 -0
- package/dist/orchestrate/executionLogAdapters.node.js +3 -0
- package/dist/orchestrate/index.cjs +6 -8
- package/dist/orchestrate/index.d.cts +9 -134
- package/dist/orchestrate/index.d.ts +9 -134
- package/dist/orchestrate/index.js +3 -5
- package/dist/patterns/memoryStore/index.cjs +4 -4
- package/dist/patterns/memoryStore/index.d.cts +2 -2
- package/dist/patterns/memoryStore/index.d.ts +2 -2
- package/dist/patterns/memoryStore/index.js +1 -1
- package/dist/types-9JbU1qd1.d.ts +182 -0
- package/dist/{types-CrTRz6Oy.d.cts → types-BRnNQbJn.d.cts} +1 -1
- package/dist/types-FP6jV-p5.d.cts +182 -0
- package/dist/{types-Ds0-O16t.d.ts → types-n54oEEx_.d.ts} +1 -1
- package/dist/utils/checkpointAdapters.node.cjs +1 -0
- package/dist/utils/checkpointAdapters.node.d.cts +36 -0
- package/dist/utils/checkpointAdapters.node.d.ts +36 -0
- package/dist/utils/checkpointAdapters.node.js +1 -0
- package/dist/utils/index.cjs +7 -7
- package/dist/utils/index.d.cts +5 -31
- package/dist/utils/index.d.ts +5 -31
- package/dist/utils/index.js +6 -6
- package/package.json +22 -2
- package/dist/chunk-G65KU7M5.js +0 -1
- package/dist/chunk-OLY7RFGZ.js +0 -1
- package/dist/types-BHpdU2-O.d.cts +0 -97
- package/dist/types-DETBg0QM.d.ts +0 -97
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function m(r){let c=r?.failureThreshold??5,t=r?.cooldownMs??3e4,o=r?.cooldown??null,i=r?.halfOpenMax??1,f=r?.now??Date.now,e="closed",n=0,a=0,s=0,d=t,u=0;function b(){if(!o)return t;let l=o(a);return l!==null?l:t}function p(){e="open",d=b(),s=f(),u=0}return{canExecute(){return e==="closed"?!0:e==="open"?f()-s>=d?(e="half-open",u=1,!0):!1:u<i?(u++,!0):!1},recordSuccess(){e==="half-open"?(e="closed",n=0,a=0):e==="closed"&&(n=0)},recordFailure(l){if(e==="half-open"){a++,p();return}e==="closed"&&(n++,n>=c&&p())},get state(){return e},get failureCount(){return n},reset(){e="closed",n=0,a=0,u=0}}}function h(r){return(c,t)=>{if(c!==0)return;let o=!1;t(0,i=>{i===2&&(o=!0)}),r.onsuccess=()=>{o||(o=!0,t(1,r.result),t(2))},r.onerror=()=>{o||(o=!0,t(2,r.error))}}}export{h as a,m as b};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as z}from"./chunk-JCENQEPP.js";import{a as W}from"./chunk-ZJCF5NYF.js";import{a as b}from"./chunk-PV347CGV.js";import{a as E}from"./chunk-GMLWTZFM.js";import{a as A}from"./chunk-EAK2HKAD.js";import{B as S,v as w}from"./chunk-TUPD47IE.js";function k(i){let a=i?.halfLife??864e5,m=i?.recency??1,p=i?.importance??1,T=i?.frequency??.5,y=Math.LN2/a;return(t,f)=>{let l=(f??Date.now())-t.accessedAt,u=Math.exp(-y*l),s=1-1/(1+t.accessCount);return m*u+p*t.importance+T*s}}function v(i,a,m){let p=a?.halfLife??864e5,T=a?.recency??1,y=a?.importance??1,t=a?.frequency??.5,f=(m??Date.now())-i.accessedAt,l=Math.exp(-Math.LN2/p*f),u=1-1/(1+i.accessCount);return T*l+y*i.importance+t*u}var O=0;function q(){return`mem-${++O}`}function L(i,a){let m=a?.id??q(),p=Date.now(),T={id:m,createdAt:p,updatedAt:p,accessedAt:p,accessCount:0,importance:a?.importance??.5,tags:new Set(a?.tags)},y=A(i,{name:`mem:${m}:content`}),t=A(T,{name:`mem:${m}:meta`,equals:()=>!1}),f={},l=b([t],()=>v(t.get(),f),{name:`mem:${m}:score`});return{id:m,content:y,meta:t,scoreStore:l,touch(){let s=Date.now();t.update(d=>({...d,accessedAt:s,accessCount:d.accessCount+1}))},tag(...s){t.update(d=>{let h=new Set(d.tags);for(let M of s)h.add(M);return{...d,tags:h,updatedAt:Date.now()}})},untag(...s){t.update(d=>{let h=new Set(d.tags);for(let M of s)h.delete(M);return{...d,tags:h,updatedAt:Date.now()}})},setImportance(s){t.update(d=>({...d,importance:Math.max(0,Math.min(1,s)),updatedAt:Date.now()}))},update(s){w(()=>{y.set(s),t.update(d=>({...d,updatedAt:Date.now()}))})},score(s){return v(t.get(),s??f)},destroy(){S(y),S(t)}}}var P=0;function oe(i){let a=++P,m=i?.maxSize??1/0,p=i?.weights??{},T=i?.admissionPolicy,y=i?.forgetPolicy,t=new Map,f=W(),l=new Map,u=m<1/0?z(e=>t.get(e).meta,e=>v(e,p)):null,s=A(0,{name:`collection-${a}:ver`}),d=b([s],()=>Array.from(t.values()),{name:`collection-${a}:nodes`}),h=b([s],()=>t.size,{name:`collection-${a}:size`}),M=!1;function _(){s.update(e=>e+1)}function x(e){let o=Array.from(e.meta.get().tags);f.update(e.id,o);let r=E(e.meta,I=>{let n=Array.from(I.tags);f.update(e.id,n)});l.set(e.id,()=>r.unsubscribe())}function D(e){let o=l.get(e);o&&(o(),l.delete(e)),f.remove(e)}function $(){if(!u||t.size<=m)return;let e=u.evict(t.size-m);for(let o of e){let r=t.get(o);r&&(D(o),r.destroy(),t.delete(o))}}function C(){if(!y)return 0;let e=[];for(let o of t.values())y(o)&&e.push(o.id);for(let o of e){let r=t.get(o);r&&(D(o),u?.delete(o),r.destroy(),t.delete(o))}return e.length}return{add(e,o){if(M)throw new Error("Collection is destroyed");if(T){let I=Array.from(t.values()),n=T(e,I);switch(n.action){case"reject":return;case"update":{let c=t.get(n.targetId);if(!c)throw new Error(`Admission update target "${n.targetId}" not found`);return c.update(n.content),c}case"merge":{let c=t.get(n.targetId);if(!c)throw new Error(`Admission merge target "${n.targetId}" not found`);let g=n.reducer(c.content.get(),e);return c.update(g),c}default:break}}y&&C();let r=L(e,o);return t.set(r.id,r),x(r),u?.insert(r.id),$(),_(),r},remove(e){let o=typeof e=="string"?e:e.id,r=t.get(o);return r?(D(o),u?.delete(o),r.destroy(),t.delete(o),_(),!0):!1},get(e){return t.get(e)},has(e){return t.has(e)},nodes:d,size:h,tagIndex:f,query(e){let o=[];for(let r of t.values())e(r)&&o.push(r);return o},byTag(e){let o=f.get(e),r=[];for(let I of o){let n=t.get(I);n&&r.push(n)}return r},topK(e,o){let r=o??p,I=Date.now(),n=Array.from(t.values()).map(c=>({node:c,score:v(c.meta.get(),r,I)}));return n.sort((c,g)=>g.score-c.score),n.slice(0,e).map(c=>c.node)},summarize(e,o,r){if(M)throw new Error("Collection is destroyed");let I=Array.from(new Set(e)),n=[];for(let N of I){let F=t.get(N);F&&n.push(F)}if(n.length===0)throw new Error("No valid nodes to summarize");let c=o(n),g;return w(()=>{for(let N of n)D(N.id),u?.delete(N.id),N.destroy(),t.delete(N.id);y&&C(),g=L(c,r),t.set(g.id,g),x(g),u?.insert(g.id),_()}),g},gc(){if(M)throw new Error("Collection is destroyed");let e=C();return e>0&&_(),e},destroy(){if(!M){M=!0,u?.clear();for(let e of l.values())e();l.clear(),f.destroy(),w(()=>{for(let e of t.values())e.destroy();t.clear()}),S(s)}}}}export{k as a,v as b,L as c,oe as d};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as g}from"./chunk-QSFTSBDR.js";import{a as u}from"./chunk-EAK2HKAD.js";import{B as m}from"./chunk-TUPD47IE.js";function A(b,d){let h=Math.max(1,d?.concurrency??1),S=d?.strategy??"fifo",s=d?.name??"asyncQueue",a=u(0,{name:`${s}.size`}),c=u(0,{name:`${s}.running`}),p=u(0,{name:`${s}.completed`}),k=u(0,{name:`${s}.failed`}),l=u(!1,{name:`${s}.paused`}),t=[],o=0,i=!1;function T(n,e){i||(o--,c.set(o),p.update(r=>r+1),n.done$.set({ok:!0,result:e}),f())}function y(n,e){i||(o--,c.set(o),k.update(r=>r+1),n.done$.set({ok:!1,error:e}),f())}function f(){if(!(i||l.get()))for(;o<h&&t.length>0;){let n=S==="lifo"?t.pop():t.shift();a.set(t.length),o++,c.set(o);try{b(n.task).then(e=>T(n,e),e=>y(n,e))}catch(e){y(n,e)}}}function Q(n){if(i)return Promise.reject(new Error("Queue is disposed"));let e=u(null,{name:`${s}.task`});return t.push({task:n,done$:e}),a.set(t.length),f(),g(e,r=>r!==null).then(r=>{if(m(e),r.ok)return r.result;throw r.error},r=>{throw m(e),r})}function $(){l.set(!0)}function v(){l.set(!1),f()}function R(){let n=t.splice(0,t.length);a.set(0);for(let e of n)e.done$.set({ok:!1,error:new Error("Queue cleared")})}function w(){i||(i=!0,R())}return{enqueue:Q,size:a,running:c,completed:p,failed:k,pause:$,resume:v,paused:l,clear:R,dispose:w}}export{A as a};
|
package/dist/data/index.d.cts
CHANGED
|
@@ -1,9 +1,34 @@
|
|
|
1
|
-
import { P as PubSub,
|
|
2
|
-
export { K as KVEvent, g as KVEventType, h as LogEntry, i as LogEvent, j as LogEventType, k as ReactiveIndexOptions } from '../types-
|
|
1
|
+
import { P as PubSub, b as PubSubSnapshot, R as ReactiveIndex, I as IndexSnapshot, N as NodeV0, L as ListSnapshot, c as ReactiveLogOptions, a as ReactiveLog, d as LogSnapshot, e as ReactiveMapOptions, f as ReactiveMap, M as MapSnapshot } from '../types-BRnNQbJn.cjs';
|
|
2
|
+
export { K as KVEvent, g as KVEventType, h as LogEntry, i as LogEvent, j as LogEventType, k as ReactiveIndexOptions } from '../types-BRnNQbJn.cjs';
|
|
3
3
|
import { S as Store } from '../types-BohB8jJr.cjs';
|
|
4
4
|
import '../eviction-DGPP1vHP.cjs';
|
|
5
5
|
import '../protocol-fwiQ1TAS.cjs';
|
|
6
6
|
|
|
7
|
+
/**
|
|
8
|
+
* Creates a lightweight topic-based publish/subscribe channel.
|
|
9
|
+
*
|
|
10
|
+
* @param opts - Optional configuration.
|
|
11
|
+
*
|
|
12
|
+
* @returns `PubSub<T>` — topic publish/subscribe API with snapshot and lifecycle methods.
|
|
13
|
+
*
|
|
14
|
+
* @remarks **Lazy channels:** Topics are created on first publish/subscribe.
|
|
15
|
+
* @remarks **Reactive subscription:** `subscribe(topic)` returns a read-only store for latest topic value.
|
|
16
|
+
* @remarks **Ephemeral emission semantics:** Message updates always emit, even for referentially equal values.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```ts
|
|
20
|
+
* import { pubsub } from "callbag-recharge/data";
|
|
21
|
+
*
|
|
22
|
+
* const bus = pubsub<string>();
|
|
23
|
+
* const chat = bus.subscribe("chat");
|
|
24
|
+
*
|
|
25
|
+
* bus.publish("chat", "hello");
|
|
26
|
+
* chat.get(); // "hello"
|
|
27
|
+
* ```
|
|
28
|
+
*
|
|
29
|
+
* @seeAlso [topic](/api/topic), [subscription](/api/subscription), [reactiveMap](./reactiveMap)
|
|
30
|
+
* @category data
|
|
31
|
+
*/
|
|
7
32
|
declare function pubsub<T = unknown>(opts?: {
|
|
8
33
|
id?: string;
|
|
9
34
|
}): PubSub<T>;
|
|
@@ -15,6 +40,39 @@ interface ReactiveIndexCreateOptions {
|
|
|
15
40
|
/** User-specified ID. Auto-generated if omitted. */
|
|
16
41
|
id?: string;
|
|
17
42
|
}
|
|
43
|
+
/**
|
|
44
|
+
* Creates a reactive secondary index from index key to sets of primary keys.
|
|
45
|
+
*
|
|
46
|
+
* @param opts - Optional configuration.
|
|
47
|
+
*
|
|
48
|
+
* @returns `ReactiveIndex` — reverse mapping queries, reactive selectors, mutation helpers, and snapshot APIs.
|
|
49
|
+
*
|
|
50
|
+
* @remarks **Reverse map:** Tracks primary key to index keys for efficient `remove()` and `update()`.
|
|
51
|
+
* @remarks **Reactive selectors:** `select(indexKey)` returns cached stores for index-key membership updates.
|
|
52
|
+
* @remarks **Structural versioning:** `keysStore`/`sizeStore` are version-gated and update on keyset changes.
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* ```ts
|
|
56
|
+
* import { reactiveIndex } from "callbag-recharge/data";
|
|
57
|
+
*
|
|
58
|
+
* const byTag = reactiveIndex();
|
|
59
|
+
* byTag.add("u1", ["admin", "active"]);
|
|
60
|
+
* byTag.get("admin"); // Set { "u1" }
|
|
61
|
+
* ```
|
|
62
|
+
*
|
|
63
|
+
* @example Update indexed keys
|
|
64
|
+
* ```ts
|
|
65
|
+
* const byTag = reactiveIndex();
|
|
66
|
+
* byTag.add("u1", ["admin"]);
|
|
67
|
+
* byTag.update("u1", ["editor"]);
|
|
68
|
+
*
|
|
69
|
+
* byTag.get("admin").size; // 0
|
|
70
|
+
* byTag.get("editor").size; // 1
|
|
71
|
+
* ```
|
|
72
|
+
*
|
|
73
|
+
* @seeAlso [reactiveMap](./reactiveMap), [reactiveList](./reactiveList), [pubsub](./pubsub)
|
|
74
|
+
* @category data
|
|
75
|
+
*/
|
|
18
76
|
declare function reactiveIndex(opts?: ReactiveIndexCreateOptions): ReactiveIndex;
|
|
19
77
|
declare namespace reactiveIndex {
|
|
20
78
|
var from: (snap: IndexSnapshot) => ReactiveIndex;
|
|
@@ -135,6 +193,38 @@ declare namespace reactiveLog {
|
|
|
135
193
|
var from: <V>(snap: LogSnapshot<V>, opts?: Omit<ReactiveLogOptions, "id">) => ReactiveLog<V>;
|
|
136
194
|
}
|
|
137
195
|
|
|
196
|
+
/**
|
|
197
|
+
* Creates a reactive key-value store with point reads, reactive selects, and optional TTL.
|
|
198
|
+
*
|
|
199
|
+
* @param opts - Optional configuration.
|
|
200
|
+
*
|
|
201
|
+
* @returns `ReactiveMap<V>` — key-value operations, reactive views, events, and lifecycle controls.
|
|
202
|
+
*
|
|
203
|
+
* @remarks **Single source of truth:** Internal `Map` is authoritative; reactive stores mirror map state.
|
|
204
|
+
* @remarks **Reactive views:** `select(key)`, `keysStore`, and `sizeStore` update through graph propagation.
|
|
205
|
+
* @remarks **TTL + eviction:** Supports per-key/default TTL and optional bounded-size eviction policies.
|
|
206
|
+
*
|
|
207
|
+
* @example
|
|
208
|
+
* ```ts
|
|
209
|
+
* import { reactiveMap } from "callbag-recharge/data";
|
|
210
|
+
*
|
|
211
|
+
* const users = reactiveMap<{ name: string }>();
|
|
212
|
+
* users.set("u1", { name: "Ada" });
|
|
213
|
+
* users.get("u1"); // { name: "Ada" }
|
|
214
|
+
* ```
|
|
215
|
+
*
|
|
216
|
+
* @example Reactive key subscription
|
|
217
|
+
* ```ts
|
|
218
|
+
* const users = reactiveMap<number>();
|
|
219
|
+
* const score = users.select("u1");
|
|
220
|
+
*
|
|
221
|
+
* users.set("u1", 10);
|
|
222
|
+
* score.get(); // 10
|
|
223
|
+
* ```
|
|
224
|
+
*
|
|
225
|
+
* @seeAlso [reactiveIndex](./reactiveIndex), [reactiveLog](./reactiveLog), [compaction](./compaction)
|
|
226
|
+
* @category data
|
|
227
|
+
*/
|
|
138
228
|
declare function reactiveMap<V>(opts?: ReactiveMapOptions<V>): ReactiveMap<V>;
|
|
139
229
|
declare namespace reactiveMap {
|
|
140
230
|
var from: <V>(snap: MapSnapshot<V>, opts?: Omit<ReactiveMapOptions<V>, "id">) => ReactiveMap<V>;
|
package/dist/data/index.d.ts
CHANGED
|
@@ -1,9 +1,34 @@
|
|
|
1
|
-
import { P as PubSub,
|
|
2
|
-
export { K as KVEvent, g as KVEventType, h as LogEntry, i as LogEvent, j as LogEventType, k as ReactiveIndexOptions } from '../types-
|
|
1
|
+
import { P as PubSub, b as PubSubSnapshot, R as ReactiveIndex, I as IndexSnapshot, N as NodeV0, L as ListSnapshot, c as ReactiveLogOptions, a as ReactiveLog, d as LogSnapshot, e as ReactiveMapOptions, f as ReactiveMap, M as MapSnapshot } from '../types-n54oEEx_.js';
|
|
2
|
+
export { K as KVEvent, g as KVEventType, h as LogEntry, i as LogEvent, j as LogEventType, k as ReactiveIndexOptions } from '../types-n54oEEx_.js';
|
|
3
3
|
import { S as Store } from '../types-CB1htCM8.js';
|
|
4
4
|
import '../eviction-DGPP1vHP.js';
|
|
5
5
|
import '../protocol-fwiQ1TAS.js';
|
|
6
6
|
|
|
7
|
+
/**
|
|
8
|
+
* Creates a lightweight topic-based publish/subscribe channel.
|
|
9
|
+
*
|
|
10
|
+
* @param opts - Optional configuration.
|
|
11
|
+
*
|
|
12
|
+
* @returns `PubSub<T>` — topic publish/subscribe API with snapshot and lifecycle methods.
|
|
13
|
+
*
|
|
14
|
+
* @remarks **Lazy channels:** Topics are created on first publish/subscribe.
|
|
15
|
+
* @remarks **Reactive subscription:** `subscribe(topic)` returns a read-only store for latest topic value.
|
|
16
|
+
* @remarks **Ephemeral emission semantics:** Message updates always emit, even for referentially equal values.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```ts
|
|
20
|
+
* import { pubsub } from "callbag-recharge/data";
|
|
21
|
+
*
|
|
22
|
+
* const bus = pubsub<string>();
|
|
23
|
+
* const chat = bus.subscribe("chat");
|
|
24
|
+
*
|
|
25
|
+
* bus.publish("chat", "hello");
|
|
26
|
+
* chat.get(); // "hello"
|
|
27
|
+
* ```
|
|
28
|
+
*
|
|
29
|
+
* @seeAlso [topic](/api/topic), [subscription](/api/subscription), [reactiveMap](./reactiveMap)
|
|
30
|
+
* @category data
|
|
31
|
+
*/
|
|
7
32
|
declare function pubsub<T = unknown>(opts?: {
|
|
8
33
|
id?: string;
|
|
9
34
|
}): PubSub<T>;
|
|
@@ -15,6 +40,39 @@ interface ReactiveIndexCreateOptions {
|
|
|
15
40
|
/** User-specified ID. Auto-generated if omitted. */
|
|
16
41
|
id?: string;
|
|
17
42
|
}
|
|
43
|
+
/**
|
|
44
|
+
* Creates a reactive secondary index from index key to sets of primary keys.
|
|
45
|
+
*
|
|
46
|
+
* @param opts - Optional configuration.
|
|
47
|
+
*
|
|
48
|
+
* @returns `ReactiveIndex` — reverse mapping queries, reactive selectors, mutation helpers, and snapshot APIs.
|
|
49
|
+
*
|
|
50
|
+
* @remarks **Reverse map:** Tracks primary key to index keys for efficient `remove()` and `update()`.
|
|
51
|
+
* @remarks **Reactive selectors:** `select(indexKey)` returns cached stores for index-key membership updates.
|
|
52
|
+
* @remarks **Structural versioning:** `keysStore`/`sizeStore` are version-gated and update on keyset changes.
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* ```ts
|
|
56
|
+
* import { reactiveIndex } from "callbag-recharge/data";
|
|
57
|
+
*
|
|
58
|
+
* const byTag = reactiveIndex();
|
|
59
|
+
* byTag.add("u1", ["admin", "active"]);
|
|
60
|
+
* byTag.get("admin"); // Set { "u1" }
|
|
61
|
+
* ```
|
|
62
|
+
*
|
|
63
|
+
* @example Update indexed keys
|
|
64
|
+
* ```ts
|
|
65
|
+
* const byTag = reactiveIndex();
|
|
66
|
+
* byTag.add("u1", ["admin"]);
|
|
67
|
+
* byTag.update("u1", ["editor"]);
|
|
68
|
+
*
|
|
69
|
+
* byTag.get("admin").size; // 0
|
|
70
|
+
* byTag.get("editor").size; // 1
|
|
71
|
+
* ```
|
|
72
|
+
*
|
|
73
|
+
* @seeAlso [reactiveMap](./reactiveMap), [reactiveList](./reactiveList), [pubsub](./pubsub)
|
|
74
|
+
* @category data
|
|
75
|
+
*/
|
|
18
76
|
declare function reactiveIndex(opts?: ReactiveIndexCreateOptions): ReactiveIndex;
|
|
19
77
|
declare namespace reactiveIndex {
|
|
20
78
|
var from: (snap: IndexSnapshot) => ReactiveIndex;
|
|
@@ -135,6 +193,38 @@ declare namespace reactiveLog {
|
|
|
135
193
|
var from: <V>(snap: LogSnapshot<V>, opts?: Omit<ReactiveLogOptions, "id">) => ReactiveLog<V>;
|
|
136
194
|
}
|
|
137
195
|
|
|
196
|
+
/**
|
|
197
|
+
* Creates a reactive key-value store with point reads, reactive selects, and optional TTL.
|
|
198
|
+
*
|
|
199
|
+
* @param opts - Optional configuration.
|
|
200
|
+
*
|
|
201
|
+
* @returns `ReactiveMap<V>` — key-value operations, reactive views, events, and lifecycle controls.
|
|
202
|
+
*
|
|
203
|
+
* @remarks **Single source of truth:** Internal `Map` is authoritative; reactive stores mirror map state.
|
|
204
|
+
* @remarks **Reactive views:** `select(key)`, `keysStore`, and `sizeStore` update through graph propagation.
|
|
205
|
+
* @remarks **TTL + eviction:** Supports per-key/default TTL and optional bounded-size eviction policies.
|
|
206
|
+
*
|
|
207
|
+
* @example
|
|
208
|
+
* ```ts
|
|
209
|
+
* import { reactiveMap } from "callbag-recharge/data";
|
|
210
|
+
*
|
|
211
|
+
* const users = reactiveMap<{ name: string }>();
|
|
212
|
+
* users.set("u1", { name: "Ada" });
|
|
213
|
+
* users.get("u1"); // { name: "Ada" }
|
|
214
|
+
* ```
|
|
215
|
+
*
|
|
216
|
+
* @example Reactive key subscription
|
|
217
|
+
* ```ts
|
|
218
|
+
* const users = reactiveMap<number>();
|
|
219
|
+
* const score = users.select("u1");
|
|
220
|
+
*
|
|
221
|
+
* users.set("u1", 10);
|
|
222
|
+
* score.get(); // 10
|
|
223
|
+
* ```
|
|
224
|
+
*
|
|
225
|
+
* @seeAlso [reactiveIndex](./reactiveIndex), [reactiveLog](./reactiveLog), [compaction](./compaction)
|
|
226
|
+
* @category data
|
|
227
|
+
*/
|
|
138
228
|
declare function reactiveMap<V>(opts?: ReactiveMapOptions<V>): ReactiveMap<V>;
|
|
139
229
|
declare namespace reactiveMap {
|
|
140
230
|
var from: <V>(snap: MapSnapshot<V>, opts?: Omit<ReactiveMapOptions<V>, "id">) => ReactiveMap<V>;
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { S as Store } from './types-BohB8jJr.cjs';
|
|
2
|
+
import { a as ReactiveLog } from './types-BRnNQbJn.cjs';
|
|
3
|
+
|
|
4
|
+
type ExecutionEventType = "start" | "value" | "complete" | "error";
|
|
5
|
+
interface ExecutionEntry {
|
|
6
|
+
/** Step name (or pipeline-level event). */
|
|
7
|
+
step: string;
|
|
8
|
+
/** Event type. */
|
|
9
|
+
event: ExecutionEventType;
|
|
10
|
+
/** Timestamp (ms since epoch). */
|
|
11
|
+
timestamp: number;
|
|
12
|
+
/** Value payload (for "value" events). */
|
|
13
|
+
value?: unknown;
|
|
14
|
+
/** Error payload (for "error" events). */
|
|
15
|
+
error?: unknown;
|
|
16
|
+
/** Run count at time of event. */
|
|
17
|
+
runCount?: number;
|
|
18
|
+
}
|
|
19
|
+
interface ExecutionLogPersistAdapter {
|
|
20
|
+
/** Append an entry to persistent storage. May be sync or async. */
|
|
21
|
+
append(entry: ExecutionEntry): void | Promise<void>;
|
|
22
|
+
/** Load all persisted entries. */
|
|
23
|
+
load(): ExecutionEntry[] | Promise<ExecutionEntry[]>;
|
|
24
|
+
/** Clear all persisted entries. */
|
|
25
|
+
clear(): void | Promise<void>;
|
|
26
|
+
}
|
|
27
|
+
interface ExecutionLogOptions {
|
|
28
|
+
/** Maximum number of entries to keep in memory. Default: unlimited. */
|
|
29
|
+
maxSize?: number;
|
|
30
|
+
/** Debug name. */
|
|
31
|
+
name?: string;
|
|
32
|
+
/** Optional persistence adapter. Entries are written through on append. */
|
|
33
|
+
persist?: ExecutionLogPersistAdapter;
|
|
34
|
+
}
|
|
35
|
+
interface ExecutionLogResult {
|
|
36
|
+
/** The underlying reactive log. */
|
|
37
|
+
log: ReactiveLog<ExecutionEntry>;
|
|
38
|
+
/** Append an execution event. */
|
|
39
|
+
append(entry: ExecutionEntry): number;
|
|
40
|
+
/** Get all entries for a specific step. */
|
|
41
|
+
forStep(step: string): ExecutionEntry[];
|
|
42
|
+
/** Reactive store: latest entry. */
|
|
43
|
+
latest: Store<ExecutionEntry | undefined>;
|
|
44
|
+
/** Reactive store: entry count. */
|
|
45
|
+
length: Store<number>;
|
|
46
|
+
/** Reactive store: last persist error (null when healthy). */
|
|
47
|
+
persistError: Store<unknown>;
|
|
48
|
+
/** Clear the log. */
|
|
49
|
+
clear(): void;
|
|
50
|
+
/** Destroy the log and clean up. */
|
|
51
|
+
destroy(): void;
|
|
52
|
+
/**
|
|
53
|
+
* Connect to a pipeline's stepMeta stores for auto-logging.
|
|
54
|
+
* Returns an unsubscribe function.
|
|
55
|
+
*/
|
|
56
|
+
connectPipeline(stepMeta: Record<string, Store<any>>, stepNames: string[]): () => void;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Creates a reactive execution log for workflow step tracking. Backed by `reactiveLog` (Phase 3b).
|
|
60
|
+
*
|
|
61
|
+
* @param opts - Optional configuration.
|
|
62
|
+
*
|
|
63
|
+
* @returns `ExecutionLogResult` — reactive log with step filtering, pipeline auto-connect, and optional persistence.
|
|
64
|
+
*
|
|
65
|
+
* @returnsTable log | ReactiveLog\<ExecutionEntry\> | Underlying reactive log.
|
|
66
|
+
* append(entry) | (entry) => number | Append an execution event.
|
|
67
|
+
* forStep(step) | (step) => ExecutionEntry[] | Get entries for a specific step.
|
|
68
|
+
* latest | Store\<ExecutionEntry \| undefined\> | Reactive latest entry.
|
|
69
|
+
* length | Store\<number\> | Reactive entry count.
|
|
70
|
+
* persistError | Store\<unknown\> | Last persist error (null when healthy).
|
|
71
|
+
* connectPipeline(stepMeta, names) | (...) => () => void | Auto-log pipeline step events.
|
|
72
|
+
* clear() | () => void | Clear the log.
|
|
73
|
+
* destroy() | () => void | Destroy and clean up.
|
|
74
|
+
*
|
|
75
|
+
* @remarks **Auto-logging:** `connectPipeline()` subscribes to per-step metadata stores and auto-appends start/value/complete/error events.
|
|
76
|
+
* @remarks **Persistence:** Optional adapter writes through on every append. Load on construction for recovery.
|
|
77
|
+
* @remarks **Bounded:** Set `maxSize` for production to prevent unbounded memory growth.
|
|
78
|
+
*
|
|
79
|
+
* @example
|
|
80
|
+
* ```ts
|
|
81
|
+
* import { executionLog } from 'callbag-recharge/orchestrate';
|
|
82
|
+
* import { pipeline, step, fromTrigger } from 'callbag-recharge/orchestrate';
|
|
83
|
+
*
|
|
84
|
+
* const log = executionLog({ maxSize: 500 });
|
|
85
|
+
* const wf = pipeline({
|
|
86
|
+
* trigger: step(fromTrigger<number>()),
|
|
87
|
+
* });
|
|
88
|
+
* const unsub = log.connectPipeline(wf.stepMeta, wf.order);
|
|
89
|
+
* // Events auto-logged as pipeline runs
|
|
90
|
+
* log.forStep("trigger"); // all events for "trigger" step
|
|
91
|
+
* unsub();
|
|
92
|
+
* ```
|
|
93
|
+
*
|
|
94
|
+
* @seeAlso [pipeline](./pipeline) — workflow builder, [reactiveLog](./reactiveLog) — underlying data structure
|
|
95
|
+
*
|
|
96
|
+
* @category orchestrate
|
|
97
|
+
*/
|
|
98
|
+
declare function executionLog(opts?: ExecutionLogOptions): ExecutionLogResult;
|
|
99
|
+
/**
|
|
100
|
+
* In-memory execution log persistence adapter. Useful for testing.
|
|
101
|
+
*/
|
|
102
|
+
declare function memoryLogAdapter(): ExecutionLogPersistAdapter;
|
|
103
|
+
|
|
104
|
+
export { type ExecutionLogPersistAdapter as E, type ExecutionEntry as a, type ExecutionEventType as b, type ExecutionLogOptions as c, type ExecutionLogResult as d, executionLog as e, memoryLogAdapter as m };
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { S as Store } from './types-CB1htCM8.js';
|
|
2
|
+
import { a as ReactiveLog } from './types-n54oEEx_.js';
|
|
3
|
+
|
|
4
|
+
type ExecutionEventType = "start" | "value" | "complete" | "error";
|
|
5
|
+
interface ExecutionEntry {
|
|
6
|
+
/** Step name (or pipeline-level event). */
|
|
7
|
+
step: string;
|
|
8
|
+
/** Event type. */
|
|
9
|
+
event: ExecutionEventType;
|
|
10
|
+
/** Timestamp (ms since epoch). */
|
|
11
|
+
timestamp: number;
|
|
12
|
+
/** Value payload (for "value" events). */
|
|
13
|
+
value?: unknown;
|
|
14
|
+
/** Error payload (for "error" events). */
|
|
15
|
+
error?: unknown;
|
|
16
|
+
/** Run count at time of event. */
|
|
17
|
+
runCount?: number;
|
|
18
|
+
}
|
|
19
|
+
interface ExecutionLogPersistAdapter {
|
|
20
|
+
/** Append an entry to persistent storage. May be sync or async. */
|
|
21
|
+
append(entry: ExecutionEntry): void | Promise<void>;
|
|
22
|
+
/** Load all persisted entries. */
|
|
23
|
+
load(): ExecutionEntry[] | Promise<ExecutionEntry[]>;
|
|
24
|
+
/** Clear all persisted entries. */
|
|
25
|
+
clear(): void | Promise<void>;
|
|
26
|
+
}
|
|
27
|
+
interface ExecutionLogOptions {
|
|
28
|
+
/** Maximum number of entries to keep in memory. Default: unlimited. */
|
|
29
|
+
maxSize?: number;
|
|
30
|
+
/** Debug name. */
|
|
31
|
+
name?: string;
|
|
32
|
+
/** Optional persistence adapter. Entries are written through on append. */
|
|
33
|
+
persist?: ExecutionLogPersistAdapter;
|
|
34
|
+
}
|
|
35
|
+
interface ExecutionLogResult {
|
|
36
|
+
/** The underlying reactive log. */
|
|
37
|
+
log: ReactiveLog<ExecutionEntry>;
|
|
38
|
+
/** Append an execution event. */
|
|
39
|
+
append(entry: ExecutionEntry): number;
|
|
40
|
+
/** Get all entries for a specific step. */
|
|
41
|
+
forStep(step: string): ExecutionEntry[];
|
|
42
|
+
/** Reactive store: latest entry. */
|
|
43
|
+
latest: Store<ExecutionEntry | undefined>;
|
|
44
|
+
/** Reactive store: entry count. */
|
|
45
|
+
length: Store<number>;
|
|
46
|
+
/** Reactive store: last persist error (null when healthy). */
|
|
47
|
+
persistError: Store<unknown>;
|
|
48
|
+
/** Clear the log. */
|
|
49
|
+
clear(): void;
|
|
50
|
+
/** Destroy the log and clean up. */
|
|
51
|
+
destroy(): void;
|
|
52
|
+
/**
|
|
53
|
+
* Connect to a pipeline's stepMeta stores for auto-logging.
|
|
54
|
+
* Returns an unsubscribe function.
|
|
55
|
+
*/
|
|
56
|
+
connectPipeline(stepMeta: Record<string, Store<any>>, stepNames: string[]): () => void;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Creates a reactive execution log for workflow step tracking. Backed by `reactiveLog` (Phase 3b).
|
|
60
|
+
*
|
|
61
|
+
* @param opts - Optional configuration.
|
|
62
|
+
*
|
|
63
|
+
* @returns `ExecutionLogResult` — reactive log with step filtering, pipeline auto-connect, and optional persistence.
|
|
64
|
+
*
|
|
65
|
+
* @returnsTable log | ReactiveLog\<ExecutionEntry\> | Underlying reactive log.
|
|
66
|
+
* append(entry) | (entry) => number | Append an execution event.
|
|
67
|
+
* forStep(step) | (step) => ExecutionEntry[] | Get entries for a specific step.
|
|
68
|
+
* latest | Store\<ExecutionEntry \| undefined\> | Reactive latest entry.
|
|
69
|
+
* length | Store\<number\> | Reactive entry count.
|
|
70
|
+
* persistError | Store\<unknown\> | Last persist error (null when healthy).
|
|
71
|
+
* connectPipeline(stepMeta, names) | (...) => () => void | Auto-log pipeline step events.
|
|
72
|
+
* clear() | () => void | Clear the log.
|
|
73
|
+
* destroy() | () => void | Destroy and clean up.
|
|
74
|
+
*
|
|
75
|
+
* @remarks **Auto-logging:** `connectPipeline()` subscribes to per-step metadata stores and auto-appends start/value/complete/error events.
|
|
76
|
+
* @remarks **Persistence:** Optional adapter writes through on every append. Load on construction for recovery.
|
|
77
|
+
* @remarks **Bounded:** Set `maxSize` for production to prevent unbounded memory growth.
|
|
78
|
+
*
|
|
79
|
+
* @example
|
|
80
|
+
* ```ts
|
|
81
|
+
* import { executionLog } from 'callbag-recharge/orchestrate';
|
|
82
|
+
* import { pipeline, step, fromTrigger } from 'callbag-recharge/orchestrate';
|
|
83
|
+
*
|
|
84
|
+
* const log = executionLog({ maxSize: 500 });
|
|
85
|
+
* const wf = pipeline({
|
|
86
|
+
* trigger: step(fromTrigger<number>()),
|
|
87
|
+
* });
|
|
88
|
+
* const unsub = log.connectPipeline(wf.stepMeta, wf.order);
|
|
89
|
+
* // Events auto-logged as pipeline runs
|
|
90
|
+
* log.forStep("trigger"); // all events for "trigger" step
|
|
91
|
+
* unsub();
|
|
92
|
+
* ```
|
|
93
|
+
*
|
|
94
|
+
* @seeAlso [pipeline](./pipeline) — workflow builder, [reactiveLog](./reactiveLog) — underlying data structure
|
|
95
|
+
*
|
|
96
|
+
* @category orchestrate
|
|
97
|
+
*/
|
|
98
|
+
declare function executionLog(opts?: ExecutionLogOptions): ExecutionLogResult;
|
|
99
|
+
/**
|
|
100
|
+
* In-memory execution log persistence adapter. Useful for testing.
|
|
101
|
+
*/
|
|
102
|
+
declare function memoryLogAdapter(): ExecutionLogPersistAdapter;
|
|
103
|
+
|
|
104
|
+
export { type ExecutionLogPersistAdapter as E, type ExecutionEntry as a, type ExecutionEventType as b, type ExecutionLogOptions as c, type ExecutionLogResult as d, executionLog as e, memoryLogAdapter as m };
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as
|
|
1
|
+
import{a as D}from"./chunk-BWH53TL4.js";import{a as A}from"./chunk-DIXN33QZ.js";import{a as R}from"./chunk-2ZFSL4MA.js";import{a as b}from"./chunk-YBVQC3GP.js";import{a as u}from"./chunk-PV347CGV.js";import"./chunk-HK7DRUNM.js";import{a as v}from"./chunk-GMLWTZFM.js";import{a as g}from"./chunk-EAK2HKAD.js";import{i as O}from"./chunk-2F6QWERG.js";import{a as l}from"./chunk-2L6223KN.js";import{A as E,B as T,a as e,b as r,d as t,e as o,f as p,g as i,h as a,r as s,s as c,t as f,u as n,v as S,w as m,x as d,y as x,z as y}from"./chunk-TUPD47IE.js";import"./chunk-I7AUKTXE.js";export{c as DATA,e as DIRTY,f as END,l as Inspector,o as PAUSE,t as RESET,r as RESOLVED,p as RESUME,s as START,n as STATE,i as TEARDOWN,S as batch,x as beginDeferredStart,d as deferEmission,E as deferStart,u as derived,D as dynamicDerived,R as effect,y as endDeferredStart,m as isBatching,a as isLifecycleSignal,b as operator,A as pipe,O as producer,g as state,v as subscribe,T as teardown};
|