@dxos/index-core 0.8.4-main.abd8ff62ef → 0.8.4-main.bc2380dfbc
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 +30 -25
- 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 +2 -2
- 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 +13 -4
- package/src/index-engine.ts +2 -2
- package/src/indexes/fts-index.test.ts +22 -0
- 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
|
|
@@ -209,11 +209,13 @@ var ObjectMeta = Schema2.Struct({
|
|
|
209
209
|
recordId: Schema2.Number,
|
|
210
210
|
objectId: Schema2.String,
|
|
211
211
|
queueId: Schema2.String,
|
|
212
|
+
/** Queue subspace namespace (e.g. 'data', 'trace'). Empty string for non-queue objects. */
|
|
213
|
+
queueNamespace: Schema2.String,
|
|
212
214
|
spaceId: Schema2.String,
|
|
213
215
|
documentId: Schema2.String,
|
|
214
216
|
entityKind: Schema2.String,
|
|
215
217
|
/** The versioned DXN of the type of the object. */
|
|
216
|
-
|
|
218
|
+
typeDXN: Schema2.String,
|
|
217
219
|
deleted: Schema2.Boolean,
|
|
218
220
|
source: Schema2.NullOr(Schema2.String),
|
|
219
221
|
target: Schema2.NullOr(Schema2.String),
|
|
@@ -250,10 +252,11 @@ var ObjectMetaIndex = class {
|
|
|
250
252
|
recordId INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
251
253
|
objectId TEXT NOT NULL,
|
|
252
254
|
queueId TEXT NOT NULL DEFAULT '',
|
|
255
|
+
queueNamespace TEXT NOT NULL DEFAULT '',
|
|
253
256
|
spaceId TEXT NOT NULL,
|
|
254
257
|
documentId TEXT NOT NULL DEFAULT '',
|
|
255
258
|
entityKind TEXT NOT NULL,
|
|
256
|
-
|
|
259
|
+
typeDXN TEXT NOT NULL,
|
|
257
260
|
deleted INTEGER NOT NULL,
|
|
258
261
|
source TEXT,
|
|
259
262
|
target TEXT,
|
|
@@ -265,8 +268,9 @@ var ObjectMetaIndex = class {
|
|
|
265
268
|
yield* Effect3.catchAll(sql`ALTER TABLE objectMeta ADD COLUMN parent TEXT`, () => Effect3.void);
|
|
266
269
|
yield* Effect3.catchAll(sql`ALTER TABLE objectMeta ADD COLUMN createdAt INTEGER`, () => Effect3.void);
|
|
267
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);
|
|
268
272
|
yield* sql`CREATE INDEX IF NOT EXISTS idx_object_index_objectId ON objectMeta(spaceId, objectId)`;
|
|
269
|
-
yield* sql`CREATE INDEX IF NOT EXISTS
|
|
273
|
+
yield* sql`CREATE INDEX IF NOT EXISTS idx_object_index_typeDXN ON objectMeta(spaceId, typeDXN)`;
|
|
270
274
|
yield* sql`CREATE INDEX IF NOT EXISTS idx_object_index_version ON objectMeta(version)`;
|
|
271
275
|
yield* sql`CREATE INDEX IF NOT EXISTS idx_object_index_parent ON objectMeta(spaceId, parent)`;
|
|
272
276
|
yield* sql`CREATE INDEX IF NOT EXISTS idx_object_index_updatedAt ON objectMeta(updatedAt)`;
|
|
@@ -274,8 +278,8 @@ var ObjectMetaIndex = class {
|
|
|
274
278
|
});
|
|
275
279
|
query = Effect3.fn("ObjectMetaIndex.query")((query) => Effect3.gen(function* () {
|
|
276
280
|
const sql = yield* SqlClient5.SqlClient;
|
|
277
|
-
const parsedType = DXN.tryParse(query.
|
|
278
|
-
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}`;
|
|
279
283
|
return rows.map((row) => ({
|
|
280
284
|
...row,
|
|
281
285
|
deleted: !!row.deleted
|
|
@@ -311,12 +315,12 @@ var ObjectMetaIndex = class {
|
|
|
311
315
|
}
|
|
312
316
|
const sql = yield* SqlClient5.SqlClient;
|
|
313
317
|
const sourceCondition = buildSourceCondition(sql, spaceIds, includeAllQueues, queueIds);
|
|
314
|
-
const typeWhere = sql.or(typeDxns.map((
|
|
315
|
-
const parsedType = DXN.tryParse(
|
|
318
|
+
const typeWhere = sql.or(typeDxns.map((typeDXN) => {
|
|
319
|
+
const parsedType = DXN.tryParse(typeDXN)?.asTypeDXN();
|
|
316
320
|
return parsedType && parsedType.version === void 0 ? sql.or([
|
|
317
|
-
sql`
|
|
318
|
-
sql`
|
|
319
|
-
]) : sql`
|
|
321
|
+
sql`typeDXN = ${typeDXN}`,
|
|
322
|
+
sql`typeDXN LIKE ${_escapeLikePrefix(typeDXN)} ESCAPE '\\'`
|
|
323
|
+
]) : sql`typeDXN = ${typeDXN}`;
|
|
320
324
|
}));
|
|
321
325
|
const rows = inverted ? yield* sql`SELECT * FROM objectMeta WHERE ${sourceCondition} AND NOT ${typeWhere}` : yield* sql`SELECT * FROM objectMeta WHERE ${sourceCondition} AND ${typeWhere}`;
|
|
322
326
|
return rows.map((row) => ({
|
|
@@ -340,7 +344,7 @@ var ObjectMetaIndex = class {
|
|
|
340
344
|
update = Effect3.fn("ObjectMetaIndex.update")((objects) => Effect3.gen(function* () {
|
|
341
345
|
const sql = yield* SqlClient5.SqlClient;
|
|
342
346
|
yield* Effect3.forEach(objects, (object) => Effect3.gen(function* () {
|
|
343
|
-
const { spaceId, queueId, documentId, data } = object;
|
|
347
|
+
const { spaceId, queueId, queueNamespace, documentId, data } = object;
|
|
344
348
|
const castData = data;
|
|
345
349
|
const objectId = castData.id;
|
|
346
350
|
let existing;
|
|
@@ -355,7 +359,7 @@ var ObjectMetaIndex = class {
|
|
|
355
359
|
const [{ v }] = result;
|
|
356
360
|
const version = (v ?? 0) + 1;
|
|
357
361
|
const entityKind = castData[ATTR_RELATION_SOURCE] ? "relation" : "object";
|
|
358
|
-
const
|
|
362
|
+
const typeDXN = castData[ATTR_TYPE] ? String(castData[ATTR_TYPE]) : "type";
|
|
359
363
|
const deleted = castData[ATTR_DELETED] ? 1 : 0;
|
|
360
364
|
const source = entityKind === "relation" ? castData[ATTR_RELATION_SOURCE] ?? null : null;
|
|
361
365
|
const target = entityKind === "relation" ? castData[ATTR_RELATION_TARGET] ?? null : null;
|
|
@@ -365,8 +369,9 @@ var ObjectMetaIndex = class {
|
|
|
365
369
|
yield* sql`
|
|
366
370
|
UPDATE objectMeta SET
|
|
367
371
|
version = ${version},
|
|
372
|
+
queueNamespace = ${queueNamespace ?? ""},
|
|
368
373
|
entityKind = ${entityKind},
|
|
369
|
-
|
|
374
|
+
typeDXN = ${typeDXN},
|
|
370
375
|
deleted = ${deleted},
|
|
371
376
|
source = ${source},
|
|
372
377
|
target = ${target},
|
|
@@ -377,12 +382,12 @@ var ObjectMetaIndex = class {
|
|
|
377
382
|
} else {
|
|
378
383
|
yield* sql`
|
|
379
384
|
INSERT INTO objectMeta (
|
|
380
|
-
objectId, queueId, spaceId, documentId,
|
|
381
|
-
entityKind,
|
|
385
|
+
objectId, queueId, queueNamespace, spaceId, documentId,
|
|
386
|
+
entityKind, typeDXN, deleted, source, target, parent, version,
|
|
382
387
|
createdAt, updatedAt
|
|
383
388
|
) VALUES (
|
|
384
|
-
${objectId}, ${queueId ?? ""}, ${spaceId}, ${documentId ?? ""},
|
|
385
|
-
${entityKind}, ${
|
|
389
|
+
${objectId}, ${queueId ?? ""}, ${queueNamespace ?? ""}, ${spaceId}, ${documentId ?? ""},
|
|
390
|
+
${entityKind}, ${typeDXN}, ${deleted},
|
|
386
391
|
${source}, ${target}, ${parent}, ${version},
|
|
387
392
|
${sourceTimestamp}, ${sourceTimestamp}
|
|
388
393
|
)
|
|
@@ -540,7 +545,7 @@ var extractReferences = (data) => {
|
|
|
540
545
|
}
|
|
541
546
|
refs.push({
|
|
542
547
|
path,
|
|
543
|
-
|
|
548
|
+
targetDXN: dxn.toString()
|
|
544
549
|
});
|
|
545
550
|
} else if (typeof value === "object" && value !== null && !Array.isArray(value)) {
|
|
546
551
|
for (const [key, v] of Object.entries(value)) {
|
|
@@ -563,7 +568,7 @@ var extractReferences = (data) => {
|
|
|
563
568
|
};
|
|
564
569
|
var ReverseRef = Schema4.Struct({
|
|
565
570
|
recordId: Schema4.Number,
|
|
566
|
-
|
|
571
|
+
targetDXN: Schema4.String,
|
|
567
572
|
/**
|
|
568
573
|
* Escaped property path within an object.
|
|
569
574
|
*
|
|
@@ -580,18 +585,18 @@ var ReverseRefIndex = class {
|
|
|
580
585
|
const sql = yield* SqlClient7.SqlClient;
|
|
581
586
|
yield* sql`CREATE TABLE IF NOT EXISTS reverseRef (
|
|
582
587
|
recordId INTEGER NOT NULL,
|
|
583
|
-
|
|
588
|
+
targetDXN TEXT NOT NULL,
|
|
584
589
|
propPath TEXT NOT NULL,
|
|
585
|
-
PRIMARY KEY (recordId,
|
|
590
|
+
PRIMARY KEY (recordId, targetDXN, propPath)
|
|
586
591
|
)`;
|
|
587
|
-
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)`;
|
|
588
593
|
});
|
|
589
594
|
/**
|
|
590
595
|
* Query all references pointing to a target DXN.
|
|
591
596
|
*/
|
|
592
|
-
query = Effect4.fn("ReverseRefIndex.query")(({
|
|
597
|
+
query = Effect4.fn("ReverseRefIndex.query")(({ targetDXN }) => Effect4.gen(function* () {
|
|
593
598
|
const sql = yield* SqlClient7.SqlClient;
|
|
594
|
-
const rows = yield* sql`SELECT * FROM reverseRef WHERE
|
|
599
|
+
const rows = yield* sql`SELECT * FROM reverseRef WHERE targetDXN = ${targetDXN}`;
|
|
595
600
|
return rows;
|
|
596
601
|
}));
|
|
597
602
|
update = Effect4.fn("ReverseRefIndex.update")((objects) => Effect4.gen(function* () {
|
|
@@ -603,7 +608,7 @@ var ReverseRefIndex = class {
|
|
|
603
608
|
}
|
|
604
609
|
yield* sql`DELETE FROM reverseRef WHERE recordId = ${recordId}`;
|
|
605
610
|
const refs = extractReferences(data);
|
|
606
|
-
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)})`, {
|
|
607
612
|
discard: true
|
|
608
613
|
});
|
|
609
614
|
}), {
|