Skip to content

Commit 0ee4738

Browse files
authored
feat: update @notionhq/client to 2.2.15 and migrate code (#68)
1 parent dfae74c commit 0ee4738

File tree

5 files changed

+26
-20
lines changed

5 files changed

+26
-20
lines changed

package-lock.json

Lines changed: 8 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
"author": "Richard Robinson",
2929
"license": "ISC",
3030
"dependencies": {
31-
"@notionhq/client": "^1.0.4",
31+
"@notionhq/client": "^2.2.15",
3232
"remark-gfm": "^1.0.0",
3333
"remark-math": "^4.0.0",
3434
"remark-parse": "^9.0.0",

src/notion/blocks.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {richText, supportedCodeLang} from './common';
1+
import {richText, supportedCodeLang, TableRowBlock} from './common';
22
import {AppendBlockChildrenParameters} from '@notionhq/client/build/src/api-endpoints';
33

44
export type Block = AppendBlockChildrenParameters['children'][number];
@@ -155,10 +155,7 @@ export function toDo(
155155
};
156156
}
157157

158-
export function table(
159-
children: BlockWithoutChildren[],
160-
tableWidth: number
161-
): Block {
158+
export function table(children: TableRowBlock[], tableWidth: number): Block {
162159
return {
163160
object: 'block',
164161
type: 'table',
@@ -170,7 +167,7 @@ export function table(
170167
};
171168
}
172169

173-
export function tableRow(cells: RichText[][] = []): BlockWithoutChildren {
170+
export function tableRow(cells: RichText[][] = []): TableRowBlock {
174171
return {
175172
object: 'block',
176173
type: 'table_row',

src/notion/common.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,3 +154,11 @@ export type supportedCodeLang = typeof SUPPORTED_CODE_BLOCK_LANGUAGES[number];
154154
export function isSupportedCodeLang(lang: string): lang is supportedCodeLang {
155155
return (SUPPORTED_CODE_BLOCK_LANGUAGES as readonly string[]).includes(lang);
156156
}
157+
158+
export interface TableRowBlock {
159+
type: 'table_row';
160+
table_row: {
161+
cells: Array<Array<RichText>>;
162+
};
163+
object?: 'block';
164+
}

src/parser/internal.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -191,13 +191,13 @@ function parseList(element: md.List, options: BlocksOptions): notion.Block[] {
191191
});
192192
}
193193

194-
function parseTableCell(node: md.TableCell): notion.RichText[][] {
195-
return [node.children.flatMap(child => parseInline(child))];
194+
function parseTableCell(node: md.TableCell): notion.RichText[] {
195+
return node.children.flatMap(child => parseInline(child));
196196
}
197197

198-
function parseTableRow(node: md.TableRow): notion.BlockWithoutChildren[] {
199-
const tableCells = node.children.flatMap(child => parseTableCell(child));
200-
return [notion.tableRow(tableCells)];
198+
function parseTableRow(node: md.TableRow): notion.TableRowBlock {
199+
const cells = node.children.map(child => parseTableCell(child));
200+
return notion.tableRow(cells);
201201
}
202202

203203
function parseTable(node: md.Table): notion.Block[] {
@@ -206,7 +206,7 @@ function parseTable(node: md.Table): notion.Block[] {
206206
? node.children[0].children.length
207207
: 0;
208208

209-
const tableRows = node.children.flatMap(child => parseTableRow(child));
209+
const tableRows = node.children.map(child => parseTableRow(child));
210210
return [notion.table(tableRows, tableWidth)];
211211
}
212212

0 commit comments

Comments
 (0)