Documentation
¶
Overview ¶
Package client is the typed Go client of the motte store and control planes.
Index ¶
- Constants
- Variables
- func ConflictPaths(err error) []string
- func CurrentRef(err error) (api.Ref, bool)
- func StaleTree(err error) string
- type Client
- func (c *Client) Blobs(ctx context.Context, shas []string) ([][]byte, error)
- func (c *Client) Claim(ctx context.Context, workspace string, req api.ClaimRequest) (api.ClaimResponse, error)
- func (c *Client) Commit(ctx context.Context, sha string) (api.Commit, error)
- func (c *Client) CreateRepo(ctx context.Context, name, owner string) (string, error)
- func (c *Client) CreateSubscription(ctx context.Context, req api.CreateSubscriptionRequest) (api.Subscription, error)
- func (c *Client) CreateUserToken(ctx context.Context, req api.CreateUserTokenRequest) (api.CreateUserTokenResponse, error)
- func (c *Client) DeleteRef(ctx context.Context, name string, expect int64) error
- func (c *Client) DeleteSubscription(ctx context.Context, id string) error
- func (c *Client) DeleteWorkspace(ctx context.Context, workspace string) error
- func (c *Client) Events(ctx context.Context, cursor string, limit int) ([]api.Event, string, error)
- func (c *Client) Flush(ctx context.Context, workspace string, req api.FlushRequest) error
- func (c *Client) Has(ctx context.Context, shas []string) ([]bool, error)
- func (c *Client) ImportPack(ctx context.Context, packID string, index, pack []byte) error
- func (c *Client) Land(ctx context.Context, repo string, req api.LandRequest) (api.LandResponse, error)
- func (c *Client) Object(ctx context.Context, sha string) (Object, error)
- func (c *Client) Op(ctx context.Context, kind, id string) ([]byte, error)
- func (c *Client) OpHeads(ctx context.Context) (api.OpHeads, error)
- func (c *Client) ProtectedRefs(ctx context.Context, repo string) ([]string, error)
- func (c *Client) PutObjects(ctx context.Context, objs []Object) ([]string, error)
- func (c *Client) PutOp(ctx context.Context, kind, id string, data []byte) error
- func (c *Client) Ref(ctx context.Context, name string) (api.Ref, error)
- func (c *Client) Refs(ctx context.Context) ([]api.Ref, error)
- func (c *Client) Repo(ctx context.Context, path string) (api.Repo, error)
- func (c *Client) Repos(ctx context.Context) ([]api.Repo, error)
- func (c *Client) RevokeUserToken(ctx context.Context, id string) error
- func (c *Client) SetProtectedRefs(ctx context.Context, repo string, patterns []string) error
- func (c *Client) SetWorkspace(ctx context.Context, op, commit string, generation int64) error
- func (c *Client) Subscriptions(ctx context.Context) ([]api.Subscription, error)
- func (c *Client) SwapOpHeads(ctx context.Context, expectGeneration int64, heads []string) (api.OpHeads, error)
- func (c *Client) SwapRef(ctx context.Context, name string, expect int64, commit string) (api.Ref, error)
- func (c *Client) Trees(ctx context.Context, sha string, maxEntries int) (api.Trees, error)
- func (c *Client) UserTokens(ctx context.Context) ([]api.UserToken, error)
- type Error
- type GrantFunc
- type Object
- type Option
Constants ¶
const DefaultBudget = 2 * time.Second
DefaultBudget is the time limit of one call unless WithBudget sets another.
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.
Variables ¶
var ( ErrNotFound = errors.New("motte: 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") 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
ConflictPaths returns the paths that a land conflict names.
func CurrentRef ¶
CurrentRef returns the stored ref that a ref generation conflict carries.
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 (*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) CreateRepo ¶
CreateRepo creates a repository with a root commit under main and returns its path.
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
func (c *Client) CreateUserToken(ctx context.Context, req api.CreateUserTokenRequest) (api.CreateUserTokenResponse, error)
CreateUserToken issues a per-user token. The text of the token is in the response and nowhere else.
func (*Client) DeleteSubscription ¶ added in v0.6.0
DeleteSubscription removes a receiver. An unknown id is ErrNotFound.
func (*Client) DeleteWorkspace ¶
DeleteWorkspace deletes a workspace. It is idempotent.
func (*Client) Events ¶ added in v0.6.0
Events returns up to limit ref events after cursor, and the cursor to pass next. An empty cursor starts at the first event. 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) ImportPack ¶
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) ProtectedRefs ¶ added in v0.6.0
ProtectedRefs returns the protected ref patterns of repo, the repository text.
func (*Client) PutObjects ¶
PutObjects stores the objects and returns their names.
func (*Client) PutOp ¶
PutOp stores one op-log object of the workspace. kind is the op kind of the store.
func (*Client) RevokeUserToken ¶ added in v0.9.0
RevokeUserToken revokes the token with id.
func (*Client) SetProtectedRefs ¶ added in v0.6.0
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 ¶
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
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.
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.
type GrantFunc ¶
GrantFunc returns the bearer grant of one call. The client calls it before each request.
func StaticGrant ¶
StaticGrant returns a GrantFunc that always answers token.
type Option ¶
type Option func(*Client)
func WithBudget ¶
WithBudget sets the time limit of one call. Zero or less removes the limit; a deadline on the call context still applies.
func WithHTTPClient ¶
WithHTTPClient sets the transport. The client still follows no redirect.