client

package
v0.29.0 Latest Latest
Warning

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

Go to latest
Published: Sep 9, 2026 License: Apache-2.0 Imports: 13 Imported by: 0 modules, 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 / transport type: adapter job: the HTTP client for a running ranke-db — one credential, one base URL, and the request plumbing every endpoint call shares, including the server's machine-readable error codes limits: transport only; what the endpoints mean is the OpenAPI contract's and what travels over them is the library's (-> codec_wire, query_codec)

package: client / transport type: adapter job: POST /contribute — a claim set and the external content it names, sent as one CBOR sequence, with the content gathered from the Universe rather than left to the caller limits: builds and posts the stream; framing it is the library's (-> codec_wire), and admitting it is the server's Sequencer

package: client / transport type: adapter job: POST /dev/clock — the dev sequencer's clock, reachable only through Client.Dev so a production consumer never meets it on the client's own surface limits: the route alone; whether it exists is the stack's launch flag, and this reports its absence rather than failing on it

package: client / transport type: logic job: the find-or-create and bulk-lookup reads three tools wrote for themselves — one claim of a type whose field equals a value, and every claim of a type set keyed by a field limits: builds queries and runs them through the client (-> read.go); minting what is missing is the caller's, since only it knows what the claim should say

package: client / transport type: adapter job: the reads — POST /query in either framing, the cacheable by-id GETs, and /health with the wait a caller would otherwise spend on a guessed sleep limits: transport only; the read language is the library's (-> query_codec) and a claim's bytes decode there too (-> codec)

package: client / transport type: io job: the two response framings a read arrives in — RFC 7464 JSON text sequences and RFC 8742 CBOR sequences — split into the records they carry limits: framing only; what a record means is the read's (-> read.go)

Index

Constants

View Source
const (
	MediaJSONSeq = "application/json-seq"
	MediaCBORSeq = "application/cbor-seq"
)

Media types the read endpoints answer with, mirroring output.encoding.

Variables

View Source
var (
	// ErrCredentials is both credentials at once, which the endpoint routes on the
	// presented scheme and so cannot resolve.
	ErrCredentials = errors.New("ranke/client: give a token or an API key, not both")
	// ErrNoBaseURL is a client built against nothing.
	ErrNoBaseURL = errors.New("ranke/client: base URL is required")
	// ErrNoUniverse is a contribution of claims naming external content with no
	// Universe to read the bytes from.
	ErrNoUniverse = errors.New("ranke/client: claims name external content, so a Universe is required")
	// ErrContentMissing is a blob a claim addresses that the Universe does not hold —
	// the state that used to travel silently, as a claim with an unbacked hash.
	ErrContentMissing = errors.New("ranke/client: the Universe holds no content under this hash")
	// ErrNilClaim is a nil entry in a contribution.
	ErrNilClaim = errors.New("ranke/client: nil claim")
	// ErrIncompleteLookup is a find naming no type or no field, which would read the
	// whole branch and match on nothing.
	ErrIncompleteLookup = errors.New("ranke/client: a lookup needs at least one type and a field")
)

Sentinels for the states a caller acts on. The rest arrive as *Error, whose Code is the server's stable category.

View Source
var ErrAmbiguous = errors.New("ranke/client: more than one claim matches")

ErrAmbiguous is a find that matched more than one claim where one was asked for. Choosing between them is the caller's, so this refuses rather than guessing.

View Source
var ErrUnknownFraming = errors.New("ranke/client: response is neither a JSON nor a CBOR sequence")

ErrUnknownFraming is a response whose media type names no sequence this can split.

Functions

func Category

func Category(err error, code string) bool

Category reports whether err is an *Error carrying code.

func ExternalContent

func ExternalContent(claims []ranke.Claim) ([]ranke.ContentRef, error)

ExternalContent lists each distinct blob the claims address, edges included: an edge holds content of its own. Order is first appearance, so a stream reproduces.

func IsNotFound

func IsNotFound(err error) bool

IsNotFound reports the read that found nothing — for a by-id GET, indistinguishable from a claim outside the scope's closure.

func IsUnimplemented

func IsUnimplemented(err error) bool

IsUnimplemented reports a route the stack does not mount, which is how a production stack answers the dev-only ones.

func MaxCreatedAt

func MaxCreatedAt(claims []ranke.Claim) time.Time

MaxCreatedAt is the latest created_at among claims, zero when there are none.

Types

type Client

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

Client talks to one ranke-db instance.

func New

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

New returns a client for the instance at baseURL. Presenting both credentials is refused here: the endpoint routes on the scheme presented, so two of them name two adapters and the request has no single answer.

func (*Client) Contribute

func (c *Client) Contribute(ctx context.Context, u ranke.Universe, branch string, claims []ranke.Claim) (*ContributionResult, error)

Contribute merges claims into branch atomically, with the content they address.

It takes a Universe so the blobs cannot be forgotten: a claim carries only its content_hash, and a re-run's dedup reads that hash rather than fetching it, so claims sent alone leave the bytes behind and nothing downstream notices.

func (*Client) Dev

func (c *Client) Dev() *DevClient

Dev returns the development-only surface.

func (*Client) FindByField

func (c *Client) FindByField(ctx context.Context, l Lookup) (map[string][]ranke.Claim, error)

FindByField keys every claim of the lookup's types by its field — FindOne in bulk, one read for many values. A claim without the field keys nothing, and claims sharing a value all appear, so a collision shows rather than resolving itself.

func (*Client) FindOne

func (c *Client) FindOne(ctx context.Context, l Lookup, value any) (claim ranke.Claim, found bool, err error)

FindOne returns the one claim whose field equals value, and whether there was one. The caller mints only when found is false, so a re-run reuses the existing id.

Two matches error: picking either would make the reused id depend on result order.

func (*Client) GetClaim

func (c *Client) GetClaim(ctx context.Context, scope Scope, id ranke.Id) (ranke.Claim, error)

GetClaim fetches one claim by id within scope. A claim outside that scope's closure is absent, which the endpoint answers the same as one that never existed.

func (*Client) Health

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

Health reports the instance as up, or the reason it is not.

func (*Client) Query

func (c *Client) Query(ctx context.Context, q ranke.Query) ([][]byte, error)

Query runs q and returns the records of the result sequence, undecoded, in the framing the response declares. The final record is the QueryReport when Execution.Report asked for one.

func (*Client) QueryClaims

func (c *Client) QueryClaims(ctx context.Context, q ranke.Query) ([]ranke.Claim, error)

QueryClaims runs q shaped so every record is a claim's stored envelope, and decodes each one. The shaping is fixed here — original form, no inlined content, CBOR — as that is the combination whose bytes re-hash to the id (`R-QCANON`); any other is a rendering, and would decode to a claim whose id does not hold.

func (*Client) WaitReady

func (c *Client) WaitReady(ctx context.Context, within time.Duration) error

WaitReady polls /health until it answers or within elapses, so a caller starting a stack waits for the fact rather than for a guessed interval.

type Clock

type Clock struct {
	Time      time.Time
	Available bool
}

Clock is where the dev sequencer's clock stands. Available is false against a stack that mounts no dev routes, which is every production one.

type ContributionResult

type ContributionResult struct {
	Head string   `json:"head"`
	Ids  []string `json:"ids"`
}

ContributionResult is what the merge produced: the new branch-table head and the ids absorbed under it.

type DevClient

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

DevClient is the development-only surface. It is reached through Client.Dev, which keeps these routes out of the way of a consumer that has no business with them: a real deployment mounts none of them.

func (*DevClient) AdvanceClock

func (d *DevClient) AdvanceClock(ctx context.Context, at time.Time) (Clock, error)

AdvanceClock moves the dev sequencer's clock to at least at, so a client whose story has its own schedule can make the archive's recorded times follow it.

The clock only moves forward: an instant already passed is accepted and changes nothing. A stack without the dev routes answers 501, which comes back as Available false rather than as an error — a caller that runs against both kinds should not have to branch on the deployment to call this.

func (*DevClient) AdvanceClockPast

func (d *DevClient) AdvanceClockPast(ctx context.Context, claims []ranke.Claim) (Clock, error)

AdvanceClockPast moves the clock to the latest created_at the claims carry, which is what a dev contribution needs: the sequencer stamps its merge from the clock, and a merge dated before a claim it absorbs would break `V-MONO`. A fixed offset from wall-clock now cannot know where a batch's own story ends.

type Error

type Error struct {
	Status  int
	Code    string
	Message string
}

Error is a failed request. Code is the server's category — unauthenticated, forbidden, not_found, conflict, busy, invalid, unimplemented, internal — and is what to branch on; Message is for a person.

func (*Error) Error

func (e *Error) Error() string

Error renders the status and the server's message.

type Health

type Health struct {
	Status string `json:"status"`
	Signer string `json:"signer"`
}

Health is the stack's liveness and the identity it merges under.

type Lookup

type Lookup struct {
	// Branch is the scope. A reserved scope works here as it does for a read.
	Branch string
	// Types are the claim types admitted, as "class/sub" globs. One entry is the
	// ordinary case; several make the type test a set.
	Types []string
	// Field is the field a match is read from — the key of the bulk form, and the
	// left side of the equality of the singular one.
	Field string
	// Head pins the closure, so a lookup repeated across a contribution sees the
	// same graph both times.
	Head ranke.Id
}

Lookup names the claims a find reads: the branch to read, the types to admit, and the field a match is decided on.

type Option

type Option func(*Client)

Option configures a Client.

func WithAPIKey

func WithAPIKey(k string) Option

WithAPIKey presents a key as `X-API-Key`.

func WithHTTPClient

func WithHTTPClient(h *http.Client) Option

WithHTTPClient supplies the transport, for timeouts, proxies or a test server.

func WithToken

func WithToken(t string) Option

WithToken presents a JWT as `Authorization: Bearer`.

type Scope

type Scope string

Scope names which of the three by-id routes a read takes. A branch confines to its closure; the other two are the reserved scopes.

const (
	ScopeArchive  Scope = "$archive"
	ScopeUniverse Scope = "$universe"
)

The reserved scopes. Any other value is a branch name.

Jump to

Keyboard shortcuts

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