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

@raydeck/ddb-manager

v3.6.1

Published

Base class for managing DynamoDB model

Downloads

47

Readme

@raydeck/ddb-manager - v3.6.1

@raydeck/ddb-manager - v3.6.1

Index

Classes

Functions

Functions

cappedPageMap

cappedPageMapT, R›(paginator: function, f: function, limit: number, lastKey?: string, filter: function): Promise‹[R[], string | undefined]›

Defined in src/index.ts:147

Iterate through pages until hitting a specified limit as generic. Allows pagination independent of DB limits

example

const [numbers, nextKey] = await cappedpageMap(
(l) => Number_page(account, l),
async (number) => number
);

Type parameters:

T

Type of objects the paginator returns

R

Type of return value (defaults to void)

Parameters:

paginator: function

Function that returns a page as [object[], lastKey] tuple (like queryPage)

▸ (l?: string): Promise‹[T[], string | undefined]›

Parameters:

Name | Type | ------ | ------ | l? | string |

f: function

Map function - takes output of queryPage and returns a value

▸ (arg: T): Promise‹R›

Parameters:

Name | Type | ------ | ------ | arg | T |

Default value limit: number= 1000

Number of records beyond which we don't get more from DB.

Optional lastKey: string

Last key used for the pagination (e.g. returned by the last call to cappedPageMap)

Default value filter: function= async (arg) => true

async function for filtering results

▸ (arg: T): Promise‹boolean›

Parameters:

Name | Type | ------ | ------ | arg | T |

Returns: Promise‹[R[], string | undefined]›


pageMap

pageMapT, R›(paginator: function, f: function, filter: function): Promise‹R[]›

Defined in src/index.ts:122

Iterate through all pages of a function as generic

example

const numbers = await pageMap(
(l) => Number_page(account, l),
async (number) => number.getId()
);

Type parameters:

T

Type of objects the paginator returns

R

Type of return value (defaults to void)

Parameters:

paginator: function

Function that returns a page as [object[], lastKey] tuple (like queryPage)

▸ (l?: string): Promise‹[T[], string | undefined]›

Parameters:

Name | Type | ------ | ------ | l? | string |

f: function

Map function - takes output of queryPage and returns a value

▸ (arg: T): Promise‹R›

Parameters:

Name | Type | ------ | ------ | arg | T |

Default value filter: function= async (arg) => true

async function for filtering results

▸ (arg: T): Promise‹boolean›

Parameters:

Name | Type | ------ | ------ | arg | T |

Returns: Promise‹R[]›


queryPage

queryPage(__namedParameters: object, lastKey?: string): Promise‹[object[], string | undefined]›

Defined in src/index.ts:43

Run paginated query on dynamoDB table

Parameters:

__namedParameters: object

Query options

Name | Type | Default | ------ | ------ | ------ | IndexName | string | - | Key | string | - | Limit | number | 50 | TableName | string | - | Value | string | number | - | isReversed | boolean | false |

Optional lastKey: string

Specifies where to start query. Undefined returned when no more items found

Returns: Promise‹[object[], string | undefined]›


scanPage

scanPage(__namedParameters: object, lastKey?: string): Promise‹[object[], string | undefined]›

Defined in src/index.ts:87

Iterate through whole table - returns only the fields specified

Parameters:

__namedParameters: object

Scan options

Name | Type | ------ | ------ | TableName | string | fields | string[] |

Optional lastKey: string

Returns: Promise‹[object[], string | undefined]›


setDDB

setDDB(newDDB: DocumentClient): void

Defined in src/index.ts:13

Set new instance of DynamoDB for ddb-manager to use

Parameters:

Name | Type | Description | ------ | ------ | ------ | newDDB | DocumentClient | Instance of DynamoDB |

Returns: void

@raydeck/ddb-manager - v3.6.1DDBError

Class: DDBError

Class for high-level DDBManager errors that can include the original raw DDB/AWS error

Hierarchy

Index

Properties

Properties

message

message: string

Inherited from DDBError.message

Defined in node_modules/typescript/lib/lib.es5.d.ts:974


name

name: string

Inherited from DDBError.name

Defined in node_modules/typescript/lib/lib.es5.d.ts:973


Optional rawError

rawError? : Error

Defined in src/index.ts:20


Optional stack

stack? : string

Inherited from DDBError.stack

Defined in node_modules/typescript/lib/lib.es5.d.ts:975


Static Error

Error: ErrorConstructor

Defined in node_modules/typescript/lib/lib.es5.d.ts:984

@raydeck/ddb-manager - v3.6.1DDBHandler

Class: DDBHandler

Manager to handle CRUD operations on a dynamoDB item

Hierarchy

  • DDBHandler

Index

Constructors

Properties

Methods

Constructors

constructor

+ new DDBHandler(tableName: string, hashKey: string): DDBHandler

Defined in src/index.ts:194

Parameters:

Name | Type | Default | ------ | ------ | ------ | tableName | string | - | hashKey | string | "id" |

Returns: DDBHandler

Properties

Protected _hashKey

_hashKey: string

Defined in src/index.ts:182

Item partition key name


cachedValues

cachedValues: object

Defined in src/index.ts:178

Item attributes

Type declaration:

  • [ key: string]: any

exists

exists: boolean = false

Defined in src/index.ts:190

Flag that indicates whether item saved persistently. If true, item exists in dynamoDB table; if false, item does not exist in dynamoDB table


id

id: object

Defined in src/index.ts:186

Item primary key

Type declaration:


loaded

loaded: boolean = false

Defined in src/index.ts:194

Flag that indicates where item data comes from. If true, data was passed via loadFromItem; if false, data was loaded directly from dynamoDB table


Protected tableName

tableName: string

Defined in src/index.ts:174

DynamoDB table item lives in

Methods

_create

_create(o: object, id: any, options: object): Promise‹this›

Defined in src/index.ts:497

Create new dynamoDB Item

If item with primary key already exists, that item will be replaced

Parameters:

Name | Type | Default | Description | ------ | ------ | ------ | ------ | o | object | - | Shape of item | id | any | - | Items primary key | options | object | {} | Options for dynamoDB put operation |

Returns: Promise‹this›


Protected _update

_update(updates: object): Promise‹this›

Defined in src/index.ts:444

Update attributes

Parameters:

Name | Type | Description | ------ | ------ | ------ | updates | object | Object of attribute key/value pairs |

Returns: Promise‹this›


Protected cacheIncrements

cacheIncrements(increments: object): [string, number][]

Defined in src/index.ts:280

Cache increments.

Updates are saved locally only. Item in dynamoDB table will not be updated by this function

Parameters:

Name | Type | Description | ------ | ------ | ------ | increments | object | increments to item attributes (e.g. {count:5} would increment count by +5) |

Returns: [string, number][]


delete

delete(key?: string | object): Promise‹void›

Defined in src/index.ts:593

Delete item

Parameters:

Name | Type | Description | ------ | ------ | ------ | key? | string | object | Primary key of item to delete |

Returns: Promise‹void›


get

getT›(key: string, def?: T): T | undefined

Defined in src/index.ts:551

Get attribute

Type parameters:

T

Parameters:

Name | Type | Description | ------ | ------ | ------ | key | string | Name of attribute | def? | T | Default value for attribute |

Returns: T | undefined


has

has(key: string): boolean

Defined in src/index.ts:558

Check if attribute exists

Parameters:

Name | Type | Description | ------ | ------ | ------ | key | string | Name of attribute |

Returns: boolean


hashKey

hashKey(): string

Defined in src/index.ts:211

Return partition key name

Returns: string


hashPage

hashPage(hashValue: any, lastValue?: string): Promise‹[object[], string]›

Defined in src/index.ts:606

Run paginated query against partition key

Parameters:

Name | Type | Description | ------ | ------ | ------ | hashValue | any | Value of items partition key | lastValue? | string | Specifies where to start query. Undefined returned when no more items found |

Returns: Promise‹[object[], string]›


increment

increment(field: string, byValue: number): Promise‹this›

Defined in src/index.ts:394

Increment one attribute

Parameters:

Name | Type | ------ | ------ | field | string | byValue | number |

Returns: Promise‹this›


indexPage

indexPage(indexName: string, key: string, value: any, lastValue?: string): Promise‹[object[], string]›

Defined in src/index.ts:623

Run paginated query against global or secondary index

Parameters:

Name | Type | Description | ------ | ------ | ------ | indexName | string | Name of global or secondary index | key | string | Partition (or sort) key to search against | value | any | Value an items "Key" should have | lastValue? | string | - |

Returns: Promise‹[object[], string]›


load

load(o: any): Promise‹this›

Defined in src/index.ts:565

Initialize instance from dynamoDB item

Parameters:

Name | Type | Description | ------ | ------ | ------ | o | any | Item primary key |

Returns: Promise‹this›


loadFromItem

loadFromItem(Item: object): this

Defined in src/index.ts:583

Initialize instance from a plain old javascript object

Parameters:

Name | Type | Description | ------ | ------ | ------ | Item | object | |

Returns: this


Protected processRemoves

processRemoves(keys: string[]): string[]

Defined in src/index.ts:318

Transform an removes object to an array of tuples.

Updates are saved locally only. Item in dynamoDB table will not be updated by this function

Parameters:

Name | Type | ------ | ------ | keys | string[] |

Returns: string[]


Protected processUpdates

processUpdates(updates: object): [string, any][]

Defined in src/index.ts:244

Transform an updates object to an array of tuples.

Updates are saved locally only. Item in dynamoDB table will not be updated by this function

Parameters:

Name | Type | Description | ------ | ------ | ------ | updates | object | Updates to item attributes |

Returns: [string, any][]


remove

remove(key: string): Promise‹void›

Defined in src/index.ts:226

Remove attribute from a record

Parameters:

Name | Type | Description | ------ | ------ | ------ | key | string | Name of attribute |

Returns: Promise‹void›


set

set(key: string, value: any): Promise‹void›

Defined in src/index.ts:219

Set attribute

Parameters:

Name | Type | Description | ------ | ------ | ------ | key | string | Name of attribute | value | any | Value of attribute |

Returns: Promise‹void›


setId

setId(id: string | object): void

Defined in src/index.ts:205

Set id (primary key) of an item

Parameters:

Name | Type | Description | ------ | ------ | ------ | id | string | object | Item primary key Id should be an object for a composite primary key |

Returns: void


setValues

setValues(mapOfValues: object): Promise‹void›

Defined in src/index.ts:233

Set multiple attributes

Parameters:

Name | Type | Description | ------ | ------ | ------ | mapOfValues | object | Object of attribute key/value pairs (e.g. {attribute1: "value1", attribute2: false}) |

Returns: Promise‹void›