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
- Variables
- func Category(err error, code string) bool
- func ExternalContent(claims []ranke.Claim) ([]ranke.ContentRef, error)
- func IsNotFound(err error) bool
- func IsUnimplemented(err error) bool
- func MaxCreatedAt(claims []ranke.Claim) time.Time
- type Client
- func (c *Client) Contribute(ctx context.Context, u ranke.Universe, branch string, claims []ranke.Claim) (*ContributionResult, error)
- func (c *Client) Dev() *DevClient
- func (c *Client) FindByField(ctx context.Context, l Lookup) (map[string][]ranke.Claim, error)
- func (c *Client) FindOne(ctx context.Context, l Lookup, value any) (claim ranke.Claim, found bool, err error)
- func (c *Client) GetClaim(ctx context.Context, scope Scope, id ranke.Id) (ranke.Claim, error)
- func (c *Client) Health(ctx context.Context) (*Health, error)
- func (c *Client) Query(ctx context.Context, q ranke.Query) ([][]byte, error)
- func (c *Client) QueryClaims(ctx context.Context, q ranke.Query) ([]ranke.Claim, error)
- func (c *Client) WaitReady(ctx context.Context, within time.Duration) error
- type Clock
- type ContributionResult
- type DevClient
- type Error
- type Health
- type Lookup
- type Option
- type Scope
Constants ¶
const ( MediaJSONSeq = "application/json-seq" MediaCBORSeq = "application/cbor-seq" )
Media types the read endpoints answer with, mirroring output.encoding.
Variables ¶
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.
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.
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 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 ¶
IsNotFound reports the read that found nothing — for a by-id GET, indistinguishable from a claim outside the scope's closure.
func IsUnimplemented ¶
IsUnimplemented reports a route the stack does not mount, which is how a production stack answers the dev-only ones.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client talks to one ranke-db instance.
func New ¶
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) FindByField ¶
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 ¶
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) Query ¶
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 ¶
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.
type Clock ¶
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 ¶
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 ¶
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 ¶
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 ¶
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.
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 WithHTTPClient ¶
WithHTTPClient supplies the transport, for timeouts, proxies or a test server.