cross-tab-worker-databus 0.6.0 → 0.8.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/CHANGELOG.md +22 -1
- package/dist/centrifuge-protocol.d.ts +4 -0
- package/dist/centrifuge-protocol.d.ts.map +1 -1
- package/dist/centrifuge-session.d.ts.map +1 -1
- package/dist/centrifuge.d.ts +2 -1
- package/dist/centrifuge.d.ts.map +1 -1
- package/dist/centrifuge.js +13 -10
- package/dist/centrifuge.js.map +2 -2
- package/dist/centrifuge.shared.worker.js +7 -4
- package/dist/centrifuge.shared.worker.js.map +2 -2
- package/dist/centrifuge.worker.js +7 -4
- package/dist/centrifuge.worker.js.map +2 -2
- package/dist/{chunk-YUSQSNCX.js → chunk-WWUY2FV2.js} +75 -14
- package/dist/chunk-WWUY2FV2.js.map +7 -0
- package/dist/cjs/centrifuge.cjs +86 -22
- package/dist/cjs/centrifuge.cjs.map +2 -2
- package/dist/cjs/index.cjs +106 -18
- package/dist/cjs/index.cjs.map +2 -2
- package/dist/core/cluster.d.ts +7 -2
- package/dist/core/cluster.d.ts.map +1 -1
- package/dist/core/data-bus.d.ts +16 -2
- package/dist/core/data-bus.d.ts.map +1 -1
- package/dist/core/replay-persistence.d.ts +4 -0
- package/dist/core/replay-persistence.d.ts.map +1 -1
- package/dist/core/trace.d.ts +10 -1
- package/dist/core/trace.d.ts.map +1 -1
- package/dist/core/types.d.ts +10 -1
- package/dist/core/types.d.ts.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +33 -6
- package/dist/index.js.map +2 -2
- package/dist/websocket.d.ts +2 -2
- package/dist/websocket.d.ts.map +1 -1
- package/docs/api.md +15 -2
- package/docs/capabilities.md +3 -3
- package/docs/roadmap.md +7 -7
- package/docs/zh/api.md +13 -2
- package/docs/zh/capabilities.md +3 -3
- package/docs/zh/roadmap.md +7 -7
- package/package.json +1 -1
- package/dist/chunk-YUSQSNCX.js.map +0 -7
package/dist/core/cluster.d.ts
CHANGED
|
@@ -3,13 +3,18 @@ import type { WorkerControlAction, WorkerRecord, WorkerRoute, WorkerStatus } fro
|
|
|
3
3
|
/** Callbacks the cluster invokes to drive the transport and lifecycle. */
|
|
4
4
|
export interface WorkerClusterHandlers {
|
|
5
5
|
/** A SUBSCRIBE/UNSUBSCRIBE/PUBLISH control action was received for this worker. */
|
|
6
|
-
onControl: (action: WorkerControlAction, topic: string, data?: unknown) => void;
|
|
6
|
+
onControl: (action: WorkerControlAction, topic: string, data?: unknown, messageId?: string) => void;
|
|
7
7
|
/** A fan-out publication event was received from another Worker. */
|
|
8
8
|
onEvent: (eventType: string, payload: unknown, sourceWorkerId: string) => void;
|
|
9
9
|
/** The cluster suspended (tab hidden / pagehide). */
|
|
10
10
|
onSuspend?: () => void;
|
|
11
11
|
/** The cluster resumed (tab visible / pageshow). */
|
|
12
12
|
onResume?: () => void;
|
|
13
|
+
/** Bounded diagnostics for route confirmation and graceful migration. */
|
|
14
|
+
onDiagnostic?: (event: {
|
|
15
|
+
operation: 'route_ack' | 'route_migration';
|
|
16
|
+
topic: string;
|
|
17
|
+
}) => void;
|
|
13
18
|
}
|
|
14
19
|
export interface WorkerClusterOptions {
|
|
15
20
|
/** Namespace for the cluster's storage keys and BroadcastChannel.
|
|
@@ -131,7 +136,7 @@ export declare class WorkerClusterRuntime {
|
|
|
131
136
|
* posted to a remote owner, so the caller can surface the failure instead of
|
|
132
137
|
* silently dropping the publication.
|
|
133
138
|
*/
|
|
134
|
-
publish(topic: string, data: unknown): boolean;
|
|
139
|
+
publish(topic: string, data: unknown, messageId?: string): boolean;
|
|
135
140
|
/** True when `route` exists and its owner worker is among `workers`.
|
|
136
141
|
* Shared by subscribe (skip re-assignment) and publish (route to owner).
|
|
137
142
|
* Intentionally returns a plain boolean (not a type guard) so the caller
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cluster.d.ts","sourceRoot":"","sources":["../../src/core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B,2EAA2E;IAC3E,OAAO,CAAC,UAAU;IAUlB;;qCAEiC;IACjC,OAAO,CAAC,gBAAgB;IAgBxB,yFAAyF;IACzF,OAAO,CAAC,YAAY;IAYpB,8EAA8E;IAC9E,OAAO,CAAC,qBAAqB;IAU7B,oEAAoE;IACpE,OAAO,CAAC,0BAA0B;IAQlC,8DAA8D;IAC9D,OAAO,CAAC,eAAe;IAQvB;;;;;0CAKsC;IACtC,OAAO,CAAC,WAAW;IAMnB,4EAA4E;IAC5E,OAAO,CAAC,cAAc;IAItB,8GAA8G;IAC9G,OAAO,CAAC,WAAW;IAOnB,kGAAkG;IAClG,OAAO,CAAC,UAAU;IAOlB;;;;;;;;;;OAUG;IACH,OAAO,CAAC,aAAa;IA6BrB,OAAO,CAAC,gBAAgB;IAIxB,OAAO,CAAC,eAAe;IAIvB,OAAO,CAAC,oBAAoB;IAI5B,OAAO,CAAC,aAAa;IAQrB,8EAA8E;IAC9E,OAAO,CAAC,YAAY;CAGrB"}
|
package/dist/core/data-bus.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { WorkerClusterOptions } from './cluster';
|
|
2
|
-
import type { DataBusErrorHandler, DataBusMessageHandler, DataBusStatusHandler, DataBusTransport, WorkerStatus } from './types';
|
|
2
|
+
import type { DataBusErrorHandler, DataBusMessageHandler, DataBusPublishOptions, DataBusStatusHandler, DataBusTransport, WorkerStatus } from './types';
|
|
3
3
|
import type { DataBusTraceOptions } from './trace';
|
|
4
4
|
import type { DataBusReplayPersistence } from './replay-persistence';
|
|
5
5
|
/** Constructor options for {@link CrossTabDataBus}. Extends WorkerClusterOptions
|
|
@@ -17,6 +17,11 @@ export interface DataBusReplayOptions<TData = unknown> {
|
|
|
17
17
|
/** Optional durable history backend. Defaults to in-memory only. */
|
|
18
18
|
persistence?: DataBusReplayPersistence<TData>;
|
|
19
19
|
}
|
|
20
|
+
/** Opt-in bounded duplicate suppression for publications carrying `messageId`. */
|
|
21
|
+
export interface DataBusDedupOptions {
|
|
22
|
+
maxEntries?: number;
|
|
23
|
+
ttlMs?: number;
|
|
24
|
+
}
|
|
20
25
|
export interface CrossTabDataBusOptions<TConfig, TData> extends Omit<WorkerClusterOptions, 'handlers'> {
|
|
21
26
|
transport: DataBusTransport<TConfig, TData>;
|
|
22
27
|
initialConfig?: TConfig;
|
|
@@ -24,6 +29,8 @@ export interface CrossTabDataBusOptions<TConfig, TData> extends Omit<WorkerClust
|
|
|
24
29
|
trace?: DataBusTraceOptions;
|
|
25
30
|
/** Opt-in bounded per-topic history. Absent → no buffering, zero overhead. */
|
|
26
31
|
replay?: DataBusReplayOptions<TData>;
|
|
32
|
+
/** Optional duplicate suppression; absent means every publication is delivered. */
|
|
33
|
+
dedup?: DataBusDedupOptions;
|
|
27
34
|
}
|
|
28
35
|
/**
|
|
29
36
|
* High-level cross-tab pub/sub client.
|
|
@@ -47,6 +54,10 @@ export declare class CrossTabDataBus<TConfig = unknown, TData = unknown> {
|
|
|
47
54
|
private readonly initialConfig;
|
|
48
55
|
private readonly hasInitialConfig;
|
|
49
56
|
private readonly trace;
|
|
57
|
+
private readonly dedupMaxEntries;
|
|
58
|
+
private readonly dedupTtlMs;
|
|
59
|
+
private readonly dedupEnabled;
|
|
60
|
+
private readonly seenMessageIds;
|
|
50
61
|
private activeConfig;
|
|
51
62
|
private status;
|
|
52
63
|
private started;
|
|
@@ -93,8 +104,10 @@ export declare class CrossTabDataBus<TConfig = unknown, TData = unknown> {
|
|
|
93
104
|
* caller used the `unsubscribe(topic)` form expecting a full teardown.
|
|
94
105
|
* The cluster is only notified on the n→0 transition (handlers.size === 0). */
|
|
95
106
|
unsubscribe(topic: string, handler?: DataBusMessageHandler<TData>): void;
|
|
107
|
+
/** Clear all in-memory replay buffers and, when supported, durable history. */
|
|
108
|
+
clearReplay(): Promise<void>;
|
|
96
109
|
/** Publish a message to `topic`. The owning Worker delivers it to the transport. */
|
|
97
|
-
publish(topic: string, data: unknown): void;
|
|
110
|
+
publish(topic: string, data: unknown, options?: DataBusPublishOptions): void;
|
|
98
111
|
/** Register a handler that fires on every transport status change. Immediately invoked with the current status. */
|
|
99
112
|
onStatus(handler: DataBusStatusHandler): () => void;
|
|
100
113
|
/** Register a handler for transport errors. */
|
|
@@ -116,6 +129,7 @@ export declare class CrossTabDataBus<TConfig = unknown, TData = unknown> {
|
|
|
116
129
|
* and dispatches locally.
|
|
117
130
|
*/
|
|
118
131
|
private handleTransportMessage;
|
|
132
|
+
private isDuplicate;
|
|
119
133
|
/** Deliver a message to every local handler registered for its topic,
|
|
120
134
|
* plus every handler registered with a wildcard subscription that matches
|
|
121
135
|
* (e.g. a handler subscribed to "chat.*" receives "chat.room.1"). */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"data-bus.d.ts","sourceRoot":"","sources":["../../src/core/data-bus.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAC;AAEtD,OAAO,KAAK,EACV,mBAAmB,EAEnB,qBAAqB,EACrB,oBAAoB,EACpB,gBAAgB,EAChB,YAAY,EACb,MAAM,SAAS,CAAC;AAEjB,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,sBAAsB,CAAC;AAcrE;;wBAEwB;AACxB;;;;mBAImB;AACnB,MAAM,WAAW,oBAAoB,CAAC,KAAK,GAAG,OAAO;IACnD;6BACyB;IACzB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,oEAAoE;IACpE,WAAW,CAAC,EAAE,wBAAwB,CAAC,KAAK,CAAC,CAAC;CAC/C;AAED,MAAM,WAAW,sBAAsB,CAAC,OAAO,EAAE,KAAK,CACpD,SAAQ,IAAI,CAAC,oBAAoB,EAAE,UAAU,CAAC;IAC9C,SAAS,EAAE,gBAAgB,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;IAC5C,aAAa,CAAC,EAAE,OAAO,CA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qCAIiC;IACjC,OAAO,CAAC,aAAa;IAqBrB;;;OAGG;IACH,OAAO,CAAC,YAAY;IAiCpB,OAAO,CAAC,WAAW;IAKnB,OAAO,CAAC,iBAAiB;IASzB,8DAA8D;IAC9D,OAAO,CAAC,kBAAkB;IAO1B,OAAO,CAAC,oBAAoB;IAM5B;;;;+CAI2C;IAC3C,OAAO,CAAC,cAAc;IAoBtB;;;OAGG;IACH,OAAO,CAAC,gBAAgB;IAwBxB;qEACiE;IACjE,OAAO,CAAC,iBAAiB;IAMzB;;;;;OAKG;IACH,OAAO,CAAC,eAAe;IAIvB;;;;;OAKG;IACH,OAAO,CAAC,eAAe;IAiCvB;;;;OAIG;IACH,OAAO,CAAC,YAAY;IA6BpB;;;OAGG;IACH,OAAO,CAAC,aAAa;CAUtB"}
|
|
@@ -3,6 +3,10 @@ import type { DataBusMessage } from './types';
|
|
|
3
3
|
export interface DataBusReplayPersistence<TData = unknown> {
|
|
4
4
|
load(): Promise<ReadonlyArray<DataBusMessage<TData>>>;
|
|
5
5
|
append(message: DataBusMessage<TData>): Promise<void>;
|
|
6
|
+
/** Remove all persisted replay history. */
|
|
7
|
+
clear?(): Promise<void>;
|
|
8
|
+
/** Remove persisted replay history for one exact topic. */
|
|
9
|
+
clearTopic?(topic: string): Promise<void>;
|
|
6
10
|
}
|
|
7
11
|
export interface IndexedDbReplayPersistenceOptions {
|
|
8
12
|
dbName?: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"replay-persistence.d.ts","sourceRoot":"","sources":["../../src/core/replay-persistence.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAE9C,uDAAuD;AACvD,MAAM,WAAW,wBAAwB,CAAC,KAAK,GAAG,OAAO;IACvD,IAAI,IAAI,OAAO,CAAC,aAAa,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IACtD,MAAM,CAAC,OAAO,EAAE,cAAc,CAAC,KAAK,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"replay-persistence.d.ts","sourceRoot":"","sources":["../../src/core/replay-persistence.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAE9C,uDAAuD;AACvD,MAAM,WAAW,wBAAwB,CAAC,KAAK,GAAG,OAAO;IACvD,IAAI,IAAI,OAAO,CAAC,aAAa,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IACtD,MAAM,CAAC,OAAO,EAAE,cAAc,CAAC,KAAK,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACtD,2CAA2C;IAC3C,KAAK,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IACxB,2DAA2D;IAC3D,UAAU,CAAC,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC3C;AAED,MAAM,WAAW,iCAAiC;IAChD,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,MAAM,CAAC;CACrB;AAED,sDAAsD;AACtD,wBAAgB,gCAAgC,CAAC,KAAK,GAAG,OAAO,EAC9D,OAAO,EAAE,iCAAiC,GACzC,wBAAwB,CAAC,KAAK,CAAC,CA+DjC"}
|
package/dist/core/trace.d.ts
CHANGED
|
@@ -48,6 +48,15 @@ export interface DataBusErrorTraceEvent {
|
|
|
48
48
|
source: 'transport' | 'operation';
|
|
49
49
|
timestamp: number;
|
|
50
50
|
}
|
|
51
|
+
/** Bounded reliability diagnostics for recovery, acknowledgments, and migrations. */
|
|
52
|
+
export interface DataBusReliabilityTraceEvent {
|
|
53
|
+
type: 'reliability';
|
|
54
|
+
operation: 'transport_recovery' | 'route_ack' | 'route_migration' | 'persistence_cleanup' | 'dedup_suppressed';
|
|
55
|
+
topic?: string;
|
|
56
|
+
attempt?: number;
|
|
57
|
+
durationMs?: number;
|
|
58
|
+
timestamp: number;
|
|
59
|
+
}
|
|
51
60
|
/**
|
|
52
61
|
* Periodic metrics snapshot: message throughput, dispatch latency percentiles,
|
|
53
62
|
* and active topic count. Aggregated over the interval and emitted every
|
|
@@ -66,7 +75,7 @@ export interface DataBusMetricsTraceEvent {
|
|
|
66
75
|
dispatchMaxMs: number;
|
|
67
76
|
timestamp: number;
|
|
68
77
|
}
|
|
69
|
-
export type DataBusTraceEvent = DataBusLifecycleTraceEvent | DataBusStatusTraceEvent | DataBusSubscriptionTraceEvent | DataBusCoordinationTraceEvent | DataBusErrorTraceEvent | DataBusMetricsTraceEvent;
|
|
78
|
+
export type DataBusTraceEvent = DataBusLifecycleTraceEvent | DataBusStatusTraceEvent | DataBusSubscriptionTraceEvent | DataBusCoordinationTraceEvent | DataBusErrorTraceEvent | DataBusReliabilityTraceEvent | DataBusMetricsTraceEvent;
|
|
70
79
|
/** Distributive-conditional type: given a trace event union, derive the same shape minus `timestamp`. */
|
|
71
80
|
type DataBusTraceEventInput = DataBusTraceEvent extends infer TEvent ? TEvent extends DataBusTraceEvent ? Omit<TEvent, 'timestamp'> : never : never;
|
|
72
81
|
/** Configuration for {@link DataBusTraceReporter}. `sink` receives every
|
package/dist/core/trace.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"trace.d.ts","sourceRoot":"","sources":["../../src/core/trace.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAE5C,uEAAuE;AACvE;;;yDAGyD;AACzD,MAAM,MAAM,gBAAgB,GAAG,QAAQ,GAAG,SAAS,GAAG,KAAK,CAAC;AAE5D,oEAAoE;AACpE,MAAM,WAAW,0BAA0B;IACzC,IAAI,EAAE,WAAW,CAAC;IAClB,MAAM,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,GAAG,QAAQ,CAAC;IAChD,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,4DA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E,MAAM,GAAG,IAAI;IAkBnC;;;;OAIG;IACH,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAQpC;;;;;OAKG;IACH,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAgBrC;;iFAE6E;IAC7E,OAAO,KAAK,aAAa,GAExB;IAED,uEAAuE;IACvE,KAAK,IAAI,IAAI;IAKb,OAAO,CAAC,QAAQ;IA0BhB,OAAO,CAAC,YAAY;IAUpB,OAAO,CAAC,IAAI;CAWb"}
|
package/dist/core/types.d.ts
CHANGED
|
@@ -19,6 +19,11 @@ export type WorkerStatus = 'connecting' | 'connected' | 'disconnected' | 'error'
|
|
|
19
19
|
/** Control-plane actions routed between Workers via BroadcastChannel.
|
|
20
20
|
* These are the three operations a subscriber asks the owning worker to perform. */
|
|
21
21
|
export type WorkerControlAction = 'SUBSCRIBE' | 'UNSUBSCRIBE' | 'PUBLISH';
|
|
22
|
+
/** Optional metadata attached to an outbound publication. */
|
|
23
|
+
export interface DataBusPublishOptions {
|
|
24
|
+
/** Stable caller/server identifier propagated through the cluster and wire protocol. */
|
|
25
|
+
messageId?: string;
|
|
26
|
+
}
|
|
22
27
|
/** Whether the tab is currently visible to the user. Only influences placement
|
|
23
28
|
* of NEW topic routes; existing routes are sticky and never migrated on hide. */
|
|
24
29
|
export type TabVisibilityState = 'visible' | 'hidden';
|
|
@@ -94,6 +99,8 @@ export type WorkerClusterMessage<TEvent = unknown> =
|
|
|
94
99
|
topicKey: string;
|
|
95
100
|
/** Present only for PUBLISH actions; the publication payload. */
|
|
96
101
|
data?: unknown;
|
|
102
|
+
/** Optional stable identifier for the publication. */
|
|
103
|
+
messageId?: string;
|
|
97
104
|
}
|
|
98
105
|
/** The owning worker fans out a publication to every tab. `eventType`
|
|
99
106
|
* distinguishes databus publications from future event types. */
|
|
@@ -124,6 +131,8 @@ export type WorkerClusterMessage<TEvent = unknown> =
|
|
|
124
131
|
export interface DataBusMessage<TData = unknown> {
|
|
125
132
|
topic: string;
|
|
126
133
|
data: TData;
|
|
134
|
+
/** Optional caller/server supplied stable identifier used by opt-in dedup. */
|
|
135
|
+
messageId?: string;
|
|
127
136
|
/** True when this delivery is a historical replay (see the `replay`
|
|
128
137
|
* subscription option) rather than a live publication. */
|
|
129
138
|
replayed?: boolean;
|
|
@@ -157,7 +166,7 @@ export interface DataBusTransport<TConfig = unknown, TData = unknown> {
|
|
|
157
166
|
/** Unsubscribe from a topic. Idempotent: unsubscribing a non-subscribed topic is a no-op. */
|
|
158
167
|
unsubscribe(topic: string): MaybePromise<void>;
|
|
159
168
|
/** Publish `data` to `topic` via the server. */
|
|
160
|
-
publish(topic: string, data: unknown): MaybePromise<void>;
|
|
169
|
+
publish(topic: string, data: unknown, options?: DataBusPublishOptions): MaybePromise<void>;
|
|
161
170
|
/** Close the connection and release all resources. Safe to call multiple times. */
|
|
162
171
|
stop(): MaybePromise<void>;
|
|
163
172
|
}
|
package/dist/core/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/core/types.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH;;+DAE+D;AAC/D,MAAM,MAAM,YAAY,CAAC,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;AAE7C;;iFAEiF;AACjF,MAAM,MAAM,UAAU,GAAG,QAAQ,GAAG,SAAS,CAAC;AAE9C;0EAC0E;AAC1E,MAAM,MAAM,YAAY,GAAG,YAAY,GAAG,WAAW,GAAG,cAAc,GAAG,OAAO,CAAC;AAEjF;oFACoF;AACpF,MAAM,MAAM,mBAAmB,GAAG,WAAW,GAAG,aAAa,GAAG,SAAS,CAAC;AAE1E;iFACiF;AACjF,MAAM,MAAM,kBAAkB,GAAG,SAAS,GAAG,QAAQ,CAAC;AAEtD;;;GAGG;AACH,MAAM,WAAW,YAAY;IAC3B,mFAAmF;IACnF,QAAQ,EAAE,MAAM,CAAC;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9,10 +9,10 @@
|
|
|
9
9
|
* ```
|
|
10
10
|
*/
|
|
11
11
|
export { CrossTabDataBus } from './core/data-bus';
|
|
12
|
-
export type { CrossTabDataBusOptions, DataBusReplayOptions } from './core/data-bus';
|
|
12
|
+
export type { CrossTabDataBusOptions, DataBusDedupOptions, DataBusReplayOptions } from './core/data-bus';
|
|
13
13
|
export { createIndexedDbReplayPersistence } from './core/replay-persistence';
|
|
14
14
|
export type { DataBusReplayPersistence, IndexedDbReplayPersistenceOptions } from './core/replay-persistence';
|
|
15
|
-
export type { DataBusCoordinationTraceEvent, DataBusErrorTraceEvent, DataBusLifecycleTraceEvent, DataBusMetricsTraceEvent, DataBusStatusTraceEvent, DataBusSubscriptionTraceEvent, DataBusTraceEvent, DataBusTraceMode, DataBusTraceOptions } from './core/trace';
|
|
15
|
+
export type { DataBusCoordinationTraceEvent, DataBusErrorTraceEvent, DataBusLifecycleTraceEvent, DataBusMetricsTraceEvent, DataBusReliabilityTraceEvent, DataBusStatusTraceEvent, DataBusSubscriptionTraceEvent, DataBusTraceEvent, DataBusTraceMode, DataBusTraceOptions } from './core/trace';
|
|
16
16
|
export { WorkerClusterRuntime } from './core/cluster';
|
|
17
17
|
export type { WorkerClusterHandlers, WorkerClusterOptions, WorkerClusterSnapshot } from './core/cluster';
|
|
18
18
|
export { createBrowserEnvironment, getOrCreateTabId } from './core/environment';
|
|
@@ -23,5 +23,5 @@ export type { CreateWebSocketDataBusOptions, WebSocketDataBusConfig, WebSocketLi
|
|
|
23
23
|
export { selectWorkerBackend } from './worker-mode';
|
|
24
24
|
export type { WorkerBackend, WorkerMode } from './worker-mode';
|
|
25
25
|
export { DEFAULT_MAX_ACTIVE_WORKERS, hasActiveOwner, isWildcardTopic, selectActiveWorkers, selectLeastLoadedWorker, selectRebalanceTarget, topicMatchesPattern } from './core/routing';
|
|
26
|
-
export type { DataBusErrorHandler, DataBusMessage, DataBusMessageHandler, DataBusStatusHandler, DataBusTransport, DataBusTransportHandlers, MaybePromise, TabVisibilityState, TopicSubscriberRecord, WorkerClusterMessage, WorkerControlAction, WorkerRecord, WorkerRole, WorkerRoute, WorkerStatus } from './core/types';
|
|
26
|
+
export type { DataBusErrorHandler, DataBusMessage, DataBusPublishOptions, DataBusMessageHandler, DataBusStatusHandler, DataBusTransport, DataBusTransportHandlers, MaybePromise, TabVisibilityState, TopicSubscriberRecord, WorkerClusterMessage, WorkerControlAction, WorkerRecord, WorkerRole, WorkerRoute, WorkerStatus } from './core/types';
|
|
27
27
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAClD,YAAY,EAAE,sBAAsB,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAClD,YAAY,EAAE,sBAAsB,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AACzG,OAAO,EAAE,gCAAgC,EAAE,MAAM,2BAA2B,CAAC;AAC7E,YAAY,EAAE,wBAAwB,EAAE,iCAAiC,EAAE,MAAM,2BAA2B,CAAC;AAC7G,YAAY,EACV,6BAA6B,EAC7B,sBAAsB,EACtB,0BAA0B,EAC1B,wBAAwB,EACxB,4BAA4B,EAC5B,uBAAuB,EACvB,6BAA6B,EAC7B,iBAAiB,EACjB,gBAAgB,EAChB,mBAAmB,EACpB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AACtD,YAAY,EACV,qBAAqB,EACrB,oBAAoB,EACpB,qBAAqB,EACtB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,wBAAwB,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAChF,YAAY,EAAE,cAAc,EAAE,kBAAkB,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAC1F,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,EACL,kBAAkB,EAClB,sBAAsB,EACvB,MAAM,aAAa,CAAC;AACrB,YAAY,EACV,6BAA6B,EAC7B,sBAAsB,EACtB,aAAa,EACd,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AACpD,YAAY,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC/D,OAAO,EACL,0BAA0B,EAC1B,cAAc,EACd,eAAe,EACf,mBAAmB,EACnB,uBAAuB,EACvB,qBAAqB,EACrB,mBAAmB,EACpB,MAAM,gBAAgB,CAAC;AACxB,YAAY,EACV,mBAAmB,EACnB,cAAc,EACd,qBAAqB,EACrB,qBAAqB,EACrB,oBAAoB,EACpB,gBAAgB,EAChB,wBAAwB,EACxB,YAAY,EACZ,kBAAkB,EAClB,qBAAqB,EACrB,oBAAoB,EACpB,mBAAmB,EACnB,YAAY,EACZ,UAAU,EACV,WAAW,EACX,YAAY,EACb,MAAM,cAAc,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -12,7 +12,7 @@ import {
|
|
|
12
12
|
selectRebalanceTarget,
|
|
13
13
|
selectWorkerBackend,
|
|
14
14
|
topicMatchesPattern
|
|
15
|
-
} from "./chunk-
|
|
15
|
+
} from "./chunk-WWUY2FV2.js";
|
|
16
16
|
|
|
17
17
|
// src/core/replay-persistence.ts
|
|
18
18
|
function createIndexedDbReplayPersistence(options) {
|
|
@@ -58,6 +58,24 @@ function createIndexedDbReplayPersistence(options) {
|
|
|
58
58
|
transaction.oncomplete = () => resolve();
|
|
59
59
|
transaction.onerror = () => reject(transaction.error ?? new Error("Failed to persist replay history."));
|
|
60
60
|
});
|
|
61
|
+
},
|
|
62
|
+
async clear() {
|
|
63
|
+
const db = await open();
|
|
64
|
+
await new Promise((resolve, reject) => {
|
|
65
|
+
const transaction = db.transaction(storeName, "readwrite");
|
|
66
|
+
transaction.objectStore(storeName).clear();
|
|
67
|
+
transaction.oncomplete = () => resolve();
|
|
68
|
+
transaction.onerror = () => reject(transaction.error ?? new Error("Failed to clear replay history."));
|
|
69
|
+
});
|
|
70
|
+
},
|
|
71
|
+
async clearTopic(topic) {
|
|
72
|
+
const db = await open();
|
|
73
|
+
await new Promise((resolve, reject) => {
|
|
74
|
+
const transaction = db.transaction(storeName, "readwrite");
|
|
75
|
+
transaction.objectStore(storeName).delete(topic);
|
|
76
|
+
transaction.oncomplete = () => resolve();
|
|
77
|
+
transaction.onerror = () => reject(transaction.error ?? new Error("Failed to clear topic replay history."));
|
|
78
|
+
});
|
|
61
79
|
}
|
|
62
80
|
};
|
|
63
81
|
}
|
|
@@ -109,12 +127,12 @@ var WebSocketTransport = class {
|
|
|
109
127
|
this.sendFrame({ op: "unsubscribe", topic });
|
|
110
128
|
}
|
|
111
129
|
/** Publish `data` to `topic` as a JSON frame. Requires an open socket. */
|
|
112
|
-
publish(topic, data) {
|
|
130
|
+
publish(topic, data, options) {
|
|
113
131
|
if (data instanceof ArrayBuffer) {
|
|
114
|
-
this.sendBinaryFrame(topic, data);
|
|
132
|
+
this.sendBinaryFrame(topic, data, options?.messageId);
|
|
115
133
|
return;
|
|
116
134
|
}
|
|
117
|
-
this.sendFrame({ op: "publish", topic, data });
|
|
135
|
+
this.sendFrame({ op: "publish", topic, data, ...options?.messageId ? { messageId: options.messageId } : {} });
|
|
118
136
|
}
|
|
119
137
|
/** Close the socket and drop all state. Safe to call multiple times. */
|
|
120
138
|
stop() {
|
|
@@ -134,7 +152,11 @@ var WebSocketTransport = class {
|
|
|
134
152
|
}
|
|
135
153
|
this.socket.send(JSON.stringify(payload));
|
|
136
154
|
}
|
|
137
|
-
sendBinaryFrame(topic, data) {
|
|
155
|
+
sendBinaryFrame(topic, data, messageId) {
|
|
156
|
+
if (messageId) {
|
|
157
|
+
this.sendFrame({ op: "publish", topic, data: Array.from(new Uint8Array(data)), messageId });
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
138
160
|
if (this.socket?.readyState !== WS_OPEN) {
|
|
139
161
|
this.handlers?.onError(new Error('WebSocket is not open; dropped "publish" frame.'));
|
|
140
162
|
return;
|
|
@@ -176,7 +198,12 @@ var WebSocketTransport = class {
|
|
|
176
198
|
if (!parsed || typeof parsed !== "object") return;
|
|
177
199
|
const frame = parsed;
|
|
178
200
|
if (typeof frame.topic !== "string") return;
|
|
179
|
-
|
|
201
|
+
const message = {
|
|
202
|
+
topic: frame.topic,
|
|
203
|
+
data: frame.data,
|
|
204
|
+
...typeof frame.messageId === "string" ? { messageId: frame.messageId } : {}
|
|
205
|
+
};
|
|
206
|
+
this.handlers?.onMessage(message);
|
|
180
207
|
}
|
|
181
208
|
};
|
|
182
209
|
function defaultWebSocketFactory(url, protocols) {
|
package/dist/index.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/core/replay-persistence.ts", "../src/websocket.ts"],
|
|
4
|
-
"sourcesContent": ["import type { DataBusMessage } from './types';\n\n/** Optional persistence backend for replay history. */\nexport interface DataBusReplayPersistence<TData = unknown> {\n load(): Promise<ReadonlyArray<DataBusMessage<TData>>>;\n append(message: DataBusMessage<TData>): Promise<void>;\n}\n\nexport interface IndexedDbReplayPersistenceOptions {\n dbName?: string;\n maxPerTopic: number;\n}\n\n/** Create a browser IndexedDB-backed replay store. */\nexport function createIndexedDbReplayPersistence<TData = unknown>(\n options: IndexedDbReplayPersistenceOptions\n): DataBusReplayPersistence<TData> {\n const indexedDb = globalThis.indexedDB;\n if (!indexedDb) throw new Error('IndexedDB is unavailable in this environment.');\n const dbName = options.dbName ?? 'cross-tab-worker-databus';\n const storeName = 'replay';\n const maxPerTopic = options.maxPerTopic;\n if (!Number.isSafeInteger(maxPerTopic) || maxPerTopic <= 0) {\n throw new TypeError(`maxPerTopic must be a positive safe integer, got ${String(maxPerTopic)}.`);\n }\n let dbPromise: Promise<IDBDatabase> | null = null;\n const open = (): Promise<IDBDatabase> => {\n if (dbPromise) return dbPromise;\n dbPromise = new Promise((resolve, reject) => {\n const request = indexedDb.open(dbName, 1);\n request.onupgradeneeded = () => request.result.createObjectStore(storeName, { keyPath: 'topic' });\n request.onsuccess = () => resolve(request.result);\n request.onerror = () => reject(request.error ?? new Error('Failed to open replay database.'));\n });\n return dbPromise;\n };\n return {\n async load() {\n const db = await open();\n return new Promise((resolve, reject) => {\n const request = db.transaction(storeName, 'readonly').objectStore(storeName).getAll();\n request.onsuccess = () => resolve(request.result.flatMap(record => record.messages as DataBusMessage<TData>[]));\n request.onerror = () => reject(request.error ?? new Error('Failed to load replay history.'));\n });\n },\n async append(message) {\n const db = await open();\n await new Promise<void>((resolve, reject) => {\n const transaction = db.transaction(storeName, 'readwrite');\n const store = transaction.objectStore(storeName);\n const request = store.get(message.topic);\n request.onsuccess = () => {\n const messages = ((request.result?.messages ?? []) as DataBusMessage<TData>[]).concat(message).slice(-maxPerTopic);\n store.put({ topic: message.topic, messages });\n };\n request.onerror = () => reject(request.error ?? new Error('Failed to read replay history.'));\n transaction.oncomplete = () => resolve();\n transaction.onerror = () => reject(transaction.error ?? new Error('Failed to persist replay history.'));\n });\n }\n };\n}\n", "/**\n * WebSocketTransport \u2014 a dependency-free transport over a plain WebSocket.\n *\n * Validates the `DataBusTransport` abstraction with a second, minimal backend:\n * any WebSocket server that speaks the tiny JSON protocol below can back the\n * same cross-tab clustering stack (owner dedup, sticky routes, EVENT fan-out)\n * that the Centrifuge backend uses.\n *\n * Wire protocol (JSON text frames):\n * - client \u2192 server: `{\"op\":\"subscribe\"|\"unsubscribe\"|\"publish\",\"topic\":...,\"data\":...}`\n * - server \u2192 client: `{\"topic\":...,\"data\":...}` for publications; anything\n * without a string `topic` field is ignored (forward-compatible).\n */\nimport { CrossTabDataBus } from './core/data-bus';\nimport type { CrossTabDataBusOptions } from './core/data-bus';\nimport type {\n DataBusTransport,\n DataBusTransportHandlers,\n MaybePromise,\n WorkerStatus\n} from './core/types';\n\n/** Minimal WebSocket surface used by the transport. Matches the browser\n * `WebSocket` subset the transport touches; injectable for tests and runtimes. */\nexport interface WebSocketLike {\n /** Current connection state; 1 (OPEN) means frames may be sent. */\n readonly readyState?: number;\n send(data: string | ArrayBuffer): void;\n close(code?: number, reason?: string): void;\n onopen: (() => void) | null;\n onclose: (() => void) | null;\n onerror: (() => void) | null;\n onmessage: ((event: { data: unknown }) => void) | null;\n}\n\n/** Connection configuration for {@link WebSocketTransport}. */\nexport interface WebSocketDataBusConfig {\n /** WebSocket endpoint, e.g. `wss://example.test/ws`. */\n url: string;\n /** Subprotocol(s) passed to the WebSocket handshake. */\n protocols?: string | string[];\n /** Custom socket factory. Defaults to the global `WebSocket`; injectable\n * for tests and non-browser runtimes. */\n webSocketFactory?: (url: string, protocols?: string | string[]) => WebSocketLike;\n}\n\n/** Options for creating a fully-configured CrossTabDataBus with a WebSocket transport. */\nexport interface CreateWebSocketDataBusOptions<TData = unknown>\n extends Omit<\n CrossTabDataBusOptions<WebSocketDataBusConfig, TData>,\n 'autoStart' | 'clusterKey' | 'initialConfig' | 'transport'\n > {\n /** WebSocket connection configuration. */\n connection: WebSocketDataBusConfig;\n /** Cluster key for cross-tab coordination. Defaults to the connection URL. */\n clusterKey?: string;\n}\n\nconst WS_OPEN = 1;\n\n/** Transport that talks a minimal JSON protocol over a plain WebSocket.\n * Connection lifecycle maps directly to the DataBus status vocabulary:\n * open \u2192 `connected`, close \u2192 `disconnected`, error \u2192 `error` (which the\n * DataBus treats as its auto-recovery trigger). The transport holds no\n * reconnection logic of its own \u2014 reopening is the DataBus's job. */\nexport class WebSocketTransport<TData = unknown>\n implements DataBusTransport<WebSocketDataBusConfig, TData>\n{\n private socket: WebSocketLike | null = null;\n private handlers: DataBusTransportHandlers<TData> | null = null;\n private readonly subscribedTopics = new Set<string>();\n\n constructor(private readonly connection: WebSocketDataBusConfig) {}\n\n /** Open the WebSocket and wire lifecycle listeners. A factory failure is\n * reported through `onStatus('error')` so the DataBus can recover. */\n start(config: WebSocketDataBusConfig, handlers: DataBusTransportHandlers<TData>): MaybePromise<void> {\n if (this.socket) return;\n this.handlers = handlers;\n // The factory may live on the constructor connection (createWebSocketDataBus\n // path) or on the runtime config (direct transport use) \u2014 accept both.\n const factory = config.webSocketFactory ?? this.connection.webSocketFactory ?? defaultWebSocketFactory;\n const protocols = config.protocols ?? this.connection.protocols;\n let socket: WebSocketLike;\n try {\n socket = factory(config.url, protocols);\n } catch (error) {\n handlers.onStatus('error');\n handlers.onError(error);\n return;\n }\n socket.onopen = () => {\n // Re-assert every topic so a reopened socket (recovery path) restores\n // the server-side subscriptions without DataBus involvement.\n for (const topic of this.subscribedTopics) {\n this.sendFrame({ op: 'subscribe', topic });\n }\n handlers.onStatus('connected');\n };\n socket.onclose = () => handlers.onStatus('disconnected');\n socket.onerror = () => handlers.onStatus('error');\n socket.onmessage = event => this.handleMessage(event.data);\n this.socket = socket;\n }\n\n /** Idempotent: re-subscribing an active topic re-sends the frame but does\n * not duplicate the local tracking entry. */\n subscribe(topic: string): MaybePromise<void> {\n this.subscribedTopics.add(topic);\n this.sendFrame({ op: 'subscribe', topic });\n }\n\n /** Idempotent: unsubscribing an unknown topic is a no-op. */\n unsubscribe(topic: string): MaybePromise<void> {\n this.subscribedTopics.delete(topic);\n this.sendFrame({ op: 'unsubscribe', topic });\n }\n\n /** Publish `data` to `topic` as a JSON frame. Requires an open socket. */\n publish(topic: string, data: unknown): MaybePromise<void> {\n if (data instanceof ArrayBuffer) {\n this.sendBinaryFrame(topic, data);\n return;\n }\n this.sendFrame({ op: 'publish', topic, data });\n }\n\n /** Close the socket and drop all state. Safe to call multiple times. */\n stop(): MaybePromise<void> {\n const socket = this.socket;\n this.socket = null;\n this.handlers = null;\n this.subscribedTopics.clear();\n socket?.close();\n }\n\n /** Send one JSON frame. Frames are dropped with an `onError` report when\n * the socket is not open \u2014 subscribe frames are re-sent on open, so the\n * only real loss is a publish during a disconnect window. */\n private sendFrame(payload: { op: string; topic: string; data?: unknown }): void {\n if (this.socket?.readyState !== WS_OPEN) {\n this.handlers?.onError(new Error(`WebSocket is not open; dropped \"${payload.op}\" frame.`));\n return;\n }\n this.socket.send(JSON.stringify(payload));\n }\n\n private sendBinaryFrame(topic: string, data: ArrayBuffer): void {\n if (this.socket?.readyState !== WS_OPEN) {\n this.handlers?.onError(new Error('WebSocket is not open; dropped \"publish\" frame.'));\n return;\n }\n const topicBytes = new TextEncoder().encode(topic);\n if (topicBytes.length > 0xffff) {\n this.handlers?.onError(new Error('WebSocket topic is too long for a binary frame.'));\n return;\n }\n const frame = new Uint8Array(3 + topicBytes.length + data.byteLength);\n frame[0] = 0xc7;\n new DataView(frame.buffer).setUint16(1, topicBytes.length);\n frame.set(topicBytes, 3);\n frame.set(new Uint8Array(data), 3 + topicBytes.length);\n this.socket.send(frame.buffer);\n }\n\n /** Parse a server frame. Only objects carrying a string `topic` are\n * publications; malformed JSON and unknown shapes are ignored so a chatty\n * server cannot crash the message path. */\n private handleMessage(raw: unknown): void {\n let parsed: unknown;\n if (raw instanceof ArrayBuffer) {\n const bytes = new Uint8Array(raw);\n if (bytes[0] !== 0xc7 || bytes.length < 3) return;\n const topicLength = new DataView(raw).getUint16(1);\n if (bytes.length < 3 + topicLength) return;\n const topic = new TextDecoder().decode(bytes.subarray(3, 3 + topicLength));\n const data = bytes.slice(3 + topicLength).buffer;\n this.handlers?.onMessage({ topic, data: data as TData });\n return;\n }\n if (typeof raw !== 'string') return;\n try {\n parsed = JSON.parse(raw);\n } catch {\n this.handlers?.onError(new Error('WebSocket server sent a non-JSON frame.'));\n return;\n }\n if (!parsed || typeof parsed !== 'object') return;\n const frame = parsed as Record<string, unknown>;\n if (typeof frame.topic !== 'string') return;\n this.handlers?.onMessage({ topic: frame.topic, data: frame.data as TData });\n }\n}\n\n/** Resolve the platform WebSocket, or null in runtimes without one (SSR/Node). */\nfunction defaultWebSocketFactory(url: string, protocols?: string | string[]): WebSocketLike {\n if (typeof WebSocket === 'undefined') {\n throw new Error('WebSocketTransport requires a WebSocket implementation.');\n }\n return new WebSocket(url, protocols) as unknown as WebSocketLike;\n}\n\n/** Create a CrossTabDataBus backed by a plain WebSocket transport.\n * Cross-tab clustering (owner dedup, sticky routes, failover) works identically\n * to the Centrifuge backend \u2014 only the transport I/O differs. */\nexport function createWebSocketDataBus<TData = unknown>(\n options: CreateWebSocketDataBusOptions<TData>\n): CrossTabDataBus<WebSocketDataBusConfig, TData> {\n const { clusterKey, connection, ...dataBusOptions } = options;\n return new CrossTabDataBus({\n ...dataBusOptions,\n autoStart: true,\n clusterKey: clusterKey ?? connection.url,\n initialConfig: connection,\n transport: new WebSocketTransport<TData>(connection)\n });\n}\n\n/** Re-export for convenience: the status type used by the transport. */\nexport type { WorkerStatus };\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;
|
|
4
|
+
"sourcesContent": ["import type { DataBusMessage } from './types';\n\n/** Optional persistence backend for replay history. */\nexport interface DataBusReplayPersistence<TData = unknown> {\n load(): Promise<ReadonlyArray<DataBusMessage<TData>>>;\n append(message: DataBusMessage<TData>): Promise<void>;\n /** Remove all persisted replay history. */\n clear?(): Promise<void>;\n /** Remove persisted replay history for one exact topic. */\n clearTopic?(topic: string): Promise<void>;\n}\n\nexport interface IndexedDbReplayPersistenceOptions {\n dbName?: string;\n maxPerTopic: number;\n}\n\n/** Create a browser IndexedDB-backed replay store. */\nexport function createIndexedDbReplayPersistence<TData = unknown>(\n options: IndexedDbReplayPersistenceOptions\n): DataBusReplayPersistence<TData> {\n const indexedDb = globalThis.indexedDB;\n if (!indexedDb) throw new Error('IndexedDB is unavailable in this environment.');\n const dbName = options.dbName ?? 'cross-tab-worker-databus';\n const storeName = 'replay';\n const maxPerTopic = options.maxPerTopic;\n if (!Number.isSafeInteger(maxPerTopic) || maxPerTopic <= 0) {\n throw new TypeError(`maxPerTopic must be a positive safe integer, got ${String(maxPerTopic)}.`);\n }\n let dbPromise: Promise<IDBDatabase> | null = null;\n const open = (): Promise<IDBDatabase> => {\n if (dbPromise) return dbPromise;\n dbPromise = new Promise((resolve, reject) => {\n const request = indexedDb.open(dbName, 1);\n request.onupgradeneeded = () => request.result.createObjectStore(storeName, { keyPath: 'topic' });\n request.onsuccess = () => resolve(request.result);\n request.onerror = () => reject(request.error ?? new Error('Failed to open replay database.'));\n });\n return dbPromise;\n };\n return {\n async load() {\n const db = await open();\n return new Promise((resolve, reject) => {\n const request = db.transaction(storeName, 'readonly').objectStore(storeName).getAll();\n request.onsuccess = () => resolve(request.result.flatMap(record => record.messages as DataBusMessage<TData>[]));\n request.onerror = () => reject(request.error ?? new Error('Failed to load replay history.'));\n });\n },\n async append(message) {\n const db = await open();\n await new Promise<void>((resolve, reject) => {\n const transaction = db.transaction(storeName, 'readwrite');\n const store = transaction.objectStore(storeName);\n const request = store.get(message.topic);\n request.onsuccess = () => {\n const messages = ((request.result?.messages ?? []) as DataBusMessage<TData>[]).concat(message).slice(-maxPerTopic);\n store.put({ topic: message.topic, messages });\n };\n request.onerror = () => reject(request.error ?? new Error('Failed to read replay history.'));\n transaction.oncomplete = () => resolve();\n transaction.onerror = () => reject(transaction.error ?? new Error('Failed to persist replay history.'));\n });\n },\n async clear() {\n const db = await open();\n await new Promise<void>((resolve, reject) => {\n const transaction = db.transaction(storeName, 'readwrite');\n transaction.objectStore(storeName).clear();\n transaction.oncomplete = () => resolve();\n transaction.onerror = () => reject(transaction.error ?? new Error('Failed to clear replay history.'));\n });\n },\n async clearTopic(topic) {\n const db = await open();\n await new Promise<void>((resolve, reject) => {\n const transaction = db.transaction(storeName, 'readwrite');\n transaction.objectStore(storeName).delete(topic);\n transaction.oncomplete = () => resolve();\n transaction.onerror = () => reject(transaction.error ?? new Error('Failed to clear topic replay history.'));\n });\n }\n };\n}\n", "/**\n * WebSocketTransport \u2014 a dependency-free transport over a plain WebSocket.\n *\n * Validates the `DataBusTransport` abstraction with a second, minimal backend:\n * any WebSocket server that speaks the tiny JSON protocol below can back the\n * same cross-tab clustering stack (owner dedup, sticky routes, EVENT fan-out)\n * that the Centrifuge backend uses.\n *\n * Wire protocol (JSON text frames):\n * - client \u2192 server: `{\"op\":\"subscribe\"|\"unsubscribe\"|\"publish\",\"topic\":...,\"data\":...}`\n * - server \u2192 client: `{\"topic\":...,\"data\":...}` for publications; anything\n * without a string `topic` field is ignored (forward-compatible).\n */\nimport { CrossTabDataBus } from './core/data-bus';\nimport type { CrossTabDataBusOptions } from './core/data-bus';\nimport type {\n DataBusTransport,\n DataBusTransportHandlers,\n DataBusPublishOptions,\n DataBusMessage,\n MaybePromise,\n WorkerStatus\n} from './core/types';\n\n/** Minimal WebSocket surface used by the transport. Matches the browser\n * `WebSocket` subset the transport touches; injectable for tests and runtimes. */\nexport interface WebSocketLike {\n /** Current connection state; 1 (OPEN) means frames may be sent. */\n readonly readyState?: number;\n send(data: string | ArrayBuffer): void;\n close(code?: number, reason?: string): void;\n onopen: (() => void) | null;\n onclose: (() => void) | null;\n onerror: (() => void) | null;\n onmessage: ((event: { data: unknown }) => void) | null;\n}\n\n/** Connection configuration for {@link WebSocketTransport}. */\nexport interface WebSocketDataBusConfig {\n /** WebSocket endpoint, e.g. `wss://example.test/ws`. */\n url: string;\n /** Subprotocol(s) passed to the WebSocket handshake. */\n protocols?: string | string[];\n /** Custom socket factory. Defaults to the global `WebSocket`; injectable\n * for tests and non-browser runtimes. */\n webSocketFactory?: (url: string, protocols?: string | string[]) => WebSocketLike;\n}\n\n/** Options for creating a fully-configured CrossTabDataBus with a WebSocket transport. */\nexport interface CreateWebSocketDataBusOptions<TData = unknown>\n extends Omit<\n CrossTabDataBusOptions<WebSocketDataBusConfig, TData>,\n 'autoStart' | 'clusterKey' | 'initialConfig' | 'transport'\n > {\n /** WebSocket connection configuration. */\n connection: WebSocketDataBusConfig;\n /** Cluster key for cross-tab coordination. Defaults to the connection URL. */\n clusterKey?: string;\n}\n\nconst WS_OPEN = 1;\n\n/** Transport that talks a minimal JSON protocol over a plain WebSocket.\n * Connection lifecycle maps directly to the DataBus status vocabulary:\n * open \u2192 `connected`, close \u2192 `disconnected`, error \u2192 `error` (which the\n * DataBus treats as its auto-recovery trigger). The transport holds no\n * reconnection logic of its own \u2014 reopening is the DataBus's job. */\nexport class WebSocketTransport<TData = unknown>\n implements DataBusTransport<WebSocketDataBusConfig, TData>\n{\n private socket: WebSocketLike | null = null;\n private handlers: DataBusTransportHandlers<TData> | null = null;\n private readonly subscribedTopics = new Set<string>();\n\n constructor(private readonly connection: WebSocketDataBusConfig) {}\n\n /** Open the WebSocket and wire lifecycle listeners. A factory failure is\n * reported through `onStatus('error')` so the DataBus can recover. */\n start(config: WebSocketDataBusConfig, handlers: DataBusTransportHandlers<TData>): MaybePromise<void> {\n if (this.socket) return;\n this.handlers = handlers;\n // The factory may live on the constructor connection (createWebSocketDataBus\n // path) or on the runtime config (direct transport use) \u2014 accept both.\n const factory = config.webSocketFactory ?? this.connection.webSocketFactory ?? defaultWebSocketFactory;\n const protocols = config.protocols ?? this.connection.protocols;\n let socket: WebSocketLike;\n try {\n socket = factory(config.url, protocols);\n } catch (error) {\n handlers.onStatus('error');\n handlers.onError(error);\n return;\n }\n socket.onopen = () => {\n // Re-assert every topic so a reopened socket (recovery path) restores\n // the server-side subscriptions without DataBus involvement.\n for (const topic of this.subscribedTopics) {\n this.sendFrame({ op: 'subscribe', topic });\n }\n handlers.onStatus('connected');\n };\n socket.onclose = () => handlers.onStatus('disconnected');\n socket.onerror = () => handlers.onStatus('error');\n socket.onmessage = event => this.handleMessage(event.data);\n this.socket = socket;\n }\n\n /** Idempotent: re-subscribing an active topic re-sends the frame but does\n * not duplicate the local tracking entry. */\n subscribe(topic: string): MaybePromise<void> {\n this.subscribedTopics.add(topic);\n this.sendFrame({ op: 'subscribe', topic });\n }\n\n /** Idempotent: unsubscribing an unknown topic is a no-op. */\n unsubscribe(topic: string): MaybePromise<void> {\n this.subscribedTopics.delete(topic);\n this.sendFrame({ op: 'unsubscribe', topic });\n }\n\n /** Publish `data` to `topic` as a JSON frame. Requires an open socket. */\n publish(topic: string, data: unknown, options?: DataBusPublishOptions): MaybePromise<void> {\n if (data instanceof ArrayBuffer) {\n this.sendBinaryFrame(topic, data, options?.messageId);\n return;\n }\n this.sendFrame({ op: 'publish', topic, data, ...(options?.messageId ? { messageId: options.messageId } : {}) });\n }\n\n /** Close the socket and drop all state. Safe to call multiple times. */\n stop(): MaybePromise<void> {\n const socket = this.socket;\n this.socket = null;\n this.handlers = null;\n this.subscribedTopics.clear();\n socket?.close();\n }\n\n /** Send one JSON frame. Frames are dropped with an `onError` report when\n * the socket is not open \u2014 subscribe frames are re-sent on open, so the\n * only real loss is a publish during a disconnect window. */\n private sendFrame(payload: { op: string; topic: string; data?: unknown; messageId?: string }): void {\n if (this.socket?.readyState !== WS_OPEN) {\n this.handlers?.onError(new Error(`WebSocket is not open; dropped \"${payload.op}\" frame.`));\n return;\n }\n this.socket.send(JSON.stringify(payload));\n }\n\n private sendBinaryFrame(topic: string, data: ArrayBuffer, messageId?: string): void {\n if (messageId) {\n // Binary frames retain their compact legacy shape; metadata is sent as a\n // JSON envelope so IDs are never silently lost.\n this.sendFrame({ op: 'publish', topic, data: Array.from(new Uint8Array(data)), messageId });\n return;\n }\n if (this.socket?.readyState !== WS_OPEN) {\n this.handlers?.onError(new Error('WebSocket is not open; dropped \"publish\" frame.'));\n return;\n }\n const topicBytes = new TextEncoder().encode(topic);\n if (topicBytes.length > 0xffff) {\n this.handlers?.onError(new Error('WebSocket topic is too long for a binary frame.'));\n return;\n }\n const frame = new Uint8Array(3 + topicBytes.length + data.byteLength);\n frame[0] = 0xc7;\n new DataView(frame.buffer).setUint16(1, topicBytes.length);\n frame.set(topicBytes, 3);\n frame.set(new Uint8Array(data), 3 + topicBytes.length);\n this.socket.send(frame.buffer);\n }\n\n /** Parse a server frame. Only objects carrying a string `topic` are\n * publications; malformed JSON and unknown shapes are ignored so a chatty\n * server cannot crash the message path. */\n private handleMessage(raw: unknown): void {\n let parsed: unknown;\n if (raw instanceof ArrayBuffer) {\n const bytes = new Uint8Array(raw);\n if (bytes[0] !== 0xc7 || bytes.length < 3) return;\n const topicLength = new DataView(raw).getUint16(1);\n if (bytes.length < 3 + topicLength) return;\n const topic = new TextDecoder().decode(bytes.subarray(3, 3 + topicLength));\n const data = bytes.slice(3 + topicLength).buffer;\n this.handlers?.onMessage({ topic, data: data as TData });\n return;\n }\n if (typeof raw !== 'string') return;\n try {\n parsed = JSON.parse(raw);\n } catch {\n this.handlers?.onError(new Error('WebSocket server sent a non-JSON frame.'));\n return;\n }\n if (!parsed || typeof parsed !== 'object') return;\n const frame = parsed as Record<string, unknown>;\n if (typeof frame.topic !== 'string') return;\n const message: DataBusMessage<TData> = {\n topic: frame.topic,\n data: frame.data as TData,\n ...(typeof frame.messageId === 'string' ? { messageId: frame.messageId } : {})\n };\n this.handlers?.onMessage(message);\n }\n}\n\n/** Resolve the platform WebSocket, or null in runtimes without one (SSR/Node). */\nfunction defaultWebSocketFactory(url: string, protocols?: string | string[]): WebSocketLike {\n if (typeof WebSocket === 'undefined') {\n throw new Error('WebSocketTransport requires a WebSocket implementation.');\n }\n return new WebSocket(url, protocols) as unknown as WebSocketLike;\n}\n\n/** Create a CrossTabDataBus backed by a plain WebSocket transport.\n * Cross-tab clustering (owner dedup, sticky routes, failover) works identically\n * to the Centrifuge backend \u2014 only the transport I/O differs. */\nexport function createWebSocketDataBus<TData = unknown>(\n options: CreateWebSocketDataBusOptions<TData>\n): CrossTabDataBus<WebSocketDataBusConfig, TData> {\n const { clusterKey, connection, ...dataBusOptions } = options;\n return new CrossTabDataBus({\n ...dataBusOptions,\n autoStart: true,\n clusterKey: clusterKey ?? connection.url,\n initialConfig: connection,\n transport: new WebSocketTransport<TData>(connection)\n });\n}\n\n/** Re-export for convenience: the status type used by the transport. */\nexport type { WorkerStatus };\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;AAkBO,SAAS,iCACd,SACiC;AACjC,QAAM,YAAY,WAAW;AAC7B,MAAI,CAAC,UAAW,OAAM,IAAI,MAAM,+CAA+C;AAC/E,QAAM,SAAS,QAAQ,UAAU;AACjC,QAAM,YAAY;AAClB,QAAM,cAAc,QAAQ;AAC5B,MAAI,CAAC,OAAO,cAAc,WAAW,KAAK,eAAe,GAAG;AAC1D,UAAM,IAAI,UAAU,oDAAoD,OAAO,WAAW,CAAC,GAAG;AAAA,EAChG;AACA,MAAI,YAAyC;AAC7C,QAAM,OAAO,MAA4B;AACvC,QAAI,UAAW,QAAO;AACtB,gBAAY,IAAI,QAAQ,CAAC,SAAS,WAAW;AAC3C,YAAM,UAAU,UAAU,KAAK,QAAQ,CAAC;AACxC,cAAQ,kBAAkB,MAAM,QAAQ,OAAO,kBAAkB,WAAW,EAAE,SAAS,QAAQ,CAAC;AAChG,cAAQ,YAAY,MAAM,QAAQ,QAAQ,MAAM;AAChD,cAAQ,UAAU,MAAM,OAAO,QAAQ,SAAS,IAAI,MAAM,iCAAiC,CAAC;AAAA,IAC9F,CAAC;AACD,WAAO;AAAA,EACT;AACA,SAAO;AAAA,IACL,MAAM,OAAO;AACX,YAAM,KAAK,MAAM,KAAK;AACtB,aAAO,IAAI,QAAQ,CAAC,SAAS,WAAW;AACtC,cAAM,UAAU,GAAG,YAAY,WAAW,UAAU,EAAE,YAAY,SAAS,EAAE,OAAO;AACpF,gBAAQ,YAAY,MAAM,QAAQ,QAAQ,OAAO,QAAQ,YAAU,OAAO,QAAmC,CAAC;AAC9G,gBAAQ,UAAU,MAAM,OAAO,QAAQ,SAAS,IAAI,MAAM,gCAAgC,CAAC;AAAA,MAC7F,CAAC;AAAA,IACH;AAAA,IACA,MAAM,OAAO,SAAS;A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,IAAI,mBAA0B,UAAU;AAAA,EACrD,CAAC;AACH;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/websocket.d.ts
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
*/
|
|
14
14
|
import { CrossTabDataBus } from './core/data-bus';
|
|
15
15
|
import type { CrossTabDataBusOptions } from './core/data-bus';
|
|
16
|
-
import type { DataBusTransport, DataBusTransportHandlers, MaybePromise, WorkerStatus } from './core/types';
|
|
16
|
+
import type { DataBusTransport, DataBusTransportHandlers, DataBusPublishOptions, MaybePromise, WorkerStatus } from './core/types';
|
|
17
17
|
/** Minimal WebSocket surface used by the transport. Matches the browser
|
|
18
18
|
* `WebSocket` subset the transport touches; injectable for tests and runtimes. */
|
|
19
19
|
export interface WebSocketLike {
|
|
@@ -65,7 +65,7 @@ export declare class WebSocketTransport<TData = unknown> implements DataBusTrans
|
|
|
65
65
|
/** Idempotent: unsubscribing an unknown topic is a no-op. */
|
|
66
66
|
unsubscribe(topic: string): MaybePromise<void>;
|
|
67
67
|
/** Publish `data` to `topic` as a JSON frame. Requires an open socket. */
|
|
68
|
-
publish(topic: string, data: unknown): MaybePromise<void>;
|
|
68
|
+
publish(topic: string, data: unknown, options?: DataBusPublishOptions): MaybePromise<void>;
|
|
69
69
|
/** Close the socket and drop all state. Safe to call multiple times. */
|
|
70
70
|
stop(): MaybePromise<void>;
|
|
71
71
|
/** Send one JSON frame. Frames are dropped with an `onError` report when
|
package/dist/websocket.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"websocket.d.ts","sourceRoot":"","sources":["../src/websocket.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAC;AAC9D,OAAO,KAAK,EACV,gBAAgB,EAChB,wBAAwB,EACxB,YAAY,EACZ,YA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AAE,QAAQ,EAAE,wBAAwB,CAAC,KAAK,CAAC,GAAG,YAAY,CAAC,IAAI,CAAC;IA6BpG;iDAC6C;IAC7C,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,YAAY,CAAC,IAAI,CAAC;IAK5C,6DAA6D;IAC7D,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,YAAY,CAAC,IAAI,CAAC;IAK9C,0EAA0E;IAC1E,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,qBAAqB,GAAG,YAAY,CAAC,IAAI,CAAC;IAQ1F,wEAAwE;IACxE,IAAI,IAAI,YAAY,CAAC,IAAI,CAAC;IAQ1B;;iEAE6D;IAC7D,OAAO,CAAC,SAAS;IAQjB,OAAO,CAAC,eAAe;IAwBvB;;+CAE2C;IAC3C,OAAO,CAAC,aAAa;CA6BtB;AAUD;;iEAEiE;AACjE,wBAAgB,sBAAsB,CAAC,KAAK,GAAG,OAAO,EACpD,OAAO,EAAE,6BAA6B,CAAC,KAAK,CAAC,GAC5C,eAAe,CAAC,sBAAsB,EAAE,KAAK,CAAC,CAShD;AAED,wEAAwE;AACxE,YAAY,EAAE,YAAY,EAAE,CAAC"}
|
package/docs/api.md
CHANGED
|
@@ -87,6 +87,7 @@ Registers a local subscription and returns a cleanup function.
|
|
|
87
87
|
- Subscriptions are automatically queued when the transport is not yet ready.
|
|
88
88
|
- Wildcard subscriptions: a topic ending in `.*` (`chat.*`) matches any remainder, and `*` matches everything. The pattern is routed, owned, and transport-subscribed as a literal channel; publications tagged with a matching concrete topic (or with the pattern itself) are delivered to wildcard handlers. See `topicMatchesPattern` below.
|
|
89
89
|
- Replay (opt-in): construct the bus with `replay: { maxPerTopic }` and pass `{ replay: true | n }` as the third `subscribe()` argument. `maxPerTopic` must be a positive safe integer. The new handler immediately receives the buffered history (up to `n`, capped by `maxPerTopic`, default 100) with `message.replayed: true`, so late joiners do not miss earlier publications. Only dispatched publications are buffered (a topic with no local subscriber drops them as unowned); buffers are in-memory and cleared when the last handler for the topic unsubscribes. Wildcard subscriptions replay across every buffered topic matching the pattern. For reload/BFCache persistence, pass an optional `persistence` created by `createIndexedDbReplayPersistence({ maxPerTopic })`; persistence is asynchronous and failures are reported through `onError` without breaking live delivery.
|
|
90
|
+
- Persistent replay stores may also implement `clearTopic(topic)`; the bus calls it on final topic unsubscribe. A store may expose `clear()` for application-controlled retention cleanup; `stop()` deliberately preserves durable history for reload/BFCache recovery.
|
|
90
91
|
|
|
91
92
|
### `unsubscribe(topic, handler?)`
|
|
92
93
|
|
|
@@ -98,10 +99,10 @@ When a handler is provided, only that callback is released; when omitted, all ha
|
|
|
98
99
|
|
|
99
100
|
Prefer using the cleanup function returned by `subscribe` to avoid accidentally removing callbacks from other modules.
|
|
100
101
|
|
|
101
|
-
### `publish(topic, data)`
|
|
102
|
+
### `publish(topic, data, options?)`
|
|
102
103
|
|
|
103
104
|
```ts
|
|
104
|
-
publish(topic: string, data: unknown): void
|
|
105
|
+
publish(topic: string, data: unknown, options?: { messageId?: string }): void
|
|
105
106
|
```
|
|
106
107
|
|
|
107
108
|
Routes the publish operation to the current topic owner; uses the current Worker when no valid route exists.
|
|
@@ -110,6 +111,18 @@ Published data must satisfy the serialization constraints of the underlying tran
|
|
|
110
111
|
|
|
111
112
|
When the owning Worker is a remote Tab and the publish control message cannot be posted (for example the BroadcastChannel fails to clone the payload), `publish()` reports the failure through `onError` instead of silently dropping it.
|
|
112
113
|
|
|
114
|
+
Incoming messages may include a caller/server supplied `messageId`. Enable bounded duplicate suppression with `dedup: { maxEntries, ttlMs }`; repeated IDs within the window are ignored. This is disabled by default and does not provide an exactly-once server guarantee.
|
|
115
|
+
|
|
116
|
+
When supplied, `options.messageId` is propagated through cross-tab routing and supported transports. It is metadata only; the server must echo or otherwise preserve it for inbound deduplication.
|
|
117
|
+
|
|
118
|
+
### `clearReplay()`
|
|
119
|
+
|
|
120
|
+
```ts
|
|
121
|
+
clearReplay(): Promise<void>
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
Clears in-memory replay buffers and invokes the persistence adapter's optional `clear()` hook. Useful for retention policies, logout, or tenant switching. Durable history is otherwise preserved across `stop()`.
|
|
125
|
+
|
|
113
126
|
### `onStatus(handler)`
|
|
114
127
|
|
|
115
128
|
```ts
|
package/docs/capabilities.md
CHANGED
|
@@ -22,14 +22,14 @@ Status Legend: `✅ Implemented` means the current version has code and test cov
|
|
|
22
22
|
| Degradation | Runs locally when localStorage or BroadcastChannel is unavailable | ✅ Implemented | Preserves the current Tab's connection and subscription capabilities |
|
|
23
23
|
| Centrifuge | Built-in Dedicated / Shared Worker transport | ✅ Implemented | Supports subscribe, unsubscribe, publish, connection status, and error reporting; `auto` degrades from SharedWorker → Dedicated Worker → main-thread WebSocket |
|
|
24
24
|
| Security Boundary | localStorage uses opaque keys derived from connection and Topic; BroadcastChannel coordination messages carry plaintext topic names | ✅ Implemented | Does not persist URLs, raw Topic names, credentials, or publication payloads. BroadcastChannel coordination messages are in-memory only and carry plaintext topic names — they are not persisted. |
|
|
25
|
-
| Diagnostics | Aggregates lifecycle events, throughput,
|
|
25
|
+
| Diagnostics | Aggregates lifecycle events, throughput, delivery latency, recovery retries, route acknowledgments, and migrations | ✅ Implemented | Disabled by default; metrics are emitted every 5 seconds by default, with bounded reliability events for recovery and route coordination |
|
|
26
26
|
| Performance | Batched writes of coordination metadata with backoff retry | ✅ Implemented | Heartbeat, route, and subscriber writes are merged and flushed in a microtask; failures use exponential backoff; `pagehide` / `stop()` flush synchronously |
|
|
27
27
|
| Performance | Optional ArrayBuffer Transferable transport | ✅ Implemented | With `transferable: true`, binary publish / receive bypasses structured clone copying; the object message API is unchanged |
|
|
28
28
|
| Message Semantics | exactly-once delivery | Not Implemented | Graceful handoff avoids overlap, but crash recovery and transport/server behavior still do not provide an exactly-once guarantee |
|
|
29
|
-
| Message Semantics | Pluggable publication deduplication |
|
|
29
|
+
| Message Semantics | Pluggable publication deduplication | ✅ Implemented | Opt-in bounded inbound suppression by `DataBusMessage.messageId`; default is disabled and transport/server IDs remain caller-controlled |
|
|
30
30
|
| Authentication | Async credential refresh bridge inside the Worker | Planned | Current Worker config must be structured-cloneable and cannot pass functions |
|
|
31
31
|
| Load Policy | Adaptive weighting by message rate, byte count, or CPU | Planned | Load is currently computed only from the number of owner Topics |
|
|
32
|
-
| Observability | Metrics for owner
|
|
32
|
+
| Observability | Metrics/events for owner acknowledgments, migrations, and recovery attempts | ✅ Implemented | `DataBusReliabilityTraceEvent` reports bounded route ack/migration and transport recovery events; exact server-side ack remains transport-specific |
|
|
33
33
|
| Runtime Model | SharedWorker / Dedicated Worker transport | ✅ Implemented | `workerMode` supports `dedicated`, `shared`, and `auto`, defaulting to `dedicated` |
|
|
34
34
|
| Runtime Model | Service Worker transport | Not Implemented | Service Worker hosting of real-time connections is not currently provided |
|
|
35
35
|
| Durable Messages | Persisting publications or publish commands across page close | Not Implemented | The SDK does not persist business payloads, nor does it replay publish commands after restoration |
|
package/docs/roadmap.md
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
# Roadmap
|
|
2
2
|
|
|
3
|
-
0.
|
|
3
|
+
0.6.0 is released. The next work is organized as 0.7.0 candidates, with reliability and diagnostics landing first so the new behavior is observable before expanding the protocol surface.
|
|
4
4
|
|
|
5
|
-
## 0.
|
|
5
|
+
## 0.7.0 candidates
|
|
6
6
|
|
|
7
|
-
1. **
|
|
8
|
-
2. **
|
|
9
|
-
3. **
|
|
10
|
-
4. **
|
|
11
|
-
5. **Operational
|
|
7
|
+
1. **Replay lifecycle and retention** — add explicit persistence cleanup (`clear`, `clearTopic`), make unsubscribe/replacement remove stale history, and surface persistence failures through trace and error handlers.
|
|
8
|
+
2. **Reliability diagnostics** — emit structured recovery/retry, owner-acknowledgment, and route-migration events with bounded metadata while keeping tracing opt-in.
|
|
9
|
+
3. **Publication deduplication** — design and implement an opt-in, bounded message-ID window that works across local dispatch, BroadcastChannel fan-out, WebSocket, and replay without changing the default behavior.
|
|
10
|
+
4. **Adapter and protocol parity** — align React/Vue lifecycle and type contracts, document binary framing and recovery semantics, and add compatibility fixtures for custom transports.
|
|
11
|
+
5. **Operational validation** — extend browser and package-consumption tests, add regression benchmarks for dedup/recovery/replay cleanup, and keep push CI as a release gate.
|
|
12
12
|
|
|
13
13
|
## Release checklist
|
|
14
14
|
|