Documentation
¶
Overview ¶
Package slots binds generated model extension slots to the translation, attachment and metadata managers. A model declares translations.Text, attachments.One/Many and metadata.Value fields; generation derives one Declaration per model, and applications bind a Runtime once per constructor.
Index ¶
- func ObserverName[M any]() (string, error)
- type Cleanup
- type CleanupJob
- func (j CleanupJob) Declare(runtime Runtime) (jobs.Declaration, error)
- func (j CleanupJob) Definition() jobs.Definition[CleanupRequest]
- func (j CleanupJob) Handler(runtime Runtime) (jobs.Handler[CleanupRequest], error)
- func (j CleanupJob) ToOutbox(queue jobs.Queue, producers map[*database.DB]*jobs.Outbox) (*CleanupQueue, error)
- type CleanupQueue
- type CleanupRequest
- type Declaration
- func (d Declaration) Describe() Description
- func (Declaration) Format(s fmt.State, _ rune)
- func (d Declaration) Owner() extensions.Declaration
- func (d Declaration) Parts() Parts
- func (d Declaration) Register(r *foundation.Registrar, pool foundation.Key[*database.DB], ...) error
- func (d Declaration) Validate() error
- type Description
- type Installer
- type Parts
- type ResolveRuntime
- type Runtime
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ObserverName ¶
ObserverName is the stable cleanup-observer name of model M, unique within a database across models and distinct from application observer names.
Types ¶
type Cleanup ¶
type Cleanup[M any] struct { // contains filtered or unexported fields }
Cleanup removes one hard-deleted owner's extension data. It runs the existing metadata, translation and attachment cleanup for every configured manager, so data written through the explicit APIs with the same owner is removed too. Soft deletion preserves data. When the deletion transaction belongs to the extension store's pool, cleanup joins it and rolls back with it. Otherwise it cannot share that transaction. With Runtime.CleanupQueue it enqueues CleanupJob in the deletion's transaction, which commits or rolls back with the deletion and survives a crash. Without it, cleanup runs after the deletion commits, in a store transaction that skips an owner that exists again; a failure there is the committed deletion's after-commit error, and the orphan inspection and pruning commands are the backstop, including for a crash before it ran.
func NewCleanup ¶
func NewCleanup[M any, K comparable](runtime Runtime, owner extensions.Owner[M, K], parts Parts, reference func(M) model.Reference[M, K]) (Cleanup[M], error)
NewCleanup binds the runtime once during construction. A slot kind whose manager is absent fails here instead of silently skipping cleanup.
func (Cleanup[M]) Deleted ¶
func (c Cleanup[M]) Deleted(ctx context.Context, tx *database.Tx, before value.Optional[M], operation value.Optional[lifecycle.Operation]) error
Deleted is the generated observer's Deleted callback body. It also runs for force deletion; soft deletion returns without changes.
type CleanupJob ¶
type CleanupJob struct {
// contains filtered or unexported fields
}
CleanupJob settles the extension data of models deleted through a connection other than the extension store's. The deletion enqueues it in its own transaction through the outbox, so a rollback leaves no job and a crash after commit loses none. Its handler is idempotent: in a store transaction it skips an owner that exists again and otherwise runs every configured manager's cleanup, which finds nothing left on a repeated delivery.
func DefineCleanupJob ¶
func DefineCleanupJob(name jobs.Name, policy jobs.Policy) CleanupJob
func (CleanupJob) Declare ¶
func (j CleanupJob) Declare(runtime Runtime) (jobs.Declaration, error)
Declare is the direct-assembly form of Handler.
func (CleanupJob) Definition ¶
func (j CleanupJob) Definition() jobs.Definition[CleanupRequest]
Definition is the typed job, for registration with a job connection.
func (CleanupJob) Handler ¶
func (j CleanupJob) Handler(runtime Runtime) (jobs.Handler[CleanupRequest], error)
Handler binds the job to runtime's store and managers. It never uses runtime.CleanupQueue, so it can be declared before that queue exists.
type CleanupQueue ¶
type CleanupQueue struct {
// contains filtered or unexported fields
}
CleanupQueue enqueues CleanupJob through the outbox of the pool a deletion uses. Each producer must write the outbox that the application's publisher relays; applications give every pool that deletes owning models one.
func (*CleanupQueue) Validate ¶
func (q *CleanupQueue) Validate() error
type CleanupRequest ¶
type CleanupRequest struct {
Owner extensions.OwnerName `json:"owner"`
Identity model.Identity `json:"identity"`
}
CleanupRequest identifies one model deleted through a connection other than the extension store's: its registered owner and persisted identity.
type Declaration ¶
type Declaration struct {
// contains filtered or unexported fields
}
Declaration is one model's generated extension envelope: its owner, slot registrations by kind and deletion-cleanup observer. It is immutable and owns no global state.
func Declare ¶
func Declare(owner extensions.Declaration, parts Parts, install Installer) Declaration
Declare is called by generated <Model>ExtensionDeclaration functions.
func DeclareORM ¶
func DeclareORM[M any, K comparable](owner extensions.Owner[M, K], parts Parts) Declaration
DeclareORM registers slots and the ordinary deletion cleanup observer for an ORM owner. Example: slots.DeclareORM(owner,parts).
func (Declaration) Describe ¶
func (d Declaration) Describe() Description
Describe returns an owned snapshot for declaration inspection. It performs no I/O and resolves no service.
func (Declaration) Owner ¶
func (d Declaration) Owner() extensions.Declaration
Owner is the owner registration for the extension registry.
func (Declaration) Parts ¶
func (d Declaration) Parts() Parts
Parts returns an owned copy of the slot registrations.
func (Declaration) Register ¶
func (d Declaration) Register(r *foundation.Registrar, pool foundation.Key[*database.DB], resolve ResolveRuntime) error
Register installs the deletion-cleanup observer on a pool that writes the owning model. On the extension store's pool, cleanup joins the owner's deletion transaction; on another pool it runs after that transaction commits, which requires Runtime.Store.
func (Declaration) Validate ¶
func (d Declaration) Validate() error
Validate checks that the declaration retains an owner and cleanup registration.
type Description ¶
type Description struct {
Owner extensions.OwnerDescription `json:"owner"`
Slots []extensions.SlotDescription `json:"slots"`
}
Description is an owned inspection snapshot of one model's declaration.
type Installer ¶
type Installer func(*foundation.Registrar, foundation.Key[*database.DB], ResolveRuntime) error
Installer registers a generated model's deletion-cleanup observer on a pool.
type Parts ¶
type Parts struct {
Translations []translations.Registration
Attachments []attachments.Registration
Metadata []metadata.Registration
Slots []extensions.SlotDescription
}
Parts lists one model's slot registrations by kind, and each slot's inspection description in field order.
type ResolveRuntime ¶
type ResolveRuntime func(foundation.Resolver) (Runtime, error)
ResolveRuntime supplies the runtime while an application is constructed.
type Runtime ¶
type Runtime struct {
Translations *translations.Manager
Attachments *attachments.Manager
Metadata *metadata.Manager
Store *extensions.Store
CleanupQueue *CleanupQueue
}
Runtime borrows the managers that bound slot descriptors use. A nil manager leaves slots of that kind unbound; using one reports fault.Missing. Store is the managers' extension store; with it, deletion cleanup also handles owners deleted through another pool. CleanupQueue makes that cleanup durable by enqueueing CleanupJob in the deletion's transaction; without it the cleanup is process-local after-commit work. Only deletion observers need it: application assembly leaves it nil in the runtime ModelExtensions returns, so descriptors bound in job handlers never depend on the job dispatcher. The application owns these lifetimes; Runtime owns nothing.