presidium 0.26.9 → 0.27.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @name DynamoTableScanIterator
|
|
3
|
+
*
|
|
4
|
+
* @synopsis
|
|
5
|
+
* ```coffeescript [specscript]
|
|
6
|
+
* DynamoTableScanIterator(
|
|
7
|
+
* dynamoTable DynamoTable,
|
|
8
|
+
* options {},
|
|
9
|
+
* ) -> AsyncGenerator<DynamoItem>
|
|
10
|
+
* ```
|
|
11
|
+
*/
|
|
12
|
+
const DynamoTableScanIterator = async function* (
|
|
13
|
+
dynamoTable, options = {},
|
|
14
|
+
) {
|
|
15
|
+
let response = await dynamoTable.scan({ limit: 1000, ...options })
|
|
16
|
+
yield* response.Items
|
|
17
|
+
while (response.LastEvaluatedKey != null) {
|
|
18
|
+
response = await dynamoTable.scan({
|
|
19
|
+
limit: 1000,
|
|
20
|
+
exclusiveStartKey: response.LastEvaluatedKey,
|
|
21
|
+
})
|
|
22
|
+
yield* response.Items
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
module.exports = DynamoTableScanIterator
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
require('rubico/global')
|
|
2
|
+
const Transducer = require('rubico/Transducer')
|
|
3
|
+
const Test = require('thunk-test')
|
|
4
|
+
const assert = require('assert')
|
|
5
|
+
const Dynamo = require('./Dynamo')
|
|
6
|
+
const DynamoTable = require('./DynamoTable')
|
|
7
|
+
const DynamoIndex = require('./DynamoIndex')
|
|
8
|
+
const DynamoTableScanIterator = require('./DynamoTableScanIterator')
|
|
9
|
+
|
|
10
|
+
const test = new Test('DynamoTableScanIterator', async function () {
|
|
11
|
+
const testTable = new DynamoTable({
|
|
12
|
+
name: 'test_table',
|
|
13
|
+
key: [{ id: 'string' }],
|
|
14
|
+
endpoint: 'http://localhost:8000/',
|
|
15
|
+
region: 'dynamodblocal',
|
|
16
|
+
})
|
|
17
|
+
await testTable.ready
|
|
18
|
+
|
|
19
|
+
await testTable.putItem({ id: '1' })
|
|
20
|
+
await testTable.putItem({ id: '2' })
|
|
21
|
+
await testTable.putItem({ id: '3' })
|
|
22
|
+
await testTable.putItem({ id: '4' })
|
|
23
|
+
await testTable.putItem({ id: '5' })
|
|
24
|
+
|
|
25
|
+
const items = await transform(
|
|
26
|
+
DynamoTableScanIterator(testTable),
|
|
27
|
+
Transducer.map(map(Dynamo.attributeValueToJSON)),
|
|
28
|
+
[],
|
|
29
|
+
)
|
|
30
|
+
|
|
31
|
+
assert.equal(items.length, 5)
|
|
32
|
+
|
|
33
|
+
}).case()
|
|
34
|
+
|
|
35
|
+
if (process.argv[1] == __filename) {
|
|
36
|
+
test()
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
module.exports = test
|