@mistriwork/engine 1.0.0-rc.37 → 1.0.0-rc.39
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 +4 -0
- package/dist/server/clientHttp.js +10 -1
- package/dist/server/http/exportRoute.js +9 -1
- package/dist/shared/query.js +21 -1
- package/dist/shared/queryOperands.d.ts +21 -0
- package/dist/shared/queryOperands.js +27 -0
- package/dist/shared/recordReads.js +26 -0
- package/dist/shared/themeRecipes.d.ts +1 -1
- package/dist/shared/themeRecipes.js +1 -0
- package/package.json +1 -1
- package/schema/model.d.ts +25 -7
- package/schema/theme.d.ts +2 -1
|
@@ -395,6 +395,8 @@ export interface InsertRequest {
|
|
|
395
395
|
* what defaults are for — and refuses what it must, in its own words.
|
|
396
396
|
*/
|
|
397
397
|
values: Record<string, string | number | boolean | null>;
|
|
398
|
+
/** What the write gives its notices to say (`{words.code}` in a notify title): told, never stored on the row. */
|
|
399
|
+
words?: Readonly<Record<string, string>>;
|
|
398
400
|
}
|
|
399
401
|
export interface InsertResult {
|
|
400
402
|
/** The new row's primary key, read back from the database. */
|
|
@@ -804,6 +806,8 @@ export interface UpdateRequest {
|
|
|
804
806
|
restore?: true;
|
|
805
807
|
/** Original values for exactly the touched fields; checked atomically by UPDATE. */
|
|
806
808
|
expected?: Record<string, string | number | boolean | null>;
|
|
809
|
+
/** What the write gives its notices to say (`{words.code}` in a notify title): told, never stored on the row. */
|
|
810
|
+
words?: Readonly<Record<string, string>>;
|
|
807
811
|
}
|
|
808
812
|
export interface UpdateResult {
|
|
809
813
|
affected: number;
|
|
@@ -140,10 +140,19 @@ const writesHead = (head) => Boolean(head?.title ||
|
|
|
140
140
|
head?.social ||
|
|
141
141
|
head?.pane ||
|
|
142
142
|
head?.pwa);
|
|
143
|
+
/** What an App's own theme carries that a page's head never writes: its served files and where its menu sits. */
|
|
144
|
+
const HEAD_UNWRITTEN = new Set(['faces', 'stylesheet', 'shell']);
|
|
143
145
|
/** Generate only registered token names and validated theme values. Row text
|
|
144
146
|
* exists only in escaped JSON; it can never close a style/script element. */
|
|
145
147
|
function brandingHead(html, presentation, base) {
|
|
146
|
-
|
|
148
|
+
/* A tenant's theme starts from the App's own, which may ship font files, a stylesheet or a menu placement. The head
|
|
149
|
+
writes none of them (the shell serves the App's already), so the validator is not asked them: a field report's
|
|
150
|
+
App wore its own faces, and every public form of a tenant that had saved a name answered 403. */
|
|
151
|
+
const said = presentation.value.theme;
|
|
152
|
+
const tokens = said && typeof said === 'object' && !Array.isArray(said)
|
|
153
|
+
? Object.fromEntries(Object.entries(said).filter(([key]) => !HEAD_UNWRITTEN.has(key)))
|
|
154
|
+
: said;
|
|
155
|
+
const theme = parseThemes([tokens], 'Request branding', 'themes', { platform: true })[0];
|
|
147
156
|
const declarations = (mode) => {
|
|
148
157
|
const pairs = [];
|
|
149
158
|
for (const [key, token] of Object.entries(PALETTE_TOKENS)) {
|
|
@@ -127,8 +127,11 @@ export async function exportFile(asked) {
|
|
|
127
127
|
return stream(res, format, view.base, rowsWanted(view.limit), read, requested(body) ?? undefined, amountsOf(view.base), asked.headers, byOffset ? answer : undefined);
|
|
128
128
|
}
|
|
129
129
|
}
|
|
130
|
+
/* Not a file, so not a 200: a client reads the status before the body. A table this reader is not served is not
|
|
131
|
+
found — the same answer whether it exists or not, so a refusal tells nothing — and any other question that cannot
|
|
132
|
+
be read is a bad request. Either way `errors` says why, as `/api/run`'s does. */
|
|
130
133
|
if (!parsed.query || parsed.errors.length) {
|
|
131
|
-
answer(
|
|
134
|
+
answer(servesTable(schema, text) ? 400 : 404, { errors: parsed.errors });
|
|
132
135
|
return undefined;
|
|
133
136
|
}
|
|
134
137
|
const query = parsed.query;
|
|
@@ -170,6 +173,11 @@ export async function exportFile(asked) {
|
|
|
170
173
|
};
|
|
171
174
|
return stream(res, format, table.id, rowsWanted(query.limit), read, wanted, amountsOf(table.id), asked.headers, byOffset ? answer : undefined);
|
|
172
175
|
}
|
|
176
|
+
/** Whether the question's first word is a table in this reader's schema, by id or by bare name (as parseQuery finds it); an empty question names none and is no missing table. */
|
|
177
|
+
function servesTable(schema, text) {
|
|
178
|
+
const first = text.trim().split(/\s+/)[0];
|
|
179
|
+
return !first || findTable(schema, first) !== undefined || schema.tables.some((table) => table.name === first);
|
|
180
|
+
}
|
|
173
181
|
function refuseTable(answer, tableId) {
|
|
174
182
|
answer(403, {
|
|
175
183
|
error: `Export of "${tableId}" is not available to this person.`,
|
package/dist/shared/query.js
CHANGED
|
@@ -4,7 +4,7 @@ import { distance, nearest } from './suggest.js';
|
|
|
4
4
|
import { columnKind, findTable } from './schema.js';
|
|
5
5
|
import { dateWindow } from './queryDates.js';
|
|
6
6
|
import { maskQuoted } from './maskQuoted.js';
|
|
7
|
-
import { ME_SET, columnOperand, meOperand, meSetOperand } from './queryOperands.js';
|
|
7
|
+
import { ME_SET, columnOperand, meOperand, meSetOperand, tenantOperand } from './queryOperands.js';
|
|
8
8
|
import { TAGS_TYPE } from './tagLists.js';
|
|
9
9
|
import { DEFINED_PATH_TYPE } from './definedFields.js';
|
|
10
10
|
const RANGE_OPS = new Set(['<', '<=', '>', '>=']);
|
|
@@ -758,6 +758,17 @@ function compileClause(raw, ctx) {
|
|
|
758
758
|
const groups = item.quoted ? undefined : (column?.states ?? ctx.states?.[name])?.groups;
|
|
759
759
|
if (groups && Object.hasOwn(groups, item.value))
|
|
760
760
|
return { error: `"${item.value}" is a group of ${name}'s states; ask it with is: ${name} is ${item.value}.` };
|
|
761
|
+
const fromTenant = tenantOperand(ctx, column, item.value, item.quoted);
|
|
762
|
+
if (fromTenant) {
|
|
763
|
+
if (fromTenant.error)
|
|
764
|
+
return { error: fromTenant.error };
|
|
765
|
+
if (typeof fromTenant.value === 'boolean')
|
|
766
|
+
return { error: `${item.value} is a flag: ask it with =, as in ${name} = ${item.value}.` };
|
|
767
|
+
/* A null profile value is in no list: left out, as a row key no one has. */
|
|
768
|
+
if (fromTenant.value !== undefined)
|
|
769
|
+
values.push(fromTenant.value);
|
|
770
|
+
continue;
|
|
771
|
+
}
|
|
761
772
|
if (!item.quoted && item.value === 'me') {
|
|
762
773
|
if (ctx.me === undefined)
|
|
763
774
|
return { error: NO_ONE_HERE };
|
|
@@ -812,6 +823,15 @@ function compileClause(raw, ctx) {
|
|
|
812
823
|
nobody is signed in says so (`me: null`); a check before any request reads it as anyone's (ANYONE). */
|
|
813
824
|
if (!quoted && value === 'me' && ctx.me === undefined)
|
|
814
825
|
return { error: NO_ONE_HERE };
|
|
826
|
+
/* The reader's tenant profile (`country = tenant.country`), read once for this request; a null value matches no row. */
|
|
827
|
+
const fromTenant = tenantOperand(ctx, column, value, quoted);
|
|
828
|
+
if (fromTenant) {
|
|
829
|
+
if (fromTenant.error)
|
|
830
|
+
return { error: fromTenant.error };
|
|
831
|
+
if (fromTenant.none)
|
|
832
|
+
return { conditions: [{ column: name, op: 'in', value: [] }] };
|
|
833
|
+
return { conditions: [{ column: name, op, value: fromTenant.value }] };
|
|
834
|
+
}
|
|
815
835
|
if (!quoted && value === 'me') {
|
|
816
836
|
const me = meOperand(ctx, column, op);
|
|
817
837
|
if (me.error)
|
|
@@ -41,7 +41,16 @@ export interface QueryPerson {
|
|
|
41
41
|
* or why they cannot be read.
|
|
42
42
|
*/
|
|
43
43
|
sets?: Readonly<Record<string, MeSet>>;
|
|
44
|
+
/**
|
|
45
|
+
* `tenant.<column>`: the reader's tenant profile row, by column, for the columns
|
|
46
|
+
* the App shares with its members (`auth.tenancy.shared`), read once for this
|
|
47
|
+
* request. A missing row reads as every column null. Absent where no tenant is
|
|
48
|
+
* meant, and `tenant.<column>` is then refused rather than read as text.
|
|
49
|
+
*/
|
|
50
|
+
tenant?: Readonly<Record<string, TenantValue>>;
|
|
44
51
|
}
|
|
52
|
+
/** One column of a tenant's profile row, as a member may read it. */
|
|
53
|
+
export type TenantValue = string | number | boolean | null;
|
|
45
54
|
/** Nobody in particular (`anyone` above): what a check that runs before any request reads `me` as. */
|
|
46
55
|
export declare const ANYONE: QueryPerson;
|
|
47
56
|
/** One `me.<table>.<column>`: its values and their kind, or the sentence that refuses it. */
|
|
@@ -62,6 +71,18 @@ export interface CompileContext {
|
|
|
62
71
|
/** A machine's states by column, where the catalog does not carry them (a parse with no schema). */
|
|
63
72
|
states?: Readonly<Record<string, MachineStates>>;
|
|
64
73
|
}
|
|
74
|
+
/**
|
|
75
|
+
* What `tenant.<column>` stands for beside one column: the profile's value, read for
|
|
76
|
+
* this request. Undefined where the word is not one (quoted, or the table has a
|
|
77
|
+
* `tenant` column of its own, whose path it then is). A null value matches no row, as
|
|
78
|
+
* SQL's `= NULL` would, but said as conditions every engine speaks; in a list it is
|
|
79
|
+
* left out. A check before any request (ANYONE) reads it as the word.
|
|
80
|
+
*/
|
|
81
|
+
export declare function tenantOperand(ctx: CompileContext, column: ColumnMeta | undefined, word: string, quoted: boolean): {
|
|
82
|
+
value?: string | number | boolean;
|
|
83
|
+
none?: true;
|
|
84
|
+
error?: string;
|
|
85
|
+
} | undefined;
|
|
65
86
|
/**
|
|
66
87
|
* The column an unquoted right-hand side names, when it names one.
|
|
67
88
|
*
|
|
@@ -1,8 +1,35 @@
|
|
|
1
1
|
import { columnKind } from './schema.js';
|
|
2
|
+
/** `tenant.<column>`, unquoted, on the right of a comparison or in a value list. */
|
|
3
|
+
const TENANT_VALUE = /^tenant\.([A-Za-z_]\w*)$/;
|
|
2
4
|
/** Nobody in particular (`anyone` above): what a check that runs before any request reads `me` as. */
|
|
3
5
|
export const ANYONE = Object.freeze({ email: null, anyone: true });
|
|
4
6
|
/** `me.<table>.<column>`, written as one item of a value list. */
|
|
5
7
|
export const ME_SET = /^me\.([A-Za-z_]\w*)\.([A-Za-z_]\w*)$/;
|
|
8
|
+
/**
|
|
9
|
+
* What `tenant.<column>` stands for beside one column: the profile's value, read for
|
|
10
|
+
* this request. Undefined where the word is not one (quoted, or the table has a
|
|
11
|
+
* `tenant` column of its own, whose path it then is). A null value matches no row, as
|
|
12
|
+
* SQL's `= NULL` would, but said as conditions every engine speaks; in a list it is
|
|
13
|
+
* left out. A check before any request (ANYONE) reads it as the word.
|
|
14
|
+
*/
|
|
15
|
+
export function tenantOperand(ctx, column, word, quoted) {
|
|
16
|
+
const match = quoted ? null : TENANT_VALUE.exec(word);
|
|
17
|
+
if (!match || ctx.table?.columns.some((c) => c.name === 'tenant'))
|
|
18
|
+
return undefined;
|
|
19
|
+
const me = ctx.me;
|
|
20
|
+
if (me?.anyone && me.tenant === undefined)
|
|
21
|
+
return { value: word };
|
|
22
|
+
if (!me?.tenant)
|
|
23
|
+
return { error: `${word} is the reader's tenant profile, and no tenant is meant here. Quote it ("${word}") to mean the text.` };
|
|
24
|
+
if (!Object.hasOwn(me.tenant, match[1]))
|
|
25
|
+
return { error: `${word} is not a column the App shares with its members: list "${match[1]}" in auth.tenancy.shared.` };
|
|
26
|
+
const value = me.tenant[match[1]];
|
|
27
|
+
if (value === null)
|
|
28
|
+
return { none: true };
|
|
29
|
+
if (typeof value === 'boolean' && column && columnKind(column.type) !== 'boolean')
|
|
30
|
+
return { error: `${word} is a flag, and ${column.name} is not.` };
|
|
31
|
+
return { value };
|
|
32
|
+
}
|
|
6
33
|
const COMPARISON_OPS = new Set(['=', '!=', '<', '<=', '>', '>=']);
|
|
7
34
|
const BARE_WORD = /^[A-Za-z_$][\w$]*$/;
|
|
8
35
|
const PATH_WORD = /^[A-Za-z_$][\w$+]*(?:\.[A-Za-z_$][\w$+]*)+$/;
|
|
@@ -454,6 +454,32 @@ export function recordPageReads(names, page, base, plans, key, options) {
|
|
|
454
454
|
assertNever(section.kind, 'page section kind');
|
|
455
455
|
}
|
|
456
456
|
});
|
|
457
|
+
/* A strip of related tabs decides which tabs it has before one is opened (kit ListTabs, useStandings): the condition of a
|
|
458
|
+
list that has one, and the first page of a list that hides while empty, which is the answer to "has it rows?". They
|
|
459
|
+
are the reads the list asks itself when its tab is opened, so they are asked here too, once, and the strip finds
|
|
460
|
+
them waiting (as for a list alone). A closed tab is asked what it must decide on and no more. */
|
|
461
|
+
for (const run of runs) {
|
|
462
|
+
if (run.length < 2)
|
|
463
|
+
continue;
|
|
464
|
+
for (const index of run) {
|
|
465
|
+
const section = page.sections[index];
|
|
466
|
+
if (section.hidden || drawn.has(index) || section.kind !== 'list')
|
|
467
|
+
continue;
|
|
468
|
+
kind = 'related';
|
|
469
|
+
if (section.when)
|
|
470
|
+
reads.push({ path: '/api/run', body: whenBody(base, key, section.when) });
|
|
471
|
+
const plan = planOf(index);
|
|
472
|
+
if (section.emptyMode !== 'hide' || !plan || plan.error || plan.empty)
|
|
473
|
+
continue;
|
|
474
|
+
if (section.group && plan.groups) {
|
|
475
|
+
reads.push({ path: '/api/breakdown', body: groupsBody(plan.groups, 0), kind });
|
|
476
|
+
continue;
|
|
477
|
+
}
|
|
478
|
+
const listed = listView(names, section, plan, options.rows).view;
|
|
479
|
+
if (listed)
|
|
480
|
+
view({ view: listed, offset: 0 });
|
|
481
|
+
}
|
|
482
|
+
}
|
|
457
483
|
/* An inferred page's tabs say how many rows each holds, all of them in one read; a list alone says it in its head. */
|
|
458
484
|
if (isInferredPage(page, names.app))
|
|
459
485
|
for (const run of runs) {
|
|
@@ -211,7 +211,7 @@ export declare function typeAttributes(type: ThemeTypeDefinition | undefined): R
|
|
|
211
211
|
* The published parts a theme may dress one by one (themeParts.ts says what each may take and how it is worn). Here,
|
|
212
212
|
* with the words the root wears for them, because the first paint sets `data-parts` as it sets the recipes'.
|
|
213
213
|
*/
|
|
214
|
-
export declare const THEME_PARTS: readonly ["ground", "bar", "bar.search", "nav", "nav.item", "nav.current", "nav.group", "logo", "page.title", "tabs", "tab.current", "section", "section.title", "stat", "stat.figure", "fields", "field.label", "table", "table.head", "table.row", "status", "tag", "button.primary", "button.secondary", "button.quiet", "link", "board.lane", "board.card", "workflow.step", "banner", "steps.step", "avatar", "identityMark", "menu", "dialog", "chart"];
|
|
214
|
+
export declare const THEME_PARTS: readonly ["ground", "bar", "bar.search", "nav", "nav.item", "nav.current", "nav.group", "logo", "page.title", "tabs", "tab.current", "section", "section.title", "stat", "stat.figure", "fields", "field.label", "table", "table.head", "table.row", "status", "tag", "button.primary", "button.secondary", "button.quiet", "link", "board.lane", "board.card", "workflow.step", "banner", "steps.step", "avatar", "identityMark", "menu", "dialog", "chart", "kicker"];
|
|
215
215
|
/** What a part style may say, in the order its words are written. */
|
|
216
216
|
export declare const PART_PROPERTIES: readonly ['ground', 'ink', 'edge', 'radius', 'lift', 'face', 'weight', 'case'];
|
|
217
217
|
/** The root's `data-parts`: one word per property a part says (`stat:ground button.primary:case`); undefined when none. */
|
|
@@ -220,6 +220,7 @@ export const THEME_PARTS = [
|
|
|
220
220
|
'menu',
|
|
221
221
|
'dialog',
|
|
222
222
|
'chart',
|
|
223
|
+
'kicker',
|
|
223
224
|
];
|
|
224
225
|
/** What a part style may say, in the order its words are written. */
|
|
225
226
|
export const PART_PROPERTIES = ['ground', 'ink', 'edge', 'radius', 'lift', 'face', 'weight', 'case'];
|
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.39",
|
|
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
|
@@ -50,13 +50,23 @@ export type StaticAppTarget = AppTarget<string | number>;
|
|
|
50
50
|
/**
|
|
51
51
|
* A field's starting value: a literal (`'phone'`, `3`, `true`); `today` on a
|
|
52
52
|
* date field or `now` on a datetime field, as the form opens in the App's time
|
|
53
|
-
* zone; `me` on a text field, the reader's email;
|
|
54
|
-
* the target record's column as the reader sees it
|
|
55
|
-
*
|
|
56
|
-
*
|
|
57
|
-
*
|
|
53
|
+
* zone; `me` on a text field, the reader's email; `{ record: 'on_hand' }`,
|
|
54
|
+
* the target record's column as the reader sees it, or one its references
|
|
55
|
+
* reach (`{ record: 'customer_id.default_rate' }`, at most two hops, each read
|
|
56
|
+
* under the reader's grants: a hop they cannot read starts nothing); or
|
|
57
|
+
* `{ tenant: 'country' }`, a column of the tenant's profile its members read
|
|
58
|
+
* (`auth.tenancy.shared`). The constants are `@mistriwork/mistri/app`'s. `me`,
|
|
59
|
+
* `{ record }` and `{ tenant }` are read when the form is prepared, so they
|
|
60
|
+
* fill a field of the input itself; `{ record }` on a command that targets one
|
|
61
|
+
* record.
|
|
58
62
|
*/
|
|
59
|
-
export type CommandFieldDefault =
|
|
63
|
+
export type CommandFieldDefault =
|
|
64
|
+
| string
|
|
65
|
+
| number
|
|
66
|
+
| boolean
|
|
67
|
+
| { readonly auto: 'today' | 'now' | 'me' }
|
|
68
|
+
| { readonly record: string }
|
|
69
|
+
| { readonly tenant: string };
|
|
60
70
|
|
|
61
71
|
/** One option of a `choice` input. */
|
|
62
72
|
export interface AppCommandChoice {
|
|
@@ -276,6 +286,10 @@ export interface CommandActionBase<Label extends string | AppMessageRef> {
|
|
|
276
286
|
the platform's control. An input in a group is named by its path (`trade.vin`), and in a repeating group stands in
|
|
277
287
|
every row; what the value must be is still the command's to judge. */
|
|
278
288
|
inputs?: Readonly<Record<string, { readonly id: string; readonly module: string; readonly kind: string }>>;
|
|
289
|
+
/** The command's own inputs this action's page supplies (`useCommand(name).open(record, { step })`): its form does not
|
|
290
|
+
draw them, and sends what the page gave. A required one with no default is typed by no one, so the action says
|
|
291
|
+
`header: false` and is not `bulk`: only a page opens it. The server judges the value as any other. */
|
|
292
|
+
given?: readonly string[];
|
|
279
293
|
}
|
|
280
294
|
|
|
281
295
|
/** A command action as the App serves it. */
|
|
@@ -283,8 +297,12 @@ export interface AppCommandAction<Target extends string = string, Label extends
|
|
|
283
297
|
/** Its key in `resources.<table>.actions`. */
|
|
284
298
|
id: string;
|
|
285
299
|
command: AppCommandReference<Target>;
|
|
286
|
-
/** Where the button is offered: the command's own `when
|
|
300
|
+
/** Where the button is offered: the command's own `when` and the action's together, or the states a machine's verb
|
|
301
|
+
leaves. Visibility only; the server judges the command's. */
|
|
287
302
|
when?: string;
|
|
303
|
+
/** The action's own `when` alone, when it has one: what a record's bar asks, since the server's availability answer
|
|
304
|
+
already holds the command's. */
|
|
305
|
+
offered?: string;
|
|
288
306
|
/** A machine's verb that says itself differently from different states (a per-edge `label`, or `{to}` in it):
|
|
289
307
|
each label with the states it is said from, as a condition. `label` is the first state's. */
|
|
290
308
|
labels?: Array<{ when: string; label: string }>;
|
package/schema/theme.d.ts
CHANGED
|
@@ -178,7 +178,8 @@ export type ThemePart =
|
|
|
178
178
|
| 'identityMark'
|
|
179
179
|
| 'menu'
|
|
180
180
|
| 'dialog'
|
|
181
|
-
| 'chart'
|
|
181
|
+
| 'chart'
|
|
182
|
+
| 'kicker';
|
|
182
183
|
|
|
183
184
|
/** A color role by its path in `colors`: `ink`, `nav.ground`, `status.good`, `chart[2]`. */
|
|
184
185
|
export type ThemeColorPath =
|