@mistriwork/engine 1.0.0-rc.72 → 1.0.0-rc.74
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/http/httpAdapter.js +5 -0
- package/dist/adapters/postgres.js +16 -4
- package/dist/adapters/postgresBatchWrites.d.ts +1 -1
- package/dist/adapters/postgresBatchWrites.js +6 -1
- package/dist/adapters/postgresReadSnapshot.js +11 -3
- package/dist/adapters/scoped/scopedCommandOperations.js +5 -6
- package/dist/adapters/scoped/scopedReads.js +18 -2
- package/dist/adapters/scoped/scopedTransaction.js +325 -107
- package/dist/adapters/scoped/triggerProof.js +1 -1
- package/dist/adapters/sqlite.js +4 -2
- package/dist/server/cli/config.d.ts +3 -0
- package/dist/server/cli/config.js +3 -1
- package/dist/server/columnGrants.js +21 -1
- package/dist/server/resourceReadHttp.d.ts +7 -0
- package/dist/server/resourceReadHttp.js +8 -1
- package/dist/server/resourceReadOperations.d.ts +1 -1
- package/dist/server/resourceReadOperations.js +30 -3
- package/dist/shared/aggregate.js +2 -2
- package/dist/shared/anyRows.d.ts +19 -1
- package/dist/shared/anyRows.js +49 -0
- package/dist/shared/filter.d.ts +34 -2
- package/dist/shared/filter.js +32 -4
- package/dist/shared/listEmpty.d.ts +5 -1
- package/dist/shared/listEmpty.js +13 -8
- package/dist/shared/listPresentations.d.ts +8 -5
- package/package.json +1 -1
|
@@ -110,6 +110,7 @@ export async function dispatchResourceReadHttp(path, body, adapter, schema, opti
|
|
|
110
110
|
return refused;
|
|
111
111
|
}
|
|
112
112
|
if (path === '/api/query') {
|
|
113
|
+
options.lastWave?.();
|
|
113
114
|
const { result, order } = await readRecords(adapter, schema, {
|
|
114
115
|
table: String(body.table ?? ''),
|
|
115
116
|
filter: body.filter,
|
|
@@ -143,6 +144,8 @@ export async function dispatchResourceReadHttp(path, body, adapter, schema, opti
|
|
|
143
144
|
return refusal(400, [`lanes is { by: a column, limit: 1 to ${LANE_MOST} }.`]);
|
|
144
145
|
const text = String(body.q ?? '');
|
|
145
146
|
const person = await personFor(text);
|
|
147
|
+
/* Every branch below reads in one wave, rows beside their count (readRecords, readView), or not at all. */
|
|
148
|
+
options.lastWave?.();
|
|
146
149
|
const parsed = parseQuery(text, { schema, now: options.now(), ...person });
|
|
147
150
|
/* A view is a superset of a query, so the bar can take one.
|
|
148
151
|
`invoice customer_id.name contains Harbour` is not a legal single-table
|
|
@@ -298,8 +301,9 @@ export async function dispatchResourceReadHttp(path, body, adapter, schema, opti
|
|
|
298
301
|
}
|
|
299
302
|
results[at] = { errors: parsed.errors.length ? parsed.errors : [{ message: 'That question does not read as a count.' }] };
|
|
300
303
|
}
|
|
304
|
+
/* The plain counts are the last wave only where no view's count is still reading beside them. */
|
|
301
305
|
const batch = plain.length
|
|
302
|
-
? readCounts(adapter, schema, plain, body.countLimit).then((counts) => {
|
|
306
|
+
? readCounts(adapter, schema, plain, body.countLimit, views.length ? undefined : options.lastWave).then((counts) => {
|
|
303
307
|
plain.forEach(({ at }, i) => {
|
|
304
308
|
results[at] = {
|
|
305
309
|
total: counts[i].count,
|
|
@@ -471,6 +475,8 @@ export async function dispatchResourceReadHttp(path, body, adapter, schema, opti
|
|
|
471
475
|
let view = normaliseView(body.view);
|
|
472
476
|
let merged = view;
|
|
473
477
|
const person = await personFor(body.text, body.query);
|
|
478
|
+
// One wave from here: the view's rows beside its count (readView).
|
|
479
|
+
options.lastWave?.();
|
|
474
480
|
const errors = [];
|
|
475
481
|
if (!view.base && typeof body.text !== 'string') {
|
|
476
482
|
return refusal(400, ['A view needs a base table.']);
|
|
@@ -546,6 +552,7 @@ export async function dispatchResourceReadHttp(path, body, adapter, schema, opti
|
|
|
546
552
|
most that many rows are counted, and past it the answer is the bound with
|
|
547
553
|
`capped`. Absent, the count is the one these routes always gave. */
|
|
548
554
|
if (path === '/api/count') {
|
|
555
|
+
options.lastWave?.();
|
|
549
556
|
const result = await readCount(adapter, schema, {
|
|
550
557
|
table: String(body.table ?? ''),
|
|
551
558
|
filter: body.filter,
|
|
@@ -73,7 +73,7 @@ export declare function readCount(reader: ResourceReader, schema: DatabaseSchema
|
|
|
73
73
|
export declare function readCounts(reader: ResourceReader, schema: DatabaseSchema, inputs: ReadonlyArray<{
|
|
74
74
|
table: string;
|
|
75
75
|
filter?: Filter;
|
|
76
|
-
}>, countLimit?: unknown): Promise<CountResult[]>;
|
|
76
|
+
}>, countLimit?: unknown, lastWave?: () => void): Promise<CountResult[]>;
|
|
77
77
|
export declare function readRecords(reader: ResourceReader, schema: DatabaseSchema, input: RecordReadInput, countMode?: ReadCountMode, countLimit?: unknown, continuation?: RecordsContinuation): Promise<{
|
|
78
78
|
request: QueryRequest;
|
|
79
79
|
result: import("@mistriwork/engine/adapters/adapter.js").QueryResult;
|
|
@@ -122,6 +122,28 @@ export function assertStructuredReadFilter(filter, field) {
|
|
|
122
122
|
assertStructuredReadFilter(any.filter, 'column');
|
|
123
123
|
continue;
|
|
124
124
|
}
|
|
125
|
+
/* The key of another table's rows (`customer_id in (customer where …)`, Condition.within): a command's read, one
|
|
126
|
+
level deep, its own conditions plain comparisons judged by the same rule. The read's scope plans that table
|
|
127
|
+
(scopedReads.ts), so a tenant's subquery keys only its own rows. */
|
|
128
|
+
if (field === 'column' && condition.within !== undefined) {
|
|
129
|
+
const within = condition.within;
|
|
130
|
+
if (Object.keys(condition).some((key) => !['column', 'op', 'within'].includes(key)) ||
|
|
131
|
+
typeof condition.column !== 'string' ||
|
|
132
|
+
!condition.column.length ||
|
|
133
|
+
condition.op !== 'in' ||
|
|
134
|
+
!within ||
|
|
135
|
+
typeof within !== 'object' ||
|
|
136
|
+
Array.isArray(within) ||
|
|
137
|
+
Object.keys(within).some((key) => key !== 'table' && key !== 'filter') ||
|
|
138
|
+
typeof within.table !== 'string' ||
|
|
139
|
+
!within.table.length)
|
|
140
|
+
fail();
|
|
141
|
+
assertStructuredReadFilter(within.filter, 'column');
|
|
142
|
+
const inner = within.filter;
|
|
143
|
+
if (inner?.groups.some((group) => group.some((nested) => nested.within !== undefined)))
|
|
144
|
+
fail();
|
|
145
|
+
continue;
|
|
146
|
+
}
|
|
125
147
|
if (Object.keys(condition).some((key) => ![field, 'op', 'value', 'collation', ...(other ? ['other'] : [])].includes(key)) ||
|
|
126
148
|
typeof condition[field] !== 'string' ||
|
|
127
149
|
!condition[field].length)
|
|
@@ -239,7 +261,9 @@ export async function readCount(reader, schema, input) {
|
|
|
239
261
|
* `capped` past it. An unfiltered count of a table the catalog calls large is
|
|
240
262
|
* the catalog's estimate instead, as a list's own total is.
|
|
241
263
|
*/
|
|
242
|
-
export async function readCounts(reader, schema, inputs, countLimit
|
|
264
|
+
export async function readCounts(reader, schema, inputs, countLimit,
|
|
265
|
+
/* Asked just before the last wave of counts (resourceReadHttp.ts `lastWave`): the one statement, or the last window. */
|
|
266
|
+
lastWave) {
|
|
243
267
|
const given = snapshotScopedData(inputs);
|
|
244
268
|
const bound = countLimitOf(countLimit) ?? DEFAULT_COUNT_LIMIT;
|
|
245
269
|
const items = given.map((item) => ({ table: checkedTable(schema, item.table, item).id, filter: item.filter }));
|
|
@@ -255,6 +279,7 @@ export async function readCounts(reader, schema, inputs, countLimit) {
|
|
|
255
279
|
const said = (n) => (n > bound ? { count: bound, exact: true, capped: true } : { count: n, exact: true });
|
|
256
280
|
const each = rest.length > 1 ? capture(reader, { countEach: true }).countEach : undefined;
|
|
257
281
|
if (each) {
|
|
282
|
+
lastWave?.();
|
|
258
283
|
const counts = await each(rest.map(({ item }) => item), bound + 1);
|
|
259
284
|
rest.forEach(({ i }, at) => {
|
|
260
285
|
results[i] = said(counts[at]);
|
|
@@ -266,7 +291,7 @@ export async function readCounts(reader, schema, inputs, countLimit) {
|
|
|
266
291
|
throw new ResourceReadError(501, 'This connection cannot count records.');
|
|
267
292
|
await inWindows(rest, async ({ item, i }) => {
|
|
268
293
|
results[i] = said(await count(item.table, item.filter, bound + 1));
|
|
269
|
-
});
|
|
294
|
+
}, lastWave);
|
|
270
295
|
}
|
|
271
296
|
return results;
|
|
272
297
|
}
|
|
@@ -277,8 +302,10 @@ export async function readCounts(reader, schema, inputs, countLimit) {
|
|
|
277
302
|
whole before a failure is thrown, so no count is still running when the
|
|
278
303
|
request answers, and no further window starts after one. */
|
|
279
304
|
const COUNT_WINDOW = 4;
|
|
280
|
-
async function inWindows(items, run) {
|
|
305
|
+
async function inWindows(items, run, last) {
|
|
281
306
|
for (let at = 0; at < items.length; at += COUNT_WINDOW) {
|
|
307
|
+
if (at + COUNT_WINDOW >= items.length)
|
|
308
|
+
last?.();
|
|
282
309
|
const settled = await Promise.allSettled(items.slice(at, at + COUNT_WINDOW).map(run));
|
|
283
310
|
const failed = settled.find((result) => result.status === 'rejected');
|
|
284
311
|
if (failed)
|
package/dist/shared/aggregate.js
CHANGED
|
@@ -61,9 +61,9 @@ function aggregateBreakdown(schema, request) {
|
|
|
61
61
|
};
|
|
62
62
|
});
|
|
63
63
|
const groups = (request.filter?.groups ?? []).map((group) => group.map((condition) => {
|
|
64
|
-
/* A comparison with another column,
|
|
64
|
+
/* A comparison with another column, rows that point here (`any`), or another table's rows (`within`), reads past this table's own values:
|
|
65
65
|
neither is a condition a command's where writes (compileWhere), and neither is taken here. */
|
|
66
|
-
if (condition.any !== undefined || condition.other !== undefined)
|
|
66
|
+
if (condition.any !== undefined || condition.other !== undefined || condition.within !== undefined)
|
|
67
67
|
throw new RequestFault("An aggregate's where compares the table's own columns with values.");
|
|
68
68
|
return {
|
|
69
69
|
path: column(condition.column, 'where'),
|
package/dist/shared/anyRows.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { AnyRows, InlineRows, SqlStyle } from './filter.js';
|
|
1
|
+
import type { AnyRows, InlineRows, SqlStyle, WithinPlan, WithinRows } from './filter.js';
|
|
2
2
|
import { type DatabaseSchema, type TableMeta } from './schema.js';
|
|
3
3
|
interface ChildRows {
|
|
4
4
|
readonly child: TableMeta;
|
|
@@ -16,4 +16,22 @@ export declare function childRows(schema: DatabaseSchema, parentId: string, rows
|
|
|
16
16
|
* child is read from its own relation, as the parent is, with no scope between.
|
|
17
17
|
*/
|
|
18
18
|
export declare function inlineRows(schema: DatabaseSchema, parentId: string, parent: string, style: SqlStyle, relation: (table: TableMeta) => string): (rows: AnyRows) => InlineRows;
|
|
19
|
+
/**
|
|
20
|
+
* The table an `in` names (`Condition.within`), and the key its subquery selects. Refused, never guessed, when the
|
|
21
|
+
* table is not one the catalog holds, has no key of one column to select, or its conditions say more than its own
|
|
22
|
+
* columns compared with values (no second `in`, no `any`, no column on the right, no resolved test, no path): one
|
|
23
|
+
* level only. The raw and the scoped read check it here, so the two cannot drift on what they refuse.
|
|
24
|
+
*/
|
|
25
|
+
export declare function withinRows(schema: DatabaseSchema, rows: WithinRows): {
|
|
26
|
+
readonly table: TableMeta;
|
|
27
|
+
readonly key: string;
|
|
28
|
+
readonly type: string;
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* `buildWhere`'s `within` for a raw read: the other table is read from its own relation, as the table asked about
|
|
32
|
+
* is, with no scope between, and its conditions bound in the statement's order.
|
|
33
|
+
*/
|
|
34
|
+
export declare function inlineWithin(schema: DatabaseSchema, style: SqlStyle, relation: (table: TableMeta) => string): (rows: WithinRows) => WithinPlan;
|
|
35
|
+
/** The subquery of an `in` read from a relation already planned (scoped, its conditions bound there): it binds nothing. */
|
|
36
|
+
export declare function plannedWithin(style: SqlStyle, source: string, key: string, type: string): WithinPlan;
|
|
19
37
|
export {};
|
package/dist/shared/anyRows.js
CHANGED
|
@@ -67,3 +67,52 @@ export function inlineRows(schema, parentId, parent, style, relation) {
|
|
|
67
67
|
};
|
|
68
68
|
};
|
|
69
69
|
}
|
|
70
|
+
/** The alias another table's rows stand under inside an `in`'s subquery. */
|
|
71
|
+
const WITHIN = '_tw_in';
|
|
72
|
+
const refusedWithin = () => new RequestFault("This read cannot compare a column with another table's rows.");
|
|
73
|
+
/**
|
|
74
|
+
* The table an `in` names (`Condition.within`), and the key its subquery selects. Refused, never guessed, when the
|
|
75
|
+
* table is not one the catalog holds, has no key of one column to select, or its conditions say more than its own
|
|
76
|
+
* columns compared with values (no second `in`, no `any`, no column on the right, no resolved test, no path): one
|
|
77
|
+
* level only. The raw and the scoped read check it here, so the two cannot drift on what they refuse.
|
|
78
|
+
*/
|
|
79
|
+
export function withinRows(schema, rows) {
|
|
80
|
+
if (!rows || typeof rows !== 'object' || typeof rows.table !== 'string')
|
|
81
|
+
throw refusedWithin();
|
|
82
|
+
const table = findTable(schema, rows.table);
|
|
83
|
+
if (!table)
|
|
84
|
+
throw new RequestFault('Unknown table in an "in" test.');
|
|
85
|
+
const keys = table.columns.filter((column) => column.primaryKey);
|
|
86
|
+
if (keys.length !== 1)
|
|
87
|
+
throw new RequestFault(`An "in" test selects a table's key, and ${table.name} has no key of exactly one column.`);
|
|
88
|
+
for (const group of rows.filter?.groups ?? []) {
|
|
89
|
+
for (const c of group) {
|
|
90
|
+
if (c.any !== undefined || c.within !== undefined || c.other !== undefined || c.via !== undefined || c.equality !== undefined)
|
|
91
|
+
throw new RequestFault('An "in" test reads one level: its rows are judged by their own columns, never by another "in" or "any".');
|
|
92
|
+
if (typeof c.column !== 'string' || !table.columns.some((column) => column.name === c.column))
|
|
93
|
+
throw new RequestFault('Unknown column in an "in" test.');
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
return { table, key: keys[0].name, type: keys[0].type };
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* `buildWhere`'s `within` for a raw read: the other table is read from its own relation, as the table asked about
|
|
100
|
+
* is, with no scope between, and its conditions bound in the statement's order.
|
|
101
|
+
*/
|
|
102
|
+
export function inlineWithin(schema, style, relation) {
|
|
103
|
+
return (rows) => {
|
|
104
|
+
const { table, key, type } = withinRows(schema, rows);
|
|
105
|
+
const alias = style.quote(WITHIN);
|
|
106
|
+
return {
|
|
107
|
+
select: `SELECT ${alias}.${style.quote(key)} FROM ${relation(table)} ${alias}`,
|
|
108
|
+
column: (name) => `${alias}.${style.quote(name)}`,
|
|
109
|
+
types: (name) => table.columns.find((column) => column.name === name)?.type,
|
|
110
|
+
key: type,
|
|
111
|
+
};
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
/** The subquery of an `in` read from a relation already planned (scoped, its conditions bound there): it binds nothing. */
|
|
115
|
+
export function plannedWithin(style, source, key, type) {
|
|
116
|
+
const alias = style.quote(WITHIN);
|
|
117
|
+
return { select: `SELECT ${alias}.${style.quote(key)} FROM ${source} ${alias}`, key: type };
|
|
118
|
+
}
|
package/dist/shared/filter.d.ts
CHANGED
|
@@ -32,6 +32,13 @@ export interface Condition {
|
|
|
32
32
|
* `op` is `isNotNull` for `any`, `isNull` for `no`.
|
|
33
33
|
*/
|
|
34
34
|
any?: AnyRows;
|
|
35
|
+
/**
|
|
36
|
+
* The column's value is the key of a row of another table that matches: `customer_id in (customer where region =
|
|
37
|
+
* west)`. Written as `column IN (SELECT key FROM …)` over the other table's relation, so a row scope on that table
|
|
38
|
+
* narrows it as it narrows a list of its rows. `op` is `in` and `value` is absent. Only a builder that knows how to
|
|
39
|
+
* read that table (`buildWhere`'s `within`) compiles it; everywhere else it is refused, never dropped.
|
|
40
|
+
*/
|
|
41
|
+
within?: WithinRows;
|
|
35
42
|
/**
|
|
36
43
|
* Compare as a PostgreSQL foreign key compares a reference with its parent's key: by its own operator, named with
|
|
37
44
|
* its schema, the value cast to the referencing column's type and each side to the operator's, as the database's
|
|
@@ -63,7 +70,30 @@ export interface InlineRows {
|
|
|
63
70
|
/** A child column's catalog type, where the style names its operators by schema. */
|
|
64
71
|
readonly types?: (name: string) => string | undefined;
|
|
65
72
|
}
|
|
66
|
-
/**
|
|
73
|
+
/**
|
|
74
|
+
* The rows of a `within` condition (`Condition.within`): the table whose key the column is compared with, by its
|
|
75
|
+
* name in the read's namespace, and which of its rows count — conditions over its own columns compared with values.
|
|
76
|
+
*/
|
|
77
|
+
export interface WithinRows {
|
|
78
|
+
table: string;
|
|
79
|
+
filter?: Filter;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* A `within` condition's rows as a builder resolved them (`buildWhere`'s `within`): the subquery that reads their key,
|
|
83
|
+
* `SELECT alias.key FROM relation alias`. Where `column` is given, the rows' own conditions are bound by `buildWhere`
|
|
84
|
+
* after it, in the statement's order; absent, the select carries them already (planned with the read's scope) and
|
|
85
|
+
* binds nothing here.
|
|
86
|
+
*/
|
|
87
|
+
export interface WithinPlan {
|
|
88
|
+
readonly select: string;
|
|
89
|
+
/** One of the rows' own columns, qualified; refuses a name the table does not hold. */
|
|
90
|
+
readonly column?: (name: string) => string;
|
|
91
|
+
/** A column's catalog type, where the style names its operators by schema. */
|
|
92
|
+
readonly types?: (name: string) => string | undefined;
|
|
93
|
+
/** The key's catalog type: with the compared column's, whether the comparison names the built-in operator. */
|
|
94
|
+
readonly key?: string;
|
|
95
|
+
}
|
|
96
|
+
/** Whether a filter asks about other rows — those that point at the one read (`any`/`no`), or another table's (`in`) — anywhere. */
|
|
67
97
|
export declare const asksAboutRows: (filter: Filter | undefined) => boolean;
|
|
68
98
|
/**
|
|
69
99
|
* A filter whose `any`/`no` children are named in another namespace: a layer that renames the tables of a request
|
|
@@ -292,5 +322,7 @@ types?: (name: string) => string | undefined,
|
|
|
292
322
|
via?: boolean,
|
|
293
323
|
/** How an `any` condition is written when its child's values are bound here, in order, with the rest of the
|
|
294
324
|
filter: a read that resolves the child itself (anyRows.ts). Absent, and without `exists`, one is refused. */
|
|
295
|
-
inline?: (rows: AnyRows) => InlineRows
|
|
325
|
+
inline?: (rows: AnyRows) => InlineRows,
|
|
326
|
+
/** How a `within` condition's subquery is read (`Condition.within`): its relation, scoped where the read is. Absent, one is refused. */
|
|
327
|
+
within?: (rows: WithinRows) => WithinPlan): SqlFragment;
|
|
296
328
|
export {};
|
package/dist/shared/filter.js
CHANGED
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import { LIKE_ESCAPE, likePattern } from './like.js';
|
|
7
7
|
import { RequestFault } from './refusal.js';
|
|
8
|
-
/** Whether a filter asks about
|
|
9
|
-
export const asksAboutRows = (filter) => filter?.groups.some((group) => group.some((condition) => condition.any !== undefined)) === true;
|
|
8
|
+
/** Whether a filter asks about other rows — those that point at the one read (`any`/`no`), or another table's (`in`) — anywhere. */
|
|
9
|
+
export const asksAboutRows = (filter) => filter?.groups.some((group) => group.some((condition) => condition.any !== undefined || condition.within !== undefined)) === true;
|
|
10
10
|
/**
|
|
11
11
|
* A filter whose `any`/`no` children are named in another namespace: a layer that renames the tables of a request
|
|
12
12
|
* (an App's resources to the database's, a loader's local names to the catalog's) renames the child as it renames the
|
|
@@ -18,6 +18,9 @@ export function renamedAnyRows(filter, rename) {
|
|
|
18
18
|
return {
|
|
19
19
|
...filter,
|
|
20
20
|
groups: filter.groups.map((group) => group.map((condition) => {
|
|
21
|
+
/* An `in`'s table is a table of the same read too. */
|
|
22
|
+
if (condition.within !== undefined)
|
|
23
|
+
return { ...condition, within: { ...condition.within, table: rename(condition.within.table) } };
|
|
21
24
|
if (condition.any === undefined)
|
|
22
25
|
return condition;
|
|
23
26
|
const { via } = condition.any;
|
|
@@ -242,7 +245,9 @@ types,
|
|
|
242
245
|
via = false,
|
|
243
246
|
/** How an `any` condition is written when its child's values are bound here, in order, with the rest of the
|
|
244
247
|
filter: a read that resolves the child itself (anyRows.ts). Absent, and without `exists`, one is refused. */
|
|
245
|
-
inline
|
|
248
|
+
inline,
|
|
249
|
+
/** How a `within` condition's subquery is read (`Condition.within`): its relation, scoped where the read is. Absent, one is refused. */
|
|
250
|
+
within) {
|
|
246
251
|
if (!filter?.groups.length)
|
|
247
252
|
return { text: '', params: [] };
|
|
248
253
|
const params = [];
|
|
@@ -287,7 +292,7 @@ inline) {
|
|
|
287
292
|
values are bound where their relation is planned (rowScope.ts `filtered`),
|
|
288
293
|
so the EXISTS carries no parameter here and the numbering is untouched. */
|
|
289
294
|
if (c.any !== undefined) {
|
|
290
|
-
if ((!exists && !inline) || typeof c.any !== 'object' || c.any === null)
|
|
295
|
+
if ((!exists && !inline) || typeof c.any !== 'object' || c.any === null || c.within !== undefined)
|
|
291
296
|
throw new RequestFault('This read cannot ask about the rows that point at it.');
|
|
292
297
|
let text;
|
|
293
298
|
if (exists)
|
|
@@ -309,6 +314,28 @@ inline) {
|
|
|
309
314
|
/* `no task …` is the same rows asked the other way: none of them matches. */
|
|
310
315
|
return c.op === 'isNull' ? `NOT ${text}` : text;
|
|
311
316
|
}
|
|
317
|
+
/* Before the column is written by an operator: another table's keys are no value. One level only — the rows'
|
|
318
|
+
own conditions are compiled with no hooks, so an `in` or an `any` inside them is refused, never dropped. */
|
|
319
|
+
if (c.within !== undefined) {
|
|
320
|
+
if (!within ||
|
|
321
|
+
typeof c.within !== 'object' ||
|
|
322
|
+
c.within === null ||
|
|
323
|
+
c.op !== 'in' ||
|
|
324
|
+
c.other !== undefined ||
|
|
325
|
+
c.equality !== undefined)
|
|
326
|
+
throw new RequestFault("This read cannot compare a column with another table's rows.");
|
|
327
|
+
const plan = within(c.within);
|
|
328
|
+
let narrowed = '';
|
|
329
|
+
if (plan.column && c.within.filter?.groups.length) {
|
|
330
|
+
const inner = buildWhere(c.within.filter, style, index, plan.column, undefined, undefined, undefined, false, plan.types);
|
|
331
|
+
params.push(...inner.params);
|
|
332
|
+
index += inner.params.length;
|
|
333
|
+
narrowed = inner.text;
|
|
334
|
+
}
|
|
335
|
+
const col = column(c.column, c);
|
|
336
|
+
const typed = builtin(c.column) && plan.key !== undefined && style.builtin?.(plan.key);
|
|
337
|
+
return typed ? `${col} ${operator('=')} ANY (${plan.select}${narrowed})` : `${col} IN (${plan.select}${narrowed})`;
|
|
338
|
+
}
|
|
312
339
|
/* Before the column is written: a record's tags are no column. */
|
|
313
340
|
if (c.op === 'has') {
|
|
314
341
|
if (!membership || c.other !== undefined)
|
|
@@ -424,6 +451,7 @@ function sameCondition(a, b) {
|
|
|
424
451
|
a.collation !== b.collation ||
|
|
425
452
|
a.other !== b.other ||
|
|
426
453
|
a.any !== b.any ||
|
|
454
|
+
a.within !== b.within ||
|
|
427
455
|
a.equality !== b.equality ||
|
|
428
456
|
a.via?.text !== b.via?.text)
|
|
429
457
|
return false;
|
|
@@ -1,6 +1,10 @@
|
|
|
1
|
-
import type { AppListEmpty } from './listPresentations.js';
|
|
1
|
+
import type { AppListEmpty, AppListLink } from './listPresentations.js';
|
|
2
2
|
/** Read the shared empty-list copy used by list views and related sections. */
|
|
3
3
|
export declare function parseListEmpty(raw: unknown, at: string): AppListEmpty;
|
|
4
|
+
/** A list's `{ label, to }` to another room: its empty state's action, and the link at its head (a list view's
|
|
5
|
+
`link`). One shape, so the two read as one thing; where `to` may go is judged where the App is whole
|
|
6
|
+
(appDestinations.ts). */
|
|
7
|
+
export declare function parseListLink(raw: unknown, at: string): AppListLink;
|
|
4
8
|
/** The authored shape again, for a definition written back out. */
|
|
5
9
|
export declare function listEmptyConfig(empty: AppListEmpty): {
|
|
6
10
|
title: string;
|
package/dist/shared/listEmpty.js
CHANGED
|
@@ -18,15 +18,20 @@ export function parseListEmpty(raw, at) {
|
|
|
18
18
|
const result = { title, ...(description === undefined ? {} : { description }) };
|
|
19
19
|
if (raw.action === undefined)
|
|
20
20
|
return result;
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
21
|
+
return { ...result, action: parseListLink(raw.action, `${here}, "action"`) };
|
|
22
|
+
}
|
|
23
|
+
/** A list's `{ label, to }` to another room: its empty state's action, and the link at its head (a list view's
|
|
24
|
+
`link`). One shape, so the two read as one thing; where `to` may go is judged where the App is whole
|
|
25
|
+
(appDestinations.ts). */
|
|
26
|
+
export function parseListLink(raw, at) {
|
|
27
|
+
if (!isRecord(raw))
|
|
28
|
+
throw new Error(`${at} must be an object with "label" and "to".`);
|
|
29
|
+
allowKeys(raw, ['label', 'to'], at);
|
|
30
|
+
const label = parseCaption(raw.label, `${at} needs a non-empty "label"`);
|
|
31
|
+
const to = typeof raw.to === 'string' || isRecord(raw.to) ? parseLinkTo(raw.to, `${at}, "to"`) : undefined;
|
|
27
32
|
if (!to || !('view' in to))
|
|
28
|
-
throw new Error(`${
|
|
29
|
-
return {
|
|
33
|
+
throw new Error(`${at} needs a "to": the key of a list, a dashboard or a signed-in form view, or { view, tab }.`);
|
|
34
|
+
return { label, ...to };
|
|
30
35
|
}
|
|
31
36
|
/** The authored shape again, for a definition written back out. */
|
|
32
37
|
export function listEmptyConfig(empty) {
|
|
@@ -194,11 +194,14 @@ export type AppListPresentation = AppTreeList | AppGanttList | AppChecklist | Ap
|
|
|
194
194
|
export interface AppListEmpty {
|
|
195
195
|
title: string;
|
|
196
196
|
description?: string;
|
|
197
|
-
action?:
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
197
|
+
action?: AppListLink;
|
|
198
|
+
}
|
|
199
|
+
/** A list's way to another room: its empty state's action, and the link at its head (a list view's `link`). */
|
|
200
|
+
export interface AppListLink {
|
|
201
|
+
label: string;
|
|
202
|
+
view: string;
|
|
203
|
+
/** The tab of a list it opens on, by its address word. */
|
|
204
|
+
tab?: string;
|
|
202
205
|
}
|
|
203
206
|
/** Whether the Export menu is offered for a table, here and not beside the payload that sets `exportableTables`, since a list's first paint asks it and appPayload.ts imports the manifest parser: `ui.export` is the App's switch, and `exportableTables` (present in an App that grants by role) the person's. */
|
|
204
207
|
export declare const exportOffered: (app: {
|
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.74",
|
|
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": {
|