viewkitjs 0.19.0 → 0.20.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +49 -0
- package/MIGRATION.md +116 -0
- package/README.md +7 -3
- package/fields/README.md +3 -3
- package/fields/dist/derived.d.ts +4 -0
- package/fields/dist/derived.js +39 -0
- package/fields/dist/entities.js +30 -30
- package/fields/dist/formula.js +2 -2
- package/fields/dist/query/evaluate.js +5 -5
- package/fields/dist/query/figures.js +5 -5
- package/fields/dist/query/filter.d.ts +15 -0
- package/fields/dist/query/filter.js +85 -0
- package/fields/dist/query/hold.js +2 -2
- package/fields/dist/query/option-counts.js +2 -2
- package/fields/dist/query/read-rule.js +2 -2
- package/fields/dist/query/search.js +2 -2
- package/fields/dist/query/set-aside.js +4 -4
- package/fields/dist/query/settings.d.ts +2 -15
- package/fields/dist/query/settings.js +3 -81
- package/fields/dist/query/sort.js +4 -4
- package/fields/dist/registry.d.ts +19 -5
- package/fields/dist/registry.js +371 -50
- package/fields/dist/types.d.ts +1 -1
- package/fields/docs/getting-started.md +2 -2
- package/fields/docs/guides/checking-definitions.md +17 -4
- package/fields/docs/guides/derived-fields.md +5 -5
- package/fields/docs/guides/queries.md +1 -1
- package/fields/docs/reference/design-category-colors.md +1 -1
- package/fields/docs/reference/design-status-slots.md +1 -1
- package/fields/docs/reference/fields.md +3 -3
- package/fields/docs/reference/query.md +1 -0
- package/fields/skills/viewkit/SKILL.md +2 -2
- package/package.json +13 -6
- package/postgres/README.md +2 -2
- package/postgres/dist/access.d.ts +12 -4
- package/postgres/dist/access.js +3 -0
- package/postgres/dist/calendar.js +3 -2
- package/postgres/dist/check.d.ts +6 -4
- package/postgres/dist/check.js +27 -16
- package/postgres/dist/counts.js +3 -2
- package/postgres/dist/definitions/build.js +7 -0
- package/postgres/dist/definitions/formula.d.ts +1 -1
- package/postgres/dist/definitions/formula.js +5 -3
- package/postgres/dist/definitions/lookup.js +5 -1
- package/postgres/dist/definitions/money.js +6 -1
- package/postgres/dist/definitions/place.d.ts +7 -0
- package/postgres/dist/definitions/place.js +8 -0
- package/postgres/dist/definitions/relations.js +36 -3
- package/postgres/dist/definitions/rollup.d.ts +1 -1
- package/postgres/dist/definitions/rollup.js +11 -6
- package/postgres/dist/field-values.js +11 -8
- package/postgres/dist/figures.js +4 -2
- package/postgres/dist/filled.js +2 -2
- package/postgres/dist/groups.d.ts +2 -1
- package/postgres/dist/groups.js +5 -3
- package/postgres/dist/index.d.ts +1 -0
- package/postgres/dist/index.js +1 -0
- package/postgres/dist/kept.js +8 -4
- package/postgres/dist/lanes.js +5 -3
- package/postgres/dist/phone.js +2 -2
- package/postgres/dist/predicates.js +2 -2
- package/postgres/dist/readable.d.ts +40 -0
- package/postgres/dist/readable.js +84 -0
- package/postgres/dist/records.js +7 -4
- package/postgres/dist/refusals.d.ts +8 -1
- package/postgres/dist/refusals.js +7 -0
- package/postgres/dist/relations.js +5 -4
- package/postgres/dist/search-indexes.js +2 -1
- package/postgres/dist/search.js +6 -4
- package/postgres/dist/several.js +8 -8
- package/postgres/dist/sort.d.ts +5 -3
- package/postgres/dist/sort.js +13 -8
- package/postgres/dist/value-rows.js +2 -2
- package/postgres/dist/values.js +4 -2
- package/postgres/docs/guides/definitions.md +2 -2
- package/postgres/docs/guides/field-map.md +43 -18
- package/postgres/docs/guides/test-kit.md +2 -0
- package/postgres/docs/reference/postgres.md +10 -4
- package/views/README.md +3 -2
- package/views/dist/styles.css +3165 -0
- package/views/dist/styles.unlayered.css +3164 -0
- package/views/docs/contract.md +13 -7
- package/views/docs/getting-started.md +1 -1
- package/views/docs/guides/the-grid.md +1 -1
- package/views/docs/install.md +35 -8
|
@@ -473,3 +473,88 @@ export function whereWaits(where) {
|
|
|
473
473
|
export function matchesTree(tree, read, opts = {}) {
|
|
474
474
|
return matchesNode(tree, typeof read === "function" ? { read } : read, opts) ?? true;
|
|
475
475
|
}
|
|
476
|
+
export const LIST_SETTINGS_LIMITS = {
|
|
477
|
+
sorts: 3,
|
|
478
|
+
filterDepth: FILTER_TREE_MAX_UI_DEPTH,
|
|
479
|
+
filterItems: 50,
|
|
480
|
+
columns: 200,
|
|
481
|
+
search: 200,
|
|
482
|
+
buckets: 500,
|
|
483
|
+
lanes: 500,
|
|
484
|
+
itemPositions: 5000,
|
|
485
|
+
groupFigures: 50,
|
|
486
|
+
key: 120,
|
|
487
|
+
part: 40,
|
|
488
|
+
};
|
|
489
|
+
const L = LIST_SETTINGS_LIMITS;
|
|
490
|
+
const FILTER_DEPTH_REASON = `a filter nests at most ${L.filterDepth} levels deep`;
|
|
491
|
+
const FILTER_ITEMS_REASON = `a filter group holds at most ${L.filterItems} items`;
|
|
492
|
+
const ruleKey = z.string().min(1).max(L.key);
|
|
493
|
+
const rulePart = z.string().min(1).max(L.part);
|
|
494
|
+
const ruleText = z.string().max(200);
|
|
495
|
+
const ruleFinite = z.number().finite();
|
|
496
|
+
const OPERATORS = [...new Set(Object.values(FILTER_OPERATORS).flat())];
|
|
497
|
+
const filterValue = z.union([
|
|
498
|
+
ruleText,
|
|
499
|
+
ruleFinite,
|
|
500
|
+
z.boolean(),
|
|
501
|
+
z.array(ruleText).max(100),
|
|
502
|
+
z.tuple([ruleFinite.nullable(), ruleFinite.nullable()]),
|
|
503
|
+
z.tuple([ruleText.nullable(), ruleText.nullable()]),
|
|
504
|
+
z.strictObject({
|
|
505
|
+
direction: z.enum(["past", "next", "this"]),
|
|
506
|
+
unit: z.enum(["day", "week", "month", "year"]),
|
|
507
|
+
}),
|
|
508
|
+
z.null(),
|
|
509
|
+
]);
|
|
510
|
+
const items = () => z.array(filterNode).max(L.filterItems, FILTER_ITEMS_REASON);
|
|
511
|
+
const ruleSetAside = z.strictObject({ reason: z.enum(SET_ASIDE_REASONS) }).optional();
|
|
512
|
+
const filterRule = z.strictObject({
|
|
513
|
+
fieldKey: ruleKey,
|
|
514
|
+
part: rulePart.optional(),
|
|
515
|
+
operator: z.enum(OPERATORS),
|
|
516
|
+
value: filterValue.optional().default(null),
|
|
517
|
+
setAside: ruleSetAside,
|
|
518
|
+
});
|
|
519
|
+
const filterNode = z.lazy(() => z.union([
|
|
520
|
+
z.strictObject({
|
|
521
|
+
fieldKey: ruleKey,
|
|
522
|
+
quantifier: z.enum(["any", "none", "every"]),
|
|
523
|
+
where: z.strictObject({ op: z.enum(["and", "or"]), items: items() }),
|
|
524
|
+
setAside: ruleSetAside,
|
|
525
|
+
}),
|
|
526
|
+
filterRule,
|
|
527
|
+
z.strictObject({ op: z.enum(["and", "or", "not"]), items: items() }),
|
|
528
|
+
]));
|
|
529
|
+
const filterTree = z.strictObject({ op: z.enum(["and", "or"]), items: items() });
|
|
530
|
+
function rawDepth(tree, limit) {
|
|
531
|
+
let deepest = 0;
|
|
532
|
+
const stack = [[tree, 1]];
|
|
533
|
+
while (stack.length > 0) {
|
|
534
|
+
const [node, depth] = stack.pop();
|
|
535
|
+
if (!node || typeof node !== "object")
|
|
536
|
+
continue;
|
|
537
|
+
deepest = Math.max(deepest, depth);
|
|
538
|
+
if (deepest > limit)
|
|
539
|
+
return deepest;
|
|
540
|
+
const children = node.items;
|
|
541
|
+
if (!Array.isArray(children))
|
|
542
|
+
continue;
|
|
543
|
+
for (const child of children) {
|
|
544
|
+
if (!child || typeof child !== "object")
|
|
545
|
+
continue;
|
|
546
|
+
if (Array.isArray(child.items))
|
|
547
|
+
stack.push([child, depth + 1]);
|
|
548
|
+
if ("where" in child)
|
|
549
|
+
stack.push([child.where, depth + 1]);
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
return deepest;
|
|
553
|
+
}
|
|
554
|
+
export const filterTreeSchema = z
|
|
555
|
+
.unknown()
|
|
556
|
+
.superRefine((value, ctx) => {
|
|
557
|
+
if (rawDepth(value, L.filterDepth) > L.filterDepth)
|
|
558
|
+
ctx.addIssue({ code: "custom", message: FILTER_DEPTH_REASON, fatal: true });
|
|
559
|
+
})
|
|
560
|
+
.pipe(filterTree);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
-
import { valueTypeOf } from "../derived.js";
|
|
2
|
+
import { knownField, valueTypeOf } from "../derived.js";
|
|
3
3
|
import { UNCATEGORIZED_KEY } from "./buckets.js";
|
|
4
4
|
export const LIST_HOLD_LIMITS = { fields: 50, values: 100, key: 120, value: 200 };
|
|
5
5
|
const H = LIST_HOLD_LIMITS;
|
|
@@ -33,7 +33,7 @@ export function heldInForce(hold, fieldOf) {
|
|
|
33
33
|
function inForce(hold, fieldOf) {
|
|
34
34
|
const out = [];
|
|
35
35
|
for (const held of hold) {
|
|
36
|
-
const field = fieldOf(held.fieldKey);
|
|
36
|
+
const field = knownField(fieldOf(held.fieldKey));
|
|
37
37
|
if (!field)
|
|
38
38
|
continue;
|
|
39
39
|
const type = valueTypeOf(field);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { DEFAULT_CONVENTIONS } from "../conventions.js";
|
|
2
2
|
import { actorKey } from "../actor.js";
|
|
3
|
-
import { presentedDef, scalarOf, valueTypeOf } from "../derived.js";
|
|
3
|
+
import { knownField, presentedDef, scalarOf, valueTypeOf } from "../derived.js";
|
|
4
4
|
import { optionValues } from "../options.js";
|
|
5
5
|
import { relationIdOf, relationKey } from "../relation.js";
|
|
6
6
|
import { UNCATEGORIZED_KEY } from "./buckets.js";
|
|
@@ -65,7 +65,7 @@ export function countHoldValues(rows, query, fieldKey, reader, opts = {}) {
|
|
|
65
65
|
return countUnder(rows, (filter) => withHold(filter, others, reader.fieldOf), query, fieldKey, reader, opts);
|
|
66
66
|
}
|
|
67
67
|
function countUnder(rows, narrow, query, fieldKey, reader, opts) {
|
|
68
|
-
const field = reader.fieldOf(fieldKey);
|
|
68
|
+
const field = knownField(reader.fieldOf(fieldKey));
|
|
69
69
|
if (!field)
|
|
70
70
|
return null;
|
|
71
71
|
const type = valueTypeOf(field);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { isPerCodeCurrency, scalarOf, valueTypeOf } from "../derived.js";
|
|
1
|
+
import { isPerCodeCurrency, knownField, scalarOf, valueTypeOf } from "../derived.js";
|
|
2
2
|
export function ruleReaderOf(row, reader) {
|
|
3
3
|
return (rule) => {
|
|
4
|
-
const field = reader.fieldOf(rule.fieldKey);
|
|
4
|
+
const field = knownField(reader.fieldOf(rule.fieldKey));
|
|
5
5
|
if (!field || isPerCodeCurrency(field))
|
|
6
6
|
return undefined;
|
|
7
7
|
return {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { actorLabel, isActorValue } from "../actor.js";
|
|
2
2
|
import { DEFAULT_CONVENTIONS } from "../conventions.js";
|
|
3
|
-
import { presentedDef, scalarOf, valueTypeOf } from "../derived.js";
|
|
3
|
+
import { knownField, presentedDef, scalarOf, valueTypeOf } from "../derived.js";
|
|
4
4
|
import { locationText } from "../location.js";
|
|
5
5
|
import { optionFor } from "../options.js";
|
|
6
6
|
import { matchesRule } from "./filter.js";
|
|
@@ -70,7 +70,7 @@ export function matchesSearch(row, search, reader, opts = {}) {
|
|
|
70
70
|
return true;
|
|
71
71
|
const cv = opts.conventions ?? DEFAULT_CONVENTIONS;
|
|
72
72
|
const fields = search.fields.flatMap((key) => {
|
|
73
|
-
const field = reader.fieldOf(key);
|
|
73
|
+
const field = knownField(reader.fieldOf(key));
|
|
74
74
|
return field ? [{ field, value: reader.read(row, key) }] : [];
|
|
75
75
|
});
|
|
76
76
|
return words.every((word) => fields.some(({ field, value }) => fieldHasWord(field, value, word, cv)));
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { valueTypeOf } from "../derived.js";
|
|
1
|
+
import { knownField, valueTypeOf } from "../derived.js";
|
|
2
2
|
import { filterPartsFor, isFilterGroup, isRelationRule, operatorsForField, } from "./filter.js";
|
|
3
3
|
import { groupOrdersFor } from "./group.js";
|
|
4
4
|
import { sortOrdersFor } from "./sort.js";
|
|
5
5
|
export function unfitReason(rule, fields) {
|
|
6
|
-
const field = fields.fieldOf(rule.fieldKey);
|
|
6
|
+
const field = knownField(fields.fieldOf(rule.fieldKey));
|
|
7
7
|
if (!field)
|
|
8
8
|
return "missing-field";
|
|
9
9
|
if (isRelationRule(rule))
|
|
@@ -13,7 +13,7 @@ export function unfitReason(rule, fields) {
|
|
|
13
13
|
return operatorsForField(field, rule.part).includes(rule.operator) ? null : "unfit-operator";
|
|
14
14
|
}
|
|
15
15
|
function unfitAxisReason(axis, fields, ordersOf) {
|
|
16
|
-
const field = fields.fieldOf(axis.fieldKey);
|
|
16
|
+
const field = knownField(fields.fieldOf(axis.fieldKey));
|
|
17
17
|
if (!field)
|
|
18
18
|
return "missing-field";
|
|
19
19
|
return axis.by !== undefined && !ordersOf(valueTypeOf(field)).includes(axis.by) ? "unfit-part" : null;
|
|
@@ -91,7 +91,7 @@ export function readListSettings(settings, fields) {
|
|
|
91
91
|
const board = settings.board;
|
|
92
92
|
const fieldKey = board?.fieldKey;
|
|
93
93
|
if (board && fieldKey !== undefined) {
|
|
94
|
-
const fits = !!fields.fieldOf(fieldKey);
|
|
94
|
+
const fits = !!knownField(fields.fieldOf(fieldKey));
|
|
95
95
|
if (board.setAside)
|
|
96
96
|
setAsideBoardField = { fieldKey, reason: board.setAside.reason, fits };
|
|
97
97
|
else if (!fits) {
|
|
@@ -2,7 +2,8 @@ import { z } from "zod";
|
|
|
2
2
|
import type { BoardLaneSpec } from "./board.js";
|
|
3
3
|
import type { ListDensity } from "./column-state.js";
|
|
4
4
|
import { type FigureKind, type ListGroupSummaryPart } from "./figure-kinds.js";
|
|
5
|
-
import { type FilterTree, type SetAside } from "./filter.js";
|
|
5
|
+
import { LIST_SETTINGS_LIMITS, type FilterTree, type SetAside } from "./filter.js";
|
|
6
|
+
export { LIST_SETTINGS_LIMITS };
|
|
6
7
|
import type { GroupSpec } from "./group.js";
|
|
7
8
|
import type { SortSpec } from "./sort.js";
|
|
8
9
|
export type ListLayout = "table" | "list" | "board" | "calendar";
|
|
@@ -58,19 +59,6 @@ export type ListSettings = {
|
|
|
58
59
|
endFieldKey?: string;
|
|
59
60
|
};
|
|
60
61
|
};
|
|
61
|
-
export declare const LIST_SETTINGS_LIMITS: {
|
|
62
|
-
readonly sorts: 3;
|
|
63
|
-
readonly filterDepth: 3;
|
|
64
|
-
readonly filterItems: 50;
|
|
65
|
-
readonly columns: 200;
|
|
66
|
-
readonly search: 200;
|
|
67
|
-
readonly buckets: 500;
|
|
68
|
-
readonly lanes: 500;
|
|
69
|
-
readonly itemPositions: 5000;
|
|
70
|
-
readonly groupFigures: 50;
|
|
71
|
-
readonly key: 120;
|
|
72
|
-
readonly part: 40;
|
|
73
|
-
};
|
|
74
62
|
/** The look's schema: a view's look, and a person's own over it. */
|
|
75
63
|
export declare const listLookSchema: z.ZodType<ListLook>;
|
|
76
64
|
/** The one schema of a list's settings, the same in the browser, on a server and from an agent. */
|
|
@@ -91,4 +79,3 @@ export declare const listSettingsChangeSchema: z.ZodType<ListSettingsChange>;
|
|
|
91
79
|
export declare const LIST_SETTINGS_DEFAULTS: ListSettings;
|
|
92
80
|
/** The settings a saved view keeps: all of them but the search. The value handed in is left as it is. */
|
|
93
81
|
export declare function settingsForSaving(settings: ListSettings): ListSettings;
|
|
94
|
-
export {};
|
|
@@ -1,91 +1,13 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import { FIGURE_KINDS, isGroupSummaryPart } from "./figure-kinds.js";
|
|
3
|
-
import { emptyTree,
|
|
4
|
-
export
|
|
5
|
-
sorts: 3,
|
|
6
|
-
filterDepth: FILTER_TREE_MAX_UI_DEPTH,
|
|
7
|
-
filterItems: 50,
|
|
8
|
-
columns: 200,
|
|
9
|
-
search: 200,
|
|
10
|
-
buckets: 500,
|
|
11
|
-
lanes: 500,
|
|
12
|
-
itemPositions: 5000,
|
|
13
|
-
groupFigures: 50,
|
|
14
|
-
key: 120,
|
|
15
|
-
part: 40,
|
|
16
|
-
};
|
|
3
|
+
import { emptyTree, filterTreeSchema, LIST_SETTINGS_LIMITS, SET_ASIDE_REASONS } from "./filter.js";
|
|
4
|
+
export { LIST_SETTINGS_LIMITS };
|
|
17
5
|
const L = LIST_SETTINGS_LIMITS;
|
|
18
|
-
const DEPTH_REASON = `a filter nests at most ${L.filterDepth} levels deep`;
|
|
19
|
-
const ITEMS_REASON = `a filter group holds at most ${L.filterItems} items`;
|
|
20
6
|
const key = z.string().min(1).max(L.key);
|
|
21
7
|
const part = z.string().min(1).max(L.part);
|
|
22
8
|
const text = z.string().max(200);
|
|
23
9
|
const finite = z.number().finite();
|
|
24
|
-
const OPERATORS = [...new Set(Object.values(FILTER_OPERATORS).flat())];
|
|
25
|
-
const filterValue = z.union([
|
|
26
|
-
text,
|
|
27
|
-
finite,
|
|
28
|
-
z.boolean(),
|
|
29
|
-
z.array(text).max(100),
|
|
30
|
-
z.tuple([finite.nullable(), finite.nullable()]),
|
|
31
|
-
z.tuple([text.nullable(), text.nullable()]),
|
|
32
|
-
z.strictObject({
|
|
33
|
-
direction: z.enum(["past", "next", "this"]),
|
|
34
|
-
unit: z.enum(["day", "week", "month", "year"]),
|
|
35
|
-
}),
|
|
36
|
-
z.null(),
|
|
37
|
-
]);
|
|
38
|
-
const items = () => z.array(filterNode).max(L.filterItems, ITEMS_REASON);
|
|
39
10
|
const setAside = z.strictObject({ reason: z.enum(SET_ASIDE_REASONS) }).optional();
|
|
40
|
-
const filterRule = z.strictObject({
|
|
41
|
-
fieldKey: key,
|
|
42
|
-
part: part.optional(),
|
|
43
|
-
operator: z.enum(OPERATORS),
|
|
44
|
-
value: filterValue.optional().default(null),
|
|
45
|
-
setAside,
|
|
46
|
-
});
|
|
47
|
-
const filterNode = z.lazy(() => z.union([
|
|
48
|
-
z.strictObject({
|
|
49
|
-
fieldKey: key,
|
|
50
|
-
quantifier: z.enum(["any", "none", "every"]),
|
|
51
|
-
where: z.strictObject({ op: z.enum(["and", "or"]), items: items() }),
|
|
52
|
-
setAside,
|
|
53
|
-
}),
|
|
54
|
-
filterRule,
|
|
55
|
-
z.strictObject({ op: z.enum(["and", "or", "not"]), items: items() }),
|
|
56
|
-
]));
|
|
57
|
-
const filterTree = z.strictObject({ op: z.enum(["and", "or"]), items: items() });
|
|
58
|
-
function rawDepth(tree, limit) {
|
|
59
|
-
let deepest = 0;
|
|
60
|
-
const stack = [[tree, 1]];
|
|
61
|
-
while (stack.length > 0) {
|
|
62
|
-
const [node, depth] = stack.pop();
|
|
63
|
-
if (!node || typeof node !== "object")
|
|
64
|
-
continue;
|
|
65
|
-
deepest = Math.max(deepest, depth);
|
|
66
|
-
if (deepest > limit)
|
|
67
|
-
return deepest;
|
|
68
|
-
const children = node.items;
|
|
69
|
-
if (!Array.isArray(children))
|
|
70
|
-
continue;
|
|
71
|
-
for (const child of children) {
|
|
72
|
-
if (!child || typeof child !== "object")
|
|
73
|
-
continue;
|
|
74
|
-
if (Array.isArray(child.items))
|
|
75
|
-
stack.push([child, depth + 1]);
|
|
76
|
-
if ("where" in child)
|
|
77
|
-
stack.push([child.where, depth + 1]);
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
return deepest;
|
|
81
|
-
}
|
|
82
|
-
const filterSchema = z
|
|
83
|
-
.unknown()
|
|
84
|
-
.superRefine((value, ctx) => {
|
|
85
|
-
if (rawDepth(value, L.filterDepth) > L.filterDepth)
|
|
86
|
-
ctx.addIssue({ code: "custom", message: DEPTH_REASON, fatal: true });
|
|
87
|
-
})
|
|
88
|
-
.pipe(filterTree);
|
|
89
11
|
const sortsSchema = z
|
|
90
12
|
.array(z.strictObject({ fieldKey: key, direction: z.enum(["asc", "desc"]), by: part.optional(), setAside }))
|
|
91
13
|
.max(L.sorts, `a view holds at most ${L.sorts} sorts`)
|
|
@@ -144,7 +66,7 @@ export const listLookSchema = z.strictObject({
|
|
|
144
66
|
const settingsObject = z.strictObject({
|
|
145
67
|
search: z.string().max(L.search).optional(),
|
|
146
68
|
layout: z.enum(["table", "list", "board", "calendar"]),
|
|
147
|
-
filter:
|
|
69
|
+
filter: filterTreeSchema,
|
|
148
70
|
sorts: sortsSchema,
|
|
149
71
|
rowOrderMode: z.enum(["fields", "manual"]).optional(),
|
|
150
72
|
itemPositions: z
|
|
@@ -2,7 +2,7 @@ import { DEFAULT_CONVENTIONS, conventionsOr } from "../conventions.js";
|
|
|
2
2
|
import { actorLabel, isActorValue } from "../actor.js";
|
|
3
3
|
import { isEmptyRange, isRangeValue, RANGE_PARTS } from "../range.js";
|
|
4
4
|
import { relationIdOf, relationKey } from "../relation.js";
|
|
5
|
-
import { isPerCodeCurrency, presentedDef, scalarOf, valueTypeOf } from "../derived.js";
|
|
5
|
+
import { isPerCodeCurrency, knownField, presentedDef, scalarOf, valueTypeOf } from "../derived.js";
|
|
6
6
|
import { isEmptyName, namePart, nameText } from "../name.js";
|
|
7
7
|
import { LOCATION_ORDERS, locationSortText } from "./location.js";
|
|
8
8
|
import { isOpenVocabulary, statusOptionOrder } from "../options.js";
|
|
@@ -194,7 +194,7 @@ export function comparatorFor(field, cv = DEFAULT_CONVENTIONS, by) {
|
|
|
194
194
|
}
|
|
195
195
|
function denominationReader(reader, key, code) {
|
|
196
196
|
const fixed = "fixed" in code ? code.fixed : undefined;
|
|
197
|
-
const sibling = "field" in code && reader.fieldOf(code.field) ? code.field : undefined;
|
|
197
|
+
const sibling = "field" in code && knownField(reader.fieldOf(code.field)) ? code.field : undefined;
|
|
198
198
|
return (row) => {
|
|
199
199
|
const declared = reader.codeOf?.(row, key);
|
|
200
200
|
if (declared != null && declared !== "")
|
|
@@ -210,7 +210,7 @@ function denominationReader(reader, key, code) {
|
|
|
210
210
|
function codeOrderFor(reader, code, cv) {
|
|
211
211
|
const order = textOrderOf(cv);
|
|
212
212
|
const byText = (a, b) => order(String(a), String(b));
|
|
213
|
-
const sibling = "field" in code ? reader.fieldOf(code.field) : undefined;
|
|
213
|
+
const sibling = "field" in code ? knownField(reader.fieldOf(code.field)) : undefined;
|
|
214
214
|
if (!sibling || sibling.type !== "select")
|
|
215
215
|
return byText;
|
|
216
216
|
const rank = new Map(sibling.options.map((o, i) => [o.value, i]));
|
|
@@ -223,7 +223,7 @@ function codeOrderFor(reader, code, cv) {
|
|
|
223
223
|
export function compareBy(sorts, reader, cv = DEFAULT_CONVENTIONS) {
|
|
224
224
|
const steps = sorts
|
|
225
225
|
.filter((s) => !s.setAside)
|
|
226
|
-
.map((s) => ({ spec: s, field: reader.fieldOf(s.fieldKey) }))
|
|
226
|
+
.map((s) => ({ spec: s, field: knownField(reader.fieldOf(s.fieldKey)) }))
|
|
227
227
|
.filter((s) => !!s.field)
|
|
228
228
|
.map(({ spec, field }) => {
|
|
229
229
|
const presented = presentedDef(field);
|
|
@@ -48,8 +48,8 @@ export declare function defineFields<const S extends FieldSpecMap>(input: {
|
|
|
48
48
|
* name is read. */
|
|
49
49
|
avatar?: keyof S & string;
|
|
50
50
|
fields: S;
|
|
51
|
-
/** `
|
|
52
|
-
*
|
|
51
|
+
/** `true` for a registry whose formulas may name a SQL function, which runs as the database. Default `false`, as
|
|
52
|
+
* `checkFieldSpec`'s. */
|
|
53
53
|
allowSql?: boolean;
|
|
54
54
|
}): DefinedFields<S>;
|
|
55
55
|
/** The entries of a line under a record's name, as a registry declares it or a host lays it on (`withLine`): each an
|
|
@@ -72,7 +72,8 @@ export declare function contributeFields<const S extends FieldSpecMap>(input: {
|
|
|
72
72
|
entity: FieldEntity;
|
|
73
73
|
from: string;
|
|
74
74
|
fields: S;
|
|
75
|
-
/** `
|
|
75
|
+
/** `true` for fields whose formulas may name a SQL function, which runs as the database. Default `false`, as
|
|
76
|
+
* `checkFieldSpec`'s. */
|
|
76
77
|
allowSql?: boolean;
|
|
77
78
|
}): DefinedContribution<S>;
|
|
78
79
|
/**
|
|
@@ -96,6 +97,9 @@ export declare function checkInverse(registries: Record<string, FieldSpecMap>):
|
|
|
96
97
|
* map is skipped: an owner that has not adopted the library yet is not an error.
|
|
97
98
|
*/
|
|
98
99
|
export declare function checkRegistries(registries: Record<string, FieldSpecMap>): void;
|
|
100
|
+
/** A definition's shape, in the order its refusals come: an object of plain data no deeper than the cap, then its
|
|
101
|
+
* closed words (the type first) in their own words, then the strict schema. What every rule after it may trust. */
|
|
102
|
+
export declare function checkShape(key: string, spec: unknown): asserts spec is FieldSpec;
|
|
99
103
|
/**
|
|
100
104
|
* One field's invariants — the same checks `defineFields()` runs per field,
|
|
101
105
|
* exported so a definition that arrives as DATA (a tenant's custom field,
|
|
@@ -108,7 +112,17 @@ export declare function checkRegistries(registries: Record<string, FieldSpecMap>
|
|
|
108
112
|
* be one amount per code. It is last and optional so every existing call — and
|
|
109
113
|
* every consumer's — still compiles.
|
|
110
114
|
*/
|
|
111
|
-
export declare function checkFieldSpec(key: string,
|
|
115
|
+
export declare function checkFieldSpec(key: string, spec: unknown, all?: FieldSpecMap, context?: {
|
|
112
116
|
inResult?: boolean;
|
|
113
117
|
allowSql?: boolean;
|
|
114
|
-
}):
|
|
118
|
+
}): asserts spec is FieldSpec;
|
|
119
|
+
/** The deepest a definition nests, objects and arrays counted: the deepest legal rule nests two levels per node
|
|
120
|
+
* (the node and its arguments), plus the field around it. Judged by one walk before any parse recurses. */
|
|
121
|
+
export declare const FIELD_SPEC_MAX_DEPTH: number;
|
|
122
|
+
/** A definition is an object, plain data no deeper than the cap. Run first, before any rule reads it. */
|
|
123
|
+
export declare function checkRawSpec(key: string, f: unknown): asserts f is object;
|
|
124
|
+
/** The strict schema alone, on a definition `checkRawSpec` already passed. */
|
|
125
|
+
export declare function checkStrictShape(key: string, f: object): asserts f is FieldSpec;
|
|
126
|
+
/** A definition's shape: an object, plain data no deeper than the cap, every key one its type declares and every
|
|
127
|
+
* value of its kind. Its closed words and its rules are `checkFieldSpec`'s. */
|
|
128
|
+
export declare function checkSpecShape(key: string, f: unknown): asserts f is FieldSpec;
|