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

@uoa/dynamo-utils

v1.0.5

Published

This library contains a helper class which assists with transformations commonly used in projects typescript projects using DynamoDB in University of Auckland projects. This library currently only supports transformation syntax for the dynamoDB document c

Downloads

3

Readme

UOA DynamoHelper

This library contains a helper class which assists with transformations commonly used in projects typescript projects using DynamoDB in University of Auckland projects. This library currently only supports transformation syntax for the dynamoDB document client.

Usage

First initialize the class after import as follows

const DynamoHelper = require("@uoa/dynamo-utils")
let dbHelper = new DynamoHelper("A table","PK", "SK");

This initializes an instance of the dynamoHelper where the partition key of the table is defined to be 'PK', while the sort key for the table is defined as 'SK' and the table name, in this case being "A table". Therefore, the Keys in all transformations will be using the Hash Key provided in the constructor.

Now you can use the helper functions below attached to the class.

transformItemsToDeleteRequests(databaseItems: any[], hashKey: string, sortKey?: string)
transformItemsToUpdateRequests(databaseItems: any[], hashKey: string, sortKey?: string)

Both above methods will transform a list of items to either the syntax required for batch delete requests or batch update requests to be used with the BacthWriteItem operation. The hashKey and sortKey will be the keys used to get the parameter value on the current object in the list of databaseItems to be used as the table hashKey & sortKey values ref: https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_BatchWriteItem.html

transformItemsToBatchGetRequests(
    databaseItems: any[],
    hashKey?: string,
    sortkey?: string,
    numItems?: number
  )

This operation will transform the array of objects to be used with the BatchGetItem operation. Like above the hashKey and sortKey will be called on the current object inside of the array of objects. If the keys are undefined, the hashKey and sortKey passed in the constructor will be used. The numItems parameter can be passed in without providing a hashKey or sortKey in the scenario where the keys passed in the constructor should be used on the object. The defualt array size for the Keys parameter is 25. ref: https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_BatchGetItem.html

setDynamicUpdateParameters(objectToUpdate: any, operation: string, hashKey?:string, sortKey?:string)

takes in an object and operation (set,remove,add,delete) and returns the respective parameters to perform the operation. hashKey and sortKey are the keys to be called on the objectToUpdate if the object does not use the same hashKey and sortKey as the initialized class, if these parameters are not provided, the initialized hashKey and sortKey (if used) will be used as the keys on the objectToUpdate. If the hashKeys and sortKeys are undefined on the objectToUpdate, an empty Key property will be returned and will need to be set for the operation to be successful to dynamoDB. ref: https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_UpdateItem.html

setDynamicCreateParameters(objectToCreate: any,hashKey?: string,sortKey?: string)

takes an object which is to be used with the PutItem operation on the document client. If hashKey and sortKey is provided, those keys will be used on the objectToCreate to get the values of the object if the hashKey and sortKey passed in the constructor are undefined on the objectToCreate. The default is to use the same hashKey and sortKey as passed in the constructor.

createBatchSlices(databaseItems: any[], tableName?: string)

splits an array into slices of size 25 and below nested in a {RequestItems : 'TABLE_NAME' : []}, this is for batch operations. If a table name is not supplied to the method, it will use the tableName passed into the constructor.