@mistriwork/engine 1.0.0-rc.75 → 1.0.0-rc.78
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 +6 -0
- package/dist/adapters/postgres.js +13 -7
- package/dist/adapters/postgresPool.d.ts +28 -0
- package/dist/adapters/postgresPool.js +36 -3
- package/dist/adapters/scoped/scopedReads.js +5 -1
- package/dist/adapters/scoped/scopedTransaction.js +3 -1
- package/dist/adapters/serverSettings.d.ts +2 -0
- package/dist/adapters/sqlite.js +7 -5
- package/dist/server/cli/args.d.ts +2 -1
- package/dist/server/cli/args.js +13 -2
- package/dist/server/columnGrants.d.ts +3 -0
- package/dist/server/columnGrants.js +29 -4
- package/dist/server/connections.d.ts +1 -1
- package/dist/server/connections.js +2 -0
- package/dist/server/http/probes.d.ts +10 -1
- package/dist/server/http/probes.js +6 -2
- package/dist/server/http/recordWrites.js +7 -1
- package/dist/server/http/refusalReport.js +7 -1
- package/dist/server/http/serverCore.d.ts +2 -1
- package/dist/server/migrate/cli.js +7 -0
- package/dist/server/poolConfig.d.ts +4 -0
- package/dist/server/poolConfig.js +20 -7
- package/dist/server/resourceReadHttp.js +7 -2
- package/dist/server/resourceReadOperations.js +5 -1
- package/dist/shared/aggregate.js +7 -1
- package/dist/shared/appComponents.js +1 -1
- package/dist/shared/autoBucket.d.ts +29 -5
- package/dist/shared/autoBucket.js +49 -14
- package/dist/shared/computedParse.d.ts +2 -0
- package/dist/shared/computedParse.js +1 -1
- package/dist/shared/computedWhere.d.ts +47 -0
- package/dist/shared/computedWhere.js +159 -0
- package/dist/shared/filter.d.ts +5 -0
- package/dist/shared/filter.js +4 -0
- package/dist/shared/query.js +20 -22
- package/dist/shared/queryDates.d.ts +16 -0
- package/dist/shared/queryDates.js +29 -0
- package/dist/shared/queryOperands.d.ts +24 -0
- package/dist/shared/queryOperands.js +36 -0
- package/dist/shared/refusal.d.ts +8 -0
- package/dist/shared/refusal.js +15 -0
- package/dist/shared/resourceHttp.d.ts +1 -1
- package/dist/shared/rowCondition.d.ts +5 -0
- package/dist/shared/rowCondition.js +80 -0
- package/dist/shared/schema.d.ts +10 -0
- package/dist/shared/schema.js +8 -0
- package/dist/shared/scopeCatalog.d.ts +1 -1
- package/dist/shared/scopeCatalog.js +13 -1
- package/dist/shared/servedApp.d.ts +19 -0
- package/dist/shared/structuredFilter.d.ts +3 -0
- package/dist/shared/viewLabels.d.ts +6 -1
- package/dist/shared/viewLabels.js +1 -1
- package/package.json +2 -1
- package/schema/model.d.ts +12 -3
|
@@ -44,6 +44,35 @@ export function shiftedDay(today, sign, count, unit) {
|
|
|
44
44
|
const last = new Date(Date.UTC(first.getUTCFullYear(), first.getUTCMonth() + 1, 0)).getUTCDate();
|
|
45
45
|
return new Date(Date.UTC(first.getUTCFullYear(), first.getUTCMonth(), Math.min(d, last))).toISOString().slice(0, 10);
|
|
46
46
|
}
|
|
47
|
+
/**
|
|
48
|
+
* Dates are bound as ISO strings because both target dialects compare them
|
|
49
|
+
* correctly that way: Postgres casts on the way in, and SQLite's documented
|
|
50
|
+
* text-date format is exactly ISO-8601. A `Date` object handed to a driver
|
|
51
|
+
* is at the mercy of whatever it decides to do with the local timezone.
|
|
52
|
+
*/
|
|
53
|
+
export function bindDate(d) {
|
|
54
|
+
const pad = (n) => String(n).padStart(2, '0');
|
|
55
|
+
const day = `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())}`;
|
|
56
|
+
/* A midnight boundary is bound as the bare day. Text comparison sorts
|
|
57
|
+
'2026-08-30' before '2026-08-30 00:00:00', so appending the zero time
|
|
58
|
+
made every bare-DATE column compare wrong at the boundary — SQLite
|
|
59
|
+
counted a task due *today* as `< today`, i.e. overdue. Bare, the bound
|
|
60
|
+
is right for every storage shape at once: it sorts before any datetime
|
|
61
|
+
of its day, and a driver casting for a real date/timestamp column reads
|
|
62
|
+
it as midnight exactly as before. */
|
|
63
|
+
if (!d.getHours() && !d.getMinutes() && !d.getSeconds())
|
|
64
|
+
return day;
|
|
65
|
+
return `${day} ${pad(d.getHours())}:${pad(d.getMinutes())}:${pad(d.getSeconds())}`;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* A window's bounds as a read compares against them (bindDate): `start` is in it, `end` is the first moment after it,
|
|
69
|
+
* so `last 30 days` on Nov 20 is 2026-10-21 to 2026-11-21. A custom dashboard section is handed these beside the
|
|
70
|
+
* phrase, to say or draw the span its rows were narrowed to without parsing the grammar itself.
|
|
71
|
+
*/
|
|
72
|
+
export function windowBounds(phrase, now) {
|
|
73
|
+
const window = dateWindow(phrase, now);
|
|
74
|
+
return window ? { start: bindDate(window.start), end: bindDate(window.end) } : undefined;
|
|
75
|
+
}
|
|
47
76
|
/**
|
|
48
77
|
* `now` is a parameter rather than a call to the clock, so the compiler is a
|
|
49
78
|
* pure function of its inputs. That is what makes the tests below able to
|
|
@@ -54,9 +54,21 @@ export interface QueryPerson {
|
|
|
54
54
|
* meant, and `tenant.<column>` is then refused rather than read as text.
|
|
55
55
|
*/
|
|
56
56
|
tenant?: Readonly<Record<string, TenantValue>>;
|
|
57
|
+
/**
|
|
58
|
+
* `chosen.<name>`: the App-wide choices (an App's `choose`) by name, each the row key the person picked,
|
|
59
|
+
* re-read and proven readable under their own row policy for this request — null where nothing is chosen
|
|
60
|
+
* or the pick was not theirs to read. Absent where no App choice is meant, and `chosen.<name>` is then
|
|
61
|
+
* refused rather than read as text.
|
|
62
|
+
*/
|
|
63
|
+
chosen?: Readonly<Record<string, string | number | null>>;
|
|
57
64
|
}
|
|
58
65
|
/** One column of a tenant's profile row, as a member may read it. */
|
|
59
66
|
export type TenantValue = string | number | boolean | null;
|
|
67
|
+
/**
|
|
68
|
+
* The App-wide choices a query's text names (`site_id = chosen.site`), in the order they first appear, so a list can
|
|
69
|
+
* say which of them narrows it. Quoted text is a value and not a reference, as the compiler reads it.
|
|
70
|
+
*/
|
|
71
|
+
export declare function choicesNamed(...texts: readonly string[]): string[];
|
|
60
72
|
/** Nobody in particular (`anyone` above): what a check that runs before any request reads `me` as. */
|
|
61
73
|
export declare const ANYONE: QueryPerson;
|
|
62
74
|
/** ANYONE for a query kept as it is compiled and served to every request: `tenant.<column>` is refused, not held. */
|
|
@@ -110,6 +122,18 @@ export declare function tenantOperand(ctx: CompileContext, column: ColumnMeta |
|
|
|
110
122
|
none?: true;
|
|
111
123
|
error?: string;
|
|
112
124
|
} | undefined;
|
|
125
|
+
/**
|
|
126
|
+
* What `chosen.<name>` stands for beside one column: the row key the person picked for this request.
|
|
127
|
+
* Undefined where the word is not one (quoted, or the table has a `chosen` column of its own, whose path it
|
|
128
|
+
* then is). Nothing chosen matches no row, as a null tenant value does: a list about the current site shows
|
|
129
|
+
* no site's rows rather than every site's. A check before any request (ANYONE) reads it as the word; a query
|
|
130
|
+
* kept for every request refuses it, as it refuses `tenant.<column>`.
|
|
131
|
+
*/
|
|
132
|
+
export declare function chosenOperand(ctx: CompileContext, word: string, quoted: boolean): {
|
|
133
|
+
value?: string | number;
|
|
134
|
+
none?: true;
|
|
135
|
+
error?: string;
|
|
136
|
+
} | undefined;
|
|
113
137
|
/**
|
|
114
138
|
* The column an unquoted right-hand side names, when it names one.
|
|
115
139
|
*
|
|
@@ -1,6 +1,19 @@
|
|
|
1
1
|
import { columnKind } from './schema.js';
|
|
2
2
|
/** `tenant.<column>`, unquoted, on the right of a comparison or in a value list. */
|
|
3
3
|
const TENANT_VALUE = /^tenant\.([A-Za-z_]\w*)$/;
|
|
4
|
+
/** `chosen.<name>`, unquoted, on the right of a comparison or in a value list. */
|
|
5
|
+
const CHOSEN_VALUE = /^chosen\.([A-Za-z_]\w*)$/;
|
|
6
|
+
/**
|
|
7
|
+
* The App-wide choices a query's text names (`site_id = chosen.site`), in the order they first appear, so a list can
|
|
8
|
+
* say which of them narrows it. Quoted text is a value and not a reference, as the compiler reads it.
|
|
9
|
+
*/
|
|
10
|
+
export function choicesNamed(...texts) {
|
|
11
|
+
const found = new Set();
|
|
12
|
+
for (const text of texts)
|
|
13
|
+
for (const [, name] of text.replace(/"(?:[^"\\]|\\.)*"|'(?:[^'\\]|\\.)*'/g, '""').matchAll(/(?<![\w.])chosen\.([A-Za-z_]\w*)/g))
|
|
14
|
+
found.add(name);
|
|
15
|
+
return [...found];
|
|
16
|
+
}
|
|
4
17
|
/** Nobody in particular (`anyone` above): what a check that runs before any request reads `me` as. */
|
|
5
18
|
export const ANYONE = Object.freeze({ email: null, anyone: true });
|
|
6
19
|
/** ANYONE for a query kept as it is compiled and served to every request: `tenant.<column>` is refused, not held. */
|
|
@@ -84,6 +97,29 @@ export function tenantOperand(ctx, column, word, quoted) {
|
|
|
84
97
|
return { error: `${word} is a flag, and ${column.name} is not.` };
|
|
85
98
|
return { value };
|
|
86
99
|
}
|
|
100
|
+
/**
|
|
101
|
+
* What `chosen.<name>` stands for beside one column: the row key the person picked for this request.
|
|
102
|
+
* Undefined where the word is not one (quoted, or the table has a `chosen` column of its own, whose path it
|
|
103
|
+
* then is). Nothing chosen matches no row, as a null tenant value does: a list about the current site shows
|
|
104
|
+
* no site's rows rather than every site's. A check before any request (ANYONE) reads it as the word; a query
|
|
105
|
+
* kept for every request refuses it, as it refuses `tenant.<column>`.
|
|
106
|
+
*/
|
|
107
|
+
export function chosenOperand(ctx, word, quoted) {
|
|
108
|
+
const match = quoted ? null : CHOSEN_VALUE.exec(word);
|
|
109
|
+
if (!match || ctx.table?.columns.some((c) => c.name === 'chosen'))
|
|
110
|
+
return undefined;
|
|
111
|
+
const me = ctx.me;
|
|
112
|
+
if (me?.anyone && me.chosen === undefined)
|
|
113
|
+
return me.once
|
|
114
|
+
? { error: `${word} is a choice of one request's person, and this query is read once for every request, so it cannot ask it.` }
|
|
115
|
+
: { value: word };
|
|
116
|
+
if (!me?.chosen)
|
|
117
|
+
return { error: `${word} is the person's App choice, and no App choice is meant here. Quote it ("${word}") to mean the text.` };
|
|
118
|
+
if (!Object.hasOwn(me.chosen, match[1]))
|
|
119
|
+
return { error: `${word} names no choice: the App's choose declares ${Object.keys(me.chosen).join(', ') || 'none'}.` };
|
|
120
|
+
const value = me.chosen[match[1]];
|
|
121
|
+
return value === null ? { none: true } : { value };
|
|
122
|
+
}
|
|
87
123
|
const COMPARISON_OPS = new Set(['=', '!=', '<', '<=', '>', '>=']);
|
|
88
124
|
const BARE_WORD = /^[A-Za-z_$][\w$]*$/;
|
|
89
125
|
const PATH_WORD = /^[A-Za-z_$][\w$+]*(?:\.[A-Za-z_$][\w$+]*)+$/;
|
package/dist/shared/refusal.d.ts
CHANGED
|
@@ -31,6 +31,14 @@ export declare class RequestFault extends Refusal {
|
|
|
31
31
|
}
|
|
32
32
|
/** Whether a refusal is a request that can never succeed as written (`RequestFault`), from any copy of the module. */
|
|
33
33
|
export declare const isRequestFault: (error: unknown) => error is RequestFault;
|
|
34
|
+
declare const FROZEN_REFUSAL: unique symbol;
|
|
35
|
+
export declare class FrozenRefusal extends Refusal {
|
|
36
|
+
readonly [FROZEN_REFUSAL] = true;
|
|
37
|
+
/** The sentence the caller reads: it names the resource and the condition, never a value of the row. */
|
|
38
|
+
constructor(message: string);
|
|
39
|
+
}
|
|
40
|
+
/** Whether a refusal is a frozen record's (`FrozenRefusal`), from any copy of the module. */
|
|
41
|
+
export declare const isFrozenRefusal: (error: unknown) => error is FrozenRefusal;
|
|
34
42
|
/** Record why a refusal happened on the refusal itself, for the trusted reader
|
|
35
43
|
* only. Every opaque refusal takes its reason this way — a tenant denial, a
|
|
36
44
|
* row policy that did not load, a command the database would not take — so
|
package/dist/shared/refusal.js
CHANGED
|
@@ -44,6 +44,21 @@ export class RequestFault extends Refusal {
|
|
|
44
44
|
}
|
|
45
45
|
/** Whether a refusal is a request that can never succeed as written (`RequestFault`), from any copy of the module. */
|
|
46
46
|
export const isRequestFault = (error) => error instanceof Error && error[REQUEST_FAULT] === true;
|
|
47
|
+
/* A write to a record its resource declares frozen (`frozen: 'status = closed'`): the record's state, never the
|
|
48
|
+
caller's grants, so every door that says a refusal's status and code says this one 409 `frozen`. Branded as
|
|
49
|
+
RequestFault is, for a handler's second copy of this module. */
|
|
50
|
+
const FROZEN_REFUSAL = Symbol.for('mistri.frozenRefusal');
|
|
51
|
+
export class FrozenRefusal extends Refusal {
|
|
52
|
+
[FROZEN_REFUSAL] = true;
|
|
53
|
+
/** The sentence the caller reads: it names the resource and the condition, never a value of the row. */
|
|
54
|
+
constructor(message) {
|
|
55
|
+
super(message);
|
|
56
|
+
this.name = 'FrozenRefusal';
|
|
57
|
+
sayRefusal(this, message);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
/** Whether a refusal is a frozen record's (`FrozenRefusal`), from any copy of the module. */
|
|
61
|
+
export const isFrozenRefusal = (error) => error instanceof Error && error[FROZEN_REFUSAL] === true;
|
|
47
62
|
/* Why a refusal happened, kept for the trusted owner that has to diagnose it.
|
|
48
63
|
A caller hears one fixed sentence and must: a driver's error text names
|
|
49
64
|
columns, values and internal tables, and a clash on a hidden unique column
|
|
@@ -134,7 +134,7 @@ type ResourceHttpIdentity<Mode extends ResourceHttpMode> = Mode extends 'app' ?
|
|
|
134
134
|
conn?: string;
|
|
135
135
|
app?: never;
|
|
136
136
|
};
|
|
137
|
-
type HttpErrorCode = 'validation_failed' | 'consumes_refused' | 'record_conflict' | 'required_value' | 'duplicate_value' | 'reference_conflict' | 'constraint_failed' | 'data_unavailable' | 'write_unconfirmed' | 'forbidden' | 'undo_failed';
|
|
137
|
+
type HttpErrorCode = 'validation_failed' | 'consumes_refused' | 'frozen' | 'record_conflict' | 'required_value' | 'duplicate_value' | 'reference_conflict' | 'constraint_failed' | 'data_unavailable' | 'write_unconfirmed' | 'forbidden' | 'undo_failed';
|
|
138
138
|
export interface HttpDiagnostic {
|
|
139
139
|
message: string;
|
|
140
140
|
at?: number;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { type DatabaseSchema } from './schema.js';
|
|
2
|
+
type Cell = string | number | boolean | null | undefined;
|
|
3
|
+
/** True when `row` plainly meets the condition `text` over `tableId`; false wherever that cannot be said exactly. */
|
|
4
|
+
export declare function rowMeetsCondition(schema: DatabaseSchema | undefined, tableId: string, text: string, row: Readonly<Record<string, Cell>>): boolean;
|
|
5
|
+
export {};
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { ANYONE, parseQuery } from './query.js';
|
|
2
|
+
import { columnKind } from './schema.js';
|
|
3
|
+
const parsed = new WeakMap();
|
|
4
|
+
/** The condition's groups (ORed, each ANDed), or null where it does not parse over the table. */
|
|
5
|
+
function groupsOf(schema, table, text) {
|
|
6
|
+
let known = parsed.get(schema);
|
|
7
|
+
if (!known)
|
|
8
|
+
parsed.set(schema, (known = new Map()));
|
|
9
|
+
const at = `${table.id} ${text}`;
|
|
10
|
+
if (known.has(at))
|
|
11
|
+
return known.get(at);
|
|
12
|
+
const result = parseQuery(at, { schema, columnValues: true, me: ANYONE });
|
|
13
|
+
const groups = result.errors.length || !result.query ? null : result.query.filter.groups;
|
|
14
|
+
known.set(at, groups);
|
|
15
|
+
return groups;
|
|
16
|
+
}
|
|
17
|
+
const truthy = (value) => value === true || value === 1 || /^(1|true|t|yes|y)$/i.test(String(value));
|
|
18
|
+
function met(table, row, condition) {
|
|
19
|
+
if (condition.other !== undefined || condition.any !== undefined || condition.within !== undefined || condition.column.includes('.'))
|
|
20
|
+
return false;
|
|
21
|
+
if (!Object.hasOwn(row, condition.column))
|
|
22
|
+
return false;
|
|
23
|
+
const column = table.columns.find((candidate) => candidate.name === condition.column);
|
|
24
|
+
if (!column)
|
|
25
|
+
return false;
|
|
26
|
+
const value = row[condition.column];
|
|
27
|
+
const empty = value === null || value === undefined;
|
|
28
|
+
if (condition.op === 'isNull')
|
|
29
|
+
return empty;
|
|
30
|
+
if (condition.op === 'isNotNull')
|
|
31
|
+
return !empty;
|
|
32
|
+
if (empty)
|
|
33
|
+
return false;
|
|
34
|
+
const kind = columnKind(column.type);
|
|
35
|
+
const same = (given) => given !== null &&
|
|
36
|
+
given !== undefined &&
|
|
37
|
+
(kind === 'number'
|
|
38
|
+
? Number(value) === Number(given)
|
|
39
|
+
: kind === 'boolean'
|
|
40
|
+
? truthy(value) === truthy(given)
|
|
41
|
+
: String(value) === String(given));
|
|
42
|
+
const given = condition.value;
|
|
43
|
+
switch (condition.op) {
|
|
44
|
+
case '=':
|
|
45
|
+
return !Array.isArray(given) && same(given);
|
|
46
|
+
case '!=':
|
|
47
|
+
return !Array.isArray(given) && given !== null && given !== undefined && !same(given);
|
|
48
|
+
case 'in':
|
|
49
|
+
return Array.isArray(given) && given.some(same);
|
|
50
|
+
case '>':
|
|
51
|
+
case '>=':
|
|
52
|
+
case '<':
|
|
53
|
+
case '<=': {
|
|
54
|
+
if (Array.isArray(given) || given === null || given === undefined)
|
|
55
|
+
return false;
|
|
56
|
+
const [left, right] = kind === 'number' ? [Number(value), Number(given)] : [String(value), String(given)];
|
|
57
|
+
if (kind !== 'number' && kind !== 'date')
|
|
58
|
+
return false;
|
|
59
|
+
if (typeof left === 'number' && Number.isNaN(left))
|
|
60
|
+
return false;
|
|
61
|
+
return condition.op === '>'
|
|
62
|
+
? left > right
|
|
63
|
+
: condition.op === '>='
|
|
64
|
+
? left >= right
|
|
65
|
+
: condition.op === '<'
|
|
66
|
+
? left < right
|
|
67
|
+
: left <= right;
|
|
68
|
+
}
|
|
69
|
+
default:
|
|
70
|
+
return false;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
/** True when `row` plainly meets the condition `text` over `tableId`; false wherever that cannot be said exactly. */
|
|
74
|
+
export function rowMeetsCondition(schema, tableId, text, row) {
|
|
75
|
+
const table = schema?.tables.find((candidate) => candidate.id === tableId);
|
|
76
|
+
if (!schema || !table)
|
|
77
|
+
return false;
|
|
78
|
+
const groups = groupsOf(schema, table, text);
|
|
79
|
+
return groups !== null && groups.some((group) => group.length > 0 && group.every((condition) => met(table, row, condition)));
|
|
80
|
+
}
|
package/dist/shared/schema.d.ts
CHANGED
|
@@ -142,9 +142,19 @@ export declare function chooseColumnReference(candidates: readonly ColumnReferen
|
|
|
142
142
|
* column the connection already hides, rather than be told it is no column.
|
|
143
143
|
*/
|
|
144
144
|
export declare const CONNECTION_HIDDEN: unique symbol;
|
|
145
|
+
/**
|
|
146
|
+
* Of a table's declared rollups and computed columns, the ones a reader's
|
|
147
|
+
* field grant names (ColumnGrant.derived), set by pruning to that grant. They
|
|
148
|
+
* are added after pruning (the App's catalog), so pruning cannot cut them;
|
|
149
|
+
* this says which to keep. Absent, every one whose inputs the reader reads.
|
|
150
|
+
* A symbol, so it is never written into a JSON answer.
|
|
151
|
+
*/
|
|
152
|
+
export declare const GRANTED_DERIVED: unique symbol;
|
|
145
153
|
export interface TableMeta {
|
|
146
154
|
/** What the connection hides of this table (CONNECTION_HIDDEN); never serialized. */
|
|
147
155
|
readonly [CONNECTION_HIDDEN]?: readonly string[];
|
|
156
|
+
/** Of its rollups and computed columns, the ones the reader's field grant names (GRANTED_DERIVED); never serialized. */
|
|
157
|
+
readonly [GRANTED_DERIVED]?: readonly string[];
|
|
148
158
|
name: string;
|
|
149
159
|
/** Server-projected delete affordance, never authority; may account for hidden columns. */
|
|
150
160
|
deletable?: boolean;
|
package/dist/shared/schema.js
CHANGED
|
@@ -60,6 +60,14 @@ export function chooseColumnReference(candidates) {
|
|
|
60
60
|
* column the connection already hides, rather than be told it is no column.
|
|
61
61
|
*/
|
|
62
62
|
export const CONNECTION_HIDDEN = Symbol('mistri.connectionHidden');
|
|
63
|
+
/**
|
|
64
|
+
* Of a table's declared rollups and computed columns, the ones a reader's
|
|
65
|
+
* field grant names (ColumnGrant.derived), set by pruning to that grant. They
|
|
66
|
+
* are added after pruning (the App's catalog), so pruning cannot cut them;
|
|
67
|
+
* this says which to keep. Absent, every one whose inputs the reader reads.
|
|
68
|
+
* A symbol, so it is never written into a JSON answer.
|
|
69
|
+
*/
|
|
70
|
+
export const GRANTED_DERIVED = Symbol('mistri.grantedDerived');
|
|
63
71
|
/**
|
|
64
72
|
* A dialect's spelling of an `ON DELETE` action, normalised.
|
|
65
73
|
*
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Refusal } from './refusal.js';
|
|
2
|
+
import { GRANTED_DERIVED } from './schema.js';
|
|
2
3
|
const refuse = () => {
|
|
3
4
|
throw new Refusal('The scoped catalog could not be verified. Refresh the catalog and permissions before continuing.');
|
|
4
5
|
};
|
|
@@ -73,7 +74,18 @@ function copyData(input) {
|
|
|
73
74
|
}
|
|
74
75
|
return Object.fromEntries(keys.map((key) => {
|
|
75
76
|
const descriptor = Object.getOwnPropertyDescriptor(value, key);
|
|
76
|
-
if (
|
|
77
|
+
if (!descriptor.enumerable || !('value' in descriptor))
|
|
78
|
+
return refuse();
|
|
79
|
+
/* The one symbol a catalog carries: which of a table's rollups and computed columns its reader's field
|
|
80
|
+
grant names (columnGrants.ts). It narrows what appRollups.ts serves and grants nothing, so it is
|
|
81
|
+
carried as a frozen list of names and left out of the fingerprint; any other symbol is refused. */
|
|
82
|
+
if (key === GRANTED_DERIVED) {
|
|
83
|
+
const names = descriptor.value;
|
|
84
|
+
if (!Array.isArray(names) || names.length > 4_096 || names.some((name) => !identifier(name)))
|
|
85
|
+
return refuse();
|
|
86
|
+
return [key, Object.freeze(names.map((name) => copy(name, depth + 1)))];
|
|
87
|
+
}
|
|
88
|
+
if (typeof key !== 'string')
|
|
77
89
|
return refuse();
|
|
78
90
|
if ((characters += key.length) > 16_777_216)
|
|
79
91
|
return refuse();
|
|
@@ -605,6 +605,8 @@ export interface ServedResource {
|
|
|
605
605
|
favorite?: true;
|
|
606
606
|
/** Its one row is a settings record, opened from the reader's settings under these words. */
|
|
607
607
|
settings?: string;
|
|
608
|
+
/** The condition (query language) that freezes a record: one it matches takes no write, and the page draws it read-only. */
|
|
609
|
+
frozen?: string;
|
|
608
610
|
/** What one record is called and several: New, a split's detail heading. */
|
|
609
611
|
noun?: AppNoun;
|
|
610
612
|
/** Its rows are files, as appFileRules resolved them: a list over it draws as attachments. */
|
|
@@ -711,9 +713,26 @@ export interface ServedApp<View extends object = ServedDashboardView | ServedFor
|
|
|
711
713
|
ai?: {
|
|
712
714
|
label: string;
|
|
713
715
|
};
|
|
716
|
+
/** The App-wide choices this reader can make (an App's `choose`), by name: each a table id of this reader's catalog,
|
|
717
|
+
the column its chooser shows, and whether the shell asks before the first page. A choice over a table this
|
|
718
|
+
reader cannot read is not here. */
|
|
719
|
+
choose?: Record<string, ServedChoice>;
|
|
720
|
+
/** The picks this person holds on the server, by choice name, each the row's key as text and proven under this reader
|
|
721
|
+
(a pick they can no longer read is left out). Present, even empty, only where the database keeps the preferences
|
|
722
|
+
store: it is how the shell knows a pick is written there too, and not only in the browser. */
|
|
723
|
+
picks?: Record<string, string>;
|
|
714
724
|
/** This reader may approve something an AI can propose: For review, `/{app}/review`, and the proposals list. */
|
|
715
725
|
review?: true;
|
|
716
726
|
}
|
|
727
|
+
/** One App-wide choice as the shell draws it (ServedApp.choose). */
|
|
728
|
+
export interface ServedChoice {
|
|
729
|
+
/** The table id the choice is a row of. */
|
|
730
|
+
table: string;
|
|
731
|
+
/** The column its chooser shows for a row; absent, the record's own label. */
|
|
732
|
+
label?: string;
|
|
733
|
+
/** The shell asks before the first page. */
|
|
734
|
+
required?: true;
|
|
735
|
+
}
|
|
717
736
|
/** A menu node as the view order reads it: a view's reference, a group of nodes, or a link elsewhere. */
|
|
718
737
|
export type ServedNavNode = {
|
|
719
738
|
view: string;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { FilterComputed } from './computedWhere.js';
|
|
1
2
|
import type { Op } from './filter.js';
|
|
2
3
|
export type StructuredScalar = string | number | boolean | null;
|
|
3
4
|
/** A validated condition, shared by execution and transport. Parsing may build
|
|
@@ -18,5 +19,7 @@ type StructuredCondition<Field extends 'column' | 'path'> = Record<Field, string
|
|
|
18
19
|
} : never));
|
|
19
20
|
export interface StructuredFilter<Field extends 'column' | 'path' = 'column'> {
|
|
20
21
|
groups: Array<Array<StructuredCondition<Field>>>;
|
|
22
|
+
/** The computed columns a column filter's conditions name, each checked where it is written (computedWhere.ts). */
|
|
23
|
+
computed?: Field extends 'column' ? FilterComputed : never;
|
|
21
24
|
}
|
|
22
25
|
export {};
|
|
@@ -5,9 +5,10 @@
|
|
|
5
5
|
* from view.ts, which plans the joins these qualify against.
|
|
6
6
|
*/
|
|
7
7
|
import type { AnyRows, Condition, SqlStyle } from './filter.js';
|
|
8
|
-
import { type DatabaseSchema } from './schema.js';
|
|
8
|
+
import { type ColumnMeta, type DatabaseSchema } from './schema.js';
|
|
9
9
|
import type { JoinPlan } from './view.js';
|
|
10
10
|
import { type ResolvedPath, type ViewDef } from './viewPaths.js';
|
|
11
|
+
import { type ValueKind } from './computed.js';
|
|
11
12
|
import type { ScopedRelations } from './rowScope.js';
|
|
12
13
|
/**
|
|
13
14
|
* A view's paths, resolved and written against one join plan.
|
|
@@ -30,6 +31,10 @@ export declare function viewPaths(schema: DatabaseSchema, view: ViewDef, plan: J
|
|
|
30
31
|
exists: (rows: AnyRows) => string;
|
|
31
32
|
typeOf: (path: string) => string | undefined;
|
|
32
33
|
};
|
|
34
|
+
export declare function columnRead(column: ColumnMeta | undefined): {
|
|
35
|
+
kind: ValueKind;
|
|
36
|
+
native?: boolean;
|
|
37
|
+
} | undefined;
|
|
33
38
|
/**
|
|
34
39
|
* The view with the record-label templates its `$label` paths need, read from
|
|
35
40
|
* a catalog that serves them (an App's, `TableMeta.labelTemplate`) — and with
|
|
@@ -404,7 +404,7 @@ function dayText(value, style, literal) {
|
|
|
404
404
|
return `CASE WHEN ${iso} THEN ${style.concat([month, day, literal(', '), `SUBSTR(${value}, 1, 4)`])} ELSE COALESCE(${value}, '') END`;
|
|
405
405
|
}
|
|
406
406
|
/* What a stored column is to an expression that reads it: a yes-or-no column native or a 0/1 integer. */
|
|
407
|
-
function columnRead(column) {
|
|
407
|
+
export function columnRead(column) {
|
|
408
408
|
if (!column)
|
|
409
409
|
return undefined;
|
|
410
410
|
if (isFlagColumn(column))
|
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.78",
|
|
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": {
|
|
@@ -237,6 +237,7 @@
|
|
|
237
237
|
"./shared/resourceHttp.js": "./dist/shared/resourceHttp.js",
|
|
238
238
|
"./shared/richText.js": "./dist/shared/richText.js",
|
|
239
239
|
"./shared/rollups.js": "./dist/shared/rollups.js",
|
|
240
|
+
"./shared/rowCondition.js": "./dist/shared/rowCondition.js",
|
|
240
241
|
"./shared/rowScope.js": "./dist/shared/rowScope.js",
|
|
241
242
|
"./shared/runtimeTables.js": "./dist/shared/runtimeTables.js",
|
|
242
243
|
"./shared/schema.js": "./dist/shared/schema.js",
|
package/schema/model.d.ts
CHANGED
|
@@ -61,6 +61,11 @@ export type StaticAppTarget = AppTarget<string | number>;
|
|
|
61
61
|
* `{ record }` and `{ tenant }` are read when the form is prepared, so they
|
|
62
62
|
* fill a field of the input itself; `{ record }` on a command that targets one
|
|
63
63
|
* record.
|
|
64
|
+
*
|
|
65
|
+
* `{ answer: 'treatment.usual_fee' }` starts from another input's pick: the column of the row a choice from a table
|
|
66
|
+
* has picked (`field.choice({ from, labelColumn })`), or the key of the `values` a static option carries. It is
|
|
67
|
+
* filled when the person picks, in an input they have not edited, and stays theirs to change. The choice is another
|
|
68
|
+
* input of the same list: of the input itself, or of the same group or line. No input filled this way is another's source.
|
|
64
69
|
*/
|
|
65
70
|
export type CommandFieldDefault =
|
|
66
71
|
| string
|
|
@@ -68,7 +73,8 @@ export type CommandFieldDefault =
|
|
|
68
73
|
| boolean
|
|
69
74
|
| { readonly auto: 'today' | 'now' | 'me' }
|
|
70
75
|
| { readonly record: string }
|
|
71
|
-
| { readonly tenant: string }
|
|
76
|
+
| { readonly tenant: string }
|
|
77
|
+
| { readonly answer: string };
|
|
72
78
|
|
|
73
79
|
/** One option of a `choice` input. */
|
|
74
80
|
export interface AppCommandChoice {
|
|
@@ -83,8 +89,11 @@ export interface AppCommandChoice {
|
|
|
83
89
|
`tenant.<column>` alone (`"tenant.country = 'IN'"`), shared through `auth.tenancy.shared`. Judged as the form
|
|
84
90
|
is prepared or a public form is served; a submitted withheld value is refused as no choice. */
|
|
85
91
|
when?: string;
|
|
86
|
-
/**
|
|
87
|
-
|
|
92
|
+
/** What picking this option fills into other inputs of the form: the keys inputs name in `default: { answer: '<this input>.<key>' }`. Scalars only. */
|
|
93
|
+
values?: Readonly<Record<string, string | number | boolean | null>>;
|
|
94
|
+
/** Set by the server on a table's row it served (`source.served`): the columns its `where` compares and the ones
|
|
95
|
+
other inputs start from (`default: { answer }`), so the page offers the rows the answers given match, and fills
|
|
96
|
+
from the pick, without a read of its own. Never written in an App. */
|
|
88
97
|
row?: Readonly<Record<string, string | number | boolean | null>>;
|
|
89
98
|
}
|
|
90
99
|
|