@dxos/echo-db 2.33.9-dev.7d11f506 → 2.33.9-dev.9bbef4e2

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 (175) hide show
  1. package/dist/src/api/index.d.ts +1 -0
  2. package/dist/src/api/index.d.ts.map +1 -1
  3. package/dist/src/api/index.js +1 -0
  4. package/dist/src/api/index.js.map +1 -1
  5. package/dist/src/api/result-set.js +4 -4
  6. package/dist/src/api/result-set.js.map +1 -1
  7. package/dist/src/api/subscription.d.ts +5 -0
  8. package/dist/src/api/subscription.d.ts.map +1 -0
  9. package/dist/src/api/subscription.js +25 -0
  10. package/dist/src/api/subscription.js.map +1 -0
  11. package/dist/src/echo-api.test.d.ts +2 -0
  12. package/dist/src/echo-api.test.d.ts.map +1 -0
  13. package/dist/src/echo-api.test.js +117 -0
  14. package/dist/src/echo-api.test.js.map +1 -0
  15. package/dist/src/echo.d.ts +3 -4
  16. package/dist/src/echo.d.ts.map +1 -1
  17. package/dist/src/echo.js +6 -8
  18. package/dist/src/echo.js.map +1 -1
  19. package/dist/src/echo.test.js +3 -3
  20. package/dist/src/echo.test.js.map +1 -1
  21. package/dist/src/halo/halo-factory.js +8 -8
  22. package/dist/src/halo/halo-factory.js.map +1 -1
  23. package/dist/src/halo/halo-party.d.ts +2 -2
  24. package/dist/src/halo/halo-party.d.ts.map +1 -1
  25. package/dist/src/halo/halo-party.js +3 -3
  26. package/dist/src/halo/halo-party.js.map +1 -1
  27. package/dist/src/halo/halo.js +9 -9
  28. package/dist/src/halo/halo.js.map +1 -1
  29. package/dist/src/halo/halo.test.js.map +1 -1
  30. package/dist/src/halo/identity-manager.d.ts.map +1 -1
  31. package/dist/src/halo/identity-manager.js +7 -10
  32. package/dist/src/halo/identity-manager.js.map +1 -1
  33. package/dist/src/halo/identity.d.ts +1 -1
  34. package/dist/src/halo/identity.d.ts.map +1 -1
  35. package/dist/src/halo/identity.js +4 -2
  36. package/dist/src/halo/identity.js.map +1 -1
  37. package/dist/src/halo/preferences.d.ts.map +1 -1
  38. package/dist/src/halo/preferences.js +6 -6
  39. package/dist/src/halo/preferences.js.map +1 -1
  40. package/dist/src/invitations/greeting-initiator.js +6 -6
  41. package/dist/src/invitations/greeting-initiator.js.map +1 -1
  42. package/dist/src/invitations/greeting-responder.js +5 -5
  43. package/dist/src/invitations/greeting-responder.js.map +1 -1
  44. package/dist/src/invitations/halo-recovery-initiator.js +6 -6
  45. package/dist/src/invitations/halo-recovery-initiator.js.map +1 -1
  46. package/dist/src/invitations/invitation-descriptor.js +9 -9
  47. package/dist/src/invitations/invitation-descriptor.js.map +1 -1
  48. package/dist/src/invitations/invitation-factory.js +3 -3
  49. package/dist/src/invitations/invitation-factory.js.map +1 -1
  50. package/dist/src/invitations/offline-invitation-claimer.js +7 -7
  51. package/dist/src/invitations/offline-invitation-claimer.js.map +1 -1
  52. package/dist/src/packlets/database/data-mirror.js +8 -8
  53. package/dist/src/packlets/database/data-mirror.js.map +1 -1
  54. package/dist/src/packlets/database/data-service-host.js +3 -3
  55. package/dist/src/packlets/database/data-service-host.js.map +1 -1
  56. package/dist/src/packlets/database/data-service-router.js +5 -5
  57. package/dist/src/packlets/database/data-service-router.js.map +1 -1
  58. package/dist/src/packlets/database/database-backend.js +3 -3
  59. package/dist/src/packlets/database/database-backend.js.map +1 -1
  60. package/dist/src/packlets/database/database.js +2 -2
  61. package/dist/src/packlets/database/database.js.map +1 -1
  62. package/dist/src/packlets/database/item-demuxer.js +14 -14
  63. package/dist/src/packlets/database/item-demuxer.js.map +1 -1
  64. package/dist/src/packlets/database/item-manager.d.ts.map +1 -1
  65. package/dist/src/packlets/database/item-manager.js +18 -18
  66. package/dist/src/packlets/database/item-manager.js.map +1 -1
  67. package/dist/src/packlets/database/link.js +3 -3
  68. package/dist/src/packlets/database/link.js.map +1 -1
  69. package/dist/src/packlets/database/selection/result.js +2 -2
  70. package/dist/src/packlets/database/selection/result.js.map +1 -1
  71. package/dist/src/parties/data-party.d.ts.map +1 -1
  72. package/dist/src/parties/data-party.js +11 -11
  73. package/dist/src/parties/data-party.js.map +1 -1
  74. package/dist/src/parties/data-party.test.js.map +1 -1
  75. package/dist/src/parties/party-factory.d.ts +3 -2
  76. package/dist/src/parties/party-factory.d.ts.map +1 -1
  77. package/dist/src/parties/party-factory.js +4 -4
  78. package/dist/src/parties/party-factory.js.map +1 -1
  79. package/dist/src/parties/party-manager.d.ts +3 -3
  80. package/dist/src/parties/party-manager.d.ts.map +1 -1
  81. package/dist/src/parties/party-manager.js +6 -11
  82. package/dist/src/parties/party-manager.js.map +1 -1
  83. package/dist/src/parties/party-manager.test.js +6 -6
  84. package/dist/src/parties/party-manager.test.js.map +1 -1
  85. package/dist/src/parties/party-preferences.d.ts +1 -1
  86. package/dist/src/parties/party-preferences.d.ts.map +1 -1
  87. package/dist/src/parties/party-preferences.js +5 -5
  88. package/dist/src/parties/party-preferences.js.map +1 -1
  89. package/dist/src/pipeline/feed-muxer.js +3 -3
  90. package/dist/src/pipeline/feed-muxer.js.map +1 -1
  91. package/dist/src/pipeline/feed-muxer.test.js +4 -2
  92. package/dist/src/pipeline/feed-muxer.test.js.map +1 -1
  93. package/dist/src/pipeline/message-selector.js +2 -2
  94. package/dist/src/pipeline/message-selector.js.map +1 -1
  95. package/dist/src/pipeline/metadata-store.d.ts.map +1 -1
  96. package/dist/src/pipeline/metadata-store.js +35 -32
  97. package/dist/src/pipeline/metadata-store.js.map +1 -1
  98. package/dist/src/pipeline/party-feed-provider.js +3 -3
  99. package/dist/src/pipeline/party-feed-provider.js.map +1 -1
  100. package/dist/src/pipeline/party-pipeline.d.ts +3 -1
  101. package/dist/src/pipeline/party-pipeline.d.ts.map +1 -1
  102. package/dist/src/pipeline/party-pipeline.js +20 -18
  103. package/dist/src/pipeline/party-pipeline.js.map +1 -1
  104. package/dist/src/pipeline/party-pipeline.test.js +10 -9
  105. package/dist/src/pipeline/party-pipeline.test.js.map +1 -1
  106. package/dist/src/pipeline/party-processor.js +3 -3
  107. package/dist/src/pipeline/party-processor.js.map +1 -1
  108. package/dist/src/protocol/authenticator.test.js +53 -12
  109. package/dist/src/protocol/authenticator.test.js.map +1 -1
  110. package/dist/src/protocol/identity-credentials.d.ts +0 -1
  111. package/dist/src/protocol/identity-credentials.d.ts.map +1 -1
  112. package/dist/src/protocol/identity-credentials.js.map +1 -1
  113. package/dist/src/protocol/index.d.ts +1 -0
  114. package/dist/src/protocol/index.d.ts.map +1 -1
  115. package/dist/src/protocol/index.js +1 -0
  116. package/dist/src/protocol/index.js.map +1 -1
  117. package/dist/src/protocol/party-protocol-factory.d.ts +1 -1
  118. package/dist/src/protocol/party-protocol-factory.d.ts.map +1 -1
  119. package/dist/src/snapshots/snapshot-store.js +2 -2
  120. package/dist/src/snapshots/snapshot-store.js.map +1 -1
  121. package/dist/src/snapshots/snapshot-store.test.js +5 -1
  122. package/dist/src/snapshots/snapshot-store.test.js.map +1 -1
  123. package/dist/src/testing/testing-factories.js +2 -2
  124. package/dist/src/testing/testing-factories.js.map +1 -1
  125. package/dist/tsconfig.tsbuildinfo +1 -1
  126. package/package.json +21 -17
  127. package/src/api/index.ts +1 -0
  128. package/src/api/result-set.ts +1 -1
  129. package/src/api/subscription.ts +24 -0
  130. package/src/echo-api.test.ts +162 -0
  131. package/src/echo.test.ts +3 -3
  132. package/src/echo.ts +12 -11
  133. package/src/halo/halo-factory.ts +1 -1
  134. package/src/halo/halo-party.ts +4 -4
  135. package/src/halo/halo.test.ts +1 -3
  136. package/src/halo/halo.ts +1 -1
  137. package/src/halo/identity-manager.ts +2 -7
  138. package/src/halo/identity.ts +3 -3
  139. package/src/halo/preferences.ts +2 -1
  140. package/src/invitations/greeting-initiator.ts +1 -1
  141. package/src/invitations/greeting-responder.ts +1 -1
  142. package/src/invitations/halo-recovery-initiator.ts +1 -1
  143. package/src/invitations/invitation-descriptor.ts +1 -1
  144. package/src/invitations/invitation-factory.ts +1 -1
  145. package/src/invitations/offline-invitation-claimer.ts +1 -1
  146. package/src/packlets/database/data-mirror.ts +1 -1
  147. package/src/packlets/database/data-service-host.ts +1 -1
  148. package/src/packlets/database/data-service-router.ts +1 -1
  149. package/src/packlets/database/database-backend.ts +1 -1
  150. package/src/packlets/database/database.ts +1 -1
  151. package/src/packlets/database/item-demuxer.ts +1 -1
  152. package/src/packlets/database/item-manager.ts +6 -6
  153. package/src/packlets/database/link.ts +1 -1
  154. package/src/packlets/database/selection/result.ts +1 -1
  155. package/src/parties/data-party.test.ts +3 -1
  156. package/src/parties/data-party.ts +3 -3
  157. package/src/parties/party-factory.ts +4 -4
  158. package/src/parties/party-manager.test.ts +1 -1
  159. package/src/parties/party-manager.ts +7 -14
  160. package/src/parties/party-preferences.ts +4 -4
  161. package/src/pipeline/feed-muxer.test.ts +4 -2
  162. package/src/pipeline/feed-muxer.ts +1 -1
  163. package/src/pipeline/message-selector.ts +1 -1
  164. package/src/pipeline/metadata-store.ts +38 -29
  165. package/src/pipeline/party-feed-provider.ts +1 -1
  166. package/src/pipeline/party-pipeline.test.ts +3 -2
  167. package/src/pipeline/party-pipeline.ts +10 -7
  168. package/src/pipeline/party-processor.ts +1 -1
  169. package/src/protocol/authenticator.test.ts +102 -17
  170. package/src/protocol/identity-credentials.ts +0 -2
  171. package/src/protocol/index.ts +1 -0
  172. package/src/protocol/party-protocol-factory.ts +1 -1
  173. package/src/snapshots/snapshot-store.test.ts +5 -1
  174. package/src/snapshots/snapshot-store.ts +1 -1
  175. package/src/testing/testing-factories.ts +1 -1
package/package.json CHANGED
@@ -1,31 +1,35 @@
1
1
  {
2
2
  "name": "@dxos/echo-db",
3
- "version": "2.33.9-dev.7d11f506",
3
+ "version": "2.33.9-dev.9bbef4e2",
4
4
  "description": "ECHO database.",
5
5
  "license": "MIT",
6
6
  "main": "dist/src/index.js",
7
7
  "types": "dist/src/index.d.ts",
8
+ "browser": {
9
+ "node:assert": "assert"
10
+ },
8
11
  "files": [
9
12
  "dist",
10
13
  "src"
11
14
  ],
12
15
  "dependencies": {
13
- "@dxos/async": "2.33.9-dev.7d11f506",
14
- "@dxos/codec-protobuf": "2.33.9-dev.7d11f506",
15
- "@dxos/credentials": "2.33.9-dev.7d11f506",
16
- "@dxos/crypto": "2.33.9-dev.7d11f506",
17
- "@dxos/debug": "2.33.9-dev.7d11f506",
18
- "@dxos/echo-protocol": "2.33.9-dev.7d11f506",
19
- "@dxos/feed-store": "2.33.9-dev.7d11f506",
20
- "@dxos/mesh-protocol": "2.33.9-dev.7d11f506",
21
- "@dxos/model-factory": "2.33.9-dev.7d11f506",
22
- "@dxos/network-manager": "2.33.9-dev.7d11f506",
23
- "@dxos/object-model": "2.33.9-dev.7d11f506",
24
- "@dxos/protocol-plugin-presence": "2.33.9-dev.7d11f506",
25
- "@dxos/protocol-plugin-replicator": "2.33.9-dev.7d11f506",
26
- "@dxos/protocols": "2.33.9-dev.7d11f506",
27
- "@dxos/random-access-multi-storage": "2.33.9-dev.7d11f506",
28
- "@dxos/util": "2.33.9-dev.7d11f506",
16
+ "@dxos/async": "2.33.9-dev.9bbef4e2",
17
+ "@dxos/codec-protobuf": "2.33.9-dev.9bbef4e2",
18
+ "@dxos/credentials": "2.33.9-dev.9bbef4e2",
19
+ "@dxos/crypto": "2.33.9-dev.9bbef4e2",
20
+ "@dxos/debug": "2.33.9-dev.9bbef4e2",
21
+ "@dxos/echo-protocol": "2.33.9-dev.9bbef4e2",
22
+ "@dxos/feed-store": "2.33.9-dev.9bbef4e2",
23
+ "@dxos/mesh-protocol": "2.33.9-dev.9bbef4e2",
24
+ "@dxos/model-factory": "2.33.9-dev.9bbef4e2",
25
+ "@dxos/network-manager": "2.33.9-dev.9bbef4e2",
26
+ "@dxos/object-model": "2.33.9-dev.9bbef4e2",
27
+ "@dxos/protocol-plugin-presence": "2.33.9-dev.9bbef4e2",
28
+ "@dxos/protocol-plugin-replicator": "2.33.9-dev.9bbef4e2",
29
+ "@dxos/protocols": "2.33.9-dev.9bbef4e2",
30
+ "@dxos/random-access-multi-storage": "2.33.9-dev.9bbef4e2",
31
+ "@dxos/util": "2.33.9-dev.9bbef4e2",
32
+ "assert": "^2.0.0",
29
33
  "base-x": "~3.0.9",
30
34
  "buffer-json-encoding": "^1.0.2",
31
35
  "debug": "^4.3.3",
package/src/api/index.ts CHANGED
@@ -4,3 +4,4 @@
4
4
 
5
5
  export * from './result-set';
6
6
  export * from './schema';
7
+ export * from './subscription';
@@ -2,7 +2,7 @@
2
2
  // Copyright 2020 DXOS.org
3
3
  //
4
4
 
5
- import assert from 'assert';
5
+ import assert from 'node:assert';
6
6
 
7
7
  import { Event, ReadOnlyEvent } from '@dxos/async';
8
8
 
@@ -0,0 +1,24 @@
1
+ //
2
+ // Copyright 2021 DXOS.org
3
+ //
4
+
5
+ import { Event } from '@dxos/async';
6
+ import { Stream } from '@dxos/codec-protobuf';
7
+
8
+ import { ResultSet } from './result-set';
9
+
10
+ export const resultSetToStream = <T, U>(resultSet: ResultSet<T>, map: (arg: T[]) => U): Stream<U> => new Stream(({ next }) => {
11
+ next(map(resultSet.value));
12
+ return resultSet.update.on(() => next(map(resultSet.value)));
13
+ });
14
+
15
+ export const streamToResultSet = <T, U>(stream: Stream<T>, map: (arg?: T) => U[]): ResultSet<U> => {
16
+ const event = new Event();
17
+ let lastItem: T | undefined;
18
+ stream.subscribe(data => {
19
+ lastItem = data;
20
+ event.emit();
21
+ });
22
+
23
+ return new ResultSet(event, () => map(lastItem));
24
+ };
@@ -0,0 +1,162 @@
1
+ //
2
+ // Copyright 2020 DXOS.org
3
+ //
4
+
5
+ import expect from 'expect';
6
+ import { it as test } from 'mocha';
7
+
8
+ // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy
9
+ // https://javascript.info/proxy
10
+ // https://www.javascripttutorial.net/es6/javascript-proxy
11
+
12
+ // TODO(burdon): Array-specific methods (e.g., push, replace, etc.)
13
+ // http://www.jomendez.com/2018/12/29/querying-arrays-with-more-readable-methods-using-javascript-proxy
14
+ // class ArrayHandler<T> extends Handler {}
15
+
16
+ type Mutation = [property: string, value: any]
17
+
18
+ interface Object {
19
+ // Special properties added by proto generator.
20
+ $id?: string
21
+ $type?: string
22
+ $mutations?: Mutation[]
23
+ }
24
+
25
+ class Handler<T> {
26
+ _mutations: Mutation[] = [];
27
+
28
+ constructor (
29
+ private readonly _parent?: Handler<any>,
30
+ protected readonly _property?: string,
31
+ protected readonly _callback?: (value: T) => void
32
+ ) {}
33
+
34
+ get mutations () {
35
+ return this._mutations;
36
+ }
37
+
38
+ addMutation (mutation: Mutation) {
39
+ if (this._parent) {
40
+ this._parent.addMutation(mutation);
41
+ } else {
42
+ this._mutations.push(mutation);
43
+ }
44
+ }
45
+
46
+ getMeta (p: string) {
47
+ switch (p) {
48
+ case '$mutations': {
49
+ return this._mutations;
50
+ }
51
+ }
52
+ }
53
+ }
54
+
55
+ //
56
+ // TODO(burdon): Generated from proto.
57
+ //
58
+
59
+ interface Contact extends Object {
60
+ name?: {
61
+ first?: string
62
+ last?: string
63
+ }
64
+ age?: number
65
+ emails?: string[]
66
+
67
+ fullname?: string // TODO(burdon): Show how to add custom functions.
68
+ }
69
+
70
+ class ContactNameHandler extends Handler<Contact['name']> {
71
+ get (obj: any, p: string) {
72
+ switch (p) {
73
+ case 'first':
74
+ case 'last': {
75
+ return obj[p];
76
+ }
77
+ }
78
+ }
79
+
80
+ set (obj: any, p: string, value: any) {
81
+ switch (p) {
82
+ case 'first':
83
+ case 'last': {
84
+ this.addMutation([`${this._property}.${p}`, value]);
85
+ obj[p] = value;
86
+ this._callback?.(obj);
87
+ return true;
88
+ }
89
+ }
90
+
91
+ return false;
92
+ }
93
+ }
94
+
95
+ class ContactHandler extends Handler<Contact> {
96
+ get (obj: any, p: string) {
97
+ const result = super.getMeta(p);
98
+ if (result !== undefined) {
99
+ return result;
100
+ }
101
+
102
+ switch (p) {
103
+ case 'name': {
104
+ return new Proxy(obj[p] ?? {}, new ContactNameHandler(this, p, value => {
105
+ obj[p] = value;
106
+ }));
107
+ }
108
+ }
109
+
110
+ return obj[p];
111
+ }
112
+
113
+ set (obj: any, p: string, value: any) {
114
+ this.addMutation([p, value]);
115
+ obj[p] = value;
116
+ return true; // Throws TypeError if false.
117
+ }
118
+ }
119
+
120
+ type ItemType<T extends object> = [string, () => Handler<T>]
121
+
122
+ const ContactType: ItemType<Contact> = ['example.Contact', () => new ContactHandler()];
123
+
124
+ class Database {
125
+ private readonly _types = new Map<ItemType<any>, (value: any) => typeof Proxy>();
126
+
127
+ addType (type: ItemType<any>, constructor: (value: any) => any) {
128
+ this._types.set(type, constructor);
129
+ return this;
130
+ }
131
+
132
+ create<T extends object> (type: ItemType<T>, value: T = {} as T): T {
133
+ const constructor = this._types.get(type)!;
134
+ return constructor(value) as any;
135
+ }
136
+ }
137
+
138
+ describe('API', () => {
139
+ test('Pseudo-code', () => {
140
+ const db = new Database();
141
+ db.addType(ContactType, value => new Proxy<Contact>(value, new ContactHandler()));
142
+
143
+ // Create type-safe proxy.
144
+ const item = db.create(ContactType);
145
+
146
+ item.age = 64;
147
+ expect(item.$mutations).toHaveLength(1);
148
+ expect(item).toEqual({ age: 64 });
149
+
150
+ item.name!.first = 'Alice';
151
+ expect(item.name?.first).toBe('Alice');
152
+ expect(item.$mutations).toHaveLength(2);
153
+ expect(item).toEqual({ age: 64, name: { first: 'Alice' } });
154
+
155
+ expect(item.$mutations).toStrictEqual([
156
+ ['age', 64],
157
+ ['name.first', 'Alice']
158
+ ]);
159
+
160
+ // TODO(burdon): Get item id, state, mutations, etc.
161
+ });
162
+ });
package/src/echo.test.ts CHANGED
@@ -2,10 +2,10 @@
2
2
  // Copyright 2020 DXOS.org
3
3
  //
4
4
 
5
- import assert from 'assert';
6
5
  import debug from 'debug';
7
6
  import expect from 'expect';
8
7
  import { it as test } from 'mocha';
8
+ import assert from 'node:assert';
9
9
 
10
10
  import { latch, promiseTimeout, waitForCondition } from '@dxos/async';
11
11
  import {
@@ -31,8 +31,8 @@ describe('ECHO', () => {
31
31
 
32
32
  const setup = async ({ createProfile, displayName }: SetupOptions = {}) => {
33
33
  const echo = new ECHO();
34
-
35
34
  await echo.open();
35
+
36
36
  afterTest(() => echo.close());
37
37
 
38
38
  if (createProfile) {
@@ -374,7 +374,7 @@ describe('ECHO', () => {
374
374
 
375
375
  }).timeout(10_000);
376
376
 
377
- test.skip('3 devices', async () => {
377
+ test('3 devices', async () => {
378
378
  const a = await setup({ createProfile: true });
379
379
  const b = await setup();
380
380
 
package/src/echo.ts CHANGED
@@ -2,9 +2,9 @@
2
2
  // Copyright 2020 DXOS.org
3
3
  //
4
4
 
5
- import assert from 'assert';
6
5
  import debug from 'debug';
7
6
  import memdown from 'memdown';
7
+ import assert from 'node:assert';
8
8
 
9
9
  import { synchronized } from '@dxos/async';
10
10
  import { Keyring, KeyStore, SecretProvider } from '@dxos/credentials';
@@ -25,7 +25,7 @@ import { InvitationDescriptor, OfflineInvitationClaimer } from './invitations';
25
25
  import { DataServiceRouter } from './packlets/database';
26
26
  import { IdentityNotInitializedError, InvalidStorageVersionError } from './packlets/errors';
27
27
  import { OpenProgress, PartyFactory, DataParty, PartyManager } from './parties';
28
- import { MetadataStore, STORAGE_VERSION, PartyFeedProvider } from './pipeline';
28
+ import { STORAGE_VERSION, MetadataStore, PartyFeedProvider } from './pipeline';
29
29
  import { SnapshotStore } from './snapshots';
30
30
 
31
31
  const log = debug('dxos:echo');
@@ -85,18 +85,19 @@ export interface EchoCreationOptions {
85
85
  * Messages are streamed into the pipeline (from the `FeedStore`) in logical order, determined by the
86
86
  * `Timeframe` (which implements a vector clock).
87
87
  */
88
- // TODO(burdon): Create ECHOError class for public errors.
89
88
  export class ECHO {
90
- private readonly _halo: HALO;
91
89
  private readonly _keyring: Keyring;
92
90
 
91
+ // TODO(burdon): Factor out.
92
+ private readonly _halo: HALO;
93
+ private readonly _partyManager: PartyManager;
94
+ private readonly _subscriptions = new SubscriptionGroup();
95
+
93
96
  private readonly _storage: Storage;
94
97
  private readonly _feedStore: FeedStore;
95
98
  private readonly _modelFactory: ModelFactory;
96
99
  private readonly _networkManager: NetworkManager;
97
100
  private readonly _snapshotStore: SnapshotStore;
98
- private readonly _partyManager: PartyManager;
99
- private readonly _subs = new SubscriptionGroup();
100
101
  private readonly _metadataStore: MetadataStore;
101
102
  private readonly _dataServiceRouter: DataServiceRouter;
102
103
 
@@ -153,7 +154,7 @@ export class ECHO {
153
154
  this._partyManager = new PartyManager(
154
155
  this._metadataStore,
155
156
  this._snapshotStore,
156
- () => this.halo.identity,
157
+ () => this._halo.identity,
157
158
  partyFactory
158
159
  );
159
160
 
@@ -170,7 +171,7 @@ export class ECHO {
170
171
  this._halo.identityReady.once(() => {
171
172
  // It might be the case that halo gets closed before this has a chance to execute.
172
173
  if (this.halo.identity?.halo.isOpen) {
173
- this._subs.push(autoPartyOpener(this.halo.identity.preferences!, this._partyManager));
174
+ this._subscriptions.push(autoPartyOpener(this.halo.identity.preferences!, this._partyManager));
174
175
  }
175
176
  });
176
177
 
@@ -260,7 +261,7 @@ export class ECHO {
260
261
  return;
261
262
  }
262
263
 
263
- this._subs.unsubscribe();
264
+ this._subscriptions.unsubscribe();
264
265
 
265
266
  await this.halo.close();
266
267
 
@@ -272,7 +273,6 @@ export class ECHO {
272
273
 
273
274
  /**
274
275
  * Removes all data and closes this ECHO instance.
275
- *
276
276
  * The instance will be in an unusable state at this point and a page refresh is recommended.
277
277
  */
278
278
  // TODO(burdon): Enable re-open.
@@ -371,7 +371,8 @@ export class ECHO {
371
371
  assert(this._partyManager.isOpen, new InvalidStateError());
372
372
 
373
373
  const actualSecretProvider =
374
- secretProvider ?? OfflineInvitationClaimer.createSecretProvider(this.halo.identity?.createCredentialsSigner() ?? raise(new IdentityNotInitializedError()));
374
+ secretProvider ?? OfflineInvitationClaimer.createSecretProvider(this.halo.identity?.createCredentialsSigner() ??
375
+ raise(new IdentityNotInitializedError()));
375
376
 
376
377
  return this._partyManager.joinParty(invitationDescriptor, actualSecretProvider);
377
378
  }
@@ -2,8 +2,8 @@
2
2
  // Copyright 2020 DXOS.org
3
3
  //
4
4
 
5
- import assert from 'assert';
6
5
  import debug from 'debug';
6
+ import assert from 'node:assert';
7
7
 
8
8
  import {
9
9
  createDeviceInfoMessage,
@@ -2,7 +2,7 @@
2
2
  // Copyright 2020 DXOS.org
3
3
  //
4
4
 
5
- import assert from 'assert';
5
+ import assert from 'node:assert';
6
6
 
7
7
  import { Event, synchronized } from '@dxos/async';
8
8
  import { timed } from '@dxos/debug';
@@ -28,9 +28,9 @@ export const HALO_PARTY_DEVICE_PREFERENCES_TYPE = 'dxos:item/halo/device/prefere
28
28
  /**
29
29
  * A record in HALO party representing a party that user is currently a member of.
30
30
  */
31
- export interface JoinedParty {
32
- partyKey: PublicKey,
33
- genesisFeed: PublicKey,
31
+ export type JoinedParty = {
32
+ partyKey: PublicKey
33
+ genesisFeed: PublicKey
34
34
  }
35
35
 
36
36
  /**
@@ -5,9 +5,7 @@
5
5
  import expect from 'expect';
6
6
  import { it as test } from 'mocha';
7
7
 
8
- import {
9
- defaultSecretProvider, generateSeedPhrase, keyPairFromSeedPhrase, Keyring
10
- } from '@dxos/credentials';
8
+ import { defaultSecretProvider, generateSeedPhrase, keyPairFromSeedPhrase, Keyring } from '@dxos/credentials';
11
9
  import { codec } from '@dxos/echo-protocol';
12
10
  import { FeedStore } from '@dxos/feed-store';
13
11
  import { ModelFactory } from '@dxos/model-factory';
package/src/halo/halo.ts CHANGED
@@ -2,8 +2,8 @@
2
2
  // Copyright 2021 DXOS.org
3
3
  //
4
4
 
5
- import assert from 'assert';
6
5
  import debug from 'debug';
6
+ import assert from 'node:assert';
7
7
 
8
8
  import { synchronized } from '@dxos/async';
9
9
  import { KeyRecord, Keyring, KeyType, SecretProvider } from '@dxos/credentials';
@@ -2,8 +2,8 @@
2
2
  // Copyright 2020 DXOS.org
3
3
  //
4
4
 
5
- import assert from 'assert';
6
5
  import debug from 'debug';
6
+ import assert from 'node:assert';
7
7
 
8
8
  import { Event, synchronized, waitForCondition } from '@dxos/async';
9
9
  import { Filter, KeyRecord, Keyring, KeyType, SecretProvider } from '@dxos/credentials';
@@ -39,15 +39,10 @@ export class IdentityManager {
39
39
  assert(halo.isOpen, 'HALO must be open.');
40
40
 
41
41
  // Wait for the minimum set of keys and messages we need for proper function:
42
- //
43
42
  // - KeyAdmit message for the current device so we can build the device KeyChain.
44
43
  // - Identity genesis so it can be copied into newly joined parties.
45
- //
46
44
  const deviceKey = this._keyring.findKey(Keyring.signingFilter({ type: KeyType.DEVICE })) ?? failUndefined();
47
- await waitForCondition(() =>
48
- halo.processor.isMemberKey(deviceKey.publicKey) &&
49
- halo.identityGenesis
50
- );
45
+ await waitForCondition(() => halo.processor.isMemberKey(deviceKey.publicKey) && halo.identityGenesis);
51
46
 
52
47
  this._identity = new Identity(this._keyring, halo);
53
48
  this.ready.emit();
@@ -2,8 +2,8 @@
2
2
  // Copyright 2021 DXOS.org
3
3
  //
4
4
 
5
- import assert from 'assert';
6
5
  import debug from 'debug';
6
+ import assert from 'node:assert';
7
7
 
8
8
  import { Filter, KeyChain, KeyRecord, Keyring, KeyType, SignedMessage, Signer } from '@dxos/credentials';
9
9
  import { failUndefined } from '@dxos/debug';
@@ -27,6 +27,7 @@ export class Identity implements IdentityCredentials {
27
27
  private readonly _deviceKeyChain: KeyChain;
28
28
 
29
29
  /**
30
+ * @param _keyring
30
31
  * @param _halo HALO party. Must be open.
31
32
  */
32
33
  constructor (
@@ -86,6 +87,7 @@ export class Identity implements IdentityCredentials {
86
87
  /**
87
88
  * HALO party. Must be open.
88
89
  */
90
+ // TODO(burdon): Remove.
89
91
  get halo (): HaloParty {
90
92
  return this._halo;
91
93
  }
@@ -100,8 +102,6 @@ export class Identity implements IdentityCredentials {
100
102
  }
101
103
  }
102
104
 
103
- export type IdentityProvider = () => Identity | undefined;
104
-
105
105
  const getDeviceKeyChainFromHalo = (halo: HaloParty, deviceKey: KeyRecord) => {
106
106
  try {
107
107
  return Keyring.buildKeyChain(
@@ -2,9 +2,9 @@
2
2
  // Copyright 2020 DXOS.org
3
3
  //
4
4
 
5
- import assert from 'assert';
6
5
  import stableStringify from 'json-stable-stringify';
7
6
  import defaultsDeep from 'lodash.defaultsdeep';
7
+ import assert from 'node:assert';
8
8
 
9
9
  import { Event } from '@dxos/async';
10
10
  import { raise } from '@dxos/debug';
@@ -139,6 +139,7 @@ export class Preferences {
139
139
  if (!database) {
140
140
  return;
141
141
  }
142
+
142
143
  const [partyDesc] = database
143
144
  .select({ type: HALO_PARTY_DESCRIPTOR_TYPE })
144
145
  .filter(partyMarker => joinedParty.partyKey.equals(partyMarker.model.get('publicKey')))
@@ -2,8 +2,8 @@
2
2
  // Copyright 2020 DXOS.org
3
3
  //
4
4
 
5
- import assert from 'assert';
6
5
  import debug from 'debug';
6
+ import assert from 'node:assert';
7
7
 
8
8
  import { waitForEvent } from '@dxos/async';
9
9
  import {
@@ -2,8 +2,8 @@
2
2
  // Copyright 2020 DXOS.org
3
3
  //
4
4
 
5
- import assert from 'assert';
6
5
  import debug from 'debug';
6
+ import assert from 'node:assert';
7
7
 
8
8
  import { Event, waitForCondition } from '@dxos/async';
9
9
  import {
@@ -2,8 +2,8 @@
2
2
  // Copyright 2020 DXOS.org
3
3
  //
4
4
 
5
- import assert from 'assert';
6
5
  import debug from 'debug';
6
+ import assert from 'node:assert';
7
7
 
8
8
  import { waitForEvent } from '@dxos/async';
9
9
  import {
@@ -2,9 +2,9 @@
2
2
  // Copyright 2020 DXOS.org
3
3
  //
4
4
 
5
- import assert from 'assert';
6
5
  import base from 'base-x';
7
6
  import stableStringify from 'json-stable-stringify';
7
+ import assert from 'node:assert';
8
8
 
9
9
  import { ripemd160 } from '@dxos/crypto';
10
10
  import { SwarmKey } from '@dxos/echo-protocol';
@@ -2,7 +2,7 @@
2
2
  // Copyright 2020 DXOS.org
3
3
  //
4
4
 
5
- import assert from 'assert';
5
+ import assert from 'node:assert';
6
6
 
7
7
  import { createPartyInvitationMessage, Message as HaloMessage } from '@dxos/credentials';
8
8
  import { FeedWriter } from '@dxos/echo-protocol';
@@ -2,8 +2,8 @@
2
2
  // Copyright 2020 DXOS.org
3
3
  //
4
4
 
5
- import assert from 'assert';
6
5
  import debug from 'debug';
6
+ import assert from 'node:assert';
7
7
 
8
8
  import { waitForEvent } from '@dxos/async';
9
9
  import {
@@ -2,8 +2,8 @@
2
2
  // Copyright 2021 DXOS.org
3
3
  //
4
4
 
5
- import assert from 'assert';
6
5
  import debug from 'debug';
6
+ import assert from 'node:assert';
7
7
 
8
8
  import { failUndefined } from '@dxos/debug';
9
9
  import { DataService } from '@dxos/echo-protocol';
@@ -2,8 +2,8 @@
2
2
  // Copyright 2021 DXOS.org
3
3
  //
4
4
 
5
- import assert from 'assert';
6
5
  import debug from 'debug';
6
+ import assert from 'node:assert';
7
7
 
8
8
  import { Stream } from '@dxos/codec-protobuf';
9
9
  import { failUndefined, raise } from '@dxos/debug';
@@ -2,8 +2,8 @@
2
2
  // Copyright 2021 DXOS.org
3
3
  //
4
4
 
5
- import assert from 'assert';
6
5
  import debug from 'debug';
6
+ import assert from 'node:assert';
7
7
 
8
8
  import { Stream } from '@dxos/codec-protobuf';
9
9
  import { raise } from '@dxos/debug';
@@ -2,8 +2,8 @@
2
2
  // Copyright 2021 DXOS.org
3
3
  //
4
4
 
5
- import assert from 'assert';
6
5
  import debug from 'debug';
6
+ import assert from 'node:assert';
7
7
 
8
8
  import { DatabaseSnapshot, DataService, EchoEnvelope, FeedWriter, PartyKey } from '@dxos/echo-protocol';
9
9
  import { ModelFactory } from '@dxos/model-factory';
@@ -2,7 +2,7 @@
2
2
  // Copyright 2020 DXOS.org
3
3
  //
4
4
 
5
- import assert from 'assert';
5
+ import assert from 'node:assert';
6
6
 
7
7
  import { Event, synchronized } from '@dxos/async';
8
8
  import { ItemID, ItemType } from '@dxos/echo-protocol';
@@ -2,8 +2,8 @@
2
2
  // Copyright 2020 DXOS.org
3
3
  //
4
4
 
5
- import assert from 'assert';
6
5
  import debug from 'debug';
6
+ import assert from 'node:assert';
7
7
 
8
8
  import { Event } from '@dxos/async';
9
9
  import { failUndefined } from '@dxos/debug';
@@ -2,8 +2,8 @@
2
2
  // Copyright 2020 DXOS.org
3
3
  //
4
4
 
5
- import assert from 'assert';
6
5
  import debug from 'debug';
6
+ import assert from 'node:assert';
7
7
 
8
8
  import { Event, trigger } from '@dxos/async';
9
9
  import { createId } from '@dxos/crypto';
@@ -26,14 +26,14 @@ export interface ModelConstructionOptions {
26
26
  }
27
27
 
28
28
  export interface ItemConstructionOptions extends ModelConstructionOptions {
29
- itemType: ItemType | undefined,
30
- parentId?: ItemID,
29
+ itemType: ItemType | undefined
30
+ parentId?: ItemID
31
31
  }
32
32
 
33
33
  export interface LinkConstructionOptions extends ModelConstructionOptions {
34
- itemType: ItemType | undefined,
35
- source: ItemID;
36
- target: ItemID;
34
+ itemType: ItemType | undefined
35
+ source: ItemID
36
+ target: ItemID
37
37
  }
38
38
 
39
39
  /**