type

HookContext

Read the request and values available to a collection or global hook.

Properties

PropertyTypeDescription
Contextcontext.ContextContext carries cancellation, deadlines, and the active transaction. Pass it to Local calls that must succeed or roll back with this operation.
Operationoperation.KindOperation names the document operation, such as Create, Update, or Read, not the hook phase. Shared hooks should check it before running write-only work.
WritePhaseoperation.WritePhaseWritePhase identifies draft saves versus publication writes independently of the row's current public status.
CollectionIDschema.StableIDCollectionID is the collection's stable resource ID, not its slug. It is empty for a global operation.
GlobalIDschema.StableIDGlobalID is the global's stable resource ID, not its slug. It is empty for a collection operation.
Actor*store.DocumentActor is the authenticated document, or nil for an anonymous operation.
ActorCollectionschema.CollectionSlugActorCollection identifies the exact auth collection that owns Actor.
SystemboolSystem reports that trusted server code started this operation with System set, so no access rule ran. Nested Local calls do not inherit it: pass System again when the nested work is also trusted.
Datastore.ValuesData contains the values being saved. On an update it holds only the top-level fields the caller sent; Candidate adds the unchanged ones from Original. Change map entries to change stored values; assigning a new map to Data does not replace the engine's values. Changes after saving are not persisted.
Document*store.DocumentDocument is the response document when available. AfterRead receives each document in a list separately. Changes to Document.Values affect the response, not stored data, and remain subject to field read access rules.
Original*store.DocumentOriginal is a detached copy of the saved document before an update, delete, or duplication. Changing it does not change storage.
Local*LocalAPILocal performs nested reads and writes through the normal operation engine. Pass Context to reuse the transaction, and pass Actor, ActorCollection, and locale options explicitly when the nested operation represents the same user. Standalone reads reject nested writes; AfterCommit starts new transactions.
ErrorerrorError is set only for after-error hooks and preserves the original failure. Returning nil from AfterError does not make the failed operation succeed.
Localeschema.LocaleCodeLocale is the selected content language. Write hooks use the write locale; AfterRead uses the response locale, whose values may include fallback text.
AllLocalesboolAllLocales reports whether localized values contain maps keyed by locale. It describes this hook's values, which may differ from the requested response.

Full signature

Methods

  • HookContext.Candidate()

    Candidate returns the values the document will have once this write is saved: Original's values with each top-level entry of Data in their place. On a create it is a copy of Data. Use it to read a field whether or not the caller sent it, for example to check a rule that spans two fields on a partial update. The map is a detached copy; change Data, not the result, to change what is saved.

Related guides