store

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2026 License: MIT Imports: 29 Imported by: 0

Documentation

Overview

Package store is the SQLite storage layer and the document engine of Phase 2: one file holds the classes, the schemas, the typed document tables of ADR-0014, the event log of ADR-0006 and ADR-0026, and the database's own metadata.

A Store opens a database file as ADR-0035 configures it: WAL mode, one pinned writer connection on which every statement is prepared once, a checkpointer on its own connection so that a commit never pays a checkpoint, and pooled connections for reads. DefineClass compiles a definition with the model package, creates the current, history and child tables and the views a user sees, and keeps the class in memory with its storage layout. Create, Set and Delete are commits in the sense of ADR-0015: compute first, write last, in one transaction, with the recalculation of the auto variables, the history row, the child rows and the event. Preview runs the same pipeline and rolls back (ADR-0025). Every refusal is an *Error with a stable code, the variable it is about, a message and, where there is one, a hint.

Transition moves a document along a named transition of its class's statechart, with the eventless transitions that follow as further commits in the same transaction, and Transitions lists what may be taken (ADR-0040); a class without states stores no documents.

The rights table and the per-transition rules are enforced on every call (ADR-0041): a transition's rule and the write rights over the stored document before the assignments, every document returned projected for the principal, and the read rights of the variables a filter names compiled into its predicate. A call that reads or previews may run at a moment the caller chooses with At, and a preview reports it; a commit runs at the database's clock (ADR-0042).

Not here yet: rules (Phase 4), the class-level access rules (Phase 5), and the server (Phase 6).

Index

Constants

View Source
const (
	EventCreated    = "created"
	EventSet        = "set"
	EventDeleted    = "deleted"
	EventMigrated   = "migrated"
	EventTransition = "transition"
)

The event kinds this build writes, and the qualifiers of their event_docs rows.

View Source
const (
	// CodeUnknownClass: no class of that name.
	CodeUnknownClass = "unknown_class"
	// CodeUnknownDocument: no current document with that id, or no such
	// version in its history.
	CodeUnknownDocument = "unknown_document"
	// CodeUnknownTable: no explicit table of that name.
	CodeUnknownTable = "unknown_table"
	// CodeUnknownVariable: a value names a variable or a field the class
	// does not have.
	CodeUnknownVariable = "unknown_variable"
	// CodeReadOnly: a value is given for a computed variable.
	CodeReadOnly = "read_only"
	// CodeRequired: a required input is blank.
	CodeRequired = "required"
	// CodeBadValue: a value is not of the variable's type, or an argument
	// is malformed.
	CodeBadValue = "bad_value"
	// CodeNotInValues: a text is outside the variable's enum list
	// (ADR-0023).
	CodeNotInValues = "not_in_values"
	// CodeOutOfRange: a number is outside the variable's min and max
	// (ADR-0034), or a text is longer than the database's text limit
	// (ADR-0021).
	CodeOutOfRange = "out_of_range"
	// CodeTooManyElements: a composite value has more than the hard cap of
	// ADR-0013.
	CodeTooManyElements = "too_many_elements"
	// CodeKeyReused: the idempotency key was used with a different command
	// (ADR-0026).
	CodeKeyReused = "key_reused"
	// CodeDuplicate: a document with that id exists already, or a table or
	// view name is taken.
	CodeDuplicate = "duplicate"
	// CodeNotSupported: a construct the design has that this build does
	// not implement yet.
	CodeNotSupported = "not_supported"
	// CodeClosed: the store is closed.
	CodeClosed = "closed"
	// CodeStorage: the database refused a statement; Message carries its
	// words.
	CodeStorage = "storage"
	// CodeBadFormula: a filter's where does not parse or bind; Pos says
	// where.
	CodeBadFormula = "bad_formula"
	// CodeNotAllowed: a function class a filter may not use, a SQL
	// statement the endpoint refuses, or At on a command that writes
	// (ADR-0042).
	CodeNotAllowed = "not_allowed"
	// CodeTooManyRows: a SQL statement returns more than MaxSQLRows.
	CodeTooManyRows = "too_many_rows"
	// CodeUnknownBlob: a File names a hash the blob store does not hold,
	// or a size that differs from the stored one (ADR-0033).
	CodeUnknownBlob = "unknown_blob"
	// CodeBlobTooLarge: a file exceeds the database's blob limit.
	CodeBlobTooLarge = "blob_too_large"
	// CodeTerminal: the document is in a terminal state and cannot change
	// (ADR-0039).
	CodeTerminal = "terminal"
	// CodeStateless: Create or CreateMany on a class without states, a
	// stateless application that stores no documents (ADR-0040).
	CodeStateless = "stateless"
	// CodeUnknownTransition: the class has no named transition of that
	// name (ADR-0040).
	CodeUnknownTransition = "unknown_transition"
	// CodeWrongState: the transition exists and does not leave the
	// document's state.
	CodeWrongState = "wrong_state"
	// CodeGuardFalse: the transition's guard did not evaluate TRUE; an
	// erroring guard is FALSE.
	CodeGuardFalse = "guard_false"
	// CodeTooManyTransitions: more than eight eventless transitions fired
	// after one command (ADR-0008).
	CodeTooManyTransitions = "too_many_transitions"
	// CodeForbidden: the principal may not set the variable in the
	// document's state, may not take the transition, or may read the
	// variable a filter names in no state at all (ADR-0041).
	CodeForbidden = "forbidden"
)

The codes of the store's own refusals. An evaluation error inside a commit keeps the code of ADR-0019 (div_by_zero, overflow, ...) and names the variable whose formula failed.

View Source
const DefaultCheckpointEvery = 100 * time.Millisecond

DefaultCheckpointEvery is how often the checkpointer runs a passive checkpoint.

View Source
const DefaultMaxBlob int64 = 32 << 20

DefaultMaxBlob is the blob size limit of a new database, 32 MiB.

View Source
const DefaultMaxIndexedRows = 100000

DefaultMaxIndexedRows is the row count up to which a table is held in memory for the lookups of auto formulas (ADR-0036).

View Source
const DefaultWALLimit int64 = 64 << 20

DefaultWALLimit is the write-ahead log size past which the checkpointer truncates the log (ADR-0035).

View Source
const MaxElements = 10000

MaxElements is the hard cap on the elements of a composite variable (ADR-0013).

View Source
const MaxSQLRows = 10000

MaxSQLRows is the most rows a SQL statement may return.

Variables

View Source
var ErrBlobTooLarge = errors.New("the blob exceeds the database's limit")

ErrBlobTooLarge is what a BlobStore's Put returns past the limit.

View Source
var ErrNoBlob = errors.New("the blob store does not hold the hash")

ErrNoBlob is what a BlobStore's Open returns for a hash it does not hold.

Functions

This section is empty.

Types

type BlobLister

type BlobLister interface {
	List(ctx context.Context, fn func(hash string) error) error
}

BlobLister is a BlobStore that can enumerate its hashes, which CheckBlobs needs; the engine's two stores can.

type BlobStore

type BlobStore interface {
	// Put stores a stream and returns its hash and size, hashing while it
	// writes. It stops with an error when the stream exceeds max bytes,
	// before anything is stored. A put of a hash already held is a no-op.
	Put(ctx context.Context, r io.Reader, max int64) (hash string, size int64, err error)
	// Open opens a blob as a stream with its size, or reports that it is
	// not held.
	Open(ctx context.Context, hash string) (io.ReadCloser, int64, error)
	// Stat reports whether a hash is held and how large the blob is.
	Stat(ctx context.Context, hash string) (size int64, ok bool, err error)
	// Delete removes a blob; removing one that is not held is no error.
	Delete(ctx context.Context, hash string) error
}

BlobStore holds the bytes of attachments by content hash (ADR-0033). The store is chosen when the database is created and recorded in its metadata; three come with the engine, "sqlite", a table in the database file, "dir", a directory beside it, and the embedder's own, given in Options.Blobs and recorded as "external".

type Document

type Document struct {
	Class   string `json:"class"`
	ID      string `json:"id"`
	Title   string `json:"title"`
	State   string `json:"state,omitempty"`
	Version int64  `json:"version"`
	// ClassVersion is the version of the class that computed this version
	// of the document (ADR-0039).
	ClassVersion int `json:"class_version"`
	// Seconds since the epoch, UTC.
	CreatedAt      int64  `json:"created_at"`
	UpdatedAt      int64  `json:"updated_at"`
	StateEnteredAt int64  `json:"state_entered_at,omitempty"`
	Values         Values `json:"values"`
}

Document is a document at one version: the system variables of ADR-0013 and the declared variables under Values, blank as nil. Every variable the principal may read in the document's state is present and a hidden one absent (ADR-0041).

type Error

type Error struct {
	Code     string `json:"code"`
	Variable string `json:"variable,omitempty"`
	// Pos is the byte offset inside a formula when the finding is about a
	// place in one, such as a filter's where, and -1 or 0 otherwise.
	Pos     int    `json:"pos,omitempty"`
	Message string `json:"message"`
	Hint    string `json:"hint,omitempty"`
}

Error is a refusal of the store: a stable code from the list below or an evaluation code of the formula engine, the variable the finding is about when there is one, a message for a person and a hint when the engine knows the fix. A caller that drives the engine without a person watching branches on Code and Variable.

func (*Error) Error

func (e *Error) Error() string

type Event

type Event struct {
	ID            string `json:"event_id"`
	Class         string `json:"class"`
	DocID         string `json:"doc_id"`
	Kind          string `json:"kind"`
	Name          string `json:"name,omitempty"`
	FromState     string `json:"from_state,omitempty"`
	ToState       string `json:"to_state,omitempty"`
	ActorID       string `json:"actor_id,omitempty"`
	BeforeVersion int64  `json:"before_version,omitempty"`
	AfterVersion  int64  `json:"after_version,omitempty"`
	CauseEventID  string `json:"cause_event_id,omitempty"`
	CommandKey    string `json:"command_key,omitempty"`
	// BusinessDate is the calendar day as YYYY-MM-DD.
	BusinessDate string `json:"business_date"`
	TS           int64  `json:"ts"`
}

Event is one row of the event log (ADR-0006, ADR-0026).

type FileInfo

type FileInfo struct {
	Hash      string `json:"hash"`
	Name      string `json:"name,omitempty"`
	MediaType string `json:"media_type,omitempty"`
	Size      int64  `json:"size"`
}

FileInfo is the fact of a file as a document holds it (ADR-0032).

type Filter

type Filter = query.Filter

Filter is a query over a class (ADR-0038).

type HistoryRow

type HistoryRow struct {
	Document
	ValidFrom int64 `json:"valid_from"`
	// ValidTo is 0 while the version is current.
	ValidTo int64  `json:"valid_to,omitempty"`
	ActorID string `json:"actor_id,omitempty"`
	EventID string `json:"event_id"`
}

HistoryRow is one committed version: the document as it was, when it was current, who committed it and the event that did (ADR-0014).

type Option

type Option func(*options)

Option configures one call.

func As

func As(p Principal) Option

As runs the call as the principal.

func At added in v0.3.0

func At(t time.Time) Option

At runs a call that reads or previews at the moment (ADR-0042): NOW() is t and TODAY() its UTC day in every formula the call evaluates, defaults, guards, access rules and rights alike, and a preview reports it as Now. A zero t is the database's clock. A command that writes refuses it with not_allowed; the business date is untouched.

func AtVersion

func AtVersion(version int64) Option

AtVersion makes OpenFile read the document at a committed version instead of the current one.

func BusinessDate

func BusinessDate(day time.Time) Option

BusinessDate gives the commit's event its business date (ADR-0026), a calendar day; the time of day and the zone are ignored.

func Key

func Key(k string) Option

Key gives a mutating command its idempotency key (ADR-0026): a repeat with the same key makes no second commit and returns the first one's result.

func Replace

func Replace() Option

Replace makes an import empty the table first, so that the rows given are all the rows.

func WithID

func WithID(id string) Option

WithID gives a new document the caller's id instead of a generated one.

type Options

type Options struct {
	// Synchronous is NORMAL, the default, where a commit survives a crash
	// of the process and the last commits may be lost on power failure,
	// or FULL, where every commit is fsynced before it is acknowledged.
	Synchronous string
	// MaxText is the text limit of a new database in code points; 0 is
	// formula.DefaultMaxText.
	MaxText int
	// WALLimit is the log size that triggers a truncating checkpoint; 0
	// is DefaultWALLimit.
	WALLimit int64
	// CheckpointEvery is the checkpointer's period; 0 is
	// DefaultCheckpointEvery.
	CheckpointEvery time.Duration
	// MaxIndexedRows is the row count up to which an explicit table is
	// held in memory for LOOKUP (ADR-0036). It is kept in the metadata;
	// a value given on open replaces the stored one, since it changes
	// speed and memory and never a result. 0 keeps what is stored, or
	// DefaultMaxIndexedRows for a new database.
	MaxIndexedRows int
	// BlobStore is the kind of blob store a new database records
	// (ADR-0033): "sqlite", the default, a table in the database file;
	// "dir", a directory beside it; or "external", the embedder's store
	// given in Blobs. An existing database keeps its kind.
	BlobStore string
	// Blobs is the embedder's blob store, required when the database's
	// kind is external.
	Blobs BlobStore
	// MaxBlob is the blob size limit of a new database in bytes; 0 is
	// DefaultMaxBlob. It may be raised on open and never lowered.
	MaxBlob int64
	// Now is the clock of the database: it stamps every commit and is
	// what NOW() and TODAY() read in every formula, unless a call that
	// reads or previews chooses a moment with At (ADR-0042). nil is
	// time.Now. A test sets it, and so does an embedder that replays a
	// scenario into a copy of the file.
	Now func() time.Time
}

Options configure Open. The ones that are properties of the database, Synchronous and MaxText, are read at creation and kept in the metadata (ADR-0021, ADR-0035); opening an existing database with a different value is an error, since a database must behave the same wherever it is opened.

type Preview

type Preview struct {
	Document    *Document        `json:"document"`
	Errors      []*Error         `json:"errors,omitempty"`
	Path        []string         `json:"path,omitempty"`
	Transitions []TransitionInfo `json:"transitions,omitempty"`
	Now         int64            `json:"now"`
}

Preview is what a commit would do, without having done it (ADR-0025): the document as it would be, and the error of every variable whose formula failed or whose value the principal may not set, each with its code; for a class with states, the states the command visited, the state before first, and the named transitions leaving the resulting state (ADR-0040); and Now, the seconds since the epoch its formulas saw, the moment chosen with At or the database's clock (ADR-0042). A preview of a set that changes nothing reports the path and the transitions all the same, the version as it is. Rules arrive with Phase 4.

type Principal

type Principal struct {
	ID     string
	Groups []string
	Admin  bool
	Today  time.Time
}

Principal is who a call runs for (ADR-0027): the embedder's id for the actor, the groups INGROUP tests, the admin bypass, and the embedder's business day, the default business date of a commit (ADR-0026). A zero Today means none.

type Rows

type Rows struct {
	Columns []string `json:"columns"`
	Rows    [][]any  `json:"rows"`
}

Rows is the result of a SQL statement: the column names and the rows, each value as the database returns it, an integer, a float, text, bytes or nil.

type Store

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

Store is one open database.

func Open

func Open(path string, o Options) (*Store, error)

Open opens the database at path, creating it when it does not exist, and loads its schemas and classes.

func (*Store) BlobStoreKind

func (s *Store) BlobStoreKind() string

BlobStoreKind is the kind of blob store the database records: sqlite, dir or external.

func (*Store) Blobs

func (s *Store) Blobs() BlobStore

Blobs is the database's blob store.

func (*Store) CheckBlobs

func (s *Store) CheckBlobs(ctx context.Context) (mismatched []string, checked int, err error)

CheckBlobs reads every held blob, recomputes its hash and returns the hashes whose bytes do not match, and how many it checked (ADR-0033); a restore from an altered backup is found this way. A blob store that cannot list its hashes is the error not_supported.

func (*Store) Class

func (s *Store) Class(name string) (*model.Class, bool)

Class returns the compiled class of that name.

func (*Store) Classes

func (s *Store) Classes() []string

Classes lists the class names in the order they were defined.

func (*Store) Close

func (s *Store) Close() error

Close stops the checkpointer, closes every statement before its connection, and closes the database.

func (*Store) Count

func (s *Store) Count(ctx context.Context, f Filter, opts ...Option) (int64, error)

Count counts the documents of a class that match a filter's where.

func (*Store) Create

func (s *Store) Create(ctx context.Context, class string, values Values, opts ...Option) (*Document, error)

Create makes a document: the values given, the defaults of the inputs not given, every auto variable computed, version 1.

func (*Store) CreateMany

func (s *Store) CreateMany(ctx context.Context, class string, docs []Values, opts ...Option) ([]*Document, error)

CreateMany makes documents of one class in one transaction, one commit each with its own history row and event, all or none: a bulk load pays one fsync for the batch (ADR-0035). The options apply to every document; a batch takes no idempotency key, since a key names one command, and no caller's id, since the documents are many. An error names the document by its position, "[3].number".

func (*Store) DefineClass

func (s *Store) DefineClass(ctx context.Context, data []byte) (*model.Class, error)

DefineClass compiles a class definition, creates its tables and views and stores the definition. Defining the same definition again is a no-op. A redefinition is the next version of the class (ADR-0039): it adds the columns and tables of new variables, drops and remakes the columns of a variable that changed type with no value anywhere, keeps the columns of removed variables for the history, remakes the views, and touches no document; every earlier version stays compiled so that a document is read under the version that computed it. What a redefinition may not do against the documents is in redefinitionDiagnostics. A class with no history at all is dropped and made again.

func (*Store) DefineSchema

func (s *Store) DefineSchema(ctx context.Context, data []byte) (*model.Schema, error)

DefineSchema compiles a schema definition and stores it (ADR-0031). Defining the same definition again is a no-op; a schema a stored class uses cannot be redefined in this build.

func (*Store) DefineTable

func (s *Store) DefineTable(ctx context.Context, data []byte) (*model.Table, error)

DefineTable compiles an explicit table definition, creates the table and its view and stores the definition. The same definition again is a no-op. A table with no rows and no class reading it can be redefined; one with rows, or one a class reads, cannot in this build.

func (*Store) Delete

func (s *Store) Delete(ctx context.Context, class, id string, opts ...Option) error

Delete removes a document's current row and appends the event; its history stays (ADR-0014).

func (*Store) Events

func (s *Store) Events(ctx context.Context, class, id string, opts ...Option) ([]*Event, error)

Events reads the events that touched a document, oldest first.

func (*Store) Get

func (s *Store) Get(ctx context.Context, class, id string, opts ...Option) (*Document, error)

Get reads the current version of a document, projected for the principal (ADR-0041).

func (*Store) History

func (s *Store) History(ctx context.Context, class, id string, opts ...Option) ([]*HistoryRow, error)

History reads every committed version of a document, oldest first, each projected for the principal under its own state and values (ADR-0041). A deleted document keeps its history.

func (*Store) ImportRows

func (s *Store) ImportRows(ctx context.Context, name string, rows []Values, opts ...Option) (int, error)

ImportRows writes rows into a table in one transaction, each a map of column to value in the wire shape, inserting a row whose key is new and replacing one whose key exists; with Replace, the table is emptied first. It returns the number of rows written and drops the table's index, which the next lookup rebuilds (ADR-0036).

func (*Store) Limits

func (s *Store) Limits() formula.Limits

Limits are the database's size limits (ADR-0021).

func (*Store) MaxBlob

func (s *Store) MaxBlob() int64

MaxBlob is the database's blob size limit in bytes (ADR-0033).

func (*Store) MaxIndexedRows

func (s *Store) MaxIndexedRows() int

MaxIndexedRows is the row count up to which a table is held in memory for lookups (ADR-0036).

func (*Store) Migrate

func (s *Store) Migrate(ctx context.Context, class string, opts ...Option) (int, error)

Migrate brings every live document of a class that an older version computed to the current version, as commits of their own in batches of a thousand per transaction, each a history row and a migrated event (ADR-0039). Terminal documents are left alone. It returns how many documents it moved. It is never automatic.

func (*Store) OpenBlob

func (s *Store) OpenBlob(ctx context.Context, hash string, opts ...Option) (io.ReadCloser, int64, error)

OpenBlob opens a blob by hash alone, which an administrator may (ADR-0033); anyone else goes through OpenFile.

func (*Store) OpenFile

func (s *Store) OpenFile(ctx context.Context, class, id, hash string, opts ...Option) (io.ReadCloser, *FileInfo, error)

OpenFile opens a file a document holds: the hash must be the hash of a File of the document's current version, or of the version AtVersion names. It returns the stream and the fact as the document holds it. The read rule and the field right of Phase 5 are not applied yet.

func (*Store) Path

func (s *Store) Path() string

Path is the database file.

func (*Store) Preview

func (s *Store) Preview(ctx context.Context, class, id string, values Values, transition string, opts ...Option) (*Preview, error)

Preview runs a create (id empty), a set or a transition through the commit pipeline and rolls back (ADR-0025): the document as it would be, the states visited and the transitions leaving the resulting state.

func (*Store) PreviewDraft added in v0.3.0

func (s *Store) PreviewDraft(ctx context.Context, definition []byte, id string, values Values, transition string, opts ...Option) (*Preview, error)

PreviewDraft compiles a class definition for this request alone and runs a create (empty id) or a set of an existing document through the commit pipeline under it, writing nothing and storing nothing (ADR-0025): a designer tries a draft on the company's own documents. The document is read from the stored class of the draft's name, under the version that computed it, and recomputed in full under the draft; a terminal document may be looked at this way, since nothing changes. A draft that does not compile returns its Diagnostics.

func (*Store) PutBlob

func (s *Store) PutBlob(ctx context.Context, name, mediaType string, r io.Reader, opts ...Option) (Values, error)

PutBlob stores the bytes of a file and returns the File fact to commit (ADR-0033): the hash, the name given, the media type given or sniffed from the first bytes when none was, and the size. The fact is a Values ready for an object<File> variable or an element of rows<File>. A stream past the database's limit is the error blob_too_large, and nothing is stored.

func (*Store) Query

func (s *Store) Query(ctx context.Context, f Filter, opts ...Option) ([]*Document, error)

Query reads the documents of a class that match a filter, in its order, at most its limit, with the fields it names (ADR-0038), each projected for the principal (ADR-0041): a variable the principal may not read in a row's state is absent from that document, and a variable the where or the order names matches and sorts only where the principal may read it.

func (*Store) SQL

func (s *Store) SQL(ctx context.Context, text string, args []any, opts ...Option) (*Rows, error)

SQL runs one read-only statement over the views (ADR-0038): SELECT only, the views and the functions, nothing physical. Positional parameters bind args. At most MaxSQLRows rows come back; more is the error too_many_rows.

func (*Store) Schemas

func (s *Store) Schemas() *model.SchemaSet

Schemas are the database's schemas, the vocabulary included.

func (*Store) Set

func (s *Store) Set(ctx context.Context, class, id string, values Values, opts ...Option) (*Document, error)

Set assigns values to a document and recalculates what depends on them, as a new version. A set that changes nothing commits nothing and returns the document as it is.

func (*Store) Synchronous

func (s *Store) Synchronous() string

Synchronous is the database's synchronous setting, NORMAL or FULL.

func (*Store) Table

func (s *Store) Table(name string) (*model.Table, bool)

Table returns a compiled table definition by name.

func (*Store) TableRows

func (s *Store) TableRows(ctx context.Context, name string) ([]Values, error)

TableRows reads every row of a table in key order, in the wire shape.

func (*Store) Tables

func (s *Store) Tables() []string

Tables lists the explicit tables in definition order.

func (*Store) Transition added in v0.3.0

func (s *Store) Transition(ctx context.Context, class, id, name string, values Values, opts ...Option) (*Document, error)

Transition moves a document along the named transition, with the assignments in values applied in the same commit (ADR-0040): the assignments, the recalculation, the guard over the recalculated document, the eventless transitions, the writes. The commit is version N+1 with one event of kind transition; every eventless transition that fires after it is a further commit in the same transaction, a version of its own with the same values and the new state. A transition that cannot happen is refused before anything is written, with unknown_transition, wrong_state, guard_false, too_many_transitions or terminal.

func (*Store) Transitions added in v0.3.0

func (s *Store) Transitions(ctx context.Context, class, id string, opts ...Option) ([]TransitionInfo, error)

Transitions lists the named transitions leaving the document's state, in definition order, each with whether the principal may take it now and, when not, why (ADR-0040, ADR-0041): forbidden when the transition's access rule is not TRUE for the principal, else guard_false, with the rule's or the guard's error when it errored. It evaluates them over the stored document and writes nothing. Eventless transitions are not listed. The rules and guards run on the writer's VM, since they may look a table up through the writer's statements, so the listing takes the writer's turn; it is short.

func (*Store) Validate

func (s *Store) Validate(data []byte) model.Diagnostics

Validate compiles a class definition and reports what DefineClass would refuse, without storing anything (ADR-0025).

func (*Store) Version

func (s *Store) Version(ctx context.Context, class, id string, version int64, opts ...Option) (*HistoryRow, error)

Version reads one committed version of a document from its history, projected for the principal under the state and the values it had (ADR-0041).

type TransitionInfo added in v0.3.0

type TransitionInfo struct {
	Name    string `json:"name"`
	To      string `json:"to"`
	Enabled bool   `json:"enabled"`
	Code    string `json:"code,omitempty"`
	Message string `json:"message,omitempty"`
}

TransitionInfo is one named transition leaving a document's state, as Transitions and Preview list them (ADR-0040): its name and target, whether the principal may take it now and, when not, the code that says why, forbidden when its access rule is not TRUE for the principal (ADR-0041) and guard_false when its guard is not, with the rule's or the guard's error when it errored.

type Values

type Values map[string]any

Values are variable values by declared name, in the wire shape of ADR-0018: a blank is nil, a bool a bool, a number a float64 or any Go integer, an exact value text such as "12.30" or a number that is exact at the variable's scale, a money "12.30 PLN", a text a string, a date "YYYY-MM-DD" or a time.Time, a datetime integer seconds, a time.Time or "YYYY-MM-DD HH:MM:SS", a ref "Class:id", a json value its text, an object a map of its fields, rows a list of maps and an array a list of scalars. Names match case-insensitively. A document's Values on the way out use the same shape with a float64 for every number, an int64 for a datetime and json.RawMessage for a json value.

Jump to

Keyboard shortcuts

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