@dxos/feed-store 0.6.12 → 0.6.13-main.548ca8d

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.
Files changed (33) hide show
  1. package/dist/lib/browser/{chunk-QEVMM5RF.mjs → chunk-QYBKGLQJ.mjs} +2 -3
  2. package/dist/lib/browser/chunk-QYBKGLQJ.mjs.map +7 -0
  3. package/dist/lib/browser/index.mjs +1 -1
  4. package/dist/lib/browser/meta.json +1 -1
  5. package/dist/lib/browser/testing/index.mjs +1 -1
  6. package/dist/lib/node/{chunk-CEOKPJ6P.cjs → chunk-PXGR6322.cjs} +5 -6
  7. package/dist/lib/node/chunk-PXGR6322.cjs.map +7 -0
  8. package/dist/lib/node/index.cjs +4 -4
  9. package/dist/lib/node/meta.json +1 -1
  10. package/dist/lib/node/testing/index.cjs +3 -3
  11. package/dist/lib/node-esm/chunk-QELQFW6D.mjs +495 -0
  12. package/dist/lib/node-esm/chunk-QELQFW6D.mjs.map +7 -0
  13. package/dist/lib/node-esm/index.mjs +567 -0
  14. package/dist/lib/node-esm/index.mjs.map +7 -0
  15. package/dist/lib/node-esm/meta.json +1 -0
  16. package/dist/lib/node-esm/testing/index.mjs +154 -0
  17. package/dist/lib/node-esm/testing/index.mjs.map +7 -0
  18. package/dist/types/src/feed-queue.browser.test.d.ts +2 -0
  19. package/dist/types/src/feed-queue.browser.test.d.ts.map +1 -0
  20. package/dist/types/src/feed-store.node.test.d.ts +2 -0
  21. package/dist/types/src/feed-store.node.test.d.ts.map +1 -0
  22. package/package.json +21 -19
  23. package/src/feed-factory.test.ts +1 -1
  24. package/src/feed-iterator.test.ts +2 -3
  25. package/src/feed-queue.browser.test.ts +54 -0
  26. package/src/feed-queue.test.ts +50 -92
  27. package/src/feed-set-iterator.test.ts +3 -4
  28. package/src/feed-store.node.test.ts +56 -0
  29. package/src/feed-store.test.ts +2 -51
  30. package/src/feed-wrapper.test.ts +3 -7
  31. package/src/feed-wrapper.ts +1 -1
  32. package/dist/lib/browser/chunk-QEVMM5RF.mjs.map +0 -7
  33. package/dist/lib/node/chunk-CEOKPJ6P.cjs.map +0 -7
@@ -0,0 +1,567 @@
1
+ import { createRequire } from 'node:module';const require = createRequire(import.meta.url);
2
+ import {
3
+ FeedFactory,
4
+ FeedStore,
5
+ FeedWrapper
6
+ } from "./chunk-QELQFW6D.mjs";
7
+
8
+ // packages/common/feed-store/src/feed-iterator.ts
9
+ import safeRace from "race-as-promised";
10
+ import { Trigger as Trigger2 } from "@dxos/async";
11
+ import { invariant as invariant2 } from "@dxos/invariant";
12
+ import { log as log2 } from "@dxos/log";
13
+
14
+ // packages/common/feed-store/src/feed-queue.ts
15
+ import { inspect } from "node:util";
16
+ import { Writable } from "streamx";
17
+ import { Event, latch, Trigger } from "@dxos/async";
18
+ import { inspectObject } from "@dxos/debug";
19
+ import { invariant } from "@dxos/invariant";
20
+ import { log } from "@dxos/log";
21
+ var __dxlog_file = "/home/runner/work/dxos/dxos/packages/common/feed-store/src/feed-queue.ts";
22
+ var defaultReadStreamOptions = {
23
+ live: true,
24
+ batch: 1024
25
+ };
26
+ var FeedQueue = class {
27
+ // prettier-ignore
28
+ constructor(_feed, _options = {}) {
29
+ this._feed = _feed;
30
+ this._options = _options;
31
+ this.updated = new Event();
32
+ this._messageTrigger = new Trigger({
33
+ autoReset: true
34
+ });
35
+ this._feedConsumer = void 0;
36
+ this._currentBlock = void 0;
37
+ this._index = -1;
38
+ }
39
+ [inspect.custom]() {
40
+ return inspectObject(this);
41
+ }
42
+ toJSON() {
43
+ return {
44
+ feedKey: this._feed.key,
45
+ index: this.index,
46
+ length: this.length,
47
+ open: this.isOpen
48
+ };
49
+ }
50
+ get feed() {
51
+ return this._feed;
52
+ }
53
+ get isOpen() {
54
+ return Boolean(this._feedConsumer);
55
+ }
56
+ get length() {
57
+ return this._feed.properties.length;
58
+ }
59
+ /**
60
+ * Index (seq) of the NEXT block to be read, or -1 if not open.
61
+ */
62
+ get index() {
63
+ return this._index;
64
+ }
65
+ /**
66
+ * Opens (or reopens) the queue.
67
+ * @param options.start Starting index. First mutation to be read would have `seq == options.start`.
68
+ */
69
+ async open(options = {}) {
70
+ if (this.isOpen) {
71
+ return;
72
+ }
73
+ this._index = options.start ?? 0;
74
+ log("opening", {
75
+ feedKey: this._feed.key
76
+ }, {
77
+ F: __dxlog_file,
78
+ L: 92,
79
+ S: this,
80
+ C: (f, a) => f(...a)
81
+ });
82
+ const opts = Object.assign({}, defaultReadStreamOptions, options);
83
+ const feedStream = this._feed.createReadableStream(opts);
84
+ this._feedConsumer = new Writable({
85
+ write: (data, next) => {
86
+ this._next = () => {
87
+ this._next = void 0;
88
+ this._currentBlock = void 0;
89
+ this._index++;
90
+ next();
91
+ };
92
+ this._currentBlock = {
93
+ feedKey: this._feed.key,
94
+ seq: this._index,
95
+ data
96
+ };
97
+ this._messageTrigger.wake(this._currentBlock);
98
+ this.updated.emit(this);
99
+ }
100
+ });
101
+ const onClose = () => {
102
+ this.feed.core.off("close", onClose);
103
+ this._feedConsumer?.off("close", onClose);
104
+ this._feedConsumer?.off("error", onError);
105
+ this._destroyConsumer();
106
+ };
107
+ const onError = (err) => {
108
+ if (!err) {
109
+ return;
110
+ }
111
+ if (err.message === "Writable stream closed prematurely" || err.message === "Feed is closed") {
112
+ return;
113
+ }
114
+ log.catch(err, {
115
+ feedKey: this._feed.key
116
+ }, {
117
+ F: __dxlog_file,
118
+ L: 135,
119
+ S: this,
120
+ C: (f, a) => f(...a)
121
+ });
122
+ };
123
+ this._feed.core.once("close", onClose);
124
+ this._feedConsumer.on("error", onError);
125
+ this._feedConsumer.once("close", onClose);
126
+ feedStream.pipe(this._feedConsumer, (err) => {
127
+ if (err) {
128
+ onError(err);
129
+ }
130
+ this._destroyConsumer();
131
+ });
132
+ log("opened", void 0, {
133
+ F: __dxlog_file,
134
+ L: 153,
135
+ S: this,
136
+ C: (f, a) => f(...a)
137
+ });
138
+ }
139
+ /**
140
+ * Closes the queue.
141
+ */
142
+ async close() {
143
+ if (this.isOpen) {
144
+ invariant(this._feedConsumer, void 0, {
145
+ F: __dxlog_file,
146
+ L: 161,
147
+ S: this,
148
+ A: [
149
+ "this._feedConsumer",
150
+ ""
151
+ ]
152
+ });
153
+ invariant(!this._feed.properties.closed, void 0, {
154
+ F: __dxlog_file,
155
+ L: 162,
156
+ S: this,
157
+ A: [
158
+ "!this._feed.properties.closed",
159
+ ""
160
+ ]
161
+ });
162
+ log("closing", {
163
+ feedKey: this._feed.key
164
+ }, {
165
+ F: __dxlog_file,
166
+ L: 164,
167
+ S: this,
168
+ C: (f, a) => f(...a)
169
+ });
170
+ const [closed, setClosed] = latch();
171
+ this._feedConsumer.once("close", setClosed);
172
+ this._feedConsumer.destroy();
173
+ this._next?.();
174
+ await closed();
175
+ log("closed", void 0, {
176
+ F: __dxlog_file,
177
+ L: 170,
178
+ S: this,
179
+ C: (f, a) => f(...a)
180
+ });
181
+ }
182
+ }
183
+ /**
184
+ * Get the block at the head of the queue without removing it.
185
+ */
186
+ peek() {
187
+ return this._currentBlock;
188
+ }
189
+ /**
190
+ * Pop block at the head of the queue.
191
+ */
192
+ async pop() {
193
+ if (!this.isOpen) {
194
+ throw new Error(`Queue closed: ${this.feed.key.truncate()}`);
195
+ }
196
+ let block = this.peek();
197
+ if (!block) {
198
+ block = await this._messageTrigger.wait();
199
+ }
200
+ if (block) {
201
+ this._next?.();
202
+ }
203
+ return block;
204
+ }
205
+ _destroyConsumer() {
206
+ if (this._feedConsumer) {
207
+ log("queue closed", {
208
+ feedKey: this._feed.key
209
+ }, {
210
+ F: __dxlog_file,
211
+ L: 203,
212
+ S: this,
213
+ C: (f, a) => f(...a)
214
+ });
215
+ this._feedConsumer = void 0;
216
+ this._next = void 0;
217
+ this._currentBlock = void 0;
218
+ this._index = -1;
219
+ }
220
+ }
221
+ };
222
+
223
+ // packages/common/feed-store/src/feed-iterator.ts
224
+ var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/common/feed-store/src/feed-iterator.ts";
225
+ var AbstractFeedIterator = class {
226
+ constructor() {
227
+ this._stopTrigger = new Trigger2();
228
+ this._open = false;
229
+ this._running = false;
230
+ }
231
+ toJSON() {
232
+ return {
233
+ open: this.isOpen,
234
+ running: this.isRunning
235
+ };
236
+ }
237
+ get isOpen() {
238
+ return this._open;
239
+ }
240
+ get isRunning() {
241
+ return this._running;
242
+ }
243
+ async open() {
244
+ if (!this._open) {
245
+ log2("opening...", void 0, {
246
+ F: __dxlog_file2,
247
+ L: 41,
248
+ S: this,
249
+ C: (f, a) => f(...a)
250
+ });
251
+ await this._onOpen();
252
+ this._open = true;
253
+ await this.start();
254
+ log2("opened", void 0, {
255
+ F: __dxlog_file2,
256
+ L: 46,
257
+ S: this,
258
+ C: (f, a) => f(...a)
259
+ });
260
+ }
261
+ }
262
+ async close() {
263
+ if (this._open) {
264
+ log2("closing...", void 0, {
265
+ F: __dxlog_file2,
266
+ L: 52,
267
+ S: this,
268
+ C: (f, a) => f(...a)
269
+ });
270
+ await this.stop();
271
+ await this._onClose();
272
+ this._open = false;
273
+ log2("closed", void 0, {
274
+ F: __dxlog_file2,
275
+ L: 57,
276
+ S: this,
277
+ C: (f, a) => f(...a)
278
+ });
279
+ }
280
+ }
281
+ async start() {
282
+ invariant2(this._open, void 0, {
283
+ F: __dxlog_file2,
284
+ L: 62,
285
+ S: this,
286
+ A: [
287
+ "this._open",
288
+ ""
289
+ ]
290
+ });
291
+ if (!this._running) {
292
+ this._running = true;
293
+ }
294
+ }
295
+ async stop() {
296
+ invariant2(this._open, void 0, {
297
+ F: __dxlog_file2,
298
+ L: 69,
299
+ S: this,
300
+ A: [
301
+ "this._open",
302
+ ""
303
+ ]
304
+ });
305
+ if (this._running) {
306
+ this._running = false;
307
+ this._stopTrigger.wake();
308
+ }
309
+ }
310
+ //
311
+ // AsyncIterable
312
+ //
313
+ [Symbol.asyncIterator]() {
314
+ return this._generator();
315
+ }
316
+ async *_generator() {
317
+ log2("started", void 0, {
318
+ F: __dxlog_file2,
319
+ L: 85,
320
+ S: this,
321
+ C: (f, a) => f(...a)
322
+ });
323
+ while (this._running) {
324
+ const block = await safeRace([
325
+ this._stopTrigger.wait(),
326
+ this._nextBlock()
327
+ ]);
328
+ if (block === void 0) {
329
+ break;
330
+ }
331
+ yield block;
332
+ }
333
+ log2("stopped", void 0, {
334
+ F: __dxlog_file2,
335
+ L: 97,
336
+ S: this,
337
+ C: (f, a) => f(...a)
338
+ });
339
+ }
340
+ };
341
+ var FeedIterator = class extends AbstractFeedIterator {
342
+ constructor(_feed) {
343
+ super();
344
+ this._feed = _feed;
345
+ this._queue = new FeedQueue(this._feed);
346
+ }
347
+ async _onOpen() {
348
+ await this._queue.open();
349
+ }
350
+ async _onClose() {
351
+ await this._queue.close();
352
+ }
353
+ async _nextBlock() {
354
+ return this._queue.pop();
355
+ }
356
+ };
357
+
358
+ // packages/common/feed-store/src/feed-set-iterator.ts
359
+ import { inspect as inspect2 } from "node:util";
360
+ import { Event as Event2, EventSubscriptions, Trigger as Trigger3 } from "@dxos/async";
361
+ import { inspectObject as inspectObject2 } from "@dxos/debug";
362
+ import { invariant as invariant3 } from "@dxos/invariant";
363
+ import { PublicKey } from "@dxos/keys";
364
+ import { log as log3 } from "@dxos/log";
365
+ import { ComplexMap, isNotNullOrUndefined } from "@dxos/util";
366
+ var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/common/feed-store/src/feed-set-iterator.ts";
367
+ var defaultFeedSetIteratorOptions = {
368
+ stallTimeout: 1e3
369
+ };
370
+ var FeedSetIterator = class extends AbstractFeedIterator {
371
+ constructor(_selector, options = defaultFeedSetIteratorOptions) {
372
+ super();
373
+ this._selector = _selector;
374
+ this.options = options;
375
+ this._feedQueues = new ComplexMap(PublicKey.hash);
376
+ this._trigger = new Trigger3({
377
+ autoReset: true
378
+ });
379
+ this._subscriptions = new EventSubscriptions();
380
+ this.stalled = new Event2();
381
+ invariant3(_selector, void 0, {
382
+ F: __dxlog_file3,
383
+ L: 55,
384
+ S: this,
385
+ A: [
386
+ "_selector",
387
+ ""
388
+ ]
389
+ });
390
+ invariant3(options, void 0, {
391
+ F: __dxlog_file3,
392
+ L: 56,
393
+ S: this,
394
+ A: [
395
+ "options",
396
+ ""
397
+ ]
398
+ });
399
+ }
400
+ [inspect2.custom]() {
401
+ return inspectObject2(this);
402
+ }
403
+ toJSON() {
404
+ return {
405
+ open: this.isOpen,
406
+ running: this.isRunning,
407
+ indexes: this.indexes
408
+ };
409
+ }
410
+ get size() {
411
+ return this._feedQueues.size;
412
+ }
413
+ get feeds() {
414
+ return Array.from(this._feedQueues.values()).map((feedQueue) => feedQueue.feed);
415
+ }
416
+ get indexes() {
417
+ return Array.from(this._feedQueues.values()).map((feedQueue) => ({
418
+ feedKey: feedQueue.feed.key,
419
+ index: feedQueue.index
420
+ }));
421
+ }
422
+ async addFeed(feed) {
423
+ invariant3(!this._feedQueues.has(feed.key), `Feed already added: ${feed.key}`, {
424
+ F: __dxlog_file3,
425
+ L: 87,
426
+ S: this,
427
+ A: [
428
+ "!this._feedQueues.has(feed.key)",
429
+ "`Feed already added: ${feed.key}`"
430
+ ]
431
+ });
432
+ invariant3(feed.properties.opened, void 0, {
433
+ F: __dxlog_file3,
434
+ L: 88,
435
+ S: this,
436
+ A: [
437
+ "feed.properties.opened",
438
+ ""
439
+ ]
440
+ });
441
+ log3("feed added", {
442
+ feedKey: feed.key
443
+ }, {
444
+ F: __dxlog_file3,
445
+ L: 89,
446
+ S: this,
447
+ C: (f, a) => f(...a)
448
+ });
449
+ const queue = new FeedQueue(feed);
450
+ this._feedQueues.set(feed.key, queue);
451
+ this._subscriptions.add(queue.updated.on(() => {
452
+ this._trigger.wake();
453
+ }));
454
+ await queue.open({
455
+ start: this.options.start?.find((index) => index.feedKey.equals(feed.key))?.index
456
+ });
457
+ this._trigger.wake();
458
+ }
459
+ hasFeed(feedKey) {
460
+ return this._feedQueues.has(feedKey);
461
+ }
462
+ async _onOpen() {
463
+ for (const queue of this._feedQueues.values()) {
464
+ await queue.open();
465
+ }
466
+ }
467
+ async _onClose() {
468
+ this._subscriptions.clear();
469
+ await Promise.all(Array.from(this._feedQueues.values()).map((queue) => queue.close()));
470
+ this._trigger.wake();
471
+ }
472
+ /**
473
+ * Gets the next block from the selected queue.
474
+ */
475
+ async _nextBlock() {
476
+ let t;
477
+ while (this._running) {
478
+ const queues = Array.from(this._feedQueues.values());
479
+ const blocks = queues.map((queue) => queue.peek()).filter(isNotNullOrUndefined);
480
+ if (blocks.length) {
481
+ const idx = this._selector(blocks);
482
+ log3("selected", {
483
+ idx,
484
+ blocks
485
+ }, {
486
+ F: __dxlog_file3,
487
+ L: 139,
488
+ S: this,
489
+ C: (f, a) => f(...a)
490
+ });
491
+ if (idx === void 0) {
492
+ if (t === void 0) {
493
+ t = setTimeout(() => {
494
+ this.stalled.emit(this);
495
+ }, this.options.stallTimeout);
496
+ }
497
+ } else {
498
+ if (t !== void 0) {
499
+ clearTimeout(t);
500
+ t = void 0;
501
+ }
502
+ if (idx >= blocks.length) {
503
+ throw new Error(`Index out of bounds: ${idx} of ${blocks.length}`);
504
+ }
505
+ const queue = this._feedQueues.get(blocks[idx].feedKey);
506
+ log3("popping", queue.toJSON(), {
507
+ F: __dxlog_file3,
508
+ L: 158,
509
+ S: this,
510
+ C: (f, a) => f(...a)
511
+ });
512
+ try {
513
+ const message = await queue.pop();
514
+ invariant3(message === blocks[idx], void 0, {
515
+ F: __dxlog_file3,
516
+ L: 161,
517
+ S: this,
518
+ A: [
519
+ "message === blocks[idx]",
520
+ ""
521
+ ]
522
+ });
523
+ return message;
524
+ } catch (err) {
525
+ log3.warn("queue closed", {
526
+ feedKey: queue.feed.key
527
+ }, {
528
+ F: __dxlog_file3,
529
+ L: 165,
530
+ S: this,
531
+ C: (f, a) => f(...a)
532
+ });
533
+ }
534
+ }
535
+ }
536
+ await this._trigger.wait();
537
+ }
538
+ }
539
+ };
540
+
541
+ // packages/common/feed-store/src/feed-writer.ts
542
+ var createFeedWriter = (cb) => ({
543
+ write: async (data) => {
544
+ return cb(data);
545
+ }
546
+ });
547
+ var writeMessages = async (writer, messages) => {
548
+ const receipts = [];
549
+ for (const message of messages) {
550
+ receipts.push(await writer.write(message));
551
+ }
552
+ return receipts;
553
+ };
554
+ export {
555
+ AbstractFeedIterator,
556
+ FeedFactory,
557
+ FeedIterator,
558
+ FeedQueue,
559
+ FeedSetIterator,
560
+ FeedStore,
561
+ FeedWrapper,
562
+ createFeedWriter,
563
+ defaultFeedSetIteratorOptions,
564
+ defaultReadStreamOptions,
565
+ writeMessages
566
+ };
567
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 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 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 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(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.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": ";;;;;;;;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,MAAM;EACNC,OAAO;AACT;AAOO,IAAMC,YAAN,MAAMA;;EAaXC,YACmBC,OACAC,WAA6B,CAAC,GAC/C;SAFiBD,QAAAA;SACAC,WAAAA;SAdZC,UAAU,IAAIb,MAAAA;SAEJc,kBAAkB,IAAIZ,QAAsB;MAC3Da,WAAW;IACb,CAAA;SAEQC,gBAA2BC;SAE3BC,gBAA+BD;SAC/BE,SAAS;EAMd;EAEH,CAACrB,QAAQsB,MAAM,IAAI;AACjB,WAAOjB,cAAc,IAAI;EAC3B;EAEAkB,SAAS;AACP,WAAO;MACLC,SAAS,KAAKX,MAAMY;MACpBC,OAAO,KAAKA;MACZC,QAAQ,KAAKA;MACbC,MAAM,KAAKC;IACb;EACF;EAEA,IAAIC,OAAO;AACT,WAAO,KAAKjB;EACd;EAEA,IAAIgB,SAAkB;AACpB,WAAOE,QAAQ,KAAKb,aAAa;EACnC;EAEA,IAAIS,SAAiB;AACnB,WAAO,KAAKd,MAAMmB,WAAWL;EAC/B;;;;EAKA,IAAID,QAAQ;AACV,WAAO,KAAKL;EACd;;;;;EAMA,MAAMO,KAAKK,UAA6B,CAAC,GAAG;AAC1C,QAAI,KAAKJ,QAAQ;AAEf;IACF;AAEA,SAAKR,SAASY,QAAQC,SAAS;AAK/B3B,QAAI,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C9BC,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", "invariant", "inspect", "custom", "inspectObject", "toJSON", "open", "isOpen", "running", "isRunning", "indexes", "size", "feeds", "Array", "from", "values", "map", "feedQueue", "feed", "feedKey", "key", "index", "addFeed", "has", "properties", "opened", "log", "queue", "FeedQueue", "set", "add", "updated", "on", "wake", "start", "find", "equals", "hasFeed", "_onOpen", "_onClose", "clear", "Promise", "all", "close", "_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"]
7
+ }
@@ -0,0 +1 @@
1
+ {"inputs":{"packages/common/feed-store/src/feed-wrapper.ts":{"bytes":34379,"imports":[{"path":"node: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":"node: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":19960,"imports":[{"path":"node: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/node-esm/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":24009},"packages/common/feed-store/dist/lib/node-esm/index.mjs":{"imports":[{"path":"packages/common/feed-store/dist/lib/node-esm/chunk-QELQFW6D.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":"node: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":"node: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":4925},"packages/common/feed-store/src/feed-set-iterator.ts":{"bytesInOutput":4883},"packages/common/feed-store/src/feed-writer.ts":{"bytesInOutput":273}},"bytes":13575},"packages/common/feed-store/dist/lib/node-esm/testing/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":9598},"packages/common/feed-store/dist/lib/node-esm/testing/index.mjs":{"imports":[{"path":"packages/common/feed-store/dist/lib/node-esm/chunk-QELQFW6D.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":4144},"packages/common/feed-store/dist/lib/node-esm/chunk-QELQFW6D.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":26062},"packages/common/feed-store/dist/lib/node-esm/chunk-QELQFW6D.mjs":{"imports":[{"path":"node: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":8205},"packages/common/feed-store/src/feed-factory.ts":{"bytesInOutput":2015},"packages/common/feed-store/src/feed-store.ts":{"bytesInOutput":3129}},"bytes":13691}}}