import { describe, expectTypeOf, it } from "vitest"; import { mysql, openai, postgres, slack, type MySQLRef, type OpenAIRef, type PostgresRef, type SlackRef, } from "./declarations.js"; type LiteralString = string extends T ? never : T; type LiteralOnlyFactory = ( id: LiteralString, ) => TRef; describe("LiteralString", () => { it("preserves string literals", () => { expectTypeOf>().toEqualTypeOf<"abc-123">(); }); it("rejects broad string", () => { expectTypeOf>().toBeNever(); }); }); describe("integration declaration signatures", () => { it("enforces literal-only postgres declarations", () => { expectTypeOf(postgres).toEqualTypeOf>(); }); it("enforces literal-only slack declarations", () => { expectTypeOf(slack).toEqualTypeOf>(); }); it("enforces literal-only mysql declarations", () => { expectTypeOf(mysql).toEqualTypeOf>(); }); it("enforces literal-only openai declarations", () => { expectTypeOf(openai).toEqualTypeOf>(); }); }); describe("integration declaration calls", () => { it("accepts inline literals", () => { const ref = postgres("a1b2c3d4-e5f6-7890-abcd-ef1234567890"); expectTypeOf(ref.pluginId).toEqualTypeOf<"postgres">(); expectTypeOf(ref.id).toBeString(); }); it("accepts const variables with preserved literal types", () => { const PROD_DB = "a1b2c3d4-e5f6-7890-abcd-ef1234567890"; const OPS_SLACK = "b2c3d4e5-f678-9012-abcd-ef1234567890"; const dbRef = postgres(PROD_DB); const slackRef = slack(OPS_SLACK); expectTypeOf(dbRef.pluginId).toEqualTypeOf<"postgres">(); expectTypeOf(slackRef.pluginId).toEqualTypeOf<"slack">(); }); });