aws-dynamodb-data-mapper
Advanced tools
Comparing version 0.7.3-pull-request-167-3 to 0.7.3-pull-request-167-4
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var marshallStartKey_1 = require("./marshallStartKey"); | ||
var protocols_1 = require("./protocols"); | ||
var dynamodb_data_marshaller_1 = require("@aws/dynamodb-data-marshaller"); | ||
var dynamodb_expressions_1 = require("@aws/dynamodb-expressions"); | ||
const marshallStartKey_1 = require("./marshallStartKey"); | ||
const protocols_1 = require("./protocols"); | ||
const dynamodb_data_marshaller_1 = require("@aws/dynamodb-data-marshaller"); | ||
const dynamodb_expressions_1 = require("@aws/dynamodb-expressions"); | ||
/** | ||
* @internal | ||
*/ | ||
function buildScanInput(valueConstructor, options) { | ||
if (options === void 0) { options = {}; } | ||
var filter = options.filter, indexName = options.indexName, pageSize = options.pageSize, projection = options.projection, readConsistency = options.readConsistency, segment = options.segment, startKey = options.startKey, prefix = options.tableNamePrefix, totalSegments = options.totalSegments; | ||
var req = { | ||
function buildScanInput(valueConstructor, options = {}) { | ||
const { filter, indexName, pageSize, projection, readConsistency, segment, startKey, tableNamePrefix: prefix, totalSegments, } = options; | ||
const req = { | ||
TableName: protocols_1.getTableName(valueConstructor.prototype, prefix), | ||
@@ -23,4 +22,4 @@ Limit: pageSize, | ||
} | ||
var schema = protocols_1.getSchema(valueConstructor.prototype); | ||
var attributes = new dynamodb_expressions_1.ExpressionAttributes(); | ||
const schema = protocols_1.getSchema(valueConstructor.prototype); | ||
const attributes = new dynamodb_expressions_1.ExpressionAttributes(); | ||
if (filter) { | ||
@@ -27,0 +26,0 @@ req.FilterExpression = dynamodb_data_marshaller_1.marshallConditionExpression(filter, schema, attributes).expression; |
"use strict"; | ||
var _a; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var tslib_1 = require("tslib"); | ||
var DataMapper_1 = require("./DataMapper"); | ||
var ItemNotFoundException_1 = require("./ItemNotFoundException"); | ||
var protocols_1 = require("./protocols"); | ||
var os_1 = require("os"); | ||
var process_1 = require("process"); | ||
var DynamoDB = require("aws-sdk/clients/dynamodb"); | ||
var dynamodb_expressions_1 = require("@aws/dynamodb-expressions"); | ||
var nestedDocumentDef = { | ||
const DataMapper_1 = require("./DataMapper"); | ||
const ItemNotFoundException_1 = require("./ItemNotFoundException"); | ||
const protocols_1 = require("./protocols"); | ||
const os_1 = require("os"); | ||
const process_1 = require("process"); | ||
const DynamoDB = require("aws-sdk/clients/dynamodb"); | ||
const dynamodb_expressions_1 = require("@aws/dynamodb-expressions"); | ||
const nestedDocumentDef = { | ||
type: 'Document', | ||
@@ -19,5 +17,5 @@ members: { | ||
nestedDocumentDef.members.recursive = nestedDocumentDef; | ||
var _b = tslib_1.__read(process_1.hrtime(), 2), seconds = _b[0], nanoseconds = _b[1]; | ||
var TableName = "mapper-integ-" + seconds + "-" + nanoseconds + "-" + os_1.hostname(); | ||
var schema = { | ||
const [seconds, nanoseconds] = process_1.hrtime(); | ||
const TableName = `mapper-integ-${seconds}-${nanoseconds}-${os_1.hostname()}`; | ||
const schema = { | ||
key: { | ||
@@ -39,17 +37,14 @@ type: 'Number', | ||
}; | ||
var TestRecord = /** @class */ (function () { | ||
function TestRecord() { | ||
} | ||
return TestRecord; | ||
}()); | ||
Object.defineProperties(TestRecord.prototype, (_a = {}, | ||
_a[protocols_1.DynamoDbSchema] = { value: schema }, | ||
_a[protocols_1.DynamoDbTable] = { value: TableName }, | ||
_a)); | ||
describe('DataMapper', function () { | ||
var idx = 0; | ||
var ddbClient = new DynamoDB(); | ||
var mapper = new DataMapper_1.DataMapper({ client: ddbClient }); | ||
class TestRecord { | ||
} | ||
Object.defineProperties(TestRecord.prototype, { | ||
[protocols_1.DynamoDbSchema]: { value: schema }, | ||
[protocols_1.DynamoDbTable]: { value: TableName }, | ||
}); | ||
describe('DataMapper', () => { | ||
let idx = 0; | ||
const ddbClient = new DynamoDB(); | ||
const mapper = new DataMapper_1.DataMapper({ client: ddbClient }); | ||
jest.setTimeout(60000); | ||
beforeAll(function () { | ||
beforeAll(() => { | ||
return mapper.ensureTableExists(TestRecord, { | ||
@@ -60,317 +55,133 @@ readCapacityUnits: 10, | ||
}); | ||
afterAll(function () { | ||
afterAll(() => { | ||
return mapper.ensureTableNotExists(TestRecord); | ||
}); | ||
it('should save and load objects', function () { return tslib_1.__awaiter(void 0, void 0, void 0, function () { | ||
var key, mapper, timestamp, item, _a, _b; | ||
return tslib_1.__generator(this, function (_c) { | ||
switch (_c.label) { | ||
case 0: | ||
key = idx++; | ||
mapper = new DataMapper_1.DataMapper({ client: ddbClient }); | ||
timestamp = new Date(); | ||
// subsecond precision will not survive the trip through the serializer, | ||
// as DynamoDB's ttl fields use unix epoch (second precision) timestamps | ||
timestamp.setMilliseconds(0); | ||
item = new TestRecord(); | ||
item.key = key; | ||
item.timestamp = timestamp; | ||
item.data = { | ||
recursive: { | ||
recursive: { | ||
recursive: { | ||
foo: '', | ||
}, | ||
}, | ||
}, | ||
}; | ||
_a = expect; | ||
return [4 /*yield*/, mapper.put(item)]; | ||
case 1: | ||
_a.apply(void 0, [_c.sent()]).toEqual(item); | ||
_b = expect; | ||
return [4 /*yield*/, mapper.get(item, { readConsistency: 'strong' })]; | ||
case 2: | ||
_b.apply(void 0, [_c.sent()]) | ||
.toEqual(item); | ||
return [2 /*return*/]; | ||
} | ||
}); | ||
}); }); | ||
it('should delete objects', function () { return tslib_1.__awaiter(void 0, void 0, void 0, function () { | ||
var key, mapper, timestamp, item; | ||
return tslib_1.__generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
key = idx++; | ||
mapper = new DataMapper_1.DataMapper({ client: ddbClient }); | ||
timestamp = new Date(); | ||
// subsecond precision will not survive the trip through the serializer, | ||
// as DynamoDB's ttl fields use unix epoch (second precision) timestamps | ||
timestamp.setMilliseconds(0); | ||
item = new TestRecord(); | ||
item.key = key; | ||
item.timestamp = timestamp; | ||
item.data = { | ||
recursive: { | ||
recursive: { | ||
recursive: { | ||
foo: '', | ||
}, | ||
}, | ||
}, | ||
}; | ||
return [4 /*yield*/, mapper.put(item)]; | ||
case 1: | ||
_a.sent(); | ||
return [4 /*yield*/, expect(mapper.get(item, { readConsistency: 'strong' })).resolves]; | ||
case 2: | ||
_a.sent(); | ||
return [4 /*yield*/, mapper.delete(item)]; | ||
case 3: | ||
_a.sent(); | ||
return [4 /*yield*/, expect(mapper.get(item, { readConsistency: 'strong' })) | ||
.rejects | ||
.toMatchObject(new ItemNotFoundException_1.ItemNotFoundException({ | ||
TableName: TableName, | ||
ConsistentRead: true, | ||
Key: { testIndex: { N: key.toString(10) } } | ||
}))]; | ||
case 4: | ||
_a.sent(); | ||
return [2 /*return*/]; | ||
} | ||
}); | ||
}); }); | ||
it('should scan objects', function () { return tslib_1.__awaiter(void 0, void 0, void 0, function () { | ||
var keys, mapper, scanIdentifier, items, i, item, _a, _b, _1, e_1_1, results, _c, _d, element, e_2_1; | ||
var e_1, _e, e_2, _f; | ||
return tslib_1.__generator(this, function (_g) { | ||
switch (_g.label) { | ||
case 0: | ||
keys = []; | ||
mapper = new DataMapper_1.DataMapper({ client: ddbClient }); | ||
scanIdentifier = Date.now(); | ||
items = []; | ||
for (i = 0; i < 30; i++) { | ||
item = new TestRecord(); | ||
item.key = idx++; | ||
item.tuple = [item.key % 2 === 0, 'string']; | ||
item.scanIdentifier = scanIdentifier; | ||
keys.push(item.key); | ||
items.push(item); | ||
} | ||
_g.label = 1; | ||
case 1: | ||
_g.trys.push([1, 6, 7, 12]); | ||
_a = tslib_1.__asyncValues(mapper.batchPut(items)); | ||
_g.label = 2; | ||
case 2: return [4 /*yield*/, _a.next()]; | ||
case 3: | ||
if (!(_b = _g.sent(), !_b.done)) return [3 /*break*/, 5]; | ||
_1 = _b.value; | ||
_g.label = 4; | ||
case 4: return [3 /*break*/, 2]; | ||
case 5: return [3 /*break*/, 12]; | ||
case 6: | ||
e_1_1 = _g.sent(); | ||
e_1 = { error: e_1_1 }; | ||
return [3 /*break*/, 12]; | ||
case 7: | ||
_g.trys.push([7, , 10, 11]); | ||
if (!(_b && !_b.done && (_e = _a.return))) return [3 /*break*/, 9]; | ||
return [4 /*yield*/, _e.call(_a)]; | ||
case 8: | ||
_g.sent(); | ||
_g.label = 9; | ||
case 9: return [3 /*break*/, 11]; | ||
case 10: | ||
if (e_1) throw e_1.error; | ||
return [7 /*endfinally*/]; | ||
case 11: return [7 /*endfinally*/]; | ||
case 12: | ||
results = []; | ||
_g.label = 13; | ||
case 13: | ||
_g.trys.push([13, 18, 19, 24]); | ||
_c = tslib_1.__asyncValues(mapper.scan(TestRecord, { | ||
readConsistency: 'strong', | ||
filter: tslib_1.__assign(tslib_1.__assign({}, dynamodb_expressions_1.equals(scanIdentifier)), { subject: 'scanIdentifier' }), | ||
})); | ||
_g.label = 14; | ||
case 14: return [4 /*yield*/, _c.next()]; | ||
case 15: | ||
if (!(_d = _g.sent(), !_d.done)) return [3 /*break*/, 17]; | ||
element = _d.value; | ||
results.push(element); | ||
_g.label = 16; | ||
case 16: return [3 /*break*/, 14]; | ||
case 17: return [3 /*break*/, 24]; | ||
case 18: | ||
e_2_1 = _g.sent(); | ||
e_2 = { error: e_2_1 }; | ||
return [3 /*break*/, 24]; | ||
case 19: | ||
_g.trys.push([19, , 22, 23]); | ||
if (!(_d && !_d.done && (_f = _c.return))) return [3 /*break*/, 21]; | ||
return [4 /*yield*/, _f.call(_c)]; | ||
case 20: | ||
_g.sent(); | ||
_g.label = 21; | ||
case 21: return [3 /*break*/, 23]; | ||
case 22: | ||
if (e_2) throw e_2.error; | ||
return [7 /*endfinally*/]; | ||
case 23: return [7 /*endfinally*/]; | ||
case 24: | ||
expect(results.sort(function (a, b) { return a.key - b.key; })).toEqual(keys.map(function (key) { | ||
var record = new TestRecord(); | ||
record.key = key; | ||
record.scanIdentifier = scanIdentifier; | ||
record.tuple = [key % 2 === 0, 'string']; | ||
return record; | ||
})); | ||
return [2 /*return*/]; | ||
} | ||
}); | ||
}); }); | ||
it('should scan objects in parallel', function () { return tslib_1.__awaiter(void 0, void 0, void 0, function () { | ||
var keys, mapper, scanIdentifier, items, i, item, _a, _b, _2, e_3_1, results, _c, _d, element, e_4_1; | ||
var e_3, _e, e_4, _f; | ||
return tslib_1.__generator(this, function (_g) { | ||
switch (_g.label) { | ||
case 0: | ||
keys = []; | ||
mapper = new DataMapper_1.DataMapper({ client: ddbClient }); | ||
scanIdentifier = Date.now(); | ||
items = []; | ||
for (i = 0; i < 10; i++) { | ||
item = new TestRecord(); | ||
item.key = idx++; | ||
item.tuple = [item.key % 2 === 0, 'string']; | ||
item.scanIdentifier = scanIdentifier; | ||
keys.push(item.key); | ||
items.push(item); | ||
} | ||
_g.label = 1; | ||
case 1: | ||
_g.trys.push([1, 6, 7, 12]); | ||
_a = tslib_1.__asyncValues(mapper.batchPut(items)); | ||
_g.label = 2; | ||
case 2: return [4 /*yield*/, _a.next()]; | ||
case 3: | ||
if (!(_b = _g.sent(), !_b.done)) return [3 /*break*/, 5]; | ||
_2 = _b.value; | ||
_g.label = 4; | ||
case 4: return [3 /*break*/, 2]; | ||
case 5: return [3 /*break*/, 12]; | ||
case 6: | ||
e_3_1 = _g.sent(); | ||
e_3 = { error: e_3_1 }; | ||
return [3 /*break*/, 12]; | ||
case 7: | ||
_g.trys.push([7, , 10, 11]); | ||
if (!(_b && !_b.done && (_e = _a.return))) return [3 /*break*/, 9]; | ||
return [4 /*yield*/, _e.call(_a)]; | ||
case 8: | ||
_g.sent(); | ||
_g.label = 9; | ||
case 9: return [3 /*break*/, 11]; | ||
case 10: | ||
if (e_3) throw e_3.error; | ||
return [7 /*endfinally*/]; | ||
case 11: return [7 /*endfinally*/]; | ||
case 12: | ||
results = []; | ||
_g.label = 13; | ||
case 13: | ||
_g.trys.push([13, 18, 19, 24]); | ||
_c = tslib_1.__asyncValues(mapper.parallelScan(TestRecord, 4, { | ||
readConsistency: 'strong', | ||
filter: tslib_1.__assign(tslib_1.__assign({}, dynamodb_expressions_1.equals(scanIdentifier)), { subject: 'scanIdentifier' }), | ||
})); | ||
_g.label = 14; | ||
case 14: return [4 /*yield*/, _c.next()]; | ||
case 15: | ||
if (!(_d = _g.sent(), !_d.done)) return [3 /*break*/, 17]; | ||
element = _d.value; | ||
results.push(element); | ||
_g.label = 16; | ||
case 16: return [3 /*break*/, 14]; | ||
case 17: return [3 /*break*/, 24]; | ||
case 18: | ||
e_4_1 = _g.sent(); | ||
e_4 = { error: e_4_1 }; | ||
return [3 /*break*/, 24]; | ||
case 19: | ||
_g.trys.push([19, , 22, 23]); | ||
if (!(_d && !_d.done && (_f = _c.return))) return [3 /*break*/, 21]; | ||
return [4 /*yield*/, _f.call(_c)]; | ||
case 20: | ||
_g.sent(); | ||
_g.label = 21; | ||
case 21: return [3 /*break*/, 23]; | ||
case 22: | ||
if (e_4) throw e_4.error; | ||
return [7 /*endfinally*/]; | ||
case 23: return [7 /*endfinally*/]; | ||
case 24: | ||
expect(results.sort(function (a, b) { return a.key - b.key; })).toEqual(keys.map(function (key) { | ||
var record = new TestRecord(); | ||
record.key = key; | ||
record.scanIdentifier = scanIdentifier; | ||
record.tuple = [key % 2 === 0, 'string']; | ||
return record; | ||
})); | ||
return [2 /*return*/]; | ||
} | ||
}); | ||
}); }); | ||
it('should query objects', function () { return tslib_1.__awaiter(void 0, void 0, void 0, function () { | ||
var mapper, item, _a, _b, element, e_5_1; | ||
var e_5, _c; | ||
return tslib_1.__generator(this, function (_d) { | ||
switch (_d.label) { | ||
case 0: | ||
mapper = new DataMapper_1.DataMapper({ client: ddbClient }); | ||
item = new TestRecord(); | ||
item.key = idx++; | ||
item.tuple = [item.key % 2 === 0, 'string']; | ||
return [4 /*yield*/, mapper.put({ item: item })]; | ||
case 1: | ||
_d.sent(); | ||
_d.label = 2; | ||
case 2: | ||
_d.trys.push([2, 7, 8, 13]); | ||
_a = tslib_1.__asyncValues(mapper.query(TestRecord, { key: item.key }, { readConsistency: 'strong' })); | ||
_d.label = 3; | ||
case 3: return [4 /*yield*/, _a.next()]; | ||
case 4: | ||
if (!(_b = _d.sent(), !_b.done)) return [3 /*break*/, 6]; | ||
element = _b.value; | ||
expect(element).toEqual(item); | ||
_d.label = 5; | ||
case 5: return [3 /*break*/, 3]; | ||
case 6: return [3 /*break*/, 13]; | ||
case 7: | ||
e_5_1 = _d.sent(); | ||
e_5 = { error: e_5_1 }; | ||
return [3 /*break*/, 13]; | ||
case 8: | ||
_d.trys.push([8, , 11, 12]); | ||
if (!(_b && !_b.done && (_c = _a.return))) return [3 /*break*/, 10]; | ||
return [4 /*yield*/, _c.call(_a)]; | ||
case 9: | ||
_d.sent(); | ||
_d.label = 10; | ||
case 10: return [3 /*break*/, 12]; | ||
case 11: | ||
if (e_5) throw e_5.error; | ||
return [7 /*endfinally*/]; | ||
case 12: return [7 /*endfinally*/]; | ||
case 13: return [2 /*return*/]; | ||
} | ||
}); | ||
}); }); | ||
it('should save and load objects', async () => { | ||
const key = idx++; | ||
const mapper = new DataMapper_1.DataMapper({ client: ddbClient }); | ||
const timestamp = new Date(); | ||
// subsecond precision will not survive the trip through the serializer, | ||
// as DynamoDB's ttl fields use unix epoch (second precision) timestamps | ||
timestamp.setMilliseconds(0); | ||
const item = new TestRecord(); | ||
item.key = key; | ||
item.timestamp = timestamp; | ||
item.data = { | ||
recursive: { | ||
recursive: { | ||
recursive: { | ||
foo: '', | ||
}, | ||
}, | ||
}, | ||
}; | ||
expect(await mapper.put(item)).toEqual(item); | ||
expect(await mapper.get(item, { readConsistency: 'strong' })) | ||
.toEqual(item); | ||
}); | ||
it('should delete objects', async () => { | ||
const key = idx++; | ||
const mapper = new DataMapper_1.DataMapper({ client: ddbClient }); | ||
const timestamp = new Date(); | ||
// subsecond precision will not survive the trip through the serializer, | ||
// as DynamoDB's ttl fields use unix epoch (second precision) timestamps | ||
timestamp.setMilliseconds(0); | ||
const item = new TestRecord(); | ||
item.key = key; | ||
item.timestamp = timestamp; | ||
item.data = { | ||
recursive: { | ||
recursive: { | ||
recursive: { | ||
foo: '', | ||
}, | ||
}, | ||
}, | ||
}; | ||
await mapper.put(item); | ||
await expect(mapper.get(item, { readConsistency: 'strong' })).resolves; | ||
await mapper.delete(item); | ||
await expect(mapper.get(item, { readConsistency: 'strong' })) | ||
.rejects | ||
.toMatchObject(new ItemNotFoundException_1.ItemNotFoundException({ | ||
TableName, | ||
ConsistentRead: true, | ||
Key: { testIndex: { N: key.toString(10) } } | ||
})); | ||
}); | ||
it('should scan objects', async () => { | ||
const keys = []; | ||
const mapper = new DataMapper_1.DataMapper({ client: ddbClient }); | ||
const scanIdentifier = Date.now(); | ||
const items = []; | ||
for (let i = 0; i < 30; i++) { | ||
const item = new TestRecord(); | ||
item.key = idx++; | ||
item.tuple = [item.key % 2 === 0, 'string']; | ||
item.scanIdentifier = scanIdentifier; | ||
keys.push(item.key); | ||
items.push(item); | ||
} | ||
for await (const _ of mapper.batchPut(items)) { } | ||
const results = []; | ||
for await (const element of mapper.scan(TestRecord, { | ||
readConsistency: 'strong', | ||
filter: { | ||
...dynamodb_expressions_1.equals(scanIdentifier), | ||
subject: 'scanIdentifier' | ||
}, | ||
})) { | ||
results.push(element); | ||
} | ||
expect(results.sort((a, b) => a.key - b.key)).toEqual(keys.map(key => { | ||
const record = new TestRecord(); | ||
record.key = key; | ||
record.scanIdentifier = scanIdentifier; | ||
record.tuple = [key % 2 === 0, 'string']; | ||
return record; | ||
})); | ||
}); | ||
it('should scan objects in parallel', async () => { | ||
const keys = []; | ||
const mapper = new DataMapper_1.DataMapper({ client: ddbClient }); | ||
const scanIdentifier = Date.now(); | ||
const items = []; | ||
for (let i = 0; i < 10; i++) { | ||
const item = new TestRecord(); | ||
item.key = idx++; | ||
item.tuple = [item.key % 2 === 0, 'string']; | ||
item.scanIdentifier = scanIdentifier; | ||
keys.push(item.key); | ||
items.push(item); | ||
} | ||
for await (const _ of mapper.batchPut(items)) { } | ||
const results = []; | ||
for await (const element of mapper.parallelScan(TestRecord, 4, { | ||
readConsistency: 'strong', | ||
filter: { | ||
...dynamodb_expressions_1.equals(scanIdentifier), | ||
subject: 'scanIdentifier' | ||
}, | ||
})) { | ||
results.push(element); | ||
} | ||
expect(results.sort((a, b) => a.key - b.key)).toEqual(keys.map(key => { | ||
const record = new TestRecord(); | ||
record.key = key; | ||
record.scanIdentifier = scanIdentifier; | ||
record.tuple = [key % 2 === 0, 'string']; | ||
return record; | ||
})); | ||
}); | ||
it('should query objects', async () => { | ||
const mapper = new DataMapper_1.DataMapper({ client: ddbClient }); | ||
const item = new TestRecord(); | ||
item.key = idx++; | ||
item.tuple = [item.key % 2 === 0, 'string']; | ||
await mapper.put({ item }); | ||
for await (const element of mapper.query(TestRecord, { key: item.key }, { readConsistency: 'strong' })) { | ||
expect(element).toEqual(item); | ||
} | ||
}); | ||
}); | ||
//# sourceMappingURL=DataMapper.integ.js.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var protocols_1 = require("./protocols"); | ||
function embed(documentConstructor, _a) { | ||
var _b = _a === void 0 ? {} : _a, attributeName = _b.attributeName, defaultProvider = _b.defaultProvider; | ||
const protocols_1 = require("./protocols"); | ||
function embed(documentConstructor, { attributeName, defaultProvider } = {}) { | ||
return { | ||
type: 'Document', | ||
members: documentConstructor.prototype[protocols_1.DynamoDbSchema] || {}, | ||
attributeName: attributeName, | ||
defaultProvider: defaultProvider, | ||
attributeName, | ||
defaultProvider, | ||
valueConstructor: documentConstructor | ||
@@ -12,0 +11,0 @@ }; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var tslib_1 = require("tslib"); | ||
const tslib_1 = require("tslib"); | ||
tslib_1.__exportStar(require("./constants"), exports); | ||
@@ -5,0 +5,0 @@ tslib_1.__exportStar(require("./DataMapper"), exports); |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var tslib_1 = require("tslib"); | ||
var _a = Object.setPrototypeOf, setPrototypeOf = _a === void 0 ? function (obj, proto) { | ||
const { setPrototypeOf = function (obj, proto) { | ||
obj.__proto__ = proto; | ||
return obj; | ||
} : _a; | ||
}, } = Object; | ||
/** | ||
@@ -13,19 +12,15 @@ * An exception thrown when an item was sought with a DynamoDB::GetItem | ||
*/ | ||
var ItemNotFoundException = /** @class */ (function (_super) { | ||
tslib_1.__extends(ItemNotFoundException, _super); | ||
function ItemNotFoundException(itemSought, message) { | ||
if (message === void 0) { message = defaultErrorMessage(itemSought); } | ||
var _this = _super.call(this, message) || this; | ||
_this.itemSought = itemSought; | ||
_this.name = 'ItemNotFoundException'; | ||
class ItemNotFoundException extends Error { | ||
constructor(itemSought, message = defaultErrorMessage(itemSought)) { | ||
super(message); | ||
this.itemSought = itemSought; | ||
this.name = 'ItemNotFoundException'; | ||
// https://github.com/Microsoft/TypeScript/wiki/Breaking-Changes#extending-built-ins-like-error-array-and-map-may-no-longer-work | ||
setPrototypeOf(_this, ItemNotFoundException.prototype); | ||
return _this; | ||
setPrototypeOf(this, ItemNotFoundException.prototype); | ||
} | ||
return ItemNotFoundException; | ||
}(Error)); | ||
} | ||
exports.ItemNotFoundException = ItemNotFoundException; | ||
function defaultErrorMessage(itemSought) { | ||
return "No item with the key " + JSON.stringify(itemSought.Key) + " found in the " + itemSought.TableName + " table."; | ||
return `No item with the key ${JSON.stringify(itemSought.Key)} found in the ${itemSought.TableName} table.`; | ||
} | ||
//# sourceMappingURL=ItemNotFoundException.js.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var tslib_1 = require("tslib"); | ||
require('./asyncIteratorSymbolPolyfill'); | ||
var Iterator = /** @class */ (function () { | ||
function Iterator(paginator) { | ||
class Iterator { | ||
constructor(paginator) { | ||
this.paginator = paginator; | ||
@@ -15,13 +14,12 @@ this._count = 0; | ||
*/ | ||
Iterator.prototype[Symbol.asyncIterator] = function () { | ||
[Symbol.asyncIterator]() { | ||
return this; | ||
}; | ||
} | ||
/** | ||
* @inheritDoc | ||
*/ | ||
Iterator.prototype.next = function () { | ||
var _this = this; | ||
this.lastResolved = this.lastResolved.then(function () { return _this.getNext(); }); | ||
next() { | ||
this.lastResolved = this.lastResolved.then(() => this.getNext()); | ||
return this.lastResolved; | ||
}; | ||
} | ||
/** | ||
@@ -36,81 +34,61 @@ * Detaches the underlying paginator from this iterator and returns it. The | ||
*/ | ||
Iterator.prototype.pages = function () { | ||
pages() { | ||
// Prevent the iterator from being used further and squelch any uncaught | ||
// promise rejection warnings | ||
this.lastResolved = Promise.reject(new Error('The underlying paginator has been detached from this iterator.')); | ||
this.lastResolved.catch(function () { }); | ||
this.lastResolved.catch(() => { }); | ||
return this.paginator; | ||
}; | ||
} | ||
/** | ||
* @inheritDoc | ||
*/ | ||
Iterator.prototype.return = function () { | ||
return() { | ||
// Prevent any further use of this iterator | ||
this.lastResolved = Promise.reject(new Error('Iteration has been manually interrupted and may not be resumed')); | ||
this.lastResolved.catch(function () { }); | ||
this.lastResolved.catch(() => { }); | ||
// Empty the pending queue to free up memory | ||
this.pending.length = 0; | ||
return this.paginator.return(); | ||
}; | ||
Object.defineProperty(Iterator.prototype, "consumedCapacity", { | ||
/** | ||
* Retrieve the reported capacity consumed by this iterator. Will be | ||
* undefined unless returned consumed capacity is requested. | ||
*/ | ||
get: function () { | ||
return this.paginator.consumedCapacity; | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
Object.defineProperty(Iterator.prototype, "count", { | ||
/** | ||
* Retrieve the number of items yielded thus far by this iterator. | ||
*/ | ||
get: function () { | ||
return this._count; | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
Object.defineProperty(Iterator.prototype, "scannedCount", { | ||
/** | ||
* Retrieve the number of items scanned thus far during the execution of | ||
* this iterator. This number should be the same as {@link count} unless a | ||
* filter expression was used. | ||
*/ | ||
get: function () { | ||
return this.paginator.scannedCount; | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
Iterator.prototype.getNext = function () { | ||
return tslib_1.__awaiter(this, void 0, void 0, function () { | ||
var _this = this; | ||
return tslib_1.__generator(this, function (_a) { | ||
if (this.pending.length > 0) { | ||
this.lastYielded = this.pending.shift(); | ||
this._count++; | ||
return [2 /*return*/, { | ||
done: false, | ||
value: this.lastYielded | ||
}]; | ||
} | ||
return [2 /*return*/, this.paginator.next().then(function (_a) { | ||
var _b; | ||
var _c = _a.value, value = _c === void 0 ? [] : _c, done = _a.done; | ||
if (!done) { | ||
(_b = _this.pending).push.apply(_b, tslib_1.__spread(value)); | ||
return _this.getNext(); | ||
} | ||
_this.lastYielded = undefined; | ||
return { done: true }; | ||
})]; | ||
}); | ||
} | ||
/** | ||
* Retrieve the reported capacity consumed by this iterator. Will be | ||
* undefined unless returned consumed capacity is requested. | ||
*/ | ||
get consumedCapacity() { | ||
return this.paginator.consumedCapacity; | ||
} | ||
/** | ||
* Retrieve the number of items yielded thus far by this iterator. | ||
*/ | ||
get count() { | ||
return this._count; | ||
} | ||
/** | ||
* Retrieve the number of items scanned thus far during the execution of | ||
* this iterator. This number should be the same as {@link count} unless a | ||
* filter expression was used. | ||
*/ | ||
get scannedCount() { | ||
return this.paginator.scannedCount; | ||
} | ||
async getNext() { | ||
if (this.pending.length > 0) { | ||
this.lastYielded = this.pending.shift(); | ||
this._count++; | ||
return { | ||
done: false, | ||
value: this.lastYielded | ||
}; | ||
} | ||
return this.paginator.next().then(({ value = [], done }) => { | ||
if (!done) { | ||
this.pending.push(...value); | ||
return this.getNext(); | ||
} | ||
this.lastYielded = undefined; | ||
return { done: true }; | ||
}); | ||
}; | ||
return Iterator; | ||
}()); | ||
} | ||
} | ||
exports.Iterator = Iterator; | ||
//# sourceMappingURL=Iterator.js.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var tslib_1 = require("tslib"); | ||
var dynamodb_data_marshaller_1 = require("@aws/dynamodb-data-marshaller"); | ||
const dynamodb_data_marshaller_1 = require("@aws/dynamodb-data-marshaller"); | ||
/** | ||
@@ -9,21 +8,10 @@ * @internal | ||
function marshallStartKey(schema, startKey) { | ||
var e_1, _a; | ||
var key = {}; | ||
try { | ||
for (var _b = tslib_1.__values(Object.keys(startKey)), _c = _b.next(); !_c.done; _c = _b.next()) { | ||
var propertyName = _c.value; | ||
var propSchema = schema[propertyName]; | ||
var _d = propSchema.attributeName, attributeName = _d === void 0 ? propertyName : _d; | ||
if (propSchema) { | ||
key[attributeName] = dynamodb_data_marshaller_1.marshallValue(propSchema, startKey[propertyName]); | ||
} | ||
const key = {}; | ||
for (const propertyName of Object.keys(startKey)) { | ||
const propSchema = schema[propertyName]; | ||
const { attributeName = propertyName } = propSchema; | ||
if (propSchema) { | ||
key[attributeName] = dynamodb_data_marshaller_1.marshallValue(propSchema, startKey[propertyName]); | ||
} | ||
} | ||
catch (e_1_1) { e_1 = { error: e_1_1 }; } | ||
finally { | ||
try { | ||
if (_c && !_c.done && (_a = _b.return)) _a.call(_b); | ||
} | ||
finally { if (e_1) throw e_1.error; } | ||
} | ||
return key; | ||
@@ -30,0 +18,0 @@ } |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var tslib_1 = require("tslib"); | ||
var protocols_1 = require("./protocols"); | ||
var dynamodb_data_marshaller_1 = require("@aws/dynamodb-data-marshaller"); | ||
const protocols_1 = require("./protocols"); | ||
const dynamodb_data_marshaller_1 = require("@aws/dynamodb-data-marshaller"); | ||
require('./asyncIteratorSymbolPolyfill'); | ||
var Paginator = /** @class */ (function () { | ||
function Paginator(paginator, valueConstructor) { | ||
class Paginator { | ||
constructor(paginator, valueConstructor) { | ||
this.paginator = paginator; | ||
@@ -17,88 +16,64 @@ this.valueConstructor = valueConstructor; | ||
*/ | ||
Paginator.prototype[Symbol.asyncIterator] = function () { | ||
[Symbol.asyncIterator]() { | ||
return this; | ||
}; | ||
} | ||
/** | ||
* @inheritDoc | ||
*/ | ||
Paginator.prototype.next = function () { | ||
var _this = this; | ||
this.lastResolved = this.lastResolved.then(function () { return _this.getNext(); }); | ||
next() { | ||
this.lastResolved = this.lastResolved.then(() => this.getNext()); | ||
return this.lastResolved; | ||
}; | ||
} | ||
/** | ||
* @inheritDoc | ||
*/ | ||
Paginator.prototype.return = function () { | ||
return() { | ||
// Prevent any further use of this iterator | ||
this.lastResolved = Promise.reject(new Error('Iteration has been manually interrupted and may not be resumed')); | ||
this.lastResolved.catch(function () { }); | ||
this.lastResolved.catch(() => { }); | ||
return this.paginator.return(); | ||
}; | ||
Object.defineProperty(Paginator.prototype, "consumedCapacity", { | ||
/** | ||
* Retrieve the reported capacity consumed by this paginator. Will be | ||
* undefined unless returned consumed capacity is requested. | ||
*/ | ||
get: function () { | ||
return this.paginator.consumedCapacity; | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
Object.defineProperty(Paginator.prototype, "count", { | ||
/** | ||
* Retrieve the number of items yielded thus far by this paginator. | ||
*/ | ||
get: function () { | ||
return this.paginator.count; | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
Object.defineProperty(Paginator.prototype, "lastEvaluatedKey", { | ||
/** | ||
* Retrieve the last reported `LastEvaluatedKey`, unmarshalled according to | ||
* the schema used by this paginator. | ||
*/ | ||
get: function () { | ||
return this.lastKey; | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
Object.defineProperty(Paginator.prototype, "scannedCount", { | ||
/** | ||
* Retrieve the number of items scanned thus far during the execution of | ||
* this paginator. This number should be the same as {@link count} unless a | ||
* filter expression was used. | ||
*/ | ||
get: function () { | ||
return this.paginator.scannedCount; | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
Paginator.prototype.getNext = function () { | ||
return tslib_1.__awaiter(this, void 0, void 0, function () { | ||
var _this = this; | ||
return tslib_1.__generator(this, function (_a) { | ||
return [2 /*return*/, this.paginator.next().then(function (_a) { | ||
var _b = _a.value, value = _b === void 0 ? {} : _b, done = _a.done; | ||
if (!done) { | ||
_this.lastKey = value.LastEvaluatedKey && dynamodb_data_marshaller_1.unmarshallItem(_this.itemSchema, value.LastEvaluatedKey, _this.valueConstructor); | ||
var items = value.Items || []; | ||
return { | ||
value: (items).map(function (item) { return dynamodb_data_marshaller_1.unmarshallItem(_this.itemSchema, item, _this.valueConstructor); }), | ||
done: false | ||
}; | ||
} | ||
return { done: true }; | ||
})]; | ||
}); | ||
} | ||
/** | ||
* Retrieve the reported capacity consumed by this paginator. Will be | ||
* undefined unless returned consumed capacity is requested. | ||
*/ | ||
get consumedCapacity() { | ||
return this.paginator.consumedCapacity; | ||
} | ||
/** | ||
* Retrieve the number of items yielded thus far by this paginator. | ||
*/ | ||
get count() { | ||
return this.paginator.count; | ||
} | ||
/** | ||
* Retrieve the last reported `LastEvaluatedKey`, unmarshalled according to | ||
* the schema used by this paginator. | ||
*/ | ||
get lastEvaluatedKey() { | ||
return this.lastKey; | ||
} | ||
/** | ||
* Retrieve the number of items scanned thus far during the execution of | ||
* this paginator. This number should be the same as {@link count} unless a | ||
* filter expression was used. | ||
*/ | ||
get scannedCount() { | ||
return this.paginator.scannedCount; | ||
} | ||
async getNext() { | ||
return this.paginator.next().then(({ value = {}, done }) => { | ||
if (!done) { | ||
this.lastKey = value.LastEvaluatedKey && dynamodb_data_marshaller_1.unmarshallItem(this.itemSchema, value.LastEvaluatedKey, this.valueConstructor); | ||
const items = value.Items || []; | ||
return { | ||
value: (items).map(item => dynamodb_data_marshaller_1.unmarshallItem(this.itemSchema, item, this.valueConstructor)), | ||
done: false | ||
}; | ||
} | ||
return { done: true }; | ||
}); | ||
}; | ||
return Paginator; | ||
}()); | ||
} | ||
} | ||
exports.Paginator = Paginator; | ||
//# sourceMappingURL=Paginator.js.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var tslib_1 = require("tslib"); | ||
var Iterator_1 = require("./Iterator"); | ||
var ParallelScanPaginator_1 = require("./ParallelScanPaginator"); | ||
const Iterator_1 = require("./Iterator"); | ||
const ParallelScanPaginator_1 = require("./ParallelScanPaginator"); | ||
/** | ||
@@ -10,11 +9,8 @@ * Iterates over each item returned by a parallel DynamoDB scan until no more | ||
*/ | ||
var ParallelScanIterator = /** @class */ (function (_super) { | ||
tslib_1.__extends(ParallelScanIterator, _super); | ||
function ParallelScanIterator(client, itemConstructor, segments, options) { | ||
if (options === void 0) { options = {}; } | ||
return _super.call(this, new ParallelScanPaginator_1.ParallelScanPaginator(client, itemConstructor, segments, options)) || this; | ||
class ParallelScanIterator extends Iterator_1.Iterator { | ||
constructor(client, itemConstructor, segments, options = {}) { | ||
super(new ParallelScanPaginator_1.ParallelScanPaginator(client, itemConstructor, segments, options)); | ||
} | ||
return ParallelScanIterator; | ||
}(Iterator_1.Iterator)); | ||
} | ||
exports.ParallelScanIterator = ParallelScanIterator; | ||
//# sourceMappingURL=ParallelScanIterator.js.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var tslib_1 = require("tslib"); | ||
var buildScanInput_1 = require("./buildScanInput"); | ||
var Paginator_1 = require("./Paginator"); | ||
var protocols_1 = require("./protocols"); | ||
var dynamodb_query_iterator_1 = require("@aws/dynamodb-query-iterator"); | ||
var dynamodb_data_marshaller_1 = require("@aws/dynamodb-data-marshaller"); | ||
const buildScanInput_1 = require("./buildScanInput"); | ||
const Paginator_1 = require("./Paginator"); | ||
const protocols_1 = require("./protocols"); | ||
const dynamodb_query_iterator_1 = require("@aws/dynamodb-query-iterator"); | ||
const dynamodb_data_marshaller_1 = require("@aws/dynamodb-data-marshaller"); | ||
/** | ||
@@ -13,62 +12,47 @@ * Iterates over each page of items returned by a parallel DynamoDB scan until | ||
*/ | ||
var ParallelScanPaginator = /** @class */ (function (_super) { | ||
tslib_1.__extends(ParallelScanPaginator, _super); | ||
function ParallelScanPaginator(client, itemConstructor, segments, options) { | ||
if (options === void 0) { options = {}; } | ||
var _this = this; | ||
var schema = protocols_1.getSchema(itemConstructor.prototype); | ||
var input = tslib_1.__assign(tslib_1.__assign({}, buildScanInput_1.buildScanInput(itemConstructor, options)), { TotalSegments: segments, ExclusiveStartKey: undefined, Segment: undefined }); | ||
var scanState; | ||
class ParallelScanPaginator extends Paginator_1.Paginator { | ||
constructor(client, itemConstructor, segments, options = {}) { | ||
const schema = protocols_1.getSchema(itemConstructor.prototype); | ||
const input = { | ||
...buildScanInput_1.buildScanInput(itemConstructor, options), | ||
TotalSegments: segments, | ||
ExclusiveStartKey: undefined, | ||
Segment: undefined | ||
}; | ||
let scanState; | ||
if (options.scanState) { | ||
scanState = options.scanState.map(function (_a) { | ||
var initialized = _a.initialized, lastKey = _a.lastEvaluatedKey; | ||
return ({ | ||
initialized: initialized, | ||
LastEvaluatedKey: lastKey | ||
? dynamodb_data_marshaller_1.marshallKey(schema, lastKey, options.indexName) | ||
: undefined | ||
}); | ||
}); | ||
scanState = options.scanState.map(({ initialized, lastEvaluatedKey: lastKey }) => ({ | ||
initialized, | ||
LastEvaluatedKey: lastKey | ||
? dynamodb_data_marshaller_1.marshallKey(schema, lastKey, options.indexName) | ||
: undefined | ||
})); | ||
} | ||
var paginator = new dynamodb_query_iterator_1.ParallelScanPaginator(client, input, scanState); | ||
_this = _super.call(this, paginator, itemConstructor) || this; | ||
_this._paginator = paginator; | ||
_this._ctor = itemConstructor; | ||
_this._schema = schema; | ||
return _this; | ||
const paginator = new dynamodb_query_iterator_1.ParallelScanPaginator(client, input, scanState); | ||
super(paginator, itemConstructor); | ||
this._paginator = paginator; | ||
this._ctor = itemConstructor; | ||
this._schema = schema; | ||
} | ||
Object.defineProperty(ParallelScanPaginator.prototype, "lastEvaluatedKey", { | ||
/** | ||
* The `lastEvaluatedKey` attribute is not available on parallel scans. Use | ||
* {@link scanState} instead. | ||
*/ | ||
get: function () { | ||
return undefined; | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
Object.defineProperty(ParallelScanPaginator.prototype, "scanState", { | ||
/** | ||
* A snapshot of the current state of a parallel scan. May be used to resume | ||
* a parallel scan with a separate paginator. | ||
*/ | ||
get: function () { | ||
var _this = this; | ||
return this._paginator.scanState.map(function (_a) { | ||
var initialized = _a.initialized, LastEvaluatedKey = _a.LastEvaluatedKey; | ||
return ({ | ||
initialized: initialized, | ||
lastEvaluatedKey: LastEvaluatedKey | ||
? dynamodb_data_marshaller_1.unmarshallItem(_this._schema, LastEvaluatedKey, _this._ctor) | ||
: undefined | ||
}); | ||
}); | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
return ParallelScanPaginator; | ||
}(Paginator_1.Paginator)); | ||
/** | ||
* The `lastEvaluatedKey` attribute is not available on parallel scans. Use | ||
* {@link scanState} instead. | ||
*/ | ||
get lastEvaluatedKey() { | ||
return undefined; | ||
} | ||
/** | ||
* A snapshot of the current state of a parallel scan. May be used to resume | ||
* a parallel scan with a separate paginator. | ||
*/ | ||
get scanState() { | ||
return this._paginator.scanState.map(({ initialized, LastEvaluatedKey }) => ({ | ||
initialized, | ||
lastEvaluatedKey: LastEvaluatedKey | ||
? dynamodb_data_marshaller_1.unmarshallItem(this._schema, LastEvaluatedKey, this._ctor) | ||
: undefined | ||
})); | ||
} | ||
} | ||
exports.ParallelScanPaginator = ParallelScanPaginator; | ||
//# sourceMappingURL=ParallelScanPaginator.js.map |
@@ -35,3 +35,3 @@ "use strict"; | ||
if (item) { | ||
var schema = item[exports.DynamoDbSchema]; | ||
const schema = item[exports.DynamoDbSchema]; | ||
if (schema && typeof schema === 'object') { | ||
@@ -65,6 +65,5 @@ return schema; | ||
exports.DynamoDbTable = Symbol('DynamoDbTableName'); | ||
function getTableName(item, tableNamePrefix) { | ||
if (tableNamePrefix === void 0) { tableNamePrefix = ''; } | ||
function getTableName(item, tableNamePrefix = '') { | ||
if (item) { | ||
var tableName = item[exports.DynamoDbTable]; | ||
const tableName = item[exports.DynamoDbTable]; | ||
if (typeof tableName === 'string') { | ||
@@ -71,0 +70,0 @@ return tableNamePrefix + tableName; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var tslib_1 = require("tslib"); | ||
var Iterator_1 = require("./Iterator"); | ||
var QueryPaginator_1 = require("./QueryPaginator"); | ||
const Iterator_1 = require("./Iterator"); | ||
const QueryPaginator_1 = require("./QueryPaginator"); | ||
/** | ||
@@ -10,10 +9,8 @@ * Iterates over each item returned by a DynamoDB query until no more pages are | ||
*/ | ||
var QueryIterator = /** @class */ (function (_super) { | ||
tslib_1.__extends(QueryIterator, _super); | ||
function QueryIterator(client, valueConstructor, keyCondition, options) { | ||
return _super.call(this, new QueryPaginator_1.QueryPaginator(client, valueConstructor, keyCondition, options)) || this; | ||
class QueryIterator extends Iterator_1.Iterator { | ||
constructor(client, valueConstructor, keyCondition, options) { | ||
super(new QueryPaginator_1.QueryPaginator(client, valueConstructor, keyCondition, options)); | ||
} | ||
return QueryIterator; | ||
}(Iterator_1.Iterator)); | ||
} | ||
exports.QueryIterator = QueryIterator; | ||
//# sourceMappingURL=QueryIterator.js.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var tslib_1 = require("tslib"); | ||
var marshallStartKey_1 = require("./marshallStartKey"); | ||
var Paginator_1 = require("./Paginator"); | ||
var protocols_1 = require("./protocols"); | ||
var dynamodb_query_iterator_1 = require("@aws/dynamodb-query-iterator"); | ||
var dynamodb_data_marshaller_1 = require("@aws/dynamodb-data-marshaller"); | ||
var dynamodb_expressions_1 = require("@aws/dynamodb-expressions"); | ||
const marshallStartKey_1 = require("./marshallStartKey"); | ||
const Paginator_1 = require("./Paginator"); | ||
const protocols_1 = require("./protocols"); | ||
const dynamodb_query_iterator_1 = require("@aws/dynamodb-query-iterator"); | ||
const dynamodb_data_marshaller_1 = require("@aws/dynamodb-data-marshaller"); | ||
const dynamodb_expressions_1 = require("@aws/dynamodb-expressions"); | ||
/** | ||
@@ -14,10 +13,7 @@ * Iterates over each page of items returned by a DynamoDB query until no more | ||
*/ | ||
var QueryPaginator = /** @class */ (function (_super) { | ||
tslib_1.__extends(QueryPaginator, _super); | ||
function QueryPaginator(client, valueConstructor, keyCondition, options) { | ||
if (options === void 0) { options = {}; } | ||
var _this = this; | ||
var itemSchema = protocols_1.getSchema(valueConstructor.prototype); | ||
var filter = options.filter, indexName = options.indexName, limit = options.limit, pageSize = options.pageSize, projection = options.projection, readConsistency = options.readConsistency, scanIndexForward = options.scanIndexForward, startKey = options.startKey, prefix = options.tableNamePrefix; | ||
var req = { | ||
class QueryPaginator extends Paginator_1.Paginator { | ||
constructor(client, valueConstructor, keyCondition, options = {}) { | ||
const itemSchema = protocols_1.getSchema(valueConstructor.prototype); | ||
let { filter, indexName, limit, pageSize, projection, readConsistency, scanIndexForward, startKey, tableNamePrefix: prefix, } = options; | ||
const req = { | ||
TableName: protocols_1.getTableName(valueConstructor.prototype, prefix), | ||
@@ -31,3 +27,3 @@ ScanIndexForward: scanIndexForward, | ||
} | ||
var attributes = new dynamodb_expressions_1.ExpressionAttributes(); | ||
const attributes = new dynamodb_expressions_1.ExpressionAttributes(); | ||
req.KeyConditionExpression = dynamodb_data_marshaller_1.marshallConditionExpression(normalizeKeyCondition(keyCondition), itemSchema, attributes).expression; | ||
@@ -49,36 +45,26 @@ if (filter) { | ||
} | ||
_this = _super.call(this, new dynamodb_query_iterator_1.QueryPaginator(client, req, limit), valueConstructor) || this; | ||
return _this; | ||
super(new dynamodb_query_iterator_1.QueryPaginator(client, req, limit), valueConstructor); | ||
} | ||
return QueryPaginator; | ||
}(Paginator_1.Paginator)); | ||
} | ||
exports.QueryPaginator = QueryPaginator; | ||
function normalizeKeyCondition(keyCondition) { | ||
var e_1, _a; | ||
if (dynamodb_expressions_1.isConditionExpression(keyCondition)) { | ||
return keyCondition; | ||
} | ||
var conditions = []; | ||
try { | ||
for (var _b = tslib_1.__values(Object.keys(keyCondition)), _c = _b.next(); !_c.done; _c = _b.next()) { | ||
var property = _c.value; | ||
var predicate = keyCondition[property]; | ||
if (dynamodb_expressions_1.isConditionExpressionPredicate(predicate)) { | ||
conditions.push(tslib_1.__assign(tslib_1.__assign({}, predicate), { subject: property })); | ||
} | ||
else { | ||
conditions.push({ | ||
type: 'Equals', | ||
subject: property, | ||
object: predicate, | ||
}); | ||
} | ||
const conditions = []; | ||
for (const property of Object.keys(keyCondition)) { | ||
const predicate = keyCondition[property]; | ||
if (dynamodb_expressions_1.isConditionExpressionPredicate(predicate)) { | ||
conditions.push({ | ||
...predicate, | ||
subject: property, | ||
}); | ||
} | ||
} | ||
catch (e_1_1) { e_1 = { error: e_1_1 }; } | ||
finally { | ||
try { | ||
if (_c && !_c.done && (_a = _b.return)) _a.call(_b); | ||
else { | ||
conditions.push({ | ||
type: 'Equals', | ||
subject: property, | ||
object: predicate, | ||
}); | ||
} | ||
finally { if (e_1) throw e_1.error; } | ||
} | ||
@@ -88,4 +74,4 @@ if (conditions.length === 1) { | ||
} | ||
return { type: 'And', conditions: conditions }; | ||
return { type: 'And', conditions }; | ||
} | ||
//# sourceMappingURL=QueryPaginator.js.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var tslib_1 = require("tslib"); | ||
var Iterator_1 = require("./Iterator"); | ||
var ScanPaginator_1 = require("./ScanPaginator"); | ||
const Iterator_1 = require("./Iterator"); | ||
const ScanPaginator_1 = require("./ScanPaginator"); | ||
/** | ||
@@ -10,10 +9,8 @@ * Iterates over each item returned by a DynamoDB scan until no more pages are | ||
*/ | ||
var ScanIterator = /** @class */ (function (_super) { | ||
tslib_1.__extends(ScanIterator, _super); | ||
function ScanIterator(client, valueConstructor, options) { | ||
return _super.call(this, new ScanPaginator_1.ScanPaginator(client, valueConstructor, options)) || this; | ||
class ScanIterator extends Iterator_1.Iterator { | ||
constructor(client, valueConstructor, options) { | ||
super(new ScanPaginator_1.ScanPaginator(client, valueConstructor, options)); | ||
} | ||
return ScanIterator; | ||
}(Iterator_1.Iterator)); | ||
} | ||
exports.ScanIterator = ScanIterator; | ||
//# sourceMappingURL=ScanIterator.js.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var tslib_1 = require("tslib"); | ||
var buildScanInput_1 = require("./buildScanInput"); | ||
var Paginator_1 = require("./Paginator"); | ||
var dynamodb_query_iterator_1 = require("@aws/dynamodb-query-iterator"); | ||
const buildScanInput_1 = require("./buildScanInput"); | ||
const Paginator_1 = require("./Paginator"); | ||
const dynamodb_query_iterator_1 = require("@aws/dynamodb-query-iterator"); | ||
/** | ||
@@ -11,11 +10,8 @@ * Iterates over each page of items returned by a DynamoDB scan until no more | ||
*/ | ||
var ScanPaginator = /** @class */ (function (_super) { | ||
tslib_1.__extends(ScanPaginator, _super); | ||
function ScanPaginator(client, itemConstructor, options) { | ||
if (options === void 0) { options = {}; } | ||
return _super.call(this, new dynamodb_query_iterator_1.ScanPaginator(client, buildScanInput_1.buildScanInput(itemConstructor, options), options.limit), itemConstructor) || this; | ||
class ScanPaginator extends Paginator_1.Paginator { | ||
constructor(client, itemConstructor, options = {}) { | ||
super(new dynamodb_query_iterator_1.ScanPaginator(client, buildScanInput_1.buildScanInput(itemConstructor, options), options.limit), itemConstructor); | ||
} | ||
return ScanPaginator; | ||
}(Paginator_1.Paginator)); | ||
} | ||
exports.ScanPaginator = ScanPaginator; | ||
//# sourceMappingURL=ScanPaginator.js.map |
{ | ||
"name": "aws-dynamodb-data-mapper", | ||
"version": "0.7.3-pull-request-167-3", | ||
"version": "0.7.3-pull-request-167-4", | ||
"description": "A schema-based data mapper for Amazon DynamoDB", | ||
@@ -51,3 +51,3 @@ "keywords": [ | ||
}, | ||
"gitHead": "7cfb733e819ee0a5a3cfc7ee8f1f4222f0ac7954" | ||
"gitHead": "78e82a3c68facefa4d2daebc382340b99ac72954" | ||
} |
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 too big to display
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
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
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
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
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
501754
6170