import * as v from "valibot" import { notionPageIdSchema } from "../ids.js" import type { CustomBlockUpdatePageErrorInfo } from "../messages/updatePageResult.js" import type { NotionPage, NotionPageCover, NotionPageIcon, NotionPageId, NotionPagePropertyInputMap, } from "../pages/page.js" import { type NotionDataSourceValue, notionDataSourceValueSchema, } from "./dataSourceValue.js" /** * Bridge shape for a data source page, as parsed from inbound host messages. The host keys * properties by raw property ID. The four built-ins (`created_time`, `last_edited_time`, * `created_by`, `last_edited_by`) are normally present, possibly with `undefined` values. * * Internal to the SDK. The consumer-facing shape is {@link NotionDataSourcePage}. */ export const notionDataSourcePageBridgeSchema = v.object({ id: notionPageIdSchema, propertiesById: v.record(v.string(), v.optional(notionDataSourceValueSchema)), }) /** Internal SDK type for a parsed bridge page. */ export type NotionDataSourcePageBridge = v.InferOutput< typeof notionDataSourcePageBridgeSchema > export type NotionDataSourcePageUpdateInput = { properties?: NotionPagePropertyInputMap icon?: NotionPageIcon cover?: NotionPageCover archived?: boolean } export type NotionDataSourcePageUpdateResult = | { status: "success" page: NotionPage } | { status: "error"; error: CustomBlockUpdatePageErrorInfo } /** * Consumer-facing page shape returned from {@link useDataSource}. Derived from the bridge payload * plus the data source's `propertyIdsByKey`. */ export type NotionDataSourcePage = { id: NotionPageId /** * Keyed mapping of raw property IDs to their value. Includes all properties on the data source, * including the four built-ins (`created_time`, `last_edited_time`, `created_by`, * `last_edited_by`). */ propertiesById: { [propertyId: string]: NotionDataSourceValue | undefined } /** * Keyed mapping of user-defined keys to their value. Only includes properties that are mapped * to a raw property ID in the data source's `propertyIdsByKey`. */ propertiesByKey: { [key: string]: NotionDataSourceValue | undefined } /** * Updates this page using the data source's property-key bindings. The SDK resolves property * keys to raw property IDs before sending the bridge message to the host. */ update: ( input: NotionDataSourcePageUpdateInput, ) => Promise }