From b58a55a9c6cd3e807f33c4e85b2c0be821eb1742 Mon Sep 17 00:00:00 2001 From: Jack Williams <1736957+jpwilliams@users.noreply.github.com> Date: Thu, 19 Oct 2023 13:56:44 +0000 Subject: [PATCH 1/2] Excess properties are errors when creating a client with an obj literal --- .../inngest/src/components/Inngest.test.ts | 12 +++++++++++ packages/inngest/src/components/Inngest.ts | 21 +++++++++++-------- 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/packages/inngest/src/components/Inngest.test.ts b/packages/inngest/src/components/Inngest.test.ts index 856c73fa..7b1b3d28 100644 --- a/packages/inngest/src/components/Inngest.test.ts +++ b/packages/inngest/src/components/Inngest.test.ts @@ -443,6 +443,18 @@ describe("send", () => { }); describe("types", () => { + describe("instantiation", () => { + test("disallows setting unknown config property with object literal", () => { + // @ts-expect-error Unknown property + const _fn = () => new Inngest({ id: "test", baseURL: "bar" }); + }); + + test("allows setting unknown config property with variable", () => { + const options = { id: "test", baseURL: "bar" }; + const _fn = () => new Inngest(options); + }); + }); + describe("no custom types", () => { const inngest = createClient({ id: "test", eventKey: testEventKey }); diff --git a/packages/inngest/src/components/Inngest.ts b/packages/inngest/src/components/Inngest.ts index bdbf6e2a..3d12f98c 100644 --- a/packages/inngest/src/components/Inngest.ts +++ b/packages/inngest/src/components/Inngest.ts @@ -1,3 +1,4 @@ +import { type Exact } from "type-fest"; import { InngestApi } from "../api/api"; import { defaultDevServerHost, @@ -146,15 +147,17 @@ export class Inngest { * }); * ``` */ - constructor({ - id, - eventKey, - baseUrl, - fetch, - env, - logger = new DefaultLogger(), - middleware, - }: TOpts) { + constructor(options: Exact) { + const { + id, + eventKey, + baseUrl, + fetch, + env, + logger = new DefaultLogger(), + middleware, + } = options as ClientOptions; + if (!id) { // TODO PrettyError throw new Error("An `id` must be passed to create an Inngest instance."); From 6fbcb661468c8064cf120fd85bfca853fd9dae9a Mon Sep 17 00:00:00 2001 From: Jack Williams <1736957+jpwilliams@users.noreply.github.com> Date: Mon, 23 Oct 2023 11:37:26 +0000 Subject: [PATCH 2/2] Resolve testing issues using `new Inngest()` This is a known problem - see `createClient()` comment. --- packages/inngest/etc/inngest.api.md | 3 ++- .../inngest/src/components/EventSchemas.test.ts | 17 +++++++++-------- packages/inngest/src/components/Inngest.test.ts | 2 +- packages/inngest/src/test/helpers.ts | 4 ++-- 4 files changed, 14 insertions(+), 12 deletions(-) diff --git a/packages/inngest/etc/inngest.api.md b/packages/inngest/etc/inngest.api.md index d4794b3c..740b4584 100644 --- a/packages/inngest/etc/inngest.api.md +++ b/packages/inngest/etc/inngest.api.md @@ -4,6 +4,7 @@ ```ts +import { Exact } from 'type-fest'; import { IsEqual } from 'type-fest'; import { Jsonify } from 'type-fest'; import { Simplify } from 'type-fest'; @@ -162,7 +163,7 @@ export enum headerKeys { // @public export class Inngest { - constructor({ id, eventKey, baseUrl, fetch, env, logger, middleware, }: TOpts); + constructor(options: Exact); // Warning: (ae-forgotten-export) The symbol "ExclusiveKeys" needs to be exported by the entry point index.d.ts // Warning: (ae-forgotten-export) The symbol "InngestFunction" needs to be exported by the entry point index.d.ts // Warning: (ae-forgotten-export) The symbol "FunctionTrigger" needs to be exported by the entry point index.d.ts diff --git a/packages/inngest/src/components/EventSchemas.test.ts b/packages/inngest/src/components/EventSchemas.test.ts index b5b2616e..b208eda5 100644 --- a/packages/inngest/src/components/EventSchemas.test.ts +++ b/packages/inngest/src/components/EventSchemas.test.ts @@ -1,9 +1,10 @@ import { EventSchemas } from "@local/components/EventSchemas"; -import { Inngest, type GetEvents } from "@local/components/Inngest"; +import { type GetEvents, type Inngest } from "@local/components/Inngest"; import { type IsAny } from "@local/helpers/types"; import { type EventPayload } from "@local/types"; import { assertType, type IsEqual } from "type-plus"; import { z } from "zod"; +import { createClient } from "../test/helpers"; // eslint-disable-next-line @typescript-eslint/no-explicit-any type Schemas> = GetEvents< @@ -659,7 +660,7 @@ describe("EventSchemas", () => { "test.event": { data: { a: string } }; }>(); - const inngest = new Inngest({ + const inngest = createClient({ id: "test", schemas, eventKey: "test-key-123", @@ -682,7 +683,7 @@ describe("EventSchemas", () => { "test.event": { data: any }; }>(); - const inngest = new Inngest({ + const inngest = createClient({ id: "test", schemas, eventKey: "test-key-123", @@ -707,7 +708,7 @@ describe("EventSchemas", () => { "test.event2": { data: { foo: string } }; }>(); - const inngest = new Inngest({ + const inngest = createClient({ id: "test", schemas, eventKey: "test-key-123", @@ -735,7 +736,7 @@ describe("EventSchemas", () => { "test.event2": { data: { bar: boolean } }; }>(); - const inngest = new Inngest({ + const inngest = createClient({ id: "test", schemas, eventKey: "test-key-123", @@ -766,7 +767,7 @@ describe("EventSchemas", () => { "test.event2": { data: any }; }>(); - const inngest = new Inngest({ + const inngest = createClient({ id: "test", schemas, eventKey: "test-key-123", @@ -795,7 +796,7 @@ describe("EventSchemas", () => { "test.event2": { data: { foo: string } }; }>(); - const inngest = new Inngest({ + const inngest = createClient({ id: "test", schemas, eventKey: "test-key-123", @@ -840,7 +841,7 @@ describe("EventSchemas", () => { const schemas = new EventSchemas().fromUnion(); - const inngest = new Inngest({ + const inngest = createClient({ id: "test", schemas, eventKey: "test-key-123", diff --git a/packages/inngest/src/components/Inngest.test.ts b/packages/inngest/src/components/Inngest.test.ts index 7b1b3d28..f1a6f472 100644 --- a/packages/inngest/src/components/Inngest.test.ts +++ b/packages/inngest/src/components/Inngest.test.ts @@ -786,7 +786,7 @@ describe("createFunction", () => { }); describe("helper types", () => { - const inngest = new Inngest({ + const inngest = createClient({ id: "test", schemas: new EventSchemas().fromRecord<{ foo: { data: { foo: string } }; diff --git a/packages/inngest/src/test/helpers.ts b/packages/inngest/src/test/helpers.ts index 3c05d991..c4c24dc0 100644 --- a/packages/inngest/src/test/helpers.ts +++ b/packages/inngest/src/test/helpers.ts @@ -2,7 +2,7 @@ /* eslint-disable @typescript-eslint/no-unsafe-member-access */ /* eslint-disable @typescript-eslint/no-unsafe-assignment */ /* eslint-disable @typescript-eslint/no-unsafe-call */ -import { Inngest } from "@local"; +import { Inngest } from "@local/components/Inngest"; import { type ServeHandlerOptions } from "@local/components/InngestCommHandler"; import { envKeys, headerKeys, queryKeys } from "@local/helpers/consts"; import { type Env } from "@local/helpers/env"; @@ -461,7 +461,7 @@ export const testFramework = ( const ret = await run( [ { - client: new Inngest({ id: "Test", env: "FOO" }), + client: createClient({ id: "Test", env: "FOO" }), functions: [], }, ],