@dxos/feed-store 0.3.11-main.fbbdc2a → 0.3.11-main.fc97a54
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-RKU3WWGX.mjs → chunk-T2S2O6PX.mjs} +8 -8
- package/dist/lib/browser/{chunk-RKU3WWGX.mjs.map → chunk-T2S2O6PX.mjs.map} +3 -3
- package/dist/lib/browser/index.mjs +1 -1
- package/dist/lib/browser/index.mjs.map +1 -1
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +2 -2
- package/dist/lib/browser/testing/index.mjs.map +3 -3
- package/dist/lib/node/{chunk-GOC254TC.cjs → chunk-M6CR35O7.cjs} +10 -10
- package/dist/lib/node/{chunk-GOC254TC.cjs.map → chunk-M6CR35O7.cjs.map} +3 -3
- package/dist/lib/node/index.cjs +4 -4
- package/dist/lib/node/index.cjs.map +1 -1
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/testing/index.cjs +7 -7
- package/dist/lib/node/testing/index.cjs.map +2 -2
- package/dist/types/src/feed-store.d.ts +1 -1
- package/dist/types/src/feed-store.d.ts.map +1 -1
- package/dist/types/src/testing/test-generator.d.ts.map +1 -1
- package/package.json +17 -17
- package/src/feed-set-iterator.test.ts +38 -32
- package/src/feed-store.test.ts +1 -1
- package/src/feed-store.ts +4 -4
- package/src/feed-wrapper.test.ts +1 -1
- package/src/testing/test-generator.ts +1 -1
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
// Copyright 2020 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { faker } from '@faker-js/faker';
|
|
6
5
|
import { expect } from 'chai';
|
|
7
6
|
|
|
8
7
|
import { latch } from '@dxos/async';
|
|
9
8
|
import { log } from '@dxos/log';
|
|
9
|
+
import { faker } from '@dxos/random';
|
|
10
10
|
import { describe, test } from '@dxos/test';
|
|
11
11
|
|
|
12
12
|
import { type FeedBlockSelector, FeedSetIterator } from './feed-set-iterator';
|
|
@@ -104,28 +104,31 @@ describe('FeedSetIterator', () => {
|
|
|
104
104
|
const iterator = new FeedSetIterator(randomFeedBlockSelector);
|
|
105
105
|
|
|
106
106
|
// Write blocks.
|
|
107
|
-
setTimeout(
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
const
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
107
|
+
setTimeout(
|
|
108
|
+
async () => {
|
|
109
|
+
// Create feeds.
|
|
110
|
+
// TODO(burdon): Test adding feeds on-the-fly.
|
|
111
|
+
const writers = await Promise.all(
|
|
112
|
+
Array.from(Array(numFeeds)).map(async () => {
|
|
113
|
+
const key = await builder.keyring.createKey();
|
|
114
|
+
const feed = await feedStore.openFeed(key, { writable: true });
|
|
115
|
+
await iterator.addFeed(feed);
|
|
116
|
+
return feed.createFeedWriter();
|
|
117
|
+
}),
|
|
118
|
+
);
|
|
119
|
+
|
|
120
|
+
expect(iterator.size).to.eq(numFeeds);
|
|
121
|
+
|
|
122
|
+
for (const _ of Array.from(Array(numBlocks))) {
|
|
123
|
+
const writer = faker.helpers.arrayElement(writers);
|
|
124
|
+
const receipts = await builder.generator.writeBlocks(writer, {
|
|
125
|
+
count: 1,
|
|
126
|
+
});
|
|
127
|
+
log('wrote', receipts);
|
|
128
|
+
}
|
|
129
|
+
},
|
|
130
|
+
faker.number.int({ min: 0, max: 100 }),
|
|
131
|
+
);
|
|
129
132
|
|
|
130
133
|
// Open and start iterator.
|
|
131
134
|
await iterator.open();
|
|
@@ -134,16 +137,19 @@ describe('FeedSetIterator', () => {
|
|
|
134
137
|
|
|
135
138
|
// Read blocks.
|
|
136
139
|
const [readAll, read] = latch({ count: numBlocks });
|
|
137
|
-
setTimeout(
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
140
|
+
setTimeout(
|
|
141
|
+
async () => {
|
|
142
|
+
for await (const block of iterator) {
|
|
143
|
+
const { feedKey, seq } = block;
|
|
144
|
+
const count = read();
|
|
145
|
+
log('read', { feedKey, seq, count });
|
|
146
|
+
if (count === numBlocks) {
|
|
147
|
+
await iterator.stop();
|
|
148
|
+
}
|
|
144
149
|
}
|
|
145
|
-
}
|
|
146
|
-
|
|
150
|
+
},
|
|
151
|
+
faker.number.int({ min: 0, max: 100 }),
|
|
152
|
+
);
|
|
147
153
|
|
|
148
154
|
// Wait until all written and read.
|
|
149
155
|
const count = await readAll();
|
package/src/feed-store.test.ts
CHANGED
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
// Copyright 2022 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { faker } from '@faker-js/faker';
|
|
6
5
|
import chai, { expect } from 'chai';
|
|
7
6
|
import chaiAsPromised from 'chai-as-promised';
|
|
8
7
|
|
|
9
8
|
import { PublicKey } from '@dxos/keys';
|
|
9
|
+
import { faker } from '@dxos/random';
|
|
10
10
|
import { createStorage, StorageType } from '@dxos/random-access-storage';
|
|
11
11
|
import { describe, test } from '@dxos/test';
|
|
12
12
|
|
package/src/feed-store.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// Copyright 2019 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { Event,
|
|
5
|
+
import { Event, Mutex } from '@dxos/async';
|
|
6
6
|
import { failUndefined } from '@dxos/debug';
|
|
7
7
|
import { invariant } from '@dxos/invariant';
|
|
8
8
|
import { PublicKey } from '@dxos/keys';
|
|
@@ -21,7 +21,7 @@ export interface FeedStoreOptions<T extends {}> {
|
|
|
21
21
|
*/
|
|
22
22
|
export class FeedStore<T extends {}> {
|
|
23
23
|
private readonly _feeds: ComplexMap<PublicKey, FeedWrapper<T>> = new ComplexMap(PublicKey.hash);
|
|
24
|
-
private readonly
|
|
24
|
+
private readonly _mutexes = new ComplexMap<PublicKey, Mutex>(PublicKey.hash);
|
|
25
25
|
private readonly _factory: FeedFactory<T>;
|
|
26
26
|
|
|
27
27
|
private _closed = false;
|
|
@@ -56,9 +56,9 @@ export class FeedStore<T extends {}> {
|
|
|
56
56
|
invariant(feedKey);
|
|
57
57
|
invariant(!this._closed, 'Feed store is closed');
|
|
58
58
|
|
|
59
|
-
const
|
|
59
|
+
const mutex = defaultMap(this._mutexes, feedKey, () => new Mutex());
|
|
60
60
|
|
|
61
|
-
return
|
|
61
|
+
return mutex.executeSynchronized(async () => {
|
|
62
62
|
let feed = this.getFeed(feedKey);
|
|
63
63
|
if (feed) {
|
|
64
64
|
// TODO(burdon): Need to check that there's another instance being used (create test and break this).
|
package/src/feed-wrapper.test.ts
CHANGED
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
// Copyright 2022 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { faker } from '@faker-js/faker';
|
|
6
5
|
import { expect } from 'chai';
|
|
7
6
|
import waitForExpect from 'wait-for-expect';
|
|
8
7
|
|
|
@@ -10,6 +9,7 @@ import { asyncTimeout, latch, sleep } from '@dxos/async';
|
|
|
10
9
|
import { createReadable } from '@dxos/hypercore';
|
|
11
10
|
import { PublicKey } from '@dxos/keys';
|
|
12
11
|
import { log } from '@dxos/log';
|
|
12
|
+
import { faker } from '@dxos/random';
|
|
13
13
|
import { describe, test } from '@dxos/test';
|
|
14
14
|
import { range } from '@dxos/util';
|
|
15
15
|
|
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
// Copyright 2022 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { faker } from '@faker-js/faker';
|
|
6
5
|
import type { AbstractValueEncoding } from 'hypercore';
|
|
7
6
|
|
|
8
7
|
import { sleep } from '@dxos/async';
|
|
9
8
|
import { type Codec } from '@dxos/codec-protobuf';
|
|
10
9
|
import { createCodecEncoding } from '@dxos/hypercore';
|
|
10
|
+
import { faker } from '@dxos/random';
|
|
11
11
|
|
|
12
12
|
import { type FeedWriter } from '../feed-writer';
|
|
13
13
|
|