@dxos/client 2.28.2-dev.8a42e72c → 2.28.2-dev.f37dd5ce

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 (31) hide show
  1. package/dist/src/api/echo-proxy.d.ts +8 -3
  2. package/dist/src/api/echo-proxy.d.ts.map +1 -1
  3. package/dist/src/api/echo-proxy.js +10 -4
  4. package/dist/src/api/echo-proxy.js.map +1 -1
  5. package/dist/src/api/halo-proxy.d.ts +12 -7
  6. package/dist/src/api/halo-proxy.d.ts.map +1 -1
  7. package/dist/src/api/halo-proxy.js +17 -6
  8. package/dist/src/api/halo-proxy.js.map +1 -1
  9. package/dist/src/api/invitations/invitation-proxy.d.ts +1 -1
  10. package/dist/src/api/invitations/invitation-proxy.d.ts.map +1 -1
  11. package/dist/src/api/invitations/invitation-proxy.js.map +1 -1
  12. package/dist/src/api/party-proxy.d.ts +15 -4
  13. package/dist/src/api/party-proxy.d.ts.map +1 -1
  14. package/dist/src/api/party-proxy.js +21 -6
  15. package/dist/src/api/party-proxy.js.map +1 -1
  16. package/dist/src/client/client.d.ts +3 -1
  17. package/dist/src/client/client.d.ts.map +1 -1
  18. package/dist/src/client/client.js +1 -1
  19. package/dist/src/client/client.js.map +1 -1
  20. package/dist/src/client/service-host/service-host.d.ts +1 -1
  21. package/dist/src/client/service-host/service-host.d.ts.map +1 -1
  22. package/dist/src/client/service-host/service-host.js +1 -1
  23. package/dist/src/client/service-host/service-host.js.map +1 -1
  24. package/dist/tsconfig.tsbuildinfo +1 -1
  25. package/package.json +17 -17
  26. package/src/api/echo-proxy.ts +15 -7
  27. package/src/api/halo-proxy.ts +22 -12
  28. package/src/api/invitations/invitation-proxy.ts +1 -1
  29. package/src/api/party-proxy.ts +25 -9
  30. package/src/client/client.ts +3 -3
  31. package/src/client/service-host/service-host.ts +2 -2
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dxos/client",
3
- "version": "2.28.2-dev.8a42e72c",
3
+ "version": "2.28.2-dev.f37dd5ce",
4
4
  "license": "MIT",
5
5
  "author": "DXOS.org",
6
6
  "main": "dist/src/index.js",
@@ -10,21 +10,21 @@
10
10
  "src"
11
11
  ],
12
12
  "dependencies": {
13
- "@dxos/async": "2.28.2-dev.8a42e72c",
14
- "@dxos/codec-protobuf": "2.28.2-dev.8a42e72c",
15
- "@dxos/config": "2.28.2-dev.8a42e72c",
16
- "@dxos/credentials": "2.28.2-dev.8a42e72c",
17
- "@dxos/crypto": "2.28.2-dev.8a42e72c",
18
- "@dxos/debug": "2.28.2-dev.8a42e72c",
19
- "@dxos/echo-db": "2.28.2-dev.8a42e72c",
20
- "@dxos/echo-protocol": "2.28.2-dev.8a42e72c",
21
- "@dxos/feed-store": "2.28.2-dev.8a42e72c",
22
- "@dxos/model-factory": "2.28.2-dev.8a42e72c",
23
- "@dxos/network-manager": "2.28.2-dev.8a42e72c",
24
- "@dxos/object-model": "2.28.2-dev.8a42e72c",
25
- "@dxos/protocols": "2.28.2-dev.8a42e72c",
26
- "@dxos/rpc": "2.28.2-dev.8a42e72c",
27
- "@dxos/util": "2.28.2-dev.8a42e72c",
13
+ "@dxos/async": "2.28.2-dev.f37dd5ce",
14
+ "@dxos/codec-protobuf": "2.28.2-dev.f37dd5ce",
15
+ "@dxos/config": "2.28.2-dev.f37dd5ce",
16
+ "@dxos/credentials": "2.28.2-dev.f37dd5ce",
17
+ "@dxos/crypto": "2.28.2-dev.f37dd5ce",
18
+ "@dxos/debug": "2.28.2-dev.f37dd5ce",
19
+ "@dxos/echo-db": "2.28.2-dev.f37dd5ce",
20
+ "@dxos/echo-protocol": "2.28.2-dev.f37dd5ce",
21
+ "@dxos/feed-store": "2.28.2-dev.f37dd5ce",
22
+ "@dxos/model-factory": "2.28.2-dev.f37dd5ce",
23
+ "@dxos/network-manager": "2.28.2-dev.f37dd5ce",
24
+ "@dxos/object-model": "2.28.2-dev.f37dd5ce",
25
+ "@dxos/protocols": "2.28.2-dev.f37dd5ce",
26
+ "@dxos/rpc": "2.28.2-dev.f37dd5ce",
27
+ "@dxos/util": "2.28.2-dev.f37dd5ce",
28
28
  "@polkadot/keyring": "6.11.1",
29
29
  "@polkadot/util": "6.11.1",
30
30
  "@polkadot/util-crypto": "6.11.1",
@@ -41,7 +41,7 @@
41
41
  "uuid": "^8.3.2"
42
42
  },
43
43
  "devDependencies": {
44
- "@dxos/random-access-multi-storage": "2.28.2-dev.8a42e72c",
44
+ "@dxos/random-access-multi-storage": "2.28.2-dev.f37dd5ce",
45
45
  "@dxos/testutils": "2.28.1",
46
46
  "@dxos/toolchain-node-library": "2.28.1",
47
47
  "@types/debug": "^4.1.7",
@@ -28,17 +28,21 @@ export class PartyInvitation extends Invitation<Party> {
28
28
  }
29
29
  }
30
30
 
31
+ /**
32
+ * Client proxy to local/remote ECHO service.
33
+ */
31
34
  export class EchoProxy {
32
- private readonly _modelFactory: ModelFactory;
33
- private _parties = new ComplexMap<PublicKey, Party>(key => key.toHex());
35
+ private readonly _parties = new ComplexMap<PublicKey, Party>(key => key.toHex());
34
36
  private readonly _partiesChanged = new Event();
35
37
  private readonly _subscriptions = new SubscriptionGroup();
38
+ private readonly _modelFactory: ModelFactory;
36
39
 
37
40
  constructor (
38
41
  private readonly _serviceProvider: ClientServiceProvider,
39
42
  private readonly _haloProxy: HaloProxy
40
43
  ) {
41
- this._modelFactory = _serviceProvider instanceof ClientServiceHost ? _serviceProvider.echo.modelFactory : new ModelFactory();
44
+ this._modelFactory = _serviceProvider instanceof ClientServiceHost
45
+ ? _serviceProvider.echo.modelFactory : new ModelFactory();
42
46
 
43
47
  this._modelFactory.registerModel(ObjectModel); // Register object-model by default.
44
48
  }
@@ -55,11 +59,13 @@ export class EchoProxy {
55
59
  }
56
60
 
57
61
  toString () {
58
- return 'EchoProxy';
62
+ return `EchoProxy(${JSON.stringify(this.info())})`;
59
63
  }
60
64
 
61
65
  info () {
62
- return this.toString();
66
+ return {
67
+ parties: this._parties.size
68
+ };
63
69
  }
64
70
 
65
71
  /**
@@ -99,6 +105,7 @@ export class EchoProxy {
99
105
  }
100
106
  this._partiesChanged.emit();
101
107
  }, () => {});
108
+
102
109
  this._subscriptions.push(() => partiesStream.close());
103
110
 
104
111
  await gotParties;
@@ -112,7 +119,7 @@ export class EchoProxy {
112
119
  await party.destroy();
113
120
  }
114
121
 
115
- this._subscriptions.unsubscribe();
122
+ await this._subscriptions.unsubscribe();
116
123
  }
117
124
 
118
125
  //
@@ -178,7 +185,8 @@ export class EchoProxy {
178
185
  * To be used with `party.createInvitation` on the inviter side.
179
186
  */
180
187
  acceptInvitation (invitationDescriptor: InvitationDescriptor): PartyInvitation {
181
- const invitationProcessStream = this._serviceProvider.services.PartyService.acceptInvitation(invitationDescriptor.toProto());
188
+ const invitationProcessStream = this._serviceProvider.services.PartyService.acceptInvitation(
189
+ invitationDescriptor.toProto());
182
190
  const { authenticate, waitForFinish } = InvitationProxy.handleInvitationRedemption({
183
191
  stream: invitationProcessStream,
184
192
  invitationDescriptor,
@@ -4,32 +4,42 @@
4
4
 
5
5
  import { Event } from '@dxos/async';
6
6
  import { KeyRecord } from '@dxos/credentials';
7
- import { Contact, CreateProfileOptions, InvitationDescriptor, InvitationOptions, PartyMember, ResultSet } from '@dxos/echo-db';
7
+ import { Contact, CreateProfileOptions, InvitationDescriptor, PartyMember, ResultSet } from '@dxos/echo-db';
8
8
  import { SubscriptionGroup } from '@dxos/util';
9
9
 
10
10
  import { ClientServiceProvider } from '../interfaces';
11
11
  import { Profile, SignRequest } from '../proto/gen/dxos/client';
12
12
  import { Invitation, InvitationProxy, InvitationRequest } from './invitations';
13
13
 
14
- export interface CreateInvitationOptions extends InvitationOptions {
15
- onPinGenerated?: (pin: string) => void
16
- }
14
+ /**
15
+ * Client proxy to local/remote HALO service.
16
+ */
17
+ export class HaloProxy {
18
+ private readonly _invitationProxy = new InvitationProxy();
19
+ private readonly _subscriptions = new SubscriptionGroup();
17
20
 
18
- export class HaloProxy extends InvitationProxy {
19
21
  private _profile?: Profile;
20
22
  private _contacts: PartyMember[] = [];
21
23
 
22
- public readonly profileChanged = new Event();
23
24
  private readonly _contactsChanged = new Event();
25
+ public readonly profileChanged = new Event();
24
26
 
25
- private readonly _subscriptions = new SubscriptionGroup();
27
+ constructor (
28
+ private readonly _serviceProvider: ClientServiceProvider
29
+ ) {}
30
+
31
+ toString () {
32
+ return `HaloProxy(${JSON.stringify(this.info())})`;
33
+ }
26
34
 
27
- constructor (private readonly _serviceProvider: ClientServiceProvider) {
28
- super();
35
+ info () {
36
+ return {
37
+ key: this._profile?.publicKey
38
+ };
29
39
  }
30
40
 
31
- override toString () {
32
- return `HaloProxy(${this._profile?.publicKey})`;
41
+ get invitationProxy () {
42
+ return this._invitationProxy;
33
43
  }
34
44
 
35
45
  /**
@@ -87,7 +97,7 @@ export class HaloProxy extends InvitationProxy {
87
97
  */
88
98
  async createInvitation (): Promise<InvitationRequest> {
89
99
  const stream = await this._serviceProvider.services.ProfileService.createInvitation();
90
- return this.createInvitationRequest({ stream });
100
+ return this._invitationProxy.createInvitationRequest({ stream });
91
101
  }
92
102
 
93
103
  /**
@@ -32,7 +32,7 @@ export class InvitationProxy {
32
32
  readonly activeInvitations: InvitationRequest[] = [];
33
33
  readonly invitationsUpdate = new Event();
34
34
 
35
- protected async createInvitationRequest ({ stream }: CreateInvitationRequestOpts): Promise<InvitationRequest> {
35
+ async createInvitationRequest ({ stream }: CreateInvitationRequestOpts): Promise<InvitationRequest> {
36
36
  return new Promise((resolve, reject) => {
37
37
  const connected = new Event();
38
38
  const finished = new Event();
@@ -5,7 +5,7 @@
5
5
  import { PublicKey } from '@dxos/crypto';
6
6
  import { failUndefined } from '@dxos/debug';
7
7
  import {
8
- ActivationOptions, Database, PARTY_ITEM_TYPE, PARTY_TITLE_PROPERTY, RemoteDatabaseBackend, RootSelector
8
+ PARTY_ITEM_TYPE, PARTY_TITLE_PROPERTY, ActivationOptions, Database, RemoteDatabaseBackend
9
9
  } from '@dxos/echo-db';
10
10
  import { PartyKey } from '@dxos/echo-protocol';
11
11
  import { ModelFactory } from '@dxos/model-factory';
@@ -21,8 +21,13 @@ export interface CreationInvitationOptions {
21
21
  inviteeKey?: PublicKey
22
22
  }
23
23
 
24
- export class Party extends InvitationProxy {
24
+ /**
25
+ * Main public Party API.
26
+ * Proxies requests to local/remove services.
27
+ */
28
+ export class Party {
25
29
  private readonly _database?: Database;
30
+ private readonly _invitationProxy = new InvitationProxy();
26
31
 
27
32
  private _key: PartyKey;
28
33
  private _isOpen: boolean;
@@ -37,11 +42,9 @@ export class Party extends InvitationProxy {
37
42
  party: PartyProto,
38
43
  memberKey: PublicKey
39
44
  ) {
40
- super();
41
45
  this._key = party.publicKey;
42
46
  this._isOpen = party.isOpen;
43
47
  this._isActive = party.isActive;
44
-
45
48
  if (!party.isOpen) {
46
49
  return;
47
50
  }
@@ -60,6 +63,10 @@ export class Party extends InvitationProxy {
60
63
  }
61
64
  }
62
65
 
66
+ get invitationProxy () {
67
+ return this._invitationProxy;
68
+ }
69
+
63
70
  async init () {
64
71
  if (this._database && this._serviceProvider instanceof ClientServiceProxy) {
65
72
  await this._database.init();
@@ -130,10 +137,17 @@ export class Party extends InvitationProxy {
130
137
  /**
131
138
  * Returns a selection context, which can be used to traverse the object graph.
132
139
  */
133
- get select (): RootSelector {
140
+ get select (): Database['select'] {
134
141
  return this.database.select.bind(this.database);
135
142
  }
136
143
 
144
+ /**
145
+ * Returns a selection context, which can be used to traverse the object graph.
146
+ */
147
+ get reduce (): Database['reduce'] {
148
+ return this.database.reduce.bind(this.database);
149
+ }
150
+
137
151
  /**
138
152
  * Creates an invitation to a given party.
139
153
  * The Invitation flow requires the inviter and invitee to be online at the same time.
@@ -142,11 +156,12 @@ export class Party extends InvitationProxy {
142
156
  *
143
157
  * To be used with `client.echo.acceptInvitation` on the invitee side.
144
158
  *
145
- * @param inviteeKey Public key of the invitee. In this case no secret exchange is required, but only the specified recipient can accept the invitation.
159
+ * @param inviteeKey Public key of the invitee. In this case no secret exchange is required,
160
+ * but only the specified recipient can accept the invitation.
146
161
  */
147
162
  async createInvitation ({ inviteeKey }: CreationInvitationOptions = {}): Promise<InvitationRequest> {
148
163
  const stream = this._serviceProvider.services.PartyService.createInvitation({ partyKey: this.key, inviteeKey });
149
- return this.createInvitationRequest({ stream });
164
+ return this._invitationProxy.createInvitationRequest({ stream });
150
165
  }
151
166
 
152
167
  queryMembers () {
@@ -156,8 +171,9 @@ export class Party extends InvitationProxy {
156
171
  );
157
172
  }
158
173
 
159
- setTitle (title: string) {
160
- return this.setProperty(PARTY_TITLE_PROPERTY, title);
174
+ async setTitle (title: string) {
175
+ await this.setProperty(PARTY_TITLE_PROPERTY, title);
176
+ return this;
161
177
  }
162
178
 
163
179
  async setProperty (key: string, value?: any) {
@@ -55,9 +55,9 @@ export class Client {
55
55
 
56
56
  private readonly _config: Config;
57
57
  private readonly _options: ClientOptions;
58
+
58
59
  private readonly _mode: Runtime.Client.Mode;
59
60
  private _serviceProvider!: ClientServiceProvider;
60
-
61
61
  private _halo!: HaloProxy;
62
62
  private _echo!: EchoProxy;
63
63
 
@@ -71,14 +71,14 @@ export class Client {
71
71
  if (typeof config !== 'object' || config == null) {
72
72
  throw new InvalidParameterError('Invalid config.');
73
73
  }
74
+
74
75
  this._config = (config instanceof Config) ? config : new Config(config);
76
+ this._options = options;
75
77
 
76
78
  if (Object.keys(this._config.values).length > 0 && this._config.values.version !== EXPECTED_CONFIG_VERSION) {
77
79
  throw new InvalidConfigurationError(`Expected config version 1, got ${this._config.values.version}.`);
78
80
  }
79
81
 
80
- this._options = options;
81
-
82
82
  // TODO(burdon): Default error level: 'dxos:*:error'
83
83
  // TODO(burdon): config.getProperty('system.debug', process.env.DEBUG, '');
84
84
  debug.enable(this._config.values.runtime?.client?.debug ?? process.env.DEBUG ?? 'dxos:*:error');
@@ -3,7 +3,7 @@
3
3
  //
4
4
 
5
5
  import { Config } from '@dxos/config';
6
- import * as debug from '@dxos/debug'; // TODO(burdon): ???
6
+ import * as debug from '@dxos/debug'; // TODO(burdon): Why import *?
7
7
  import { ECHO, OpenProgress } from '@dxos/echo-db';
8
8
 
9
9
  import { createDevtoolsHost, DevtoolsHostEvents, DevtoolsServiceDependencies } from '../../devtools';
@@ -13,8 +13,8 @@ import { createServices } from './services';
13
13
  import { createStorageObjects } from './storage';
14
14
 
15
15
  export class ClientServiceHost implements ClientServiceProvider {
16
- private readonly _echo: ECHO;
17
16
  private readonly _devtoolsEvents = new DevtoolsHostEvents();
17
+ private readonly _echo: ECHO;
18
18
 
19
19
  constructor (
20
20
  private readonly _config: Config