@dxos/client-services 0.4.10-main.cd13a57 → 0.4.10-main.cfbf503
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-UFFMYQPD.mjs → chunk-PPCSGOUM.mjs} +116 -73
- package/dist/lib/browser/{chunk-UFFMYQPD.mjs.map → chunk-PPCSGOUM.mjs.map} +4 -4
- package/dist/lib/browser/index.mjs +3 -1
- package/dist/lib/browser/index.mjs.map +1 -1
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/packlets/testing/index.mjs +6 -4
- package/dist/lib/browser/packlets/testing/index.mjs.map +3 -3
- package/dist/lib/node/{chunk-73BOAPSS.cjs → chunk-5O2MOLHJ.cjs} +109 -71
- package/dist/lib/node/{chunk-73BOAPSS.cjs.map → chunk-5O2MOLHJ.cjs.map} +4 -4
- package/dist/lib/node/index.cjs +39 -37
- package/dist/lib/node/index.cjs.map +1 -1
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/packlets/testing/index.cjs +10 -8
- package/dist/lib/node/packlets/testing/index.cjs.map +3 -3
- package/dist/types/src/packlets/indexing/util.d.ts +2 -2
- package/dist/types/src/packlets/indexing/util.d.ts.map +1 -1
- package/dist/types/src/packlets/services/service-context.d.ts +7 -5
- package/dist/types/src/packlets/services/service-context.d.ts.map +1 -1
- package/dist/types/src/packlets/services/service-host.d.ts +1 -0
- package/dist/types/src/packlets/services/service-host.d.ts.map +1 -1
- package/dist/types/src/packlets/storage/index.d.ts +1 -0
- package/dist/types/src/packlets/storage/index.d.ts.map +1 -1
- package/dist/types/src/packlets/storage/level.d.ts +4 -0
- package/dist/types/src/packlets/storage/level.d.ts.map +1 -0
- package/dist/types/src/packlets/storage/storage.d.ts.map +1 -1
- package/dist/types/src/packlets/storage/util.d.ts +4 -0
- package/dist/types/src/packlets/storage/util.d.ts.map +1 -0
- package/dist/types/src/packlets/testing/test-builder.d.ts +1 -1
- package/dist/types/src/packlets/testing/test-builder.d.ts.map +1 -1
- package/dist/types/src/version.d.ts +1 -1
- package/package.json +35 -34
- package/src/packlets/devices/devices-service.test.ts +1 -1
- package/src/packlets/identity/identity-service.test.ts +1 -1
- package/src/packlets/indexing/util.ts +4 -4
- package/src/packlets/invitations/device-invitation-protocol.test.ts +1 -1
- package/src/packlets/network/network-service.test.ts +1 -1
- package/src/packlets/services/service-context.test.ts +5 -5
- package/src/packlets/services/service-context.ts +13 -8
- package/src/packlets/services/service-host.ts +29 -8
- package/src/packlets/services/service-registry.test.ts +1 -1
- package/src/packlets/spaces/spaces-service.test.ts +1 -1
- package/src/packlets/storage/index.ts +1 -0
- package/src/packlets/storage/level.ts +19 -0
- package/src/packlets/storage/storage.ts +3 -9
- package/src/packlets/storage/util.ts +19 -0
- package/src/packlets/testing/test-builder.ts +5 -3
- package/src/version.ts +1 -1
|
@@ -2,12 +2,14 @@
|
|
|
2
2
|
// Copyright 2021 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
+
import { type Level } from 'level';
|
|
6
|
+
|
|
5
7
|
import { Event, synchronized } from '@dxos/async';
|
|
6
|
-
import {
|
|
8
|
+
import { clientServiceBundle, defaultKey, type ClientServices, Properties } from '@dxos/client-protocol';
|
|
7
9
|
import { type Config } from '@dxos/config';
|
|
8
10
|
import { Context } from '@dxos/context';
|
|
9
|
-
import { DataServiceImpl, type SpaceDoc } from '@dxos/echo-pipeline';
|
|
10
|
-
import
|
|
11
|
+
import { DataServiceImpl, type ObjectStructure, encodeReference, type SpaceDoc } from '@dxos/echo-pipeline';
|
|
12
|
+
import * as E from '@dxos/echo-schema';
|
|
11
13
|
import { IndexServiceImpl } from '@dxos/indexing';
|
|
12
14
|
import { invariant } from '@dxos/invariant';
|
|
13
15
|
import { PublicKey } from '@dxos/keys';
|
|
@@ -32,7 +34,7 @@ import { Lock, type ResourceLock } from '../locks';
|
|
|
32
34
|
import { LoggingServiceImpl } from '../logging';
|
|
33
35
|
import { NetworkServiceImpl } from '../network';
|
|
34
36
|
import { SpacesServiceImpl } from '../spaces';
|
|
35
|
-
import { createStorageObjects } from '../storage';
|
|
37
|
+
import { createLevel, createStorageObjects } from '../storage';
|
|
36
38
|
import { SystemServiceImpl } from '../system';
|
|
37
39
|
|
|
38
40
|
export type ClientServicesHostParams = {
|
|
@@ -76,6 +78,7 @@ export class ClientServicesHost {
|
|
|
76
78
|
private _signalManager?: SignalManager;
|
|
77
79
|
private _networkManager?: NetworkManager;
|
|
78
80
|
private _storage?: Storage;
|
|
81
|
+
private _level?: Level<string, string>;
|
|
79
82
|
private _callbacks?: ClientServicesHostCallbacks;
|
|
80
83
|
private _devtoolsProxy?: WebsocketRpcClient<{}, ClientServices>;
|
|
81
84
|
|
|
@@ -226,12 +229,17 @@ export class ClientServicesHost {
|
|
|
226
229
|
|
|
227
230
|
this._opening = true;
|
|
228
231
|
log('opening...', { lockKey: this._resourceLock?.lockKey });
|
|
232
|
+
|
|
233
|
+
if (!this._level) {
|
|
234
|
+
this._level = await createLevel(this._config.get('runtime.client.storage', {})!);
|
|
235
|
+
}
|
|
229
236
|
await this._resourceLock?.acquire();
|
|
230
237
|
|
|
231
238
|
await this._loggingService.open();
|
|
232
239
|
|
|
233
240
|
this._serviceContext = new ServiceContext(
|
|
234
241
|
this._storage,
|
|
242
|
+
this._level,
|
|
235
243
|
this._networkManager,
|
|
236
244
|
this._signalManager,
|
|
237
245
|
this._runtimeParams,
|
|
@@ -323,6 +331,7 @@ export class ClientServicesHost {
|
|
|
323
331
|
this._serviceRegistry.setServices({ SystemService: this._systemService });
|
|
324
332
|
await this._loggingService.close();
|
|
325
333
|
await this._serviceContext.close();
|
|
334
|
+
await this._level?.close();
|
|
326
335
|
this._open = false;
|
|
327
336
|
this._statusUpdate.emit();
|
|
328
337
|
log('closed', { deviceKey });
|
|
@@ -347,18 +356,30 @@ export class ClientServicesHost {
|
|
|
347
356
|
await this._serviceContext.initialized.wait();
|
|
348
357
|
const space = await this._serviceContext.dataSpaceManager!.createSpace();
|
|
349
358
|
|
|
350
|
-
const obj: TypedObject = new Properties(undefined);
|
|
351
|
-
obj[defaultKey] = identity.identityKey.toHex();
|
|
352
|
-
|
|
353
359
|
const automergeIndex = space.automergeSpaceState.rootUrl;
|
|
354
360
|
invariant(automergeIndex);
|
|
355
361
|
const document = await this._serviceContext.automergeHost.repo.find<SpaceDoc>(automergeIndex as any);
|
|
356
362
|
await document.whenReady();
|
|
357
363
|
|
|
364
|
+
// TODO(dmaretskyi): Better API for low-level data access.
|
|
365
|
+
const properties: ObjectStructure = {
|
|
366
|
+
system: {
|
|
367
|
+
type: encodeReference(E.getTypeReference(Properties)!),
|
|
368
|
+
},
|
|
369
|
+
data: {
|
|
370
|
+
[defaultKey]: identity.identityKey.toHex(),
|
|
371
|
+
},
|
|
372
|
+
meta: {
|
|
373
|
+
keys: [],
|
|
374
|
+
},
|
|
375
|
+
};
|
|
376
|
+
const propertiesId = PublicKey.random().toHex();
|
|
358
377
|
document.change((doc: SpaceDoc) => {
|
|
359
|
-
assignDeep(doc, ['objects',
|
|
378
|
+
assignDeep(doc, ['objects', propertiesId], properties);
|
|
360
379
|
});
|
|
361
380
|
|
|
381
|
+
await this._serviceContext.automergeHost.repo.flush();
|
|
382
|
+
|
|
362
383
|
return identity;
|
|
363
384
|
}
|
|
364
385
|
}
|
|
@@ -31,7 +31,7 @@ const serviceBundle = createServiceBundle<TestServices>({
|
|
|
31
31
|
describe('service registry', () => {
|
|
32
32
|
test('builds a service registry', async () => {
|
|
33
33
|
const remoteSource = 'https://remote.source';
|
|
34
|
-
const serviceContext = createServiceContext();
|
|
34
|
+
const serviceContext = await createServiceContext();
|
|
35
35
|
await serviceContext.open(new Context());
|
|
36
36
|
|
|
37
37
|
const serviceRegistry = new ServiceRegistry(serviceBundle, {
|
|
@@ -22,7 +22,7 @@ describe('SpacesService', () => {
|
|
|
22
22
|
let spacesService: SpacesService;
|
|
23
23
|
|
|
24
24
|
beforeEach(async () => {
|
|
25
|
-
serviceContext = createServiceContext();
|
|
25
|
+
serviceContext = await createServiceContext();
|
|
26
26
|
await serviceContext.open(new Context());
|
|
27
27
|
spacesService = new SpacesServiceImpl(serviceContext.identityManager, serviceContext.spaceManager, async () => {
|
|
28
28
|
await serviceContext.initialized.wait();
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2024 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { Level } from 'level';
|
|
6
|
+
import path from 'node:path';
|
|
7
|
+
|
|
8
|
+
import { PublicKey } from '@dxos/keys';
|
|
9
|
+
import { type Runtime } from '@dxos/protocols/proto/dxos/config';
|
|
10
|
+
|
|
11
|
+
import { getRootPath, isPersistent } from './util';
|
|
12
|
+
|
|
13
|
+
export const createLevel = async (config: Runtime.Client.Storage) => {
|
|
14
|
+
const persistent = isPersistent(config);
|
|
15
|
+
const storagePath = persistent ? getRootPath(config) : path.join('tmp', 'level', PublicKey.random().toHex());
|
|
16
|
+
const level = new Level<string, string>(storagePath);
|
|
17
|
+
await level.open();
|
|
18
|
+
return level;
|
|
19
|
+
};
|
|
@@ -4,22 +4,16 @@
|
|
|
4
4
|
// Copyright 2023 DXOS.org
|
|
5
5
|
//
|
|
6
6
|
|
|
7
|
-
import { DX_DATA } from '@dxos/client-protocol';
|
|
8
7
|
import { InvalidConfigError } from '@dxos/protocols';
|
|
9
8
|
import { Runtime } from '@dxos/protocols/proto/dxos/config';
|
|
10
9
|
import { createStorage, StorageType } from '@dxos/random-access-storage';
|
|
11
|
-
import { isNode } from '@dxos/util';
|
|
12
10
|
|
|
13
11
|
import StorageDriver = Runtime.Client.Storage.StorageDriver;
|
|
12
|
+
import { getRootPath } from './util';
|
|
14
13
|
|
|
15
14
|
// TODO(burdon): Factor out.
|
|
16
15
|
export const createStorageObjects = (config: Runtime.Client.Storage) => {
|
|
17
|
-
const {
|
|
18
|
-
persistent = false,
|
|
19
|
-
keyStore,
|
|
20
|
-
dataStore,
|
|
21
|
-
dataRoot = isNode() ? DX_DATA : 'dxos/storage', // TODO(burdon): Factor out const.
|
|
22
|
-
} = config ?? {};
|
|
16
|
+
const { persistent = false, keyStore, dataStore } = config ?? {};
|
|
23
17
|
|
|
24
18
|
if (persistent && dataStore === StorageDriver.RAM) {
|
|
25
19
|
throw new InvalidConfigError('RAM storage cannot be used in persistent mode.');
|
|
@@ -37,7 +31,7 @@ export const createStorageObjects = (config: Runtime.Client.Storage) => {
|
|
|
37
31
|
return {
|
|
38
32
|
storage: createStorage({
|
|
39
33
|
type: persistent ? toStorageType(dataStore) : StorageType.RAM,
|
|
40
|
-
root:
|
|
34
|
+
root: getRootPath(config),
|
|
41
35
|
}),
|
|
42
36
|
};
|
|
43
37
|
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2024 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { DX_DATA } from '@dxos/client-protocol';
|
|
6
|
+
import { Runtime } from '@dxos/protocols/proto/dxos/config';
|
|
7
|
+
import { isNode } from '@dxos/util';
|
|
8
|
+
|
|
9
|
+
export const getRootPath = (config: Runtime.Client.Storage) => {
|
|
10
|
+
const { dataRoot = isNode() ? DX_DATA : 'dxos/storage' } = config ?? {};
|
|
11
|
+
return `${dataRoot}/`;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export const isPersistent = (config: Runtime.Client.Storage) => {
|
|
15
|
+
const { persistent = false } = config ?? {};
|
|
16
|
+
return (
|
|
17
|
+
(config.dataStore !== undefined && config.dataStore !== Runtime.Client.Storage.StorageDriver.RAM) || persistent
|
|
18
|
+
);
|
|
19
|
+
};
|
|
@@ -8,6 +8,7 @@ import { createCredentialSignerWithChain, CredentialGenerator } from '@dxos/cred
|
|
|
8
8
|
import { failUndefined } from '@dxos/debug';
|
|
9
9
|
import { AutomergeHost, MetadataStore, SnapshotStore, SpaceManager, valueEncoding } from '@dxos/echo-pipeline';
|
|
10
10
|
import { FeedFactory, FeedStore } from '@dxos/feed-store';
|
|
11
|
+
import { createTestLevel } from '@dxos/indexing/testing';
|
|
11
12
|
import { Keyring } from '@dxos/keyring';
|
|
12
13
|
import { MemorySignalManager, MemorySignalManagerContext } from '@dxos/messaging';
|
|
13
14
|
import { MemoryTransportFactory, NetworkManager } from '@dxos/network-manager';
|
|
@@ -29,7 +30,7 @@ export const createServiceHost = (config: Config, signalManagerContext: MemorySi
|
|
|
29
30
|
});
|
|
30
31
|
};
|
|
31
32
|
|
|
32
|
-
export const createServiceContext = ({
|
|
33
|
+
export const createServiceContext = async ({
|
|
33
34
|
signalContext = new MemorySignalManagerContext(),
|
|
34
35
|
storage = createStorage({ type: StorageType.RAM }),
|
|
35
36
|
}: {
|
|
@@ -41,8 +42,9 @@ export const createServiceContext = ({
|
|
|
41
42
|
signalManager,
|
|
42
43
|
transportFactory: MemoryTransportFactory,
|
|
43
44
|
});
|
|
45
|
+
const level = await createTestLevel();
|
|
44
46
|
|
|
45
|
-
return new ServiceContext(storage, networkManager, signalManager);
|
|
47
|
+
return new ServiceContext(storage, level, networkManager, signalManager);
|
|
46
48
|
};
|
|
47
49
|
|
|
48
50
|
export const createPeers = async (numPeers: number) => {
|
|
@@ -50,7 +52,7 @@ export const createPeers = async (numPeers: number) => {
|
|
|
50
52
|
|
|
51
53
|
return await Promise.all(
|
|
52
54
|
Array.from(Array(numPeers)).map(async () => {
|
|
53
|
-
const peer = createServiceContext({ signalContext });
|
|
55
|
+
const peer = await createServiceContext({ signalContext });
|
|
54
56
|
await peer.open(new Context());
|
|
55
57
|
return peer;
|
|
56
58
|
}),
|
package/src/version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const DXOS_VERSION = "0.4.10-main.
|
|
1
|
+
export const DXOS_VERSION = "0.4.10-main.cfbf503";
|