import type { Database } from "../database.js"; import type { CustomBlockHandle } from "../custom-block.js"; import { type DatabaseIntent, type DatabasePageLayout, type NotionAsCodeIcon, type NotionAsCodeSchema, type Parent, type ResourceId } from "./intents.js"; import { type ChildPageArgs, type PageHandle } from "./page.js"; import { type AppsSchemaForSchema } from "./schema.js"; import type { ViewSchema } from "./views.js"; /** Reuse serialized database intent metadata, excluding identity, parent, and sources. */ type DatabaseMetadata = Omit; type NonEmptyViewSchemas = readonly [ViewSchema, ...ViewSchema[]]; /** A keyed data-source declaration; the containing map key supplies the serialized source name. */ export type DataSourceArgs = { resourceId: ResourceId; name?: never; description?: string; schema: Schema; icon?: NotionAsCodeIcon; pageLayout?: DatabasePageLayout; }; /** Data sources keyed by the names used to access their handles. */ export type DataSourceMap = Record; /** * Single-source inputs require a name for both database and source. `datasources?: never` * keeps this form exclusive even when callers pass a predeclared object. */ type SingleSourceDatabaseOptions = Omit & { dataSourceResourceId: ResourceId; name: string; schema: Schema; pageLayout?: DatabasePageLayout; datasources?: never; }; /** Top-level single-source inputs may choose a parent; page.addDatabase/teamspace.addDatabase bind it instead. */ export type SingleSourceDatabaseArgs = SingleSourceDatabaseOptions & { parent?: Parent; }; /** * Multi-source inputs preserve source-map keys. The NoInfer guard makes the * emptiness check inspect the inferred map instead of widening it to the broad * DataSourceMap constraint. */ type MultiSourceDatabaseOptions = DatabaseMetadata & { datasources: DataSources; dataSourceResourceId?: never; schema?: never; pageLayout?: never; } & (keyof NoInfer extends never ? { views: NonEmptyViewSchemas; } : { views?: readonly ViewSchema[]; }); /** Top-level multi-source inputs may choose a parent; page.addDatabase/teamspace.addDatabase bind it instead. */ export type MultiSourceDatabaseArgs = MultiSourceDatabaseOptions & { parent?: Parent; }; /** Linked-only databases use a nonempty typed view tuple and no authored source map. */ type ViewOnlyDatabaseOptions = DatabaseMetadata & { datasources?: never; dataSourceResourceId?: never; schema?: never; pageLayout?: never; views: NonEmptyViewSchemas; }; type ViewOnlyDatabaseArgs = ViewOnlyDatabaseOptions & { parent?: Parent; }; /** Remove parent because page.addDatabase/teamspace.addDatabase supplies it. */ export type ChildSingleSourceDatabaseArgs = Omit, "parent">; /** Remove parent because page.addDatabase/teamspace.addDatabase supplies it. */ export type ChildMultiSourceDatabaseArgs = Omit, "parent">; /** Input for declaring a database and its data sources. */ export type DatabaseArgs = SingleSourceDatabaseArgs | MultiSourceDatabaseArgs | ViewOnlyDatabaseArgs; /** * Child inputs omit parent from each union member separately. `page.addDatabase` * and `teamspace.addDatabase` use this shape for their shared child factory. */ export type ChildDatabaseArgs = ChildSingleSourceDatabaseArgs | ChildMultiSourceDatabaseArgs | Omit; export type PropertyHandle = { readonly resourceType: "property"; readonly resourceId: Property["resourceId"]; readonly dataSourceResourceId: string; readonly name: string; readonly propertyType: Property["type"]; }; export type DataSourceProperties = { readonly [Name in keyof Schema]: PropertyHandle; }; /** A source handle retains its keyed authoring schema for sync inference. */ export type DataSourceHandle = { readonly resourceType: "dataSource"; readonly resourceId: string; readonly name: string; readonly description?: string; readonly schema: Schema; readonly properties: DataSourceProperties; readonly database: Database>; addPage: (args: ChildPageArgs) => PageHandle; }; type DatabaseHandleBase = { readonly resourceType: "database"; readonly resourceId: string; addView: (view: ViewSchema) => void; addCustomView: (view: AddCustomViewArgs) => void; }; export type AddCustomViewArgs = { resourceId: ResourceId; name?: string; icon?: Extract; customBlock: CustomBlockHandle; dataSource?: DataSourceHandle; }; /** Map each authoring source key to a handle backed by that source's own schema. */ export type DatabaseHandle = DatabaseHandleBase & { readonly datasources: { readonly [DataSourceName in keyof DataSources]: DataSourceHandle; }; }; /** A database whose sole data source is available without a key lookup. */ export type SingleSourceDatabaseHandle = DatabaseHandleBase & { readonly dataSource: DataSourceHandle; }; /** * Overloaded callable used by page.addDatabase/teamspace.addDatabase. Each form * returns its matching handle while preserving literal source and schema inference. */ export type ChildDatabaseFactory = { (databaseResourceId: ResourceId, args: ChildSingleSourceDatabaseArgs): SingleSourceDatabaseHandle; (databaseResourceId: ResourceId, args: ChildMultiSourceDatabaseArgs): DatabaseHandle; (databaseResourceId: ResourceId, args: Omit): DatabaseHandle<{}>; }; /** Declare a database, defaulting to the Apps workspace. */ export declare function database(databaseResourceId: ResourceId, args: SingleSourceDatabaseArgs): SingleSourceDatabaseHandle; export declare function database(databaseResourceId: ResourceId, args: MultiSourceDatabaseArgs): DatabaseHandle; export declare function database(databaseResourceId: ResourceId, args: ViewOnlyDatabaseArgs): DatabaseHandle<{}>; /** Bind a parent for page.addDatabase/teamspace.addDatabase. */ export declare function createChildDatabase(parent: Parent): ChildDatabaseFactory; export {}; //# sourceMappingURL=database.d.ts.map