@dxos/client-services 0.1.19 → 0.1.21
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/index.mjs +306 -129
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node/index.cjs +333 -152
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/meta.json +1 -1
- package/dist/types/src/packlets/identity/identity-manager.d.ts.map +1 -1
- package/dist/types/src/packlets/identity/identity.d.ts.map +1 -1
- package/dist/types/src/packlets/invitations/space-invitations-handler.d.ts.map +1 -1
- package/dist/types/src/packlets/network/index.d.ts +2 -0
- package/dist/types/src/packlets/network/index.d.ts.map +1 -0
- package/dist/types/src/packlets/network/network-service.d.ts +10 -0
- package/dist/types/src/packlets/network/network-service.d.ts.map +1 -0
- package/dist/types/src/packlets/services/service-context.d.ts +2 -1
- package/dist/types/src/packlets/services/service-context.d.ts.map +1 -1
- package/dist/types/src/packlets/services/service-definitions.d.ts +2 -1
- package/dist/types/src/packlets/services/service-definitions.d.ts.map +1 -1
- package/dist/types/src/packlets/services/service-host.d.ts +4 -1
- package/dist/types/src/packlets/services/service-host.d.ts.map +1 -1
- package/dist/types/src/packlets/services/service-host.test.d.ts +2 -0
- package/dist/types/src/packlets/services/service-host.test.d.ts.map +1 -0
- package/dist/types/src/packlets/spaces/data-space-manager.d.ts +4 -2
- package/dist/types/src/packlets/spaces/data-space-manager.d.ts.map +1 -1
- package/dist/types/src/packlets/spaces/data-space.d.ts +13 -6
- package/dist/types/src/packlets/spaces/data-space.d.ts.map +1 -1
- package/dist/types/src/packlets/spaces/spaces-service.d.ts +6 -1
- package/dist/types/src/packlets/spaces/spaces-service.d.ts.map +1 -1
- package/dist/types/src/packlets/storage/storage.d.ts +0 -2
- package/dist/types/src/packlets/storage/storage.d.ts.map +1 -1
- package/dist/types/src/packlets/vault/worker-session.d.ts.map +1 -1
- package/package.json +28 -34
- package/src/packlets/deprecated/space.ts +1 -1
- package/src/packlets/devtools/spaces.ts +1 -1
- package/src/packlets/identity/identity-manager.ts +3 -9
- package/src/packlets/identity/identity.test.ts +4 -33
- package/src/packlets/identity/identity.ts +26 -18
- package/src/packlets/invitations/space-invitations-handler.test.ts +53 -1
- package/src/packlets/invitations/space-invitations-handler.ts +9 -5
- package/src/packlets/network/index.ts +5 -0
- package/src/packlets/network/network-service.ts +24 -0
- package/src/packlets/services/service-context.ts +9 -2
- package/src/packlets/services/service-definitions.ts +5 -1
- package/src/packlets/services/service-host.test.ts +31 -0
- package/src/packlets/services/service-host.ts +13 -9
- package/src/packlets/spaces/data-space-manager.ts +46 -9
- package/src/packlets/spaces/data-space.ts +28 -10
- package/src/packlets/spaces/spaces-service.ts +21 -0
- package/src/packlets/storage/storage.ts +4 -41
- package/src/packlets/vault/worker-session.ts +1 -0
|
@@ -4,25 +4,42 @@
|
|
|
4
4
|
|
|
5
5
|
import assert from 'node:assert';
|
|
6
6
|
|
|
7
|
+
import { trackLeaks } from '@dxos/async';
|
|
7
8
|
import { Context } from '@dxos/context';
|
|
8
|
-
import { Database, DataPipelineControllerImpl, ISpace, Space } from '@dxos/echo-db';
|
|
9
|
+
import { Database, DataPipelineControllerImpl, ISpace, MetadataStore, Space, SnapshotManager } from '@dxos/echo-db';
|
|
9
10
|
import { PublicKey } from '@dxos/keys';
|
|
10
11
|
import { ModelFactory } from '@dxos/model-factory';
|
|
11
12
|
import { Presence } from '@dxos/teleport-extension-presence';
|
|
12
13
|
|
|
14
|
+
export type DataSpaceParams = {
|
|
15
|
+
inner: Space;
|
|
16
|
+
modelFactory: ModelFactory;
|
|
17
|
+
metadataStore: MetadataStore;
|
|
18
|
+
snapshotManager: SnapshotManager;
|
|
19
|
+
presence: Presence;
|
|
20
|
+
memberKey: PublicKey;
|
|
21
|
+
snapshotId?: string | undefined;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
@trackLeaks('open', 'close')
|
|
13
25
|
export class DataSpace implements ISpace {
|
|
14
26
|
private readonly _ctx = new Context();
|
|
15
27
|
private readonly _dataPipelineController: DataPipelineControllerImpl;
|
|
28
|
+
private readonly _inner: Space;
|
|
29
|
+
private readonly _presence: Presence;
|
|
16
30
|
|
|
17
|
-
constructor(
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
31
|
+
constructor(params: DataSpaceParams) {
|
|
32
|
+
this._inner = params.inner;
|
|
33
|
+
this._presence = params.presence;
|
|
34
|
+
this._dataPipelineController = new DataPipelineControllerImpl({
|
|
35
|
+
modelFactory: params.modelFactory,
|
|
36
|
+
metadataStore: params.metadataStore,
|
|
37
|
+
snapshotManager: params.snapshotManager,
|
|
38
|
+
memberKey: params.memberKey,
|
|
39
|
+
spaceKey: this._inner.key,
|
|
40
|
+
feedInfoProvider: (feedKey) => this._inner.spaceState.feeds.get(feedKey),
|
|
41
|
+
snapshotId: params.snapshotId
|
|
42
|
+
});
|
|
26
43
|
}
|
|
27
44
|
|
|
28
45
|
get key() {
|
|
@@ -56,6 +73,7 @@ export class DataSpace implements ISpace {
|
|
|
56
73
|
|
|
57
74
|
async open() {
|
|
58
75
|
await this._inner.open();
|
|
76
|
+
await this._inner.initDataPipeline(this._dataPipelineController);
|
|
59
77
|
}
|
|
60
78
|
|
|
61
79
|
async close() {
|
|
@@ -2,18 +2,25 @@
|
|
|
2
2
|
// Copyright 2022 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
+
import { scheduleTask } from '@dxos/async';
|
|
5
6
|
import { Stream } from '@dxos/codec-protobuf';
|
|
7
|
+
import { raise } from '@dxos/debug';
|
|
8
|
+
import { SpaceManager, SpaceNotFoundError } from '@dxos/echo-db';
|
|
6
9
|
import {
|
|
10
|
+
QueryCredentialsRequest,
|
|
7
11
|
QueryMembersRequest,
|
|
8
12
|
QueryMembersResponse,
|
|
9
13
|
Space,
|
|
10
14
|
SpacesService
|
|
11
15
|
} from '@dxos/protocols/proto/dxos/client/services';
|
|
16
|
+
import { Credential } from '@dxos/protocols/proto/dxos/halo/credentials';
|
|
12
17
|
|
|
13
18
|
/**
|
|
14
19
|
*
|
|
15
20
|
*/
|
|
16
21
|
export class SpacesServiceImpl implements SpacesService {
|
|
22
|
+
constructor(private readonly _spaceManager: SpaceManager) {}
|
|
23
|
+
|
|
17
24
|
async createSpace(): Promise<Space> {
|
|
18
25
|
throw new Error();
|
|
19
26
|
}
|
|
@@ -25,4 +32,18 @@ export class SpacesServiceImpl implements SpacesService {
|
|
|
25
32
|
queryMembers(query: QueryMembersRequest): Stream<QueryMembersResponse> {
|
|
26
33
|
throw new Error();
|
|
27
34
|
}
|
|
35
|
+
|
|
36
|
+
queryCredentials({ spaceKey }: QueryCredentialsRequest): Stream<Credential> {
|
|
37
|
+
return new Stream(({ ctx, next }) => {
|
|
38
|
+
const space = this._spaceManager.spaces.get(spaceKey) ?? raise(new SpaceNotFoundError(spaceKey));
|
|
39
|
+
|
|
40
|
+
const processor = space.spaceState.registerProcessor({
|
|
41
|
+
process: async (credential) => {
|
|
42
|
+
next(credential);
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
ctx.onDispose(() => processor.close());
|
|
46
|
+
scheduleTask(ctx, () => processor.open());
|
|
47
|
+
});
|
|
48
|
+
}
|
|
28
49
|
}
|
|
@@ -1,20 +1,15 @@
|
|
|
1
1
|
//
|
|
2
|
-
// Copyright 2021 DXOS.org
|
|
3
|
-
//
|
|
4
2
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
//
|
|
4
|
+
// Copyright 2023 DXOS.org
|
|
5
|
+
//
|
|
8
6
|
|
|
9
7
|
import { InvalidConfigError } from '@dxos/errors';
|
|
10
8
|
import { Runtime } from '@dxos/protocols/proto/dxos/config';
|
|
11
9
|
import { createStorage, StorageType } from '@dxos/random-access-storage';
|
|
12
|
-
import { isNode } from '@dxos/util';
|
|
13
10
|
|
|
14
11
|
import StorageDriver = Runtime.Client.Storage.StorageDriver;
|
|
15
12
|
|
|
16
|
-
export type KeyStorageType = 'ram' | 'leveljs' | 'jsondown';
|
|
17
|
-
|
|
18
13
|
// TODO(burdon): Factor out.
|
|
19
14
|
export const createStorageObjects = (config: Runtime.Client.Storage) => {
|
|
20
15
|
const {
|
|
@@ -41,27 +36,10 @@ export const createStorageObjects = (config: Runtime.Client.Storage) => {
|
|
|
41
36
|
storage: createStorage({
|
|
42
37
|
type: persistent ? toStorageType(storageType) : StorageType.RAM,
|
|
43
38
|
root: `${path}/`
|
|
44
|
-
})
|
|
45
|
-
keyStorage: createKeyStorage(`${path}/keystore`, persistent ? toKeyStorageType(keyStorage) : 'ram')
|
|
39
|
+
})
|
|
46
40
|
};
|
|
47
41
|
};
|
|
48
42
|
|
|
49
|
-
// TODO(burdon): Factor out.
|
|
50
|
-
const createKeyStorage = (path: string, type?: KeyStorageType) => {
|
|
51
|
-
const defaultedType = type ?? (isNode() ? 'jsondown' : 'leveljs');
|
|
52
|
-
|
|
53
|
-
switch (defaultedType) {
|
|
54
|
-
case 'leveljs':
|
|
55
|
-
return leveljs(path);
|
|
56
|
-
case 'jsondown':
|
|
57
|
-
return jsondown(path);
|
|
58
|
-
case 'ram':
|
|
59
|
-
return memdown();
|
|
60
|
-
default:
|
|
61
|
-
throw new InvalidConfigError(`Invalid key storage type: ${defaultedType}`);
|
|
62
|
-
}
|
|
63
|
-
};
|
|
64
|
-
|
|
65
43
|
const toStorageType = (type: StorageDriver | undefined): StorageType | undefined => {
|
|
66
44
|
switch (type) {
|
|
67
45
|
case undefined:
|
|
@@ -80,18 +58,3 @@ const toStorageType = (type: StorageDriver | undefined): StorageType | undefined
|
|
|
80
58
|
throw new Error(`Invalid storage type: ${StorageDriver[type]}`);
|
|
81
59
|
}
|
|
82
60
|
};
|
|
83
|
-
|
|
84
|
-
const toKeyStorageType = (type: StorageDriver | undefined): KeyStorageType | undefined => {
|
|
85
|
-
switch (type) {
|
|
86
|
-
case undefined:
|
|
87
|
-
return undefined;
|
|
88
|
-
case StorageDriver.RAM:
|
|
89
|
-
return 'ram';
|
|
90
|
-
case StorageDriver.LEVELJS:
|
|
91
|
-
return 'leveljs';
|
|
92
|
-
case StorageDriver.JSONDOWN:
|
|
93
|
-
return 'jsondown';
|
|
94
|
-
default:
|
|
95
|
-
throw new Error(`Invalid key storage type: ${StorageDriver[type]}`);
|
|
96
|
-
}
|
|
97
|
-
};
|
|
@@ -61,6 +61,7 @@ export class WorkerSession {
|
|
|
61
61
|
DevicesService: async () => (await this._getServices()).services.DevicesService,
|
|
62
62
|
SpaceInvitationsService: async () => (await this._getServices()).services.SpaceInvitationsService,
|
|
63
63
|
SpacesService: async () => (await this._getServices()).services.SpacesService,
|
|
64
|
+
NetworkService: async () => (await this._getServices()).services.NetworkService,
|
|
64
65
|
SpaceService: async () => (await this._getServices()).services.SpaceService,
|
|
65
66
|
DataService: async () => (await this._getServices()).services.DataService,
|
|
66
67
|
ProfileService: async () => (await this._getServices()).services.ProfileService,
|