Server-side work
Convert, edit, and export documents in Node with revise/server.
revise/server is the SDK's self-contained Node entry point, included in
revise. The SDK license
covers programmatic use, including commercial-use requirements.
npm i revise@4.3.0pnpm add revise@4.3.0yarn add revise@4.3.0The library docs cover this API.
The editor never imports revise/server, and server code that imports it
doesn't load React.
Documents move between the two unchanged: a Y.Doc the editor edits is a
Y.Doc revise/server opens, and the reverse. It runs the same converters and
the same document tools, with the same schemas and { ok, value | error }
results, so a server can seed a room, edit it while people have it open, and
export it to Word:
import { ReviseDocument } from "revise/server";
import type * as Y from "yjs";
async function reviewRoom(room: Y.Doc): Promise<Uint8Array> {
const doc = await ReviseDocument.fromYDoc(room, { author: "Review bot" });
try {
const [hit] = doc.grep("Delaware");
if (hit) {
// A tracked change in every open editor.
await doc.tools.call("replace", {
id: hit.id,
replacements: [{ find: "Delaware", replace: "New York" }],
});
}
const { bytes } = await doc.export({ format: "docx" });
return bytes;
} finally {
doc.dispose(); // the room stays alive
}
}Open, read, edit, review, and export documents.
Seed, edit, and export live rooms.
A server and browsers in the same room.
The agent tools without a browser.
Upgrade from 2.x#
The 2.x server entry point exported standalone functions; 4.x is built around
ReviseDocument. The 2.x names still import from revise/server, so a build
doesn't break on them, but each one throws when used, naming its replacement.
The 2.3 reference documents them.
| 2.x | 4.x |
|---|---|
createServerDocumentSession(ydoc) | ReviseDocument.fromYDoc(ydoc), then doc.tools |
parseDocument, documentToDocx, fileToYDoc | ReviseDocument.open(file), doc.export({ format: "docx" }), doc.ydoc |
exportDocument(room, { mode }), ydocToDocx(room) | ReviseDocument.fromYDoc(room), then doc.export({ format, mode }) |
seedYDocFromFile(room, bytes, filename) | seedYDoc(room, { bytes, filename }) |
encodeYDoc, decodeYDoc | Y.js itself: Y.encodeStateAsUpdate(doc.ydoc); ReviseDocument.restore(update) opens a bare update |
Three differences when porting:
ReviseDocumentmethods are async:awaitthem.- Tools return
{ ok: true, value }or{ ok: false, error }instead of throwing.doc.tools.call()is the typed form;doc.tools.run()takes a tool name and JSON from a model. doc.export()returns{ bytes, fidelity, … }: write.bytes.
The server runtime includes its required dependencies.
doc.snapshot() is Revise's own storage format, not a Y.js update: keep
Y.encodeStateAsUpdate(doc.ydoc) for anything that speaks Y.js, such as a
sync server or the editor.
License#
The SDK license covers revise/server, its bindings,
and its bundled engine. Its commercial-use requirements apply to server-only
applications as well as applications embedding the editor.