@mistriwork/engine 1.0.0-rc.15 → 1.0.0-rc.17
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/README.md +5 -0
- package/dist/host.d.ts +46 -0
- package/dist/host.js +51 -0
- package/dist/server/cli/startup.js +7 -2
- package/dist/server/cli/usage.d.ts +2 -0
- package/dist/server/cli/usage.js +12 -1
- package/dist/server/clientHttp.js +20 -3
- package/dist/server/config/profile.d.ts +10 -3
- package/dist/server/config/profile.js +28 -4
- package/dist/server/connections.js +9 -0
- package/dist/server/http/baselineHeaders.d.ts +13 -3
- package/dist/server/http/baselineHeaders.js +6 -0
- package/dist/server/http/exportRoute.d.ts +74 -0
- package/dist/server/http/exportRoute.js +206 -169
- package/dist/server/http/frontDoor.d.ts +41 -0
- package/dist/server/http/frontDoor.js +36 -0
- package/dist/server/http/recordCompose.d.ts +3 -0
- package/dist/server/http/recordCompose.js +1 -0
- package/dist/server/http/reply.js +6 -0
- package/dist/server/http/serverCore.d.ts +2 -2
- package/dist/server/http/serverCore.js +16 -32
- package/dist/server/journal.d.ts +35 -6
- package/dist/server/journal.js +79 -8
- package/dist/server/journalStore.d.ts +37 -0
- package/dist/server/journalStore.js +352 -0
- package/dist/server/migrate/cli.js +8 -1
- package/dist/server/migrate/target.d.ts +8 -0
- package/dist/server/migrate/target.js +15 -0
- package/dist/server/seed/seed.js +46 -11
- package/dist/shared/appCards.d.ts +4 -0
- package/dist/shared/appCards.js +5 -0
- package/dist/shared/appListColumns.d.ts +7 -0
- package/dist/shared/appListColumns.js +13 -0
- package/dist/shared/breakdown.js +8 -2
- package/dist/shared/computed.d.ts +16 -2
- package/dist/shared/computed.js +23 -4
- package/dist/shared/computedValue.js +23 -0
- package/dist/shared/listQuestion.js +2 -2
- package/dist/shared/mentionLookup.js +3 -1
- package/dist/shared/page.js +23 -5
- package/dist/shared/pageAnatomy.js +2 -0
- package/dist/shared/pageConfig.d.ts +1 -1
- package/dist/shared/pageConfig.js +68 -18
- package/dist/shared/pageModel.d.ts +42 -5
- package/dist/shared/pagePaths.js +4 -1
- package/dist/shared/pagePlans.d.ts +2 -2
- package/dist/shared/pagePlans.js +3 -3
- package/dist/shared/recordLabel.d.ts +12 -3
- package/dist/shared/recordLabel.js +39 -18
- package/dist/shared/recordReads.d.ts +6 -30
- package/dist/shared/recordReads.js +32 -2
- package/dist/shared/rollups.d.ts +4 -4
- package/dist/shared/rollups.js +1 -1
- package/dist/shared/schema.d.ts +7 -0
- package/dist/shared/schema.js +17 -0
- package/dist/shared/servedApp.d.ts +1 -1
- package/dist/shared/viewLabels.js +22 -17
- package/package.json +5 -2
package/dist/shared/computed.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { noteRead } from './query.js';
|
|
2
|
-
export const COMPUTED_TYPES = ['boolean', 'number', 'date'];
|
|
2
|
+
export const COMPUTED_TYPES = ['boolean', 'number', 'date', 'text'];
|
|
3
3
|
/** What a computed column is to anything that reads columns: typed, never written, never a key. */
|
|
4
4
|
export function computedColumnMeta(name, computed) {
|
|
5
5
|
return {
|
|
@@ -43,9 +43,10 @@ export class ComputedError extends Error {
|
|
|
43
43
|
export function computedReads(node) {
|
|
44
44
|
const out = [];
|
|
45
45
|
const walk = (n) => {
|
|
46
|
-
if (n.k === 'path') {
|
|
47
|
-
|
|
48
|
-
|
|
46
|
+
if (n.k === 'path' || n.k === 'json') {
|
|
47
|
+
const path = n.k === 'path' ? n.path : n.column;
|
|
48
|
+
if (!out.includes(path))
|
|
49
|
+
out.push(path);
|
|
49
50
|
return;
|
|
50
51
|
}
|
|
51
52
|
if (n.k === 'op') {
|
|
@@ -78,6 +79,10 @@ export function computedKind(node, kindOf) {
|
|
|
78
79
|
}
|
|
79
80
|
case 'number':
|
|
80
81
|
return 'number';
|
|
82
|
+
case 'json':
|
|
83
|
+
if (!kindOf(n.column))
|
|
84
|
+
throw new Error(`"${n.column}" is not a column here.`);
|
|
85
|
+
return 'text';
|
|
81
86
|
case 'text':
|
|
82
87
|
case 'me':
|
|
83
88
|
case 'nobody':
|
|
@@ -257,6 +262,8 @@ export function compileComputed(computed, style, column, kindOf) {
|
|
|
257
262
|
switch (n.k) {
|
|
258
263
|
case 'path':
|
|
259
264
|
return column(n.path);
|
|
265
|
+
case 'json':
|
|
266
|
+
return jsonMember(column(n.column), n.keys, dialect);
|
|
260
267
|
case 'number':
|
|
261
268
|
return String(n.value);
|
|
262
269
|
case 'text':
|
|
@@ -350,6 +357,18 @@ export function compileComputed(computed, style, column, kindOf) {
|
|
|
350
357
|
}
|
|
351
358
|
return sql(computed.expr);
|
|
352
359
|
}
|
|
360
|
+
/**
|
|
361
|
+
* A JSON member as text, alike on both engines: PostgreSQL's `#>>` gives text, and a yes-or-no as `true`/`false`;
|
|
362
|
+
* SQLite's `json_extract` gives a number as a number and a yes-or-no as 1 or 0, so it is said as PostgreSQL says it.
|
|
363
|
+
* An object or an array is its JSON text on both. The keys are identifiers (ComputedJson), never quoted text.
|
|
364
|
+
*/
|
|
365
|
+
function jsonMember(column, keys, dialect) {
|
|
366
|
+
if (dialect === 'postgres')
|
|
367
|
+
return `(${column} #>> '{${keys.join(',')}}')`;
|
|
368
|
+
const at = `'$${keys.map((key) => `."${key}"`).join('')}'`;
|
|
369
|
+
return (`(CASE json_type(${column}, ${at}) WHEN 'true' THEN 'true' WHEN 'false' THEN 'false' ` +
|
|
370
|
+
`ELSE CAST(json_extract(${column}, ${at}) AS TEXT) END)`);
|
|
371
|
+
}
|
|
353
372
|
/** Whether an expression says the instant (`now`), so it comes to a moment rather than a day. */
|
|
354
373
|
export function readsNow(node) {
|
|
355
374
|
if (node.k === 'now' || node.k === 'instant')
|
|
@@ -120,6 +120,8 @@ export function evaluateComputed(node, values, read = (path) => {
|
|
|
120
120
|
const v = read(n.path);
|
|
121
121
|
return v === undefined || v === '' ? null : v;
|
|
122
122
|
}
|
|
123
|
+
case 'json':
|
|
124
|
+
return jsonMember(read(n.column), n.keys);
|
|
123
125
|
case 'op': {
|
|
124
126
|
if (n.op === 'and' || n.op === 'or') {
|
|
125
127
|
const l = truth(value(n.left)), r = truth(value(n.right));
|
|
@@ -168,6 +170,27 @@ export function evaluateComputed(node, values, read = (path) => {
|
|
|
168
170
|
const result = value(node);
|
|
169
171
|
return result === null && isCondition(node) ? false : result;
|
|
170
172
|
}
|
|
173
|
+
/* A JSON member as the statement reads it (computed.ts jsonMember): text, a yes-or-no as `true`/`false`, an object
|
|
174
|
+
or an array as its JSON. The column arrives as its text (SQLite) or already read (PostgreSQL's driver). */
|
|
175
|
+
function jsonMember(stored, keys) {
|
|
176
|
+
let at = stored;
|
|
177
|
+
if (typeof at === 'string') {
|
|
178
|
+
try {
|
|
179
|
+
at = JSON.parse(at);
|
|
180
|
+
}
|
|
181
|
+
catch {
|
|
182
|
+
return null;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
for (const key of keys) {
|
|
186
|
+
if (at === null || typeof at !== 'object' || Array.isArray(at) || !Object.hasOwn(at, key))
|
|
187
|
+
return null;
|
|
188
|
+
at = at[key];
|
|
189
|
+
}
|
|
190
|
+
if (at === null || at === undefined)
|
|
191
|
+
return null;
|
|
192
|
+
return typeof at === 'object' ? JSON.stringify(at) : String(at);
|
|
193
|
+
}
|
|
171
194
|
/**
|
|
172
195
|
* A constant expression's value, worked out where a fixed action's `set`
|
|
173
196
|
* writes it (appStamps on the server): `today + 14 days`, `now + 1 week`,
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
*/
|
|
14
14
|
import { andQuery } from './query.js';
|
|
15
15
|
import { splitQuery } from './clauses.js';
|
|
16
|
-
import { listPresentationColumns } from './appListColumns.js';
|
|
16
|
+
import { listPresentationColumns, listSecondLineColumns } from './appListColumns.js';
|
|
17
17
|
import { findTable, labelPath, primaryKey } from './schema.js';
|
|
18
18
|
import { referenceProjection } from './referenceModel.js';
|
|
19
19
|
import { tableAtPrefix } from './viewPaths.js';
|
|
@@ -109,7 +109,7 @@ export function showClause(rules, spec) {
|
|
|
109
109
|
...(naming ? [naming] : []),
|
|
110
110
|
...named,
|
|
111
111
|
...(spec.order ? [spec.order] : []),
|
|
112
|
-
...subtitleColumns(rules, spec.table, names),
|
|
112
|
+
...subtitleColumns(rules, spec.table, [...names, ...(spec.presentation ? listSecondLineColumns(spec.presentation) : [])]),
|
|
113
113
|
...editedReferences(rules, spec),
|
|
114
114
|
...(spec.opens ? [spec.opens] : []),
|
|
115
115
|
...(spec.group ? [spec.group] : []),
|
|
@@ -24,7 +24,9 @@ export function mentionLabelText(source, row) {
|
|
|
24
24
|
if ('problem' in parsed)
|
|
25
25
|
return '';
|
|
26
26
|
return parsed.parts
|
|
27
|
-
.map((part) =>
|
|
27
|
+
.map((part) => 'text' in part
|
|
28
|
+
? part.text
|
|
29
|
+
: ([part.path, ...(part.or ?? []).map((other) => other.path)].map((path) => said(row[path])).find(Boolean) ?? ''))
|
|
28
30
|
.join('')
|
|
29
31
|
.replace(/\s+/g, ' ')
|
|
30
32
|
.trim();
|
package/dist/shared/page.js
CHANGED
|
@@ -187,6 +187,12 @@ function validated(schema, page) {
|
|
|
187
187
|
error: `${at}: "was" is a number or money column beside the figure; "${section.was}" is ${was.resolved.column.type || 'untyped'}.`,
|
|
188
188
|
};
|
|
189
189
|
}
|
|
190
|
+
/* The line under the figure is read from the record, so it must name something there. */
|
|
191
|
+
if (section.subtitle !== undefined) {
|
|
192
|
+
const line = tryResolvePath(schema, page.base, section.subtitle);
|
|
193
|
+
if (!line.resolved)
|
|
194
|
+
return { ...page, error: `${at}: "subtitle" names "${section.subtitle}", ${line.error?.message ?? 'which does not resolve'}` };
|
|
195
|
+
}
|
|
190
196
|
if (section.status !== undefined && !columnOrRollup(base, section.status)) {
|
|
191
197
|
return { ...page, error: `${at}: the header's status "${section.status}" is not a column on ${base.name}.` };
|
|
192
198
|
}
|
|
@@ -229,7 +235,7 @@ function validated(schema, page) {
|
|
|
229
235
|
error: `${here}: "${stream.at}" is ${atCol.type || 'untyped'} — a timeline orders by a date column. See \`mistri docs dates-and-types\`.`,
|
|
230
236
|
};
|
|
231
237
|
}
|
|
232
|
-
for (const path of [stream.
|
|
238
|
+
for (const path of [stream.text, stream.badge, stream.by].filter((p) => Boolean(p))) {
|
|
233
239
|
/* A bare name is a column of `from`; a dotted path walks references
|
|
234
240
|
to a column of the table it reaches, and is judged the way a
|
|
235
241
|
list column is — `author_id.name`, not a chain of references. */
|
|
@@ -334,6 +340,11 @@ function validated(schema, page) {
|
|
|
334
340
|
const problem = relatedMatchProblem(schema, page, section);
|
|
335
341
|
if (problem)
|
|
336
342
|
return { ...page, error: `${at}: ${problem}` };
|
|
343
|
+
if (section.opens) {
|
|
344
|
+
const reference = table.columns.find((column) => column.name === section.opens)?.references;
|
|
345
|
+
if (!reference || !findTable(schema, reference.table))
|
|
346
|
+
return { ...page, error: `${at}: "opens" names "${section.opens}", which is not a reference column of ${table.name}.` };
|
|
347
|
+
}
|
|
337
348
|
}
|
|
338
349
|
if (section.kind === 'metric' && section.fn !== 'count' && !section.column) {
|
|
339
350
|
return { ...page, error: `${at}: "${section.fn}" needs a column to ${section.fn}.` };
|
|
@@ -799,6 +810,7 @@ function createConfig(create) {
|
|
|
799
810
|
export function sectionConfig(s) {
|
|
800
811
|
const common = {
|
|
801
812
|
...(s.title !== undefined ? { title: s.title } : {}),
|
|
813
|
+
...(s.icon ? { icon: s.icon } : {}),
|
|
802
814
|
...(s.region !== undefined ? { region: s.region } : {}),
|
|
803
815
|
...(s.tab !== undefined ? { tab: s.tab } : {}),
|
|
804
816
|
...(s.width && s.width !== 'full' ? { width: s.width } : {}),
|
|
@@ -843,6 +855,7 @@ export function sectionConfig(s) {
|
|
|
843
855
|
show: s.paths ?? [],
|
|
844
856
|
...(s.actions ? { links: s.actions.map((a) => ('view' in a ? (({ view, ...rest }) => ({ ...rest, to: view }))(a) : a)) } : {}),
|
|
845
857
|
...(s.subfigure !== undefined ? { subfigure: s.subfigure } : {}),
|
|
858
|
+
...(s.subtitle !== undefined ? { subtitle: s.subtitle } : {}),
|
|
846
859
|
...(s.was !== undefined ? { was: s.was } : {}),
|
|
847
860
|
...(s.note !== undefined ? { note: s.note } : {}),
|
|
848
861
|
};
|
|
@@ -854,6 +867,7 @@ export function sectionConfig(s) {
|
|
|
854
867
|
...(s.names === false ? { names: false } : {}),
|
|
855
868
|
...(s.presentation ? { presentation: s.presentation } : {}),
|
|
856
869
|
...(s.edit ? { editable: true } : {}),
|
|
870
|
+
...(s.emptyMode ? { empty: s.emptyMode } : {}),
|
|
857
871
|
};
|
|
858
872
|
case 'timeline':
|
|
859
873
|
return {
|
|
@@ -864,8 +878,8 @@ export function sectionConfig(s) {
|
|
|
864
878
|
from: stream.from,
|
|
865
879
|
whose: stream.path,
|
|
866
880
|
at: stream.at,
|
|
867
|
-
|
|
868
|
-
|
|
881
|
+
text: stream.text,
|
|
882
|
+
badge: stream.badge,
|
|
869
883
|
author: stream.by,
|
|
870
884
|
query: stream.filter,
|
|
871
885
|
...(stream.of ? { about: stream.of } : {}),
|
|
@@ -925,7 +939,8 @@ export function sectionConfig(s) {
|
|
|
925
939
|
whose: s.path,
|
|
926
940
|
show: s.labels ? s.columns?.map((column) => (s.labels[column] ? { column, label: s.labels[column] } : column)) : s.columns,
|
|
927
941
|
query: s.filter,
|
|
928
|
-
...(s.empty ? { empty: listEmptyConfig(s.empty) } : {}),
|
|
942
|
+
...(s.emptyMode === 'hide' ? { empty: 'hide' } : s.empty ? { empty: listEmptyConfig(s.empty) } : {}),
|
|
943
|
+
...(s.opens ? { opens: s.opens } : {}),
|
|
929
944
|
sort: s.orderBy?.map((o) => (o.direction === 'desc' ? `${o.column} desc` : o.column)).join(', '),
|
|
930
945
|
};
|
|
931
946
|
return {
|
|
@@ -975,6 +990,7 @@ export function sectionConfig(s) {
|
|
|
975
990
|
: { measure: [s.fn, s.column].filter(Boolean).join(' ') }),
|
|
976
991
|
query: s.filter,
|
|
977
992
|
limit: s.limit,
|
|
993
|
+
...(s.emptyMode ? { empty: s.emptyMode } : {}),
|
|
978
994
|
...(s.format !== undefined ? { format: s.format } : {}),
|
|
979
995
|
...(s.unit !== undefined ? { unit: s.unit } : {}),
|
|
980
996
|
};
|
|
@@ -998,6 +1014,9 @@ export function sectionConfig(s) {
|
|
|
998
1014
|
limit: s.limit,
|
|
999
1015
|
...(s.height !== undefined ? { height: s.height } : {}),
|
|
1000
1016
|
...(s.target !== undefined ? { target: s.target } : {}),
|
|
1017
|
+
...(s.curve ? { curve: s.curve } : {}),
|
|
1018
|
+
...(s.total ? { total: s.total } : {}),
|
|
1019
|
+
...(s.emptyMode ? { empty: s.emptyMode } : {}),
|
|
1001
1020
|
...(s.format !== undefined ? { format: s.format } : {}),
|
|
1002
1021
|
...(s.unit !== undefined ? { unit: s.unit } : {}),
|
|
1003
1022
|
};
|
|
@@ -1007,7 +1026,6 @@ export function sectionConfig(s) {
|
|
|
1007
1026
|
kind: s.kind,
|
|
1008
1027
|
text: s.text,
|
|
1009
1028
|
...(s.variant ? { variant: s.variant } : {}),
|
|
1010
|
-
...(s.icon ? { icon: s.icon } : {}),
|
|
1011
1029
|
...(s.action ? { action: 'view' in s.action ? { label: s.action.label, to: s.action.view } : s.action } : {}),
|
|
1012
1030
|
};
|
|
1013
1031
|
case 'custom':
|
|
@@ -358,6 +358,8 @@ export function withDefaultAside(schema, page) {
|
|
|
358
358
|
shown.add(section.status);
|
|
359
359
|
if (section.was)
|
|
360
360
|
shown.add(section.was.split('.')[0]);
|
|
361
|
+
if (section.subtitle)
|
|
362
|
+
shown.add(section.subtitle.split('.')[0]);
|
|
361
363
|
}
|
|
362
364
|
const name = labelColumn(base);
|
|
363
365
|
const paths = railOf(base.columns.filter((column) => readable(base, column) && column.name !== name && !shown.has(column.name)));
|
|
@@ -15,7 +15,7 @@ export declare const APP_PAGE_KEYS: ("aside" | "base" | "empty" | "layout" | "li
|
|
|
15
15
|
/** The keys each page section kind takes. Anything else is refused by name. A `segment` is read before the
|
|
16
16
|
section is (appSegments.ts unfoldSegments), as its word in `query`. */
|
|
17
17
|
export declare const PAGE_SECTION_KEYS: Record<PageSection['kind'] | 'view' | 'header' | 'current' | 'card' | 'headline', readonly string[]>;
|
|
18
|
-
export declare const STREAM_KEYS: readonly ['from', 'whose', 'at', '
|
|
18
|
+
export declare const STREAM_KEYS: readonly ['from', 'whose', 'at', 'text', 'badge', 'author', 'query', 'about', 'side', 'tone', 'compact'];
|
|
19
19
|
/**
|
|
20
20
|
* One page body: a tablewalk.json page, whose `id` is its own or derives
|
|
21
21
|
* from the name, or an App page, whose id is its key. The body is the same
|
|
@@ -9,7 +9,7 @@ import { parseRelatedCreate } from './relatedCreate.js';
|
|
|
9
9
|
import { parseListEmpty } from './listEmpty.js';
|
|
10
10
|
import { CHART_SHAPES, FIGURE_FORMATS, FIGURE_FORMAT_WORDS, allowKeys, humanName } from './model.js';
|
|
11
11
|
import { headingOf } from './appNoun.js';
|
|
12
|
-
import { CARDS_MAX_LINES, parseCards, parseFacts } from './appCards.js';
|
|
12
|
+
import { CARDS_MAX_LINES, HEADER_MAX_FACTS, parseCards, parseFacts } from './appCards.js';
|
|
13
13
|
import { parseIcon } from './appIcons.js';
|
|
14
14
|
import { slug } from './slug.js';
|
|
15
15
|
import { parsePageLayout } from './pageLayouts.js';
|
|
@@ -74,7 +74,7 @@ export const PAGE_KEYS = ['label', 'base', 'connection', 'listTabs', 'empty', 's
|
|
|
74
74
|
export const APP_PAGE_KEYS = PAGE_KEYS.filter((key) => key !== 'connection' && key !== 'label');
|
|
75
75
|
/* `aside` and `layout` are an App page's alone: the Workbench's pages draw what they say, in the record's one skeleton. */
|
|
76
76
|
const WORKBENCH_PAGE_KEYS = PAGE_KEYS.filter((key) => key !== 'aside' && key !== 'layout');
|
|
77
|
-
const SECTION_COMMON = ['kind', 'title', 'region', 'tab', 'width', 'offsetLeft', 'offsetRight', 'hidden', 'when'];
|
|
77
|
+
const SECTION_COMMON = ['kind', 'title', 'icon', 'region', 'tab', 'width', 'offsetLeft', 'offsetRight', 'hidden', 'when'];
|
|
78
78
|
/** A tab's name is a word or two across the strip, not a sentence. */
|
|
79
79
|
const MAX_TAB_NAME = 40;
|
|
80
80
|
/** The keys each page section kind takes. Anything else is refused by name. A `segment` is read before the
|
|
@@ -82,22 +82,22 @@ const MAX_TAB_NAME = 40;
|
|
|
82
82
|
/* `view` is an authored kind with no section of its own: `embed(view, { whose })`
|
|
83
83
|
is read into a related list that remembers the view (PageList.view). */
|
|
84
84
|
export const PAGE_SECTION_KEYS = {
|
|
85
|
-
fields: [...SECTION_COMMON, 'show', 'columns', 'names', 'presentation', 'editable'],
|
|
85
|
+
fields: [...SECTION_COMMON, 'show', 'columns', 'names', 'presentation', 'editable', 'empty'],
|
|
86
86
|
/* The record a reference names, in a box of its own: the first shown field is its title, the rest its facts. */
|
|
87
87
|
card: [...SECTION_COMMON, 'show'],
|
|
88
88
|
/* A figure with its facts, its earlier value, its estimate and the calls to action beside it. */
|
|
89
|
-
headline: [...SECTION_COMMON, 'show', 'links', 'subfigure', 'was', 'note'],
|
|
89
|
+
headline: [...SECTION_COMMON, 'show', 'links', 'subfigure', 'subtitle', 'was', 'note'],
|
|
90
90
|
/* The record's head: drawn where the head is, so nothing that would place it elsewhere. */
|
|
91
91
|
header: ['kind', 'status', 'facts', 'primary', 'destructive', 'actions'],
|
|
92
92
|
/* The one current related row as a card: nothing to page, sum or add under it. */
|
|
93
|
-
current: ['kind', 'title', 'region', 'tab', 'width', 'when', 'from', 'whose', 'show', 'query', 'sort', 'empty'],
|
|
93
|
+
current: ['kind', 'title', 'icon', 'region', 'tab', 'width', 'when', 'from', 'whose', 'show', 'query', 'sort', 'empty', 'opens'],
|
|
94
94
|
timeline: [...SECTION_COMMON, 'streams', 'limit', 'create', 'newest', 'composer', 'tone', 'compact', 'side', 'reactions'],
|
|
95
95
|
history: [...SECTION_COMMON, 'limit'],
|
|
96
96
|
flows: [...SECTION_COMMON],
|
|
97
97
|
diagram: [...SECTION_COMMON],
|
|
98
98
|
custom: [...SECTION_COMMON, 'component', 'record', 'rows', 'figures', 'props'],
|
|
99
99
|
metric: [...SECTION_COMMON, 'from', 'whose', 'about', 'measure', 'query', 'segment', 'format', 'unit'],
|
|
100
|
-
breakdown: [...SECTION_COMMON, 'from', 'whose', 'about', 'by', 'measure', 'query', 'segment', 'limit', 'format', 'unit'],
|
|
100
|
+
breakdown: [...SECTION_COMMON, 'from', 'whose', 'about', 'by', 'measure', 'query', 'segment', 'limit', 'format', 'unit', 'empty'],
|
|
101
101
|
chart: [
|
|
102
102
|
...SECTION_COMMON,
|
|
103
103
|
'from',
|
|
@@ -106,6 +106,8 @@ export const PAGE_SECTION_KEYS = {
|
|
|
106
106
|
'by',
|
|
107
107
|
'measure',
|
|
108
108
|
'shape',
|
|
109
|
+
'curve',
|
|
110
|
+
'total',
|
|
109
111
|
'sort',
|
|
110
112
|
'query',
|
|
111
113
|
'segment',
|
|
@@ -114,8 +116,9 @@ export const PAGE_SECTION_KEYS = {
|
|
|
114
116
|
'target',
|
|
115
117
|
'format',
|
|
116
118
|
'unit',
|
|
119
|
+
'empty',
|
|
117
120
|
],
|
|
118
|
-
note: [...SECTION_COMMON, 'text', '
|
|
121
|
+
note: [...SECTION_COMMON, 'text', 'action', 'variant'],
|
|
119
122
|
view: [...SECTION_COMMON, 'view', 'whose', 'about', 'limit'],
|
|
120
123
|
list: [
|
|
121
124
|
...SECTION_COMMON,
|
|
@@ -133,12 +136,13 @@ export const PAGE_SECTION_KEYS = {
|
|
|
133
136
|
'totals',
|
|
134
137
|
'same',
|
|
135
138
|
'near',
|
|
139
|
+
'opens',
|
|
136
140
|
'rowActions',
|
|
137
141
|
'actions',
|
|
138
142
|
'group',
|
|
139
143
|
],
|
|
140
144
|
};
|
|
141
|
-
export const STREAM_KEYS = ['from', 'whose', 'at', '
|
|
145
|
+
export const STREAM_KEYS = ['from', 'whose', 'at', 'text', 'badge', 'author', 'query', 'about', 'side', 'tone', 'compact'];
|
|
142
146
|
/**
|
|
143
147
|
* One page body: a tablewalk.json page, whose `id` is its own or derives
|
|
144
148
|
* from the name, or an App page, whose id is its key. The body is the same
|
|
@@ -366,6 +370,7 @@ function parseSection(entry, at, config) {
|
|
|
366
370
|
const placement = {
|
|
367
371
|
...(region === undefined ? {} : { region }),
|
|
368
372
|
...(tab === undefined ? {} : { tab }),
|
|
373
|
+
...(s.icon === undefined ? {} : { icon: parseIcon(s.icon, at) }),
|
|
369
374
|
};
|
|
370
375
|
if (s.create !== undefined && kind !== 'list' && kind !== 'timeline')
|
|
371
376
|
throw new Error(`${at}: create belongs on a related list or a timeline.`);
|
|
@@ -393,6 +398,7 @@ function parseSection(entry, at, config) {
|
|
|
393
398
|
? {
|
|
394
399
|
actions: `belongs on a headline(figure, { links }). ${retiredFieldsForms()}`,
|
|
395
400
|
subfigure: `belongs on a headline(figure, { subfigure }). ${retiredFieldsForms()}`,
|
|
401
|
+
subtitle: `belongs on a headline(figure, { subtitle }). ${retiredFieldsForms()}`,
|
|
396
402
|
was: `belongs on a headline(figure, { was }). ${retiredFieldsForms()}`,
|
|
397
403
|
note: `belongs on a headline(figure, { note }). ${retiredFieldsForms()}`,
|
|
398
404
|
}
|
|
@@ -418,12 +424,18 @@ function parseSection(entry, at, config) {
|
|
|
418
424
|
if (s.editable === true && s.presentation !== undefined && !['summary', 'properties'].includes(s.presentation)) {
|
|
419
425
|
throw new Error(`${at}: "editable" belongs on the fields a reader edits — a summary or a property rail; a ${String(s.presentation)} says values, it does not hold them.`);
|
|
420
426
|
}
|
|
427
|
+
if (s.empty !== undefined && s.empty !== 'hide' && s.empty !== 'show') {
|
|
428
|
+
throw new Error(`${at} has "empty": ${JSON.stringify(s.empty)}. A block of fields leaves out the values a record does not have ('hide') or says each as a dash ('show'); a property rail hides them unless it says 'show'.`);
|
|
429
|
+
}
|
|
421
430
|
if (s.was !== undefined && (typeof s.was !== 'string' || !FIELD_PATH.test(s.was.trim()))) {
|
|
422
431
|
throw new Error(`${at} has a "was" that is not a field name, like "was_price": the figure's earlier value.`);
|
|
423
432
|
}
|
|
424
433
|
if (s.subfigure !== undefined && (typeof s.subfigure !== 'string' || !FIELD_PATH.test(s.subfigure.trim()))) {
|
|
425
434
|
throw new Error(`${at} has a "subfigure" that is not a field name or a label path like "account_id.name".`);
|
|
426
435
|
}
|
|
436
|
+
if (s.subtitle !== undefined && (typeof s.subtitle !== 'string' || !FIELD_PATH.test(s.subtitle.trim()))) {
|
|
437
|
+
throw new Error(`${at} has a "subtitle" that is not a field name or a label path like "income_frequency": the line under the figure.`);
|
|
438
|
+
}
|
|
427
439
|
if (s.note !== undefined && (typeof s.note !== 'string' || !s.note.trim() || s.note.trim().length > 300)) {
|
|
428
440
|
throw new Error(`${at} has a "note" that is not text of at most 300 characters.`);
|
|
429
441
|
}
|
|
@@ -446,8 +458,10 @@ function parseSection(entry, at, config) {
|
|
|
446
458
|
names: s.names === false ? false : undefined,
|
|
447
459
|
...(s.presentation === undefined ? {} : { presentation: s.presentation }),
|
|
448
460
|
...(s.editable === true ? { edit: true } : {}),
|
|
461
|
+
...(s.empty === 'hide' || s.empty === 'show' ? { emptyMode: s.empty } : {}),
|
|
449
462
|
...(s.links === undefined ? {} : { actions: parseHeadlineActions(s.links, at) }),
|
|
450
463
|
...(s.subfigure === undefined ? {} : { subfigure: s.subfigure.trim() }),
|
|
464
|
+
...(s.subtitle === undefined ? {} : { subtitle: s.subtitle.trim() }),
|
|
451
465
|
...(s.was === undefined ? {} : { was: s.was.trim() }),
|
|
452
466
|
...(s.note === undefined ? {} : { note: s.note.trim() }),
|
|
453
467
|
};
|
|
@@ -467,6 +481,14 @@ function parseSection(entry, at, config) {
|
|
|
467
481
|
throw new Error(`${here} is not an object.`);
|
|
468
482
|
const t = raw;
|
|
469
483
|
refuseRenamed(t, here, ['path', 'tint']);
|
|
484
|
+
/* The parts as the row draws them. `show` and `detail` read the opposite of how they were drawn (the main value
|
|
485
|
+
leads, the badge sits beside who and when): they are refused with their new names, not read. */
|
|
486
|
+
for (const [was, now] of [
|
|
487
|
+
['show', 'text'],
|
|
488
|
+
['detail', 'badge'],
|
|
489
|
+
])
|
|
490
|
+
if (t[was] !== undefined)
|
|
491
|
+
throw new Error(`${here} has "${was}", which is now "${now}"${now === 'text' ? " — the row's main value" : ' — the quiet word beside who and when'}.`);
|
|
470
492
|
allowKeys(t, STREAM_KEYS, here);
|
|
471
493
|
const from = typeof t.from === 'string' ? t.from.trim() : '';
|
|
472
494
|
if (!from)
|
|
@@ -477,9 +499,9 @@ function parseSection(entry, at, config) {
|
|
|
477
499
|
const atCol = typeof t.at === 'string' ? t.at.trim() : '';
|
|
478
500
|
if (!atCol)
|
|
479
501
|
throw new Error(`${here} has no "at" — the date column the stream is ordered by.`);
|
|
480
|
-
const
|
|
481
|
-
if (!
|
|
482
|
-
throw new Error(`${here} has no "
|
|
502
|
+
const text = typeof t.text === 'string' ? t.text.trim() : '';
|
|
503
|
+
if (!text)
|
|
504
|
+
throw new Error(`${here} has no "text" — the line each row becomes.`);
|
|
483
505
|
/* `query` is the one spelling; the internal stream keeps its `filter`.
|
|
484
506
|
`author` says who wrote a row, where `by` groups one everywhere else;
|
|
485
507
|
the internal stream keeps its `by`. */
|
|
@@ -501,8 +523,8 @@ function parseSection(entry, at, config) {
|
|
|
501
523
|
from,
|
|
502
524
|
path,
|
|
503
525
|
at: atCol,
|
|
504
|
-
|
|
505
|
-
|
|
526
|
+
text,
|
|
527
|
+
badge: t.badge === undefined ? undefined : String(t.badge).trim() || undefined,
|
|
506
528
|
by: t.author === undefined ? undefined : String(t.author).trim() || undefined,
|
|
507
529
|
filter: filterRaw === undefined ? undefined : String(filterRaw).trim() || undefined,
|
|
508
530
|
...(typeof t.side === 'string' ? { side: t.side.trim() } : {}),
|
|
@@ -631,7 +653,6 @@ function parseSection(entry, at, config) {
|
|
|
631
653
|
...(when ? { when } : {}),
|
|
632
654
|
...(s.variant === undefined ? {} : { variant: s.variant }),
|
|
633
655
|
text: s.text.trim(),
|
|
634
|
-
...(s.icon === undefined ? {} : { icon: parseIcon(s.icon, at) }),
|
|
635
656
|
...(action ? { action } : {}),
|
|
636
657
|
};
|
|
637
658
|
}
|
|
@@ -681,7 +702,10 @@ function parseSection(entry, at, config) {
|
|
|
681
702
|
editable: 'is gone: the lines of a record are edited in its form (a form\'s "lines")',
|
|
682
703
|
order: 'is gone with the editable lines; a list sorts with "sort"',
|
|
683
704
|
}
|
|
684
|
-
: {
|
|
705
|
+
: {
|
|
706
|
+
subtitle: "is a second line under a record's own figure, read from a column of the record (headline(figure, { subtitle })); " +
|
|
707
|
+
'a measured figure has no record\'s column to read it from. Say it in the figure\'s "unit" or its title',
|
|
708
|
+
});
|
|
685
709
|
const from = typeof s.from === 'string' ? s.from.trim() : '';
|
|
686
710
|
if (!from)
|
|
687
711
|
throw new Error(`${at} has no "from" table.`);
|
|
@@ -768,6 +792,20 @@ function parseSection(entry, at, config) {
|
|
|
768
792
|
sort = parsed[0].direction === 'desc' ? `${parsed[0].column} desc` : parsed[0].column;
|
|
769
793
|
}
|
|
770
794
|
}
|
|
795
|
+
if (s.curve !== undefined) {
|
|
796
|
+
if (s.curve !== 'smooth' && s.curve !== 'straight')
|
|
797
|
+
throw new Error(`${at} has a "curve" of ${JSON.stringify(s.curve)}. Use "smooth" or "straight".`);
|
|
798
|
+
if (s.shape !== undefined && s.shape !== 'line')
|
|
799
|
+
throw new Error(`${at} is a ${String(s.shape)} chart; only a line has a "curve".`);
|
|
800
|
+
}
|
|
801
|
+
if (s.total !== undefined) {
|
|
802
|
+
if (s.shape !== 'donut')
|
|
803
|
+
throw new Error(`${at} has a "total", which names a donut's middle figure; it is not a donut.`);
|
|
804
|
+
if (typeof s.total !== 'string' || !s.total.trim() || s.total.trim().length > 40)
|
|
805
|
+
throw new Error(`${at} has a "total" that is not a few words (at most 40 characters): what the middle figure counts.`);
|
|
806
|
+
}
|
|
807
|
+
if (s.empty !== undefined && s.empty !== 'hide')
|
|
808
|
+
throw new Error(`${at} has "empty": ${JSON.stringify(s.empty)}. A chart takes 'hide', which leaves it out while it has nothing to draw.`);
|
|
771
809
|
const { fn, column } = parseMeasure(s.measure, at);
|
|
772
810
|
return {
|
|
773
811
|
kind: 'chart',
|
|
@@ -790,6 +828,9 @@ function parseSection(entry, at, config) {
|
|
|
790
828
|
...(s.limit === undefined ? {} : { limit: s.limit }),
|
|
791
829
|
...(s.height === undefined ? {} : { height: s.height }),
|
|
792
830
|
...(s.target === undefined ? {} : { target: s.target }),
|
|
831
|
+
...(s.curve === undefined ? {} : { curve: s.curve }),
|
|
832
|
+
...(s.total === undefined ? {} : { total: s.total.trim() }),
|
|
833
|
+
...(s.empty === 'hide' ? { emptyMode: 'hide' } : {}),
|
|
793
834
|
...figureWords,
|
|
794
835
|
};
|
|
795
836
|
}
|
|
@@ -801,6 +842,8 @@ function parseSection(entry, at, config) {
|
|
|
801
842
|
if (s.limit !== undefined && (typeof s.limit !== 'number' || !Number.isInteger(s.limit) || s.limit < 1)) {
|
|
802
843
|
throw new Error(`${at} has a "limit" that is not a positive whole number.`);
|
|
803
844
|
}
|
|
845
|
+
if (s.empty !== undefined && s.empty !== 'hide')
|
|
846
|
+
throw new Error(`${at} has "empty": ${JSON.stringify(s.empty)}. A breakdown takes 'hide', which leaves it out while it has nothing to count.`);
|
|
804
847
|
const measure = parseMeasure(s.measure, at);
|
|
805
848
|
return {
|
|
806
849
|
kind: 'breakdown',
|
|
@@ -821,6 +864,7 @@ function parseSection(entry, at, config) {
|
|
|
821
864
|
by,
|
|
822
865
|
filter,
|
|
823
866
|
limit: s.limit,
|
|
867
|
+
...(s.empty === 'hide' ? { emptyMode: 'hide' } : {}),
|
|
824
868
|
...figureWords,
|
|
825
869
|
};
|
|
826
870
|
}
|
|
@@ -840,8 +884,13 @@ function parseSection(entry, at, config) {
|
|
|
840
884
|
/* The one current row as a card — the active lease, the latest visit —
|
|
841
885
|
chosen by the list's query and sort: one row, so nothing to page, sum
|
|
842
886
|
or add under it. */
|
|
843
|
-
|
|
844
|
-
|
|
887
|
+
/* The reference a card over a link table opens, instead of the link row: judged against the catalog with the page. */
|
|
888
|
+
if (s.opens !== undefined && !current)
|
|
889
|
+
throw new Error(`${at} has "opens", which belongs on a current() card.`);
|
|
890
|
+
if (s.opens !== undefined && (typeof s.opens !== 'string' || !/^[A-Za-z_][A-Za-z0-9_]*$/.test(s.opens.trim())))
|
|
891
|
+
throw new Error(`${at} has an "opens" that is not a reference column of "${from}", e.g. "conversation_id".`);
|
|
892
|
+
if (current && (s.empty === false || s.empty === 'collapse'))
|
|
893
|
+
throw new Error(`${at} is a current() card; say what no row means with "empty" guidance, or leave it out while there is none with empty: 'hide'.`);
|
|
845
894
|
if (s.presentation !== undefined && s.presentation !== 'gallery' && !current) {
|
|
846
895
|
const raw = s.presentation;
|
|
847
896
|
if (!raw || typeof raw !== 'object' || Array.isArray(raw) || raw.kind !== 'cards') {
|
|
@@ -929,6 +978,7 @@ function parseSection(entry, at, config) {
|
|
|
929
978
|
...(shown?.labels ? { labels: shown.labels } : {}),
|
|
930
979
|
filter,
|
|
931
980
|
limit: s.presentation === 'card' ? 1 : s.limit,
|
|
981
|
+
...(typeof s.opens === 'string' ? { opens: s.opens.trim() } : {}),
|
|
932
982
|
orderBy: parseSort(s.sort, at),
|
|
933
983
|
...(s.create === undefined ? {} : s.create === false ? { noCreate: true } : { create: parseRelatedCreate(s.create, at) }),
|
|
934
984
|
...(s.empty === undefined || emptyMode ? {} : { empty: parseListEmpty(s.empty, at) }),
|
|
@@ -1047,7 +1097,7 @@ function parseHeader(s, at) {
|
|
|
1047
1097
|
if (['status', 'facts', 'primary', 'destructive', 'actions'].every((key) => s[key] === undefined)) {
|
|
1048
1098
|
throw new Error(`${at}: a record header says something: a "status", "facts", its "primary" verb, its "destructive" ones or the "actions" it draws.`);
|
|
1049
1099
|
}
|
|
1050
|
-
const facts = s.facts === undefined ? undefined : parseFacts(s.facts, `${at}, header
|
|
1100
|
+
const facts = s.facts === undefined ? undefined : parseFacts(s.facts, `${at}, header`, 'facts', HEADER_MAX_FACTS);
|
|
1051
1101
|
return {
|
|
1052
1102
|
kind: 'fields',
|
|
1053
1103
|
presentation: 'header',
|