镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

Commit eb69f51

Browse files
committed
fix(core): evaluate nested $exists filters under missing parents
eventFilterMatches returned false for any non-empty filter as soon as the payload was undefined or null, before the filter itself was evaluated. That made a nested $exists: false filter fail when a parent key was absent or null, even though a missing child is exactly what $exists: false asserts. Reachable through retry.fetch bodyFilter on response bodies.
1 parent 9f8cc32 commit eb69f51

3 files changed

Lines changed: 20 additions & 5 deletions

File tree

‎.changeset/nested-exists-filter.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@trigger.dev/core": patch
3+
---
4+
5+
Fix `bodyFilter` in `retry.fetch` not matching when a nested `$exists: false` filter sits under a parent key that is missing or null in the response body.

‎packages/core/src/eventFilterMatches.ts‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,9 @@ import type { EventFilter } from "./schemas/eventFilter.js";
66
// An example would be [{ $endsWith: ".png" }, { $startsWith: "images/" } ]
77
export function eventFilterMatches(payload: any, filter: EventFilter): boolean {
88
if (payload === undefined || payload === null) {
9-
if (Object.entries(filter).length === 0) {
10-
return true;
11-
} else {
12-
return false;
13-
}
9+
// A missing or null payload means none of its keys exist either, so the
10+
// filter still has to be evaluated: { a: [{ $exists: false }] } must match.
11+
payload = {};
1412
}
1513

1614
for (const [patternKey, patternValue] of Object.entries(filter)) {

‎packages/core/test/eventFilterMatches.test.ts‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,18 @@ describe("eventFilterMatches", () => {
209209
expect(eventFilterMatches(payload, filter)).toBe(true);
210210
});
211211

212+
it("should return true for nested $exists = false when the parent key is missing or null", () => {
213+
const filter: EventFilter = {
214+
user: {
215+
email: [{ $exists: false }],
216+
},
217+
};
218+
expect(eventFilterMatches({}, filter)).toBe(true);
219+
expect(eventFilterMatches({ user: null }, filter)).toBe(true);
220+
expect(eventFilterMatches({ user: {} }, filter)).toBe(true);
221+
expect(eventFilterMatches({ user: { email: "a@example.com" } }, filter)).toBe(false);
222+
});
223+
212224
it("should return true when payload does match numeric condition", () => {
213225
const payload = {
214226
name: "John",

0 commit comments

Comments
 (0)