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

dynaql

Package Overview
Dependencies
Maintainers
1
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dynaql - npm Package Compare versions

Comparing version 2.2.0 to 2.2.1

.prettierrc

10

package.json
{
"name": "dynaql",
"version": "2.2.0",
"version": "2.2.1",
"description": "Dynamo library to make interacting with dynamo easier",

@@ -8,4 +8,3 @@ "main": "src/index.js",

"test": "./test.sh",
"prettier": "prettier --write \"./**/*.js\"",
"build": "./build.sh"
"prettier": "prettier --write \"./**/*.js\""
},

@@ -27,3 +26,3 @@ "repository": {

"engines": {
"node": ">=6.10"
"node": ">=8.9"
},

@@ -35,5 +34,2 @@ "dependencies": {

"devDependencies": {
"@babel/core": "^7.0.0-beta.42",
"@babel/plugin-proposal-object-rest-spread": "^7.0.0-beta.42",
"@babel/preset-env": "^7.0.0-beta.42",
"jest": "^21.1.0",

@@ -40,0 +36,0 @@ "prettier": "^1.7.4"

@@ -1,33 +0,22 @@

"use strict";
const createClients = require('./lib/create-clients');
const createClients = require('./lib/create-clients'); // document client
// document client
const get = require('./methods/get');
const update = require('./methods/update');
const query = require('./methods/query');
const put = require('./methods/put');
const destroy = require('./methods/delete');
const getAll = require('./methods/get-all');
const writeAll = require('./methods/write-all');
const writeAll = require('./methods/write-all'); // normal client
// normal client
const createTable = require('./methods/create-table');
const deleteTable = require('./methods/delete-table');
const listTables = require('./methods/list-tables');
const describeTable = require('./methods/describe-table');
const waitFor = require('./methods/wait-for');
module.exports = function (config) {
module.exports = function(config) {
let clientPromise = createClients(config);
return {

@@ -42,2 +31,3 @@ get: get.bind(null, clientPromise),

deleteAll: writeAll.bind(null, clientPromise, 'DeleteRequest'),
createTable: createTable.bind(null, clientPromise),

@@ -47,4 +37,4 @@ deleteTable: deleteTable.bind(null, clientPromise),

describeTable: describeTable.bind(null, clientPromise),
waitFor: waitFor.bind(null, clientPromise)
waitFor: waitFor.bind(null, clientPromise),
};
};
};

@@ -1,3 +0,1 @@

"use strict";
const buildQueryExpression = require('../build-query-expression');

@@ -7,25 +5,19 @@

it('builds the hash key', () => {
let params = buildQueryExpression({
id: '1'
}, {
hash: 'id'
});
let params = buildQueryExpression({ id: '1' }, { hash: 'id' });
expect(params).toEqual({
KeyConditionExpression: '#HASH = :HVALUE',
ExpressionAttributeNames: {
'#HASH': 'id'
'#HASH': 'id',
},
ExpressionAttributeValues: {
':HVALUE': '1'
}
':HVALUE': '1',
},
});
});
it('builds the range key if it is there', () => {
let params = buildQueryExpression({
id: '1',
date: '2'
}, {
hash: 'id',
range: 'date'
});
let params = buildQueryExpression(
{ id: '1', date: '2' },
{ hash: 'id', range: 'date' }
);
expect(params).toEqual({

@@ -35,10 +27,10 @@ KeyConditionExpression: '#HASH = :HVALUE AND #RANGE = :RVALUE',

'#HASH': 'id',
'#RANGE': 'date'
'#RANGE': 'date',
},
ExpressionAttributeValues: {
':HVALUE': '1',
':RVALUE': '2'
}
':RVALUE': '2',
},
});
});
});
});

@@ -1,7 +0,2 @@

"use strict";
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } } function _next(value) { step("next", value); } function _throw(err) { step("throw", err); } _next(); }); }; }
const createClients = require('../create-clients');
const testHelpers = require('../../../test/helpers');

@@ -13,42 +8,35 @@

accessKeyId: 'dynaql',
secretAccessKey: 'dynaql'
secretAccessKey: 'dynaql',
};
describe('createClients', () => {
beforeAll(
/*#__PURE__*/
_asyncToGenerator(function* () {
yield testHelpers.createTable('createClientsTable');
}));
afterAll(
/*#__PURE__*/
_asyncToGenerator(function* () {
yield testHelpers.deleteTable('createClientsTable');
}));
it('creates the clients',
/*#__PURE__*/
_asyncToGenerator(function* () {
let {
documentClient,
client
} = yield createClients(config);
beforeAll(async () => {
await testHelpers.createTable('createClientsTable');
});
afterAll(async () => {
await testHelpers.deleteTable('createClientsTable');
});
it('creates the clients', async () => {
let { documentClient, client } = await createClients(config);
expect(documentClient).not.toBeNull();
expect(client).not.toBeNull();
}));
it('gets the indexes of existing tables',
/*#__PURE__*/
_asyncToGenerator(function* () {
let {
indexes
} = yield createClients(config);
});
it('gets the indexes of existing tables', async () => {
let { indexes } = await createClients(config);
expect(indexes).toEqual({
createClientsTable: {
createClientsTable: {
hash: 'id'
hash: 'id',
},
dynaqlTestIndex: {
hash: 'name'
}
}
hash: 'name',
},
},
});
}));
});
});
});

@@ -1,3 +0,1 @@

"use strict";
const createWriteExpression = require('../create-write-expression');

@@ -9,19 +7,22 @@

id: 'asdf',
username: 'fdsa'
username: 'fdsa',
};
let params = createWriteExpression(update);
expect(params.UpdateExpression).toEqual('SET #id = :id, #username = :username');
expect(params.UpdateExpression).toEqual(
'SET #id = :id, #username = :username'
);
expect(params.ExpressionAttributeNames).toEqual({
'#id': 'id',
'#username': 'username'
'#username': 'username',
});
expect(params.ExpressionAttributeValues).toEqual({
':id': 'asdf',
':username': 'fdsa'
':username': 'fdsa',
});
});
it('works for removing values', () => {
let update = {
id: null,
username: null
username: null,
};

@@ -32,9 +33,10 @@ let params = createWriteExpression(update);

'#id': 'id',
'#username': 'username'
'#username': 'username',
});
});
it('can combine both', () => {
let update = {
id: 'asdf',
username: null
username: null,
};

@@ -45,8 +47,8 @@ let params = createWriteExpression(update);

'#id': 'id',
'#username': 'username'
'#username': 'username',
});
expect(params.ExpressionAttributeValues).toEqual({
':id': 'asdf'
':id': 'asdf',
});
});
});
});

@@ -1,3 +0,1 @@

"use strict";
const extractIndexes = require('../extract-indexes');

@@ -9,49 +7,63 @@

TableName: 'extractTable',
KeySchema: [{
KeyType: 'HASH',
AttributeName: 'id'
}, {
KeyType: 'RANGE',
AttributeName: 'date'
}]
KeySchema: [
{
KeyType: 'HASH',
AttributeName: 'id',
},
{
KeyType: 'RANGE',
AttributeName: 'date',
},
],
};
expect(extractIndexes(params)).toEqual({
extractTable: {
hash: 'id',
range: 'date'
}
range: 'date',
},
});
});
it('gets the tables global secondary indexes', () => {
let params = {
TableName: 'extractTable',
KeySchema: [{
KeyType: 'HASH',
AttributeName: 'id'
}, {
KeyType: 'RANGE',
AttributeName: 'date'
}],
GlobalSecondaryIndexes: [{
IndexName: 'extractTableIndex',
KeySchema: [{
KeySchema: [
{
KeyType: 'HASH',
AttributeName: 'id'
}, {
AttributeName: 'id',
},
{
KeyType: 'RANGE',
AttributeName: 'date'
}]
}]
AttributeName: 'date',
},
],
GlobalSecondaryIndexes: [
{
IndexName: 'extractTableIndex',
KeySchema: [
{
KeyType: 'HASH',
AttributeName: 'id',
},
{
KeyType: 'RANGE',
AttributeName: 'date',
},
],
},
],
};
expect(extractIndexes(params)).toEqual({
extractTable: {
hash: 'id',
range: 'date'
range: 'date',
},
extractTableIndex: {
hash: 'id',
range: 'date'
}
range: 'date',
},
});
});
});
});

@@ -1,3 +0,1 @@

"use strict";
const findIndex = require('../find-index');

@@ -9,32 +7,28 @@

hash: 'id',
range: 'date'
range: 'date',
},
second: {
hash: 'username'
hash: 'username',
},
third: {
hash: 'id',
range: 'startDate'
range: 'startDate',
},
fourth: {
hash: 'username',
range: 'startDate'
}
range: 'startDate',
},
};
it('finds the index schema when it matches both hash and range key', () => {
expect(findIndex(indexes, {
id: '1',
date: '2'
})).toEqual('first');
expect(findIndex(indexes, { id: '1', date: '2' })).toEqual('first');
});
it('finds the index when its just a hash', () => {
expect(findIndex(indexes, {
username: '1'
})).toEqual('second');
expect(findIndex(indexes, { username: '1' })).toEqual('second');
});
it('finds the first hash/range index using the hash key', () => {
expect(findIndex(indexes, {
id: '1'
})).toEqual('first');
expect(findIndex(indexes, { id: '1' })).toEqual('first');
});
});
});

@@ -1,3 +0,1 @@

"use strict";
module.exports = function buildExpression(key, index) {

@@ -7,7 +5,7 @@ let params = {

ExpressionAttributeNames: {
'#HASH': index.hash
'#HASH': index.hash,
},
ExpressionAttributeValues: {
':HVALUE': key[index.hash]
}
':HVALUE': key[index.hash],
},
};

@@ -17,6 +15,7 @@

params.KeyConditionExpression += ' AND #RANGE = :RVALUE';
params.ExpressionAttributeNames['#RANGE'] = index.range, params.ExpressionAttributeValues[':RVALUE'] = key[index.range];
(params.ExpressionAttributeNames['#RANGE'] = index.range),
(params.ExpressionAttributeValues[':RVALUE'] = key[index.range]);
}
return params;
};
};

@@ -1,43 +0,28 @@

"use strict";
const AWS = require('aws-sdk');
const listTables = require('../methods/list-tables');
const describeTable = require('../methods/describe-table');
const extractIndexes = require('./extract-indexes');
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } } function _next(value) { step("next", value); } function _throw(err) { step("throw", err); } _next(); }); }; }
module.exports = async function createClient(config) {
let client = new AWS.DynamoDB(config);
let documentClient = new AWS.DynamoDB.DocumentClient({ service: client });
const AWS = require('aws-sdk');
let { result } = await listTables(Promise.resolve({ client }));
const listTables = require('../methods/list-tables');
if (!result) result = []
const describeTable = require('../methods/describe-table');
let tableDefinitions = await Promise.all(
result.map(tableName =>
describeTable(Promise.resolve({ client }), tableName)
)
);
const extractIndexes = require('./extract-indexes');
module.exports =
/*#__PURE__*/
function () {
var _createClient = _asyncToGenerator(function* (config) {
let client = new AWS.DynamoDB(config);
let documentClient = new AWS.DynamoDB.DocumentClient({
service: client
});
let {
result
} = yield listTables(Promise.resolve({
client
}));
let tableDefinitions = yield Promise.all(result.map(tableName => describeTable(Promise.resolve({
client
}), tableName)));
let indexes = tableDefinitions.map(tableDefinition => tableDefinition.result).reduce((collection, definition) => {
let indexes = tableDefinitions
.map(tableDefinition => tableDefinition.result)
.reduce((collection, definition) => {
collection[definition.TableName] = extractIndexes(definition);
return collection;
}, {});
return {
documentClient,
client,
indexes
};
});
return function createClient(_x) {
return _createClient.apply(this, arguments);
};
}();
return { documentClient, client, indexes };
};

@@ -1,3 +0,1 @@

"use strict";
module.exports = function createWriteExpression(update) {

@@ -7,34 +5,30 @@ let params = {

ExpressionAttributeNames: {},
ExpressionAttributeValues: {}
ExpressionAttributeValues: {},
};
let expressions = Object.keys(update).reduce((expressions, key) => {
let expressionName = `#${key}`;
let expressions = Object.keys(update).reduce(
(expressions, key) => {
let expressionName = `#${key}`;
if (update[key] != null) {
let expressionValue = `:${key}`;
expressions.set.push(`${expressionName} = ${expressionValue}`);
params.ExpressionAttributeNames[expressionName] = key;
params.ExpressionAttributeValues[expressionValue] = update[key];
} else {
expressions.remove.push(expressionName);
params.ExpressionAttributeNames[expressionName] = key;
}
if (update[key] != null) {
let expressionValue = `:${key}`;
expressions.set.push(`${expressionName} = ${expressionValue}`);
params.ExpressionAttributeNames[expressionName] = key;
params.ExpressionAttributeValues[expressionValue] = update[key];
} else {
expressions.remove.push(expressionName);
params.ExpressionAttributeNames[expressionName] = key;
}
return expressions;
}, {
set: [],
remove: []
});
return expressions;
},
{ set: [], remove: [] }
);
let expression = [];
if (expressions.set.length) {
expression.push(`SET ${expressions.set.join(', ')}`);
}
if (expressions.remove.length) {
expression.push(`REMOVE ${expressions.remove.join(', ')}`);
}
params.UpdateExpression = expression.join(' ');
return params;
};
};

@@ -1,22 +0,28 @@

"use strict";
module.exports = function (tableDefinition) {
module.exports = function(tableDefinition) {
let indexes = {
[tableDefinition.TableName]: {
hash: (tableDefinition.KeySchema.find(key => key.KeyType === 'HASH') || {}).AttributeName,
range: (tableDefinition.KeySchema.find(key => key.KeyType === 'RANGE') || {}).AttributeName
}
hash: (tableDefinition.KeySchema.find(key => key.KeyType === 'HASH') || {}
).AttributeName,
range: (tableDefinition.KeySchema.find(key => key.KeyType === 'RANGE') ||
{}
).AttributeName,
},
};
if (tableDefinition.GlobalSecondaryIndexes) {
indexes = tableDefinition.GlobalSecondaryIndexes.reduce((tableIndexes, index) => {
tableIndexes[index.IndexName] = {
hash: (index.KeySchema.find(key => key.KeyType === 'HASH') || {}).AttributeName,
range: (index.KeySchema.find(key => key.KeyType === 'RANGE') || {}).AttributeName
};
return tableIndexes;
}, indexes);
indexes = tableDefinition.GlobalSecondaryIndexes.reduce(
(tableIndexes, index) => {
tableIndexes[index.IndexName] = {
hash: (index.KeySchema.find(key => key.KeyType === 'HASH') || {})
.AttributeName,
range: (index.KeySchema.find(key => key.KeyType === 'RANGE') || {})
.AttributeName,
};
return tableIndexes;
},
indexes
);
}
return indexes;
};
};

@@ -1,25 +0,22 @@

"use strict";
module.exports = function (indexes, key) {
module.exports = function(indexes, key) {
let keys = Object.keys(key);
let indexNames = Object.keys(indexes);
let bestIndex = indexNames.reduce((best, indexName) => {
let keysUsed = 0;
let index = indexes[indexName];
keys.includes(index.hash) && keysUsed++;
keys.includes(index.range) && keysUsed++;
if (keysUsed / keys.length > best.keysUsed) {
return {
indexName,
keysUsed
};
} else {
return best;
}
}, {
indexName: '',
keysUsed: 0
});
let bestIndex = indexNames.reduce(
(best, indexName) => {
let keysUsed = 0;
let index = indexes[indexName];
keys.includes(index.hash) && keysUsed++;
keys.includes(index.range) && keysUsed++;
if (keysUsed / keys.length > best.keysUsed) {
return { indexName, keysUsed };
} else {
return best;
}
},
{ indexName: '', keysUsed: 0 }
);
return bestIndex.indexName;
};
};

@@ -1,96 +0,101 @@

"use strict";
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } } function _next(value) { step("next", value); } function _throw(err) { step("throw", err); } _next(); }); }; }
const describeTable = require('../describe-table');
const createTable = require('../create-table');
const waitFor = require('../wait-for');
const createClients = require('../../lib/create-clients');
const testHelpers = require('../../../test/helpers');
describe('createTable', () => {
it('creates the table',
/*#__PURE__*/
_asyncToGenerator(function* () {
it('creates the table', async () => {
let tableName = 'createTableTestTable';
yield createTable(testHelpers.clientPromise, {
await createTable(testHelpers.clientPromise, {
TableName: tableName,
KeySchema: [{
AttributeName: 'id',
KeyType: 'HASH'
}],
AttributeDefinitions: [{
AttributeName: 'id',
AttributeType: 'S'
}],
KeySchema: [
{
AttributeName: 'id',
KeyType: 'HASH',
},
],
AttributeDefinitions: [
{
AttributeName: 'id',
AttributeType: 'S',
},
],
ProvisionedThroughput: {
ReadCapacityUnits: 1,
WriteCapacityUnits: 1
}
WriteCapacityUnits: 1,
},
});
yield waitFor(testHelpers.clientPromise, tableName, 'tableExists');
let {
result
} = yield describeTable(testHelpers.clientPromise, tableName);
yield testHelpers.deleteTable(tableName);
await waitFor(testHelpers.clientPromise, tableName, 'tableExists');
let { result } = await describeTable(testHelpers.clientPromise, tableName);
await testHelpers.deleteTable(tableName);
expect(result).toMatchObject({
TableName: tableName,
KeySchema: [{
AttributeName: 'id',
KeyType: 'HASH'
}],
AttributeDefinitions: [{
AttributeName: 'id',
AttributeType: 'S'
}],
KeySchema: [
{
AttributeName: 'id',
KeyType: 'HASH',
},
],
AttributeDefinitions: [
{
AttributeName: 'id',
AttributeType: 'S',
},
],
ProvisionedThroughput: {
ReadCapacityUnits: 1,
WriteCapacityUnits: 1
}
WriteCapacityUnits: 1,
},
});
}));
it('adds the table schema and indexes to the indexes',
/*#__PURE__*/
_asyncToGenerator(function* () {
});
it('adds the table schema and indexes to the indexes', async () => {
let tableName = 'createTableIndexesTestTable';
yield createTable(testHelpers.clientPromise, {
await createTable(testHelpers.clientPromise, {
TableName: tableName,
KeySchema: [{
AttributeName: 'id',
KeyType: 'HASH'
}],
AttributeDefinitions: [{
AttributeName: 'id',
AttributeType: 'S'
}, {
AttributeName: 'username',
AttributeType: 'S'
}],
KeySchema: [
{
AttributeName: 'id',
KeyType: 'HASH',
},
],
AttributeDefinitions: [
{
AttributeName: 'id',
AttributeType: 'S',
},
{
AttributeName: 'username',
AttributeType: 'S',
},
],
ProvisionedThroughput: {
ReadCapacityUnits: 1,
WriteCapacityUnits: 1
WriteCapacityUnits: 1,
},
GlobalSecondaryIndexes: [{
IndexName: 'createTableIndexesTestTableIndex',
KeySchema: [{
KeyType: 'HASH',
AttributeName: 'username'
}],
ProvisionedThroughput: {
ReadCapacityUnits: 1,
WriteCapacityUnits: 1
GlobalSecondaryIndexes: [
{
IndexName: 'createTableIndexesTestTableIndex',
KeySchema: [
{
KeyType: 'HASH',
AttributeName: 'username',
},
],
ProvisionedThroughput: {
ReadCapacityUnits: 1,
WriteCapacityUnits: 1,
},
Projection: {
ProjectionType: 'ALL',
},
},
Projection: {
ProjectionType: 'ALL'
}
}]
],
});
yield waitFor(testHelpers.clientPromise, tableName, 'tableExists');
let {
indexes
} = yield testHelpers.clientPromise;
await waitFor(testHelpers.clientPromise, tableName, 'tableExists');
let { indexes } = await testHelpers.clientPromise;
expect(indexes).toMatchObject({

@@ -100,12 +105,13 @@ [tableName]: {

hash: 'id',
range: undefined
range: undefined,
},
createTableIndexesTestTableIndex: {
hash: 'username',
range: undefined
}
}
range: undefined,
},
},
});
yield testHelpers.deleteTable(tableName);
}));
});
await testHelpers.deleteTable(tableName);
});
});

@@ -1,45 +0,31 @@

"use strict";
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } } function _next(value) { step("next", value); } function _throw(err) { step("throw", err); } _next(); }); }; }
const testHelpers = require('../../../test/helpers');
const listTables = require('../list-tables');
const deleteTable = require('../delete-table');
const waitFor = require('../wait-for');
const createClients = require('../../lib/create-clients');
describe('deleteTable', () => {
it('deletes a table',
/*#__PURE__*/
_asyncToGenerator(function* () {
it('deletes a table', async () => {
let tableName = 'deleteTableTestTable';
yield testHelpers.createTable(tableName);
yield deleteTable(testHelpers.clientPromise, {
TableName: tableName
});
yield waitFor(testHelpers.clientPromise, tableName, 'tableNotExists');
let {
result
} = yield listTables(testHelpers.clientPromise);
await testHelpers.createTable(tableName);
await deleteTable(testHelpers.clientPromise, { TableName: tableName });
await waitFor(testHelpers.clientPromise, tableName, 'tableNotExists');
let { result } = await listTables(testHelpers.clientPromise);
expect(result.includes(tableName)).toBeFalsy();
}));
it('deletes table indexes',
/*#__PURE__*/
_asyncToGenerator(function* () {
});
it('deletes table indexes', async () => {
let tableName = 'deleteTableIndexesTestTable';
yield testHelpers.createTable(tableName);
let {
indexes
} = yield testHelpers.clientPromise;
await testHelpers.createTable(tableName);
let { indexes } = await testHelpers.clientPromise;
expect(indexes[tableName]).toBeDefined();
yield deleteTable(testHelpers.clientPromise, {
TableName: tableName
});
yield waitFor(testHelpers.clientPromise, tableName, 'tableNotExists');
await deleteTable(testHelpers.clientPromise, { TableName: tableName });
await waitFor(testHelpers.clientPromise, tableName, 'tableNotExists');
expect(indexes[tableName]).toBeUndefined();
}));
});
});
});

@@ -1,11 +0,4 @@

"use strict";
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } } function _next(value) { step("next", value); } function _throw(err) { step("throw", err); } _next(); }); }; }
const testHelpers = require('../../../test/helpers');
const deleteItem = require('../delete');
const put = require('../put');
const get = require('../get');

@@ -15,31 +8,20 @@

let tableName = 'deleteTestTable';
beforeAll(
/*#__PURE__*/
_asyncToGenerator(function* () {
yield testHelpers.createTable(tableName);
}));
afterAll(
/*#__PURE__*/
_asyncToGenerator(function* () {
yield testHelpers.deleteTable(tableName);
}));
it('deletes an item',
/*#__PURE__*/
_asyncToGenerator(function* () {
yield put(testHelpers.clientPromise, tableName, {
id: '1',
name: 'asdf'
});
let results = yield get(testHelpers.clientPromise, tableName, {
id: '1'
});
beforeAll(async () => {
await testHelpers.createTable(tableName);
});
afterAll(async () => {
await testHelpers.deleteTable(tableName);
});
it('deletes an item', async () => {
await put(testHelpers.clientPromise, tableName, { id: '1', name: 'asdf' });
let results = await get(testHelpers.clientPromise, tableName, { id: '1' });
expect(results.result).toBeDefined();
yield deleteItem(testHelpers.clientPromise, tableName, {
id: '1'
});
results = yield get(testHelpers.clientPromise, tableName, {
id: '1'
});
await deleteItem(testHelpers.clientPromise, tableName, { id: '1' });
results = await get(testHelpers.clientPromise, tableName, { id: '1' });
expect(results.result).not.toBeDefined();
}));
});
});
});

@@ -1,7 +0,2 @@

"use strict";
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } } function _next(value) { step("next", value); } function _throw(err) { step("throw", err); } _next(); }); }; }
const testHelpers = require('../../../test/helpers');
const describeTable = require('../describe-table');

@@ -11,20 +6,13 @@

let tableName = 'describeTableTestTable';
beforeAll(
/*#__PURE__*/
_asyncToGenerator(function* () {
yield testHelpers.createTable(tableName);
}));
afterAll(
/*#__PURE__*/
_asyncToGenerator(function* () {
yield testHelpers.deleteTable(tableName);
}));
it('gets the table definition',
/*#__PURE__*/
_asyncToGenerator(function* () {
let {
result
} = yield describeTable(testHelpers.clientPromise, tableName);
beforeAll(async () => {
await testHelpers.createTable(tableName);
});
afterAll(async () => {
await testHelpers.deleteTable(tableName);
});
it('gets the table definition', async () => {
let { result } = await describeTable(testHelpers.clientPromise, tableName);
expect(result.TableName).toEqual(tableName);
}));
});
});
});

@@ -1,11 +0,4 @@

"use strict";
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } } function _next(value) { step("next", value); } function _throw(err) { step("throw", err); } _next(); }); }; }
const testHelpers = require('../../../test/helpers');
const getAll = require('../get-all');
const writeAll = require('../write-all');
const uuid = require('uuid/v4');

@@ -15,46 +8,42 @@

let tableName = 'getAllTestTable';
let items = [...Array(150)].map(() => ({
id: uuid()
}));
beforeAll(
/*#__PURE__*/
_asyncToGenerator(function* () {
yield testHelpers.createTable(tableName);
let items = [...Array(150)].map(() => ({ id: uuid() }));
beforeAll(async () => {
await testHelpers.createTable(tableName);
let itemsToWrite = items.slice();
while (itemsToWrite.length) {
let {
meta: {
next
}
} = yield writeAll(testHelpers.clientPromise, 'PutRequest', tableName, itemsToWrite);
let { meta: { next } } = await writeAll(
testHelpers.clientPromise,
'PutRequest',
tableName,
itemsToWrite
);
itemsToWrite = next;
}
}));
afterAll(
/*#__PURE__*/
_asyncToGenerator(function* () {
yield testHelpers.deleteTable(tableName);
}));
it('can get all items less than max batch size',
/*#__PURE__*/
_asyncToGenerator(function* () {
});
afterAll(async () => {
await testHelpers.deleteTable(tableName);
});
it('can get all items less than max batch size', async () => {
let subItems = items.slice(0, 50);
let {
result,
meta
} = yield getAll(testHelpers.clientPromise, tableName, subItems);
let { result, meta } = await getAll(
testHelpers.clientPromise,
tableName,
subItems
);
expect(result.length).toEqual(50);
expect(meta.next.length).toEqual(0);
}));
it('can get items up to the max batch size',
/*#__PURE__*/
_asyncToGenerator(function* () {
let {
result,
meta
} = yield getAll(testHelpers.clientPromise, tableName, items);
});
it('can get items up to the max batch size', async () => {
let { result, meta } = await getAll(
testHelpers.clientPromise,
tableName,
items
);
expect(result.length).toEqual(100);
expect(meta.next.length).toEqual(50);
}));
});
});
});

@@ -1,9 +0,3 @@

"use strict";
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } } function _next(value) { step("next", value); } function _throw(err) { step("throw", err); } _next(); }); }; }
const testHelpers = require('../../../test/helpers');
const get = require('../get');
const put = require('../put');

@@ -13,27 +7,18 @@

let tableName = 'getTestTable';
beforeAll(
/*#__PURE__*/
_asyncToGenerator(function* () {
yield testHelpers.createTable(tableName);
yield put(testHelpers.clientPromise, tableName, {
id: '1'
beforeAll(async () => {
await testHelpers.createTable(tableName);
await put(testHelpers.clientPromise, tableName, { id: '1' });
});
afterAll(async () => {
await testHelpers.deleteTable(tableName);
});
it('can get a single item', async () => {
let { result } = await get(testHelpers.clientPromise, tableName, {
id: '1',
});
}));
afterAll(
/*#__PURE__*/
_asyncToGenerator(function* () {
yield testHelpers.deleteTable(tableName);
}));
it('can get a single item',
/*#__PURE__*/
_asyncToGenerator(function* () {
let {
result
} = yield get(testHelpers.clientPromise, tableName, {
id: '1'
});
expect(result).toEqual({
id: '1'
id: '1',
});
}));
});
});
});

@@ -1,7 +0,2 @@

"use strict";
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } } function _next(value) { step("next", value); } function _throw(err) { step("throw", err); } _next(); }); }; }
const testHelpers = require('../../../test/helpers');
const listTables = require('../list-tables');

@@ -11,20 +6,12 @@

let tableName = 'listTablesTestTable';
beforeAll(
/*#__PURE__*/
_asyncToGenerator(function* () {
yield testHelpers.createTable(tableName);
}));
afterAll(
/*#__PURE__*/
_asyncToGenerator(function* () {
yield testHelpers.deleteTable(tableName);
}));
it('lists tables',
/*#__PURE__*/
_asyncToGenerator(function* () {
let {
result
} = yield listTables(testHelpers.clientPromise);
beforeAll(async () => {
await testHelpers.createTable(tableName);
});
afterAll(async () => {
await testHelpers.deleteTable(tableName);
});
it('lists tables', async () => {
let { result } = await listTables(testHelpers.clientPromise);
expect(result).toEqual([tableName]);
}));
});
});
});

@@ -1,9 +0,3 @@

"use strict";
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } } function _next(value) { step("next", value); } function _throw(err) { step("throw", err); } _next(); }); }; }
const testHelpers = require('../../../test/helpers');
const put = require('../put');
const get = require('../get');

@@ -13,48 +7,35 @@

let tableName = 'putTestTable';
beforeAll(
/*#__PURE__*/
_asyncToGenerator(function* () {
yield testHelpers.createTable(tableName);
}));
afterAll(
/*#__PURE__*/
_asyncToGenerator(function* () {
yield testHelpers.deleteTable(tableName);
}));
it('can put an item',
/*#__PURE__*/
_asyncToGenerator(function* () {
yield put(testHelpers.clientPromise, tableName, {
beforeAll(async () => {
await testHelpers.createTable(tableName);
});
afterAll(async () => {
await testHelpers.deleteTable(tableName);
});
it('can put an item', async () => {
await put(testHelpers.clientPromise, tableName, { id: '1', name: 'yo' });
let { result } = await get(testHelpers.clientPromise, tableName, {
id: '1',
name: 'yo'
});
let {
result
} = yield get(testHelpers.clientPromise, tableName, {
id: '1'
});
expect(result).toEqual({
id: '1',
name: 'yo'
name: 'yo',
});
}));
it('can create an id if one is not passed in',
/*#__PURE__*/
_asyncToGenerator(function* () {
let {
result: item
} = yield put(testHelpers.clientPromise, tableName, {
name: 'ya'
});
it('can create an id if one is not passed in', async () => {
let { result: item } = await put(testHelpers.clientPromise, tableName, {
name: 'ya',
});
expect(item.id).toBeDefined();
let {
result
} = yield get(testHelpers.clientPromise, tableName, {
id: item.id
let { result } = await get(testHelpers.clientPromise, tableName, {
id: item.id,
});
expect(result).toEqual({
id: item.id,
name: 'ya'
name: 'ya',
});
}));
});
});
});

@@ -1,11 +0,4 @@

"use strict";
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } } function _next(value) { step("next", value); } function _throw(err) { step("throw", err); } _next(); }); }; }
const uuid = require('uuid/v4');
const testHelpers = require('../../../test/helpers');
const query = require('../query');
const writeAll = require('../write-all');

@@ -17,40 +10,33 @@

id: uuid(),
name: 'queryName'
name: 'queryName',
}));
beforeAll(
/*#__PURE__*/
_asyncToGenerator(function* () {
yield testHelpers.createTable(tableName);
yield writeAll(testHelpers.clientPromise, 'PutRequest', tableName, items);
}));
afterAll(
/*#__PURE__*/
_asyncToGenerator(function* () {
yield testHelpers.deleteTable(tableName);
}));
it('can query an index',
/*#__PURE__*/
_asyncToGenerator(function* () {
let {
result
} = yield query(testHelpers.clientPromise, tableName, {
name: 'queryName'
beforeAll(async () => {
await testHelpers.createTable(tableName);
await writeAll(testHelpers.clientPromise, 'PutRequest', tableName, items);
});
afterAll(async () => {
await testHelpers.deleteTable(tableName);
});
it('can query an index', async () => {
let { result } = await query(testHelpers.clientPromise, tableName, {
name: 'queryName',
});
expect(result.length).toEqual(5);
}));
it('accepts a limit',
/*#__PURE__*/
_asyncToGenerator(function* () {
let {
result
} = yield query(testHelpers.clientPromise, tableName, {
name: 'queryName'
}, {
limit: 1
});
});
it('accepts a limit', async () => {
let { result } = await query(
testHelpers.clientPromise,
tableName,
{ name: 'queryName' },
{ limit: 1 }
);
expect(result.length).toEqual(1);
}));
it('can sort forward',
/*#__PURE__*/
_asyncToGenerator(function* () {}));
});
});
it('can sort forward', async () => {
})
});

@@ -1,11 +0,4 @@

"use strict";
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } } function _next(value) { step("next", value); } function _throw(err) { step("throw", err); } _next(); }); }; }
const testHelpers = require('../../../test/helpers');
const update = require('../update');
const put = require('../put');
const get = require('../get');

@@ -15,37 +8,26 @@

let tableName = 'updateTestTable';
beforeAll(
/*#__PURE__*/
_asyncToGenerator(function* () {
yield testHelpers.createTable(tableName);
yield put(testHelpers.clientPromise, tableName, {
beforeAll(async () => {
await testHelpers.createTable(tableName);
await put(testHelpers.clientPromise, tableName, { id: '1', name: 'Yo' });
});
afterAll(async () => {
await testHelpers.deleteTable(tableName);
});
it('can update an item', async () => {
let { result } = await update(testHelpers.clientPromise, tableName, {
id: '1',
name: 'Yo'
name: 'Ya',
});
}));
afterAll(
/*#__PURE__*/
_asyncToGenerator(function* () {
yield testHelpers.deleteTable(tableName);
}));
it('can update an item',
/*#__PURE__*/
_asyncToGenerator(function* () {
let {
result
} = yield update(testHelpers.clientPromise, tableName, {
id: '1',
name: 'Ya'
});
expect(result).toEqual({
id: '1',
name: 'Ya'
name: 'Ya',
});
let response = yield get(testHelpers.clientPromise, tableName, {
id: '1'
});
let response = await get(testHelpers.clientPromise, tableName, { id: '1' });
expect(response.result).toEqual({
id: '1',
name: 'Ya'
name: 'Ya',
});
}));
});
});
});

@@ -1,11 +0,4 @@

"use strict";
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } } function _next(value) { step("next", value); } function _throw(err) { step("throw", err); } _next(); }); }; }
const testHelpers = require('../../../test/helpers');
const waitFor = require('../wait-for');
const createTable = require('../create-table');
const deleteTable = require('../delete-table');

@@ -15,26 +8,27 @@

let tableName = 'waitForTestTable';
it('can wait for table states',
/*#__PURE__*/
_asyncToGenerator(function* () {
yield createTable(testHelpers.clientPromise, {
it('can wait for table states', async () => {
await createTable(testHelpers.clientPromise, {
TableName: tableName,
ProvisionedThroughput: {
ReadCapacityUnits: 1,
WriteCapacityUnits: 1
WriteCapacityUnits: 1,
},
KeySchema: [{
AttributeName: 'id',
KeyType: 'HASH'
}],
AttributeDefinitions: [{
AttributeName: 'id',
AttributeType: 'S'
}]
KeySchema: [
{
AttributeName: 'id',
KeyType: 'HASH',
},
],
AttributeDefinitions: [
{
AttributeName: 'id',
AttributeType: 'S',
},
],
});
yield waitFor(testHelpers.clientPromise, tableName, 'tableExists');
yield deleteTable(testHelpers.clientPromise, {
TableName: tableName
});
yield waitFor(testHelpers.clientPromise, tableName, 'tableNotExists');
}));
});
await waitFor(testHelpers.clientPromise, tableName, 'tableExists');
await deleteTable(testHelpers.clientPromise, { TableName: tableName });
await waitFor(testHelpers.clientPromise, tableName, 'tableNotExists');
});
});

@@ -1,9 +0,3 @@

"use strict";
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } } function _next(value) { step("next", value); } function _throw(err) { step("throw", err); } _next(); }); }; }
const testHelpers = require('../../../test/helpers');
const writeAll = require('../write-all');
const getAll = require('../get-all');

@@ -13,78 +7,74 @@

let tableName = 'writeAllTestTable';
beforeAll(
/*#__PURE__*/
_asyncToGenerator(function* () {
yield testHelpers.createTable(tableName);
}));
afterAll(
/*#__PURE__*/
_asyncToGenerator(function* () {
yield testHelpers.deleteTable(tableName);
}));
it('can create new items',
/*#__PURE__*/
_asyncToGenerator(function* () {
let items = [{
id: '1',
name: 'yo'
}, {
id: '2',
name: 'ya'
}];
yield writeAll(testHelpers.clientPromise, 'PutRequest', tableName, items);
let {
result
} = yield getAll(testHelpers.clientPromise, tableName, [{
id: '1'
}, {
id: '2'
}]);
beforeAll(async () => {
await testHelpers.createTable(tableName);
});
afterAll(async () => {
await testHelpers.deleteTable(tableName);
});
it('can create new items', async () => {
let items = [
{
id: '1',
name: 'yo',
},
{
id: '2',
name: 'ya',
},
];
await writeAll(testHelpers.clientPromise, 'PutRequest', tableName, items);
let { result } = await getAll(testHelpers.clientPromise, tableName, [
{ id: '1' },
{ id: '2' },
]);
expect(result).toEqual(items);
}));
it('can update existing items',
/*#__PURE__*/
_asyncToGenerator(function* () {
let items = [{
id: '1',
name: 'ya'
}, {
id: '2',
name: 'yo'
}];
yield writeAll(testHelpers.clientPromise, 'PutRequest', tableName, items);
let {
result
} = yield getAll(testHelpers.clientPromise, tableName, [{
id: '1'
}, {
id: '2'
}]);
});
it('can update existing items', async () => {
let items = [
{
id: '1',
name: 'ya',
},
{
id: '2',
name: 'yo',
},
];
await writeAll(testHelpers.clientPromise, 'PutRequest', tableName, items);
let { result } = await getAll(testHelpers.clientPromise, tableName, [
{ id: '1' },
{ id: '2' },
]);
expect(result).toEqual(items);
}));
it('can delete items',
/*#__PURE__*/
_asyncToGenerator(function* () {
let items = [{
id: '1'
}, {
id: '2'
}];
yield writeAll(testHelpers.clientPromise, 'DeleteRequest', tableName, items);
let {
result
} = yield getAll(testHelpers.clientPromise, tableName, items);
});
it('can delete items', async () => {
let items = [{ id: '1' }, { id: '2' }];
await writeAll(
testHelpers.clientPromise,
'DeleteRequest',
tableName,
items
);
let { result } = await getAll(testHelpers.clientPromise, tableName, items);
expect(result.length).toEqual(0);
}));
it('returns next',
/*#__PURE__*/
_asyncToGenerator(function* () {
});
it('returns next', async () => {
let items = [...Array(26)].map((_, i) => ({
id: String(i),
name: String(i)
name: String(i),
}));
let {
meta
} = yield writeAll(testHelpers.clientPromise, 'PutRequest', tableName, items);
let { meta } = await writeAll(
testHelpers.clientPromise,
'PutRequest',
tableName,
items
);
expect(meta.next.length).toEqual(1);
}));
});
});
});

@@ -1,26 +0,10 @@

"use strict";
const extractIndexes = require('../lib/extract-indexes');
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } } function _next(value) { step("next", value); } function _throw(err) { step("throw", err); } _next(); }); }; }
module.exports = async function(clientPromise, params) {
let { client, indexes } = await clientPromise;
let result = await client.createTable(params).promise();
const extractIndexes = require('../lib/extract-indexes');
indexes[params.TableName] = extractIndexes(params);
module.exports =
/*#__PURE__*/
function () {
var _ref = _asyncToGenerator(function* (clientPromise, params) {
let {
client,
indexes
} = yield clientPromise;
let result = yield client.createTable(params).promise();
indexes[params.TableName] = extractIndexes(params);
return {
result,
meta: {}
};
});
return function (_x, _x2) {
return _ref.apply(this, arguments);
};
}();
return { result, meta: {} };
};

@@ -1,24 +0,8 @@

"use strict";
module.exports = async function(clientPromise, params) {
let { client, indexes } = await clientPromise;
let result = await client.deleteTable(params).promise();
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } } function _next(value) { step("next", value); } function _throw(err) { step("throw", err); } _next(); }); }; }
delete indexes[params.TableName];
module.exports =
/*#__PURE__*/
function () {
var _ref = _asyncToGenerator(function* (clientPromise, params) {
let {
client,
indexes
} = yield clientPromise;
let result = yield client.deleteTable(params).promise();
delete indexes[params.TableName];
return {
result,
meta: {}
};
});
return function (_x, _x2) {
return _ref.apply(this, arguments);
};
}();
return { result, meta: {} };
};

@@ -1,26 +0,6 @@

"use strict";
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } } function _next(value) { step("next", value); } function _throw(err) { step("throw", err); } _next(); }); }; }
module.exports =
/*#__PURE__*/
function () {
var _ref = _asyncToGenerator(function* (clientPromise, TableName, Key) {
let {
documentClient
} = yield clientPromise;
let params = {
TableName,
Key
};
let data = yield documentClient.delete(params).promise();
return {
result: null,
meta: data
};
});
return function (_x, _x2, _x3) {
return _ref.apply(this, arguments);
};
}();
module.exports = async function(clientPromise, TableName, Key) {
let { documentClient } = await clientPromise;
let params = { TableName, Key };
let data = await documentClient.delete(params).promise();
return { result: null, meta: data };
};

@@ -1,26 +0,5 @@

"use strict";
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } } function _next(value) { step("next", value); } function _throw(err) { step("throw", err); } _next(); }); }; }
module.exports =
/*#__PURE__*/
function () {
var _ref = _asyncToGenerator(function* (clientPromise, TableName) {
let {
client
} = yield clientPromise;
let {
Table: result
} = yield client.describeTable({
TableName
}).promise();
return {
result,
meta: {}
};
});
return function (_x, _x2) {
return _ref.apply(this, arguments);
};
}();
module.exports = async function(clientPromise, TableName) {
let { client } = await clientPromise;
let { Table: result } = await client.describeTable({ TableName }).promise();
return { result, meta: {} };
};

@@ -1,54 +0,35 @@

"use strict";
const MAX_BATCH_GET = 100;
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; }
module.exports = async function(clientPromise, TableName, Keys) {
let { documentClient } = await clientPromise;
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
let maxKeys = Keys.slice(0, MAX_BATCH_GET);
let remainingKeys = Keys.slice(MAX_BATCH_GET);
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
let params = {
RequestItems: {
[TableName]: {
Keys: maxKeys,
},
},
};
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } } function _next(value) { step("next", value); } function _throw(err) { step("throw", err); } _next(); }); }; }
let response = await documentClient.batchGet(params).promise();
const MAX_BATCH_GET = 100;
let {
Responses: { [TableName]: result },
UnprocessedKeys: { [TableName]: unprocessedKeys },
...meta
} = response;
module.exports =
/*#__PURE__*/
function () {
var _ref = _asyncToGenerator(function* (clientPromise, TableName, Keys) {
let {
documentClient
} = yield clientPromise;
let maxKeys = Keys.slice(0, MAX_BATCH_GET);
let remainingKeys = Keys.slice(MAX_BATCH_GET);
let params = {
RequestItems: {
[TableName]: {
Keys: maxKeys
}
}
};
let response = yield documentClient.batchGet(params).promise();
next = unprocessedKeys || [];
next.push(...remainingKeys);
let {
Responses: {
[TableName]: result
},
UnprocessedKeys: {
[TableName]: unprocessedKeys
}
} = response,
meta = _objectWithoutProperties(response, ["Responses", "UnprocessedKeys"]);
next = unprocessedKeys || [];
next.push(...remainingKeys);
return {
result,
meta: _objectSpread({}, meta, {
next
})
};
});
return function (_x, _x2, _x3) {
return _ref.apply(this, arguments);
return {
result,
meta: {
...meta,
next,
},
};
}();
};

@@ -1,34 +0,9 @@

"use strict";
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } } function _next(value) { step("next", value); } function _throw(err) { step("throw", err); } _next(); }); }; }
module.exports =
/*#__PURE__*/
function () {
var _ref = _asyncToGenerator(function* (clientPromise, TableName, Key) {
let {
documentClient
} = yield clientPromise;
let params = {
TableName,
Key
};
let _ref2 = yield documentClient.get(params).promise(),
{
Item: result
} = _ref2,
meta = _objectWithoutProperties(_ref2, ["Item"]);
return {
result,
meta
};
});
return function (_x, _x2, _x3) {
return _ref.apply(this, arguments);
module.exports = async function(clientPromise, TableName, Key) {
let { documentClient } = await clientPromise;
let params = {
TableName,
Key,
};
}();
let { Item: result, ...meta } = await documentClient.get(params).promise();
return { result, meta };
};

@@ -1,24 +0,5 @@

"use strict";
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } } function _next(value) { step("next", value); } function _throw(err) { step("throw", err); } _next(); }); }; }
module.exports =
/*#__PURE__*/
function () {
var _ref = _asyncToGenerator(function* (clientPromise, options = {}) {
let {
client
} = yield clientPromise;
let {
TableNames: result
} = yield client.listTables(options).promise();
return {
result,
meta: {}
};
});
return function (_x) {
return _ref.apply(this, arguments);
};
}();
module.exports = async function(clientPromise, options = {}) {
let { client } = await clientPromise;
let { TableNames: result } = await client.listTables(options).promise();
return { result, meta: {} };
};

@@ -1,39 +0,16 @@

"use strict";
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; }
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } } function _next(value) { step("next", value); } function _throw(err) { step("throw", err); } _next(); }); }; }
const uuid = require('uuid/v4');
module.exports =
/*#__PURE__*/
function () {
var _ref = _asyncToGenerator(function* (clientPromise, TableName, model, options = {}) {
let {
documentClient,
indexes
} = yield clientPromise;
let Item = _objectSpread({
[indexes[TableName][TableName].hash]: uuid()
}, model);
let params = _objectSpread({
TableName,
Item
}, options);
let meta = yield documentClient.put(params).promise();
return {
result: Item,
meta
};
});
return function (_x, _x2, _x3) {
return _ref.apply(this, arguments);
module.exports = async function(clientPromise, TableName, model, options = {}) {
let { documentClient, indexes } = await clientPromise;
let Item = {
[indexes[TableName][TableName].hash]: uuid(),
...model,
};
}();
let params = {
TableName,
Item,
...options,
};
let meta = await documentClient.put(params).promise();
return { result: Item, meta };
};

@@ -1,13 +0,2 @@

"use strict";
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; }
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } } function _next(value) { step("next", value); } function _throw(err) { step("throw", err); } _next(); }); }; }
const buildQueryExpression = require('../lib/build-query-expression');
const findIndex = require('../lib/find-index');

@@ -17,2 +6,3 @@

let params = {};
Object.keys(options).forEach(option => {

@@ -23,7 +13,5 @@ switch (option) {

break;
case 'limit':
params.Limit = options.limit;
break;
case 'sortForward':

@@ -34,42 +22,36 @@ params.ScanIndexForward = options.sortForward;

});
return params;
}
module.exports =
/*#__PURE__*/
function () {
var _ref = _asyncToGenerator(function* (clientPromise, TableName, query, options = {}) {
let {
documentClient,
indexes
} = yield clientPromise;
let params = {
TableName
};
let IndexName = options.index || findIndex(indexes[TableName], query);
module.exports = async function(clientPromise, TableName, query, options = {}) {
let { documentClient, indexes } = await clientPromise;
if (IndexName && IndexName !== TableName) {
params.IndexName = IndexName;
}
let params = {
TableName,
};
let IndexName = options.index || findIndex(indexes[TableName], query);
params = _objectSpread({}, params, buildParamsFromOptions(options), buildQueryExpression(query, indexes[TableName][IndexName]));
if (IndexName && IndexName !== TableName) {
params.IndexName = IndexName;
}
let _ref2 = yield documentClient.query(params).promise(),
{
Items: result,
LastEvaluatedKey: next
} = _ref2,
meta = _objectWithoutProperties(_ref2, ["Items", "LastEvaluatedKey"]);
params = {
...params,
...buildParamsFromOptions(options),
...buildQueryExpression(query, indexes[TableName][IndexName]),
};
return {
result,
meta: _objectSpread({}, meta, {
next
})
};
});
return function (_x, _x2, _x3) {
return _ref.apply(this, arguments);
let {
Items: result,
LastEvaluatedKey: next,
...meta
} = await documentClient.query(params).promise();
return {
result,
meta: {
...meta,
next,
},
};
}();
};

@@ -1,61 +0,27 @@

"use strict";
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; }
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
function _toPropertyKey(key) { if (typeof key === "symbol") { return key; } else { return String(key); } }
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } } function _next(value) { step("next", value); } function _throw(err) { step("throw", err); } _next(); }); }; }
const createWriteExpression = require('../lib/create-write-expression');
module.exports =
/*#__PURE__*/
function () {
var _ref = _asyncToGenerator(function* (clientPromise, TableName, update) {
let {
documentClient,
indexes
} = yield clientPromise;
let hashKey = indexes[TableName][TableName].hash;
let rangeKey = indexes[TableName][TableName].range;
module.exports = async function(clientPromise, TableName, update) {
let { documentClient, indexes } = await clientPromise;
let {
[hashKey]: hash,
[rangeKey]: range
} = update,
fieldsToUpdate = _objectWithoutProperties(update, [hashKey, rangeKey].map(_toPropertyKey));
let hashKey = indexes[TableName][TableName].hash;
let rangeKey = indexes[TableName][TableName].range;
let Key = {
[hashKey]: hash
};
let { [hashKey]: hash, [rangeKey]: range, ...fieldsToUpdate } = update;
if (rangeKey) {
Key[rangeKey] = range;
}
let Key = {
[hashKey]: hash,
};
if (rangeKey) {
Key[rangeKey] = range;
}
let params = _objectSpread({
TableName,
Key,
ReturnValues: 'ALL_NEW'
}, createWriteExpression(fieldsToUpdate));
let params = {
TableName,
Key,
ReturnValues: 'ALL_NEW',
...createWriteExpression(fieldsToUpdate),
};
let _ref2 = yield documentClient.update(params).promise(),
{
Attributes
} = _ref2,
meta = _objectWithoutProperties(_ref2, ["Attributes"]);
return {
result: Attributes,
meta
};
});
return function (_x, _x2, _x3) {
return _ref.apply(this, arguments);
};
}();
let { Attributes, ...meta } = await documentClient.update(params).promise();
return { result: Attributes, meta };
};

@@ -1,24 +0,5 @@

"use strict";
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } } function _next(value) { step("next", value); } function _throw(err) { step("throw", err); } _next(); }); }; }
module.exports =
/*#__PURE__*/
function () {
var _ref = _asyncToGenerator(function* (clientPromise, TableName, state) {
let {
client
} = yield clientPromise;
let result = yield client.waitFor(state, {
TableName
}).promise();
return {
result,
meta: {}
};
});
return function (_x, _x2, _x3) {
return _ref.apply(this, arguments);
};
}();
module.exports = async function(clientPromise, TableName, state) {
let { client } = await clientPromise;
let result = await client.waitFor(state, { TableName }).promise();
return { result, meta: {} };
};

@@ -1,54 +0,38 @@

"use strict";
// const chunk = require('chunk')
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; }
const MAX_BATCH_WRITE = 25;
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
module.exports = async function(clientPromise, writeType, TableName, items) {
let { documentClient } = await clientPromise;
let param = writeType === 'PutRequest' ? 'Item' : 'Key';
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
let maxItems = items.slice(0, MAX_BATCH_WRITE);
let remainingItems = items.slice(MAX_BATCH_WRITE);
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } } function _next(value) { step("next", value); } function _throw(err) { step("throw", err); } _next(); }); }; }
let params = {
RequestItems: {
[TableName]: maxItems.map(item => ({
[writeType]: {
[param]: item,
},
})),
},
};
// const chunk = require('chunk')
const MAX_BATCH_WRITE = 25;
let {
UnprocessedItems: unprocessedItems,
...meta
} = await documentClient.batchWrite(params).promise();
module.exports =
/*#__PURE__*/
function () {
var _ref = _asyncToGenerator(function* (clientPromise, writeType, TableName, items) {
let {
documentClient
} = yield clientPromise;
let param = writeType === 'PutRequest' ? 'Item' : 'Key';
let maxItems = items.slice(0, MAX_BATCH_WRITE);
let remainingItems = items.slice(MAX_BATCH_WRITE);
let params = {
RequestItems: {
[TableName]: maxItems.map(item => ({
[writeType]: {
[param]: item
}
}))
}
};
let _ref2 = yield documentClient.batchWrite(params).promise(),
{
UnprocessedItems: unprocessedItems
} = _ref2,
meta = _objectWithoutProperties(_ref2, ["UnprocessedItems"]);
unprocessedItems = (unprocessedItems[TableName] || []).map(item => {
return item[writeType];
});
return {
result: null,
meta: _objectSpread({}, meta, {
next: [...unprocessedItems, ...remainingItems]
})
};
unprocessedItems = (unprocessedItems[TableName] || []).map(item => {
return item[writeType];
});
return function (_x, _x2, _x3, _x4) {
return _ref.apply(this, arguments);
return {
result: null,
meta: {
...meta,
next: [...unprocessedItems, ...remainingItems],
},
};
}();
};
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