type

CollectionHooks

CollectionHooks configures resource-level callbacks through Collection.Hooks or Global.Hooks. Use BeforeChange to change values before a save, AfterRead to change a response without changing storage, and AfterCommit for effects that must run only after a successful commit. Each list runs in declaration order. Resource hooks run before field hooks in the same phase, except AfterCommit, where field hooks run first. Globals do not support BeforeDuplicate, BeforeDelete, or AfterDelete.

Properties

PropertyTypeDescription
BeforeDuplicate[]HookBeforeDuplicate runs after the source is access-checked and copied but before validation.
BeforeValidate[]HookBeforeValidate runs before field hooks and built-in checks for create, duplicate, update, publish, and unpublish. On updates, Data contains only the submitted fields.
BeforeChange[]HookBeforeChange runs after initial built-in validation for create, duplicate, update, publish, and unpublish. Changes to Data are checked again afterward; custom field validators run after the write hooks finish.
BeforeOperation[]HookBeforeOperation runs before the store operation, including reads and deletes. On writes it follows BeforeChange; changed values are validated before saving.
BeforeRead[]HookBeforeRead runs before one or many documents are read.
BeforeDelete[]HookBeforeDelete runs after the original document is loaded but before deletion.
AfterChange[]HookAfterChange runs after create, duplicate, update, publish, or unpublish has saved the document, but before commit. Returning an error rolls back the save.
AfterRead[]HookAfterRead runs for each response document, including mutation responses, after computed fields resolve and before field read access removes values.
AfterDelete[]HookAfterDelete runs inside the transaction after deletion or trashing.
AfterOperation[]HookAfterOperation runs after the store operation, including reads and deletes, but before response processing and commit. Errors can still roll back writes.
AfterError[]HookAfterError observes a failure in this resource through Error. It cannot suppress that failure; its own error is added to the returned error.
AfterCommit[]HookAfterCommit runs after a change commits: creates, duplicates, updates, publishing, deletes, and restores, but never reads. It runs outside the transaction; failures cannot roll back saved data, and later effects still run.

Full signature

type CollectionHooks struct { // BeforeDuplicate runs after the source is access-checked and copied but before validation. BeforeDuplicate []Hook // BeforeValidate runs before field hooks and built-in checks for create, // duplicate, update, publish, and unpublish. On updates, Data contains only // the submitted fields. BeforeValidate []Hook // BeforeChange runs after initial built-in validation for create, duplicate, // update, publish, and unpublish. Changes to Data are checked again afterward; // custom field validators run after the write hooks finish. BeforeChange []Hook // BeforeOperation runs before the store operation, including reads and deletes. // On writes it follows BeforeChange; changed values are validated before saving. 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 after create, duplicate, update, publish, or unpublish has // saved the document, but before commit. Returning an error rolls back the save. AfterChange []Hook // AfterRead runs for each response document, including mutation responses, // after computed fields resolve and before field read access removes values. AfterRead []Hook // AfterDelete runs inside the transaction after deletion or trashing. AfterDelete []Hook // AfterOperation runs after the store operation, including reads and deletes, // but before response processing and commit. Errors can still roll back writes. AfterOperation []Hook // AfterError observes a failure in this resource through Error. It cannot // suppress that failure; its own error is added to the returned error. AfterError []Hook // AfterCommit runs after a change commits: creates, duplicates, updates, // publishing, deletes, and restores, but never reads. It runs outside the // transaction; failures cannot roll back saved data, and later effects still run. AfterCommit []Hook }

Source core/hook.go:123