@mistriwork/engine 1.0.0-rc.38 → 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.
|
@@ -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;
|
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$+]*)+$/;
|
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. */
|