type
HookContext
type HookContext struct {
// Context is the request-scoped cancellation and deadline context.
Context context.Context
// Operation is the lifecycle operation currently running.
Operation Operation
// CollectionID is the stable identity of the target collection.
CollectionID schema.StableID
// GlobalID is the stable identity of the target global, when applicable.
GlobalID schema.StableID
// Actor is the authenticated document, or nil for an anonymous operation.
Actor *store.Document
// ActorCollection identifies the exact auth collection that owns Actor.
ActorCollection schema.CollectionSlug
// Data contains mutable incoming values before persistence.
Data store.Values
// Document is the current operation result when available.
Document *store.Document
// Original is the persisted document before an update or delete.
Original *store.Document
// Local exposes nested operations through the same operation engine.
Local *LocalAPI
// FieldPath is set when a hook is registered for a specific field.
FieldPath string
// Error is set only for after-error hooks and preserves the original failure.
Error error
Locale schema.LocaleCode
AllLocales bool
}Transactional operation state passed to lifecycle hooks.
Contextcontext.Context- Cancellation, deadline, and transaction context.
OperationOperation- The active lifecycle operation.
CollectionIDschema.StableID- Target collection identity.
GlobalIDschema.StableID- Target global identity, when applicable.
Actor*store.Document- Authenticated actor, or nil.
ActorCollectionschema.CollectionSlug- ActorCollection identifies the exact auth collection that owns Actor.
Datastore.Values- Mutable incoming values.
Document*store.Document- Current operation result.
Original*store.Document- Document before update or delete.
Local*LocalAPI- Nested operations; pre-commit phases reuse the transaction.
FieldPathstring- Path for a field-scoped hook.
Errorerror- Original failure for AfterError.
Localeschema.LocaleCode- Selected locale.
AllLocalesbool- Whether every locale is selected.
Most applications import the ridu.HookContext alias from the root package. AfterCommit and AfterError run outside the original transaction.
Example
func writeAuditEntry(ctx ridu.HookContext) error {
if ctx.Document == nil {
return nil
}
_, err := ctx.Local.Create(ctx.Context, "audit-log", store.Values{
"document": store.String(ctx.Document.ID),
}, ctx.Actor)
return err
}