@dxos/index-core 0.8.4-main.e00bdcdb52 → 0.8.4-main.effb148878
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/LICENSE +102 -5
- package/README.md +1 -1
- package/dist/lib/neutral/index.mjs +121 -57
- package/dist/lib/neutral/index.mjs.map +3 -3
- package/dist/lib/neutral/meta.json +1 -1
- package/dist/types/src/index-engine.d.ts +16 -6
- package/dist/types/src/index-engine.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +1 -1
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/indexes/fts-index.d.ts +1 -0
- package/dist/types/src/indexes/fts-index.d.ts.map +1 -1
- package/dist/types/src/indexes/interface.d.ts +5 -0
- package/dist/types/src/indexes/interface.d.ts.map +1 -1
- package/dist/types/src/indexes/object-meta-index.d.ts +25 -11
- package/dist/types/src/indexes/object-meta-index.d.ts.map +1 -1
- package/dist/types/src/indexes/reverse-ref-index.d.ts +3 -2
- package/dist/types/src/indexes/reverse-ref-index.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +12 -12
- package/src/index-engine.test.ts +121 -8
- package/src/index-engine.ts +83 -29
- package/src/index.ts +7 -1
- package/src/indexes/fts-index.test.ts +135 -3
- package/src/indexes/fts-index.ts +25 -8
- package/src/indexes/interface.ts +5 -0
- package/src/indexes/object-meta-index.test.ts +73 -24
- package/src/indexes/object-meta-index.ts +58 -33
- package/src/indexes/reverse-ref-index.test.ts +31 -24
- package/src/indexes/reverse-ref-index.ts +16 -14
package/LICENSE
CHANGED
|
@@ -1,8 +1,105 @@
|
|
|
1
|
-
|
|
2
|
-
Copyright (c) 2022 DXOS
|
|
1
|
+
# Functional Source License, Version 1.1, ALv2 Future License
|
|
3
2
|
|
|
4
|
-
|
|
3
|
+
## Abbreviation
|
|
5
4
|
|
|
6
|
-
|
|
5
|
+
FSL-1.1-Apache-2.0
|
|
7
6
|
|
|
8
|
-
|
|
7
|
+
## Notice
|
|
8
|
+
|
|
9
|
+
Copyright 2026 DXOS
|
|
10
|
+
|
|
11
|
+
## Terms and Conditions
|
|
12
|
+
|
|
13
|
+
### Licensor ("We")
|
|
14
|
+
|
|
15
|
+
The party offering the Software under these Terms and Conditions.
|
|
16
|
+
|
|
17
|
+
### The Software
|
|
18
|
+
|
|
19
|
+
The "Software" is each version of the software that we make available under
|
|
20
|
+
these Terms and Conditions, as indicated by our inclusion of these Terms and
|
|
21
|
+
Conditions with the Software.
|
|
22
|
+
|
|
23
|
+
### License Grant
|
|
24
|
+
|
|
25
|
+
Subject to your compliance with this License Grant and the Patents,
|
|
26
|
+
Redistribution and Trademark clauses below, we hereby grant you the right to
|
|
27
|
+
use, copy, modify, create derivative works, publicly perform, publicly display
|
|
28
|
+
and redistribute the Software for any Permitted Purpose identified below.
|
|
29
|
+
|
|
30
|
+
### Permitted Purpose
|
|
31
|
+
|
|
32
|
+
A Permitted Purpose is any purpose other than a Competing Use. A Competing Use
|
|
33
|
+
means making the Software available to others in a commercial product or
|
|
34
|
+
service that:
|
|
35
|
+
|
|
36
|
+
1. substitutes for the Software;
|
|
37
|
+
|
|
38
|
+
2. substitutes for any other product or service we offer using the Software
|
|
39
|
+
that exists as of the date we make the Software available; or
|
|
40
|
+
|
|
41
|
+
3. offers the same or substantially similar functionality as the Software.
|
|
42
|
+
|
|
43
|
+
Permitted Purposes specifically include using the Software:
|
|
44
|
+
|
|
45
|
+
1. for your internal use and access;
|
|
46
|
+
|
|
47
|
+
2. for non-commercial education;
|
|
48
|
+
|
|
49
|
+
3. for non-commercial research; and
|
|
50
|
+
|
|
51
|
+
4. in connection with professional services that you provide to a licensee
|
|
52
|
+
using the Software in accordance with these Terms and Conditions.
|
|
53
|
+
|
|
54
|
+
### Patents
|
|
55
|
+
|
|
56
|
+
To the extent your use for a Permitted Purpose would necessarily infringe our
|
|
57
|
+
patents, the license grant above includes a license under our patents. If you
|
|
58
|
+
make a claim against any party that the Software infringes or contributes to
|
|
59
|
+
the infringement of any patent, then your patent license to the Software ends
|
|
60
|
+
immediately.
|
|
61
|
+
|
|
62
|
+
### Redistribution
|
|
63
|
+
|
|
64
|
+
The Terms and Conditions apply to all copies, modifications and derivatives of
|
|
65
|
+
the Software.
|
|
66
|
+
|
|
67
|
+
If you redistribute any copies, modifications or derivatives of the Software,
|
|
68
|
+
you must include a copy of or a link to these Terms and Conditions and not
|
|
69
|
+
remove any copyright notices provided in or with the Software.
|
|
70
|
+
|
|
71
|
+
### Disclaimer
|
|
72
|
+
|
|
73
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTIES OF ANY KIND, EXPRESS OR
|
|
74
|
+
IMPLIED, INCLUDING WITHOUT LIMITATION WARRANTIES OF FITNESS FOR A PARTICULAR
|
|
75
|
+
PURPOSE, MERCHANTABILITY, TITLE OR NON-INFRINGEMENT.
|
|
76
|
+
|
|
77
|
+
IN NO EVENT WILL WE HAVE ANY LIABILITY TO YOU ARISING OUT OF OR RELATED TO THE
|
|
78
|
+
SOFTWARE, INCLUDING INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES,
|
|
79
|
+
EVEN IF WE HAVE BEEN INFORMED OF THEIR POSSIBILITY IN ADVANCE.
|
|
80
|
+
|
|
81
|
+
### Trademarks
|
|
82
|
+
|
|
83
|
+
Except for displaying the License Details and identifying us as the origin of
|
|
84
|
+
the Software, you have no right under these Terms and Conditions to use our
|
|
85
|
+
trademarks, trade names, service marks or product names.
|
|
86
|
+
|
|
87
|
+
## Grant of Future License
|
|
88
|
+
|
|
89
|
+
We hereby irrevocably grant you an additional license to use the Software under
|
|
90
|
+
the Apache License, Version 2.0 that is effective on the second anniversary of
|
|
91
|
+
the date we make the Software available. On or after that date, you may use the
|
|
92
|
+
Software under the Apache License, Version 2.0, in which case the following
|
|
93
|
+
will apply:
|
|
94
|
+
|
|
95
|
+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
|
96
|
+
this file except in compliance with the License.
|
|
97
|
+
|
|
98
|
+
You may obtain a copy of the License at
|
|
99
|
+
|
|
100
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
101
|
+
|
|
102
|
+
Unless required by applicable law or agreed to in writing, software distributed
|
|
103
|
+
under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
|
104
|
+
CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
|
105
|
+
specific language governing permissions and limitations under the License.
|
package/README.md
CHANGED
|
@@ -18,4 +18,4 @@ pnpm i @dxos/index-core
|
|
|
18
18
|
|
|
19
19
|
Your ideas, issues, and code are most welcome. Please take a look at our [community code of conduct](https://github.com/dxos/dxos/blob/main/CODE_OF_CONDUCT.md), the [issue guide](https://github.com/dxos/dxos/blob/main/CONTRIBUTING.md#submitting-issues), and the [PR contribution guide](https://github.com/dxos/dxos/blob/main/CONTRIBUTING.md#submitting-prs).
|
|
20
20
|
|
|
21
|
-
License: [
|
|
21
|
+
License: [FSL-1.1-Apache-2.0](./LICENSE) Copyright 2022 © DXOS
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// src/index-engine.ts
|
|
2
2
|
import * as Effect5 from "effect/Effect";
|
|
3
|
+
import { ATTR_TYPE as ATTR_TYPE2 } from "@dxos/echo/internal";
|
|
3
4
|
import * as SqlTransaction from "@dxos/sql-sqlite/SqlTransaction";
|
|
4
5
|
|
|
5
6
|
// src/index-tracker.ts
|
|
@@ -88,6 +89,7 @@ var IndexTracker = class {
|
|
|
88
89
|
// src/indexes/fts-index.ts
|
|
89
90
|
import * as SqlClient3 from "@effect/sql/SqlClient";
|
|
90
91
|
import * as Effect2 from "effect/Effect";
|
|
92
|
+
var SQL_CHUNK_SIZE = 500;
|
|
91
93
|
var escapeFts5Query = (text) => {
|
|
92
94
|
return text.split(/\s+/).filter(Boolean).map((term) => `"${term.replace(/"/g, '""')}"`).join(" ");
|
|
93
95
|
};
|
|
@@ -149,6 +151,7 @@ var FtsIndex = class {
|
|
|
149
151
|
/**
|
|
150
152
|
* Query snapshots by recordIds.
|
|
151
153
|
* Returns the parsed JSON snapshots for queue objects.
|
|
154
|
+
* RecordIds not present in the FTS index are silently omitted from the result.
|
|
152
155
|
*/
|
|
153
156
|
querySnapshotsJSON(recordIds) {
|
|
154
157
|
return Effect2.gen(function* () {
|
|
@@ -156,11 +159,21 @@ var FtsIndex = class {
|
|
|
156
159
|
return [];
|
|
157
160
|
}
|
|
158
161
|
const sql = yield* SqlClient3.SqlClient;
|
|
159
|
-
const
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
162
|
+
const chunks = [];
|
|
163
|
+
for (let i = 0; i < recordIds.length; i += SQL_CHUNK_SIZE) {
|
|
164
|
+
chunks.push(recordIds.slice(i, i + SQL_CHUNK_SIZE));
|
|
165
|
+
}
|
|
166
|
+
const allResults = [];
|
|
167
|
+
for (const chunk of chunks) {
|
|
168
|
+
const rows = yield* sql`SELECT rowid, snapshot FROM ftsIndex WHERE rowid IN ${sql.in(chunk)}`;
|
|
169
|
+
for (const r of rows) {
|
|
170
|
+
allResults.push({
|
|
171
|
+
recordId: r.rowid,
|
|
172
|
+
snapshot: JSON.parse(r.snapshot)
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
return allResults;
|
|
164
177
|
});
|
|
165
178
|
}
|
|
166
179
|
update = Effect2.fn("FtsIndex.update")((objects) => Effect2.gen(function* () {
|
|
@@ -187,25 +200,32 @@ import * as SqlClient5 from "@effect/sql/SqlClient";
|
|
|
187
200
|
import * as Effect3 from "effect/Effect";
|
|
188
201
|
import * as Schema2 from "effect/Schema";
|
|
189
202
|
import { ATTR_DELETED, ATTR_PARENT, ATTR_RELATION_SOURCE, ATTR_RELATION_TARGET, ATTR_TYPE } from "@dxos/echo/internal";
|
|
190
|
-
import { DXN } from "@dxos/keys";
|
|
203
|
+
import { DXN, EchoURI, ObjectId, SpaceId as SpaceId2, URI } from "@dxos/keys";
|
|
191
204
|
var _escapeLikePrefix = (prefix) => {
|
|
192
205
|
const escaped = prefix.replaceAll("\\", "\\\\").replaceAll("%", "\\%").replaceAll("_", "\\_");
|
|
193
206
|
return `${escaped}:%`;
|
|
194
207
|
};
|
|
195
208
|
var ObjectMeta = Schema2.Struct({
|
|
196
209
|
recordId: Schema2.Number,
|
|
197
|
-
objectId:
|
|
210
|
+
objectId: ObjectId,
|
|
211
|
+
/** Empty string for non-queue objects. */
|
|
198
212
|
queueId: Schema2.String,
|
|
199
|
-
|
|
213
|
+
/** Queue subspace namespace (e.g. 'data', 'trace'). Empty string for non-queue objects. */
|
|
214
|
+
queueNamespace: Schema2.String,
|
|
215
|
+
spaceId: SpaceId2,
|
|
200
216
|
documentId: Schema2.String,
|
|
201
217
|
entityKind: Schema2.String,
|
|
202
|
-
/**
|
|
203
|
-
|
|
218
|
+
/**
|
|
219
|
+
* Type identifier URI for the object — typename DXN for non-stored schemas,
|
|
220
|
+
* schema-as-object EchoURI for stored (dynamic) schemas. Mirrors the value
|
|
221
|
+
* written into the object's `system.type`.
|
|
222
|
+
*/
|
|
223
|
+
typeDXN: URI.Schema,
|
|
204
224
|
deleted: Schema2.Boolean,
|
|
205
|
-
source: Schema2.NullOr(
|
|
206
|
-
target: Schema2.NullOr(
|
|
225
|
+
source: Schema2.NullOr(EchoURI.Schema),
|
|
226
|
+
target: Schema2.NullOr(EchoURI.Schema),
|
|
207
227
|
/** Parent object id (nullable). */
|
|
208
|
-
parent: Schema2.NullOr(
|
|
228
|
+
parent: Schema2.NullOr(EchoURI.Schema),
|
|
209
229
|
/** Monotonically increasing sequence number assigned on insert/update for tracking indexing order. */
|
|
210
230
|
version: Schema2.Number,
|
|
211
231
|
/** Unix ms timestamp when the object was first indexed. */
|
|
@@ -237,10 +257,11 @@ var ObjectMetaIndex = class {
|
|
|
237
257
|
recordId INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
238
258
|
objectId TEXT NOT NULL,
|
|
239
259
|
queueId TEXT NOT NULL DEFAULT '',
|
|
260
|
+
queueNamespace TEXT NOT NULL DEFAULT '',
|
|
240
261
|
spaceId TEXT NOT NULL,
|
|
241
262
|
documentId TEXT NOT NULL DEFAULT '',
|
|
242
263
|
entityKind TEXT NOT NULL,
|
|
243
|
-
|
|
264
|
+
typeDXN TEXT NOT NULL,
|
|
244
265
|
deleted INTEGER NOT NULL,
|
|
245
266
|
source TEXT,
|
|
246
267
|
target TEXT,
|
|
@@ -252,8 +273,9 @@ var ObjectMetaIndex = class {
|
|
|
252
273
|
yield* Effect3.catchAll(sql`ALTER TABLE objectMeta ADD COLUMN parent TEXT`, () => Effect3.void);
|
|
253
274
|
yield* Effect3.catchAll(sql`ALTER TABLE objectMeta ADD COLUMN createdAt INTEGER`, () => Effect3.void);
|
|
254
275
|
yield* Effect3.catchAll(sql`ALTER TABLE objectMeta ADD COLUMN updatedAt INTEGER`, () => Effect3.void);
|
|
276
|
+
yield* Effect3.catchAll(sql`ALTER TABLE objectMeta ADD COLUMN queueNamespace TEXT NOT NULL DEFAULT ''`, () => Effect3.void);
|
|
255
277
|
yield* sql`CREATE INDEX IF NOT EXISTS idx_object_index_objectId ON objectMeta(spaceId, objectId)`;
|
|
256
|
-
yield* sql`CREATE INDEX IF NOT EXISTS
|
|
278
|
+
yield* sql`CREATE INDEX IF NOT EXISTS idx_object_index_typeDXN ON objectMeta(spaceId, typeDXN)`;
|
|
257
279
|
yield* sql`CREATE INDEX IF NOT EXISTS idx_object_index_version ON objectMeta(version)`;
|
|
258
280
|
yield* sql`CREATE INDEX IF NOT EXISTS idx_object_index_parent ON objectMeta(spaceId, parent)`;
|
|
259
281
|
yield* sql`CREATE INDEX IF NOT EXISTS idx_object_index_updatedAt ON objectMeta(updatedAt)`;
|
|
@@ -261,8 +283,10 @@ var ObjectMetaIndex = class {
|
|
|
261
283
|
});
|
|
262
284
|
query = Effect3.fn("ObjectMetaIndex.query")((query) => Effect3.gen(function* () {
|
|
263
285
|
const sql = yield* SqlClient5.SqlClient;
|
|
264
|
-
const
|
|
265
|
-
const
|
|
286
|
+
const parsedDxn = DXN.isDXN(query.typeDXN) ? query.typeDXN : void 0;
|
|
287
|
+
const hasNoVersion = parsedDxn !== void 0 && DXN.getVersion(parsedDxn) === void 0;
|
|
288
|
+
const legacyTypeDXN = parsedDxn ? `dxn:type:${parsedDxn.slice(4)}` : void 0;
|
|
289
|
+
const rows = hasNoVersion ? yield* sql`SELECT * FROM objectMeta WHERE spaceId = ${query.spaceId} AND (typeDXN = ${query.typeDXN} OR typeDXN LIKE ${_escapeLikePrefix(query.typeDXN)} ESCAPE '\\' ${legacyTypeDXN ? sql`OR typeDXN = ${legacyTypeDXN}` : sql``})` : yield* sql`SELECT * FROM objectMeta WHERE spaceId = ${query.spaceId} AND (typeDXN = ${query.typeDXN} ${legacyTypeDXN ? sql`OR typeDXN = ${legacyTypeDXN}` : sql``})`;
|
|
266
290
|
return rows.map((row) => ({
|
|
267
291
|
...row,
|
|
268
292
|
deleted: !!row.deleted
|
|
@@ -298,12 +322,18 @@ var ObjectMetaIndex = class {
|
|
|
298
322
|
}
|
|
299
323
|
const sql = yield* SqlClient5.SqlClient;
|
|
300
324
|
const sourceCondition = buildSourceCondition(sql, spaceIds, includeAllQueues, queueIds);
|
|
301
|
-
const typeWhere = sql.or(typeDxns.map((
|
|
302
|
-
const
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
325
|
+
const typeWhere = sql.or(typeDxns.map((typeDXN) => {
|
|
326
|
+
const parsedDxn = DXN.isDXN(typeDXN) ? typeDXN : void 0;
|
|
327
|
+
const hasNoVersion = parsedDxn !== void 0 && DXN.getVersion(parsedDxn) === void 0;
|
|
328
|
+
const legacyTypeDXN = parsedDxn ? `dxn:type:${parsedDxn.slice(4)}` : void 0;
|
|
329
|
+
const exactMatch = legacyTypeDXN ? sql.or([
|
|
330
|
+
sql`typeDXN = ${typeDXN}`,
|
|
331
|
+
sql`typeDXN = ${legacyTypeDXN}`
|
|
332
|
+
]) : sql`typeDXN = ${typeDXN}`;
|
|
333
|
+
return hasNoVersion ? sql.or([
|
|
334
|
+
exactMatch,
|
|
335
|
+
sql`typeDXN LIKE ${_escapeLikePrefix(typeDXN)} ESCAPE '\\'`
|
|
336
|
+
]) : exactMatch;
|
|
307
337
|
}));
|
|
308
338
|
const rows = inverted ? yield* sql`SELECT * FROM objectMeta WHERE ${sourceCondition} AND NOT ${typeWhere}` : yield* sql`SELECT * FROM objectMeta WHERE ${sourceCondition} AND ${typeWhere}`;
|
|
309
339
|
return rows.map((row) => ({
|
|
@@ -327,7 +357,7 @@ var ObjectMetaIndex = class {
|
|
|
327
357
|
update = Effect3.fn("ObjectMetaIndex.update")((objects) => Effect3.gen(function* () {
|
|
328
358
|
const sql = yield* SqlClient5.SqlClient;
|
|
329
359
|
yield* Effect3.forEach(objects, (object) => Effect3.gen(function* () {
|
|
330
|
-
const { spaceId, queueId, documentId, data } = object;
|
|
360
|
+
const { spaceId, queueId, queueNamespace, documentId, data } = object;
|
|
331
361
|
const castData = data;
|
|
332
362
|
const objectId = castData.id;
|
|
333
363
|
let existing;
|
|
@@ -342,7 +372,8 @@ var ObjectMetaIndex = class {
|
|
|
342
372
|
const [{ v }] = result;
|
|
343
373
|
const version = (v ?? 0) + 1;
|
|
344
374
|
const entityKind = castData[ATTR_RELATION_SOURCE] ? "relation" : "object";
|
|
345
|
-
const
|
|
375
|
+
const rawTypeDXN = castData[ATTR_TYPE] ? String(castData[ATTR_TYPE]) : "type";
|
|
376
|
+
const typeDXN = DXN.tryMake(rawTypeDXN) ?? rawTypeDXN;
|
|
346
377
|
const deleted = castData[ATTR_DELETED] ? 1 : 0;
|
|
347
378
|
const source = entityKind === "relation" ? castData[ATTR_RELATION_SOURCE] ?? null : null;
|
|
348
379
|
const target = entityKind === "relation" ? castData[ATTR_RELATION_TARGET] ?? null : null;
|
|
@@ -352,8 +383,9 @@ var ObjectMetaIndex = class {
|
|
|
352
383
|
yield* sql`
|
|
353
384
|
UPDATE objectMeta SET
|
|
354
385
|
version = ${version},
|
|
386
|
+
queueNamespace = ${queueNamespace ?? ""},
|
|
355
387
|
entityKind = ${entityKind},
|
|
356
|
-
|
|
388
|
+
typeDXN = ${typeDXN},
|
|
357
389
|
deleted = ${deleted},
|
|
358
390
|
source = ${source},
|
|
359
391
|
target = ${target},
|
|
@@ -364,12 +396,12 @@ var ObjectMetaIndex = class {
|
|
|
364
396
|
} else {
|
|
365
397
|
yield* sql`
|
|
366
398
|
INSERT INTO objectMeta (
|
|
367
|
-
objectId, queueId, spaceId, documentId,
|
|
368
|
-
entityKind,
|
|
399
|
+
objectId, queueId, queueNamespace, spaceId, documentId,
|
|
400
|
+
entityKind, typeDXN, deleted, source, target, parent, version,
|
|
369
401
|
createdAt, updatedAt
|
|
370
402
|
) VALUES (
|
|
371
|
-
${objectId}, ${queueId ?? ""}, ${spaceId}, ${documentId ?? ""},
|
|
372
|
-
${entityKind}, ${
|
|
403
|
+
${objectId}, ${queueId ?? ""}, ${queueNamespace ?? ""}, ${spaceId}, ${documentId ?? ""},
|
|
404
|
+
${entityKind}, ${typeDXN}, ${deleted},
|
|
373
405
|
${source}, ${target}, ${parent}, ${version},
|
|
374
406
|
${sourceTimestamp}, ${sourceTimestamp}
|
|
375
407
|
)
|
|
@@ -463,14 +495,17 @@ var ObjectMetaIndex = class {
|
|
|
463
495
|
* Matches both:
|
|
464
496
|
* - Objects whose `parent` field references one of the given parent ids (standard parent/child hierarchy).
|
|
465
497
|
* - Queue items whose `queueId` equals one of the parent ids (e.g. items inside a Feed, since a feed's queue
|
|
466
|
-
* DXN uses the feed's object id as its queue id — see `Feed.
|
|
498
|
+
* DXN uses the feed's object id as its queue id — see `Feed.getQueueUri`).
|
|
467
499
|
*/
|
|
468
500
|
queryChildren = Effect3.fn("ObjectMetaIndex.queryChildren")((query) => Effect3.gen(function* () {
|
|
469
501
|
if (query.parentIds.length === 0) {
|
|
470
502
|
return [];
|
|
471
503
|
}
|
|
472
504
|
const sql = yield* SqlClient5.SqlClient;
|
|
473
|
-
const
|
|
505
|
+
const parentDzns = query.parentIds.map((id) => EchoURI.make({
|
|
506
|
+
objectId: id
|
|
507
|
+
}));
|
|
508
|
+
const parentDxns = parentDzns;
|
|
474
509
|
const rows = yield* sql`SELECT * FROM objectMeta WHERE ${sql.in("spaceId", query.spaceId)} AND (${sql.in("parent", parentDxns)} OR ${sql.in("queueId", query.parentIds)})`;
|
|
475
510
|
return rows.map((row) => ({
|
|
476
511
|
...row,
|
|
@@ -484,6 +519,7 @@ import * as SqlClient7 from "@effect/sql/SqlClient";
|
|
|
484
519
|
import * as Effect4 from "effect/Effect";
|
|
485
520
|
import * as Schema4 from "effect/Schema";
|
|
486
521
|
import { EncodedReference, isEncodedReference } from "@dxos/echo-protocol";
|
|
522
|
+
import { EchoURI as EchoURI2 } from "@dxos/keys";
|
|
487
523
|
|
|
488
524
|
// src/utils.ts
|
|
489
525
|
import * as Schema3 from "effect/Schema";
|
|
@@ -520,14 +556,15 @@ var extractReferences = (data) => {
|
|
|
520
556
|
const refs = [];
|
|
521
557
|
const visit = (path, value) => {
|
|
522
558
|
if (isEncodedReference(value)) {
|
|
523
|
-
const
|
|
524
|
-
const
|
|
525
|
-
|
|
559
|
+
const uri = EncodedReference.toURI(value);
|
|
560
|
+
const parsedEchoUri = EchoURI2.tryParse(uri);
|
|
561
|
+
const echoUri = parsedEchoUri ? EchoURI2.getObjectId(parsedEchoUri) : void 0;
|
|
562
|
+
if (!echoUri || !parsedEchoUri) {
|
|
526
563
|
return;
|
|
527
564
|
}
|
|
528
565
|
refs.push({
|
|
529
566
|
path,
|
|
530
|
-
|
|
567
|
+
targetDXN: parsedEchoUri
|
|
531
568
|
});
|
|
532
569
|
} else if (typeof value === "object" && value !== null && !Array.isArray(value)) {
|
|
533
570
|
for (const [key, v] of Object.entries(value)) {
|
|
@@ -550,7 +587,7 @@ var extractReferences = (data) => {
|
|
|
550
587
|
};
|
|
551
588
|
var ReverseRef = Schema4.Struct({
|
|
552
589
|
recordId: Schema4.Number,
|
|
553
|
-
|
|
590
|
+
targetDXN: EchoURI2.Schema,
|
|
554
591
|
/**
|
|
555
592
|
* Escaped property path within an object.
|
|
556
593
|
*
|
|
@@ -567,18 +604,18 @@ var ReverseRefIndex = class {
|
|
|
567
604
|
const sql = yield* SqlClient7.SqlClient;
|
|
568
605
|
yield* sql`CREATE TABLE IF NOT EXISTS reverseRef (
|
|
569
606
|
recordId INTEGER NOT NULL,
|
|
570
|
-
|
|
607
|
+
targetDXN TEXT NOT NULL,
|
|
571
608
|
propPath TEXT NOT NULL,
|
|
572
|
-
PRIMARY KEY (recordId,
|
|
609
|
+
PRIMARY KEY (recordId, targetDXN, propPath)
|
|
573
610
|
)`;
|
|
574
|
-
yield* sql`CREATE INDEX IF NOT EXISTS idx_reverse_ref_target ON reverseRef(
|
|
611
|
+
yield* sql`CREATE INDEX IF NOT EXISTS idx_reverse_ref_target ON reverseRef(targetDXN)`;
|
|
575
612
|
});
|
|
576
613
|
/**
|
|
577
614
|
* Query all references pointing to a target DXN.
|
|
578
615
|
*/
|
|
579
|
-
query = Effect4.fn("ReverseRefIndex.query")(({
|
|
616
|
+
query = Effect4.fn("ReverseRefIndex.query")(({ targetDXN }) => Effect4.gen(function* () {
|
|
580
617
|
const sql = yield* SqlClient7.SqlClient;
|
|
581
|
-
const rows = yield* sql`SELECT * FROM reverseRef WHERE
|
|
618
|
+
const rows = yield* sql`SELECT * FROM reverseRef WHERE targetDXN = ${targetDXN}`;
|
|
582
619
|
return rows;
|
|
583
620
|
}));
|
|
584
621
|
update = Effect4.fn("ReverseRefIndex.update")((objects) => Effect4.gen(function* () {
|
|
@@ -590,7 +627,7 @@ var ReverseRefIndex = class {
|
|
|
590
627
|
}
|
|
591
628
|
yield* sql`DELETE FROM reverseRef WHERE recordId = ${recordId}`;
|
|
592
629
|
const refs = extractReferences(data);
|
|
593
|
-
yield* Effect4.forEach(refs, (ref) => sql`INSERT INTO reverseRef (recordId,
|
|
630
|
+
yield* Effect4.forEach(refs, (ref) => sql`INSERT INTO reverseRef (recordId, targetDXN, propPath) VALUES (${recordId}, ${ref.targetDXN}, ${EscapedPropPath.escape(ref.path)})`, {
|
|
594
631
|
discard: true
|
|
595
632
|
});
|
|
596
633
|
}), {
|
|
@@ -600,6 +637,33 @@ var ReverseRefIndex = class {
|
|
|
600
637
|
};
|
|
601
638
|
|
|
602
639
|
// src/index-engine.ts
|
|
640
|
+
var makeEmptyIndexingResult = () => ({
|
|
641
|
+
updated: 0,
|
|
642
|
+
done: true,
|
|
643
|
+
spaces: /* @__PURE__ */ new Set(),
|
|
644
|
+
queues: /* @__PURE__ */ new Set(),
|
|
645
|
+
documents: /* @__PURE__ */ new Set(),
|
|
646
|
+
types: /* @__PURE__ */ new Set(),
|
|
647
|
+
objects: /* @__PURE__ */ new Set()
|
|
648
|
+
});
|
|
649
|
+
var accumulateIndexingResult = (acc, objects) => {
|
|
650
|
+
for (const obj of objects) {
|
|
651
|
+
acc.spaces.add(obj.spaceId);
|
|
652
|
+
if (obj.queueId) {
|
|
653
|
+
acc.queues.add(obj.queueId);
|
|
654
|
+
}
|
|
655
|
+
if (obj.documentId) {
|
|
656
|
+
acc.documents.add(obj.documentId);
|
|
657
|
+
}
|
|
658
|
+
const t = obj.data[ATTR_TYPE2];
|
|
659
|
+
if (t) {
|
|
660
|
+
acc.types.add(String(t));
|
|
661
|
+
}
|
|
662
|
+
if (obj.data.id) {
|
|
663
|
+
acc.objects.add(obj.data.id);
|
|
664
|
+
}
|
|
665
|
+
}
|
|
666
|
+
};
|
|
603
667
|
var IndexEngine = class {
|
|
604
668
|
#tracker;
|
|
605
669
|
#objectMetaIndex;
|
|
@@ -666,26 +730,24 @@ var IndexEngine = class {
|
|
|
666
730
|
}
|
|
667
731
|
update(ctx, dataSource, opts) {
|
|
668
732
|
return Effect5.gen(this, function* () {
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
const { updated: updatedFtsIndex, done: doneFtsIndex } = yield* this.#update(ctx, this.#ftsIndex, dataSource, {
|
|
733
|
+
const result = makeEmptyIndexingResult();
|
|
734
|
+
const { updated: updatedFtsIndex, done: doneFtsIndex, objects: ftsObjects } = yield* this.#update(ctx, this.#ftsIndex, dataSource, {
|
|
672
735
|
indexName: "fts5",
|
|
673
736
|
spaceId: opts.spaceId,
|
|
674
737
|
limit: opts.limit
|
|
675
738
|
});
|
|
676
|
-
updated += updatedFtsIndex;
|
|
677
|
-
done = done && doneFtsIndex;
|
|
678
|
-
|
|
739
|
+
result.updated += updatedFtsIndex;
|
|
740
|
+
result.done = result.done && doneFtsIndex;
|
|
741
|
+
accumulateIndexingResult(result, ftsObjects);
|
|
742
|
+
const { updated: updatedReverseRefIndex, done: doneReverseRefIndex, objects: reverseRefObjects } = yield* this.#update(ctx, this.#reverseRefIndex, dataSource, {
|
|
679
743
|
indexName: "reverseRef",
|
|
680
744
|
spaceId: opts.spaceId,
|
|
681
745
|
limit: opts.limit
|
|
682
746
|
});
|
|
683
|
-
updated += updatedReverseRefIndex;
|
|
684
|
-
done = done && doneReverseRefIndex;
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
done
|
|
688
|
-
};
|
|
747
|
+
result.updated += updatedReverseRefIndex;
|
|
748
|
+
result.done = result.done && doneReverseRefIndex;
|
|
749
|
+
accumulateIndexingResult(result, reverseRefObjects);
|
|
750
|
+
return result;
|
|
689
751
|
}).pipe(Effect5.withSpan("IndexEngine.update"));
|
|
690
752
|
}
|
|
691
753
|
/**
|
|
@@ -713,7 +775,8 @@ var IndexEngine = class {
|
|
|
713
775
|
if (objects.length === 0) {
|
|
714
776
|
return {
|
|
715
777
|
updated: 0,
|
|
716
|
-
done: true
|
|
778
|
+
done: true,
|
|
779
|
+
objects: []
|
|
717
780
|
};
|
|
718
781
|
}
|
|
719
782
|
yield* this.#objectMetaIndex.update(objects);
|
|
@@ -728,7 +791,8 @@ var IndexEngine = class {
|
|
|
728
791
|
})));
|
|
729
792
|
return {
|
|
730
793
|
updated: objects.length,
|
|
731
|
-
done: false
|
|
794
|
+
done: false,
|
|
795
|
+
objects
|
|
732
796
|
};
|
|
733
797
|
}));
|
|
734
798
|
}).pipe(Effect5.withSpan("IndexEngine.#update"));
|