mindoodb 0.0.63 → 0.0.64

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.
Files changed (63) hide show
  1. package/README.md +14 -1
  2. package/dist/browser/index.mjs +4 -0
  3. package/dist/core/expressions/builder.d.ts +25 -0
  4. package/dist/core/expressions/builder.d.ts.map +1 -1
  5. package/dist/core/expressions/builder.js +33 -13
  6. package/dist/core/expressions/builder.js.map +1 -1
  7. package/dist/core/expressions/evaluateExpression.d.ts +55 -2
  8. package/dist/core/expressions/evaluateExpression.d.ts.map +1 -1
  9. package/dist/core/expressions/evaluateExpression.js +95 -3
  10. package/dist/core/expressions/evaluateExpression.js.map +1 -1
  11. package/dist/core/expressions/formulaSource.d.ts.map +1 -1
  12. package/dist/core/expressions/formulaSource.js +21 -2
  13. package/dist/core/expressions/formulaSource.js.map +1 -1
  14. package/dist/core/expressions/index.d.ts +1 -1
  15. package/dist/core/expressions/index.d.ts.map +1 -1
  16. package/dist/core/expressions/index.js +3 -1
  17. package/dist/core/expressions/index.js.map +1 -1
  18. package/dist/core/expressions/metadata.d.ts +1 -1
  19. package/dist/core/expressions/metadata.d.ts.map +1 -1
  20. package/dist/core/expressions/metadata.js +5 -0
  21. package/dist/core/expressions/metadata.js.map +1 -1
  22. package/dist/core/expressions/types.d.ts +17 -2
  23. package/dist/core/expressions/types.d.ts.map +1 -1
  24. package/dist/core/index.d.ts +1 -1
  25. package/dist/core/index.d.ts.map +1 -1
  26. package/dist/core/index.js +4 -2
  27. package/dist/core/index.js.map +1 -1
  28. package/dist/core/indexing/createViewDataProvider.d.ts.map +1 -1
  29. package/dist/core/indexing/createViewDataProvider.js +1 -0
  30. package/dist/core/indexing/createViewDataProvider.js.map +1 -1
  31. package/dist/core/indexing/summary/SummaryVirtualViewDataProvider.d.ts.map +1 -1
  32. package/dist/core/indexing/summary/SummaryVirtualViewDataProvider.js +1 -0
  33. package/dist/core/indexing/summary/SummaryVirtualViewDataProvider.js.map +1 -1
  34. package/dist/core/indexing/virtualviews/MindooDBVirtualViewDataProvider.d.ts.map +1 -1
  35. package/dist/core/indexing/virtualviews/MindooDBVirtualViewDataProvider.js +1 -0
  36. package/dist/core/indexing/virtualviews/MindooDBVirtualViewDataProvider.js.map +1 -1
  37. package/dist/core/query/executeQuery.d.ts +1 -1
  38. package/dist/core/query/executeQuery.d.ts.map +1 -1
  39. package/dist/core/query/executeQuery.js +106 -71
  40. package/dist/core/query/executeQuery.js.map +1 -1
  41. package/dist/core/query/executeQueryInclude.d.ts +99 -0
  42. package/dist/core/query/executeQueryInclude.d.ts.map +1 -0
  43. package/dist/core/query/executeQueryInclude.js +447 -0
  44. package/dist/core/query/executeQueryInclude.js.map +1 -0
  45. package/dist/core/query/index.d.ts +2 -1
  46. package/dist/core/query/index.d.ts.map +1 -1
  47. package/dist/core/query/index.js +5 -1
  48. package/dist/core/query/index.js.map +1 -1
  49. package/dist/core/query/queryInternals.d.ts +45 -0
  50. package/dist/core/query/queryInternals.d.ts.map +1 -0
  51. package/dist/core/query/queryInternals.js +87 -0
  52. package/dist/core/query/queryInternals.js.map +1 -0
  53. package/dist/core/query/queryLive.d.ts.map +1 -1
  54. package/dist/core/query/queryLive.js +67 -8
  55. package/dist/core/query/queryLive.js.map +1 -1
  56. package/dist/core/query/queryView.d.ts.map +1 -1
  57. package/dist/core/query/queryView.js +19 -0
  58. package/dist/core/query/queryView.js.map +1 -1
  59. package/dist/core/query/types.d.ts +122 -7
  60. package/dist/core/query/types.d.ts.map +1 -1
  61. package/dist/core/query/types.js +13 -1
  62. package/dist/core/query/types.js.map +1 -1
  63. package/package.json +1 -1
@@ -0,0 +1,447 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.extractJoinKey = extractJoinKey;
4
+ exports.validateQueryIncludes = validateQueryIncludes;
5
+ exports.hydrateQueryIncludes = hydrateQueryIncludes;
6
+ const expressions_1 = require("../expressions");
7
+ const extractSummaryFields_1 = require("../indexing/summary/extractSummaryFields");
8
+ const types_1 = require("./types");
9
+ const queryInternals_1 = require("./queryInternals");
10
+ /** Splits nested `and` nodes into a flat list of conjuncts. */
11
+ function flattenConjuncts(expression) {
12
+ if (expression.kind === "operation" && expression.op === "and") {
13
+ return expression.args.flatMap((arg) => flattenConjuncts(arg));
14
+ }
15
+ return [expression];
16
+ }
17
+ function combineConjuncts(conjuncts) {
18
+ if (conjuncts.length === 0) {
19
+ return null;
20
+ }
21
+ if (conjuncts.length === 1) {
22
+ return conjuncts[0];
23
+ }
24
+ return { kind: "operation", op: "and", args: conjuncts };
25
+ }
26
+ function referencesParent(expression) {
27
+ return (0, expressions_1.analyzeExpressionRequirements)(expression).needsParentContext;
28
+ }
29
+ /**
30
+ * Reduces an include filter to the one join equality the planner can
31
+ * execute, plus the parent-free rest.
32
+ *
33
+ * Accepted: exactly one equality between a child term (`field(X)` or
34
+ * `docId()`) and a parent term (`parent(Y)` or `parentDocId()`), in
35
+ * either operand order, optionally ANDed with conditions that do not
36
+ * mention the parent.
37
+ * Rejected: everything else that references the parent — a range
38
+ * comparison against a parent value, an `or` spanning parent terms, a
39
+ * second parent equality. Those would each require evaluating the filter
40
+ * once per (parent, child) pair, which turns a linear scan into a nested
41
+ * loop; a slot over 200 paged parents and 10k children would be ~2M
42
+ * evaluations. Rejecting them keeps the cost model of `query()` intact
43
+ * and the failure obvious instead of silently slow.
44
+ */
45
+ function extractJoinKey(filter) {
46
+ const conjuncts = flattenConjuncts(filter);
47
+ const parentConjuncts = conjuncts.filter((conjunct) => referencesParent(conjunct));
48
+ const parentFree = conjuncts.filter((conjunct) => !referencesParent(conjunct));
49
+ if (parentConjuncts.length === 0) {
50
+ return {
51
+ ok: false,
52
+ reason: "it does not reference the parent document. Add the join condition " +
53
+ 'v.eq(v.field("<child field>"), v.parentDocId()) (or use localKey)',
54
+ };
55
+ }
56
+ if (parentConjuncts.length > 1) {
57
+ return {
58
+ ok: false,
59
+ reason: `it references the parent document in ${parentConjuncts.length} separate conditions. ` +
60
+ "Exactly one parent equality can be used as the join key",
61
+ };
62
+ }
63
+ const join = parentConjuncts[0];
64
+ if (join.kind !== "operation" || join.op !== "eq" || join.args.length !== 2) {
65
+ return {
66
+ ok: false,
67
+ reason: `the condition referencing the parent is not an equality: ${(0, expressions_1.formatMindooDBFormulaExpression)(join)}. ` +
68
+ 'Only v.eq(v.field("<child field>"), v.parentDocId()) and friends can be used as the join key',
69
+ };
70
+ }
71
+ const [left, right] = join.args;
72
+ const plan = joinSides(left, right) ??
73
+ joinSides(right, left) ??
74
+ null;
75
+ if (!plan) {
76
+ return {
77
+ ok: false,
78
+ reason: `the join equality compares ${(0, expressions_1.formatMindooDBFormulaExpression)(join)}. ` +
79
+ "One side must read the related document (v.field(...) or v.docId()), " +
80
+ "the other the parent (v.parent(...) or v.parentDocId())",
81
+ };
82
+ }
83
+ return {
84
+ ok: true,
85
+ plan: { ...plan, residualFilter: combineConjuncts(parentFree) },
86
+ };
87
+ }
88
+ /** Reads an expression as the child side of a join equality. */
89
+ function childJoinSide(expression) {
90
+ if (expression.kind === "field") {
91
+ return { kind: "field", path: expression.path };
92
+ }
93
+ if (expression.kind === "operation" && expression.op === "docId") {
94
+ return { kind: "docId" };
95
+ }
96
+ return null;
97
+ }
98
+ /** Reads an expression as the parent side of a join equality. */
99
+ function parentJoinSide(expression) {
100
+ if (expression.kind === "parent") {
101
+ return { kind: "field", path: expression.path };
102
+ }
103
+ if (expression.kind === "operation" && expression.op === "parentDocId") {
104
+ return { kind: "docId" };
105
+ }
106
+ return null;
107
+ }
108
+ /** Pairs the two operands of an equality in the given order, if they fit. */
109
+ function joinSides(childCandidate, parentCandidate) {
110
+ const child = childJoinSide(childCandidate);
111
+ const parent = parentJoinSide(parentCandidate);
112
+ return child && parent ? { child, parent } : null;
113
+ }
114
+ /** Builds the join plan of a slot from `localKey` and/or `filter`. */
115
+ function planInclude(slot, include) {
116
+ if (include.localKey !== undefined) {
117
+ // `localKey` already IS the join key, so an additional filter must not
118
+ // introduce a second one — it can only narrow the children further.
119
+ if (include.filter && referencesParent(include.filter)) {
120
+ throw new types_1.MindooQueryError(`Include "${slot}" combines localKey with a filter that also references the parent document. ` +
121
+ "Use either localKey or a parent join condition, not both.");
122
+ }
123
+ return {
124
+ child: { kind: "docId" },
125
+ parent: { kind: "field", path: include.localKey },
126
+ residualFilter: include.filter ?? null,
127
+ };
128
+ }
129
+ const extraction = extractJoinKey(include.filter);
130
+ if (!extraction.ok) {
131
+ throw new types_1.MindooQueryError(`Include "${slot}" cannot be joined because ${extraction.reason}.`);
132
+ }
133
+ return extraction.plan;
134
+ }
135
+ /**
136
+ * Structural validation of the include tree, run before any scanning so a
137
+ * malformed query fails immediately rather than after the root scan.
138
+ */
139
+ function validateQueryIncludes(includes, depth = 1, slotPath = "") {
140
+ for (const [slot, include] of Object.entries(includes)) {
141
+ const label = slotPath ? `${slotPath}.${slot}` : slot;
142
+ if (slot.trim() === "") {
143
+ throw new types_1.MindooQueryError("Include slot names must not be empty.");
144
+ }
145
+ if (depth > types_1.MAX_INCLUDE_DEPTH) {
146
+ throw new types_1.MindooQueryError(`Include "${label}" nests ${depth} levels deep, more than the maximum of ${types_1.MAX_INCLUDE_DEPTH}.`);
147
+ }
148
+ if (include.cardinality !== "one" && include.cardinality !== "many") {
149
+ throw new types_1.MindooQueryError(`Include "${label}" needs an explicit cardinality of "one" or "many" ` +
150
+ `(got ${JSON.stringify(include.cardinality)}).`);
151
+ }
152
+ if (include.localKey === undefined && include.filter === undefined) {
153
+ throw new types_1.MindooQueryError(`Include "${label}" needs a localKey or a filter to relate documents to the parent row.`);
154
+ }
155
+ if (include.localKey !== undefined && include.localKey.trim() === "") {
156
+ throw new types_1.MindooQueryError(`Include "${label}" has an empty localKey.`);
157
+ }
158
+ if (include.cardinality === "one") {
159
+ if (include.sortBy !== undefined) {
160
+ throw new types_1.MindooQueryError(`Include "${label}" has cardinality "one", which resolves to a single row — sortBy is meaningless there.`);
161
+ }
162
+ if (include.limit !== undefined) {
163
+ throw new types_1.MindooQueryError(`Include "${label}" has cardinality "one", which resolves to a single row — limit is meaningless there.`);
164
+ }
165
+ }
166
+ if (include.limit !== undefined && (!Number.isFinite(include.limit) || include.limit < 0)) {
167
+ throw new types_1.MindooQueryError(`Include "${label}" has an invalid limit (${include.limit}).`);
168
+ }
169
+ if (include.db && !include.db.getSummaryStore) {
170
+ throw new types_1.MindooQueryError(`Include "${label}" points at a MindooDB instance without a summary buffer, which cannot answer queries.`);
171
+ }
172
+ for (const sortKey of include.sortBy ?? []) {
173
+ if (sortKey.special === "textScore") {
174
+ throw new types_1.MindooQueryError(`Include "${label}" sorts by textScore, but includes have no text clause to score against.`);
175
+ }
176
+ if (sortKey.expression && referencesParent(sortKey.expression)) {
177
+ throw new types_1.MindooQueryError(`Include "${label}" sorts by an expression referencing the parent document. ` +
178
+ "Sorting applies to the related documents only.");
179
+ }
180
+ }
181
+ if (include.filter) {
182
+ validateIncludeFilter(label, include.filter);
183
+ }
184
+ if (include.include) {
185
+ validateQueryIncludes(include.include, depth + 1, label);
186
+ }
187
+ }
188
+ }
189
+ function validateIncludeFilter(label, filter) {
190
+ const unknown = (0, expressions_1.findUnknownExpressionNode)(filter);
191
+ if (unknown !== null) {
192
+ throw new types_1.MindooQueryError(`Include "${label}" has a filter containing ${unknown}, which the expression language does not define. ` +
193
+ "Build expressions with createViewLanguage() (or pass the filter as formula source text).");
194
+ }
195
+ const requirements = (0, expressions_1.analyzeExpressionRequirements)(filter);
196
+ if (requirements.needsViewContext) {
197
+ throw new types_1.MindooQueryError(`Include "${label}" has a filter using view-tree operations ` +
198
+ `(${requirements.viewContextOperations.join(", ")}); these only evaluate inside a materialized view.`);
199
+ }
200
+ if (requirements.needsDecryption) {
201
+ throw new types_1.MindooQueryError(`Include "${label}" has a filter referencing encrypted fields (decrypt), ` +
202
+ "which the summary buffer does not store.");
203
+ }
204
+ }
205
+ /** Reads the join value of a parent row for the planned parent side. */
206
+ function readParentJoinValue(parent, side) {
207
+ return side.kind === "docId" ? parent.docId : (0, extractSummaryFields_1.getSummaryFieldValue)(parent.doc, side.path);
208
+ }
209
+ /** Reads the join value of a candidate child for the planned child side. */
210
+ function readChildJoinValue(docId, evaluationDoc, side) {
211
+ return side.kind === "docId" ? docId : (0, extractSummaryFields_1.getSummaryFieldValue)(evaluationDoc, side.path);
212
+ }
213
+ /**
214
+ * A join value may be a list (`memberIds: ["u_1", "u_2"]`), in which case
215
+ * every element joins independently — that is what makes `localKey` work
216
+ * for "this document references several others".
217
+ */
218
+ function joinValuesOf(value) {
219
+ if (value === undefined || value === null) {
220
+ return [];
221
+ }
222
+ if (Array.isArray(value)) {
223
+ return value.filter((item) => item !== undefined && item !== null);
224
+ }
225
+ return [value];
226
+ }
227
+ function assertNotAborted(options, slot) {
228
+ if (options?.signal?.aborted) {
229
+ throw new types_1.MindooQueryError(`Query aborted while resolving include "${slot}".`);
230
+ }
231
+ }
232
+ function resolveIncludeSummary(db, label) {
233
+ if (!db.getSummaryStore) {
234
+ throw new types_1.MindooQueryError(`Include "${label}" points at a MindooDB instance without a summary buffer, which cannot answer queries.`);
235
+ }
236
+ return db.getSummaryStore();
237
+ }
238
+ /** Verifies that both sides of the join are answerable from their summaries. */
239
+ function checkIncludeCoverage(label, plan, include, childSummary, parentSummary) {
240
+ const childPaths = new Set();
241
+ if (plan.child.kind === "field") {
242
+ childPaths.add(plan.child.path);
243
+ }
244
+ if (plan.residualFilter) {
245
+ for (const path of (0, expressions_1.getReferencedFields)(plan.residualFilter)) {
246
+ childPaths.add(path);
247
+ }
248
+ }
249
+ for (const sortKey of include.sortBy ?? []) {
250
+ if (sortKey.expression) {
251
+ for (const path of (0, expressions_1.getReferencedFields)(sortKey.expression)) {
252
+ childPaths.add(path);
253
+ }
254
+ }
255
+ else if (sortKey.field) {
256
+ childPaths.add(sortKey.field);
257
+ }
258
+ }
259
+ for (const path of childPaths) {
260
+ if (!childSummary.isFieldCovered(path)) {
261
+ throw new types_1.MindooQueryError(`Include "${label}" references field "${path}", which is not covered by the summary configuration ` +
262
+ "of the database it looks up (check include/exclude in SummaryConfig).");
263
+ }
264
+ }
265
+ // Parent-side paths are checked against the PARENT summary: that is the
266
+ // buffer the join value is actually read from.
267
+ const parentPaths = new Set();
268
+ if (plan.parent.kind === "field") {
269
+ parentPaths.add(plan.parent.path);
270
+ }
271
+ if (include.filter) {
272
+ for (const path of (0, expressions_1.getReferencedParentFields)(include.filter)) {
273
+ parentPaths.add(path);
274
+ }
275
+ }
276
+ for (const path of parentPaths) {
277
+ if (!parentSummary.isFieldCovered(path)) {
278
+ throw new types_1.MindooQueryError(`Include "${label}" reads parent field "${path}", which is not covered by the summary configuration ` +
279
+ "of the parent database (check include/exclude in SummaryConfig).");
280
+ }
281
+ }
282
+ }
283
+ function includeSortKeys(include) {
284
+ return include.sortBy ?? [];
285
+ }
286
+ /**
287
+ * Hydrates one level of include slots onto already-paged parent rows.
288
+ *
289
+ * Per slot: bring the target summary up to date, scan it once, keep the
290
+ * children whose join value hits one of the parents' keys, group them,
291
+ * and attach. Nested slots recurse on the attached rows, which are by
292
+ * then themselves a set of paged parents.
293
+ *
294
+ * @returns the merged coverage of every summary this level touched.
295
+ */
296
+ async function hydrateQueryIncludes(params) {
297
+ const { parentDb, parentSummary, includes, parents, depth, options, slotPath = "" } = params;
298
+ let coverage = "full";
299
+ for (const [slot, include] of Object.entries(includes)) {
300
+ const label = slotPath ? `${slotPath}.${slot}` : slot;
301
+ const plan = planInclude(label, include);
302
+ const childDb = include.db ?? parentDb;
303
+ const childSummary = resolveIncludeSummary(childDb, label);
304
+ checkIncludeCoverage(label, plan, include, childSummary, parentSummary);
305
+ // Empty parent page: no keys to look up, but the slot must still exist
306
+ // on every (zero) row — and nested levels have nothing to do either.
307
+ if (parents.length === 0) {
308
+ continue;
309
+ }
310
+ await childSummary.update(options);
311
+ assertNotAborted(options, label);
312
+ coverage = (0, queryInternals_1.mergeCoverage)(coverage, childSummary.getCoverage());
313
+ // Unique join keys of the current page. A Map keyed by the raw value
314
+ // matches the strict equality semantics of v.eq (1 and "1" differ).
315
+ const parentsByKey = new Map();
316
+ for (const parent of parents) {
317
+ for (const key of joinValuesOf(readParentJoinValue(parent, plan.parent))) {
318
+ const bucket = parentsByKey.get(key);
319
+ if (bucket) {
320
+ bucket.push(parent);
321
+ }
322
+ else {
323
+ parentsByKey.set(key, [parent]);
324
+ }
325
+ }
326
+ }
327
+ const childrenByKey = new Map();
328
+ if (parentsByKey.size > 0) {
329
+ const origin = (0, queryInternals_1.queryOrigin)(childDb);
330
+ const sortKeys = includeSortKeys(include);
331
+ for (const entry of childSummary.getAllEntries()) {
332
+ const evaluationDoc = (0, extractSummaryFields_1.buildSummaryEvaluationDoc)(entry.fields, entry.lastModified);
333
+ const matchedKeys = joinValuesOf(readChildJoinValue(entry.docId, evaluationDoc, plan.child)).filter((key) => parentsByKey.has(key));
334
+ if (matchedKeys.length === 0) {
335
+ continue;
336
+ }
337
+ const context = {
338
+ doc: evaluationDoc,
339
+ values: {},
340
+ origin,
341
+ docId: entry.docId,
342
+ lastModifiedAt: new Date(entry.lastModified).toISOString(),
343
+ decryptionKeyId: entry.decryptionKeyId,
344
+ variables: {},
345
+ };
346
+ if (plan.residualFilter && !(0, expressions_1.expressionToBoolean)((0, expressions_1.evaluateExpression)(plan.residualFilter, context))) {
347
+ continue;
348
+ }
349
+ const candidate = {
350
+ docId: entry.docId,
351
+ fields: (0, queryInternals_1.projectFields)(evaluationDoc, include.fields),
352
+ lastModified: entry.lastModified,
353
+ sortValues: (0, queryInternals_1.computeSortValues)(sortKeys, context),
354
+ evaluationDoc,
355
+ keys: matchedKeys,
356
+ };
357
+ for (const key of matchedKeys) {
358
+ const bucket = childrenByKey.get(key);
359
+ if (bucket) {
360
+ bucket.push(candidate);
361
+ }
362
+ else {
363
+ childrenByKey.set(key, [candidate]);
364
+ }
365
+ }
366
+ }
367
+ }
368
+ const childParents = attachIncludeSlot(slot, label, include, plan, parents, childrenByKey);
369
+ if (include.include && childParents.length > 0) {
370
+ const nestedCoverage = await hydrateQueryIncludes({
371
+ parentDb: childDb,
372
+ parentSummary: childSummary,
373
+ includes: include.include,
374
+ parents: childParents,
375
+ depth: depth + 1,
376
+ options,
377
+ slotPath: label,
378
+ });
379
+ coverage = (0, queryInternals_1.mergeCoverage)(coverage, nestedCoverage);
380
+ }
381
+ }
382
+ return coverage;
383
+ }
384
+ /**
385
+ * Writes the grouped children into `row.includes[slot]` and returns the
386
+ * attached rows as parent bindings for the next nesting level.
387
+ *
388
+ * Every attachment gets its OWN row object even when two parents matched
389
+ * the same document: nested hydration writes into these rows, and sharing
390
+ * one object would make a nested slot of one parent visible on another.
391
+ */
392
+ function attachIncludeSlot(slot, label, include, plan, parents, childrenByKey) {
393
+ var _a;
394
+ const sortKeys = includeSortKeys(include);
395
+ const limit = include.limit ?? types_1.DEFAULT_INCLUDE_LIMIT;
396
+ const nextParents = [];
397
+ for (const parent of parents) {
398
+ const seen = new Set();
399
+ const matches = [];
400
+ for (const key of joinValuesOf(readParentJoinValue(parent, plan.parent))) {
401
+ for (const candidate of childrenByKey.get(key) ?? []) {
402
+ // A parent whose join value is an array can reach the same child
403
+ // through two entries; it is still one related document.
404
+ if (seen.has(candidate.docId)) {
405
+ continue;
406
+ }
407
+ seen.add(candidate.docId);
408
+ matches.push(candidate);
409
+ }
410
+ }
411
+ const slots = ((_a = parent.row).includes ?? (_a.includes = {}));
412
+ if (include.cardinality === "one") {
413
+ if (matches.length > 1) {
414
+ const sample = matches.slice(0, 3).map((match) => match.docId).join(", ");
415
+ throw new types_1.MindooQueryError(`Include "${label}" has cardinality "one", but document "${parent.docId}" matched ` +
416
+ `${matches.length} related documents (${sample}${matches.length > 3 ? ", …" : ""}). ` +
417
+ 'Use cardinality "many" if several matches are expected.');
418
+ }
419
+ if (matches.length === 0) {
420
+ slots[slot] = null;
421
+ continue;
422
+ }
423
+ const row = toIncludedRow(matches[0]);
424
+ slots[slot] = row;
425
+ nextParents.push({ row, docId: matches[0].docId, doc: matches[0].evaluationDoc });
426
+ continue;
427
+ }
428
+ matches.sort((left, right) => (0, queryInternals_1.compareCandidates)(left, right, sortKeys));
429
+ const rows = [];
430
+ for (const candidate of matches.slice(0, limit)) {
431
+ const row = toIncludedRow(candidate);
432
+ rows.push(row);
433
+ nextParents.push({ row, docId: candidate.docId, doc: candidate.evaluationDoc });
434
+ }
435
+ slots[slot] = rows;
436
+ }
437
+ return nextParents;
438
+ }
439
+ /** Strips the scan-internal bookkeeping off a candidate. */
440
+ function toIncludedRow(candidate) {
441
+ return {
442
+ docId: candidate.docId,
443
+ fields: candidate.fields,
444
+ lastModified: candidate.lastModified,
445
+ };
446
+ }
447
+ //# sourceMappingURL=executeQueryInclude.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"executeQueryInclude.js","sourceRoot":"","sources":["../../../src/core/query/executeQueryInclude.ts"],"names":[],"mappings":";;AA0HA,wCAmDC;AA+DD,sDAyEC;AAiJD,oDA2GC;AA/iBD,gDASwB;AAExB,mFAA2G;AAC3G,mCASiB;AACjB,qDAO0B;AAqD1B,+DAA+D;AAC/D,SAAS,gBAAgB,CAAC,UAAiC;IACzD,IAAI,UAAU,CAAC,IAAI,KAAK,WAAW,IAAI,UAAU,CAAC,EAAE,KAAK,KAAK,EAAE,CAAC;QAC/D,OAAO,UAAU,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,gBAAgB,CAAC,GAAG,CAAC,CAAC,CAAC;IACjE,CAAC;IACD,OAAO,CAAC,UAAU,CAAC,CAAC;AACtB,CAAC;AAED,SAAS,gBAAgB,CAAC,SAAkC;IAC1D,IAAI,SAAS,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC3B,OAAO,IAAI,CAAC;IACd,CAAC;IACD,IAAI,SAAS,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC3B,OAAO,SAAS,CAAC,CAAC,CAAiC,CAAC;IACtD,CAAC;IACD,OAAO,EAAE,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AAC,CAAC;QACxE,MAAM,IAAI,GAAqB,EAAE,CAAC;QAClC,KAAK,MAAM,SAAS,IAAI,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,EAAE,CAAC;YAChD,MAAM,GAAG,GAAG,aAAa,CAAC,SAAS,CAAC,CAAC;YACrC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;YACf,WAAW,CAAC,IAAI,CAAC,EAAE,GAAG,EAAE,KAAK,EAAE,SAAS,CAAC,KAAK,EAAE,GAAG,EAAE,SAAS,CAAC,aAAa,EAAE,CAAC,CAAC;QAClF,CAAC;QACD,KAAK,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;IACrB,CAAC;IAED,OAAO,WAAW,CAAC;AACrB,CAAC;AAED,4DAA4D;AAC5D,SAAS,aAAa,CAAC,SAAyB;IAC9C,OAAO;QACL,KAAK,EAAE,SAAS,CAAC,KAAK;QACtB,MAAM,EAAE,SAAS,CAAC,MAAM;QACxB,YAAY,EAAE,SAAS,CAAC,YAAY;KACrC,CAAC;AACJ,CAAC"}
@@ -1,5 +1,6 @@
1
- export { MindooQueryError, type MindooQuery, type MindooQuerySortKey, type MindooQueryTextClause, type MindooQueryErrorCode, type MindooQueryOptions, type MindooQueryRow, type MindooQueryCoverage, type MindooQueryResult, } from "./types";
1
+ export { MindooQueryError, DEFAULT_INCLUDE_LIMIT, MAX_INCLUDE_DEPTH, type MindooQuery, type MindooQueryInclude, type MindooQueryIncludeCardinality, type MindooQueryIncludeSlots, type MindooQuerySortKey, type MindooQueryTextClause, type MindooQueryErrorCode, type MindooQueryOptions, type MindooQueryRow, type MindooQueryCoverage, type MindooQueryResult, } from "./types";
2
2
  export { executeQuery } from "./executeQuery";
3
+ export { extractJoinKey, type JoinKeyExtraction, type JoinKeyPlan, type JoinKeySide, } from "./executeQueryInclude";
3
4
  export { EphemeralSummaryView, createEphemeralSummaryView, queryViewAcross, type EphemeralViewSource, type MindooQueryViewDefinition, } from "./queryView";
4
5
  export { executeQueryLive, type MindooQuerySubscription, } from "./queryLive";
5
6
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/core/query/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAChB,KAAK,WAAW,EAChB,KAAK,kBAAkB,EACvB,KAAK,qBAAqB,EAC1B,KAAK,oBAAoB,EACzB,KAAK,kBAAkB,EACvB,KAAK,cAAc,EACnB,KAAK,mBAAmB,EACxB,KAAK,iBAAiB,GACvB,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EACL,oBAAoB,EACpB,0BAA0B,EAC1B,eAAe,EACf,KAAK,mBAAmB,EACxB,KAAK,yBAAyB,GAC/B,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,gBAAgB,EAChB,KAAK,uBAAuB,GAC7B,MAAM,aAAa,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/core/query/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAChB,qBAAqB,EACrB,iBAAiB,EACjB,KAAK,WAAW,EAChB,KAAK,kBAAkB,EACvB,KAAK,6BAA6B,EAClC,KAAK,uBAAuB,EAC5B,KAAK,kBAAkB,EACvB,KAAK,qBAAqB,EAC1B,KAAK,oBAAoB,EACzB,KAAK,kBAAkB,EACvB,KAAK,cAAc,EACnB,KAAK,mBAAmB,EACxB,KAAK,iBAAiB,GACvB,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EACL,cAAc,EACd,KAAK,iBAAiB,EACtB,KAAK,WAAW,EAChB,KAAK,WAAW,GACjB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACL,oBAAoB,EACpB,0BAA0B,EAC1B,eAAe,EACf,KAAK,mBAAmB,EACxB,KAAK,yBAAyB,GAC/B,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,gBAAgB,EAChB,KAAK,uBAAuB,GAC7B,MAAM,aAAa,CAAC"}
@@ -1,10 +1,14 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.executeQueryLive = exports.queryViewAcross = exports.createEphemeralSummaryView = exports.EphemeralSummaryView = exports.executeQuery = exports.MindooQueryError = void 0;
3
+ exports.executeQueryLive = exports.queryViewAcross = exports.createEphemeralSummaryView = exports.EphemeralSummaryView = exports.extractJoinKey = exports.executeQuery = exports.MAX_INCLUDE_DEPTH = exports.DEFAULT_INCLUDE_LIMIT = exports.MindooQueryError = void 0;
4
4
  var types_1 = require("./types");
5
5
  Object.defineProperty(exports, "MindooQueryError", { enumerable: true, get: function () { return types_1.MindooQueryError; } });
6
+ Object.defineProperty(exports, "DEFAULT_INCLUDE_LIMIT", { enumerable: true, get: function () { return types_1.DEFAULT_INCLUDE_LIMIT; } });
7
+ Object.defineProperty(exports, "MAX_INCLUDE_DEPTH", { enumerable: true, get: function () { return types_1.MAX_INCLUDE_DEPTH; } });
6
8
  var executeQuery_1 = require("./executeQuery");
7
9
  Object.defineProperty(exports, "executeQuery", { enumerable: true, get: function () { return executeQuery_1.executeQuery; } });
10
+ var executeQueryInclude_1 = require("./executeQueryInclude");
11
+ Object.defineProperty(exports, "extractJoinKey", { enumerable: true, get: function () { return executeQueryInclude_1.extractJoinKey; } });
8
12
  var queryView_1 = require("./queryView");
9
13
  Object.defineProperty(exports, "EphemeralSummaryView", { enumerable: true, get: function () { return queryView_1.EphemeralSummaryView; } });
10
14
  Object.defineProperty(exports, "createEphemeralSummaryView", { enumerable: true, get: function () { return queryView_1.createEphemeralSummaryView; } });
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/core/query/index.ts"],"names":[],"mappings":";;;AAAA,iCAUiB;AATf,yGAAA,gBAAgB,OAAA;AAUlB,+CAA8C;AAArC,4GAAA,YAAY,OAAA;AACrB,yCAMqB;AALnB,iHAAA,oBAAoB,OAAA;AACpB,uHAAA,0BAA0B,OAAA;AAC1B,4GAAA,eAAe,OAAA;AAIjB,yCAGqB;AAFnB,6GAAA,gBAAgB,OAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/core/query/index.ts"],"names":[],"mappings":";;;AAAA,iCAeiB;AAdf,yGAAA,gBAAgB,OAAA;AAChB,8GAAA,qBAAqB,OAAA;AACrB,0GAAA,iBAAiB,OAAA;AAanB,+CAA8C;AAArC,4GAAA,YAAY,OAAA;AACrB,6DAK+B;AAJ7B,qHAAA,cAAc,OAAA;AAKhB,yCAMqB;AALnB,iHAAA,oBAAoB,OAAA;AACpB,uHAAA,0BAA0B,OAAA;AAC1B,4GAAA,eAAe,OAAA;AAIjB,yCAGqB;AAFnB,6GAAA,gBAAgB,OAAA"}
@@ -0,0 +1,45 @@
1
+ import type { MindooDB } from "../types";
2
+ import { type ExpressionEvaluationContext } from "../expressions";
3
+ import type { MindooQueryCoverage, MindooQueryRow, MindooQuerySortKey, ParsedMindooQuery } from "./types";
4
+ /**
5
+ * Pieces shared by the root query scan ({@link executeQuery}) and the
6
+ * nested include hydration ({@link hydrateQueryIncludes}).
7
+ *
8
+ * They live here rather than in `executeQuery.ts` so both paths sort and
9
+ * project through the SAME code: an included row must be built exactly
10
+ * like a root row, otherwise projection or ordering semantics drift apart
11
+ * between the two levels of the same result.
12
+ */
13
+ /** A row plus its scan-internal bookkeeping, used while a scan is in progress. */
14
+ export type CandidateRow = MindooQueryRow & {
15
+ sortValues: unknown[];
16
+ /**
17
+ * The document's UNPROJECTED values in evaluation form. Kept alongside
18
+ * the (possibly projected) `fields` because include hydration reads
19
+ * join keys from it — projecting the result must not break the join.
20
+ */
21
+ evaluationDoc: Record<string, unknown>;
22
+ };
23
+ /**
24
+ * Effective sort keys of a query: an explicit `sortBy` wins; a `text`
25
+ * clause without one defaults to relevance ranking (best score first).
26
+ */
27
+ export declare function effectiveSortKeys(query: ParsedMindooQuery): MindooQuerySortKey[];
28
+ export declare function sortDirectionDescending(sortKey: MindooQuerySortKey): boolean;
29
+ export declare function computeSortValues(sortKeys: MindooQuerySortKey[], context: ExpressionEvaluationContext, textScore?: number): unknown[];
30
+ /**
31
+ * Orders two candidates by their precomputed sort values, falling back to
32
+ * the document id so equal keys still produce a stable, reproducible
33
+ * order.
34
+ */
35
+ export declare function compareCandidates(left: CandidateRow, right: CandidateRow, sortKeys: MindooQuerySortKey[]): number;
36
+ export declare function projectFields(fields: Record<string, unknown>, projection?: string[]): Record<string, unknown>;
37
+ export declare function queryOrigin(db: MindooDB): string;
38
+ /**
39
+ * Merges the coverage of several data sources into the one reported for
40
+ * the result. Anything less than complete wins: a query joining a current
41
+ * summary with one that is still backfilling may be missing rows, and
42
+ * saying `"full"` there would be the most misleading answer available.
43
+ */
44
+ export declare function mergeCoverage(current: MindooQueryCoverage, next: MindooQueryCoverage): MindooQueryCoverage;
45
+ //# sourceMappingURL=queryInternals.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"queryInternals.d.ts","sourceRoot":"","sources":["../../../src/core/query/queryInternals.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAsB,KAAK,2BAA2B,EAAE,MAAM,gBAAgB,CAAC;AAGtF,OAAO,KAAK,EAAE,mBAAmB,EAAE,cAAc,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAE1G;;;;;;;;GAQG;AAEH,kFAAkF;AAClF,MAAM,MAAM,YAAY,GAAG,cAAc,GAAG;IAC1C,UAAU,EAAE,OAAO,EAAE,CAAC;IACtB;;;;OAIG;IACH,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACxC,CAAC;AAEF;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,iBAAiB,GAAG,kBAAkB,EAAE,CAQhF;AAED,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,kBAAkB,GAAG,OAAO,CAE5E;AAED,wBAAgB,iBAAiB,CAC/B,QAAQ,EAAE,kBAAkB,EAAE,EAC9B,OAAO,EAAE,2BAA2B,EACpC,SAAS,CAAC,EAAE,MAAM,GACjB,OAAO,EAAE,CAYX;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,YAAY,EAClB,KAAK,EAAE,YAAY,EACnB,QAAQ,EAAE,kBAAkB,EAAE,GAC7B,MAAM,CAQR;AAED,wBAAgB,aAAa,CAC3B,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC/B,UAAU,CAAC,EAAE,MAAM,EAAE,GACpB,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAYzB;AAED,wBAAgB,WAAW,CAAC,EAAE,EAAE,QAAQ,GAAG,MAAM,CAEhD;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAC3B,OAAO,EAAE,mBAAmB,EAC5B,IAAI,EAAE,mBAAmB,GACxB,mBAAmB,CAQrB"}
@@ -0,0 +1,87 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.effectiveSortKeys = effectiveSortKeys;
4
+ exports.sortDirectionDescending = sortDirectionDescending;
5
+ exports.computeSortValues = computeSortValues;
6
+ exports.compareCandidates = compareCandidates;
7
+ exports.projectFields = projectFields;
8
+ exports.queryOrigin = queryOrigin;
9
+ exports.mergeCoverage = mergeCoverage;
10
+ const expressions_1 = require("../expressions");
11
+ const extractSummaryFields_1 = require("../indexing/summary/extractSummaryFields");
12
+ const types_1 = require("../indexing/virtualviews/types");
13
+ /**
14
+ * Effective sort keys of a query: an explicit `sortBy` wins; a `text`
15
+ * clause without one defaults to relevance ranking (best score first).
16
+ */
17
+ function effectiveSortKeys(query) {
18
+ if (query.sortBy && query.sortBy.length > 0) {
19
+ return query.sortBy;
20
+ }
21
+ if (query.text) {
22
+ return [{ special: "textScore", direction: "descending" }];
23
+ }
24
+ return [];
25
+ }
26
+ function sortDirectionDescending(sortKey) {
27
+ return sortKey.direction === "descending";
28
+ }
29
+ function computeSortValues(sortKeys, context, textScore) {
30
+ return sortKeys.map((sortKey) => {
31
+ if (sortKey.special === "textScore") {
32
+ return textScore ?? 0;
33
+ }
34
+ if (sortKey.expression) {
35
+ return (0, expressions_1.evaluateExpression)(sortKey.expression, context);
36
+ }
37
+ // Plain field sort keys resolve against the evaluation doc, which also
38
+ // carries the mirrored managed fields (`_lastModified`, `_attachments`).
39
+ return (0, extractSummaryFields_1.getSummaryFieldValue)(context.doc, sortKey.field ?? "");
40
+ });
41
+ }
42
+ /**
43
+ * Orders two candidates by their precomputed sort values, falling back to
44
+ * the document id so equal keys still produce a stable, reproducible
45
+ * order.
46
+ */
47
+ function compareCandidates(left, right, sortKeys) {
48
+ for (let i = 0; i < sortKeys.length; i++) {
49
+ const result = (0, types_1.compareValues)(left.sortValues[i], right.sortValues[i], sortDirectionDescending(sortKeys[i]));
50
+ if (result !== 0) {
51
+ return result;
52
+ }
53
+ }
54
+ return left.docId.localeCompare(right.docId);
55
+ }
56
+ function projectFields(fields, projection) {
57
+ if (!projection) {
58
+ return fields;
59
+ }
60
+ const projected = {};
61
+ for (const path of projection) {
62
+ const value = (0, extractSummaryFields_1.getSummaryFieldValue)(fields, path);
63
+ if (value !== undefined) {
64
+ projected[path] = value;
65
+ }
66
+ }
67
+ return projected;
68
+ }
69
+ function queryOrigin(db) {
70
+ return `${db.getTenant().getId()}/${db.getStore().getId()}`;
71
+ }
72
+ /**
73
+ * Merges the coverage of several data sources into the one reported for
74
+ * the result. Anything less than complete wins: a query joining a current
75
+ * summary with one that is still backfilling may be missing rows, and
76
+ * saying `"full"` there would be the most misleading answer available.
77
+ */
78
+ function mergeCoverage(current, next) {
79
+ if (current === "rebuilding" || next === "rebuilding") {
80
+ return "rebuilding";
81
+ }
82
+ if (current === "full-scan" || next === "full-scan") {
83
+ return "full-scan";
84
+ }
85
+ return "full";
86
+ }
87
+ //# sourceMappingURL=queryInternals.js.map