@dxos/echo-pipeline 0.4.8-next.fff1521 → 0.4.9-main.1057b49
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-3FVT6KX6.mjs → chunk-RTEEJ723.mjs} +289 -1807
- package/dist/lib/browser/chunk-RTEEJ723.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +633 -14
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +4 -332
- package/dist/lib/browser/testing/index.mjs.map +4 -4
- package/dist/lib/node/chunk-7VZVCCNF.cjs +1948 -0
- package/dist/lib/node/chunk-7VZVCCNF.cjs.map +7 -0
- package/dist/lib/node/index.cjs +643 -34
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/testing/index.cjs +13 -338
- package/dist/lib/node/testing/index.cjs.map +4 -4
- package/dist/types/src/db-host/data-service.d.ts +3 -13
- package/dist/types/src/db-host/data-service.d.ts.map +1 -1
- package/dist/types/src/db-host/index.d.ts +0 -2
- package/dist/types/src/db-host/index.d.ts.map +1 -1
- package/dist/types/src/space/control-pipeline.d.ts.map +1 -1
- package/dist/types/src/space/index.d.ts +0 -1
- package/dist/types/src/space/index.d.ts.map +1 -1
- package/dist/types/src/space/space-manager.d.ts +1 -4
- package/dist/types/src/space/space-manager.d.ts.map +1 -1
- package/dist/types/src/space/space.d.ts +1 -7
- package/dist/types/src/space/space.d.ts.map +1 -1
- package/dist/types/src/testing/index.d.ts +0 -2
- package/dist/types/src/testing/index.d.ts.map +1 -1
- package/dist/types/src/testing/test-agent-builder.d.ts +1 -3
- package/dist/types/src/testing/test-agent-builder.d.ts.map +1 -1
- package/package.json +30 -33
- package/src/automerge/automerge-host.ts +1 -1
- package/src/db-host/data-service.ts +10 -56
- package/src/db-host/index.ts +0 -2
- package/src/space/control-pipeline.ts +3 -1
- package/src/space/index.ts +0 -1
- package/src/space/space-manager.ts +1 -13
- package/src/space/space.test.ts +2 -112
- package/src/space/space.ts +2 -60
- package/src/testing/index.ts +0 -2
- package/src/testing/test-agent-builder.ts +3 -8
- package/dist/lib/browser/chunk-3FVT6KX6.mjs.map +0 -7
- package/dist/lib/node/chunk-WZ4WTAN6.cjs +0 -3454
- package/dist/lib/node/chunk-WZ4WTAN6.cjs.map +0 -7
- package/dist/types/src/db-host/data-service-host.d.ts +0 -38
- package/dist/types/src/db-host/data-service-host.d.ts.map +0 -1
- package/dist/types/src/db-host/database-host.d.ts +0 -27
- package/dist/types/src/db-host/database-host.d.ts.map +0 -1
- package/dist/types/src/space/data-pipeline.d.ts +0 -80
- package/dist/types/src/space/data-pipeline.d.ts.map +0 -1
- package/dist/types/src/space/data-pipeline.test.d.ts +0 -1
- package/dist/types/src/space/data-pipeline.test.d.ts.map +0 -1
- package/dist/types/src/testing/database-test-rig.d.ts +0 -67
- package/dist/types/src/testing/database-test-rig.d.ts.map +0 -1
- package/dist/types/src/testing/util.d.ts +0 -14
- package/dist/types/src/testing/util.d.ts.map +0 -1
- package/dist/types/src/tests/database.test.d.ts +0 -2
- package/dist/types/src/tests/database.test.d.ts.map +0 -1
- package/src/db-host/data-service-host.ts +0 -233
- package/src/db-host/database-host.ts +0 -63
- package/src/space/data-pipeline.test.ts +0 -3
- package/src/space/data-pipeline.ts +0 -468
- package/src/testing/database-test-rig.ts +0 -289
- package/src/testing/util.ts +0 -85
- package/src/tests/database.test.ts +0 -100
|
@@ -18,28 +18,21 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
19
|
var testing_exports = {};
|
|
20
20
|
__export(testing_exports, {
|
|
21
|
-
DatabaseTestBuilder: () => DatabaseTestBuilder,
|
|
22
|
-
DatabaseTestPeer: () => DatabaseTestPeer,
|
|
23
21
|
MemoryNetworkManagerProvider: () => MemoryNetworkManagerProvider,
|
|
24
22
|
TestAgent: () => TestAgent,
|
|
25
23
|
TestAgentBuilder: () => TestAgentBuilder,
|
|
26
24
|
TestFeedBuilder: () => TestFeedBuilder,
|
|
27
25
|
WebsocketNetworkManagerProvider: () => WebsocketNetworkManagerProvider,
|
|
28
|
-
changeStorageVersionInMetadata: () => changeStorageVersionInMetadata
|
|
29
|
-
createMemoryDatabase: () => createMemoryDatabase,
|
|
30
|
-
createRemoteDatabaseFromDataServiceHost: () => createRemoteDatabaseFromDataServiceHost,
|
|
31
|
-
testLocalDatabase: () => testLocalDatabase
|
|
26
|
+
changeStorageVersionInMetadata: () => changeStorageVersionInMetadata
|
|
32
27
|
});
|
|
33
28
|
module.exports = __toCommonJS(testing_exports);
|
|
34
|
-
var
|
|
29
|
+
var import_chunk_7VZVCCNF = require("../chunk-7VZVCCNF.cjs");
|
|
35
30
|
var import_log = require("@dxos/log");
|
|
36
31
|
var import_protocols = require("@dxos/protocols");
|
|
37
32
|
var import_context = require("@dxos/context");
|
|
38
33
|
var import_credentials = require("@dxos/credentials");
|
|
39
|
-
var import_document_model = require("@dxos/document-model");
|
|
40
34
|
var import_keys = require("@dxos/keys");
|
|
41
35
|
var import_messaging = require("@dxos/messaging");
|
|
42
|
-
var import_model_factory = require("@dxos/model-factory");
|
|
43
36
|
var import_network_manager = require("@dxos/network-manager");
|
|
44
37
|
var import_credentials2 = require("@dxos/protocols/proto/dxos/halo/credentials");
|
|
45
38
|
var import_random_access_storage = require("@dxos/random-access-storage");
|
|
@@ -47,24 +40,6 @@ var import_teleport_extension_gossip = require("@dxos/teleport-extension-gossip"
|
|
|
47
40
|
var import_teleport_extension_object_sync = require("@dxos/teleport-extension-object-sync");
|
|
48
41
|
var import_util = require("@dxos/util");
|
|
49
42
|
var import_testing = require("@dxos/feed-store/testing");
|
|
50
|
-
var import_async = require("@dxos/async");
|
|
51
|
-
var import_document_model2 = require("@dxos/document-model");
|
|
52
|
-
var import_echo_db = require("@dxos/echo-db");
|
|
53
|
-
var import_testing2 = require("@dxos/feed-store/testing");
|
|
54
|
-
var import_keys2 = require("@dxos/keys");
|
|
55
|
-
var import_model_factory2 = require("@dxos/model-factory");
|
|
56
|
-
var import_random_access_storage2 = require("@dxos/random-access-storage");
|
|
57
|
-
var import_timeframe = require("@dxos/timeframe");
|
|
58
|
-
var import_async2 = require("@dxos/async");
|
|
59
|
-
var import_document_model3 = require("@dxos/document-model");
|
|
60
|
-
var import_echo_db2 = require("@dxos/echo-db");
|
|
61
|
-
var import_invariant = require("@dxos/invariant");
|
|
62
|
-
var import_keys3 = require("@dxos/keys");
|
|
63
|
-
var import_model_factory3 = require("@dxos/model-factory");
|
|
64
|
-
var import_protocols2 = require("@dxos/protocols");
|
|
65
|
-
var import_text_model = require("@dxos/text-model");
|
|
66
|
-
var import_timeframe2 = require("@dxos/timeframe");
|
|
67
|
-
var import_util2 = require("@dxos/util");
|
|
68
43
|
var __dxlog_file = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/testing/change-metadata.ts";
|
|
69
44
|
var EchoMetadata = import_protocols.schema.getCodecForType("dxos.echo.metadata.EchoMetadata");
|
|
70
45
|
var changeStorageVersionInMetadata = async (storage, version) => {
|
|
@@ -74,7 +49,7 @@ var changeStorageVersionInMetadata = async (storage, version) => {
|
|
|
74
49
|
S: void 0,
|
|
75
50
|
C: (f, a) => f(...a)
|
|
76
51
|
});
|
|
77
|
-
const metadata = new
|
|
52
|
+
const metadata = new import_chunk_7VZVCCNF.MetadataStore(storage.createDirectory("metadata"));
|
|
78
53
|
await metadata.load();
|
|
79
54
|
const echoMetadata = metadata.metadata;
|
|
80
55
|
echoMetadata.version = version;
|
|
@@ -85,7 +60,7 @@ var changeStorageVersionInMetadata = async (storage, version) => {
|
|
|
85
60
|
var TestFeedBuilder = class extends import_testing.TestBuilder {
|
|
86
61
|
constructor() {
|
|
87
62
|
super({
|
|
88
|
-
valueEncoding:
|
|
63
|
+
valueEncoding: import_chunk_7VZVCCNF.valueEncoding
|
|
89
64
|
});
|
|
90
65
|
}
|
|
91
66
|
};
|
|
@@ -129,10 +104,10 @@ var TestAgentBuilder = class {
|
|
|
129
104
|
};
|
|
130
105
|
var TestAgent = class {
|
|
131
106
|
get metadataStore() {
|
|
132
|
-
return this._metadataStore ??= new
|
|
107
|
+
return this._metadataStore ??= new import_chunk_7VZVCCNF.MetadataStore(this.storage.createDirectory("metadata"));
|
|
133
108
|
}
|
|
134
109
|
get snapshotStore() {
|
|
135
|
-
return this._snapshotStore ??= new
|
|
110
|
+
return this._snapshotStore ??= new import_chunk_7VZVCCNF.SnapshotStore(this.storage.createDirectory("snapshots"));
|
|
136
111
|
}
|
|
137
112
|
get blobStore() {
|
|
138
113
|
return this._blobStore ??= new import_teleport_extension_object_sync.BlobStore(this.storage.createDirectory("blobs"));
|
|
@@ -143,7 +118,6 @@ var TestAgent = class {
|
|
|
143
118
|
this.identityKey = identityKey;
|
|
144
119
|
this.deviceKey = deviceKey;
|
|
145
120
|
this._spaces = new import_util.ComplexMap(import_keys.PublicKey.hash);
|
|
146
|
-
this.modelFactory = new import_model_factory.ModelFactory().registerModel(import_document_model.DocumentModel);
|
|
147
121
|
this.storage = this._feedBuilder.storage;
|
|
148
122
|
this.keyring = this._feedBuilder.keyring;
|
|
149
123
|
this.feedStore = this._feedBuilder.createFeedStore();
|
|
@@ -160,10 +134,9 @@ var TestAgent = class {
|
|
|
160
134
|
return this._spaces.get(spaceKey);
|
|
161
135
|
}
|
|
162
136
|
get spaceManager() {
|
|
163
|
-
return this._spaceManager ??= new
|
|
137
|
+
return this._spaceManager ??= new import_chunk_7VZVCCNF.SpaceManager({
|
|
164
138
|
feedStore: this.feedStore,
|
|
165
139
|
networkManager: this._networkManagerProvider(),
|
|
166
|
-
modelFactory: this.modelFactory,
|
|
167
140
|
metadataStore: this.metadataStore,
|
|
168
141
|
snapshotStore: this.snapshotStore,
|
|
169
142
|
blobStore: this.blobStore
|
|
@@ -198,8 +171,8 @@ var TestAgent = class {
|
|
|
198
171
|
metadata,
|
|
199
172
|
swarmIdentity: {
|
|
200
173
|
peerKey: this.deviceKey,
|
|
201
|
-
credentialProvider:
|
|
202
|
-
credentialAuthenticator:
|
|
174
|
+
credentialProvider: import_chunk_7VZVCCNF.MOCK_AUTH_PROVIDER,
|
|
175
|
+
credentialAuthenticator: import_chunk_7VZVCCNF.MOCK_AUTH_VERIFIER
|
|
203
176
|
},
|
|
204
177
|
memberKey: identityKey,
|
|
205
178
|
onAuthorizedConnection: (session) => {
|
|
@@ -215,12 +188,12 @@ var TestAgent = class {
|
|
|
215
188
|
return space;
|
|
216
189
|
}
|
|
217
190
|
createSpaceProtocol(topic, gossip) {
|
|
218
|
-
return new
|
|
191
|
+
return new import_chunk_7VZVCCNF.SpaceProtocol({
|
|
219
192
|
topic,
|
|
220
193
|
swarmIdentity: {
|
|
221
194
|
peerKey: this.deviceKey,
|
|
222
|
-
credentialProvider:
|
|
223
|
-
credentialAuthenticator:
|
|
195
|
+
credentialProvider: import_chunk_7VZVCCNF.MOCK_AUTH_PROVIDER,
|
|
196
|
+
credentialAuthenticator: import_chunk_7VZVCCNF.MOCK_AUTH_VERIFIER
|
|
224
197
|
},
|
|
225
198
|
networkManager: this._networkManagerProvider(),
|
|
226
199
|
blobStore: this.blobStore,
|
|
@@ -260,311 +233,13 @@ var TestAgent = class {
|
|
|
260
233
|
}
|
|
261
234
|
}
|
|
262
235
|
};
|
|
263
|
-
var createMemoryDatabase = async (modelFactory) => {
|
|
264
|
-
const feed = new import_testing2.MockFeedWriter();
|
|
265
|
-
const backend = new import_chunk_WZ4WTAN6.DatabaseHost(feed, async () => {
|
|
266
|
-
});
|
|
267
|
-
feed.written.on(([data, meta]) => backend.echoProcessor({
|
|
268
|
-
batch: data.batch,
|
|
269
|
-
meta: {
|
|
270
|
-
...meta,
|
|
271
|
-
memberKey: import_keys2.PublicKey.random(),
|
|
272
|
-
timeframe: new import_timeframe.Timeframe([
|
|
273
|
-
[
|
|
274
|
-
meta.feedKey,
|
|
275
|
-
meta.seq
|
|
276
|
-
]
|
|
277
|
-
])
|
|
278
|
-
}
|
|
279
|
-
}));
|
|
280
|
-
const itemManager = new import_echo_db.ItemManager(modelFactory);
|
|
281
|
-
await backend.open(itemManager, new import_model_factory2.ModelFactory().registerModel(import_document_model2.DocumentModel));
|
|
282
|
-
return {
|
|
283
|
-
backend,
|
|
284
|
-
itemManager
|
|
285
|
-
};
|
|
286
|
-
};
|
|
287
|
-
var createRemoteDatabaseFromDataServiceHost = async (modelFactory, dataServiceHost) => {
|
|
288
|
-
const dataServiceSubscriptions = new import_chunk_WZ4WTAN6.DataServiceSubscriptions();
|
|
289
|
-
const automergeHost = new import_chunk_WZ4WTAN6.AutomergeHost({
|
|
290
|
-
directory: (0, import_random_access_storage2.createStorage)({
|
|
291
|
-
type: import_random_access_storage2.StorageType.RAM
|
|
292
|
-
}).createDirectory()
|
|
293
|
-
});
|
|
294
|
-
const dataService = new import_chunk_WZ4WTAN6.DataServiceImpl(dataServiceSubscriptions, automergeHost);
|
|
295
|
-
const spaceKey = import_keys2.PublicKey.random();
|
|
296
|
-
await dataServiceSubscriptions.registerSpace(spaceKey, dataServiceHost);
|
|
297
|
-
const itemManager = new import_echo_db.ItemManager(modelFactory);
|
|
298
|
-
const backend = new import_echo_db.DatabaseProxy({
|
|
299
|
-
service: dataService,
|
|
300
|
-
itemManager,
|
|
301
|
-
spaceKey
|
|
302
|
-
});
|
|
303
|
-
await backend.open(new import_model_factory2.ModelFactory().registerModel(import_document_model2.DocumentModel));
|
|
304
|
-
return {
|
|
305
|
-
itemManager,
|
|
306
|
-
backend
|
|
307
|
-
};
|
|
308
|
-
};
|
|
309
|
-
var testLocalDatabase = async (create, check = create) => {
|
|
310
|
-
const objectId = import_keys2.PublicKey.random().toHex();
|
|
311
|
-
await create.databaseHost.getWriteStream()?.write({
|
|
312
|
-
batch: {
|
|
313
|
-
objects: [
|
|
314
|
-
{
|
|
315
|
-
objectId,
|
|
316
|
-
genesis: {
|
|
317
|
-
modelType: import_document_model2.DocumentModel.meta.type
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
]
|
|
321
|
-
}
|
|
322
|
-
});
|
|
323
|
-
await (0, import_async.asyncTimeout)(check.databaseHost._itemDemuxer.mutation.waitForCondition(() => check.itemManager.entities.has(objectId)), 2e3);
|
|
324
|
-
};
|
|
325
|
-
var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/testing/database-test-rig.ts";
|
|
326
|
-
var SPACE_KEY = import_keys3.PublicKey.random();
|
|
327
|
-
var DatabaseTestBuilder = class {
|
|
328
|
-
constructor() {
|
|
329
|
-
this.peers = new import_util2.ComplexMap(import_keys3.PublicKey.hash);
|
|
330
|
-
}
|
|
331
|
-
async createPeer(spaceKey = SPACE_KEY) {
|
|
332
|
-
const peer = new DatabaseTestPeer(this, spaceKey);
|
|
333
|
-
this.peers.set(peer.key, peer);
|
|
334
|
-
await peer.open();
|
|
335
|
-
return peer;
|
|
336
|
-
}
|
|
337
|
-
};
|
|
338
|
-
var DatabaseTestPeer = class {
|
|
339
|
-
constructor(rig, spaceKey) {
|
|
340
|
-
this.rig = rig;
|
|
341
|
-
this.spaceKey = spaceKey;
|
|
342
|
-
this.modelFactory = new import_model_factory3.ModelFactory().registerModel(import_document_model3.DocumentModel).registerModel(import_text_model.TextModel);
|
|
343
|
-
this.key = import_keys3.PublicKey.random();
|
|
344
|
-
this.feedMessages = [];
|
|
345
|
-
this.snapshots = /* @__PURE__ */ new Map();
|
|
346
|
-
this.confirmed = -1;
|
|
347
|
-
this.timeframe = new import_timeframe2.Timeframe();
|
|
348
|
-
this._onConfirm = new import_async2.Event();
|
|
349
|
-
this._writes = /* @__PURE__ */ new Set();
|
|
350
|
-
}
|
|
351
|
-
async open() {
|
|
352
|
-
this.hostItems = new import_echo_db2.ItemManager(this.modelFactory);
|
|
353
|
-
this.host = new import_chunk_WZ4WTAN6.DatabaseHost({
|
|
354
|
-
write: async (message, { afterWrite }) => {
|
|
355
|
-
const seq = this.feedMessages.push({
|
|
356
|
-
timeframe: this.timeframe,
|
|
357
|
-
payload: {
|
|
358
|
-
data: message
|
|
359
|
-
}
|
|
360
|
-
}) - 1;
|
|
361
|
-
const request = {
|
|
362
|
-
receipt: {
|
|
363
|
-
seq,
|
|
364
|
-
feedKey: this.key
|
|
365
|
-
},
|
|
366
|
-
options: {
|
|
367
|
-
afterWrite
|
|
368
|
-
},
|
|
369
|
-
trigger: new import_async2.Trigger()
|
|
370
|
-
};
|
|
371
|
-
this._writes.add(request);
|
|
372
|
-
await request.trigger.wait();
|
|
373
|
-
return request.receipt;
|
|
374
|
-
}
|
|
375
|
-
}, async () => {
|
|
376
|
-
});
|
|
377
|
-
await this.host.open(this.hostItems, this.modelFactory);
|
|
378
|
-
if (this.snapshot) {
|
|
379
|
-
this.host._itemDemuxer.restoreFromSnapshot(this.snapshot.database);
|
|
380
|
-
}
|
|
381
|
-
this.items = new import_echo_db2.ItemManager(this.modelFactory);
|
|
382
|
-
this.proxy = new import_echo_db2.DatabaseProxy({
|
|
383
|
-
service: this.host.createDataServiceHost({
|
|
384
|
-
deferEvents: false
|
|
385
|
-
}),
|
|
386
|
-
itemManager: this.items,
|
|
387
|
-
spaceKey: this.spaceKey
|
|
388
|
-
});
|
|
389
|
-
await this.proxy.open(this.modelFactory);
|
|
390
|
-
}
|
|
391
|
-
/**
|
|
392
|
-
* Confirm mutations written to the local feed.
|
|
393
|
-
* @param seq Sequence number of the mutation to confirm. If not specified, all mutations will be confirmed.
|
|
394
|
-
*/
|
|
395
|
-
async confirm(seq) {
|
|
396
|
-
this.confirmed = seq ?? this.feedMessages.length - 1;
|
|
397
|
-
this._onConfirm.emit();
|
|
398
|
-
for (const request of [
|
|
399
|
-
...this._writes
|
|
400
|
-
]) {
|
|
401
|
-
if (this.confirmed >= request.receipt.seq) {
|
|
402
|
-
this._writes.delete(request);
|
|
403
|
-
await request.options.afterWrite?.(request.receipt);
|
|
404
|
-
request.trigger.wake();
|
|
405
|
-
}
|
|
406
|
-
}
|
|
407
|
-
this._processMessages(import_timeframe2.Timeframe.merge(this.timeframe, new import_timeframe2.Timeframe([
|
|
408
|
-
[
|
|
409
|
-
this.key,
|
|
410
|
-
this.confirmed
|
|
411
|
-
]
|
|
412
|
-
])));
|
|
413
|
-
}
|
|
414
|
-
/**
|
|
415
|
-
* Replicate the database to the specified timeframe.
|
|
416
|
-
* @param to Timeframe to replicate to. If not specified, the database will be replicated to the latest timeframe (based on all other peers).
|
|
417
|
-
*/
|
|
418
|
-
replicate(to) {
|
|
419
|
-
const toTimeframe = import_timeframe2.Timeframe.merge(to ?? new import_timeframe2.Timeframe(Array.from(this.rig.peers.values()).map((peer) => [
|
|
420
|
-
peer.key,
|
|
421
|
-
peer.confirmed
|
|
422
|
-
])), this.timeframe);
|
|
423
|
-
toTimeframe.set(this.key, this.confirmed);
|
|
424
|
-
this._processMessages(toTimeframe);
|
|
425
|
-
}
|
|
426
|
-
/**
|
|
427
|
-
* Reload data from the feed. Wipes unconfirmed mutations.
|
|
428
|
-
*/
|
|
429
|
-
async reload() {
|
|
430
|
-
await this.open();
|
|
431
|
-
const timeframe = this.timeframe;
|
|
432
|
-
this.timeframe = this.snapshot?.timeframe ?? new import_timeframe2.Timeframe();
|
|
433
|
-
this._processMessages(timeframe);
|
|
434
|
-
}
|
|
435
|
-
/**
|
|
436
|
-
* Create snapshot and use it for the next reload.
|
|
437
|
-
*/
|
|
438
|
-
makeSnapshot() {
|
|
439
|
-
this.snapshot = {
|
|
440
|
-
spaceKey: SPACE_KEY.asUint8Array(),
|
|
441
|
-
database: this.host.createSnapshot(),
|
|
442
|
-
timeframe: this.timeframe
|
|
443
|
-
};
|
|
444
|
-
return this.snapshot;
|
|
445
|
-
}
|
|
446
|
-
createEpoch(mockSnapshot) {
|
|
447
|
-
const snapshot = this.makeSnapshot();
|
|
448
|
-
mockSnapshot && (snapshot.database = mockSnapshot);
|
|
449
|
-
const snapshotCid = import_keys3.PublicKey.from(import_protocols2.schema.getCodecForType("dxos.echo.snapshot.SpaceSnapshot").encode(snapshot)).toHex();
|
|
450
|
-
this.snapshots.set(snapshotCid, snapshot);
|
|
451
|
-
const epoch = {
|
|
452
|
-
previousId: import_keys3.PublicKey.random(),
|
|
453
|
-
timeframe: this.timeframe,
|
|
454
|
-
number: this.currentEpoch ? this.currentEpoch.number + 1 : 0,
|
|
455
|
-
snapshotCid
|
|
456
|
-
};
|
|
457
|
-
this.currentEpoch = epoch;
|
|
458
|
-
this.host._itemDemuxer.restoreFromSnapshot(snapshot.database);
|
|
459
|
-
}
|
|
460
|
-
/**
|
|
461
|
-
* Gets all candidate messages according to the current timeframe.
|
|
462
|
-
* Does not take into account the current snapshot, timeframe dependencies, or the confirmed, or replicated state.
|
|
463
|
-
*/
|
|
464
|
-
_getHeads() {
|
|
465
|
-
return Array.from(this.rig.peers.values()).map((peer) => {
|
|
466
|
-
const seq = this.timeframe.get(peer.key) ?? -1;
|
|
467
|
-
const message = peer.feedMessages[seq + 1];
|
|
468
|
-
return message && {
|
|
469
|
-
feedKey: peer.key,
|
|
470
|
-
seq: seq + 1,
|
|
471
|
-
data: message
|
|
472
|
-
};
|
|
473
|
-
}).filter(import_util2.isNotNullOrUndefined);
|
|
474
|
-
}
|
|
475
|
-
_processMessages(to) {
|
|
476
|
-
let run = true;
|
|
477
|
-
while (run) {
|
|
478
|
-
run = false;
|
|
479
|
-
const heads = this._getHeads();
|
|
480
|
-
for (const candidate of heads) {
|
|
481
|
-
const toSeq = to.get(candidate.feedKey) ?? -1;
|
|
482
|
-
if (toSeq < candidate.seq) {
|
|
483
|
-
continue;
|
|
484
|
-
}
|
|
485
|
-
const snapshotSeq = this.snapshot?.timeframe?.get(candidate.feedKey) ?? -1;
|
|
486
|
-
if (candidate.seq <= snapshotSeq) {
|
|
487
|
-
continue;
|
|
488
|
-
}
|
|
489
|
-
if (!import_timeframe2.Timeframe.dependencies(candidate.data.timeframe, this.timeframe).isEmpty()) {
|
|
490
|
-
continue;
|
|
491
|
-
}
|
|
492
|
-
run = true;
|
|
493
|
-
this.host.echoProcessor({
|
|
494
|
-
batch: candidate.data.payload.data.batch,
|
|
495
|
-
meta: {
|
|
496
|
-
feedKey: candidate.feedKey,
|
|
497
|
-
seq: candidate.seq,
|
|
498
|
-
memberKey: candidate.feedKey,
|
|
499
|
-
timeframe: candidate.data.timeframe
|
|
500
|
-
}
|
|
501
|
-
});
|
|
502
|
-
this.timeframe = import_timeframe2.Timeframe.merge(this.timeframe, new import_timeframe2.Timeframe([
|
|
503
|
-
[
|
|
504
|
-
candidate.feedKey,
|
|
505
|
-
candidate.seq
|
|
506
|
-
]
|
|
507
|
-
]));
|
|
508
|
-
}
|
|
509
|
-
}
|
|
510
|
-
}
|
|
511
|
-
getModel(id) {
|
|
512
|
-
const item = this.items.getItem(id);
|
|
513
|
-
if (!item) {
|
|
514
|
-
return;
|
|
515
|
-
}
|
|
516
|
-
(0, import_invariant.invariant)(item.modelMeta, void 0, {
|
|
517
|
-
F: __dxlog_file2,
|
|
518
|
-
L: 267,
|
|
519
|
-
S: this,
|
|
520
|
-
A: [
|
|
521
|
-
"item.modelMeta",
|
|
522
|
-
""
|
|
523
|
-
]
|
|
524
|
-
});
|
|
525
|
-
const ModelConstructor = this.modelFactory.getModel(item.modelMeta.type)?.constructor;
|
|
526
|
-
(0, import_invariant.invariant)(ModelConstructor, void 0, {
|
|
527
|
-
F: __dxlog_file2,
|
|
528
|
-
L: 269,
|
|
529
|
-
S: this,
|
|
530
|
-
A: [
|
|
531
|
-
"ModelConstructor",
|
|
532
|
-
""
|
|
533
|
-
]
|
|
534
|
-
});
|
|
535
|
-
const model = new ModelConstructor(item.modelMeta, item.id, () => item.state, async (mutation) => {
|
|
536
|
-
(0, import_invariant.invariant)(item.modelMeta, void 0, {
|
|
537
|
-
F: __dxlog_file2,
|
|
538
|
-
L: 276,
|
|
539
|
-
S: this,
|
|
540
|
-
A: [
|
|
541
|
-
"item.modelMeta",
|
|
542
|
-
""
|
|
543
|
-
]
|
|
544
|
-
});
|
|
545
|
-
this.proxy.mutate((0, import_echo_db2.createModelMutation)(id, (0, import_echo_db2.encodeModelMutation)(item.modelMeta, mutation)));
|
|
546
|
-
return {
|
|
547
|
-
feedKey: import_keys3.PublicKey.from("00"),
|
|
548
|
-
seq: 0,
|
|
549
|
-
waitToBeProcessed: () => Promise.resolve()
|
|
550
|
-
};
|
|
551
|
-
});
|
|
552
|
-
model.initialize();
|
|
553
|
-
return model;
|
|
554
|
-
}
|
|
555
|
-
};
|
|
556
236
|
// Annotate the CommonJS export names for ESM import in node:
|
|
557
237
|
0 && (module.exports = {
|
|
558
|
-
DatabaseTestBuilder,
|
|
559
|
-
DatabaseTestPeer,
|
|
560
238
|
MemoryNetworkManagerProvider,
|
|
561
239
|
TestAgent,
|
|
562
240
|
TestAgentBuilder,
|
|
563
241
|
TestFeedBuilder,
|
|
564
242
|
WebsocketNetworkManagerProvider,
|
|
565
|
-
changeStorageVersionInMetadata
|
|
566
|
-
createMemoryDatabase,
|
|
567
|
-
createRemoteDatabaseFromDataServiceHost,
|
|
568
|
-
testLocalDatabase
|
|
243
|
+
changeStorageVersionInMetadata
|
|
569
244
|
});
|
|
570
245
|
//# sourceMappingURL=index.cjs.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../../../../src/testing/change-metadata.ts", "../../../../src/testing/test-agent-builder.ts", "../../../../src/testing/test-feed-builder.ts"
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nimport { log } from '@dxos/log';\nimport { schema } from '@dxos/protocols';\nimport type { Storage } from '@dxos/random-access-storage';\n\nimport { MetadataStore } from '../metadata';\n\nconst EchoMetadata = schema.getCodecForType('dxos.echo.metadata.EchoMetadata');\n\n/**\n * This function will change the storage version in the metadata.\n * This will break your storage and make it unusable.\n * Use this only for testing purposes.\n */\nexport const changeStorageVersionInMetadata = async (storage: Storage, version: number) => {\n log.info('Changing storage version in metadata. USE ONLY FOR TESTING.');\n const metadata = new MetadataStore(storage.createDirectory('metadata'));\n await metadata.load();\n const echoMetadata = metadata.metadata;\n echoMetadata.version = version;\n const file = metadata._directory.getOrCreateFile('EchoMetadata');\n await metadata._writeFile(file, EchoMetadata, echoMetadata);\n await metadata._directory.flush();\n};\n", "//\n// Copyright 2022 DXOS.org\n//\n\nimport { Context } from '@dxos/context';\nimport { CredentialGenerator } from '@dxos/credentials';\nimport { DocumentModel } from '@dxos/document-model';\nimport { type FeedStore } from '@dxos/feed-store';\nimport { type Keyring } from '@dxos/keyring';\nimport { PublicKey } from '@dxos/keys';\nimport { MemorySignalManager, MemorySignalManagerContext, WebsocketSignalManager } from '@dxos/messaging';\nimport { ModelFactory } from '@dxos/model-factory';\nimport { createSimplePeerTransportFactory, MemoryTransportFactory, NetworkManager } from '@dxos/network-manager';\nimport type { FeedMessage } from '@dxos/protocols/proto/dxos/echo/feed';\nimport { type SpaceMetadata } from '@dxos/protocols/proto/dxos/echo/metadata';\nimport { AdmittedFeed } from '@dxos/protocols/proto/dxos/halo/credentials';\nimport { createStorage, type Storage, StorageType } from '@dxos/random-access-storage';\nimport { Gossip, Presence } from '@dxos/teleport-extension-gossip';\nimport { BlobStore } from '@dxos/teleport-extension-object-sync';\nimport { ComplexMap } from '@dxos/util';\n\nimport { TestFeedBuilder } from './test-feed-builder';\nimport { SnapshotStore } from '../db-host';\nimport { MetadataStore } from '../metadata';\nimport { MOCK_AUTH_PROVIDER, MOCK_AUTH_VERIFIER, type Space, SpaceManager, SpaceProtocol } from '../space';\n\nexport type NetworkManagerProvider = () => NetworkManager;\n\nexport const MemoryNetworkManagerProvider =\n (signalContext: MemorySignalManagerContext): NetworkManagerProvider =>\n () =>\n new NetworkManager({\n signalManager: new MemorySignalManager(signalContext),\n transportFactory: MemoryTransportFactory,\n });\n\nexport const WebsocketNetworkManagerProvider =\n (signalUrl: string): NetworkManagerProvider =>\n () =>\n new NetworkManager({\n signalManager: new WebsocketSignalManager([{ server: signalUrl }]),\n transportFactory: createSimplePeerTransportFactory(),\n });\n\nexport type TestAgentBuilderOptions = {\n storage?: Storage;\n networkManagerProvider?: NetworkManagerProvider;\n};\n\n/**\n * Factory for test agents.\n */\nexport class TestAgentBuilder {\n private readonly _agents = new ComplexMap<PublicKey, TestAgent>(PublicKey.hash);\n private readonly _storage: Storage;\n private readonly _networkManagerProvider: NetworkManagerProvider;\n\n constructor({ storage, networkManagerProvider }: TestAgentBuilderOptions = {}) {\n this._storage = storage ?? createStorage({ type: StorageType.RAM });\n this._networkManagerProvider =\n networkManagerProvider ?? MemoryNetworkManagerProvider(new MemorySignalManagerContext());\n }\n\n async close() {\n return Promise.all(this.agents.map((agent) => agent.close()));\n }\n\n get agents() {\n return Array.from(this._agents.values());\n }\n\n getAgent(deviceKey: PublicKey) {\n return this._agents.get(deviceKey);\n }\n\n async createPeer(): Promise<TestAgent> {\n // prettier-ignore\n const feedBuilder = new TestFeedBuilder()\n .setStorage(this._storage, `agent-${this._agents.size}`);\n\n const identityKey = await feedBuilder.keyring.createKey();\n const deviceKey = await feedBuilder.keyring.createKey();\n\n const agent = new TestAgent(this._networkManagerProvider, feedBuilder, identityKey, deviceKey);\n this._agents.set(deviceKey, agent);\n return agent;\n }\n}\n\n/**\n * Test agent that enables the creation and replication of multiple spaces.\n */\nexport class TestAgent {\n private readonly _spaces = new ComplexMap<PublicKey, Space>(PublicKey.hash);\n\n public readonly storage: Storage;\n public readonly keyring: Keyring;\n public readonly feedStore: FeedStore<FeedMessage>;\n\n private _metadataStore?: MetadataStore;\n get metadataStore() {\n return (this._metadataStore ??= new MetadataStore(this.storage.createDirectory('metadata')));\n }\n\n private _snapshotStore?: SnapshotStore;\n get snapshotStore() {\n return (this._snapshotStore ??= new SnapshotStore(this.storage.createDirectory('snapshots')));\n }\n\n private _blobStore?: BlobStore;\n get blobStore() {\n return (this._blobStore ??= new BlobStore(this.storage.createDirectory('blobs')));\n }\n\n public modelFactory = new ModelFactory().registerModel(DocumentModel);\n\n constructor(\n private readonly _networkManagerProvider: NetworkManagerProvider,\n private readonly _feedBuilder: TestFeedBuilder,\n public readonly identityKey: PublicKey,\n public readonly deviceKey: PublicKey,\n ) {\n this.storage = this._feedBuilder.storage;\n this.keyring = this._feedBuilder.keyring;\n this.feedStore = this._feedBuilder.createFeedStore();\n }\n\n async close() {\n return Promise.all([...this.spaces.map((space) => space.close())]);\n }\n\n get spaces() {\n return Array.from(this._spaces.values());\n }\n\n getSpace(spaceKey: PublicKey) {\n return this._spaces.get(spaceKey);\n }\n\n private _spaceManager?: SpaceManager;\n get spaceManager() {\n return (this._spaceManager ??= new SpaceManager({\n feedStore: this.feedStore,\n networkManager: this._networkManagerProvider(),\n modelFactory: this.modelFactory,\n metadataStore: this.metadataStore,\n snapshotStore: this.snapshotStore,\n blobStore: this.blobStore,\n }));\n }\n\n async createSpace(\n identityKey: PublicKey = this.identityKey,\n spaceKey?: PublicKey,\n genesisKey?: PublicKey,\n dataKey?: PublicKey,\n saveMetadata = false,\n ): Promise<Space> {\n if (!spaceKey) {\n saveMetadata = true;\n spaceKey = await this.keyring.createKey();\n }\n if (!genesisKey) {\n genesisKey = await this.keyring.createKey();\n }\n\n const controlFeed = await this.feedStore.openFeed(genesisKey, { writable: true });\n const dataFeed = await this.feedStore.openFeed(dataKey ?? (await this.keyring.createKey()), {\n writable: true,\n sparse: true,\n });\n\n const metadata: SpaceMetadata = {\n key: spaceKey,\n genesisFeedKey: genesisKey,\n controlFeedKey: controlFeed.key,\n dataFeedKey: dataFeed.key,\n };\n if (saveMetadata) {\n await this.metadataStore.addSpace(metadata);\n }\n\n await this.spaceManager.open();\n const space = await this.spaceManager.constructSpace({\n metadata,\n swarmIdentity: {\n peerKey: this.deviceKey,\n credentialProvider: MOCK_AUTH_PROVIDER,\n credentialAuthenticator: MOCK_AUTH_VERIFIER,\n },\n memberKey: identityKey,\n onAuthorizedConnection: (session) => {\n session.addExtension(\n 'dxos.mesh.teleport.gossip',\n this.createGossip().createExtension({ remotePeerId: session.remotePeerId }),\n );\n },\n });\n await space.setControlFeed(controlFeed);\n await space.setDataFeed(dataFeed);\n\n await space.open(new Context());\n\n this._spaces.set(spaceKey, space);\n return space;\n }\n\n createSpaceProtocol(topic: PublicKey, gossip?: Gossip) {\n return new SpaceProtocol({\n topic,\n swarmIdentity: {\n peerKey: this.deviceKey,\n credentialProvider: MOCK_AUTH_PROVIDER,\n credentialAuthenticator: MOCK_AUTH_VERIFIER,\n },\n networkManager: this._networkManagerProvider(),\n blobStore: this.blobStore,\n onSessionAuth: (session) => {\n session.addExtension(\n 'dxos.mesh.teleport.gossip',\n (gossip ?? this.createGossip()).createExtension({ remotePeerId: session.remotePeerId }),\n );\n },\n });\n }\n\n createGossip() {\n return new Gossip({\n localPeerId: this.deviceKey,\n });\n }\n\n createPresence(gossip?: Gossip) {\n return new Presence({\n announceInterval: 30,\n offlineTimeout: 200,\n identityKey: this.identityKey,\n gossip: gossip ?? this.createGossip(),\n });\n }\n\n async spaceGenesis(space: Space) {\n const generator = new CredentialGenerator(this.keyring, this.identityKey, this.deviceKey);\n const credentials = [\n ...(await generator.createSpaceGenesis(space.key, space.controlFeedKey!)),\n await generator.createFeedAdmission(space.key, space.dataFeedKey!, AdmittedFeed.Designation.DATA),\n await generator.createEpochCredential(space.key),\n ];\n\n for (const credential of credentials) {\n await space.controlPipeline.writer.write({\n credential: { credential },\n });\n }\n }\n}\n", "//\n// Copyright 2022 DXOS.org\n//\n\nimport { TestBuilder } from '@dxos/feed-store/testing';\nimport type { FeedMessage } from '@dxos/protocols/proto/dxos/echo/feed';\n\nimport { valueEncoding } from '../common';\n\n/**\n * Builder with default encoder and generator.\n */\nexport class TestFeedBuilder extends TestBuilder<FeedMessage> {\n constructor() {\n super({\n valueEncoding,\n });\n }\n}\n", "//\n// Copyright 2021 DXOS.org\n//\n\nimport { asyncTimeout } from '@dxos/async';\nimport { DocumentModel } from '@dxos/document-model';\nimport { DatabaseProxy, ItemManager } from '@dxos/echo-db';\nimport { MockFeedWriter } from '@dxos/feed-store/testing';\nimport { PublicKey } from '@dxos/keys';\nimport { ModelFactory } from '@dxos/model-factory';\nimport { type DataMessage } from '@dxos/protocols/proto/dxos/echo/feed';\nimport { StorageType, createStorage } from '@dxos/random-access-storage';\nimport { Timeframe } from '@dxos/timeframe';\n\nimport { AutomergeHost } from '../automerge';\nimport { DatabaseHost, type DataServiceHost, DataServiceImpl, DataServiceSubscriptions } from '../db-host';\nimport { type DataPipeline } from '../space';\n\nexport const createMemoryDatabase = async (modelFactory: ModelFactory) => {\n const feed = new MockFeedWriter<DataMessage>();\n const backend = new DatabaseHost(feed, async () => {\n // No-op.\n });\n\n feed.written.on(([data, meta]) =>\n backend.echoProcessor({\n batch: data.batch,\n meta: {\n ...meta,\n memberKey: PublicKey.random(),\n timeframe: new Timeframe([[meta.feedKey, meta.seq]]),\n },\n }),\n );\n\n const itemManager = new ItemManager(modelFactory);\n await backend.open(itemManager, new ModelFactory().registerModel(DocumentModel));\n return {\n backend,\n itemManager,\n };\n};\n\nexport const createRemoteDatabaseFromDataServiceHost = async (\n modelFactory: ModelFactory,\n dataServiceHost: DataServiceHost,\n) => {\n const dataServiceSubscriptions = new DataServiceSubscriptions();\n const automergeHost = new AutomergeHost({\n directory: createStorage({ type: StorageType.RAM }).createDirectory(),\n });\n const dataService = new DataServiceImpl(dataServiceSubscriptions, automergeHost);\n\n const spaceKey = PublicKey.random();\n await dataServiceSubscriptions.registerSpace(spaceKey, dataServiceHost);\n\n const itemManager = new ItemManager(modelFactory);\n const backend = new DatabaseProxy({ service: dataService, itemManager, spaceKey });\n await backend.open(new ModelFactory().registerModel(DocumentModel));\n return {\n itemManager,\n backend,\n };\n};\n\nexport const testLocalDatabase = async (create: DataPipeline, check: DataPipeline = create) => {\n const objectId = PublicKey.random().toHex();\n await create.databaseHost!.getWriteStream()?.write({\n batch: {\n objects: [\n {\n objectId,\n genesis: {\n modelType: DocumentModel.meta.type,\n },\n },\n ],\n },\n });\n\n await asyncTimeout(\n check.databaseHost!._itemDemuxer.mutation.waitForCondition(() => check.itemManager.entities.has(objectId)),\n 2000,\n );\n};\n", "//\n// Copyright 2023 DXOS.org\n//\n\nimport { Event, Trigger } from '@dxos/async';\nimport { DocumentModel } from '@dxos/document-model';\nimport { DatabaseProxy, ItemManager, createModelMutation, encodeModelMutation } from '@dxos/echo-db';\nimport { type WriteOptions, type WriteReceipt } from '@dxos/feed-store';\nimport { invariant } from '@dxos/invariant';\nimport { PublicKey } from '@dxos/keys';\nimport { ModelFactory } from '@dxos/model-factory';\nimport { type FeedMessageBlock, schema } from '@dxos/protocols';\nimport { type FeedMessage } from '@dxos/protocols/proto/dxos/echo/feed';\nimport { type EchoSnapshot, type SpaceSnapshot } from '@dxos/protocols/proto/dxos/echo/snapshot';\nimport { type Epoch } from '@dxos/protocols/proto/dxos/halo/credentials';\nimport { TextModel } from '@dxos/text-model';\nimport { Timeframe } from '@dxos/timeframe';\nimport { ComplexMap, isNotNullOrUndefined } from '@dxos/util';\n\nimport { DatabaseHost } from '../db-host';\n\nconst SPACE_KEY = PublicKey.random();\n\nexport class DatabaseTestBuilder {\n public readonly peers = new ComplexMap<PublicKey, DatabaseTestPeer>(PublicKey.hash);\n\n async createPeer(spaceKey = SPACE_KEY): Promise<DatabaseTestPeer> {\n const peer = new DatabaseTestPeer(this, spaceKey);\n this.peers.set(peer.key, peer);\n await peer.open();\n return peer;\n }\n}\n\ntype WriteRequest = {\n receipt: WriteReceipt;\n options: WriteOptions;\n trigger: Trigger;\n};\n\n// TODO(dmaretskyi): Still used in echo-schema test builder.\n\nexport class DatabaseTestPeer {\n public readonly modelFactory = new ModelFactory().registerModel(DocumentModel).registerModel(TextModel);\n\n public items!: ItemManager;\n public proxy!: DatabaseProxy;\n\n public host!: DatabaseHost;\n public hostItems!: ItemManager;\n\n //\n // Test state.\n //\n\n public readonly key = PublicKey.random();\n\n public feedMessages: FeedMessage[] = [];\n\n public readonly snapshots = new Map<string, SpaceSnapshot>();\n private currentEpoch?: Epoch;\n\n /**\n * Sequence number of the last mutation confirmed to be written to the feed store.\n */\n public confirmed = -1;\n\n /**\n * Current position of the peer's pipeline.\n */\n public timeframe = new Timeframe();\n\n public snapshot: SpaceSnapshot | undefined;\n\n private readonly _onConfirm = new Event();\n\n private readonly _writes = new Set<WriteRequest>();\n\n constructor(\n public readonly rig: DatabaseTestBuilder,\n public readonly spaceKey: PublicKey,\n ) {}\n\n async open() {\n this.hostItems = new ItemManager(this.modelFactory);\n this.host = new DatabaseHost(\n {\n write: async (message, { afterWrite }: WriteOptions) => {\n const seq =\n this.feedMessages.push({\n timeframe: this.timeframe,\n payload: {\n data: message,\n },\n }) - 1;\n\n const request: WriteRequest = {\n receipt: {\n seq,\n feedKey: this.key,\n },\n options: { afterWrite },\n trigger: new Trigger(),\n };\n this._writes.add(request);\n await request.trigger.wait();\n return request.receipt;\n },\n },\n async () => {\n // No-op.\n },\n );\n\n await this.host.open(this.hostItems, this.modelFactory);\n if (this.snapshot) {\n this.host._itemDemuxer.restoreFromSnapshot(this.snapshot.database);\n }\n\n this.items = new ItemManager(this.modelFactory);\n this.proxy = new DatabaseProxy({\n service: this.host.createDataServiceHost({ deferEvents: false }),\n itemManager: this.items,\n spaceKey: this.spaceKey,\n });\n await this.proxy.open(this.modelFactory);\n }\n\n /**\n * Confirm mutations written to the local feed.\n * @param seq Sequence number of the mutation to confirm. If not specified, all mutations will be confirmed.\n */\n async confirm(seq?: number) {\n this.confirmed = seq ?? this.feedMessages.length - 1;\n this._onConfirm.emit();\n\n for (const request of [...this._writes]) {\n if (this.confirmed >= request.receipt.seq) {\n this._writes.delete(request);\n await request.options.afterWrite?.(request.receipt);\n request.trigger.wake();\n }\n }\n\n this._processMessages(Timeframe.merge(this.timeframe, new Timeframe([[this.key, this.confirmed]])));\n }\n\n /**\n * Replicate the database to the specified timeframe.\n * @param to Timeframe to replicate to. If not specified, the database will be replicated to the latest timeframe (based on all other peers).\n */\n replicate(to?: Timeframe) {\n const toTimeframe = Timeframe.merge(\n to ?? new Timeframe(Array.from(this.rig.peers.values()).map((peer) => [peer.key, peer.confirmed])),\n this.timeframe,\n );\n toTimeframe.set(this.key, this.confirmed);\n\n this._processMessages(toTimeframe);\n }\n\n /**\n * Reload data from the feed. Wipes unconfirmed mutations.\n */\n async reload() {\n await this.open();\n const timeframe = this.timeframe;\n this.timeframe = this.snapshot?.timeframe ?? new Timeframe();\n this._processMessages(timeframe);\n }\n\n /**\n * Create snapshot and use it for the next reload.\n */\n makeSnapshot(): SpaceSnapshot {\n this.snapshot = {\n spaceKey: SPACE_KEY.asUint8Array(),\n database: this.host.createSnapshot(),\n timeframe: this.timeframe,\n };\n return this.snapshot;\n }\n\n createEpoch(mockSnapshot?: EchoSnapshot) {\n const snapshot = this.makeSnapshot();\n // Substitute snapshot with the mock one for test purposes (e.g. to test with empty snapshot).\n mockSnapshot && (snapshot.database = mockSnapshot);\n const snapshotCid = PublicKey.from(\n schema.getCodecForType('dxos.echo.snapshot.SpaceSnapshot').encode(snapshot),\n ).toHex();\n this.snapshots.set(snapshotCid, snapshot);\n\n const epoch: Epoch = {\n previousId: PublicKey.random(),\n timeframe: this.timeframe,\n number: this.currentEpoch ? this.currentEpoch.number + 1 : 0,\n snapshotCid,\n };\n\n this.currentEpoch = epoch;\n\n this.host._itemDemuxer.restoreFromSnapshot(snapshot.database);\n }\n\n /**\n * Gets all candidate messages according to the current timeframe.\n * Does not take into account the current snapshot, timeframe dependencies, or the confirmed, or replicated state.\n */\n private _getHeads(): FeedMessageBlock[] {\n return Array.from(this.rig.peers.values())\n .map((peer): FeedMessageBlock => {\n const seq = this.timeframe.get(peer.key) ?? -1;\n const message = peer.feedMessages[seq + 1];\n return (\n message && {\n feedKey: peer.key,\n seq: seq + 1,\n data: message,\n }\n );\n })\n .filter(isNotNullOrUndefined);\n }\n\n private _processMessages(to: Timeframe) {\n let run = true;\n while (run) {\n run = false;\n\n const heads = this._getHeads();\n for (const candidate of heads) {\n const toSeq = to.get(candidate.feedKey) ?? -1;\n if (toSeq < candidate.seq) {\n continue;\n }\n\n const snapshotSeq = this.snapshot?.timeframe?.get(candidate.feedKey) ?? -1;\n if (candidate.seq <= snapshotSeq) {\n continue;\n }\n\n if (!Timeframe.dependencies(candidate.data.timeframe, this.timeframe).isEmpty()) {\n continue;\n }\n\n run = true;\n this.host.echoProcessor({\n batch: candidate.data.payload.data!.batch,\n meta: {\n feedKey: candidate.feedKey,\n seq: candidate.seq,\n memberKey: candidate.feedKey,\n timeframe: candidate.data.timeframe,\n },\n });\n this.timeframe = Timeframe.merge(this.timeframe, new Timeframe([[candidate.feedKey, candidate.seq]]));\n }\n }\n }\n\n getModel(id: string): DocumentModel | TextModel | undefined {\n const item = this.items.getItem(id);\n if (!item) {\n return;\n }\n\n invariant(item.modelMeta);\n const ModelConstructor = this.modelFactory.getModel(item.modelMeta.type)?.constructor;\n invariant(ModelConstructor);\n\n const model = new ModelConstructor(\n item.modelMeta,\n item.id,\n () => item.state,\n async (mutation) => {\n invariant(item.modelMeta);\n this.proxy.mutate(createModelMutation(id, encodeModelMutation(item.modelMeta, mutation)));\n return {\n feedKey: PublicKey.from('00'),\n seq: 0,\n waitToBeProcessed: () => Promise.resolve(),\n };\n },\n );\n model.initialize();\n\n return model;\n }\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIA,iBAAoB;AACpB,uBAAuB;ACDvB,qBAAwB;AACxB,yBAAoC;AACpC,4BAA8B;AAG9B,kBAA0B;AAC1B,uBAAwF;AACxF,2BAA6B;AAC7B,6BAAyF;AAGzF,IAAAA,sBAA6B;AAC7B,mCAAyD;AACzD,uCAAiC;AACjC,4CAA0B;AAC1B,kBAA2B;ACf3B,qBAA4B;ACA5B,mBAA6B;AAC7B,IAAAC,yBAA8B;AAC9B,qBAA2C;AAC3C,IAAAC,kBAA+B;AAC/B,IAAAC,eAA0B;AAC1B,IAAAC,wBAA6B;A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D,KAAMG;UACpCF,MAAM;YACJM,SAAS8F,UAAU9F;YACnBC,KAAK6F,UAAU7F;YACflD,WAAW+I,UAAU9F;YACrBF,WAAWgG,UAAUrG,KAAKK;UAC5B;QACF,CAAA;AACA,aAAKA,YAAYC,kBAAAA,UAAU0E,MAAM,KAAK3E,WAAW,IAAIC,kBAAAA,UAAU;UAAC;YAAC+F,UAAU9F;YAAS8F,UAAU7F;;SAAK,CAAA;MACrG;IACF;EACF;EAEAkG,SAASC,IAAmD;AAC1D,UAAMC,OAAO,KAAKtC,MAAMuC,QAAQF,EAAAA;AAChC,QAAI,CAACC,MAAM;AACT;IACF;AAEAE,oCAAUF,KAAKG,WAAS,QAAA;;;;;;;;;AACxB,UAAMC,mBAAmB,KAAK9L,aAAawL,SAASE,KAAKG,UAAUjO,IAAI,GAAGtB;AAC1EsP,oCAAUE,kBAAAA,QAAAA;;;;;;;;;AAEV,UAAMC,QAAQ,IAAID,iBAChBJ,KAAKG,WACLH,KAAKD,IACL,MAAMC,KAAKM,OACX,OAAO/E,aAAAA;AACL2E,sCAAUF,KAAKG,WAAS,QAAA;;;;;;;;;AACxB,WAAKxC,MAAM4C,WAAOC,qCAAoBT,QAAIU,qCAAoBT,KAAKG,WAAW5E,QAAAA,CAAAA,CAAAA;AAC9E,aAAO;QACL5B,SAAS7H,aAAAA,UAAUgB,KAAK,IAAA;QACxB8G,KAAK;QACL8G,mBAAmB,MAAMlO,QAAQmO,QAAO;MAC1C;IACF,CAAA;AAEFN,UAAMO,WAAU;AAEhB,WAAOP;EACT;AACF;",
|
|
6
|
-
"names": ["import_credentials", "
|
|
3
|
+
"sources": ["../../../../src/testing/change-metadata.ts", "../../../../src/testing/test-agent-builder.ts", "../../../../src/testing/test-feed-builder.ts"],
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nimport { log } from '@dxos/log';\nimport { schema } from '@dxos/protocols';\nimport type { Storage } from '@dxos/random-access-storage';\n\nimport { MetadataStore } from '../metadata';\n\nconst EchoMetadata = schema.getCodecForType('dxos.echo.metadata.EchoMetadata');\n\n/**\n * This function will change the storage version in the metadata.\n * This will break your storage and make it unusable.\n * Use this only for testing purposes.\n */\nexport const changeStorageVersionInMetadata = async (storage: Storage, version: number) => {\n log.info('Changing storage version in metadata. USE ONLY FOR TESTING.');\n const metadata = new MetadataStore(storage.createDirectory('metadata'));\n await metadata.load();\n const echoMetadata = metadata.metadata;\n echoMetadata.version = version;\n const file = metadata._directory.getOrCreateFile('EchoMetadata');\n await metadata._writeFile(file, EchoMetadata, echoMetadata);\n await metadata._directory.flush();\n};\n", "//\n// Copyright 2022 DXOS.org\n//\n\nimport { Context } from '@dxos/context';\nimport { CredentialGenerator } from '@dxos/credentials';\nimport { type FeedStore } from '@dxos/feed-store';\nimport { type Keyring } from '@dxos/keyring';\nimport { PublicKey } from '@dxos/keys';\nimport { MemorySignalManager, MemorySignalManagerContext, WebsocketSignalManager } from '@dxos/messaging';\nimport { MemoryTransportFactory, NetworkManager, createSimplePeerTransportFactory } from '@dxos/network-manager';\nimport type { FeedMessage } from '@dxos/protocols/proto/dxos/echo/feed';\nimport { type SpaceMetadata } from '@dxos/protocols/proto/dxos/echo/metadata';\nimport { AdmittedFeed } from '@dxos/protocols/proto/dxos/halo/credentials';\nimport { StorageType, createStorage, type Storage } from '@dxos/random-access-storage';\nimport { Gossip, Presence } from '@dxos/teleport-extension-gossip';\nimport { BlobStore } from '@dxos/teleport-extension-object-sync';\nimport { ComplexMap } from '@dxos/util';\n\nimport { TestFeedBuilder } from './test-feed-builder';\nimport { SnapshotStore } from '../db-host';\nimport { MetadataStore } from '../metadata';\nimport { MOCK_AUTH_PROVIDER, MOCK_AUTH_VERIFIER, SpaceManager, SpaceProtocol, type Space } from '../space';\n\nexport type NetworkManagerProvider = () => NetworkManager;\n\nexport const MemoryNetworkManagerProvider =\n (signalContext: MemorySignalManagerContext): NetworkManagerProvider =>\n () =>\n new NetworkManager({\n signalManager: new MemorySignalManager(signalContext),\n transportFactory: MemoryTransportFactory,\n });\n\nexport const WebsocketNetworkManagerProvider =\n (signalUrl: string): NetworkManagerProvider =>\n () =>\n new NetworkManager({\n signalManager: new WebsocketSignalManager([{ server: signalUrl }]),\n transportFactory: createSimplePeerTransportFactory(),\n });\n\nexport type TestAgentBuilderOptions = {\n storage?: Storage;\n networkManagerProvider?: NetworkManagerProvider;\n};\n\n/**\n * Factory for test agents.\n */\nexport class TestAgentBuilder {\n private readonly _agents = new ComplexMap<PublicKey, TestAgent>(PublicKey.hash);\n private readonly _storage: Storage;\n private readonly _networkManagerProvider: NetworkManagerProvider;\n\n constructor({ storage, networkManagerProvider }: TestAgentBuilderOptions = {}) {\n this._storage = storage ?? createStorage({ type: StorageType.RAM });\n this._networkManagerProvider =\n networkManagerProvider ?? MemoryNetworkManagerProvider(new MemorySignalManagerContext());\n }\n\n async close() {\n return Promise.all(this.agents.map((agent) => agent.close()));\n }\n\n get agents() {\n return Array.from(this._agents.values());\n }\n\n getAgent(deviceKey: PublicKey) {\n return this._agents.get(deviceKey);\n }\n\n async createPeer(): Promise<TestAgent> {\n // prettier-ignore\n const feedBuilder = new TestFeedBuilder()\n .setStorage(this._storage, `agent-${this._agents.size}`);\n\n const identityKey = await feedBuilder.keyring.createKey();\n const deviceKey = await feedBuilder.keyring.createKey();\n\n const agent = new TestAgent(this._networkManagerProvider, feedBuilder, identityKey, deviceKey);\n this._agents.set(deviceKey, agent);\n return agent;\n }\n}\n\n/**\n * Test agent that enables the creation and replication of multiple spaces.\n */\nexport class TestAgent {\n private readonly _spaces = new ComplexMap<PublicKey, Space>(PublicKey.hash);\n\n public readonly storage: Storage;\n public readonly keyring: Keyring;\n public readonly feedStore: FeedStore<FeedMessage>;\n\n private _metadataStore?: MetadataStore;\n get metadataStore() {\n return (this._metadataStore ??= new MetadataStore(this.storage.createDirectory('metadata')));\n }\n\n private _snapshotStore?: SnapshotStore;\n get snapshotStore() {\n return (this._snapshotStore ??= new SnapshotStore(this.storage.createDirectory('snapshots')));\n }\n\n private _blobStore?: BlobStore;\n get blobStore() {\n return (this._blobStore ??= new BlobStore(this.storage.createDirectory('blobs')));\n }\n\n constructor(\n private readonly _networkManagerProvider: NetworkManagerProvider,\n private readonly _feedBuilder: TestFeedBuilder,\n public readonly identityKey: PublicKey,\n public readonly deviceKey: PublicKey,\n ) {\n this.storage = this._feedBuilder.storage;\n this.keyring = this._feedBuilder.keyring;\n this.feedStore = this._feedBuilder.createFeedStore();\n }\n\n async close() {\n return Promise.all([...this.spaces.map((space) => space.close())]);\n }\n\n get spaces() {\n return Array.from(this._spaces.values());\n }\n\n getSpace(spaceKey: PublicKey) {\n return this._spaces.get(spaceKey);\n }\n\n private _spaceManager?: SpaceManager;\n get spaceManager() {\n return (this._spaceManager ??= new SpaceManager({\n feedStore: this.feedStore,\n networkManager: this._networkManagerProvider(),\n metadataStore: this.metadataStore,\n snapshotStore: this.snapshotStore,\n blobStore: this.blobStore,\n }));\n }\n\n async createSpace(\n identityKey: PublicKey = this.identityKey,\n spaceKey?: PublicKey,\n genesisKey?: PublicKey,\n dataKey?: PublicKey,\n saveMetadata = false,\n ): Promise<Space> {\n if (!spaceKey) {\n saveMetadata = true;\n spaceKey = await this.keyring.createKey();\n }\n if (!genesisKey) {\n genesisKey = await this.keyring.createKey();\n }\n\n const controlFeed = await this.feedStore.openFeed(genesisKey, { writable: true });\n const dataFeed = await this.feedStore.openFeed(dataKey ?? (await this.keyring.createKey()), {\n writable: true,\n sparse: true,\n });\n\n const metadata: SpaceMetadata = {\n key: spaceKey,\n genesisFeedKey: genesisKey,\n controlFeedKey: controlFeed.key,\n dataFeedKey: dataFeed.key,\n };\n if (saveMetadata) {\n await this.metadataStore.addSpace(metadata);\n }\n\n await this.spaceManager.open();\n const space = await this.spaceManager.constructSpace({\n metadata,\n swarmIdentity: {\n peerKey: this.deviceKey,\n credentialProvider: MOCK_AUTH_PROVIDER,\n credentialAuthenticator: MOCK_AUTH_VERIFIER,\n },\n memberKey: identityKey,\n onAuthorizedConnection: (session) => {\n session.addExtension(\n 'dxos.mesh.teleport.gossip',\n this.createGossip().createExtension({ remotePeerId: session.remotePeerId }),\n );\n },\n });\n await space.setControlFeed(controlFeed);\n await space.setDataFeed(dataFeed);\n\n await space.open(new Context());\n\n this._spaces.set(spaceKey, space);\n return space;\n }\n\n createSpaceProtocol(topic: PublicKey, gossip?: Gossip) {\n return new SpaceProtocol({\n topic,\n swarmIdentity: {\n peerKey: this.deviceKey,\n credentialProvider: MOCK_AUTH_PROVIDER,\n credentialAuthenticator: MOCK_AUTH_VERIFIER,\n },\n networkManager: this._networkManagerProvider(),\n blobStore: this.blobStore,\n onSessionAuth: (session) => {\n session.addExtension(\n 'dxos.mesh.teleport.gossip',\n (gossip ?? this.createGossip()).createExtension({ remotePeerId: session.remotePeerId }),\n );\n },\n });\n }\n\n createGossip() {\n return new Gossip({\n localPeerId: this.deviceKey,\n });\n }\n\n createPresence(gossip?: Gossip) {\n return new Presence({\n announceInterval: 30,\n offlineTimeout: 200,\n identityKey: this.identityKey,\n gossip: gossip ?? this.createGossip(),\n });\n }\n\n async spaceGenesis(space: Space) {\n const generator = new CredentialGenerator(this.keyring, this.identityKey, this.deviceKey);\n const credentials = [\n ...(await generator.createSpaceGenesis(space.key, space.controlFeedKey!)),\n await generator.createFeedAdmission(space.key, space.dataFeedKey!, AdmittedFeed.Designation.DATA),\n await generator.createEpochCredential(space.key),\n ];\n\n for (const credential of credentials) {\n await space.controlPipeline.writer.write({\n credential: { credential },\n });\n }\n }\n}\n", "//\n// Copyright 2022 DXOS.org\n//\n\nimport { TestBuilder } from '@dxos/feed-store/testing';\nimport type { FeedMessage } from '@dxos/protocols/proto/dxos/echo/feed';\n\nimport { valueEncoding } from '../common';\n\n/**\n * Builder with default encoder and generator.\n */\nexport class TestFeedBuilder extends TestBuilder<FeedMessage> {\n constructor() {\n super({\n valueEncoding,\n });\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;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C,iCAAaC,YAAYC,IAAI;MAChG,MAAMP,UAAUQ,sBAAsB3D,MAAMgB,GAAG;;AAGjD,eAAW4C,cAAcP,aAAa;AACpC,YAAMrD,MAAM6D,gBAAgBC,OAAOC,MAAM;QACvCH,YAAY;UAAEA;QAAW;MAC3B,CAAA;IACF;EACF;AACF;",
|
|
6
|
+
"names": ["import_credentials", "EchoMetadata", "schema", "getCodecForType", "changeStorageVersionInMetadata", "storage", "version", "log", "info", "metadata", "MetadataStore", "createDirectory", "load", "echoMetadata", "file", "_directory", "getOrCreateFile", "_writeFile", "flush", "TestFeedBuilder", "TestBuilder", "constructor", "valueEncoding", "MemoryNetworkManagerProvider", "signalContext", "NetworkManager", "signalManager", "MemorySignalManager", "transportFactory", "MemoryTransportFactory", "WebsocketNetworkManagerProvider", "signalUrl", "WebsocketSignalManager", "server", "createSimplePeerTransportFactory", "TestAgentBuilder", "networkManagerProvider", "_agents", "ComplexMap", "PublicKey", "hash", "_storage", "createStorage", "type", "StorageType", "RAM", "_networkManagerProvider", "MemorySignalManagerContext", "close", "Promise", "all", "agents", "map", "agent", "Array", "from", "values", "getAgent", "deviceKey", "get", "createPeer", "feedBuilder", "setStorage", "size", "identityKey", "keyring", "createKey", "TestAgent", "set", "metadataStore", "_metadataStore", "snapshotStore", "_snapshotStore", "SnapshotStore", "blobStore", "_blobStore", "BlobStore", "_feedBuilder", "_spaces", "feedStore", "createFeedStore", "spaces", "space", "getSpace", "spaceKey", "spaceManager", "_spaceManager", "SpaceManager", "networkManager", "createSpace", "genesisKey", "dataKey", "saveMetadata", "controlFeed", "openFeed", "writable", "dataFeed", "sparse", "key", "genesisFeedKey", "controlFeedKey", "dataFeedKey", "addSpace", "open", "constructSpace", "swarmIdentity", "peerKey", "credentialProvider", "MOCK_AUTH_PROVIDER", "credentialAuthenticator", "MOCK_AUTH_VERIFIER", "memberKey", "onAuthorizedConnection", "session", "addExtension", "createGossip", "createExtension", "remotePeerId", "setControlFeed", "setDataFeed", "Context", "createSpaceProtocol", "topic", "gossip", "SpaceProtocol", "onSessionAuth", "Gossip", "localPeerId", "createPresence", "Presence", "announceInterval", "offlineTimeout", "spaceGenesis", "generator", "CredentialGenerator", "credentials", "createSpaceGenesis", "createFeedAdmission", "AdmittedFeed", "Designation", "DATA", "createEpochCredential", "credential", "controlPipeline", "writer", "write"]
|
|
7
7
|
}
|
|
@@ -1,22 +1,12 @@
|
|
|
1
1
|
import { type Stream } from '@dxos/codec-protobuf';
|
|
2
|
-
import {
|
|
3
|
-
import { type DataService, type MutationReceipt, type SubscribeRequest, type EchoEvent, type WriteRequest, type FlushRequest, type SyncRepoRequest, type SyncRepoResponse, type HostInfo } from '@dxos/protocols/proto/dxos/echo/service';
|
|
4
|
-
import { type DataServiceHost } from './data-service-host';
|
|
2
|
+
import { type DataService, type EchoEvent, type FlushRequest, type HostInfo, type MutationReceipt, type SubscribeRequest, type SyncRepoRequest, type SyncRepoResponse, type WriteRequest } from '@dxos/protocols/proto/dxos/echo/service';
|
|
5
3
|
import { type AutomergeHost } from '../automerge';
|
|
6
|
-
export declare class DataServiceSubscriptions {
|
|
7
|
-
private readonly _spaces;
|
|
8
|
-
clear(): void;
|
|
9
|
-
registerSpace(spaceKey: PublicKey, host: DataServiceHost): Promise<void>;
|
|
10
|
-
unregisterSpace(spaceKey: PublicKey): Promise<void>;
|
|
11
|
-
getDataService(spaceKey: PublicKey): DataServiceHost | undefined;
|
|
12
|
-
}
|
|
13
4
|
/**
|
|
14
|
-
*
|
|
5
|
+
* Data sync between client and services.
|
|
15
6
|
*/
|
|
16
7
|
export declare class DataServiceImpl implements DataService {
|
|
17
|
-
private readonly _subscriptions;
|
|
18
8
|
private readonly _automergeHost;
|
|
19
|
-
constructor(
|
|
9
|
+
constructor(_automergeHost: AutomergeHost);
|
|
20
10
|
subscribe(request: SubscribeRequest): Stream<EchoEvent>;
|
|
21
11
|
write(request: WriteRequest): Promise<MutationReceipt>;
|
|
22
12
|
flush(request: FlushRequest): Promise<void>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"data-service.d.ts","sourceRoot":"","sources":["../../../../src/db-host/data-service.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,MAAM,EAAE,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"data-service.d.ts","sourceRoot":"","sources":["../../../../src/db-host/data-service.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,MAAM,EAAE,MAAM,sBAAsB,CAAC;AACnD,OAAO,EACL,KAAK,WAAW,EAChB,KAAK,SAAS,EACd,KAAK,YAAY,EACjB,KAAK,QAAQ,EACb,KAAK,eAAe,EACpB,KAAK,gBAAgB,EACrB,KAAK,eAAe,EACpB,KAAK,gBAAgB,EACrB,KAAK,YAAY,EAClB,MAAM,yCAAyC,CAAC;AAEjD,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,cAAc,CAAC;AAElD;;GAEG;AAEH,qBAAa,eAAgB,YAAW,WAAW;IACrC,OAAO,CAAC,QAAQ,CAAC,cAAc;gBAAd,cAAc,EAAE,aAAa;IAE1D,SAAS,CAAC,OAAO,EAAE,gBAAgB,GAAG,MAAM,CAAC,SAAS,CAAC;IAIvD,KAAK,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,eAAe,CAAC;IAIhD,KAAK,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC;IAM3C,WAAW,CAAC,OAAO,EAAE,IAAI,GAAG,OAAO,CAAC,QAAQ,CAAC;IAInD,QAAQ,CAAC,OAAO,EAAE,eAAe,GAAG,MAAM,CAAC,gBAAgB,CAAC;IAI5D,eAAe,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,IAAI,CAAC;CAGzD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/db-host/index.ts"],"names":[],"mappings":"AAIA,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/db-host/index.ts"],"names":[],"mappings":"AAIA,cAAc,oBAAoB,CAAC;AACnC,cAAc,kBAAkB,CAAC;AACjC,cAAc,gBAAgB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"control-pipeline.d.ts","sourceRoot":"","sources":["../../../../src/space/control-pipeline.ts"],"names":[],"mappings":"AAMA,OAAO,EAAqB,KAAK,UAAU,EAAE,KAAK,UAAU,EAAE,KAAK,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AACvG,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAGvC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sCAAsC,CAAC;AAExE,OAAO,EAAgB,KAAK,UAAU,EAAE,MAAM,6CAA6C,CAAC;AAG5F,OAAO,EAAE,KAAK,aAAa,EAAE,QAAQ,EAAU,MAAM,YAAY,CAAC;AAElE,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,EAAY,KAAK,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAE9D,MAAM,MAAM,qBAAqB,GAAG;IAClC,QAAQ,EAAE,SAAS,CAAC;IACpB,WAAW,EAAE,WAAW,CAAC,WAAW,CAAC,CAAC;IACtC,YAAY,EAAE,CAAC,OAAO,EAAE,SAAS,KAAK,OAAO,CAAC,WAAW,CAAC,WAAW,CAAC,CAAC,CAAC;IACxE,aAAa,EAAE,aAAa,CAAC;CAC9B,CAAC;AAQF;;GAEG;AACH,qBAEa,eAAe;IAC1B,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAiB;IACtC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAW;IACrC,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAAoB;IAEvD,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAY;IACtC,OAAO,CAAC,QAAQ,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