UNPKG

@jitl/notion-api

Version:

The missing companion library for the official Notion public API.

32 lines 1.25 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const __1 = require(".."); async function iterateDB() { for await (const page of (0, __1.iteratePaginatedAPI)(notion.databases.query, { database_id: databaseId, })) { if ((0, __1.isFullPage)(page)) { // TODO } } } /** * Query all pages and return all records from a Notion database object * Will log a warning if database has no records * @param parameters To specify database id, control sorting, filtering and * pagination, directly using Notion's sdk types * @returns A list of all the results from the database or an empty array */ const queryAll = async (parameters) => { const params = { ...parameters }; const resultsWithPartialPages = await (0, __1.asyncIterableToArray)( // getNotionClient() returns an authenticated instance of the notion SDK (0, __1.iteratePaginatedAPI)(getNotionClient().databases.query, parameters)); // Filter out partial pages const fullPages = resultsWithPartialPages.filter(__1.isFullPage); if (!fullPages.length) { logger.warn(`No results found in database ${params.database_id}`); } return fullPages; }; //# sourceMappingURL=iteration.js.map