Add real-time collaboration with page history
Pages are now shared Yjs documents. docwell-server relays the y-websocket protocol at /collab (token sent as the first message), flushes updates to page_yupdates every second, and compacts them into page_ydoc with yrs compiled to WebAssembly under wazero (ADR-3) after 30 s idle or when the last editor leaves. Compaction refreshes content_json/content_text and records page_versions; versions can be listed, previewed and restored. The editor connects through a small y-protocols provider with carets and presence. Pages saved before this change are seeded from content_json. The yrs module lives in Server/ycrdt-wasm and is built by go generate, CI and the Dockerfiles rather than committed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
abf55a426b
commit
5e1dcf4291
45 files changed
+3480
-213
No files matched your search
+67
-3
@@ -717,7 +717,10 @@ paths:
|
||||
get:
|
||||
operationId: getPageContent
|
||||
tags: [pages]
|
||||
summary: The page's document as Tiptap JSON (null for a page that was never edited)
|
||||
summary: >-
|
||||
The page's document as Tiptap JSON (null for a page that was never edited).
|
||||
Editors sync the live document over the WebSocket at /collab instead
|
||||
(y-websocket protocol; send the session token as the first, text, message).
|
||||
security: [{ bearer: [] }]
|
||||
responses:
|
||||
"200":
|
||||
@@ -730,8 +733,8 @@ paths:
|
||||
operationId: savePageContent
|
||||
tags: [pages]
|
||||
summary: >-
|
||||
Replace the page's document (editor). Last write wins until the collab
|
||||
relay lands; the server derives the plain text and word count.
|
||||
Replace the page's document (editor). The change is applied as an edit
|
||||
to the live document, so open editors see it at once.
|
||||
security: [{ bearer: [] }]
|
||||
requestBody:
|
||||
required: true
|
||||
@@ -751,6 +754,59 @@ paths:
|
||||
"400": { $ref: "#/components/responses/Error" }
|
||||
"403": { $ref: "#/components/responses/Error" }
|
||||
"404": { $ref: "#/components/responses/Error" }
|
||||
/api/v1/pages/{id}/versions:
|
||||
parameters:
|
||||
- { name: id, in: path, required: true, schema: { type: string } }
|
||||
get:
|
||||
operationId: listPageVersions
|
||||
tags: [pages]
|
||||
summary: >-
|
||||
The page's history, newest first. A version is recorded at most every
|
||||
10 minutes while people edit, and when the last editor leaves.
|
||||
security: [{ bearer: [] }]
|
||||
responses:
|
||||
"200":
|
||||
description: OK
|
||||
content:
|
||||
application/json:
|
||||
schema: { type: array, items: { $ref: "#/components/schemas/PageVersion" } }
|
||||
"404": { $ref: "#/components/responses/Error" }
|
||||
/api/v1/pages/{id}/versions/{versionId}:
|
||||
parameters:
|
||||
- { name: id, in: path, required: true, schema: { type: string } }
|
||||
- { name: versionId, in: path, required: true, schema: { type: string } }
|
||||
get:
|
||||
operationId: getPageVersion
|
||||
tags: [pages]
|
||||
summary: One version's document
|
||||
security: [{ bearer: [] }]
|
||||
responses:
|
||||
"200":
|
||||
description: OK
|
||||
content:
|
||||
application/json:
|
||||
schema: { $ref: "#/components/schemas/PageContent" }
|
||||
"404": { $ref: "#/components/responses/Error" }
|
||||
/api/v1/pages/{id}/versions/{versionId}/restore:
|
||||
parameters:
|
||||
- { name: id, in: path, required: true, schema: { type: string } }
|
||||
- { name: versionId, in: path, required: true, schema: { type: string } }
|
||||
post:
|
||||
operationId: restorePageVersion
|
||||
tags: [pages]
|
||||
summary: >-
|
||||
Make an old version the page's document again (editor). It is applied as
|
||||
a new edit, so open editors update live and the current text stays in the history.
|
||||
security: [{ bearer: [] }]
|
||||
responses:
|
||||
"200":
|
||||
description: OK
|
||||
content:
|
||||
application/json:
|
||||
schema: { $ref: "#/components/schemas/PageContent" }
|
||||
"400": { $ref: "#/components/responses/Error" }
|
||||
"403": { $ref: "#/components/responses/Error" }
|
||||
"404": { $ref: "#/components/responses/Error" }
|
||||
/api/v1/pages/{id}/move:
|
||||
parameters:
|
||||
- { name: id, in: path, required: true, schema: { type: string } }
|
||||
@@ -984,6 +1040,14 @@ components:
|
||||
oneOf: [{ type: object, additionalProperties: true }, { type: "null" }]
|
||||
description: Tiptap JSON with type "doc"; null for a page that was never edited
|
||||
updated: { type: string }
|
||||
PageVersion:
|
||||
type: object
|
||||
required: [id, author, label, created]
|
||||
properties:
|
||||
id: { type: string }
|
||||
author: { type: string, description: Name (or email) of the last person who edited before it was taken }
|
||||
label: { type: string }
|
||||
created: { type: string }
|
||||
TrashedPage:
|
||||
type: object
|
||||
required: [id, title, icon, deletedAt]
|
||||
|
||||
Reference in new issue
Block a user