import { expectTypeOf, it } from "vitest"; import { events } from "./events.generated.js"; import { connections, workflow, type WorkflowConnectionDeclarations } from "./workflow.js"; it("infers only the declared provider clients", () => { workflow({ name: "Mail", description: "Read the configured mailbox", connections: { inbox: connections.mail() }, triggers: ({ events }) => [events.mailEmailReceived({ connectionKey: "inbox" })], handler(_event, context) { expectTypeOf().toEqualTypeOf<"inbox">(); expectTypeOf(context.connections.inbox.searchEmails).toBeFunction(); expectTypeOf(context.connections.inbox.listLabels).toBeFunction(); expectTypeOf(context.connections.inbox.sendNewEmail).toBeFunction(); expectTypeOf(context.connections.inbox.createMailBlock).toBeFunction(); }, }); workflow({ name: "Calendar", description: "Calendar only", triggers: [events.notionPageCreated()], connections: { work: connections.calendar({ targets: { calendar: { description: "Calendar", permissions: "read", multiple: true }, }, }), }, handler(_event, context) { expectTypeOf().toEqualTypeOf<"work">(); expectTypeOf(context.connections.work.listCalendars).toBeFunction(); expectTypeOf(context.connections.work.createEvents).toBeFunction(); expectTypeOf(context.connections.work.updateEvents).toBeFunction(); expectTypeOf(context.connections.work.cancelEvents).toBeFunction(); }, }); const requirements = { calendar: connections.calendar({ targets: { calendar: { description: "Calendar", permissions: "read", multiple: true } }, }), support: connections.slack(), team: connections.slack(), }; workflow({ name: "Multiple providers", description: "Preserves clients in a separately declared object", triggers: [events.notionPageCreated()], connections: requirements, handler(_event, context) { expectTypeOf().toEqualTypeOf< "calendar" | "support" | "team" >(); }, }); }); it("exposes no providers for omitted or empty connections", () => { workflow({ name: "No connections", description: "Omitted", triggers: [events.notionPageCreated()], handler(_event, context) { expectTypeOf().toEqualTypeOf(); }, }); workflow({ name: "No connections", description: "Empty", triggers: [events.notionPageCreated()], connections: {}, handler(_event, context) { expectTypeOf().toEqualTypeOf(); }, }); }); it("preserves literal declarations checked with satisfies", () => { const requirements = { support: connections.slack() } satisfies WorkflowConnectionDeclarations; workflow({ name: "Slack", description: "Slack only", triggers: [events.notionPageCreated()], connections: requirements, handler(_event, context) { expectTypeOf().toEqualTypeOf<"support">(); }, }); });