@aws/dynamodb-batch-iterator
Advanced tools
Comparing version 0.3.0 to 0.3.1
@@ -6,2 +6,3 @@ import { BatchGetOptions } from './BatchGetOptions'; | ||
import DynamoDB = require('aws-sdk/clients/dynamodb'); | ||
export declare const MAX_READ_BATCH_SIZE = 100; | ||
/** | ||
@@ -8,0 +9,0 @@ * Retrieves items from DynamoDB in batches of 100 or fewer via one or more |
@@ -5,3 +5,3 @@ "use strict"; | ||
var BatchOperation_1 = require("./BatchOperation"); | ||
var MAX_READ_BATCH_SIZE = 100; | ||
exports.MAX_READ_BATCH_SIZE = 100; | ||
/** | ||
@@ -29,3 +29,3 @@ * Retrieves items from DynamoDB in batches of 100 or fewer via one or more | ||
var _this = _super.call(this, client, items) || this; | ||
_this.batchSize = MAX_READ_BATCH_SIZE; | ||
_this.batchSize = exports.MAX_READ_BATCH_SIZE; | ||
_this.consistentRead = ConsistentRead; | ||
@@ -32,0 +32,0 @@ _this.options = PerTableOptions; |
@@ -156,14 +156,20 @@ "use strict"; | ||
return tslib_1.__awaiter(this, void 0, void 0, function () { | ||
var toProcess, _a; | ||
return tslib_1.__generator(this, function (_b) { | ||
switch (_b.label) { | ||
var toProcess, _a, _b; | ||
return tslib_1.__generator(this, function (_c) { | ||
switch (_c.label) { | ||
case 0: | ||
if (!(!this.sourceDone && | ||
this.toSend.length < this.batchSize)) return [3 /*break*/, 2]; | ||
return [4 /*yield*/, Promise.race([ | ||
this.sourceNext, | ||
Promise.race(this.throttled) | ||
])]; | ||
case 1: | ||
toProcess = _b.sent(); | ||
this.toSend.length < this.batchSize)) return [3 /*break*/, 4]; | ||
if (!isIteratorResult(this.sourceNext)) return [3 /*break*/, 1]; | ||
_a = this.sourceNext; | ||
return [3 /*break*/, 3]; | ||
case 1: return [4 /*yield*/, Promise.race([ | ||
this.sourceNext, | ||
Promise.race(this.throttled) | ||
])]; | ||
case 2: | ||
_a = _c.sent(); | ||
_c.label = 3; | ||
case 3: | ||
toProcess = _a; | ||
if (isIteratorResult(toProcess)) { | ||
@@ -180,16 +186,16 @@ this.sourceDone = toProcess.done; | ||
return [3 /*break*/, 0]; | ||
case 2: | ||
if (!(this.toSend.length < this.batchSize && this.throttled.size > 0)) return [3 /*break*/, 4]; | ||
_a = this.enqueueThrottled; | ||
case 4: | ||
if (!(this.toSend.length < this.batchSize && this.throttled.size > 0)) return [3 /*break*/, 6]; | ||
_b = this.enqueueThrottled; | ||
return [4 /*yield*/, Promise.race(this.throttled)]; | ||
case 3: | ||
_a.apply(this, [_b.sent()]); | ||
return [3 /*break*/, 2]; | ||
case 4: | ||
if (!(this.toSend.length > 0)) return [3 /*break*/, 6]; | ||
case 5: | ||
_b.apply(this, [_c.sent()]); | ||
return [3 /*break*/, 4]; | ||
case 6: | ||
if (!(this.toSend.length > 0)) return [3 /*break*/, 8]; | ||
return [4 /*yield*/, this.doBatchRequest()]; | ||
case 5: | ||
_b.sent(); | ||
_b.label = 6; | ||
case 6: return [2 /*return*/]; | ||
case 7: | ||
_c.sent(); | ||
_c.label = 8; | ||
case 8: return [2 /*return*/]; | ||
} | ||
@@ -196,0 +202,0 @@ }); |
import { BatchOperation } from './BatchOperation'; | ||
import { WriteRequest } from './types'; | ||
export declare const MAX_WRITE_BATCH_SIZE = 25; | ||
/** | ||
@@ -17,4 +18,4 @@ * Puts or deletes items from DynamoDB in batches of 25 or fewer via one or more | ||
export declare class BatchWrite extends BatchOperation<WriteRequest> { | ||
readonly batchSize: number; | ||
protected readonly batchSize: number; | ||
protected doBatchRequest(): Promise<void>; | ||
} |
@@ -6,3 +6,3 @@ "use strict"; | ||
var itemIdentifier_1 = require("./itemIdentifier"); | ||
var MAX_WRITE_BATCH_SIZE = 25; | ||
exports.MAX_WRITE_BATCH_SIZE = 25; | ||
/** | ||
@@ -25,3 +25,3 @@ * Puts or deletes items from DynamoDB in batches of 25 or fewer via one or more | ||
var _this = _super !== null && _super.apply(this, arguments) || this; | ||
_this.batchSize = MAX_WRITE_BATCH_SIZE; | ||
_this.batchSize = exports.MAX_WRITE_BATCH_SIZE; | ||
return _this; | ||
@@ -31,5 +31,5 @@ } | ||
return tslib_1.__awaiter(this, void 0, void 0, function () { | ||
var inFlight, operationInput, batchSize, _a, tableName, marshalled, _b, UnprocessedItems, unprocessedTables, _loop_1, this_1, _c, _d, table, processedTables, inFlight_1, inFlight_1_1, _e, tableName, marshalled, processedTables_1, processedTables_1_1, tableName, e_1, _f, e_2, _g, e_3, _h; | ||
return tslib_1.__generator(this, function (_j) { | ||
switch (_j.label) { | ||
var inFlight, operationInput, batchSize, _a, tableName, marshalled, _b, UnprocessedItems, unprocessedTables, _c, _d, table, unprocessed, _e, _f, item, identifier, i, _g, tableName, attributes, processedTables, inFlight_1, inFlight_1_1, _h, tableName, marshalled, processedTables_1, processedTables_1_1, tableName, e_1, _j, e_2, _k, e_3, _l, e_4, _m; | ||
return tslib_1.__generator(this, function (_o) { | ||
switch (_o.label) { | ||
case 0: | ||
@@ -52,39 +52,33 @@ inFlight = []; | ||
case 1: | ||
_b = (_j.sent()).UnprocessedItems, UnprocessedItems = _b === void 0 ? {} : _b; | ||
_b = (_o.sent()).UnprocessedItems, UnprocessedItems = _b === void 0 ? {} : _b; | ||
unprocessedTables = new Set(); | ||
_loop_1 = function (table) { | ||
unprocessedTables.add(table); | ||
var unprocessed = []; | ||
var _loop_2 = function (item) { | ||
if (item.DeleteRequest || item.PutRequest) { | ||
unprocessed.push(item); | ||
var identifier_1 = itemIdentifier_1.itemIdentifier(table, item); | ||
inFlight.filter(function (_a) { | ||
var _b = tslib_1.__read(_a, 2), tableName = _b[0], attributes = _b[1]; | ||
return tableName !== table || | ||
itemIdentifier_1.itemIdentifier(tableName, attributes) !== identifier_1; | ||
}); | ||
} | ||
}; | ||
try { | ||
for (var _a = tslib_1.__values(UnprocessedItems[table]), _b = _a.next(); !_b.done; _b = _a.next()) { | ||
var item = _b.value; | ||
_loop_2(item); | ||
} | ||
} | ||
catch (e_4_1) { e_4 = { error: e_4_1 }; } | ||
finally { | ||
try { | ||
if (_b && !_b.done && (_c = _a.return)) _c.call(_a); | ||
} | ||
finally { if (e_4) throw e_4.error; } | ||
} | ||
this_1.handleThrottled(table, unprocessed); | ||
var e_4, _c; | ||
}; | ||
this_1 = this; | ||
try { | ||
for (_c = tslib_1.__values(Object.keys(UnprocessedItems)), _d = _c.next(); !_d.done; _d = _c.next()) { | ||
table = _d.value; | ||
_loop_1(table); | ||
unprocessedTables.add(table); | ||
unprocessed = []; | ||
try { | ||
for (_e = tslib_1.__values(UnprocessedItems[table]), _f = _e.next(); !_f.done; _f = _e.next()) { | ||
item = _f.value; | ||
if (item.DeleteRequest || item.PutRequest) { | ||
unprocessed.push(item); | ||
identifier = itemIdentifier_1.itemIdentifier(table, item); | ||
for (i = inFlight.length - 1; i >= 0; i--) { | ||
_g = tslib_1.__read(inFlight[i], 2), tableName = _g[0], attributes = _g[1]; | ||
if (tableName === table && | ||
itemIdentifier_1.itemIdentifier(tableName, attributes) === identifier) { | ||
inFlight.splice(i, 1); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
catch (e_2_1) { e_2 = { error: e_2_1 }; } | ||
finally { | ||
try { | ||
if (_f && !_f.done && (_k = _e.return)) _k.call(_e); | ||
} | ||
finally { if (e_2) throw e_2.error; } | ||
} | ||
this.handleThrottled(table, unprocessed); | ||
} | ||
@@ -95,3 +89,3 @@ } | ||
try { | ||
if (_d && !_d.done && (_f = _c.return)) _f.call(_c); | ||
if (_d && !_d.done && (_j = _c.return)) _j.call(_c); | ||
} | ||
@@ -104,3 +98,3 @@ finally { if (e_1) throw e_1.error; } | ||
for (inFlight_1 = tslib_1.__values(inFlight), inFlight_1_1 = inFlight_1.next(); !inFlight_1_1.done; inFlight_1_1 = inFlight_1.next()) { | ||
_e = tslib_1.__read(inFlight_1_1.value, 2), tableName = _e[0], marshalled = _e[1]; | ||
_h = tslib_1.__read(inFlight_1_1.value, 2), tableName = _h[0], marshalled = _h[1]; | ||
processedTables.add(tableName); | ||
@@ -110,8 +104,8 @@ this.pending.push([tableName, marshalled]); | ||
} | ||
catch (e_2_1) { e_2 = { error: e_2_1 }; } | ||
catch (e_3_1) { e_3 = { error: e_3_1 }; } | ||
finally { | ||
try { | ||
if (inFlight_1_1 && !inFlight_1_1.done && (_g = inFlight_1.return)) _g.call(inFlight_1); | ||
if (inFlight_1_1 && !inFlight_1_1.done && (_l = inFlight_1.return)) _l.call(inFlight_1); | ||
} | ||
finally { if (e_2) throw e_2.error; } | ||
finally { if (e_3) throw e_3.error; } | ||
} | ||
@@ -125,8 +119,8 @@ try { | ||
} | ||
catch (e_3_1) { e_3 = { error: e_3_1 }; } | ||
catch (e_4_1) { e_4 = { error: e_4_1 }; } | ||
finally { | ||
try { | ||
if (processedTables_1_1 && !processedTables_1_1.done && (_h = processedTables_1.return)) _h.call(processedTables_1); | ||
if (processedTables_1_1 && !processedTables_1_1.done && (_m = processedTables_1.return)) _m.call(processedTables_1); | ||
} | ||
finally { if (e_3) throw e_3.error; } | ||
finally { if (e_4) throw e_4.error; } | ||
} | ||
@@ -133,0 +127,0 @@ return [2 /*return*/]; |
{ | ||
"name": "@aws/dynamodb-batch-iterator", | ||
"version": "0.3.0", | ||
"version": "0.3.1", | ||
"description": "Abstraction for DynamoDB batch reads and writes for that handles batch splitting and partial retries with exponential backoff", | ||
@@ -5,0 +5,0 @@ "main": "./build/index.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
65987
29
775