Event Filters
They are declarative pattern-matching rules, modeled after AWS EventBridge patterns.
Given the following custom event payload:
The following event filter would match the event:
For an event pattern to match an event, the event must contain all the field names listed in the event pattern. The field names must also appear in the event with the same nesting structure.
The value of each field name in the event pattern must be an array of strings, numbers, or booleans. The event pattern matches the event if the value of the field name in the event is equal to any of the values in the array.
Effectively, each array is an OR condition, and the entire event pattern is an AND condition.
So the above event filter will match because status == "ACCEPTED"
, and it would also match if status == "REJECTED"
.
String Filters
String filters are used to match string values within the event payload. You can filter events based on exact string matches, case-insensitive matches, starts-with, ends-with, and more.
Examples:
name: ["John"]
: Triggers the job if the name field in the event payload is exactly “John”.name: [{ $startsWith: "Jo" }]
: Triggers the job if the name field starts with “Jo”.name: [{ $endsWith: "hn" }]
: Triggers the job if the name field ends with “hn”.name: [{ $ignoreCaseEquals: "john" }]
: Triggers the job if the name field is equal to “john” regardless of case.
Examples
Boolean Filters
Boolean filters are used to filter events based on boolean values within the event payload.
Examples:
paidPlan: [true]
: Triggers the job if thePaidPlan
field in the event payload istrue
.isAdmin: [false]
: Triggers the job if theisAdmin
field in the event payload isfalse
.
Examples
Number Filters
Number filters are used to filter events based on numeric values within the event payload. It can also be used to perform numeric comparisons on values within the event payload.
Examples:
age [18]
: Triggers the job if theage
field in the event payload is equal to18
.score: [{ $gt: 90 }]
: Triggers the job if the score field is greater than90
.score: [{ $gte: 90 }]
: Triggers the job if the score field is greater than or equal to90
.score: [{ $lt: 90 }]
: Triggers the job if the score field is less than90
.score: [{ $lte: 90 }]
: Triggers the job if the score field is less than or equal to90
.age: [{ $gt: 20 }, { $lt: 40 }]
: Triggers the job if theage
field is greater than 20 and less than 40.score: [{ $between: [90, 110] }]
: Triggers the job if thescore
field is between 90 and 110.
Examples
Array Filters
Array filters are used to filter events based on the content of arrays within the event payload.
Examples:
hobbies: [{ $includes: "reading" }]
: Triggers the job if the hobbies array includes the value “reading”.
Examples
Existence Filters
Existence filters are used to filter events based on the presence or absence of certain keys within the event payload.
Examples:
name: [{ $exists: true }]
: Triggers the job if thename
field exists in the event payload.foo: [{ $exists: false }]
: Triggers the job if the foo field does not exist in the event payload.
Examples
Combining Filters
Filters can be combined to create more complex conditions for triggering jobs.
Examples:
name: ["Alice"], age: [30]
: Triggers the job if the name is “Alice” and the age is 30.name: ["Alice"], age: [{ $gt: 20 }, { $lt: 40 }]
: Triggers the job if the name is “Alice” and the age is between 20 and 40.name: ["Alice", "Bob"]
: Triggers the job if the name is either “Alice” or “Bob”.name: ["Alice", "Bob"], age: [30]
: Triggers the job if the name is either “Alice” or “Bob” and the age is 30.
Examples
Using with Stripe triggers
Here is an example of a Stripe Trigger with an Event Filter:
The job is triggered by the onCustomerSubscriptionCreated
event from Stripe. It is configured to trigger only when certain conditions are met. In this case, the job is triggered when a subscription is created with the following condition:
- Currency: Only subscriptions with the currency “USD” will trigger this job.
Using with Supabase triggers
Here is an example of a Supabase Trigger with an Event Filter:
- This Listens for insert events in the “objects” table of the “storage” schema.
- Conditions for Triggering:
- Object belongs to “example_bucket”.
- Object’s name ends with “.png”.
- Object’s path includes the token “images”.
Was this page helpful?