@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,295 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module
|
|
3
|
+
* Rig — the universal harness for b3nd.
|
|
4
|
+
*
|
|
5
|
+
* Single object that wires up backends, identity, and serving.
|
|
6
|
+
* Two core actions: send (outward to the network) and receive
|
|
7
|
+
* (inward from external sources). Everything else is observation.
|
|
8
|
+
*
|
|
9
|
+
* Supports per-operation client routing, synchronous hooks
|
|
10
|
+
* (pre/post), async events, and URI-pattern reactions.
|
|
11
|
+
*/
|
|
12
|
+
import type { Output, ProgramResult, ProtocolInterfaceNode, ReceiveResult, StatusResult } from "../types/types.js";
|
|
13
|
+
import type { RigConfig, RigInfo } from "./types.js";
|
|
14
|
+
import type { EventHandler, RigEventName } from "./events.js";
|
|
15
|
+
import type { ReactionHandler } from "./reactions.js";
|
|
16
|
+
import type { OperationHandle } from "./operation-handle.js";
|
|
17
|
+
/**
|
|
18
|
+
* Rig — pure orchestration for b3nd.
|
|
19
|
+
*
|
|
20
|
+
* The rig is identity-free — it routes, validates, and dispatches.
|
|
21
|
+
* For authenticated operations, use `Identity.sign()` + `message()` +
|
|
22
|
+
* `rig.send()` directly.
|
|
23
|
+
*
|
|
24
|
+
* @example Unsigned operations
|
|
25
|
+
* ```typescript
|
|
26
|
+
* const local = connection(client, ["**"]);
|
|
27
|
+
* const rig = new Rig({
|
|
28
|
+
* routes: { receive: [local], read: [local], observe: [local] },
|
|
29
|
+
* });
|
|
30
|
+
* const results = await rig.receive([["mutable://open/app/x", data]]);
|
|
31
|
+
* ```
|
|
32
|
+
*
|
|
33
|
+
* @example Authenticated send
|
|
34
|
+
* ```typescript
|
|
35
|
+
* // With messageDataHandler registered, the rig decomposes the
|
|
36
|
+
* // envelope into outputs + null-payload deletions for inputs.
|
|
37
|
+
* const id = await Identity.fromSeed("my-secret");
|
|
38
|
+
* const auth = [await id.sign({ inputs: [], outputs })];
|
|
39
|
+
* const envelope = await message({ auth, inputs: [], outputs });
|
|
40
|
+
* await rig.send([envelope]);
|
|
41
|
+
* ```
|
|
42
|
+
*
|
|
43
|
+
* @example With programs, hooks, events, and reactions
|
|
44
|
+
* ```typescript
|
|
45
|
+
* const local = connection(client, ["**"]);
|
|
46
|
+
* const rig = new Rig({
|
|
47
|
+
* routes: { receive: [local], read: [local], observe: [local] },
|
|
48
|
+
* programs,
|
|
49
|
+
* handlers,
|
|
50
|
+
* hooks: {
|
|
51
|
+
* beforeReceive: (ctx) => { rateLimit(ctx.uri); },
|
|
52
|
+
* afterRead: (ctx, result) => { audit(ctx.uri, result); },
|
|
53
|
+
* },
|
|
54
|
+
* on: {
|
|
55
|
+
* "send:success": [audit],
|
|
56
|
+
* },
|
|
57
|
+
* reactions: {
|
|
58
|
+
* "mutable://app/users/*": async (out, _read) => {
|
|
59
|
+
* const id = out[0].split("/").pop();
|
|
60
|
+
* return [[`notify://email/${id}`, { kind: "user-updated" }]];
|
|
61
|
+
* },
|
|
62
|
+
* },
|
|
63
|
+
* });
|
|
64
|
+
* ```
|
|
65
|
+
*/
|
|
66
|
+
export declare class Rig {
|
|
67
|
+
private readonly _receiveRoutes;
|
|
68
|
+
private readonly _readRoutes;
|
|
69
|
+
private readonly _observeRoutes;
|
|
70
|
+
private readonly _dispatch;
|
|
71
|
+
private readonly _programs;
|
|
72
|
+
private readonly _handlers;
|
|
73
|
+
private readonly _hooks;
|
|
74
|
+
private readonly _events;
|
|
75
|
+
private readonly _reactors;
|
|
76
|
+
constructor(config: RigConfig);
|
|
77
|
+
/**
|
|
78
|
+
* Raw composite client — bypasses hooks, events, and react.
|
|
79
|
+
*
|
|
80
|
+
* Prefer passing the Rig itself (it satisfies `ProtocolInterfaceNode`).
|
|
81
|
+
* This getter exists for third-party code that requires a plain object.
|
|
82
|
+
*/
|
|
83
|
+
get client(): ProtocolInterfaceNode;
|
|
84
|
+
/**
|
|
85
|
+
* Send tuples — the host application acting as the origin.
|
|
86
|
+
*
|
|
87
|
+
* Returns an `OperationHandle` that:
|
|
88
|
+
* - Awaits to `ReceiveResult[]` once the pipeline (process →
|
|
89
|
+
* handle) finishes. Pipeline-stage ack only — broadcast may
|
|
90
|
+
* still be in flight.
|
|
91
|
+
* - Fires per-stage events (`process:done`, `handle:emit`,
|
|
92
|
+
* `route:success`/`route:error`, `settled`) scoped to this call.
|
|
93
|
+
*
|
|
94
|
+
* Dispatch to connections runs in the background; per-route outcomes
|
|
95
|
+
* arrive as events. Wait for `op.settled` for read-after-write
|
|
96
|
+
* guarantees across replicas.
|
|
97
|
+
*
|
|
98
|
+
* Use this when the host is the origin of the content (a button
|
|
99
|
+
* click, a worker emitting state, a signed envelope from
|
|
100
|
+
* `Identity.sign()` + `message()`). Use `receive()` when content arrives from
|
|
101
|
+
* elsewhere (a peer, a webhook, an upstream sync).
|
|
102
|
+
*
|
|
103
|
+
* @example
|
|
104
|
+
* ```typescript
|
|
105
|
+
* const op = rig.send([["mutable://app/state", { value: 42 }]]);
|
|
106
|
+
* op.on("route:error", (e) => retry(e.emission));
|
|
107
|
+
* const [result] = await op; // pipeline ack
|
|
108
|
+
* await op.settled; // routes fully settled
|
|
109
|
+
* ```
|
|
110
|
+
*/
|
|
111
|
+
send(outs: Output[]): OperationHandle;
|
|
112
|
+
/**
|
|
113
|
+
* Receive tuples — the host application accepting state from elsewhere.
|
|
114
|
+
*
|
|
115
|
+
* Same shape as `send()` but fires `beforeReceive`/`afterReceive`
|
|
116
|
+
* hooks and `receive:*` global events. Returns an `OperationHandle`
|
|
117
|
+
* with the same scoped per-stage events.
|
|
118
|
+
*
|
|
119
|
+
* @example
|
|
120
|
+
* ```typescript
|
|
121
|
+
* const [result] = await rig.receive([
|
|
122
|
+
* ["mutable://open/external", { source: "webhook" }],
|
|
123
|
+
* ]);
|
|
124
|
+
* ```
|
|
125
|
+
*/
|
|
126
|
+
receive(outs: Output[]): OperationHandle;
|
|
127
|
+
/**
|
|
128
|
+
* Same as `receive()` but throws if any input tuple is rejected at
|
|
129
|
+
* the pipeline stage. Convenience for callers that don't want to
|
|
130
|
+
* inspect `accepted`.
|
|
131
|
+
*/
|
|
132
|
+
receiveOrThrow(outs: Output[]): Promise<ReceiveResult[]>;
|
|
133
|
+
/** Same as `send()` but throws on any pipeline-stage rejection. */
|
|
134
|
+
sendOrThrow(outs: Output[]): Promise<ReceiveResult[]>;
|
|
135
|
+
/**
|
|
136
|
+
* Classify a batch of tuples — runs registered programs.
|
|
137
|
+
*
|
|
138
|
+
* For each output, finds the program with the longest matching URI
|
|
139
|
+
* prefix and invokes it. Tuples whose URI matches no registered
|
|
140
|
+
* program get a default `{ code: "ok" }` classification (so the
|
|
141
|
+
* default-dispatch path persists them as-is).
|
|
142
|
+
*
|
|
143
|
+
* Pure: returns one `ProgramResult` per input tuple. No side effects.
|
|
144
|
+
*/
|
|
145
|
+
process(outs: Output[]): Promise<ProgramResult[]>;
|
|
146
|
+
/**
|
|
147
|
+
* Run the handler for a classified tuple — returns the emissions.
|
|
148
|
+
*
|
|
149
|
+
* If no handler is registered for the result's code, the input tuple
|
|
150
|
+
* is returned as-is (default-persist). Handlers themselves return the
|
|
151
|
+
* `Output[]` they want the Rig to dispatch; this method surfaces that
|
|
152
|
+
* return for callers that want to compose the pipeline manually.
|
|
153
|
+
*
|
|
154
|
+
* Pure: no dispatch happens here. Use `send()` / `receive()` for the
|
|
155
|
+
* full pipeline including dispatch and reactions.
|
|
156
|
+
*/
|
|
157
|
+
handle(out: Output, result: ProgramResult): Promise<Output[]>;
|
|
158
|
+
/**
|
|
159
|
+
* The pipeline body shared by `send()` and `receive()`.
|
|
160
|
+
*
|
|
161
|
+
* Returns an `OperationHandle` synchronously. The pipeline runs
|
|
162
|
+
* asynchronously inside; awaiting the handle resolves to the
|
|
163
|
+
* pipeline-stage `ReceiveResult[]` (process + handle outcome only).
|
|
164
|
+
* Per-route dispatch runs in the background; route outcomes arrive
|
|
165
|
+
* as events on the handle. `op.settled` resolves once every route
|
|
166
|
+
* has answered.
|
|
167
|
+
*
|
|
168
|
+
* Reactions fire after each emission's routes settle — once per
|
|
169
|
+
* emission, only if at least one route accepted. Their emissions
|
|
170
|
+
* spawn a fresh `rig.send(...)` operation, independent of this one.
|
|
171
|
+
*/
|
|
172
|
+
private _pipeline;
|
|
173
|
+
/** Internal: pipeline body driven against an OperationHandleImpl. */
|
|
174
|
+
private _runPipeline;
|
|
175
|
+
/**
|
|
176
|
+
* Run process for a single output. Isolated so a thrown program
|
|
177
|
+
* doesn't fail the whole batch.
|
|
178
|
+
*/
|
|
179
|
+
private _processOne;
|
|
180
|
+
/** Run the direction-appropriate after-hook with the standard payload. */
|
|
181
|
+
private _runAfterFor;
|
|
182
|
+
/**
|
|
183
|
+
* Per-emission, per-connection dispatch with route events.
|
|
184
|
+
*
|
|
185
|
+
* For each emission: find every connection in `routes.receive` that
|
|
186
|
+
* accepts the URI, dispatch the emission to each independently, emit
|
|
187
|
+
* `route:success` / `route:error` per (emission, connection). Once
|
|
188
|
+
* all routes for an emission settle, fire reactions if any route
|
|
189
|
+
* accepted. Reactions' returned tuples spawn a fresh `rig.send`
|
|
190
|
+
* operation (independent of this one).
|
|
191
|
+
*
|
|
192
|
+
* `input` is the original tuple that drove this dispatch — passed
|
|
193
|
+
* through so the `onError` hook can correlate route failures back
|
|
194
|
+
* to the input that triggered them.
|
|
195
|
+
*/
|
|
196
|
+
private _dispatchRouteAware;
|
|
197
|
+
/**
|
|
198
|
+
* Fire reactions for a successfully-dispatched emission. Reaction
|
|
199
|
+
* returns are dispatched through a fresh `rig.send(...)` — that
|
|
200
|
+
* spawned operation has its own OperationHandle and is unrelated
|
|
201
|
+
* to the one that triggered it. Loops are usage error.
|
|
202
|
+
*/
|
|
203
|
+
private _fireReactionsForEmission;
|
|
204
|
+
/** Internal read helper bound to the dispatch read interface. */
|
|
205
|
+
private _readFn;
|
|
206
|
+
/**
|
|
207
|
+
* Find the program with the longest matching URI prefix.
|
|
208
|
+
*/
|
|
209
|
+
private _findProgram;
|
|
210
|
+
/**
|
|
211
|
+
* Read a batch of locators. Each locator goes to the first connection
|
|
212
|
+
* whose route pattern accepts it. Locators are opaque strings; the
|
|
213
|
+
* executing client owns any grammar interpretation.
|
|
214
|
+
*/
|
|
215
|
+
read<T = unknown>(urls: string[]): Promise<Output<T>[]>;
|
|
216
|
+
/**
|
|
217
|
+
* Observe changes matching a URI pattern.
|
|
218
|
+
*
|
|
219
|
+
* Routes to the first connection that accepts `observe` for the pattern,
|
|
220
|
+
* then delegates to the client's native transport (SSE, internal events, etc).
|
|
221
|
+
*
|
|
222
|
+
* @example
|
|
223
|
+
* ```typescript
|
|
224
|
+
* const abort = new AbortController();
|
|
225
|
+
* for await (const uris of rig.observe(["mutable://data/market/**"], abort.signal)) {
|
|
226
|
+
* for (const uri of uris) console.log(uri);
|
|
227
|
+
* }
|
|
228
|
+
* ```
|
|
229
|
+
*/
|
|
230
|
+
observe(urls: string[], signal: AbortSignal): AsyncIterable<readonly string[]>;
|
|
231
|
+
/**
|
|
232
|
+
* Get a snapshot of this rig's current state.
|
|
233
|
+
*
|
|
234
|
+
* Pure local inspection, no network calls.
|
|
235
|
+
*
|
|
236
|
+
* @example
|
|
237
|
+
* ```typescript
|
|
238
|
+
* const info = rig.info();
|
|
239
|
+
* console.log(info.behavior.hooks);
|
|
240
|
+
* console.log(info.behavior.reactors);
|
|
241
|
+
* ```
|
|
242
|
+
*/
|
|
243
|
+
info(): RigInfo;
|
|
244
|
+
/**
|
|
245
|
+
* Status — health + schema.
|
|
246
|
+
* Aggregates client status across all connections.
|
|
247
|
+
*/
|
|
248
|
+
status(): Promise<StatusResult>;
|
|
249
|
+
/**
|
|
250
|
+
* Return any in-flight event handler promises and clear the queue.
|
|
251
|
+
*/
|
|
252
|
+
drain(): Promise<void>[];
|
|
253
|
+
/**
|
|
254
|
+
* Register an event handler at runtime. Returns an unsubscribe function.
|
|
255
|
+
*
|
|
256
|
+
* @example
|
|
257
|
+
* ```typescript
|
|
258
|
+
* const unsub = rig.on("send:success", (event) => {
|
|
259
|
+
* console.log(`Sent to ${event.uri}`);
|
|
260
|
+
* });
|
|
261
|
+
*
|
|
262
|
+
* // Later:
|
|
263
|
+
* unsub();
|
|
264
|
+
* ```
|
|
265
|
+
*/
|
|
266
|
+
on(event: RigEventName, handler: EventHandler): () => void;
|
|
267
|
+
/** Remove a specific event handler. */
|
|
268
|
+
off(event: RigEventName, handler: EventHandler): void;
|
|
269
|
+
/**
|
|
270
|
+
* Register a react pattern at runtime. Returns an unsubscribe function.
|
|
271
|
+
*
|
|
272
|
+
* Fires on successful `send()` or `receive()` when the written URI
|
|
273
|
+
* matches the pattern. Fire-and-forget — errors are caught and logged.
|
|
274
|
+
*
|
|
275
|
+
* Reactions return `Output[]` — those tuples flow back through
|
|
276
|
+
* `rig.send` (full pipeline). See chapter 7 of RFC 001 for the
|
|
277
|
+
* productive-observation model.
|
|
278
|
+
*
|
|
279
|
+
* @example
|
|
280
|
+
* ```typescript
|
|
281
|
+
* const unsub = rig.reaction(
|
|
282
|
+
* "mutable://app/users/*",
|
|
283
|
+
* async (out, _read) => {
|
|
284
|
+
* const id = out[0].split("/").pop();
|
|
285
|
+
* return [[`notify://email/${id}`, { kind: "user-updated" }]];
|
|
286
|
+
* },
|
|
287
|
+
* );
|
|
288
|
+
*
|
|
289
|
+
* // Later:
|
|
290
|
+
* unsub();
|
|
291
|
+
* ```
|
|
292
|
+
*/
|
|
293
|
+
reaction(pattern: string, handler: ReactionHandler): () => void;
|
|
294
|
+
}
|
|
295
|
+
//# sourceMappingURL=rig.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rig.d.ts","sourceRoot":"","sources":["../../../../../../../../src/deps/jsr.io/@bandeira-tech/b3nd-core/0.22.0/src/rig/rig.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AA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