PdfEx.Session (pdf_ex v0.1.0)

Copy Markdown View Source

Public facade for collaborative editing sessions.

open/1 seeds the snapshot and starts a supervised per-document session. Writes (apply_op/2) are serialized through the session GenServer; reads (fetch/1) bypass it entirely and read the CacheOwner-held ETS snapshot.

Summary

Functions

Applies an op to the session (server-serialized write). For OT-mediated concurrent edits use submit_op/2.

Stops the session and drops its cached snapshot.

Reads the current document snapshot directly from the cache (bypasses the server).

Seeds the snapshot and starts a supervised session. Returns its doc_id (pass :id to choose one).

Submits an OT Pending op; it is transformed against concurrent edits, applied, and the new version returned (:noop if dropped).

Returns the session's current version counter.

Returns the session GenServer pid for doc_id, or nil if none is running.

Types

doc_id()

@type doc_id() :: term()

Functions

apply_op(doc_id, op)

@spec apply_op(doc_id(), PdfEx.Op.t()) ::
  {:ok, PdfEx.Op.t()} | {:error, PdfEx.Error.t()}

Applies an op to the session (server-serialized write). For OT-mediated concurrent edits use submit_op/2.

close(doc_id)

@spec close(doc_id()) :: :ok

Stops the session and drops its cached snapshot.

fetch(doc_id)

@spec fetch(doc_id()) :: {:ok, PdfEx.Document.t()} | {:error, :no_session}

Reads the current document snapshot directly from the cache (bypasses the server).

open(doc, opts \\ [])

@spec open(PdfEx.Document.t(), [{:id, doc_id()}]) ::
  {:ok, doc_id()} | {:error, term()}

Seeds the snapshot and starts a supervised session. Returns its doc_id (pass :id to choose one).

submit_op(doc_id, pending)

@spec submit_op(doc_id(), PdfEx.OT.Pending.t()) ::
  {:ok, PdfEx.Op.t() | :noop, non_neg_integer()} | {:error, PdfEx.Error.t()}

Submits an OT Pending op; it is transformed against concurrent edits, applied, and the new version returned (:noop if dropped).

version(doc_id)

@spec version(doc_id()) :: non_neg_integer()

Returns the session's current version counter.

whereis(doc_id)

@spec whereis(doc_id()) :: pid() | nil

Returns the session GenServer pid for doc_id, or nil if none is running.