@dxos/feed-store 0.8.4-main.84f28bd → 0.8.4-main.8baae0fced
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/LICENSE +102 -5
- package/README.md +1 -1
- package/dist/lib/browser/{chunk-YBS47XQD.mjs → chunk-MB63GMGR.mjs} +106 -191
- package/dist/lib/browser/chunk-MB63GMGR.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +54 -194
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +14 -16
- package/dist/lib/browser/testing/index.mjs.map +3 -3
- package/dist/lib/node-esm/{chunk-3SO44TKS.mjs → chunk-VZUET36D.mjs} +106 -191
- package/dist/lib/node-esm/chunk-VZUET36D.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +54 -194
- package/dist/lib/node-esm/index.mjs.map +3 -3
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/testing/index.mjs +14 -16
- package/dist/lib/node-esm/testing/index.mjs.map +3 -3
- package/dist/types/src/feed-factory.d.ts.map +1 -1
- package/dist/types/src/feed-iterator.d.ts.map +1 -1
- package/dist/types/src/feed-queue.d.ts +1 -1
- package/dist/types/src/feed-queue.d.ts.map +1 -1
- package/dist/types/src/feed-set-iterator.d.ts.map +1 -1
- package/dist/types/src/feed-store.d.ts.map +1 -1
- package/dist/types/src/feed-wrapper.d.ts +18 -19
- package/dist/types/src/feed-wrapper.d.ts.map +1 -1
- package/dist/types/src/feed-writer.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +1 -1
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/testing/mocks.d.ts.map +1 -1
- package/dist/types/src/testing/test-builder.d.ts +2 -2
- package/dist/types/src/testing/test-builder.d.ts.map +1 -1
- package/dist/types/src/testing/test-generator.d.ts +2 -2
- package/dist/types/src/testing/test-generator.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +27 -27
- package/src/feed-queue.test.ts +1 -1
- package/src/feed-queue.ts +5 -3
- package/src/feed-set-iterator.test.ts +6 -6
- package/src/feed-store.node.test.ts +5 -5
- package/src/feed-wrapper.test.ts +45 -12
- package/src/feed-wrapper.ts +74 -35
- package/src/index.ts +1 -1
- package/src/testing/test-builder.ts +3 -4
- package/src/testing/test-generator.ts +5 -6
- package/dist/lib/browser/chunk-YBS47XQD.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-3SO44TKS.mjs.map +0 -7
|
@@ -1 +1 @@
|
|
|
1
|
-
{"inputs":{"src/feed-wrapper.ts":{"bytes":
|
|
1
|
+
{"inputs":{"src/feed-wrapper.ts":{"bytes":34881,"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":8838,"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":18825,"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":9407,"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":18871,"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":11463,"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":2542,"imports":[],"format":"esm"},"src/index.ts":{"bytes":1025,"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":3350,"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":5435,"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":9557,"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":575,"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":24107},"dist/lib/browser/index.mjs":{"imports":[{"path":"dist/lib/browser/chunk-MB63GMGR.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":2509},"src/feed-queue.ts":{"bytesInOutput":4679},"src/feed-set-iterator.ts":{"bytesInOutput":4540},"src/feed-writer.ts":{"bytesInOutput":273}},"bytes":12499},"dist/lib/browser/testing/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":9581},"dist/lib/browser/testing/index.mjs":{"imports":[{"path":"dist/lib/browser/chunk-MB63GMGR.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":776},"src/testing/index.ts":{"bytesInOutput":0},"src/testing/test-builder.ts":{"bytesInOutput":1800},"src/testing/test-generator.ts":{"bytesInOutput":971}},"bytes":3979},"dist/lib/browser/chunk-MB63GMGR.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":26977},"dist/lib/browser/chunk-MB63GMGR.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":8460},"src/feed-factory.ts":{"bytesInOutput":1945},"src/feed-store.ts":{"bytesInOutput":2885}},"bytes":13492}}}
|
|
@@ -2,7 +2,7 @@ import "@dxos/node-std/globals";
|
|
|
2
2
|
import {
|
|
3
3
|
FeedFactory,
|
|
4
4
|
FeedStore
|
|
5
|
-
} from "../chunk-
|
|
5
|
+
} from "../chunk-MB63GMGR.mjs";
|
|
6
6
|
|
|
7
7
|
// src/testing/mocks.ts
|
|
8
8
|
import { Event, scheduleTask } from "@dxos/async";
|
|
@@ -10,10 +10,11 @@ import { Context } from "@dxos/context";
|
|
|
10
10
|
import { PublicKey } from "@dxos/keys";
|
|
11
11
|
var __dxlog_file = "/__w/dxos/dxos/packages/common/feed-store/src/testing/mocks.ts";
|
|
12
12
|
var MockFeedWriter = class {
|
|
13
|
+
feedKey;
|
|
14
|
+
written = new Event();
|
|
15
|
+
messages = [];
|
|
13
16
|
constructor(feedKey = PublicKey.random()) {
|
|
14
17
|
this.feedKey = feedKey;
|
|
15
|
-
this.written = new Event();
|
|
16
|
-
this.messages = [];
|
|
17
18
|
}
|
|
18
19
|
async write(data, { afterWrite } = {}) {
|
|
19
20
|
this.messages.push(data);
|
|
@@ -22,10 +23,7 @@ var MockFeedWriter = class {
|
|
|
22
23
|
seq: this.messages.length - 1
|
|
23
24
|
};
|
|
24
25
|
await afterWrite?.(receipt);
|
|
25
|
-
scheduleTask(new Context(void 0, {
|
|
26
|
-
F: __dxlog_file,
|
|
27
|
-
L: 30
|
|
28
|
-
}), () => {
|
|
26
|
+
scheduleTask(new Context(void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 23 }), () => {
|
|
29
27
|
this.written.emit([
|
|
30
28
|
data,
|
|
31
29
|
receipt
|
|
@@ -37,33 +35,34 @@ var MockFeedWriter = class {
|
|
|
37
35
|
|
|
38
36
|
// src/testing/test-builder.ts
|
|
39
37
|
import { Keyring } from "@dxos/keyring";
|
|
40
|
-
import {
|
|
38
|
+
import { StorageType, createStorage } from "@dxos/random-access-storage";
|
|
41
39
|
|
|
42
40
|
// src/testing/test-generator.ts
|
|
43
41
|
import { sleep } from "@dxos/async";
|
|
44
42
|
import { createCodecEncoding } from "@dxos/hypercore";
|
|
45
|
-
import {
|
|
43
|
+
import { random } from "@dxos/random";
|
|
46
44
|
var defaultCodec = {
|
|
47
45
|
encode: (obj) => Buffer.from(JSON.stringify(obj)),
|
|
48
46
|
decode: (buffer) => JSON.parse(buffer.toString())
|
|
49
47
|
};
|
|
50
48
|
var defaultValueEncoding = createCodecEncoding(defaultCodec);
|
|
51
49
|
var defaultTestBlockGenerator = (i) => ({
|
|
52
|
-
id:
|
|
50
|
+
id: random.string.uuid(),
|
|
53
51
|
index: i,
|
|
54
|
-
value:
|
|
52
|
+
value: random.lorem.sentence()
|
|
55
53
|
});
|
|
56
54
|
var TestGenerator = class {
|
|
55
|
+
_generate;
|
|
56
|
+
_count = 0;
|
|
57
57
|
constructor(_generate) {
|
|
58
58
|
this._generate = _generate;
|
|
59
|
-
this._count = 0;
|
|
60
59
|
}
|
|
61
60
|
async writeBlocks(writer, { count = 1, delay } = {}) {
|
|
62
61
|
return await Promise.all(Array.from(Array(count)).map(async () => {
|
|
63
62
|
const data = this._generate(this._count++);
|
|
64
63
|
const receipt = await writer.write(data);
|
|
65
64
|
if (delay) {
|
|
66
|
-
await sleep(
|
|
65
|
+
await sleep(random.number.int(delay));
|
|
67
66
|
}
|
|
68
67
|
return receipt;
|
|
69
68
|
}));
|
|
@@ -74,9 +73,8 @@ var defaultTestGenerator = new TestGenerator(defaultTestBlockGenerator);
|
|
|
74
73
|
// src/testing/test-builder.ts
|
|
75
74
|
var evaluate = (builder, arg) => arg === "function" ? arg(builder) : arg;
|
|
76
75
|
var TestBuilder = class _TestBuilder {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
}
|
|
76
|
+
_properties;
|
|
77
|
+
static ROOT_DIR = "feeds";
|
|
80
78
|
constructor(_properties = {}) {
|
|
81
79
|
this._properties = _properties;
|
|
82
80
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/testing/mocks.ts", "../../../../src/testing/test-builder.ts", "../../../../src/testing/test-generator.ts"],
|
|
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
|
|
5
|
-
"mappings": ";;;;;;;AAIA,SAASA,OAAOC,oBAAoB;AACpC,SAASC,eAAe;AACxB,SAASC,iBAAiB
|
|
6
|
-
"names": ["Event", "scheduleTask", "Context", "PublicKey", "
|
|
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';\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 { random } 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: random.string.uuid(),\n index: i,\n value: random.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(random.number.int(delay));\n }\n\n return receipt;\n }),\n );\n }\n}\n\nexport const defaultTestGenerator = new TestGenerator<TestItem>(defaultTestBlockGenerator);\n"],
|
|
5
|
+
"mappings": "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",
|
|
6
|
+
"names": ["Event", "scheduleTask", "Context", "PublicKey", "written", "messages", "feedKey", "write", "receipt", "seq", "afterWrite", "emit", "data", "Keyring", "StorageType", "createStorage", "sleep", "createCodecEncoding", "random", "defaultCodec", "encode", "obj", "Buffer", "from", "JSON", "stringify", "decode", "buffer", "parse", "toString", "defaultValueEncoding", "defaultTestBlockGenerator", "i", "id", "string", "uuid", "index", "value", "lorem", "sentence", "TestGenerator", "_count", "_generate", "writeBlocks", "writer", "count", "delay", "Promise", "all", "Array", "map", "data", "receipt", "write", "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
|
}
|
|
@@ -2,72 +2,28 @@ import { createRequire } from 'node:module';const require = createRequire(import
|
|
|
2
2
|
|
|
3
3
|
// src/feed-wrapper.ts
|
|
4
4
|
import { inspect } from "node:util";
|
|
5
|
+
import { promisify } from "node:util";
|
|
5
6
|
import { Readable, Transform } from "streamx";
|
|
6
7
|
import { Trigger } from "@dxos/async";
|
|
7
|
-
import {
|
|
8
|
-
import { invariant } from "@dxos/invariant";
|
|
8
|
+
import { StackTrace, inspectObject } from "@dxos/debug";
|
|
9
|
+
import { assertArgument, invariant } from "@dxos/invariant";
|
|
9
10
|
import { log } from "@dxos/log";
|
|
10
|
-
import { arrayToBuffer,
|
|
11
|
+
import { arrayToBuffer, rangeFromTo } from "@dxos/util";
|
|
11
12
|
var __dxlog_file = "/__w/dxos/dxos/packages/common/feed-store/src/feed-wrapper.ts";
|
|
12
13
|
var FeedWrapper = class {
|
|
13
|
-
|
|
14
|
-
|
|
14
|
+
_key;
|
|
15
|
+
_storageDirectory;
|
|
16
|
+
_hypercore;
|
|
17
|
+
_pendingWrites = /* @__PURE__ */ new Set();
|
|
18
|
+
// Pending while writes are happening. Resolves when there are no pending writes.
|
|
19
|
+
_writeLock = new Trigger();
|
|
20
|
+
_closed = false;
|
|
21
|
+
constructor(hypercore2, _key, _storageDirectory) {
|
|
15
22
|
this._key = _key;
|
|
16
23
|
this._storageDirectory = _storageDirectory;
|
|
17
|
-
|
|
18
|
-
this.
|
|
19
|
-
this.
|
|
20
|
-
this._closed = false;
|
|
21
|
-
this.on = this._binder.fn(this._hypercore.on);
|
|
22
|
-
this.off = this._binder.fn(this._hypercore.off);
|
|
23
|
-
this.open = this._binder.async(this._hypercore.open);
|
|
24
|
-
this._close = this._binder.async(this._hypercore.close);
|
|
25
|
-
this.close = async () => {
|
|
26
|
-
if (this._pendingWrites.size) {
|
|
27
|
-
log.warn("Closing feed with pending writes", {
|
|
28
|
-
feed: this._key,
|
|
29
|
-
count: this._pendingWrites.size,
|
|
30
|
-
pendingWrites: Array.from(this._pendingWrites.values()).map((stack) => stack.getStack())
|
|
31
|
-
}, {
|
|
32
|
-
F: __dxlog_file,
|
|
33
|
-
L: 173,
|
|
34
|
-
S: this,
|
|
35
|
-
C: (f, a) => f(...a)
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
this._closed = true;
|
|
39
|
-
await this.flushToDisk();
|
|
40
|
-
await this._close();
|
|
41
|
-
};
|
|
42
|
-
this.has = this._binder.fn(this._hypercore.has);
|
|
43
|
-
this.get = this._binder.async(this._hypercore.get);
|
|
44
|
-
this.append = this._binder.async(this._hypercore.append);
|
|
45
|
-
this.download = this._binder.fn(this._hypercore.download);
|
|
46
|
-
this.undownload = this._binder.fn(this._hypercore.undownload);
|
|
47
|
-
this.setDownloading = this._binder.fn(this._hypercore.setDownloading);
|
|
48
|
-
this.replicate = this._binder.fn(this._hypercore.replicate);
|
|
49
|
-
this.clear = this._binder.async(this._hypercore.clear);
|
|
50
|
-
this.proof = this._binder.async(this._hypercore.proof);
|
|
51
|
-
this.put = this._binder.async(this._hypercore.put);
|
|
52
|
-
this.putBuffer = this._binder.async(this._hypercore._putBuffer);
|
|
53
|
-
invariant(this._hypercore, void 0, {
|
|
54
|
-
F: __dxlog_file,
|
|
55
|
-
L: 37,
|
|
56
|
-
S: this,
|
|
57
|
-
A: [
|
|
58
|
-
"this._hypercore",
|
|
59
|
-
""
|
|
60
|
-
]
|
|
61
|
-
});
|
|
62
|
-
invariant(this._key, void 0, {
|
|
63
|
-
F: __dxlog_file,
|
|
64
|
-
L: 38,
|
|
65
|
-
S: this,
|
|
66
|
-
A: [
|
|
67
|
-
"this._key",
|
|
68
|
-
""
|
|
69
|
-
]
|
|
70
|
-
});
|
|
24
|
+
assertArgument(hypercore2, "hypercore");
|
|
25
|
+
this._hypercore = hypercore2;
|
|
26
|
+
invariant(this._key, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 27, S: this, A: ["this._key", ""] });
|
|
71
27
|
this._writeLock.wake();
|
|
72
28
|
}
|
|
73
29
|
[inspect.custom]() {
|
|
@@ -112,21 +68,8 @@ var FeedWrapper = class {
|
|
|
112
68
|
log("write", {
|
|
113
69
|
feed: this._key,
|
|
114
70
|
seq: this._hypercore.length
|
|
115
|
-
}, {
|
|
116
|
-
|
|
117
|
-
L: 97,
|
|
118
|
-
S: this,
|
|
119
|
-
C: (f, a) => f(...a)
|
|
120
|
-
});
|
|
121
|
-
invariant(!this._closed, "Feed closed", {
|
|
122
|
-
F: __dxlog_file,
|
|
123
|
-
L: 98,
|
|
124
|
-
S: this,
|
|
125
|
-
A: [
|
|
126
|
-
"!this._closed",
|
|
127
|
-
"'Feed closed'"
|
|
128
|
-
]
|
|
129
|
-
});
|
|
71
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 74, S: this });
|
|
72
|
+
invariant(!this._closed, "Feed closed", { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 78, S: this, A: ["!this._closed", "'Feed closed'"] });
|
|
130
73
|
const stackTrace = new StackTrace();
|
|
131
74
|
try {
|
|
132
75
|
this._pendingWrites.add(stackTrace);
|
|
@@ -148,24 +91,11 @@ var FeedWrapper = class {
|
|
|
148
91
|
}
|
|
149
92
|
async appendWithReceipt(data) {
|
|
150
93
|
const seq = await this.append(data);
|
|
151
|
-
invariant(seq < this.length, "Invalid seq after write", {
|
|
152
|
-
F: __dxlog_file,
|
|
153
|
-
L: 129,
|
|
154
|
-
S: this,
|
|
155
|
-
A: [
|
|
156
|
-
"seq < this.length",
|
|
157
|
-
"'Invalid seq after write'"
|
|
158
|
-
]
|
|
159
|
-
});
|
|
94
|
+
invariant(seq < this.length, "Invalid seq after write", { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 103, S: this, A: ["seq < this.length", "'Invalid seq after write'"] });
|
|
160
95
|
log("write complete", {
|
|
161
96
|
feed: this._key,
|
|
162
97
|
seq
|
|
163
|
-
}, {
|
|
164
|
-
F: __dxlog_file,
|
|
165
|
-
L: 130,
|
|
166
|
-
S: this,
|
|
167
|
-
C: (f, a) => f(...a)
|
|
168
|
-
});
|
|
98
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 104, S: this });
|
|
169
99
|
const receipt = {
|
|
170
100
|
feedKey: this.key,
|
|
171
101
|
seq
|
|
@@ -194,19 +124,72 @@ var FeedWrapper = class {
|
|
|
194
124
|
get byteLength() {
|
|
195
125
|
return this._hypercore.byteLength;
|
|
196
126
|
}
|
|
127
|
+
on(...args) {
|
|
128
|
+
return this._hypercore.on(...args);
|
|
129
|
+
}
|
|
130
|
+
off(...args) {
|
|
131
|
+
return this._hypercore.off(...args);
|
|
132
|
+
}
|
|
133
|
+
open(...args) {
|
|
134
|
+
return promisify(this._hypercore.open.bind(this._hypercore))(...args);
|
|
135
|
+
}
|
|
136
|
+
_close(...args) {
|
|
137
|
+
return promisify(this._hypercore.close.bind(this._hypercore))(...args);
|
|
138
|
+
}
|
|
139
|
+
close = async () => {
|
|
140
|
+
if (this._pendingWrites.size) {
|
|
141
|
+
log.warn("Closing feed with pending writes", {
|
|
142
|
+
feed: this._key,
|
|
143
|
+
count: this._pendingWrites.size,
|
|
144
|
+
pendingWrites: Array.from(this._pendingWrites.values()).map((stack) => stack.getStack())
|
|
145
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 149, S: this });
|
|
146
|
+
}
|
|
147
|
+
this._closed = true;
|
|
148
|
+
await this.flushToDisk();
|
|
149
|
+
await this._close();
|
|
150
|
+
};
|
|
151
|
+
has(start, end) {
|
|
152
|
+
return this._hypercore.has(start, end);
|
|
153
|
+
}
|
|
154
|
+
get(index, options) {
|
|
155
|
+
return promisify(this._hypercore.get.bind(this._hypercore))(index, options);
|
|
156
|
+
}
|
|
157
|
+
// TODO(dmaretskyi): Type better
|
|
158
|
+
append(data) {
|
|
159
|
+
return promisify(this._hypercore.append.bind(this._hypercore))(data);
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Will not resolve if `end` parameter is not specified and the feed is not closed.
|
|
163
|
+
*/
|
|
164
|
+
download(...args) {
|
|
165
|
+
return this._hypercore.download(...args);
|
|
166
|
+
}
|
|
167
|
+
undownload(...args) {
|
|
168
|
+
return this._hypercore.undownload(...args);
|
|
169
|
+
}
|
|
170
|
+
setDownloading(...args) {
|
|
171
|
+
return this._hypercore.setDownloading(...args);
|
|
172
|
+
}
|
|
173
|
+
replicate(...args) {
|
|
174
|
+
return this._hypercore.replicate(...args);
|
|
175
|
+
}
|
|
176
|
+
clear(start, end) {
|
|
177
|
+
return promisify(this._hypercore.clear.bind(this._hypercore))(start, end);
|
|
178
|
+
}
|
|
179
|
+
proof(index, options) {
|
|
180
|
+
return promisify(this._hypercore.proof.bind(this._hypercore))(index);
|
|
181
|
+
}
|
|
182
|
+
put(index, data, proof) {
|
|
183
|
+
return promisify(this._hypercore.put.bind(this._hypercore))(index, data, proof);
|
|
184
|
+
}
|
|
185
|
+
putBuffer(index, data, proof, peer) {
|
|
186
|
+
return promisify(this._hypercore._putBuffer.bind(this._hypercore))(index, data, proof, peer);
|
|
187
|
+
}
|
|
197
188
|
/**
|
|
198
189
|
* Clear and check for integrity.
|
|
199
190
|
*/
|
|
200
191
|
async safeClear(from, to) {
|
|
201
|
-
invariant(from >= 0 && from < to && to <= this.length, "Invalid range", {
|
|
202
|
-
F: __dxlog_file,
|
|
203
|
-
L: 210,
|
|
204
|
-
S: this,
|
|
205
|
-
A: [
|
|
206
|
-
"from >= 0 && from < to && to <= this.length",
|
|
207
|
-
"'Invalid range'"
|
|
208
|
-
]
|
|
209
|
-
});
|
|
192
|
+
invariant(from >= 0 && from < to && to <= this.length, "Invalid range", { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 198, S: this, A: ["from >= 0 && from < to && to <= this.length", "'Invalid range'"] });
|
|
210
193
|
const CHECK_MESSAGES = 20;
|
|
211
194
|
const checkBegin = to;
|
|
212
195
|
const checkEnd = Math.min(checkBegin + CHECK_MESSAGES, this.length);
|
|
@@ -231,29 +214,16 @@ var FeedWrapper = class {
|
|
|
231
214
|
}
|
|
232
215
|
};
|
|
233
216
|
var BatchedReadStream = class extends Readable {
|
|
217
|
+
_feed;
|
|
218
|
+
_batch;
|
|
219
|
+
_cursor;
|
|
220
|
+
_reading = false;
|
|
234
221
|
constructor(feed, opts = {}) {
|
|
235
222
|
super({
|
|
236
223
|
objectMode: true
|
|
237
224
|
});
|
|
238
|
-
this.
|
|
239
|
-
invariant(opts.
|
|
240
|
-
F: __dxlog_file,
|
|
241
|
-
L: 252,
|
|
242
|
-
S: this,
|
|
243
|
-
A: [
|
|
244
|
-
"opts.live === true",
|
|
245
|
-
"'Only live mode supported'"
|
|
246
|
-
]
|
|
247
|
-
});
|
|
248
|
-
invariant(opts.batch !== void 0 && opts.batch > 1, void 0, {
|
|
249
|
-
F: __dxlog_file,
|
|
250
|
-
L: 253,
|
|
251
|
-
S: this,
|
|
252
|
-
A: [
|
|
253
|
-
"opts.batch !== undefined && opts.batch > 1",
|
|
254
|
-
""
|
|
255
|
-
]
|
|
256
|
-
});
|
|
225
|
+
invariant(opts.live === true, "Only live mode supported", { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 231, S: this, A: ["opts.live === true", "'Only live mode supported'"] });
|
|
226
|
+
invariant(opts.batch !== void 0 && opts.batch > 1, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 232, S: this, A: ["opts.batch !== undefined && opts.batch > 1", ""] });
|
|
257
227
|
this._feed = feed;
|
|
258
228
|
this._batch = opts.batch;
|
|
259
229
|
this._cursor = opts.start ?? 0;
|
|
@@ -311,15 +281,13 @@ import { createCrypto, hypercore } from "@dxos/hypercore";
|
|
|
311
281
|
import { log as log2 } from "@dxos/log";
|
|
312
282
|
var __dxlog_file2 = "/__w/dxos/dxos/packages/common/feed-store/src/feed-factory.ts";
|
|
313
283
|
var FeedFactory = class {
|
|
284
|
+
_root;
|
|
285
|
+
_signer;
|
|
286
|
+
_hypercoreOptions;
|
|
314
287
|
constructor({ root, signer, hypercore: hypercore2 }) {
|
|
315
288
|
log2("FeedFactory", {
|
|
316
289
|
options: hypercore2
|
|
317
|
-
}, {
|
|
318
|
-
F: __dxlog_file2,
|
|
319
|
-
L: 43,
|
|
320
|
-
S: this,
|
|
321
|
-
C: (f, a) => f(...a)
|
|
322
|
-
});
|
|
290
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file2, L: 17, S: this });
|
|
323
291
|
this._root = root ?? failUndefined();
|
|
324
292
|
this._signer = signer;
|
|
325
293
|
this._hypercoreOptions = hypercore2;
|
|
@@ -332,12 +300,7 @@ var FeedFactory = class {
|
|
|
332
300
|
throw new Error("Signer required to create writable feeds.");
|
|
333
301
|
}
|
|
334
302
|
if (options?.secretKey) {
|
|
335
|
-
log2.warn("Secret key ignored due to signer.", void 0, {
|
|
336
|
-
F: __dxlog_file2,
|
|
337
|
-
L: 58,
|
|
338
|
-
S: this,
|
|
339
|
-
C: (f, a) => f(...a)
|
|
340
|
-
});
|
|
303
|
+
log2.warn("Secret key ignored due to signer.", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file2, L: 32, S: this });
|
|
341
304
|
}
|
|
342
305
|
const key = await subtleCrypto.digest("SHA-256", Buffer.from(publicKey.toHex()));
|
|
343
306
|
const opts = defaultsDeep({}, this._hypercoreOptions, {
|
|
@@ -351,12 +314,7 @@ var FeedFactory = class {
|
|
|
351
314
|
const { type, native } = storageDir.getOrCreateFile(filename);
|
|
352
315
|
log2("created", {
|
|
353
316
|
path: `${type}:${this._root.path}/${publicKey.truncate()}/${filename}`
|
|
354
|
-
}, {
|
|
355
|
-
F: __dxlog_file2,
|
|
356
|
-
L: 82,
|
|
357
|
-
S: this,
|
|
358
|
-
C: (f, a) => f(...a)
|
|
359
|
-
});
|
|
317
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file2, L: 46, S: this });
|
|
360
318
|
return native;
|
|
361
319
|
};
|
|
362
320
|
const core = hypercore(makeStorage, Buffer.from(key), opts);
|
|
@@ -373,11 +331,12 @@ import { log as log3 } from "@dxos/log";
|
|
|
373
331
|
import { ComplexMap, defaultMap } from "@dxos/util";
|
|
374
332
|
var __dxlog_file3 = "/__w/dxos/dxos/packages/common/feed-store/src/feed-store.ts";
|
|
375
333
|
var FeedStore = class {
|
|
334
|
+
_feeds = new ComplexMap(PublicKey.hash);
|
|
335
|
+
_mutexes = new ComplexMap(PublicKey.hash);
|
|
336
|
+
_factory;
|
|
337
|
+
_closed = false;
|
|
338
|
+
feedOpened = new Event();
|
|
376
339
|
constructor({ factory }) {
|
|
377
|
-
this._feeds = new ComplexMap(PublicKey.hash);
|
|
378
|
-
this._mutexes = new ComplexMap(PublicKey.hash);
|
|
379
|
-
this._closed = false;
|
|
380
|
-
this.feedOpened = new Event();
|
|
381
340
|
this._factory = factory ?? failUndefined2();
|
|
382
341
|
}
|
|
383
342
|
get size() {
|
|
@@ -399,30 +358,9 @@ var FeedStore = class {
|
|
|
399
358
|
async openFeed(feedKey, { writable, sparse } = {}) {
|
|
400
359
|
log3("opening feed", {
|
|
401
360
|
feedKey
|
|
402
|
-
}, {
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
S: this,
|
|
406
|
-
C: (f, a) => f(...a)
|
|
407
|
-
});
|
|
408
|
-
invariant2(feedKey, void 0, {
|
|
409
|
-
F: __dxlog_file3,
|
|
410
|
-
L: 56,
|
|
411
|
-
S: this,
|
|
412
|
-
A: [
|
|
413
|
-
"feedKey",
|
|
414
|
-
""
|
|
415
|
-
]
|
|
416
|
-
});
|
|
417
|
-
invariant2(!this._closed, "Feed store is closed", {
|
|
418
|
-
F: __dxlog_file3,
|
|
419
|
-
L: 57,
|
|
420
|
-
S: this,
|
|
421
|
-
A: [
|
|
422
|
-
"!this._closed",
|
|
423
|
-
"'Feed store is closed'"
|
|
424
|
-
]
|
|
425
|
-
});
|
|
361
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 36, S: this });
|
|
362
|
+
invariant2(feedKey, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 39, S: this, A: ["feedKey", ""] });
|
|
363
|
+
invariant2(!this._closed, "Feed store is closed", { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 40, S: this, A: ["!this._closed", "'Feed store is closed'"] });
|
|
426
364
|
const mutex = defaultMap(this._mutexes, feedKey, () => new Mutex());
|
|
427
365
|
return mutex.executeSynchronized(async () => {
|
|
428
366
|
let feed = this.getFeed(feedKey);
|
|
@@ -445,12 +383,7 @@ var FeedStore = class {
|
|
|
445
383
|
this.feedOpened.emit(feed);
|
|
446
384
|
log3("opened", {
|
|
447
385
|
feedKey
|
|
448
|
-
}, {
|
|
449
|
-
F: __dxlog_file3,
|
|
450
|
-
L: 85,
|
|
451
|
-
S: this,
|
|
452
|
-
C: (f, a) => f(...a)
|
|
453
|
-
});
|
|
386
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 63, S: this });
|
|
454
387
|
return feed;
|
|
455
388
|
});
|
|
456
389
|
}
|
|
@@ -458,32 +391,14 @@ var FeedStore = class {
|
|
|
458
391
|
* Close all feeds.
|
|
459
392
|
*/
|
|
460
393
|
async close() {
|
|
461
|
-
log3("closing...", void 0, {
|
|
462
|
-
F: __dxlog_file3,
|
|
463
|
-
L: 94,
|
|
464
|
-
S: this,
|
|
465
|
-
C: (f, a) => f(...a)
|
|
466
|
-
});
|
|
394
|
+
log3("closing...", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 72, S: this });
|
|
467
395
|
this._closed = true;
|
|
468
396
|
await Promise.all(Array.from(this._feeds.values()).map(async (feed) => {
|
|
469
397
|
await feed.close();
|
|
470
|
-
invariant2(feed.closed, void 0, {
|
|
471
|
-
F: __dxlog_file3,
|
|
472
|
-
L: 99,
|
|
473
|
-
S: this,
|
|
474
|
-
A: [
|
|
475
|
-
"feed.closed",
|
|
476
|
-
""
|
|
477
|
-
]
|
|
478
|
-
});
|
|
398
|
+
invariant2(feed.closed, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 76, S: this, A: ["feed.closed", ""] });
|
|
479
399
|
}));
|
|
480
400
|
this._feeds.clear();
|
|
481
|
-
log3("closed", void 0, {
|
|
482
|
-
F: __dxlog_file3,
|
|
483
|
-
L: 108,
|
|
484
|
-
S: this,
|
|
485
|
-
C: (f, a) => f(...a)
|
|
486
|
-
});
|
|
401
|
+
log3("closed", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 83, S: this });
|
|
487
402
|
}
|
|
488
403
|
};
|
|
489
404
|
|
|
@@ -492,4 +407,4 @@ export {
|
|
|
492
407
|
FeedFactory,
|
|
493
408
|
FeedStore
|
|
494
409
|
};
|
|
495
|
-
//# sourceMappingURL=chunk-
|
|
410
|
+
//# sourceMappingURL=chunk-VZUET36D.mjs.map
|