Comparing version 0.0.1 to 0.0.2
@@ -1,22 +0,57 @@ | ||
var tableDb = require('../db').tableDb | ||
var db = require('../db'), | ||
tableDb = db.tableDb | ||
module.exports = function createTable(data, cb) { | ||
data.CreationDateTime = Date.now() / 1000 | ||
data.ItemCount = 0 | ||
data.ProvisionedThroughput.NumberOfDecreasesToday = 0 | ||
data.TableSizeBytes = 0 | ||
data.TableStatus = 'CREATING' | ||
if (data.LocalSecondaryIndexes) { | ||
data.LocalSecondaryIndexes.forEach(function(index) { | ||
index.IndexSizeBytes = 0 | ||
index.ItemCount = 0 | ||
var key = data.TableName | ||
tableDb.lock(key, function(release) { | ||
cb = release(cb) | ||
tableDb.get(key, function(err) { | ||
if (err && err.name != 'NotFoundError') return cb(err) | ||
if (!err) { | ||
err = new Error | ||
err.statusCode = 400 | ||
err.body = { | ||
__type: 'com.amazonaws.dynamodb.v20120810#ResourceInUseException', | ||
message: '', | ||
} | ||
return cb(err) | ||
} | ||
data.CreationDateTime = Date.now() / 1000 | ||
data.ItemCount = 0 | ||
data.ProvisionedThroughput.NumberOfDecreasesToday = 0 | ||
data.TableSizeBytes = 0 | ||
data.TableStatus = 'CREATING' | ||
if (data.LocalSecondaryIndexes) { | ||
data.LocalSecondaryIndexes.forEach(function(index) { | ||
index.IndexSizeBytes = 0 | ||
index.ItemCount = 0 | ||
}) | ||
} | ||
tableDb.put(key, data, function(err) { | ||
if (err) return cb(err) | ||
setTimeout(function() { | ||
// Shouldn't need to lock/fetch as nothing should have changed | ||
data.TableStatus = 'ACTIVE' | ||
tableDb.put(key, data, function(err) { | ||
// TODO: Need to check this | ||
if (err) console.error(err) | ||
}) | ||
}, db.createTableMs) | ||
cb(null, {TableDescription: data}) | ||
}) | ||
}) | ||
} | ||
}) | ||
tableDb.put(data.TableName, data, function(err) { | ||
cb(err, {TableDescription: data}) | ||
}) | ||
} | ||
@@ -1,20 +0,40 @@ | ||
var tableDb = require('../db').tableDb | ||
var db = require('../db') | ||
module.exports = function deleteTable(data, cb) { | ||
tableDb.get(data.TableName, function(err, table) { | ||
if (err) { | ||
if (err.name == 'NotFoundError') { | ||
err.statusCode = 400 | ||
err.body = { | ||
__type: 'com.amazonaws.dynamodb.v20120810#ResourceNotFoundException', | ||
message: 'Requested resource not found: Table: ' + data.TableName + ' not found', | ||
} | ||
var key = data.TableName | ||
db.getTable(key, function(err, table) { | ||
if (err) return cb(err) | ||
// Check if table is ACTIVE or not? | ||
if (table.TableStatus == 'CREATING') { | ||
err = new Error | ||
err.statusCode = 400 | ||
err.body = { | ||
__type: 'com.amazonaws.dynamodb.v20120810#ResourceInUseException', | ||
message: 'Attempt to change a resource which is still in use: Table is being created: ' + key, | ||
} | ||
return cb(err) | ||
} | ||
cb(null, {Table: table}) | ||
table.TableStatus = 'DELETING' | ||
db.tableDb.put(key, table, function(err) { | ||
if (err) return cb(err) | ||
setTimeout(function() { | ||
// TODO: Delete items too | ||
db.tableDb.del(key, function(err) { | ||
// TODO: Need to check this | ||
if (err) console.error(err) | ||
}) | ||
}, db.deleteTableMs) | ||
cb(null, {TableDescription: table}) | ||
}) | ||
}) | ||
} | ||
@@ -1,16 +0,8 @@ | ||
var tableDb = require('../db').tableDb | ||
var db = require('../db') | ||
module.exports = function describeTable(data, cb) { | ||
tableDb.get(data.TableName, function(err, table) { | ||
if (err) { | ||
if (err.name == 'NotFoundError') { | ||
err.statusCode = 400 | ||
err.body = { | ||
__type: 'com.amazonaws.dynamodb.v20120810#ResourceNotFoundException', | ||
message: 'Requested resource not found: Table: ' + data.TableName + ' not found', | ||
} | ||
} | ||
return cb(err) | ||
} | ||
db.getTable(data.TableName, function(err, table) { | ||
if (err) return cb(err) | ||
cb(null, {Table: table}) | ||
@@ -17,0 +9,0 @@ }) |
var levelup = require('levelup'), | ||
MemDown = require('memdown'), | ||
sublevel = require('level-sublevel'), | ||
levelUpdate = require('level-update') | ||
Lock = require('lock') | ||
var db = sublevel(levelup('./mydb', {db: function(location){ return new MemDown(location) }})), | ||
tableDb = db.sublevel('table', {valueEncoding: 'json'}) | ||
var db = sublevel(levelup('./mydb', {db: function(location) { return new MemDown(location) }})), | ||
tableDb = db.sublevel('table', {valueEncoding: 'json'}), | ||
itemDb = db.sublevel('item', {valueEncoding: 'json'}) | ||
levelUpdate(tableDb, function(newValue, oldValue) { | ||
if (oldValue) throw new Error('Already exists') | ||
}) | ||
exports.tableDb = tableDb | ||
exports.itemDb = itemDb | ||
exports.getTable = getTable | ||
exports.createTableMs = 1000 | ||
exports.deleteTableMs = 1000 | ||
exports.tableDb = tableDb | ||
tableDb.lock = new Lock() | ||
function getTable(name, cb) { | ||
tableDb.get(name, function(err, table) { | ||
if (err) { | ||
if (err.name == 'NotFoundError') { | ||
err.statusCode = 400 | ||
err.body = { | ||
__type: 'com.amazonaws.dynamodb.v20120810#ResourceNotFoundException', | ||
message: 'Requested resource not found: Table: ' + name + ' not found', | ||
} | ||
} | ||
return cb(err) | ||
} | ||
cb(null, table) | ||
}) | ||
} |
{ | ||
"name": "dynalite", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"description": "A mock implementation of Amazon's DynamoDB", | ||
@@ -31,3 +31,3 @@ "main": "index.js", | ||
"level-sublevel": ">=4.7.0", | ||
"level-update": ">=0.0.5" | ||
"lock": ">=0.0.4" | ||
}, | ||
@@ -34,0 +34,0 @@ "optionalDependencies": { |
@@ -683,2 +683,32 @@ var async = require('async'), | ||
it.skip('should change state to ACTIVE after a period', function(done) { | ||
this.timeout(100000) | ||
var table = { | ||
TableName: 'abc' + Math.random() * 0x100000000, | ||
AttributeDefinitions: [{AttributeName: 'a', AttributeType: 'S'}], | ||
KeySchema: [{KeyType: 'HASH', AttributeName: 'a'}], | ||
ProvisionedThroughput: {ReadCapacityUnits: 1, WriteCapacityUnits: 1}, | ||
} | ||
request(opts(table), function(err, res) { | ||
if (err) return done(err) | ||
res.body.TableDescription.TableStatus.should.equal('CREATING') | ||
function waitUntilActive(done) { | ||
request(helpers.opts('DynamoDB_20120810.DescribeTable', table), function(err, res) { | ||
if (err) return done(err) | ||
if (res.body.Table.TableStatus != 'CREATING') return done(null, res) | ||
setTimeout(waitUntilActive, 1000, done) | ||
}) | ||
} | ||
var start = Date.now() | ||
waitUntilActive(function(err, res) { | ||
if (err) return done(err) | ||
res.body.Table.TableStatus.should.equal('ACTIVE') | ||
//console.log(Date.now() - start) | ||
done() | ||
}) | ||
}) | ||
}) | ||
it.skip('should succeed for indexes', function(done) { | ||
@@ -685,0 +715,0 @@ var table = { |
@@ -12,3 +12,4 @@ var async = require('async'), | ||
assertValidation = helpers.assertValidation.bind(null, target), | ||
assertNotFound = helpers.assertNotFound.bind(null, target) | ||
assertNotFound = helpers.assertNotFound.bind(null, target), | ||
assertInUse = helpers.assertInUse.bind(null, target) | ||
@@ -69,2 +70,62 @@ describe('deleteTable', function() { | ||
it.skip('should return ResourceInUseException if table is being created', function(done) { | ||
var table = { | ||
TableName: 'abc' + Math.random() * 0x100000000, | ||
AttributeDefinitions: [{AttributeName: 'a', AttributeType: 'S'}], | ||
KeySchema: [{KeyType: 'HASH', AttributeName: 'a'}], | ||
ProvisionedThroughput: {ReadCapacityUnits: 1, WriteCapacityUnits: 1}, | ||
} | ||
request(helpers.opts('DynamoDB_20120810.CreateTable', table), function(err) { | ||
if (err) return done(err) | ||
assertInUse({TableName: table.TableName}, | ||
'Attempt to change a resource which is still in use: Table is being created: ' + table.TableName, done) | ||
}) | ||
}) | ||
it.skip('should eventually delete', function(done) { | ||
this.timeout(100000) | ||
var table = { | ||
TableName: 'abc' + Math.random() * 0x100000000, | ||
AttributeDefinitions: [{AttributeName: 'a', AttributeType: 'S'}], | ||
KeySchema: [{KeyType: 'HASH', AttributeName: 'a'}], | ||
ProvisionedThroughput: {ReadCapacityUnits: 1, WriteCapacityUnits: 1}, | ||
} | ||
request(helpers.opts('DynamoDB_20120810.CreateTable', table), function(err, res) { | ||
if (err) return done(err) | ||
function waitUntilActive(done) { | ||
request(helpers.opts('DynamoDB_20120810.DescribeTable', table), function(err, res) { | ||
if (err) return done(err) | ||
if (res.body.Table.TableStatus != 'CREATING') return done(null, res) | ||
setTimeout(waitUntilActive, 1000, done) | ||
}) | ||
} | ||
waitUntilActive(function(err) { | ||
if (err) return done(err) | ||
request(opts(table), function(err, res) { | ||
if (err) return done(err) | ||
res.body.TableDescription.TableStatus.should.equal('DELETING') | ||
function waitUntilDeleted(done) { | ||
request(helpers.opts('DynamoDB_20120810.DescribeTable', table), function(err, res) { | ||
if (err) return done(err) | ||
if (!res.body.Table || res.body.Table.TableStatus != 'DELETING') return done(null, res) | ||
setTimeout(waitUntilDeleted, 1000, done) | ||
}) | ||
} | ||
var start = Date.now() | ||
waitUntilDeleted(function(err, res) { | ||
if (err) return done(err) | ||
res.body.__type.should.equal('com.amazonaws.dynamodb.v20120810#ResourceNotFoundException') | ||
//console.log(Date.now() - start) | ||
done() | ||
}) | ||
}) | ||
}) | ||
}) | ||
}) | ||
}) | ||
@@ -71,0 +132,0 @@ |
@@ -14,2 +14,3 @@ var http = require('http'), | ||
exports.assertNotFound = assertNotFound | ||
exports.assertInUse = assertInUse | ||
@@ -182,2 +183,13 @@ function request(opts, cb) { | ||
function assertInUse(target, data, msg, done) { | ||
request(opts(target, data), function(err, res) { | ||
if (err) return done(err) | ||
res.statusCode.should.equal(400) | ||
res.body.should.eql({ | ||
__type: 'com.amazonaws.dynamodb.v20120810#ResourceInUseException', | ||
message: msg, | ||
}) | ||
done() | ||
}) | ||
} | ||
@@ -275,2 +275,157 @@ var async = require('async'), | ||
it('should return ValidationException for 1 arg to NULL', function(done) { | ||
assertValidation({ | ||
TableName: 'abc', | ||
KeyConditions: {a: {ComparisonOperator: 'NULL', AttributeValueList: [{S: 'a'}]}}}, | ||
'The attempted filter operation is not supported for the provided filter argument count', done) | ||
}) | ||
it('should return ValidationException for 1 arg to NOT_NULL', function(done) { | ||
assertValidation({ | ||
TableName: 'abc', | ||
KeyConditions: {a: {ComparisonOperator: 'NOT_NULL', AttributeValueList: [{S: 'a'}]}}}, | ||
'The attempted filter operation is not supported for the provided filter argument count', done) | ||
}) | ||
it('should return ValidationException for 0 args to NE', function(done) { | ||
assertValidation({ | ||
TableName: 'abc', | ||
KeyConditions: {a: {ComparisonOperator: 'NE'}}}, | ||
'The attempted filter operation is not supported for the provided filter argument count', done) | ||
}) | ||
it('should return ValidationException for 2 args to NE', function(done) { | ||
assertValidation({ | ||
TableName: 'abc', | ||
KeyConditions: {a: {ComparisonOperator: 'NE', AttributeValueList: [{S: 'a'}, {S: 'a'}]}}}, | ||
'The attempted filter operation is not supported for the provided filter argument count', done) | ||
}) | ||
it('should return ValidationException for 0 args to LE', function(done) { | ||
assertValidation({ | ||
TableName: 'abc', | ||
KeyConditions: {a: {ComparisonOperator: 'LE'}}}, | ||
'The attempted filter operation is not supported for the provided filter argument count', done) | ||
}) | ||
it('should return ValidationException for 2 args to LE', function(done) { | ||
assertValidation({ | ||
TableName: 'abc', | ||
KeyConditions: {a: {ComparisonOperator: 'LE', AttributeValueList: [{S: 'a'}, {S: 'a'}]}}}, | ||
'The attempted filter operation is not supported for the provided filter argument count', done) | ||
}) | ||
it('should return ValidationException for 0 args to LT', function(done) { | ||
assertValidation({ | ||
TableName: 'abc', | ||
KeyConditions: {a: {ComparisonOperator: 'LT'}}}, | ||
'The attempted filter operation is not supported for the provided filter argument count', done) | ||
}) | ||
it('should return ValidationException for 2 args to LT', function(done) { | ||
assertValidation({ | ||
TableName: 'abc', | ||
KeyConditions: {a: {ComparisonOperator: 'LT', AttributeValueList: [{S: 'a'}, {S: 'a'}]}}}, | ||
'The attempted filter operation is not supported for the provided filter argument count', done) | ||
}) | ||
it('should return ValidationException for 0 args to GE', function(done) { | ||
assertValidation({ | ||
TableName: 'abc', | ||
KeyConditions: {a: {ComparisonOperator: 'GE'}}}, | ||
'The attempted filter operation is not supported for the provided filter argument count', done) | ||
}) | ||
it('should return ValidationException for 2 args to GE', function(done) { | ||
assertValidation({ | ||
TableName: 'abc', | ||
KeyConditions: {a: {ComparisonOperator: 'GE', AttributeValueList: [{S: 'a'}, {S: 'a'}]}}}, | ||
'The attempted filter operation is not supported for the provided filter argument count', done) | ||
}) | ||
it('should return ValidationException for 0 args to GT', function(done) { | ||
assertValidation({ | ||
TableName: 'abc', | ||
KeyConditions: {a: {ComparisonOperator: 'GT'}}}, | ||
'The attempted filter operation is not supported for the provided filter argument count', done) | ||
}) | ||
it('should return ValidationException for 2 args to GT', function(done) { | ||
assertValidation({ | ||
TableName: 'abc', | ||
KeyConditions: {a: {ComparisonOperator: 'GT', AttributeValueList: [{S: 'a'}, {S: 'a'}]}}}, | ||
'The attempted filter operation is not supported for the provided filter argument count', done) | ||
}) | ||
it('should return ValidationException for 0 args to CONTAINS', function(done) { | ||
assertValidation({ | ||
TableName: 'abc', | ||
KeyConditions: {a: {ComparisonOperator: 'CONTAINS'}}}, | ||
'The attempted filter operation is not supported for the provided filter argument count', done) | ||
}) | ||
it('should return ValidationException for 2 args to CONTAINS', function(done) { | ||
assertValidation({ | ||
TableName: 'abc', | ||
KeyConditions: {a: {ComparisonOperator: 'CONTAINS', AttributeValueList: [{S: 'a'}, {S: 'a'}]}}}, | ||
'The attempted filter operation is not supported for the provided filter argument count', done) | ||
}) | ||
it('should return ValidationException for 0 args to NOT_CONTAINS', function(done) { | ||
assertValidation({ | ||
TableName: 'abc', | ||
KeyConditions: {a: {ComparisonOperator: 'NOT_CONTAINS'}}}, | ||
'The attempted filter operation is not supported for the provided filter argument count', done) | ||
}) | ||
it('should return ValidationException for 2 args to NOT_CONTAINS', function(done) { | ||
assertValidation({ | ||
TableName: 'abc', | ||
KeyConditions: {a: {ComparisonOperator: 'NOT_CONTAINS', AttributeValueList: [{S: 'a'}, {S: 'a'}]}}}, | ||
'The attempted filter operation is not supported for the provided filter argument count', done) | ||
}) | ||
it('should return ValidationException for 0 args to BEGINS_WITH', function(done) { | ||
assertValidation({ | ||
TableName: 'abc', | ||
KeyConditions: {a: {ComparisonOperator: 'BEGINS_WITH'}}}, | ||
'The attempted filter operation is not supported for the provided filter argument count', done) | ||
}) | ||
it('should return ValidationException for 2 args to BEGINS_WITH', function(done) { | ||
assertValidation({ | ||
TableName: 'abc', | ||
KeyConditions: {a: {ComparisonOperator: 'BEGINS_WITH', AttributeValueList: [{S: 'a'}, {S: 'a'}]}}}, | ||
'The attempted filter operation is not supported for the provided filter argument count', done) | ||
}) | ||
it('should return ValidationException for 0 args to IN', function(done) { | ||
assertValidation({ | ||
TableName: 'abc', | ||
KeyConditions: {a: {ComparisonOperator: 'IN'}}}, | ||
'The attempted filter operation is not supported for the provided filter argument count', done) | ||
}) | ||
// TODO: Will have to come back to this one - not sure what the upper bound is | ||
it.skip('should return ValidationException for 3 args to IN', function(done) { | ||
assertValidation({ | ||
TableName: 'abc', | ||
KeyConditions: {a: {ComparisonOperator: 'IN', AttributeValueList: [{S: 'a'}, {S: 'a'}, {S: 'a'}]}}}, | ||
'The attempted filter operation is not supported for the provided filter argument count', done) | ||
}) | ||
it('should return ValidationException for 0 args to BETWEEN', function(done) { | ||
assertValidation({ | ||
TableName: 'abc', | ||
KeyConditions: {a: {ComparisonOperator: 'BETWEEN'}}}, | ||
'The attempted filter operation is not supported for the provided filter argument count', done) | ||
}) | ||
it('should return ValidationException for 3 args to BETWEEN', function(done) { | ||
assertValidation({ | ||
TableName: 'abc', | ||
KeyConditions: {a: {ComparisonOperator: 'BETWEEN', AttributeValueList: [{S: 'a'}, {S: 'a'}, {S: 'a'}]}}}, | ||
'The attempted filter operation is not supported for the provided filter argument count', done) | ||
}) | ||
// Weird - only checks this *after* it finds the table | ||
@@ -277,0 +432,0 @@ it.skip('should return ValidationException for unsupported comparison', function(done) { |
155
test/scan.js
@@ -246,2 +246,157 @@ var async = require('async'), | ||
it('should return ValidationException for 1 arg to NULL', function(done) { | ||
assertValidation({ | ||
TableName: 'abc', | ||
ScanFilter: {a: {ComparisonOperator: 'NULL', AttributeValueList: [{S: 'a'}]}}}, | ||
'The attempted filter operation is not supported for the provided filter argument count', done) | ||
}) | ||
it('should return ValidationException for 1 arg to NOT_NULL', function(done) { | ||
assertValidation({ | ||
TableName: 'abc', | ||
ScanFilter: {a: {ComparisonOperator: 'NOT_NULL', AttributeValueList: [{S: 'a'}]}}}, | ||
'The attempted filter operation is not supported for the provided filter argument count', done) | ||
}) | ||
it('should return ValidationException for 0 args to NE', function(done) { | ||
assertValidation({ | ||
TableName: 'abc', | ||
ScanFilter: {a: {ComparisonOperator: 'NE'}}}, | ||
'The attempted filter operation is not supported for the provided filter argument count', done) | ||
}) | ||
it('should return ValidationException for 2 args to NE', function(done) { | ||
assertValidation({ | ||
TableName: 'abc', | ||
ScanFilter: {a: {ComparisonOperator: 'NE', AttributeValueList: [{S: 'a'}, {S: 'a'}]}}}, | ||
'The attempted filter operation is not supported for the provided filter argument count', done) | ||
}) | ||
it('should return ValidationException for 0 args to LE', function(done) { | ||
assertValidation({ | ||
TableName: 'abc', | ||
ScanFilter: {a: {ComparisonOperator: 'LE'}}}, | ||
'The attempted filter operation is not supported for the provided filter argument count', done) | ||
}) | ||
it('should return ValidationException for 2 args to LE', function(done) { | ||
assertValidation({ | ||
TableName: 'abc', | ||
ScanFilter: {a: {ComparisonOperator: 'LE', AttributeValueList: [{S: 'a'}, {S: 'a'}]}}}, | ||
'The attempted filter operation is not supported for the provided filter argument count', done) | ||
}) | ||
it('should return ValidationException for 0 args to LT', function(done) { | ||
assertValidation({ | ||
TableName: 'abc', | ||
ScanFilter: {a: {ComparisonOperator: 'LT'}}}, | ||
'The attempted filter operation is not supported for the provided filter argument count', done) | ||
}) | ||
it('should return ValidationException for 2 args to LT', function(done) { | ||
assertValidation({ | ||
TableName: 'abc', | ||
ScanFilter: {a: {ComparisonOperator: 'LT', AttributeValueList: [{S: 'a'}, {S: 'a'}]}}}, | ||
'The attempted filter operation is not supported for the provided filter argument count', done) | ||
}) | ||
it('should return ValidationException for 0 args to GE', function(done) { | ||
assertValidation({ | ||
TableName: 'abc', | ||
ScanFilter: {a: {ComparisonOperator: 'GE'}}}, | ||
'The attempted filter operation is not supported for the provided filter argument count', done) | ||
}) | ||
it('should return ValidationException for 2 args to GE', function(done) { | ||
assertValidation({ | ||
TableName: 'abc', | ||
ScanFilter: {a: {ComparisonOperator: 'GE', AttributeValueList: [{S: 'a'}, {S: 'a'}]}}}, | ||
'The attempted filter operation is not supported for the provided filter argument count', done) | ||
}) | ||
it('should return ValidationException for 0 args to GT', function(done) { | ||
assertValidation({ | ||
TableName: 'abc', | ||
ScanFilter: {a: {ComparisonOperator: 'GT'}}}, | ||
'The attempted filter operation is not supported for the provided filter argument count', done) | ||
}) | ||
it('should return ValidationException for 2 args to GT', function(done) { | ||
assertValidation({ | ||
TableName: 'abc', | ||
ScanFilter: {a: {ComparisonOperator: 'GT', AttributeValueList: [{S: 'a'}, {S: 'a'}]}}}, | ||
'The attempted filter operation is not supported for the provided filter argument count', done) | ||
}) | ||
it('should return ValidationException for 0 args to CONTAINS', function(done) { | ||
assertValidation({ | ||
TableName: 'abc', | ||
ScanFilter: {a: {ComparisonOperator: 'CONTAINS'}}}, | ||
'The attempted filter operation is not supported for the provided filter argument count', done) | ||
}) | ||
it('should return ValidationException for 2 args to CONTAINS', function(done) { | ||
assertValidation({ | ||
TableName: 'abc', | ||
ScanFilter: {a: {ComparisonOperator: 'CONTAINS', AttributeValueList: [{S: 'a'}, {S: 'a'}]}}}, | ||
'The attempted filter operation is not supported for the provided filter argument count', done) | ||
}) | ||
it('should return ValidationException for 0 args to NOT_CONTAINS', function(done) { | ||
assertValidation({ | ||
TableName: 'abc', | ||
ScanFilter: {a: {ComparisonOperator: 'NOT_CONTAINS'}}}, | ||
'The attempted filter operation is not supported for the provided filter argument count', done) | ||
}) | ||
it('should return ValidationException for 2 args to NOT_CONTAINS', function(done) { | ||
assertValidation({ | ||
TableName: 'abc', | ||
ScanFilter: {a: {ComparisonOperator: 'NOT_CONTAINS', AttributeValueList: [{S: 'a'}, {S: 'a'}]}}}, | ||
'The attempted filter operation is not supported for the provided filter argument count', done) | ||
}) | ||
it('should return ValidationException for 0 args to BEGINS_WITH', function(done) { | ||
assertValidation({ | ||
TableName: 'abc', | ||
ScanFilter: {a: {ComparisonOperator: 'BEGINS_WITH'}}}, | ||
'The attempted filter operation is not supported for the provided filter argument count', done) | ||
}) | ||
it('should return ValidationException for 2 args to BEGINS_WITH', function(done) { | ||
assertValidation({ | ||
TableName: 'abc', | ||
ScanFilter: {a: {ComparisonOperator: 'BEGINS_WITH', AttributeValueList: [{S: 'a'}, {S: 'a'}]}}}, | ||
'The attempted filter operation is not supported for the provided filter argument count', done) | ||
}) | ||
it('should return ValidationException for 0 args to IN', function(done) { | ||
assertValidation({ | ||
TableName: 'abc', | ||
ScanFilter: {a: {ComparisonOperator: 'IN'}}}, | ||
'The attempted filter operation is not supported for the provided filter argument count', done) | ||
}) | ||
// TODO: Will have to come back to this one - not sure what the upper bound is | ||
it.skip('should return ValidationException for 3 args to IN', function(done) { | ||
assertValidation({ | ||
TableName: 'abc', | ||
ScanFilter: {a: {ComparisonOperator: 'IN', AttributeValueList: [{S: 'a'}, {S: 'a'}, {S: 'a'}]}}}, | ||
'The attempted filter operation is not supported for the provided filter argument count', done) | ||
}) | ||
it('should return ValidationException for 0 args to BETWEEN', function(done) { | ||
assertValidation({ | ||
TableName: 'abc', | ||
ScanFilter: {a: {ComparisonOperator: 'BETWEEN'}}}, | ||
'The attempted filter operation is not supported for the provided filter argument count', done) | ||
}) | ||
it('should return ValidationException for 3 args to BETWEEN', function(done) { | ||
assertValidation({ | ||
TableName: 'abc', | ||
ScanFilter: {a: {ComparisonOperator: 'BETWEEN', AttributeValueList: [{S: 'a'}, {S: 'a'}, {S: 'a'}]}}}, | ||
'The attempted filter operation is not supported for the provided filter argument count', done) | ||
}) | ||
// Weird - only checks this *after* it finds the table | ||
@@ -248,0 +403,0 @@ it.skip('should return ValidationException for unsupported comparison', function(done) { |
@@ -104,3 +104,14 @@ var validateAttributeValue = require('./index').validateAttributeValue | ||
NULL: 0, | ||
NOT_NULL: 0, | ||
EQ: 1, | ||
NE: 1, | ||
LE: 1, | ||
LT: 1, | ||
GE: 1, | ||
GT: 1, | ||
CONTAINS: 1, | ||
NOT_CONTAINS: 1, | ||
BEGINS_WITH: 1, | ||
IN: [1], | ||
BETWEEN: 2, | ||
} | ||
@@ -114,3 +125,4 @@ for (var key in data.KeyConditions) { | ||
} | ||
if (lengths[comparisonOperator] != attrValList.length) | ||
if ((typeof lengths[comparisonOperator] == 'number' && attrValList.length != lengths[comparisonOperator]) || | ||
(attrValList.length < lengths[comparisonOperator][0] || attrValList.length > lengths[comparisonOperator][1])) | ||
return 'The attempted filter operation is not supported for the provided filter argument count' | ||
@@ -117,0 +129,0 @@ } |
@@ -101,3 +101,14 @@ var validateAttributeValue = require('./index').validateAttributeValue | ||
NULL: 0, | ||
NOT_NULL: 0, | ||
EQ: 1, | ||
NE: 1, | ||
LE: 1, | ||
LT: 1, | ||
GE: 1, | ||
GT: 1, | ||
CONTAINS: 1, | ||
NOT_CONTAINS: 1, | ||
BEGINS_WITH: 1, | ||
IN: [1], | ||
BETWEEN: 2, | ||
} | ||
@@ -111,3 +122,4 @@ for (var key in data.ScanFilter) { | ||
} | ||
if (lengths[comparisonOperator] != attrValList.length) | ||
if ((typeof lengths[comparisonOperator] == 'number' && attrValList.length != lengths[comparisonOperator]) || | ||
(attrValList.length < lengths[comparisonOperator][0] || attrValList.length > lengths[comparisonOperator][1])) | ||
return 'The attempted filter operation is not supported for the provided filter argument count' | ||
@@ -114,0 +126,0 @@ } |
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
222216
4674
2
+ Addedlock@>=0.0.4
+ Addedlock@1.1.0(transitive)
- Removedlevel-update@>=0.0.5
- Removedlevel-update@0.1.0(transitive)
- Removedlock@0.0.4(transitive)
- Removedshasum@0.0.2(transitive)