@mistriwork/engine 1.0.0-rc.14 → 1.0.0-rc.16

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.
Files changed (60) hide show
  1. package/dist/adapters/cache/cacheStore.d.ts +1 -1
  2. package/dist/adapters/cache/cacheStore.js +1 -1
  3. package/dist/server/cli/startup.js +7 -2
  4. package/dist/server/cli/usage.d.ts +2 -0
  5. package/dist/server/cli/usage.js +12 -1
  6. package/dist/server/clientHttp.js +20 -3
  7. package/dist/server/config/profile.d.ts +10 -3
  8. package/dist/server/config/profile.js +28 -4
  9. package/dist/server/connections.js +1 -1
  10. package/dist/server/demo.js +3 -3
  11. package/dist/server/http/baselineHeaders.d.ts +13 -3
  12. package/dist/server/http/baselineHeaders.js +6 -0
  13. package/dist/server/http/frontDoor.d.ts +41 -0
  14. package/dist/server/http/frontDoor.js +36 -0
  15. package/dist/server/http/rateLimit.d.ts +2 -2
  16. package/dist/server/http/rateLimit.js +16 -2
  17. package/dist/server/http/recordCompose.d.ts +3 -0
  18. package/dist/server/http/recordCompose.js +1 -0
  19. package/dist/server/http/serverCore.d.ts +2 -2
  20. package/dist/server/http/serverCore.js +16 -32
  21. package/dist/server/migrate/cli.js +8 -1
  22. package/dist/server/migrate/desired.js +2 -2
  23. package/dist/server/migrate/target.d.ts +8 -0
  24. package/dist/server/migrate/target.js +15 -0
  25. package/dist/server/seed/seed.js +46 -11
  26. package/dist/server/startupWarnings.js +1 -1
  27. package/dist/shared/appCards.d.ts +4 -0
  28. package/dist/shared/appCards.js +5 -0
  29. package/dist/shared/breakdown.js +8 -2
  30. package/dist/shared/computed.d.ts +16 -2
  31. package/dist/shared/computed.js +23 -4
  32. package/dist/shared/computedValue.js +23 -0
  33. package/dist/shared/iconWeights.js +1 -0
  34. package/dist/shared/listPresentations.d.ts +9 -2
  35. package/dist/shared/listPresentations.js +2 -0
  36. package/dist/shared/listQuestion.d.ts +9 -0
  37. package/dist/shared/listQuestion.js +18 -0
  38. package/dist/shared/mentionLookup.js +3 -1
  39. package/dist/shared/page.d.ts +8 -1
  40. package/dist/shared/page.js +151 -7
  41. package/dist/shared/pageAnatomy.js +2 -0
  42. package/dist/shared/pageConfig.d.ts +1 -1
  43. package/dist/shared/pageConfig.js +106 -19
  44. package/dist/shared/pageModel.d.ts +62 -5
  45. package/dist/shared/pagePaths.js +4 -1
  46. package/dist/shared/pagePlans.d.ts +4 -2
  47. package/dist/shared/pagePlans.js +6 -4
  48. package/dist/shared/recordLabel.d.ts +12 -3
  49. package/dist/shared/recordLabel.js +39 -18
  50. package/dist/shared/recordReads.d.ts +6 -30
  51. package/dist/shared/recordReads.js +13 -1
  52. package/dist/shared/rollups.d.ts +4 -4
  53. package/dist/shared/rollups.js +1 -1
  54. package/dist/shared/schema.d.ts +7 -0
  55. package/dist/shared/schema.js +17 -0
  56. package/dist/shared/servedApp.d.ts +5 -1
  57. package/dist/shared/viewLabels.js +22 -17
  58. package/package.json +3 -2
  59. package/schema/model.d.ts +14 -5
  60. package/schema/theme.d.ts +1 -1
@@ -57,6 +57,8 @@ export interface PageFields {
57
57
  region?: SectionRegion;
58
58
  /** The tab of the record's section strip this section is drawn in; sections sharing a name share a panel. */
59
59
  tab?: string;
60
+ /** A mark drawn before the section's heading: one of the App's icons. */
61
+ icon?: import('./appIcons.js').AppIconName;
60
62
  title?: string;
61
63
  /** Paths relative to the root. Empty means "whatever the schema suggests". */
62
64
  paths?: string[];
@@ -84,6 +86,10 @@ export interface PageFields {
84
86
  `properties`: the record form's property rail — caption beside value, a hairline between rows, every
85
87
  field kept (an empty one is where a value is set) and editable in place where the record may change. */
86
88
  presentation?: 'summary' | 'headline' | 'facts' | 'table' | 'properties' | 'card' | 'header';
89
+ /** Authored `empty: 'hide' | 'show'` on a block of fields: the values the record does not have are left out ('hide') or
90
+ said as a dash ('show'). A property rail (the aside's default) hides them unless it says 'show'; a block with nothing
91
+ left to say is not drawn. A field the reader may fill in place stays, as the place to set it. */
92
+ emptyMode?: 'hide' | 'show';
87
93
  /** `fields`: each property is picked or typed in place; where the reader may not write the column, an action of theirs that sets it is offered as the picker. */
88
94
  edit?: true;
89
95
  /** `header`: the record's head as the author says it (a `header` section, DSL `header({ … })`), drawn in the head wherever it is
@@ -105,6 +111,8 @@ export interface PageFields {
105
111
  actions?: PageHeadlineAction[];
106
112
  /** A headline's second figure, under the first and smaller: an estimate, a unit price. */
107
113
  subfigure?: string;
114
+ /** A headline's line under its figure, read from a column of the record: an income's frequency. */
115
+ subtitle?: string;
108
116
  /** A headline's earlier value of its figure — a was-price — struck through beside it when it has one above the figure. */
109
117
  was?: string;
110
118
  /** A headline's line of small print under its actions: what the figures assume. */
@@ -150,6 +158,8 @@ export interface PageMetric {
150
158
  region?: SectionRegion;
151
159
  /** The tab of the record's section strip this section is drawn in; sections sharing a name share a panel. */
152
160
  tab?: string;
161
+ /** A mark drawn before the section's heading: one of the App's icons. */
162
+ icon?: import('./appIcons.js').AppIconName;
153
163
  title?: string;
154
164
  fn: 'count' | 'sum' | 'min' | 'max' | 'avg';
155
165
  /**
@@ -243,6 +253,8 @@ export interface PageList {
243
253
  The record itself is left out when `from` is the page's own table. Such a list has no `path` (it is ''):
244
254
  its rows are not the record's children. */
245
255
  similar?: PageSimilar;
256
+ /** A `current()` card's reference column whose record it opens in place of its own row (a link table's far side). */
257
+ opens?: string;
246
258
  /**
247
259
  * Written as `embed(view, { whose })`: the key of the App list view this
248
260
  * section draws, its rows narrowed to those pointing at the record. The
@@ -256,6 +268,8 @@ export interface PageList {
256
268
  region?: SectionRegion;
257
269
  /** The tab of the record's section strip this section is drawn in; sections sharing a name share a panel. */
258
270
  tab?: string;
271
+ /** A mark drawn before the section's heading: one of the App's icons. */
272
+ icon?: import('./appIcons.js').AppIconName;
259
273
  title?: string;
260
274
  from: string;
261
275
  path: string;
@@ -319,6 +333,8 @@ export interface PageBreakdown {
319
333
  region?: SectionRegion;
320
334
  /** The tab of the record's section strip this section is drawn in; sections sharing a name share a panel. */
321
335
  tab?: string;
336
+ /** A mark drawn before the section's heading: one of the App's icons. */
337
+ icon?: import('./appIcons.js').AppIconName;
322
338
  title?: string;
323
339
  from: string;
324
340
  path: string;
@@ -334,6 +350,8 @@ export interface PageBreakdown {
334
350
  filter?: string;
335
351
  /** Groups shown, biggest first. */
336
352
  limit?: number;
353
+ /** Authored `empty: 'hide'`: the section is left out while there is nothing to count, rather than drawn empty. */
354
+ emptyMode?: 'hide';
337
355
  /** How each figure is said, as a metric's: `percent` (0–100), `number` or `money`; and a word after it. */
338
356
  format?: FigureFormat;
339
357
  unit?: string;
@@ -357,6 +375,8 @@ export interface PageChart {
357
375
  region?: SectionRegion;
358
376
  /** The tab of the record's section strip this section is drawn in; sections sharing a name share a panel. */
359
377
  tab?: string;
378
+ /** A mark drawn before the section's heading: one of the App's icons. */
379
+ icon?: import('./appIcons.js').AppIconName;
360
380
  title?: string;
361
381
  from: string;
362
382
  path: string;
@@ -381,6 +401,12 @@ export interface PageChart {
381
401
  height?: number;
382
402
  /** A goal ruled across a line or stacked bars. */
383
403
  target?: number;
404
+ /** A line's curve, as on a dashboard chart: "smooth" draws a monotone curve through the points. */
405
+ curve?: 'smooth' | 'straight';
406
+ /** A donut's words for the figure in its middle ("Total visitors"), as on a dashboard chart. */
407
+ total?: string;
408
+ /** Authored `empty: 'hide'`: the section is left out while there is nothing to draw, rather than drawn empty. */
409
+ emptyMode?: 'hide';
384
410
  /** How each figure is said, as a metric's: `percent` (0–100), `number` or `money`; and a word after it. */
385
411
  format?: FigureFormat;
386
412
  unit?: string;
@@ -429,10 +455,10 @@ export interface TimelineStream {
429
455
  path: string;
430
456
  /** The date column the stream is ordered and merged by. */
431
457
  at: string;
432
- /** The line itself: a column of `from`, or a dotted path. */
433
- show: string;
434
- /** A quieter second word — a kind, an author. */
435
- detail?: string;
458
+ /** The row's text, its main value: a column of `from`, or a dotted path. It leads a row nobody wrote; in a message it sits under who, the badge and when. */
459
+ text: string;
460
+ /** The row's badge: a quieter word — a kind, a status. In a message it sits beside who and when, over the text; after the text in a row nobody wrote. */
461
+ badge?: string;
436
462
  /** Who wrote it: a column of `from`, or a dotted path — said beside its date. */
437
463
  by?: string;
438
464
  /** Extra narrowing, in the query language, resolved against `from`. */
@@ -457,9 +483,12 @@ export interface PageTimeline {
457
483
  region?: SectionRegion;
458
484
  /** The tab of the record's section strip this section is drawn in; sections sharing a name share a panel. */
459
485
  tab?: string;
486
+ /** A mark drawn before the section's heading: one of the App's icons. */
487
+ icon?: import('./appIcons.js').AppIconName;
460
488
  title?: string;
461
489
  streams: TimelineStream[];
462
- /** Per stream, before the merge. */
490
+ /** Per stream, before the merge: the rows drawn first. Where a stream has more, a "Show more" asks for another
491
+ `limit` of each, on demand. */
463
492
  limit?: number;
464
493
  /** A composer: adds a row of the first stream, bound to this record. */
465
494
  create?: RelatedCreate<string>;
@@ -476,6 +505,9 @@ export interface PageTimeline {
476
505
  `record.<column>` is the page's record — `author_id = record.caller_id`. A stream whose table lacks a column it
477
506
  names is never on the far side; a stream's own `side` replaces it (timelineSides, page.ts). */
478
507
  side?: string;
508
+ /** Reactions under each entry: the rows of `from` that name it, counted by kind, the reader's own pressed, and the
509
+ App's command run to give or take one back (timelineReactions, page.ts). */
510
+ reactions?: TimelineReactions;
479
511
  width?: SectionWidth;
480
512
  offsetLeft?: SectionOffset;
481
513
  offsetRight?: SectionOffset;
@@ -484,6 +516,23 @@ export interface PageTimeline {
484
516
  language: "status = converted". Judged against the base table. */
485
517
  when?: string;
486
518
  }
519
+ /**
520
+ * A timeline's reactions: rows of `from`, one per person per kind per entry. `whose` names the entry, `by` the person
521
+ * (read as `<by> = me`), `column` the kind; each is inferred where `from` has exactly one candidate and named
522
+ * otherwise (page.ts timelineReactions). `command` is the App's own, offered by an action of the entry's resource and
523
+ * handed the kind as its `<column>` input: it gives a reaction or takes it back, under the reader's grants.
524
+ */
525
+ export interface TimelineReactions {
526
+ from: string;
527
+ /** The kinds offered, in the order they are drawn; each a value of `column`, said through its display rule. */
528
+ kinds: string[];
529
+ command: string;
530
+ whose?: string;
531
+ by?: string;
532
+ column?: string;
533
+ /** The table people are rows of (an App's `auth.me`), set as the App loads: `by` is inferred among its references. */
534
+ person?: string;
535
+ }
487
536
  /** The tones a timeline row may be tinted: the display tones' words. */
488
537
  export type TimelineTone = 'good' | 'warn' | 'bad' | 'info' | 'neutral';
489
538
  /** The commands a conversation's composer runs: a Reply and, beside it, an Internal note. Each is offered to the reader by an action of the page's resource. */
@@ -539,6 +588,8 @@ interface PageHistory {
539
588
  region?: SectionRegion;
540
589
  /** The tab of the record's section strip this section is drawn in; sections sharing a name share a panel. */
541
590
  tab?: string;
591
+ /** A mark drawn before the section's heading: one of the App's icons. */
592
+ icon?: import('./appIcons.js').AppIconName;
542
593
  title?: string;
543
594
  /** Writes shown before "Show earlier changes", 1 to 100. Default 8. */
544
595
  limit?: number;
@@ -560,6 +611,8 @@ interface PageFlows {
560
611
  region?: SectionRegion;
561
612
  /** The tab of the record's section strip this section is drawn in; sections sharing a name share a panel. */
562
613
  tab?: string;
614
+ /** A mark drawn before the section's heading: one of the App's icons. */
615
+ icon?: import('./appIcons.js').AppIconName;
563
616
  title?: string;
564
617
  width?: SectionWidth;
565
618
  offsetLeft?: SectionOffset;
@@ -581,6 +634,8 @@ interface PageDiagram {
581
634
  region?: SectionRegion;
582
635
  /** The tab of the record's section strip this section is drawn in; sections sharing a name share a panel. */
583
636
  tab?: string;
637
+ /** A mark drawn before the section's heading: one of the App's icons. */
638
+ icon?: import('./appIcons.js').AppIconName;
584
639
  title?: string;
585
640
  width?: SectionWidth;
586
641
  offsetLeft?: SectionOffset;
@@ -603,6 +658,8 @@ export interface PageCustom {
603
658
  kind: 'custom';
604
659
  region?: SectionRegion;
605
660
  tab?: string;
661
+ /** A mark drawn before the section's heading: one of the App's icons. */
662
+ icon?: import('./appIcons.js').AppIconName;
606
663
  title?: string;
607
664
  component: import('./appComponents.js').ComponentDecl;
608
665
  /** The record's own fields the component reads, label paths welcome. */
@@ -3,7 +3,7 @@
3
3
  * root, the filter that pins it to one root row, and the list and metric
4
4
  * views a section runs. Pure; nothing fetches.
5
5
  */
6
- import { columnOrRollup, findTable, labelColumn, primaryKey } from './schema.js';
6
+ import { columnOrRollup, findTable, labelColumn, linkTarget, primaryKey, } from './schema.js';
7
7
  import { MAX_PATH_DEPTH, hopName, parseViewQuery, validateView } from './view.js';
8
8
  import { quoteValue, saidAt } from './query.js';
9
9
  import { DEFAULT_PAGE_LIST_LIMIT, GROUPS_DEFAULT } from './pageModel.js';
@@ -503,9 +503,12 @@ export function listView(schema, page, section, key, index, now, ofKeys, rootVal
503
503
  : [];
504
504
  /* A current card is titled by its row's name, which its facts leave out. */
505
505
  const titled = section.presentation === 'card' ? [labelColumn(table)].filter((name) => Boolean(name)) : [];
506
+ /* A card over a link table is named by, and opens, the record its far reference names: that column is read. */
507
+ const opened = section.presentation === 'card' ? [linkTarget(table, section.path, section.opens)].filter((name) => Boolean(name)) : [];
506
508
  const columns = [
507
509
  ...new Set([
508
510
  ...titled,
511
+ ...opened,
509
512
  ...(section.columns?.length ? section.columns : defaultColumns(table, section.path, resolved.path)),
510
513
  ...cardColumns,
511
514
  ...groupFactPaths(section),
@@ -21,11 +21,13 @@ type HttpPagePlan = {
21
21
  streams: Array<{
22
22
  from: string;
23
23
  at: string;
24
- show: string;
25
- detail?: string;
24
+ text: string;
25
+ badge?: string;
26
26
  by?: string;
27
27
  /** With a `side`: the stream's key columns, and the same read narrowed to the other party's rows. */
28
28
  key?: string[];
29
+ /** The column the section's reactions name this stream's rows by (page.ts reactedColumn), read with them. */
30
+ reacts?: string;
29
31
  side?: ReturnType<typeof listView>;
30
32
  } & ReturnType<typeof listView>>;
31
33
  } | {
@@ -1,5 +1,5 @@
1
1
  /** Section planning only: callers own page validation, root lookup and access. */
2
- import { breakdownPlan, chartPlan, customReadView, customTotalPlan, listView, metricView, sectionQuery, timelineMarkColumns, timelineSides, } from './page.js';
2
+ import { breakdownPlan, chartPlan, customReadView, customTotalPlan, listView, metricView, reactedColumn, sectionQuery, timelineMarkColumns, timelineSides, } from './page.js';
3
3
  import { groupsView, totalsView } from './pagePaths.js';
4
4
  import { sectionReading } from './pageModel.js';
5
5
  import { findTable, primaryKey } from './schema.js';
@@ -38,12 +38,13 @@ export function planPageSections(schema, page, key, ofKeys, now = new Date(), ro
38
38
  const side = sides[s];
39
39
  const table = side === undefined ? undefined : findTable(schema, stream.from);
40
40
  const keyColumns = table ? primaryKey(table) : [];
41
+ const reacts = reactedColumn(schema, section, stream);
41
42
  const asList = {
42
43
  kind: 'list',
43
44
  from: stream.from,
44
45
  path: stream.path,
45
46
  columns: [
46
- ...new Set([stream.at, stream.show, stream.detail, stream.by, ...streamMarks(stream), ...keyColumns].filter((c) => Boolean(c))),
47
+ ...new Set([stream.at, stream.text, stream.badge, stream.by, ...streamMarks(stream), ...keyColumns, reacts].filter((c) => Boolean(c))),
47
48
  ],
48
49
  filter: stream.filter,
49
50
  orderBy: [{ column: stream.at, direction: 'desc' }],
@@ -57,13 +58,14 @@ export function planPageSections(schema, page, key, ofKeys, now = new Date(), ro
57
58
  return {
58
59
  from: stream.from,
59
60
  at: stream.at,
60
- show: stream.show,
61
- detail: stream.detail,
61
+ text: stream.text,
62
+ badge: stream.badge,
62
63
  by: stream.by,
63
64
  view: built.view,
64
65
  empty: built.empty,
65
66
  error: built.error,
66
67
  ...(others ? { key: keyColumns, side: others } : {}),
68
+ ...(reacts ? { reacts } : {}),
67
69
  };
68
70
  }),
69
71
  };
@@ -16,15 +16,18 @@
16
16
  */
17
17
  /** The last segment that names a record's templated label. */
18
18
  export declare const LABEL_SEGMENT = "$label";
19
- type LabelPart = {
20
- text: string;
21
- } | {
19
+ export type LabelField = {
22
20
  path: string;
23
21
  mask?: {
24
22
  prefix?: string;
25
23
  };
26
24
  words?: Record<string, string>;
27
25
  };
26
+ type LabelPart = {
27
+ text: string;
28
+ } | (LabelField & {
29
+ or?: LabelField[];
30
+ });
28
31
  /** Whether an authored record label is a template rather than a path. */
29
32
  export declare const isLabelTemplate: (text: unknown) => text is string;
30
33
  /** The prefix a `$label` path hangs off ('' for the base's own), or undefined for any other path. */
@@ -36,10 +39,16 @@ export declare function parseLabelTemplate(template: string): {
36
39
  } | {
37
40
  problem: string;
38
41
  };
42
+ /** A template field's text, written back from its alternatives' own (a masked one marked, a worded one with its words). */
43
+ export declare const fieldText: (alternatives: readonly string[]) => string;
39
44
  /** A template field for a path whose stored values are said as words, as the server writes it into a served template. */
40
45
  export declare const wordedField: (path: string, words: Record<string, string>) => string;
46
+ /** The same inside a fallback chain, without its braces. */
47
+ export declare const wordedPath: (path: string, words: Record<string, string>) => string;
41
48
  /** A template field for a masked path, as the server writes it into a served template. */
42
49
  export declare const maskedField: (path: string, prefix?: string) => string;
50
+ /** The same inside a fallback chain, without its braces. */
51
+ export declare const maskedPath: (path: string, prefix?: string) => string;
43
52
  /** Whether an authored template writes a mask itself: that is the column's display rule's to say. */
44
53
  export declare const writesMask: (template: string) => boolean;
45
54
  /**
@@ -16,6 +16,8 @@
16
16
  */
17
17
  /** The last segment that names a record's templated label. */
18
18
  export const LABEL_SEGMENT = '$label';
19
+ /** The words between a field's alternatives. */
20
+ const FALLBACK = ' ?? ';
19
21
  const MASK_MARK = '|masked';
20
22
  /* Or its words: `{token|words:…}`, the column's display rule (`values`,
21
23
  `humanize`, a vocabulary's words) reaching the name the way it reaches a
@@ -58,23 +60,17 @@ export function parseLabelTemplate(template) {
58
60
  const end = rest.indexOf('}', open);
59
61
  if (end === -1)
60
62
  return { problem: `"${template}" opens a "{" it never closes.` };
61
- let field = rest.slice(open + 1, end);
62
- let words;
63
- const worded = field.indexOf(WORDS_MARK);
64
- if (worded !== -1) {
65
- words = readWords(field.slice(worded + WORDS_MARK.length));
66
- if (!words)
67
- return { problem: `"{${field}}" in "${template}" is not a column or a reference path, like {id} or {customer_id.name}.` };
68
- field = field.slice(0, worded);
63
+ const alternatives = rest.slice(open + 1, end).split(/\s\?\?\s/);
64
+ const fields = [];
65
+ for (const field of alternatives) {
66
+ const one = parseField(field, template);
67
+ if ('problem' in one)
68
+ return one;
69
+ fields.push(one);
70
+ paths.push(one.path);
69
71
  }
70
- const marked = field.indexOf(MASK_MARK);
71
- const path = (marked === -1 ? field : field.slice(0, marked)).trim();
72
- const after = marked === -1 ? undefined : field.slice(marked + MASK_MARK.length);
73
- if (!FIELD.test(path) || path.split('.').includes(LABEL_SEGMENT) || (after !== undefined && after !== '' && !after.startsWith(':'))) {
74
- return { problem: `"{${field}}" in "${template}" is not a column or a reference path, like {id} or {customer_id.name}.` };
75
- }
76
- parts.push({ path, ...(after === undefined ? {} : { mask: after ? { prefix: after.slice(1) } : {} }), ...(words ? { words } : {}) });
77
- paths.push(path);
72
+ const [first, ...others] = fields;
73
+ parts.push(others.length ? { ...first, or: others } : first);
78
74
  rest = rest.slice(end + 1);
79
75
  }
80
76
  if (!paths.length)
@@ -86,6 +82,27 @@ export function parseLabelTemplate(template) {
86
82
  }
87
83
  return { parts, paths };
88
84
  }
85
+ /* One field's path and the marks the server writes after it (mask, words), or why it is not one. */
86
+ function parseField(source, template) {
87
+ let field = source;
88
+ let words;
89
+ const worded = field.indexOf(WORDS_MARK);
90
+ if (worded !== -1) {
91
+ words = readWords(field.slice(worded + WORDS_MARK.length));
92
+ if (!words)
93
+ return { problem: `"{${field}}" in "${template}" is not a column or a reference path, like {id} or {customer_id.name}.` };
94
+ field = field.slice(0, worded);
95
+ }
96
+ const marked = field.indexOf(MASK_MARK);
97
+ const path = (marked === -1 ? field : field.slice(0, marked)).trim();
98
+ const after = marked === -1 ? undefined : field.slice(marked + MASK_MARK.length);
99
+ if (!FIELD.test(path) || path.split('.').includes(LABEL_SEGMENT) || (after !== undefined && after !== '' && !after.startsWith(':'))) {
100
+ return { problem: `"{${field}}" in "${template}" is not a column or a reference path, like {id} or {customer_id.name}.` };
101
+ }
102
+ return { path, ...(after === undefined ? {} : { mask: after ? { prefix: after.slice(1) } : {} }), ...(words ? { words } : {}) };
103
+ }
104
+ /** A template field's text, written back from its alternatives' own (a masked one marked, a worded one with its words). */
105
+ export const fieldText = (alternatives) => `{${alternatives.join(FALLBACK)}}`;
89
106
  /* A words map as a field carries it, or undefined when it is not one: every
90
107
  key and word a string every engine reads alike inside quotes. */
91
108
  function readWords(encoded) {
@@ -104,9 +121,13 @@ function readWords(encoded) {
104
121
  return Object.fromEntries(entries);
105
122
  }
106
123
  /** A template field for a path whose stored values are said as words, as the server writes it into a served template. */
107
- export const wordedField = (path, words) => `{${path}${WORDS_MARK}${encodeURIComponent(JSON.stringify(words))}}`;
124
+ export const wordedField = (path, words) => `{${wordedPath(path, words)}}`;
125
+ /** The same inside a fallback chain, without its braces. */
126
+ export const wordedPath = (path, words) => `${path}${WORDS_MARK}${encodeURIComponent(JSON.stringify(words))}`;
108
127
  /** A template field for a masked path, as the server writes it into a served template. */
109
- export const maskedField = (path, prefix) => `{${path}${MASK_MARK}${prefix ? `:${prefix}` : ''}}`;
128
+ export const maskedField = (path, prefix) => `{${maskedPath(path, prefix)}}`;
129
+ /** The same inside a fallback chain, without its braces. */
130
+ export const maskedPath = (path, prefix) => `${path}${MASK_MARK}${prefix ? `:${prefix}` : ''}`;
110
131
  /** Whether an authored template writes a mask itself: that is the column's display rule's to say. */
111
132
  export const writesMask = (template) => template.includes(MASK_MARK) || template.includes(WORDS_MARK);
112
133
  /**
@@ -1,32 +1,3 @@
1
- /**
2
- * What a record page reads, as the requests its sections send.
3
- *
4
- * A record page used to reach its reader in three waves of requests — the
5
- * root and the plan, then a request or two per section, then the history —
6
- * and at 20 ms to the database each wave was a round of admissions and
7
- * statements: a lender's loan finished at 0.9 s. The server now answers the
8
- * whole page in one request (server/http/recordCompose.ts, and the tenant
9
- * host's own): it plans the page, then asks each section's read on the
10
- * section's behalf, through the same route and the same grants as the
11
- * section's own request, and hands every answer back beside the plan. The
12
- * client keeps them for the requests they answer (client/composedReads.ts),
13
- * and a section that asks finds its answer waiting.
14
- *
15
- * So the one rule is that server and client build each request alike, and
16
- * the builders live here, used by both: the sections' own modules call them
17
- * for the request they send, and the server calls them to know what the
18
- * sections will ask. A request built differently is only asked again — the
19
- * section sends it, as it always did — so a drift costs a request, never a
20
- * wrong answer.
21
- *
22
- * The record's own row is the one read that is not asked alike: every fields
23
- * section, the header, the root probe and a custom section's record fields
24
- * read the one row, each for its columns, and which of them ask together
25
- * depends on what is drawn (a tab not yet opened asks nothing). The server
26
- * reads every column any of them names, once, and each is answered with
27
- * exactly its part (`rowPart`), as the client's own shared read already was
28
- * (pageFieldsRead.ts).
29
- */
30
1
  import { type DatabaseSchema, type TableMeta } from './schema.js';
31
2
  import { type PageSection } from './pageModel.js';
32
3
  import type { HttpBreakdownDefinition, HttpFilter } from './resourceHttp.js';
@@ -47,18 +18,23 @@ export interface RecordReadNames {
47
18
  readonly defined?: (tableId: string) => Readonly<Record<string, {
48
19
  per?: string;
49
20
  }>> | undefined;
21
+ /** A column's display rule (`resources.<r>.display`), where a shown column's `subtitle` is read with the record. */
22
+ readonly display?: (tableId: string, column: string) => {
23
+ subtitle?: string;
24
+ } | null | undefined;
50
25
  }
51
26
  /** The parts of a section its reads are built from (client pageModel.ts PageSection, shared page.ts). */
52
27
  export interface ReadSection {
53
28
  readonly kind: PageSection['kind'];
54
29
  readonly hidden?: boolean;
55
- readonly emptyMode?: 'hide' | 'collapse';
30
+ readonly emptyMode?: 'hide' | 'collapse' | 'show';
56
31
  /** A grouped related list reads its groups, then each group's rows (the rows wait on the groups). */
57
32
  readonly group?: unknown;
58
33
  readonly presentation?: unknown;
59
34
  readonly paths?: readonly string[];
60
35
  readonly status?: string;
61
36
  readonly subfigure?: string;
37
+ readonly subtitle?: string;
62
38
  readonly was?: string;
63
39
  readonly actions?: ReadonlyArray<{
64
40
  readonly prefill?: Readonly<Record<string, string>>;
@@ -27,6 +27,7 @@
27
27
  * exactly its part (`rowPart`), as the client's own shared read already was
28
28
  * (pageFieldsRead.ts).
29
29
  */
30
+ import { subtitlePath } from './subtitlePath.js';
30
31
  import { findTable, labelPath, primaryKey } from './schema.js';
31
32
  import { DEFAULT_HISTORY_LIMIT, kindReading } from './pageModel.js';
32
33
  import { assertNever } from './model.js';
@@ -82,6 +83,7 @@ export function fieldsColumns(names, base, section) {
82
83
  const extra = section.presentation === 'headline'
83
84
  ? [
84
85
  ...(section.subfigure ? [section.subfigure] : []),
86
+ ...(section.subtitle ? [section.subtitle] : []),
85
87
  ...(section.was ? [section.was] : []),
86
88
  ...(section.actions ?? []).flatMap((action) => [
87
89
  ...Object.values(action.prefill ?? {}),
@@ -89,7 +91,17 @@ export function fieldsColumns(names, base, section) {
89
91
  ]),
90
92
  ].filter((path) => !paths.includes(path))
91
93
  : [];
92
- const projection = referenceProjection(names.schema, base, [...paths, ...new Set(extra)], section.names !== false && names.app, (table) => namePathOf(names, table));
94
+ /* A column whose rule has a `subtitle` is drawn with it wherever it is a field, so the record reads it too
95
+ (the same rule a list's cell reads, listQuestion.ts subtitleColumns). */
96
+ const seconds = names.display
97
+ ? [...new Set([...paths, ...(section.presentation === 'headline' ? extra : [])])].flatMap((path) => {
98
+ const hop = path.lastIndexOf('.');
99
+ const owner = hop < 0 ? base.id : tableAtPrefix(names.schema, base.id, path.slice(0, hop))?.id;
100
+ const second = owner ? subtitlePath(names.display(owner, path.slice(hop + 1)), path) : undefined;
101
+ return second ? [second] : [];
102
+ })
103
+ : [];
104
+ const projection = referenceProjection(names.schema, base, [...new Set([...paths, ...extra, ...seconds])], section.names !== false && names.app, (table) => namePathOf(names, table));
93
105
  const fetched = projection.fetched;
94
106
  if (namePath && !fetched.includes(namePath))
95
107
  fetched.push(namePath);
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Rollups: one number about the rows that point at a record — an order's
3
3
  * line total, an account's open deals — declared once on the resource
4
- * (`rollups: { line_total: sum('order_line', 'amount') }`) and read wherever
4
+ * (`rollups: { line_total: rollup.sum('order_line', 'amount') }`) and read wherever
5
5
  * a column of the record is: a list's `show`, a sort, a tab's condition, a
6
6
  * record page's fields, a card's figure and facts, a queue's facts, a
7
7
  * picker's query, a dashboard's measure and a breakdown's key — and through
@@ -28,7 +28,7 @@
28
28
  import type { Filter } from './filter.js';
29
29
  import type { ComputedColumn } from './computed.js';
30
30
  import type { ColumnMeta } from './schema.js';
31
- export declare const ROLLUP_FNS: readonly ['count', 'sum', 'min', 'max', 'latest'];
31
+ export declare const ROLLUP_FNS: readonly ['count', 'sum', 'avg', 'min', 'max', 'latest'];
32
32
  export type RollupFn = (typeof ROLLUP_FNS)[number];
33
33
  /** A rollup as the catalog serves it and a view carries it: no request ever supplies one. */
34
34
  export interface Rollup {
@@ -99,13 +99,13 @@ export interface Rollup {
99
99
  type: string;
100
100
  /**
101
101
  * Set when `column` names a rollup of the child rather than one of its
102
- * columns — a customer's `lines: sum('sales_order', 'lines')`, the count
102
+ * columns — a customer's `lines: rollup.sum('sales_order', 'lines')`, the count
103
103
  * of its orders' lines, which is how a rollup reaches two hops. The inner
104
104
  * rollup is compiled inside the outer one's aggregate, each through its own
105
105
  * child's relation, so a row policy narrows both levels. One level only:
106
106
  * the inner one reads a column (appRollupRules says so when it does not).
107
107
  *
108
- * A rollup whose `whose` walks two references (`sum('time_entry', 'hours',
108
+ * A rollup whose `whose` walks two references (`rollup.sum('time_entry', 'hours',
109
109
  * { whose: 'task_id.project_id' })`) is served in the same shape: the outer
110
110
  * reads the middle table (`task.project_id`) with no column of its own,
111
111
  * the inner the rows and column declared, with the declared query. A count
@@ -1,4 +1,4 @@
1
- export const ROLLUP_FNS = ['count', 'sum', 'min', 'max', 'latest'];
1
+ export const ROLLUP_FNS = ['count', 'sum', 'avg', 'min', 'max', 'latest'];
2
2
  /** A rollup read as a column: never written, null only where there are no rows to read (a count is 0). */
3
3
  export function rollupColumnMeta(name, rollup) {
4
4
  return {
@@ -527,3 +527,10 @@ export declare function comparableType(type: string | undefined): boolean;
527
527
  * as a plain value of a comparable type: the write is then as blind as ever.
528
528
  */
529
529
  export declare function expectedValues(table: Pick<TableMeta, 'columns'>, values: Record<string, unknown>, row: Record<string, unknown> | undefined): Record<string, string | number | boolean | null> | undefined;
530
+ /**
531
+ * The reference a card over `table`'s row opens, where that row is a link (join) table's: the far side. The author's
532
+ * `opens` where they name one; otherwise, a table that is two references and nothing else of note (its key and
533
+ * dates aside) opens the one that `whose` — the reference back to the page's record — does not name. Any other table
534
+ * opens its own row, and gives none.
535
+ */
536
+ export declare function linkTarget(table: TableMeta, whose: string, opens?: string): string | undefined;
@@ -625,3 +625,20 @@ export function expectedValues(table, values, row) {
625
625
  }
626
626
  return Object.keys(expected).length ? expected : undefined;
627
627
  }
628
+ /**
629
+ * The reference a card over `table`'s row opens, where that row is a link (join) table's: the far side. The author's
630
+ * `opens` where they name one; otherwise, a table that is two references and nothing else of note (its key and
631
+ * dates aside) opens the one that `whose` — the reference back to the page's record — does not name. Any other table
632
+ * opens its own row, and gives none.
633
+ */
634
+ export function linkTarget(table, whose, opens) {
635
+ if (opens)
636
+ return opens;
637
+ if (whose.includes('.'))
638
+ return undefined;
639
+ const references = table.columns.filter((column) => column.references && column.references.table !== table.id);
640
+ if (references.length !== 2 || !references.some((column) => column.name === whose))
641
+ return undefined;
642
+ const plain = table.columns.every((column) => column.primaryKey || references.includes(column) || (column.type !== undefined && columnKind(column.type) === 'date'));
643
+ return plain ? references.find((column) => column.name !== whose)?.name : undefined;
644
+ }
@@ -244,7 +244,7 @@ export interface AppDisplayRule {
244
244
  links a column named like one (`email`, `phone`, `website`) without a rule. richText: the value is
245
245
  sanitized HTML (shared/richText.ts), drawn formatted on a record, as an excerpt in a list, edited in the
246
246
  rich text editor; every write of the column is sanitized on the server, and Markdown is read into it. */
247
- format?: 'money' | 'percent' | 'number' | 'relative' | 'date' | 'datetime' | 'items' | 'duration' | 'email' | 'phone' | 'url' | 'richText' | 'avatars' | 'rating' | 'color' | 'time' | 'month' | 'year' | 'json' | 'qr';
247
+ format?: 'money' | 'percent' | 'number' | 'relative' | 'date' | 'datetime' | 'items' | 'duration' | 'email' | 'phone' | 'url' | 'richText' | 'avatars' | 'rating' | 'color' | 'time' | 'month' | 'year' | 'json' | 'qr' | 'address';
248
248
  /** The face this column's values are set in, over the look's own: `data` (the look's data face, usually
249
249
  monospace), `sans` (the interface's reading face) or `code` (always monospace, for a VIN or a hash):
250
250
  `display: { vin: { face: 'code' } }`. Left out, an App sets a key, a reference, a code or a QR value in the
@@ -271,6 +271,8 @@ export interface AppDisplayRule {
271
271
  table: string;
272
272
  key: string;
273
273
  };
274
+ /** A copy button beside the value on a record: the stored value copied, a toast saying so. */
275
+ copy?: true;
274
276
  /** Value → one of the theme's chart colors, 1 to 8: a category's own color — a board card's chip and stripe, a
275
277
  chip in a cell — kept apart from `tone`, which says meaning. A value it does not name takes a color of its
276
278
  own, fixed by its words. */
@@ -416,6 +418,8 @@ export interface AppFormField<Field extends string = string> {
416
418
  as?: 'cards' | 'buttons' | 'radios' | 'select';
417
419
  /** The referenced table's column → this form's field whose value it must equal. */
418
420
  where?: Record<string, Field>;
421
+ /** The referenced table's column naming each record's parent: the picker draws the hierarchy it makes. */
422
+ tree?: string;
419
423
  }
420
424
  /** A resource's tags resolved against the catalog: the link table, its reference back to the record and out to the tag, and how a tag is named. */
421
425
  export interface AppTagRule extends Omit<AppTagsDef, 'toneOf'> {