Skip to content
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

Ensure event payloads are typed as JSON #700

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion packages/inngest/src/components/Inngest.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -824,7 +824,7 @@ describe("createFunction", () => {
schemas: new EventSchemas().fromRecord<{
foo: {
name: "foo";
data: { title: string };
data: { title: string; date: Date };
};
bar: {
name: "bar";
Expand All @@ -847,6 +847,17 @@ describe("createFunction", () => {
});
});

test("JSONifies known event data", () => {
inngest.createFunction(
{ id: "test" },
{ event: "foo" },
({ event, events }) => {
assertType<string>(event.data.date);
assertType<string>(events[0].data.date);
}
);
});

test("allows name to be an object", () => {
inngest.createFunction(
{ id: "test" },
Expand Down
8 changes: 6 additions & 2 deletions packages/inngest/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,14 @@ import {
} from "./components/InngestMiddleware";
import { type createStepTools } from "./components/InngestStepTools";
import { type internalEvents } from "./helpers/consts";
import { type Jsonify } from "./helpers/jsonify";
import {
type AsTuple,
type IsEqual,
type IsNever,
type Public,
type Simplify,
type SimplifyDeep,
type WithoutInternal,
} from "./helpers/types";
import { type Logger } from "./middleware/logger";
Expand Down Expand Up @@ -360,8 +362,10 @@ export type BaseContext<
/**
* The event data present in the payload.
*/
event: GetContextEvents<TClient, TTriggers>;
events: AsTuple<GetContextEvents<TClient, TTriggers, true>>;
event: SimplifyDeep<Jsonify<GetContextEvents<TClient, TTriggers>>>;
events: AsTuple<
SimplifyDeep<Jsonify<GetContextEvents<TClient, TTriggers, true>>>
>;

/**
* The run ID for the current function execution
Expand Down
Loading