@dxos/feed-store 0.7.5-main.9d2a38b → 0.7.5-main.e94eead

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.
@@ -362,7 +362,7 @@ import { inspectObject as inspectObject2 } from "@dxos/debug";
362
362
  import { invariant as invariant3 } from "@dxos/invariant";
363
363
  import { PublicKey } from "@dxos/keys";
364
364
  import { log as log3 } from "@dxos/log";
365
- import { ComplexMap, isNotNullOrUndefined } from "@dxos/util";
365
+ import { ComplexMap, isNonNullable } from "@dxos/util";
366
366
  var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/common/feed-store/src/feed-set-iterator.ts";
367
367
  var defaultFeedSetIteratorOptions = {
368
368
  stallTimeout: 1e3
@@ -378,10 +378,9 @@ var FeedSetIterator = class extends AbstractFeedIterator {
378
378
  });
379
379
  this._subscriptions = new EventSubscriptions();
380
380
  this.stalled = new Event2();
381
- this._reiterateBlocks = [];
382
381
  invariant3(_selector, void 0, {
383
382
  F: __dxlog_file3,
384
- L: 61,
383
+ L: 55,
385
384
  S: this,
386
385
  A: [
387
386
  "_selector",
@@ -390,7 +389,7 @@ var FeedSetIterator = class extends AbstractFeedIterator {
390
389
  });
391
390
  invariant3(options, void 0, {
392
391
  F: __dxlog_file3,
393
- L: 62,
392
+ L: 56,
394
393
  S: this,
395
394
  A: [
396
395
  "options",
@@ -421,13 +420,12 @@ var FeedSetIterator = class extends AbstractFeedIterator {
421
420
  }));
422
421
  }
423
422
  reiterateBlock(block) {
424
- this._reiterateBlocks.push(block);
425
423
  this._trigger.wake();
426
424
  }
427
425
  async addFeed(feed) {
428
426
  invariant3(!this._feedQueues.has(feed.key), `Feed already added: ${feed.key}`, {
429
427
  F: __dxlog_file3,
430
- L: 98,
428
+ L: 91,
431
429
  S: this,
432
430
  A: [
433
431
  "!this._feedQueues.has(feed.key)",
@@ -436,7 +434,7 @@ var FeedSetIterator = class extends AbstractFeedIterator {
436
434
  });
437
435
  invariant3(feed.properties.opened, void 0, {
438
436
  F: __dxlog_file3,
439
- L: 99,
437
+ L: 92,
440
438
  S: this,
441
439
  A: [
442
440
  "feed.properties.opened",
@@ -447,7 +445,7 @@ var FeedSetIterator = class extends AbstractFeedIterator {
447
445
  feedKey: feed.key
448
446
  }, {
449
447
  F: __dxlog_file3,
450
- L: 100,
448
+ L: 93,
451
449
  S: this,
452
450
  C: (f, a) => f(...a)
453
451
  });
@@ -474,37 +472,14 @@ var FeedSetIterator = class extends AbstractFeedIterator {
474
472
  await Promise.all(Array.from(this._feedQueues.values()).map((queue) => queue.close()));
475
473
  this._trigger.wake();
476
474
  }
477
- _getNextBlockForReiteration() {
478
- const block = this._reiterateBlocks.shift();
479
- invariant3(block, void 0, {
480
- F: __dxlog_file3,
481
- L: 139,
482
- S: this,
483
- A: [
484
- "block",
485
- ""
486
- ]
487
- });
488
- log3("reiterate", {
489
- key: block?.feedKey.toHex(),
490
- seq: block?.seq
491
- }, {
492
- F: __dxlog_file3,
493
- L: 140,
494
- S: this,
495
- C: (f, a) => f(...a)
496
- });
497
- return block;
498
- }
499
475
  /**
500
476
  * Gets the next block from the selected queue.
501
477
  */
502
478
  async _nextBlock() {
503
479
  let t;
504
480
  while (this._running) {
505
- let stalled = false;
506
481
  const queues = Array.from(this._feedQueues.values());
507
- const blocks = queues.map((queue) => queue.peek()).filter(isNotNullOrUndefined);
482
+ const blocks = queues.map((queue) => queue.peek()).filter(isNonNullable);
508
483
  if (blocks.length) {
509
484
  const idx = this._selector(blocks);
510
485
  log3("selected", {
@@ -512,7 +487,7 @@ var FeedSetIterator = class extends AbstractFeedIterator {
512
487
  blocks
513
488
  }, {
514
489
  F: __dxlog_file3,
515
- L: 158,
490
+ L: 143,
516
491
  S: this,
517
492
  C: (f, a) => f(...a)
518
493
  });
@@ -521,7 +496,6 @@ var FeedSetIterator = class extends AbstractFeedIterator {
521
496
  t = setTimeout(() => {
522
497
  this.stalled.emit(this);
523
498
  this._trigger.wake();
524
- stalled = true;
525
499
  }, this.options.stallTimeout);
526
500
  }
527
501
  } else {
@@ -535,7 +509,7 @@ var FeedSetIterator = class extends AbstractFeedIterator {
535
509
  const queue = this._feedQueues.get(blocks[idx].feedKey);
536
510
  log3("popping", queue.toJSON(), {
537
511
  F: __dxlog_file3,
538
- L: 179,
512
+ L: 163,
539
513
  S: this,
540
514
  C: (f, a) => f(...a)
541
515
  });
@@ -543,7 +517,7 @@ var FeedSetIterator = class extends AbstractFeedIterator {
543
517
  const message = await queue.pop();
544
518
  invariant3(message === blocks[idx], void 0, {
545
519
  F: __dxlog_file3,
546
- L: 182,
520
+ L: 166,
547
521
  S: this,
548
522
  A: [
549
523
  "message === blocks[idx]",
@@ -556,19 +530,14 @@ var FeedSetIterator = class extends AbstractFeedIterator {
556
530
  feedKey: queue.feed.key
557
531
  }, {
558
532
  F: __dxlog_file3,
559
- L: 186,
533
+ L: 170,
560
534
  S: this,
561
535
  C: (f, a) => f(...a)
562
536
  });
563
537
  }
564
538
  }
565
- } else if (this._reiterateBlocks.length) {
566
- return this._getNextBlockForReiteration();
567
539
  }
568
540
  await this._trigger.wait();
569
- if (stalled && this._reiterateBlocks.length) {
570
- return this._getNextBlockForReiteration();
571
- }
572
541
  }
573
542
  }
574
543
  };
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/feed-iterator.ts", "../../../src/feed-queue.ts", "../../../src/feed-set-iterator.ts", "../../../src/feed-writer.ts"],
4
- "sourcesContent": ["//\n// Copyright 2020 DXOS.org\n//\n\nimport safeRace from 'race-as-promised';\n\nimport { Trigger } from '@dxos/async';\nimport { invariant } from '@dxos/invariant';\nimport { log } from '@dxos/log';\n\nimport { FeedQueue } from './feed-queue';\nimport { type FeedWrapper } from './feed-wrapper';\nimport { type FeedBlock } from './types';\n\n/**\n * Base class for an async iterable feed.\n */\nexport abstract class AbstractFeedIterator<T> implements AsyncIterable<FeedBlock<T>> {\n private readonly _stopTrigger = new Trigger();\n\n protected _open = false;\n protected _running = false;\n\n toJSON() {\n return {\n open: this.isOpen,\n running: this.isRunning,\n };\n }\n\n get isOpen() {\n return this._open;\n }\n\n get isRunning() {\n return this._running;\n }\n\n async open() {\n if (!this._open) {\n log('opening...');\n await this._onOpen();\n this._open = true;\n\n await this.start();\n log('opened');\n }\n }\n\n async close() {\n if (this._open) {\n log('closing...');\n await this.stop();\n\n await this._onClose();\n this._open = false;\n log('closed');\n }\n }\n\n async start() {\n invariant(this._open);\n if (!this._running) {\n this._running = true;\n }\n }\n\n async stop() {\n invariant(this._open);\n if (this._running) {\n this._running = false;\n this._stopTrigger.wake();\n }\n }\n\n //\n // AsyncIterable\n //\n\n [Symbol.asyncIterator]() {\n return this._generator();\n }\n\n async *_generator() {\n log('started');\n while (this._running) {\n // https://github.com/nodejs/node/issues/17469\n const block = await safeRace([this._stopTrigger.wait(), this._nextBlock()]);\n\n if (block === undefined) {\n break;\n }\n\n yield block;\n }\n\n log('stopped');\n }\n\n abstract _onOpen(): Promise<void>;\n abstract _onClose(): Promise<void>;\n abstract _nextBlock(): Promise<FeedBlock<T> | undefined>;\n}\n\n/**\n * Iterator that reads blocks from a single feed.\n */\nexport class FeedIterator<T extends {}> extends AbstractFeedIterator<T> {\n private readonly _queue: FeedQueue<T>;\n\n constructor(private readonly _feed: FeedWrapper<T>) {\n super();\n this._queue = new FeedQueue<T>(this._feed);\n }\n\n override async _onOpen(): Promise<void> {\n await this._queue.open();\n }\n\n override async _onClose(): Promise<void> {\n await this._queue.close();\n }\n\n override async _nextBlock(): Promise<FeedBlock<T> | undefined> {\n return this._queue.pop();\n }\n}\n", "//\n// Copyright 2022 DXOS.org\n//\n\nimport { inspect } from 'node:util';\nimport { Writable } from 'streamx';\n\nimport { Event, latch, Trigger } from '@dxos/async';\nimport { inspectObject } from '@dxos/debug';\nimport type { ReadStreamOptions } from '@dxos/hypercore';\nimport { invariant } from '@dxos/invariant';\nimport { log } from '@dxos/log';\n\nimport { type FeedWrapper } from './feed-wrapper';\nimport { type FeedBlock } from './types';\n\nexport const defaultReadStreamOptions: ReadStreamOptions = {\n live: true, // Keep reading until closed.\n batch: 1024, // Read in batches.\n};\n\nexport type FeedQueueOptions = {};\n\n/**\n * Async queue using an AsyncIterator created from a hypercore.\n */\nexport class FeedQueue<T extends {}> {\n public updated = new Event<FeedQueue<T>>();\n\n private readonly _messageTrigger = new Trigger<FeedBlock<T>>({\n autoReset: true,\n });\n\n private _feedConsumer?: Writable = undefined;\n private _next?: () => void;\n private _currentBlock?: FeedBlock<T> = undefined;\n private _index = -1;\n\n // prettier-ignore\n constructor(\n private readonly _feed: FeedWrapper<T>,\n private readonly _options: FeedQueueOptions = {},\n ) {}\n\n [inspect.custom]() {\n return inspectObject(this);\n }\n\n toJSON() {\n return {\n feedKey: this._feed.key,\n index: this.index,\n length: this.length,\n open: this.isOpen,\n };\n }\n\n get feed() {\n return this._feed;\n }\n\n get isOpen(): boolean {\n return Boolean(this._feedConsumer);\n }\n\n get length(): number {\n return this._feed.properties.length;\n }\n\n /**\n * Index (seq) of the NEXT block to be read, or -1 if not open.\n */\n get index() {\n return this._index;\n }\n\n /**\n * Opens (or reopens) the queue.\n * @param options.start Starting index. First mutation to be read would have `seq == options.start`.\n */\n async open(options: ReadStreamOptions = {}) {\n if (this.isOpen) {\n // TODO(burdon): Warn if re-opening (e.g., with different starting point).\n return;\n }\n\n this._index = options.start ?? 0;\n // if (this._index !== 0) {\n // console.warn('Start index not yet supported.');\n // }\n\n log('opening', { feedKey: this._feed.key });\n\n // TODO(burdon): Open with starting range.\n const opts = Object.assign({}, defaultReadStreamOptions, options);\n const feedStream = this._feed.createReadableStream(opts);\n\n this._feedConsumer = new Writable({\n write: (data: any, next: () => void) => {\n this._next = () => {\n this._next = undefined;\n this._currentBlock = undefined;\n this._index++;\n next();\n };\n\n this._currentBlock = {\n feedKey: this._feed.key,\n seq: this._index,\n data,\n };\n\n this._messageTrigger.wake(this._currentBlock);\n this.updated.emit(this);\n },\n });\n\n const onClose = () => {\n this.feed.core.off('close', onClose);\n this._feedConsumer?.off('close', onClose);\n this._feedConsumer?.off('error', onError);\n\n this._destroyConsumer();\n };\n\n const onError = (err?: Error) => {\n if (!err) {\n return;\n }\n\n if (err.message === 'Writable stream closed prematurely' || err.message === 'Feed is closed') {\n return;\n }\n\n log.catch(err, { feedKey: this._feed.key });\n };\n\n // Called if feed is closed externally.\n this._feed.core.once('close', onClose);\n this._feedConsumer.on('error', onError);\n\n // Called when queue is closed. Throws exception if waiting for `pop`.\n this._feedConsumer.once('close', onClose);\n\n // Pipe readable stream into writable consumer.\n feedStream.pipe(this._feedConsumer, (err) => {\n if (err) {\n onError(err);\n }\n this._destroyConsumer();\n });\n\n log('opened');\n }\n\n /**\n * Closes the queue.\n */\n async close() {\n if (this.isOpen) {\n invariant(this._feedConsumer);\n invariant(!this._feed.properties.closed);\n\n log('closing', { feedKey: this._feed.key });\n const [closed, setClosed] = latch();\n this._feedConsumer.once('close', setClosed);\n this._feedConsumer.destroy();\n this._next?.(); // Release any message currently in the queue (otherwise destroy will block).\n await closed();\n log('closed');\n }\n }\n\n /**\n * Get the block at the head of the queue without removing it.\n */\n peek(): FeedBlock<T> | undefined {\n return this._currentBlock;\n }\n\n /**\n * Pop block at the head of the queue.\n */\n async pop(): Promise<FeedBlock<T>> {\n if (!this.isOpen) {\n throw new Error(`Queue closed: ${this.feed.key.truncate()}`);\n }\n\n let block = this.peek();\n if (!block) {\n block = await this._messageTrigger.wait();\n }\n\n if (block) {\n this._next?.();\n }\n\n return block;\n }\n\n private _destroyConsumer() {\n if (this._feedConsumer) {\n log('queue closed', { feedKey: this._feed.key });\n this._feedConsumer = undefined;\n this._next = undefined;\n this._currentBlock = undefined;\n this._index = -1;\n }\n }\n}\n", "//\n// Copyright 2020 DXOS.org\n//\n\nimport { inspect } from 'node:util';\n\nimport { Event, EventSubscriptions, Trigger } from '@dxos/async';\nimport { inspectObject } from '@dxos/debug';\nimport { invariant } from '@dxos/invariant';\nimport { PublicKey } from '@dxos/keys';\nimport { log } from '@dxos/log';\nimport { ComplexMap, isNotNullOrUndefined } from '@dxos/util';\n\nimport { AbstractFeedIterator } from './feed-iterator';\nimport { FeedQueue } from './feed-queue';\nimport { type FeedWrapper } from './feed-wrapper';\nimport { type FeedBlock } from './types';\n\n/**\n * Select next block.\n */\nexport type FeedBlockSelector<T> = (blocks: FeedBlock<T>[]) => number | undefined;\n\nexport type FeedIndex = {\n feedKey: PublicKey;\n index: number;\n};\n\nexport type FeedSetIteratorOptions = {\n // TODO(burdon): Should we remove this and assume the feeds are positioned before adding?\n start?: FeedIndex[];\n stallTimeout?: number;\n};\n\nexport const defaultFeedSetIteratorOptions = {\n stallTimeout: 1000,\n};\n\n/**\n * Iterator that reads blocks from multiple feeds, ordering them based on a traversal callback.\n */\nexport class FeedSetIterator<T extends {}> extends AbstractFeedIterator<T> {\n private readonly _feedQueues = new ComplexMap<PublicKey, FeedQueue<T>>(PublicKey.hash);\n\n private readonly _trigger = new Trigger({ autoReset: true });\n private readonly _subscriptions = new EventSubscriptions();\n\n public readonly stalled = new Event<FeedSetIterator<T>>();\n\n /**\n * Blocks to be retried once all feeds are processed or stalled.\n * It is used to retry blocks that failed to be processed.\n */\n private readonly _reiterateBlocks: FeedBlock<T>[] = [];\n\n constructor(\n private readonly _selector: FeedBlockSelector<T>,\n public readonly options: FeedSetIteratorOptions = defaultFeedSetIteratorOptions,\n ) {\n super();\n invariant(_selector);\n invariant(options);\n }\n\n [inspect.custom]() {\n return inspectObject(this);\n }\n\n override toJSON() {\n return {\n open: this.isOpen,\n running: this.isRunning,\n indexes: this.indexes,\n };\n }\n\n get size() {\n return this._feedQueues.size;\n }\n\n get feeds(): FeedWrapper<T>[] {\n return Array.from(this._feedQueues.values()).map((feedQueue) => feedQueue.feed);\n }\n\n get indexes(): FeedIndex[] {\n return Array.from(this._feedQueues.values()).map((feedQueue) => ({\n feedKey: feedQueue.feed.key,\n index: feedQueue.index,\n }));\n }\n\n reiterateBlock(block: FeedBlock<T>) {\n this._reiterateBlocks.push(block);\n this._trigger.wake();\n }\n\n async addFeed(feed: FeedWrapper<T>) {\n invariant(!this._feedQueues.has(feed.key), `Feed already added: ${feed.key}`);\n invariant(feed.properties.opened);\n log('feed added', { feedKey: feed.key });\n\n // Create queue and listen for updates.\n const queue = new FeedQueue<T>(feed);\n this._feedQueues.set(feed.key, queue);\n this._subscriptions.add(\n queue.updated.on(() => {\n this._trigger.wake();\n }),\n );\n\n await queue.open({\n start: this.options.start?.find((index) => index.feedKey.equals(feed.key))?.index,\n });\n\n // Wake when feed added or queue updated.\n this._trigger.wake();\n }\n\n hasFeed(feedKey: PublicKey) {\n return this._feedQueues.has(feedKey);\n }\n\n override async _onOpen(): Promise<void> {\n for (const queue of this._feedQueues.values()) {\n await queue.open();\n }\n }\n\n override async _onClose(): Promise<void> {\n this._subscriptions.clear();\n await Promise.all(Array.from(this._feedQueues.values()).map((queue) => queue.close()));\n\n // Wake when feed added or queue updated.\n this._trigger.wake();\n }\n\n private _getNextBlockForReiteration() {\n const block = this._reiterateBlocks.shift();\n invariant(block);\n log('reiterate', { key: block?.feedKey.toHex(), seq: block?.seq });\n return block;\n }\n\n /**\n * Gets the next block from the selected queue.\n */\n override async _nextBlock(): Promise<FeedBlock<T> | undefined> {\n let t: NodeJS.Timeout | undefined;\n\n while (this._running) {\n let stalled = false;\n // Get blocks from the head of each queue.\n const queues = Array.from(this._feedQueues.values());\n const blocks = queues.map((queue) => queue.peek()).filter(isNotNullOrUndefined);\n if (blocks.length) {\n // Get the selected block from candidates.\n const idx = this._selector(blocks);\n log('selected', { idx, blocks });\n if (idx === undefined) {\n // Timeout if all candidates are rejected.\n if (t === undefined) {\n t = setTimeout(() => {\n this.stalled.emit(this);\n this._trigger.wake();\n stalled = true;\n }, this.options.stallTimeout);\n }\n } else {\n if (t !== undefined) {\n clearTimeout(t);\n t = undefined;\n }\n if (idx >= blocks.length) {\n throw new Error(`Index out of bounds: ${idx} of ${blocks.length}`);\n }\n\n // Pop from queue.\n const queue = this._feedQueues.get(blocks[idx].feedKey)!;\n log('popping', queue.toJSON());\n try {\n const message = await queue.pop();\n invariant(message === blocks[idx]);\n return message;\n } catch (err) {\n // TODO(burdon): Same queue closed twice.\n log.warn('queue closed', { feedKey: queue.feed.key });\n // console.log(Array.from(this._feedQueues.values()));\n }\n }\n } else if (this._reiterateBlocks.length) {\n return this._getNextBlockForReiteration();\n }\n\n // Wait until feed added, new block, or closing.\n await this._trigger.wait();\n if (stalled && this._reiterateBlocks.length) {\n return this._getNextBlockForReiteration();\n }\n }\n }\n}\n", "//\n// Copyright 2022 DXOS.org\n//\n\nimport { type PublicKey } from '@dxos/keys';\n\nexport type WriteReceipt = {\n feedKey: PublicKey;\n seq: number;\n};\n\nexport type WriteOptions = {\n /**\n * Called after the write is complete.\n * Runs and completes before the mutation is read from the pipeline.\n */\n afterWrite?: (receipt: WriteReceipt) => Promise<void>;\n};\n\nexport interface FeedWriter<T extends {}> {\n /**\n * Write data to the feed.\n * Awaits `afterWrite` before returning.\n */\n write(data: T, options?: WriteOptions): Promise<WriteReceipt>;\n}\n\nexport const createFeedWriter = <T extends {}>(cb: (data: T) => Promise<WriteReceipt>): FeedWriter<T> => ({\n write: async (data: T) => {\n return cb(data);\n },\n});\n\nexport const writeMessages = async <T extends {}>(writer: FeedWriter<T>, messages: T[]): Promise<WriteReceipt[]> => {\n const receipts: WriteReceipt[] = [];\n // NOTE: Write messages sequentially.\n for (const message of messages) {\n receipts.push(await writer.write(message));\n }\n return receipts;\n};\n"],
5
- "mappings": ";;;;;;;;AAIA,OAAOA,cAAc;AAErB,SAASC,WAAAA,gBAAe;AACxB,SAASC,aAAAA,kBAAiB;AAC1B,SAASC,OAAAA,YAAW;;;ACJpB,SAASC,eAAe;AACxB,SAASC,gBAAgB;AAEzB,SAASC,OAAOC,OAAOC,eAAe;AACtC,SAASC,qBAAqB;AAE9B,SAASC,iBAAiB;AAC1B,SAASC,WAAW;;AAKb,IAAMC,2BAA8C;EACzDC,MA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GE,IAAAA;EACZ;AACF;AAEO,IAAMC,gBAAgB,OAAqBC,QAAuBC,aAAAA;AACvE,QAAMC,WAA2B,CAAA;AAEjC,aAAWC,WAAWF,UAAU;AAC9BC,aAASE,KAAK,MAAMJ,OAAOH,MAAMM,OAAAA,CAAAA;EACnC;AACA,SAAOD;AACT;",
6
- "names": ["safeRace", "Trigger", "invariant", "log", "inspect", "Writable", "Event", "latch", "Trigger", "inspectObject", "invariant", "log", "defaultReadStreamOptions", "live", "batch", "FeedQueue", "constructor", "_feed", "_options", "updated", "_messageTrigger", "autoReset", "_feedConsumer", "undefined", "_currentBlock", "_index", "custom", "toJSON", "feedKey", "key", "index", "length", "open", "isOpen", "feed", "Boolean", "properties", "options", "start", "opts", "Object", "assign", "feedStream", "createReadableStream", "write", "data", "next", "_next", "seq", "wake", "emit", "onClose", "core", "off", "onError", "_destroyConsumer", "err", "message", "catch", "once", "on", "pipe", "close", "closed", "setClosed", "destroy", "peek", "pop", "Error", "truncate", "block", "wait", "AbstractFeedIterator", "_stopTrigger", "Trigger", "_open", "_running", "toJSON", "open", "isOpen", "running", "isRunning", "log", "_onOpen", "start", "close", "stop", "_onClose", "invariant", "wake", "Symbol", "asyncIterator", "_generator", "block", "safeRace", "wait", "_nextBlock", "undefined", "FeedIterator", "constructor", "_feed", "_queue", "FeedQueue", "pop", "inspect", "Event", "EventSubscriptions", "Trigger", "inspectObject", "invariant", "PublicKey", "log", "ComplexMap", "isNotNullOrUndefined", "defaultFeedSetIteratorOptions", "stallTimeout", "FeedSetIterator", "AbstractFeedIterator", "constructor", "_selector", "options", "_feedQueues", "ComplexMap", "PublicKey", "hash", "_trigger", "Trigger", "autoReset", "_subscriptions", "EventSubscriptions", "stalled", "Event", "_reiterateBlocks", "invariant", "inspect", "custom", "inspectObject", "toJSON", "open", "isOpen", "running", "isRunning", "indexes", "size", "feeds", "Array", "from", "values", "map", "feedQueue", "feed", "feedKey", "key", "index", "reiterateBlock", "block", "push", "wake", "addFeed", "has", "properties", "opened", "log", "queue", "FeedQueue", "set", "add", "updated", "on", "start", "find", "equals", "hasFeed", "_onOpen", "_onClose", "clear", "Promise", "all", "close", "_getNextBlockForReiteration", "shift", "toHex", "seq", "_nextBlock", "t", "_running", "queues", "blocks", "peek", "filter", "isNotNullOrUndefined", "length", "idx", "undefined", "setTimeout", "emit", "clearTimeout", "Error", "get", "message", "pop", "err", "warn", "wait", "createFeedWriter", "cb", "write", "data", "writeMessages", "writer", "messages", "receipts", "message", "push"]
4
+ "sourcesContent": ["//\n// Copyright 2020 DXOS.org\n//\n\nimport safeRace from 'race-as-promised';\n\nimport { Trigger } from '@dxos/async';\nimport { invariant } from '@dxos/invariant';\nimport { log } from '@dxos/log';\n\nimport { FeedQueue } from './feed-queue';\nimport { type FeedWrapper } from './feed-wrapper';\nimport { type FeedBlock } from './types';\n\n/**\n * Base class for an async iterable feed.\n */\nexport abstract class AbstractFeedIterator<T> implements AsyncIterable<FeedBlock<T>> {\n private readonly _stopTrigger = new Trigger();\n\n protected _open = false;\n protected _running = false;\n\n toJSON() {\n return {\n open: this.isOpen,\n running: this.isRunning,\n };\n }\n\n get isOpen() {\n return this._open;\n }\n\n get isRunning() {\n return this._running;\n }\n\n async open() {\n if (!this._open) {\n log('opening...');\n await this._onOpen();\n this._open = true;\n\n await this.start();\n log('opened');\n }\n }\n\n async close() {\n if (this._open) {\n log('closing...');\n await this.stop();\n\n await this._onClose();\n this._open = false;\n log('closed');\n }\n }\n\n async start() {\n invariant(this._open);\n if (!this._running) {\n this._running = true;\n }\n }\n\n async stop() {\n invariant(this._open);\n if (this._running) {\n this._running = false;\n this._stopTrigger.wake();\n }\n }\n\n //\n // AsyncIterable\n //\n\n [Symbol.asyncIterator]() {\n return this._generator();\n }\n\n async *_generator() {\n log('started');\n while (this._running) {\n // https://github.com/nodejs/node/issues/17469\n const block = await safeRace([this._stopTrigger.wait(), this._nextBlock()]);\n\n if (block === undefined) {\n break;\n }\n\n yield block;\n }\n\n log('stopped');\n }\n\n abstract _onOpen(): Promise<void>;\n abstract _onClose(): Promise<void>;\n abstract _nextBlock(): Promise<FeedBlock<T> | undefined>;\n}\n\n/**\n * Iterator that reads blocks from a single feed.\n */\nexport class FeedIterator<T extends {}> extends AbstractFeedIterator<T> {\n private readonly _queue: FeedQueue<T>;\n\n constructor(private readonly _feed: FeedWrapper<T>) {\n super();\n this._queue = new FeedQueue<T>(this._feed);\n }\n\n override async _onOpen(): Promise<void> {\n await this._queue.open();\n }\n\n override async _onClose(): Promise<void> {\n await this._queue.close();\n }\n\n override async _nextBlock(): Promise<FeedBlock<T> | undefined> {\n return this._queue.pop();\n }\n}\n", "//\n// Copyright 2022 DXOS.org\n//\n\nimport { inspect } from 'node:util';\nimport { Writable } from 'streamx';\n\nimport { Event, latch, Trigger } from '@dxos/async';\nimport { inspectObject } from '@dxos/debug';\nimport type { ReadStreamOptions } from '@dxos/hypercore';\nimport { invariant } from '@dxos/invariant';\nimport { log } from '@dxos/log';\n\nimport { type FeedWrapper } from './feed-wrapper';\nimport { type FeedBlock } from './types';\n\nexport const defaultReadStreamOptions: ReadStreamOptions = {\n live: true, // Keep reading until closed.\n batch: 1024, // Read in batches.\n};\n\nexport type FeedQueueOptions = {};\n\n/**\n * Async queue using an AsyncIterator created from a hypercore.\n */\nexport class FeedQueue<T extends {}> {\n public updated = new Event<FeedQueue<T>>();\n\n private readonly _messageTrigger = new Trigger<FeedBlock<T>>({\n autoReset: true,\n });\n\n private _feedConsumer?: Writable = undefined;\n private _next?: () => void;\n private _currentBlock?: FeedBlock<T> = undefined;\n private _index = -1;\n\n // prettier-ignore\n constructor(\n private readonly _feed: FeedWrapper<T>,\n private readonly _options: FeedQueueOptions = {},\n ) {}\n\n [inspect.custom]() {\n return inspectObject(this);\n }\n\n toJSON() {\n return {\n feedKey: this._feed.key,\n index: this.index,\n length: this.length,\n open: this.isOpen,\n };\n }\n\n get feed() {\n return this._feed;\n }\n\n get isOpen(): boolean {\n return Boolean(this._feedConsumer);\n }\n\n get length(): number {\n return this._feed.properties.length;\n }\n\n /**\n * Index (seq) of the NEXT block to be read, or -1 if not open.\n */\n get index() {\n return this._index;\n }\n\n /**\n * Opens (or reopens) the queue.\n * @param options.start Starting index. First mutation to be read would have `seq == options.start`.\n */\n async open(options: ReadStreamOptions = {}) {\n if (this.isOpen) {\n // TODO(burdon): Warn if re-opening (e.g., with different starting point).\n return;\n }\n\n this._index = options.start ?? 0;\n // if (this._index !== 0) {\n // console.warn('Start index not yet supported.');\n // }\n\n log('opening', { feedKey: this._feed.key });\n\n // TODO(burdon): Open with starting range.\n const opts = Object.assign({}, defaultReadStreamOptions, options);\n const feedStream = this._feed.createReadableStream(opts);\n\n this._feedConsumer = new Writable({\n write: (data: any, next: () => void) => {\n this._next = () => {\n this._next = undefined;\n this._currentBlock = undefined;\n this._index++;\n next();\n };\n\n this._currentBlock = {\n feedKey: this._feed.key,\n seq: this._index,\n data,\n };\n\n this._messageTrigger.wake(this._currentBlock);\n this.updated.emit(this);\n },\n });\n\n const onClose = () => {\n this.feed.core.off('close', onClose);\n this._feedConsumer?.off('close', onClose);\n this._feedConsumer?.off('error', onError);\n\n this._destroyConsumer();\n };\n\n const onError = (err?: Error) => {\n if (!err) {\n return;\n }\n\n if (err.message === 'Writable stream closed prematurely' || err.message === 'Feed is closed') {\n return;\n }\n\n log.catch(err, { feedKey: this._feed.key });\n };\n\n // Called if feed is closed externally.\n this._feed.core.once('close', onClose);\n this._feedConsumer.on('error', onError);\n\n // Called when queue is closed. Throws exception if waiting for `pop`.\n this._feedConsumer.once('close', onClose);\n\n // Pipe readable stream into writable consumer.\n feedStream.pipe(this._feedConsumer, (err) => {\n if (err) {\n onError(err);\n }\n this._destroyConsumer();\n });\n\n log('opened');\n }\n\n /**\n * Closes the queue.\n */\n async close() {\n if (this.isOpen) {\n invariant(this._feedConsumer);\n invariant(!this._feed.properties.closed);\n\n log('closing', { feedKey: this._feed.key });\n const [closed, setClosed] = latch();\n this._feedConsumer.once('close', setClosed);\n this._feedConsumer.destroy();\n this._next?.(); // Release any message currently in the queue (otherwise destroy will block).\n await closed();\n log('closed');\n }\n }\n\n /**\n * Get the block at the head of the queue without removing it.\n */\n peek(): FeedBlock<T> | undefined {\n return this._currentBlock;\n }\n\n /**\n * Pop block at the head of the queue.\n */\n async pop(): Promise<FeedBlock<T>> {\n if (!this.isOpen) {\n throw new Error(`Queue closed: ${this.feed.key.truncate()}`);\n }\n\n let block = this.peek();\n if (!block) {\n block = await this._messageTrigger.wait();\n }\n\n if (block) {\n this._next?.();\n }\n\n return block;\n }\n\n private _destroyConsumer() {\n if (this._feedConsumer) {\n log('queue closed', { feedKey: this._feed.key });\n this._feedConsumer = undefined;\n this._next = undefined;\n this._currentBlock = undefined;\n this._index = -1;\n }\n }\n}\n", "//\n// Copyright 2020 DXOS.org\n//\n\nimport { inspect } from 'node:util';\n\nimport { Event, EventSubscriptions, Trigger } from '@dxos/async';\nimport { inspectObject } from '@dxos/debug';\nimport { invariant } from '@dxos/invariant';\nimport { PublicKey } from '@dxos/keys';\nimport { log } from '@dxos/log';\nimport { ComplexMap, isNonNullable } from '@dxos/util';\n\nimport { AbstractFeedIterator } from './feed-iterator';\nimport { FeedQueue } from './feed-queue';\nimport { type FeedWrapper } from './feed-wrapper';\nimport { type FeedBlock } from './types';\n\n/**\n * Select next block.\n */\nexport type FeedBlockSelector<T> = (blocks: FeedBlock<T>[]) => number | undefined;\n\nexport type FeedIndex = {\n feedKey: PublicKey;\n index: number;\n};\n\nexport type FeedSetIteratorOptions = {\n // TODO(burdon): Should we remove this and assume the feeds are positioned before adding?\n start?: FeedIndex[];\n stallTimeout?: number;\n};\n\nexport const defaultFeedSetIteratorOptions = {\n stallTimeout: 1000,\n};\n\n/**\n * Iterator that reads blocks from multiple feeds, ordering them based on a traversal callback.\n */\nexport class FeedSetIterator<T extends {}> extends AbstractFeedIterator<T> {\n private readonly _feedQueues = new ComplexMap<PublicKey, FeedQueue<T>>(PublicKey.hash);\n\n private readonly _trigger = new Trigger({ autoReset: true });\n private readonly _subscriptions = new EventSubscriptions();\n\n public readonly stalled = new Event<FeedSetIterator<T>>();\n\n constructor(\n private readonly _selector: FeedBlockSelector<T>,\n public readonly options: FeedSetIteratorOptions = defaultFeedSetIteratorOptions,\n ) {\n super();\n invariant(_selector);\n invariant(options);\n }\n\n [inspect.custom]() {\n return inspectObject(this);\n }\n\n override toJSON() {\n return {\n open: this.isOpen,\n running: this.isRunning,\n indexes: this.indexes,\n };\n }\n\n get size() {\n return this._feedQueues.size;\n }\n\n get feeds(): FeedWrapper<T>[] {\n return Array.from(this._feedQueues.values()).map((feedQueue) => feedQueue.feed);\n }\n\n get indexes(): FeedIndex[] {\n return Array.from(this._feedQueues.values()).map((feedQueue) => ({\n feedKey: feedQueue.feed.key,\n index: feedQueue.index,\n }));\n }\n\n reiterateBlock(block: FeedBlock<T>) {\n this._trigger.wake();\n }\n\n async addFeed(feed: FeedWrapper<T>) {\n invariant(!this._feedQueues.has(feed.key), `Feed already added: ${feed.key}`);\n invariant(feed.properties.opened);\n log('feed added', { feedKey: feed.key });\n\n // Create queue and listen for updates.\n const queue = new FeedQueue<T>(feed);\n this._feedQueues.set(feed.key, queue);\n this._subscriptions.add(\n queue.updated.on(() => {\n this._trigger.wake();\n }),\n );\n\n await queue.open({\n start: this.options.start?.find((index) => index.feedKey.equals(feed.key))?.index,\n });\n\n // Wake when feed added or queue updated.\n this._trigger.wake();\n }\n\n hasFeed(feedKey: PublicKey) {\n return this._feedQueues.has(feedKey);\n }\n\n override async _onOpen(): Promise<void> {\n for (const queue of this._feedQueues.values()) {\n await queue.open();\n }\n }\n\n override async _onClose(): Promise<void> {\n this._subscriptions.clear();\n await Promise.all(Array.from(this._feedQueues.values()).map((queue) => queue.close()));\n\n // Wake when feed added or queue updated.\n this._trigger.wake();\n }\n\n /**\n * Gets the next block from the selected queue.\n */\n override async _nextBlock(): Promise<FeedBlock<T> | undefined> {\n let t: NodeJS.Timeout | undefined;\n\n while (this._running) {\n // Get blocks from the head of each queue.\n const queues = Array.from(this._feedQueues.values());\n const blocks = queues.map((queue) => queue.peek()).filter(isNonNullable);\n if (blocks.length) {\n // Get the selected block from candidates.\n const idx = this._selector(blocks);\n log('selected', { idx, blocks });\n if (idx === undefined) {\n // Timeout if all candidates are rejected.\n if (t === undefined) {\n t = setTimeout(() => {\n this.stalled.emit(this);\n this._trigger.wake();\n }, this.options.stallTimeout);\n }\n } else {\n if (t !== undefined) {\n clearTimeout(t);\n t = undefined;\n }\n if (idx >= blocks.length) {\n throw new Error(`Index out of bounds: ${idx} of ${blocks.length}`);\n }\n\n // Pop from queue.\n const queue = this._feedQueues.get(blocks[idx].feedKey)!;\n log('popping', queue.toJSON());\n try {\n const message = await queue.pop();\n invariant(message === blocks[idx]);\n return message;\n } catch (err) {\n // TODO(burdon): Same queue closed twice.\n log.warn('queue closed', { feedKey: queue.feed.key });\n // console.log(Array.from(this._feedQueues.values()));\n }\n }\n }\n\n // Wait until feed added, new block, or closing.\n await this._trigger.wait();\n }\n }\n}\n", "//\n// Copyright 2022 DXOS.org\n//\n\nimport { type PublicKey } from '@dxos/keys';\n\nexport type WriteReceipt = {\n feedKey: PublicKey;\n seq: number;\n};\n\nexport type WriteOptions = {\n /**\n * Called after the write is complete.\n * Runs and completes before the mutation is read from the pipeline.\n */\n afterWrite?: (receipt: WriteReceipt) => Promise<void>;\n};\n\nexport interface FeedWriter<T extends {}> {\n /**\n * Write data to the feed.\n * Awaits `afterWrite` before returning.\n */\n write(data: T, options?: WriteOptions): Promise<WriteReceipt>;\n}\n\nexport const createFeedWriter = <T extends {}>(cb: (data: T) => Promise<WriteReceipt>): FeedWriter<T> => ({\n write: async (data: T) => {\n return cb(data);\n },\n});\n\nexport const writeMessages = async <T extends {}>(writer: FeedWriter<T>, messages: T[]): Promise<WriteReceipt[]> => {\n const receipts: WriteReceipt[] = [];\n // NOTE: Write messages sequentially.\n for (const message of messages) {\n receipts.push(await writer.write(message));\n }\n return receipts;\n};\n"],
5
+ "mappings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AACT;",
6
+ "names": ["safeRace", "Trigger", "invariant", "log", "inspect", "Writable", "Event", "latch", "Trigger", "inspectObject", "invariant", "log", "defaultReadStreamOptions", "live", "batch", "FeedQueue", "constructor", "_feed", "_options", "updated", "_messageTrigger", "autoReset", "_feedConsumer", "undefined", "_currentBlock", "_index", "custom", "toJSON", "feedKey", "key", "index", "length", "open", "isOpen", "feed", "Boolean", "properties", "options", "start", "opts", "Object", "assign", "feedStream", "createReadableStream", "write", "data", "next", "_next", "seq", "wake", "emit", "onClose", "core", "off", "onError", "_destroyConsumer", "err", "message", "catch", "once", "on", "pipe", "close", "closed", "setClosed", "destroy", "peek", "pop", "Error", "truncate", "block", "wait", "AbstractFeedIterator", "_stopTrigger", "Trigger", "_open", "_running", "toJSON", "open", "isOpen", "running", "isRunning", "log", "_onOpen", "start", "close", "stop", "_onClose", "invariant", "wake", "Symbol", "asyncIterator", "_generator", "block", "safeRace", "wait", "_nextBlock", "undefined", "FeedIterator", "constructor", "_feed", "_queue", "FeedQueue", "pop", "inspect", "Event", "EventSubscriptions", "Trigger", "inspectObject", "invariant", "PublicKey", "log", "ComplexMap", "isNonNullable", "defaultFeedSetIteratorOptions", "stallTimeout", "FeedSetIterator", "AbstractFeedIterator", "constructor", "_selector", "options", "_feedQueues", "ComplexMap", "PublicKey", "hash", "_trigger", "Trigger", "autoReset", "_subscriptions", "EventSubscriptions", "stalled", "Event", "invariant", "inspect", "custom", "inspectObject", "toJSON", "open", "isOpen", "running", "isRunning", "indexes", "size", "feeds", "Array", "from", "values", "map", "feedQueue", "feed", "feedKey", "key", "index", "reiterateBlock", "block", "wake", "addFeed", "has", "properties", "opened", "log", "queue", "FeedQueue", "set", "add", "updated", "on", "start", "find", "equals", "hasFeed", "_onOpen", "_onClose", "clear", "Promise", "all", "close", "_nextBlock", "t", "_running", "queues", "blocks", "peek", "filter", "isNonNullable", "length", "idx", "undefined", "setTimeout", "emit", "clearTimeout", "Error", "get", "message", "pop", "err", "warn", "wait", "createFeedWriter", "cb", "write", "data", "writeMessages", "writer", "messages", "receipts", "message", "push"]
7
7
  }
@@ -1 +1 @@
1
- {"inputs":{"packages/common/feed-store/src/feed-wrapper.ts":{"bytes":34379,"imports":[{"path":"@dxos/node-std/util","kind":"import-statement","external":true},{"path":"streamx","kind":"import-statement","external":true},{"path":"@dxos/async","kind":"import-statement","external":true},{"path":"@dxos/debug","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true}],"format":"esm"},"packages/common/feed-store/src/feed-factory.ts":{"bytes":9251,"imports":[{"path":"lodash.defaultsdeep","kind":"import-statement","external":true},{"path":"@dxos/crypto","kind":"import-statement","external":true},{"path":"@dxos/debug","kind":"import-statement","external":true},{"path":"@dxos/hypercore","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"packages/common/feed-store/src/feed-wrapper.ts","kind":"import-statement","original":"./feed-wrapper"}],"format":"esm"},"packages/common/feed-store/src/feed-queue.ts":{"bytes":19868,"imports":[{"path":"@dxos/node-std/util","kind":"import-statement","external":true},{"path":"streamx","kind":"import-statement","external":true},{"path":"@dxos/async","kind":"import-statement","external":true},{"path":"@dxos/debug","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true}],"format":"esm"},"packages/common/feed-store/src/feed-iterator.ts":{"bytes":10231,"imports":[{"path":"race-as-promised","kind":"import-statement","external":true},{"path":"@dxos/async","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"packages/common/feed-store/src/feed-queue.ts","kind":"import-statement","original":"./feed-queue"}],"format":"esm"},"packages/common/feed-store/src/feed-set-iterator.ts":{"bytes":23256,"imports":[{"path":"@dxos/node-std/util","kind":"import-statement","external":true},{"path":"@dxos/async","kind":"import-statement","external":true},{"path":"@dxos/debug","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/keys","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true},{"path":"packages/common/feed-store/src/feed-iterator.ts","kind":"import-statement","original":"./feed-iterator"},{"path":"packages/common/feed-store/src/feed-queue.ts","kind":"import-statement","original":"./feed-queue"}],"format":"esm"},"packages/common/feed-store/src/feed-store.ts":{"bytes":12315,"imports":[{"path":"@dxos/async","kind":"import-statement","external":true},{"path":"@dxos/debug","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/keys","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true}],"format":"esm"},"packages/common/feed-store/src/feed-writer.ts":{"bytes":2686,"imports":[],"format":"esm"},"packages/common/feed-store/src/types.ts":{"bytes":614,"imports":[],"format":"esm"},"packages/common/feed-store/src/index.ts":{"bytes":1196,"imports":[{"path":"packages/common/feed-store/src/feed-factory.ts","kind":"import-statement","original":"./feed-factory"},{"path":"packages/common/feed-store/src/feed-iterator.ts","kind":"import-statement","original":"./feed-iterator"},{"path":"packages/common/feed-store/src/feed-set-iterator.ts","kind":"import-statement","original":"./feed-set-iterator"},{"path":"packages/common/feed-store/src/feed-queue.ts","kind":"import-statement","original":"./feed-queue"},{"path":"packages/common/feed-store/src/feed-store.ts","kind":"import-statement","original":"./feed-store"},{"path":"packages/common/feed-store/src/feed-wrapper.ts","kind":"import-statement","original":"./feed-wrapper"},{"path":"packages/common/feed-store/src/feed-writer.ts","kind":"import-statement","original":"./feed-writer"},{"path":"packages/common/feed-store/src/types.ts","kind":"import-statement","original":"./types"}],"format":"esm"},"packages/common/feed-store/src/testing/mocks.ts":{"bytes":3541,"imports":[{"path":"@dxos/async","kind":"import-statement","external":true},{"path":"@dxos/context","kind":"import-statement","external":true},{"path":"@dxos/keys","kind":"import-statement","external":true}],"format":"esm"},"packages/common/feed-store/src/testing/test-generator.ts":{"bytes":5631,"imports":[{"path":"@dxos/async","kind":"import-statement","external":true},{"path":"@dxos/hypercore","kind":"import-statement","external":true},{"path":"@dxos/random","kind":"import-statement","external":true}],"format":"esm"},"packages/common/feed-store/src/testing/test-builder.ts":{"bytes":9730,"imports":[{"path":"@dxos/keyring","kind":"import-statement","external":true},{"path":"@dxos/random-access-storage","kind":"import-statement","external":true},{"path":"packages/common/feed-store/src/testing/test-generator.ts","kind":"import-statement","original":"./test-generator"},{"path":"packages/common/feed-store/src/feed-factory.ts","kind":"import-statement","original":"../feed-factory"},{"path":"packages/common/feed-store/src/feed-store.ts","kind":"import-statement","original":"../feed-store"}],"format":"esm"},"packages/common/feed-store/src/testing/index.ts":{"bytes":705,"imports":[{"path":"packages/common/feed-store/src/testing/mocks.ts","kind":"import-statement","original":"./mocks"},{"path":"packages/common/feed-store/src/testing/test-builder.ts","kind":"import-statement","original":"./test-builder"},{"path":"packages/common/feed-store/src/testing/test-generator.ts","kind":"import-statement","original":"./test-generator"}],"format":"esm"}},"outputs":{"packages/common/feed-store/dist/lib/browser/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":25451},"packages/common/feed-store/dist/lib/browser/index.mjs":{"imports":[{"path":"packages/common/feed-store/dist/lib/browser/chunk-I3RTOCTQ.mjs","kind":"import-statement"},{"path":"race-as-promised","kind":"import-statement","external":true},{"path":"@dxos/async","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"@dxos/node-std/util","kind":"import-statement","external":true},{"path":"streamx","kind":"import-statement","external":true},{"path":"@dxos/async","kind":"import-statement","external":true},{"path":"@dxos/debug","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"@dxos/node-std/util","kind":"import-statement","external":true},{"path":"@dxos/async","kind":"import-statement","external":true},{"path":"@dxos/debug","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/keys","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true}],"exports":["AbstractFeedIterator","FeedFactory","FeedIterator","FeedQueue","FeedSetIterator","FeedStore","FeedWrapper","createFeedWriter","defaultFeedSetIteratorOptions","defaultReadStreamOptions","writeMessages"],"entryPoint":"packages/common/feed-store/src/index.ts","inputs":{"packages/common/feed-store/src/index.ts":{"bytesInOutput":0},"packages/common/feed-store/src/feed-iterator.ts":{"bytesInOutput":2802},"packages/common/feed-store/src/feed-queue.ts":{"bytesInOutput":4935},"packages/common/feed-store/src/feed-set-iterator.ts":{"bytesInOutput":5749},"packages/common/feed-store/src/feed-writer.ts":{"bytesInOutput":273}},"bytes":14392},"packages/common/feed-store/dist/lib/browser/testing/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":9598},"packages/common/feed-store/dist/lib/browser/testing/index.mjs":{"imports":[{"path":"packages/common/feed-store/dist/lib/browser/chunk-I3RTOCTQ.mjs","kind":"import-statement"},{"path":"@dxos/async","kind":"import-statement","external":true},{"path":"@dxos/context","kind":"import-statement","external":true},{"path":"@dxos/keys","kind":"import-statement","external":true},{"path":"@dxos/keyring","kind":"import-statement","external":true},{"path":"@dxos/random-access-storage","kind":"import-statement","external":true},{"path":"@dxos/async","kind":"import-statement","external":true},{"path":"@dxos/hypercore","kind":"import-statement","external":true},{"path":"@dxos/random","kind":"import-statement","external":true}],"exports":["MockFeedWriter","TestBuilder","TestGenerator","TestItemBuilder","defaultCodec","defaultTestBlockGenerator","defaultTestGenerator","defaultValueEncoding"],"entryPoint":"packages/common/feed-store/src/testing/index.ts","inputs":{"packages/common/feed-store/src/testing/mocks.ts":{"bytesInOutput":784},"packages/common/feed-store/src/testing/index.ts":{"bytesInOutput":0},"packages/common/feed-store/src/testing/test-builder.ts":{"bytesInOutput":1800},"packages/common/feed-store/src/testing/test-generator.ts":{"bytesInOutput":961}},"bytes":4085},"packages/common/feed-store/dist/lib/browser/chunk-I3RTOCTQ.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":26062},"packages/common/feed-store/dist/lib/browser/chunk-I3RTOCTQ.mjs":{"imports":[{"path":"@dxos/node-std/util","kind":"import-statement","external":true},{"path":"streamx","kind":"import-statement","external":true},{"path":"@dxos/async","kind":"import-statement","external":true},{"path":"@dxos/debug","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true},{"path":"lodash.defaultsdeep","kind":"import-statement","external":true},{"path":"@dxos/crypto","kind":"import-statement","external":true},{"path":"@dxos/debug","kind":"import-statement","external":true},{"path":"@dxos/hypercore","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"@dxos/async","kind":"import-statement","external":true},{"path":"@dxos/debug","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/keys","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true}],"exports":["FeedFactory","FeedStore","FeedWrapper"],"inputs":{"packages/common/feed-store/src/feed-wrapper.ts":{"bytesInOutput":8215},"packages/common/feed-store/src/feed-factory.ts":{"bytesInOutput":2015},"packages/common/feed-store/src/feed-store.ts":{"bytesInOutput":3129}},"bytes":13642}}}
1
+ {"inputs":{"packages/common/feed-store/src/feed-wrapper.ts":{"bytes":34379,"imports":[{"path":"@dxos/node-std/util","kind":"import-statement","external":true},{"path":"streamx","kind":"import-statement","external":true},{"path":"@dxos/async","kind":"import-statement","external":true},{"path":"@dxos/debug","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true}],"format":"esm"},"packages/common/feed-store/src/feed-factory.ts":{"bytes":9251,"imports":[{"path":"lodash.defaultsdeep","kind":"import-statement","external":true},{"path":"@dxos/crypto","kind":"import-statement","external":true},{"path":"@dxos/debug","kind":"import-statement","external":true},{"path":"@dxos/hypercore","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"packages/common/feed-store/src/feed-wrapper.ts","kind":"import-statement","original":"./feed-wrapper"}],"format":"esm"},"packages/common/feed-store/src/feed-queue.ts":{"bytes":19868,"imports":[{"path":"@dxos/node-std/util","kind":"import-statement","external":true},{"path":"streamx","kind":"import-statement","external":true},{"path":"@dxos/async","kind":"import-statement","external":true},{"path":"@dxos/debug","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true}],"format":"esm"},"packages/common/feed-store/src/feed-iterator.ts":{"bytes":10231,"imports":[{"path":"race-as-promised","kind":"import-statement","external":true},{"path":"@dxos/async","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"packages/common/feed-store/src/feed-queue.ts","kind":"import-statement","original":"./feed-queue"}],"format":"esm"},"packages/common/feed-store/src/feed-set-iterator.ts":{"bytes":20352,"imports":[{"path":"@dxos/node-std/util","kind":"import-statement","external":true},{"path":"@dxos/async","kind":"import-statement","external":true},{"path":"@dxos/debug","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/keys","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true},{"path":"packages/common/feed-store/src/feed-iterator.ts","kind":"import-statement","original":"./feed-iterator"},{"path":"packages/common/feed-store/src/feed-queue.ts","kind":"import-statement","original":"./feed-queue"}],"format":"esm"},"packages/common/feed-store/src/feed-store.ts":{"bytes":12315,"imports":[{"path":"@dxos/async","kind":"import-statement","external":true},{"path":"@dxos/debug","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/keys","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true}],"format":"esm"},"packages/common/feed-store/src/feed-writer.ts":{"bytes":2686,"imports":[],"format":"esm"},"packages/common/feed-store/src/types.ts":{"bytes":614,"imports":[],"format":"esm"},"packages/common/feed-store/src/index.ts":{"bytes":1196,"imports":[{"path":"packages/common/feed-store/src/feed-factory.ts","kind":"import-statement","original":"./feed-factory"},{"path":"packages/common/feed-store/src/feed-iterator.ts","kind":"import-statement","original":"./feed-iterator"},{"path":"packages/common/feed-store/src/feed-set-iterator.ts","kind":"import-statement","original":"./feed-set-iterator"},{"path":"packages/common/feed-store/src/feed-queue.ts","kind":"import-statement","original":"./feed-queue"},{"path":"packages/common/feed-store/src/feed-store.ts","kind":"import-statement","original":"./feed-store"},{"path":"packages/common/feed-store/src/feed-wrapper.ts","kind":"import-statement","original":"./feed-wrapper"},{"path":"packages/common/feed-store/src/feed-writer.ts","kind":"import-statement","original":"./feed-writer"},{"path":"packages/common/feed-store/src/types.ts","kind":"import-statement","original":"./types"}],"format":"esm"},"packages/common/feed-store/src/testing/mocks.ts":{"bytes":3541,"imports":[{"path":"@dxos/async","kind":"import-statement","external":true},{"path":"@dxos/context","kind":"import-statement","external":true},{"path":"@dxos/keys","kind":"import-statement","external":true}],"format":"esm"},"packages/common/feed-store/src/testing/test-generator.ts":{"bytes":5631,"imports":[{"path":"@dxos/async","kind":"import-statement","external":true},{"path":"@dxos/hypercore","kind":"import-statement","external":true},{"path":"@dxos/random","kind":"import-statement","external":true}],"format":"esm"},"packages/common/feed-store/src/testing/test-builder.ts":{"bytes":9730,"imports":[{"path":"@dxos/keyring","kind":"import-statement","external":true},{"path":"@dxos/random-access-storage","kind":"import-statement","external":true},{"path":"packages/common/feed-store/src/testing/test-generator.ts","kind":"import-statement","original":"./test-generator"},{"path":"packages/common/feed-store/src/feed-factory.ts","kind":"import-statement","original":"../feed-factory"},{"path":"packages/common/feed-store/src/feed-store.ts","kind":"import-statement","original":"../feed-store"}],"format":"esm"},"packages/common/feed-store/src/testing/index.ts":{"bytes":705,"imports":[{"path":"packages/common/feed-store/src/testing/mocks.ts","kind":"import-statement","original":"./mocks"},{"path":"packages/common/feed-store/src/testing/test-builder.ts","kind":"import-statement","original":"./test-builder"},{"path":"packages/common/feed-store/src/testing/test-generator.ts","kind":"import-statement","original":"./test-generator"}],"format":"esm"}},"outputs":{"packages/common/feed-store/dist/lib/browser/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":24195},"packages/common/feed-store/dist/lib/browser/index.mjs":{"imports":[{"path":"packages/common/feed-store/dist/lib/browser/chunk-I3RTOCTQ.mjs","kind":"import-statement"},{"path":"race-as-promised","kind":"import-statement","external":true},{"path":"@dxos/async","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"@dxos/node-std/util","kind":"import-statement","external":true},{"path":"streamx","kind":"import-statement","external":true},{"path":"@dxos/async","kind":"import-statement","external":true},{"path":"@dxos/debug","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"@dxos/node-std/util","kind":"import-statement","external":true},{"path":"@dxos/async","kind":"import-statement","external":true},{"path":"@dxos/debug","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/keys","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true}],"exports":["AbstractFeedIterator","FeedFactory","FeedIterator","FeedQueue","FeedSetIterator","FeedStore","FeedWrapper","createFeedWriter","defaultFeedSetIteratorOptions","defaultReadStreamOptions","writeMessages"],"entryPoint":"packages/common/feed-store/src/index.ts","inputs":{"packages/common/feed-store/src/index.ts":{"bytesInOutput":0},"packages/common/feed-store/src/feed-iterator.ts":{"bytesInOutput":2802},"packages/common/feed-store/src/feed-queue.ts":{"bytesInOutput":4935},"packages/common/feed-store/src/feed-set-iterator.ts":{"bytesInOutput":4971},"packages/common/feed-store/src/feed-writer.ts":{"bytesInOutput":273}},"bytes":13614},"packages/common/feed-store/dist/lib/browser/testing/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":9598},"packages/common/feed-store/dist/lib/browser/testing/index.mjs":{"imports":[{"path":"packages/common/feed-store/dist/lib/browser/chunk-I3RTOCTQ.mjs","kind":"import-statement"},{"path":"@dxos/async","kind":"import-statement","external":true},{"path":"@dxos/context","kind":"import-statement","external":true},{"path":"@dxos/keys","kind":"import-statement","external":true},{"path":"@dxos/keyring","kind":"import-statement","external":true},{"path":"@dxos/random-access-storage","kind":"import-statement","external":true},{"path":"@dxos/async","kind":"import-statement","external":true},{"path":"@dxos/hypercore","kind":"import-statement","external":true},{"path":"@dxos/random","kind":"import-statement","external":true}],"exports":["MockFeedWriter","TestBuilder","TestGenerator","TestItemBuilder","defaultCodec","defaultTestBlockGenerator","defaultTestGenerator","defaultValueEncoding"],"entryPoint":"packages/common/feed-store/src/testing/index.ts","inputs":{"packages/common/feed-store/src/testing/mocks.ts":{"bytesInOutput":784},"packages/common/feed-store/src/testing/index.ts":{"bytesInOutput":0},"packages/common/feed-store/src/testing/test-builder.ts":{"bytesInOutput":1800},"packages/common/feed-store/src/testing/test-generator.ts":{"bytesInOutput":961}},"bytes":4085},"packages/common/feed-store/dist/lib/browser/chunk-I3RTOCTQ.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":26062},"packages/common/feed-store/dist/lib/browser/chunk-I3RTOCTQ.mjs":{"imports":[{"path":"@dxos/node-std/util","kind":"import-statement","external":true},{"path":"streamx","kind":"import-statement","external":true},{"path":"@dxos/async","kind":"import-statement","external":true},{"path":"@dxos/debug","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true},{"path":"lodash.defaultsdeep","kind":"import-statement","external":true},{"path":"@dxos/crypto","kind":"import-statement","external":true},{"path":"@dxos/debug","kind":"import-statement","external":true},{"path":"@dxos/hypercore","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"@dxos/async","kind":"import-statement","external":true},{"path":"@dxos/debug","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/keys","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true}],"exports":["FeedFactory","FeedStore","FeedWrapper"],"inputs":{"packages/common/feed-store/src/feed-wrapper.ts":{"bytesInOutput":8215},"packages/common/feed-store/src/feed-factory.ts":{"bytesInOutput":2015},"packages/common/feed-store/src/feed-store.ts":{"bytesInOutput":3129}},"bytes":13642}}}
@@ -408,10 +408,9 @@ var FeedSetIterator = class extends AbstractFeedIterator {
408
408
  });
409
409
  this._subscriptions = new import_async3.EventSubscriptions();
410
410
  this.stalled = new import_async3.Event();
411
- this._reiterateBlocks = [];
412
411
  (0, import_invariant3.invariant)(_selector, void 0, {
413
412
  F: __dxlog_file3,
414
- L: 61,
413
+ L: 55,
415
414
  S: this,
416
415
  A: [
417
416
  "_selector",
@@ -420,7 +419,7 @@ var FeedSetIterator = class extends AbstractFeedIterator {
420
419
  });
421
420
  (0, import_invariant3.invariant)(options, void 0, {
422
421
  F: __dxlog_file3,
423
- L: 62,
422
+ L: 56,
424
423
  S: this,
425
424
  A: [
426
425
  "options",
@@ -451,13 +450,12 @@ var FeedSetIterator = class extends AbstractFeedIterator {
451
450
  }));
452
451
  }
453
452
  reiterateBlock(block) {
454
- this._reiterateBlocks.push(block);
455
453
  this._trigger.wake();
456
454
  }
457
455
  async addFeed(feed) {
458
456
  (0, import_invariant3.invariant)(!this._feedQueues.has(feed.key), `Feed already added: ${feed.key}`, {
459
457
  F: __dxlog_file3,
460
- L: 98,
458
+ L: 91,
461
459
  S: this,
462
460
  A: [
463
461
  "!this._feedQueues.has(feed.key)",
@@ -466,7 +464,7 @@ var FeedSetIterator = class extends AbstractFeedIterator {
466
464
  });
467
465
  (0, import_invariant3.invariant)(feed.properties.opened, void 0, {
468
466
  F: __dxlog_file3,
469
- L: 99,
467
+ L: 92,
470
468
  S: this,
471
469
  A: [
472
470
  "feed.properties.opened",
@@ -477,7 +475,7 @@ var FeedSetIterator = class extends AbstractFeedIterator {
477
475
  feedKey: feed.key
478
476
  }, {
479
477
  F: __dxlog_file3,
480
- L: 100,
478
+ L: 93,
481
479
  S: this,
482
480
  C: (f, a) => f(...a)
483
481
  });
@@ -504,37 +502,14 @@ var FeedSetIterator = class extends AbstractFeedIterator {
504
502
  await Promise.all(Array.from(this._feedQueues.values()).map((queue) => queue.close()));
505
503
  this._trigger.wake();
506
504
  }
507
- _getNextBlockForReiteration() {
508
- const block = this._reiterateBlocks.shift();
509
- (0, import_invariant3.invariant)(block, void 0, {
510
- F: __dxlog_file3,
511
- L: 139,
512
- S: this,
513
- A: [
514
- "block",
515
- ""
516
- ]
517
- });
518
- (0, import_log3.log)("reiterate", {
519
- key: block?.feedKey.toHex(),
520
- seq: block?.seq
521
- }, {
522
- F: __dxlog_file3,
523
- L: 140,
524
- S: this,
525
- C: (f, a) => f(...a)
526
- });
527
- return block;
528
- }
529
505
  /**
530
506
  * Gets the next block from the selected queue.
531
507
  */
532
508
  async _nextBlock() {
533
509
  let t;
534
510
  while (this._running) {
535
- let stalled = false;
536
511
  const queues = Array.from(this._feedQueues.values());
537
- const blocks = queues.map((queue) => queue.peek()).filter(import_util.isNotNullOrUndefined);
512
+ const blocks = queues.map((queue) => queue.peek()).filter(import_util.isNonNullable);
538
513
  if (blocks.length) {
539
514
  const idx = this._selector(blocks);
540
515
  (0, import_log3.log)("selected", {
@@ -542,7 +517,7 @@ var FeedSetIterator = class extends AbstractFeedIterator {
542
517
  blocks
543
518
  }, {
544
519
  F: __dxlog_file3,
545
- L: 158,
520
+ L: 143,
546
521
  S: this,
547
522
  C: (f, a) => f(...a)
548
523
  });
@@ -551,7 +526,6 @@ var FeedSetIterator = class extends AbstractFeedIterator {
551
526
  t = setTimeout(() => {
552
527
  this.stalled.emit(this);
553
528
  this._trigger.wake();
554
- stalled = true;
555
529
  }, this.options.stallTimeout);
556
530
  }
557
531
  } else {
@@ -565,7 +539,7 @@ var FeedSetIterator = class extends AbstractFeedIterator {
565
539
  const queue = this._feedQueues.get(blocks[idx].feedKey);
566
540
  (0, import_log3.log)("popping", queue.toJSON(), {
567
541
  F: __dxlog_file3,
568
- L: 179,
542
+ L: 163,
569
543
  S: this,
570
544
  C: (f, a) => f(...a)
571
545
  });
@@ -573,7 +547,7 @@ var FeedSetIterator = class extends AbstractFeedIterator {
573
547
  const message = await queue.pop();
574
548
  (0, import_invariant3.invariant)(message === blocks[idx], void 0, {
575
549
  F: __dxlog_file3,
576
- L: 182,
550
+ L: 166,
577
551
  S: this,
578
552
  A: [
579
553
  "message === blocks[idx]",
@@ -586,19 +560,14 @@ var FeedSetIterator = class extends AbstractFeedIterator {
586
560
  feedKey: queue.feed.key
587
561
  }, {
588
562
  F: __dxlog_file3,
589
- L: 186,
563
+ L: 170,
590
564
  S: this,
591
565
  C: (f, a) => f(...a)
592
566
  });
593
567
  }
594
568
  }
595
- } else if (this._reiterateBlocks.length) {
596
- return this._getNextBlockForReiteration();
597
569
  }
598
570
  await this._trigger.wait();
599
- if (stalled && this._reiterateBlocks.length) {
600
- return this._getNextBlockForReiteration();
601
- }
602
571
  }
603
572
  }
604
573
  };