Documentation
¶
Overview ¶
Package document implements the Document Engine: Create, Read, Update, Delete, and List operations driven by the compiled Registry schema, with field validation, lifecycle hooks, permission enforcement, and audit logging.
See TAD §3.2 and PRD §12.2 for the full request lifecycle. Implemented in Phases 3 (bare CRUD) and 4 (full integration).
Index ¶
- Constants
- type Engine
- func (e *Engine) Create(ctx context.Context, docType string, data map[string]any) (string, error)
- func (e *Engine) Delete(ctx context.Context, docType, id string) error
- func (e *Engine) List(ctx context.Context, docType string, opts ListOpts) ([]map[string]any, error)
- func (e *Engine) Read(ctx context.Context, docType, id string) (map[string]any, error)
- func (e *Engine) SetAuditLog(a audit.Log)
- func (e *Engine) SetEventBus(b event.Bus)
- func (e *Engine) SetPermEngine(p perm.Engine)
- func (e *Engine) Update(ctx context.Context, docType, id string, data map[string]any) error
- type ListOpts
Constants ¶
const ( DocStatusDraft = 0 DocStatusSubmitted = 1 DocStatusCancelled = 2 )
DocStatus values per PRD §10.2.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Engine ¶
type Engine struct {
// contains filtered or unexported fields
}
Engine is the Document Engine that drives Create/Read/Update/Delete/List through the DAL with schema validation, permission checks, lifecycle hooks, and audit logging. See TAD §3.2.
func New ¶
New constructs a Document Engine backed by the given Database and Registry. The Registry must already be compiled (Registry.Compile() must have been called).
func NewWithServices ¶
func NewWithServices(db dal.Database, reg schema.Registry, permEngine perm.Engine, bus event.Bus, auditLog audit.Log) *Engine
NewWithServices constructs a Document Engine with permission engine, event bus, and audit log attached.
func (*Engine) Create ¶
Create validates data against the CompiledDoc for docType, enforces permissions, triggers lifecycle hooks, inserts a new record, and writes an audit entry inside a transaction. Returns the new record's ID.
See TAD §3.2 (full request lifecycle).
func (*Engine) Delete ¶
Delete soft-deletes the record by setting Deleted=true inside a transaction.
func (*Engine) Read ¶
Read fetches a single record by its ID and filters fields based on caller role.
func (*Engine) SetAuditLog ¶
SetAuditLog sets the audit log.
func (*Engine) SetEventBus ¶
SetEventBus sets the event bus.
func (*Engine) SetPermEngine ¶
SetPermEngine sets the permission engine.
type ListOpts ¶
type ListOpts struct {
// Filters are equality predicates applied to the query (column or field name).
Filters map[string]any
// OrderBy is the column/field to sort by (e.g. "created_at DESC").
OrderBy string
// Limit is the max number of rows to return (0 = no limit).
Limit int
// Offset is the number of rows to skip.
Offset int
// IncludeDeleted, when true, includes soft-deleted records.
IncludeDeleted bool
}
ListOpts controls the List query.