-
Notifications
You must be signed in to change notification settings - Fork 35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow specifying function
with appId
when invoking
#449
Conversation
🦋 Changeset detectedLatest commit: 8ea53e2 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Is this a breaking change for users already specifying |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM - great work :)
Looks like this filters out empty strings before joining to make it backwards compatible |
But |
This PR was opened by the [Changesets release](https://github.com/changesets/action) GitHub action. When you're ready to do a release, you can merge this and the packages will be published to npm automatically. If you're not ready to do a release yet, that's fine, whenever you add more changesets to main, this PR will be updated. # Releases ## inngest@3.10.0 ### Minor Changes - [#449](#449) [`a452cf1`](a452cf1) Thanks [@jpwilliams](https://github.com/jpwilliams)! - Add `referenceFunction()`, allowing easier, typed invocation of functions across apps and languages - [#459](#459) [`eec41d2`](eec41d2) Thanks [@jpwilliams](https://github.com/jpwilliams)! - Add new `Inngest.Any` and `InngestFunction.Any` type helpers ### Patch Changes - [#460](#460) [`a225206`](a225206) Thanks [@MonsterDeveloper](https://github.com/MonsterDeveloper)! - Add exports for `FinishedEventPayload` and `Context` types to fix a TypeScript error when using Inngest in projects with `composite` setting in `tsconfig`. Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Summary
When using
step.invoke()
, the providedfunction
option can be either anInngestFunction
instance or astring
.In the latter case, the user is required to also include the ID of the app being called, which is unclear. This PR makes a few changes to accommodate this nicety.
Awkwardly, the functionality of
function: string
must stay the same to avoid a breaking change. This makes adding a newfunctionId
option a bit confusing, as now I can specify bothfunction: string
andfunctionId: string
.A related issue for invocation is wanting to import only a function's types to avoid also importing all of another function's dependencies when invoking. This also applies to cross-app invocation, where a user may want to invoke a function using a string ID and simultaneously provide typing or schemas for validating input/output.
This change requires some form of referencing a function using only an ID and relying on either the types of an
InngestFunction
instance or some inputted types/schemas.Broadly, we add a new
referenceFunction
export (I don't like the name of it) which can be passed in as thefunction
being invoked. We should also deprecate use offunction: string
and prefer creating areferenceFunction
.Currently, and unchanged to avoid a breaking change
A "full" function ID, which is
[clientId]-[functionId]
.Input and output types are
unknown
.Currently, and unchanged
Input and output types are known.
Referencing a function using an existing function instance
No dependencies of the target function are imported.
The function ID must be provided at runtime, but we can enforce that this is the literal ID given to the function, i.e.
functionId: "some-fn"
instead of justfunctionId: string
.Input and output types are known.
Referencing some external function by ID
The app ID of the client executing the call is used, as we don't specify an
appId
.Input and output types are
unknown
.Referencing some external function by ID and app ID
We specify an app ID here to form the full ID instead of using the executing client's ID.
Input and output types are
unknown
.Specifying types for the input and output of a reference function
We can also provide input and output schemas to add typing to our reference function, which adds types to the required input and output of
step.invoke()
.Providing a
schema
is optional and you can also choose to provide only aninput
or only anoutput
.Note
If you've passed an actual Inngest function like
referenceFunction<typeof someFn>({ ... })
, you cannot add additionalschemas
.For the purposes of this example, we use Zod, but this will expand to allow many validation libraries (or types directly) in the future. This will complement being able to provide schemas on a function directly in the future, as well as validating I/O instead of only using types.
Reusing reference functions
It's likely healthy for a user to declare reference functions the same way they do all of their others, meaning importing and invoking it is the same experience for both local and remote functions.
For example, if a local function is declared like so:
Then a remote function may be declared like so:
In both instances, the function is then simply imported and invoked.
Checklist
function: string
when invoking; deprecate in v4input
todata
output
toreturn
function_id
andapp_id
are sent during invocationfunction_id
andapp_id
should be sent togetherRelated
referenceFunction()
website#624