@dxos/feed-store 0.10.0 → 0.11.0

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.
@@ -1,7 +0,0 @@
1
- {
2
- "version": 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 { 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": ";;;;;;;AAIA,SAASA,OAAOC,oBAAoB;AACpC,SAASC,eAAe;AACxB,SAASC,iBAAiB;AAI1B,IAAA,eAAA;AAIkBC,IAAU,iBAAVA,MAAyC;EACzCC;EAEhB,UAAA,IAAqBC,MAAAA;aAAAA,CAAAA;EAA+B,YAAA,UAAA,UAAA,OAAA,GAAA;AAEpD,SAAMC,UAAe;;QAGnB,MAAMC,MAAAA,EAAwB,WAAA,IAAA,CAAA,GAAA;SAC5BF,SAAS,KAAKA,IAAAA;UACdG,UAAUJ;MACZ,SAAA,KAAA;MAEA,KAAMK,KAAAA,SAAaF,SAAAA;IAEnBP;UACE,aAAaU,OAAK;iBAACC,IAAAA,QAA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AY;AACd,WAAO,KAAK1B,YAAY0B;EAC1B;AACF;",
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
- }
@@ -1,410 +0,0 @@
1
- import { createRequire } from 'node:module';const require = createRequire(import.meta.url);
2
-
3
- // src/feed-wrapper.ts
4
- import { inspect } from "node:util";
5
- import { promisify } from "node:util";
6
- import { Readable, Transform } from "streamx";
7
- import { Trigger } from "@dxos/async";
8
- import { StackTrace, inspectObject } from "@dxos/debug";
9
- import { assertArgument, invariant } from "@dxos/invariant";
10
- import { log } from "@dxos/log";
11
- import { arrayToBuffer, rangeFromTo } from "@dxos/util";
12
- var __dxlog_file = "/__w/dxos/dxos/packages/common/feed-store/src/feed-wrapper.ts";
13
- var FeedWrapper = class {
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) {
22
- this._key = _key;
23
- this._storageDirectory = _storageDirectory;
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", ""] });
27
- this._writeLock.wake();
28
- }
29
- [inspect.custom]() {
30
- return inspectObject(this);
31
- }
32
- toJSON() {
33
- return {
34
- feedKey: this._key,
35
- length: this.properties.length,
36
- opened: this.properties.opened,
37
- closed: this.properties.closed
38
- };
39
- }
40
- get key() {
41
- return this._key;
42
- }
43
- get core() {
44
- return this._hypercore;
45
- }
46
- // TODO(burdon): Create proxy.
47
- get properties() {
48
- return this._hypercore;
49
- }
50
- createReadableStream(opts) {
51
- const self = this;
52
- const transform = new Transform({
53
- transform(data, cb) {
54
- void self._writeLock.wait().then(() => {
55
- this.push(data);
56
- cb();
57
- });
58
- }
59
- });
60
- const readStream = opts?.batch !== void 0 && opts?.batch > 1 ? new BatchedReadStream(this._hypercore, opts) : this._hypercore.createReadStream(opts);
61
- readStream.pipe(transform, (err) => {
62
- });
63
- return transform;
64
- }
65
- createFeedWriter() {
66
- return {
67
- write: async (data, { afterWrite } = {}) => {
68
- log("write", {
69
- feed: this._key,
70
- seq: this._hypercore.length
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'"] });
73
- const stackTrace = new StackTrace();
74
- try {
75
- this._pendingWrites.add(stackTrace);
76
- if (this._pendingWrites.size === 1) {
77
- this._writeLock.reset();
78
- }
79
- const receipt = await this.appendWithReceipt(data);
80
- await this.flushToDisk();
81
- await afterWrite?.(receipt);
82
- return receipt;
83
- } finally {
84
- this._pendingWrites.delete(stackTrace);
85
- if (this._pendingWrites.size === 0) {
86
- this._writeLock.wake();
87
- }
88
- }
89
- }
90
- };
91
- }
92
- async appendWithReceipt(data) {
93
- const seq = await this.append(data);
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'"] });
95
- log("write complete", {
96
- feed: this._key,
97
- seq
98
- }, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 104, S: this });
99
- const receipt = {
100
- feedKey: this.key,
101
- seq
102
- };
103
- return receipt;
104
- }
105
- /**
106
- * Flush pending changes to disk.
107
- * Calling this is not required unless you want to explicitly wait for data to be written.
108
- */
109
- async flushToDisk() {
110
- await this._storageDirectory.flush();
111
- }
112
- get opened() {
113
- return this._hypercore.opened;
114
- }
115
- get closed() {
116
- return this._hypercore.closed;
117
- }
118
- get readable() {
119
- return this._hypercore.readable;
120
- }
121
- get length() {
122
- return this._hypercore.length;
123
- }
124
- get byteLength() {
125
- return this._hypercore.byteLength;
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
- }
188
- /**
189
- * Clear and check for integrity.
190
- */
191
- async safeClear(from, to) {
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'"] });
193
- const CHECK_MESSAGES = 20;
194
- const checkBegin = to;
195
- const checkEnd = Math.min(checkBegin + CHECK_MESSAGES, this.length);
196
- const messagesBefore = await Promise.all(rangeFromTo(checkBegin, checkEnd).map((idx) => this.get(idx, {
197
- valueEncoding: {
198
- decode: (x) => x
199
- }
200
- })));
201
- await this.clear(from, to);
202
- const messagesAfter = await Promise.all(rangeFromTo(checkBegin, checkEnd).map((idx) => this.get(idx, {
203
- valueEncoding: {
204
- decode: (x) => x
205
- }
206
- })));
207
- for (let i = 0; i < messagesBefore.length; i++) {
208
- const before = arrayToBuffer(messagesBefore[i]);
209
- const after = arrayToBuffer(messagesAfter[i]);
210
- if (!before.equals(after)) {
211
- throw new Error("Feed corruption on clear. There has likely been a data loss.");
212
- }
213
- }
214
- }
215
- };
216
- var BatchedReadStream = class extends Readable {
217
- _feed;
218
- _batch;
219
- _cursor;
220
- _reading = false;
221
- constructor(feed, opts = {}) {
222
- super({
223
- objectMode: true
224
- });
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", ""] });
227
- this._feed = feed;
228
- this._batch = opts.batch;
229
- this._cursor = opts.start ?? 0;
230
- }
231
- _open(cb) {
232
- this._feed.ready(cb);
233
- }
234
- _read(cb) {
235
- if (this._reading) {
236
- return;
237
- }
238
- if (this._feed.bitfield.total(this._cursor, this._cursor + this._batch) === this._batch) {
239
- this._batchedRead(cb);
240
- } else {
241
- this._nonBatchedRead(cb);
242
- }
243
- }
244
- _nonBatchedRead(cb) {
245
- this._feed.get(this._cursor, {
246
- wait: true
247
- }, (err, data) => {
248
- if (err) {
249
- cb(err);
250
- } else {
251
- this._cursor++;
252
- this._reading = false;
253
- this.push(data);
254
- cb(null);
255
- }
256
- });
257
- }
258
- _batchedRead(cb) {
259
- this._feed.getBatch(this._cursor, this._cursor + this._batch, {
260
- wait: true
261
- }, (err, data) => {
262
- if (err) {
263
- cb(err);
264
- } else {
265
- this._cursor += data.length;
266
- this._reading = false;
267
- for (const item of data) {
268
- this.push(item);
269
- }
270
- cb(null);
271
- }
272
- });
273
- }
274
- };
275
-
276
- // src/feed-factory.ts
277
- import defaultsDeep from "lodash.defaultsdeep";
278
- import { subtleCrypto } from "@dxos/crypto";
279
- import { failUndefined } from "@dxos/debug";
280
- import { createCrypto, hypercore } from "@dxos/hypercore";
281
- import { log as log2 } from "@dxos/log";
282
- var __dxlog_file2 = "/__w/dxos/dxos/packages/common/feed-store/src/feed-factory.ts";
283
- var FeedFactory = class {
284
- _root;
285
- _signer;
286
- _hypercoreOptions;
287
- constructor({ root, signer, hypercore: hypercore2 }) {
288
- log2("FeedFactory", {
289
- options: hypercore2
290
- }, { "~LogMeta": "~LogMeta", F: __dxlog_file2, L: 17, S: this });
291
- this._root = root ?? failUndefined();
292
- this._signer = signer;
293
- this._hypercoreOptions = hypercore2;
294
- }
295
- get storageRoot() {
296
- return this._root;
297
- }
298
- async createFeed(publicKey, options) {
299
- if (options?.writable && !this._signer) {
300
- throw new Error("Signer required to create writable feeds.");
301
- }
302
- if (options?.secretKey) {
303
- log2.warn("Secret key ignored due to signer.", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file2, L: 32, S: this });
304
- }
305
- const key = await subtleCrypto.digest("SHA-256", Buffer.from(publicKey.toHex()));
306
- const opts = defaultsDeep({}, this._hypercoreOptions, {
307
- secretKey: this._signer && options?.writable ? Buffer.from("secret") : void 0,
308
- crypto: this._signer ? createCrypto(this._signer, publicKey) : void 0,
309
- onwrite: options?.onwrite,
310
- noiseKeyPair: {}
311
- }, options);
312
- const storageDir = this._root.createDirectory(publicKey.toHex());
313
- const makeStorage = (filename) => {
314
- const { type, native } = storageDir.getOrCreateFile(filename);
315
- log2("created", {
316
- path: `${type}:${this._root.path}/${publicKey.truncate()}/${filename}`
317
- }, { "~LogMeta": "~LogMeta", F: __dxlog_file2, L: 46, S: this });
318
- return native;
319
- };
320
- const core = hypercore(makeStorage, Buffer.from(key), opts);
321
- return new FeedWrapper(core, publicKey, storageDir);
322
- }
323
- };
324
-
325
- // src/feed-store.ts
326
- import { Event, Mutex } from "@dxos/async";
327
- import { failUndefined as failUndefined2 } from "@dxos/debug";
328
- import { invariant as invariant2 } from "@dxos/invariant";
329
- import { PublicKey } from "@dxos/keys";
330
- import { log as log3 } from "@dxos/log";
331
- import { ComplexMap, defaultMap } from "@dxos/util";
332
- var __dxlog_file3 = "/__w/dxos/dxos/packages/common/feed-store/src/feed-store.ts";
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();
339
- constructor({ factory }) {
340
- this._factory = factory ?? failUndefined2();
341
- }
342
- get size() {
343
- return this._feeds.size;
344
- }
345
- get feeds() {
346
- return Array.from(this._feeds.values());
347
- }
348
- /**
349
- * Get the open feed if it exists.
350
- */
351
- getFeed(publicKey) {
352
- return this._feeds.get(publicKey);
353
- }
354
- /**
355
- * Gets or opens a feed.
356
- * The feed is readonly unless a secret key is provided.
357
- */
358
- async openFeed(feedKey, { writable, sparse } = {}) {
359
- log3("opening feed", {
360
- feedKey
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'"] });
364
- const mutex = defaultMap(this._mutexes, feedKey, () => new Mutex());
365
- return mutex.executeSynchronized(async () => {
366
- let feed = this.getFeed(feedKey);
367
- if (feed) {
368
- if (writable && !feed.properties.writable) {
369
- throw new Error(`Read-only feed is already open: ${feedKey.truncate()}`);
370
- } else if ((sparse ?? false) !== feed.properties.sparse) {
371
- throw new Error(`Feed already open with different sparse setting: ${feedKey.truncate()} [${sparse} !== ${feed.properties.sparse}]`);
372
- } else {
373
- await feed.open();
374
- return feed;
375
- }
376
- }
377
- feed = await this._factory.createFeed(feedKey, {
378
- writable,
379
- sparse
380
- });
381
- this._feeds.set(feed.key, feed);
382
- await feed.open();
383
- this.feedOpened.emit(feed);
384
- log3("opened", {
385
- feedKey
386
- }, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 63, S: this });
387
- return feed;
388
- });
389
- }
390
- /**
391
- * Close all feeds.
392
- */
393
- async close() {
394
- log3("closing...", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 72, S: this });
395
- this._closed = true;
396
- await Promise.all(Array.from(this._feeds.values()).map(async (feed) => {
397
- await feed.close();
398
- invariant2(feed.closed, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 76, S: this, A: ["feed.closed", ""] });
399
- }));
400
- this._feeds.clear();
401
- log3("closed", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 83, S: this });
402
- }
403
- };
404
-
405
- export {
406
- FeedWrapper,
407
- FeedFactory,
408
- FeedStore
409
- };
410
- //# sourceMappingURL=chunk-VZUET36D.mjs.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/feed-wrapper.ts", "../../../src/feed-factory.ts", "../../../src/feed-store.ts"],
4
- "sourcesContent": ["//\n// Copyright 2022 DXOS.org\n//\n\nimport { inspect } from 'node:util';\nimport { promisify } from 'node:util';\nimport { Readable, Transform } from 'streamx';\n\nimport { Trigger } from '@dxos/async';\nimport { StackTrace, inspectObject } from '@dxos/debug';\nimport type { Hypercore, HypercoreProperties, ReadStreamOptions } from '@dxos/hypercore';\nimport { assertArgument, invariant } from '@dxos/invariant';\nimport { type PublicKey } from '@dxos/keys';\nimport { log } from '@dxos/log';\nimport { type Directory } from '@dxos/random-access-storage';\nimport { arrayToBuffer, rangeFromTo } from '@dxos/util';\nimport type { GetOptions, Proof } from '@dxos/vendor-hypercore/hypercore';\n\nimport { type FeedWriter, type WriteReceipt } from './feed-writer';\n\n/**\n * Async feed wrapper.\n */\nexport class FeedWrapper<T extends {}> {\n private _hypercore: Hypercore<T>;\n private readonly _pendingWrites = new Set<StackTrace>();\n\n // Pending while writes are happening. Resolves when there are no pending writes.\n private readonly _writeLock = new Trigger();\n\n private _closed = false;\n\n constructor(\n hypercore: Hypercore<T>,\n private _key: PublicKey, // TODO(burdon): Required since currently patching the key inside factory.\n private _storageDirectory: Directory,\n ) {\n assertArgument(hypercore, 'hypercore');\n this._hypercore = hypercore;\n invariant(this._key);\n this._writeLock.wake();\n }\n\n [inspect.custom](): string {\n return inspectObject(this);\n }\n\n toJSON(): { feedKey: PublicKey; length: number; opened: boolean; closed: boolean } {\n return {\n feedKey: this._key,\n length: this.properties.length,\n opened: this.properties.opened,\n closed: this.properties.closed,\n };\n }\n\n get key(): PublicKey {\n return this._key;\n }\n\n get core(): Hypercore<T> {\n return this._hypercore;\n }\n\n // TODO(burdon): Create proxy.\n get properties(): HypercoreProperties {\n return this._hypercore;\n }\n\n createReadableStream(opts?: ReadStreamOptions): Readable {\n // eslint-disable-next-line @typescript-eslint/no-this-alias\n const self = this;\n const transform = new Transform({\n transform(data: any, cb: (err?: Error | null, data?: any) => void) {\n // Delay until write is complete.\n void self._writeLock.wait().then(() => {\n this.push(data);\n cb();\n });\n },\n });\n const readStream =\n opts?.batch !== undefined && opts?.batch > 1\n ? new BatchedReadStream(this._hypercore, opts)\n : this._hypercore.createReadStream(opts);\n\n readStream.pipe(transform, (err: any) => {\n // Ignore errors.\n // We might get \"Writable stream closed prematurely\" error.\n // Its okay since the pipeline is closed and does not expect more messages.\n });\n\n return transform;\n }\n\n createFeedWriter(): FeedWriter<T> {\n return {\n write: async (data: T, { afterWrite } = {}) => {\n log('write', { feed: this._key, seq: this._hypercore.length });\n invariant(!this._closed, 'Feed closed');\n const stackTrace = new StackTrace();\n\n try {\n // Pending writes pause the read stream.\n this._pendingWrites.add(stackTrace);\n if (this._pendingWrites.size === 1) {\n this._writeLock.reset();\n }\n\n const receipt = await this.appendWithReceipt(data);\n\n // TODO(dmaretskyi): Removing this will make user-intiated writes faster but might result in a data-loss.\n await this.flushToDisk();\n\n await afterWrite?.(receipt);\n\n return receipt;\n } finally {\n // Unblock the read stream after the write (and callback) is complete.\n this._pendingWrites.delete(stackTrace);\n if (this._pendingWrites.size === 0) {\n this._writeLock.wake();\n }\n }\n },\n };\n }\n\n async appendWithReceipt(data: T): Promise<WriteReceipt> {\n const seq = await this.append(data);\n invariant(seq < this.length, 'Invalid seq after write');\n log('write complete', { feed: this._key, seq });\n const receipt: WriteReceipt = {\n feedKey: this.key,\n seq,\n };\n return receipt;\n }\n\n /**\n * Flush pending changes to disk.\n * Calling this is not required unless you want to explicitly wait for data to be written.\n */\n async flushToDisk(): Promise<void> {\n await this._storageDirectory.flush();\n }\n\n get opened(): boolean {\n return this._hypercore.opened;\n }\n\n get closed(): boolean {\n return this._hypercore.closed;\n }\n\n get readable(): boolean {\n return this._hypercore.readable;\n }\n\n get length(): number {\n return this._hypercore.length;\n }\n\n get byteLength(): number {\n return this._hypercore.byteLength;\n }\n\n on(...args: any[]) {\n return (this._hypercore as any).on(...args);\n }\n\n off(...args: any[]) {\n return (this._hypercore as any).off(...args);\n }\n\n open(...args: Parameters<Hypercore<T>['open']>) {\n return promisify(this._hypercore.open.bind(this._hypercore) as any)(...args);\n }\n\n _close(...args: Parameters<Hypercore<T>['close']>) {\n return promisify(this._hypercore.close.bind(this._hypercore) as any)(...args);\n }\n\n close = async () => {\n if (this._pendingWrites.size) {\n log.warn('Closing feed with pending writes', {\n feed: this._key,\n count: this._pendingWrites.size,\n pendingWrites: Array.from(this._pendingWrites.values()).map((stack) => stack.getStack()),\n });\n }\n this._closed = true;\n await this.flushToDisk();\n await this._close();\n };\n\n has(start: number, end?: number) {\n return this._hypercore.has(start, end);\n }\n\n get(index: number, options?: GetOptions) {\n return promisify(this._hypercore.get.bind(this._hypercore) as any)(index, options);\n }\n\n // TODO(dmaretskyi): Type better\n append(data: any | any[]): Promise<number> {\n return promisify(this._hypercore.append.bind(this._hypercore))(data);\n }\n\n /**\n * Will not resolve if `end` parameter is not specified and the feed is not closed.\n */\n download(...args: Parameters<Hypercore<T>['download']>) {\n return this._hypercore.download(...args);\n }\n\n undownload(...args: Parameters<Hypercore<T>['undownload']>) {\n return this._hypercore.undownload(...args);\n }\n\n setDownloading(...args: Parameters<Hypercore<T>['setDownloading']>) {\n return this._hypercore.setDownloading(...args);\n }\n\n replicate(...args: Parameters<Hypercore<T>['replicate']>) {\n return this._hypercore.replicate(...args);\n }\n\n clear(start: number, end?: number) {\n return promisify(this._hypercore.clear.bind(this._hypercore))(start, end);\n }\n\n proof(index: number, options?: any) {\n return promisify(this._hypercore.proof.bind(this._hypercore))(index);\n }\n\n put(index: number, data: T, proof: Proof) {\n return promisify(this._hypercore.put.bind(this._hypercore))(index, data, proof);\n }\n\n putBuffer(index: number, data: Buffer | Uint8Array, proof: Proof, peer: null): Promise<void> {\n return promisify((this._hypercore as any)._putBuffer.bind(this._hypercore) as any)(index, data, proof, peer);\n }\n\n /**\n * Clear and check for integrity.\n */\n async safeClear(from: number, to: number): Promise<void> {\n invariant(from >= 0 && from < to && to <= this.length, 'Invalid range');\n\n const CHECK_MESSAGES = 20;\n const checkBegin = to;\n const checkEnd = Math.min(checkBegin + CHECK_MESSAGES, this.length);\n\n const messagesBefore = await Promise.all(\n rangeFromTo(checkBegin, checkEnd).map((idx) =>\n this.get(idx, {\n valueEncoding: { decode: (x: Uint8Array) => x } as any,\n }),\n ),\n );\n\n await this.clear(from, to);\n\n const messagesAfter = await Promise.all(\n rangeFromTo(checkBegin, checkEnd).map((idx) =>\n this.get(idx, {\n valueEncoding: { decode: (x: Uint8Array) => x } as any,\n }),\n ),\n );\n\n for (let i = 0; i < messagesBefore.length; i++) {\n const before = arrayToBuffer(messagesBefore[i]);\n const after = arrayToBuffer(messagesAfter[i]);\n if (!before.equals(after)) {\n throw new Error('Feed corruption on clear. There has likely been a data loss.');\n }\n }\n }\n}\n\nclass BatchedReadStream extends Readable {\n private readonly _feed: Hypercore<any>;\n private readonly _batch: number;\n private _cursor: number;\n private _reading = false;\n\n constructor(feed: Hypercore<any>, opts: ReadStreamOptions = {}) {\n super({ objectMode: true });\n invariant(opts.live === true, 'Only live mode supported');\n invariant(opts.batch !== undefined && opts.batch > 1);\n this._feed = feed;\n this._batch = opts.batch;\n this._cursor = opts.start ?? 0;\n }\n\n override _open(cb: (err: Error | null) => void): void {\n this._feed.ready(cb);\n }\n\n override _read(cb: (err: Error | null) => void): void {\n if (this._reading) {\n return;\n }\n\n if (this._feed.bitfield!.total(this._cursor, this._cursor + this._batch) === this._batch) {\n this._batchedRead(cb);\n } else {\n this._nonBatchedRead(cb);\n }\n }\n\n private _nonBatchedRead(cb: (err: Error | null) => void): void {\n this._feed.get(this._cursor, { wait: true }, (err, data) => {\n if (err) {\n cb(err);\n } else {\n this._cursor++;\n this._reading = false;\n this.push(data);\n cb(null);\n }\n });\n }\n\n private _batchedRead(cb: (err: Error | null) => void): void {\n this._feed.getBatch(this._cursor, this._cursor + this._batch, { wait: true }, (err, data) => {\n if (err) {\n cb(err);\n } else {\n this._cursor += data.length;\n this._reading = false;\n for (const item of data) {\n this.push(item);\n }\n cb(null);\n }\n });\n }\n}\n", "//\n// Copyright 2022 DXOS.org\n//\n\nimport defaultsDeep from 'lodash.defaultsdeep';\n\nimport { type Signer, subtleCrypto } from '@dxos/crypto';\nimport { failUndefined } from '@dxos/debug';\nimport type { HypercoreOptions } from '@dxos/hypercore';\nimport { createCrypto, hypercore } from '@dxos/hypercore';\nimport { type PublicKey } from '@dxos/keys';\nimport { log } from '@dxos/log';\nimport { type Directory } from '@dxos/random-access-storage';\n\nimport { FeedWrapper } from './feed-wrapper';\n\nexport type FeedFactoryOptions = {\n root: Directory;\n signer?: Signer;\n hypercore?: HypercoreOptions;\n};\n\nexport type FeedOptions = HypercoreOptions & {\n writable?: boolean;\n /**\n * Optional hook called before data is written after being verified.\n * Called for writes done by this peer as well as for data replicated from other peers.\n * NOTE: The callback must be invoked to complete the write operation.\n * @param peer Always null in hypercore@9.12.0.\n */\n onwrite?: (index: number, data: any, peer: null, cb: (err: Error | null) => void) => void;\n};\n\n/**\n * Hypercore factory.\n */\nexport class FeedFactory<T extends {}> {\n private readonly _root: Directory;\n private readonly _signer?: Signer;\n private readonly _hypercoreOptions?: HypercoreOptions;\n\n constructor({ root, signer, hypercore }: FeedFactoryOptions) {\n log('FeedFactory', { options: hypercore });\n this._root = root ?? failUndefined();\n this._signer = signer;\n this._hypercoreOptions = hypercore;\n }\n\n get storageRoot() {\n return this._root;\n }\n\n async createFeed(publicKey: PublicKey, options?: FeedOptions): Promise<FeedWrapper<T>> {\n if (options?.writable && !this._signer) {\n throw new Error('Signer required to create writable feeds.');\n }\n if (options?.secretKey) {\n log.warn('Secret key ignored due to signer.');\n }\n\n // Required due to hypercore's 32-byte key limit.\n const key = await subtleCrypto.digest('SHA-256', Buffer.from(publicKey.toHex()));\n\n const opts = defaultsDeep(\n {\n // sparse: false,\n // stats: false,\n },\n this._hypercoreOptions,\n {\n secretKey: this._signer && options?.writable ? Buffer.from('secret') : undefined,\n crypto: this._signer ? createCrypto(this._signer, publicKey) : undefined,\n onwrite: options?.onwrite,\n noiseKeyPair: {}, // We're not using noise.\n },\n options,\n );\n\n const storageDir = this._root.createDirectory(publicKey.toHex());\n const makeStorage = (filename: string) => {\n const { type, native } = storageDir.getOrCreateFile(filename);\n log('created', {\n path: `${type}:${this._root.path}/${publicKey.truncate()}/${filename}`,\n });\n\n return native;\n };\n\n const core = hypercore(makeStorage, Buffer.from(key), opts);\n return new FeedWrapper(core, publicKey, storageDir);\n }\n}\n", "//\n// Copyright 2019 DXOS.org\n//\n\nimport { Event, Mutex } from '@dxos/async';\nimport { failUndefined } from '@dxos/debug';\nimport { invariant } from '@dxos/invariant';\nimport { PublicKey } from '@dxos/keys';\nimport { log } from '@dxos/log';\nimport { ComplexMap, defaultMap } from '@dxos/util';\n\nimport { type FeedFactory, type FeedOptions } from './feed-factory';\nimport { type FeedWrapper } from './feed-wrapper';\n\nexport interface FeedStoreOptions<T extends {}> {\n factory: FeedFactory<T>;\n}\n\n/**\n * Persistent hypercore store.\n */\nexport class FeedStore<T extends {}> {\n private readonly _feeds: ComplexMap<PublicKey, FeedWrapper<T>> = new ComplexMap(PublicKey.hash);\n private readonly _mutexes = new ComplexMap<PublicKey, Mutex>(PublicKey.hash);\n private readonly _factory: FeedFactory<T>;\n\n private _closed = false;\n\n readonly feedOpened = new Event<FeedWrapper<T>>();\n\n constructor({ factory }: FeedStoreOptions<T>) {\n this._factory = factory ?? failUndefined();\n }\n\n get size() {\n return this._feeds.size;\n }\n\n get feeds() {\n return Array.from(this._feeds.values());\n }\n\n /**\n * Get the open feed if it exists.\n */\n getFeed(publicKey: PublicKey): FeedWrapper<T> | undefined {\n return this._feeds.get(publicKey);\n }\n\n /**\n * Gets or opens a feed.\n * The feed is readonly unless a secret key is provided.\n */\n async openFeed(feedKey: PublicKey, { writable, sparse }: FeedOptions = {}): Promise<FeedWrapper<T>> {\n log('opening feed', { feedKey });\n invariant(feedKey);\n invariant(!this._closed, 'Feed store is closed');\n\n const mutex = defaultMap(this._mutexes, feedKey, () => new Mutex());\n\n return mutex.executeSynchronized(async () => {\n let feed = this.getFeed(feedKey);\n if (feed) {\n // TODO(burdon): Need to check that there's another instance being used (create test and break this).\n // TODO(burdon): Remove from store if feed is closed externally? (remove wrapped open/close methods?)\n if (writable && !feed.properties.writable) {\n throw new Error(`Read-only feed is already open: ${feedKey.truncate()}`);\n } else if ((sparse ?? false) !== feed.properties.sparse) {\n throw new Error(\n `Feed already open with different sparse setting: ${feedKey.truncate()} [${sparse} !== ${\n feed.properties.sparse\n }]`,\n );\n } else {\n await feed.open();\n return feed;\n }\n }\n\n feed = await this._factory.createFeed(feedKey, { writable, sparse });\n this._feeds.set(feed.key, feed);\n\n await feed.open();\n this.feedOpened.emit(feed);\n log('opened', { feedKey });\n return feed;\n });\n }\n\n /**\n * Close all feeds.\n */\n async close(): Promise<void> {\n log('closing...');\n this._closed = true;\n await Promise.all(\n Array.from(this._feeds.values()).map(async (feed) => {\n await feed.close();\n invariant(feed.closed);\n // TODO(burdon): SpaceProxy still being initialized.\n // SpaceProxy.initialize => Database.createItem => ... => FeedWrapper.append\n // Uncaught Error: Closed [random-access-storage/index.js:181:38]\n // await sleep(100);\n }),\n );\n\n this._feeds.clear();\n log('closed');\n }\n}\n"],
5
- "mappings": ";;;AAIA,SAASA,eAAe;AACxB,SAASC,iBAAiB;AAC1B,SAASC,UAAUC,iBAAiB;AAEpC,SAASC,eAAe;AACxB,SAASC,YAAYC,qBAAqB;AAE1C,SAASC,gBAAgBC,iBAAiB;AAE1C,SAASC,WAAW;AAEpB,SAASC,eAAeC,mBAAmB;AAK3C,IAAA,eAAA;;EAIUC;EACSC;EAEjB;EACiBC,i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G,eAAA,GAAA,IAAA,GAAA,KAAA,CAAA;;;",
6
- "names": ["inspect", "promisify", "Readable", "Transform", "Trigger", "StackTrace", "inspectObject", "assertArgument", "invariant", "log", "arrayToBuffer", "rangeFromTo", "_hypercore", "_pendingWrites", "_writeLock", "hypercore", "_key", "_storageDirectory", "wake", "custom", "toJSON", "feedKey", "length", "opened", "properties", "closed", "key", "core", "createReadableStream", "transform", "self", "cb", "readStream", "createFeedWriter", "seq", "stackTrace", "reset", "receipt", "flushToDisk", "readable", "byteLength", "open", "args", "_close", "close", "feed", "count", "pendingWrites", "_closed", "start", "index", "options", "append", "undownload", "setDownloading", "replicate", "clear", "proof", "data", "putBuffer", "CHECK_MESSAGES", "checkBegin", "to", "checkEnd", "min", "messagesBefore", "valueEncoding", "x", "messagesAfter", "i", "after", "before", "equals", "Error", "_batch", "_cursor", "_reading", "objectMode", "live", "opts", "_open", "_read", "_nonBatchedRead", "err", "push", "_batchedRead", "wait", "item", "defaultsDeep", "subtleCrypto", "failUndefined", "createCrypto", "hypercore", "log", "__dxlog_file", "_signer", "_hypercoreOptions", "options", "hypercore", "log", "root", "signer", "storageRoot", "createFeed", "secretKey", "crypto", "createCrypto", "onwrite", "noiseKeyPair", "storageDir", "makeStorage", "native", "getOrCreateFile", "filename", "path", "type", "truncate", "core", "Event", "Mutex", "failUndefined", "invariant", "PublicKey", "log", "ComplexMap", "defaultMap", "__dxlog_file", "_mutexes", "_factory", "_closed", "feedOpened", "factory", "size", "feeds", "feedKey", "mutex", "executeSynchronized", "feed", "getFeed", "sparse", "properties", "Error", "emit", "from", "_feeds", "close", "closed"]
7
- }