diff --git a/.changeset/mean-brooms-pull.md b/.changeset/mean-brooms-pull.md new file mode 100644 index 00000000..ef1a7a1d --- /dev/null +++ b/.changeset/mean-brooms-pull.md @@ -0,0 +1,5 @@ +--- +"inngest": patch +--- + +Expose `EventSchemas` in `Inngest` instances diff --git a/packages/inngest/src/components/EventSchemas.ts b/packages/inngest/src/components/EventSchemas.ts index 031b210a..8ccee701 100644 --- a/packages/inngest/src/components/EventSchemas.ts +++ b/packages/inngest/src/components/EventSchemas.ts @@ -248,6 +248,15 @@ export class EventSchemas< [internalEvents.ScheduledTimer]: ScheduledTimerEventPayload; }>, > { + protected runtimeSchemas: Record = {}; + + private addRuntimeSchemas(schemas: Record) { + this.runtimeSchemas = { + ...this.runtimeSchemas, + ...schemas, + }; + } + /** * Use generated Inngest types to type events. */ @@ -343,7 +352,6 @@ export class EventSchemas< * ``` */ public fromZod( - // eslint-disable-next-line @typescript-eslint/no-unused-vars schemas: T ): EventSchemas< Combine< @@ -353,6 +361,26 @@ export class EventSchemas< > > > { + let runtimeSchemas: Record; + + if (Array.isArray(schemas)) { + runtimeSchemas = schemas.reduce((acc, schema) => { + const { + name: { value: name }, + ...rest + } = schema.shape; + + return { + ...acc, + [name]: rest, + }; + }, {}); + } else { + runtimeSchemas = schemas; + } + + this.addRuntimeSchemas(runtimeSchemas); + return this; } } diff --git a/packages/inngest/src/components/Inngest.ts b/packages/inngest/src/components/Inngest.ts index f365f96d..54907ac1 100644 --- a/packages/inngest/src/components/Inngest.ts +++ b/packages/inngest/src/components/Inngest.ts @@ -151,6 +151,8 @@ export class Inngest { */ private _mode!: Mode; + protected readonly schemas?: NonNullable; + get apiBaseUrl(): string | undefined { return this._apiBaseUrl; } @@ -192,6 +194,7 @@ export class Inngest { logger = new DefaultLogger(), middleware, isDev, + schemas, } = this.options; if (!id) { @@ -216,6 +219,7 @@ export class Inngest { mode: this.mode, }); + this.schemas = schemas; this.loadModeEnvVars(); this.logger = logger;