@mistriwork/engine 1.0.0-rc.48 → 1.0.0-rc.50
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/scoped/sqliteScopeCatalog.js +11 -2
- package/dist/shared/appMessages.js +1 -0
- package/dist/shared/computed.d.ts +5 -3
- package/dist/shared/computed.js +11 -0
- package/dist/shared/computedParse.js +14 -6
- package/dist/shared/computedValue.js +2 -0
- package/dist/shared/formValues.d.ts +4 -3
- package/dist/shared/formValues.js +12 -2
- package/dist/shared/frameworkWords.d.ts +35 -0
- package/dist/shared/frameworkWords.js +36 -0
- package/dist/shared/pageConfig.js +3 -2
- package/dist/shared/pageModel.d.ts +5 -0
- package/dist/shared/pageModel.js +14 -4
- package/dist/shared/query.d.ts +1 -1
- package/dist/shared/query.js +70 -7
- package/dist/shared/queryDates.d.ts +4 -0
- package/dist/shared/queryDates.js +41 -0
- package/dist/shared/queryOperands.d.ts +27 -0
- package/dist/shared/queryOperands.js +55 -1
- package/dist/shared/tagLists.d.ts +3 -0
- package/dist/shared/tagLists.js +3 -0
- package/dist/shared/view.js +5 -0
- package/package.json +2 -1
- package/schema/model.d.ts +35 -1
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { ANSI_STYLE, Refusal } from '../adapter.js';
|
|
2
2
|
import { cachedStatement as prepared } from '../sqliteHandles.js';
|
|
3
|
-
import { chooseColumnReference, deleteRuleOf, } from '../../shared/schema.js';
|
|
3
|
+
import { chooseColumnReference, columnKind, deleteRuleOf, } from '../../shared/schema.js';
|
|
4
4
|
import { mapScopeCatalog } from '../../shared/scopeCatalog.js';
|
|
5
|
+
import { flagsFromDDL, vocabularyFromDDL } from '../../shared/vocabulary.js';
|
|
5
6
|
import { referenceKey } from './scopedTransaction.js';
|
|
6
7
|
import { keyTypeRefusal, sqliteAffinity, sqliteKeyType, sqliteTypeSaid } from './keyTypes.js';
|
|
7
8
|
import { readSqliteTrigger, sqliteColumnCollations, sqliteConflictClauses } from './sqliteTriggers.js';
|
|
@@ -217,7 +218,7 @@ function scanSqliteScopeCatalog(db) {
|
|
|
217
218
|
try {
|
|
218
219
|
if (prepared(db, 'PRAGMA foreign_keys').get()?.foreign_keys !== 1)
|
|
219
220
|
return refuse();
|
|
220
|
-
const entries = prepared(db, "SELECT name, type FROM main.sqlite_schema WHERE type IN ('table', 'view') ORDER BY name").all();
|
|
221
|
+
const entries = prepared(db, "SELECT name, type, sql FROM main.sqlite_schema WHERE type IN ('table', 'view') ORDER BY name").all();
|
|
221
222
|
const listed = prepared(db, 'PRAGMA main.table_list').all();
|
|
222
223
|
// Unknown PRAGMAs can return nothing without throwing. Never interpret
|
|
223
224
|
// unavailable table-kind metadata as proof that a table is ordinary.
|
|
@@ -283,6 +284,12 @@ function scanSqliteScopeCatalog(db) {
|
|
|
283
284
|
!indexes.some((index) => index.origin === 'pk')
|
|
284
285
|
? primary[0].name
|
|
285
286
|
: undefined;
|
|
287
|
+
/* A CHECK's vocabulary and a 0-or-1 flag, read off the statement as the browser's catalog reads them (sqlite.ts):
|
|
288
|
+
evidence of how a value reads, never a grant (scopeCatalog.ts leaves both out of the fingerprint). A tenant
|
|
289
|
+
App judges a menu's `when` over its profile by them (appTenantProfile.ts menuFor), as check did. */
|
|
290
|
+
const names = columns.map((column) => column.name);
|
|
291
|
+
const vocabulary = typeof entry.sql === 'string' ? vocabularyFromDDL(entry.sql, names) : new Map();
|
|
292
|
+
const flags = typeof entry.sql === 'string' ? flagsFromDDL(entry.sql, names) : new Set();
|
|
286
293
|
tables.push({
|
|
287
294
|
id: entry.name,
|
|
288
295
|
name: entry.name,
|
|
@@ -295,6 +302,8 @@ function scanSqliteScopeCatalog(db) {
|
|
|
295
302
|
nullable: column.notnull === 0 && column.name !== identity && !(column.pk > 0 && (kind.wr === 1 || kind.strict === 1)),
|
|
296
303
|
...(column.dflt_value !== null ? { default: column.dflt_value } : {}),
|
|
297
304
|
...(column.name === identity ? { identity: 'by-default' } : {}),
|
|
305
|
+
...(vocabulary.has(column.name) ? { allowed: vocabulary.get(column.name) } : {}),
|
|
306
|
+
...(flags.has(column.name) && columnKind(column.type) === 'number' ? { flag: true } : {}),
|
|
298
307
|
// The database computes a generated column from its row: read like any other, never written.
|
|
299
308
|
...(generated(column) ? { writable: false } : {}),
|
|
300
309
|
})),
|
|
@@ -18,10 +18,12 @@
|
|
|
18
18
|
* account's email, as a fixed action's `set` writes it), comparisons,
|
|
19
19
|
* `and`/`or`/`not`, `in (…)`, `is empty`, arithmetic, and dates: a date minus a date is
|
|
20
20
|
* days, a date plus a number is that many days later, and a unit says others
|
|
21
|
-
* (`ends_on + term months`, `now - 30 minutes`).
|
|
21
|
+
* (`ends_on + term months`, `now - 30 minutes`). Six functions: `coalesce(a, b, …)`
|
|
22
22
|
* the first that has a value, `round(x)` and `round(x, 2)`, `abs(x)`, and
|
|
23
23
|
* `min(a, b, …)` and `max(a, b, …)` of numbers or dates, which have no value
|
|
24
|
-
* where one of theirs has none, as arithmetic has (`max(owed - paid, 0)`)
|
|
24
|
+
* where one of theirs has none, as arithmetic has (`max(owed - paid, 0)`), and
|
|
25
|
+
* `concat(a, b, …)`, text joined, where a part with no value reads as empty
|
|
26
|
+
* (`concat(first, ' ', last)`). There is no `||`: SQLite and PostgreSQL differ on what it does with a null.
|
|
25
27
|
* That covers a due flag, an age, a renewal day, a balance.
|
|
26
28
|
* Anything heavier is a database view or a generated column, which the
|
|
27
29
|
* catalog reads as a column already.
|
|
@@ -99,7 +101,7 @@ export interface ComputedJson {
|
|
|
99
101
|
keys: string[];
|
|
100
102
|
}
|
|
101
103
|
/** The functions an expression may call (computedParse.ts COMPUTED_FUNCTIONS): each written alike on every engine and worked out alike in JavaScript. */
|
|
102
|
-
export type ComputedFunction = 'coalesce' | 'round' | 'min' | 'max' | 'abs';
|
|
104
|
+
export type ComputedFunction = 'coalesce' | 'round' | 'min' | 'max' | 'abs' | 'concat';
|
|
103
105
|
interface ComputedSpan {
|
|
104
106
|
k: 'span';
|
|
105
107
|
of: ComputedNode;
|
package/dist/shared/computed.js
CHANGED
|
@@ -117,6 +117,14 @@ export function computedKind(node, kindOf) {
|
|
|
117
117
|
}
|
|
118
118
|
case 'call': {
|
|
119
119
|
const kinds = n.args.map(kind);
|
|
120
|
+
/* Text only: a number or a day said as text is written differently by each engine (3.0, 3), so joining one
|
|
121
|
+
would answer differently on SQLite and PostgreSQL. */
|
|
122
|
+
if (n.fn === 'concat') {
|
|
123
|
+
const other = kinds.find((each) => each !== 'text');
|
|
124
|
+
if (other)
|
|
125
|
+
throw new Error(`concat(…) joins text, and has a ${other}.`);
|
|
126
|
+
return 'text';
|
|
127
|
+
}
|
|
120
128
|
if (n.fn === 'round' || n.fn === 'abs') {
|
|
121
129
|
if (kinds.some((each) => each !== 'number'))
|
|
122
130
|
throw new Error(`${n.fn}(…) reads numbers.`);
|
|
@@ -307,6 +315,9 @@ export function compileComputed(computed, style, column, kindOf) {
|
|
|
307
315
|
return `ABS(${args[0]})`;
|
|
308
316
|
if (n.fn === 'coalesce')
|
|
309
317
|
return `COALESCE(${args.join(', ')})`;
|
|
318
|
+
/* A part with no value reads as empty, which the dialect's own `||` would not (a null swallows the whole). */
|
|
319
|
+
if (n.fn === 'concat')
|
|
320
|
+
return style.concat(args.map((arg) => `COALESCE(${arg}, '')`));
|
|
310
321
|
if (n.fn === 'round') {
|
|
311
322
|
const places = args[1] ?? '0';
|
|
312
323
|
/* A half rounds away from zero, of the figure as written: 1.005 is 1.01. PostgreSQL rounds a numeric so (a
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import { ComputedError } from './computed.js';
|
|
8
8
|
/** The functions an expression may call: each written alike on every engine and worked out alike in JavaScript. */
|
|
9
|
-
const COMPUTED_FUNCTIONS = ['coalesce', 'round', 'min', 'max', 'abs'];
|
|
9
|
+
const COMPUTED_FUNCTIONS = ['coalesce', 'round', 'min', 'max', 'abs', 'concat'];
|
|
10
10
|
const isFunction = (word) => COMPUTED_FUNCTIONS.includes(word);
|
|
11
11
|
/* The greatest number of places `round` keeps: past it a figure is no longer one an engine says exactly. */
|
|
12
12
|
const ROUND_PLACES = 10;
|
|
@@ -251,12 +251,20 @@ export function parseComputed(text, isColumn) {
|
|
|
251
251
|
expect(')');
|
|
252
252
|
const fn = lower;
|
|
253
253
|
const many = fn === 'coalesce' || fn === 'min' || fn === 'max';
|
|
254
|
-
if (
|
|
255
|
-
|
|
256
|
-
|
|
254
|
+
if (fn === 'concat'
|
|
255
|
+
? args.length < 1
|
|
256
|
+
: many
|
|
257
|
+
? args.length < 2
|
|
257
258
|
: fn === 'round'
|
|
258
|
-
?
|
|
259
|
-
:
|
|
259
|
+
? args.length < 1 || args.length > 2
|
|
260
|
+
: args.length !== 1)
|
|
261
|
+
throw new ComputedError(fn === 'concat'
|
|
262
|
+
? "concat(…) takes one text or more: concat(first, ' ', last)."
|
|
263
|
+
: many
|
|
264
|
+
? `${fn}(…) takes two values or more: ${fn}(a, b).`
|
|
265
|
+
: fn === 'round'
|
|
266
|
+
? 'round(…) takes a number and, if you like, how many places: round(total) or round(total, 2).'
|
|
267
|
+
: `${fn}(…) takes one number.`, token.at);
|
|
260
268
|
if (fn === 'round' && args[1] && !(args[1].k === 'number' && Number.isInteger(args[1].value) && args[1].value <= ROUND_PLACES))
|
|
261
269
|
throw new ComputedError(`round(…)'s places are a whole number from 0 to ${ROUND_PLACES}, written out: round(total, 2).`, token.at);
|
|
262
270
|
return { k: 'call', fn, args };
|
|
@@ -102,6 +102,8 @@ export function evaluateComputed(node, values, read = (path) => {
|
|
|
102
102
|
const args = n.args.map(value);
|
|
103
103
|
if (n.fn === 'coalesce')
|
|
104
104
|
return args.find((each) => each !== null) ?? null;
|
|
105
|
+
if (n.fn === 'concat')
|
|
106
|
+
return args.map((each) => (each === null ? '' : String(each))).join('');
|
|
105
107
|
if (args.some((each) => each === null))
|
|
106
108
|
return null;
|
|
107
109
|
if (n.fn === 'abs')
|
|
@@ -11,18 +11,19 @@ import type { ComputedValue } from './computed.js';
|
|
|
11
11
|
/** Data only: local columns, no paths, expressions, clock or executable hooks. */
|
|
12
12
|
export type FormScalar = string | number | boolean | null;
|
|
13
13
|
/** The comparisons a compiled condition holds: the query language's own, named for the evaluator. */
|
|
14
|
-
export type FormOperator = 'eq' | 'ne' | 'lt' | 'lte' | 'gt' | 'gte';
|
|
14
|
+
export type FormOperator = 'eq' | 'ne' | 'lt' | 'lte' | 'gt' | 'gte' | 'has';
|
|
15
15
|
/**
|
|
16
16
|
* A condition in the query language — the one a page section's `when` and an
|
|
17
17
|
* action's `when` speak — read against a record's own values rather than run
|
|
18
18
|
* as SQL: "completed = false", "stage = closed_won and probability < 100".
|
|
19
19
|
* One language for every condition an App writes; what a form or a rule can
|
|
20
20
|
* evaluate in memory is its comparisons of local columns (`=`, `!=`, `<`,
|
|
21
|
-
* `<=`, `>`, `>=`, `in`, `is (not) empty`) under `and`, `or` and brackets
|
|
21
|
+
* `<=`, `>`, `>=`, `in`, `is (not) empty`) under `and`, `or` and brackets, and for an answer of several choices
|
|
22
|
+
* `has` (`services has cleaning`, `services has (cleaning, repairs)`: it holds any of them).
|
|
22
23
|
*/
|
|
23
24
|
export type FormCondition = string;
|
|
24
25
|
/** One compiled comparison: true when the field compares with any of the values (one, or an `in` list), or with
|
|
25
|
-
* the record's own `other` column. */
|
|
26
|
+
* the record's own `other` column; for `has`, when the field's list of answers holds any of the values. */
|
|
26
27
|
interface Comparison {
|
|
27
28
|
field: string;
|
|
28
29
|
operator: FormOperator;
|
|
@@ -76,9 +76,11 @@ function comparison(condition, where, paths) {
|
|
|
76
76
|
return { field: condition.column, operator: 'ne', values: [null] };
|
|
77
77
|
if (condition.op === 'in')
|
|
78
78
|
return { field: condition.column, operator: 'eq', values: values(condition.value) };
|
|
79
|
+
if (condition.op === 'has')
|
|
80
|
+
return { field: condition.column, operator: 'has', values: values(condition.value) };
|
|
79
81
|
const op = QUERY_OPERATORS[condition.op];
|
|
80
82
|
if (!op) {
|
|
81
|
-
throw new Error(`${where}: "${condition.op}" matches text, which a condition here cannot; compare with =, !=, <, <=, >, >=, in or is empty.`);
|
|
83
|
+
throw new Error(`${where}: "${condition.op}" matches text, which a condition here cannot; compare with =, !=, <, <=, >, >=, in, has (a list of several choices) or is empty.`);
|
|
82
84
|
}
|
|
83
85
|
return { field: condition.column, operator: op, values: values(condition.value) };
|
|
84
86
|
}
|
|
@@ -279,13 +281,21 @@ export function comparisonResult(p, row, columns) {
|
|
|
279
281
|
const column = columnNamed(columns, p.field);
|
|
280
282
|
if (!column)
|
|
281
283
|
return 'unknown';
|
|
284
|
+
if (p.operator === 'has') {
|
|
285
|
+
/* An answer of several choices is a list; its values compare as text, so a number option is asked as it is written. */
|
|
286
|
+
const answers = rowValue(row, p.field);
|
|
287
|
+
if (!Array.isArray(answers))
|
|
288
|
+
return 'unknown';
|
|
289
|
+
return p.values.some((value) => answers.some((answer) => String(answer) === String(value)));
|
|
290
|
+
}
|
|
282
291
|
if (p.other !== undefined) {
|
|
283
292
|
const other = columnNamed(columns, p.other);
|
|
284
293
|
return !other || family(column) !== family(other)
|
|
285
294
|
? 'unknown'
|
|
286
295
|
: compare(normalize(column, rowValue(row, p.field)), p.operator, normalize(other, rowValue(row, p.other)));
|
|
287
296
|
}
|
|
288
|
-
const
|
|
297
|
+
const operator = p.operator;
|
|
298
|
+
const results = p.values.map((value) => compare(normalize(column, rowValue(row, p.field)), operator, normalize(column, value)));
|
|
289
299
|
return results.includes('unknown') ? 'unknown' : results.some((r) => r === true);
|
|
290
300
|
}
|
|
291
301
|
export function conditionResult(condition, row, columns) {
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The fixed words the platform says on an App's command and public forms, which the App's own catalog may say instead
|
|
3
|
+
* (`messages/<locale>.ts`, a `mistri.*` key). Without them an App translated into Spanish still said "Step 2 of 3",
|
|
4
|
+
* "Back" and "(optional)" in English around its own words. Each key's English is what the platform says when the
|
|
5
|
+
* App's catalog has no word for it in the reader's language, so a key is opt-in and an App without one changes
|
|
6
|
+
* nothing. The server checks an App's `mistri.*` keys against this table (server/app/appMessages.ts readCatalogs)
|
|
7
|
+
* and serves the ones it has, in the reader's words, as plain `{name}` templates (`words`); the client says them in
|
|
8
|
+
* place of its own (`appWord`, kit client/messages.ts).
|
|
9
|
+
*/
|
|
10
|
+
export declare const FRAMEWORK_WORDS: {
|
|
11
|
+
readonly 'mistri.form.step': 'Step {step} of {count}';
|
|
12
|
+
readonly 'mistri.form.stepNamed': 'Step {step} of {count}: {label}';
|
|
13
|
+
readonly 'mistri.form.back': 'Back';
|
|
14
|
+
readonly 'mistri.form.optional': '(optional)';
|
|
15
|
+
readonly 'mistri.form.required': '(required)';
|
|
16
|
+
readonly 'mistri.form.reference': 'Your reference';
|
|
17
|
+
readonly 'mistri.form.signAgain': 'Sign again';
|
|
18
|
+
readonly 'mistri.form.yes': 'Yes';
|
|
19
|
+
readonly 'mistri.form.no': 'No';
|
|
20
|
+
readonly 'mistri.form.monthHint': 'MM/YYYY';
|
|
21
|
+
readonly 'mistri.form.dateTimeHint': 'YYYY-MM-DD HH:MM';
|
|
22
|
+
readonly 'mistri.status.offerEmail': 'We can email a code to the address on this application. It opens its details once, for 10 minutes.';
|
|
23
|
+
readonly 'mistri.status.offerText': 'We can send a code to the phone number on this application. It opens its details once, for 10 minutes.';
|
|
24
|
+
readonly 'mistri.status.askEmail': 'Email me a code';
|
|
25
|
+
readonly 'mistri.status.askText': 'Send me a code';
|
|
26
|
+
readonly 'mistri.status.sentEmail': 'We sent a code to your email.';
|
|
27
|
+
readonly 'mistri.status.sentText': 'We sent a code by text message.';
|
|
28
|
+
readonly 'mistri.status.codeEmail': 'Code from the email';
|
|
29
|
+
readonly 'mistri.status.codeText': 'Code from the message';
|
|
30
|
+
};
|
|
31
|
+
export type FrameworkWordKey = keyof typeof FRAMEWORK_WORDS;
|
|
32
|
+
/** A catalog key the platform reserves: an App's catalog may say it only as one of FRAMEWORK_WORDS. */
|
|
33
|
+
export declare const isFrameworkWordKey: (key: string) => boolean;
|
|
34
|
+
/** The `{name}` arguments a built-in word's English reads: all an App's word for it may read. */
|
|
35
|
+
export declare function frameworkWordArgs(key: FrameworkWordKey): Set<string>;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The fixed words the platform says on an App's command and public forms, which the App's own catalog may say instead
|
|
3
|
+
* (`messages/<locale>.ts`, a `mistri.*` key). Without them an App translated into Spanish still said "Step 2 of 3",
|
|
4
|
+
* "Back" and "(optional)" in English around its own words. Each key's English is what the platform says when the
|
|
5
|
+
* App's catalog has no word for it in the reader's language, so a key is opt-in and an App without one changes
|
|
6
|
+
* nothing. The server checks an App's `mistri.*` keys against this table (server/app/appMessages.ts readCatalogs)
|
|
7
|
+
* and serves the ones it has, in the reader's words, as plain `{name}` templates (`words`); the client says them in
|
|
8
|
+
* place of its own (`appWord`, kit client/messages.ts).
|
|
9
|
+
*/
|
|
10
|
+
export const FRAMEWORK_WORDS = {
|
|
11
|
+
'mistri.form.step': 'Step {step} of {count}',
|
|
12
|
+
'mistri.form.stepNamed': 'Step {step} of {count}: {label}',
|
|
13
|
+
'mistri.form.back': 'Back',
|
|
14
|
+
'mistri.form.optional': '(optional)',
|
|
15
|
+
'mistri.form.required': '(required)',
|
|
16
|
+
'mistri.form.reference': 'Your reference',
|
|
17
|
+
'mistri.form.signAgain': 'Sign again',
|
|
18
|
+
'mistri.form.yes': 'Yes',
|
|
19
|
+
'mistri.form.no': 'No',
|
|
20
|
+
'mistri.form.monthHint': 'MM/YYYY',
|
|
21
|
+
'mistri.form.dateTimeHint': 'YYYY-MM-DD HH:MM',
|
|
22
|
+
'mistri.status.offerEmail': 'We can email a code to the address on this application. It opens its details once, for 10 minutes.',
|
|
23
|
+
'mistri.status.offerText': 'We can send a code to the phone number on this application. It opens its details once, for 10 minutes.',
|
|
24
|
+
'mistri.status.askEmail': 'Email me a code',
|
|
25
|
+
'mistri.status.askText': 'Send me a code',
|
|
26
|
+
'mistri.status.sentEmail': 'We sent a code to your email.',
|
|
27
|
+
'mistri.status.sentText': 'We sent a code by text message.',
|
|
28
|
+
'mistri.status.codeEmail': 'Code from the email',
|
|
29
|
+
'mistri.status.codeText': 'Code from the message',
|
|
30
|
+
};
|
|
31
|
+
/** A catalog key the platform reserves: an App's catalog may say it only as one of FRAMEWORK_WORDS. */
|
|
32
|
+
export const isFrameworkWordKey = (key) => key.startsWith('mistri.');
|
|
33
|
+
/** The `{name}` arguments a built-in word's English reads: all an App's word for it may read. */
|
|
34
|
+
export function frameworkWordArgs(key) {
|
|
35
|
+
return new Set([...FRAMEWORK_WORDS[key].matchAll(/\{(\w+)\}/g)].map((match) => match[1]));
|
|
36
|
+
}
|
|
@@ -17,7 +17,7 @@ import { CONFIG_PAGE_RENAMED, CUSTOM_SECTION_RENAMED, LINK_INTENT_RENAMED, SECTI
|
|
|
17
17
|
import { parseSortText } from './sortText.js';
|
|
18
18
|
import { componentPropValues, parseComponentDecl, parsePageReads, parsePageTotals, parseRecordFields } from './appComponents.js';
|
|
19
19
|
import { parseAppLinkAction, parseAppTarget, parseLinkTo } from './appLinks.js';
|
|
20
|
-
import { WIDTHS, OFFSETS, SECTION_REGIONS, FIELD_COLUMNS, MAX_STREAMS, MAX_HISTORY_LIMIT, MAX_SECTIONS, MAX_PAGE_SECTIONS, screenSections, GROUPS_MOST, GROUP_ROWS_MOST, } from './pageModel.js';
|
|
20
|
+
import { WIDTHS, OFFSETS, SECTION_REGIONS, FIELD_COLUMNS, MAX_STREAMS, MAX_HISTORY_LIMIT, MAX_SECTIONS, MAX_PAGE_SECTIONS, screenSections, screenSectionsSaid, GROUPS_MOST, GROUP_ROWS_MOST, } from './pageModel.js';
|
|
21
21
|
/* ---------- config ---------- */
|
|
22
22
|
/**
|
|
23
23
|
* Read the `pages` section of a tablewalk.json.
|
|
@@ -209,7 +209,8 @@ function parseSections(raw, at, name, config) {
|
|
|
209
209
|
const drawn = screenSections(sections);
|
|
210
210
|
if (drawn > MAX_SECTIONS) {
|
|
211
211
|
throw new Error(`${at} ("${name}") has more than ${MAX_SECTIONS} sections on one screen (${drawn}). A page is a screen, not a report: ` +
|
|
212
|
-
|
|
212
|
+
`a screen counts the sections in no tab plus its fullest tab's, in each region (here ${screenSectionsSaid(sections)}), ` +
|
|
213
|
+
'so give some of them a "tab", and each tab is counted as a screen of its own.');
|
|
213
214
|
}
|
|
214
215
|
/* A record has one head. */
|
|
215
216
|
if (sections.filter((s) => s.kind === 'fields' && s.presentation === 'header').length > 1) {
|
|
@@ -855,6 +855,11 @@ export declare function screenSections(sections: readonly {
|
|
|
855
855
|
region?: SectionRegion;
|
|
856
856
|
tab?: string;
|
|
857
857
|
}[]): number;
|
|
858
|
+
/** How that count is made, for the sentence that refuses a page over the ceiling: "main 18 in no tab + 6 in its fullest tab". */
|
|
859
|
+
export declare function screenSectionsSaid(sections: readonly {
|
|
860
|
+
region?: SectionRegion;
|
|
861
|
+
tab?: string;
|
|
862
|
+
}[]): string;
|
|
858
863
|
/** A workflow step's label when it names none: `in_review` reads "In review". */
|
|
859
864
|
export declare function workflowLabel(value: string): string;
|
|
860
865
|
export {};
|
package/dist/shared/pageModel.js
CHANGED
|
@@ -105,8 +105,8 @@ export const HISTORY_TAB = 'history';
|
|
|
105
105
|
export const MAX_SECTIONS = 24;
|
|
106
106
|
/** Sections a page may hold in all, every tab's included. */
|
|
107
107
|
export const MAX_PAGE_SECTIONS = 96;
|
|
108
|
-
/**
|
|
109
|
-
|
|
108
|
+
/** Per region, the sections in no tab and the fullest tab's: what one screen of the page draws. */
|
|
109
|
+
function screenCounts(sections) {
|
|
110
110
|
const regions = new Map();
|
|
111
111
|
for (const section of sections) {
|
|
112
112
|
const region = section.region ?? 'main';
|
|
@@ -117,11 +117,21 @@ export function screenSections(sections) {
|
|
|
117
117
|
else
|
|
118
118
|
counted.tabs.set(section.tab, (counted.tabs.get(section.tab) ?? 0) + 1);
|
|
119
119
|
}
|
|
120
|
+
return new Map([...regions].map(([region, { untabbed, tabs }]) => [region, { untabbed, fullest: Math.max(0, ...tabs.values()) }]));
|
|
121
|
+
}
|
|
122
|
+
/** How many sections a page draws on its fullest screen: per region, those in no tab and its largest tab's. */
|
|
123
|
+
export function screenSections(sections) {
|
|
120
124
|
let most = 0;
|
|
121
|
-
for (const { untabbed,
|
|
122
|
-
most += untabbed +
|
|
125
|
+
for (const { untabbed, fullest } of screenCounts(sections).values())
|
|
126
|
+
most += untabbed + fullest;
|
|
123
127
|
return most;
|
|
124
128
|
}
|
|
129
|
+
/** How that count is made, for the sentence that refuses a page over the ceiling: "main 18 in no tab + 6 in its fullest tab". */
|
|
130
|
+
export function screenSectionsSaid(sections) {
|
|
131
|
+
return [...screenCounts(sections)]
|
|
132
|
+
.map(([region, { untabbed, fullest }]) => `${region} ${untabbed} in no tab${fullest ? ` + ${fullest} in its fullest tab` : ''}`)
|
|
133
|
+
.join(', ');
|
|
134
|
+
}
|
|
125
135
|
/** A workflow step's label when it names none: `in_review` reads "In review". */
|
|
126
136
|
export function workflowLabel(value) {
|
|
127
137
|
const words = value.replaceAll('_', ' ');
|
package/dist/shared/query.d.ts
CHANGED
|
@@ -129,7 +129,7 @@ export declare function expandSegments(text: string, segments: Readonly<Record<s
|
|
|
129
129
|
*/
|
|
130
130
|
export declare function quoteValue(value: unknown): string;
|
|
131
131
|
export type { QueryPerson } from './queryOperands.js';
|
|
132
|
-
export { ANYONE } from './queryOperands.js';
|
|
132
|
+
export { ANYONE, ANYONE_ONCE } from './queryOperands.js';
|
|
133
133
|
interface ParseOptions {
|
|
134
134
|
schema?: DatabaseSchema;
|
|
135
135
|
/** Injected so compilation is deterministic and testable. */
|
package/dist/shared/query.js
CHANGED
|
@@ -4,8 +4,8 @@ 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, tenantOperand } from './queryOperands.js';
|
|
8
|
-
import { TAGS_TYPE } from './tagLists.js';
|
|
7
|
+
import { ME_SET, TENANT_FIELD, columnOperand, meOperand, meSetOperand, tenantHolds, tenantOperand, } from './queryOperands.js';
|
|
8
|
+
import { CHOICES_TYPE, TAGS_TYPE } from './tagLists.js';
|
|
9
9
|
import { DEFINED_PATH_TYPE } from './definedFields.js';
|
|
10
10
|
const RANGE_OPS = new Set(['<', '<=', '>', '>=']);
|
|
11
11
|
export { dateWindow } from './queryDates.js';
|
|
@@ -600,16 +600,64 @@ function resolveColumn(table, name) {
|
|
|
600
600
|
const suggestion = near ? ` Did you mean "${near}"?` : '';
|
|
601
601
|
return { error: `"${name}" is not a column on ${table.name}.${suggestion}` };
|
|
602
602
|
}
|
|
603
|
-
export { ANYONE } from './queryOperands.js';
|
|
603
|
+
export { ANYONE, ANYONE_ONCE } from './queryOperands.js';
|
|
604
604
|
/* A record's tags are asked only whether they hold a label: `tags = bug` would
|
|
605
605
|
compare the list itself, which is no question anyone means. */
|
|
606
606
|
function compileCondition(raw, ctx) {
|
|
607
|
+
const constant = tenantClause(raw.trim(), ctx);
|
|
608
|
+
if (constant)
|
|
609
|
+
return constant;
|
|
607
610
|
const compiled = compileClause(raw, ctx);
|
|
608
611
|
const tagged = compiled.conditions?.find((c) => c.op !== 'has' && ctx.table?.columns.find((col) => col.name === c.column)?.type === TAGS_TYPE);
|
|
609
612
|
if (tagged)
|
|
610
613
|
return { error: `"${tagged.column}" is a record's tags: ask it with has, as in ${tagged.column} has bug.` };
|
|
614
|
+
const listed = compiled.conditions?.find((c) => c.op !== 'has' && ctx.table?.columns.find((col) => col.name === c.column)?.type === CHOICES_TYPE);
|
|
615
|
+
if (listed)
|
|
616
|
+
return { error: `"${listed.column}" holds several choices: ask it with has, as in ${listed.column} has cleaning.` };
|
|
611
617
|
return compiled;
|
|
612
618
|
}
|
|
619
|
+
/**
|
|
620
|
+
* A condition on the reader's tenant (`tenant.plan = 'pro'`, `tenant.plan in (pro, team)`, `tenant.plan is empty`),
|
|
621
|
+
* judged for this request (queryOperands.ts tenantHolds): one that holds says `holds`, and its group asks nothing
|
|
622
|
+
* more of the row; one that does not is a condition no row meets. Undefined where the left is not that word: a
|
|
623
|
+
* table with a `tenant` column of its own, or a path the view parser found (`tenant.plan` through a reference).
|
|
624
|
+
*/
|
|
625
|
+
function tenantClause(text, ctx) {
|
|
626
|
+
const table = ctx.table;
|
|
627
|
+
const field = /^([\w.$+]+)/.exec(text)?.[1];
|
|
628
|
+
if (!table || !field || !TENANT_FIELD.test(field) || table.columns.some((c) => c.name === 'tenant') || !resolveColumn(table, field).error)
|
|
629
|
+
return undefined;
|
|
630
|
+
const rest = text.slice(field.length);
|
|
631
|
+
let judged;
|
|
632
|
+
const empty = /^\s+is\s+(not\s+)?empty$/i.exec(rest);
|
|
633
|
+
const listed = /^\s+(not\s+in|in)\s+(.+)$/i.exec(rest);
|
|
634
|
+
const symbol = /^\s*(!=|<=|>=|=|<|>)\s*(.+)$/.exec(rest);
|
|
635
|
+
if (empty)
|
|
636
|
+
judged = tenantHolds(ctx, field, empty[1] ? 'isNotNull' : 'isNull', []);
|
|
637
|
+
else if (listed) {
|
|
638
|
+
const items = listed[2]
|
|
639
|
+
.trim()
|
|
640
|
+
.replace(/^[([]\s*/, '')
|
|
641
|
+
.replace(/\s*[)\]]$/, '')
|
|
642
|
+
.split(',')
|
|
643
|
+
.map((s) => unquoteValue(s))
|
|
644
|
+
.filter((s) => s.value !== '');
|
|
645
|
+
if (!items.length)
|
|
646
|
+
return { error: `"${listed[1]}" needs at least one value` };
|
|
647
|
+
judged = tenantHolds(ctx, field, /^not/i.test(listed[1]) ? 'not in' : 'in', items);
|
|
648
|
+
}
|
|
649
|
+
else if (symbol)
|
|
650
|
+
judged = tenantHolds(ctx, field, symbol[1], [unquoteValue(symbol[2])]);
|
|
651
|
+
else
|
|
652
|
+
return { error: `${field} is the reader's tenant: ask it with =, !=, <, >, in or is empty, as in ${field} = 'pro'.` };
|
|
653
|
+
if (judged.error)
|
|
654
|
+
return { error: judged.error };
|
|
655
|
+
if (judged.holds)
|
|
656
|
+
return { conditions: [], holds: true };
|
|
657
|
+
/* No row: an empty list, which every engine says as a falsehood (filter.ts `never`), over a column every read has. */
|
|
658
|
+
const key = table.columns.find((c) => c.primaryKey) ?? table.columns[0];
|
|
659
|
+
return { conditions: [{ column: key.name, op: 'in', value: [] }] };
|
|
660
|
+
}
|
|
613
661
|
function compileClause(raw, ctx) {
|
|
614
662
|
const { table, now } = ctx;
|
|
615
663
|
const text = raw.trim();
|
|
@@ -714,8 +762,10 @@ function compileClause(raw, ctx) {
|
|
|
714
762
|
/* `tags has bug`, `tags has (bug, docs)`: a record's tags (TableMeta.tags)
|
|
715
763
|
hold any of the labels. A set, so a list never needs `in`. */
|
|
716
764
|
if (op === 'has') {
|
|
717
|
-
|
|
718
|
-
|
|
765
|
+
/* A parse with no table reads the words alone (a form's condition before its fields are known), so it cannot
|
|
766
|
+
say what the column is; the form judges that itself, against the fields it has. */
|
|
767
|
+
if (ctx.table && column?.type !== TAGS_TYPE && column?.type !== DEFINED_PATH_TYPE && column?.type !== CHOICES_TYPE)
|
|
768
|
+
return { error: `"has" asks a record's tags, a key of a JSON column or a form's several choices, and "${name}" is none of them.` };
|
|
719
769
|
const list = valueRaw
|
|
720
770
|
.trim()
|
|
721
771
|
.replace(/^[([]\s*/, '')
|
|
@@ -1191,26 +1241,39 @@ function parseUncached(input, options) {
|
|
|
1191
1241
|
errors.push({ message: `That expands to more than ${MAX_GROUPS} OR branches. Simplify it or filter in two steps.` });
|
|
1192
1242
|
}
|
|
1193
1243
|
else {
|
|
1244
|
+
/* A group whose every condition is the reader's tenant, and holds (`tenant.plan = 'pro'`), asks nothing of the
|
|
1245
|
+
row: every row is in it, so the filter is every row, whatever the other branches ask. */
|
|
1246
|
+
let everything = false;
|
|
1194
1247
|
for (const group of groups) {
|
|
1195
1248
|
const conditions = [];
|
|
1249
|
+
let held = 0;
|
|
1250
|
+
let failed = false;
|
|
1196
1251
|
for (const node of group) {
|
|
1197
1252
|
if (node.kind !== 'cond')
|
|
1198
1253
|
continue;
|
|
1199
|
-
const { conditions: got, error } = compileCondition(node.text, {
|
|
1254
|
+
const { conditions: got, error, holds, } = compileCondition(node.text, {
|
|
1200
1255
|
table,
|
|
1201
1256
|
now,
|
|
1202
1257
|
columnValues: options.columnValues === true,
|
|
1203
1258
|
...(options.me !== undefined ? { me: options.me } : {}),
|
|
1204
1259
|
...(options.states ? { states: options.states } : {}),
|
|
1205
1260
|
});
|
|
1206
|
-
if (error)
|
|
1261
|
+
if (error) {
|
|
1207
1262
|
errors.push({ message: error, at: said(node.at) });
|
|
1263
|
+
failed = true;
|
|
1264
|
+
}
|
|
1208
1265
|
else if (got)
|
|
1209
1266
|
conditions.push(...got);
|
|
1267
|
+
if (holds)
|
|
1268
|
+
held++;
|
|
1210
1269
|
}
|
|
1211
1270
|
if (conditions.length)
|
|
1212
1271
|
filter.groups.push(conditions);
|
|
1272
|
+
else if (held && !failed)
|
|
1273
|
+
everything = true;
|
|
1213
1274
|
}
|
|
1275
|
+
if (everything)
|
|
1276
|
+
filter.groups = [];
|
|
1214
1277
|
}
|
|
1215
1278
|
}
|
|
1216
1279
|
const orderBy = [];
|
|
@@ -3,6 +3,10 @@ interface DateWindow {
|
|
|
3
3
|
start: Date;
|
|
4
4
|
end: Date;
|
|
5
5
|
}
|
|
6
|
+
/** `today + 30 days` inside a longer text, each one found. */
|
|
7
|
+
export declare const DATE_ARITHMETIC: RegExp;
|
|
8
|
+
/** The day `today ± N units` names, from `today` (YYYY-MM-DD); a month or a year past the month's end lands on its last day. */
|
|
9
|
+
export declare function shiftedDay(today: string, sign: string, count: number, unit: string): string;
|
|
6
10
|
/**
|
|
7
11
|
* `now` is a parameter rather than a call to the clock, so the compiler is a
|
|
8
12
|
* pure function of its inputs. That is what makes the tests below able to
|
|
@@ -13,6 +13,37 @@ function addDays(d, n) {
|
|
|
13
13
|
c.setDate(c.getDate() + n);
|
|
14
14
|
return c;
|
|
15
15
|
}
|
|
16
|
+
/* ---------- today plus or minus N units ----------
|
|
17
|
+
|
|
18
|
+
One grammar for the day `today - 18 years` names, read by the query language (a window of that one day) and by a
|
|
19
|
+
command's conditions (`shared/commandDraft.ts`, which works the day out before it compiles), so the two cannot
|
|
20
|
+
come to mean different days. */
|
|
21
|
+
const ARITHMETIC_UNITS = {
|
|
22
|
+
day: 'day',
|
|
23
|
+
days: 'day',
|
|
24
|
+
week: 'day',
|
|
25
|
+
weeks: 'day',
|
|
26
|
+
month: 'month',
|
|
27
|
+
months: 'month',
|
|
28
|
+
year: 'year',
|
|
29
|
+
years: 'year',
|
|
30
|
+
};
|
|
31
|
+
const ARITHMETIC_SOURCE = String.raw `today\s*([+-])\s*(\d{1,4})\s*(days?|weeks?|months?|years?)`;
|
|
32
|
+
/** `today + 30 days` inside a longer text, each one found. */
|
|
33
|
+
export const DATE_ARITHMETIC = new RegExp(String.raw `\b${ARITHMETIC_SOURCE}\b`, 'gi');
|
|
34
|
+
const WHOLE_ARITHMETIC = new RegExp(`^${ARITHMETIC_SOURCE}$`, 'i');
|
|
35
|
+
/** The day `today ± N units` names, from `today` (YYYY-MM-DD); a month or a year past the month's end lands on its last day. */
|
|
36
|
+
export function shiftedDay(today, sign, count, unit) {
|
|
37
|
+
const [y, m, d] = today.split('-').map(Number);
|
|
38
|
+
const by = (sign === '-' ? -1 : 1) * count * (unit.toLowerCase().startsWith('week') ? 7 : 1);
|
|
39
|
+
const kind = ARITHMETIC_UNITS[unit.toLowerCase()];
|
|
40
|
+
if (kind === 'day')
|
|
41
|
+
return new Date(Date.UTC(y, m - 1, d + by)).toISOString().slice(0, 10);
|
|
42
|
+
const months = kind === 'year' ? by * 12 : by;
|
|
43
|
+
const first = new Date(Date.UTC(y, m - 1 + months, 1));
|
|
44
|
+
const last = new Date(Date.UTC(first.getUTCFullYear(), first.getUTCMonth() + 1, 0)).getUTCDate();
|
|
45
|
+
return new Date(Date.UTC(first.getUTCFullYear(), first.getUTCMonth(), Math.min(d, last))).toISOString().slice(0, 10);
|
|
46
|
+
}
|
|
16
47
|
/**
|
|
17
48
|
* `now` is a parameter rather than a call to the clock, so the compiler is a
|
|
18
49
|
* pure function of its inputs. That is what makes the tests below able to
|
|
@@ -51,6 +82,16 @@ export function dateWindow(phrase, now) {
|
|
|
51
82
|
const year = today.getFullYear() + (p === 'last year' ? -1 : 0);
|
|
52
83
|
return { label: p, start: new Date(year, 0, 1), end: new Date(year + 1, 0, 1) };
|
|
53
84
|
}
|
|
85
|
+
/* One day, not a span: `due = today + 30 days` is that whole day, and `next 30 days` stays the "within" form. */
|
|
86
|
+
const arithmetic = WHOLE_ARITHMETIC.exec(p);
|
|
87
|
+
if (arithmetic) {
|
|
88
|
+
const pad = (n) => String(n).padStart(2, '0');
|
|
89
|
+
const [, sign, count, unit] = arithmetic;
|
|
90
|
+
const day = shiftedDay(`${today.getFullYear()}-${pad(today.getMonth() + 1)}-${pad(today.getDate())}`, sign, Number(count), unit);
|
|
91
|
+
const [y, m, d] = day.split('-').map(Number);
|
|
92
|
+
const start = new Date(y, m - 1, d);
|
|
93
|
+
return { label: p, start, end: addDays(start, 1) };
|
|
94
|
+
}
|
|
54
95
|
const span = p.match(/^(last|next|previous)\s+(\d+)\s+(minute|hour|day|week|month|year)s?$/);
|
|
55
96
|
if (span) {
|
|
56
97
|
const [, dir, amountRaw, unit] = span;
|
|
@@ -24,6 +24,12 @@ export interface QueryPerson {
|
|
|
24
24
|
* read as no one's, so a segment about the person is judged by the rest of what it says.
|
|
25
25
|
*/
|
|
26
26
|
anyone?: true;
|
|
27
|
+
/**
|
|
28
|
+
* With `anyone`: the query is compiled once and kept for every request (a rollup's rows), so a fact of one
|
|
29
|
+
* request, `tenant.<column>`, cannot be read into it. Held for `anyone` alone, as a check before any request
|
|
30
|
+
* does; here refused, since a figure that held it for everyone would count every row.
|
|
31
|
+
*/
|
|
32
|
+
once?: true;
|
|
27
33
|
/**
|
|
28
34
|
* The table people are rows of (an App's `auth.me`), and the signed-in
|
|
29
35
|
* account's row key there — null when no row carries their email, which
|
|
@@ -53,6 +59,8 @@ export interface QueryPerson {
|
|
|
53
59
|
export type TenantValue = string | number | boolean | null;
|
|
54
60
|
/** Nobody in particular (`anyone` above): what a check that runs before any request reads `me` as. */
|
|
55
61
|
export declare const ANYONE: QueryPerson;
|
|
62
|
+
/** ANYONE for a query kept as it is compiled and served to every request: `tenant.<column>` is refused, not held. */
|
|
63
|
+
export declare const ANYONE_ONCE: QueryPerson;
|
|
56
64
|
/** One `me.<table>.<column>`: its values and their kind, or the sentence that refuses it. */
|
|
57
65
|
export type MeSet = {
|
|
58
66
|
values: readonly (string | number)[];
|
|
@@ -71,6 +79,25 @@ export interface CompileContext {
|
|
|
71
79
|
/** A machine's states by column, where the catalog does not carry them (a parse with no schema). */
|
|
72
80
|
states?: Readonly<Record<string, MachineStates>>;
|
|
73
81
|
}
|
|
82
|
+
/** `tenant.<column>` where a condition's left-hand column would be. */
|
|
83
|
+
export declare const TENANT_FIELD: RegExp;
|
|
84
|
+
/** How a condition with `tenant.<column>` on its left compares (`tenant.plan = 'pro'`, `tenant.plan in (pro, team)`). */
|
|
85
|
+
export type TenantTest = '=' | '!=' | '<' | '<=' | '>' | '>=' | 'in' | 'not in' | 'isNull' | 'isNotNull';
|
|
86
|
+
/**
|
|
87
|
+
* `tenant.<column>` on the left of a condition (`tenant.plan = 'pro'`): no column of the row but a fact of this
|
|
88
|
+
* request, as a menu's or a command input's `when` reads it (commandWhen.ts foldWhen), so the condition holds of
|
|
89
|
+
* every row or of none. Judged against the profile as that fold judges it: a null value meets only `is empty`, and
|
|
90
|
+
* a value written is read as the profile's kind (a number, a flag, text). Refused with the words the right-hand
|
|
91
|
+
* form uses where no tenant is meant or the column is not shared. A check before any request (ANYONE) holds it,
|
|
92
|
+
* and the request judges it.
|
|
93
|
+
*/
|
|
94
|
+
export declare function tenantHolds(ctx: CompileContext, word: string, test: TenantTest, values: readonly {
|
|
95
|
+
value: string;
|
|
96
|
+
quoted: boolean;
|
|
97
|
+
}[]): {
|
|
98
|
+
holds?: boolean;
|
|
99
|
+
error?: string;
|
|
100
|
+
};
|
|
74
101
|
/**
|
|
75
102
|
* What `tenant.<column>` stands for beside one column: the profile's value, read for
|
|
76
103
|
* this request. Undefined where the word is not one (quoted, or the table has a
|
|
@@ -3,8 +3,62 @@ import { columnKind } from './schema.js';
|
|
|
3
3
|
const TENANT_VALUE = /^tenant\.([A-Za-z_]\w*)$/;
|
|
4
4
|
/** Nobody in particular (`anyone` above): what a check that runs before any request reads `me` as. */
|
|
5
5
|
export const ANYONE = Object.freeze({ email: null, anyone: true });
|
|
6
|
+
/** ANYONE for a query kept as it is compiled and served to every request: `tenant.<column>` is refused, not held. */
|
|
7
|
+
export const ANYONE_ONCE = Object.freeze({ email: null, anyone: true, once: true });
|
|
8
|
+
const ONCE_TENANT = (word) => `${word} is a fact of one request's tenant, and this query is read once for every request, so it cannot ask it. Test the tenant in a \`when\` instead.`;
|
|
6
9
|
/** `me.<table>.<column>`, written as one item of a value list. */
|
|
7
10
|
export const ME_SET = /^me\.([A-Za-z_]\w*)\.([A-Za-z_]\w*)$/;
|
|
11
|
+
/** `tenant.<column>` where a condition's left-hand column would be. */
|
|
12
|
+
export const TENANT_FIELD = TENANT_VALUE;
|
|
13
|
+
/**
|
|
14
|
+
* `tenant.<column>` on the left of a condition (`tenant.plan = 'pro'`): no column of the row but a fact of this
|
|
15
|
+
* request, as a menu's or a command input's `when` reads it (commandWhen.ts foldWhen), so the condition holds of
|
|
16
|
+
* every row or of none. Judged against the profile as that fold judges it: a null value meets only `is empty`, and
|
|
17
|
+
* a value written is read as the profile's kind (a number, a flag, text). Refused with the words the right-hand
|
|
18
|
+
* form uses where no tenant is meant or the column is not shared. A check before any request (ANYONE) holds it,
|
|
19
|
+
* and the request judges it.
|
|
20
|
+
*/
|
|
21
|
+
export function tenantHolds(ctx, word, test, values) {
|
|
22
|
+
const column = TENANT_VALUE.exec(word)[1];
|
|
23
|
+
const me = ctx.me;
|
|
24
|
+
if (me?.anyone && me.tenant === undefined)
|
|
25
|
+
return me.once ? { error: ONCE_TENANT(word) } : { holds: true };
|
|
26
|
+
if (!me?.tenant)
|
|
27
|
+
return { error: `${word} is the reader's tenant profile, and no tenant is meant here. Quote it ("${word}") to mean the text.` };
|
|
28
|
+
if (!Object.hasOwn(me.tenant, column))
|
|
29
|
+
return { error: `${word} is not a column the App shares with its members: list "${column}" in auth.tenancy.shared.` };
|
|
30
|
+
for (const { value, quoted } of values) {
|
|
31
|
+
if (!quoted && (value === 'me' || ME_SET.test(value) || TENANT_VALUE.test(value) || ctx.table?.columns.some((c) => c.name === value)))
|
|
32
|
+
return { error: `${word} is compared with a value, and ${value} is not one. Quote it ("${value}") to mean the text.` };
|
|
33
|
+
}
|
|
34
|
+
const held = me.tenant[column];
|
|
35
|
+
if (test === 'isNull')
|
|
36
|
+
return { holds: held === null };
|
|
37
|
+
if (test === 'isNotNull')
|
|
38
|
+
return { holds: held !== null };
|
|
39
|
+
if (held === null)
|
|
40
|
+
return { holds: false };
|
|
41
|
+
const as = (given) => typeof held === 'number' ? Number(given) : typeof held === 'boolean' ? /^(1|true|t|yes|y)$/i.test(given) : given;
|
|
42
|
+
const read = values.map((item) => as(item.value));
|
|
43
|
+
switch (test) {
|
|
44
|
+
case 'in':
|
|
45
|
+
return { holds: read.includes(held) };
|
|
46
|
+
case 'not in':
|
|
47
|
+
return { holds: !read.includes(held) };
|
|
48
|
+
case '=':
|
|
49
|
+
return { holds: held === read[0] };
|
|
50
|
+
case '!=':
|
|
51
|
+
return { holds: held !== read[0] };
|
|
52
|
+
case '<':
|
|
53
|
+
return { holds: held < read[0] };
|
|
54
|
+
case '<=':
|
|
55
|
+
return { holds: held <= read[0] };
|
|
56
|
+
case '>':
|
|
57
|
+
return { holds: held > read[0] };
|
|
58
|
+
case '>=':
|
|
59
|
+
return { holds: held >= read[0] };
|
|
60
|
+
}
|
|
61
|
+
}
|
|
8
62
|
/**
|
|
9
63
|
* What `tenant.<column>` stands for beside one column: the profile's value, read for
|
|
10
64
|
* this request. Undefined where the word is not one (quoted, or the table has a
|
|
@@ -18,7 +72,7 @@ export function tenantOperand(ctx, column, word, quoted) {
|
|
|
18
72
|
return undefined;
|
|
19
73
|
const me = ctx.me;
|
|
20
74
|
if (me?.anyone && me.tenant === undefined)
|
|
21
|
-
return { value: word };
|
|
75
|
+
return me.once ? { error: ONCE_TENANT(word) } : { value: word };
|
|
22
76
|
if (!me?.tenant)
|
|
23
77
|
return { error: `${word} is the reader's tenant profile, and no tenant is meant here. Quote it ("${word}") to mean the text.` };
|
|
24
78
|
if (!Object.hasOwn(me.tenant, match[1]))
|
|
@@ -20,6 +20,9 @@ import type { ColumnMeta } from './schema.js';
|
|
|
20
20
|
export declare const TAGS_COLUMN = "tags";
|
|
21
21
|
/** The type a record's tags carry where a column's would be: no column has it. */
|
|
22
22
|
export declare const TAGS_TYPE = "tags";
|
|
23
|
+
/** The type a form's several-choices answer (`field.choices`) carries where a column's would be: a list the draft
|
|
24
|
+
* holds, asked with `has` (`services has cleaning`) and never compared whole. Only a form's draft has one. */
|
|
25
|
+
export declare const CHOICES_TYPE = "choices";
|
|
23
26
|
/** A record's tags as the catalog serves them and a view carries them: no request ever supplies one. */
|
|
24
27
|
export interface TagSet {
|
|
25
28
|
/** The link table's id. */
|
package/dist/shared/tagLists.js
CHANGED
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
export const TAGS_COLUMN = 'tags';
|
|
3
3
|
/** The type a record's tags carry where a column's would be: no column has it. */
|
|
4
4
|
export const TAGS_TYPE = 'tags';
|
|
5
|
+
/** The type a form's several-choices answer (`field.choices`) carries where a column's would be: a list the draft
|
|
6
|
+
* holds, asked with `has` (`services has cleaning`) and never compared whole. Only a form's draft has one. */
|
|
7
|
+
export const CHOICES_TYPE = 'choices';
|
|
5
8
|
/** The tags read as a column: never written, never null (a record without tags has none). */
|
|
6
9
|
export function tagsColumnMeta(name = TAGS_COLUMN) {
|
|
7
10
|
return { name, type: TAGS_TYPE, nullable: false, primaryKey: false, writable: false };
|
package/dist/shared/view.js
CHANGED
|
@@ -38,6 +38,7 @@ import { ANSI_STYLE, buildWhere, collate, orderClauseSql, } from './filter.js';
|
|
|
38
38
|
import { clampLimit, clampOffset, countStatement, LANE_ROW } from './reads.js';
|
|
39
39
|
import { aggregateInput, declaredOrder, findTable, } from './schema.js';
|
|
40
40
|
import { ANY_CONDITION, anyConditions, expandSegments, parseQuery, splitClauseTail } from './query.js';
|
|
41
|
+
import { TENANT_FIELD } from './queryOperands.js';
|
|
41
42
|
import { stitchedListProblem } from './stitchedPaths.js';
|
|
42
43
|
import { qualifiedTable } from './sqlRelation.js';
|
|
43
44
|
import { ScopedRelations } from './rowScope.js';
|
|
@@ -509,6 +510,10 @@ export function parseViewQuery(schema, baseId, text, now, options = {}) {
|
|
|
509
510
|
added.add(path);
|
|
510
511
|
const { resolved, error } = tryResolvePath(schema, baseId, path);
|
|
511
512
|
if (error) {
|
|
513
|
+
/* `tenant.plan = 'pro'` is no path but the reader's tenant, which the parser judges for this request
|
|
514
|
+
(query.ts tenantClause); a table with a `tenant` column of its own reads it as the path it is. */
|
|
515
|
+
if (TENANT_FIELD.test(path) && !base.columns.some((c) => c.name === 'tenant'))
|
|
516
|
+
continue;
|
|
512
517
|
/* Located at the token so the composer can underline the right word.
|
|
513
518
|
The offset is into the filter text, and the caller shifts it. */
|
|
514
519
|
if (isField) {
|
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.50",
|
|
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": {
|
|
@@ -189,6 +189,7 @@
|
|
|
189
189
|
"./shared/firstPaint.js": "./dist/shared/firstPaint.js",
|
|
190
190
|
"./shared/form.js": "./dist/shared/form.js",
|
|
191
191
|
"./shared/formValues.js": "./dist/shared/formValues.js",
|
|
192
|
+
"./shared/frameworkWords.js": "./dist/shared/frameworkWords.js",
|
|
192
193
|
"./shared/funnel.js": "./dist/shared/funnel.js",
|
|
193
194
|
"./shared/httpOperations.js": "./dist/shared/httpOperations.js",
|
|
194
195
|
"./shared/iconGlyphs.js": "./dist/shared/iconGlyphs.js",
|
package/schema/model.d.ts
CHANGED
|
@@ -79,6 +79,9 @@ export interface AppCommandChoice {
|
|
|
79
79
|
icon?: string;
|
|
80
80
|
/** A line under the label, on a card. */
|
|
81
81
|
help?: string;
|
|
82
|
+
/** Set by the server on a table's row it served (`source.served`): the columns its `where` compares, so the page
|
|
83
|
+
offers the rows the answers given match without a read of its own. Never written in an App. */
|
|
84
|
+
row?: Readonly<Record<string, string | number | boolean | null>>;
|
|
82
85
|
}
|
|
83
86
|
|
|
84
87
|
/** A shape a text value must have; each refuses anything else. */
|
|
@@ -130,12 +133,32 @@ export interface CommandSensitive { keep: 'last4' | 'hash' | 'none' | 'handler'
|
|
|
130
133
|
export type CommandLiveLines = Readonly<Record<string, string>>;
|
|
131
134
|
/** Choices read from a table rather than written out: its rows' key (`by`, its primary key) and the column each is
|
|
132
135
|
shown by, read under the reader's grants and validated against the table where the command runs. */
|
|
136
|
+
/** One side of a choice's `where` comparison: a literal, or the answer to a field of the form (`{ answer: 'region' }`). */
|
|
137
|
+
export type CommandChoiceOperand = string | number | boolean | null | { readonly answer: string };
|
|
138
|
+
/** One comparison of a choice's `where`: a column of `from` against operands; several for `in`, `[null]` for `is empty`. */
|
|
139
|
+
export interface CommandChoiceTest {
|
|
140
|
+
readonly column: string;
|
|
141
|
+
readonly operator: 'eq' | 'ne' | 'lt' | 'lte' | 'gt' | 'gte';
|
|
142
|
+
readonly values: readonly CommandChoiceOperand[];
|
|
143
|
+
}
|
|
144
|
+
/** A choice's `where`, compiled: OR of ANDs of comparisons. */
|
|
145
|
+
export type CommandChoiceMatch = readonly (readonly CommandChoiceTest[])[];
|
|
133
146
|
export interface CommandChoiceSource {
|
|
134
147
|
from: string;
|
|
135
148
|
by: string;
|
|
136
149
|
labelColumn: string;
|
|
137
|
-
/** The
|
|
150
|
+
/** The column each row is shown by in a locale, keyed by the locale's tag as the App's catalogs name it
|
|
151
|
+
(`{ es: 'name_es' }`); a row with nothing there is shown by `labelColumn`. */
|
|
152
|
+
labelColumns?: Readonly<Record<string, string>>;
|
|
153
|
+
/** The order the rows are offered in: a column of `from` and a direction. Absent, the rows are in the order of `labelColumn`
|
|
154
|
+
(in a locale `labelColumns` names, of the words shown, in that locale's order). */
|
|
138
155
|
sort?: { column: string; direction: 'asc' | 'desc' };
|
|
156
|
+
/** The rows offered, narrowed by other answers of the form, as the App wrote it (`'region = region and active = true'`):
|
|
157
|
+
a name on the right of a comparison that is a field of the form is that field's answer, any other name a column
|
|
158
|
+
of `from`. Until every answer it reads is given, nothing is offered. */
|
|
159
|
+
where?: string;
|
|
160
|
+
/** `where`, compiled by the server: OR of ANDs of its comparisons. */
|
|
161
|
+
match?: CommandChoiceMatch;
|
|
139
162
|
/** Set by the server on a public form it served this field's rows with: `options` is the whole answer, an empty list
|
|
140
163
|
meaning none to offer, and the page reads nothing of its own. Never written in an App. */
|
|
141
164
|
served?: true;
|
|
@@ -234,6 +257,9 @@ export interface AppFormCommandReference {
|
|
|
234
257
|
label?: string;
|
|
235
258
|
}
|
|
236
259
|
|
|
260
|
+
/** As served, where every `msg()` is said, a caption is text; as authored it may be a message. */
|
|
261
|
+
type SubmitLabel<Label> = [Label] extends [string] ? string : string | AppMessageRef;
|
|
262
|
+
|
|
237
263
|
export interface AppUpdateAction<Label extends string | AppMessageRef = string> {
|
|
238
264
|
/** Its key in `resources.<table>.actions`: what a header, a queue and a role name it by. Served, never authored in the object. */
|
|
239
265
|
id: string;
|
|
@@ -257,11 +283,19 @@ export interface AppUpdateAction<Label extends string | AppMessageRef = string>
|
|
|
257
283
|
bulk?: boolean;
|
|
258
284
|
/** See `CommandActionBase.header`. */
|
|
259
285
|
header?: boolean;
|
|
286
|
+
/** The words on the button of the dialog this action opens (the confirmation, the reason), at most 60 characters; left
|
|
287
|
+
out, the action's own label. A label that reads right as a button on the record (a noun) may read wrong as the
|
|
288
|
+
dialog's submit, which is an instruction. */
|
|
289
|
+
submitLabel?: SubmitLabel<Label>;
|
|
260
290
|
command?: never;
|
|
261
291
|
}
|
|
262
292
|
|
|
263
293
|
export interface CommandActionBase<Label extends string | AppMessageRef> {
|
|
264
294
|
label: Label;
|
|
295
|
+
/** The words on the submit of the form (or the confirmation) this action opens, at most 60 characters; left out, the
|
|
296
|
+
action's own label. A label that reads right as a button on the record (a noun) may read wrong as the dialog's
|
|
297
|
+
submit, which is an instruction. */
|
|
298
|
+
submitLabel?: SubmitLabel<Label>;
|
|
265
299
|
/** A command collects what it needs through its own input. */
|
|
266
300
|
reason?: never;
|
|
267
301
|
set?: never;
|