import { expectTypeOf, it } from "vitest"; import { access } from "../workflow-access.js"; import { page, database, customAgent } from "../index.js"; import type { CustomAgentAccess, CustomAgentArgs, CustomAgentPropertyUpdatedTrigger, CustomAgentTrustedUrls, CustomAgentTrigger, DatabasePageLayout, NotionAsCodePropertyConfig, PageArgs, PageCoverReference, PageLayoutPropertyModule, SingleSourceDatabaseArgs, } from "./index.js"; it("types custom agent resource access and URL trust", () => { const home = page({ resourceId: "home" }); const tasks = database("tasks", { dataSourceResourceId: "source", name: "Tasks", schema: { Title: { resourceId: "title", type: "title" } }, }); expectTypeOf(access.view(home)).toExtend(); expectTypeOf(access.edit(tasks)).toExtend(); expectTypeOf(access.view(tasks.dataSource)).not.toExtend(); expectTypeOf(access.comment(tasks.dataSource)).not.toExtend(); expectTypeOf(access.edit(tasks.dataSource)).not.toExtend(); expectTypeOf(access.fullAccess(tasks.dataSource)).not.toExtend(); expectTypeOf<{ resource: typeof tasks.dataSource; level: "view"; }>().not.toExtend(); expectTypeOf<{ resourceId: "tasks"; role: "can_view" }>().not.toExtend(); expectTypeOf( access.call(customAgent({ resourceId: "agent", name: "Agent" })), ).not.toExtend(); expectTypeOf().toEqualTypeOf<"all" | "none" | [string, ...string[]]>(); expectTypeOf<[]>().not.toExtend(); expectTypeOf<{ type: "all" }>().not.toExtend(); expectTypeOf().toEqualTypeOf(); expectTypeOf().toEqualTypeOf(); expectTypeOf().toEqualTypeOf< CustomAgentTrustedUrls | undefined >(); expectTypeOf().toEqualTypeOf< readonly CustomAgentAccess[] | undefined >(); }); it("types page and database covers as URL references", () => { expectTypeOf<{ type: "url"; url: "https://example.com/cover.png"; position: 0.25; }>().toExtend(); expectTypeOf<{ type: "external"; url: "https://example.com/cover.png"; }>().not.toExtend(); expectTypeOf().toEqualTypeOf(); }); it("requires configuration for each advanced property kind", () => { expectTypeOf<{ type: "relation"; resourceId: "project"; targetDataSourceResourceId: "projects"; limit: 1; }>().toExtend(); expectTypeOf<{ type: "relation"; resourceId: "project"; }>().not.toExtend(); expectTypeOf<{ type: "rollup"; resourceId: "total"; relationPropertyResourceId: "project"; targetPropertyResourceId: "estimate"; targetPropertyType: "number"; aggregation: "sum"; }>().toExtend(); expectTypeOf<{ type: "rollup"; resourceId: "invalid-total"; relationPropertyResourceId: "project"; targetPropertyResourceId: "name"; targetPropertyType: "title"; aggregation: "sum"; }>().not.toExtend(); expectTypeOf<{ type: "verification"; resourceId: "verification"; verifierPropertyResourceId: "owner"; }>().toExtend(); expectTypeOf<{ type: "verification"; resourceId: "verification"; }>().not.toExtend(); }); it("links page-layout property styles and relation groups to the data source schema", () => { type Schema = { Name: { type: "title"; resourceId: "name" }; Estimate: { type: "number"; resourceId: "estimate" }; Owner: { type: "person"; resourceId: "owner" }; Project: { type: "relation"; resourceId: "project"; targetDataSourceResourceId: "projects"; }; }; expectTypeOf<{ type: "property"; property: "estimate"; style: "large"; }>().toExtend>(); expectTypeOf<{ type: "property"; property: "estimate"; style: "landscape"; }>().not.toExtend>(); expectTypeOf<{ type: "property"; property: "name"; style: "large"; }>().not.toExtend>(); type ValidLayout = { main: [ { type: "properties"; properties: [{ property: "name" }] }, { type: "relations"; relations: [{ property: "project"; display: "pageSection" }]; }, ]; pinnedProperties: ["owner"]; }; type InvalidRelationLayout = { main: [ { type: "properties"; properties: [{ property: "name" }] }, { type: "relations"; relations: [{ property: "estimate"; display: "pageSection" }]; }, ]; }; expectTypeOf().toExtend>(); expectTypeOf().not.toExtend>(); expectTypeOf<{ dataSourceResourceId: "tasks"; name: "Tasks"; schema: Schema; pageLayout: ValidLayout; }>().toExtend>(); expectTypeOf<{ dataSourceResourceId: "tasks"; name: "Tasks"; schema: Schema; pageLayout: InvalidRelationLayout; }>().not.toExtend>(); }); it("requires a meaningful custom agent trigger configuration", () => { expectTypeOf<{ type: "recurrence"; resourceId: "weekday-trigger"; frequency: "week"; interval: 1; start: "2026-09-21T09:00:00"; timeZone: "America/Los_Angeles"; weekdays: { MO: true; FR: true }; }>().toExtend(); expectTypeOf<{ type: "recurrence"; resourceId: "empty-weekdays"; frequency: "week"; interval: 1; start: "2026-09-21T09:00:00"; timeZone: "America/Los_Angeles"; weekdays: {}; }>().not.toExtend(); expectTypeOf<{ type: "property_updated"; resourceId: "content-trigger"; dataSourceResourceId: "tasks"; triggerWhenPageContentEdited: true; }>().toExtend(); expectTypeOf<{ type: "property_updated"; resourceId: "empty-trigger"; dataSourceResourceId: "tasks"; }>().not.toExtend(); expectTypeOf().toEqualTypeOf< readonly CustomAgentTrigger[] | undefined >(); });