Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

dynamodb-admin

Package Overview
Dependencies
Maintainers
2
Versions
48
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dynamodb-admin - npm Package Compare versions

Comparing version 1.10.0 to 1.11.0

144

index.js
const express = require('express')
const _ = require('lodash');
const AWS = require('aws-sdk')

@@ -11,2 +12,3 @@ const promisify = require('es6-promisify')

const yaml = require('js-yaml')
const querystring = require('querystring');

@@ -129,9 +131,99 @@ require('es7-object-polyfill')

var doSearch = function (docClient, tableName, scanParams, limit, startKey, done, progress, readOperation = "scan") {
limit = typeof limit !== 'undefined' ? limit : null;
startKey = typeof startKey !== 'undefined' ? startKey : null;
var self = this;
var params = {TableName: tableName};
if (typeof scanParams !== 'undefined' && scanParams) {
params = _.assign(params, scanParams);
}
if (limit != null)
params.Limit = limit;
if (startKey != null)
params.ExclusiveStartKey = startKey;
var items = [];
var processNextBite = function (err, items, nextKey) {
if (!err && nextKey) {
params.ExclusiveStartKey = nextKey;
getNextBite(params, items, processNextBite);
} else {
if (done) done(err, items);
}
};
var readMethod = {
"scan": docClient.scan,
"query": docClient.query,
}[readOperation].bind(docClient);
var getNextBite = function (params, items, callback) {
var result = readMethod(params, function (err, data) {
var obj = null;
if (err != null) {
obj = null;
callback(err, items, null);
return;
}
if (typeof data.Items == "undefined") {
}
if (data && data.Items && data.Items.length > 0)
items = items.concat(data.Items);
var lastStartKey = null;
if (data)
lastStartKey = data.LastEvaluatedKey;
if (progress) {
var stop = progress(err, data.Items, lastStartKey);
if (!stop) {
callback(err, items, lastStartKey);
} else {
if (done) done(err, items);
}
} else {
callback(err, items, lastStartKey);
}
});
};
getNextBite(params, items, processNextBite);
};
var getPage = function(docClient, keySchema, TableName, scanParams, pageSize, startKey, done)
{
var pageItems = [];
doSearch(docClient, TableName, scanParams, 10, startKey,
function (err, items) {
let nextKey = null;
if (_.size(pageItems) > pageSize) {
pageItems = pageItems.slice(0, pageSize)
nextKey = extractKey(pageItems[pageSize - 1], keySchema);
}
done(pageItems, err, nextKey);
},
function (err, items, lastStartKey) {
for (let i = 0; i < items.length && _.size(pageItems) < pageSize + 1; i++) {
let item = items[i];
pageItems.push(item);
}
if (_.size(pageItems) >= pageSize || !lastStartKey) {
return true;
}
else return false;
}
);
}
app.get('/tables/:TableName', (req, res, next) => {
const TableName = req.params.TableName
req.query = pickBy(req.query)
const filters = omit(req.query, ['_hash', 'range'])
const filters = omit(req.query, ['_hash', 'range', 'startKey', 'pageNum'])
describeTable({TableName}).then((description) => {
let ExclusiveStartKey = {}
let ExclusiveStartKey = req.query.startKey ? JSON.parse(req.query.startKey) : {}
let pageNum = req.query.pageNum ? parseInt(req.query.pageNum) : 1;
const ExpressionAttributeNames = {}

@@ -151,28 +243,40 @@ const ExpressionAttributeValues = {}

ExpressionAttributeValues[`:${key}`] = req.query[key]
const isSchemaKey = description.Table.KeySchema.find((definition) => {
return definition.AttributeName === key
});
FilterExpressions.push(`#${key} = :${key}`)
}
const params = pickBy({
TableName,
FilterExpression: FilterExpressions.length ? FilterExpressions.join(' AND ') : undefined,
ExpressionAttributeNames: FilterExpressions.length ? ExpressionAttributeNames : undefined,
ExpressionAttributeValues: FilterExpressions.length ? ExpressionAttributeValues : undefined,
ExclusiveStartKey: Object.keys(ExclusiveStartKey).length ? ExclusiveStartKey : undefined,
Limit: 25
ExpressionAttributeNames: Object.keys(ExpressionAttributeNames).length ? ExpressionAttributeNames : undefined,
ExpressionAttributeValues: Object.keys(ExpressionAttributeValues).length ? ExpressionAttributeValues : undefined,
})
return Promise.all([
docClient.scan(params).promise()
]).then(([result]) => {
const data = Object.assign({}, description, {
query: req.query,
yaml,
omit,
filters,
Items: result.Items.map((item) => {
return Object.assign({}, item, {
__key: extractKey(item, description.Table.KeySchema)
let startKey = Object.keys(ExclusiveStartKey).length ? ExclusiveStartKey : undefined;
getPage(docClient, description.Table.KeySchema, TableName, params, 25, startKey,
function(pageItems, err, nextKey) {
console.log("page done!", pageItems.length, nextKey);
let nextKeyParam = nextKey ? encodeURIComponent(JSON.stringify(nextKey)) : null;
const data = Object.assign({}, description, {
query: req.query,
yaml,
omit,
filters,
pageNum: pageNum,
nextKey: nextKeyParam,
filterQueryString: querystring.stringify(filters),
Items: pageItems.map((item) => {
return Object.assign({}, item, {
__key: extractKey(item, description.Table.KeySchema)
})
})
})
})
res.render('scan', data)
});
res.render('scan', data);
})

@@ -179,0 +283,0 @@ }).catch(next)

4

package.json
{
"name": "dynamodb-admin",
"version": "1.10.0",
"version": "1.11.0",
"description": "GUI for DynamoDB. Useful for local development.",

@@ -29,3 +29,3 @@ "main": "index.js",

"dependencies": {
"aws-sdk": "^2.5.0",
"aws-sdk": "^2.7.27",
"body-parser": "^1.15.2",

@@ -32,0 +32,0 @@ "ejs": "^2.5.1",

@@ -7,3 +7,3 @@ ## Usage

```
```
dynamodb-admin

@@ -14,2 +14,12 @@ ```

Example:
```
export AWS_ACCESS_KEY_ID=mykey
export AWS_SECRET_ACCESS_KEY=mysecret
export DYNAMO_ENDPOINT=http://localhost:8000
dynamodb-admin
```
![Screencast](https://d3vv6lp55qjaqc.cloudfront.net/items/2S1m213N1o2L231e011o/Screen%20Recording%202016-10-17%20at%2001.11%20PM.gif?X-CloudApp-Visitor-Id=ab2071d5f76f8504ab6d3070d8a2c5c3&v=e6056da9)

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc