diff --git a/README.md b/README.md index fa01038..8149981 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,84 @@ # Typed Notion Client -`@notionhq/client` wrapper with better Type-safe for Notion API. \ No newline at end of file +`@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(); +} +``` \ No newline at end of file diff --git a/package.json b/package.json index 652d1c8..b60a4a9 100644 --- a/package.json +++ b/package.json @@ -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",