@dxos/feed-store 0.8.3 → 0.8.4-main.03d5cd7b56
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-MB63GMGR.mjs} +112 -197
- package/dist/lib/browser/chunk-MB63GMGR.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +62 -202
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +19 -21
- package/dist/lib/browser/testing/index.mjs.map +3 -3
- package/dist/lib/node-esm/{chunk-AO5I2BX3.mjs → chunk-VZUET36D.mjs} +112 -197
- package/dist/lib/node-esm/chunk-VZUET36D.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +62 -202
- 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 +19 -21
- package/dist/lib/node-esm/testing/index.mjs.map +3 -3
- package/dist/types/src/feed-factory.d.ts.map +1 -1
- package/dist/types/src/feed-iterator.d.ts.map +1 -1
- package/dist/types/src/feed-queue.d.ts.map +1 -1
- package/dist/types/src/feed-set-iterator.d.ts.map +1 -1
- package/dist/types/src/feed-store.d.ts.map +1 -1
- package/dist/types/src/feed-wrapper.d.ts +18 -19
- package/dist/types/src/feed-wrapper.d.ts.map +1 -1
- package/dist/types/src/feed-writer.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +1 -1
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/testing/mocks.d.ts.map +1 -1
- package/dist/types/src/testing/test-builder.d.ts +2 -2
- package/dist/types/src/testing/test-builder.d.ts.map +1 -1
- package/dist/types/src/testing/test-generator.d.ts +2 -2
- package/dist/types/src/testing/test-generator.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +26 -26
- package/src/feed-queue.test.ts +1 -1
- package/src/feed-queue.ts +4 -2
- package/src/feed-set-iterator.test.ts +6 -6
- package/src/feed-store.node.test.ts +5 -5
- package/src/feed-wrapper.test.ts +45 -12
- package/src/feed-wrapper.ts +74 -35
- package/src/index.ts +1 -1
- package/src/testing/test-builder.ts +3 -4
- package/src/testing/test-generator.ts +5 -6
- package/dist/lib/browser/chunk-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,33 +1,32 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxos/feed-store",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.4-main.03d5cd7b56",
|
|
4
4
|
"description": "A consistent store for hypercore feeds.",
|
|
5
5
|
"homepage": "https://dxos.org",
|
|
6
6
|
"bugs": "https://github.com/dxos/dxos/issues",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "https://github.com/dxos/dxos"
|
|
10
|
+
},
|
|
7
11
|
"license": "MIT",
|
|
8
12
|
"author": "info@dxos.org",
|
|
9
|
-
"sideEffects":
|
|
13
|
+
"sideEffects": false,
|
|
10
14
|
"type": "module",
|
|
11
15
|
"exports": {
|
|
12
16
|
".": {
|
|
17
|
+
"source": "./src/index.ts",
|
|
13
18
|
"types": "./dist/types/src/index.d.ts",
|
|
14
19
|
"browser": "./dist/lib/browser/index.mjs",
|
|
15
20
|
"node": "./dist/lib/node-esm/index.mjs"
|
|
16
21
|
},
|
|
17
22
|
"./testing": {
|
|
23
|
+
"source": "./src/testing/index.ts",
|
|
18
24
|
"types": "./dist/types/src/testing/index.d.ts",
|
|
19
25
|
"browser": "./dist/lib/browser/testing/index.mjs",
|
|
20
26
|
"node": "./dist/lib/node-esm/testing/index.mjs"
|
|
21
27
|
}
|
|
22
28
|
},
|
|
23
29
|
"types": "dist/types/src/index.d.ts",
|
|
24
|
-
"typesVersions": {
|
|
25
|
-
"*": {
|
|
26
|
-
"testing": [
|
|
27
|
-
"dist/types/src/testing/index.d.ts"
|
|
28
|
-
]
|
|
29
|
-
}
|
|
30
|
-
},
|
|
31
30
|
"files": [
|
|
32
31
|
"testing.d.ts",
|
|
33
32
|
"testing.js",
|
|
@@ -36,29 +35,30 @@
|
|
|
36
35
|
],
|
|
37
36
|
"dependencies": {
|
|
38
37
|
"lodash.defaultsdeep": "^4.6.1",
|
|
39
|
-
"race-as-promised": "^0.0.
|
|
38
|
+
"race-as-promised": "^0.0.3",
|
|
40
39
|
"streamx": "^2.12.5",
|
|
41
|
-
"@dxos/
|
|
42
|
-
"@dxos/
|
|
43
|
-
"@dxos/context": "0.8.
|
|
44
|
-
"@dxos/
|
|
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/
|
|
40
|
+
"@dxos/async": "0.8.4-main.03d5cd7b56",
|
|
41
|
+
"@dxos/codec-protobuf": "0.8.4-main.03d5cd7b56",
|
|
42
|
+
"@dxos/context": "0.8.4-main.03d5cd7b56",
|
|
43
|
+
"@dxos/hypercore": "0.8.4-main.03d5cd7b56",
|
|
44
|
+
"@dxos/debug": "0.8.4-main.03d5cd7b56",
|
|
45
|
+
"@dxos/invariant": "0.8.4-main.03d5cd7b56",
|
|
46
|
+
"@dxos/crypto": "0.8.4-main.03d5cd7b56",
|
|
47
|
+
"@dxos/keyring": "0.8.4-main.03d5cd7b56",
|
|
48
|
+
"@dxos/keys": "0.8.4-main.03d5cd7b56",
|
|
49
|
+
"@dxos/log": "0.8.4-main.03d5cd7b56",
|
|
50
|
+
"@dxos/node-std": "0.8.4-main.03d5cd7b56",
|
|
51
|
+
"@dxos/random-access-storage": "0.8.4-main.03d5cd7b56",
|
|
52
|
+
"@dxos/vendor-hypercore": "0.8.4-main.03d5cd7b56",
|
|
53
|
+
"@dxos/util": "0.8.4-main.03d5cd7b56"
|
|
54
54
|
},
|
|
55
55
|
"devDependencies": {
|
|
56
56
|
"@types/lodash.defaultsdeep": "^4.6.6",
|
|
57
|
-
"@dxos/keys": "0.8.
|
|
58
|
-
"@dxos/random": "0.8.
|
|
57
|
+
"@dxos/keys": "0.8.4-main.03d5cd7b56",
|
|
58
|
+
"@dxos/random": "0.8.4-main.03d5cd7b56"
|
|
59
59
|
},
|
|
60
60
|
"optionalDependencies": {
|
|
61
|
-
"@dxos/random": "0.8.
|
|
61
|
+
"@dxos/random": "0.8.4-main.03d5cd7b56"
|
|
62
62
|
},
|
|
63
63
|
"publishConfig": {
|
|
64
64
|
"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
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
import { inspect } from 'node:util';
|
|
6
6
|
import { Writable } from 'streamx';
|
|
7
7
|
|
|
8
|
-
import { Event,
|
|
8
|
+
import { Event, Trigger, latch } from '@dxos/async';
|
|
9
9
|
import { inspectObject } from '@dxos/debug';
|
|
10
10
|
import type { ReadStreamOptions } from '@dxos/hypercore';
|
|
11
11
|
import { invariant } from '@dxos/invariant';
|
|
@@ -124,10 +124,12 @@ export class FeedQueue<T extends {}> {
|
|
|
124
124
|
};
|
|
125
125
|
|
|
126
126
|
const onError = (err?: Error) => {
|
|
127
|
+
if (!this.isOpen) {
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
127
130
|
if (!err) {
|
|
128
131
|
return;
|
|
129
132
|
}
|
|
130
|
-
|
|
131
133
|
if (err.message === 'Writable stream closed prematurely' || err.message === 'Feed is closed') {
|
|
132
134
|
return;
|
|
133
135
|
}
|
|
@@ -6,7 +6,7 @@ import { describe, expect, test } from 'vitest';
|
|
|
6
6
|
|
|
7
7
|
import { latch } from '@dxos/async';
|
|
8
8
|
import { log } from '@dxos/log';
|
|
9
|
-
import {
|
|
9
|
+
import { random } from '@dxos/random';
|
|
10
10
|
|
|
11
11
|
import { type FeedBlockSelector, FeedSetIterator } from './feed-set-iterator';
|
|
12
12
|
import { TestItemBuilder } from './testing';
|
|
@@ -14,7 +14,7 @@ import { type FeedBlock } from './types';
|
|
|
14
14
|
|
|
15
15
|
// Random selector.
|
|
16
16
|
const randomFeedBlockSelector: FeedBlockSelector<any> = (blocks: FeedBlock<any>[]) =>
|
|
17
|
-
|
|
17
|
+
random.number.int({ min: 0, max: blocks.length - 1 });
|
|
18
18
|
|
|
19
19
|
// TODO(burdon): Create randomized setTimeout to test race conditions.
|
|
20
20
|
|
|
@@ -79,7 +79,7 @@ describe('FeedSetIterator', () => {
|
|
|
79
79
|
|
|
80
80
|
// Write block.
|
|
81
81
|
setTimeout(async () => {
|
|
82
|
-
const feed =
|
|
82
|
+
const feed = random.helpers.arrayElement(feeds);
|
|
83
83
|
await builder.generator.writeBlocks(feed.createFeedWriter(), {
|
|
84
84
|
count: numBlocks,
|
|
85
85
|
});
|
|
@@ -119,14 +119,14 @@ describe('FeedSetIterator', () => {
|
|
|
119
119
|
expect(iterator.size).to.eq(numFeeds);
|
|
120
120
|
|
|
121
121
|
for (const _ of Array.from(Array(numBlocks))) {
|
|
122
|
-
const writer =
|
|
122
|
+
const writer = random.helpers.arrayElement(writers);
|
|
123
123
|
const receipts = await builder.generator.writeBlocks(writer, {
|
|
124
124
|
count: 1,
|
|
125
125
|
});
|
|
126
126
|
log('wrote', receipts);
|
|
127
127
|
}
|
|
128
128
|
},
|
|
129
|
-
|
|
129
|
+
random.number.int({ min: 0, max: 100 }),
|
|
130
130
|
);
|
|
131
131
|
|
|
132
132
|
// Open and start iterator.
|
|
@@ -147,7 +147,7 @@ describe('FeedSetIterator', () => {
|
|
|
147
147
|
}
|
|
148
148
|
}
|
|
149
149
|
},
|
|
150
|
-
|
|
150
|
+
random.number.int({ min: 0, max: 100 }),
|
|
151
151
|
);
|
|
152
152
|
|
|
153
153
|
// Wait until all written and read.
|
|
@@ -4,10 +4,10 @@
|
|
|
4
4
|
|
|
5
5
|
import { describe, expect, test } from 'vitest';
|
|
6
6
|
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
7
|
+
import { random } from '@dxos/random';
|
|
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 () => {
|
|
@@ -27,8 +27,8 @@ describe('FeedStore', () => {
|
|
|
27
27
|
for (const i of Array.from(Array(numBlocks)).keys()) {
|
|
28
28
|
await feed.append({
|
|
29
29
|
id: String(i),
|
|
30
|
-
value:
|
|
31
|
-
});
|
|
30
|
+
value: random.lorem.sentence(),
|
|
31
|
+
} as TestItem);
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
expect(feed.properties.length).to.eq(numBlocks);
|
package/src/feed-wrapper.test.ts
CHANGED
|
@@ -9,10 +9,10 @@ import { asyncTimeout, latch, sleep } from '@dxos/async';
|
|
|
9
9
|
import { createReadable } from '@dxos/hypercore';
|
|
10
10
|
import { PublicKey } from '@dxos/keys';
|
|
11
11
|
import { log } from '@dxos/log';
|
|
12
|
-
import {
|
|
12
|
+
import { random } from '@dxos/random';
|
|
13
13
|
import { range } from '@dxos/util';
|
|
14
14
|
|
|
15
|
-
import {
|
|
15
|
+
import { TestBuilder, TestItemBuilder, defaultValueEncoding } from './testing';
|
|
16
16
|
|
|
17
17
|
describe('FeedWrapper', () => {
|
|
18
18
|
const factory = new TestBuilder().createFeedFactory();
|
|
@@ -58,7 +58,7 @@ describe('FeedWrapper', () => {
|
|
|
58
58
|
const feed = await feedFactory.createFeed(key, { writable: true });
|
|
59
59
|
|
|
60
60
|
for (const _ of Array.from(Array(numBlocks)).keys()) {
|
|
61
|
-
await feed.append(
|
|
61
|
+
await feed.append(random.lorem.sentence());
|
|
62
62
|
}
|
|
63
63
|
|
|
64
64
|
expect(feed.properties.length).to.eq(numBlocks);
|
|
@@ -77,7 +77,7 @@ describe('FeedWrapper', () => {
|
|
|
77
77
|
});
|
|
78
78
|
|
|
79
79
|
for (const _ of Array.from(Array(numBlocks)).keys()) {
|
|
80
|
-
await feed.append(
|
|
80
|
+
await feed.append(random.lorem.sentence());
|
|
81
81
|
}
|
|
82
82
|
expect(emittedAppend).to.eq(numBlocks);
|
|
83
83
|
});
|
|
@@ -95,8 +95,8 @@ describe('FeedWrapper', () => {
|
|
|
95
95
|
for (const i of Array.from(Array(numBlocks)).keys()) {
|
|
96
96
|
await feed.append({
|
|
97
97
|
id: String(i + 1),
|
|
98
|
-
value:
|
|
99
|
-
});
|
|
98
|
+
value: random.lorem.sentence(),
|
|
99
|
+
} as any);
|
|
100
100
|
}
|
|
101
101
|
|
|
102
102
|
expect(feed.properties.length).to.eq(numBlocks);
|
|
@@ -117,10 +117,10 @@ describe('FeedWrapper', () => {
|
|
|
117
117
|
|
|
118
118
|
// TODO(burdon): Use generator.
|
|
119
119
|
for (const i of Array.from(Array(numBlocks)).keys()) {
|
|
120
|
-
await sleep(
|
|
120
|
+
await sleep(random.number.int({ min: 0, max: 20 }));
|
|
121
121
|
await feed.append({
|
|
122
122
|
id: String(i + 1),
|
|
123
|
-
value:
|
|
123
|
+
value: random.lorem.sentence(),
|
|
124
124
|
});
|
|
125
125
|
}
|
|
126
126
|
|
|
@@ -172,7 +172,7 @@ describe('FeedWrapper', () => {
|
|
|
172
172
|
const block = {
|
|
173
173
|
id: String(i + 1),
|
|
174
174
|
index: i,
|
|
175
|
-
value:
|
|
175
|
+
value: random.lorem.sentence(),
|
|
176
176
|
};
|
|
177
177
|
|
|
178
178
|
const seq = await writer.write(block);
|
|
@@ -220,7 +220,7 @@ describe('FeedWrapper', () => {
|
|
|
220
220
|
const block = {
|
|
221
221
|
id: String(index + 1),
|
|
222
222
|
index,
|
|
223
|
-
value:
|
|
223
|
+
value: random.lorem.sentence(),
|
|
224
224
|
};
|
|
225
225
|
await writer.write(block);
|
|
226
226
|
};
|
|
@@ -233,7 +233,7 @@ describe('FeedWrapper', () => {
|
|
|
233
233
|
// Reader.
|
|
234
234
|
{
|
|
235
235
|
const start = 5;
|
|
236
|
-
feed2.download({ start, linear: true }, (err: Error) => {
|
|
236
|
+
feed2.download({ start, linear: true }, (err: Error | null) => {
|
|
237
237
|
if (err) {
|
|
238
238
|
throw err;
|
|
239
239
|
}
|
|
@@ -260,7 +260,7 @@ describe('FeedWrapper', () => {
|
|
|
260
260
|
await feed2.open();
|
|
261
261
|
|
|
262
262
|
for (const i of range(numBlocks)) {
|
|
263
|
-
await feed1.append(`block-${i}`);
|
|
263
|
+
await feed1.append(`block-${i}` as any);
|
|
264
264
|
}
|
|
265
265
|
|
|
266
266
|
for (const i of range(numBlocks)) {
|
|
@@ -283,4 +283,37 @@ describe('FeedWrapper', () => {
|
|
|
283
283
|
console.log('audit', { err, valid });
|
|
284
284
|
});
|
|
285
285
|
});
|
|
286
|
+
|
|
287
|
+
test('integrates blocks via putBuffer', async () => {
|
|
288
|
+
const numBlocks = 5;
|
|
289
|
+
const builder = new TestBuilder();
|
|
290
|
+
const feedFactory = builder.createFeedFactory();
|
|
291
|
+
|
|
292
|
+
const key = await builder.keyring.createKey();
|
|
293
|
+
const source = await feedFactory.createFeed(key, { writable: true });
|
|
294
|
+
const target = await feedFactory.createFeed(key);
|
|
295
|
+
|
|
296
|
+
await source.open();
|
|
297
|
+
await target.open();
|
|
298
|
+
|
|
299
|
+
// Append to source.
|
|
300
|
+
for (let i = 0; i < numBlocks; i++) {
|
|
301
|
+
await source.append(random.lorem.sentence() as any);
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
// Integrate into target via putBuffer using proofs from source.
|
|
305
|
+
for (let i = 0; i < numBlocks; i++) {
|
|
306
|
+
const data = (await source.get(i, { valueEncoding: 'binary' })) as Uint8Array;
|
|
307
|
+
const proof = await source.proof(i);
|
|
308
|
+
await target.putBuffer(i, data, proof, null);
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
// Verify data and length.
|
|
312
|
+
expect(target.length).to.eq(numBlocks);
|
|
313
|
+
for (let i = 0; i < numBlocks; i++) {
|
|
314
|
+
const src = (await source.get(i, { valueEncoding: 'binary' })) as Uint8Array;
|
|
315
|
+
const dst = (await target.get(i, { valueEncoding: 'binary' })) as Uint8Array;
|
|
316
|
+
expect(Buffer.from(dst).equals(Buffer.from(src))).to.be.true;
|
|
317
|
+
}
|
|
318
|
+
});
|
|
286
319
|
});
|
package/src/feed-wrapper.ts
CHANGED
|
@@ -2,18 +2,19 @@
|
|
|
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
|
import { Readable, Transform } from 'streamx';
|
|
8
8
|
|
|
9
9
|
import { Trigger } from '@dxos/async';
|
|
10
|
-
import {
|
|
10
|
+
import { StackTrace, inspectObject } from '@dxos/debug';
|
|
11
11
|
import type { Hypercore, HypercoreProperties, ReadStreamOptions } from '@dxos/hypercore';
|
|
12
|
-
import { invariant } from '@dxos/invariant';
|
|
12
|
+
import { assertArgument, invariant } from '@dxos/invariant';
|
|
13
13
|
import { type PublicKey } from '@dxos/keys';
|
|
14
14
|
import { log } from '@dxos/log';
|
|
15
15
|
import { type Directory } from '@dxos/random-access-storage';
|
|
16
|
-
import { arrayToBuffer,
|
|
16
|
+
import { arrayToBuffer, rangeFromTo } from '@dxos/util';
|
|
17
|
+
import type { GetOptions, Proof } from '@dxos/vendor-hypercore/hypercore';
|
|
17
18
|
|
|
18
19
|
import { type FeedWriter, type WriteReceipt } from './feed-writer';
|
|
19
20
|
|
|
@@ -21,8 +22,8 @@ import { type FeedWriter, type WriteReceipt } from './feed-writer';
|
|
|
21
22
|
* Async feed wrapper.
|
|
22
23
|
*/
|
|
23
24
|
export class FeedWrapper<T extends {}> {
|
|
25
|
+
private _hypercore: Hypercore<T>;
|
|
24
26
|
private readonly _pendingWrites = new Set<StackTrace>();
|
|
25
|
-
private readonly _binder = createBinder(this._hypercore);
|
|
26
27
|
|
|
27
28
|
// Pending while writes are happening. Resolves when there are no pending writes.
|
|
28
29
|
private readonly _writeLock = new Trigger();
|
|
@@ -30,11 +31,12 @@ export class FeedWrapper<T extends {}> {
|
|
|
30
31
|
private _closed = false;
|
|
31
32
|
|
|
32
33
|
constructor(
|
|
33
|
-
|
|
34
|
+
hypercore: Hypercore<T>,
|
|
34
35
|
private _key: PublicKey, // TODO(burdon): Required since currently patching the key inside factory.
|
|
35
36
|
private _storageDirectory: Directory,
|
|
36
37
|
) {
|
|
37
|
-
|
|
38
|
+
assertArgument(hypercore, 'hypercore');
|
|
39
|
+
this._hypercore = hypercore;
|
|
38
40
|
invariant(this._key);
|
|
39
41
|
this._writeLock.wake();
|
|
40
42
|
}
|
|
@@ -143,31 +145,42 @@ export class FeedWrapper<T extends {}> {
|
|
|
143
145
|
await this._storageDirectory.flush();
|
|
144
146
|
}
|
|
145
147
|
|
|
146
|
-
get opened() {
|
|
148
|
+
get opened(): boolean {
|
|
147
149
|
return this._hypercore.opened;
|
|
148
150
|
}
|
|
149
151
|
|
|
150
|
-
get closed() {
|
|
152
|
+
get closed(): boolean {
|
|
151
153
|
return this._hypercore.closed;
|
|
152
154
|
}
|
|
153
155
|
|
|
154
|
-
get readable() {
|
|
156
|
+
get readable(): boolean {
|
|
155
157
|
return this._hypercore.readable;
|
|
156
158
|
}
|
|
157
159
|
|
|
158
|
-
get length() {
|
|
160
|
+
get length(): number {
|
|
159
161
|
return this._hypercore.length;
|
|
160
162
|
}
|
|
161
163
|
|
|
162
|
-
get byteLength() {
|
|
164
|
+
get byteLength(): number {
|
|
163
165
|
return this._hypercore.byteLength;
|
|
164
166
|
}
|
|
165
167
|
|
|
166
|
-
on
|
|
167
|
-
|
|
168
|
+
on(...args: any[]) {
|
|
169
|
+
return (this._hypercore as any).on(...args);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
off(...args: any[]) {
|
|
173
|
+
return (this._hypercore as any).off(...args);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
open(...args: Parameters<Hypercore<T>['open']>) {
|
|
177
|
+
return promisify(this._hypercore.open.bind(this._hypercore) as any)(...args);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
_close(...args: Parameters<Hypercore<T>['close']>) {
|
|
181
|
+
return promisify(this._hypercore.close.bind(this._hypercore) as any)(...args);
|
|
182
|
+
}
|
|
168
183
|
|
|
169
|
-
open = this._binder.async(this._hypercore.open);
|
|
170
|
-
private _close = this._binder.async(this._hypercore.close);
|
|
171
184
|
close = async () => {
|
|
172
185
|
if (this._pendingWrites.size) {
|
|
173
186
|
log.warn('Closing feed with pending writes', {
|
|
@@ -181,27 +194,53 @@ export class FeedWrapper<T extends {}> {
|
|
|
181
194
|
await this._close();
|
|
182
195
|
};
|
|
183
196
|
|
|
184
|
-
has
|
|
185
|
-
|
|
186
|
-
|
|
197
|
+
has(start: number, end?: number) {
|
|
198
|
+
return this._hypercore.has(start, end);
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
get(index: number, options?: GetOptions) {
|
|
202
|
+
return promisify(this._hypercore.get.bind(this._hypercore) as any)(index, options);
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
// TODO(dmaretskyi): Type better
|
|
206
|
+
append(data: any | any[]): Promise<number> {
|
|
207
|
+
return promisify(this._hypercore.append.bind(this._hypercore))(data);
|
|
208
|
+
}
|
|
187
209
|
|
|
188
210
|
/**
|
|
189
211
|
* Will not resolve if `end` parameter is not specified and the feed is not closed.
|
|
190
212
|
*/
|
|
191
|
-
download
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
213
|
+
download(...args: Parameters<Hypercore<T>['download']>) {
|
|
214
|
+
return this._hypercore.download(...args);
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
undownload(...args: Parameters<Hypercore<T>['undownload']>) {
|
|
218
|
+
return this._hypercore.undownload(...args);
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
setDownloading(...args: Parameters<Hypercore<T>['setDownloading']>) {
|
|
222
|
+
return this._hypercore.setDownloading(...args);
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
replicate(...args: Parameters<Hypercore<T>['replicate']>) {
|
|
226
|
+
return this._hypercore.replicate(...args);
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
clear(start: number, end?: number) {
|
|
230
|
+
return promisify(this._hypercore.clear.bind(this._hypercore))(start, end);
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
proof(index: number, options?: any) {
|
|
234
|
+
return promisify(this._hypercore.proof.bind(this._hypercore))(index);
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
put(index: number, data: T, proof: Proof) {
|
|
238
|
+
return promisify(this._hypercore.put.bind(this._hypercore))(index, data, proof);
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
putBuffer(index: number, data: Buffer | Uint8Array, proof: Proof, peer: null): Promise<void> {
|
|
242
|
+
return promisify((this._hypercore as any)._putBuffer.bind(this._hypercore) as any)(index, data, proof, peer);
|
|
243
|
+
}
|
|
205
244
|
|
|
206
245
|
/**
|
|
207
246
|
* Clear and check for integrity.
|
|
@@ -216,7 +255,7 @@ export class FeedWrapper<T extends {}> {
|
|
|
216
255
|
const messagesBefore = await Promise.all(
|
|
217
256
|
rangeFromTo(checkBegin, checkEnd).map((idx) =>
|
|
218
257
|
this.get(idx, {
|
|
219
|
-
valueEncoding: { decode: (x: Uint8Array) => x },
|
|
258
|
+
valueEncoding: { decode: (x: Uint8Array) => x } as any,
|
|
220
259
|
}),
|
|
221
260
|
),
|
|
222
261
|
);
|
|
@@ -226,7 +265,7 @@ export class FeedWrapper<T extends {}> {
|
|
|
226
265
|
const messagesAfter = await Promise.all(
|
|
227
266
|
rangeFromTo(checkBegin, checkEnd).map((idx) =>
|
|
228
267
|
this.get(idx, {
|
|
229
|
-
valueEncoding: { decode: (x: Uint8Array) => x },
|
|
268
|
+
valueEncoding: { decode: (x: Uint8Array) => x } as any,
|
|
230
269
|
}),
|
|
231
270
|
),
|
|
232
271
|
);
|
package/src/index.ts
CHANGED
|
@@ -2,14 +2,13 @@
|
|
|
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';
|
|
11
|
+
import { type TestGenerator, type TestItem, defaultTestGenerator, defaultValueEncoding } from './test-generator';
|
|
13
12
|
|
|
14
13
|
export type TestBuilderOptions<T extends {}> = {
|
|
15
14
|
storage?: Storage;
|
|
@@ -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
|
-
import {
|
|
8
|
+
import { random } from '@dxos/random';
|
|
9
|
+
import type { AbstractValueEncoding } from '@dxos/vendor-hypercore/hypercore';
|
|
11
10
|
|
|
12
11
|
import { type FeedWriter } from '../feed-writer';
|
|
13
12
|
|
|
@@ -27,9 +26,9 @@ export const defaultValueEncoding: AbstractValueEncoding<any> = createCodecEncod
|
|
|
27
26
|
export type TestBlockGenerator<T> = (i: number) => T;
|
|
28
27
|
|
|
29
28
|
export const defaultTestBlockGenerator: TestBlockGenerator<TestItem> = (i) => ({
|
|
30
|
-
id:
|
|
29
|
+
id: random.string.uuid(),
|
|
31
30
|
index: i,
|
|
32
|
-
value:
|
|
31
|
+
value: random.lorem.sentence(),
|
|
33
32
|
});
|
|
34
33
|
|
|
35
34
|
/**
|
|
@@ -58,7 +57,7 @@ export class TestGenerator<T extends {}> {
|
|
|
58
57
|
const data = this._generate(this._count++);
|
|
59
58
|
const receipt = await writer.write(data);
|
|
60
59
|
if (delay) {
|
|
61
|
-
await sleep(
|
|
60
|
+
await sleep(random.number.int(delay));
|
|
62
61
|
}
|
|
63
62
|
|
|
64
63
|
return receipt;
|
|
@@ -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,SAASC,eAAe;AACxB,SAASC,eAAeC,kBAAkB;AAE1C,SAASC,iBAAiB;AAE1B,SAASC,WAAW;AAEpB,SAASC,eAAeC,cAAcC,mBAAmB;;AAOlD,IAAMC,cAAN,MAAMA;EASX,YACUC,YACAC,MACAC,mBACR;SAHQF,aAAAA;SACAC,OAAAA;SACAC,oBAAAA;SAXOC,iBAAiB,oBAAIC,IAAAA;SACrBC,UAAUR,aAAa,KAAKG,UAAU;SAGtCM,aAAa,IAAIf,QAAAA;SAE1BgB,UAAU;SAwIlBC,KAAK,KAAKH,QAAQI,GAAG,KAAKT,WAAWQ,EAAE;SACvCE,MAAM,KAAKL,QAAQI,GAAG,KAAKT,WAAWU,GAAG;SAEzCC,OAAO,KAAKN,QAAQO,MAAM,KAAKZ,WAAWW,IAAI;SACtCE,SAAS,KAAKR,QAAQO,MAAM,KAAKZ,WAAWc,KAAK;SACzDA,QAAQ,YAAA;AACN,UAAI,KAAKX,eAAeY,MAAM;AAC5BpB,YAAIqB,KAAK,oCAAoC;UAC3CC,MAAM,KAAKhB;UACXiB,OAAO,KAAKf,eAAeY;UAC3BI,eAAeC,MAAMC,KAAK,KAAKlB,eAAemB,OAAM,CAAA,EAAIC,IAAI,CAACC,UAAUA,MAAMC,SAAQ,CAAA;QACvF,GAAA;;;;;;MACF;AACA,WAAKlB,UAAU;AACf,YAAM,KAAKmB,YAAW;AACtB,YAAM,KAAKb,OAAM;IACnB;SAEAc,MAAM,KAAKtB,QAAQI,GAAG,KAAKT,WAAW2B,GAAG;SACzCC,MAAM,KAA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AIK,MAAM;AAGR,YAAIJ,YAAY,CAACI,KAAKC,WAAWL,UAAU;AACzC,gBAAM,IAAIM,MAAM,mCAAmCP,QAAQQ,SAAQ,CAAA,EAAI;QACzE,YAAYN,UAAU,WAAWG,KAAKC,WAAWJ,QAAQ;AACvD,gBAAM,IAAIK,MACR,oDAAoDP,QAAQQ,SAAQ,CAAA,KAAON,MAAAA,QACzEG,KAAKC,WAAWJ,MAAM,GACrB;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
|
-
}
|