types

package
v0.2.15 Latest Latest
Warning

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

Go to latest
Published: Aug 8, 2022 License: Apache-2.0 Imports: 14 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidWebhookRequest is returned when the given webhook request is not valid.
	ErrInvalidWebhookRequest = errors.New("invalid authorization webhook request")

	// ErrInvalidWebhookResponse is returned when the given webhook response is not valid.
	ErrInvalidWebhookResponse = errors.New("invalid authorization webhook response")
)
View Source
var ErrEmptyProjectFields = errors.New("updatable project fields are empty")

ErrEmptyProjectFields is returned when all the fields are empty.

View Source
var (
	// ErrInvalidID is returned when the given ID is not ObjectID.
	ErrInvalidID = errors.New("invalid ID")
)

Functions

func GetChangesRange added in v0.2.11

func GetChangesRange(
	paging Paging[int64],
	lastSeq int64,
) (int64, int64)

GetChangesRange returns a range of changes.

func IsAuthMethod

func IsAuthMethod(method string) bool

IsAuthMethod returns whether the given method can be used for authorization.

Types

type AccessAttribute

type AccessAttribute struct {
	Key  string   `json:"key"`
	Verb VerbType `json:"verb"`
}

AccessAttribute represents an access attribute.

type AccessInfo

type AccessInfo struct {
	Method     Method
	Attributes []AccessAttribute
}

AccessInfo represents an access information.

type AuthWebhookRequest

type AuthWebhookRequest struct {
	Token      string            `json:"token"`
	Method     Method            `json:"method"`
	Attributes []AccessAttribute `json:"attributes"`
}

AuthWebhookRequest represents the request of authentication webhook.

func NewAuthWebhookRequest

func NewAuthWebhookRequest(reader io.Reader) (*AuthWebhookRequest, error)

NewAuthWebhookRequest creates a new instance of AuthWebhookRequest.

type AuthWebhookResponse

type AuthWebhookResponse struct {
	Allowed bool   `json:"allowed"`
	Reason  string `json:"reason"`
}

AuthWebhookResponse represents the response of authentication webhook.

func NewAuthWebhookResponse

func NewAuthWebhookResponse(reader io.Reader) (*AuthWebhookResponse, error)

NewAuthWebhookResponse creates a new instance of AuthWebhookResponse.

func (*AuthWebhookResponse) Write

func (r *AuthWebhookResponse) Write(writer io.Writer) (int, error)

Write writes this response to the given writer.

type ChangeSummary

type ChangeSummary struct {
	// ID is the unique identifier of the change.
	ID change.ID

	// Message is the message of the change.
	Message string

	// Snapshot is the snapshot of the document.
	Snapshot string
}

ChangeSummary represents a summary of change.

type Client

type Client struct {
	ID           *time.ActorID
	PresenceInfo PresenceInfo
}

Client represents the Client that communicates with the Server.

func NewClient

func NewClient(encoded []byte) (*Client, error)

NewClient creates a new Client from the given JSON.

func (*Client) Marshal

func (c *Client) Marshal() (string, error)

Marshal serializes the Client to JSON.

type DocEventType

type DocEventType string

DocEventType represents the event that the Server delivers to the client.

const (
	// DocumentsChangedEvent is an event indicating that documents are being
	// modified by a change.
	DocumentsChangedEvent DocEventType = "documents-changed"

	// DocumentsWatchedEvent is an event that occurs when documents are watched
	// by other clients.
	DocumentsWatchedEvent DocEventType = "documents-watched"

	// DocumentsUnwatchedEvent is an event that occurs when documents are
	// unwatched by other clients.
	DocumentsUnwatchedEvent DocEventType = "documents-unwatched"

	// PresenceChangedEvent is an event indicating that presence is changed.
	PresenceChangedEvent DocEventType = "presence-changed"
)

type DocumentSummary

type DocumentSummary struct {
	// ID is the unique identifier of the document.
	ID ID

	// Key is the key of the document.
	Key key.Key

	// CreatedAt is the time when the document is created.
	CreatedAt time.Time

	// AccessedAt is the time when the document is accessed.
	AccessedAt time.Time

	// UpdatedAt is the time when the document is updated.
	UpdatedAt time.Time

	// Snapshot is the string representation of the document.
	Snapshot string
}

DocumentSummary represents a summary of document.

type FieldViolation added in v0.2.11

type FieldViolation struct {
	// A Field of which field of the reques is bad.
	Field string
	// A description of why the request element is bad.
	Description string
}

FieldViolation is used to describe a single bad request field

type ID

type ID string

ID represents ID of entity.

func IDFromActorID

func IDFromActorID(actorID *time.ActorID) ID

IDFromActorID returns ID represented by the encoded hexadecimal string from actor ID.

func IDFromBytes

func IDFromBytes(bytes []byte) ID

IDFromBytes returns ID represented by the encoded hexadecimal string from bytes.

func (*ID) Bytes

func (id *ID) Bytes() ([]byte, error)

Bytes returns bytes of decoded hexadecimal string representation of this ID.

func (*ID) String

func (id *ID) String() string

String returns a string representation of this ID.

func (*ID) ToActorID

func (id *ID) ToActorID() (*time.ActorID, error)

ToActorID returns ActorID from this ID.

func (*ID) Validate

func (id *ID) Validate() error

Validate returns error if this ID is invalid.

type InvalidFieldsError added in v0.2.11

type InvalidFieldsError struct {
	Violations []*FieldViolation
}

InvalidFieldsError is used to describe invalid fields.

func (*InvalidFieldsError) Error added in v0.2.11

func (e *InvalidFieldsError) Error() string

Error returns the error message.

type Method

type Method string

Method represents a method name of RPC.

const (
	ActivateClient   Method = "ActivateClient"
	DeactivateClient Method = "DeactivateClient"
	AttachDocument   Method = "AttachDocument"
	DetachDocument   Method = "DetachDocument"
	PushPull         Method = "PushPull"
	WatchDocuments   Method = "WatchDocuments"
)

Belows are the names of RPCs.

func AuthMethods

func AuthMethods() []Method

AuthMethods returns a slice of methods that can be used for authorization.

type Paging

type Paging[T any] struct {
	Offset    T
	PageSize  int
	IsForward bool
}

Paging is the paging information for the document.

type Presence

type Presence map[string]string

Presence represents custom presence that can be defined in the client.

type PresenceInfo

type PresenceInfo struct {
	Clock    int32
	Presence Presence
}

PresenceInfo is a presence information with logical clock.

func (*PresenceInfo) Update

func (i *PresenceInfo) Update(info PresenceInfo) bool

Update updates the given presence information with the given clock.

type Project

type Project struct {
	// ID is the unique ID of the project.
	ID ID `json:"id"`

	// Name is the name of this project.
	Name string `json:"name"`

	// AuthWebhookURL is the url of the authorization webhook.
	AuthWebhookURL string `json:"auth_webhook_url"`

	// AuthWebhookMethods is the methods that run the authorization webhook.
	AuthWebhookMethods []string `json:"auth_webhook_methods"`

	// PublicKey is the API key of this project.
	PublicKey string `json:"public_key"`

	// SecretKey is the secret key of this project.
	SecretKey string `json:"secret_key"`

	// CreatedAt is the time when the project was created.
	CreatedAt time.Time `json:"created_at"`

	// UpdatedAt is the time when the project was updated.
	UpdatedAt time.Time `json:"updated_at"`
}

Project is a project that consists of multiple documents and clients. It allows developers to work on the same cluster.

func (*Project) RequireAuth

func (p *Project) RequireAuth(method Method) bool

RequireAuth returns whether the given method requires authorization.

type SearchResult added in v0.2.13

type SearchResult[T any] struct {
	// TotalCount is the total count of the elements.
	TotalCount int

	// Elements is a list of elements.
	Elements []T
}

SearchResult is a result of search.

type UpdatableProjectFields added in v0.2.8

type UpdatableProjectFields struct {
	// Name is the name of this project.
	Name *string `bson:"name,omitempty" validate:"omitempty,min=2,max=30,slug,reservedname"`

	// AuthWebhookURL is the url of the authorization webhook.
	AuthWebhookURL *string `bson:"auth_webhook_url,omitempty"`

	// AuthWebhookMethods is the methods that run the authorization webhook.
	AuthWebhookMethods *[]string `bson:"auth_webhook_methods,omitempty" validate:"omitempty,invalidmethod"`
}

UpdatableProjectFields is a set of fields that use to update a project.

func (*UpdatableProjectFields) Validate added in v0.2.8

func (i *UpdatableProjectFields) Validate() error

Validate validates the UpdatableProjectFields.

type User added in v0.2.14

type User struct {
	// ID is the unique ID of the user.
	ID ID `json:"id"`

	// Username is the username of the user.
	Username string `json:"username"`

	// CreatedAt is the time when the user was created.
	CreatedAt time.Time `json:"created_at"`
}

User is a user that can access the project.

type VerbType

type VerbType string

VerbType represents an action taken on the document.

const (

	// Read represents the case of only reading the given document.
	Read VerbType = "r"

	// ReadWrite represents the case of reading and writing the given document.
	ReadWrite VerbType = "rw"
)

Jump to

Keyboard shortcuts

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