cross-tab-worker-databus 0.5.0 → 0.6.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 +8 -0
- package/README.md +1 -0
- package/README.zh.md +1 -0
- package/dist/centrifuge.js +1 -2
- package/dist/centrifuge.js.map +1 -1
- package/dist/{chunk-W7DAXK4D.js → chunk-YUSQSNCX.js} +9 -1
- package/dist/chunk-YUSQSNCX.js.map +7 -0
- package/dist/cjs/centrifuge.cjs +8 -0
- package/dist/cjs/centrifuge.cjs.map +2 -2
- package/dist/cjs/hooks.cjs +1 -1913
- package/dist/cjs/hooks.cjs.map +4 -4
- package/dist/cjs/index.cjs +39 -0
- package/dist/cjs/index.cjs.map +2 -2
- package/dist/cjs/vue.cjs +93 -0
- package/dist/cjs/vue.cjs.map +7 -0
- package/dist/core/cluster.d.ts.map +1 -1
- package/dist/hooks.js +7 -1911
- package/dist/hooks.js.map +4 -4
- package/dist/index.js +32 -2
- package/dist/index.js.map +2 -2
- package/dist/vue.d.ts +10 -0
- package/dist/vue.d.ts.map +1 -0
- package/dist/vue.js +72 -0
- package/dist/vue.js.map +7 -0
- package/dist/websocket.d.ts +2 -1
- package/dist/websocket.d.ts.map +1 -1
- package/docs/api.md +18 -0
- package/docs/roadmap.md +7 -7
- package/docs/transports.md +4 -0
- package/docs/zh/api.md +18 -0
- package/docs/zh/roadmap.md +7 -7
- package/docs/zh/transports.md +4 -0
- package/package.json +13 -3
- package/dist/chunk-5WRI5ZAA.js +0 -31
- package/dist/chunk-5WRI5ZAA.js.map +0 -7
- package/dist/chunk-W7DAXK4D.js.map +0 -7
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,O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D,wEAAwE;IACxE,IAAI,IAAI,YAAY,CAAC,IAAI,CAAC;IAQ1B;;iEAE6D;IAC7D,OAAO,CAAC,SAAS;IAQjB,OAAO,CAAC,eAAe;IAkBvB;;+CAE2C;IAC3C,OAAO,CAAC,aAAa;CAwBtB;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
|
@@ -30,6 +30,12 @@ import {
|
|
|
30
30
|
useCrossTabStatus,
|
|
31
31
|
useCrossTabSubscription
|
|
32
32
|
} from 'cross-tab-worker-databus/hooks';
|
|
33
|
+
|
|
34
|
+
import {
|
|
35
|
+
useCrossTabDataBus as useVueCrossTabDataBus,
|
|
36
|
+
useCrossTabStatus as useVueCrossTabStatus,
|
|
37
|
+
useCrossTabSubscription as useVueCrossTabSubscription
|
|
38
|
+
} from 'cross-tab-worker-databus/vue';
|
|
33
39
|
```
|
|
34
40
|
|
|
35
41
|
Business integration should prefer `CrossTabDataBus` or `createCentrifugeDataBus`. `WorkerClusterRuntime` is an advanced coordination API.
|
|
@@ -289,6 +295,18 @@ Attaches a message handler with automatic cleanup. The handler is read through a
|
|
|
289
295
|
|
|
290
296
|
Mirrors `bus.onStatus()` into React state and reads the current value synchronously whenever the bus identity changes. Returns `'connecting' | 'connected' | 'disconnected' | 'error'`.
|
|
291
297
|
|
|
298
|
+
## Vue Composables (`cross-tab-worker-databus/vue`)
|
|
299
|
+
|
|
300
|
+
Vue 3.3+ is an optional peer dependency; this entry is separate from the core package.
|
|
301
|
+
|
|
302
|
+
```ts
|
|
303
|
+
const bus = useVueCrossTabDataBus(() => createWebSocketDataBus({ connection: { url } }));
|
|
304
|
+
const status = useVueCrossTabStatus(bus);
|
|
305
|
+
useVueCrossTabSubscription(bus, 'chat.*', message => console.log(message.data));
|
|
306
|
+
```
|
|
307
|
+
|
|
308
|
+
`useCrossTabDataBus` returns a Vue `Ref` that is populated on mount and stopped on unmount. `useCrossTabSubscription` accepts a string or `Ref<string>` topic and rebinds when the bus or topic changes. `useCrossTabStatus` returns a `Ref<WorkerStatus>` synchronized with `bus.onStatus()`.
|
|
309
|
+
|
|
292
310
|
## `WorkerClusterRuntime`
|
|
293
311
|
|
|
294
312
|
Advanced API responsible for Worker registration, heartbeat, visibility, routing, BroadcastChannel protocol, and migration. Business modules should not operate on it directly.
|
package/docs/roadmap.md
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
# Roadmap
|
|
2
2
|
|
|
3
|
-
0.
|
|
3
|
+
0.5.0 is released. The next work is organized as 0.6.0 candidates, with publish-path improvements landing first because they are measurable without changing the public transport contract.
|
|
4
4
|
|
|
5
|
-
## 0.
|
|
5
|
+
## 0.6.0 candidates
|
|
6
6
|
|
|
7
|
-
1. **Publish-path profiling and optimization** —
|
|
8
|
-
2. **
|
|
9
|
-
3. **
|
|
10
|
-
4. **
|
|
11
|
-
5. **
|
|
7
|
+
1. **Publish-path profiling and optimization** — continue isolating routing, storage, and transport overhead; the first 0.6.0 slice adds a synchronous owner fast path for local publishes.
|
|
8
|
+
2. **Vue composables** — provide a Vue 3 adapter mirroring the React hooks lifecycle and subscription semantics without making Vue a core dependency. (Adapter implemented; contract coverage and examples remain.)
|
|
9
|
+
3. **End-to-end binary demo** — exercise real `ArrayBuffer` frames through the WebSocket demo path; keep the existing base64 JSON fallback for servers that only support JSON.
|
|
10
|
+
4. **Push CI browser gate** — run the existing Playwright suite on pushes with an installed Chromium fallback; keep local/manual execution as the fallback for contributors. (Workflow implemented.)
|
|
11
|
+
5. **Operational polish** — document IndexedDB replay retention/cleanup and add diagnostics around persistence quota failures.
|
|
12
12
|
|
|
13
13
|
## Release checklist
|
|
14
14
|
|
package/docs/transports.md
CHANGED
|
@@ -146,6 +146,10 @@ Wire protocol (JSON text frames):
|
|
|
146
146
|
without a string `topic` are ignored; malformed JSON is reported through
|
|
147
147
|
`handlers.onError` without throwing.
|
|
148
148
|
|
|
149
|
+
When `data` is an `ArrayBuffer`, publish uses a binary frame with a small
|
|
150
|
+
header (`0xc7`, UTF-8 topic length, topic, payload). Servers may echo the same
|
|
151
|
+
frame unchanged; JSON remains the compatibility path for all other payloads.
|
|
152
|
+
|
|
149
153
|
Lifecycle mapping: `open` → `connected`, `close` → `disconnected`,
|
|
150
154
|
`error` → `error` (DataBus auto-recovery). Subscribe frames are re-sent when
|
|
151
155
|
the socket reopens in place. A pattern-aware server may tag publications with
|
package/docs/zh/api.md
CHANGED
|
@@ -30,6 +30,12 @@ import {
|
|
|
30
30
|
useCrossTabStatus,
|
|
31
31
|
useCrossTabSubscription
|
|
32
32
|
} from 'cross-tab-worker-databus/hooks';
|
|
33
|
+
|
|
34
|
+
import {
|
|
35
|
+
useCrossTabDataBus as useVueCrossTabDataBus,
|
|
36
|
+
useCrossTabStatus as useVueCrossTabStatus,
|
|
37
|
+
useCrossTabSubscription as useVueCrossTabSubscription
|
|
38
|
+
} from 'cross-tab-worker-databus/vue';
|
|
33
39
|
```
|
|
34
40
|
|
|
35
41
|
业务接入优先使用 `CrossTabDataBus` 或 `createCentrifugeDataBus`。`WorkerClusterRuntime` 属于高级协调 API。
|
|
@@ -289,6 +295,18 @@ React(>= 18)是可选 peer 依赖;独立入口保证非 React 消费者不
|
|
|
289
295
|
|
|
290
296
|
把 `bus.onStatus()` 镜像为 React 状态,bus 身份变化时同步读取当前值。返回 `'connecting' | 'connected' | 'disconnected' | 'error'`。
|
|
291
297
|
|
|
298
|
+
## Vue Composables(`cross-tab-worker-databus/vue`)
|
|
299
|
+
|
|
300
|
+
Vue 3.3+ 是可选 peer 依赖;独立入口不会影响核心包。
|
|
301
|
+
|
|
302
|
+
```ts
|
|
303
|
+
const bus = useVueCrossTabDataBus(() => createWebSocketDataBus({ connection: { url } }));
|
|
304
|
+
const status = useVueCrossTabStatus(bus);
|
|
305
|
+
useVueCrossTabSubscription(bus, 'chat.*', message => console.log(message.data));
|
|
306
|
+
```
|
|
307
|
+
|
|
308
|
+
`useCrossTabDataBus` 返回 Vue `Ref`,在组件挂载时创建 bus、卸载时停止。`useCrossTabSubscription` 接受字符串或 `Ref<string>` topic,在 bus/topic 变化时自动重绑。`useCrossTabStatus` 返回与 `bus.onStatus()` 同步的 `Ref<WorkerStatus>`。
|
|
309
|
+
|
|
292
310
|
## `WorkerClusterRuntime`
|
|
293
311
|
|
|
294
312
|
高级 API,负责 Worker 注册、心跳、可见性、路由、BroadcastChannel 协议和迁移。业务模块不应直接操作它。
|
package/docs/zh/roadmap.md
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
# 路线图
|
|
2
2
|
|
|
3
|
-
0.
|
|
3
|
+
0.5.0 已发布。下一阶段按 0.6.0 候选推进,先处理可用基准直接验证的 publish 路径优化,不改变公开 transport 契约。
|
|
4
4
|
|
|
5
|
-
## 0.
|
|
5
|
+
## 0.6.0 候选
|
|
6
6
|
|
|
7
|
-
1. **publish 路径 profile
|
|
8
|
-
2.
|
|
9
|
-
3.
|
|
10
|
-
4.
|
|
11
|
-
5.
|
|
7
|
+
1. **publish 路径 profile 与优化**:继续拆分路由、存储和 transport 开销;0.6.0 首批加入 owner 本地 publish 的同步快路径;
|
|
8
|
+
2. **Vue composable**:复制 React hooks 的生命周期与订阅语义,Vue 仍保持可选依赖。(适配层已实现,后续补契约覆盖与示例);
|
|
9
|
+
3. **二进制 demo 真链路**:让 WebSocket demo 端到端覆盖真实 `ArrayBuffer` 帧,同时保留仅支持 JSON 服务端的 base64 fallback;
|
|
10
|
+
4. **Push CI 浏览器门禁**:push 时运行 Playwright,CI 使用安装的 Chromium 作为 Chrome fallback,贡献者本地仍可手动执行。(workflow 已实现);
|
|
11
|
+
5. **运维完善**:补充 IndexedDB replay 留存/清理说明,并为持久化配额失败增加诊断。
|
|
12
12
|
|
|
13
13
|
## 发版检查清单
|
|
14
14
|
|
package/docs/zh/transports.md
CHANGED
|
@@ -133,6 +133,10 @@ const bus = createWebSocketDataBus({
|
|
|
133
133
|
- server → client:发布为 `{"topic":"...","data":...}`。没有字符串 `topic` 的帧
|
|
134
134
|
会被忽略;非法 JSON 通过 `handlers.onError` 上报而不会抛出。
|
|
135
135
|
|
|
136
|
+
当 `data` 是 `ArrayBuffer` 时,publish 使用二进制帧:帧头为 `0xc7`,随后是
|
|
137
|
+
UTF-8 topic 长度、topic 和 payload。服务器可以原样回显该帧;其他 payload 仍走
|
|
138
|
+
JSON 兼容路径。
|
|
139
|
+
|
|
136
140
|
生命周期映射:`open` → `connected`,`close` → `disconnected`,`error` → `error`
|
|
137
141
|
(触发 DataBus 自动恢复)。socket 原地重连时自动重发订阅帧。支持 pattern 的
|
|
138
142
|
服务器可以以具体 topic 标注发布——见 [api.md](../api.md) 中的通配符订阅。
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cross-tab-worker-databus",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "Framework-agnostic cross-tab data bus with Dedicated/Shared Worker clustering and Centrifuge support.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -56,6 +56,11 @@
|
|
|
56
56
|
"import": "./dist/hooks.js",
|
|
57
57
|
"require": "./dist/cjs/hooks.cjs"
|
|
58
58
|
},
|
|
59
|
+
"./vue": {
|
|
60
|
+
"types": "./dist/vue.d.ts",
|
|
61
|
+
"import": "./dist/vue.js",
|
|
62
|
+
"require": "./dist/cjs/vue.cjs"
|
|
63
|
+
},
|
|
59
64
|
"./package.json": "./package.json"
|
|
60
65
|
},
|
|
61
66
|
"sideEffects": [
|
|
@@ -78,7 +83,8 @@
|
|
|
78
83
|
},
|
|
79
84
|
"peerDependencies": {
|
|
80
85
|
"centrifuge": "^5.5.3",
|
|
81
|
-
"react": ">=18"
|
|
86
|
+
"react": ">=18",
|
|
87
|
+
"vue": ">=3.3"
|
|
82
88
|
},
|
|
83
89
|
"peerDependenciesMeta": {
|
|
84
90
|
"centrifuge": {
|
|
@@ -86,6 +92,9 @@
|
|
|
86
92
|
},
|
|
87
93
|
"react": {
|
|
88
94
|
"optional": true
|
|
95
|
+
},
|
|
96
|
+
"vue": {
|
|
97
|
+
"optional": true
|
|
89
98
|
}
|
|
90
99
|
},
|
|
91
100
|
"devDependencies": {
|
|
@@ -103,7 +112,8 @@
|
|
|
103
112
|
"react-dom": "^18.3.1",
|
|
104
113
|
"typescript": "^5.9.0",
|
|
105
114
|
"typescript-eslint": "^8.68.0",
|
|
106
|
-
"vitest": "^3.2.0"
|
|
115
|
+
"vitest": "^3.2.0",
|
|
116
|
+
"vue": "^3.5.42"
|
|
107
117
|
},
|
|
108
118
|
"engines": {
|
|
109
119
|
"node": ">=18.0.0"
|
package/dist/chunk-5WRI5ZAA.js
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
var __create = Object.create;
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
var __commonJS = (cb, mod) => function __require() {
|
|
8
|
-
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
19
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
20
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
21
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
22
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
23
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
24
|
-
mod
|
|
25
|
-
));
|
|
26
|
-
|
|
27
|
-
export {
|
|
28
|
-
__commonJS,
|
|
29
|
-
__toESM
|
|
30
|
-
};
|
|
31
|
-
//# sourceMappingURL=chunk-5WRI5ZAA.js.map
|