@dxos/client 2.31.8-dev.f21022f7 → 2.32.1-dev.0d16db2c
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 -8
- package/dist/src/api/client.d.ts.map +1 -1
- package/dist/src/api/client.js +5 -14
- package/dist/src/api/client.js.map +1 -1
- package/dist/src/api/client.test.js +15 -0
- package/dist/src/api/client.test.js.map +1 -1
- package/dist/src/api/proxies/party-proxy.d.ts +3 -0
- package/dist/src/api/proxies/party-proxy.d.ts.map +1 -1
- package/dist/src/api/proxies/party-proxy.js +3 -0
- package/dist/src/api/proxies/party-proxy.js.map +1 -1
- package/dist/src/devtools/devtools-context.d.ts +1 -2
- package/dist/src/devtools/devtools-context.d.ts.map +1 -1
- package/dist/src/devtools/devtools-rpc-server.d.ts +4 -0
- package/dist/src/devtools/devtools-rpc-server.d.ts.map +1 -0
- package/dist/src/devtools/devtools-rpc-server.js +64 -0
- package/dist/src/devtools/devtools-rpc-server.js.map +1 -0
- package/dist/src/devtools/index.d.ts +1 -0
- package/dist/src/devtools/index.d.ts.map +1 -1
- package/dist/src/devtools/index.js +1 -0
- package/dist/src/devtools/index.js.map +1 -1
- package/dist/src/proto/gen/dxos/client.d.ts +10 -0
- package/dist/src/proto/gen/dxos/client.d.ts.map +1 -1
- package/dist/src/proto/gen/dxos/rpc.d.ts +5 -1
- package/dist/src/proto/gen/dxos/rpc.d.ts.map +1 -1
- package/dist/src/proto/gen/dxos/rpc.js.map +1 -1
- package/dist/src/proto/gen/google/protobuf.d.ts +4 -4
- package/dist/src/proto/gen/google/protobuf.d.ts.map +1 -1
- package/dist/src/proto/gen/index.d.ts +2 -0
- 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/src/services/impl/party.d.ts +2 -1
- package/dist/src/services/impl/party.d.ts.map +1 -1
- package/dist/src/services/impl/party.js +7 -0
- package/dist/src/services/impl/party.js.map +1 -1
- package/dist/src/services/service-proxy.d.ts +2 -1
- package/dist/src/services/service-proxy.d.ts.map +1 -1
- package/dist/src/services/service-proxy.js +3 -2
- package/dist/src/services/service-proxy.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 +21 -22
- package/src/api/client.test.ts +19 -0
- package/src/api/client.ts +14 -17
- package/src/api/proxies/party-proxy.ts +7 -1
- package/src/devtools/devtools-context.ts +1 -3
- package/src/devtools/devtools-rpc-server.ts +73 -0
- package/src/devtools/index.ts +1 -0
- package/src/proto/gen/dxos/client.ts +10 -0
- package/src/proto/gen/dxos/rpc.ts +5 -1
- package/src/proto/gen/google/protobuf.ts +4 -4
- package/src/proto/gen/index.ts +3 -1
- package/src/services/impl/party.ts +10 -1
- package/src/services/service-proxy.ts +5 -2
- package/src/version.ts +1 -1
package/src/api/client.test.ts
CHANGED
|
@@ -12,6 +12,7 @@ import { ConfigObject } from '@dxos/config';
|
|
|
12
12
|
import { generateSeedPhrase, keyPairFromSeedPhrase } from '@dxos/crypto';
|
|
13
13
|
import { throwUnhandledRejection } from '@dxos/debug';
|
|
14
14
|
import { InvitationDescriptor } from '@dxos/echo-db';
|
|
15
|
+
import { Timeframe } from '@dxos/echo-protocol';
|
|
15
16
|
import { TestModel } from '@dxos/model-factory';
|
|
16
17
|
import { ObjectModel } from '@dxos/object-model';
|
|
17
18
|
import { createBundledRpcServer, createLinkedPorts } from '@dxos/rpc';
|
|
@@ -265,6 +266,24 @@ describe('Client', () => {
|
|
|
265
266
|
|
|
266
267
|
expect(item1.model.get('prop1')).toEqual('x');
|
|
267
268
|
});
|
|
269
|
+
|
|
270
|
+
test('party timeframe is incremented after creating ECHO mutations', async () => {
|
|
271
|
+
const client = await createClient();
|
|
272
|
+
await client.initialize();
|
|
273
|
+
afterTest(() => client.destroy());
|
|
274
|
+
|
|
275
|
+
await client.halo.createProfile();
|
|
276
|
+
const party = await client.echo.createParty();
|
|
277
|
+
|
|
278
|
+
const item1 = await party.database.createItem({ model: ObjectModel, type: 'test' });
|
|
279
|
+
await item1.model.set('prop1', 'x');
|
|
280
|
+
const item2 = await party.database.createItem({ model: ObjectModel, type: 'test' });
|
|
281
|
+
await item2.model.set('prop1', 'y');
|
|
282
|
+
|
|
283
|
+
const details = await party.getDetails();
|
|
284
|
+
expect(details.processedTimeframe).toBeInstanceOf(Timeframe);
|
|
285
|
+
expect(details.processedTimeframe.frames().some(([key, seq]) => seq > 0)).toBe(true);
|
|
286
|
+
});
|
|
268
287
|
});
|
|
269
288
|
}
|
|
270
289
|
|
package/src/api/client.ts
CHANGED
|
@@ -12,7 +12,7 @@ import { OpenProgress } from '@dxos/echo-db';
|
|
|
12
12
|
import { ModelConstructor } from '@dxos/model-factory';
|
|
13
13
|
import { RpcPort } from '@dxos/rpc';
|
|
14
14
|
|
|
15
|
-
import {
|
|
15
|
+
import { createDevtoolsRpcServer } from '../devtools';
|
|
16
16
|
import { Runtime } from '../proto/gen/dxos/config';
|
|
17
17
|
import { ClientServiceProvider, ClientServices, ClientServiceHost, ClientServiceProxy, HaloSigner } from '../services';
|
|
18
18
|
import { createWindowMessagePort, isNode } from '../util';
|
|
@@ -47,6 +47,11 @@ export interface ClientOptions {
|
|
|
47
47
|
*
|
|
48
48
|
*/
|
|
49
49
|
signer?: HaloSigner
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
*
|
|
53
|
+
*/
|
|
54
|
+
timeout?: number
|
|
50
55
|
}
|
|
51
56
|
|
|
52
57
|
/**
|
|
@@ -173,6 +178,10 @@ export class Client {
|
|
|
173
178
|
await this.initializeAuto(onProgressCallback);
|
|
174
179
|
}
|
|
175
180
|
|
|
181
|
+
if (typeof window !== 'undefined') {
|
|
182
|
+
await createDevtoolsRpcServer(this, this._serviceProvider);
|
|
183
|
+
}
|
|
184
|
+
|
|
176
185
|
this._halo = new HaloProxy(this._serviceProvider);
|
|
177
186
|
this._echo = new EchoProxy(this._serviceProvider, this._halo);
|
|
178
187
|
|
|
@@ -189,7 +198,10 @@ export class Client {
|
|
|
189
198
|
}
|
|
190
199
|
|
|
191
200
|
log('Creating client proxy.');
|
|
192
|
-
this._serviceProvider = new ClientServiceProxy(
|
|
201
|
+
this._serviceProvider = new ClientServiceProxy(
|
|
202
|
+
this._options.rpcPort ?? createWindowMessagePort(),
|
|
203
|
+
this._options.timeout
|
|
204
|
+
);
|
|
193
205
|
await this._serviceProvider.open(onProgressCallback);
|
|
194
206
|
}
|
|
195
207
|
|
|
@@ -253,19 +265,4 @@ export class Client {
|
|
|
253
265
|
this._echo.modelFactory.registerModel(constructor);
|
|
254
266
|
return this;
|
|
255
267
|
}
|
|
256
|
-
|
|
257
|
-
/**
|
|
258
|
-
* Returns devtools context.
|
|
259
|
-
* Used by the DXOS DevTool Extension.
|
|
260
|
-
* This is what gets assigned to `window.__DXOS__` global.
|
|
261
|
-
*/
|
|
262
|
-
getDevtoolsContext (): DevtoolsHook {
|
|
263
|
-
const devtoolsContext: DevtoolsHook = {
|
|
264
|
-
client: this,
|
|
265
|
-
// TODO(dmaretskyi): Is serviceHost needed?
|
|
266
|
-
serviceHost: this._serviceProvider
|
|
267
|
-
};
|
|
268
|
-
|
|
269
|
-
return devtoolsContext;
|
|
270
|
-
}
|
|
271
268
|
}
|
|
@@ -18,7 +18,7 @@ import { PartyKey, PartySnapshot } from '@dxos/echo-protocol';
|
|
|
18
18
|
import { ModelFactory } from '@dxos/model-factory';
|
|
19
19
|
import { ObjectModel, ObjectProperties } from '@dxos/object-model';
|
|
20
20
|
|
|
21
|
-
import { Party as PartyProto } from '../../proto/gen/dxos/client';
|
|
21
|
+
import { Party as PartyProto, PartyDetails } from '../../proto/gen/dxos/client';
|
|
22
22
|
import { ClientServiceHost, ClientServiceProvider, ClientServiceProxy } from '../../services';
|
|
23
23
|
import { streamToResultSet } from '../../util';
|
|
24
24
|
import { InvitationRequest, InvitationProxy } from '../invitations';
|
|
@@ -51,6 +51,8 @@ export interface Party {
|
|
|
51
51
|
setTitle (title: string): Promise<void>
|
|
52
52
|
getTitle (): string
|
|
53
53
|
|
|
54
|
+
getDetails(): Promise<PartyDetails>
|
|
55
|
+
|
|
54
56
|
get properties (): ObjectProperties
|
|
55
57
|
/**
|
|
56
58
|
* @deprecated
|
|
@@ -179,6 +181,10 @@ export class PartyProxy implements Party {
|
|
|
179
181
|
await this._setOpen(false);
|
|
180
182
|
}
|
|
181
183
|
|
|
184
|
+
async getDetails (): Promise<PartyDetails> {
|
|
185
|
+
return this._serviceProvider.services.PartyService.getPartyDetails({ partyKey: this._key });
|
|
186
|
+
}
|
|
187
|
+
|
|
182
188
|
async _setOpen (open: boolean) {
|
|
183
189
|
await this._serviceProvider.services.PartyService.setPartyState({
|
|
184
190
|
partyKey: this.key,
|
|
@@ -10,15 +10,13 @@ import { ModelFactory } from '@dxos/model-factory';
|
|
|
10
10
|
import { NetworkManager } from '@dxos/network-manager';
|
|
11
11
|
|
|
12
12
|
import { Client } from '../api';
|
|
13
|
-
import { ClientServiceProvider } from '../services';
|
|
14
13
|
|
|
15
14
|
/**
|
|
16
15
|
* A hook bound to window.__DXOS__.
|
|
17
16
|
*/
|
|
18
17
|
export interface DevtoolsHook {
|
|
19
|
-
// TODO(marik-d): Reduce to just exporting ClientServices.
|
|
20
|
-
serviceHost: ClientServiceProvider
|
|
21
18
|
client: Client
|
|
19
|
+
openClientRpcServer: () => Promise<boolean>
|
|
22
20
|
}
|
|
23
21
|
|
|
24
22
|
export interface DevtoolsServiceDependencies {
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2022 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import debug from 'debug';
|
|
6
|
+
|
|
7
|
+
import { createBundledRpcServer, RpcPeer, RpcPort } from '@dxos/rpc';
|
|
8
|
+
|
|
9
|
+
import { Client } from '../api';
|
|
10
|
+
import { clientServiceBundle, ClientServiceProvider } from '../services';
|
|
11
|
+
import { DevtoolsHook } from './devtools-context';
|
|
12
|
+
|
|
13
|
+
const log = debug('dxos:client:devtools');
|
|
14
|
+
const error = log.extend('error');
|
|
15
|
+
|
|
16
|
+
const port: RpcPort = {
|
|
17
|
+
send: async message => window.postMessage({
|
|
18
|
+
data: Array.from(message),
|
|
19
|
+
source: 'dxos-client'
|
|
20
|
+
}, '*'),
|
|
21
|
+
subscribe: callback => {
|
|
22
|
+
const handler = (event: MessageEvent<any>) => {
|
|
23
|
+
if (event.source !== window) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const message = event.data;
|
|
28
|
+
|
|
29
|
+
if (
|
|
30
|
+
typeof message !== 'object' ||
|
|
31
|
+
message === null ||
|
|
32
|
+
message.source !== 'content-script'
|
|
33
|
+
) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
callback(new Uint8Array(message.data));
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
window.addEventListener('message', handler);
|
|
41
|
+
return () => window.removeEventListener('message', handler);
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
// Console debug access.
|
|
46
|
+
// TODO(burdon): Debug only.
|
|
47
|
+
export const createDevtoolsRpcServer = async (client: Client, serviceHost: ClientServiceProvider) => {
|
|
48
|
+
let server: RpcPeer;
|
|
49
|
+
((window as any).__DXOS__ as DevtoolsHook) = {
|
|
50
|
+
client,
|
|
51
|
+
openClientRpcServer: async () => {
|
|
52
|
+
if (server) {
|
|
53
|
+
log('Closing existing client RPC server.');
|
|
54
|
+
server.close();
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
log('Opening devtools client RPC server...');
|
|
58
|
+
server = createBundledRpcServer({
|
|
59
|
+
services: clientServiceBundle,
|
|
60
|
+
handlers: serviceHost.services,
|
|
61
|
+
port
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
await server.open().catch(err => {
|
|
65
|
+
error(`Failed to open RPC server: ${err}`);
|
|
66
|
+
return false;
|
|
67
|
+
});
|
|
68
|
+
log('Opened devtools client RPC server.');
|
|
69
|
+
|
|
70
|
+
return true;
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
};
|
package/src/devtools/index.ts
CHANGED
|
@@ -130,6 +130,15 @@ export namespace Party {
|
|
|
130
130
|
export interface SubscribePartyRequest {
|
|
131
131
|
partyKey: ReturnType<typeof substitutions["dxos.halo.keys.PubKey"]["decode"]>;
|
|
132
132
|
}
|
|
133
|
+
export interface GetPartyDetailsRequest {
|
|
134
|
+
partyKey: ReturnType<typeof substitutions["dxos.halo.keys.PubKey"]["decode"]>;
|
|
135
|
+
}
|
|
136
|
+
export interface PartyDetails {
|
|
137
|
+
/**
|
|
138
|
+
* The timeframe of mutations processed by the client.
|
|
139
|
+
*/
|
|
140
|
+
processedTimeframe: ReturnType<typeof substitutions["dxos.echo.feed.TimeframeVector"]["decode"]>;
|
|
141
|
+
}
|
|
133
142
|
export interface SubscribePartyResponse {
|
|
134
143
|
party?: Party;
|
|
135
144
|
}
|
|
@@ -171,6 +180,7 @@ export interface CreateSnaspotRequest {
|
|
|
171
180
|
export interface PartyService {
|
|
172
181
|
subscribeToParty: (request: SubscribePartyRequest) => Stream<SubscribePartyResponse>;
|
|
173
182
|
subscribeParties: (request: void) => Stream<SubscribePartiesResponse>;
|
|
183
|
+
getPartyDetails: (request: GetPartyDetailsRequest) => Promise<PartyDetails>;
|
|
174
184
|
createParty: (request: void) => Promise<Party>;
|
|
175
185
|
cloneParty: (request: dxos_echo_snapshot.PartySnapshot) => Promise<Party>;
|
|
176
186
|
/**
|
|
@@ -14,9 +14,13 @@ export interface RpcMessage {
|
|
|
14
14
|
request?: Request;
|
|
15
15
|
response?: Response;
|
|
16
16
|
/**
|
|
17
|
-
* Means that the node is
|
|
17
|
+
* Means that the node is trying to open the connection.
|
|
18
18
|
*/
|
|
19
19
|
open?: boolean;
|
|
20
|
+
/**
|
|
21
|
+
* Means that the node has received the "open" message and is ready to perform requests.
|
|
22
|
+
*/
|
|
23
|
+
openAck?: boolean;
|
|
20
24
|
streamClose?: StreamClose;
|
|
21
25
|
}
|
|
22
26
|
export interface Request {
|
|
@@ -12,14 +12,14 @@ import * as dxos_halo_keys from "../dxos/halo/keys";
|
|
|
12
12
|
import * as dxos_rpc from "../dxos/rpc";
|
|
13
13
|
export interface Empty {
|
|
14
14
|
}
|
|
15
|
-
export interface Any {
|
|
16
|
-
type_url?: string;
|
|
17
|
-
value?: Uint8Array;
|
|
18
|
-
}
|
|
19
15
|
export interface Timestamp {
|
|
20
16
|
seconds?: string;
|
|
21
17
|
nanos?: number;
|
|
22
18
|
}
|
|
19
|
+
export interface Any {
|
|
20
|
+
type_url?: string;
|
|
21
|
+
value?: Uint8Array;
|
|
22
|
+
}
|
|
23
23
|
export interface FileDescriptorSet {
|
|
24
24
|
file?: FileDescriptorProto[];
|
|
25
25
|
}
|