Skip to content

feat(pulse-core): add filter predicate to EventEngine.subscribe()#241

Open
Jayking40 wants to merge 1 commit intodetermined-001:mainfrom
Jayking40:main
Open

feat(pulse-core): add filter predicate to EventEngine.subscribe()#241
Jayking40 wants to merge 1 commit intodetermined-001:mainfrom
Jayking40:main

Conversation

@Jayking40
Copy link
Copy Markdown

# feat(pulse-core): EventEngine.subscribe() filter predicate

## Summary

Consumers that need only a subset of events (e.g. payments above a
threshold, only USDC transfers) previously had to receive every event
and discard unwanted ones in their own code. This change moves that gate
inside the engine so events that will never be consumed are suppressed
before they are emitted.

An optional [filter](cci:1://file:///home/jayking/projects/orbital_stellar/packages/pulse-core/test/pulse-core.test.ts:473:8-473:65) predicate can now be passed at subscribe time:

```ts
const watcher = engine.subscribe("GABC...", {
  filter: (event) =>
    event.type === "payment.received" && Number(event.amount) >= 100,
});

Only events for which filter returns true are delivered to that
watcher. All watchers without a filter behave exactly as before.

Changes

  • New SubscribeOptions type exported from the package — carries the
    optional filter predicate so callers get full TypeScript support.
  • subscribe(address, options?) — extended signature stores the
    predicate in a per-address filters map; the existing stop handler
    now also removes the entry from that map when the watcher is stopped.
  • passesFilter(address, event) — private helper that invokes the
    predicate inside a try/catch. A throwing predicate is treated as a
    rejection and a [pulse-core] warning is logged; the engine keeps
    running.
  • route() — calls passesFilter() once per watcher before
    emitting both the specific event type and the * wildcard. The
    payment-type resolution was also deduplicated as a minor side-effect.
  • Three new unit tests covering all three required scenarios:
    filter accepts, filter rejects, and filter throws (engine survives).

Testing

The full @orbital/pulse-core test suite was run with:

pnpm --filter @orbital/pulse-core test

Result: 17 tests pass, 0 failures.

New tests added under describe("subscribe() filter predicate"):

Test Scenario
delivers events to a watcher whose filter returns true Happy path — matching event reaches the handler
suppresses events for a watcher whose filter returns false Reject path — no handler fires, neither on specific type nor *
treats a throwing filter as a reject and logs a warning Safety path — handler suppressed, warning logged, engine routes subsequent events normally

Closes #83

@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 28, 2026

@Jayking40 is attempting to deploy a commit to the determined's projects Team on Vercel.

A member of the Team first needs to authorize it.

@drips-wave
Copy link
Copy Markdown

drips-wave Bot commented Apr 28, 2026

@Jayking40 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1.23 — EventEngine.subscribe(address, { filter }) predicate filtering

1 participant