Closed jpwilliams closed 8 months ago
Latest commit: 8ea53e2fb7c97b1ec74a4ffd323c331e51a81f5d
The changes in this PR will be included in the next version bump.
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 function: appID + "-" + functionID
?
Is this a breaking change for users already specifying
function: appID + "-" + functionID
?
Looks like this filters out empty strings before joining to make it backwards compatible
Is this a breaking change for users already specifying
function: appID + "-" + functionID
?Looks like this filters out empty strings before joining to make it backwards compatible
But client.id
will always be a string, right? Seems like setting function
to the full-qualified ID (with app ID) will result in a string twice prefixed with the app ID
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 areunknown
.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 areunknown
.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
.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