Skip to content

Commit

Permalink
release 0.0.0-internal.4
Browse files Browse the repository at this point in the history
  • Loading branch information
mildronize committed Feb 15, 2024
1 parent 408e5f1 commit 2afff5d
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 2 deletions.
83 changes: 82 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,84 @@
# Typed Notion Client

`@notionhq/client` wrapper with better Type-safe for Notion API.
`@notionhq/client` wrapper with better Type-safe for Notion API.

## Example

```typescript
import { Client as NotionClient } from '@notionhq/client';
import { NotionDatabase } from '../src/main';
import { z } from 'zod';

export const schema = z.object({
DATABASE_ID: z.string(),
NOTION_KEY: z.string(),
});

export const env = schema.parse(process.env);
const notion = new NotionClient({ auth: env.NOTION_KEY });
export const myDatabase = new NotionDatabase({
notionClient: notion,
databaseId: env.DATABASE_ID,
propTypes: {
Name: 'title',
Date: 'date',
Note: 'rich_text',
},
});

/**
* Create a new page under the database (new record)
*/

async function createPage() {
const page = await myDatabase.page.create(prop => ({
properties: {
...prop['Note'].params({
rich_text: [
{
text: {
content: 'My Note!',
},
},
]
}),
...prop['Name'].params({
title: [
{
text: {
content: 'Hello, world!',
},
},
],
}),
...prop['Date'].params({
date: {
start: new Date().toISOString(),
},
}),
},
}));
console.log(`Created page: ${page.id}`);
return page.id;
}

async function filterToday() {
const pages = await myDatabase.query(prop => ({
filter: prop['Date'].params({
date: {
equals: new Date().toISOString(),
},
}),
}));
for (const page of pages) {
const title = page.properties.Name.title[0].plain_text;
console.log(`Today's page: ${page.id} - ${title}`);
}
}


async function main(){
await createPage();
await filterToday();
}
```
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "typed-notion-client",
"version": "0.0.0-internal.3",
"version": "0.0.0-internal.4",
"description": "Type-safe Notion API client",
"main": "./dist/main.js",
"module": "./dist/main.mjs",
Expand Down

0 comments on commit 2afff5d

Please sign in to comment.