entity

package
v0.19.2 Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package entity exposes shared entity types used in the public wick contract (tool/job registration). Most entity types stay in internal/entity — only the bits downstream authors touch live here.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MapToStruct added in v0.13.0

func MapToStruct(m map[string]string, dst any)

MapToStruct fills dst (pointer to struct) from m using each field's wick tag. key= picks the map key; default= is used when the map value is empty or absent. Fields without a wick tag or key are ignored.

Types

type Config

type Config struct {
	Owner         string `gorm:"primaryKey;type:varchar(64);default:''"`
	Key           string `gorm:"primaryKey;type:varchar(64)"`
	Value         string `gorm:"type:text"`
	Type          string `gorm:"type:varchar(16);default:'text'"`
	Options       string `gorm:"type:text"`
	IsSecret      bool   `gorm:"default:false"`
	CanRegenerate bool   `gorm:"default:false"`
	Locked        bool   `gorm:"default:false"`
	Required      bool   `gorm:"default:false"`
	Description   string `gorm:"type:text"`
	UpdatedAt     time.Time
	// Hidden is set from the `wick:"hidden"` tag at seed time. Not persisted
	// (gorm:"-") — tells the manager Settings page to skip this row. Hidden
	// configs are still seeded to DB so runtime reads work normally.
	//
	// JSON-exposed (omitempty) so the SPA inspector / workflow editor
	// receives the same presentation hint the templ admin page already
	// uses. Pure UI flag — no secret material here.
	Hidden bool `gorm:"-" json:"hidden,omitempty"`
	// ColOptions holds per-column select options for kvlist rows. Not persisted.
	// Key = column name; Value = pipe-separated "label::value" pairs (or just
	// "value" when label == value). The kvlist component renders a <select>
	// instead of <input> for columns that have options set.
	ColOptions map[string]string `gorm:"-" json:"col_options,omitempty"`
	// VisibleWhen is a "<otherField>:<value>" predicate sourced from the
	// `wick:"visible_when=..."` tag. When set, the admin UI shows this row
	// only while the named field's current value equals <value>. Not
	// persisted — pure presentation hint.
	VisibleWhen string `gorm:"-" json:"visible_when,omitempty"`
	// Mode locks the workflow editor's Fixed ⇄ Expression toggle for this
	// field, sourced from the `wick:"mode=fixed"` / `wick:"mode=expression"`
	// tag. Empty = operator chooses freely (toggle enabled, defaults to
	// fixed). "fixed" or "expression" = toggle greyed out, forced to that
	// mode. Pure presentation hint for the SPA workflow inspector — the
	// admin Settings page (templ) does not render a mode toggle. Not
	// persisted.
	Mode string `gorm:"-" json:"mode,omitempty"`
	// EnvOverride names the environment variable currently overriding
	// this row's value. Set by Service.ListOwned when the operator has
	// exported an env var declared in configs.envOverrides — the UI
	// renders a badge + disables the input, and Set() rejects writes
	// while the override is live. Empty when no override is active.
	EnvOverride string `gorm:"-" json:"env_override,omitempty"`
}

Config is one row in the runtime-editable KV config table (legacy name: `app_variables`). Wick reconciles two sources into this table at boot:

  • app-level defaults declared in internal/configs/spec.go (Owner == "", for session_secret / app_url / app_name)
  • per-module Config structs passed to app.RegisterTool. Framework reflects the typed struct + `wick:"..."` tags into rows via StructToConfigs, with Owner == Meta.Key stamped at boot.

The composite primary key (Owner, Key) lets the same Key repeat across scopes without collision (every tool can have its own "api_key", for example).

Type drives which widget the admin UI renders:

text (default), textarea, dropdown, number, checkbox,
email, url, color, date, datetime,
kvlist (editable table; Options = pipe-separated column names)

Options is pipe-separated (`a|b|c`). For "dropdown" it holds option values; for "kvlist" it holds column names (e.g. "id|name"). Value for kvlist rows is a JSON array of string-keyed objects.

func StructToConfigs

func StructToConfigs(cfg any) []Config

StructToConfigs reflects a typed per-module Config struct into a slice of Config rows ready for reconciliation. Each exported field with a non-empty `wick:"..."` tag becomes one row.

Field name → Key: CamelCase → snake_case (InitText → init_text), unless overridden by `key=...` in the tag.

Field type → widget:

bool   → "checkbox"
int*   → "number"
string → "text" (or whatever tag flag says: textarea, dropdown,
                 email, url, color, date, datetime)

Field value → seed Value. Zero values are written as empty string for string fields, "0" for int fields, "false" for bool fields — reconcile then either inserts the row or preserves the existing DB value.

Fields without a `wick` tag are ignored, so Config structs can hold internal state that should not become a row.

func (Config) TableName

func (Config) TableName() string

type ToolVisibility

type ToolVisibility string

ToolVisibility controls who can access a tool.

const (
	VisibilityPublic  ToolVisibility = "public"  // no login needed
	VisibilityPrivate ToolVisibility = "private" // login + approved (optionally filtered by tags)
)

Jump to

Keyboard shortcuts

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