@dxos/client-services 0.3.9-main.f27ec14 → 0.3.9-next.4584ca9
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-RXLILE6E.mjs → chunk-JY4EWWY6.mjs} +128 -65
- package/dist/lib/browser/chunk-JY4EWWY6.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +1 -1
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/packlets/testing/index.mjs +7 -3
- package/dist/lib/browser/packlets/testing/index.mjs.map +3 -3
- package/dist/lib/node/{chunk-U3CT7ITF.cjs → chunk-7MMXK6YU.cjs} +129 -77
- package/dist/lib/node/chunk-7MMXK6YU.cjs.map +7 -0
- package/dist/lib/node/index.cjs +37 -37
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/packlets/testing/index.cjs +11 -8
- package/dist/lib/node/packlets/testing/index.cjs.map +3 -3
- package/dist/types/src/packlets/services/automerge-host.test.d.ts +2 -0
- package/dist/types/src/packlets/services/automerge-host.test.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-host.d.ts.map +1 -1
- package/dist/types/src/packlets/spaces/automerge-space-state.d.ts +8 -0
- package/dist/types/src/packlets/spaces/automerge-space-state.d.ts.map +1 -0
- package/dist/types/src/packlets/spaces/data-space-manager.d.ts +3 -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 +7 -2
- package/dist/types/src/packlets/spaces/data-space.d.ts.map +1 -1
- package/dist/types/src/packlets/spaces/genesis.d.ts +1 -1
- package/dist/types/src/packlets/spaces/genesis.d.ts.map +1 -1
- package/dist/types/src/packlets/testing/test-builder.d.ts +3 -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 -35
- package/src/packlets/services/automerge-host.test.ts +56 -0
- package/src/packlets/services/service-context.ts +6 -0
- package/src/packlets/services/service-host.ts +5 -2
- package/src/packlets/spaces/automerge-space-state.ts +22 -0
- package/src/packlets/spaces/data-space-manager.ts +12 -2
- package/src/packlets/spaces/data-space.ts +52 -6
- package/src/packlets/spaces/genesis.ts +7 -1
- package/src/packlets/testing/test-builder.ts +7 -0
- package/src/version.ts +1 -1
- package/dist/lib/browser/chunk-RXLILE6E.mjs.map +0 -7
- package/dist/lib/node/chunk-U3CT7ITF.cjs.map +0 -7
|
@@ -282,7 +282,10 @@ export class ClientServicesHost {
|
|
|
282
282
|
},
|
|
283
283
|
),
|
|
284
284
|
|
|
285
|
-
DataService: new DataServiceImpl(
|
|
285
|
+
DataService: new DataServiceImpl(
|
|
286
|
+
this._serviceContext.dataServiceSubscriptions,
|
|
287
|
+
this._serviceContext.automergeHost,
|
|
288
|
+
),
|
|
286
289
|
|
|
287
290
|
NetworkService: new NetworkServiceImpl(this._serviceContext.networkManager, this._serviceContext.signalManager),
|
|
288
291
|
|
|
@@ -354,7 +357,7 @@ export class ClientServicesHost {
|
|
|
354
357
|
// Setup default space.
|
|
355
358
|
await this._serviceContext.initialized.wait();
|
|
356
359
|
const space = await this._serviceContext.dataSpaceManager!.createSpace();
|
|
357
|
-
const obj: TypedObject = new Properties();
|
|
360
|
+
const obj: TypedObject = new Properties(undefined, { useAutomergeBackend: false });
|
|
358
361
|
obj[defaultKey] = identity.identityKey.toHex();
|
|
359
362
|
await this._serviceRegistry.services.DataService!.write({
|
|
360
363
|
spaceKey: space.key,
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2023 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { type CredentialProcessor, type SpecificCredential, checkCredentialType } from '@dxos/credentials';
|
|
6
|
+
import { type Credential, type Epoch } from '@dxos/protocols/proto/dxos/halo/credentials';
|
|
7
|
+
|
|
8
|
+
export class AutomergeSpaceState implements CredentialProcessor {
|
|
9
|
+
public rootUrl: string | undefined = undefined;
|
|
10
|
+
public lastEpoch: SpecificCredential<Epoch> | undefined = undefined;
|
|
11
|
+
|
|
12
|
+
async processCredential(credential: Credential) {
|
|
13
|
+
if (!checkCredentialType(credential, 'dxos.halo.credentials.Epoch')) {
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
this.lastEpoch = credential;
|
|
18
|
+
if (credential.subject.assertion.automergeRoot) {
|
|
19
|
+
this.rootUrl = credential.subject.assertion.automergeRoot;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -5,7 +5,13 @@
|
|
|
5
5
|
import { Event, synchronized, trackLeaks } from '@dxos/async';
|
|
6
6
|
import { cancelWithContext, Context } from '@dxos/context';
|
|
7
7
|
import { type CredentialSigner, getCredentialAssertion } from '@dxos/credentials';
|
|
8
|
-
import {
|
|
8
|
+
import {
|
|
9
|
+
type AutomergeHost,
|
|
10
|
+
type DataServiceSubscriptions,
|
|
11
|
+
type MetadataStore,
|
|
12
|
+
type Space,
|
|
13
|
+
type SpaceManager,
|
|
14
|
+
} from '@dxos/echo-pipeline';
|
|
9
15
|
import { type FeedStore } from '@dxos/feed-store';
|
|
10
16
|
import { invariant } from '@dxos/invariant';
|
|
11
17
|
import { type Keyring } from '@dxos/keyring';
|
|
@@ -71,6 +77,7 @@ export class DataSpaceManager {
|
|
|
71
77
|
private readonly _keyring: Keyring,
|
|
72
78
|
private readonly _signingContext: SigningContext,
|
|
73
79
|
private readonly _feedStore: FeedStore<FeedMessage>,
|
|
80
|
+
private readonly _automergeHost: AutomergeHost,
|
|
74
81
|
) {}
|
|
75
82
|
|
|
76
83
|
// TODO(burdon): Remove.
|
|
@@ -135,7 +142,9 @@ export class DataSpaceManager {
|
|
|
135
142
|
log('creating space...', { spaceKey });
|
|
136
143
|
const space = await this._constructSpace(metadata);
|
|
137
144
|
|
|
138
|
-
const
|
|
145
|
+
const automergeRoot = this._automergeHost.repo.create();
|
|
146
|
+
|
|
147
|
+
const credentials = await spaceGenesis(this._keyring, this._signingContext, space.inner, automergeRoot.url);
|
|
139
148
|
await this._metadataStore.addSpace(metadata);
|
|
140
149
|
|
|
141
150
|
const memberCredential = credentials[1];
|
|
@@ -257,6 +266,7 @@ export class DataSpaceManager {
|
|
|
257
266
|
},
|
|
258
267
|
},
|
|
259
268
|
cache: metadata.cache,
|
|
269
|
+
automergeHost: this._automergeHost,
|
|
260
270
|
});
|
|
261
271
|
|
|
262
272
|
if (metadata.state !== SpaceState.INACTIVE) {
|
|
@@ -6,22 +6,35 @@ import { Event, scheduleTask, sleep, synchronized, trackLeaks } from '@dxos/asyn
|
|
|
6
6
|
import { AUTH_TIMEOUT } from '@dxos/client-protocol';
|
|
7
7
|
import { cancelWithContext, Context } from '@dxos/context';
|
|
8
8
|
import { timed } from '@dxos/debug';
|
|
9
|
-
import {
|
|
9
|
+
import {
|
|
10
|
+
type MetadataStore,
|
|
11
|
+
type Space,
|
|
12
|
+
createMappedFeedWriter,
|
|
13
|
+
type DataPipeline,
|
|
14
|
+
type CreateEpochOptions,
|
|
15
|
+
type AutomergeHost,
|
|
16
|
+
} from '@dxos/echo-pipeline';
|
|
10
17
|
import { type FeedStore } from '@dxos/feed-store';
|
|
11
18
|
import { type Keyring } from '@dxos/keyring';
|
|
12
19
|
import { PublicKey } from '@dxos/keys';
|
|
13
20
|
import { log } from '@dxos/log';
|
|
14
21
|
import { CancelledError, SystemError } from '@dxos/protocols';
|
|
15
|
-
import { SpaceState, type Space as SpaceProto } from '@dxos/protocols/proto/dxos/client/services';
|
|
22
|
+
import { SpaceState, type Space as SpaceProto, CreateEpochRequest } from '@dxos/protocols/proto/dxos/client/services';
|
|
16
23
|
import { type FeedMessage } from '@dxos/protocols/proto/dxos/echo/feed';
|
|
17
24
|
import { type SpaceCache } from '@dxos/protocols/proto/dxos/echo/metadata';
|
|
18
|
-
import {
|
|
25
|
+
import {
|
|
26
|
+
AdmittedFeed,
|
|
27
|
+
type ProfileDocument,
|
|
28
|
+
type Credential,
|
|
29
|
+
type Epoch,
|
|
30
|
+
} from '@dxos/protocols/proto/dxos/halo/credentials';
|
|
19
31
|
import { type GossipMessage } from '@dxos/protocols/proto/dxos/mesh/teleport/gossip';
|
|
20
32
|
import { type Gossip, type Presence } from '@dxos/teleport-extension-gossip';
|
|
21
33
|
import { Timeframe } from '@dxos/timeframe';
|
|
22
34
|
import { trace } from '@dxos/tracing';
|
|
23
35
|
import { ComplexSet } from '@dxos/util';
|
|
24
36
|
|
|
37
|
+
import { AutomergeSpaceState } from './automerge-space-state';
|
|
25
38
|
import { type SigningContext } from './data-space-manager';
|
|
26
39
|
import { NotarizationPlugin } from './notarization-plugin';
|
|
27
40
|
import { TrustedKeySetAuthVerifier } from '../identity';
|
|
@@ -54,6 +67,7 @@ export type DataSpaceParams = {
|
|
|
54
67
|
signingContext: SigningContext;
|
|
55
68
|
callbacks?: DataSpaceCallbacks;
|
|
56
69
|
cache?: SpaceCache;
|
|
70
|
+
automergeHost: AutomergeHost;
|
|
57
71
|
};
|
|
58
72
|
|
|
59
73
|
/**
|
|
@@ -74,7 +88,11 @@ export class DataSpace {
|
|
|
74
88
|
private readonly _signingContext: SigningContext;
|
|
75
89
|
private readonly _notarizationPlugin = new NotarizationPlugin();
|
|
76
90
|
private readonly _callbacks: DataSpaceCallbacks;
|
|
77
|
-
private readonly _cache?: SpaceCache;
|
|
91
|
+
private readonly _cache?: SpaceCache = undefined;
|
|
92
|
+
private readonly _automergeHost: AutomergeHost;
|
|
93
|
+
|
|
94
|
+
// TODO(dmaretskyi): Move into Space?
|
|
95
|
+
private readonly _automergeSpaceState = new AutomergeSpaceState();
|
|
78
96
|
|
|
79
97
|
private _state = SpaceState.CLOSED;
|
|
80
98
|
|
|
@@ -99,6 +117,7 @@ export class DataSpace {
|
|
|
99
117
|
this._metadataStore = params.metadataStore;
|
|
100
118
|
this._signingContext = params.signingContext;
|
|
101
119
|
this._callbacks = params.callbacks ?? {};
|
|
120
|
+
this._automergeHost = params.automergeHost;
|
|
102
121
|
|
|
103
122
|
this.authVerifier = new TrustedKeySetAuthVerifier({
|
|
104
123
|
trustedKeysProvider: () =>
|
|
@@ -151,6 +170,10 @@ export class DataSpace {
|
|
|
151
170
|
return this._cache;
|
|
152
171
|
}
|
|
153
172
|
|
|
173
|
+
get automergeSpaceState() {
|
|
174
|
+
return this._automergeSpaceState;
|
|
175
|
+
}
|
|
176
|
+
|
|
154
177
|
@synchronized
|
|
155
178
|
async open() {
|
|
156
179
|
await this._open();
|
|
@@ -160,6 +183,7 @@ export class DataSpace {
|
|
|
160
183
|
await this._gossip.open();
|
|
161
184
|
await this._notarizationPlugin.open();
|
|
162
185
|
await this._inner.spaceState.addCredentialProcessor(this._notarizationPlugin);
|
|
186
|
+
await this._inner.spaceState.addCredentialProcessor(this._automergeSpaceState);
|
|
163
187
|
await this._inner.open(new Context());
|
|
164
188
|
this._state = SpaceState.CONTROL_ONLY;
|
|
165
189
|
log('new state', { state: SpaceState[this._state] });
|
|
@@ -183,6 +207,7 @@ export class DataSpace {
|
|
|
183
207
|
await this.authVerifier.close();
|
|
184
208
|
|
|
185
209
|
await this._inner.close();
|
|
210
|
+
await this._inner.spaceState.removeCredentialProcessor(this._automergeSpaceState);
|
|
186
211
|
await this._inner.spaceState.removeCredentialProcessor(this._notarizationPlugin);
|
|
187
212
|
await this._notarizationPlugin.close();
|
|
188
213
|
|
|
@@ -350,8 +375,29 @@ export class DataSpace {
|
|
|
350
375
|
await this.inner.controlPipeline.writer.write({ credential: { credential } });
|
|
351
376
|
}
|
|
352
377
|
|
|
353
|
-
async createEpoch() {
|
|
354
|
-
|
|
378
|
+
async createEpoch(options?: CreateEpochOptions) {
|
|
379
|
+
let epoch: Epoch | undefined;
|
|
380
|
+
switch (options?.migration) {
|
|
381
|
+
case undefined:
|
|
382
|
+
case CreateEpochRequest.Migration.NONE:
|
|
383
|
+
{
|
|
384
|
+
epoch = await this.dataPipeline.createEpoch();
|
|
385
|
+
}
|
|
386
|
+
break;
|
|
387
|
+
case CreateEpochRequest.Migration.INIT_AUTOMERGE: {
|
|
388
|
+
const document = this._automergeHost.repo.create();
|
|
389
|
+
epoch = {
|
|
390
|
+
previousId: this._automergeSpaceState.lastEpoch?.id,
|
|
391
|
+
number: (this._automergeSpaceState.lastEpoch?.subject.assertion.number ?? -1) + 1,
|
|
392
|
+
timeframe: this._automergeSpaceState.lastEpoch?.subject.assertion.timeframe ?? new Timeframe(),
|
|
393
|
+
automergeRoot: document.url,
|
|
394
|
+
};
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
if (!epoch) {
|
|
399
|
+
return;
|
|
400
|
+
}
|
|
355
401
|
|
|
356
402
|
const receipt = await this.inner.controlPipeline.writer.write({
|
|
357
403
|
credential: {
|
|
@@ -11,7 +11,12 @@ import { Timeframe } from '@dxos/timeframe';
|
|
|
11
11
|
|
|
12
12
|
import { type SigningContext } from './data-space-manager';
|
|
13
13
|
|
|
14
|
-
export const spaceGenesis = async (
|
|
14
|
+
export const spaceGenesis = async (
|
|
15
|
+
keyring: Keyring,
|
|
16
|
+
signingContext: SigningContext,
|
|
17
|
+
space: Space,
|
|
18
|
+
automergeRoot?: string,
|
|
19
|
+
) => {
|
|
15
20
|
// TODO(dmaretskyi): Find a way to reconcile with credential generator.
|
|
16
21
|
const credentials = [
|
|
17
22
|
await createCredential({
|
|
@@ -67,6 +72,7 @@ export const spaceGenesis = async (keyring: Keyring, signingContext: SigningCont
|
|
|
67
72
|
previousId: undefined,
|
|
68
73
|
timeframe: new Timeframe(),
|
|
69
74
|
snapshotCid: undefined,
|
|
75
|
+
automergeRoot,
|
|
70
76
|
},
|
|
71
77
|
}),
|
|
72
78
|
];
|
|
@@ -13,6 +13,7 @@ import {
|
|
|
13
13
|
SpaceManager,
|
|
14
14
|
valueEncoding,
|
|
15
15
|
DataServiceSubscriptions,
|
|
16
|
+
AutomergeHost,
|
|
16
17
|
} from '@dxos/echo-pipeline';
|
|
17
18
|
import { testLocalDatabase } from '@dxos/echo-pipeline/testing';
|
|
18
19
|
import { FeedFactory, FeedStore } from '@dxos/feed-store';
|
|
@@ -108,6 +109,7 @@ export type TestPeerProps = {
|
|
|
108
109
|
snapshotStore?: SnapshotStore;
|
|
109
110
|
signingContext?: SigningContext;
|
|
110
111
|
blobStore?: BlobStore;
|
|
112
|
+
automergeHost?: AutomergeHost;
|
|
111
113
|
};
|
|
112
114
|
|
|
113
115
|
export class TestPeer {
|
|
@@ -176,6 +178,10 @@ export class TestPeer {
|
|
|
176
178
|
return this._props.signingContext ?? failUndefined();
|
|
177
179
|
}
|
|
178
180
|
|
|
181
|
+
get automergeHost() {
|
|
182
|
+
return (this._props.automergeHost ??= new AutomergeHost(this.storage.createDirectory('automerge')));
|
|
183
|
+
}
|
|
184
|
+
|
|
179
185
|
get dataSpaceManager() {
|
|
180
186
|
return (this._props.dataSpaceManager ??= new DataSpaceManager(
|
|
181
187
|
this.spaceManager,
|
|
@@ -184,6 +190,7 @@ export class TestPeer {
|
|
|
184
190
|
this.keyring,
|
|
185
191
|
this.identity,
|
|
186
192
|
this.feedStore,
|
|
193
|
+
this.automergeHost,
|
|
187
194
|
));
|
|
188
195
|
}
|
|
189
196
|
|
package/src/version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const DXOS_VERSION = "0.3.9-
|
|
1
|
+
export const DXOS_VERSION = "0.3.9-next.4584ca9";
|