import { nextCursor, notionRequest } from './request.ts' import { boundedPageSize, inputRecord, optionalString, requiredString } from './validation.ts' type BlockChildrenResponse = { results?: unknown[] has_more?: boolean next_cursor?: string | null [key: string]: unknown } /** Read the child blocks of a Notion page or block (page content). */ export default async function getBlockChildren(params: Record) { const input = inputRecord(params) const blockId = requiredString(input, 'blockId') const result = await notionRequest( '/blocks/' + encodeURIComponent(blockId) + '/children', { query: { page_size: boundedPageSize(input.pageSize), start_cursor: optionalString(input, 'startCursor'), }, account: optionalString(input, 'account'), integration: optionalString(input, 'integration'), }, ) return { blocks: result.results ?? [], hasMore: result.has_more === true, nextCursor: nextCursor(result), } }