@dxos/echo-db 2.33.5-dev.0a40e013 → 2.33.5-dev.1fc05a51

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.
Files changed (168) hide show
  1. package/dist/src/api/selection/queries.d.ts.map +1 -1
  2. package/dist/src/api/selection/queries.js +13 -17
  3. package/dist/src/api/selection/queries.js.map +1 -1
  4. package/dist/src/api/selection/selection.d.ts.map +1 -1
  5. package/dist/src/api/selection/selection.js +1 -3
  6. package/dist/src/api/selection/selection.js.map +1 -1
  7. package/dist/src/api/selection/selection.test.js +4 -12
  8. package/dist/src/api/selection/selection.test.js.map +1 -1
  9. package/dist/src/database/item-demuxer.d.ts +1 -1
  10. package/dist/src/database/item-demuxer.d.ts.map +1 -1
  11. package/dist/src/database/item-demuxer.js +3 -3
  12. package/dist/src/database/item-demuxer.js.map +1 -1
  13. package/dist/src/database/item-manager.js +2 -2
  14. package/dist/src/database/item-manager.js.map +1 -1
  15. package/dist/src/database/testing.js +1 -1
  16. package/dist/src/database/testing.js.map +1 -1
  17. package/dist/src/echo.d.ts +1 -0
  18. package/dist/src/echo.d.ts.map +1 -1
  19. package/dist/src/echo.js +7 -18
  20. package/dist/src/echo.js.map +1 -1
  21. package/dist/src/halo/halo-factory.d.ts.map +1 -1
  22. package/dist/src/halo/halo-factory.js +5 -11
  23. package/dist/src/halo/halo-factory.js.map +1 -1
  24. package/dist/src/halo/halo-party.d.ts +3 -3
  25. package/dist/src/halo/halo-party.d.ts.map +1 -1
  26. package/dist/src/halo/halo-party.js +3 -3
  27. package/dist/src/halo/halo-party.js.map +1 -1
  28. package/dist/src/halo/halo.test.js +4 -3
  29. package/dist/src/halo/halo.test.js.map +1 -1
  30. package/dist/src/halo/identity.js +2 -2
  31. package/dist/src/halo/identity.js.map +1 -1
  32. package/dist/src/halo/party-opener.d.ts +1 -1
  33. package/dist/src/halo/party-opener.d.ts.map +1 -1
  34. package/dist/src/halo/party-opener.js +2 -2
  35. package/dist/src/halo/party-opener.js.map +1 -1
  36. package/dist/src/halo/preferences.d.ts.map +1 -1
  37. package/dist/src/halo/preferences.js +7 -10
  38. package/dist/src/halo/preferences.js.map +1 -1
  39. package/dist/src/invitations/greeting-protocol-provider.d.ts.map +1 -1
  40. package/dist/src/invitations/greeting-protocol-provider.js +5 -9
  41. package/dist/src/invitations/greeting-protocol-provider.js.map +1 -1
  42. package/dist/src/invitations/greeting-responder.d.ts +2 -2
  43. package/dist/src/invitations/greeting-responder.d.ts.map +1 -1
  44. package/dist/src/invitations/greeting-responder.js +8 -12
  45. package/dist/src/invitations/greeting-responder.js.map +1 -1
  46. package/dist/src/invitations/invitation-factory.d.ts +2 -2
  47. package/dist/src/invitations/invitation-factory.d.ts.map +1 -1
  48. package/dist/src/invitations/invitation-factory.js.map +1 -1
  49. package/dist/src/invitations/offline-invitation-claimer.d.ts.map +1 -1
  50. package/dist/src/invitations/offline-invitation-claimer.js +5 -7
  51. package/dist/src/invitations/offline-invitation-claimer.js.map +1 -1
  52. package/dist/src/parties/data-party.d.ts +7 -5
  53. package/dist/src/parties/data-party.d.ts.map +1 -1
  54. package/dist/src/parties/data-party.js +9 -8
  55. package/dist/src/parties/data-party.js.map +1 -1
  56. package/dist/src/parties/data-party.test.js +16 -15
  57. package/dist/src/parties/data-party.test.js.map +1 -1
  58. package/dist/src/parties/party-factory.d.ts +0 -6
  59. package/dist/src/parties/party-factory.d.ts.map +1 -1
  60. package/dist/src/parties/party-factory.js +17 -45
  61. package/dist/src/parties/party-factory.js.map +1 -1
  62. package/dist/src/parties/party-manager.d.ts.map +1 -1
  63. package/dist/src/parties/party-manager.js +2 -1
  64. package/dist/src/parties/party-manager.js.map +1 -1
  65. package/dist/src/parties/party-manager.test.js +7 -6
  66. package/dist/src/parties/party-manager.test.js.map +1 -1
  67. package/dist/src/pipeline/message-selector.d.ts +2 -2
  68. package/dist/src/pipeline/message-selector.d.ts.map +1 -1
  69. package/dist/src/pipeline/message-selector.js +29 -29
  70. package/dist/src/pipeline/message-selector.js.map +1 -1
  71. package/dist/src/pipeline/metadata-store.d.ts +3 -3
  72. package/dist/src/pipeline/metadata-store.d.ts.map +1 -1
  73. package/dist/src/pipeline/metadata-store.js +5 -5
  74. package/dist/src/pipeline/metadata-store.js.map +1 -1
  75. package/dist/src/pipeline/metadata-store.test.js +8 -4
  76. package/dist/src/pipeline/metadata-store.test.js.map +1 -1
  77. package/dist/src/pipeline/party-core.d.ts +3 -2
  78. package/dist/src/pipeline/party-core.d.ts.map +1 -1
  79. package/dist/src/pipeline/party-core.js +5 -0
  80. package/dist/src/pipeline/party-core.js.map +1 -1
  81. package/dist/src/pipeline/party-core.test.js +15 -15
  82. package/dist/src/pipeline/party-core.test.js.map +1 -1
  83. package/dist/src/pipeline/party-processor.d.ts +23 -5
  84. package/dist/src/pipeline/party-processor.d.ts.map +1 -1
  85. package/dist/src/pipeline/party-processor.js.map +1 -1
  86. package/dist/src/pipeline/pipeline.d.ts +2 -4
  87. package/dist/src/pipeline/pipeline.d.ts.map +1 -1
  88. package/dist/src/pipeline/pipeline.js +0 -3
  89. package/dist/src/pipeline/pipeline.js.map +1 -1
  90. package/dist/src/pipeline/pipeline.test.js +2 -2
  91. package/dist/src/pipeline/pipeline.test.js.map +1 -1
  92. package/dist/src/protocol/auth-plugin.d.ts +1 -1
  93. package/dist/src/protocol/auth-plugin.d.ts.map +1 -1
  94. package/dist/src/protocol/auth-plugin.js +1 -3
  95. package/dist/src/protocol/auth-plugin.js.map +1 -1
  96. package/dist/src/protocol/authenticator.d.ts +2 -2
  97. package/dist/src/protocol/authenticator.d.ts.map +1 -1
  98. package/dist/src/protocol/authenticator.js +12 -16
  99. package/dist/src/protocol/authenticator.js.map +1 -1
  100. package/dist/src/protocol/halo-recovery-plugin.d.ts +1 -1
  101. package/dist/src/protocol/halo-recovery-plugin.d.ts.map +1 -1
  102. package/dist/src/protocol/halo-recovery-plugin.js +1 -3
  103. package/dist/src/protocol/halo-recovery-plugin.js.map +1 -1
  104. package/dist/src/protocol/identity-credentials.d.ts +2 -2
  105. package/dist/src/protocol/identity-credentials.d.ts.map +1 -1
  106. package/dist/src/protocol/identity-credentials.js +4 -4
  107. package/dist/src/protocol/identity-credentials.js.map +1 -1
  108. package/dist/src/protocol/offline-invitation-plugin.d.ts +1 -1
  109. package/dist/src/protocol/offline-invitation-plugin.d.ts.map +1 -1
  110. package/dist/src/protocol/offline-invitation-plugin.js +1 -3
  111. package/dist/src/protocol/offline-invitation-plugin.js.map +1 -1
  112. package/dist/src/protocol/replicator-plugin.d.ts.map +1 -1
  113. package/dist/src/protocol/replicator-plugin.js +4 -6
  114. package/dist/src/protocol/replicator-plugin.js.map +1 -1
  115. package/dist/src/snapshots/snapshot-generator.d.ts +1 -1
  116. package/dist/src/snapshots/snapshot-generator.d.ts.map +1 -1
  117. package/dist/src/snapshots/snapshot-generator.js +13 -15
  118. package/dist/src/snapshots/snapshot-generator.js.map +1 -1
  119. package/dist/src/snapshots/snapshot-store.d.ts +3 -3
  120. package/dist/src/snapshots/snapshot-store.d.ts.map +1 -1
  121. package/dist/src/snapshots/snapshot-store.js +5 -5
  122. package/dist/src/snapshots/snapshot-store.js.map +1 -1
  123. package/dist/src/snapshots/snapshot-store.test.js +1 -1
  124. package/dist/src/snapshots/snapshot-store.test.js.map +1 -1
  125. package/dist/src/testing/testing-factories.js +2 -2
  126. package/dist/src/testing/testing-factories.js.map +1 -1
  127. package/dist/tsconfig.tsbuildinfo +1 -1
  128. package/package.json +18 -18
  129. package/src/api/selection/queries.ts +14 -18
  130. package/src/api/selection/selection.test.ts +4 -12
  131. package/src/api/selection/selection.ts +1 -7
  132. package/src/database/item-demuxer.ts +2 -2
  133. package/src/database/item-manager.ts +2 -2
  134. package/src/database/testing.ts +1 -1
  135. package/src/echo.ts +8 -18
  136. package/src/halo/halo-factory.ts +6 -18
  137. package/src/halo/halo-party.ts +6 -6
  138. package/src/halo/halo.test.ts +4 -3
  139. package/src/halo/identity.ts +2 -2
  140. package/src/halo/party-opener.ts +2 -2
  141. package/src/halo/preferences.ts +7 -10
  142. package/src/invitations/greeting-protocol-provider.ts +5 -9
  143. package/src/invitations/greeting-responder.ts +10 -14
  144. package/src/invitations/invitation-factory.ts +2 -2
  145. package/src/invitations/offline-invitation-claimer.ts +5 -7
  146. package/src/parties/data-party.test.ts +17 -15
  147. package/src/parties/data-party.ts +15 -12
  148. package/src/parties/party-factory.ts +23 -69
  149. package/src/parties/party-manager.test.ts +9 -6
  150. package/src/parties/party-manager.ts +2 -1
  151. package/src/pipeline/message-selector.ts +30 -34
  152. package/src/pipeline/metadata-store.test.ts +8 -4
  153. package/src/pipeline/metadata-store.ts +5 -5
  154. package/src/pipeline/party-core.test.ts +15 -15
  155. package/src/pipeline/party-core.ts +7 -2
  156. package/src/pipeline/party-processor.ts +26 -2
  157. package/src/pipeline/pipeline.test.ts +2 -2
  158. package/src/pipeline/pipeline.ts +2 -6
  159. package/src/protocol/auth-plugin.ts +1 -3
  160. package/src/protocol/authenticator.ts +27 -31
  161. package/src/protocol/halo-recovery-plugin.ts +4 -6
  162. package/src/protocol/identity-credentials.ts +4 -4
  163. package/src/protocol/offline-invitation-plugin.ts +4 -6
  164. package/src/protocol/replicator-plugin.ts +4 -6
  165. package/src/snapshots/snapshot-generator.ts +12 -16
  166. package/src/snapshots/snapshot-store.test.ts +1 -1
  167. package/src/snapshots/snapshot-store.ts +5 -6
  168. package/src/testing/testing-factories.ts +2 -2
@@ -12,19 +12,17 @@ import { CredentialsSigner } from './credentials-signer';
12
12
 
13
13
  const log = debug('dxos:echo-db:authenticator');
14
14
 
15
- export function createAuthenticator (partyProcessor: PartyProcessor, credentialsSigner: CredentialsSigner): Authenticator {
16
- return new PartyAuthenticator(partyProcessor.state, async auth => {
17
- if (auth.feedAdmit && auth.feedKey && !partyProcessor.isFeedAdmitted(auth.feedKey)) {
18
- log(`Admitting feed of authenticated member: ${auth.feedKey}`);
19
- await partyProcessor.writeHaloMessage(createEnvelopeMessage(
20
- credentialsSigner.signer,
21
- partyProcessor.partyKey,
22
- auth.feedAdmit,
23
- [credentialsSigner.getDeviceSigningKeys()]
24
- ));
25
- }
26
- });
27
- }
15
+ export const createAuthenticator = (partyProcessor: PartyProcessor, credentialsSigner: CredentialsSigner): Authenticator => new PartyAuthenticator(partyProcessor.state, async auth => {
16
+ if (auth.feedAdmit && auth.feedKey && !partyProcessor.isFeedAdmitted(auth.feedKey)) {
17
+ log(`Admitting feed of authenticated member: ${auth.feedKey}`);
18
+ await partyProcessor.writeHaloMessage(createEnvelopeMessage(
19
+ credentialsSigner.signer,
20
+ partyProcessor.partyKey,
21
+ auth.feedAdmit,
22
+ [credentialsSigner.getDeviceSigningKeys()]
23
+ ));
24
+ }
25
+ });
28
26
 
29
27
  export interface CredentialsProvider {
30
28
  /**
@@ -33,24 +31,22 @@ export interface CredentialsProvider {
33
31
  get (): Buffer
34
32
  }
35
33
 
36
- export function createCredentialsProvider (credentialsSigner: CredentialsSigner, partyKey: PartyKey, feedKey: FeedKey): CredentialsProvider {
37
- return {
38
- get: () => {
39
- const authMessage = createAuthMessage(
34
+ export const createCredentialsProvider = (credentialsSigner: CredentialsSigner, partyKey: PartyKey, feedKey: FeedKey): CredentialsProvider => ({
35
+ get: () => {
36
+ const authMessage = createAuthMessage(
37
+ credentialsSigner.signer,
38
+ partyKey,
39
+ credentialsSigner.getIdentityKey(),
40
+ credentialsSigner.getDeviceSigningKeys(),
41
+ feedKey,
42
+ undefined,
43
+ createFeedAdmitMessage(
40
44
  credentialsSigner.signer,
41
45
  partyKey,
42
- credentialsSigner.getIdentityKey(),
43
- credentialsSigner.getDeviceSigningKeys(),
44
46
  feedKey,
45
- undefined,
46
- createFeedAdmitMessage(
47
- credentialsSigner.signer,
48
- partyKey,
49
- feedKey,
50
- [feedKey, credentialsSigner.getDeviceSigningKeys()]
51
- )
52
- );
53
- return Buffer.from(codec.encode(authMessage));
54
- }
55
- };
56
- }
47
+ [feedKey, credentialsSigner.getDeviceSigningKeys()]
48
+ )
49
+ );
50
+ return Buffer.from(codec.encode(authMessage));
51
+ }
52
+ });
@@ -12,9 +12,7 @@ import { HaloRecoveryInitiator, InvitationFactory } from '../invitations';
12
12
  * Plugin is intended to be used in HALO party swarm.
13
13
  *
14
14
  */
15
- export function createHaloRecoveryPlugin (identityKey: PublicKey, invitationFactory: InvitationFactory, peerId: PublicKey) {
16
- return new GreetingCommandPlugin(
17
- peerId.asBuffer(),
18
- HaloRecoveryInitiator.createHaloInvitationClaimHandler(identityKey, invitationFactory)
19
- );
20
- }
15
+ export const createHaloRecoveryPlugin = (identityKey: PublicKey, invitationFactory: InvitationFactory, peerId: PublicKey) => new GreetingCommandPlugin(
16
+ peerId.asBuffer(),
17
+ HaloRecoveryInitiator.createHaloInvitationClaimHandler(identityKey, invitationFactory)
18
+ );
@@ -25,7 +25,7 @@ export interface IdentityCredentials {
25
25
 
26
26
  export type IdentityCredentialsProvider = () => IdentityCredentials | undefined
27
27
 
28
- export async function createTestIdentityCredentials (keyring: Keyring): Promise<IdentityCredentials> {
28
+ export const createTestIdentityCredentials = async (keyring: Keyring): Promise<IdentityCredentials> => {
29
29
  const identityKey = await keyring.createKeyRecord({ type: KeyType.IDENTITY });
30
30
  const deviceKey = await keyring.createKeyRecord({ type: KeyType.DEVICE });
31
31
  const feedKey = await keyring.createKeyRecord({ type: KeyType.FEED });
@@ -53,9 +53,9 @@ export async function createTestIdentityCredentials (keyring: Keyring): Promise<
53
53
  preferences: undefined,
54
54
  contacts: undefined
55
55
  };
56
- }
56
+ };
57
57
 
58
- export async function deriveTestDeviceCredentials (identity: IdentityCredentials): Promise<IdentityCredentials> {
58
+ export const deriveTestDeviceCredentials = async (identity: IdentityCredentials): Promise<IdentityCredentials> => {
59
59
  const deviceKey = await identity.keyring.createKeyRecord({ type: KeyType.DEVICE });
60
60
  const keyAdmit = createKeyAdmitMessage(identity.keyring, identity.identityKey.publicKey, deviceKey, [identity.identityKey]);
61
61
 
@@ -75,4 +75,4 @@ export async function deriveTestDeviceCredentials (identity: IdentityCredentials
75
75
  deviceKeyChain
76
76
  )
77
77
  };
78
- }
78
+ };
@@ -11,9 +11,7 @@ import { InvitationFactory, OfflineInvitationClaimer } from '../invitations';
11
11
  * Creates network protocol plugin that allows peers to claim offline invitations.
12
12
  * Plugin is intended to be used in data-party swarms.
13
13
  */
14
- export function createOfflineInvitationPlugin (invitationFactory: InvitationFactory, peerId: PublicKey) {
15
- return new GreetingCommandPlugin(
16
- peerId.asBuffer(),
17
- OfflineInvitationClaimer.createOfflineInvitationClaimHandler(invitationFactory)
18
- );
19
- }
14
+ export const createOfflineInvitationPlugin = (invitationFactory: InvitationFactory, peerId: PublicKey) => new GreetingCommandPlugin(
15
+ peerId.asBuffer(),
16
+ OfflineInvitationClaimer.createOfflineInvitationClaimHandler(invitationFactory)
17
+ );
@@ -22,12 +22,10 @@ export const createReplicatorPlugin = (feedProvider: PartyFeedProvider) =>
22
22
  return feeds.map((feed) => ({ discoveryKey: feed.feed.discoveryKey }));
23
23
  },
24
24
 
25
- subscribe: (addFeedToReplicatedSet: (feed: any) => void) => {
26
- return feedProvider.feedOpened.on(async (feed) => {
27
- log(`Adding feed: ${feed.key.toHex()}`);
28
- addFeedToReplicatedSet({ discoveryKey: feed.feed.discoveryKey });
29
- });
30
- },
25
+ subscribe: (addFeedToReplicatedSet: (feed: any) => void) => feedProvider.feedOpened.on(async (feed) => {
26
+ log(`Adding feed: ${feed.key.toHex()}`);
27
+ addFeedToReplicatedSet({ discoveryKey: feed.feed.discoveryKey });
28
+ }),
31
29
 
32
30
  replicate: async (remoteFeeds, info) => {
33
31
  // We can ignore remoteFeeds entirely, since the set of feeds we want to replicate is dictated by the Party.
@@ -10,20 +10,16 @@ import { SnapshotStore } from './snapshot-store';
10
10
 
11
11
  const log = debug('dxos:snapshot-generator');
12
12
 
13
- export function createAutomaticSnapshots (
14
- party: PartyCore, clock: TimeframeClock, store: SnapshotStore, interval: number
15
- ) {
16
- return clock.update.on(async timeframe => {
17
- const totalMessages = timeframe.totalMessages();
18
- if (totalMessages > 0 && totalMessages % interval === 0) {
19
- log(`Saving snapshot of ${party.key.humanize()}...`);
20
- try {
21
- const snapshot = party.createSnapshot();
22
- await store.save(snapshot);
23
- } catch (err: any) {
24
- console.error('Failed to save snapshot');
25
- console.error(err);
26
- }
13
+ export const createAutomaticSnapshots = (party: PartyCore, clock: TimeframeClock, store: SnapshotStore, interval: number) => clock.update.on(async timeframe => {
14
+ const totalMessages = timeframe.totalMessages();
15
+ if (totalMessages > 0 && totalMessages % interval === 0) {
16
+ log(`Saving snapshot of ${party.key.humanize()}...`);
17
+ try {
18
+ const snapshot = party.createSnapshot();
19
+ await store.save(snapshot);
20
+ } catch (err: any) {
21
+ console.error('Failed to save snapshot');
22
+ console.error(err);
27
23
  }
28
- });
29
- }
24
+ }
25
+ });
@@ -15,7 +15,7 @@ const createPublicKey = () => PublicKey.from(createKeyPair().publicKey);
15
15
 
16
16
  describe('SnapshotStore', () => {
17
17
  test('in-memory', async () => {
18
- const store = new SnapshotStore(createStorage('snapshots', StorageType.RAM));
18
+ const store = new SnapshotStore(createStorage('', StorageType.RAM).directory('snapshots'));
19
19
 
20
20
  const key1 = createPublicKey();
21
21
  const key2 = createPublicKey();
@@ -7,10 +7,9 @@ import debug from 'debug';
7
7
 
8
8
  import { keyToString } from '@dxos/crypto';
9
9
  import { schema, PartyKey, PartySnapshot } from '@dxos/echo-protocol';
10
- import { Storage } from '@dxos/random-access-multi-storage';
10
+ import { Directory } from '@dxos/random-access-multi-storage';
11
11
 
12
12
  const log = debug('dxos:snapshot-store');
13
-
14
13
  /**
15
14
  * Stores party snapshots. Takes any `random-access-storage` compatible backend.
16
15
  *
@@ -18,11 +17,11 @@ const log = debug('dxos:snapshot-store');
18
17
  */
19
18
  export class SnapshotStore {
20
19
  constructor (
21
- private readonly _storage: Storage
20
+ private readonly _directory: Directory
22
21
  ) {}
23
22
 
24
23
  async load (partyKey: PartyKey): Promise<PartySnapshot | undefined> {
25
- const file = this._storage.createOrOpen(partyKey.toHex());
24
+ const file = this._directory.createOrOpen(partyKey.toHex());
26
25
 
27
26
  try {
28
27
  const { size } = await file.stat();
@@ -45,7 +44,7 @@ export class SnapshotStore {
45
44
 
46
45
  async save (snapshot: PartySnapshot) {
47
46
  assert(snapshot.partyKey);
48
- const file = this._storage.createOrOpen(keyToString(snapshot.partyKey), { truncate: true, size: 0 });
47
+ const file = this._directory.createOrOpen(keyToString(snapshot.partyKey), { truncate: true, size: 0 });
49
48
 
50
49
  try {
51
50
  const data = schema.getCodecForType('dxos.echo.snapshot.PartySnapshot').encode(snapshot);
@@ -60,6 +59,6 @@ export class SnapshotStore {
60
59
  */
61
60
  async clear () {
62
61
  log('Clearing all snapshots..');
63
- await this._storage.destroy();
62
+ await this._directory.destroy();
64
63
  }
65
64
  }
@@ -22,10 +22,10 @@ export type TestPeer = Awaited<ReturnType<typeof createTestInstance>>;
22
22
 
23
23
  export type WithTestMeta<T> = T & { testMeta: TestPeer }
24
24
 
25
- function addTestMeta<T> (obj: T, meta: TestPeer): WithTestMeta<T> {
25
+ const addTestMeta = <T>(obj: T, meta: TestPeer): WithTestMeta<T> => {
26
26
  (obj as any).testMeta = meta;
27
27
  return obj as any;
28
- }
28
+ };
29
29
 
30
30
  /**
31
31
  * Creates a number of test ECHO instances and a party that's shared between all of them.