souvikinator / notion-to-md

Convert notion pages, block and list of blocks to markdown (supports nesting and custom parsing)
https://www.npmjs.com/package/notion-to-md
MIT License
1.09k stars 90 forks source link

WIP: Convert project to typescript #3 #8

Closed dharshatharan closed 2 years ago

dharshatharan commented 2 years ago

Feature: Typescript support #3

Followed similar typescript setup to @notionhq/client (makenotion/notion-sdk-js) - https://github.com/makenotion/notion-sdk-js

Things to Note:

Things yet to be done:

Looking for feedback on this implementation :)

souvikinator commented 2 years ago

Hey, great work. So I also gave this a try and referred to this https://github.com/instantish/martian/blob/master/src/notion/ where they defined the types making them independent of the notion SDK.

Dependency on notion SDK shouldn't be a problem, so I'll test it and let you know.

dharshatharan commented 2 years ago

Oh, interesting. I guess there are pros and cons of being tied to notion as a dependency. But I think the advantage is that we try and stay up to date with the changes in types in the notion SDK.

I feel like for our use case, having the dependency might be a good thing. After all, we do depend on the notion SDK anyways.

Thanks for checking it out, looking forward to seeing what you think.

souvikinator commented 2 years ago

@dharshatharan facing few errors on compiling, related to block argument in blockToMarkdown and blocksToMarkdown. I guess we can set it to any for now or have to use @ts-ignore.

dharshatharan commented 2 years ago

@souvikinator Sorry I was not feeling well for the past few days. What are these errors you are talking about? Can you provide me with some steps to reproduce them?

souvikinator commented 2 years ago

Hey @dharshatharan it's absolutely fine.

So there are some type-related errors because of blocks: ListBlockChildrenResponseResults and block: ListBlockChildrenResponseResult ig? Properties like image, videos,equations... do not exist in block.

dharshatharan commented 2 years ago

I don't get these errors you are talking about. I'm able to parse images, videos, and equations with no errors thrown and I don't get any type related errors showing up on VSCode. Can you double-check if you have the latest changes and have everything installed properly? Or if you're still having issues, maybe send me exact steps to replicate it or send me a screenshot?

souvikinator commented 2 years ago

Okay so I noticed that the latest commit is causing the issue however still can't figure out the reason.

In utils/notion.js the getChildren() takes extra argument called totalPage to deal with pagination https://github.com/souvikinator/notion-to-md/blob/d548ee42d0d3d03a2a1a58d3137f365aa5459f3b/utils/notion.js#L1

so we retrieve children like so (with extra args):

const response = await notionClient.blocks.children.list({
        start_cursor: start_cursor,
        page_size: pageSize,
        block_id: block_id,
      });

image

removing start_cursor and page_size fixes the issue:

image

seems like this is a type-related issue from the SDK side but I'm not sure.

Workaround:

 const response = (await notionClient.blocks.children.list({
        start_cursor,
        page_size,
        block_id,
  })) as ListBlockChildrenResponse;

Also please make the required changes as per #9

dharshatharan commented 2 years ago

I had to merge the latest changes from master and I performed the workaround you recommended. Hopefully, it works now.

souvikinator commented 2 years ago

Hey, @dharshatharan thanks for contributing. Did minor changes, and restructured the project. Will be releasing an update shortly.