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

@begin-functions/data

v1.0.4

Published

[ ![Codeship Status for smallwins/fun-data](https://app.codeship.com/projects/1f33e4b0-21ac-0136-c2d9-3a7e7af3da57/status?branch=master)](https://app.codeship.com/projects/285941)

Downloads

11

Readme

begin functions data

Codeship Status for smallwins/fun-data

BFD is an durable and fast key/value store for Begin Functions built on top of DynamoDB with storage/access patterns similar to Redis.

Considerations

  • A document is maximum 100KB
  • Paginated reads return 1MB per page
  • namespaces are unique to an app
  • keys are unique to a namespace
  • namespaces and keys must start with a letter
  • namespaces and keys can only contain lowercase characters, numbers, dashes and colons
  • namespaces and keys must be minimum 1 character and max 255 characters

Data Types

Namespaces contain documents. Documents stored in BFD always have the following keys:

  • ns which references the document namespace
  • key which is a unique identifier within a namespace

Optionally a document can also have a ttl key with a UNIX epoch value representing the expiry time for the document.

Every namespace also has a reserved key _count which is used for generating unique keys within the namespace

API

Grab a BFD client named data.

let data = require('@begin-functions/data')

Writes

Save a document in a namespace by key. Remember ns is always required.

data.set({
  ns: 'tacos', 
  key: 'al-pastor'
}, console.log)

key is optional. But all documents have a key. If no key is given set will generate a key unique to the namespace.

data.set({
  ns: 'tacos', 
}, console.log)

Batch save multiple documents at once by passing an array of objects.

data.set([
  {ns: 'ppl', name:'brian', email:'[email protected]'},
  {ns: 'ppl', name:'sutr0', email:'[email protected]'},
  {ns: 'tacos', key:'pollo'},
  {ns: 'tacos', key:'carnitas'},
], console.log)

Reads

Read a document by key.

data.get({
  ns: 'tacos', 
  key: 'al-pastor'
}, console.log)

Or paginate an entire namespace.

// define a read function
function read(cursor) {

  var uery = {ns: 'tacos'}

  // if we have a cursor add it to the query
  if (cursor) {
    query.cursor = cursor
  }

  // read the namespace
  data.get(query, function _get(err, page) {
    
    // bubble any errors
    if (err) throw err
    
    // log the docs
    console.log(page.docs)

    // continue reading if there's another page
    if (page.cursor) {
      read(cursor)
    }
  })
}

// start reading..
read()

Batch read by passing an array of objects. With these building blocks you can construct secondary indexesand joins like one-to-many and many-to-many.

data.get([
  {ns:'tacos', key:'carnitas'},
  {ns:'tacos', key:'al-pastor'},
], console.log)

Deletes

Delete a document by key.

data.del({
  ns: 'tacos', 
  key: 'pollo'
}, console.log)

Batch delete documents by passinng an array of objects.

data.del([
  {ns:'tacos', key:'carnitas'},
  {ns:'tacos', key:'al-pastor'},
], console.log)

Additional Superpowers

  • Documents can be expired by setting ttl to an UNIX epoch in the future.
  • Atomic counters: data.incr and data.decr

Patterns

Coming soon! Detailed guides for various data persistence tasks:

  • denormalizing
  • pagination
  • counters
  • hashids
  • secondary indexes
  • one to many
  • many to many