Spaces:
Build error
Build error
import { BlockObjectResponse, CommentObjectResponse, DatabaseObjectResponse, PageObjectResponse, PartialBlockObjectResponse, PartialCommentObjectResponse, PartialDatabaseObjectResponse, PartialPageObjectResponse, PartialUserObjectResponse, UserObjectResponse } from "./api-endpoints"; | |
interface PaginatedArgs { | |
start_cursor?: string; | |
} | |
interface PaginatedList<T> { | |
object: "list"; | |
results: T[]; | |
next_cursor: string | null; | |
has_more: boolean; | |
} | |
/** | |
* Returns an async iterator over the results of any paginated Notion API. | |
* | |
* Example (given a notion Client called `notion`): | |
* | |
* ``` | |
* for await (const block of iteratePaginatedAPI(notion.blocks.children.list, { | |
* block_id: parentBlockId, | |
* })) { | |
* // Do something with block. | |
* } | |
* ``` | |
* | |
* @param listFn A bound function on the Notion client that represents a conforming paginated | |
* API. Example: `notion.blocks.children.list`. | |
* @param firstPageArgs Arguments that should be passed to the API on the first and subsequent | |
* calls to the API. Any necessary `next_cursor` will be automatically populated by | |
* this function. Example: `{ block_id: "<my block id>" }` | |
*/ | |
export declare function iteratePaginatedAPI<Args extends PaginatedArgs, Item>(listFn: (args: Args) => Promise<PaginatedList<Item>>, firstPageArgs: Args): AsyncIterableIterator<Item>; | |
/** | |
* Collect all of the results of paginating an API into an in-memory array. | |
* | |
* Example (given a notion Client called `notion`): | |
* | |
* ``` | |
* const blocks = collectPaginatedAPI(notion.blocks.children.list, { | |
* block_id: parentBlockId, | |
* }) | |
* // Do something with blocks. | |
* ``` | |
* | |
* @param listFn A bound function on the Notion client that represents a conforming paginated | |
* API. Example: `notion.blocks.children.list`. | |
* @param firstPageArgs Arguments that should be passed to the API on the first and subsequent | |
* calls to the API. Any necessary `next_cursor` will be automatically populated by | |
* this function. Example: `{ block_id: "<my block id>" }` | |
*/ | |
export declare function collectPaginatedAPI<Args extends PaginatedArgs, Item>(listFn: (args: Args) => Promise<PaginatedList<Item>>, firstPageArgs: Args): Promise<Item[]>; | |
/** | |
* @returns `true` if `response` is a full `BlockObjectResponse`. | |
*/ | |
export declare function isFullBlock(response: BlockObjectResponse | PartialBlockObjectResponse): response is BlockObjectResponse; | |
/** | |
* @returns `true` if `response` is a full `PageObjectResponse`. | |
*/ | |
export declare function isFullPage(response: PageObjectResponse | PartialPageObjectResponse): response is PageObjectResponse; | |
/** | |
* @returns `true` if `response` is a full `DatabaseObjectResponse`. | |
*/ | |
export declare function isFullDatabase(response: DatabaseObjectResponse | PartialDatabaseObjectResponse): response is DatabaseObjectResponse; | |
/** | |
* @returns `true` if `response` is a full `UserObjectResponse`. | |
*/ | |
export declare function isFullUser(response: UserObjectResponse | PartialUserObjectResponse): response is UserObjectResponse; | |
/** | |
* @returns `true` if `response` is a full `CommentObjectResponse`. | |
*/ | |
export declare function isFullComment(response: CommentObjectResponse | PartialCommentObjectResponse): response is CommentObjectResponse; | |
export {}; | |
//# sourceMappingURL=helpers.d.ts.map |