document

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

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

View Source
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

func New(db dal.Database, reg schema.Registry) *Engine

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

func (e *Engine) Create(ctx context.Context, docType string, data map[string]any) (string, error)

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

func (e *Engine) Delete(ctx context.Context, docType, id string) error

Delete soft-deletes the record by setting Deleted=true inside a transaction.

func (*Engine) List

func (e *Engine) List(ctx context.Context, docType string, opts ListOpts) ([]map[string]any, error)

List returns records for docType, filtered by caller permissions.

func (*Engine) Read

func (e *Engine) Read(ctx context.Context, docType, id string) (map[string]any, error)

Read fetches a single record by its ID and filters fields based on caller role.

func (*Engine) SetAuditLog

func (e *Engine) SetAuditLog(a audit.Log)

SetAuditLog sets the audit log.

func (*Engine) SetEventBus

func (e *Engine) SetEventBus(b event.Bus)

SetEventBus sets the event bus.

func (*Engine) SetPermEngine

func (e *Engine) SetPermEngine(p perm.Engine)

SetPermEngine sets the permission engine.

func (*Engine) Update

func (e *Engine) Update(ctx context.Context, docType, id string, data map[string]any) error

Update validates data and applies partial updates with permission enforcement, hooks, and audit logging inside a transaction.

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.

Jump to

Keyboard shortcuts

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