@dxos/feed-store 0.8.3 → 0.8.4-main.1da679c
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-WS47OKDO.mjs → chunk-4RW534M7.mjs} +192 -116
- package/dist/lib/browser/chunk-4RW534M7.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +116 -64
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +78 -32
- package/dist/lib/browser/testing/index.mjs.map +3 -3
- package/dist/lib/node-esm/{chunk-AO5I2BX3.mjs → chunk-D4DVCY7Y.mjs} +192 -116
- package/dist/lib/node-esm/chunk-D4DVCY7Y.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +116 -64
- 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 +78 -32
- package/dist/lib/node-esm/testing/index.mjs.map +3 -3
- package/dist/types/src/feed-queue.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/index.d.ts +1 -1
- package/dist/types/src/index.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 +1 -1
- package/dist/types/src/testing/test-generator.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +20 -17
- package/src/feed-queue.test.ts +1 -1
- package/src/feed-queue.ts +5 -2
- package/src/feed-store.node.test.ts +3 -3
- package/src/feed-wrapper.test.ts +38 -4
- package/src/feed-wrapper.ts +75 -35
- package/src/index.ts +1 -1
- package/src/testing/test-builder.ts +4 -4
- package/src/testing/test-generator.ts +1 -2
- package/dist/lib/browser/chunk-WS47OKDO.mjs.map +0 -7
- package/dist/lib/node/chunk-YOYJCS5J.cjs +0 -523
- package/dist/lib/node/chunk-YOYJCS5J.cjs.map +0 -7
- package/dist/lib/node/index.cjs +0 -593
- package/dist/lib/node/index.cjs.map +0 -7
- package/dist/lib/node/meta.json +0 -1
- package/dist/lib/node/testing/index.cjs +0 -173
- package/dist/lib/node/testing/index.cjs.map +0 -7
- package/dist/lib/node-esm/chunk-AO5I2BX3.mjs.map +0 -7
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxos/feed-store",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.4-main.1da679c",
|
|
4
4
|
"description": "A consistent store for hypercore feeds.",
|
|
5
5
|
"homepage": "https://dxos.org",
|
|
6
6
|
"bugs": "https://github.com/dxos/dxos/issues",
|
|
@@ -10,11 +10,13 @@
|
|
|
10
10
|
"type": "module",
|
|
11
11
|
"exports": {
|
|
12
12
|
".": {
|
|
13
|
+
"source": "./src/index.ts",
|
|
13
14
|
"types": "./dist/types/src/index.d.ts",
|
|
14
15
|
"browser": "./dist/lib/browser/index.mjs",
|
|
15
16
|
"node": "./dist/lib/node-esm/index.mjs"
|
|
16
17
|
},
|
|
17
18
|
"./testing": {
|
|
19
|
+
"source": "./src/testing/index.ts",
|
|
18
20
|
"types": "./dist/types/src/testing/index.d.ts",
|
|
19
21
|
"browser": "./dist/lib/browser/testing/index.mjs",
|
|
20
22
|
"node": "./dist/lib/node-esm/testing/index.mjs"
|
|
@@ -38,27 +40,28 @@
|
|
|
38
40
|
"lodash.defaultsdeep": "^4.6.1",
|
|
39
41
|
"race-as-promised": "^0.0.2",
|
|
40
42
|
"streamx": "^2.12.5",
|
|
41
|
-
"@dxos/
|
|
42
|
-
"@dxos/
|
|
43
|
-
"@dxos/
|
|
44
|
-
"@dxos/crypto": "0.8.
|
|
45
|
-
"@dxos/
|
|
46
|
-
"@dxos/
|
|
47
|
-
"@dxos/
|
|
48
|
-
"@dxos/
|
|
49
|
-
"@dxos/keys": "0.8.
|
|
50
|
-
"@dxos/log": "0.8.
|
|
51
|
-
"@dxos/node-std": "0.8.
|
|
52
|
-
"@dxos/
|
|
53
|
-
"@dxos/
|
|
43
|
+
"@dxos/async": "0.8.4-main.1da679c",
|
|
44
|
+
"@dxos/context": "0.8.4-main.1da679c",
|
|
45
|
+
"@dxos/codec-protobuf": "0.8.4-main.1da679c",
|
|
46
|
+
"@dxos/crypto": "0.8.4-main.1da679c",
|
|
47
|
+
"@dxos/debug": "0.8.4-main.1da679c",
|
|
48
|
+
"@dxos/hypercore": "0.8.4-main.1da679c",
|
|
49
|
+
"@dxos/invariant": "0.8.4-main.1da679c",
|
|
50
|
+
"@dxos/keyring": "0.8.4-main.1da679c",
|
|
51
|
+
"@dxos/keys": "0.8.4-main.1da679c",
|
|
52
|
+
"@dxos/log": "0.8.4-main.1da679c",
|
|
53
|
+
"@dxos/node-std": "0.8.4-main.1da679c",
|
|
54
|
+
"@dxos/random-access-storage": "0.8.4-main.1da679c",
|
|
55
|
+
"@dxos/util": "0.8.4-main.1da679c",
|
|
56
|
+
"@dxos/vendor-hypercore": "0.8.4-main.1da679c"
|
|
54
57
|
},
|
|
55
58
|
"devDependencies": {
|
|
56
59
|
"@types/lodash.defaultsdeep": "^4.6.6",
|
|
57
|
-
"@dxos/keys": "0.8.
|
|
58
|
-
"@dxos/random": "0.8.
|
|
60
|
+
"@dxos/keys": "0.8.4-main.1da679c",
|
|
61
|
+
"@dxos/random": "0.8.4-main.1da679c"
|
|
59
62
|
},
|
|
60
63
|
"optionalDependencies": {
|
|
61
|
-
"@dxos/random": "0.8.
|
|
64
|
+
"@dxos/random": "0.8.4-main.1da679c"
|
|
62
65
|
},
|
|
63
66
|
"publishConfig": {
|
|
64
67
|
"access": "public"
|
package/src/feed-queue.test.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
import { describe, expect, test } from 'vitest';
|
|
6
6
|
|
|
7
|
-
import {
|
|
7
|
+
import { asyncTimeout, latch, sleep, untilError, untilPromise } from '@dxos/async';
|
|
8
8
|
import { log } from '@dxos/log';
|
|
9
9
|
import { range } from '@dxos/util';
|
|
10
10
|
|
package/src/feed-queue.ts
CHANGED
|
@@ -3,9 +3,10 @@
|
|
|
3
3
|
//
|
|
4
4
|
|
|
5
5
|
import { inspect } from 'node:util';
|
|
6
|
+
|
|
6
7
|
import { Writable } from 'streamx';
|
|
7
8
|
|
|
8
|
-
import { Event,
|
|
9
|
+
import { Event, Trigger, latch } from '@dxos/async';
|
|
9
10
|
import { inspectObject } from '@dxos/debug';
|
|
10
11
|
import type { ReadStreamOptions } from '@dxos/hypercore';
|
|
11
12
|
import { invariant } from '@dxos/invariant';
|
|
@@ -124,10 +125,12 @@ export class FeedQueue<T extends {}> {
|
|
|
124
125
|
};
|
|
125
126
|
|
|
126
127
|
const onError = (err?: Error) => {
|
|
128
|
+
if (!this.isOpen) {
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
127
131
|
if (!err) {
|
|
128
132
|
return;
|
|
129
133
|
}
|
|
130
|
-
|
|
131
134
|
if (err.message === 'Writable stream closed prematurely' || err.message === 'Feed is closed') {
|
|
132
135
|
return;
|
|
133
136
|
}
|
|
@@ -5,9 +5,9 @@
|
|
|
5
5
|
import { describe, expect, test } from 'vitest';
|
|
6
6
|
|
|
7
7
|
import { faker } from '@dxos/random';
|
|
8
|
-
import {
|
|
8
|
+
import { StorageType, createStorage } from '@dxos/random-access-storage';
|
|
9
9
|
|
|
10
|
-
import { TestItemBuilder } from './testing';
|
|
10
|
+
import { type TestItem, TestItemBuilder } from './testing';
|
|
11
11
|
|
|
12
12
|
describe('FeedStore', () => {
|
|
13
13
|
test('reopens a feed and reads data from storage', async () => {
|
|
@@ -28,7 +28,7 @@ describe('FeedStore', () => {
|
|
|
28
28
|
await feed.append({
|
|
29
29
|
id: String(i),
|
|
30
30
|
value: faker.lorem.sentence(),
|
|
31
|
-
});
|
|
31
|
+
} as TestItem);
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
expect(feed.properties.length).to.eq(numBlocks);
|
package/src/feed-wrapper.test.ts
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
//
|
|
4
4
|
|
|
5
5
|
import { inspect } from 'node:util';
|
|
6
|
+
|
|
6
7
|
import { describe, expect, test } from 'vitest';
|
|
7
8
|
|
|
8
9
|
import { asyncTimeout, latch, sleep } from '@dxos/async';
|
|
@@ -12,7 +13,7 @@ import { log } from '@dxos/log';
|
|
|
12
13
|
import { faker } from '@dxos/random';
|
|
13
14
|
import { range } from '@dxos/util';
|
|
14
15
|
|
|
15
|
-
import {
|
|
16
|
+
import { TestBuilder, TestItemBuilder, defaultValueEncoding } from './testing';
|
|
16
17
|
|
|
17
18
|
describe('FeedWrapper', () => {
|
|
18
19
|
const factory = new TestBuilder().createFeedFactory();
|
|
@@ -96,7 +97,7 @@ describe('FeedWrapper', () => {
|
|
|
96
97
|
await feed.append({
|
|
97
98
|
id: String(i + 1),
|
|
98
99
|
value: faker.lorem.sentence(),
|
|
99
|
-
});
|
|
100
|
+
} as any);
|
|
100
101
|
}
|
|
101
102
|
|
|
102
103
|
expect(feed.properties.length).to.eq(numBlocks);
|
|
@@ -233,7 +234,7 @@ describe('FeedWrapper', () => {
|
|
|
233
234
|
// Reader.
|
|
234
235
|
{
|
|
235
236
|
const start = 5;
|
|
236
|
-
feed2.download({ start, linear: true }, (err: Error) => {
|
|
237
|
+
feed2.download({ start, linear: true }, (err: Error | null) => {
|
|
237
238
|
if (err) {
|
|
238
239
|
throw err;
|
|
239
240
|
}
|
|
@@ -260,7 +261,7 @@ describe('FeedWrapper', () => {
|
|
|
260
261
|
await feed2.open();
|
|
261
262
|
|
|
262
263
|
for (const i of range(numBlocks)) {
|
|
263
|
-
await feed1.append(`block-${i}`);
|
|
264
|
+
await feed1.append(`block-${i}` as any);
|
|
264
265
|
}
|
|
265
266
|
|
|
266
267
|
for (const i of range(numBlocks)) {
|
|
@@ -283,4 +284,37 @@ describe('FeedWrapper', () => {
|
|
|
283
284
|
console.log('audit', { err, valid });
|
|
284
285
|
});
|
|
285
286
|
});
|
|
287
|
+
|
|
288
|
+
test('integrates blocks via putBuffer', async () => {
|
|
289
|
+
const numBlocks = 5;
|
|
290
|
+
const builder = new TestBuilder();
|
|
291
|
+
const feedFactory = builder.createFeedFactory();
|
|
292
|
+
|
|
293
|
+
const key = await builder.keyring.createKey();
|
|
294
|
+
const source = await feedFactory.createFeed(key, { writable: true });
|
|
295
|
+
const target = await feedFactory.createFeed(key);
|
|
296
|
+
|
|
297
|
+
await source.open();
|
|
298
|
+
await target.open();
|
|
299
|
+
|
|
300
|
+
// Append to source.
|
|
301
|
+
for (let i = 0; i < numBlocks; i++) {
|
|
302
|
+
await source.append(faker.lorem.sentence() as any);
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
// Integrate into target via putBuffer using proofs from source.
|
|
306
|
+
for (let i = 0; i < numBlocks; i++) {
|
|
307
|
+
const data = (await source.get(i, { valueEncoding: 'binary' })) as Uint8Array;
|
|
308
|
+
const proof = await source.proof(i);
|
|
309
|
+
await target.putBuffer(i, data, proof, null);
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
// Verify data and length.
|
|
313
|
+
expect(target.length).to.eq(numBlocks);
|
|
314
|
+
for (let i = 0; i < numBlocks; i++) {
|
|
315
|
+
const src = (await source.get(i, { valueEncoding: 'binary' })) as Uint8Array;
|
|
316
|
+
const dst = (await target.get(i, { valueEncoding: 'binary' })) as Uint8Array;
|
|
317
|
+
expect(Buffer.from(dst).equals(Buffer.from(src))).to.be.true;
|
|
318
|
+
}
|
|
319
|
+
});
|
|
286
320
|
});
|
package/src/feed-wrapper.ts
CHANGED
|
@@ -2,18 +2,20 @@
|
|
|
2
2
|
// Copyright 2022 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import type { Proof } from 'hypercore';
|
|
6
5
|
import { inspect } from 'node:util';
|
|
6
|
+
import { promisify } from 'node:util';
|
|
7
|
+
|
|
7
8
|
import { Readable, Transform } from 'streamx';
|
|
8
9
|
|
|
9
10
|
import { Trigger } from '@dxos/async';
|
|
10
|
-
import {
|
|
11
|
+
import { StackTrace, inspectObject } from '@dxos/debug';
|
|
11
12
|
import type { Hypercore, HypercoreProperties, ReadStreamOptions } from '@dxos/hypercore';
|
|
12
|
-
import { invariant } from '@dxos/invariant';
|
|
13
|
+
import { assertArgument, invariant } from '@dxos/invariant';
|
|
13
14
|
import { type PublicKey } from '@dxos/keys';
|
|
14
15
|
import { log } from '@dxos/log';
|
|
15
16
|
import { type Directory } from '@dxos/random-access-storage';
|
|
16
|
-
import { arrayToBuffer,
|
|
17
|
+
import { arrayToBuffer, rangeFromTo } from '@dxos/util';
|
|
18
|
+
import type { GetOptions, Proof } from '@dxos/vendor-hypercore/hypercore';
|
|
17
19
|
|
|
18
20
|
import { type FeedWriter, type WriteReceipt } from './feed-writer';
|
|
19
21
|
|
|
@@ -21,8 +23,8 @@ import { type FeedWriter, type WriteReceipt } from './feed-writer';
|
|
|
21
23
|
* Async feed wrapper.
|
|
22
24
|
*/
|
|
23
25
|
export class FeedWrapper<T extends {}> {
|
|
26
|
+
private _hypercore: Hypercore<T>;
|
|
24
27
|
private readonly _pendingWrites = new Set<StackTrace>();
|
|
25
|
-
private readonly _binder = createBinder(this._hypercore);
|
|
26
28
|
|
|
27
29
|
// Pending while writes are happening. Resolves when there are no pending writes.
|
|
28
30
|
private readonly _writeLock = new Trigger();
|
|
@@ -30,11 +32,12 @@ export class FeedWrapper<T extends {}> {
|
|
|
30
32
|
private _closed = false;
|
|
31
33
|
|
|
32
34
|
constructor(
|
|
33
|
-
|
|
35
|
+
hypercore: Hypercore<T>,
|
|
34
36
|
private _key: PublicKey, // TODO(burdon): Required since currently patching the key inside factory.
|
|
35
37
|
private _storageDirectory: Directory,
|
|
36
38
|
) {
|
|
37
|
-
|
|
39
|
+
assertArgument(hypercore, 'hypercore');
|
|
40
|
+
this._hypercore = hypercore;
|
|
38
41
|
invariant(this._key);
|
|
39
42
|
this._writeLock.wake();
|
|
40
43
|
}
|
|
@@ -143,31 +146,42 @@ export class FeedWrapper<T extends {}> {
|
|
|
143
146
|
await this._storageDirectory.flush();
|
|
144
147
|
}
|
|
145
148
|
|
|
146
|
-
get opened() {
|
|
149
|
+
get opened(): boolean {
|
|
147
150
|
return this._hypercore.opened;
|
|
148
151
|
}
|
|
149
152
|
|
|
150
|
-
get closed() {
|
|
153
|
+
get closed(): boolean {
|
|
151
154
|
return this._hypercore.closed;
|
|
152
155
|
}
|
|
153
156
|
|
|
154
|
-
get readable() {
|
|
157
|
+
get readable(): boolean {
|
|
155
158
|
return this._hypercore.readable;
|
|
156
159
|
}
|
|
157
160
|
|
|
158
|
-
get length() {
|
|
161
|
+
get length(): number {
|
|
159
162
|
return this._hypercore.length;
|
|
160
163
|
}
|
|
161
164
|
|
|
162
|
-
get byteLength() {
|
|
165
|
+
get byteLength(): number {
|
|
163
166
|
return this._hypercore.byteLength;
|
|
164
167
|
}
|
|
165
168
|
|
|
166
|
-
on
|
|
167
|
-
|
|
169
|
+
on(...args: any[]) {
|
|
170
|
+
return (this._hypercore as any).on(...args);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
off(...args: any[]) {
|
|
174
|
+
return (this._hypercore as any).off(...args);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
open(...args: Parameters<Hypercore<T>['open']>) {
|
|
178
|
+
return promisify(this._hypercore.open.bind(this._hypercore) as any)(...args);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
_close(...args: Parameters<Hypercore<T>['close']>) {
|
|
182
|
+
return promisify(this._hypercore.close.bind(this._hypercore) as any)(...args);
|
|
183
|
+
}
|
|
168
184
|
|
|
169
|
-
open = this._binder.async(this._hypercore.open);
|
|
170
|
-
private _close = this._binder.async(this._hypercore.close);
|
|
171
185
|
close = async () => {
|
|
172
186
|
if (this._pendingWrites.size) {
|
|
173
187
|
log.warn('Closing feed with pending writes', {
|
|
@@ -181,27 +195,53 @@ export class FeedWrapper<T extends {}> {
|
|
|
181
195
|
await this._close();
|
|
182
196
|
};
|
|
183
197
|
|
|
184
|
-
has
|
|
185
|
-
|
|
186
|
-
|
|
198
|
+
has(start: number, end?: number) {
|
|
199
|
+
return this._hypercore.has(start, end);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
get(index: number, options?: GetOptions) {
|
|
203
|
+
return promisify(this._hypercore.get.bind(this._hypercore) as any)(index, options);
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
// TODO(dmaretskyi): Type better
|
|
207
|
+
append(data: any | any[]): Promise<number> {
|
|
208
|
+
return promisify(this._hypercore.append.bind(this._hypercore))(data);
|
|
209
|
+
}
|
|
187
210
|
|
|
188
211
|
/**
|
|
189
212
|
* Will not resolve if `end` parameter is not specified and the feed is not closed.
|
|
190
213
|
*/
|
|
191
|
-
download
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
214
|
+
download(...args: Parameters<Hypercore<T>['download']>) {
|
|
215
|
+
return this._hypercore.download(...args);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
undownload(...args: Parameters<Hypercore<T>['undownload']>) {
|
|
219
|
+
return this._hypercore.undownload(...args);
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
setDownloading(...args: Parameters<Hypercore<T>['setDownloading']>) {
|
|
223
|
+
return this._hypercore.setDownloading(...args);
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
replicate(...args: Parameters<Hypercore<T>['replicate']>) {
|
|
227
|
+
return this._hypercore.replicate(...args);
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
clear(start: number, end?: number) {
|
|
231
|
+
return promisify(this._hypercore.clear.bind(this._hypercore))(start, end);
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
proof(index: number, options?: any) {
|
|
235
|
+
return promisify(this._hypercore.proof.bind(this._hypercore))(index);
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
put(index: number, data: T, proof: Proof) {
|
|
239
|
+
return promisify(this._hypercore.put.bind(this._hypercore))(index, data, proof);
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
putBuffer(index: number, data: Buffer | Uint8Array, proof: Proof, peer: null): Promise<void> {
|
|
243
|
+
return promisify((this._hypercore as any)._putBuffer.bind(this._hypercore) as any)(index, data, proof, peer);
|
|
244
|
+
}
|
|
205
245
|
|
|
206
246
|
/**
|
|
207
247
|
* Clear and check for integrity.
|
|
@@ -216,7 +256,7 @@ export class FeedWrapper<T extends {}> {
|
|
|
216
256
|
const messagesBefore = await Promise.all(
|
|
217
257
|
rangeFromTo(checkBegin, checkEnd).map((idx) =>
|
|
218
258
|
this.get(idx, {
|
|
219
|
-
valueEncoding: { decode: (x: Uint8Array) => x },
|
|
259
|
+
valueEncoding: { decode: (x: Uint8Array) => x } as any,
|
|
220
260
|
}),
|
|
221
261
|
),
|
|
222
262
|
);
|
|
@@ -226,7 +266,7 @@ export class FeedWrapper<T extends {}> {
|
|
|
226
266
|
const messagesAfter = await Promise.all(
|
|
227
267
|
rangeFromTo(checkBegin, checkEnd).map((idx) =>
|
|
228
268
|
this.get(idx, {
|
|
229
|
-
valueEncoding: { decode: (x: Uint8Array) => x },
|
|
269
|
+
valueEncoding: { decode: (x: Uint8Array) => x } as any,
|
|
230
270
|
}),
|
|
231
271
|
),
|
|
232
272
|
);
|
package/src/index.ts
CHANGED
|
@@ -2,15 +2,15 @@
|
|
|
2
2
|
// Copyright 2022 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import type { ValueEncoding } from 'hypercore';
|
|
6
|
-
|
|
7
5
|
import { Keyring } from '@dxos/keyring';
|
|
8
|
-
import {
|
|
6
|
+
import { type Directory, type Storage, StorageType, createStorage } from '@dxos/random-access-storage';
|
|
7
|
+
import type { ValueEncoding } from '@dxos/vendor-hypercore/hypercore';
|
|
9
8
|
|
|
10
|
-
import { defaultTestGenerator, defaultValueEncoding, type TestGenerator, type TestItem } from './test-generator';
|
|
11
9
|
import { FeedFactory } from '../feed-factory';
|
|
12
10
|
import { FeedStore } from '../feed-store';
|
|
13
11
|
|
|
12
|
+
import { type TestGenerator, type TestItem, defaultTestGenerator, defaultValueEncoding } from './test-generator';
|
|
13
|
+
|
|
14
14
|
export type TestBuilderOptions<T extends {}> = {
|
|
15
15
|
storage?: Storage;
|
|
16
16
|
root?: Directory;
|
|
@@ -2,12 +2,11 @@
|
|
|
2
2
|
// Copyright 2022 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import type { AbstractValueEncoding } from 'hypercore';
|
|
6
|
-
|
|
7
5
|
import { sleep } from '@dxos/async';
|
|
8
6
|
import { type Codec } from '@dxos/codec-protobuf';
|
|
9
7
|
import { createCodecEncoding } from '@dxos/hypercore';
|
|
10
8
|
import { faker } from '@dxos/random';
|
|
9
|
+
import type { AbstractValueEncoding } from '@dxos/vendor-hypercore/hypercore';
|
|
11
10
|
|
|
12
11
|
import { type FeedWriter } from '../feed-writer';
|
|
13
12
|
|
|
@@ -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](): 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() {\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): 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 },\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): 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": ";;;AAKA,SAASA,eAAe;AACxB,SAASC,UAAUC,iBAAiB;AAEpC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ACrB;QAEP,OAAO;AACL,gBAAMG,KAAKI,KAAI;AACf,iBAAOJ;QACT;MACF;AAEAA,aAAO,MAAM,KAAKf,SAASoB,WAAWV,SAAS;QAAEC;QAAUC;MAAO,CAAA;AAClE,WAAKjB,OAAO0B,IAAIN,KAAKO,KAAKP,IAAAA;AAE1B,YAAMA,KAAKI,KAAI;AACf,WAAKpB,WAAWwB,KAAKR,IAAAA;AACrBzB,MAAAA,KAAI,UAAU;QAAEoB;MAAQ,GAAA;;;;;;AACxB,aAAOK;IACT,CAAA;EACF;;;;EAKA,MAAMS,QAAuB;AAC3BlC,IAAAA,KAAI,cAAA,QAAA;;;;;;AACJ,SAAKQ,UAAU;AACf,UAAM2B,QAAQC,IACZvB,MAAMC,KAAK,KAAKT,OAAOU,OAAM,CAAA,EAAIsB,IAAI,OAAOZ,SAAAA;AAC1C,YAAMA,KAAKS,MAAK;AAChBpC,MAAAA,WAAU2B,KAAKa,QAAM,QAAA;;;;;;;;;IAKvB,CAAA,CAAA;AAGF,SAAKjC,OAAOkC,MAAK;AACjBvC,IAAAA,KAAI,UAAA,QAAA;;;;;;EACN;AACF;",
|
|
6
|
-
"names": ["inspect", "Readable", "Transform", "Trigger", "inspectObject", "StackTrace", "invariant", "log", "arrayToBuffer", "createBinder", "rangeFromTo", "FeedWrapper", "_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", "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", "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
|
-
}
|