type

Hooks

Hooks registers transforms and event callbacks for one field. Each list runs in declaration order for each field occurrence, including nested array rows. Collection or global hooks run first in the same phase, except AfterCommit, where field callbacks run first. Use ReadHooks for response transformations.

Properties

PropertyTypeDescription
BeforeDuplicate[]RawTransformBeforeDuplicate receives raw copied input before validation. It runs only when duplicating a collection document, after the resource hook.
BeforeValidate[]RawTransformBeforeValidate receives raw input before built-in validation. It can supply or normalize a value before conversion to T. This shared phase also runs on reads and deletes; check the context's Operation for write-only logic.
BeforeChange[]Transform[T]BeforeChange transforms T after initial built-in checks on create, duplicate, update, publish, and unpublish. Custom validators run later.
BeforeOperation[]Transform[T]BeforeOperation transforms T before the store operation, after BeforeChange on writes. This shared phase also runs on reads and deletes.
BeforeDelete[]Observer[T]BeforeDelete observes the saved value before trashing or permanent deletion.
AfterChange[]Observer[T]AfterChange observes a saved create, duplicate, update, publish, or unpublish before commit. It cannot replace the field; an error rolls back the save.
AfterDelete[]Observer[T]AfterDelete observes a value after trashing or permanent deletion but before commit. An error can still roll back the deletion.
AfterOperation[]Observer[T]AfterOperation observes the result before response processing and commit. It also runs on reads and deletes; check Operation for write-only work.
AfterCommit[]Observer[T]AfterCommit observes the value outside the committed transaction, before resource AfterCommit hooks. It also runs for reads. Errors cannot roll back saved data, and later effects still run.

Full signature

type Hooks[T any] struct { // BeforeDuplicate receives raw copied input before validation. It runs only // when duplicating a collection document, after the resource hook. BeforeDuplicate []RawTransform // BeforeValidate receives raw input before built-in validation. It can supply // or normalize a value before conversion to T. This shared phase also runs on // reads and deletes; check the context's Operation for write-only logic. BeforeValidate []RawTransform // BeforeChange transforms T after initial built-in checks on create, // duplicate, update, publish, and unpublish. Custom validators run later. BeforeChange []Transform[T] // BeforeOperation transforms T before the store operation, after BeforeChange // on writes. This shared phase also runs on reads and deletes. BeforeOperation []Transform[T] // BeforeDelete observes the saved value before trashing or permanent deletion. BeforeDelete []Observer[T] // AfterChange observes a saved create, duplicate, update, publish, or unpublish // before commit. It cannot replace the field; an error rolls back the save. AfterChange []Observer[T] // AfterDelete observes a value after trashing or permanent deletion but before // commit. An error can still roll back the deletion. AfterDelete []Observer[T] // AfterOperation observes the result before response processing and commit. // It also runs on reads and deletes; check Operation for write-only work. AfterOperation []Observer[T] // AfterCommit observes the value outside the committed transaction, before // resource AfterCommit hooks. It also runs for reads. Errors cannot roll back // saved data, and later effects still run. AfterCommit []Observer[T] }

Source field/policy.go:69