@dxos/client-services 0.1.9 → 0.1.11
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/index.d.ts +0 -1
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +0 -1
- package/dist/src/index.js.map +1 -1
- package/dist/src/packlets/deprecated/invitations.d.ts +4 -4
- package/dist/src/packlets/deprecated/invitations.d.ts.map +1 -1
- package/dist/src/packlets/deprecated/profile.d.ts.map +1 -1
- package/dist/src/packlets/deprecated/profile.js +21 -9
- package/dist/src/packlets/deprecated/profile.js.map +1 -1
- package/dist/src/packlets/deprecated/space.d.ts.map +1 -1
- package/dist/src/packlets/deprecated/space.js +18 -15
- package/dist/src/packlets/deprecated/space.js.map +1 -1
- package/dist/src/packlets/deprecated/system.d.ts +3 -1
- package/dist/src/packlets/deprecated/system.d.ts.map +1 -1
- package/dist/src/packlets/deprecated/system.js +4 -3
- package/dist/src/packlets/deprecated/system.js.map +1 -1
- package/dist/src/packlets/devtools/devtools.d.ts +1 -1
- package/dist/src/packlets/devtools/devtools.d.ts.map +1 -1
- package/dist/src/packlets/devtools/feeds.d.ts.map +1 -1
- package/dist/src/packlets/devtools/feeds.js +2 -1
- package/dist/src/packlets/devtools/feeds.js.map +1 -1
- package/dist/src/packlets/devtools/network.js +3 -3
- package/dist/src/packlets/devtools/network.js.map +1 -1
- package/dist/src/packlets/devtools/spaces.d.ts.map +1 -1
- package/dist/src/packlets/devtools/spaces.js +2 -1
- package/dist/src/packlets/devtools/spaces.js.map +1 -1
- package/dist/src/packlets/identity/authenticator.js +3 -3
- package/dist/src/packlets/identity/authenticator.js.map +1 -1
- package/dist/src/packlets/identity/identity-manager.d.ts +5 -2
- package/dist/src/packlets/identity/identity-manager.d.ts.map +1 -1
- package/dist/src/packlets/identity/identity-manager.js +13 -9
- package/dist/src/packlets/identity/identity-manager.js.map +1 -1
- package/dist/src/packlets/identity/identity.d.ts +4 -1
- package/dist/src/packlets/identity/identity.d.ts.map +1 -1
- package/dist/src/packlets/identity/identity.js +8 -2
- package/dist/src/packlets/identity/identity.js.map +1 -1
- package/dist/src/packlets/invitations/halo-invitations-handler.d.ts +2 -2
- package/dist/src/packlets/invitations/halo-invitations-handler.d.ts.map +1 -1
- package/dist/src/packlets/invitations/halo-invitations-handler.js +17 -17
- package/dist/src/packlets/invitations/halo-invitations-handler.js.map +1 -1
- package/dist/src/packlets/invitations/invitations-handler.d.ts +6 -4
- package/dist/src/packlets/invitations/invitations-handler.d.ts.map +1 -1
- package/dist/src/packlets/invitations/invitations-handler.js.map +1 -1
- package/dist/src/packlets/invitations/invitations-proxy.d.ts +2 -2
- package/dist/src/packlets/invitations/invitations-proxy.d.ts.map +1 -1
- package/dist/src/packlets/invitations/invitations-proxy.js +2 -2
- package/dist/src/packlets/invitations/invitations-proxy.js.map +1 -1
- package/dist/src/packlets/invitations/invitations-service.js +12 -12
- package/dist/src/packlets/invitations/invitations-service.js.map +1 -1
- package/dist/src/packlets/invitations/invitations.d.ts +6 -9
- package/dist/src/packlets/invitations/invitations.d.ts.map +1 -1
- package/dist/src/packlets/invitations/invitations.js +6 -5
- package/dist/src/packlets/invitations/invitations.js.map +1 -1
- package/dist/src/packlets/invitations/space-invitations-handler.d.ts +2 -2
- package/dist/src/packlets/invitations/space-invitations-handler.d.ts.map +1 -1
- package/dist/src/packlets/invitations/space-invitations-handler.js +28 -20
- package/dist/src/packlets/invitations/space-invitations-handler.js.map +1 -1
- package/dist/src/packlets/services/service-context.d.ts +3 -2
- package/dist/src/packlets/services/service-context.d.ts.map +1 -1
- package/dist/src/packlets/services/service-context.js +15 -8
- package/dist/src/packlets/services/service-context.js.map +1 -1
- package/dist/src/packlets/services/service-definitions.d.ts +1 -1
- package/dist/src/packlets/services/service-definitions.d.ts.map +1 -1
- package/dist/src/packlets/services/service-host.d.ts +8 -4
- package/dist/src/packlets/services/service-host.d.ts.map +1 -1
- package/dist/src/packlets/services/service-host.js +33 -26
- package/dist/src/packlets/services/service-host.js.map +1 -1
- package/dist/src/packlets/services/service-proxy.d.ts.map +1 -1
- package/dist/src/packlets/services/service-proxy.js +1 -1
- package/dist/src/packlets/services/service-proxy.js.map +1 -1
- package/dist/src/packlets/services/service-registry.test.js +3 -3
- package/dist/src/packlets/services/service-registry.test.js.map +1 -1
- package/dist/src/packlets/storage/storage.d.ts +1 -1
- package/dist/src/packlets/storage/storage.d.ts.map +1 -1
- package/dist/src/packlets/storage/storage.js +6 -6
- package/dist/src/packlets/storage/storage.js.map +1 -1
- package/dist/src/packlets/testing/test-builder.js +1 -1
- package/dist/src/packlets/testing/test-builder.js.map +1 -1
- package/dist/src/packlets/vault/iframe-runtime.d.ts +1 -1
- package/dist/src/packlets/vault/iframe-runtime.d.ts.map +1 -1
- package/dist/src/packlets/vault/services.d.ts +2 -2
- package/dist/src/packlets/vault/services.d.ts.map +1 -1
- package/dist/src/packlets/vault/worker-runtime.d.ts +1 -1
- package/dist/src/packlets/vault/worker-runtime.d.ts.map +1 -1
- package/dist/src/packlets/vault/worker-session.d.ts +1 -1
- package/dist/src/packlets/vault/worker-session.d.ts.map +1 -1
- package/dist/src/packlets/vault/worker-session.js +3 -3
- package/dist/src/packlets/vault/worker-session.js.map +1 -1
- package/package.json +39 -29
- package/src/index.ts +0 -2
- package/src/packlets/deprecated/profile.ts +11 -3
- package/src/packlets/deprecated/space.ts +21 -20
- package/src/packlets/deprecated/system.ts +5 -3
- package/src/packlets/devtools/feeds.ts +2 -1
- package/src/packlets/devtools/network.ts +3 -3
- package/src/packlets/devtools/spaces.ts +2 -1
- package/src/packlets/identity/identity-manager.ts +14 -5
- package/src/packlets/identity/identity.ts +12 -3
- package/src/packlets/invitations/halo-invitations-handler.ts +6 -6
- package/src/packlets/invitations/invitations-handler.ts +6 -3
- package/src/packlets/invitations/invitations-proxy.ts +2 -2
- package/src/packlets/invitations/invitations-service.ts +2 -2
- package/src/packlets/invitations/invitations.ts +6 -11
- package/src/packlets/invitations/space-invitations-handler.ts +21 -9
- package/src/packlets/services/service-context.ts +15 -5
- package/src/packlets/services/service-host.ts +48 -36
- package/src/packlets/services/service-proxy.ts +1 -1
- package/src/packlets/storage/storage.ts +6 -6
- package/src/packlets/testing/test-builder.ts +1 -1
- package/testing.d.ts +11 -0
- package/testing.js +5 -0
- package/dist/src/errors.d.ts +0 -8
- package/dist/src/errors.d.ts.map +0 -1
- package/dist/src/errors.js +0 -21
- package/dist/src/errors.js.map +0 -1
- package/src/errors.ts +0 -19
|
@@ -12,7 +12,7 @@ import { Invitation } from '@dxos/protocols/proto/dxos/client/services';
|
|
|
12
12
|
import {
|
|
13
13
|
AuthenticatingInvitationObservable,
|
|
14
14
|
AuthenticatingInvitationProvider,
|
|
15
|
-
|
|
15
|
+
CancellableInvitationObservable,
|
|
16
16
|
InvitationObservableProvider,
|
|
17
17
|
InvitationsService
|
|
18
18
|
} from './invitations';
|
|
@@ -34,7 +34,7 @@ export abstract class AbstractInvitationsProxy<T = void> implements InvitationsP
|
|
|
34
34
|
|
|
35
35
|
abstract getInvitationOptions(context: T): Invitation;
|
|
36
36
|
|
|
37
|
-
createInvitation(context: T, options?: InvitationsOptions):
|
|
37
|
+
createInvitation(context: T, options?: InvitationsOptions): CancellableInvitationObservable {
|
|
38
38
|
let invitationId: string;
|
|
39
39
|
const observable = new InvitationObservableProvider(async () => {
|
|
40
40
|
if (invitationId) {
|
|
@@ -43,8 +43,8 @@ export abstract class AbstractInvitationsService<T = void> implements Invitation
|
|
|
43
43
|
log('stream opened', this.getLoggingContext());
|
|
44
44
|
|
|
45
45
|
let invitationId: string;
|
|
46
|
-
const { type } = invitation;
|
|
47
|
-
const observable = invitationsHandler.createInvitation(context, { type });
|
|
46
|
+
const { type, swarmKey } = invitation;
|
|
47
|
+
const observable = invitationsHandler.createInvitation(context, { type, swarmKey });
|
|
48
48
|
observable.subscribe({
|
|
49
49
|
onConnecting: (invitation) => {
|
|
50
50
|
assert(invitation.invitationId);
|
|
@@ -8,7 +8,6 @@ import {
|
|
|
8
8
|
AsyncEvents,
|
|
9
9
|
CancellableObservable,
|
|
10
10
|
CancellableObservableEvents,
|
|
11
|
-
Observable,
|
|
12
11
|
CancellableObservableProvider
|
|
13
12
|
} from '@dxos/async';
|
|
14
13
|
import type { Stream } from '@dxos/codec-protobuf';
|
|
@@ -43,13 +42,13 @@ export interface InvitationEvents extends AsyncEvents, CancellableObservableEven
|
|
|
43
42
|
* Base class for all invitation observables and providers.
|
|
44
43
|
* Observable that supports inspection of the current value.
|
|
45
44
|
*/
|
|
46
|
-
export interface
|
|
45
|
+
export interface CancellableInvitationObservable extends CancellableObservable<InvitationEvents> {
|
|
47
46
|
get invitation(): Invitation | undefined;
|
|
48
47
|
}
|
|
49
48
|
|
|
50
49
|
export class InvitationObservableProvider
|
|
51
50
|
extends CancellableObservableProvider<InvitationEvents>
|
|
52
|
-
implements
|
|
51
|
+
implements CancellableInvitationObservable
|
|
53
52
|
{
|
|
54
53
|
private _invitation?: Invitation;
|
|
55
54
|
|
|
@@ -62,11 +61,6 @@ export class InvitationObservableProvider
|
|
|
62
61
|
}
|
|
63
62
|
}
|
|
64
63
|
|
|
65
|
-
/**
|
|
66
|
-
* Cancelable observer.
|
|
67
|
-
*/
|
|
68
|
-
export type CancellableInvitationObservable = InvitationObservable;
|
|
69
|
-
|
|
70
64
|
/**
|
|
71
65
|
* Cancelable observer that relays authentication requests.
|
|
72
66
|
*/
|
|
@@ -96,11 +90,12 @@ export class AuthenticatingInvitationProvider
|
|
|
96
90
|
}
|
|
97
91
|
|
|
98
92
|
/**
|
|
99
|
-
*
|
|
93
|
+
* Testing util to wrap non-authenticating observable with promise.
|
|
94
|
+
* Don't use this in production code.
|
|
100
95
|
* @deprecated
|
|
101
96
|
*/
|
|
102
|
-
// TODO(burdon):
|
|
103
|
-
export const
|
|
97
|
+
// TODO(burdon): Throw error if auth requested.
|
|
98
|
+
export const wrapObservable = async (observable: CancellableInvitationObservable): Promise<Invitation> => {
|
|
104
99
|
return new Promise((resolve, reject) => {
|
|
105
100
|
const unsubscribe = observable.subscribe({
|
|
106
101
|
onSuccess: (invitation: Invitation) => {
|
|
@@ -14,11 +14,12 @@ import { createProtocolFactory, NetworkManager, StarTopology, SwarmConnection }
|
|
|
14
14
|
import { createRpcPlugin, RpcPlugin } from '@dxos/protocol-plugin-rpc';
|
|
15
15
|
import { schema } from '@dxos/protocols';
|
|
16
16
|
import { Invitation } from '@dxos/protocols/proto/dxos/client/services';
|
|
17
|
+
import { ProfileDocument } from '@dxos/protocols/proto/dxos/halo/credentials';
|
|
17
18
|
import { createProtoRpcPeer } from '@dxos/rpc';
|
|
18
19
|
|
|
19
20
|
import {
|
|
20
21
|
AuthenticatingInvitationProvider,
|
|
21
|
-
|
|
22
|
+
CancellableInvitationObservable,
|
|
22
23
|
InvitationObservableProvider,
|
|
23
24
|
AUTHENTICATION_CODE_LENGTH,
|
|
24
25
|
INVITATION_TIMEOUT,
|
|
@@ -42,16 +43,16 @@ export class SpaceInvitationsHandler extends AbstractInvitationsHandler<Space> {
|
|
|
42
43
|
/**
|
|
43
44
|
* Creates an invitation and listens for a join request from the invited (guest) peer.
|
|
44
45
|
*/
|
|
45
|
-
createInvitation(space: Space, options?: InvitationsOptions):
|
|
46
|
+
createInvitation(space: Space, options?: InvitationsOptions): CancellableInvitationObservable {
|
|
46
47
|
let swarmConnection: SwarmConnection | undefined;
|
|
47
|
-
const { type, timeout = INVITATION_TIMEOUT } = options ?? {};
|
|
48
|
+
const { type, timeout = INVITATION_TIMEOUT, swarmKey } = options ?? {};
|
|
48
49
|
assert(type !== Invitation.Type.OFFLINE);
|
|
49
50
|
assert(space);
|
|
50
51
|
|
|
51
52
|
const invitation: Invitation = {
|
|
52
53
|
type,
|
|
53
54
|
invitationId: PublicKey.random().toHex(),
|
|
54
|
-
swarmKey: PublicKey.random(),
|
|
55
|
+
swarmKey: swarmKey ?? PublicKey.random(),
|
|
55
56
|
spaceKey: space.key,
|
|
56
57
|
authenticationCode: generatePasscode(AUTHENTICATION_CODE_LENGTH)
|
|
57
58
|
};
|
|
@@ -64,19 +65,25 @@ export class SpaceInvitationsHandler extends AbstractInvitationsHandler<Space> {
|
|
|
64
65
|
let authenticationCode: string;
|
|
65
66
|
const complete = new Trigger<PublicKey>();
|
|
66
67
|
const plugin = new RpcPlugin(async (port) => {
|
|
68
|
+
let guestProfile: ProfileDocument | undefined;
|
|
69
|
+
|
|
67
70
|
const peer = createProtoRpcPeer({
|
|
68
71
|
exposed: {
|
|
69
72
|
SpaceHostService: schema.getService('dxos.halo.invitations.SpaceHostService')
|
|
70
73
|
},
|
|
71
74
|
handlers: {
|
|
72
75
|
SpaceHostService: {
|
|
73
|
-
requestAdmission: async () => {
|
|
76
|
+
requestAdmission: async ({ profile }) => {
|
|
74
77
|
log('responding with admission offer', {
|
|
78
|
+
guestProfile: profile,
|
|
75
79
|
host: this._signingContext.deviceKey,
|
|
76
80
|
spaceKey: space.key
|
|
77
81
|
});
|
|
78
82
|
|
|
83
|
+
guestProfile = profile;
|
|
84
|
+
|
|
79
85
|
// TODO(burdon): Is this the right place to set this state?
|
|
86
|
+
// TODO(dmaretskyi): Should we expose guest's profile in this callback?
|
|
80
87
|
observable.callback.onAuthenticating?.(invitation);
|
|
81
88
|
return {
|
|
82
89
|
spaceKey: space.key,
|
|
@@ -97,6 +104,8 @@ export class SpaceInvitationsHandler extends AbstractInvitationsHandler<Space> {
|
|
|
97
104
|
invitation.authenticationCode === undefined ||
|
|
98
105
|
authenticationCode !== invitation.authenticationCode
|
|
99
106
|
) {
|
|
107
|
+
invitation.authenticationCode &&
|
|
108
|
+
log.error('bad auth code', { code: authenticationCode, expected: invitation.authenticationCode });
|
|
100
109
|
throw new Error('authentication code not set');
|
|
101
110
|
}
|
|
102
111
|
}
|
|
@@ -111,7 +120,8 @@ export class SpaceInvitationsHandler extends AbstractInvitationsHandler<Space> {
|
|
|
111
120
|
deviceKey,
|
|
112
121
|
space.key,
|
|
113
122
|
controlFeedKey,
|
|
114
|
-
dataFeedKey
|
|
123
|
+
dataFeedKey,
|
|
124
|
+
guestProfile
|
|
115
125
|
)
|
|
116
126
|
);
|
|
117
127
|
|
|
@@ -150,7 +160,7 @@ export class SpaceInvitationsHandler extends AbstractInvitationsHandler<Space> {
|
|
|
150
160
|
setTimeout(async () => {
|
|
151
161
|
const topic = invitation.swarmKey!;
|
|
152
162
|
const peerId = PublicKey.random(); // Use anonymous key.
|
|
153
|
-
swarmConnection = await this._networkManager.
|
|
163
|
+
swarmConnection = await this._networkManager.joinSwarm({
|
|
154
164
|
topic,
|
|
155
165
|
peerId: topic,
|
|
156
166
|
protocol: createProtocolFactory(topic, peerId, [plugin]),
|
|
@@ -206,7 +216,9 @@ export class SpaceInvitationsHandler extends AbstractInvitationsHandler<Space> {
|
|
|
206
216
|
|
|
207
217
|
// 1. Send request.
|
|
208
218
|
log('sending admission request', { guest: this._signingContext.deviceKey });
|
|
209
|
-
const { spaceKey, genesisFeedKey } = await peer.rpc.SpaceHostService.requestAdmission(
|
|
219
|
+
const { spaceKey, genesisFeedKey } = await peer.rpc.SpaceHostService.requestAdmission({
|
|
220
|
+
profile: this._signingContext.profile
|
|
221
|
+
});
|
|
210
222
|
|
|
211
223
|
// 2. Get authentication code.
|
|
212
224
|
// TODO(burdon): Test timeout (options for timeouts at different steps).
|
|
@@ -248,7 +260,7 @@ export class SpaceInvitationsHandler extends AbstractInvitationsHandler<Space> {
|
|
|
248
260
|
assert(invitation.swarmKey);
|
|
249
261
|
const topic = invitation.swarmKey;
|
|
250
262
|
const peerId = PublicKey.random(); // Use anonymous key.
|
|
251
|
-
swarmConnection = await this._networkManager.
|
|
263
|
+
swarmConnection = await this._networkManager.joinSwarm({
|
|
252
264
|
topic,
|
|
253
265
|
peerId: PublicKey.random(),
|
|
254
266
|
protocol: createProtocolFactory(topic, peerId, [plugin]),
|
|
@@ -21,12 +21,13 @@ import { NetworkManager } from '@dxos/network-manager';
|
|
|
21
21
|
import type { FeedMessage } from '@dxos/protocols/proto/dxos/echo/feed';
|
|
22
22
|
import { Storage } from '@dxos/random-access-storage';
|
|
23
23
|
|
|
24
|
-
import { IdentityManager } from '../identity';
|
|
24
|
+
import { CreateIdentityOptions, IdentityManager } from '../identity';
|
|
25
25
|
import { HaloInvitationsHandler, SpaceInvitationsHandler } from '../invitations';
|
|
26
26
|
|
|
27
27
|
/**
|
|
28
28
|
* Shared backend for all client services.
|
|
29
29
|
*/
|
|
30
|
+
|
|
30
31
|
// TODO(burdon): Rename/break-up into smaller components. And/or make members private.
|
|
31
32
|
export class ServiceContext {
|
|
32
33
|
public readonly initialized = new Trigger();
|
|
@@ -87,13 +88,21 @@ export class ServiceContext {
|
|
|
87
88
|
await this.identityManager.close();
|
|
88
89
|
await this.spaceManager?.close();
|
|
89
90
|
await this.feedStore.close();
|
|
90
|
-
await this.networkManager.
|
|
91
|
+
await this.networkManager.close();
|
|
91
92
|
this.dataServiceSubscriptions.clear();
|
|
92
93
|
log('closed');
|
|
93
94
|
}
|
|
94
95
|
|
|
95
|
-
async
|
|
96
|
-
|
|
96
|
+
async reset() {
|
|
97
|
+
log('resetting...');
|
|
98
|
+
await this.close();
|
|
99
|
+
await this.storage.reset();
|
|
100
|
+
log('reset');
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
async createIdentity(params: CreateIdentityOptions = {}) {
|
|
104
|
+
const identity = await this.identityManager.createIdentity(params);
|
|
105
|
+
|
|
97
106
|
this.dataServiceSubscriptions.registerSpace(identity.haloSpaceKey, identity.haloDatabase.createDataServiceHost());
|
|
98
107
|
await this._initialize();
|
|
99
108
|
return identity;
|
|
@@ -107,7 +116,8 @@ export class ServiceContext {
|
|
|
107
116
|
credentialAuthenticator: MOCK_AUTH_VERIFIER,
|
|
108
117
|
credentialSigner: identity.getIdentityCredentialSigner(),
|
|
109
118
|
identityKey: identity.identityKey,
|
|
110
|
-
deviceKey: identity.deviceKey
|
|
119
|
+
deviceKey: identity.deviceKey,
|
|
120
|
+
profile: identity.profileDocument
|
|
111
121
|
};
|
|
112
122
|
|
|
113
123
|
// Create in constructor (avoid all of these private variables).
|
|
@@ -21,25 +21,28 @@ import { ServiceContext } from './service-context';
|
|
|
21
21
|
import { ClientServicesProvider, ClientServices, clientServiceBundle } from './service-definitions';
|
|
22
22
|
import { ServiceRegistry } from './service-registry';
|
|
23
23
|
|
|
24
|
-
type ClientServicesHostParams = {
|
|
25
|
-
config: Config;
|
|
26
|
-
modelFactory?: ModelFactory;
|
|
27
|
-
networkManager: NetworkManager;
|
|
28
|
-
};
|
|
29
|
-
|
|
30
24
|
// TODO(burdon): Factor out to spaces.
|
|
31
25
|
// TODO(burdon): Defaults (with TextModel).
|
|
32
26
|
export const createDefaultModelFactory = () => {
|
|
33
27
|
return new ModelFactory().registerModel(ObjectModel).registerModel(TextModel);
|
|
34
28
|
};
|
|
35
29
|
|
|
30
|
+
type ClientServicesHostParams = {
|
|
31
|
+
config: Config;
|
|
32
|
+
modelFactory?: ModelFactory;
|
|
33
|
+
networkManager: NetworkManager;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
36
|
/**
|
|
37
37
|
* Remote service implementation.
|
|
38
38
|
*/
|
|
39
|
-
// TODO(burdon): Reconcile Host/Backend, etc.
|
|
40
39
|
export class ClientServicesHost implements ClientServicesProvider {
|
|
41
|
-
private
|
|
42
|
-
private
|
|
40
|
+
private _serviceContext!: ServiceContext;
|
|
41
|
+
private _serviceRegistry!: ServiceRegistry<ClientServices>;
|
|
42
|
+
|
|
43
|
+
private readonly _config: Config;
|
|
44
|
+
private readonly _modelFactory: ModelFactory;
|
|
45
|
+
private readonly _networkManager: NetworkManager;
|
|
43
46
|
|
|
44
47
|
constructor({
|
|
45
48
|
config,
|
|
@@ -47,11 +50,42 @@ export class ClientServicesHost implements ClientServicesProvider {
|
|
|
47
50
|
// TODO(burdon): Create ApolloLink abstraction (see Client).
|
|
48
51
|
networkManager
|
|
49
52
|
}: ClientServicesHostParams) {
|
|
53
|
+
this._config = config;
|
|
54
|
+
this._modelFactory = modelFactory;
|
|
55
|
+
this._networkManager = networkManager;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
get descriptors() {
|
|
59
|
+
return this._serviceRegistry.descriptors;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
get services() {
|
|
63
|
+
return this._serviceRegistry.services;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
async open() {
|
|
67
|
+
await this._initialize();
|
|
68
|
+
const deviceKey = this._serviceContext.identityManager.identity?.deviceKey;
|
|
69
|
+
log('opening...', { deviceKey });
|
|
70
|
+
await this._initialize();
|
|
71
|
+
await this._serviceContext.open();
|
|
72
|
+
log('opened', { deviceKey });
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
async close() {
|
|
76
|
+
const deviceKey = this._serviceContext.identityManager.identity?.deviceKey;
|
|
77
|
+
log('closing...', { deviceKey });
|
|
78
|
+
await this._serviceContext.close();
|
|
79
|
+
log('closed', { deviceKey });
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// TODO(burdon): Move into open.
|
|
83
|
+
async _initialize() {
|
|
50
84
|
// TODO(dmaretskyi): Remove keyStorage.
|
|
51
|
-
const { storage } = createStorageObjects(
|
|
85
|
+
const { storage } = createStorageObjects(this._config.get('runtime.client.storage', {})!);
|
|
52
86
|
|
|
53
87
|
// TODO(burdon): Break into components.
|
|
54
|
-
this._serviceContext = new ServiceContext(storage,
|
|
88
|
+
this._serviceContext = new ServiceContext(storage, this._networkManager, this._modelFactory);
|
|
55
89
|
|
|
56
90
|
// TODO(burdon): Start to think of DMG (dynamic services).
|
|
57
91
|
this._serviceRegistry = new ServiceRegistry<ClientServices>(clientServiceBundle, {
|
|
@@ -75,35 +109,13 @@ export class ClientServicesHost implements ClientServicesProvider {
|
|
|
75
109
|
// TODO(burdon): Move to new protobuf definitions.
|
|
76
110
|
ProfileService: new ProfileServiceImpl(this._serviceContext),
|
|
77
111
|
SpaceService: new SpaceServiceImpl(this._serviceContext),
|
|
78
|
-
SystemService: new SystemServiceImpl(
|
|
79
|
-
TracingService: new TracingServiceImpl(
|
|
112
|
+
SystemService: new SystemServiceImpl(this._config, this._serviceContext),
|
|
113
|
+
TracingService: new TracingServiceImpl(this._config),
|
|
80
114
|
DevtoolsHost: new DevtoolsServiceImpl({
|
|
81
115
|
events: new DevtoolsHostEvents(),
|
|
82
|
-
config,
|
|
116
|
+
config: this._config,
|
|
83
117
|
context: this._serviceContext
|
|
84
118
|
})
|
|
85
119
|
});
|
|
86
120
|
}
|
|
87
|
-
|
|
88
|
-
get descriptors() {
|
|
89
|
-
return this._serviceRegistry.descriptors;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
get services() {
|
|
93
|
-
return this._serviceRegistry.services;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
async open() {
|
|
97
|
-
const deviceKey = this._serviceContext.identityManager.identity?.deviceKey;
|
|
98
|
-
log('opening...', { deviceKey });
|
|
99
|
-
await this._serviceContext.open();
|
|
100
|
-
log('opened', { deviceKey });
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
async close() {
|
|
104
|
-
const deviceKey = this._serviceContext.identityManager.identity?.deviceKey;
|
|
105
|
-
log('closing...', { deviceKey });
|
|
106
|
-
await this._serviceContext.close();
|
|
107
|
-
log('closed', { deviceKey });
|
|
108
|
-
}
|
|
109
121
|
}
|
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
//
|
|
4
4
|
|
|
5
5
|
import { asyncTimeout } from '@dxos/async';
|
|
6
|
+
import { RemoteServiceConnectionTimeout } from '@dxos/errors';
|
|
6
7
|
import { createProtoRpcPeer, ProtoRpcPeer, RpcPort } from '@dxos/rpc';
|
|
7
8
|
|
|
8
|
-
import { RemoteServiceConnectionTimeout } from '../../errors';
|
|
9
9
|
import { ClientServicesProvider, ClientServices, clientServiceBundle } from './service-definitions';
|
|
10
10
|
|
|
11
11
|
/**
|
|
@@ -6,12 +6,12 @@ import jsondown from 'jsondown'; // TODO(burdon): Uses custom implementation.
|
|
|
6
6
|
import leveljs from 'level-js';
|
|
7
7
|
import memdown from 'memdown';
|
|
8
8
|
|
|
9
|
+
import { InvalidConfigError } from '@dxos/errors';
|
|
9
10
|
import { Runtime } from '@dxos/protocols/proto/dxos/config';
|
|
10
11
|
import { createStorage, StorageType } from '@dxos/random-access-storage';
|
|
11
12
|
import { isNode } from '@dxos/util';
|
|
12
13
|
|
|
13
14
|
import StorageDriver = Runtime.Client.Storage.StorageDriver;
|
|
14
|
-
import { InvalidConfigurationError } from '../../errors';
|
|
15
15
|
|
|
16
16
|
export type KeyStorageType = 'ram' | 'leveljs' | 'jsondown';
|
|
17
17
|
|
|
@@ -25,16 +25,16 @@ export const createStorageObjects = (config: Runtime.Client.Storage) => {
|
|
|
25
25
|
} = config ?? {};
|
|
26
26
|
|
|
27
27
|
if (persistent && storageType === StorageDriver.RAM) {
|
|
28
|
-
throw new
|
|
28
|
+
throw new InvalidConfigError('RAM storage cannot be used in persistent mode.');
|
|
29
29
|
}
|
|
30
30
|
if (!persistent && storageType !== undefined && storageType !== StorageDriver.RAM) {
|
|
31
|
-
throw new
|
|
31
|
+
throw new InvalidConfigError('Cannot use a persistent storage in not persistent mode.');
|
|
32
32
|
}
|
|
33
33
|
if (persistent && keyStorage === StorageDriver.RAM) {
|
|
34
|
-
throw new
|
|
34
|
+
throw new InvalidConfigError('RAM key storage cannot be used in persistent mode.');
|
|
35
35
|
}
|
|
36
36
|
if (!persistent && keyStorage !== StorageDriver.RAM && keyStorage !== undefined) {
|
|
37
|
-
throw new
|
|
37
|
+
throw new InvalidConfigError('Cannot use a persistent key storage in not persistent mode.');
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
return {
|
|
@@ -58,7 +58,7 @@ const createKeyStorage = (path: string, type?: KeyStorageType) => {
|
|
|
58
58
|
case 'ram':
|
|
59
59
|
return memdown();
|
|
60
60
|
default:
|
|
61
|
-
throw new
|
|
61
|
+
throw new InvalidConfigError(`Invalid key storage type: ${defaultedType}`);
|
|
62
62
|
}
|
|
63
63
|
};
|
|
64
64
|
|
|
@@ -61,7 +61,7 @@ export const createIdentity = async (peer: ServiceContext) => {
|
|
|
61
61
|
return peer;
|
|
62
62
|
};
|
|
63
63
|
|
|
64
|
-
// TODO(
|
|
64
|
+
// TODO(burdon): Remove @dxos/client-testing.
|
|
65
65
|
// TODO(burdon): Create builder and make configurable.
|
|
66
66
|
export const syncItems = async (space1: ISpace, space2: ISpace) => {
|
|
67
67
|
{
|
package/testing.d.ts
ADDED
package/testing.js
ADDED
package/dist/src/errors.d.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { DXOSError } from '@dxos/debug';
|
|
2
|
-
export declare class InvalidConfigurationError extends DXOSError {
|
|
3
|
-
constructor(message: string);
|
|
4
|
-
}
|
|
5
|
-
export declare class RemoteServiceConnectionTimeout extends DXOSError {
|
|
6
|
-
constructor(message?: string);
|
|
7
|
-
}
|
|
8
|
-
//# sourceMappingURL=errors.d.ts.map
|
package/dist/src/errors.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAIxC,qBAAa,yBAA0B,SAAQ,SAAS;gBAC1C,OAAO,EAAE,MAAM;CAG5B;AAED,qBAAa,8BAA+B,SAAQ,SAAS;gBAC/C,OAAO,CAAC,EAAE,MAAM;CAG7B"}
|
package/dist/src/errors.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
//
|
|
3
|
-
// Copyright 2021 DXOS.org
|
|
4
|
-
//
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.RemoteServiceConnectionTimeout = exports.InvalidConfigurationError = void 0;
|
|
7
|
-
const debug_1 = require("@dxos/debug");
|
|
8
|
-
// TODO(burdon): Consolidate with @dxos/echo-db.
|
|
9
|
-
class InvalidConfigurationError extends debug_1.DXOSError {
|
|
10
|
-
constructor(message) {
|
|
11
|
-
super('INVALID_CONFIGURATION', message);
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
exports.InvalidConfigurationError = InvalidConfigurationError;
|
|
15
|
-
class RemoteServiceConnectionTimeout extends debug_1.DXOSError {
|
|
16
|
-
constructor(message) {
|
|
17
|
-
super('REMOTE_SERVICE_CONNECTION_TIMEOUT', message);
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
exports.RemoteServiceConnectionTimeout = RemoteServiceConnectionTimeout;
|
|
21
|
-
//# sourceMappingURL=errors.js.map
|
package/dist/src/errors.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":";AAAA,EAAE;AACF,0BAA0B;AAC1B,EAAE;;;AAEF,uCAAwC;AAExC,gDAAgD;AAEhD,MAAa,yBAA0B,SAAQ,iBAAS;IACtD,YAAY,OAAe;QACzB,KAAK,CAAC,uBAAuB,EAAE,OAAO,CAAC,CAAC;IAC1C,CAAC;CACF;AAJD,8DAIC;AAED,MAAa,8BAA+B,SAAQ,iBAAS;IAC3D,YAAY,OAAgB;QAC1B,KAAK,CAAC,mCAAmC,EAAE,OAAO,CAAC,CAAC;IACtD,CAAC;CACF;AAJD,wEAIC"}
|
package/src/errors.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2021 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import { DXOSError } from '@dxos/debug';
|
|
6
|
-
|
|
7
|
-
// TODO(burdon): Consolidate with @dxos/echo-db.
|
|
8
|
-
|
|
9
|
-
export class InvalidConfigurationError extends DXOSError {
|
|
10
|
-
constructor(message: string) {
|
|
11
|
-
super('INVALID_CONFIGURATION', message);
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export class RemoteServiceConnectionTimeout extends DXOSError {
|
|
16
|
-
constructor(message?: string) {
|
|
17
|
-
super('REMOTE_SERVICE_CONNECTION_TIMEOUT', message);
|
|
18
|
-
}
|
|
19
|
-
}
|