Documentation
¶
Index ¶
- Constants
- func Validate() func(*ReadOptions)
- func ValidateCollectionID(id string) error
- func ValidateColumnType(ct ColumnType) error
- type ChangeKind
- type ChangedFile
- type CollectionDef
- type CollectionReadmeDef
- type CollectionsReader
- type ColumnDef
- type ColumnDefWithID
- type ColumnType
- type Definition
- type DiscordDef
- type EmailDef
- type GitHubActionDef
- type GitLabCIDef
- type HandlerBase
- type MaterializeResult
- type NtfyDef
- type ProgressEvent
- type ProgressKind
- type RSSDef
- type ReadOption
- type ReadOptions
- type RecordEntry
- type RecordFileDef
- type RecordFormat
- type RecordType
- type RecordsReader
- type SMSDef
- type Scanner
- type SearchIndexDef
- type Severity
- type SlackDef
- type SubscriberDef
- type SubscriberFor
- type TelegramDef
- type TriggerDef
- type TriggerEventType
- type TriggerJobDef
- type TriggerStepDef
- type ValidationError
- type ValidationResult
- type ViewDef
- type WebhookDef
- type WhatsAppDef
Constants ¶
const CollectionDefFileName = "definition.yaml"
CollectionDefFileName is the fixed file name for collection definitions inside the SchemaDir directory.
const SchemaDir = ".collection"
Variables ¶
This section is empty.
Functions ¶
func Validate ¶
func Validate() func(*ReadOptions)
func ValidateCollectionID ¶ added in v0.13.0
ValidateCollectionID validates a full collection ID. Allowed characters are alphanumeric and dot; ID must start/end with alphanumeric.
func ValidateColumnType ¶
func ValidateColumnType(ct ColumnType) error
Types ¶
type ChangeKind ¶ added in v0.8.0
type ChangeKind string
ChangeKind describes how a file changed between two git refs.
const ( ChangeKindAdded ChangeKind = "added" ChangeKindModified ChangeKind = "modified" ChangeKindDeleted ChangeKind = "deleted" ChangeKindRenamed ChangeKind = "renamed" )
type ChangedFile ¶ added in v0.8.0
type ChangedFile struct {
Kind ChangeKind
Path string // repo-relative path
OldPath string // set only for ChangeKindRenamed
}
ChangedFile is one file that differed between two git refs.
type CollectionDef ¶
type CollectionDef struct {
ID string `json:"-"` // Taken from dir name
DirPath string `yaml:"-" json:"-"`
Titles map[string]string `yaml:"titles,omitempty"`
RecordFile *RecordFileDef `yaml:"record_file"`
DataDir string `yaml:"data_dir,omitempty"`
Columns map[string]*ColumnDef `yaml:"columns"`
ColumnsOrder []string `yaml:"columns_order,omitempty"`
DefaultView string `yaml:"default_view,omitempty"`
// SubCollections are not part of the collection definition file,
// they are stored in the "subcollections" subdirectory as directories,
// each containing their own .collection/definition.yaml.
SubCollections map[string]*CollectionDef `yaml:"-" json:"-"`
// Views are not part of the collection definition file,
// they are stored in the "views" subdirectory.
Views map[string]*ViewDef `yaml:"-" json:"-"`
Readme *CollectionReadmeDef `yaml:"readme,omitempty" json:"readme,omitempty"`
}
func (*CollectionDef) Validate ¶
func (v *CollectionDef) Validate() error
type CollectionReadmeDef ¶ added in v0.28.0
type CollectionReadmeDef struct {
HideColumns bool `yaml:"hide_columns,omitempty" json:"hide_columns,omitempty"`
HideSubcollections bool `yaml:"hide_subcollections,omitempty" json:"hide_subcollections,omitempty"`
HideViews bool `yaml:"hide_views,omitempty" json:"hide_views,omitempty"`
HideTriggers bool `yaml:"hide_triggers,omitempty" json:"hide_triggers,omitempty"`
DataPreview *ViewDef `yaml:"data_preview,omitempty" json:"data_preview,omitempty"`
}
func (*CollectionReadmeDef) Validate ¶ added in v0.28.0
func (r *CollectionReadmeDef) Validate() error
type CollectionsReader ¶ added in v0.8.0
type CollectionsReader interface {
ReadDefinition(dbPath string, opts ...ReadOption) (*Definition, error)
}
CollectionsReader loads the full database definition from disk. The default implementation wraps validator.ReadDefinition.
type ColumnDef ¶
type ColumnDef struct {
Type ColumnType `yaml:"type"`
Title string `yaml:"title,omitempty"`
Titles map[string]string `yaml:"titles,omitempty"`
ValueTitle string `yaml:"valueTitle,omitempty"`
Required bool `yaml:"required,omitempty"`
Length int `yaml:"length,omitempty"`
MinLength int `yaml:"min_length,omitempty"`
MaxLength int `yaml:"max_length,omitempty"`
ForeignKey string `yaml:"foreign_key,omitempty"`
// Locale pairs this column with a map[locale]string column named <this_column_name>+"s".
// For example, column "title" with locale "en" is paired with column "titles".
// When reading, the locale value is extracted from the pair column and exposed as this column.
// When writing, this column is stored as-is in the file; if the pair column contains an entry
// for the primary locale key, that entry is promoted here and removed from the pair column.
Locale string `yaml:"locale,omitempty"`
}
type ColumnDefWithID ¶
type ColumnType ¶
type ColumnType string
const ( ColumnTypeL10N ColumnType = "map[locale]string" ColumnTypeString ColumnType = "string" ColumnTypeInt ColumnType = "int" ColumnTypeFloat ColumnType = "float" ColumnTypeBool ColumnType = "bool" ColumnTypeDate ColumnType = "date" ColumnTypeTime ColumnType = "time" ColumnTypeDateTime ColumnType = "datetime" ColumnTypeAny ColumnType = "any" )
type Definition ¶
type Definition struct {
Collections map[string]*CollectionDef `yaml:"collections,omitempty"`
Subscribers map[string]*SubscriberDef `yaml:"subscribers,omitempty"`
}
type DiscordDef ¶ added in v0.24.3
type DiscordDef struct {
HandlerBase `yaml:",inline"`
WebhookURL string `yaml:"webhook_url"`
}
DiscordDef represents a Discord webhook subscriber handler
func (*DiscordDef) Validate ¶ added in v0.24.3
func (d *DiscordDef) Validate() error
type EmailDef ¶ added in v0.24.3
type EmailDef struct {
HandlerBase `yaml:",inline"`
From string `yaml:"from,omitempty"`
To []string `yaml:"to"`
SMTP string `yaml:"smtp"`
Port int `yaml:"port,omitempty"`
User string `yaml:"user,omitempty"`
Pass string `yaml:"pass,omitempty"`
Subject string `yaml:"subject,omitempty"`
}
EmailDef represents an email subscriber handler via SMTP
type GitHubActionDef ¶ added in v0.24.3
type GitHubActionDef struct {
HandlerBase `yaml:",inline"`
Owner string `yaml:"owner"`
Repo string `yaml:"repo"`
Workflow string `yaml:"workflow"`
Ref string `yaml:"ref"`
Token string `yaml:"token"`
}
GitHubActionDef represents a GitHub Actions workflow_dispatch subscriber handler
func (*GitHubActionDef) Validate ¶ added in v0.24.3
func (d *GitHubActionDef) Validate() error
type GitLabCIDef ¶ added in v0.24.3
type GitLabCIDef struct {
HandlerBase `yaml:",inline"`
ProjectID string `yaml:"project_id"`
Ref string `yaml:"ref"`
Token string `yaml:"token"`
Host string `yaml:"host,omitempty"`
}
GitLabCIDef represents a GitLab CI pipeline trigger subscriber handler
func (*GitLabCIDef) Validate ¶ added in v0.24.3
func (d *GitLabCIDef) Validate() error
type HandlerBase ¶ added in v0.24.3
type HandlerBase struct {
Name string `yaml:"name,omitempty"`
}
HandlerBase contains common fields for all subscriber handlers
type MaterializeResult ¶ added in v0.8.0
MaterializeResult summarises the outcome of a materialisation run.
type NtfyDef ¶ added in v0.24.3
type NtfyDef struct {
HandlerBase `yaml:",inline"`
Topic string `yaml:"topic"`
Server string `yaml:"server,omitempty"`
}
NtfyDef represents a ntfy.sh push notification subscriber handler
type ProgressEvent ¶ added in v0.8.0
type ProgressEvent struct {
Kind ProgressKind
TaskName string // "validate" or "materialize"
Scope string // collection or view ID
ItemKey string // record key or output file name
Done int // items completed so far
Total int // total items; 0 = unknown
Err *ValidationError // non-nil only for ProgressKindError
}
ProgressEvent carries one progress update from a running task.
type ProgressKind ¶ added in v0.8.0
type ProgressKind string
ProgressKind describes the type of progress update.
const ( ProgressKindStarted ProgressKind = "started" ProgressKindItemDone ProgressKind = "item_done" ProgressKindSkipped ProgressKind = "skipped" ProgressKindCompleted ProgressKind = "completed" ProgressKindAborted ProgressKind = "aborted" ProgressKindError ProgressKind = "error" )
type RSSDef ¶ added in v0.24.3
type RSSDef struct {
HandlerBase `yaml:",inline"`
Output string `yaml:"output"`
Title string `yaml:"title"`
Link string `yaml:"link"`
Format string `yaml:"format,omitempty"`
}
RSSDef represents an RSS or Atom feed generator subscriber handler
type ReadOption ¶
type ReadOption func(*ReadOptions)
type ReadOptions ¶
type ReadOptions struct {
// contains filtered or unexported fields
}
func NewReadOptions ¶
func NewReadOptions(o ...ReadOption) (opts ReadOptions)
func (*ReadOptions) IsValidationRequired ¶
func (o *ReadOptions) IsValidationRequired() bool
type RecordEntry ¶ added in v0.8.0
type RecordEntry struct {
Key string // may be empty for list-type files
FilePath string // absolute path
Data map[string]any
}
RecordEntry is one parsed record with its location on disk.
type RecordFileDef ¶
type RecordFileDef struct {
Name string `yaml:"name"`
Format RecordFormat `yaml:"format"`
// RecordType can have next values:
// "map[string]any" - each record in a separate file
// "[]map[string]any" - list of records
// "map[string]map[string]any" - dictionary of records
// "map[id]map[field]any" - all records in one file; top-level keys are record IDs, second level is field names
RecordType RecordType `yaml:"type"`
}
func (RecordFileDef) GetRecordFileName ¶
func (rfd RecordFileDef) GetRecordFileName(record dal.Record) string
func (RecordFileDef) Validate ¶
func (rfd RecordFileDef) Validate() error
type RecordFormat ¶
type RecordFormat string
type RecordType ¶
type RecordType string
const ( SingleRecord RecordType = "map[string]any" ListOfRecords RecordType = "[]map[string]any" MapOfRecords RecordType = "map[string]map[string]any" MapOfIDRecords RecordType = "map[id]map[field]any" )
type RecordsReader ¶ added in v0.8.0
type RecordsReader interface {
ReadRecords(
ctx context.Context,
dbPath string,
col *CollectionDef,
yield func(RecordEntry) error,
) error
}
RecordsReader streams records from one collection. Uses a yield callback to avoid goroutine leaks and keep allocation low.
type SMSDef ¶ added in v0.24.3
type SMSDef struct {
HandlerBase `yaml:",inline"`
Provider string `yaml:"provider"`
From string `yaml:"from"`
To string `yaml:"to"`
AccountSID string `yaml:"account_sid,omitempty"`
AuthToken string `yaml:"auth_token"`
APIKey string `yaml:"api_key,omitempty"`
}
SMSDef represents an SMS subscriber handler via Twilio or Vonage
type Scanner ¶ added in v0.8.0
type Scanner interface {
// Scan walks dbPath, validates all records, and rebuilds all views.
Scan(ctx context.Context, dbPath string, def *Definition) error
}
Scanner orchestrates the full pipeline: walk filesystem, invoke Validator and ViewBuilder.
type SearchIndexDef ¶ added in v0.24.3
type SearchIndexDef struct {
HandlerBase `yaml:",inline"`
Provider string `yaml:"provider"`
Index string `yaml:"index"`
AppID string `yaml:"app_id,omitempty"`
APIKey string `yaml:"api_key"`
Host string `yaml:"host,omitempty"`
}
SearchIndexDef represents a search index sync subscriber handler
func (*SearchIndexDef) Validate ¶ added in v0.24.3
func (d *SearchIndexDef) Validate() error
type SlackDef ¶ added in v0.24.3
type SlackDef struct {
HandlerBase `yaml:",inline"`
WebhookURL string `yaml:"webhook_url"`
}
SlackDef represents a Slack incoming webhook subscriber handler
type SubscriberDef ¶ added in v0.24.3
type SubscriberDef struct {
HandlerBase `yaml:",inline"`
For *SubscriberFor `yaml:"for"`
Webhooks []WebhookDef `yaml:"webhooks,omitempty"`
Emails []EmailDef `yaml:"emails,omitempty"`
Telegrams []TelegramDef `yaml:"telegrams,omitempty"`
WhatsApp []WhatsAppDef `yaml:"whatsapp,omitempty"`
Slacks []SlackDef `yaml:"slacks,omitempty"`
Discords []DiscordDef `yaml:"discords,omitempty"`
GitHubActions []GitHubActionDef `yaml:"github_actions,omitempty"`
GitLabCI []GitLabCIDef `yaml:"gitlab_ci,omitempty"`
Ntfy []NtfyDef `yaml:"ntfy,omitempty"`
SMS []SMSDef `yaml:"sms,omitempty"`
SearchIndexes []SearchIndexDef `yaml:"search_indexes,omitempty"`
RSS []RSSDef `yaml:"rss,omitempty"`
}
SubscriberDef represents a single subscriber configuration block
func (*SubscriberDef) Validate ¶ added in v0.24.3
func (s *SubscriberDef) Validate() error
type SubscriberFor ¶ added in v0.24.3
type SubscriberFor struct {
Paths []string `yaml:"paths,omitempty"`
Events []TriggerEventType `yaml:"events,omitempty"`
}
SubscriberFor represents the selector for when a subscriber group should be triggered
func (*SubscriberFor) Validate ¶ added in v0.24.3
func (s *SubscriberFor) Validate() error
type TelegramDef ¶ added in v0.24.3
type TelegramDef struct {
HandlerBase `yaml:",inline"`
Token string `yaml:"token"`
ChatID string `yaml:"chat_id"`
}
TelegramDef represents a Telegram subscriber handler
func (*TelegramDef) Validate ¶ added in v0.24.3
func (d *TelegramDef) Validate() error
type TriggerDef ¶ added in v0.23.0
type TriggerDef struct {
On []TriggerEventType `yaml:"on"`
Jobs map[string]*TriggerJobDef `yaml:"jobs"`
}
TriggerDef is the schema for a trigger workflow file (.collection/trigger_<name>.yaml). Modelled after GitHub Actions workflow syntax.
type TriggerEventType ¶ added in v0.23.0
type TriggerEventType string
TriggerEventType is the lifecycle event that fires a trigger.
const ( TriggerEventCreated TriggerEventType = "created" TriggerEventUpdated TriggerEventType = "updated" TriggerEventDeleted TriggerEventType = "deleted" )
type TriggerJobDef ¶ added in v0.23.0
type TriggerJobDef struct {
RunsOn string `yaml:"runs-on"`
Steps []TriggerStepDef `yaml:"steps"`
}
TriggerJobDef is one job inside a trigger workflow. RunsOn must be "." (run in the same environment as ingitdb itself).
type TriggerStepDef ¶ added in v0.23.0
type TriggerStepDef struct {
Run string `yaml:"run"`
}
TriggerStepDef is a single shell step within a trigger job.
type ValidationError ¶ added in v0.8.0
type ValidationError struct {
Severity Severity
CollectionID string // e.g. "todo.tasks"
FilePath string // absolute path to offending file
RecordKey string // empty for list/map files where key is unknown
FieldName string // set for field-level errors
Message string
Err error // wrapped cause
}
ValidationError is one finding from data validation. All location fields (CollectionID…FieldName) are optional. Implements error.
func (ValidationError) Error ¶ added in v0.8.0
func (v ValidationError) Error() string
Error implements the error interface.
type ValidationResult ¶ added in v0.8.0
type ValidationResult struct {
// contains filtered or unexported fields
}
ValidationResult aggregates findings; mutex-protected for goroutine safety.
func (*ValidationResult) Append ¶ added in v0.8.0
func (r *ValidationResult) Append(e ValidationError)
Append adds a finding to the result.
func (*ValidationResult) ErrorCount ¶ added in v0.8.0
func (r *ValidationResult) ErrorCount() int
ErrorCount returns the total number of recorded findings.
func (*ValidationResult) Errors ¶ added in v0.8.0
func (r *ValidationResult) Errors() []ValidationError
Errors returns a snapshot copy of all findings.
func (*ValidationResult) Filter ¶ added in v0.8.0
func (r *ValidationResult) Filter(fn func(ValidationError) bool) []ValidationError
Filter returns findings that match the given predicate.
func (*ValidationResult) HasErrors ¶ added in v0.8.0
func (r *ValidationResult) HasErrors() bool
HasErrors reports whether any findings have been recorded.
type ViewDef ¶
type ViewDef struct {
ID string `yaml:"-"`
Titles map[string]string `yaml:"titles,omitempty"`
OrderBy string `yaml:"order_by,omitempty"`
// Formats TODO: Needs definition
Formats []string `yaml:"formats,omitempty"`
Columns []string `yaml:"columns,omitempty"`
// How many records to include; 0 means all
Top int `yaml:"top,omitempty"`
// Where holds filtering condition
Where string `yaml:"where,omitempty"`
// Template path relative to the collection directory.
/*
Build in templates:
- md-table - renders a Markdown table
- md-list - renders a Markdown list
- JSON - renders JSON
- YAML - renders YAML
*/
Template string `yaml:"template,omitempty"`
// Output file name relative to the collection directory.
FileName string `yaml:"file_name,omitempty"`
// RecordsVarName provides a custom Template variable name for the records slice. The default is "records".
RecordsVarName string `yaml:"records_var_name,omitempty"`
}
type WebhookDef ¶ added in v0.24.3
type WebhookDef struct {
HandlerBase `yaml:",inline"`
URL string `yaml:"url"`
Method string `yaml:"method,omitempty"`
Headers map[string]string `yaml:"headers,omitempty"`
}
WebhookDef represents a webhook subscriber handler
func (*WebhookDef) Validate ¶ added in v0.24.3
func (d *WebhookDef) Validate() error
type WhatsAppDef ¶ added in v0.24.3
type WhatsAppDef struct {
HandlerBase `yaml:",inline"`
From string `yaml:"from"`
To string `yaml:"to"`
AccountSID string `yaml:"account_sid"`
AuthToken string `yaml:"auth_token"`
}
WhatsAppDef represents a WhatsApp Business API subscriber handler
func (*WhatsAppDef) Validate ¶ added in v0.24.3
func (d *WhatsAppDef) Validate() error