@dxos/echo-pipeline 0.4.8-main.05fda5d → 0.4.8-main.06fa7e4
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-LED7X4WK.mjs → chunk-WAN2XUWE.mjs} +38 -691
- package/dist/lib/browser/chunk-WAN2XUWE.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +634 -5
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +2 -274
- package/dist/lib/browser/testing/index.mjs.map +4 -4
- package/dist/lib/node/{chunk-UKREXVZX.cjs → chunk-U6J2HC4T.cjs} +39 -681
- package/dist/lib/node/chunk-U6J2HC4T.cjs.map +7 -0
- package/dist/lib/node/index.cjs +648 -29
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/testing/index.cjs +12 -282
- package/dist/lib/node/testing/index.cjs.map +4 -4
- package/dist/types/src/automerge/automerge-host.d.ts +2 -1
- package/dist/types/src/automerge/automerge-host.d.ts.map +1 -1
- package/dist/types/src/automerge/automerge-storage-adapter.d.ts +2 -2
- package/dist/types/src/automerge/automerge-storage-adapter.d.ts.map +1 -1
- package/dist/types/src/space/control-pipeline.d.ts.map +1 -1
- package/dist/types/src/space/data-pipeline.d.ts +0 -1
- package/dist/types/src/space/data-pipeline.d.ts.map +1 -1
- package/dist/types/src/testing/index.d.ts +0 -1
- package/dist/types/src/testing/index.d.ts.map +1 -1
- package/dist/types/src/testing/util.d.ts +2 -6
- package/dist/types/src/testing/util.d.ts.map +1 -1
- package/package.json +33 -33
- package/src/automerge/automerge-host.ts +21 -22
- package/src/automerge/automerge-storage-adapter.ts +8 -10
- package/src/space/control-pipeline.ts +3 -1
- package/src/space/data-pipeline.ts +1 -44
- package/src/testing/index.ts +0 -1
- package/src/testing/util.ts +2 -26
- package/dist/lib/browser/chunk-LED7X4WK.mjs.map +0 -7
- package/dist/lib/node/chunk-UKREXVZX.cjs.map +0 -7
- 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/tests/database.test.d.ts +0 -2
- package/dist/types/src/tests/database.test.d.ts.map +0 -1
- package/src/testing/database-test-rig.ts +0 -289
- package/src/tests/database.test.ts +0 -100
|
@@ -1,14 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ItemManager } from '@dxos/echo-db';
|
|
2
2
|
import { ModelFactory } from '@dxos/model-factory';
|
|
3
|
-
import { DatabaseHost
|
|
3
|
+
import { DatabaseHost } from '../db-host';
|
|
4
4
|
import { type DataPipeline } from '../space';
|
|
5
5
|
export declare const createMemoryDatabase: (modelFactory: ModelFactory) => Promise<{
|
|
6
6
|
backend: DatabaseHost;
|
|
7
7
|
itemManager: ItemManager;
|
|
8
8
|
}>;
|
|
9
|
-
export declare const createRemoteDatabaseFromDataServiceHost: (modelFactory: ModelFactory, dataServiceHost: DataServiceHost) => Promise<{
|
|
10
|
-
itemManager: ItemManager;
|
|
11
|
-
backend: DatabaseProxy;
|
|
12
|
-
}>;
|
|
13
9
|
export declare const testLocalDatabase: (create: DataPipeline, check?: DataPipeline) => Promise<void>;
|
|
14
10
|
//# sourceMappingURL=util.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../../../../src/testing/util.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../../../../src/testing/util.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAG5C,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAInD,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC1C,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,UAAU,CAAC;AAE7C,eAAO,MAAM,oBAAoB,iBAAwB,YAAY;;;EAuBpE,CAAC;AAEF,eAAO,MAAM,iBAAiB,WAAkB,YAAY,UAAS,YAAY,kBAmBhF,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxos/echo-pipeline",
|
|
3
|
-
"version": "0.4.8-main.
|
|
3
|
+
"version": "0.4.8-main.06fa7e4",
|
|
4
4
|
"description": "ECHO database.",
|
|
5
5
|
"homepage": "https://dxos.org",
|
|
6
6
|
"bugs": "https://github.com/dxos/dxos/issues",
|
|
@@ -36,38 +36,38 @@
|
|
|
36
36
|
],
|
|
37
37
|
"dependencies": {
|
|
38
38
|
"crc-32": "^1.2.2",
|
|
39
|
-
"@dxos/
|
|
40
|
-
"@dxos/
|
|
41
|
-
"@dxos/
|
|
42
|
-
"@dxos/
|
|
43
|
-
"@dxos/credentials": "0.4.8-main.
|
|
44
|
-
"@dxos/
|
|
45
|
-
"@dxos/
|
|
46
|
-
"@dxos/
|
|
47
|
-
"@dxos/
|
|
48
|
-
"@dxos/
|
|
49
|
-
"@dxos/
|
|
50
|
-
"@dxos/
|
|
51
|
-
"@dxos/
|
|
52
|
-
"@dxos/
|
|
53
|
-
"@dxos/
|
|
54
|
-
"@dxos/messaging": "0.4.8-main.
|
|
55
|
-
"@dxos/
|
|
56
|
-
"@dxos/
|
|
57
|
-
"@dxos/
|
|
58
|
-
"@dxos/
|
|
59
|
-
"@dxos/
|
|
60
|
-
"@dxos/
|
|
61
|
-
"@dxos/
|
|
62
|
-
"@dxos/teleport-extension-
|
|
63
|
-
"@dxos/teleport
|
|
64
|
-
"@dxos/teleport-extension-
|
|
65
|
-
"@dxos/
|
|
66
|
-
"@dxos/
|
|
67
|
-
"@dxos/
|
|
68
|
-
"@dxos/
|
|
69
|
-
"@dxos/
|
|
70
|
-
"@dxos/
|
|
39
|
+
"@dxos/async": "0.4.8-main.06fa7e4",
|
|
40
|
+
"@dxos/automerge": "0.4.8-main.06fa7e4",
|
|
41
|
+
"@dxos/codec-protobuf": "0.4.8-main.06fa7e4",
|
|
42
|
+
"@dxos/context": "0.4.8-main.06fa7e4",
|
|
43
|
+
"@dxos/credentials": "0.4.8-main.06fa7e4",
|
|
44
|
+
"@dxos/crypto": "0.4.8-main.06fa7e4",
|
|
45
|
+
"@dxos/echo-db": "0.4.8-main.06fa7e4",
|
|
46
|
+
"@dxos/document-model": "0.4.8-main.06fa7e4",
|
|
47
|
+
"@dxos/debug": "0.4.8-main.06fa7e4",
|
|
48
|
+
"@dxos/feed-store": "0.4.8-main.06fa7e4",
|
|
49
|
+
"@dxos/invariant": "0.4.8-main.06fa7e4",
|
|
50
|
+
"@dxos/hypercore": "0.4.8-main.06fa7e4",
|
|
51
|
+
"@dxos/keyring": "0.4.8-main.06fa7e4",
|
|
52
|
+
"@dxos/keys": "0.4.8-main.06fa7e4",
|
|
53
|
+
"@dxos/log": "0.4.8-main.06fa7e4",
|
|
54
|
+
"@dxos/messaging": "0.4.8-main.06fa7e4",
|
|
55
|
+
"@dxos/model-factory": "0.4.8-main.06fa7e4",
|
|
56
|
+
"@dxos/node-std": "0.4.8-main.06fa7e4",
|
|
57
|
+
"@dxos/network-manager": "0.4.8-main.06fa7e4",
|
|
58
|
+
"@dxos/protocols": "0.4.8-main.06fa7e4",
|
|
59
|
+
"@dxos/random-access-storage": "0.4.8-main.06fa7e4",
|
|
60
|
+
"@dxos/rpc": "0.4.8-main.06fa7e4",
|
|
61
|
+
"@dxos/teleport-extension-automerge-replicator": "0.4.8-main.06fa7e4",
|
|
62
|
+
"@dxos/teleport-extension-object-sync": "0.4.8-main.06fa7e4",
|
|
63
|
+
"@dxos/teleport": "0.4.8-main.06fa7e4",
|
|
64
|
+
"@dxos/teleport-extension-gossip": "0.4.8-main.06fa7e4",
|
|
65
|
+
"@dxos/teleport-extension-replicator": "0.4.8-main.06fa7e4",
|
|
66
|
+
"@dxos/text-model": "0.4.8-main.06fa7e4",
|
|
67
|
+
"@dxos/tracing": "0.4.8-main.06fa7e4",
|
|
68
|
+
"@dxos/timeframe": "0.4.8-main.06fa7e4",
|
|
69
|
+
"@dxos/typings": "0.4.8-main.06fa7e4",
|
|
70
|
+
"@dxos/util": "0.4.8-main.06fa7e4"
|
|
71
71
|
},
|
|
72
72
|
"devDependencies": {
|
|
73
73
|
"fast-check": "^3.15.1",
|
|
@@ -13,7 +13,7 @@ import {
|
|
|
13
13
|
} from '@dxos/automerge/automerge-repo';
|
|
14
14
|
import { IndexedDBStorageAdapter } from '@dxos/automerge/automerge-repo-storage-indexeddb';
|
|
15
15
|
import { type Stream } from '@dxos/codec-protobuf';
|
|
16
|
-
import { Context
|
|
16
|
+
import { Context } from '@dxos/context';
|
|
17
17
|
import { PublicKey } from '@dxos/keys';
|
|
18
18
|
import { log } from '@dxos/log';
|
|
19
19
|
import { idCodec } from '@dxos/protocols';
|
|
@@ -31,7 +31,7 @@ import { MeshNetworkAdapter } from './mesh-network-adapter';
|
|
|
31
31
|
export type { DocumentId };
|
|
32
32
|
|
|
33
33
|
export interface MetadataMethods {
|
|
34
|
-
markDirty(
|
|
34
|
+
markDirty(idToLastHash: Map<string, string>): Promise<void>;
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
export type AutomergeHostParams = {
|
|
@@ -98,15 +98,13 @@ export class AutomergeHost {
|
|
|
98
98
|
}
|
|
99
99
|
|
|
100
100
|
try {
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
if (!rawSpaceKey) {
|
|
101
|
+
const spaceKey = getSpaceKeyFromDoc(doc);
|
|
102
|
+
if (!spaceKey) {
|
|
104
103
|
log('space key not found for share policy check', { peerId, documentId });
|
|
105
104
|
return false;
|
|
106
105
|
}
|
|
107
106
|
|
|
108
|
-
const
|
|
109
|
-
const authorizedDevices = this._authorizedDevices.get(spaceKey);
|
|
107
|
+
const authorizedDevices = this._authorizedDevices.get(PublicKey.from(spaceKey));
|
|
110
108
|
|
|
111
109
|
// TODO(mykola): Hack, stop abusing `peerMetadata` field.
|
|
112
110
|
const deviceKeyHex = (this.repo.peerMetadataByPeerId[peerId] as any)?.dxos_deviceKey;
|
|
@@ -164,8 +162,7 @@ export class AutomergeHost {
|
|
|
164
162
|
}
|
|
165
163
|
|
|
166
164
|
private _onUpdate(event: DocHandleChangePayload<any>) {
|
|
167
|
-
|
|
168
|
-
if (!spaceKey) {
|
|
165
|
+
if (this._metadata == null) {
|
|
169
166
|
return;
|
|
170
167
|
}
|
|
171
168
|
|
|
@@ -180,24 +177,16 @@ export class AutomergeHost {
|
|
|
180
177
|
return;
|
|
181
178
|
}
|
|
182
179
|
|
|
183
|
-
const
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
this._metadata!.markDirty(
|
|
188
|
-
idCodec.encode({ documentId: event.handle.documentId, objectId }),
|
|
189
|
-
lastAvailableHash,
|
|
190
|
-
),
|
|
191
|
-
);
|
|
192
|
-
}),
|
|
193
|
-
)
|
|
180
|
+
const encodedIds = objectIds.map((objectId) => idCodec.encode({ documentId: event.handle.documentId, objectId }));
|
|
181
|
+
const idToLastHash = new Map(encodedIds.map((id) => [id, lastAvailableHash]));
|
|
182
|
+
const markingDirtyPromise = this._metadata
|
|
183
|
+
.markDirty(idToLastHash)
|
|
194
184
|
.then(() => {
|
|
195
185
|
this._updatingMetadata.delete(event.handle.documentId);
|
|
196
186
|
})
|
|
197
187
|
.catch((err: Error) => {
|
|
198
|
-
|
|
188
|
+
this._ctx.disposed && log.catch(err);
|
|
199
189
|
});
|
|
200
|
-
|
|
201
190
|
this._updatingMetadata.set(event.handle.documentId, markingDirtyPromise);
|
|
202
191
|
}
|
|
203
192
|
|
|
@@ -285,3 +274,13 @@ const getInlineChanges = (event: DocHandleChangePayload<any>) => {
|
|
|
285
274
|
}
|
|
286
275
|
return [...inlineChangedObjectIds];
|
|
287
276
|
};
|
|
277
|
+
|
|
278
|
+
export const getSpaceKeyFromDoc = (doc: any): string | null => {
|
|
279
|
+
// experimental_spaceKey is set on old documents, new ones are created with doc.access.spaceKey
|
|
280
|
+
const rawSpaceKey = doc.access?.spaceKey ?? doc.experimental_spaceKey;
|
|
281
|
+
if (rawSpaceKey == null) {
|
|
282
|
+
return null;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
return String(rawSpaceKey);
|
|
286
|
+
};
|
|
@@ -5,20 +5,18 @@
|
|
|
5
5
|
// Copyright 2023 DXOS.org
|
|
6
6
|
//
|
|
7
7
|
|
|
8
|
-
import {
|
|
8
|
+
import { type Chunk, type StorageKey, type StorageAdapterInterface } from '@dxos/automerge/automerge-repo';
|
|
9
9
|
import { type Directory } from '@dxos/random-access-storage';
|
|
10
10
|
import { arrayToBuffer, bufferToArray } from '@dxos/util';
|
|
11
11
|
|
|
12
|
-
export class AutomergeStorageAdapter
|
|
12
|
+
export class AutomergeStorageAdapter implements StorageAdapterInterface {
|
|
13
13
|
// TODO(mykola): Hack for restricting automerge Repo to access storage if Host is `closed`.
|
|
14
14
|
// Automerge Repo do not have any lifetime management.
|
|
15
15
|
private _state: 'opened' | 'closed' = 'opened';
|
|
16
16
|
|
|
17
|
-
constructor(private readonly _directory: Directory) {
|
|
18
|
-
super();
|
|
19
|
-
}
|
|
17
|
+
constructor(private readonly _directory: Directory) {}
|
|
20
18
|
|
|
21
|
-
|
|
19
|
+
async load(key: StorageKey): Promise<Uint8Array | undefined> {
|
|
22
20
|
if (this._state !== 'opened') {
|
|
23
21
|
return undefined;
|
|
24
22
|
}
|
|
@@ -32,7 +30,7 @@ export class AutomergeStorageAdapter extends StorageAdapter {
|
|
|
32
30
|
return bufferToArray(buffer);
|
|
33
31
|
}
|
|
34
32
|
|
|
35
|
-
|
|
33
|
+
async save(key: StorageKey, data: Uint8Array): Promise<void> {
|
|
36
34
|
if (this._state !== 'opened') {
|
|
37
35
|
return undefined;
|
|
38
36
|
}
|
|
@@ -44,7 +42,7 @@ export class AutomergeStorageAdapter extends StorageAdapter {
|
|
|
44
42
|
await file.flush?.();
|
|
45
43
|
}
|
|
46
44
|
|
|
47
|
-
|
|
45
|
+
async remove(key: StorageKey): Promise<void> {
|
|
48
46
|
if (this._state !== 'opened') {
|
|
49
47
|
return undefined;
|
|
50
48
|
}
|
|
@@ -54,7 +52,7 @@ export class AutomergeStorageAdapter extends StorageAdapter {
|
|
|
54
52
|
await file.destroy();
|
|
55
53
|
}
|
|
56
54
|
|
|
57
|
-
|
|
55
|
+
async loadRange(keyPrefix: StorageKey): Promise<Chunk[]> {
|
|
58
56
|
if (this._state !== 'opened') {
|
|
59
57
|
return [];
|
|
60
58
|
}
|
|
@@ -75,7 +73,7 @@ export class AutomergeStorageAdapter extends StorageAdapter {
|
|
|
75
73
|
);
|
|
76
74
|
}
|
|
77
75
|
|
|
78
|
-
|
|
76
|
+
async removeRange(keyPrefix: StorageKey): Promise<void> {
|
|
79
77
|
if (this._state !== 'opened') {
|
|
80
78
|
return undefined;
|
|
81
79
|
}
|
|
@@ -78,7 +78,9 @@ export class ControlPipeline {
|
|
|
78
78
|
queueMicrotask(async () => {
|
|
79
79
|
try {
|
|
80
80
|
const feed = await feedProvider(info.key);
|
|
81
|
-
|
|
81
|
+
if (!this._pipeline.hasFeed(feed.key)) {
|
|
82
|
+
await this._pipeline.addFeed(feed);
|
|
83
|
+
}
|
|
82
84
|
} catch (err: any) {
|
|
83
85
|
log.catch(err);
|
|
84
86
|
}
|
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
type SpecificCredential,
|
|
11
11
|
checkCredentialType,
|
|
12
12
|
} from '@dxos/credentials';
|
|
13
|
-
import {
|
|
13
|
+
import { ItemManager } from '@dxos/echo-db';
|
|
14
14
|
import { type FeedWriter } from '@dxos/feed-store';
|
|
15
15
|
import { invariant } from '@dxos/invariant';
|
|
16
16
|
import { type PublicKey } from '@dxos/keys';
|
|
@@ -19,8 +19,6 @@ import { type ModelFactory } from '@dxos/model-factory';
|
|
|
19
19
|
import { CancelledError, type DataPipelineProcessed } from '@dxos/protocols';
|
|
20
20
|
import { type CreateEpochRequest } from '@dxos/protocols/proto/dxos/client/services';
|
|
21
21
|
import { type DataMessage } from '@dxos/protocols/proto/dxos/echo/feed';
|
|
22
|
-
import { type SpaceCache } from '@dxos/protocols/proto/dxos/echo/metadata';
|
|
23
|
-
import { type ObjectSnapshot } from '@dxos/protocols/proto/dxos/echo/model/document';
|
|
24
22
|
import { type SpaceSnapshot } from '@dxos/protocols/proto/dxos/echo/snapshot';
|
|
25
23
|
import { type Credential, type Epoch } from '@dxos/protocols/proto/dxos/halo/credentials';
|
|
26
24
|
import { Timeframe } from '@dxos/timeframe';
|
|
@@ -50,16 +48,6 @@ export type DataPipelineParams = {
|
|
|
50
48
|
onPipelineCreated: (pipeline: Pipeline) => Promise<void>;
|
|
51
49
|
};
|
|
52
50
|
|
|
53
|
-
/**
|
|
54
|
-
* Number of mutations since the last snapshot before we automatically create another snapshot.
|
|
55
|
-
*/
|
|
56
|
-
const MESSAGES_PER_SNAPSHOT = 10;
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* Minimum time between automatic snapshots.
|
|
60
|
-
*/
|
|
61
|
-
const AUTOMATIC_SNAPSHOT_DEBOUNCE_INTERVAL = 5_000;
|
|
62
|
-
|
|
63
51
|
/**
|
|
64
52
|
* Minimum time in MS between recording latest timeframe in metadata.
|
|
65
53
|
*/
|
|
@@ -194,7 +182,6 @@ export class DataPipeline implements CredentialProcessor {
|
|
|
194
182
|
|
|
195
183
|
// NOTE: Make sure the processing is stopped BEFORE we save the snapshot.
|
|
196
184
|
try {
|
|
197
|
-
await this._saveCache();
|
|
198
185
|
if (this._pipeline) {
|
|
199
186
|
await this._saveTargetTimeframe(this._pipeline.state.timeframe);
|
|
200
187
|
}
|
|
@@ -293,28 +280,6 @@ export class DataPipeline implements CredentialProcessor {
|
|
|
293
280
|
this._targetTimeframe = newTimeframe;
|
|
294
281
|
}
|
|
295
282
|
|
|
296
|
-
private async _saveCache() {
|
|
297
|
-
const cache: SpaceCache = {};
|
|
298
|
-
|
|
299
|
-
try {
|
|
300
|
-
// Add properties to cache.
|
|
301
|
-
const propertiesItem = this.itemManager.items.find(
|
|
302
|
-
(item) =>
|
|
303
|
-
item.modelMeta?.type === 'dxos.org/model/document' &&
|
|
304
|
-
// TODO(burdon): Document?
|
|
305
|
-
(getStateMachineFromItem(item)?.snapshot() as ObjectSnapshot).type === TYPE_PROPERTIES,
|
|
306
|
-
);
|
|
307
|
-
if (propertiesItem) {
|
|
308
|
-
cache.properties = getStateMachineFromItem(propertiesItem)?.snapshot() as ObjectSnapshot;
|
|
309
|
-
}
|
|
310
|
-
} catch (err) {
|
|
311
|
-
log.warn('Failed to cache properties', err);
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
// Save cache.
|
|
315
|
-
await this._params.metadataStore.setCache(this._params.spaceKey, cache);
|
|
316
|
-
}
|
|
317
|
-
|
|
318
283
|
private async _noteTargetStateIfNeeded(timeframe: Timeframe) {
|
|
319
284
|
if (!this._pipeline?.state.reachedTarget) {
|
|
320
285
|
return;
|
|
@@ -327,13 +292,6 @@ export class DataPipeline implements CredentialProcessor {
|
|
|
327
292
|
|
|
328
293
|
await this._saveTargetTimeframe(timeframe);
|
|
329
294
|
}
|
|
330
|
-
|
|
331
|
-
if (
|
|
332
|
-
Date.now() - this._lastSnapshotSaveTime > AUTOMATIC_SNAPSHOT_DEBOUNCE_INTERVAL &&
|
|
333
|
-
timeframe.totalMessages() - this._lastAutomaticSnapshotTimeframe.totalMessages() > MESSAGES_PER_SNAPSHOT
|
|
334
|
-
) {
|
|
335
|
-
await this._saveCache();
|
|
336
|
-
}
|
|
337
295
|
}
|
|
338
296
|
|
|
339
297
|
private async _processEpochInSeparateTask(epoch: SpecificCredential<Epoch>) {
|
|
@@ -419,7 +377,6 @@ export class DataPipeline implements CredentialProcessor {
|
|
|
419
377
|
|
|
420
378
|
private async _flush() {
|
|
421
379
|
try {
|
|
422
|
-
await this._saveCache();
|
|
423
380
|
if (this._pipeline) {
|
|
424
381
|
await this._saveTargetTimeframe(this._pipeline.state.timeframe);
|
|
425
382
|
}
|
package/src/testing/index.ts
CHANGED
package/src/testing/util.ts
CHANGED
|
@@ -4,16 +4,14 @@
|
|
|
4
4
|
|
|
5
5
|
import { asyncTimeout } from '@dxos/async';
|
|
6
6
|
import { DocumentModel } from '@dxos/document-model';
|
|
7
|
-
import {
|
|
7
|
+
import { ItemManager } from '@dxos/echo-db';
|
|
8
8
|
import { MockFeedWriter } from '@dxos/feed-store/testing';
|
|
9
9
|
import { PublicKey } from '@dxos/keys';
|
|
10
10
|
import { ModelFactory } from '@dxos/model-factory';
|
|
11
11
|
import { type DataMessage } from '@dxos/protocols/proto/dxos/echo/feed';
|
|
12
|
-
import { StorageType, createStorage } from '@dxos/random-access-storage';
|
|
13
12
|
import { Timeframe } from '@dxos/timeframe';
|
|
14
13
|
|
|
15
|
-
import {
|
|
16
|
-
import { DatabaseHost, type DataServiceHost, DataServiceImpl, DataServiceSubscriptions } from '../db-host';
|
|
14
|
+
import { DatabaseHost } from '../db-host';
|
|
17
15
|
import { type DataPipeline } from '../space';
|
|
18
16
|
|
|
19
17
|
export const createMemoryDatabase = async (modelFactory: ModelFactory) => {
|
|
@@ -41,28 +39,6 @@ export const createMemoryDatabase = async (modelFactory: ModelFactory) => {
|
|
|
41
39
|
};
|
|
42
40
|
};
|
|
43
41
|
|
|
44
|
-
export const createRemoteDatabaseFromDataServiceHost = async (
|
|
45
|
-
modelFactory: ModelFactory,
|
|
46
|
-
dataServiceHost: DataServiceHost,
|
|
47
|
-
) => {
|
|
48
|
-
const dataServiceSubscriptions = new DataServiceSubscriptions();
|
|
49
|
-
const automergeHost = new AutomergeHost({
|
|
50
|
-
directory: createStorage({ type: StorageType.RAM }).createDirectory(),
|
|
51
|
-
});
|
|
52
|
-
const dataService = new DataServiceImpl(dataServiceSubscriptions, automergeHost);
|
|
53
|
-
|
|
54
|
-
const spaceKey = PublicKey.random();
|
|
55
|
-
await dataServiceSubscriptions.registerSpace(spaceKey, dataServiceHost);
|
|
56
|
-
|
|
57
|
-
const itemManager = new ItemManager(modelFactory);
|
|
58
|
-
const backend = new DatabaseProxy({ service: dataService, itemManager, spaceKey });
|
|
59
|
-
await backend.open(new ModelFactory().registerModel(DocumentModel));
|
|
60
|
-
return {
|
|
61
|
-
itemManager,
|
|
62
|
-
backend,
|
|
63
|
-
};
|
|
64
|
-
};
|
|
65
|
-
|
|
66
42
|
export const testLocalDatabase = async (create: DataPipeline, check: DataPipeline = create) => {
|
|
67
43
|
const objectId = PublicKey.random().toHex();
|
|
68
44
|
await create.databaseHost!.getWriteStream()?.write({
|