api

package
v0.2.10 Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package api is the sheet API's HTTP surface: one URL per document, the action selected by method × media type. The document plane (store, version, apply, notify) evaluates no expression; the compute plane — enabled when the operator turns it on — serves computed values in the SPECIFICATION §9 vendor types, making every served sheet an IMPORT*-able origin.

The read half of the HTTP surface: every representation a GET can serve — the change feed, a computed reference, a computed grid, or the source document — and the caching headers that keep them distinguishable.

Idempotency-Key replay: a retried batch returns its original result instead of re-applying or failing a now-stale precondition.

Replay over the change feed: what a reconnecting subscriber is owed from the journal, and what it is told when its resume point is gone.

A subscriber's session over the change feed, as the handler sees it: the replay it is owed on connect and the live events that follow.

Server-Sent Events framing: turning one journal event into one SSE frame, and forwarding a live subscription until it ends.

The write half of the HTTP surface: replacing or creating a document, applying an edits batch, deleting, and the preconditions every one of them requires.

Index

Constants

View Source
const (
	TypeDoc     = "application/vnd.tsvsheet.doc+tsv"
	TypeEdits   = "application/vnd.tsvsheet.edits+tsv"
	TypeCells   = "application/vnd.tsvsheet.cells+tsv"
	TypeSheet   = "application/vnd.tsvsheet+tsv"
	TypeCell    = "application/vnd.tsvsheet.cell+tsv"
	TypeRow     = "application/vnd.tsvsheet.row+tsv"
	TypeColumn  = "application/vnd.tsvsheet.column+tsv"
	TypeRange   = "application/vnd.tsvsheet.range+tsv"
	TypeTSV     = "text/tab-separated-values"
	TypeCSV     = "text/csv"
	TypeStream  = "text/event-stream"
	TypeProblem = "application/problem+json"
)

The +tsv media-type family the API speaks. TypeDoc and TypeEdits are the document plane's own; the §9 vendor types (TypeSheet through TypeRange) mean computed values, in the shapes the language's IMPORT* builtins request — TestComputedRangeRowColumnShapes and TestGetValuesAcceptWithoutComputeIs406 assert the shapes and the source-versus-values refusal.

View Source
const (
	SlugNotFound     = problemNotFound
	SlugPrecondition = problemPrecondition
	SlugConflict     = problemConflict
	SlugStaleBase    = problemStaleBase
	SlugRefusedEdits = problemRefusedEdits
	SlugBadDocument  = problemBadDocument
	SlugDocTooLarge  = problemDocTooLarge
	SlugBadEdits     = problemBadEdits
)

The API's problem vocabulary. Each condition a client must be able to act on differently gets its own slug: a client port reconstructs the document plane's sentinels from these, so two conditions sharing a slug would make the remote adapter return a different error than the embedded one for the same cause. The exported names for the slugs a client acts on.

View Source
const ProblemBase = "https://tsvsheet.com/problems/"

ProblemBase prefixes every problem type URI (RFC 9457). It is exported because a client reads the type URI to tell one refusal from another.

Variables

This section is empty.

Functions

This section is empty.

Types

type Clock

type Clock func() time.Time

Clock supplies the compute plane's evaluation time, injected so volatile functions are deterministic under test.

type ComputePlane

type ComputePlane bool

ComputePlane selects whether the server carries the engine's compute plane.

const (
	DocumentPlaneOnly ComputePlane = false
	WithComputePlane  ComputePlane = true
)

The two plane configurations, named at the call sites.

type Config

type Config struct {
	Port           document.Port
	Clock          Clock
	Limits         tsvsheet.Limits
	ComputeEnabled ComputePlane
}

Config assembles a handler. Observability is deliberately absent: it is a decorator a server applies (observe.Handler), not a handler feature — see R17 and the observe package.

type Handler

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

Handler is the sheet API's http.Handler.

Pointer receivers are necessary: the handler owns the feed hub and the idempotency replay cache, which carry mutexes and shared maps.

func NewHandler

func NewHandler(config Config) Handler

NewHandler builds the API handler over its store.

func (Handler) ServeHTTP

func (handler Handler) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP routes one request: the path names a document (optionally with a `!` reference suffix), the method and media types name the action.

type ProblemSlug

type ProblemSlug = problemSlug

ProblemSlug names one error condition in a problem type URI. A client maps these back to the document plane's sentinels, so they are part of the wire contract rather than an implementation detail.

Jump to

Keyboard shortcuts

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