@mistriwork/engine 1.0.0-rc.28 → 1.0.0-rc.30
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.
|
@@ -20,6 +20,7 @@
|
|
|
20
20
|
*/
|
|
21
21
|
import type { ServerResponse } from 'node:http';
|
|
22
22
|
import { type PageDef } from '../../shared/page.js';
|
|
23
|
+
import { type ReadAsk } from '../../shared/recordReads.js';
|
|
23
24
|
import type { RequestContext, ResolvedSource } from './context.js';
|
|
24
25
|
export declare const COMPOSE_PATH = "/api/pages/compose";
|
|
25
26
|
/** The resources of the App a page is drawn in, as far as composing its reads needs them. */
|
|
@@ -54,6 +55,10 @@ export interface ComposeHooks {
|
|
|
54
55
|
resources(ctx: RequestContext, source: ResolvedSource): ComposeResources;
|
|
55
56
|
/** A table's suggested page (`suggested:<table>`). */
|
|
56
57
|
suggested(source: ResolvedSource, table: string): PageDef | null;
|
|
58
|
+
/** An error that refuses the whole page rather than leaving the part out (a read the audit could not record). */
|
|
59
|
+
fatal?(error: unknown): boolean;
|
|
60
|
+
/** Runs a part's read as the door its `kind` names (a related list's), for a read audit; where none is kept, as it is. */
|
|
61
|
+
asking?<T>(path: string, kind: ReadAsk['kind'], work: () => T): T;
|
|
57
62
|
/** Which of the record's commands are available to this reader: the availability route's answer, or none. */
|
|
58
63
|
availability?(ctx: RequestContext, checks: CommandCheck[]): Promise<{
|
|
59
64
|
status: number;
|
|
@@ -36,14 +36,17 @@ export async function composeRecordPage({ ctx, source, body, post, hooks, }) {
|
|
|
36
36
|
/* A part asked on the page's behalf: through the route its section's own
|
|
37
37
|
request reaches, answered into memory. What that route would refuse, or
|
|
38
38
|
throw, leaves the part out. */
|
|
39
|
-
const ask = async (path, given) => {
|
|
39
|
+
const ask = async (path, given, kind) => {
|
|
40
40
|
if (!hooks.mayAsk(ctx, path))
|
|
41
41
|
return undefined;
|
|
42
42
|
const reply = new CapturedReply();
|
|
43
43
|
try {
|
|
44
|
-
|
|
44
|
+
const posting = () => post(reply.asResponse(), path, given);
|
|
45
|
+
await (hooks.asking ? hooks.asking(path, kind, posting) : posting());
|
|
45
46
|
}
|
|
46
|
-
catch {
|
|
47
|
+
catch (error) {
|
|
48
|
+
if (hooks.fatal?.(error))
|
|
49
|
+
throw error;
|
|
47
50
|
return undefined;
|
|
48
51
|
}
|
|
49
52
|
return reply.answer();
|
|
@@ -67,7 +70,7 @@ export async function composeRecordPage({ ctx, source, body, post, hooks, }) {
|
|
|
67
70
|
const answered = [];
|
|
68
71
|
const keep = (asked, answer) => {
|
|
69
72
|
if (!failed(answer))
|
|
70
|
-
answered.push({
|
|
73
|
+
answered.push({ path: asked.path, body: asked.body, status: answer.status, reply: answer.body });
|
|
71
74
|
};
|
|
72
75
|
const { row, parts, reads } = recordPageReads(names, page, base, plans, record, options);
|
|
73
76
|
/* The record's fixed edits ask their `when` of the row, as a section does. */
|
|
@@ -100,7 +103,7 @@ export async function composeRecordPage({ ctx, source, body, post, hooks, }) {
|
|
|
100
103
|
/* The page's own row first, its verbs last: they are advice, and wait behind what is shown. */
|
|
101
104
|
const done = Promise.all([
|
|
102
105
|
whole(),
|
|
103
|
-
...reads.map(async (asked) => keep(asked, await (begun.get(readKey(asked)) ?? ask(asked.path, asked.body)))),
|
|
106
|
+
...reads.map(async (asked) => keep(asked, await (begun.get(readKey(asked)) ?? ask(asked.path, asked.body, asked.kind)))),
|
|
104
107
|
availability(),
|
|
105
108
|
]);
|
|
106
109
|
return { reads: new Set(reads.map((asked) => readKey(asked))), done: done.then(() => answered) };
|
|
@@ -113,10 +116,14 @@ export async function composeRecordPage({ ctx, source, body, post, hooks, }) {
|
|
|
113
116
|
const history = expected && expectedBase
|
|
114
117
|
? recordPageReads(names, expected, expectedBase, [], record, options)
|
|
115
118
|
.reads.filter((asked) => asked.path === '/api/record-history')
|
|
116
|
-
.map((asked) => [asked, ask(asked.path, asked.body)])
|
|
119
|
+
.map((asked) => [asked, ask(asked.path, asked.body, asked.kind)])
|
|
117
120
|
: [];
|
|
118
121
|
const planning = ask('/api/pages/plan', { page: body.page, key });
|
|
119
122
|
const early = expected && expectedBase ? reading(expected, expectedBase, [], history) : undefined;
|
|
123
|
+
/* A part that refuses the page ends it where it is awaited; what was started beside it settles unobserved otherwise. */
|
|
124
|
+
for (const [, started] of history)
|
|
125
|
+
started.catch(() => { });
|
|
126
|
+
early?.done.catch(() => { });
|
|
120
127
|
const plan = await planning;
|
|
121
128
|
const planned = failed(plan) ? undefined : plan.body;
|
|
122
129
|
const base = planned && findTable(source.schema, planned.page.base);
|
|
@@ -136,10 +143,10 @@ export async function composeRecordPage({ ctx, source, body, post, hooks, }) {
|
|
|
136
143
|
/* Only what the plan adds: its lists, figures, timelines and custom reads. */
|
|
137
144
|
const { reads } = recordPageReads(names, planned.page, base, planned.plans, record, options);
|
|
138
145
|
const later = reads.filter((asked) => !kept.reads.has(readKey(asked)));
|
|
139
|
-
const more = await Promise.all(later.map(async (asked) => ({ asked, answer: await ask(asked.path, asked.body) })));
|
|
146
|
+
const more = await Promise.all(later.map(async (asked) => ({ asked, answer: await ask(asked.path, asked.body, asked.kind) })));
|
|
140
147
|
answered = [
|
|
141
148
|
...(await kept.done),
|
|
142
|
-
...more.flatMap(({ asked, answer }) =>
|
|
149
|
+
...more.flatMap(({ asked, answer }) => failed(answer) ? [] : [{ path: asked.path, body: asked.body, status: answer.status, reply: answer.body }]),
|
|
143
150
|
];
|
|
144
151
|
}
|
|
145
152
|
else
|
|
@@ -123,6 +123,8 @@ export declare function timelineReads<V extends ReadView>(names: {
|
|
|
123
123
|
export interface ReadAsk {
|
|
124
124
|
readonly path: string;
|
|
125
125
|
readonly body: Record<string, unknown>;
|
|
126
|
+
/** What the read is where it is not a page's own: a related list's (the `x-mistri-read` a list asking alone would carry), so a read audit says so. */
|
|
127
|
+
readonly kind?: 'related';
|
|
126
128
|
}
|
|
127
129
|
/**
|
|
128
130
|
* The fields a section shows when it names none. In the Workbench, every
|
|
@@ -368,11 +368,14 @@ export function recordPageReads(names, page, base, plans, key, options) {
|
|
|
368
368
|
const parts = [{ part: 'root', columns: probeColumns(names, base) }];
|
|
369
369
|
const reads = [];
|
|
370
370
|
const planOf = (index) => plans.find((plan) => plan.index === index);
|
|
371
|
-
|
|
372
|
-
|
|
371
|
+
/* A list section is a related list: what it asks, it asks as one (a read audit names the door `related`). */
|
|
372
|
+
let kind;
|
|
373
|
+
const view = (body) => reads.push({ path: '/api/view/run', body, ...(kind && { kind }) });
|
|
374
|
+
const breakdown = (def) => reads.push({ path: '/api/breakdown', body: { def }, ...(kind && { kind }) });
|
|
373
375
|
page.sections.forEach((section, index) => {
|
|
374
376
|
if (section.hidden || !drawn.has(index))
|
|
375
377
|
return;
|
|
378
|
+
kind = section.kind === 'list' ? 'related' : undefined;
|
|
376
379
|
if (section.when)
|
|
377
380
|
reads.push({ path: '/api/run', body: whenBody(base, key, section.when) });
|
|
378
381
|
const plan = planOf(index);
|
|
@@ -435,7 +438,7 @@ export function recordPageReads(names, page, base, plans, key, options) {
|
|
|
435
438
|
case 'list': {
|
|
436
439
|
/* A grouped list asks its groups first; each group's rows are asked of the keys that come back. */
|
|
437
440
|
if (section.group && plan.groups) {
|
|
438
|
-
reads.push({ path: '/api/breakdown', body: groupsBody(plan.groups, 0) });
|
|
441
|
+
reads.push({ path: '/api/breakdown', body: groupsBody(plan.groups, 0), kind: 'related' });
|
|
439
442
|
if (plan.totals)
|
|
440
443
|
breakdown(plan.totals);
|
|
441
444
|
return;
|
|
@@ -456,7 +459,7 @@ export function recordPageReads(names, page, base, plans, key, options) {
|
|
|
456
459
|
for (const run of runs) {
|
|
457
460
|
const body = relatedCountsBody(names.schema, run.map((index) => page.sections[index]), base, key);
|
|
458
461
|
if (body)
|
|
459
|
-
reads.push({ path: '/api/counts', body });
|
|
462
|
+
reads.push({ path: '/api/counts', body, kind: 'related' });
|
|
460
463
|
}
|
|
461
464
|
return { row: [...new Set(parts.flatMap((part) => part.columns))], parts, reads };
|
|
462
465
|
}
|
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.30",
|
|
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": {
|