livedb-dynamodb
Advanced tools
Comparing version 0.2.2 to 0.2.3
// Generated by CoffeeScript 1.6.3 | ||
(function() { | ||
var LiveDbDynamoDB, async, castDocToSnapshot, castItemToOp, castOpToDoc, castSnapshotToDoc, decodeValue, docVal, encodeValue, exports, purgeTable, zlib, _, | ||
var LiveDbDynamoDB, async, castDocToSnapshot, castItemToOp, castOpToDoc, castSnapshotToDoc, decodeValue, docVal, encodeValue, exports, purgeTable, r, retry, zlib, _, | ||
__bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }; | ||
@@ -10,2 +10,4 @@ | ||
retry = require('retry'); | ||
_ = require('lodash'); | ||
@@ -17,2 +19,19 @@ | ||
r = function(callback, routine) { | ||
var op; | ||
op = retry.operation({ | ||
retries: 5 | ||
}); | ||
return op.attempt(function(num) { | ||
return routine(function() { | ||
var args; | ||
args = _.toArray(arguments); | ||
if (op.retry(args[0])) { | ||
return; | ||
} | ||
return callback.apply(this, args); | ||
}); | ||
}); | ||
}; | ||
LiveDbDynamoDB = (function() { | ||
@@ -33,29 +52,33 @@ function LiveDbDynamoDB(dynamodb, s3, options) { | ||
var _this = this; | ||
return this.dynamodb.getItem({ | ||
TableName: cName, | ||
Key: { | ||
id: { | ||
S: docName | ||
} | ||
}, | ||
ConsistentRead: true | ||
}, function(err, data) { | ||
if (!data) { | ||
return callback(err, null); | ||
} else { | ||
if (data.Item != null) { | ||
return _this.s3.getObject({ | ||
Bucket: _this.bucketName, | ||
Key: "" + cName + "/" + docName | ||
}, function(err, object) { | ||
if (!object) { | ||
return callback(err, null); | ||
} else { | ||
return castDocToSnapshot(data.Item, object.Body, callback); | ||
} | ||
}); | ||
return r(callback, function(retry) { | ||
return _this.dynamodb.getItem({ | ||
TableName: cName, | ||
Key: { | ||
id: { | ||
S: docName | ||
} | ||
}, | ||
ConsistentRead: true | ||
}, function(err, data) { | ||
if (!data) { | ||
return retry(err, null); | ||
} else { | ||
return callback(null, null); | ||
if (data.Item != null) { | ||
return r(callback, function(retry) { | ||
return _this.s3.getObject({ | ||
Bucket: _this.bucketName, | ||
Key: "" + cName + "/" + docName | ||
}, function(err, object) { | ||
if (!object) { | ||
return retry(err, null); | ||
} else { | ||
return castDocToSnapshot(data.Item, object.Body, callback); | ||
} | ||
}); | ||
}); | ||
} else { | ||
return callback(null, null); | ||
} | ||
} | ||
} | ||
}); | ||
}); | ||
@@ -89,13 +112,15 @@ }; | ||
return function(cb) { | ||
return _this.s3.getObject({ | ||
Bucket: _this.bucketName, | ||
Key: "" + cName + "/" + docName | ||
}, function(err, data) { | ||
if (err && err.code !== 'NotFound') { | ||
return cb(err); | ||
} | ||
if ((data != null ? data.Body : void 0) != null) { | ||
docData[cName][docName] = data.Body; | ||
} | ||
return cb(null); | ||
return r(cb, function(retry) { | ||
return _this.s3.getObject({ | ||
Bucket: _this.bucketName, | ||
Key: "" + cName + "/" + docName | ||
}, function(err, data) { | ||
if (err && err.code !== 'NotFound') { | ||
return retry(err); | ||
} | ||
if ((data != null ? data.Body : void 0) != null) { | ||
docData[cName][docName] = data.Body; | ||
} | ||
return cb(null); | ||
}); | ||
}); | ||
@@ -110,23 +135,25 @@ }; | ||
} | ||
return _this.dynamodb.batchGetItem({ | ||
RequestItems: requestItems | ||
}, function(err, data) { | ||
if (err) { | ||
return callback(err); | ||
} | ||
return async.each(_.keys(data.Responses), (function(cName, nextMap) { | ||
return async.map(data.Responses[cName], (function(item, cb) { | ||
docName = docVal(item, "id"); | ||
return castDocToSnapshot(item, docData[cName][docName], cb); | ||
}), function(err, snapshots) { | ||
var snapshot, _j, _len1; | ||
for (_j = 0, _len1 = snapshots.length; _j < _len1; _j++) { | ||
snapshot = snapshots[_j]; | ||
results[cName][snapshot.docName] = snapshot; | ||
} | ||
return nextMap(err); | ||
}); | ||
}), (function(err) { | ||
return callback(err, results); | ||
})); | ||
return r(callback, function(retry) { | ||
return _this.dynamodb.batchGetItem({ | ||
RequestItems: requestItems | ||
}, function(err, data) { | ||
if (err) { | ||
return retry(err); | ||
} | ||
return async.each(_.keys(data.Responses), (function(cName, nextMap) { | ||
return async.map(data.Responses[cName], (function(item, cb) { | ||
docName = docVal(item, "id"); | ||
return castDocToSnapshot(item, docData[cName][docName], cb); | ||
}), function(err, snapshots) { | ||
var snapshot, _j, _len1; | ||
for (_j = 0, _len1 = snapshots.length; _j < _len1; _j++) { | ||
snapshot = snapshots[_j]; | ||
results[cName][snapshot.docName] = snapshot; | ||
} | ||
return nextMap(err); | ||
}); | ||
}), (function(err) { | ||
return callback(err, results); | ||
})); | ||
}); | ||
}); | ||
@@ -144,12 +171,26 @@ }); | ||
(function(cb) { | ||
return _this.dynamodb.putItem({ | ||
TableName: cName, | ||
Item: doc.item | ||
}, cb); | ||
return r(cb, function(retry) { | ||
return _this.dynamodb.putItem({ | ||
TableName: cName, | ||
Item: doc.item | ||
}, function(err, data) { | ||
if (err) { | ||
return retry(err); | ||
} | ||
return cb(err, data); | ||
}); | ||
}); | ||
}), (function(cb) { | ||
return _this.s3.putObject({ | ||
Bucket: _this.bucketName, | ||
Key: "" + cName + "/" + docName, | ||
Body: doc.object | ||
}, cb); | ||
return r(cb, function(retry) { | ||
return _this.s3.putObject({ | ||
Bucket: _this.bucketName, | ||
Key: "" + cName + "/" + docName, | ||
Body: doc.object | ||
}, function(err, data) { | ||
if (err) { | ||
return retry(err); | ||
} | ||
return cb(err, data); | ||
}); | ||
}); | ||
}) | ||
@@ -169,24 +210,33 @@ ], callback); | ||
(function(cb) { | ||
return _this.dynamodb.putItem({ | ||
TableName: _this.getOplogCollectionName(cName), | ||
Item: doc.item, | ||
Expected: { | ||
op_id: { | ||
Exists: false | ||
return r(cb, function(retry) { | ||
return _this.dynamodb.putItem({ | ||
TableName: _this.getOplogCollectionName(cName), | ||
Item: doc.item, | ||
Expected: { | ||
op_id: { | ||
Exists: false | ||
} | ||
} | ||
} | ||
}, function(err, data) { | ||
if (!err || ((err.code != null) && err.code === 'ConditionalCheckFailedException')) { | ||
return cb(null); | ||
} else { | ||
return cb(err); | ||
} | ||
}, function(err, data) { | ||
if (!err || ((err.code != null) && err.code === 'ConditionalCheckFailedException')) { | ||
return cb(null); | ||
} else { | ||
return retry(err); | ||
} | ||
}); | ||
}); | ||
}), (function(cb) { | ||
if (doc.object) { | ||
return _this.s3.putObject({ | ||
Bucket: _this.bucketName, | ||
Key: "" + (_this.getOplogCollectionName(cName)) + "/" + doc.item.op_id.S, | ||
Body: doc.object | ||
}, cb); | ||
return r(cb, function(retry) { | ||
return _this.s3.putObject({ | ||
Bucket: _this.bucketName, | ||
Key: "" + (_this.getOplogCollectionName(cName)) + "/" + doc.item.op_id.S, | ||
Body: doc.object | ||
}, function(err, data) { | ||
if (err) { | ||
return retry(err); | ||
} | ||
return cb(err, data); | ||
}); | ||
}); | ||
} else { | ||
@@ -193,0 +243,0 @@ return cb(null); |
{ | ||
"name": "livedb-dynamodb", | ||
"version": "0.2.2", | ||
"version": "0.2.3", | ||
"description": "DynamoDB database adapter for livedb", | ||
@@ -11,3 +11,4 @@ "main": "lib/dynamodb.js", | ||
"optimist": "~0.6.0", | ||
"aws-sdk": "git://github.com/aws/aws-sdk-js.git#master" | ||
"aws-sdk": "git://github.com/aws/aws-sdk-js.git#master", | ||
"retry": "~0.6.0" | ||
}, | ||
@@ -14,0 +15,0 @@ "devDependencies": { |
Sorry, the diff of this file is not supported yet
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
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
34026
619
6
+ Addedretry@~0.6.0
+ Addedretry@0.6.1(transitive)