@aglyn/shared-util-tools 1.0.0-beta.231 → 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.
- package/package.json +2 -2
- package/src/lib/list-query/list-column-sort.d.ts +33 -0
- package/src/lib/list-query/list-column-sort.js +47 -0
- package/src/lib/list-query/list-column-sort.js.map +1 -0
- package/src/lib/list-query/list-query-plan.d.ts +33 -0
- package/src/lib/list-query/list-query-plan.js +54 -8
- package/src/lib/list-query/list-query-plan.js.map +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aglyn/shared-util-tools",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.232",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"homepage": "https://aglyn.com",
|
|
6
6
|
"repository": {
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"./package.json": "./package.json"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@aglyn/shared-data-types": "1.0.0-beta.
|
|
28
|
+
"@aglyn/shared-data-types": "1.0.0-beta.232",
|
|
29
29
|
"@swc/helpers": "0.5.23",
|
|
30
30
|
"lodash-es": "^4.18.1",
|
|
31
31
|
"php-serialize": "^5.1.3"
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Aglyn LLC
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
import type { ListQuerySort } from './list-query-plan';
|
|
18
|
+
/** A value a page sort compares: text, a number, a date, or nothing. */
|
|
19
|
+
export type ListSortValue = string | number | boolean | Date | null | undefined;
|
|
20
|
+
/** How one column reads a row for a page sort (strategy 3). */
|
|
21
|
+
export type ListPageSort<Row> = (row: Row) => ListSortValue;
|
|
22
|
+
/**
|
|
23
|
+
* Two values in `direction`, EMPTY LAST either way — a reader sorting by
|
|
24
|
+
* "Last sign-in" wants the accounts that have one, not a screen of blanks.
|
|
25
|
+
* Text compares as a reader reads it: case-blind, digits as numbers.
|
|
26
|
+
*/
|
|
27
|
+
export declare function compareListSortValues(a: ListSortValue, b: ListSortValue, direction: ListQuerySort['direction']): number;
|
|
28
|
+
/** The rows, a copy, in `direction` by `value` — stable for equal values. */
|
|
29
|
+
export declare function sortListRows<Row>(rows: readonly Row[], value: ListPageSort<Row>, direction: ListQuerySort['direction']): Row[];
|
|
30
|
+
/** What a page-sorted header says, so it never reads as the whole list's order. */
|
|
31
|
+
export declare const LIST_PAGE_SORT_DESCRIPTION = "Sorts the rows on this page";
|
|
32
|
+
/** The notice over a page-sorted list. */
|
|
33
|
+
export declare const listPageSortNotice: (label: string) => string;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Aglyn LLC
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/ const isEmpty = (value)=>value === null || value === undefined || value === '' || value instanceof Date && Number.isNaN(value.getTime()) || typeof value === 'number' && Number.isNaN(value);
|
|
17
|
+
const comparable = (value)=>value instanceof Date ? value.getTime() : typeof value === 'boolean' ? Number(value) : value;
|
|
18
|
+
const collator = new Intl.Collator(undefined, {
|
|
19
|
+
sensitivity: 'base',
|
|
20
|
+
numeric: true
|
|
21
|
+
});
|
|
22
|
+
/**
|
|
23
|
+
* Two values in `direction`, EMPTY LAST either way — a reader sorting by
|
|
24
|
+
* "Last sign-in" wants the accounts that have one, not a screen of blanks.
|
|
25
|
+
* Text compares as a reader reads it: case-blind, digits as numbers.
|
|
26
|
+
*/ export function compareListSortValues(a, b, direction) {
|
|
27
|
+
const emptyA = isEmpty(a);
|
|
28
|
+
const emptyB = isEmpty(b);
|
|
29
|
+
if (emptyA || emptyB) return emptyA === emptyB ? 0 : emptyA ? 1 : -1;
|
|
30
|
+
const left = comparable(a);
|
|
31
|
+
const right = comparable(b);
|
|
32
|
+
// Equal first: `Infinity - Infinity` is NaN, which no sort can use.
|
|
33
|
+
if (left === right) return 0;
|
|
34
|
+
const order = typeof left === 'string' || typeof right === 'string' ? collator.compare(String(left), String(right)) : left - right;
|
|
35
|
+
return direction === 'desc' ? -order : order;
|
|
36
|
+
}
|
|
37
|
+
/** The rows, a copy, in `direction` by `value` — stable for equal values. */ export function sortListRows(rows, value, direction) {
|
|
38
|
+
return rows.map((row, index)=>({
|
|
39
|
+
row,
|
|
40
|
+
index,
|
|
41
|
+
value: value(row)
|
|
42
|
+
})).sort((a, b)=>compareListSortValues(a.value, b.value, direction) || a.index - b.index).map((entry)=>entry.row);
|
|
43
|
+
}
|
|
44
|
+
/** What a page-sorted header says, so it never reads as the whole list's order. */ export const LIST_PAGE_SORT_DESCRIPTION = 'Sorts the rows on this page';
|
|
45
|
+
/** The notice over a page-sorted list. */ export const listPageSortNotice = (label)=>`Sorted by ${label} on this page only: it is not stored where the list's query can order by it.`;
|
|
46
|
+
|
|
47
|
+
//# sourceMappingURL=list-column-sort.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../../../libs/shared/util/tools/src/lib/list-query/list-column-sort.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type { ListQuerySort } from './list-query-plan'\n\n/*\n * EVERY TABLE SORTS BY ITS COLUMN HEADERS (AGL-3680).\n *\n * A header sort on a paged list used to order only the page on screen, which\n * reads as the whole list's order, so the query-served tables switched header\n * sorting off (AGL-3352, AGL-3321). Every column sorts again, each by the one\n * strategy that is honest for it:\n *\n * 1 a stored field on EVERY document the query's `orderBy`: a\n * `ListQuerySort` with `column`,\n * `alone: true` unless it is the\n * default (see `ListQuerySort.alone`)\n * 2 a stored field missing on some stamp it on every write (null is\n * fine) + a backfill, then (1);\n * until then (3) — an `orderBy`\n * DROPS every doc that lacks it\n * 3 joined or computed, not on the doc a PAGE sort: the loaded rows, by a\n * `ListPageSort` value getter; the\n * header says it sorts this page\n * 4 the list loads ALL its rows plain client sort — the grid's own,\n * exact; no `columnSort` needed\n * 5 Firebase Auth the route sorts the complete\n * directory read when it fits the\n * scan bound, the page otherwise\n *\n * Only the actions column is unsortable by design. The web hook is\n * `useListColumnSort` (`@aglyn/shared-ui-jsx/hooks/use-list-column-sort`),\n * handed to `ListTable` as `columnSort`. The pieces here are SDK-free so a\n * route and a native surface sort with the same comparison.\n *\n * ## Converting a list (the staff Users, Sites and Organizations pages are\n * ## the reference implementations)\n *\n * 1. Declare the header orders beside the list's declaration: one\n * `ListQuerySort` per (column, direction), each with `column` and a\n * `label`. The default order first and full; every other one\n * `alone: true` unless it must hold under every filter.\n * 2. Add them to the declaration's `sorts`. The list's spec runs\n * `missingListQueryIndexes` over `listQueryIndexes(declaration, base)`;\n * add only what it reports to `cloud/firebase-firestore.indexes.json`\n * (an `alone` order on an unscoped list adds nothing).\n * 3. The page: hold the asked order in state, hand it to the query (or the\n * route's `sort` param), plan it locally for `orderBy`, and call\n * `useListColumnSort({ sorts, defaultSort, sort, onSortChange, orderBy,\n * rows, pageSorts, headers })`. `pageSorts` holds a value getter for each\n * joined or derived column.\n * 4. `<ListTable rows={columnSort.rows} columnSort={columnSort} … />`, drop\n * `disableColumnSorting`, show `columnSort.notices` beside the route's\n * in `ListQueryNotices`, and delete the file's line from\n * `NOT_YET_CONVERTED` in `apps/console/specs/list-tables-sort-by-their-headers.spec.ts`.\n * 5. A list that loads every row it has (strategy 4): just drop\n * `disableColumnSorting` and let the grid sort.\n */\n\n/** A value a page sort compares: text, a number, a date, or nothing. */\nexport type ListSortValue = string | number | boolean | Date | null | undefined\n\n/** How one column reads a row for a page sort (strategy 3). */\nexport type ListPageSort<Row> = (row: Row) => ListSortValue\n\nconst isEmpty = (value: ListSortValue): boolean =>\n value === null ||\n value === undefined ||\n value === '' ||\n (value instanceof Date && Number.isNaN(value.getTime())) ||\n (typeof value === 'number' && Number.isNaN(value))\n\nconst comparable = (value: ListSortValue): string | number =>\n value instanceof Date\n ? value.getTime()\n : typeof value === 'boolean'\n ? Number(value)\n : (value as string | number)\n\nconst collator = new Intl.Collator(undefined, { sensitivity: 'base', numeric: true })\n\n/**\n * Two values in `direction`, EMPTY LAST either way — a reader sorting by\n * \"Last sign-in\" wants the accounts that have one, not a screen of blanks.\n * Text compares as a reader reads it: case-blind, digits as numbers.\n */\nexport function compareListSortValues(\n a: ListSortValue,\n b: ListSortValue,\n direction: ListQuerySort['direction'],\n): number {\n const emptyA = isEmpty(a)\n const emptyB = isEmpty(b)\n if (emptyA || emptyB) return emptyA === emptyB ? 0 : emptyA ? 1 : -1\n const left = comparable(a)\n const right = comparable(b)\n // Equal first: `Infinity - Infinity` is NaN, which no sort can use.\n if (left === right) return 0\n const order =\n typeof left === 'string' || typeof right === 'string'\n ? collator.compare(String(left), String(right))\n : left - right\n return direction === 'desc' ? -order : order\n}\n\n/** The rows, a copy, in `direction` by `value` — stable for equal values. */\nexport function sortListRows<Row>(\n rows: readonly Row[],\n value: ListPageSort<Row>,\n direction: ListQuerySort['direction'],\n): Row[] {\n return rows\n .map((row, index) => ({ row, index, value: value(row) }))\n .sort((a, b) => compareListSortValues(a.value, b.value, direction) || a.index - b.index)\n .map((entry) => entry.row)\n}\n\n/** What a page-sorted header says, so it never reads as the whole list's order. */\nexport const LIST_PAGE_SORT_DESCRIPTION = 'Sorts the rows on this page'\n\n/** The notice over a page-sorted list. */\nexport const listPageSortNotice = (label: string): string =>\n `Sorted by ${label} on this page only: it is not stored where the list's query can order by it.`\n"],"names":["isEmpty","value","undefined","Date","Number","isNaN","getTime","comparable","collator","Intl","Collator","sensitivity","numeric","compareListSortValues","a","b","direction","emptyA","emptyB","left","right","order","compare","String","sortListRows","rows","map","row","index","sort","entry","LIST_PAGE_SORT_DESCRIPTION","listPageSortNotice","label"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAgED,MAAMA,UAAU,CAACC,QACfA,UAAU,QACVA,UAAUC,aACVD,UAAU,MACTA,iBAAiBE,QAAQC,OAAOC,KAAK,CAACJ,MAAMK,OAAO,OACnD,OAAOL,UAAU,YAAYG,OAAOC,KAAK,CAACJ;AAE7C,MAAMM,aAAa,CAACN,QAClBA,iBAAiBE,OACbF,MAAMK,OAAO,KACb,OAAOL,UAAU,YACfG,OAAOH,SACNA;AAET,MAAMO,WAAW,IAAIC,KAAKC,QAAQ,CAACR,WAAW;IAAES,aAAa;IAAQC,SAAS;AAAK;AAEnF;;;;CAIC,GACD,OAAO,SAASC,sBACdC,CAAgB,EAChBC,CAAgB,EAChBC,SAAqC;IAErC,MAAMC,SAASjB,QAAQc;IACvB,MAAMI,SAASlB,QAAQe;IACvB,IAAIE,UAAUC,QAAQ,OAAOD,WAAWC,SAAS,IAAID,SAAS,IAAI,CAAC;IACnE,MAAME,OAAOZ,WAAWO;IACxB,MAAMM,QAAQb,WAAWQ;IACzB,oEAAoE;IACpE,IAAII,SAASC,OAAO,OAAO;IAC3B,MAAMC,QACJ,OAAOF,SAAS,YAAY,OAAOC,UAAU,WACzCZ,SAASc,OAAO,CAACC,OAAOJ,OAAOI,OAAOH,UACtCD,OAAOC;IACb,OAAOJ,cAAc,SAAS,CAACK,QAAQA;AACzC;AAEA,2EAA2E,GAC3E,OAAO,SAASG,aACdC,IAAoB,EACpBxB,KAAwB,EACxBe,SAAqC;IAErC,OAAOS,KACJC,GAAG,CAAC,CAACC,KAAKC,QAAW,CAAA;YAAED;YAAKC;YAAO3B,OAAOA,MAAM0B;QAAK,CAAA,GACrDE,IAAI,CAAC,CAACf,GAAGC,IAAMF,sBAAsBC,EAAEb,KAAK,EAAEc,EAAEd,KAAK,EAAEe,cAAcF,EAAEc,KAAK,GAAGb,EAAEa,KAAK,EACtFF,GAAG,CAAC,CAACI,QAAUA,MAAMH,GAAG;AAC7B;AAEA,iFAAiF,GACjF,OAAO,MAAMI,6BAA6B,8BAA6B;AAEvE,wCAAwC,GACxC,OAAO,MAAMC,qBAAqB,CAACC,QACjC,CAAC,UAAU,EAAEA,MAAM,4EAA4E,CAAC,CAAA"}
|
|
@@ -40,6 +40,24 @@ export interface ListQuerySort {
|
|
|
40
40
|
direction: 'asc' | 'desc';
|
|
41
41
|
/** The grid column this order sorts, when the list lets the grid sort by it. */
|
|
42
42
|
column?: string;
|
|
43
|
+
/**
|
|
44
|
+
* Served ONLY while nothing narrows the list past its base scope — no
|
|
45
|
+
* served clause, no search word (AGL-3680).
|
|
46
|
+
*
|
|
47
|
+
* A header sort on every column would otherwise cost one composite per
|
|
48
|
+
* (equality field × order), a matrix the 1,000-composite cap cannot hold.
|
|
49
|
+
* An `alone` order is paired only with the base predicates
|
|
50
|
+
* (`listQueryIndexes`), so on a top-level or subcollection list it costs
|
|
51
|
+
* NO composite, and on a base-scoped collection-group list one per
|
|
52
|
+
* direction. Asked while a filter or the search is on, the plan falls
|
|
53
|
+
* back to the list's default header order and says so in `notices`.
|
|
54
|
+
*
|
|
55
|
+
* Leave it off the default order and on at most one other high-value
|
|
56
|
+
* order a list wants to hold under every filter.
|
|
57
|
+
*/
|
|
58
|
+
alone?: boolean;
|
|
59
|
+
/** How the order reads in a notice — "Created", "Plan". Defaults to the column. */
|
|
60
|
+
label?: string;
|
|
43
61
|
}
|
|
44
62
|
/** The document id, as a path. */
|
|
45
63
|
export declare const LIST_QUERY_ID_PATH = "__name__";
|
|
@@ -114,6 +132,15 @@ export interface ListQueryPlan {
|
|
|
114
132
|
refused: ListQueryRefusal[];
|
|
115
133
|
/** Said to the reader about what WAS served — e.g. one search word of two. */
|
|
116
134
|
notices: string[];
|
|
135
|
+
/**
|
|
136
|
+
* The order asked for that the plan did not serve, and why: `alone` — it
|
|
137
|
+
* is served only with no filter or search on; `range` — a range filter
|
|
138
|
+
* leads the order with its own field. Absent when the asked order is served.
|
|
139
|
+
*/
|
|
140
|
+
sortFallback?: {
|
|
141
|
+
asked: ListQuerySort;
|
|
142
|
+
reason: 'alone' | 'range';
|
|
143
|
+
} | null;
|
|
117
144
|
}
|
|
118
145
|
/**
|
|
119
146
|
* Every clause and the search, as ONE query — or as much of it as one query
|
|
@@ -127,6 +154,12 @@ export interface ListQueryPlan {
|
|
|
127
154
|
* it is the thing a reader typed last and looks at.
|
|
128
155
|
*/
|
|
129
156
|
export declare function planListQuery(declaration: ListQueryDeclaration, request: ListQueryRequest, names: ListQueryNormalizers): ListQueryPlan;
|
|
157
|
+
/**
|
|
158
|
+
* The order an `alone` sort falls back to: the first header order that is
|
|
159
|
+
* not itself `alone`, else the list's default. A fallback that could itself
|
|
160
|
+
* fall back would leave the list in no order at all.
|
|
161
|
+
*/
|
|
162
|
+
export declare function defaultHeaderSort(declaration: ListQueryDeclaration): ListQuerySort;
|
|
130
163
|
/** A composite the plan's shapes need, in the index file's own terms. */
|
|
131
164
|
export interface ListQueryIndex {
|
|
132
165
|
fields: Array<{
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { _ as _extends } from "@swc/helpers/_/_extends";
|
|
1
2
|
/**
|
|
2
3
|
* @license
|
|
3
4
|
* Copyright 2026 Aglyn LLC
|
|
@@ -499,10 +500,21 @@ const disjunctionsOf = (filter)=>filter.op === 'in' || filter.op === 'array-cont
|
|
|
499
500
|
disjunctions = product;
|
|
500
501
|
}
|
|
501
502
|
// The order.
|
|
502
|
-
const
|
|
503
|
+
const declared = request.sort ? declaration.sorts.find((sort)=>{
|
|
503
504
|
var _request_sort, _request_sort1;
|
|
504
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);
|
|
505
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
|
+
}
|
|
506
518
|
// A range leads the order with the field it ranges over — in the asked
|
|
507
519
|
// direction when the asked order IS that field, since a declared order has
|
|
508
520
|
// its composites either way.
|
|
@@ -510,13 +522,43 @@ const disjunctionsOf = (filter)=>filter.op === 'in' || filter.op === 'array-cont
|
|
|
510
522
|
path: LIST_QUERY_ID_PATH,
|
|
511
523
|
direction: 'asc'
|
|
512
524
|
};
|
|
513
|
-
|
|
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({
|
|
514
539
|
filters,
|
|
515
540
|
orderBy,
|
|
516
541
|
served,
|
|
517
542
|
searched,
|
|
518
543
|
refused,
|
|
519
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'
|
|
520
562
|
};
|
|
521
563
|
}
|
|
522
564
|
const ORDER = {
|
|
@@ -535,14 +577,17 @@ const ORDER = {
|
|
|
535
577
|
*/ export function listQueryIndexes(declaration, base = []) {
|
|
536
578
|
const equalities = new Map() // path → is array clause
|
|
537
579
|
;
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
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));
|
|
541
583
|
const addOrder = (sort)=>{
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
}
|
|
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
|
+
}));
|
|
545
589
|
};
|
|
590
|
+
const basePaths = new Set(base.map((entry)=>entry.path));
|
|
546
591
|
for (const entry of base)equalities.set(entry.path, Boolean(entry.array));
|
|
547
592
|
if (declaration.search) {
|
|
548
593
|
equalities.set(declaration.search.tokensPath, true);
|
|
@@ -587,6 +632,7 @@ const ORDER = {
|
|
|
587
632
|
for (const [path, array] of equalities){
|
|
588
633
|
for (const order of orders){
|
|
589
634
|
if (order.path === path || order.path === LIST_QUERY_ID_PATH) continue;
|
|
635
|
+
if (order.alone && !basePaths.has(path)) continue;
|
|
590
636
|
const index = {
|
|
591
637
|
fields: [
|
|
592
638
|
array ? {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../../../libs/shared/util/tools/src/lib/list-query/list-query-plan.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n type ListFilterField,\n type ListFilterRequest,\n listFilterDay,\n listFilterOperators,\n} from './list-filter'\n\n/*\n * EVERY CLAUSE ON THE QUERY (AGL-3321).\n *\n * The AGL-2501 contract turned ONE filter into a Firestore query — the list\n * put the first servable clause on its query and matched the rest over the\n * rows it had loaded, and search the same way. A clause matched over a loaded\n * page answers \"no match\" for a record on the next one, which is the one\n * answer a list must never give wrongly.\n *\n * This composes them all. A list declares its fields (the same\n * `ListFilterField` grammar), the sorts it offers and the token array its\n * quick search reads; `planListQuery` turns the clauses in force and the\n * search words into ONE query — every predicate, one order — and says which\n * it could not put there and why. Nothing is matched in memory afterwards:\n * a clause the plan refuses is not applied, and the list says so, rather\n * than being applied to some rows and not others.\n *\n * The plan is SDK-free and model-free: the text normalizers the written\n * search fields were stamped with come in as `ListQueryNormalizers` — the\n * platform's are `nameSearchNormalizers` (`@aglyn/aglyn/app-utils/name-search`)\n * — so the query asks for exactly the keys the writers stored. The web twin (`listQueryConstraints` in the instance\n * library) and the Admin twin (`applyListQuery` in the console) turn it into\n * their SDK's query, so the two cannot disagree about what a clause means.\n *\n * ## What one Firestore query can hold\n *\n * - any number of equalities (`==`, `in`), composed through INDEX MERGING:\n * one `(field, sort)` composite per equality field serves every\n * combination of them, measured against production (AGL-3321);\n * - ONE array clause — `array-contains` or `array-contains-any` — which a\n * search token, a `contains` filter and a scope clause all compete for;\n * - ONE inequality field (a range, `!=`, a prefix range), which must then\n * lead the order — so a range orders the list by the field it ranges over;\n * - at most thirty disjunctions, which an `in` and an\n * `array-contains-any` multiply.\n *\n * The declaration's `listQueryIndexes` enumerates the composites those\n * shapes need, and each list's spec holds the index file to it.\n */\n\n/**\n * How the written search fields were normalized, so a typed value becomes the\n * key the query can match: the lower-cased key (`equals`, `startsWith`), the\n * one word-prefix token (`contains`, search), and the reversed key\n * (`endsWith`). `maxPrefix` is the longest token a writer stores.\n */\nexport interface ListQueryNormalizers {\n key(value: string): string\n token(value: string): string\n reversed(value: string): string\n maxPrefix: number\n}\n\n/** A predicate on the query, SDK-free. `path` `__name__` is the document id. */\nexport type ListQueryOp =\n | '=='\n | '!='\n | '<'\n | '<='\n | '>'\n | '>='\n | 'in'\n | 'array-contains'\n | 'array-contains-any'\n\nexport type ListQueryValue = string | number | boolean | null | Date | readonly (string | number)[]\n\nexport interface ListQueryFilter {\n path: string\n op: ListQueryOp\n value: ListQueryValue\n}\n\nexport interface ListQuerySort {\n path: string\n direction: 'asc' | 'desc'\n /** The grid column this order sorts, when the list lets the grid sort by it. */\n column?: string\n}\n\n/** The document id, as a path. */\nexport const LIST_QUERY_ID_PATH = '__name__'\n\n/** Firestore's cap on disjunctions — `in` values times `array-contains-any` values. */\nexport const LIST_QUERY_DISJUNCTIONS = 30\n\n/** A very high private-use codepoint: `[p, p + HIGH]` spans every string starting `p`. */\nconst HIGH = '\\uf8ff'\n\nexport interface ListQueryDeclaration {\n /** Every field the Filters panel may name. */\n fields: readonly ListFilterField[]\n /**\n * The orders the list offers, its default FIRST. The query takes no other:\n * each is a composite the index file carries for every filterable field.\n */\n sorts: readonly ListQuerySort[]\n /**\n * The quick search: the token array every write stamps (see\n * `nameSearchTokens`), queried with `array-contains` on one typed word.\n * Absent, the list offers no search box.\n */\n search?: {\n tokensPath: string\n /**\n * Under a scope clause the search cannot be a SECOND array clause, so a\n * scoped list writes `<scopeToken><join><prefix>` tokens and the query\n * asks `array-contains-any` over the scope's tokens joined to the word —\n * one array clause that answers both.\n *\n * ⛔ Rules that grant a list from `visibleTo.hasAny(...)` DENY this\n * query, because it no longer constrains `visibleTo`. Declare it only for\n * readers whose rule needs no `visibleTo` term, or for an Admin-SDK read;\n * see `SCOPED_SEARCH_JOIN` in `@aglyn/aglyn/app-utils/name-search`.\n */\n scoped?: { tokensPath: string; join: string }\n }\n /**\n * Keys a presence-map field (`keysOf`) is filtered by, for the index\n * enumeration: `sources.form`, `sources.order`, …\n */\n keys?: Readonly<Record<string, readonly string[]>>\n}\n\n/** What the list asks this time. */\nexport interface ListQueryRequest {\n clauses: readonly ListFilterRequest[]\n /** The quick search's words. */\n search?: readonly string[]\n /** The order asked for; a sort the declaration does not offer is ignored. */\n sort?: ListQuerySort | null\n /**\n * Predicates the list always applies — its scope — which count against\n * the same limits. An `array-contains-any` scope is what a scoped search\n * folds into (`declaration.search.scoped`).\n */\n base?: readonly ListQueryFilter[]\n}\n\nexport interface ListQueryRefusal {\n /** The clause refused, or `search`. */\n clause: ListFilterRequest | 'search'\n reason: string\n}\n\nexport interface ListQueryPlan {\n /** Every predicate, base included, in the order the SDK should add them. */\n filters: ListQueryFilter[]\n /** The one order: the range field's when there is one, else the sort. */\n orderBy: ListQuerySort\n /** The clauses on the query. */\n served: ListFilterRequest[]\n /** The search word on the query, or null. */\n searched: string | null\n /** What was asked and could not be put on the query, with why. */\n refused: ListQueryRefusal[]\n /** Said to the reader about what WAS served — e.g. one search word of two. */\n notices: string[]\n}\n\n/** How one clause lands on a query, before it is composed with the others. */\ninterface ClauseShape {\n filters: ListQueryFilter[]\n /** The inequality field the clause needs to lead the order, if any. */\n inequality?: string\n /** The clause is the query's array clause. */\n array?: boolean\n /** `in` values, for the disjunction budget. */\n disjunctions?: number\n}\n\nconst csv = (raw: string): string[] =>\n raw\n .split(',')\n .map((entry) => entry.trim())\n .filter(Boolean)\n\nconst dayBounds = (raw: string): { start: Date; end: Date } | null => {\n const start = listFilterDay(raw)\n if (Number.isNaN(start.getTime())) return null\n const day = new Date(start)\n day.setHours(0, 0, 0, 0)\n const end = new Date(day)\n end.setDate(end.getDate() + 1)\n return { start: day, end }\n}\n\n/** The order a range over `path` puts the list in. */\nconst rangeOrder = (\n declaration: ListQueryDeclaration,\n field: ListFilterField | undefined,\n path: string,\n): ListQuerySort => {\n const offered = declaration.sorts.find((sort) => sort.path === path)\n if (offered) return offered\n return { path, direction: field?.kind === 'date' ? 'desc' : 'asc' }\n}\n\n/**\n * One clause as predicates, or the reason it has none. The same operator\n * meanings as the AGL-2501 twins (`applyListFilter`, `listFilterConstraints`),\n * which this replaces for a list that composes clauses.\n */\nfunction shapeClause(\n field: ListFilterField,\n input: ListFilterRequest,\n names: ListQueryNormalizers,\n): ClauseShape | string {\n if (field.windowOnly) return 'this field is not stored where a query can reach it'\n if (!listFilterOperators(field).includes(input.op)) {\n return `${input.op} is not something this list can ask of ${field.column}`\n }\n const raw = (input.value ?? '').trim()\n const op = input.op\n\n if (op === 'isEmpty') {\n if (field.presence !== 'nullable') return 'only a field stored as null can be asked for empty'\n return { filters: [{ path: field.path, op: '==', value: null }] }\n }\n if (op === 'isNotEmpty') {\n if (field.presence === 'always') return 'this field is never empty'\n return { filters: [{ path: field.path, op: '!=', value: null }], inequality: field.path }\n }\n if (field.kind === 'boolean') {\n if (raw !== 'true' && raw !== 'false') return 'pick true or false'\n return { filters: [{ path: field.path, op: '==', value: raw === 'true' }] }\n }\n if (!raw) return 'no value yet'\n\n if (field.keysOf) {\n if (op !== 'equals' || !/^[A-Za-z0-9_]+$/.test(raw)) return 'pick one of the choices'\n return { filters: [{ path: `${field.path}.${raw}`, op: '==', value: true }] }\n }\n\n if (field.kind === 'text') {\n if (op === 'contains' && field.tokensPath) {\n const token = field.verbatimTokens ? raw : names.token(raw)\n if (!token) return 'no value yet'\n return {\n filters: [{ path: field.tokensPath, op: 'array-contains', value: token }],\n array: true,\n }\n }\n if (op === 'equals' && field.lowerPath) {\n return { filters: [{ path: field.lowerPath, op: '==', value: names.key(raw) }] }\n }\n if (op === 'equals' && field.presence === 'always' && !field.lowerPath) {\n return { filters: [{ path: field.path, op: '==', value: raw }] }\n }\n if (op === 'startsWith' && field.lowerPath) {\n const key = names.key(raw)\n return {\n filters: [\n { path: field.lowerPath, op: '>=', value: key },\n { path: field.lowerPath, op: '<=', value: `${key}${HIGH}` },\n ],\n inequality: field.lowerPath,\n }\n }\n if (op === 'endsWith' && field.reversedPath) {\n const key = names.reversed(raw)\n return {\n filters: [\n { path: field.reversedPath, op: '>=', value: key },\n { path: field.reversedPath, op: '<=', value: `${key}${HIGH}` },\n ],\n inequality: field.reversedPath,\n }\n }\n if (op === 'isAnyOf' && field.lowerPath) {\n const values = csv(raw).map((value) => names.key(value))\n if (values.length > LIST_QUERY_DISJUNCTIONS) return `at most ${LIST_QUERY_DISJUNCTIONS} values`\n return {\n filters: [{ path: field.lowerPath, op: 'in', value: values }],\n disjunctions: values.length,\n }\n }\n return `${op} is not something this list can ask of ${field.column}`\n }\n\n if (field.kind === 'id') {\n if (op === 'equals') return { filters: [{ path: LIST_QUERY_ID_PATH, op: '==', value: raw }] }\n if (op === 'isAnyOf') {\n const values = csv(raw)\n if (values.length > LIST_QUERY_DISJUNCTIONS) return `at most ${LIST_QUERY_DISJUNCTIONS} values`\n return {\n filters: [{ path: LIST_QUERY_ID_PATH, op: 'in', value: values }],\n disjunctions: values.length,\n }\n }\n if (op === 'startsWith') {\n return {\n filters: [\n { path: LIST_QUERY_ID_PATH, op: '>=', value: raw },\n { path: LIST_QUERY_ID_PATH, op: '<=', value: `${raw}${HIGH}` },\n ],\n inequality: LIST_QUERY_ID_PATH,\n }\n }\n return `${op} is not something this list can ask of ${field.column}`\n }\n\n if (field.kind === 'exact') {\n if (op === 'equals') return { filters: [{ path: field.path, op: '==', value: raw }] }\n if (op === 'isAnyOf') {\n const values = csv(raw)\n if (values.length > LIST_QUERY_DISJUNCTIONS) return `at most ${LIST_QUERY_DISJUNCTIONS} values`\n if (field.tokensPath) {\n // An array field asked \"any of these\": one array clause.\n return {\n filters: [{ path: field.tokensPath, op: 'array-contains-any', value: values }],\n array: true,\n disjunctions: values.length,\n }\n }\n return {\n filters: [{ path: field.path, op: 'in', value: values }],\n disjunctions: values.length,\n }\n }\n if (op === 'contains' && field.tokensPath) {\n return {\n filters: [{ path: field.tokensPath, op: 'array-contains', value: raw }],\n array: true,\n }\n }\n return `${op} is not something this list can ask of ${field.column}`\n }\n\n if (field.kind === 'number') {\n const value = Number(raw)\n if (!Number.isFinite(value)) return 'type a number'\n if (op === '=') return { filters: [{ path: field.path, op: '==', value }] }\n const comparison: Record<string, ListQueryOp> = {\n '!=': '!=',\n '>': '>',\n '>=': '>=',\n '<': '<',\n '<=': '<=',\n }\n const found = comparison[op]\n if (!found) return `${op} is not something this list can ask of ${field.column}`\n return { filters: [{ path: field.path, op: found, value }], inequality: field.path }\n }\n\n if (field.kind === 'date') {\n const day = dayBounds(raw)\n if (!day) return 'pick a date'\n // A `…AtMs` field is compared as the number it is stored as.\n const at = (date: Date): Date | number =>\n field.storedAs === 'millis' ? date.getTime() : date\n if (op === 'is') {\n return {\n filters: [\n { path: field.path, op: '>=', value: at(day.start) },\n { path: field.path, op: '<', value: at(day.end) },\n ],\n inequality: field.path,\n }\n }\n const bound: Record<string, [ListQueryOp, Date]> = {\n after: ['>=', day.end],\n onOrAfter: ['>=', day.start],\n before: ['<', day.start],\n onOrBefore: ['<', day.end],\n }\n const found = bound[op]\n if (!found) return `${op} is not something this list can ask of ${field.column}`\n return { filters: [{ path: field.path, op: found[0], value: at(found[1]) }], inequality: field.path }\n }\n\n return `${op} is not something this list can ask of ${field.column}`\n}\n\nconst disjunctionsOf = (filter: ListQueryFilter): number =>\n filter.op === 'in' || filter.op === 'array-contains-any'\n ? Math.max(1, Array.isArray(filter.value) ? filter.value.length : 1)\n : 1\n\n/**\n * Every clause and the search, as ONE query — or as much of it as one query\n * can hold, with the rest refused by name.\n *\n * Order of claim: the base (the list's scope) first, then the search, then\n * the clauses in the order they were added. A clause that would be a second\n * array clause, a second inequality field or push the disjunctions past\n * thirty is refused, and the list shows the refusal beside its chip; the\n * clauses before it stand. The search is claimed before the clauses because\n * it is the thing a reader typed last and looks at.\n */\nexport function planListQuery(\n declaration: ListQueryDeclaration,\n request: ListQueryRequest,\n names: ListQueryNormalizers,\n): ListQueryPlan {\n const filters: ListQueryFilter[] = [...(request.base ?? [])]\n const served: ListFilterRequest[] = []\n const refused: ListQueryRefusal[] = []\n const notices: string[] = []\n let arrayTaken = filters.some(\n (filter) => filter.op === 'array-contains' || filter.op === 'array-contains-any',\n )\n let inequality: string | null =\n filters.find((filter) => ['!=', '<', '<=', '>', '>='].includes(filter.op))?.path ?? null\n let disjunctions = filters.reduce((product, filter) => product * disjunctionsOf(filter), 1)\n\n // The search.\n let searched: string | null = null\n const words = (request.search ?? []).map((word) => word.trim()).filter(Boolean)\n if (words.length) {\n const search = declaration.search\n const token = names.token(words.join(' '))\n if (!search) {\n refused.push({ clause: 'search', reason: 'this list has no search' })\n } else if (!token) {\n // Nothing searchable was typed.\n } else {\n const scopeAt = filters.findIndex(\n (filter) => filter.op === 'array-contains-any' || filter.op === 'array-contains',\n )\n if (scopeAt === -1) {\n filters.push({ path: search.tokensPath, op: 'array-contains', value: token })\n arrayTaken = true\n searched = token\n } else if (search.scoped) {\n // Fold the search into the scope: one array clause answers both.\n const scope = filters[scopeAt]\n const scopes = Array.isArray(scope.value) ? scope.value : [scope.value]\n filters.splice(scopeAt, 1, {\n path: search.scoped.tokensPath,\n op: 'array-contains-any',\n value: scopes.map((entry) => `${String(entry)}${search.scoped?.join}${token}`),\n })\n searched = token\n } else {\n refused.push({\n clause: 'search',\n reason: 'this list is already narrowed to what you can see, which search cannot combine with',\n })\n }\n if (searched && words.length > 1) {\n notices.push(\n `Search matches one word at a time: showing results for \"${token}\".`,\n )\n }\n if (searched && names.key(words[0]).length > names.maxPrefix) {\n notices.push(`Search reads the first ${names.maxPrefix} letters of a word.`)\n }\n }\n }\n\n // The clauses.\n for (const clause of request.clauses) {\n const field = declaration.fields.find((entry) => entry.column === clause.field)\n if (!field) {\n refused.push({ clause, reason: 'this list does not filter by that' })\n continue\n }\n const shape = shapeClause(field, clause, names)\n if (typeof shape === 'string') {\n refused.push({ clause, reason: shape })\n continue\n }\n if (shape.array && arrayTaken) {\n refused.push({\n clause,\n reason: searched\n ? 'cannot be combined with the search — clear the search to use it'\n : 'cannot be combined with another \"contains\" or \"any of\" filter on a list',\n })\n continue\n }\n if (shape.inequality && inequality && shape.inequality !== inequality) {\n refused.push({\n clause,\n reason: 'only one range (dates, numbers, starts with) can apply at a time',\n })\n continue\n }\n const product =\n disjunctions * shape.filters.reduce((total, filter) => total * disjunctionsOf(filter), 1)\n if (product > LIST_QUERY_DISJUNCTIONS) {\n refused.push({ clause, reason: `too many values at once (the limit is ${LIST_QUERY_DISJUNCTIONS})` })\n continue\n }\n filters.push(...shape.filters)\n served.push(clause)\n if (shape.array) arrayTaken = true\n if (shape.inequality) inequality = shape.inequality\n disjunctions = product\n }\n\n // The order.\n const asked = request.sort\n ? declaration.sorts.find(\n (sort) => sort.path === request.sort?.path && sort.direction === request.sort?.direction,\n )\n : undefined\n // A range leads the order with the field it ranges over — in the asked\n // direction when the asked order IS that field, since a declared order has\n // its composites either way.\n const orderBy = inequality\n ? asked?.path === inequality\n ? asked\n : rangeOrder(\n declaration,\n declaration.fields.find(\n (field) =>\n field.path === inequality ||\n field.lowerPath === inequality ||\n field.reversedPath === inequality,\n ),\n inequality,\n )\n : (asked ?? declaration.sorts[0] ?? { path: LIST_QUERY_ID_PATH, direction: 'asc' })\n\n return { filters, orderBy, served, searched, refused, notices }\n}\n\n/** A composite the plan's shapes need, in the index file's own terms. */\nexport interface ListQueryIndex {\n fields: Array<{ fieldPath: string; order?: 'ASCENDING' | 'DESCENDING'; arrayConfig?: 'CONTAINS' }>\n}\n\nconst ORDER = { asc: 'ASCENDING', desc: 'DESCENDING' } as const\n\n/**\n * Every composite a declaration's queries can need, under index merging:\n * one `(predicate field, order)` index per equality or array field and per\n * order the list can take — its sorts, and the order each range imposes.\n *\n * `base` names the scope predicates the list always applies (their paths\n * and whether they are array clauses), which need their own index per order\n * like any other equality. Pinned by each list's spec against\n * `cloud/firebase-firestore.indexes.json`.\n */\nexport function listQueryIndexes(\n declaration: ListQueryDeclaration,\n base: readonly { path: string; array?: boolean }[] = [],\n): ListQueryIndex[] {\n const equalities = new Map<string, boolean>() // path → is array clause\n const orders: ListQuerySort[] = [...declaration.sorts]\n const addOrder = (sort: ListQuerySort) => {\n if (!orders.some((entry) => entry.path === sort.path && entry.direction === sort.direction)) {\n orders.push(sort)\n }\n }\n for (const entry of base) equalities.set(entry.path, Boolean(entry.array))\n if (declaration.search) {\n equalities.set(declaration.search.tokensPath, true)\n if (declaration.search.scoped) equalities.set(declaration.search.scoped.tokensPath, true)\n }\n for (const field of declaration.fields) {\n if (field.windowOnly) continue\n const ops = listFilterOperators(field)\n const has = (...names: string[]) => names.some((name) => ops.includes(name))\n if (field.keysOf) {\n for (const key of declaration.keys?.[field.column] ?? []) {\n equalities.set(`${field.path}.${key}`, false)\n }\n continue\n }\n if (field.kind === 'text') {\n if (has('contains') && field.tokensPath) equalities.set(field.tokensPath, true)\n if (has('equals', 'isAnyOf') && field.lowerPath) equalities.set(field.lowerPath, false)\n if (has('equals') && !field.lowerPath && field.presence === 'always') equalities.set(field.path, false)\n if (has('startsWith') && field.lowerPath) addOrder(rangeOrder(declaration, field, field.lowerPath))\n if (has('endsWith') && field.reversedPath) addOrder(rangeOrder(declaration, field, field.reversedPath))\n } else if (field.kind === 'exact') {\n if (has('equals', 'isAnyOf')) equalities.set(field.path, false)\n if (has('contains', 'isAnyOf') && field.tokensPath) equalities.set(field.tokensPath, true)\n } else if (field.kind === 'boolean') {\n equalities.set(field.path, false)\n } else if (field.kind === 'number') {\n if (has('=')) equalities.set(field.path, false)\n if (has('!=', '>', '>=', '<', '<=')) addOrder(rangeOrder(declaration, field, field.path))\n } else if (field.kind === 'date') {\n if (has('is', 'after', 'onOrAfter', 'before', 'onOrBefore')) {\n addOrder(rangeOrder(declaration, field, field.path))\n }\n }\n if (has('isEmpty')) equalities.set(field.path, false)\n if (has('isNotEmpty')) addOrder(rangeOrder(declaration, field, field.path))\n }\n const indexes: ListQueryIndex[] = []\n const seen = new Set<string>()\n for (const [path, array] of equalities) {\n for (const order of orders) {\n if (order.path === path || order.path === LIST_QUERY_ID_PATH) continue\n const index: ListQueryIndex = {\n fields: [\n array ? { fieldPath: path, arrayConfig: 'CONTAINS' } : { fieldPath: path, order: 'ASCENDING' },\n { fieldPath: order.path, order: ORDER[order.direction] },\n ],\n }\n const key = JSON.stringify(index)\n if (!seen.has(key)) {\n seen.add(key)\n indexes.push(index)\n }\n }\n }\n return indexes\n}\n\n/** An index entry as `cloud/firebase-firestore.indexes.json` stores it. */\ninterface IndexFileEntry {\n collectionGroup: string\n queryScope: string\n fields: Array<{ fieldPath: string; order?: string; arrayConfig?: string }>\n}\n\n/**\n * The composites a declaration needs that an index file does not hold — what\n * a list's spec asserts is empty, so a declared filter cannot ship without\n * the index that serves it.\n */\nexport function missingListQueryIndexes(\n file: { indexes: readonly IndexFileEntry[] },\n collectionGroup: string,\n needed: readonly ListQueryIndex[],\n queryScope: 'COLLECTION' | 'COLLECTION_GROUP' = 'COLLECTION',\n): ListQueryIndex[] {\n const shape = (fields: IndexFileEntry['fields']) =>\n fields\n .filter((field) => field.fieldPath !== LIST_QUERY_ID_PATH)\n .map((field) => `${field.fieldPath}:${field.order ?? field.arrayConfig}`)\n .join(',')\n const present = new Set(\n file.indexes\n .filter((index) => index.collectionGroup === collectionGroup && index.queryScope === queryScope)\n .map((index) => shape(index.fields)),\n )\n return needed.filter((index) => !present.has(shape(index.fields)))\n}\n"],"names":["listFilterDay","listFilterOperators","LIST_QUERY_ID_PATH","LIST_QUERY_DISJUNCTIONS","HIGH","csv","raw","split","map","entry","trim","filter","Boolean","dayBounds","start","Number","isNaN","getTime","day","Date","setHours","end","setDate","getDate","rangeOrder","declaration","field","path","offered","sorts","find","sort","direction","kind","shapeClause","input","names","windowOnly","includes","op","column","value","presence","filters","inequality","keysOf","test","tokensPath","token","verbatimTokens","array","lowerPath","key","reversedPath","reversed","values","length","disjunctions","isFinite","comparison","found","at","date","storedAs","bound","after","onOrAfter","before","onOrBefore","disjunctionsOf","Math","max","Array","isArray","planListQuery","request","asked","base","served","refused","notices","arrayTaken","some","reduce","product","searched","words","search","word","join","push","clause","reason","scopeAt","findIndex","scoped","scope","scopes","splice","String","maxPrefix","clauses","fields","shape","total","undefined","orderBy","ORDER","asc","desc","listQueryIndexes","equalities","Map","orders","addOrder","set","ops","has","name","keys","indexes","seen","Set","order","index","fieldPath","arrayConfig","JSON","stringify","add","missingListQueryIndexes","file","collectionGroup","needed","queryScope","present"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAED,SAGEA,aAAa,EACbC,mBAAmB,QACd,mBAAe;AAkFtB,gCAAgC,GAChC,OAAO,MAAMC,qBAAqB,WAAU;AAE5C,qFAAqF,GACrF,OAAO,MAAMC,0BAA0B,GAAE;AAEzC,wFAAwF,GACxF,MAAMC,OAAO;AAoFb,MAAMC,MAAM,CAACC,MACXA,IACGC,KAAK,CAAC,KACNC,GAAG,CAAC,CAACC,QAAUA,MAAMC,IAAI,IACzBC,MAAM,CAACC;AAEZ,MAAMC,YAAY,CAACP;IACjB,MAAMQ,QAAQd,cAAcM;IAC5B,IAAIS,OAAOC,KAAK,CAACF,MAAMG,OAAO,KAAK,OAAO;IAC1C,MAAMC,MAAM,IAAIC,KAAKL;IACrBI,IAAIE,QAAQ,CAAC,GAAG,GAAG,GAAG;IACtB,MAAMC,MAAM,IAAIF,KAAKD;IACrBG,IAAIC,OAAO,CAACD,IAAIE,OAAO,KAAK;IAC5B,OAAO;QAAET,OAAOI;QAAKG;IAAI;AAC3B;AAEA,oDAAoD,GACpD,MAAMG,aAAa,CACjBC,aACAC,OACAC;IAEA,MAAMC,UAAUH,YAAYI,KAAK,CAACC,IAAI,CAAC,CAACC,OAASA,KAAKJ,IAAI,KAAKA;IAC/D,IAAIC,SAAS,OAAOA;IACpB,OAAO;QAAED;QAAMK,WAAWN,CAAAA,yBAAA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ources":["../../../../../../../../libs/shared/util/tools/src/lib/list-query/list-query-plan.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n type ListFilterField,\n type ListFilterRequest,\n listFilterDay,\n listFilterOperators,\n} from './list-filter'\n\n/*\n * EVERY CLAUSE ON THE QUERY (AGL-3321).\n *\n * The AGL-2501 contract turned ONE filter into a Firestore query — the list\n * put the first servable clause on its query and matched the rest over the\n * rows it had loaded, and search the same way. A clause matched over a loaded\n * page answers \"no match\" for a record on the next one, which is the one\n * answer a list must never give wrongly.\n *\n * This composes them all. A list declares its fields (the same\n * `ListFilterField` grammar), the sorts it offers and the token array its\n * quick search reads; `planListQuery` turns the clauses in force and the\n * search words into ONE query — every predicate, one order — and says which\n * it could not put there and why. Nothing is matched in memory afterwards:\n * a clause the plan refuses is not applied, and the list says so, rather\n * than being applied to some rows and not others.\n *\n * The plan is SDK-free and model-free: the text normalizers the written\n * search fields were stamped with come in as `ListQueryNormalizers` — the\n * platform's are `nameSearchNormalizers` (`@aglyn/aglyn/app-utils/name-search`)\n * — so the query asks for exactly the keys the writers stored. The web twin (`listQueryConstraints` in the instance\n * library) and the Admin twin (`applyListQuery` in the console) turn it into\n * their SDK's query, so the two cannot disagree about what a clause means.\n *\n * ## What one Firestore query can hold\n *\n * - any number of equalities (`==`, `in`), composed through INDEX MERGING:\n * one `(field, sort)` composite per equality field serves every\n * combination of them, measured against production (AGL-3321);\n * - ONE array clause — `array-contains` or `array-contains-any` — which a\n * search token, a `contains` filter and a scope clause all compete for;\n * - ONE inequality field (a range, `!=`, a prefix range), which must then\n * lead the order — so a range orders the list by the field it ranges over;\n * - at most thirty disjunctions, which an `in` and an\n * `array-contains-any` multiply.\n *\n * The declaration's `listQueryIndexes` enumerates the composites those\n * shapes need, and each list's spec holds the index file to it.\n */\n\n/**\n * How the written search fields were normalized, so a typed value becomes the\n * key the query can match: the lower-cased key (`equals`, `startsWith`), the\n * one word-prefix token (`contains`, search), and the reversed key\n * (`endsWith`). `maxPrefix` is the longest token a writer stores.\n */\nexport interface ListQueryNormalizers {\n key(value: string): string\n token(value: string): string\n reversed(value: string): string\n maxPrefix: number\n}\n\n/** A predicate on the query, SDK-free. `path` `__name__` is the document id. */\nexport type ListQueryOp =\n | '=='\n | '!='\n | '<'\n | '<='\n | '>'\n | '>='\n | 'in'\n | 'array-contains'\n | 'array-contains-any'\n\nexport type ListQueryValue = string | number | boolean | null | Date | readonly (string | number)[]\n\nexport interface ListQueryFilter {\n path: string\n op: ListQueryOp\n value: ListQueryValue\n}\n\nexport interface ListQuerySort {\n path: string\n direction: 'asc' | 'desc'\n /** The grid column this order sorts, when the list lets the grid sort by it. */\n column?: string\n /**\n * Served ONLY while nothing narrows the list past its base scope — no\n * served clause, no search word (AGL-3680).\n *\n * A header sort on every column would otherwise cost one composite per\n * (equality field × order), a matrix the 1,000-composite cap cannot hold.\n * An `alone` order is paired only with the base predicates\n * (`listQueryIndexes`), so on a top-level or subcollection list it costs\n * NO composite, and on a base-scoped collection-group list one per\n * direction. Asked while a filter or the search is on, the plan falls\n * back to the list's default header order and says so in `notices`.\n *\n * Leave it off the default order and on at most one other high-value\n * order a list wants to hold under every filter.\n */\n alone?: boolean\n /** How the order reads in a notice — \"Created\", \"Plan\". Defaults to the column. */\n label?: string\n}\n\n/** The document id, as a path. */\nexport const LIST_QUERY_ID_PATH = '__name__'\n\n/** Firestore's cap on disjunctions — `in` values times `array-contains-any` values. */\nexport const LIST_QUERY_DISJUNCTIONS = 30\n\n/** A very high private-use codepoint: `[p, p + HIGH]` spans every string starting `p`. */\nconst HIGH = '\\uf8ff'\n\nexport interface ListQueryDeclaration {\n /** Every field the Filters panel may name. */\n fields: readonly ListFilterField[]\n /**\n * The orders the list offers, its default FIRST. The query takes no other:\n * each is a composite the index file carries for every filterable field.\n */\n sorts: readonly ListQuerySort[]\n /**\n * The quick search: the token array every write stamps (see\n * `nameSearchTokens`), queried with `array-contains` on one typed word.\n * Absent, the list offers no search box.\n */\n search?: {\n tokensPath: string\n /**\n * Under a scope clause the search cannot be a SECOND array clause, so a\n * scoped list writes `<scopeToken><join><prefix>` tokens and the query\n * asks `array-contains-any` over the scope's tokens joined to the word —\n * one array clause that answers both.\n *\n * ⛔ Rules that grant a list from `visibleTo.hasAny(...)` DENY this\n * query, because it no longer constrains `visibleTo`. Declare it only for\n * readers whose rule needs no `visibleTo` term, or for an Admin-SDK read;\n * see `SCOPED_SEARCH_JOIN` in `@aglyn/aglyn/app-utils/name-search`.\n */\n scoped?: { tokensPath: string; join: string }\n }\n /**\n * Keys a presence-map field (`keysOf`) is filtered by, for the index\n * enumeration: `sources.form`, `sources.order`, …\n */\n keys?: Readonly<Record<string, readonly string[]>>\n}\n\n/** What the list asks this time. */\nexport interface ListQueryRequest {\n clauses: readonly ListFilterRequest[]\n /** The quick search's words. */\n search?: readonly string[]\n /** The order asked for; a sort the declaration does not offer is ignored. */\n sort?: ListQuerySort | null\n /**\n * Predicates the list always applies — its scope — which count against\n * the same limits. An `array-contains-any` scope is what a scoped search\n * folds into (`declaration.search.scoped`).\n */\n base?: readonly ListQueryFilter[]\n}\n\nexport interface ListQueryRefusal {\n /** The clause refused, or `search`. */\n clause: ListFilterRequest | 'search'\n reason: string\n}\n\nexport interface ListQueryPlan {\n /** Every predicate, base included, in the order the SDK should add them. */\n filters: ListQueryFilter[]\n /** The one order: the range field's when there is one, else the sort. */\n orderBy: ListQuerySort\n /** The clauses on the query. */\n served: ListFilterRequest[]\n /** The search word on the query, or null. */\n searched: string | null\n /** What was asked and could not be put on the query, with why. */\n refused: ListQueryRefusal[]\n /** Said to the reader about what WAS served — e.g. one search word of two. */\n notices: string[]\n /**\n * The order asked for that the plan did not serve, and why: `alone` — it\n * is served only with no filter or search on; `range` — a range filter\n * leads the order with its own field. Absent when the asked order is served.\n */\n sortFallback?: { asked: ListQuerySort; reason: 'alone' | 'range' } | null\n}\n\n/** How one clause lands on a query, before it is composed with the others. */\ninterface ClauseShape {\n filters: ListQueryFilter[]\n /** The inequality field the clause needs to lead the order, if any. */\n inequality?: string\n /** The clause is the query's array clause. */\n array?: boolean\n /** `in` values, for the disjunction budget. */\n disjunctions?: number\n}\n\nconst csv = (raw: string): string[] =>\n raw\n .split(',')\n .map((entry) => entry.trim())\n .filter(Boolean)\n\nconst dayBounds = (raw: string): { start: Date; end: Date } | null => {\n const start = listFilterDay(raw)\n if (Number.isNaN(start.getTime())) return null\n const day = new Date(start)\n day.setHours(0, 0, 0, 0)\n const end = new Date(day)\n end.setDate(end.getDate() + 1)\n return { start: day, end }\n}\n\n/** The order a range over `path` puts the list in. */\nconst rangeOrder = (\n declaration: ListQueryDeclaration,\n field: ListFilterField | undefined,\n path: string,\n): ListQuerySort => {\n const offered = declaration.sorts.find((sort) => sort.path === path)\n if (offered) return offered\n return { path, direction: field?.kind === 'date' ? 'desc' : 'asc' }\n}\n\n/**\n * One clause as predicates, or the reason it has none. The same operator\n * meanings as the AGL-2501 twins (`applyListFilter`, `listFilterConstraints`),\n * which this replaces for a list that composes clauses.\n */\nfunction shapeClause(\n field: ListFilterField,\n input: ListFilterRequest,\n names: ListQueryNormalizers,\n): ClauseShape | string {\n if (field.windowOnly) return 'this field is not stored where a query can reach it'\n if (!listFilterOperators(field).includes(input.op)) {\n return `${input.op} is not something this list can ask of ${field.column}`\n }\n const raw = (input.value ?? '').trim()\n const op = input.op\n\n if (op === 'isEmpty') {\n if (field.presence !== 'nullable') return 'only a field stored as null can be asked for empty'\n return { filters: [{ path: field.path, op: '==', value: null }] }\n }\n if (op === 'isNotEmpty') {\n if (field.presence === 'always') return 'this field is never empty'\n return { filters: [{ path: field.path, op: '!=', value: null }], inequality: field.path }\n }\n if (field.kind === 'boolean') {\n if (raw !== 'true' && raw !== 'false') return 'pick true or false'\n return { filters: [{ path: field.path, op: '==', value: raw === 'true' }] }\n }\n if (!raw) return 'no value yet'\n\n if (field.keysOf) {\n if (op !== 'equals' || !/^[A-Za-z0-9_]+$/.test(raw)) return 'pick one of the choices'\n return { filters: [{ path: `${field.path}.${raw}`, op: '==', value: true }] }\n }\n\n if (field.kind === 'text') {\n if (op === 'contains' && field.tokensPath) {\n const token = field.verbatimTokens ? raw : names.token(raw)\n if (!token) return 'no value yet'\n return {\n filters: [{ path: field.tokensPath, op: 'array-contains', value: token }],\n array: true,\n }\n }\n if (op === 'equals' && field.lowerPath) {\n return { filters: [{ path: field.lowerPath, op: '==', value: names.key(raw) }] }\n }\n if (op === 'equals' && field.presence === 'always' && !field.lowerPath) {\n return { filters: [{ path: field.path, op: '==', value: raw }] }\n }\n if (op === 'startsWith' && field.lowerPath) {\n const key = names.key(raw)\n return {\n filters: [\n { path: field.lowerPath, op: '>=', value: key },\n { path: field.lowerPath, op: '<=', value: `${key}${HIGH}` },\n ],\n inequality: field.lowerPath,\n }\n }\n if (op === 'endsWith' && field.reversedPath) {\n const key = names.reversed(raw)\n return {\n filters: [\n { path: field.reversedPath, op: '>=', value: key },\n { path: field.reversedPath, op: '<=', value: `${key}${HIGH}` },\n ],\n inequality: field.reversedPath,\n }\n }\n if (op === 'isAnyOf' && field.lowerPath) {\n const values = csv(raw).map((value) => names.key(value))\n if (values.length > LIST_QUERY_DISJUNCTIONS) return `at most ${LIST_QUERY_DISJUNCTIONS} values`\n return {\n filters: [{ path: field.lowerPath, op: 'in', value: values }],\n disjunctions: values.length,\n }\n }\n return `${op} is not something this list can ask of ${field.column}`\n }\n\n if (field.kind === 'id') {\n if (op === 'equals') return { filters: [{ path: LIST_QUERY_ID_PATH, op: '==', value: raw }] }\n if (op === 'isAnyOf') {\n const values = csv(raw)\n if (values.length > LIST_QUERY_DISJUNCTIONS) return `at most ${LIST_QUERY_DISJUNCTIONS} values`\n return {\n filters: [{ path: LIST_QUERY_ID_PATH, op: 'in', value: values }],\n disjunctions: values.length,\n }\n }\n if (op === 'startsWith') {\n return {\n filters: [\n { path: LIST_QUERY_ID_PATH, op: '>=', value: raw },\n { path: LIST_QUERY_ID_PATH, op: '<=', value: `${raw}${HIGH}` },\n ],\n inequality: LIST_QUERY_ID_PATH,\n }\n }\n return `${op} is not something this list can ask of ${field.column}`\n }\n\n if (field.kind === 'exact') {\n if (op === 'equals') return { filters: [{ path: field.path, op: '==', value: raw }] }\n if (op === 'isAnyOf') {\n const values = csv(raw)\n if (values.length > LIST_QUERY_DISJUNCTIONS) return `at most ${LIST_QUERY_DISJUNCTIONS} values`\n if (field.tokensPath) {\n // An array field asked \"any of these\": one array clause.\n return {\n filters: [{ path: field.tokensPath, op: 'array-contains-any', value: values }],\n array: true,\n disjunctions: values.length,\n }\n }\n return {\n filters: [{ path: field.path, op: 'in', value: values }],\n disjunctions: values.length,\n }\n }\n if (op === 'contains' && field.tokensPath) {\n return {\n filters: [{ path: field.tokensPath, op: 'array-contains', value: raw }],\n array: true,\n }\n }\n return `${op} is not something this list can ask of ${field.column}`\n }\n\n if (field.kind === 'number') {\n const value = Number(raw)\n if (!Number.isFinite(value)) return 'type a number'\n if (op === '=') return { filters: [{ path: field.path, op: '==', value }] }\n const comparison: Record<string, ListQueryOp> = {\n '!=': '!=',\n '>': '>',\n '>=': '>=',\n '<': '<',\n '<=': '<=',\n }\n const found = comparison[op]\n if (!found) return `${op} is not something this list can ask of ${field.column}`\n return { filters: [{ path: field.path, op: found, value }], inequality: field.path }\n }\n\n if (field.kind === 'date') {\n const day = dayBounds(raw)\n if (!day) return 'pick a date'\n // A `…AtMs` field is compared as the number it is stored as.\n const at = (date: Date): Date | number =>\n field.storedAs === 'millis' ? date.getTime() : date\n if (op === 'is') {\n return {\n filters: [\n { path: field.path, op: '>=', value: at(day.start) },\n { path: field.path, op: '<', value: at(day.end) },\n ],\n inequality: field.path,\n }\n }\n const bound: Record<string, [ListQueryOp, Date]> = {\n after: ['>=', day.end],\n onOrAfter: ['>=', day.start],\n before: ['<', day.start],\n onOrBefore: ['<', day.end],\n }\n const found = bound[op]\n if (!found) return `${op} is not something this list can ask of ${field.column}`\n return { filters: [{ path: field.path, op: found[0], value: at(found[1]) }], inequality: field.path }\n }\n\n return `${op} is not something this list can ask of ${field.column}`\n}\n\nconst disjunctionsOf = (filter: ListQueryFilter): number =>\n filter.op === 'in' || filter.op === 'array-contains-any'\n ? Math.max(1, Array.isArray(filter.value) ? filter.value.length : 1)\n : 1\n\n/**\n * Every clause and the search, as ONE query — or as much of it as one query\n * can hold, with the rest refused by name.\n *\n * Order of claim: the base (the list's scope) first, then the search, then\n * the clauses in the order they were added. A clause that would be a second\n * array clause, a second inequality field or push the disjunctions past\n * thirty is refused, and the list shows the refusal beside its chip; the\n * clauses before it stand. The search is claimed before the clauses because\n * it is the thing a reader typed last and looks at.\n */\nexport function planListQuery(\n declaration: ListQueryDeclaration,\n request: ListQueryRequest,\n names: ListQueryNormalizers,\n): ListQueryPlan {\n const filters: ListQueryFilter[] = [...(request.base ?? [])]\n const served: ListFilterRequest[] = []\n const refused: ListQueryRefusal[] = []\n const notices: string[] = []\n let arrayTaken = filters.some(\n (filter) => filter.op === 'array-contains' || filter.op === 'array-contains-any',\n )\n let inequality: string | null =\n filters.find((filter) => ['!=', '<', '<=', '>', '>='].includes(filter.op))?.path ?? null\n let disjunctions = filters.reduce((product, filter) => product * disjunctionsOf(filter), 1)\n\n // The search.\n let searched: string | null = null\n const words = (request.search ?? []).map((word) => word.trim()).filter(Boolean)\n if (words.length) {\n const search = declaration.search\n const token = names.token(words.join(' '))\n if (!search) {\n refused.push({ clause: 'search', reason: 'this list has no search' })\n } else if (!token) {\n // Nothing searchable was typed.\n } else {\n const scopeAt = filters.findIndex(\n (filter) => filter.op === 'array-contains-any' || filter.op === 'array-contains',\n )\n if (scopeAt === -1) {\n filters.push({ path: search.tokensPath, op: 'array-contains', value: token })\n arrayTaken = true\n searched = token\n } else if (search.scoped) {\n // Fold the search into the scope: one array clause answers both.\n const scope = filters[scopeAt]\n const scopes = Array.isArray(scope.value) ? scope.value : [scope.value]\n filters.splice(scopeAt, 1, {\n path: search.scoped.tokensPath,\n op: 'array-contains-any',\n value: scopes.map((entry) => `${String(entry)}${search.scoped?.join}${token}`),\n })\n searched = token\n } else {\n refused.push({\n clause: 'search',\n reason: 'this list is already narrowed to what you can see, which search cannot combine with',\n })\n }\n if (searched && words.length > 1) {\n notices.push(\n `Search matches one word at a time: showing results for \"${token}\".`,\n )\n }\n if (searched && names.key(words[0]).length > names.maxPrefix) {\n notices.push(`Search reads the first ${names.maxPrefix} letters of a word.`)\n }\n }\n }\n\n // The clauses.\n for (const clause of request.clauses) {\n const field = declaration.fields.find((entry) => entry.column === clause.field)\n if (!field) {\n refused.push({ clause, reason: 'this list does not filter by that' })\n continue\n }\n const shape = shapeClause(field, clause, names)\n if (typeof shape === 'string') {\n refused.push({ clause, reason: shape })\n continue\n }\n if (shape.array && arrayTaken) {\n refused.push({\n clause,\n reason: searched\n ? 'cannot be combined with the search — clear the search to use it'\n : 'cannot be combined with another \"contains\" or \"any of\" filter on a list',\n })\n continue\n }\n if (shape.inequality && inequality && shape.inequality !== inequality) {\n refused.push({\n clause,\n reason: 'only one range (dates, numbers, starts with) can apply at a time',\n })\n continue\n }\n const product =\n disjunctions * shape.filters.reduce((total, filter) => total * disjunctionsOf(filter), 1)\n if (product > LIST_QUERY_DISJUNCTIONS) {\n refused.push({ clause, reason: `too many values at once (the limit is ${LIST_QUERY_DISJUNCTIONS})` })\n continue\n }\n filters.push(...shape.filters)\n served.push(clause)\n if (shape.array) arrayTaken = true\n if (shape.inequality) inequality = shape.inequality\n disjunctions = product\n }\n\n // The order.\n const declared = request.sort\n ? declaration.sorts.find(\n (sort) => sort.path === request.sort?.path && sort.direction === request.sort?.direction,\n )\n : undefined\n let sortFallback: ListQueryPlan['sortFallback'] = null\n let asked = declared\n // An `alone` order holds only while nothing narrows the list past its base.\n if (declared?.alone && (served.length > 0 || searched !== null)) {\n asked = defaultHeaderSort(declaration)\n sortFallback = { asked: declared, reason: 'alone' }\n notices.push(\n `Sorted by ${sortLabel(asked)}: ${sortLabel(declared)} sorts only with no filter or search on.`,\n )\n }\n // A range leads the order with the field it ranges over — in the asked\n // direction when the asked order IS that field, since a declared order has\n // its composites either way.\n const orderBy = inequality\n ? asked?.path === inequality\n ? asked\n : rangeOrder(\n declaration,\n declaration.fields.find(\n (field) =>\n field.path === inequality ||\n field.lowerPath === inequality ||\n field.reversedPath === inequality,\n ),\n inequality,\n )\n : (asked ?? declaration.sorts[0] ?? { path: LIST_QUERY_ID_PATH, direction: 'asc' })\n\n // A range took the order from a header the reader picked: say so. Not for\n // the default order, which nobody picked.\n if (\n !sortFallback &&\n declared &&\n declared !== declaration.sorts[0] &&\n declared !== defaultHeaderSort(declaration) &&\n orderBy.path !== declared.path\n ) {\n sortFallback = { asked: declared, reason: 'range' }\n const label = sortLabel(orderBy)\n notices.push(`Sorted by ${label}: a ${label} filter orders the list by it.`)\n }\n\n // Absent rather than null when the asked order was served, so a plan that\n // sorted as asked reads exactly as it did before AGL-3680 (the native twins\n // compare plans key by key).\n return {\n filters,\n orderBy,\n served,\n searched,\n refused,\n notices,\n ...(sortFallback ? { sortFallback } : {}),\n }\n}\n\n/** How an order reads in a notice. */\nconst sortLabel = (sort: ListQuerySort | undefined): string =>\n sort?.label ?? sort?.column ?? sort?.path ?? 'the default order'\n\n/**\n * The order an `alone` sort falls back to: the first header order that is\n * not itself `alone`, else the list's default. A fallback that could itself\n * fall back would leave the list in no order at all.\n */\nexport function defaultHeaderSort(declaration: ListQueryDeclaration): ListQuerySort {\n return (\n declaration.sorts.find((sort) => sort.column && !sort.alone) ??\n declaration.sorts.find((sort) => !sort.alone) ??\n { path: LIST_QUERY_ID_PATH, direction: 'asc' }\n )\n}\n\n/** A composite the plan's shapes need, in the index file's own terms. */\nexport interface ListQueryIndex {\n fields: Array<{ fieldPath: string; order?: 'ASCENDING' | 'DESCENDING'; arrayConfig?: 'CONTAINS' }>\n}\n\nconst ORDER = { asc: 'ASCENDING', desc: 'DESCENDING' } as const\n\n/**\n * Every composite a declaration's queries can need, under index merging:\n * one `(predicate field, order)` index per equality or array field and per\n * order the list can take — its sorts, and the order each range imposes.\n *\n * `base` names the scope predicates the list always applies (their paths\n * and whether they are array clauses), which need their own index per order\n * like any other equality. Pinned by each list's spec against\n * `cloud/firebase-firestore.indexes.json`.\n */\nexport function listQueryIndexes(\n declaration: ListQueryDeclaration,\n base: readonly { path: string; array?: boolean }[] = [],\n): ListQueryIndex[] {\n const equalities = new Map<string, boolean>() // path → is array clause\n // `alone` orders pair with the base only (AGL-3680); every other order —\n // and an `alone` one a range also imposes — with every equality.\n const orders: Array<ListQuerySort & { alone?: boolean }> = declaration.sorts.map((sort) => ({\n ...sort,\n }))\n const addOrder = (sort: ListQuerySort) => {\n const found = orders.find(\n (entry) => entry.path === sort.path && entry.direction === sort.direction,\n )\n if (found) found.alone = false\n else orders.push({ ...sort, alone: false })\n }\n const basePaths = new Set(base.map((entry) => entry.path))\n for (const entry of base) equalities.set(entry.path, Boolean(entry.array))\n if (declaration.search) {\n equalities.set(declaration.search.tokensPath, true)\n if (declaration.search.scoped) equalities.set(declaration.search.scoped.tokensPath, true)\n }\n for (const field of declaration.fields) {\n if (field.windowOnly) continue\n const ops = listFilterOperators(field)\n const has = (...names: string[]) => names.some((name) => ops.includes(name))\n if (field.keysOf) {\n for (const key of declaration.keys?.[field.column] ?? []) {\n equalities.set(`${field.path}.${key}`, false)\n }\n continue\n }\n if (field.kind === 'text') {\n if (has('contains') && field.tokensPath) equalities.set(field.tokensPath, true)\n if (has('equals', 'isAnyOf') && field.lowerPath) equalities.set(field.lowerPath, false)\n if (has('equals') && !field.lowerPath && field.presence === 'always') equalities.set(field.path, false)\n if (has('startsWith') && field.lowerPath) addOrder(rangeOrder(declaration, field, field.lowerPath))\n if (has('endsWith') && field.reversedPath) addOrder(rangeOrder(declaration, field, field.reversedPath))\n } else if (field.kind === 'exact') {\n if (has('equals', 'isAnyOf')) equalities.set(field.path, false)\n if (has('contains', 'isAnyOf') && field.tokensPath) equalities.set(field.tokensPath, true)\n } else if (field.kind === 'boolean') {\n equalities.set(field.path, false)\n } else if (field.kind === 'number') {\n if (has('=')) equalities.set(field.path, false)\n if (has('!=', '>', '>=', '<', '<=')) addOrder(rangeOrder(declaration, field, field.path))\n } else if (field.kind === 'date') {\n if (has('is', 'after', 'onOrAfter', 'before', 'onOrBefore')) {\n addOrder(rangeOrder(declaration, field, field.path))\n }\n }\n if (has('isEmpty')) equalities.set(field.path, false)\n if (has('isNotEmpty')) addOrder(rangeOrder(declaration, field, field.path))\n }\n const indexes: ListQueryIndex[] = []\n const seen = new Set<string>()\n for (const [path, array] of equalities) {\n for (const order of orders) {\n if (order.path === path || order.path === LIST_QUERY_ID_PATH) continue\n if (order.alone && !basePaths.has(path)) continue\n const index: ListQueryIndex = {\n fields: [\n array ? { fieldPath: path, arrayConfig: 'CONTAINS' } : { fieldPath: path, order: 'ASCENDING' },\n { fieldPath: order.path, order: ORDER[order.direction] },\n ],\n }\n const key = JSON.stringify(index)\n if (!seen.has(key)) {\n seen.add(key)\n indexes.push(index)\n }\n }\n }\n return indexes\n}\n\n/** An index entry as `cloud/firebase-firestore.indexes.json` stores it. */\ninterface IndexFileEntry {\n collectionGroup: string\n queryScope: string\n fields: Array<{ fieldPath: string; order?: string; arrayConfig?: string }>\n}\n\n/**\n * The composites a declaration needs that an index file does not hold — what\n * a list's spec asserts is empty, so a declared filter cannot ship without\n * the index that serves it.\n */\nexport function missingListQueryIndexes(\n file: { indexes: readonly IndexFileEntry[] },\n collectionGroup: string,\n needed: readonly ListQueryIndex[],\n queryScope: 'COLLECTION' | 'COLLECTION_GROUP' = 'COLLECTION',\n): ListQueryIndex[] {\n const shape = (fields: IndexFileEntry['fields']) =>\n fields\n .filter((field) => field.fieldPath !== LIST_QUERY_ID_PATH)\n .map((field) => `${field.fieldPath}:${field.order ?? field.arrayConfig}`)\n .join(',')\n const present = new Set(\n file.indexes\n .filter((index) => index.collectionGroup === collectionGroup && index.queryScope === queryScope)\n .map((index) => shape(index.fields)),\n )\n return needed.filter((index) => !present.has(shape(index.fields)))\n}\n"],"names":["listFilterDay","listFilterOperators","LIST_QUERY_ID_PATH","LIST_QUERY_DISJUNCTIONS","HIGH","csv","raw","split","map","entry","trim","filter","Boolean","dayBounds","start","Number","isNaN","getTime","day","Date","setHours","end","setDate","getDate","rangeOrder","declaration","field","path","offered","sorts","find","sort","direction","kind","shapeClause","input","names","windowOnly","includes","op","column","value","presence","filters","inequality","keysOf","test","tokensPath","token","verbatimTokens","array","lowerPath","key","reversedPath","reversed","values","length","disjunctions","isFinite","comparison","found","at","date","storedAs","bound","after","onOrAfter","before","onOrBefore","disjunctionsOf","Math","max","Array","isArray","planListQuery","request","asked","base","served","refused","notices","arrayTaken","some","reduce","product","searched","words","search","word","join","push","clause","reason","scopeAt","findIndex","scoped","scope","scopes","splice","String","maxPrefix","clauses","fields","shape","total","declared","undefined","sortFallback","alone","defaultHeaderSort","sortLabel","orderBy","label","ORDER","asc","desc","listQueryIndexes","equalities","Map","orders","addOrder","basePaths","Set","set","ops","has","name","keys","indexes","seen","order","index","fieldPath","arrayConfig","JSON","stringify","add","missingListQueryIndexes","file","collectionGroup","needed","queryScope","present"],"mappings":";AAAA;;;;;;;;;;;;;;;CAeC,GAED,SAGEA,aAAa,EACbC,mBAAmB,QACd,mBAAe;AAoGtB,gCAAgC,GAChC,OAAO,MAAMC,qBAAqB,WAAU;AAE5C,qFAAqF,GACrF,OAAO,MAAMC,0BAA0B,GAAE;AAEzC,wFAAwF,GACxF,MAAMC,OAAO;AA0Fb,MAAMC,MAAM,CAACC,MACXA,IACGC,KAAK,CAAC,KACNC,GAAG,CAAC,CAACC,QAAUA,MAAMC,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