viewkitjs 0.28.0 → 0.29.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 +107 -0
- package/MIGRATION.md +85 -4
- package/fields/dist/derived.d.ts +2 -1
- package/fields/dist/derived.js +9 -3
- package/fields/dist/entities.js +41 -3
- package/fields/dist/index.d.ts +1 -1
- package/fields/dist/index.js +1 -1
- package/fields/dist/messages.d.ts +8 -2
- package/fields/dist/messages.js +3 -0
- package/fields/dist/range.d.ts +6 -0
- package/fields/dist/range.js +8 -0
- package/fields/dist/registry.js +11 -1
- package/fields/dist/spec-changes.js +1 -0
- package/fields/dist/types.d.ts +23 -1
- package/fields/docs/guides/derived-fields.md +7 -5
- package/fields/docs/guides/field-types.md +2 -2
- package/fields/docs/guides/the-index.md +1 -1
- package/fields/docs/reference/fields.md +3 -1
- package/fields/docs/reference/types.md +3 -1
- package/fields/skills/viewkit/SKILL.md +1 -1
- package/package.json +2 -1
- package/postgres/dist/definitions/build.js +29 -5
- package/postgres/dist/definitions/label.d.ts +7 -0
- package/postgres/dist/definitions/label.js +9 -1
- package/postgres/dist/definitions/lookup.js +6 -2
- package/postgres/dist/definitions/place.d.ts +6 -3
- package/postgres/dist/definitions/rollup.js +5 -1
- package/postgres/dist/definitions/storage.d.ts +15 -0
- package/postgres/dist/definitions/storage.js +52 -1
- package/postgres/dist/definitions/stored.js +21 -0
- package/postgres/dist/phone.d.ts +13 -1
- package/postgres/dist/phone.js +23 -3
- package/postgres/dist/search-indexes.d.ts +6 -1
- package/postgres/dist/search-indexes.js +71 -25
- package/postgres/dist/search.js +3 -3
- package/postgres/docs/guides/definitions.md +22 -5
- package/postgres/docs/guides/field-map.md +5 -4
- package/postgres/docs/reference/definitions.md +3 -3
- package/postgres/docs/reference/postgres.md +1 -1
- package/views/dist/cells/cell-format.js +2 -2
- package/views/dist/cells/cell-values.js +9 -10
- package/views/dist/contract.d.ts +149 -3
- package/views/dist/contract.js +157 -1
- package/views/dist/controls/bulk-bar/bulk-bar-of.d.ts +66 -0
- package/views/dist/controls/bulk-bar/bulk-bar-of.js +22 -0
- package/views/dist/controls/bulk-bar/bulk-bar.d.ts +40 -0
- package/views/dist/controls/bulk-bar/bulk-bar.js +278 -0
- package/views/dist/controls/bulk-bar/looks.d.ts +10 -0
- package/views/dist/controls/bulk-bar/looks.js +14 -0
- package/views/dist/controls/bulk-bar/map-selection-bar.d.ts +19 -0
- package/views/dist/controls/bulk-bar/map-selection-bar.js +57 -0
- package/views/dist/controls/bulk-bar/tokens.d.ts +136 -0
- package/views/dist/controls/bulk-bar/tokens.js +36 -0
- package/views/dist/controls/bulk-bar/words.d.ts +50 -0
- package/views/dist/controls/bulk-bar/words.js +19 -0
- package/views/dist/controls/bulk-bar.css +96 -0
- package/views/dist/controls/button/button.js +3 -1
- package/views/dist/controls/button.css +5 -4
- package/views/dist/controls/checkbox/checkbox.js +3 -1
- package/views/dist/controls/checkbox.css +1 -1
- package/views/dist/controls/choice/tokens.d.ts +79 -0
- package/views/dist/controls/choice/tokens.js +22 -0
- package/views/dist/controls/choice.css +31 -0
- package/views/dist/controls/compound-editor/looks.js +1 -1
- package/views/dist/controls/controls.d.ts +10 -0
- package/views/dist/controls/controls.js +8 -0
- package/views/dist/controls/customize/customize.d.ts +125 -0
- package/views/dist/controls/customize/customize.js +243 -0
- package/views/dist/controls/customize/glide.d.ts +10 -0
- package/views/dist/controls/customize/glide.js +55 -0
- package/views/dist/controls/customize/looks.d.ts +13 -0
- package/views/dist/controls/customize/looks.js +11 -0
- package/views/dist/controls/customize/map-customize-body.d.ts +18 -0
- package/views/dist/controls/customize/map-customize-body.js +160 -0
- package/views/dist/controls/customize/rules.d.ts +23 -0
- package/views/dist/controls/customize/rules.js +19 -0
- package/views/dist/controls/customize/tokens.d.ts +40 -0
- package/views/dist/controls/customize/tokens.js +12 -0
- package/views/dist/controls/customize/words.d.ts +58 -0
- package/views/dist/controls/customize/words.js +37 -0
- package/views/dist/controls/customize.css +54 -0
- package/views/dist/controls/date-editor/looks.js +1 -1
- package/views/dist/controls/filter-editor/block.d.ts +31 -0
- package/views/dist/controls/filter-editor/block.js +27 -0
- package/views/dist/controls/filter-editor/filter-editor.d.ts +2 -0
- package/views/dist/controls/filter-editor/filter-editor.js +85 -43
- package/views/dist/controls/filter-editor/how.d.ts +1 -1
- package/views/dist/controls/filter-editor/how.js +1 -0
- package/views/dist/controls/filter-editor/map-filter-body.d.ts +16 -1
- package/views/dist/controls/filter-editor/map-filter-body.js +39 -13
- package/views/dist/controls/filter-editor/map-rules.d.ts +27 -11
- package/views/dist/controls/filter-editor/map-rules.js +73 -42
- package/views/dist/controls/filter-editor/rules.d.ts +43 -5
- package/views/dist/controls/filter-editor/rules.js +55 -2
- package/views/dist/controls/filter-editor/words.d.ts +15 -0
- package/views/dist/controls/filter-editor/words.js +6 -0
- package/views/dist/controls/filter-editor.css +18 -0
- package/views/dist/controls/index.d.ts +26 -2
- package/views/dist/controls/index.js +25 -2
- package/views/dist/controls/inline-input/looks.js +1 -1
- package/views/dist/controls/input/input.js +10 -4
- package/views/dist/controls/internal/phone.d.ts +5 -4
- package/views/dist/controls/internal/phone.js +7 -7
- package/views/dist/controls/internal/scroll.js +5 -1
- package/views/dist/controls/internal/typed-run.d.ts +2 -0
- package/views/dist/controls/internal/typed-run.js +5 -0
- package/views/dist/controls/menu/map-menu.js +2 -2
- package/views/dist/controls/number-editor/looks.js +1 -1
- package/views/dist/controls/option/option.js +3 -1
- package/views/dist/controls/option.css +1 -1
- package/views/dist/controls/pane/pane.d.ts +4 -0
- package/views/dist/controls/pane/pane.js +2 -1
- package/views/dist/controls/picker/looks.js +1 -1
- package/views/dist/controls/picker/map-picker.d.ts +6 -2
- package/views/dist/controls/picker/map-picker.js +4 -2
- package/views/dist/controls/picker/picker.d.ts +7 -0
- package/views/dist/controls/picker/picker.js +57 -8
- package/views/dist/controls/popover/map-popover.d.ts +1 -1
- package/views/dist/controls/popover/map-popover.js +2 -2
- package/views/dist/controls/popover/popover.js +2 -1
- package/views/dist/controls/popover.css +3 -0
- package/views/dist/controls/ports-host/map-ports-host.d.ts +7 -0
- package/views/dist/controls/ports-host/map-ports-host.js +43 -0
- package/views/dist/controls/press/tokens.d.ts +8 -0
- package/views/dist/controls/press/tokens.js +4 -0
- package/views/dist/controls/press.css +44 -0
- package/views/dist/controls/quick-filters/looks.d.ts +11 -0
- package/views/dist/controls/quick-filters/looks.js +9 -0
- package/views/dist/controls/quick-filters/map-quick-filters-body.d.ts +31 -0
- package/views/dist/controls/quick-filters/map-quick-filters-body.js +56 -0
- package/views/dist/controls/quick-filters/quick-filters.d.ts +37 -0
- package/views/dist/controls/quick-filters/quick-filters.js +89 -0
- package/views/dist/controls/quick-filters/reminder.d.ts +18 -0
- package/views/dist/controls/quick-filters/reminder.js +41 -0
- package/views/dist/controls/quick-filters/rules.d.ts +89 -0
- package/views/dist/controls/quick-filters/rules.js +52 -0
- package/views/dist/controls/quick-filters/tokens.d.ts +112 -0
- package/views/dist/controls/quick-filters/tokens.js +30 -0
- package/views/dist/controls/quick-filters/words.d.ts +25 -0
- package/views/dist/controls/quick-filters/words.js +13 -0
- package/views/dist/controls/quick-filters.css +118 -0
- package/views/dist/controls/sheet/bottom-sheet.d.ts +9 -4
- package/views/dist/controls/sheet/bottom-sheet.js +4 -4
- package/views/dist/controls/sheet/map-sheet.d.ts +4 -1
- package/views/dist/controls/sheet/map-sheet.js +19 -6
- package/views/dist/controls/sheet/sheet-parts.d.ts +10 -0
- package/views/dist/controls/sheet/sheet-parts.js +2 -0
- package/views/dist/controls/switch-row/switch-row.d.ts +15 -0
- package/views/dist/controls/switch-row/switch-row.js +9 -0
- package/views/dist/controls/switch-row/tokens.d.ts +51 -0
- package/views/dist/controls/switch-row/tokens.js +15 -0
- package/views/dist/controls/switch-row.css +39 -0
- package/views/dist/controls/switch.css +1 -1
- package/views/dist/controls/tag/tag.js +3 -1
- package/views/dist/controls/tag-field/tag-field.d.ts +20 -0
- package/views/dist/controls/tag-field/tag-field.js +19 -0
- package/views/dist/controls/tag-field/tokens.d.ts +7 -0
- package/views/dist/controls/tag-field/tokens.js +4 -0
- package/views/dist/controls/tag-field.css +13 -0
- package/views/dist/controls/text-editor/looks.js +1 -1
- package/views/dist/controls/text-editor/text-editor.js +1 -5
- package/views/dist/controls/toast/toast.d.ts +5 -1
- package/views/dist/controls/toast/toast.js +5 -3
- package/views/dist/controls/tokens.js +18 -0
- package/views/dist/controls/toolbar/keys.d.ts +3 -0
- package/views/dist/controls/toolbar/keys.js +11 -0
- package/views/dist/controls/toolbar/looks.d.ts +10 -0
- package/views/dist/controls/toolbar/looks.js +40 -0
- package/views/dist/controls/toolbar/tokens.d.ts +28 -0
- package/views/dist/controls/toolbar/tokens.js +9 -0
- package/views/dist/controls/toolbar/toolbar.d.ts +111 -0
- package/views/dist/controls/toolbar/toolbar.js +370 -0
- package/views/dist/controls/toolbar/words.d.ts +28 -0
- package/views/dist/controls/toolbar/words.js +17 -0
- package/views/dist/controls/toolbar-button/looks.d.ts +4 -0
- package/views/dist/controls/toolbar-button/looks.js +21 -0
- package/views/dist/controls/toolbar-button/tokens.d.ts +103 -0
- package/views/dist/controls/toolbar-button/tokens.js +28 -0
- package/views/dist/controls/toolbar-button/toolbar-button.d.ts +66 -0
- package/views/dist/controls/toolbar-button/toolbar-button.js +51 -0
- package/views/dist/controls/toolbar-button.css +75 -0
- package/views/dist/controls/toolbar.css +65 -0
- package/views/dist/controls/tooltip/map-tooltip.d.ts +1 -1
- package/views/dist/controls/tooltip/map-tooltip.js +2 -2
- package/views/dist/controls/tooltip/tooltip.d.ts +3 -1
- package/views/dist/controls/tooltip/tooltip.js +2 -2
- package/views/dist/controls/values-editor/looks.js +1 -1
- package/views/dist/controls/views-list/map-views-list-body.d.ts +4 -1
- package/views/dist/controls/views-list/map-views-list-body.js +128 -4
- package/views/dist/controls/views-list/rules.d.ts +26 -0
- package/views/dist/controls/views-list/rules.js +63 -0
- package/views/dist/controls/views-list/view-menu.d.ts +84 -0
- package/views/dist/controls/views-list/view-menu.js +201 -0
- package/views/dist/controls/views-list/views-list.d.ts +8 -1
- package/views/dist/controls/views-list/views-list.js +18 -3
- package/views/dist/controls/views-list/words.d.ts +54 -0
- package/views/dist/controls/views-list/words.js +10 -1
- package/views/dist/controls/views-list.css +5 -1
- package/views/dist/display/date.js +3 -3
- package/views/dist/display/format.d.ts +6 -0
- package/views/dist/display/format.js +3 -0
- package/views/dist/display/index.d.ts +1 -1
- package/views/dist/display/index.js +1 -1
- package/views/dist/display/range.d.ts +2 -1
- package/views/dist/display/range.js +4 -1
- package/views/dist/grid/chrome/GridHeader.js +2 -1
- package/views/dist/grid/chrome/GridNumberEditor.js +2 -2
- package/views/dist/grid/chrome/GridRowCells.js +2 -1
- package/views/dist/grid/chrome/GridTextEditor.js +2 -2
- package/views/dist/grid/chrome/grid-editor-layer.d.ts +5 -1
- package/views/dist/grid/chrome/grid-editor-layer.js +1 -0
- package/views/dist/grid/chrome/grid-fitted-box.d.ts +7 -1
- package/views/dist/grid/chrome/grid-fitted-box.js +4 -4
- package/views/dist/grid/core/clipboard-model.js +9 -4
- package/views/dist/grid/grid.css +240 -0
- package/views/dist/grid/looks.d.ts +5 -1
- package/views/dist/grid/looks.js +20 -12
- package/views/dist/grid-tokens.d.ts +109 -0
- package/views/dist/grid-tokens.js +29 -0
- package/views/dist/looks/index.d.ts +5 -0
- package/views/dist/looks/index.js +5 -0
- package/views/dist/looks/pieces.js +10 -0
- package/views/dist/model/column-capabilities.d.ts +2 -0
- package/views/dist/model/column-filters.d.ts +2 -1
- package/views/dist/model/column-from.js +2 -2
- package/views/dist/model/relation-filters.d.ts +2 -0
- package/views/dist/panels/index.d.ts +2 -2
- package/views/dist/panels/index.js +2 -2
- package/views/dist/panels/labels.d.ts +4 -0
- package/views/dist/panels/labels.js +8 -0
- package/views/dist/panels/model.d.ts +10 -2
- package/views/dist/panels/quick/model.d.ts +4 -0
- package/views/dist/panels/react/customize-body.d.ts +9 -4
- package/views/dist/panels/react/customize-body.js +39 -11
- package/views/dist/panels/react/customize.d.ts +8 -1
- package/views/dist/panels/react/customize.js +9 -6
- package/views/dist/panels/react/filter/FilterEditor.js +4 -4
- package/views/dist/panels/react/filter/FilterFieldList.js +10 -2
- package/views/dist/panels/react/filter/PhoneFilterEditor.js +3 -3
- package/views/dist/panels/react/filter/filter-body.js +5 -2
- package/views/dist/panels/react/panel-step.d.ts +3 -0
- package/views/dist/panels/react/panel-step.js +2 -1
- package/views/dist/panels/react/quick/QuickFiltersPanel.js +1 -0
- package/views/dist/panels/react/toolbar/ReadyToolbar.d.ts +13 -3
- package/views/dist/panels/react/toolbar/ReadyToolbar.js +10 -3
- package/views/dist/panels/react/toolbar/Toolbar.js +1 -1
- package/views/dist/panels/react/toolbar/ToolbarAsideFilter.js +2 -2
- package/views/dist/panels/react/toolbar/ToolbarBarFilter.js +13 -3
- package/views/dist/panels/react/toolbar/ToolbarFilterAdd.js +2 -1
- package/views/dist/panels/react/toolbar/ToolbarFilters.js +3 -3
- package/views/dist/panels/react/toolbar/ToolbarOptions.d.ts +12 -4
- package/views/dist/panels/react/toolbar/ToolbarOptions.js +6 -2
- package/views/dist/panels/react/view-footer.d.ts +1 -1
- package/views/dist/panels/react/views-row/ViewPicker.js +25 -4
- package/views/dist/panels/settings/filter-groups.d.ts +3 -0
- package/views/dist/panels/settings/filter-groups.js +40 -9
- package/views/dist/panels/settings/filters.d.ts +5 -0
- package/views/dist/panels/settings/filters.js +12 -6
- package/views/dist/panels/views-row/model.d.ts +10 -1
- package/views/dist/provider/ViewsProvider.js +29 -5
- package/views/dist/provider/components.d.ts +149 -8
- package/views/dist/provider/context.d.ts +6 -0
- package/views/dist/provider/ports.d.ts +18 -6
- package/views/dist/provider/ports.js +2 -1
- package/views/dist/react.d.ts +2 -2
- package/views/dist/react.js +1 -1
- package/views/dist/selection/SelectionBar.d.ts +2 -16
- package/views/dist/selection/SelectionBar.js +4 -1
- package/views/dist/selection/bar-props.d.ts +26 -0
- package/views/dist/selection/bar-props.js +1 -0
- package/views/dist/selection/index.d.ts +1 -1
- package/views/dist/selection/verbs.d.ts +32 -5
- package/views/dist/styles.css +656 -25
- package/views/dist/styles.unlayered.css +653 -22
- package/views/docs/contract.md +44 -17
- package/views/docs/controls/bulk-bar.md +41 -0
- package/views/docs/controls/choice.md +25 -0
- package/views/docs/controls/customize.md +17 -0
- package/views/docs/controls/popover.md +2 -0
- package/views/docs/controls/press.md +9 -0
- package/views/docs/controls/quick-filters.md +35 -0
- package/views/docs/controls/radio.md +1 -1
- package/views/docs/controls/switch-row.md +18 -0
- package/views/docs/controls/tag-field.md +7 -0
- package/views/docs/controls/toolbar-button.md +31 -0
- package/views/docs/controls/toolbar.md +14 -0
- package/views/docs/guides/atoms.md +2 -2
- package/views/docs/guides/cells.md +2 -2
- package/views/docs/guides/display.md +2 -2
- package/views/docs/guides/looks.md +8 -2
- package/views/docs/guides/ports.md +6 -6
- package/views/docs/guides/selection.md +5 -1
- package/views/docs/guides/the-grid.md +1 -1
- package/views/docs/guides/the-provider.md +2 -2
- package/views/docs/install.md +4 -1
- package/views/docs/reference/cells.md +1 -1
- package/views/docs/reference/controls.md +194 -13
- package/views/docs/reference/display.md +1 -0
- package/views/docs/reference/looks.md +25 -11
- package/views/docs/reference/panels-react.md +7 -7
- package/views/docs/reference/panels.md +8 -6
- package/views/docs/reference/react.md +13 -6
- package/views/docs/reference/selection.md +4 -2
- package/views/docs/reference/views.md +7 -6
- package/views/skills/views/SKILL.md +2 -2
package/fields/dist/types.d.ts
CHANGED
|
@@ -275,6 +275,25 @@ export type Breakdown = {
|
|
|
275
275
|
/** How current a rollup's or a formula's worked-out value is, as the host states it beside the definition. The
|
|
276
276
|
* library keeps it on the field and reads nothing from it. */
|
|
277
277
|
export type Freshness = "live" | "minute" | "sync";
|
|
278
|
+
/** A field a worked-out field's note names, as the index found it: where it lives and its label. The note words it
|
|
279
|
+
* through the host's `field.label` message, which answers the label by default. */
|
|
280
|
+
export type NamedField = {
|
|
281
|
+
readonly entity: string;
|
|
282
|
+
readonly field: string;
|
|
283
|
+
readonly label: string;
|
|
284
|
+
};
|
|
285
|
+
/** The fields a lookup's or a rollup's note names, each as the index found it. `defineIndex()` fills it in; a part
|
|
286
|
+
* the index couldn't reach is left out, and the note words that part by its key, as before. */
|
|
287
|
+
export type DerivedNames = {
|
|
288
|
+
/** A lookup's relation, on its own record. */
|
|
289
|
+
readonly via?: NamedField;
|
|
290
|
+
/** A lookup's far field. */
|
|
291
|
+
readonly field?: NamedField;
|
|
292
|
+
/** A rollup's relations, one per hop; present only when every hop was found. */
|
|
293
|
+
readonly over?: readonly NamedField[];
|
|
294
|
+
/** A rollup's far field. */
|
|
295
|
+
readonly of?: NamedField;
|
|
296
|
+
};
|
|
278
297
|
/** The member shapes a rollup or formula may produce — declared once, used
|
|
279
298
|
* by the def union (with base keys) and by `result` (without them). */
|
|
280
299
|
/** What a text-like value may be held to. `pattern` is a regular expression source in ViewKit's dialect, matched
|
|
@@ -520,15 +539,18 @@ export type FieldDef = (FieldBase & TextSpec & {
|
|
|
520
539
|
* `via` names a `cardinality: "one"` relation of this registry; `field` a field
|
|
521
540
|
* of the far registry. `target` — the far definition — is filled in by
|
|
522
541
|
* `defineIndex()` and never written in a registry: a copied definition drifts.
|
|
523
|
-
* Read-only: it is edited on its owner. One hop; a far field may itself be a
|
|
542
|
+
* So is `names`, the fields its note names. Read-only: it is edited on its owner. One hop; a far field may itself be a
|
|
524
543
|
* lookup, which is how a chain is built. */
|
|
525
544
|
| (FieldBase & {
|
|
526
545
|
type: "lookup";
|
|
527
546
|
via: string;
|
|
528
547
|
field: string;
|
|
529
548
|
target?: FieldDef;
|
|
549
|
+
names?: DerivedNames;
|
|
530
550
|
}) | (FieldBase & {
|
|
531
551
|
type: "rollup";
|
|
552
|
+
/** The fields its note names, as the index found them: filled in by `defineIndex()`, never written. */
|
|
553
|
+
names?: DerivedNames;
|
|
532
554
|
/** A relation of this registry (or a declared inverse) — or two, for two hops:
|
|
533
555
|
* the second a relation of the middle record. Each far record counts once. */
|
|
534
556
|
over: string | readonly [string, string];
|
|
@@ -604,7 +604,7 @@ Every surface that dispatches on a type asks `valueTypeOf(field)`: a rollup's or
|
|
|
604
604
|
|
|
605
605
|
`isDerived(field)` says whether a field is a lookup, a rollup or a formula; `isLookup(field)` whether it is a lookup.
|
|
606
606
|
|
|
607
|
-
`derivedReason(field, conventions?)` is the sentence a lock shows for a derived field, worded by the host's messages. `lockReason(field, conventions?)` asks the same of any field: for a derived one, the registry's own `edit.reasons.editable` sentence when it states one, else its `description`, else `derivedReason`. Ask both about the original field, never its presented definition.
|
|
607
|
+
`derivedReason(field, conventions?)` is the sentence a lock shows for a derived field, worded by the host's messages. A lookup or rollup that came through the index names its fields by their labels: `defineIndex` stamps each with `names`, the relation, the hops and the far field it reads, each as `{ entity, field, label }`, and each goes through the host's `field.label` message before it goes into the sentence. That message answers the label by default, and a host whose labels are its own catalog's keys words them there. A field the index didn't name, or a part it couldn't reach (the far field of a first hop that names kinds), is worded by its key, as before. `lockReason(field, conventions?)` asks the same of any field: for a derived one, the registry's own `edit.reasons.editable` sentence when it states one, else its `description`, else `derivedReason`. Ask both about the original field, never its presented definition.
|
|
608
608
|
|
|
609
609
|
```ts
|
|
610
610
|
import { derivedReason, isDerived, isLookup, lockReason, presentedDef } from "viewkitjs/fields";
|
|
@@ -635,10 +635,12 @@ assert.equal(isLookup(INDEX.deal.fields.company_country), true);
|
|
|
635
635
|
function reasonOf(field: FieldDef): string | undefined {
|
|
636
636
|
return isDerived(field) ? derivedReason(field) : undefined;
|
|
637
637
|
}
|
|
638
|
-
assert.equal(reasonOf(INDEX.deal.fields.company_country), "From the linked
|
|
639
|
-
assert.equal(reasonOf(ACCOUNT_INDEX.company.fields.deal_count), "A count of
|
|
640
|
-
assert.equal(reasonOf(wonValue), "The sum of
|
|
641
|
-
assert.equal(reasonOf(ACCOUNT_INDEX.company.fields.has_won), "Whether any of
|
|
638
|
+
assert.equal(reasonOf(INDEX.deal.fields.company_country), "From the linked Company: Country");
|
|
639
|
+
assert.equal(reasonOf(ACCOUNT_INDEX.company.fields.deal_count), "A count of Deals");
|
|
640
|
+
assert.equal(reasonOf(wonValue), "The sum of Value over Deals");
|
|
641
|
+
assert.equal(reasonOf(ACCOUNT_INDEX.company.fields.has_won), "Whether any of Deals");
|
|
642
|
+
// Outside the index, a lookup names its fields by their keys.
|
|
643
|
+
assert.equal(reasonOf(DEAL_FIELDS.company_country), "From the linked company: country");
|
|
642
644
|
assert.equal(reasonOf(TASK_FIELDS.progress), "Computed from time spent over the estimate");
|
|
643
645
|
assert.equal(lockReason(TASK_FIELDS.days_left), "Computed from today and the due date");
|
|
644
646
|
```
|
|
@@ -272,7 +272,7 @@ assert.throws(
|
|
|
272
272
|
|
|
273
273
|
## Dates and instants
|
|
274
274
|
|
|
275
|
-
A `date` is a calendar day, `"2026-09-15"`, with no zone. A `datetime` is an instant, an ISO string with its offset. Both take `format.dateStyle`: `"short"` (drops the year when it is the viewer's current one), `"long"`, `"numeric"` or `"relative"`. A `datetime` also takes `format.withTime`.
|
|
275
|
+
A `date` is a calendar day, `"2026-09-15"`, with no zone. A `datetime` is an instant, an ISO string with its offset. Both take `format.dateStyle`: `"short"` (drops the year when it is the viewer's current one), `"long"`, `"numeric"` or `"relative"`. A `datetime` also takes `format.withTime`: its time shows unless it is `false`.
|
|
276
276
|
|
|
277
277
|
`ahead: true` marks a date people look forward to, such as a close or a charge. `looksAhead(field)` reads it, through a lookup too, and a host sorts such a column soonest first and groups it by when it is due.
|
|
278
278
|
|
|
@@ -561,7 +561,7 @@ An `actor` says who did something: `{ type, id, label? }`, where `type` is `"use
|
|
|
561
561
|
|
|
562
562
|
A `rich_text` is one markdown string (CommonMark and GFM), capped by `validation.maxLength`. It filters by contains and is never sorted or grouped.
|
|
563
563
|
|
|
564
|
-
A `range` is a low and a high end, `{ low, high }`, both inclusive, null for an open end ("10,001+"). `of` says what it ranges over: `"number"`, `"percent"` or `"currency"`. An amount range names its `code` (`{ fixed }`) and may name its `period` (`"hour"` to `"year"`). `presets` are the named buckets it is picked and grouped by.
|
|
564
|
+
A `range` is a low and a high end, `{ low, high }`, both inclusive, null for an open end ("10,001+"). `of` says what it ranges over: `"number"`, `"percent"` or `"currency"`. An amount range names its `code` (`{ fixed }`) and may name its `period` (`"hour"` to `"year"`). `presets` are the named buckets it is picked and grouped by. A value whose ends are exactly a preset's reads as that preset's label, in a cell, a field row and a copy (a paste reads the label back); any other value reads as its numbers.
|
|
565
565
|
|
|
566
566
|
```ts
|
|
567
567
|
const PROFILE_FIELDS = defineFields({
|
|
@@ -65,7 +65,7 @@ assert.throws(() => defineIndex([company, company]), FieldDefinitionError);
|
|
|
65
65
|
|
|
66
66
|
## Lookups resolved
|
|
67
67
|
|
|
68
|
-
A lookup shows one field of the record a one relation points at. Its registry names the relation (`via`) and the far field (`field`), never the far definition. `defineIndex` fills that in as the lookup's `target`, in a frozen copy: the registry itself is never written to, so a far definition is never copied into source, and the lookup always reads as what the far field is today.
|
|
68
|
+
A lookup shows one field of the record a one relation points at. Its registry names the relation (`via`) and the far field (`field`), never the far definition. `defineIndex` fills that in as the lookup's `target`, in a frozen copy: the registry itself is never written to, so a far definition is never copied into source, and the lookup always reads as what the far field is today. Each lookup and rollup also gets `names`, the fields its note names (its relation, its hops, its far field), each as `{ entity, field, label }`, so `derivedReason` can name them by their labels; neither is ever written in a registry.
|
|
69
69
|
|
|
70
70
|
```ts
|
|
71
71
|
const companyName = PEOPLE.person.fields.companyName;
|
|
@@ -116,7 +116,7 @@ Guide: [options](../guides/options.md).
|
|
|
116
116
|
Guide: [who may change a field](../guides/who-may-change.md).
|
|
117
117
|
|
|
118
118
|
- `lockReason` — why a field refuses an edit, in the user's words, for a lock's hover or a settings readout. It reads the declaration, most specific first: the registry's own reason, a worked-out field's description, what the value is computed from, who owns it (the system, or a provider and how fresh), that it is set once when the record is made, else that it never changes. It reads the declaration, not whether the field is writable: a provider-owned field left editable still gets its owner's sentence, and so does any field that states `edit.reasons.editable`. Undefined for a plain editable field and for a command field; ask it about the original field, never a presented one.
|
|
119
|
-
- `derivedReason` — the sentence a lock shows for a derived field: what its value is computed from or looked up through, in words.
|
|
119
|
+
- `derivedReason` — the sentence a lock shows for a derived field: what its value is computed from or looked up through, in words, each field the index named (`names`) by its label through the message `field.label`.
|
|
120
120
|
- `requestedSettlementTitle` — the hover a cell carries while a write is only requested of the provider that owns the value: saved here, the provider still to confirm, named when the provenance names one.
|
|
121
121
|
- `FieldSettlement` — what a confirmed save achieved beyond durable storage: confirmed, or requested of the provider that owns the value.
|
|
122
122
|
- `FieldSaveResult` — what a host's write reports for one admitted save: confirmed with the row (and an optional warning and settlement), saved but unconfirmed, or uncertain, each of the last two with a warning.
|
|
@@ -226,7 +226,9 @@ Guide: [field types](../guides/field-types.md).
|
|
|
226
226
|
- `rangeOverlaps` — says whether a range shares any part with the bounds given; an open end reaches forever.
|
|
227
227
|
- `presetOf` — the preset a range value is grouped under: the one its low end falls in, or its high end when the low is open.
|
|
228
228
|
- `rangeDecimals` — the most fraction digits a range's ends are edited and drawn with: none for an integer range, else the field's stated decimals, else the number editor's default.
|
|
229
|
+
- `exactPresetOf` — the preset whose two ends are exactly a range value's: the band it is, not the one it is grouped under.
|
|
229
230
|
- `rangeText` — a range written out, such as "11–50", "10,001+" or "up to 50", with up to the range's decimals.
|
|
231
|
+
- `rangeShownText` — a range as a cell shows it: its band's name when its ends are exactly a preset's, else `rangeText`.
|
|
230
232
|
- `normalizeMarkdown` — tidies rich text at its edges only: line endings become `\n`, and blank lines before and whitespace after the text go. Nothing inside changes.
|
|
231
233
|
- `markdownFirstLine` — the first line of rich text with words in it: what a one-line cell shows.
|
|
232
234
|
- `markdownPlainText` — every line of rich text with words in it, as plain text: what a card's few lines show.
|
|
@@ -21,7 +21,7 @@ Import from `viewkitjs/fields/types` only for module augmentation: narrowing the
|
|
|
21
21
|
- `PercentSpec` — the spec of a `percent` field: its storage, its validation (with `reason`, why its bounds leave 0–100, required then) and its percent format.
|
|
22
22
|
- `CurrencySpec` — the spec of a `currency` field: the currency code, an optional conversion, its storage, its validation and its currency format. A conversion is legal only beside a code that comes from a sibling field, because a code per row is what converts.
|
|
23
23
|
- `DateSpec` — the spec of a `date` field: a date style, and `ahead` for a date people look forward to, which sorts soonest first and groups by when it is due.
|
|
24
|
-
- `DatetimeSpec` — the spec of a `datetime` field: the same as a date, with a `withTime` format flag as well.
|
|
24
|
+
- `DatetimeSpec` — the spec of a `datetime` field: the same as a date, with a `withTime` format flag as well (the time shows unless it is `false`).
|
|
25
25
|
- `BooleanSpec` — the spec of a `boolean` field: its style, and optionally a pair of options that name the two states.
|
|
26
26
|
- `SelectSpec` — the spec of a `select` field: its options, and a vocabulary that is `closed` (the default) or `custom-values`, where the values are whatever the records hold.
|
|
27
27
|
- `StatusSpec` — the spec of a `status` field: its options, and optional groups that gather options under a label.
|
|
@@ -82,6 +82,8 @@ Import from `viewkitjs/fields/types` only for module augmentation: narrowing the
|
|
|
82
82
|
- `BreakdownPart` — one part of a breakdown: a `key`, an optional `label`, a `value` that is a number or null, an optional `slot`, and a `partial` flag.
|
|
83
83
|
- `Breakdown` — a grouped rollup's value: the headline, and the parts in order. Every option is there, zeros included.
|
|
84
84
|
- `Freshness` — how current a derived value must be: `live`, `minute` or `sync`.
|
|
85
|
+
- `NamedField` — a field a lookup's or a rollup's note names, as the index found it: its `entity`, its `field` key and its `label`. The note words it through the message `field.label`.
|
|
86
|
+
- `DerivedNames` — the fields a lookup's or a rollup's note names, stamped by `defineIndex` as `names`: a lookup's `via` and `field`, a rollup's `over` (one per hop, all or none) and `of`. A part the index couldn't reach is left out.
|
|
85
87
|
|
|
86
88
|
## Registries and entities
|
|
87
89
|
|
|
@@ -74,7 +74,7 @@ Four more field types, and growth in the relation, the rollup and the formula. E
|
|
|
74
74
|
|
|
75
75
|
**A worked-out name** (an identity that is a formula) is renamed through the stored field the registry names with `rename`; `renamedName(fields)` gives the field a rename edits: the stored field, under the name's key and label.
|
|
76
76
|
|
|
77
|
-
**A lookup** shows one field of the record a single relation points at: `via` names a `cardinality: "one"` relation of this registry, `field` a field of the far registry. It is read-only and never stored. Never write its `target
|
|
77
|
+
**A lookup** shows one field of the record a single relation points at: `via` names a `cardinality: "one"` relation of this registry, `field` a field of the far registry. It is read-only and never stored. Never write its `target` or `names` (a rollup's `names` neither): `defineIndex` fills them in from the index (`names` holds the fields its note names, so the note reads their labels through the message `field.label`), and `checkFieldSpec` refuses either written by hand.
|
|
78
78
|
|
|
79
79
|
**The index** gathers the registries so a lookup, a rollup and a relation filter can read across them. `entityDef(registry)` takes a registry from `defineFields`; `defineIndex(entities)` checks them together, resolves lookups (a far lookup is followed, a cycle is refused) and freezes the result; `checkIndex(index)` checks an index again.
|
|
80
80
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "viewkitjs",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.29.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": {
|
|
@@ -187,6 +187,7 @@
|
|
|
187
187
|
"./views/styles.css": "./views/dist/styles.css",
|
|
188
188
|
"./views/styles.unlayered.css": "./views/dist/styles.unlayered.css",
|
|
189
189
|
"./views/controls/*.css": "./views/dist/controls/*.css",
|
|
190
|
+
"./views/grid.css": "./views/dist/grid/grid.css",
|
|
190
191
|
"./postgres": {
|
|
191
192
|
"types": "./postgres/dist/index.d.ts",
|
|
192
193
|
"default": "./postgres/dist/index.js"
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { valueTypeOf } from "viewkitjs/fields";
|
|
1
2
|
import { defineFieldMap, FieldMapError } from "../map.js";
|
|
2
3
|
import { labelOf } from "./label.js";
|
|
3
4
|
import { placeField, REASONS } from "./place.js";
|
|
@@ -16,8 +17,8 @@ export function buildFieldMap(input) {
|
|
|
16
17
|
const tables = new Map([[own, checked.kinds[own]]]);
|
|
17
18
|
const memo = new Map();
|
|
18
19
|
const queue = [own];
|
|
19
|
-
const farTable = (kind) => {
|
|
20
|
-
const key = `${FAR}${kind}`;
|
|
20
|
+
const farTable = (kind, under) => {
|
|
21
|
+
const key = under === undefined ? `${FAR}${kind}` : `${FAR}${kind}:${under}`;
|
|
21
22
|
if (!tables.has(key)) {
|
|
22
23
|
const found = Object.hasOwn(checked.kinds, kind) ? checked.kinds[kind] : undefined;
|
|
23
24
|
if (found === undefined)
|
|
@@ -34,8 +35,8 @@ export function buildFieldMap(input) {
|
|
|
34
35
|
const [table, field] = address.split("\u0000");
|
|
35
36
|
return `${tables.get(table).kind}.${field}`;
|
|
36
37
|
};
|
|
37
|
-
const placed = (table, field) => {
|
|
38
|
-
const address = `${table}\u0000${field}`;
|
|
38
|
+
const placed = (table, field, under) => {
|
|
39
|
+
const address = under === undefined ? `${table}\u0000${field}` : `${table}\u0000${field}\u0000${under}`;
|
|
39
40
|
const done = memo.get(address);
|
|
40
41
|
if (done !== undefined)
|
|
41
42
|
return done;
|
|
@@ -52,7 +53,19 @@ export function buildFieldMap(input) {
|
|
|
52
53
|
const def = kind?.entity === undefined ? undefined : kind.entity.fields[field];
|
|
53
54
|
if (kind === undefined || def === undefined)
|
|
54
55
|
throw new TypeError(`buildFieldMap: no field ${field} on ${table}`);
|
|
55
|
-
|
|
56
|
+
if (under !== undefined && valueTypeOf(def) !== "relation")
|
|
57
|
+
throw new TypeError(`buildFieldMap: ${field} of ${table} is no relation to read under ${under}`);
|
|
58
|
+
const at = under === undefined
|
|
59
|
+
? { input: checked, table, kind, def, farTable, relationKey, placed }
|
|
60
|
+
: {
|
|
61
|
+
input: checked,
|
|
62
|
+
table,
|
|
63
|
+
kind,
|
|
64
|
+
def,
|
|
65
|
+
farTable: (far) => farTable(far, under),
|
|
66
|
+
relationKey: (from, key) => `${relationKey(from, key)}:${under}`,
|
|
67
|
+
placed,
|
|
68
|
+
};
|
|
56
69
|
placing.push(address);
|
|
57
70
|
const result = placeField(at);
|
|
58
71
|
placing.pop();
|
|
@@ -113,6 +126,15 @@ export function buildFieldMap(input) {
|
|
|
113
126
|
ownFields = fields;
|
|
114
127
|
reads.push([table, { kind: kind.kind, far: table !== own, table: kind.table, columns: [], handWritten }]);
|
|
115
128
|
}
|
|
129
|
+
const relationKeys = new Set(relations.map(([key]) => key));
|
|
130
|
+
for (const [address, result] of memo) {
|
|
131
|
+
if (address.split("\u0000").length !== 3 || "leftOut" in result || result.relation === undefined)
|
|
132
|
+
continue;
|
|
133
|
+
if (relationKeys.has(result.relation.key))
|
|
134
|
+
throw new TypeError(`buildFieldMap: the relation ${result.relation.key} a field reads under a name is also a field's own relation`);
|
|
135
|
+
relationKeys.add(result.relation.key);
|
|
136
|
+
relations.push([result.relation.key, result.relation.map]);
|
|
137
|
+
}
|
|
116
138
|
const columnsOf = new Map();
|
|
117
139
|
for (const [table, kind] of tables) {
|
|
118
140
|
const set = new Set([kind.key]);
|
|
@@ -143,6 +165,8 @@ export function buildFieldMap(input) {
|
|
|
143
165
|
}
|
|
144
166
|
const fieldsRead = new Map();
|
|
145
167
|
for (const [address, result] of memo) {
|
|
168
|
+
if (address.split("\u0000").length !== 2)
|
|
169
|
+
continue;
|
|
146
170
|
if (!("leftOut" in result) && result.fields !== undefined && result.fields.length > 0)
|
|
147
171
|
fieldsRead.set(address, result.fields);
|
|
148
172
|
}
|
|
@@ -1,8 +1,15 @@
|
|
|
1
1
|
import { type FieldDef } from "viewkitjs/fields";
|
|
2
2
|
import type { Read } from "../map.js";
|
|
3
|
+
import { type Sql } from "../sql.js";
|
|
3
4
|
import type { ColumnRead, Placing } from "./place.js";
|
|
4
5
|
/** A table's label: its kind's identity field, placed as text or as a name's parts; none for anything else. */
|
|
5
6
|
export declare function labelOf(at: Pick<Placing, "placed">, table: string, identity: FieldDef): {
|
|
6
7
|
readonly label?: Read;
|
|
7
8
|
readonly reads: readonly ColumnRead[];
|
|
8
9
|
};
|
|
10
|
+
/**
|
|
11
|
+
* The parts that aren't NULL joined by one space, NULL when none is: concat_ws(' ', …)'s answer, NULL for its '',
|
|
12
|
+
* written in immutable functions (concat_ws is stable) as a formula's `join` writes it, so an index can hold it. Each
|
|
13
|
+
* part is already NULL when blank (`NULLIF(<trimmed>, '')`).
|
|
14
|
+
*/
|
|
15
|
+
export declare function spacedSql(parts: readonly Sql[]): Sql;
|
|
@@ -24,7 +24,7 @@ export function labelOf(at, table, identity) {
|
|
|
24
24
|
label: (row) => {
|
|
25
25
|
const full = part(row, "full");
|
|
26
26
|
const rest = [part(row, "given"), part(row, "family")].filter((one) => one !== null);
|
|
27
|
-
const joined = rest.length === 0 ? null :
|
|
27
|
+
const joined = rest.length === 0 ? null : spacedSql(rest);
|
|
28
28
|
const items = [full, joined].filter((one) => one !== null);
|
|
29
29
|
return items.length === 0 ? sql `NULL::text` : sql `COALESCE(${join(items, sql `, `)})`;
|
|
30
30
|
},
|
|
@@ -33,3 +33,11 @@ export function labelOf(at, table, identity) {
|
|
|
33
33
|
}
|
|
34
34
|
return { reads: [] };
|
|
35
35
|
}
|
|
36
|
+
export function spacedSql(parts) {
|
|
37
|
+
if (parts.length === 0)
|
|
38
|
+
return sql `NULL::text`;
|
|
39
|
+
if (parts.length === 1)
|
|
40
|
+
return parts[0];
|
|
41
|
+
const pieces = parts.map((part) => sql `COALESCE(' ' || ${part}, '')`);
|
|
42
|
+
return sql `NULLIF(substr(${join(pieces, sql ` || `)}, 2), '')`;
|
|
43
|
+
}
|
|
@@ -4,6 +4,8 @@ import { trimmedSql } from "../fold.js";
|
|
|
4
4
|
import { readsUser, userReadOf } from "../users.js";
|
|
5
5
|
import { sql } from "../sql.js";
|
|
6
6
|
import { joinedOf, mappingReadsZone, readSql, readsZone } from "../values.js";
|
|
7
|
+
import { spacedSql } from "./label.js";
|
|
8
|
+
import { underOf } from "./storage.js";
|
|
7
9
|
export const LOOKUP_REASONS = {
|
|
8
10
|
via: (via, why) => `its relation ${via} is left out: ${why}`,
|
|
9
11
|
farField: (field, why) => `its far field ${field} is left out: ${why}`,
|
|
@@ -13,7 +15,8 @@ export const LOOKUP_REASONS = {
|
|
|
13
15
|
const NAME_PARTS_WRITTEN = ["full", "given", "family"];
|
|
14
16
|
export const placeLookup = (at) => {
|
|
15
17
|
const def = at.def;
|
|
16
|
-
const
|
|
18
|
+
const under = underOf(at.input, at.kind.kind, def.key);
|
|
19
|
+
const via = at.placed(at.table, def.via, under);
|
|
17
20
|
if ("leftOut" in via)
|
|
18
21
|
return { leftOut: LOOKUP_REASONS.via(def.via, via.leftOut) };
|
|
19
22
|
const relation = via.relation;
|
|
@@ -60,6 +63,7 @@ export const placeLookup = (at) => {
|
|
|
60
63
|
const fields = [
|
|
61
64
|
{ table: at.table, key: def.via },
|
|
62
65
|
{ table: to, key: def.field },
|
|
66
|
+
...(under === undefined ? [] : (via.fields ?? [])),
|
|
63
67
|
];
|
|
64
68
|
return { mapping, reads: [...via.reads, ...far.reads], fields };
|
|
65
69
|
};
|
|
@@ -80,7 +84,7 @@ function sortReadOf(far, def, value) {
|
|
|
80
84
|
const text = Object.hasOwn(parts, name) ? readSql(f, parts[name], def.field) : sql `NULL`;
|
|
81
85
|
return sql `NULLIF(${trimmedSql(text)}, '')`;
|
|
82
86
|
});
|
|
83
|
-
return sql `COALESCE(${full},
|
|
87
|
+
return sql `COALESCE(${full}, ${spacedSql([given, family])})`;
|
|
84
88
|
},
|
|
85
89
|
column: false,
|
|
86
90
|
};
|
|
@@ -34,12 +34,15 @@ export type Placing = {
|
|
|
34
34
|
readonly table: string;
|
|
35
35
|
readonly kind: CheckedKind;
|
|
36
36
|
readonly def: FieldDef;
|
|
37
|
-
/** The table key a far read of `kind` opens, laid out (its fields placed in turn) on first ask
|
|
37
|
+
/** The table key a far read of `kind` opens, laid out (its fields placed in turn) on first ask: `far:<kind>`, or
|
|
38
|
+
* `far:<kind>:<name>` while a relation is placed under a name. */
|
|
38
39
|
farTable(kind: string): string;
|
|
39
40
|
/** The key of the relation that relation field `field` of table `table` reads. */
|
|
40
41
|
relationKey(table: string, field: string): string;
|
|
41
|
-
/** Field `field` of table `table`, placed once and kept: what a worked-out field reads through.
|
|
42
|
-
|
|
42
|
+
/** Field `field` of table `table`, placed once and kept: what a worked-out field reads through. With `under`, a
|
|
43
|
+
* relation field placed for a lookup or a rollup named in `readUnder`: every table it opens is `far:<kind>:<under>`,
|
|
44
|
+
* its relation keyed `<key>:<under>`, and it is no field of any table. */
|
|
45
|
+
placed(table: string, field: string, under?: string): Placed;
|
|
43
46
|
};
|
|
44
47
|
/** A worked-out field's own read: the fields it reads are read with no list, since the door held them (`readingWorkedOut`).
|
|
45
48
|
* So every field its read can reach must be in its `Placed.fields`: one left out there is read unchecked. */
|
|
@@ -5,6 +5,7 @@ import { farOrderSql } from "../sort.js";
|
|
|
5
5
|
import { join, sql, TRUE } from "../sql.js";
|
|
6
6
|
import { hasParts, mappingReadsZone, oneKeyOf, readsWhole, readsZone, valueSql } from "../values.js";
|
|
7
7
|
import { workedOut } from "./place.js";
|
|
8
|
+
import { underOf } from "./storage.js";
|
|
8
9
|
export const ROLLUP_REASONS = {
|
|
9
10
|
breakdown: "a rollup that breaks down by an option or a time is not built yet",
|
|
10
11
|
range: "a rollup that follows a page's range is not built yet",
|
|
@@ -123,17 +124,20 @@ export const placeRollup = (at) => {
|
|
|
123
124
|
const reads = [];
|
|
124
125
|
const relations = [];
|
|
125
126
|
const fields = [];
|
|
127
|
+
const under = underOf(at.input, at.kind.kind, def.key);
|
|
126
128
|
let table = at.table;
|
|
127
129
|
let kind = at.kind;
|
|
128
130
|
for (const hop of hops) {
|
|
129
131
|
fields.push({ table, key: hop });
|
|
130
|
-
const placed = at.placed(table, hop);
|
|
132
|
+
const placed = at.placed(table, hop, under);
|
|
131
133
|
if ("leftOut" in placed)
|
|
132
134
|
return { leftOut: ROLLUP_REASONS.hop(hop, placed.leftOut) };
|
|
133
135
|
if (placed.relation === undefined)
|
|
134
136
|
throw new TypeError(`placeRollup: ${def.key} goes over ${hop}, which is no relation`);
|
|
135
137
|
relations.push(placed.relation.key);
|
|
136
138
|
reads.push(...placed.reads);
|
|
139
|
+
if (under !== undefined)
|
|
140
|
+
fields.push(...(placed.fields ?? []));
|
|
137
141
|
const hopDef = kind.entity.fields[hop];
|
|
138
142
|
kind = at.input.kinds[hopDef.relation.kind];
|
|
139
143
|
table = placed.relation.map.to;
|
|
@@ -66,6 +66,15 @@ string
|
|
|
66
66
|
readonly from: string;
|
|
67
67
|
readonly to: string;
|
|
68
68
|
};
|
|
69
|
+
}
|
|
70
|
+
/** A value kept as another kind's record: the column holding that record's key, the kind, and its column holding the
|
|
71
|
+
* value (a status kept as a code table's row id, valued by its code). */
|
|
72
|
+
| {
|
|
73
|
+
readonly column: string;
|
|
74
|
+
readonly from: {
|
|
75
|
+
readonly kind: string;
|
|
76
|
+
readonly value: string;
|
|
77
|
+
};
|
|
69
78
|
};
|
|
70
79
|
/** What `buildFieldMap` takes. */
|
|
71
80
|
export type BuildFieldMapInput = {
|
|
@@ -79,6 +88,8 @@ export type BuildFieldMapInput = {
|
|
|
79
88
|
readonly money?: ConvertMoney;
|
|
80
89
|
/** Your own entry for a field the storage can't say, by kind and field. It replaces the built one wherever that kind is read, and answers for its own access. */
|
|
81
90
|
readonly handWritten?: Readonly<Record<string, Readonly<Record<string, FieldMapping>>>>;
|
|
91
|
+
/** Lookups and rollups that read their far records under a condition of their own, by kind and field: the name of that condition. Each reads through tables keyed `far:<kind>:<name>`, which `reads` names for you to hand a condition and a list of readable fields; fields named alike share them. */
|
|
92
|
+
readonly readUnder?: Readonly<Record<string, Readonly<Record<string, string>>>>;
|
|
82
93
|
};
|
|
83
94
|
/** A storage refused: `path` names the place in the input. */
|
|
84
95
|
export declare class StorageError extends Error {
|
|
@@ -109,6 +120,8 @@ export type CheckedInput = {
|
|
|
109
120
|
readonly money: ConvertMoney | undefined;
|
|
110
121
|
readonly kind: string;
|
|
111
122
|
readonly handWritten: Readonly<Record<string, Readonly<Record<string, FieldMapping>>>>;
|
|
123
|
+
/** The name each named lookup or rollup reads under, by kind and field: `{}` when none is named. */
|
|
124
|
+
readonly readUnder: Readonly<Record<string, Readonly<Record<string, string>>>>;
|
|
112
125
|
/** The kind a user field points at, or undefined when the storage names none. */
|
|
113
126
|
readonly users: string | undefined;
|
|
114
127
|
};
|
|
@@ -118,3 +131,5 @@ export declare const TEXT_TYPES: ReadonlySet<ValueType>;
|
|
|
118
131
|
export declare function holdsSeveral(def: FieldDef): boolean;
|
|
119
132
|
/** Refuses with a `StorageError` at the first thing the input can't hold. */
|
|
120
133
|
export declare function checkInput(given: BuildFieldMapInput): CheckedInput;
|
|
134
|
+
/** The name `field` of `kind` reads under (`readUnder`), or undefined when it reads as every field does. */
|
|
135
|
+
export declare function underOf(input: CheckedInput, kind: string, field: string): string | undefined;
|
|
@@ -30,8 +30,10 @@ const JSON_TYPES = new Set([
|
|
|
30
30
|
"datetime",
|
|
31
31
|
"boolean",
|
|
32
32
|
]);
|
|
33
|
+
const UNDER_NAME = /^[A-Za-z0-9_-]{1,63}$/;
|
|
34
|
+
const NAMED_FIELDS = "give the named fields by kind and field";
|
|
33
35
|
const WORKED_OUT = "a lookup, a rollup or a formula is worked out from the definitions, never kept";
|
|
34
|
-
const NO_FORM = "a field is kept as a column, { column, stored }, { parts }, { json, path }, { rows } or { through }";
|
|
36
|
+
const NO_FORM = "a field is kept as a column, { column, stored }, { column, from }, { parts }, { json, path }, { rows } or { through }";
|
|
35
37
|
const UNKEPT = /\u0000|[\ud800-\udbff](?![\udc00-\udfff])|(?<![\ud800-\udbff])[\udc00-\udfff]/;
|
|
36
38
|
export function holdsSeveral(def) {
|
|
37
39
|
const type = valueTypeOf(def);
|
|
@@ -205,6 +207,7 @@ export function checkInput(given) {
|
|
|
205
207
|
throw new StorageError(path, "an amount that converts is read through your money function");
|
|
206
208
|
}
|
|
207
209
|
}
|
|
210
|
+
const readUnder = checkReadUnder(given.readUnder, checkedKinds, handWritten);
|
|
208
211
|
const users = storage.users;
|
|
209
212
|
if (users !== undefined) {
|
|
210
213
|
if (typeof users !== "string")
|
|
@@ -227,9 +230,44 @@ export function checkInput(given) {
|
|
|
227
230
|
money: money,
|
|
228
231
|
kind: listKind,
|
|
229
232
|
handWritten,
|
|
233
|
+
readUnder,
|
|
230
234
|
users: users,
|
|
231
235
|
});
|
|
232
236
|
}
|
|
237
|
+
export function underOf(input, kind, field) {
|
|
238
|
+
return own(own(input.readUnder, kind), field);
|
|
239
|
+
}
|
|
240
|
+
function checkReadUnder(given, kinds, handWritten) {
|
|
241
|
+
if (given === undefined)
|
|
242
|
+
return Object.freeze({});
|
|
243
|
+
const copy = frozenCopy(given);
|
|
244
|
+
if (!isRecord(copy))
|
|
245
|
+
throw new StorageError("readUnder", NAMED_FIELDS);
|
|
246
|
+
for (const kind of Object.keys(copy)) {
|
|
247
|
+
if (kind.includes(":"))
|
|
248
|
+
throw new StorageError(`readUnder.${kind}`, 'a kind\'s name holds no ":"');
|
|
249
|
+
}
|
|
250
|
+
for (const [kind, fields] of Object.entries(copy)) {
|
|
251
|
+
const checked = own(kinds, kind);
|
|
252
|
+
if (checked === undefined)
|
|
253
|
+
throw new StorageError(`readUnder.${kind}`, `${kind} is not one of the storage's kinds`);
|
|
254
|
+
if (!isRecord(fields))
|
|
255
|
+
throw new StorageError(`readUnder.${kind}`, NAMED_FIELDS);
|
|
256
|
+
for (const [key, name] of Object.entries(fields)) {
|
|
257
|
+
const path = `readUnder.${kind}.${key}`;
|
|
258
|
+
const named = checked.entity === undefined ? undefined : own(checked.entity.fields, key);
|
|
259
|
+
if (named === undefined)
|
|
260
|
+
throw new StorageError(path, `${key} is no field of ${kind}`);
|
|
261
|
+
if (named.type !== "lookup" && named.type !== "rollup")
|
|
262
|
+
throw new StorageError(path, "only a lookup or a rollup reads under a condition of its own");
|
|
263
|
+
if (Object.hasOwn(own(handWritten, kind) ?? {}, key))
|
|
264
|
+
throw new StorageError(path, "a hand-written field answers for its own reads");
|
|
265
|
+
if (typeof name !== "string" || !UNDER_NAME.test(name))
|
|
266
|
+
throw new StorageError(path, "a name is 1 to 63 letters, digits, - and _");
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
return copy;
|
|
270
|
+
}
|
|
233
271
|
function checkForm(path, kind, def, form, kinds) {
|
|
234
272
|
const type = valueTypeOf(def);
|
|
235
273
|
const several = holdsSeveral(def);
|
|
@@ -265,6 +303,19 @@ function checkForm(path, kind, def, form, kinds) {
|
|
|
265
303
|
if (!("through" in form))
|
|
266
304
|
throw new StorageError(path, "a relation of several records is kept through its inverse or a link kind");
|
|
267
305
|
}
|
|
306
|
+
if ("from" in form) {
|
|
307
|
+
onlyKeys(path, form, ["column", "from"]);
|
|
308
|
+
if (several || (type !== "select" && type !== "status" && !TEXT_TYPES.has(type)))
|
|
309
|
+
throw new StorageError(path, "only a select, a status or a text of one value is read from the row its column points at");
|
|
310
|
+
name(path, form.column);
|
|
311
|
+
const from = form.from;
|
|
312
|
+
if (!isRecord(from))
|
|
313
|
+
throw new StorageError(path, "from names a kind and its value column");
|
|
314
|
+
onlyKeys(path, from, ["kind", "value"]);
|
|
315
|
+
isKind(path, from.kind);
|
|
316
|
+
name(path, from.value);
|
|
317
|
+
return;
|
|
318
|
+
}
|
|
268
319
|
if ("column" in form) {
|
|
269
320
|
onlyKeys(path, form, ["column", "stored"]);
|
|
270
321
|
if (!TEXT_TYPES.has(type) || several)
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { valueTypeOf } from "viewkitjs/fields";
|
|
2
|
+
import { openedOf } from "../access.js";
|
|
2
3
|
import { trimmedSql } from "../fold.js";
|
|
3
4
|
import { sql } from "../sql.js";
|
|
5
|
+
import { joinedOf } from "../values.js";
|
|
4
6
|
import { jsonMember, memberOf } from "./json.js";
|
|
5
7
|
import { holdsSeveral, TEXT_TYPES } from "./storage.js";
|
|
6
8
|
function withPhoneSort(mapping) {
|
|
@@ -50,6 +52,25 @@ export function placeStored(at) {
|
|
|
50
52
|
const member = jsonMember(type, form.json, form.path);
|
|
51
53
|
return placed({ value: member.read, stored: member.stored }, [read(form.json)]);
|
|
52
54
|
}
|
|
55
|
+
if (isForm(form, "from")) {
|
|
56
|
+
const key = at.relationKey(table, def.key);
|
|
57
|
+
const to = at.farTable(form.from.kind);
|
|
58
|
+
const value = form.from.value;
|
|
59
|
+
const through = (row) => {
|
|
60
|
+
const opened = openedOf(row);
|
|
61
|
+
if (opened === undefined)
|
|
62
|
+
throw new TypeError(`${def.key}: a value kept as another kind's record is read only on a row the translator opened`);
|
|
63
|
+
if (opened.at.table !== table)
|
|
64
|
+
throw new TypeError(`${def.key} is read on ${table}'s rows, not ${opened.at.table}'s`);
|
|
65
|
+
const joined = joinedOf(opened.scope, opened.at, key);
|
|
66
|
+
return joined.read(sql `(${joined.far.row.column(value)})::text`);
|
|
67
|
+
};
|
|
68
|
+
return {
|
|
69
|
+
mapping: { value: through, sort: through, search: through, stored: "text" },
|
|
70
|
+
reads: [read(form.column), { table: to, column: value }],
|
|
71
|
+
relation: { key, map: { from: table, to, column: form.column } },
|
|
72
|
+
};
|
|
73
|
+
}
|
|
53
74
|
if (isForm(form, "column"))
|
|
54
75
|
return placed({ value: asText(form.column), stored: "text" }, [read(form.column)]);
|
|
55
76
|
if (typeof form !== "string")
|
package/postgres/dist/phone.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type FilterRule } from "viewkitjs/fields/query";
|
|
2
2
|
import type { Opened, Scope } from "./access.js";
|
|
3
3
|
import { type Read, type ValueRow } from "./map.js";
|
|
4
4
|
import { type Sql } from "./sql.js";
|
|
@@ -26,3 +26,15 @@ export declare function phoneAt(scope: Scope, at: Opened, key: string): PhoneRea
|
|
|
26
26
|
export declare function phoneOfElement(element: Sql, text: Sql): PhoneReading;
|
|
27
27
|
/** `rule` on the phone `reading`, as matchesRule's phone case answers it, the operand read in `region`. */
|
|
28
28
|
export declare function phoneRuleSql(reading: PhoneReading, rule: FilterRule, region: string | undefined): Sql;
|
|
29
|
+
/**
|
|
30
|
+
* A search word on the phone `reading`, answering what phoneRuleSql's "contains" answers, written as arms an index
|
|
31
|
+
* serves: `(international AND number contains operand) OR (NOT international AND typed contains word)` in
|
|
32
|
+
* place of a CASE chosen on each row, which no index serves; the same predicate, every part being two-valued. Each
|
|
33
|
+
* contains is a LIKE over a folded text, which a trigram index on that text serves (searchIndexes prints both). The
|
|
34
|
+
* number's arm is left out when no international number can hold the word (a letter in it), and a phone that is never
|
|
35
|
+
* international (no number part) is its typed arm alone.
|
|
36
|
+
*/
|
|
37
|
+
export declare function phoneWordSql(reading: PhoneReading, word: string): Sql;
|
|
38
|
+
/** Whether a trigram index serves every arm phoneWordSql writes for `word`: three folded characters or more in the
|
|
39
|
+
* word, and in the number's operand where that arm is kept. */
|
|
40
|
+
export declare function phoneWordIndexed(word: string): boolean;
|
package/postgres/dist/phone.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { phoneFilterOperand } from "viewkitjs/fields";
|
|
2
|
-
import {
|
|
2
|
+
import { foldText } from "viewkitjs/fields/query";
|
|
3
|
+
import { TRIGRAM, trimmedSql } from "./fold.js";
|
|
3
4
|
import { textSql } from "./rules.js";
|
|
4
|
-
import { sql } from "./sql.js";
|
|
5
|
+
import { FALSE, sql } from "./sql.js";
|
|
5
6
|
import { readSql, rowJoinOf } from "./values.js";
|
|
6
7
|
import { readableField } from "./readable.js";
|
|
7
8
|
const E164 = "^\\+[1-9][0-9]{1,14}$";
|
|
@@ -9,7 +10,7 @@ const EXTENSION = "^[0-9]{1,20}$";
|
|
|
9
10
|
export function phoneOf(row, parts, typed, key) {
|
|
10
11
|
const fallback = typed === null ? sql `NULL::text` : sql `(${typed})`;
|
|
11
12
|
if (parts === undefined || !Object.hasOwn(parts, "number"))
|
|
12
|
-
return { international:
|
|
13
|
+
return { international: FALSE, number: sql `NULL::text`, typed: fallback };
|
|
13
14
|
const number = sql `(${readSql(row, parts.number, key)})`;
|
|
14
15
|
const ext = Object.hasOwn(parts, "extension") ? readSql(row, parts.extension, key) : null;
|
|
15
16
|
const extension = ext === null ? sql `` : sql ` AND (${ext} IS NULL OR ${ext} ~ ${EXTENSION}::text)`;
|
|
@@ -52,3 +53,22 @@ export function phoneRuleSql(reading, rule, region) {
|
|
|
52
53
|
: textSql(reading.number, operator, operand);
|
|
53
54
|
return sql `(CASE WHEN ${reading.international} THEN ${international} ELSE ${textSql(reading.typed, operator, query)} END)`;
|
|
54
55
|
}
|
|
56
|
+
const NUMBER_TEXT = /^[+0-9]*$/;
|
|
57
|
+
function numberOperand(word) {
|
|
58
|
+
const operand = foldText(phoneFilterOperand("contains", word, undefined).trim());
|
|
59
|
+
return NUMBER_TEXT.test(operand) ? operand : null;
|
|
60
|
+
}
|
|
61
|
+
export function phoneWordSql(reading, word) {
|
|
62
|
+
const typed = textSql(reading.typed, "contains", word);
|
|
63
|
+
if (reading.international === FALSE)
|
|
64
|
+
return typed;
|
|
65
|
+
const operand = numberOperand(word);
|
|
66
|
+
if (operand === null)
|
|
67
|
+
return sql `(NOT ${reading.international} AND ${typed})`;
|
|
68
|
+
const number = operand === "" ? sql `TRUE` : textSql(reading.number, "contains", operand);
|
|
69
|
+
return sql `((${reading.international} AND ${number}) OR (NOT ${reading.international} AND ${typed}))`;
|
|
70
|
+
}
|
|
71
|
+
export function phoneWordIndexed(word) {
|
|
72
|
+
const operand = numberOperand(word);
|
|
73
|
+
return [...foldText(word.trim())].length >= TRIGRAM && (operand === null || [...operand].length >= TRIGRAM);
|
|
74
|
+
}
|
|
@@ -38,7 +38,8 @@ export type SearchStatistics = {
|
|
|
38
38
|
* second map over the same table prints the same statement, which then changes nothing. */
|
|
39
39
|
readonly statement: string;
|
|
40
40
|
};
|
|
41
|
-
/** A field the search names that no index serves, and why: a search naming one reads every row.
|
|
41
|
+
/** A field the search names that no index serves, and why: a search naming one reads every row. A relation whose far
|
|
42
|
+
* label no index can hold is named too, its own column's index still printed: each word reads the far table whole. */
|
|
42
43
|
export type UnservedField = {
|
|
43
44
|
readonly field: string;
|
|
44
45
|
readonly reason: string;
|
|
@@ -50,9 +51,13 @@ export type SearchIndexes = {
|
|
|
50
51
|
readonly statistics: readonly SearchStatistics[];
|
|
51
52
|
};
|
|
52
53
|
export declare const SEARCH_INDEX_REASONS: {
|
|
54
|
+
/** No longer given: a phone is searched by its number and its typed text, each served by a trigram index.
|
|
55
|
+
* Kept for an app that compares a reason to it. */
|
|
53
56
|
readonly phone: "a phone is searched by its number's own rule, which no index serves";
|
|
54
57
|
readonly option: "an option is searched by its options' labels, which no index serves yet";
|
|
55
58
|
readonly otherTable: "it is read through another table or a subquery, which an index on this table can't hold";
|
|
59
|
+
readonly notImmutable: "it is written with a function whose answer can change from one statement to the next, which no index can hold";
|
|
60
|
+
readonly farLabel: "its far table's label can't be held by an index, so each search word reads that table whole";
|
|
56
61
|
};
|
|
57
62
|
/** The indexes the search over `fields` reads through on `map`, the statistics beside its trigram ones, and the fields no
|
|
58
63
|
* index serves. */
|