@bandeira-tech/b3nd-save 0.8.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/LICENSE +21 -0
- package/esm/_dnt.shims.d.ts +2 -0
- package/esm/_dnt.shims.d.ts.map +1 -0
- package/esm/_dnt.shims.js +57 -0
- package/esm/byte-entity-shim.d.ts +47 -0
- package/esm/byte-entity-shim.d.ts.map +1 -0
- package/esm/byte-entity-shim.js +138 -0
- package/esm/clients/mod.d.ts +15 -0
- package/esm/clients/mod.d.ts.map +1 -0
- package/esm/clients/mod.js +14 -0
- package/esm/clients/save-client.d.ts +87 -0
- package/esm/clients/save-client.d.ts.map +1 -0
- package/esm/clients/save-client.js +174 -0
- package/esm/deps/jsr.io/@bandeira-tech/b3nd-core/0.22.0/mod.d.ts +40 -0
- package/esm/deps/jsr.io/@bandeira-tech/b3nd-core/0.22.0/mod.d.ts.map +1 -0
- package/esm/deps/jsr.io/@bandeira-tech/b3nd-core/0.22.0/mod.js +31 -0
- package/esm/deps/jsr.io/@bandeira-tech/b3nd-core/0.22.0/src/client-console/client.d.ts +30 -0
- package/esm/deps/jsr.io/@bandeira-tech/b3nd-core/0.22.0/src/client-console/client.d.ts.map +1 -0
- package/esm/deps/jsr.io/@bandeira-tech/b3nd-core/0.22.0/src/client-console/client.js +70 -0
- package/esm/deps/jsr.io/@bandeira-tech/b3nd-core/0.22.0/src/encoding/encoding.d.ts +16 -0
- package/esm/deps/jsr.io/@bandeira-tech/b3nd-core/0.22.0/src/encoding/encoding.d.ts.map +1 -0
- package/esm/deps/jsr.io/@bandeira-tech/b3nd-core/0.22.0/src/encoding/encoding.js +50 -0
- package/esm/deps/jsr.io/@bandeira-tech/b3nd-core/0.22.0/src/encrypt/mod.d.ts +235 -0
- package/esm/deps/jsr.io/@bandeira-tech/b3nd-core/0.22.0/src/encrypt/mod.d.ts.map +1 -0
- package/esm/deps/jsr.io/@bandeira-tech/b3nd-core/0.22.0/src/encrypt/mod.js +619 -0
- package/esm/deps/jsr.io/@bandeira-tech/b3nd-core/0.22.0/src/functional-client/functional-client.d.ts +43 -0
- package/esm/deps/jsr.io/@bandeira-tech/b3nd-core/0.22.0/src/functional-client/functional-client.d.ts.map +1 -0
- package/esm/deps/jsr.io/@bandeira-tech/b3nd-core/0.22.0/src/functional-client/functional-client.js +54 -0
- package/esm/deps/jsr.io/@bandeira-tech/b3nd-core/0.22.0/src/match-pattern/match-pattern.d.ts +47 -0
- package/esm/deps/jsr.io/@bandeira-tech/b3nd-core/0.22.0/src/match-pattern/match-pattern.d.ts.map +1 -0
- package/esm/deps/jsr.io/@bandeira-tech/b3nd-core/0.22.0/src/match-pattern/match-pattern.js +134 -0
- package/esm/deps/jsr.io/@bandeira-tech/b3nd-core/0.22.0/src/network/decorators.d.ts +20 -0
- package/esm/deps/jsr.io/@bandeira-tech/b3nd-core/0.22.0/src/network/decorators.d.ts.map +1 -0
- package/esm/deps/jsr.io/@bandeira-tech/b3nd-core/0.22.0/src/network/decorators.js +34 -0
- package/esm/deps/jsr.io/@bandeira-tech/b3nd-core/0.22.0/src/network/network.d.ts +46 -0
- package/esm/deps/jsr.io/@bandeira-tech/b3nd-core/0.22.0/src/network/network.d.ts.map +1 -0
- package/esm/deps/jsr.io/@bandeira-tech/b3nd-core/0.22.0/src/network/network.js +131 -0
- package/esm/deps/jsr.io/@bandeira-tech/b3nd-core/0.22.0/src/network/peer.d.ts +27 -0
- package/esm/deps/jsr.io/@bandeira-tech/b3nd-core/0.22.0/src/network/peer.d.ts.map +1 -0
- package/esm/deps/jsr.io/@bandeira-tech/b3nd-core/0.22.0/src/network/peer.js +25 -0
- package/esm/deps/jsr.io/@bandeira-tech/b3nd-core/0.22.0/src/network/policies/flood.d.ts +59 -0
- package/esm/deps/jsr.io/@bandeira-tech/b3nd-core/0.22.0/src/network/policies/flood.d.ts.map +1 -0
- package/esm/deps/jsr.io/@bandeira-tech/b3nd-core/0.22.0/src/network/policies/flood.js +188 -0
- package/esm/deps/jsr.io/@bandeira-tech/b3nd-core/0.22.0/src/network/policies/path-vector.d.ts +35 -0
- package/esm/deps/jsr.io/@bandeira-tech/b3nd-core/0.22.0/src/network/policies/path-vector.d.ts.map +1 -0
- package/esm/deps/jsr.io/@bandeira-tech/b3nd-core/0.22.0/src/network/policies/path-vector.js +57 -0
- package/esm/deps/jsr.io/@bandeira-tech/b3nd-core/0.22.0/src/network/policies/tell-and-read.d.ts +117 -0
- package/esm/deps/jsr.io/@bandeira-tech/b3nd-core/0.22.0/src/network/policies/tell-and-read.d.ts.map +1 -0
- package/esm/deps/jsr.io/@bandeira-tech/b3nd-core/0.22.0/src/network/policies/tell-and-read.js +125 -0
- package/esm/deps/jsr.io/@bandeira-tech/b3nd-core/0.22.0/src/network/types.d.ts +112 -0
- package/esm/deps/jsr.io/@bandeira-tech/b3nd-core/0.22.0/src/network/types.d.ts.map +1 -0
- package/esm/deps/jsr.io/@bandeira-tech/b3nd-core/0.22.0/src/network/types.js +21 -0
- package/esm/deps/jsr.io/@bandeira-tech/b3nd-core/0.22.0/src/observe-emitter/observe-emitter.d.ts +35 -0
- package/esm/deps/jsr.io/@bandeira-tech/b3nd-core/0.22.0/src/observe-emitter/observe-emitter.d.ts.map +1 -0
- package/esm/deps/jsr.io/@bandeira-tech/b3nd-core/0.22.0/src/observe-emitter/observe-emitter.js +106 -0
- package/esm/deps/jsr.io/@bandeira-tech/b3nd-core/0.22.0/src/rig/connection.d.ts +88 -0
- package/esm/deps/jsr.io/@bandeira-tech/b3nd-core/0.22.0/src/rig/connection.d.ts.map +1 -0
- package/esm/deps/jsr.io/@bandeira-tech/b3nd-core/0.22.0/src/rig/connection.js +86 -0
- package/esm/deps/jsr.io/@bandeira-tech/b3nd-core/0.22.0/src/rig/events.d.ts +83 -0
- package/esm/deps/jsr.io/@bandeira-tech/b3nd-core/0.22.0/src/rig/events.d.ts.map +1 -0
- package/esm/deps/jsr.io/@bandeira-tech/b3nd-core/0.22.0/src/rig/events.js +115 -0
- package/esm/deps/jsr.io/@bandeira-tech/b3nd-core/0.22.0/src/rig/hooks.d.ts +164 -0
- package/esm/deps/jsr.io/@bandeira-tech/b3nd-core/0.22.0/src/rig/hooks.d.ts.map +1 -0
- package/esm/deps/jsr.io/@bandeira-tech/b3nd-core/0.22.0/src/rig/hooks.js +67 -0
- package/esm/deps/jsr.io/@bandeira-tech/b3nd-core/0.22.0/src/rig/identity.d.ts +99 -0
- package/esm/deps/jsr.io/@bandeira-tech/b3nd-core/0.22.0/src/rig/identity.d.ts.map +1 -0
- package/esm/deps/jsr.io/@bandeira-tech/b3nd-core/0.22.0/src/rig/identity.js +190 -0
- package/esm/deps/jsr.io/@bandeira-tech/b3nd-core/0.22.0/src/rig/operation-handle.d.ts +185 -0
- package/esm/deps/jsr.io/@bandeira-tech/b3nd-core/0.22.0/src/rig/operation-handle.d.ts.map +1 -0
- package/esm/deps/jsr.io/@bandeira-tech/b3nd-core/0.22.0/src/rig/operation-handle.js +103 -0
- package/esm/deps/jsr.io/@bandeira-tech/b3nd-core/0.22.0/src/rig/reactions.d.ts +58 -0
- package/esm/deps/jsr.io/@bandeira-tech/b3nd-core/0.22.0/src/rig/reactions.d.ts.map +1 -0
- package/esm/deps/jsr.io/@bandeira-tech/b3nd-core/0.22.0/src/rig/reactions.js +64 -0
- package/esm/deps/jsr.io/@bandeira-tech/b3nd-core/0.22.0/src/rig/rig.d.ts +295 -0
- package/esm/deps/jsr.io/@bandeira-tech/b3nd-core/0.22.0/src/rig/rig.d.ts.map +1 -0
- package/esm/deps/jsr.io/@bandeira-tech/b3nd-core/0.22.0/src/rig/rig.js +898 -0
- package/esm/deps/jsr.io/@bandeira-tech/b3nd-core/0.22.0/src/rig/types.d.ts +167 -0
- package/esm/deps/jsr.io/@bandeira-tech/b3nd-core/0.22.0/src/rig/types.d.ts.map +1 -0
- package/esm/deps/jsr.io/@bandeira-tech/b3nd-core/0.22.0/src/rig/types.js +5 -0
- package/esm/deps/jsr.io/@bandeira-tech/b3nd-core/0.22.0/src/types/types.d.ts +278 -0
- package/esm/deps/jsr.io/@bandeira-tech/b3nd-core/0.22.0/src/types/types.d.ts.map +1 -0
- package/esm/deps/jsr.io/@bandeira-tech/b3nd-core/0.22.0/src/types/types.js +89 -0
- package/esm/dispatch.d.ts +35 -0
- package/esm/dispatch.d.ts.map +1 -0
- package/esm/dispatch.js +40 -0
- package/esm/elasticsearch/mod.d.ts +31 -0
- package/esm/elasticsearch/mod.d.ts.map +1 -0
- package/esm/elasticsearch/mod.js +8 -0
- package/esm/elasticsearch/store.d.ts +44 -0
- package/esm/elasticsearch/store.d.ts.map +1 -0
- package/esm/elasticsearch/store.js +213 -0
- package/esm/entity-store.d.ts +106 -0
- package/esm/entity-store.d.ts.map +1 -0
- package/esm/entity-store.js +46 -0
- package/esm/entity.d.ts +125 -0
- package/esm/entity.d.ts.map +1 -0
- package/esm/entity.js +66 -0
- package/esm/errors.d.ts +23 -0
- package/esm/errors.d.ts.map +1 -0
- package/esm/errors.js +25 -0
- package/esm/fs/mod.d.ts +28 -0
- package/esm/fs/mod.d.ts.map +1 -0
- package/esm/fs/mod.js +13 -0
- package/esm/fs/store.d.ts +45 -0
- package/esm/fs/store.d.ts.map +1 -0
- package/esm/fs/store.js +194 -0
- package/esm/indexeddb/mod.d.ts +9 -0
- package/esm/indexeddb/mod.d.ts.map +1 -0
- package/esm/indexeddb/mod.js +8 -0
- package/esm/indexeddb/store.d.ts +47 -0
- package/esm/indexeddb/store.d.ts.map +1 -0
- package/esm/indexeddb/store.js +299 -0
- package/esm/ipfs/mod.d.ts +24 -0
- package/esm/ipfs/mod.d.ts.map +1 -0
- package/esm/ipfs/mod.js +13 -0
- package/esm/ipfs/store.d.ts +42 -0
- package/esm/ipfs/store.d.ts.map +1 -0
- package/esm/ipfs/store.js +197 -0
- package/esm/localstorage/mod.d.ts +9 -0
- package/esm/localstorage/mod.d.ts.map +1 -0
- package/esm/localstorage/mod.js +8 -0
- package/esm/localstorage/store.d.ts +45 -0
- package/esm/localstorage/store.d.ts.map +1 -0
- package/esm/localstorage/store.js +147 -0
- package/esm/memory/mod.d.ts +12 -0
- package/esm/memory/mod.d.ts.map +1 -0
- package/esm/memory/mod.js +11 -0
- package/esm/memory/store.d.ts +73 -0
- package/esm/memory/store.d.ts.map +1 -0
- package/esm/memory/store.js +300 -0
- package/esm/mod.d.ts +36 -0
- package/esm/mod.d.ts.map +1 -0
- package/esm/mod.js +31 -0
- package/esm/mongo/mod.d.ts +35 -0
- package/esm/mongo/mod.d.ts.map +1 -0
- package/esm/mongo/mod.js +8 -0
- package/esm/mongo/store.d.ts +42 -0
- package/esm/mongo/store.d.ts.map +1 -0
- package/esm/mongo/store.js +185 -0
- package/esm/package.json +3 -0
- package/esm/payload.d.ts +24 -0
- package/esm/payload.d.ts.map +1 -0
- package/esm/payload.js +30 -0
- package/esm/postgres/columns.d.ts +33 -0
- package/esm/postgres/columns.d.ts.map +1 -0
- package/esm/postgres/columns.js +51 -0
- package/esm/postgres/mod.d.ts +19 -0
- package/esm/postgres/mod.d.ts.map +1 -0
- package/esm/postgres/mod.js +9 -0
- package/esm/postgres/store.d.ts +75 -0
- package/esm/postgres/store.d.ts.map +1 -0
- package/esm/postgres/store.js +364 -0
- package/esm/read.d.ts +40 -0
- package/esm/read.d.ts.map +1 -0
- package/esm/read.js +67 -0
- package/esm/s3/mod.d.ts +23 -0
- package/esm/s3/mod.d.ts.map +1 -0
- package/esm/s3/mod.js +13 -0
- package/esm/s3/store.d.ts +46 -0
- package/esm/s3/store.d.ts.map +1 -0
- package/esm/s3/store.js +183 -0
- package/esm/sqlite/mod.d.ts +18 -0
- package/esm/sqlite/mod.d.ts.map +1 -0
- package/esm/sqlite/mod.js +8 -0
- package/esm/sqlite/schema.d.ts +10 -0
- package/esm/sqlite/schema.d.ts.map +1 -0
- package/esm/sqlite/schema.js +26 -0
- package/esm/sqlite/store.d.ts +42 -0
- package/esm/sqlite/store.d.ts.map +1 -0
- package/esm/sqlite/store.js +184 -0
- package/esm/types.d.ts +101 -0
- package/esm/types.d.ts.map +1 -0
- package/esm/types.js +21 -0
- package/esm/url.d.ts +108 -0
- package/esm/url.d.ts.map +1 -0
- package/esm/url.js +151 -0
- package/package.json +93 -0
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module
|
|
3
|
+
* Operation handles — the return value of `rig.receive()` / `rig.send()`.
|
|
4
|
+
*
|
|
5
|
+
* An OperationHandle is BOTH:
|
|
6
|
+
* - a `Promise<ReceiveResult[]>` (the pipeline-stage acknowledgment;
|
|
7
|
+
* resolves once `process` + `handle` finish for every input tuple),
|
|
8
|
+
* - and a scoped event emitter that fires per-stage events for THIS
|
|
9
|
+
* operation as it progresses (`process:done`, `handle:emit`,
|
|
10
|
+
* `route:success`, `route:error`, `settled`).
|
|
11
|
+
*
|
|
12
|
+
* Why both shapes:
|
|
13
|
+
* - Awaitable so existing callers (`await rig.receive(outs)`) and
|
|
14
|
+
* `ProtocolInterfaceNode.receive` consumers see no contract change.
|
|
15
|
+
* - Observable so callers who care about per-stage detail or per-route
|
|
16
|
+
* dispatch outcomes can subscribe inline, without correlation IDs
|
|
17
|
+
* or filtering global rig events.
|
|
18
|
+
*
|
|
19
|
+
* Single paper-trail: the events are the source of truth. The result
|
|
20
|
+
* the await resolves to (`ReceiveResult[]`) is the small pipeline-level
|
|
21
|
+
* ack; everything richer flows through events.
|
|
22
|
+
*
|
|
23
|
+
* Dispatch is async by design: `await op` resolves once the pipeline
|
|
24
|
+
* decides what to dispatch, but the broadcast itself runs in the
|
|
25
|
+
* background. Per-route events fire after the await has returned.
|
|
26
|
+
* Callers that need full settlement await `op.settled` (a Promise that
|
|
27
|
+
* resolves on the `settled` event).
|
|
28
|
+
*/
|
|
29
|
+
import type { B3ndError, Output, ProgramResult, ReceiveResult } from "../types/types.js";
|
|
30
|
+
/** Emitted once `process()` produces a classification for one input tuple. */
|
|
31
|
+
export interface ProcessDoneEvent {
|
|
32
|
+
/** The input tuple being classified. */
|
|
33
|
+
input: Output;
|
|
34
|
+
/** The classification produced by `process()`. */
|
|
35
|
+
result: ProgramResult;
|
|
36
|
+
}
|
|
37
|
+
/** Emitted when `process()` throws or a program returns an error code. */
|
|
38
|
+
export interface ProcessErrorEvent {
|
|
39
|
+
/** The input tuple whose classification failed. */
|
|
40
|
+
input: Output;
|
|
41
|
+
/** Error message. */
|
|
42
|
+
error: string;
|
|
43
|
+
/** Structured error info, when available. */
|
|
44
|
+
errorDetail?: B3ndError;
|
|
45
|
+
/** The original thrown value (if `process()` threw). */
|
|
46
|
+
cause?: unknown;
|
|
47
|
+
}
|
|
48
|
+
/** Emitted once `handle()` returns its emissions for one classified tuple. */
|
|
49
|
+
export interface HandleEmitEvent {
|
|
50
|
+
/** The input tuple that was handled. */
|
|
51
|
+
input: Output;
|
|
52
|
+
/** The classification that was passed to `handle()`. */
|
|
53
|
+
classification: ProgramResult;
|
|
54
|
+
/** What the handler returned — the tuples to dispatch. */
|
|
55
|
+
emissions: Output[];
|
|
56
|
+
}
|
|
57
|
+
/** Emitted when `handle()` throws while processing one classified tuple. */
|
|
58
|
+
export interface HandleErrorEvent {
|
|
59
|
+
/** The input tuple that was handled. */
|
|
60
|
+
input: Output;
|
|
61
|
+
/** The classification that was passed to `handle()`. */
|
|
62
|
+
classification: ProgramResult;
|
|
63
|
+
/** Error message. */
|
|
64
|
+
error: string;
|
|
65
|
+
/** The original thrown value. */
|
|
66
|
+
cause?: unknown;
|
|
67
|
+
}
|
|
68
|
+
/** Emitted when a registered reaction throws while running. */
|
|
69
|
+
export interface ReactionErrorEvent {
|
|
70
|
+
/** The emission whose URI matched the reaction's pattern. */
|
|
71
|
+
emission: Output;
|
|
72
|
+
/** The reaction's URI pattern. */
|
|
73
|
+
pattern: string;
|
|
74
|
+
/** Error message. */
|
|
75
|
+
error: string;
|
|
76
|
+
/** The original thrown value. */
|
|
77
|
+
cause?: unknown;
|
|
78
|
+
}
|
|
79
|
+
/** Emitted when a single connection accepts a single emission. */
|
|
80
|
+
export interface RouteSuccessEvent {
|
|
81
|
+
/** The tuple that was dispatched. */
|
|
82
|
+
emission: Output;
|
|
83
|
+
/** Stable ID of the connection that accepted. */
|
|
84
|
+
connectionId: string;
|
|
85
|
+
}
|
|
86
|
+
/** Emitted when a single connection rejects a single emission. */
|
|
87
|
+
export interface RouteErrorEvent {
|
|
88
|
+
/** The tuple that was dispatched. */
|
|
89
|
+
emission: Output;
|
|
90
|
+
/** Stable ID of the connection that rejected. */
|
|
91
|
+
connectionId: string;
|
|
92
|
+
/** Error message. */
|
|
93
|
+
error?: string;
|
|
94
|
+
/** Structured error info, when available. */
|
|
95
|
+
errorDetail?: B3ndError;
|
|
96
|
+
}
|
|
97
|
+
/** Emitted once after the operation's last route has settled. */
|
|
98
|
+
export interface SettledEvent {
|
|
99
|
+
/** The pipeline-stage results returned by the await. */
|
|
100
|
+
results: ReceiveResult[];
|
|
101
|
+
}
|
|
102
|
+
/** Names of events the OperationHandle fires. */
|
|
103
|
+
export type OperationEventName = "process:done" | "process:error" | "handle:emit" | "handle:error" | "route:success" | "route:error" | "reaction:error" | "settled";
|
|
104
|
+
/** Map from event name to payload type. */
|
|
105
|
+
export interface OperationEventMap {
|
|
106
|
+
"process:done": ProcessDoneEvent;
|
|
107
|
+
"process:error": ProcessErrorEvent;
|
|
108
|
+
"handle:emit": HandleEmitEvent;
|
|
109
|
+
"handle:error": HandleErrorEvent;
|
|
110
|
+
"route:success": RouteSuccessEvent;
|
|
111
|
+
"route:error": RouteErrorEvent;
|
|
112
|
+
"reaction:error": ReactionErrorEvent;
|
|
113
|
+
"settled": SettledEvent;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Generic event handler. Return value is ignored, but accepting any
|
|
117
|
+
* type lets handler bodies use expression-style arrow functions —
|
|
118
|
+
* `op.on("route:success", e => log.push(e.emission[0]))` — without
|
|
119
|
+
* TS yelling about the return type.
|
|
120
|
+
*/
|
|
121
|
+
export type OperationEventHandler<E extends OperationEventName> = (event: OperationEventMap[E]) => unknown;
|
|
122
|
+
/**
|
|
123
|
+
* Promise + scoped event emitter for one rig.receive / rig.send call.
|
|
124
|
+
*
|
|
125
|
+
* Awaiting the handle resolves to the pipeline-stage `ReceiveResult[]`
|
|
126
|
+
* (one per input tuple). Subscribing to the handle observes per-stage
|
|
127
|
+
* events scoped to this operation only.
|
|
128
|
+
*
|
|
129
|
+
* Construction is internal — the Rig builds the handle, exposes it to
|
|
130
|
+
* the caller, and drives its lifecycle via the helper methods on the
|
|
131
|
+
* implementation class.
|
|
132
|
+
*/
|
|
133
|
+
export interface OperationHandle extends PromiseLike<ReceiveResult[]> {
|
|
134
|
+
/**
|
|
135
|
+
* Subscribe to an event scoped to this operation.
|
|
136
|
+
* Returns an unsubscribe function.
|
|
137
|
+
*/
|
|
138
|
+
on<E extends OperationEventName>(event: E, handler: OperationEventHandler<E>): () => void;
|
|
139
|
+
/** Remove a previously-registered handler. */
|
|
140
|
+
off<E extends OperationEventName>(event: E, handler: OperationEventHandler<E>): void;
|
|
141
|
+
/**
|
|
142
|
+
* Convenience Promise that resolves once the `settled` event fires —
|
|
143
|
+
* i.e., every dispatched route has settled. Useful for callers who
|
|
144
|
+
* need read-after-write semantics across replicas:
|
|
145
|
+
*
|
|
146
|
+
* ```ts
|
|
147
|
+
* const op = rig.send([out]);
|
|
148
|
+
* await op; // pipeline ack
|
|
149
|
+
* await op.settled; // wait for all routes
|
|
150
|
+
* const data = await rig.read(out[0]);
|
|
151
|
+
* ```
|
|
152
|
+
*
|
|
153
|
+
* The same outcome is observable via `op.on("settled", …)`. This
|
|
154
|
+
* accessor exists for the common await-then-read pattern.
|
|
155
|
+
*/
|
|
156
|
+
readonly settled: Promise<SettledEvent>;
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Internal implementation. The Rig drives this via the `_pipelineDone`
|
|
160
|
+
* and `_emit` methods; callers see the `OperationHandle` interface.
|
|
161
|
+
*/
|
|
162
|
+
export declare class OperationHandleImpl implements OperationHandle {
|
|
163
|
+
private _listeners;
|
|
164
|
+
private _pipelinePromise;
|
|
165
|
+
private _resolvePipeline;
|
|
166
|
+
private _rejectPipeline;
|
|
167
|
+
private _settledPromise;
|
|
168
|
+
private _resolveSettled;
|
|
169
|
+
constructor();
|
|
170
|
+
/** Resolve the pipeline-stage promise. */
|
|
171
|
+
_pipelineDone(results: ReceiveResult[]): void;
|
|
172
|
+
/** Reject the pipeline-stage promise (a hook threw, etc.). */
|
|
173
|
+
_pipelineError(err: unknown): void;
|
|
174
|
+
/**
|
|
175
|
+
* Emit a scoped event. Handlers run fire-and-forget; errors caught
|
|
176
|
+
* and logged so a misbehaving handler can't break the operation.
|
|
177
|
+
* The `settled` event also resolves the `settled` promise.
|
|
178
|
+
*/
|
|
179
|
+
_emit<E extends OperationEventName>(event: E, payload: OperationEventMap[E]): void;
|
|
180
|
+
on<E extends OperationEventName>(event: E, handler: OperationEventHandler<E>): () => void;
|
|
181
|
+
off<E extends OperationEventName>(event: E, handler: OperationEventHandler<E>): void;
|
|
182
|
+
get settled(): Promise<SettledEvent>;
|
|
183
|
+
then<TResult1 = ReceiveResult[], TResult2 = never>(onfulfilled?: ((value: ReceiveResult[]) => TResult1 | PromiseLike<TResult1>) | null | undefined, onrejected?: ((reason: unknown) => TResult2 | PromiseLike<TResult2>) | null | undefined): PromiseLike<TResult1 | TResult2>;
|
|
184
|
+
}
|
|
185
|
+
//# sourceMappingURL=operation-handle.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"operation-handle.d.ts","sourceRoot":"","sources":["../../../../../../../../src/deps/jsr.io/@bandeira-tech/b3nd-core/0.22.0/src/rig/operation-handle.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEH,OAAO,KAAK,EACV,SAAS,EACT,MAAM,EACN,aAAa,EACb,aAAa,EACd,MAAM,mBAAmB,CAAC;AAI3B,8EAA8E;AAC9E,MAAM,WAAW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
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module
|
|
3
|
+
* Operation handles — the return value of `rig.receive()` / `rig.send()`.
|
|
4
|
+
*
|
|
5
|
+
* An OperationHandle is BOTH:
|
|
6
|
+
* - a `Promise<ReceiveResult[]>` (the pipeline-stage acknowledgment;
|
|
7
|
+
* resolves once `process` + `handle` finish for every input tuple),
|
|
8
|
+
* - and a scoped event emitter that fires per-stage events for THIS
|
|
9
|
+
* operation as it progresses (`process:done`, `handle:emit`,
|
|
10
|
+
* `route:success`, `route:error`, `settled`).
|
|
11
|
+
*
|
|
12
|
+
* Why both shapes:
|
|
13
|
+
* - Awaitable so existing callers (`await rig.receive(outs)`) and
|
|
14
|
+
* `ProtocolInterfaceNode.receive` consumers see no contract change.
|
|
15
|
+
* - Observable so callers who care about per-stage detail or per-route
|
|
16
|
+
* dispatch outcomes can subscribe inline, without correlation IDs
|
|
17
|
+
* or filtering global rig events.
|
|
18
|
+
*
|
|
19
|
+
* Single paper-trail: the events are the source of truth. The result
|
|
20
|
+
* the await resolves to (`ReceiveResult[]`) is the small pipeline-level
|
|
21
|
+
* ack; everything richer flows through events.
|
|
22
|
+
*
|
|
23
|
+
* Dispatch is async by design: `await op` resolves once the pipeline
|
|
24
|
+
* decides what to dispatch, but the broadcast itself runs in the
|
|
25
|
+
* background. Per-route events fire after the await has returned.
|
|
26
|
+
* Callers that need full settlement await `op.settled` (a Promise that
|
|
27
|
+
* resolves on the `settled` event).
|
|
28
|
+
*/
|
|
29
|
+
/**
|
|
30
|
+
* Internal implementation. The Rig drives this via the `_pipelineDone`
|
|
31
|
+
* and `_emit` methods; callers see the `OperationHandle` interface.
|
|
32
|
+
*/
|
|
33
|
+
export class OperationHandleImpl {
|
|
34
|
+
_listeners = [];
|
|
35
|
+
_pipelinePromise;
|
|
36
|
+
_resolvePipeline;
|
|
37
|
+
_rejectPipeline;
|
|
38
|
+
_settledPromise;
|
|
39
|
+
_resolveSettled;
|
|
40
|
+
constructor() {
|
|
41
|
+
this._pipelinePromise = new Promise((resolve, reject) => {
|
|
42
|
+
this._resolvePipeline = resolve;
|
|
43
|
+
this._rejectPipeline = reject;
|
|
44
|
+
});
|
|
45
|
+
this._settledPromise = new Promise((resolve) => {
|
|
46
|
+
this._resolveSettled = resolve;
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
// ── Internal driver methods (called by the Rig) ──
|
|
50
|
+
/** Resolve the pipeline-stage promise. */
|
|
51
|
+
_pipelineDone(results) {
|
|
52
|
+
this._resolvePipeline(results);
|
|
53
|
+
}
|
|
54
|
+
/** Reject the pipeline-stage promise (a hook threw, etc.). */
|
|
55
|
+
_pipelineError(err) {
|
|
56
|
+
this._rejectPipeline(err);
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Emit a scoped event. Handlers run fire-and-forget; errors caught
|
|
60
|
+
* and logged so a misbehaving handler can't break the operation.
|
|
61
|
+
* The `settled` event also resolves the `settled` promise.
|
|
62
|
+
*/
|
|
63
|
+
_emit(event, payload) {
|
|
64
|
+
// Schedule handler microtasks BEFORE resolving the settled promise.
|
|
65
|
+
// Microtask order is FIFO, so handlers' microtasks run before any
|
|
66
|
+
// `await op.settled` continuation. This matters for tests/callers
|
|
67
|
+
// that subscribe to `settled` and inspect state right after
|
|
68
|
+
// awaiting `op.settled`.
|
|
69
|
+
for (const entry of this._listeners) {
|
|
70
|
+
if (entry.event !== event)
|
|
71
|
+
continue;
|
|
72
|
+
Promise.resolve()
|
|
73
|
+
.then(() => entry.handler(payload))
|
|
74
|
+
.catch((err) => {
|
|
75
|
+
console.warn(`[rig] operation listener error on "${event}":`, err);
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
if (event === "settled") {
|
|
79
|
+
this._resolveSettled(payload);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
// ── Public OperationHandle interface ──
|
|
83
|
+
on(event, handler) {
|
|
84
|
+
const entry = {
|
|
85
|
+
event,
|
|
86
|
+
handler: handler,
|
|
87
|
+
};
|
|
88
|
+
this._listeners.push(entry);
|
|
89
|
+
return () => this.off(event, handler);
|
|
90
|
+
}
|
|
91
|
+
off(event, handler) {
|
|
92
|
+
const idx = this._listeners.findIndex((e) => e.event === event && e.handler === handler);
|
|
93
|
+
if (idx >= 0)
|
|
94
|
+
this._listeners.splice(idx, 1);
|
|
95
|
+
}
|
|
96
|
+
get settled() {
|
|
97
|
+
return this._settledPromise;
|
|
98
|
+
}
|
|
99
|
+
// PromiseLike implementation — delegates to the pipeline promise.
|
|
100
|
+
then(onfulfilled, onrejected) {
|
|
101
|
+
return this._pipelinePromise.then(onfulfilled, onrejected);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module
|
|
3
|
+
* Reaction registry for the Rig.
|
|
4
|
+
*
|
|
5
|
+
* Reactions fire on successfully dispatched outputs (via send/receive)
|
|
6
|
+
* whose URI matches a registered pattern. Patterns use the shared glob
|
|
7
|
+
* grammar (`*` for one segment, `**` for the rest).
|
|
8
|
+
*
|
|
9
|
+
* Reactions are pure: they take the dispatched output and a `read`
|
|
10
|
+
* function and return `Output[]`. The Rig feeds those returned tuples
|
|
11
|
+
* back through `rig.send` (full pipeline — programs run, handlers run,
|
|
12
|
+
* more reactions can fire).
|
|
13
|
+
*
|
|
14
|
+
* Reactions receive only the dispatched output; if a handler needs a
|
|
15
|
+
* segment value, it extracts it from the URI directly.
|
|
16
|
+
*
|
|
17
|
+
* Pure module — no Rig dependency, testable in isolation.
|
|
18
|
+
*/
|
|
19
|
+
import type { Output, ReadFn } from "../types/types.js";
|
|
20
|
+
/**
|
|
21
|
+
* Reaction handler — called when a dispatched URI matches the pattern.
|
|
22
|
+
*
|
|
23
|
+
* Receives the dispatched output and a read function. Returns the tuples
|
|
24
|
+
* the Rig should put on the wire as a consequence of what the reaction
|
|
25
|
+
* observed; those flow through full `rig.send` (programs + handlers +
|
|
26
|
+
* more reactions).
|
|
27
|
+
*
|
|
28
|
+
* Returning `[]` means "I observed it but emit nothing further."
|
|
29
|
+
*/
|
|
30
|
+
export type Reaction = (out: Output, read: ReadFn) => Promise<Output[]>;
|
|
31
|
+
/** @deprecated alias kept for migration; prefer `Reaction`. */
|
|
32
|
+
export type ReactionHandler = Reaction;
|
|
33
|
+
/**
|
|
34
|
+
* Registry of URI-pattern-matched reaction handlers.
|
|
35
|
+
*
|
|
36
|
+
* Use `match()` to find matching reactions for a dispatched URI; the
|
|
37
|
+
* caller (the Rig) is responsible for invoking each reaction and
|
|
38
|
+
* routing its returned tuples back through the pipeline.
|
|
39
|
+
*/
|
|
40
|
+
export declare class ReactionRegistry {
|
|
41
|
+
private entries;
|
|
42
|
+
/**
|
|
43
|
+
* Register a reaction handler for a URI pattern.
|
|
44
|
+
* Returns an unsubscribe function.
|
|
45
|
+
*/
|
|
46
|
+
add(pattern: string, handler: Reaction): () => void;
|
|
47
|
+
/**
|
|
48
|
+
* Find every reaction whose pattern matches `uri`. Returns the list
|
|
49
|
+
* of `(pattern, handler)` pairs the caller can invoke.
|
|
50
|
+
*/
|
|
51
|
+
matches(uri: string): {
|
|
52
|
+
pattern: string;
|
|
53
|
+
handler: Reaction;
|
|
54
|
+
}[];
|
|
55
|
+
/** Whether any patterns are registered. */
|
|
56
|
+
get size(): number;
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=reactions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reactions.d.ts","sourceRoot":"","sources":["../../../../../../../../src/deps/jsr.io/@bandeira-tech/b3nd-core/0.22.0/src/rig/reactions.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAMH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAIxD;;;;;;;;;GASG;AACH,MAAM,MAAM,QAAQ,GAAG,CACrB,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,MAAM,KACT,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;AAEvB,+DAA+D;AAC/D,MAAM,MAAM,eAAe,GAAG,QAAQ,CAAC;AAavC;;;;;;GAMG;AACH,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,OAAO,CAAuB;IAEtC;;;OAGG;IACH,GAAG,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,QAAQ,GAAG,MAAM,IAAI;IAanD;;;OAGG;IACH,OAAO,CACL,GAAG,EAAE,MAAM,GACV;QACD,OAAO,EAAE,MAAM,CAAC;QAChB,OAAO,EAAE,QAAQ,CAAC;KACnB,EAAE;IAUH,2CAA2C;IAC3C,IAAI,IAAI,IAAI,MAAM,CAEjB;CACF"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module
|
|
3
|
+
* Reaction registry for the Rig.
|
|
4
|
+
*
|
|
5
|
+
* Reactions fire on successfully dispatched outputs (via send/receive)
|
|
6
|
+
* whose URI matches a registered pattern. Patterns use the shared glob
|
|
7
|
+
* grammar (`*` for one segment, `**` for the rest).
|
|
8
|
+
*
|
|
9
|
+
* Reactions are pure: they take the dispatched output and a `read`
|
|
10
|
+
* function and return `Output[]`. The Rig feeds those returned tuples
|
|
11
|
+
* back through `rig.send` (full pipeline — programs run, handlers run,
|
|
12
|
+
* more reactions can fire).
|
|
13
|
+
*
|
|
14
|
+
* Reactions receive only the dispatched output; if a handler needs a
|
|
15
|
+
* segment value, it extracts it from the URI directly.
|
|
16
|
+
*
|
|
17
|
+
* Pure module — no Rig dependency, testable in isolation.
|
|
18
|
+
*/
|
|
19
|
+
import { compilePattern, } from "../match-pattern/match-pattern.js";
|
|
20
|
+
// ── Registry ──
|
|
21
|
+
/**
|
|
22
|
+
* Registry of URI-pattern-matched reaction handlers.
|
|
23
|
+
*
|
|
24
|
+
* Use `match()` to find matching reactions for a dispatched URI; the
|
|
25
|
+
* caller (the Rig) is responsible for invoking each reaction and
|
|
26
|
+
* routing its returned tuples back through the pipeline.
|
|
27
|
+
*/
|
|
28
|
+
export class ReactionRegistry {
|
|
29
|
+
entries = [];
|
|
30
|
+
/**
|
|
31
|
+
* Register a reaction handler for a URI pattern.
|
|
32
|
+
* Returns an unsubscribe function.
|
|
33
|
+
*/
|
|
34
|
+
add(pattern, handler) {
|
|
35
|
+
const entry = {
|
|
36
|
+
pattern,
|
|
37
|
+
matcher: compilePattern(pattern),
|
|
38
|
+
handler,
|
|
39
|
+
};
|
|
40
|
+
this.entries.push(entry);
|
|
41
|
+
return () => {
|
|
42
|
+
const idx = this.entries.indexOf(entry);
|
|
43
|
+
if (idx >= 0)
|
|
44
|
+
this.entries.splice(idx, 1);
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Find every reaction whose pattern matches `uri`. Returns the list
|
|
49
|
+
* of `(pattern, handler)` pairs the caller can invoke.
|
|
50
|
+
*/
|
|
51
|
+
matches(uri) {
|
|
52
|
+
const out = [];
|
|
53
|
+
for (const entry of this.entries) {
|
|
54
|
+
if (entry.matcher(uri)) {
|
|
55
|
+
out.push({ pattern: entry.pattern, handler: entry.handler });
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return out;
|
|
59
|
+
}
|
|
60
|
+
/** Whether any patterns are registered. */
|
|
61
|
+
get size() {
|
|
62
|
+
return this.entries.length;
|
|
63
|
+
}
|
|
64
|
+
}
|