npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

notionable

v0.1.13

Published

Simple CRUD for Notion API

Downloads

17

Readme

Notionable

Notionable is a general purpose package to work with Notion API. For now it contains the full CRUD methods set of Notion database that could be fetched from your integration. It, also, will generate Typescript types to have a better experience with databases structure.

Disclaimer

That tool is in the early stage of development, so it may work not as you (and I) expected, but I will (and maybe you will also) maintain and improve work with Notion API.

How to use

On first you should create an integration that have access to those databases you want to work with here. After you will get your integration secret key you can use it to retrieve your workspace.

Retrieving the workspace

You can easily retrieve your workspace with fetchWorkspace method:

import { Notionable } from 'notionable'

try {
  const myWorkspace = await Notionable.fetchWorkspace({ auth: YOUR_INTEGRATION_KEY }, './your-types-path')
  // it will also generate all database types that your integration has access to
} catch (e) {
  console.error(e)
}

Retrieving database CRUD interface

You can pass database name to get it quikly, it isn't case sensitive.

const usersDb = myWorkspace.getDatabase('users')
const users = await usersDb.find() 
// -> User[]

Crud interface methods

Create

const usersDb = await myWorkspace.getDatabase('users')
const newUser: User = {
  name: 'Stan'
}

const savedUser = await usersDb.create(newUser) 
// -> { id: 'd77da116-13ce-11ec-82a8-0242ac130003' , name: 'Stan' }

const moreSavedUsers = await usersDb.bulkCreate([newUser, newUser])
// -> [
//      { id: 'd77da116-13ce-11ec-82a8-0242ac130003' , name: 'Stan' },
//      { id: 'd77da116-13ce-11ec-82a8-0242ac130003' , name: 'Stan' }
//    ]

Read

const stanQuery= {
  filter: { 
    property: 'name',
    text: {
      contains: 'Stan'
    } 
  }
}

const usersNamedStan = await usersDb.find(stanQuery) 
// -> [{ id: 'd77da116-13ce-11ec-82a8-0242ac130003', name: 'Stan' }]

const oneStan = await usersDb.findOne(stanQuery) 
// -> { id: 'd77da116-13ce-11ec-82a8-0242ac130003', name: 'Stan' }

const userById = await usersDb.findById('d77da116-13ce-11ec-82a8-0242ac130003') 
// -> { id: 'd77da116-13ce-11ec-82a8-0242ac130003', name: 'Stan' }

Update

const newStan: User[] = {
  name: 'Stanly'
}

const stanly = await userDb.updateById('d77da116-13ce-11ec-82a8-0242ac130003', newStan)
// -> { id: 'd77da116-13ce-11ec-82a8-0242ac130003', name: Stanly }

const allTheStanlies = await userDb.updateOne(stanQuery, newStan)
// -> { id: 1, name: Stanly }

const allTheStanlies = await userDb.bulkUpdate(stanQuery, newStan)
// -> [
//      { id: 'd77da116-13ce-11ec-82a8-0242ac130003' , name: 'Stanly' },
//      { id: 'd77da116-13ce-11ec-82a8-0242ac130003' , name: 'Stanly' }
//    ]

Delete

const stanWasDeleted = await userDb.deleteById('d77da116-13ce-11ec-82a8-0242ac130003')
// -> true

const stanWasDeleted = await userDb.deleteOne(stanQuery)
// -> true

const stansWasDeleted = await userDb.bulkDelete(stanQuery)
// -> true