braid-text 0.0.8 → 0.0.10
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/README.md +19 -16
- package/index.js +1 -1
- package/package.json +1 -1
- package/server-demo.js +1 -1
package/README.md
CHANGED
|
@@ -8,11 +8,14 @@ This library provides a simple http route handler, along with client code, enabl
|
|
|
8
8
|
- As little as 50 lines of code!
|
|
9
9
|
- With zero history overhead on client
|
|
10
10
|
- Supports [backpressure](https://braid.org/meeting-81/simpleton) to run smoothly on constrained servers
|
|
11
|
-
-
|
|
11
|
+
- Server merges with Diamond-Types
|
|
12
12
|
- Supports [Diamond Types](https://github.com/josephg/diamond-types) merge-type
|
|
13
|
-
-
|
|
13
|
+
- Fully peer-to-peer CRDT
|
|
14
|
+
- Fast / Robust / Extensively fuzz-tested
|
|
14
15
|
- Developed in [braid.org](https://braid.org)
|
|
15
16
|
|
|
17
|
+
This library makes it safe, easy & efficient to add collaborative text editing to every user-editable string in your web app. Make your app multiplayer!
|
|
18
|
+
|
|
16
19
|
### Demo: a Wiki!
|
|
17
20
|
|
|
18
21
|
This will run a collaboratively-editable wiki:
|
|
@@ -26,8 +29,9 @@ Now open these URLs in your browser:
|
|
|
26
29
|
- http://localhost:8888/demo (to see the demo text)
|
|
27
30
|
- http://localhost:8888/demo?editor (to edit the text)
|
|
28
31
|
- http://localhost:8888/demo?markdown-editor (to edit it as markdown)
|
|
32
|
+
- http://localhost:8888/any-other-path?editor (to create a new page, just go to its URL, and then start editing)
|
|
29
33
|
|
|
30
|
-
Or try opening the URL in [Braid-Chrome](https://github.com/braid-org/braid-chrome), or another Braid client, to edit it directly!
|
|
34
|
+
Or try opening the URL in [Braid-Chrome](https://github.com/braid-org/braid-chrome), or [another Braid client](https://bloop.monster/simpleditor), to edit it directly!
|
|
31
35
|
|
|
32
36
|
Check out the `server-demo.js` file to see examples for how to add access control, and a `/pages` endpoint to show all the edited pages.
|
|
33
37
|
|
|
@@ -59,8 +63,8 @@ http_server.on("request", (req, res) => {
|
|
|
59
63
|
- The files for a resource will all be prefixed with a url-encoding of `key` within this folder.
|
|
60
64
|
|
|
61
65
|
`braid_text.serve(req, res, options)`
|
|
62
|
-
- `req`:
|
|
63
|
-
- `res`:
|
|
66
|
+
- `req`: Incoming HTTP request object.
|
|
67
|
+
- `res`: Outgoing HTTP response object.
|
|
64
68
|
- `options`: <small style="color:lightgrey">[optional]</small> An object containing additional options:
|
|
65
69
|
- `key`: <small style="color:lightgrey">[optional]</small> ID of text resource to sync with. Defaults to `req.url`.
|
|
66
70
|
- This is the main method of this library, and does all the work to handle Braid-HTTP `GET` and `PUT` requests concerned with a specific text resource.
|
|
@@ -72,21 +76,20 @@ http_server.on("request", (req, res) => {
|
|
|
72
76
|
`await braid_text.get(key, options)`
|
|
73
77
|
- `key`: ID of text resource.
|
|
74
78
|
- `options`: An object containing additional options, like http headers:
|
|
75
|
-
- `version`: <small style="color:lightgrey">[optional]</small> The version to get.
|
|
76
|
-
- `
|
|
77
|
-
- `
|
|
78
|
-
- `merge_type`: <small style="color:lightgrey">[optional]</small>
|
|
79
|
-
- `peer`: <small style="color:lightgrey">[optional]</small>
|
|
80
|
-
|
|
81
|
-
- If we are NOT subscribing, returns `{version, body}`, with the `version` being returned, and the text as `body`. If we are subscribing, this returns nothing.
|
|
79
|
+
- `version`: <small style="color:lightgrey">[optional]</small> The [version](https://datatracker.ietf.org/doc/html/draft-toomim-httpbis-braid-http#section-2) to get, as an array of strings. (The array is typically length 1.)
|
|
80
|
+
- `parents`: <small style="color:lightgrey">[optional]</small> The version to start the subscription at, as an array of strings.
|
|
81
|
+
- `subscribe: cb`: <small style="color:lightgrey">[optional]</small> Instead of returning the state; [subscribes](https://datatracker.ietf.org/doc/html/draft-toomim-httpbis-braid-http#section-4) to the state, and calls `cb` with the initial state and each update. The function `cb` will be called with a Braid [update](https://datatracker.ietf.org/doc/html/draft-toomim-httpbis-braid-http#section-3) of the form `cb({version, parents, body, patches})`.
|
|
82
|
+
- `merge_type`: <small style="color:lightgrey">[optional]</small> The CRDT/OT [merge-type](https://raw.githubusercontent.com/braid-org/braid-spec/master/draft-toomim-httpbis-merge-types-00.txt) algorithm to emulate. Currently supports `"simpleton"` (default) and `"dt"`.
|
|
83
|
+
- `peer`: <small style="color:lightgrey">[optional]</small> Unique string ID that identifies the peer making the subscription. Mutations will not be echoed back to the same peer that `PUT`s them, for any `PUT` setting the same `peer` header.
|
|
84
|
+
- If NOT subscribing, returns `{version: <current_version>, body: <current-text>}`. If subscribing, returns nothing.
|
|
82
85
|
|
|
83
86
|
`await braid_text.put(key, options)`
|
|
84
87
|
- `key`: ID of text resource.
|
|
85
88
|
- `options`: An object containing additional options, like http headers:
|
|
86
|
-
- `version`: <small style="color:lightgrey">[optional]</small> The version being
|
|
87
|
-
- `parents`: <small style="color:lightgrey">[optional]</small>
|
|
88
|
-
- `body`: <small style="color:lightgrey">[optional]</small> Use this to completely replace the existing text with this new text.
|
|
89
|
-
- `patches`: <small style="color:lightgrey">[optional]</small> Array of patches, each of the form `{unit: 'text', range: '[1:3]', content: 'hi'}`, which would replace the second and third unicode code-points in the text with `hi`.
|
|
89
|
+
- `version`: <small style="color:lightgrey">[optional]</small> The [version](https://datatracker.ietf.org/doc/html/draft-toomim-httpbis-braid-http#section-2) being `PUT`, as an array of strings. Will be generated if not provided.
|
|
90
|
+
- `parents`: <small style="color:lightgrey">[optional]</small> The previous version being updated, as array of strings. Defaults to the server’s current version.
|
|
91
|
+
- `body`: <small style="color:lightgrey">[optional]</small> Use this to completely replace the existing text with this new text. See Braid [updates](https://datatracker.ietf.org/doc/html/draft-toomim-httpbis-braid-http#section-3).
|
|
92
|
+
- `patches`: <small style="color:lightgrey">[optional]</small> Array of patches, each of the form `{unit: 'text', range: '[1:3]', content: 'hi'}`, which would replace the second and third unicode code-points in the text with `hi`. See Braid [Range-Patches](https://github.com/braid-org/braid-spec/blob/master/draft-toomim-httpbis-range-patch-01.txt).
|
|
90
93
|
- `peer`: <small style="color:lightgrey">[optional]</small> Identifies this peer. This mutation will not be echoed back to `get` subscriptions that use this same `peer` header.
|
|
91
94
|
|
|
92
95
|
## General Use on Client
|
package/index.js
CHANGED
|
@@ -261,7 +261,7 @@ braid_text.get = async (key, options) => {
|
|
|
261
261
|
let local_version = OpLog_remote_to_local(resource.doc, x.parents)
|
|
262
262
|
if (local_version) {
|
|
263
263
|
x.patches = get_xf_patches(resource.doc, local_version)
|
|
264
|
-
|
|
264
|
+
options.subscribe(x)
|
|
265
265
|
}
|
|
266
266
|
}
|
|
267
267
|
|
package/package.json
CHANGED
package/server-demo.js
CHANGED