inngest / inngest

A scalable, low-latency, event-driven durable execution platform. Supports functions deployed to serverless, servers, or the edge.
https://www.inngest.com/docs
Other
1.7k stars 68 forks source link

Support wildcard event triggers e.g. `something/*` #326

Closed djfarrelly closed 1 year ago

djfarrelly commented 1 year ago

Describe the bug In Inngest Cloud, wildcard event triggers are supported, but they are not well supported in the SDK or CLI.

To Reproduce Steps to reproduce the behavior:

  1. Create a function w/ the event trigger test/*
  2. Send an event to the dev server test/whatever and test/another
  3. No function gets run

Expected behavior I expect the functions to run.

I had to create a combination event type for the SDK to work correctly. Example:

export const inngest = new Inngest<
  Events<{
    "test/*": Test__Whatever | Test__Another;
  }>
>({
  name: "App",
});

Screenshots / Stack trace dump n/a

System info

Additional context n/a

jpwilliams commented 1 year ago

This is cool.

Can the wildcards be anywhere, e.g. test/so*thing? Or is it limited to scope/*?

We could look at template types, perhaps, though I think that's usually based on calculating all permutations of the given variables, so it might struggle here if the wildcards can be anywhere.

At the very least we could look at providing scope/* helpers which just roll up potential types within that scope as you've done here.

Or even helpers for app/user.*; for every separator, be it / or ..

🤔

djfarrelly commented 1 year ago

I believe the wildcard is only valid at the end of a trigger to work as expected. (Since event triggers are strings, really anything can be accepted by the API). I think the key thing would be to ensure this works in the dev server repo and then we can document how to do it with the SDK manually or otherwise.

tonyhb commented 1 year ago

Handled, though types are necessary. cc @jpwilliams on the SDK