viewkitjs 0.19.0 → 0.21.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +66 -0
- package/MIGRATION.md +117 -0
- package/README.md +7 -3
- package/fields/README.md +3 -3
- package/fields/dist/derived.d.ts +4 -0
- package/fields/dist/derived.js +39 -0
- package/fields/dist/entities.js +30 -30
- package/fields/dist/formula.js +2 -2
- package/fields/dist/query/evaluate.js +5 -5
- package/fields/dist/query/figures.js +5 -5
- package/fields/dist/query/filter.d.ts +15 -0
- package/fields/dist/query/filter.js +85 -0
- package/fields/dist/query/hold.js +2 -2
- package/fields/dist/query/option-counts.js +2 -2
- package/fields/dist/query/read-rule.js +2 -2
- package/fields/dist/query/search.js +2 -2
- package/fields/dist/query/set-aside.js +4 -4
- package/fields/dist/query/settings.d.ts +2 -15
- package/fields/dist/query/settings.js +3 -81
- package/fields/dist/query/sort.js +4 -4
- package/fields/dist/registry.d.ts +19 -5
- package/fields/dist/registry.js +371 -50
- package/fields/dist/types.d.ts +1 -1
- package/fields/docs/getting-started.md +2 -2
- package/fields/docs/guides/checking-definitions.md +17 -4
- package/fields/docs/guides/derived-fields.md +5 -5
- package/fields/docs/guides/queries.md +1 -1
- package/fields/docs/reference/design-category-colors.md +1 -1
- package/fields/docs/reference/design-status-slots.md +1 -1
- package/fields/docs/reference/fields.md +3 -3
- package/fields/docs/reference/query.md +1 -0
- package/fields/skills/viewkit/SKILL.md +2 -2
- package/package.json +17 -6
- package/postgres/README.md +2 -2
- package/postgres/dist/access.d.ts +12 -4
- package/postgres/dist/access.js +3 -0
- package/postgres/dist/calendar.js +3 -2
- package/postgres/dist/check.d.ts +6 -4
- package/postgres/dist/check.js +27 -16
- package/postgres/dist/counts.js +3 -2
- package/postgres/dist/definitions/build.js +7 -0
- package/postgres/dist/definitions/formula.d.ts +1 -1
- package/postgres/dist/definitions/formula.js +5 -3
- package/postgres/dist/definitions/lookup.js +5 -1
- package/postgres/dist/definitions/money.js +6 -1
- package/postgres/dist/definitions/place.d.ts +7 -0
- package/postgres/dist/definitions/place.js +8 -0
- package/postgres/dist/definitions/relations.js +36 -3
- package/postgres/dist/definitions/rollup.d.ts +1 -1
- package/postgres/dist/definitions/rollup.js +11 -6
- package/postgres/dist/field-values.js +11 -8
- package/postgres/dist/figures.js +4 -2
- package/postgres/dist/filled.js +2 -2
- package/postgres/dist/groups.d.ts +2 -1
- package/postgres/dist/groups.js +5 -3
- package/postgres/dist/index.d.ts +1 -0
- package/postgres/dist/index.js +1 -0
- package/postgres/dist/kept.js +8 -4
- package/postgres/dist/lanes.js +5 -3
- package/postgres/dist/phone.js +2 -2
- package/postgres/dist/predicates.js +2 -2
- package/postgres/dist/readable.d.ts +40 -0
- package/postgres/dist/readable.js +84 -0
- package/postgres/dist/records.js +7 -4
- package/postgres/dist/refusals.d.ts +8 -1
- package/postgres/dist/refusals.js +7 -0
- package/postgres/dist/relations.js +5 -4
- package/postgres/dist/search-indexes.js +2 -1
- package/postgres/dist/search.js +6 -4
- package/postgres/dist/several.js +8 -8
- package/postgres/dist/sort.d.ts +5 -3
- package/postgres/dist/sort.js +13 -8
- package/postgres/dist/value-rows.js +2 -2
- package/postgres/dist/values.js +4 -2
- package/postgres/docs/guides/definitions.md +2 -2
- package/postgres/docs/guides/field-map.md +43 -18
- package/postgres/docs/guides/test-kit.md +2 -0
- package/postgres/docs/reference/postgres.md +10 -4
- package/views/README.md +4 -2
- package/views/dist/atoms/StatusBadge.js +1 -1
- package/views/dist/atoms/tones.js +7 -7
- package/views/dist/atoms/types.d.ts +3 -2
- package/views/dist/contract.d.ts +7 -2
- package/views/dist/contract.js +33 -0
- package/views/dist/display/fit-values.d.ts +3 -2
- package/views/dist/display/link.d.ts +1 -1
- package/views/dist/display/location.js +2 -1
- package/views/dist/display/multi-value.js +1 -1
- package/views/dist/display/name.js +3 -1
- package/views/dist/display/select.js +1 -1
- package/views/dist/display/value-list.d.ts +1 -1
- package/views/dist/grid/chrome/GridStructure.js +2 -1
- package/views/dist/grid/looks.d.ts +45 -0
- package/views/dist/grid/looks.js +74 -0
- package/views/dist/looks/index.d.ts +7 -0
- package/views/dist/looks/index.js +3 -0
- package/views/dist/looks/looks.d.ts +46 -0
- package/views/dist/looks/looks.js +25 -0
- package/views/dist/looks/pieces.d.ts +3 -0
- package/views/dist/looks/pieces.js +2 -0
- package/views/dist/provider/ViewsProvider.d.ts +3 -3
- package/views/dist/provider/ViewsProvider.js +1 -1
- package/views/dist/provider/context.d.ts +1 -1
- package/views/dist/styles.css +3277 -0
- package/views/dist/styles.unlayered.css +3276 -0
- package/views/docs/contract.md +61 -13
- package/views/docs/getting-started.md +1 -1
- package/views/docs/guides/display.md +11 -7
- package/views/docs/guides/looks.md +29 -0
- package/views/docs/guides/the-grid.md +1 -1
- package/views/docs/guides/the-provider.md +1 -1
- package/views/docs/index.md +2 -0
- package/views/docs/install.md +36 -9
- package/views/docs/reference/display.md +2 -2
- package/views/docs/reference/looks.md +31 -0
- package/views/docs/reference/react.md +2 -2
- package/views/docs/reference/views.md +1 -1
- package/views/skills/views/SKILL.md +2 -2
package/postgres/dist/search.js
CHANGED
|
@@ -10,6 +10,7 @@ import { REFUSALS } from "./refusals.js";
|
|
|
10
10
|
import { FALSE, isSql, join, sql } from "./sql.js";
|
|
11
11
|
import { labelOf, leadOf, oneKeyOf, valueSql } from "./values.js";
|
|
12
12
|
import { rowProbeOn, rowProbeSql } from "./value-rows.js";
|
|
13
|
+
import { readableField } from "./readable.js";
|
|
13
14
|
const NEVER = new Set([
|
|
14
15
|
"number",
|
|
15
16
|
"percent",
|
|
@@ -21,7 +22,7 @@ const NEVER = new Set([
|
|
|
21
22
|
]);
|
|
22
23
|
const TEXT = new Set(["text", "rich_text", "url", "domain", "email"]);
|
|
23
24
|
function relationRead(scope, main, key) {
|
|
24
|
-
const { mapping } = scope.
|
|
25
|
+
const { mapping } = readableField(scope, main.table, key);
|
|
25
26
|
const value = mapping.value;
|
|
26
27
|
if (typeof value !== "object" || value === null)
|
|
27
28
|
throw REFUSALS.unsafeMapping(key);
|
|
@@ -35,9 +36,10 @@ function relationRead(scope, main, key) {
|
|
|
35
36
|
return { kind: "relation", own: oneKeyOf(scope, main, value.relation), to: relation.to };
|
|
36
37
|
}
|
|
37
38
|
export function searchedReadOf(scope, main, key) {
|
|
38
|
-
|
|
39
|
+
const field = readableField(scope, main.table, key);
|
|
40
|
+
if (field === undefined)
|
|
39
41
|
throw REFUSALS.unknownField(key);
|
|
40
|
-
const { def, type, mapping } =
|
|
42
|
+
const { def, type, mapping } = field;
|
|
41
43
|
if (NEVER.has(type))
|
|
42
44
|
return null;
|
|
43
45
|
const read = mapping.search;
|
|
@@ -93,7 +95,7 @@ function wordOf(scope, read, fenced) {
|
|
|
93
95
|
return (word) => phoneRuleSql(read.reading, { fieldKey: read.key, operator: "contains", value: word }, undefined);
|
|
94
96
|
case "row":
|
|
95
97
|
if (read.phone) {
|
|
96
|
-
const row = scope.
|
|
98
|
+
const row = readableField(scope, read.at.table, read.key).mapping.row;
|
|
97
99
|
return (word) => rowProbeOn(scope, read.at, read.key, (probe) => phoneRuleSql(phoneOnRow(probe, row, read.key), { fieldKey: read.key, operator: "contains", value: word }, undefined), fenced);
|
|
98
100
|
}
|
|
99
101
|
return (word) => rowProbeSql(scope, read.at, read.key, (value) => (read.option ? optionWord(read.def, value)(word) : foldedContainsSql(value, word)), fenced);
|
package/postgres/dist/several.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { elementsOf, joinWorkedOut, open } from "./access.js";
|
|
2
2
|
import { trimmedSql } from "./fold.js";
|
|
3
|
-
import { fieldsOf } from "./map.js";
|
|
4
3
|
import { phoneOf, phoneOfElement, phoneRuleSql } from "./phone.js";
|
|
5
4
|
import { optionSql, ruleSql } from "./rules.js";
|
|
6
5
|
import { sql, TRUE } from "./sql.js";
|
|
7
6
|
import { listSql, readSql } from "./values.js";
|
|
7
|
+
import { readableField } from "./readable.js";
|
|
8
8
|
const paren = (inner) => sql `(${inner})`;
|
|
9
9
|
const not = (inner) => sql `(NOT ${inner})`;
|
|
10
10
|
const EVERY_VALUE = new Set(["is_not", "not_contains"]);
|
|
@@ -12,7 +12,7 @@ const ITEM_KEYS = ["value", "label", "main"];
|
|
|
12
12
|
const OBJECT_TEXT = "[object Object]";
|
|
13
13
|
const NULL_TEXT = "null";
|
|
14
14
|
export function elementsOn(scope, at, key) {
|
|
15
|
-
const { mapping } =
|
|
15
|
+
const { mapping } = readableField(scope, at.table, key);
|
|
16
16
|
const several = mapping.several;
|
|
17
17
|
if (several.kept === "rows") {
|
|
18
18
|
const rows = open(scope, several.table, "f", several.pick);
|
|
@@ -45,7 +45,7 @@ function phoneReading(found, parts, key) {
|
|
|
45
45
|
return { international: sql `FALSE`, number: sql `NULL::text`, typed: found.element };
|
|
46
46
|
}
|
|
47
47
|
export function mainValueSql(scope, at, key) {
|
|
48
|
-
const several =
|
|
48
|
+
const several = readableField(scope, at.table, key).mapping.several;
|
|
49
49
|
const { made, read } = joinWorkedOut(at, `\u0000main\u0000${key}`, (named) => {
|
|
50
50
|
const worked = named();
|
|
51
51
|
if (several.kept === "rows" && several.oneMain === true)
|
|
@@ -59,7 +59,7 @@ export function mainValueSql(scope, at, key) {
|
|
|
59
59
|
return read(made.value);
|
|
60
60
|
}
|
|
61
61
|
function mainValueOf(scope, at, key, found) {
|
|
62
|
-
const { type, mapping } =
|
|
62
|
+
const { type, mapping } = readableField(scope, at.table, key);
|
|
63
63
|
if (type === "phone") {
|
|
64
64
|
const reading = phoneReading(found, mapping.parts, key);
|
|
65
65
|
return {
|
|
@@ -73,7 +73,7 @@ function mainValueOf(scope, at, key, found) {
|
|
|
73
73
|
return { value: text, kept: sql `(jsonb_typeof(${found.list}) <> 'array' OR ${trimmedSql(text)} <> '')` };
|
|
74
74
|
}
|
|
75
75
|
function mainRows(scope, at, key) {
|
|
76
|
-
const several =
|
|
76
|
+
const several = readableField(scope, at.table, key).mapping.several;
|
|
77
77
|
const found = elementsOn(scope, at, key);
|
|
78
78
|
const row = found.row;
|
|
79
79
|
const { value, kept } = mainValueOf(scope, at, key, found);
|
|
@@ -81,7 +81,7 @@ function mainRows(scope, at, key) {
|
|
|
81
81
|
return sql `SELECT ${row.row.column(several.record)} AS "record", ${value} AS "value" FROM ${found.from} WHERE (${main}) AND ${kept}`;
|
|
82
82
|
}
|
|
83
83
|
function mainPick(scope, at, key) {
|
|
84
|
-
const several =
|
|
84
|
+
const several = readableField(scope, at.table, key).mapping.several;
|
|
85
85
|
const valueOf = (found) => mainValueOf(scope, at, key, found);
|
|
86
86
|
if (several.kept === "rows") {
|
|
87
87
|
const found = elementsOn(scope, at, key);
|
|
@@ -105,7 +105,7 @@ export function joinedValueSql(scope, at, key) {
|
|
|
105
105
|
return read(made.value);
|
|
106
106
|
}
|
|
107
107
|
function joinedPick(scope, at, key) {
|
|
108
|
-
const several =
|
|
108
|
+
const several = readableField(scope, at.table, key).mapping.several;
|
|
109
109
|
const joined = (from, text, kept, place) => sql `SELECT CASE WHEN bool_or(${kept}) THEN string_agg(COALESCE(${text}, ''), ',' ORDER BY ${place}) END AS "value" FROM ${from}`;
|
|
110
110
|
if (several.kept === "rows") {
|
|
111
111
|
const found = elementsOn(scope, at, key);
|
|
@@ -150,7 +150,7 @@ export function severalSql(scope, at, checked, context, fenced = false) {
|
|
|
150
150
|
const found = elementsOn(scope, at, checked.key);
|
|
151
151
|
if (checked.type === "multiselect")
|
|
152
152
|
return optionsSql(found, checked, fenced);
|
|
153
|
-
const { mapping } =
|
|
153
|
+
const { mapping } = readableField(scope, at.table, checked.key);
|
|
154
154
|
let kept;
|
|
155
155
|
let holds;
|
|
156
156
|
if (checked.type === "phone") {
|
package/postgres/dist/sort.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { type ValueType } from "viewkitjs/fields";
|
|
|
2
2
|
import { type Opened, type Scope } from "./access.js";
|
|
3
3
|
import { type FieldMap, type MappedField, type RelationMap, type Stored } from "./map.js";
|
|
4
4
|
import { type Sql, type SqlQuery } from "./sql.js";
|
|
5
|
+
import { type Reader } from "./readable.js";
|
|
5
6
|
/** The most sorts a view holds ("A view holds up to 3 sorts", 11 Nov). */
|
|
6
7
|
export declare const SORTS_MOST = 3;
|
|
7
8
|
/** One sort, checked against the map: its field, the type its value has, its direction and its order of parts. */
|
|
@@ -78,11 +79,12 @@ export type RowWalk = {
|
|
|
78
79
|
/** The most options a select or a status walks one branch each: each branch costs Postgres about 0.15 ms to plan. */
|
|
79
80
|
export declare const OPTION_BRANCHES_MOST = 32;
|
|
80
81
|
/** `sorts` checked against the map, each refusal at its place; in their order, `by` filled with the type's first. A
|
|
81
|
-
* set-aside sort (`setAside`, fields' `readListSettings`) orders nothing and is left out
|
|
82
|
-
|
|
82
|
+
* set-aside sort (`setAside`, fields' `readListSettings`) orders nothing and is left out, checked only for whether the
|
|
83
|
+
* reader may read its field. */
|
|
84
|
+
export declare function checkSorts(scope: Reader, sorts: unknown): readonly CheckedSort[];
|
|
83
85
|
/** A relation's `sortBy` held to the map: a relation of one record, whose far table places the field, a number, a
|
|
84
86
|
* percent, a date or an instant. A sort and a group by the relation are refused alike, at `path`. */
|
|
85
|
-
export declare function checkFarOrder(scope:
|
|
87
|
+
export declare function checkFarOrder(scope: Reader, path: string, fieldKey: string, relation: RelationMap, sortBy: string): void;
|
|
86
88
|
/** A part as an ORDER BY item: its expression, its direction and where its NULLs go; a part never NULL, its direction
|
|
87
89
|
* alone, so one index serves it both ways. */
|
|
88
90
|
export declare function orderItem(part: KeyPart): Sql;
|
package/postgres/dist/sort.js
CHANGED
|
@@ -10,6 +10,7 @@ import { currencyOf } from "./rules.js";
|
|
|
10
10
|
import { joinedValueSql, mainValueSql } from "./several.js";
|
|
11
11
|
import { joinedOf, labelOf, partNamesOf, partSql, rowJoinOf, valueSql } from "./values.js";
|
|
12
12
|
import { rowFilledSql, rowProbeOn, rowProbeSql } from "./value-rows.js";
|
|
13
|
+
import { readableField } from "./readable.js";
|
|
13
14
|
export const SORTS_MOST = 3;
|
|
14
15
|
export const OPTION_BRANCHES_MOST = 32;
|
|
15
16
|
const WALKED = new Set([
|
|
@@ -31,6 +32,7 @@ export function checkSorts(scope, sorts) {
|
|
|
31
32
|
throw REFUSALS.badSort("sorts", `a view holds at most ${SORTS_MOST} sorts`);
|
|
32
33
|
const seen = new Set();
|
|
33
34
|
return sorts.flatMap((given, index) => {
|
|
35
|
+
const named = isRecord(given) && typeof given.fieldKey === "string" ? readableField(scope, map.table, given.fieldKey) : undefined;
|
|
34
36
|
if (isRecord(given) && given.setAside !== undefined)
|
|
35
37
|
return [];
|
|
36
38
|
const path = `sorts[${index}]`;
|
|
@@ -42,12 +44,12 @@ export function checkSorts(scope, sorts) {
|
|
|
42
44
|
(by !== undefined && typeof by !== "string")) {
|
|
43
45
|
throw REFUSALS.badSort(path, 'a sort is { fieldKey, direction: "asc" or "desc", by? }');
|
|
44
46
|
}
|
|
45
|
-
if (
|
|
47
|
+
if (named === undefined)
|
|
46
48
|
throw REFUSALS.unknownField(fieldKey);
|
|
47
49
|
if (seen.has(fieldKey))
|
|
48
50
|
throw REFUSALS.badSort(path, `${fieldKey} is sorted twice: a field sorts once in a view`);
|
|
49
51
|
seen.add(fieldKey);
|
|
50
|
-
const field =
|
|
52
|
+
const field = named;
|
|
51
53
|
const type = field.type;
|
|
52
54
|
const orders = sortOrdersFor(type);
|
|
53
55
|
if (by !== undefined && !orders.includes(by)) {
|
|
@@ -89,9 +91,10 @@ export function checkFarOrder(scope, path, fieldKey, relation, sortBy) {
|
|
|
89
91
|
const far = fieldsOf(scope.map, relation.to);
|
|
90
92
|
if (far === undefined)
|
|
91
93
|
throw REFUSALS.noFields(fieldKey, relation.to);
|
|
92
|
-
|
|
94
|
+
const farField = readableField(scope, relation.to, sortBy);
|
|
95
|
+
if (farField === undefined)
|
|
93
96
|
throw REFUSALS.unknownFarField(relation.to, sortBy);
|
|
94
|
-
const type =
|
|
97
|
+
const type = farField.type;
|
|
95
98
|
if (!FAR_ORDER_TYPES.has(type))
|
|
96
99
|
throw REFUSALS.badSort(path, `${fieldKey} sorts by ${sortBy}, a ${type}: a relation sorts by a number, a percent, a date or an instant`);
|
|
97
100
|
}
|
|
@@ -308,11 +311,11 @@ function farFieldPart(scope, main, sort, sortBy, last) {
|
|
|
308
311
|
const relation = sort.field.mapping.value.relation;
|
|
309
312
|
const joined = joinedOf(scope, main, relation);
|
|
310
313
|
const far = joined.far;
|
|
311
|
-
const farField =
|
|
314
|
+
const farField = readableField(scope, far.table, sortBy);
|
|
312
315
|
return last(joined.read(sql `(CASE WHEN ${far.row.key} IS NOT NULL THEN ${farOrderSql(scope, far, sortBy)} END)`), kindOf(farField.mapping.stored));
|
|
313
316
|
}
|
|
314
317
|
export function farOrderSql(scope, far, sortBy) {
|
|
315
|
-
const farField =
|
|
318
|
+
const farField = readableField(scope, far.table, sortBy);
|
|
316
319
|
return farField.mapping.sort !== undefined ? readSql(far, sortBy, farField.mapping.sort) : valueSql(scope, far, sortBy);
|
|
317
320
|
}
|
|
318
321
|
function currencyParts(scope, main, sort, def, amount, kind, last, flag, walkOn) {
|
|
@@ -320,9 +323,11 @@ function currencyParts(scope, main, sort, def, amount, kind, last, flag, walkOn)
|
|
|
320
323
|
return [flag(sql `${amount} IS NULL`)];
|
|
321
324
|
const code = Reflect.get(def, "code");
|
|
322
325
|
const siblingKey = isRecord(code) && typeof code.field === "string" ? code.field : null;
|
|
323
|
-
if (siblingKey === null
|
|
326
|
+
if (siblingKey === null)
|
|
327
|
+
return [last(amount, kind)];
|
|
328
|
+
const sibling = readableField(scope, main.table, siblingKey);
|
|
329
|
+
if (sibling === undefined)
|
|
324
330
|
return [last(amount, kind)];
|
|
325
|
-
const sibling = scope.map.fields[siblingKey];
|
|
326
331
|
const { mapping } = sibling;
|
|
327
332
|
if (mapping.stored !== "text" || mapping.parts !== undefined || mapping.several !== undefined)
|
|
328
333
|
throw REFUSALS.badSort(sort.path, `${sort.key}'s currency is ${siblingKey}, which must keep one text value`);
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { open } from "./access.js";
|
|
2
|
-
import { fieldsOf } from "./map.js";
|
|
3
2
|
import { nameSql, placeSql, rangeSql } from "./parts.js";
|
|
4
3
|
import { phoneOnRow, phoneRuleSql } from "./phone.js";
|
|
5
4
|
import { ruleSql } from "./rules.js";
|
|
6
5
|
import { castTo, FALSE, sql, TRUE } from "./sql.js";
|
|
6
|
+
import { readableField } from "./readable.js";
|
|
7
7
|
const NUMBERS = new Set(["number", "percent", "currency"]);
|
|
8
8
|
function rowAt(scope, at, key) {
|
|
9
|
-
const { mapping } =
|
|
9
|
+
const { mapping } = readableField(scope, at.table, key);
|
|
10
10
|
if (mapping.row === undefined)
|
|
11
11
|
throw new TypeError(`value-rows: ${key} is not kept in a row of its own`);
|
|
12
12
|
return { row: mapping.row, stored: mapping.stored };
|
package/postgres/dist/values.js
CHANGED
|
@@ -2,6 +2,7 @@ import { joinOnto, open } from "./access.js";
|
|
|
2
2
|
import { fieldsOf, isOneRelation } from "./map.js";
|
|
3
3
|
import { REFUSALS } from "./refusals.js";
|
|
4
4
|
import { isSql, sql } from "./sql.js";
|
|
5
|
+
import { readableField } from "./readable.js";
|
|
5
6
|
export function readSql(row, read, key) {
|
|
6
7
|
if (typeof read === "string")
|
|
7
8
|
return row.row.column(read);
|
|
@@ -99,8 +100,9 @@ function fieldAt(scope, at, key) {
|
|
|
99
100
|
const own = fieldsOf(scope.map, at.table);
|
|
100
101
|
if (own === undefined)
|
|
101
102
|
throw new TypeError(`valueSql reads a table whose fields the map describes, not ${at.table}'s`);
|
|
102
|
-
|
|
103
|
-
|
|
103
|
+
const field = readableField(scope, at.table, key);
|
|
104
|
+
if (field !== undefined)
|
|
105
|
+
return field;
|
|
104
106
|
throw at.table === scope.map.table
|
|
105
107
|
? REFUSALS.unknownField(key)
|
|
106
108
|
: REFUSALS.unknownFarField(at.table, key);
|
|
@@ -28,7 +28,7 @@ A link table and a table of several values are kinds too, with their own table,
|
|
|
28
28
|
```ts
|
|
29
29
|
import assert from "node:assert/strict";
|
|
30
30
|
import { defineFields, defineIndex } from "viewkitjs/fields";
|
|
31
|
-
import { keysQuery, sql, type Access, type Condition } from "viewkitjs/postgres";
|
|
31
|
+
import { EVERY_FIELD, keysQuery, sql, type Access, type Condition } from "viewkitjs/postgres";
|
|
32
32
|
import { buildFieldMap, StorageError, type AppStorage } from "viewkitjs/postgres/definitions";
|
|
33
33
|
|
|
34
34
|
const person = defineFields({
|
|
@@ -75,7 +75,7 @@ assert.deepEqual(built.leftOut, []);
|
|
|
75
75
|
const workspace = "00000000-0000-0000-0000-00000000000a";
|
|
76
76
|
const inWorkspace: Condition = (row) => sql`${row.column("workspace_id")} = ${workspace}`;
|
|
77
77
|
const access: Access = Object.fromEntries(Object.keys(built.reads).map((key) => [key, inWorkspace]));
|
|
78
|
-
const query = keysQuery({ map: built.map, access, filter: { op: "and", items: [{ fieldKey: "manager", operator: "is_not_empty", value: null }] } });
|
|
78
|
+
const query = keysQuery({ map: built.map, readable: EVERY_FIELD, access, filter: { op: "and", items: [{ fieldKey: "manager", operator: "is_not_empty", value: null }] } });
|
|
79
79
|
assert.ok(query.text.includes('"crm"."people"'));
|
|
80
80
|
|
|
81
81
|
// A storage it can't hold is refused at its path.
|
|
@@ -11,7 +11,7 @@ To build the map from your field definitions and a storage declaration instead o
|
|
|
11
11
|
```ts
|
|
12
12
|
import assert from "node:assert/strict";
|
|
13
13
|
import type { FieldDef } from "viewkitjs/fields";
|
|
14
|
-
import { defineFieldMap, EVERY_ROW, FieldMapError, identifier, keysQuery, pageQuery, RefusedRequest, sql, type SqlQuery } from "viewkitjs/postgres";
|
|
14
|
+
import { defineFieldMap, EVERY_FIELD, EVERY_ROW, FieldMapError, identifier, keysQuery, pageQuery, RefusedRequest, sql, type SqlQuery } from "viewkitjs/postgres";
|
|
15
15
|
|
|
16
16
|
const definitions: FieldDef[] = [
|
|
17
17
|
{ key: "title", label: "Title", type: "text" },
|
|
@@ -75,6 +75,7 @@ const objects = defineFieldMap({
|
|
|
75
75
|
const sorted = pageQuery({
|
|
76
76
|
map: objects,
|
|
77
77
|
access: { deals: EVERY_ROW, values: (row) => sql`${row.column("workspace_id")} = ${"w1"}::uuid` },
|
|
78
|
+
readable: EVERY_FIELD,
|
|
78
79
|
sorts: [{ fieldKey: "budget", direction: "asc" }],
|
|
79
80
|
size: 50,
|
|
80
81
|
});
|
|
@@ -82,6 +83,7 @@ assert.ok(sorted.text.includes("UNION ALL"));
|
|
|
82
83
|
const probed = keysQuery({
|
|
83
84
|
map: objects,
|
|
84
85
|
access: { deals: EVERY_ROW, values: (row) => sql`${row.column("workspace_id")} = ${"w1"}::uuid` },
|
|
86
|
+
readable: EVERY_FIELD,
|
|
85
87
|
filter: { op: "and", items: [{ fieldKey: "budget", operator: "gt", value: 5 }] },
|
|
86
88
|
});
|
|
87
89
|
assert.ok(probed.text.includes("EXISTS ("));
|
|
@@ -101,6 +103,7 @@ const contacts = defineFieldMap({
|
|
|
101
103
|
const byFamily = keysQuery({
|
|
102
104
|
map: contacts,
|
|
103
105
|
access: { people: EVERY_ROW, names: (row) => sql`${row.column("workspace_id")} = ${"w1"}::uuid` },
|
|
106
|
+
readable: EVERY_FIELD,
|
|
104
107
|
filter: { op: "and", items: [{ fieldKey: "contact", part: "family", operator: "contains", value: "pop" }] },
|
|
105
108
|
});
|
|
106
109
|
assert.ok(byFamily.text.includes(`EXISTS (SELECT 1 FROM (SELECT * FROM "objects"."value_name"`));
|
|
@@ -119,20 +122,35 @@ const deals = defineFieldMap({
|
|
|
119
122
|
});
|
|
120
123
|
const workspaceId = "00000000-0000-0000-0000-00000000000a";
|
|
121
124
|
|
|
122
|
-
const query = keysQuery({ map: deals, access: { deals: (row) => sql`${row.column("workspace_id")} = ${workspaceId}` } });
|
|
125
|
+
const query = keysQuery({ map: deals, readable: EVERY_FIELD, access: { deals: (row) => sql`${row.column("workspace_id")} = ${workspaceId}` } });
|
|
123
126
|
assert.equal(
|
|
124
127
|
query.text,
|
|
125
128
|
'SELECT "vk_r0"."id" AS "key" FROM (SELECT * FROM "crm"."deals" AS "vk_r0" WHERE "vk_r0"."deleted_at" IS NULL AND ("vk_r0"."workspace_id" = $1)) AS "vk_r0"'
|
|
126
129
|
);
|
|
127
130
|
assert.deepEqual(query.values, [workspaceId]);
|
|
128
131
|
|
|
129
|
-
assert.equal(keysQuery({ map: deals, access: { deals: EVERY_ROW } }).values.length, 0);
|
|
132
|
+
assert.equal(keysQuery({ map: deals, readable: EVERY_FIELD, access: { deals: EVERY_ROW } }).values.length, 0);
|
|
130
133
|
assert.throws(
|
|
131
|
-
() => keysQuery({ map: deals, access: {} }),
|
|
134
|
+
() => keysQuery({ map: deals, readable: EVERY_FIELD, access: {} }),
|
|
132
135
|
(error) => error instanceof RefusedRequest && error.code === "no-condition"
|
|
133
136
|
);
|
|
134
137
|
```
|
|
135
138
|
|
|
139
|
+
## The fields a reader may read
|
|
140
|
+
|
|
141
|
+
Every request also hands in `readable`: the fields its reader may read, per table of the map a list of field keys, or `EVERY_FIELD` for a table whose every field the reader may read; `readable: EVERY_FIELD` alone for a reader with no field rules. With none, the translator writes no SQL and throws a `RefusedRequest` (`no-field-list`), as it does for a table with no condition. A request that names any other field, in its filter (a rule set aside or still being typed too), its hold, its sorts, its group or board, a calendar, a count, figures, its search or a read of values, is refused as `hidden-field` before any SQL is written, so no count and no "contains" can tell a reader anything about a field they may not read, through a field worked out from it either. A far field, read through a relation, is held by its own table's list. A field worked out from others (a lookup, a rollup, a formula, an amount that converts, a relation of several records pointing back) is readable only when each field it reads is, each on its own table's list. A table's label is no field: whoever may see a record reads its label, so hiding a table's name field doesn't hide its label; hide the relation instead. A relation through a link kind whose end is the column one of the link kind's fields is kept in reads that field, so the link table needs a list too. A map you write yourself that reuses a built field's entry carries no record of the fields it reads: there it is held as itself alone.
|
|
142
|
+
|
|
143
|
+
```ts
|
|
144
|
+
const readable = { deals: ["title"] };
|
|
145
|
+
assert.ok(keysQuery({ map: deals, access: { deals: EVERY_ROW }, readable }).text.includes('"vk_r0"'));
|
|
146
|
+
assert.throws(
|
|
147
|
+
() => keysQuery({ map: deals, access: { deals: EVERY_ROW } } as never),
|
|
148
|
+
(error) => error instanceof RefusedRequest && error.code === "no-field-list"
|
|
149
|
+
);
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
A request your server builds from what a client sent takes `readable` from your server, beside `access`, never from the client: spread what the client sent first, then set both.
|
|
153
|
+
|
|
136
154
|
A condition stands only inside an AND, never under NOT, so a condition that comes out NULL for a row reads as "not seen". Write it however your app thinks of access: a workspace, one borrowed through a parent, shared records, anything SQL can say.
|
|
137
155
|
|
|
138
156
|
A condition your app already writes for a row alias, with subqueries of its own, takes the row's `alias`: the plain name the translator opened the row under (`vk_` and a letter and a number), which reads the same quoted or bare. Quote it with `identifier` as you would any name. A subquery of your condition may alias its own table by the row's alias and a suffix (`${row.alias}_teams`): the translator's own names are `vk_`, a letter and a number, so such a name never meets one of them. Every row the translator opens names its alias; the type leaves it optional only so a row your own code builds needs none.
|
|
@@ -140,7 +158,7 @@ A condition your app already writes for a row alias, with subqueries of its own,
|
|
|
140
158
|
```ts
|
|
141
159
|
const reach = (alias: string) => sql`${identifier(alias, "workspace_id")} = ${workspaceId}`;
|
|
142
160
|
// A row with no alias (one your own code built) would name "", which identifier refuses.
|
|
143
|
-
const byAlias = keysQuery({ map: deals, access: { deals: (row) => reach(row.alias ?? "") } });
|
|
161
|
+
const byAlias = keysQuery({ map: deals, readable: EVERY_FIELD, access: { deals: (row) => reach(row.alias ?? "") } });
|
|
144
162
|
assert.equal(byAlias.text, query.text);
|
|
145
163
|
```
|
|
146
164
|
|
|
@@ -174,13 +192,13 @@ const contactsMap = defineFieldMap({
|
|
|
174
192
|
});
|
|
175
193
|
const contactsAccess = { people: EVERY_ROW, members: EVERY_ROW, companies: EVERY_ROW, companyLinks: EVERY_ROW } as const;
|
|
176
194
|
// Sorted by the main company: the lead row joined once, then its company, never a subquery per row.
|
|
177
|
-
const byCompany = pageQuery({ map: contactsMap, access: contactsAccess, sorts: [{ fieldKey: "company", direction: "asc" }], size: 50 });
|
|
195
|
+
const byCompany = pageQuery({ map: contactsMap, readable: EVERY_FIELD, access: contactsAccess, sorts: [{ fieldKey: "company", direction: "asc" }], size: 50 });
|
|
178
196
|
assert.ok(byCompany.text.includes(`LEFT JOIN (SELECT * FROM "contacts"."person_company"`) && !byCompany.text.includes("ARRAY("));
|
|
179
197
|
// A rule probes the lead row by record.
|
|
180
|
-
const noCompany = keysQuery({ map: contactsMap, access: contactsAccess, filter: { op: "and", items: [{ fieldKey: "company", operator: "is_empty", value: null }] } });
|
|
198
|
+
const noCompany = keysQuery({ map: contactsMap, readable: EVERY_FIELD, access: contactsAccess, filter: { op: "and", items: [{ fieldKey: "company", operator: "is_empty", value: null }] } });
|
|
181
199
|
assert.ok(noCompany.text.includes("EXISTS (") && !noCompany.text.includes("LEFT JOIN"));
|
|
182
200
|
// Sorted by owner: the users' table joined once, sorted by its label.
|
|
183
|
-
const byOwner = pageQuery({ map: contactsMap, access: contactsAccess, sorts: [{ fieldKey: "owner", direction: "asc" }], size: 50 });
|
|
201
|
+
const byOwner = pageQuery({ map: contactsMap, readable: EVERY_FIELD, access: contactsAccess, sorts: [{ fieldKey: "owner", direction: "asc" }], size: 50 });
|
|
184
202
|
assert.ok(byOwner.text.includes(`LEFT JOIN (SELECT * FROM "platform"."member"`));
|
|
185
203
|
```
|
|
186
204
|
|
|
@@ -208,7 +226,7 @@ const worked = defineFieldMap({
|
|
|
208
226
|
definitions: [{ key: "client", label: "Client", type: "relation", relation: { kind: "client" } } as FieldDef],
|
|
209
227
|
fields: { client: { value: { relation: "client" }, stored: "uuid" } },
|
|
210
228
|
});
|
|
211
|
-
const byClient = keysQuery({ map: worked, access: { runs: EVERY_ROW, clients: EVERY_ROW }, search: { text: "ana", fields: ["client"] } });
|
|
229
|
+
const byClient = keysQuery({ map: worked, readable: EVERY_FIELD, access: { runs: EVERY_ROW, clients: EVERY_ROW }, search: { text: "ana", fields: ["client"] } });
|
|
212
230
|
assert.ok(byClient.text.includes(`concat_ws(' ', "vk_f1"."given", "vk_f1"."family")`));
|
|
213
231
|
```
|
|
214
232
|
|
|
@@ -240,6 +258,7 @@ void [readWithPool, readWithPrisma];
|
|
|
240
258
|
const filtered = keysQuery({
|
|
241
259
|
map: deals,
|
|
242
260
|
access: { deals: EVERY_ROW },
|
|
261
|
+
readable: EVERY_FIELD,
|
|
243
262
|
filter: { op: "and", items: [{ fieldKey: "title", operator: "is_empty", value: null }] },
|
|
244
263
|
context: { timeZone: "Europe/Bucharest", now: new Date("2026-11-05T09:00:00.000Z") },
|
|
245
264
|
});
|
|
@@ -286,6 +305,7 @@ const withCompanies = defineFieldMap({
|
|
|
286
305
|
const gold = keysQuery({
|
|
287
306
|
map: withCompanies,
|
|
288
307
|
access: { deals: EVERY_ROW, companies: EVERY_ROW },
|
|
308
|
+
readable: EVERY_FIELD,
|
|
289
309
|
filter: {
|
|
290
310
|
op: "and",
|
|
291
311
|
items: [
|
|
@@ -333,6 +353,7 @@ const narrowed = defineFieldMap({
|
|
|
333
353
|
const withPartners = keysQuery({
|
|
334
354
|
map: narrowed,
|
|
335
355
|
access: { deals: EVERY_ROW, companies: EVERY_ROW, links: EVERY_ROW },
|
|
356
|
+
readable: EVERY_FIELD,
|
|
336
357
|
filter: { op: "and", items: [{ fieldKey: "partners", operator: "is_not_empty", value: null }] },
|
|
337
358
|
});
|
|
338
359
|
assert.deepEqual(withPartners.values, [["gold"]]);
|
|
@@ -358,6 +379,7 @@ A request's `hold` is what a quick filter holds on top of the view (`viewkitjs/f
|
|
|
358
379
|
const searched = keysQuery({
|
|
359
380
|
map: deals,
|
|
360
381
|
access: { deals: EVERY_ROW },
|
|
382
|
+
readable: EVERY_FIELD,
|
|
361
383
|
search: { text: "Ștefan, acme", fields: ["title"] },
|
|
362
384
|
});
|
|
363
385
|
assert.equal(searched.values[0], "ștefan, acme");
|
|
@@ -422,6 +444,7 @@ const list = defineFieldMap({
|
|
|
422
444
|
const ordered = {
|
|
423
445
|
map: list,
|
|
424
446
|
access: { deals: EVERY_ROW },
|
|
447
|
+
readable: EVERY_FIELD,
|
|
425
448
|
sorts: [
|
|
426
449
|
{ fieldKey: "total", direction: "desc" },
|
|
427
450
|
{ fieldKey: "title", direction: "asc" },
|
|
@@ -465,7 +488,7 @@ const collated = defineFieldMap({
|
|
|
465
488
|
fields: { title: { value: "title", stored: "text" } },
|
|
466
489
|
textSort: { collation: "und-x-icu", length: 512 },
|
|
467
490
|
});
|
|
468
|
-
const byTitle = pageQuery({ map: collated, access: { deals: EVERY_ROW }, sorts: [{ fieldKey: "title", direction: "asc" }], size: 2 });
|
|
491
|
+
const byTitle = pageQuery({ map: collated, readable: EVERY_FIELD, access: { deals: EVERY_ROW }, sorts: [{ fieldKey: "title", direction: "asc" }], size: 2 });
|
|
469
492
|
assert.ok(byTitle.text.includes(`ORDER BY left(NULLIF("vk_r0"."title", ''), 512) COLLATE "und-x-icu" ASC NULLS LAST, "vk_r0"."id" ASC`));
|
|
470
493
|
|
|
471
494
|
// Several emails kept as rows of their own sort by the row their main mark names, worked out once per row.
|
|
@@ -478,7 +501,7 @@ const people = defineFieldMap({
|
|
|
478
501
|
definitions: [{ key: "emails", label: "Emails", type: "email", multiple: true } as FieldDef],
|
|
479
502
|
fields: { emails: { stored: "text", several: { kept: "rows", table: "emails", record: "person_id", value: "email", main: "is_main" } } },
|
|
480
503
|
});
|
|
481
|
-
const byEmail = pageQuery({ map: people, access: { people: EVERY_ROW, emails: EVERY_ROW }, sorts: [{ fieldKey: "emails", direction: "asc" }], size: 2 });
|
|
504
|
+
const byEmail = pageQuery({ map: people, readable: EVERY_FIELD, access: { people: EVERY_ROW, emails: EVERY_ROW }, sorts: [{ fieldKey: "emails", direction: "asc" }], size: 2 });
|
|
482
505
|
assert.ok(byEmail.text.includes(`AND ("vk_f2"."is_main")`));
|
|
483
506
|
assert.ok(byEmail.text.includes(`ORDER BY NULLIF("vk_f1"."value", '') ASC NULLS LAST`));
|
|
484
507
|
|
|
@@ -492,7 +515,7 @@ const peopleOneMain = defineFieldMap({
|
|
|
492
515
|
definitions: [{ key: "emails", label: "Emails", type: "email", multiple: true } as FieldDef],
|
|
493
516
|
fields: { emails: { stored: "text", several: { kept: "rows", table: "emails", record: "person_id", value: "email", main: "is_main", oneMain: true } } },
|
|
494
517
|
});
|
|
495
|
-
const byOneEmail = pageQuery({ map: peopleOneMain, access: { people: EVERY_ROW, emails: EVERY_ROW }, sorts: [{ fieldKey: "emails", direction: "asc" }], size: 2 });
|
|
518
|
+
const byOneEmail = pageQuery({ map: peopleOneMain, readable: EVERY_FIELD, access: { people: EVERY_ROW, emails: EVERY_ROW }, sorts: [{ fieldKey: "emails", direction: "asc" }], size: 2 });
|
|
496
519
|
assert.ok(byOneEmail.text.includes("LEFT JOIN (SELECT") && !byOneEmail.text.includes("LATERAL"));
|
|
497
520
|
|
|
498
521
|
// A field the map marks notNull sorts by its direction alone, so one index serves newest first and oldest first.
|
|
@@ -502,11 +525,11 @@ const stamped = defineFieldMap({
|
|
|
502
525
|
definitions: [{ key: "created", label: "Created", type: "datetime" }],
|
|
503
526
|
fields: { created: { value: "created_at", stored: "timestamptz", notNull: true } },
|
|
504
527
|
});
|
|
505
|
-
const newestFirst = pageQuery({ map: stamped, access: { deals: EVERY_ROW }, sorts: [{ fieldKey: "created", direction: "desc" }], size: 2 });
|
|
528
|
+
const newestFirst = pageQuery({ map: stamped, readable: EVERY_FIELD, access: { deals: EVERY_ROW }, sorts: [{ fieldKey: "created", direction: "desc" }], size: 2 });
|
|
506
529
|
assert.ok(newestFirst.text.includes(`ORDER BY "vk_r0"."created_at" DESC, "vk_r0"."id" DESC`));
|
|
507
530
|
```
|
|
508
531
|
|
|
509
|
-
- **A set-aside sort orders nothing.** A sort a list's settings set aside (it carries `setAside`, fields' `readListSettings`) is left out
|
|
532
|
+
- **A set-aside sort orders nothing.** A sort a list's settings set aside (it carries `setAside`, fields' `readListSettings`) is left out, the next one deciding, checked only for whether the reader may read its field: one naming a field your map no longer holds is never refused, one naming a field the reader may not read is (`hidden-field`).
|
|
510
533
|
- **Up to 3 sorts, a field once.** Each sorts by its whole value or, for a name, a place or a range, by the order of its parts it names (`by`): a name as written, by family name then given, or by given name then family; a place by its city, region, postal code or country (by its name in the request's `language`, else its `locale`); a range by its low end then its high end, or the other way. An empty value (no value, `""`, a name or a place with no part, a range with neither end) is last whichever the direction; a value without the part a sort reads (a name with no family name, sorted by it) comes after the rest and before the empties. Options sort in the order the field declares them, a status in its lifecycle's order, a value the field doesn't list after them all. A relation sorts by its records' names, read from its far table's `label` under that table's own condition: one record by its name, several by their names put in A-to-Z order and compared one by one, a value whose names run out first coming first. A relation of one record whose definition names `sortBy` sorts by that far field instead (a number, a percent, a date or an instant: a deal's stage by its position), read on its far record under that table's own condition, its own `sort` if it has one; a record the reader may not see, a deleted one or no value is empty, and the far table needs no `label`. A user sorts by the name its map's `sort` reads, or, read through its users' table, by that table's label; a relation of one record kept on a link table's lead row sorts as one kept in a column. Several emails, links, domains or phones sort by their main value (*Values of more than one shape*), a list with none empty, or by their `sort` when the map gives one; rows of their own need their `several.main` to sort. Several options sort by their values joined with `","` as one text, not in the order the field declares its options, or by their `sort` as text, `""` empty; rows of their own need no `several.main`. A lookup, a phone and an actor sort by their map's `sort` too: a lookup as the type it shows sorts a value (options in their order, text with `""` empty); a lookup of a name, a place, a range or money by its read alone, and of a relation by its read as a name; a lookup of a place with no `sort` and its `parts` by those parts, as a place sorts (every `by` a place takes, its country by name in the request's `language`, else its `locale`); a phone by its read as text, `""` empty; an actor by its read as a name, as a user does. A lookup's `sort` is your own expression: one that reads another table answers for access itself. A field's `sort` stands in for its value for every type read from one value, so a sort can read a column of its own; a name, a place and a range sort by their parts, and a relation by its far records. It must read a value of the type the field's `stored` names (text, for a user's or a relation's name), since a cursor carries it back as that type.
|
|
511
534
|
- **A field that is never empty.** A number, a percent, a date, an instant or a yes-or-no on the list's own table that the map marks `notNull` orders by its direction alone: it promises no row holds NULL there, so its empties need no place of their own. Broken anyway: the NULL rows show only on a first page that reaches them (ascending, after the last valued row; descending, first; for a later sort, within each run of the ones before it, where a later page may reach them too); load more after a valued row never reaches them, and load more after a page ending on one is refused (`bad-cursor`). Never a wrong or repeated page. A rollup or a formula you map to a column of the row takes `notNull` as your promise too; a lookup and a far table's field are refused it. A cursor written before you marked a field reads back after.
|
|
512
535
|
- **Text sorts in your database's order, or in the one your map names.** With no `textSort`, text compares as its column does, so on a `C` or libc database a page may come in another order than ViewKit's. `textSort.collation` names the one collation every text part a sort reads compares under (a text, a link, a domain, an email, an open select, a closed select's or a status's tie-break, a money field's code, a name's and a place's parts, a relation's or a user's name, a `sort` read of text), quoted whole as Postgres names it (`en_US.utf8` is one name). ViewKit's own order is its collator for the request's locale at base strength, so the collation to name is that locale's ICU one. For a locale with no ordering of its own, English among them, that is ICU root, `und-x-icu`: a page comes in ViewKit's order, but for texts ViewKit counts equal ("ana" and "Ana"), which ICU orders, and that order decides before a later part does (a name's given name after its family name, a relation's second name). A nondeterministic ICU collation at base strength counts them equal as ViewKit does, so the later part decides and the order is ViewKit's own: `CREATE COLLATION vk_base (provider = icu, locale = 'und-u-ks-level1', deterministic = false)`, then `textSort: { collation: "vk_base" }`. A locale with an ordering of its own (Romanian puts "ă" after "a", Swedish "ä" after "z") names its own: `ro-x-icu`, or `ro-u-ks-level1` the same way at base strength. One map names one collation, while ViewKit follows each request's locale, so a map read in several locales agrees with one of them. `textSort.length` reads at most that many characters of each text, so a cursor stays small; two texts alike that far come in key order. A list's groups order by name the same way, collated and cut, so a list and its groups never disagree about the alphabet. A number, a day and an instant compare as their columns. An endless day (`infinity`) sorts as the latest day, though a filter reads it as no day.
|
|
@@ -543,6 +566,7 @@ const cards = defineFieldMap({
|
|
|
543
566
|
const opened = valuesQuery({
|
|
544
567
|
map: cards,
|
|
545
568
|
access: { deals: EVERY_ROW, companies: EVERY_ROW },
|
|
569
|
+
readable: EVERY_FIELD,
|
|
546
570
|
ids: ["6f1c1c3e-0000-4000-8000-000000000001"],
|
|
547
571
|
fields: ["title", "company"],
|
|
548
572
|
});
|
|
@@ -574,7 +598,7 @@ Each count is a `Step`: its `query` (SQL text and its values) and `read(rows)`,
|
|
|
574
598
|
- **`optionCountsQuery(request, fieldKey)`** counts each option of a select, a status, a tag list, a user, a relation, an actor or a yes-or-no with that field's own rules left out, as ViewKit's `countOptions` does: every rule on the field the whole filter requires, so its picker shows the alternatives while every other rule still narrows. It answers `{ counts, labels }`: every option the field declares, and the empty key `""`, is listed in `counts`, at 0 when no row holds it; `labels` names a relation's record, a user or an actor by what the database read for it. A row counts once under each value its list holds and under each record a relation of several records reaches, every related table read under its own condition. No quick-filter hold narrows it.
|
|
575
599
|
- **`holdCountsQuery(request, fieldKey)`** counts each value a quick filter offers on the same fields, as ViewKit's `countHoldValues` does: under the whole filter, the field's own rules included, the search and the request's hold on the OTHER fields, never the field's own, so a value's count is the rows a press on it shows. It answers and refuses as `optionCountsQuery` does.
|
|
576
600
|
- **`groupsQuery`** splits the rows by one field, as ViewKit's `bucketRows` does: each group's `key` (`""` for rows with no value), its `count`, the `label` the database read for a relation, a user or an actor, and whether the app's placing or `hideEmpty` hides it. The empty group comes last, the groups the app placed by hand first, then by count, name, the field's own order or the app's order. A relation of one record whose definition names `sortBy` opens a group for every far record its table's condition lets the reader see, one no row points at included, at 0; in the field's own order (`lifecycle`) they are ordered by that far field, read on the far record under that condition: the direction applied, a record with no value after the rest, a tie by name, then by key. A relation with no `sortBy` is ordered by its records' names. Names are ordered as the map's sorts order text: under its `textSort`, collated and cut, else in the database's own order. A field whose type makes no groups answers one group, `"_all"`.
|
|
577
|
-
- **A set-aside group** (it carries `setAside`, fields' `readListSettings`) splits nothing: `groupsQuery` answers one group of every row, `"_all"`, as for a field that makes no groups, and its field is
|
|
601
|
+
- **A set-aside group** (it carries `setAside`, fields' `readListSettings`) splits nothing: `groupsQuery` answers one group of every row, `"_all"`, as for a field that makes no groups, and its field is checked only for whether the reader may read it.
|
|
578
602
|
- **`groupKeysQuery(request, key)`** is one group's keys, unordered: exactly the rows its count counted. A key the field could never hold selects no row.
|
|
579
603
|
|
|
580
604
|
```ts
|
|
@@ -597,7 +621,7 @@ const pipeline = defineFieldMap({
|
|
|
597
621
|
],
|
|
598
622
|
fields: { stage: { value: "stage", stored: "text" }, due: { value: "due", stored: "date" } },
|
|
599
623
|
});
|
|
600
|
-
const counting: KeysRequest = { map: pipeline, access: { deals: EVERY_ROW } };
|
|
624
|
+
const counting: KeysRequest = { map: pipeline, readable: EVERY_FIELD, access: { deals: EVERY_ROW } };
|
|
601
625
|
|
|
602
626
|
const total = totalQuery({ ...counting, cap: 10000 });
|
|
603
627
|
assert.ok(total.query.text.startsWith('SELECT count(*) AS "total" FROM (SELECT 1 FROM'));
|
|
@@ -642,7 +666,7 @@ const ledger = defineFieldMap({
|
|
|
642
666
|
definitions: [{ key: "amount", label: "Amount", type: "currency", code: { fixed: "EUR" } } as FieldDef],
|
|
643
667
|
fields: { amount: { value: "amount", stored: "numeric" } },
|
|
644
668
|
});
|
|
645
|
-
const figures = figuresQuery({ map: ledger, access: { deals: EVERY_ROW }, keys: ["amount"] });
|
|
669
|
+
const figures = figuresQuery({ map: ledger, readable: EVERY_FIELD, access: { deals: EVERY_ROW }, keys: ["amount"] });
|
|
646
670
|
assert.ok(figures.query.text.startsWith('SELECT count(*) AS "rows", ARRAY[(SELECT'));
|
|
647
671
|
void answer(figures, async () => [
|
|
648
672
|
{ rows: "2", vk_sums: [String(30.5 * 2 ** -64)], vk_counts: ["2"], vk_mins: ["1.0000000000000000e+01"], vk_maxes: ["2.0500000000000000e+01"], vk_filled: ["2"] },
|
|
@@ -659,7 +683,7 @@ Each of these counts or pages the rows `keysQuery` keeps, under the same permiss
|
|
|
659
683
|
- **`viewCountsQuery`** counts each view in one statement, each view's `filter` beside the request's own filter and search (a quick filter, a pin), at most 100 views (`VIEW_COUNTS_LIMIT`).
|
|
660
684
|
- **`idsQuery`** is every key the list keeps, in the order its pages hold them, read a page of 1,000 a step with no cap: the ids behind "select all matching", and with manual order and no filter, the order a drag splices into.
|
|
661
685
|
- **`groupPageQuery`** pages one group's rows, by keyset, under the list's sorts or its manual order: exactly the rows the group counts. Its cursor is bound to the group and its key, so a cursor of one group is refused for another.
|
|
662
|
-
- **`lanesQuery`** is a board's lanes: every lane's count, then one statement holding the first `size` cards (25, `LANE_ROWS`) of the first `fill` lanes shown (10, `LANES_FILLED`). Hand the board's field as a group (fields' `boardAxis`): a status, a select, a yes-or-no, a relation of one record or a user; a board by a relation that names `sortBy` opens a lane for each far record the reader may see, an empty one answered filled, with no cards; any other is refused as `no-layout`. A set-aside board field is no board field: replace it with `boardAxis(defaultBoardField(…), lanes)` before you ask; a `board` that still carries the mark gets one `"_all"` lane of every row. Each lane's `next` is read by `groupPageQuery` for that lane.
|
|
686
|
+
- **`lanesQuery`** is a board's lanes: every lane's count, then one statement holding the first `size` cards (25, `LANE_ROWS`) of the first `fill` lanes shown (10, `LANES_FILLED`). Hand the board's field as a group (fields' `boardAxis`): a status, a select, a yes-or-no, a relation of one record or a user; a board by a relation that names `sortBy` opens a lane for each far record the reader may see, an empty one answered filled, with no cards; any other is refused as `no-layout`. A set-aside board field is no board field: replace it with `boardAxis(defaultBoardField(…), lanes)` before you ask; a `board` that still carries the mark gets one `"_all"` lane of every row, its field checked only for whether the reader may read it. Each lane's `next` is read by `groupPageQuery` for that lane.
|
|
663
687
|
- **`calendarQuery`** is a calendar's month in the request's zone, in one statement: each day's count, the first 500 rows in date order (`CALENDAR_ROWS_LIMIT`), and every day those didn't reach topped up with its first 2 (`CALENDAR_DAY_ROWS`), so each cell draws what it holds and its "+N" is the day's real count. At most 42 days (`CALENDAR_DAYS_LIMIT`); a date or a date and time only, else `no-layout`. The zone is read only in each day's first instant, worked out in JavaScript.
|
|
664
688
|
- **A page's cursor is bound to the region** (`context.region`) when a phone rule reads it: a cursor made under one region is refused under another.
|
|
665
689
|
- **A page's cursor is bound to the currencies** it reads (`context.currencies`) when it sorts, filters or groups by a field whose definition converts: a cursor made under one is refused under another.
|
|
@@ -686,6 +710,7 @@ const board = defineFieldMap({
|
|
|
686
710
|
const lanes = lanesQuery({
|
|
687
711
|
map: board,
|
|
688
712
|
access: { deals: EVERY_ROW },
|
|
713
|
+
readable: EVERY_FIELD,
|
|
689
714
|
board: { fieldKey: "stage", order: { mode: "lifecycle", dir: "asc" }, buckets: [] },
|
|
690
715
|
});
|
|
691
716
|
// No lane holds a card, so the lanes are read in one step.
|
|
@@ -17,6 +17,7 @@ import assert from "node:assert/strict";
|
|
|
17
17
|
import type { KitBackend, KitQuestion, KitSamples } from "viewkitjs/fields/testing";
|
|
18
18
|
import {
|
|
19
19
|
answer,
|
|
20
|
+
EVERY_FIELD,
|
|
20
21
|
EVERY_ROW,
|
|
21
22
|
figuresQuery,
|
|
22
23
|
holdCountsQuery,
|
|
@@ -41,6 +42,7 @@ function postgresBackend(run: Run, load: (samples: KitSamples) => Promise<FieldM
|
|
|
41
42
|
const requestOf = (question: KitQuestion): KeysRequest => ({
|
|
42
43
|
map: map!,
|
|
43
44
|
access: access(),
|
|
45
|
+
readable: EVERY_FIELD,
|
|
44
46
|
filter: question.settings.filter,
|
|
45
47
|
search: { text: question.settings.search ?? "", fields: question.searchFields },
|
|
46
48
|
// The `hold` area's questions hold a quick filter on top of the settings.
|
|
@@ -22,7 +22,7 @@ The one door. Guide: [the field map and the permission condition](../guides/fiel
|
|
|
22
22
|
- `TableFields` — a table's fields as the map holds them (`FieldMap.tableFields`, by table): each field it places, and the key of every field it defines.
|
|
23
23
|
- `FieldMapping` — where one field is read (`value`, a relation field's or a user's `{ relation }` among them, `parts`, or `row`, one value kept in a row of a table many fields share, or a value made of parts kept in its type's own table), the SQL type it is kept as (`stored`), how several values are kept (`several`), what a sort and a search read, and whether it is never empty (`notNull`, a sort by it ordered by its direction alone).
|
|
24
24
|
- `MappedField` — a field of the map: its definition, the type its value has, and where it is read.
|
|
25
|
-
- `Read` — a column of the row, or your own SQL over it. An expression is your own SQL, written as you wrote it: build it with sql from your own code, never from text a person typed; one that reads another table answers for access itself.
|
|
25
|
+
- `Read` — a column of the row, or your own SQL over it. An expression is your own SQL, written as you wrote it: build it with sql from your own code, never from text a person typed; one that reads another table answers for access itself, and one that reads another field answers for that field's readers.
|
|
26
26
|
- `RelationMap` — a relation between two of the map's tables: one (`column`, a column or your expression over the row it starts from, returning the far key), many pointing back (`back`), or many through a link table (`through`), which may name the columns that pick one relation's links out of a table many relations share (`pick`), and its lead row (`lead`, a boolean column of the link row or your condition over it), which makes it reach one record.
|
|
27
27
|
- `Row` — a row the translator opened: `alias` is the plain name it was opened under (`vk_r0`), `column(name)` quotes a column under it, `key` is its key column.
|
|
28
28
|
- `Several` — how a field of several values keeps them: an array, a json array, or rows of their own, which may name their main mark (`main`, a boolean column or your condition over the row) for a sort by the main one, whether at most one row per record holds that mark (`oneMain: true`, your write path's promise), which reads the main rows through one join, and the columns that pick one field's rows out of a table many fields share (`pick`).
|
|
@@ -39,9 +39,15 @@ The one door. Guide: [the field map and the permission condition](../guides/fiel
|
|
|
39
39
|
|
|
40
40
|
- `EVERY_ROW` — said instead of a condition, for a table whose every row the reader may read.
|
|
41
41
|
- `Condition` — a table's permission condition: a function of its row returning SQL, or `EVERY_ROW`.
|
|
42
|
-
- `Access` — the condition for each table of the map a query reaches, by the map's table keys.
|
|
42
|
+
- `Access` — the condition for each table of the map a query reaches, by the map's table keys: which rows the reader may read.
|
|
43
|
+
|
|
44
|
+
## The readable fields
|
|
45
|
+
|
|
46
|
+
- `EVERY_FIELD` — said instead of a list, for a reader who may read every field: of one table, or of every table.
|
|
47
|
+
- `EveryField` — `EVERY_FIELD`'s own type: a symbol no other symbol passes for, kept as it is in a request built apart from its call.
|
|
48
|
+
- `Readable` — the fields the reader may read: `EVERY_FIELD`, or per table of the map, by its table keys, a list of field keys or `EVERY_FIELD`. A request names a field it doesn't hold, in a filter, a hold, a sort, a group, a board, a calendar, a count, a figure, a search or a read of values, and is refused as `hidden-field`, a rule set aside or still being typed included. A far field is held by its own table's list. A field worked out from others (a lookup, a rollup, a formula, an amount that converts, a relation of several records pointing back) is readable only when each field it reads is, on its own table's list. A table's label is no field: whoever may see a record reads its label, so hiding a table's name field doesn't hide its label. A key the map doesn't place grants nothing and is no refusal.
|
|
43
49
|
- `RefusedRequest` — a request the translator writes no SQL for; `code` says why.
|
|
44
|
-
- `RefusalCode` — why a request is refused: `not-a-map`, `unknown-table`, `not-a-condition`, `no-condition`, `no-sql`, `unknown-field`, `unsafe-mapping`, `bad-rule` (a filter rule ViewKit wouldn't accept, at its place, or a search text Postgres can't keep), `bad-hold` (a quick-filter hold fields' `listHoldSchema` refuses, at its place), `bad-sort` (a sort or a manual order it can't answer, at its place), `bad-cursor` (a cursor read under other settings, or one it can't read), `no-label` (a search or a sort by a relation whose far table names no label), `no-options` (a field with no options to count, or none whose values it offers), `too-many` (more keys or date buckets than the limit), `too-big` (a filter, a search or a statement past one of the request's caps, its message naming the cap and the place), `no-layout` (a board or a calendar laid out by a field that can't lay one out), `no-fields` (a relation rule, a far value or a sort by a far field reaching a table whose fields the map doesn't describe) or `not-yet`.
|
|
50
|
+
- `RefusalCode` — why a request is refused: `not-a-map`, `unknown-table`, `not-a-condition`, `no-condition`, `no-sql`, `unknown-field`, `unsafe-mapping`, `bad-rule` (a filter rule ViewKit wouldn't accept, at its place, or a search text Postgres can't keep), `bad-hold` (a quick-filter hold fields' `listHoldSchema` refuses, at its place), `bad-sort` (a sort or a manual order it can't answer, at its place), `bad-cursor` (a cursor read under other settings, or one it can't read), `no-label` (a search or a sort by a relation whose far table names no label), `no-options` (a field with no options to count, or none whose values it offers), `too-many` (more keys or date buckets than the limit), `too-big` (a filter, a search or a statement past one of the request's caps, its message naming the cap and the place), `no-layout` (a board or a calendar laid out by a field that can't lay one out), `no-fields` (a relation rule, a far value or a sort by a far field reaching a table whose fields the map doesn't describe), `no-field-list` (a request handing no list of readable fields, or none for a table one of its reads reaches), `not-a-field-list` (a table's readable fields that are neither a list of keys nor `EVERY_FIELD`), `hidden-field` (a field the reader may not read, or one worked out from such a field, named at its place in the map, never with a value) or `not-yet`.
|
|
45
51
|
|
|
46
52
|
## Statements
|
|
47
53
|
|
|
@@ -66,7 +72,7 @@ The one door. Guide: [the field map and the permission condition](../guides/fiel
|
|
|
66
72
|
- `RecordValues` — one record: its `key` as the database handed it back, and its `values`, each field asked by key.
|
|
67
73
|
- `VALUES_PAGE` — 1000: the keys one step of `valuesQuery` reads.
|
|
68
74
|
- `Page` — a page's `keys` in order, and `next`, the cursor the next page starts after, or null after the last.
|
|
69
|
-
- `KeysRequest` — a request: the app's map
|
|
75
|
+
- `KeysRequest` — a request: the app's map, its permission condition and the fields the reader may read (`readable`, required); the list's filter tree (relation rules and a value's parts included), its search (each word in some field it names, or the whole text a row's key), its quick-filter `hold` (fields' `ListHold`, on top of the filter: every statement keeps only rows that pass both, and a page's cursor is bound to it), and the context a date rule reads.
|
|
70
76
|
- `FilterContext` — what a rule reads beside its row: the reader's time zone and the moment relative days count from, which a date rule needs, and the reader's `region` (two letters), which a phone typed without its country code is read in; `since`, the instant a relation's `within` reads a rule's records from, never bound into a cursor; and `currencies`, the currency each field whose definition converts is read in, by key, bound into a page's cursor when it sorts, filters or groups by one.
|
|
71
77
|
|
|
72
78
|
## Counts and groups
|
package/views/README.md
CHANGED
|
@@ -10,7 +10,7 @@ The grid, its cells, the field display and the editors over typed fields: a head
|
|
|
10
10
|
pnpm add viewkitjs zod
|
|
11
11
|
```
|
|
12
12
|
|
|
13
|
-
ESM only. Node 20 or later. `viewkitjs/fields` ships in the same package. `zod` `^4.1.12` is a peer; `react` and `react-dom` 19 are optional peers that the views part needs, which a React app already has; `@dnd-kit/core`, `@dnd-kit/sortable` and `@dnd-kit/utilities` are optional ones, for the panels' parts that drag (the views row's pills, the sort's rules, the Columns list, the group order), which the door loads with `import()` as it loads: `/panels/react` itself loads without them.
|
|
13
|
+
ESM only. Node 20 or later. `viewkitjs/fields` ships in the same package. `zod` `^4.1.12` is a peer; `react` and `react-dom` 19 are optional peers that the views part needs, which a React app already has; `@dnd-kit/core`, `@dnd-kit/sortable` and `@dnd-kit/utilities` are optional ones, for the panels' parts that drag (the views row's pills, the sort's rules, the Columns list, the group order), which the door loads with `import()` as it loads: `/panels/react` itself loads without them. Import its stylesheet in one line (`@import "viewkitjs/views/styles.css";`), or let your own Tailwind compile it with one `@source` line: [docs/install.md](./docs/install.md).
|
|
14
14
|
|
|
15
15
|
## Getting started
|
|
16
16
|
|
|
@@ -86,10 +86,12 @@ References, one per door, each naming every export: [`viewkitjs/views`](./docs/r
|
|
|
86
86
|
| `viewkitjs/views/cells` | a column's typed cell, and its column-shaped string formatters |
|
|
87
87
|
| `viewkitjs/views/selection` | a list's selection: the model, the hook, the row checkbox, drag-select and the row-click rules |
|
|
88
88
|
| `viewkitjs/views/grid` | the grid: the table, its props, its preferences, and the helpers a host shares with it |
|
|
89
|
+
| `viewkitjs/views/looks` | a piece's options and looks, declared beside it, and the helpers that wear one; the grid's first; no React |
|
|
89
90
|
| `viewkitjs/views/panels` | what a list's panels read and say, built from its settings, and the toolbar's arrangement; no React |
|
|
90
91
|
| `viewkitjs/views/panels/react` | the panels as they draw, the toolbar's frame, its parts and the ready toolbar |
|
|
92
|
+
| `viewkitjs/views/styles.css`, `/styles.unlayered.css` | the rendering's look as one stylesheet, the Outright look by default, with no Tailwind needed ([install](./docs/install.md)) |
|
|
91
93
|
|
|
92
|
-
Twenty-
|
|
94
|
+
Twenty-four doors and two stylesheets; there are no other subpaths.
|
|
93
95
|
|
|
94
96
|
## For coding agents
|
|
95
97
|
|
|
@@ -3,5 +3,5 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
3
3
|
import { cx } from "../internal/cx.js";
|
|
4
4
|
import { STATUS_DOT, STATUS_TEXT } from "./tones.js";
|
|
5
5
|
export function DefaultStatusBadge({ slot, label, leading, title, size = "compact", className }) {
|
|
6
|
-
return (_jsxs("span", { "data-slot": "vk-status", "data-status": slot, title: title, className: cx("inline-flex min-w-0 items-center gap-1.5 font-medium", size === "compact" ? "text-[11px]" : "text-xs", STATUS_TEXT[slot], className), children: [leading ?? _jsx("span", { "aria-hidden": "true", className: cx("size-1.5 shrink-0 rounded-full", STATUS_DOT[slot]) }), _jsx("span", { className: "truncate", children: label })] }));
|
|
6
|
+
return (_jsxs("span", { "data-slot": "vk-status", "data-status": slot, title: title, className: cx("inline-flex min-w-0 items-center gap-1.5 font-medium", size === "compact" ? "text-[11px]" : size === "regular" && "text-xs", STATUS_TEXT[slot], className), children: [leading ?? _jsx("span", { "aria-hidden": "true", className: cx("size-1.5 shrink-0 rounded-full", STATUS_DOT[slot]) }), _jsx("span", { className: "truncate", children: label })] }));
|
|
7
7
|
}
|