client

package
v0.19.0 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2026 License: MIT Imports: 14 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package client is the typed Go client of the motte store and control planes.

Index

Constants

View Source
const DefaultBudget = 2 * time.Second

DefaultBudget is the time limit of one call unless WithBudget sets another.

View Source
const DefaultLandBudget = 35 * time.Second

DefaultLandBudget is the time limit of a Land call unless WithBudget sets another. It is above the 30 seconds that the server waits for a land.

View Source
const FromLatest = "latest"

FromLatest is the cursor of Events that starts after the newest event and returns none.

Variables

View Source
var (
	ErrNotFound           = errors.New("motte: not found")
	ErrPathNotFound       = errors.New("motte: path not found")
	ErrGenerationConflict = errors.New("motte: generation conflict")
	ErrClaimLost          = errors.New("motte: claim lost")
	ErrObjectInvalid      = errors.New("motte: object invalid")
	ErrObjectTooLarge     = errors.New("motte: object too large")
	ErrRepoForbidden      = errors.New("motte: repository forbidden")
	ErrWorkspaceConflict  = errors.New("motte: workspace conflict")
	ErrWorkspaceDeleted   = errors.New("motte: workspace deleted")
	ErrRefProtected       = errors.New("motte: ref protected")
	ErrEventsPruned       = errors.New("motte: events pruned")
	ErrLandConflict       = errors.New("motte: land conflict")
	ErrLandStale          = errors.New("motte: land stale")
	ErrLandInvalid        = errors.New("motte: land invalid")
	ErrLandTimeout        = errors.New("motte: land timeout")
	ErrLandPending        = errors.New("motte: land pending")
	ErrLandAcknowledged   = errors.New("motte: land acknowledged")
	ErrUnauthorized       = errors.New("motte: unauthorized")
	ErrInvalidBody        = errors.New("motte: invalid body")
	ErrInternal           = errors.New("motte: internal error")
	// ErrRedirect is the error of a 3xx answer. The client follows no redirect, so a grant never leaves the base URL.
	ErrRedirect = errors.New("motte: unexpected redirect")
	// ErrUnexpected is the error of a failure answer that carries no wire error body.
	ErrUnexpected = errors.New("motte: unexpected response")
)

Functions

func ConflictPaths added in v0.6.0

func ConflictPaths(err error) []string

ConflictPaths returns the paths that a land conflict names.

func CurrentRef

func CurrentRef(err error) (api.Ref, bool)

CurrentRef returns the stored ref that a ref generation conflict carries.

func StaleTree added in v0.7.0

func StaleTree(err error) string

StaleTree returns the tree that a stale land would have made.

Types

type Client

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

Client calls one store. A grant has one scope, so a caller holds one Client for each scope it uses. A Client is safe for concurrent use.

func New

func New(baseURL string, grant GrantFunc, opts ...Option) *Client

New returns a client of the store at baseURL.

func (*Client) AckLand added in v0.19.0

func (c *Client) AckLand(ctx context.Context, repo, id string) error

AckLand drops the stored result of the land id, which the caller has saved. The server keeps a result until the caller acknowledges it or 30 days pass, and a repeat of the id answers the result meanwhile. After the acknowledgment a repeat of the id is ErrLandAcknowledged and never lands again. A land that has no result yet is ErrLandPending, and an unknown id is ErrNotFound.

func (*Client) Blobs

func (c *Client) Blobs(ctx context.Context, shas []string) ([][]byte, error)

Blobs returns the contents of the blobs, in the order of shas.

func (*Client) Claim

func (c *Client) Claim(ctx context.Context, workspace string, req api.ClaimRequest) (api.ClaimResponse, error)

Claim binds or raises the epoch of a workspace and returns its stored state.

func (*Client) Commit

func (c *Client) Commit(ctx context.Context, sha string) (api.Commit, error)

Commit returns the root tree and time of a commit.

func (*Client) CreateRepo

func (c *Client) CreateRepo(ctx context.Context, name, owner string) (string, error)

CreateRepo creates a repository with a root commit under main and returns its path.

func (*Client) CreateRepoWithID added in v0.19.0

func (c *Client) CreateRepoWithID(ctx context.Context, id, name, owner string) (string, error)

CreateRepoWithID is CreateRepo with an idempotency key. A repeat of id with the same name and owner returns the first path, and a repeat with another name or owner is ErrInvalidBody.

func (*Client) CreateSubscription added in v0.6.0

func (c *Client) CreateSubscription(ctx context.Context, req api.CreateSubscriptionRequest) (api.Subscription, error)

CreateSubscription registers a receiver of ref events. Its cursor starts at the newest event.

func (*Client) CreateUserToken added in v0.9.0

CreateUserToken issues a per-user token. The text of the token is in the response and nowhere else.

func (*Client) DeleteRef

func (c *Client) DeleteRef(ctx context.Context, name string, expect int64) error

DeleteRef deletes the ref when its stored generation is expect.

func (*Client) DeleteSubscription added in v0.6.0

func (c *Client) DeleteSubscription(ctx context.Context, id string) error

DeleteSubscription removes a receiver. An unknown id is ErrNotFound.

func (*Client) DeleteWorkspace

func (c *Client) DeleteWorkspace(ctx context.Context, workspace string) error

DeleteWorkspace deletes a workspace. It is idempotent.

func (*Client) Events added in v0.6.0

func (c *Client) Events(ctx context.Context, cursor string, limit int) ([]api.Event, string, error)

Events returns up to limit ref events after cursor, and the cursor to pass next. An empty cursor starts at the first event, and FromLatest starts after the newest event and returns none. Zero limit takes the server default. Events of one ref arrive in order. ErrEventsPruned means retention removed events after the cursor, and the caller must read the refs again.

func (*Client) File added in v0.19.0

func (c *Client) File(ctx context.Context, repo, commit, path string) ([]byte, error)

File returns the content of the file at path in the commit. repo is the repository text of the grant, and the grant has the read scope. A path that names no file is ErrPathNotFound, and a file over the server limit of 1 MiB is ErrObjectTooLarge.

func (*Client) Flush

func (c *Client) Flush(ctx context.Context, workspace string, req api.FlushRequest) error

Flush stores the state of a workspace under its claim epoch.

func (*Client) Has

func (c *Client) Has(ctx context.Context, shas []string) ([]bool, error)

Has reports for each sha whether the repository holds it.

func (*Client) ImportPack

func (c *Client) ImportPack(ctx context.Context, packID string, index, pack []byte) error

ImportPack stores a pack and its v2 index. packID is the lowercase hex SHA-256 of pack.

func (*Client) Land added in v0.6.0

func (c *Client) Land(ctx context.Context, repo string, req api.LandRequest) (api.LandResponse, error)

Land lands the commits base..head of req on the ref of req. repo is the repository text of the grant, and the grant has the merge scope, or the write scope for an unprotected ref. The call waits for the result, at most DefaultLandBudget unless WithBudget sets another. A conflict is ErrLandConflict and ConflictPaths returns its paths. A land whose tree is not req.ExpectTree is ErrLandStale and StaleTree returns the tree that it would have made. An invalid range is ErrLandInvalid, a land that the server did not end in time is ErrLandTimeout, and a repeat of the same ID then returns the result once it exists.

func (*Client) LandTrial added in v0.19.0

func (c *Client) LandTrial(ctx context.Context, repo string, req api.TrialRequest) (api.TrialResponse, error)

LandTrial lands the changes of req one after the other on req.Tip without moving any ref, and returns one item for each change. It writes the objects that the lands make. repo is the repository text of the grant, and the grant has the merge or the write scope.

func (*Client) Object

func (c *Client) Object(ctx context.Context, sha string) (Object, error)

Object returns the type and content of one object.

func (*Client) Op

func (c *Client) Op(ctx context.Context, kind, id string) ([]byte, error)

Op returns one op-log object of the workspace.

func (*Client) OpHeads

func (c *Client) OpHeads(ctx context.Context) (api.OpHeads, error)

OpHeads returns the head set of the op log of the workspace.

func (*Client) ProtectedRefs added in v0.6.0

func (c *Client) ProtectedRefs(ctx context.Context, repo string) ([]string, error)

ProtectedRefs returns the protected ref patterns of repo, the repository text.

func (*Client) PutObjects

func (c *Client) PutObjects(ctx context.Context, objs []Object) ([]string, error)

PutObjects stores the objects and returns their names.

func (*Client) PutOp

func (c *Client) PutOp(ctx context.Context, kind, id string, data []byte) error

PutOp stores one op-log object of the workspace. kind is the op kind of the store.

func (*Client) PutSubscription added in v0.19.0

func (c *Client) PutSubscription(ctx context.Context, name string, req api.PutSubscriptionRequest) (api.Subscription, error)

PutSubscription creates the subscription name, or replaces its receiver and keeps its cursors.

func (*Client) Ref

func (c *Client) Ref(ctx context.Context, name string) (api.Ref, error)

Ref returns one ref.

func (*Client) Refs

func (c *Client) Refs(ctx context.Context) ([]api.Ref, error)

Refs lists the refs of the repository.

func (*Client) Repo

func (c *Client) Repo(ctx context.Context, path string) (api.Repo, error)

Repo returns one repository.

func (*Client) Repos

func (c *Client) Repos(ctx context.Context) ([]api.Repo, error)

Repos lists the repositories, newest first.

func (*Client) RevokeUserToken added in v0.9.0

func (c *Client) RevokeUserToken(ctx context.Context, id string) error

RevokeUserToken revokes the token with id.

func (*Client) SetProtectedRefs added in v0.6.0

func (c *Client) SetProtectedRefs(ctx context.Context, repo string, patterns []string) error

SetProtectedRefs replaces the protected ref patterns of repo, the repository text. A pattern is a ref name, or a prefix that ends in "*". An empty list protects nothing.

func (*Client) SetWorkspace

func (c *Client) SetWorkspace(ctx context.Context, op, commit string, generation int64) error

SetWorkspace reports the op and commit of the workspace. generation is that of the op-heads swap of op.

func (*Client) Subscriptions added in v0.6.0

func (c *Client) Subscriptions(ctx context.Context) ([]api.Subscription, error)

Subscriptions lists the registered receivers.

func (*Client) SwapOpHeads

func (c *Client) SwapOpHeads(ctx context.Context, expectGeneration int64, heads []string) (api.OpHeads, error)

SwapOpHeads replaces the head set when the stored generation is expectGeneration. Use 0 for the first write.

func (*Client) SwapRef

func (c *Client) SwapRef(ctx context.Context, name string, expect int64, commit string) (api.Ref, error)

SwapRef points the ref at commit when its stored generation is expect. Use 0 to create the ref. A conflict is ErrGenerationConflict, and CurrentRef returns the stored ref. A client with a merge grant writes any ref of its repository with no workspace. A client with a node grant gets ErrRefProtected for a protected ref.

func (*Client) Trees

func (c *Client) Trees(ctx context.Context, sha string, maxEntries int) (api.Trees, error)

Trees returns the tree sha and the trees under it, at most maxEntries entries in all. Zero takes the server default.

func (*Client) UserTokens added in v0.9.0

func (c *Client) UserTokens(ctx context.Context) ([]api.UserToken, error)

UserTokens lists the per-user tokens, newest first.

type Error

type Error struct {
	Status  int
	Code    api.Code
	Message string
	Details map[string]any
	// contains filtered or unexported fields
}

Error is a failure answer of the store. errors.Is matches the sentinel of its code.

func (*Error) Error

func (e *Error) Error() string

func (*Error) Unwrap

func (e *Error) Unwrap() error

type GrantFunc

type GrantFunc func(ctx context.Context) (string, error)

GrantFunc returns the bearer grant of one call. The client calls it before each request.

func StaticGrant

func StaticGrant(token string) GrantFunc

StaticGrant returns a GrantFunc that always answers token.

type Object

type Object struct {
	Type string
	Data []byte
}

Object is one git object. Type is commit, tree, blob or tag.

type Option

type Option func(*Client)

func WithBudget

func WithBudget(d time.Duration) Option

WithBudget sets the time limit of one call. Zero or less removes the limit; a deadline on the call context still applies.

func WithHTTPClient

func WithHTTPClient(h *http.Client) Option

WithHTTPClient sets the transport. The client still follows no redirect.

Jump to

Keyboard shortcuts

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