@dxos/echo-pipeline 0.8.4-main.dedc0f3 → 0.8.4-main.e8ec1fe
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 → chunk-FR6GJ4S4.mjs} +341 -427
- package/dist/lib/browser/{chunk-I4JBIZSN.mjs.map → chunk-FR6GJ4S4.mjs.map} +2 -2
- package/dist/lib/browser/{chunk-MBMJB3V7.mjs → chunk-WJJXJTNS.mjs} +62 -4
- package/dist/lib/browser/chunk-WJJXJTNS.mjs.map +7 -0
- package/dist/lib/browser/filter/index.mjs +1 -1
- package/dist/lib/browser/index.mjs +797 -802
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +65 -106
- package/dist/lib/browser/testing/index.mjs.map +3 -3
- package/dist/lib/node-esm/{chunk-YOL7JY5W.mjs → chunk-JQCCVDLT.mjs} +341 -427
- package/dist/lib/node-esm/{chunk-YOL7JY5W.mjs.map → chunk-JQCCVDLT.mjs.map} +2 -2
- package/dist/lib/node-esm/{chunk-XJZTCD4G.mjs → chunk-LEQ77KAT.mjs} +62 -4
- package/dist/lib/node-esm/chunk-LEQ77KAT.mjs.map +7 -0
- package/dist/lib/node-esm/filter/index.mjs +1 -1
- package/dist/lib/node-esm/index.mjs +797 -802
- package/dist/lib/node-esm/index.mjs.map +3 -3
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/testing/index.mjs +65 -106
- package/dist/lib/node-esm/testing/index.mjs.map +3 -3
- package/dist/types/src/automerge/automerge-host.d.ts.map +1 -1
- package/dist/types/src/automerge/collection-synchronizer.d.ts +2 -1
- package/dist/types/src/automerge/collection-synchronizer.d.ts.map +1 -1
- package/dist/types/src/db-host/query-service.d.ts.map +1 -1
- package/dist/types/src/edge/echo-edge-replicator.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/query/errors.d.ts +14 -13
- package/dist/types/src/query/errors.d.ts.map +1 -1
- package/dist/types/src/query/query-executor.d.ts +9 -0
- package/dist/types/src/query/query-executor.d.ts.map +1 -1
- package/dist/types/src/query/query-planner.d.ts.map +1 -1
- package/dist/types/src/testing/test-data.d.ts.map +1 -1
- package/dist/types/src/testing/test-schema.d.ts +1 -1
- package/dist/types/src/testing/test-schema.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +37 -39
- package/src/automerge/automerge-host.ts +34 -21
- package/src/automerge/collection-synchronizer.test.ts +4 -3
- package/src/automerge/collection-synchronizer.ts +14 -9
- package/src/db-host/echo-host.ts +1 -1
- package/src/db-host/query-service.ts +2 -1
- package/src/edge/echo-edge-replicator.ts +30 -9
- package/src/filter/filter-match.test.ts +32 -12
- package/src/filter/filter-match.ts +88 -11
- package/src/query/errors.ts +2 -0
- package/src/query/query-executor.ts +121 -36
- package/src/query/query-planner.test.ts +90 -5
- package/src/query/query-planner.ts +48 -12
- package/src/testing/test-data.ts +1 -1
- package/src/testing/test-schema.ts +1 -1
- package/dist/lib/browser/chunk-MBMJB3V7.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-XJZTCD4G.mjs.map +0 -7
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
5
|
+
import { ATTR_META, EXPANDO_TYPENAME, type ObjectJSON } from '@dxos/echo/internal';
|
|
6
|
+
import { ObjectStructure, type QueryAST, decodeReference, isEncodedReference } from '@dxos/echo-protocol';
|
|
7
7
|
import { DXN, type ObjectId, type SpaceId } from '@dxos/keys';
|
|
8
8
|
|
|
9
9
|
export type MatchedObject = {
|
|
@@ -19,11 +19,11 @@ export type MatchedObject = {
|
|
|
19
19
|
export const filterMatchObject = (filter: QueryAST.Filter, obj: MatchedObject): boolean => {
|
|
20
20
|
switch (filter.type) {
|
|
21
21
|
case 'object': {
|
|
22
|
-
// Check typename if specified
|
|
22
|
+
// Check typename if specified.
|
|
23
23
|
if (filter.typename !== null) {
|
|
24
24
|
// TODO(dmaretskyi): `system` is missing in some cases.
|
|
25
25
|
if (!obj.doc.system?.type?.['/']) {
|
|
26
|
-
// Objects with no type are considered to be expando objects
|
|
26
|
+
// Objects with no type are considered to be expando objects.
|
|
27
27
|
const expectedDXN = DXN.parse(filter.typename).asTypeDXN();
|
|
28
28
|
if (expectedDXN?.type !== EXPANDO_TYPENAME) {
|
|
29
29
|
return false;
|
|
@@ -31,19 +31,18 @@ export const filterMatchObject = (filter: QueryAST.Filter, obj: MatchedObject):
|
|
|
31
31
|
} else {
|
|
32
32
|
const actualDXN = DXN.parse(obj.doc.system.type['/']);
|
|
33
33
|
const expectedDXN = DXN.parse(filter.typename);
|
|
34
|
-
|
|
35
34
|
if (!compareTypename(expectedDXN, actualDXN)) {
|
|
36
35
|
return false;
|
|
37
36
|
}
|
|
38
37
|
}
|
|
39
38
|
}
|
|
40
39
|
|
|
41
|
-
// Check IDs if specified
|
|
40
|
+
// Check IDs if specified.
|
|
42
41
|
if (filter.id && filter.id.length > 0 && !filter.id.includes(obj.id)) {
|
|
43
42
|
return false;
|
|
44
43
|
}
|
|
45
44
|
|
|
46
|
-
// Check properties
|
|
45
|
+
// Check properties.
|
|
47
46
|
if (filter.props) {
|
|
48
47
|
for (const [key, valueFilter] of Object.entries(filter.props)) {
|
|
49
48
|
const value = obj.doc.data[key];
|
|
@@ -53,7 +52,7 @@ export const filterMatchObject = (filter: QueryAST.Filter, obj: MatchedObject):
|
|
|
53
52
|
}
|
|
54
53
|
}
|
|
55
54
|
|
|
56
|
-
// Check foreign keys if specified
|
|
55
|
+
// Check foreign keys if specified.
|
|
57
56
|
if (filter.foreignKeys && filter.foreignKeys.length > 0) {
|
|
58
57
|
const hasMatchingKey = filter.foreignKeys.some((filterKey) =>
|
|
59
58
|
obj.doc.meta.keys.some((objKey) => objKey.source === filterKey.source && objKey.id === filterKey.id),
|
|
@@ -66,8 +65,13 @@ export const filterMatchObject = (filter: QueryAST.Filter, obj: MatchedObject):
|
|
|
66
65
|
return true;
|
|
67
66
|
}
|
|
68
67
|
|
|
68
|
+
case 'tag': {
|
|
69
|
+
const tags = ObjectStructure.getTags(obj.doc);
|
|
70
|
+
return tags.some((tag) => tag === filter.tag);
|
|
71
|
+
}
|
|
72
|
+
|
|
69
73
|
case 'text-search': {
|
|
70
|
-
// TODO: Implement text search
|
|
74
|
+
// TODO(???): Implement text search.
|
|
71
75
|
return false;
|
|
72
76
|
}
|
|
73
77
|
|
|
@@ -88,6 +92,7 @@ export const filterMatchObject = (filter: QueryAST.Filter, obj: MatchedObject):
|
|
|
88
92
|
}
|
|
89
93
|
};
|
|
90
94
|
|
|
95
|
+
// TODO(burdon): Reconcile with filterMatchObject.
|
|
91
96
|
export const filterMatchObjectJSON = (filter: QueryAST.Filter, obj: ObjectJSON): boolean => {
|
|
92
97
|
switch (filter.type) {
|
|
93
98
|
case 'object': {
|
|
@@ -103,7 +108,6 @@ export const filterMatchObjectJSON = (filter: QueryAST.Filter, obj: ObjectJSON):
|
|
|
103
108
|
} else {
|
|
104
109
|
const actualDXN = DXN.parse(obj['@type']);
|
|
105
110
|
const expectedDXN = DXN.parse(filter.typename);
|
|
106
|
-
|
|
107
111
|
if (!compareTypename(expectedDXN, actualDXN)) {
|
|
108
112
|
return false;
|
|
109
113
|
}
|
|
@@ -142,6 +146,11 @@ export const filterMatchObjectJSON = (filter: QueryAST.Filter, obj: ObjectJSON):
|
|
|
142
146
|
return true;
|
|
143
147
|
}
|
|
144
148
|
|
|
149
|
+
case 'tag': {
|
|
150
|
+
const tags = obj[ATTR_META]?.tags ?? [];
|
|
151
|
+
return tags.some((tag) => tag === filter.tag);
|
|
152
|
+
}
|
|
153
|
+
|
|
145
154
|
case 'text-search': {
|
|
146
155
|
// TODO: Implement text search
|
|
147
156
|
return false;
|
|
@@ -164,6 +173,42 @@ export const filterMatchObjectJSON = (filter: QueryAST.Filter, obj: ObjectJSON):
|
|
|
164
173
|
}
|
|
165
174
|
};
|
|
166
175
|
|
|
176
|
+
/**
|
|
177
|
+
* Performs structural matching between a filter object and a target object.
|
|
178
|
+
* This handles nested object comparison for array matching scenarios.
|
|
179
|
+
*/
|
|
180
|
+
// TODO(wittjosiah): Add ast support for non-strict matching.
|
|
181
|
+
const structuralMatch = (filterObj: any, targetObj: any, strict = true): boolean => {
|
|
182
|
+
if (typeof filterObj !== 'object' || filterObj === null) {
|
|
183
|
+
return filterObj === targetObj;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
if (typeof targetObj !== 'object' || targetObj === null) {
|
|
187
|
+
return false;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
// Prohibit extra keys in targetObj.
|
|
191
|
+
const filterKeys = Object.keys(filterObj);
|
|
192
|
+
const targetKeys = Object.keys(targetObj);
|
|
193
|
+
if (strict && filterKeys.length !== targetKeys.length) {
|
|
194
|
+
return false;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
return filterKeys.every((key) => {
|
|
198
|
+
if (!(key in targetObj)) {
|
|
199
|
+
return false;
|
|
200
|
+
}
|
|
201
|
+
const filterValue = filterObj[key];
|
|
202
|
+
const targetValue = targetObj[key];
|
|
203
|
+
|
|
204
|
+
if (typeof filterValue === 'object' && filterValue !== null) {
|
|
205
|
+
return structuralMatch(filterValue, targetValue);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
return filterValue === targetValue;
|
|
209
|
+
});
|
|
210
|
+
};
|
|
211
|
+
|
|
167
212
|
export const filterMatchValue = (filter: QueryAST.Filter, value: unknown): boolean => {
|
|
168
213
|
switch (filter.type) {
|
|
169
214
|
case 'compare': {
|
|
@@ -187,12 +232,44 @@ export const filterMatchValue = (filter: QueryAST.Filter, value: unknown): boole
|
|
|
187
232
|
return (value as any) < compareValue;
|
|
188
233
|
case 'lte':
|
|
189
234
|
return (value as any) <= compareValue;
|
|
235
|
+
default:
|
|
236
|
+
return false;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
case 'object': {
|
|
240
|
+
// Handle nested object filters for property matching
|
|
241
|
+
if (typeof value !== 'object' || value === null) {
|
|
242
|
+
return false;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
// Check properties
|
|
246
|
+
if (filter.props) {
|
|
247
|
+
for (const [key, valueFilter] of Object.entries(filter.props)) {
|
|
248
|
+
const nestedValue = (value as any)[key];
|
|
249
|
+
if (!filterMatchValue(valueFilter, nestedValue)) {
|
|
250
|
+
return false;
|
|
251
|
+
}
|
|
252
|
+
}
|
|
190
253
|
}
|
|
191
|
-
|
|
254
|
+
|
|
255
|
+
return true;
|
|
192
256
|
}
|
|
193
257
|
case 'in': {
|
|
194
258
|
return filter.values.includes(value);
|
|
195
259
|
}
|
|
260
|
+
case 'contains': {
|
|
261
|
+
if (!Array.isArray(value)) {
|
|
262
|
+
return false;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
return value.some((element) => {
|
|
266
|
+
if (typeof filter.value === 'object' && filter.value !== null && !Array.isArray(filter.value)) {
|
|
267
|
+
return structuralMatch(filter.value, element);
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
return element === filter.value;
|
|
271
|
+
});
|
|
272
|
+
}
|
|
196
273
|
case 'range': {
|
|
197
274
|
return (value as any) >= filter.from && (value as any) <= filter.to;
|
|
198
275
|
}
|
package/src/query/errors.ts
CHANGED
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
//
|
|
4
4
|
|
|
5
5
|
import type { AutomergeUrl, DocumentId } from '@automerge/automerge-repo';
|
|
6
|
-
import
|
|
6
|
+
import * as Match from 'effect/Match';
|
|
7
|
+
import * as Predicate from 'effect/Predicate';
|
|
7
8
|
|
|
8
9
|
import { Context, ContextDisposedError, LifecycleState, Resource } from '@dxos/context';
|
|
9
10
|
import { DatabaseDirectory, ObjectStructure, type QueryAST, isEncodedReference } from '@dxos/echo-protocol';
|
|
@@ -63,6 +64,9 @@ export type ExecutionTrace = {
|
|
|
63
64
|
documentsLoaded: number;
|
|
64
65
|
indexHits: number;
|
|
65
66
|
|
|
67
|
+
beginTs: number;
|
|
68
|
+
endTs: number;
|
|
69
|
+
|
|
66
70
|
executionTime: number;
|
|
67
71
|
indexQueryTime: number;
|
|
68
72
|
documentLoadTime: number;
|
|
@@ -77,11 +81,42 @@ export const ExecutionTrace = Object.freeze({
|
|
|
77
81
|
objectCount: 0,
|
|
78
82
|
documentsLoaded: 0,
|
|
79
83
|
indexHits: 0,
|
|
84
|
+
beginTs: 0,
|
|
85
|
+
endTs: 0,
|
|
80
86
|
indexQueryTime: 0,
|
|
81
87
|
documentLoadTime: 0,
|
|
82
88
|
executionTime: 0,
|
|
83
89
|
children: [],
|
|
84
90
|
}),
|
|
91
|
+
markEnd: (trace: ExecutionTrace) => {
|
|
92
|
+
trace.endTs = performance.now();
|
|
93
|
+
trace.executionTime = trace.endTs - trace.beginTs;
|
|
94
|
+
},
|
|
95
|
+
putOnPerformanceTimeline: (trace: ExecutionTrace) => {
|
|
96
|
+
performance.measure(trace.name, {
|
|
97
|
+
start: trace.beginTs,
|
|
98
|
+
end: trace.endTs,
|
|
99
|
+
detail: {
|
|
100
|
+
devtools: {
|
|
101
|
+
dataType: 'track-entry',
|
|
102
|
+
track: 'Query Execution',
|
|
103
|
+
trackGroup: 'ECHO', // Group related tracks together
|
|
104
|
+
color: 'tertiary-dark',
|
|
105
|
+
properties: [
|
|
106
|
+
['objectCount', trace.objectCount],
|
|
107
|
+
['documentsLoaded', trace.documentsLoaded],
|
|
108
|
+
['index hits', trace.indexHits],
|
|
109
|
+
['indexQueryTime', trace.indexQueryTime],
|
|
110
|
+
['documentLoadTime', trace.documentLoadTime],
|
|
111
|
+
],
|
|
112
|
+
tooltipText: trace.details,
|
|
113
|
+
},
|
|
114
|
+
},
|
|
115
|
+
});
|
|
116
|
+
for (const child of trace.children) {
|
|
117
|
+
ExecutionTrace.putOnPerformanceTimeline(child);
|
|
118
|
+
}
|
|
119
|
+
},
|
|
85
120
|
format: (trace: ExecutionTrace): string => {
|
|
86
121
|
const go = (trace: ExecutionTrace, indent: number): string => {
|
|
87
122
|
return [
|
|
@@ -191,6 +226,9 @@ export class QueryExecutor extends Resource {
|
|
|
191
226
|
workingSet[index].documentId !== item.documentId,
|
|
192
227
|
);
|
|
193
228
|
|
|
229
|
+
// Disabled because concurrent queries don't print hierarchies correctly.
|
|
230
|
+
// ExecutionTrace.putOnPerformanceTimeline(trace);
|
|
231
|
+
|
|
194
232
|
if (TRACE_QUERY_EXECUTION) {
|
|
195
233
|
console.log(ExecutionTrace.format(trace));
|
|
196
234
|
}
|
|
@@ -213,7 +251,7 @@ export class QueryExecutor extends Resource {
|
|
|
213
251
|
trace.children.push(result.trace);
|
|
214
252
|
}
|
|
215
253
|
trace.objectCount = workingSet.length;
|
|
216
|
-
|
|
254
|
+
ExecutionTrace.markEnd(trace);
|
|
217
255
|
return { workingSet, trace };
|
|
218
256
|
}
|
|
219
257
|
|
|
@@ -253,7 +291,8 @@ export class QueryExecutor extends Resource {
|
|
|
253
291
|
default:
|
|
254
292
|
throw new Error(`Unknown step type: ${(step as any)._tag}`);
|
|
255
293
|
}
|
|
256
|
-
trace.
|
|
294
|
+
trace.beginTs = begin;
|
|
295
|
+
ExecutionTrace.markEnd(trace);
|
|
257
296
|
|
|
258
297
|
return { workingSet: newWorkingSet, trace };
|
|
259
298
|
}
|
|
@@ -265,6 +304,7 @@ export class QueryExecutor extends Resource {
|
|
|
265
304
|
...ExecutionTrace.makeEmpty(),
|
|
266
305
|
name: 'Select',
|
|
267
306
|
details: JSON.stringify(step.selector),
|
|
307
|
+
beginTs: performance.now(),
|
|
268
308
|
};
|
|
269
309
|
|
|
270
310
|
switch (step.selector._tag) {
|
|
@@ -291,6 +331,7 @@ export class QueryExecutor extends Resource {
|
|
|
291
331
|
|
|
292
332
|
break;
|
|
293
333
|
}
|
|
334
|
+
|
|
294
335
|
case 'IdSelector': {
|
|
295
336
|
const beginLoad = performance.now();
|
|
296
337
|
const items = await Promise.all(
|
|
@@ -304,6 +345,7 @@ export class QueryExecutor extends Resource {
|
|
|
304
345
|
trace.objectCount = workingSet.length;
|
|
305
346
|
break;
|
|
306
347
|
}
|
|
348
|
+
|
|
307
349
|
case 'TypeSelector': {
|
|
308
350
|
const beginIndexQuery = performance.now();
|
|
309
351
|
const indexHits = await this._indexer.execQuery({
|
|
@@ -327,6 +369,7 @@ export class QueryExecutor extends Resource {
|
|
|
327
369
|
|
|
328
370
|
break;
|
|
329
371
|
}
|
|
372
|
+
|
|
330
373
|
case 'TextSelector': {
|
|
331
374
|
const beginIndexQuery = performance.now();
|
|
332
375
|
const indexHits = await this._indexer.execQuery({
|
|
@@ -357,6 +400,7 @@ export class QueryExecutor extends Resource {
|
|
|
357
400
|
trace.objectCount = workingSet.length;
|
|
358
401
|
break;
|
|
359
402
|
}
|
|
403
|
+
|
|
360
404
|
default:
|
|
361
405
|
throw new Error(`Unknown selector type: ${(step.selector as any)._tag}`);
|
|
362
406
|
}
|
|
@@ -372,6 +416,7 @@ export class QueryExecutor extends Resource {
|
|
|
372
416
|
doc: item.doc,
|
|
373
417
|
}),
|
|
374
418
|
);
|
|
419
|
+
|
|
375
420
|
return {
|
|
376
421
|
workingSet: result,
|
|
377
422
|
trace: {
|
|
@@ -592,17 +637,7 @@ export class QueryExecutor extends Resource {
|
|
|
592
637
|
}
|
|
593
638
|
|
|
594
639
|
private async _execOrderStep(step: QueryPlan.OrderStep, workingSet: QueryItem[]): Promise<StepExecutionResult> {
|
|
595
|
-
const
|
|
596
|
-
step.order.reduce((comparison, order) => {
|
|
597
|
-
// If we already have a definitive result, return it
|
|
598
|
-
if (comparison !== 0) {
|
|
599
|
-
return comparison;
|
|
600
|
-
}
|
|
601
|
-
|
|
602
|
-
return this._compareByOrder(a, b, order);
|
|
603
|
-
}, 0);
|
|
604
|
-
|
|
605
|
-
const sortedWorkingSet = [...workingSet].sort(compareItems);
|
|
640
|
+
const sortedWorkingSet = [...workingSet].sort((a, b) => this._compareMultiOrder(a, b, step.order));
|
|
606
641
|
|
|
607
642
|
return {
|
|
608
643
|
workingSet: sortedWorkingSet,
|
|
@@ -615,34 +650,73 @@ export class QueryExecutor extends Resource {
|
|
|
615
650
|
};
|
|
616
651
|
}
|
|
617
652
|
|
|
653
|
+
private _compareMultiOrder(a: QueryItem, b: QueryItem, orders: readonly QueryAST.Order[]): number {
|
|
654
|
+
// Short circuit for common cases.
|
|
655
|
+
if (orders.length === 0) {
|
|
656
|
+
return 0;
|
|
657
|
+
} else if (orders.length === 1) {
|
|
658
|
+
return this._compareByOrder(a, b, orders[0]);
|
|
659
|
+
}
|
|
660
|
+
|
|
661
|
+
for (const order of orders) {
|
|
662
|
+
const comparison = this._compareByOrder(a, b, order);
|
|
663
|
+
if (comparison !== 0) {
|
|
664
|
+
return comparison;
|
|
665
|
+
}
|
|
666
|
+
}
|
|
667
|
+
return 0;
|
|
668
|
+
}
|
|
669
|
+
|
|
618
670
|
private _compareByOrder(a: QueryItem, b: QueryItem, order: QueryAST.Order): number {
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
const comparison = this._compareByProperty(a, b, property);
|
|
624
|
-
return direction === 'desc' ? -comparison : comparison;
|
|
625
|
-
}
|
|
626
|
-
|
|
627
|
-
|
|
671
|
+
switch (order.kind) {
|
|
672
|
+
case 'natural':
|
|
673
|
+
return a.objectId.localeCompare(b.objectId);
|
|
674
|
+
case 'property': {
|
|
675
|
+
const comparison = this._compareByProperty(a, b, order.property);
|
|
676
|
+
return order.direction === 'desc' ? -comparison : comparison;
|
|
677
|
+
}
|
|
678
|
+
default:
|
|
679
|
+
// Should never reach here with proper TypeScript types
|
|
680
|
+
return 0;
|
|
681
|
+
}
|
|
628
682
|
}
|
|
629
683
|
|
|
630
684
|
private _compareByProperty(a: QueryItem, b: QueryItem, property: string): number {
|
|
631
685
|
const aValue = a.doc.data[property];
|
|
632
686
|
const bValue = b.doc.data[property];
|
|
633
687
|
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
688
|
+
// Both null or undefined
|
|
689
|
+
if (aValue == null && bValue == null) {
|
|
690
|
+
return 0;
|
|
691
|
+
}
|
|
692
|
+
|
|
693
|
+
// Only a is null/undefined
|
|
694
|
+
if (aValue == null) {
|
|
695
|
+
return 1;
|
|
696
|
+
}
|
|
697
|
+
|
|
698
|
+
// Only b is null/undefined
|
|
699
|
+
if (bValue == null) {
|
|
700
|
+
return -1;
|
|
701
|
+
}
|
|
702
|
+
|
|
703
|
+
// Both strings
|
|
704
|
+
if (typeof aValue === 'string' && typeof bValue === 'string') {
|
|
705
|
+
return aValue.localeCompare(bValue);
|
|
706
|
+
}
|
|
707
|
+
|
|
708
|
+
// Both numbers
|
|
709
|
+
if (typeof aValue === 'number' && typeof bValue === 'number') {
|
|
710
|
+
return aValue - bValue;
|
|
711
|
+
}
|
|
712
|
+
|
|
713
|
+
// Both booleans
|
|
714
|
+
if (typeof aValue === 'boolean' && typeof bValue === 'boolean') {
|
|
715
|
+
return aValue === bValue ? 0 : aValue ? 1 : -1;
|
|
716
|
+
}
|
|
717
|
+
|
|
718
|
+
// Fallback: convert to strings and compare
|
|
719
|
+
return String(aValue).localeCompare(String(bValue));
|
|
646
720
|
}
|
|
647
721
|
|
|
648
722
|
private async _loadDocumentsAfterIndexQuery(indexHits: FindResult[]): Promise<(QueryItem | null)[]> {
|
|
@@ -653,6 +727,11 @@ export class QueryExecutor extends Resource {
|
|
|
653
727
|
);
|
|
654
728
|
}
|
|
655
729
|
|
|
730
|
+
/**
|
|
731
|
+
* Space key hex -> SpaceId.
|
|
732
|
+
*/
|
|
733
|
+
private readonly _spaceIdCache = new Map<string, SpaceId>();
|
|
734
|
+
|
|
656
735
|
private async _loadFromIndexHit(hit: FindResult): Promise<QueryItem | null> {
|
|
657
736
|
const { objectId, documentId, spaceKey: spaceKeyInIndex } = objectPointerCodec.decode(hit.id);
|
|
658
737
|
|
|
@@ -667,6 +746,12 @@ export class QueryExecutor extends Resource {
|
|
|
667
746
|
return null;
|
|
668
747
|
}
|
|
669
748
|
|
|
749
|
+
let spaceId = this._spaceIdCache.get(spaceKey);
|
|
750
|
+
if (!spaceId) {
|
|
751
|
+
spaceId = await createIdFromSpaceKey(PublicKey.from(spaceKey));
|
|
752
|
+
this._spaceIdCache.set(spaceKey, spaceId);
|
|
753
|
+
}
|
|
754
|
+
|
|
670
755
|
const object = DatabaseDirectory.getInlineObject(doc, objectId);
|
|
671
756
|
if (!object) {
|
|
672
757
|
return null;
|
|
@@ -675,7 +760,7 @@ export class QueryExecutor extends Resource {
|
|
|
675
760
|
return {
|
|
676
761
|
objectId,
|
|
677
762
|
documentId: documentId as DocumentId,
|
|
678
|
-
spaceId
|
|
763
|
+
spaceId,
|
|
679
764
|
doc: object,
|
|
680
765
|
};
|
|
681
766
|
}
|
|
@@ -39,6 +39,15 @@ describe('QueryPlanner', () => {
|
|
|
39
39
|
"_tag": "FilterDeletedStep",
|
|
40
40
|
"mode": "only-non-deleted",
|
|
41
41
|
},
|
|
42
|
+
{
|
|
43
|
+
"_tag": "FilterStep",
|
|
44
|
+
"filter": {
|
|
45
|
+
"id": undefined,
|
|
46
|
+
"props": {},
|
|
47
|
+
"type": "object",
|
|
48
|
+
"typename": "dxn:type:dxos.org/type/Person:0.1.0",
|
|
49
|
+
},
|
|
50
|
+
},
|
|
42
51
|
{
|
|
43
52
|
"_tag": "OrderStep",
|
|
44
53
|
"order": [
|
|
@@ -76,6 +85,15 @@ describe('QueryPlanner', () => {
|
|
|
76
85
|
"_tag": "FilterDeletedStep",
|
|
77
86
|
"mode": "only-non-deleted",
|
|
78
87
|
},
|
|
88
|
+
{
|
|
89
|
+
"_tag": "FilterStep",
|
|
90
|
+
"filter": {
|
|
91
|
+
"id": undefined,
|
|
92
|
+
"props": {},
|
|
93
|
+
"type": "object",
|
|
94
|
+
"typename": "dxn:type:dxos.org/type/Person:0.1.0",
|
|
95
|
+
},
|
|
96
|
+
},
|
|
79
97
|
{
|
|
80
98
|
"_tag": "OrderStep",
|
|
81
99
|
"order": [
|
|
@@ -127,7 +145,7 @@ describe('QueryPlanner', () => {
|
|
|
127
145
|
},
|
|
128
146
|
},
|
|
129
147
|
"type": "object",
|
|
130
|
-
"typename":
|
|
148
|
+
"typename": "dxn:type:dxos.org/type/Person:0.1.0",
|
|
131
149
|
},
|
|
132
150
|
},
|
|
133
151
|
{
|
|
@@ -334,7 +352,7 @@ describe('QueryPlanner', () => {
|
|
|
334
352
|
},
|
|
335
353
|
},
|
|
336
354
|
"type": "object",
|
|
337
|
-
"typename":
|
|
355
|
+
"typename": "dxn:type:dxos.org/type/Organization:0.1.0",
|
|
338
356
|
},
|
|
339
357
|
},
|
|
340
358
|
{
|
|
@@ -433,6 +451,15 @@ describe('QueryPlanner', () => {
|
|
|
433
451
|
"_tag": "FilterDeletedStep",
|
|
434
452
|
"mode": "only-non-deleted",
|
|
435
453
|
},
|
|
454
|
+
{
|
|
455
|
+
"_tag": "FilterStep",
|
|
456
|
+
"filter": {
|
|
457
|
+
"id": undefined,
|
|
458
|
+
"props": {},
|
|
459
|
+
"type": "object",
|
|
460
|
+
"typename": "dxn:type:dxos.org/type/Person:0.1.0",
|
|
461
|
+
},
|
|
462
|
+
},
|
|
436
463
|
],
|
|
437
464
|
},
|
|
438
465
|
{
|
|
@@ -454,6 +481,15 @@ describe('QueryPlanner', () => {
|
|
|
454
481
|
"_tag": "FilterDeletedStep",
|
|
455
482
|
"mode": "only-non-deleted",
|
|
456
483
|
},
|
|
484
|
+
{
|
|
485
|
+
"_tag": "FilterStep",
|
|
486
|
+
"filter": {
|
|
487
|
+
"id": undefined,
|
|
488
|
+
"props": {},
|
|
489
|
+
"type": "object",
|
|
490
|
+
"typename": "dxn:type:dxos.org/type/Organization:0.1.0",
|
|
491
|
+
},
|
|
492
|
+
},
|
|
457
493
|
],
|
|
458
494
|
},
|
|
459
495
|
],
|
|
@@ -508,7 +544,7 @@ describe('QueryPlanner', () => {
|
|
|
508
544
|
"id": undefined,
|
|
509
545
|
"props": {},
|
|
510
546
|
"type": "object",
|
|
511
|
-
"typename":
|
|
547
|
+
"typename": "dxn:type:dxos.org/type/Person:0.1.0",
|
|
512
548
|
},
|
|
513
549
|
},
|
|
514
550
|
{
|
|
@@ -569,7 +605,7 @@ describe('QueryPlanner', () => {
|
|
|
569
605
|
"id": undefined,
|
|
570
606
|
"props": {},
|
|
571
607
|
"type": "object",
|
|
572
|
-
"typename":
|
|
608
|
+
"typename": "dxn:type:dxos.org/type/Person:0.1.0",
|
|
573
609
|
},
|
|
574
610
|
},
|
|
575
611
|
],
|
|
@@ -624,7 +660,7 @@ describe('QueryPlanner', () => {
|
|
|
624
660
|
},
|
|
625
661
|
},
|
|
626
662
|
"type": "object",
|
|
627
|
-
"typename":
|
|
663
|
+
"typename": "dxn:type:dxos.org/type/Task:0.1.0",
|
|
628
664
|
},
|
|
629
665
|
},
|
|
630
666
|
{
|
|
@@ -756,6 +792,26 @@ describe('QueryPlanner', () => {
|
|
|
756
792
|
"_tag": "FilterDeletedStep",
|
|
757
793
|
"mode": "only-non-deleted",
|
|
758
794
|
},
|
|
795
|
+
{
|
|
796
|
+
"_tag": "FilterStep",
|
|
797
|
+
"filter": {
|
|
798
|
+
"filters": [
|
|
799
|
+
{
|
|
800
|
+
"id": undefined,
|
|
801
|
+
"props": {},
|
|
802
|
+
"type": "object",
|
|
803
|
+
"typename": "dxn:type:dxos.org/type/Organization:0.1.0",
|
|
804
|
+
},
|
|
805
|
+
{
|
|
806
|
+
"id": undefined,
|
|
807
|
+
"props": {},
|
|
808
|
+
"type": "object",
|
|
809
|
+
"typename": "dxn:type:dxos.org/type/Person:0.1.0",
|
|
810
|
+
},
|
|
811
|
+
],
|
|
812
|
+
"type": "or",
|
|
813
|
+
},
|
|
814
|
+
},
|
|
759
815
|
{
|
|
760
816
|
"_tag": "OrderStep",
|
|
761
817
|
"order": [
|
|
@@ -804,6 +860,26 @@ describe('QueryPlanner', () => {
|
|
|
804
860
|
"_tag": "FilterDeletedStep",
|
|
805
861
|
"mode": "only-non-deleted",
|
|
806
862
|
},
|
|
863
|
+
{
|
|
864
|
+
"_tag": "FilterStep",
|
|
865
|
+
"filter": {
|
|
866
|
+
"filters": [
|
|
867
|
+
{
|
|
868
|
+
"id": undefined,
|
|
869
|
+
"props": {},
|
|
870
|
+
"type": "object",
|
|
871
|
+
"typename": "dxn:type:dxos.org/type/Organization:0.1.0",
|
|
872
|
+
},
|
|
873
|
+
{
|
|
874
|
+
"id": undefined,
|
|
875
|
+
"props": {},
|
|
876
|
+
"type": "object",
|
|
877
|
+
"typename": "dxn:type:dxos.org/type/Person:0.1.0",
|
|
878
|
+
},
|
|
879
|
+
],
|
|
880
|
+
"type": "or",
|
|
881
|
+
},
|
|
882
|
+
},
|
|
807
883
|
{
|
|
808
884
|
"_tag": "OrderStep",
|
|
809
885
|
"order": [
|
|
@@ -841,6 +917,15 @@ describe('QueryPlanner', () => {
|
|
|
841
917
|
"_tag": "FilterDeletedStep",
|
|
842
918
|
"mode": "only-deleted",
|
|
843
919
|
},
|
|
920
|
+
{
|
|
921
|
+
"_tag": "FilterStep",
|
|
922
|
+
"filter": {
|
|
923
|
+
"id": undefined,
|
|
924
|
+
"props": {},
|
|
925
|
+
"type": "object",
|
|
926
|
+
"typename": "dxn:type:dxos.org/type/Task:0.1.0",
|
|
927
|
+
},
|
|
928
|
+
},
|
|
844
929
|
{
|
|
845
930
|
"_tag": "OrderStep",
|
|
846
931
|
"order": [
|