@mistriwork/engine 1.0.0-rc.16 → 1.0.0-rc.18
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/adapters/adapter.d.ts +35 -2
- package/dist/adapters/adapter.js +32 -1
- package/dist/adapters/postgres.js +8 -4
- package/dist/adapters/scoped/scopedReads.js +23 -5
- package/dist/adapters/scoped/sqliteTriggers.js +65 -38
- package/dist/adapters/sqlite.js +8 -4
- package/dist/host.d.ts +46 -0
- package/dist/host.js +51 -0
- package/dist/server/columnGrants.d.ts +5 -0
- package/dist/server/connections.d.ts +1 -0
- package/dist/server/connections.js +20 -1
- package/dist/server/http/exportRoute.d.ts +74 -0
- package/dist/server/http/exportRoute.js +206 -169
- package/dist/server/http/firstPaint.d.ts +5 -1
- package/dist/server/http/firstPaint.js +4 -4
- package/dist/server/http/reply.js +6 -0
- package/dist/server/httpConnection.d.ts +4 -2
- package/dist/server/httpConnection.js +10 -3
- 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 +375 -0
- package/dist/server/resourceReadHttp.d.ts +4 -2
- package/dist/server/resourceReadHttp.js +40 -4
- package/dist/server/resourceReadOperations.d.ts +4 -0
- package/dist/server/scaffoldMachine.js +12 -1
- package/dist/shared/appListColumns.d.ts +7 -0
- package/dist/shared/appListColumns.js +13 -0
- package/dist/shared/boardLanes.d.ts +44 -0
- package/dist/shared/boardLanes.js +69 -0
- package/dist/shared/builtInThemes.js +26 -20
- package/dist/shared/dashboardAsks.d.ts +2 -0
- package/dist/shared/filter.d.ts +2 -0
- package/dist/shared/filter.js +3 -2
- package/dist/shared/form.d.ts +24 -1
- package/dist/shared/form.js +53 -0
- package/dist/shared/keysetPage.js +3 -0
- package/dist/shared/listInference.d.ts +91 -0
- package/dist/shared/listInference.js +323 -0
- package/dist/shared/listPresentations.d.ts +3 -0
- package/dist/shared/listQuestion.d.ts +2 -0
- package/dist/shared/listQuestion.js +3 -2
- package/dist/shared/pageAnatomy.d.ts +27 -3
- package/dist/shared/pageAnatomy.js +217 -36
- package/dist/shared/pageModel.d.ts +17 -1
- package/dist/shared/pageModel.js +8 -0
- package/dist/shared/query.d.ts +2 -0
- package/dist/shared/query.js +11 -3
- package/dist/shared/reads.d.ts +9 -0
- package/dist/shared/reads.js +9 -0
- package/dist/shared/recordLabel.d.ts +5 -0
- package/dist/shared/recordLabel.js +22 -2
- package/dist/shared/recordReads.d.ts +30 -0
- package/dist/shared/recordReads.js +101 -19
- package/dist/shared/referenceSubline.d.ts +18 -0
- package/dist/shared/referenceSubline.js +62 -0
- package/dist/shared/resourceHttp.d.ts +5 -0
- package/dist/shared/rowScope.js +52 -6
- package/dist/shared/schema.d.ts +2 -0
- package/dist/shared/servedApp.d.ts +19 -1
- package/dist/shared/servedApp.js +10 -0
- package/dist/shared/themeLooks.js +61 -35
- package/dist/shared/themeRecipeWords.d.ts +5 -0
- package/dist/shared/themeRecipeWords.js +6 -1
- package/dist/shared/themeRecipes.d.ts +5 -0
- package/dist/shared/themeRecipes.js +3 -0
- package/dist/shared/themeType.js +2 -1
- package/dist/shared/view.js +29 -2
- package/dist/shared/viewLabels.js +16 -0
- package/dist/shared/viewPaths.d.ts +9 -0
- package/package.json +6 -1
- package/schema/theme.d.ts +8 -4
|
@@ -9,16 +9,20 @@
|
|
|
9
9
|
* them a rail of the rest of its properties over its history. This says, for
|
|
10
10
|
* one table, which columns go where — name-like, status, money, date and
|
|
11
11
|
* count columns, and the rollups the catalog serves — so the default page and
|
|
12
|
-
* the scaffold's are one rule.
|
|
12
|
+
* the scaffold's are one rule. Two arrangements read it: the scaffold's page
|
|
13
|
+
* (`anatomySections`, what an author's `page()` can say) and the inferred page
|
|
14
|
+
* an App serves (`inferredSections`: a classic form, every related table as a
|
|
15
|
+
* counted tab, the references as cards).
|
|
13
16
|
*
|
|
14
17
|
* Pure: the caller says what only it knows (which columns are money in the
|
|
15
18
|
* App's words, whether the resource keeps a history, what a list is called).
|
|
16
19
|
*/
|
|
17
20
|
import { columnKind, findTable, labelColumn, primaryKey, referencesFrom, referencesTo, } from './schema.js';
|
|
18
21
|
import { pageHop } from './pagePaths.js';
|
|
22
|
+
import { referenceSubline } from './referenceSubline.js';
|
|
19
23
|
import { humanName } from './model.js';
|
|
20
24
|
import { headingOf, recordNoun } from './appNoun.js';
|
|
21
|
-
import { DEFAULT_PAGE_LIST_LIMIT } from './pageModel.js';
|
|
25
|
+
import { DEFAULT_PAGE_LIST_LIMIT, MAX_SECTIONS } from './pageModel.js';
|
|
22
26
|
const MONEY = /(^|_)(amount|total|subtotal|price|cost|revenue|budget|quota|fee|fees|salary|balance|value|pay|paid|wage|rent|charge|charges|billed|deposit|pipeline)$/i;
|
|
23
27
|
const STATE = /^(status|state|stage|phase)$|_(status|state|stage)$/i;
|
|
24
28
|
const COUNTED = /^(qty|quantity|units|seats|beds|baths|bedrooms|bathrooms|count|headcount|employees|capacity|size|sq_ft|sqft|area|mileage|minutes|hours)$|_(count|qty)$/i;
|
|
@@ -79,6 +83,23 @@ function dateColumns(table, taken) {
|
|
|
79
83
|
];
|
|
80
84
|
return [...new Set(ranked)];
|
|
81
85
|
}
|
|
86
|
+
/* A span's two ends, by their names: `starts_at` and `ends_at`, `start_date` and `end_date`, `shift_start` and
|
|
87
|
+
`shift_end`. */
|
|
88
|
+
const SPAN_START = /(^|_)(starts?|begins?)(_|$)/i;
|
|
89
|
+
/** The record's span: two dates named for its start and its end, read as one range ("Sep 13, 2:00 – 4:00 PM"). */
|
|
90
|
+
export function spanOf(table) {
|
|
91
|
+
const dated = table.columns.filter((column) => columnKind(column.type ?? '') === 'date' && !column.primaryKey);
|
|
92
|
+
for (const start of dated) {
|
|
93
|
+
if (!SPAN_START.test(start.name))
|
|
94
|
+
continue;
|
|
95
|
+
for (const word of ['ends', 'end']) {
|
|
96
|
+
const name = start.name.replace(SPAN_START, (_, before, _word, after) => `${before}${word}${after}`);
|
|
97
|
+
if (name !== start.name && dated.some((column) => column.name === name))
|
|
98
|
+
return { start: start.name, end: name };
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
return undefined;
|
|
102
|
+
}
|
|
82
103
|
/** A related list's columns: the row's name, its state, then what it says, never the reference it is found by. */
|
|
83
104
|
function listColumns(child, fk, hints) {
|
|
84
105
|
const name = hints.label?.(child) ?? labelColumn(child);
|
|
@@ -109,8 +130,45 @@ function railOf(rest) {
|
|
|
109
130
|
.map((column) => column.name)
|
|
110
131
|
.slice(0, MAX_PROPERTIES);
|
|
111
132
|
}
|
|
112
|
-
/**
|
|
113
|
-
|
|
133
|
+
/**
|
|
134
|
+
* A reference as a card in the aside: the reference and two of its record's own fields, its state first, or nothing
|
|
135
|
+
* where its record has fewer than two things to say (a patient's insurer is a name alone; their provider has a
|
|
136
|
+
* specialty and a phone).
|
|
137
|
+
*/
|
|
138
|
+
function referenceCard(schema, up, hints, noun) {
|
|
139
|
+
const column = up.from.columns[0];
|
|
140
|
+
const upTable = findTable(schema, up.to.table);
|
|
141
|
+
const base = findTable(schema, up.from.table);
|
|
142
|
+
if (!upTable)
|
|
143
|
+
return undefined;
|
|
144
|
+
const upName = hints.label?.(upTable) ?? labelColumn(upTable);
|
|
145
|
+
const upState = statusColumn(upTable, hints);
|
|
146
|
+
/* What tells this record from another of its name (referenceSubline.ts): its code, its email, the day it was made —
|
|
147
|
+
read on the card beside the name, after its state, where two Ana Silvas would otherwise be one card twice. */
|
|
148
|
+
const told = referenceSubline(schema, upTable, upName, upName ? { [upName]: { subtitle: hints.subtitle?.(upTable, upName) } } : undefined);
|
|
149
|
+
const telling = told && !told.path.includes('.') ? upTable.columns.find((c) => c.name === told.path) : undefined;
|
|
150
|
+
const tells = telling && telling !== upState && readable(upTable, telling) && !LONG_OR_KEY(telling) ? telling : undefined;
|
|
151
|
+
const glance = [
|
|
152
|
+
...(upState ? [upState] : []),
|
|
153
|
+
...(tells ? [tells] : []),
|
|
154
|
+
...upTable.columns.filter((c) => c !== upState &&
|
|
155
|
+
c !== tells &&
|
|
156
|
+
readable(upTable, c) &&
|
|
157
|
+
c.name !== upName &&
|
|
158
|
+
!LONG_OR_KEY(c) &&
|
|
159
|
+
!HOUSEKEEPING.test(c.name) &&
|
|
160
|
+
!c.flag),
|
|
161
|
+
].slice(0, 2);
|
|
162
|
+
if (glance.length < 2)
|
|
163
|
+
return undefined;
|
|
164
|
+
return {
|
|
165
|
+
title: headingOf((base && hints.caption?.(base, column)) || humanName(column.replace(/_id$/i, '')) || noun(upTable)),
|
|
166
|
+
paths: [column, ...glance.map((c) => `${column}.${c.name}`)],
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
/** Which of a table's columns go where on its record's page, or nothing where a record has no key to open it by. At
|
|
170
|
+
most `lists` related lists: four on a scaffold's page, every one on the inferred page's tab strip. */
|
|
171
|
+
export function recordAnatomy(schema, baseId, hints = {}, lists = MAX_RELATED) {
|
|
114
172
|
const base = findTable(schema, baseId);
|
|
115
173
|
if (!base || !primaryKey(base).length)
|
|
116
174
|
return null;
|
|
@@ -131,11 +189,14 @@ export function recordAnatomy(schema, baseId, hints = {}) {
|
|
|
131
189
|
const figures = own.filter((column) => columnKind(column.type ?? '') === 'number' && !column.primaryKey && !refColumns.includes(column.name));
|
|
132
190
|
const moneyColumns = figures.filter((column) => money(base, column)).map((column) => column.name);
|
|
133
191
|
const counted = figures.filter((column) => COUNTED.test(column.name)).map((column) => column.name);
|
|
134
|
-
/* The header says what the record belongs to, what it is worth and when
|
|
192
|
+
/* The header says what the record belongs to, what it is worth and when: a span from its start to its end, said
|
|
193
|
+
once, where it has both (a visit's 2:00 – 4:00 PM), never its end alone. */
|
|
194
|
+
const span = spanOf(base);
|
|
195
|
+
const shownSpan = span && own.some((column) => column.name === span.start) && own.some((column) => column.name === span.end);
|
|
135
196
|
const facts = [
|
|
136
197
|
...take(refColumns[0]),
|
|
137
198
|
...take(moneyColumns[0]),
|
|
138
|
-
...take(dateColumns(base, taken).map((column) => column.name)[0]),
|
|
199
|
+
...take(shownSpan ? span.start : dateColumns(base, taken).map((column) => column.name)[0]),
|
|
139
200
|
...take(counted[0]),
|
|
140
201
|
...take(refColumns[1]),
|
|
141
202
|
].slice(0, MAX_FACTS);
|
|
@@ -164,7 +225,7 @@ export function recordAnatomy(schema, baseId, hints = {}) {
|
|
|
164
225
|
pageHop(schema, fk) !== undefined &&
|
|
165
226
|
findTable(schema, fk.from.table) &&
|
|
166
227
|
(hints.includes?.(findTable(schema, fk.from.table)) ?? true));
|
|
167
|
-
const related = incoming.slice(0,
|
|
228
|
+
const related = incoming.slice(0, lists).map((fk) => {
|
|
168
229
|
const child = findTable(schema, fk.from.table);
|
|
169
230
|
const ambiguous = incoming.filter((other) => other.from.table === fk.from.table).length > 1 || child.id === base.id;
|
|
170
231
|
const title = hints.title?.(fk, child, ambiguous) ?? (ambiguous ? `${child.name} via ${fk.from.columns.join(', ')}` : undefined);
|
|
@@ -184,22 +245,10 @@ export function recordAnatomy(schema, baseId, hints = {}) {
|
|
|
184
245
|
let parent;
|
|
185
246
|
const required = (column) => base.columns.find((c) => c.name === column)?.nullable === false;
|
|
186
247
|
for (const column of related.length ? [...refColumns].sort((a, b) => Number(required(b)) - Number(required(a))) : []) {
|
|
187
|
-
const
|
|
188
|
-
|
|
189
|
-
if (!upTable)
|
|
190
|
-
continue;
|
|
191
|
-
const upName = hints.label?.(upTable) ?? labelColumn(upTable);
|
|
192
|
-
const upState = statusColumn(upTable, hints);
|
|
193
|
-
const glance = [
|
|
194
|
-
...(upState ? [upState] : []),
|
|
195
|
-
...upTable.columns.filter((c) => c !== upState && readable(upTable, c) && c.name !== upName && !LONG_OR_KEY(c) && !HOUSEKEEPING.test(c.name) && !c.flag),
|
|
196
|
-
].slice(0, 2);
|
|
197
|
-
if (glance.length < 2)
|
|
248
|
+
const card = referenceCard(schema, refs.find((fk) => fk.from.columns[0] === column), hints, noun);
|
|
249
|
+
if (!card)
|
|
198
250
|
continue;
|
|
199
|
-
parent =
|
|
200
|
-
title: headingOf(humanName(column.replace(/_id$/i, '')) || noun(upTable)),
|
|
201
|
-
paths: [column, ...glance.map((c) => `${column}.${c.name}`)],
|
|
202
|
-
};
|
|
251
|
+
parent = card;
|
|
203
252
|
// Said on its card, the reference is not said again in the rail.
|
|
204
253
|
taken.add(column);
|
|
205
254
|
break;
|
|
@@ -246,6 +295,7 @@ export function recordAnatomy(schema, baseId, hints = {}) {
|
|
|
246
295
|
return {
|
|
247
296
|
...(status ? { status } : {}),
|
|
248
297
|
facts,
|
|
298
|
+
...(shownSpan && facts.includes(span.start) ? { spans: { [span.start]: span.end } } : {}),
|
|
249
299
|
summary,
|
|
250
300
|
related,
|
|
251
301
|
...(parent ? { parent } : {}),
|
|
@@ -263,17 +313,7 @@ export function anatomySections(anatomy) {
|
|
|
263
313
|
}
|
|
264
314
|
if (anatomy.summary.length)
|
|
265
315
|
sections.push({ kind: 'fields', presentation: 'summary', paths: anatomy.summary });
|
|
266
|
-
|
|
267
|
-
sections.push({
|
|
268
|
-
kind: 'list',
|
|
269
|
-
...(list.title ? { title: list.title } : {}),
|
|
270
|
-
from: list.from,
|
|
271
|
-
path: list.whose,
|
|
272
|
-
columns: list.show,
|
|
273
|
-
limit: DEFAULT_PAGE_LIST_LIMIT,
|
|
274
|
-
...(list.sort ? { orderBy: [{ column: list.sort.split(' ')[0], direction: 'desc' }] } : {}),
|
|
275
|
-
});
|
|
276
|
-
}
|
|
316
|
+
sections.push(...anatomy.related.map(listSection));
|
|
277
317
|
/* With no children to list, the fields are the page, not a rail beside nothing. */
|
|
278
318
|
const aside = anatomy.related.length > 0;
|
|
279
319
|
if (anatomy.parent)
|
|
@@ -311,17 +351,158 @@ export function anatomySections(anatomy) {
|
|
|
311
351
|
sections.unshift({ kind: 'fields', presentation: 'header', paths: [] });
|
|
312
352
|
return sections;
|
|
313
353
|
}
|
|
354
|
+
/** A related list as a page section: its first page, newest first where it has a date to sort by. */
|
|
355
|
+
function listSection(list) {
|
|
356
|
+
return {
|
|
357
|
+
kind: 'list',
|
|
358
|
+
...(list.title ? { title: list.title } : {}),
|
|
359
|
+
from: list.from,
|
|
360
|
+
path: list.whose,
|
|
361
|
+
columns: list.show,
|
|
362
|
+
limit: DEFAULT_PAGE_LIST_LIMIT,
|
|
363
|
+
...(list.sort ? { orderBy: [{ column: list.sort.split(' ')[0], direction: 'desc' }] } : {}),
|
|
364
|
+
};
|
|
365
|
+
}
|
|
366
|
+
/** Text a reader reads rather than scans, and the stamps a database keeps, go last in a group of fields. */
|
|
367
|
+
const lateness = (path) => (LONG_TEXT.test(path) ? 2 : HOUSEKEEPING.test(path) ? 1 : 0);
|
|
368
|
+
/**
|
|
369
|
+
* The page an App draws for a record it declared none for: the head, a classic form, the related tables as tabs and
|
|
370
|
+
* the references beside them (docs/design.md, "The inferred record"). Coding agents leave a record page undeclared
|
|
371
|
+
* or thin, so this is the page most records are read on, and it must not read as a dump of columns.
|
|
372
|
+
*
|
|
373
|
+
* - The head: the name, its column's second line, the status, and at most four facts — the anatomy's (what it belongs
|
|
374
|
+
* to, what it is worth, when, how many, its second reference), then the record's rollups while under four, then its
|
|
375
|
+
* figures and short words while under three. A fact may be a field too: the head is the glance, the form is where
|
|
376
|
+
* a value is read whole and set.
|
|
377
|
+
* - The form: a fields section per group the App's form declares, after an untitled one of what no group holds; one
|
|
378
|
+
* untitled section where it declares none, so no heading repeats the record's kind. In the form's order, then the
|
|
379
|
+
* schema's; stamps, then long text, last. Not the name, not a status a machine moves (its verbs move it, the head
|
|
380
|
+
* says it), not a reference its card already says.
|
|
381
|
+
* - Every table that points here and that the reader's catalog holds, one tab each in foreign-key order, then the
|
|
382
|
+
* history where the App keeps one; one strip, counted (recordReads.ts, relatedCountsBody).
|
|
383
|
+
* - Beside them, a card for each reference whose record has two things to say (three at most), then the current child.
|
|
384
|
+
*
|
|
385
|
+
* Every choice is made from the catalog and the App's declarations, never from a row: a page that changed shape when
|
|
386
|
+
* its row arrived would move under the reader.
|
|
387
|
+
*/
|
|
388
|
+
function inferredSections(schema, base, hints = {}) {
|
|
389
|
+
const anatomy = recordAnatomy(schema, base.id, hints, Number.POSITIVE_INFINITY);
|
|
390
|
+
if (!anatomy)
|
|
391
|
+
return null;
|
|
392
|
+
const name = hints.label?.(base) ?? labelColumn(base);
|
|
393
|
+
const own = base.columns.filter((column) => readable(base, column) && column.name !== name);
|
|
394
|
+
const noun = (table) => hints.noun?.(table) ?? recordNoun(undefined, table.name);
|
|
395
|
+
const refs = referencesFrom(schema, base.id).filter((fk) => fk.from.columns.length === 1 && !fk.stitched && own.some((column) => column.name === fk.from.columns[0]));
|
|
396
|
+
const refColumns = new Set(refs.map((fk) => fk.from.columns[0]));
|
|
397
|
+
const required = (fk) => base.columns.find((column) => column.name === fk.from.columns[0])?.nullable === false;
|
|
398
|
+
const cards = [...refs]
|
|
399
|
+
.sort((a, b) => Number(required(b)) - Number(required(a)))
|
|
400
|
+
.flatMap((fk) => referenceCard(schema, fk, hints, noun) ?? [])
|
|
401
|
+
.slice(0, 3);
|
|
402
|
+
const status = anatomy.status;
|
|
403
|
+
const facts = [...anatomy.facts];
|
|
404
|
+
const said = new Set([...facts, ...(status ? [status] : [])]);
|
|
405
|
+
const say = (column) => {
|
|
406
|
+
if (said.has(column))
|
|
407
|
+
return;
|
|
408
|
+
said.add(column);
|
|
409
|
+
facts.push(column);
|
|
410
|
+
};
|
|
411
|
+
const rollups = Object.keys(base.rollups ?? {});
|
|
412
|
+
for (const rollup of rollups)
|
|
413
|
+
if (facts.length < MAX_FACTS)
|
|
414
|
+
say(rollup);
|
|
415
|
+
const plain = own.filter((column) => !column.primaryKey && !refColumns.has(column.name) && !LONG_OR_KEY(column) && !HOUSEKEEPING.test(column.name) && !column.flag);
|
|
416
|
+
for (const kind of ['number', 'text'])
|
|
417
|
+
for (const column of plain)
|
|
418
|
+
if (facts.length < 3 && columnKind(column.type ?? '') === kind)
|
|
419
|
+
say(column.name);
|
|
420
|
+
/* The form: what the record holds that the head and the cards do not already say whole. */
|
|
421
|
+
const left = new Set([...(status && hints.moved?.(base, status) ? [status] : []), ...cards.map((card) => card.paths[0])]);
|
|
422
|
+
const held = new Set([...own.map((column) => column.name).filter((column) => !left.has(column)), ...rollups.filter((r) => !said.has(r))]);
|
|
423
|
+
const declared = hints.groups?.(base) ?? [];
|
|
424
|
+
const inTitled = new Set(declared.flatMap((group) => (group.label ? group.fields : [])));
|
|
425
|
+
const placed = new Set();
|
|
426
|
+
const group = (paths) => {
|
|
427
|
+
const mine = [];
|
|
428
|
+
for (const path of paths) {
|
|
429
|
+
if (!held.has(path) || placed.has(path))
|
|
430
|
+
continue;
|
|
431
|
+
placed.add(path);
|
|
432
|
+
mine.push(path);
|
|
433
|
+
}
|
|
434
|
+
return mine.sort((a, b) => lateness(a) - lateness(b));
|
|
435
|
+
};
|
|
436
|
+
const untitled = group([
|
|
437
|
+
...declared.flatMap((each) => (each.label ? [] : each.fields)),
|
|
438
|
+
...[...held].filter((path) => !inTitled.has(path)),
|
|
439
|
+
]);
|
|
440
|
+
const groups = [
|
|
441
|
+
{ paths: untitled },
|
|
442
|
+
...declared.flatMap((each) => (each.label ? [{ title: each.label, paths: group(each.fields) }] : [])),
|
|
443
|
+
].filter((each) => each.paths.length);
|
|
444
|
+
const subtitle = name ? hints.subtitle?.(base, name) : undefined;
|
|
445
|
+
const sections = [
|
|
446
|
+
{
|
|
447
|
+
kind: 'fields',
|
|
448
|
+
presentation: 'header',
|
|
449
|
+
paths: facts,
|
|
450
|
+
...(status ? { status } : {}),
|
|
451
|
+
...(subtitle ? { subtitle } : {}),
|
|
452
|
+
...(anatomy.spans ? { spans: anatomy.spans } : {}),
|
|
453
|
+
},
|
|
454
|
+
...groups.map((each) => ({
|
|
455
|
+
kind: 'fields',
|
|
456
|
+
...('title' in each && each.title ? { title: each.title } : {}),
|
|
457
|
+
presentation: 'properties',
|
|
458
|
+
columns: 2,
|
|
459
|
+
emptyMode: 'show',
|
|
460
|
+
paths: each.paths,
|
|
461
|
+
})),
|
|
462
|
+
];
|
|
463
|
+
const beside = cards.map((card) => ({
|
|
464
|
+
kind: 'fields',
|
|
465
|
+
title: card.title,
|
|
466
|
+
presentation: 'card',
|
|
467
|
+
region: 'aside',
|
|
468
|
+
paths: card.paths,
|
|
469
|
+
}));
|
|
470
|
+
const now = anatomy.current;
|
|
471
|
+
if (now) {
|
|
472
|
+
beside.push({
|
|
473
|
+
kind: 'list',
|
|
474
|
+
title: now.title,
|
|
475
|
+
from: now.from,
|
|
476
|
+
path: now.whose,
|
|
477
|
+
columns: now.show,
|
|
478
|
+
limit: 1,
|
|
479
|
+
presentation: 'card',
|
|
480
|
+
region: 'aside',
|
|
481
|
+
...(now.query ? { filter: now.query } : {}),
|
|
482
|
+
...(now.sort
|
|
483
|
+
? { orderBy: [{ column: now.sort.split(' ')[0], direction: now.sort.endsWith(' asc') ? 'asc' : 'desc' }] }
|
|
484
|
+
: {}),
|
|
485
|
+
});
|
|
486
|
+
}
|
|
487
|
+
/* Every list fits on the page's one screen with the rest (MAX_SECTIONS): a table pointed at by more than that
|
|
488
|
+
keeps its first ones, in the order the schema declares them. */
|
|
489
|
+
const room = MAX_SECTIONS - sections.length - (anatomy.history ? 1 : 0) - beside.length;
|
|
490
|
+
sections.push(...anatomy.related.slice(0, Math.max(0, room)).map(listSection));
|
|
491
|
+
if (anatomy.history)
|
|
492
|
+
sections.push({ kind: 'history' });
|
|
493
|
+
return [...sections, ...beside];
|
|
494
|
+
}
|
|
314
495
|
/** The page an App draws for a resource it declared none for (appProjection.ts, /api/pages/suggested). */
|
|
315
496
|
export function anatomyPage(schema, baseId, hints = {}) {
|
|
316
|
-
const anatomy = recordAnatomy(schema, baseId, hints);
|
|
317
497
|
const base = findTable(schema, baseId);
|
|
318
|
-
|
|
498
|
+
const sections = base ? inferredSections(schema, base, hints) : null;
|
|
499
|
+
if (!base || !sections)
|
|
319
500
|
return null;
|
|
320
501
|
return {
|
|
321
502
|
id: `suggested:${base.id}`,
|
|
322
503
|
name: base.name,
|
|
323
504
|
base: base.id,
|
|
324
|
-
sections
|
|
505
|
+
sections,
|
|
325
506
|
listTabs: true,
|
|
326
507
|
source: 'suggested',
|
|
327
508
|
};
|
|
@@ -111,8 +111,14 @@ export interface PageFields {
|
|
|
111
111
|
actions?: PageHeadlineAction[];
|
|
112
112
|
/** A headline's second figure, under the first and smaller: an estimate, a unit price. */
|
|
113
113
|
subfigure?: string;
|
|
114
|
-
/** A headline's line under its figure, read from a column of the record: an income's frequency.
|
|
114
|
+
/** A headline's line under its figure, read from a column of the record: an income's frequency. On an inferred
|
|
115
|
+
page's header (pageAnatomy.ts), the line under the record's name, its name column's own `subtitle`; an
|
|
116
|
+
authored `header()` has no such key. */
|
|
115
117
|
subtitle?: string;
|
|
118
|
+
/** On an inferred page's header (pageAnatomy.ts), a fact path → the path its value runs until: the fact is said as
|
|
119
|
+
one range ("Sep 13, 2026, 2:00 – 4:00 PM"), the end never repeating the start's day, and the end is no fact of its
|
|
120
|
+
own. An authored `header()` has no such key. */
|
|
121
|
+
spans?: Record<string, string>;
|
|
116
122
|
/** A headline's earlier value of its figure — a was-price — struck through beside it when it has one above the figure. */
|
|
117
123
|
was?: string;
|
|
118
124
|
/** A headline's line of small print under its actions: what the figures assume. */
|
|
@@ -827,6 +833,16 @@ export interface PageDef {
|
|
|
827
833
|
}
|
|
828
834
|
/** Rows a list section shows before it needs a page of its own. */
|
|
829
835
|
export declare const DEFAULT_PAGE_LIST_LIMIT = 10;
|
|
836
|
+
/**
|
|
837
|
+
* The page an App draws for a resource it declared none for (pageAnatomy.ts, inferredSections): only it counts its
|
|
838
|
+
* related tabs, ends them with the history and dresses its fields as a classic form, so a page an author wrote is
|
|
839
|
+
* drawn exactly as written. The Workbench's suggested pages are the schema's own and keep their dress.
|
|
840
|
+
*/
|
|
841
|
+
export declare const isInferredPage: (page: {
|
|
842
|
+
id?: string;
|
|
843
|
+
} | undefined, app: boolean) => boolean;
|
|
844
|
+
/** The address word of an inferred page's history tab (PageSections.tsx, recordReads.ts drawnSections). */
|
|
845
|
+
export declare const HISTORY_TAB = "history";
|
|
830
846
|
/** Sections one screen of a page may draw: in each region, those in no tab and the largest tab's. A page is a
|
|
831
847
|
screen, not a report; a record's tabs are more screens of it, so they are counted one at a time. */
|
|
832
848
|
export declare const MAX_SECTIONS = 24;
|
package/dist/shared/pageModel.js
CHANGED
|
@@ -92,6 +92,14 @@ export function kindReading(kind, ...reads) {
|
|
|
92
92
|
export const walksRelation = (section) => SECTION_TRAITS[section.kind].relation;
|
|
93
93
|
/** Rows a list section shows before it needs a page of its own. */
|
|
94
94
|
export const DEFAULT_PAGE_LIST_LIMIT = 10;
|
|
95
|
+
/**
|
|
96
|
+
* The page an App draws for a resource it declared none for (pageAnatomy.ts, inferredSections): only it counts its
|
|
97
|
+
* related tabs, ends them with the history and dresses its fields as a classic form, so a page an author wrote is
|
|
98
|
+
* drawn exactly as written. The Workbench's suggested pages are the schema's own and keep their dress.
|
|
99
|
+
*/
|
|
100
|
+
export const isInferredPage = (page, app) => app && Boolean(page?.id?.startsWith('suggested:'));
|
|
101
|
+
/** The address word of an inferred page's history tab (PageSections.tsx, recordReads.ts drawnSections). */
|
|
102
|
+
export const HISTORY_TAB = 'history';
|
|
95
103
|
/** Sections one screen of a page may draw: in each region, those in no tab and the largest tab's. A page is a
|
|
96
104
|
screen, not a report; a record's tabs are more screens of it, so they are counted one at a time. */
|
|
97
105
|
export const MAX_SECTIONS = 24;
|
package/dist/shared/query.d.ts
CHANGED
|
@@ -34,9 +34,11 @@ interface ParsedQuery {
|
|
|
34
34
|
filter: Filter;
|
|
35
35
|
/** Explicit column list from `show`, empty for all columns. */
|
|
36
36
|
columns: string[];
|
|
37
|
+
/** `nulls: 'last'` where the sort says `nulls last`: an empty value after every other, in either direction, on every engine. */
|
|
37
38
|
orderBy: {
|
|
38
39
|
column: string;
|
|
39
40
|
direction: 'asc' | 'desc';
|
|
41
|
+
nulls?: 'last';
|
|
40
42
|
}[];
|
|
41
43
|
limit?: number;
|
|
42
44
|
}
|
package/dist/shared/query.js
CHANGED
|
@@ -1196,14 +1196,22 @@ function parseUncached(input, options) {
|
|
|
1196
1196
|
const orderBy = [];
|
|
1197
1197
|
if (clauses.sort) {
|
|
1198
1198
|
for (const part of clauses.sort.split(/\s*,\s*|\s+and\s+/i)) {
|
|
1199
|
-
|
|
1199
|
+
/* `due_on`, `due_on desc`, `due_on nulls last`, `due_on asc nulls last`: where an empty value goes is said
|
|
1200
|
+
once, the same on every engine (SQLite and MySQL put it first going up, PostgreSQL last). */
|
|
1201
|
+
const words = part.trim().split(/\s+/);
|
|
1202
|
+
const nullsLast = words.length >= 3 && /^nulls$/i.test(words[words.length - 2]) && /^last$/i.test(words[words.length - 1]);
|
|
1203
|
+
const [field, dir] = nullsLast ? words.slice(0, -2) : words;
|
|
1200
1204
|
if (!field)
|
|
1201
1205
|
continue;
|
|
1202
1206
|
const { column, error } = resolveColumn(table, field);
|
|
1203
1207
|
if (error)
|
|
1204
1208
|
errors.push({ message: error, at: clauseAt.sort });
|
|
1205
1209
|
else
|
|
1206
|
-
orderBy.push({
|
|
1210
|
+
orderBy.push({
|
|
1211
|
+
column: column?.name ?? field,
|
|
1212
|
+
direction: (dir ?? '').toLowerCase() === 'desc' ? 'desc' : 'asc',
|
|
1213
|
+
...(nullsLast ? { nulls: 'last' } : {}),
|
|
1214
|
+
});
|
|
1207
1215
|
}
|
|
1208
1216
|
}
|
|
1209
1217
|
const columns = [];
|
|
@@ -1287,7 +1295,7 @@ export function explain(query) {
|
|
|
1287
1295
|
lines.push(` WHERE ${groups.length === 1 ? groups[0] : groups.map((g) => `(${g})`).join('\n OR ')}`);
|
|
1288
1296
|
}
|
|
1289
1297
|
if (query.orderBy.length) {
|
|
1290
|
-
lines.push(` ORDER BY ${query.orderBy.map((o) => `${o.column} ${o.direction.toUpperCase()}`).join(', ')}`);
|
|
1298
|
+
lines.push(` ORDER BY ${query.orderBy.map((o) => `${o.column} ${o.direction.toUpperCase()}${o.nulls ? ' NULLS LAST' : ''}`).join(', ')}`);
|
|
1291
1299
|
}
|
|
1292
1300
|
if (query.limit !== undefined)
|
|
1293
1301
|
lines.push(` LIMIT ${query.limit}`);
|
package/dist/shared/reads.d.ts
CHANGED
|
@@ -1,7 +1,16 @@
|
|
|
1
1
|
import { type Filter, type SqlStyle } from './filter.js';
|
|
2
|
+
/** What a lanes read (`lanes: { by, limit }`, adapter.ts lanesStatement, view.ts compileView) numbers each row by
|
|
3
|
+
within its lane: no column of a result is called it, and it never leaves the server. */
|
|
4
|
+
export declare const LANE_ROW = "mistri_lane_row";
|
|
2
5
|
/** What a caller gets when it does not say. Small on purpose: the first page
|
|
3
6
|
of a browse should be instant, and paging is one click. */
|
|
4
7
|
export declare const DEFAULT_LIMIT = 20;
|
|
8
|
+
/** The rows a list page holds until the reader chooses another size. Fifty fills a tall desktop's grid (about thirty
|
|
9
|
+
rows at a comfortable height) so a first look needs no paging, and is still one cheap read. It is a constant, not
|
|
10
|
+
the viewport's row count, because the server draws a list's first page before it knows the window: a size the
|
|
11
|
+
browser alone chose would ask a different question than the page carried and read it again. The API's own default
|
|
12
|
+
stays `DEFAULT_LIMIT`. */
|
|
13
|
+
export declare const LIST_PAGE_SIZE = 50;
|
|
5
14
|
/** The hard ceiling. Nothing may exceed it, including an explicit request. */
|
|
6
15
|
export declare const MAX_LIMIT = 100000;
|
|
7
16
|
/** The most rows one read answers for a table its reader may not export: the largest a screen reads (a tree list,
|
package/dist/shared/reads.js
CHANGED
|
@@ -13,9 +13,18 @@ import { buildWhere } from './filter.js';
|
|
|
13
13
|
path to an unbounded query: a caller that omits a limit gets the default, a
|
|
14
14
|
caller that asks for too many gets the ceiling, and a caller that sends
|
|
15
15
|
nonsense gets the default rather than `LIMIT NaN`. */
|
|
16
|
+
/** What a lanes read (`lanes: { by, limit }`, adapter.ts lanesStatement, view.ts compileView) numbers each row by
|
|
17
|
+
within its lane: no column of a result is called it, and it never leaves the server. */
|
|
18
|
+
export const LANE_ROW = 'mistri_lane_row';
|
|
16
19
|
/** What a caller gets when it does not say. Small on purpose: the first page
|
|
17
20
|
of a browse should be instant, and paging is one click. */
|
|
18
21
|
export const DEFAULT_LIMIT = 20;
|
|
22
|
+
/** The rows a list page holds until the reader chooses another size. Fifty fills a tall desktop's grid (about thirty
|
|
23
|
+
rows at a comfortable height) so a first look needs no paging, and is still one cheap read. It is a constant, not
|
|
24
|
+
the viewport's row count, because the server draws a list's first page before it knows the window: a size the
|
|
25
|
+
browser alone chose would ask a different question than the page carried and read it again. The API's own default
|
|
26
|
+
stays `DEFAULT_LIMIT`. */
|
|
27
|
+
export const LIST_PAGE_SIZE = 50;
|
|
19
28
|
/** The hard ceiling. Nothing may exceed it, including an explicit request. */
|
|
20
29
|
export const MAX_LIMIT = 100_000;
|
|
21
30
|
/** The most rows one read answers for a table its reader may not export: the largest a screen reads (a tree list,
|
|
@@ -22,6 +22,7 @@ export type LabelField = {
|
|
|
22
22
|
prefix?: string;
|
|
23
23
|
};
|
|
24
24
|
words?: Record<string, string>;
|
|
25
|
+
date?: true;
|
|
25
26
|
};
|
|
26
27
|
type LabelPart = {
|
|
27
28
|
text: string;
|
|
@@ -51,6 +52,10 @@ export declare const maskedField: (path: string, prefix?: string) => string;
|
|
|
51
52
|
export declare const maskedPath: (path: string, prefix?: string) => string;
|
|
52
53
|
/** Whether an authored template writes a mask itself: that is the column's display rule's to say. */
|
|
53
54
|
export declare const writesMask: (template: string) => boolean;
|
|
55
|
+
/** Whether an authored template writes the day mark itself: the server's, in a name it composes. */
|
|
56
|
+
export declare const writesDay: (template: string) => boolean;
|
|
57
|
+
/** A template field for a date path said as its day, as the server writes it into a template it composes. */
|
|
58
|
+
export declare const datedField: (path: string) => string;
|
|
54
59
|
/**
|
|
55
60
|
* The name a record with no name of its own is given: its noun and its key,
|
|
56
61
|
* "Purchase order #3", rather than the bare key a title and a breadcrumb
|
|
@@ -25,6 +25,10 @@ const MASK_MARK = '|masked';
|
|
|
25
25
|
physical". The map is URI-encoded JSON, so no brace or bar in a word
|
|
26
26
|
ends the field early. */
|
|
27
27
|
const WORDS_MARK = '|words:';
|
|
28
|
+
/* Or its day, `{starts_at|date}`: a date or a timestamp said as a person reads a day ("Sep 13, 2026"), never its
|
|
29
|
+
stored text ("2026-09-13 14:00:00"). Only the server writes it, in the name it composes for a table with no name of
|
|
30
|
+
its own (appRecordLabels.ts): the parent's name and the day the record is for. */
|
|
31
|
+
const DATE_MARK = '|date';
|
|
28
32
|
/** Whether an authored record label is a template rather than a path. */
|
|
29
33
|
export const isLabelTemplate = (text) => typeof text === 'string' && text.includes('{');
|
|
30
34
|
/** The prefix a `$label` path hangs off ('' for the base's own), or undefined for any other path. */
|
|
@@ -86,6 +90,9 @@ export function parseLabelTemplate(template) {
|
|
|
86
90
|
function parseField(source, template) {
|
|
87
91
|
let field = source;
|
|
88
92
|
let words;
|
|
93
|
+
const dated = field.trimEnd().endsWith(DATE_MARK);
|
|
94
|
+
if (dated)
|
|
95
|
+
field = field.trimEnd().slice(0, -DATE_MARK.length);
|
|
89
96
|
const worded = field.indexOf(WORDS_MARK);
|
|
90
97
|
if (worded !== -1) {
|
|
91
98
|
words = readWords(field.slice(worded + WORDS_MARK.length));
|
|
@@ -99,7 +106,12 @@ function parseField(source, template) {
|
|
|
99
106
|
if (!FIELD.test(path) || path.split('.').includes(LABEL_SEGMENT) || (after !== undefined && after !== '' && !after.startsWith(':'))) {
|
|
100
107
|
return { problem: `"{${field}}" in "${template}" is not a column or a reference path, like {id} or {customer_id.name}.` };
|
|
101
108
|
}
|
|
102
|
-
return {
|
|
109
|
+
return {
|
|
110
|
+
path,
|
|
111
|
+
...(after === undefined ? {} : { mask: after ? { prefix: after.slice(1) } : {} }),
|
|
112
|
+
...(words ? { words } : {}),
|
|
113
|
+
...(dated ? { date: true } : {}),
|
|
114
|
+
};
|
|
103
115
|
}
|
|
104
116
|
/** A template field's text, written back from its alternatives' own (a masked one marked, a worded one with its words). */
|
|
105
117
|
export const fieldText = (alternatives) => `{${alternatives.join(FALLBACK)}}`;
|
|
@@ -130,15 +142,23 @@ export const maskedField = (path, prefix) => `{${maskedPath(path, prefix)}}`;
|
|
|
130
142
|
export const maskedPath = (path, prefix) => `${path}${MASK_MARK}${prefix ? `:${prefix}` : ''}`;
|
|
131
143
|
/** Whether an authored template writes a mask itself: that is the column's display rule's to say. */
|
|
132
144
|
export const writesMask = (template) => template.includes(MASK_MARK) || template.includes(WORDS_MARK);
|
|
145
|
+
/** Whether an authored template writes the day mark itself: the server's, in a name it composes. */
|
|
146
|
+
export const writesDay = (template) => /\|date\s*[}?]/.test(template);
|
|
147
|
+
/** A template field for a date path said as its day, as the server writes it into a template it composes. */
|
|
148
|
+
export const datedField = (path) => `{${path}${DATE_MARK}}`;
|
|
133
149
|
/**
|
|
134
150
|
* The name a record with no name of its own is given: its noun and its key,
|
|
135
151
|
* "Purchase order #3", rather than the bare key a title and a breadcrumb
|
|
136
152
|
* used to show. One key column only: a composite key is not one number.
|
|
137
153
|
*/
|
|
138
154
|
export function nounTemplate(noun, key) {
|
|
155
|
+
return `${nounWord(noun)} #{${key}}`;
|
|
156
|
+
}
|
|
157
|
+
/** A noun as a template's literal words: capitalized, and held to what a template's text may hold. */
|
|
158
|
+
function nounWord(noun) {
|
|
139
159
|
const word = [...noun]
|
|
140
160
|
.filter((character) => character !== '{' && character !== '}' && !unsafe(character))
|
|
141
161
|
.join('')
|
|
142
162
|
.trim() || 'Record';
|
|
143
|
-
return `${word.charAt(0).toUpperCase()}${word.slice(1)}
|
|
163
|
+
return `${word.charAt(0).toUpperCase()}${word.slice(1)}`;
|
|
144
164
|
}
|
|
@@ -35,6 +35,7 @@ export interface ReadSection {
|
|
|
35
35
|
readonly status?: string;
|
|
36
36
|
readonly subfigure?: string;
|
|
37
37
|
readonly subtitle?: string;
|
|
38
|
+
readonly spans?: Readonly<Record<string, string>>;
|
|
38
39
|
readonly was?: string;
|
|
39
40
|
readonly actions?: ReadonlyArray<{
|
|
40
41
|
readonly prefill?: Readonly<Record<string, string>>;
|
|
@@ -45,6 +46,11 @@ export interface ReadSection {
|
|
|
45
46
|
readonly field: string;
|
|
46
47
|
};
|
|
47
48
|
readonly from?: string;
|
|
49
|
+
/** A related list's way back to the record, and its own narrowing: what its tab's count asks. */
|
|
50
|
+
readonly path?: string;
|
|
51
|
+
readonly filter?: string;
|
|
52
|
+
readonly of?: string;
|
|
53
|
+
readonly similar?: unknown;
|
|
48
54
|
readonly limit?: number;
|
|
49
55
|
readonly record?: readonly string[];
|
|
50
56
|
readonly when?: string;
|
|
@@ -214,9 +220,33 @@ export declare function historyBody(base: TableMeta, key: Readonly<Record<string
|
|
|
214
220
|
* is opened, as ever, and asked for nothing here.
|
|
215
221
|
*/
|
|
216
222
|
export declare function drawnSections(schema: DatabaseSchema, page: {
|
|
223
|
+
id?: string;
|
|
217
224
|
sections: readonly ReadSection[];
|
|
218
225
|
listTabs?: boolean;
|
|
219
226
|
}, tab: string | undefined, appPage: boolean): Set<number>;
|
|
227
|
+
/**
|
|
228
|
+
* A section a run of lists draws as one of its tabs: a list that is no picture and has no width an author gave it,
|
|
229
|
+
* and on an inferred page its history, which ends the strip (pageAnatomy.ts) — read when its tab is opened, never
|
|
230
|
+
* with the page.
|
|
231
|
+
*/
|
|
232
|
+
export declare function tabbedSection(section: ReadSection, appPage: boolean, inferred: boolean): boolean;
|
|
233
|
+
/** A related tab's count's ceiling, as a list's total has one: past it the tab says "10,000+". */
|
|
234
|
+
export declare const RELATED_COUNT_LIMIT = 10000;
|
|
235
|
+
/**
|
|
236
|
+
* The question a related tab's count asks, in the words `/api/counts` reads: the rows of its list that point at the
|
|
237
|
+
* record (`booking class_session_id = 5`), under the list's own narrowing. One hop to the record by its whole key,
|
|
238
|
+
* which is what an inferred page lists; any other list has no question, and its tab keeps the count's room empty.
|
|
239
|
+
*/
|
|
240
|
+
export declare function relatedCountQuestion(schema: DatabaseSchema, section: ReadSection, base: TableMeta, key: Readonly<Record<string, unknown>>): string | undefined;
|
|
241
|
+
/**
|
|
242
|
+
* Every count a strip of related tabs shows, in one request: one statement for them all where each is a plain
|
|
243
|
+
* condition (countEach), never a list's read per tab. The client's strip asks this very body (PageSections.tsx),
|
|
244
|
+
* so on a composed page it is answered from the compose.
|
|
245
|
+
*/
|
|
246
|
+
export declare function relatedCountsBody(schema: DatabaseSchema, sections: readonly ReadSection[], base: TableMeta, key: Readonly<Record<string, unknown>>): {
|
|
247
|
+
items: string[];
|
|
248
|
+
countLimit: number;
|
|
249
|
+
} | undefined;
|
|
220
250
|
/**
|
|
221
251
|
* Every read a record page's sections will ask for when it opens on `tab`,
|
|
222
252
|
* given its plan: the record's row (every column any section drawn reads),
|