viewkitjs 0.19.0 → 0.20.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (85) hide show
  1. package/CHANGELOG.md +49 -0
  2. package/MIGRATION.md +116 -0
  3. package/README.md +7 -3
  4. package/fields/README.md +3 -3
  5. package/fields/dist/derived.d.ts +4 -0
  6. package/fields/dist/derived.js +39 -0
  7. package/fields/dist/entities.js +30 -30
  8. package/fields/dist/formula.js +2 -2
  9. package/fields/dist/query/evaluate.js +5 -5
  10. package/fields/dist/query/figures.js +5 -5
  11. package/fields/dist/query/filter.d.ts +15 -0
  12. package/fields/dist/query/filter.js +85 -0
  13. package/fields/dist/query/hold.js +2 -2
  14. package/fields/dist/query/option-counts.js +2 -2
  15. package/fields/dist/query/read-rule.js +2 -2
  16. package/fields/dist/query/search.js +2 -2
  17. package/fields/dist/query/set-aside.js +4 -4
  18. package/fields/dist/query/settings.d.ts +2 -15
  19. package/fields/dist/query/settings.js +3 -81
  20. package/fields/dist/query/sort.js +4 -4
  21. package/fields/dist/registry.d.ts +19 -5
  22. package/fields/dist/registry.js +371 -50
  23. package/fields/dist/types.d.ts +1 -1
  24. package/fields/docs/getting-started.md +2 -2
  25. package/fields/docs/guides/checking-definitions.md +17 -4
  26. package/fields/docs/guides/derived-fields.md +5 -5
  27. package/fields/docs/guides/queries.md +1 -1
  28. package/fields/docs/reference/design-category-colors.md +1 -1
  29. package/fields/docs/reference/design-status-slots.md +1 -1
  30. package/fields/docs/reference/fields.md +3 -3
  31. package/fields/docs/reference/query.md +1 -0
  32. package/fields/skills/viewkit/SKILL.md +2 -2
  33. package/package.json +13 -6
  34. package/postgres/README.md +2 -2
  35. package/postgres/dist/access.d.ts +12 -4
  36. package/postgres/dist/access.js +3 -0
  37. package/postgres/dist/calendar.js +3 -2
  38. package/postgres/dist/check.d.ts +6 -4
  39. package/postgres/dist/check.js +27 -16
  40. package/postgres/dist/counts.js +3 -2
  41. package/postgres/dist/definitions/build.js +7 -0
  42. package/postgres/dist/definitions/formula.d.ts +1 -1
  43. package/postgres/dist/definitions/formula.js +5 -3
  44. package/postgres/dist/definitions/lookup.js +5 -1
  45. package/postgres/dist/definitions/money.js +6 -1
  46. package/postgres/dist/definitions/place.d.ts +7 -0
  47. package/postgres/dist/definitions/place.js +8 -0
  48. package/postgres/dist/definitions/relations.js +36 -3
  49. package/postgres/dist/definitions/rollup.d.ts +1 -1
  50. package/postgres/dist/definitions/rollup.js +11 -6
  51. package/postgres/dist/field-values.js +11 -8
  52. package/postgres/dist/figures.js +4 -2
  53. package/postgres/dist/filled.js +2 -2
  54. package/postgres/dist/groups.d.ts +2 -1
  55. package/postgres/dist/groups.js +5 -3
  56. package/postgres/dist/index.d.ts +1 -0
  57. package/postgres/dist/index.js +1 -0
  58. package/postgres/dist/kept.js +8 -4
  59. package/postgres/dist/lanes.js +5 -3
  60. package/postgres/dist/phone.js +2 -2
  61. package/postgres/dist/predicates.js +2 -2
  62. package/postgres/dist/readable.d.ts +40 -0
  63. package/postgres/dist/readable.js +84 -0
  64. package/postgres/dist/records.js +7 -4
  65. package/postgres/dist/refusals.d.ts +8 -1
  66. package/postgres/dist/refusals.js +7 -0
  67. package/postgres/dist/relations.js +5 -4
  68. package/postgres/dist/search-indexes.js +2 -1
  69. package/postgres/dist/search.js +6 -4
  70. package/postgres/dist/several.js +8 -8
  71. package/postgres/dist/sort.d.ts +5 -3
  72. package/postgres/dist/sort.js +13 -8
  73. package/postgres/dist/value-rows.js +2 -2
  74. package/postgres/dist/values.js +4 -2
  75. package/postgres/docs/guides/definitions.md +2 -2
  76. package/postgres/docs/guides/field-map.md +43 -18
  77. package/postgres/docs/guides/test-kit.md +2 -0
  78. package/postgres/docs/reference/postgres.md +10 -4
  79. package/views/README.md +3 -2
  80. package/views/dist/styles.css +3165 -0
  81. package/views/dist/styles.unlayered.css +3164 -0
  82. package/views/docs/contract.md +13 -7
  83. package/views/docs/getting-started.md +1 -1
  84. package/views/docs/guides/the-grid.md +1 -1
  85. package/views/docs/install.md +35 -8
package/CHANGELOG.md CHANGED
@@ -5,6 +5,55 @@ Until 0.19.0 ViewKit shipped as three packages; their changes are in [fields/CHA
5
5
 
6
6
  ## [Unreleased]
7
7
 
8
+ ## [0.20.0] — 2026-11-25
9
+
10
+ ### Added
11
+
12
+ - `viewkitjs/postgres`: a request's `readable`, the fields its reader may read: per table of the map a list of field keys, or `EVERY_FIELD` for every field of that table; or `EVERY_FIELD` alone for every field of every table. Types `Readable` and `EveryField`.
13
+ - `viewkitjs/postgres`: the refusal codes `no-field-list` (`readable: no list of the fields the reader may read; hand one in, or EVERY_FIELD when the reader may read every field`, or `readable.<table>: …` for a table a read reaches that the list leaves out), `not-a-field-list` (`readable.<table>: a table's readable fields are a list of field keys, or EVERY_FIELD`) and `hidden-field` (`fields.<key>: this reader may not read <key>`, `tables.<table>.fields.<key>: …` for a far field, and `…, which reads <place>` for a field worked out from a hidden one). No message carries a value.
14
+ - `MIGRATION.md`: the move from `@viewkitjs/fields`, `@viewkitjs/views` and `@viewkitjs/postgres` to `viewkitjs`, written out: the install, every old import path beside its new one, the `declare module "viewkitjs/fields/types"` augmentation and the Tailwind `@source` line. The README's new section, "Coming from `@viewkitjs/fields`, `@viewkitjs/views` or `@viewkitjs/postgres`", links it.
15
+ - `viewkitjs/views/styles.css`: the views part's whole look as one stylesheet, with no Tailwind and no `@source` needed. `@import "viewkitjs/views/styles.css";` anywhere among your imports. Its defaults are the Outright look, light, and dark under `.dark` or `[data-theme="dark"]`; declare any `--vk-*` colour to wear your own. Its rules sit in `components › viewkit` and the file opens with Tailwind's layer order (`theme, base, components, utilities`), so your own components rules and utilities win over ViewKit's whatever the order you import things in. The reset it carries (Tailwind's preflight) touches only ViewKit's elements and what you draw inside them, from `base › viewkit`, under your own base styles. Three fills keep the Outright look for now, with no name to set: the success, warning and information soft fills, the text on those filled statuses and on a filled error, and a category chip's fill.
16
+ - `viewkitjs/views/styles.unlayered.css`: the same look outside any layer, for an app whose reset or styles sit in no layer (Tailwind 3, a plain CSS reset), whose unlayered preflight would beat any layer.
17
+
18
+ ### Changed
19
+
20
+ - `viewkitjs/postgres`: every request hands in `readable`. A request without it is refused as `no-field-list`, as a table with no condition is refused as `no-condition`.
21
+
22
+ ```ts
23
+ // before
24
+ pageQuery({ map, access, sorts, size: 50 });
25
+ // after: a reader with no field rules
26
+ pageQuery({ map, access, readable: EVERY_FIELD, sorts, size: 50 });
27
+ // after: a reader who may not read a company's revenue
28
+ pageQuery({ map, access, readable: { deals: ["title", "stage", "company"], companies: ["name"] }, sorts, size: 50 });
29
+ ```
30
+
31
+ - `viewkitjs/postgres`: a request naming a field its reader may not read, in a filter (a rule set aside or still being typed too), a hold, a sort, a group, a board, a calendar, a count, figures, a search or a read of values, is refused as `hidden-field` before any SQL is written. A far field is held by its own table's list; a lookup, a rollup, a formula, an amount that converts and a relation pointing back are readable only when every field they read is, and a relation through a link kind whose end is a link field's column reads that field, so the link table then needs a list. A table's label is no field: hiding a table's name field doesn't hide its label.
32
+ - `viewkitjs/postgres`: a request type that leaves `map` and `access` to your server (`Omit<KeysRequest, "map" | "access">`) leaves out `readable` too; set it on the server beside `access`, after spreading what the client sent, never from it.
33
+ - `viewkitjs/fields`: `defineFields` and `contributeFields` refuse a formula that names a SQL function unless you pass `allowSql: true`, as `checkFieldSpec` already did. A registry written in code that names one adds the flag:
34
+
35
+ ```ts
36
+ // before
37
+ defineFields({ entity: "campaign", identity: "name", fields: { lastReply: { type: "formula", rule: { sql: "app.last_reply" }, … } } });
38
+ // after
39
+ defineFields({ entity: "campaign", identity: "name", allowSql: true, fields: { lastReply: { type: "formula", rule: { sql: "app.last_reply" }, … } } });
40
+ ```
41
+
42
+ - `viewkitjs/fields`: every definition is checked for its shape before its rules, by `checkFieldSpec` and so by `defineFields` and `contributeFields` too: a key its type doesn't declare, a value of the wrong kind, a blank label, a missing required setting or a definition nested deeper than 408 levels is refused with a `FieldDefinitionError` that names it, such as `fields: "title": "colour" is not a setting of a text field`. TypeScript does not flag an unknown key inside `defineFields`, so a registry that carried one now fails where it loads: remove the key. A field reused from another registry may keep the stamps it carries there.
43
+ - `viewkitjs/fields`: `defineFields` and `contributeFields` drop a definition's own `identity`, `avatar`, `rename` and `subtitleThrough` before they stamp it, so a field reused from another registry, or read from data, never becomes a second identity, picture or rename.
44
+ - `viewkitjs/fields`: `checkFieldSpec` takes `unknown` and asserts `FieldSpec`, so a definition read from a row needs no cast.
45
+ - `viewkitjs/fields/types`: `FieldSpec` no longer holds `avatar`, which `defineFields({ avatar })` stamps.
46
+ - `sideEffects` is `["**/*.css"]`, so a bundler keeps a stylesheet import.
47
+ - Nothing changes for an app that doesn't import the stylesheet: one on `@source` with its own `--vk-*` mapping draws exactly as before.
48
+ - `viewkitjs/views/styles.css`: until each piece moves to classes of its own, the stylesheet carries ViewKit's classes under Tailwind's names (`h-8`, `rounded-md`). Where your own Tailwind writes a class of the same name, your rule wins on ViewKit's element too: a stock Tailwind app that uses `rounded-md` itself draws ViewKit's corners at 6px, not the Outright look's 7.5px.
49
+
50
+ ### Fixed
51
+
52
+ - `viewkitjs/fields`: a malformed definition read from data — an option that is `null`, a currency with no code, a relation with no relation, a filter thousands of levels deep — is refused with a `FieldDefinitionError`, where it threw a `TypeError` or overflowed the stack.
53
+ - `viewkitjs/fields/query`: a sort, a filter or a group on `constructor`, `__proto__` or `toString` is ignored as an unknown field, whatever your `fieldOf` answers for it; it threw `build is not a function`.
54
+ - `viewkitjs/fields`: no key an object inherits counts as a field a definition names: an identity, a formula's field, a lookup's relation or far field, a rollup's relation, a relation's kind.
55
+ - The getting-started guide's `fieldOf` asks `Object.hasOwn(REGISTRY, key)`; if you copied its `key in REGISTRY`, change yours the same way.
56
+
8
57
  ## [0.19.0] — 2026-11-24
9
58
 
10
59
  ViewKit is one package. `viewkitjs` replaces `@viewkitjs/fields` 0.18.0, `@viewkitjs/views` 0.15.0 and
package/MIGRATION.md ADDED
@@ -0,0 +1,116 @@
1
+ # From `@viewkitjs/fields`, `@viewkitjs/views` and `@viewkitjs/postgres` to `viewkitjs`
2
+
3
+ Since 0.19.0, ViewKit is one package, `viewkitjs`. The three packages it replaces stopped at their last
4
+ versions (`@viewkitjs/fields` 0.18.0, `@viewkitjs/views` 0.15.0, `@viewkitjs/postgres` 0.12.0): they keep
5
+ working where they are installed and receive nothing new.
6
+
7
+ Every name they exported is exported from the same entry of `viewkitjs`, and each entry's new path is its old
8
+ one with `@viewkitjs/` replaced by `viewkitjs/`. So the move is one install and one find-and-replace. This page
9
+ is that replacement written out, every path beside its new one, for when you want to check one.
10
+
11
+ This page maps the names. What the code behaves like in each version is in the changelog: an app coming
12
+ from an older version of the three packages reads, in `CHANGELOG.md`, the notes of every version between
13
+ its own and the one it installs.
14
+
15
+ ## Install
16
+
17
+ Remove the three packages and add the one:
18
+
19
+ ```sh
20
+ pnpm remove @viewkitjs/fields @viewkitjs/views @viewkitjs/postgres
21
+ pnpm add viewkitjs
22
+ ```
23
+
24
+ `zod` `^4.1.12` stays a peer. `react` and `react-dom` 19, and the three `@dnd-kit` packages the panels drag
25
+ with, are optional peers, needed only by `viewkitjs/views/*`: an app that uses only fields or postgres
26
+ installs none of them.
27
+
28
+ ## Every import path
29
+
30
+ | Old | New |
31
+ | --- | --- |
32
+ | `@viewkitjs/fields` | `viewkitjs/fields` |
33
+ | `@viewkitjs/fields/types` | `viewkitjs/fields/types` |
34
+ | `@viewkitjs/fields/query` | `viewkitjs/fields/query` |
35
+ | `@viewkitjs/fields/definitions` | `viewkitjs/fields/definitions` |
36
+ | `@viewkitjs/fields/design/status-slots` | `viewkitjs/fields/design/status-slots` |
37
+ | `@viewkitjs/fields/design/stage-marks` | `viewkitjs/fields/design/stage-marks` |
38
+ | `@viewkitjs/fields/design/category-colors` | `viewkitjs/fields/design/category-colors` |
39
+ | `@viewkitjs/fields/format/time` | `viewkitjs/fields/format/time` |
40
+ | `@viewkitjs/fields/phone` | `viewkitjs/fields/phone` |
41
+ | `@viewkitjs/fields/places` | `viewkitjs/fields/places` |
42
+ | `@viewkitjs/fields/root-domain` | `viewkitjs/fields/root-domain` |
43
+ | `@viewkitjs/fields/testing` | `viewkitjs/fields/testing` |
44
+ | `@viewkitjs/views` | `viewkitjs/views` |
45
+ | `@viewkitjs/views/react` | `viewkitjs/views/react` |
46
+ | `@viewkitjs/views/display` | `viewkitjs/views/display` |
47
+ | `@viewkitjs/views/editors` | `viewkitjs/views/editors` |
48
+ | `@viewkitjs/views/editors/select` | `viewkitjs/views/editors/select` |
49
+ | `@viewkitjs/views/editors/text` | `viewkitjs/views/editors/text` |
50
+ | `@viewkitjs/views/editors/relation` | `viewkitjs/views/editors/relation` |
51
+ | `@viewkitjs/views/editors/number` | `viewkitjs/views/editors/number` |
52
+ | `@viewkitjs/views/editors/range` | `viewkitjs/views/editors/range` |
53
+ | `@viewkitjs/views/editors/name` | `viewkitjs/views/editors/name` |
54
+ | `@viewkitjs/views/editors/location` | `viewkitjs/views/editors/location` |
55
+ | `@viewkitjs/views/editors/value-list` | `viewkitjs/views/editors/value-list` |
56
+ | `@viewkitjs/views/editors/date` | `viewkitjs/views/editors/date` |
57
+ | `@viewkitjs/views/editors/chips` | `viewkitjs/views/editors/chips` |
58
+ | `@viewkitjs/views/editors/session` | `viewkitjs/views/editors/session` |
59
+ | `@viewkitjs/views/editors/panel` | `viewkitjs/views/editors/panel` |
60
+ | `@viewkitjs/views/editors/open-values` | `viewkitjs/views/editors/open-values` |
61
+ | `@viewkitjs/views/field-row` | `viewkitjs/views/field-row` |
62
+ | `@viewkitjs/views/cells` | `viewkitjs/views/cells` |
63
+ | `@viewkitjs/views/selection` | `viewkitjs/views/selection` |
64
+ | `@viewkitjs/views/grid` | `viewkitjs/views/grid` |
65
+ | `@viewkitjs/views/panels` | `viewkitjs/views/panels` |
66
+ | `@viewkitjs/views/panels/react` | `viewkitjs/views/panels/react` |
67
+ | `@viewkitjs/postgres` | `viewkitjs/postgres` |
68
+ | `@viewkitjs/postgres/definitions` | `viewkitjs/postgres/definitions` |
69
+
70
+ There is no `viewkitjs` entry on its own: every path names its part. The three `package.json` entries move the
71
+ same way (`@viewkitjs/fields/package.json` is `viewkitjs/package.json`, one manifest for all three parts).
72
+
73
+ ## The names your app narrows
74
+
75
+ An app that narrows ViewKit's names (its entities, fields and kinds) augments the types entry. The block's
76
+ module name moves like an import:
77
+
78
+ ```ts
79
+ // before
80
+ declare module "@viewkitjs/fields/types" {
81
+ // …your interfaces, unchanged
82
+ }
83
+
84
+ // after
85
+ declare module "viewkitjs/fields/types" {
86
+ // …your interfaces, unchanged
87
+ }
88
+ ```
89
+
90
+ Change it in the same pass as the imports. TypeScript reports no error for an augmentation of a module that is
91
+ no longer installed: the block stops applying, and every name it narrowed widens back to `string` in silence.
92
+ The fields part's guide `fields/docs/guides/narrowing-names.md` shows the whole block.
93
+
94
+ ## The views part's look
95
+
96
+ An app that lets its own Tailwind 4 compile the views part points the `@source` line at the new folder, the
97
+ path relative to the stylesheet it sits in:
98
+
99
+ | Old | New |
100
+ | --- | --- |
101
+ | `@source "../../node_modules/@viewkitjs/views";` | `@source "../../node_modules/viewkitjs/views";` |
102
+ | `@source "../../node_modules/@viewkitjs/views/dist";` | `@source "../../node_modules/viewkitjs/views/dist";` |
103
+
104
+ A line still on the old folder finds nothing once the old package is removed, and the grid draws unstyled.
105
+
106
+ From 0.20.0 the views part also ships its look as a ready stylesheet, which needs neither Tailwind nor the
107
+ `@source` line: `@import "viewkitjs/views/styles.css";`. The views part's install page,
108
+ `views/docs/install.md`, has both ways and the colours.
109
+
110
+ ## Check you're done
111
+
112
+ After the replacement, nothing in your code, styles or manifest names `@viewkitjs/`:
113
+
114
+ ```sh
115
+ git grep -n "@viewkitjs/" -- ':!*lock*'
116
+ ```
package/README.md CHANGED
@@ -24,13 +24,17 @@ Fields and postgres load no React. A Node script, a worker or a route handler im
24
24
 
25
25
  ## Styles
26
26
 
27
- The views part draws with Tailwind classes. With Tailwind 4, one line in the stylesheet that imports Tailwind lets it see them (the path is relative to that stylesheet):
27
+ One line gives the views part its whole look, its defaults the Outright look, with no Tailwind needed:
28
28
 
29
29
  ```css
30
- @source "../node_modules/viewkitjs/views";
30
+ @import "viewkitjs/views/styles.css";
31
31
  ```
32
32
 
33
- The colours and the rest of the install are in [views' install page](views/docs/install.md).
33
+ [Views' install page](views/docs/install.md) has the rest: the unlayered twin for an app whose reset sits in no layer, the `@source` line that lets your own Tailwind compile the look instead, and your own colours.
34
+
35
+ ## Coming from `@viewkitjs/fields`, `@viewkitjs/views` or `@viewkitjs/postgres`
36
+
37
+ Those three packages are now this one, and they receive nothing new. Install `viewkitjs` in their place and replace `@viewkitjs/` with `viewkitjs/` in every import, `declare module` and `@source` line. [MIGRATION.md](MIGRATION.md) lists every old path beside its new one.
34
38
 
35
39
  ## Changes
36
40
 
package/fields/README.md CHANGED
@@ -64,8 +64,8 @@ const { rows } = evaluateView(
64
64
  group: null,
65
65
  },
66
66
  {
67
- // A key the registry does not know is skipped, never an error.
68
- fieldOf: (key) => (key in DEAL_FIELDS ? DEAL_FIELDS[key as DealKey] : undefined),
67
+ // A key the registry does not hold — constructor or toString included — is skipped, never an error.
68
+ fieldOf: (key) => (Object.hasOwn(DEAL_FIELDS, key) ? DEAL_FIELDS[key as DealKey] : undefined),
69
69
  read: (deal, key) => deal[key as keyof Deal],
70
70
  },
71
71
  { conventions }
@@ -113,7 +113,7 @@ References, one per entry point, each naming every export: [`viewkitjs/fields`](
113
113
  | `viewkitjs/fields` | Definitions, registries, conventions, validation, acceptance, codecs, relation helpers, the field kit |
114
114
  | `viewkitjs/fields/query` | Filters, sorts, grouping, `evaluateView`, the query kit |
115
115
  | `viewkitjs/fields/types` | The types, for module augmentation — narrowing entity, relation and provider names to your own |
116
- | `viewkitjs/fields/design/status-slots`, `/design/stage-marks`, `/design/category-colors`, `/format/time` | Presentation leaves: Tailwind class names keyed by semantic slot, and duration and time formatting. Your stylesheet defines the tokens |
116
+ | `viewkitjs/fields/design/status-slots`, `/design/stage-marks`, `/design/category-colors`, `/format/time` | Presentation leaves: Tailwind class names keyed by semantic slot, and duration and time formatting. Your stylesheet defines the tokens, or `viewkitjs/views/styles.css` draws them in the Outright look |
117
117
  | `viewkitjs/fields/phone` | A phone read, written and dialled (`parsePhone`, `readPhone`, `phoneText`, `phoneHref`…), without the rest of the entry |
118
118
  | `viewkitjs/fields/places` | A country's regions with their ISO 3166-2 codes (`loadRegions`, `regionLabel`), one country at a time, loaded when asked for |
119
119
  | `viewkitjs/fields/root-domain` | A domain's root domain (`rootDomain`: `shop.acme.ro` → `acme.ro`), read with the Public Suffix List, which only this entry carries |
@@ -82,3 +82,7 @@ export declare function isIntegerField(field: FieldDef): boolean;
82
82
  * It writes NO sentence: a definition holds data, and the reason is produced by
83
83
  * `lockReason(originalField, cv)` when someone asks for it. */
84
84
  export declare function presentedDef(field: FieldDef): FieldDef;
85
+ /** The value `map` holds under `key` as its own key, when it is a non-null object; else undefined. Internal. */
86
+ export declare function ownField<T extends object>(map: Readonly<Record<string, T>> | undefined, key: unknown): T | undefined;
87
+ /** `field` when it is a non-null object whose own `type` is a field type; else undefined. Internal. */
88
+ export declare function knownField(field: unknown): FieldDef | undefined;
@@ -124,3 +124,42 @@ export function presentedDef(field) {
124
124
  edit: { mutability: "never" },
125
125
  });
126
126
  }
127
+ export function ownField(map, key) {
128
+ if (map === undefined || typeof key !== "string" || !Object.hasOwn(map, key))
129
+ return undefined;
130
+ const value = map[key];
131
+ return value !== null && typeof value === "object" ? value : undefined;
132
+ }
133
+ const TYPE_NAMES = {
134
+ text: true,
135
+ number: true,
136
+ percent: true,
137
+ currency: true,
138
+ date: true,
139
+ datetime: true,
140
+ boolean: true,
141
+ select: true,
142
+ status: true,
143
+ multiselect: true,
144
+ relation: true,
145
+ user: true,
146
+ url: true,
147
+ domain: true,
148
+ email: true,
149
+ phone: true,
150
+ location: true,
151
+ name: true,
152
+ actor: true,
153
+ rich_text: true,
154
+ range: true,
155
+ lookup: true,
156
+ rollup: true,
157
+ formula: true,
158
+ };
159
+ const TYPES = new Set(Object.keys(TYPE_NAMES));
160
+ export function knownField(field) {
161
+ if (field === null || typeof field !== "object" || !Object.hasOwn(field, "type"))
162
+ return undefined;
163
+ const type = field.type;
164
+ return typeof type === "string" && TYPES.has(type) ? field : undefined;
165
+ }
@@ -1,4 +1,4 @@
1
- import { isGroupedRollup, presentedDef, valueTypeOf } from "./derived.js";
1
+ import { isGroupedRollup, ownField, presentedDef, valueTypeOf } from "./derived.js";
2
2
  import { formulaReads } from "./formula.js";
3
3
  import { filterPartsFor, isFilterGroup, isRelationRule, operatorsForField, } from "./query/filter.js";
4
4
  import { relationKinds } from "./relation.js";
@@ -29,7 +29,7 @@ export function subtitleThrough(key) {
29
29
  }
30
30
  export function subtitleField(fields, key) {
31
31
  if (!subtitleThrough(key))
32
- return fields[key];
32
+ return ownField(fields, key);
33
33
  return Object.values(fields).find((field) => field.identity)?.subtitleTargets?.[key];
34
34
  }
35
35
  export function avatarKey(fields) {
@@ -37,7 +37,7 @@ export function avatarKey(fields) {
37
37
  }
38
38
  export function renamedName(fields) {
39
39
  const name = Object.values(fields).find((field) => field.identity && field.rename !== undefined);
40
- const stored = name?.rename !== undefined ? fields[name.rename] : undefined;
40
+ const stored = name?.rename !== undefined ? ownField(fields, name.rename) : undefined;
41
41
  if (!name || !stored)
42
42
  return undefined;
43
43
  const { subtitle: _subtitle, description: _description, ...shape } = stored;
@@ -52,8 +52,8 @@ export function renamedName(fields) {
52
52
  });
53
53
  }
54
54
  export function editedThroughField(fields, key) {
55
- const field = fields[key];
56
- const stored = field?.editThrough !== undefined ? fields[field.editThrough] : undefined;
55
+ const field = ownField(fields, key);
56
+ const stored = field?.editThrough !== undefined ? ownField(fields, field.editThrough) : undefined;
57
57
  if (!field || !stored || field.identity)
58
58
  return undefined;
59
59
  const { subtitle: _subtitle, description: _description, ...shape } = stored;
@@ -67,11 +67,11 @@ export function editedThroughField(fields, key) {
67
67
  });
68
68
  }
69
69
  function farEntityOf(index, near, via) {
70
- const relation = near.fields[via];
70
+ const relation = ownField(near.fields, via);
71
71
  if (!relation || relation.type !== "relation")
72
72
  return undefined;
73
73
  const [kind] = relationKinds(relation);
74
- return kind === undefined ? undefined : index[kind];
74
+ return kind === undefined ? undefined : ownField(index, kind);
75
75
  }
76
76
  export function checkIndex(index) {
77
77
  checkRegistries(Object.fromEntries(Object.entries(index).map(([k, e]) => [k, e.fields])));
@@ -91,7 +91,7 @@ function checkRelationOrders(index) {
91
91
  const far = farEntityOf(index, entity, key);
92
92
  if (!far)
93
93
  continue;
94
- const read = far.fields[field.sortBy];
94
+ const read = ownField(far.fields, field.sortBy);
95
95
  if (!read) {
96
96
  throw new FieldDefinitionError(`${kind}.${key}`, `sortBy "${field.sortBy}" is not a field of ${far.entity}`);
97
97
  }
@@ -120,20 +120,20 @@ function checkSubtitles(index) {
120
120
  checkEntityLine(index, kind);
121
121
  }
122
122
  function checkEntityLine(index, kind) {
123
- const entity = index[kind];
123
+ const entity = ownField(index, kind);
124
124
  for (const key of subtitleKeys(entity.fields)) {
125
125
  const at = `${kind}.${key}`;
126
126
  const path = subtitleThrough(key);
127
- let drawn = entity.fields[key];
127
+ let drawn = ownField(entity.fields, key);
128
128
  if (path) {
129
- const relation = entity.fields[path.via];
129
+ const relation = ownField(entity.fields, path.via);
130
130
  if (relation?.type === "relation" && relationKinds(relation).length > 1) {
131
131
  throw new FieldDefinitionError(at, "a relation to several kinds cannot carry the line under the name");
132
132
  }
133
133
  const far = farEntityOf(index, entity, path.via);
134
134
  if (!far)
135
135
  continue;
136
- drawn = far.fields[path.field];
136
+ drawn = ownField(far.fields, path.field);
137
137
  if (!drawn)
138
138
  throw new FieldDefinitionError(at, `${far.entity} has no field "${path.field}"`);
139
139
  }
@@ -151,7 +151,7 @@ export function drawsUnderName(field) {
151
151
  return SUBTITLE_TYPES.has(valueTypeOf(field));
152
152
  }
153
153
  export function withLine(index, entity, keys) {
154
- const near = index[entity];
154
+ const near = ownField(index, entity);
155
155
  if (!near)
156
156
  throw new FieldDefinitionError(entity, `${entity} is not an entity of the index`);
157
157
  checkLineEntries(near.identity, keys, near.fields);
@@ -190,7 +190,7 @@ function checkAvatars(index) {
190
190
  const key = avatarKey(entity.fields);
191
191
  if (key === undefined)
192
192
  continue;
193
- const type = valueTypeOf(entity.fields[key]);
193
+ const type = valueTypeOf(ownField(entity.fields, key));
194
194
  if (type !== "url")
195
195
  throw new FieldDefinitionError(`${kind}.${key}`, `a ${type} cannot be the picture beside the name`);
196
196
  }
@@ -216,7 +216,7 @@ function endsInRollup(field, entity, index, seen = new Set()) {
216
216
  ...(field.ratio ? [field.ratio.numerator, field.ratio.denominator] : []),
217
217
  ];
218
218
  return reads.some((key) => {
219
- const read = entity.fields[key];
219
+ const read = ownField(entity.fields, key);
220
220
  return !!read && endsInRollup(read, entity, index, seen);
221
221
  });
222
222
  }
@@ -236,7 +236,7 @@ function checkLookups(index) {
236
236
  const far = farEntityOf(index, entity, field.via);
237
237
  if (!far)
238
238
  continue;
239
- if (!far.fields[field.field]) {
239
+ if (!ownField(far.fields, field.field)) {
240
240
  throw new FieldDefinitionError(`${kind}.${key}`, `the lookup's far field "${field.field}" is not a field of ${far.entity}`);
241
241
  }
242
242
  }
@@ -252,7 +252,7 @@ function checkRelationReach(index) {
252
252
  if (!far)
253
253
  continue;
254
254
  const need = (name, what) => {
255
- const found = far.fields[name];
255
+ const found = ownField(far.fields, name);
256
256
  if (!found)
257
257
  throw new FieldDefinitionError(at, `${what} "${name}" is not a field of ${far.entity}`);
258
258
  return found;
@@ -290,7 +290,7 @@ function checkRollups(index) {
290
290
  for (const [i, hop] of hops.entries()) {
291
291
  if (!far)
292
292
  break;
293
- const rel = far.fields[hop];
293
+ const rel = ownField(far.fields, hop);
294
294
  if (i > 0 && (!rel || rel.type !== "relation")) {
295
295
  throw new FieldDefinitionError(at, `the second hop "${hop}" is not a relation of ${far.entity}`);
296
296
  }
@@ -299,11 +299,11 @@ function checkRollups(index) {
299
299
  }
300
300
  far = farEntityOf(index, far, hop);
301
301
  }
302
- const firstRel = entity.fields[hops[0]];
302
+ const firstRel = ownField(entity.fields, hops[0]);
303
303
  if (field.of && firstRel?.type === "relation" && "kinds" in firstRel.relation) {
304
304
  for (const k of firstRel.relation.kinds) {
305
- const other = index[k];
306
- const read = other?.fields[field.of];
305
+ const other = ownField(index, k);
306
+ const read = ownField(other?.fields, field.of);
307
307
  if (other && read && endsInRollup(read, other, index)) {
308
308
  throw new FieldDefinitionError(at, `${other.entity}.${field.of} is itself a rollup — a rollup does not read another`);
309
309
  }
@@ -313,7 +313,7 @@ function checkRollups(index) {
313
313
  continue;
314
314
  const farEntity = far;
315
315
  const need = (name, what) => {
316
- const found = farEntity.fields[name];
316
+ const found = ownField(farEntity.fields, name);
317
317
  if (!found) {
318
318
  throw new FieldDefinitionError(at, `${what} "${name}" is not a field of ${farEntity.entity}`);
319
319
  }
@@ -340,7 +340,7 @@ function checkRollups(index) {
340
340
  ...(field.where ? treeFields(field.where) : []),
341
341
  ].filter((name) => !!name);
342
342
  for (const name of reads) {
343
- const read = farEntity.fields[name];
343
+ const read = ownField(farEntity.fields, name);
344
344
  if (read && endsInRollup(read, farEntity, index)) {
345
345
  throw new FieldDefinitionError(at, `${farEntity.entity}.${name} is itself a rollup — a rollup does not read another`);
346
346
  }
@@ -407,7 +407,7 @@ export function checkFilterTree(tree, entity, index, at) {
407
407
  if (!node.where || !Array.isArray(node.where.items)) {
408
408
  throw new FieldDefinitionError(at, `the filter across "${node.fieldKey}" has no where`);
409
409
  }
410
- const rel = entity.fields[node.fieldKey];
410
+ const rel = ownField(entity.fields, node.fieldKey);
411
411
  if (!rel || rel.type !== "relation") {
412
412
  throw new FieldDefinitionError(at, `"${node.fieldKey}" is not a relation of ${entity.entity}`);
413
413
  }
@@ -421,7 +421,7 @@ export function checkFilterTree(tree, entity, index, at) {
421
421
  checkFilterTree(node.where, far, index, at);
422
422
  continue;
423
423
  }
424
- const field = entity.fields[node.fieldKey];
424
+ const field = ownField(entity.fields, node.fieldKey);
425
425
  if (!field) {
426
426
  throw new FieldDefinitionError(at, `the filter names "${node.fieldKey}", which ${entity.entity} does not have`);
427
427
  }
@@ -435,7 +435,7 @@ export function checkFilterTree(tree, entity, index, at) {
435
435
  }
436
436
  function withContributions(raw, contributions) {
437
437
  for (const c of contributions) {
438
- const base = raw[c.entity];
438
+ const base = ownField(raw, c.entity);
439
439
  if (!base) {
440
440
  throw new FieldDefinitionError(c.from, `adds to ${c.entity}, which the index does not hold`);
441
441
  }
@@ -461,7 +461,7 @@ function withContributions(raw, contributions) {
461
461
  export function defineIndex(entities, contributions = []) {
462
462
  const raw = {};
463
463
  for (const e of entities) {
464
- if (raw[e.entity])
464
+ if (ownField(raw, e.entity))
465
465
  throw new FieldDefinitionError(e.entity, "an entity is named twice in the index");
466
466
  raw[e.entity] = e;
467
467
  }
@@ -474,7 +474,7 @@ export function defineIndex(entities, contributions = []) {
474
474
  const ready = done.get(address);
475
475
  if (ready)
476
476
  return ready;
477
- const field = raw[kind].fields[key];
477
+ const field = ownField(ownField(raw, kind).fields, key);
478
478
  if (field.type !== "lookup") {
479
479
  done.set(address, field);
480
480
  return field;
@@ -483,7 +483,7 @@ export function defineIndex(entities, contributions = []) {
483
483
  throw new FieldDefinitionError(address, "a lookup cycle — follow the chain and break it");
484
484
  }
485
485
  resolving.add(address);
486
- const far = farEntityOf(raw, raw[kind], field.via);
486
+ const far = farEntityOf(raw, ownField(raw, kind), field.via);
487
487
  const target = far ? resolve(far.entity, field.field) : undefined;
488
488
  resolving.delete(address);
489
489
  if (target) {
@@ -505,7 +505,7 @@ export function defineIndex(entities, contributions = []) {
505
505
  const fields = {};
506
506
  for (const key of Object.keys(e.fields))
507
507
  fields[key] = resolve(kind, key);
508
- const name = fields[e.identity];
508
+ const name = ownField(fields, e.identity);
509
509
  if (name?.subtitleThrough) {
510
510
  const targets = {};
511
511
  for (const path of Object.keys(name.subtitleThrough)) {
@@ -1,5 +1,5 @@
1
1
  import { utcDay } from "./codecs.js";
2
- import { isBreakdown, isPerCodeCurrency, storesDecimalText, valueTypeOf } from "./derived.js";
2
+ import { isBreakdown, isPerCodeCurrency, ownField, storesDecimalText, valueTypeOf } from "./derived.js";
3
3
  import { FieldDefinitionError } from "./errors.js";
4
4
  import { phoneMatchText } from "./phone.js";
5
5
  import { isRangeValue } from "./range.js";
@@ -415,7 +415,7 @@ export function checkFormula(rule, fields, self = "formula") {
415
415
  if ("field" in node) {
416
416
  if (node.field === self)
417
417
  throw new FieldDefinitionError(self, "a formula cannot read itself");
418
- const field = fields[node.field];
418
+ const field = ownField(fields, node.field);
419
419
  if (!field) {
420
420
  throw new FieldDefinitionError(self, `the rule reads "${node.field}", which is not a field here`);
421
421
  }
@@ -1,4 +1,4 @@
1
- import { isPerCodeCurrency, scalarOf, valueTypeOf } from "../derived.js";
1
+ import { isPerCodeCurrency, knownField, scalarOf, valueTypeOf } from "../derived.js";
2
2
  import { ruleReaderOf } from "./read-rule.js";
3
3
  import { isRelationRule, matchesTree, ruleIsActive, whereWaits, } from "./filter.js";
4
4
  import { compareBy } from "./sort.js";
@@ -12,7 +12,7 @@ export function recordReaderFor(row, reader) {
12
12
  read: ruleReaderOf(row, reader),
13
13
  ...(related
14
14
  ? {
15
- related: (rule) => reader.fieldOf(rule.fieldKey)?.type === "relation"
15
+ related: (rule) => knownField(reader.fieldOf(rule.fieldKey))?.type === "relation"
16
16
  ? related(row, rule.fieldKey)
17
17
  : undefined,
18
18
  }
@@ -31,8 +31,8 @@ export function hasActiveRules(filter, fieldOf, answersRelations = false) {
31
31
  if ("items" in item)
32
32
  return hasActiveRules({ op: "and", items: item.items }, fieldOf, answersRelations);
33
33
  if (isRelationRule(item))
34
- return (answersRelations && !item.setAside && !whereWaits(item.where) && fieldOf(item.fieldKey)?.type === "relation");
35
- const field = fieldOf(item.fieldKey);
34
+ return (answersRelations && !item.setAside && !whereWaits(item.where) && knownField(fieldOf(item.fieldKey))?.type === "relation");
35
+ const field = knownField(fieldOf(item.fieldKey));
36
36
  return !!field && !isPerCodeCurrency(field) && ruleIsActive(valueTypeOf(field), item);
37
37
  });
38
38
  }
@@ -50,7 +50,7 @@ export function evaluateView(rows, query, reader, opts = {}) {
50
50
  const sorted = query.rowOrderMode === "manual" && opts.rowId
51
51
  ? applyManualOrder(fieldSorted, query.itemPositions ?? [], opts.rowId)
52
52
  : fieldSorted;
53
- const groupField = query.group && !query.group.setAside ? reader.fieldOf(query.group.fieldKey) : undefined;
53
+ const groupField = query.group && !query.group.setAside ? knownField(reader.fieldOf(query.group.fieldKey)) : undefined;
54
54
  const buckets = query.group && groupField
55
55
  ? bucketRows(sorted, query.group, groupField, (row) => scalarOf(groupField, reader.read(row, query.group.fieldKey)), { conventions: opts.conventions, now: opts.now })
56
56
  : null;
@@ -1,5 +1,5 @@
1
1
  import { actorKey } from "../actor.js";
2
- import { presentedDef, scalarOf, valueTypeOf } from "../derived.js";
2
+ import { knownField, ownField, presentedDef, scalarOf, valueTypeOf } from "../derived.js";
3
3
  import { locationText } from "../location.js";
4
4
  import { nameText } from "../name.js";
5
5
  import { phoneMatchText } from "../phone.js";
@@ -35,7 +35,7 @@ export function figureFor(kind, figures, key) {
35
35
  return null;
36
36
  if (kind === "count")
37
37
  return figures.rows;
38
- const figure = figures.fields[key];
38
+ const figure = ownField(figures.fields, key);
39
39
  if (!figure)
40
40
  return null;
41
41
  if (kind === "filled")
@@ -49,8 +49,8 @@ export function figureFor(kind, figures, key) {
49
49
  return kind === "min" ? figure.min : figure.max;
50
50
  }
51
51
  export function ratioFigure(figures, numerator, denominator) {
52
- const num = figures.fields[numerator];
53
- const den = figures.fields[denominator];
52
+ const num = ownField(figures.fields, numerator);
53
+ const den = ownField(figures.fields, denominator);
54
54
  if (!num || !den)
55
55
  return null;
56
56
  const denominatorSum = den.sum ?? 0;
@@ -152,7 +152,7 @@ export function ratioOf(parts) {
152
152
  export function figuresOf(rows, keys, reader) {
153
153
  const fields = {};
154
154
  for (const key of keys) {
155
- const field = reader.fieldOf(key);
155
+ const field = knownField(reader.fieldOf(key));
156
156
  if (!field) {
157
157
  fields[key] = EMPTY_FIGURE;
158
158
  continue;
@@ -136,3 +136,18 @@ export declare function whereWaits(where: FilterTree): boolean;
136
136
  /** Judges one record against a tree: through a reader of its fields, or a `RecordReader` that also hands in the
137
137
  * records its relations hold. */
138
138
  export declare function matchesTree(tree: FilterTree, read: RuleReader | RecordReader, opts?: MatchOptions): boolean;
139
+ /** The bounds a list's settings and a definition's filter are held to. */
140
+ export declare const LIST_SETTINGS_LIMITS: {
141
+ readonly sorts: 3;
142
+ readonly filterDepth: 3;
143
+ readonly filterItems: 50;
144
+ readonly columns: 200;
145
+ readonly search: 200;
146
+ readonly buckets: 500;
147
+ readonly lanes: 500;
148
+ readonly itemPositions: 5000;
149
+ readonly groupFigures: 50;
150
+ readonly key: 120;
151
+ readonly part: 40;
152
+ };
153
+ export declare const filterTreeSchema: z.ZodType<FilterTree>;