@pagenote/notion-database
Version:
make notion as a real-database for server
64 lines (63 loc) • 2.84 kB
TypeScript
import { Client } from '@notionhq/client';
import { CreateDatabaseItemProperties, NotionDatabaseProperties, ObjectType } from './types/notionType';
import { AllowFilter, AppendNotionPropertiesDocumentFields, NotionDatabaseCreateSchema, NotionObjectSchema, ResponseNotionPropertiesDocument } from './types/base';
import { QueryDatabaseResponse } from '@notionhq/client/build/src/api-endpoints';
interface TableProps {
database_id: string;
parentPageId?: string;
token: string;
cloudDescribe: NotionDatabaseCreateSchema | null;
demoData: NotionObjectSchema | null;
notion?: Client;
onError: (databaseId: string, reason: any) => void;
}
type QueryResponse<T extends Record<string, ObjectType>> = QueryDatabaseResponse & {
_list?: (T & AppendNotionPropertiesDocumentFields)[];
};
export default class Table<T extends NotionObjectSchema> {
shortDatabaseId: string;
protected parentPageId: string;
notion: Client;
option: TableProps;
connected: boolean;
cloudPropertiesSchema: NotionDatabaseCreateSchema | null;
demoPropertiesSchema: NotionDatabaseCreateSchema;
private demoData;
private readonly onError;
constructor(option: TableProps);
_reformatCloudPropertiesByDemoData(data: NotionObjectSchema): Promise<void>;
_formatCloudProperties(tablePropertiesDesc: {
[x: string]: NotionDatabaseProperties;
}): Promise<void>;
_syncProperties(): Promise<void>;
_setDemoData(data: NotionObjectSchema | null): void;
_getValidDataBySchema<T extends NotionObjectSchema>(data: T, forceAddByModifyTable: boolean): Promise<CreateDatabaseItemProperties>;
_commentError(error: any, pageId?: string): void;
ready(): Promise<Table<T>>;
add(data: Partial<T>, forceAddByModifyTable?: boolean): Promise<ResponseNotionPropertiesDocument<T> | null>;
query(data: AllowFilter<T>, sorts?: {
property: string;
direction: 'ascending' | 'descending';
}[], pagination?: {
page_size: number;
start_cursor?: string;
}, filterProperty?: string[]): Promise<QueryResponse<ResponseNotionPropertiesDocument<T>>>;
queryAll(finder: {
filter: AllowFilter<T>;
sorts?: {
property: string;
direction: 'ascending' | 'descending';
}[];
pagination?: {
page_size: number;
start_cursor?: string;
};
}): Promise<QueryResponse<ResponseNotionPropertiesDocument<T>>>;
delete(query: Partial<T> | string[]): Promise<number>;
deleteOne(pageId: string): Promise<boolean>;
batchUpdate(query: Partial<T>, data: Partial<T>, option?: {
upsert: boolean;
}): Promise<(ResponseNotionPropertiesDocument<T> | null)[]>;
updateOne(pageId: string, data: Partial<T>): Promise<ResponseNotionPropertiesDocument<T>>;
}
export {};