@dxos/client 2.31.7-dev.3c7d6556 → 2.31.8-dev.613ef955
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/client.d.ts +5 -2
- package/dist/src/api/client.d.ts.map +1 -1
- package/dist/src/api/client.js +8 -8
- package/dist/src/api/client.js.map +1 -1
- package/dist/src/api/client.test.js +6 -2
- package/dist/src/api/client.test.js.map +1 -1
- package/dist/src/api/proxies/echo-proxy.d.ts +4 -2
- package/dist/src/api/proxies/echo-proxy.d.ts.map +1 -1
- package/dist/src/api/proxies/echo-proxy.js +8 -3
- package/dist/src/api/proxies/echo-proxy.js.map +1 -1
- package/dist/src/api/proxies/halo-proxy.d.ts +3 -3
- package/dist/src/api/proxies/halo-proxy.d.ts.map +1 -1
- package/dist/src/api/proxies/halo-proxy.js +3 -3
- package/dist/src/api/proxies/halo-proxy.js.map +1 -1
- package/dist/src/api/proxies/party-proxy.d.ts.map +1 -1
- package/dist/src/api/proxies/party-proxy.js +1 -0
- package/dist/src/api/proxies/party-proxy.js.map +1 -1
- package/dist/src/devtools/network.d.ts.map +1 -1
- package/dist/src/devtools/network.js.map +1 -1
- package/dist/src/proto/gen/google/protobuf.d.ts +5 -5
- package/dist/src/proto/gen/google/protobuf.d.ts.map +1 -1
- package/dist/src/proto/gen/google/protobuf.js.map +1 -1
- package/dist/src/version.d.ts +1 -1
- package/dist/src/version.js +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +20 -19
- package/src/api/client.test.ts +10 -7
- package/src/api/client.ts +11 -9
- package/src/api/proxies/echo-proxy.ts +12 -5
- package/src/api/proxies/halo-proxy.ts +4 -4
- package/src/api/proxies/party-proxy.ts +2 -0
- package/src/devtools/network.ts +1 -0
- package/src/proto/gen/google/protobuf.ts +5 -5
- package/src/version.ts +1 -1
package/src/api/client.test.ts
CHANGED
|
@@ -21,6 +21,9 @@ import { clientServiceBundle } from '../services';
|
|
|
21
21
|
import { Client } from './client';
|
|
22
22
|
|
|
23
23
|
describe('Client', () => {
|
|
24
|
+
//
|
|
25
|
+
// Suite is called for local and remote client configurations.
|
|
26
|
+
//
|
|
24
27
|
function testSuite (createClient: () => Promise<Client>) {
|
|
25
28
|
describe('initialization', () => {
|
|
26
29
|
test('initialize and destroy', async () => {
|
|
@@ -49,10 +52,8 @@ describe('Client', () => {
|
|
|
49
52
|
afterTest(() => client.destroy());
|
|
50
53
|
|
|
51
54
|
const profile = await client.halo.createProfile({ username: 'test-user' });
|
|
52
|
-
|
|
53
55
|
expect(profile).toBeDefined();
|
|
54
56
|
expect(profile?.username).toEqual('test-user');
|
|
55
|
-
|
|
56
57
|
expect(client.halo.profile).toBeDefined();
|
|
57
58
|
}).timeout(500);
|
|
58
59
|
|
|
@@ -77,10 +78,8 @@ describe('Client', () => {
|
|
|
77
78
|
const keyPair = keyPairFromSeedPhrase(seedPhrase);
|
|
78
79
|
|
|
79
80
|
const profile = await client.halo.createProfile({ ...keyPair, username: 'test-user' });
|
|
80
|
-
|
|
81
81
|
expect(profile).toBeDefined();
|
|
82
82
|
expect(profile?.username).toEqual('test-user');
|
|
83
|
-
|
|
84
83
|
expect(client.halo.profile).toBeDefined();
|
|
85
84
|
|
|
86
85
|
const recoveredClient = await createClient();
|
|
@@ -119,7 +118,6 @@ describe('Client', () => {
|
|
|
119
118
|
const invitation = await party.createInvitation();
|
|
120
119
|
invitation.error.on(throwUnhandledRejection);
|
|
121
120
|
const inviteeParty = await invitee.echo.acceptInvitation(invitation.descriptor).getParty();
|
|
122
|
-
|
|
123
121
|
expect(inviteeParty.key).toEqual(party.key);
|
|
124
122
|
|
|
125
123
|
const members = party.queryMembers().value;
|
|
@@ -289,6 +287,7 @@ describe('Client', () => {
|
|
|
289
287
|
handlers: hostClient.services,
|
|
290
288
|
port: hostPort
|
|
291
289
|
});
|
|
290
|
+
|
|
292
291
|
void server.open(); // This blocks until the other client connects.
|
|
293
292
|
afterTest(() => server.close());
|
|
294
293
|
|
|
@@ -296,6 +295,8 @@ describe('Client', () => {
|
|
|
296
295
|
});
|
|
297
296
|
});
|
|
298
297
|
|
|
298
|
+
// TODO(burdon): Factor out tests.
|
|
299
|
+
|
|
299
300
|
test('late-register models after refresh', async () => {
|
|
300
301
|
const config: ConfigObject = {
|
|
301
302
|
version: 1,
|
|
@@ -312,12 +313,14 @@ describe('Client', () => {
|
|
|
312
313
|
{
|
|
313
314
|
const client = new Client(config);
|
|
314
315
|
await client.initialize();
|
|
315
|
-
client.registerModel(TestModel);
|
|
316
|
+
client.echo.registerModel(TestModel);
|
|
316
317
|
// TODO(burdon): Better error if halo is not created.
|
|
317
318
|
await client.halo.createProfile({ username: 'test-user' });
|
|
318
319
|
const party = await client.echo.createParty();
|
|
320
|
+
|
|
319
321
|
const item = await party.database.createItem({ model: TestModel, type: 'test' });
|
|
320
322
|
await item.model.set('prop', 'value1');
|
|
323
|
+
|
|
321
324
|
await client.destroy();
|
|
322
325
|
}
|
|
323
326
|
|
|
@@ -327,7 +330,7 @@ describe('Client', () => {
|
|
|
327
330
|
await waitForCondition(() => !!client.halo.profile);
|
|
328
331
|
await sleep(10); // Make sure all events were processed.
|
|
329
332
|
|
|
330
|
-
client.registerModel(TestModel);
|
|
333
|
+
client.echo.registerModel(TestModel);
|
|
331
334
|
|
|
332
335
|
const party = client.echo.queryParties().first;
|
|
333
336
|
const result = party.database.select({ type: 'test' }).exec();
|
package/src/api/client.ts
CHANGED
|
@@ -58,19 +58,20 @@ export class Client {
|
|
|
58
58
|
|
|
59
59
|
private readonly _config: Config;
|
|
60
60
|
private readonly _options: ClientOptions;
|
|
61
|
-
|
|
62
61
|
private readonly _mode: Runtime.Client.Mode;
|
|
62
|
+
|
|
63
63
|
private _serviceProvider!: ClientServiceProvider;
|
|
64
64
|
private _halo!: HaloProxy;
|
|
65
65
|
private _echo!: EchoProxy;
|
|
66
|
-
|
|
67
66
|
private _initialized = false;
|
|
68
67
|
|
|
68
|
+
// TODO(burdon): Expose some kind of stable ID (e.g., from HALO).
|
|
69
|
+
|
|
69
70
|
/**
|
|
70
71
|
* Creates the client object based on supplied configuration.
|
|
71
72
|
* Requires initialization after creating by calling `.initialize()`.
|
|
72
73
|
*/
|
|
73
|
-
// TODO(burdon):
|
|
74
|
+
// TODO(burdon): What are the defaults if `{}` is passed?
|
|
74
75
|
constructor (config: ConfigObject | Config = defaultConfig, options: ClientOptions = {}) {
|
|
75
76
|
if (typeof config !== 'object' || config == null) {
|
|
76
77
|
throw new InvalidParameterError('Invalid config.');
|
|
@@ -80,12 +81,12 @@ export class Client {
|
|
|
80
81
|
this._options = options;
|
|
81
82
|
|
|
82
83
|
if (Object.keys(this._config.values).length > 0 && this._config.values.version !== EXPECTED_CONFIG_VERSION) {
|
|
83
|
-
throw new InvalidConfigurationError(
|
|
84
|
+
throw new InvalidConfigurationError(
|
|
85
|
+
`Invalid config version: ${this._config.values.version} !== ${EXPECTED_CONFIG_VERSION}]`);
|
|
84
86
|
}
|
|
85
87
|
|
|
86
|
-
// TODO(burdon):
|
|
87
|
-
//
|
|
88
|
-
debug.enable(this._config.values.runtime?.client?.debug ?? process.env.DEBUG ?? 'dxos:*:error');
|
|
88
|
+
// TODO(burdon): Library should not set app-level globals.
|
|
89
|
+
// debug.enable(this._config.values.runtime?.client?.debug ?? process.env.DEBUG ?? 'dxos:*:error');
|
|
89
90
|
|
|
90
91
|
this._mode = this._config.get('runtime.client.mode', Runtime.Client.Mode.AUTOMATIC)!;
|
|
91
92
|
log(`mode=${Runtime.Client.Mode[this._mode]}`);
|
|
@@ -98,7 +99,8 @@ export class Client {
|
|
|
98
99
|
info () {
|
|
99
100
|
return {
|
|
100
101
|
initialized: this.initialized,
|
|
101
|
-
echo: this.echo.info()
|
|
102
|
+
echo: this.echo.info(),
|
|
103
|
+
halo: this.halo.info()
|
|
102
104
|
};
|
|
103
105
|
}
|
|
104
106
|
|
|
@@ -245,6 +247,7 @@ export class Client {
|
|
|
245
247
|
|
|
246
248
|
/**
|
|
247
249
|
* Registers a new ECHO model.
|
|
250
|
+
* @deprecated
|
|
248
251
|
*/
|
|
249
252
|
registerModel (constructor: ModelConstructor<any>): this {
|
|
250
253
|
this._echo.modelFactory.registerModel(constructor);
|
|
@@ -254,7 +257,6 @@ export class Client {
|
|
|
254
257
|
/**
|
|
255
258
|
* Returns devtools context.
|
|
256
259
|
* Used by the DXOS DevTool Extension.
|
|
257
|
-
*
|
|
258
260
|
* This is what gets assigned to `window.__DXOS__` global.
|
|
259
261
|
*/
|
|
260
262
|
getDevtoolsContext (): DevtoolsHook {
|
|
@@ -9,7 +9,7 @@ import { PublicKey } from '@dxos/crypto';
|
|
|
9
9
|
import { failUndefined } from '@dxos/debug';
|
|
10
10
|
import { InvitationDescriptor, PARTY_ITEM_TYPE, ResultSet } from '@dxos/echo-db';
|
|
11
11
|
import { PartyKey, PartySnapshot } from '@dxos/echo-protocol';
|
|
12
|
-
import { ModelFactory } from '@dxos/model-factory';
|
|
12
|
+
import { ModelConstructor, ModelFactory } from '@dxos/model-factory';
|
|
13
13
|
import { ObjectModel } from '@dxos/object-model';
|
|
14
14
|
import { ComplexMap, SubscriptionGroup } from '@dxos/util';
|
|
15
15
|
|
|
@@ -33,6 +33,7 @@ export class PartyInvitation extends Invitation<Party> {
|
|
|
33
33
|
// TODO(burdon): Separate public API form implementation (move comments here).
|
|
34
34
|
export interface Echo {
|
|
35
35
|
info (): { parties: number }
|
|
36
|
+
registerModel (constructor: ModelConstructor<any>): void
|
|
36
37
|
createParty (): Promise<Party>
|
|
37
38
|
cloneParty (snapshot: PartySnapshot): Promise<Party>
|
|
38
39
|
getParty (partyKey: PartyKey): Party | undefined
|
|
@@ -59,6 +60,10 @@ export class EchoProxy implements Echo {
|
|
|
59
60
|
this._modelFactory.registerModel(ObjectModel); // Register object-model by default.
|
|
60
61
|
}
|
|
61
62
|
|
|
63
|
+
toString () {
|
|
64
|
+
return `EchoProxy(${JSON.stringify(this.info())})`;
|
|
65
|
+
}
|
|
66
|
+
|
|
62
67
|
get modelFactory (): ModelFactory {
|
|
63
68
|
return this._modelFactory;
|
|
64
69
|
}
|
|
@@ -71,16 +76,18 @@ export class EchoProxy implements Echo {
|
|
|
71
76
|
throw new Error('Network Manager not available in service proxy.');
|
|
72
77
|
}
|
|
73
78
|
|
|
74
|
-
|
|
75
|
-
return `EchoProxy(${JSON.stringify(this.info())})`;
|
|
76
|
-
}
|
|
77
|
-
|
|
79
|
+
// TODO(burdon): Client ID?
|
|
78
80
|
info () {
|
|
79
81
|
return {
|
|
80
82
|
parties: this._parties.size
|
|
81
83
|
};
|
|
82
84
|
}
|
|
83
85
|
|
|
86
|
+
registerModel (constructor: ModelConstructor<any>): this {
|
|
87
|
+
this._modelFactory.registerModel(constructor);
|
|
88
|
+
return this;
|
|
89
|
+
}
|
|
90
|
+
|
|
84
91
|
/**
|
|
85
92
|
* @internal
|
|
86
93
|
*/
|
|
@@ -48,12 +48,12 @@ export class HaloProxy implements Halo {
|
|
|
48
48
|
private readonly _invitationProxy = new InvitationProxy();
|
|
49
49
|
private readonly _subscriptions = new SubscriptionGroup();
|
|
50
50
|
|
|
51
|
+
private readonly _contactsChanged = new Event();
|
|
52
|
+
public readonly profileChanged = new Event(); // TODO(burdon): Move into Profile object.
|
|
53
|
+
|
|
51
54
|
private _profile?: Profile;
|
|
52
55
|
private _contacts: PartyMember[] = [];
|
|
53
56
|
|
|
54
|
-
private readonly _contactsChanged = new Event();
|
|
55
|
-
public readonly profileChanged = new Event();
|
|
56
|
-
|
|
57
57
|
constructor (
|
|
58
58
|
private readonly _serviceProvider: ClientServiceProvider
|
|
59
59
|
) {}
|
|
@@ -74,7 +74,7 @@ export class HaloProxy implements Halo {
|
|
|
74
74
|
|
|
75
75
|
/**
|
|
76
76
|
* User profile info.
|
|
77
|
-
|
|
77
|
+
*/
|
|
78
78
|
get profile (): Profile | undefined {
|
|
79
79
|
return this._profile;
|
|
80
80
|
}
|
|
@@ -36,6 +36,7 @@ export interface Party {
|
|
|
36
36
|
get isOpen (): boolean
|
|
37
37
|
get isActive (): boolean
|
|
38
38
|
|
|
39
|
+
// TODO(burdon): Verbs should be on same interface.
|
|
39
40
|
get database (): Database
|
|
40
41
|
get select (): Database['select']
|
|
41
42
|
get reduce (): Database['reduce']
|
|
@@ -126,6 +127,7 @@ export class PartyProxy implements Party {
|
|
|
126
127
|
return this._isActive;
|
|
127
128
|
}
|
|
128
129
|
|
|
130
|
+
// TODO(burdon): Invert party/database? (e.g., const db = client.connect()).
|
|
129
131
|
get database (): Database {
|
|
130
132
|
if (!this._database) {
|
|
131
133
|
throw Error('Party not open.');
|
package/src/devtools/network.ts
CHANGED
|
@@ -80,6 +80,7 @@ export const getNetworkPeers = (hook: DevtoolsServiceDependencies, request: GetN
|
|
|
80
80
|
if (!request.topic) {
|
|
81
81
|
throw new Error('Expected a network topic');
|
|
82
82
|
}
|
|
83
|
+
|
|
83
84
|
const map = hook.networkManager.getSwarmMap(PublicKey.from(request.topic));
|
|
84
85
|
return {
|
|
85
86
|
peers: map?.peers.map(peer => ({
|
|
@@ -10,14 +10,16 @@ import * as dxos_echo_service from "../dxos/echo/service";
|
|
|
10
10
|
import * as dxos_echo_snapshot from "../dxos/echo/snapshot";
|
|
11
11
|
import * as dxos_halo_keys from "../dxos/halo/keys";
|
|
12
12
|
import * as dxos_rpc from "../dxos/rpc";
|
|
13
|
-
export interface
|
|
14
|
-
type_url?: string;
|
|
15
|
-
value?: Uint8Array;
|
|
13
|
+
export interface Empty {
|
|
16
14
|
}
|
|
17
15
|
export interface Timestamp {
|
|
18
16
|
seconds?: string;
|
|
19
17
|
nanos?: number;
|
|
20
18
|
}
|
|
19
|
+
export interface Any {
|
|
20
|
+
type_url?: string;
|
|
21
|
+
value?: Uint8Array;
|
|
22
|
+
}
|
|
21
23
|
export interface FileDescriptorSet {
|
|
22
24
|
file?: FileDescriptorProto[];
|
|
23
25
|
}
|
|
@@ -257,5 +259,3 @@ export namespace GeneratedCodeInfo {
|
|
|
257
259
|
end?: number;
|
|
258
260
|
}
|
|
259
261
|
}
|
|
260
|
-
export interface Empty {
|
|
261
|
-
}
|
package/src/version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const DXOS_VERSION = "2.31.
|
|
1
|
+
export const DXOS_VERSION = "2.31.7";
|