@mistriwork/engine 1.0.0-rc.81 → 1.0.0-rc.82
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.
|
@@ -246,8 +246,9 @@ export function withHead(html, head) {
|
|
|
246
246
|
beforeScripts('<meta name="mistri-shell" content="workbench">');
|
|
247
247
|
if (head.scheme)
|
|
248
248
|
beforeScripts(`<meta name="mistri-scheme" content="${escapeHtml(head.scheme)}">`);
|
|
249
|
+
/* Before the scripts too: the first one keys its cached startup colours by the look these grounds say. */
|
|
249
250
|
if (head.grounds)
|
|
250
|
-
|
|
251
|
+
beforeScripts(groundsMeta(head.grounds).replace(/\n /g, '\n '));
|
|
251
252
|
if (head.observe)
|
|
252
253
|
out = out.replace(/<\/head>/i, () => ` <meta name="mistri-observe" content="${escapeHtml(head.observe)}">\n </head>`);
|
|
253
254
|
if (head.density)
|
|
@@ -64,7 +64,7 @@ export async function exportFile(asked) {
|
|
|
64
64
|
const amountsOf = (tableId) => asked.amounts?.(tableId);
|
|
65
65
|
/* An App that grants by role says who exports which table (appExportable); the file is refused where the Export menu is not offered. */
|
|
66
66
|
if (!may('')) {
|
|
67
|
-
answer(403,
|
|
67
|
+
answer(403, refusal('forbidden', ['Export is not available to this person.']));
|
|
68
68
|
return undefined;
|
|
69
69
|
}
|
|
70
70
|
/* Counted until the response closes, whichever way it ends: a refusal, the file, or a client that left. */
|
|
@@ -84,11 +84,11 @@ export async function exportFile(asked) {
|
|
|
84
84
|
});
|
|
85
85
|
const format = body.format ?? 'csv';
|
|
86
86
|
if (typeof format !== 'string' || !Object.hasOwn(FORMATS, format)) {
|
|
87
|
-
answer(400,
|
|
87
|
+
answer(400, refusal('invalid_request', ['format must be "csv", "json" or "ndjson".']));
|
|
88
88
|
return undefined;
|
|
89
89
|
}
|
|
90
90
|
if (body.columns !== undefined && (!Array.isArray(body.columns) || body.columns.some((column) => typeof column !== 'string'))) {
|
|
91
|
-
answer(400,
|
|
91
|
+
answer(400, refusal('invalid_request', ['columns must be a list of column names.']));
|
|
92
92
|
return undefined;
|
|
93
93
|
}
|
|
94
94
|
const text = String(body.q ?? '');
|
|
@@ -133,13 +133,16 @@ export async function exportFile(asked) {
|
|
|
133
133
|
found — the same answer whether it exists or not, so a refusal tells nothing — and any other question that cannot
|
|
134
134
|
be read is a bad request. Either way `errors` says why, as `/api/run`'s does. */
|
|
135
135
|
if (!parsed.query || parsed.errors.length) {
|
|
136
|
-
|
|
136
|
+
const code = servesTable(schema, text) ? 'invalid_request' : 'not_found';
|
|
137
|
+
/* Each error keeps where it is in the question (`at`), which the query bar underlines. */
|
|
138
|
+
const said = refusal(code, parsed.errors.map((error) => error.message));
|
|
139
|
+
answer(code === 'not_found' ? 404 : 400, { ...said, errors: parsed.errors.map((error) => ({ code, ...error })) });
|
|
137
140
|
return undefined;
|
|
138
141
|
}
|
|
139
142
|
const query = parsed.query;
|
|
140
143
|
const table = findTable(schema, query.table);
|
|
141
144
|
if (!table) {
|
|
142
|
-
answer(404,
|
|
145
|
+
answer(404, refusal('not_found', [`Unknown table "${query.table}"`]));
|
|
143
146
|
return undefined;
|
|
144
147
|
}
|
|
145
148
|
if (!may(table.id))
|
|
@@ -181,11 +184,17 @@ function servesTable(schema, text) {
|
|
|
181
184
|
return !first || findTable(schema, first) !== undefined || schema.tables.some((table) => table.name === first);
|
|
182
185
|
}
|
|
183
186
|
function refuseTable(answer, tableId) {
|
|
184
|
-
answer(403, {
|
|
185
|
-
error: `Export of "${tableId}" is not available to this person.`,
|
|
186
|
-
});
|
|
187
|
+
answer(403, refusal('forbidden', [`Export of "${tableId}" is not available to this person.`]));
|
|
187
188
|
return undefined;
|
|
188
189
|
}
|
|
190
|
+
/**
|
|
191
|
+
* A reply that is not the file, in the body the App API's other refusals use: a snake_case `code` a program branches
|
|
192
|
+
* on, `error` for a client that reads one sentence, and `errors` for the Export menu, which shows the first. A field
|
|
193
|
+
* report read a refusal's body for its code and found none, and took the status alone for the reason.
|
|
194
|
+
*/
|
|
195
|
+
function refusal(code, messages) {
|
|
196
|
+
return { code, error: messages[0] ?? '', errors: messages.map((message) => ({ code, message })) };
|
|
197
|
+
}
|
|
189
198
|
/** Stands for a table a view reaches that cannot be named (a many-valued condition it cannot resolve): never exportable. */
|
|
190
199
|
const UNKNOWN_TABLE = '\u0000unknown';
|
|
191
200
|
/** Every table a view reads from: its base, each table along a reference path in its columns, filter and order, and the rows its aggregates and `any` conditions read. */
|
|
@@ -33,6 +33,15 @@ export function toleratesLag(path, body) {
|
|
|
33
33
|
if (!LAG_TOLERANT.has(path))
|
|
34
34
|
return false;
|
|
35
35
|
const view = body.view && typeof body.view === 'object' ? body.view : undefined;
|
|
36
|
+
/* A batch carries a free-form page's views (`items[].view`): one that asks for one row goes where it would alone. */
|
|
37
|
+
if (path === '/api/breakdowns' && Array.isArray(body.items)) {
|
|
38
|
+
const one = body.items.some((item) => {
|
|
39
|
+
const asked = item && typeof item === 'object' ? item.view : undefined;
|
|
40
|
+
return !!asked && typeof asked === 'object' && !toleratesLag('/api/view/run', asked);
|
|
41
|
+
});
|
|
42
|
+
if (one)
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
36
45
|
return body.limit !== 1 && view?.limit !== 1;
|
|
37
46
|
}
|
|
38
47
|
/** The cookie a write sets so the same browser's next reads go to the primary, in the running product's name. */
|
|
@@ -42,6 +42,8 @@ function plainCount(schema, view) {
|
|
|
42
42
|
}
|
|
43
43
|
/* What a batched list's page may say: what `/api/run` reads of a first page. */
|
|
44
44
|
const RUN_FIELDS = ['q', 'limit', 'offset', 'count', 'exactCount', 'countLimit', 'lanes'];
|
|
45
|
+
/* What a batched view may say: what `/api/view/run` reads. */
|
|
46
|
+
const VIEW_FIELDS = ['view', 'text', 'query', 'where', 'count', 'limit', 'offset'];
|
|
45
47
|
/** The most rows a lanes read keeps per lane: a board's page, a few times over. */
|
|
46
48
|
const LANE_MOST = 100;
|
|
47
49
|
/** A run's `lanes`, read: absent, refused, or the column and how many of each. */
|
|
@@ -351,6 +353,14 @@ export async function dispatchResourceReadHttp(path, body, adapter, schema, opti
|
|
|
351
353
|
if (items.some((item) => 'run' in item && !run(item))) {
|
|
352
354
|
return refusal(400, ['A batched list is `run: { q, limit, offset, count, exactCount, countLimit }`.']);
|
|
353
355
|
}
|
|
356
|
+
/* A free-form page's reads ride the same way (the ui-sdk host's useRows, its record, its choices): an item
|
|
357
|
+
that is `view` is answered as `/api/view/run` answers it, from the view-run fields alone. Nineteen lists
|
|
358
|
+
on one page were nineteen requests, each its own admission and its own person looked up. */
|
|
359
|
+
const viewed = (item) => item.view && typeof item.view === 'object' && !Array.isArray(item.view) ? item.view : undefined;
|
|
360
|
+
if (items.some((item) => 'view' in item && !viewed(item))) {
|
|
361
|
+
return refusal(400, ['A batched view is `view: { view, text, query, where, count, limit, offset }`.']);
|
|
362
|
+
}
|
|
363
|
+
const only = (asked, fields) => Object.fromEntries(fields.filter((field) => asked[field] !== undefined).map((field) => [field, asked[field]]));
|
|
354
364
|
const results = Array.from({ length: items.length });
|
|
355
365
|
const queue = items.map((item, at) => ({ item, at }));
|
|
356
366
|
/* An item's route knows its own last wave, not the batch's: the others are
|
|
@@ -361,11 +371,14 @@ export async function dispatchResourceReadHttp(path, body, adapter, schema, opti
|
|
|
361
371
|
const one = async () => {
|
|
362
372
|
for (let next = queue.shift(); next; next = queue.shift()) {
|
|
363
373
|
const page = run(next.item);
|
|
374
|
+
const view = viewed(next.item);
|
|
364
375
|
const { def, text, limit, offset } = next.item;
|
|
365
376
|
try {
|
|
366
377
|
results[next.at] = (await (page
|
|
367
|
-
? dispatchResourceReadHttp('/api/run',
|
|
368
|
-
:
|
|
378
|
+
? dispatchResourceReadHttp('/api/run', only(page, RUN_FIELDS), adapter, schema, each)
|
|
379
|
+
: view
|
|
380
|
+
? dispatchResourceReadHttp('/api/view/run', only(view, VIEW_FIELDS), adapter, schema, each)
|
|
381
|
+
: dispatchResourceReadHttp('/api/breakdown', { def, text, limit, offset }, adapter, schema, each)));
|
|
369
382
|
}
|
|
370
383
|
catch (error) {
|
|
371
384
|
/* A request's own refusal (a ResourceReadError: the provider's are
|
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.82",
|
|
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": {
|