Skip to content

Commit

Permalink
feat(v4-types): update 0.4.11
Browse files Browse the repository at this point in the history
0.4.11 adds additional aliases to some of the results type. This leads to breaking current typings

BREAKING CHANGE:
- 0.4.11 adds aliases that do not conform with other existing aliases in QueryResult type leading to
breaking changes
  • Loading branch information
nartc committed Dec 25, 2021
1 parent 5fb7ced commit caf4b59
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 8 deletions.
4 changes: 2 additions & 2 deletions libs/blocks-html-parser/src/lib/blocks-html-parser.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { NotionBlocksMarkdownParser } from '@notion-stuff/blocks-markdown-parser';
import type { Block } from '@notion-stuff/v4-types';
import type { Blocks } from '@notion-stuff/v4-types';
import type { marked as Marked } from 'marked';
import type { NotionBlocksHtmlParserOptions } from './interfaces';

Expand Down Expand Up @@ -53,7 +53,7 @@ export class NotionBlocksHtmlParser {
return this.markdownParser;
}

parse(blocks: Block[]) {
parse(blocks: Blocks) {
const markdown = NotionBlocksHtmlParser.markdownParser.parse(blocks);
const { mdToHtmlOptions } = this.parserOptions;

Expand Down
4 changes: 2 additions & 2 deletions libs/blocks-markdown-parser/src/lib/blocks-markdown-parser.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type {
Annotations,
AudioBlock,
Block,
Blocks,
BulletedListItemBlock,
CalloutBlock,
CalloutIconEmoji,
Expand Down Expand Up @@ -55,7 +55,7 @@ export class NotionBlocksMarkdownParser {
return this.instance;
}

parse(blocks: Block[], depth = 0): string {
parse(blocks: Blocks, depth = 0): string {
return blocks
.reduce((markdown, childBlock) => {
let childBlockString = '';
Expand Down
5 changes: 3 additions & 2 deletions libs/scully-plugin-notion/src/lib/plugin.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { NotionBlocksHtmlParser } from '@notion-stuff/blocks-html-parser';
import { Blocks, PostResult } from '@notion-stuff/v4-types';
import { Client } from '@notionhq/client/build/src';
import type { HandledRoute, RouteConfig } from '@scullyio/scully';
import {
Expand Down Expand Up @@ -80,7 +81,7 @@ async function notionDomRouterPlugin(
setupParserAndPluginOptions();

return Promise.resolve(
posts.results.map((postResult) => {
posts.results.map((postResult: PostResult) => {
const frontmatter = processPageProperties(postResult, mergedConfig);

let cover = '';
Expand Down Expand Up @@ -163,7 +164,7 @@ async function notionDomPlugin(dom: any, route: HandledRoute | undefined) {
return Promise.resolve(dom);
}

return injectHtml(dom, htmlParser.parse(blocks.results), route);
return injectHtml(dom, htmlParser.parse(blocks.results as Blocks), route);
} catch (e) {
log(red(`Something went wrong. ${e}`));
return Promise.resolve(dom);
Expand Down
16 changes: 14 additions & 2 deletions libs/v4-types/src/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ import type {
} from '@notionhq/client/build/src/api-endpoints';

/** Property **/
export type PostResult = QueryDatabaseResponse['results'][number];
export type PostResult = Extract<
QueryDatabaseResponse['results'][number],
{ properties: Record<string, unknown> }
>;
export type PropertyValueMap = PostResult['properties'];
export type PropertyValue = PropertyValueMap[string];

Expand Down Expand Up @@ -49,7 +52,10 @@ export type PropertyValueUserPerson = Extract<
export type PropertyValueUserBot = Extract<PropertyValueUser, { type: 'bot' }>;

/** Block **/
export type Block = ListBlockChildrenResponse['results'][number];
export type Block = Extract<
ListBlockChildrenResponse['results'][number],
{ type: string }
>;

export type BlockType = Block['type'];

Expand Down Expand Up @@ -81,6 +87,9 @@ export type CalloutBlock = ExtractedBlockType<'callout'>;
export type ToDoBlock = ExtractedBlockType<'to_do'>;
export type BookmarkBlock = ExtractedBlockType<'bookmark'>;
export type ToggleBlock = ExtractedBlockType<'toggle'>;
export type TemplateBlock = ExtractedBlockType<'template'>;
export type SyncedBlock = ExtractedBlockType<'synced_block'>;
export type BreadcrumbBlock = ExtractedBlockType<'breadcrumb'>;

export type ChildPageBlock = ExtractedBlockType<'child_page'>;
export type ChildDatabaseBlock = ExtractedBlockType<'child_database'>;
Expand All @@ -98,6 +107,9 @@ export type DividerBlock = ExtractedBlockType<'divider'>;
export type ColumnBlock = ExtractedBlockType<'column'>;
export type ColumnListBlock = ExtractedBlockType<'column_list'>;

export type LinkPreviewBlock = ExtractedBlockType<'link_preview'>;
export type LinkToPageBlock = ExtractedBlockType<'link_to_page'>;

export type UnsupportedBlock = ExtractedBlockType<'unsupported'>;

/** RichText **/
Expand Down

0 comments on commit caf4b59

Please sign in to comment.