Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ivynya/notion_flatten
Flattens Notion API responses to be easier to work with.
https://github.com/ivynya/notion_flatten
deno notion notion-api
Last synced: 30 days ago
JSON representation
Flattens Notion API responses to be easier to work with.
- Host: GitHub
- URL: https://github.com/ivynya/notion_flatten
- Owner: ivynya
- License: mit
- Created: 2021-12-22T06:57:10.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2022-01-17T06:56:41.000Z (almost 3 years ago)
- Last Synced: 2024-11-17T14:12:34.347Z (about 1 month ago)
- Topics: deno, notion, notion-api
- Language: TypeScript
- Homepage: https://deno.land/x/notion_flatten
- Size: 24.4 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# notion-flatten
> ⚠️ WIP, flattened object schema subject to change in future versions.
>
> ⚠️ Probably not a good idea use this in a production scenario (for now). You have been warned.Flattens Notion API responses to be easier to work. This is accomplished by removing type and other information (and therefore the assosciated nested objects created by the Notion API).
This module is best used if type information is known beforehand, but if type information is needed, a flattened database schema can be generated using `flattenDatabase` containing all DB properties and type information.
## Usage Examples
### Pre & Post Transformation Data
Examples of non-flattened and flattened data are available in the [test folder](./test) of this repository. Each file contains raw API data as well as the flattened version of that data, according to the appropriate transform function.### Flattening a Database Query
```ts
import { flattenQuery } from "https://deno.land/x/[email protected]/mod.ts";const res = await fetch(`https://api.notion.com/v1/databases/:id/query`, ...);
const data = await res.json();const flatData = flattenQuery(data);
```### Flattening Database Meta Info
```ts
import { flattenDatabase } from "https://deno.land/x/[email protected]/mod.ts";const res = await fetch(`https://api.notion.com/v1/databases/:id`, ...);
const data = await res.json();const flatMetadata = flattenDatabase(data);
```### Flattening a Page
```ts
import { flattenPage } from "https://deno.land/x/[email protected]/mod.ts";const res = await fetch(`https://api.notion.com/v1/pages/:id`, ...);
const data = await res.json();const flatPage = flattenPage(data);
```### Flattening a Property
```ts
import { flattenProperty } from "https://deno.land/x/[email protected]/mod.ts";const res = await fetch(`https://api.notion.com/v1/pages/:id`, ...);
const data = await res.json();const flatPage = flattenProperty(data);
```