@dxos/client-services 0.8.3 → 0.8.4-main.1068cf700f
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/lib/browser/chunk-NQSC7HOE.mjs +22 -0
- package/dist/lib/browser/chunk-NQSC7HOE.mjs.map +7 -0
- package/dist/lib/browser/{chunk-LBG3C332.mjs → chunk-OZGICTH7.mjs} +3864 -3786
- package/dist/lib/browser/chunk-OZGICTH7.mjs.map +7 -0
- package/dist/lib/browser/chunk-QCWEHHJW.mjs +24 -0
- package/dist/lib/browser/chunk-QCWEHHJW.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +474 -80
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/packlets/diagnostics/browser-diagnostics-broadcast.mjs +93 -0
- package/dist/lib/browser/packlets/diagnostics/browser-diagnostics-broadcast.mjs.map +7 -0
- package/dist/lib/browser/packlets/diagnostics/diagnostics-broadcast.mjs +11 -0
- package/dist/lib/browser/packlets/diagnostics/diagnostics-broadcast.mjs.map +7 -0
- package/dist/lib/browser/packlets/locks/browser.mjs +126 -0
- package/dist/lib/browser/packlets/locks/browser.mjs.map +7 -0
- package/dist/lib/browser/packlets/locks/node.mjs +66 -0
- package/dist/lib/browser/packlets/locks/node.mjs.map +7 -0
- package/dist/lib/browser/testing/index.mjs +39 -27
- package/dist/lib/browser/testing/index.mjs.map +3 -3
- package/dist/lib/node-esm/chunk-2SZHAWBN.mjs +24 -0
- package/dist/lib/node-esm/chunk-2SZHAWBN.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-PKEGMOQ4.mjs +22 -0
- package/dist/lib/node-esm/chunk-PKEGMOQ4.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-SKGQLRKS.mjs → chunk-RXHISBCS.mjs} +3551 -3341
- package/dist/lib/node-esm/chunk-RXHISBCS.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +474 -80
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/packlets/diagnostics/browser-diagnostics-broadcast.mjs +93 -0
- package/dist/lib/node-esm/packlets/diagnostics/browser-diagnostics-broadcast.mjs.map +7 -0
- package/dist/lib/node-esm/packlets/diagnostics/diagnostics-broadcast.mjs +11 -0
- package/dist/lib/node-esm/packlets/diagnostics/diagnostics-broadcast.mjs.map +7 -0
- package/dist/lib/node-esm/packlets/locks/browser.mjs +126 -0
- package/dist/lib/node-esm/packlets/locks/browser.mjs.map +7 -0
- package/dist/lib/node-esm/packlets/locks/node.mjs +66 -0
- package/dist/lib/node-esm/packlets/locks/node.mjs.map +7 -0
- package/dist/lib/node-esm/testing/index.mjs +39 -27
- package/dist/lib/node-esm/testing/index.mjs.map +3 -3
- package/dist/types/src/packlets/agents/edge-agent-service.d.ts +1 -1
- package/dist/types/src/packlets/agents/edge-agent-service.d.ts.map +1 -1
- package/dist/types/src/packlets/devices/devices-service.d.ts.map +1 -1
- package/dist/types/src/packlets/devtools/devtools.d.ts +20 -20
- package/dist/types/src/packlets/devtools/devtools.d.ts.map +1 -1
- package/dist/types/src/packlets/devtools/feeds.d.ts +1 -1
- package/dist/types/src/packlets/devtools/feeds.d.ts.map +1 -1
- package/dist/types/src/packlets/devtools/network.d.ts +1 -1
- package/dist/types/src/packlets/devtools/network.d.ts.map +1 -1
- package/dist/types/src/packlets/diagnostics/browser-diagnostics-broadcast.d.ts +1 -1
- package/dist/types/src/packlets/diagnostics/browser-diagnostics-broadcast.d.ts.map +1 -1
- package/dist/types/src/packlets/diagnostics/diagnostics-broadcast.d.ts +1 -1
- package/dist/types/src/packlets/diagnostics/diagnostics-broadcast.d.ts.map +1 -1
- package/dist/types/src/packlets/diagnostics/diagnostics.d.ts +1 -1
- package/dist/types/src/packlets/diagnostics/diagnostics.d.ts.map +1 -1
- package/dist/types/src/packlets/diagnostics/index.d.ts +1 -1
- package/dist/types/src/packlets/diagnostics/index.d.ts.map +1 -1
- package/dist/types/src/packlets/identity/authenticator.d.ts +2 -2
- package/dist/types/src/packlets/identity/authenticator.d.ts.map +1 -1
- package/dist/types/src/packlets/identity/contacts-service.d.ts +1 -1
- package/dist/types/src/packlets/identity/contacts-service.d.ts.map +1 -1
- package/dist/types/src/packlets/identity/default-space-state-machine.d.ts +3 -3
- package/dist/types/src/packlets/identity/default-space-state-machine.d.ts.map +1 -1
- package/dist/types/src/packlets/identity/identity-manager.d.ts +5 -5
- package/dist/types/src/packlets/identity/identity-manager.d.ts.map +1 -1
- package/dist/types/src/packlets/identity/identity-recovery-manager.d.ts +2 -2
- package/dist/types/src/packlets/identity/identity-recovery-manager.d.ts.map +1 -1
- package/dist/types/src/packlets/identity/identity-service.d.ts +1 -1
- package/dist/types/src/packlets/identity/identity-service.d.ts.map +1 -1
- package/dist/types/src/packlets/identity/identity.d.ts +3 -3
- package/dist/types/src/packlets/identity/identity.d.ts.map +1 -1
- package/dist/types/src/packlets/invitations/device-invitation-protocol.d.ts +4 -4
- package/dist/types/src/packlets/invitations/device-invitation-protocol.d.ts.map +1 -1
- package/dist/types/src/packlets/invitations/edge-invitation-handler.d.ts +1 -1
- package/dist/types/src/packlets/invitations/edge-invitation-handler.d.ts.map +1 -1
- package/dist/types/src/packlets/invitations/index.d.ts +1 -1
- package/dist/types/src/packlets/invitations/index.d.ts.map +1 -1
- package/dist/types/src/packlets/invitations/invitation-guest-extenstion.d.ts.map +1 -1
- package/dist/types/src/packlets/invitations/invitation-host-extension.d.ts.map +1 -1
- package/dist/types/src/packlets/invitations/invitation-protocol.d.ts +3 -4
- package/dist/types/src/packlets/invitations/invitation-protocol.d.ts.map +1 -1
- package/dist/types/src/packlets/invitations/invitations-handler.d.ts +4 -4
- package/dist/types/src/packlets/invitations/invitations-handler.d.ts.map +1 -1
- package/dist/types/src/packlets/invitations/invitations-manager.d.ts.map +1 -1
- package/dist/types/src/packlets/invitations/invitations-service.d.ts +1 -1
- package/dist/types/src/packlets/invitations/invitations-service.d.ts.map +1 -1
- package/dist/types/src/packlets/invitations/space-invitation-protocol.d.ts +3 -3
- package/dist/types/src/packlets/invitations/space-invitation-protocol.d.ts.map +1 -1
- package/dist/types/src/packlets/invitations/utils.d.ts.map +1 -1
- package/dist/types/src/packlets/locks/index.d.ts +2 -2
- package/dist/types/src/packlets/locks/index.d.ts.map +1 -1
- package/dist/types/src/packlets/logging/logging-service.d.ts +5 -1
- package/dist/types/src/packlets/logging/logging-service.d.ts.map +1 -1
- package/dist/types/src/packlets/network/network-service.d.ts +2 -2
- package/dist/types/src/packlets/network/network-service.d.ts.map +1 -1
- package/dist/types/src/packlets/services/client-rpc-server.d.ts +2 -2
- package/dist/types/src/packlets/services/client-rpc-server.d.ts.map +1 -1
- package/dist/types/src/packlets/services/feed-syncer.d.ts +41 -0
- package/dist/types/src/packlets/services/feed-syncer.d.ts.map +1 -0
- package/dist/types/src/packlets/services/platform.d.ts.map +1 -1
- package/dist/types/src/packlets/services/service-context.d.ts +14 -8
- package/dist/types/src/packlets/services/service-context.d.ts.map +1 -1
- package/dist/types/src/packlets/services/service-host.d.ts +20 -6
- package/dist/types/src/packlets/services/service-host.d.ts.map +1 -1
- package/dist/types/src/packlets/space-export/space-archive-writer.d.ts +1 -1
- package/dist/types/src/packlets/space-export/space-archive-writer.d.ts.map +1 -1
- package/dist/types/src/packlets/spaces/automerge-space-state.d.ts +1 -1
- package/dist/types/src/packlets/spaces/automerge-space-state.d.ts.map +1 -1
- package/dist/types/src/packlets/spaces/data-space-manager.d.ts +12 -7
- package/dist/types/src/packlets/spaces/data-space-manager.d.ts.map +1 -1
- package/dist/types/src/packlets/spaces/data-space.d.ts +6 -6
- package/dist/types/src/packlets/spaces/data-space.d.ts.map +1 -1
- package/dist/types/src/packlets/spaces/edge-feed-replicator.d.ts +2 -2
- package/dist/types/src/packlets/spaces/edge-feed-replicator.d.ts.map +1 -1
- package/dist/types/src/packlets/spaces/notarization-plugin.d.ts +6 -6
- package/dist/types/src/packlets/spaces/notarization-plugin.d.ts.map +1 -1
- package/dist/types/src/packlets/spaces/spaces-service.d.ts +2 -2
- package/dist/types/src/packlets/spaces/spaces-service.d.ts.map +1 -1
- package/dist/types/src/packlets/storage/profile-archive.d.ts.map +1 -1
- package/dist/types/src/packlets/storage/storage.d.ts.map +1 -1
- package/dist/types/src/packlets/system/system-service.d.ts +1 -1
- package/dist/types/src/packlets/system/system-service.d.ts.map +1 -1
- package/dist/types/src/packlets/testing/invitation-utils.d.ts +6 -3
- package/dist/types/src/packlets/testing/invitation-utils.d.ts.map +1 -1
- package/dist/types/src/packlets/testing/test-builder.d.ts +8 -7
- package/dist/types/src/packlets/testing/test-builder.d.ts.map +1 -1
- package/dist/types/src/packlets/worker/worker-runtime.d.ts +31 -4
- package/dist/types/src/packlets/worker/worker-runtime.d.ts.map +1 -1
- package/dist/types/src/packlets/worker/worker-session.d.ts +2 -2
- package/dist/types/src/packlets/worker/worker-session.d.ts.map +1 -1
- package/dist/types/src/version.d.ts +1 -1
- package/dist/types/src/version.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +72 -48
- package/src/packlets/agents/edge-agent-manager.ts +2 -2
- package/src/packlets/agents/edge-agent-service.ts +13 -3
- package/src/packlets/devices/devices-service.test.ts +4 -3
- package/src/packlets/devices/devices-service.ts +2 -2
- package/src/packlets/devtools/devtools.ts +30 -29
- package/src/packlets/devtools/feeds.ts +2 -2
- package/src/packlets/devtools/network.ts +1 -1
- package/src/packlets/diagnostics/browser-diagnostics-broadcast.ts +1 -1
- package/src/packlets/diagnostics/diagnostics-broadcast.ts +1 -1
- package/src/packlets/diagnostics/diagnostics-collector.ts +1 -1
- package/src/packlets/diagnostics/diagnostics.ts +1 -1
- package/src/packlets/diagnostics/index.ts +1 -1
- package/src/packlets/identity/authenticator.node.test.ts +1 -1
- package/src/packlets/identity/authenticator.ts +3 -3
- package/src/packlets/identity/contacts-service.ts +3 -2
- package/src/packlets/identity/default-space-state-machine.ts +3 -3
- package/src/packlets/identity/identity-manager.test.ts +3 -3
- package/src/packlets/identity/identity-manager.ts +9 -9
- package/src/packlets/identity/identity-recovery-manager.ts +2 -2
- package/src/packlets/identity/identity-service.test.ts +3 -2
- package/src/packlets/identity/identity-service.ts +2 -1
- package/src/packlets/identity/identity.test.ts +9 -9
- package/src/packlets/identity/identity.ts +9 -8
- package/src/packlets/invitations/device-invitation-protocol.test.ts +4 -4
- package/src/packlets/invitations/device-invitation-protocol.ts +6 -5
- package/src/packlets/invitations/edge-invitation-handler.ts +1 -1
- package/src/packlets/invitations/index.ts +1 -1
- package/src/packlets/invitations/invitation-guest-extenstion.ts +7 -5
- package/src/packlets/invitations/invitation-host-extension.ts +8 -6
- package/src/packlets/invitations/invitation-protocol.ts +3 -4
- package/src/packlets/invitations/invitations-handler.test.ts +302 -292
- package/src/packlets/invitations/invitations-handler.ts +10 -10
- package/src/packlets/invitations/invitations-manager.ts +3 -3
- package/src/packlets/invitations/invitations-service.ts +1 -1
- package/src/packlets/invitations/space-invitation-protocol.test.ts +9 -9
- package/src/packlets/invitations/space-invitation-protocol.ts +10 -15
- package/src/packlets/invitations/utils.ts +1 -1
- package/src/packlets/locks/browser.ts +1 -1
- package/src/packlets/locks/index.ts +2 -2
- package/src/packlets/logging/logging-service.ts +8 -3
- package/src/packlets/logging/logging.test.ts +1 -1
- package/src/packlets/network/network-service.test.ts +4 -3
- package/src/packlets/network/network-service.ts +2 -2
- package/src/packlets/services/client-rpc-server.ts +5 -5
- package/src/packlets/services/feed-syncer.ts +227 -0
- package/src/packlets/services/platform.ts +7 -1
- package/src/packlets/services/service-context.test.ts +1 -1
- package/src/packlets/services/service-context.ts +56 -29
- package/src/packlets/services/service-host.test.ts +3 -2
- package/src/packlets/services/service-host.ts +78 -29
- package/src/packlets/services/service-registry.test.ts +2 -1
- package/src/packlets/space-export/space-archive-reader.ts +2 -2
- package/src/packlets/space-export/space-archive-writer.ts +7 -5
- package/src/packlets/space-export/tar.test.ts +1 -1
- package/src/packlets/spaces/automerge-space-state.ts +1 -1
- package/src/packlets/spaces/data-space-manager.ts +76 -36
- package/src/packlets/spaces/data-space.ts +18 -13
- package/src/packlets/spaces/edge-feed-replicator.test.ts +3 -3
- package/src/packlets/spaces/edge-feed-replicator.ts +4 -4
- package/src/packlets/spaces/epoch-migrations.ts +2 -2
- package/src/packlets/spaces/notarization-plugin.test.ts +3 -3
- package/src/packlets/spaces/notarization-plugin.ts +11 -11
- package/src/packlets/spaces/spaces-service.test.ts +3 -2
- package/src/packlets/spaces/spaces-service.ts +27 -23
- package/src/packlets/storage/profile-archive.ts +1 -1
- package/src/packlets/storage/storage.ts +7 -8
- package/src/packlets/system/system-service.test.ts +1 -1
- package/src/packlets/system/system-service.ts +4 -4
- package/src/packlets/testing/invitation-utils.ts +8 -5
- package/src/packlets/testing/test-builder.ts +39 -13
- package/src/packlets/worker/worker-runtime.ts +151 -12
- package/src/packlets/worker/worker-session.ts +7 -7
- package/src/version.ts +1 -5
- package/README.yml +0 -5
- package/dist/lib/browser/chunk-LBG3C332.mjs.map +0 -7
- package/dist/lib/node/chunk-LMGLGOUU.cjs +0 -9311
- package/dist/lib/node/chunk-LMGLGOUU.cjs.map +0 -7
- package/dist/lib/node/index.cjs +0 -437
- package/dist/lib/node/index.cjs.map +0 -7
- package/dist/lib/node/meta.json +0 -1
- package/dist/lib/node/testing/index.cjs +0 -452
- package/dist/lib/node/testing/index.cjs.map +0 -7
- package/dist/lib/node-esm/chunk-SKGQLRKS.mjs.map +0 -7
|
@@ -19,44 +19,45 @@ import { assertArgument, assertState, invariant } from '@dxos/invariant';
|
|
|
19
19
|
import { SpaceId } from '@dxos/keys';
|
|
20
20
|
import { log } from '@dxos/log';
|
|
21
21
|
import {
|
|
22
|
-
encodeError,
|
|
23
22
|
ApiError,
|
|
24
23
|
AuthorizationError,
|
|
25
24
|
IdentityNotInitializedError,
|
|
26
25
|
SpaceNotFoundError,
|
|
26
|
+
encodeError,
|
|
27
27
|
} from '@dxos/protocols';
|
|
28
28
|
import {
|
|
29
|
-
|
|
30
|
-
|
|
29
|
+
type AdmitContactRequest,
|
|
30
|
+
type ContactAdmission,
|
|
31
31
|
type CreateEpochRequest,
|
|
32
|
+
type CreateEpochResponse,
|
|
33
|
+
type ExportSpaceRequest,
|
|
34
|
+
type ExportSpaceResponse,
|
|
35
|
+
type ImportSpaceRequest,
|
|
36
|
+
type ImportSpaceResponse,
|
|
37
|
+
type JoinBySpaceKeyRequest,
|
|
38
|
+
type JoinSpaceResponse,
|
|
32
39
|
type PostMessageRequest,
|
|
33
40
|
type QueryCredentialsRequest,
|
|
34
41
|
type QuerySpacesResponse,
|
|
35
42
|
type Space,
|
|
43
|
+
SpaceMember,
|
|
44
|
+
SpaceState,
|
|
36
45
|
type SpacesService,
|
|
37
46
|
type SubscribeMessagesRequest,
|
|
47
|
+
type UpdateMemberRoleRequest,
|
|
38
48
|
type UpdateSpaceRequest,
|
|
39
49
|
type WriteCredentialsRequest,
|
|
40
|
-
type UpdateMemberRoleRequest,
|
|
41
|
-
type AdmitContactRequest,
|
|
42
|
-
type ContactAdmission,
|
|
43
|
-
type JoinSpaceResponse,
|
|
44
|
-
type JoinBySpaceKeyRequest,
|
|
45
|
-
type CreateEpochResponse,
|
|
46
|
-
type ExportSpaceResponse,
|
|
47
|
-
type ExportSpaceRequest,
|
|
48
|
-
type ImportSpaceRequest,
|
|
49
|
-
type ImportSpaceResponse,
|
|
50
50
|
} from '@dxos/protocols/proto/dxos/client/services';
|
|
51
51
|
import { type Credential } from '@dxos/protocols/proto/dxos/halo/credentials';
|
|
52
52
|
import { type GossipMessage } from '@dxos/protocols/proto/dxos/mesh/teleport/gossip';
|
|
53
53
|
import { trace } from '@dxos/tracing';
|
|
54
54
|
import { type Provider } from '@dxos/util';
|
|
55
55
|
|
|
56
|
+
import { type IdentityManager } from '../identity';
|
|
57
|
+
import { SpaceArchiveWriter, extractSpaceArchive } from '../space-export';
|
|
58
|
+
|
|
56
59
|
import { type DataSpace } from './data-space';
|
|
57
60
|
import { type DataSpaceManager } from './data-space-manager';
|
|
58
|
-
import { type IdentityManager } from '../identity';
|
|
59
|
-
import { extractSpaceArchive, SpaceArchiveWriter } from '../space-export';
|
|
60
61
|
|
|
61
62
|
export class SpacesServiceImpl implements SpacesService {
|
|
62
63
|
constructor(
|
|
@@ -87,7 +88,7 @@ export class SpacesServiceImpl implements SpacesService {
|
|
|
87
88
|
await space.deactivate();
|
|
88
89
|
break;
|
|
89
90
|
default:
|
|
90
|
-
throw new ApiError('Invalid space state');
|
|
91
|
+
throw new ApiError({ message: 'Invalid space state' });
|
|
91
92
|
}
|
|
92
93
|
}
|
|
93
94
|
|
|
@@ -103,9 +104,12 @@ export class SpacesServiceImpl implements SpacesService {
|
|
|
103
104
|
throw new SpaceNotFoundError(request.spaceKey);
|
|
104
105
|
}
|
|
105
106
|
if (!space.spaceState.hasMembershipManagementPermission(identity.identityKey)) {
|
|
106
|
-
throw new AuthorizationError(
|
|
107
|
-
|
|
108
|
-
|
|
107
|
+
throw new AuthorizationError({
|
|
108
|
+
message: 'No member management permission.',
|
|
109
|
+
context: {
|
|
110
|
+
spaceKey: space.key,
|
|
111
|
+
role: space.spaceState.getMemberRole(identity.identityKey),
|
|
112
|
+
},
|
|
109
113
|
});
|
|
110
114
|
}
|
|
111
115
|
const credentials = await createAdmissionCredentials(
|
|
@@ -266,7 +270,7 @@ export class SpacesServiceImpl implements SpacesService {
|
|
|
266
270
|
|
|
267
271
|
async exportSpace(request: ExportSpaceRequest): Promise<ExportSpaceResponse> {
|
|
268
272
|
await using writer = await new SpaceArchiveWriter().open();
|
|
269
|
-
assertArgument(SpaceId.isValid(request.spaceId), 'Invalid space ID');
|
|
273
|
+
assertArgument(SpaceId.isValid(request.spaceId), 'spaceId', 'Invalid space ID');
|
|
270
274
|
|
|
271
275
|
const dataSpaceManager = await this._getDataSpaceManager();
|
|
272
276
|
const space = dataSpaceManager.getSpaceById(request.spaceId) ?? raise(new Error('Space not found'));
|
|
@@ -367,9 +371,9 @@ export class SpacesServiceImpl implements SpacesService {
|
|
|
367
371
|
|
|
368
372
|
private _requireIdentity() {
|
|
369
373
|
if (!this._identityManager.identity) {
|
|
370
|
-
throw new IdentityNotInitializedError(
|
|
371
|
-
'This device has no HALO identity available. See https://docs.dxos.org/guide/platform/halo',
|
|
372
|
-
);
|
|
374
|
+
throw new IdentityNotInitializedError({
|
|
375
|
+
message: 'This device has no HALO identity available. See https://docs.dxos.org/guide/platform/halo',
|
|
376
|
+
});
|
|
373
377
|
}
|
|
374
378
|
return this._identityManager.identity;
|
|
375
379
|
}
|
|
@@ -7,7 +7,7 @@ import { cbor } from '@automerge/automerge-repo';
|
|
|
7
7
|
import { invariant } from '@dxos/invariant';
|
|
8
8
|
import type { LevelDB } from '@dxos/kv-store';
|
|
9
9
|
import { log } from '@dxos/log';
|
|
10
|
-
import {
|
|
10
|
+
import { type ProfileArchive, ProfileArchiveEntryType } from '@dxos/protocols';
|
|
11
11
|
import type { Storage } from '@dxos/random-access-storage';
|
|
12
12
|
import { arrayToBuffer } from '@dxos/util';
|
|
13
13
|
|
|
@@ -1,30 +1,29 @@
|
|
|
1
|
-
//
|
|
2
|
-
|
|
3
1
|
//
|
|
4
2
|
// Copyright 2023 DXOS.org
|
|
5
3
|
//
|
|
6
4
|
|
|
7
5
|
import { InvalidConfigError } from '@dxos/protocols';
|
|
8
6
|
import { Runtime } from '@dxos/protocols/proto/dxos/config';
|
|
9
|
-
import {
|
|
7
|
+
import { StorageType, createStorage } from '@dxos/random-access-storage';
|
|
10
8
|
|
|
11
|
-
import StorageDriver = Runtime.Client.Storage.StorageDriver;
|
|
12
9
|
import { getRootPath } from './util';
|
|
13
10
|
|
|
11
|
+
import StorageDriver = Runtime.Client.Storage.StorageDriver;
|
|
12
|
+
|
|
14
13
|
// TODO(burdon): Factor out.
|
|
15
14
|
export const createStorageObjects = (config: Runtime.Client.Storage) => {
|
|
16
15
|
const { persistent = false, keyStore, dataStore } = config ?? {};
|
|
17
16
|
if (persistent && dataStore === StorageDriver.RAM) {
|
|
18
|
-
throw new InvalidConfigError('RAM storage cannot be used in persistent mode.');
|
|
17
|
+
throw new InvalidConfigError({ message: 'RAM storage cannot be used in persistent mode.' });
|
|
19
18
|
}
|
|
20
19
|
if (!persistent && dataStore !== undefined && dataStore !== StorageDriver.RAM) {
|
|
21
|
-
throw new InvalidConfigError('Cannot use a persistent storage in not persistent mode.');
|
|
20
|
+
throw new InvalidConfigError({ message: 'Cannot use a persistent storage in not persistent mode.' });
|
|
22
21
|
}
|
|
23
22
|
if (persistent && keyStore === StorageDriver.RAM) {
|
|
24
|
-
throw new InvalidConfigError('RAM key storage cannot be used in persistent mode.');
|
|
23
|
+
throw new InvalidConfigError({ message: 'RAM key storage cannot be used in persistent mode.' });
|
|
25
24
|
}
|
|
26
25
|
if (!persistent && keyStore !== StorageDriver.RAM && keyStore !== undefined) {
|
|
27
|
-
throw new InvalidConfigError('Cannot use a persistent key storage in not persistent mode.');
|
|
26
|
+
throw new InvalidConfigError({ message: 'Cannot use a persistent key storage in not persistent mode.' });
|
|
28
27
|
}
|
|
29
28
|
|
|
30
29
|
return {
|
|
@@ -6,7 +6,7 @@ import { beforeEach, describe, expect, test } from 'vitest';
|
|
|
6
6
|
|
|
7
7
|
import { Event, Trigger } from '@dxos/async';
|
|
8
8
|
import { Config } from '@dxos/config';
|
|
9
|
-
import { type SystemService, SystemStatus
|
|
9
|
+
import { type QueryStatusResponse, type SystemService, SystemStatus } from '@dxos/protocols/proto/dxos/client/services';
|
|
10
10
|
|
|
11
11
|
import { SystemServiceImpl } from './system-service';
|
|
12
12
|
|
|
@@ -7,14 +7,14 @@ import { Stream } from '@dxos/codec-protobuf/stream';
|
|
|
7
7
|
import { type Config } from '@dxos/config';
|
|
8
8
|
import {
|
|
9
9
|
GetDiagnosticsRequest,
|
|
10
|
+
type Platform,
|
|
11
|
+
type QueryStatusRequest,
|
|
12
|
+
type QueryStatusResponse,
|
|
10
13
|
type SystemService,
|
|
11
14
|
type SystemStatus,
|
|
12
15
|
type UpdateStatusRequest,
|
|
13
|
-
type QueryStatusRequest,
|
|
14
|
-
type QueryStatusResponse,
|
|
15
|
-
type Platform,
|
|
16
16
|
} from '@dxos/protocols/proto/dxos/client/services';
|
|
17
|
-
import {
|
|
17
|
+
import { type MaybePromise, jsonKeyReplacer } from '@dxos/util';
|
|
18
18
|
|
|
19
19
|
import { type Diagnostics } from '../diagnostics';
|
|
20
20
|
import { getPlatform } from '../services/platform';
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
//
|
|
4
4
|
|
|
5
5
|
import { Trigger } from '@dxos/async';
|
|
6
|
-
import {
|
|
6
|
+
import { type AuthenticatingInvitation, type CancellableInvitation, InvitationEncoder } from '@dxos/client-protocol';
|
|
7
7
|
import { invariant } from '@dxos/invariant';
|
|
8
8
|
import { Invitation } from '@dxos/protocols/proto/dxos/client/services';
|
|
9
9
|
import { type DeviceProfileDocument } from '@dxos/protocols/proto/dxos/halo/credentials';
|
|
@@ -36,15 +36,15 @@ export type PerformInvitationCallbacks<T> = {
|
|
|
36
36
|
onError?: (value: T) => boolean | void;
|
|
37
37
|
};
|
|
38
38
|
|
|
39
|
-
export type
|
|
39
|
+
export type PerformInvitationProps = {
|
|
40
40
|
host: ServiceContext | InvitationHost;
|
|
41
41
|
guest: ServiceContext | InvitationGuest;
|
|
42
|
+
guestDeviceProfile?: DeviceProfileDocument;
|
|
42
43
|
options?: Partial<Invitation>;
|
|
43
44
|
hooks?: {
|
|
44
45
|
host?: PerformInvitationCallbacks<CancellableInvitation>;
|
|
45
46
|
guest?: PerformInvitationCallbacks<AuthenticatingInvitation>;
|
|
46
47
|
};
|
|
47
|
-
guestDeviceProfile?: DeviceProfileDocument;
|
|
48
48
|
codeInputDelay?: number;
|
|
49
49
|
};
|
|
50
50
|
|
|
@@ -52,14 +52,17 @@ export type Result = { invitation?: Invitation; error?: Error };
|
|
|
52
52
|
|
|
53
53
|
// TODO(burdon): Make async.
|
|
54
54
|
// TODO(burdon): Rename startInvitation.
|
|
55
|
+
/**
|
|
56
|
+
*
|
|
57
|
+
*/
|
|
55
58
|
export const performInvitation = ({
|
|
56
59
|
host,
|
|
57
60
|
guest,
|
|
61
|
+
guestDeviceProfile,
|
|
58
62
|
options,
|
|
59
63
|
hooks,
|
|
60
|
-
guestDeviceProfile,
|
|
61
64
|
codeInputDelay,
|
|
62
|
-
}:
|
|
65
|
+
}: PerformInvitationProps): [Promise<Result>, Promise<Result>] => {
|
|
63
66
|
let guestError = false;
|
|
64
67
|
let guestConnected = false;
|
|
65
68
|
let wereConnected = false;
|
|
@@ -2,11 +2,15 @@
|
|
|
2
2
|
// Copyright 2022 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
+
import * as Reactivity from '@effect/experimental/Reactivity';
|
|
6
|
+
import * as Layer from 'effect/Layer';
|
|
7
|
+
import * as ManagedRuntime from 'effect/ManagedRuntime';
|
|
8
|
+
|
|
5
9
|
import { type Config } from '@dxos/config';
|
|
6
10
|
import { Context } from '@dxos/context';
|
|
7
|
-
import {
|
|
11
|
+
import { CredentialGenerator, createCredentialSignerWithChain } from '@dxos/credentials';
|
|
8
12
|
import { failUndefined } from '@dxos/debug';
|
|
9
|
-
import { EchoHost, MetadataStore, SpaceManager, valueEncoding
|
|
13
|
+
import { EchoHost, MeshEchoReplicator, MetadataStore, SpaceManager, valueEncoding } from '@dxos/echo-pipeline';
|
|
10
14
|
import { FeedFactory, FeedStore } from '@dxos/feed-store';
|
|
11
15
|
import { Keyring } from '@dxos/keyring';
|
|
12
16
|
import { type LevelDB } from '@dxos/kv-store';
|
|
@@ -14,12 +18,14 @@ import { createTestLevel } from '@dxos/kv-store/testing';
|
|
|
14
18
|
import { MemorySignalManager, MemorySignalManagerContext, type SignalManager } from '@dxos/messaging';
|
|
15
19
|
import { MemoryTransportFactory, SwarmNetworkManager } from '@dxos/network-manager';
|
|
16
20
|
import { Invitation } from '@dxos/protocols/proto/dxos/client/services';
|
|
17
|
-
import {
|
|
21
|
+
import { type Storage, StorageType, createStorage } from '@dxos/random-access-storage';
|
|
22
|
+
import { layerMemory as sqliteLayerMemory } from '@dxos/sql-sqlite/platform';
|
|
23
|
+
import * as SqlTransaction from '@dxos/sql-sqlite/SqlTransaction';
|
|
18
24
|
import { BlobStore } from '@dxos/teleport-extension-object-sync';
|
|
19
25
|
|
|
20
26
|
import { InvitationsHandler, InvitationsManager, SpaceInvitationProtocol } from '../invitations';
|
|
21
|
-
import { ClientServicesHost, ServiceContext, type
|
|
22
|
-
import { DataSpaceManager, type
|
|
27
|
+
import { ClientServicesHost, ServiceContext, type ServiceContextRuntimeProps } from '../services';
|
|
28
|
+
import { DataSpaceManager, type DataSpaceManagerRuntimeProps, type SigningContext } from '../spaces';
|
|
23
29
|
|
|
24
30
|
//
|
|
25
31
|
// TODO(burdon): Replace with test builder.
|
|
@@ -30,6 +36,11 @@ export const createServiceHost = (config: Config, signalManagerContext: MemorySi
|
|
|
30
36
|
config,
|
|
31
37
|
signalManager: new MemorySignalManager(signalManagerContext),
|
|
32
38
|
transportFactory: MemoryTransportFactory,
|
|
39
|
+
runtime: ManagedRuntime.make(
|
|
40
|
+
SqlTransaction.layer
|
|
41
|
+
.pipe(Layer.provideMerge(sqliteLayerMemory), Layer.provideMerge(Reactivity.layer))
|
|
42
|
+
.pipe(Layer.orDie),
|
|
43
|
+
).runtimeEffect,
|
|
33
44
|
});
|
|
34
45
|
};
|
|
35
46
|
|
|
@@ -39,11 +50,11 @@ export const createServiceContext = async ({
|
|
|
39
50
|
return new MemorySignalManager(signalContext);
|
|
40
51
|
},
|
|
41
52
|
storage = createStorage({ type: StorageType.RAM }),
|
|
42
|
-
|
|
53
|
+
runtimeProps,
|
|
43
54
|
}: {
|
|
44
55
|
signalManagerFactory?: () => Promise<SignalManager>;
|
|
45
56
|
storage?: Storage;
|
|
46
|
-
|
|
57
|
+
runtimeProps?: ServiceContextRuntimeProps;
|
|
47
58
|
} = {}) => {
|
|
48
59
|
const signalManager = await signalManagerFactory();
|
|
49
60
|
const networkManager = new SwarmNetworkManager({
|
|
@@ -53,9 +64,15 @@ export const createServiceContext = async ({
|
|
|
53
64
|
const level = createTestLevel();
|
|
54
65
|
await level.open();
|
|
55
66
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
67
|
+
const runtime = ManagedRuntime.make(
|
|
68
|
+
SqlTransaction.layer
|
|
69
|
+
.pipe(Layer.provideMerge(sqliteLayerMemory), Layer.provideMerge(Reactivity.layer))
|
|
70
|
+
.pipe(Layer.orDie),
|
|
71
|
+
).runtimeEffect;
|
|
72
|
+
|
|
73
|
+
return new ServiceContext(storage, level, networkManager, signalManager, undefined, undefined, runtime, {
|
|
74
|
+
invitationConnectionDefaultProps: { teleport: { controlHeartbeatInterval: 200 } },
|
|
75
|
+
...runtimeProps,
|
|
59
76
|
});
|
|
60
77
|
};
|
|
61
78
|
|
|
@@ -95,7 +112,7 @@ export class TestBuilder {
|
|
|
95
112
|
|
|
96
113
|
export type TestPeerOpts = {
|
|
97
114
|
dataStore?: StorageType;
|
|
98
|
-
|
|
115
|
+
dataSpaceProps?: DataSpaceManagerRuntimeProps;
|
|
99
116
|
};
|
|
100
117
|
|
|
101
118
|
export type TestPeerProps = {
|
|
@@ -116,6 +133,11 @@ export type TestPeerProps = {
|
|
|
116
133
|
|
|
117
134
|
export class TestPeer {
|
|
118
135
|
private _props: TestPeerProps = {};
|
|
136
|
+
private readonly _runtime = ManagedRuntime.make(
|
|
137
|
+
SqlTransaction.layer
|
|
138
|
+
.pipe(Layer.provideMerge(sqliteLayerMemory), Layer.provideMerge(Reactivity.layer))
|
|
139
|
+
.pipe(Layer.orDie),
|
|
140
|
+
);
|
|
119
141
|
|
|
120
142
|
constructor(
|
|
121
143
|
private readonly _signalContext: MemorySignalManagerContext,
|
|
@@ -179,7 +201,10 @@ export class TestPeer {
|
|
|
179
201
|
}
|
|
180
202
|
|
|
181
203
|
get echoHost() {
|
|
182
|
-
return (this._props.echoHost ??= new EchoHost({
|
|
204
|
+
return (this._props.echoHost ??= new EchoHost({
|
|
205
|
+
kv: this.level,
|
|
206
|
+
runtime: this._runtime.runtimeEffect,
|
|
207
|
+
}));
|
|
183
208
|
}
|
|
184
209
|
|
|
185
210
|
get meshEchoReplicator() {
|
|
@@ -198,7 +223,7 @@ export class TestPeer {
|
|
|
198
223
|
edgeConnection: undefined,
|
|
199
224
|
meshReplicator: this.meshEchoReplicator,
|
|
200
225
|
echoEdgeReplicator: undefined,
|
|
201
|
-
|
|
226
|
+
runtimeProps: this._opts.dataSpaceProps,
|
|
202
227
|
}));
|
|
203
228
|
}
|
|
204
229
|
|
|
@@ -227,6 +252,7 @@ export class TestPeer {
|
|
|
227
252
|
async destroy(): Promise<void> {
|
|
228
253
|
await this.level.close();
|
|
229
254
|
await this.storage.reset();
|
|
255
|
+
await this._runtime.dispose();
|
|
230
256
|
}
|
|
231
257
|
}
|
|
232
258
|
|
|
@@ -2,6 +2,12 @@
|
|
|
2
2
|
// Copyright 2022 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
+
import * as Reactivity from '@effect/experimental/Reactivity';
|
|
6
|
+
import type * as SqlClient from '@effect/sql/SqlClient';
|
|
7
|
+
import * as Effect from 'effect/Effect';
|
|
8
|
+
import * as Layer from 'effect/Layer';
|
|
9
|
+
import * as ManagedRuntime from 'effect/ManagedRuntime';
|
|
10
|
+
|
|
5
11
|
import { Trigger } from '@dxos/async';
|
|
6
12
|
import { DEFAULT_WORKER_BROADCAST_CHANNEL } from '@dxos/client-protocol';
|
|
7
13
|
import { type Config } from '@dxos/config';
|
|
@@ -16,16 +22,22 @@ import {
|
|
|
16
22
|
} from '@dxos/messaging';
|
|
17
23
|
import { RtcTransportProxyFactory } from '@dxos/network-manager';
|
|
18
24
|
import { type RpcPort } from '@dxos/rpc';
|
|
25
|
+
import * as OpfsWorker from '@dxos/sql-sqlite/OpfsWorker';
|
|
26
|
+
import * as SqlExport from '@dxos/sql-sqlite/SqlExport';
|
|
27
|
+
import * as SqliteClient from '@dxos/sql-sqlite/SqliteClient';
|
|
28
|
+
import * as SqlTransaction from '@dxos/sql-sqlite/SqlTransaction';
|
|
19
29
|
import { type MaybePromise } from '@dxos/util';
|
|
20
30
|
|
|
21
|
-
import { WorkerSession } from './worker-session';
|
|
22
31
|
import { ClientServicesHost } from '../services';
|
|
23
32
|
|
|
33
|
+
import { WorkerSession } from './worker-session';
|
|
34
|
+
|
|
24
35
|
// NOTE: Keep as RpcPorts to avoid dependency on @dxos/rpc-tunnel so we don't depend on browser-specific apis.
|
|
25
|
-
export type
|
|
36
|
+
export type CreateSessionProps = {
|
|
26
37
|
appPort: RpcPort;
|
|
27
38
|
systemPort: RpcPort;
|
|
28
39
|
shellPort?: RpcPort;
|
|
40
|
+
onClose?: () => Promise<void>;
|
|
29
41
|
};
|
|
30
42
|
|
|
31
43
|
export type WorkerRuntimeOptions = {
|
|
@@ -34,10 +46,20 @@ export type WorkerRuntimeOptions = {
|
|
|
34
46
|
acquireLock: () => Promise<void>;
|
|
35
47
|
releaseLock: () => void;
|
|
36
48
|
onStop?: () => Promise<void>;
|
|
49
|
+
/**
|
|
50
|
+
* @default true
|
|
51
|
+
*/
|
|
52
|
+
automaticallyConnectWebrtc?: boolean;
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Optional SQLite layer for Effect. Defaults to LocalSqliteOpfsLayer.
|
|
56
|
+
* For testing in Node.js, use `sqliteLayerMemory` from `@dxos/sql-sqlite/platform`.
|
|
57
|
+
*/
|
|
58
|
+
sqliteLayer?: Layer.Layer<SqlClient.SqlClient | SqlExport.SqlExport, unknown>;
|
|
37
59
|
};
|
|
38
60
|
|
|
39
61
|
/**
|
|
40
|
-
* Runtime for the shared worker.
|
|
62
|
+
* Runtime for the shared and dedciated worker.
|
|
41
63
|
* Manages connections from proxies (in tabs).
|
|
42
64
|
* Tabs make requests to the `ClientServicesHost`, and provide a WebRTC gateway.
|
|
43
65
|
*/
|
|
@@ -51,11 +73,17 @@ export class WorkerRuntime {
|
|
|
51
73
|
private readonly _sessions = new Set<WorkerSession>();
|
|
52
74
|
private readonly _clientServices!: ClientServicesHost;
|
|
53
75
|
private readonly _channel: string;
|
|
76
|
+
private readonly _automaticallyConnectWebrtc: boolean;
|
|
77
|
+
private readonly _livenessLock = new WebLockWrapper(`@dxos/client-services/WorkerRuntime/${crypto.randomUUID()}`);
|
|
54
78
|
private _broadcastChannel?: BroadcastChannel;
|
|
55
79
|
private _sessionForNetworking?: WorkerSession; // TODO(burdon): Expose to client QueryStatusResponse.
|
|
56
80
|
private _config!: Config;
|
|
57
81
|
private _signalMetadataTags: any = { runtime: 'worker-runtime' };
|
|
58
82
|
private _signalTelemetryEnabled: boolean = false;
|
|
83
|
+
private _runtime!: ManagedRuntime.ManagedRuntime<
|
|
84
|
+
SqlTransaction.SqlTransaction | SqlClient.SqlClient | SqlExport.SqlExport,
|
|
85
|
+
never
|
|
86
|
+
>;
|
|
59
87
|
|
|
60
88
|
constructor({
|
|
61
89
|
channel = DEFAULT_WORKER_BROADCAST_CHANNEL,
|
|
@@ -63,26 +91,49 @@ export class WorkerRuntime {
|
|
|
63
91
|
acquireLock,
|
|
64
92
|
releaseLock,
|
|
65
93
|
onStop,
|
|
94
|
+
automaticallyConnectWebrtc = true,
|
|
95
|
+
sqliteLayer,
|
|
66
96
|
}: WorkerRuntimeOptions) {
|
|
67
97
|
this._configProvider = configProvider;
|
|
68
98
|
this._acquireLock = acquireLock;
|
|
69
99
|
this._releaseLock = releaseLock;
|
|
70
100
|
this._onStop = onStop;
|
|
71
101
|
this._channel = channel;
|
|
102
|
+
if (sqliteLayer) {
|
|
103
|
+
log.warn('Using testing SQLite layer');
|
|
104
|
+
}
|
|
105
|
+
this._runtime = ManagedRuntime.make(
|
|
106
|
+
SqlTransaction.layer
|
|
107
|
+
.pipe(Layer.provideMerge(sqliteLayer ?? LocalSqliteOpfsLayer), Layer.provideMerge(Reactivity.layer))
|
|
108
|
+
.pipe(Layer.orDie),
|
|
109
|
+
);
|
|
72
110
|
this._clientServices = new ClientServicesHost({
|
|
73
111
|
callbacks: {
|
|
74
112
|
onReset: async () => this.stop(),
|
|
75
113
|
},
|
|
114
|
+
runtime: this._runtime.runtimeEffect,
|
|
115
|
+
runtimeProps: {
|
|
116
|
+
// Auto-activate spaces that were previously active after leader changeover.
|
|
117
|
+
autoActivateSpaces: true,
|
|
118
|
+
},
|
|
76
119
|
});
|
|
120
|
+
this._automaticallyConnectWebrtc = automaticallyConnectWebrtc;
|
|
77
121
|
}
|
|
78
122
|
|
|
79
123
|
get host() {
|
|
80
124
|
return this._clientServices;
|
|
81
125
|
}
|
|
82
126
|
|
|
127
|
+
get livenessLockKey(): string {
|
|
128
|
+
return this._livenessLock.key;
|
|
129
|
+
}
|
|
130
|
+
|
|
83
131
|
async start(): Promise<void> {
|
|
84
132
|
log('starting...');
|
|
85
133
|
try {
|
|
134
|
+
void this._livenessLock.acquire();
|
|
135
|
+
|
|
136
|
+
// Steal the lock from the other worker.
|
|
86
137
|
this._broadcastChannel = new BroadcastChannel(this._channel);
|
|
87
138
|
this._broadcastChannel.postMessage({ action: 'stop' });
|
|
88
139
|
this._broadcastChannel.onmessage = async (event) => {
|
|
@@ -126,13 +177,15 @@ export class WorkerRuntime {
|
|
|
126
177
|
this._broadcastChannel?.close();
|
|
127
178
|
this._broadcastChannel = undefined;
|
|
128
179
|
await this._clientServices.close();
|
|
180
|
+
await this._runtime.dispose();
|
|
129
181
|
await this._onStop?.();
|
|
182
|
+
await this._livenessLock.release();
|
|
130
183
|
}
|
|
131
184
|
|
|
132
185
|
/**
|
|
133
186
|
* Create a new session.
|
|
134
187
|
*/
|
|
135
|
-
async createSession({ appPort, systemPort, shellPort }:
|
|
188
|
+
async createSession({ appPort, systemPort, shellPort, onClose }: CreateSessionProps): Promise<WorkerSession> {
|
|
136
189
|
const session = new WorkerSession({
|
|
137
190
|
serviceHost: this._clientServices,
|
|
138
191
|
appPort,
|
|
@@ -148,8 +201,11 @@ export class WorkerRuntime {
|
|
|
148
201
|
// Terminate the worker when all sessions are closed.
|
|
149
202
|
await this.stop();
|
|
150
203
|
} else {
|
|
151
|
-
this.
|
|
204
|
+
if (this._automaticallyConnectWebrtc) {
|
|
205
|
+
this._reconnectWebrtc();
|
|
206
|
+
}
|
|
152
207
|
}
|
|
208
|
+
await onClose?.();
|
|
153
209
|
});
|
|
154
210
|
|
|
155
211
|
await session.open();
|
|
@@ -165,7 +221,24 @@ export class WorkerRuntime {
|
|
|
165
221
|
this._signalMetadataTags.origin = session.origin;
|
|
166
222
|
this._sessions.add(session);
|
|
167
223
|
|
|
168
|
-
this.
|
|
224
|
+
if (this._automaticallyConnectWebrtc) {
|
|
225
|
+
this._reconnectWebrtc();
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
return session;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
/**
|
|
232
|
+
* Connects the WebRTC bridge to the specified session.
|
|
233
|
+
* If no session is provided, disconnects the WebRTC bridge.
|
|
234
|
+
*
|
|
235
|
+
* Called automatically if `automaticallyConnectWebrtc` is true.
|
|
236
|
+
*
|
|
237
|
+
* @param session The session to connect the WebRTC bridge to.
|
|
238
|
+
*/
|
|
239
|
+
connectWebrtcBridge(session: WorkerSession | undefined): void {
|
|
240
|
+
this._sessionForNetworking = session;
|
|
241
|
+
this._transportFactory.setBridgeService(session?.bridgeService);
|
|
169
242
|
}
|
|
170
243
|
|
|
171
244
|
/**
|
|
@@ -183,12 +256,78 @@ export class WorkerRuntime {
|
|
|
183
256
|
// Select existing session.
|
|
184
257
|
if (!this._sessionForNetworking) {
|
|
185
258
|
const selected = Array.from(this._sessions).find((session) => session.bridgeService);
|
|
186
|
-
|
|
187
|
-
this._sessionForNetworking = selected;
|
|
188
|
-
this._transportFactory.setBridgeService(selected.bridgeService);
|
|
189
|
-
} else {
|
|
190
|
-
this._transportFactory.setBridgeService(undefined);
|
|
191
|
-
}
|
|
259
|
+
this.connectWebrtcBridge(selected);
|
|
192
260
|
}
|
|
193
261
|
}
|
|
194
262
|
}
|
|
263
|
+
|
|
264
|
+
const DB_NAME = 'DXOS';
|
|
265
|
+
|
|
266
|
+
/**
|
|
267
|
+
* SqlExport layer that wraps SqliteClient to provide export functionality.
|
|
268
|
+
*/
|
|
269
|
+
const SqlExportLayer: Layer.Layer<SqlExport.SqlExport, never, SqliteClient.SqliteClient> = Layer.effect(
|
|
270
|
+
SqlExport.SqlExport,
|
|
271
|
+
Effect.gen(function* () {
|
|
272
|
+
const sql = yield* SqliteClient.SqliteClient;
|
|
273
|
+
return {
|
|
274
|
+
export: sql.export,
|
|
275
|
+
} satisfies SqlExport.Service;
|
|
276
|
+
}),
|
|
277
|
+
);
|
|
278
|
+
|
|
279
|
+
/**
|
|
280
|
+
* Local SQLite layer for the worker.
|
|
281
|
+
* Uses OPFS sync API as an FS backend.
|
|
282
|
+
* Does NOT spawn a new worker.
|
|
283
|
+
* NOTE: Only usable within a worker.
|
|
284
|
+
* TODO(mykola): This does not work right now. Fix.
|
|
285
|
+
*/
|
|
286
|
+
const LocalSqliteOpfsLayer = Layer.unwrapScoped(
|
|
287
|
+
Effect.gen(function* () {
|
|
288
|
+
const { port1: clientPort, port2: serverPort } = new MessageChannel();
|
|
289
|
+
clientPort.start();
|
|
290
|
+
serverPort.start();
|
|
291
|
+
yield* Effect.addFinalizer(() =>
|
|
292
|
+
Effect.sync(() => {
|
|
293
|
+
clientPort.close();
|
|
294
|
+
serverPort.close();
|
|
295
|
+
}),
|
|
296
|
+
);
|
|
297
|
+
|
|
298
|
+
yield* Effect.forkScoped(OpfsWorker.run({ port: serverPort, dbName: DB_NAME }));
|
|
299
|
+
return SqlExportLayer.pipe(Layer.provideMerge(SqliteClient.layer({ worker: Effect.succeed(clientPort) })));
|
|
300
|
+
}),
|
|
301
|
+
);
|
|
302
|
+
|
|
303
|
+
// TODO(wittjosiah): Factor out to a separate module.
|
|
304
|
+
class WebLockWrapper {
|
|
305
|
+
readonly #key: string;
|
|
306
|
+
#release?: () => void;
|
|
307
|
+
|
|
308
|
+
constructor(key: string) {
|
|
309
|
+
this.#key = key;
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
get key(): string {
|
|
313
|
+
return this.#key;
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
acquire(options: LockOptions = {}) {
|
|
317
|
+
return navigator.locks.request(this.#key, options, async () => {
|
|
318
|
+
await new Promise<void>((resolve) => {
|
|
319
|
+
this.#release = resolve;
|
|
320
|
+
}); // Blocks for the duration of the worker's lifetime.
|
|
321
|
+
this.#release = undefined;
|
|
322
|
+
});
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
release() {
|
|
326
|
+
this.#release?.();
|
|
327
|
+
this.#release = undefined;
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
[Symbol.dispose]() {
|
|
331
|
+
this.release();
|
|
332
|
+
}
|
|
333
|
+
}
|
|
@@ -2,22 +2,22 @@
|
|
|
2
2
|
// Copyright 2022 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import {
|
|
5
|
+
import { Trigger, asyncTimeout } from '@dxos/async';
|
|
6
6
|
import {
|
|
7
|
-
iframeServiceBundle,
|
|
8
7
|
type IframeServiceBundle,
|
|
9
8
|
PROXY_CONNECTION_TIMEOUT,
|
|
9
|
+
iframeServiceBundle,
|
|
10
10
|
workerServiceBundle,
|
|
11
11
|
} from '@dxos/client-protocol';
|
|
12
12
|
import { invariant } from '@dxos/invariant';
|
|
13
13
|
import { log, logInfo } from '@dxos/log';
|
|
14
14
|
import { type BridgeService } from '@dxos/protocols/proto/dxos/mesh/bridge';
|
|
15
|
-
import {
|
|
15
|
+
import { type ProtoRpcPeer, type RpcPort, createProtoRpcPeer } from '@dxos/rpc';
|
|
16
16
|
import { Callback, type MaybePromise } from '@dxos/util';
|
|
17
17
|
|
|
18
|
-
import { type
|
|
18
|
+
import { ClientRpcServer, type ClientRpcServerProps, type ClientServicesHost } from '../services';
|
|
19
19
|
|
|
20
|
-
export type
|
|
20
|
+
export type WorkerSessionProps = {
|
|
21
21
|
serviceHost: ClientServicesHost;
|
|
22
22
|
systemPort: RpcPort;
|
|
23
23
|
appPort: RpcPort;
|
|
@@ -50,11 +50,11 @@ export class WorkerSession {
|
|
|
50
50
|
|
|
51
51
|
public bridgeService?: BridgeService;
|
|
52
52
|
|
|
53
|
-
constructor({ serviceHost, systemPort, appPort, shellPort, readySignal }:
|
|
53
|
+
constructor({ serviceHost, systemPort, appPort, shellPort, readySignal }: WorkerSessionProps) {
|
|
54
54
|
invariant(serviceHost);
|
|
55
55
|
this._serviceHost = serviceHost;
|
|
56
56
|
|
|
57
|
-
const middleware: Pick<
|
|
57
|
+
const middleware: Pick<ClientRpcServerProps, 'handleCall' | 'handleStream'> = {
|
|
58
58
|
handleCall: async (method, params, handler) => {
|
|
59
59
|
const error = await readySignal.wait({ timeout: PROXY_CONNECTION_TIMEOUT });
|
|
60
60
|
if (error) {
|
package/src/version.ts
CHANGED