@mistriwork/engine 1.0.0-rc.39 → 1.0.0-rc.41
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/postgres.d.ts +3 -50
- package/dist/adapters/postgres.js +36 -232
- package/dist/adapters/postgresSql.d.ts +63 -0
- package/dist/adapters/postgresSql.js +238 -0
- package/dist/adapters/postgresTransactionHandle.d.ts +13 -1
- package/dist/adapters/postgresTransactionHandle.js +36 -0
- package/dist/adapters/postgresWriteAhead.d.ts +4 -1
- package/dist/adapters/postgresWriteAhead.js +14 -6
- package/dist/server/clientHttp.d.ts +9 -0
- package/dist/server/clientHttp.js +9 -0
- package/dist/server/devclient.d.ts +18 -0
- package/dist/server/devclient.js +44 -0
- package/dist/shared/addressParams.d.ts +6 -0
- package/dist/shared/addressParams.js +17 -0
- package/dist/shared/appLinks.d.ts +15 -3
- package/dist/shared/appLinks.js +24 -7
- package/dist/shared/computedParse.js +4 -0
- package/dist/shared/listEmpty.d.ts +4 -1
- package/dist/shared/listEmpty.js +13 -4
- package/dist/shared/listPresentations.d.ts +2 -1
- package/dist/shared/model.d.ts +9 -0
- package/dist/shared/model.js +35 -3
- package/dist/shared/page.js +12 -2
- package/dist/shared/pageAnatomy.d.ts +2 -0
- package/dist/shared/pageAnatomy.js +20 -9
- package/dist/shared/pageConfig.js +14 -6
- package/dist/shared/pageModel.d.ts +2 -0
- package/package.json +1 -1
- package/schema/model.d.ts +3 -1
package/dist/shared/listEmpty.js
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import { allowKeys, isRecord } from './model.js';
|
|
8
8
|
import { parseCaption } from './appMessages.js';
|
|
9
|
+
import { parseLinkTo } from './appLinks.js';
|
|
9
10
|
/** Read the shared empty-list copy used by list views and related sections. */
|
|
10
11
|
export function parseListEmpty(raw, at) {
|
|
11
12
|
const here = `${at}, "empty"`;
|
|
@@ -22,15 +23,23 @@ export function parseListEmpty(raw, at) {
|
|
|
22
23
|
const actionAt = `${here}, "action"`;
|
|
23
24
|
allowKeys(raw.action, ['label', 'to'], actionAt);
|
|
24
25
|
const label = parseCaption(raw.action.label, `${actionAt} needs a non-empty "label"`);
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
26
|
+
const to = typeof raw.action.to === 'string' || isRecord(raw.action.to) ? parseLinkTo(raw.action.to, `${actionAt}, "to"`) : undefined;
|
|
27
|
+
if (!to || !('view' in to))
|
|
28
|
+
throw new Error(`${actionAt} needs a "to": the key of a list, a dashboard or a signed-in form view, or { view, tab }.`);
|
|
29
|
+
return { ...result, action: { label, ...to } };
|
|
28
30
|
}
|
|
29
31
|
/** The authored shape again, for a definition written back out. */
|
|
30
32
|
export function listEmptyConfig(empty) {
|
|
31
33
|
return {
|
|
32
34
|
title: empty.title,
|
|
33
35
|
...(empty.description === undefined ? {} : { description: empty.description }),
|
|
34
|
-
...(empty.action
|
|
36
|
+
...(empty.action
|
|
37
|
+
? {
|
|
38
|
+
action: {
|
|
39
|
+
label: empty.action.label,
|
|
40
|
+
to: empty.action.tab ? { view: empty.action.view, tab: empty.action.tab } : empty.action.view,
|
|
41
|
+
},
|
|
42
|
+
}
|
|
43
|
+
: {}),
|
|
35
44
|
};
|
|
36
45
|
}
|
|
@@ -196,7 +196,8 @@ export interface AppListEmpty {
|
|
|
196
196
|
description?: string;
|
|
197
197
|
action?: {
|
|
198
198
|
label: string;
|
|
199
|
-
view: string;
|
|
199
|
+
view: string; /** The tab of a list it opens on, by its address word. */
|
|
200
|
+
tab?: string;
|
|
200
201
|
};
|
|
201
202
|
}
|
|
202
203
|
/** Whether the Export menu is offered for a table, here and not beside the payload that sets `exportableTables`, since a list's first paint asks it and appPayload.ts imports the manifest parser: `ui.export` is the App's switch, and `exportableTables` (present in an App that grants by role) the person's. */
|
package/dist/shared/model.d.ts
CHANGED
|
@@ -21,6 +21,15 @@ export declare function assertNever(value: never, what?: string): never;
|
|
|
21
21
|
* it is a near miss of, or the place it belongs (unknownKey).
|
|
22
22
|
*/
|
|
23
23
|
export declare function allowKeys(obj: Record<string, unknown>, allowed: readonly string[], at: string, refused?: Readonly<Record<string, string>>): void;
|
|
24
|
+
/**
|
|
25
|
+
* Parse with every refused key noted in `into` and passed over, not thrown. A key the location does not take is
|
|
26
|
+
* read by nothing, so the part it is in still parses and the parts that depend on that one are judged too: an App
|
|
27
|
+
* moved across a release met one kind of refused key per run — its display keys, then its page keys, then its tabs —
|
|
28
|
+
* because a resource refused for one key held back every view over it (a field report). The caller refuses the
|
|
29
|
+
* load when `into` is not empty. Outside it — a request's input, a tenant's row — a refused key is thrown at once;
|
|
30
|
+
* `undefined` puts that back for a read inside it that has to know (a lenient read that drops what does not parse).
|
|
31
|
+
*/
|
|
32
|
+
export declare function noteRefusedKeys<T>(into: string[] | undefined, parse: () => T): T;
|
|
24
33
|
export declare const setKeyHomes: (homes: (key: string) => readonly string[]) => void;
|
|
25
34
|
export declare const keyHomesOf: (key: string) => readonly string[];
|
|
26
35
|
export declare const isRecord: (value: unknown) => value is Record<string, unknown>;
|
package/dist/shared/model.js
CHANGED
|
@@ -32,9 +32,41 @@ export function allowKeys(obj, allowed, at, refused = {}) {
|
|
|
32
32
|
for (const key of Object.keys(obj)) {
|
|
33
33
|
if (allowed.includes(key) || /^[$_]/.test(key))
|
|
34
34
|
continue;
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
35
|
+
const refusal = Object.hasOwn(refused, key)
|
|
36
|
+
? `${at} has "${key}", which ${refused[key]}.`
|
|
37
|
+
: `${at} ${unknownKey(key, allowed, keyHomes(key))}.`;
|
|
38
|
+
/* A key declared ahead of its feature stops the parse: the part was written to do what is not there yet, so
|
|
39
|
+
what follows from it (an action with no write) would only be a second, misleading refusal. */
|
|
40
|
+
if (!noted || Object.hasOwn(refused, key))
|
|
41
|
+
throw new Error(refusal);
|
|
42
|
+
// A place read twice — its shape, then the whole — says a key it does not take once.
|
|
43
|
+
const said = notedAt.get(noted) ?? new Set();
|
|
44
|
+
notedAt.set(noted, said);
|
|
45
|
+
if (said.has(`${at}\0${key}`))
|
|
46
|
+
continue;
|
|
47
|
+
said.add(`${at}\0${key}`);
|
|
48
|
+
noted.push(refusal);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
const notedAt = new WeakMap();
|
|
52
|
+
/* Where a refused key is noted instead of thrown, while an App is parsed whole (noteRefusedKeys). */
|
|
53
|
+
let noted;
|
|
54
|
+
/**
|
|
55
|
+
* Parse with every refused key noted in `into` and passed over, not thrown. A key the location does not take is
|
|
56
|
+
* read by nothing, so the part it is in still parses and the parts that depend on that one are judged too: an App
|
|
57
|
+
* moved across a release met one kind of refused key per run — its display keys, then its page keys, then its tabs —
|
|
58
|
+
* because a resource refused for one key held back every view over it (a field report). The caller refuses the
|
|
59
|
+
* load when `into` is not empty. Outside it — a request's input, a tenant's row — a refused key is thrown at once;
|
|
60
|
+
* `undefined` puts that back for a read inside it that has to know (a lenient read that drops what does not parse).
|
|
61
|
+
*/
|
|
62
|
+
export function noteRefusedKeys(into, parse) {
|
|
63
|
+
const outer = noted;
|
|
64
|
+
noted = into;
|
|
65
|
+
try {
|
|
66
|
+
return parse();
|
|
67
|
+
}
|
|
68
|
+
finally {
|
|
69
|
+
noted = outer;
|
|
38
70
|
}
|
|
39
71
|
}
|
|
40
72
|
/* Where else a key is taken, for a refusal to name. app.ts sets it to the
|
package/dist/shared/page.js
CHANGED
|
@@ -853,7 +853,11 @@ export function sectionConfig(s) {
|
|
|
853
853
|
...common,
|
|
854
854
|
kind: 'headline',
|
|
855
855
|
show: s.paths ?? [],
|
|
856
|
-
...(s.actions
|
|
856
|
+
...(s.actions
|
|
857
|
+
? {
|
|
858
|
+
links: s.actions.map((a) => 'view' in a ? (({ view, tab, ...rest }) => ({ ...rest, to: tab ? { view, tab } : view }))(a) : a),
|
|
859
|
+
}
|
|
860
|
+
: {}),
|
|
857
861
|
...(s.subfigure !== undefined ? { subfigure: s.subfigure } : {}),
|
|
858
862
|
...(s.subtitle !== undefined ? { subtitle: s.subtitle } : {}),
|
|
859
863
|
...(s.was !== undefined ? { was: s.was } : {}),
|
|
@@ -1026,7 +1030,13 @@ export function sectionConfig(s) {
|
|
|
1026
1030
|
kind: s.kind,
|
|
1027
1031
|
text: s.text,
|
|
1028
1032
|
...(s.variant ? { variant: s.variant } : {}),
|
|
1029
|
-
...(s.action
|
|
1033
|
+
...(s.action
|
|
1034
|
+
? {
|
|
1035
|
+
action: 'view' in s.action
|
|
1036
|
+
? { label: s.action.label, to: s.action.tab ? { view: s.action.view, tab: s.action.tab } : s.action.view }
|
|
1037
|
+
: s.action,
|
|
1038
|
+
}
|
|
1039
|
+
: {}),
|
|
1030
1040
|
};
|
|
1031
1041
|
case 'custom':
|
|
1032
1042
|
return {
|
|
@@ -120,4 +120,6 @@ export declare function anatomyPage(schema: DatabaseSchema, baseId: string, hint
|
|
|
120
120
|
* no aside.
|
|
121
121
|
*/
|
|
122
122
|
export declare function withDefaultAside(schema: DatabaseSchema, page: PageDef): PageDef;
|
|
123
|
+
/** The fields a page's default aside draws, or why it draws none: the rule `withDefaultAside` follows, as `mistri check --defaults` says it. */
|
|
124
|
+
export declare function defaultAsidePaths(schema: DatabaseSchema, page: PageDef): string[] | string;
|
|
123
125
|
export {};
|
|
@@ -521,11 +521,27 @@ export function anatomyPage(schema, baseId, hints = {}) {
|
|
|
521
521
|
export function withDefaultAside(schema, page) {
|
|
522
522
|
if (!page.defaultAside || page.aside === false || page.error || page.document)
|
|
523
523
|
return page;
|
|
524
|
-
|
|
524
|
+
const paths = defaultAsidePaths(schema, page);
|
|
525
|
+
if (typeof paths === 'string')
|
|
525
526
|
return page;
|
|
527
|
+
return {
|
|
528
|
+
...page,
|
|
529
|
+
sections: [...page.sections, { kind: 'fields', title: page.name, presentation: 'properties', region: 'aside', paths }],
|
|
530
|
+
};
|
|
531
|
+
}
|
|
532
|
+
/** The fields a page's default aside draws, or why it draws none: the rule `withDefaultAside` follows, as `mistri check --defaults` says it. */
|
|
533
|
+
export function defaultAsidePaths(schema, page) {
|
|
534
|
+
if (page.aside === false)
|
|
535
|
+
return 'none: the page says aside: false';
|
|
536
|
+
if (page.document)
|
|
537
|
+
return 'none: a document has no aside';
|
|
538
|
+
if (!page.defaultAside)
|
|
539
|
+
return `none: the '${page.layout ?? 'record'}' layout has no default aside`;
|
|
540
|
+
if (page.sections.some((section) => section.region === 'aside'))
|
|
541
|
+
return 'none: the page writes its own aside';
|
|
526
542
|
const base = findTable(schema, page.base);
|
|
527
543
|
if (!base)
|
|
528
|
-
return page;
|
|
544
|
+
return 'none: the page names no table';
|
|
529
545
|
const shown = new Set();
|
|
530
546
|
for (const section of page.sections) {
|
|
531
547
|
if (section.kind === 'custom')
|
|
@@ -533,7 +549,7 @@ export function withDefaultAside(schema, page) {
|
|
|
533
549
|
if (section.kind !== 'fields')
|
|
534
550
|
continue;
|
|
535
551
|
if (!section.paths?.length && section.presentation !== 'header')
|
|
536
|
-
return
|
|
552
|
+
return 'none: a fields section with no paths shows the whole record';
|
|
537
553
|
section.paths?.forEach((path) => shown.add(path.split('.')[0]));
|
|
538
554
|
if (section.status)
|
|
539
555
|
shown.add(section.status);
|
|
@@ -544,10 +560,5 @@ export function withDefaultAside(schema, page) {
|
|
|
544
560
|
}
|
|
545
561
|
const name = labelColumn(base);
|
|
546
562
|
const paths = railOf(base.columns.filter((column) => readable(base, column) && column.name !== name && !shown.has(column.name)));
|
|
547
|
-
|
|
548
|
-
return page;
|
|
549
|
-
return {
|
|
550
|
-
...page,
|
|
551
|
-
sections: [...page.sections, { kind: 'fields', title: page.name, presentation: 'properties', region: 'aside', paths }],
|
|
552
|
-
};
|
|
563
|
+
return paths.length ? paths : 'none: the sections already show every field';
|
|
553
564
|
}
|
|
@@ -9,13 +9,13 @@ import { parseRelatedCreate } from './relatedCreate.js';
|
|
|
9
9
|
import { parseListEmpty } from './listEmpty.js';
|
|
10
10
|
import { CHART_SHAPES, FIGURE_FORMATS, FIGURE_FORMAT_WORDS, allowKeys, humanName } from './model.js';
|
|
11
11
|
import { headingOf } from './appNoun.js';
|
|
12
|
-
import { CARDS_MAX_LINES, HEADER_MAX_FACTS, parseCards, parseFacts } from './appCards.js';
|
|
12
|
+
import { CARDS_MAX_LINES, HEADER_FACTS_SHOWN, HEADER_MAX_FACTS, parseCards, parseFacts } from './appCards.js';
|
|
13
13
|
import { parseIcon } from './appIcons.js';
|
|
14
14
|
import { slug } from './slug.js';
|
|
15
15
|
import { parsePageLayout } from './pageLayouts.js';
|
|
16
16
|
import { parseSortText } from './sortText.js';
|
|
17
17
|
import { componentPropValues, parseComponentDecl, parsePageReads, parsePageTotals, parseRecordFields } from './appComponents.js';
|
|
18
|
-
import { parseAppLinkAction, parseAppTarget } from './appLinks.js';
|
|
18
|
+
import { parseAppLinkAction, parseAppTarget, parseLinkTo } from './appLinks.js';
|
|
19
19
|
import { WIDTHS, OFFSETS, SECTION_REGIONS, FIELD_COLUMNS, MAX_STREAMS, MAX_HISTORY_LIMIT, MAX_SECTIONS, MAX_PAGE_SECTIONS, screenSections, GROUPS_MOST, GROUP_ROWS_MOST, } from './pageModel.js';
|
|
20
20
|
/* ---------- config ---------- */
|
|
21
21
|
/**
|
|
@@ -1097,6 +1097,11 @@ function parseHeader(s, at) {
|
|
|
1097
1097
|
if (['status', 'facts', 'primary', 'destructive', 'actions'].every((key) => s[key] === undefined)) {
|
|
1098
1098
|
throw new Error(`${at}: a record header says something: a "status", "facts", its "primary" verb, its "destructive" ones or the "actions" it draws.`);
|
|
1099
1099
|
}
|
|
1100
|
+
/* The limit said with the rule behind it: a field report met "one to 12" and could not tell what the line holds. */
|
|
1101
|
+
if (Array.isArray(s.facts) && s.facts.length > HEADER_MAX_FACTS) {
|
|
1102
|
+
throw new Error(`${at}, header: "facts" names ${s.facts.length}, and a header says at most ${HEADER_MAX_FACTS}: the first ${HEADER_FACTS_SHOWN} in the line under the name, the rest in its More. ` +
|
|
1103
|
+
`Keep the ${HEADER_MAX_FACTS} a reader looks for first and show the others in fields([...]).`);
|
|
1104
|
+
}
|
|
1100
1105
|
const facts = s.facts === undefined ? undefined : parseFacts(s.facts, `${at}, header`, 'facts', HEADER_MAX_FACTS);
|
|
1101
1106
|
return {
|
|
1102
1107
|
kind: 'fields',
|
|
@@ -1318,7 +1323,8 @@ function parseHeadlineActions(raw, at) {
|
|
|
1318
1323
|
if (!entry || typeof entry !== 'object' || Array.isArray(entry))
|
|
1319
1324
|
throw new Error(`${here} is not an object { label, to }.`);
|
|
1320
1325
|
const a = entry;
|
|
1321
|
-
|
|
1326
|
+
const appLink = !!a.to && typeof a.to === 'object' && (Object.hasOwn(a.to, 'app') || Object.hasOwn(a.to, 'kind'));
|
|
1327
|
+
if (appLink) {
|
|
1322
1328
|
allowKeys(a, ['label', 'to', 'intent'], here, INTENT_RENAMED);
|
|
1323
1329
|
if (typeof a.label !== 'string' || !a.label.trim() || a.label.trim().length > 60)
|
|
1324
1330
|
throw new Error(`${here} needs a "label" of at most 60 characters.`);
|
|
@@ -1333,8 +1339,9 @@ function parseHeadlineActions(raw, at) {
|
|
|
1333
1339
|
allowKeys(a, ['label', 'to', 'intent', 'prefill', 'defaults', 'open'], here, INTENT_RENAMED);
|
|
1334
1340
|
if (typeof a.label !== 'string' || !a.label.trim() || a.label.trim().length > 60)
|
|
1335
1341
|
throw new Error(`${here} needs a "label" of at most 60 characters.`);
|
|
1336
|
-
|
|
1337
|
-
|
|
1342
|
+
const to = typeof a.to === 'string' || (a.to && typeof a.to === 'object') ? parseLinkTo(a.to, `${here}, "to"`) : undefined;
|
|
1343
|
+
if (!to || !('view' in to) || !/^[a-z0-9][a-z0-9-]{0,63}$/.test(to.view))
|
|
1344
|
+
throw new Error(`${here} needs a "to": the key of one of the App's views, { view, tab }, or an appLink().`);
|
|
1338
1345
|
if (a.intent !== undefined && a.intent !== 'primary' && a.intent !== 'secondary')
|
|
1339
1346
|
throw new Error(`${here} has an "intent" of "${String(a.intent)}". Use "primary" or "secondary".`);
|
|
1340
1347
|
/* A public form over the record, rather than a page of its own. Only
|
|
@@ -1364,7 +1371,8 @@ function parseHeadlineActions(raw, at) {
|
|
|
1364
1371
|
const defaults = inputs(a.defaults, 'defaults');
|
|
1365
1372
|
return {
|
|
1366
1373
|
label: a.label.trim(),
|
|
1367
|
-
view:
|
|
1374
|
+
view: to.view,
|
|
1375
|
+
...(to.tab === undefined ? {} : { tab: to.tab }),
|
|
1368
1376
|
...(a.intent === undefined ? {} : { intent: a.intent }),
|
|
1369
1377
|
...(prefill ? { prefill } : {}),
|
|
1370
1378
|
...(defaults ? { defaults } : {}),
|
|
@@ -141,6 +141,8 @@ export type PageHeadlineAction = {
|
|
|
141
141
|
} | {
|
|
142
142
|
label: string;
|
|
143
143
|
view: string;
|
|
144
|
+
/** The tab of a list it opens on, by its address word (`to: { view, tab }`). */
|
|
145
|
+
tab?: string;
|
|
144
146
|
intent?: 'primary' | 'secondary';
|
|
145
147
|
prefill?: Record<string, string>;
|
|
146
148
|
defaults?: Record<string, string>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mistriwork/engine",
|
|
3
|
-
"version": "1.0.0-rc.
|
|
3
|
+
"version": "1.0.0-rc.41",
|
|
4
4
|
"description": "The engine both products stand on: the adapters (SQLite, Postgres), the catalog, the query language, keyset pages, the HTTP kit and the shared rules. No React.",
|
|
5
5
|
"homepage": "https://mistriwork.dev",
|
|
6
6
|
"bugs": {
|
package/schema/model.d.ts
CHANGED
|
@@ -41,7 +41,9 @@ export interface AppHomeTarget<Value> extends AppTargetBase<Value> { kind: 'home
|
|
|
41
41
|
export interface AppViewTarget<Value> extends AppTargetBase<Value> { kind: 'view'; view: string; resource?: never; key?: never }
|
|
42
42
|
export interface AppRecordTarget<Value> extends AppTargetBase<Value> { kind: 'record'; resource: string; key: Readonly<Record<string, Value>>; view?: never }
|
|
43
43
|
export type AppTarget<Value = AppLinkValue> = AppHomeTarget<Value> | AppViewTarget<Value> | AppRecordTarget<Value>;
|
|
44
|
-
|
|
44
|
+
/** One of this App's views by key, or a list on one of its tabs, named by the tab's address word (`?tab=`): `{ view: 'leads', tab: 'working' }`. */
|
|
45
|
+
export type ViewTo = string | { view: string; tab?: string };
|
|
46
|
+
export type AppLinkAction = { label: string | AppMessageRef; to: AppTarget | ViewTo };
|
|
45
47
|
/** A checked destination on a surface with no source row (nav or App switcher). */
|
|
46
48
|
export type StaticAppTarget = AppTarget<string | number>;
|
|
47
49
|
|