UNPKG

@pagenote/notion-database

Version:

make notion as a real-database for server

34 lines (33 loc) 1.6 kB
import { Client } from '@notionhq/client'; import Table from './Table'; import { NotionObjectSchema, NotionDatabaseCreateSchema } from './types/base'; import { PageObjectResponse } from '@notionhq/client/build/src/api-endpoints'; import { DatabaseProps, IonError } from './types/props'; export default class Database { props: DatabaseProps; notion: Client; readonly tables: Map<string, Table<any>>; basePage: PageObjectResponse | null; onError: IonError; private lastSyncAt; constructor(props: DatabaseProps); refreshOption(props: Partial<DatabaseProps>): Promise<Database>; ready(): Promise<Database>; /** * 初始化基础页面(根页面),没有的情况下,影响新建表,不影响存量表使用 */ _initBasePage(): Promise<string>; /** * 初始化授权页面下的所有表 */ _fetchTables(): Promise<Map<string, Table<any>>>; _setTable(tableName: string, table: Table<any>): void; _getTable(tableNameOrId: string): Table<any> | undefined; getTableAsync<TableSchema extends NotionObjectSchema>(tableName: string, createOnNoTableByInitData?: NotionObjectSchema): Promise<Table<TableSchema> | undefined>; getTableSync<TableSchema extends NotionObjectSchema>(tableName: string, databaseId: string, demoData: NotionObjectSchema): Table<TableSchema>; createTable<TableSchema extends NotionObjectSchema>(tableName: string, option: { properties?: NotionDatabaseCreateSchema; demoData: NotionObjectSchema; titleKey?: string; }): Promise<Table<TableSchema> | undefined>; }