export

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Jan 21, 2026 License: MIT Imports: 20 Imported by: 0

Documentation

Overview

Package export defines core interfaces and runner scaffolding for go-export.

Index

Constants

View Source
const (
	// DefaultPDFAssetsPath is the local path used to serve embedded PDF preview assets.
	DefaultPDFAssetsPath = "/exports/assets/pdf/"
)

Variables

This section is empty.

Functions

func AsGoError

func AsGoError(err error) *errorslib.Error

AsGoError maps an error into a go-errors error.

func DefaultPDFAssetsHost

func DefaultPDFAssetsHost() string

DefaultPDFAssetsHost returns the default assets host, respecting GO_EXPORT_PDF_ASSETS_CDN if set.

func PDFAssetsFS

func PDFAssetsFS() fs.FS

PDFAssetsFS exposes the embedded PDF preview assets.

func RuntimeAssetsFS

func RuntimeAssetsFS() fs.FS

RuntimeAssetsFS exposes the embedded frontend helpers (datagrid export client).

Typical mount:

mux.Handle("/assets/",
	http.StripPrefix("/assets/",
		http.FileServer(http.FS(export.RuntimeAssetsFS())),
	),
)

Types

type Actor

type Actor struct {
	ID      string         `json:"id"`
	Scope   Scope          `json:"scope"`
	Roles   []string       `json:"roles,omitempty"`
	Details map[string]any `json:"details,omitempty"`
}

Actor identifies the requesting principal.

type ActorProvider

type ActorProvider interface {
	FromContext(ctx context.Context) (Actor, error)
}

ActorProvider extracts the actor from context.

type ArtifactMeta

type ArtifactMeta struct {
	ContentType string    `json:"content_type,omitempty"`
	Size        int64     `json:"size,omitempty"`
	Filename    string    `json:"filename,omitempty"`
	CreatedAt   time.Time `json:"created_at,omitempty"`
	ExpiresAt   time.Time `json:"expires_at,omitempty"`
}

ArtifactMeta captures stored artifact metadata.

type ArtifactRef

type ArtifactRef struct {
	Key  string       `json:"key"`
	Meta ArtifactMeta `json:"meta"`
}

ArtifactRef references a stored artifact.

type ArtifactStore

type ArtifactStore interface {
	Put(ctx context.Context, key string, r io.Reader, meta ArtifactMeta) (ArtifactRef, error)
	Open(ctx context.Context, key string) (io.ReadCloser, ArtifactMeta, error)
	Delete(ctx context.Context, key string) error
	SignedURL(ctx context.Context, key string, ttl time.Duration) (string, error)
}

ArtifactStore stores export artifacts.

type ArtifactTracker

type ArtifactTracker interface {
	SetArtifact(ctx context.Context, id string, ref ArtifactRef) error
}

ArtifactTracker updates stored artifact metadata.

type AugmentTransformer

type AugmentTransformer struct {
	Columns     []Column
	AugmentFunc RowAugmentFunc
}

AugmentTransformer appends derived columns to each row.

func NewAugmentTransformer

func NewAugmentTransformer(columns []Column, fn RowAugmentFunc) AugmentTransformer

NewAugmentTransformer creates an AugmentTransformer.

func (AugmentTransformer) Wrap

Wrap implements RowTransformer.

type BufferedTransformer

type BufferedTransformer interface {
	Process(ctx context.Context, rows RowIterator, schema Schema) ([]Row, Schema, error)
}

BufferedTransformer collects rows to perform non-streaming transforms.

type BufferedTransformerFactory

type BufferedTransformerFactory func(config TransformerConfig) (BufferedTransformer, error)

BufferedTransformerFactory creates a BufferedTransformer from config.

type CSVOptions

type CSVOptions struct {
	IncludeHeaders bool
	Delimiter      rune
	HeadersSet     bool
}

CSVOptions configures CSV output.

type CSVRenderer

type CSVRenderer struct{}

CSVRenderer renders CSV output.

func (CSVRenderer) Render

func (r CSVRenderer) Render(ctx context.Context, schema Schema, rows RowIterator, w io.Writer, opts RenderOptions) (RenderStats, error)

Render streams rows as CSV.

type CancelHook

type CancelHook interface {
	Cancel(ctx context.Context, exportID string) error
}

CancelHook allows adapters to cancel running exports.

type ChangeEmitter

type ChangeEmitter interface {
	Emit(ctx context.Context, evt ChangeEvent) error
}

ChangeEmitter emits lifecycle events.

type ChangeEvent

type ChangeEvent struct {
	Name       string
	ExportID   string
	Definition string
	Format     Format
	Delivery   DeliveryMode
	Actor      Actor
	Timestamp  time.Time
	Metadata   map[string]any
}

ChangeEvent describes lifecycle events.

type Column

type Column struct {
	Name   string
	Label  string
	Type   string
	Format ColumnFormat
}

Column defines a column in the export schema.

type ColumnFormat

type ColumnFormat struct {
	Layout string
	Number string
	Excel  string
}

ColumnFormat provides renderer-specific formatting hints.

type DefinitionRegistry

type DefinitionRegistry struct {
	// contains filtered or unexported fields
}

DefinitionRegistry stores export definitions.

func NewDefinitionRegistry

func NewDefinitionRegistry() *DefinitionRegistry

NewDefinitionRegistry creates an empty registry.

func (*DefinitionRegistry) Get added in v0.2.0

Get returns a definition by name.

func (*DefinitionRegistry) List added in v0.2.0

List returns all registered definitions in name order.

func (*DefinitionRegistry) Register

func (r *DefinitionRegistry) Register(def ExportDefinition) error

Register adds a definition.

func (*DefinitionRegistry) Resolve

Resolve returns a resolved definition for the request.

func (*DefinitionRegistry) ResolveByResource

func (r *DefinitionRegistry) ResolveByResource(resource string) (ExportDefinition, error)

ResolveByResource finds a definition by resource name.

type DeleteParams

type DeleteParams struct {
	Record  ExportRecord
	Tracker ProgressTracker
	Store   ArtifactStore
	Now     time.Time
}

DeleteParams provides dependencies to delete strategies.

type DeleteStrategy

type DeleteStrategy interface {
	Delete(ctx context.Context, params DeleteParams) error
}

DeleteStrategy defines how delete requests are handled.

type DeliveryMode

type DeliveryMode string

DeliveryMode describes how exports are delivered.

const (
	DeliverySync  DeliveryMode = "sync"
	DeliveryAsync DeliveryMode = "async"
	DeliveryAuto  DeliveryMode = "auto"
)

func SelectDelivery

func SelectDelivery(req ExportRequest, def ResolvedDefinition, policy DeliveryPolicy) DeliveryMode

SelectDelivery determines the final delivery mode.

type DeliveryPolicy

type DeliveryPolicy struct {
	Default    DeliveryMode
	Thresholds DeliveryThresholds
}

DeliveryPolicy configures delivery selection thresholds.

type DeliveryThresholds

type DeliveryThresholds struct {
	MaxRows     int
	MaxBytes    int64
	MaxDuration time.Duration
}

DeliveryThresholds drive auto delivery decisions.

type DownloadInfo

type DownloadInfo struct {
	ExportID string
	Artifact ArtifactRef
}

DownloadInfo describes downloadable export metadata.

type ErrorKind

type ErrorKind string

ErrorKind defines export error kinds.

const (
	KindValidation ErrorKind = "validation"
	KindAuthz      ErrorKind = "authz"
	KindNotFound   ErrorKind = "not_found"
	KindTimeout    ErrorKind = "timeout"
	KindCanceled   ErrorKind = "canceled"
	KindExternal   ErrorKind = "external"
	KindInternal   ErrorKind = "internal"
	KindNotImpl    ErrorKind = "not_implemented"
)

func KindFromError

func KindFromError(err error) ErrorKind

KindFromError maps an error to its export error kind.

type ExportCounts

type ExportCounts struct {
	Processed int64 `json:"processed,omitempty"`
	Total     int64 `json:"total,omitempty"`
	Errors    int64 `json:"errors,omitempty"`
}

ExportCounts tracks row counts.

type ExportDefinition

type ExportDefinition struct {
	Name             string
	Resource         string
	Schema           Schema
	AllowedFormats   []Format
	DefaultFilename  string
	RowSourceKey     string
	Transformers     []TransformerConfig
	DefaultSelection Selection
	SelectionPolicy  SelectionPolicy
	SourceVariants   map[string]SourceVariant
	Policy           ExportPolicy
	DeliveryPolicy   *DeliveryPolicy
	Template         TemplateOptions
}

ExportDefinition declares an exportable dataset.

type ExportError

type ExportError struct {
	Kind ErrorKind
	Msg  string
	Err  error
}

ExportError wraps errors with a kind.

func NewError

func NewError(kind ErrorKind, msg string, err error) *ExportError

NewError creates a new export error.

func (*ExportError) Error

func (e *ExportError) Error() string

func (*ExportError) Unwrap

func (e *ExportError) Unwrap() error

type ExportPolicy

type ExportPolicy struct {
	AllowedColumns []string
	RedactColumns  []string
	RedactionValue any
	MaxRows        int
	MaxBytes       int64
	MaxDuration    time.Duration
}

ExportPolicy enforces export limits and redaction.

type ExportRecord

type ExportRecord struct {
	ID           string        `json:"id"`
	Definition   string        `json:"definition"`
	Format       Format        `json:"format"`
	State        ExportState   `json:"state"`
	RequestedBy  Actor         `json:"requested_by"`
	Scope        Scope         `json:"scope"`
	Request      ExportRequest `json:"-"`
	Counts       ExportCounts  `json:"counts"`
	BytesWritten int64         `json:"bytes_written,omitempty"`
	Artifact     ArtifactRef   `json:"artifact"`
	CreatedAt    time.Time     `json:"created_at"`
	StartedAt    time.Time     `json:"started_at,omitempty"`
	CompletedAt  time.Time     `json:"completed_at,omitempty"`
	ExpiresAt    time.Time     `json:"expires_at,omitempty"`
}

ExportRecord captures tracker state for an export.

type ExportRequest

type ExportRequest struct {
	Definition        string
	Resource          string
	SourceVariant     string
	Format            Format
	Query             any
	Selection         Selection
	Columns           []string
	Locale            string
	Timezone          string
	Delivery          DeliveryMode
	IdempotencyKey    string
	EstimatedRows     int
	EstimatedBytes    int64
	EstimatedDuration time.Duration
	Output            io.Writer
	RenderOptions     RenderOptions
}

ExportRequest captures an export request.

type ExportResult

type ExportResult struct {
	ID       string       `json:"id"`
	Delivery DeliveryMode `json:"delivery"`
	Format   Format       `json:"format"`
	Rows     int64        `json:"rows"`
	Bytes    int64        `json:"bytes"`
	Filename string       `json:"filename"`
	Artifact *ArtifactRef `json:"artifact,omitempty"`
}

ExportResult captures a completed export.

type ExportState

type ExportState string

ExportState captures progress states.

const (
	StateQueued     ExportState = "queued"
	StateRunning    ExportState = "running"
	StatePublishing ExportState = "publishing"
	StateCompleted  ExportState = "completed"
	StateFailed     ExportState = "failed"
	StateCanceled   ExportState = "canceled"
	StateDeleted    ExportState = "deleted"
)

type FilterTransformer

type FilterTransformer struct {
	FilterFunc RowFilterFunc
}

FilterTransformer drops rows that do not pass the filter.

func NewFilterTransformer

func NewFilterTransformer(fn RowFilterFunc) FilterTransformer

NewFilterTransformer creates a FilterTransformer.

func (FilterTransformer) Wrap

Wrap implements RowTransformer.

type Format

type Format string

Format is the export output format.

const (
	FormatCSV      Format = "csv"
	FormatJSON     Format = "json"
	FormatNDJSON   Format = "ndjson"
	FormatXLSX     Format = "xlsx"
	FormatSQLite   Format = "sqlite"
	FormatTemplate Format = "template"
	FormatPDF      Format = "pdf"
)

func NormalizeFormat

func NormalizeFormat(format Format) Format

NormalizeFormat coerces format values into known aliases with defaults applied.

type FormatOptions

type FormatOptions struct {
	Locale   string
	Timezone string
}

FormatOptions configures locale/timezone formatting.

type Guard

type Guard interface {
	AuthorizeExport(ctx context.Context, actor Actor, req ExportRequest, def ResolvedDefinition) error
	AuthorizeDownload(ctx context.Context, actor Actor, exportID string) error
}

Guard enforces authorization.

type JSONMode

type JSONMode string

JSONMode configures JSON rendering.

const (
	JSONModeArray  JSONMode = "array"
	JSONModeLines  JSONMode = "ndjson"
	JSONModeObject JSONMode = "object"
)

type JSONOptions

type JSONOptions struct {
	Mode JSONMode
}

JSONOptions configures JSON output.

type JSONRenderer

type JSONRenderer struct{}

JSONRenderer renders JSON output.

func (JSONRenderer) Render

func (r JSONRenderer) Render(ctx context.Context, schema Schema, rows RowIterator, w io.Writer, opts RenderOptions) (RenderStats, error)

Render streams rows as JSON array or NDJSON.

type Logger

type Logger interface {
	Debugf(format string, args ...any)
	Infof(format string, args ...any)
	Errorf(format string, args ...any)
}

Logger provides logging hooks.

type MapTransformer

type MapTransformer struct {
	MapFunc RowMapFunc
}

MapTransformer applies a mapping function to each row.

func NewMapTransformer

func NewMapTransformer(fn RowMapFunc) MapTransformer

NewMapTransformer creates a MapTransformer.

func (MapTransformer) Wrap

Wrap implements RowTransformer.

type MemoryStore

type MemoryStore struct {
	// contains filtered or unexported fields
}

MemoryStore stores artifacts in memory (test/dev only).

func NewMemoryStore

func NewMemoryStore() *MemoryStore

NewMemoryStore creates an in-memory artifact store.

func (*MemoryStore) Delete

func (s *MemoryStore) Delete(ctx context.Context, key string) error

Delete removes an artifact.

func (*MemoryStore) Open

Open reads an artifact.

func (*MemoryStore) Put

func (s *MemoryStore) Put(ctx context.Context, key string, r io.Reader, meta ArtifactMeta) (ArtifactRef, error)

Put stores an artifact.

func (*MemoryStore) SignedURL

func (s *MemoryStore) SignedURL(ctx context.Context, key string, ttl time.Duration) (string, error)

SignedURL returns a static error for memory store.

type MemoryTracker

type MemoryTracker struct {
	// contains filtered or unexported fields
}

MemoryTracker stores progress in memory (test/dev only).

func NewMemoryTracker

func NewMemoryTracker() *MemoryTracker

NewMemoryTracker creates an in-memory tracker.

func (*MemoryTracker) Advance

func (t *MemoryTracker) Advance(ctx context.Context, id string, delta ProgressDelta, meta map[string]any) error

Advance updates counts.

func (*MemoryTracker) Complete

func (t *MemoryTracker) Complete(ctx context.Context, id string, meta map[string]any) error

Complete marks the export as completed.

func (*MemoryTracker) Delete

func (t *MemoryTracker) Delete(ctx context.Context, id string) error

Delete removes a record from the tracker.

func (*MemoryTracker) Fail

func (t *MemoryTracker) Fail(ctx context.Context, id string, err error, meta map[string]any) error

Fail records failure state.

func (*MemoryTracker) List

func (t *MemoryTracker) List(ctx context.Context, filter ProgressFilter) ([]ExportRecord, error)

List returns records matching a filter.

func (*MemoryTracker) SetArtifact

func (t *MemoryTracker) SetArtifact(ctx context.Context, id string, ref ArtifactRef) error

SetArtifact updates the artifact metadata for a record.

func (*MemoryTracker) SetState

func (t *MemoryTracker) SetState(ctx context.Context, id string, state ExportState, meta map[string]any) error

SetState updates the record state.

func (*MemoryTracker) Start

func (t *MemoryTracker) Start(ctx context.Context, record ExportRecord) (string, error)

Start creates a new record.

func (*MemoryTracker) Status

func (t *MemoryTracker) Status(ctx context.Context, id string) (ExportRecord, error)

Status returns a record by ID.

func (*MemoryTracker) Update

func (t *MemoryTracker) Update(ctx context.Context, record ExportRecord) error

Update replaces a record by ID.

type MetricsEvent

type MetricsEvent struct {
	Name       string
	ExportID   string
	Definition string
	Format     Format
	Delivery   DeliveryMode
	Actor      Actor
	Rows       int64
	Bytes      int64
	Duration   time.Duration
	ErrorKind  ErrorKind
	Timestamp  time.Time
}

MetricsEvent describes lifecycle metrics.

type MetricsHook

type MetricsHook interface {
	Emit(ctx context.Context, evt MetricsEvent) error
}

MetricsHook emits metrics-friendly lifecycle observations.

type NopLogger

type NopLogger struct{}

NopLogger is a no-op logger.

func (NopLogger) Debugf

func (NopLogger) Debugf(string, ...any)

func (NopLogger) Errorf

func (NopLogger) Errorf(string, ...any)

func (NopLogger) Infof

func (NopLogger) Infof(string, ...any)

type PDFExternalAssetsPolicy

type PDFExternalAssetsPolicy string

PDFExternalAssetsPolicy controls how external assets are handled in PDF rendering.

const (
	PDFExternalAssetsUnspecified PDFExternalAssetsPolicy = ""
	PDFExternalAssetsAllow       PDFExternalAssetsPolicy = "allow"
	PDFExternalAssetsBlock       PDFExternalAssetsPolicy = "block"
)

type PDFOptions

type PDFOptions struct {
	PageSize             string
	Landscape            *bool
	PrintBackground      *bool
	Scale                float64
	MarginTop            string
	MarginBottom         string
	MarginLeft           string
	MarginRight          string
	PreferCSSPageSize    *bool
	BaseURL              string
	ExternalAssetsPolicy PDFExternalAssetsPolicy
}

PDFOptions configures PDF output for headless engines.

type ProgressDelta

type ProgressDelta struct {
	Rows  int64
	Bytes int64
}

ProgressDelta indicates progress changes.

type ProgressFilter

type ProgressFilter struct {
	Definition string
	State      ExportState
	Since      time.Time
	Until      time.Time
}

ProgressFilter filters tracker lists.

type ProgressTracker

type ProgressTracker interface {
	Start(ctx context.Context, record ExportRecord) (string, error)
	Advance(ctx context.Context, id string, delta ProgressDelta, meta map[string]any) error
	SetState(ctx context.Context, id string, state ExportState, meta map[string]any) error
	Fail(ctx context.Context, id string, err error, meta map[string]any) error
	Complete(ctx context.Context, id string, meta map[string]any) error
	Status(ctx context.Context, id string) (ExportRecord, error)
	List(ctx context.Context, filter ProgressFilter) ([]ExportRecord, error)
}

ProgressTracker tracks export progress.

type QuotaHook

type QuotaHook interface {
	Allow(ctx context.Context, actor Actor, req ExportRequest, def ResolvedDefinition) error
}

QuotaHook enforces limits beyond per-definition policy.

type RateLimiter

type RateLimiter struct {
	Max     int
	Window  time.Duration
	KeyFunc func(actor Actor, req ExportRequest, def ResolvedDefinition) string
	Now     func() time.Time
	// contains filtered or unexported fields
}

RateLimiter enforces per-actor rate limits in memory.

func (*RateLimiter) Allow

func (l *RateLimiter) Allow(ctx context.Context, actor Actor, req ExportRequest, def ResolvedDefinition) error

Allow enforces the configured rate limit, keyed by actor/scope unless overridden.

type RecordDeleter

type RecordDeleter interface {
	Delete(ctx context.Context, id string) error
}

RecordDeleter removes records from the tracker.

type RecordUpdater

type RecordUpdater interface {
	Update(ctx context.Context, record ExportRecord) error
}

RecordUpdater updates records outside state transitions.

type RenderOptions

type RenderOptions struct {
	CSV      CSVOptions
	JSON     JSONOptions
	Template TemplateOptions
	XLSX     XLSXOptions
	SQLite   SQLiteOptions
	PDF      PDFOptions
	Format   FormatOptions
}

RenderOptions configures renderer behavior.

type RenderStats

type RenderStats struct {
	Rows  int64
	Bytes int64
}

RenderStats capture renderer output.

type Renderer

type Renderer interface {
	Render(ctx context.Context, schema Schema, rows RowIterator, w io.Writer, opts RenderOptions) (RenderStats, error)
}

Renderer writes rows to the destination.

type RendererRegistry

type RendererRegistry struct {
	// contains filtered or unexported fields
}

RendererRegistry stores renderers by format.

func NewRendererRegistry

func NewRendererRegistry() *RendererRegistry

NewRendererRegistry creates a registry.

func (*RendererRegistry) Register

func (r *RendererRegistry) Register(format Format, renderer Renderer) error

Register adds a renderer for a format.

func (*RendererRegistry) Resolve

func (r *RendererRegistry) Resolve(format Format) (Renderer, bool)

Resolve returns the renderer for the format.

type ResolvedDefinition

type ResolvedDefinition struct {
	ExportDefinition
	Variant string
}

ResolvedDefinition is a definition with variant overrides applied.

type ResolvedExport

type ResolvedExport struct {
	Request       ExportRequest
	Definition    ResolvedDefinition
	Columns       []Column
	ColumnNames   []string
	RedactIndices map[int]any
	Filename      string
}

ResolvedExport contains validated inputs for a run.

func ResolveExport

func ResolveExport(req ExportRequest, def ResolvedDefinition, now time.Time) (ResolvedExport, error)

ResolveExport validates and resolves a request against a definition.

type RetentionPolicy

type RetentionPolicy interface {
	TTL(ctx context.Context, actor Actor, req ExportRequest, def ResolvedDefinition) (time.Duration, error)
}

RetentionPolicy decides artifact TTLs.

type RetentionRule

type RetentionRule struct {
	Definition string
	Format     Format
	Role       string
	TTL        time.Duration
}

RetentionRule defines a TTL override for matching exports.

type RetentionRules

type RetentionRules struct {
	DefaultTTL   time.Duration
	ByDefinition map[string]time.Duration
	ByFormat     map[Format]time.Duration
	ByRole       map[string]time.Duration
	Rules        []RetentionRule
	RoleResolver func(actor Actor) []string
}

RetentionRules configures TTL lookups for exports.

func (RetentionRules) TTL

TTL returns a TTL for the provided request.

type RouterRegistrar

type RouterRegistrar interface {
	RegisterRoutes(router any)
}

RouterRegistrar provides optional route registration.

type Row

type Row []any

Row is a column-aligned record.

type RowAugmentFunc

type RowAugmentFunc func(ctx context.Context, row Row) ([]any, error)

RowAugmentFunc returns additional values to append to a row.

type RowFilterFunc

type RowFilterFunc func(ctx context.Context, row Row) (bool, error)

RowFilterFunc decides whether a row should be kept.

type RowIterator

type RowIterator interface {
	Next(ctx context.Context) (Row, error)
	Close() error
}

RowIterator streams rows.

type RowMapFunc

type RowMapFunc func(ctx context.Context, row Row) (Row, error)

RowMapFunc maps a row to a new row.

type RowSource

type RowSource interface {
	Open(ctx context.Context, spec RowSourceSpec) (RowIterator, error)
}

RowSource provides row iterators for exports.

type RowSourceFactory

type RowSourceFactory func(req ExportRequest, def ResolvedDefinition) (RowSource, error)

RowSourceFactory creates a RowSource for a request.

type RowSourceRegistry

type RowSourceRegistry struct {
	// contains filtered or unexported fields
}

RowSourceRegistry stores row source factories.

func NewRowSourceRegistry

func NewRowSourceRegistry() *RowSourceRegistry

NewRowSourceRegistry creates an empty registry.

func (*RowSourceRegistry) Register

func (r *RowSourceRegistry) Register(key string, factory RowSourceFactory) error

Register adds a row source factory.

func (*RowSourceRegistry) Resolve

func (r *RowSourceRegistry) Resolve(key string) (RowSourceFactory, bool)

Resolve finds a row source factory by key.

type RowSourceSpec

type RowSourceSpec struct {
	Definition ResolvedDefinition
	Request    ExportRequest
	Columns    []Column
	Actor      Actor
}

RowSourceSpec is passed to RowSource.Open.

type RowTransformer

type RowTransformer interface {
	Wrap(ctx context.Context, in RowIterator, schema Schema) (RowIterator, Schema, error)
}

RowTransformer wraps an iterator with row-level transformations.

type Runner

type Runner struct {
	Definitions    *DefinitionRegistry
	RowSources     *RowSourceRegistry
	Renderers      *RendererRegistry
	Transformers   *TransformerRegistry
	Tracker        ProgressTracker
	Store          ArtifactStore
	Guard          Guard
	ActorProvider  ActorProvider
	Logger         Logger
	Emitter        ChangeEmitter
	Metrics        MetricsHook
	QuotaHook      QuotaHook
	Retention      RetentionPolicy
	DeliveryPolicy DeliveryPolicy
	Now            func() time.Time
	IDGenerator    func() string
}

Runner orchestrates export execution.

func NewRunner

func NewRunner() *Runner

NewRunner creates a runner with default registries.

func (*Runner) Run

func (r *Runner) Run(ctx context.Context, req ExportRequest) (ExportResult, error)

Run executes an export request.

type SQLiteOptions added in v0.6.0

type SQLiteOptions struct {
	TableName string
}

SQLiteOptions configures SQLite output.

type Schema

type Schema struct {
	Columns []Column
}

Schema defines the columns for a dataset.

type Scope

type Scope struct {
	TenantID    string `json:"tenant_id,omitempty"`
	WorkspaceID string `json:"workspace_id,omitempty"`
}

Scope identifies tenant/workspace scope.

type Selection

type Selection struct {
	Mode  SelectionMode
	IDs   []string
	Query SelectionQueryRef
}

Selection captures row selection intent.

type SelectionMode

type SelectionMode string

SelectionMode describes how rows are selected.

const (
	SelectionAll   SelectionMode = "all"
	SelectionIDs   SelectionMode = "ids"
	SelectionQuery SelectionMode = "query"
)

type SelectionPolicy

type SelectionPolicy interface {
	DefaultSelection(ctx context.Context, actor Actor, req ExportRequest, def ResolvedDefinition) (Selection, bool, error)
}

SelectionPolicy supplies default selections for requests without one.

type SelectionPolicyFunc

type SelectionPolicyFunc func(ctx context.Context, actor Actor, req ExportRequest, def ResolvedDefinition) (Selection, bool, error)

SelectionPolicyFunc adapts a function to a SelectionPolicy.

func (SelectionPolicyFunc) DefaultSelection

func (f SelectionPolicyFunc) DefaultSelection(ctx context.Context, actor Actor, req ExportRequest, def ResolvedDefinition) (Selection, bool, error)

type SelectionQueryRef

type SelectionQueryRef struct {
	Name   string
	Params any
}

SelectionQueryRef references a named selection query plus optional params.

type Service

type Service interface {
	RequestExport(ctx context.Context, actor Actor, req ExportRequest) (ExportRecord, error)
	GenerateExport(ctx context.Context, actor Actor, exportID string, req ExportRequest) (ExportResult, error)
	CancelExport(ctx context.Context, actor Actor, exportID string) (ExportRecord, error)
	DeleteExport(ctx context.Context, actor Actor, exportID string) error
	Status(ctx context.Context, actor Actor, exportID string) (ExportRecord, error)
	History(ctx context.Context, actor Actor, filter ProgressFilter) ([]ExportRecord, error)
	DownloadMetadata(ctx context.Context, actor Actor, exportID string) (DownloadInfo, error)
	Cleanup(ctx context.Context, now time.Time) (int, error)
}

Service coordinates export operations across runner, guard, tracker, and store.

func NewService

func NewService(cfg ServiceConfig) Service

NewService creates a Service with the provided configuration.

type ServiceConfig

type ServiceConfig struct {
	Runner         *Runner
	Tracker        ProgressTracker
	Store          ArtifactStore
	Guard          Guard
	DeliveryPolicy DeliveryPolicy
	DeleteStrategy DeleteStrategy
	CancelHook     CancelHook
	Now            func() time.Time
	IDGenerator    func() string
}

ServiceConfig supplies dependencies for Service.

type SoftDeleteStrategy

type SoftDeleteStrategy struct{}

SoftDeleteStrategy deletes artifacts and tombstones the record.

func (SoftDeleteStrategy) Delete

func (SoftDeleteStrategy) Delete(ctx context.Context, params DeleteParams) error

type SourceVariant

type SourceVariant struct {
	RowSourceKey    string
	AllowedFormats  []Format
	DefaultFilename string
	Transformers    []TransformerConfig
	Policy          *ExportPolicy
	Template        *TemplateOptions
}

SourceVariant allows alternate sources and policy overrides.

type TemplateOptions

type TemplateOptions struct {
	Strategy     TemplateStrategy
	MaxRows      int
	TemplateName string
	Layout       string
	Title        string
	Definition   string
	GeneratedAt  time.Time
	ChartConfig  any
	Theme        map[string]any
	Header       map[string]any
	Footer       map[string]any
	Data         map[string]any
}

TemplateOptions configures template rendering.

type TemplateStrategy

type TemplateStrategy string

TemplateStrategy selects template rendering behavior.

const (
	TemplateStrategyBuffered  TemplateStrategy = "buffered"
	TemplateStrategyStreaming TemplateStrategy = "streaming"
)

type TombstoneDeleteStrategy

type TombstoneDeleteStrategy struct {
	TTL time.Duration
}

TombstoneDeleteStrategy marks records deleted and purges them after TTL.

func (TombstoneDeleteStrategy) Delete

type TransformerConfig

type TransformerConfig struct {
	Key    string         `json:"key"`
	Params map[string]any `json:"params,omitempty"`
}

TransformerConfig identifies a configured transformer in a pipeline.

type TransformerFactory

type TransformerFactory func(config TransformerConfig) (RowTransformer, error)

TransformerFactory creates a RowTransformer from config.

type TransformerRegistry

type TransformerRegistry struct {
	// contains filtered or unexported fields
}

TransformerRegistry stores transformers by key.

func NewTransformerRegistry

func NewTransformerRegistry() *TransformerRegistry

NewTransformerRegistry creates a registry.

func (*TransformerRegistry) Register

func (r *TransformerRegistry) Register(key string, factory TransformerFactory) error

Register adds a streaming transformer factory.

func (*TransformerRegistry) RegisterBuffered

func (r *TransformerRegistry) RegisterBuffered(key string, factory BufferedTransformerFactory) error

RegisterBuffered adds a buffered transformer factory.

func (*TransformerRegistry) Resolve

func (r *TransformerRegistry) Resolve(key string) (transformerFactory, bool)

Resolve finds a transformer factory by key.

type XLSXOptions

type XLSXOptions struct {
	IncludeHeaders bool
	HeadersSet     bool
	SheetName      string
	MaxRows        int
	MaxBytes       int64
}

XLSXOptions configures XLSX output.

type XLSXRenderer

type XLSXRenderer struct{}

XLSXRenderer renders XLSX output.

func (XLSXRenderer) Render

func (r XLSXRenderer) Render(ctx context.Context, schema Schema, rows RowIterator, w io.Writer, opts RenderOptions) (RenderStats, error)

Render streams rows into an XLSX workbook.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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