@dxos/index-core 0.8.4-main.e00bdcdb52 → 0.8.4-main.f466a3d56e
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 +89 -44
- 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 +5 -3
- package/dist/types/src/indexes/object-meta-index.d.ts.map +1 -1
- package/dist/types/src/indexes/reverse-ref-index.d.ts +2 -2
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +12 -12
- package/src/index-engine.test.ts +118 -5
- package/src/index-engine.ts +83 -29
- package/src/index.ts +7 -1
- package/src/indexes/fts-index.test.ts +132 -0
- package/src/indexes/fts-index.ts +25 -8
- package/src/indexes/interface.ts +5 -0
- package/src/indexes/object-meta-index.test.ts +59 -10
- package/src/indexes/object-meta-index.ts +30 -21
- package/src/indexes/reverse-ref-index.test.ts +22 -15
- package/src/indexes/reverse-ref-index.ts +11 -11
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* () {
|
|
@@ -196,11 +209,13 @@ var ObjectMeta = Schema2.Struct({
|
|
|
196
209
|
recordId: Schema2.Number,
|
|
197
210
|
objectId: Schema2.String,
|
|
198
211
|
queueId: Schema2.String,
|
|
212
|
+
/** Queue subspace namespace (e.g. 'data', 'trace'). Empty string for non-queue objects. */
|
|
213
|
+
queueNamespace: Schema2.String,
|
|
199
214
|
spaceId: Schema2.String,
|
|
200
215
|
documentId: Schema2.String,
|
|
201
216
|
entityKind: Schema2.String,
|
|
202
217
|
/** The versioned DXN of the type of the object. */
|
|
203
|
-
|
|
218
|
+
typeDXN: Schema2.String,
|
|
204
219
|
deleted: Schema2.Boolean,
|
|
205
220
|
source: Schema2.NullOr(Schema2.String),
|
|
206
221
|
target: Schema2.NullOr(Schema2.String),
|
|
@@ -237,10 +252,11 @@ var ObjectMetaIndex = class {
|
|
|
237
252
|
recordId INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
238
253
|
objectId TEXT NOT NULL,
|
|
239
254
|
queueId TEXT NOT NULL DEFAULT '',
|
|
255
|
+
queueNamespace TEXT NOT NULL DEFAULT '',
|
|
240
256
|
spaceId TEXT NOT NULL,
|
|
241
257
|
documentId TEXT NOT NULL DEFAULT '',
|
|
242
258
|
entityKind TEXT NOT NULL,
|
|
243
|
-
|
|
259
|
+
typeDXN TEXT NOT NULL,
|
|
244
260
|
deleted INTEGER NOT NULL,
|
|
245
261
|
source TEXT,
|
|
246
262
|
target TEXT,
|
|
@@ -252,8 +268,9 @@ var ObjectMetaIndex = class {
|
|
|
252
268
|
yield* Effect3.catchAll(sql`ALTER TABLE objectMeta ADD COLUMN parent TEXT`, () => Effect3.void);
|
|
253
269
|
yield* Effect3.catchAll(sql`ALTER TABLE objectMeta ADD COLUMN createdAt INTEGER`, () => Effect3.void);
|
|
254
270
|
yield* Effect3.catchAll(sql`ALTER TABLE objectMeta ADD COLUMN updatedAt INTEGER`, () => Effect3.void);
|
|
271
|
+
yield* Effect3.catchAll(sql`ALTER TABLE objectMeta ADD COLUMN queueNamespace TEXT NOT NULL DEFAULT ''`, () => Effect3.void);
|
|
255
272
|
yield* sql`CREATE INDEX IF NOT EXISTS idx_object_index_objectId ON objectMeta(spaceId, objectId)`;
|
|
256
|
-
yield* sql`CREATE INDEX IF NOT EXISTS
|
|
273
|
+
yield* sql`CREATE INDEX IF NOT EXISTS idx_object_index_typeDXN ON objectMeta(spaceId, typeDXN)`;
|
|
257
274
|
yield* sql`CREATE INDEX IF NOT EXISTS idx_object_index_version ON objectMeta(version)`;
|
|
258
275
|
yield* sql`CREATE INDEX IF NOT EXISTS idx_object_index_parent ON objectMeta(spaceId, parent)`;
|
|
259
276
|
yield* sql`CREATE INDEX IF NOT EXISTS idx_object_index_updatedAt ON objectMeta(updatedAt)`;
|
|
@@ -261,8 +278,8 @@ var ObjectMetaIndex = class {
|
|
|
261
278
|
});
|
|
262
279
|
query = Effect3.fn("ObjectMetaIndex.query")((query) => Effect3.gen(function* () {
|
|
263
280
|
const sql = yield* SqlClient5.SqlClient;
|
|
264
|
-
const parsedType = DXN.tryParse(query.
|
|
265
|
-
const rows = parsedType && parsedType.version === void 0 ? yield* sql`SELECT * FROM objectMeta WHERE spaceId = ${query.spaceId} AND (
|
|
281
|
+
const parsedType = DXN.tryParse(query.typeDXN)?.asTypeDXN();
|
|
282
|
+
const rows = parsedType && parsedType.version === void 0 ? yield* sql`SELECT * FROM objectMeta WHERE spaceId = ${query.spaceId} AND (typeDXN = ${query.typeDXN} OR typeDXN LIKE ${_escapeLikePrefix(query.typeDXN)} ESCAPE '\\')` : yield* sql`SELECT * FROM objectMeta WHERE spaceId = ${query.spaceId} AND typeDXN = ${query.typeDXN}`;
|
|
266
283
|
return rows.map((row) => ({
|
|
267
284
|
...row,
|
|
268
285
|
deleted: !!row.deleted
|
|
@@ -298,12 +315,12 @@ var ObjectMetaIndex = class {
|
|
|
298
315
|
}
|
|
299
316
|
const sql = yield* SqlClient5.SqlClient;
|
|
300
317
|
const sourceCondition = buildSourceCondition(sql, spaceIds, includeAllQueues, queueIds);
|
|
301
|
-
const typeWhere = sql.or(typeDxns.map((
|
|
302
|
-
const parsedType = DXN.tryParse(
|
|
318
|
+
const typeWhere = sql.or(typeDxns.map((typeDXN) => {
|
|
319
|
+
const parsedType = DXN.tryParse(typeDXN)?.asTypeDXN();
|
|
303
320
|
return parsedType && parsedType.version === void 0 ? sql.or([
|
|
304
|
-
sql`
|
|
305
|
-
sql`
|
|
306
|
-
]) : sql`
|
|
321
|
+
sql`typeDXN = ${typeDXN}`,
|
|
322
|
+
sql`typeDXN LIKE ${_escapeLikePrefix(typeDXN)} ESCAPE '\\'`
|
|
323
|
+
]) : sql`typeDXN = ${typeDXN}`;
|
|
307
324
|
}));
|
|
308
325
|
const rows = inverted ? yield* sql`SELECT * FROM objectMeta WHERE ${sourceCondition} AND NOT ${typeWhere}` : yield* sql`SELECT * FROM objectMeta WHERE ${sourceCondition} AND ${typeWhere}`;
|
|
309
326
|
return rows.map((row) => ({
|
|
@@ -327,7 +344,7 @@ var ObjectMetaIndex = class {
|
|
|
327
344
|
update = Effect3.fn("ObjectMetaIndex.update")((objects) => Effect3.gen(function* () {
|
|
328
345
|
const sql = yield* SqlClient5.SqlClient;
|
|
329
346
|
yield* Effect3.forEach(objects, (object) => Effect3.gen(function* () {
|
|
330
|
-
const { spaceId, queueId, documentId, data } = object;
|
|
347
|
+
const { spaceId, queueId, queueNamespace, documentId, data } = object;
|
|
331
348
|
const castData = data;
|
|
332
349
|
const objectId = castData.id;
|
|
333
350
|
let existing;
|
|
@@ -342,7 +359,7 @@ var ObjectMetaIndex = class {
|
|
|
342
359
|
const [{ v }] = result;
|
|
343
360
|
const version = (v ?? 0) + 1;
|
|
344
361
|
const entityKind = castData[ATTR_RELATION_SOURCE] ? "relation" : "object";
|
|
345
|
-
const
|
|
362
|
+
const typeDXN = castData[ATTR_TYPE] ? String(castData[ATTR_TYPE]) : "type";
|
|
346
363
|
const deleted = castData[ATTR_DELETED] ? 1 : 0;
|
|
347
364
|
const source = entityKind === "relation" ? castData[ATTR_RELATION_SOURCE] ?? null : null;
|
|
348
365
|
const target = entityKind === "relation" ? castData[ATTR_RELATION_TARGET] ?? null : null;
|
|
@@ -352,8 +369,9 @@ var ObjectMetaIndex = class {
|
|
|
352
369
|
yield* sql`
|
|
353
370
|
UPDATE objectMeta SET
|
|
354
371
|
version = ${version},
|
|
372
|
+
queueNamespace = ${queueNamespace ?? ""},
|
|
355
373
|
entityKind = ${entityKind},
|
|
356
|
-
|
|
374
|
+
typeDXN = ${typeDXN},
|
|
357
375
|
deleted = ${deleted},
|
|
358
376
|
source = ${source},
|
|
359
377
|
target = ${target},
|
|
@@ -364,12 +382,12 @@ var ObjectMetaIndex = class {
|
|
|
364
382
|
} else {
|
|
365
383
|
yield* sql`
|
|
366
384
|
INSERT INTO objectMeta (
|
|
367
|
-
objectId, queueId, spaceId, documentId,
|
|
368
|
-
entityKind,
|
|
385
|
+
objectId, queueId, queueNamespace, spaceId, documentId,
|
|
386
|
+
entityKind, typeDXN, deleted, source, target, parent, version,
|
|
369
387
|
createdAt, updatedAt
|
|
370
388
|
) VALUES (
|
|
371
|
-
${objectId}, ${queueId ?? ""}, ${spaceId}, ${documentId ?? ""},
|
|
372
|
-
${entityKind}, ${
|
|
389
|
+
${objectId}, ${queueId ?? ""}, ${queueNamespace ?? ""}, ${spaceId}, ${documentId ?? ""},
|
|
390
|
+
${entityKind}, ${typeDXN}, ${deleted},
|
|
373
391
|
${source}, ${target}, ${parent}, ${version},
|
|
374
392
|
${sourceTimestamp}, ${sourceTimestamp}
|
|
375
393
|
)
|
|
@@ -527,7 +545,7 @@ var extractReferences = (data) => {
|
|
|
527
545
|
}
|
|
528
546
|
refs.push({
|
|
529
547
|
path,
|
|
530
|
-
|
|
548
|
+
targetDXN: dxn.toString()
|
|
531
549
|
});
|
|
532
550
|
} else if (typeof value === "object" && value !== null && !Array.isArray(value)) {
|
|
533
551
|
for (const [key, v] of Object.entries(value)) {
|
|
@@ -550,7 +568,7 @@ var extractReferences = (data) => {
|
|
|
550
568
|
};
|
|
551
569
|
var ReverseRef = Schema4.Struct({
|
|
552
570
|
recordId: Schema4.Number,
|
|
553
|
-
|
|
571
|
+
targetDXN: Schema4.String,
|
|
554
572
|
/**
|
|
555
573
|
* Escaped property path within an object.
|
|
556
574
|
*
|
|
@@ -567,18 +585,18 @@ var ReverseRefIndex = class {
|
|
|
567
585
|
const sql = yield* SqlClient7.SqlClient;
|
|
568
586
|
yield* sql`CREATE TABLE IF NOT EXISTS reverseRef (
|
|
569
587
|
recordId INTEGER NOT NULL,
|
|
570
|
-
|
|
588
|
+
targetDXN TEXT NOT NULL,
|
|
571
589
|
propPath TEXT NOT NULL,
|
|
572
|
-
PRIMARY KEY (recordId,
|
|
590
|
+
PRIMARY KEY (recordId, targetDXN, propPath)
|
|
573
591
|
)`;
|
|
574
|
-
yield* sql`CREATE INDEX IF NOT EXISTS idx_reverse_ref_target ON reverseRef(
|
|
592
|
+
yield* sql`CREATE INDEX IF NOT EXISTS idx_reverse_ref_target ON reverseRef(targetDXN)`;
|
|
575
593
|
});
|
|
576
594
|
/**
|
|
577
595
|
* Query all references pointing to a target DXN.
|
|
578
596
|
*/
|
|
579
|
-
query = Effect4.fn("ReverseRefIndex.query")(({
|
|
597
|
+
query = Effect4.fn("ReverseRefIndex.query")(({ targetDXN }) => Effect4.gen(function* () {
|
|
580
598
|
const sql = yield* SqlClient7.SqlClient;
|
|
581
|
-
const rows = yield* sql`SELECT * FROM reverseRef WHERE
|
|
599
|
+
const rows = yield* sql`SELECT * FROM reverseRef WHERE targetDXN = ${targetDXN}`;
|
|
582
600
|
return rows;
|
|
583
601
|
}));
|
|
584
602
|
update = Effect4.fn("ReverseRefIndex.update")((objects) => Effect4.gen(function* () {
|
|
@@ -590,7 +608,7 @@ var ReverseRefIndex = class {
|
|
|
590
608
|
}
|
|
591
609
|
yield* sql`DELETE FROM reverseRef WHERE recordId = ${recordId}`;
|
|
592
610
|
const refs = extractReferences(data);
|
|
593
|
-
yield* Effect4.forEach(refs, (ref) => sql`INSERT INTO reverseRef (recordId,
|
|
611
|
+
yield* Effect4.forEach(refs, (ref) => sql`INSERT INTO reverseRef (recordId, targetDXN, propPath) VALUES (${recordId}, ${ref.targetDXN}, ${EscapedPropPath.escape(ref.path)})`, {
|
|
594
612
|
discard: true
|
|
595
613
|
});
|
|
596
614
|
}), {
|
|
@@ -600,6 +618,33 @@ var ReverseRefIndex = class {
|
|
|
600
618
|
};
|
|
601
619
|
|
|
602
620
|
// src/index-engine.ts
|
|
621
|
+
var makeEmptyIndexingResult = () => ({
|
|
622
|
+
updated: 0,
|
|
623
|
+
done: true,
|
|
624
|
+
spaces: /* @__PURE__ */ new Set(),
|
|
625
|
+
queues: /* @__PURE__ */ new Set(),
|
|
626
|
+
documents: /* @__PURE__ */ new Set(),
|
|
627
|
+
types: /* @__PURE__ */ new Set(),
|
|
628
|
+
objects: /* @__PURE__ */ new Set()
|
|
629
|
+
});
|
|
630
|
+
var accumulateIndexingResult = (acc, objects) => {
|
|
631
|
+
for (const obj of objects) {
|
|
632
|
+
acc.spaces.add(obj.spaceId);
|
|
633
|
+
if (obj.queueId) {
|
|
634
|
+
acc.queues.add(obj.queueId);
|
|
635
|
+
}
|
|
636
|
+
if (obj.documentId) {
|
|
637
|
+
acc.documents.add(obj.documentId);
|
|
638
|
+
}
|
|
639
|
+
const t = obj.data[ATTR_TYPE2];
|
|
640
|
+
if (t) {
|
|
641
|
+
acc.types.add(String(t));
|
|
642
|
+
}
|
|
643
|
+
if (obj.data.id) {
|
|
644
|
+
acc.objects.add(obj.data.id);
|
|
645
|
+
}
|
|
646
|
+
}
|
|
647
|
+
};
|
|
603
648
|
var IndexEngine = class {
|
|
604
649
|
#tracker;
|
|
605
650
|
#objectMetaIndex;
|
|
@@ -666,26 +711,24 @@ var IndexEngine = class {
|
|
|
666
711
|
}
|
|
667
712
|
update(ctx, dataSource, opts) {
|
|
668
713
|
return Effect5.gen(this, function* () {
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
const { updated: updatedFtsIndex, done: doneFtsIndex } = yield* this.#update(ctx, this.#ftsIndex, dataSource, {
|
|
714
|
+
const result = makeEmptyIndexingResult();
|
|
715
|
+
const { updated: updatedFtsIndex, done: doneFtsIndex, objects: ftsObjects } = yield* this.#update(ctx, this.#ftsIndex, dataSource, {
|
|
672
716
|
indexName: "fts5",
|
|
673
717
|
spaceId: opts.spaceId,
|
|
674
718
|
limit: opts.limit
|
|
675
719
|
});
|
|
676
|
-
updated += updatedFtsIndex;
|
|
677
|
-
done = done && doneFtsIndex;
|
|
678
|
-
|
|
720
|
+
result.updated += updatedFtsIndex;
|
|
721
|
+
result.done = result.done && doneFtsIndex;
|
|
722
|
+
accumulateIndexingResult(result, ftsObjects);
|
|
723
|
+
const { updated: updatedReverseRefIndex, done: doneReverseRefIndex, objects: reverseRefObjects } = yield* this.#update(ctx, this.#reverseRefIndex, dataSource, {
|
|
679
724
|
indexName: "reverseRef",
|
|
680
725
|
spaceId: opts.spaceId,
|
|
681
726
|
limit: opts.limit
|
|
682
727
|
});
|
|
683
|
-
updated += updatedReverseRefIndex;
|
|
684
|
-
done = done && doneReverseRefIndex;
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
done
|
|
688
|
-
};
|
|
728
|
+
result.updated += updatedReverseRefIndex;
|
|
729
|
+
result.done = result.done && doneReverseRefIndex;
|
|
730
|
+
accumulateIndexingResult(result, reverseRefObjects);
|
|
731
|
+
return result;
|
|
689
732
|
}).pipe(Effect5.withSpan("IndexEngine.update"));
|
|
690
733
|
}
|
|
691
734
|
/**
|
|
@@ -713,7 +756,8 @@ var IndexEngine = class {
|
|
|
713
756
|
if (objects.length === 0) {
|
|
714
757
|
return {
|
|
715
758
|
updated: 0,
|
|
716
|
-
done: true
|
|
759
|
+
done: true,
|
|
760
|
+
objects: []
|
|
717
761
|
};
|
|
718
762
|
}
|
|
719
763
|
yield* this.#objectMetaIndex.update(objects);
|
|
@@ -728,7 +772,8 @@ var IndexEngine = class {
|
|
|
728
772
|
})));
|
|
729
773
|
return {
|
|
730
774
|
updated: objects.length,
|
|
731
|
-
done: false
|
|
775
|
+
done: false,
|
|
776
|
+
objects
|
|
732
777
|
};
|
|
733
778
|
}));
|
|
734
779
|
}).pipe(Effect5.withSpan("IndexEngine.#update"));
|