@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.
@@ -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(async () => {
108
- // Create feeds.
109
- // TODO(burdon): Test adding feeds on-the-fly.
110
- const writers = await Promise.all(
111
- Array.from(Array(numFeeds)).map(async () => {
112
- const key = await builder.keyring.createKey();
113
- const feed = await feedStore.openFeed(key, { writable: true });
114
- await iterator.addFeed(feed);
115
- return feed.createFeedWriter();
116
- }),
117
- );
118
-
119
- expect(iterator.size).to.eq(numFeeds);
120
-
121
- for (const _ of Array.from(Array(numBlocks))) {
122
- const writer = faker.helpers.arrayElement(writers);
123
- const receipts = await builder.generator.writeBlocks(writer, {
124
- count: 1,
125
- });
126
- log('wrote', receipts);
127
- }
128
- }, faker.number.int({ min: 0, max: 100 }));
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(async () => {
138
- for await (const block of iterator) {
139
- const { feedKey, seq } = block;
140
- const count = read();
141
- log('read', { feedKey, seq, count });
142
- if (count === numBlocks) {
143
- await iterator.stop();
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
- }, faker.number.int({ min: 0, max: 100 }));
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();
@@ -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, Lock } from '@dxos/async';
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 _locks = new ComplexMap<PublicKey, Lock>(PublicKey.hash);
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 lock = defaultMap(this._locks, feedKey, () => new Lock());
59
+ const mutex = defaultMap(this._mutexes, feedKey, () => new Mutex());
60
60
 
61
- return lock.executeSynchronized(async () => {
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).
@@ -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