Comparing version 2.1.0 to 2.2.0
{ | ||
"name": "dynaql", | ||
"version": "2.1.0", | ||
"version": "2.2.0", | ||
"description": "Dynamo library to make interacting with dynamo easier", | ||
@@ -8,3 +8,4 @@ "main": "src/index.js", | ||
"test": "./test.sh", | ||
"prettier": "prettier --write \"./**/*.js\"" | ||
"prettier": "prettier --write \"./**/*.js\"", | ||
"build": "./build.sh" | ||
}, | ||
@@ -26,3 +27,3 @@ "repository": { | ||
"engines": { | ||
"node": ">=8.6.0" | ||
"node": ">=6.10" | ||
}, | ||
@@ -34,2 +35,5 @@ "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", | ||
@@ -36,0 +40,0 @@ "prettier": "^1.7.4" |
@@ -1,22 +0,33 @@ | ||
const createClients = require('./lib/create-clients'); | ||
"use strict"; | ||
// document client | ||
const createClients = require('./lib/create-clients'); // 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'); | ||
// normal client | ||
const writeAll = require('./methods/write-all'); // 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 { | ||
@@ -31,3 +42,2 @@ get: get.bind(null, clientPromise), | ||
deleteAll: writeAll.bind(null, clientPromise, 'DeleteRequest'), | ||
createTable: createTable.bind(null, clientPromise), | ||
@@ -37,4 +47,4 @@ deleteTable: deleteTable.bind(null, clientPromise), | ||
describeTable: describeTable.bind(null, clientPromise), | ||
waitFor: waitFor.bind(null, clientPromise), | ||
waitFor: waitFor.bind(null, clientPromise) | ||
}; | ||
}; | ||
}; |
@@ -0,1 +1,3 @@ | ||
"use strict"; | ||
const buildQueryExpression = require('../build-query-expression'); | ||
@@ -5,19 +7,25 @@ | ||
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({ | ||
@@ -27,10 +35,10 @@ KeyConditionExpression: '#HASH = :HVALUE AND #RANGE = :RVALUE', | ||
'#HASH': 'id', | ||
'#RANGE': 'date', | ||
'#RANGE': 'date' | ||
}, | ||
ExpressionAttributeValues: { | ||
':HVALUE': '1', | ||
':RVALUE': '2', | ||
}, | ||
':RVALUE': '2' | ||
} | ||
}); | ||
}); | ||
}); | ||
}); |
@@ -0,2 +1,7 @@ | ||
"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'); | ||
@@ -8,35 +13,42 @@ | ||
accessKeyId: 'dynaql', | ||
secretAccessKey: 'dynaql', | ||
secretAccessKey: 'dynaql' | ||
}; | ||
describe('createClients', () => { | ||
beforeAll(async () => { | ||
await testHelpers.createTable('createClientsTable'); | ||
}); | ||
afterAll(async () => { | ||
await testHelpers.deleteTable('createClientsTable'); | ||
}); | ||
it('creates the clients', async () => { | ||
let { documentClient, client } = await createClients(config); | ||
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); | ||
expect(documentClient).not.toBeNull(); | ||
expect(client).not.toBeNull(); | ||
}); | ||
it('gets the indexes of existing tables', async () => { | ||
let { indexes } = await createClients(config); | ||
})); | ||
it('gets the indexes of existing tables', | ||
/*#__PURE__*/ | ||
_asyncToGenerator(function* () { | ||
let { | ||
indexes | ||
} = yield createClients(config); | ||
expect(indexes).toEqual({ | ||
createClientsTable: { | ||
createClientsTable: { | ||
hash: 'id', | ||
hash: 'id' | ||
}, | ||
dynaqlTestIndex: { | ||
hash: 'name', | ||
}, | ||
}, | ||
hash: 'name' | ||
} | ||
} | ||
}); | ||
}); | ||
}); | ||
})); | ||
}); |
@@ -0,1 +1,3 @@ | ||
"use strict"; | ||
const createWriteExpression = require('../create-write-expression'); | ||
@@ -7,22 +9,19 @@ | ||
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 | ||
}; | ||
@@ -33,10 +32,9 @@ let params = createWriteExpression(update); | ||
'#id': 'id', | ||
'#username': 'username', | ||
'#username': 'username' | ||
}); | ||
}); | ||
it('can combine both', () => { | ||
let update = { | ||
id: 'asdf', | ||
username: null, | ||
username: null | ||
}; | ||
@@ -47,8 +45,8 @@ let params = createWriteExpression(update); | ||
'#id': 'id', | ||
'#username': 'username', | ||
'#username': 'username' | ||
}); | ||
expect(params.ExpressionAttributeValues).toEqual({ | ||
':id': 'asdf', | ||
':id': 'asdf' | ||
}); | ||
}); | ||
}); | ||
}); |
@@ -0,1 +1,3 @@ | ||
"use strict"; | ||
const extractIndexes = require('../extract-indexes'); | ||
@@ -7,63 +9,49 @@ | ||
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: [ | ||
{ | ||
KeySchema: [{ | ||
KeyType: 'HASH', | ||
AttributeName: 'id' | ||
}, { | ||
KeyType: 'RANGE', | ||
AttributeName: 'date' | ||
}], | ||
GlobalSecondaryIndexes: [{ | ||
IndexName: 'extractTableIndex', | ||
KeySchema: [{ | ||
KeyType: 'HASH', | ||
AttributeName: 'id', | ||
}, | ||
{ | ||
AttributeName: 'id' | ||
}, { | ||
KeyType: 'RANGE', | ||
AttributeName: 'date', | ||
}, | ||
], | ||
GlobalSecondaryIndexes: [ | ||
{ | ||
IndexName: 'extractTableIndex', | ||
KeySchema: [ | ||
{ | ||
KeyType: 'HASH', | ||
AttributeName: 'id', | ||
}, | ||
{ | ||
KeyType: 'RANGE', | ||
AttributeName: 'date', | ||
}, | ||
], | ||
}, | ||
], | ||
AttributeName: 'date' | ||
}] | ||
}] | ||
}; | ||
expect(extractIndexes(params)).toEqual({ | ||
extractTable: { | ||
hash: 'id', | ||
range: 'date', | ||
range: 'date' | ||
}, | ||
extractTableIndex: { | ||
hash: 'id', | ||
range: 'date', | ||
}, | ||
range: 'date' | ||
} | ||
}); | ||
}); | ||
}); | ||
}); |
@@ -0,1 +1,3 @@ | ||
"use strict"; | ||
const findIndex = require('../find-index'); | ||
@@ -7,28 +9,32 @@ | ||
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'); | ||
}); | ||
}); | ||
}); |
@@ -0,1 +1,3 @@ | ||
"use strict"; | ||
module.exports = function buildExpression(key, index) { | ||
@@ -5,7 +7,7 @@ let params = { | ||
ExpressionAttributeNames: { | ||
'#HASH': index.hash, | ||
'#HASH': index.hash | ||
}, | ||
ExpressionAttributeValues: { | ||
':HVALUE': key[index.hash], | ||
}, | ||
':HVALUE': key[index.hash] | ||
} | ||
}; | ||
@@ -15,7 +17,6 @@ | ||
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; | ||
}; | ||
}; |
@@ -0,26 +1,43 @@ | ||
"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 AWS = require('aws-sdk'); | ||
const listTables = require('../methods/list-tables'); | ||
const describeTable = require('../methods/describe-table'); | ||
const extractIndexes = require('./extract-indexes'); | ||
module.exports = async function createClient(config) { | ||
let client = new AWS.DynamoDB(config); | ||
let documentClient = new AWS.DynamoDB.DocumentClient({ service: client }); | ||
let { result } = await listTables(Promise.resolve({ client })); | ||
let tableDefinitions = await Promise.all( | ||
result.map(tableName => | ||
describeTable(Promise.resolve({ client }), tableName) | ||
) | ||
); | ||
let indexes = tableDefinitions | ||
.map(tableDefinition => tableDefinition.result) | ||
.reduce((collection, definition) => { | ||
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) => { | ||
collection[definition.TableName] = extractIndexes(definition); | ||
return collection; | ||
}, {}); | ||
return { | ||
documentClient, | ||
client, | ||
indexes | ||
}; | ||
}); | ||
return { documentClient, client, indexes }; | ||
}; | ||
return function createClient(_x) { | ||
return _createClient.apply(this, arguments); | ||
}; | ||
}(); |
@@ -0,1 +1,3 @@ | ||
"use strict"; | ||
module.exports = function createWriteExpression(update) { | ||
@@ -5,30 +7,34 @@ let params = { | ||
ExpressionAttributeNames: {}, | ||
ExpressionAttributeValues: {}, | ||
ExpressionAttributeValues: {} | ||
}; | ||
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; | ||
} | ||
let expressions = Object.keys(update).reduce((expressions, key) => { | ||
let expressionName = `#${key}`; | ||
return expressions; | ||
}, | ||
{ set: [], remove: [] } | ||
); | ||
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: [] | ||
}); | ||
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,28 +0,22 @@ | ||
module.exports = function(tableDefinition) { | ||
"use strict"; | ||
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,22 +0,25 @@ | ||
module.exports = function(indexes, key) { | ||
"use strict"; | ||
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++; | ||
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 } | ||
); | ||
if (keysUsed / keys.length > best.keysUsed) { | ||
return { | ||
indexName, | ||
keysUsed | ||
}; | ||
} else { | ||
return best; | ||
} | ||
}, { | ||
indexName: '', | ||
keysUsed: 0 | ||
}); | ||
return bestIndex.indexName; | ||
}; | ||
}; |
@@ -0,101 +1,96 @@ | ||
"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', async () => { | ||
it('creates the table', | ||
/*#__PURE__*/ | ||
_asyncToGenerator(function* () { | ||
let tableName = 'createTableTestTable'; | ||
await createTable(testHelpers.clientPromise, { | ||
yield 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 | ||
} | ||
}); | ||
await waitFor(testHelpers.clientPromise, tableName, 'tableExists'); | ||
let { result } = await describeTable(testHelpers.clientPromise, tableName); | ||
await testHelpers.deleteTable(tableName); | ||
yield waitFor(testHelpers.clientPromise, tableName, 'tableExists'); | ||
let { | ||
result | ||
} = yield describeTable(testHelpers.clientPromise, tableName); | ||
yield 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', async () => { | ||
})); | ||
it('adds the table schema and indexes to the indexes', | ||
/*#__PURE__*/ | ||
_asyncToGenerator(function* () { | ||
let tableName = 'createTableIndexesTestTable'; | ||
await createTable(testHelpers.clientPromise, { | ||
yield 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, | ||
}, | ||
Projection: { | ||
ProjectionType: 'ALL', | ||
}, | ||
GlobalSecondaryIndexes: [{ | ||
IndexName: 'createTableIndexesTestTableIndex', | ||
KeySchema: [{ | ||
KeyType: 'HASH', | ||
AttributeName: 'username' | ||
}], | ||
ProvisionedThroughput: { | ||
ReadCapacityUnits: 1, | ||
WriteCapacityUnits: 1 | ||
}, | ||
], | ||
Projection: { | ||
ProjectionType: 'ALL' | ||
} | ||
}] | ||
}); | ||
await waitFor(testHelpers.clientPromise, tableName, 'tableExists'); | ||
let { indexes } = await testHelpers.clientPromise; | ||
yield waitFor(testHelpers.clientPromise, tableName, 'tableExists'); | ||
let { | ||
indexes | ||
} = yield testHelpers.clientPromise; | ||
expect(indexes).toMatchObject({ | ||
@@ -105,13 +100,12 @@ [tableName]: { | ||
hash: 'id', | ||
range: undefined, | ||
range: undefined | ||
}, | ||
createTableIndexesTestTableIndex: { | ||
hash: 'username', | ||
range: undefined, | ||
}, | ||
}, | ||
range: undefined | ||
} | ||
} | ||
}); | ||
await testHelpers.deleteTable(tableName); | ||
}); | ||
}); | ||
yield testHelpers.deleteTable(tableName); | ||
})); | ||
}); |
@@ -0,31 +1,45 @@ | ||
"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', async () => { | ||
it('deletes a table', | ||
/*#__PURE__*/ | ||
_asyncToGenerator(function* () { | ||
let tableName = 'deleteTableTestTable'; | ||
await testHelpers.createTable(tableName); | ||
await deleteTable(testHelpers.clientPromise, { TableName: tableName }); | ||
await waitFor(testHelpers.clientPromise, tableName, 'tableNotExists'); | ||
let { result } = await listTables(testHelpers.clientPromise); | ||
yield testHelpers.createTable(tableName); | ||
yield deleteTable(testHelpers.clientPromise, { | ||
TableName: tableName | ||
}); | ||
yield waitFor(testHelpers.clientPromise, tableName, 'tableNotExists'); | ||
let { | ||
result | ||
} = yield listTables(testHelpers.clientPromise); | ||
expect(result.includes(tableName)).toBeFalsy(); | ||
}); | ||
it('deletes table indexes', async () => { | ||
})); | ||
it('deletes table indexes', | ||
/*#__PURE__*/ | ||
_asyncToGenerator(function* () { | ||
let tableName = 'deleteTableIndexesTestTable'; | ||
await testHelpers.createTable(tableName); | ||
let { indexes } = await testHelpers.clientPromise; | ||
yield testHelpers.createTable(tableName); | ||
let { | ||
indexes | ||
} = yield testHelpers.clientPromise; | ||
expect(indexes[tableName]).toBeDefined(); | ||
await deleteTable(testHelpers.clientPromise, { TableName: tableName }); | ||
await waitFor(testHelpers.clientPromise, tableName, 'tableNotExists'); | ||
yield deleteTable(testHelpers.clientPromise, { | ||
TableName: tableName | ||
}); | ||
yield waitFor(testHelpers.clientPromise, tableName, 'tableNotExists'); | ||
expect(indexes[tableName]).toBeUndefined(); | ||
}); | ||
}); | ||
})); | ||
}); |
@@ -0,4 +1,11 @@ | ||
"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'); | ||
@@ -8,20 +15,31 @@ | ||
let tableName = 'deleteTestTable'; | ||
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' }); | ||
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' | ||
}); | ||
expect(results.result).toBeDefined(); | ||
await deleteItem(testHelpers.clientPromise, tableName, { id: '1' }); | ||
results = await get(testHelpers.clientPromise, tableName, { id: '1' }); | ||
yield deleteItem(testHelpers.clientPromise, tableName, { | ||
id: '1' | ||
}); | ||
results = yield get(testHelpers.clientPromise, tableName, { | ||
id: '1' | ||
}); | ||
expect(results.result).not.toBeDefined(); | ||
}); | ||
}); | ||
})); | ||
}); |
@@ -0,2 +1,7 @@ | ||
"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'); | ||
@@ -6,13 +11,20 @@ | ||
let tableName = 'describeTableTestTable'; | ||
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); | ||
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); | ||
expect(result.TableName).toEqual(tableName); | ||
}); | ||
}); | ||
})); | ||
}); |
@@ -0,4 +1,11 @@ | ||
"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'); | ||
@@ -8,42 +15,46 @@ | ||
let tableName = 'getAllTestTable'; | ||
let items = [...Array(150)].map(() => ({ id: uuid() })); | ||
beforeAll(async () => { | ||
await testHelpers.createTable(tableName); | ||
let items = [...Array(150)].map(() => ({ | ||
id: uuid() | ||
})); | ||
beforeAll( | ||
/*#__PURE__*/ | ||
_asyncToGenerator(function* () { | ||
yield testHelpers.createTable(tableName); | ||
let itemsToWrite = items.slice(); | ||
let itemsToWrite = items.slice(); | ||
while (itemsToWrite.length) { | ||
let { meta: { next } } = await writeAll( | ||
testHelpers.clientPromise, | ||
'PutRequest', | ||
tableName, | ||
itemsToWrite | ||
); | ||
let { | ||
meta: { | ||
next | ||
} | ||
} = yield writeAll(testHelpers.clientPromise, 'PutRequest', tableName, itemsToWrite); | ||
itemsToWrite = next; | ||
} | ||
}); | ||
afterAll(async () => { | ||
await testHelpers.deleteTable(tableName); | ||
}); | ||
it('can get all items less than max batch size', async () => { | ||
})); | ||
afterAll( | ||
/*#__PURE__*/ | ||
_asyncToGenerator(function* () { | ||
yield testHelpers.deleteTable(tableName); | ||
})); | ||
it('can get all items less than max batch size', | ||
/*#__PURE__*/ | ||
_asyncToGenerator(function* () { | ||
let subItems = items.slice(0, 50); | ||
let { result, meta } = await getAll( | ||
testHelpers.clientPromise, | ||
tableName, | ||
subItems | ||
); | ||
let { | ||
result, | ||
meta | ||
} = yield 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', async () => { | ||
let { result, meta } = await getAll( | ||
testHelpers.clientPromise, | ||
tableName, | ||
items | ||
); | ||
})); | ||
it('can get items up to the max batch size', | ||
/*#__PURE__*/ | ||
_asyncToGenerator(function* () { | ||
let { | ||
result, | ||
meta | ||
} = yield getAll(testHelpers.clientPromise, tableName, items); | ||
expect(result.length).toEqual(100); | ||
expect(meta.next.length).toEqual(50); | ||
}); | ||
}); | ||
})); | ||
}); |
@@ -0,3 +1,9 @@ | ||
"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'); | ||
@@ -7,18 +13,27 @@ | ||
let tableName = 'getTestTable'; | ||
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', | ||
beforeAll( | ||
/*#__PURE__*/ | ||
_asyncToGenerator(function* () { | ||
yield testHelpers.createTable(tableName); | ||
yield put(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' | ||
}); | ||
}); | ||
}); | ||
})); | ||
}); |
@@ -0,2 +1,7 @@ | ||
"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'); | ||
@@ -6,12 +11,20 @@ | ||
let tableName = 'listTablesTestTable'; | ||
beforeAll(async () => { | ||
await testHelpers.createTable(tableName); | ||
}); | ||
afterAll(async () => { | ||
await testHelpers.deleteTable(tableName); | ||
}); | ||
it('lists tables', async () => { | ||
let { result } = await listTables(testHelpers.clientPromise); | ||
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); | ||
expect(result).toEqual([tableName]); | ||
}); | ||
}); | ||
})); | ||
}); |
@@ -0,3 +1,9 @@ | ||
"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'); | ||
@@ -7,35 +13,48 @@ | ||
let tableName = 'putTestTable'; | ||
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, { | ||
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, { | ||
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', async () => { | ||
let { result: item } = await put(testHelpers.clientPromise, tableName, { | ||
name: 'ya', | ||
})); | ||
it('can create an id if one is not passed in', | ||
/*#__PURE__*/ | ||
_asyncToGenerator(function* () { | ||
let { | ||
result: item | ||
} = yield put(testHelpers.clientPromise, tableName, { | ||
name: 'ya' | ||
}); | ||
expect(item.id).toBeDefined(); | ||
let { result } = await get(testHelpers.clientPromise, tableName, { | ||
id: item.id, | ||
let { | ||
result | ||
} = yield get(testHelpers.clientPromise, tableName, { | ||
id: item.id | ||
}); | ||
expect(result).toEqual({ | ||
id: item.id, | ||
name: 'ya', | ||
name: 'ya' | ||
}); | ||
}); | ||
}); | ||
})); | ||
}); |
@@ -0,4 +1,11 @@ | ||
"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'); | ||
@@ -10,33 +17,40 @@ | ||
id: uuid(), | ||
name: 'queryName', | ||
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', | ||
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' | ||
}); | ||
expect(result.length).toEqual(5); | ||
}); | ||
it('accepts a limit', async () => { | ||
let { result } = await query( | ||
testHelpers.clientPromise, | ||
tableName, | ||
{ name: 'queryName' }, | ||
{ limit: 1 } | ||
); | ||
})); | ||
it('accepts a limit', | ||
/*#__PURE__*/ | ||
_asyncToGenerator(function* () { | ||
let { | ||
result | ||
} = yield query(testHelpers.clientPromise, tableName, { | ||
name: 'queryName' | ||
}, { | ||
limit: 1 | ||
}); | ||
expect(result.length).toEqual(1); | ||
}); | ||
it('can sort forward', async () => { | ||
}) | ||
}); | ||
})); | ||
it('can sort forward', | ||
/*#__PURE__*/ | ||
_asyncToGenerator(function* () {})); | ||
}); |
@@ -0,4 +1,11 @@ | ||
"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'); | ||
@@ -8,26 +15,37 @@ | ||
let tableName = 'updateTestTable'; | ||
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, { | ||
beforeAll( | ||
/*#__PURE__*/ | ||
_asyncToGenerator(function* () { | ||
yield testHelpers.createTable(tableName); | ||
yield put(testHelpers.clientPromise, tableName, { | ||
id: '1', | ||
name: 'Ya', | ||
name: 'Yo' | ||
}); | ||
})); | ||
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 = await get(testHelpers.clientPromise, tableName, { id: '1' }); | ||
let response = yield get(testHelpers.clientPromise, tableName, { | ||
id: '1' | ||
}); | ||
expect(response.result).toEqual({ | ||
id: '1', | ||
name: 'Ya', | ||
name: 'Ya' | ||
}); | ||
}); | ||
}); | ||
})); | ||
}); |
@@ -0,4 +1,11 @@ | ||
"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'); | ||
@@ -8,27 +15,26 @@ | ||
let tableName = 'waitForTestTable'; | ||
it('can wait for table states', async () => { | ||
await createTable(testHelpers.clientPromise, { | ||
it('can wait for table states', | ||
/*#__PURE__*/ | ||
_asyncToGenerator(function* () { | ||
yield 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' | ||
}] | ||
}); | ||
await waitFor(testHelpers.clientPromise, tableName, 'tableExists'); | ||
await deleteTable(testHelpers.clientPromise, { TableName: tableName }); | ||
await waitFor(testHelpers.clientPromise, tableName, 'tableNotExists'); | ||
}); | ||
}); | ||
yield waitFor(testHelpers.clientPromise, tableName, 'tableExists'); | ||
yield deleteTable(testHelpers.clientPromise, { | ||
TableName: tableName | ||
}); | ||
yield waitFor(testHelpers.clientPromise, tableName, 'tableNotExists'); | ||
})); | ||
}); |
@@ -0,3 +1,9 @@ | ||
"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'); | ||
@@ -7,74 +13,78 @@ | ||
let tableName = 'writeAllTestTable'; | ||
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' }, | ||
]); | ||
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' | ||
}]); | ||
expect(result).toEqual(items); | ||
}); | ||
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' }, | ||
]); | ||
})); | ||
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' | ||
}]); | ||
expect(result).toEqual(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); | ||
})); | ||
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); | ||
expect(result.length).toEqual(0); | ||
}); | ||
it('returns next', async () => { | ||
})); | ||
it('returns next', | ||
/*#__PURE__*/ | ||
_asyncToGenerator(function* () { | ||
let items = [...Array(26)].map((_, i) => ({ | ||
id: String(i), | ||
name: String(i), | ||
name: String(i) | ||
})); | ||
let { meta } = await writeAll( | ||
testHelpers.clientPromise, | ||
'PutRequest', | ||
tableName, | ||
items | ||
); | ||
let { | ||
meta | ||
} = yield writeAll(testHelpers.clientPromise, 'PutRequest', tableName, items); | ||
expect(meta.next.length).toEqual(1); | ||
}); | ||
}); | ||
})); | ||
}); |
@@ -0,10 +1,26 @@ | ||
"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 extractIndexes = require('../lib/extract-indexes'); | ||
module.exports = async function(clientPromise, params) { | ||
let { client, indexes } = await clientPromise; | ||
let result = await client.createTable(params).promise(); | ||
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: {} | ||
}; | ||
}); | ||
indexes[params.TableName] = extractIndexes(params); | ||
return { result, meta: {} }; | ||
}; | ||
return function (_x, _x2) { | ||
return _ref.apply(this, arguments); | ||
}; | ||
}(); |
@@ -1,8 +0,24 @@ | ||
module.exports = async function(clientPromise, params) { | ||
let { client, indexes } = await clientPromise; | ||
let result = await client.deleteTable(params).promise(); | ||
"use strict"; | ||
delete indexes[params.TableName]; | ||
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(); }); }; } | ||
return { result, meta: {} }; | ||
}; | ||
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); | ||
}; | ||
}(); |
@@ -1,6 +0,26 @@ | ||
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 }; | ||
}; | ||
"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); | ||
}; | ||
}(); |
@@ -1,5 +0,26 @@ | ||
module.exports = async function(clientPromise, TableName) { | ||
let { client } = await clientPromise; | ||
let { Table: result } = await client.describeTable({ TableName }).promise(); | ||
return { result, meta: {} }; | ||
}; | ||
"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); | ||
}; | ||
}(); |
@@ -1,35 +0,54 @@ | ||
const MAX_BATCH_GET = 100; | ||
"use strict"; | ||
module.exports = async function(clientPromise, TableName, Keys) { | ||
let { documentClient } = await clientPromise; | ||
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; } | ||
let maxKeys = Keys.slice(0, MAX_BATCH_GET); | ||
let remainingKeys = Keys.slice(MAX_BATCH_GET); | ||
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 params = { | ||
RequestItems: { | ||
[TableName]: { | ||
Keys: maxKeys, | ||
}, | ||
}, | ||
}; | ||
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 response = await documentClient.batchGet(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(); }); }; } | ||
let { | ||
Responses: { [TableName]: result }, | ||
UnprocessedKeys: { [TableName]: unprocessedKeys }, | ||
...meta | ||
} = response; | ||
const MAX_BATCH_GET = 100; | ||
next = unprocessedKeys || []; | ||
next.push(...remainingKeys); | ||
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(); | ||
return { | ||
result, | ||
meta: { | ||
...meta, | ||
next, | ||
}, | ||
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); | ||
}; | ||
}; | ||
}(); |
@@ -1,9 +0,34 @@ | ||
module.exports = async function(clientPromise, TableName, Key) { | ||
let { documentClient } = await clientPromise; | ||
let params = { | ||
TableName, | ||
Key, | ||
"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); | ||
}; | ||
let { Item: result, ...meta } = await documentClient.get(params).promise(); | ||
return { result, meta }; | ||
}; | ||
}(); |
@@ -1,5 +0,24 @@ | ||
module.exports = async function(clientPromise, options = {}) { | ||
let { client } = await clientPromise; | ||
let { TableNames: result } = await client.listTables(options).promise(); | ||
return { result, meta: {} }; | ||
}; | ||
"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); | ||
}; | ||
}(); |
@@ -0,16 +1,39 @@ | ||
"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 = async function(clientPromise, TableName, model, options = {}) { | ||
let { documentClient, indexes } = await clientPromise; | ||
let Item = { | ||
[indexes[TableName][TableName].hash]: uuid(), | ||
...model, | ||
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); | ||
}; | ||
let params = { | ||
TableName, | ||
Item, | ||
...options, | ||
}; | ||
let meta = await documentClient.put(params).promise(); | ||
return { result: Item, meta }; | ||
}; | ||
}(); |
@@ -0,2 +1,13 @@ | ||
"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'); | ||
@@ -6,3 +17,2 @@ | ||
let params = {}; | ||
Object.keys(options).forEach(option => { | ||
@@ -13,5 +23,7 @@ switch (option) { | ||
break; | ||
case 'limit': | ||
params.Limit = options.limit; | ||
break; | ||
case 'sortForward': | ||
@@ -22,36 +34,42 @@ params.ScanIndexForward = options.sortForward; | ||
}); | ||
return params; | ||
} | ||
module.exports = async function(clientPromise, TableName, query, options = {}) { | ||
let { documentClient, indexes } = await clientPromise; | ||
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); | ||
let params = { | ||
TableName, | ||
}; | ||
let IndexName = options.index || findIndex(indexes[TableName], query); | ||
if (IndexName && IndexName !== TableName) { | ||
params.IndexName = IndexName; | ||
} | ||
if (IndexName && IndexName !== TableName) { | ||
params.IndexName = IndexName; | ||
} | ||
params = _objectSpread({}, params, buildParamsFromOptions(options), buildQueryExpression(query, indexes[TableName][IndexName])); | ||
params = { | ||
...params, | ||
...buildParamsFromOptions(options), | ||
...buildQueryExpression(query, indexes[TableName][IndexName]), | ||
}; | ||
let _ref2 = yield documentClient.query(params).promise(), | ||
{ | ||
Items: result, | ||
LastEvaluatedKey: next | ||
} = _ref2, | ||
meta = _objectWithoutProperties(_ref2, ["Items", "LastEvaluatedKey"]); | ||
let { | ||
Items: result, | ||
LastEvaluatedKey: next, | ||
...meta | ||
} = await documentClient.query(params).promise(); | ||
return { | ||
result, | ||
meta: { | ||
...meta, | ||
next, | ||
}, | ||
return { | ||
result, | ||
meta: _objectSpread({}, meta, { | ||
next | ||
}) | ||
}; | ||
}); | ||
return function (_x, _x2, _x3) { | ||
return _ref.apply(this, arguments); | ||
}; | ||
}; | ||
}(); |
@@ -0,27 +1,61 @@ | ||
"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 = async function(clientPromise, TableName, update) { | ||
let { documentClient, indexes } = await clientPromise; | ||
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; | ||
let hashKey = indexes[TableName][TableName].hash; | ||
let rangeKey = indexes[TableName][TableName].range; | ||
let { | ||
[hashKey]: hash, | ||
[rangeKey]: range | ||
} = update, | ||
fieldsToUpdate = _objectWithoutProperties(update, [hashKey, rangeKey].map(_toPropertyKey)); | ||
let { [hashKey]: hash, [rangeKey]: range, ...fieldsToUpdate } = update; | ||
let Key = { | ||
[hashKey]: hash | ||
}; | ||
let Key = { | ||
[hashKey]: hash, | ||
}; | ||
if (rangeKey) { | ||
Key[rangeKey] = range; | ||
} | ||
if (rangeKey) { | ||
Key[rangeKey] = range; | ||
} | ||
let params = { | ||
TableName, | ||
Key, | ||
ReturnValues: 'ALL_NEW', | ||
...createWriteExpression(fieldsToUpdate), | ||
let params = _objectSpread({ | ||
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,5 +0,24 @@ | ||
module.exports = async function(clientPromise, TableName, state) { | ||
let { client } = await clientPromise; | ||
let result = await client.waitFor(state, { TableName }).promise(); | ||
return { result, meta: {} }; | ||
}; | ||
"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); | ||
}; | ||
}(); |
@@ -1,38 +0,54 @@ | ||
// const chunk = require('chunk') | ||
"use strict"; | ||
const MAX_BATCH_WRITE = 25; | ||
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, writeType, TableName, items) { | ||
let { documentClient } = await clientPromise; | ||
let param = writeType === 'PutRequest' ? 'Item' : 'Key'; | ||
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 maxItems = items.slice(0, MAX_BATCH_WRITE); | ||
let remainingItems = items.slice(MAX_BATCH_WRITE); | ||
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]: maxItems.map(item => ({ | ||
[writeType]: { | ||
[param]: item, | ||
}, | ||
})), | ||
}, | ||
}; | ||
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 { | ||
UnprocessedItems: unprocessedItems, | ||
...meta | ||
} = await documentClient.batchWrite(params).promise(); | ||
// const chunk = require('chunk') | ||
const MAX_BATCH_WRITE = 25; | ||
unprocessedItems = (unprocessedItems[TableName] || []).map(item => { | ||
return item[writeType]; | ||
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] | ||
}) | ||
}; | ||
}); | ||
return { | ||
result: null, | ||
meta: { | ||
...meta, | ||
next: [...unprocessedItems, ...remainingItems], | ||
}, | ||
return function (_x, _x2, _x3, _x4) { | ||
return _ref.apply(this, arguments); | ||
}; | ||
}; | ||
}(); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1354
1
54989
5
36
2
0
1