Documentation ¶
Overview ¶
Package document provides JSON-like document(CRDT) implementation.
Index ¶
- Variables
- type BroadcastRequest
- type DocEvent
- type DocEventType
- type Document
- func (d *Document) ActorID() *time.ActorID
- func (d *Document) AddOnlineClient(clientID string)
- func (d *Document) AllPresences() map[string]innerpresence.Presence
- func (d *Document) ApplyChangePack(pack *change.Pack) error
- func (d *Document) Broadcast(topic string, payload any) error
- func (d *Document) BroadcastEventHandlers() map[string]func(topic string, publisher string, payload []byte) error
- func (d *Document) BroadcastRequests() <-chan BroadcastRequest
- func (d *Document) BroadcastResponses() chan error
- func (d *Document) Checkpoint() change.Checkpoint
- func (d *Document) CreateChangePack() *change.Pack
- func (d *Document) Events() <-chan DocEvent
- func (d *Document) GarbageCollect(vector time.VersionVector) int
- func (d *Document) GarbageLen() int
- func (d *Document) HasLocalChanges() bool
- func (d *Document) InternalDocument() *InternalDocument
- func (d *Document) IsAttached() bool
- func (d *Document) Key() key.Key
- func (d *Document) Marshal() string
- func (d *Document) MyPresence() innerpresence.Presence
- func (d *Document) Presence(clientID string) innerpresence.Presence
- func (d *Document) PresenceForTest(clientID string) innerpresence.Presence
- func (d *Document) Presences() map[string]innerpresence.Presence
- func (d *Document) RemoveOnlineClient(clientID string)
- func (d *Document) Root() *json.Object
- func (d *Document) RootObject() *crdt.Object
- func (d *Document) SetActor(actor *time.ActorID)
- func (d *Document) SetOnlineClients(clientIDs ...string)
- func (d *Document) SetStatus(status StatusType)
- func (d *Document) Status() StatusType
- func (d *Document) SubscribeBroadcastEvent(topic string, handler func(topic, publisher string, payload []byte) error)
- func (d *Document) UnsubscribeBroadcastEvent(topic string)
- func (d *Document) Update(updater func(root *json.Object, p *presence.Presence) error, ...) error
- func (d *Document) VersionVector() time.VersionVector
- type InternalDocument
- func (d *InternalDocument) ActorID() *time.ActorID
- func (d *InternalDocument) AddOnlineClient(clientID string)
- func (d *InternalDocument) AllPresences() map[string]innerpresence.Presence
- func (d *InternalDocument) ApplyChangePack(pack *change.Pack, disableGC bool) error
- func (d *InternalDocument) ApplyChanges(changes ...*change.Change) ([]DocEvent, error)
- func (d *InternalDocument) Checkpoint() change.Checkpoint
- func (d *InternalDocument) CreateChangePack() *change.Pack
- func (d *InternalDocument) GarbageCollect(vector time.VersionVector) (int, error)
- func (d *InternalDocument) GarbageLen() int
- func (d *InternalDocument) HasLocalChanges() bool
- func (d *InternalDocument) IsAttached() bool
- func (d *InternalDocument) Key() key.Key
- func (d *InternalDocument) Lamport() int64
- func (d *InternalDocument) Marshal() string
- func (d *InternalDocument) MyPresence() innerpresence.Presence
- func (d *InternalDocument) Presence(clientID string) innerpresence.Presence
- func (d *InternalDocument) PresenceForTest(clientID string) innerpresence.Presence
- func (d *InternalDocument) Presences() map[string]innerpresence.Presence
- func (d *InternalDocument) RemoveOnlineClient(clientID string)
- func (d *InternalDocument) Root() *crdt.Root
- func (d *InternalDocument) RootObject() *crdt.Object
- func (d *InternalDocument) SetActor(actor *time.ActorID)
- func (d *InternalDocument) SetOnlineClients(ids ...string)
- func (d *InternalDocument) SetStatus(status StatusType)
- func (d *InternalDocument) SyncCheckpoint(serverSeq int64, clientSeq uint32)
- func (d *InternalDocument) ToDocument() *Document
- func (d *InternalDocument) VersionVector() time.VersionVector
- type Option
- type Options
- type StatusType
Constants ¶
This section is empty.
Variables ¶
var ( // ErrDocumentRemoved occurs when the document is removed. ErrDocumentRemoved = errors.New("document is removed") )
var ( // ErrUnsupportedPayloadType is returned when the payload is unserializable to JSON. ErrUnsupportedPayloadType = errors.New("unsupported payload type") )
Functions ¶
This section is empty.
Types ¶
type BroadcastRequest ¶ added in v0.4.7
BroadcastRequest represents a broadcast request that will be delivered to the client.
type DocEvent ¶ added in v0.4.5
type DocEvent struct { Type DocEventType Presences map[string]innerpresence.Presence }
DocEvent represents the event that occurred in the document.
type DocEventType ¶ added in v0.4.5
type DocEventType string
DocEventType represents the type of the event that occurred in the document.
const ( // WatchedEvent means that the client has established a connection with the server, // enabling real-time synchronization. WatchedEvent DocEventType = "watched" // UnwatchedEvent means that the client has disconnected from the server, // disabling real-time synchronization. UnwatchedEvent DocEventType = "unwatched" // PresenceChangedEvent means that the presences of the clients who are editing // the document have changed. PresenceChangedEvent DocEventType = "presence-changed" )
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 (*Document) ActorID ¶ added in v0.2.2
ActorID returns ID of the actor currently editing the document.
func (*Document) AddOnlineClient ¶ added in v0.4.5
AddOnlineClient adds the given client to the online clients.
func (*Document) AllPresences ¶ added in v0.4.6
func (d *Document) AllPresences() map[string]innerpresence.Presence
AllPresences returns the presence map of all clients regardless of whether the client is online or not.
func (*Document) ApplyChangePack ¶
ApplyChangePack applies the given change pack into this document.
func (*Document) Broadcast ¶ added in v0.4.7
Broadcast encodes the given payload and sends a Broadcast request.
func (*Document) BroadcastEventHandlers ¶ added in v0.4.7
func (d *Document) BroadcastEventHandlers() map[string]func( topic string, publisher string, payload []byte, ) error
BroadcastEventHandlers returns the registered handlers for broadcast events.
func (*Document) BroadcastRequests ¶ added in v0.4.7
func (d *Document) BroadcastRequests() <-chan BroadcastRequest
BroadcastRequests returns the broadcast requests of this document.
func (*Document) BroadcastResponses ¶ added in v0.4.7
BroadcastResponses returns the broadcast responses of this document.
func (*Document) Checkpoint ¶
func (d *Document) Checkpoint() change.Checkpoint
Checkpoint returns the checkpoint of this document.
func (*Document) CreateChangePack ¶
CreateChangePack creates pack of the local changes to send to the server.
func (*Document) GarbageCollect ¶
func (d *Document) GarbageCollect(vector time.VersionVector) int
GarbageCollect purge elements that were removed before the given time.
func (*Document) GarbageLen ¶
GarbageLen returns the count of removed elements.
func (*Document) HasLocalChanges ¶
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 ¶
IsAttached returns whether this document is attached or not.
func (*Document) MyPresence ¶ added in v0.4.5
func (d *Document) MyPresence() innerpresence.Presence
MyPresence returns the presence of the actor.
func (*Document) Presence ¶ added in v0.4.5
func (d *Document) Presence(clientID string) innerpresence.Presence
Presence returns the presence of the given client. If the client is not online, it returns nil.
func (*Document) PresenceForTest ¶ added in v0.4.6
func (d *Document) PresenceForTest(clientID string) innerpresence.Presence
PresenceForTest returns the presence of the given client regardless of whether the client is online or not.
func (*Document) Presences ¶ added in v0.4.5
func (d *Document) Presences() map[string]innerpresence.Presence
Presences returns the presence map of online clients.
func (*Document) RemoveOnlineClient ¶ added in v0.4.5
RemoveOnlineClient removes the given client from the online clients.
func (*Document) RootObject ¶
RootObject returns the internal root object of this document.
func (*Document) SetActor ¶
SetActor sets actor into this document. This is also applied in the local changes the document has.
func (*Document) SetOnlineClients ¶ added in v0.4.6
SetOnlineClients sets the online clients.
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) SubscribeBroadcastEvent ¶ added in v0.4.7
func (d *Document) SubscribeBroadcastEvent( topic string, handler func(topic, publisher string, payload []byte) error, )
SubscribeBroadcastEvent subscribes to the given topic and registers an event handler.
func (*Document) UnsubscribeBroadcastEvent ¶ added in v0.4.7
UnsubscribeBroadcastEvent unsubscribes to the given topic and deregisters the event handler.
func (*Document) Update ¶
func (d *Document) Update( updater func(root *json.Object, p *presence.Presence) error, msgAndArgs ...interface{}, ) error
Update executes the given updater to update this document.
func (*Document) VersionVector ¶ added in v0.5.3
func (d *Document) VersionVector() time.VersionVector
VersionVector returns the version vector of this document.
type InternalDocument ¶
type InternalDocument struct {
// contains filtered or unexported fields
}
InternalDocument is a document that is used internally. It is not directly exposed to the user.
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, vector time.VersionVector, 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) AddOnlineClient ¶ added in v0.4.5
func (d *InternalDocument) AddOnlineClient(clientID string)
AddOnlineClient adds the given client to the online clients.
func (*InternalDocument) AllPresences ¶ added in v0.4.6
func (d *InternalDocument) AllPresences() map[string]innerpresence.Presence
AllPresences returns the presence map of all clients regardless of whether the client is online or not.
func (*InternalDocument) ApplyChangePack ¶
func (d *InternalDocument) ApplyChangePack(pack *change.Pack, disableGC bool) 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) ([]DocEvent, 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(vector time.VersionVector) (int, error)
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 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) MyPresence ¶ added in v0.4.5
func (d *InternalDocument) MyPresence() innerpresence.Presence
MyPresence returns the presence of the actor currently editing the document.
func (*InternalDocument) Presence ¶ added in v0.4.5
func (d *InternalDocument) Presence(clientID string) innerpresence.Presence
Presence returns the presence of the given client. If the client is not online, it returns nil.
func (*InternalDocument) PresenceForTest ¶ added in v0.4.6
func (d *InternalDocument) PresenceForTest(clientID string) innerpresence.Presence
PresenceForTest returns the presence of the given client regardless of whether the client is online or not.
func (*InternalDocument) Presences ¶ added in v0.4.5
func (d *InternalDocument) Presences() map[string]innerpresence.Presence
Presences returns the presence map of online clients.
func (*InternalDocument) RemoveOnlineClient ¶ added in v0.4.5
func (d *InternalDocument) RemoveOnlineClient(clientID string)
RemoveOnlineClient removes the given client from the online clients.
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) SetOnlineClients ¶ added in v0.4.6
func (d *InternalDocument) SetOnlineClients(ids ...string)
SetOnlineClients sets the online clients.
func (*InternalDocument) SetStatus ¶ added in v0.1.1
func (d *InternalDocument) SetStatus(status StatusType)
SetStatus sets the status of this document.
func (*InternalDocument) SyncCheckpoint ¶ added in v0.5.2
func (d *InternalDocument) SyncCheckpoint(serverSeq int64, clientSeq uint32)
SyncCheckpoint syncs the checkpoint and the changeID with the given serverSeq and clientSeq.
func (*InternalDocument) ToDocument ¶ added in v0.5.2
func (d *InternalDocument) ToDocument() *Document
ToDocument converts this document to Document.
func (*InternalDocument) VersionVector ¶ added in v0.5.3
func (d *InternalDocument) VersionVector() time.VersionVector
VersionVector returns the version vector of this document.
type Option ¶ added in v0.4.20
type Option func(*Options)
Option configures Options.
func WithDisableGC ¶ added in v0.4.20
func WithDisableGC() Option
WithDisableGC configures the document to disable garbage collection.
type Options ¶ added in v0.4.20
type Options struct { // DisableGC disables garbage collection. // NOTE(hackerwins): This is temporary option. We need to remove this option // after introducing the garbage collection based on the version vector. DisableGC bool }
Options configures how we set up the 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 innerpresence provides the implementation of Presence.
|
Package innerpresence provides the implementation of Presence. |
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 presence provides the proxy for the innerpresence.Presence to be manipulated from the outside.
|
Package presence provides the proxy for the innerpresence.Presence to be manipulated from the outside. |
Package time provides logical clock and ticket for document.
|
Package time provides logical clock and ticket for document. |