orez-sync-executor 0.11.1 → 0.11.2

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.
Files changed (57) hide show
  1. package/dist/realtime/host.d.ts +7 -0
  2. package/dist/realtime/host.d.ts.map +1 -0
  3. package/dist/realtime/host.js +77 -0
  4. package/dist/realtime/host.js.map +1 -0
  5. package/dist/realtime/hub.d.ts +67 -0
  6. package/dist/realtime/hub.d.ts.map +1 -0
  7. package/dist/realtime/hub.js +456 -0
  8. package/dist/realtime/hub.js.map +1 -0
  9. package/dist/realtime/index.d.ts +24 -0
  10. package/dist/realtime/index.d.ts.map +1 -0
  11. package/dist/realtime/index.js +27 -0
  12. package/dist/realtime/index.js.map +1 -0
  13. package/dist/realtime/local.d.ts +15 -0
  14. package/dist/realtime/local.d.ts.map +1 -0
  15. package/dist/realtime/local.js +63 -0
  16. package/dist/realtime/local.js.map +1 -0
  17. package/dist/realtime/manifest.d.ts +51 -0
  18. package/dist/realtime/manifest.d.ts.map +1 -0
  19. package/dist/realtime/manifest.js +110 -0
  20. package/dist/realtime/manifest.js.map +1 -0
  21. package/dist/realtime/message-port.d.ts +34 -0
  22. package/dist/realtime/message-port.d.ts.map +1 -0
  23. package/dist/realtime/message-port.js +141 -0
  24. package/dist/realtime/message-port.js.map +1 -0
  25. package/dist/realtime/producer-socket.d.ts +10 -0
  26. package/dist/realtime/producer-socket.d.ts.map +1 -0
  27. package/dist/realtime/producer-socket.js +90 -0
  28. package/dist/realtime/producer-socket.js.map +1 -0
  29. package/dist/realtime/producer.d.ts +16 -0
  30. package/dist/realtime/producer.d.ts.map +1 -0
  31. package/dist/realtime/producer.js +51 -0
  32. package/dist/realtime/producer.js.map +1 -0
  33. package/dist/realtime/protocol.d.ts +99 -0
  34. package/dist/realtime/protocol.d.ts.map +1 -0
  35. package/dist/realtime/protocol.js +191 -0
  36. package/dist/realtime/protocol.js.map +1 -0
  37. package/dist/realtime/publisher.d.ts +28 -0
  38. package/dist/realtime/publisher.d.ts.map +1 -0
  39. package/dist/realtime/publisher.js +309 -0
  40. package/dist/realtime/publisher.js.map +1 -0
  41. package/dist/realtime/socket-host.d.ts +25 -0
  42. package/dist/realtime/socket-host.d.ts.map +1 -0
  43. package/dist/realtime/socket-host.js +105 -0
  44. package/dist/realtime/socket-host.js.map +1 -0
  45. package/dist/realtime/store.d.ts +28 -0
  46. package/dist/realtime/store.d.ts.map +1 -0
  47. package/dist/realtime/store.js +0 -0
  48. package/dist/realtime/store.js.map +1 -0
  49. package/dist/realtime/writer.d.ts +17 -0
  50. package/dist/realtime/writer.d.ts.map +1 -0
  51. package/dist/realtime/writer.js +138 -0
  52. package/dist/realtime/writer.js.map +1 -0
  53. package/package.json +5 -1
  54. package/dist/adapters.d.ts +0 -25
  55. package/dist/adapters.d.ts.map +0 -1
  56. package/dist/adapters.js +0 -116
  57. package/dist/adapters.js.map +0 -1
@@ -0,0 +1,309 @@
1
+ // The producer side of a streaming field.
2
+ //
3
+ // A producer opens one generation per field, pushes values, and finishes by
4
+ // running the application's authoritative durable write. Orez never performs
5
+ // that write: in a delegated-push deployment the application worker is the
6
+ // write authority, so the commit is a callback the application supplies.
7
+ //
8
+ // The transport is injected. Trusted server code gets an in-process publisher
9
+ // on the native and local hosts; on Cloudflare the same interface is backed by
10
+ // one private service-bound producer WebSocket per generation.
11
+ import { canonicalTopic } from './protocol.js';
12
+ export class RealtimePublisher {
13
+ #transport;
14
+ #manifest;
15
+ #now;
16
+ #randomID;
17
+ constructor(transport, manifest, options = {}) {
18
+ this.#transport = transport;
19
+ this.#manifest = manifest;
20
+ this.#now = options.now ?? (() => Date.now());
21
+ this.#randomID = options.randomID ?? (() => crypto.randomUUID());
22
+ }
23
+ async begin(table, field, options) {
24
+ const spec = this.#manifest.fields.get(`${table}.${field}`);
25
+ if (!spec) {
26
+ throw new TypeError(`'${table}.${field}' is not a streaming field in this manifest`);
27
+ }
28
+ const topic = { table, key: options.key, field };
29
+ for (const column of spec.primaryKey) {
30
+ if (options.key[column] === undefined) {
31
+ throw new TypeError(`streaming topic '${table}.${field}' is missing primary key column '${column}'`);
32
+ }
33
+ }
34
+ const streamID = this.#randomID();
35
+ await this.#transport.begin(topic, streamID);
36
+ return new Session(this.#transport, spec, topic, canonicalTopic(spec.primaryKey, topic), streamID, this.#now);
37
+ }
38
+ }
39
+ class Session {
40
+ streamID;
41
+ topic;
42
+ #transport;
43
+ #spec;
44
+ #id;
45
+ #now;
46
+ #seq = 0;
47
+ // what the subscribers have been told, so append mode can ship the suffix
48
+ #delivered = '';
49
+ #started = false;
50
+ #closed = false;
51
+ #pending;
52
+ #inFlight = Promise.resolve();
53
+ // A background flush cannot reject into the caller's stack, so a transport
54
+ // failure (most often: this generation was superseded by a retry) is held
55
+ // here and raised on the next set/finish. Without this the failure would
56
+ // surface as an unhandled rejection and the producer would keep writing into
57
+ // a stream nobody accepts.
58
+ #failure;
59
+ constructor(transport, spec, topic, id, streamID, now) {
60
+ this.#transport = transport;
61
+ this.#spec = spec;
62
+ this.topic = topic;
63
+ this.#id = id;
64
+ this.streamID = streamID;
65
+ this.#now = now;
66
+ this.#pending = {
67
+ value: undefined,
68
+ windowBytes: 0,
69
+ windowUpdates: 0,
70
+ windowStartedAt: now(),
71
+ timer: undefined,
72
+ flushing: false,
73
+ };
74
+ }
75
+ set(value) {
76
+ this.#throwIfUnusable();
77
+ this.#validate(value);
78
+ this.#pending.value = value;
79
+ this.#schedule();
80
+ }
81
+ // Deliver whatever is pending now, waiting only as long as the manifest's
82
+ // rate bounds require. `set` is fire-and-forget by design so a token loop
83
+ // never awaits; this is for the places a producer needs the value to have
84
+ // actually left: a semantic checkpoint, or a deterministic test.
85
+ //
86
+ // It waits rather than bypassing the bound, so a producer calling flush in a
87
+ // loop still cannot exceed its declared maxUpdatesPerSecond.
88
+ async flush() {
89
+ this.#throwIfUnusable();
90
+ if (this.#pending.value === undefined)
91
+ return;
92
+ const delay = this.#delayUntilAllowed();
93
+ if (delay > 0)
94
+ await new Promise((resolve) => setTimeout(resolve, delay));
95
+ // A scheduled flush can fire during that wait, and if it failed then this
96
+ // generation is dead and its pending value was never delivered. Re-checking
97
+ // is what keeps flush() honest: it either delivered, or it throws. Without
98
+ // it the scheduled flush's suffix bookkeeping makes the retry here a no-op
99
+ // and the producer is told its value went out when it did not.
100
+ this.#throwIfUnusable();
101
+ this.#cancelTimer();
102
+ await this.#flush(false);
103
+ }
104
+ async finish(value, commit) {
105
+ this.#throwIfUnusable();
106
+ this.#validate(value);
107
+ this.#pending.value = value;
108
+ this.#cancelTimer();
109
+ // 1. flush the final value so subscribers see it before the commit round-trip
110
+ await this.#flush(true);
111
+ // 2. the application's authoritative durable write. Orez cannot do this
112
+ // generically: in a delegated-push deployment the application worker is
113
+ // the write authority.
114
+ await commit();
115
+ // 3. `end` puts every subscriber in `committing`, holding the final overlay
116
+ // until their own Zero query produces the committed value. No waiting on
117
+ // replication here: the client's durable-equality check is what ends the
118
+ // overlay, and blocking the generation on replica observation would
119
+ // couple producer lifetime to pull lag for no extra safety.
120
+ this.#closed = true;
121
+ await this.#emit({
122
+ topic: this.#id,
123
+ streamID: this.streamID,
124
+ seq: ++this.#seq,
125
+ op: 'end',
126
+ });
127
+ await this.#transport.end(this.streamID);
128
+ }
129
+ async abort() {
130
+ if (this.#closed)
131
+ return;
132
+ this.#closed = true;
133
+ this.#cancelTimer();
134
+ await this.#emit({
135
+ topic: this.#id,
136
+ streamID: this.streamID,
137
+ seq: ++this.#seq,
138
+ op: 'abort',
139
+ });
140
+ await this.#transport.end(this.streamID);
141
+ }
142
+ #throwIfUnusable() {
143
+ if (this.#failure)
144
+ throw this.#failure;
145
+ if (this.#closed)
146
+ throw new Error('streaming field generation is already closed');
147
+ }
148
+ #validate(value) {
149
+ if (this.#spec.mode === 'append' && typeof value !== 'string') {
150
+ throw new TypeError(`streaming field '${this.#spec.table}.${this.#spec.field}' is append mode and takes a string`);
151
+ }
152
+ if (this.#spec.validate && !this.#spec.validate(value)) {
153
+ throw new TypeError(`streaming field '${this.#spec.table}.${this.#spec.field}' rejected a value in validate()`);
154
+ }
155
+ const bytes = byteLength(typeof value === 'string' ? value : JSON.stringify(value ?? null));
156
+ if (bytes > this.#spec.maxBytes) {
157
+ throw new RangeError(`streaming field '${this.#spec.table}.${this.#spec.field}' value is ${bytes} bytes, over its ${this.#spec.maxBytes} maxBytes`);
158
+ }
159
+ if (this.#spec.mode === 'append' && this.#started) {
160
+ // append ships suffixes, so the value must only ever grow. A producer that
161
+ // rewrites history needs `mode: 'replace'`; silently shipping a bogus
162
+ // suffix would leave every subscriber with a corrupted value.
163
+ const next = value;
164
+ if (!next.startsWith(this.#delivered)) {
165
+ // A text column holding JSON is the common way to hit this: the
166
+ // manifest infers append from the Zero column type, but the producer
167
+ // replaces the value rather than extending it. Naming the fix here
168
+ // saves the reader from inferring it from a corrupted overlay.
169
+ throw new TypeError(`streaming field '${this.#spec.table}.${this.#spec.field}' is append mode, but its new value is not an extension of what was already sent. ` +
170
+ `Append ships only the added suffix, so the value must grow. If this field is replaced rather than extended (a JSON payload in a text column, for example), declare mode: 'replace' for it in the manifest.`);
171
+ }
172
+ }
173
+ }
174
+ #schedule() {
175
+ if (this.#pending.timer || this.#pending.flushing || this.#failure)
176
+ return;
177
+ const delay = this.#delayUntilAllowed();
178
+ if (delay === 0) {
179
+ void this.#flush(false).catch((error) => this.#fail(error));
180
+ return;
181
+ }
182
+ this.#pending.timer = setTimeout(() => {
183
+ this.#pending.timer = undefined;
184
+ void this.#flush(false).catch((error) => this.#fail(error));
185
+ }, delay);
186
+ }
187
+ // How long before another update may go out, honouring BOTH manifest bounds.
188
+ // In append mode the byte budget is charged against new bytes only, which is
189
+ // what keeps a long generation's update rate flat instead of degrading as the
190
+ // accumulated value grows.
191
+ #delayUntilAllowed() {
192
+ const now = this.#now();
193
+ const elapsed = now - this.#pending.windowStartedAt;
194
+ if (elapsed >= 1000)
195
+ return 0;
196
+ const newBytes = this.#pendingBytes();
197
+ const overUpdates = this.#pending.windowUpdates >= this.#spec.maxUpdatesPerSecond;
198
+ const overBytes = this.#pending.windowBytes + newBytes > this.#spec.maxBytesPerSecond;
199
+ if (!overUpdates && !overBytes) {
200
+ // spread updates evenly rather than bursting then starving
201
+ const minGap = Math.floor(1000 / this.#spec.maxUpdatesPerSecond);
202
+ const sinceWindowStart = elapsed;
203
+ const expected = this.#pending.windowUpdates * minGap;
204
+ return Math.max(0, expected - sinceWindowStart);
205
+ }
206
+ return 1000 - elapsed;
207
+ }
208
+ #pendingBytes() {
209
+ const value = this.#pending.value;
210
+ if (this.#spec.mode === 'append') {
211
+ const text = value ?? '';
212
+ return byteLength(text.slice(this.#delivered.length));
213
+ }
214
+ return byteLength(JSON.stringify(value ?? null));
215
+ }
216
+ async #flush(final) {
217
+ const value = this.#pending.value;
218
+ if (value === undefined)
219
+ return;
220
+ this.#pending.flushing = true;
221
+ try {
222
+ const now = this.#now();
223
+ if (now - this.#pending.windowStartedAt >= 1000) {
224
+ this.#pending.windowStartedAt = now;
225
+ this.#pending.windowBytes = 0;
226
+ this.#pending.windowUpdates = 0;
227
+ }
228
+ let update;
229
+ if (this.#spec.mode === 'append' && this.#started) {
230
+ const text = value.slice(this.#delivered.length);
231
+ if (!text && !final)
232
+ return;
233
+ update = {
234
+ topic: this.#id,
235
+ streamID: this.streamID,
236
+ seq: ++this.#seq,
237
+ op: 'append',
238
+ text,
239
+ };
240
+ this.#delivered = value;
241
+ }
242
+ else {
243
+ update = {
244
+ topic: this.#id,
245
+ streamID: this.streamID,
246
+ seq: ++this.#seq,
247
+ op: 'snapshot',
248
+ value,
249
+ };
250
+ this.#started = true;
251
+ this.#delivered = this.#spec.mode === 'append' ? value : '';
252
+ }
253
+ this.#pending.windowBytes += this.#pendingBytes();
254
+ this.#pending.windowUpdates++;
255
+ await this.#emit(update);
256
+ }
257
+ finally {
258
+ this.#pending.flushing = false;
259
+ }
260
+ // a value that arrived while this flush was in flight still needs sending
261
+ if (!final && this.#pendingHasNewBytes())
262
+ this.#schedule();
263
+ }
264
+ #pendingHasNewBytes() {
265
+ if (this.#spec.mode !== 'append')
266
+ return false;
267
+ const text = this.#pending.value ?? '';
268
+ return text.length > this.#delivered.length;
269
+ }
270
+ #cancelTimer() {
271
+ if (this.#pending.timer) {
272
+ clearTimeout(this.#pending.timer);
273
+ this.#pending.timer = undefined;
274
+ }
275
+ }
276
+ // Serialize every emit for the generation. WebSocket ordering owns frame
277
+ // order on the wire, but two overlapping flushes could otherwise hand the
278
+ // transport its frames out of sequence.
279
+ #emit(update) {
280
+ this.#inFlight = this.#inFlight.then(() => this.#transport.publish(update));
281
+ return this.#inFlight;
282
+ }
283
+ // Record a background failure and stop the generation. `finish` and `abort`
284
+ // await their emits directly, so they still reject into the caller; only the
285
+ // scheduled flushes route through here.
286
+ #fail(error) {
287
+ this.#failure = error instanceof Error ? error : new Error(String(error));
288
+ this.#closed = true;
289
+ this.#cancelTimer();
290
+ }
291
+ }
292
+ function byteLength(value) {
293
+ let bytes = 0;
294
+ for (let index = 0; index < value.length; index++) {
295
+ const code = value.charCodeAt(index);
296
+ if (code < 0x80)
297
+ bytes += 1;
298
+ else if (code < 0x800)
299
+ bytes += 2;
300
+ else if (code >= 0xd800 && code < 0xdc00) {
301
+ bytes += 4;
302
+ index++;
303
+ }
304
+ else
305
+ bytes += 3;
306
+ }
307
+ return bytes;
308
+ }
309
+ //# sourceMappingURL=publisher.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"publisher.js","sourceRoot":"","sources":["../../src/realtime/publisher.ts"],"names":[],"mappings":"AAAA,0CAA0C;AAC1C,EAAE;AACF,4EAA4E;AAC5E,6EAA6E;AAC7E,2EAA2E;AAC3E,yEAAyE;AACzE,EAAE;AACF,8EAA8E;AAC9E,+EAA+E;AAC/E,+DAA+D;AAE/D,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAA;AA8C9C,MAAM,OAAO,iBAAiB;IACnB,UAAU,CAAoB;IAC9B,SAAS,CAAmB;IAC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,MAAM,IAAI,GAAG,KAAK,CAAC,UAAU,CAAC,KAAK,CAAC,CAAA;QACpC,IAAI,IAAI,GAAG,IAAI;YAAE,KAAK,IAAI,CAAC,CAAA;aACtB,IAAI,IAAI,GAAG,KAAK;YAAE,KAAK,IAAI,CAAC,CAAA;aAC5B,IAAI,IAAI,IAAI,MAAM,IAAI,IAAI,GAAG,MAAM,EAAE,CAAC;YACzC,KAAK,IAAI,CAAC,CAAA;YACV,KAAK,EAAE,CAAA;QACT,CAAC;;YAAM,KAAK,IAAI,CAAC,CAAA;IACnB,CAAC;IACD,OAAO,KAAK,CAAA;AACd,CAAC"}
@@ -0,0 +1,25 @@
1
+ import { RealtimeHub } from './hub.js';
2
+ import type { HubOptions, RealtimeIdentity } from './hub.js';
3
+ import type { RealtimeTopic } from './protocol.js';
4
+ export type HostSocket = {
5
+ send(data: string): void;
6
+ };
7
+ export type HostConnection = {
8
+ handleMessage(raw: string): void;
9
+ close(): void;
10
+ topics(): readonly RealtimeTopic[];
11
+ };
12
+ export type RealtimeSocketHost = {
13
+ readonly hub: RealtimeHub;
14
+ acceptSubscriber(socket: HostSocket, identity: RealtimeIdentity, connectionID: string): HostConnection;
15
+ acceptProducer(socket: HostSocket, producerID: string): HostConnection;
16
+ rehydrate(entries: readonly {
17
+ socket: HostSocket;
18
+ identity: RealtimeIdentity;
19
+ connectionID: string;
20
+ topics: readonly RealtimeTopic[];
21
+ }[]): Promise<readonly HostConnection[]>;
22
+ flush(): void;
23
+ };
24
+ export declare function createSocketHost(options: HubOptions): RealtimeSocketHost;
25
+ //# sourceMappingURL=socket-host.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"socket-host.d.ts","sourceRoot":"","sources":["../../src/realtime/socket-host.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAA;AAGtC,OAAO,KAAK,EAA8B,UAAU,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAA;AACxF,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,eAAe,CAAA;AAElD,MAAM,MAAM,UAAU,GAAG;IACvB,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAA;CACzB,CAAA;AAOD,MAAM,MAAM,cAAc,GAAG;IAC3B,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAAA;IAChC,KAAK,IAAI,IAAI,CAAA;IACb,MAAM,IAAI,SAAS,aAAa,EAAE,CAAA;CACnC,CAAA;AAED,MAAM,MAAM,kBAAkB,GAAG;IAC/B,QAAQ,CAAC,GAAG,EAAE,WAAW,CAAA;IAIzB,gBAAgB,CACd,MAAM,EAAE,UAAU,EAClB,QAAQ,EAAE,gBAAgB,EAC1B,YAAY,EAAE,MAAM,GACnB,cAAc,CAAA;IAIjB,cAAc,CAAC,MAAM,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,GAAG,cAAc,CAAA;IAkBtE,SAAS,CACP,OAAO,EAAE,SAAS;QAChB,MAAM,EAAE,UAAU,CAAA;QAClB,QAAQ,EAAE,gBAAgB,CAAA;QAC1B,YAAY,EAAE,MAAM,CAAA;QACpB,MAAM,EAAE,SAAS,aAAa,EAAE,CAAA;KACjC,EAAE,GACF,OAAO,CAAC,SAAS,cAAc,EAAE,CAAC,CAAA;IACrC,KAAK,IAAI,IAAI,CAAA;CACd,CAAA;AAED,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,UAAU,GAAG,kBAAkB,CA+FxE"}
@@ -0,0 +1,105 @@
1
+ // The host role over sockets, for any runtime that has them.
2
+ //
3
+ // A Cloudflare Durable Object, a Node WebSocket server, and a test harness
4
+ // differ in how they accept a socket and in nothing else. So this owns the
5
+ // parts that are the same everywhere (which frames a role may send, when a
6
+ // connection is dropped, what survives a cold start) and leaves each runtime
7
+ // only its own socket lifecycle.
8
+ //
9
+ // The role split is enforced here rather than trusted. A subscriber socket is
10
+ // accepted as a subscriber and can never publish, whatever it sends: it has no
11
+ // producer handle, and the hub checks the handle rather than the frame. That is
12
+ // why a leaked streamID grants nothing.
13
+ import { applyClientFrame, applyProducerFrame } from './host.js';
14
+ import { RealtimeHub } from './hub.js';
15
+ import { decodeFrame, encodeFrame } from './protocol.js';
16
+ export function createSocketHost(options) {
17
+ const hub = new RealtimeHub(options);
18
+ // One subscriber, whether it is being accepted for the first time or rebuilt
19
+ // after an eviction. Both paths need the same tracking, so neither gets its
20
+ // own copy of it.
21
+ const subscriber = (socket, identity, connectionID) => {
22
+ // keyed for dedup, valued with the structured topic so `topics()` can hand
23
+ // back something `rehydrate` accepts without a second parser
24
+ const owned = new Map();
25
+ const connection = {
26
+ id: connectionID,
27
+ identity,
28
+ send: (frame) => {
29
+ socket.send(encodeFrame(frame));
30
+ },
31
+ };
32
+ const host = {
33
+ handleMessage(raw) {
34
+ const frame = decodeFrame(raw);
35
+ if (!frame)
36
+ return;
37
+ // A subscriber channel is never a publish channel, whatever arrives on
38
+ // it. Producer frames are not merely ignored by the hub here; they are
39
+ // refused before reaching it.
40
+ if (frame[0] !== 'subscribe' && frame[0] !== 'unsubscribe')
41
+ return;
42
+ if (frame[0] === 'subscribe')
43
+ owned.set(topicKey(frame[1].topic), frame[1].topic);
44
+ else
45
+ owned.delete(topicKey(frame[1].topic));
46
+ void applyClientFrame(hub, connection, frame);
47
+ },
48
+ close() {
49
+ hub.dropConnection(connectionID);
50
+ },
51
+ topics: () => [...owned.values()],
52
+ };
53
+ return { connection, owned, host };
54
+ };
55
+ return {
56
+ hub,
57
+ acceptSubscriber: (socket, identity, connectionID) => subscriber(socket, identity, connectionID).host,
58
+ acceptProducer(socket, producerID) {
59
+ const producer = {
60
+ id: producerID,
61
+ send: (frame) => {
62
+ socket.send(encodeFrame(frame));
63
+ },
64
+ };
65
+ return {
66
+ handleMessage(raw) {
67
+ const frame = decodeFrame(raw);
68
+ if (!frame)
69
+ return;
70
+ if (frame[0] !== 'begin' && frame[0] !== 'publish')
71
+ return;
72
+ applyProducerFrame(hub, producer, frame);
73
+ },
74
+ close() {
75
+ hub.dropProducer(producerID);
76
+ },
77
+ topics: () => [],
78
+ };
79
+ },
80
+ async rehydrate(entries) {
81
+ const restored = [];
82
+ for (const entry of entries) {
83
+ const { connection, owned, host } = subscriber(entry.socket, entry.identity, entry.connectionID);
84
+ for (const topic of entry.topics) {
85
+ // recorded before the result, exactly as a live subscribe frame does:
86
+ // a topic denied during the gap stays the client's asserted interest,
87
+ // so a membership that comes back is picked up at the next eviction
88
+ // instead of being forgotten here.
89
+ owned.set(topicKey(topic), topic);
90
+ await hub.subscribe(connection, topic);
91
+ }
92
+ restored.push(host);
93
+ }
94
+ return restored;
95
+ },
96
+ flush: () => hub.flush(),
97
+ };
98
+ }
99
+ // Dedup key only. Never persisted and never parsed back: `topics()` hands out
100
+ // the structured topic, so there is no second encoding to keep in agreement
101
+ // with canonicalTopic.
102
+ function topicKey(topic) {
103
+ return JSON.stringify(topic);
104
+ }
105
+ //# sourceMappingURL=socket-host.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"socket-host.js","sourceRoot":"","sources":["../../src/realtime/socket-host.ts"],"names":[],"mappings":"AAAA,6DAA6D;AAC7D,EAAE;AACF,2EAA2E;AAC3E,2EAA2E;AAC3E,2EAA2E;AAC3E,6EAA6E;AAC7E,iCAAiC;AACjC,EAAE;AACF,8EAA8E;AAC9E,+EAA+E;AAC/E,gFAAgF;AAChF,wCAAwC;AAExC,OAAO,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAA;AAChE,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAA;AACtC,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AA8DxD,MAAM,UAAU,gBAAgB,CAAC,OAAmB;IAClD,MAAM,GAAG,GAAG,IAAI,WAAW,CAAC,OAAO,CAAC,CAAA;IAEpC,6EAA6E;IAC7E,4EAA4E;IAC5E,kBAAkB;IAClB,MAAM,UAAU,GAAG,CACjB,MAAkB,EAClB,QAA0B,E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C,GAAG,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,KAAK,CAAC,CAAA;oBACjC,MAAM,GAAG,CAAC,SAAS,CAAC,UAAU,EAAE,KAAK,CAAC,CAAA;gBACxC,CAAC;gBACD,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;YACrB,CAAC;YACD,OAAO,QAAQ,CAAA;QACjB,CAAC;QAED,KAAK,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,KAAK,EAAE;KACzB,CAAA;AACH,CAAC;AAED,8EAA8E;AAC9E,4EAA4E;AAC5E,uBAAuB;AACvB,SAAS,QAAQ,CAAC,KAAoB;IACpC,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAA;AAC9B,CAAC"}
@@ -0,0 +1,28 @@
1
+ import type { StreamingFieldHandle } from './manifest.js';
2
+ import type { FieldUpdate } from './protocol.js';
3
+ export type StreamingPhase = 'committing' | 'durable' | 'stale' | 'streaming';
4
+ export type StreamingFieldState<Value> = {
5
+ readonly value: Value;
6
+ readonly phase: StreamingPhase;
7
+ readonly streamID: string | null;
8
+ };
9
+ export declare function canonicalEncode(value: unknown): string;
10
+ export type RealtimeStoreOptions = {
11
+ readonly send: (frame: unknown) => void;
12
+ readonly staleAfterMs?: number;
13
+ readonly onError?: (message: string) => void;
14
+ };
15
+ export declare class RealtimeStore {
16
+ #private;
17
+ constructor(options: RealtimeStoreOptions);
18
+ subscribe(handle: StreamingFieldHandle, listener: () => void): () => void;
19
+ read<Value>(handle: StreamingFieldHandle, base: Value): StreamingFieldState<Value>;
20
+ applyUpdates(updates: readonly FieldUpdate[]): void;
21
+ handleSubscribed(topic: string, status: 'active' | 'pending'): void;
22
+ handleSubscribeError(topic: string, reason: string): void;
23
+ retryPending(): void;
24
+ handleDisconnect(): void;
25
+ handleReconnect(): void;
26
+ get topicCount(): number;
27
+ }
28
+ //# sourceMappingURL=store.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"store.d.ts","source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AM;QACN,MAAM,CAAC,EAAE,CAAC,MAAM,CAAC,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC;QACnC,MAAM,CAAC,KAAK,KAAK,IAAI,CAAC,KAAK;QAC3B,MAAM,CAAC,QAAQ,KAAK,IAAI,CAAC,QAAQ,EACjC,CAAC;QACD,OAAO,MAAM,CAAA;IACf,CAAC;IACD,KAAK,CAAC,MAAM,GAAG,IAAI,CAAA;IACnB,OAAO,IAAI,CAAA;AACb,CAAC;AAED,SAAS,UAAU,CAAC,KAAa;IAC/B,8EAA8E;IAC9E,IAAI,KAAK,GAAG,CAAC,CAAA;IACb,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,KAAK,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE,CAAC;QAClD,MAAM,IAAI,GAAG,KAAK,CAAC,UAAU,CAAC,KAAK,CAAC,CAAA;QACpC,IAAI,IAAI,GAAG,IAAI;YAAE,KAAK,IAAI,CAAC,CAAA;aACtB,IAAI,IAAI,GAAG,KAAK;YAAE,KAAK,IAAI,CAAC,CAAA;aAC5B,IAAI,IAAI,IAAI,MAAM,IAAI,IAAI,GAAG,MAAM,EAAE,CAAC;YACzC,KAAK,IAAI,CAAC,CAAA;YACV,KAAK,EAAE,CAAA;QACT,CAAC;;YAAM,KAAK,IAAI,CAAC,CAAA;IACnB,CAAC;IACD,OAAO,KAAK,CAAA;AACd,CAAC"}
@@ -0,0 +1,17 @@
1
+ import type { StreamingFieldHandle } from './manifest.js';
2
+ import type { RealtimeTopic } from './protocol.js';
3
+ import type { RealtimePublisher } from './publisher.js';
4
+ export type FieldWriterOptions = {
5
+ readonly onError?: (error: Error, topic: RealtimeTopic) => void;
6
+ };
7
+ export declare class FieldWriter {
8
+ #private;
9
+ constructor(publisher: RealtimePublisher, options?: FieldWriterOptions);
10
+ set(handle: StreamingFieldHandle, value: unknown): void;
11
+ flush(handle: StreamingFieldHandle): Promise<void>;
12
+ finish(handle: StreamingFieldHandle, value: unknown, commit: () => Promise<void>): Promise<void>;
13
+ abort(handle: StreamingFieldHandle): Promise<void>;
14
+ isStreaming(handle: StreamingFieldHandle): boolean;
15
+ abortAll(): Promise<void>;
16
+ }
17
+ //# sourceMappingURL=writer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"writer.d.ts","sourceRoot":"","sources":["../../src/realtime/writer.ts"],"names":[],"mappings":"AAiBA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAA;AACzD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,eAAe,CAAA;AAClD,OAAO,KAAK,EAAE,iBAAiB,EAAiB,MAAM,gBAAgB,CAAA;AAUtE,MAAM,MAAM,kBAAkB,GAAG;IAI/B,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,aAAa,KAAK,IAAI,CAAA;CAChE,CAAA;AAED,qBAAa,WAAW;;gBAKV,SAAS,EAAE,iBAAiB,EAAE,OAAO,GAAE,kBAAuB;IAqB1E,GAAG,CAAC,MAAM,EAAE,oBAAoB,EAAE,KAAK,EAAE,OAAO,GAAG,IAAI;IAwCjD,KAAK,CAAC,MAAM,EAAE,oBAAoB,GAAG,OAAO,CAAC,IAAI,CAAC;IASlD,MAAM,CACV,MAAM,EAAE,oBAAoB,EAC5B,KAAK,EAAE,OAAO,EACd,MAAM,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,GAC1B,OAAO,CAAC,IAAI,CAAC;IAqBV,KAAK,CAAC,MAAM,EAAE,oBAAoB,GAAG,OAAO,CAAC,IAAI,CAAC;IAUxD,WAAW,CAAC,MAAM,EAAE,oBAAoB,GAAG,OAAO;IAQ5C,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;CAiBhC"}