@dxos/client 2.23.1-dev.f5b1145e → 2.24.1-dev.4c2329ab
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/src/api/echo-proxy.d.ts +7 -7
- package/dist/src/api/echo-proxy.d.ts.map +1 -1
- package/dist/src/api/echo-proxy.js +1 -1
- package/dist/src/api/echo-proxy.js.map +1 -1
- package/dist/src/api/halo-proxy.d.ts +1 -6
- package/dist/src/api/halo-proxy.d.ts.map +1 -1
- package/dist/src/api/halo-proxy.js +1 -10
- package/dist/src/api/halo-proxy.js.map +1 -1
- package/dist/src/api/party-proxy.d.ts +1 -5
- package/dist/src/api/party-proxy.d.ts.map +1 -1
- package/dist/src/api/party-proxy.js +6 -3
- package/dist/src/api/party-proxy.js.map +1 -1
- package/dist/src/client/client.d.ts +5 -5
- package/dist/src/client/client.d.ts.map +1 -1
- package/dist/src/client/client.js +16 -8
- package/dist/src/client/client.js.map +1 -1
- package/dist/src/client/client.test.js +11 -8
- package/dist/src/client/client.test.js.map +1 -1
- package/dist/src/client/local-client.test.js +8 -5
- package/dist/src/client/local-client.test.js.map +1 -1
- package/dist/src/client/service-host/service-host.js +5 -5
- package/dist/src/client/service-host/service-host.js.map +1 -1
- package/dist/src/client/service-host/services/party.d.ts.map +1 -1
- package/dist/src/client/service-host/services/party.js +4 -4
- package/dist/src/client/service-host/services/party.js.map +1 -1
- package/dist/src/client/service-host/services/profile.d.ts +1 -4
- package/dist/src/client/service-host/services/profile.d.ts.map +1 -1
- package/dist/src/index.d.ts +1 -0
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +12 -1
- package/dist/src/index.js.map +1 -1
- package/dist/src/proto/gen/dxos/halo/keys.d.ts +2 -1
- package/dist/src/proto/gen/dxos/halo/keys.d.ts.map +1 -1
- package/dist/src/proto/gen/dxos/halo/keys.js +1 -0
- package/dist/src/proto/gen/dxos/halo/keys.js.map +1 -1
- package/dist/src/proto/gen/index.d.ts.map +1 -1
- package/dist/src/proto/gen/index.js +1 -1
- package/dist/src/proto/gen/index.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +19 -19
- package/src/api/echo-proxy.ts +9 -9
- package/src/api/halo-proxy.ts +1 -12
- package/src/api/party-proxy.ts +7 -4
- package/src/client/client.test.ts +13 -10
- package/src/client/client.ts +19 -9
- package/src/client/local-client.test.ts +10 -7
- package/src/client/service-host/service-host.ts +6 -6
- package/src/client/service-host/services/party.ts +6 -6
- package/src/index.ts +15 -0
- package/src/proto/gen/dxos/halo/keys.ts +2 -1
- package/src/proto/gen/index.ts +1 -1
package/src/api/party-proxy.ts
CHANGED
|
@@ -13,7 +13,7 @@ import { ModelFactory } from '@dxos/model-factory';
|
|
|
13
13
|
import { ClientServiceHost } from '../client/service-host';
|
|
14
14
|
import { ClientServiceProxy } from '../client/service-proxy';
|
|
15
15
|
import { ClientServiceProvider } from '../interfaces';
|
|
16
|
-
import { Party } from '../proto/gen/dxos/client';
|
|
16
|
+
import { Party as PartyProto } from '../proto/gen/dxos/client';
|
|
17
17
|
import { streamToResultSet } from '../util';
|
|
18
18
|
import { InvitationRequest, InvitationProxy } from './invitations';
|
|
19
19
|
|
|
@@ -21,17 +21,20 @@ export interface CreationInvitationOptions {
|
|
|
21
21
|
inviteeKey?: PublicKey
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
export class
|
|
24
|
+
export class Party extends InvitationProxy {
|
|
25
25
|
private readonly _database?: Database;
|
|
26
26
|
|
|
27
27
|
private _key: PartyKey;
|
|
28
28
|
private _isOpen: boolean;
|
|
29
29
|
private _isActive: boolean;
|
|
30
30
|
|
|
31
|
+
/**
|
|
32
|
+
* @internal
|
|
33
|
+
*/
|
|
31
34
|
constructor (
|
|
32
35
|
private _serviceProvider: ClientServiceProvider,
|
|
33
36
|
private _modelFactory: ModelFactory,
|
|
34
|
-
_party:
|
|
37
|
+
_party: PartyProto
|
|
35
38
|
) {
|
|
36
39
|
super();
|
|
37
40
|
this._key = _party.publicKey;
|
|
@@ -72,7 +75,7 @@ export class PartyProxy extends InvitationProxy {
|
|
|
72
75
|
* Called by EchoProxy to update this party instance.
|
|
73
76
|
* @internal
|
|
74
77
|
*/
|
|
75
|
-
_processPartyUpdate (party:
|
|
78
|
+
_processPartyUpdate (party: PartyProto) {
|
|
76
79
|
this._key = party.publicKey;
|
|
77
80
|
this._isOpen = party.isOpen;
|
|
78
81
|
this._isActive = party.isActive;
|
|
@@ -7,7 +7,7 @@ import expect from 'expect';
|
|
|
7
7
|
import { it as test } from 'mocha';
|
|
8
8
|
|
|
9
9
|
import { sleep, waitForCondition } from '@dxos/async';
|
|
10
|
-
import {
|
|
10
|
+
import { ConfigV1Object } from '@dxos/config';
|
|
11
11
|
import { generateSeedPhrase, keyPairFromSeedPhrase } from '@dxos/crypto';
|
|
12
12
|
import { throwUnhandledRejection } from '@dxos/debug';
|
|
13
13
|
import { InvitationDescriptor } from '@dxos/echo-db';
|
|
@@ -61,10 +61,10 @@ describe('Client', () => {
|
|
|
61
61
|
afterTest(() => client.destroy());
|
|
62
62
|
|
|
63
63
|
await client.halo.createProfile({ username: 'test-user' });
|
|
64
|
-
expect(client.halo.
|
|
64
|
+
expect(!!client.halo.profile).toBeTruthy();
|
|
65
65
|
|
|
66
66
|
await expect(client.halo.createProfile({ username: 'test-user' })).rejects.toThrow();
|
|
67
|
-
expect(client.halo.
|
|
67
|
+
expect(!!client.halo.profile).toBeTruthy();
|
|
68
68
|
});
|
|
69
69
|
|
|
70
70
|
test('Recovers a profile with a seed phrase', async () => {
|
|
@@ -87,7 +87,7 @@ describe('Client', () => {
|
|
|
87
87
|
afterTest(() => recoveredClient.destroy());
|
|
88
88
|
|
|
89
89
|
await recoveredClient.halo.recoverProfile(seedPhrase);
|
|
90
|
-
await waitForCondition(() => !!recoveredClient.halo.
|
|
90
|
+
await waitForCondition(() => !!recoveredClient.halo.profile, 2000);
|
|
91
91
|
|
|
92
92
|
expect(recoveredClient.halo.profile).toBeDefined();
|
|
93
93
|
expect(recoveredClient.halo.profile!.publicKey).toEqual(client.halo.profile!.publicKey);
|
|
@@ -276,11 +276,14 @@ describe('Client', () => {
|
|
|
276
276
|
});
|
|
277
277
|
|
|
278
278
|
test('late-register models after refresh', async () => {
|
|
279
|
-
const config:
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
279
|
+
const config: ConfigV1Object = {
|
|
280
|
+
version: 1,
|
|
281
|
+
runtime: {
|
|
282
|
+
client: {
|
|
283
|
+
storage: {
|
|
284
|
+
persistent: true,
|
|
285
|
+
path: `/tmp/dxos-${Date.now()}`
|
|
286
|
+
}
|
|
284
287
|
}
|
|
285
288
|
}
|
|
286
289
|
};
|
|
@@ -300,7 +303,7 @@ describe('Client', () => {
|
|
|
300
303
|
{
|
|
301
304
|
const client = new Client(config);
|
|
302
305
|
await client.initialize();
|
|
303
|
-
await waitForCondition(() => client.halo.
|
|
306
|
+
await waitForCondition(() => !!client.halo.profile);
|
|
304
307
|
await sleep(10); // Make sure all events were processed.
|
|
305
308
|
|
|
306
309
|
client.registerModel(TestModel);
|
package/src/client/client.ts
CHANGED
|
@@ -6,7 +6,7 @@ import assert from 'assert';
|
|
|
6
6
|
import debug from 'debug';
|
|
7
7
|
|
|
8
8
|
import { synchronized } from '@dxos/async';
|
|
9
|
-
import { Config,
|
|
9
|
+
import { Config, ConfigV1Object } from '@dxos/config';
|
|
10
10
|
import { InvalidParameterError, TimeoutError } from '@dxos/debug';
|
|
11
11
|
import { OpenProgress, sortItemsTopologically } from '@dxos/echo-db';
|
|
12
12
|
import { DatabaseSnapshot } from '@dxos/echo-protocol';
|
|
@@ -17,6 +17,7 @@ import { RpcPort } from '@dxos/rpc';
|
|
|
17
17
|
import { EchoProxy, HaloProxy } from '../api';
|
|
18
18
|
import { DevtoolsHook } from '../devtools';
|
|
19
19
|
import { ClientServiceProvider, ClientServices, RemoteServiceConnectionTimeout } from '../interfaces';
|
|
20
|
+
import { InvalidConfigurationError } from '../interfaces/errors';
|
|
20
21
|
import { System } from '../proto/gen/dxos/config';
|
|
21
22
|
import { createWindowMessagePort, isNode } from '../util';
|
|
22
23
|
import { ClientServiceHost } from './service-host';
|
|
@@ -24,12 +25,17 @@ import { ClientServiceProxy } from './service-proxy';
|
|
|
24
25
|
|
|
25
26
|
const log = debug('dxos:client');
|
|
26
27
|
|
|
27
|
-
|
|
28
|
+
const EXPECTED_CONFIG_VERSION = 1;
|
|
28
29
|
|
|
29
|
-
export const
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
30
|
+
export const defaultConfig: ConfigV1Object = { version: 1 };
|
|
31
|
+
|
|
32
|
+
export const defaultTestingConfig: ConfigV1Object = {
|
|
33
|
+
version: 1,
|
|
34
|
+
runtime: {
|
|
35
|
+
services: {
|
|
36
|
+
signal: {
|
|
37
|
+
server: 'ws://localhost:4000'
|
|
38
|
+
}
|
|
33
39
|
}
|
|
34
40
|
}
|
|
35
41
|
};
|
|
@@ -63,19 +69,23 @@ export class Client {
|
|
|
63
69
|
* Creates the client object based on supplied configuration.
|
|
64
70
|
* Requires initialization after creating by calling `.initialize()`.
|
|
65
71
|
*/
|
|
66
|
-
constructor (config:
|
|
72
|
+
constructor (config: ConfigV1Object | Config = { version: 1 }, options: ClientOptions = {}) {
|
|
67
73
|
if (typeof config !== 'object' || config == null) {
|
|
68
74
|
throw new InvalidParameterError('Invalid config.');
|
|
69
75
|
}
|
|
70
76
|
this._config = (config instanceof Config) ? config : new Config(config);
|
|
71
77
|
|
|
78
|
+
if (Object.keys(this._config.values).length > 0 && this._config.values.version !== EXPECTED_CONFIG_VERSION) {
|
|
79
|
+
throw new InvalidConfigurationError(`Expected config version 1, got ${this._config.values.version}.`);
|
|
80
|
+
}
|
|
81
|
+
|
|
72
82
|
this._options = options;
|
|
73
83
|
|
|
74
84
|
// TODO(burdon): Default error level: 'dxos:*:error'
|
|
75
85
|
// TODO(burdon): config.getProperty('system.debug', process.env.DEBUG, '');
|
|
76
|
-
debug.enable(this._config.values.system?.debug ?? process.env.DEBUG ?? 'dxos:*:error');
|
|
86
|
+
debug.enable(this._config.values.runtime?.system?.debug ?? process.env.DEBUG ?? 'dxos:*:error');
|
|
77
87
|
|
|
78
|
-
this._mode = this._config.get('
|
|
88
|
+
this._mode = this._config.get('runtime.client.mode', System.Mode.AUTOMATIC)!;
|
|
79
89
|
log(`mode=${System.Mode[this._mode]}`);
|
|
80
90
|
}
|
|
81
91
|
|
|
@@ -6,7 +6,7 @@ import expect from 'expect';
|
|
|
6
6
|
import { it as test } from 'mocha';
|
|
7
7
|
|
|
8
8
|
import { waitForCondition } from '@dxos/async';
|
|
9
|
-
import {
|
|
9
|
+
import { ConfigV1Object } from '@dxos/config';
|
|
10
10
|
|
|
11
11
|
import { Client } from './client';
|
|
12
12
|
|
|
@@ -31,11 +31,14 @@ describe('Client', () => {
|
|
|
31
31
|
|
|
32
32
|
describe('With persistent storage', () => {
|
|
33
33
|
test('persistent storage', async () => {
|
|
34
|
-
const config:
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
34
|
+
const config: ConfigV1Object = {
|
|
35
|
+
version: 1,
|
|
36
|
+
runtime: {
|
|
37
|
+
client: {
|
|
38
|
+
storage: {
|
|
39
|
+
persistent: true,
|
|
40
|
+
path: `/tmp/dxos-${Date.now()}`
|
|
41
|
+
}
|
|
39
42
|
}
|
|
40
43
|
}
|
|
41
44
|
};
|
|
@@ -54,7 +57,7 @@ describe('Client', () => {
|
|
|
54
57
|
{
|
|
55
58
|
const client = new Client(config);
|
|
56
59
|
await client.initialize();
|
|
57
|
-
await waitForCondition(() => client.halo.
|
|
60
|
+
await waitForCondition(() => !!client.halo.profile);
|
|
58
61
|
|
|
59
62
|
expect(client.halo.profile).toBeDefined();
|
|
60
63
|
await client.destroy();
|
|
@@ -20,8 +20,8 @@ export class ClientServiceHost implements ClientServiceProvider {
|
|
|
20
20
|
private readonly _config: Config
|
|
21
21
|
) {
|
|
22
22
|
const { feedStorage, keyStorage, snapshotStorage, metadataStorage } = createStorageObjects(
|
|
23
|
-
this._config.get('
|
|
24
|
-
this._config.get('
|
|
23
|
+
this._config.get('runtime.client.storage', {})!,
|
|
24
|
+
this._config.get('runtime.client.enableSnapshots', false)
|
|
25
25
|
);
|
|
26
26
|
|
|
27
27
|
this._echo = new ECHO({
|
|
@@ -30,12 +30,12 @@ export class ClientServiceHost implements ClientServiceProvider {
|
|
|
30
30
|
snapshotStorage,
|
|
31
31
|
metadataStorage,
|
|
32
32
|
networkManagerOptions: {
|
|
33
|
-
signal: this._config.get('services.signal.server') ? [this._config.get('services.signal.server')!] : undefined,
|
|
34
|
-
ice: this._config.get('services.ice'),
|
|
33
|
+
signal: this._config.get('runtime.services.signal.server') ? [this._config.get('runtime.services.signal.server')!] : undefined,
|
|
34
|
+
ice: this._config.get('runtime.services.ice'),
|
|
35
35
|
log: true
|
|
36
36
|
},
|
|
37
|
-
snapshots: this._config.get('
|
|
38
|
-
snapshotInterval: this._config.get('
|
|
37
|
+
snapshots: this._config.get('runtime.client.enableSnapshots', false),
|
|
38
|
+
snapshotInterval: this._config.get('runtime.client.snapshotInterval')
|
|
39
39
|
});
|
|
40
40
|
|
|
41
41
|
this.services = {
|
|
@@ -8,8 +8,8 @@ import { v4 } from 'uuid';
|
|
|
8
8
|
import { latch } from '@dxos/async';
|
|
9
9
|
import { Stream } from '@dxos/codec-protobuf';
|
|
10
10
|
import { defaultSecretValidator, generatePasscode, SecretProvider } from '@dxos/credentials';
|
|
11
|
-
import { raise } from '@dxos/debug';
|
|
12
|
-
import { ECHO,
|
|
11
|
+
import { InvalidStateError, raise } from '@dxos/debug';
|
|
12
|
+
import { ECHO, InvitationDescriptor, InvitationDescriptorType, PartyNotFoundError } from '@dxos/echo-db';
|
|
13
13
|
|
|
14
14
|
import {
|
|
15
15
|
InvitationState,
|
|
@@ -50,7 +50,7 @@ class PartyService implements IPartyService {
|
|
|
50
50
|
}
|
|
51
51
|
});
|
|
52
52
|
} catch (error) {
|
|
53
|
-
if (error instanceof
|
|
53
|
+
if (error instanceof InvalidStateError) {
|
|
54
54
|
// Do nothing.
|
|
55
55
|
} else {
|
|
56
56
|
throw error;
|
|
@@ -156,7 +156,7 @@ class PartyService implements IPartyService {
|
|
|
156
156
|
next({ state: InvitationState.CONNECTED });
|
|
157
157
|
return Buffer.from(secret);
|
|
158
158
|
};
|
|
159
|
-
invitation = await party.createInvitation({
|
|
159
|
+
invitation = await party.invitationManager.createInvitation({
|
|
160
160
|
secretProvider,
|
|
161
161
|
secretValidator: defaultSecretValidator
|
|
162
162
|
}, {
|
|
@@ -169,7 +169,7 @@ class PartyService implements IPartyService {
|
|
|
169
169
|
assert(invitation.type === InvitationDescriptorType.INTERACTIVE);
|
|
170
170
|
invitation.secret = Buffer.from(secret);
|
|
171
171
|
} else {
|
|
172
|
-
invitation = await party.createOfflineInvitation(request.inviteeKey);
|
|
172
|
+
invitation = await party.invitationManager.createOfflineInvitation(request.inviteeKey);
|
|
173
173
|
}
|
|
174
174
|
|
|
175
175
|
next({ state: InvitationState.WAITING_FOR_CONNECTION, descriptor: invitation.toProto() });
|
|
@@ -256,7 +256,7 @@ class PartyService implements IPartyService {
|
|
|
256
256
|
}
|
|
257
257
|
}
|
|
258
258
|
|
|
259
|
-
CreateSnapshot (request: CreateSnaspotRequest): Promise<PartySnapshot> {
|
|
259
|
+
async CreateSnapshot (request: CreateSnaspotRequest): Promise<PartySnapshot> {
|
|
260
260
|
assert(request.partyKey);
|
|
261
261
|
const party = this.echo.getParty(request.partyKey) ?? raise(new PartyNotFoundError(request.partyKey));
|
|
262
262
|
return party.createSnapshot();
|
package/src/index.ts
CHANGED
|
@@ -9,3 +9,18 @@ export * from './devtools/devtools-context';
|
|
|
9
9
|
export * from './devtools/devtools-host-events';
|
|
10
10
|
export * from './util';
|
|
11
11
|
export * as proto from './proto/gen';
|
|
12
|
+
|
|
13
|
+
export {
|
|
14
|
+
Entity,
|
|
15
|
+
Item,
|
|
16
|
+
Link,
|
|
17
|
+
Database,
|
|
18
|
+
Selection,
|
|
19
|
+
SelectionResult,
|
|
20
|
+
InvitationDescriptor,
|
|
21
|
+
InvitationDescriptorType,
|
|
22
|
+
OpenProgress,
|
|
23
|
+
PartyMember,
|
|
24
|
+
ResultSet,
|
|
25
|
+
PARTY_ITEM_TYPE
|
|
26
|
+
} from '@dxos/echo-db';
|