@dxos/client-services 0.1.10 → 0.1.12
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/space.d.ts.map +1 -1
- package/dist/src/packlets/deprecated/space.js +21 -21
- package/dist/src/packlets/deprecated/space.js.map +1 -1
- package/dist/src/packlets/deprecated/system.d.ts +6 -1
- package/dist/src/packlets/deprecated/system.d.ts.map +1 -1
- package/dist/src/packlets/deprecated/system.js +9 -4
- package/dist/src/packlets/deprecated/system.js.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/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.js +5 -5
- package/dist/src/packlets/identity/identity-manager.js.map +1 -1
- package/dist/src/packlets/identity/identity.js +1 -1
- 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 +13 -13
- package/dist/src/packlets/invitations/halo-invitations-handler.js.map +1 -1
- package/dist/src/packlets/invitations/invitations-handler.d.ts +3 -3
- package/dist/src/packlets/invitations/invitations-handler.d.ts.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 +10 -10
- 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 +15 -13
- package/dist/src/packlets/invitations/space-invitations-handler.js.map +1 -1
- package/dist/src/packlets/services/service-context.d.ts +1 -1
- package/dist/src/packlets/services/service-context.d.ts.map +1 -1
- package/dist/src/packlets/services/service-context.js +10 -6
- package/dist/src/packlets/services/service-context.js.map +1 -1
- package/dist/src/packlets/services/service-host.d.ts +6 -2
- package/dist/src/packlets/services/service-host.d.ts.map +1 -1
- package/dist/src/packlets/services/service-host.js +33 -25
- 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.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/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 +17 -8
- package/dist/src/packlets/vault/worker-session.js.map +1 -1
- package/package.json +28 -28
- package/src/index.ts +0 -2
- package/src/packlets/deprecated/space.ts +21 -20
- package/src/packlets/deprecated/system.ts +11 -4
- package/src/packlets/devtools/feeds.ts +2 -1
- package/src/packlets/devtools/spaces.ts +2 -1
- package/src/packlets/invitations/halo-invitations-handler.ts +2 -2
- package/src/packlets/invitations/invitations-handler.ts +3 -3
- package/src/packlets/invitations/invitations-proxy.ts +2 -2
- package/src/packlets/invitations/invitations.ts +6 -11
- package/src/packlets/invitations/space-invitations-handler.ts +4 -2
- package/src/packlets/services/service-context.ts +7 -2
- package/src/packlets/services/service-host.ts +42 -29
- 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/src/packlets/vault/worker-session.ts +16 -9
- 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
|
@@ -18,7 +18,7 @@ import { createProtoRpcPeer } from '@dxos/rpc';
|
|
|
18
18
|
import { IdentityManager } from '../identity';
|
|
19
19
|
import {
|
|
20
20
|
AuthenticatingInvitationProvider,
|
|
21
|
-
|
|
21
|
+
CancellableInvitationObservable,
|
|
22
22
|
InvitationObservableProvider,
|
|
23
23
|
AUTHENTICATION_CODE_LENGTH,
|
|
24
24
|
INVITATION_TIMEOUT,
|
|
@@ -42,7 +42,7 @@ export class HaloInvitationsHandler extends AbstractInvitationsHandler {
|
|
|
42
42
|
/**
|
|
43
43
|
* Creates an invitation and listens for a join request from the invited (guest) peer.
|
|
44
44
|
*/
|
|
45
|
-
createInvitation(context: void, options?: InvitationsOptions):
|
|
45
|
+
createInvitation(context: void, options?: InvitationsOptions): CancellableInvitationObservable {
|
|
46
46
|
let swarmConnection: SwarmConnection | undefined;
|
|
47
47
|
const { type, timeout = INVITATION_TIMEOUT, swarmKey } = options ?? {};
|
|
48
48
|
assert(type !== Invitation.Type.OFFLINE);
|
|
@@ -6,7 +6,7 @@ import { PublicKey } from '@dxos/keys';
|
|
|
6
6
|
import { NetworkManager } from '@dxos/network-manager';
|
|
7
7
|
import { Invitation } from '@dxos/protocols/proto/dxos/client/services';
|
|
8
8
|
|
|
9
|
-
import { AuthenticatingInvitationObservable,
|
|
9
|
+
import { AuthenticatingInvitationObservable, CancellableInvitationObservable } from './invitations';
|
|
10
10
|
|
|
11
11
|
export type InvitationsOptions = {
|
|
12
12
|
type?: Invitation.Type;
|
|
@@ -43,7 +43,7 @@ export type InvitationsOptions = {
|
|
|
43
43
|
* ```
|
|
44
44
|
*/
|
|
45
45
|
export interface InvitationsHandler<T = void> {
|
|
46
|
-
createInvitation(context: T, options?: InvitationsOptions):
|
|
46
|
+
createInvitation(context: T, options?: InvitationsOptions): CancellableInvitationObservable;
|
|
47
47
|
acceptInvitation(invitation: Invitation, options?: InvitationsOptions): AuthenticatingInvitationObservable;
|
|
48
48
|
}
|
|
49
49
|
|
|
@@ -57,6 +57,6 @@ export abstract class AbstractInvitationsHandler<T = void> implements Invitation
|
|
|
57
57
|
protected readonly _networkManager: NetworkManager
|
|
58
58
|
) {}
|
|
59
59
|
|
|
60
|
-
abstract createInvitation(context: T, options?: InvitationsOptions):
|
|
60
|
+
abstract createInvitation(context: T, options?: InvitationsOptions): CancellableInvitationObservable;
|
|
61
61
|
abstract acceptInvitation(invitation: Invitation, options?: InvitationsOptions): AuthenticatingInvitationObservable;
|
|
62
62
|
}
|
|
@@ -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) {
|
|
@@ -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) => {
|
|
@@ -19,7 +19,7 @@ import { createProtoRpcPeer } from '@dxos/rpc';
|
|
|
19
19
|
|
|
20
20
|
import {
|
|
21
21
|
AuthenticatingInvitationProvider,
|
|
22
|
-
|
|
22
|
+
CancellableInvitationObservable,
|
|
23
23
|
InvitationObservableProvider,
|
|
24
24
|
AUTHENTICATION_CODE_LENGTH,
|
|
25
25
|
INVITATION_TIMEOUT,
|
|
@@ -43,7 +43,7 @@ export class SpaceInvitationsHandler extends AbstractInvitationsHandler<Space> {
|
|
|
43
43
|
/**
|
|
44
44
|
* Creates an invitation and listens for a join request from the invited (guest) peer.
|
|
45
45
|
*/
|
|
46
|
-
createInvitation(space: Space, options?: InvitationsOptions):
|
|
46
|
+
createInvitation(space: Space, options?: InvitationsOptions): CancellableInvitationObservable {
|
|
47
47
|
let swarmConnection: SwarmConnection | undefined;
|
|
48
48
|
const { type, timeout = INVITATION_TIMEOUT, swarmKey } = options ?? {};
|
|
49
49
|
assert(type !== Invitation.Type.OFFLINE);
|
|
@@ -104,6 +104,8 @@ export class SpaceInvitationsHandler extends AbstractInvitationsHandler<Space> {
|
|
|
104
104
|
invitation.authenticationCode === undefined ||
|
|
105
105
|
authenticationCode !== invitation.authenticationCode
|
|
106
106
|
) {
|
|
107
|
+
invitation.authenticationCode &&
|
|
108
|
+
log.error('bad auth code', { code: authenticationCode, expected: invitation.authenticationCode });
|
|
107
109
|
throw new Error('authentication code not set');
|
|
108
110
|
}
|
|
109
111
|
}
|
|
@@ -27,6 +27,7 @@ import { HaloInvitationsHandler, SpaceInvitationsHandler } from '../invitations'
|
|
|
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();
|
|
@@ -92,8 +93,12 @@ export class ServiceContext {
|
|
|
92
93
|
log('closed');
|
|
93
94
|
}
|
|
94
95
|
|
|
95
|
-
|
|
96
|
-
|
|
96
|
+
async reset() {
|
|
97
|
+
log('resetting...');
|
|
98
|
+
await this.close();
|
|
99
|
+
await this.storage.reset();
|
|
100
|
+
log('reset');
|
|
101
|
+
}
|
|
97
102
|
|
|
98
103
|
async createIdentity(params: CreateIdentityOptions = {}) {
|
|
99
104
|
const identity = await this.identityManager.createIdentity(params);
|
|
@@ -37,8 +37,12 @@ type ClientServicesHostParams = {
|
|
|
37
37
|
* Remote service implementation.
|
|
38
38
|
*/
|
|
39
39
|
export class ClientServicesHost implements ClientServicesProvider {
|
|
40
|
-
private
|
|
41
|
-
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;
|
|
42
46
|
|
|
43
47
|
constructor({
|
|
44
48
|
config,
|
|
@@ -46,11 +50,42 @@ export class ClientServicesHost implements ClientServicesProvider {
|
|
|
46
50
|
// TODO(burdon): Create ApolloLink abstraction (see Client).
|
|
47
51
|
networkManager
|
|
48
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() {
|
|
49
84
|
// TODO(dmaretskyi): Remove keyStorage.
|
|
50
|
-
const { storage } = createStorageObjects(
|
|
85
|
+
const { storage } = createStorageObjects(this._config.get('runtime.client.storage', {})!);
|
|
51
86
|
|
|
52
87
|
// TODO(burdon): Break into components.
|
|
53
|
-
this._serviceContext = new ServiceContext(storage,
|
|
88
|
+
this._serviceContext = new ServiceContext(storage, this._networkManager, this._modelFactory);
|
|
54
89
|
|
|
55
90
|
// TODO(burdon): Start to think of DMG (dynamic services).
|
|
56
91
|
this._serviceRegistry = new ServiceRegistry<ClientServices>(clientServiceBundle, {
|
|
@@ -74,35 +109,13 @@ export class ClientServicesHost implements ClientServicesProvider {
|
|
|
74
109
|
// TODO(burdon): Move to new protobuf definitions.
|
|
75
110
|
ProfileService: new ProfileServiceImpl(this._serviceContext),
|
|
76
111
|
SpaceService: new SpaceServiceImpl(this._serviceContext),
|
|
77
|
-
SystemService: new SystemServiceImpl(
|
|
78
|
-
TracingService: new TracingServiceImpl(
|
|
112
|
+
SystemService: new SystemServiceImpl(this._config, this._serviceContext),
|
|
113
|
+
TracingService: new TracingServiceImpl(this._config),
|
|
79
114
|
DevtoolsHost: new DevtoolsServiceImpl({
|
|
80
115
|
events: new DevtoolsHostEvents(),
|
|
81
|
-
config,
|
|
116
|
+
config: this._config,
|
|
82
117
|
context: this._serviceContext
|
|
83
118
|
})
|
|
84
119
|
});
|
|
85
120
|
}
|
|
86
|
-
|
|
87
|
-
get descriptors() {
|
|
88
|
-
return this._serviceRegistry.descriptors;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
get services() {
|
|
92
|
-
return this._serviceRegistry.services;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
async open() {
|
|
96
|
-
const deviceKey = this._serviceContext.identityManager.identity?.deviceKey;
|
|
97
|
-
log('opening...', { deviceKey });
|
|
98
|
-
await this._serviceContext.open();
|
|
99
|
-
log('opened', { deviceKey });
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
async close() {
|
|
103
|
-
const deviceKey = this._serviceContext.identityManager.identity?.deviceKey;
|
|
104
|
-
log('closing...', { deviceKey });
|
|
105
|
-
await this._serviceContext.close();
|
|
106
|
-
log('closed', { deviceKey });
|
|
107
|
-
}
|
|
108
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
|
{
|
|
@@ -2,13 +2,15 @@
|
|
|
2
2
|
// Copyright 2022 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
+
import assert from 'assert';
|
|
6
|
+
|
|
5
7
|
import { Trigger } from '@dxos/async';
|
|
6
8
|
import { log } from '@dxos/log';
|
|
7
9
|
import { BridgeService } from '@dxos/protocols/proto/dxos/mesh/bridge';
|
|
8
10
|
import { createProtoRpcPeer, ProtoRpcPeer, RpcPort } from '@dxos/rpc';
|
|
9
11
|
import { Callback } from '@dxos/util';
|
|
10
12
|
|
|
11
|
-
import { clientServiceBundle, ClientServicesHost } from '../services';
|
|
13
|
+
import { clientServiceBundle, ClientServices, ClientServicesHost } from '../services';
|
|
12
14
|
import { IframeServiceBundle, iframeServiceBundle, workerServiceBundle } from './services';
|
|
13
15
|
|
|
14
16
|
export type WorkerSessionParams = {
|
|
@@ -25,8 +27,8 @@ export type WorkerSessionParams = {
|
|
|
25
27
|
* Represents a tab connection within the worker.
|
|
26
28
|
*/
|
|
27
29
|
export class WorkerSession {
|
|
28
|
-
private readonly _clientRpc: ProtoRpcPeer<
|
|
29
|
-
private readonly
|
|
30
|
+
private readonly _clientRpc: ProtoRpcPeer<ClientServices>;
|
|
31
|
+
private readonly _iframeRpc: ProtoRpcPeer<IframeServiceBundle>;
|
|
30
32
|
private readonly _startTrigger = new Trigger();
|
|
31
33
|
private readonly _getServices: () => Promise<ClientServicesHost>;
|
|
32
34
|
private readonly _options: NonNullable<WorkerSessionParams['options']>;
|
|
@@ -42,9 +44,11 @@ export class WorkerSession {
|
|
|
42
44
|
systemPort,
|
|
43
45
|
appPort,
|
|
44
46
|
options = {
|
|
45
|
-
heartbeatInterval:
|
|
47
|
+
heartbeatInterval: 1_000
|
|
46
48
|
}
|
|
47
49
|
}: WorkerSessionParams) {
|
|
50
|
+
assert(options);
|
|
51
|
+
assert(getServices);
|
|
48
52
|
this._options = options;
|
|
49
53
|
this._getServices = getServices;
|
|
50
54
|
|
|
@@ -65,7 +69,7 @@ export class WorkerSession {
|
|
|
65
69
|
port: appPort
|
|
66
70
|
});
|
|
67
71
|
|
|
68
|
-
this.
|
|
72
|
+
this._iframeRpc = createProtoRpcPeer({
|
|
69
73
|
requested: iframeServiceBundle,
|
|
70
74
|
exposed: workerServiceBundle,
|
|
71
75
|
handlers: {
|
|
@@ -90,17 +94,20 @@ export class WorkerSession {
|
|
|
90
94
|
timeout: 200
|
|
91
95
|
});
|
|
92
96
|
|
|
93
|
-
this.bridgeService = this.
|
|
97
|
+
this.bridgeService = this._iframeRpc.rpc.BridgeService;
|
|
94
98
|
}
|
|
95
99
|
|
|
96
100
|
async open() {
|
|
97
|
-
await Promise.all([this._clientRpc.open(), this.
|
|
101
|
+
await Promise.all([this._clientRpc.open(), this._iframeRpc.open()]);
|
|
98
102
|
|
|
99
103
|
await this._startTrigger.wait({ timeout: 3_000 });
|
|
100
104
|
|
|
105
|
+
// Detect if bridge is present.
|
|
106
|
+
// TODO(burdon): Add heartbeat to client's System service.
|
|
107
|
+
// How do we detect if the client's tab closed?
|
|
101
108
|
this._heartbeatTimer = setInterval(async () => {
|
|
102
109
|
try {
|
|
103
|
-
await this.
|
|
110
|
+
await this._iframeRpc.rpc.IframeService.heartbeat();
|
|
104
111
|
} catch (err) {
|
|
105
112
|
try {
|
|
106
113
|
await this.close();
|
|
@@ -122,6 +129,6 @@ export class WorkerSession {
|
|
|
122
129
|
clearInterval(this._heartbeatTimer);
|
|
123
130
|
}
|
|
124
131
|
|
|
125
|
-
await Promise.all([this._clientRpc.close(), this.
|
|
132
|
+
await Promise.all([this._clientRpc.close(), this._iframeRpc.close()]);
|
|
126
133
|
}
|
|
127
134
|
}
|
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
|
-
}
|