@dxos/echo-pipeline 0.8.4-main.5ea62a8 → 0.8.4-main.72ec0f3
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-I4JBIZSN.mjs → chunk-FR6GJ4S4.mjs} +341 -427
- package/dist/lib/browser/{chunk-I4JBIZSN.mjs.map → chunk-FR6GJ4S4.mjs.map} +2 -2
- package/dist/lib/browser/chunk-WJJXJTNS.mjs +240 -0
- package/dist/lib/browser/chunk-WJJXJTNS.mjs.map +7 -0
- package/dist/lib/browser/filter/index.mjs +3 -1
- package/dist/lib/browser/index.mjs +864 -751
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +65 -106
- package/dist/lib/browser/testing/index.mjs.map +3 -3
- package/dist/lib/node-esm/{chunk-YOL7JY5W.mjs → chunk-JQCCVDLT.mjs} +341 -427
- package/dist/lib/node-esm/{chunk-YOL7JY5W.mjs.map → chunk-JQCCVDLT.mjs.map} +2 -2
- package/dist/lib/node-esm/chunk-LEQ77KAT.mjs +240 -0
- package/dist/lib/node-esm/chunk-LEQ77KAT.mjs.map +7 -0
- package/dist/lib/node-esm/filter/index.mjs +3 -1
- package/dist/lib/node-esm/index.mjs +864 -751
- package/dist/lib/node-esm/index.mjs.map +3 -3
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/testing/index.mjs +65 -106
- package/dist/lib/node-esm/testing/index.mjs.map +3 -3
- package/dist/types/src/automerge/automerge-host.d.ts +2 -27
- package/dist/types/src/automerge/automerge-host.d.ts.map +1 -1
- package/dist/types/src/automerge/collection-synchronizer.d.ts +2 -1
- package/dist/types/src/automerge/collection-synchronizer.d.ts.map +1 -1
- package/dist/types/src/common/codec.d.ts +1 -1
- package/dist/types/src/common/codec.d.ts.map +1 -1
- package/dist/types/src/db-host/data-service.d.ts.map +1 -1
- package/dist/types/src/db-host/echo-host.d.ts.map +1 -1
- package/dist/types/src/db-host/query-service.d.ts.map +1 -1
- package/dist/types/src/edge/echo-edge-replicator.d.ts.map +1 -1
- package/dist/types/src/filter/filter-match.d.ts +4 -1
- package/dist/types/src/filter/filter-match.d.ts.map +1 -1
- package/dist/types/src/query/errors.d.ts +14 -13
- package/dist/types/src/query/errors.d.ts.map +1 -1
- package/dist/types/src/query/plan.d.ts +8 -1
- package/dist/types/src/query/plan.d.ts.map +1 -1
- package/dist/types/src/query/query-executor.d.ts +12 -0
- package/dist/types/src/query/query-executor.d.ts.map +1 -1
- package/dist/types/src/query/query-planner.d.ts +2 -0
- package/dist/types/src/query/query-planner.d.ts.map +1 -1
- package/dist/types/src/testing/test-data.d.ts.map +1 -1
- package/dist/types/src/testing/test-schema.d.ts +1 -1
- package/dist/types/src/testing/test-schema.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +37 -39
- package/src/automerge/automerge-host.ts +41 -56
- package/src/automerge/collection-synchronizer.test.ts +4 -3
- package/src/automerge/collection-synchronizer.ts +14 -9
- package/src/db-host/data-service.ts +1 -10
- package/src/db-host/echo-host.ts +1 -3
- package/src/db-host/query-service.ts +2 -1
- package/src/edge/echo-edge-replicator.ts +30 -9
- package/src/filter/filter-match.test.ts +32 -12
- package/src/filter/filter-match.ts +164 -10
- package/src/query/errors.ts +2 -0
- package/src/query/plan.ts +12 -1
- package/src/query/query-executor.ts +148 -4
- package/src/query/query-planner.test.ts +234 -6
- package/src/query/query-planner.ts +87 -12
- package/src/testing/test-data.ts +1 -1
- package/src/testing/test-schema.ts +1 -1
- package/dist/lib/browser/chunk-VUXUDIPM.mjs +0 -126
- package/dist/lib/browser/chunk-VUXUDIPM.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-PGZYXNYE.mjs +0 -126
- package/dist/lib/node-esm/chunk-PGZYXNYE.mjs.map +0 -7
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import "@dxos/node-std/globals";
|
|
2
2
|
import {
|
|
3
3
|
filterMatchObject,
|
|
4
|
+
filterMatchObjectJSON,
|
|
4
5
|
filterMatchValue
|
|
5
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-WJJXJTNS.mjs";
|
|
6
7
|
import {
|
|
7
8
|
AuthExtension,
|
|
8
9
|
AuthStatus,
|
|
@@ -25,7 +26,7 @@ import {
|
|
|
25
26
|
mapTimeframeToFeedIndexes,
|
|
26
27
|
startAfter,
|
|
27
28
|
valueEncoding
|
|
28
|
-
} from "./chunk-
|
|
29
|
+
} from "./chunk-FR6GJ4S4.mjs";
|
|
29
30
|
import "./chunk-CGS2ULMK.mjs";
|
|
30
31
|
|
|
31
32
|
// src/db-host/data-service.ts
|
|
@@ -38,7 +39,6 @@ import { log as log7 } from "@dxos/log";
|
|
|
38
39
|
// src/automerge/automerge-host.ts
|
|
39
40
|
import { getBackend, getHeads, equals as headsEquals, isAutomerge, save } from "@automerge/automerge";
|
|
40
41
|
import { Repo, interpretAsDocumentId } from "@automerge/automerge-repo";
|
|
41
|
-
import { exportBundle } from "@automerge/automerge-repo-bundles";
|
|
42
42
|
import { DeferredTask, Event as Event2, asyncTimeout } from "@dxos/async";
|
|
43
43
|
import { Context, Resource as Resource3, cancelWithContext } from "@dxos/context";
|
|
44
44
|
import { DatabaseDirectory } from "@dxos/echo-protocol";
|
|
@@ -47,28 +47,17 @@ import { PublicKey } from "@dxos/keys";
|
|
|
47
47
|
import { log as log3 } from "@dxos/log";
|
|
48
48
|
import { objectPointerCodec } from "@dxos/protocols";
|
|
49
49
|
import { trace as trace2 } from "@dxos/tracing";
|
|
50
|
-
import { ComplexSet, bufferToArray, range } from "@dxos/util";
|
|
50
|
+
import { ComplexSet, bufferToArray, isNonNullable as isNonNullable2, range } from "@dxos/util";
|
|
51
51
|
|
|
52
52
|
// src/automerge/collection-synchronizer.ts
|
|
53
|
-
import { next as
|
|
53
|
+
import { next as A } from "@automerge/automerge";
|
|
54
|
+
import * as Array2 from "effect/Array";
|
|
55
|
+
import * as Record from "effect/Record";
|
|
54
56
|
import { Event, asyncReturn, scheduleTask, scheduleTaskInterval } from "@dxos/async";
|
|
55
57
|
import { Resource } from "@dxos/context";
|
|
56
58
|
import { log } from "@dxos/log";
|
|
57
59
|
import { trace } from "@dxos/tracing";
|
|
58
60
|
import { defaultMap } from "@dxos/util";
|
|
59
|
-
function _define_property(obj, key, value) {
|
|
60
|
-
if (key in obj) {
|
|
61
|
-
Object.defineProperty(obj, key, {
|
|
62
|
-
value,
|
|
63
|
-
enumerable: true,
|
|
64
|
-
configurable: true,
|
|
65
|
-
writable: true
|
|
66
|
-
});
|
|
67
|
-
} else {
|
|
68
|
-
obj[key] = value;
|
|
69
|
-
}
|
|
70
|
-
return obj;
|
|
71
|
-
}
|
|
72
61
|
function _ts_decorate(decorators, target, key, desc) {
|
|
73
62
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
74
63
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -79,6 +68,22 @@ var __dxlog_file = "/__w/dxos/dxos/packages/core/echo/echo-pipeline/src/automerg
|
|
|
79
68
|
var MIN_QUERY_INTERVAL = 5e3;
|
|
80
69
|
var POLL_INTERVAL = 3e4;
|
|
81
70
|
var CollectionSynchronizer = class extends Resource {
|
|
71
|
+
_sendCollectionState;
|
|
72
|
+
_queryCollectionState;
|
|
73
|
+
_shouldSyncCollection;
|
|
74
|
+
/**
|
|
75
|
+
* CollectionId -> State.
|
|
76
|
+
*/
|
|
77
|
+
_perCollectionStates = /* @__PURE__ */ new Map();
|
|
78
|
+
_activeCollections = /* @__PURE__ */ new Set();
|
|
79
|
+
_connectedPeers = /* @__PURE__ */ new Set();
|
|
80
|
+
remoteStateUpdated = new Event();
|
|
81
|
+
constructor(params) {
|
|
82
|
+
super();
|
|
83
|
+
this._sendCollectionState = params.sendCollectionState;
|
|
84
|
+
this._queryCollectionState = params.queryCollectionState;
|
|
85
|
+
this._shouldSyncCollection = params.shouldSyncCollection;
|
|
86
|
+
}
|
|
82
87
|
async _open(ctx) {
|
|
83
88
|
scheduleTaskInterval(this._ctx, async () => {
|
|
84
89
|
for (const collectionId of this._perCollectionStates.keys()) {
|
|
@@ -104,7 +109,7 @@ var CollectionSynchronizer = class extends Resource {
|
|
|
104
109
|
state
|
|
105
110
|
}, {
|
|
106
111
|
F: __dxlog_file,
|
|
107
|
-
L:
|
|
112
|
+
L: 78,
|
|
108
113
|
S: this,
|
|
109
114
|
C: (f, a) => f(...a)
|
|
110
115
|
});
|
|
@@ -123,7 +128,7 @@ var CollectionSynchronizer = class extends Resource {
|
|
|
123
128
|
collectionId
|
|
124
129
|
}, {
|
|
125
130
|
F: __dxlog_file,
|
|
126
|
-
L:
|
|
131
|
+
L: 92,
|
|
127
132
|
S: this,
|
|
128
133
|
C: (f, a) => f(...a)
|
|
129
134
|
});
|
|
@@ -206,7 +211,7 @@ var CollectionSynchronizer = class extends Resource {
|
|
|
206
211
|
state
|
|
207
212
|
}, {
|
|
208
213
|
F: __dxlog_file,
|
|
209
|
-
L:
|
|
214
|
+
L: 173,
|
|
210
215
|
S: this,
|
|
211
216
|
C: (f, a) => f(...a)
|
|
212
217
|
});
|
|
@@ -257,33 +262,28 @@ var CollectionSynchronizer = class extends Resource {
|
|
|
257
262
|
}
|
|
258
263
|
}
|
|
259
264
|
}
|
|
260
|
-
constructor(params) {
|
|
261
|
-
super(), _define_property(this, "_sendCollectionState", void 0), _define_property(this, "_queryCollectionState", void 0), _define_property(this, "_shouldSyncCollection", void 0), /**
|
|
262
|
-
* CollectionId -> State.
|
|
263
|
-
*/
|
|
264
|
-
_define_property(this, "_perCollectionStates", /* @__PURE__ */ new Map()), _define_property(this, "_activeCollections", /* @__PURE__ */ new Set()), _define_property(this, "_connectedPeers", /* @__PURE__ */ new Set()), _define_property(this, "remoteStateUpdated", new Event());
|
|
265
|
-
this._sendCollectionState = params.sendCollectionState;
|
|
266
|
-
this._queryCollectionState = params.queryCollectionState;
|
|
267
|
-
this._shouldSyncCollection = params.shouldSyncCollection;
|
|
268
|
-
}
|
|
269
265
|
};
|
|
270
266
|
CollectionSynchronizer = _ts_decorate([
|
|
271
267
|
trace.resource()
|
|
272
268
|
], CollectionSynchronizer);
|
|
273
269
|
var diffCollectionState = (local, remote) => {
|
|
274
|
-
const
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
270
|
+
const localDocuments = Record.filter(local.documents, (heads) => heads.length > 0);
|
|
271
|
+
const remoteDocuments = Record.filter(remote.documents, (heads) => heads.length > 0);
|
|
272
|
+
const allDocuments = [
|
|
273
|
+
.../* @__PURE__ */ new Set([
|
|
274
|
+
...Record.keys(localDocuments),
|
|
275
|
+
...Record.keys(remoteDocuments)
|
|
276
|
+
])
|
|
277
|
+
];
|
|
278
278
|
const missingOnRemote = [];
|
|
279
279
|
const missingOnLocal = [];
|
|
280
280
|
const different = [];
|
|
281
281
|
for (const documentId of allDocuments) {
|
|
282
|
-
if (!
|
|
282
|
+
if (!localDocuments[documentId]) {
|
|
283
283
|
missingOnLocal.push(documentId);
|
|
284
|
-
} else if (!
|
|
284
|
+
} else if (!remoteDocuments[documentId]) {
|
|
285
285
|
missingOnRemote.push(documentId);
|
|
286
|
-
} else if (!
|
|
286
|
+
} else if (!A.equals(local.documents[documentId], remote.documents[documentId])) {
|
|
287
287
|
different.push(documentId);
|
|
288
288
|
}
|
|
289
289
|
}
|
|
@@ -298,7 +298,7 @@ var validateCollectionState = (state) => {
|
|
|
298
298
|
if (!isValidDocumentId(documentId)) {
|
|
299
299
|
throw new Error(`Invalid documentId: ${documentId}`);
|
|
300
300
|
}
|
|
301
|
-
if (
|
|
301
|
+
if (Array2.isArray(heads) && heads.some((head) => typeof head !== "string")) {
|
|
302
302
|
throw new Error(`Invalid heads: ${heads}`);
|
|
303
303
|
}
|
|
304
304
|
});
|
|
@@ -324,19 +324,6 @@ var isCollectionQueryMessage = (message) => message.type === MESSAGE_TYPE_COLLEC
|
|
|
324
324
|
var isCollectionStateMessage = (message) => message.type === MESSAGE_TYPE_COLLECTION_STATE;
|
|
325
325
|
|
|
326
326
|
// src/automerge/echo-network-adapter.ts
|
|
327
|
-
function _define_property2(obj, key, value) {
|
|
328
|
-
if (key in obj) {
|
|
329
|
-
Object.defineProperty(obj, key, {
|
|
330
|
-
value,
|
|
331
|
-
enumerable: true,
|
|
332
|
-
configurable: true,
|
|
333
|
-
writable: true
|
|
334
|
-
});
|
|
335
|
-
} else {
|
|
336
|
-
obj[key] = value;
|
|
337
|
-
}
|
|
338
|
-
return obj;
|
|
339
|
-
}
|
|
340
327
|
function _ts_decorate2(decorators, target, key, desc) {
|
|
341
328
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
342
329
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -345,6 +332,18 @@ function _ts_decorate2(decorators, target, key, desc) {
|
|
|
345
332
|
}
|
|
346
333
|
var __dxlog_file2 = "/__w/dxos/dxos/packages/core/echo/echo-pipeline/src/automerge/echo-network-adapter.ts";
|
|
347
334
|
var EchoNetworkAdapter = class extends NetworkAdapter {
|
|
335
|
+
_params;
|
|
336
|
+
_replicators = /* @__PURE__ */ new Set();
|
|
337
|
+
/**
|
|
338
|
+
* Remote peer id -> connection.
|
|
339
|
+
*/
|
|
340
|
+
_connections = /* @__PURE__ */ new Map();
|
|
341
|
+
_lifecycleState = LifecycleState.CLOSED;
|
|
342
|
+
_connected = new Trigger();
|
|
343
|
+
_ready = new Trigger();
|
|
344
|
+
constructor(_params) {
|
|
345
|
+
super(), this._params = _params;
|
|
346
|
+
}
|
|
348
347
|
isReady() {
|
|
349
348
|
return this._lifecycleState === LifecycleState.OPEN;
|
|
350
349
|
}
|
|
@@ -674,12 +673,6 @@ var EchoNetworkAdapter = class extends NetworkAdapter {
|
|
|
674
673
|
peerMetadata: createEchoPeerMetadata()
|
|
675
674
|
});
|
|
676
675
|
}
|
|
677
|
-
constructor(_params) {
|
|
678
|
-
super(), _define_property2(this, "_params", void 0), _define_property2(this, "_replicators", void 0), /**
|
|
679
|
-
* Remote peer id -> connection.
|
|
680
|
-
*/
|
|
681
|
-
_define_property2(this, "_connections", void 0), _define_property2(this, "_lifecycleState", void 0), _define_property2(this, "_connected", void 0), _define_property2(this, "_ready", void 0), this._params = _params, this._replicators = /* @__PURE__ */ new Set(), this._connections = /* @__PURE__ */ new Map(), this._lifecycleState = LifecycleState.CLOSED, this._connected = new Trigger(), this._ready = new Trigger();
|
|
682
|
-
}
|
|
683
676
|
};
|
|
684
677
|
_ts_decorate2([
|
|
685
678
|
synchronized
|
|
@@ -701,20 +694,11 @@ var isEchoPeerMetadata = (metadata) => metadata?.dxos_peerSource === "EchoNetwor
|
|
|
701
694
|
|
|
702
695
|
// src/automerge/heads-store.ts
|
|
703
696
|
import { headsEncoding } from "@dxos/indexing";
|
|
704
|
-
function _define_property3(obj, key, value) {
|
|
705
|
-
if (key in obj) {
|
|
706
|
-
Object.defineProperty(obj, key, {
|
|
707
|
-
value,
|
|
708
|
-
enumerable: true,
|
|
709
|
-
configurable: true,
|
|
710
|
-
writable: true
|
|
711
|
-
});
|
|
712
|
-
} else {
|
|
713
|
-
obj[key] = value;
|
|
714
|
-
}
|
|
715
|
-
return obj;
|
|
716
|
-
}
|
|
717
697
|
var HeadsStore = class {
|
|
698
|
+
_db;
|
|
699
|
+
constructor({ db }) {
|
|
700
|
+
this._db = db;
|
|
701
|
+
}
|
|
718
702
|
setHeads(documentId, heads, batch) {
|
|
719
703
|
batch.put(documentId, heads, {
|
|
720
704
|
sublevel: this._db,
|
|
@@ -729,28 +713,15 @@ var HeadsStore = class {
|
|
|
729
713
|
valueEncoding: headsEncoding
|
|
730
714
|
});
|
|
731
715
|
}
|
|
732
|
-
constructor({ db }) {
|
|
733
|
-
_define_property3(this, "_db", void 0);
|
|
734
|
-
this._db = db;
|
|
735
|
-
}
|
|
736
716
|
};
|
|
737
717
|
|
|
738
718
|
// src/automerge/leveldb-storage-adapter.ts
|
|
739
719
|
import { Resource as Resource2 } from "@dxos/context";
|
|
740
|
-
function _define_property4(obj, key, value) {
|
|
741
|
-
if (key in obj) {
|
|
742
|
-
Object.defineProperty(obj, key, {
|
|
743
|
-
value,
|
|
744
|
-
enumerable: true,
|
|
745
|
-
configurable: true,
|
|
746
|
-
writable: true
|
|
747
|
-
});
|
|
748
|
-
} else {
|
|
749
|
-
obj[key] = value;
|
|
750
|
-
}
|
|
751
|
-
return obj;
|
|
752
|
-
}
|
|
753
720
|
var LevelDBStorageAdapter = class extends Resource2 {
|
|
721
|
+
_params;
|
|
722
|
+
constructor(_params) {
|
|
723
|
+
super(), this._params = _params;
|
|
724
|
+
}
|
|
754
725
|
async load(keyArray) {
|
|
755
726
|
try {
|
|
756
727
|
if (!this.isOpen) {
|
|
@@ -838,9 +809,6 @@ var LevelDBStorageAdapter = class extends Resource2 {
|
|
|
838
809
|
}
|
|
839
810
|
await batch.write();
|
|
840
811
|
}
|
|
841
|
-
constructor(_params) {
|
|
842
|
-
super(), _define_property4(this, "_params", void 0), this._params = _params;
|
|
843
|
-
}
|
|
844
812
|
};
|
|
845
813
|
var keyEncoder = {
|
|
846
814
|
encode: (key) => Buffer.from(key.map((k) => k.replaceAll("%", "%25").replaceAll("-", "%2D")).join("-")),
|
|
@@ -854,19 +822,6 @@ var encodingOptions = {
|
|
|
854
822
|
var isLevelDbNotFoundError = (err) => err.code === "LEVEL_NOT_FOUND";
|
|
855
823
|
|
|
856
824
|
// src/automerge/automerge-host.ts
|
|
857
|
-
function _define_property5(obj, key, value) {
|
|
858
|
-
if (key in obj) {
|
|
859
|
-
Object.defineProperty(obj, key, {
|
|
860
|
-
value,
|
|
861
|
-
enumerable: true,
|
|
862
|
-
configurable: true,
|
|
863
|
-
writable: true
|
|
864
|
-
});
|
|
865
|
-
} else {
|
|
866
|
-
obj[key] = value;
|
|
867
|
-
}
|
|
868
|
-
return obj;
|
|
869
|
-
}
|
|
870
825
|
function _ts_decorate3(decorators, target, key, desc) {
|
|
871
826
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
872
827
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -884,6 +839,57 @@ var BUNDLE_SIZE = 100;
|
|
|
884
839
|
var BUNDLE_SYNC_CONCURRENCY = 2;
|
|
885
840
|
var BUNDLE_SYNC_THRESHOLD = 50;
|
|
886
841
|
var AutomergeHost = class extends Resource3 {
|
|
842
|
+
_db;
|
|
843
|
+
_indexMetadataStore;
|
|
844
|
+
_echoNetworkAdapter;
|
|
845
|
+
_collectionSynchronizer = new CollectionSynchronizer({
|
|
846
|
+
queryCollectionState: this._queryCollectionState.bind(this),
|
|
847
|
+
sendCollectionState: this._sendCollectionState.bind(this),
|
|
848
|
+
shouldSyncCollection: this._shouldSyncCollection.bind(this)
|
|
849
|
+
});
|
|
850
|
+
_repo;
|
|
851
|
+
_storage;
|
|
852
|
+
_headsStore;
|
|
853
|
+
_syncTask = void 0;
|
|
854
|
+
/**
|
|
855
|
+
* Cache of collections that would be synced on next sync task run.
|
|
856
|
+
*/
|
|
857
|
+
_collectionsToSync = new ComplexSet(({ collectionId, peerId }) => `${collectionId}|${peerId}`);
|
|
858
|
+
_peerId;
|
|
859
|
+
_peerIdProvider;
|
|
860
|
+
_getSpaceKeyByRootDocumentId;
|
|
861
|
+
collectionStateUpdated = new Event2();
|
|
862
|
+
/**
|
|
863
|
+
* Fired after a batch of documents was saved to disk.
|
|
864
|
+
*/
|
|
865
|
+
documentsSaved = new Event2();
|
|
866
|
+
_headsUpdates = /* @__PURE__ */ new Map();
|
|
867
|
+
_onHeadsChangedTask;
|
|
868
|
+
constructor({ db, indexMetadataStore, dataMonitor, peerIdProvider, getSpaceKeyByRootDocumentId }) {
|
|
869
|
+
super();
|
|
870
|
+
this._db = db;
|
|
871
|
+
this._storage = new LevelDBStorageAdapter({
|
|
872
|
+
db: db.sublevel("automerge"),
|
|
873
|
+
callbacks: {
|
|
874
|
+
beforeSave: async (params) => this._beforeSave(params),
|
|
875
|
+
afterSave: async (key) => this._afterSave(key)
|
|
876
|
+
},
|
|
877
|
+
monitor: dataMonitor
|
|
878
|
+
});
|
|
879
|
+
this._echoNetworkAdapter = new EchoNetworkAdapter({
|
|
880
|
+
getContainingSpaceForDocument: this._getContainingSpaceForDocument.bind(this),
|
|
881
|
+
isDocumentInRemoteCollection: this._isDocumentInRemoteCollection.bind(this),
|
|
882
|
+
onCollectionStateQueried: this._onCollectionStateQueried.bind(this),
|
|
883
|
+
onCollectionStateReceived: this._onCollectionStateReceived.bind(this),
|
|
884
|
+
monitor: dataMonitor
|
|
885
|
+
});
|
|
886
|
+
this._headsStore = new HeadsStore({
|
|
887
|
+
db: db.sublevel("heads")
|
|
888
|
+
});
|
|
889
|
+
this._indexMetadataStore = indexMetadataStore;
|
|
890
|
+
this._peerIdProvider = peerIdProvider;
|
|
891
|
+
this._getSpaceKeyByRootDocumentId = getSpaceKeyByRootDocumentId;
|
|
892
|
+
}
|
|
887
893
|
async _open() {
|
|
888
894
|
this._peerId = `host-${this._peerIdProvider?.() ?? PublicKey.random().toHex()}`;
|
|
889
895
|
this._onHeadsChangedTask = new DeferredTask(this._ctx, async () => {
|
|
@@ -1086,7 +1092,7 @@ var AutomergeHost = class extends Resource3 {
|
|
|
1086
1092
|
return !(currentHeads !== null && headsEquals(currentHeads, targetHeads));
|
|
1087
1093
|
});
|
|
1088
1094
|
if (headsToWait.length > 0) {
|
|
1089
|
-
await Promise.all(headsToWait.map(async (entry
|
|
1095
|
+
await Promise.all(headsToWait.map(async (entry) => {
|
|
1090
1096
|
const handle = await this.loadDoc(Context.default(void 0, {
|
|
1091
1097
|
F: __dxlog_file3,
|
|
1092
1098
|
L: 346
|
|
@@ -1144,9 +1150,6 @@ var AutomergeHost = class extends Resource3 {
|
|
|
1144
1150
|
// NOTE: If both peers return sharePolicy=false the replication will not happen
|
|
1145
1151
|
// https://github.com/automerge/automerge-repo/pull/292
|
|
1146
1152
|
async _sharePolicy(peerId, documentId) {
|
|
1147
|
-
if (peerId.startsWith("client-")) {
|
|
1148
|
-
return false;
|
|
1149
|
-
}
|
|
1150
1153
|
if (!documentId) {
|
|
1151
1154
|
return false;
|
|
1152
1155
|
}
|
|
@@ -1212,7 +1215,7 @@ var AutomergeHost = class extends Resource3 {
|
|
|
1212
1215
|
this._headsUpdates.set(documentId, heads);
|
|
1213
1216
|
invariant2(this._onHeadsChangedTask, "onHeadsChangedTask is not initialized", {
|
|
1214
1217
|
F: __dxlog_file3,
|
|
1215
|
-
L:
|
|
1218
|
+
L: 445,
|
|
1216
1219
|
S: this,
|
|
1217
1220
|
A: [
|
|
1218
1221
|
"this._onHeadsChangedTask",
|
|
@@ -1256,11 +1259,12 @@ var AutomergeHost = class extends Resource3 {
|
|
|
1256
1259
|
* Flush documents to disk.
|
|
1257
1260
|
*/
|
|
1258
1261
|
async flush({ documentIds } = {}) {
|
|
1259
|
-
const loadedDocuments = documentIds
|
|
1262
|
+
const loadedDocuments = (documentIds ?? Object.keys(this._repo.handles)).filter((documentId) => {
|
|
1260
1263
|
const handle = this._repo.handles[documentId];
|
|
1261
1264
|
return handle && handle.isReady();
|
|
1262
1265
|
});
|
|
1263
1266
|
await this._repo.flush(loadedDocuments);
|
|
1267
|
+
await this._onHeadsChangedTask?.runBlocking();
|
|
1264
1268
|
}
|
|
1265
1269
|
async getHeads(documentIds) {
|
|
1266
1270
|
const result = [];
|
|
@@ -1313,7 +1317,16 @@ var AutomergeHost = class extends Resource3 {
|
|
|
1313
1317
|
missingOnLocal: diff.missingOnLocal.length,
|
|
1314
1318
|
differentDocuments: diff.different.length,
|
|
1315
1319
|
localDocumentCount: Object.entries(localState.documents).filter(([_, heads]) => heads.length > 0).length,
|
|
1316
|
-
remoteDocumentCount: Object.entries(state.documents).filter(([_, heads]) => heads.length > 0).length
|
|
1320
|
+
remoteDocumentCount: Object.entries(state.documents).filter(([_, heads]) => heads.length > 0).length,
|
|
1321
|
+
totalDocumentCount: (/* @__PURE__ */ new Set([
|
|
1322
|
+
...Object.keys(localState.documents),
|
|
1323
|
+
...Object.keys(state.documents)
|
|
1324
|
+
])).size,
|
|
1325
|
+
unsyncedDocumentCount: (/* @__PURE__ */ new Set([
|
|
1326
|
+
...diff.missingOnLocal,
|
|
1327
|
+
...diff.missingOnRemote,
|
|
1328
|
+
...diff.different
|
|
1329
|
+
])).size
|
|
1317
1330
|
});
|
|
1318
1331
|
}
|
|
1319
1332
|
return result;
|
|
@@ -1386,7 +1399,7 @@ var AutomergeHost = class extends Resource3 {
|
|
|
1386
1399
|
amount: missingOnRemote.length
|
|
1387
1400
|
}, {
|
|
1388
1401
|
F: __dxlog_file3,
|
|
1389
|
-
L:
|
|
1402
|
+
L: 650,
|
|
1390
1403
|
S: this,
|
|
1391
1404
|
C: (f, a) => f(...a)
|
|
1392
1405
|
});
|
|
@@ -1399,7 +1412,7 @@ var AutomergeHost = class extends Resource3 {
|
|
|
1399
1412
|
amount: missingOnRemote.length
|
|
1400
1413
|
}, {
|
|
1401
1414
|
F: __dxlog_file3,
|
|
1402
|
-
L:
|
|
1415
|
+
L: 654,
|
|
1403
1416
|
S: this,
|
|
1404
1417
|
C: (f, a) => f(...a)
|
|
1405
1418
|
});
|
|
@@ -1410,7 +1423,7 @@ var AutomergeHost = class extends Resource3 {
|
|
|
1410
1423
|
amount: missingOnLocal.length
|
|
1411
1424
|
}, {
|
|
1412
1425
|
F: __dxlog_file3,
|
|
1413
|
-
L:
|
|
1426
|
+
L: 662,
|
|
1414
1427
|
S: this,
|
|
1415
1428
|
C: (f, a) => f(...a)
|
|
1416
1429
|
});
|
|
@@ -1423,7 +1436,7 @@ var AutomergeHost = class extends Resource3 {
|
|
|
1423
1436
|
amount: missingOnLocal.length
|
|
1424
1437
|
}, {
|
|
1425
1438
|
F: __dxlog_file3,
|
|
1426
|
-
L:
|
|
1439
|
+
L: 666,
|
|
1427
1440
|
S: this,
|
|
1428
1441
|
C: (f, a) => f(...a)
|
|
1429
1442
|
});
|
|
@@ -1439,7 +1452,7 @@ var AutomergeHost = class extends Resource3 {
|
|
|
1439
1452
|
count: toReplicateWithoutBatching.length
|
|
1440
1453
|
}, {
|
|
1441
1454
|
F: __dxlog_file3,
|
|
1442
|
-
L:
|
|
1455
|
+
L: 678,
|
|
1443
1456
|
S: this,
|
|
1444
1457
|
C: (f, a) => f(...a)
|
|
1445
1458
|
});
|
|
@@ -1467,7 +1480,7 @@ var AutomergeHost = class extends Resource3 {
|
|
|
1467
1480
|
err
|
|
1468
1481
|
}, {
|
|
1469
1482
|
F: __dxlog_file3,
|
|
1470
|
-
L:
|
|
1483
|
+
L: 709,
|
|
1471
1484
|
S: this,
|
|
1472
1485
|
C: (f, a) => f(...a)
|
|
1473
1486
|
});
|
|
@@ -1483,13 +1496,38 @@ var AutomergeHost = class extends Resource3 {
|
|
|
1483
1496
|
if (this._ctx.disposed) {
|
|
1484
1497
|
return;
|
|
1485
1498
|
}
|
|
1486
|
-
const
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1499
|
+
const docs = documentIds.map((documentId) => {
|
|
1500
|
+
const handle = this._repo.handles[documentId];
|
|
1501
|
+
if (!handle || !handle.isReady()) {
|
|
1502
|
+
log3.warn("document not ready, skipping", {
|
|
1503
|
+
documentId
|
|
1504
|
+
}, {
|
|
1505
|
+
F: __dxlog_file3,
|
|
1506
|
+
L: 727,
|
|
1507
|
+
S: this,
|
|
1508
|
+
C: (f, a) => f(...a)
|
|
1509
|
+
});
|
|
1510
|
+
return;
|
|
1511
|
+
}
|
|
1512
|
+
const doc = handle.doc();
|
|
1513
|
+
if (!doc) {
|
|
1514
|
+
log3.warn("document not available, skipping", {
|
|
1515
|
+
documentId
|
|
1516
|
+
}, {
|
|
1517
|
+
F: __dxlog_file3,
|
|
1518
|
+
L: 732,
|
|
1519
|
+
S: this,
|
|
1520
|
+
C: (f, a) => f(...a)
|
|
1521
|
+
});
|
|
1522
|
+
return;
|
|
1523
|
+
}
|
|
1524
|
+
return {
|
|
1525
|
+
documentId,
|
|
1526
|
+
data: save(doc),
|
|
1527
|
+
heads: getHeads(doc)
|
|
1528
|
+
};
|
|
1529
|
+
});
|
|
1530
|
+
await this._echoNetworkAdapter.pushBundle(peerId, docs.filter(isNonNullable2));
|
|
1493
1531
|
}
|
|
1494
1532
|
async _pullInBundles(peerId, documentIds) {
|
|
1495
1533
|
const documentsToPull = [
|
|
@@ -1510,7 +1548,7 @@ var AutomergeHost = class extends Resource3 {
|
|
|
1510
1548
|
err
|
|
1511
1549
|
}, {
|
|
1512
1550
|
F: __dxlog_file3,
|
|
1513
|
-
L:
|
|
1551
|
+
L: 762,
|
|
1514
1552
|
S: this,
|
|
1515
1553
|
C: (f, a) => f(...a)
|
|
1516
1554
|
});
|
|
@@ -1548,9 +1586,12 @@ var AutomergeHost = class extends Resource3 {
|
|
|
1548
1586
|
const collectionsChanged = /* @__PURE__ */ new Set();
|
|
1549
1587
|
for (const collectionId of this._collectionSynchronizer.getRegisteredCollectionIds()) {
|
|
1550
1588
|
const state = this._collectionSynchronizer.getLocalCollectionState(collectionId);
|
|
1589
|
+
if (!state) {
|
|
1590
|
+
continue;
|
|
1591
|
+
}
|
|
1551
1592
|
let newState;
|
|
1552
1593
|
for (const [documentId, heads] of docHeads) {
|
|
1553
|
-
if (state
|
|
1594
|
+
if (documentId in state.documents) {
|
|
1554
1595
|
if (!newState) {
|
|
1555
1596
|
newState = structuredClone(state);
|
|
1556
1597
|
}
|
|
@@ -1568,41 +1609,6 @@ var AutomergeHost = class extends Resource3 {
|
|
|
1568
1609
|
});
|
|
1569
1610
|
}
|
|
1570
1611
|
}
|
|
1571
|
-
constructor({ db, indexMetadataStore, dataMonitor, peerIdProvider, getSpaceKeyByRootDocumentId }) {
|
|
1572
|
-
super(), _define_property5(this, "_db", void 0), _define_property5(this, "_indexMetadataStore", void 0), _define_property5(this, "_echoNetworkAdapter", void 0), _define_property5(this, "_collectionSynchronizer", new CollectionSynchronizer({
|
|
1573
|
-
queryCollectionState: this._queryCollectionState.bind(this),
|
|
1574
|
-
sendCollectionState: this._sendCollectionState.bind(this),
|
|
1575
|
-
shouldSyncCollection: this._shouldSyncCollection.bind(this)
|
|
1576
|
-
})), _define_property5(this, "_repo", void 0), _define_property5(this, "_storage", void 0), _define_property5(this, "_headsStore", void 0), _define_property5(this, "_syncTask", void 0), /**
|
|
1577
|
-
* Cache of collections that would be synced on next sync task run.
|
|
1578
|
-
*/
|
|
1579
|
-
_define_property5(this, "_collectionsToSync", new ComplexSet(({ collectionId, peerId }) => `${collectionId}|${peerId}`)), _define_property5(this, "_peerId", void 0), _define_property5(this, "_peerIdProvider", void 0), _define_property5(this, "_getSpaceKeyByRootDocumentId", void 0), _define_property5(this, "collectionStateUpdated", new Event2()), /**
|
|
1580
|
-
* Fired after a batch of documents was saved to disk.
|
|
1581
|
-
*/
|
|
1582
|
-
_define_property5(this, "documentsSaved", new Event2()), _define_property5(this, "_headsUpdates", /* @__PURE__ */ new Map()), _define_property5(this, "_onHeadsChangedTask", void 0);
|
|
1583
|
-
this._db = db;
|
|
1584
|
-
this._storage = new LevelDBStorageAdapter({
|
|
1585
|
-
db: db.sublevel("automerge"),
|
|
1586
|
-
callbacks: {
|
|
1587
|
-
beforeSave: async (params) => this._beforeSave(params),
|
|
1588
|
-
afterSave: async (key) => this._afterSave(key)
|
|
1589
|
-
},
|
|
1590
|
-
monitor: dataMonitor
|
|
1591
|
-
});
|
|
1592
|
-
this._echoNetworkAdapter = new EchoNetworkAdapter({
|
|
1593
|
-
getContainingSpaceForDocument: this._getContainingSpaceForDocument.bind(this),
|
|
1594
|
-
isDocumentInRemoteCollection: this._isDocumentInRemoteCollection.bind(this),
|
|
1595
|
-
onCollectionStateQueried: this._onCollectionStateQueried.bind(this),
|
|
1596
|
-
onCollectionStateReceived: this._onCollectionStateReceived.bind(this),
|
|
1597
|
-
monitor: dataMonitor
|
|
1598
|
-
});
|
|
1599
|
-
this._headsStore = new HeadsStore({
|
|
1600
|
-
db: db.sublevel("heads")
|
|
1601
|
-
});
|
|
1602
|
-
this._indexMetadataStore = indexMetadataStore;
|
|
1603
|
-
this._peerIdProvider = peerIdProvider;
|
|
1604
|
-
this._getSpaceKeyByRootDocumentId = getSpaceKeyByRootDocumentId;
|
|
1605
|
-
}
|
|
1606
1612
|
};
|
|
1607
1613
|
_ts_decorate3([
|
|
1608
1614
|
trace2.info()
|
|
@@ -1638,7 +1644,7 @@ var changeIsPresentInDoc = (doc, changeHash) => {
|
|
|
1638
1644
|
var decodeCollectionState = (state) => {
|
|
1639
1645
|
invariant2(typeof state === "object" && state !== null, "Invalid state", {
|
|
1640
1646
|
F: __dxlog_file3,
|
|
1641
|
-
L:
|
|
1647
|
+
L: 845,
|
|
1642
1648
|
S: void 0,
|
|
1643
1649
|
A: [
|
|
1644
1650
|
"typeof state === 'object' && state !== null",
|
|
@@ -1658,81 +1664,24 @@ import { log as log5 } from "@dxos/log";
|
|
|
1658
1664
|
import { ComplexSet as ComplexSet2, defaultMap as defaultMap2 } from "@dxos/util";
|
|
1659
1665
|
|
|
1660
1666
|
// src/automerge/mesh-echo-replicator-connection.ts
|
|
1661
|
-
import * as
|
|
1667
|
+
import * as A2 from "@automerge/automerge";
|
|
1662
1668
|
import { cbor } from "@automerge/automerge-repo";
|
|
1663
1669
|
import { Resource as Resource4 } from "@dxos/context";
|
|
1664
1670
|
import { invariant as invariant3 } from "@dxos/invariant";
|
|
1665
1671
|
import { log as log4 } from "@dxos/log";
|
|
1666
1672
|
import { AutomergeReplicator } from "@dxos/teleport-extension-automerge-replicator";
|
|
1667
|
-
function _define_property6(obj, key, value) {
|
|
1668
|
-
if (key in obj) {
|
|
1669
|
-
Object.defineProperty(obj, key, {
|
|
1670
|
-
value,
|
|
1671
|
-
enumerable: true,
|
|
1672
|
-
configurable: true,
|
|
1673
|
-
writable: true
|
|
1674
|
-
});
|
|
1675
|
-
} else {
|
|
1676
|
-
obj[key] = value;
|
|
1677
|
-
}
|
|
1678
|
-
return obj;
|
|
1679
|
-
}
|
|
1680
1673
|
var __dxlog_file4 = "/__w/dxos/dxos/packages/core/echo/echo-pipeline/src/automerge/mesh-echo-replicator-connection.ts";
|
|
1681
1674
|
var DEFAULT_FACTORY = (params) => new AutomergeReplicator(...params);
|
|
1682
1675
|
var MeshReplicatorConnection = class extends Resource4 {
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
F: __dxlog_file4,
|
|
1691
|
-
L: 106,
|
|
1692
|
-
S: this,
|
|
1693
|
-
A: [
|
|
1694
|
-
"this._remotePeerId != null",
|
|
1695
|
-
"'Remote peer has not connected yet.'"
|
|
1696
|
-
]
|
|
1697
|
-
});
|
|
1698
|
-
return this._remotePeerId;
|
|
1699
|
-
}
|
|
1700
|
-
get isEnabled() {
|
|
1701
|
-
return this._isEnabled;
|
|
1702
|
-
}
|
|
1703
|
-
get bundleSyncEnabled() {
|
|
1704
|
-
return false;
|
|
1705
|
-
}
|
|
1706
|
-
async shouldAdvertise(params) {
|
|
1707
|
-
return this._params.shouldAdvertise(params);
|
|
1708
|
-
}
|
|
1709
|
-
shouldSyncCollection(params) {
|
|
1710
|
-
return this._params.shouldSyncCollection(params);
|
|
1711
|
-
}
|
|
1712
|
-
/**
|
|
1713
|
-
* Start exchanging messages with the remote peer.
|
|
1714
|
-
* Call after the remote peer has connected.
|
|
1715
|
-
*/
|
|
1716
|
-
enable() {
|
|
1717
|
-
invariant3(this._remotePeerId != null, "Remote peer has not connected yet.", {
|
|
1718
|
-
F: __dxlog_file4,
|
|
1719
|
-
L: 131,
|
|
1720
|
-
S: this,
|
|
1721
|
-
A: [
|
|
1722
|
-
"this._remotePeerId != null",
|
|
1723
|
-
"'Remote peer has not connected yet.'"
|
|
1724
|
-
]
|
|
1725
|
-
});
|
|
1726
|
-
this._isEnabled = true;
|
|
1727
|
-
}
|
|
1728
|
-
/**
|
|
1729
|
-
* Stop exchanging messages with the remote peer.
|
|
1730
|
-
*/
|
|
1731
|
-
disable() {
|
|
1732
|
-
this._isEnabled = false;
|
|
1733
|
-
}
|
|
1676
|
+
_params;
|
|
1677
|
+
readable;
|
|
1678
|
+
writable;
|
|
1679
|
+
remoteDeviceKey = null;
|
|
1680
|
+
replicatorExtension;
|
|
1681
|
+
_remotePeerId = null;
|
|
1682
|
+
_isEnabled = false;
|
|
1734
1683
|
constructor(_params) {
|
|
1735
|
-
super(),
|
|
1684
|
+
super(), this._params = _params;
|
|
1736
1685
|
let readableStreamController;
|
|
1737
1686
|
this.readable = new ReadableStream({
|
|
1738
1687
|
start: (controller) => {
|
|
@@ -1796,10 +1745,61 @@ var MeshReplicatorConnection = class extends Resource4 {
|
|
|
1796
1745
|
}
|
|
1797
1746
|
]);
|
|
1798
1747
|
}
|
|
1748
|
+
_disconnectIfEnabled() {
|
|
1749
|
+
if (this._isEnabled) {
|
|
1750
|
+
this._params.onRemoteDisconnected();
|
|
1751
|
+
}
|
|
1752
|
+
}
|
|
1753
|
+
get peerId() {
|
|
1754
|
+
invariant3(this._remotePeerId != null, "Remote peer has not connected yet.", {
|
|
1755
|
+
F: __dxlog_file4,
|
|
1756
|
+
L: 106,
|
|
1757
|
+
S: this,
|
|
1758
|
+
A: [
|
|
1759
|
+
"this._remotePeerId != null",
|
|
1760
|
+
"'Remote peer has not connected yet.'"
|
|
1761
|
+
]
|
|
1762
|
+
});
|
|
1763
|
+
return this._remotePeerId;
|
|
1764
|
+
}
|
|
1765
|
+
get isEnabled() {
|
|
1766
|
+
return this._isEnabled;
|
|
1767
|
+
}
|
|
1768
|
+
get bundleSyncEnabled() {
|
|
1769
|
+
return false;
|
|
1770
|
+
}
|
|
1771
|
+
async shouldAdvertise(params) {
|
|
1772
|
+
return this._params.shouldAdvertise(params);
|
|
1773
|
+
}
|
|
1774
|
+
shouldSyncCollection(params) {
|
|
1775
|
+
return this._params.shouldSyncCollection(params);
|
|
1776
|
+
}
|
|
1777
|
+
/**
|
|
1778
|
+
* Start exchanging messages with the remote peer.
|
|
1779
|
+
* Call after the remote peer has connected.
|
|
1780
|
+
*/
|
|
1781
|
+
enable() {
|
|
1782
|
+
invariant3(this._remotePeerId != null, "Remote peer has not connected yet.", {
|
|
1783
|
+
F: __dxlog_file4,
|
|
1784
|
+
L: 131,
|
|
1785
|
+
S: this,
|
|
1786
|
+
A: [
|
|
1787
|
+
"this._remotePeerId != null",
|
|
1788
|
+
"'Remote peer has not connected yet.'"
|
|
1789
|
+
]
|
|
1790
|
+
});
|
|
1791
|
+
this._isEnabled = true;
|
|
1792
|
+
}
|
|
1793
|
+
/**
|
|
1794
|
+
* Stop exchanging messages with the remote peer.
|
|
1795
|
+
*/
|
|
1796
|
+
disable() {
|
|
1797
|
+
this._isEnabled = false;
|
|
1798
|
+
}
|
|
1799
1799
|
};
|
|
1800
1800
|
var logSendSync = (message) => {
|
|
1801
1801
|
log4("sendSyncMessage", () => {
|
|
1802
|
-
const decodedSyncMessage = message.type === "sync" && message.data ?
|
|
1802
|
+
const decodedSyncMessage = message.type === "sync" && message.data ? A2.decodeSyncMessage(message.data) : void 0;
|
|
1803
1803
|
return {
|
|
1804
1804
|
sync: decodedSyncMessage && {
|
|
1805
1805
|
headsLength: decodedSyncMessage.heads.length,
|
|
@@ -1838,21 +1838,24 @@ var getSpaceIdFromCollectionId = (collectionId) => {
|
|
|
1838
1838
|
};
|
|
1839
1839
|
|
|
1840
1840
|
// src/automerge/mesh-echo-replicator.ts
|
|
1841
|
-
function _define_property7(obj, key, value) {
|
|
1842
|
-
if (key in obj) {
|
|
1843
|
-
Object.defineProperty(obj, key, {
|
|
1844
|
-
value,
|
|
1845
|
-
enumerable: true,
|
|
1846
|
-
configurable: true,
|
|
1847
|
-
writable: true
|
|
1848
|
-
});
|
|
1849
|
-
} else {
|
|
1850
|
-
obj[key] = value;
|
|
1851
|
-
}
|
|
1852
|
-
return obj;
|
|
1853
|
-
}
|
|
1854
1841
|
var __dxlog_file6 = "/__w/dxos/dxos/packages/core/echo/echo-pipeline/src/automerge/mesh-echo-replicator.ts";
|
|
1855
1842
|
var MeshEchoReplicator = class {
|
|
1843
|
+
/**
|
|
1844
|
+
* We might have multiple connections open with a peer (one per space), but there'll be only one enabled
|
|
1845
|
+
* connection at any given moment, because there's a single repo for all the spaces.
|
|
1846
|
+
* When a connection closes (space was closed) it gets removed from the list and the next connection
|
|
1847
|
+
* in the line gets enabled.
|
|
1848
|
+
*/
|
|
1849
|
+
_connectionsPerPeer = /* @__PURE__ */ new Map();
|
|
1850
|
+
/**
|
|
1851
|
+
* A set of all connections (enabled and disabled).
|
|
1852
|
+
*/
|
|
1853
|
+
_connections = /* @__PURE__ */ new Set();
|
|
1854
|
+
/**
|
|
1855
|
+
* spaceId -> deviceKey[]
|
|
1856
|
+
*/
|
|
1857
|
+
_authorizedDevices = /* @__PURE__ */ new Map();
|
|
1858
|
+
_context = null;
|
|
1856
1859
|
async connect(context) {
|
|
1857
1860
|
this._context = context;
|
|
1858
1861
|
}
|
|
@@ -2065,30 +2068,11 @@ var MeshEchoReplicator = class {
|
|
|
2065
2068
|
}
|
|
2066
2069
|
}
|
|
2067
2070
|
}
|
|
2068
|
-
constructor() {
|
|
2069
|
-
_define_property7(this, "_connectionsPerPeer", /* @__PURE__ */ new Map());
|
|
2070
|
-
_define_property7(this, "_connections", /* @__PURE__ */ new Set());
|
|
2071
|
-
_define_property7(this, "_authorizedDevices", /* @__PURE__ */ new Map());
|
|
2072
|
-
_define_property7(this, "_context", null);
|
|
2073
|
-
}
|
|
2074
2071
|
};
|
|
2075
2072
|
|
|
2076
2073
|
// src/automerge/echo-data-monitor.ts
|
|
2077
2074
|
import { trace as trace3 } from "@dxos/tracing";
|
|
2078
2075
|
import { CircularBuffer, SlidingWindowSummary, mapValues } from "@dxos/util";
|
|
2079
|
-
function _define_property8(obj, key, value) {
|
|
2080
|
-
if (key in obj) {
|
|
2081
|
-
Object.defineProperty(obj, key, {
|
|
2082
|
-
value,
|
|
2083
|
-
enumerable: true,
|
|
2084
|
-
configurable: true,
|
|
2085
|
-
writable: true
|
|
2086
|
-
});
|
|
2087
|
-
} else {
|
|
2088
|
-
obj[key] = value;
|
|
2089
|
-
}
|
|
2090
|
-
return obj;
|
|
2091
|
-
}
|
|
2092
2076
|
function _ts_decorate4(decorators, target, key, desc) {
|
|
2093
2077
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
2094
2078
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -2098,6 +2082,22 @@ function _ts_decorate4(decorators, target, key, desc) {
|
|
|
2098
2082
|
var PER_SECOND_RATE_AVG_WINDOW_SIZE = 5;
|
|
2099
2083
|
var DEFAULT_AVG_WINDOW_SIZE = 25;
|
|
2100
2084
|
var EchoDataMonitor = class {
|
|
2085
|
+
_params;
|
|
2086
|
+
_lastTick = 0;
|
|
2087
|
+
_activeCounters = createLocalCounters();
|
|
2088
|
+
_lastCompleteCounters;
|
|
2089
|
+
_localTimeSeries = createLocalTimeSeries();
|
|
2090
|
+
_storageAverages = createStorageAverages();
|
|
2091
|
+
_replicationAverages = createNetworkAverages();
|
|
2092
|
+
_sizeByMessage = {};
|
|
2093
|
+
_lastReceivedMessages = new CircularBuffer(100);
|
|
2094
|
+
_lastSentMessages = new CircularBuffer(100);
|
|
2095
|
+
_connectionsCount = 0;
|
|
2096
|
+
constructor(_params = {
|
|
2097
|
+
timeSeriesLength: 30
|
|
2098
|
+
}) {
|
|
2099
|
+
this._params = _params;
|
|
2100
|
+
}
|
|
2101
2101
|
tick(timeMs) {
|
|
2102
2102
|
this._advanceTimeWindow(timeMs - this._lastTick);
|
|
2103
2103
|
this._lastTick = timeMs;
|
|
@@ -2337,9 +2337,8 @@ var EchoDataMonitor = class {
|
|
|
2337
2337
|
messageCounts.failed++;
|
|
2338
2338
|
}
|
|
2339
2339
|
_getStatsForType(message) {
|
|
2340
|
-
|
|
2341
|
-
const
|
|
2342
|
-
const messageCounts = (_this__activeCounters_byType = this._activeCounters.byType)[_message_type1 = message.type] ?? (_this__activeCounters_byType[_message_type1] = createMessageCounter());
|
|
2340
|
+
const messageSize = this._sizeByMessage[message.type] ??= createSlidingWindow();
|
|
2341
|
+
const messageCounts = this._activeCounters.byType[message.type] ??= createMessageCounter();
|
|
2343
2342
|
return {
|
|
2344
2343
|
messageCounts,
|
|
2345
2344
|
messageSize
|
|
@@ -2348,48 +2347,21 @@ var EchoDataMonitor = class {
|
|
|
2348
2347
|
_computeMessageHistogram(groupKey) {
|
|
2349
2348
|
const result = {};
|
|
2350
2349
|
for (const receivedMessage of this._lastReceivedMessages) {
|
|
2351
|
-
|
|
2352
|
-
const counters = (_result = result)[_receivedMessage_groupKey = receivedMessage[groupKey]] ?? (_result[_receivedMessage_groupKey] = {
|
|
2350
|
+
const counters = result[receivedMessage[groupKey]] ??= {
|
|
2353
2351
|
received: 0,
|
|
2354
2352
|
sent: 0
|
|
2355
|
-
}
|
|
2353
|
+
};
|
|
2356
2354
|
counters.received++;
|
|
2357
2355
|
}
|
|
2358
2356
|
for (const receivedMessage of this._lastSentMessages) {
|
|
2359
|
-
|
|
2360
|
-
const counters = (_result1 = result)[_receivedMessage_groupKey1 = receivedMessage[groupKey]] ?? (_result1[_receivedMessage_groupKey1] = {
|
|
2357
|
+
const counters = result[receivedMessage[groupKey]] ??= {
|
|
2361
2358
|
received: 0,
|
|
2362
2359
|
sent: 0
|
|
2363
|
-
}
|
|
2360
|
+
};
|
|
2364
2361
|
counters.sent++;
|
|
2365
2362
|
}
|
|
2366
2363
|
return result;
|
|
2367
2364
|
}
|
|
2368
|
-
constructor(_params = {
|
|
2369
|
-
timeSeriesLength: 30
|
|
2370
|
-
}) {
|
|
2371
|
-
_define_property8(this, "_params", void 0);
|
|
2372
|
-
_define_property8(this, "_lastTick", void 0);
|
|
2373
|
-
_define_property8(this, "_activeCounters", void 0);
|
|
2374
|
-
_define_property8(this, "_lastCompleteCounters", void 0);
|
|
2375
|
-
_define_property8(this, "_localTimeSeries", void 0);
|
|
2376
|
-
_define_property8(this, "_storageAverages", void 0);
|
|
2377
|
-
_define_property8(this, "_replicationAverages", void 0);
|
|
2378
|
-
_define_property8(this, "_sizeByMessage", void 0);
|
|
2379
|
-
_define_property8(this, "_lastReceivedMessages", void 0);
|
|
2380
|
-
_define_property8(this, "_lastSentMessages", void 0);
|
|
2381
|
-
_define_property8(this, "_connectionsCount", void 0);
|
|
2382
|
-
this._params = _params;
|
|
2383
|
-
this._lastTick = 0;
|
|
2384
|
-
this._activeCounters = createLocalCounters();
|
|
2385
|
-
this._localTimeSeries = createLocalTimeSeries();
|
|
2386
|
-
this._storageAverages = createStorageAverages();
|
|
2387
|
-
this._replicationAverages = createNetworkAverages();
|
|
2388
|
-
this._sizeByMessage = {};
|
|
2389
|
-
this._lastReceivedMessages = new CircularBuffer(100);
|
|
2390
|
-
this._lastSentMessages = new CircularBuffer(100);
|
|
2391
|
-
this._connectionsCount = 0;
|
|
2392
|
-
}
|
|
2393
2365
|
};
|
|
2394
2366
|
EchoDataMonitor = _ts_decorate4([
|
|
2395
2367
|
trace3.resource()
|
|
@@ -2462,29 +2434,30 @@ var getByteCount = (message) => {
|
|
|
2462
2434
|
};
|
|
2463
2435
|
|
|
2464
2436
|
// src/db-host/documents-synchronizer.ts
|
|
2465
|
-
import { next as
|
|
2437
|
+
import { next as A3 } from "@automerge/automerge";
|
|
2466
2438
|
import { UpdateScheduler, sleep } from "@dxos/async";
|
|
2467
2439
|
import { LifecycleState as LifecycleState2, Resource as Resource5, cancelWithContext as cancelWithContext2 } from "@dxos/context";
|
|
2468
2440
|
import { invariant as invariant6 } from "@dxos/invariant";
|
|
2469
2441
|
import { log as log6 } from "@dxos/log";
|
|
2470
|
-
function _define_property9(obj, key, value) {
|
|
2471
|
-
if (key in obj) {
|
|
2472
|
-
Object.defineProperty(obj, key, {
|
|
2473
|
-
value,
|
|
2474
|
-
enumerable: true,
|
|
2475
|
-
configurable: true,
|
|
2476
|
-
writable: true
|
|
2477
|
-
});
|
|
2478
|
-
} else {
|
|
2479
|
-
obj[key] = value;
|
|
2480
|
-
}
|
|
2481
|
-
return obj;
|
|
2482
|
-
}
|
|
2483
2442
|
var __dxlog_file7 = "/__w/dxos/dxos/packages/core/echo/echo-pipeline/src/db-host/documents-synchronizer.ts";
|
|
2484
2443
|
var MAX_UPDATE_FREQ = 10;
|
|
2485
2444
|
var WRAP_AROUND_RETRY_LIMIT = 3;
|
|
2486
2445
|
var WRAP_AROUND_RETRY_INITIAL_DELAY = 100;
|
|
2487
2446
|
var DocumentsSynchronizer = class extends Resource5 {
|
|
2447
|
+
_params;
|
|
2448
|
+
_syncStates = /* @__PURE__ */ new Map();
|
|
2449
|
+
/**
|
|
2450
|
+
* Documents that have pending updates.
|
|
2451
|
+
* Used to batch updates.
|
|
2452
|
+
*/
|
|
2453
|
+
_pendingUpdates = /* @__PURE__ */ new Set();
|
|
2454
|
+
/**
|
|
2455
|
+
* Job that schedules if there are pending updates.
|
|
2456
|
+
*/
|
|
2457
|
+
_sendUpdatesJob = void 0;
|
|
2458
|
+
constructor(_params) {
|
|
2459
|
+
super(), this._params = _params;
|
|
2460
|
+
}
|
|
2488
2461
|
addDocuments(documentIds, retryCounter = 0, wrapAroundRetryDelay = WRAP_AROUND_RETRY_INITIAL_DELAY) {
|
|
2489
2462
|
if (retryCounter > WRAP_AROUND_RETRY_LIMIT) {
|
|
2490
2463
|
log6.warn("Failed to load document, retry limit reached", {
|
|
@@ -2603,11 +2576,11 @@ var DocumentsSynchronizer = class extends Resource5 {
|
|
|
2603
2576
|
return;
|
|
2604
2577
|
}
|
|
2605
2578
|
const doc = handle.doc();
|
|
2606
|
-
const mutation = syncState.lastSentHead ?
|
|
2579
|
+
const mutation = syncState.lastSentHead ? A3.saveSince(doc, syncState.lastSentHead) : A3.save(doc);
|
|
2607
2580
|
if (mutation.length === 0) {
|
|
2608
2581
|
return;
|
|
2609
2582
|
}
|
|
2610
|
-
syncState.lastSentHead =
|
|
2583
|
+
syncState.lastSentHead = A3.getHeads(doc);
|
|
2611
2584
|
return mutation;
|
|
2612
2585
|
}
|
|
2613
2586
|
_writeMutation(documentId, mutation, isNew) {
|
|
@@ -2619,7 +2592,7 @@ var DocumentsSynchronizer = class extends Resource5 {
|
|
|
2619
2592
|
docId: documentId
|
|
2620
2593
|
});
|
|
2621
2594
|
const syncState = this._startSync(newHandle);
|
|
2622
|
-
syncState.lastSentHead =
|
|
2595
|
+
syncState.lastSentHead = A3.getHeads(newHandle.doc());
|
|
2623
2596
|
} else {
|
|
2624
2597
|
const syncState = this._syncStates.get(documentId);
|
|
2625
2598
|
invariant6(syncState, "Sync state for document not found", {
|
|
@@ -2631,43 +2604,33 @@ var DocumentsSynchronizer = class extends Resource5 {
|
|
|
2631
2604
|
"'Sync state for document not found'"
|
|
2632
2605
|
]
|
|
2633
2606
|
});
|
|
2634
|
-
const headsBefore =
|
|
2607
|
+
const headsBefore = A3.getHeads(syncState.handle.doc());
|
|
2635
2608
|
this._params.repo.import(mutation, {
|
|
2636
2609
|
docId: documentId
|
|
2637
2610
|
});
|
|
2638
|
-
if (
|
|
2639
|
-
syncState.lastSentHead =
|
|
2611
|
+
if (A3.equals(headsBefore, syncState.lastSentHead)) {
|
|
2612
|
+
syncState.lastSentHead = A3.getHeads(syncState.handle.doc());
|
|
2640
2613
|
}
|
|
2641
2614
|
}
|
|
2642
2615
|
}
|
|
2643
|
-
constructor(_params) {
|
|
2644
|
-
super(), _define_property9(this, "_params", void 0), _define_property9(this, "_syncStates", void 0), /**
|
|
2645
|
-
* Documents that have pending updates.
|
|
2646
|
-
* Used to batch updates.
|
|
2647
|
-
*/
|
|
2648
|
-
_define_property9(this, "_pendingUpdates", void 0), /**
|
|
2649
|
-
* Job that schedules if there are pending updates.
|
|
2650
|
-
*/
|
|
2651
|
-
_define_property9(this, "_sendUpdatesJob", void 0), this._params = _params, this._syncStates = /* @__PURE__ */ new Map(), this._pendingUpdates = /* @__PURE__ */ new Set(), this._sendUpdatesJob = void 0;
|
|
2652
|
-
}
|
|
2653
2616
|
};
|
|
2654
2617
|
|
|
2655
2618
|
// src/db-host/data-service.ts
|
|
2656
|
-
function _define_property10(obj, key, value) {
|
|
2657
|
-
if (key in obj) {
|
|
2658
|
-
Object.defineProperty(obj, key, {
|
|
2659
|
-
value,
|
|
2660
|
-
enumerable: true,
|
|
2661
|
-
configurable: true,
|
|
2662
|
-
writable: true
|
|
2663
|
-
});
|
|
2664
|
-
} else {
|
|
2665
|
-
obj[key] = value;
|
|
2666
|
-
}
|
|
2667
|
-
return obj;
|
|
2668
|
-
}
|
|
2669
2619
|
var __dxlog_file8 = "/__w/dxos/dxos/packages/core/echo/echo-pipeline/src/db-host/data-service.ts";
|
|
2670
2620
|
var DataServiceImpl = class {
|
|
2621
|
+
/**
|
|
2622
|
+
* Map of subscriptions.
|
|
2623
|
+
* subscriptionId -> DocumentsSynchronizer
|
|
2624
|
+
*/
|
|
2625
|
+
_subscriptions = /* @__PURE__ */ new Map();
|
|
2626
|
+
_automergeHost;
|
|
2627
|
+
_spaceStateManager;
|
|
2628
|
+
_updateIndexes;
|
|
2629
|
+
constructor(params) {
|
|
2630
|
+
this._automergeHost = params.automergeHost;
|
|
2631
|
+
this._spaceStateManager = params.spaceStateManager;
|
|
2632
|
+
this._updateIndexes = params.updateIndexes;
|
|
2633
|
+
}
|
|
2671
2634
|
subscribe(request) {
|
|
2672
2635
|
return new Stream(({ next, ready }) => {
|
|
2673
2636
|
const synchronizer = new DocumentsSynchronizer({
|
|
@@ -2777,14 +2740,7 @@ var DataServiceImpl = class {
|
|
|
2777
2740
|
peers: []
|
|
2778
2741
|
};
|
|
2779
2742
|
next({
|
|
2780
|
-
peers: state.peers
|
|
2781
|
-
peerId: peer.peerId,
|
|
2782
|
-
missingOnRemote: peer.missingOnRemote,
|
|
2783
|
-
missingOnLocal: peer.missingOnLocal,
|
|
2784
|
-
differentDocuments: peer.differentDocuments,
|
|
2785
|
-
localDocumentCount: peer.localDocumentCount,
|
|
2786
|
-
remoteDocumentCount: peer.remoteDocumentCount
|
|
2787
|
-
}))
|
|
2743
|
+
peers: state.peers
|
|
2788
2744
|
});
|
|
2789
2745
|
});
|
|
2790
2746
|
this._automergeHost.collectionStateUpdated.on(ctx, (e) => {
|
|
@@ -2795,15 +2751,6 @@ var DataServiceImpl = class {
|
|
|
2795
2751
|
scheduler.trigger();
|
|
2796
2752
|
});
|
|
2797
2753
|
}
|
|
2798
|
-
constructor(params) {
|
|
2799
|
-
_define_property10(this, "_subscriptions", /* @__PURE__ */ new Map());
|
|
2800
|
-
_define_property10(this, "_automergeHost", void 0);
|
|
2801
|
-
_define_property10(this, "_spaceStateManager", void 0);
|
|
2802
|
-
_define_property10(this, "_updateIndexes", void 0);
|
|
2803
|
-
this._automergeHost = params.automergeHost;
|
|
2804
|
-
this._spaceStateManager = params.spaceStateManager;
|
|
2805
|
-
this._updateIndexes = params.updateIndexes;
|
|
2806
|
-
}
|
|
2807
2754
|
};
|
|
2808
2755
|
|
|
2809
2756
|
// src/db-host/echo-host.ts
|
|
@@ -2816,7 +2763,7 @@ import { IndexKind } from "@dxos/protocols/proto/dxos/echo/indexing";
|
|
|
2816
2763
|
import { trace as trace5 } from "@dxos/tracing";
|
|
2817
2764
|
|
|
2818
2765
|
// src/db-host/documents-iterator.ts
|
|
2819
|
-
import * as
|
|
2766
|
+
import * as A4 from "@automerge/automerge";
|
|
2820
2767
|
import { Context as Context2 } from "@dxos/context";
|
|
2821
2768
|
import { DatabaseDirectory as DatabaseDirectory2, SpaceDocVersion } from "@dxos/echo-protocol";
|
|
2822
2769
|
import { invariant as invariant8 } from "@dxos/invariant";
|
|
@@ -2847,10 +2794,10 @@ var createSelectedDocumentsIterator = (automergeHost) => (
|
|
|
2847
2794
|
""
|
|
2848
2795
|
]
|
|
2849
2796
|
});
|
|
2850
|
-
const currentHeads =
|
|
2851
|
-
if (!
|
|
2797
|
+
const currentHeads = A4.getHeads(doc);
|
|
2798
|
+
if (!A4.equals(currentHeads, heads)) {
|
|
2852
2799
|
const begin = Date.now();
|
|
2853
|
-
doc =
|
|
2800
|
+
doc = A4.view(doc, heads);
|
|
2854
2801
|
const end = Date.now();
|
|
2855
2802
|
if (end - begin > LOG_VIEW_OPERATION_THRESHOLD) {
|
|
2856
2803
|
log8("Checking out document version is taking too long", {
|
|
@@ -2905,7 +2852,7 @@ var createSelectedDocumentsIterator = (automergeHost) => (
|
|
|
2905
2852
|
|
|
2906
2853
|
// src/db-host/query-service.ts
|
|
2907
2854
|
import { getHeads as getHeads3 } from "@automerge/automerge";
|
|
2908
|
-
import
|
|
2855
|
+
import * as Schema from "effect/Schema";
|
|
2909
2856
|
import { DeferredTask as DeferredTask2, scheduleMicroTask, synchronized as synchronized2 } from "@dxos/async";
|
|
2910
2857
|
import { Stream as Stream2 } from "@dxos/codec-protobuf/stream";
|
|
2911
2858
|
import { Context as Context4, Resource as Resource7 } from "@dxos/context";
|
|
@@ -2916,7 +2863,8 @@ import { objectPointerCodec as objectPointerCodec4 } from "@dxos/protocols";
|
|
|
2916
2863
|
import { trace as trace4 } from "@dxos/tracing";
|
|
2917
2864
|
|
|
2918
2865
|
// src/query/query-executor.ts
|
|
2919
|
-
import
|
|
2866
|
+
import * as Match from "effect/Match";
|
|
2867
|
+
import * as Predicate from "effect/Predicate";
|
|
2920
2868
|
import { Context as Context3, ContextDisposedError, LifecycleState as LifecycleState3, Resource as Resource6 } from "@dxos/context";
|
|
2921
2869
|
import { DatabaseDirectory as DatabaseDirectory3, ObjectStructure, isEncodedReference } from "@dxos/echo-protocol";
|
|
2922
2870
|
import { EscapedPropPath } from "@dxos/indexing";
|
|
@@ -2924,15 +2872,18 @@ import { invariant as invariant10 } from "@dxos/invariant";
|
|
|
2924
2872
|
import { DXN, PublicKey as PublicKey3 } from "@dxos/keys";
|
|
2925
2873
|
import { log as log9 } from "@dxos/log";
|
|
2926
2874
|
import { objectPointerCodec as objectPointerCodec3 } from "@dxos/protocols";
|
|
2927
|
-
import { getDeep, isNonNullable as
|
|
2875
|
+
import { getDeep, isNonNullable as isNonNullable3 } from "@dxos/util";
|
|
2928
2876
|
|
|
2929
2877
|
// src/query/query-planner.ts
|
|
2878
|
+
import { Order } from "@dxos/echo";
|
|
2930
2879
|
import { invariant as invariant9 } from "@dxos/invariant";
|
|
2931
2880
|
|
|
2932
2881
|
// src/query/errors.ts
|
|
2933
2882
|
import { BaseError } from "@dxos/errors";
|
|
2934
2883
|
var QueryError = class extends BaseError.extend("QUERY_ERROR") {
|
|
2935
2884
|
};
|
|
2885
|
+
var InvalidQueryError = class extends QueryError.extend("INVALID_QUERY") {
|
|
2886
|
+
};
|
|
2936
2887
|
|
|
2937
2888
|
// src/query/plan.ts
|
|
2938
2889
|
(function(QueryPlan2) {
|
|
@@ -2956,24 +2907,18 @@ var QueryError = class extends BaseError.extend("QUERY_ERROR") {
|
|
|
2956
2907
|
var QueryPlan;
|
|
2957
2908
|
|
|
2958
2909
|
// src/query/query-planner.ts
|
|
2959
|
-
function _define_property11(obj, key, value) {
|
|
2960
|
-
if (key in obj) {
|
|
2961
|
-
Object.defineProperty(obj, key, {
|
|
2962
|
-
value,
|
|
2963
|
-
enumerable: true,
|
|
2964
|
-
configurable: true,
|
|
2965
|
-
writable: true
|
|
2966
|
-
});
|
|
2967
|
-
} else {
|
|
2968
|
-
obj[key] = value;
|
|
2969
|
-
}
|
|
2970
|
-
return obj;
|
|
2971
|
-
}
|
|
2972
2910
|
var __dxlog_file10 = "/__w/dxos/dxos/packages/core/echo/echo-pipeline/src/query/query-planner.ts";
|
|
2973
2911
|
var DEFAULT_OPTIONS = {
|
|
2974
2912
|
defaultTextSearchKind: "full-text"
|
|
2975
2913
|
};
|
|
2976
2914
|
var QueryPlanner = class {
|
|
2915
|
+
_options;
|
|
2916
|
+
constructor(options) {
|
|
2917
|
+
this._options = {
|
|
2918
|
+
...DEFAULT_OPTIONS,
|
|
2919
|
+
...options
|
|
2920
|
+
};
|
|
2921
|
+
}
|
|
2977
2922
|
createPlan(query) {
|
|
2978
2923
|
let plan = this._generate(query, {
|
|
2979
2924
|
...DEFAULT_CONTEXT,
|
|
@@ -2981,6 +2926,7 @@ var QueryPlanner = class {
|
|
|
2981
2926
|
});
|
|
2982
2927
|
plan = this._optimizeEmptyFilters(plan);
|
|
2983
2928
|
plan = this._optimizeSoloUnions(plan);
|
|
2929
|
+
plan = this._ensureOrderStep(plan);
|
|
2984
2930
|
return plan;
|
|
2985
2931
|
}
|
|
2986
2932
|
_generate(query, context) {
|
|
@@ -3003,8 +2949,11 @@ var QueryPlanner = class {
|
|
|
3003
2949
|
return this._generateUnionClause(query, context);
|
|
3004
2950
|
case "set-difference":
|
|
3005
2951
|
return this._generateSetDifferenceClause(query, context);
|
|
2952
|
+
case "order":
|
|
2953
|
+
return this._generateOrderClause(query, context);
|
|
3006
2954
|
default:
|
|
3007
|
-
throw new QueryError(
|
|
2955
|
+
throw new QueryError({
|
|
2956
|
+
message: `Unsupported query type: ${query.type}`,
|
|
3008
2957
|
context: {
|
|
3009
2958
|
query: context.originalQuery
|
|
3010
2959
|
}
|
|
@@ -3028,10 +2977,11 @@ var QueryPlanner = class {
|
|
|
3028
2977
|
}
|
|
3029
2978
|
// TODO(dmaretskyi): This can be rewritten as a function of (filter[]) -> (selection ? undefined, rest: filter[]) that recurses onto itself.
|
|
3030
2979
|
// TODO(dmaretskyi): If the tip of the query ast is a [select, ...filter] shape we can reorder the filters so the query is most efficient.
|
|
3031
|
-
_generateSelectionFromFilter(
|
|
3032
|
-
switch (
|
|
2980
|
+
_generateSelectionFromFilter(filter2, context) {
|
|
2981
|
+
switch (filter2.type) {
|
|
2982
|
+
// Props
|
|
3033
2983
|
case "object": {
|
|
3034
|
-
if (context.selectionInverted &&
|
|
2984
|
+
if (context.selectionInverted && filter2.id === void 0 && filter2.typename === null && Object.keys(filter2.props).length === 0) {
|
|
3035
2985
|
return QueryPlan.Plan.make([
|
|
3036
2986
|
{
|
|
3037
2987
|
_tag: "ClearWorkingSetStep"
|
|
@@ -3040,32 +2990,33 @@ var QueryPlanner = class {
|
|
|
3040
2990
|
]);
|
|
3041
2991
|
}
|
|
3042
2992
|
if (context.selectionInverted) {
|
|
3043
|
-
throw new QueryError(
|
|
2993
|
+
throw new QueryError({
|
|
2994
|
+
message: "Query too complex",
|
|
3044
2995
|
context: {
|
|
3045
2996
|
query: context.originalQuery
|
|
3046
2997
|
}
|
|
3047
2998
|
});
|
|
3048
2999
|
}
|
|
3049
|
-
if (
|
|
3000
|
+
if (filter2.id && filter2.id?.length > 0) {
|
|
3050
3001
|
return QueryPlan.Plan.make([
|
|
3051
3002
|
{
|
|
3052
3003
|
_tag: "SelectStep",
|
|
3053
3004
|
spaces: context.selectionSpaces,
|
|
3054
3005
|
selector: {
|
|
3055
3006
|
_tag: "IdSelector",
|
|
3056
|
-
objectIds:
|
|
3007
|
+
objectIds: filter2.id
|
|
3057
3008
|
}
|
|
3058
3009
|
},
|
|
3059
3010
|
...this._generateDeletedHandlingSteps(context),
|
|
3060
3011
|
{
|
|
3061
3012
|
_tag: "FilterStep",
|
|
3062
3013
|
filter: {
|
|
3063
|
-
...
|
|
3014
|
+
...filter2,
|
|
3064
3015
|
id: void 0
|
|
3065
3016
|
}
|
|
3066
3017
|
}
|
|
3067
3018
|
]);
|
|
3068
|
-
} else if (
|
|
3019
|
+
} else if (filter2.typename) {
|
|
3069
3020
|
return QueryPlan.Plan.make([
|
|
3070
3021
|
{
|
|
3071
3022
|
_tag: "SelectStep",
|
|
@@ -3073,17 +3024,17 @@ var QueryPlanner = class {
|
|
|
3073
3024
|
selector: {
|
|
3074
3025
|
_tag: "TypeSelector",
|
|
3075
3026
|
typename: [
|
|
3076
|
-
|
|
3027
|
+
filter2.typename
|
|
3077
3028
|
],
|
|
3078
3029
|
inverted: false
|
|
3079
3030
|
}
|
|
3080
3031
|
},
|
|
3081
3032
|
...this._generateDeletedHandlingSteps(context),
|
|
3033
|
+
// TODO(dmaretskyi): Normally we could skip filtering by typename here, but since the index does not separate schema versions, we need to do additional filter to only select the correct version.
|
|
3082
3034
|
{
|
|
3083
3035
|
_tag: "FilterStep",
|
|
3084
3036
|
filter: {
|
|
3085
|
-
...
|
|
3086
|
-
typename: null
|
|
3037
|
+
...filter2
|
|
3087
3038
|
}
|
|
3088
3039
|
}
|
|
3089
3040
|
]);
|
|
@@ -3100,12 +3051,32 @@ var QueryPlanner = class {
|
|
|
3100
3051
|
{
|
|
3101
3052
|
_tag: "FilterStep",
|
|
3102
3053
|
filter: {
|
|
3103
|
-
...
|
|
3054
|
+
...filter2
|
|
3104
3055
|
}
|
|
3105
3056
|
}
|
|
3106
3057
|
]);
|
|
3107
3058
|
}
|
|
3108
3059
|
}
|
|
3060
|
+
// Tag
|
|
3061
|
+
case "tag": {
|
|
3062
|
+
return QueryPlan.Plan.make([
|
|
3063
|
+
{
|
|
3064
|
+
_tag: "SelectStep",
|
|
3065
|
+
spaces: context.selectionSpaces,
|
|
3066
|
+
selector: {
|
|
3067
|
+
_tag: "WildcardSelector"
|
|
3068
|
+
}
|
|
3069
|
+
},
|
|
3070
|
+
...this._generateDeletedHandlingSteps(context),
|
|
3071
|
+
{
|
|
3072
|
+
_tag: "FilterStep",
|
|
3073
|
+
filter: {
|
|
3074
|
+
...filter2
|
|
3075
|
+
}
|
|
3076
|
+
}
|
|
3077
|
+
]);
|
|
3078
|
+
}
|
|
3079
|
+
// Text
|
|
3109
3080
|
case "text-search": {
|
|
3110
3081
|
return QueryPlan.Plan.make([
|
|
3111
3082
|
{
|
|
@@ -3113,55 +3084,61 @@ var QueryPlanner = class {
|
|
|
3113
3084
|
spaces: context.selectionSpaces,
|
|
3114
3085
|
selector: {
|
|
3115
3086
|
_tag: "TextSelector",
|
|
3116
|
-
text:
|
|
3117
|
-
searchKind:
|
|
3087
|
+
text: filter2.text,
|
|
3088
|
+
searchKind: filter2.searchKind ?? this._options.defaultTextSearchKind
|
|
3118
3089
|
}
|
|
3119
3090
|
},
|
|
3120
3091
|
...this._generateDeletedHandlingSteps(context)
|
|
3121
3092
|
]);
|
|
3122
3093
|
}
|
|
3094
|
+
// Compare
|
|
3123
3095
|
case "compare":
|
|
3124
|
-
throw new QueryError(
|
|
3096
|
+
throw new QueryError({
|
|
3097
|
+
message: "Query too complex",
|
|
3125
3098
|
context: {
|
|
3126
3099
|
query: context.originalQuery
|
|
3127
3100
|
}
|
|
3128
3101
|
});
|
|
3129
3102
|
case "in":
|
|
3130
|
-
throw new QueryError(
|
|
3103
|
+
throw new QueryError({
|
|
3104
|
+
message: "Query too complex",
|
|
3131
3105
|
context: {
|
|
3132
3106
|
query: context.originalQuery
|
|
3133
3107
|
}
|
|
3134
3108
|
});
|
|
3135
3109
|
case "range":
|
|
3136
|
-
throw new QueryError(
|
|
3110
|
+
throw new QueryError({
|
|
3111
|
+
message: "Query too complex",
|
|
3137
3112
|
context: {
|
|
3138
3113
|
query: context.originalQuery
|
|
3139
3114
|
}
|
|
3140
3115
|
});
|
|
3116
|
+
// Boolean
|
|
3141
3117
|
case "not":
|
|
3142
|
-
return this._generateSelectionFromFilter(
|
|
3118
|
+
return this._generateSelectionFromFilter(filter2.filter, {
|
|
3143
3119
|
...context,
|
|
3144
3120
|
selectionInverted: !context.selectionInverted
|
|
3145
3121
|
});
|
|
3146
3122
|
case "and":
|
|
3147
|
-
throw new QueryError(
|
|
3123
|
+
throw new QueryError({
|
|
3124
|
+
message: "Query too complex",
|
|
3148
3125
|
context: {
|
|
3149
3126
|
query: context.originalQuery
|
|
3150
3127
|
}
|
|
3151
3128
|
});
|
|
3152
3129
|
case "or":
|
|
3153
|
-
if (
|
|
3154
|
-
const typenames =
|
|
3155
|
-
invariant9(
|
|
3130
|
+
if (filter2.filters.every(isTrivialTypenameFilter)) {
|
|
3131
|
+
const typenames = filter2.filters.map((filter3) => {
|
|
3132
|
+
invariant9(filter3.type === "object" && filter3.typename !== null, void 0, {
|
|
3156
3133
|
F: __dxlog_file10,
|
|
3157
|
-
L:
|
|
3134
|
+
L: 225,
|
|
3158
3135
|
S: this,
|
|
3159
3136
|
A: [
|
|
3160
|
-
"
|
|
3137
|
+
"filter.type === 'object' && filter.typename !== null",
|
|
3161
3138
|
""
|
|
3162
3139
|
]
|
|
3163
3140
|
});
|
|
3164
|
-
return
|
|
3141
|
+
return filter3.typename;
|
|
3165
3142
|
});
|
|
3166
3143
|
return QueryPlan.Plan.make([
|
|
3167
3144
|
{
|
|
@@ -3173,17 +3150,25 @@ var QueryPlanner = class {
|
|
|
3173
3150
|
inverted: context.selectionInverted
|
|
3174
3151
|
}
|
|
3175
3152
|
},
|
|
3176
|
-
...this._generateDeletedHandlingSteps(context)
|
|
3153
|
+
...this._generateDeletedHandlingSteps(context),
|
|
3154
|
+
{
|
|
3155
|
+
_tag: "FilterStep",
|
|
3156
|
+
filter: {
|
|
3157
|
+
...filter2
|
|
3158
|
+
}
|
|
3159
|
+
}
|
|
3177
3160
|
]);
|
|
3178
3161
|
} else {
|
|
3179
|
-
throw new QueryError(
|
|
3162
|
+
throw new QueryError({
|
|
3163
|
+
message: "Query too complex",
|
|
3180
3164
|
context: {
|
|
3181
3165
|
query: context.originalQuery
|
|
3182
3166
|
}
|
|
3183
3167
|
});
|
|
3184
3168
|
}
|
|
3185
3169
|
default:
|
|
3186
|
-
throw new QueryError(
|
|
3170
|
+
throw new QueryError({
|
|
3171
|
+
message: `Unsupported filter type: ${filter2.type}`,
|
|
3187
3172
|
context: {
|
|
3188
3173
|
query: context.originalQuery
|
|
3189
3174
|
}
|
|
@@ -3383,12 +3368,44 @@ var QueryPlanner = class {
|
|
|
3383
3368
|
_optimizeSoloUnions(plan) {
|
|
3384
3369
|
return plan;
|
|
3385
3370
|
}
|
|
3386
|
-
|
|
3387
|
-
|
|
3388
|
-
|
|
3389
|
-
|
|
3390
|
-
|
|
3391
|
-
|
|
3371
|
+
_generateOrderClause(query, context) {
|
|
3372
|
+
return QueryPlan.Plan.make([
|
|
3373
|
+
...this._generate(query.query, context).steps,
|
|
3374
|
+
{
|
|
3375
|
+
_tag: "OrderStep",
|
|
3376
|
+
order: query.order
|
|
3377
|
+
}
|
|
3378
|
+
]);
|
|
3379
|
+
}
|
|
3380
|
+
// After complete plan is built, inspect it from the end:
|
|
3381
|
+
// - Walk backwards until hitting an object set changer.
|
|
3382
|
+
// - If an order step is found, skip.
|
|
3383
|
+
// - Otherwise append natural order to the end.
|
|
3384
|
+
_ensureOrderStep(plan) {
|
|
3385
|
+
const OBJECT_SET_CHANGERS = /* @__PURE__ */ new Set([
|
|
3386
|
+
"SelectStep",
|
|
3387
|
+
"TraverseStep",
|
|
3388
|
+
"UnionStep",
|
|
3389
|
+
"SetDifferenceStep"
|
|
3390
|
+
]);
|
|
3391
|
+
for (let i = plan.steps.length - 1; i >= 0; i--) {
|
|
3392
|
+
const step = plan.steps[i];
|
|
3393
|
+
if (step._tag === "OrderStep") {
|
|
3394
|
+
return plan;
|
|
3395
|
+
}
|
|
3396
|
+
if (OBJECT_SET_CHANGERS.has(step._tag)) {
|
|
3397
|
+
break;
|
|
3398
|
+
}
|
|
3399
|
+
}
|
|
3400
|
+
return QueryPlan.Plan.make([
|
|
3401
|
+
...plan.steps,
|
|
3402
|
+
{
|
|
3403
|
+
_tag: "OrderStep",
|
|
3404
|
+
order: [
|
|
3405
|
+
Order.natural.ast
|
|
3406
|
+
]
|
|
3407
|
+
}
|
|
3408
|
+
]);
|
|
3392
3409
|
}
|
|
3393
3410
|
};
|
|
3394
3411
|
var DEFAULT_CONTEXT = {
|
|
@@ -3410,24 +3427,11 @@ var createRelationTraversalStep = (direction) => ({
|
|
|
3410
3427
|
direction
|
|
3411
3428
|
}
|
|
3412
3429
|
});
|
|
3413
|
-
var isTrivialTypenameFilter = (
|
|
3414
|
-
return
|
|
3430
|
+
var isTrivialTypenameFilter = (filter2) => {
|
|
3431
|
+
return filter2.type === "object" && filter2.typename !== null && Object.keys(filter2.props).length === 0 && (filter2.id === void 0 || filter2.id.length === 0) && (filter2.foreignKeys === void 0 || filter2.foreignKeys.length === 0);
|
|
3415
3432
|
};
|
|
3416
3433
|
|
|
3417
3434
|
// src/query/query-executor.ts
|
|
3418
|
-
function _define_property12(obj, key, value) {
|
|
3419
|
-
if (key in obj) {
|
|
3420
|
-
Object.defineProperty(obj, key, {
|
|
3421
|
-
value,
|
|
3422
|
-
enumerable: true,
|
|
3423
|
-
configurable: true,
|
|
3424
|
-
writable: true
|
|
3425
|
-
});
|
|
3426
|
-
} else {
|
|
3427
|
-
obj[key] = value;
|
|
3428
|
-
}
|
|
3429
|
-
return obj;
|
|
3430
|
-
}
|
|
3431
3435
|
var __dxlog_file11 = "/__w/dxos/dxos/packages/core/echo/echo-pipeline/src/query/query-executor.ts";
|
|
3432
3436
|
var ExecutionTrace = Object.freeze({
|
|
3433
3437
|
makeEmpty: () => ({
|
|
@@ -3436,11 +3440,57 @@ var ExecutionTrace = Object.freeze({
|
|
|
3436
3440
|
objectCount: 0,
|
|
3437
3441
|
documentsLoaded: 0,
|
|
3438
3442
|
indexHits: 0,
|
|
3443
|
+
beginTs: 0,
|
|
3444
|
+
endTs: 0,
|
|
3439
3445
|
indexQueryTime: 0,
|
|
3440
3446
|
documentLoadTime: 0,
|
|
3441
3447
|
executionTime: 0,
|
|
3442
3448
|
children: []
|
|
3443
3449
|
}),
|
|
3450
|
+
markEnd: (trace6) => {
|
|
3451
|
+
trace6.endTs = performance.now();
|
|
3452
|
+
trace6.executionTime = trace6.endTs - trace6.beginTs;
|
|
3453
|
+
},
|
|
3454
|
+
putOnPerformanceTimeline: (trace6) => {
|
|
3455
|
+
performance.measure(trace6.name, {
|
|
3456
|
+
start: trace6.beginTs,
|
|
3457
|
+
end: trace6.endTs,
|
|
3458
|
+
detail: {
|
|
3459
|
+
devtools: {
|
|
3460
|
+
dataType: "track-entry",
|
|
3461
|
+
track: "Query Execution",
|
|
3462
|
+
trackGroup: "ECHO",
|
|
3463
|
+
color: "tertiary-dark",
|
|
3464
|
+
properties: [
|
|
3465
|
+
[
|
|
3466
|
+
"objectCount",
|
|
3467
|
+
trace6.objectCount
|
|
3468
|
+
],
|
|
3469
|
+
[
|
|
3470
|
+
"documentsLoaded",
|
|
3471
|
+
trace6.documentsLoaded
|
|
3472
|
+
],
|
|
3473
|
+
[
|
|
3474
|
+
"index hits",
|
|
3475
|
+
trace6.indexHits
|
|
3476
|
+
],
|
|
3477
|
+
[
|
|
3478
|
+
"indexQueryTime",
|
|
3479
|
+
trace6.indexQueryTime
|
|
3480
|
+
],
|
|
3481
|
+
[
|
|
3482
|
+
"documentLoadTime",
|
|
3483
|
+
trace6.documentLoadTime
|
|
3484
|
+
]
|
|
3485
|
+
],
|
|
3486
|
+
tooltipText: trace6.details
|
|
3487
|
+
}
|
|
3488
|
+
}
|
|
3489
|
+
});
|
|
3490
|
+
for (const child of trace6.children) {
|
|
3491
|
+
ExecutionTrace.putOnPerformanceTimeline(child);
|
|
3492
|
+
}
|
|
3493
|
+
},
|
|
3444
3494
|
format: (trace6) => {
|
|
3445
3495
|
const go = (trace7, indent) => {
|
|
3446
3496
|
return [
|
|
@@ -3455,6 +3505,30 @@ var ExecutionTrace = Object.freeze({
|
|
|
3455
3505
|
});
|
|
3456
3506
|
var TRACE_QUERY_EXECUTION = false;
|
|
3457
3507
|
var QueryExecutor = class extends Resource6 {
|
|
3508
|
+
_indexer;
|
|
3509
|
+
_automergeHost;
|
|
3510
|
+
_spaceStateManager;
|
|
3511
|
+
/**
|
|
3512
|
+
* Id of this query.
|
|
3513
|
+
*/
|
|
3514
|
+
_id;
|
|
3515
|
+
_query;
|
|
3516
|
+
// TODO(dmaretskyi): Might be used in the future.
|
|
3517
|
+
_reactivity;
|
|
3518
|
+
_plan;
|
|
3519
|
+
_trace = ExecutionTrace.makeEmpty();
|
|
3520
|
+
_lastResultSet = [];
|
|
3521
|
+
constructor(options) {
|
|
3522
|
+
super();
|
|
3523
|
+
this._indexer = options.indexer;
|
|
3524
|
+
this._automergeHost = options.automergeHost;
|
|
3525
|
+
this._spaceStateManager = options.spaceStateManager;
|
|
3526
|
+
this._id = options.queryId;
|
|
3527
|
+
this._query = options.query;
|
|
3528
|
+
this._reactivity = options.reactivity;
|
|
3529
|
+
const queryPlanner = new QueryPlanner();
|
|
3530
|
+
this._plan = queryPlanner.createPlan(this._query);
|
|
3531
|
+
}
|
|
3458
3532
|
get query() {
|
|
3459
3533
|
return this._query;
|
|
3460
3534
|
}
|
|
@@ -3480,7 +3554,7 @@ var QueryExecutor = class extends Resource6 {
|
|
|
3480
3554
|
async execQuery() {
|
|
3481
3555
|
invariant10(this._lifecycleState === LifecycleState3.OPEN, void 0, {
|
|
3482
3556
|
F: __dxlog_file11,
|
|
3483
|
-
L:
|
|
3557
|
+
L: 211,
|
|
3484
3558
|
S: this,
|
|
3485
3559
|
A: [
|
|
3486
3560
|
"this._lifecycleState === LifecycleState.OPEN",
|
|
@@ -3515,7 +3589,7 @@ var QueryExecutor = class extends Resource6 {
|
|
|
3515
3589
|
trace6.children.push(result.trace);
|
|
3516
3590
|
}
|
|
3517
3591
|
trace6.objectCount = workingSet.length;
|
|
3518
|
-
|
|
3592
|
+
ExecutionTrace.markEnd(trace6);
|
|
3519
3593
|
return {
|
|
3520
3594
|
workingSet,
|
|
3521
3595
|
trace: trace6
|
|
@@ -3553,10 +3627,14 @@ var QueryExecutor = class extends Resource6 {
|
|
|
3553
3627
|
case "TraverseStep":
|
|
3554
3628
|
({ workingSet: newWorkingSet, trace: trace6 } = await this._execTraverseStep(step, workingSet));
|
|
3555
3629
|
break;
|
|
3630
|
+
case "OrderStep":
|
|
3631
|
+
({ workingSet: newWorkingSet, trace: trace6 } = await this._execOrderStep(step, workingSet));
|
|
3632
|
+
break;
|
|
3556
3633
|
default:
|
|
3557
3634
|
throw new Error(`Unknown step type: ${step._tag}`);
|
|
3558
3635
|
}
|
|
3559
|
-
trace6.
|
|
3636
|
+
trace6.beginTs = begin;
|
|
3637
|
+
ExecutionTrace.markEnd(trace6);
|
|
3560
3638
|
return {
|
|
3561
3639
|
workingSet: newWorkingSet,
|
|
3562
3640
|
trace: trace6
|
|
@@ -3569,7 +3647,8 @@ var QueryExecutor = class extends Resource6 {
|
|
|
3569
3647
|
const trace6 = {
|
|
3570
3648
|
...ExecutionTrace.makeEmpty(),
|
|
3571
3649
|
name: "Select",
|
|
3572
|
-
details: JSON.stringify(step.selector)
|
|
3650
|
+
details: JSON.stringify(step.selector),
|
|
3651
|
+
beginTs: performance.now()
|
|
3573
3652
|
};
|
|
3574
3653
|
switch (step.selector._tag) {
|
|
3575
3654
|
case "WildcardSelector": {
|
|
@@ -3590,7 +3669,7 @@ var QueryExecutor = class extends Resource6 {
|
|
|
3590
3669
|
const results = await this._loadDocumentsAfterIndexQuery(indexHits);
|
|
3591
3670
|
trace6.documentsLoaded += results.length;
|
|
3592
3671
|
trace6.documentLoadTime += performance.now() - documentLoadStart;
|
|
3593
|
-
workingSet.push(...results.filter(
|
|
3672
|
+
workingSet.push(...results.filter(isNonNullable3).filter((item) => step.spaces.includes(item.spaceId)));
|
|
3594
3673
|
trace6.objectCount = workingSet.length;
|
|
3595
3674
|
break;
|
|
3596
3675
|
}
|
|
@@ -3600,7 +3679,7 @@ var QueryExecutor = class extends Resource6 {
|
|
|
3600
3679
|
sourceSpaceId: step.spaces[0]
|
|
3601
3680
|
})));
|
|
3602
3681
|
trace6.documentLoadTime += performance.now() - beginLoad;
|
|
3603
|
-
workingSet.push(...items.filter(
|
|
3682
|
+
workingSet.push(...items.filter(isNonNullable3));
|
|
3604
3683
|
trace6.objectCount = workingSet.length;
|
|
3605
3684
|
break;
|
|
3606
3685
|
}
|
|
@@ -3622,7 +3701,7 @@ var QueryExecutor = class extends Resource6 {
|
|
|
3622
3701
|
const results = await this._loadDocumentsAfterIndexQuery(indexHits);
|
|
3623
3702
|
trace6.documentsLoaded += results.length;
|
|
3624
3703
|
trace6.documentLoadTime += performance.now() - documentLoadStart;
|
|
3625
|
-
workingSet.push(...results.filter(
|
|
3704
|
+
workingSet.push(...results.filter(isNonNullable3).filter((item) => step.spaces.includes(item.spaceId)));
|
|
3626
3705
|
trace6.objectCount = workingSet.length;
|
|
3627
3706
|
break;
|
|
3628
3707
|
}
|
|
@@ -3647,7 +3726,7 @@ var QueryExecutor = class extends Resource6 {
|
|
|
3647
3726
|
const results = await this._loadDocumentsAfterIndexQuery(indexHits);
|
|
3648
3727
|
trace6.documentsLoaded += results.length;
|
|
3649
3728
|
trace6.documentLoadTime += performance.now() - documentLoadStart;
|
|
3650
|
-
workingSet.push(...results.filter(
|
|
3729
|
+
workingSet.push(...results.filter(isNonNullable3).filter((item) => step.spaces.includes(item.spaceId)));
|
|
3651
3730
|
trace6.objectCount = workingSet.length;
|
|
3652
3731
|
break;
|
|
3653
3732
|
}
|
|
@@ -3717,20 +3796,20 @@ var QueryExecutor = class extends Resource6 {
|
|
|
3717
3796
|
ref: ref2["/"]
|
|
3718
3797
|
}, {
|
|
3719
3798
|
F: __dxlog_file11,
|
|
3720
|
-
L:
|
|
3799
|
+
L: 477,
|
|
3721
3800
|
S: this,
|
|
3722
3801
|
C: (f, a) => f(...a)
|
|
3723
3802
|
});
|
|
3724
3803
|
return null;
|
|
3725
3804
|
}
|
|
3726
3805
|
});
|
|
3727
|
-
}).filter(
|
|
3806
|
+
}).filter(isNonNullable3);
|
|
3728
3807
|
const beginLoad = performance.now();
|
|
3729
3808
|
const items = await Promise.all(refs.map(({ ref, spaceId }) => this._loadFromDXN(ref, {
|
|
3730
3809
|
sourceSpaceId: spaceId
|
|
3731
3810
|
})));
|
|
3732
3811
|
trace6.documentLoadTime += performance.now() - beginLoad;
|
|
3733
|
-
newWorkingSet.push(...items.filter(
|
|
3812
|
+
newWorkingSet.push(...items.filter(isNonNullable3));
|
|
3734
3813
|
trace6.objectCount = newWorkingSet.length;
|
|
3735
3814
|
break;
|
|
3736
3815
|
}
|
|
@@ -3749,7 +3828,7 @@ var QueryExecutor = class extends Resource6 {
|
|
|
3749
3828
|
const results = await this._loadDocumentsAfterIndexQuery(indexHits);
|
|
3750
3829
|
trace6.documentsLoaded += results.length;
|
|
3751
3830
|
trace6.documentLoadTime += performance.now() - documentLoadStart;
|
|
3752
|
-
newWorkingSet.push(...results.filter(
|
|
3831
|
+
newWorkingSet.push(...results.filter(isNonNullable3));
|
|
3753
3832
|
trace6.objectCount = newWorkingSet.length;
|
|
3754
3833
|
break;
|
|
3755
3834
|
}
|
|
@@ -3775,19 +3854,19 @@ var QueryExecutor = class extends Resource6 {
|
|
|
3775
3854
|
ref: ref["/"]
|
|
3776
3855
|
}, {
|
|
3777
3856
|
F: __dxlog_file11,
|
|
3778
|
-
L:
|
|
3857
|
+
L: 540,
|
|
3779
3858
|
S: this,
|
|
3780
3859
|
C: (f, a) => f(...a)
|
|
3781
3860
|
});
|
|
3782
3861
|
return null;
|
|
3783
3862
|
}
|
|
3784
|
-
}).filter(
|
|
3863
|
+
}).filter(isNonNullable3);
|
|
3785
3864
|
const beginLoad = performance.now();
|
|
3786
3865
|
const items = await Promise.all(refs.map(({ ref, spaceId }) => this._loadFromDXN(ref, {
|
|
3787
3866
|
sourceSpaceId: spaceId
|
|
3788
3867
|
})));
|
|
3789
3868
|
trace6.documentLoadTime += performance.now() - beginLoad;
|
|
3790
|
-
newWorkingSet.push(...items.filter(
|
|
3869
|
+
newWorkingSet.push(...items.filter(isNonNullable3));
|
|
3791
3870
|
trace6.objectCount = newWorkingSet.length;
|
|
3792
3871
|
break;
|
|
3793
3872
|
}
|
|
@@ -3807,7 +3886,7 @@ var QueryExecutor = class extends Resource6 {
|
|
|
3807
3886
|
const results = await this._loadDocumentsAfterIndexQuery(indexHits);
|
|
3808
3887
|
trace6.documentsLoaded += results.length;
|
|
3809
3888
|
trace6.documentLoadTime += performance.now() - documentLoadStart;
|
|
3810
|
-
newWorkingSet.push(...results.filter(
|
|
3889
|
+
newWorkingSet.push(...results.filter(isNonNullable3));
|
|
3811
3890
|
trace6.objectCount = newWorkingSet.length;
|
|
3812
3891
|
break;
|
|
3813
3892
|
}
|
|
@@ -3864,16 +3943,83 @@ var QueryExecutor = class extends Resource6 {
|
|
|
3864
3943
|
trace: trace6
|
|
3865
3944
|
};
|
|
3866
3945
|
}
|
|
3946
|
+
async _execOrderStep(step, workingSet) {
|
|
3947
|
+
const sortedWorkingSet = [
|
|
3948
|
+
...workingSet
|
|
3949
|
+
].sort((a, b) => this._compareMultiOrder(a, b, step.order));
|
|
3950
|
+
return {
|
|
3951
|
+
workingSet: sortedWorkingSet,
|
|
3952
|
+
trace: {
|
|
3953
|
+
...ExecutionTrace.makeEmpty(),
|
|
3954
|
+
name: "Order",
|
|
3955
|
+
details: JSON.stringify(step.order),
|
|
3956
|
+
objectCount: sortedWorkingSet.length
|
|
3957
|
+
}
|
|
3958
|
+
};
|
|
3959
|
+
}
|
|
3960
|
+
_compareMultiOrder(a, b, orders) {
|
|
3961
|
+
if (orders.length === 0) {
|
|
3962
|
+
return 0;
|
|
3963
|
+
} else if (orders.length === 1) {
|
|
3964
|
+
return this._compareByOrder(a, b, orders[0]);
|
|
3965
|
+
}
|
|
3966
|
+
for (const order of orders) {
|
|
3967
|
+
const comparison = this._compareByOrder(a, b, order);
|
|
3968
|
+
if (comparison !== 0) {
|
|
3969
|
+
return comparison;
|
|
3970
|
+
}
|
|
3971
|
+
}
|
|
3972
|
+
return 0;
|
|
3973
|
+
}
|
|
3974
|
+
_compareByOrder(a, b, order) {
|
|
3975
|
+
switch (order.kind) {
|
|
3976
|
+
case "natural":
|
|
3977
|
+
return a.objectId.localeCompare(b.objectId);
|
|
3978
|
+
case "property": {
|
|
3979
|
+
const comparison = this._compareByProperty(a, b, order.property);
|
|
3980
|
+
return order.direction === "desc" ? -comparison : comparison;
|
|
3981
|
+
}
|
|
3982
|
+
default:
|
|
3983
|
+
return 0;
|
|
3984
|
+
}
|
|
3985
|
+
}
|
|
3986
|
+
_compareByProperty(a, b, property) {
|
|
3987
|
+
const aValue = a.doc.data[property];
|
|
3988
|
+
const bValue = b.doc.data[property];
|
|
3989
|
+
if (aValue == null && bValue == null) {
|
|
3990
|
+
return 0;
|
|
3991
|
+
}
|
|
3992
|
+
if (aValue == null) {
|
|
3993
|
+
return 1;
|
|
3994
|
+
}
|
|
3995
|
+
if (bValue == null) {
|
|
3996
|
+
return -1;
|
|
3997
|
+
}
|
|
3998
|
+
if (typeof aValue === "string" && typeof bValue === "string") {
|
|
3999
|
+
return aValue.localeCompare(bValue);
|
|
4000
|
+
}
|
|
4001
|
+
if (typeof aValue === "number" && typeof bValue === "number") {
|
|
4002
|
+
return aValue - bValue;
|
|
4003
|
+
}
|
|
4004
|
+
if (typeof aValue === "boolean" && typeof bValue === "boolean") {
|
|
4005
|
+
return aValue === bValue ? 0 : aValue ? 1 : -1;
|
|
4006
|
+
}
|
|
4007
|
+
return String(aValue).localeCompare(String(bValue));
|
|
4008
|
+
}
|
|
3867
4009
|
async _loadDocumentsAfterIndexQuery(indexHits) {
|
|
3868
4010
|
return Promise.all(indexHits.map(async (hit) => {
|
|
3869
4011
|
return this._loadFromIndexHit(hit);
|
|
3870
4012
|
}));
|
|
3871
4013
|
}
|
|
4014
|
+
/**
|
|
4015
|
+
* Space key hex -> SpaceId.
|
|
4016
|
+
*/
|
|
4017
|
+
_spaceIdCache = /* @__PURE__ */ new Map();
|
|
3872
4018
|
async _loadFromIndexHit(hit) {
|
|
3873
4019
|
const { objectId, documentId, spaceKey: spaceKeyInIndex } = objectPointerCodec3.decode(hit.id);
|
|
3874
4020
|
const handle = await this._automergeHost.loadDoc(Context3.default(void 0, {
|
|
3875
4021
|
F: __dxlog_file11,
|
|
3876
|
-
L:
|
|
4022
|
+
L: 738
|
|
3877
4023
|
}), documentId);
|
|
3878
4024
|
const doc = handle.doc();
|
|
3879
4025
|
if (!doc) {
|
|
@@ -3883,6 +4029,11 @@ var QueryExecutor = class extends Resource6 {
|
|
|
3883
4029
|
if (!spaceKey) {
|
|
3884
4030
|
return null;
|
|
3885
4031
|
}
|
|
4032
|
+
let spaceId = this._spaceIdCache.get(spaceKey);
|
|
4033
|
+
if (!spaceId) {
|
|
4034
|
+
spaceId = await createIdFromSpaceKey(PublicKey3.from(spaceKey));
|
|
4035
|
+
this._spaceIdCache.set(spaceKey, spaceId);
|
|
4036
|
+
}
|
|
3886
4037
|
const object = DatabaseDirectory3.getInlineObject(doc, objectId);
|
|
3887
4038
|
if (!object) {
|
|
3888
4039
|
return null;
|
|
@@ -3890,7 +4041,7 @@ var QueryExecutor = class extends Resource6 {
|
|
|
3890
4041
|
return {
|
|
3891
4042
|
objectId,
|
|
3892
4043
|
documentId,
|
|
3893
|
-
spaceId
|
|
4044
|
+
spaceId,
|
|
3894
4045
|
doc: object
|
|
3895
4046
|
};
|
|
3896
4047
|
}
|
|
@@ -3901,7 +4052,7 @@ var QueryExecutor = class extends Resource6 {
|
|
|
3901
4052
|
dxn
|
|
3902
4053
|
}, {
|
|
3903
4054
|
F: __dxlog_file11,
|
|
3904
|
-
L:
|
|
4055
|
+
L: 771,
|
|
3905
4056
|
S: this,
|
|
3906
4057
|
C: (f, a) => f(...a)
|
|
3907
4058
|
});
|
|
@@ -3914,7 +4065,7 @@ var QueryExecutor = class extends Resource6 {
|
|
|
3914
4065
|
spaceId
|
|
3915
4066
|
}, {
|
|
3916
4067
|
F: __dxlog_file11,
|
|
3917
|
-
L:
|
|
4068
|
+
L: 779,
|
|
3918
4069
|
S: this,
|
|
3919
4070
|
C: (f, a) => f(...a)
|
|
3920
4071
|
});
|
|
@@ -3926,7 +4077,7 @@ var QueryExecutor = class extends Resource6 {
|
|
|
3926
4077
|
spaceId
|
|
3927
4078
|
}, {
|
|
3928
4079
|
F: __dxlog_file11,
|
|
3929
|
-
L:
|
|
4080
|
+
L: 784,
|
|
3930
4081
|
S: this,
|
|
3931
4082
|
C: (f, a) => f(...a)
|
|
3932
4083
|
});
|
|
@@ -3947,7 +4098,7 @@ var QueryExecutor = class extends Resource6 {
|
|
|
3947
4098
|
}
|
|
3948
4099
|
const handle = await this._automergeHost.loadDoc(Context3.default(void 0, {
|
|
3949
4100
|
F: __dxlog_file11,
|
|
3950
|
-
L:
|
|
4101
|
+
L: 803
|
|
3951
4102
|
}), link);
|
|
3952
4103
|
const doc = handle.doc();
|
|
3953
4104
|
if (!doc) {
|
|
@@ -3964,37 +4115,9 @@ var QueryExecutor = class extends Resource6 {
|
|
|
3964
4115
|
doc: object
|
|
3965
4116
|
};
|
|
3966
4117
|
}
|
|
3967
|
-
constructor(options) {
|
|
3968
|
-
super(), _define_property12(this, "_indexer", void 0), _define_property12(this, "_automergeHost", void 0), _define_property12(this, "_spaceStateManager", void 0), /**
|
|
3969
|
-
* Id of this query.
|
|
3970
|
-
*/
|
|
3971
|
-
_define_property12(this, "_id", void 0), _define_property12(this, "_query", void 0), // TODO(dmaretskyi): Might be used in the future.
|
|
3972
|
-
_define_property12(this, "_reactivity", void 0), _define_property12(this, "_plan", void 0), _define_property12(this, "_trace", ExecutionTrace.makeEmpty()), _define_property12(this, "_lastResultSet", []);
|
|
3973
|
-
this._indexer = options.indexer;
|
|
3974
|
-
this._automergeHost = options.automergeHost;
|
|
3975
|
-
this._spaceStateManager = options.spaceStateManager;
|
|
3976
|
-
this._id = options.queryId;
|
|
3977
|
-
this._query = options.query;
|
|
3978
|
-
this._reactivity = options.reactivity;
|
|
3979
|
-
const queryPlanner = new QueryPlanner();
|
|
3980
|
-
this._plan = queryPlanner.createPlan(this._query);
|
|
3981
|
-
}
|
|
3982
4118
|
};
|
|
3983
4119
|
|
|
3984
4120
|
// src/db-host/query-service.ts
|
|
3985
|
-
function _define_property13(obj, key, value) {
|
|
3986
|
-
if (key in obj) {
|
|
3987
|
-
Object.defineProperty(obj, key, {
|
|
3988
|
-
value,
|
|
3989
|
-
enumerable: true,
|
|
3990
|
-
configurable: true,
|
|
3991
|
-
writable: true
|
|
3992
|
-
});
|
|
3993
|
-
} else {
|
|
3994
|
-
obj[key] = value;
|
|
3995
|
-
}
|
|
3996
|
-
return obj;
|
|
3997
|
-
}
|
|
3998
4121
|
function _ts_decorate5(decorators, target, key, desc) {
|
|
3999
4122
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4000
4123
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -4003,6 +4126,27 @@ function _ts_decorate5(decorators, target, key, desc) {
|
|
|
4003
4126
|
}
|
|
4004
4127
|
var __dxlog_file12 = "/__w/dxos/dxos/packages/core/echo/echo-pipeline/src/db-host/query-service.ts";
|
|
4005
4128
|
var QueryServiceImpl = class extends Resource7 {
|
|
4129
|
+
_params;
|
|
4130
|
+
// TODO(dmaretskyi): We need to implement query deduping. Idle composer has 80 queries with only 10 being unique.
|
|
4131
|
+
_queries = /* @__PURE__ */ new Set();
|
|
4132
|
+
_updateQueries;
|
|
4133
|
+
// TODO(burdon): OK for options, but not params. Pass separately and type readonly here.
|
|
4134
|
+
constructor(_params) {
|
|
4135
|
+
super(), this._params = _params;
|
|
4136
|
+
trace4.diagnostic({
|
|
4137
|
+
id: "active-queries",
|
|
4138
|
+
name: "Active Queries",
|
|
4139
|
+
fetch: () => {
|
|
4140
|
+
return Array.from(this._queries).map((query) => {
|
|
4141
|
+
return {
|
|
4142
|
+
query: JSON.stringify(query.executor.query),
|
|
4143
|
+
plan: JSON.stringify(query.executor.plan),
|
|
4144
|
+
trace: JSON.stringify(query.executor.trace)
|
|
4145
|
+
};
|
|
4146
|
+
});
|
|
4147
|
+
}
|
|
4148
|
+
});
|
|
4149
|
+
}
|
|
4006
4150
|
async _open() {
|
|
4007
4151
|
this._params.indexer.updated.on(this._ctx, () => this.invalidateQueries());
|
|
4008
4152
|
this._updateQueries = new DeferredTask2(this._ctx, this._executeQueries.bind(this));
|
|
@@ -4021,7 +4165,7 @@ var QueryServiceImpl = class extends Resource7 {
|
|
|
4021
4165
|
config: this._params.indexer.config
|
|
4022
4166
|
}, {
|
|
4023
4167
|
F: __dxlog_file12,
|
|
4024
|
-
L:
|
|
4168
|
+
L: 102,
|
|
4025
4169
|
S: this,
|
|
4026
4170
|
C: (f, a) => f(...a)
|
|
4027
4171
|
});
|
|
@@ -4043,7 +4187,7 @@ var QueryServiceImpl = class extends Resource7 {
|
|
|
4043
4187
|
async reindex() {
|
|
4044
4188
|
log10("Reindexing all documents...", void 0, {
|
|
4045
4189
|
F: __dxlog_file12,
|
|
4046
|
-
L:
|
|
4190
|
+
L: 121,
|
|
4047
4191
|
S: this,
|
|
4048
4192
|
C: (f, a) => f(...a)
|
|
4049
4193
|
});
|
|
@@ -4058,7 +4202,7 @@ var QueryServiceImpl = class extends Resource7 {
|
|
|
4058
4202
|
count: ids.size
|
|
4059
4203
|
}, {
|
|
4060
4204
|
F: __dxlog_file12,
|
|
4061
|
-
L:
|
|
4205
|
+
L: 129,
|
|
4062
4206
|
S: this,
|
|
4063
4207
|
C: (f, a) => f(...a)
|
|
4064
4208
|
});
|
|
@@ -4068,7 +4212,7 @@ var QueryServiceImpl = class extends Resource7 {
|
|
|
4068
4212
|
count: ids.size
|
|
4069
4213
|
}, {
|
|
4070
4214
|
F: __dxlog_file12,
|
|
4071
|
-
L:
|
|
4215
|
+
L: 133,
|
|
4072
4216
|
S: this,
|
|
4073
4217
|
C: (f, a) => f(...a)
|
|
4074
4218
|
});
|
|
@@ -4134,7 +4278,7 @@ var QueryServiceImpl = class extends Resource7 {
|
|
|
4134
4278
|
} catch (err) {
|
|
4135
4279
|
log10.catch(err, void 0, {
|
|
4136
4280
|
F: __dxlog_file12,
|
|
4137
|
-
L:
|
|
4281
|
+
L: 204,
|
|
4138
4282
|
S: this,
|
|
4139
4283
|
C: (f, a) => f(...a)
|
|
4140
4284
|
});
|
|
@@ -4145,28 +4289,11 @@ var QueryServiceImpl = class extends Resource7 {
|
|
|
4145
4289
|
duration: performance.now() - begin
|
|
4146
4290
|
}, {
|
|
4147
4291
|
F: __dxlog_file12,
|
|
4148
|
-
L:
|
|
4292
|
+
L: 208,
|
|
4149
4293
|
S: this,
|
|
4150
4294
|
C: (f, a) => f(...a)
|
|
4151
4295
|
});
|
|
4152
4296
|
}
|
|
4153
|
-
// TODO(burdon): OK for options, but not params. Pass separately and type readonly here.
|
|
4154
|
-
constructor(_params) {
|
|
4155
|
-
super(), _define_property13(this, "_params", void 0), _define_property13(this, "_queries", void 0), _define_property13(this, "_updateQueries", void 0), this._params = _params, this._queries = /* @__PURE__ */ new Set();
|
|
4156
|
-
trace4.diagnostic({
|
|
4157
|
-
id: "active-queries",
|
|
4158
|
-
name: "Active Queries",
|
|
4159
|
-
fetch: () => {
|
|
4160
|
-
return Array.from(this._queries).map((query) => {
|
|
4161
|
-
return {
|
|
4162
|
-
query: JSON.stringify(query.executor.query),
|
|
4163
|
-
plan: JSON.stringify(query.executor.plan),
|
|
4164
|
-
trace: JSON.stringify(query.executor.trace)
|
|
4165
|
-
};
|
|
4166
|
-
});
|
|
4167
|
-
}
|
|
4168
|
-
});
|
|
4169
|
-
}
|
|
4170
4297
|
};
|
|
4171
4298
|
_ts_decorate5([
|
|
4172
4299
|
synchronized2
|
|
@@ -4213,7 +4340,7 @@ var createDocumentsIterator = (automergeHost) => (
|
|
|
4213
4340
|
}
|
|
4214
4341
|
const linkHandle = await automergeHost.loadDoc(Context4.default(void 0, {
|
|
4215
4342
|
F: __dxlog_file12,
|
|
4216
|
-
L:
|
|
4343
|
+
L: 248
|
|
4217
4344
|
}), urlString);
|
|
4218
4345
|
for await (const result of getObjectsFromHandle(linkHandle)) {
|
|
4219
4346
|
yield result;
|
|
@@ -4247,17 +4374,17 @@ import { DatabaseDirectory as DatabaseDirectory5, SpaceDocVersion as SpaceDocVer
|
|
|
4247
4374
|
import { invariant as invariant11 } from "@dxos/invariant";
|
|
4248
4375
|
|
|
4249
4376
|
// src/db-host/automerge-metrics.ts
|
|
4250
|
-
import * as
|
|
4377
|
+
import * as A5 from "@automerge/automerge";
|
|
4251
4378
|
import { log as log11 } from "@dxos/log";
|
|
4252
4379
|
var __dxlog_file13 = "/__w/dxos/dxos/packages/core/echo/echo-pipeline/src/db-host/automerge-metrics.ts";
|
|
4253
4380
|
var measureDocMetrics = (doc) => {
|
|
4254
|
-
const snapshot =
|
|
4381
|
+
const snapshot = A5.save(doc);
|
|
4255
4382
|
const start = Date.now();
|
|
4256
|
-
const temp =
|
|
4383
|
+
const temp = A5.load(snapshot);
|
|
4257
4384
|
const end = Date.now();
|
|
4258
|
-
|
|
4385
|
+
A5.free(temp);
|
|
4259
4386
|
const getAllChangesStart = Date.now();
|
|
4260
|
-
const mutationCount =
|
|
4387
|
+
const mutationCount = A5.getAllChanges(doc).length;
|
|
4261
4388
|
const getAllChangesEnd = Date.now();
|
|
4262
4389
|
if (getAllChangesEnd - getAllChangesStart > 300) {
|
|
4263
4390
|
log11.warn("getAllChanges took too long", {
|
|
@@ -4277,21 +4404,9 @@ var measureDocMetrics = (doc) => {
|
|
|
4277
4404
|
};
|
|
4278
4405
|
|
|
4279
4406
|
// src/db-host/database-root.ts
|
|
4280
|
-
function _define_property14(obj, key, value) {
|
|
4281
|
-
if (key in obj) {
|
|
4282
|
-
Object.defineProperty(obj, key, {
|
|
4283
|
-
value,
|
|
4284
|
-
enumerable: true,
|
|
4285
|
-
configurable: true,
|
|
4286
|
-
writable: true
|
|
4287
|
-
});
|
|
4288
|
-
} else {
|
|
4289
|
-
obj[key] = value;
|
|
4290
|
-
}
|
|
4291
|
-
return obj;
|
|
4292
|
-
}
|
|
4293
4407
|
var __dxlog_file14 = "/__w/dxos/dxos/packages/core/echo/echo-pipeline/src/db-host/database-root.ts";
|
|
4294
4408
|
var DatabaseRoot = class {
|
|
4409
|
+
_rootHandle;
|
|
4295
4410
|
static mapLinks(doc, mapping) {
|
|
4296
4411
|
doc.change((d) => {
|
|
4297
4412
|
if (!d.links) {
|
|
@@ -4305,6 +4420,9 @@ var DatabaseRoot = class {
|
|
|
4305
4420
|
}
|
|
4306
4421
|
});
|
|
4307
4422
|
}
|
|
4423
|
+
constructor(_rootHandle) {
|
|
4424
|
+
this._rootHandle = _rootHandle;
|
|
4425
|
+
}
|
|
4308
4426
|
get documentId() {
|
|
4309
4427
|
return this._rootHandle.documentId;
|
|
4310
4428
|
}
|
|
@@ -4368,28 +4486,16 @@ var DatabaseRoot = class {
|
|
|
4368
4486
|
}
|
|
4369
4487
|
return measureDocMetrics(doc);
|
|
4370
4488
|
}
|
|
4371
|
-
constructor(_rootHandle) {
|
|
4372
|
-
_define_property14(this, "_rootHandle", void 0);
|
|
4373
|
-
this._rootHandle = _rootHandle;
|
|
4374
|
-
}
|
|
4375
4489
|
};
|
|
4376
4490
|
|
|
4377
4491
|
// src/db-host/space-state-manager.ts
|
|
4378
|
-
function _define_property15(obj, key, value) {
|
|
4379
|
-
if (key in obj) {
|
|
4380
|
-
Object.defineProperty(obj, key, {
|
|
4381
|
-
value,
|
|
4382
|
-
enumerable: true,
|
|
4383
|
-
configurable: true,
|
|
4384
|
-
writable: true
|
|
4385
|
-
});
|
|
4386
|
-
} else {
|
|
4387
|
-
obj[key] = value;
|
|
4388
|
-
}
|
|
4389
|
-
return obj;
|
|
4390
|
-
}
|
|
4391
4492
|
var __dxlog_file15 = "/__w/dxos/dxos/packages/core/echo/echo-pipeline/src/db-host/space-state-manager.ts";
|
|
4392
4493
|
var SpaceStateManager = class extends Resource8 {
|
|
4494
|
+
_roots = /* @__PURE__ */ new Map();
|
|
4495
|
+
_rootBySpace = /* @__PURE__ */ new Map();
|
|
4496
|
+
_perRootContext = /* @__PURE__ */ new Map();
|
|
4497
|
+
_lastSpaceDocumentList = /* @__PURE__ */ new Map();
|
|
4498
|
+
spaceDocumentListUpdated = new Event3();
|
|
4393
4499
|
async _close(ctx) {
|
|
4394
4500
|
for (const [_, rootCtx] of this._perRootContext) {
|
|
4395
4501
|
await rootCtx.dispose();
|
|
@@ -4462,16 +4568,13 @@ var SpaceStateManager = class extends Resource8 {
|
|
|
4462
4568
|
documentListCheckScheduler.trigger();
|
|
4463
4569
|
return root;
|
|
4464
4570
|
}
|
|
4465
|
-
constructor(...args) {
|
|
4466
|
-
super(...args), _define_property15(this, "_roots", /* @__PURE__ */ new Map()), _define_property15(this, "_rootBySpace", /* @__PURE__ */ new Map()), _define_property15(this, "_perRootContext", /* @__PURE__ */ new Map()), _define_property15(this, "_lastSpaceDocumentList", /* @__PURE__ */ new Map()), _define_property15(this, "spaceDocumentListUpdated", new Event3());
|
|
4467
|
-
}
|
|
4468
4571
|
};
|
|
4469
4572
|
var SpaceDocumentListUpdatedEvent = class {
|
|
4573
|
+
spaceId;
|
|
4574
|
+
spaceRootId;
|
|
4575
|
+
previousRootId;
|
|
4576
|
+
documentIds;
|
|
4470
4577
|
constructor(spaceId, spaceRootId, previousRootId, documentIds) {
|
|
4471
|
-
_define_property15(this, "spaceId", void 0);
|
|
4472
|
-
_define_property15(this, "spaceRootId", void 0);
|
|
4473
|
-
_define_property15(this, "previousRootId", void 0);
|
|
4474
|
-
_define_property15(this, "documentIds", void 0);
|
|
4475
4578
|
this.spaceId = spaceId;
|
|
4476
4579
|
this.spaceRootId = spaceRootId;
|
|
4477
4580
|
this.previousRootId = previousRootId;
|
|
@@ -4480,19 +4583,6 @@ var SpaceDocumentListUpdatedEvent = class {
|
|
|
4480
4583
|
};
|
|
4481
4584
|
|
|
4482
4585
|
// src/db-host/echo-host.ts
|
|
4483
|
-
function _define_property16(obj, key, value) {
|
|
4484
|
-
if (key in obj) {
|
|
4485
|
-
Object.defineProperty(obj, key, {
|
|
4486
|
-
value,
|
|
4487
|
-
enumerable: true,
|
|
4488
|
-
configurable: true,
|
|
4489
|
-
writable: true
|
|
4490
|
-
});
|
|
4491
|
-
} else {
|
|
4492
|
-
obj[key] = value;
|
|
4493
|
-
}
|
|
4494
|
-
return obj;
|
|
4495
|
-
}
|
|
4496
4586
|
var __dxlog_file16 = "/__w/dxos/dxos/packages/core/echo/echo-pipeline/src/db-host/echo-host.ts";
|
|
4497
4587
|
var DEFAULT_INDEXING_CONFIG = {
|
|
4498
4588
|
// TODO(dmaretskyi): Disabled by default since embedding generation is expensive.
|
|
@@ -4500,6 +4590,111 @@ var DEFAULT_INDEXING_CONFIG = {
|
|
|
4500
4590
|
vector: false
|
|
4501
4591
|
};
|
|
4502
4592
|
var EchoHost = class extends Resource9 {
|
|
4593
|
+
_indexMetadataStore;
|
|
4594
|
+
_indexer;
|
|
4595
|
+
_automergeHost;
|
|
4596
|
+
_queryService;
|
|
4597
|
+
_dataService;
|
|
4598
|
+
_spaceStateManager = new SpaceStateManager();
|
|
4599
|
+
_echoDataMonitor;
|
|
4600
|
+
constructor({ kv, indexing = {}, peerIdProvider, getSpaceKeyByRootDocumentId }) {
|
|
4601
|
+
super();
|
|
4602
|
+
const indexingConfig = {
|
|
4603
|
+
...DEFAULT_INDEXING_CONFIG,
|
|
4604
|
+
...indexing
|
|
4605
|
+
};
|
|
4606
|
+
this._indexMetadataStore = new IndexMetadataStore({
|
|
4607
|
+
db: kv.sublevel("index-metadata")
|
|
4608
|
+
});
|
|
4609
|
+
this._echoDataMonitor = new EchoDataMonitor();
|
|
4610
|
+
this._automergeHost = new AutomergeHost({
|
|
4611
|
+
db: kv,
|
|
4612
|
+
dataMonitor: this._echoDataMonitor,
|
|
4613
|
+
indexMetadataStore: this._indexMetadataStore,
|
|
4614
|
+
peerIdProvider,
|
|
4615
|
+
getSpaceKeyByRootDocumentId
|
|
4616
|
+
});
|
|
4617
|
+
this._indexer = new Indexer({
|
|
4618
|
+
db: kv,
|
|
4619
|
+
indexStore: new IndexStore({
|
|
4620
|
+
db: kv.sublevel("index-storage")
|
|
4621
|
+
}),
|
|
4622
|
+
metadataStore: this._indexMetadataStore,
|
|
4623
|
+
loadDocuments: createSelectedDocumentsIterator(this._automergeHost),
|
|
4624
|
+
indexCooldownTime: false ? 0 : void 0
|
|
4625
|
+
});
|
|
4626
|
+
void this._indexer.setConfig({
|
|
4627
|
+
enabled: true,
|
|
4628
|
+
indexes: [
|
|
4629
|
+
//
|
|
4630
|
+
{
|
|
4631
|
+
kind: IndexKind.Kind.SCHEMA_MATCH
|
|
4632
|
+
},
|
|
4633
|
+
{
|
|
4634
|
+
kind: IndexKind.Kind.GRAPH
|
|
4635
|
+
},
|
|
4636
|
+
...indexingConfig.fullText ? [
|
|
4637
|
+
{
|
|
4638
|
+
kind: IndexKind.Kind.FULL_TEXT
|
|
4639
|
+
}
|
|
4640
|
+
] : [],
|
|
4641
|
+
...indexingConfig.vector ? [
|
|
4642
|
+
{
|
|
4643
|
+
kind: IndexKind.Kind.VECTOR
|
|
4644
|
+
}
|
|
4645
|
+
] : []
|
|
4646
|
+
]
|
|
4647
|
+
});
|
|
4648
|
+
this._queryService = new QueryServiceImpl({
|
|
4649
|
+
automergeHost: this._automergeHost,
|
|
4650
|
+
indexer: this._indexer,
|
|
4651
|
+
spaceStateManager: this._spaceStateManager
|
|
4652
|
+
});
|
|
4653
|
+
this._dataService = new DataServiceImpl({
|
|
4654
|
+
automergeHost: this._automergeHost,
|
|
4655
|
+
spaceStateManager: this._spaceStateManager,
|
|
4656
|
+
updateIndexes: async () => {
|
|
4657
|
+
await this._indexer.updateIndexes();
|
|
4658
|
+
}
|
|
4659
|
+
});
|
|
4660
|
+
trace5.diagnostic({
|
|
4661
|
+
id: "echo-stats",
|
|
4662
|
+
name: "Echo Stats",
|
|
4663
|
+
fetch: async () => {
|
|
4664
|
+
return {
|
|
4665
|
+
dataStats: this._echoDataMonitor.computeStats(),
|
|
4666
|
+
loadedDocsCount: this._automergeHost.loadedDocsCount
|
|
4667
|
+
};
|
|
4668
|
+
}
|
|
4669
|
+
});
|
|
4670
|
+
trace5.diagnostic({
|
|
4671
|
+
id: "database-roots",
|
|
4672
|
+
name: "Database Roots",
|
|
4673
|
+
fetch: async () => {
|
|
4674
|
+
return Array.from(this._spaceStateManager.roots.values()).map((root) => ({
|
|
4675
|
+
url: root.url,
|
|
4676
|
+
isLoaded: root.isLoaded,
|
|
4677
|
+
spaceKey: root.getSpaceKey(),
|
|
4678
|
+
inlineObjects: root.getInlineObjectCount(),
|
|
4679
|
+
linkedObjects: root.getLinkedObjectCount()
|
|
4680
|
+
}));
|
|
4681
|
+
}
|
|
4682
|
+
});
|
|
4683
|
+
trace5.diagnostic({
|
|
4684
|
+
id: "database-root-metrics",
|
|
4685
|
+
name: "Database Roots (with metrics)",
|
|
4686
|
+
fetch: async () => {
|
|
4687
|
+
return Array.from(this._spaceStateManager.roots.values()).map((root) => ({
|
|
4688
|
+
url: root.url,
|
|
4689
|
+
isLoaded: root.isLoaded,
|
|
4690
|
+
spaceKey: root.getSpaceKey(),
|
|
4691
|
+
inlineObjects: root.getInlineObjectCount(),
|
|
4692
|
+
linkedObjects: root.getLinkedObjectCount(),
|
|
4693
|
+
...root.measureMetrics() ?? {}
|
|
4694
|
+
}));
|
|
4695
|
+
}
|
|
4696
|
+
});
|
|
4697
|
+
}
|
|
4503
4698
|
get queryService() {
|
|
4504
4699
|
return this._queryService;
|
|
4505
4700
|
}
|
|
@@ -4524,7 +4719,6 @@ var EchoHost = class extends Resource9 {
|
|
|
4524
4719
|
if (e.previousRootId) {
|
|
4525
4720
|
void this._automergeHost.clearLocalCollectionState(deriveCollectionIdFromSpaceId(e.spaceId, e.previousRootId));
|
|
4526
4721
|
}
|
|
4527
|
-
void this._automergeHost.updateLocalCollectionState(deriveCollectionIdFromSpaceId(e.spaceId), e.documentIds);
|
|
4528
4722
|
void this._automergeHost.updateLocalCollectionState(deriveCollectionIdFromSpaceId(e.spaceId, e.spaceRootId), e.documentIds);
|
|
4529
4723
|
});
|
|
4530
4724
|
this._automergeHost.documentsSaved.on(this._ctx, () => {
|
|
@@ -4541,7 +4735,7 @@ var EchoHost = class extends Resource9 {
|
|
|
4541
4735
|
* Flush all pending writes to the underlying storage.
|
|
4542
4736
|
*/
|
|
4543
4737
|
async flush() {
|
|
4544
|
-
await this._automergeHost.
|
|
4738
|
+
await this._automergeHost.flush();
|
|
4545
4739
|
}
|
|
4546
4740
|
/**
|
|
4547
4741
|
* Perform any pending index updates.
|
|
@@ -4570,7 +4764,7 @@ var EchoHost = class extends Resource9 {
|
|
|
4570
4764
|
async createSpaceRoot(spaceKey) {
|
|
4571
4765
|
invariant13(this._lifecycleState === LifecycleState5.OPEN, void 0, {
|
|
4572
4766
|
F: __dxlog_file16,
|
|
4573
|
-
L:
|
|
4767
|
+
L: 254,
|
|
4574
4768
|
S: this,
|
|
4575
4769
|
A: [
|
|
4576
4770
|
"this._lifecycleState === LifecycleState.OPEN",
|
|
@@ -4598,7 +4792,7 @@ var EchoHost = class extends Resource9 {
|
|
|
4598
4792
|
async openSpaceRoot(spaceId, automergeUrl) {
|
|
4599
4793
|
invariant13(this._lifecycleState === LifecycleState5.OPEN, void 0, {
|
|
4600
4794
|
F: __dxlog_file16,
|
|
4601
|
-
L:
|
|
4795
|
+
L: 273,
|
|
4602
4796
|
S: this,
|
|
4603
4797
|
A: [
|
|
4604
4798
|
"this._lifecycleState === LifecycleState.OPEN",
|
|
@@ -4625,107 +4819,10 @@ var EchoHost = class extends Resource9 {
|
|
|
4625
4819
|
async removeReplicator(replicator) {
|
|
4626
4820
|
await this._automergeHost.removeReplicator(replicator);
|
|
4627
4821
|
}
|
|
4628
|
-
constructor({ kv, indexing = {}, peerIdProvider, getSpaceKeyByRootDocumentId }) {
|
|
4629
|
-
super(), _define_property16(this, "_indexMetadataStore", void 0), _define_property16(this, "_indexer", void 0), _define_property16(this, "_automergeHost", void 0), _define_property16(this, "_queryService", void 0), _define_property16(this, "_dataService", void 0), _define_property16(this, "_spaceStateManager", new SpaceStateManager()), _define_property16(this, "_echoDataMonitor", void 0);
|
|
4630
|
-
const indexingConfig = {
|
|
4631
|
-
...DEFAULT_INDEXING_CONFIG,
|
|
4632
|
-
...indexing
|
|
4633
|
-
};
|
|
4634
|
-
this._indexMetadataStore = new IndexMetadataStore({
|
|
4635
|
-
db: kv.sublevel("index-metadata")
|
|
4636
|
-
});
|
|
4637
|
-
this._echoDataMonitor = new EchoDataMonitor();
|
|
4638
|
-
this._automergeHost = new AutomergeHost({
|
|
4639
|
-
db: kv,
|
|
4640
|
-
dataMonitor: this._echoDataMonitor,
|
|
4641
|
-
indexMetadataStore: this._indexMetadataStore,
|
|
4642
|
-
peerIdProvider,
|
|
4643
|
-
getSpaceKeyByRootDocumentId
|
|
4644
|
-
});
|
|
4645
|
-
this._indexer = new Indexer({
|
|
4646
|
-
db: kv,
|
|
4647
|
-
indexStore: new IndexStore({
|
|
4648
|
-
db: kv.sublevel("index-storage")
|
|
4649
|
-
}),
|
|
4650
|
-
metadataStore: this._indexMetadataStore,
|
|
4651
|
-
loadDocuments: createSelectedDocumentsIterator(this._automergeHost),
|
|
4652
|
-
indexCooldownTime: false ? 0 : void 0
|
|
4653
|
-
});
|
|
4654
|
-
void this._indexer.setConfig({
|
|
4655
|
-
enabled: true,
|
|
4656
|
-
indexes: [
|
|
4657
|
-
//
|
|
4658
|
-
{
|
|
4659
|
-
kind: IndexKind.Kind.SCHEMA_MATCH
|
|
4660
|
-
},
|
|
4661
|
-
{
|
|
4662
|
-
kind: IndexKind.Kind.GRAPH
|
|
4663
|
-
},
|
|
4664
|
-
...indexingConfig.fullText ? [
|
|
4665
|
-
{
|
|
4666
|
-
kind: IndexKind.Kind.FULL_TEXT
|
|
4667
|
-
}
|
|
4668
|
-
] : [],
|
|
4669
|
-
...indexingConfig.vector ? [
|
|
4670
|
-
{
|
|
4671
|
-
kind: IndexKind.Kind.VECTOR
|
|
4672
|
-
}
|
|
4673
|
-
] : []
|
|
4674
|
-
]
|
|
4675
|
-
});
|
|
4676
|
-
this._queryService = new QueryServiceImpl({
|
|
4677
|
-
automergeHost: this._automergeHost,
|
|
4678
|
-
indexer: this._indexer,
|
|
4679
|
-
spaceStateManager: this._spaceStateManager
|
|
4680
|
-
});
|
|
4681
|
-
this._dataService = new DataServiceImpl({
|
|
4682
|
-
automergeHost: this._automergeHost,
|
|
4683
|
-
spaceStateManager: this._spaceStateManager,
|
|
4684
|
-
updateIndexes: async () => {
|
|
4685
|
-
await this._indexer.updateIndexes();
|
|
4686
|
-
}
|
|
4687
|
-
});
|
|
4688
|
-
trace5.diagnostic({
|
|
4689
|
-
id: "echo-stats",
|
|
4690
|
-
name: "Echo Stats",
|
|
4691
|
-
fetch: async () => {
|
|
4692
|
-
return {
|
|
4693
|
-
dataStats: this._echoDataMonitor.computeStats(),
|
|
4694
|
-
loadedDocsCount: this._automergeHost.loadedDocsCount
|
|
4695
|
-
};
|
|
4696
|
-
}
|
|
4697
|
-
});
|
|
4698
|
-
trace5.diagnostic({
|
|
4699
|
-
id: "database-roots",
|
|
4700
|
-
name: "Database Roots",
|
|
4701
|
-
fetch: async () => {
|
|
4702
|
-
return Array.from(this._spaceStateManager.roots.values()).map((root) => ({
|
|
4703
|
-
url: root.url,
|
|
4704
|
-
isLoaded: root.isLoaded,
|
|
4705
|
-
spaceKey: root.getSpaceKey(),
|
|
4706
|
-
inlineObjects: root.getInlineObjectCount(),
|
|
4707
|
-
linkedObjects: root.getLinkedObjectCount()
|
|
4708
|
-
}));
|
|
4709
|
-
}
|
|
4710
|
-
});
|
|
4711
|
-
trace5.diagnostic({
|
|
4712
|
-
id: "database-root-metrics",
|
|
4713
|
-
name: "Database Roots (with metrics)",
|
|
4714
|
-
fetch: async () => {
|
|
4715
|
-
return Array.from(this._spaceStateManager.roots.values()).map((root) => ({
|
|
4716
|
-
url: root.url,
|
|
4717
|
-
isLoaded: root.isLoaded,
|
|
4718
|
-
spaceKey: root.getSpaceKey(),
|
|
4719
|
-
inlineObjects: root.getInlineObjectCount(),
|
|
4720
|
-
linkedObjects: root.getLinkedObjectCount(),
|
|
4721
|
-
...root.measureMetrics() ?? {}
|
|
4722
|
-
}));
|
|
4723
|
-
}
|
|
4724
|
-
});
|
|
4725
|
-
}
|
|
4726
4822
|
};
|
|
4727
4823
|
|
|
4728
4824
|
// src/edge/echo-edge-replicator.ts
|
|
4825
|
+
import * as Automerge from "@automerge/automerge";
|
|
4729
4826
|
import { cbor as cbor2 } from "@automerge/automerge-repo";
|
|
4730
4827
|
import { Mutex, scheduleMicroTask as scheduleMicroTask2, scheduleTask as scheduleTask2 } from "@dxos/async";
|
|
4731
4828
|
import { Context as Context6, Resource as Resource11 } from "@dxos/context";
|
|
@@ -4735,27 +4832,26 @@ import { log as log13 } from "@dxos/log";
|
|
|
4735
4832
|
import { DocumentCodec, EdgeService } from "@dxos/protocols";
|
|
4736
4833
|
import { buf } from "@dxos/protocols/buf";
|
|
4737
4834
|
import { MessageSchema as RouterMessageSchema } from "@dxos/protocols/buf/dxos/edge/messenger_pb";
|
|
4738
|
-
import { bufferToArray as bufferToArray2 } from "@dxos/util";
|
|
4835
|
+
import { bufferToArray as bufferToArray2, setDeep } from "@dxos/util";
|
|
4739
4836
|
|
|
4740
4837
|
// src/edge/inflight-request-limiter.ts
|
|
4741
4838
|
import { Trigger as Trigger2 } from "@dxos/async";
|
|
4742
4839
|
import { Resource as Resource10 } from "@dxos/context";
|
|
4743
4840
|
import { log as log12 } from "@dxos/log";
|
|
4744
|
-
function _define_property17(obj, key, value) {
|
|
4745
|
-
if (key in obj) {
|
|
4746
|
-
Object.defineProperty(obj, key, {
|
|
4747
|
-
value,
|
|
4748
|
-
enumerable: true,
|
|
4749
|
-
configurable: true,
|
|
4750
|
-
writable: true
|
|
4751
|
-
});
|
|
4752
|
-
} else {
|
|
4753
|
-
obj[key] = value;
|
|
4754
|
-
}
|
|
4755
|
-
return obj;
|
|
4756
|
-
}
|
|
4757
4841
|
var __dxlog_file17 = "/__w/dxos/dxos/packages/core/echo/echo-pipeline/src/edge/inflight-request-limiter.ts";
|
|
4758
4842
|
var InflightRequestLimiter = class extends Resource10 {
|
|
4843
|
+
_config;
|
|
4844
|
+
/**
|
|
4845
|
+
* Decrement when we receive a sync message, increment when we send one.
|
|
4846
|
+
* Can't exceed _config.maxInflightRequests.
|
|
4847
|
+
* Resets after timeout to avoid replicator being stuck.
|
|
4848
|
+
*/
|
|
4849
|
+
_inflightRequestBalance = 0;
|
|
4850
|
+
_requestBarrier = new Trigger2();
|
|
4851
|
+
_resetBalanceTimeout;
|
|
4852
|
+
constructor(_config) {
|
|
4853
|
+
super(), this._config = _config;
|
|
4854
|
+
}
|
|
4759
4855
|
async _open() {
|
|
4760
4856
|
this._inflightRequestBalance = 0;
|
|
4761
4857
|
this._requestBarrier.reset();
|
|
@@ -4798,30 +4894,9 @@ var InflightRequestLimiter = class extends Resource10 {
|
|
|
4798
4894
|
clearInterval(this._resetBalanceTimeout);
|
|
4799
4895
|
}
|
|
4800
4896
|
}
|
|
4801
|
-
constructor(_config) {
|
|
4802
|
-
super(), _define_property17(this, "_config", void 0), /**
|
|
4803
|
-
* Decrement when we receive a sync message, increment when we send one.
|
|
4804
|
-
* Can't exceed _config.maxInflightRequests.
|
|
4805
|
-
* Resets after timeout to avoid replicator being stuck.
|
|
4806
|
-
*/
|
|
4807
|
-
_define_property17(this, "_inflightRequestBalance", void 0), _define_property17(this, "_requestBarrier", void 0), _define_property17(this, "_resetBalanceTimeout", void 0), this._config = _config, this._inflightRequestBalance = 0, this._requestBarrier = new Trigger2();
|
|
4808
|
-
}
|
|
4809
4897
|
};
|
|
4810
4898
|
|
|
4811
4899
|
// src/edge/echo-edge-replicator.ts
|
|
4812
|
-
function _define_property18(obj, key, value) {
|
|
4813
|
-
if (key in obj) {
|
|
4814
|
-
Object.defineProperty(obj, key, {
|
|
4815
|
-
value,
|
|
4816
|
-
enumerable: true,
|
|
4817
|
-
configurable: true,
|
|
4818
|
-
writable: true
|
|
4819
|
-
});
|
|
4820
|
-
} else {
|
|
4821
|
-
obj[key] = value;
|
|
4822
|
-
}
|
|
4823
|
-
return obj;
|
|
4824
|
-
}
|
|
4825
4900
|
function _ts_add_disposable_resource(env, value, async) {
|
|
4826
4901
|
if (value !== null && value !== void 0) {
|
|
4827
4902
|
if (typeof value !== "object" && typeof value !== "function") throw new TypeError("Object expected.");
|
|
@@ -4892,20 +4967,33 @@ var INITIAL_RESTART_DELAY = 500;
|
|
|
4892
4967
|
var RESTART_DELAY_JITTER = 250;
|
|
4893
4968
|
var MAX_RESTART_DELAY = 5e3;
|
|
4894
4969
|
var EchoEdgeReplicator = class {
|
|
4970
|
+
_edgeConnection;
|
|
4971
|
+
_edgeHttpClient;
|
|
4972
|
+
_mutex = new Mutex();
|
|
4973
|
+
_ctx = void 0;
|
|
4974
|
+
_context = null;
|
|
4975
|
+
_connectedSpaces = /* @__PURE__ */ new Set();
|
|
4976
|
+
_connections = /* @__PURE__ */ new Map();
|
|
4977
|
+
_sharePolicyEnabled = true;
|
|
4978
|
+
constructor({ edgeConnection, edgeHttpClient, disableSharePolicy }) {
|
|
4979
|
+
this._edgeConnection = edgeConnection;
|
|
4980
|
+
this._edgeHttpClient = edgeHttpClient;
|
|
4981
|
+
this._sharePolicyEnabled = !disableSharePolicy;
|
|
4982
|
+
}
|
|
4895
4983
|
async connect(context) {
|
|
4896
4984
|
log13("connecting...", {
|
|
4897
4985
|
peerId: context.peerId,
|
|
4898
4986
|
connectedSpaces: this._connectedSpaces.size
|
|
4899
4987
|
}, {
|
|
4900
4988
|
F: __dxlog_file18,
|
|
4901
|
-
L:
|
|
4989
|
+
L: 73,
|
|
4902
4990
|
S: this,
|
|
4903
4991
|
C: (f, a) => f(...a)
|
|
4904
4992
|
});
|
|
4905
4993
|
this._context = context;
|
|
4906
4994
|
this._ctx = Context6.default(void 0, {
|
|
4907
4995
|
F: __dxlog_file18,
|
|
4908
|
-
L:
|
|
4996
|
+
L: 75
|
|
4909
4997
|
});
|
|
4910
4998
|
this._ctx.onDispose(this._edgeConnection.onReconnected(() => {
|
|
4911
4999
|
this._ctx && scheduleMicroTask2(this._ctx, () => this._handleReconnect());
|
|
@@ -5004,7 +5092,7 @@ var EchoEdgeReplicator = class {
|
|
|
5004
5092
|
async _openConnection(spaceId, reconnects = 0) {
|
|
5005
5093
|
invariant14(this._context, void 0, {
|
|
5006
5094
|
F: __dxlog_file18,
|
|
5007
|
-
L:
|
|
5095
|
+
L: 136,
|
|
5008
5096
|
S: this,
|
|
5009
5097
|
A: [
|
|
5010
5098
|
"this._context",
|
|
@@ -5013,7 +5101,7 @@ var EchoEdgeReplicator = class {
|
|
|
5013
5101
|
});
|
|
5014
5102
|
invariant14(!this._connections.has(spaceId), void 0, {
|
|
5015
5103
|
F: __dxlog_file18,
|
|
5016
|
-
L:
|
|
5104
|
+
L: 137,
|
|
5017
5105
|
S: this,
|
|
5018
5106
|
A: [
|
|
5019
5107
|
"!this._connections.has(spaceId)",
|
|
@@ -5032,7 +5120,7 @@ var EchoEdgeReplicator = class {
|
|
|
5032
5120
|
spaceId
|
|
5033
5121
|
}, {
|
|
5034
5122
|
F: __dxlog_file18,
|
|
5035
|
-
L:
|
|
5123
|
+
L: 148,
|
|
5036
5124
|
S: this,
|
|
5037
5125
|
C: (f, a) => f(...a)
|
|
5038
5126
|
});
|
|
@@ -5043,7 +5131,7 @@ var EchoEdgeReplicator = class {
|
|
|
5043
5131
|
spaceId
|
|
5044
5132
|
}, {
|
|
5045
5133
|
F: __dxlog_file18,
|
|
5046
|
-
L:
|
|
5134
|
+
L: 152,
|
|
5047
5135
|
S: this,
|
|
5048
5136
|
C: (f, a) => f(...a)
|
|
5049
5137
|
});
|
|
@@ -5060,7 +5148,7 @@ var EchoEdgeReplicator = class {
|
|
|
5060
5148
|
restartDelay
|
|
5061
5149
|
}, {
|
|
5062
5150
|
F: __dxlog_file18,
|
|
5063
|
-
L:
|
|
5151
|
+
L: 163,
|
|
5064
5152
|
S: this,
|
|
5065
5153
|
C: (f, a) => f(...a)
|
|
5066
5154
|
});
|
|
@@ -5088,7 +5176,7 @@ var EchoEdgeReplicator = class {
|
|
|
5088
5176
|
restartDelay
|
|
5089
5177
|
}, {
|
|
5090
5178
|
F: __dxlog_file18,
|
|
5091
|
-
L:
|
|
5179
|
+
L: 180,
|
|
5092
5180
|
S: this,
|
|
5093
5181
|
C: (f, a) => f(...a)
|
|
5094
5182
|
});
|
|
@@ -5105,27 +5193,57 @@ var EchoEdgeReplicator = class {
|
|
|
5105
5193
|
this._connections.set(spaceId, connection);
|
|
5106
5194
|
await connection.open();
|
|
5107
5195
|
}
|
|
5108
|
-
constructor({ edgeConnection, edgeHttpClient, disableSharePolicy }) {
|
|
5109
|
-
_define_property18(this, "_edgeConnection", void 0);
|
|
5110
|
-
_define_property18(this, "_edgeHttpClient", void 0);
|
|
5111
|
-
_define_property18(this, "_mutex", new Mutex());
|
|
5112
|
-
_define_property18(this, "_ctx", void 0);
|
|
5113
|
-
_define_property18(this, "_context", null);
|
|
5114
|
-
_define_property18(this, "_connectedSpaces", /* @__PURE__ */ new Set());
|
|
5115
|
-
_define_property18(this, "_connections", /* @__PURE__ */ new Map());
|
|
5116
|
-
_define_property18(this, "_sharePolicyEnabled", true);
|
|
5117
|
-
this._edgeConnection = edgeConnection;
|
|
5118
|
-
this._edgeHttpClient = edgeHttpClient;
|
|
5119
|
-
this._sharePolicyEnabled = !disableSharePolicy;
|
|
5120
|
-
}
|
|
5121
5196
|
};
|
|
5122
5197
|
var MAX_INFLIGHT_REQUESTS = 5;
|
|
5123
5198
|
var MAX_RATE_LIMIT_WAIT_TIME_MS = 3e3;
|
|
5124
5199
|
var EdgeReplicatorConnection = class extends Resource11 {
|
|
5200
|
+
_connectionId = randomUUID();
|
|
5201
|
+
_edgeConnection;
|
|
5202
|
+
_edgeHttpClient;
|
|
5203
|
+
_remotePeerId = null;
|
|
5204
|
+
_targetServiceId;
|
|
5205
|
+
_spaceId;
|
|
5206
|
+
_context;
|
|
5207
|
+
_sharedPolicyEnabled;
|
|
5208
|
+
_onRemoteConnected;
|
|
5209
|
+
_onRemoteDisconnected;
|
|
5210
|
+
_onRestartRequested;
|
|
5211
|
+
_sequence = 0;
|
|
5212
|
+
_requestLimiter = new InflightRequestLimiter({
|
|
5213
|
+
maxInflightRequests: MAX_INFLIGHT_REQUESTS,
|
|
5214
|
+
resetBalanceTimeoutMs: MAX_RATE_LIMIT_WAIT_TIME_MS
|
|
5215
|
+
});
|
|
5216
|
+
_readableStreamController;
|
|
5217
|
+
readable;
|
|
5218
|
+
writable;
|
|
5219
|
+
constructor({ edgeConnection, edgeHttpClient, spaceId, context, sharedPolicyEnabled, onRemoteConnected, onRemoteDisconnected, onRestartRequested }) {
|
|
5220
|
+
super();
|
|
5221
|
+
this._edgeConnection = edgeConnection;
|
|
5222
|
+
this._edgeHttpClient = edgeHttpClient;
|
|
5223
|
+
this._spaceId = spaceId;
|
|
5224
|
+
this._context = context;
|
|
5225
|
+
this._remotePeerId = `${EdgeService.AUTOMERGE_REPLICATOR}:${spaceId}-${this._connectionId}`;
|
|
5226
|
+
this._targetServiceId = `${EdgeService.AUTOMERGE_REPLICATOR}:${spaceId}`;
|
|
5227
|
+
this._sharedPolicyEnabled = sharedPolicyEnabled;
|
|
5228
|
+
this._onRemoteConnected = onRemoteConnected;
|
|
5229
|
+
this._onRemoteDisconnected = onRemoteDisconnected;
|
|
5230
|
+
this._onRestartRequested = onRestartRequested;
|
|
5231
|
+
this.readable = new ReadableStream({
|
|
5232
|
+
start: (controller) => {
|
|
5233
|
+
this._readableStreamController = controller;
|
|
5234
|
+
}
|
|
5235
|
+
});
|
|
5236
|
+
this.writable = new WritableStream({
|
|
5237
|
+
write: async (message, controller) => {
|
|
5238
|
+
await this._requestLimiter.rateLimit(message);
|
|
5239
|
+
await this._sendMessage(message);
|
|
5240
|
+
}
|
|
5241
|
+
});
|
|
5242
|
+
}
|
|
5125
5243
|
async _open(ctx) {
|
|
5126
5244
|
log13("opening...", void 0, {
|
|
5127
5245
|
F: __dxlog_file18,
|
|
5128
|
-
L:
|
|
5246
|
+
L: 273,
|
|
5129
5247
|
S: this,
|
|
5130
5248
|
C: (f, a) => f(...a)
|
|
5131
5249
|
});
|
|
@@ -5140,7 +5258,7 @@ var EdgeReplicatorConnection = class extends Resource11 {
|
|
|
5140
5258
|
if (firstReconnect) {
|
|
5141
5259
|
log13.verbose("first reconnect skipped", void 0, {
|
|
5142
5260
|
F: __dxlog_file18,
|
|
5143
|
-
L:
|
|
5261
|
+
L: 288,
|
|
5144
5262
|
S: this,
|
|
5145
5263
|
C: (f, a) => f(...a)
|
|
5146
5264
|
});
|
|
@@ -5155,7 +5273,7 @@ var EdgeReplicatorConnection = class extends Resource11 {
|
|
|
5155
5273
|
async _close() {
|
|
5156
5274
|
log13("closing...", void 0, {
|
|
5157
5275
|
F: __dxlog_file18,
|
|
5158
|
-
L:
|
|
5276
|
+
L: 301,
|
|
5159
5277
|
S: this,
|
|
5160
5278
|
C: (f, a) => f(...a)
|
|
5161
5279
|
});
|
|
@@ -5166,7 +5284,7 @@ var EdgeReplicatorConnection = class extends Resource11 {
|
|
|
5166
5284
|
get peerId() {
|
|
5167
5285
|
invariant14(this._remotePeerId, "Not connected", {
|
|
5168
5286
|
F: __dxlog_file18,
|
|
5169
|
-
L:
|
|
5287
|
+
L: 310,
|
|
5170
5288
|
S: this,
|
|
5171
5289
|
A: [
|
|
5172
5290
|
"this._remotePeerId",
|
|
@@ -5191,7 +5309,7 @@ var EdgeReplicatorConnection = class extends Resource11 {
|
|
|
5191
5309
|
remoteId: this._remotePeerId
|
|
5192
5310
|
}, {
|
|
5193
5311
|
F: __dxlog_file18,
|
|
5194
|
-
L:
|
|
5312
|
+
L: 325,
|
|
5195
5313
|
S: this,
|
|
5196
5314
|
C: (f, a) => f(...a)
|
|
5197
5315
|
});
|
|
@@ -5212,12 +5330,11 @@ var EdgeReplicatorConnection = class extends Resource11 {
|
|
|
5212
5330
|
}
|
|
5213
5331
|
const payload = cbor2.decode(message.payload.value);
|
|
5214
5332
|
log13.verbose("received", {
|
|
5215
|
-
|
|
5216
|
-
documentId: payload.type === "sync" && payload.documentId,
|
|
5333
|
+
...getMessageInfo(payload),
|
|
5217
5334
|
remoteId: this._remotePeerId
|
|
5218
5335
|
}, {
|
|
5219
5336
|
F: __dxlog_file18,
|
|
5220
|
-
L:
|
|
5337
|
+
L: 354,
|
|
5221
5338
|
S: this,
|
|
5222
5339
|
C: (f, a) => f(...a)
|
|
5223
5340
|
});
|
|
@@ -5248,7 +5365,7 @@ var EdgeReplicatorConnection = class extends Resource11 {
|
|
|
5248
5365
|
]));
|
|
5249
5366
|
}
|
|
5250
5367
|
_processMessage(message) {
|
|
5251
|
-
if (
|
|
5368
|
+
if (isErrorMessage(message)) {
|
|
5252
5369
|
this._onRestartRequested();
|
|
5253
5370
|
return;
|
|
5254
5371
|
}
|
|
@@ -5257,13 +5374,20 @@ var EdgeReplicatorConnection = class extends Resource11 {
|
|
|
5257
5374
|
}
|
|
5258
5375
|
async _sendMessage(message) {
|
|
5259
5376
|
message.targetId = this._targetServiceId;
|
|
5377
|
+
setDeep(message, [
|
|
5378
|
+
"metadata",
|
|
5379
|
+
"dxos_sequence"
|
|
5380
|
+
], this._getSequence());
|
|
5381
|
+
setDeep(message, [
|
|
5382
|
+
"metadata",
|
|
5383
|
+
"dxos_connectionId"
|
|
5384
|
+
], this._connectionId);
|
|
5260
5385
|
log13.verbose("sending...", {
|
|
5261
|
-
|
|
5262
|
-
documentId: message.type === "sync" && message.documentId,
|
|
5386
|
+
...getMessageInfo(message),
|
|
5263
5387
|
remoteId: this._remotePeerId
|
|
5264
5388
|
}, {
|
|
5265
5389
|
F: __dxlog_file18,
|
|
5266
|
-
L:
|
|
5390
|
+
L: 407,
|
|
5267
5391
|
S: this,
|
|
5268
5392
|
C: (f, a) => f(...a)
|
|
5269
5393
|
});
|
|
@@ -5284,41 +5408,29 @@ var EdgeReplicatorConnection = class extends Resource11 {
|
|
|
5284
5408
|
err
|
|
5285
5409
|
}, {
|
|
5286
5410
|
F: __dxlog_file18,
|
|
5287
|
-
L:
|
|
5411
|
+
L: 426,
|
|
5288
5412
|
S: this,
|
|
5289
5413
|
C: (f, a) => f(...a)
|
|
5290
5414
|
});
|
|
5291
5415
|
}
|
|
5292
5416
|
}
|
|
5293
|
-
|
|
5294
|
-
|
|
5295
|
-
maxInflightRequests: MAX_INFLIGHT_REQUESTS,
|
|
5296
|
-
resetBalanceTimeoutMs: MAX_RATE_LIMIT_WAIT_TIME_MS
|
|
5297
|
-
})), _define_property18(this, "_readableStreamController", void 0), _define_property18(this, "readable", void 0), _define_property18(this, "writable", void 0);
|
|
5298
|
-
this._edgeConnection = edgeConnection;
|
|
5299
|
-
this._edgeHttpClient = edgeHttpClient;
|
|
5300
|
-
this._spaceId = spaceId;
|
|
5301
|
-
this._context = context;
|
|
5302
|
-
this._remotePeerId = `${EdgeService.AUTOMERGE_REPLICATOR}:${spaceId}-${randomUUID()}`;
|
|
5303
|
-
this._targetServiceId = `${EdgeService.AUTOMERGE_REPLICATOR}:${spaceId}`;
|
|
5304
|
-
this._sharedPolicyEnabled = sharedPolicyEnabled;
|
|
5305
|
-
this._onRemoteConnected = onRemoteConnected;
|
|
5306
|
-
this._onRemoteDisconnected = onRemoteDisconnected;
|
|
5307
|
-
this._onRestartRequested = onRestartRequested;
|
|
5308
|
-
this.readable = new ReadableStream({
|
|
5309
|
-
start: (controller) => {
|
|
5310
|
-
this._readableStreamController = controller;
|
|
5311
|
-
}
|
|
5312
|
-
});
|
|
5313
|
-
this.writable = new WritableStream({
|
|
5314
|
-
write: async (message, controller) => {
|
|
5315
|
-
await this._requestLimiter.rateLimit(message);
|
|
5316
|
-
await this._sendMessage(message);
|
|
5317
|
-
}
|
|
5318
|
-
});
|
|
5417
|
+
_getSequence() {
|
|
5418
|
+
return this._sequence++;
|
|
5319
5419
|
}
|
|
5320
5420
|
};
|
|
5321
|
-
var
|
|
5421
|
+
var isErrorMessage = (message) => message.type === "error";
|
|
5422
|
+
var getMessageInfo = (msg) => {
|
|
5423
|
+
const { have, heads, need, changes } = msg.type === "sync" ? Automerge.decodeSyncMessage(msg.data) : {};
|
|
5424
|
+
return {
|
|
5425
|
+
type: msg.type,
|
|
5426
|
+
documentId: "documentId" in msg ? msg.documentId : void 0,
|
|
5427
|
+
have,
|
|
5428
|
+
heads,
|
|
5429
|
+
need,
|
|
5430
|
+
changes: changes?.length,
|
|
5431
|
+
sequence: msg.metadata?.dxos_sequence
|
|
5432
|
+
};
|
|
5433
|
+
};
|
|
5322
5434
|
|
|
5323
5435
|
// src/util.ts
|
|
5324
5436
|
import { ObjectStructure as ObjectStructure2, decodeReference } from "@dxos/echo-protocol";
|
|
@@ -5373,6 +5485,7 @@ export {
|
|
|
5373
5485
|
diffCollectionState,
|
|
5374
5486
|
encodingOptions,
|
|
5375
5487
|
filterMatchObject,
|
|
5488
|
+
filterMatchObjectJSON,
|
|
5376
5489
|
filterMatchValue,
|
|
5377
5490
|
findInlineObjectOfType,
|
|
5378
5491
|
getSpaceIdFromCollectionId,
|