UNPKG

notion-page-tree

Version:

Recursively fetch nested Notion pages from the root page/database/block node.

65 lines (64 loc) 1.98 kB
import { Client } from '@notionhq/client'; import { GetPageResponse, GetDatabaseResponse, GetBlockResponse, QueryDatabaseResponse } from '@notionhq/client/build/src/api-endpoints'; import { normalizeBlockType } from './fetcher/utils'; export interface RequestParameters { client: Client; entry_id?: string; entry_key?: string; entry_type?: string; } export declare type NormalizedEntryType = ReturnType<typeof normalizeBlockType>; export declare type SubTreeEntity = SubTreeCommons & (Page | Database | Block); export interface SubTreeCommons { id: string; depth: number; blockContentPlainText: string; parent?: string; children: (string | SubTreeEntity)[]; } export declare type FlatEntity = FlatCommons & (Page | Database | Block); export interface FlatCommons { id: string; depth: number; blockContentPlainText: string; parent?: string; children: string[]; } export declare type Entity = Commons & (Page | Database | Block); export interface Commons { id: string; depth: number; blockContentPlainText: string; parent?: Entity; children: Entity[]; } export declare type GetPageResponseWithMetadata = Extract<GetPageResponse, { last_edited_time: string; }>; export interface Page { type: 'page'; metadata: Extract<GetPageResponse, { last_edited_time: string; }>; } export declare type QueryDatabaseResponseWithProperties = Extract<QueryDatabaseResponse['results'][0], { properties: unknown; }>; export declare type GetDatabaseResponseWithMetadata = Extract<GetDatabaseResponse, { last_edited_time: string; }>; export interface Database { type: 'database'; metadata: Extract<GetDatabaseResponse, { last_edited_time: string; }>; } export declare type GetBlockResponseWithMetadata = Extract<GetBlockResponse, { type: string; }>; export interface Block { type: 'block'; metadata: Extract<GetBlockResponse, { type: string; }>; }