Skip to content

Commit

Permalink
Merge branch 'main' into feat/invocation
Browse files Browse the repository at this point in the history
  • Loading branch information
jpwilliams committed Nov 20, 2023
2 parents 096ac18 + 79f0aeb commit 3ac600f
Show file tree
Hide file tree
Showing 21 changed files with 823 additions and 280 deletions.
14 changes: 7 additions & 7 deletions packages/inngest/etc/inngest.api.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions packages/inngest/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -161,14 +161,14 @@
"@types/ms": "^0.7.31",
"@types/node": "^18.16.16",
"@types/sha.js": "^2.4.0",
"@typescript-eslint/eslint-plugin": "^5.47.0",
"@typescript-eslint/parser": "^5.47.0",
"@typescript-eslint/eslint-plugin": "^6.0.0",
"@typescript-eslint/parser": "^6.0.0",
"@vercel/node": "^2.15.9",
"concurrently": "^7.4.0",
"eslint": "^8.30.0",
"eslint-config-prettier": "^8.5.0",
"eslint-config-prettier": "^9.0.0",
"eslint-plugin-import": "^2.27.5",
"eslint-plugin-prettier": "^4.2.1",
"eslint-plugin-prettier": "^5.0.0",
"express": "^4.18.2",
"fastify": "^4.21.0",
"genversion": "^3.1.1",
Expand All @@ -180,7 +180,7 @@
"nock": "^13.2.9",
"node-mocks-http": "^1.11.0",
"nodemon": "^2.0.20",
"prettier": "^2.7.1",
"prettier": "^3.1.0",
"shx": "^0.3.4",
"ts-jest": "^29.1.0",
"tsx": "^3.12.7",
Expand Down
11 changes: 7 additions & 4 deletions packages/inngest/scripts/integrationTestRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,10 +244,13 @@ async function runIntegrationTest(
exampleServerPort: number
): Promise<void> {
// Start a 10 minute timeout. If we don't finish within 10 minutes, something is wrong.
setTimeout(() => {
console.error("Integration test timed out");
process.exit(1);
}, 10 * 60 * 1000);
setTimeout(
() => {
console.error("Integration test timed out");
process.exit(1);
},
10 * 60 * 1000
);

const rootPath = path.join(__dirname, "..", "..", "..");
const sdkPath = path.join(rootPath, "packages", "inngest");
Expand Down
6 changes: 3 additions & 3 deletions packages/inngest/src/components/EventSchemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,8 @@ export type LiteralToRecordZodSchemas<T> = PickLiterals<
[I in keyof T as GetName<T[I]>]: InferZodShape<T[I]>;
}
: T extends ZodEventSchemas
? T
: never
? T
: never
>;

/**
Expand Down Expand Up @@ -177,7 +177,7 @@ export type StandardEventSchemaToPayload<T> = Simplify<{
*/
export type Combine<
TCurr extends Record<string, EventPayload>,
TInc extends StandardEventSchemas
TInc extends StandardEventSchemas,
> = IsStringLiteral<keyof TCurr & string> extends true
? Simplify<
Omit<TCurr, keyof StandardEventSchemaToPayload<TInc>> &
Expand Down
2 changes: 1 addition & 1 deletion packages/inngest/src/components/Inngest.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -762,7 +762,7 @@ describe("helper types", () => {

type GetUnionKeyValue<
T,
K extends string | number | symbol
K extends string | number | symbol,
> = T extends Record<K, infer U> ? U : never;

describe("type GetFunctionInput", () => {
Expand Down
16 changes: 8 additions & 8 deletions packages/inngest/src/components/Inngest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -347,8 +347,8 @@ export class Inngest<TOpts extends ClientOptions = ClientOptions> {
let payloads: EventPayload[] = Array.isArray(payload)
? (payload as EventPayload[])
: payload
? ([payload] as [EventPayload])
: [];
? ([payload] as [EventPayload])
: [];

const inputChanges = await hooks.transformInput?.({
payloads: [...payloads],
Expand Down Expand Up @@ -465,10 +465,10 @@ export class Inngest<TOpts extends ClientOptions = ClientOptions> {
[
typeof builtInMiddleware,
NonNullable<TOpts["middleware"]>,
TMiddleware
TMiddleware,
]
>
>
>,
>(
options: ExclusiveKeys<
Omit<
Expand All @@ -491,7 +491,7 @@ export class Inngest<TOpts extends ClientOptions = ClientOptions> {
[
typeof builtInMiddleware,
NonNullable<TOpts["middleware"]>,
TMiddleware
TMiddleware,
],
FailureEventArgs<EventsFromOpts<TOpts>[TTriggerName]>
>
Expand Down Expand Up @@ -683,7 +683,7 @@ export type GetStepTools<
// eslint-disable-next-line @typescript-eslint/no-explicit-any
TInngest extends Inngest<any>,
TTrigger extends keyof GetEvents<TInngest> &
string = keyof GetEvents<TInngest> & string
string = keyof GetEvents<TInngest> & string,
> = GetFunctionInput<TInngest, TTrigger> extends { step: infer TStep }
? TStep
: never;
Expand All @@ -708,7 +708,7 @@ export type GetFunctionInput<
// eslint-disable-next-line @typescript-eslint/no-explicit-any
TInngest extends Inngest<any>,
TTrigger extends keyof GetEvents<TInngest> &
string = keyof GetEvents<TInngest> & string
string = keyof GetEvents<TInngest> & string,
> = Parameters<
Handler<
ClientOptionsFromInngest<TInngest>,
Expand All @@ -717,7 +717,7 @@ export type GetFunctionInput<
ExtendWithMiddleware<
[
typeof builtInMiddleware,
NonNullable<ClientOptionsFromInngest<TInngest>["middleware"]>
NonNullable<ClientOptionsFromInngest<TInngest>["middleware"]>,
]
>
>
Expand Down
8 changes: 4 additions & 4 deletions packages/inngest/src/components/InngestCommHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ interface InngestCommHandlerOptions<
// eslint-disable-next-line @typescript-eslint/no-explicit-any
Output = any,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
StreamOutput = any
StreamOutput = any,
> extends RegisterOptions {
/**
* The name of the framework this handler is designed for. Should be
Expand Down Expand Up @@ -210,7 +210,7 @@ export class InngestCommHandler<
// eslint-disable-next-line @typescript-eslint/no-explicit-any
Output = any,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
StreamOutput = any
StreamOutput = any,
> {
/**
* The ID of this serve handler, e.g. `"my-app"`. It's recommended that this
Expand Down Expand Up @@ -1234,7 +1234,7 @@ export type Handler<
// eslint-disable-next-line @typescript-eslint/no-explicit-any
Output = any,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
StreamOutput = any
StreamOutput = any,
> = (...args: Input) => HandlerResponse<Output, StreamOutput>;

// eslint-disable-next-line @typescript-eslint/no-explicit-any
Expand Down Expand Up @@ -1304,7 +1304,7 @@ export type HandlerResponse<Output = any, StreamOutput = any> = {
* framework-compatible response by an {@link InngestCommHandler} instance.
*/
export interface ActionResponse<
TBody extends string | ReadableStream = string
TBody extends string | ReadableStream = string,
> {
/**
* The HTTP status code to return.
Expand Down
6 changes: 3 additions & 3 deletions packages/inngest/src/components/InngestFunction.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ describe("runFn", () => {
event?: EventPayload;
onFailure?: boolean;
},
U extends Record<keyof T["steps"], string>
U extends Record<keyof T["steps"], string>,
>(
fnName: string,
createTools: () => T,
Expand Down Expand Up @@ -449,8 +449,8 @@ describe("runFn", () => {
ret!.type === "step-ran"
? [ret!.step]
: ret!.type === "steps-found"
? ret!.steps
: [];
? ret!.steps
: [];

outgoingOps.forEach((op) => {
expect(op.id).toMatch(/^[a-f0-9]{40}$/i);
Expand Down
2 changes: 1 addition & 1 deletion packages/inngest/src/components/InngestFunction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export class InngestFunction<
Events,
EventNameFromTrigger<Events, Trigger>
> = FunctionOptions<Events, EventNameFromTrigger<Events, Trigger>>,
THandler extends AnyHandler = Handler<TOpts, Events, keyof Events & string>
THandler extends AnyHandler = Handler<TOpts, Events, keyof Events & string>,
> {
static stepId = "step";
static failureSuffix = "-failure";
Expand Down
50 changes: 27 additions & 23 deletions packages/inngest/src/components/InngestMiddleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,20 +73,20 @@ export class InngestMiddleware<TOpts extends MiddlewareOptions> {

type FnsWithSameInputAsOutput<
// eslint-disable-next-line @typescript-eslint/no-explicit-any
TRecord extends Record<string, (arg: any) => any>
TRecord extends Record<string, (arg: any) => any>,
> = {
[K in keyof TRecord as Await<TRecord[K]> extends Parameters<TRecord[K]>[0]
? K
: Await<TRecord[K]> extends void | undefined
? Parameters<TRecord[K]>[0] extends void | undefined
? K
: never
: never]: TRecord[K];
? Parameters<TRecord[K]>[0] extends void | undefined
? K
: never
: never]: TRecord[K];
};

type PromisifiedFunctionRecord<
// eslint-disable-next-line @typescript-eslint/no-explicit-any
TRecord extends Record<string, (arg: any) => any>
TRecord extends Record<string, (arg: any) => any>,
> = Pick<
Partial<{
[K in keyof TRecord]: (
Expand Down Expand Up @@ -124,7 +124,8 @@ export const getHookStack = async <
TMiddleware extends Record<string, (arg: any) => any>,
TKey extends keyof TMiddleware,
TResult extends Await<TMiddleware[TKey]>,
TRet extends PromisifiedFunctionRecord<TResult> = PromisifiedFunctionRecord<TResult>
TRet extends
PromisifiedFunctionRecord<TResult> = PromisifiedFunctionRecord<TResult>,
>(
/**
* The stack of middleware that will be used to run hooks.
Expand Down Expand Up @@ -152,26 +153,29 @@ export const getHookStack = async <
[K in keyof TResult as Await<TResult[K]> extends Parameters<TResult[K]>[0]
? K
: Await<TResult[K]> extends void | undefined
? Parameters<TResult[K]>[0] extends void | undefined
? K
: never
: never]: void;
? Parameters<TResult[K]>[0] extends void | undefined
? K
: never
: never]: void;
}
>
): Promise<TRet> => {
// Wait for middleware to initialize
const mwStack = await middleware;

// Step through each middleware and get the hook for the given key
const keyFns = mwStack.reduce((acc, mw) => {
const fn = mw[key];
const keyFns = mwStack.reduce(
(acc, mw) => {
const fn = mw[key];

if (fn) {
return [...acc, fn];
}
if (fn) {
return [...acc, fn];
}

return acc;
}, [] as NonNullable<TMiddleware[TKey]>[]);
return acc;
},
[] as NonNullable<TMiddleware[TKey]>[]
);

// Run each hook found in sequence and collect the results
const hooksRegistered = await keyFns.reduce<
Expand Down Expand Up @@ -473,7 +477,7 @@ type MiddlewareRunOutput = (ctx: {
* @internal
*/
type GetMiddlewareRunInputMutation<
TMiddleware extends InngestMiddleware<MiddlewareOptions>
TMiddleware extends InngestMiddleware<MiddlewareOptions>,
> = TMiddleware extends InngestMiddleware<infer TOpts>
? TOpts["init"] extends MiddlewareRegisterFn
? Await<
Expand All @@ -495,7 +499,7 @@ type GetMiddlewareRunInputMutation<
* @internal
*/
type GetMiddlewareSendEventOutputMutation<
TMiddleware extends InngestMiddleware<MiddlewareOptions>
TMiddleware extends InngestMiddleware<MiddlewareOptions>,
> = TMiddleware extends InngestMiddleware<infer TOpts>
? TOpts["init"] extends MiddlewareRegisterFn
? Await<
Expand All @@ -518,7 +522,7 @@ type GetMiddlewareSendEventOutputMutation<
*/
export type MiddlewareStackSendEventOutputMutation<
TContext,
TMiddleware extends MiddlewareStack
TMiddleware extends MiddlewareStack,
> = ObjectAssign<
{
[K in keyof TMiddleware]: GetMiddlewareSendEventOutputMutation<
Expand All @@ -531,7 +535,7 @@ export type MiddlewareStackSendEventOutputMutation<
export type ExtendWithMiddleware<
TMiddlewareStacks extends MiddlewareStack[],
// eslint-disable-next-line @typescript-eslint/ban-types
TContext = {}
TContext = {},
> = ObjectAssign<
{
[K in keyof TMiddlewareStacks]: MiddlewareStackRunInputMutation<
Expand All @@ -548,7 +552,7 @@ export type ExtendWithMiddleware<
*/
export type MiddlewareStackRunInputMutation<
TContext,
TMiddleware extends MiddlewareStack
TMiddleware extends MiddlewareStack,
> = ObjectAssign<
{
[K in keyof TMiddleware]: GetMiddlewareRunInputMutation<TMiddleware[K]>;
Expand Down
1 change: 1 addition & 0 deletions packages/inngest/src/components/InngestStepTools.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,7 @@ describe("sendEvent", () => {
typeof createStepTools<typeof opts, EventsFromOpts<typeof opts>, "foo">
>["invoke"];

// eslint-disable-next-line @typescript-eslint/no-explicit-any
type GetTestReturn<T extends () => InvocationResult<any>> = Awaited<
ReturnType<T>
>;
Expand Down
Loading

0 comments on commit 3ac600f

Please sign in to comment.