@dovetail-ts/hocuspocus 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 +30 -0
- package/LICENSE +21 -0
- package/README.md +50 -2
- package/dist/engine-error.d.ts +6 -0
- package/dist/index.d.ts +25 -0
- package/dist/index.js +54 -0
- package/dist/index.js.map +1 -0
- package/dist/yjs.d.ts +4 -0
- package/package.json +53 -3
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# @dovetail-ts/hocuspocus
|
|
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/crdt@1.0.1
|
|
10
|
+
- @dovetail-ts/protocol@1.0.1
|
|
11
|
+
|
|
12
|
+
## 1.0.0
|
|
13
|
+
|
|
14
|
+
### Major Changes
|
|
15
|
+
|
|
16
|
+
- 480744b: First release of Dovetail: real-time and offline sync for Ember.
|
|
17
|
+
|
|
18
|
+
- `@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`.
|
|
19
|
+
- `@dovetail-ts/warp-drive`: the store feed into WarpDrive.
|
|
20
|
+
- `@dovetail-ts/crdt`, `crdt-yjs`, `crdt-loro` and `crdt-automerge`: one `DocEngine` interface with three engines.
|
|
21
|
+
- `@dovetail-ts/tiptap`: co-editing in Tiptap 3 with carets, per-user undo, versions and comment threads.
|
|
22
|
+
- `@dovetail-ts/ember`, `notifications` and `inspector`: presence and status components, the inbox, toasts and activity feeds, and a dev panel.
|
|
23
|
+
- `@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.
|
|
24
|
+
- 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).
|
|
25
|
+
|
|
26
|
+
### Patch Changes
|
|
27
|
+
|
|
28
|
+
- Updated dependencies [480744b]
|
|
29
|
+
- @dovetail-ts/crdt@1.0.0
|
|
30
|
+
- @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,51 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @dovetail-ts/hocuspocus
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The Hocuspocus adapter: doc sync and presence for a Yjs document.
|
|
4
|
+
|
|
5
|
+
Part of [Dovetail](https://joegaudet.com/dovetail/). Not released yet.
|
|
6
|
+
|
|
7
|
+
| Kind | Supported |
|
|
8
|
+
| ----------- | --------- |
|
|
9
|
+
| `StoreFeed` | No |
|
|
10
|
+
| `DocSync` | Yes |
|
|
11
|
+
| `Presence` | Yes |
|
|
12
|
+
|
|
13
|
+
`kinds` has the same list: `['DocSync', 'Presence']`.
|
|
14
|
+
|
|
15
|
+
## Use
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
import { yjsEngine } from '@dovetail-ts/crdt-yjs'
|
|
19
|
+
import { hocuspocusSync } from '@dovetail-ts/hocuspocus'
|
|
20
|
+
|
|
21
|
+
const handle = yjsEngine().create()
|
|
22
|
+
const sync = hocuspocusSync(handle, {
|
|
23
|
+
url: 'wss://collab.example.com',
|
|
24
|
+
name: 'notes:42',
|
|
25
|
+
token: () => getToken(),
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
sync.provider.on('synced', () => console.log('synced'))
|
|
29
|
+
sync.destroy()
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
`hocuspocusSync(handle, options)` takes the configuration of `HocuspocusProvider`, without
|
|
33
|
+
`document` and `awareness`. The handle gives them. Give `url` or a shared `websocketProvider`.
|
|
34
|
+
|
|
35
|
+
- The provider uses the Yjs document and the awareness of the handle. Presence thus needs no
|
|
36
|
+
bridge, and the Tiptap carets work.
|
|
37
|
+
- `destroy()` stops the sync. The provider removes the local awareness state, so the peers see
|
|
38
|
+
that this client left. The handle and its awareness stay usable.
|
|
39
|
+
|
|
40
|
+
## Yjs only
|
|
41
|
+
|
|
42
|
+
Hocuspocus supports Yjs only (ADR 0002). A handle of another engine gives an `EngineError`:
|
|
43
|
+
|
|
44
|
+
```
|
|
45
|
+
The Hocuspocus adapter supports the Yjs engine only. This document uses the "loro" engine.
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## Tests
|
|
49
|
+
|
|
50
|
+
The unit tests do not open a socket. The live test runs only when `HOCUSPOCUS_URL` names a
|
|
51
|
+
Hocuspocus server, for example `ws://127.0.0.1:1234`.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { HocuspocusProvider } from '@hocuspocus/provider';
|
|
2
|
+
import type { HocuspocusProviderConfiguration } from '@hocuspocus/provider';
|
|
3
|
+
import type { DocHandle } from '@dovetail-ts/crdt';
|
|
4
|
+
export { EngineError } from './engine-error';
|
|
5
|
+
/** The name of this package. */
|
|
6
|
+
export declare const PACKAGE_NAME = "@dovetail-ts/hocuspocus";
|
|
7
|
+
/** A kind of adapter (ADR 0003). */
|
|
8
|
+
export type AdapterKind = 'StoreFeed' | 'DocSync' | 'Presence';
|
|
9
|
+
/** The kinds that this adapter supports. */
|
|
10
|
+
export declare const kinds: readonly ["DocSync", "Presence"];
|
|
11
|
+
type DistributiveOmit<T, K extends PropertyKey> = T extends unknown ? Omit<T, K> : never;
|
|
12
|
+
/** The provider configuration without `document` and `awareness`: the handle gives them. */
|
|
13
|
+
export type HocuspocusSyncOptions = DistributiveOmit<HocuspocusProviderConfiguration, 'document' | 'awareness'>;
|
|
14
|
+
/** The doc sync and the presence of one document. */
|
|
15
|
+
export interface HocuspocusSync {
|
|
16
|
+
/** The provider, for its events (`synced`, `status`) and `sendStateless`. */
|
|
17
|
+
readonly provider: HocuspocusProvider;
|
|
18
|
+
/** Stops the sync. The handle and its awareness stay usable. */
|
|
19
|
+
destroy(): void;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Syncs a Yjs document and its awareness with a Hocuspocus server. Throws an `EngineError` for
|
|
23
|
+
* a document of another engine.
|
|
24
|
+
*/
|
|
25
|
+
export declare function hocuspocusSync(handle: DocHandle, options: HocuspocusSyncOptions): HocuspocusSync;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { HocuspocusProvider } from '@hocuspocus/provider';
|
|
2
|
+
import * as Y from 'yjs';
|
|
3
|
+
|
|
4
|
+
// src/index.ts
|
|
5
|
+
|
|
6
|
+
// src/engine-error.ts
|
|
7
|
+
var EngineError = class extends Error {
|
|
8
|
+
constructor(adapter, engine) {
|
|
9
|
+
super(
|
|
10
|
+
`The ${adapter} adapter supports the Yjs engine only. This document uses the "${engine}" engine.`
|
|
11
|
+
);
|
|
12
|
+
this.adapter = adapter;
|
|
13
|
+
this.engine = engine;
|
|
14
|
+
this.name = "EngineError";
|
|
15
|
+
}
|
|
16
|
+
adapter;
|
|
17
|
+
engine;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
// src/yjs.ts
|
|
21
|
+
function requireYjs(handle, adapter) {
|
|
22
|
+
if (isYjs(handle)) return handle;
|
|
23
|
+
throw new EngineError(adapter, handle.engine.name);
|
|
24
|
+
}
|
|
25
|
+
function isYjs(handle) {
|
|
26
|
+
return handle.engine.name === "yjs" && "doc" in handle && handle.doc instanceof Y.Doc && "yAwareness" in handle;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// src/index.ts
|
|
30
|
+
var PACKAGE_NAME = "@dovetail-ts/hocuspocus";
|
|
31
|
+
var kinds = ["DocSync", "Presence"];
|
|
32
|
+
function hocuspocusSync(handle, options) {
|
|
33
|
+
const yjs = requireYjs(handle, "Hocuspocus");
|
|
34
|
+
const provider = new HocuspocusProvider({
|
|
35
|
+
...options,
|
|
36
|
+
document: yjs.doc,
|
|
37
|
+
awareness: keepAlive(yjs.yAwareness)
|
|
38
|
+
});
|
|
39
|
+
return { provider, destroy: () => provider.destroy() };
|
|
40
|
+
}
|
|
41
|
+
function keepAlive(awareness) {
|
|
42
|
+
return new Proxy(awareness, {
|
|
43
|
+
get(target, key) {
|
|
44
|
+
if (key === "destroy") return () => {
|
|
45
|
+
};
|
|
46
|
+
const value = Reflect.get(target, key, target);
|
|
47
|
+
return typeof value === "function" ? value.bind(target) : value;
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export { EngineError, PACKAGE_NAME, hocuspocusSync, kinds };
|
|
53
|
+
//# sourceMappingURL=index.js.map
|
|
54
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/engine-error.ts","../src/yjs.ts","../src/index.ts"],"names":[],"mappings":";;;;;;AAGO,IAAM,WAAA,GAAN,cAA0B,KAAA,CAAM;AAAA,EACrC,WAAA,CACW,SACA,MAAA,EACT;AACA,IAAA,KAAA;AAAA,MACE,CAAA,IAAA,EAAO,OAAO,CAAA,+DAAA,EACe,MAAM,CAAA,SAAA;AAAA,KACrC;AANS,IAAA,IAAA,CAAA,OAAA,GAAA,OAAA;AACA,IAAA,IAAA,CAAA,MAAA,GAAA,MAAA;AAMT,IAAA,IAAA,CAAK,IAAA,GAAO,aAAA;AAAA,EACd;AAAA,EARW,OAAA;AAAA,EACA,MAAA;AAQb;;;ACPO,SAAS,UAAA,CAAW,QAAmB,OAAA,EAA+B;AAC3E,EAAA,IAAI,KAAA,CAAM,MAAM,CAAA,EAAG,OAAO,MAAA;AAC1B,EAAA,MAAM,IAAI,WAAA,CAAY,OAAA,EAAS,MAAA,CAAO,OAAO,IAAI,CAAA;AACnD;AAEA,SAAS,MAAM,MAAA,EAA2C;AACxD,EAAA,OACE,MAAA,CAAO,OAAO,IAAA,KAAS,KAAA,IACvB,SAAS,MAAA,IACT,MAAA,CAAO,GAAA,YAAiB,CAAA,CAAA,GAAA,IACxB,YAAA,IAAgB,MAAA;AAEpB;;;ACTO,IAAM,YAAA,GAAe;AAMrB,IAAM,KAAA,GAAQ,CAAC,SAAA,EAAW,UAAU;AAsBpC,SAAS,cAAA,CAAe,QAAmB,OAAA,EAAgD;AAChG,EAAA,MAAM,GAAA,GAAM,UAAA,CAAW,MAAA,EAAQ,YAAY,CAAA;AAC3C,EAAA,MAAM,QAAA,GAAW,IAAI,kBAAA,CAAmB;AAAA,IACtC,GAAG,OAAA;AAAA,IACH,UAAU,GAAA,CAAI,GAAA;AAAA,IACd,SAAA,EAAW,SAAA,CAAU,GAAA,CAAI,UAAU;AAAA,GACpC,CAAA;AACD,EAAA,OAAO,EAAE,QAAA,EAAU,OAAA,EAAS,MAAM,QAAA,CAAS,SAAQ,EAAE;AACvD;AAUA,SAAS,UAAkD,SAAA,EAAiB;AAC1E,EAAA,OAAO,IAAI,MAAM,SAAA,EAAW;AAAA,IAC1B,GAAA,CAAI,QAAQ,GAAA,EAAK;AACf,MAAA,IAAI,GAAA,KAAQ,SAAA,EAAW,OAAO,MAAM;AAAA,MAAC,CAAA;AACrC,MAAA,MAAM,KAAA,GAAiB,OAAA,CAAQ,GAAA,CAAI,MAAA,EAAQ,KAAK,MAAM,CAAA;AACtD,MAAA,OAAO,OAAO,KAAA,KAAU,UAAA,GAAa,KAAA,CAAM,IAAA,CAAK,MAAM,CAAA,GAAI,KAAA;AAAA,IAC5D;AAAA,GACD,CAAA;AACH","file":"index.js","sourcesContent":["// The error of an adapter that supports the Yjs engine only (ADR 0002).\n\n/** The error for a document of an engine that the adapter does not support. */\nexport class EngineError extends Error {\n constructor(\n readonly adapter: string,\n readonly engine: string,\n ) {\n super(\n `The ${adapter} adapter supports the Yjs engine only. ` +\n `This document uses the \"${engine}\" engine.`,\n )\n this.name = 'EngineError'\n }\n}\n","// The Yjs check of the adapters that support the Yjs engine only (ADR 0002).\nimport * as Y from 'yjs'\nimport type { DocHandle } from '@dovetail-ts/crdt'\nimport type { YjsDocHandle } from '@dovetail-ts/crdt-yjs'\nimport { EngineError } from './engine-error'\n\n/** Gives the handle as a Yjs handle, or throws an `EngineError`. */\nexport function requireYjs(handle: DocHandle, adapter: string): YjsDocHandle {\n if (isYjs(handle)) return handle\n throw new EngineError(adapter, handle.engine.name)\n}\n\nfunction isYjs(handle: DocHandle): handle is YjsDocHandle {\n return (\n handle.engine.name === 'yjs' &&\n 'doc' in handle &&\n handle.doc instanceof Y.Doc &&\n 'yAwareness' in handle\n )\n}\n","// The Hocuspocus adapter: doc sync and presence for a Yjs document (ADR 0003, ADR 0017). The\n// provider uses the Yjs document and the awareness of the handle, so presence needs no bridge.\nimport { HocuspocusProvider } from '@hocuspocus/provider'\nimport type { HocuspocusProviderConfiguration } from '@hocuspocus/provider'\nimport type { DocHandle } from '@dovetail-ts/crdt'\nimport { requireYjs } from './yjs'\n\nexport { EngineError } from './engine-error'\n\n/** The name of this package. */\nexport const PACKAGE_NAME = '@dovetail-ts/hocuspocus'\n\n/** A kind of adapter (ADR 0003). */\nexport type AdapterKind = 'StoreFeed' | 'DocSync' | 'Presence'\n\n/** The kinds that this adapter supports. */\nexport const kinds = ['DocSync', 'Presence'] as const satisfies readonly AdapterKind[]\n\ntype DistributiveOmit<T, K extends PropertyKey> = T extends unknown ? Omit<T, K> : never\n\n/** The provider configuration without `document` and `awareness`: the handle gives them. */\nexport type HocuspocusSyncOptions = DistributiveOmit<\n HocuspocusProviderConfiguration,\n 'document' | 'awareness'\n>\n\n/** The doc sync and the presence of one document. */\nexport interface HocuspocusSync {\n /** The provider, for its events (`synced`, `status`) and `sendStateless`. */\n readonly provider: HocuspocusProvider\n /** Stops the sync. The handle and its awareness stay usable. */\n destroy(): void\n}\n\n/**\n * Syncs a Yjs document and its awareness with a Hocuspocus server. Throws an `EngineError` for\n * a document of another engine.\n */\nexport function hocuspocusSync(handle: DocHandle, options: HocuspocusSyncOptions): HocuspocusSync {\n const yjs = requireYjs(handle, 'Hocuspocus')\n const provider = new HocuspocusProvider({\n ...options,\n document: yjs.doc,\n awareness: keepAlive(yjs.yAwareness),\n })\n return { provider, destroy: () => provider.destroy() }\n}\n\n/**\n * The awareness of the handle, but `destroy` does nothing. `HocuspocusProvider.destroy` destroys\n * its awareness, and the handle owns this one. The provider still removes the local state, so\n * the peers see that this client left.\n *\n * shortcut: the provider keeps two listeners on the awareness after destroy, so each provider\n * stays in memory while the handle lives. Remove them when Hocuspocus lets a provider do so.\n */\nfunction keepAlive<T extends object & { destroy(): void }>(awareness: T): T {\n return new Proxy(awareness, {\n get(target, key) {\n if (key === 'destroy') return () => {}\n const value: unknown = Reflect.get(target, key, target)\n return typeof value === 'function' ? value.bind(target) : value\n },\n })\n}\n"]}
|
package/dist/yjs.d.ts
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,56 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dovetail-ts/hocuspocus",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"description": "The Hocuspocus adapter: doc sync and presence. Yjs only.",
|
|
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/hocuspocus"
|
|
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/crdt": "1.0.1",
|
|
38
|
+
"@dovetail-ts/protocol": "1.0.1",
|
|
39
|
+
"@hocuspocus/provider": "^4.9.0",
|
|
40
|
+
"yjs": "^13.6.33"
|
|
41
|
+
},
|
|
42
|
+
"devDependencies": {
|
|
43
|
+
"@dovetail-ts/crdt-loro": "1.0.1",
|
|
44
|
+
"@dovetail-ts/crdt-yjs": "1.0.1",
|
|
45
|
+
"tsup": "^8.5.1"
|
|
46
|
+
},
|
|
47
|
+
"publishConfig": {
|
|
48
|
+
"access": "public"
|
|
49
|
+
},
|
|
50
|
+
"engines": {
|
|
51
|
+
"node": ">=22.12.0"
|
|
52
|
+
},
|
|
53
|
+
"scripts": {
|
|
54
|
+
"build": "tsc --build --force && tsup"
|
|
55
|
+
}
|
|
6
56
|
}
|