import * as v from "valibot" import { notionDataSourceIdSchema, notionSpaceIdSchema } from "../ids.js" import { notionPropertySchemaSchema } from "./propertySchema.js" const collectionPointerValidator = v.object({ id: notionDataSourceIdSchema, table: v.string(), spaceId: v.optional(notionSpaceIdSchema), }) export type NotionCollectionPointer = v.InferOutput< typeof collectionPointerValidator > export const notionCollectionSchemaValidator = v.object({ id: v.optional(notionDataSourceIdSchema), propertiesById: v.record(v.string(), notionPropertySchemaSchema), }) export type NotionCollectionSchema = v.InferOutput< typeof notionCollectionSchemaValidator > /** * Bridge shape for a single data source: a semantic key bound (optionally) to a collection, * its property name → ID mapping, and its column schemas. */ export const notionDataSourceSchema = v.object({ key: v.string(), collectionPointer: v.optional(collectionPointerValidator), collectionSchema: v.optional(notionCollectionSchemaValidator), /** * Keyed mapping of user-defined keys to a raw property ID. A key mapped to `undefined` * is a declared-but-unbound slot. */ propertyIdsByKey: v.record(v.string(), v.optional(v.string())), /** * Keyed mapping of raw property IDs to their schema. Always includes the four built-ins * (`created_time`, `last_edited_time`, `created_by`, `last_edited_by`). */ propertySchemasById: v.record(v.string(), notionPropertySchemaSchema), }) export type NotionDataSource = v.InferOutput export const notionDataSourceBindingSchema = v.object({ collectionPointer: v.optional(collectionPointerValidator), collectionSchema: v.optional(notionCollectionSchemaValidator), propertyIdsByKey: v.optional(v.record(v.string(), v.optional(v.string()))), }) export type NotionDataSourceBinding = v.InferOutput< typeof notionDataSourceBindingSchema > export const notionDataSourceBindingsSchema = v.record( v.string(), notionDataSourceBindingSchema, ) export type NotionDataSourceBindings = v.InferOutput< typeof notionDataSourceBindingsSchema >