Functions: Functions new document change events and filtering options!

We are excited to give developers more document change events to trigger their Functions! The new events are:

create: Emitted when a document is created.

delete: Emitted when a document is deleted.

update: Emitted when a document is updated.

Additionally, two new boolean toggles are available when defining the triggering event for your Functions:

includeDrafts: Whether the event should be emitted with respect to draft documents. Defaults to false.

includeAllVersions: Whether the event should be emitted with respect to version documents (documents part of a Content Release). Defaults to false.

Keep in mind that combining update with includeDrafts and/or includeAllVersions may result in many, rapid invocations—every edit to a draft or version document will trigger your function, not just when they are published. See the rate limits and use with caution.

Note that these new events and options overlaps with the existing publish event. In fact, publish is equivalent to on: ['create', 'update'].

The publish event was an early beta attempt at encapsulating a useful, initial first-pass at a Functions source event.

These new additions set up a deprecation of the publish event, so keep an eye out for that to officially land sometime in the near future. If you want to get ahead of things, you can update any existing function events that use on: ['publish'] to instead use the on and includeAllVersions values mentioned above—or make them more specific for your needs.

Support for these new events and filters landed in the following tools under the specified versions. Upgrade to at least these versions to take advantage of the changes:

@sanity/blueprints v0.2.0

sanity CLI v4.5.0