refactor: use typescript

Signed-off-by: Vojtěch Mareš <vojtech@mares.cz>
This commit is contained in:
Vojtěch Mareš 2025-05-07 17:30:19 +02:00
parent 0a9d12b777
commit 333969a4fa
Signed by: vojtech.mares
GPG key ID: C6827B976F17240D
4 changed files with 338 additions and 7 deletions

View file

@ -1,4 +0,0 @@
import { Client } from "@notionhq/client";
import dotenv from "dotenv";
dotenv.config();

41
src/main.mts Normal file
View file

@ -0,0 +1,41 @@
import { Client } from "@notionhq/client";
import dotenv from "dotenv";
dotenv.config();
await main();
async function main() {
const notion = new Client({
auth: process.env.NOTION_KEY as string,
});
const databaseID = process.env.DATABASE_ID as string;
const pages = await queryDatabase(notion, databaseID);
console.log(pages);
}
async function queryDatabase(notion: Client, databaseID: string) {
const pages: any[] = [];
let cursor: string | undefined = undefined;
const shouldContinue = true;
while (shouldContinue) {
const { results, next_cursor } = await notion.databases.query({
database_id: databaseID,
start_cursor: cursor,
});
pages.push(...results as never[]);
if (!next_cursor) {
break;
}
cursor = next_cursor;
}
return pages;
}