presidium 0.15.16 → 0.15.17
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.
- package/DynamoStream.js +26 -12
- package/DynamoStream.test.js +0 -46
- package/package.json +1 -1
package/DynamoStream.js
CHANGED
|
@@ -60,6 +60,7 @@ const DynamoStream = function (options) {
|
|
|
60
60
|
this.shardIteratorType = options.shardIteratorType ?? 'LATEST'
|
|
61
61
|
this.shardUpdatePeriod = options.shardUpdatePeriod ?? 30000
|
|
62
62
|
this.listStreamsLimit = options.listStreamsLimit ?? 100
|
|
63
|
+
this.debug = options.debug ?? false
|
|
63
64
|
this.client = new DynamoDBStreams({
|
|
64
65
|
apiVersion: '2012-08-10',
|
|
65
66
|
accessKeyId: 'id',
|
|
@@ -129,12 +130,14 @@ DynamoStream.prototype.getRecords = async function* getRecords(
|
|
|
129
130
|
ShardId: Shard.ShardId,
|
|
130
131
|
StreamArn: Shard.Stream.StreamArn,
|
|
131
132
|
ShardIteratorType: Shard.ShardIteratorType,
|
|
133
|
+
|
|
134
|
+
/*
|
|
132
135
|
...(
|
|
133
|
-
|
|
134
|
-
||
|
|
135
|
-
) ? {
|
|
136
|
-
|
|
137
|
-
|
|
136
|
+
Shard.ShardIteratorType == 'AFTER_SEQUENCE_NUMBER'
|
|
137
|
+
|| Shard.ShardIteratorType == 'AT_SEQUENCE_NUMBER'
|
|
138
|
+
) ? { SequenceNumber: Shard.SequenceNumber } : {},
|
|
139
|
+
*/
|
|
140
|
+
|
|
138
141
|
}).promise().then(get('ShardIterator'))
|
|
139
142
|
let records = await this.client.getRecords({
|
|
140
143
|
ShardIterator: startingShardIterator,
|
|
@@ -156,10 +159,13 @@ const SymbolUpdateShards = Symbol('UpdateShards')
|
|
|
156
159
|
|
|
157
160
|
DynamoStream.prototype[Symbol.asyncIterator] = async function* () {
|
|
158
161
|
let shards = await pipe([
|
|
159
|
-
|
|
162
|
+
always(this.getStreams()),
|
|
160
163
|
flatMap(Stream => this.getShards(Stream)),
|
|
161
|
-
map(assign({
|
|
162
|
-
|
|
164
|
+
map(assign({
|
|
165
|
+
ShardIteratorType: always(this.shardIteratorType),
|
|
166
|
+
})),
|
|
167
|
+
transform(map(identity), []),
|
|
168
|
+
])()
|
|
163
169
|
let muxAsyncIterator = Mux.race(shards.map(Shard => this.getRecords(Shard)))
|
|
164
170
|
let iterationPromise = muxAsyncIterator.next()
|
|
165
171
|
let shardUpdatePromise = new Promise(resolve => setTimeout(
|
|
@@ -172,16 +178,24 @@ DynamoStream.prototype[Symbol.asyncIterator] = async function* () {
|
|
|
172
178
|
])
|
|
173
179
|
if (iteration == SymbolUpdateShards) {
|
|
174
180
|
const latestShards = await pipe([
|
|
175
|
-
|
|
181
|
+
always(this.getStreams()),
|
|
176
182
|
flatMap(Stream => this.getShards(Stream)),
|
|
177
|
-
|
|
183
|
+
transform(map(identity), []),
|
|
184
|
+
])()
|
|
178
185
|
const newShards = pipe([
|
|
186
|
+
always(shards),
|
|
179
187
|
differenceWith(
|
|
180
188
|
(ShardA, ShardB) => ShardA.ShardId == ShardB.ShardId,
|
|
181
189
|
latestShards,
|
|
182
190
|
),
|
|
183
|
-
map(assign({
|
|
184
|
-
|
|
191
|
+
map(assign({
|
|
192
|
+
ShardIteratorType: always('TRIM_HORIZON'),
|
|
193
|
+
})),
|
|
194
|
+
])()
|
|
195
|
+
|
|
196
|
+
if (this.debug) {
|
|
197
|
+
console.log('Latest shards:', latestShards)
|
|
198
|
+
}
|
|
185
199
|
|
|
186
200
|
shards = latestShards
|
|
187
201
|
muxAsyncIterator = newShards.length == 0 ? muxAsyncIterator : Mux.race([
|
package/DynamoStream.test.js
CHANGED
|
@@ -223,52 +223,6 @@ const test = Test('DynamoStream', DynamoStream)
|
|
|
223
223
|
myStream.close()
|
|
224
224
|
})
|
|
225
225
|
|
|
226
|
-
.case({
|
|
227
|
-
table: 'my-table',
|
|
228
|
-
endpoint: 'http://localhost:8000',
|
|
229
|
-
listStreamsLimit: 1,
|
|
230
|
-
shardIteratorType: 'AFTER_SEQUENCE_NUMBER',
|
|
231
|
-
debug: true,
|
|
232
|
-
}, async function (myStream) {
|
|
233
|
-
await myStream.ready
|
|
234
|
-
|
|
235
|
-
const table = this.table
|
|
236
|
-
await table.putItem({
|
|
237
|
-
id: '1',
|
|
238
|
-
status: 'waitlist',
|
|
239
|
-
createTime: 1000,
|
|
240
|
-
name: 'George',
|
|
241
|
-
})
|
|
242
|
-
await table.putItem({
|
|
243
|
-
id: '2',
|
|
244
|
-
status: 'waitlist',
|
|
245
|
-
createTime: 1001,
|
|
246
|
-
name: 'geo',
|
|
247
|
-
})
|
|
248
|
-
await table.putItem({
|
|
249
|
-
id: '3',
|
|
250
|
-
status: 'waitlist',
|
|
251
|
-
createTime: 1002,
|
|
252
|
-
name: 'john',
|
|
253
|
-
})
|
|
254
|
-
await table.putItem({
|
|
255
|
-
id: '4',
|
|
256
|
-
status: 'approved',
|
|
257
|
-
createTime: 1003,
|
|
258
|
-
name: 'sally',
|
|
259
|
-
})
|
|
260
|
-
await table.putItem({
|
|
261
|
-
id: '5',
|
|
262
|
-
status: 'approved',
|
|
263
|
-
createTime: 1004,
|
|
264
|
-
name: 'sally',
|
|
265
|
-
})
|
|
266
|
-
|
|
267
|
-
const first5 = await asyncIterableTake(5)(myStream)
|
|
268
|
-
assert.strictEqual(first5.length, 5)
|
|
269
|
-
myStream.close()
|
|
270
|
-
})
|
|
271
|
-
|
|
272
226
|
.case({
|
|
273
227
|
table: 'my-table',
|
|
274
228
|
endpoint: 'http://localhost:8000',
|