import { APPS_WORKSPACE_RESOURCE_ID, type NotionAsCodeIcon, type ResourceId, type TeamspaceIntent, } from "./intents.js"; import { createChildDatabase, type ChildDatabaseFactory } from "./database.js"; import { createPage, type ChildPageArgs, type PageHandle } from "./page.js"; import { recordIntent } from "./recorder.js"; import { assertUserResourceId } from "./resource.js"; export type TeamspaceArgs = { resourceId: ResourceId; name: string; accessLevel: "default" | "open" | "closed" | "private"; icon?: NotionAsCodeIcon; description?: string; }; export type TeamspaceHandle = { readonly resourceId: string; addDatabase: ChildDatabaseFactory; addPage: (args: ChildPageArgs) => PageHandle; }; /** Declare a teamspace that Apps automatically creates in its workspace. */ export function teamspace(args: TeamspaceArgs): TeamspaceHandle { assertUserResourceId(args.resourceId); recordIntent({ type: "teamspace", ...args, parent: { type: "resourceId", resourceId: APPS_WORKSPACE_RESOURCE_ID }, } satisfies { type: "teamspace" } & TeamspaceIntent); return { resourceId: args.resourceId, addDatabase: createChildDatabase({ type: "resourceId", resourceId: args.resourceId }), addPage(pageArgs) { return createPage(pageArgs, { type: "resourceId", resourceId: args.resourceId }); }, }; }