type
CollectionHooks
type CollectionHooks struct {
// BeforeDuplicate runs after the source is access-checked and copied but before validation.
BeforeDuplicate []Hook
// BeforeValidate runs before field validation.
BeforeValidate []Hook
// BeforeChange runs after validation for create, duplicate, update, publish, and unpublish.
BeforeChange []Hook
// BeforeOperation runs after validation but before persistence.
BeforeOperation []Hook
// BeforeRead runs before one or many documents are read.
BeforeRead []Hook
// BeforeDelete runs after the original document is loaded but before deletion.
BeforeDelete []Hook
// AfterChange runs inside the transaction after a changed document is persisted.
AfterChange []Hook
// AfterRead runs after computed values resolve and before field redaction.
AfterRead []Hook
// AfterDelete runs inside the transaction after deletion or trashing.
AfterDelete []Hook
// AfterOperation runs inside the transaction after persistence.
AfterOperation []Hook
// AfterError runs when an operation associated with this resource fails.
AfterError []Hook
// AfterCommit runs only after the transaction commits successfully.
AfterCommit []Hook
}Ordered lifecycle hooks for a collection.
BeforeDuplicate[]Hook- Prepare a copied document before validation.
BeforeValidate[]Hook- Normalize values before validation.
BeforeChange[]Hook- Derive values before persistence.
BeforeOperation[]Hook- Run immediately before storage.
BeforeRead[]Hook- Prepare document reads.
BeforeDelete[]Hook- Run before a loaded document is deleted.
AfterChange[]Hook- React to persistence inside the transaction.
AfterRead[]Hook- Decorate a result before field redaction.
AfterDelete[]Hook- React to deletion inside the transaction.
AfterOperation[]Hook- Run before the operation commits.
AfterError[]Hook- Observe resource failures.
AfterCommit[]Hook- Run after a successful commit.
Each hook slice runs in order. In FieldHooks, BeforeRead and AfterError remain resource-level phases, and map order across paths is not significant.
Example
var Posts = ridu.Collection{
Hooks: ridu.CollectionHooks{
BeforeValidate: []ridu.Hook{trimTitle},
BeforeChange: []ridu.Hook{recordEditor},
AfterCommit: []ridu.Hook{reindexPost},
},
}