@dxos/echo-pipeline 0.8.2-main.fbd8ed0 → 0.8.2-staging.4d6ad0f
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-TPEBUDNJ.mjs → chunk-3XSXS5EX.mjs} +7 -13
- package/dist/lib/browser/chunk-3XSXS5EX.mjs.map +7 -0
- package/dist/lib/browser/chunk-CGS2ULMK.mjs +11 -0
- package/dist/lib/browser/chunk-CGS2ULMK.mjs.map +7 -0
- package/dist/lib/browser/chunk-TQJTKNMS.mjs +126 -0
- package/dist/lib/browser/chunk-TQJTKNMS.mjs.map +7 -0
- package/dist/lib/browser/filter/index.mjs +11 -0
- package/dist/lib/browser/filter/index.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +1255 -392
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +192 -11
- package/dist/lib/browser/testing/index.mjs.map +4 -4
- package/dist/lib/node/chunk-HOPOFWAL.cjs +147 -0
- package/dist/lib/node/chunk-HOPOFWAL.cjs.map +7 -0
- package/dist/lib/node/chunk-Q7SFCCGT.cjs +33 -0
- package/dist/lib/node/chunk-Q7SFCCGT.cjs.map +7 -0
- package/dist/lib/node/{chunk-QD3U65NM.cjs → chunk-SG2PL5RH.cjs} +10 -16
- package/dist/lib/node/chunk-SG2PL5RH.cjs.map +7 -0
- package/dist/lib/node/filter/index.cjs +32 -0
- package/dist/lib/node/filter/index.cjs.map +7 -0
- package/dist/lib/node/index.cjs +1255 -401
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/testing/index.cjs +197 -20
- package/dist/lib/node/testing/index.cjs.map +4 -4
- package/dist/lib/node-esm/{chunk-S5YERQ4D.mjs → chunk-3BZP75TJ.mjs} +7 -13
- package/dist/lib/node-esm/chunk-3BZP75TJ.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-HSLMI22Q.mjs +11 -0
- package/dist/lib/node-esm/chunk-HSLMI22Q.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-RVK35BS7.mjs +126 -0
- package/dist/lib/node-esm/chunk-RVK35BS7.mjs.map +7 -0
- package/dist/lib/node-esm/filter/index.mjs +11 -0
- package/dist/lib/node-esm/filter/index.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +1255 -392
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/testing/index.mjs +192 -11
- package/dist/lib/node-esm/testing/index.mjs.map +4 -4
- package/dist/types/src/automerge/automerge-host.d.ts +1 -2
- package/dist/types/src/automerge/automerge-host.d.ts.map +1 -1
- package/dist/types/src/automerge/collection-synchronizer.d.ts.map +1 -1
- package/dist/types/src/automerge/echo-data-monitor.d.ts.map +1 -1
- package/dist/types/src/automerge/echo-network-adapter.d.ts.map +1 -1
- package/dist/types/src/automerge/heads-store.d.ts.map +1 -1
- package/dist/types/src/automerge/mesh-echo-replicator-connection.d.ts.map +1 -1
- package/dist/types/src/automerge/mesh-echo-replicator.d.ts.map +1 -1
- package/dist/types/src/db-host/data-service.d.ts.map +1 -1
- package/dist/types/src/db-host/database-root.d.ts +5 -5
- package/dist/types/src/db-host/database-root.d.ts.map +1 -1
- package/dist/types/src/db-host/documents-iterator.d.ts +1 -1
- package/dist/types/src/db-host/documents-iterator.d.ts.map +1 -1
- package/dist/types/src/db-host/documents-synchronizer.d.ts +2 -2
- package/dist/types/src/db-host/documents-synchronizer.d.ts.map +1 -1
- package/dist/types/src/db-host/echo-host.d.ts +12 -1
- package/dist/types/src/db-host/echo-host.d.ts.map +1 -1
- package/dist/types/src/db-host/index.d.ts +0 -1
- package/dist/types/src/db-host/index.d.ts.map +1 -1
- package/dist/types/src/db-host/query-service.d.ts +2 -0
- package/dist/types/src/db-host/query-service.d.ts.map +1 -1
- package/dist/types/src/db-host/space-state-manager.d.ts +3 -2
- package/dist/types/src/db-host/space-state-manager.d.ts.map +1 -1
- package/dist/types/src/edge/echo-edge-replicator.d.ts.map +1 -1
- package/dist/types/src/edge/inflight-request-limiter.d.ts.map +1 -1
- package/dist/types/src/filter/filter-match.d.ts +13 -0
- package/dist/types/src/filter/filter-match.d.ts.map +1 -0
- package/dist/types/src/filter/filter-match.test.d.ts +2 -0
- package/dist/types/src/filter/filter-match.test.d.ts.map +1 -0
- package/dist/types/src/filter/index.d.ts +2 -0
- package/dist/types/src/filter/index.d.ts.map +1 -0
- package/dist/types/src/index.d.ts +1 -0
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/metadata/metadata-store.d.ts.map +1 -1
- package/dist/types/src/pipeline/pipeline.d.ts.map +1 -1
- package/dist/types/src/pipeline/timeframe-clock.d.ts.map +1 -1
- package/dist/types/src/query/errors.d.ts +23 -0
- package/dist/types/src/query/errors.d.ts.map +1 -0
- package/dist/types/src/query/index.d.ts +5 -0
- package/dist/types/src/query/index.d.ts.map +1 -0
- package/dist/types/src/query/plan.d.ts +132 -0
- package/dist/types/src/query/plan.d.ts.map +1 -0
- package/dist/types/src/query/query-executor.d.ts +83 -0
- package/dist/types/src/query/query-executor.d.ts.map +1 -0
- package/dist/types/src/query/query-planner.d.ts +33 -0
- package/dist/types/src/query/query-planner.d.ts.map +1 -0
- package/dist/types/src/query/query-planner.test.d.ts +2 -0
- package/dist/types/src/query/query-planner.test.d.ts.map +1 -0
- package/dist/types/src/space/admission-discovery-extension.d.ts.map +1 -1
- package/dist/types/src/space/control-pipeline.d.ts.map +1 -1
- package/dist/types/src/space/space-manager.d.ts.map +1 -1
- package/dist/types/src/space/space-protocol.d.ts.map +1 -1
- package/dist/types/src/space/space.d.ts.map +1 -1
- package/dist/types/src/testing/index.d.ts +2 -0
- package/dist/types/src/testing/index.d.ts.map +1 -1
- package/dist/types/src/testing/test-agent-builder.d.ts.map +1 -1
- package/dist/types/src/testing/test-data.d.ts +18 -0
- package/dist/types/src/testing/test-data.d.ts.map +1 -0
- package/dist/types/src/testing/test-network-adapter.d.ts.map +1 -1
- package/dist/types/src/testing/test-schema.d.ts +39 -0
- package/dist/types/src/testing/test-schema.d.ts.map +1 -0
- package/dist/types/src/util.d.ts +2 -2
- package/dist/types/src/util.d.ts.map +1 -1
- package/package.json +43 -35
- package/src/automerge/automerge-host.ts +29 -38
- package/src/automerge/automerge-repo.test.ts +1 -1
- package/src/automerge/collection-synchronizer.ts +8 -8
- package/src/automerge/echo-data-monitor.ts +12 -12
- package/src/automerge/echo-network-adapter.ts +12 -12
- package/src/automerge/heads-store.ts +1 -1
- package/src/automerge/mesh-echo-replicator-connection.ts +3 -3
- package/src/automerge/mesh-echo-replicator.ts +2 -2
- package/src/db-host/data-service.ts +2 -2
- package/src/db-host/database-root.ts +6 -7
- package/src/db-host/documents-iterator.ts +5 -5
- package/src/db-host/documents-synchronizer.ts +11 -11
- package/src/db-host/echo-host.ts +40 -14
- package/src/db-host/index.ts +0 -1
- package/src/db-host/query-service.ts +38 -33
- package/src/db-host/space-state-manager.ts +13 -3
- package/src/edge/echo-edge-replicator.ts +7 -7
- package/src/edge/inflight-request-limiter.ts +4 -4
- package/src/filter/filter-match.test.ts +101 -0
- package/src/filter/filter-match.ts +174 -0
- package/src/filter/index.ts +5 -0
- package/src/index.ts +1 -0
- package/src/metadata/metadata-store.ts +13 -13
- package/src/pipeline/pipeline-stress.test.ts +9 -9
- package/src/pipeline/pipeline.ts +13 -13
- package/src/pipeline/timeframe-clock.ts +5 -5
- package/src/query/errors.ts +7 -0
- package/src/query/index.ts +8 -0
- package/src/query/plan.ts +179 -0
- package/src/query/query-executor.ts +648 -0
- package/src/query/query-planner.test.ts +613 -0
- package/src/query/query-planner.ts +470 -0
- package/src/space/admission-discovery-extension.ts +2 -2
- package/src/space/control-pipeline.ts +8 -8
- package/src/space/space-manager.ts +3 -3
- package/src/space/space-protocol.browser.test.ts +1 -0
- package/src/space/space-protocol.test.ts +1 -0
- package/src/space/space-protocol.ts +4 -4
- package/src/space/space.ts +5 -5
- package/src/testing/index.ts +2 -0
- package/src/testing/test-agent-builder.ts +6 -6
- package/src/testing/test-data.ts +127 -0
- package/src/testing/test-network-adapter.ts +7 -7
- package/src/testing/test-replicator.ts +2 -2
- package/src/testing/test-schema.ts +53 -0
- package/src/util.ts +7 -3
- package/dist/lib/browser/chunk-TPEBUDNJ.mjs.map +0 -7
- package/dist/lib/node/chunk-QD3U65NM.cjs.map +0 -7
- package/dist/lib/node-esm/chunk-S5YERQ4D.mjs.map +0 -7
- package/dist/types/src/db-host/query-state.d.ts +0 -41
- package/dist/types/src/db-host/query-state.d.ts.map +0 -1
- package/src/db-host/query-state.ts +0 -224
package/dist/lib/node/index.cjs
CHANGED
|
@@ -28,50 +28,56 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
28
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
29
|
var node_exports = {};
|
|
30
30
|
__export(node_exports, {
|
|
31
|
-
AuthExtension: () =>
|
|
32
|
-
AuthStatus: () =>
|
|
31
|
+
AuthExtension: () => import_chunk_SG2PL5RH.AuthExtension,
|
|
32
|
+
AuthStatus: () => import_chunk_SG2PL5RH.AuthStatus,
|
|
33
33
|
AutomergeHost: () => AutomergeHost,
|
|
34
|
-
CredentialRetrieverExtension: () =>
|
|
35
|
-
CredentialServerExtension: () =>
|
|
34
|
+
CredentialRetrieverExtension: () => import_chunk_SG2PL5RH.CredentialRetrieverExtension,
|
|
35
|
+
CredentialServerExtension: () => import_chunk_SG2PL5RH.CredentialServerExtension,
|
|
36
36
|
DataServiceImpl: () => DataServiceImpl,
|
|
37
37
|
DatabaseRoot: () => DatabaseRoot,
|
|
38
38
|
DocumentsSynchronizer: () => DocumentsSynchronizer,
|
|
39
39
|
EchoDataMonitor: () => EchoDataMonitor,
|
|
40
40
|
EchoEdgeReplicator: () => EchoEdgeReplicator,
|
|
41
41
|
EchoHost: () => EchoHost,
|
|
42
|
+
ExecutionTrace: () => ExecutionTrace,
|
|
42
43
|
FIND_PARAMS: () => FIND_PARAMS,
|
|
43
44
|
LevelDBStorageAdapter: () => LevelDBStorageAdapter,
|
|
44
|
-
MOCK_AUTH_PROVIDER: () =>
|
|
45
|
-
MOCK_AUTH_VERIFIER: () =>
|
|
45
|
+
MOCK_AUTH_PROVIDER: () => import_chunk_SG2PL5RH.MOCK_AUTH_PROVIDER,
|
|
46
|
+
MOCK_AUTH_VERIFIER: () => import_chunk_SG2PL5RH.MOCK_AUTH_VERIFIER,
|
|
46
47
|
MeshEchoReplicator: () => MeshEchoReplicator,
|
|
47
|
-
MetadataStore: () =>
|
|
48
|
-
Pipeline: () =>
|
|
48
|
+
MetadataStore: () => import_chunk_SG2PL5RH.MetadataStore,
|
|
49
|
+
Pipeline: () => import_chunk_SG2PL5RH.Pipeline,
|
|
50
|
+
QueryExecutor: () => QueryExecutor,
|
|
51
|
+
QueryPlan: () => QueryPlan,
|
|
52
|
+
QueryPlanner: () => QueryPlanner,
|
|
49
53
|
QueryServiceImpl: () => QueryServiceImpl,
|
|
50
|
-
|
|
51
|
-
Space: () => import_chunk_QD3U65NM.Space,
|
|
54
|
+
Space: () => import_chunk_SG2PL5RH.Space,
|
|
52
55
|
SpaceDocumentListUpdatedEvent: () => SpaceDocumentListUpdatedEvent,
|
|
53
|
-
SpaceManager: () =>
|
|
54
|
-
SpaceProtocol: () =>
|
|
55
|
-
SpaceProtocolSession: () =>
|
|
56
|
+
SpaceManager: () => import_chunk_SG2PL5RH.SpaceManager,
|
|
57
|
+
SpaceProtocol: () => import_chunk_SG2PL5RH.SpaceProtocol,
|
|
58
|
+
SpaceProtocolSession: () => import_chunk_SG2PL5RH.SpaceProtocolSession,
|
|
56
59
|
SpaceStateManager: () => SpaceStateManager,
|
|
57
|
-
TimeframeClock: () =>
|
|
58
|
-
codec: () =>
|
|
59
|
-
createIdFromSpaceKey: () =>
|
|
60
|
-
createMappedFeedWriter: () =>
|
|
60
|
+
TimeframeClock: () => import_chunk_SG2PL5RH.TimeframeClock,
|
|
61
|
+
codec: () => import_chunk_SG2PL5RH.codec,
|
|
62
|
+
createIdFromSpaceKey: () => import_chunk_SG2PL5RH.createIdFromSpaceKey,
|
|
63
|
+
createMappedFeedWriter: () => import_chunk_SG2PL5RH.createMappedFeedWriter,
|
|
61
64
|
deriveCollectionIdFromSpaceId: () => deriveCollectionIdFromSpaceId,
|
|
62
65
|
diffCollectionState: () => diffCollectionState,
|
|
63
66
|
encodingOptions: () => encodingOptions,
|
|
67
|
+
filterMatchObject: () => import_chunk_HOPOFWAL.filterMatchObject,
|
|
68
|
+
filterMatchValue: () => import_chunk_HOPOFWAL.filterMatchValue,
|
|
64
69
|
findInlineObjectOfType: () => findInlineObjectOfType,
|
|
65
70
|
getSpaceIdFromCollectionId: () => getSpaceIdFromCollectionId,
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
valueEncoding: () => import_chunk_QD3U65NM.valueEncoding
|
|
71
|
+
hasInvitationExpired: () => import_chunk_SG2PL5RH.hasInvitationExpired,
|
|
72
|
+
mapFeedIndexesToTimeframe: () => import_chunk_SG2PL5RH.mapFeedIndexesToTimeframe,
|
|
73
|
+
mapTimeframeToFeedIndexes: () => import_chunk_SG2PL5RH.mapTimeframeToFeedIndexes,
|
|
74
|
+
startAfter: () => import_chunk_SG2PL5RH.startAfter,
|
|
75
|
+
valueEncoding: () => import_chunk_SG2PL5RH.valueEncoding
|
|
72
76
|
});
|
|
73
77
|
module.exports = __toCommonJS(node_exports);
|
|
74
|
-
var
|
|
78
|
+
var import_chunk_HOPOFWAL = require("./chunk-HOPOFWAL.cjs");
|
|
79
|
+
var import_chunk_SG2PL5RH = require("./chunk-SG2PL5RH.cjs");
|
|
80
|
+
var import_chunk_Q7SFCCGT = require("./chunk-Q7SFCCGT.cjs");
|
|
75
81
|
var import_async = require("@dxos/async");
|
|
76
82
|
var import_stream = require("@dxos/codec-protobuf/stream");
|
|
77
83
|
var import_invariant = require("@dxos/invariant");
|
|
@@ -86,6 +92,7 @@ var import_automerge2 = require("@automerge/automerge");
|
|
|
86
92
|
var import_automerge_repo = require("@automerge/automerge-repo");
|
|
87
93
|
var import_async3 = require("@dxos/async");
|
|
88
94
|
var import_context2 = require("@dxos/context");
|
|
95
|
+
var import_echo_protocol = require("@dxos/echo-protocol");
|
|
89
96
|
var import_invariant3 = require("@dxos/invariant");
|
|
90
97
|
var import_keys2 = require("@dxos/keys");
|
|
91
98
|
var import_log3 = require("@dxos/log");
|
|
@@ -123,63 +130,67 @@ var import_tracing3 = require("@dxos/tracing");
|
|
|
123
130
|
var import_util5 = require("@dxos/util");
|
|
124
131
|
var import_context7 = require("@dxos/context");
|
|
125
132
|
var import_debug = require("@dxos/debug");
|
|
126
|
-
var
|
|
133
|
+
var import_echo_protocol2 = require("@dxos/echo-protocol");
|
|
127
134
|
var import_indexing2 = require("@dxos/indexing");
|
|
128
135
|
var import_invariant8 = require("@dxos/invariant");
|
|
129
136
|
var import_indexing3 = require("@dxos/protocols/proto/dxos/echo/indexing");
|
|
130
137
|
var import_tracing4 = require("@dxos/tracing");
|
|
131
138
|
var A3 = __toESM(require("@automerge/automerge"));
|
|
132
139
|
var import_context8 = require("@dxos/context");
|
|
133
|
-
var
|
|
140
|
+
var import_echo_protocol3 = require("@dxos/echo-protocol");
|
|
134
141
|
var import_invariant9 = require("@dxos/invariant");
|
|
135
142
|
var import_log8 = require("@dxos/log");
|
|
136
143
|
var import_protocols3 = require("@dxos/protocols");
|
|
137
144
|
var import_automerge4 = require("@automerge/automerge");
|
|
145
|
+
var import_effect = require("effect");
|
|
138
146
|
var import_async6 = require("@dxos/async");
|
|
139
147
|
var import_stream2 = require("@dxos/codec-protobuf/stream");
|
|
140
148
|
var import_context9 = require("@dxos/context");
|
|
149
|
+
var import_debug2 = require("@dxos/debug");
|
|
150
|
+
var import_echo_protocol4 = require("@dxos/echo-protocol");
|
|
141
151
|
var import_log9 = require("@dxos/log");
|
|
142
152
|
var import_protocols4 = require("@dxos/protocols");
|
|
143
153
|
var import_tracing5 = require("@dxos/tracing");
|
|
154
|
+
var import_effect2 = require("effect");
|
|
144
155
|
var import_context10 = require("@dxos/context");
|
|
145
|
-
var
|
|
156
|
+
var import_echo_protocol5 = require("@dxos/echo-protocol");
|
|
157
|
+
var import_indexing4 = require("@dxos/indexing");
|
|
146
158
|
var import_invariant10 = require("@dxos/invariant");
|
|
147
159
|
var import_keys5 = require("@dxos/keys");
|
|
160
|
+
var import_log10 = require("@dxos/log");
|
|
148
161
|
var import_protocols5 = require("@dxos/protocols");
|
|
149
|
-
var import_tracing6 = require("@dxos/tracing");
|
|
150
162
|
var import_util6 = require("@dxos/util");
|
|
163
|
+
var import_invariant11 = require("@dxos/invariant");
|
|
164
|
+
var import_errors = require("@dxos/errors");
|
|
151
165
|
var import_automerge_repo4 = require("@automerge/automerge-repo");
|
|
152
166
|
var import_lodash = __toESM(require("lodash.isequal"));
|
|
153
167
|
var import_async7 = require("@dxos/async");
|
|
154
168
|
var import_context11 = require("@dxos/context");
|
|
169
|
+
var import_invariant12 = require("@dxos/invariant");
|
|
155
170
|
var import_automerge_repo5 = require("@automerge/automerge-repo");
|
|
156
|
-
var
|
|
157
|
-
var
|
|
171
|
+
var import_echo_protocol6 = require("@dxos/echo-protocol");
|
|
172
|
+
var import_invariant13 = require("@dxos/invariant");
|
|
158
173
|
var A4 = __toESM(require("@automerge/automerge"));
|
|
159
|
-
var
|
|
174
|
+
var import_log11 = require("@dxos/log");
|
|
160
175
|
var import_automerge_repo6 = require("@automerge/automerge-repo");
|
|
161
176
|
var import_async8 = require("@dxos/async");
|
|
162
177
|
var import_context12 = require("@dxos/context");
|
|
163
178
|
var import_crypto = require("@dxos/crypto");
|
|
164
|
-
var
|
|
165
|
-
var
|
|
179
|
+
var import_invariant14 = require("@dxos/invariant");
|
|
180
|
+
var import_log12 = require("@dxos/log");
|
|
166
181
|
var import_protocols6 = require("@dxos/protocols");
|
|
167
182
|
var import_buf = require("@dxos/protocols/buf");
|
|
168
183
|
var import_messenger_pb = require("@dxos/protocols/buf/dxos/edge/messenger_pb");
|
|
169
184
|
var import_util7 = require("@dxos/util");
|
|
170
185
|
var import_async9 = require("@dxos/async");
|
|
171
186
|
var import_context13 = require("@dxos/context");
|
|
172
|
-
var
|
|
173
|
-
var
|
|
187
|
+
var import_log13 = require("@dxos/log");
|
|
188
|
+
var import_echo_protocol7 = require("@dxos/echo-protocol");
|
|
174
189
|
var __dxlog_file = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/db-host/documents-synchronizer.ts";
|
|
175
190
|
var MAX_UPDATE_FREQ = 10;
|
|
176
191
|
var DocumentsSynchronizer = class extends import_context.Resource {
|
|
177
192
|
constructor(_params) {
|
|
178
|
-
super();
|
|
179
|
-
this._params = _params;
|
|
180
|
-
this._syncStates = /* @__PURE__ */ new Map();
|
|
181
|
-
this._pendingUpdates = /* @__PURE__ */ new Set();
|
|
182
|
-
this._sendUpdatesJob = void 0;
|
|
193
|
+
super(), this._params = _params, this._syncStates = /* @__PURE__ */ new Map(), this._pendingUpdates = /* @__PURE__ */ new Set(), this._sendUpdatesJob = void 0;
|
|
183
194
|
}
|
|
184
195
|
addDocuments(documentIds, retryCounter = 0) {
|
|
185
196
|
if (retryCounter > 3) {
|
|
@@ -583,13 +594,7 @@ function _ts_decorate2(decorators, target, key, desc) {
|
|
|
583
594
|
var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/automerge/echo-network-adapter.ts";
|
|
584
595
|
var EchoNetworkAdapter = class extends import_automerge_repo2.NetworkAdapter {
|
|
585
596
|
constructor(_params) {
|
|
586
|
-
super();
|
|
587
|
-
this._params = _params;
|
|
588
|
-
this._replicators = /* @__PURE__ */ new Set();
|
|
589
|
-
this._connections = /* @__PURE__ */ new Map();
|
|
590
|
-
this._lifecycleState = import_context4.LifecycleState.CLOSED;
|
|
591
|
-
this._connected = new import_async5.Trigger();
|
|
592
|
-
this._ready = new import_async5.Trigger();
|
|
597
|
+
super(), this._params = _params, this._replicators = /* @__PURE__ */ new Set(), this._connections = /* @__PURE__ */ new Map(), this._lifecycleState = import_context4.LifecycleState.CLOSED, this._connected = new import_async5.Trigger(), this._ready = new import_async5.Trigger();
|
|
593
598
|
}
|
|
594
599
|
isReady() {
|
|
595
600
|
return this._lifecycleState === import_context4.LifecycleState.OPEN;
|
|
@@ -668,7 +673,7 @@ var EchoNetworkAdapter = class extends import_automerge_repo2.NetworkAdapter {
|
|
|
668
673
|
getContainingSpaceForDocument: this._params.getContainingSpaceForDocument,
|
|
669
674
|
getContainingSpaceIdForDocument: async (documentId) => {
|
|
670
675
|
const key = await this._params.getContainingSpaceForDocument(documentId);
|
|
671
|
-
return key ? (0,
|
|
676
|
+
return key ? (0, import_chunk_SG2PL5RH.createIdFromSpaceKey)(key) : null;
|
|
672
677
|
}
|
|
673
678
|
});
|
|
674
679
|
}
|
|
@@ -941,8 +946,7 @@ var HeadsStore = class {
|
|
|
941
946
|
};
|
|
942
947
|
var LevelDBStorageAdapter = class extends import_context5.Resource {
|
|
943
948
|
constructor(_params) {
|
|
944
|
-
super();
|
|
945
|
-
this._params = _params;
|
|
949
|
+
super(), this._params = _params;
|
|
946
950
|
}
|
|
947
951
|
async load(keyArray) {
|
|
948
952
|
try {
|
|
@@ -1281,7 +1285,7 @@ var AutomergeHost = class extends import_context2.Resource {
|
|
|
1281
1285
|
}
|
|
1282
1286
|
const heads = (0, import_automerge2.getHeads)(doc);
|
|
1283
1287
|
this._headsStore.setHeads(handle.documentId, heads, batch);
|
|
1284
|
-
const spaceKey =
|
|
1288
|
+
const spaceKey = import_echo_protocol.DatabaseDirectory.getSpaceKey(doc) ?? void 0;
|
|
1285
1289
|
const objectIds = Object.keys(doc.objects ?? {});
|
|
1286
1290
|
const encodedIds = objectIds.map((objectId) => import_protocols.objectPointerCodec.encode({
|
|
1287
1291
|
documentId: handle.documentId,
|
|
@@ -1334,7 +1338,7 @@ var AutomergeHost = class extends import_context2.Resource {
|
|
|
1334
1338
|
await handle.whenReady();
|
|
1335
1339
|
}
|
|
1336
1340
|
if (handle && handle.isReady() && handle.doc()) {
|
|
1337
|
-
const spaceKeyHex =
|
|
1341
|
+
const spaceKeyHex = import_echo_protocol.DatabaseDirectory.getSpaceKey(handle.doc());
|
|
1338
1342
|
if (spaceKeyHex) {
|
|
1339
1343
|
return import_keys2.PublicKey.from(spaceKeyHex);
|
|
1340
1344
|
}
|
|
@@ -1349,7 +1353,10 @@ var AutomergeHost = class extends import_context2.Resource {
|
|
|
1349
1353
|
* Flush documents to disk.
|
|
1350
1354
|
*/
|
|
1351
1355
|
async flush({ documentIds } = {}) {
|
|
1352
|
-
const loadedDocuments = documentIds?.filter((documentId) =>
|
|
1356
|
+
const loadedDocuments = documentIds?.filter((documentId) => {
|
|
1357
|
+
const handle = this._repo.handles[documentId];
|
|
1358
|
+
return handle && handle.isReady();
|
|
1359
|
+
});
|
|
1353
1360
|
await this._repo.flush(loadedDocuments);
|
|
1354
1361
|
}
|
|
1355
1362
|
async getHeads(documentIds) {
|
|
@@ -1464,7 +1471,7 @@ var AutomergeHost = class extends import_context2.Resource {
|
|
|
1464
1471
|
count: toReplicate.length
|
|
1465
1472
|
}, {
|
|
1466
1473
|
F: __dxlog_file4,
|
|
1467
|
-
L:
|
|
1474
|
+
L: 557,
|
|
1468
1475
|
S: this,
|
|
1469
1476
|
C: (f, a) => f(...a)
|
|
1470
1477
|
});
|
|
@@ -1506,13 +1513,6 @@ _ts_decorate3([
|
|
|
1506
1513
|
AutomergeHost = _ts_decorate3([
|
|
1507
1514
|
import_tracing.trace.resource()
|
|
1508
1515
|
], AutomergeHost);
|
|
1509
|
-
var getSpaceKeyFromDoc = (doc) => {
|
|
1510
|
-
const rawSpaceKey = doc.access?.spaceKey ?? doc.experimental_spaceKey;
|
|
1511
|
-
if (rawSpaceKey == null) {
|
|
1512
|
-
return null;
|
|
1513
|
-
}
|
|
1514
|
-
return String(rawSpaceKey);
|
|
1515
|
-
};
|
|
1516
1516
|
var waitForHeads = async (handle, heads) => {
|
|
1517
1517
|
const unavailableHeads = new Set(heads);
|
|
1518
1518
|
await handle.whenReady();
|
|
@@ -1531,7 +1531,7 @@ var changeIsPresentInDoc = (doc, changeHash) => {
|
|
|
1531
1531
|
var decodeCollectionState = (state) => {
|
|
1532
1532
|
(0, import_invariant3.invariant)(typeof state === "object" && state !== null, "Invalid state", {
|
|
1533
1533
|
F: __dxlog_file4,
|
|
1534
|
-
L:
|
|
1534
|
+
L: 608,
|
|
1535
1535
|
S: void 0,
|
|
1536
1536
|
A: [
|
|
1537
1537
|
"typeof state === 'object' && state !== null",
|
|
@@ -1547,11 +1547,7 @@ var __dxlog_file5 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipelin
|
|
|
1547
1547
|
var DEFAULT_FACTORY = (params) => new import_teleport_extension_automerge_replicator.AutomergeReplicator(...params);
|
|
1548
1548
|
var MeshReplicatorConnection = class extends import_context6.Resource {
|
|
1549
1549
|
constructor(_params) {
|
|
1550
|
-
super();
|
|
1551
|
-
this._params = _params;
|
|
1552
|
-
this.remoteDeviceKey = null;
|
|
1553
|
-
this._remotePeerId = null;
|
|
1554
|
-
this._isEnabled = false;
|
|
1550
|
+
super(), this._params = _params, this.remoteDeviceKey = null, this._remotePeerId = null, this._isEnabled = false;
|
|
1555
1551
|
let readableStreamController;
|
|
1556
1552
|
this.readable = new ReadableStream({
|
|
1557
1553
|
start: (controller) => {
|
|
@@ -1838,7 +1834,7 @@ var MeshEchoReplicator = class {
|
|
|
1838
1834
|
});
|
|
1839
1835
|
return remoteDocumentExists;
|
|
1840
1836
|
}
|
|
1841
|
-
const spaceId = await (0,
|
|
1837
|
+
const spaceId = await (0, import_chunk_SG2PL5RH.createIdFromSpaceKey)(spaceKey);
|
|
1842
1838
|
const authorizedDevices = this._authorizedDevices.get(spaceId);
|
|
1843
1839
|
if (!connection.remoteDeviceKey) {
|
|
1844
1840
|
(0, import_log6.log)("device key not found for share policy check", {
|
|
@@ -1909,7 +1905,7 @@ var MeshEchoReplicator = class {
|
|
|
1909
1905
|
S: this,
|
|
1910
1906
|
C: (f, a) => f(...a)
|
|
1911
1907
|
});
|
|
1912
|
-
const spaceId = await (0,
|
|
1908
|
+
const spaceId = await (0, import_chunk_SG2PL5RH.createIdFromSpaceKey)(spaceKey);
|
|
1913
1909
|
(0, import_util4.defaultMap)(this._authorizedDevices, spaceId, () => new import_util4.ComplexSet(import_keys3.PublicKey.hash)).add(deviceKey);
|
|
1914
1910
|
for (const connection of this._connections) {
|
|
1915
1911
|
if (connection.isEnabled && connection.remoteDeviceKey && connection.remoteDeviceKey.equals(deviceKey)) {
|
|
@@ -2456,7 +2452,7 @@ var createSelectedDocumentsIterator = (automergeHost) => (
|
|
|
2456
2452
|
});
|
|
2457
2453
|
}
|
|
2458
2454
|
}
|
|
2459
|
-
if (doc.version !==
|
|
2455
|
+
if (doc.version !== import_echo_protocol3.SpaceDocVersion.CURRENT) {
|
|
2460
2456
|
continue;
|
|
2461
2457
|
}
|
|
2462
2458
|
if (!doc.objects?.[objectId]) {
|
|
@@ -2464,7 +2460,7 @@ var createSelectedDocumentsIterator = (automergeHost) => (
|
|
|
2464
2460
|
}
|
|
2465
2461
|
let newId = id;
|
|
2466
2462
|
if (import_protocols3.objectPointerCodec.getVersion(id) === import_protocols3.ObjectPointerVersion.V0) {
|
|
2467
|
-
const spaceKey =
|
|
2463
|
+
const spaceKey = import_echo_protocol3.DatabaseDirectory.getSpaceKey(doc) ?? void 0;
|
|
2468
2464
|
newId = import_protocols3.objectPointerCodec.encode({
|
|
2469
2465
|
documentId,
|
|
2470
2466
|
objectId,
|
|
@@ -2493,192 +2489,992 @@ var createSelectedDocumentsIterator = (automergeHost) => (
|
|
|
2493
2489
|
}
|
|
2494
2490
|
}
|
|
2495
2491
|
);
|
|
2496
|
-
|
|
2497
|
-
|
|
2498
|
-
|
|
2499
|
-
|
|
2500
|
-
|
|
2501
|
-
|
|
2502
|
-
|
|
2503
|
-
|
|
2504
|
-
|
|
2505
|
-
|
|
2492
|
+
var QueryError = class extends import_errors.BaseError.extend("QUERY_ERROR") {
|
|
2493
|
+
};
|
|
2494
|
+
(function(QueryPlan2) {
|
|
2495
|
+
QueryPlan2.Plan = Object.freeze({
|
|
2496
|
+
make: (steps) => ({
|
|
2497
|
+
steps
|
|
2498
|
+
})
|
|
2499
|
+
});
|
|
2500
|
+
QueryPlan2.FilterStep = Object.freeze({
|
|
2501
|
+
isNoop: (step) => {
|
|
2502
|
+
switch (step.filter.type) {
|
|
2503
|
+
case "object": {
|
|
2504
|
+
return step.filter.typename === null && (step.filter.id === void 0 || step.filter.id.length === 0) && (step.filter.props === void 0 || Object.keys(step.filter.props).length === 0) && (step.filter.foreignKeys === void 0 || step.filter.foreignKeys.length === 0);
|
|
2505
|
+
}
|
|
2506
|
+
default:
|
|
2507
|
+
return false;
|
|
2508
|
+
}
|
|
2509
|
+
}
|
|
2510
|
+
});
|
|
2511
|
+
})(QueryPlan || (QueryPlan = {}));
|
|
2512
|
+
var QueryPlan;
|
|
2513
|
+
var __dxlog_file10 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/query/query-planner.ts";
|
|
2514
|
+
var DEFAULT_OPTIONS = {
|
|
2515
|
+
defaultTextSearchKind: "full-text"
|
|
2516
|
+
};
|
|
2517
|
+
var QueryPlanner = class {
|
|
2518
|
+
constructor(options) {
|
|
2519
|
+
this._options = {
|
|
2520
|
+
...DEFAULT_OPTIONS,
|
|
2521
|
+
...options
|
|
2522
|
+
};
|
|
2506
2523
|
}
|
|
2507
|
-
|
|
2508
|
-
|
|
2509
|
-
|
|
2510
|
-
|
|
2511
|
-
|
|
2512
|
-
|
|
2513
|
-
|
|
2514
|
-
|
|
2515
|
-
|
|
2516
|
-
|
|
2517
|
-
|
|
2518
|
-
|
|
2524
|
+
createPlan(query) {
|
|
2525
|
+
let plan = this._generate(query, {
|
|
2526
|
+
...DEFAULT_CONTEXT,
|
|
2527
|
+
originalQuery: query
|
|
2528
|
+
});
|
|
2529
|
+
plan = this._optimizeEmptyFilters(plan);
|
|
2530
|
+
plan = this._optimizeSoloUnions(plan);
|
|
2531
|
+
return plan;
|
|
2532
|
+
}
|
|
2533
|
+
_generate(query, context) {
|
|
2534
|
+
switch (query.type) {
|
|
2535
|
+
case "options":
|
|
2536
|
+
return this._generateOptionsClause(query, context);
|
|
2537
|
+
case "select":
|
|
2538
|
+
return this._generateSelectClause(query, context);
|
|
2539
|
+
case "filter":
|
|
2540
|
+
return this._generateFilterClause(query, context);
|
|
2541
|
+
case "incoming-references":
|
|
2542
|
+
return this._generateIncomingReferencesClause(query, context);
|
|
2543
|
+
case "relation":
|
|
2544
|
+
return this._generateRelationClause(query, context);
|
|
2545
|
+
case "relation-traversal":
|
|
2546
|
+
return this._generateRelationTraversalClause(query, context);
|
|
2547
|
+
case "reference-traversal":
|
|
2548
|
+
return this._generateReferenceTraversalClause(query, context);
|
|
2549
|
+
case "union":
|
|
2550
|
+
return this._generateUnionClause(query, context);
|
|
2551
|
+
default:
|
|
2552
|
+
throw new QueryError(`Unsupported query type: ${query.type}`, {
|
|
2553
|
+
context: {
|
|
2554
|
+
query: context.originalQuery
|
|
2555
|
+
}
|
|
2556
|
+
});
|
|
2557
|
+
}
|
|
2558
|
+
}
|
|
2559
|
+
_generateOptionsClause(query, context) {
|
|
2560
|
+
const newContext = {
|
|
2561
|
+
...context
|
|
2519
2562
|
};
|
|
2520
|
-
|
|
2563
|
+
if (query.options.spaceIds) {
|
|
2564
|
+
newContext.selectionSpaces = query.options.spaceIds;
|
|
2565
|
+
}
|
|
2566
|
+
if (query.options.deleted) {
|
|
2567
|
+
newContext.deletedHandling = query.options.deleted;
|
|
2568
|
+
}
|
|
2569
|
+
return this._generate(query.query, newContext);
|
|
2570
|
+
}
|
|
2571
|
+
_generateSelectClause(query, context) {
|
|
2572
|
+
return this._generateSelectionFromFilter(query.filter, context);
|
|
2573
|
+
}
|
|
2574
|
+
// TODO(dmaretskyi): This can be rewritten as a function of (filter[]) -> (selection ? undefined, rest: filter[]) that recurses onto itself.
|
|
2575
|
+
// 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.
|
|
2576
|
+
_generateSelectionFromFilter(filter, context) {
|
|
2577
|
+
switch (filter.type) {
|
|
2578
|
+
case "object": {
|
|
2579
|
+
if (context.selectionInverted && filter.id === void 0 && filter.typename === null && Object.keys(filter.props).length === 0) {
|
|
2580
|
+
return QueryPlan.Plan.make([
|
|
2581
|
+
{
|
|
2582
|
+
_tag: "ClearWorkingSetStep"
|
|
2583
|
+
},
|
|
2584
|
+
...this._generateDeletedHandlingSteps(context)
|
|
2585
|
+
]);
|
|
2586
|
+
}
|
|
2587
|
+
if (context.selectionInverted) {
|
|
2588
|
+
throw new QueryError("Query too complex", {
|
|
2589
|
+
context: {
|
|
2590
|
+
query: context.originalQuery
|
|
2591
|
+
}
|
|
2592
|
+
});
|
|
2593
|
+
}
|
|
2594
|
+
if (filter.id && filter.id?.length > 0) {
|
|
2595
|
+
return QueryPlan.Plan.make([
|
|
2596
|
+
{
|
|
2597
|
+
_tag: "SelectStep",
|
|
2598
|
+
spaces: context.selectionSpaces,
|
|
2599
|
+
selector: {
|
|
2600
|
+
_tag: "IdSelector",
|
|
2601
|
+
objectIds: filter.id
|
|
2602
|
+
}
|
|
2603
|
+
},
|
|
2604
|
+
...this._generateDeletedHandlingSteps(context),
|
|
2605
|
+
{
|
|
2606
|
+
_tag: "FilterStep",
|
|
2607
|
+
filter: {
|
|
2608
|
+
...filter,
|
|
2609
|
+
id: void 0
|
|
2610
|
+
}
|
|
2611
|
+
}
|
|
2612
|
+
]);
|
|
2613
|
+
} else if (filter.typename) {
|
|
2614
|
+
return QueryPlan.Plan.make([
|
|
2615
|
+
{
|
|
2616
|
+
_tag: "SelectStep",
|
|
2617
|
+
spaces: context.selectionSpaces,
|
|
2618
|
+
selector: {
|
|
2619
|
+
_tag: "TypeSelector",
|
|
2620
|
+
typename: [
|
|
2621
|
+
filter.typename
|
|
2622
|
+
],
|
|
2623
|
+
inverted: false
|
|
2624
|
+
}
|
|
2625
|
+
},
|
|
2626
|
+
...this._generateDeletedHandlingSteps(context),
|
|
2627
|
+
{
|
|
2628
|
+
_tag: "FilterStep",
|
|
2629
|
+
filter: {
|
|
2630
|
+
...filter,
|
|
2631
|
+
typename: null
|
|
2632
|
+
}
|
|
2633
|
+
}
|
|
2634
|
+
]);
|
|
2635
|
+
} else {
|
|
2636
|
+
return QueryPlan.Plan.make([
|
|
2637
|
+
{
|
|
2638
|
+
_tag: "SelectStep",
|
|
2639
|
+
spaces: context.selectionSpaces,
|
|
2640
|
+
selector: {
|
|
2641
|
+
_tag: "WildcardSelector"
|
|
2642
|
+
}
|
|
2643
|
+
},
|
|
2644
|
+
...this._generateDeletedHandlingSteps(context),
|
|
2645
|
+
{
|
|
2646
|
+
_tag: "FilterStep",
|
|
2647
|
+
filter: {
|
|
2648
|
+
...filter
|
|
2649
|
+
}
|
|
2650
|
+
}
|
|
2651
|
+
]);
|
|
2652
|
+
}
|
|
2653
|
+
}
|
|
2654
|
+
case "text-search": {
|
|
2655
|
+
return QueryPlan.Plan.make([
|
|
2656
|
+
{
|
|
2657
|
+
_tag: "SelectStep",
|
|
2658
|
+
spaces: context.selectionSpaces,
|
|
2659
|
+
selector: {
|
|
2660
|
+
_tag: "TextSelector",
|
|
2661
|
+
text: filter.text,
|
|
2662
|
+
searchKind: filter.searchKind ?? this._options.defaultTextSearchKind
|
|
2663
|
+
}
|
|
2664
|
+
},
|
|
2665
|
+
...this._generateDeletedHandlingSteps(context)
|
|
2666
|
+
]);
|
|
2667
|
+
}
|
|
2668
|
+
case "compare":
|
|
2669
|
+
throw new QueryError("Query too complex", {
|
|
2670
|
+
context: {
|
|
2671
|
+
query: context.originalQuery
|
|
2672
|
+
}
|
|
2673
|
+
});
|
|
2674
|
+
case "in":
|
|
2675
|
+
throw new QueryError("Query too complex", {
|
|
2676
|
+
context: {
|
|
2677
|
+
query: context.originalQuery
|
|
2678
|
+
}
|
|
2679
|
+
});
|
|
2680
|
+
case "range":
|
|
2681
|
+
throw new QueryError("Query too complex", {
|
|
2682
|
+
context: {
|
|
2683
|
+
query: context.originalQuery
|
|
2684
|
+
}
|
|
2685
|
+
});
|
|
2686
|
+
case "not":
|
|
2687
|
+
return this._generateSelectionFromFilter(filter.filter, {
|
|
2688
|
+
...context,
|
|
2689
|
+
selectionInverted: !context.selectionInverted
|
|
2690
|
+
});
|
|
2691
|
+
case "and":
|
|
2692
|
+
throw new QueryError("Query too complex", {
|
|
2693
|
+
context: {
|
|
2694
|
+
query: context.originalQuery
|
|
2695
|
+
}
|
|
2696
|
+
});
|
|
2697
|
+
case "or":
|
|
2698
|
+
if (filter.filters.every(isTrivialTypenameFilter)) {
|
|
2699
|
+
const typenames = filter.filters.map((f) => {
|
|
2700
|
+
(0, import_invariant11.invariant)(f.type === "object" && f.typename !== null, void 0, {
|
|
2701
|
+
F: __dxlog_file10,
|
|
2702
|
+
L: 189,
|
|
2703
|
+
S: this,
|
|
2704
|
+
A: [
|
|
2705
|
+
"f.type === 'object' && f.typename !== null",
|
|
2706
|
+
""
|
|
2707
|
+
]
|
|
2708
|
+
});
|
|
2709
|
+
return f.typename;
|
|
2710
|
+
});
|
|
2711
|
+
return QueryPlan.Plan.make([
|
|
2712
|
+
{
|
|
2713
|
+
_tag: "SelectStep",
|
|
2714
|
+
spaces: context.selectionSpaces,
|
|
2715
|
+
selector: {
|
|
2716
|
+
_tag: "TypeSelector",
|
|
2717
|
+
typename: typenames,
|
|
2718
|
+
inverted: context.selectionInverted
|
|
2719
|
+
}
|
|
2720
|
+
},
|
|
2721
|
+
...this._generateDeletedHandlingSteps(context)
|
|
2722
|
+
]);
|
|
2723
|
+
} else {
|
|
2724
|
+
throw new QueryError("Query too complex", {
|
|
2725
|
+
context: {
|
|
2726
|
+
query: context.originalQuery
|
|
2727
|
+
}
|
|
2728
|
+
});
|
|
2729
|
+
}
|
|
2730
|
+
default:
|
|
2731
|
+
throw new QueryError(`Unsupported filter type: ${filter.type}`, {
|
|
2732
|
+
context: {
|
|
2733
|
+
query: context.originalQuery
|
|
2734
|
+
}
|
|
2735
|
+
});
|
|
2736
|
+
}
|
|
2521
2737
|
}
|
|
2522
|
-
|
|
2523
|
-
|
|
2738
|
+
_generateDeletedHandlingSteps(context) {
|
|
2739
|
+
switch (context.deletedHandling) {
|
|
2740
|
+
case "include":
|
|
2741
|
+
return [];
|
|
2742
|
+
case "exclude":
|
|
2743
|
+
return [
|
|
2744
|
+
{
|
|
2745
|
+
_tag: "FilterDeletedStep",
|
|
2746
|
+
mode: "only-non-deleted"
|
|
2747
|
+
}
|
|
2748
|
+
];
|
|
2749
|
+
case "only":
|
|
2750
|
+
return [
|
|
2751
|
+
{
|
|
2752
|
+
_tag: "FilterDeletedStep",
|
|
2753
|
+
mode: "only-deleted"
|
|
2754
|
+
}
|
|
2755
|
+
];
|
|
2756
|
+
}
|
|
2524
2757
|
}
|
|
2525
|
-
|
|
2526
|
-
|
|
2527
|
-
|
|
2528
|
-
|
|
2529
|
-
|
|
2530
|
-
|
|
2531
|
-
|
|
2532
|
-
|
|
2533
|
-
|
|
2534
|
-
|
|
2535
|
-
|
|
2536
|
-
|
|
2537
|
-
|
|
2538
|
-
|
|
2539
|
-
|
|
2540
|
-
|
|
2541
|
-
|
|
2542
|
-
} else {
|
|
2543
|
-
if (this._firstRun) {
|
|
2544
|
-
this.metrics.documentsLoaded++;
|
|
2758
|
+
_generateUnionClause(query, context) {
|
|
2759
|
+
return QueryPlan.Plan.make([
|
|
2760
|
+
{
|
|
2761
|
+
_tag: "UnionStep",
|
|
2762
|
+
plans: query.queries.map((query2) => this._generate(query2, context))
|
|
2763
|
+
}
|
|
2764
|
+
]);
|
|
2765
|
+
}
|
|
2766
|
+
_generateReferenceTraversalClause(query, context) {
|
|
2767
|
+
return QueryPlan.Plan.make([
|
|
2768
|
+
...this._generate(query.anchor, context).steps,
|
|
2769
|
+
{
|
|
2770
|
+
_tag: "TraverseStep",
|
|
2771
|
+
traversal: {
|
|
2772
|
+
_tag: "ReferenceTraversal",
|
|
2773
|
+
direction: "outgoing",
|
|
2774
|
+
property: query.property
|
|
2545
2775
|
}
|
|
2546
|
-
|
|
2547
|
-
|
|
2548
|
-
|
|
2549
|
-
|
|
2550
|
-
|
|
2551
|
-
|
|
2776
|
+
},
|
|
2777
|
+
...this._generateDeletedHandlingSteps(context)
|
|
2778
|
+
]);
|
|
2779
|
+
}
|
|
2780
|
+
_generateIncomingReferencesClause(query, context) {
|
|
2781
|
+
return QueryPlan.Plan.make([
|
|
2782
|
+
...this._generate(query.anchor, context).steps,
|
|
2783
|
+
{
|
|
2784
|
+
_tag: "TraverseStep",
|
|
2785
|
+
traversal: {
|
|
2786
|
+
_tag: "ReferenceTraversal",
|
|
2787
|
+
direction: "incoming",
|
|
2788
|
+
property: query.property
|
|
2789
|
+
}
|
|
2790
|
+
},
|
|
2791
|
+
...this._generateDeletedHandlingSteps(context),
|
|
2792
|
+
{
|
|
2793
|
+
_tag: "FilterStep",
|
|
2794
|
+
filter: {
|
|
2795
|
+
type: "object",
|
|
2796
|
+
typename: query.typename,
|
|
2797
|
+
props: {}
|
|
2552
2798
|
}
|
|
2553
|
-
spaceKey = getSpaceKeyFromDoc(handle.doc());
|
|
2554
2799
|
}
|
|
2555
|
-
|
|
2556
|
-
|
|
2800
|
+
]);
|
|
2801
|
+
}
|
|
2802
|
+
_generateRelationTraversalClause(query, context) {
|
|
2803
|
+
switch (query.direction) {
|
|
2804
|
+
case "source": {
|
|
2805
|
+
return QueryPlan.Plan.make([
|
|
2806
|
+
...this._generate(query.anchor, context).steps,
|
|
2807
|
+
createRelationTraversalStep("relation-to-source"),
|
|
2808
|
+
...this._generateDeletedHandlingSteps(context)
|
|
2809
|
+
]);
|
|
2557
2810
|
}
|
|
2558
|
-
|
|
2559
|
-
return
|
|
2811
|
+
case "target": {
|
|
2812
|
+
return QueryPlan.Plan.make([
|
|
2813
|
+
...this._generate(query.anchor, context).steps,
|
|
2814
|
+
createRelationTraversalStep("relation-to-target"),
|
|
2815
|
+
...this._generateDeletedHandlingSteps(context)
|
|
2816
|
+
]);
|
|
2560
2817
|
}
|
|
2561
|
-
|
|
2562
|
-
|
|
2563
|
-
return
|
|
2818
|
+
case "both": {
|
|
2819
|
+
const anchorPlan = this._generate(query.anchor, context);
|
|
2820
|
+
return QueryPlan.Plan.make([
|
|
2821
|
+
...anchorPlan.steps,
|
|
2822
|
+
{
|
|
2823
|
+
_tag: "UnionStep",
|
|
2824
|
+
plans: [
|
|
2825
|
+
QueryPlan.Plan.make([
|
|
2826
|
+
createRelationTraversalStep("relation-to-source")
|
|
2827
|
+
]),
|
|
2828
|
+
QueryPlan.Plan.make([
|
|
2829
|
+
createRelationTraversalStep("relation-to-target")
|
|
2830
|
+
])
|
|
2831
|
+
]
|
|
2832
|
+
},
|
|
2833
|
+
...this._generateDeletedHandlingSteps(context)
|
|
2834
|
+
]);
|
|
2564
2835
|
}
|
|
2565
|
-
|
|
2566
|
-
|
|
2836
|
+
}
|
|
2837
|
+
}
|
|
2838
|
+
_generateRelationClause(query, context) {
|
|
2839
|
+
switch (query.direction) {
|
|
2840
|
+
case "outgoing": {
|
|
2841
|
+
return QueryPlan.Plan.make([
|
|
2842
|
+
...this._generate(query.anchor, context).steps,
|
|
2843
|
+
createRelationTraversalStep("source-to-relation"),
|
|
2844
|
+
...this._generateDeletedHandlingSteps(context),
|
|
2845
|
+
{
|
|
2846
|
+
_tag: "FilterStep",
|
|
2847
|
+
filter: query.filter ?? NOOP_FILTER
|
|
2848
|
+
}
|
|
2849
|
+
]);
|
|
2850
|
+
}
|
|
2851
|
+
case "incoming": {
|
|
2852
|
+
return QueryPlan.Plan.make([
|
|
2853
|
+
...this._generate(query.anchor, context).steps,
|
|
2854
|
+
createRelationTraversalStep("target-to-relation"),
|
|
2855
|
+
...this._generateDeletedHandlingSteps(context),
|
|
2856
|
+
{
|
|
2857
|
+
_tag: "FilterStep",
|
|
2858
|
+
filter: query.filter ?? NOOP_FILTER
|
|
2859
|
+
}
|
|
2860
|
+
]);
|
|
2861
|
+
}
|
|
2862
|
+
case "both": {
|
|
2863
|
+
const anchorPlan = this._generate(query.anchor, context);
|
|
2864
|
+
return QueryPlan.Plan.make([
|
|
2865
|
+
...anchorPlan.steps,
|
|
2866
|
+
{
|
|
2867
|
+
_tag: "UnionStep",
|
|
2868
|
+
plans: [
|
|
2869
|
+
QueryPlan.Plan.make([
|
|
2870
|
+
createRelationTraversalStep("source-to-relation")
|
|
2871
|
+
]),
|
|
2872
|
+
QueryPlan.Plan.make([
|
|
2873
|
+
createRelationTraversalStep("target-to-relation")
|
|
2874
|
+
])
|
|
2875
|
+
]
|
|
2876
|
+
},
|
|
2877
|
+
...this._generateDeletedHandlingSteps(context),
|
|
2878
|
+
{
|
|
2879
|
+
_tag: "FilterStep",
|
|
2880
|
+
filter: query.filter ?? NOOP_FILTER
|
|
2881
|
+
}
|
|
2882
|
+
]);
|
|
2567
2883
|
}
|
|
2568
|
-
return {
|
|
2569
|
-
id: objectId,
|
|
2570
|
-
documentId,
|
|
2571
|
-
spaceId,
|
|
2572
|
-
spaceKey: import_keys5.PublicKey.from(spaceKey),
|
|
2573
|
-
rank: result.rank
|
|
2574
|
-
};
|
|
2575
|
-
}))).filter(import_util6.isNonNullable);
|
|
2576
|
-
if (this._firstRun) {
|
|
2577
|
-
this.metrics.documentLoadTime = performance.now() - beginFilter;
|
|
2578
2884
|
}
|
|
2885
|
+
}
|
|
2886
|
+
_generateFilterClause(query, context) {
|
|
2887
|
+
return QueryPlan.Plan.make([
|
|
2888
|
+
...this._generate(query.selection, context).steps,
|
|
2889
|
+
{
|
|
2890
|
+
_tag: "FilterStep",
|
|
2891
|
+
filter: query.filter
|
|
2892
|
+
}
|
|
2893
|
+
]);
|
|
2894
|
+
}
|
|
2895
|
+
/**
|
|
2896
|
+
* Removes filter steps that have no predicates.
|
|
2897
|
+
*/
|
|
2898
|
+
_optimizeEmptyFilters(plan) {
|
|
2899
|
+
return QueryPlan.Plan.make(plan.steps.filter((step) => {
|
|
2900
|
+
if (step._tag === "FilterStep") {
|
|
2901
|
+
return !QueryPlan.FilterStep.isNoop(step);
|
|
2902
|
+
} else {
|
|
2903
|
+
return true;
|
|
2904
|
+
}
|
|
2905
|
+
}).map((step) => {
|
|
2906
|
+
if (step._tag === "UnionStep") {
|
|
2907
|
+
return {
|
|
2908
|
+
_tag: "UnionStep",
|
|
2909
|
+
plans: step.plans.map((plan2) => this._optimizeEmptyFilters(plan2))
|
|
2910
|
+
};
|
|
2911
|
+
} else {
|
|
2912
|
+
return step;
|
|
2913
|
+
}
|
|
2914
|
+
}));
|
|
2915
|
+
}
|
|
2916
|
+
/**
|
|
2917
|
+
* Removes union steps that have only one child.
|
|
2918
|
+
*/
|
|
2919
|
+
_optimizeSoloUnions(plan) {
|
|
2920
|
+
return plan;
|
|
2921
|
+
}
|
|
2922
|
+
};
|
|
2923
|
+
var DEFAULT_CONTEXT = {
|
|
2924
|
+
originalQuery: null,
|
|
2925
|
+
selectionSpaces: [],
|
|
2926
|
+
deletedHandling: "exclude",
|
|
2927
|
+
selectionInverted: false
|
|
2928
|
+
};
|
|
2929
|
+
var NOOP_FILTER = {
|
|
2930
|
+
type: "object",
|
|
2931
|
+
typename: null,
|
|
2932
|
+
id: [],
|
|
2933
|
+
props: {}
|
|
2934
|
+
};
|
|
2935
|
+
var createRelationTraversalStep = (direction) => ({
|
|
2936
|
+
_tag: "TraverseStep",
|
|
2937
|
+
traversal: {
|
|
2938
|
+
_tag: "RelationTraversal",
|
|
2939
|
+
direction
|
|
2940
|
+
}
|
|
2941
|
+
});
|
|
2942
|
+
var isTrivialTypenameFilter = (filter) => {
|
|
2943
|
+
return filter.type === "object" && filter.typename !== null && Object.keys(filter.props).length === 0 && (filter.id === void 0 || filter.id.length === 0) && (filter.foreignKeys === void 0 || filter.foreignKeys.length === 0);
|
|
2944
|
+
};
|
|
2945
|
+
var __dxlog_file11 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/query/query-executor.ts";
|
|
2946
|
+
var ExecutionTrace = Object.freeze({
|
|
2947
|
+
makeEmpty: () => ({
|
|
2948
|
+
name: "Empty",
|
|
2949
|
+
details: "",
|
|
2950
|
+
objectCount: 0,
|
|
2951
|
+
documentsLoaded: 0,
|
|
2952
|
+
indexHits: 0,
|
|
2953
|
+
indexQueryTime: 0,
|
|
2954
|
+
documentLoadTime: 0,
|
|
2955
|
+
executionTime: 0,
|
|
2956
|
+
children: []
|
|
2957
|
+
}),
|
|
2958
|
+
format: (trace6) => {
|
|
2959
|
+
const go = (trace7, indent) => {
|
|
2960
|
+
return [
|
|
2961
|
+
`${" ".repeat(indent)} - ${trace7.name}(${trace7.details})`,
|
|
2962
|
+
`${" ".repeat(indent)} objects: ${trace7.objectCount} docs: ${trace7.documentsLoaded} index hits: ${trace7.indexHits} | total: ${trace7.executionTime.toFixed(0)}ms index: ${trace7.indexQueryTime.toFixed(0)}ms load: ${trace7.documentLoadTime.toFixed(0)}ms`,
|
|
2963
|
+
"",
|
|
2964
|
+
...trace7.children.map((child) => go(child, indent + 2))
|
|
2965
|
+
].join("\n");
|
|
2966
|
+
};
|
|
2967
|
+
return go(trace6, 0);
|
|
2968
|
+
}
|
|
2969
|
+
});
|
|
2970
|
+
var QueryExecutor = class extends import_context10.Resource {
|
|
2971
|
+
constructor(options) {
|
|
2972
|
+
super();
|
|
2973
|
+
this._trace = ExecutionTrace.makeEmpty();
|
|
2974
|
+
this._lastResultSet = [];
|
|
2975
|
+
this._indexer = options.indexer;
|
|
2976
|
+
this._automergeHost = options.automergeHost;
|
|
2977
|
+
this._spaceStateManager = options.spaceStateManager;
|
|
2978
|
+
this._id = options.queryId;
|
|
2979
|
+
this._query = options.query;
|
|
2980
|
+
this._reactivity = options.reactivity;
|
|
2981
|
+
const queryPlanner = new QueryPlanner();
|
|
2982
|
+
this._plan = queryPlanner.createPlan(this._query);
|
|
2983
|
+
}
|
|
2984
|
+
get query() {
|
|
2985
|
+
return this._query;
|
|
2986
|
+
}
|
|
2987
|
+
get plan() {
|
|
2988
|
+
return this._plan;
|
|
2989
|
+
}
|
|
2990
|
+
get trace() {
|
|
2991
|
+
return this._trace;
|
|
2992
|
+
}
|
|
2993
|
+
async _open(ctx) {
|
|
2994
|
+
}
|
|
2995
|
+
async _close(ctx) {
|
|
2996
|
+
}
|
|
2997
|
+
getResults() {
|
|
2998
|
+
return this._lastResultSet.map((item) => ({
|
|
2999
|
+
id: item.objectId,
|
|
3000
|
+
documentId: item.documentId,
|
|
3001
|
+
spaceId: item.spaceId,
|
|
3002
|
+
// TODO(dmaretskyi): Plumb through the rank.
|
|
3003
|
+
rank: 0
|
|
3004
|
+
}));
|
|
3005
|
+
}
|
|
3006
|
+
async execQuery() {
|
|
3007
|
+
(0, import_invariant10.invariant)(this._lifecycleState === import_context10.LifecycleState.OPEN, void 0, {
|
|
3008
|
+
F: __dxlog_file11,
|
|
3009
|
+
L: 171,
|
|
3010
|
+
S: this,
|
|
3011
|
+
A: [
|
|
3012
|
+
"this._lifecycleState === LifecycleState.OPEN",
|
|
3013
|
+
""
|
|
3014
|
+
]
|
|
3015
|
+
});
|
|
3016
|
+
const prevResultSet = this._lastResultSet;
|
|
3017
|
+
const { workingSet, trace: trace6 } = await this._execPlan(this._plan, this._lastResultSet);
|
|
3018
|
+
this._lastResultSet = workingSet;
|
|
3019
|
+
trace6.name = "Root";
|
|
3020
|
+
trace6.details = JSON.stringify({
|
|
3021
|
+
id: this._id
|
|
3022
|
+
});
|
|
3023
|
+
this._trace = trace6;
|
|
3024
|
+
const changed = prevResultSet.length !== workingSet.length || prevResultSet.some((item, index) => workingSet[index].objectId !== item.objectId || workingSet[index].spaceId !== item.spaceId || workingSet[index].documentId !== item.documentId);
|
|
3025
|
+
return {
|
|
3026
|
+
changed
|
|
3027
|
+
};
|
|
3028
|
+
}
|
|
3029
|
+
async _execPlan(plan, workingSet) {
|
|
3030
|
+
const trace6 = ExecutionTrace.makeEmpty();
|
|
3031
|
+
for (const step of plan.steps) {
|
|
3032
|
+
if (this._ctx.disposed) {
|
|
3033
|
+
throw new import_context10.ContextDisposedError();
|
|
3034
|
+
}
|
|
3035
|
+
const result = await this._execStep(step, workingSet);
|
|
3036
|
+
workingSet = result.workingSet;
|
|
3037
|
+
trace6.children.push(result.trace);
|
|
3038
|
+
}
|
|
3039
|
+
return {
|
|
3040
|
+
workingSet,
|
|
3041
|
+
trace: trace6
|
|
3042
|
+
};
|
|
3043
|
+
}
|
|
3044
|
+
async _execStep(step, workingSet) {
|
|
2579
3045
|
if (this._ctx.disposed) {
|
|
2580
3046
|
return {
|
|
2581
|
-
|
|
3047
|
+
workingSet,
|
|
3048
|
+
trace: ExecutionTrace.makeEmpty()
|
|
2582
3049
|
};
|
|
2583
3050
|
}
|
|
2584
|
-
|
|
2585
|
-
|
|
2586
|
-
|
|
3051
|
+
let newWorkingSet, trace6;
|
|
3052
|
+
const begin = performance.now();
|
|
3053
|
+
switch (step._tag) {
|
|
3054
|
+
case "ClearWorkingSetStep":
|
|
3055
|
+
newWorkingSet = [];
|
|
3056
|
+
trace6 = ExecutionTrace.makeEmpty();
|
|
3057
|
+
break;
|
|
3058
|
+
case "SelectStep":
|
|
3059
|
+
({ workingSet: newWorkingSet, trace: trace6 } = await this._execSelectStep(step, workingSet));
|
|
3060
|
+
break;
|
|
3061
|
+
case "FilterStep":
|
|
3062
|
+
({ workingSet: newWorkingSet, trace: trace6 } = await this._execFilterStep(step, workingSet));
|
|
3063
|
+
break;
|
|
3064
|
+
case "FilterDeletedStep":
|
|
3065
|
+
({ workingSet: newWorkingSet, trace: trace6 } = await this._execFilterDeletedStep(step, workingSet));
|
|
3066
|
+
break;
|
|
3067
|
+
case "UnionStep":
|
|
3068
|
+
({ workingSet: newWorkingSet, trace: trace6 } = await this._execUnionStep(step, workingSet));
|
|
3069
|
+
break;
|
|
3070
|
+
case "TraverseStep":
|
|
3071
|
+
({ workingSet: newWorkingSet, trace: trace6 } = await this._execTraverseStep(step, workingSet));
|
|
3072
|
+
break;
|
|
3073
|
+
default:
|
|
3074
|
+
throw new Error(`Unknown step type: ${step._tag}`);
|
|
2587
3075
|
}
|
|
2588
|
-
|
|
2589
|
-
|
|
2590
|
-
|
|
2591
|
-
|
|
2592
|
-
|
|
3076
|
+
trace6.executionTime = performance.now() - begin;
|
|
3077
|
+
return {
|
|
3078
|
+
workingSet: newWorkingSet,
|
|
3079
|
+
trace: trace6
|
|
3080
|
+
};
|
|
3081
|
+
}
|
|
3082
|
+
async _execSelectStep(step, workingSet) {
|
|
3083
|
+
workingSet = [
|
|
3084
|
+
...workingSet
|
|
3085
|
+
];
|
|
3086
|
+
const trace6 = {
|
|
3087
|
+
...ExecutionTrace.makeEmpty(),
|
|
3088
|
+
name: "Select",
|
|
3089
|
+
details: JSON.stringify(step.selector)
|
|
3090
|
+
};
|
|
3091
|
+
switch (step.selector._tag) {
|
|
3092
|
+
case "WildcardSelector": {
|
|
3093
|
+
const beginIndexQuery = performance.now();
|
|
3094
|
+
const indexHits = await this._indexer.execQuery({
|
|
3095
|
+
typenames: [],
|
|
3096
|
+
inverted: false
|
|
3097
|
+
});
|
|
3098
|
+
trace6.indexHits = +indexHits.length;
|
|
3099
|
+
trace6.indexQueryTime += performance.now() - beginIndexQuery;
|
|
3100
|
+
if (this._ctx.disposed) {
|
|
3101
|
+
return {
|
|
3102
|
+
workingSet,
|
|
3103
|
+
trace: trace6
|
|
3104
|
+
};
|
|
3105
|
+
}
|
|
3106
|
+
const documentLoadStart = performance.now();
|
|
3107
|
+
const results = await this._loadDocumentsAfterIndexQuery(indexHits);
|
|
3108
|
+
trace6.documentsLoaded += results.length;
|
|
3109
|
+
trace6.documentLoadTime += performance.now() - documentLoadStart;
|
|
3110
|
+
workingSet.push(...results.filter(import_util6.isNonNullable).filter((item) => step.spaces.includes(item.spaceId)));
|
|
3111
|
+
trace6.objectCount = workingSet.length;
|
|
3112
|
+
break;
|
|
3113
|
+
}
|
|
3114
|
+
case "IdSelector": {
|
|
3115
|
+
const beginLoad = performance.now();
|
|
3116
|
+
const items = await Promise.all(step.selector.objectIds.map((id) => this._loadFromDXN(import_keys5.DXN.fromLocalObjectId(id), {
|
|
3117
|
+
sourceSpaceId: step.spaces[0]
|
|
3118
|
+
})));
|
|
3119
|
+
trace6.documentLoadTime += performance.now() - beginLoad;
|
|
3120
|
+
workingSet.push(...items.filter(import_util6.isNonNullable));
|
|
3121
|
+
trace6.objectCount = workingSet.length;
|
|
3122
|
+
break;
|
|
3123
|
+
}
|
|
3124
|
+
case "TypeSelector": {
|
|
3125
|
+
const beginIndexQuery = performance.now();
|
|
3126
|
+
const indexHits = await this._indexer.execQuery({
|
|
3127
|
+
typenames: step.selector.typename,
|
|
3128
|
+
inverted: step.selector.inverted
|
|
3129
|
+
});
|
|
3130
|
+
trace6.indexHits = +indexHits.length;
|
|
3131
|
+
trace6.indexQueryTime += performance.now() - beginIndexQuery;
|
|
3132
|
+
if (this._ctx.disposed) {
|
|
3133
|
+
return {
|
|
3134
|
+
workingSet,
|
|
3135
|
+
trace: trace6
|
|
3136
|
+
};
|
|
3137
|
+
}
|
|
3138
|
+
const documentLoadStart = performance.now();
|
|
3139
|
+
const results = await this._loadDocumentsAfterIndexQuery(indexHits);
|
|
3140
|
+
trace6.documentsLoaded += results.length;
|
|
3141
|
+
trace6.documentLoadTime += performance.now() - documentLoadStart;
|
|
3142
|
+
workingSet.push(...results.filter(import_util6.isNonNullable).filter((item) => step.spaces.includes(item.spaceId)));
|
|
3143
|
+
trace6.objectCount = workingSet.length;
|
|
3144
|
+
break;
|
|
3145
|
+
}
|
|
3146
|
+
case "TextSelector": {
|
|
3147
|
+
const beginIndexQuery = performance.now();
|
|
3148
|
+
const indexHits = await this._indexer.execQuery({
|
|
3149
|
+
typenames: [],
|
|
3150
|
+
text: {
|
|
3151
|
+
query: step.selector.text,
|
|
3152
|
+
kind: import_effect2.Match.type().pipe(import_effect2.Match.withReturnType(), import_effect2.Match.when("full-text", () => "text"), import_effect2.Match.when("vector", () => "vector"), import_effect2.Match.orElseAbsurd)(step.selector.searchKind)
|
|
3153
|
+
}
|
|
3154
|
+
});
|
|
3155
|
+
trace6.indexHits = +indexHits.length;
|
|
3156
|
+
trace6.indexQueryTime += performance.now() - beginIndexQuery;
|
|
3157
|
+
if (this._ctx.disposed) {
|
|
3158
|
+
return {
|
|
3159
|
+
workingSet,
|
|
3160
|
+
trace: trace6
|
|
3161
|
+
};
|
|
3162
|
+
}
|
|
3163
|
+
const documentLoadStart = performance.now();
|
|
3164
|
+
const results = await this._loadDocumentsAfterIndexQuery(indexHits);
|
|
3165
|
+
trace6.documentsLoaded += results.length;
|
|
3166
|
+
trace6.documentLoadTime += performance.now() - documentLoadStart;
|
|
3167
|
+
workingSet.push(...results.filter(import_util6.isNonNullable).filter((item) => step.spaces.includes(item.spaceId)));
|
|
3168
|
+
trace6.objectCount = workingSet.length;
|
|
3169
|
+
break;
|
|
3170
|
+
}
|
|
3171
|
+
default:
|
|
3172
|
+
throw new Error(`Unknown selector type: ${step.selector._tag}`);
|
|
2593
3173
|
}
|
|
2594
|
-
this._results = results;
|
|
2595
3174
|
return {
|
|
2596
|
-
|
|
3175
|
+
workingSet,
|
|
3176
|
+
trace: trace6
|
|
2597
3177
|
};
|
|
2598
3178
|
}
|
|
2599
|
-
|
|
2600
|
-
|
|
2601
|
-
|
|
2602
|
-
|
|
2603
|
-
|
|
2604
|
-
|
|
2605
|
-
|
|
2606
|
-
|
|
2607
|
-
|
|
2608
|
-
|
|
2609
|
-
|
|
2610
|
-
|
|
2611
|
-
|
|
2612
|
-
|
|
2613
|
-
|
|
2614
|
-
|
|
2615
|
-
|
|
2616
|
-
|
|
3179
|
+
async _execFilterStep(step, workingSet) {
|
|
3180
|
+
const result = workingSet.filter((item) => (0, import_chunk_HOPOFWAL.filterMatchObject)(step.filter, {
|
|
3181
|
+
id: item.objectId,
|
|
3182
|
+
spaceId: item.spaceId,
|
|
3183
|
+
doc: item.doc
|
|
3184
|
+
}));
|
|
3185
|
+
return {
|
|
3186
|
+
workingSet: result,
|
|
3187
|
+
trace: {
|
|
3188
|
+
...ExecutionTrace.makeEmpty(),
|
|
3189
|
+
name: "Filter",
|
|
3190
|
+
details: JSON.stringify(step.filter),
|
|
3191
|
+
objectCount: result.length
|
|
3192
|
+
}
|
|
3193
|
+
};
|
|
3194
|
+
}
|
|
3195
|
+
async _execFilterDeletedStep(step, workingSet) {
|
|
3196
|
+
const expected = step.mode === "only-deleted";
|
|
3197
|
+
const result = workingSet.filter((item) => import_echo_protocol5.ObjectStructure.isDeleted(item.doc) === expected);
|
|
3198
|
+
return {
|
|
3199
|
+
workingSet: result,
|
|
3200
|
+
trace: {
|
|
3201
|
+
...ExecutionTrace.makeEmpty(),
|
|
3202
|
+
name: "FilterDeleted",
|
|
3203
|
+
details: step.mode,
|
|
3204
|
+
objectCount: result.length
|
|
3205
|
+
}
|
|
3206
|
+
};
|
|
3207
|
+
}
|
|
3208
|
+
// TODO(dmaretskyi): This needs to be completed.
|
|
3209
|
+
async _execTraverseStep(step, workingSet) {
|
|
3210
|
+
const trace6 = {
|
|
3211
|
+
...ExecutionTrace.makeEmpty(),
|
|
3212
|
+
name: "Traverse",
|
|
3213
|
+
details: JSON.stringify(step.traversal)
|
|
3214
|
+
};
|
|
3215
|
+
const newWorkingSet = [];
|
|
3216
|
+
switch (step.traversal._tag) {
|
|
3217
|
+
case "ReferenceTraversal": {
|
|
3218
|
+
switch (step.traversal.direction) {
|
|
3219
|
+
case "outgoing": {
|
|
3220
|
+
const property = import_indexing4.EscapedPropPath.unescape(step.traversal.property);
|
|
3221
|
+
const refs = workingSet.map((item) => {
|
|
3222
|
+
const ref = (0, import_util6.getDeep)(item.doc.data, property);
|
|
3223
|
+
if (!(0, import_echo_protocol5.isEncodedReference)(ref)) {
|
|
3224
|
+
return null;
|
|
3225
|
+
}
|
|
3226
|
+
try {
|
|
3227
|
+
return {
|
|
3228
|
+
ref: import_keys5.DXN.parse(ref["/"]),
|
|
3229
|
+
spaceId: item.spaceId
|
|
3230
|
+
};
|
|
3231
|
+
} catch {
|
|
3232
|
+
import_log10.log.warn("Invalid reference", {
|
|
3233
|
+
ref: ref["/"]
|
|
3234
|
+
}, {
|
|
3235
|
+
F: __dxlog_file11,
|
|
3236
|
+
L: 421,
|
|
3237
|
+
S: this,
|
|
3238
|
+
C: (f, a) => f(...a)
|
|
3239
|
+
});
|
|
3240
|
+
return null;
|
|
3241
|
+
}
|
|
3242
|
+
}).filter(import_util6.isNonNullable);
|
|
3243
|
+
const beginLoad = performance.now();
|
|
3244
|
+
const items = await Promise.all(refs.map(({ ref, spaceId }) => this._loadFromDXN(ref, {
|
|
3245
|
+
sourceSpaceId: spaceId
|
|
3246
|
+
})));
|
|
3247
|
+
trace6.documentLoadTime += performance.now() - beginLoad;
|
|
3248
|
+
newWorkingSet.push(...items.filter(import_util6.isNonNullable));
|
|
3249
|
+
trace6.objectCount = newWorkingSet.length;
|
|
3250
|
+
break;
|
|
3251
|
+
}
|
|
3252
|
+
case "incoming": {
|
|
3253
|
+
const indexHits = await this._indexer.execQuery({
|
|
3254
|
+
typenames: [],
|
|
3255
|
+
inverted: false,
|
|
3256
|
+
graph: {
|
|
3257
|
+
kind: "inbound-reference",
|
|
3258
|
+
property: step.traversal.property,
|
|
3259
|
+
anchors: workingSet.map((item) => item.objectId)
|
|
3260
|
+
}
|
|
3261
|
+
});
|
|
3262
|
+
trace6.indexHits += indexHits.length;
|
|
3263
|
+
const documentLoadStart = performance.now();
|
|
3264
|
+
const results = await this._loadDocumentsAfterIndexQuery(indexHits);
|
|
3265
|
+
trace6.documentsLoaded += results.length;
|
|
3266
|
+
trace6.documentLoadTime += performance.now() - documentLoadStart;
|
|
3267
|
+
newWorkingSet.push(...results.filter(import_util6.isNonNullable));
|
|
3268
|
+
trace6.objectCount = newWorkingSet.length;
|
|
3269
|
+
break;
|
|
3270
|
+
}
|
|
3271
|
+
}
|
|
3272
|
+
break;
|
|
3273
|
+
}
|
|
3274
|
+
case "RelationTraversal": {
|
|
3275
|
+
switch (step.traversal.direction) {
|
|
3276
|
+
case "relation-to-source":
|
|
3277
|
+
case "relation-to-target": {
|
|
3278
|
+
const refs = workingSet.map((item) => {
|
|
3279
|
+
const ref = step.traversal.direction === "relation-to-source" ? import_echo_protocol5.ObjectStructure.getRelationSource(item.doc) : import_echo_protocol5.ObjectStructure.getRelationTarget(item.doc);
|
|
3280
|
+
if (!(0, import_echo_protocol5.isEncodedReference)(ref)) {
|
|
3281
|
+
return null;
|
|
3282
|
+
}
|
|
3283
|
+
try {
|
|
3284
|
+
return {
|
|
3285
|
+
ref: import_keys5.DXN.parse(ref["/"]),
|
|
3286
|
+
spaceId: item.spaceId
|
|
3287
|
+
};
|
|
3288
|
+
} catch {
|
|
3289
|
+
import_log10.log.warn("Invalid reference", {
|
|
3290
|
+
ref: ref["/"]
|
|
3291
|
+
}, {
|
|
3292
|
+
F: __dxlog_file11,
|
|
3293
|
+
L: 483,
|
|
3294
|
+
S: this,
|
|
3295
|
+
C: (f, a) => f(...a)
|
|
3296
|
+
});
|
|
3297
|
+
return null;
|
|
3298
|
+
}
|
|
3299
|
+
}).filter(import_util6.isNonNullable);
|
|
3300
|
+
const beginLoad = performance.now();
|
|
3301
|
+
const items = await Promise.all(refs.map(({ ref, spaceId }) => this._loadFromDXN(ref, {
|
|
3302
|
+
sourceSpaceId: spaceId
|
|
3303
|
+
})));
|
|
3304
|
+
trace6.documentLoadTime += performance.now() - beginLoad;
|
|
3305
|
+
newWorkingSet.push(...items.filter(import_util6.isNonNullable));
|
|
3306
|
+
trace6.objectCount = newWorkingSet.length;
|
|
3307
|
+
break;
|
|
3308
|
+
}
|
|
3309
|
+
case "source-to-relation":
|
|
3310
|
+
case "target-to-relation": {
|
|
3311
|
+
const indexHits = await this._indexer.execQuery({
|
|
3312
|
+
typenames: [],
|
|
3313
|
+
inverted: false,
|
|
3314
|
+
graph: {
|
|
3315
|
+
kind: step.traversal.direction === "source-to-relation" ? "relation-source" : "relation-target",
|
|
3316
|
+
anchors: workingSet.map((item) => item.objectId),
|
|
3317
|
+
property: null
|
|
3318
|
+
}
|
|
3319
|
+
});
|
|
3320
|
+
trace6.indexHits += indexHits.length;
|
|
3321
|
+
const documentLoadStart = performance.now();
|
|
3322
|
+
const results = await this._loadDocumentsAfterIndexQuery(indexHits);
|
|
3323
|
+
trace6.documentsLoaded += results.length;
|
|
3324
|
+
trace6.documentLoadTime += performance.now() - documentLoadStart;
|
|
3325
|
+
newWorkingSet.push(...results.filter(import_util6.isNonNullable));
|
|
3326
|
+
trace6.objectCount = newWorkingSet.length;
|
|
3327
|
+
break;
|
|
3328
|
+
}
|
|
3329
|
+
}
|
|
3330
|
+
break;
|
|
3331
|
+
}
|
|
3332
|
+
default:
|
|
3333
|
+
throw new Error(`Unknown traversal type: ${step.traversal._tag}`);
|
|
2617
3334
|
}
|
|
2618
|
-
})
|
|
2619
|
-
], QueryState.prototype, "execQuery", null);
|
|
2620
|
-
QueryState = _ts_decorate5([
|
|
2621
|
-
import_tracing6.trace.resource()
|
|
2622
|
-
], QueryState);
|
|
2623
|
-
var filterToIndexQuery = (filter) => {
|
|
2624
|
-
const { type = [], or = [] } = filter;
|
|
2625
|
-
(0, import_invariant10.invariant)(!(type.length > 0 && or.length > 0), "Cannot mix type and or filters.", {
|
|
2626
|
-
F: __dxlog_file10,
|
|
2627
|
-
L: 194,
|
|
2628
|
-
S: void 0,
|
|
2629
|
-
A: [
|
|
2630
|
-
"!(type.length > 0 && or.length > 0)",
|
|
2631
|
-
"'Cannot mix type and or filters.'"
|
|
2632
|
-
]
|
|
2633
|
-
});
|
|
2634
|
-
(0, import_invariant10.invariant)(or.every((subFilter) => !((subFilter.type ?? []).length > 0 && (subFilter.or ?? []).length > 0)), "Cannot mix type and or filters.", {
|
|
2635
|
-
F: __dxlog_file10,
|
|
2636
|
-
L: 195,
|
|
2637
|
-
S: void 0,
|
|
2638
|
-
A: [
|
|
2639
|
-
"or.every((subFilter) => !((subFilter.type ?? []).length > 0 && (subFilter.or ?? []).length > 0))",
|
|
2640
|
-
"'Cannot mix type and or filters.'"
|
|
2641
|
-
]
|
|
2642
|
-
});
|
|
2643
|
-
if (type.length > 0 || or.length > 0 && (or ?? []).every((subFilter) => !subFilter.not && subFilter.type)) {
|
|
2644
3335
|
return {
|
|
2645
|
-
|
|
2646
|
-
|
|
3336
|
+
workingSet: newWorkingSet,
|
|
3337
|
+
trace: trace6
|
|
3338
|
+
};
|
|
3339
|
+
}
|
|
3340
|
+
async _execUnionStep(step, workingSet) {
|
|
3341
|
+
const results = /* @__PURE__ */ new Map();
|
|
3342
|
+
const resultSets = await Promise.all(step.plans.map((plan) => this._execPlan(plan, [
|
|
3343
|
+
...workingSet
|
|
3344
|
+
])));
|
|
3345
|
+
const trace6 = {
|
|
3346
|
+
...ExecutionTrace.makeEmpty(),
|
|
3347
|
+
name: "Union"
|
|
2647
3348
|
};
|
|
2648
|
-
|
|
3349
|
+
for (const resultSet of resultSets) {
|
|
3350
|
+
for (const item of resultSet.workingSet) {
|
|
3351
|
+
results.set(`${item.spaceId}:${item.documentId}:${item.objectId}`, item);
|
|
3352
|
+
}
|
|
3353
|
+
trace6.children.push(resultSet.trace);
|
|
3354
|
+
}
|
|
2649
3355
|
return {
|
|
2650
|
-
|
|
3356
|
+
workingSet: [
|
|
3357
|
+
...results.values()
|
|
3358
|
+
],
|
|
3359
|
+
trace: trace6
|
|
2651
3360
|
};
|
|
2652
3361
|
}
|
|
2653
|
-
|
|
2654
|
-
|
|
2655
|
-
|
|
2656
|
-
|
|
2657
|
-
|
|
2658
|
-
|
|
2659
|
-
|
|
2660
|
-
default
|
|
2661
|
-
|
|
3362
|
+
async _loadDocumentsAfterIndexQuery(indexHits) {
|
|
3363
|
+
return Promise.all(indexHits.map(async (hit) => {
|
|
3364
|
+
return this._loadFromIndexHit(hit);
|
|
3365
|
+
}));
|
|
3366
|
+
}
|
|
3367
|
+
async _loadFromIndexHit(hit) {
|
|
3368
|
+
const { objectId, documentId, spaceKey: spaceKeyInIndex } = import_protocols5.objectPointerCodec.decode(hit.id);
|
|
3369
|
+
const handle = await this._automergeHost.loadDoc(import_context10.Context.default(void 0, {
|
|
3370
|
+
F: __dxlog_file11,
|
|
3371
|
+
L: 571
|
|
3372
|
+
}), documentId);
|
|
3373
|
+
const doc = handle.doc();
|
|
3374
|
+
if (!doc) {
|
|
3375
|
+
return null;
|
|
3376
|
+
}
|
|
3377
|
+
const spaceKey = spaceKeyInIndex ?? import_echo_protocol5.DatabaseDirectory.getSpaceKey(doc);
|
|
3378
|
+
if (!spaceKey) {
|
|
3379
|
+
return null;
|
|
3380
|
+
}
|
|
3381
|
+
const object = import_echo_protocol5.DatabaseDirectory.getInlineObject(doc, objectId);
|
|
3382
|
+
if (!object) {
|
|
3383
|
+
return null;
|
|
3384
|
+
}
|
|
3385
|
+
return {
|
|
3386
|
+
objectId,
|
|
3387
|
+
documentId,
|
|
3388
|
+
spaceId: await (0, import_chunk_SG2PL5RH.createIdFromSpaceKey)(import_keys5.PublicKey.from(spaceKey)),
|
|
3389
|
+
doc: object
|
|
3390
|
+
};
|
|
3391
|
+
}
|
|
3392
|
+
async _loadFromDXN(dxn, { sourceSpaceId }) {
|
|
3393
|
+
const echoDxn = dxn.asEchoDXN();
|
|
3394
|
+
if (!echoDxn) {
|
|
3395
|
+
import_log10.log.warn("unable to resolve DXN", {
|
|
3396
|
+
dxn
|
|
3397
|
+
}, {
|
|
3398
|
+
F: __dxlog_file11,
|
|
3399
|
+
L: 598,
|
|
3400
|
+
S: this,
|
|
3401
|
+
C: (f, a) => f(...a)
|
|
3402
|
+
});
|
|
3403
|
+
return null;
|
|
3404
|
+
}
|
|
3405
|
+
const spaceId = echoDxn.spaceId ?? sourceSpaceId;
|
|
3406
|
+
const spaceRoot = this._spaceStateManager.getRootBySpaceId(spaceId);
|
|
3407
|
+
if (!spaceRoot) {
|
|
3408
|
+
import_log10.log.warn("no space state found for", {
|
|
3409
|
+
spaceId
|
|
3410
|
+
}, {
|
|
3411
|
+
F: __dxlog_file11,
|
|
3412
|
+
L: 606,
|
|
3413
|
+
S: this,
|
|
3414
|
+
C: (f, a) => f(...a)
|
|
3415
|
+
});
|
|
3416
|
+
return null;
|
|
3417
|
+
}
|
|
3418
|
+
const dbDirectory = spaceRoot.doc();
|
|
3419
|
+
if (!dbDirectory) {
|
|
3420
|
+
import_log10.log.warn("no space state found for", {
|
|
3421
|
+
spaceId
|
|
3422
|
+
}, {
|
|
3423
|
+
F: __dxlog_file11,
|
|
3424
|
+
L: 611,
|
|
3425
|
+
S: this,
|
|
3426
|
+
C: (f, a) => f(...a)
|
|
3427
|
+
});
|
|
3428
|
+
return null;
|
|
3429
|
+
}
|
|
3430
|
+
const inlineObject = import_echo_protocol5.DatabaseDirectory.getInlineObject(dbDirectory, echoDxn.echoId);
|
|
3431
|
+
if (inlineObject) {
|
|
3432
|
+
return {
|
|
3433
|
+
objectId: echoDxn.echoId,
|
|
3434
|
+
documentId: spaceRoot.documentId,
|
|
3435
|
+
spaceId,
|
|
3436
|
+
doc: inlineObject
|
|
3437
|
+
};
|
|
3438
|
+
}
|
|
3439
|
+
const link = import_echo_protocol5.DatabaseDirectory.getLink(dbDirectory, echoDxn.echoId);
|
|
3440
|
+
if (!link) {
|
|
3441
|
+
return null;
|
|
3442
|
+
}
|
|
3443
|
+
const handle = await this._automergeHost.loadDoc(import_context10.Context.default(void 0, {
|
|
3444
|
+
F: __dxlog_file11,
|
|
3445
|
+
L: 630
|
|
3446
|
+
}), link);
|
|
3447
|
+
const doc = handle.doc();
|
|
3448
|
+
if (!doc) {
|
|
3449
|
+
return null;
|
|
3450
|
+
}
|
|
3451
|
+
const object = import_echo_protocol5.DatabaseDirectory.getInlineObject(doc, echoDxn.echoId);
|
|
3452
|
+
if (!object) {
|
|
3453
|
+
return null;
|
|
3454
|
+
}
|
|
3455
|
+
return {
|
|
3456
|
+
objectId: echoDxn.echoId,
|
|
3457
|
+
documentId: handle.documentId,
|
|
3458
|
+
spaceId,
|
|
3459
|
+
doc: object
|
|
3460
|
+
};
|
|
2662
3461
|
}
|
|
2663
3462
|
};
|
|
2664
|
-
var
|
|
3463
|
+
var __dxlog_file12 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/db-host/query-service.ts";
|
|
2665
3464
|
var QueryServiceImpl = class extends import_context9.Resource {
|
|
2666
3465
|
// TODO(burdon): OK for options, but not params. Pass separately and type readonly here.
|
|
2667
3466
|
constructor(_params) {
|
|
2668
|
-
super()
|
|
2669
|
-
this._params = _params;
|
|
2670
|
-
this._queries = /* @__PURE__ */ new Set();
|
|
2671
|
-
this._updateQueries = new import_async6.DeferredTask(this._ctx, async () => {
|
|
3467
|
+
super(), this._params = _params, this._queries = /* @__PURE__ */ new Set(), this._updateQueries = new import_async6.DeferredTask(this._ctx, async () => {
|
|
2672
3468
|
await Promise.all(Array.from(this._queries).map(async (query) => {
|
|
2673
3469
|
try {
|
|
2674
|
-
const { changed } = await query.
|
|
3470
|
+
const { changed } = await query.executor.execQuery();
|
|
2675
3471
|
if (changed) {
|
|
2676
|
-
query.sendResults(query.
|
|
3472
|
+
query.sendResults(query.executor.getResults());
|
|
2677
3473
|
}
|
|
2678
3474
|
} catch (err) {
|
|
2679
3475
|
import_log9.log.catch(err, void 0, {
|
|
2680
|
-
F:
|
|
2681
|
-
L:
|
|
3476
|
+
F: __dxlog_file12,
|
|
3477
|
+
L: 57,
|
|
2682
3478
|
S: this,
|
|
2683
3479
|
C: (f, a) => f(...a)
|
|
2684
3480
|
});
|
|
@@ -2691,8 +3487,9 @@ var QueryServiceImpl = class extends import_context9.Resource {
|
|
|
2691
3487
|
fetch: () => {
|
|
2692
3488
|
return Array.from(this._queries).map((query) => {
|
|
2693
3489
|
return {
|
|
2694
|
-
|
|
2695
|
-
|
|
3490
|
+
query: JSON.stringify(query.executor.query),
|
|
3491
|
+
plan: JSON.stringify(query.executor.plan),
|
|
3492
|
+
trace: JSON.stringify(query.executor.trace)
|
|
2696
3493
|
};
|
|
2697
3494
|
});
|
|
2698
3495
|
}
|
|
@@ -2705,24 +3502,19 @@ var QueryServiceImpl = class extends import_context9.Resource {
|
|
|
2705
3502
|
await Promise.all(Array.from(this._queries).map((query) => query.close()));
|
|
2706
3503
|
}
|
|
2707
3504
|
async setConfig(config) {
|
|
2708
|
-
|
|
2709
|
-
import_log9.log.warn("Indexer already initialized.", void 0, {
|
|
2710
|
-
F: __dxlog_file11,
|
|
2711
|
-
L: 87,
|
|
2712
|
-
S: this,
|
|
2713
|
-
C: (f, a) => f(...a)
|
|
2714
|
-
});
|
|
2715
|
-
return;
|
|
2716
|
-
}
|
|
2717
|
-
void this._params.indexer.setConfig(config);
|
|
3505
|
+
await this._params.indexer.setConfig(config);
|
|
2718
3506
|
}
|
|
2719
3507
|
execQuery(request) {
|
|
2720
3508
|
return new import_stream2.Stream(({ next, close, ctx }) => {
|
|
2721
|
-
const
|
|
2722
|
-
|
|
3509
|
+
const parsedQuery = import_echo_protocol4.QueryAST.Query.pipe(import_effect.Schema.decodeUnknownSync)(JSON.parse(request.query));
|
|
3510
|
+
const queryEntry = {
|
|
3511
|
+
executor: new QueryExecutor({
|
|
2723
3512
|
indexer: this._params.indexer,
|
|
2724
3513
|
automergeHost: this._params.automergeHost,
|
|
2725
|
-
request
|
|
3514
|
+
queryId: request.queryId ?? (0, import_debug2.raise)(new Error("query id required")),
|
|
3515
|
+
query: parsedQuery,
|
|
3516
|
+
reactivity: request.reactivity,
|
|
3517
|
+
spaceStateManager: this._params.spaceStateManager
|
|
2726
3518
|
}),
|
|
2727
3519
|
sendResults: (results) => {
|
|
2728
3520
|
if (ctx.disposed) {
|
|
@@ -2735,28 +3527,21 @@ var QueryServiceImpl = class extends import_context9.Resource {
|
|
|
2735
3527
|
},
|
|
2736
3528
|
close: async () => {
|
|
2737
3529
|
close();
|
|
2738
|
-
await
|
|
2739
|
-
this._queries.delete(
|
|
3530
|
+
await queryEntry.executor.close();
|
|
3531
|
+
this._queries.delete(queryEntry);
|
|
2740
3532
|
}
|
|
2741
3533
|
};
|
|
2742
|
-
this._queries.add(
|
|
3534
|
+
this._queries.add(queryEntry);
|
|
2743
3535
|
queueMicrotask(async () => {
|
|
2744
|
-
await
|
|
3536
|
+
await queryEntry.executor.open();
|
|
2745
3537
|
try {
|
|
2746
|
-
|
|
2747
|
-
|
|
2748
|
-
query.sendResults(query.state.getResults());
|
|
2749
|
-
}
|
|
3538
|
+
await queryEntry.executor.execQuery();
|
|
3539
|
+
queryEntry.sendResults(queryEntry.executor.getResults());
|
|
2750
3540
|
} catch (error) {
|
|
2751
|
-
|
|
2752
|
-
F: __dxlog_file11,
|
|
2753
|
-
L: 124,
|
|
2754
|
-
S: this,
|
|
2755
|
-
C: (f, a) => f(...a)
|
|
2756
|
-
});
|
|
3541
|
+
close(error);
|
|
2757
3542
|
}
|
|
2758
3543
|
});
|
|
2759
|
-
return
|
|
3544
|
+
return queryEntry.close;
|
|
2760
3545
|
});
|
|
2761
3546
|
}
|
|
2762
3547
|
/**
|
|
@@ -2764,8 +3549,8 @@ var QueryServiceImpl = class extends import_context9.Resource {
|
|
|
2764
3549
|
*/
|
|
2765
3550
|
async reindex() {
|
|
2766
3551
|
import_log9.log.info("Reindexing all documents...", void 0, {
|
|
2767
|
-
F:
|
|
2768
|
-
L:
|
|
3552
|
+
F: __dxlog_file12,
|
|
3553
|
+
L: 141,
|
|
2769
3554
|
S: this,
|
|
2770
3555
|
C: (f, a) => f(...a)
|
|
2771
3556
|
});
|
|
@@ -2779,8 +3564,8 @@ var QueryServiceImpl = class extends import_context9.Resource {
|
|
|
2779
3564
|
import_log9.log.info("Collected documents...", {
|
|
2780
3565
|
count: ids.size
|
|
2781
3566
|
}, {
|
|
2782
|
-
F:
|
|
2783
|
-
L:
|
|
3567
|
+
F: __dxlog_file12,
|
|
3568
|
+
L: 149,
|
|
2784
3569
|
S: this,
|
|
2785
3570
|
C: (f, a) => f(...a)
|
|
2786
3571
|
});
|
|
@@ -2789,8 +3574,8 @@ var QueryServiceImpl = class extends import_context9.Resource {
|
|
|
2789
3574
|
import_log9.log.info("Marking all documents as dirty...", {
|
|
2790
3575
|
count: ids.size
|
|
2791
3576
|
}, {
|
|
2792
|
-
F:
|
|
2793
|
-
L:
|
|
3577
|
+
F: __dxlog_file12,
|
|
3578
|
+
L: 153,
|
|
2794
3579
|
S: this,
|
|
2795
3580
|
C: (f, a) => f(...a)
|
|
2796
3581
|
});
|
|
@@ -2809,7 +3594,7 @@ var createDocumentsIterator = (automergeHost) => (
|
|
|
2809
3594
|
return;
|
|
2810
3595
|
}
|
|
2811
3596
|
const doc = handle.doc();
|
|
2812
|
-
const spaceKey =
|
|
3597
|
+
const spaceKey = import_echo_protocol4.DatabaseDirectory.getSpaceKey(doc) ?? void 0;
|
|
2813
3598
|
if (doc.objects) {
|
|
2814
3599
|
yield Object.entries(doc.objects).map(([objectId, object]) => {
|
|
2815
3600
|
return {
|
|
@@ -2830,8 +3615,8 @@ var createDocumentsIterator = (automergeHost) => (
|
|
|
2830
3615
|
continue;
|
|
2831
3616
|
}
|
|
2832
3617
|
const linkHandle = await automergeHost.loadDoc(import_context9.Context.default(void 0, {
|
|
2833
|
-
F:
|
|
2834
|
-
L:
|
|
3618
|
+
F: __dxlog_file12,
|
|
3619
|
+
L: 195
|
|
2835
3620
|
}), urlString);
|
|
2836
3621
|
for await (const result of getObjectsFromHandle(linkHandle)) {
|
|
2837
3622
|
yield result;
|
|
@@ -2851,7 +3636,7 @@ var createDocumentsIterator = (automergeHost) => (
|
|
|
2851
3636
|
}
|
|
2852
3637
|
}
|
|
2853
3638
|
);
|
|
2854
|
-
var
|
|
3639
|
+
var __dxlog_file13 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/db-host/automerge-metrics.ts";
|
|
2855
3640
|
var measureDocMetrics = (doc) => {
|
|
2856
3641
|
const snapshot = A4.save(doc);
|
|
2857
3642
|
const start = Date.now();
|
|
@@ -2862,10 +3647,10 @@ var measureDocMetrics = (doc) => {
|
|
|
2862
3647
|
const mutationCount = A4.getAllChanges(doc).length;
|
|
2863
3648
|
const getAllChangesEnd = Date.now();
|
|
2864
3649
|
if (getAllChangesEnd - getAllChangesStart > 300) {
|
|
2865
|
-
|
|
3650
|
+
import_log11.log.warn("getAllChanges took too long", {
|
|
2866
3651
|
elapsed: getAllChangesEnd - getAllChangesStart
|
|
2867
3652
|
}, {
|
|
2868
|
-
F:
|
|
3653
|
+
F: __dxlog_file13,
|
|
2869
3654
|
L: 31,
|
|
2870
3655
|
S: void 0,
|
|
2871
3656
|
C: (f, a) => f(...a)
|
|
@@ -2877,7 +3662,7 @@ var measureDocMetrics = (doc) => {
|
|
|
2877
3662
|
mutationCount
|
|
2878
3663
|
};
|
|
2879
3664
|
};
|
|
2880
|
-
var
|
|
3665
|
+
var __dxlog_file14 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/db-host/database-root.ts";
|
|
2881
3666
|
var DatabaseRoot = class {
|
|
2882
3667
|
static mapLinks(doc, mapping) {
|
|
2883
3668
|
doc.change((d) => {
|
|
@@ -2915,14 +3700,14 @@ var DatabaseRoot = class {
|
|
|
2915
3700
|
if (!doc) {
|
|
2916
3701
|
return null;
|
|
2917
3702
|
}
|
|
2918
|
-
return doc.version ??
|
|
3703
|
+
return doc.version ?? import_echo_protocol6.SpaceDocVersion.LEGACY;
|
|
2919
3704
|
}
|
|
2920
3705
|
getSpaceKey() {
|
|
2921
3706
|
const doc = this.doc();
|
|
2922
3707
|
if (!doc) {
|
|
2923
3708
|
return null;
|
|
2924
3709
|
}
|
|
2925
|
-
return
|
|
3710
|
+
return import_echo_protocol6.DatabaseDirectory.getSpaceKey(doc);
|
|
2926
3711
|
}
|
|
2927
3712
|
getInlineObjectCount() {
|
|
2928
3713
|
const doc = this.doc();
|
|
@@ -2940,9 +3725,9 @@ var DatabaseRoot = class {
|
|
|
2940
3725
|
}
|
|
2941
3726
|
getAllLinkedDocuments() {
|
|
2942
3727
|
const doc = this.doc();
|
|
2943
|
-
(0,
|
|
2944
|
-
F:
|
|
2945
|
-
L:
|
|
3728
|
+
(0, import_invariant13.invariant)(doc, void 0, {
|
|
3729
|
+
F: __dxlog_file14,
|
|
3730
|
+
L: 88,
|
|
2946
3731
|
S: this,
|
|
2947
3732
|
A: [
|
|
2948
3733
|
"doc",
|
|
@@ -2959,7 +3744,7 @@ var DatabaseRoot = class {
|
|
|
2959
3744
|
return measureDocMetrics(doc);
|
|
2960
3745
|
}
|
|
2961
3746
|
};
|
|
2962
|
-
var
|
|
3747
|
+
var __dxlog_file15 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/db-host/space-state-manager.ts";
|
|
2963
3748
|
var SpaceStateManager = class extends import_context11.Resource {
|
|
2964
3749
|
constructor() {
|
|
2965
3750
|
super(...arguments);
|
|
@@ -2984,6 +3769,22 @@ var SpaceStateManager = class extends import_context11.Resource {
|
|
|
2984
3769
|
getSpaceRootDocumentId(spaceId) {
|
|
2985
3770
|
return this._rootBySpace.get(spaceId);
|
|
2986
3771
|
}
|
|
3772
|
+
getRootBySpaceId(spaceId) {
|
|
3773
|
+
(0, import_invariant12.invariant)(this._lifecycleState === import_context11.LifecycleState.OPEN, void 0, {
|
|
3774
|
+
F: __dxlog_file15,
|
|
3775
|
+
L: 44,
|
|
3776
|
+
S: this,
|
|
3777
|
+
A: [
|
|
3778
|
+
"this._lifecycleState === LifecycleState.OPEN",
|
|
3779
|
+
""
|
|
3780
|
+
]
|
|
3781
|
+
});
|
|
3782
|
+
const documentId = this._rootBySpace.get(spaceId);
|
|
3783
|
+
if (!documentId) {
|
|
3784
|
+
return void 0;
|
|
3785
|
+
}
|
|
3786
|
+
return this._roots.get(documentId);
|
|
3787
|
+
}
|
|
2987
3788
|
async assignRootToSpace(spaceId, handle) {
|
|
2988
3789
|
let root;
|
|
2989
3790
|
if (this._roots.has(handle.documentId)) {
|
|
@@ -3002,8 +3803,8 @@ var SpaceStateManager = class extends import_context11.Resource {
|
|
|
3002
3803
|
}
|
|
3003
3804
|
this._rootBySpace.set(spaceId, root.handle.documentId);
|
|
3004
3805
|
const ctx = new import_context11.Context(void 0, {
|
|
3005
|
-
F:
|
|
3006
|
-
L:
|
|
3806
|
+
F: __dxlog_file15,
|
|
3807
|
+
L: 72
|
|
3007
3808
|
});
|
|
3008
3809
|
this._perRootContext.set(root.handle.documentId, ctx);
|
|
3009
3810
|
await root.handle.whenReady();
|
|
@@ -3034,19 +3835,20 @@ var SpaceDocumentListUpdatedEvent = class {
|
|
|
3034
3835
|
this.documentIds = documentIds;
|
|
3035
3836
|
}
|
|
3036
3837
|
};
|
|
3037
|
-
var
|
|
3038
|
-
var
|
|
3039
|
-
|
|
3040
|
-
|
|
3041
|
-
|
|
3042
|
-
kind: import_indexing3.IndexKind.Kind.SCHEMA_MATCH
|
|
3043
|
-
}
|
|
3044
|
-
]
|
|
3838
|
+
var __dxlog_file16 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/db-host/echo-host.ts";
|
|
3839
|
+
var DEFAULT_INDEXING_CONFIG = {
|
|
3840
|
+
// TODO(dmaretskyi): Disabled by default since embedding generation is expensive.
|
|
3841
|
+
fullText: false,
|
|
3842
|
+
vector: false
|
|
3045
3843
|
};
|
|
3046
3844
|
var EchoHost = class extends import_context7.Resource {
|
|
3047
|
-
constructor({ kv, peerIdProvider, getSpaceKeyByRootDocumentId }) {
|
|
3845
|
+
constructor({ kv, indexing = {}, peerIdProvider, getSpaceKeyByRootDocumentId }) {
|
|
3048
3846
|
super();
|
|
3049
3847
|
this._spaceStateManager = new SpaceStateManager();
|
|
3848
|
+
const indexingConfig = {
|
|
3849
|
+
...DEFAULT_INDEXING_CONFIG,
|
|
3850
|
+
...indexing
|
|
3851
|
+
};
|
|
3050
3852
|
this._indexMetadataStore = new import_indexing2.IndexMetadataStore({
|
|
3051
3853
|
db: kv.sublevel("index-metadata")
|
|
3052
3854
|
});
|
|
@@ -3067,10 +3869,32 @@ var EchoHost = class extends import_context7.Resource {
|
|
|
3067
3869
|
loadDocuments: createSelectedDocumentsIterator(this._automergeHost),
|
|
3068
3870
|
indexCooldownTime: process.env.NODE_ENV === "test" ? 0 : void 0
|
|
3069
3871
|
});
|
|
3070
|
-
void this._indexer.setConfig(
|
|
3872
|
+
void this._indexer.setConfig({
|
|
3873
|
+
enabled: true,
|
|
3874
|
+
indexes: [
|
|
3875
|
+
//
|
|
3876
|
+
{
|
|
3877
|
+
kind: import_indexing3.IndexKind.Kind.SCHEMA_MATCH
|
|
3878
|
+
},
|
|
3879
|
+
{
|
|
3880
|
+
kind: import_indexing3.IndexKind.Kind.GRAPH
|
|
3881
|
+
},
|
|
3882
|
+
...indexingConfig.fullText ? [
|
|
3883
|
+
{
|
|
3884
|
+
kind: import_indexing3.IndexKind.Kind.FULL_TEXT
|
|
3885
|
+
}
|
|
3886
|
+
] : [],
|
|
3887
|
+
...indexingConfig.vector ? [
|
|
3888
|
+
{
|
|
3889
|
+
kind: import_indexing3.IndexKind.Kind.VECTOR
|
|
3890
|
+
}
|
|
3891
|
+
] : []
|
|
3892
|
+
]
|
|
3893
|
+
});
|
|
3071
3894
|
this._queryService = new QueryServiceImpl({
|
|
3072
3895
|
automergeHost: this._automergeHost,
|
|
3073
|
-
indexer: this._indexer
|
|
3896
|
+
indexer: this._indexer,
|
|
3897
|
+
spaceStateManager: this._spaceStateManager
|
|
3074
3898
|
});
|
|
3075
3899
|
this._dataService = new DataServiceImpl({
|
|
3076
3900
|
automergeHost: this._automergeHost,
|
|
@@ -3146,8 +3970,8 @@ var EchoHost = class extends import_context7.Resource {
|
|
|
3146
3970
|
});
|
|
3147
3971
|
}
|
|
3148
3972
|
async _close(ctx) {
|
|
3149
|
-
await this._spaceStateManager.close();
|
|
3150
3973
|
await this._queryService.close(ctx);
|
|
3974
|
+
await this._spaceStateManager.close(ctx);
|
|
3151
3975
|
await this._indexer.close(ctx);
|
|
3152
3976
|
await this._automergeHost.close();
|
|
3153
3977
|
}
|
|
@@ -3183,17 +4007,17 @@ var EchoHost = class extends import_context7.Resource {
|
|
|
3183
4007
|
*/
|
|
3184
4008
|
async createSpaceRoot(spaceKey) {
|
|
3185
4009
|
(0, import_invariant8.invariant)(this._lifecycleState === import_context7.LifecycleState.OPEN, void 0, {
|
|
3186
|
-
F:
|
|
3187
|
-
L:
|
|
4010
|
+
F: __dxlog_file16,
|
|
4011
|
+
L: 252,
|
|
3188
4012
|
S: this,
|
|
3189
4013
|
A: [
|
|
3190
4014
|
"this._lifecycleState === LifecycleState.OPEN",
|
|
3191
4015
|
""
|
|
3192
4016
|
]
|
|
3193
4017
|
});
|
|
3194
|
-
const spaceId = await (0,
|
|
4018
|
+
const spaceId = await (0, import_echo_protocol2.createIdFromSpaceKey)(spaceKey);
|
|
3195
4019
|
const automergeRoot = this._automergeHost.createDoc({
|
|
3196
|
-
version:
|
|
4020
|
+
version: import_echo_protocol2.SpaceDocVersion.CURRENT,
|
|
3197
4021
|
access: {
|
|
3198
4022
|
spaceKey: spaceKey.toHex()
|
|
3199
4023
|
},
|
|
@@ -3211,8 +4035,8 @@ var EchoHost = class extends import_context7.Resource {
|
|
|
3211
4035
|
// TODO(dmaretskyi): Change to document id.
|
|
3212
4036
|
async openSpaceRoot(spaceId, automergeUrl) {
|
|
3213
4037
|
(0, import_invariant8.invariant)(this._lifecycleState === import_context7.LifecycleState.OPEN, void 0, {
|
|
3214
|
-
F:
|
|
3215
|
-
L:
|
|
4038
|
+
F: __dxlog_file16,
|
|
4039
|
+
L: 271,
|
|
3216
4040
|
S: this,
|
|
3217
4041
|
A: [
|
|
3218
4042
|
"this._lifecycleState === LifecycleState.OPEN",
|
|
@@ -3240,13 +4064,10 @@ var EchoHost = class extends import_context7.Resource {
|
|
|
3240
4064
|
await this._automergeHost.removeReplicator(replicator);
|
|
3241
4065
|
}
|
|
3242
4066
|
};
|
|
3243
|
-
var
|
|
4067
|
+
var __dxlog_file17 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/edge/inflight-request-limiter.ts";
|
|
3244
4068
|
var InflightRequestLimiter = class extends import_context13.Resource {
|
|
3245
4069
|
constructor(_config) {
|
|
3246
|
-
super();
|
|
3247
|
-
this._config = _config;
|
|
3248
|
-
this._inflightRequestBalance = 0;
|
|
3249
|
-
this._requestBarrier = new import_async9.Trigger();
|
|
4070
|
+
super(), this._config = _config, this._inflightRequestBalance = 0, this._requestBarrier = new import_async9.Trigger();
|
|
3250
4071
|
}
|
|
3251
4072
|
async _open() {
|
|
3252
4073
|
this._inflightRequestBalance = 0;
|
|
@@ -3269,8 +4090,8 @@ var InflightRequestLimiter = class extends import_context13.Resource {
|
|
|
3269
4090
|
if (this._inflightRequestBalance === this._config.maxInflightRequests) {
|
|
3270
4091
|
this._requestBarrier.reset();
|
|
3271
4092
|
this._resetBalanceTimeout = setTimeout(() => {
|
|
3272
|
-
|
|
3273
|
-
F:
|
|
4093
|
+
import_log13.log.warn("Request balance has not changed during specified timeout, resetting request limiter.", void 0, {
|
|
4094
|
+
F: __dxlog_file17,
|
|
3274
4095
|
L: 52,
|
|
3275
4096
|
S: this,
|
|
3276
4097
|
C: (f, a) => f(...a)
|
|
@@ -3291,69 +4112,72 @@ var InflightRequestLimiter = class extends import_context13.Resource {
|
|
|
3291
4112
|
}
|
|
3292
4113
|
}
|
|
3293
4114
|
};
|
|
3294
|
-
function
|
|
3295
|
-
|
|
3296
|
-
|
|
3297
|
-
|
|
3298
|
-
|
|
3299
|
-
|
|
3300
|
-
|
|
3301
|
-
}, empty = {}, stack = [];
|
|
3302
|
-
function using(isAwait, value) {
|
|
3303
|
-
if (value != null) {
|
|
3304
|
-
if (Object(value) !== value) {
|
|
3305
|
-
throw new TypeError("using declarations can only be used with objects, functions, null, or undefined.");
|
|
3306
|
-
}
|
|
3307
|
-
if (isAwait) {
|
|
3308
|
-
var dispose = value[Symbol.asyncDispose || Symbol.for("Symbol.asyncDispose")];
|
|
3309
|
-
}
|
|
3310
|
-
if (dispose == null) {
|
|
3311
|
-
dispose = value[Symbol.dispose || Symbol.for("Symbol.dispose")];
|
|
3312
|
-
}
|
|
3313
|
-
if (typeof dispose !== "function") {
|
|
3314
|
-
throw new TypeError(`Property [Symbol.dispose] is not a function.`);
|
|
3315
|
-
}
|
|
3316
|
-
stack.push({
|
|
3317
|
-
v: value,
|
|
3318
|
-
d: dispose,
|
|
3319
|
-
a: isAwait
|
|
3320
|
-
});
|
|
3321
|
-
} else if (isAwait) {
|
|
3322
|
-
stack.push({
|
|
3323
|
-
d: value,
|
|
3324
|
-
a: isAwait
|
|
3325
|
-
});
|
|
4115
|
+
function _ts_add_disposable_resource(env, value, async) {
|
|
4116
|
+
if (value !== null && value !== void 0) {
|
|
4117
|
+
if (typeof value !== "object" && typeof value !== "function") throw new TypeError("Object expected.");
|
|
4118
|
+
var dispose, inner;
|
|
4119
|
+
if (async) {
|
|
4120
|
+
if (!Symbol.asyncDispose) throw new TypeError("Symbol.asyncDispose is not defined.");
|
|
4121
|
+
dispose = value[Symbol.asyncDispose];
|
|
3326
4122
|
}
|
|
3327
|
-
|
|
4123
|
+
if (dispose === void 0) {
|
|
4124
|
+
if (!Symbol.dispose) throw new TypeError("Symbol.dispose is not defined.");
|
|
4125
|
+
dispose = value[Symbol.dispose];
|
|
4126
|
+
if (async) inner = dispose;
|
|
4127
|
+
}
|
|
4128
|
+
if (typeof dispose !== "function") throw new TypeError("Object not disposable.");
|
|
4129
|
+
if (inner) dispose = function() {
|
|
4130
|
+
try {
|
|
4131
|
+
inner.call(this);
|
|
4132
|
+
} catch (e) {
|
|
4133
|
+
return Promise.reject(e);
|
|
4134
|
+
}
|
|
4135
|
+
};
|
|
4136
|
+
env.stack.push({
|
|
4137
|
+
value,
|
|
4138
|
+
dispose,
|
|
4139
|
+
async
|
|
4140
|
+
});
|
|
4141
|
+
} else if (async) {
|
|
4142
|
+
env.stack.push({
|
|
4143
|
+
async: true
|
|
4144
|
+
});
|
|
3328
4145
|
}
|
|
3329
|
-
return
|
|
3330
|
-
|
|
3331
|
-
|
|
3332
|
-
|
|
3333
|
-
|
|
3334
|
-
|
|
3335
|
-
|
|
3336
|
-
|
|
3337
|
-
|
|
3338
|
-
|
|
3339
|
-
|
|
3340
|
-
|
|
3341
|
-
|
|
3342
|
-
|
|
3343
|
-
|
|
3344
|
-
|
|
4146
|
+
return value;
|
|
4147
|
+
}
|
|
4148
|
+
function _ts_dispose_resources(env) {
|
|
4149
|
+
var _SuppressedError = typeof SuppressedError === "function" ? SuppressedError : function(error, suppressed, message) {
|
|
4150
|
+
var e = new Error(message);
|
|
4151
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
4152
|
+
};
|
|
4153
|
+
return (_ts_dispose_resources = function _ts_dispose_resources2(env2) {
|
|
4154
|
+
function fail(e) {
|
|
4155
|
+
env2.error = env2.hasError ? new _SuppressedError(e, env2.error, "An error was suppressed during disposal.") : e;
|
|
4156
|
+
env2.hasError = true;
|
|
4157
|
+
}
|
|
4158
|
+
var r, s = 0;
|
|
4159
|
+
function next() {
|
|
4160
|
+
while (r = env2.stack.pop()) {
|
|
4161
|
+
try {
|
|
4162
|
+
if (!r.async && s === 1) return s = 0, env2.stack.push(r), Promise.resolve().then(next);
|
|
4163
|
+
if (r.dispose) {
|
|
4164
|
+
var result = r.dispose.call(r.value);
|
|
4165
|
+
if (r.async) return s |= 2, Promise.resolve(result).then(next, function(e) {
|
|
4166
|
+
fail(e);
|
|
4167
|
+
return next();
|
|
4168
|
+
});
|
|
4169
|
+
} else s |= 1;
|
|
4170
|
+
} catch (e) {
|
|
4171
|
+
fail(e);
|
|
3345
4172
|
}
|
|
3346
|
-
if (error !== empty) throw error;
|
|
3347
4173
|
}
|
|
3348
|
-
|
|
3349
|
-
|
|
3350
|
-
return next();
|
|
3351
|
-
}
|
|
3352
|
-
return next();
|
|
4174
|
+
if (s === 1) return env2.hasError ? Promise.reject(env2.error) : Promise.resolve();
|
|
4175
|
+
if (env2.hasError) throw env2.error;
|
|
3353
4176
|
}
|
|
3354
|
-
|
|
4177
|
+
return next();
|
|
4178
|
+
})(env);
|
|
3355
4179
|
}
|
|
3356
|
-
var
|
|
4180
|
+
var __dxlog_file18 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/edge/echo-edge-replicator.ts";
|
|
3357
4181
|
var INITIAL_RESTART_DELAY = 500;
|
|
3358
4182
|
var RESTART_DELAY_JITTER = 250;
|
|
3359
4183
|
var MAX_RESTART_DELAY = 5e3;
|
|
@@ -3369,18 +4193,18 @@ var EchoEdgeReplicator = class {
|
|
|
3369
4193
|
this._sharePolicyEnabled = !disableSharePolicy;
|
|
3370
4194
|
}
|
|
3371
4195
|
async connect(context) {
|
|
3372
|
-
|
|
4196
|
+
import_log12.log.info("connecting...", {
|
|
3373
4197
|
peerId: context.peerId,
|
|
3374
4198
|
connectedSpaces: this._connectedSpaces.size
|
|
3375
4199
|
}, {
|
|
3376
|
-
F:
|
|
4200
|
+
F: __dxlog_file18,
|
|
3377
4201
|
L: 61,
|
|
3378
4202
|
S: this,
|
|
3379
4203
|
C: (f, a) => f(...a)
|
|
3380
4204
|
});
|
|
3381
4205
|
this._context = context;
|
|
3382
4206
|
this._ctx = import_context12.Context.default(void 0, {
|
|
3383
|
-
F:
|
|
4207
|
+
F: __dxlog_file18,
|
|
3384
4208
|
L: 64
|
|
3385
4209
|
});
|
|
3386
4210
|
this._ctx.onDispose(this._edgeConnection.onReconnected(() => {
|
|
@@ -3388,9 +4212,13 @@ var EchoEdgeReplicator = class {
|
|
|
3388
4212
|
}));
|
|
3389
4213
|
}
|
|
3390
4214
|
async _handleReconnect() {
|
|
4215
|
+
const env = {
|
|
4216
|
+
stack: [],
|
|
4217
|
+
error: void 0,
|
|
4218
|
+
hasError: false
|
|
4219
|
+
};
|
|
3391
4220
|
try {
|
|
3392
|
-
|
|
3393
|
-
const _guard = _usingCtx.u(await this._mutex.acquire());
|
|
4221
|
+
const _guard = _ts_add_disposable_resource(env, await this._mutex.acquire(), false);
|
|
3394
4222
|
const spaces = [
|
|
3395
4223
|
...this._connectedSpaces
|
|
3396
4224
|
];
|
|
@@ -3403,31 +4231,41 @@ var EchoEdgeReplicator = class {
|
|
|
3403
4231
|
await this._openConnection(spaceId);
|
|
3404
4232
|
}
|
|
3405
4233
|
}
|
|
3406
|
-
} catch (
|
|
3407
|
-
|
|
4234
|
+
} catch (e) {
|
|
4235
|
+
env.error = e;
|
|
4236
|
+
env.hasError = true;
|
|
3408
4237
|
} finally {
|
|
3409
|
-
|
|
4238
|
+
_ts_dispose_resources(env);
|
|
3410
4239
|
}
|
|
3411
4240
|
}
|
|
3412
4241
|
async disconnect() {
|
|
4242
|
+
const env = {
|
|
4243
|
+
stack: [],
|
|
4244
|
+
error: void 0,
|
|
4245
|
+
hasError: false
|
|
4246
|
+
};
|
|
3413
4247
|
try {
|
|
3414
|
-
|
|
3415
|
-
const _guard = _usingCtx.u(await this._mutex.acquire());
|
|
4248
|
+
const _guard = _ts_add_disposable_resource(env, await this._mutex.acquire(), false);
|
|
3416
4249
|
await this._ctx?.dispose();
|
|
3417
4250
|
for (const connection of this._connections.values()) {
|
|
3418
4251
|
await connection.close();
|
|
3419
4252
|
}
|
|
3420
4253
|
this._connections.clear();
|
|
3421
|
-
} catch (
|
|
3422
|
-
|
|
4254
|
+
} catch (e) {
|
|
4255
|
+
env.error = e;
|
|
4256
|
+
env.hasError = true;
|
|
3423
4257
|
} finally {
|
|
3424
|
-
|
|
4258
|
+
_ts_dispose_resources(env);
|
|
3425
4259
|
}
|
|
3426
4260
|
}
|
|
3427
4261
|
async connectToSpace(spaceId) {
|
|
4262
|
+
const env = {
|
|
4263
|
+
stack: [],
|
|
4264
|
+
error: void 0,
|
|
4265
|
+
hasError: false
|
|
4266
|
+
};
|
|
3428
4267
|
try {
|
|
3429
|
-
|
|
3430
|
-
const _guard = _usingCtx.u(await this._mutex.acquire());
|
|
4268
|
+
const _guard = _ts_add_disposable_resource(env, await this._mutex.acquire(), false);
|
|
3431
4269
|
if (this._connectedSpaces.has(spaceId)) {
|
|
3432
4270
|
return;
|
|
3433
4271
|
}
|
|
@@ -3435,31 +4273,37 @@ var EchoEdgeReplicator = class {
|
|
|
3435
4273
|
if (this._context !== null) {
|
|
3436
4274
|
await this._openConnection(spaceId);
|
|
3437
4275
|
}
|
|
3438
|
-
} catch (
|
|
3439
|
-
|
|
4276
|
+
} catch (e) {
|
|
4277
|
+
env.error = e;
|
|
4278
|
+
env.hasError = true;
|
|
3440
4279
|
} finally {
|
|
3441
|
-
|
|
4280
|
+
_ts_dispose_resources(env);
|
|
3442
4281
|
}
|
|
3443
4282
|
}
|
|
3444
4283
|
async disconnectFromSpace(spaceId) {
|
|
4284
|
+
const env = {
|
|
4285
|
+
stack: [],
|
|
4286
|
+
error: void 0,
|
|
4287
|
+
hasError: false
|
|
4288
|
+
};
|
|
3445
4289
|
try {
|
|
3446
|
-
|
|
3447
|
-
const _guard = _usingCtx.u(await this._mutex.acquire());
|
|
4290
|
+
const _guard = _ts_add_disposable_resource(env, await this._mutex.acquire(), false);
|
|
3448
4291
|
this._connectedSpaces.delete(spaceId);
|
|
3449
4292
|
const connection = this._connections.get(spaceId);
|
|
3450
4293
|
if (connection) {
|
|
3451
4294
|
await connection.close();
|
|
3452
4295
|
this._connections.delete(spaceId);
|
|
3453
4296
|
}
|
|
3454
|
-
} catch (
|
|
3455
|
-
|
|
4297
|
+
} catch (e) {
|
|
4298
|
+
env.error = e;
|
|
4299
|
+
env.hasError = true;
|
|
3456
4300
|
} finally {
|
|
3457
|
-
|
|
4301
|
+
_ts_dispose_resources(env);
|
|
3458
4302
|
}
|
|
3459
4303
|
}
|
|
3460
4304
|
async _openConnection(spaceId, reconnects = 0) {
|
|
3461
|
-
(0,
|
|
3462
|
-
F:
|
|
4305
|
+
(0, import_invariant14.invariant)(this._context, void 0, {
|
|
4306
|
+
F: __dxlog_file18,
|
|
3463
4307
|
L: 125,
|
|
3464
4308
|
S: this,
|
|
3465
4309
|
A: [
|
|
@@ -3467,8 +4311,8 @@ var EchoEdgeReplicator = class {
|
|
|
3467
4311
|
""
|
|
3468
4312
|
]
|
|
3469
4313
|
});
|
|
3470
|
-
(0,
|
|
3471
|
-
F:
|
|
4314
|
+
(0, import_invariant14.invariant)(!this._connections.has(spaceId), void 0, {
|
|
4315
|
+
F: __dxlog_file18,
|
|
3472
4316
|
L: 126,
|
|
3473
4317
|
S: this,
|
|
3474
4318
|
A: [
|
|
@@ -3493,21 +4337,25 @@ var EchoEdgeReplicator = class {
|
|
|
3493
4337
|
return;
|
|
3494
4338
|
}
|
|
3495
4339
|
const restartDelay = Math.min(MAX_RESTART_DELAY, INITIAL_RESTART_DELAY * reconnects) + Math.random() * RESTART_DELAY_JITTER;
|
|
3496
|
-
|
|
4340
|
+
import_log12.log.info("connection restart scheduled", {
|
|
3497
4341
|
spaceId,
|
|
3498
4342
|
reconnects,
|
|
3499
4343
|
restartDelay
|
|
3500
4344
|
}, {
|
|
3501
|
-
F:
|
|
4345
|
+
F: __dxlog_file18,
|
|
3502
4346
|
L: 149,
|
|
3503
4347
|
S: this,
|
|
3504
4348
|
C: (f, a) => f(...a)
|
|
3505
4349
|
});
|
|
3506
4350
|
restartScheduled = true;
|
|
3507
4351
|
(0, import_async8.scheduleTask)(this._ctx, async () => {
|
|
4352
|
+
const env = {
|
|
4353
|
+
stack: [],
|
|
4354
|
+
error: void 0,
|
|
4355
|
+
hasError: false
|
|
4356
|
+
};
|
|
3508
4357
|
try {
|
|
3509
|
-
|
|
3510
|
-
const _guard = _usingCtx.u(await this._mutex.acquire());
|
|
4358
|
+
const _guard = _ts_add_disposable_resource(env, await this._mutex.acquire(), false);
|
|
3511
4359
|
if (this._connections.get(spaceId) !== connection) {
|
|
3512
4360
|
return;
|
|
3513
4361
|
}
|
|
@@ -3518,10 +4366,11 @@ var EchoEdgeReplicator = class {
|
|
|
3518
4366
|
return;
|
|
3519
4367
|
}
|
|
3520
4368
|
await this._openConnection(spaceId, reconnects + 1);
|
|
3521
|
-
} catch (
|
|
3522
|
-
|
|
4369
|
+
} catch (e) {
|
|
4370
|
+
env.error = e;
|
|
4371
|
+
env.hasError = true;
|
|
3523
4372
|
} finally {
|
|
3524
|
-
|
|
4373
|
+
_ts_dispose_resources(env);
|
|
3525
4374
|
}
|
|
3526
4375
|
}, restartDelay);
|
|
3527
4376
|
}
|
|
@@ -3562,8 +4411,8 @@ var EdgeReplicatorConnection = class extends import_context12.Resource {
|
|
|
3562
4411
|
});
|
|
3563
4412
|
}
|
|
3564
4413
|
async _open(ctx) {
|
|
3565
|
-
(0,
|
|
3566
|
-
F:
|
|
4414
|
+
(0, import_log12.log)("opening...", void 0, {
|
|
4415
|
+
F: __dxlog_file18,
|
|
3567
4416
|
L: 252,
|
|
3568
4417
|
S: this,
|
|
3569
4418
|
C: (f, a) => f(...a)
|
|
@@ -3575,8 +4424,8 @@ var EdgeReplicatorConnection = class extends import_context12.Resource {
|
|
|
3575
4424
|
await this._onRemoteConnected();
|
|
3576
4425
|
}
|
|
3577
4426
|
async _close() {
|
|
3578
|
-
(0,
|
|
3579
|
-
F:
|
|
4427
|
+
(0, import_log12.log)("closing...", void 0, {
|
|
4428
|
+
F: __dxlog_file18,
|
|
3580
4429
|
L: 267,
|
|
3581
4430
|
S: this,
|
|
3582
4431
|
C: (f, a) => f(...a)
|
|
@@ -3586,8 +4435,8 @@ var EdgeReplicatorConnection = class extends import_context12.Resource {
|
|
|
3586
4435
|
await this._onRemoteDisconnected();
|
|
3587
4436
|
}
|
|
3588
4437
|
get peerId() {
|
|
3589
|
-
(0,
|
|
3590
|
-
F:
|
|
4438
|
+
(0, import_invariant14.invariant)(this._remotePeerId, "Not connected", {
|
|
4439
|
+
F: __dxlog_file18,
|
|
3591
4440
|
L: 276,
|
|
3592
4441
|
S: this,
|
|
3593
4442
|
A: [
|
|
@@ -3607,12 +4456,12 @@ var EdgeReplicatorConnection = class extends import_context12.Resource {
|
|
|
3607
4456
|
documentId: params.documentId,
|
|
3608
4457
|
peerId: this._remotePeerId
|
|
3609
4458
|
});
|
|
3610
|
-
|
|
4459
|
+
import_log12.log.verbose("document not found locally for share policy check", {
|
|
3611
4460
|
documentId: params.documentId,
|
|
3612
4461
|
acceptDocument: remoteDocumentExists,
|
|
3613
4462
|
remoteId: this._remotePeerId
|
|
3614
4463
|
}, {
|
|
3615
|
-
F:
|
|
4464
|
+
F: __dxlog_file18,
|
|
3616
4465
|
L: 291,
|
|
3617
4466
|
S: this,
|
|
3618
4467
|
C: (f, a) => f(...a)
|
|
@@ -3633,12 +4482,12 @@ var EdgeReplicatorConnection = class extends import_context12.Resource {
|
|
|
3633
4482
|
return;
|
|
3634
4483
|
}
|
|
3635
4484
|
const payload = import_automerge_repo6.cbor.decode(message.payload.value);
|
|
3636
|
-
|
|
4485
|
+
import_log12.log.verbose("received", {
|
|
3637
4486
|
type: payload.type,
|
|
3638
4487
|
documentId: payload.type === "sync" && payload.documentId,
|
|
3639
4488
|
remoteId: this._remotePeerId
|
|
3640
4489
|
}, {
|
|
3641
|
-
F:
|
|
4490
|
+
F: __dxlog_file18,
|
|
3642
4491
|
L: 320,
|
|
3643
4492
|
S: this,
|
|
3644
4493
|
C: (f, a) => f(...a)
|
|
@@ -3656,12 +4505,12 @@ var EdgeReplicatorConnection = class extends import_context12.Resource {
|
|
|
3656
4505
|
}
|
|
3657
4506
|
async _sendMessage(message) {
|
|
3658
4507
|
message.targetId = this._targetServiceId;
|
|
3659
|
-
|
|
4508
|
+
import_log12.log.verbose("sending...", {
|
|
3660
4509
|
type: message.type,
|
|
3661
4510
|
documentId: message.type === "sync" && message.documentId,
|
|
3662
4511
|
remoteId: this._remotePeerId
|
|
3663
4512
|
}, {
|
|
3664
|
-
F:
|
|
4513
|
+
F: __dxlog_file18,
|
|
3665
4514
|
L: 349,
|
|
3666
4515
|
S: this,
|
|
3667
4516
|
C: (f, a) => f(...a)
|
|
@@ -3683,7 +4532,8 @@ var isForbiddenErrorMessage = (message) => message.type === "error" && message.m
|
|
|
3683
4532
|
var findInlineObjectOfType = (spaceDoc, typename) => {
|
|
3684
4533
|
for (const id in spaceDoc.objects ?? {}) {
|
|
3685
4534
|
const obj = spaceDoc.objects[id];
|
|
3686
|
-
|
|
4535
|
+
const objType = import_echo_protocol7.ObjectStructure.getTypeReference(obj);
|
|
4536
|
+
if (objType && (0, import_echo_protocol7.decodeReference)(objType).objectId === typename) {
|
|
3687
4537
|
return [
|
|
3688
4538
|
id,
|
|
3689
4539
|
obj
|
|
@@ -3705,6 +4555,7 @@ var findInlineObjectOfType = (spaceDoc, typename) => {
|
|
|
3705
4555
|
EchoDataMonitor,
|
|
3706
4556
|
EchoEdgeReplicator,
|
|
3707
4557
|
EchoHost,
|
|
4558
|
+
ExecutionTrace,
|
|
3708
4559
|
FIND_PARAMS,
|
|
3709
4560
|
LevelDBStorageAdapter,
|
|
3710
4561
|
MOCK_AUTH_PROVIDER,
|
|
@@ -3712,8 +4563,10 @@ var findInlineObjectOfType = (spaceDoc, typename) => {
|
|
|
3712
4563
|
MeshEchoReplicator,
|
|
3713
4564
|
MetadataStore,
|
|
3714
4565
|
Pipeline,
|
|
4566
|
+
QueryExecutor,
|
|
4567
|
+
QueryPlan,
|
|
4568
|
+
QueryPlanner,
|
|
3715
4569
|
QueryServiceImpl,
|
|
3716
|
-
QueryState,
|
|
3717
4570
|
Space,
|
|
3718
4571
|
SpaceDocumentListUpdatedEvent,
|
|
3719
4572
|
SpaceManager,
|
|
@@ -3727,9 +4580,10 @@ var findInlineObjectOfType = (spaceDoc, typename) => {
|
|
|
3727
4580
|
deriveCollectionIdFromSpaceId,
|
|
3728
4581
|
diffCollectionState,
|
|
3729
4582
|
encodingOptions,
|
|
4583
|
+
filterMatchObject,
|
|
4584
|
+
filterMatchValue,
|
|
3730
4585
|
findInlineObjectOfType,
|
|
3731
4586
|
getSpaceIdFromCollectionId,
|
|
3732
|
-
getSpaceKeyFromDoc,
|
|
3733
4587
|
hasInvitationExpired,
|
|
3734
4588
|
mapFeedIndexesToTimeframe,
|
|
3735
4589
|
mapTimeframeToFeedIndexes,
|