@dxos/feed-store 0.8.4-main.a4bbb77 → 0.8.4-main.ae835ea
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/lib/browser/{chunk-4RW534M7.mjs → chunk-I36R5SR3.mjs} +91 -130
- package/dist/lib/browser/{chunk-4RW534M7.mjs.map → chunk-I36R5SR3.mjs.map} +2 -2
- package/dist/lib/browser/index.mjs +56 -96
- package/dist/lib/browser/index.mjs.map +2 -2
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +27 -72
- package/dist/lib/browser/testing/index.mjs.map +2 -2
- package/dist/lib/node-esm/{chunk-D4DVCY7Y.mjs → chunk-HJBZDWE4.mjs} +91 -130
- package/dist/lib/node-esm/{chunk-D4DVCY7Y.mjs.map → chunk-HJBZDWE4.mjs.map} +2 -2
- package/dist/lib/node-esm/index.mjs +56 -96
- package/dist/lib/node-esm/index.mjs.map +2 -2
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/testing/index.mjs +27 -72
- package/dist/lib/node-esm/testing/index.mjs.map +2 -2
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +18 -18
|
@@ -2,6 +2,6 @@
|
|
|
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
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(): { open: boolean; running: boolean } {\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(): Promise<void> {\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(): Promise<void> {\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(): Promise<void> {\n invariant(this._open);\n if (!this._running) {\n this._running = true;\n }\n }\n\n async stop(): Promise<void> {\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';\n\nimport { Writable } from 'streamx';\n\nimport { Event, Trigger, latch } 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](): string {\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 = {}): Promise<void> {\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 (!this.isOpen) {\n return;\n }\n if (!err) {\n return;\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(): Promise<void> {\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(): void {\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, SubscriptionList, 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 SubscriptionList();\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](): string {\n return inspectObject(this);\n }\n\n override toJSON(): { open: boolean; running: boolean; indexes: FeedIndex[] } {\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>): void {\n this._trigger.wake();\n }\n\n async addFeed(feed: FeedWrapper<T>): Promise<void> {\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): boolean {\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": ";;;;;;;;AAIA,OAAOA,cAAc;AAErB,SAASC,WAAAA,gBAAe;AACxB,SAASC,aAAAA,kBAAiB;AAC1B,SAASC,OAAAA,YAAW;;;ACJpB,SAASC,eAAe;AAExB,SAASC,gBAAgB;AAEzB,SAASC,OAAOC,SAASC,aAAa;AACtC,SAASC,qBAAqB;AAE9B,SAASC,iBAAiB;AAC1B,SAASC,WAAW
|
|
6
|
-
"names": ["safeRace", "Trigger", "invariant", "log", "inspect", "Writable", "Event", "Trigger", "latch", "inspectObject", "invariant", "log", "defaultReadStreamOptions", "live", "batch", "
|
|
5
|
+
"mappings": ";;;;;;;;AAIA,OAAOA,cAAc;AAErB,SAASC,WAAAA,gBAAe;AACxB,SAASC,aAAAA,kBAAiB;AAC1B,SAASC,OAAAA,YAAW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invariant", "log", "inspect", "Writable", "Event", "Trigger", "latch", "inspectObject", "invariant", "log", "defaultReadStreamOptions", "live", "batch", "FeedQueue", "updated", "_messageTrigger", "autoReset", "_feedConsumer", "undefined", "_next", "_currentBlock", "_index", "_feed", "_options", "custom", "toJSON", "feedKey", "key", "index", "length", "open", "isOpen", "feed", "Boolean", "properties", "options", "start", "opts", "Object", "assign", "feedStream", "createReadableStream", "write", "data", "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", "_queue", "_feed", "FeedQueue", "pop", "inspect", "Event", "SubscriptionList", "Trigger", "inspectObject", "invariant", "PublicKey", "log", "ComplexMap", "isNonNullable", "defaultFeedSetIteratorOptions", "stallTimeout", "FeedSetIterator", "AbstractFeedIterator", "_feedQueues", "ComplexMap", "PublicKey", "hash", "_trigger", "Trigger", "autoReset", "_subscriptions", "SubscriptionList", "stalled", "Event", "_selector", "options", "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":{"src/feed-wrapper.ts":{"bytes":
|
|
1
|
+
{"inputs":{"src/feed-wrapper.ts":{"bytes":35830,"imports":[{"path":"@dxos/node-std/util","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/util","kind":"import-statement","external":true}],"format":"esm"},"src/feed-factory.ts":{"bytes":9086,"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":"src/feed-wrapper.ts","kind":"import-statement","original":"./feed-wrapper"}],"format":"esm"},"src/feed-queue.ts":{"bytes":19592,"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"},"src/feed-iterator.ts":{"bytes":10114,"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":"src/feed-queue.ts","kind":"import-statement","original":"./feed-queue"}],"format":"esm"},"src/feed-set-iterator.ts":{"bytes":19967,"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":"src/feed-iterator.ts","kind":"import-statement","original":"./feed-iterator"},{"path":"src/feed-queue.ts","kind":"import-statement","original":"./feed-queue"}],"format":"esm"},"src/feed-store.ts":{"bytes":12102,"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"},"src/feed-writer.ts":{"bytes":2625,"imports":[],"format":"esm"},"src/index.ts":{"bytes":1106,"imports":[{"path":"src/feed-factory.ts","kind":"import-statement","original":"./feed-factory"},{"path":"src/feed-iterator.ts","kind":"import-statement","original":"./feed-iterator"},{"path":"src/feed-set-iterator.ts","kind":"import-statement","original":"./feed-set-iterator"},{"path":"src/feed-queue.ts","kind":"import-statement","original":"./feed-queue"},{"path":"src/feed-store.ts","kind":"import-statement","original":"./feed-store"},{"path":"src/feed-wrapper.ts","kind":"import-statement","original":"./feed-wrapper"},{"path":"src/feed-writer.ts","kind":"import-statement","original":"./feed-writer"}],"format":"esm"},"src/testing/mocks.ts":{"bytes":3371,"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"},"src/testing/test-generator.ts":{"bytes":5521,"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"},"src/testing/test-builder.ts":{"bytes":9653,"imports":[{"path":"@dxos/keyring","kind":"import-statement","external":true},{"path":"@dxos/random-access-storage","kind":"import-statement","external":true},{"path":"src/feed-factory.ts","kind":"import-statement","original":"../feed-factory"},{"path":"src/feed-store.ts","kind":"import-statement","original":"../feed-store"},{"path":"src/testing/test-generator.ts","kind":"import-statement","original":"./test-generator"}],"format":"esm"},"src/testing/index.ts":{"bytes":660,"imports":[{"path":"src/testing/mocks.ts","kind":"import-statement","original":"./mocks"},{"path":"src/testing/test-builder.ts","kind":"import-statement","original":"./test-builder"},{"path":"src/testing/test-generator.ts","kind":"import-statement","original":"./test-generator"}],"format":"esm"}},"outputs":{"dist/lib/browser/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":24505},"dist/lib/browser/index.mjs":{"imports":[{"path":"dist/lib/browser/chunk-I36R5SR3.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":"src/index.ts","inputs":{"src/index.ts":{"bytesInOutput":0},"src/feed-iterator.ts":{"bytesInOutput":2761},"src/feed-queue.ts":{"bytesInOutput":4963},"src/feed-set-iterator.ts":{"bytesInOutput":4938},"src/feed-writer.ts":{"bytesInOutput":273}},"bytes":13433},"dist/lib/browser/testing/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":9644},"dist/lib/browser/testing/index.mjs":{"imports":[{"path":"dist/lib/browser/chunk-I36R5SR3.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":"src/testing/index.ts","inputs":{"src/testing/mocks.ts":{"bytesInOutput":768},"src/testing/index.ts":{"bytesInOutput":0},"src/testing/test-builder.ts":{"bytesInOutput":1800},"src/testing/test-generator.ts":{"bytesInOutput":967}},"bytes":3967},"dist/lib/browser/chunk-I36R5SR3.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":27830},"dist/lib/browser/chunk-I36R5SR3.mjs":{"imports":[{"path":"@dxos/node-std/util","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/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":{"src/feed-wrapper.ts":{"bytesInOutput":8770},"src/feed-factory.ts":{"bytesInOutput":2043},"src/feed-store.ts":{"bytesInOutput":3100}},"bytes":14115}}}
|
|
@@ -2,27 +2,20 @@ import "@dxos/node-std/globals";
|
|
|
2
2
|
import {
|
|
3
3
|
FeedFactory,
|
|
4
4
|
FeedStore
|
|
5
|
-
} from "../chunk-
|
|
5
|
+
} from "../chunk-I36R5SR3.mjs";
|
|
6
6
|
|
|
7
7
|
// src/testing/mocks.ts
|
|
8
8
|
import { Event, scheduleTask } from "@dxos/async";
|
|
9
9
|
import { Context } from "@dxos/context";
|
|
10
10
|
import { PublicKey } from "@dxos/keys";
|
|
11
|
-
function _define_property(obj, key, value) {
|
|
12
|
-
if (key in obj) {
|
|
13
|
-
Object.defineProperty(obj, key, {
|
|
14
|
-
value,
|
|
15
|
-
enumerable: true,
|
|
16
|
-
configurable: true,
|
|
17
|
-
writable: true
|
|
18
|
-
});
|
|
19
|
-
} else {
|
|
20
|
-
obj[key] = value;
|
|
21
|
-
}
|
|
22
|
-
return obj;
|
|
23
|
-
}
|
|
24
11
|
var __dxlog_file = "/__w/dxos/dxos/packages/common/feed-store/src/testing/mocks.ts";
|
|
25
12
|
var MockFeedWriter = class {
|
|
13
|
+
feedKey;
|
|
14
|
+
written = new Event();
|
|
15
|
+
messages = [];
|
|
16
|
+
constructor(feedKey = PublicKey.random()) {
|
|
17
|
+
this.feedKey = feedKey;
|
|
18
|
+
}
|
|
26
19
|
async write(data, { afterWrite } = {}) {
|
|
27
20
|
this.messages.push(data);
|
|
28
21
|
const receipt = {
|
|
@@ -41,14 +34,6 @@ var MockFeedWriter = class {
|
|
|
41
34
|
});
|
|
42
35
|
return receipt;
|
|
43
36
|
}
|
|
44
|
-
constructor(feedKey = PublicKey.random()) {
|
|
45
|
-
_define_property(this, "feedKey", void 0);
|
|
46
|
-
_define_property(this, "written", void 0);
|
|
47
|
-
_define_property(this, "messages", void 0);
|
|
48
|
-
this.feedKey = feedKey;
|
|
49
|
-
this.written = new Event();
|
|
50
|
-
this.messages = [];
|
|
51
|
-
}
|
|
52
37
|
};
|
|
53
38
|
|
|
54
39
|
// src/testing/test-builder.ts
|
|
@@ -59,19 +44,6 @@ import { StorageType, createStorage } from "@dxos/random-access-storage";
|
|
|
59
44
|
import { sleep } from "@dxos/async";
|
|
60
45
|
import { createCodecEncoding } from "@dxos/hypercore";
|
|
61
46
|
import { faker } from "@dxos/random";
|
|
62
|
-
function _define_property2(obj, key, value) {
|
|
63
|
-
if (key in obj) {
|
|
64
|
-
Object.defineProperty(obj, key, {
|
|
65
|
-
value,
|
|
66
|
-
enumerable: true,
|
|
67
|
-
configurable: true,
|
|
68
|
-
writable: true
|
|
69
|
-
});
|
|
70
|
-
} else {
|
|
71
|
-
obj[key] = value;
|
|
72
|
-
}
|
|
73
|
-
return obj;
|
|
74
|
-
}
|
|
75
47
|
var defaultCodec = {
|
|
76
48
|
encode: (obj) => Buffer.from(JSON.stringify(obj)),
|
|
77
49
|
decode: (buffer) => JSON.parse(buffer.toString())
|
|
@@ -83,6 +55,11 @@ var defaultTestBlockGenerator = (i) => ({
|
|
|
83
55
|
value: faker.lorem.sentence()
|
|
84
56
|
});
|
|
85
57
|
var TestGenerator = class {
|
|
58
|
+
_generate;
|
|
59
|
+
_count = 0;
|
|
60
|
+
constructor(_generate) {
|
|
61
|
+
this._generate = _generate;
|
|
62
|
+
}
|
|
86
63
|
async writeBlocks(writer, { count = 1, delay } = {}) {
|
|
87
64
|
return await Promise.all(Array.from(Array(count)).map(async () => {
|
|
88
65
|
const data = this._generate(this._count++);
|
|
@@ -93,31 +70,17 @@ var TestGenerator = class {
|
|
|
93
70
|
return receipt;
|
|
94
71
|
}));
|
|
95
72
|
}
|
|
96
|
-
constructor(_generate) {
|
|
97
|
-
_define_property2(this, "_generate", void 0);
|
|
98
|
-
_define_property2(this, "_count", void 0);
|
|
99
|
-
this._generate = _generate;
|
|
100
|
-
this._count = 0;
|
|
101
|
-
}
|
|
102
73
|
};
|
|
103
74
|
var defaultTestGenerator = new TestGenerator(defaultTestBlockGenerator);
|
|
104
75
|
|
|
105
76
|
// src/testing/test-builder.ts
|
|
106
|
-
function _define_property3(obj, key, value) {
|
|
107
|
-
if (key in obj) {
|
|
108
|
-
Object.defineProperty(obj, key, {
|
|
109
|
-
value,
|
|
110
|
-
enumerable: true,
|
|
111
|
-
configurable: true,
|
|
112
|
-
writable: true
|
|
113
|
-
});
|
|
114
|
-
} else {
|
|
115
|
-
obj[key] = value;
|
|
116
|
-
}
|
|
117
|
-
return obj;
|
|
118
|
-
}
|
|
119
77
|
var evaluate = (builder, arg) => arg === "function" ? arg(builder) : arg;
|
|
120
78
|
var TestBuilder = class _TestBuilder {
|
|
79
|
+
_properties;
|
|
80
|
+
static ROOT_DIR = "feeds";
|
|
81
|
+
constructor(_properties = {}) {
|
|
82
|
+
this._properties = _properties;
|
|
83
|
+
}
|
|
121
84
|
/**
|
|
122
85
|
* Creates a new builder with the current builder's properties.
|
|
123
86
|
*/
|
|
@@ -125,18 +88,15 @@ var TestBuilder = class _TestBuilder {
|
|
|
125
88
|
return new _TestBuilder(Object.assign({}, this._properties));
|
|
126
89
|
}
|
|
127
90
|
get keyring() {
|
|
128
|
-
|
|
129
|
-
return (_this__properties = this._properties).keyring ?? (_this__properties.keyring = new Keyring());
|
|
91
|
+
return this._properties.keyring ??= new Keyring();
|
|
130
92
|
}
|
|
131
93
|
get storage() {
|
|
132
|
-
|
|
133
|
-
return (_this__properties = this._properties).storage ?? (_this__properties.storage = createStorage({
|
|
94
|
+
return this._properties.storage ??= createStorage({
|
|
134
95
|
type: StorageType.RAM
|
|
135
|
-
})
|
|
96
|
+
});
|
|
136
97
|
}
|
|
137
98
|
get root() {
|
|
138
|
-
|
|
139
|
-
return (_this__properties = this._properties).root ?? (_this__properties.root = this.storage.createDirectory(_TestBuilder.ROOT_DIR));
|
|
99
|
+
return this._properties.root ??= this.storage.createDirectory(_TestBuilder.ROOT_DIR);
|
|
140
100
|
}
|
|
141
101
|
setKeyring(keyring) {
|
|
142
102
|
this._properties.keyring = evaluate(this, keyring);
|
|
@@ -167,25 +127,20 @@ var TestBuilder = class _TestBuilder {
|
|
|
167
127
|
factory: this.createFeedFactory()
|
|
168
128
|
});
|
|
169
129
|
}
|
|
170
|
-
constructor(_properties = {}) {
|
|
171
|
-
_define_property3(this, "_properties", void 0);
|
|
172
|
-
this._properties = _properties;
|
|
173
|
-
}
|
|
174
130
|
};
|
|
175
|
-
_define_property3(TestBuilder, "ROOT_DIR", "feeds");
|
|
176
131
|
var TestItemBuilder = class extends TestBuilder {
|
|
177
|
-
get valueEncoding() {
|
|
178
|
-
return this._properties.valueEncoding;
|
|
179
|
-
}
|
|
180
|
-
get generator() {
|
|
181
|
-
return this._properties.generator;
|
|
182
|
-
}
|
|
183
132
|
constructor() {
|
|
184
133
|
super({
|
|
185
134
|
valueEncoding: defaultValueEncoding,
|
|
186
135
|
generator: defaultTestGenerator
|
|
187
136
|
});
|
|
188
137
|
}
|
|
138
|
+
get valueEncoding() {
|
|
139
|
+
return this._properties.valueEncoding;
|
|
140
|
+
}
|
|
141
|
+
get generator() {
|
|
142
|
+
return this._properties.generator;
|
|
143
|
+
}
|
|
189
144
|
};
|
|
190
145
|
export {
|
|
191
146
|
MockFeedWriter,
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/testing/mocks.ts", "../../../../src/testing/test-builder.ts", "../../../../src/testing/test-generator.ts"],
|
|
4
4
|
"sourcesContent": ["//\n// Copyright 2022 DXOS.org\n//\n\nimport { Event, scheduleTask } from '@dxos/async';\nimport { Context } from '@dxos/context';\nimport { PublicKey } from '@dxos/keys';\n\nimport type { FeedWriter, WriteOptions, WriteReceipt } from '../feed-writer';\n\n/**\n * Mock writer collects and emits messages.\n */\nexport class MockFeedWriter<T extends {}> implements FeedWriter<T> {\n public readonly written = new Event<[T, WriteReceipt]>();\n public readonly messages: T[] = [];\n\n constructor(readonly feedKey = PublicKey.random()) {}\n\n async write(data: T, { afterWrite }: WriteOptions = {}): Promise<WriteReceipt> {\n this.messages.push(data);\n\n const receipt: WriteReceipt = {\n feedKey: this.feedKey,\n seq: this.messages.length - 1,\n };\n\n await afterWrite?.(receipt);\n\n scheduleTask(new Context(), () => {\n this.written.emit([data, receipt]);\n });\n\n return receipt;\n }\n}\n", "//\n// Copyright 2022 DXOS.org\n//\n\nimport { Keyring } from '@dxos/keyring';\nimport { type Directory, type Storage, StorageType, createStorage } from '@dxos/random-access-storage';\nimport type { ValueEncoding } from '@dxos/vendor-hypercore/hypercore';\n\nimport { FeedFactory } from '../feed-factory';\nimport { FeedStore } from '../feed-store';\n\nimport { type TestGenerator, type TestItem, defaultTestGenerator, defaultValueEncoding } from './test-generator';\n\nexport type TestBuilderOptions<T extends {}> = {\n storage?: Storage;\n root?: Directory;\n keyring?: Keyring;\n valueEncoding?: ValueEncoding<T>;\n generator?: TestGenerator<T>;\n};\n\ntype PropertyProvider<T extends {}, P> = (cb: TestBuilder<T>) => P;\n\nconst evaluate = <T extends {}, P>(builder: TestBuilder<T>, arg: P | PropertyProvider<T, P>) =>\n arg === 'function' ? (arg as Function)(builder) : arg;\n\n/**\n * The builder provides building blocks for tests with sensible defaults.\n * - Factory methods trigger the automatic generation of unset required properties.\n * - Avoids explosion of overly specific test functions that require and return large bags of properties.\n */\nexport class TestBuilder<T extends {}> {\n static readonly ROOT_DIR = 'feeds';\n\n constructor(public readonly _properties: TestBuilderOptions<T> = {}) {}\n\n /**\n * Creates a new builder with the current builder's properties.\n */\n clone(): TestBuilder<T> {\n return new TestBuilder<T>(Object.assign({}, this._properties));\n }\n\n get keyring(): Keyring {\n return (this._properties.keyring ??= new Keyring());\n }\n\n get storage(): Storage {\n return (this._properties.storage ??= createStorage({ type: StorageType.RAM }));\n }\n\n get root(): Directory {\n return (this._properties.root ??= this.storage.createDirectory(TestBuilder.ROOT_DIR));\n }\n\n setKeyring(keyring: Keyring | PropertyProvider<T, Keyring>): this {\n this._properties.keyring = evaluate(this, keyring);\n return this;\n }\n\n setStorage(storage: Storage, root?: string): this {\n this._properties.storage = evaluate(this, storage);\n if (root) {\n this._properties.root = this.storage.createDirectory(root);\n }\n\n return this;\n }\n\n setRoot(root: Directory): this {\n this._properties.root = evaluate(this, root);\n return this;\n }\n\n createFeedFactory(): FeedFactory<T> {\n return new FeedFactory<T>({\n root: this.root,\n signer: this.keyring,\n hypercore: {\n valueEncoding: this._properties.valueEncoding,\n },\n });\n }\n\n createFeedStore(): FeedStore<T> {\n return new FeedStore<T>({\n factory: this.createFeedFactory(),\n });\n }\n}\n\n/**\n * Builder with default encoder and generator.\n */\nexport class TestItemBuilder extends TestBuilder<TestItem> {\n constructor() {\n super({\n valueEncoding: defaultValueEncoding,\n generator: defaultTestGenerator,\n });\n }\n\n get valueEncoding() {\n return this._properties.valueEncoding!;\n }\n\n get generator() {\n return this._properties.generator!;\n }\n}\n", "//\n// Copyright 2022 DXOS.org\n//\n\nimport { sleep } from '@dxos/async';\nimport { type Codec } from '@dxos/codec-protobuf';\nimport { createCodecEncoding } from '@dxos/hypercore';\nimport { faker } from '@dxos/random';\nimport type { AbstractValueEncoding } from '@dxos/vendor-hypercore/hypercore';\n\nimport { type FeedWriter } from '../feed-writer';\n\nexport type TestItem = {\n id: string;\n index: number;\n value: string;\n};\n\nexport const defaultCodec: Codec<any> = {\n encode: (obj: any) => Buffer.from(JSON.stringify(obj)),\n decode: (buffer: Uint8Array) => JSON.parse(buffer.toString()),\n};\n\nexport const defaultValueEncoding: AbstractValueEncoding<any> = createCodecEncoding(defaultCodec);\n\nexport type TestBlockGenerator<T> = (i: number) => T;\n\nexport const defaultTestBlockGenerator: TestBlockGenerator<TestItem> = (i) => ({\n id: faker.string.uuid(),\n index: i,\n value: faker.lorem.sentence(),\n});\n\n/**\n * Writes data to feeds.\n */\nexport class TestGenerator<T extends {}> {\n _count = 0;\n\n constructor(private readonly _generate: TestBlockGenerator<T>) {}\n\n async writeBlocks(\n writer: FeedWriter<T>,\n {\n count = 1,\n delay,\n }: {\n count?: number;\n delay?: {\n min: number;\n max: number;\n };\n } = {},\n ) {\n return await Promise.all(\n Array.from(Array(count)).map(async () => {\n const data = this._generate(this._count++);\n const receipt = await writer.write(data);\n if (delay) {\n await sleep(faker.number.int(delay));\n }\n\n return receipt;\n }),\n );\n }\n}\n\nexport const defaultTestGenerator = new TestGenerator<TestItem>(defaultTestBlockGenerator);\n"],
|
|
5
|
-
"mappings": ";;;;;;;AAIA,SAASA,OAAOC,oBAAoB;AACpC,SAASC,eAAe;AACxB,SAASC,iBAAiB
|
|
6
|
-
"names": ["Event", "scheduleTask", "Context", "PublicKey", "MockFeedWriter", "
|
|
5
|
+
"mappings": ";;;;;;;AAIA,SAASA,OAAOC,oBAAoB;AACpC,SAASC,eAAe;AACxB,SAASC,iBAAiB;;AAOnB,IAAMC,iBAAN,MAAMA;;EACKC,UAAU,IAAIL,MAAAA;EACdM,WAAgB,CAAA;EAEhC,YAAqBC,UAAUJ,UAAUK,OAAM,GAAI;SAA9BD,UAAAA;EAA+B;EAEpD,MAAME,MAAMC,MAAS,EAAEC,WAAU,IAAmB,CAAC,GAA0B;AAC7E,SAAKL,SAASM,KAAKF,IAAAA;AAEnB,UAAMG,UAAwB;MAC5BN,SAAS,KAAKA;MACdO,KAAK,KAAKR,SAASS,SAAS;IAC9B;AAEA,UAAMJ,aAAaE,OAAAA;AAEnBZ,iBAAa,IAAIC,QAAAA,QAAAA;;;QAAW,MAAA;AAC1B,WAAKG,QAAQW,KAAK;QAACN;QAAMG;OAAQ;IACnC,CAAA;AAEA,WAAOA;EACT;AACF;;;AC/BA,SAASI,eAAe;AACxB,SAAu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AAII,UAAmB;AACrB,WAAQ,KAAKJ,YAAYI,YAAY,IAAIC,QAAAA;EAC3C;EAEA,IAAIC,UAAmB;AACrB,WAAQ,KAAKN,YAAYM,YAAYC,cAAc;MAAEC,MAAMC,YAAYC;IAAI,CAAA;EAC7E;EAEA,IAAIC,OAAkB;AACpB,WAAQ,KAAKX,YAAYW,SAAS,KAAKL,QAAQM,gBAAgBd,aAAYC,QAAQ;EACrF;EAEAc,WAAWT,SAAuD;AAChE,SAAKJ,YAAYI,UAAUT,SAAS,MAAMS,OAAAA;AAC1C,WAAO;EACT;EAEAU,WAAWR,SAAkBK,MAAqB;AAChD,SAAKX,YAAYM,UAAUX,SAAS,MAAMW,OAAAA;AAC1C,QAAIK,MAAM;AACR,WAAKX,YAAYW,OAAO,KAAKL,QAAQM,gBAAgBD,IAAAA;IACvD;AAEA,WAAO;EACT;EAEAI,QAAQJ,MAAuB;AAC7B,SAAKX,YAAYW,OAAOhB,SAAS,MAAMgB,IAAAA;AACvC,WAAO;EACT;EAEAK,oBAAoC;AAClC,WAAO,IAAIC,YAAe;MACxBN,MAAM,KAAKA;MACXO,QAAQ,KAAKd;MACbe,WAAW;QACTC,eAAe,KAAKpB,YAAYoB;MAClC;IACF,CAAA;EACF;EAEAC,kBAAgC;AAC9B,WAAO,IAAIC,UAAa;MACtBC,SAAS,KAAKP,kBAAiB;IACjC,CAAA;EACF;AACF;AAKO,IAAMQ,kBAAN,cAA8B1B,YAAAA;EACnC,cAAc;AACZ,UAAM;MACJsB,eAAeK;MACfC,WAAWC;IACb,CAAA;EACF;EAEA,IAAIP,gBAAgB;AAClB,WAAO,KAAKpB,YAAYoB;EAC1B;EAEA,IAAIM,YAAY;AACd,WAAO,KAAK1B,YAAY0B;EAC1B;AACF;",
|
|
6
|
+
"names": ["Event", "scheduleTask", "Context", "PublicKey", "MockFeedWriter", "written", "messages", "feedKey", "random", "write", "data", "afterWrite", "push", "receipt", "seq", "length", "emit", "Keyring", "StorageType", "createStorage", "sleep", "createCodecEncoding", "faker", "defaultCodec", "encode", "obj", "Buffer", "from", "JSON", "stringify", "decode", "buffer", "parse", "toString", "defaultValueEncoding", "createCodecEncoding", "defaultTestBlockGenerator", "i", "id", "faker", "string", "uuid", "index", "value", "lorem", "sentence", "TestGenerator", "_count", "_generate", "writeBlocks", "writer", "count", "delay", "Promise", "all", "Array", "map", "data", "receipt", "write", "sleep", "number", "int", "defaultTestGenerator", "evaluate", "builder", "arg", "TestBuilder", "ROOT_DIR", "_properties", "clone", "Object", "assign", "keyring", "Keyring", "storage", "createStorage", "type", "StorageType", "RAM", "root", "createDirectory", "setKeyring", "setStorage", "setRoot", "createFeedFactory", "FeedFactory", "signer", "hypercore", "valueEncoding", "createFeedStore", "FeedStore", "factory", "TestItemBuilder", "defaultValueEncoding", "generator", "defaultTestGenerator"]
|
|
7
7
|
}
|