GenServer wrapper around ProsemirrorEx.Authority.
Handles JSON serialization/deserialization at the boundary so callers work with plain maps. Suitable for integration with Phoenix channels, LiveView, or any Elixir web framework.
Supports process subscriptions for new-step notifications (the Elixir
equivalent of the guide's onNewSteps callbacks / the collab demo's
waiting clients).
Usage
{:ok, pid} = Authority.Server.start_link(schema: schema, doc: doc_node)
# Optionally subscribe this process to updates
:ok = Authority.Server.subscribe(pid)
# Receive steps from a client (steps as JSON maps)
{:ok, new_version} = Authority.Server.receive_steps(pid, "client1", 0, [step_json])
# Subscribers receive:
# {:authority_update, %{version: v, steps: steps_json, client_ids: ids}}
# Get the current document as JSON
{doc_json, version} = Authority.Server.get_doc(pid)
# Get step history since a version
{:ok, steps_json, client_ids} = Authority.Server.steps_since(pid, 0)
Summary
Functions
Returns a specification to start this module under a supervisor.
Get the current document as JSON and the current version.
Get the current authority version.
Submit steps from a client.
Start a linked Authority.Server process.
Get all steps since the given version as JSON maps.
Subscribe the calling process to authority updates.
Unsubscribe a process from authority updates.
Functions
Returns a specification to start this module under a supervisor.
See Supervisor.
Get the current document as JSON and the current version.
Returns {doc_json, version}.
Get the current authority version.
Submit steps from a client.
steps_json is a list of step JSON maps (as would arrive from a client).
Steps are deserialized, validated, and applied.
On success, subscribed processes are notified with
{:authority_update, %{version, steps, client_ids}}.
Returns {:ok, new_version} on success, or {:error, reason} /
{:error, reason, message}.
Start a linked Authority.Server process.
Options
:schema(required) - the ProseMirror schema:doc(optional) - initial document node:max_history(optional) - max retained steps (seeAuthority.new/3):name(optional) - process name for registration
Get all steps since the given version as JSON maps.
Returns {:ok, steps_json, client_ids} or {:error, reason}
(:invalid_version or :history_unavailable).
Subscribe the calling process to authority updates.
The subscriber receives {:authority_update, payload} messages whenever
new steps are accepted. The subscription is removed automatically when the
subscriber exits.
Unsubscribe a process from authority updates.