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

@toi/dynamo

v1.0.15

Published

Toi's Dynamo is a validator and transformer of DynamoDB objects for TypeScript.

Downloads

16

Readme

Toi's Dynamo

Build Status codecov

Toi is a validator for JavaScript values written in TypeScript.

This is the extra package, where you can find extra validators and transformers useful for working with DynamoDB values.

It's heavily inspired by Joi, but actually uses different features from TypeScript's type system to infer the output type of a validation schema.

See the documentation on Toi on GitHub: github.com/hf/toi.

What's up with Dynamo?

If you've ever seen DynamoDB's values you'll shriek. Amazon tried to do a good job, and let's face it -- JavaScript is terrible with data types -- but the system they chose is weird and difficult to work with. Toi's Dynamo helps with that.

Toi is a validation chain builder, but it can also transform values in the same steps. Dynamo uses these capabilities to transform (and also validate!) DynamoDB values.

It turns an object like this:

const value = {
  M: {
    Null: { NULL: true }, // this is my favorite monstrosity!
    Number: { N: "0.123" },
    String: { S: "Hello, Toi's Dynamo!" },
    Binary: { B: "SGVsbG8sIFRvaSdzIER5bmFtbyE=" },
    Bool: { BOOL: true },
    NumberSet: { NS: ["123", "456"] },
    StringSet: { SS: [ "a", "b" ] }, // really, they had to use "SS"
    BinarySet: { BS: [ "Yq==", "Yg==" }, // it's b.s. !
    ArrayList: { L: [ /* other values here recursively */ ] },
    // ...
  }
}

into:

const validator = toi.optional()
  .and(dynamo.map.is())
  .and(toi.obj.keys({
    Null: dynamo.isnull(),   // null if null, null if { NULL: true }
    String: dynamo.str.is(), // -> string
    Number: dynamo.num.is().and(toi.num.parse()),
    // -> number in JavaScript
    Binary: dynamo.bin.is(), // -> Buffer
    Bool: dynamo.bool.is(), // -> boolean
    NumberSet: dynamo.numset.is().and(toi.array.items(toi.num.parse())),
    // -> number[] in JavaScript,
    StringSet: dynamo.strset.is(), // -> string[]
    BinarySet: dynamo.binset.is(), // -> Buffer[]
    ArrayList: dynamo.list.is(), // -> unknown[]
  })

Additionally it can do validation on the object if you need to use it for schema versioning or similar use cases.

Contributors

  • Stojan Dimitrovski

License

Copyright © 2018 Stojan Dimitrovski et al., some rights reserved.

Licensed under the MIT license. You can get a copy of it in LICENSE.