@mistriwork/engine 1.0.0-rc.17 → 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/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/server/columnGrants.d.ts +5 -0
- package/dist/server/connections.d.ts +1 -0
- package/dist/server/connections.js +13 -3
- package/dist/server/http/firstPaint.d.ts +5 -1
- package/dist/server/http/firstPaint.js +4 -4
- package/dist/server/httpConnection.d.ts +4 -2
- package/dist/server/httpConnection.js +10 -3
- package/dist/server/journalStore.d.ts +2 -2
- package/dist/server/journalStore.js +33 -10
- 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/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 +1 -0
- 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 +72 -8
- 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 +18 -0
- 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 +4 -1
- package/schema/theme.d.ts +8 -4
package/dist/shared/form.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { stateStampColumn } from './schema.js';
|
|
1
2
|
/** The explicit selection wins; otherwise steps declare the form's fields
|
|
2
3
|
* in order. Groups only arrange fields and do not narrow a schema-derived form. */
|
|
3
4
|
export function formShownFields(form) {
|
|
@@ -23,3 +24,55 @@ export function unformedColumns(table, writes) {
|
|
|
23
24
|
const assigned = autoKey(table);
|
|
24
25
|
return table.columns.filter((column) => isRequired(column, assigned) && !writes(column.name)).map((column) => column.name);
|
|
25
26
|
}
|
|
27
|
+
/* Stamps of a row's own life, by their names: when it was entered, when it was last touched. */
|
|
28
|
+
const STAMP = /^(sys_)?(created|inserted|added|entered|updated|modified|changed|last_updated)(_at|_on|_date|_time)?$/i;
|
|
29
|
+
/* A default that hands out the next number: a sequence's, an engine's own counter. */
|
|
30
|
+
const NUMBERED = /\bnextval\s*\(|\bauto_?increment\b/i;
|
|
31
|
+
/* When a record was entered, by the words people use for it: a ticket's `opened_at`, a note's `created_at`. */
|
|
32
|
+
const ENTERED = /^(created|opened|raised|logged|reported|entered|inserted|added)(_at|_on|_date)?$/i;
|
|
33
|
+
const dated = (column) => /date|time/i.test(column.type ?? '') || /_(at|on)$/.test(column.name);
|
|
34
|
+
const defaulted = (column) => column.default !== undefined || column.hasDefault === true;
|
|
35
|
+
/**
|
|
36
|
+
* The columns a New form leaves to the database and the App's machine, where the App's form does not name them: a
|
|
37
|
+
* moment the database stamps (a timestamp with a default, or a creation or upkeep stamp with one), a number a
|
|
38
|
+
* sequence hands out, and a state's own stamp (`completed_at` beside a `completed` state), which the platform
|
|
39
|
+
* writes as the record enters the state (stateStampColumn) — a new record starts in its first one. None of these is
|
|
40
|
+
* the creator's to say, and a form that asked for them asked a person to invent a value the system keeps. Each stays
|
|
41
|
+
* on the record, editable there where it is writable. A day with a default (an invoice's date, today unless said)
|
|
42
|
+
* is the creator's, and stays asked.
|
|
43
|
+
*/
|
|
44
|
+
export function platformWritten(table, machine) {
|
|
45
|
+
const written = new Set();
|
|
46
|
+
for (const column of table.columns) {
|
|
47
|
+
if (column.primaryKey || column.references)
|
|
48
|
+
continue;
|
|
49
|
+
if (defaulted(column) && dated(column) && (/time|datetime/i.test(column.type ?? '') || STAMP.test(column.name)))
|
|
50
|
+
written.add(column.name);
|
|
51
|
+
else if (column.default !== undefined && NUMBERED.test(column.default))
|
|
52
|
+
written.add(column.name);
|
|
53
|
+
}
|
|
54
|
+
if (machine) {
|
|
55
|
+
if (machine.since)
|
|
56
|
+
written.add(machine.since);
|
|
57
|
+
for (const state of machine.states) {
|
|
58
|
+
const stamp = stateStampColumn(state, table.columns, machine);
|
|
59
|
+
if (stamp)
|
|
60
|
+
written.add(stamp.name);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return written;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* The columns a New form starts at now where nothing else starts them: a required stamp of when the record was
|
|
67
|
+
* entered (`opened_at`, `created_at`) with no default of the database's or the form's. The form still asks it, so a
|
|
68
|
+
* record entered late can say when it really was; it no longer asks a person to type the moment they are in.
|
|
69
|
+
*/
|
|
70
|
+
export function enteredNow(columns, defaults) {
|
|
71
|
+
return columns.filter((column) => !column.primaryKey &&
|
|
72
|
+
!column.references &&
|
|
73
|
+
column.nullable === false &&
|
|
74
|
+
!defaulted(column) &&
|
|
75
|
+
!Object.hasOwn(defaults, column.name) &&
|
|
76
|
+
ENTERED.test(column.name) &&
|
|
77
|
+
dated(column));
|
|
78
|
+
}
|
|
@@ -32,6 +32,9 @@ export function keysetOrder(table, order, dialect) {
|
|
|
32
32
|
const key = primaryKey(table);
|
|
33
33
|
if (!key.length || !key.every((column) => order.some((o) => o.column === column)))
|
|
34
34
|
return false;
|
|
35
|
+
/* A sort that moves its empty values says where they go on its own terms; a step is asked by offset there. */
|
|
36
|
+
if (order.some((o) => o.nulls))
|
|
37
|
+
return false;
|
|
35
38
|
return order.every((o) => {
|
|
36
39
|
const column = table.columns.find((c) => c.name === o.column);
|
|
37
40
|
if (!column || UNFAITHFUL.test(column.type))
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { type DatabaseSchema, type TableMeta } from './schema.js';
|
|
2
|
+
import type { AppBoardList } from './listPresentations.js';
|
|
3
|
+
/** What the App says about the resource that the inference reads. */
|
|
4
|
+
export interface InferenceResource {
|
|
5
|
+
/** The App's record label (`recordLabel`): the column, path or template a record is named by; false withholds it. */
|
|
6
|
+
recordLabel?: string | false;
|
|
7
|
+
/** Each column's display rule as drawn (declared over the conventions, displayDefaults.ts effectiveDisplay). */
|
|
8
|
+
display?: Readonly<Record<string, {
|
|
9
|
+
subtitle?: string;
|
|
10
|
+
format?: string;
|
|
11
|
+
} | undefined>>;
|
|
12
|
+
/** The resource's machine: its column and its states in order. */
|
|
13
|
+
machine?: {
|
|
14
|
+
column: string;
|
|
15
|
+
states: readonly {
|
|
16
|
+
name: string;
|
|
17
|
+
label?: string;
|
|
18
|
+
final?: boolean;
|
|
19
|
+
}[];
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
/** One inferred tab: the label, the condition it adds (a sort clause after it where it reads its own order). */
|
|
23
|
+
interface InferredTab {
|
|
24
|
+
label: string;
|
|
25
|
+
query?: string;
|
|
26
|
+
}
|
|
27
|
+
/** The state a list's rows are in: the machine's column, else a vocabulary named like one. */
|
|
28
|
+
export declare function stateColumn(table: TableMeta, resource?: InferenceResource): string | undefined;
|
|
29
|
+
/** The one date a list shows and filters by: when it is due, else when it starts, else when it came to be. */
|
|
30
|
+
export declare function oneDate(table: TableMeta): string | undefined;
|
|
31
|
+
/** When a row came to be, for newest first. */
|
|
32
|
+
export declare const createdDate: (table: TableMeta) => string | undefined;
|
|
33
|
+
/** When a row is due, where the table says: what an overdue row is late against. */
|
|
34
|
+
export declare const dueDate: (table: TableMeta) => string | undefined;
|
|
35
|
+
/** The rows still under way, in the query language: the machine's open states, or the vocabulary's words that are not
|
|
36
|
+
final. Undefined where nothing says a row is ever over. */
|
|
37
|
+
export declare function openQuery(table: TableMeta, resource?: InferenceResource): string | undefined;
|
|
38
|
+
/**
|
|
39
|
+
* The column a list leads with: what the record is called, where it is one of its own required columns. A name a row
|
|
40
|
+
* may leave blank (a visit's nullable summary) names nothing on the rows that leave it, so the row leads with what it
|
|
41
|
+
* belongs to instead (`job_id`, said by the job's name), the first required reference with a name of its own.
|
|
42
|
+
*/
|
|
43
|
+
export declare function leadColumn(schema: DatabaseSchema, table: TableMeta, resource?: InferenceResource): string | undefined;
|
|
44
|
+
export declare const CODE: RegExp;
|
|
45
|
+
/**
|
|
46
|
+
* The second line under a list's name where its view names no columns and its display rule names none: a code the
|
|
47
|
+
* row is also quoted by (a job's number under its title), proven unique by the catalog. Only a list whose columns
|
|
48
|
+
* are inferred draws it, so a list an author arranged, and every record page, stays as written.
|
|
49
|
+
*/
|
|
50
|
+
export declare function inferListSubtitles(schema: DatabaseSchema, table: TableMeta, resource?: InferenceResource): Record<string, string>;
|
|
51
|
+
/**
|
|
52
|
+
* A list's columns where its view names none, in the order a row is read: its name (the display rule's second line
|
|
53
|
+
* under it, where one exists), its state, what it belongs to by name, one date, its money, then its other short
|
|
54
|
+
* words and figures. Left out: the key where the row has a name, a column pinned to one value, long text, a second
|
|
55
|
+
* copy of what the name's second line already says, every date but the one, a postal address past its first part,
|
|
56
|
+
* documents and bytes. The grid leaves out from the end what its room cannot hold.
|
|
57
|
+
*/
|
|
58
|
+
export declare function inferListColumns(schema: DatabaseSchema, table: TableMeta, resource?: InferenceResource): string[];
|
|
59
|
+
/**
|
|
60
|
+
* The order a list reads in where its view says none: work that has a date to be done by is read soonest first —
|
|
61
|
+
* the open tabs, by that date — and anything else newest first by when it came to be. A table with neither reads
|
|
62
|
+
* by its name, never by its key. Undefined leaves the platform's own order (schema.ts defaultOrder).
|
|
63
|
+
*/
|
|
64
|
+
export declare function inferListSort(schema: DatabaseSchema, table: TableMeta, resource?: InferenceResource): string | undefined;
|
|
65
|
+
/**
|
|
66
|
+
* Tabs where the view names none, from the machine (or a status vocabulary): Open — every state that is not final —
|
|
67
|
+
* then each open state while there are two to five of them, Done — the final ones — and All. The open tabs read in
|
|
68
|
+
* the list's order; Done and All read newest first, where finished work is looked back on.
|
|
69
|
+
*/
|
|
70
|
+
export declare function inferListTabs(_schema: DatabaseSchema, table: TableMeta, resource?: InferenceResource): InferredTab[] | undefined;
|
|
71
|
+
/**
|
|
72
|
+
* Filters where the view names none: every vocabulary and yes-or-no among its own columns (the state too where no
|
|
73
|
+
* tab says it already), each reference to a table of at most fifty records, and the one date.
|
|
74
|
+
*/
|
|
75
|
+
export declare function inferListFilters(schema: DatabaseSchema, table: TableMeta, resource?: InferenceResource, tabbed?: boolean): string[];
|
|
76
|
+
/**
|
|
77
|
+
* A board to switch the list to, where its machine has three to seven open states: a lane per state in the
|
|
78
|
+
* machine's order, the final ones together in one folded Done lane, a card of the name, what it belongs to, the date and its
|
|
79
|
+
* urgency toned. A card dropped in another lane runs the one verb that leads there (BoardList.tsx).
|
|
80
|
+
*/
|
|
81
|
+
export declare function inferBoard(schema: DatabaseSchema, table: TableMeta, resource?: InferenceResource): AppBoardList | undefined;
|
|
82
|
+
/**
|
|
83
|
+
* The table an App is about, for a home it did not declare: the one with a machine that the most of its other
|
|
84
|
+
* tables point at, else the most pointed at; between two pointed at as often, the one that points at more (a job
|
|
85
|
+
* before the technician it is filed under), then the App's own order.
|
|
86
|
+
*/
|
|
87
|
+
export declare function mainTable(schema: DatabaseSchema, tables: readonly {
|
|
88
|
+
table: TableMeta;
|
|
89
|
+
machine: boolean;
|
|
90
|
+
}[]): TableMeta | undefined;
|
|
91
|
+
export {};
|
|
@@ -0,0 +1,323 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a list draws when its view says nothing of it: its columns, its order,
|
|
3
|
+
* its tabs, its filters and a board to switch to. A coding agent's least
|
|
4
|
+
* effort is a `listView(label, table)`, and the list it opens on is the one
|
|
5
|
+
* nobody wrote, so it has to read as if somebody had: the name first, the
|
|
6
|
+
* state beside it, what it belongs to, one date, the money, and nothing the
|
|
7
|
+
* reader has already been told.
|
|
8
|
+
*
|
|
9
|
+
* Each piece is inferred only where the view declares none (app.ts
|
|
10
|
+
* resolveListView), from the catalog and what the App says of the resource —
|
|
11
|
+
* its record label, its display rules, its machine — never from a row, so the
|
|
12
|
+
* list's first question is known before anything is read and nothing moves
|
|
13
|
+
* when the rows arrive. Pure, so the server's projection and the tests read
|
|
14
|
+
* one rule.
|
|
15
|
+
*/
|
|
16
|
+
import { isMoneyColumn } from './displayDefaults.js';
|
|
17
|
+
import { DUE } from './dueDate.js';
|
|
18
|
+
import { humanName } from './model.js';
|
|
19
|
+
import { columnKind, findTable, isFlagColumn, labelColumn, labelPath, looksLikeDate, primaryKey, referencesTo, } from './schema.js';
|
|
20
|
+
/** A list never shows more than this many inferred columns; the grid leaves out what its room cannot hold (gridSizing.ts). */
|
|
21
|
+
const INFERRED_COLUMNS = 7;
|
|
22
|
+
/** A reference is a filter while the table it points at is this small: a picker of fifty names is read at a glance. */
|
|
23
|
+
const FILTER_TARGETS = 50;
|
|
24
|
+
/** Tabs for the open states one by one, at most: past it the open tab is the way in. */
|
|
25
|
+
const STATE_TABS = 5;
|
|
26
|
+
/** A machine whose open states number this many is drawn as lanes as well as rows. */
|
|
27
|
+
const BOARD_STATES = { min: 3, max: 7 };
|
|
28
|
+
/* Text written to be read, not scanned: a list has no room for it, and its record page does. */
|
|
29
|
+
const LONG_TEXT = /(^|_)(description|body|notes?|summary|content|details|comments?|bio|message|text|html|markdown|instructions|access_notes)$/i;
|
|
30
|
+
/* The parts of a postal address: a place is said once, by the first of them the table keeps. */
|
|
31
|
+
const ADDRESS = /^(street|street_address|address|address_line_?\d|line_?\d|city|town|state|province|region|zip|zip_code|postal_code|postcode|country)$/i;
|
|
32
|
+
/* A start, in the order a person plans by. */
|
|
33
|
+
const START = /^(start|starts|start_date|starts_at|starts_on|start_at|start_on|scheduled_at|scheduled_on|scheduled_for|begins_at|begins_on|event_date|date)$/i;
|
|
34
|
+
/* When the row came to be: what newest first reads. */
|
|
35
|
+
const CREATED = /^(sys_)?(created|inserted|added|opened|raised|issued|ordered|received|submitted|signed_up|joined)(_at|_on|_date)?$/i;
|
|
36
|
+
/* A vocabulary that is the row's state where no machine moves it. */
|
|
37
|
+
const STATUS = /^(status|state|stage|phase)$/i;
|
|
38
|
+
/* The words of a vocabulary that a row ends in: over, however it ended. */
|
|
39
|
+
const FINAL_WORD = /^(done|complete|completed|closed|closed_won|closed_lost|cancelled|canceled|resolved|archived|rejected|declined|lost|won|missed|expired|void|voided|paid|delivered|shipped|failed|no_show|retired|withdrawn)$/i;
|
|
40
|
+
/* A vocabulary of urgency: toned on a board's card. */
|
|
41
|
+
const PRIORITY = /^(priority|urgency|severity|importance)$/i;
|
|
42
|
+
const columnOf = (table, name) => name === undefined ? undefined : table.columns.find((column) => column.name === name);
|
|
43
|
+
const isText = (column) => columnKind(column.type) === 'text' && !/json/i.test(column.type);
|
|
44
|
+
const isBinary = (column) => /blob|bytea|binary/i.test(column.type);
|
|
45
|
+
const isLong = (column) => isText(column) && (LONG_TEXT.test(column.name) || (column.text?.max ?? 0) > 255);
|
|
46
|
+
/* Pinned to one value by the schema: every row says the same, so a column of it says nothing. A distinct read would
|
|
47
|
+
find more, but costs a statement per column on every catalog; the vocabulary is free. */
|
|
48
|
+
const isConstant = (column) => column.allowed?.length === 1;
|
|
49
|
+
/** The state a list's rows are in: the machine's column, else a vocabulary named like one. */
|
|
50
|
+
export function stateColumn(table, resource = {}) {
|
|
51
|
+
if (resource.machine && columnOf(table, resource.machine.column))
|
|
52
|
+
return resource.machine.column;
|
|
53
|
+
return table.columns.find((column) => STATUS.test(column.name) && (column.allowed?.length ?? 0) > 1)?.name;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* The states a list's tabs and board read, in order, each open or final: the machine's, else a status vocabulary's
|
|
57
|
+
* with its final words read off what they say. Undefined where nothing says a row is ever over.
|
|
58
|
+
*/
|
|
59
|
+
function inferredStates(table, resource = {}) {
|
|
60
|
+
const column = stateColumn(table, resource);
|
|
61
|
+
if (!column)
|
|
62
|
+
return undefined;
|
|
63
|
+
if (resource.machine?.column === column) {
|
|
64
|
+
const states = resource.machine.states.map((state) => ({
|
|
65
|
+
name: state.name,
|
|
66
|
+
label: state.label ?? humanName(state.name),
|
|
67
|
+
final: state.final === true,
|
|
68
|
+
}));
|
|
69
|
+
return states.some((state) => state.final) && states.some((state) => !state.final) ? { column, states, machine: true } : undefined;
|
|
70
|
+
}
|
|
71
|
+
const allowed = columnOf(table, column)?.allowed ?? [];
|
|
72
|
+
const states = allowed.map((name) => ({ name, label: humanName(name), final: FINAL_WORD.test(name.trim().replace(/[\s-]+/g, '_')) }));
|
|
73
|
+
return states.some((state) => state.final) && states.some((state) => !state.final) ? { column, states, machine: false } : undefined;
|
|
74
|
+
}
|
|
75
|
+
/** The one date a list shows and filters by: when it is due, else when it starts, else when it came to be. */
|
|
76
|
+
export function oneDate(table) {
|
|
77
|
+
const dates = table.columns.filter((column) => !column.primaryKey && !column.references && looksLikeDate(column));
|
|
78
|
+
return (dates.find((column) => DUE.test(column.name))?.name ??
|
|
79
|
+
dates.find((column) => START.test(column.name))?.name ??
|
|
80
|
+
dates.find((column) => CREATED.test(column.name))?.name);
|
|
81
|
+
}
|
|
82
|
+
/** When a row came to be, for newest first. */
|
|
83
|
+
export const createdDate = (table) => table.columns.find((column) => !column.primaryKey && looksLikeDate(column) && CREATED.test(column.name))?.name;
|
|
84
|
+
/** When a row is due, where the table says: what an overdue row is late against. */
|
|
85
|
+
export const dueDate = (table) => table.columns.find((column) => !column.primaryKey && !column.references && looksLikeDate(column) && DUE.test(column.name))?.name;
|
|
86
|
+
/** The rows still under way, in the query language: the machine's open states, or the vocabulary's words that are not
|
|
87
|
+
final. Undefined where nothing says a row is ever over. */
|
|
88
|
+
export function openQuery(table, resource = {}) {
|
|
89
|
+
const states = inferredStates(table, resource);
|
|
90
|
+
if (!states)
|
|
91
|
+
return undefined;
|
|
92
|
+
return states.machine
|
|
93
|
+
? `${states.column} is open`
|
|
94
|
+
: inStates(states.column, states.states.filter((state) => !state.final).map((state) => state.name));
|
|
95
|
+
}
|
|
96
|
+
const inStates = (column, names) => names.length === 1 ? `${column} = ${names[0]}` : `${column} in (${names.join(', ')})`;
|
|
97
|
+
/**
|
|
98
|
+
* The column a list leads with: what the record is called, where it is one of its own required columns. A name a row
|
|
99
|
+
* may leave blank (a visit's nullable summary) names nothing on the rows that leave it, so the row leads with what it
|
|
100
|
+
* belongs to instead (`job_id`, said by the job's name), the first required reference with a name of its own.
|
|
101
|
+
*/
|
|
102
|
+
export function leadColumn(schema, table, resource = {}) {
|
|
103
|
+
const said = labelPath(schema, table, resource.recordLabel);
|
|
104
|
+
const own = said && !said.includes('.') && !said.startsWith('$') ? columnOf(table, said) : undefined;
|
|
105
|
+
const key = primaryKey(table);
|
|
106
|
+
if (own && !key.includes(own.name) && !own.nullable)
|
|
107
|
+
return own.name;
|
|
108
|
+
/* A name the App chose stands even where a row may leave it blank: it is the author's word. */
|
|
109
|
+
if (own && !key.includes(own.name) && typeof resource.recordLabel === 'string')
|
|
110
|
+
return own.name;
|
|
111
|
+
const parent = table.columns.find((column) => column.references && !column.nullable && namedTarget(schema, column));
|
|
112
|
+
if (parent)
|
|
113
|
+
return parent.name;
|
|
114
|
+
if (own && !key.includes(own.name))
|
|
115
|
+
return own.name;
|
|
116
|
+
return key.length === 1 ? key[0] : undefined;
|
|
117
|
+
}
|
|
118
|
+
/** Whether a reference points at a table whose records have a name of their own, so it is said as that name. */
|
|
119
|
+
function namedTarget(schema, column) {
|
|
120
|
+
const target = column.references ? findTable(schema, column.references.table) : undefined;
|
|
121
|
+
if (!target)
|
|
122
|
+
return false;
|
|
123
|
+
const named = labelColumn(target);
|
|
124
|
+
return Boolean(target.labelTemplate || (named && !primaryKey(target).includes(named)));
|
|
125
|
+
}
|
|
126
|
+
/* A code a row is quoted by beside its name: its number, its SKU, its reference. A reference's second line reads the
|
|
127
|
+
same rule (referenceSubline.ts). */
|
|
128
|
+
export const CODE = /^(number|code|sku|ref|reference|stock_ref)$|_(number|code|no|ref|reference)$/i;
|
|
129
|
+
/**
|
|
130
|
+
* The second line under a list's name where its view names no columns and its display rule names none: a code the
|
|
131
|
+
* row is also quoted by (a job's number under its title), proven unique by the catalog. Only a list whose columns
|
|
132
|
+
* are inferred draws it, so a list an author arranged, and every record page, stays as written.
|
|
133
|
+
*/
|
|
134
|
+
export function inferListSubtitles(schema, table, resource = {}) {
|
|
135
|
+
const lead = leadColumn(schema, table, resource);
|
|
136
|
+
const column = columnOf(table, lead);
|
|
137
|
+
if (!column || column.primaryKey || column.references || resource.display?.[column.name]?.subtitle)
|
|
138
|
+
return {};
|
|
139
|
+
const code = table.columns.find((other) => other.name !== column.name &&
|
|
140
|
+
!other.primaryKey &&
|
|
141
|
+
!other.references &&
|
|
142
|
+
isText(other) &&
|
|
143
|
+
CODE.test(other.name) &&
|
|
144
|
+
(table.unique ?? []).includes(other.name));
|
|
145
|
+
return code ? { [column.name]: code.name } : {};
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* A list's columns where its view names none, in the order a row is read: its name (the display rule's second line
|
|
149
|
+
* under it, where one exists), its state, what it belongs to by name, one date, its money, then its other short
|
|
150
|
+
* words and figures. Left out: the key where the row has a name, a column pinned to one value, long text, a second
|
|
151
|
+
* copy of what the name's second line already says, every date but the one, a postal address past its first part,
|
|
152
|
+
* documents and bytes. The grid leaves out from the end what its room cannot hold.
|
|
153
|
+
*/
|
|
154
|
+
export function inferListColumns(schema, table, resource = {}) {
|
|
155
|
+
const lead = leadColumn(schema, table, resource);
|
|
156
|
+
const key = primaryKey(table);
|
|
157
|
+
const named = lead !== undefined && !key.includes(lead);
|
|
158
|
+
const state = stateColumn(table, resource);
|
|
159
|
+
const date = oneDate(table);
|
|
160
|
+
const under = inferListSubtitles(schema, table, resource);
|
|
161
|
+
const shownUnder = new Set([lead, ...table.columns.filter((column) => column.references).map((column) => column.name)].flatMap((name) => {
|
|
162
|
+
const sub = name === undefined ? undefined : (resource.display?.[name]?.subtitle ?? under[name]);
|
|
163
|
+
return sub && !sub.includes('.') ? [sub] : [];
|
|
164
|
+
}));
|
|
165
|
+
const firstAddress = table.columns.find((column) => ADDRESS.test(column.name))?.name;
|
|
166
|
+
const left = (column) => column.name === lead ||
|
|
167
|
+
column.name === state ||
|
|
168
|
+
(named && column.primaryKey) ||
|
|
169
|
+
(column.primaryKey && key.length > 1) ||
|
|
170
|
+
isConstant(column) ||
|
|
171
|
+
isLong(column) ||
|
|
172
|
+
isBinary(column) ||
|
|
173
|
+
/json/i.test(column.type) ||
|
|
174
|
+
shownUnder.has(column.name) ||
|
|
175
|
+
(looksLikeDate(column) && column.name !== date) ||
|
|
176
|
+
(ADDRESS.test(column.name) && column.name !== firstAddress);
|
|
177
|
+
const candidates = table.columns.filter((column) => !left(column));
|
|
178
|
+
const references = candidates.filter((column) => column.references && namedTarget(schema, column));
|
|
179
|
+
const money = candidates.filter((column) => !column.references && (isMoneyColumn(column) || resource.display?.[column.name]?.format === 'money'));
|
|
180
|
+
const taken = new Set([...references, ...money].map((column) => column.name));
|
|
181
|
+
const rest = candidates.filter((column) => !column.references && !taken.has(column.name) && column.name !== date);
|
|
182
|
+
const words = rest.filter((column) => (column.allowed?.length ?? 0) > 1 || isFlagColumn(column));
|
|
183
|
+
const figures = rest.filter((column) => !words.includes(column) && columnKind(column.type) === 'number' && !column.primaryKey);
|
|
184
|
+
const texts = rest.filter((column) => !words.includes(column) && !figures.includes(column) && isText(column));
|
|
185
|
+
const ordered = [
|
|
186
|
+
...(lead !== undefined ? [lead] : []),
|
|
187
|
+
...(state ? [state] : []),
|
|
188
|
+
...references.map((column) => column.name),
|
|
189
|
+
...(date ? [date] : []),
|
|
190
|
+
...money.map((column) => column.name),
|
|
191
|
+
...words.map((column) => column.name),
|
|
192
|
+
...figures.map((column) => column.name),
|
|
193
|
+
...texts.map((column) => column.name),
|
|
194
|
+
];
|
|
195
|
+
return [...new Set(ordered)].slice(0, INFERRED_COLUMNS);
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* The order a list reads in where its view says none: work that has a date to be done by is read soonest first —
|
|
199
|
+
* the open tabs, by that date — and anything else newest first by when it came to be. A table with neither reads
|
|
200
|
+
* by its name, never by its key. Undefined leaves the platform's own order (schema.ts defaultOrder).
|
|
201
|
+
*/
|
|
202
|
+
export function inferListSort(schema, table, resource = {}) {
|
|
203
|
+
const states = inferredStates(table, resource);
|
|
204
|
+
const date = oneDate(table);
|
|
205
|
+
const created = createdDate(table);
|
|
206
|
+
/* Undated work after the dated, on every engine: SQLite and MySQL would put it first. */
|
|
207
|
+
if (states && date && date !== created)
|
|
208
|
+
return `${date} nulls last`;
|
|
209
|
+
if (created)
|
|
210
|
+
return `${created} desc`;
|
|
211
|
+
const lead = leadColumn(schema, table, resource);
|
|
212
|
+
const column = columnOf(table, lead);
|
|
213
|
+
return column && !column.primaryKey && !column.references && isText(column) ? lead : undefined;
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* Tabs where the view names none, from the machine (or a status vocabulary): Open — every state that is not final —
|
|
217
|
+
* then each open state while there are two to five of them, Done — the final ones — and All. The open tabs read in
|
|
218
|
+
* the list's order; Done and All read newest first, where finished work is looked back on.
|
|
219
|
+
*/
|
|
220
|
+
export function inferListTabs(_schema, table, resource = {}) {
|
|
221
|
+
const states = inferredStates(table, resource);
|
|
222
|
+
if (!states)
|
|
223
|
+
return undefined;
|
|
224
|
+
const { column } = states;
|
|
225
|
+
const open = states.states.filter((state) => !state.final);
|
|
226
|
+
const final = states.states.filter((state) => state.final);
|
|
227
|
+
const created = createdDate(table);
|
|
228
|
+
const date = oneDate(table);
|
|
229
|
+
const back = created ? `${created} desc` : date ? `${date} desc` : undefined;
|
|
230
|
+
const sorted = (query, sort) => sort === undefined ? query : `${query ? `${query} ` : ''}sort ${sort}`;
|
|
231
|
+
const umbrella = new Set(['open', 'done', 'all']);
|
|
232
|
+
const each = open.length >= 2 && open.length <= STATE_TABS
|
|
233
|
+
? open
|
|
234
|
+
.filter((state) => !umbrella.has(state.label.trim().toLowerCase()))
|
|
235
|
+
.map((state) => ({ label: state.label, query: inStates(column, [state.name]) }))
|
|
236
|
+
: [];
|
|
237
|
+
return [
|
|
238
|
+
{ label: 'Open', query: openQuery(table, resource) },
|
|
239
|
+
...each,
|
|
240
|
+
{
|
|
241
|
+
label: 'Done',
|
|
242
|
+
query: sorted(states.machine
|
|
243
|
+
? `${column} is not open`
|
|
244
|
+
: inStates(column, final.map((state) => state.name)), back),
|
|
245
|
+
},
|
|
246
|
+
{ label: 'All', ...(back ? { query: sorted(undefined, back) } : {}) },
|
|
247
|
+
];
|
|
248
|
+
}
|
|
249
|
+
/**
|
|
250
|
+
* Filters where the view names none: every vocabulary and yes-or-no among its own columns (the state too where no
|
|
251
|
+
* tab says it already), each reference to a table of at most fifty records, and the one date.
|
|
252
|
+
*/
|
|
253
|
+
export function inferListFilters(schema, table, resource = {}, tabbed = false) {
|
|
254
|
+
const state = stateColumn(table, resource);
|
|
255
|
+
const date = oneDate(table);
|
|
256
|
+
const usable = (column) => !table.filterable || table.filterable.includes(column.name);
|
|
257
|
+
const words = table.columns.filter((column) => usable(column) &&
|
|
258
|
+
!column.primaryKey &&
|
|
259
|
+
!column.references &&
|
|
260
|
+
!isConstant(column) &&
|
|
261
|
+
((column.allowed?.length ?? 0) > 1 || isFlagColumn(column)) &&
|
|
262
|
+
!(tabbed && column.name === state));
|
|
263
|
+
const references = table.columns.filter((column) => {
|
|
264
|
+
if (!usable(column) || !column.references || !namedTarget(schema, column))
|
|
265
|
+
return false;
|
|
266
|
+
const target = findTable(schema, column.references.table);
|
|
267
|
+
return target?.approxRows !== undefined && target.approxRows <= FILTER_TARGETS;
|
|
268
|
+
});
|
|
269
|
+
const dated = date && usable(columnOf(table, date)) ? [date] : [];
|
|
270
|
+
/* The state leads, where it is a filter: it is what a list is most often narrowed by. */
|
|
271
|
+
const ordered = [...words.filter((column) => column.name === state), ...references, ...words.filter((column) => column.name !== state)];
|
|
272
|
+
return [...new Set([...ordered.map((column) => column.name), ...dated])];
|
|
273
|
+
}
|
|
274
|
+
/**
|
|
275
|
+
* A board to switch the list to, where its machine has three to seven open states: a lane per state in the
|
|
276
|
+
* machine's order, the final ones together in one folded Done lane, a card of the name, what it belongs to, the date and its
|
|
277
|
+
* urgency toned. A card dropped in another lane runs the one verb that leads there (BoardList.tsx).
|
|
278
|
+
*/
|
|
279
|
+
export function inferBoard(schema, table, resource = {}) {
|
|
280
|
+
const states = inferredStates(table, resource);
|
|
281
|
+
if (!states?.machine)
|
|
282
|
+
return undefined;
|
|
283
|
+
const open = states.states.filter((state) => !state.final);
|
|
284
|
+
if (open.length < BOARD_STATES.min || open.length > BOARD_STATES.max)
|
|
285
|
+
return undefined;
|
|
286
|
+
const primary = leadColumn(schema, table, resource);
|
|
287
|
+
if (!primary || primaryKey(table).includes(primary))
|
|
288
|
+
return undefined;
|
|
289
|
+
const reference = table.columns.find((column) => column.references && column.name !== primary && !column.nullable && namedTarget(schema, column));
|
|
290
|
+
const date = oneDate(table);
|
|
291
|
+
const priority = table.columns.find((column) => PRIORITY.test(column.name) && (column.allowed?.length ?? 0) > 1);
|
|
292
|
+
const facts = [...(date ? [date] : []), ...(priority ? [priority.name] : [])];
|
|
293
|
+
return {
|
|
294
|
+
kind: 'board',
|
|
295
|
+
by: states.column,
|
|
296
|
+
primary,
|
|
297
|
+
...(reference ? { lines: [reference.name] } : {}),
|
|
298
|
+
...(facts.length ? { footer: facts.map((column) => ({ column })) } : {}),
|
|
299
|
+
lanes: open.map((state) => state.name),
|
|
300
|
+
done: states.states.filter((state) => state.final).map((state) => state.name),
|
|
301
|
+
};
|
|
302
|
+
}
|
|
303
|
+
/** How many of the App's tables point at a table: what makes it the one the others are about. */
|
|
304
|
+
const incomingCount = (schema, tableId, among) => new Set(referencesTo(schema, tableId)
|
|
305
|
+
.filter((fk) => fk.from.table !== tableId && among.has(fk.from.table))
|
|
306
|
+
.map((fk) => fk.from.table)).size;
|
|
307
|
+
/**
|
|
308
|
+
* The table an App is about, for a home it did not declare: the one with a machine that the most of its other
|
|
309
|
+
* tables point at, else the most pointed at; between two pointed at as often, the one that points at more (a job
|
|
310
|
+
* before the technician it is filed under), then the App's own order.
|
|
311
|
+
*/
|
|
312
|
+
export function mainTable(schema, tables) {
|
|
313
|
+
const among = new Set(tables.map((entry) => entry.table.id));
|
|
314
|
+
const ranked = tables
|
|
315
|
+
.map((entry, index) => ({
|
|
316
|
+
...entry,
|
|
317
|
+
index,
|
|
318
|
+
incoming: incomingCount(schema, entry.table.id, among),
|
|
319
|
+
outgoing: new Set(schema.foreignKeys.filter((fk) => fk.from.table === entry.table.id && fk.to.table !== entry.table.id).map((fk) => fk.to.table)).size,
|
|
320
|
+
}))
|
|
321
|
+
.sort((a, b) => Number(b.machine) - Number(a.machine) || b.incoming - a.incoming || b.outgoing - a.outgoing || a.index - b.index);
|
|
322
|
+
return ranked[0]?.table;
|
|
323
|
+
}
|
|
@@ -117,6 +117,9 @@ export interface AppBoardList {
|
|
|
117
117
|
/** Lane values drawn folded until a reader opens one — a closed stage, won or lost: a narrow strip with its name,
|
|
118
118
|
count and sum. The reader's choice is remembered in their browser, per board. */
|
|
119
119
|
folded?: readonly string[];
|
|
120
|
+
/** A machine's final states, drawn as one folded "Done" lane after the open ones, present only while it holds a
|
|
121
|
+
card. Set by the board a list infers (listInference.ts inferBoard), never authored (appViews.ts keys). */
|
|
122
|
+
done?: readonly string[];
|
|
120
123
|
}
|
|
121
124
|
/** One fact on a board card's foot. */
|
|
122
125
|
export interface AppBoardFact {
|
|
@@ -30,6 +30,8 @@ export interface ListQuestionSpec {
|
|
|
30
30
|
opens?: string;
|
|
31
31
|
/** The column a grid's rows are grouped by (a view's `group`): fetched, shown or not, as each row's head is read from it. */
|
|
32
32
|
group?: string;
|
|
33
|
+
/** An inferred second line under a shown column, by column (listInference.ts): fetched with the row, drawn under it. */
|
|
34
|
+
subtitles?: Readonly<Record<string, string>>;
|
|
33
35
|
}
|
|
34
36
|
/**
|
|
35
37
|
* The references among a list's columns, each with the path its record's
|
|
@@ -110,6 +110,7 @@ export function showClause(rules, spec) {
|
|
|
110
110
|
...named,
|
|
111
111
|
...(spec.order ? [spec.order] : []),
|
|
112
112
|
...subtitleColumns(rules, spec.table, [...names, ...(spec.presentation ? listSecondLineColumns(spec.presentation) : [])]),
|
|
113
|
+
...names.flatMap((name) => (spec.subtitles && Object.hasOwn(spec.subtitles, name) ? [spec.subtitles[name]] : [])),
|
|
113
114
|
...editedReferences(rules, spec),
|
|
114
115
|
...(spec.opens ? [spec.opens] : []),
|
|
115
116
|
...(spec.group ? [spec.group] : []),
|
|
@@ -9,7 +9,10 @@
|
|
|
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).
|
|
@@ -33,6 +36,19 @@ export interface AnatomyHints {
|
|
|
33
36
|
title?: (fk: ForeignKey, child: TableMeta, ambiguous: boolean) => string | undefined;
|
|
34
37
|
/** What one record of a table is called, mid-sentence ("work order"), where the caller has the word (its `noun`). */
|
|
35
38
|
noun?: (table: TableMeta) => string | undefined;
|
|
39
|
+
/** The column a shown column's second line reads (its display rule's `subtitle`), where the caller has the rule. */
|
|
40
|
+
subtitle?: (table: TableMeta, column: string) => string | undefined;
|
|
41
|
+
/** The record's fields as the App groups its form (`form.groups`, else `form.steps`, else `form.show` alone, one
|
|
42
|
+
untitled group): the inferred page's form follows them. */
|
|
43
|
+
groups?: (table: TableMeta) => ReadonlyArray<{
|
|
44
|
+
label?: string;
|
|
45
|
+
fields: readonly string[];
|
|
46
|
+
}> | undefined;
|
|
47
|
+
/** Whether a column is the one a state machine moves: its verbs set it, so the inferred form leaves it to the head. */
|
|
48
|
+
moved?: (table: TableMeta, column: string) => boolean;
|
|
49
|
+
/** What the caller calls a column (its `labels`): a reference's card is titled as its field is ("Class", not
|
|
50
|
+
"Class session"). */
|
|
51
|
+
caption?: (table: TableMeta, column: string) => string | undefined;
|
|
36
52
|
}
|
|
37
53
|
interface RelatedPick {
|
|
38
54
|
title?: string;
|
|
@@ -56,6 +72,8 @@ interface Anatomy {
|
|
|
56
72
|
status?: string;
|
|
57
73
|
/** The header's facts line: the parent, a figure, a date — at most four. */
|
|
58
74
|
facts: string[];
|
|
75
|
+
/** A fact said as a range, start → end (spanOf): the end is no fact of its own. */
|
|
76
|
+
spans?: Record<string, string>;
|
|
59
77
|
/** A summary of the record's figures: its rollups, then money the facts did not say — at most four. */
|
|
60
78
|
summary: string[];
|
|
61
79
|
/** The children, drawn as tabs: at most four lists of at most four columns. */
|
|
@@ -78,8 +96,14 @@ interface Anatomy {
|
|
|
78
96
|
export declare const isLongText: (column: string) => boolean;
|
|
79
97
|
/** A rail's worth of fields. */
|
|
80
98
|
export declare const MAX_PROPERTIES = 12;
|
|
81
|
-
/**
|
|
82
|
-
export declare function
|
|
99
|
+
/** The record's span: two dates named for its start and its end, read as one range ("Sep 13, 2:00 – 4:00 PM"). */
|
|
100
|
+
export declare function spanOf(table: TableMeta): {
|
|
101
|
+
start: string;
|
|
102
|
+
end: string;
|
|
103
|
+
} | undefined;
|
|
104
|
+
/** 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
|
|
105
|
+
most `lists` related lists: four on a scaffold's page, every one on the inferred page's tab strip. */
|
|
106
|
+
export declare function recordAnatomy(schema: DatabaseSchema, baseId: string, hints?: AnatomyHints, lists?: number): Anatomy | null;
|
|
83
107
|
/** The anatomy as a page: header, summary, the lists as tabs, and the aside's parent, current child and rail over the history. */
|
|
84
108
|
export declare function anatomySections(anatomy: Anatomy): PageSection[];
|
|
85
109
|
/** The page an App draws for a resource it declared none for (appProjection.ts, /api/pages/suggested). */
|