@dxos/client-services 0.8.4-main.84f28bd → 0.8.4-main.8baae0fced
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/LICENSE +102 -5
- package/README.md +1 -1
- package/dist/lib/browser/{chunk-OCFDRCSN.mjs → chunk-KBMYCFTL.mjs} +3177 -4457
- package/dist/lib/browser/chunk-KBMYCFTL.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/chunk-XJRPB3GA.mjs +22 -0
- package/dist/lib/browser/chunk-XJRPB3GA.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +451 -145
- 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 +88 -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 +86 -0
- package/dist/lib/browser/packlets/locks/browser.mjs.map +7 -0
- package/dist/lib/browser/packlets/locks/node.mjs +48 -0
- package/dist/lib/browser/packlets/locks/node.mjs.map +7 -0
- package/dist/lib/browser/testing/index.mjs +35 -36
- package/dist/lib/browser/testing/index.mjs.map +3 -3
- package/dist/lib/node-esm/chunk-2DT3MZRL.mjs +22 -0
- package/dist/lib/node-esm/chunk-2DT3MZRL.mjs.map +7 -0
- 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-D7F3FYZS.mjs → chunk-TCS4PMDH.mjs} +3056 -4204
- package/dist/lib/node-esm/chunk-TCS4PMDH.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +451 -145
- 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 +88 -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 +86 -0
- package/dist/lib/node-esm/packlets/locks/browser.mjs.map +7 -0
- package/dist/lib/node-esm/packlets/locks/node.mjs +48 -0
- package/dist/lib/node-esm/packlets/locks/node.mjs.map +7 -0
- package/dist/lib/node-esm/testing/index.mjs +35 -36
- package/dist/lib/node-esm/testing/index.mjs.map +3 -3
- package/dist/types/src/index.d.ts +1 -0
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/packlets/agents/edge-agent-manager.d.ts +3 -2
- package/dist/types/src/packlets/agents/edge-agent-manager.d.ts.map +1 -1
- package/dist/types/src/packlets/agents/edge-agent-service.d.ts +3 -2
- 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/keys.d.ts.map +1 -1
- package/dist/types/src/packlets/devtools/metadata.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/devtools/spaces.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-collector.d.ts.map +1 -1
- package/dist/types/src/packlets/diagnostics/diagnostics.d.ts +3 -4
- 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/identity-manager.d.ts +7 -7
- package/dist/types/src/packlets/identity/identity-manager.d.ts.map +1 -1
- package/dist/types/src/packlets/identity/identity-recovery-manager.d.ts +8 -7
- package/dist/types/src/packlets/identity/identity-recovery-manager.d.ts.map +1 -1
- package/dist/types/src/packlets/identity/identity-service.d.ts +6 -10
- package/dist/types/src/packlets/identity/identity-service.d.ts.map +1 -1
- package/dist/types/src/packlets/identity/identity.d.ts +9 -12
- package/dist/types/src/packlets/identity/identity.d.ts.map +1 -1
- package/dist/types/src/packlets/invitations/device-invitation-protocol.d.ts +6 -5
- 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 +2 -2
- 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 +8 -5
- package/dist/types/src/packlets/invitations/invitation-protocol.d.ts.map +1 -1
- package/dist/types/src/packlets/invitations/invitation-state.d.ts.map +1 -1
- package/dist/types/src/packlets/invitations/invitation-topology.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 +3 -3
- package/dist/types/src/packlets/invitations/invitations-manager.d.ts.map +1 -1
- package/dist/types/src/packlets/invitations/invitations-service.d.ts +4 -4
- package/dist/types/src/packlets/invitations/invitations-service.d.ts.map +1 -1
- package/dist/types/src/packlets/invitations/space-invitation-protocol.d.ts +5 -4
- 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/browser.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/locks/node.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 +7 -6
- package/dist/types/src/packlets/network/network-service.d.ts.map +1 -1
- package/dist/types/src/packlets/services/client-rpc-server.d.ts +5 -5
- package/dist/types/src/packlets/services/client-rpc-server.d.ts.map +1 -1
- package/dist/types/src/packlets/services/feed-syncer.d.ts +59 -0
- package/dist/types/src/packlets/services/feed-syncer.d.ts.map +1 -0
- package/dist/types/src/packlets/services/feed-syncer.test.d.ts +2 -0
- package/dist/types/src/packlets/services/feed-syncer.test.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 -10
- package/dist/types/src/packlets/services/service-context.d.ts.map +1 -1
- package/dist/types/src/packlets/services/service-host.d.ts +21 -8
- package/dist/types/src/packlets/services/service-host.d.ts.map +1 -1
- package/dist/types/src/packlets/services/service-registry.d.ts.map +1 -1
- package/dist/types/src/packlets/services/util.d.ts.map +1 -1
- package/dist/types/src/packlets/space-export/archive-format.d.ts +9 -0
- package/dist/types/src/packlets/space-export/archive-format.d.ts.map +1 -0
- package/dist/types/src/packlets/space-export/index.d.ts +4 -1
- package/dist/types/src/packlets/space-export/index.d.ts.map +1 -1
- package/dist/types/src/packlets/space-export/serialized-space-reader.d.ts +23 -0
- package/dist/types/src/packlets/space-export/serialized-space-reader.d.ts.map +1 -0
- package/dist/types/src/packlets/space-export/serialized-space-writer.d.ts +36 -0
- package/dist/types/src/packlets/space-export/serialized-space-writer.d.ts.map +1 -0
- package/dist/types/src/packlets/space-export/space-archive-reader.d.ts +9 -1
- package/dist/types/src/packlets/space-export/space-archive-reader.d.ts.map +1 -1
- package/dist/types/src/packlets/space-export/space-archive-writer.d.ts +8 -2
- package/dist/types/src/packlets/space-export/space-archive-writer.d.ts.map +1 -1
- package/dist/types/src/packlets/space-export/space-archive.test.d.ts +2 -0
- package/dist/types/src/packlets/space-export/space-archive.test.d.ts.map +1 -0
- 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 +31 -20
- package/dist/types/src/packlets/spaces/data-space-manager.d.ts.map +1 -1
- package/dist/types/src/packlets/spaces/data-space.d.ts +30 -13
- 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/epoch-migrations.d.ts.map +1 -1
- package/dist/types/src/packlets/spaces/genesis.d.ts +2 -1
- package/dist/types/src/packlets/spaces/genesis.d.ts.map +1 -1
- package/dist/types/src/packlets/spaces/notarization-plugin.d.ts +6 -9
- package/dist/types/src/packlets/spaces/notarization-plugin.d.ts.map +1 -1
- package/dist/types/src/packlets/spaces/spaces-service.d.ts +11 -8
- package/dist/types/src/packlets/spaces/spaces-service.d.ts.map +1 -1
- package/dist/types/src/packlets/storage/level.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/storage/util.d.ts.map +1 -1
- package/dist/types/src/packlets/system/system-service.d.ts +2 -2
- package/dist/types/src/packlets/system/system-service.d.ts.map +1 -1
- package/dist/types/src/packlets/testing/credential-utils.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 +41 -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 -4
- package/dist/types/src/packlets/worker/worker-session.d.ts.map +1 -1
- package/dist/types/src/testing/setup.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 +73 -56
- package/src/index.ts +1 -0
- package/src/packlets/agents/edge-agent-manager.ts +10 -7
- package/src/packlets/agents/edge-agent-service.ts +17 -5
- package/src/packlets/devices/devices-service.test.ts +3 -3
- package/src/packlets/devices/devices-service.ts +2 -2
- package/src/packlets/devtools/devtools.ts +29 -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 +2 -3
- 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 +2 -2
- package/src/packlets/identity/identity-manager.test.ts +8 -8
- package/src/packlets/identity/identity-manager.ts +25 -24
- package/src/packlets/identity/identity-recovery-manager.ts +22 -18
- package/src/packlets/identity/identity-service.test.ts +8 -28
- package/src/packlets/identity/identity-service.ts +13 -80
- package/src/packlets/identity/identity.test.ts +11 -11
- package/src/packlets/identity/identity.ts +17 -39
- package/src/packlets/invitations/device-invitation-protocol.test.ts +4 -4
- package/src/packlets/invitations/device-invitation-protocol.ts +8 -6
- package/src/packlets/invitations/edge-invitation-handler.ts +10 -6
- 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 +15 -16
- package/src/packlets/invitations/invitation-protocol.ts +8 -5
- package/src/packlets/invitations/invitation-state.ts +1 -15
- package/src/packlets/invitations/invitations-handler.test.ts +301 -292
- package/src/packlets/invitations/invitations-handler.ts +77 -25
- package/src/packlets/invitations/invitations-manager.ts +43 -18
- package/src/packlets/invitations/invitations-service.ts +10 -10
- package/src/packlets/invitations/space-invitation-protocol.test.ts +26 -25
- package/src/packlets/invitations/space-invitation-protocol.ts +13 -17
- 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 +22 -17
- package/src/packlets/logging/logging.test.ts +1 -1
- package/src/packlets/network/network-service.test.ts +3 -3
- package/src/packlets/network/network-service.ts +12 -10
- package/src/packlets/services/client-rpc-server.ts +20 -17
- package/src/packlets/services/feed-syncer.test.ts +340 -0
- package/src/packlets/services/feed-syncer.ts +377 -0
- package/src/packlets/services/platform.ts +7 -1
- package/src/packlets/services/service-context.test.ts +4 -3
- package/src/packlets/services/service-context.ts +160 -67
- package/src/packlets/services/service-host.test.ts +10 -9
- package/src/packlets/services/service-host.ts +86 -47
- package/src/packlets/services/service-registry.test.ts +1 -1
- package/src/packlets/space-export/archive-format.ts +42 -0
- package/src/packlets/space-export/index.ts +4 -1
- package/src/packlets/space-export/serialized-space-reader.ts +111 -0
- package/src/packlets/space-export/serialized-space-writer.ts +252 -0
- package/src/packlets/space-export/space-archive-reader.ts +65 -4
- package/src/packlets/space-export/space-archive-writer.ts +44 -6
- package/src/packlets/space-export/space-archive.test.ts +461 -0
- 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.test.ts +79 -13
- package/src/packlets/spaces/data-space-manager.ts +134 -129
- package/src/packlets/spaces/data-space.ts +71 -42
- package/src/packlets/spaces/edge-feed-replicator.test.ts +4 -4
- package/src/packlets/spaces/edge-feed-replicator.ts +13 -11
- package/src/packlets/spaces/epoch-migrations.ts +6 -5
- package/src/packlets/spaces/genesis.ts +6 -1
- package/src/packlets/spaces/notarization-plugin.test.ts +3 -3
- package/src/packlets/spaces/notarization-plugin.ts +13 -12
- package/src/packlets/spaces/spaces-service.test.ts +20 -12
- package/src/packlets/spaces/spaces-service.ts +140 -38
- 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 +11 -7
- package/src/packlets/testing/test-builder.ts +39 -13
- package/src/packlets/worker/worker-runtime.ts +189 -17
- package/src/packlets/worker/worker-session.ts +15 -21
- package/src/version.ts +1 -1
- package/dist/lib/browser/chunk-OCFDRCSN.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-D7F3FYZS.mjs.map +0 -7
- package/dist/types/src/packlets/identity/default-space-state-machine.d.ts +0 -19
- package/dist/types/src/packlets/identity/default-space-state-machine.d.ts.map +0 -1
- package/src/packlets/identity/default-space-state-machine.ts +0 -44
|
@@ -2,16 +2,17 @@
|
|
|
2
2
|
// Copyright 2023 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { afterEach,
|
|
5
|
+
import { afterEach, beforeEach, describe, expect, onTestFinished, test } from 'vitest';
|
|
6
6
|
|
|
7
7
|
import { Trigger } from '@dxos/async';
|
|
8
8
|
import { Context } from '@dxos/context';
|
|
9
9
|
import { PublicKey } from '@dxos/keys';
|
|
10
10
|
import { type Space, type SpacesService } from '@dxos/protocols/proto/dxos/client/services';
|
|
11
|
+
import { MembershipPolicy } from '@dxos/protocols/proto/dxos/halo/credentials';
|
|
11
12
|
|
|
12
|
-
import { SpacesServiceImpl } from './spaces-service';
|
|
13
13
|
import { type ServiceContext } from '../services';
|
|
14
14
|
import { createServiceContext } from '../testing';
|
|
15
|
+
import { SpacesServiceImpl } from './spaces-service';
|
|
15
16
|
|
|
16
17
|
describe('SpacesService', () => {
|
|
17
18
|
let serviceContext: ServiceContext;
|
|
@@ -20,10 +21,15 @@ describe('SpacesService', () => {
|
|
|
20
21
|
beforeEach(async () => {
|
|
21
22
|
serviceContext = await createServiceContext();
|
|
22
23
|
await serviceContext.open(new Context());
|
|
23
|
-
spacesService = new SpacesServiceImpl(
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
24
|
+
spacesService = new SpacesServiceImpl(
|
|
25
|
+
serviceContext.identityManager,
|
|
26
|
+
serviceContext.spaceManager,
|
|
27
|
+
serviceContext.echoHost,
|
|
28
|
+
async () => {
|
|
29
|
+
await serviceContext.initialized.wait();
|
|
30
|
+
return serviceContext.dataSpaceManager!;
|
|
31
|
+
},
|
|
32
|
+
);
|
|
27
33
|
});
|
|
28
34
|
|
|
29
35
|
afterEach(async () => {
|
|
@@ -32,12 +38,14 @@ describe('SpacesService', () => {
|
|
|
32
38
|
|
|
33
39
|
describe('createSpace', () => {
|
|
34
40
|
test('fails if no identity is available', async () => {
|
|
35
|
-
await expect(spacesService.createSpace()).rejects.toBeInstanceOf(
|
|
41
|
+
await expect(spacesService.createSpace({ membershipPolicy: MembershipPolicy.INVITE })).rejects.toBeInstanceOf(
|
|
42
|
+
Error,
|
|
43
|
+
);
|
|
36
44
|
});
|
|
37
45
|
|
|
38
46
|
test('creates a new space', async () => {
|
|
39
47
|
await serviceContext.createIdentity();
|
|
40
|
-
const space = await spacesService.createSpace();
|
|
48
|
+
const space = await spacesService.createSpace({ membershipPolicy: MembershipPolicy.INVITE });
|
|
41
49
|
expect(space).to.exist;
|
|
42
50
|
expect(space.spaceKey).to.be.instanceof(PublicKey);
|
|
43
51
|
});
|
|
@@ -59,9 +67,9 @@ describe('SpacesService', () => {
|
|
|
59
67
|
test('returns list of existing spaces', async () => {
|
|
60
68
|
await serviceContext.createIdentity();
|
|
61
69
|
const existingSpaces = [
|
|
62
|
-
await spacesService.createSpace(),
|
|
63
|
-
await spacesService.createSpace(),
|
|
64
|
-
await spacesService.createSpace(),
|
|
70
|
+
await spacesService.createSpace({ membershipPolicy: MembershipPolicy.INVITE }),
|
|
71
|
+
await spacesService.createSpace({ membershipPolicy: MembershipPolicy.INVITE }),
|
|
72
|
+
await spacesService.createSpace({ membershipPolicy: MembershipPolicy.INVITE }),
|
|
65
73
|
];
|
|
66
74
|
|
|
67
75
|
const query = spacesService.querySpaces();
|
|
@@ -87,7 +95,7 @@ describe('SpacesService', () => {
|
|
|
87
95
|
expect(await result.wait()).to.be.length(0);
|
|
88
96
|
|
|
89
97
|
result.reset();
|
|
90
|
-
const space = await spacesService.createSpace();
|
|
98
|
+
const space = await spacesService.createSpace({ membershipPolicy: MembershipPolicy.INVITE });
|
|
91
99
|
const spaces = await result.wait();
|
|
92
100
|
expect(spaces).to.be.length(1);
|
|
93
101
|
expect(spaces?.[0].spaceKey.equals(space.spaceKey)).to.be.true;
|
|
@@ -5,7 +5,9 @@
|
|
|
5
5
|
import type { AutomergeUrl } from '@automerge/automerge-repo';
|
|
6
6
|
|
|
7
7
|
import { SubscriptionList, UpdateScheduler, scheduleTask } from '@dxos/async';
|
|
8
|
+
import { type RequestOptions } from '@dxos/codec-protobuf';
|
|
8
9
|
import { Stream } from '@dxos/codec-protobuf/stream';
|
|
10
|
+
import { Context } from '@dxos/context';
|
|
9
11
|
import {
|
|
10
12
|
type CredentialProcessor,
|
|
11
13
|
createAdmissionCredentials,
|
|
@@ -13,86 +15,103 @@ import {
|
|
|
13
15
|
getCredentialAssertion,
|
|
14
16
|
} from '@dxos/credentials';
|
|
15
17
|
import { raise } from '@dxos/debug';
|
|
16
|
-
import { type SpaceManager } from '@dxos/echo-pipeline';
|
|
18
|
+
import { type EchoHost, type SpaceManager } from '@dxos/echo-pipeline';
|
|
19
|
+
import { type DatabaseDirectory } from '@dxos/echo-protocol';
|
|
17
20
|
import { writeMessages } from '@dxos/feed-store';
|
|
18
21
|
import { assertArgument, assertState, invariant } from '@dxos/invariant';
|
|
19
22
|
import { SpaceId } from '@dxos/keys';
|
|
20
23
|
import { log } from '@dxos/log';
|
|
21
24
|
import {
|
|
22
|
-
encodeError,
|
|
23
25
|
ApiError,
|
|
24
26
|
AuthorizationError,
|
|
27
|
+
FeedProtocol,
|
|
25
28
|
IdentityNotInitializedError,
|
|
26
29
|
SpaceNotFoundError,
|
|
30
|
+
encodeError,
|
|
27
31
|
} from '@dxos/protocols';
|
|
28
32
|
import {
|
|
29
|
-
|
|
30
|
-
|
|
33
|
+
type AdmitContactRequest,
|
|
34
|
+
type ContactAdmission,
|
|
31
35
|
type CreateEpochRequest,
|
|
36
|
+
type CreateEpochResponse,
|
|
37
|
+
type ExportSpaceRequest,
|
|
38
|
+
type ExportSpaceResponse,
|
|
39
|
+
type ImportSpaceRequest,
|
|
40
|
+
type ImportSpaceResponse,
|
|
41
|
+
type JoinBySpaceKeyRequest,
|
|
42
|
+
type JoinSpaceResponse,
|
|
32
43
|
type PostMessageRequest,
|
|
33
44
|
type QueryCredentialsRequest,
|
|
34
45
|
type QuerySpacesResponse,
|
|
35
46
|
type Space,
|
|
47
|
+
SpaceArchive,
|
|
48
|
+
SpaceMember,
|
|
49
|
+
SpaceState,
|
|
36
50
|
type SpacesService,
|
|
37
51
|
type SubscribeMessagesRequest,
|
|
52
|
+
type UpdateMemberRoleRequest,
|
|
53
|
+
type CreateSpaceRequest,
|
|
38
54
|
type UpdateSpaceRequest,
|
|
39
55
|
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
56
|
} from '@dxos/protocols/proto/dxos/client/services';
|
|
51
57
|
import { type Credential } from '@dxos/protocols/proto/dxos/halo/credentials';
|
|
52
58
|
import { type GossipMessage } from '@dxos/protocols/proto/dxos/mesh/teleport/gossip';
|
|
53
59
|
import { trace } from '@dxos/tracing';
|
|
54
60
|
import { type Provider } from '@dxos/util';
|
|
55
61
|
|
|
62
|
+
import { type IdentityManager } from '../identity';
|
|
63
|
+
import {
|
|
64
|
+
SpaceArchiveWriter,
|
|
65
|
+
detectSpaceArchiveFormat,
|
|
66
|
+
extractSpaceArchive,
|
|
67
|
+
readSerializedSpaceArchive,
|
|
68
|
+
writeSerializedSpaceArchive,
|
|
69
|
+
objJsonToObjectStructure,
|
|
70
|
+
} from '../space-export';
|
|
56
71
|
import { type DataSpace } from './data-space';
|
|
57
72
|
import { type DataSpaceManager } from './data-space-manager';
|
|
58
|
-
import { type IdentityManager } from '../identity';
|
|
59
|
-
import { extractSpaceArchive, SpaceArchiveWriter } from '../space-export';
|
|
60
73
|
|
|
61
74
|
export class SpacesServiceImpl implements SpacesService {
|
|
62
75
|
constructor(
|
|
63
76
|
private readonly _identityManager: IdentityManager,
|
|
64
77
|
private readonly _spaceManager: SpaceManager,
|
|
78
|
+
private readonly _echoHost: EchoHost,
|
|
65
79
|
private readonly _getDataSpaceManager: Provider<Promise<DataSpaceManager>>,
|
|
66
80
|
) {}
|
|
67
81
|
|
|
68
|
-
async createSpace(): Promise<Space> {
|
|
82
|
+
async createSpace(request: CreateSpaceRequest, options?: RequestOptions): Promise<Space> {
|
|
69
83
|
this._requireIdentity();
|
|
84
|
+
const ctx = options?.ctx ?? new Context();
|
|
70
85
|
const dataSpaceManager = await this._getDataSpaceManager();
|
|
71
|
-
const space = await dataSpaceManager.createSpace(
|
|
86
|
+
const space = await dataSpaceManager.createSpace(ctx, {
|
|
87
|
+
tags: request?.tags,
|
|
88
|
+
membershipPolicy: request?.membershipPolicy,
|
|
89
|
+
});
|
|
72
90
|
await this._updateMetrics();
|
|
73
91
|
return this._serializeSpace(space);
|
|
74
92
|
}
|
|
75
93
|
|
|
76
|
-
async updateSpace({ spaceKey, state, edgeReplication }: UpdateSpaceRequest): Promise<void> {
|
|
94
|
+
async updateSpace({ spaceKey, state, edgeReplication }: UpdateSpaceRequest, options?: RequestOptions): Promise<void> {
|
|
95
|
+
const ctx = options?.ctx ?? Context.default();
|
|
77
96
|
const dataSpaceManager = await this._getDataSpaceManager();
|
|
78
97
|
const space = dataSpaceManager.spaces.get(spaceKey) ?? raise(new SpaceNotFoundError(spaceKey));
|
|
79
98
|
|
|
80
99
|
if (state) {
|
|
81
100
|
switch (state) {
|
|
82
101
|
case SpaceState.SPACE_ACTIVE:
|
|
83
|
-
await space.activate();
|
|
102
|
+
await space.activate(ctx);
|
|
84
103
|
break;
|
|
85
104
|
|
|
86
105
|
case SpaceState.SPACE_INACTIVE:
|
|
87
|
-
await space.deactivate();
|
|
106
|
+
await space.deactivate(ctx);
|
|
88
107
|
break;
|
|
89
108
|
default:
|
|
90
|
-
throw new ApiError('Invalid space state');
|
|
109
|
+
throw new ApiError({ message: 'Invalid space state' });
|
|
91
110
|
}
|
|
92
111
|
}
|
|
93
112
|
|
|
94
113
|
if (edgeReplication !== undefined) {
|
|
95
|
-
await dataSpaceManager.setSpaceEdgeReplicationSetting(spaceKey, edgeReplication);
|
|
114
|
+
await dataSpaceManager.setSpaceEdgeReplicationSetting(ctx, spaceKey, edgeReplication);
|
|
96
115
|
}
|
|
97
116
|
}
|
|
98
117
|
|
|
@@ -103,9 +122,12 @@ export class SpacesServiceImpl implements SpacesService {
|
|
|
103
122
|
throw new SpaceNotFoundError(request.spaceKey);
|
|
104
123
|
}
|
|
105
124
|
if (!space.spaceState.hasMembershipManagementPermission(identity.identityKey)) {
|
|
106
|
-
throw new AuthorizationError(
|
|
107
|
-
|
|
108
|
-
|
|
125
|
+
throw new AuthorizationError({
|
|
126
|
+
message: 'No member management permission.',
|
|
127
|
+
context: {
|
|
128
|
+
spaceKey: space.key,
|
|
129
|
+
role: space.spaceState.getMemberRole(identity.identityKey),
|
|
130
|
+
},
|
|
109
131
|
});
|
|
110
132
|
}
|
|
111
133
|
const credentials = await createAdmissionCredentials(
|
|
@@ -258,18 +280,26 @@ export class SpacesServiceImpl implements SpacesService {
|
|
|
258
280
|
});
|
|
259
281
|
}
|
|
260
282
|
|
|
261
|
-
async joinBySpaceKey({ spaceKey }: JoinBySpaceKeyRequest): Promise<JoinSpaceResponse> {
|
|
283
|
+
async joinBySpaceKey({ spaceKey }: JoinBySpaceKeyRequest, options?: RequestOptions): Promise<JoinSpaceResponse> {
|
|
284
|
+
const ctx = options?.ctx ?? Context.default();
|
|
262
285
|
const dataSpaceManager = await this._getDataSpaceManager();
|
|
263
|
-
const credential = await dataSpaceManager.requestSpaceAdmissionCredential(spaceKey);
|
|
264
|
-
return this._joinByAdmission({ credential });
|
|
286
|
+
const credential = await dataSpaceManager.requestSpaceAdmissionCredential(ctx, spaceKey);
|
|
287
|
+
return this._joinByAdmission(ctx, { credential });
|
|
265
288
|
}
|
|
266
289
|
|
|
267
290
|
async exportSpace(request: ExportSpaceRequest): Promise<ExportSpaceResponse> {
|
|
268
|
-
|
|
269
|
-
assertArgument(SpaceId.isValid(request.spaceId), 'Invalid space ID');
|
|
291
|
+
assertArgument(SpaceId.isValid(request.spaceId), 'spaceId', 'Invalid space ID');
|
|
270
292
|
|
|
271
293
|
const dataSpaceManager = await this._getDataSpaceManager();
|
|
272
294
|
const space = dataSpaceManager.getSpaceById(request.spaceId) ?? raise(new Error('Space not found'));
|
|
295
|
+
|
|
296
|
+
const format = request.format ?? SpaceArchive.Format.BINARY;
|
|
297
|
+
if (format === SpaceArchive.Format.JSON) {
|
|
298
|
+
const archive = await writeSerializedSpaceArchive({ space, echoHost: this._echoHost });
|
|
299
|
+
return { archive };
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
await using writer = await new SpaceArchiveWriter().open();
|
|
273
303
|
await writer.begin({ spaceId: space.id });
|
|
274
304
|
const rootUrl = space.automergeSpaceState.lastEpoch?.subject.assertion.automergeRoot;
|
|
275
305
|
assertState(rootUrl, 'Space does not have a root URL');
|
|
@@ -279,23 +309,92 @@ export class SpacesServiceImpl implements SpacesService {
|
|
|
279
309
|
await writer.writeDocument(documentId, data);
|
|
280
310
|
}
|
|
281
311
|
|
|
312
|
+
const feeds = await space.getAllFeeds();
|
|
313
|
+
for (const feed of feeds) {
|
|
314
|
+
const archiveBlocks = feed.blocks.map((block) => ({
|
|
315
|
+
actorId: block.actorId,
|
|
316
|
+
sequence: block.sequence,
|
|
317
|
+
prevActorId: block.prevActorId,
|
|
318
|
+
prevSequence: block.prevSequence,
|
|
319
|
+
position: block.position,
|
|
320
|
+
timestamp: block.timestamp,
|
|
321
|
+
data: Buffer.from(block.data).toString('base64'),
|
|
322
|
+
}));
|
|
323
|
+
await writer.writeFeed(feed.feedId, feed.feedNamespace, archiveBlocks);
|
|
324
|
+
}
|
|
325
|
+
|
|
282
326
|
const archive = await writer.finish();
|
|
283
327
|
return { archive };
|
|
284
328
|
}
|
|
285
329
|
|
|
286
|
-
async importSpace(request: ImportSpaceRequest): Promise<ImportSpaceResponse> {
|
|
330
|
+
async importSpace(request: ImportSpaceRequest, options?: RequestOptions): Promise<ImportSpaceResponse> {
|
|
331
|
+
const ctx = options?.ctx ?? Context.default();
|
|
287
332
|
const dataSpaceManager = await this._getDataSpaceManager();
|
|
333
|
+
|
|
334
|
+
const format = request.archive.format ?? detectSpaceArchiveFormat(request.archive);
|
|
335
|
+
if (format === SpaceArchive.Format.JSON) {
|
|
336
|
+
const serialized = readSerializedSpaceArchive(request.archive);
|
|
337
|
+
const space = await dataSpaceManager.createSpace(ctx, { tags: request.tags });
|
|
338
|
+
await this._hydrateSpaceFromSerialized(space, serialized);
|
|
339
|
+
await this._updateMetrics();
|
|
340
|
+
return { newSpaceId: space.id };
|
|
341
|
+
}
|
|
342
|
+
|
|
288
343
|
const extracted = await extractSpaceArchive(request.archive);
|
|
289
344
|
invariant(extracted.metadata.echo?.currentRootUrl, 'Space archive does not contain a root URL');
|
|
290
|
-
const space = await dataSpaceManager.createSpace({
|
|
345
|
+
const space = await dataSpaceManager.createSpace(ctx, {
|
|
291
346
|
documents: extracted.documents,
|
|
292
347
|
rootUrl: extracted.metadata.echo?.currentRootUrl as AutomergeUrl,
|
|
348
|
+
tags: request.tags,
|
|
293
349
|
});
|
|
294
350
|
await this._updateMetrics();
|
|
295
351
|
return { newSpaceId: space.id };
|
|
296
352
|
}
|
|
297
353
|
|
|
298
|
-
|
|
354
|
+
/**
|
|
355
|
+
* Populate a freshly-created space with the objects and feed messages described in a {@link SerializedSpace}.
|
|
356
|
+
*
|
|
357
|
+
* Objects are written directly into the space's automerge root document as inline
|
|
358
|
+
* {@link ObjectStructure} entries; feed messages are appended to the appropriate queue
|
|
359
|
+
* via {@link EchoHost.queuesService}.
|
|
360
|
+
*/
|
|
361
|
+
private async _hydrateSpaceFromSerialized(
|
|
362
|
+
space: DataSpace,
|
|
363
|
+
serialized: ReturnType<typeof readSerializedSpaceArchive>,
|
|
364
|
+
): Promise<void> {
|
|
365
|
+
const databaseRoot = space.databaseRoot;
|
|
366
|
+
assertState(databaseRoot, 'Space database root is not ready');
|
|
367
|
+
|
|
368
|
+
databaseRoot.handle.change((doc: DatabaseDirectory) => {
|
|
369
|
+
if (!doc.objects) {
|
|
370
|
+
doc.objects = {};
|
|
371
|
+
}
|
|
372
|
+
for (const obj of serialized.objects) {
|
|
373
|
+
doc.objects[obj.id] = objJsonToObjectStructure(obj);
|
|
374
|
+
}
|
|
375
|
+
});
|
|
376
|
+
|
|
377
|
+
for (const feed of serialized.feeds ?? []) {
|
|
378
|
+
if (feed.messages.length === 0) {
|
|
379
|
+
continue;
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
const namespace =
|
|
383
|
+
feed.namespace === 'trace' ? FeedProtocol.WellKnownNamespaces.trace : FeedProtocol.WellKnownNamespaces.data;
|
|
384
|
+
try {
|
|
385
|
+
await this._echoHost.queuesService.insertIntoQueue({
|
|
386
|
+
spaceId: space.id,
|
|
387
|
+
queueId: feed.feedObjectId,
|
|
388
|
+
subspaceTag: namespace,
|
|
389
|
+
objects: feed.messages.map((message) => JSON.stringify(message)),
|
|
390
|
+
});
|
|
391
|
+
} catch (err) {
|
|
392
|
+
log.warn('failed to import feed data', { feedObjectId: feed.feedObjectId, error: err });
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
private async _joinByAdmission(ctx: Context, { credential }: ContactAdmission): Promise<JoinSpaceResponse> {
|
|
299
398
|
const assertion = getCredentialAssertion(credential);
|
|
300
399
|
invariant(assertion['@type'] === 'dxos.halo.credentials.SpaceMember', 'Invalid credential');
|
|
301
400
|
const myIdentity = this._identityManager.identity;
|
|
@@ -304,9 +403,10 @@ export class SpacesServiceImpl implements SpacesService {
|
|
|
304
403
|
const dataSpaceManager = await this._getDataSpaceManager();
|
|
305
404
|
let dataSpace = dataSpaceManager.spaces.get(assertion.spaceKey);
|
|
306
405
|
if (!dataSpace) {
|
|
307
|
-
dataSpace = await dataSpaceManager.acceptSpace({
|
|
406
|
+
dataSpace = await dataSpaceManager.acceptSpace(ctx, {
|
|
308
407
|
spaceKey: assertion.spaceKey,
|
|
309
408
|
genesisFeedKey: assertion.genesisFeedKey,
|
|
409
|
+
tags: assertion.tags,
|
|
310
410
|
});
|
|
311
411
|
await myIdentity.controlPipeline.writer.write({ credential: { credential } });
|
|
312
412
|
}
|
|
@@ -359,6 +459,8 @@ export class SpacesServiceImpl implements SpacesService {
|
|
|
359
459
|
}),
|
|
360
460
|
),
|
|
361
461
|
creator: space.inner.spaceState.creator?.key,
|
|
462
|
+
tags: space.tags,
|
|
463
|
+
membershipPolicy: space.membershipPolicy,
|
|
362
464
|
cache: space.cache,
|
|
363
465
|
metrics: space.metrics,
|
|
364
466
|
edgeReplication: space.getEdgeReplicationSetting(),
|
|
@@ -367,9 +469,9 @@ export class SpacesServiceImpl implements SpacesService {
|
|
|
367
469
|
|
|
368
470
|
private _requireIdentity() {
|
|
369
471
|
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
|
-
);
|
|
472
|
+
throw new IdentityNotInitializedError({
|
|
473
|
+
message: 'This device has no HALO identity available. See https://docs.dxos.org/guide/platform/halo',
|
|
474
|
+
});
|
|
373
475
|
}
|
|
374
476
|
return this._identityManager.identity;
|
|
375
477
|
}
|
|
@@ -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,8 @@
|
|
|
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
|
+
import { Context } from '@dxos/context';
|
|
7
8
|
import { invariant } from '@dxos/invariant';
|
|
8
9
|
import { Invitation } from '@dxos/protocols/proto/dxos/client/services';
|
|
9
10
|
import { type DeviceProfileDocument } from '@dxos/protocols/proto/dxos/halo/credentials';
|
|
@@ -36,15 +37,15 @@ export type PerformInvitationCallbacks<T> = {
|
|
|
36
37
|
onError?: (value: T) => boolean | void;
|
|
37
38
|
};
|
|
38
39
|
|
|
39
|
-
export type
|
|
40
|
+
export type PerformInvitationProps = {
|
|
40
41
|
host: ServiceContext | InvitationHost;
|
|
41
42
|
guest: ServiceContext | InvitationGuest;
|
|
43
|
+
guestDeviceProfile?: DeviceProfileDocument;
|
|
42
44
|
options?: Partial<Invitation>;
|
|
43
45
|
hooks?: {
|
|
44
46
|
host?: PerformInvitationCallbacks<CancellableInvitation>;
|
|
45
47
|
guest?: PerformInvitationCallbacks<AuthenticatingInvitation>;
|
|
46
48
|
};
|
|
47
|
-
guestDeviceProfile?: DeviceProfileDocument;
|
|
48
49
|
codeInputDelay?: number;
|
|
49
50
|
};
|
|
50
51
|
|
|
@@ -52,14 +53,17 @@ export type Result = { invitation?: Invitation; error?: Error };
|
|
|
52
53
|
|
|
53
54
|
// TODO(burdon): Make async.
|
|
54
55
|
// TODO(burdon): Rename startInvitation.
|
|
56
|
+
/**
|
|
57
|
+
*
|
|
58
|
+
*/
|
|
55
59
|
export const performInvitation = ({
|
|
56
60
|
host,
|
|
57
61
|
guest,
|
|
62
|
+
guestDeviceProfile,
|
|
58
63
|
options,
|
|
59
64
|
hooks,
|
|
60
|
-
guestDeviceProfile,
|
|
61
65
|
codeInputDelay,
|
|
62
|
-
}:
|
|
66
|
+
}: PerformInvitationProps): [Promise<Result>, Promise<Result>] => {
|
|
63
67
|
let guestError = false;
|
|
64
68
|
let guestConnected = false;
|
|
65
69
|
let wereConnected = false;
|
|
@@ -226,7 +230,7 @@ export const createInvitation = async (
|
|
|
226
230
|
};
|
|
227
231
|
|
|
228
232
|
if (host instanceof ServiceContext) {
|
|
229
|
-
return host.invitationsManager.createInvitation({
|
|
233
|
+
return host.invitationsManager.createInvitation(new Context(), {
|
|
230
234
|
kind: Invitation.Kind.SPACE,
|
|
231
235
|
...options,
|
|
232
236
|
});
|
|
@@ -243,7 +247,7 @@ export const acceptInvitation = (
|
|
|
243
247
|
invitation = sanitizeInvitation(invitation);
|
|
244
248
|
|
|
245
249
|
if (guest instanceof ServiceContext) {
|
|
246
|
-
return guest.invitationsManager.acceptInvitation({
|
|
250
|
+
return guest.invitationsManager.acceptInvitation(new Context(), {
|
|
247
251
|
invitation,
|
|
248
252
|
deviceProfile: guestDeviceProfile,
|
|
249
253
|
});
|
|
@@ -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
|
|