demo

package
v0.35.0 Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2026 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Package demo is the built-in TODO demo service (spec/features/todo-demo, decision 0010): two lists, To buy and To watch, in a schemaless inGitDB database registered as `todo` at <data home>/demos/todo, and the documents `ovdb demo install|open|status`, the TUI, the web console and the TODO app render.

Installing goes through the registry like any create and seeds the lists through the data API, so the demo's files are exactly what an app writing the same records would produce. It never overwrites: a demo already installed is reported as such, and a conflicting `todo` database or a folder with other files is refused with a --id to use instead.

Index

Constants

View Source
const (
	// App is the demo name commands default to, leaving room for
	// `--app <name>` (REQ:demo-command-shape).
	App = "todo"
	// DefaultID is the database id the demo installs as.
	DefaultID = setup.DemoDefaultID
	// AppPath is the TODO app on the local server (REQ:todo-app-same-origin).
	AppPath = "/apps/todo/"
)

The TODO demo's fixed names.

View Source
const (
	// ActionOpenApp opens the TODO app signed in.
	ActionOpenApp = "open_app"
	// ActionInstall installs the demo.
	ActionInstall = "install_demo"
)

Next actions presentations act on in place (envelope.Next.Action).

View Source
const ActionExplore = "explore"

ActionExplore opens Explore data for the demo database (increment 7).

Variables

View Source
var Lists = leadingSlash(todo.Lists)

Lists are the demo's list paths, in the order apps show them: todo.Lists (github.com/ingitdb/ingitdb-go/ingitdb/demos/todo), the shared TODO demo records package, with a leading slash.

Functions

func Find

func Find(home string, databases []setup.Database) (setup.Database, bool)

Find is the installed demo among databases: the registered database a demo install recorded in OVDB home, never one that merely lives in a folder named demos.

func Location

func Location(dataHome, id string) string

Location is where database id keeps the demo under dataHome.

Types

type Document

type Document struct {
	Schema int    `json:"schema"`
	App    string `json:"app"`
	// Installed is true once the demo database is registered.
	Installed bool `json:"installed"`
	// AlreadyInstalled is set on an install that changed nothing.
	AlreadyInstalled bool `json:"already_installed,omitempty"`
	// Database is the demo database id; empty until installed.
	Database string `json:"database,omitempty"`
	// Location is where the demo's files are, or will be once installed.
	Location string `json:"location"`
	// State is the database's mount state once installed.
	State string `json:"state,omitempty"`
	// AppPath is the TODO app's path on the local server.
	AppPath string          `json:"app_path"`
	Lists   []string        `json:"lists"`
	Next    []envelope.Next `json:"next"`
}

Document is the body of GET /api/local/v1/demo, of POST /api/local/v1/demo/install, and the --json output of `ovdb demo status` and `ovdb demo install`.

func Inspect

func Inspect(dirs paths.Dirs, databases []setup.Database) Document

Inspect is the demo document for the registered databases, with the default location under the data home when the demo is not installed.

type InstallRequest

type InstallRequest struct {
	ID   string `json:"id,omitempty"`
	Path string `json:"path,omitempty"`
}

InstallRequest is the body of POST /api/local/v1/demo/install. Both fields are optional: ID defaults to todo, Path to <data home>/demos/<id> under the data home the client resolved (the server's own when the web console asks).

type Op

type Op struct {
	Path string         `json:"key"`
	Data map[string]any `json:"data"`
}

Op is one record the seed writes: an absolute escaped path and its data.

type Registry

type Registry interface {
	Create(request setup.CreateRequest) (setup.DatabaseResult, error)
	Reconnect(request setup.CreateRequest) (setup.DatabaseResult, error)
	Remove(ctx context.Context, id string) (setup.DatabaseResult, error)
	List() ([]setup.Database, error)
}

Registry is the part of setup.Registry installing uses.

type Seeder

type Seeder func(ctx context.Context, id string, ops []Op) error

Seeder writes ops to database id in one batch through the data API.

type Service

type Service struct {
	Dirs     paths.Dirs
	Registry Registry
	Seed     Seeder
	Now      func() time.Time // time.Now when nil
	Logf     func(format string, args ...any)
	// contains filtered or unexported fields
}

Service installs the demo on a running server. Only the server holding home.lock owns one, and every client (CLI, TUI, web console, agents) installs through it, so its mutex serialises every install for the home.

func (*Service) Install

func (s *Service) Install(ctx context.Context, request InstallRequest) (Document, error)

Install registers the demo database, writes the seed lists, records the install, and returns the installed demo (REQ:demo-install-idempotent). An installed demo is reported with AlreadyInstalled and nothing written. Installs run one at a time, so one that finds the demo installed returns only once its lists exist.

Jump to

Keyboard shortcuts

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