document

package
v0.4.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 29, 2023 License: Apache-2.0 Imports: 8 Imported by: 4

Documentation

Overview

Package document provides JSON-like document(CRDT) implementation.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrDocumentRemoved occurs when the document is removed.
	ErrDocumentRemoved = errors.New("document is removed")
)

Functions

This section is empty.

Types

type Document

type Document struct {
	// contains filtered or unexported fields
}

Document represents a document accessible to the user.

How document works: The operations are generated by the proxy while executing user's command on the clone. Then the operations will apply the changes into the base json root. This is to protect the base json from errors that may occur while user edit the document.

func New

func New(key key.Key) *Document

New creates a new instance of Document.

func (*Document) ActorID added in v0.2.2

func (d *Document) ActorID() *time.ActorID

ActorID returns ID of the actor currently editing the document.

func (*Document) ApplyChangePack

func (d *Document) ApplyChangePack(pack *change.Pack) error

ApplyChangePack applies the given change pack into this document.

func (*Document) Checkpoint

func (d *Document) Checkpoint() change.Checkpoint

Checkpoint returns the checkpoint of this document.

func (*Document) CreateChangePack

func (d *Document) CreateChangePack() *change.Pack

CreateChangePack creates pack of the local changes to send to the server.

func (*Document) GarbageCollect

func (d *Document) GarbageCollect(ticket *time.Ticket) int

GarbageCollect purge elements that were removed before the given time.

func (*Document) GarbageLen

func (d *Document) GarbageLen() int

GarbageLen returns the count of removed elements.

func (*Document) HasLocalChanges

func (d *Document) HasLocalChanges() bool

HasLocalChanges returns whether this document has local changes or not.

func (*Document) InternalDocument added in v0.1.11

func (d *Document) InternalDocument() *InternalDocument

InternalDocument returns the internal document.

func (*Document) IsAttached

func (d *Document) IsAttached() bool

IsAttached returns the whether this document is attached or not.

func (*Document) Key

func (d *Document) Key() key.Key

Key returns the key of this document.

func (*Document) Marshal

func (d *Document) Marshal() string

Marshal returns the JSON encoding of this document.

func (*Document) Root added in v0.1.3

func (d *Document) Root() *json.Object

Root returns the root object of this document.

func (*Document) RootObject

func (d *Document) RootObject() *crdt.Object

RootObject returns the internal root object of this document.

func (*Document) SetActor

func (d *Document) SetActor(actor *time.ActorID)

SetActor sets actor into this document. This is also applied in the local changes the document has.

func (*Document) SetStatus added in v0.1.1

func (d *Document) SetStatus(status StatusType)

SetStatus updates the status of this document.

func (*Document) Status added in v0.3.3

func (d *Document) Status() StatusType

Status returns the status of this document.

func (*Document) Update

func (d *Document) Update(
	updater func(root *json.Object) error,
	msgAndArgs ...interface{},
) error

Update executes the given updater to update this document.

type InternalDocument

type InternalDocument struct {
	// contains filtered or unexported fields
}

InternalDocument represents a document in MongoDB and contains logical clocks.

func NewInternalDocument

func NewInternalDocument(k key.Key) *InternalDocument

NewInternalDocument creates a new instance of InternalDocument.

func NewInternalDocumentFromSnapshot

func NewInternalDocumentFromSnapshot(
	k key.Key,
	serverSeq int64,
	lamport int64,
	snapshot []byte,
) (*InternalDocument, error)

NewInternalDocumentFromSnapshot creates a new instance of InternalDocument with the snapshot.

func (*InternalDocument) ActorID added in v0.2.2

func (d *InternalDocument) ActorID() *time.ActorID

ActorID returns ID of the actor currently editing the document.

func (*InternalDocument) ApplyChangePack

func (d *InternalDocument) ApplyChangePack(pack *change.Pack) error

ApplyChangePack applies the given change pack into this document.

func (*InternalDocument) ApplyChanges added in v0.2.3

func (d *InternalDocument) ApplyChanges(changes ...*change.Change) error

ApplyChanges applies remote changes to the document.

func (*InternalDocument) Checkpoint

func (d *InternalDocument) Checkpoint() change.Checkpoint

Checkpoint returns the checkpoint of this document.

func (*InternalDocument) CreateChangePack

func (d *InternalDocument) CreateChangePack() *change.Pack

CreateChangePack creates pack of the local changes to send to the server.

func (*InternalDocument) GarbageCollect

func (d *InternalDocument) GarbageCollect(ticket *time.Ticket) int

GarbageCollect purge elements that were removed before the given time.

func (*InternalDocument) GarbageLen

func (d *InternalDocument) GarbageLen() int

GarbageLen returns the count of removed elements.

func (*InternalDocument) HasLocalChanges

func (d *InternalDocument) HasLocalChanges() bool

HasLocalChanges returns whether this document has local changes or not.

func (*InternalDocument) IsAttached

func (d *InternalDocument) IsAttached() bool

IsAttached returns the whether this document is attached or not.

func (*InternalDocument) Key

func (d *InternalDocument) Key() key.Key

Key returns the key of this document.

func (*InternalDocument) Lamport added in v0.2.4

func (d *InternalDocument) Lamport() int64

Lamport returns the Lamport clock of this document.

func (*InternalDocument) Marshal

func (d *InternalDocument) Marshal() string

Marshal returns the JSON encoding of this document.

func (*InternalDocument) Root added in v0.2.1

func (d *InternalDocument) Root() *crdt.Root

Root returns the root of this document.

func (*InternalDocument) RootObject

func (d *InternalDocument) RootObject() *crdt.Object

RootObject returns the root object.

func (*InternalDocument) SetActor

func (d *InternalDocument) SetActor(actor *time.ActorID)

SetActor sets actor into this document. This is also applied in the local changes the document has.

func (*InternalDocument) SetStatus added in v0.1.1

func (d *InternalDocument) SetStatus(status StatusType)

SetStatus sets the status of this document.

type StatusType added in v0.3.3

type StatusType int

StatusType represents the status of the document.

const (
	// StatusDetached means that the document is not attached to the client.
	// The actor of the ticket is created without being assigned.
	StatusDetached StatusType = iota

	// StatusAttached means that this document is attached to the client.
	// The actor of the ticket is created with being assigned by the client.
	StatusAttached

	// StatusRemoved means that this document is removed. If the document is removed,
	// it cannot be edited.
	StatusRemoved
)

Directories

Path Synopsis
Package change provides the implementation of Change.
Package change provides the implementation of Change.
Package crdt provides the implementation of the CRDT data structure.
Package crdt provides the implementation of the CRDT data structure.
Package json provides the JSON document implementation.
Package json provides the JSON document implementation.
Package key provides the key implementation of the document.
Package key provides the key implementation of the document.
Package operations implements the operations that can be executed on the document.
Package operations implements the operations that can be executed on the document.
Package time provides logical clock and ticket for document.
Package time provides logical clock and ticket for document.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL