| 66 | } |
| 67 | |
| 68 | async function createDatabase(notion: Client, parent: any): Promise<DatabaseHandles> { |
| 69 | const db = await notion.request<any>({ |
| 70 | path: "databases", method: "post", |
| 71 | body: { |
| 72 | parent, |
| 73 | title: [{ type: "text", text: { content: DB_TITLE } }], |
| 74 | icon: DB_ICON, |
| 75 | initial_data_source: { properties: SCHEMA }, |
| 76 | }, |
| 77 | }); |
| 78 | const dataSourceId = db.data_sources?.[0]?.id; |
| 79 | if (!dataSourceId) bail(`Notion created the database but didn't return a data source ID.`); |
| 80 | return { |
| 81 | databaseId: db.id, |
| 82 | dataSourceId, |
| 83 | databaseUrl: db.url ?? `https://www.notion.so/${db.id.replace(/-/g, "")}`, |
| 84 | }; |
| 85 | } |
| 86 | |
| 87 | async function createViews(notion: Client, databaseId: string, dataSourceId: string): Promise<void> { |
| 88 | const ds = await notion.request<any>({ path: `data_sources/${dataSourceId}`, method: "get" }); |