@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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aglyn/shared-util-tools",
3
- "version": "1.0.0-beta.230",
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.230",
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,CAAC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OAAO,MAAMC,qBAAqB,CAACC,QACjC,CAAC,UAAU,EAAEA,MAAM,4EAA4E,CAAC,CAAA"}
@@ -0,0 +1,56 @@
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 ListFilterRequest } from './list-filter';
18
+ /**
19
+ * A Filters panel item, structurally: the fields of the data grid's
20
+ * `GridFilterItem` a codec reads and writes, so this module needs no grid.
21
+ */
22
+ export interface ListFilterPanelItem {
23
+ id?: number | string;
24
+ field: string;
25
+ operator: string;
26
+ value?: any;
27
+ }
28
+ /** One clause a list is narrowed by; `label` names a picked value on a chip. */
29
+ export interface ListFilterClause extends ListFilterRequest {
30
+ label?: string;
31
+ }
32
+ /** A choice for a field whose value is picked rather than typed. */
33
+ export interface ListFilterOption {
34
+ value: string;
35
+ label: string;
36
+ }
37
+ /** The grid operator each stored select operator shows as. */
38
+ export declare const SELECT_TO_GRID: Readonly<Record<string, string>>;
39
+ /** The stored operator each grid select operator saves as. */
40
+ export declare const SELECT_FROM_GRID: Readonly<Record<string, string>>;
41
+ /**
42
+ * How one field's stored clause and the panel's item translate. A field
43
+ * with choices uses {@link listSelectCodec}; a typed one,
44
+ * {@link listPlainCodec}. A list whose clauses predate the panel supplies
45
+ * its own.
46
+ */
47
+ export interface ListGridFilterCodec {
48
+ toItem: (clause: ListFilterClause) => Pick<ListFilterPanelItem, 'operator' | 'value'> | null;
49
+ toClause: (item: ListFilterPanelItem) => ListFilterClause | null;
50
+ }
51
+ /** The panel's item as a clause, through the grammar's one notion of "usable". */
52
+ export declare const plainClause: (item: ListFilterPanelItem) => ListFilterClause | null;
53
+ /** A typed field: the stored operator IS the grid's. */
54
+ export declare const listPlainCodec: ListGridFilterCodec;
55
+ /** A picked field: `equals` shows as `is`, and `isAnyOf` holds a comma list. */
56
+ export declare const listSelectCodec: ListGridFilterCodec;
@@ -0,0 +1,61 @@
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 { gridFilterRequests } from "./list-filter.js";
18
+ /** The grid operator each stored select operator shows as. */ export const SELECT_TO_GRID = {
19
+ equals: 'is',
20
+ doesNotEqual: 'not',
21
+ isAnyOf: 'isAnyOf'
22
+ };
23
+ /** The stored operator each grid select operator saves as. */ export const SELECT_FROM_GRID = {
24
+ is: 'equals',
25
+ not: 'doesNotEqual',
26
+ isAnyOf: 'isAnyOf'
27
+ };
28
+ /** The panel's item as a clause, through the grammar's one notion of "usable". */ export const plainClause = (item)=>{
29
+ var _gridFilterRequests_;
30
+ return (_gridFilterRequests_ = gridFilterRequests({
31
+ items: [
32
+ item
33
+ ]
34
+ })[0]) != null ? _gridFilterRequests_ : null;
35
+ };
36
+ /** A typed field: the stored operator IS the grid's. */ export const listPlainCodec = {
37
+ toItem: (clause)=>({
38
+ operator: clause.op,
39
+ value: clause.value === '' ? undefined : clause.value
40
+ }),
41
+ toClause: plainClause
42
+ };
43
+ /** A picked field: `equals` shows as `is`, and `isAnyOf` holds a comma list. */ export const listSelectCodec = {
44
+ toItem: (clause)=>{
45
+ const operator = SELECT_TO_GRID[clause.op];
46
+ if (!operator) return null;
47
+ return {
48
+ operator,
49
+ value: operator === 'isAnyOf' ? clause.value.split(',').map((entry)=>entry.trim()).filter(Boolean) : clause.value
50
+ };
51
+ },
52
+ toClause: (item)=>{
53
+ const op = SELECT_FROM_GRID[String(item.operator)];
54
+ const request = op ? plainClause(item) : null;
55
+ return request && op ? _extends({}, request, {
56
+ op
57
+ }) : null;
58
+ }
59
+ };
60
+
61
+ //# sourceMappingURL=list-filter-codecs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../../../../libs/shared/util/tools/src/lib/list-query/list-filter-codecs.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 { gridFilterRequests, type ListFilterRequest } from './list-filter'\n\n/*\n * The clause shapes and codecs of the grid filter grammar that need no grid:\n * what a list stores, and how a stored clause and a Filters panel item\n * translate. The web's data grid (`@aglyn/shared-ui-jsx/const/list-grid-filter`)\n * and a surface with no grid at all — the native app — read a list's\n * declaration through the same codecs.\n */\n\n/**\n * A Filters panel item, structurally: the fields of the data grid's\n * `GridFilterItem` a codec reads and writes, so this module needs no grid.\n */\nexport interface ListFilterPanelItem {\n id?: number | string\n field: string\n operator: string\n // The grid types a panel value as `any`; a codec narrows it.\n value?: any\n}\n\n/** One clause a list is narrowed by; `label` names a picked value on a chip. */\nexport interface ListFilterClause extends ListFilterRequest {\n label?: string\n}\n\n/** A choice for a field whose value is picked rather than typed. */\nexport interface ListFilterOption {\n value: string\n label: string\n}\n\n/** The grid operator each stored select operator shows as. */\nexport const SELECT_TO_GRID: Readonly<Record<string, string>> = {\n equals: 'is',\n doesNotEqual: 'not',\n isAnyOf: 'isAnyOf',\n}\n\n/** The stored operator each grid select operator saves as. */\nexport const SELECT_FROM_GRID: Readonly<Record<string, string>> = {\n is: 'equals',\n not: 'doesNotEqual',\n isAnyOf: 'isAnyOf',\n}\n\n/**\n * How one field's stored clause and the panel's item translate. A field\n * with choices uses {@link listSelectCodec}; a typed one,\n * {@link listPlainCodec}. A list whose clauses predate the panel supplies\n * its own.\n */\nexport interface ListGridFilterCodec {\n toItem: (clause: ListFilterClause) => Pick<ListFilterPanelItem, 'operator' | 'value'> | null\n toClause: (item: ListFilterPanelItem) => ListFilterClause | null\n}\n\n/** The panel's item as a clause, through the grammar's one notion of \"usable\". */\nexport const plainClause = (item: ListFilterPanelItem): ListFilterClause | null =>\n gridFilterRequests({ items: [item] })[0] ?? null\n\n/** A typed field: the stored operator IS the grid's. */\nexport const listPlainCodec: ListGridFilterCodec = {\n toItem: (clause) => ({\n operator: clause.op,\n value: clause.value === '' ? undefined : clause.value,\n }),\n toClause: plainClause,\n}\n\n/** A picked field: `equals` shows as `is`, and `isAnyOf` holds a comma list. */\nexport const listSelectCodec: ListGridFilterCodec = {\n toItem: (clause) => {\n const operator = SELECT_TO_GRID[clause.op]\n if (!operator) return null\n return {\n operator,\n value:\n operator === 'isAnyOf'\n ? clause.value.split(',').map((entry) => entry.trim()).filter(Boolean)\n : clause.value,\n }\n },\n toClause: (item) => {\n const op = SELECT_FROM_GRID[String(item.operator)]\n const request = op ? plainClause(item) : null\n return request && op ? { ...request, op } : null\n },\n}\n"],"names":["gridFilterRequests","SELECT_TO_GRID","equals","doesNotEqual","isAnyOf","SELECT_FROM_GRID","is","not","plainClause","item","items","listPlainCodec","toItem","clause","operator","op","value","undefined","toClause","listSelectCodec","split","map","entry","trim","filter","Boolean","String","request"],"mappings":";AAAA;;;;;;;;;;;;;;;CAeC,GAED,SAASA,kBAAkB,QAAgC,mBAAe;AAiC1E,4DAA4D,GAC5D,OAAO,MAAMC,iBAAmD;IAC9DC,QAAQ;IACRC,cAAc;IACdC,SAAS;AACX,EAAC;AAED,4DAA4D,GAC5D,OAAO,MAAMC,mBAAqD;IAChEC,IAAI;IACJC,KAAK;IACLH,SAAS;AACX,EAAC;AAaD,gFAAgF,GAChF,OAAO,MAAMI,cAAc,CAACC;QAC1BT;YAAAA,uBAAAA,mBAAmB;QAAEU,OAAO;YAACD;SAAK;IAAC,EAAE,CAAC,EAAE,YAAxCT,uBAA4C;EAAI;AAElD,sDAAsD,GACtD,OAAO,MAAMW,iBAAsC;IACjDC,QAAQ,CAACC,SAAY,CAAA;YACnBC,UAAUD,OAAOE,EAAE;YACnBC,OAAOH,OAAOG,KAAK,KAAK,KAAKC,YAAYJ,OAAOG,KAAK;QACvD,CAAA;IACAE,UAAUV;AACZ,EAAC;AAED,8EAA8E,GAC9E,OAAO,MAAMW,kBAAuC;IAClDP,QAAQ,CAACC;QACP,MAAMC,WAAWb,cAAc,CAACY,OAAOE,EAAE,CAAC;QAC1C,IAAI,CAACD,UAAU,OAAO;QACtB,OAAO;YACLA;YACAE,OACEF,aAAa,YACTD,OAAOG,KAAK,CAACI,KAAK,CAAC,KAAKC,GAAG,CAAC,CAACC,QAAUA,MAAMC,IAAI,IAAIC,MAAM,CAACC,WAC5DZ,OAAOG,KAAK;QACpB;IACF;IACAE,UAAU,CAACT;QACT,MAAMM,KAAKV,gBAAgB,CAACqB,OAAOjB,KAAKK,QAAQ,EAAE;QAClD,MAAMa,UAAUZ,KAAKP,YAAYC,QAAQ;QACzC,OAAOkB,WAAWZ,KAAK,aAAKY;YAASZ;aAAO;IAC9C;AACF,EAAC"}
@@ -0,0 +1,40 @@
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 { ListFilterField } from './list-filter';
18
+ import type { ListFilterClause, ListFilterOption } from './list-filter-codecs';
19
+ /**
20
+ * How an operator reads on a chip or in a sentence — "Owner is Dana",
21
+ * "Created on or after 1 Jan". One map so every list that shows its
22
+ * clauses back spells them the same way; an operator nothing here names
23
+ * is shown as itself rather than hidden.
24
+ */
25
+ export declare function listFilterOperatorLabel(op: string): string;
26
+ export declare const listFilterDay: (raw: string) => Date;
27
+ /**
28
+ * How a clause reads as a sentence — "Owner is Dana", "Created on or after
29
+ * 1 Jan", "Reason is any of Bounced, Complained": its header, its operator,
30
+ * and its value by the label of the option it names.
31
+ *
32
+ * ONE wording, used by the chips over a list and by the notices that say a
33
+ * clause was not applied (`listQueryRefusals`), so the two cannot describe
34
+ * the same clause differently.
35
+ */
36
+ export declare function listFilterClauseSentence(clause: ListFilterClause, context: {
37
+ fields: readonly ListFilterField[];
38
+ headers?: Readonly<Record<string, string>>;
39
+ options?: Readonly<Record<string, readonly ListFilterOption[]>>;
40
+ }): string;
@@ -0,0 +1,123 @@
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
+ * How a list's filter clauses read as words, for the chips over a list and
18
+ * the notices that say a clause was not applied (AGL-3321).
19
+ *
20
+ * ⛔ No `@mui/x-data-grid` here, and no runtime import of `list-filter` or
21
+ * `list-grid-filter`, which build the data grid's operators. The storefront's
22
+ * product grid shows these notices on customers' published pages, and
23
+ * reaching the grid's operators from here would ship the grid's filter
24
+ * inputs with every storefront page.
25
+ */ /**
26
+ * How an operator reads on a chip or in a sentence — "Owner is Dana",
27
+ * "Created on or after 1 Jan". One map so every list that shows its
28
+ * clauses back spells them the same way; an operator nothing here names
29
+ * is shown as itself rather than hidden.
30
+ */ export function listFilterOperatorLabel(op) {
31
+ switch(op){
32
+ case 'contains':
33
+ return 'contains';
34
+ case 'doesNotContain':
35
+ return 'does not contain';
36
+ case 'equals':
37
+ case 'is':
38
+ case '=':
39
+ return 'is';
40
+ case 'doesNotEqual':
41
+ case '!=':
42
+ return 'is not';
43
+ case 'startsWith':
44
+ return 'starts with';
45
+ case 'endsWith':
46
+ return 'ends with';
47
+ case 'isAnyOf':
48
+ return 'is any of';
49
+ case 'isEmpty':
50
+ return 'is empty';
51
+ case 'isNotEmpty':
52
+ return 'is set';
53
+ case 'after':
54
+ return 'after';
55
+ case 'onOrAfter':
56
+ return 'on or after';
57
+ case 'before':
58
+ return 'before';
59
+ case 'onOrBefore':
60
+ return 'on or before';
61
+ case '>':
62
+ return 'over';
63
+ case '>=':
64
+ return 'at least';
65
+ case '<':
66
+ return 'under';
67
+ case '<=':
68
+ return 'at most';
69
+ default:
70
+ return op;
71
+ }
72
+ }
73
+ /** Operators that carry no value. */ const VALUELESS_OPERATORS = new Set([
74
+ 'isEmpty',
75
+ 'isNotEmpty'
76
+ ]);
77
+ /** Operators that take several values, comma-joined the way the grammar splits them. */ const MULTI_OPERATORS = new Set([
78
+ 'isAnyOf'
79
+ ]);
80
+ /**
81
+ * The calendar day a date clause names, as a LOCAL date.
82
+ *
83
+ * The panel's date input holds a day, not an instant, and hands it over as
84
+ * `YYYY-MM-DD` — which `new Date` reads as UTC midnight, the previous
85
+ * evening anywhere west of UTC. Travelled through `toISOString`, the same
86
+ * day arrives as `YYYY-MM-DDT00:00:00.000Z`. Either spelling is read by its
87
+ * date parts, so "on or after Sep 17" starts on Sep 17 wherever the reader
88
+ * is. Any other value is an instant and is read as one. The query
89
+ * translators read a date clause through it too, so the day a query asks for
90
+ * is the day the rows are matched by.
91
+ */ const DAY_ONLY = /^(\d{4})-(\d{2})-(\d{2})(?:T00:00:00(?:\.000)?Z)?$/;
92
+ export const listFilterDay = (raw)=>{
93
+ const day = DAY_ONLY.exec(raw);
94
+ return day ? new Date(Number(day[1]), Number(day[2]) - 1, Number(day[3])) : new Date(raw);
95
+ };
96
+ /** A date clause's value as the day it names, read the way the query reads it. */ const dayLabel = (raw)=>{
97
+ const at = listFilterDay(raw);
98
+ return Number.isNaN(at.getTime()) ? raw : at.toLocaleDateString();
99
+ };
100
+ /**
101
+ * How a clause reads as a sentence — "Owner is Dana", "Created on or after
102
+ * 1 Jan", "Reason is any of Bounced, Complained": its header, its operator,
103
+ * and its value by the label of the option it names.
104
+ *
105
+ * ONE wording, used by the chips over a list and by the notices that say a
106
+ * clause was not applied (`listQueryRefusals`), so the two cannot describe
107
+ * the same clause differently.
108
+ */ export function listFilterClauseSentence(clause, context) {
109
+ var _ref, _clause_label;
110
+ var _context_headers, _context_options;
111
+ const field = context.fields.find((entry)=>entry.column === clause.field);
112
+ const header = (_ref = (_context_headers = context.headers) == null ? void 0 : _context_headers[clause.field]) != null ? _ref : clause.field;
113
+ const choices = (_context_options = context.options) == null ? void 0 : _context_options[clause.field];
114
+ const named = (value)=>{
115
+ var _ref;
116
+ var _choices_find;
117
+ return (_ref = choices == null ? void 0 : (_choices_find = choices.find((option)=>option.value === value)) == null ? void 0 : _choices_find.label) != null ? _ref : value;
118
+ };
119
+ const value = VALUELESS_OPERATORS.has(clause.op) ? '' : MULTI_OPERATORS.has(clause.op) ? clause.value.split(',').map((entry)=>entry.trim()).filter(Boolean).map(named).join(', ') : (_clause_label = clause.label) != null ? _clause_label : (field == null ? void 0 : field.kind) === 'date' ? dayLabel(clause.value) : named(clause.value);
120
+ return `${header} ${listFilterOperatorLabel(clause.op)}${value ? ` ${value}` : ''}`;
121
+ }
122
+
123
+ //# sourceMappingURL=list-filter-sentence.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../../../../libs/shared/util/tools/src/lib/list-query/list-filter-sentence.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 { ListFilterField } from './list-filter'\nimport type { ListFilterClause, ListFilterOption } from './list-filter-codecs'\n\n/*\n * How a list's filter clauses read as words, for the chips over a list and\n * the notices that say a clause was not applied (AGL-3321).\n *\n * ⛔ No `@mui/x-data-grid` here, and no runtime import of `list-filter` or\n * `list-grid-filter`, which build the data grid's operators. The storefront's\n * product grid shows these notices on customers' published pages, and\n * reaching the grid's operators from here would ship the grid's filter\n * inputs with every storefront page.\n */\n\n/**\n * How an operator reads on a chip or in a sentence — \"Owner is Dana\",\n * \"Created on or after 1 Jan\". One map so every list that shows its\n * clauses back spells them the same way; an operator nothing here names\n * is shown as itself rather than hidden.\n */\nexport function listFilterOperatorLabel(op: string): string {\n switch (op) {\n case 'contains':\n return 'contains'\n case 'doesNotContain':\n return 'does not contain'\n case 'equals':\n case 'is':\n case '=':\n return 'is'\n case 'doesNotEqual':\n case '!=':\n return 'is not'\n case 'startsWith':\n return 'starts with'\n case 'endsWith':\n return 'ends with'\n case 'isAnyOf':\n return 'is any of'\n case 'isEmpty':\n return 'is empty'\n case 'isNotEmpty':\n return 'is set'\n case 'after':\n return 'after'\n case 'onOrAfter':\n return 'on or after'\n case 'before':\n return 'before'\n case 'onOrBefore':\n return 'on or before'\n case '>':\n return 'over'\n case '>=':\n return 'at least'\n case '<':\n return 'under'\n case '<=':\n return 'at most'\n default:\n return op\n }\n}\n\n/** Operators that carry no value. */\nconst VALUELESS_OPERATORS = new Set(['isEmpty', 'isNotEmpty'])\n/** Operators that take several values, comma-joined the way the grammar splits them. */\nconst MULTI_OPERATORS = new Set(['isAnyOf'])\n\n/**\n * The calendar day a date clause names, as a LOCAL date.\n *\n * The panel's date input holds a day, not an instant, and hands it over as\n * `YYYY-MM-DD` — which `new Date` reads as UTC midnight, the previous\n * evening anywhere west of UTC. Travelled through `toISOString`, the same\n * day arrives as `YYYY-MM-DDT00:00:00.000Z`. Either spelling is read by its\n * date parts, so \"on or after Sep 17\" starts on Sep 17 wherever the reader\n * is. Any other value is an instant and is read as one. The query\n * translators read a date clause through it too, so the day a query asks for\n * is the day the rows are matched by.\n */\nconst DAY_ONLY = /^(\\d{4})-(\\d{2})-(\\d{2})(?:T00:00:00(?:\\.000)?Z)?$/\nexport const listFilterDay = (raw: string): Date => {\n const day = DAY_ONLY.exec(raw)\n return day ? new Date(Number(day[1]), Number(day[2]) - 1, Number(day[3])) : new Date(raw)\n}\n\n/** A date clause's value as the day it names, read the way the query reads it. */\nconst dayLabel = (raw: string): string => {\n const at = listFilterDay(raw)\n return Number.isNaN(at.getTime()) ? raw : at.toLocaleDateString()\n}\n\n/**\n * How a clause reads as a sentence — \"Owner is Dana\", \"Created on or after\n * 1 Jan\", \"Reason is any of Bounced, Complained\": its header, its operator,\n * and its value by the label of the option it names.\n *\n * ONE wording, used by the chips over a list and by the notices that say a\n * clause was not applied (`listQueryRefusals`), so the two cannot describe\n * the same clause differently.\n */\nexport function listFilterClauseSentence(\n clause: ListFilterClause,\n context: {\n fields: readonly ListFilterField[]\n headers?: Readonly<Record<string, string>>\n options?: Readonly<Record<string, readonly ListFilterOption[]>>\n },\n): string {\n const field = context.fields.find((entry) => entry.column === clause.field)\n const header = context.headers?.[clause.field] ?? clause.field\n const choices = context.options?.[clause.field]\n const named = (value: string) =>\n choices?.find((option) => option.value === value)?.label ?? value\n const value = VALUELESS_OPERATORS.has(clause.op)\n ? ''\n : MULTI_OPERATORS.has(clause.op)\n ? clause.value\n .split(',')\n .map((entry) => entry.trim())\n .filter(Boolean)\n .map(named)\n .join(', ')\n : clause.label ?? (field?.kind === 'date' ? dayLabel(clause.value) : named(clause.value))\n return `${header} ${listFilterOperatorLabel(clause.op)}${value ? ` ${value}` : ''}`\n}\n"],"names":["listFilterOperatorLabel","op","VALUELESS_OPERATORS","Set","MULTI_OPERATORS","DAY_ONLY","listFilterDay","raw","day","exec","Date","Number","dayLabel","at","isNaN","getTime","toLocaleDateString","listFilterClauseSentence","clause","context","field","fields","find","entry","column","header","headers","choices","options","named","value","option","label","has","split","map","trim","filter","Boolean","join","kind"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAKD;;;;;;;;;CASC,GAED;;;;;CAKC,GACD,OAAO,SAASA,wBAAwBC,EAAU;IAChD,OAAQA;QACN,KAAK;YACH,OAAO;QACT,KAAK;YACH,OAAO;QACT,KAAK;QACL,KAAK;QACL,KAAK;YACH,OAAO;QACT,KAAK;QACL,KAAK;YACH,OAAO;QACT,KAAK;YACH,OAAO;QACT,KAAK;YACH,OAAO;QACT,KAAK;YACH,OAAO;QACT,KAAK;YACH,OAAO;QACT,KAAK;YACH,OAAO;QACT,KAAK;YACH,OAAO;QACT,KAAK;YACH,OAAO;QACT,KAAK;YACH,OAAO;QACT,KAAK;YACH,OAAO;QACT,KAAK;YACH,OAAO;QACT,KAAK;YACH,OAAO;QACT,KAAK;YACH,OAAO;QACT,KAAK;YACH,OAAO;QACT;YACE,OAAOA;IACX;AACF;AAEA,mCAAmC,GACnC,MAAMC,sBAAsB,IAAIC,IAAI;IAAC;IAAW;CAAa;AAC7D,sFAAsF,GACtF,M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