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.
- package/CHANGELOG.md +49 -0
- package/MIGRATION.md +116 -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 +13 -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 +3 -2
- package/views/dist/styles.css +3165 -0
- package/views/dist/styles.unlayered.css +3164 -0
- package/views/docs/contract.md +13 -7
- package/views/docs/getting-started.md +1 -1
- package/views/docs/guides/the-grid.md +1 -1
- package/views/docs/install.md +35 -8
|
@@ -82,7 +82,7 @@ A lookup shows one field of the record a single relation points at. `via` names
|
|
|
82
82
|
Never write a lookup's `target`. `defineIndex` fills in the far definition from the far registry, in a frozen copy, so a far definition is never copied into source. Inside its own registry, before the index resolves it, a lookup reads as text. A far field may itself be a lookup, which is how a chain is built; a chain that comes back on itself is refused.
|
|
83
83
|
|
|
84
84
|
```ts
|
|
85
|
-
import { checkFieldSpec, FieldDefinitionError, looksAhead, valueTypeOf } from "viewkitjs/fields";
|
|
85
|
+
import { checkFieldSpec, FieldDefinitionError, looksAhead, valueTypeOf, type FieldSpec } from "viewkitjs/fields";
|
|
86
86
|
|
|
87
87
|
// Before the index: the far field is unknown, so the lookup reads as text.
|
|
88
88
|
assert.equal(valueTypeOf(DEAL_FIELDS.company_renewal), "text");
|
|
@@ -282,7 +282,7 @@ assert.throws(
|
|
|
282
282
|
);
|
|
283
283
|
|
|
284
284
|
/** A company registry with one extra rollup, for the refusals only the index can see. */
|
|
285
|
-
function companyWith(key: string, rollup:
|
|
285
|
+
function companyWith(key: string, rollup: FieldSpec) {
|
|
286
286
|
return defineFields({
|
|
287
287
|
entity: "company",
|
|
288
288
|
identity: "name",
|
|
@@ -485,7 +485,7 @@ assert.equal(FORMULA_MAX_NODES, 200);
|
|
|
485
485
|
- a literal that is no text, finite number, boolean or null;
|
|
486
486
|
- more than `FORMULA_MAX_NODES` values, fields and calls in one rule. How deep it nests is no limit.
|
|
487
487
|
|
|
488
|
-
`defineFields` also refuses formulas that read each other round. A rule may instead be `{ sql: "schema.name" }`, a named database function for a value that needs other rows; only a registry written in code may name one, never a definition that arrives as data.
|
|
488
|
+
`defineFields` also refuses formulas that read each other round. A rule may instead be `{ sql: "schema.name" }`, a named database function for a value that needs other rows; only a registry written in code that passes `allowSql: true` may name one, never a definition that arrives as data.
|
|
489
489
|
|
|
490
490
|
```ts
|
|
491
491
|
import { checkFormula } from "viewkitjs/fields";
|
|
@@ -531,10 +531,10 @@ assert.throws(
|
|
|
531
531
|
),
|
|
532
532
|
FieldDefinitionError
|
|
533
533
|
);
|
|
534
|
-
// A definition that arrives as data cannot name a database function;
|
|
534
|
+
// A definition that arrives as data cannot name a database function; a registry written in code may, when it says so.
|
|
535
535
|
const sqlTotal = { type: "formula", label: "Total", from: "the invoices", rule: { sql: "billing.total" }, result: { type: "number" } } as const;
|
|
536
536
|
assert.throws(() => checkFieldSpec("total", sqlTotal), FieldDefinitionError);
|
|
537
|
-
defineFields({ entity: "task", identity: "title", fields: { title: { type: "text", label: "Title" }, total: sqlTotal } });
|
|
537
|
+
defineFields({ entity: "task", identity: "title", allowSql: true, fields: { title: { type: "text", label: "Title" }, total: sqlTotal } });
|
|
538
538
|
// Formulas that read each other round never finish.
|
|
539
539
|
assert.throws(
|
|
540
540
|
() =>
|
|
@@ -159,7 +159,7 @@ const PEOPLE: Person[] = [
|
|
|
159
159
|
/** A reader over plain rows: the field from its registry, the value from the row's own key. */
|
|
160
160
|
function readerOf<Row extends { id: string }>(fields: Readonly<Record<string, FieldDef>>): ViewFieldReader<Row> {
|
|
161
161
|
return {
|
|
162
|
-
fieldOf: (key) => fields[key],
|
|
162
|
+
fieldOf: (key) => (Object.hasOwn(fields, key) ? fields[key] : undefined),
|
|
163
163
|
read: (row, key) => (row as Record<string, unknown>)[key],
|
|
164
164
|
};
|
|
165
165
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# `viewkitjs/fields/design/category-colors`
|
|
2
2
|
|
|
3
|
-
Import from `viewkitjs/fields/design/category-colors` where you draw a value of a `select` or a `multiselect`. These colours are decorative: they tell one category from another and say nothing about state, which is a status's slot. The class names read your stylesheet's `--label-*` tokens, eight hues that stay the same in every theme. The [options guide](../guides/options.md) shows an option with its colour.
|
|
3
|
+
Import from `viewkitjs/fields/design/category-colors` where you draw a value of a `select` or a `multiselect`. These colours are decorative: they tell one category from another and say nothing about state, which is a status's slot. The class names read your stylesheet's `--label-*` tokens, eight hues that stay the same in every theme. Under `viewkitjs/views/styles.css` instead of your own Tailwind, a chip's text reads `--vk-label-<hue>` and its fill is the Outright look's, fixed for now. The [options guide](../guides/options.md) shows an option with its colour.
|
|
4
4
|
- `CategoryColor` — the eight colours: `gray`, `blue`, `green`, `amber`, `red`, `purple`, `pink` and `teal`.
|
|
5
5
|
- `CATEGORY_COLOR_CLASSES` — a chip's class names per colour: the colour's soft rung as the fill and the colour as text.
|
|
6
6
|
- `CATEGORY_DOT_CLASSES` — a solid dot's class name per colour.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# `viewkitjs/fields/design/status-slots`
|
|
2
2
|
|
|
3
|
-
Import from `viewkitjs/fields/design/status-slots` where you draw a status. Every option of a `status` field wears one semantic slot (`slot: "success"`), and this entry maps each slot to Tailwind class names. Each class names a theme token (`success`, `destructive`, `warning`, `info`, `primary` and the greys), never a palette colour, so your stylesheet defines the tokens once and every badge, dot and pill follows them in both themes. The [options guide](../guides/options.md) shows a status's options.
|
|
3
|
+
Import from `viewkitjs/fields/design/status-slots` where you draw a status. Every option of a `status` field wears one semantic slot (`slot: "success"`), and this entry maps each slot to Tailwind class names. Each class names a theme token (`success`, `destructive`, `warning`, `info`, `primary` and the greys), never a palette colour, so your stylesheet defines the tokens once and every badge, dot and pill follows them in both themes. Under `viewkitjs/views/styles.css` instead of your own Tailwind, the classes draw the Outright look's colours, the main ones through `--vk-*` names you can declare (`--vk-success`, `--vk-brand`, `--vk-neutral`…), the success, warning and information soft fills and the text on those filled pills and on a filled error fixed for now. The [options guide](../guides/options.md) shows a status's options.
|
|
4
4
|
- `StatusSlot` — the seven slots: `success` (a good end), `error` (failed), `warning` (needs attention), `running` (happening now), `pending` (waiting), `primary` (active, mid-way) and `muted` (skipped, inactive).
|
|
5
5
|
- `StatusBadgeVariant` — a status pill's two looks, both borderless: `soft` (a tinted fill and the colour as text) and `solid` (the colour as fill).
|
|
6
6
|
- `STATUS_SLOT_CLASSES` — the class names per slot: a badge's pill for each variant, an avatar's corner dot, a bare glyph's colour, an active tab and a plain tab's hover.
|
|
@@ -6,9 +6,9 @@ This is the entry an app imports from: the definitions, the index, the conventio
|
|
|
6
6
|
|
|
7
7
|
Guides: [field types](../guides/field-types.md), [checking definitions](../guides/checking-definitions.md).
|
|
8
8
|
|
|
9
|
-
- `defineFields` — defines one entity's registry: stamps each field with its key and entity, marks the identity field, checks the rename, the line under the name and the avatar it names, freezes the registry and throws `FieldDefinitionError` on a broken definition when the module loads. It keeps every literal on the type, so a stored value's type is the union of the declared codes rather than any string.
|
|
10
|
-
- `contributeFields` — declares fields one owner adds to an entity another owns, checked like a registry and stamped with the entity it adds to, with no identity of its own; `defineIndex` lays it onto that entity. It takes `allowSql:
|
|
11
|
-
- `checkFieldSpec` — runs the checks `defineFields` runs on one field, so a definition that arrives as data (a custom field read from a stored row) is held to the same bar; it takes the sibling fields the field refers to, and where the field sits, and throws `FieldDefinitionError` when something is wrong. Every closed word it holds is checked, the type first, and an unknown one is refused by name.
|
|
9
|
+
- `defineFields` — defines one entity's registry: stamps each field with its key and entity, marks the identity field, checks the rename, the line under the name and the avatar it names, freezes the registry and throws `FieldDefinitionError` on a broken definition when the module loads. It keeps every literal on the type, so a stored value's type is the union of the declared codes rather than any string. A formula may name a SQL function only with `allowSql: true`; by default it is refused, as for a definition that arrives as data.
|
|
10
|
+
- `contributeFields` — declares fields one owner adds to an entity another owns, checked like a registry and stamped with the entity it adds to, with no identity of its own; `defineIndex` lays it onto that entity. It takes `allowSql: true` the same way.
|
|
11
|
+
- `checkFieldSpec` — takes any value and asserts it is a `FieldSpec`: it checks its shape (every key one its type declares, every value of its kind, nothing nested deeper than 408 levels), then runs the checks `defineFields` runs on one field, so a definition that arrives as data (a custom field read from a stored row) is held to the same bar; it takes the sibling fields the field refers to, and where the field sits, and throws `FieldDefinitionError` when something is wrong. Every closed word it holds is checked, the type first, and an unknown one is refused by name.
|
|
12
12
|
- `checkInverse` — checks that every declared inverse relation points back at the relation that names it, across a set of registries keyed by relation kind.
|
|
13
13
|
- `checkRegistries` — runs the checks only a composition root can run, because only it sees every registry: each inverse points back, and each rollup aggregates a real field of the far registry with a function that can aggregate it. A far kind missing from the set is skipped.
|
|
14
14
|
- `FieldSpecMap` — the type of a registry's fields as written: field keys to field specs.
|
|
@@ -169,6 +169,7 @@ A link's platform is read through `matchesRule` with the part `platform`, from t
|
|
|
169
169
|
- `ListLayout` — the layout a list draws: a table, a list, a board or a calendar.
|
|
170
170
|
- `ListLook` — the view's look: density, vertical borders, the row icon, frozen identity columns and checkboxes always shown, each absent meaning the layout's own default.
|
|
171
171
|
- `LIST_SETTINGS_LIMITS` — the bounds the schema holds a value to: 3 sorts, 3 levels and 50 items per group in the filter, 200 columns, 500 group buckets, 500 board lanes, 50 group figures, 5,000 hand-placed records, a search of 200 characters, and the lengths of keys and parts.
|
|
172
|
+
- `filterTreeSchema` — the Zod schema of a filter tree, the one `listSettingsSchema` holds a view's filter to and a field definition's `where` is held to: strict at every level, no deeper than 3 levels (judged before the tree is read) and no more than 50 items in a group.
|
|
172
173
|
- `listSettingsSchema` — the one Zod schema of a list's settings, the same in the browser, on a server and from an agent. It checks shape, not fields, and refuses, each with its reason: an unknown key at any level, a fourth sort, a field sorted twice (whole or by a part), a filter deeper than 3 levels (judged before the tree is read, so a hostile input never recurses), a group of more than 50 items, an operator ViewKit has no word for, a column or a group figure listed twice and more than 5,000 hand-placed records. It keeps a set-aside mark, refusing a reason it has no word for, and reads a date pair whose end is still empty, `""` or null, as it is stored.
|
|
173
174
|
- `LIST_SETTINGS_DEFAULTS` — a list with nothing set: a table, unfiltered, unsorted, ungrouped, its columns and look the app's own.
|
|
174
175
|
- `settingsForSaving` — the settings a saved view keeps: all of them but the search. The value handed in is left as it is.
|
|
@@ -86,7 +86,7 @@ Four more field types, and growth in the relation, the rollup and the formula. E
|
|
|
86
86
|
|
|
87
87
|
**A rollup** aggregates over a relation (`over`), a declared inverse, or two relations for two hops (each far record counted once). Its functions are `count`, `countDistinct`, `sum`, `avg`, `min`, `max`, `earliest`, `latest`, `exists`, `none` and `first`. `where` is a filter tree on the far records; it may not filter across another relation. `within` names a far instant field, and a host counts only the far records whose value falls in the range its ask carries. `first` takes an `orderBy`. `exists` and `none` answer a boolean. `groupBy` (`{ option }` or `{ time, bucket }`) with a `headline` (`"total"` or `{ part }`) makes a breakdown, `{ headline, parts }` (`Breakdown`); only the headline sorts, filters and totals (`scalarOf`). `checkIndex` holds each of these to its far entity.
|
|
88
88
|
|
|
89
|
-
**A formula** carries a `rule`: a tree of `{ field }`, `{ value }` and `{ fn, args }` nodes over a closed list of functions (arithmetic and rounding, comparisons, `and` / `or` / `not`, `if` and `switch`, `coalesce` and `isEmpty`, text joining and trimming, `startsWith`, `endsWith`, `contains` and `before`, `today`, `now`, `daysBetween`, `secondsBetween`, `addDays`, `percentOf`). `checkFormula` checks it against the fields it reads; `evaluateFormula(rule, read, ctx, fields?)` evaluates it with SQL's null rules, and `round` rounds half away from zero. Both sides of a comparison, the branches of `if` and the values of `coalesce` share one type. A formula reads a grouped rollup as its headline, and formulas may not read each other round. A rule holds at most `FORMULA_MAX_NODES` (200) values, fields and calls, however deep it nests. `{ sql: "schema.name" }` names a database function; only a registry written in code may name one
|
|
89
|
+
**A formula** carries a `rule`: a tree of `{ field }`, `{ value }` and `{ fn, args }` nodes over a closed list of functions (arithmetic and rounding, comparisons, `and` / `or` / `not`, `if` and `switch`, `coalesce` and `isEmpty`, text joining and trimming, `startsWith`, `endsWith`, `contains` and `before`, `today`, `now`, `daysBetween`, `secondsBetween`, `addDays`, `percentOf`). `checkFormula` checks it against the fields it reads; `evaluateFormula(rule, read, ctx, fields?)` evaluates it with SQL's null rules, and `round` rounds half away from zero. Both sides of a comparison, the branches of `if` and the values of `coalesce` share one type. A formula reads a grouped rollup as its headline, and formulas may not read each other round. A rule holds at most `FORMULA_MAX_NODES` (200) values, fields and calls, however deep it nests. `{ sql: "schema.name" }` names a database function; only a registry written in code may name one, with `allowSql: true`.
|
|
90
90
|
|
|
91
91
|
**A relation rule** in a filter tree asks about the far records: `{ fieldKey, quantifier: "any" | "none" | "every", where }`. `checkFilterTree` holds it to the far entity and refuses an unknown quantifier, a missing `where` and a far kind the index lacks. A database adapter answers it; in memory it is answered when the reader hands in the far records (`related(row, fieldKey)`, each far row read with `recordReaderFor(farRow, farReader)`), "every" true for a row with none, and without them it has no opinion and the row stays. `isRelationRule(node)` tells it from a field rule when you walk a tree.
|
|
92
92
|
|
|
@@ -96,7 +96,7 @@ Four more field types, and growth in the relation, the rollup and the formula. E
|
|
|
96
96
|
|
|
97
97
|
**The types a person may create.** `creatableFieldTypes(conventions)`, from `viewkitjs/fields/definitions`, lists the twenty a New field dialog offers (never the actor, a lookup, a rollup or a formula), each with its `label` (`fieldTypeLabel`'s, New field's words), its `icon` (the type's key), `several`, its `settings` as data (`path`, `kind`, allowed `words`, `when`, `required`, `start`; a switch that is off is a removed key) and a starting `spec` `checkFieldSpec` accepts. Filter it; never re-type it. `FIELD_TYPES`, `STATUS_SLOTS` and `CATEGORY_COLORS` are the closed words at run time.
|
|
98
98
|
|
|
99
|
-
**A definition that arrives as data.** `checkFieldSpec` refuses
|
|
99
|
+
**A definition that arrives as data.** `checkFieldSpec` takes any value: it refuses a definition of the wrong shape (a key its type does not declare, a value of the wrong kind, a blank label, nesting past 408 levels) and every closed word it does not know, the type first, naming each. `defineFields` and `contributeFields` refuse a SQL formula unless you pass `allowSql: true`. `fieldSpecChanges(before, after)` (`viewkitjs/fields/definitions`) names every change between two definitions of one field, each with `reachesValues` (cautious: any validation change says true); allow or refuse each in your own words.
|
|
100
100
|
|
|
101
101
|
**Normalize steps.** A multiselect's `normalize` is a list of steps, `"trim"`, `"lowercase"` and `"hyphenate"`, never a function: `checkFieldSpec` refuses any function in a definition. `applyNormalize(steps, raw)` and `normalizerFor(field)` run them.
|
|
102
102
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "viewkitjs",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.20.0",
|
|
4
4
|
"description": "ViewKit — typed fields, the grid and its editors, and a list's SQL for record lists, in one package: viewkitjs/fields, viewkitjs/views and viewkitjs/postgres. By Sheaf.",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"repository": {
|
|
@@ -8,7 +8,9 @@
|
|
|
8
8
|
"url": "git+https://github.com/outright-agency/portal.git"
|
|
9
9
|
},
|
|
10
10
|
"type": "module",
|
|
11
|
-
"sideEffects":
|
|
11
|
+
"sideEffects": [
|
|
12
|
+
"**/*.css"
|
|
13
|
+
],
|
|
12
14
|
"files": [
|
|
13
15
|
"fields/dist",
|
|
14
16
|
"fields/docs",
|
|
@@ -26,6 +28,7 @@
|
|
|
26
28
|
"postgres/README.md",
|
|
27
29
|
"postgres/CHANGELOG.md",
|
|
28
30
|
"README.md",
|
|
31
|
+
"MIGRATION.md",
|
|
29
32
|
"CHANGELOG.md",
|
|
30
33
|
"LICENSE.md"
|
|
31
34
|
],
|
|
@@ -173,6 +176,8 @@
|
|
|
173
176
|
"types": "./views/dist/panels/react.d.ts",
|
|
174
177
|
"default": "./views/dist/panels/react.js"
|
|
175
178
|
},
|
|
179
|
+
"./views/styles.css": "./views/dist/styles.css",
|
|
180
|
+
"./views/styles.unlayered.css": "./views/dist/styles.unlayered.css",
|
|
176
181
|
"./postgres": {
|
|
177
182
|
"types": "./postgres/dist/index.d.ts",
|
|
178
183
|
"default": "./postgres/dist/index.js"
|
|
@@ -222,7 +227,7 @@
|
|
|
222
227
|
"@dnd-kit/utilities": "^3.2.2",
|
|
223
228
|
"@prisma/adapter-pg": "7.10.0",
|
|
224
229
|
"@prisma/client": "7.10.0",
|
|
225
|
-
"@tailwindcss/postcss": "
|
|
230
|
+
"@tailwindcss/postcss": "4.3.3",
|
|
226
231
|
"@testing-library/react": "^16.3.2",
|
|
227
232
|
"@types/node": "^20",
|
|
228
233
|
"@types/pg": "^8.20.0",
|
|
@@ -237,7 +242,7 @@
|
|
|
237
242
|
"prisma-client-6": "npm:@prisma/client@6.19.3",
|
|
238
243
|
"react": "19.2.0",
|
|
239
244
|
"react-dom": "19.2.0",
|
|
240
|
-
"tailwindcss": "
|
|
245
|
+
"tailwindcss": "4.3.3",
|
|
241
246
|
"typescript": "^5",
|
|
242
247
|
"vitest": "^4.1.5",
|
|
243
248
|
"zod": "^4.1.12"
|
|
@@ -249,7 +254,7 @@
|
|
|
249
254
|
"typecheck:postgres": "tsc -p postgres/tsconfig.json",
|
|
250
255
|
"build": "pnpm build:fields && pnpm build:views && pnpm build:postgres",
|
|
251
256
|
"build:fields": "node ../../scripts/clean-package-dist.mjs viewkit/fields && tsc -p fields/tsconfig.build.json && tsc -p fields/tsconfig.types.json && node ../../scripts/finalize-package-declarations.mjs viewkit/fields",
|
|
252
|
-
"build:views": "node ../../scripts/clean-package-dist.mjs viewkit/views && tsc -p views/tsconfig.build.json && tsc -p views/tsconfig.types.json && node ../../scripts/finalize-package-declarations.mjs viewkit/views",
|
|
257
|
+
"build:views": "node ../../scripts/clean-package-dist.mjs viewkit/views && tsc -p views/tsconfig.build.json && tsc -p views/tsconfig.types.json && node ../../scripts/finalize-package-declarations.mjs viewkit/views && node views/styles/build.ts",
|
|
253
258
|
"build:postgres": "node ../../scripts/clean-package-dist.mjs viewkit/postgres && tsc -p postgres/tsconfig.build.json && tsc -p postgres/tsconfig.types.json && node ../../scripts/finalize-package-declarations.mjs viewkit/postgres",
|
|
254
259
|
"check": "node ../../scripts/check-viewkit-package.mjs",
|
|
255
260
|
"bench": "node views/bench/run.ts",
|
|
@@ -259,6 +264,8 @@
|
|
|
259
264
|
"bench:picking": "node views/bench/picking-check.ts",
|
|
260
265
|
"bench:footer": "node views/bench/footer-check.ts",
|
|
261
266
|
"bench:chip": "node views/bench/chip-check.ts",
|
|
262
|
-
"bench:shift": "node views/bench/shift-check.ts"
|
|
267
|
+
"bench:shift": "node views/bench/shift-check.ts",
|
|
268
|
+
"styles:defaults": "node views/styles/defaults.ts",
|
|
269
|
+
"bench:stylesheet": "node views/bench/stylesheet-check.ts"
|
|
263
270
|
}
|
|
264
271
|
}
|
package/postgres/README.md
CHANGED
|
@@ -14,7 +14,7 @@ It loads no React: a Node script or a worker imports it with none installed.
|
|
|
14
14
|
|
|
15
15
|
```ts
|
|
16
16
|
import assert from "node:assert/strict";
|
|
17
|
-
import { defineFieldMap, keysQuery, sql } from "viewkitjs/postgres";
|
|
17
|
+
import { defineFieldMap, EVERY_FIELD, keysQuery, sql } from "viewkitjs/postgres";
|
|
18
18
|
|
|
19
19
|
const map = defineFieldMap({
|
|
20
20
|
table: "deals",
|
|
@@ -23,7 +23,7 @@ const map = defineFieldMap({
|
|
|
23
23
|
fields: { title: { value: "title", stored: "text" } },
|
|
24
24
|
});
|
|
25
25
|
const workspaceId = "00000000-0000-0000-0000-00000000000a";
|
|
26
|
-
const query = keysQuery({ map, access: { deals: (row) => sql`${row.column("workspace_id")} = ${workspaceId}` } });
|
|
26
|
+
const query = keysQuery({ map, readable: EVERY_FIELD, access: { deals: (row) => sql`${row.column("workspace_id")} = ${workspaceId}` } });
|
|
27
27
|
assert.deepEqual(query.values, [workspaceId]);
|
|
28
28
|
```
|
|
29
29
|
|
|
@@ -2,18 +2,23 @@ import type { FilterTree, ListHold, ViewSearch } from "viewkitjs/fields/query";
|
|
|
2
2
|
import type { CheckedNode } from "./check.js";
|
|
3
3
|
import { type FieldMap, type Read, type Row, type RowPick } from "./map.js";
|
|
4
4
|
import type { FilterContext } from "./rules.js";
|
|
5
|
+
import { type Readable, type ReadableFields } from "./readable.js";
|
|
5
6
|
import { type Sql } from "./sql.js";
|
|
6
7
|
/** Said instead of a condition, for a table whose every row the reader may read. */
|
|
7
8
|
export declare const EVERY_ROW: unique symbol;
|
|
8
9
|
/** A table's permission condition: a function of its row, or EVERY_ROW. */
|
|
9
10
|
export type Condition = ((row: Row) => Sql) | typeof EVERY_ROW;
|
|
10
|
-
/** The app's permission condition for each table of its map a query reaches, by the map's table keys
|
|
11
|
+
/** The app's permission condition for each table of its map a query reaches, by the map's table keys: which rows the
|
|
12
|
+
* reader may read. Which fields, a request's `readable` says. */
|
|
11
13
|
export type Access = Readonly<Record<string, Condition>>;
|
|
12
|
-
/** A request: the app's map
|
|
13
|
-
* them, and what a date rule reads. */
|
|
14
|
+
/** A request: the app's map, its permission condition and the fields the reader may read; a list's filter, its search,
|
|
15
|
+
* a quick-filter hold on top of them, and what a date rule reads. */
|
|
14
16
|
export type KeysRequest = {
|
|
15
17
|
readonly map: FieldMap;
|
|
16
18
|
readonly access: Access;
|
|
19
|
+
/** The fields the reader may read, per table of the map: EVERY_FIELD when the reader may read them all. A request
|
|
20
|
+
* without it is refused (`no-field-list`). */
|
|
21
|
+
readonly readable: Readable;
|
|
17
22
|
readonly filter?: FilterTree;
|
|
18
23
|
readonly search?: ViewSearch;
|
|
19
24
|
/** A quick-filter hold on top of the filter (fields' `ListHold`): a row stays only if it passes both. Never part of
|
|
@@ -28,6 +33,8 @@ export type Walk = (scope: Scope, at: Opened, node: CheckedNode) => Sql;
|
|
|
28
33
|
export type Scope = {
|
|
29
34
|
readonly map: FieldMap;
|
|
30
35
|
readonly access: Access;
|
|
36
|
+
/** The fields the reader may read, checked and frozen: every field a statement reads is held to it. */
|
|
37
|
+
readonly readable: ReadableFields;
|
|
31
38
|
readonly context: FilterContext | undefined;
|
|
32
39
|
alias(prefix: "r" | "f" | "e"): string;
|
|
33
40
|
walk(at: Opened, node: CheckedNode): Sql;
|
|
@@ -38,7 +45,8 @@ export type Opened = {
|
|
|
38
45
|
readonly from: Sql;
|
|
39
46
|
readonly row: Row;
|
|
40
47
|
};
|
|
41
|
-
/** The request's scope, its map and its
|
|
48
|
+
/** The request's scope, its map, its access and its readable fields checked whole first; `walk` walks a relation's own
|
|
49
|
+
* `where`. */
|
|
42
50
|
export declare function scopeOf(request: KeysRequest, walk?: Walk): Scope;
|
|
43
51
|
/** The collation the map's textSort names, quoted whole as one name (`"und-x-icu"`, `"en_US.utf8"`); undefined when it
|
|
44
52
|
* names none. Here because only this file quotes a name. */
|
package/postgres/dist/access.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { isFieldMap } from "./map.js";
|
|
2
|
+
import { readableOf } from "./readable.js";
|
|
2
3
|
import { REFUSALS } from "./refusals.js";
|
|
3
4
|
import { deferred, identifier, isSql, join, pickLiteral, render, sql, TRUE } from "./sql.js";
|
|
4
5
|
export const EVERY_ROW = Symbol("EVERY_ROW");
|
|
@@ -25,10 +26,12 @@ export function scopeOf(request, walk = NO_WALK) {
|
|
|
25
26
|
for (const [table, condition] of entries)
|
|
26
27
|
access[table] = condition;
|
|
27
28
|
Object.freeze(access);
|
|
29
|
+
const readable = readableOf(map, request.readable);
|
|
28
30
|
let count = 0;
|
|
29
31
|
const scope = {
|
|
30
32
|
map,
|
|
31
33
|
access,
|
|
34
|
+
readable,
|
|
32
35
|
context: request.context,
|
|
33
36
|
alias: (prefix) => `vk_${prefix}${count++}`,
|
|
34
37
|
walk: (at, node) => walk(scope, at, node),
|
|
@@ -4,6 +4,7 @@ import { boundOf, bucketingFor, dateColumn, isDateType, OPEN_END } from "./date-
|
|
|
4
4
|
import { kept } from "./kept.js";
|
|
5
5
|
import { REFUSALS } from "./refusals.js";
|
|
6
6
|
import { countOf } from "./steps.js";
|
|
7
|
+
import { readableField } from "./readable.js";
|
|
7
8
|
export const CALENDAR_DAYS_LIMIT = 42;
|
|
8
9
|
export const CALENDAR_ROWS_LIMIT = 500;
|
|
9
10
|
export const CALENDAR_DAY_ROWS = 2;
|
|
@@ -28,9 +29,9 @@ function daysOf(from, to) {
|
|
|
28
29
|
export function calendarQuery(request) {
|
|
29
30
|
const { scope, main, where } = kept(request);
|
|
30
31
|
const key = request.fieldKey;
|
|
31
|
-
|
|
32
|
+
const field = readableField(scope, scope.map.table, key);
|
|
33
|
+
if (field === undefined)
|
|
32
34
|
throw REFUSALS.unknownField(key);
|
|
33
|
-
const field = scope.map.fields[key];
|
|
34
35
|
if (!isDateType(field.type))
|
|
35
36
|
throw REFUSALS.noLayout(key, "calendar");
|
|
36
37
|
const days = daysOf(request.from, request.to);
|
package/postgres/dist/check.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { type FilterNode, type FilterTree } from "viewkitjs/fields/query";
|
|
2
2
|
import { type FieldMap } from "./map.js";
|
|
3
|
+
import { type Reader } from "./readable.js";
|
|
3
4
|
import { type CheckedRule, type FilterContext } from "./rules.js";
|
|
4
5
|
/**
|
|
5
6
|
* A relation rule held to its field: the field's key on its own table, the map's relation it reads, its quantifier,
|
|
@@ -37,17 +38,18 @@ export declare function walkTree(map: FieldMap, tree: FilterTree, path: string,
|
|
|
37
38
|
/** `tree` held to `map`'s caps (its rules and groups, its depth), refused as too big at the first node past one, before
|
|
38
39
|
* anything recurses into it. Nothing to hold when there is no tree. */
|
|
39
40
|
export declare function capTree(map: FieldMap, tree: FilterTree | undefined, path?: string): void;
|
|
40
|
-
/** `tree` held to
|
|
41
|
-
|
|
41
|
+
/** `tree` held to the reader's map, its caps and its readable fields: the checked tree with only what has an opinion,
|
|
42
|
+
* or null when nothing has one. */
|
|
43
|
+
export declare function checkTree(reader: Reader, tree: FilterTree, context: FilterContext | undefined): CheckedNode | null;
|
|
42
44
|
/**
|
|
43
45
|
* Field `key`'s own `where` (a relation of several records on table `table`), held to its far table's fields as a
|
|
44
46
|
* relation rule's `where` is, at `<field>.where`; null when it names none or nothing in it has an opinion. It holds no
|
|
45
47
|
* relation rule (fields refuses one), and no date or phone rule yet: a page's cursor can't see what those read.
|
|
46
48
|
*/
|
|
47
|
-
export declare function checkOwnWhere(
|
|
49
|
+
export declare function checkOwnWhere(reader: Reader, table: string, key: string, context: FilterContext | undefined): CheckedNode | null;
|
|
48
50
|
/**
|
|
49
51
|
* A rollup's own `where`, held to its far table `table`'s fields at `path`, as a relation rule's `where` is: a date rule
|
|
50
52
|
* read in the request's context, no relation rule (fields refuses one in a rollup's where). Null when nothing in it has
|
|
51
53
|
* an opinion.
|
|
52
54
|
*/
|
|
53
|
-
export declare function checkFarWhere(
|
|
55
|
+
export declare function checkFarWhere(reader: Reader, table: string, where: FilterTree, path: string, context: FilterContext | undefined): CheckedNode | null;
|
package/postgres/dist/check.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { defineConventions, isMultipleType } from "viewkitjs/fields";
|
|
2
2
|
import { filterPartsFor, filterValueSchema, operatorsForField, ruleIsActive, whereWaits, } from "viewkitjs/fields/query";
|
|
3
3
|
import { fieldsOf, isOneRelation } from "./map.js";
|
|
4
|
+
import { readableField } from "./readable.js";
|
|
4
5
|
import { REFUSALS } from "./refusals.js";
|
|
5
6
|
import { currenciesProblem } from "./rules.js";
|
|
6
7
|
const TEXT_TYPES = new Set([
|
|
@@ -163,15 +164,24 @@ export function capTree(map, tree, path = "filter") {
|
|
|
163
164
|
return;
|
|
164
165
|
walkTree(map, tree, path, [capsOf(map)]);
|
|
165
166
|
}
|
|
166
|
-
|
|
167
|
-
|
|
167
|
+
function readableVisitor(reader) {
|
|
168
|
+
return (node, _at, _depth, table) => {
|
|
169
|
+
const key = Reflect.get(node, "fieldKey");
|
|
170
|
+
if (table !== undefined && typeof key === "string")
|
|
171
|
+
readableField(reader, table, key);
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
export function checkTree(reader, tree, context) {
|
|
175
|
+
const { map } = reader;
|
|
176
|
+
walkTree(map, tree, "filter", [capsOf(map), readableVisitor(reader)]);
|
|
168
177
|
checkContext(context);
|
|
169
|
-
return groupChecker(
|
|
178
|
+
return groupChecker(reader, context, false)(tree.op, tree.items, "filter", map.table, false);
|
|
170
179
|
}
|
|
171
180
|
const OWN_ACROSS = "a relation's where filters the far records' own fields, not across another relation";
|
|
172
|
-
export function checkOwnWhere(
|
|
181
|
+
export function checkOwnWhere(reader, table, key, context) {
|
|
182
|
+
const { map } = reader;
|
|
173
183
|
checkContext(context);
|
|
174
|
-
const { def, mapping } =
|
|
184
|
+
const { def, mapping } = readableField(reader, table, key);
|
|
175
185
|
const where = def.where;
|
|
176
186
|
if (where === undefined)
|
|
177
187
|
return null;
|
|
@@ -181,10 +191,10 @@ export function checkOwnWhere(map, table, key, context) {
|
|
|
181
191
|
throw REFUSALS.noFields(key, to, path);
|
|
182
192
|
if (typeof where !== "object" || where === null || (where.op !== "and" && where.op !== "or") || !Array.isArray(where.items))
|
|
183
193
|
throw REFUSALS.badRule(path, "a relation's where joins its rules with and or or");
|
|
184
|
-
return groupChecker(
|
|
194
|
+
return groupChecker(reader, context, true)(where.op, where.items, path, to, true);
|
|
185
195
|
}
|
|
186
196
|
const ROLLUP_ACROSS = "a rollup's where filters the far records' own fields, not across another relation";
|
|
187
|
-
export function checkFarWhere(
|
|
197
|
+
export function checkFarWhere(reader, table, where, path, context) {
|
|
188
198
|
checkContext(context);
|
|
189
199
|
if (typeof where !== "object" || where === null || (where.op !== "and" && where.op !== "or") || !Array.isArray(where.items))
|
|
190
200
|
throw REFUSALS.badRule(path, "a rollup's where joins its rules with and or or");
|
|
@@ -196,17 +206,18 @@ export function checkFarWhere(map, table, where, path, context) {
|
|
|
196
206
|
across(item.items, itemPath);
|
|
197
207
|
});
|
|
198
208
|
across(where.items, path);
|
|
199
|
-
return groupChecker(
|
|
209
|
+
return groupChecker(reader, context, false)(where.op, where.items, path, table, true);
|
|
200
210
|
}
|
|
201
|
-
function groupChecker(
|
|
211
|
+
function groupChecker(reader, context, ownWhere) {
|
|
212
|
+
const { map } = reader;
|
|
202
213
|
const at = (table, far, key) => far && table !== map.table ? `tables.${table}.fields.${key}` : `fields.${key}`;
|
|
203
214
|
const fieldOf = (table, far, key) => {
|
|
204
|
-
const
|
|
205
|
-
if (
|
|
206
|
-
return
|
|
215
|
+
const field = readableField(reader, table, key);
|
|
216
|
+
if (field !== undefined)
|
|
217
|
+
return field;
|
|
207
218
|
if (!far)
|
|
208
219
|
throw REFUSALS.unknownField(key);
|
|
209
|
-
if (!
|
|
220
|
+
if (!fieldsOf(map, table).defined.includes(key))
|
|
210
221
|
return null;
|
|
211
222
|
throw REFUSALS.unknownFarField(table, key);
|
|
212
223
|
};
|
|
@@ -287,10 +298,10 @@ function groupChecker(map, context, ownWhere) {
|
|
|
287
298
|
}
|
|
288
299
|
const within = isOneRelation(map.relations[value.relation]) ? undefined : def.within;
|
|
289
300
|
if (within !== undefined) {
|
|
290
|
-
const instant =
|
|
291
|
-
if (
|
|
301
|
+
const instant = typeof within === "string" ? readableField(reader, to, within) : undefined;
|
|
302
|
+
if (instant === undefined)
|
|
292
303
|
throw REFUSALS.unknownFarField(to, String(within));
|
|
293
|
-
if (instant
|
|
304
|
+
if (instant.type !== "datetime")
|
|
294
305
|
throw REFUSALS.badRule(path, `${def.label}'s within reads an instant`);
|
|
295
306
|
}
|
|
296
307
|
const kept = groupOf(where.op, where.items, `${path}.where`, to, true);
|
package/postgres/dist/counts.js
CHANGED
|
@@ -7,6 +7,7 @@ import { isFieldMap } from "./map.js";
|
|
|
7
7
|
import { REFUSALS } from "./refusals.js";
|
|
8
8
|
import { render, sql, TRUE } from "./sql.js";
|
|
9
9
|
import { countOf } from "./steps.js";
|
|
10
|
+
import { readableField } from "./readable.js";
|
|
10
11
|
export const DISTINCT_LIMIT = 1000;
|
|
11
12
|
const whereOf = (where) => (where === TRUE ? sql `` : sql ` WHERE ${where}`);
|
|
12
13
|
export function totalQuery(request) {
|
|
@@ -38,9 +39,9 @@ const COUNTED = new Set([
|
|
|
38
39
|
"boolean",
|
|
39
40
|
]);
|
|
40
41
|
export function heldField(scope, key, countable) {
|
|
41
|
-
|
|
42
|
+
const field = readableField(scope, scope.map.table, key);
|
|
43
|
+
if (field === undefined)
|
|
42
44
|
throw REFUSALS.unknownField(key);
|
|
43
|
-
const field = scope.map.fields[key];
|
|
44
45
|
if (!countable(field.type))
|
|
45
46
|
throw REFUSALS.noOptions(key, field.type);
|
|
46
47
|
return field;
|
|
@@ -2,6 +2,7 @@ import { defineFieldMap, FieldMapError } from "../map.js";
|
|
|
2
2
|
import { labelOf } from "./label.js";
|
|
3
3
|
import { placeField, REASONS } from "./place.js";
|
|
4
4
|
import { checkInput, StorageError } from "./storage.js";
|
|
5
|
+
import { fieldsReadBy } from "../readable.js";
|
|
5
6
|
const FAR = "far:";
|
|
6
7
|
function withoutNotNull(mapping) {
|
|
7
8
|
if (!("notNull" in mapping))
|
|
@@ -140,6 +141,12 @@ export function buildFieldMap(input) {
|
|
|
140
141
|
catch (error) {
|
|
141
142
|
throw handWrittenRefusal(error, tables, checked.handWritten) ?? error;
|
|
142
143
|
}
|
|
144
|
+
const fieldsRead = new Map();
|
|
145
|
+
for (const [address, result] of memo) {
|
|
146
|
+
if (!("leftOut" in result) && result.fields !== undefined && result.fields.length > 0)
|
|
147
|
+
fieldsRead.set(address, result.fields);
|
|
148
|
+
}
|
|
149
|
+
fieldsReadBy(map, fieldsRead);
|
|
143
150
|
const frozenReads = Object.fromEntries(reads.map(([table, entry]) => [
|
|
144
151
|
table,
|
|
145
152
|
Object.freeze({
|
|
@@ -9,6 +9,7 @@ import { labelOf as kindLabelOf } from "./label.js";
|
|
|
9
9
|
import { keptOf } from "./money.js";
|
|
10
10
|
import { named, numberOf } from "./float.js";
|
|
11
11
|
import { formulaSql, instantOfSpelled, textOf } from "./formula-forms.js";
|
|
12
|
+
import { workedOut } from "./place.js";
|
|
12
13
|
export const FORMULA_REASONS = {
|
|
13
14
|
noRule: "a formula with no rule is not built",
|
|
14
15
|
namedSql: (name) => `names the SQL function ${name}, which the builder doesn't write`,
|
|
@@ -196,7 +197,7 @@ export const placeFormula = (at) => {
|
|
|
196
197
|
});
|
|
197
198
|
}
|
|
198
199
|
const stored = storedOf(resultType);
|
|
199
|
-
const value = (row) => {
|
|
200
|
+
const value = workedOut((row) => {
|
|
200
201
|
const opened = openedOf(row);
|
|
201
202
|
if (opened === undefined)
|
|
202
203
|
throw new TypeError(`${def.key}: a formula is read only on a row the translator opened`);
|
|
@@ -204,6 +205,7 @@ export const placeFormula = (at) => {
|
|
|
204
205
|
const mappings = scope.map.tableFields[on.table].fields;
|
|
205
206
|
const read = (key) => readField(scope, on, mappings[key].def, mappings[key].mapping, types.get(key));
|
|
206
207
|
return outputOf(formulaSql(rule, read, clockOf(def.key, scope)), stored);
|
|
207
|
-
};
|
|
208
|
-
|
|
208
|
+
});
|
|
209
|
+
const fields = readsOf(rule).map((key) => ({ table: at.table, key }));
|
|
210
|
+
return { mapping: { value: zoned ? readsZone(value) : value, stored }, reads, fields };
|
|
209
211
|
};
|
|
@@ -57,7 +57,11 @@ export const placeLookup = (at) => {
|
|
|
57
57
|
...(given.search === undefined ? {} : { search: reading(given.search) }),
|
|
58
58
|
...(sort === undefined ? {} : { sort: marked(through(sort)) }),
|
|
59
59
|
};
|
|
60
|
-
|
|
60
|
+
const fields = [
|
|
61
|
+
{ table: at.table, key: def.via },
|
|
62
|
+
{ table: to, key: def.field },
|
|
63
|
+
];
|
|
64
|
+
return { mapping, reads: [...via.reads, ...far.reads], fields };
|
|
61
65
|
};
|
|
62
66
|
function sortReadOf(far, def, value) {
|
|
63
67
|
const type = valueTypeOf(def);
|
|
@@ -76,5 +76,10 @@ export function placeConverted(at, base) {
|
|
|
76
76
|
return into === undefined ? kept(row) : convert(row, into);
|
|
77
77
|
};
|
|
78
78
|
KEPT.set(value, kept);
|
|
79
|
-
|
|
79
|
+
const fields = [
|
|
80
|
+
...("fields" in base ? (base.fields ?? []) : []),
|
|
81
|
+
{ table, key: codeKey },
|
|
82
|
+
...(typeof conversion.at === "object" ? [{ table, key: conversion.at.field }] : []),
|
|
83
|
+
];
|
|
84
|
+
return { mapping: { value, stored: "numeric" }, reads, convert, fields };
|
|
80
85
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { type FieldDef } from "viewkitjs/fields";
|
|
2
2
|
import type { FieldMapping, RelationMap, Row } from "../map.js";
|
|
3
|
+
import { type FieldAt } from "../readable.js";
|
|
3
4
|
import type { Sql } from "../sql.js";
|
|
4
5
|
import { type MoneyInto } from "./money.js";
|
|
5
6
|
import type { CheckedInput, CheckedKind } from "./storage.js";
|
|
@@ -16,6 +17,9 @@ export type Placed = {
|
|
|
16
17
|
readonly key: string;
|
|
17
18
|
readonly map: RelationMap;
|
|
18
19
|
};
|
|
20
|
+
/** The other fields its value is worked out from, each on its own table: a reader who may not read one of them
|
|
21
|
+
* may not read this one. */
|
|
22
|
+
readonly fields?: readonly FieldAt[];
|
|
19
23
|
readonly handWritten?: true;
|
|
20
24
|
/** An amount that converts: this amount on `row` (a row `open` built, a far one included), converted on
|
|
21
25
|
* that row's own day into `into`, as numeric. What a rollup adds up. */
|
|
@@ -37,6 +41,9 @@ export type Placing = {
|
|
|
37
41
|
/** Field `field` of table `table`, placed once and kept: what a worked-out field reads through. */
|
|
38
42
|
placed(table: string, field: string): Placed;
|
|
39
43
|
};
|
|
44
|
+
/** A worked-out field's own read: the fields it reads are read with no list, since the door held them (`readingWorkedOut`).
|
|
45
|
+
* So every field its read can reach must be in its `Placed.fields`: one left out there is read unchecked. */
|
|
46
|
+
export declare function workedOut(read: (row: Row) => Sql): (row: Row) => Sql;
|
|
40
47
|
/** One kind of field's placer: each lives in a file of its own. */
|
|
41
48
|
export type Place = (at: Placing) => Placed;
|
|
42
49
|
/** Why a field is left out, for the reasons the seam itself gives. */
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { conversionOf, valueTypeOf } from "viewkitjs/fields";
|
|
2
|
+
import { openedOf } from "../access.js";
|
|
3
|
+
import { readingWorkedOut } from "../readable.js";
|
|
2
4
|
import { placeFormula } from "./formula.js";
|
|
3
5
|
import { placeLookup } from "./lookup.js";
|
|
4
6
|
import { placeConverted } from "./money.js";
|
|
@@ -6,6 +8,12 @@ import { placeRelation } from "./relations.js";
|
|
|
6
8
|
import { placeRollup } from "./rollup.js";
|
|
7
9
|
import { placeStored } from "./stored.js";
|
|
8
10
|
import { placeUser } from "./user.js";
|
|
11
|
+
export function workedOut(read) {
|
|
12
|
+
return (row) => {
|
|
13
|
+
const opened = openedOf(row);
|
|
14
|
+
return opened === undefined ? read(row) : readingWorkedOut(opened.scope, () => read(row));
|
|
15
|
+
};
|
|
16
|
+
}
|
|
9
17
|
export const REASONS = {
|
|
10
18
|
notKept: "its table keeps nothing for it",
|
|
11
19
|
actor: "an actor is not read from a storage yet",
|