@aglyn/shared-util-tools 1.0.0-beta.230 → 1.0.0-beta.232

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.
@@ -0,0 +1,673 @@
1
+ import { _ as _extends } from "@swc/helpers/_/_extends";
2
+ /**
3
+ * @license
4
+ * Copyright 2026 Aglyn LLC
5
+ *
6
+ * Licensed under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this file except in compliance with the License.
8
+ * You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ */ import { listFilterDay, listFilterOperators } from "./list-filter.js";
18
+ /** The document id, as a path. */ export const LIST_QUERY_ID_PATH = '__name__';
19
+ /** Firestore's cap on disjunctions — `in` values times `array-contains-any` values. */ export const LIST_QUERY_DISJUNCTIONS = 30;
20
+ /** A very high private-use codepoint: `[p, p + HIGH]` spans every string starting `p`. */ const HIGH = '\uf8ff';
21
+ const csv = (raw)=>raw.split(',').map((entry)=>entry.trim()).filter(Boolean);
22
+ const dayBounds = (raw)=>{
23
+ const start = listFilterDay(raw);
24
+ if (Number.isNaN(start.getTime())) return null;
25
+ const day = new Date(start);
26
+ day.setHours(0, 0, 0, 0);
27
+ const end = new Date(day);
28
+ end.setDate(end.getDate() + 1);
29
+ return {
30
+ start: day,
31
+ end
32
+ };
33
+ };
34
+ /** The order a range over `path` puts the list in. */ const rangeOrder = (declaration, field, path)=>{
35
+ const offered = declaration.sorts.find((sort)=>sort.path === path);
36
+ if (offered) return offered;
37
+ return {
38
+ path,
39
+ direction: (field == null ? void 0 : field.kind) === 'date' ? 'desc' : 'asc'
40
+ };
41
+ };
42
+ /**
43
+ * One clause as predicates, or the reason it has none. The same operator
44
+ * meanings as the AGL-2501 twins (`applyListFilter`, `listFilterConstraints`),
45
+ * which this replaces for a list that composes clauses.
46
+ */ function shapeClause(field, input, names) {
47
+ var _input_value;
48
+ if (field.windowOnly) return 'this field is not stored where a query can reach it';
49
+ if (!listFilterOperators(field).includes(input.op)) {
50
+ return `${input.op} is not something this list can ask of ${field.column}`;
51
+ }
52
+ const raw = ((_input_value = input.value) != null ? _input_value : '').trim();
53
+ const op = input.op;
54
+ if (op === 'isEmpty') {
55
+ if (field.presence !== 'nullable') return 'only a field stored as null can be asked for empty';
56
+ return {
57
+ filters: [
58
+ {
59
+ path: field.path,
60
+ op: '==',
61
+ value: null
62
+ }
63
+ ]
64
+ };
65
+ }
66
+ if (op === 'isNotEmpty') {
67
+ if (field.presence === 'always') return 'this field is never empty';
68
+ return {
69
+ filters: [
70
+ {
71
+ path: field.path,
72
+ op: '!=',
73
+ value: null
74
+ }
75
+ ],
76
+ inequality: field.path
77
+ };
78
+ }
79
+ if (field.kind === 'boolean') {
80
+ if (raw !== 'true' && raw !== 'false') return 'pick true or false';
81
+ return {
82
+ filters: [
83
+ {
84
+ path: field.path,
85
+ op: '==',
86
+ value: raw === 'true'
87
+ }
88
+ ]
89
+ };
90
+ }
91
+ if (!raw) return 'no value yet';
92
+ if (field.keysOf) {
93
+ if (op !== 'equals' || !/^[A-Za-z0-9_]+$/.test(raw)) return 'pick one of the choices';
94
+ return {
95
+ filters: [
96
+ {
97
+ path: `${field.path}.${raw}`,
98
+ op: '==',
99
+ value: true
100
+ }
101
+ ]
102
+ };
103
+ }
104
+ if (field.kind === 'text') {
105
+ if (op === 'contains' && field.tokensPath) {
106
+ const token = field.verbatimTokens ? raw : names.token(raw);
107
+ if (!token) return 'no value yet';
108
+ return {
109
+ filters: [
110
+ {
111
+ path: field.tokensPath,
112
+ op: 'array-contains',
113
+ value: token
114
+ }
115
+ ],
116
+ array: true
117
+ };
118
+ }
119
+ if (op === 'equals' && field.lowerPath) {
120
+ return {
121
+ filters: [
122
+ {
123
+ path: field.lowerPath,
124
+ op: '==',
125
+ value: names.key(raw)
126
+ }
127
+ ]
128
+ };
129
+ }
130
+ if (op === 'equals' && field.presence === 'always' && !field.lowerPath) {
131
+ return {
132
+ filters: [
133
+ {
134
+ path: field.path,
135
+ op: '==',
136
+ value: raw
137
+ }
138
+ ]
139
+ };
140
+ }
141
+ if (op === 'startsWith' && field.lowerPath) {
142
+ const key = names.key(raw);
143
+ return {
144
+ filters: [
145
+ {
146
+ path: field.lowerPath,
147
+ op: '>=',
148
+ value: key
149
+ },
150
+ {
151
+ path: field.lowerPath,
152
+ op: '<=',
153
+ value: `${key}${HIGH}`
154
+ }
155
+ ],
156
+ inequality: field.lowerPath
157
+ };
158
+ }
159
+ if (op === 'endsWith' && field.reversedPath) {
160
+ const key = names.reversed(raw);
161
+ return {
162
+ filters: [
163
+ {
164
+ path: field.reversedPath,
165
+ op: '>=',
166
+ value: key
167
+ },
168
+ {
169
+ path: field.reversedPath,
170
+ op: '<=',
171
+ value: `${key}${HIGH}`
172
+ }
173
+ ],
174
+ inequality: field.reversedPath
175
+ };
176
+ }
177
+ if (op === 'isAnyOf' && field.lowerPath) {
178
+ const values = csv(raw).map((value)=>names.key(value));
179
+ if (values.length > LIST_QUERY_DISJUNCTIONS) return `at most ${LIST_QUERY_DISJUNCTIONS} values`;
180
+ return {
181
+ filters: [
182
+ {
183
+ path: field.lowerPath,
184
+ op: 'in',
185
+ value: values
186
+ }
187
+ ],
188
+ disjunctions: values.length
189
+ };
190
+ }
191
+ return `${op} is not something this list can ask of ${field.column}`;
192
+ }
193
+ if (field.kind === 'id') {
194
+ if (op === 'equals') return {
195
+ filters: [
196
+ {
197
+ path: LIST_QUERY_ID_PATH,
198
+ op: '==',
199
+ value: raw
200
+ }
201
+ ]
202
+ };
203
+ if (op === 'isAnyOf') {
204
+ const values = csv(raw);
205
+ if (values.length > LIST_QUERY_DISJUNCTIONS) return `at most ${LIST_QUERY_DISJUNCTIONS} values`;
206
+ return {
207
+ filters: [
208
+ {
209
+ path: LIST_QUERY_ID_PATH,
210
+ op: 'in',
211
+ value: values
212
+ }
213
+ ],
214
+ disjunctions: values.length
215
+ };
216
+ }
217
+ if (op === 'startsWith') {
218
+ return {
219
+ filters: [
220
+ {
221
+ path: LIST_QUERY_ID_PATH,
222
+ op: '>=',
223
+ value: raw
224
+ },
225
+ {
226
+ path: LIST_QUERY_ID_PATH,
227
+ op: '<=',
228
+ value: `${raw}${HIGH}`
229
+ }
230
+ ],
231
+ inequality: LIST_QUERY_ID_PATH
232
+ };
233
+ }
234
+ return `${op} is not something this list can ask of ${field.column}`;
235
+ }
236
+ if (field.kind === 'exact') {
237
+ if (op === 'equals') return {
238
+ filters: [
239
+ {
240
+ path: field.path,
241
+ op: '==',
242
+ value: raw
243
+ }
244
+ ]
245
+ };
246
+ if (op === 'isAnyOf') {
247
+ const values = csv(raw);
248
+ if (values.length > LIST_QUERY_DISJUNCTIONS) return `at most ${LIST_QUERY_DISJUNCTIONS} values`;
249
+ if (field.tokensPath) {
250
+ // An array field asked "any of these": one array clause.
251
+ return {
252
+ filters: [
253
+ {
254
+ path: field.tokensPath,
255
+ op: 'array-contains-any',
256
+ value: values
257
+ }
258
+ ],
259
+ array: true,
260
+ disjunctions: values.length
261
+ };
262
+ }
263
+ return {
264
+ filters: [
265
+ {
266
+ path: field.path,
267
+ op: 'in',
268
+ value: values
269
+ }
270
+ ],
271
+ disjunctions: values.length
272
+ };
273
+ }
274
+ if (op === 'contains' && field.tokensPath) {
275
+ return {
276
+ filters: [
277
+ {
278
+ path: field.tokensPath,
279
+ op: 'array-contains',
280
+ value: raw
281
+ }
282
+ ],
283
+ array: true
284
+ };
285
+ }
286
+ return `${op} is not something this list can ask of ${field.column}`;
287
+ }
288
+ if (field.kind === 'number') {
289
+ const value = Number(raw);
290
+ if (!Number.isFinite(value)) return 'type a number';
291
+ if (op === '=') return {
292
+ filters: [
293
+ {
294
+ path: field.path,
295
+ op: '==',
296
+ value
297
+ }
298
+ ]
299
+ };
300
+ const comparison = {
301
+ '!=': '!=',
302
+ '>': '>',
303
+ '>=': '>=',
304
+ '<': '<',
305
+ '<=': '<='
306
+ };
307
+ const found = comparison[op];
308
+ if (!found) return `${op} is not something this list can ask of ${field.column}`;
309
+ return {
310
+ filters: [
311
+ {
312
+ path: field.path,
313
+ op: found,
314
+ value
315
+ }
316
+ ],
317
+ inequality: field.path
318
+ };
319
+ }
320
+ if (field.kind === 'date') {
321
+ const day = dayBounds(raw);
322
+ if (!day) return 'pick a date';
323
+ // A `…AtMs` field is compared as the number it is stored as.
324
+ const at = (date)=>field.storedAs === 'millis' ? date.getTime() : date;
325
+ if (op === 'is') {
326
+ return {
327
+ filters: [
328
+ {
329
+ path: field.path,
330
+ op: '>=',
331
+ value: at(day.start)
332
+ },
333
+ {
334
+ path: field.path,
335
+ op: '<',
336
+ value: at(day.end)
337
+ }
338
+ ],
339
+ inequality: field.path
340
+ };
341
+ }
342
+ const bound = {
343
+ after: [
344
+ '>=',
345
+ day.end
346
+ ],
347
+ onOrAfter: [
348
+ '>=',
349
+ day.start
350
+ ],
351
+ before: [
352
+ '<',
353
+ day.start
354
+ ],
355
+ onOrBefore: [
356
+ '<',
357
+ day.end
358
+ ]
359
+ };
360
+ const found = bound[op];
361
+ if (!found) return `${op} is not something this list can ask of ${field.column}`;
362
+ return {
363
+ filters: [
364
+ {
365
+ path: field.path,
366
+ op: found[0],
367
+ value: at(found[1])
368
+ }
369
+ ],
370
+ inequality: field.path
371
+ };
372
+ }
373
+ return `${op} is not something this list can ask of ${field.column}`;
374
+ }
375
+ const disjunctionsOf = (filter)=>filter.op === 'in' || filter.op === 'array-contains-any' ? Math.max(1, Array.isArray(filter.value) ? filter.value.length : 1) : 1;
376
+ /**
377
+ * Every clause and the search, as ONE query — or as much of it as one query
378
+ * can hold, with the rest refused by name.
379
+ *
380
+ * Order of claim: the base (the list's scope) first, then the search, then
381
+ * the clauses in the order they were added. A clause that would be a second
382
+ * array clause, a second inequality field or push the disjunctions past
383
+ * thirty is refused, and the list shows the refusal beside its chip; the
384
+ * clauses before it stand. The search is claimed before the clauses because
385
+ * it is the thing a reader typed last and looks at.
386
+ */ export function planListQuery(declaration, request, names) {
387
+ var _request_base, _ref, _request_search, _ref1;
388
+ var _filters_find;
389
+ const filters = [
390
+ ...(_request_base = request.base) != null ? _request_base : []
391
+ ];
392
+ const served = [];
393
+ const refused = [];
394
+ const notices = [];
395
+ let arrayTaken = filters.some((filter)=>filter.op === 'array-contains' || filter.op === 'array-contains-any');
396
+ let inequality = (_ref = (_filters_find = filters.find((filter)=>[
397
+ '!=',
398
+ '<',
399
+ '<=',
400
+ '>',
401
+ '>='
402
+ ].includes(filter.op))) == null ? void 0 : _filters_find.path) != null ? _ref : null;
403
+ let disjunctions = filters.reduce((product, filter)=>product * disjunctionsOf(filter), 1);
404
+ // The search.
405
+ let searched = null;
406
+ const words = ((_request_search = request.search) != null ? _request_search : []).map((word)=>word.trim()).filter(Boolean);
407
+ if (words.length) {
408
+ const search = declaration.search;
409
+ const token = names.token(words.join(' '));
410
+ if (!search) {
411
+ refused.push({
412
+ clause: 'search',
413
+ reason: 'this list has no search'
414
+ });
415
+ } else if (!token) {
416
+ // Nothing searchable was typed.
417
+ } else {
418
+ const scopeAt = filters.findIndex((filter)=>filter.op === 'array-contains-any' || filter.op === 'array-contains');
419
+ if (scopeAt === -1) {
420
+ filters.push({
421
+ path: search.tokensPath,
422
+ op: 'array-contains',
423
+ value: token
424
+ });
425
+ arrayTaken = true;
426
+ searched = token;
427
+ } else if (search.scoped) {
428
+ // Fold the search into the scope: one array clause answers both.
429
+ const scope = filters[scopeAt];
430
+ const scopes = Array.isArray(scope.value) ? scope.value : [
431
+ scope.value
432
+ ];
433
+ filters.splice(scopeAt, 1, {
434
+ path: search.scoped.tokensPath,
435
+ op: 'array-contains-any',
436
+ value: scopes.map((entry)=>{
437
+ var _search_scoped;
438
+ return `${String(entry)}${(_search_scoped = search.scoped) == null ? void 0 : _search_scoped.join}${token}`;
439
+ })
440
+ });
441
+ searched = token;
442
+ } else {
443
+ refused.push({
444
+ clause: 'search',
445
+ reason: 'this list is already narrowed to what you can see, which search cannot combine with'
446
+ });
447
+ }
448
+ if (searched && words.length > 1) {
449
+ notices.push(`Search matches one word at a time: showing results for "${token}".`);
450
+ }
451
+ if (searched && names.key(words[0]).length > names.maxPrefix) {
452
+ notices.push(`Search reads the first ${names.maxPrefix} letters of a word.`);
453
+ }
454
+ }
455
+ }
456
+ // The clauses.
457
+ for (const clause of request.clauses){
458
+ const field = declaration.fields.find((entry)=>entry.column === clause.field);
459
+ if (!field) {
460
+ refused.push({
461
+ clause,
462
+ reason: 'this list does not filter by that'
463
+ });
464
+ continue;
465
+ }
466
+ const shape = shapeClause(field, clause, names);
467
+ if (typeof shape === 'string') {
468
+ refused.push({
469
+ clause,
470
+ reason: shape
471
+ });
472
+ continue;
473
+ }
474
+ if (shape.array && arrayTaken) {
475
+ refused.push({
476
+ clause,
477
+ reason: searched ? 'cannot be combined with the search — clear the search to use it' : 'cannot be combined with another "contains" or "any of" filter on a list'
478
+ });
479
+ continue;
480
+ }
481
+ if (shape.inequality && inequality && shape.inequality !== inequality) {
482
+ refused.push({
483
+ clause,
484
+ reason: 'only one range (dates, numbers, starts with) can apply at a time'
485
+ });
486
+ continue;
487
+ }
488
+ const product = disjunctions * shape.filters.reduce((total, filter)=>total * disjunctionsOf(filter), 1);
489
+ if (product > LIST_QUERY_DISJUNCTIONS) {
490
+ refused.push({
491
+ clause,
492
+ reason: `too many values at once (the limit is ${LIST_QUERY_DISJUNCTIONS})`
493
+ });
494
+ continue;
495
+ }
496
+ filters.push(...shape.filters);
497
+ served.push(clause);
498
+ if (shape.array) arrayTaken = true;
499
+ if (shape.inequality) inequality = shape.inequality;
500
+ disjunctions = product;
501
+ }
502
+ // The order.
503
+ const declared = request.sort ? declaration.sorts.find((sort)=>{
504
+ var _request_sort, _request_sort1;
505
+ return sort.path === ((_request_sort = request.sort) == null ? void 0 : _request_sort.path) && sort.direction === ((_request_sort1 = request.sort) == null ? void 0 : _request_sort1.direction);
506
+ }) : undefined;
507
+ let sortFallback = null;
508
+ let asked = declared;
509
+ // An `alone` order holds only while nothing narrows the list past its base.
510
+ if ((declared == null ? void 0 : declared.alone) && (served.length > 0 || searched !== null)) {
511
+ asked = defaultHeaderSort(declaration);
512
+ sortFallback = {
513
+ asked: declared,
514
+ reason: 'alone'
515
+ };
516
+ notices.push(`Sorted by ${sortLabel(asked)}: ${sortLabel(declared)} sorts only with no filter or search on.`);
517
+ }
518
+ // A range leads the order with the field it ranges over — in the asked
519
+ // direction when the asked order IS that field, since a declared order has
520
+ // its composites either way.
521
+ const orderBy = inequality ? (asked == null ? void 0 : asked.path) === inequality ? asked : rangeOrder(declaration, declaration.fields.find((field)=>field.path === inequality || field.lowerPath === inequality || field.reversedPath === inequality), inequality) : (_ref1 = asked != null ? asked : declaration.sorts[0]) != null ? _ref1 : {
522
+ path: LIST_QUERY_ID_PATH,
523
+ direction: 'asc'
524
+ };
525
+ // A range took the order from a header the reader picked: say so. Not for
526
+ // the default order, which nobody picked.
527
+ if (!sortFallback && declared && declared !== declaration.sorts[0] && declared !== defaultHeaderSort(declaration) && orderBy.path !== declared.path) {
528
+ sortFallback = {
529
+ asked: declared,
530
+ reason: 'range'
531
+ };
532
+ const label = sortLabel(orderBy);
533
+ notices.push(`Sorted by ${label}: a ${label} filter orders the list by it.`);
534
+ }
535
+ // Absent rather than null when the asked order was served, so a plan that
536
+ // sorted as asked reads exactly as it did before AGL-3680 (the native twins
537
+ // compare plans key by key).
538
+ return _extends({
539
+ filters,
540
+ orderBy,
541
+ served,
542
+ searched,
543
+ refused,
544
+ notices
545
+ }, sortFallback ? {
546
+ sortFallback
547
+ } : {});
548
+ }
549
+ /** How an order reads in a notice. */ const sortLabel = (sort)=>{
550
+ var _ref, _ref1, _ref2;
551
+ return (_ref = (_ref1 = (_ref2 = sort == null ? void 0 : sort.label) != null ? _ref2 : sort == null ? void 0 : sort.column) != null ? _ref1 : sort == null ? void 0 : sort.path) != null ? _ref : 'the default order';
552
+ };
553
+ /**
554
+ * The order an `alone` sort falls back to: the first header order that is
555
+ * not itself `alone`, else the list's default. A fallback that could itself
556
+ * fall back would leave the list in no order at all.
557
+ */ export function defaultHeaderSort(declaration) {
558
+ var _ref, _declaration_sorts_find;
559
+ return (_ref = (_declaration_sorts_find = declaration.sorts.find((sort)=>sort.column && !sort.alone)) != null ? _declaration_sorts_find : declaration.sorts.find((sort)=>!sort.alone)) != null ? _ref : {
560
+ path: LIST_QUERY_ID_PATH,
561
+ direction: 'asc'
562
+ };
563
+ }
564
+ const ORDER = {
565
+ asc: 'ASCENDING',
566
+ desc: 'DESCENDING'
567
+ };
568
+ /**
569
+ * Every composite a declaration's queries can need, under index merging:
570
+ * one `(predicate field, order)` index per equality or array field and per
571
+ * order the list can take — its sorts, and the order each range imposes.
572
+ *
573
+ * `base` names the scope predicates the list always applies (their paths
574
+ * and whether they are array clauses), which need their own index per order
575
+ * like any other equality. Pinned by each list's spec against
576
+ * `cloud/firebase-firestore.indexes.json`.
577
+ */ export function listQueryIndexes(declaration, base = []) {
578
+ const equalities = new Map() // path → is array clause
579
+ ;
580
+ // `alone` orders pair with the base only (AGL-3680); every other order —
581
+ // and an `alone` one a range also imposes — with every equality.
582
+ const orders = declaration.sorts.map((sort)=>_extends({}, sort));
583
+ const addOrder = (sort)=>{
584
+ const found = orders.find((entry)=>entry.path === sort.path && entry.direction === sort.direction);
585
+ if (found) found.alone = false;
586
+ else orders.push(_extends({}, sort, {
587
+ alone: false
588
+ }));
589
+ };
590
+ const basePaths = new Set(base.map((entry)=>entry.path));
591
+ for (const entry of base)equalities.set(entry.path, Boolean(entry.array));
592
+ if (declaration.search) {
593
+ equalities.set(declaration.search.tokensPath, true);
594
+ if (declaration.search.scoped) equalities.set(declaration.search.scoped.tokensPath, true);
595
+ }
596
+ for (const field of declaration.fields){
597
+ if (field.windowOnly) continue;
598
+ const ops = listFilterOperators(field);
599
+ const has = (...names)=>names.some((name)=>ops.includes(name));
600
+ if (field.keysOf) {
601
+ var _ref;
602
+ var _declaration_keys;
603
+ for (const key of (_ref = (_declaration_keys = declaration.keys) == null ? void 0 : _declaration_keys[field.column]) != null ? _ref : []){
604
+ equalities.set(`${field.path}.${key}`, false);
605
+ }
606
+ continue;
607
+ }
608
+ if (field.kind === 'text') {
609
+ if (has('contains') && field.tokensPath) equalities.set(field.tokensPath, true);
610
+ if (has('equals', 'isAnyOf') && field.lowerPath) equalities.set(field.lowerPath, false);
611
+ if (has('equals') && !field.lowerPath && field.presence === 'always') equalities.set(field.path, false);
612
+ if (has('startsWith') && field.lowerPath) addOrder(rangeOrder(declaration, field, field.lowerPath));
613
+ if (has('endsWith') && field.reversedPath) addOrder(rangeOrder(declaration, field, field.reversedPath));
614
+ } else if (field.kind === 'exact') {
615
+ if (has('equals', 'isAnyOf')) equalities.set(field.path, false);
616
+ if (has('contains', 'isAnyOf') && field.tokensPath) equalities.set(field.tokensPath, true);
617
+ } else if (field.kind === 'boolean') {
618
+ equalities.set(field.path, false);
619
+ } else if (field.kind === 'number') {
620
+ if (has('=')) equalities.set(field.path, false);
621
+ if (has('!=', '>', '>=', '<', '<=')) addOrder(rangeOrder(declaration, field, field.path));
622
+ } else if (field.kind === 'date') {
623
+ if (has('is', 'after', 'onOrAfter', 'before', 'onOrBefore')) {
624
+ addOrder(rangeOrder(declaration, field, field.path));
625
+ }
626
+ }
627
+ if (has('isEmpty')) equalities.set(field.path, false);
628
+ if (has('isNotEmpty')) addOrder(rangeOrder(declaration, field, field.path));
629
+ }
630
+ const indexes = [];
631
+ const seen = new Set();
632
+ for (const [path, array] of equalities){
633
+ for (const order of orders){
634
+ if (order.path === path || order.path === LIST_QUERY_ID_PATH) continue;
635
+ if (order.alone && !basePaths.has(path)) continue;
636
+ const index = {
637
+ fields: [
638
+ array ? {
639
+ fieldPath: path,
640
+ arrayConfig: 'CONTAINS'
641
+ } : {
642
+ fieldPath: path,
643
+ order: 'ASCENDING'
644
+ },
645
+ {
646
+ fieldPath: order.path,
647
+ order: ORDER[order.direction]
648
+ }
649
+ ]
650
+ };
651
+ const key = JSON.stringify(index);
652
+ if (!seen.has(key)) {
653
+ seen.add(key);
654
+ indexes.push(index);
655
+ }
656
+ }
657
+ }
658
+ return indexes;
659
+ }
660
+ /**
661
+ * The composites a declaration needs that an index file does not hold — what
662
+ * a list's spec asserts is empty, so a declared filter cannot ship without
663
+ * the index that serves it.
664
+ */ export function missingListQueryIndexes(file, collectionGroup, needed, queryScope = 'COLLECTION') {
665
+ const shape = (fields)=>fields.filter((field)=>field.fieldPath !== LIST_QUERY_ID_PATH).map((field)=>{
666
+ var _field_order;
667
+ return `${field.fieldPath}:${(_field_order = field.order) != null ? _field_order : field.arrayConfig}`;
668
+ }).join(',');
669
+ const present = new Set(file.indexes.filter((index)=>index.collectionGroup === collectionGroup && index.queryScope === queryScope).map((index)=>shape(index.fields)));
670
+ return needed.filter((index)=>!present.has(shape(index.fields)));
671
+ }
672
+
673
+ //# sourceMappingURL=list-query-plan.js.map