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

dynamoflow

v1.5.0

Published

A practical & extendable DynamoDB client for TypeScript applications.

Downloads

17

Readme

DynamoFlow

A practical & extendable DynamoDB client for TypeScript applications.

Coverage Status NPM code style: prettier semantic-release

Release notes

Features

Why?

Unlike many other database technologies, DynamoDB expects your data management logic to live in the application layer. Rather than providing built-in features such as unique fields, foreign keys, or cascading deletes, DynamoDB provides the foundational technologies to implement these features yourself.

Rather than picking which of these features we do and don't include, DynamoFlow provides a set of tools to make it easy to implement these features yourself. We also provide a set of ready-to-go extensions for common patters, such as unique fields, foreign keys, secondary indexes & timestamping

There are several other Typescript DynamoDB clients available, and I encourage you to check them all out before committing to one.

My personal favourites are

Getting Started

  1. Install the package: npm install --save dynamoflow or yarn add dynamoflow
  2. Install the Amazon SDK, if not already installed npm install --save @aws-sdk/client-dynamodb @aws-sdk/lib-dynamodb or yarn add @aws-sdk/client-dynamodb @aws-sdk/lib-dynamodb
  3. Start DynamoDB Local docker run -p 8000:8000 amazon/dynamodb-local (or copy our example docker-compose.yml file)
  4. Create a DFTable instance
    1. Following single table design, your application will likely only have one DFTable instance
    2. AWS credentials are loaded from the v3 SDK
import {DFTable} from "dynamoflow";

const table = new DFTable({
  tableName: "my-application-table",
  GSIs: ["GSI1", "GSI2"], // GSIs can be added later if needed

  // using DynamoDBLocal
  endpoint: "http://localhost:8000",
});

// not recommended for production use, but useful for local development
await table.createTableIfNotExists();
  1. Define types for your entities
    1. Any normal TypeScript type can be used, DynamoFlow does not care about the schema of your objects
    2. If desired, you can use extensions like DFZodValidationExt to validate your objects at runtime
  2. Create collections for each entity type you have
    1. Collections are used to read & write from your table
    2. Many collections can exist within a single Table
    3. Extensions can be used to add additional functionality to your collections
import {DFUniqueConstraintExt} from "dynamoflow";

interface User {
   id: string;

   name: string;
   email: string;
}

const usersCollection = table.createCollection<User>({
   name: "users",
   partitionKey: "id",
   extensions: [
      new DFUniqueConstraintExt('email')
   ],
});

interface Project {
   id: string;
   userId: string;

   name: string;
   description: string;

   status: "DRAFT" | "IN-PROGRESS" | "COMPLETED";
}

const projectsCollection = table.createCollection<Project>({
   // the name of the collection is used to prefix the partition key for each item
   name: "projects",

   // any string, number or boolean fields of this entity can be used as keys
   // different collections can have different keys
   partitionKey: "userId",
   sortKey: "id"
});
  1. Use these collections to read & write from your table
const user1 = await usersCollection.insert({
    id: "user-1",
    name: "John Smith",
    email: "[email protected]"
});

const insertedProject = await projectsCollection.insert({
  id: "project-1",
  userId: user1.id,

  name: "My First Project",
  description: "This is my first project",

  status: "DRAFT",
});

await projectsCollection.update({
  id: "project-1"
}, {
  status: "IN-PROGRESS"
});

const retrievedProject = await projectsCollection.retrieveOne({
  where: {
    userId: "user-1",
    id: "project-1"
  }
});

For a more comprehensive example, take a look at the included Messaging app demo.

Once you're ready to test against a real DynamoDB table, read Configuring DynamoDB Tables