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

nosqlist

v0.0.5

Published

NoSQL Object Mapper for designing multiple access patterns.

Downloads

1

Readme

nosqlist

NoSQL Data Library For NodeJS. Primarily developed for use with Single Table Design on NoSQL databases(mostly DynamoDB) spoken about in the talks presented by Rick Houlihan at AWS Re:Invent: https://www.youtube.com/watch?v=6yqfmXiZTlM&t=2137s.

Motivation

Current Single Table solutions either work similarly to ORM's or are too opinionated for defining schema. The idea was to rather create schema that are self-descriptive, could be used within a function and don't really require any state. So, a simple interpolater on a key/value pairing sufficed.

Installation

npm install nosqlist

const {transform, flatten} = require("nosqlist");

Usage

transform

The primary idea of this function is to be able to interpolate values into keys of a data object to satisfy specific access patterns on a data model. This way developers can also separate keys of an entity into those that are used for access and those that hold needed data:

const {transform}              = require("nosqlist");


// test data 
const metadata  = {
    orgName: "Microsoft",
    planType: "Enterprise"
};

const userBillGates = {
    orgName: "Microsoft",
    UserName: "Bill Gates",
    UserType: "Member"
};

const userSatyaNadella = {
    orgName: "Microsoft",
    UserName: "Satya Nadella",
    UserType: "Admin"
};


// schemas 

const metaSchema = {
    "PK": "ORG#{orgName}",
    "SK": "METADATA#{orgName}",
    "OrgName": "{orgName}",
    "PlantType": "{planType}",
    "createdAt": () => Date.now()
};

const userSchema = {
    "PK": "ORG#{orgName}",
    "SK": "USER#{UserName}",
    "UserName": "{UserName}",
    "UserType": "{UserType}",
    "createdAt": () => Date.now()
};


// transform organisation
transform(metaSchema, metadata);
// {
//     PK: 'ORG#Microsoft',
//     SK: 'METADATA#Microsoft',
//     OrgName: 'Microsoft',
//     PlantType: 'Enterprise',
//     createdAt: 1595094213336
// }

// tranform user
transform(userSchema, userBillGates);
// {
//     PK: 'ORG#Microsoft',
//     SK: 'USER#Bill Gates',
//     UserName: 'Bill Gates',
//     UserType: 'Member',
//     createdAt: 1595094213343
// }

flatten

The flatten function takes a hierarchy of defined schemas and then generates an index of schemas that are the flattened version of the hierarchy. For example:

Let's say the requirement is we have to model an organisation where we have the organisation, users and tickets.

Our access patterns would be:

  • Get All Users for an organisation.
  • Get All Tickets for a user and organisation.
const {flatten}             = require("nosqlist");

const Ticket = {
    // name parameter decides what our entity is called within a hierarchy
    $name: "Ticket",
    // key parameter decides which key will be used to primarily identify this schema
    $key: "{ticketId}"
};

const User = {
    $name: "User",
    $key: "{emailAddress}",
    // we then define a relationship for an access pattern: 
    getTicketsByUser: {
        // define which schema was referenced here:
        schema: Ticket,
        // define the key that is used within this hierarchy
        key: {
            hash: "PK",
            range: "SK"
        }
    }
};

const Org = {
    $name: "Org",
    $key: "{orgId}",
    // relationship between user and organisation
    getUsersByOrg: {
        // define which schema was referenced here:
        schema: User,
        // define the key that is used within this hierarchy
        key: {
            hash: "PK",
            range: "SK"
        }
    }
};

// flatten the Org Schema(always the top-level schema.)
flatten({collection: Org});

//result:
{
  Ticket: {
    PK: 'Org#{orgId}',
    SK: 'User#{emailAddress}#Ticket#{ticketId}',
    '$name': 'Ticket',
    '$key': '{ticketId}'
  },
  User: {
    PK: 'Org#{orgId}',
    SK: 'User#{emailAddress}',
    '$name': 'User',
    '$key': '{emailAddress}'
  },
  Org: {
    PK: 'Org#{orgId}',
    SK: 'Org#{orgId}',
    '$name': 'Org',
    '$key': '{orgId}'
  }
} 

You can see here that when we invoke the transform function on the Ticket data, it will output data that makes it able to query the ticket via organisation and user. This would also make way for other access patterns such as getting a specific ticket.

Some Ending Comments

I've been building this library for fun and to learn more about the different use cases for single table designa and how people are using it. If you have any use cases that the library doesn't cater/work for, then I am very open to criticism as long as it is constructive :)

Hope you enjoy it!