Documentation
¶
Overview ¶
Package source provides data source implementations for lvt-source blocks.
Package source provides data source implementations for lvt-source blocks.
Package source provides data source implementations for lvt-source blocks. Sources fetch data from external systems (exec, databases, APIs) and make it available to templates.
Index ¶
- Constants
- func AddIDsToItems(content string) (string, bool)
- func EnsureUniqueIDs(content string) (string, bool)
- func InputTypeForColumn(colType string) string
- func ReferencedParams(statements ...string) []string
- func RunSQLAction(ctx context.Context, executor SQLExecutor, action *config.Action, ...) error
- func ScanMarkdownForIDs(content string) []string
- func SubstituteParams(stmt string, data map[string]interface{}) (string, []interface{}, error)
- func UserFriendlyMessage(err error) string
- func WithRetry(ctx context.Context, source string, cfg RetryConfig, fn RetryableFunc) ([]map[string]interface{}, error)
- type CSVFileSource
- type CacheInfoProvider
- type CachedSource
- type CachedWritableSource
- type CircuitBreaker
- type CircuitBreakerConfig
- type CircuitOpenError
- type CircuitState
- type ColumnInfo
- type ComputedSource
- type ConflictError
- type ConnectionError
- type ExecSource
- type Followable
- type GraphQLError
- type GraphQLSource
- type HTTPError
- type JSONFileSource
- type MarkdownSource
- func (s *MarkdownSource) Close() error
- func (s *MarkdownSource) Fetch(ctx context.Context) ([]map[string]interface{}, error)
- func (s *MarkdownSource) GetAnchor() string
- func (s *MarkdownSource) GetFilePath() string
- func (s *MarkdownSource) IsReadonly() bool
- func (s *MarkdownSource) Name() string
- func (s *MarkdownSource) WriteItem(ctx context.Context, action string, data map[string]interface{}) error
- type MarkdownSourceParser
- type Page
- type PostgresSource
- type QuerySetter
- type Registry
- type RestSource
- type RetryConfig
- type RetryableFunc
- type SQLExecutor
- type SQLStatement
- type SQLiteSource
- func (s *SQLiteSource) Close() error
- func (s *SQLiteSource) Exec(ctx context.Context, query string, args ...interface{}) (int64, error)
- func (s *SQLiteSource) ExecTx(ctx context.Context, stmts []SQLStatement) error
- func (s *SQLiteSource) Fetch(ctx context.Context) ([]map[string]interface{}, error)
- func (s *SQLiteSource) IsReadonly() bool
- func (s *SQLiteSource) Name() string
- func (s *SQLiteSource) Schema(ctx context.Context) ([]ColumnInfo, error)
- func (s *SQLiteSource) WriteItem(ctx context.Context, action string, data map[string]interface{}) error
- type SchemaProvider
- type Source
- type SourceError
- type StreamSource
- func (s *StreamSource) Close() error
- func (s *StreamSource) Fetch(ctx context.Context) ([]map[string]interface{}, error)
- func (s *StreamSource) FlushInterval() time.Duration
- func (s *StreamSource) Name() string
- func (s *StreamSource) SetQuery(q url.Values) bool
- func (s *StreamSource) Subscribe() *stream.Subscription
- type TimeoutError
- type UnsupportedSourceError
- type ValidationError
- type WritableSource
Constants ¶
const MergeParamIdle = 30 * time.Second
MergeParamIdle is how long a params merge's inputs run after the last page showing them leaves: each value opened starts its own commands.
Variables ¶
This section is empty.
Functions ¶
func AddIDsToItems ¶
AddIDsToItems adds ID comments to items that don't have them
func EnsureUniqueIDs ¶
EnsureUniqueIDs checks for duplicate IDs and generates new ones if needed
func InputTypeForColumn ¶
InputTypeForColumn returns the HTML input type for a given column type.
func ReferencedParams ¶ added in v0.4.0
ReferencedParams returns the distinct :name parameters referenced across the given statements, in first-seen order — the names a caller must supply for SubstituteParams to succeed.
func RunSQLAction ¶ added in v0.4.0
func RunSQLAction(ctx context.Context, executor SQLExecutor, action *config.Action, data map[string]interface{}) error
RunSQLAction executes a `kind: sql` action's statement(s) against executor.
It is the single place both the UI action path (internal/runtime) and the webhook path (internal/server) run a sql action, so the two cannot drift — the asymmetry that previously let `:operator` be injected on one path but not the other is impossible when both go through here. It:
- injects the operator identity so `:operator` resolves the same everywhere;
- substitutes `:name` placeholders via SubstituteParams;
- runs a `statements:` batch atomically via ExecTx (a single `statement:` via Exec). Config validation guarantees exactly one of the two is set.
The caller owns everything around execution — source lookup, timeouts, and any post-mutation refresh — this is only the execute step.
func ScanMarkdownForIDs ¶
ScanMarkdownForIDs scans a markdown file and returns all item IDs found
func SubstituteParams ¶ added in v0.4.0
SubstituteParams converts :name placeholders to positional args. Input: "DELETE FROM tasks WHERE id = :id", {"id": "123"} Output: "DELETE FROM tasks WHERE id = ?", ["123"] Returns an error if a parameter in the statement is not found in data.
Parameter names must start with a letter (a-z, A-Z) and can contain letters, digits, and underscores. This avoids false matches on: - Time literals like '12:30:00' (digits after colon) - Postgres casts like value::text (double colon)
func UserFriendlyMessage ¶
UserFriendlyMessage returns a user-friendly error message for templates
func WithRetry ¶
func WithRetry(ctx context.Context, source string, cfg RetryConfig, fn RetryableFunc) ([]map[string]interface{}, error)
WithRetry wraps a function with retry logic
Types ¶
type CSVFileSource ¶
type CSVFileSource struct {
// contains filtered or unexported fields
}
CSVFileSource reads data from a CSV file
func NewCSVFileSource ¶
func NewCSVFileSource(name, file, siteDir string, options map[string]string) (*CSVFileSource, error)
NewCSVFileSource creates a new CSV file source
func (*CSVFileSource) Close ¶
func (s *CSVFileSource) Close() error
Close is a no-op for file sources
func (*CSVFileSource) Fetch ¶
func (s *CSVFileSource) Fetch(ctx context.Context) ([]map[string]interface{}, error)
Fetch reads and parses the CSV file
func (*CSVFileSource) Name ¶
func (s *CSVFileSource) Name() string
Name returns the source identifier
type CacheInfoProvider ¶
CacheInfoProvider is implemented by sources that expose cache metadata
type CachedSource ¶
type CachedSource struct {
// contains filtered or unexported fields
}
CachedSource wraps a Source with caching behavior
func NewCachedSource ¶
func NewCachedSource(inner Source, c cache.Cache, cfg config.SourceConfig) *CachedSource
NewCachedSource creates a new cached source wrapper
func (*CachedSource) Close ¶
func (s *CachedSource) Close() error
Close closes the underlying source and cancels any background operations
func (*CachedSource) Fetch ¶
func (s *CachedSource) Fetch(ctx context.Context) ([]map[string]interface{}, error)
Fetch retrieves data, using cache if available
func (*CachedSource) GetCacheInfo ¶
func (s *CachedSource) GetCacheInfo() *cache.CacheInfo
GetCacheInfo returns cache metadata for UI display Implements CacheInfoProvider interface
func (*CachedSource) GetInner ¶
func (s *CachedSource) GetInner() Source
GetInner returns the underlying source This is useful for accessing WritableSource methods
func (*CachedSource) Invalidate ¶
func (s *CachedSource) Invalidate()
Invalidate removes this source's data from cache
type CachedWritableSource ¶
type CachedWritableSource struct {
*CachedSource
// contains filtered or unexported fields
}
CachedWritableSource wraps a WritableSource with caching behavior It invalidates the cache on write operations
func NewCachedWritableSource ¶
func NewCachedWritableSource(inner WritableSource, c cache.Cache, cfg config.SourceConfig) *CachedWritableSource
NewCachedWritableSource creates a new cached writable source wrapper
func (*CachedWritableSource) IsReadonly ¶
func (s *CachedWritableSource) IsReadonly() bool
IsReadonly returns whether the source is in read-only mode
type CircuitBreaker ¶
type CircuitBreaker struct {
// contains filtered or unexported fields
}
CircuitBreaker implements the circuit breaker pattern
func NewCircuitBreaker ¶
func NewCircuitBreaker(name string, config CircuitBreakerConfig) *CircuitBreaker
NewCircuitBreaker creates a new circuit breaker
func (*CircuitBreaker) Execute ¶
func (cb *CircuitBreaker) Execute(ctx context.Context, fn RetryableFunc) ([]map[string]interface{}, error)
Execute runs a function through the circuit breaker
func (*CircuitBreaker) Reset ¶
func (cb *CircuitBreaker) Reset()
Reset forces the circuit breaker to closed state
func (*CircuitBreaker) State ¶
func (cb *CircuitBreaker) State() CircuitState
State returns the current circuit state
type CircuitBreakerConfig ¶
type CircuitBreakerConfig struct {
FailureThreshold int // Number of failures to open circuit (default: 5)
SuccessThreshold int // Number of successes in half-open to close (default: 2)
Timeout time.Duration // Time to wait before half-open (default: 30s)
FailureWindow time.Duration // Window to count failures (default: 1 minute)
EnableLog bool // Whether to log state changes
}
CircuitBreakerConfig configures the circuit breaker
func DefaultCircuitBreakerConfig ¶
func DefaultCircuitBreakerConfig() CircuitBreakerConfig
DefaultCircuitBreakerConfig returns the default circuit breaker configuration
type CircuitOpenError ¶
type CircuitOpenError struct {
Source string
}
CircuitOpenError indicates the circuit breaker is open
func (*CircuitOpenError) Error ¶
func (e *CircuitOpenError) Error() string
type CircuitState ¶
type CircuitState int
CircuitState represents the state of a circuit breaker
const ( CircuitClosed CircuitState = iota // Normal operation, requests allowed CircuitOpen // Failures exceeded threshold, requests blocked CircuitHalfOpen // Testing if service recovered )
func (CircuitState) String ¶
func (s CircuitState) String() string
type ColumnInfo ¶
type ColumnInfo struct {
Name string // Column name (e.g., "amount")
Type string // Normalized type: "text", "integer", "real", "boolean", "date", "datetime"
Required bool // Whether the column is NOT NULL
}
ColumnInfo describes a column in a data source's schema.
func QuerySQLiteSchema ¶
func QuerySQLiteSchema(dbPath, table, siteDir string) []ColumnInfo
QuerySQLiteSchema opens a SQLite database and returns column info for the given table. This is a standalone function for use at parse time, before a full SQLiteSource is created.
Returns nil (no error) if the table doesn't exist or the DB can't be opened. This allows graceful degradation — auto-tables will use text inputs as fallback.
type ComputedSource ¶
type ComputedSource struct {
// contains filtered or unexported fields
}
ComputedSource derives data from another source by applying group_by and aggregate operations. It implements the Source interface (read-only).
Example config:
sources:
expenses:
type: sqlite
db: ./expenses.db
table: expenses
by_category:
type: computed
from: expenses
group_by: category
aggregate:
total: sum(amount)
count: count()
func NewComputedSource ¶
func NewComputedSource(name string, cfg config.SourceConfig, registry *Registry) (*ComputedSource, error)
NewComputedSource creates a computed source that derives data from a parent source. The parent source must already be registered in the registry.
func (*ComputedSource) Close ¶
func (s *ComputedSource) Close() error
func (*ComputedSource) Fetch ¶
func (s *ComputedSource) Fetch(ctx context.Context) ([]map[string]interface{}, error)
Fetch retrieves data from the parent source, applies optional filter, groups by the specified field, and computes aggregations per group.
func (*ComputedSource) Name ¶
func (s *ComputedSource) Name() string
type ConflictError ¶
ConflictError is returned when a write operation detects concurrent modification
func (*ConflictError) Error ¶
func (e *ConflictError) Error() string
type ConnectionError ¶
ConnectionError represents a connection failure
func (*ConnectionError) Error ¶
func (e *ConnectionError) Error() string
func (*ConnectionError) Unwrap ¶
func (e *ConnectionError) Unwrap() error
type ExecSource ¶
type ExecSource struct {
// contains filtered or unexported fields
}
ExecSource runs a command and parses output as data
func NewExecSource ¶
func NewExecSource(name, cmd, siteDir string) (*ExecSource, error)
NewExecSource creates a new exec source (legacy constructor for backwards compatibility)
func NewExecSourceWithConfig ¶
func NewExecSourceWithConfig(name string, cfg config.SourceConfig, siteDir string) (*ExecSource, error)
NewExecSourceWithConfig creates a new exec source from config
func (*ExecSource) Fetch ¶
func (s *ExecSource) Fetch(ctx context.Context) ([]map[string]interface{}, error)
Fetch executes the command and parses output according to format
func (*ExecSource) FetchWithArgs ¶
func (s *ExecSource) FetchWithArgs(ctx context.Context, args map[string]string) ([]map[string]interface{}, error)
FetchWithArgs executes the command with custom argument values The args map contains argument name -> value pairs that override the defaults
type Followable ¶ added in v0.5.0
type Followable interface {
Source
Subscribe() *stream.Subscription
FlushInterval() time.Duration
}
Followable is a source that grows on its own. The server subscribes to it and pushes new rows to the page at most every FlushInterval.
type GraphQLError ¶
GraphQLError represents an error returned by a GraphQL API
func (*GraphQLError) Error ¶
func (e *GraphQLError) Error() string
type GraphQLSource ¶
type GraphQLSource struct {
// contains filtered or unexported fields
}
GraphQLSource fetches data from a GraphQL API endpoint
func NewGraphQLSource ¶
func NewGraphQLSource(name string, cfg config.SourceConfig, siteDir string) (*GraphQLSource, error)
NewGraphQLSource creates a new GraphQL API source
func (*GraphQLSource) Close ¶
func (s *GraphQLSource) Close() error
Close is a no-op for GraphQL sources
func (*GraphQLSource) Fetch ¶
func (s *GraphQLSource) Fetch(ctx context.Context) ([]map[string]interface{}, error)
Fetch makes a GraphQL request and parses the response
func (*GraphQLSource) Name ¶
func (s *GraphQLSource) Name() string
Name returns the source identifier
type HTTPError ¶
HTTPError represents an HTTP error response
func (*HTTPError) IsRetryable ¶
IsRetryable returns true for 5xx errors and 429 (rate limit)
type JSONFileSource ¶
type JSONFileSource struct {
// contains filtered or unexported fields
}
JSONFileSource reads data from a JSON file
func NewJSONFileSource ¶
func NewJSONFileSource(name, file, siteDir string) (*JSONFileSource, error)
NewJSONFileSource creates a new JSON file source
func (*JSONFileSource) Close ¶
func (s *JSONFileSource) Close() error
Close is a no-op for file sources
func (*JSONFileSource) Fetch ¶
func (s *JSONFileSource) Fetch(ctx context.Context) ([]map[string]interface{}, error)
Fetch reads and parses the JSON file
func (*JSONFileSource) Name ¶
func (s *JSONFileSource) Name() string
Name returns the source identifier
type MarkdownSource ¶
type MarkdownSource struct {
// contains filtered or unexported fields
}
MarkdownSource reads data from markdown sections (task lists, bullet lists, tables)
func NewMarkdownSource ¶
func NewMarkdownSource(name, file, anchor, siteDir, currentFile string, readonly bool) (*MarkdownSource, error)
NewMarkdownSource creates a new markdown source
func (*MarkdownSource) Close ¶
func (s *MarkdownSource) Close() error
Close is a no-op for file sources
func (*MarkdownSource) Fetch ¶
func (s *MarkdownSource) Fetch(ctx context.Context) ([]map[string]interface{}, error)
Fetch reads and parses the markdown section
func (*MarkdownSource) GetAnchor ¶
func (s *MarkdownSource) GetAnchor() string
GetAnchor returns the section anchor
func (*MarkdownSource) GetFilePath ¶
func (s *MarkdownSource) GetFilePath() string
GetFilePath returns the resolved file path for file watching
func (*MarkdownSource) IsReadonly ¶
func (s *MarkdownSource) IsReadonly() bool
IsReadonly returns whether the source is read-only
func (*MarkdownSource) Name ¶
func (s *MarkdownSource) Name() string
Name returns the source identifier
func (*MarkdownSource) WriteItem ¶
func (s *MarkdownSource) WriteItem(ctx context.Context, action string, data map[string]interface{}) error
WriteItem adds, updates, or deletes an item in the markdown source Supported actions: add, toggle, delete, update Returns ConflictError if the file was modified externally since last read
type MarkdownSourceParser ¶
type MarkdownSourceParser struct{}
MarkdownSourceParser provides utilities for parsing markdown data sections Used by the code generator to inline parsing logic
func (*MarkdownSourceParser) ParseContent ¶
func (p *MarkdownSourceParser) ParseContent(content, anchor string) ([]map[string]interface{}, error)
ParseContent parses markdown content and returns structured data
type Page ¶ added in v0.7.0
type Page struct {
Query url.Values
Resolve func(name string) (config.SourceConfig, bool)
InputLookup func(merge string) func(string) (config.SourceConfig, bool)
}
Page is what a gated merge needs from the page showing it: the query its params come from, and how the page resolves a gate merge and that merge's inputs. A gate built the way the gate's own block is built shares its buffer, so the gate's commands run once.
type PostgresSource ¶
type PostgresSource struct {
// contains filtered or unexported fields
}
PostgresSource executes queries against a PostgreSQL database
func NewPostgresSource ¶
func NewPostgresSource(name, query string, options map[string]string) (*PostgresSource, error)
NewPostgresSource creates a new PostgreSQL source
func NewPostgresSourceWithConfig ¶
func NewPostgresSourceWithConfig(name, query string, options map[string]string, cfg config.SourceConfig) (*PostgresSource, error)
NewPostgresSourceWithConfig creates a new PostgreSQL source with full configuration
func (*PostgresSource) Close ¶
func (s *PostgresSource) Close() error
Close releases the database connection
func (*PostgresSource) Fetch ¶
func (s *PostgresSource) Fetch(ctx context.Context) ([]map[string]interface{}, error)
Fetch executes the query and returns results with retry and circuit breaker
func (*PostgresSource) Name ¶
func (s *PostgresSource) Name() string
Name returns the source identifier
type QuerySetter ¶ added in v0.7.0
QuerySetter is a source whose rows depend on the page URL's query. SetQuery reports whether the values it reads changed, so the page must refresh.
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry holds configured sources for a site
func NewEmptyRegistry ¶
func NewEmptyRegistry() *Registry
NewEmptyRegistry creates an empty registry (for testing or temporary use).
func NewRegistry ¶
NewRegistry creates a source registry from config
func NewRegistryWithFile ¶
NewRegistryWithFile creates a source registry with knowledge of the current markdown file This is needed for markdown sources that reference anchors in the current file
func (*Registry) InvalidateAllCaches ¶
func (r *Registry) InvalidateAllCaches()
InvalidateAllCaches invalidates all cached data
func (*Registry) InvalidateCache ¶
InvalidateCache invalidates the cache for a specific source
type RestSource ¶
type RestSource struct {
// contains filtered or unexported fields
}
RestSource fetches data from a REST API endpoint
func NewRestSource ¶
func NewRestSource(name, apiURL string, options map[string]string) (*RestSource, error)
NewRestSource creates a new REST API source (legacy, uses URL directly)
func NewRestSourceWithConfig ¶
func NewRestSourceWithConfig(name string, cfg config.SourceConfig) (*RestSource, error)
NewRestSourceWithConfig creates a new REST API source with full configuration
func (*RestSource) Fetch ¶
func (s *RestSource) Fetch(ctx context.Context) ([]map[string]interface{}, error)
Fetch makes an HTTP request and parses JSON response with retry and circuit breaker
func (*RestSource) String ¶
func (s *RestSource) String() string
String returns a debug representation with masked sensitive headers
type RetryConfig ¶
type RetryConfig struct {
MaxRetries int // Maximum number of retry attempts (default: 3)
BaseDelay time.Duration // Initial delay between retries (default: 100ms)
MaxDelay time.Duration // Maximum delay between retries (default: 5s)
Multiplier float64 // Delay multiplier for exponential backoff (default: 2.0)
EnableLog bool // Whether to log retry attempts
}
RetryConfig configures retry behavior
func DefaultRetryConfig ¶
func DefaultRetryConfig() RetryConfig
DefaultRetryConfig returns the default retry configuration
type RetryableFunc ¶
RetryableFunc is a function that can be retried
type SQLExecutor ¶
type SQLExecutor interface {
Source
// Exec executes a SQL statement with the given arguments.
// Returns the number of rows affected.
Exec(ctx context.Context, query string, args ...interface{}) (int64, error)
// ExecTx runs stmts in a single transaction: either every statement
// commits, or the first error rolls all of them back. It exists so one
// action can change state and append its audit record atomically — a
// partial success (state changed, audit missing) would defeat the durable
// trail that makes an approval workflow auditable.
ExecTx(ctx context.Context, stmts []SQLStatement) error
}
SQLExecutor extends Source with ability to execute arbitrary SQL statements. This is used by custom actions defined in frontmatter (action kind: "sql").
type SQLStatement ¶ added in v0.4.0
type SQLStatement struct {
Query string
Args []interface{}
}
SQLStatement is one parameterized statement in a transactional batch. Query uses positional placeholders (?), already substituted from :name form.
type SQLiteSource ¶
type SQLiteSource struct {
// contains filtered or unexported fields
}
SQLiteSource provides read/write access to SQLite tables. It implements WritableSource for Add, Update, Delete operations.
func NewSQLiteSource ¶
func NewSQLiteSource(name, dbPath, table, siteDir string, readonly bool) (*SQLiteSource, error)
NewSQLiteSource creates a new SQLite source
func (*SQLiteSource) Close ¶
func (s *SQLiteSource) Close() error
Close releases the database connection
func (*SQLiteSource) Exec ¶
Exec executes a SQL statement with the given arguments. This implements the SQLExecutor interface for custom action support. Returns the number of rows affected.
func (*SQLiteSource) ExecTx ¶ added in v0.4.0
func (s *SQLiteSource) ExecTx(ctx context.Context, stmts []SQLStatement) error
ExecTx runs the given statements in a single transaction. Either every statement commits, or the first error rolls all of them back — so an action that must change state and append an audit record does both or neither. The source's write mutex is held for the whole transaction, matching Exec's single-writer discipline against SQLite's one-writer lock.
func (*SQLiteSource) Fetch ¶
func (s *SQLiteSource) Fetch(ctx context.Context) ([]map[string]interface{}, error)
Fetch retrieves all records from the table
func (*SQLiteSource) IsReadonly ¶
func (s *SQLiteSource) IsReadonly() bool
IsReadonly returns whether the source is read-only
func (*SQLiteSource) Schema ¶
func (s *SQLiteSource) Schema(ctx context.Context) ([]ColumnInfo, error)
Schema returns column information for the table, implementing SchemaProvider. Excludes internal columns (id, created_at).
type SchemaProvider ¶
type SchemaProvider interface {
// Schema returns column info for the source's data.
// Columns like "id" and "created_at" (internal) should be excluded.
Schema(ctx context.Context) ([]ColumnInfo, error)
}
SchemaProvider is an optional interface for sources that can expose their schema. This is used by auto-tables to generate form inputs with appropriate types (e.g., <input type="number"> for integer columns).
type Source ¶
type Source interface {
// Name returns the source identifier
Name() string
// Fetch retrieves data from the source.
// Returns a slice of maps suitable for template iteration.
Fetch(ctx context.Context) ([]map[string]interface{}, error)
// Close releases any resources held by the source
Close() error
}
Source is the interface for data providers. Implementations fetch data from various backends (exec, pg, rest, etc.)
type SourceError ¶
type SourceError struct {
Source string // Source name (e.g., "users")
Operation string // Operation that failed (e.g., "fetch", "connect")
Err error // Underlying error
Retryable bool // Whether this error is retryable
}
SourceError wraps errors with source context
func NewSourceError ¶
func NewSourceError(source, operation string, err error) *SourceError
NewSourceError creates a SourceError with retryable detection
func (*SourceError) Error ¶
func (e *SourceError) Error() string
func (*SourceError) IsRetryable ¶
func (e *SourceError) IsRetryable() bool
IsRetryable returns true if the error is retryable
func (*SourceError) Unwrap ¶
func (e *SourceError) Unwrap() error
type StreamSource ¶ added in v0.5.0
type StreamSource struct {
// contains filtered or unexported fields
}
StreamSource is a Source backed by a stream.Buffer shared with every other page showing the same input. Fetch returns the buffer's current rows.
A merge with params is gated: it watches its gate merges and, with every param in the page's query, shows rows only while each value is in its gate. Its own buffer is built the first time every gate opens, so a value never listed creates nothing in the hub, and it holds that buffer (running its inputs) only while every gate is open. SetQuery changes the values.
func NewStreamSource ¶ added in v0.5.0
func NewStreamSource(hub *stream.Hub, name string, cfg config.SourceConfig, siteDir string, lookup func(string) (config.SourceConfig, bool), page *Page) (*StreamSource, error)
NewStreamSource builds a stream or merge source on hub. lookup resolves the stream sources a merge lists in inputs.
page carries the query and resolver a merge with params needs; it may be nil for any other source.
func (*StreamSource) Close ¶ added in v0.5.0
func (s *StreamSource) Close() error
Close is a no-op: the input belongs to the hub and outlives one page.
func (*StreamSource) Fetch ¶ added in v0.5.0
func (s *StreamSource) Fetch(ctx context.Context) ([]map[string]interface{}, error)
Fetch returns the buffered rows, oldest first. The rows are shared and must not be modified. A gated source returns no rows while a gate is closed, and attaches or detaches its buffer to match. That works because a gate's new rows wake the page's subscription, and every wake-up refreshes, so Fetch runs each time a gate may have opened or closed.
func (*StreamSource) FlushInterval ¶ added in v0.5.0
func (s *StreamSource) FlushInterval() time.Duration
FlushInterval is the minimum time between pushes to one page.
func (*StreamSource) Name ¶ added in v0.5.0
func (s *StreamSource) Name() string
Name returns the source identifier.
func (*StreamSource) SetQuery ¶ added in v0.7.0
func (s *StreamSource) SetQuery(q url.Values) bool
SetQuery takes a gated source's values from the page's query, and reports whether they changed. New values let go of the earlier values' buffer, which stops once no page shows it. A refused value is returned by the next Fetch. A source without params ignores the query.
func (*StreamSource) Subscribe ¶ added in v0.5.0
func (s *StreamSource) Subscribe() *stream.Subscription
Subscribe starts the input if needed and wakes the caller on new rows. A gated source wakes on its gates' rows too, and starts its own input only while its gates are open, even before the query has its values.
type TimeoutError ¶
TimeoutError represents a timeout
func (*TimeoutError) Error ¶
func (e *TimeoutError) Error() string
type UnsupportedSourceError ¶
type UnsupportedSourceError struct {
Type string
}
UnsupportedSourceError is returned for unknown source types
func (*UnsupportedSourceError) Error ¶
func (e *UnsupportedSourceError) Error() string
type ValidationError ¶
ValidationError represents invalid data or configuration
func (*ValidationError) Error ¶
func (e *ValidationError) Error() string
type WritableSource ¶
type WritableSource interface {
Source
// WriteItem performs a write operation on the source.
// action is one of: "add", "toggle", "delete", "update"
// data contains the item data (e.g., form fields, id for delete)
WriteItem(ctx context.Context, action string, data map[string]interface{}) error
// IsReadonly returns whether the source is in read-only mode
IsReadonly() bool
}
WritableSource extends Source with write capability. Sources like markdown and sqlite implement this to support Add, Update, Delete actions.