@dxos/echo-pipeline 0.8.4-main.dedc0f3 → 0.8.4-main.dfabb4ec29
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/lib/{browser/chunk-I4JBIZSN.mjs → neutral/chunk-VIHYDCCC.mjs} +406 -965
- package/dist/lib/neutral/chunk-VIHYDCCC.mjs.map +7 -0
- package/dist/lib/{browser/chunk-MBMJB3V7.mjs → neutral/chunk-YBC6ONBZ.mjs} +78 -13
- package/dist/lib/neutral/chunk-YBC6ONBZ.mjs.map +7 -0
- package/dist/lib/{browser → neutral}/filter/index.mjs +1 -2
- package/dist/lib/neutral/index.mjs +7065 -0
- package/dist/lib/neutral/index.mjs.map +7 -0
- package/dist/lib/neutral/meta.json +1 -0
- package/dist/lib/{browser → neutral}/testing/index.mjs +111 -395
- package/dist/lib/neutral/testing/index.mjs.map +7 -0
- package/dist/types/src/automerge/automerge-host-subduction.test.d.ts +2 -0
- package/dist/types/src/automerge/automerge-host-subduction.test.d.ts.map +1 -0
- package/dist/types/src/automerge/automerge-host.d.ts +85 -27
- package/dist/types/src/automerge/automerge-host.d.ts.map +1 -1
- package/dist/types/src/automerge/automerge-repo-subduction.test.d.ts +2 -0
- package/dist/types/src/automerge/automerge-repo-subduction.test.d.ts.map +1 -0
- package/dist/types/src/automerge/automerge-repo.test.d.ts +1 -1
- package/dist/types/src/automerge/automerge-repo.test.d.ts.map +1 -1
- package/dist/types/src/automerge/automerge-subduction.test.d.ts +2 -0
- package/dist/types/src/automerge/automerge-subduction.test.d.ts.map +1 -0
- package/dist/types/src/automerge/collection-synchronizer.d.ts +24 -3
- 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 +17 -11
- package/dist/types/src/automerge/echo-network-adapter.d.ts.map +1 -1
- package/dist/types/src/automerge/echo-replicator.d.ts +20 -16
- package/dist/types/src/automerge/echo-replicator.d.ts.map +1 -1
- package/dist/types/src/automerge/handle-state.d.ts +52 -0
- package/dist/types/src/automerge/handle-state.d.ts.map +1 -0
- package/dist/types/src/automerge/heads-store.d.ts +9 -2
- package/dist/types/src/automerge/heads-store.d.ts.map +1 -1
- package/dist/types/src/automerge/index.d.ts +1 -0
- package/dist/types/src/automerge/index.d.ts.map +1 -1
- package/dist/types/src/automerge/leveldb-storage-adapter.d.ts +8 -4
- package/dist/types/src/automerge/leveldb-storage-adapter.d.ts.map +1 -1
- package/dist/types/src/automerge/mesh-echo-replicator-connection.d.ts +8 -8
- package/dist/types/src/automerge/mesh-echo-replicator-connection.d.ts.map +1 -1
- package/dist/types/src/automerge/mesh-echo-replicator.d.ts +6 -5
- package/dist/types/src/automerge/mesh-echo-replicator.d.ts.map +1 -1
- package/dist/types/src/automerge/network-protocol.d.ts.map +1 -1
- package/dist/types/src/automerge/space-collection.d.ts.map +1 -1
- package/dist/types/src/common/feeds.d.ts.map +1 -1
- package/dist/types/src/common/space-id.d.ts.map +1 -1
- package/dist/types/src/db-host/automerge-data-source.d.ts +35 -0
- package/dist/types/src/db-host/automerge-data-source.d.ts.map +1 -0
- package/dist/types/src/db-host/automerge-data-source.test.d.ts +2 -0
- package/dist/types/src/db-host/automerge-data-source.test.d.ts.map +1 -0
- package/dist/types/src/db-host/automerge-metrics.d.ts.map +1 -1
- package/dist/types/src/db-host/data-service.d.ts +7 -6
- package/dist/types/src/db-host/data-service.d.ts.map +1 -1
- package/dist/types/src/db-host/database-root.d.ts +9 -3
- package/dist/types/src/db-host/database-root.d.ts.map +1 -1
- package/dist/types/src/db-host/documents-synchronizer.d.ts +9 -8
- package/dist/types/src/db-host/documents-synchronizer.d.ts.map +1 -1
- package/dist/types/src/db-host/echo-host.d.ts +62 -27
- package/dist/types/src/db-host/echo-host.d.ts.map +1 -1
- package/dist/types/src/db-host/index.d.ts +2 -0
- package/dist/types/src/db-host/index.d.ts.map +1 -1
- package/dist/types/src/db-host/invalidation-hint.d.ts +19 -0
- package/dist/types/src/db-host/invalidation-hint.d.ts.map +1 -0
- package/dist/types/src/db-host/local-queue-service.d.ts +19 -0
- package/dist/types/src/db-host/local-queue-service.d.ts.map +1 -0
- package/dist/types/src/db-host/query-invalidation.test.d.ts +2 -0
- package/dist/types/src/db-host/query-invalidation.test.d.ts.map +1 -0
- package/dist/types/src/db-host/query-service.d.ts +18 -10
- package/dist/types/src/db-host/query-service.d.ts.map +1 -1
- package/dist/types/src/db-host/queue-data-source.d.ts +38 -0
- package/dist/types/src/db-host/queue-data-source.d.ts.map +1 -0
- package/dist/types/src/db-host/queue-service.test.d.ts +2 -0
- package/dist/types/src/db-host/queue-service.test.d.ts.map +1 -0
- 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/db-host/stub.d.ts +11 -0
- package/dist/types/src/db-host/stub.d.ts.map +1 -0
- package/dist/types/src/edge/echo-edge-replicator.d.ts +7 -6
- package/dist/types/src/edge/echo-edge-replicator.d.ts.map +1 -1
- package/dist/types/src/edge/echo-edge-subduction-replicator.d.ts +39 -0
- package/dist/types/src/edge/echo-edge-subduction-replicator.d.ts.map +1 -0
- package/dist/types/src/edge/echo-edge-subduction-replicator.test.d.ts +2 -0
- package/dist/types/src/edge/echo-edge-subduction-replicator.test.d.ts.map +1 -0
- package/dist/types/src/edge/index.d.ts +1 -0
- package/dist/types/src/edge/index.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 +2 -2
- package/dist/types/src/filter/filter-match.d.ts.map +1 -1
- package/dist/types/src/metadata/metadata-store.d.ts.map +1 -1
- package/dist/types/src/pipeline/message-selector.d.ts.map +1 -1
- package/dist/types/src/pipeline/pipeline.d.ts +2 -2
- 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 +20 -21
- package/dist/types/src/query/errors.d.ts.map +1 -1
- package/dist/types/src/query/plan.d.ts +59 -8
- package/dist/types/src/query/plan.d.ts.map +1 -1
- package/dist/types/src/query/query-executor.d.ts +62 -10
- package/dist/types/src/query/query-executor.d.ts.map +1 -1
- package/dist/types/src/query/query-planner.d.ts +10 -1
- package/dist/types/src/query/query-planner.d.ts.map +1 -1
- package/dist/types/src/space/admission-discovery-extension.d.ts.map +1 -1
- package/dist/types/src/space/auth.d.ts +3 -3
- package/dist/types/src/space/auth.d.ts.map +1 -1
- package/dist/types/src/space/control-pipeline.d.ts +4 -3
- package/dist/types/src/space/control-pipeline.d.ts.map +1 -1
- package/dist/types/src/space/space-manager.d.ts +7 -7
- package/dist/types/src/space/space-manager.d.ts.map +1 -1
- package/dist/types/src/space/space-protocol.d.ts +9 -8
- package/dist/types/src/space/space-protocol.d.ts.map +1 -1
- package/dist/types/src/space/space.d.ts +5 -5
- package/dist/types/src/space/space.d.ts.map +1 -1
- package/dist/types/src/testing/change-metadata.d.ts.map +1 -1
- package/dist/types/src/testing/index.d.ts +0 -2
- package/dist/types/src/testing/index.d.ts.map +1 -1
- package/dist/types/src/testing/test-agent-builder.d.ts.map +1 -1
- package/dist/types/src/testing/test-feed-builder.d.ts.map +1 -1
- package/dist/types/src/testing/test-network-adapter.d.ts +1 -1
- package/dist/types/src/testing/test-network-adapter.d.ts.map +1 -1
- package/dist/types/src/testing/test-replicator.d.ts +13 -13
- package/dist/types/src/testing/test-replicator.d.ts.map +1 -1
- package/dist/types/src/util.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +53 -55
- package/src/automerge/automerge-host-subduction.test.ts +247 -0
- package/src/automerge/automerge-host.test.ts +48 -32
- package/src/automerge/automerge-host.ts +367 -170
- package/src/automerge/automerge-repo-subduction.test.ts +1049 -0
- package/src/automerge/automerge-repo.test.ts +284 -77
- package/src/automerge/automerge-subduction.test.ts +330 -0
- package/src/automerge/collection-synchronizer.test.ts +52 -16
- package/src/automerge/collection-synchronizer.ts +117 -34
- package/src/automerge/echo-network-adapter.test.ts +2 -1
- package/src/automerge/echo-network-adapter.ts +40 -29
- package/src/automerge/echo-replicator.ts +21 -16
- package/src/automerge/handle-state.ts +62 -0
- package/src/automerge/heads-store.ts +42 -3
- package/src/automerge/index.ts +1 -0
- package/src/automerge/leveldb-storage-adapter.ts +33 -4
- package/src/automerge/mesh-echo-replicator-connection.ts +8 -8
- package/src/automerge/mesh-echo-replicator.ts +14 -11
- package/src/db-host/automerge-data-source.test.ts +299 -0
- package/src/db-host/automerge-data-source.ts +187 -0
- package/src/db-host/data-service.ts +17 -10
- package/src/db-host/database-root.ts +19 -7
- package/src/db-host/documents-synchronizer.test.ts +143 -14
- package/src/db-host/documents-synchronizer.ts +66 -62
- package/src/db-host/echo-host.ts +340 -87
- package/src/db-host/index.ts +2 -0
- package/src/db-host/invalidation-hint.ts +50 -0
- package/src/db-host/local-queue-service.ts +127 -0
- package/src/db-host/query-invalidation.test.ts +270 -0
- package/src/db-host/query-service.ts +110 -112
- package/src/db-host/queue-data-source.ts +160 -0
- package/src/db-host/queue-service.test.ts +145 -0
- package/src/db-host/space-state-manager.ts +11 -9
- package/src/db-host/stub.ts +33 -0
- package/src/edge/echo-edge-replicator.test.ts +9 -9
- package/src/edge/echo-edge-replicator.ts +76 -47
- package/src/edge/echo-edge-subduction-replicator.test.ts +158 -0
- package/src/edge/echo-edge-subduction-replicator.ts +377 -0
- package/src/edge/index.ts +1 -0
- package/src/filter/filter-match.test.ts +67 -31
- package/src/filter/filter-match.ts +114 -27
- package/src/metadata/metadata-store.ts +8 -5
- package/src/pipeline/pipeline-stress.test.ts +1 -3
- package/src/pipeline/pipeline.test.ts +0 -1
- package/src/pipeline/pipeline.ts +2 -3
- package/src/query/errors.ts +3 -1
- package/src/query/plan.ts +71 -8
- package/src/query/query-executor.ts +1178 -198
- package/src/query/query-planner.test.ts +854 -86
- package/src/query/query-planner.ts +440 -39
- package/src/space/admission-discovery-extension.ts +1 -1
- package/src/space/auth.ts +6 -6
- package/src/space/control-pipeline.test.ts +2 -2
- package/src/space/control-pipeline.ts +7 -7
- package/src/space/space-manager.ts +12 -17
- package/src/space/space-protocol.browser.test.ts +13 -12
- package/src/space/space-protocol.test.ts +13 -13
- package/src/space/space-protocol.ts +16 -15
- package/src/space/space.test.ts +2 -2
- package/src/space/space.ts +9 -10
- package/src/testing/index.ts +0 -2
- package/src/testing/test-agent-builder.ts +0 -1
- package/src/testing/test-network-adapter.ts +24 -3
- package/src/testing/test-replicator.ts +15 -20
- package/src/util.ts +7 -3
- package/dist/lib/browser/chunk-CGS2ULMK.mjs +0 -11
- package/dist/lib/browser/chunk-CGS2ULMK.mjs.map +0 -7
- package/dist/lib/browser/chunk-I4JBIZSN.mjs.map +0 -7
- package/dist/lib/browser/chunk-MBMJB3V7.mjs.map +0 -7
- package/dist/lib/browser/index.mjs +0 -5503
- package/dist/lib/browser/index.mjs.map +0 -7
- package/dist/lib/browser/meta.json +0 -1
- package/dist/lib/browser/testing/index.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-HSLMI22Q.mjs +0 -11
- package/dist/lib/node-esm/chunk-HSLMI22Q.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-XJZTCD4G.mjs +0 -182
- package/dist/lib/node-esm/chunk-XJZTCD4G.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-YOL7JY5W.mjs +0 -2230
- package/dist/lib/node-esm/chunk-YOL7JY5W.mjs.map +0 -7
- package/dist/lib/node-esm/filter/index.mjs +0 -13
- package/dist/lib/node-esm/filter/index.mjs.map +0 -7
- package/dist/lib/node-esm/index.mjs +0 -5503
- package/dist/lib/node-esm/index.mjs.map +0 -7
- package/dist/lib/node-esm/meta.json +0 -1
- package/dist/lib/node-esm/testing/index.mjs +0 -805
- package/dist/lib/node-esm/testing/index.mjs.map +0 -7
- package/dist/types/src/db-host/documents-iterator.d.ts +0 -7
- package/dist/types/src/db-host/documents-iterator.d.ts.map +0 -1
- package/dist/types/src/testing/test-data.d.ts +0 -18
- package/dist/types/src/testing/test-data.d.ts.map +0 -1
- package/dist/types/src/testing/test-schema.d.ts +0 -37
- package/dist/types/src/testing/test-schema.d.ts.map +0 -1
- package/src/db-host/documents-iterator.ts +0 -74
- package/src/testing/test-data.ts +0 -127
- package/src/testing/test-schema.ts +0 -53
- /package/dist/lib/{browser → neutral}/filter/index.mjs.map +0 -0
package/src/db-host/echo-host.ts
CHANGED
|
@@ -2,67 +2,77 @@
|
|
|
2
2
|
// Copyright 2024 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
} from '@automerge/automerge-repo';
|
|
12
|
-
|
|
13
|
-
import { type Context, LifecycleState, Resource } from '@dxos/context';
|
|
5
|
+
import { type AnyDocumentId, type AutomergeUrl, type DocHandle, type DocumentId } from '@automerge/automerge-repo';
|
|
6
|
+
import * as SqlClient from '@effect/sql/SqlClient';
|
|
7
|
+
import * as Effect from 'effect/Effect';
|
|
8
|
+
|
|
9
|
+
import { asyncTimeout, DeferredTask, sleep } from '@dxos/async';
|
|
10
|
+
import { Context, LifecycleState, Resource } from '@dxos/context';
|
|
14
11
|
import { todo } from '@dxos/debug';
|
|
15
12
|
import { type DatabaseDirectory, SpaceDocVersion, createIdFromSpaceKey } from '@dxos/echo-protocol';
|
|
16
|
-
import {
|
|
13
|
+
import { RuntimeProvider } from '@dxos/effect';
|
|
14
|
+
import { FeedStore } from '@dxos/feed';
|
|
15
|
+
import { IndexEngine, type IndexingResult } from '@dxos/index-core';
|
|
17
16
|
import { invariant } from '@dxos/invariant';
|
|
18
|
-
import { type PublicKey, type SpaceId } from '@dxos/keys';
|
|
17
|
+
import { type ObjectId, type PublicKey, type SpaceId } from '@dxos/keys';
|
|
19
18
|
import { type LevelDB } from '@dxos/kv-store';
|
|
20
|
-
import {
|
|
19
|
+
import { log } from '@dxos/log';
|
|
20
|
+
import { type FeedProtocol } from '@dxos/protocols';
|
|
21
|
+
import type { SyncQueueRequest } from '@dxos/protocols/proto/dxos/client/services';
|
|
22
|
+
import type * as SqlTransaction from '@dxos/sql-sqlite/SqlTransaction';
|
|
21
23
|
import { trace } from '@dxos/tracing';
|
|
22
24
|
|
|
23
25
|
import {
|
|
24
26
|
AutomergeHost,
|
|
27
|
+
type AutomergeReplicator,
|
|
25
28
|
type CreateDocOptions,
|
|
26
29
|
EchoDataMonitor,
|
|
27
30
|
type EchoDataStats,
|
|
28
|
-
type EchoReplicator,
|
|
29
|
-
FIND_PARAMS,
|
|
30
31
|
type LoadDocOptions,
|
|
31
32
|
type PeerIdProvider,
|
|
32
33
|
type RootDocumentSpaceKeyProvider,
|
|
33
34
|
deriveCollectionIdFromSpaceId,
|
|
34
35
|
} from '../automerge';
|
|
35
|
-
|
|
36
|
+
import { AutomergeDataSource } from './automerge-data-source';
|
|
36
37
|
import { DataServiceImpl } from './data-service';
|
|
37
38
|
import { type DatabaseRoot } from './database-root';
|
|
38
|
-
import {
|
|
39
|
+
import { hintFromIndexingResult } from './invalidation-hint';
|
|
40
|
+
import { LocalQueueServiceImpl } from './local-queue-service';
|
|
39
41
|
import { QueryServiceImpl } from './query-service';
|
|
42
|
+
import { QueueDataSource } from './queue-data-source';
|
|
40
43
|
import { SpaceStateManager } from './space-state-manager';
|
|
41
44
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
45
|
+
/**
|
|
46
|
+
* Executes "PRAGMA quick_check;" on SQLite database on startup.
|
|
47
|
+
*
|
|
48
|
+
* NOTE: Keep DISABLED in production, "quick" check is O(dbSize) which took 6 seconds for my relatively-small profile.
|
|
49
|
+
*
|
|
50
|
+
*/
|
|
51
|
+
const RUN_SQLITE_QUICK_CHECK_ON_STARTUP = false;
|
|
52
|
+
|
|
53
|
+
export type EchoHostProps = {
|
|
54
|
+
kv: LevelDB;
|
|
55
|
+
peerIdProvider?: PeerIdProvider;
|
|
56
|
+
getSpaceKeyByRootDocumentId?: RootDocumentSpaceKeyProvider;
|
|
57
|
+
|
|
58
|
+
runtime: RuntimeProvider.RuntimeProvider<SqlClient.SqlClient | SqlTransaction.SqlTransaction>;
|
|
47
59
|
|
|
48
60
|
/**
|
|
61
|
+
* This peer is allowed to assign positions (global-order) to items appended to the queue.
|
|
49
62
|
* @default false
|
|
50
63
|
*/
|
|
51
|
-
|
|
52
|
-
}
|
|
64
|
+
assignQueuePositions?: boolean;
|
|
53
65
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
export type EchoHostParams = {
|
|
61
|
-
kv: LevelDB;
|
|
62
|
-
peerIdProvider?: PeerIdProvider;
|
|
63
|
-
getSpaceKeyByRootDocumentId?: RootDocumentSpaceKeyProvider;
|
|
66
|
+
/**
|
|
67
|
+
* Callback to run blocking queue sync.
|
|
68
|
+
*/
|
|
69
|
+
syncQueue?: (ctx: Context, request: SyncQueueRequest) => Promise<void>;
|
|
64
70
|
|
|
65
|
-
|
|
71
|
+
/**
|
|
72
|
+
* Enable Subduction sedimentree transport for Automerge document replication.
|
|
73
|
+
* @default false
|
|
74
|
+
*/
|
|
75
|
+
useSubduction?: boolean;
|
|
66
76
|
};
|
|
67
77
|
|
|
68
78
|
/**
|
|
@@ -72,51 +82,62 @@ export type EchoHostParams = {
|
|
|
72
82
|
* Can sync with pluggable data replicators.
|
|
73
83
|
*/
|
|
74
84
|
export class EchoHost extends Resource {
|
|
75
|
-
private readonly _indexMetadataStore: IndexMetadataStore;
|
|
76
|
-
private readonly _indexer: Indexer;
|
|
77
85
|
private readonly _automergeHost: AutomergeHost;
|
|
78
86
|
private readonly _queryService: QueryServiceImpl;
|
|
79
87
|
private readonly _dataService: DataServiceImpl;
|
|
80
88
|
private readonly _spaceStateManager = new SpaceStateManager();
|
|
81
89
|
private readonly _echoDataMonitor: EchoDataMonitor;
|
|
82
90
|
|
|
83
|
-
|
|
84
|
-
|
|
91
|
+
private readonly _automergeDataSource: AutomergeDataSource;
|
|
92
|
+
private readonly _indexEngine: IndexEngine;
|
|
93
|
+
private readonly _runtime: RuntimeProvider.RuntimeProvider<SqlClient.SqlClient | SqlTransaction.SqlTransaction>;
|
|
94
|
+
private readonly _feedStore: FeedStore;
|
|
95
|
+
private readonly _queueDataSource: QueueDataSource;
|
|
96
|
+
|
|
97
|
+
private _updateIndexes!: DeferredTask;
|
|
98
|
+
|
|
99
|
+
private _queuesService: FeedProtocol.QueueService;
|
|
85
100
|
|
|
86
|
-
|
|
101
|
+
private _indexesUpToDate = false;
|
|
102
|
+
|
|
103
|
+
constructor({
|
|
104
|
+
kv,
|
|
105
|
+
peerIdProvider,
|
|
106
|
+
getSpaceKeyByRootDocumentId,
|
|
107
|
+
runtime,
|
|
108
|
+
assignQueuePositions = false,
|
|
109
|
+
syncQueue,
|
|
110
|
+
useSubduction,
|
|
111
|
+
}: EchoHostProps) {
|
|
112
|
+
super();
|
|
87
113
|
|
|
88
|
-
this._indexMetadataStore = new IndexMetadataStore({ db: kv.sublevel('index-metadata') });
|
|
89
114
|
this._echoDataMonitor = new EchoDataMonitor();
|
|
90
115
|
this._automergeHost = new AutomergeHost({
|
|
91
116
|
db: kv,
|
|
92
117
|
dataMonitor: this._echoDataMonitor,
|
|
93
|
-
indexMetadataStore: this._indexMetadataStore,
|
|
94
118
|
peerIdProvider,
|
|
95
119
|
getSpaceKeyByRootDocumentId,
|
|
120
|
+
useSubduction,
|
|
96
121
|
});
|
|
97
122
|
|
|
98
|
-
this.
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
enabled: true,
|
|
107
|
-
indexes: [
|
|
108
|
-
//
|
|
109
|
-
{ kind: IndexKind.Kind.SCHEMA_MATCH },
|
|
110
|
-
{ kind: IndexKind.Kind.GRAPH },
|
|
111
|
-
|
|
112
|
-
...(indexingConfig.fullText ? [{ kind: IndexKind.Kind.FULL_TEXT }] : []),
|
|
113
|
-
...(indexingConfig.vector ? [{ kind: IndexKind.Kind.VECTOR }] : []),
|
|
114
|
-
],
|
|
123
|
+
this._runtime = runtime;
|
|
124
|
+
this._automergeDataSource = new AutomergeDataSource(this._automergeHost);
|
|
125
|
+
|
|
126
|
+
this._feedStore = new FeedStore({ assignPositions: assignQueuePositions, localActorId: crypto.randomUUID() });
|
|
127
|
+
this._queueDataSource = new QueueDataSource({
|
|
128
|
+
feedStore: this._feedStore,
|
|
129
|
+
runtime: this._runtime,
|
|
130
|
+
getSpaceIds: () => this._spaceStateManager.spaceIds,
|
|
115
131
|
});
|
|
132
|
+
this._queuesService = new LocalQueueServiceImpl(runtime, this._feedStore, syncQueue);
|
|
133
|
+
|
|
134
|
+
// SQLite-based index engine for all queries.
|
|
135
|
+
this._indexEngine = new IndexEngine();
|
|
116
136
|
|
|
117
137
|
this._queryService = new QueryServiceImpl({
|
|
118
138
|
automergeHost: this._automergeHost,
|
|
119
|
-
|
|
139
|
+
indexEngine: this._indexEngine,
|
|
140
|
+
runtime: this._runtime,
|
|
120
141
|
spaceStateManager: this._spaceStateManager,
|
|
121
142
|
});
|
|
122
143
|
|
|
@@ -124,7 +145,9 @@ export class EchoHost extends Resource {
|
|
|
124
145
|
automergeHost: this._automergeHost,
|
|
125
146
|
spaceStateManager: this._spaceStateManager,
|
|
126
147
|
updateIndexes: async () => {
|
|
127
|
-
|
|
148
|
+
do {
|
|
149
|
+
await this._updateIndexes.runBlocking();
|
|
150
|
+
} while (!this._indexesUpToDate);
|
|
128
151
|
},
|
|
129
152
|
});
|
|
130
153
|
|
|
@@ -169,6 +192,10 @@ export class EchoHost extends Resource {
|
|
|
169
192
|
});
|
|
170
193
|
}
|
|
171
194
|
|
|
195
|
+
get spaceIds(): SpaceId[] {
|
|
196
|
+
return this._spaceStateManager.spaceIds;
|
|
197
|
+
}
|
|
198
|
+
|
|
172
199
|
get queryService(): QueryServiceImpl {
|
|
173
200
|
return this._queryService;
|
|
174
201
|
}
|
|
@@ -177,22 +204,56 @@ export class EchoHost extends Resource {
|
|
|
177
204
|
return this._dataService;
|
|
178
205
|
}
|
|
179
206
|
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
*/
|
|
183
|
-
get automergeRepo(): Repo {
|
|
184
|
-
return this._automergeHost.repo;
|
|
207
|
+
get queuesService(): FeedProtocol.QueueService {
|
|
208
|
+
return this._queuesService;
|
|
185
209
|
}
|
|
186
210
|
|
|
187
211
|
get roots(): ReadonlyMap<DocumentId, DatabaseRoot> {
|
|
188
212
|
return this._spaceStateManager.roots;
|
|
189
213
|
}
|
|
190
214
|
|
|
215
|
+
get feedStore(): FeedStore {
|
|
216
|
+
return this._feedStore;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* Index engine for queries.
|
|
221
|
+
*/
|
|
222
|
+
get indexEngine(): IndexEngine {
|
|
223
|
+
return this._indexEngine;
|
|
224
|
+
}
|
|
225
|
+
|
|
191
226
|
protected override async _open(ctx: Context): Promise<void> {
|
|
192
|
-
|
|
193
|
-
await this.
|
|
227
|
+
log('echo-host: opening automerge host...');
|
|
228
|
+
await this._automergeHost.open(ctx);
|
|
229
|
+
log('echo-host: automerge host opened');
|
|
230
|
+
|
|
231
|
+
log('echo-host: opening query service...');
|
|
194
232
|
await this._queryService.open(ctx);
|
|
233
|
+
log('echo-host: query service opened');
|
|
234
|
+
|
|
235
|
+
log('echo-host: opening space state manager...');
|
|
195
236
|
await this._spaceStateManager.open(ctx);
|
|
237
|
+
log('echo-host: space state manager opened');
|
|
238
|
+
|
|
239
|
+
// Timeout needs to be outside effect runtime to catch the layer hanging on startup.
|
|
240
|
+
await asyncTimeout(
|
|
241
|
+
RuntimeProvider.runPromise(this._runtime)(testSqlite()),
|
|
242
|
+
15_000,
|
|
243
|
+
new Error('SQLite quick check timed out'),
|
|
244
|
+
);
|
|
245
|
+
|
|
246
|
+
log('echo-host: running index engine migration...');
|
|
247
|
+
await RuntimeProvider.runPromise(this._runtime)(this._indexEngine.migrate());
|
|
248
|
+
log('echo-host: index engine migration done');
|
|
249
|
+
this._updateIndexes = new DeferredTask(this._ctx, this._runUpdateIndexes);
|
|
250
|
+
|
|
251
|
+
log('echo-host: running feed store migration...');
|
|
252
|
+
await RuntimeProvider.runPromise(this._runtime)(this._feedStore.migrate());
|
|
253
|
+
log('echo-host: feed store migration done');
|
|
254
|
+
this._feedStore.onNewBlocks.on(this._ctx, () => {
|
|
255
|
+
this._updateIndexes.schedule();
|
|
256
|
+
});
|
|
196
257
|
|
|
197
258
|
this._spaceStateManager.spaceDocumentListUpdated.on(this._ctx, (e) => {
|
|
198
259
|
if (e.previousRootId) {
|
|
@@ -204,29 +265,32 @@ export class EchoHost extends Resource {
|
|
|
204
265
|
);
|
|
205
266
|
});
|
|
206
267
|
this._automergeHost.documentsSaved.on(this._ctx, () => {
|
|
207
|
-
this.
|
|
268
|
+
this._updateIndexes.schedule();
|
|
208
269
|
});
|
|
270
|
+
this._updateIndexes.schedule();
|
|
271
|
+
log('echo-host: open complete');
|
|
209
272
|
}
|
|
210
273
|
|
|
211
274
|
protected override async _close(ctx: Context): Promise<void> {
|
|
212
275
|
await this._queryService.close(ctx);
|
|
213
276
|
await this._spaceStateManager.close(ctx);
|
|
214
|
-
await this._indexer.close(ctx);
|
|
215
277
|
await this._automergeHost.close();
|
|
216
278
|
}
|
|
217
279
|
|
|
218
280
|
/**
|
|
219
281
|
* Flush all pending writes to the underlying storage.
|
|
220
282
|
*/
|
|
221
|
-
async flush(): Promise<void> {
|
|
222
|
-
await this._automergeHost.
|
|
283
|
+
async flush(ctx: Context): Promise<void> {
|
|
284
|
+
await this._automergeHost.flush(ctx);
|
|
223
285
|
}
|
|
224
286
|
|
|
225
287
|
/**
|
|
226
288
|
* Perform any pending index updates.
|
|
227
289
|
*/
|
|
228
290
|
async updateIndexes(): Promise<void> {
|
|
229
|
-
|
|
291
|
+
do {
|
|
292
|
+
await this._updateIndexes.runBlocking();
|
|
293
|
+
} while (!this._indexesUpToDate);
|
|
230
294
|
}
|
|
231
295
|
|
|
232
296
|
/**
|
|
@@ -236,25 +300,25 @@ export class EchoHost extends Resource {
|
|
|
236
300
|
return await this._automergeHost.loadDoc(ctx, documentId, opts);
|
|
237
301
|
}
|
|
238
302
|
|
|
239
|
-
async exportDoc(
|
|
240
|
-
return await this._automergeHost.exportDoc(
|
|
303
|
+
async exportDoc(id: AnyDocumentId): Promise<Uint8Array> {
|
|
304
|
+
return await this._automergeHost.exportDoc(id);
|
|
241
305
|
}
|
|
242
306
|
|
|
243
307
|
/**
|
|
244
308
|
* Create new persisted document.
|
|
245
309
|
*/
|
|
246
|
-
createDoc<T>(initialValue?: T, opts?: CreateDocOptions): DocHandle<T
|
|
310
|
+
async createDoc<T>(initialValue?: T, opts?: CreateDocOptions): Promise<DocHandle<T>> {
|
|
247
311
|
return this._automergeHost.createDoc(initialValue, opts);
|
|
248
312
|
}
|
|
249
313
|
|
|
250
314
|
/**
|
|
251
315
|
* Create new space root.
|
|
252
316
|
*/
|
|
253
|
-
async createSpaceRoot(spaceKey: PublicKey): Promise<DatabaseRoot> {
|
|
317
|
+
async createSpaceRoot(ctx: Context, spaceKey: PublicKey): Promise<DatabaseRoot> {
|
|
254
318
|
invariant(this._lifecycleState === LifecycleState.OPEN);
|
|
255
319
|
const spaceId = await createIdFromSpaceKey(spaceKey);
|
|
256
320
|
|
|
257
|
-
const automergeRoot = this._automergeHost.createDoc<DatabaseDirectory>({
|
|
321
|
+
const automergeRoot = await this._automergeHost.createDoc<DatabaseDirectory>({
|
|
258
322
|
version: SpaceDocVersion.CURRENT,
|
|
259
323
|
access: { spaceKey: spaceKey.toHex() },
|
|
260
324
|
|
|
@@ -263,43 +327,232 @@ export class EchoHost extends Resource {
|
|
|
263
327
|
links: {},
|
|
264
328
|
});
|
|
265
329
|
|
|
266
|
-
await this._automergeHost.flush({ documentIds: [automergeRoot.documentId] });
|
|
330
|
+
await this._automergeHost.flush(ctx, { documentIds: [automergeRoot.documentId] });
|
|
267
331
|
|
|
268
|
-
return await this.openSpaceRoot(spaceId, automergeRoot.url);
|
|
332
|
+
return await this.openSpaceRoot(ctx, spaceId, automergeRoot.url);
|
|
269
333
|
}
|
|
270
334
|
|
|
271
335
|
// TODO(dmaretskyi): Change to document id.
|
|
272
|
-
async openSpaceRoot(spaceId: SpaceId, automergeUrl: AutomergeUrl): Promise<DatabaseRoot> {
|
|
336
|
+
async openSpaceRoot(ctx: Context, spaceId: SpaceId, automergeUrl: AutomergeUrl): Promise<DatabaseRoot> {
|
|
273
337
|
invariant(this._lifecycleState === LifecycleState.OPEN);
|
|
274
|
-
const handle = await this._automergeHost.
|
|
275
|
-
|
|
338
|
+
const handle = await this._automergeHost.loadDoc<DatabaseDirectory>(ctx, automergeUrl, {
|
|
339
|
+
fetchFromNetwork: true,
|
|
340
|
+
});
|
|
341
|
+
const query = this._automergeHost.findWithProgress<DatabaseDirectory>(handle.documentId);
|
|
276
342
|
|
|
277
|
-
return this._spaceStateManager.assignRootToSpace(spaceId,
|
|
343
|
+
return this._spaceStateManager.assignRootToSpace(spaceId, query);
|
|
278
344
|
}
|
|
279
345
|
|
|
280
346
|
// TODO(dmaretskyi): Change to document id.
|
|
281
|
-
async closeSpaceRoot(
|
|
347
|
+
async closeSpaceRoot(_automergeUrl: AutomergeUrl): Promise<void> {
|
|
282
348
|
todo();
|
|
283
349
|
}
|
|
284
350
|
|
|
285
351
|
/**
|
|
286
352
|
* Install data replicator.
|
|
287
353
|
*/
|
|
288
|
-
async addReplicator(replicator:
|
|
289
|
-
await this._automergeHost.addReplicator(replicator);
|
|
354
|
+
async addReplicator(ctx: Context, replicator: AutomergeReplicator): Promise<void> {
|
|
355
|
+
await this._automergeHost.addReplicator(ctx, replicator);
|
|
290
356
|
}
|
|
291
357
|
|
|
292
358
|
/**
|
|
293
359
|
* Remove data replicator.
|
|
294
360
|
*/
|
|
295
|
-
async removeReplicator(replicator:
|
|
361
|
+
async removeReplicator(replicator: AutomergeReplicator): Promise<void> {
|
|
296
362
|
await this._automergeHost.removeReplicator(replicator);
|
|
297
363
|
}
|
|
364
|
+
|
|
365
|
+
/**
|
|
366
|
+
* Run collection sync for the given space.
|
|
367
|
+
* Does not wait for the sync to complete.
|
|
368
|
+
*/
|
|
369
|
+
async runCollectionSync(spaceId: SpaceId) {
|
|
370
|
+
const root = this._spaceStateManager.getRootBySpaceId(spaceId);
|
|
371
|
+
if (!root) {
|
|
372
|
+
throw new Error(`Space not found: ${spaceId}`);
|
|
373
|
+
}
|
|
374
|
+
this._automergeHost.refreshCollection(deriveCollectionIdFromSpaceId(spaceId, root.documentId));
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
/**
|
|
378
|
+
* Get all feeds and their blocks for a space.
|
|
379
|
+
* Used for space archive export.
|
|
380
|
+
*/
|
|
381
|
+
async getAllFeedsForSpace(
|
|
382
|
+
spaceId: SpaceId,
|
|
383
|
+
): Promise<Array<{ feedId: string; feedNamespace: string; blocks: FeedProtocol.Block[] }>> {
|
|
384
|
+
return RuntimeProvider.runPromise(this._runtime)(this._feedStore.getAllFeedsForSpace({ spaceId }));
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
private _runUpdateIndexes = async (): Promise<void> => {
|
|
388
|
+
if (this._ctx.disposed || !this.isOpen) {
|
|
389
|
+
return;
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
try {
|
|
393
|
+
const combinedResult = _makeEmptyMergedResult();
|
|
394
|
+
|
|
395
|
+
{
|
|
396
|
+
performance.mark('indexEngine.update.automerge:start');
|
|
397
|
+
const result = await this._indexEngine
|
|
398
|
+
.update(this._ctx, this._automergeDataSource, { spaceId: null, limit: 50 })
|
|
399
|
+
.pipe(RuntimeProvider.runPromise(this._runtime));
|
|
400
|
+
_mergeInto(combinedResult, result);
|
|
401
|
+
performance.measure('Index Automerge', {
|
|
402
|
+
start: 'indexEngine.update.automerge:start',
|
|
403
|
+
detail: {
|
|
404
|
+
devtools: {
|
|
405
|
+
dataType: 'track-entry',
|
|
406
|
+
track: 'Indexing',
|
|
407
|
+
trackGroup: 'ECHO', // Group related tracks together
|
|
408
|
+
color: 'tertiary-dark',
|
|
409
|
+
properties: [['count', result.updated]],
|
|
410
|
+
},
|
|
411
|
+
},
|
|
412
|
+
});
|
|
413
|
+
}
|
|
414
|
+
if (this._ctx.disposed || !this.isOpen) {
|
|
415
|
+
return;
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
{
|
|
419
|
+
performance.mark('indexEngine.update.queue:start');
|
|
420
|
+
const result = await this._indexEngine
|
|
421
|
+
.update(this._ctx, this._queueDataSource, { spaceId: null, limit: 50 })
|
|
422
|
+
.pipe(RuntimeProvider.runPromise(this._runtime));
|
|
423
|
+
_mergeInto(combinedResult, result);
|
|
424
|
+
performance.measure('Index Queues', {
|
|
425
|
+
start: 'indexEngine.update.queue:start',
|
|
426
|
+
detail: {
|
|
427
|
+
devtools: {
|
|
428
|
+
dataType: 'track-entry',
|
|
429
|
+
track: 'Indexing',
|
|
430
|
+
trackGroup: 'ECHO',
|
|
431
|
+
color: 'tertiary-dark',
|
|
432
|
+
properties: [['count', result.updated]],
|
|
433
|
+
},
|
|
434
|
+
},
|
|
435
|
+
});
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
log.verbose('indexEngine update completed', {
|
|
439
|
+
updated: combinedResult.updated,
|
|
440
|
+
done: combinedResult.done,
|
|
441
|
+
spaces: combinedResult.spaces.size,
|
|
442
|
+
queues: combinedResult.queues.size,
|
|
443
|
+
documents: combinedResult.documents.size,
|
|
444
|
+
types: combinedResult.types.size,
|
|
445
|
+
objects: combinedResult.objects.size,
|
|
446
|
+
});
|
|
447
|
+
await sleep(1);
|
|
448
|
+
if (!combinedResult.done) {
|
|
449
|
+
this._indexesUpToDate = false;
|
|
450
|
+
this._updateIndexes!.schedule();
|
|
451
|
+
} else {
|
|
452
|
+
this._indexesUpToDate = true;
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
// Invalidate queries after index update — the indexer is the sole invalidation source.
|
|
456
|
+
const hint = hintFromIndexingResult(combinedResult);
|
|
457
|
+
if (hint) {
|
|
458
|
+
this._queryService.invalidateQueries(hint);
|
|
459
|
+
}
|
|
460
|
+
} catch (err) {
|
|
461
|
+
if (this._ctx.disposed || !this.isOpen) {
|
|
462
|
+
return;
|
|
463
|
+
}
|
|
464
|
+
log.catch(err);
|
|
465
|
+
// Failsafe: prevent queries from freezing if the indexer faults.
|
|
466
|
+
this._queryService.invalidateQueries();
|
|
467
|
+
throw err;
|
|
468
|
+
}
|
|
469
|
+
};
|
|
298
470
|
}
|
|
299
471
|
|
|
300
472
|
export type { EchoDataStats };
|
|
301
473
|
|
|
474
|
+
type MutableIndexingAccumulator = {
|
|
475
|
+
updated: number;
|
|
476
|
+
done: boolean;
|
|
477
|
+
spaces: Set<SpaceId>;
|
|
478
|
+
queues: Set<ObjectId>;
|
|
479
|
+
documents: Set<string>;
|
|
480
|
+
types: Set<string>;
|
|
481
|
+
objects: Set<ObjectId>;
|
|
482
|
+
};
|
|
483
|
+
|
|
484
|
+
const _makeEmptyMergedResult = (): MutableIndexingAccumulator => ({
|
|
485
|
+
updated: 0,
|
|
486
|
+
done: true,
|
|
487
|
+
spaces: new Set(),
|
|
488
|
+
queues: new Set(),
|
|
489
|
+
documents: new Set(),
|
|
490
|
+
types: new Set(),
|
|
491
|
+
objects: new Set(),
|
|
492
|
+
});
|
|
493
|
+
|
|
494
|
+
const _mergeInto = (acc: MutableIndexingAccumulator, r: IndexingResult): void => {
|
|
495
|
+
acc.updated += r.updated;
|
|
496
|
+
acc.done = acc.done && r.done;
|
|
497
|
+
for (const s of r.spaces) {
|
|
498
|
+
acc.spaces.add(s);
|
|
499
|
+
}
|
|
500
|
+
for (const q of r.queues) {
|
|
501
|
+
acc.queues.add(q);
|
|
502
|
+
}
|
|
503
|
+
for (const d of r.documents) {
|
|
504
|
+
acc.documents.add(d);
|
|
505
|
+
}
|
|
506
|
+
for (const t of r.types) {
|
|
507
|
+
acc.types.add(t);
|
|
508
|
+
}
|
|
509
|
+
for (const o of r.objects) {
|
|
510
|
+
acc.objects.add(o);
|
|
511
|
+
}
|
|
512
|
+
};
|
|
513
|
+
|
|
302
514
|
export type EchoStatsDiagnostic = {
|
|
303
515
|
loadedDocsCount: number;
|
|
304
516
|
dataStats: EchoDataStats;
|
|
305
517
|
};
|
|
518
|
+
|
|
519
|
+
/**
|
|
520
|
+
* Sqlite health check on startup.
|
|
521
|
+
*
|
|
522
|
+
* Always runs a cheap schema-level probe (`PRAGMA schema_version` + a read from
|
|
523
|
+
* `sqlite_schema`). These do not walk user data, but they fail fast if the DB
|
|
524
|
+
* file header or schema root page is unreadable.
|
|
525
|
+
*
|
|
526
|
+
* Additionally runs `PRAGMA quick_check` when `RUN_SQLITE_QUICK_CHECK_ON_STARTUP`
|
|
527
|
+
* is enabled. That walks every page and is O(dbSize) — slow on OPFS.
|
|
528
|
+
*/
|
|
529
|
+
const testSqlite = () =>
|
|
530
|
+
Effect.gen(function* () {
|
|
531
|
+
log('begin sqlite health check');
|
|
532
|
+
const sql = yield* SqlClient.SqlClient;
|
|
533
|
+
const databases = yield* sql<{ seq: number; name: string; file: string }>`PRAGMA database_list`;
|
|
534
|
+
log('SQLite databases', { databases });
|
|
535
|
+
|
|
536
|
+
// Cheap header/schema probe: forces SQLite to read the file header and
|
|
537
|
+
// schema root page. Catches catastrophic corruption (bad header,
|
|
538
|
+
// unreadable schema) without walking user data.
|
|
539
|
+
const [schemaVersion] = yield* sql<{ schema_version: number }>`PRAGMA schema_version`;
|
|
540
|
+
const [schemaCount] = yield* sql<{ n: number }>`SELECT count(*) AS n FROM sqlite_schema`;
|
|
541
|
+
log('sqlite schema probe passed', {
|
|
542
|
+
schemaVersion: schemaVersion.schema_version,
|
|
543
|
+
objectCount: schemaCount.n,
|
|
544
|
+
});
|
|
545
|
+
|
|
546
|
+
if (RUN_SQLITE_QUICK_CHECK_ON_STARTUP) {
|
|
547
|
+
// NOTE: This is slow on non-trivial databases: O(dbSize).
|
|
548
|
+
log('starting sqlite quick_check');
|
|
549
|
+
const [result] = yield* sql<{ quick_check: string }>`PRAGMA quick_check`;
|
|
550
|
+
if (result.quick_check !== 'ok') {
|
|
551
|
+
throw new Error('SQLite quick check failed');
|
|
552
|
+
}
|
|
553
|
+
log('sqlite quick_check passed');
|
|
554
|
+
} else {
|
|
555
|
+
log('sqlite quick_check skipped');
|
|
556
|
+
}
|
|
557
|
+
log('sqlite health check complete');
|
|
558
|
+
});
|
package/src/db-host/index.ts
CHANGED
|
@@ -2,9 +2,11 @@
|
|
|
2
2
|
// Copyright 2024 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
+
export * from './automerge-data-source';
|
|
5
6
|
export * from './data-service';
|
|
6
7
|
export * from './documents-synchronizer';
|
|
7
8
|
export * from './echo-host';
|
|
8
9
|
export * from './database-root';
|
|
10
|
+
export * from './invalidation-hint';
|
|
9
11
|
export * from './query-service';
|
|
10
12
|
export * from './space-state-manager';
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2026 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import type { IndexingResult } from '@dxos/index-core';
|
|
6
|
+
import type { ObjectId, SpaceId } from '@dxos/keys';
|
|
7
|
+
|
|
8
|
+
export type InvalidationHint = {
|
|
9
|
+
spaceIds?: ReadonlySet<SpaceId>;
|
|
10
|
+
queueIds?: ReadonlySet<ObjectId>;
|
|
11
|
+
typenames?: ReadonlySet<string>;
|
|
12
|
+
objectIds?: ReadonlySet<ObjectId>;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Converts an IndexingResult to an InvalidationHint.
|
|
17
|
+
* Returns undefined when nothing was indexed (no need to invalidate).
|
|
18
|
+
*/
|
|
19
|
+
export const hintFromIndexingResult = (r: IndexingResult): InvalidationHint | undefined => {
|
|
20
|
+
if (r.updated === 0) {
|
|
21
|
+
return undefined;
|
|
22
|
+
}
|
|
23
|
+
return {
|
|
24
|
+
spaceIds: r.spaces.size > 0 ? r.spaces : undefined,
|
|
25
|
+
queueIds: r.queues.size > 0 ? r.queues : undefined,
|
|
26
|
+
typenames: r.types.size > 0 ? r.types : undefined,
|
|
27
|
+
objectIds: r.objects.size > 0 ? r.objects : undefined,
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Merges two hints for the same tick.
|
|
33
|
+
* If either side leaves a dimension unconstrained (undefined), the merged result is also unconstrained on that dimension.
|
|
34
|
+
*/
|
|
35
|
+
export const mergeHints = (a: InvalidationHint, b: InvalidationHint): InvalidationHint => ({
|
|
36
|
+
spaceIds: unionOrUndefined(a.spaceIds, b.spaceIds),
|
|
37
|
+
queueIds: unionOrUndefined(a.queueIds, b.queueIds),
|
|
38
|
+
typenames: unionOrUndefined(a.typenames, b.typenames),
|
|
39
|
+
objectIds: unionOrUndefined(a.objectIds, b.objectIds),
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
const unionOrUndefined = <T>(
|
|
43
|
+
a: ReadonlySet<T> | undefined,
|
|
44
|
+
b: ReadonlySet<T> | undefined,
|
|
45
|
+
): ReadonlySet<T> | undefined => {
|
|
46
|
+
if (a === undefined || b === undefined) {
|
|
47
|
+
return undefined;
|
|
48
|
+
}
|
|
49
|
+
return new Set<T>([...a, ...b]);
|
|
50
|
+
};
|