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 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
- this.shardIteratorType == 'AFTER_SEQUENCE_NUMBER'
134
- || this.shardIteratorType == 'AT_SEQUENCE_NUMBER'
135
- ) ? {
136
- SequenceNumber: Shard.SequenceNumberRange.StartingSequenceNumber,
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
- transform(map(identity), []),
162
+ always(this.getStreams()),
160
163
  flatMap(Stream => this.getShards(Stream)),
161
- map(assign({ ShardIteratorType: always(this.shardIteratorType) })),
162
- ])(this.getStreams())
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
- transform(map(identity), []),
181
+ always(this.getStreams()),
176
182
  flatMap(Stream => this.getShards(Stream)),
177
- ])(this.getStreams())
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({ ShardIteratorType: always('TRIM_HORIZON') })),
184
- ])(shards)
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([
@@ -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',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "presidium",
3
- "version": "0.15.16",
3
+ "version": "0.15.17",
4
4
  "description": "A library for creating web services",
5
5
  "author": "Richard Tong",
6
6
  "license": "MIT",