@dxos/client-services 0.5.9-main.bdf733d → 0.5.9-main.bf3bb8f
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-KNGR7BYM.mjs → chunk-IUSAD4RP.mjs} +1678 -935
- package/dist/lib/browser/chunk-IUSAD4RP.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +13 -4
- 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 +20 -13
- package/dist/lib/browser/packlets/testing/index.mjs.map +3 -3
- package/dist/lib/node/{chunk-WWHTBQNR.cjs → chunk-5PALJZPW.cjs} +1936 -1200
- package/dist/lib/node/chunk-5PALJZPW.cjs.map +7 -0
- package/dist/lib/node/index.cjs +53 -44
- 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 +26 -19
- package/dist/lib/node/packlets/testing/index.cjs.map +3 -3
- package/dist/types/src/packlets/identity/contacts-service.d.ts +14 -0
- package/dist/types/src/packlets/identity/contacts-service.d.ts.map +1 -0
- package/dist/types/src/packlets/identity/default-space-state-machine.d.ts +19 -0
- package/dist/types/src/packlets/identity/default-space-state-machine.d.ts.map +1 -0
- package/dist/types/src/packlets/identity/identity-service.d.ts +14 -7
- package/dist/types/src/packlets/identity/identity-service.d.ts.map +1 -1
- package/dist/types/src/packlets/identity/identity.d.ts +4 -1
- package/dist/types/src/packlets/identity/identity.d.ts.map +1 -1
- package/dist/types/src/packlets/invitations/invitations-handler.d.ts.map +1 -1
- package/dist/types/src/packlets/invitations/space-invitation-protocol.d.ts.map +1 -1
- package/dist/types/src/packlets/services/service-context.d.ts.map +1 -1
- package/dist/types/src/packlets/services/service-host.d.ts +1 -1
- package/dist/types/src/packlets/services/service-host.d.ts.map +1 -1
- package/dist/types/src/packlets/spaces/automerge-space-state.d.ts +4 -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 +15 -4
- package/dist/types/src/packlets/spaces/data-space-manager.d.ts.map +1 -1
- package/dist/types/src/packlets/spaces/data-space.d.ts +10 -9
- package/dist/types/src/packlets/spaces/data-space.d.ts.map +1 -1
- package/dist/types/src/packlets/spaces/epoch-migrations.d.ts +23 -0
- package/dist/types/src/packlets/spaces/epoch-migrations.d.ts.map +1 -0
- package/dist/types/src/packlets/spaces/spaces-service.d.ts +5 -2
- package/dist/types/src/packlets/spaces/spaces-service.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/profile-archive.d.ts +14 -0
- package/dist/types/src/packlets/storage/profile-archive.d.ts.map +1 -0
- package/dist/types/src/packlets/testing/test-builder.d.ts +8 -6
- 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 +36 -36
- package/src/packlets/identity/contacts-service.ts +85 -0
- package/src/packlets/identity/default-space-state-machine.ts +44 -0
- package/src/packlets/identity/identity-service.test.ts +35 -5
- package/src/packlets/identity/identity-service.ts +82 -8
- package/src/packlets/identity/identity.ts +25 -2
- package/src/packlets/invitations/invitations-handler.ts +13 -5
- package/src/packlets/invitations/space-invitation-protocol.ts +11 -32
- package/src/packlets/services/service-context.ts +1 -4
- package/src/packlets/services/service-host.ts +23 -42
- package/src/packlets/spaces/automerge-space-state.ts +11 -2
- package/src/packlets/spaces/data-space-manager.test.ts +46 -1
- package/src/packlets/spaces/data-space-manager.ts +136 -33
- package/src/packlets/spaces/data-space.ts +89 -140
- package/src/packlets/spaces/epoch-migrations.ts +154 -0
- package/src/packlets/spaces/spaces-service.ts +56 -4
- package/src/packlets/storage/index.ts +1 -0
- package/src/packlets/storage/profile-archive.ts +111 -0
- package/src/packlets/testing/test-builder.ts +12 -10
- package/src/version.ts +1 -1
- package/dist/lib/browser/chunk-KNGR7BYM.mjs.map +0 -7
- package/dist/lib/node/chunk-WWHTBQNR.cjs.map +0 -7
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { Event } from '@dxos/async';
|
|
2
|
-
import {
|
|
2
|
+
import type { SpecificCredential } from '@dxos/credentials';
|
|
3
|
+
import { type EchoHost, type DatabaseRoot } from '@dxos/echo-db';
|
|
3
4
|
import { type MetadataStore, type Space } from '@dxos/echo-pipeline';
|
|
4
|
-
import { type ObjectStructure, type SpaceDoc } from '@dxos/echo-protocol';
|
|
5
5
|
import { type FeedStore } from '@dxos/feed-store';
|
|
6
6
|
import { type Keyring } from '@dxos/keyring';
|
|
7
7
|
import { PublicKey } from '@dxos/keys';
|
|
8
|
-
import { CreateEpochRequest, SpaceState, type Space as SpaceProto } from '@dxos/protocols/proto/dxos/client/services';
|
|
8
|
+
import { type CreateEpochRequest, SpaceState, type Space as SpaceProto } from '@dxos/protocols/proto/dxos/client/services';
|
|
9
9
|
import { type FeedMessage } from '@dxos/protocols/proto/dxos/echo/feed';
|
|
10
10
|
import { type SpaceCache } from '@dxos/protocols/proto/dxos/echo/metadata';
|
|
11
|
-
import { type ProfileDocument } from '@dxos/protocols/proto/dxos/halo/credentials';
|
|
11
|
+
import { type Epoch, type ProfileDocument } from '@dxos/protocols/proto/dxos/halo/credentials';
|
|
12
12
|
import { type GossipMessage } from '@dxos/protocols/proto/dxos/mesh/teleport/gossip';
|
|
13
13
|
import { type Gossip, type Presence } from '@dxos/teleport-extension-gossip';
|
|
14
14
|
import { AutomergeSpaceState } from './automerge-space-state';
|
|
@@ -44,6 +44,7 @@ export type DataSpaceParams = {
|
|
|
44
44
|
};
|
|
45
45
|
export type CreateEpochOptions = {
|
|
46
46
|
migration?: CreateEpochRequest.Migration;
|
|
47
|
+
newAutomergeRoot?: string;
|
|
47
48
|
};
|
|
48
49
|
export declare class DataSpace {
|
|
49
50
|
private _ctx;
|
|
@@ -59,7 +60,9 @@ export declare class DataSpace {
|
|
|
59
60
|
private readonly _cache?;
|
|
60
61
|
private readonly _echoHost;
|
|
61
62
|
private readonly _automergeSpaceState;
|
|
63
|
+
private readonly _epochProcessingMutex;
|
|
62
64
|
private _state;
|
|
65
|
+
private _databaseRoot;
|
|
63
66
|
/**
|
|
64
67
|
* Error for _state === SpaceState.ERROR.
|
|
65
68
|
*/
|
|
@@ -77,6 +80,7 @@ export declare class DataSpace {
|
|
|
77
80
|
get notarizationPlugin(): NotarizationPlugin;
|
|
78
81
|
get cache(): SpaceCache | undefined;
|
|
79
82
|
get automergeSpaceState(): AutomergeSpaceState;
|
|
83
|
+
get databaseRoot(): DatabaseRoot | null;
|
|
80
84
|
private get _automergeInfo();
|
|
81
85
|
open(): Promise<void>;
|
|
82
86
|
private _open;
|
|
@@ -91,16 +95,13 @@ export declare class DataSpace {
|
|
|
91
95
|
*/
|
|
92
96
|
initializeDataPipelineAsync(): void;
|
|
93
97
|
initializeDataPipeline(): Promise<void>;
|
|
98
|
+
private _enterReadyState;
|
|
94
99
|
private _initializeAndReadControlPipeline;
|
|
95
100
|
private _createWritableFeeds;
|
|
96
101
|
private _onNewAutomergeRoot;
|
|
97
102
|
updateOwnProfile(profile: ProfileDocument): Promise<void>;
|
|
98
|
-
createEpoch(options?: CreateEpochOptions): Promise<
|
|
103
|
+
createEpoch(options?: CreateEpochOptions): Promise<SpecificCredential<Epoch> | null>;
|
|
99
104
|
activate(): Promise<void>;
|
|
100
105
|
deactivate(): Promise<void>;
|
|
101
106
|
}
|
|
102
|
-
/**
|
|
103
|
-
* Assumes properties are at root.
|
|
104
|
-
*/
|
|
105
|
-
export declare const findPropertiesObject: (spaceDoc: SpaceDoc) => [string, ObjectStructure] | undefined;
|
|
106
107
|
//# sourceMappingURL=data-space.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"data-space.d.ts","sourceRoot":"","sources":["../../../../../src/packlets/spaces/data-space.ts"],"names":[],"mappings":"AA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AajB"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { type Context } from '@dxos/context';
|
|
2
|
+
import { type EchoHost } from '@dxos/echo-db';
|
|
3
|
+
import type { PublicKey, SpaceId } from '@dxos/keys';
|
|
4
|
+
import { CreateEpochRequest } from '@dxos/protocols/proto/dxos/client/services';
|
|
5
|
+
export type MigrationContext = {
|
|
6
|
+
echoHost: EchoHost;
|
|
7
|
+
spaceId: SpaceId;
|
|
8
|
+
/**
|
|
9
|
+
* @deprecated Remove.
|
|
10
|
+
*/
|
|
11
|
+
spaceKey: PublicKey;
|
|
12
|
+
migration: CreateEpochRequest.Migration;
|
|
13
|
+
currentRoot: string | null;
|
|
14
|
+
/**
|
|
15
|
+
* For set automerge root migration type.
|
|
16
|
+
*/
|
|
17
|
+
newAutomergeRoot?: string;
|
|
18
|
+
};
|
|
19
|
+
export type MigrationResult = {
|
|
20
|
+
newRoot?: string;
|
|
21
|
+
};
|
|
22
|
+
export declare const runEpochMigration: (ctx: Context, context: MigrationContext) => Promise<MigrationResult>;
|
|
23
|
+
//# sourceMappingURL=epoch-migrations.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"epoch-migrations.d.ts","sourceRoot":"","sources":["../../../../../src/packlets/spaces/epoch-migrations.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,KAAK,OAAO,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,EAKL,KAAK,QAAQ,EACd,MAAM,eAAe,CAAC;AAIvB,OAAO,KAAK,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAErD,OAAO,EAAE,kBAAkB,EAAE,MAAM,4CAA4C,CAAC;AAEhF,MAAM,MAAM,gBAAgB,GAAG;IAC7B,QAAQ,EAAE,QAAQ,CAAC;IAEnB,OAAO,EAAE,OAAO,CAAC;IACjB;;OAEG;IACH,QAAQ,EAAE,SAAS,CAAC;IACpB,SAAS,EAAE,kBAAkB,CAAC,SAAS,CAAC;IACxC,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IAE3B;;OAEG;IACH,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG;IAC5B,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAIF,eAAO,MAAM,iBAAiB,QAAe,OAAO,WAAW,gBAAgB,KAAG,QAAQ,eAAe,CA8GxG,CAAC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Stream } from '@dxos/codec-protobuf';
|
|
2
2
|
import { type SpaceManager } from '@dxos/echo-pipeline';
|
|
3
|
-
import { type CreateEpochRequest, type PostMessageRequest, type QueryCredentialsRequest, type QuerySpacesResponse, type Space, type SpacesService, type SubscribeMessagesRequest, type UpdateSpaceRequest, type WriteCredentialsRequest, type UpdateMemberRoleRequest } from '@dxos/protocols/proto/dxos/client/services';
|
|
3
|
+
import { type CreateEpochRequest, type PostMessageRequest, type QueryCredentialsRequest, type QuerySpacesResponse, type Space, type SpacesService, type SubscribeMessagesRequest, type UpdateSpaceRequest, type WriteCredentialsRequest, type UpdateMemberRoleRequest, type AdmitContactRequest, type JoinSpaceResponse, type JoinBySpaceKeyRequest, type CreateEpochResponse } from '@dxos/protocols/proto/dxos/client/services';
|
|
4
4
|
import { type Credential } from '@dxos/protocols/proto/dxos/halo/credentials';
|
|
5
5
|
import { type GossipMessage } from '@dxos/protocols/proto/dxos/mesh/teleport/gossip';
|
|
6
6
|
import { type Provider } from '@dxos/util';
|
|
@@ -19,7 +19,10 @@ export declare class SpacesServiceImpl implements SpacesService {
|
|
|
19
19
|
subscribeMessages({ spaceKey, channel }: SubscribeMessagesRequest): Stream<GossipMessage>;
|
|
20
20
|
queryCredentials({ spaceKey, noTail }: QueryCredentialsRequest): Stream<Credential>;
|
|
21
21
|
writeCredentials({ spaceKey, credentials }: WriteCredentialsRequest): Promise<void>;
|
|
22
|
-
createEpoch({ spaceKey, migration }: CreateEpochRequest): Promise<
|
|
22
|
+
createEpoch({ spaceKey, migration, automergeRootUrl }: CreateEpochRequest): Promise<CreateEpochResponse>;
|
|
23
|
+
admitContact(request: AdmitContactRequest): Promise<void>;
|
|
24
|
+
joinBySpaceKey({ spaceKey }: JoinBySpaceKeyRequest): Promise<JoinSpaceResponse>;
|
|
25
|
+
private _joinByAdmission;
|
|
23
26
|
private _serializeSpace;
|
|
24
27
|
private _requireIdentity;
|
|
25
28
|
private _updateMetrics;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"spaces-service.d.ts","sourceRoot":"","sources":["../../../../../src/packlets/spaces/spaces-service.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAG9C,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAWxD,OAAO,EAGL,KAAK,kBAAkB,EACvB,KAAK,kBAAkB,EACvB,KAAK,uBAAuB,EAC5B,KAAK,mBAAmB,EACxB,KAAK,KAAK,EACV,KAAK,aAAa,EAClB,KAAK,wBAAwB,EAC7B,KAAK,kBAAkB,EACvB,KAAK,uBAAuB,EAC5B,KAAK,uBAAuB,
|
|
1
|
+
{"version":3,"file":"spaces-service.d.ts","sourceRoot":"","sources":["../../../../../src/packlets/spaces/spaces-service.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAG9C,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAWxD,OAAO,EAGL,KAAK,kBAAkB,EACvB,KAAK,kBAAkB,EACvB,KAAK,uBAAuB,EAC5B,KAAK,mBAAmB,EACxB,KAAK,KAAK,EACV,KAAK,aAAa,EAClB,KAAK,wBAAwB,EAC7B,KAAK,kBAAkB,EACvB,KAAK,uBAAuB,EAC5B,KAAK,uBAAuB,EAC5B,KAAK,mBAAmB,EAExB,KAAK,iBAAiB,EACtB,KAAK,qBAAqB,EAC1B,KAAK,mB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BAAmB,CAAC;IAOxG,YAAY,CAAC,OAAO,EAAE,mBAAmB,GAAG,OAAO,CAAC,IAAI,CAAC;IASzD,cAAc,CAAC,EAAE,QAAQ,EAAE,EAAE,qBAAqB,GAAG,OAAO,CAAC,iBAAiB,CAAC;YAMvE,gBAAgB;IAmB9B,OAAO,CAAC,eAAe;IA+CvB,OAAO,CAAC,gBAAgB;YASV,cAAc;CAS7B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/packlets/storage/index.ts"],"names":[],"mappings":"AAIA,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/packlets/storage/index.ts"],"names":[],"mappings":"AAIA,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC;AACxB,cAAc,mBAAmB,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { LevelDB } from '@dxos/kv-store';
|
|
2
|
+
import { type ProfileArchive } from '@dxos/protocols';
|
|
3
|
+
import type { Storage } from '@dxos/random-access-storage';
|
|
4
|
+
export declare const encodeProfileArchive: (profile: ProfileArchive) => Uint8Array;
|
|
5
|
+
export declare const decodeProfileArchive: (data: Uint8Array) => ProfileArchive;
|
|
6
|
+
export declare const exportProfileData: ({ storage, level, }: {
|
|
7
|
+
storage: Storage;
|
|
8
|
+
level: LevelDB;
|
|
9
|
+
}) => Promise<ProfileArchive>;
|
|
10
|
+
export declare const importProfileData: ({ storage, level, }: {
|
|
11
|
+
storage: Storage;
|
|
12
|
+
level: LevelDB;
|
|
13
|
+
}, archive: ProfileArchive) => Promise<void>;
|
|
14
|
+
//# sourceMappingURL=profile-archive.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"profile-archive.d.ts","sourceRoot":"","sources":["../../../../../src/packlets/storage/profile-archive.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAE9C,OAAO,EAA2B,KAAK,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAC/E,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,6BAA6B,CAAC;AAG3D,eAAO,MAAM,oBAAoB,YAAa,cAAc,KAAG,UAAkC,CAAC;AAElG,eAAO,MAAM,oBAAoB,SAAU,UAAU,KAAG,cAAmC,CAAC;AAE5F,eAAO,MAAM,iBAAiB,wBAG3B;IACD,OAAO,EAAE,OAAO,CAAC;IACjB,KAAK,EAAE,OAAO,CAAC;CAChB,KAAG,QAAQ,cAAc,CAqCzB,CAAC;AAEF,eAAO,MAAM,iBAAiB,wBAIzB;IACD,OAAO,EAAE,OAAO,CAAC;IACjB,KAAK,EAAE,OAAO,CAAC;CAChB,WACQ,cAAc,KACtB,QAAQ,IAAI,CAwCd,CAAC"}
|
|
@@ -9,12 +9,13 @@ import { SwarmNetworkManager } from '@dxos/network-manager';
|
|
|
9
9
|
import { StorageType, type Storage } from '@dxos/random-access-storage';
|
|
10
10
|
import { BlobStore } from '@dxos/teleport-extension-object-sync';
|
|
11
11
|
import { InvitationsManager } from '../invitations';
|
|
12
|
-
import { ClientServicesHost, ServiceContext } from '../services';
|
|
13
|
-
import { DataSpaceManager, type SigningContext } from '../spaces';
|
|
12
|
+
import { ClientServicesHost, ServiceContext, type ServiceContextRuntimeParams } from '../services';
|
|
13
|
+
import { DataSpaceManager, type DataSpaceManagerRuntimeParams, type SigningContext } from '../spaces';
|
|
14
14
|
export declare const createServiceHost: (config: Config, signalManagerContext: MemorySignalManagerContext) => ClientServicesHost;
|
|
15
|
-
export declare const createServiceContext: ({ signalContext, storage, }?: {
|
|
15
|
+
export declare const createServiceContext: ({ signalContext, storage, runtimeParams, }?: {
|
|
16
16
|
signalContext?: MemorySignalManagerContext;
|
|
17
17
|
storage?: Storage;
|
|
18
|
+
runtimeParams?: ServiceContextRuntimeParams;
|
|
18
19
|
}) => Promise<ServiceContext>;
|
|
19
20
|
export declare const createPeers: (numPeers: number) => Promise<ServiceContext[]>;
|
|
20
21
|
export declare const createIdentity: (peer: ServiceContext) => Promise<ServiceContext>;
|
|
@@ -26,6 +27,7 @@ export declare class TestBuilder {
|
|
|
26
27
|
}
|
|
27
28
|
export type TestPeerOpts = {
|
|
28
29
|
dataStore?: StorageType;
|
|
30
|
+
dataSpaceParams?: DataSpaceManagerRuntimeParams;
|
|
29
31
|
};
|
|
30
32
|
export type TestPeerProps = {
|
|
31
33
|
storage?: Storage;
|
|
@@ -43,10 +45,10 @@ export type TestPeerProps = {
|
|
|
43
45
|
invitationsManager?: InvitationsManager;
|
|
44
46
|
};
|
|
45
47
|
export declare class TestPeer {
|
|
46
|
-
private readonly
|
|
47
|
-
private readonly
|
|
48
|
+
private readonly _signalContext;
|
|
49
|
+
private readonly _opts;
|
|
48
50
|
private _props;
|
|
49
|
-
constructor(
|
|
51
|
+
constructor(_signalContext: MemorySignalManagerContext, _opts?: TestPeerOpts);
|
|
50
52
|
get props(): TestPeerProps;
|
|
51
53
|
get storage(): Storage;
|
|
52
54
|
get keyring(): Keyring;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"test-builder.d.ts","sourceRoot":"","sources":["../../../../../src/packlets/testing/test-builder.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,MAAM,EAAE,MAAM,cAAc,CAAC;AAI3C,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,YAAY,EAAiB,MAAM,qBAAqB,CAAC;AAChG,OAAO,EAAe,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC1D,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACxC,OAAO,EAAE,KAAK,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAE9C,OAAO,EAAuB,0BAA0B,EAAE,MAAM,iBAAiB,CAAC;AAClF,OAA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AC,MAAM,CAAqB;gBAGhB,cAAc,EAAE,0BAA0B,EAC1C,KAAK,GAAE,YAA6C;IAGvE,IAAI,KAAK,kBAER;IAED,IAAI,OAAO,YAEV;IAED,IAAI,OAAO,YAEV;IAED,IAAI,KAAK,YAER;IAED,IAAI,SAAS,mBAUZ;IAED,IAAI,aAAa,kBAEhB;IAED,IAAI,SAAS,cAEZ;IAED,IAAI,aAAa,kBAEhB;IAED,IAAI,cAAc,wBAKjB;IAED,IAAI,YAAY,iBAQf;IAED,IAAI,QAAQ,mBAEX;IAED,IAAI,QAAQ,aAEX;IAED,IAAI,gBAAgB,IAAI,gBAAgB,CAWvC;IAED,IAAI,kBAAkB,uBAYrB;IAEK,cAAc;IAId,OAAO;CAId;AAED,eAAO,MAAM,oBAAoB,YAAmB,OAAO,KAAG,QAAQ,cAAc,CAiBnF,CAAC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const DXOS_VERSION = "0.5.9-main.
|
|
1
|
+
export declare const DXOS_VERSION = "0.5.9-main.bf3bb8f";
|
|
2
2
|
//# sourceMappingURL=version.d.ts.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxos/client-services",
|
|
3
|
-
"version": "0.5.9-main.
|
|
3
|
+
"version": "0.5.9-main.bf3bb8f",
|
|
4
4
|
"description": "DXOS client services implementation",
|
|
5
5
|
"homepage": "https://dxos.org",
|
|
6
6
|
"bugs": "https://github.com/dxos/dxos/issues",
|
|
@@ -23,45 +23,45 @@
|
|
|
23
23
|
],
|
|
24
24
|
"dependencies": {
|
|
25
25
|
"platform": "^1.3.6",
|
|
26
|
-
"@dxos/async": "0.5.9-main.
|
|
27
|
-
"@dxos/
|
|
28
|
-
"@dxos/
|
|
29
|
-
"@dxos/
|
|
30
|
-
"@dxos/
|
|
31
|
-
"@dxos/
|
|
32
|
-
"@dxos/credentials": "0.5.9-main.
|
|
33
|
-
"@dxos/
|
|
34
|
-
"@dxos/
|
|
35
|
-
"@dxos/echo-db": "0.5.9-main.
|
|
36
|
-
"@dxos/echo-
|
|
37
|
-
"@dxos/echo-
|
|
38
|
-
"@dxos/echo-
|
|
39
|
-
"@dxos/
|
|
40
|
-
"@dxos/
|
|
41
|
-
"@dxos/keyring": "0.5.9-main.
|
|
42
|
-
"@dxos/
|
|
43
|
-
"@dxos/
|
|
44
|
-
"@dxos/
|
|
45
|
-
"@dxos/
|
|
46
|
-
"@dxos/log": "0.5.9-main.
|
|
47
|
-
"@dxos/
|
|
48
|
-
"@dxos/
|
|
49
|
-
"@dxos/
|
|
50
|
-
"@dxos/
|
|
51
|
-
"@dxos/
|
|
52
|
-
"@dxos/
|
|
53
|
-
"@dxos/
|
|
54
|
-
"@dxos/teleport-extension-gossip": "0.5.9-main.
|
|
55
|
-
"@dxos/teleport-extension-object-sync": "0.5.9-main.
|
|
56
|
-
"@dxos/timeframe": "0.5.9-main.
|
|
57
|
-
"@dxos/
|
|
58
|
-
"@dxos/
|
|
59
|
-
"@dxos/
|
|
26
|
+
"@dxos/async": "0.5.9-main.bf3bb8f",
|
|
27
|
+
"@dxos/automerge": "0.5.9-main.bf3bb8f",
|
|
28
|
+
"@dxos/client-protocol": "0.5.9-main.bf3bb8f",
|
|
29
|
+
"@dxos/codec-protobuf": "0.5.9-main.bf3bb8f",
|
|
30
|
+
"@dxos/context": "0.5.9-main.bf3bb8f",
|
|
31
|
+
"@dxos/config": "0.5.9-main.bf3bb8f",
|
|
32
|
+
"@dxos/credentials": "0.5.9-main.bf3bb8f",
|
|
33
|
+
"@dxos/crypto": "0.5.9-main.bf3bb8f",
|
|
34
|
+
"@dxos/debug": "0.5.9-main.bf3bb8f",
|
|
35
|
+
"@dxos/echo-db": "0.5.9-main.bf3bb8f",
|
|
36
|
+
"@dxos/echo-protocol": "0.5.9-main.bf3bb8f",
|
|
37
|
+
"@dxos/echo-schema": "0.5.9-main.bf3bb8f",
|
|
38
|
+
"@dxos/echo-pipeline": "0.5.9-main.bf3bb8f",
|
|
39
|
+
"@dxos/invariant": "0.5.9-main.bf3bb8f",
|
|
40
|
+
"@dxos/feed-store": "0.5.9-main.bf3bb8f",
|
|
41
|
+
"@dxos/keyring": "0.5.9-main.bf3bb8f",
|
|
42
|
+
"@dxos/keys": "0.5.9-main.bf3bb8f",
|
|
43
|
+
"@dxos/kv-store": "0.5.9-main.bf3bb8f",
|
|
44
|
+
"@dxos/lock-file": "0.5.9-main.bf3bb8f",
|
|
45
|
+
"@dxos/indexing": "0.5.9-main.bf3bb8f",
|
|
46
|
+
"@dxos/log": "0.5.9-main.bf3bb8f",
|
|
47
|
+
"@dxos/node-std": "0.5.9-main.bf3bb8f",
|
|
48
|
+
"@dxos/messaging": "0.5.9-main.bf3bb8f",
|
|
49
|
+
"@dxos/protocols": "0.5.9-main.bf3bb8f",
|
|
50
|
+
"@dxos/random-access-storage": "0.5.9-main.bf3bb8f",
|
|
51
|
+
"@dxos/rpc": "0.5.9-main.bf3bb8f",
|
|
52
|
+
"@dxos/network-manager": "0.5.9-main.bf3bb8f",
|
|
53
|
+
"@dxos/teleport": "0.5.9-main.bf3bb8f",
|
|
54
|
+
"@dxos/teleport-extension-gossip": "0.5.9-main.bf3bb8f",
|
|
55
|
+
"@dxos/teleport-extension-object-sync": "0.5.9-main.bf3bb8f",
|
|
56
|
+
"@dxos/timeframe": "0.5.9-main.bf3bb8f",
|
|
57
|
+
"@dxos/tracing": "0.5.9-main.bf3bb8f",
|
|
58
|
+
"@dxos/websocket-rpc": "0.5.9-main.bf3bb8f",
|
|
59
|
+
"@dxos/util": "0.5.9-main.bf3bb8f"
|
|
60
60
|
},
|
|
61
61
|
"devDependencies": {
|
|
62
62
|
"@types/platform": "^1.3.4",
|
|
63
63
|
"@types/readable-stream": "^2.3.9",
|
|
64
|
-
"@dxos/signal": "0.5.9-main.
|
|
64
|
+
"@dxos/signal": "0.5.9-main.bf3bb8f"
|
|
65
65
|
},
|
|
66
66
|
"publishConfig": {
|
|
67
67
|
"access": "public"
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2024 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { EventSubscriptions, scheduleTask, UpdateScheduler } from '@dxos/async';
|
|
6
|
+
import { Stream } from '@dxos/codec-protobuf';
|
|
7
|
+
import { type MemberInfo } from '@dxos/credentials';
|
|
8
|
+
import type { SpaceManager } from '@dxos/echo-pipeline';
|
|
9
|
+
import { PublicKey } from '@dxos/keys';
|
|
10
|
+
import { type Contact, type ContactBook, type ContactsService } from '@dxos/protocols/proto/dxos/client/services';
|
|
11
|
+
import { ComplexMap, ComplexSet } from '@dxos/util';
|
|
12
|
+
|
|
13
|
+
import { type IdentityManager } from './identity-manager';
|
|
14
|
+
import { type DataSpaceManager } from '../spaces';
|
|
15
|
+
|
|
16
|
+
export class ContactsServiceImpl implements ContactsService {
|
|
17
|
+
constructor(
|
|
18
|
+
private readonly _identityManager: IdentityManager,
|
|
19
|
+
private readonly _spaceManager: SpaceManager,
|
|
20
|
+
private readonly _dataSpaceManagerProvider: () => Promise<DataSpaceManager>,
|
|
21
|
+
) {}
|
|
22
|
+
|
|
23
|
+
async getContacts(): Promise<ContactBook> {
|
|
24
|
+
const identity = this._identityManager.identity;
|
|
25
|
+
if (identity == null) {
|
|
26
|
+
return { contacts: [] };
|
|
27
|
+
}
|
|
28
|
+
const contacts = [...this._spaceManager.spaces.values()]
|
|
29
|
+
.flatMap((s) => [...s.spaceState.members.values()].map((m) => [s.key, m]))
|
|
30
|
+
.reduce((acc, v) => {
|
|
31
|
+
const [spaceKey, memberInfo] = v as [PublicKey, MemberInfo];
|
|
32
|
+
if (memberInfo.key.equals(identity.identityKey)) {
|
|
33
|
+
return acc;
|
|
34
|
+
}
|
|
35
|
+
const existing = acc.get(memberInfo.key);
|
|
36
|
+
if (existing != null) {
|
|
37
|
+
existing.profile ??= memberInfo.profile;
|
|
38
|
+
existing.commonSpaces?.push(spaceKey);
|
|
39
|
+
} else {
|
|
40
|
+
acc.set(memberInfo.key, {
|
|
41
|
+
identityKey: memberInfo.key,
|
|
42
|
+
profile: memberInfo.profile,
|
|
43
|
+
commonSpaces: [spaceKey],
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
return acc;
|
|
47
|
+
}, new ComplexMap<PublicKey, Contact>(PublicKey.hash));
|
|
48
|
+
return {
|
|
49
|
+
contacts: [...contacts.values()],
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
queryContacts(): Stream<ContactBook> {
|
|
54
|
+
const subscribedSpaceKeySet = new ComplexSet(PublicKey.hash);
|
|
55
|
+
return new Stream<ContactBook>(({ next, ctx }) => {
|
|
56
|
+
const pushUpdateTask = new UpdateScheduler(
|
|
57
|
+
ctx,
|
|
58
|
+
async () => {
|
|
59
|
+
const contacts = await this.getContacts();
|
|
60
|
+
next(contacts);
|
|
61
|
+
},
|
|
62
|
+
{ maxFrequency: 2 },
|
|
63
|
+
);
|
|
64
|
+
scheduleTask(ctx, async () => {
|
|
65
|
+
const subscriptions = new EventSubscriptions();
|
|
66
|
+
ctx.onDispose(() => subscriptions.clear());
|
|
67
|
+
const subscribeToSpaceAndUpdate = () => {
|
|
68
|
+
const oldSetSize = subscribedSpaceKeySet.size;
|
|
69
|
+
for (const space of this._spaceManager.spaces.values()) {
|
|
70
|
+
if (!subscribedSpaceKeySet.has(space.key)) {
|
|
71
|
+
subscriptions.add(space.stateUpdate.on(ctx, () => pushUpdateTask.trigger()));
|
|
72
|
+
subscribedSpaceKeySet.add(space.key);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
if (oldSetSize !== subscribedSpaceKeySet.size) {
|
|
76
|
+
pushUpdateTask.trigger();
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
const unsubscribe = (await this._dataSpaceManagerProvider()).updated.on(ctx, subscribeToSpaceAndUpdate);
|
|
80
|
+
ctx.onDispose(unsubscribe);
|
|
81
|
+
subscribeToSpaceAndUpdate();
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2022 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { type CredentialProcessor, getCredentialAssertion } from '@dxos/credentials';
|
|
6
|
+
import { SpaceId, type PublicKey } from '@dxos/keys';
|
|
7
|
+
import { log } from '@dxos/log';
|
|
8
|
+
import { type Credential } from '@dxos/protocols/proto/dxos/halo/credentials';
|
|
9
|
+
|
|
10
|
+
type DefaultSpaceStateMachineParams = {
|
|
11
|
+
identityKey: PublicKey;
|
|
12
|
+
onUpdate?: () => void;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Processes device invitation credentials.
|
|
17
|
+
*/
|
|
18
|
+
export class DefaultSpaceStateMachine implements CredentialProcessor {
|
|
19
|
+
private _spaceId: SpaceId | undefined;
|
|
20
|
+
|
|
21
|
+
constructor(private readonly _params: DefaultSpaceStateMachineParams) {}
|
|
22
|
+
|
|
23
|
+
public get spaceId(): SpaceId | undefined {
|
|
24
|
+
return this._spaceId;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
async processCredential(credential: Credential) {
|
|
28
|
+
const assertion = getCredentialAssertion(credential);
|
|
29
|
+
switch (assertion['@type']) {
|
|
30
|
+
case 'dxos.halo.credentials.DefaultSpace': {
|
|
31
|
+
if (!credential.subject.id.equals(this._params.identityKey)) {
|
|
32
|
+
log.warn('Invalid default space credential', { expectedIdentity: this._params.identityKey, credential });
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
if (!SpaceId.isValid(assertion.spaceId)) {
|
|
36
|
+
log.warn('Invalid default space id', { id: assertion.spaceId });
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
this._spaceId = assertion.spaceId;
|
|
40
|
+
break;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -24,11 +24,7 @@ describe('IdentityService', () => {
|
|
|
24
24
|
beforeEach(async () => {
|
|
25
25
|
serviceContext = await createServiceContext();
|
|
26
26
|
await serviceContext.open(new Context());
|
|
27
|
-
identityService =
|
|
28
|
-
(options) => serviceContext.createIdentity(options),
|
|
29
|
-
serviceContext.identityManager,
|
|
30
|
-
serviceContext.keyring,
|
|
31
|
-
);
|
|
27
|
+
identityService = createIdentityService(serviceContext);
|
|
32
28
|
});
|
|
33
29
|
|
|
34
30
|
afterEach(async () => {
|
|
@@ -95,3 +91,37 @@ describe('IdentityService', () => {
|
|
|
95
91
|
});
|
|
96
92
|
});
|
|
97
93
|
});
|
|
94
|
+
|
|
95
|
+
describe('open', () => {
|
|
96
|
+
test('identity without default space fixed', async () => {
|
|
97
|
+
const serviceContext = await createServiceContext();
|
|
98
|
+
await serviceContext.open(new Context());
|
|
99
|
+
const identity = await serviceContext.createIdentity();
|
|
100
|
+
const identityService = createIdentityService(serviceContext);
|
|
101
|
+
const getDataSpaces = () => [...(serviceContext.dataSpaceManager?.spaces?.values() ?? [])];
|
|
102
|
+
expect(getDataSpaces().length).to.eq(0);
|
|
103
|
+
expect(identity.defaultSpaceId).to.be.undefined;
|
|
104
|
+
await identityService.open();
|
|
105
|
+
expect(getDataSpaces()[0].id === identity.defaultSpaceId).to.be.true;
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
test('identity without default space credential fixed', async () => {
|
|
109
|
+
const serviceContext = await createServiceContext();
|
|
110
|
+
await serviceContext.open(new Context());
|
|
111
|
+
const identity = await serviceContext.createIdentity();
|
|
112
|
+
const space = await serviceContext.dataSpaceManager!.createDefaultSpace();
|
|
113
|
+
const identityService = createIdentityService(serviceContext);
|
|
114
|
+
expect(identity.defaultSpaceId).to.be.undefined;
|
|
115
|
+
await identityService.open();
|
|
116
|
+
expect(identity.defaultSpaceId === space.id).to.be.true;
|
|
117
|
+
});
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
const createIdentityService = (serviceContext: ServiceContext) => {
|
|
121
|
+
return new IdentityServiceImpl(
|
|
122
|
+
serviceContext.identityManager,
|
|
123
|
+
serviceContext.keyring,
|
|
124
|
+
() => serviceContext.dataSpaceManager!,
|
|
125
|
+
(options) => serviceContext.createIdentity(options),
|
|
126
|
+
);
|
|
127
|
+
};
|
|
@@ -2,37 +2,65 @@
|
|
|
2
2
|
// Copyright 2023 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
+
import { Trigger, sleep } from '@dxos/async';
|
|
5
6
|
import { Stream } from '@dxos/codec-protobuf';
|
|
7
|
+
import { Resource } from '@dxos/context';
|
|
6
8
|
import { signPresentation } from '@dxos/credentials';
|
|
7
9
|
import { todo } from '@dxos/debug';
|
|
8
10
|
import { invariant } from '@dxos/invariant';
|
|
9
11
|
import { type Keyring } from '@dxos/keyring';
|
|
12
|
+
import { log } from '@dxos/log';
|
|
10
13
|
import {
|
|
11
14
|
type CreateIdentityRequest,
|
|
12
|
-
type Identity,
|
|
15
|
+
type Identity as IdentityProto,
|
|
13
16
|
type IdentityService,
|
|
14
17
|
type QueryIdentityResponse,
|
|
15
18
|
type RecoverIdentityRequest,
|
|
16
19
|
type SignPresentationRequest,
|
|
20
|
+
SpaceState,
|
|
17
21
|
} from '@dxos/protocols/proto/dxos/client/services';
|
|
18
22
|
import { type Presentation, type ProfileDocument } from '@dxos/protocols/proto/dxos/halo/credentials';
|
|
23
|
+
import { safeAwaitAll } from '@dxos/util';
|
|
19
24
|
|
|
25
|
+
import { type Identity } from './identity';
|
|
20
26
|
import { type CreateIdentityOptions, type IdentityManager } from './identity-manager';
|
|
27
|
+
import { type DataSpaceManager } from '../spaces';
|
|
21
28
|
|
|
22
|
-
|
|
29
|
+
const DEFAULT_SPACE_SEARCH_TIMEOUT = 10_000;
|
|
30
|
+
|
|
31
|
+
export class IdentityServiceImpl extends Resource implements IdentityService {
|
|
23
32
|
constructor(
|
|
24
|
-
private readonly _createIdentity: (params: CreateIdentityOptions) => Promise<Identity>,
|
|
25
33
|
private readonly _identityManager: IdentityManager,
|
|
26
34
|
private readonly _keyring: Keyring,
|
|
35
|
+
private readonly _dataSpaceManagerProvider: () => DataSpaceManager,
|
|
36
|
+
private readonly _createIdentity: (params: CreateIdentityOptions) => Promise<Identity>,
|
|
27
37
|
private readonly _onProfileUpdate?: (profile: ProfileDocument | undefined) => Promise<void>,
|
|
28
|
-
) {
|
|
38
|
+
) {
|
|
39
|
+
super();
|
|
40
|
+
}
|
|
29
41
|
|
|
30
|
-
async
|
|
42
|
+
protected override async _open() {
|
|
43
|
+
const identity = this._identityManager.identity;
|
|
44
|
+
if (identity && !identity.defaultSpaceId) {
|
|
45
|
+
await this._fixIdentityWithoutDefaultSpace(identity);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
async createIdentity(request: CreateIdentityRequest): Promise<IdentityProto> {
|
|
31
50
|
await this._createIdentity({ displayName: request.profile?.displayName, deviceProfile: request.deviceProfile });
|
|
51
|
+
const dataSpaceManager = this._dataSpaceManagerProvider();
|
|
52
|
+
await this._createDefaultSpace(dataSpaceManager);
|
|
32
53
|
return this._getIdentity()!;
|
|
33
54
|
}
|
|
34
55
|
|
|
35
|
-
async
|
|
56
|
+
private async _createDefaultSpace(dataSpaceManager: DataSpaceManager) {
|
|
57
|
+
const space = await dataSpaceManager!.createDefaultSpace();
|
|
58
|
+
const identity = this._identityManager.identity;
|
|
59
|
+
invariant(identity);
|
|
60
|
+
await identity.updateDefaultSpace(space.id);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
async recoverIdentity(request: RecoverIdentityRequest): Promise<IdentityProto> {
|
|
36
64
|
return todo();
|
|
37
65
|
}
|
|
38
66
|
|
|
@@ -45,7 +73,7 @@ export class IdentityServiceImpl implements IdentityService {
|
|
|
45
73
|
});
|
|
46
74
|
}
|
|
47
75
|
|
|
48
|
-
private _getIdentity():
|
|
76
|
+
private _getIdentity(): IdentityProto | undefined {
|
|
49
77
|
if (!this._identityManager.identity) {
|
|
50
78
|
return undefined;
|
|
51
79
|
}
|
|
@@ -57,7 +85,7 @@ export class IdentityServiceImpl implements IdentityService {
|
|
|
57
85
|
};
|
|
58
86
|
}
|
|
59
87
|
|
|
60
|
-
async updateProfile(profile: ProfileDocument): Promise<
|
|
88
|
+
async updateProfile(profile: ProfileDocument): Promise<IdentityProto> {
|
|
61
89
|
invariant(this._identityManager.identity, 'Identity not initialized.');
|
|
62
90
|
await this._identityManager.updateProfile(profile);
|
|
63
91
|
await this._onProfileUpdate?.(this._identityManager.identity.profileDocument);
|
|
@@ -75,4 +103,50 @@ export class IdentityServiceImpl implements IdentityService {
|
|
|
75
103
|
nonce,
|
|
76
104
|
});
|
|
77
105
|
}
|
|
106
|
+
|
|
107
|
+
private async _fixIdentityWithoutDefaultSpace(identity: Identity) {
|
|
108
|
+
let recodedDefaultSpace = false;
|
|
109
|
+
let foundDefaultSpace = false;
|
|
110
|
+
const dataSpaceManager = this._dataSpaceManagerProvider();
|
|
111
|
+
|
|
112
|
+
const recordedDefaultSpaceTrigger = new Trigger();
|
|
113
|
+
|
|
114
|
+
const allProcessed = safeAwaitAll(
|
|
115
|
+
dataSpaceManager.spaces.values(),
|
|
116
|
+
async (space) => {
|
|
117
|
+
if (space.state === SpaceState.CLOSED) {
|
|
118
|
+
await space.open();
|
|
119
|
+
|
|
120
|
+
// Wait until the space is either READY or REQUIRES_MIGRATION.
|
|
121
|
+
// NOTE: Space could potentially never initialize if the space data is corrupted.
|
|
122
|
+
const requiresMigration = space.stateUpdate.waitForCondition(
|
|
123
|
+
() => space.state === SpaceState.REQUIRES_MIGRATION,
|
|
124
|
+
);
|
|
125
|
+
await Promise.race([space.initializeDataPipeline(), requiresMigration]);
|
|
126
|
+
}
|
|
127
|
+
if (await dataSpaceManager.isDefaultSpace(space)) {
|
|
128
|
+
if (foundDefaultSpace) {
|
|
129
|
+
log.warn('Multiple default spaces found. Using the first one.', { duplicate: space.id });
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
foundDefaultSpace = true;
|
|
134
|
+
await identity.updateDefaultSpace(space.id);
|
|
135
|
+
recodedDefaultSpace = true;
|
|
136
|
+
recordedDefaultSpaceTrigger.wake();
|
|
137
|
+
}
|
|
138
|
+
},
|
|
139
|
+
(err) => {
|
|
140
|
+
log.catch(err);
|
|
141
|
+
},
|
|
142
|
+
);
|
|
143
|
+
|
|
144
|
+
// Wait for all spaces to be processed or until the default space is recorded.
|
|
145
|
+
// If the timeout is reached, create a new default space.
|
|
146
|
+
await Promise.race([allProcessed, recordedDefaultSpaceTrigger.wait(), sleep(DEFAULT_SPACE_SEARCH_TIMEOUT)]);
|
|
147
|
+
|
|
148
|
+
if (!recodedDefaultSpace) {
|
|
149
|
+
await this._createDefaultSpace(dataSpaceManager);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
78
152
|
}
|