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

dynalee

v0.4.3

Published

Typescript DynamoDB ORM

Downloads

11

Readme

dynalee

dyanlee is DML only DynamoDB ORM

Strongly typed.

Define model with way to follow DynamoDB philosophy.

usage

Model

define hash model

import {HashModel} from 'dynalee'

interface Cat {
  name: string
  birth: number
  color: string
}

const CatModel = new HashModel<Cat, 'name'>({
  table: 'TableName',
  hashKey: 'name'
})

const aCat = CatModel.of({
  name: 'first cat',
  birth: 2018,
  color: 'white'
})

const docCat = await aCat.put() // save
console.log(docCat.head())
/*
{
  name: 'first cat'
  birth: 2018
  color: 'white'
}
*/

define multiple model in one table

import {RangeModel} from 'dynalee'

interface Index {
  name: string
  birth: number
}
interface Cat extends Index {
  color: string
  age?: number,
  doYouWantSet?: string[]|Set<string> // use union for DynamoDB type and javascript type
  doYouWantList?: string[]
}
interface Dog extends Index {
  longLegs: boolean
}

const model = new RangeModel<Index, 'name', 'birth'>({
  table: 'TableName',
  hashKey: 'name',
  rangeKey: 'birth',
})
const CatModel = model as RangeModel<Cat, 'name', 'birth'>
const DogModel = model as RangeModel<Dog, 'name', 'birth'>

update

CatModel
    .update('deptno cat', '1985')
    .update(setter => {
      setter 
          .of({
            age: 10,
            color: 'white'
          }) // set multiple props
    })
    condition(setter => {
      setter.attributeNotExists('ID')
    })
    .returnValue('NONE')
    .run()

update 2

CatModel
    .update('deptno cat', '1985')
    .update(setter => {
      setter 
        .set('color', 'white')
        .add('age', 10)
    })
    condition((and, or, not) => {
      and.attributeNotExists('ID')
    })
    .returnValue('NONE')
    .run()

delete

CatModel.delete('deptno cat', '1985')

get item

CatModel.get('deptno cat', '1985')

Document

create

const document = await CatModel
    .of({
        name: 'son of deptno cat',
        birth: '2006',
        age: 10
    })
    .put() // save

get raw data

const document = await CatModel.get('deptno cat', '1985')
const rawdata = document.head()

delete

const document = await CatModel.get('deptno cat', '1985')
document.delete()

put

const document = await CatModel.get('deptno cat', '1985')
await document
    .set(setter => {
      setter.age = 10
      setter.color = 'white'
    })
    .put()

SecondaryIndex

define secondary index

import {SecondaryIndex} from 'dynalee'

interface Index {
  name: string
  birth: number
}
interface Cat extends Index {
  color: string
}
interface Dog extends Index {
  longLegs: boolean
}

const model = new SecondaryIndex<Index, 'name', 'birth'>({
  table: 'TableName',
  index: 'IndexTable',
  hashKey: 'species',
  rangeKey: 'birth'
})
const CatModel = model as SecondaryIndex<Cat, 'name', 'birth'>
const DogModel = model as SecondaryIndex<Dog, 'name', 'birth'>

query on secondary index

const documents = await CatModel
    .query('Turkish Angora')
    .run()
const items = documents.Items.map(item => item.head())

query on secondary index

const documents = await CatModel
    .rangeQuery('Turkish Angora')
    .eq('2006')
    .run()
const items = documents.Items.map(item => item.head())

more query options

const nextToken = null
const documents = await CatModel
    .rangeQuery('Turkish Angora')
    .eq('2006')
    .desc()
    .consistent()
    .limit(10)
    .startAt(nextToken)
    .run()
const items = documents.Items.map(item => item.head())

scan on secondary index

const documents = await CatModel
    .scan()
    .filter(setter => {
        setter.attributeNotExists('specis')
    })
    .run()
const items = documents.Items.map(item => item.head())

advanced usage

Set

const cat = await CatModel
    .of({
      name: 'my cat',
      birth: '2018',
      age: 10,
      doYouWantSet: new Set(['string set 1', 'string set 2'])
    })
    .update(setter => { // example code, `of` method can include below props
      setter
        .plus('age', 1)
        .add('doYouWantSet', new Set(['string set 3']))
    })
    .put()
    
const document = cat.head()
console.log(document.doYouWantSet instanceof Set) // true

const jsDocument = cat.head(true)
console.log(jsDocument.doYouWantSet instanceof Set) // false
console.log(Array.isArray(jsDocument.doYouWantSet)) // true

List

const cat = await CatModel
    .of({
      name: 'my cat',
      birth: '2018',
      age: 10,
      doYouWantList: ['string 1', 'string 2']
    })
    .update(setter => { // example code, `of` method can include below props
      setter
        .plus('age', 1)
        .add('doYouWantSet', ['string 3'])
    })
    .put()

Trigger

likes CreatedAt, UpdatedAt

import {HashModel, DocumentOptions} from 'dynalee'
const document: DocumentOptions = {
  onCreate: [
    {
      attributeName: 'CreatedAt',
      handler(prevVal?) {
        return new Date().toISOString()
      }
    },
  ],
  onUpdate: [
    {
      attributeName: 'UpdatedAt',
      handler(prevVal?) {
        return new Date().toISOString()
      }
    }
  ],
}
interface Cat {
  name: string
}
const CatModel = new HashModel<Cat, 'name'>({
  table: 'TableName',
  hashKey: 'name',
  options: {
    document
  }
})

use with dynamon

import {HashModel} from 'dynalee'
interface Cat {
  name: string
}
const CatModel = new HashModel<Cat, 'name'>({
  table: 'TableName',
  hashKey: 'name',
  options: {
    aws: {
      region  : 'dynamon',
      endpoint: 'http://localhost:8000'
    },
  }
})

link

#dynamon

license

MIT