@dxos/feed-store 0.6.12-main.ed7cda7 → 0.6.12-staging.0b4bb48
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-QYBKGLQJ.mjs → chunk-QEVMM5RF.mjs} +3 -2
- package/dist/lib/browser/chunk-QEVMM5RF.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +1 -1
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +1 -1
- package/dist/lib/node/{chunk-PXGR6322.cjs → chunk-CEOKPJ6P.cjs} +6 -5
- package/dist/lib/node/chunk-CEOKPJ6P.cjs.map +7 -0
- package/dist/lib/node/index.cjs +4 -4
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/testing/index.cjs +3 -3
- package/package.json +19 -21
- package/src/feed-factory.test.ts +1 -1
- package/src/feed-iterator.test.ts +3 -2
- package/src/feed-queue.test.ts +92 -50
- package/src/feed-set-iterator.test.ts +4 -3
- package/src/feed-store.test.ts +51 -2
- package/src/feed-wrapper.test.ts +7 -3
- package/src/feed-wrapper.ts +1 -1
- package/dist/lib/browser/chunk-QYBKGLQJ.mjs.map +0 -7
- package/dist/lib/node/chunk-PXGR6322.cjs.map +0 -7
- package/dist/lib/node-esm/chunk-QELQFW6D.mjs +0 -495
- package/dist/lib/node-esm/chunk-QELQFW6D.mjs.map +0 -7
- package/dist/lib/node-esm/index.mjs +0 -567
- package/dist/lib/node-esm/index.mjs.map +0 -7
- package/dist/lib/node-esm/meta.json +0 -1
- package/dist/lib/node-esm/testing/index.mjs +0 -154
- package/dist/lib/node-esm/testing/index.mjs.map +0 -7
- package/dist/types/src/feed-queue.browser.test.d.ts +0 -2
- package/dist/types/src/feed-queue.browser.test.d.ts.map +0 -1
- package/dist/types/src/feed-store.node.test.d.ts +0 -2
- package/dist/types/src/feed-store.node.test.d.ts.map +0 -1
- package/src/feed-queue.browser.test.ts +0 -54
- package/src/feed-store.node.test.ts +0 -56
package/src/feed-queue.test.ts
CHANGED
|
@@ -2,10 +2,12 @@
|
|
|
2
2
|
// Copyright 2022 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import {
|
|
5
|
+
import { expect } from 'chai';
|
|
6
6
|
|
|
7
7
|
import { latch, asyncTimeout, sleep, untilError, untilPromise } from '@dxos/async';
|
|
8
8
|
import { log } from '@dxos/log';
|
|
9
|
+
import { StorageType, createStorage } from '@dxos/random-access-storage';
|
|
10
|
+
import { describe, test } from '@dxos/test';
|
|
9
11
|
import { range } from '@dxos/util';
|
|
10
12
|
|
|
11
13
|
import { FeedQueue } from './feed-queue';
|
|
@@ -67,6 +69,44 @@ describe('FeedQueue', () => {
|
|
|
67
69
|
expect(queue.feed.properties.closed).to.be.false;
|
|
68
70
|
});
|
|
69
71
|
|
|
72
|
+
test('works with webfs', async () => {
|
|
73
|
+
const localBuilder = builder.clone().setStorage(createStorage({ type: StorageType.WEBFS }));
|
|
74
|
+
const feedStore = localBuilder.createFeedStore();
|
|
75
|
+
const key = await localBuilder.keyring.createKey();
|
|
76
|
+
const feed = await feedStore.openFeed(key, { writable: true });
|
|
77
|
+
|
|
78
|
+
const queue = new FeedQueue<any>(feed);
|
|
79
|
+
await queue.open();
|
|
80
|
+
|
|
81
|
+
expect(queue.isOpen).to.be.true;
|
|
82
|
+
expect(queue.feed.properties.closed).to.be.false;
|
|
83
|
+
|
|
84
|
+
// Write blocks.
|
|
85
|
+
// TODO(burdon): Write slowly to test writing close feed.
|
|
86
|
+
await localBuilder._properties.generator!.writeBlocks(feed.createFeedWriter(), { count: 10 });
|
|
87
|
+
|
|
88
|
+
// Read until queue closed (pop throws exception).
|
|
89
|
+
const errorPromise = untilError(async () => {
|
|
90
|
+
while (true) {
|
|
91
|
+
const next = await queue.pop();
|
|
92
|
+
log('next', { next: next.seq });
|
|
93
|
+
await sleep(50);
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
// Close the queue.
|
|
98
|
+
await untilPromise(async () => {
|
|
99
|
+
await sleep(400);
|
|
100
|
+
await queue.close();
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
// Expect pop to throw error when queue is closed.
|
|
104
|
+
await errorPromise;
|
|
105
|
+
|
|
106
|
+
expect(queue.isOpen).to.be.false;
|
|
107
|
+
expect(queue.feed.properties.closed).to.be.false;
|
|
108
|
+
}).onlyEnvironments('chromium');
|
|
109
|
+
|
|
70
110
|
test('feed closed while reading', async () => {
|
|
71
111
|
const feedStore = builder.createFeedStore();
|
|
72
112
|
const key = await builder.keyring.createKey();
|
|
@@ -105,56 +145,58 @@ describe('FeedQueue', () => {
|
|
|
105
145
|
});
|
|
106
146
|
|
|
107
147
|
// TODO(dmaretskyi): Fix.
|
|
108
|
-
test
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
received();
|
|
130
|
-
|
|
131
|
-
// Check called immediately (i.e., after first block is written).
|
|
132
|
-
expect(queue.length).to.eq(1);
|
|
133
|
-
expect(feed.properties.length).to.eq(1);
|
|
134
|
-
|
|
135
|
-
for await (const _ of Array.from(Array(numBlocks - 1))) {
|
|
136
|
-
const next = await queue.pop();
|
|
148
|
+
test
|
|
149
|
+
.skip('responds immediately when feed is appended', async () => {
|
|
150
|
+
const key = await builder.keyring.createKey();
|
|
151
|
+
const feed = await factory.createFeed(key, { writable: true });
|
|
152
|
+
await feed.open();
|
|
153
|
+
|
|
154
|
+
const queue = new FeedQueue<any>(feed);
|
|
155
|
+
await queue.open();
|
|
156
|
+
expect(queue.isOpen).to.be.true;
|
|
157
|
+
|
|
158
|
+
const numBlocks = 10;
|
|
159
|
+
const [done, received] = latch({ count: numBlocks });
|
|
160
|
+
|
|
161
|
+
{
|
|
162
|
+
// Read blocks.
|
|
163
|
+
setTimeout(async () => {
|
|
164
|
+
expect(queue.peek()).to.be.undefined;
|
|
165
|
+
expect(queue.length).to.eq(0);
|
|
166
|
+
expect(feed.properties.length).to.eq(0);
|
|
167
|
+
|
|
168
|
+
const next = await asyncTimeout(queue.pop(), 500);
|
|
137
169
|
expect(next).not.to.be.undefined;
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
170
|
+
received();
|
|
171
|
+
|
|
172
|
+
// Check called immediately (i.e., after first block is written).
|
|
173
|
+
expect(queue.length).to.eq(1);
|
|
174
|
+
expect(feed.properties.length).to.eq(1);
|
|
175
|
+
|
|
176
|
+
for await (const _ of Array.from(Array(numBlocks - 1))) {
|
|
177
|
+
const next = await queue.pop();
|
|
178
|
+
expect(next).not.to.be.undefined;
|
|
179
|
+
const i = received();
|
|
180
|
+
expect(i).to.eq(queue.index);
|
|
181
|
+
}
|
|
147
182
|
});
|
|
148
|
-
expect(feed.properties.length).to.eq(numBlocks);
|
|
149
|
-
expect(queue.length).to.eq(numBlocks);
|
|
150
|
-
}, 100); // Make sure reader waits.
|
|
151
|
-
}
|
|
152
183
|
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
184
|
+
// Write blocks.
|
|
185
|
+
setTimeout(async () => {
|
|
186
|
+
await builder.generator.writeBlocks(feed.createFeedWriter(), {
|
|
187
|
+
count: numBlocks,
|
|
188
|
+
});
|
|
189
|
+
expect(feed.properties.length).to.eq(numBlocks);
|
|
190
|
+
expect(queue.length).to.eq(numBlocks);
|
|
191
|
+
}, 100); // Make sure reader waits.
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
await done();
|
|
195
|
+
expect(queue.isOpen).to.be.true;
|
|
196
|
+
await queue.close();
|
|
197
|
+
expect(queue.isOpen).to.be.false;
|
|
198
|
+
})
|
|
199
|
+
.timeout(1000);
|
|
158
200
|
|
|
159
201
|
test('peeks ahead', async () => {
|
|
160
202
|
const key = await builder.keyring.createKey();
|
|
@@ -198,7 +240,7 @@ describe('FeedQueue', () => {
|
|
|
198
240
|
await queue.close();
|
|
199
241
|
});
|
|
200
242
|
|
|
201
|
-
test('set a start sequence',
|
|
243
|
+
test('set a start sequence', async () => {
|
|
202
244
|
const numBlocks = 10;
|
|
203
245
|
const start = 2;
|
|
204
246
|
|
|
@@ -231,5 +273,5 @@ describe('FeedQueue', () => {
|
|
|
231
273
|
expect(queue.isOpen).to.be.true;
|
|
232
274
|
await queue.close();
|
|
233
275
|
expect(queue.isOpen).to.be.false;
|
|
234
|
-
});
|
|
276
|
+
}).timeout(1000);
|
|
235
277
|
});
|
|
@@ -2,11 +2,12 @@
|
|
|
2
2
|
// Copyright 2020 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import {
|
|
5
|
+
import { expect } from 'chai';
|
|
6
6
|
|
|
7
7
|
import { latch } from '@dxos/async';
|
|
8
8
|
import { log } from '@dxos/log';
|
|
9
9
|
import { faker } from '@dxos/random';
|
|
10
|
+
import { describe, test } from '@dxos/test';
|
|
10
11
|
|
|
11
12
|
import { type FeedBlockSelector, FeedSetIterator } from './feed-set-iterator';
|
|
12
13
|
import { TestItemBuilder } from './testing';
|
|
@@ -91,7 +92,7 @@ describe('FeedSetIterator', () => {
|
|
|
91
92
|
await iterator.close();
|
|
92
93
|
});
|
|
93
94
|
|
|
94
|
-
test('reads blocks in order',
|
|
95
|
+
test('reads blocks in order', async () => {
|
|
95
96
|
const builder = new TestItemBuilder();
|
|
96
97
|
const feedStore = builder.createFeedStore();
|
|
97
98
|
|
|
@@ -167,7 +168,7 @@ describe('FeedSetIterator', () => {
|
|
|
167
168
|
expect(iterator.isRunning).to.be.false;
|
|
168
169
|
await iterator.close();
|
|
169
170
|
await feedStore.close();
|
|
170
|
-
});
|
|
171
|
+
}).timeout(3_000);
|
|
171
172
|
|
|
172
173
|
test('start from non-zero index', async () => {
|
|
173
174
|
const builder = new TestItemBuilder();
|
package/src/feed-store.test.ts
CHANGED
|
@@ -2,12 +2,18 @@
|
|
|
2
2
|
// Copyright 2022 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import {
|
|
5
|
+
import chai, { expect } from 'chai';
|
|
6
|
+
import chaiAsPromised from 'chai-as-promised';
|
|
6
7
|
|
|
7
8
|
import { PublicKey } from '@dxos/keys';
|
|
9
|
+
import { faker } from '@dxos/random';
|
|
10
|
+
import { createStorage, StorageType } from '@dxos/random-access-storage';
|
|
11
|
+
import { describe, test } from '@dxos/test';
|
|
8
12
|
|
|
9
13
|
import { TestItemBuilder } from './testing';
|
|
10
14
|
|
|
15
|
+
chai.use(chaiAsPromised);
|
|
16
|
+
|
|
11
17
|
describe('FeedStore', () => {
|
|
12
18
|
test('creates feeds', async () => {
|
|
13
19
|
const builder = new TestItemBuilder();
|
|
@@ -74,7 +80,50 @@ describe('FeedStore', () => {
|
|
|
74
80
|
|
|
75
81
|
// Attempt to reopen as writable (fail).
|
|
76
82
|
{
|
|
77
|
-
await expect(feedStore.openFeed(feedKey, { writable: true })).
|
|
83
|
+
await expect(feedStore.openFeed(feedKey, { writable: true })).to.be.rejected;
|
|
78
84
|
}
|
|
79
85
|
});
|
|
86
|
+
|
|
87
|
+
test('reopens a feed and reads data from storage', async () => {
|
|
88
|
+
const builder = new TestItemBuilder();
|
|
89
|
+
const feedKey = await builder.keyring!.createKey();
|
|
90
|
+
|
|
91
|
+
const numBlocks = 10;
|
|
92
|
+
|
|
93
|
+
const storage = createStorage({ type: StorageType.NODE });
|
|
94
|
+
|
|
95
|
+
// Write.
|
|
96
|
+
{
|
|
97
|
+
const feedStore = builder.clone().setStorage(storage).createFeedStore();
|
|
98
|
+
const feed = await feedStore.openFeed(feedKey, { writable: true });
|
|
99
|
+
|
|
100
|
+
for (const i of Array.from(Array(numBlocks)).keys()) {
|
|
101
|
+
await feed.append({
|
|
102
|
+
id: String(i),
|
|
103
|
+
value: faker.lorem.sentence(),
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
expect(feed.properties.length).to.eq(numBlocks);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// Read.
|
|
111
|
+
{
|
|
112
|
+
const feedStore = builder.clone().setStorage(storage).createFeedStore();
|
|
113
|
+
const feed = await feedStore.openFeed(feedKey);
|
|
114
|
+
expect(feed.properties.length).to.eq(numBlocks);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// Delete.
|
|
118
|
+
{
|
|
119
|
+
await storage.reset();
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// Read (should be empty).
|
|
123
|
+
{
|
|
124
|
+
const feedStore = builder.clone().setStorage(storage).createFeedStore();
|
|
125
|
+
const feed = await feedStore.openFeed(feedKey);
|
|
126
|
+
expect(feed.properties.length).to.eq(0);
|
|
127
|
+
}
|
|
128
|
+
}).onlyEnvironments('nodejs'); // NOTE: Must use Node so that data is persistent across invocations.
|
|
80
129
|
});
|
package/src/feed-wrapper.test.ts
CHANGED
|
@@ -2,14 +2,16 @@
|
|
|
2
2
|
// Copyright 2022 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
5
|
+
import { expect } from 'chai';
|
|
6
|
+
import { inspect } from 'util';
|
|
7
|
+
import waitForExpect from 'wait-for-expect';
|
|
7
8
|
|
|
8
9
|
import { asyncTimeout, latch, sleep } from '@dxos/async';
|
|
9
10
|
import { createReadable } from '@dxos/hypercore';
|
|
10
11
|
import { PublicKey } from '@dxos/keys';
|
|
11
12
|
import { log } from '@dxos/log';
|
|
12
13
|
import { faker } from '@dxos/random';
|
|
14
|
+
import { describe, test } from '@dxos/test';
|
|
13
15
|
import { range } from '@dxos/util';
|
|
14
16
|
|
|
15
17
|
import { defaultValueEncoding, TestBuilder, TestItemBuilder } from './testing';
|
|
@@ -238,7 +240,9 @@ describe('FeedWrapper', () => {
|
|
|
238
240
|
throw err;
|
|
239
241
|
}
|
|
240
242
|
});
|
|
241
|
-
await
|
|
243
|
+
await waitForExpect(async () => {
|
|
244
|
+
expect(feed2.has(start)).to.be.true;
|
|
245
|
+
}, 500);
|
|
242
246
|
for (const i of range(numBlocks)) {
|
|
243
247
|
expect(feed2.has(i)).to.eq(i >= start);
|
|
244
248
|
}
|
package/src/feed-wrapper.ts
CHANGED
|
@@ -94,7 +94,7 @@ export class FeedWrapper<T extends {}> {
|
|
|
94
94
|
createFeedWriter(): FeedWriter<T> {
|
|
95
95
|
return {
|
|
96
96
|
write: async (data: T, { afterWrite } = {}) => {
|
|
97
|
-
log('write', { feed: this._key, seq: this._hypercore.length });
|
|
97
|
+
log('write', { feed: this._key, seq: this._hypercore.length, data });
|
|
98
98
|
invariant(!this._closed, 'Feed closed');
|
|
99
99
|
const stackTrace = new StackTrace();
|
|
100
100
|
|
|
@@ -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 type { Proof } from 'hypercore';\nimport { inspect } from 'node:util';\nimport { Readable, Transform } from 'streamx';\n\nimport { Trigger } from '@dxos/async';\nimport { inspectObject, StackTrace } from '@dxos/debug';\nimport type { Hypercore, HypercoreProperties, ReadStreamOptions } from '@dxos/hypercore';\nimport { 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, createBinder, rangeFromTo } from '@dxos/util';\n\nimport { type FeedWriter, type WriteReceipt } from './feed-writer';\n\n/**\n * Async feed wrapper.\n */\nexport class FeedWrapper<T extends {}> {\n private readonly _pendingWrites = new Set<StackTrace>();\n private readonly _binder = createBinder(this._hypercore);\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 private _hypercore: Hypercore<T>,\n private _key: PublicKey, // TODO(burdon): Required since currently patching the key inside factory.\n private _storageDirectory: Directory,\n ) {\n invariant(this._hypercore);\n invariant(this._key);\n this._writeLock.wake();\n }\n\n [inspect.custom]() {\n return inspectObject(this);\n }\n\n toJSON() {\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() {\n await this._storageDirectory.flush();\n }\n\n get opened() {\n return this._hypercore.opened;\n }\n\n get closed() {\n return this._hypercore.closed;\n }\n\n get readable() {\n return this._hypercore.readable;\n }\n\n get length() {\n return this._hypercore.length;\n }\n\n get byteLength() {\n return this._hypercore.byteLength;\n }\n\n on = this._binder.fn(this._hypercore.on);\n off = this._binder.fn(this._hypercore.off);\n\n open = this._binder.async(this._hypercore.open);\n private _close = this._binder.async(this._hypercore.close);\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 = this._binder.fn(this._hypercore.has) as (start: number, end?: number) => boolean;\n get = this._binder.async(this._hypercore.get);\n append = this._binder.async(this._hypercore.append);\n\n /**\n * Will not resolve if `end` parameter is not specified and the feed is not closed.\n */\n download = this._binder.fn(this._hypercore.download);\n undownload = this._binder.fn(this._hypercore.undownload);\n setDownloading = this._binder.fn(this._hypercore.setDownloading);\n replicate: Hypercore<T>['replicate'] = this._binder.fn(this._hypercore.replicate);\n clear = this._binder.async(this._hypercore.clear) as (start: number, end?: number) => Promise<void>;\n\n proof = this._binder.async(this._hypercore.proof) as (index: number) => Promise<Proof>;\n put = this._binder.async(this._hypercore.put) as (index: number, data: T, proof: Proof) => Promise<void>;\n putBuffer = this._binder.async((this._hypercore as any)._putBuffer) as (\n index: number,\n data: Buffer,\n proof: Proof,\n from: null,\n ) => Promise<void>;\n\n /**\n * Clear and check for integrity.\n */\n async safeClear(from: number, to: number) {\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 },\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 },\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) {\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) {\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() {\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": ";;;;;;;;;;AAKA,SAASA,eAAe;AACxB,SAASC,UAAUC,iBAAiB;AAEpC,SAASC,eAAe;AACxB,SAASC,eAAeC,kBAAkB;AAE1C,SAASC,iBAAiB;AAE1B,SAASC,WAAW;AAEpB,SAASC,eAAeC,cAAcC,mBAAmB;;AAOlD,IAAMC,cAAN,MAAMA;EASXC,YACUC,YACAC,MACAC,mBACR;SAHQF,aAAAA;SACAC,O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1B,YAAMA,KAAKI,KAAI;AACf,WAAKpB,WAAWwB,KAAKR,IAAAA;AACrB1B,MAAAA,KAAI,UAAU;QAAEqB;MAAQ,GAAA;;;;;;AACxB,aAAOK;IACT,CAAA;EACF;;;;EAKA,MAAMS,QAAQ;AACZnC,IAAAA,KAAI,cAAA,QAAA;;;;;;AACJ,SAAKS,UAAU;AACf,UAAM2B,QAAQC,IACZvB,MAAMC,KAAK,KAAKT,OAAOU,OAAM,CAAA,EAAIsB,IAAI,OAAOZ,SAAAA;AAC1C,YAAMA,KAAKS,MAAK;AAChBrC,MAAAA,WAAU4B,KAAKa,QAAM,QAAA;;;;;;;;;IAKvB,CAAA,CAAA;AAGF,SAAKjC,OAAOkC,MAAK;AACjBxC,IAAAA,KAAI,UAAA,QAAA;;;;;;EACN;AACF;",
|
|
6
|
-
"names": ["inspect", "Readable", "Transform", "Trigger", "inspectObject", "StackTrace", "invariant", "log", "arrayToBuffer", "createBinder", "rangeFromTo", "FeedWrapper", "constructor", "_hypercore", "_key", "_storageDirectory", "_pendingWrites", "Set", "_binder", "_writeLock", "_closed", "on", "fn", "off", "open", "async", "_close", "close", "size", "warn", "feed", "count", "pendingWrites", "Array", "from", "values", "map", "stack", "getStack", "flushToDisk", "has", "get", "append", "download", "undownload", "setDownloading", "replicate", "clear", "proof", "put", "putBuffer", "_putBuffer", "wake", "custom", "toJSON", "feedKey", "length", "properties", "opened", "closed", "key", "core", "createReadableStream", "opts", "self", "transform", "data", "cb", "wait", "then", "push", "readStream", "batch", "undefined", "BatchedReadStream", "createReadStream", "pipe", "err", "createFeedWriter", "write", "afterWrite", "seq", "stackTrace", "add", "reset", "receipt", "appendWithReceipt", "delete", "flush", "readable", "byteLength", "safeClear", "to", "CHECK_MESSAGES", "checkBegin", "checkEnd", "Math", "min", "messagesBefore", "Promise", "all", "idx", "valueEncoding", "decode", "x", "messagesAfter", "i", "before", "after", "equals", "Error", "objectMode", "_reading", "live", "_feed", "_batch", "_cursor", "start", "_open", "ready", "_read", "bitfield", "total", "_batchedRead", "_nonBatchedRead", "getBatch", "item", "defaultsDeep", "subtleCrypto", "failUndefined", "createCrypto", "hypercore", "log", "FeedFactory", "constructor", "root", "signer", "hypercore", "log", "options", "_root", "failUndefined", "_signer", "_hypercoreOptions", "storageRoot", "createFeed", "publicKey", "writable", "Error", "secretKey", "warn", "key", "subtleCrypto", "digest", "Buffer", "from", "toHex", "opts", "defaultsDeep", "undefined", "crypto", "createCrypto", "onwrite", "noiseKeyPair", "storageDir", "createDirectory", "makeStorage", "filename", "type", "native", "getOrCreateFile", "path", "truncate", "core", "FeedWrapper", "Event", "Mutex", "failUndefined", "invariant", "PublicKey", "log", "ComplexMap", "defaultMap", "FeedStore", "constructor", "factory", "_feeds", "hash", "_mutexes", "_closed", "feedOpened", "_factory", "size", "feeds", "Array", "from", "values", "getFeed", "publicKey", "get", "openFeed", "feedKey", "writable", "sparse", "mutex", "executeSynchronized", "feed", "properties", "Error", "truncate", "open", "createFeed", "set", "key", "emit", "close", "Promise", "all", "map", "closed", "clear"]
|
|
7
|
-
}
|
|
@@ -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 type { Proof } from 'hypercore';\nimport { inspect } from 'node:util';\nimport { Readable, Transform } from 'streamx';\n\nimport { Trigger } from '@dxos/async';\nimport { inspectObject, StackTrace } from '@dxos/debug';\nimport type { Hypercore, HypercoreProperties, ReadStreamOptions } from '@dxos/hypercore';\nimport { 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, createBinder, rangeFromTo } from '@dxos/util';\n\nimport { type FeedWriter, type WriteReceipt } from './feed-writer';\n\n/**\n * Async feed wrapper.\n */\nexport class FeedWrapper<T extends {}> {\n private readonly _pendingWrites = new Set<StackTrace>();\n private readonly _binder = createBinder(this._hypercore);\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 private _hypercore: Hypercore<T>,\n private _key: PublicKey, // TODO(burdon): Required since currently patching the key inside factory.\n private _storageDirectory: Directory,\n ) {\n invariant(this._hypercore);\n invariant(this._key);\n this._writeLock.wake();\n }\n\n [inspect.custom]() {\n return inspectObject(this);\n }\n\n toJSON() {\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() {\n await this._storageDirectory.flush();\n }\n\n get opened() {\n return this._hypercore.opened;\n }\n\n get closed() {\n return this._hypercore.closed;\n }\n\n get readable() {\n return this._hypercore.readable;\n }\n\n get length() {\n return this._hypercore.length;\n }\n\n get byteLength() {\n return this._hypercore.byteLength;\n }\n\n on = this._binder.fn(this._hypercore.on);\n off = this._binder.fn(this._hypercore.off);\n\n open = this._binder.async(this._hypercore.open);\n private _close = this._binder.async(this._hypercore.close);\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 = this._binder.fn(this._hypercore.has) as (start: number, end?: number) => boolean;\n get = this._binder.async(this._hypercore.get);\n append = this._binder.async(this._hypercore.append);\n\n /**\n * Will not resolve if `end` parameter is not specified and the feed is not closed.\n */\n download = this._binder.fn(this._hypercore.download);\n undownload = this._binder.fn(this._hypercore.undownload);\n setDownloading = this._binder.fn(this._hypercore.setDownloading);\n replicate: Hypercore<T>['replicate'] = this._binder.fn(this._hypercore.replicate);\n clear = this._binder.async(this._hypercore.clear) as (start: number, end?: number) => Promise<void>;\n\n proof = this._binder.async(this._hypercore.proof) as (index: number) => Promise<Proof>;\n put = this._binder.async(this._hypercore.put) as (index: number, data: T, proof: Proof) => Promise<void>;\n putBuffer = this._binder.async((this._hypercore as any)._putBuffer) as (\n index: number,\n data: Buffer,\n proof: Proof,\n from: null,\n ) => Promise<void>;\n\n /**\n * Clear and check for integrity.\n */\n async safeClear(from: number, to: number) {\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 },\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 },\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) {\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) {\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() {\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": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAKA,uBAAwB;AACxB,qBAAoC;AAEpC,mBAAwB;AACxB,mBAA0C;AAE1C,uBAA0B;AAE1B,iBAAoB;AAEpB,kBAAyD;ACXzD,oBAAyB;AAEzB,oBAA0C;AAC1C,IAAAA,gBAA8B;AAE9B,uBAAwC;AAExC,IAAAC,cAAoB;ACPpB,IAA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OgB,IAAI3J,KAAKiC,KAAKjC,IAAAA;AAE1B,YAAMA,KAAKP,KAAI;AACf,WAAKuJ,WAAWY,KAAK5J,IAAAA;AACrBF,sBAAAA,KAAI,UAAU;QAAE8B;MAAQ,GAAA;;;;;;AACxB,aAAO5B;IACT,CAAA;EACF;;;;EAKA,MAAMJ,QAAQ;AACZE,oBAAAA,KAAI,cAAA,QAAA;;;;;;AACJ,SAAKT,UAAU;AACf,UAAMqF,QAAQC,IACZxE,MAAMC,KAAK,KAAKuI,OAAOtI,OAAM,CAAA,EAAIC,IAAI,OAAON,SAAAA;AAC1C,YAAMA,KAAKJ,MAAK;AAChB0B,4BAAAA,WAAUtB,KAAKgC,QAAM,QAAA;;;;;;;;;IAKvB,CAAA,CAAA;AAGF,SAAK2G,OAAO1H,MAAK;AACjBnB,oBAAAA,KAAI,UAAA,QAAA;;;;;;EACN;AACF;",
|
|
6
|
-
"names": ["import_debug", "import_log", "import_async", "import_invariant", "import_util", "FeedWrapper", "constructor", "_hypercore", "_key", "_storageDirectory", "_pendingWrites", "Set", "_binder", "createBinder", "_writeLock", "Trigger", "_closed", "on", "fn", "off", "open", "async", "_close", "close", "size", "log", "warn", "feed", "count", "pendingWrites", "Array", "from", "values", "map", "stack", "getStack", "flushToDisk", "has", "get", "append", "download", "undownload", "setDownloading", "replicate", "clear", "proof", "put", "putBuffer", "_putBuffer", "invariant", "wake", "inspect", "custom", "inspectObject", "toJSON", "feedKey", "length", "properties", "opened", "closed", "key", "core", "createReadableStream", "opts", "self", "transform", "Transform", "data", "cb", "wait", "then", "push", "readStream", "batch", "undefined", "BatchedReadStream", "createReadStream", "pipe", "err", "createFeedWriter", "write", "afterWrite", "seq", "stackTrace", "StackTrace", "add", "reset", "receipt", "appendWithReceipt", "delete", "flush", "readable", "byteLength", "safeClear", "to", "CHECK_MESSAGES", "checkBegin", "checkEnd", "Math", "min", "messagesBefore", "Promise", "all", "rangeFromTo", "idx", "valueEncoding", "decode", "x", "messagesAfter", "i", "before", "arrayToBuffer", "after", "equals", "Error", "Readable", "objectMode", "_reading", "live", "_feed", "_batch", "_cursor", "start", "_open", "ready", "_read", "bitfield", "total", "_batchedRead", "_nonBatchedRead", "getBatch", "item", "FeedFactory", "root", "signer", "hypercore", "options", "_root", "failUndefined", "_signer", "_hypercoreOptions", "storageRoot", "createFeed", "publicKey", "writable", "secretKey", "subtleCrypto", "digest", "Buffer", "toHex", "defaultsDeep", "crypto", "createCrypto", "onwrite", "noiseKeyPair", "storageDir", "createDirectory", "makeStorage", "filename", "type", "native", "getOrCreateFile", "path", "truncate", "FeedStore", "factory", "_feeds", "ComplexMap", "PublicKey", "hash", "_mutexes", "feedOpened", "Event", "_factory", "feeds", "getFeed", "openFeed", "sparse", "mutex", "defaultMap", "Mutex", "executeSynchronized", "set", "emit"]
|
|
7
|
-
}
|