viewkitjs 0.19.0 → 0.21.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.
- package/CHANGELOG.md +66 -0
- package/MIGRATION.md +117 -0
- package/README.md +7 -3
- package/fields/README.md +3 -3
- package/fields/dist/derived.d.ts +4 -0
- package/fields/dist/derived.js +39 -0
- package/fields/dist/entities.js +30 -30
- package/fields/dist/formula.js +2 -2
- package/fields/dist/query/evaluate.js +5 -5
- package/fields/dist/query/figures.js +5 -5
- package/fields/dist/query/filter.d.ts +15 -0
- package/fields/dist/query/filter.js +85 -0
- package/fields/dist/query/hold.js +2 -2
- package/fields/dist/query/option-counts.js +2 -2
- package/fields/dist/query/read-rule.js +2 -2
- package/fields/dist/query/search.js +2 -2
- package/fields/dist/query/set-aside.js +4 -4
- package/fields/dist/query/settings.d.ts +2 -15
- package/fields/dist/query/settings.js +3 -81
- package/fields/dist/query/sort.js +4 -4
- package/fields/dist/registry.d.ts +19 -5
- package/fields/dist/registry.js +371 -50
- package/fields/dist/types.d.ts +1 -1
- package/fields/docs/getting-started.md +2 -2
- package/fields/docs/guides/checking-definitions.md +17 -4
- package/fields/docs/guides/derived-fields.md +5 -5
- package/fields/docs/guides/queries.md +1 -1
- package/fields/docs/reference/design-category-colors.md +1 -1
- package/fields/docs/reference/design-status-slots.md +1 -1
- package/fields/docs/reference/fields.md +3 -3
- package/fields/docs/reference/query.md +1 -0
- package/fields/skills/viewkit/SKILL.md +2 -2
- package/package.json +17 -6
- package/postgres/README.md +2 -2
- package/postgres/dist/access.d.ts +12 -4
- package/postgres/dist/access.js +3 -0
- package/postgres/dist/calendar.js +3 -2
- package/postgres/dist/check.d.ts +6 -4
- package/postgres/dist/check.js +27 -16
- package/postgres/dist/counts.js +3 -2
- package/postgres/dist/definitions/build.js +7 -0
- package/postgres/dist/definitions/formula.d.ts +1 -1
- package/postgres/dist/definitions/formula.js +5 -3
- package/postgres/dist/definitions/lookup.js +5 -1
- package/postgres/dist/definitions/money.js +6 -1
- package/postgres/dist/definitions/place.d.ts +7 -0
- package/postgres/dist/definitions/place.js +8 -0
- package/postgres/dist/definitions/relations.js +36 -3
- package/postgres/dist/definitions/rollup.d.ts +1 -1
- package/postgres/dist/definitions/rollup.js +11 -6
- package/postgres/dist/field-values.js +11 -8
- package/postgres/dist/figures.js +4 -2
- package/postgres/dist/filled.js +2 -2
- package/postgres/dist/groups.d.ts +2 -1
- package/postgres/dist/groups.js +5 -3
- package/postgres/dist/index.d.ts +1 -0
- package/postgres/dist/index.js +1 -0
- package/postgres/dist/kept.js +8 -4
- package/postgres/dist/lanes.js +5 -3
- package/postgres/dist/phone.js +2 -2
- package/postgres/dist/predicates.js +2 -2
- package/postgres/dist/readable.d.ts +40 -0
- package/postgres/dist/readable.js +84 -0
- package/postgres/dist/records.js +7 -4
- package/postgres/dist/refusals.d.ts +8 -1
- package/postgres/dist/refusals.js +7 -0
- package/postgres/dist/relations.js +5 -4
- package/postgres/dist/search-indexes.js +2 -1
- package/postgres/dist/search.js +6 -4
- package/postgres/dist/several.js +8 -8
- package/postgres/dist/sort.d.ts +5 -3
- package/postgres/dist/sort.js +13 -8
- package/postgres/dist/value-rows.js +2 -2
- package/postgres/dist/values.js +4 -2
- package/postgres/docs/guides/definitions.md +2 -2
- package/postgres/docs/guides/field-map.md +43 -18
- package/postgres/docs/guides/test-kit.md +2 -0
- package/postgres/docs/reference/postgres.md +10 -4
- package/views/README.md +4 -2
- package/views/dist/atoms/StatusBadge.js +1 -1
- package/views/dist/atoms/tones.js +7 -7
- package/views/dist/atoms/types.d.ts +3 -2
- package/views/dist/contract.d.ts +7 -2
- package/views/dist/contract.js +33 -0
- package/views/dist/display/fit-values.d.ts +3 -2
- package/views/dist/display/link.d.ts +1 -1
- package/views/dist/display/location.js +2 -1
- package/views/dist/display/multi-value.js +1 -1
- package/views/dist/display/name.js +3 -1
- package/views/dist/display/select.js +1 -1
- package/views/dist/display/value-list.d.ts +1 -1
- package/views/dist/grid/chrome/GridStructure.js +2 -1
- package/views/dist/grid/looks.d.ts +45 -0
- package/views/dist/grid/looks.js +74 -0
- package/views/dist/looks/index.d.ts +7 -0
- package/views/dist/looks/index.js +3 -0
- package/views/dist/looks/looks.d.ts +46 -0
- package/views/dist/looks/looks.js +25 -0
- package/views/dist/looks/pieces.d.ts +3 -0
- package/views/dist/looks/pieces.js +2 -0
- package/views/dist/provider/ViewsProvider.d.ts +3 -3
- package/views/dist/provider/ViewsProvider.js +1 -1
- package/views/dist/provider/context.d.ts +1 -1
- package/views/dist/styles.css +3277 -0
- package/views/dist/styles.unlayered.css +3276 -0
- package/views/docs/contract.md +61 -13
- package/views/docs/getting-started.md +1 -1
- package/views/docs/guides/display.md +11 -7
- package/views/docs/guides/looks.md +29 -0
- package/views/docs/guides/the-grid.md +1 -1
- package/views/docs/guides/the-provider.md +1 -1
- package/views/docs/index.md +2 -0
- package/views/docs/install.md +36 -9
- package/views/docs/reference/display.md +2 -2
- package/views/docs/reference/looks.md +31 -0
- package/views/docs/reference/react.md +2 -2
- package/views/docs/reference/views.md +1 -1
- package/views/skills/views/SKILL.md +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,72 @@ Until 0.19.0 ViewKit shipped as three packages; their changes are in [fields/CHA
|
|
|
5
5
|
|
|
6
6
|
## [Unreleased]
|
|
7
7
|
|
|
8
|
+
## [0.21.0] — 2026-11-25
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
|
|
12
|
+
- `viewkitjs/views/looks`: a piece's options and looks, declared beside it, and the helpers to wear one. `lookAttrs` gives the `data-<piece>-<option>` attributes for a set of picks, `lookPicks` a look's picks by its id, and `lookWorn` and `lookWornOf` read the picks back, from picks or from the frame round an element; a pick its option doesn't have wears the default. `LOOKS` lists every piece that declares looks; today, the grid. No React at runtime. A piece's, its options', their values' and its looks' ids are public ([the contract](views/docs/contract.md#looks)).
|
|
13
|
+
- The grid's options and its two looks, `attio` and `portal`, as `GRID_LOOKS`, with `gridLookWorn`, `gridLookWornOf` and `gridLookProps`: the `GridTable` props a look sets (its column lines, density and scale on a phone, pinned name, checkboxes, row icon, groups, width, and on a phone its footer, + Add column and picking). The options only the grid's look stylesheet reads (the header's words, the rows' lines, the pinned edge, picked rows and cells, the cells' frames, names and phones) draw nothing yet: that stylesheet ships later.
|
|
14
|
+
- Each hue's pill reads three optional colours, `--vk-label-<hue>-fill`, `--vk-label-<hue>-edge` and `--vk-label-<hue>-strong`. Undeclared, they come from your own `--vk-label-<hue>` (15% and 40% into `--vk-ground`, 60% into `--vk-fg`), so an app on `@source` that declares only its hues keeps them. The stylesheet declares the Outright look's, so under `styles.css` an app that sets its own `--vk-label-<hue>` sets the three rungs too, or the pill wears the Outright look's.
|
|
15
|
+
- Under `viewkitjs/views/styles.css`, the fills that kept the Outright look have names you can declare: `--vk-success-subtlest`, `--vk-warning-subtlest` and `--vk-info-subtlest` (a status's soft fill), `--vk-fg-inverse` and `--vk-fg-warning-inverse` (the words on a filled status), and `--vk-label-<hue>-soft` (a category chip's fill). `docs/contract.md`, Tokens, lists them all. With `@source`, an app's own theme draws these as before.
|
|
16
|
+
|
|
17
|
+
### Changed
|
|
18
|
+
|
|
19
|
+
- Several values in one cell (several emails, phones, links or domains, a multiselect, a many relation, a lookup's names or places) now show as many whole values as fit the cell's width, then "+N", by default. `severalValues: "first"` on `ViewsProvider` keeps the old way: the first value and a count at any width.
|
|
20
|
+
- Every cell type's text that doesn't fit its column ends in "…". A place and a name used to be cut mid-letter.
|
|
21
|
+
- A status drawn as a field's value (a grid cell, a drawer's field row, a card) draws its text at the size of the text around it, its dot as before. `ViewsStatusBadgeProps["size"]` gains `"row"`, which a cell's status value hands; your own `StatusBadge` atom should take its text size from around it for `"row"`.
|
|
22
|
+
- A group's count is a chip ViewKit draws itself, on `--vk-neutral` at the row's text size, with no dot before it; each figure still follows its dot. A rule your app wrote to dress `vk-grid-group-count` as a chip, or to hide the dot before it, can go.
|
|
23
|
+
- The default Tag draws a pill, the Outright look's Option: each hue's fill, its edge drawn inside, and its words a strong step, which read at 4.5:1 or more on their fill in every hue, light and dark (before, the hue's own words on a 12% tint, as low as 1.97:1 for amber). An app that hands its own `Tag` atom sees no change.
|
|
24
|
+
|
|
25
|
+
## [0.20.0] — 2026-11-25
|
|
26
|
+
|
|
27
|
+
### Added
|
|
28
|
+
|
|
29
|
+
- `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`.
|
|
30
|
+
- `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.
|
|
31
|
+
- `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.
|
|
32
|
+
- `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.
|
|
33
|
+
- `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.
|
|
34
|
+
|
|
35
|
+
### Changed
|
|
36
|
+
|
|
37
|
+
- `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`.
|
|
38
|
+
|
|
39
|
+
```ts
|
|
40
|
+
// before
|
|
41
|
+
pageQuery({ map, access, sorts, size: 50 });
|
|
42
|
+
// after: a reader with no field rules
|
|
43
|
+
pageQuery({ map, access, readable: EVERY_FIELD, sorts, size: 50 });
|
|
44
|
+
// after: a reader who may not read a company's revenue
|
|
45
|
+
pageQuery({ map, access, readable: { deals: ["title", "stage", "company"], companies: ["name"] }, sorts, size: 50 });
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
- `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.
|
|
49
|
+
- `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.
|
|
50
|
+
- `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:
|
|
51
|
+
|
|
52
|
+
```ts
|
|
53
|
+
// before
|
|
54
|
+
defineFields({ entity: "campaign", identity: "name", fields: { lastReply: { type: "formula", rule: { sql: "app.last_reply" }, … } } });
|
|
55
|
+
// after
|
|
56
|
+
defineFields({ entity: "campaign", identity: "name", allowSql: true, fields: { lastReply: { type: "formula", rule: { sql: "app.last_reply" }, … } } });
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
- `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.
|
|
60
|
+
- `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.
|
|
61
|
+
- `viewkitjs/fields`: `checkFieldSpec` takes `unknown` and asserts `FieldSpec`, so a definition read from a row needs no cast.
|
|
62
|
+
- `viewkitjs/fields/types`: `FieldSpec` no longer holds `avatar`, which `defineFields({ avatar })` stamps.
|
|
63
|
+
- `sideEffects` is `["**/*.css"]`, so a bundler keeps a stylesheet import.
|
|
64
|
+
- Nothing changes for an app that doesn't import the stylesheet: one on `@source` with its own `--vk-*` mapping draws exactly as before.
|
|
65
|
+
- `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.
|
|
66
|
+
|
|
67
|
+
### Fixed
|
|
68
|
+
|
|
69
|
+
- `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.
|
|
70
|
+
- `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`.
|
|
71
|
+
- `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.
|
|
72
|
+
- The getting-started guide's `fieldOf` asks `Object.hasOwn(REGISTRY, key)`; if you copied its `key in REGISTRY`, change yours the same way.
|
|
73
|
+
|
|
8
74
|
## [0.19.0] — 2026-11-24
|
|
9
75
|
|
|
10
76
|
ViewKit is one package. `viewkitjs` replaces `@viewkitjs/fields` 0.18.0, `@viewkitjs/views` 0.15.0 and
|
package/MIGRATION.md
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
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. A door added since, such as
|
|
71
|
+
`viewkitjs/views/looks`, has no old path: an app starts on it under `viewkitjs`. The three `package.json` entries move the
|
|
72
|
+
same way (`@viewkitjs/fields/package.json` is `viewkitjs/package.json`, one manifest for all three parts).
|
|
73
|
+
|
|
74
|
+
## The names your app narrows
|
|
75
|
+
|
|
76
|
+
An app that narrows ViewKit's names (its entities, fields and kinds) augments the types entry. The block's
|
|
77
|
+
module name moves like an import:
|
|
78
|
+
|
|
79
|
+
```ts
|
|
80
|
+
// before
|
|
81
|
+
declare module "@viewkitjs/fields/types" {
|
|
82
|
+
// …your interfaces, unchanged
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// after
|
|
86
|
+
declare module "viewkitjs/fields/types" {
|
|
87
|
+
// …your interfaces, unchanged
|
|
88
|
+
}
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
Change it in the same pass as the imports. TypeScript reports no error for an augmentation of a module that is
|
|
92
|
+
no longer installed: the block stops applying, and every name it narrowed widens back to `string` in silence.
|
|
93
|
+
The fields part's guide `fields/docs/guides/narrowing-names.md` shows the whole block.
|
|
94
|
+
|
|
95
|
+
## The views part's look
|
|
96
|
+
|
|
97
|
+
An app that lets its own Tailwind 4 compile the views part points the `@source` line at the new folder, the
|
|
98
|
+
path relative to the stylesheet it sits in:
|
|
99
|
+
|
|
100
|
+
| Old | New |
|
|
101
|
+
| --- | --- |
|
|
102
|
+
| `@source "../../node_modules/@viewkitjs/views";` | `@source "../../node_modules/viewkitjs/views";` |
|
|
103
|
+
| `@source "../../node_modules/@viewkitjs/views/dist";` | `@source "../../node_modules/viewkitjs/views/dist";` |
|
|
104
|
+
|
|
105
|
+
A line still on the old folder finds nothing once the old package is removed, and the grid draws unstyled.
|
|
106
|
+
|
|
107
|
+
From 0.20.0 the views part also ships its look as a ready stylesheet, which needs neither Tailwind nor the
|
|
108
|
+
`@source` line: `@import "viewkitjs/views/styles.css";`. The views part's install page,
|
|
109
|
+
`views/docs/install.md`, has both ways and the colours.
|
|
110
|
+
|
|
111
|
+
## Check you're done
|
|
112
|
+
|
|
113
|
+
After the replacement, nothing in your code, styles or manifest names `@viewkitjs/`:
|
|
114
|
+
|
|
115
|
+
```sh
|
|
116
|
+
git grep -n "@viewkitjs/" -- ':!*lock*'
|
|
117
|
+
```
|
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
|
-
|
|
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
|
-
@
|
|
30
|
+
@import "viewkitjs/views/styles.css";
|
|
31
31
|
```
|
|
32
32
|
|
|
33
|
-
|
|
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
|
|
68
|
-
fieldOf: (key) => (key
|
|
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 |
|
package/fields/dist/derived.d.ts
CHANGED
|
@@ -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;
|
package/fields/dist/derived.js
CHANGED
|
@@ -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
|
+
}
|
package/fields/dist/entities.js
CHANGED
|
@@ -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
|
|
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
|
|
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
|
|
56
|
-
const stored = field?.editThrough !== undefined ? fields
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
127
|
+
let drawn = ownField(entity.fields, key);
|
|
128
128
|
if (path) {
|
|
129
|
-
const relation = entity.fields
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
306
|
-
const read = other?.fields
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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)) {
|
package/fields/dist/formula.js
CHANGED
|
@@ -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
|
|
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
|
|
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
|
|
53
|
-
const den = figures.fields
|
|
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>;
|