@dovetail-ts/transport-cable 0.0.0-stage → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +28 -0
- package/LICENSE +21 -0
- package/README.md +19 -2
- package/dist/index.d.ts +44 -0
- package/dist/index.js +92 -0
- package/dist/index.js.map +1 -0
- package/package.json +49 -3
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# @dovetail-ts/transport-cable
|
|
2
|
+
|
|
3
|
+
## 1.0.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 21b3dbf: Publish through OIDC trusted publishing only, with the Ember Workbench release kit. Each version from this release on has npm provenance.
|
|
8
|
+
- Updated dependencies [21b3dbf]
|
|
9
|
+
- @dovetail-ts/protocol@1.0.1
|
|
10
|
+
|
|
11
|
+
## 1.0.0
|
|
12
|
+
|
|
13
|
+
### Major Changes
|
|
14
|
+
|
|
15
|
+
- 480744b: First release of Dovetail: real-time and offline sync for Ember.
|
|
16
|
+
|
|
17
|
+
- `@dovetail-ts/core`: the connection life cycle, live store subscriptions, the optimistic ledger with rebase and rollback, the offline write queue in IndexedDB with a leader tab and dead letters, `DocSession` and `PresenceRoom`.
|
|
18
|
+
- `@dovetail-ts/warp-drive`: the store feed into WarpDrive.
|
|
19
|
+
- `@dovetail-ts/crdt`, `crdt-yjs`, `crdt-loro` and `crdt-automerge`: one `DocEngine` interface with three engines.
|
|
20
|
+
- `@dovetail-ts/tiptap`: co-editing in Tiptap 3 with carets, per-user undo, versions and comment threads.
|
|
21
|
+
- `@dovetail-ts/ember`, `notifications` and `inspector`: presence and status components, the inbox, toasts and activity feeds, and a dev panel.
|
|
22
|
+
- `@dovetail-ts/server`, the transports (`transport-ws`, `transport-sse`, `transport-cable`) and `conformance`: a Node server and one wire protocol that the Rails gems also pass.
|
|
23
|
+
- Adapters for Hocuspocus, Liveblocks, PartyKit and Supabase, and integrations for Switchyard, Millwork, Benchdog and Lattice. The Neon adapter is not in 1.0: it waits for a stable Neon Realtime client (1.1).
|
|
24
|
+
|
|
25
|
+
### Patch Changes
|
|
26
|
+
|
|
27
|
+
- Updated dependencies [480744b]
|
|
28
|
+
- @dovetail-ts/protocol@1.0.0
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Joe Gaudet
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,20 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @dovetail-ts/transport-cable
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The Rails ActionCable transport. It talks to `Dovetail::Channel` of the `dovetail-rails` gem.
|
|
4
|
+
|
|
5
|
+
Part of [Dovetail](https://joegaudet.com/dovetail/). Not released yet.
|
|
6
|
+
|
|
7
|
+
```ts
|
|
8
|
+
import { CableTransport } from '@dovetail-ts/transport-cable'
|
|
9
|
+
|
|
10
|
+
const transport = new CableTransport({ url: 'wss://example.com/cable' })
|
|
11
|
+
await transport.open()
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
Options: `url` (the transport makes and owns a consumer) or `consumer` (a consumer of your
|
|
15
|
+
app, which the transport does not disconnect), `channel` (default `Dovetail::Channel`), `params`
|
|
16
|
+
and `limits`. Each frame is the string field `frame` of the cable data, with its number `seq`
|
|
17
|
+
(from 1): ActionCable runs the frames on a worker pool, and the channel runs them in the order of
|
|
18
|
+
`seq`. A disconnect closes the
|
|
19
|
+
transport, so ActionCable does not subscribe again by itself: the Connection makes a new
|
|
20
|
+
transport. `sendText(text)` sends a frame as it is, for tests and proxies.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { ClientMessage, ClientTransport, CloseInfo, Limits, ServerMessage } from '@dovetail-ts/protocol';
|
|
2
|
+
/** The callbacks of one subscription, as ActionCable calls them. */
|
|
3
|
+
export interface CableMixin {
|
|
4
|
+
connected?(): void;
|
|
5
|
+
disconnected?(): void;
|
|
6
|
+
rejected?(): void;
|
|
7
|
+
received?(data: unknown): void;
|
|
8
|
+
}
|
|
9
|
+
export interface CableSubscription {
|
|
10
|
+
send(data: object): boolean;
|
|
11
|
+
unsubscribe(): void;
|
|
12
|
+
}
|
|
13
|
+
/** The parts of an ActionCable consumer (`createConsumer()`) that the transport uses. */
|
|
14
|
+
export interface CableConsumer {
|
|
15
|
+
subscriptions: {
|
|
16
|
+
create(params: Record<string, unknown>, mixin: CableMixin): CableSubscription;
|
|
17
|
+
};
|
|
18
|
+
disconnect(): void;
|
|
19
|
+
}
|
|
20
|
+
export interface CableTransportOptions {
|
|
21
|
+
/** The cable URL, as `wss://example.com/cable`. The transport makes and owns a consumer. */
|
|
22
|
+
url?: string;
|
|
23
|
+
/** A consumer of the app. The transport does not disconnect it. */
|
|
24
|
+
consumer?: CableConsumer;
|
|
25
|
+
/** The channel class. Default `Dovetail::Channel`. */
|
|
26
|
+
channel?: string;
|
|
27
|
+
/** More subscription params for the channel. */
|
|
28
|
+
params?: Record<string, unknown>;
|
|
29
|
+
/** The limits for the frames of the server. */
|
|
30
|
+
limits?: Partial<Limits>;
|
|
31
|
+
}
|
|
32
|
+
export declare class CableTransport implements ClientTransport {
|
|
33
|
+
#private;
|
|
34
|
+
constructor(options: CableTransportOptions);
|
|
35
|
+
get isOpen(): boolean;
|
|
36
|
+
/** Subscribes to the channel, and resolves on the confirmation. A transport opens once. */
|
|
37
|
+
open(): Promise<void>;
|
|
38
|
+
send(message: ClientMessage): void;
|
|
39
|
+
/** Sends one frame as it is. For tests and proxies: `send` is the normal way. */
|
|
40
|
+
sendText(text: string): void;
|
|
41
|
+
close(code?: number, reason?: string): void;
|
|
42
|
+
onMessage(listener: (message: ServerMessage) => void): () => void;
|
|
43
|
+
onClose(listener: (info: CloseInfo) => void): () => void;
|
|
44
|
+
}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { createConsumer } from '@rails/actioncable';
|
|
2
|
+
import { encodeMessage, parseMessage } from '@dovetail-ts/protocol';
|
|
3
|
+
|
|
4
|
+
// src/index.ts
|
|
5
|
+
var CableTransport = class {
|
|
6
|
+
#options;
|
|
7
|
+
#consumer;
|
|
8
|
+
#subscription;
|
|
9
|
+
#open = false;
|
|
10
|
+
/** The number of the last frame that went. The channel runs the frames in this order. */
|
|
11
|
+
#seq = 0;
|
|
12
|
+
#messages = /* @__PURE__ */ new Set();
|
|
13
|
+
#closes = /* @__PURE__ */ new Set();
|
|
14
|
+
constructor(options) {
|
|
15
|
+
if (!options.url && !options.consumer) throw new Error("CableTransport: give url or consumer");
|
|
16
|
+
this.#options = options;
|
|
17
|
+
}
|
|
18
|
+
get isOpen() {
|
|
19
|
+
return this.#open;
|
|
20
|
+
}
|
|
21
|
+
/** Subscribes to the channel, and resolves on the confirmation. A transport opens once. */
|
|
22
|
+
open() {
|
|
23
|
+
if (this.#consumer) return Promise.reject(new Error("CableTransport: open only once"));
|
|
24
|
+
const consumer = this.#options.consumer ?? createConsumer(this.#options.url);
|
|
25
|
+
this.#consumer = consumer;
|
|
26
|
+
return new Promise((resolve, reject) => {
|
|
27
|
+
this.#subscription = consumer.subscriptions.create(
|
|
28
|
+
{ channel: this.#options.channel ?? "Dovetail::Channel", ...this.#options.params },
|
|
29
|
+
{
|
|
30
|
+
connected: () => {
|
|
31
|
+
this.#open = true;
|
|
32
|
+
resolve();
|
|
33
|
+
},
|
|
34
|
+
rejected: () => {
|
|
35
|
+
this.#release();
|
|
36
|
+
reject(new Error("CableTransport: the channel rejected the subscription"));
|
|
37
|
+
},
|
|
38
|
+
disconnected: () => this.#closed({ code: 1006, reason: "disconnected", wasClean: false }),
|
|
39
|
+
received: (data) => this.#receive(data)
|
|
40
|
+
}
|
|
41
|
+
);
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
send(message) {
|
|
45
|
+
this.sendText(encodeMessage(message));
|
|
46
|
+
}
|
|
47
|
+
/** Sends one frame as it is. For tests and proxies: `send` is the normal way. */
|
|
48
|
+
sendText(text) {
|
|
49
|
+
if (!this.#open || !this.#subscription) {
|
|
50
|
+
throw new Error("CableTransport: the transport is not open");
|
|
51
|
+
}
|
|
52
|
+
this.#subscription.send({ frame: text, seq: ++this.#seq });
|
|
53
|
+
}
|
|
54
|
+
close(code = 1e3, reason = "") {
|
|
55
|
+
this.#closed({ code, reason, wasClean: true });
|
|
56
|
+
}
|
|
57
|
+
onMessage(listener) {
|
|
58
|
+
this.#messages.add(listener);
|
|
59
|
+
return () => this.#messages.delete(listener);
|
|
60
|
+
}
|
|
61
|
+
onClose(listener) {
|
|
62
|
+
this.#closes.add(listener);
|
|
63
|
+
return () => this.#closes.delete(listener);
|
|
64
|
+
}
|
|
65
|
+
#receive(data) {
|
|
66
|
+
if (!this.#open) return;
|
|
67
|
+
const frame = typeof data === "object" && data !== null && "frame" in data ? data.frame : "";
|
|
68
|
+
const result = parseMessage(typeof frame === "string" ? frame : "", {
|
|
69
|
+
from: "server",
|
|
70
|
+
limits: this.#options.limits
|
|
71
|
+
});
|
|
72
|
+
if (!result.ok) {
|
|
73
|
+
return this.#closed({ code: 1007, reason: result.error.message, wasClean: false });
|
|
74
|
+
}
|
|
75
|
+
for (const listener of [...this.#messages]) listener(result.message);
|
|
76
|
+
}
|
|
77
|
+
/** Stops the subscription, and the consumer when the transport made it. */
|
|
78
|
+
#release() {
|
|
79
|
+
this.#subscription?.unsubscribe();
|
|
80
|
+
if (!this.#options.consumer) this.#consumer?.disconnect();
|
|
81
|
+
}
|
|
82
|
+
#closed(info) {
|
|
83
|
+
if (!this.#open) return;
|
|
84
|
+
this.#open = false;
|
|
85
|
+
this.#release();
|
|
86
|
+
for (const listener of [...this.#closes]) listener(info);
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
export { CableTransport };
|
|
91
|
+
//# sourceMappingURL=index.js.map
|
|
92
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"names":[],"mappings":";;;;AAgDO,IAAM,iBAAN,MAAgD;AAAA,EAC5C,QAAA;AAAA,EACT,SAAA;AAAA,EACA,aAAA;AAAA,EACA,KAAA,GAAQ,KAAA;AAAA;AAAA,EAER,IAAA,GAAO,CAAA;AAAA,EACP,SAAA,uBAAgB,GAAA,EAAsC;AAAA,EACtD,OAAA,uBAAc,GAAA,EAA+B;AAAA,EAE7C,YAAY,OAAA,EAAgC;AAC1C,IAAA,IAAI,CAAC,QAAQ,GAAA,IAAO,CAAC,QAAQ,QAAA,EAAU,MAAM,IAAI,KAAA,CAAM,sC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QAAA,CAAS;AAAA,KACvB,CAAA;AACD,IAAA,IAAI,CAAC,OAAO,EAAA,EAAI;AACd,MAAA,OAAO,IAAA,CAAK,OAAA,CAAQ,EAAE,IAAA,EAAM,IAAA,EAAM,MAAA,EAAQ,MAAA,CAAO,KAAA,CAAM,OAAA,EAAS,QAAA,EAAU,KAAA,EAAO,CAAA;AAAA,IACnF;AACA,IAAA,KAAA,MAAW,QAAA,IAAY,CAAC,GAAG,IAAA,CAAK,SAAS,CAAA,EAAG,QAAA,CAAS,OAAO,OAAO,CAAA;AAAA,EACrE;AAAA;AAAA,EAGA,QAAA,GAAiB;AACf,IAAA,IAAA,CAAK,eAAe,WAAA,EAAY;AAChC,IAAA,IAAI,CAAC,IAAA,CAAK,QAAA,CAAS,QAAA,EAAU,IAAA,CAAK,WAAW,UAAA,EAAW;AAAA,EAC1D;AAAA,EAEA,QAAQ,IAAA,EAAuB;AAC7B,IAAA,IAAI,CAAC,KAAK,KAAA,EAAO;AACjB,IAAA,IAAA,CAAK,KAAA,GAAQ,KAAA;AACb,IAAA,IAAA,CAAK,QAAA,EAAS;AACd,IAAA,KAAA,MAAW,YAAY,CAAC,GAAG,KAAK,OAAO,CAAA,WAAY,IAAI,CAAA;AAAA,EACzD;AACF","file":"index.js","sourcesContent":["// The ActionCable transport (ADR 0012). It talks to the channel of the `dovetail-rails` gem.\n// Each frame is the string field `frame` of the cable data, both ways, so the gem checks its\n// size before it parses it. The transport does not reconnect: the Connection of\n// @dovetail-ts/core makes a new transport for that.\nimport { createConsumer } from '@rails/actioncable'\nimport { encodeMessage, parseMessage } from '@dovetail-ts/protocol'\nimport type {\n ClientMessage,\n ClientTransport,\n CloseInfo,\n Limits,\n ServerMessage,\n} from '@dovetail-ts/protocol'\n\n/** The callbacks of one subscription, as ActionCable calls them. */\nexport interface CableMixin {\n connected?(): void\n disconnected?(): void\n rejected?(): void\n received?(data: unknown): void\n}\n\nexport interface CableSubscription {\n send(data: object): boolean\n unsubscribe(): void\n}\n\n/** The parts of an ActionCable consumer (`createConsumer()`) that the transport uses. */\nexport interface CableConsumer {\n subscriptions: {\n create(params: Record<string, unknown>, mixin: CableMixin): CableSubscription\n }\n disconnect(): void\n}\n\nexport interface CableTransportOptions {\n /** The cable URL, as `wss://example.com/cable`. The transport makes and owns a consumer. */\n url?: string\n /** A consumer of the app. The transport does not disconnect it. */\n consumer?: CableConsumer\n /** The channel class. Default `Dovetail::Channel`. */\n channel?: string\n /** More subscription params for the channel. */\n params?: Record<string, unknown>\n /** The limits for the frames of the server. */\n limits?: Partial<Limits>\n}\n\nexport class CableTransport implements ClientTransport {\n readonly #options: CableTransportOptions\n #consumer: CableConsumer | undefined\n #subscription: CableSubscription | undefined\n #open = false\n /** The number of the last frame that went. The channel runs the frames in this order. */\n #seq = 0\n #messages = new Set<(message: ServerMessage) => void>()\n #closes = new Set<(info: CloseInfo) => void>()\n\n constructor(options: CableTransportOptions) {\n if (!options.url && !options.consumer) throw new Error('CableTransport: give url or consumer')\n this.#options = options\n }\n\n get isOpen(): boolean {\n return this.#open\n }\n\n /** Subscribes to the channel, and resolves on the confirmation. A transport opens once. */\n open(): Promise<void> {\n if (this.#consumer) return Promise.reject(new Error('CableTransport: open only once'))\n const consumer = this.#options.consumer ?? (createConsumer(this.#options.url) as CableConsumer)\n this.#consumer = consumer\n return new Promise((resolve, reject) => {\n this.#subscription = consumer.subscriptions.create(\n { channel: this.#options.channel ?? 'Dovetail::Channel', ...this.#options.params },\n {\n connected: () => {\n this.#open = true\n resolve()\n },\n rejected: () => {\n this.#release()\n reject(new Error('CableTransport: the channel rejected the subscription'))\n },\n disconnected: () => this.#closed({ code: 1006, reason: 'disconnected', wasClean: false }),\n received: data => this.#receive(data),\n },\n )\n })\n }\n\n send(message: ClientMessage): void {\n this.sendText(encodeMessage(message))\n }\n\n /** Sends one frame as it is. For tests and proxies: `send` is the normal way. */\n sendText(text: string): void {\n if (!this.#open || !this.#subscription) {\n throw new Error('CableTransport: the transport is not open')\n }\n // ActionCable runs the actions of a connection on a worker pool, in any order. The channel\n // runs the frames in the order of `seq` (R6).\n this.#subscription.send({ frame: text, seq: ++this.#seq })\n }\n\n close(code = 1000, reason = ''): void {\n this.#closed({ code, reason, wasClean: true })\n }\n\n onMessage(listener: (message: ServerMessage) => void): () => void {\n this.#messages.add(listener)\n return () => this.#messages.delete(listener)\n }\n\n onClose(listener: (info: CloseInfo) => void): () => void {\n this.#closes.add(listener)\n return () => this.#closes.delete(listener)\n }\n\n #receive(data: unknown): void {\n if (!this.#open) return\n const frame = typeof data === 'object' && data !== null && 'frame' in data ? data.frame : ''\n const result = parseMessage(typeof frame === 'string' ? frame : '', {\n from: 'server',\n limits: this.#options.limits,\n })\n if (!result.ok) {\n return this.#closed({ code: 1007, reason: result.error.message, wasClean: false })\n }\n for (const listener of [...this.#messages]) listener(result.message)\n }\n\n /** Stops the subscription, and the consumer when the transport made it. */\n #release(): void {\n this.#subscription?.unsubscribe()\n if (!this.#options.consumer) this.#consumer?.disconnect()\n }\n\n #closed(info: CloseInfo): void {\n if (!this.#open) return\n this.#open = false\n this.#release()\n for (const listener of [...this.#closes]) listener(info)\n }\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,52 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dovetail-ts/transport-cable",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"description": "The Rails ActionCable transport.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "Joe Gaudet <joe@joegaudet.com>",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/joegaudet/dovetail.git",
|
|
10
|
+
"directory": "packages/transport-cable"
|
|
11
|
+
},
|
|
12
|
+
"homepage": "https://joegaudet.com/dovetail/",
|
|
13
|
+
"bugs": "https://github.com/joegaudet/dovetail/issues",
|
|
14
|
+
"keywords": [
|
|
15
|
+
"realtime",
|
|
16
|
+
"offline",
|
|
17
|
+
"sync",
|
|
18
|
+
"crdt"
|
|
19
|
+
],
|
|
20
|
+
"type": "module",
|
|
21
|
+
"types": "./dist/index.d.ts",
|
|
22
|
+
"exports": {
|
|
23
|
+
".": {
|
|
24
|
+
"types": "./dist/index.d.ts",
|
|
25
|
+
"default": "./dist/index.js"
|
|
26
|
+
},
|
|
27
|
+
"./package.json": "./package.json"
|
|
28
|
+
},
|
|
29
|
+
"files": [
|
|
30
|
+
"dist",
|
|
31
|
+
"CHANGELOG.md",
|
|
32
|
+
"README.md",
|
|
33
|
+
"LICENSE"
|
|
34
|
+
],
|
|
35
|
+
"sideEffects": false,
|
|
36
|
+
"dependencies": {
|
|
37
|
+
"@dovetail-ts/protocol": "1.0.1",
|
|
38
|
+
"@rails/actioncable": "^8.1.401"
|
|
39
|
+
},
|
|
40
|
+
"devDependencies": {
|
|
41
|
+
"tsup": "^8.5.1"
|
|
42
|
+
},
|
|
43
|
+
"publishConfig": {
|
|
44
|
+
"access": "public"
|
|
45
|
+
},
|
|
46
|
+
"engines": {
|
|
47
|
+
"node": ">=22.12.0"
|
|
48
|
+
},
|
|
49
|
+
"scripts": {
|
|
50
|
+
"build": "tsc --build --force && tsup"
|
|
51
|
+
}
|
|
6
52
|
}
|