Gathering detailed insights and metrics for @dolsem/dynamodb-toolbox
Gathering detailed insights and metrics for @dolsem/dynamodb-toolbox
Gathering detailed insights and metrics for @dolsem/dynamodb-toolbox
Gathering detailed insights and metrics for @dolsem/dynamodb-toolbox
npm install @dolsem/dynamodb-toolbox
Typescript
Module System
Node Version
NPM Version
75.7
Supply Chain
99.1
Quality
75.3
Maintenance
100
Vulnerability
100
License
TypeScript (100%)
Total Downloads
440
Last Day
1
Last Week
3
Last Month
13
Last Year
84
1,857 Stars
1,368 Commits
174 Forks
26 Watching
9 Branches
62 Contributors
Latest Version
0.5.0-beta.0-1
Package Id
@dolsem/dynamodb-toolbox@0.5.0-beta.0-1
Unpacked Size
263.45 kB
Size
42.64 kB
File Count
45
NPM Version
8.1.0
Node Version
16.13.0
Cumulative downloads
Total Downloads
Last day
0%
1
Compared to previous day
Last week
50%
3
Compared to previous week
Last month
225%
13
Compared to previous month
Last year
-46.2%
84
Compared to previous year
1
The DynamoDB Toolbox is a set of tools that makes it easy to work with Amazon DynamoDB and the DocumentClient. It's designed with Single Tables in mind, but works just as well with multiple tables. It lets you define your Entities (with typings and aliases) and map them to your DynamoDB tables. You can then generate the API parameters to put
, get
, delete
, update
, query
, scan
, batchGet
, and batchWrite
data by passing in JavaScript objects. The DynamoDB Toolbox will map aliases, validate and coerce types, and even write complex UpdateExpression
s for you. 😉
v0.4 is here and now supports "Type Inferencing" 😎. This is a new feature that infers types from your Entity definitions. There should be NO regressions from v0.3.5, but please submit an issue if you find one!
Feedback is welcome and much appreciated! (Huge thanks to @ThomasAribart for all his work on this 🙌)
Install DynamoDB Toolbox:
1# npm 2npm i dynamodb-toolbox 3 4# yarn 5yarn add dynamodb-toolbox
Require or import Table
and Entity
from dynamodb-toolbox
:
1import { Table, Entity } from 'dynamodb-toolbox'
Create a Table (with the DocumentClient):
1import DynamoDB from 'aws-sdk/clients/dynamodb' 2 3const DocumentClient = new DynamoDB.DocumentClient({ 4 // Specify your client options as usual 5 convertEmptyValue: false 6}) 7 8// Instantiate a table 9const MyTable = new Table({ 10 // Specify table name (used by DynamoDB) 11 name: 'my-table', 12 13 // Define partition and sort keys 14 partitionKey: 'pk', 15 sortKey: 'sk', 16 17 // Add the DocumentClient 18 DocumentClient 19})
Create an Entity:
1const Customer = new Entity({ 2 // Specify entity name 3 name: 'Customer', 4 5 // Define attributes 6 attributes: { 7 id: { partitionKey: true }, // flag as partitionKey 8 sk: { hidden: true, sortKey: true }, // flag as sortKey and mark hidden 9 age: { type: 'number' }, // set the attribute type 10 name: { type: 'string', map: 'data' }, // map 'name' to table attribute 'data' 11 emailVerified: { type: 'boolean', required: true }, // specify attribute as required 12 co: { alias: 'company' }, // alias table attribute 'co' to 'company' 13 status: ['sk', 0], // composite key mapping 14 date_added: ['sk', 1] // composite key mapping 15 }, 16 17 // Assign it to our table 18 table: MyTable 19 20 // In Typescript, the "as const" statement is needed for type inference 21} as const)
Put an item:
1// Create an item (using table attribute names or aliases) 2const customer = { 3 id: 123, 4 age: 35, 5 name: 'Jane Smith', 6 emailVerified: true, 7 company: 'ACME', 8 status: 'active', 9 date_added: '2020-04-24' 10} 11 12// Use the 'put' method of Customer: 13await Customer.put(customer)
The item will be saved to DynamoDB like this:
1{ 2 "pk": 123, 3 "sk": "active#2020-04-24", 4 "age": 35, 5 "data": "Jane Smith", 6 "emailVerified": true, 7 "co": "ACME", 8 // Attributes auto-generated by DynamoDB-Toolbox 9 "_et": "customer", // Entity name (required for parsing) 10 "_ct": "2021-01-01T00:00:00.000Z", // Item creation date (optional) 11 "_md": "2021-01-01T00:00:00.000Z" // Item last modification date (optional) 12}
You can then get the data:
1// Specify primary key 2const primaryKey = { 3 id: 123, 4 status: 'active', 5 date_added: '2020-04-24' 6} 7 8// Use the 'get' method of Customer 9const response = await Customer.get(primaryKey)
Since v0.4, the method inputs, options and response types are inferred from the Entity definition:
1await Customer.put({ 2 id: 123, 3 // ❌ Sort key is required ("sk" or both "status" and "date_added") 4 age: 35, 5 name: ['Jane', 'Smith'], // ❌ name should be a string 6 emailVerified: undefined, // ❌ attribute is marked as required 7 company: 'ACME' 8}) 9 10const { Item: customer } = await Customer.get({ 11 id: 123, 12 status: 'active', 13 date_added: '2020-04-24' // ✅ Valid primary key 14}) 15type Customer = typeof customer 16// 🙌 Type is equal to: 17type ExpectedCustomer = 18 | { 19 id: any 20 age?: number | undefined 21 name?: string | undefined 22 emailVerified: boolean 23 company?: any 24 status: any 25 date_added: any 26 entity: string 27 created: string 28 modified: string 29 } 30 | undefined
See Type Inference in the documentation for more details.
UpdateExpression
strings is a major pain, especially if the input data changes the underlying clauses or requires dynamic (or nested) attributes. This library handles everything from simple SET
clauses, to complex list
and set
manipulations, to defaulting values with smartly applied if_not_exists()
to avoid overwriting data.pk
andsk
) and map them to different aliases depending on the item type. Your data is automatically mapped correctly when reading and writing data.sortKey
to [country]#[region]#[state]#[county]#[city]#[neighborhood]
model hierarchies? DynamoDB Toolbox lets you map data to these composite keys which will both autogenerate the value and parse them into fields for you.list
, map
, and set
types against your data. Oh yeah, and set
s are automatically handled for you. 😉partitionKey
, and then easily configure your sortKey conditions, filters, and attribute projections to query your primary or secondary indexes. This library can even handle pagination with a simple .next()
method..next()
.array
and object
notation. No more appending strings!Contributions, ideas and bug reports are welcome and greatly appreciated. Please add issues for suggestions and bug reports or create a pull request. You can also contact me on Twitter: @jeremy_daly.
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
30 commit(s) and 29 issue activity found in the last 90 days -- score normalized to 10
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
packaging workflow detected
Details
Reason
SAST tool is run on all commits
Details
Reason
dependency not pinned by hash detected -- score normalized to 3
Details
Reason
7 existing vulnerabilities detected
Details
Reason
Found 1/10 approved changesets -- score normalized to 1
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Score
Last Scanned on 2024-12-23
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More