0.2.0 • Published 6 months ago

ds-aws-utils v0.2.0

Weekly downloads
-
License
MIT
Repository
github
Last release
6 months ago

ds-aws-utils package

How to Publish

Push tag publish/*

dynamodb

Type check methods (for single table pattern)

  • Use the same object structure as in aws-sdk
export type UserState = 'New' | 'Register'
export interface UserData {
  PK: `User#${string}`          // {userId}
  SK: '#'
  
  GSI1PK: `User`                // -> query all users
  GSI1SK: `${number}`           // {createdTime}
  
  GSI1PK: `User#${UserState}`   // -> query users by state
  GSI1SK: `${number}`           // {updatedTime}
}

const newItem = await updateItem<UserData>({
  TableName: tableName,
  Key: {
    PK: `User#123`,             // literal string check
    SK: '#'                     // literal string check
  },
  UpdateExpression: "SET #GSI2PK=:GSI2PK",
  ExpressionAttributeNames: {
    "#GSI2PK": "GSI2PK"          
  },
  ExpressionAttributeValues: {
    ":GSI2PK": "User#New"       // literal string check
  }
})

One liners

This is meant to be used for quick scripting. For maintainable codes, should still use Type Check methods

function query(table: string, index: string | null, expression: string, pk, sk?: string, pages: number = 1, forward: boolean = true): Promise<object[]> {}

function getItem(table: string, pk: string, sk: string): Promise<Object> {}

function updateItem(table: string, pk: string, sk: string, expression: string, props: {names, values, condition}): Promise<Object> {}

Example Usage

import {query} from "ds-aws-utils"

const table = "your-table";

const users = await query(table, "gsi1-index", "#GSI1PK=:GSI1PK and begin_with(#GSI1PK,:#GSI1SK)", "User", "SignedUp#", 1, false);

const userA = await getItem(table, "User#123", "#");

cognito

0.2.0

6 months ago

0.1.10

7 months ago

0.1.9

7 months ago

0.1.8

10 months ago

0.1.7

10 months ago

0.1.4

12 months ago

0.1.3

12 months ago

0.1.6

11 months ago

0.1.5

12 months ago

0.1.2

1 year ago

0.1.1

1 year ago

0.0.5

1 year ago

0.0.3

1 year ago

0.0.4

1 year ago

0.0.1

1 year ago