@mistriwork/engine 1.0.0-rc.67 → 1.0.0-rc.68
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/server/http/pageRoutes.js +5 -1
- package/dist/shared/appComponents.d.ts +5 -1
- package/dist/shared/appComponents.js +17 -3
- package/dist/shared/dashLayout.js +0 -3
- package/dist/shared/pagePaths.d.ts +1 -1
- package/dist/shared/pagePaths.js +20 -1
- package/dist/shared/pagePlans.js +4 -1
- package/package.json +1 -1
- package/schema/model.d.ts +3 -1
|
@@ -163,7 +163,11 @@ export async function pageRoutes(post, hooks) {
|
|
|
163
163
|
Read through the same scoped adapter, so a value the reader may not
|
|
164
164
|
read is refused like any other read of it. */
|
|
165
165
|
const likeColumns = [
|
|
166
|
-
...new Set(page.sections.flatMap((s) =>
|
|
166
|
+
...new Set(page.sections.flatMap((s) => s.kind === 'list' && s.similar
|
|
167
|
+
? [...s.similar.same, ...Object.keys(s.similar.near ?? {})]
|
|
168
|
+
: s.kind === 'custom'
|
|
169
|
+
? Object.values(s.reads ?? {}).flatMap((read) => read.similar?.same ?? [])
|
|
170
|
+
: [])),
|
|
167
171
|
];
|
|
168
172
|
let rootValues;
|
|
169
173
|
if (likeColumns.length) {
|
|
@@ -41,7 +41,7 @@ export declare const MAX_CUSTOM_READS = 8;
|
|
|
41
41
|
*/
|
|
42
42
|
export declare const MAX_CUSTOM_FIGURES = 8;
|
|
43
43
|
/** The keys a declared read of rows takes, on a page and on a dashboard. */
|
|
44
|
-
export declare const PAGE_READ_KEYS: readonly ['from', 'whose', 'query', 'show', 'sort', 'limit'];
|
|
44
|
+
export declare const PAGE_READ_KEYS: readonly ['from', 'whose', 'same', 'query', 'show', 'sort', 'limit'];
|
|
45
45
|
export declare const DASH_READ_KEYS: readonly ['from', 'query', 'show', 'sort', 'limit', 'over'];
|
|
46
46
|
/**
|
|
47
47
|
* What a total measures: the breakdown grammar's aggregates over one column of the resource (count takes none, and
|
|
@@ -69,6 +69,10 @@ export interface PageCustomRead {
|
|
|
69
69
|
from: string;
|
|
70
70
|
/** Config `whose`: the path from `from` back to the page's record. Absent, the rows are not tied to it. */
|
|
71
71
|
path?: string;
|
|
72
|
+
/** Config `same`: the rows that share these columns' values with the record (as a related list's `same`), the record left out. */
|
|
73
|
+
similar?: {
|
|
74
|
+
same: string[];
|
|
75
|
+
};
|
|
72
76
|
filter?: string;
|
|
73
77
|
columns: string[];
|
|
74
78
|
/** Query-bar text, as authored; `orderBy` is what the planner runs. */
|
|
@@ -46,7 +46,7 @@ const MAX_CUSTOM_LIST_SHOW = 32;
|
|
|
46
46
|
*/
|
|
47
47
|
export const MAX_CUSTOM_FIGURES = 8;
|
|
48
48
|
/** The keys a declared read of rows takes, on a page and on a dashboard. */
|
|
49
|
-
export const PAGE_READ_KEYS = ['from', 'whose', 'query', 'show', 'sort', 'limit'];
|
|
49
|
+
export const PAGE_READ_KEYS = ['from', 'whose', 'same', 'query', 'show', 'sort', 'limit'];
|
|
50
50
|
export const DASH_READ_KEYS = ['from', 'query', 'show', 'sort', 'limit', 'over'];
|
|
51
51
|
/** The keys a declared aggregate read takes, on a page and on a dashboard. */
|
|
52
52
|
const PAGE_TOTAL_KEYS = ['from', 'measure', 'by', 'whose', 'query', 'limit'];
|
|
@@ -245,9 +245,23 @@ function reads(raw, at, one, { key = 'rows', most = MAX_CUSTOM_READS, noun = 're
|
|
|
245
245
|
export function parsePageReads(raw, at) {
|
|
246
246
|
return reads(raw, at, (entry, here) => {
|
|
247
247
|
const r = readShape(entry, here, PAGE_READ_KEYS);
|
|
248
|
+
let similar;
|
|
249
|
+
if (r.same !== undefined) {
|
|
250
|
+
if (r.whose !== undefined)
|
|
251
|
+
throw new Error(`${here} has "whose" beside "same": its rows share the record's values rather than point at it.`);
|
|
252
|
+
const same = r.same;
|
|
253
|
+
if (!Array.isArray(same) ||
|
|
254
|
+
!same.length ||
|
|
255
|
+
same.length > 4 ||
|
|
256
|
+
same.some((column) => typeof column !== 'string' || !/^[A-Za-z_][A-Za-z0-9_]*$/.test(column)) ||
|
|
257
|
+
new Set(same).size !== same.length)
|
|
258
|
+
throw new Error(`${here}: "same" must be one to 4 different columns a row shares with the record, e.g. ['body_type'].`);
|
|
259
|
+
similar = { same: [...same] };
|
|
260
|
+
}
|
|
248
261
|
return {
|
|
249
262
|
from: r.from.trim(),
|
|
250
263
|
...(r.whose === undefined ? {} : { path: r.whose.trim() }),
|
|
264
|
+
...(similar ? { similar } : {}),
|
|
251
265
|
...(r.query === undefined ? {} : { filter: r.query.trim() }),
|
|
252
266
|
columns: r.show.map((path) => path.trim()),
|
|
253
267
|
...(r.sort === undefined ? {} : { sort: r.sort.trim() }),
|
|
@@ -361,8 +375,8 @@ export function parseCustomList(raw, at) {
|
|
|
361
375
|
throw new Error(`${at} names one column twice in "show".`);
|
|
362
376
|
return { kind: 'custom', component, show: columns, props: componentPropValues(component, raw.props, at) };
|
|
363
377
|
}
|
|
364
|
-
/** The most address parameters one page keeps, and the most loaders it names. */
|
|
365
|
-
const MAX_PAGE_PARAMS =
|
|
378
|
+
/** The most address parameters one page keeps, and the most loaders it names. A filter bar of a dozen fields is a real page; the address stays well inside a URL's length at 24 short names. */
|
|
379
|
+
const MAX_PAGE_PARAMS = 24;
|
|
366
380
|
const MAX_PAGE_LOADERS = 8;
|
|
367
381
|
const PARAM = /^[a-z][a-z0-9_]{0,31}$/;
|
|
368
382
|
const LOADER = /^[A-Za-z][A-Za-z0-9_]{0,63}$/;
|
|
@@ -10,7 +10,6 @@ import { nearest } from './suggest.js';
|
|
|
10
10
|
const AREA_NAME = /^[a-z][a-z0-9-]{0,23}$/;
|
|
11
11
|
/** Words CSS reads before an area name: `grid-area: span` or `auto` is not a name. */
|
|
12
12
|
const CSS_WORDS = new Set(['auto', 'span', 'initial', 'inherit', 'unset', 'revert', 'default']);
|
|
13
|
-
const LAYOUT_MAX_ROWS = 8;
|
|
14
13
|
const LAYOUT_MAX_COLUMNS = 4;
|
|
15
14
|
/** The cell that holds no area. */
|
|
16
15
|
const EMPTY_CELL = '.';
|
|
@@ -64,8 +63,6 @@ export function layoutProblems(layout, at) {
|
|
|
64
63
|
return [`${here} is not a list of rows, each a string of area names: ['kpis kpis', 'trend side'].`];
|
|
65
64
|
}
|
|
66
65
|
const problems = [];
|
|
67
|
-
if (layout.length > LAYOUT_MAX_ROWS)
|
|
68
|
-
problems.push(`${here} has ${layout.length} rows. At most ${LAYOUT_MAX_ROWS}.`);
|
|
69
66
|
const grid = layoutGrid(layout);
|
|
70
67
|
const widest = Math.max(...grid.map((row) => row.length));
|
|
71
68
|
if (grid.some((row) => !row.length))
|
|
@@ -155,7 +155,7 @@ export declare function defaultColumns(table: TableMeta, path: string, resolved?
|
|
|
155
155
|
* dashboard's rows section, on a page. Either way the result is a view the
|
|
156
156
|
* server compiles and authorizes on every run, like any section's.
|
|
157
157
|
*/
|
|
158
|
-
export declare function customReadView(schema: DatabaseSchema, page: PageDef, name: string, read: PageCustomRead, key: Record<string, string | number>, index: number, now?: Date): {
|
|
158
|
+
export declare function customReadView(schema: DatabaseSchema, page: PageDef, name: string, read: PageCustomRead, key: Record<string, string | number>, index: number, now?: Date, rootValues?: RootValues): {
|
|
159
159
|
view?: ViewDef;
|
|
160
160
|
empty?: boolean;
|
|
161
161
|
error?: string;
|
package/dist/shared/pagePaths.js
CHANGED
|
@@ -763,7 +763,21 @@ export function defaultColumns(table, path, resolved) {
|
|
|
763
763
|
* dashboard's rows section, on a page. Either way the result is a view the
|
|
764
764
|
* server compiles and authorizes on every run, like any section's.
|
|
765
765
|
*/
|
|
766
|
-
export function customReadView(schema, page, name, read, key, index, now) {
|
|
766
|
+
export function customReadView(schema, page, name, read, key, index, now, rootValues) {
|
|
767
|
+
if (read.similar) {
|
|
768
|
+
/* Rows that share the record's values: planned as a related list's `same` is, from values read off the record's row. */
|
|
769
|
+
const built = similarView(schema, page, {
|
|
770
|
+
kind: 'list',
|
|
771
|
+
from: read.from,
|
|
772
|
+
path: '',
|
|
773
|
+
columns: read.columns,
|
|
774
|
+
filter: read.filter,
|
|
775
|
+
orderBy: read.orderBy,
|
|
776
|
+
limit: read.limit ?? DEFAULT_PAGE_LIST_LIMIT,
|
|
777
|
+
similar: read.similar,
|
|
778
|
+
}, key, index, now, rootValues);
|
|
779
|
+
return built.view ? { ...built, view: { ...built.view, id: `page:${page.id}:${index}:${name}` } } : built;
|
|
780
|
+
}
|
|
767
781
|
if (read.path) {
|
|
768
782
|
const built = listView(schema, page, {
|
|
769
783
|
kind: 'list',
|
|
@@ -822,6 +836,11 @@ export function customProblem(schema, page, section, index) {
|
|
|
822
836
|
const table = findTable(schema, read.from);
|
|
823
837
|
if (!table)
|
|
824
838
|
return `${here}: "${read.from}" is not a table on this connection.`;
|
|
839
|
+
if (read.similar) {
|
|
840
|
+
const problem = similarProblem(schema, page, { from: read.from, similar: read.similar });
|
|
841
|
+
if (problem)
|
|
842
|
+
return `${here}: ${problem}`;
|
|
843
|
+
}
|
|
825
844
|
if (read.path) {
|
|
826
845
|
const resolved = resolvePath(schema, read.from, read.path);
|
|
827
846
|
if (resolved.error)
|
package/dist/shared/pagePlans.js
CHANGED
|
@@ -75,7 +75,10 @@ export function planPageSections(schema, page, key, ofKeys, now = new Date(), ro
|
|
|
75
75
|
return {
|
|
76
76
|
index,
|
|
77
77
|
kind: section.kind,
|
|
78
|
-
reads: Object.fromEntries(Object.entries(section.reads ?? {}).map(([name, read]) => [
|
|
78
|
+
reads: Object.fromEntries(Object.entries(section.reads ?? {}).map(([name, read]) => [
|
|
79
|
+
name,
|
|
80
|
+
customReadView(schema, page, name, read, key, index, now, rootValues),
|
|
81
|
+
])),
|
|
79
82
|
aggregates: Object.fromEntries(Object.entries(section.aggregates ?? {}).map(([name, total]) => {
|
|
80
83
|
const built = customTotalPlan(schema, page, name, total, key, index, now);
|
|
81
84
|
return [name, { breakdown: built.def, empty: built.empty, error: built.error }];
|
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.68",
|
|
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
|
@@ -312,8 +312,10 @@ export interface CommandActionBase<Label extends string | AppMessageRef> {
|
|
|
312
312
|
* Offered for a queue selection only when the command declares
|
|
313
313
|
* `targets: 'many'`: one request names every selected record, and the
|
|
314
314
|
* handler applies all of them in one transaction or none.
|
|
315
|
+
* `'each'` offers a command that names one record, and asks nothing, for a selection too: it runs once per selected
|
|
316
|
+
* record, each in its own transaction and each answered on its own, as a fixed action's bulk does.
|
|
315
317
|
*/
|
|
316
|
-
bulk?: boolean;
|
|
318
|
+
bulk?: boolean | 'each';
|
|
317
319
|
/**
|
|
318
320
|
* `false` keeps the button out of the record's action bar and its menu, for
|
|
319
321
|
* a verb the App runs from its own place — a custom component through
|