Documentation
¶
Overview ¶
Package document provides bounded, document-level routing for MoveRGA sequences. It deliberately does not define another replication wire format: applications authenticate and authorize a document ID before selecting the corresponding, separately negotiated MoveRGA stream.
Index ¶
- Variables
- type DocManager
- func (m *DocManager[T]) ApplyDelta(id string, delta list.MoveDelta) error
- func (m *DocManager[T]) CreateDocument(id, replicaID string) (*list.MoveRGA[T], error)
- func (m *DocManager[T]) Delete(id string, offset, count int) (list.MoveDelta, error)
- func (m *DocManager[T]) Document(id string) (*list.MoveRGA[T], bool)
- func (m *DocManager[T]) DocumentIDs() []string
- func (m *DocManager[T]) Insert(id string, offset int, values []T) (list.MoveDelta, error)
- func (m *DocManager[T]) Len() int
- func (m *DocManager[T]) Move(id string, from, count, to int) (list.MoveDelta, error)
- type Options
Constants ¶
This section is empty.
Variables ¶
var ( ErrNilManager = errors.New("document: nil manager") ErrInvalidDocumentID = errors.New("document: invalid document ID") ErrDocumentExists = errors.New("document: document already exists") ErrDocumentNotFound = errors.New("document: document not found") ErrResourceLimit = errors.New("document: resource limit exceeded") )
Functions ¶
This section is empty.
Types ¶
type DocManager ¶
type DocManager[T any] struct { // contains filtered or unexported fields }
DocManager owns a fixed, explicitly created set of MoveRGA documents. It never creates a document while applying a remote delta: otherwise a peer could turn arbitrary document IDs into unbounded retained state.
The manager lock only protects the registry. Each returned MoveRGA has its own lock, so operations on different documents do not serialize globally.
func NewDocManager ¶
func NewDocManager[T any](codec list.ElementCodec[T], options Options) (*DocManager[T], error)
NewDocManager creates an empty document registry. It validates the shared codec and per-document options up front, so an invalid manager cannot become partially populated before its first CreateDocument call fails.
func (*DocManager[T]) ApplyDelta ¶
func (m *DocManager[T]) ApplyDelta(id string, delta list.MoveDelta) error
ApplyDelta routes one already-decoded MoveRGA delta to an existing document. Transport-facing callers must decode with list.UnmarshalMoveDeltaWithLimits and complete authentication/authorization before calling this method.
func (*DocManager[T]) CreateDocument ¶
func (m *DocManager[T]) CreateDocument(id, replicaID string) (*list.MoveRGA[T], error)
CreateDocument creates a locally authorized document with its own HLC replica ID. Call it on every replica before accepting deltas for that document. Reusing one logical replica ID after a restart requires restoring the document's clock together with its complete snapshot.
func (*DocManager[T]) Document ¶
func (m *DocManager[T]) Document(id string) (*list.MoveRGA[T], bool)
Document returns a document only when it was explicitly created. The returned CRDT remains independently concurrency-safe.
func (*DocManager[T]) DocumentIDs ¶
func (m *DocManager[T]) DocumentIDs() []string
DocumentIDs returns a sorted copy so callers can enumerate a stable view without gaining access to the manager's map.
func (*DocManager[T]) Len ¶
func (m *DocManager[T]) Len() int
Len reports the number of locally opened documents.
type Options ¶
Options bounds manager-owned document metadata. ListOptions applies to each individual document; it is intentionally not a shared global element budget. A replication service should choose both limits from its authenticated tenant and group policy rather than treating this manager as an authorization layer.
func DefaultOptions ¶
func DefaultOptions() Options
DefaultOptions returns conservative manager limits suitable for a single process. Production services should set limits appropriate to a tenant.