items

package
v0.17.0 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2026 License: Apache-2.0 Imports: 10 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 items provides API operations for Truestamp items.

Index

Constants

View Source
const CodeItemCodeUnavailable = "item_code_unavailable"

CodeItemCodeUnavailable is the server's code for a submission it could not give an item code. Nothing was created, and the same request may be sent again.

View Source
const DefaultLimit = 25

DefaultLimit matches the server's own default for the paginated read.

View Source
const MaxNumberOctets = 1024

MaxNumberOctets is the longest number literal, in octets as written (sign, point and exponent included), that the Truestamp service reads in a request body: its request reader, TruestampWeb.RequestJSON, refuses a body holding a longer one before anything else reads it, under Truestamp.JSONNumbers.max_octets (1,024). It is a limit on what can be sent, not a rule about the value: the service answers such a request with a bare 400 that names neither the claims nor the number.

Variables

View Source
var ErrEmptyVisibility = errors.New("--visibility needs a value: private, team or public")

ErrEmptyVisibility refuses an explicit empty --visibility: the flag given with no value would otherwise send "" (update) or drop the member (create), where the user named a visibility and gave none.

View Source
var ErrItemCodeUnavailable = errors.New("the server could not issue an item code")

ErrItemCodeUnavailable is the class of a 409 item_code_unavailable refusal: nothing was created, and sending the same request again is expected to succeed.

View Source
var ErrNothingToUpdate = errors.New("nothing to update: pass --visibility, --tags or --to-team")

ErrNothingToUpdate is an update that asks for no change.

View Source
var Visibilities = []string{"private", "team", "public"}

Visibilities is the closed set the server accepts for an item's visibility. It is declared once so `items create` and `items update` validate and describe the same three values.

Functions

func ClaimsJSONString added in v0.17.0

func ClaimsJSONString(s string) []byte

ClaimsJSONString writes s, valid UTF-8, as a JSON string that reads back as s: a quotation mark, a reverse solidus and each control character below U+0020 are escaped, and every other character is written as itself. It is the one writer of a claims value that `truestamp items create` and the console's new-item pane build, so the two send the same claims text for the same input. encoding/json is not used: its v1 API rewrites invalid UTF-8 to U+FFFD and escapes "<", ">" and "&", and its v2 API refuses invalid UTF-8.

func LongNumber added in v0.17.0

func LongNumber(text []byte) (offset, length int, found bool)

LongNumber returns the offset, counted in octets from 0, and the length of the first number literal of text longer than MaxNumberOctets, and true; or false when there is none. A literal is a run of the octets a JSON number is written with (0 to 9, "-", "+", ".", "e" and "E"), outside a string, that begins with a digit or "-"; a string is skipped with its escapes, so a number inside one is not a literal. That is the service's own scan (Truestamp.JSONNumbers), and in a JSON text each such run is exactly one number.

func NormalizeTags added in v0.14.0

func NormalizeTags(in []string) []string

NormalizeTags trims whitespace and drops empty entries, so "a, b,," from a flag becomes ["a" "b"] whichever command received it.

func ValidateVisibility added in v0.14.0

func ValidateVisibility(v string) error

ValidateVisibility rejects a value outside Visibilities. The empty string is accepted: it means "not supplied".

Types

type ClaimsReason added in v0.17.0

type ClaimsReason struct {
	Code    string `json:"code"`
	Message string `json:"message"`
	Pointer string `json:"pointer"`
}

ClaimsReason is one claims rule the server found broken: its code (such as claims_surrounding_whitespace), its message, which names the fix, and Pointer, the RFC 6901 pointer into the claims at the member that breaks it ("" for the claims as a whole).

type ClaimsRefusedError added in v0.17.0

type ClaimsRefusedError struct {
	Status  int
	Reasons []ClaimsReason
	Others  []string
}

ClaimsRefusedError is a create the server refused because the claims break one or more of its rules: every rule broken, in the server's order. Others holds the detail of any error in the same response that names no member of the claims, so that nothing the server said is dropped.

func (*ClaimsRefusedError) Error added in v0.17.0

func (e *ClaimsRefusedError) Error() string

type CreateItemResponse

type CreateItemResponse struct {
	ID         string
	State      string
	ClaimsHash string
	// ClaimsJCS is the server's claims_jcs: the canonical form (RFC 8785)
	// of the claims it accepted, the bytes ClaimsHash is computed over.
	ClaimsJCS string
	ItemHash  string
	// ItemCode is the item code the server issued the item (SPEC.md
	// section 3.9 (The item code)), in its one spelling.
	ItemCode   string
	Visibility string
	Tags       []string
	TeamID     string
	Name       string
	Hash       string
	HashType   string
}

CreateItemResponse holds the parsed JSON:API response for a created item.

func CreateItemCtx added in v0.3.0

func CreateItemCtx(ctx context.Context, apiURL, team string, claimsJSON []byte, visibility string, tags []string) (*CreateItemResponse, error)

CreateItemCtx sends a JSON:API POST request to create a new item. claimsJSON is the claims as a JSON text, one value the caller has read with the strict reader (internal/strictjson); it is written into the request body byte for byte as the value of attributes.claims, never decoded and re-encoded, so the server reads exactly the text the user gave. visibility and tags are item attributes. ctx cancels the in-flight request. The credential is applied by the process-wide [auth.Authorizer].

A refusal of the claims is a *ClaimsRefusedError; a 409 item_code_unavailable is a *jsonapi.APIError whose Sentinel is ErrItemCodeUnavailable; any other non-2xx status is a *jsonapi.APIError.

type Item added in v0.14.0

type Item struct {
	ID         string         `json:"id"`
	State      string         `json:"state"`
	Claims     map[string]any `json:"claims,omitempty"`
	ClaimsHash string         `json:"claims_hash,omitempty"`
	ItemHash   string         `json:"item_hash,omitempty"`
	// ItemCode is the item code the server issued the item (SPEC.md
	// section 3.9 (The item code)), in its one spelling: a name for the
	// item, never a stand-in for ItemHash where identity is compared.
	ItemCode    string   `json:"item_code,omitempty"`
	Visibility  string   `json:"visibility,omitempty"`
	Tags        []string `json:"tags,omitempty"`
	TeamID      string   `json:"team_id,omitempty"`
	DisplayName string   `json:"display_name,omitempty"`
	InsertedAt  string   `json:"inserted_at,omitempty"`
	UpdatedAt   string   `json:"updated_at,omitempty"`
	ExpiresAt   string   `json:"expires_at,omitempty"`
}

Item is the subset of an item's attributes the CLI reads back.

Three of these fields, InsertedAt, UpdatedAt and ExpiresAt, are NOT in the resource's json_api default_fields, so every request that wants them must ask for them explicitly via fields[item]. See requestFields.

func Get added in v0.14.0

func Get(ctx context.Context, apiURL, team, ref string) (*Item, error)

Get fetches one item by ref, its UUIDv7 id, its item code or its item_hash, sent as given: the app's item read route (GET /items/:id, its :read_by_ref action) reads each of the three.

func Update added in v0.14.0

func Update(ctx context.Context, apiURL, team, id string, opts UpdateOptions) (*Item, error)

Update patches an item's mutable attributes. id is the item's UUIDv7 id: the app's update route (PATCH /items/:id, read through :read_by_id) reads no other reference.

func (Item) Committed added in v0.14.0

func (i Item) Committed() bool

Committed reports whether the item is in a block. Proof generation requires it server-side: an item not yet committed is refused with subject_not_ready, and a committed item whose block has no commitment on a public chain yet with no_block_commitment, or with commitment_not_final while none of its commitments is final.

func (Item) Pending added in v0.17.0

func (i Item) Pending() bool

Pending reports whether the item is still on its way into a block: it is created or processing. A committed item is not, and neither is a redacted or deleted one, which no block will take.

type ListOptions added in v0.14.0

type ListOptions struct {
	Limit int
	// After is a keyset cursor from a previous Page.NextCursor; Before is
	// one from Page.PrevCursor. At most one is set.
	After  string
	Before string
	// OldestFirst walks from the beginning instead of the newest item.
	OldestFirst bool
	// Count asks the server for the total, reported as Page.Total.
	Count bool
	// Committed and Pending filter on commitment state. Both false means
	// no filter; both true is refused here and, before any request, by the
	// command's mutually exclusive flags.
	Committed bool
	Pending   bool
}

ListOptions configures a list request.

type Page added in v0.14.0

type Page struct {
	Items []Item
	// NextCursor is empty when there are no more pages; PrevCursor is
	// empty on the first.
	NextCursor string
	PrevCursor string
	// Total is the server's count of matching items, only when asked for.
	Total int
	// Limit is the page size the server actually used (it clamps to its
	// max_page_size rather than refusing).
	Limit int
}

Page is one page of a list response plus the cursor for the next.

func List added in v0.14.0

func List(ctx context.Context, apiURL, team string, opts ListOptions) (*Page, error)

List fetches one page of items, newest first.

type UpdateOptions added in v0.14.0

type UpdateOptions struct {
	Visibility *string
	Tags       *[]string
	TeamID     *string
}

UpdateOptions carries the mutable attributes.

The server's :update action is `accept [:team_id, :visibility, :tags]`, described there as "considered mutable and not included in the item's hash". name and description live inside claims and are immutable, so there is deliberately no way to reach a hashed field from here.

func (UpdateOptions) Empty added in v0.14.0

func (o UpdateOptions) Empty() bool

Empty reports whether the caller asked for no change at all.

Jump to

Keyboard shortcuts

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