Documentation
¶
Overview ¶
Package setup holds the onboarding and configuration services: the documents the local API returns and the pure reads that build the same documents from state files when no server is running. Presentations (CLI, TUI, web) render these documents; they never compute next actions, order or validation themselves.
See decision 0006 and spec/features/configuration-parity#REQ:json-equals-api.
Index ¶
- Constants
- Variables
- func CatalogueDir(home string) string
- func CreatedNext(database Database) []envelope.Next
- func DatabaseIDs(databases []Database) []string
- func DefaultPath(dataHome, engine, id string) string
- func FallbackAddress(port int) string
- func Location(m *manifest.Manifest, baseDir string) string
- func ManifestPath(home, id string) string
- func ManifestSteps(engine, home string) []envelope.Next
- func MountsPath(runtimeDir string) string
- func NormalizeOrigins(origins []string) []string
- func ParseOrigins(value string) ([]string, *envelope.Error)
- func ParsePort(value, source string) (int, *envelope.Error)
- func PrimaryAddress(port int) string
- func RegistryDir(home string) string
- func ReloadedNext(database Database) []envelope.Next
- func ResolvePort(flagPort int, getenv paths.Getenv, config Config) (port int, explicit bool, err *envelope.Error)
- func SuggestedName(next envelope.Next) string
- func UnknownConfigKey(key string) *envelope.Error
- func ValidPort(port int) bool
- func ValidateCreate(request *CreateRequest) *envelope.Error
- func WriteMounts(runtimeDir string, mounts Mounts) error
- type Badge
- type Config
- type ConfigChange
- type ConfigDocument
- type CopyRef
- type CreateRequest
- type Database
- type DatabaseResult
- type DatabasesDocument
- type Engine
- type EnginesDocument
- type HomeDocument
- type HomeOption
- type MountRecord
- type Mounter
- type Mounts
- type Registration
- type Registry
- func (r *Registry) Close()
- func (r *Registry) Create(request CreateRequest) (DatabaseResult, error)
- func (r *Registry) List() ([]Database, error)
- func (r *Registry) MountAll(ctx context.Context)
- func (r *Registry) Mounts() *Mounts
- func (r *Registry) Reload(ctx context.Context, id string) (DatabaseResult, error)
- func (r *Registry) ReloadAll(ctx context.Context) (DatabasesDocument, error)
- func (r *Registry) Remove(ctx context.Context, id string) (DatabaseResult, error)
- type RegistryOptions
- type Server
- type ServerConfig
- type ServerDocument
- type Status
Constants ¶
const ( KeyServerPort = "server.port" // KeyServerCORS lists the browser app origins allowed to call /v1/… and // /token with bearer tokens (capability 25, CLI only: exception E7). KeyServerCORS = "server.cors" )
Configuration keys. Telemetry and the global context follow in later increments.
const ( MinPort = 1 MaxPort = 65535 )
MinPort and MaxPort bound every port ovdb accepts, from a flag, an environment variable, `ovdb config set server.port` or the TUI's own pre-submit check — one place so the range cannot drift between them.
const ( // UnmountTimeout bounds the wait for in-flight requests when a database // is removed, reloaded or the server stops. UnmountTimeout = 10 * time.Second // DefaultMountTimeout bounds one database's mount. DefaultMountTimeout = 5 * time.Second )
Timeouts.
const ( ActionEditName = "edit_name" ActionEditLocation = "edit_location" ActionDatabases = "databases" ActionDone = "done" // ActionUse makes the database current: for this project in the TUI, // as the default for all projects in the web console (parity E3). ActionUse = "use" // ActionBrowse opens Browse data for the database. ActionBrowse = "browse" )
Next actions presentations can act on in place (envelope.Next.Action). For edit_name, a command naming a database (`ovdb databases create notes-2`) carries the suggested name: see SuggestedName.
const ( EngineInGitDB = "ingitdb" EngineSQLite = "sqlite" EngineFirestore = "firestore" EngineMySQL = "mysql" EnginePostgres = "postgres" )
Engine ids. They are the storage.engine values the manifest parser and openvaultdb-go's mount accept; engines_test.go fails when the two drift.
const ( SetupGuided = "guided" SetupManifest = "manifest" )
Setup kinds: an engine is created and connected in guided steps, or set up with a manifest file only (database-setup-and-providers#REQ:manifest-only-engines-are-honest).
const ( // DatabasesDir holds one manifest per registered database, <id>.yaml. DatabasesDir = "databases" // CataloguesDir holds the inferred-schema catalogues OVDB keeps for // registered databases, so mounting never writes into user storage. CataloguesDir = "catalogues" // MountsFile is the running server's per-database mount state. MountsFile = "mounts.json" )
Registry locations inside OVDB home and the runtime directory.
const ( MountMounting = "mounting" // loading after a start or reload MountMounted = "mounted" MountNeedsAttention = "needs_attention" MountUnknown = "unknown" // no server running )
Mount states.
const ( StateRunning = "running" StateNotRunning = "not_running" StateStopping = "stopping" // only in the shutdown response )
Server states.
const ConfigFile = "config.yaml"
ConfigFile is the configuration file in OVDB home.
const EnvPort = "OVDB_PORT"
EnvPort overrides the configured port for one shell.
const ManifestDocsURL = "https://github.com/openvaultdb/openvaultdb-go#manifest-examples"
ManifestDocsURL explains manifests, engines and schema modes.
const SchemaDocsURL = "https://github.com/openvaultdb/openvaultdb-go#schema-modes"
SchemaDocsURL explains schema modes and how to declare collections.
Variables ¶
var Keys = []string{KeyServerPort, KeyServerCORS}
Keys lists the supported keys, for usage errors.
Functions ¶
func CatalogueDir ¶ added in v0.11.0
CatalogueDir is <home>/catalogues.
func CreatedNext ¶ added in v0.11.0
CreatedNext is what to do after creating database: for SQLite, describing the data comes before anything that writes (database-setup-and-providers#REQ:sqlite-next-step-is-schema). Only implemented commands are offered; Browse data, Explore data and AI agent skills join as their increments land.
func DatabaseIDs ¶ added in v0.11.0
DatabaseIDs are the ids of databases, in order.
func DefaultPath ¶ added in v0.11.0
DefaultPath is where a new database lives unless the person picks another place: <data home>/<id>/ for inGitDB, <data home>/<id>.sqlite for SQLite (database-setup-and-providers#REQ:create-new-database). Clients call it with the data home they resolved.
func FallbackAddress ¶
FallbackAddress is the address that works where *.localhost does not.
func Location ¶ added in v0.11.0
Location describes where m keeps its data without any credential: the absolute storage path, or for server engines where the connection comes from. baseDir resolves relative paths.
func ManifestPath ¶ added in v0.11.0
ManifestPath is where database id is registered.
func ManifestSteps ¶ added in v0.11.0
ManifestSteps is how to set up a manifest-only engine today: write a manifest, edit it, put it in the registry folder and load it; guided connect comes later. home is OVDB home ("" names it generically).
func MountsPath ¶ added in v0.11.0
MountsPath is <runtime>/mounts.json.
func NormalizeOrigins ¶ added in v0.9.0
NormalizeOrigins cleans origins read from a hand-edited config.yaml the way ParseOrigins cleans CLI input, dropping entries that are not origins (and a trailing slash, which browsers never send).
func ParseOrigins ¶ added in v0.9.0
ParseOrigins parses a comma-separated list of browser origins (scheme://host[:port], http or https, nothing after the host). An empty value clears the list.
func ParsePort ¶
ParsePort validates a port number given through source (a flag, variable or key name).
func PrimaryAddress ¶
PrimaryAddress is the address people open.
func RegistryDir ¶ added in v0.11.0
RegistryDir is <home>/databases.
func ReloadedNext ¶ added in v0.11.0
ReloadedNext is what to do after a reload.
func ResolvePort ¶
func ResolvePort(flagPort int, getenv paths.Getenv, config Config) (port int, explicit bool, err *envelope.Error)
ResolvePort applies --port > OVDB_PORT > server.port > 6832 (REQ:port-precedence). explicit is true for the flag and the variable, which must match a running server's port.
func SuggestedName ¶ added in v0.11.0
SuggestedName is the name an edit_name next action suggests, or "".
func UnknownConfigKey ¶
UnknownConfigKey is invalid_argument naming the supported keys.
func ValidateCreate ¶ added in v0.11.0
func ValidateCreate(request *CreateRequest) *envelope.Error
ValidateCreate checks a request without touching anything. It fills the default engine and normalizes the location with this OS's path rules (so C:/Users/… is absolute on Windows, and a trailing separator is fine).
func WriteMounts ¶ added in v0.11.0
WriteMounts atomically writes mounts.json owner-only.
Types ¶
type Badge ¶ added in v0.9.0
type Badge struct {
Tone string `json:"tone"` // ok, warn, neutral
LabelKey string `json:"label_key"`
}
Badge is a server state as presentations show it: a tone and a copy key.
func StateBadge ¶ added in v0.9.0
StateBadge maps a server state to its badge.
type Config ¶
type Config struct {
Server ServerConfig `yaml:"server,omitempty" json:"server"`
}
Config is config.yaml. Unset values are omitted and mean "default".
func LoadConfig ¶
LoadConfig reads config.yaml; a missing file is the empty configuration.
type ConfigChange ¶
ConfigChange is the body of PUT /api/local/v1/config.
type ConfigDocument ¶
type ConfigDocument struct {
Schema int `json:"schema"`
Config Config `json:"config"`
// Changed is set on a change's result: false when the value was
// already the one asked for, so nothing needs a restart.
Changed *bool `json:"changed,omitempty"`
Next []envelope.Next `json:"next"`
}
ConfigDocument is the body of GET/PUT /api/local/v1/config and the --json output of `ovdb config get|set`.
func ApplyConfigChange ¶
func ApplyConfigChange(dirs paths.Dirs, change ConfigChange, serverRunning bool) (ConfigDocument, error)
ApplyConfigChange validates change, writes config.yaml owner-only and returns the resulting document. The caller must be the home's single writer: the running server, or a client holding home.lock (serverRunning false).
func NewConfigDocument ¶
func NewConfigDocument(config Config, changedWhileRunning bool) ConfigDocument
NewConfigDocument wraps config. A change made while the server runs gets the restart that applies it as its next action.
type CopyRef ¶ added in v0.9.0
CopyRef is copy a presentation renders: a catalogue key and its params.
func ContextStatus ¶ added in v0.11.0
ContextStatus is the status line part naming the current database and its scope (first-run-onboarding#REQ:home-status-line).
func DatabasesStatus ¶ added in v0.11.0
DatabasesStatus is the status line part counting databases and how many need attention (first-run-onboarding#REQ:home-status-line).
type CreateRequest ¶ added in v0.11.0
type CreateRequest struct {
ID string `json:"id"`
Engine string `json:"engine"`
Path string `json:"path"`
}
CreateRequest is the body of POST /api/local/v1/databases. Path is the absolute location the client resolved (by default under its data home).
type Database ¶ added in v0.11.0
type Database struct {
ID string `json:"id"`
Engine string `json:"engine,omitempty"`
Location string `json:"location,omitempty"`
State string `json:"state,omitempty"` // mounted, needs_attention, unknown
// Reason says, redacted, why a database needs attention.
Reason string `json:"reason,omitempty"`
// Manifest is the registry file, so a person can inspect or fix it.
Manifest string `json:"manifest"`
}
Database is one registered database as every interface lists it.
type DatabaseResult ¶ added in v0.11.0
type DatabaseResult struct {
Schema int `json:"schema"`
Database Database `json:"database"`
Next []envelope.Next `json:"next"`
}
DatabaseResult is the body of a successful create, reload or remove, and the --json output of `ovdb databases create|reload|remove`.
func NewRemovedResult ¶ added in v0.11.0
func NewRemovedResult(database Database) DatabaseResult
NewRemovedResult is the result of removing database.
type DatabasesDocument ¶ added in v0.11.0
type DatabasesDocument struct {
Schema int `json:"schema"`
Databases []Database `json:"databases"`
Next []envelope.Next `json:"next"`
}
DatabasesDocument is the body of GET /api/local/v1/databases and the --json output of `ovdb databases`.
func NewDatabasesDocument ¶ added in v0.11.0
func NewDatabasesDocument(databases []Database) DatabasesDocument
NewDatabasesDocument wraps databases with the next actions that apply.
type Engine ¶ added in v0.11.0
type Engine struct {
ID string `json:"id"`
Name string `json:"name"`
Description string `json:"description"`
SchemaModes []string `json:"schema_modes"`
// Pinned engines come first, in catalogue order, and presentations
// separate them from the rest.
Pinned bool `json:"pinned"`
Setup string `json:"setup"` // guided, manifest
// Note adds a detail under the description, e.g. GitHub-backed inGitDB.
Note string `json:"note,omitempty"`
// ManifestSteps are the steps for a manifest-only engine, in order; the
// last one points to the documentation.
ManifestSteps []envelope.Next `json:"manifest_steps,omitempty"`
}
Engine is one storage choice in the catalogue.
func Engines ¶ added in v0.11.0
func Engines() []Engine
Engines is the storage catalogue in display order: inGitDB and SQLite pinned, then the rest by name (database-setup-and-providers#REQ:catalogue-order-and-filter). This order does not change the backend build order.
func FilterEngines ¶ added in v0.11.0
FilterEngines keeps the engines whose id, name or description contains filter, ignoring case, in their order (REQ:catalogue-order-and-filter). The web console applies the same rule in web/src/engines.ts.
func FindEngine ¶ added in v0.11.0
FindEngine returns the catalogue entry for id.
type EnginesDocument ¶ added in v0.11.0
type EnginesDocument struct {
Schema int `json:"schema"`
Engines []Engine `json:"engines"`
Next []envelope.Next `json:"next"`
}
EnginesDocument is the body of GET /api/local/v1/engines and the --json output of `ovdb engines`.
func NewEnginesDocument ¶ added in v0.11.0
func NewEnginesDocument(home string) EnginesDocument
NewEnginesDocument wraps the catalogue for OVDB home.
type HomeDocument ¶ added in v0.9.0
type HomeDocument struct {
Schema int `json:"schema"`
StatusLine []CopyRef `json:"status_line"`
QuestionKey string `json:"question_key"`
Options []HomeOption `json:"options"`
}
HomeDocument is the body of GET /api/local/v1/home: the status line and the implemented Home options in the founder's order (first-run-onboarding#REQ:home-menu-options, REQ:home-status-line). The TUI and the web console both render it, so neither builds the menu.
func NewHome ¶ added in v0.9.0
func NewHome(server Server, databases []Database, context *dbcontext.Context) HomeDocument
NewHome builds Home for server, the registered databases and the context that applies to the caller (nil when none does). Options appear here only once they are implemented; later increments insert theirs in the founder's order.
A returning user (at least one database) sees one summary line above the same question and menu: `2 databases · using todo (this project) · OVDB server running at …` (first-run-onboarding#REQ:returning-user-home).
type HomeOption ¶ added in v0.9.0
type HomeOption struct {
ID string `json:"id"`
Group string `json:"group"` // primary, secondary
LabelKey string `json:"label_key"`
WebLabelKey string `json:"web_label_key,omitempty"`
DescriptionKey string `json:"description_key,omitempty"`
Badge *Badge `json:"badge,omitempty"`
// Disabled options are shown with DescriptionKey saying why.
Disabled bool `json:"disabled,omitempty"`
}
HomeOption is one Home menu option. LabelKey is the terminal wording; WebLabelKey, when set, replaces it in the web console, which cannot start the server that serves it (parity E1).
type MountRecord ¶ added in v0.11.0
type MountRecord struct {
ID string `json:"id"`
Manifest string `json:"manifest"`
State string `json:"state"`
Reason string `json:"reason,omitempty"`
}
MountRecord is one database's entry in mounts.json.
type Mounter ¶ added in v0.11.0
type Mounter interface {
Mount(db *core.Database) error
UnmountContext(ctx context.Context, id string) error
}
Mounter is the part of the openvaultdb-go server the registry drives.
type Mounts ¶ added in v0.11.0
type Mounts struct {
Schema int `json:"schema"`
Databases []MountRecord `json:"databases"`
}
Mounts is mounts.json: what the running server mounted and what needs attention, with reasons already redacted.
func ReadMounts ¶ added in v0.11.0
ReadMounts reads mounts.json; nil when there is none.
type Registration ¶ added in v0.11.0
type Registration struct {
ID string
Manifest string
Parsed *manifest.Manifest // nil when the file cannot be parsed
Err error // why it cannot be parsed
}
Registration is one manifest file in the registry, read without mounting.
func ReadRegistry ¶ added in v0.11.0
func ReadRegistry(home string) ([]Registration, error)
ReadRegistry lists the manifests in <home>/databases, sorted by file name. A manifest that cannot be read or parsed is still listed, under its file name, with its error: one broken file never hides the others (local-server-and-web-console#REQ:registry-serving).
func (Registration) Describe ¶ added in v0.11.0
func (r Registration) Describe() Database
Describe is registration as listed, with state and reason left to the caller.
type Registry ¶ added in v0.11.0
type Registry struct {
// contains filtered or unexported fields
}
Registry is the running server's view of <home>/databases: it mounts every manifest, keeps each one's mount state, and creates, reloads and removes registrations while serving. Only the server holding home.lock owns one (local-server-and-web-console#REQ:single-server-home-lock).
Database ids are unique ignoring case (registry files live on file systems that may ignore case); commands name a database by its exact id, or by any casing when exactly one registered id matches.
func OpenRegistry ¶ added in v0.11.0
func OpenRegistry(dirs paths.Dirs, srv Mounter, logf func(format string, args ...any), opts RegistryOptions) (*Registry, error)
OpenRegistry reads <home>/databases and records every registration as mounting, without mounting anything: call MountAll once the server listens. It never blocks on storage.
func (*Registry) Close ¶ added in v0.11.0
func (r *Registry) Close()
Close unmounts every database, releasing engine resources such as SQLite file handles, and removes mounts.json: without a server, mount state is unknown. Mounts still in flight are closed when they finish.
func (*Registry) Create ¶ added in v0.11.0
func (r *Registry) Create(request CreateRequest) (DatabaseResult, error)
Create registers, creates and mounts a new database without a restart. It never overwrites: a registered id is already_exists and a location in use is location_not_empty, both with nothing changed (database-setup-and-providers#REQ:create-never-overwrites).
func (*Registry) MountAll ¶ added in v0.11.0
MountAll mounts every registration still mounting, each with its own deadline and in parallel, and returns when all are settled or ctx ends (a server stopping while storage is unreachable). A database that fails, times out or whose storage is missing needs attention, with a redacted reason in status, mounts.json and server.log (local-server-and-web-console#REQ:registry-serving).
func (*Registry) Reload ¶ added in v0.11.0
Reload mounts database id again from its manifest, so an edited manifest (a SQLite schema, a fixed connection variable) or restored storage takes effect without restarting the server.
func (*Registry) ReloadAll ¶ added in v0.11.0
func (r *Registry) ReloadAll(ctx context.Context) (DatabasesDocument, error)
ReloadAll reloads every registration, picks up manifests added to <home>/databases by hand and forgets ones deleted by hand.
func (*Registry) Remove ¶ added in v0.11.0
Remove unregisters database id without deleting its data, and says where the data remains (database-setup-and-providers#REQ:list-and-remove). The manifest goes first, so a failure leaves the database registered and served; the drain of in-flight requests happens without the registry lock, so status and lists never wait on it.
type RegistryOptions ¶ added in v0.11.0
RegistryOptions tune a registry; the zero value is the default.
type Server ¶
type Server struct {
State string `json:"state"`
Address string `json:"address"`
FallbackAddress string `json:"fallback_address"`
Port int `json:"port"`
Version string `json:"version,omitempty"`
PID int `json:"pid,omitempty"`
StartedAt *time.Time `json:"started_at,omitempty"`
Log string `json:"log"`
}
Server describes the local OVDB server in status and server documents. It carries no uptime: a start time keeps two reads of the same server byte-identical, and presentations format the uptime from it.
func RunningServer ¶
RunningServer describes the server recorded in record.
type ServerConfig ¶
type ServerConfig struct {
Port int `yaml:"port,omitempty" json:"port,omitempty"`
CORS []string `yaml:"cors,omitempty" json:"cors,omitempty"`
}
ServerConfig is the server section of config.yaml.
type ServerDocument ¶
type ServerDocument struct {
Schema int `json:"schema"`
Server Server `json:"server"`
Next []envelope.Next `json:"next"`
}
ServerDocument is the body of GET /api/local/v1/server and the --json output of `ovdb server start|stop|restart|status`. Next holds the commands that change the server's state, so every presentation shows the same ones (the web console cannot run them itself: parity E1 and E2).
func NewServerDocument ¶
func NewServerDocument(server Server) ServerDocument
NewServerDocument wraps server in its document.
type Status ¶
type Status struct {
Schema int `json:"schema"`
Version string `json:"version"`
Locations paths.Dirs `json:"locations"`
Server Server `json:"server"`
Databases []Database `json:"databases"`
// Context is the database and path that apply where the client runs
// (capability 14); null when none does.
Context *dbcontext.Context `json:"context"`
Next []envelope.Next `json:"next"`
}
Status is the body of GET /api/local/v1/status and of `ovdb status --json` (first-run-onboarding#REQ:status-command). Later increments add databases, context, demo, skills and telemetry as they are implemented.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package dbcontext is the one resolver for "which database and path does this command act on" (decision 0008, spec/features/database-context-navigation REQ:use-sets-scoped-context and REQ:context-lookup).
|
Package dbcontext is the one resolver for "which database and path does this command act on" (decision 0008, spec/features/database-context-navigation REQ:use-sets-scoped-context and REQ:context-lookup). |