Documentation ¶
Index ¶
- Constants
- Variables
- func EncodeOperations(operations []operations.Operation) ([][]byte, error)
- type ChangeInfo
- type ClientDocInfo
- type ClientInfo
- func (i *ClientInfo) AttachDocument(docID types.ID) error
- func (i ClientInfo) CheckIfInProject(projectID types.ID) error
- func (i *ClientInfo) Checkpoint(docID types.ID) change.Checkpoint
- func (i *ClientInfo) Deactivate()
- func (i *ClientInfo) DeepCopy() *ClientInfo
- func (i *ClientInfo) DetachDocument(docID types.ID) error
- func (i *ClientInfo) EnsureDocumentAttached(docID types.ID) error
- func (i *ClientInfo) IsAttached(docID types.ID) (bool, error)
- func (i *ClientInfo) UpdateCheckpoint(docID types.ID, cp change.Checkpoint) error
- type Database
- type DocInfo
- type ProjectInfo
- type SnapshotInfo
- type SyncedSeqInfo
Constants ¶
const ( ClientDeactivated = "deactivated" ClientActivated = "activated" )
Below are statuses of the client.
Variables ¶
var ( ErrClientNotActivated = errors.New("client not activated") ErrDocumentNotAttached = errors.New("document not attached") ErrDocumentNeverAttached = errors.New("client has never attached the document") ErrDocumentAlreadyAttached = errors.New("document already attached") )
Below are the errors may occur depending on the document and client status.
var ( // ErrProjectAlreadyExists is returned when the project already exists. ErrProjectAlreadyExists = errors.New("project already exists") // ErrProjectNotFound is returned when the project is not found. ErrProjectNotFound = errors.New("project not found") // ErrClientNotFound is returned when the client could not be found. ErrClientNotFound = errors.New("client not found") // ErrDocumentNotFound is returned when the document could not be found. ErrDocumentNotFound = errors.New("document not found") // ErrConflictOnUpdate is returned when a conflict occurs during update. ErrConflictOnUpdate = errors.New("conflict on update") // ErrProjectNameAlreadyExists is returned when the project name already exists. ErrProjectNameAlreadyExists = errors.New("project name already exists") )
var DefaultProjectID = types.ID("000000000000000000000000")
DefaultProjectID is the default project ID.
var DefaultProjectName = "default"
DefaultProjectName is the default project name.
var ErrEncodeOperationFailed = errors.New("encode operations failed")
ErrEncodeOperationFailed is returned when encoding operations failed.
Functions ¶
func EncodeOperations ¶
func EncodeOperations(operations []operations.Operation) ([][]byte, error)
EncodeOperations encodes the given operations into bytes array.
Types ¶
type ChangeInfo ¶
type ChangeInfo struct { ID types.ID `bson:"_id"` DocID types.ID `bson:"doc_id"` ServerSeq uint64 `bson:"server_seq"` ClientSeq uint32 `bson:"client_seq"` Lamport uint64 `bson:"lamport"` ActorID types.ID `bson:"actor_id"` Message string `bson:"message"` Operations [][]byte `bson:"operations"` }
ChangeInfo is a structure representing information of a change.
type ClientDocInfo ¶
type ClientDocInfo struct { Status string `bson:"status"` ServerSeq uint64 `bson:"server_seq"` ClientSeq uint32 `bson:"client_seq"` }
ClientDocInfo is a structure representing information of the document attached to the client.
type ClientInfo ¶
type ClientInfo struct { // ID is the unique ID of the client. ID types.ID `bson:"_id"` // ProjectID is the ID of the project the client belongs to. ProjectID types.ID `bson:"project_id"` // Key is the key of the client. It is used to identify the client by users. Key string `bson:"key"` // Status is the status of the client. Status string `bson:"status"` // Documents is a map of document which is attached to the client. Documents map[types.ID]*ClientDocInfo `bson:"documents"` // CreatedAt is the time when the client was created. CreatedAt time.Time `bson:"created_at"` // UpdatedAt is the last time the client was accessed. // NOTE(hackerwins): The field name is "updated_at" but it is used as // "accessed_at". UpdatedAt time.Time `bson:"updated_at"` }
ClientInfo is a structure representing information of a client.
func (*ClientInfo) AttachDocument ¶
func (i *ClientInfo) AttachDocument(docID types.ID) error
AttachDocument attaches the given document to this client.
func (ClientInfo) CheckIfInProject ¶
func (i ClientInfo) CheckIfInProject(projectID types.ID) error
CheckIfInProject checks if the client is in the project.
func (*ClientInfo) Checkpoint ¶
func (i *ClientInfo) Checkpoint(docID types.ID) change.Checkpoint
Checkpoint returns the checkpoint of the given document.
func (*ClientInfo) Deactivate ¶
func (i *ClientInfo) Deactivate()
Deactivate sets the status of this client to be deactivated.
func (*ClientInfo) DeepCopy ¶
func (i *ClientInfo) DeepCopy() *ClientInfo
DeepCopy returns a deep copy of this client info.
func (*ClientInfo) DetachDocument ¶
func (i *ClientInfo) DetachDocument(docID types.ID) error
DetachDocument detaches the given document from this client.
func (*ClientInfo) EnsureDocumentAttached ¶
func (i *ClientInfo) EnsureDocumentAttached(docID types.ID) error
EnsureDocumentAttached ensures the given document is attached.
func (*ClientInfo) IsAttached ¶
func (i *ClientInfo) IsAttached(docID types.ID) (bool, error)
IsAttached returns whether the given document is attached to this client.
func (*ClientInfo) UpdateCheckpoint ¶
func (i *ClientInfo) UpdateCheckpoint( docID types.ID, cp change.Checkpoint, ) error
UpdateCheckpoint updates the checkpoint of the given document.
type Database ¶
type Database interface { // Close all resources of this database. Close() error // FindProjectInfoByPublicKey returns a project by public key. FindProjectInfoByPublicKey(ctx context.Context, publicKey string) (*ProjectInfo, error) // FindProjectInfoByName returns a project by the given name. FindProjectInfoByName(ctx context.Context, name string) (*ProjectInfo, error) // FindProjectInfoByID returns a project by the given id. FindProjectInfoByID(ctx context.Context, id types.ID) (*ProjectInfo, error) // EnsureDefaultProjectInfo ensures that the default project exists. EnsureDefaultProjectInfo(ctx context.Context) (*ProjectInfo, error) // CreateProjectInfo creates a new project. CreateProjectInfo(ctx context.Context, name string) (*ProjectInfo, error) // ListProjectInfos returns all projects. ListProjectInfos(ctx context.Context) ([]*ProjectInfo, error) // UpdateProjectInfo updates the project. UpdateProjectInfo(ctx context.Context, id types.ID, fields *types.UpdatableProjectFields) (*ProjectInfo, error) // ActivateClient activates the client of the given key. ActivateClient(ctx context.Context, projectID types.ID, key string) (*ClientInfo, error) // DeactivateClient deactivates the client of the given ID. DeactivateClient(ctx context.Context, projectID, clientID types.ID) (*ClientInfo, error) // FindClientInfoByID finds the client of the given ID. FindClientInfoByID(ctx context.Context, projectID, clientID types.ID) (*ClientInfo, error) // UpdateClientInfoAfterPushPull updates the client from the given clientInfo // after handling PushPull. UpdateClientInfoAfterPushPull(ctx context.Context, clientInfo *ClientInfo, docInfo *DocInfo) error // FindDeactivateCandidates finds the housekeeping candidates. FindDeactivateCandidates( ctx context.Context, deactivateThreshold gotime.Duration, candidatesLimit int, ) ([]*ClientInfo, error) // FindDocInfoByKey finds the document of the given key. FindDocInfoByKey( ctx context.Context, projectID types.ID, docKey key.Key, ) (*DocInfo, error) // FindDocInfoByKeyAndOwner finds the document of the given key. If the // createDocIfNotExist condition is true, create the document if it does not // exist. FindDocInfoByKeyAndOwner( ctx context.Context, projectID types.ID, clientID types.ID, docKey key.Key, createDocIfNotExist bool, ) (*DocInfo, error) FindDocInfoByID( ctx context.Context, id types.ID, ) (*DocInfo, error) // CreateChangeInfos stores the given changes then updates the given docInfo. CreateChangeInfos( ctx context.Context, projectID types.ID, docInfo *DocInfo, initialServerSeq uint64, changes []*change.Change, ) error // FindChangesBetweenServerSeqs returns the changes between two server sequences. FindChangesBetweenServerSeqs( ctx context.Context, docID types.ID, from uint64, to uint64, ) ([]*change.Change, error) // FindChangeInfosBetweenServerSeqs returns the changeInfos between two server sequences. FindChangeInfosBetweenServerSeqs( ctx context.Context, docID types.ID, from uint64, to uint64, ) ([]*ChangeInfo, error) // CreateSnapshotInfo stores the snapshot of the given document. CreateSnapshotInfo(ctx context.Context, docID types.ID, doc *document.InternalDocument) error // FindClosestSnapshotInfo finds the closest snapshot info in a given serverSeq. FindClosestSnapshotInfo(ctx context.Context, docID types.ID, serverSeq uint64) (*SnapshotInfo, error) // UpdateAndFindMinSyncedTicket updates the given serverSeq of the given client // and returns the min synced ticket. UpdateAndFindMinSyncedTicket( ctx context.Context, clientInfo *ClientInfo, docID types.ID, serverSeq uint64, ) (*time.Ticket, error) // UpdateSyncedSeq updates the syncedSeq of the given client. UpdateSyncedSeq( ctx context.Context, clientInfo *ClientInfo, docID types.ID, serverSeq uint64, ) error // FindDocInfosByPaging returns the documentInfos of the given paging. FindDocInfosByPaging( ctx context.Context, projectID types.ID, paging types.Paging[types.ID], ) ([]*DocInfo, error) }
Database represents database which reads or saves Yorkie data.
type DocInfo ¶
type DocInfo struct { // ID is the unique ID of the document. ID types.ID `bson:"_id"` // ProjectID is the ID of the project that the document belongs to. ProjectID types.ID `bson:"project_id"` // Key is the key of the document. Key key.Key `bson:"key"` // ServerSeq is the sequence number of the last change of the document on the server. ServerSeq uint64 `bson:"server_seq"` // Owner is the owner(ID of the client) of the document. Owner types.ID `bson:"owner"` // CreatedAt is the time when the document is created. CreatedAt time.Time `bson:"created_at"` // AccessedAt is the time when the document is accessed. AccessedAt time.Time `bson:"accessed_at"` // UpdatedAt is the time when the document is updated. UpdatedAt time.Time `bson:"updated_at"` }
DocInfo is a structure representing information of the document.
func (*DocInfo) IncreaseServerSeq ¶
IncreaseServerSeq increases server sequence of the document.
type ProjectInfo ¶
type ProjectInfo struct { // ID is the unique ID of the project. ID types.ID `bson:"_id"` // Name is the name of this project. Name string `bson:"name"` // PublicKey is the API key of this project. PublicKey string `bson:"public_key"` // SecretKey is the secret key of this project. SecretKey string `bson:"secret_key"` // AuthWebhookURL is the url of the authorization webhook. AuthWebhookURL string `bson:"auth_webhook_url"` // AuthWebhookMethods is the methods that run the authorization webhook. AuthWebhookMethods []string `bson:"auth_webhook_methods"` // CreatedAt is the time when the project was created. CreatedAt time.Time `bson:"created_at"` // UpdatedAt is the time when the project was updated. UpdatedAt time.Time `bson:"updated_at"` }
ProjectInfo is a struct for project information.
func NewProjectInfo ¶
func NewProjectInfo(name string) *ProjectInfo
NewProjectInfo creates a new ProjectInfo of the given name.
func ToProjectInfo ¶
func ToProjectInfo(project *types.Project) *ProjectInfo
ToProjectInfo converts the given types.Project to ProjectInfo.
func (*ProjectInfo) DeepCopy ¶
func (i *ProjectInfo) DeepCopy() *ProjectInfo
DeepCopy returns a deep copy of the ProjectInfo.
func (*ProjectInfo) ToProject ¶
func (i *ProjectInfo) ToProject() *types.Project
ToProject converts the ProjectInfo to the Project.
func (*ProjectInfo) UpdateFields ¶ added in v0.2.8
func (i *ProjectInfo) UpdateFields(fields *types.UpdatableProjectFields)
UpdateFields updates the fields.
type SnapshotInfo ¶
type SnapshotInfo struct { // ID is the unique ID of the snapshot. ID types.ID `bson:"_id"` // DocID is the ID of the document which the snapshot belongs to. DocID types.ID `bson:"doc_id"` // ServerSeq is the sequence number of the server which the snapshot belongs to. ServerSeq uint64 `bson:"server_seq"` // Lamport is the Lamport timestamp of the snapshot. Lamport uint64 `bson:"lamport"` // Snapshot is the snapshot data. Snapshot []byte `bson:"snapshot"` // CreatedAt is the time when the snapshot is created. CreatedAt time.Time `bson:"created_at"` }
SnapshotInfo is a structure representing information of the snapshot.
type SyncedSeqInfo ¶
type SyncedSeqInfo struct { ID types.ID `bson:"_id"` DocID types.ID `bson:"doc_id"` ClientID types.ID `bson:"client_id"` Lamport uint64 `bson:"lamport"` ActorID types.ID `bson:"actor_id"` ServerSeq uint64 `bson:"server_seq"` }
SyncedSeqInfo is a structure representing information about the synchronized sequence for each client.