Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
dynamodb-toolkit
Advanced tools
No-dependencies opinionated micro-library for AWS DynamoDB to build small efficient RESTful APIs and high-performance command-line utilities with a simple intuitive API.
Extensively documented: see the wiki.
const Adapter = require('dynamodb-toolkit');
const AWS = require('aws-sdk');
AWS.config.update({region: 'us-east-2'});
const adapter = new Adapter({
client: new AWS.DynamoDB(),
table: 'test',
keyFields: ['name']
});
// ...
const planet = await adapter.get({name: 'Alderaan'});
await adapter.patch({name: planet.name, diameter: planet.diameter * 2});
// ...
await adapter.clone({name: planet.name}, planet => {
const newPlanet = {...planet, name: planet.name + ' Two'};
return newPlanet;
});
await adapter.delete({name: planet.name});
The full documentation: Adapter. Here is a cheatsheet:
prepare()
.params
for a given item and an index to list related items.params
for different writing operations.params
.params
with forcing a table name.ConditionExpression
from params
.params
to list items.params
.Included utility functions:
params
) including adding projections, filtering.The library provides a helper for Koa to write HTTP REST servers: KoaAdapter. It takes care of query parameters, extracts POST/PUT JSON bodies, sends responses encoded as JSON with proper HTTP status codes, and prepares parameters for mass operations.
Define a Koa adapter:
const koaAdapter = new KoaAdapter(adapter, {
sortableIndices: {name: '-t-name-index'},
augmentItemFromContext(item, ctx) {
if (ctx.params.planet) {
item.name = ctx.params.planet;
}
return item;
},
augmentCloneFromContext(ctx) {
// how to transform an object when cloning/moving (the default)
return item => ({...item, name: item.name + ' COPY'});
},
async getAll(ctx) {
// custom getAll(), which supports sorting
let index, descending;
if (ctx.query.sort) {
let sortName = ctx.query.sort;
descending = ctx.query.sort[0] == '-';
if (descending) {
sortName = sortName.substr(1);
}
index = this.sortableIndices[sortName];
}
const options = this.makeOptions(ctx);
options.descending = !!descending;
ctx.body = await this.adapter.getAll(options, null, index);
},
async load(ctx) {
// custom operation
const data = JSON.parse(zlib.gunzipSync(fs.readFileSync(path.join(__dirname, 'data.json.gz'))));
await this.adapter.putAll(data);
ctx.body = {processed: data.length};
}
});
Most operations were trivial. Some operations take more than a couple of lines for flexibility's sake.
Define the routing table:
const router = new Router();
router
// mass operations
.get('/', async ctx => koaAdapter.getAll(ctx))
.delete('/', async ctx => koaAdapter.deleteAll(ctx))
.put('/-load', async ctx => koaAdapter.load(ctx))
.put('/-clone', async ctx => koaAdapter.cloneAll(ctx))
.put('/-clone-by-names', async ctx => koaAdapter.cloneByNames(ctx))
.put('/-move', async ctx => koaAdapter.moveAll(ctx))
.put('/-move-by-names', async ctx => koaAdapter.moveByNames(ctx))
.get('/-by-names', async ctx => koaAdapter.getByNames(ctx))
.delete('/-by-names', async ctx => koaAdapter.deleteByNames(ctx))
// item operations
.post('/', async ctx => koaAdapter.post(ctx))
.get('/:planet', async ctx => koaAdapter.get(ctx))
.put('/:planet', async ctx => koaAdapter.put(ctx))
.patch('/:planet', async ctx => koaAdapter.patch(ctx))
.delete('/:planet', async ctx => koaAdapter.delete(ctx))
.put('/:planet/-clone', async ctx => koaAdapter.clone(ctx))
.put('/:planet/-move', async ctx => koaAdapter.move(ctx));
module.exports = router;
It cannot be simpler than that!
See wiki for the full documentation.
__separator
to a patch object.readOrderedListByKeys()
and indirection to Adapter's GET-like methods.addProjection()
to avoid duplicates.moveXXX()
operations, some minor implementation improvements.revive()
.AWS.DynamoDB.DocumentClient
, and so on.AWS.DynamoDB.Convert
, added getPath()
and setPath()
utilities.seq()
for sequential asynchronous operations.addKeyFields()
, simplified getAllByParams()
, fixed genericDeleteAllByParams()
.iterateList()
.xxxList()
functions to use getBatch()
and applyBatch()
.getTotal()
API and added a no-limit version of paginateList()
.Adapter.makeCheck()
.Adapter
related to transactions.applyTransaction()
.checkExistence()
helper.KoaAdapter
.xxxByNames
methods to KoaAdapter
.scanAllByParams()
, updated dev deps.scanAllByParams()
.makeListParams()
and scanAllByParams()
.readList()
, added streamable reading.deleteByNames()
and cloneByNames()
, renamed getAllByKeys()
to getByKeys()
.updateParams()
to add writing conditions.KoaAdapter
's mass methods: augmenting instead of copying.clone()
and cloneAll()
as default methods.doClone()
.undefined
for mapping functions.toDynamo()
, toDynamoKey()
, fromDynamo()
.clone()
added to KoaAdapter
. A related bug was fixed.The test JSON file containing planets of the Star Wars universe is extracted from SWAPI and used under BSD license.
FAQs
Helpers for AWS DynamoDB to build efficient web applications
The npm package dynamodb-toolkit receives a total of 12 weekly downloads. As such, dynamodb-toolkit popularity was classified as not popular.
We found that dynamodb-toolkit demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.