@hocuspocus/extension-database 4.0.0-rc.6 → 4.0.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.
Files changed (2) hide show
  1. package/README.md +42 -5
  2. package/package.json +3 -3
package/README.md CHANGED
@@ -4,11 +4,48 @@
4
4
  [![License](https://img.shields.io/npm/l/@hocuspocus/extension-database.svg)](https://www.npmjs.com/package/@hocuspocus/extension-database)
5
5
  [![Sponsor](https://img.shields.io/static/v1?label=Sponsor&message=%E2%9D%A4&logo=GitHub)](https://github.com/sponsors/ueberdosis)
6
6
 
7
- ## Introduction
8
- A generic persistence base class for [Hocuspocus](https://github.com/ueberdosis/hocuspocus). Provide your own `fetch` and `store` functions to plug any database into the collaboration backend, or extend the `Database` class to build a dedicated storage extension (as `@hocuspocus/extension-sqlite` and `@hocuspocus/extension-s3` do).
7
+ A generic persistence base class for [Hocuspocus](https://github.com/ueberdosis/hocuspocus). Provide your own `fetch` and `store` functions to plug any database into the collaboration backend — Postgres, MySQL, MongoDB, a REST API, etc.
9
8
 
10
- ## Official Documentation
11
- Documentation can be found in the [GitHub repository](https://github.com/ueberdosis/hocuspocus).
9
+ ## Installation
10
+
11
+ ```bash
12
+ npm install @hocuspocus/extension-database
13
+ ```
14
+
15
+ ## Usage
16
+
17
+ Plug in any storage backend by implementing two async functions:
18
+
19
+ ```js
20
+ import { Server } from "@hocuspocus/server"
21
+ import { Database } from "@hocuspocus/extension-database"
22
+
23
+ const server = new Server({
24
+ extensions: [
25
+ new Database({
26
+ fetch: async ({ documentName }) => {
27
+ // return a Uint8Array of the stored Y.js update, or null for new documents
28
+ return await yourDb.findDocument(documentName)
29
+ },
30
+ store: async ({ documentName, state }) => {
31
+ // persist the binary Y.js state wherever you like
32
+ await yourDb.upsertDocument(documentName, state)
33
+ },
34
+ }),
35
+ ],
36
+ })
37
+
38
+ server.listen()
39
+ ```
40
+
41
+ `state` is a `Buffer` containing the encoded Y.js update. Store it as-is and return it unchanged from `fetch`.
42
+
43
+ For dedicated storage drivers, see [`@hocuspocus/extension-sqlite`](../extension-sqlite) or [`@hocuspocus/extension-s3`](../extension-s3), both of which extend this base class.
44
+
45
+ ## Documentation
46
+
47
+ Persistence patterns and performance tips: [tiptap.dev/docs/hocuspocus/guides/persistence](https://tiptap.dev/docs/hocuspocus/guides/persistence).
12
48
 
13
49
  ## License
14
- Hocuspocus is open-sourced software licensed under the [MIT license](https://github.com/ueberdosis/hocuspocus/blob/main/LICENSE.md).
50
+
51
+ MIT — see [LICENSE.md](https://github.com/ueberdosis/hocuspocus/blob/main/LICENSE.md).
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@hocuspocus/extension-database",
3
3
  "description": "a generic Hocuspocus persistence driver for the database",
4
- "version": "4.0.0-rc.6",
4
+ "version": "4.0.0",
5
5
  "homepage": "https://hocuspocus.dev",
6
6
  "keywords": [
7
7
  "hocuspocus",
@@ -27,7 +27,7 @@
27
27
  "dist"
28
28
  ],
29
29
  "dependencies": {
30
- "@hocuspocus/server": "^4.0.0-rc.6"
30
+ "@hocuspocus/server": "^4.0.0"
31
31
  },
32
32
  "peerDependencies": {
33
33
  "yjs": "^13.6.8"
@@ -35,7 +35,7 @@
35
35
  "publishConfig": {
36
36
  "access": "public"
37
37
  },
38
- "gitHead": "f8b039aea9d9c7f5b80b2cbb82381e2153ef8dc0",
38
+ "gitHead": "1c1b34800f702a06e1ce236e8a175c82876bff42",
39
39
  "repository": {
40
40
  "url": "https://github.com/ueberdosis/hocuspocus"
41
41
  }