@mistriwork/engine 1.0.0-rc.10 → 1.0.0-rc.12
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 +33 -0
- package/dist/adapters/postgres.d.ts +21 -16
- package/dist/adapters/postgres.js +199 -223
- package/dist/adapters/postgresCatalog.d.ts +12 -1
- package/dist/adapters/postgresCatalog.js +57 -23
- package/dist/adapters/postgresCatalogDigest.js +40 -34
- package/dist/adapters/postgresCatalogRows.d.ts +2 -0
- package/dist/adapters/postgresWriteAhead.d.ts +47 -0
- package/dist/adapters/postgresWriteAhead.js +209 -0
- package/dist/adapters/scoped/keyRows.js +9 -3
- package/dist/adapters/scoped/keyTypes.d.ts +34 -0
- package/dist/adapters/scoped/keyTypes.js +66 -0
- package/dist/adapters/scoped/postgresScopeCatalog.d.ts +40 -1
- package/dist/adapters/scoped/postgresScopeCatalog.js +417 -13
- package/dist/adapters/scoped/postgresTriggers.d.ts +137 -0
- package/dist/adapters/scoped/postgresTriggers.js +1545 -0
- package/dist/adapters/scoped/scopeTriggers.d.ts +122 -0
- package/dist/adapters/scoped/scopeTriggers.js +131 -0
- package/dist/adapters/scoped/scopedReads.d.ts +3 -1
- package/dist/adapters/scoped/scopedReads.js +28 -8
- package/dist/adapters/scoped/scopedTransaction.d.ts +95 -6
- package/dist/adapters/scoped/scopedTransaction.js +308 -34
- package/dist/adapters/scoped/sqliteScopeCatalog.d.ts +17 -1
- package/dist/adapters/scoped/sqliteScopeCatalog.js +197 -18
- package/dist/adapters/scoped/sqliteTriggerSession.d.ts +64 -0
- package/dist/adapters/scoped/sqliteTriggerSession.js +245 -0
- package/dist/adapters/scoped/sqliteTriggers.d.ts +20 -0
- package/dist/adapters/scoped/sqliteTriggers.js +822 -0
- package/dist/adapters/scoped/storedText.d.ts +45 -0
- package/dist/adapters/scoped/storedText.js +61 -0
- package/dist/adapters/scoped/triggerEffects.d.ts +98 -0
- package/dist/adapters/scoped/triggerEffects.js +189 -0
- package/dist/adapters/scoped/triggerProof.d.ts +124 -0
- package/dist/adapters/scoped/triggerProof.js +366 -0
- package/dist/adapters/snapshotRead.d.ts +8 -0
- package/dist/adapters/snapshotRead.js +37 -0
- package/dist/adapters/sqlite.d.ts +13 -2
- package/dist/adapters/sqlite.js +139 -16
- package/dist/adapters/sqliteDecimals.d.ts +2 -2
- package/dist/adapters/sqliteDecimals.js +2 -8
- package/dist/adapters/storeHost.d.ts +4 -1
- package/dist/adapters/writeCapture.d.ts +7 -0
- package/dist/server/cli/args.d.ts +6 -0
- package/dist/server/cli/args.js +6 -0
- package/dist/server/columnGrants.d.ts +3 -0
- package/dist/server/columnGrants.js +12 -1
- package/dist/server/config/profile.d.ts +123 -0
- package/dist/server/config/profile.js +236 -0
- package/dist/server/connections.d.ts +5 -0
- package/dist/server/connections.js +11 -1
- package/dist/server/hiddenColumns.js +6 -0
- package/dist/server/http/refusalReport.js +16 -4
- package/dist/server/http/router.d.ts +11 -22
- package/dist/server/http/router.js +0 -15
- package/dist/server/migrate/cli.d.ts +50 -3
- package/dist/server/migrate/cli.js +199 -14
- package/dist/server/migrate/runner.js +5 -1
- package/dist/server/shapeonly.js +5 -0
- package/dist/shared/addressParams.d.ts +2 -0
- package/dist/shared/addressParams.js +2 -0
- package/dist/shared/aggregate.d.ts +49 -0
- package/dist/shared/aggregate.js +107 -0
- package/dist/shared/breakdown.js +19 -6
- package/dist/shared/decimals.d.ts +37 -0
- package/dist/shared/decimals.js +148 -0
- package/dist/shared/displayDefaults.js +15 -1
- package/dist/shared/filter.d.ts +39 -1
- package/dist/shared/filter.js +96 -15
- package/dist/shared/listPresentations.d.ts +2 -0
- package/dist/shared/listQuestion.d.ts +3 -1
- package/dist/shared/money.d.ts +9 -0
- package/dist/shared/money.js +17 -0
- package/dist/shared/moneyEntry.d.ts +6 -3
- package/dist/shared/moneyEntry.js +14 -7
- package/dist/shared/pageModel.d.ts +1 -1
- package/dist/shared/recordview.d.ts +1 -1
- package/dist/shared/refusal.d.ts +16 -0
- package/dist/shared/refusal.js +40 -0
- package/dist/shared/rowScope.js +12 -4
- package/dist/shared/schema.d.ts +6 -0
- package/dist/shared/schematext.d.ts +22 -6
- package/dist/shared/schematext.js +18 -2
- package/dist/shared/scopeCatalog.js +4 -0
- package/dist/shared/servedApp.d.ts +15 -4
- package/dist/shared/view.js +4 -4
- package/dist/shared/viewLabels.d.ts +1 -0
- package/dist/shared/viewLabels.js +8 -2
- package/dist/shared/viewPaths.d.ts +3 -0
- package/dist/shared/viewPaths.js +8 -0
- package/package.json +5 -2
- package/schema/model.d.ts +1 -1
- package/dist/shared/order.d.ts +0 -59
- package/dist/shared/order.js +0 -133
package/dist/shared/refusal.d.ts
CHANGED
|
@@ -21,6 +21,16 @@ export declare class Refusal extends Error {
|
|
|
21
21
|
cause?: unknown;
|
|
22
22
|
});
|
|
23
23
|
}
|
|
24
|
+
declare const REQUEST_FAULT: unique symbol;
|
|
25
|
+
export declare class RequestFault extends Refusal {
|
|
26
|
+
readonly [REQUEST_FAULT] = true;
|
|
27
|
+
constructor(message: string, options?: {
|
|
28
|
+
columns?: readonly string[];
|
|
29
|
+
cause?: unknown;
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
/** Whether a refusal is a request that can never succeed as written (`RequestFault`), from any copy of the module. */
|
|
33
|
+
export declare const isRequestFault: (error: unknown) => error is RequestFault;
|
|
24
34
|
/** Record why a refusal happened on the refusal itself, for the trusted reader
|
|
25
35
|
* only. Every opaque refusal takes its reason this way — a tenant denial, a
|
|
26
36
|
* row policy that did not load, a command the database would not take — so
|
|
@@ -29,6 +39,11 @@ export declare class Refusal extends Error {
|
|
|
29
39
|
export declare function recordRefusalCause<E extends object>(error: E, cause: unknown): E;
|
|
30
40
|
/** The recorded reason behind a refusal, for a trusted diagnostic only. */
|
|
31
41
|
export declare const refusalCause: (error: unknown) => unknown;
|
|
42
|
+
/** Mark a refusal as its App author's mistake, and record why: the operator is told the cause first. */
|
|
43
|
+
export declare function authorFault<E extends object>(error: E, cause: string): E;
|
|
44
|
+
/** Whether a refusal, or one it was rebuilt over (a command's refusals are re-issued with the outcome), was marked
|
|
45
|
+
as its App author's mistake (authorFault). */
|
|
46
|
+
export declare function isAuthorFault(error: unknown): boolean;
|
|
32
47
|
/**
|
|
33
48
|
* What the operator is told about a refusal: each reason under it, outermost
|
|
34
49
|
* first — a recorded cause before `cause`, since the recorded one is the
|
|
@@ -62,3 +77,4 @@ export declare function faultFrames(error: unknown, most?: number): string[];
|
|
|
62
77
|
export declare function sayRefusal<E extends object>(error: E, sentence: string): E;
|
|
63
78
|
/** The sentence a refusal's caller may read about why, if the code that refused said one. */
|
|
64
79
|
export declare const refusalSaid: (error: unknown) => string | undefined;
|
|
80
|
+
export {};
|
package/dist/shared/refusal.js
CHANGED
|
@@ -29,6 +29,21 @@ export class Refusal extends Error {
|
|
|
29
29
|
this.columns = [...new Set(options.columns)];
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
|
+
/* A request that can never succeed as written: a malformed filter, an aggregate naming a column the table lacks, a
|
|
33
|
+
sum SQLite cannot add exactly. Whoever wrote the request fixes it, so nothing is worth retrying; a command that
|
|
34
|
+
meets one says invalid_result, where every other refusal it could not place was temporarily_unavailable and
|
|
35
|
+
sent a job or a workflow round a retry that could not end. Branded with a registered symbol, since a handler
|
|
36
|
+
may import a second copy of this module. */
|
|
37
|
+
const REQUEST_FAULT = Symbol.for('mistri.requestFault');
|
|
38
|
+
export class RequestFault extends Refusal {
|
|
39
|
+
[REQUEST_FAULT] = true;
|
|
40
|
+
constructor(message, options = {}) {
|
|
41
|
+
super(message, options);
|
|
42
|
+
this.name = 'RequestFault';
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
/** Whether a refusal is a request that can never succeed as written (`RequestFault`), from any copy of the module. */
|
|
46
|
+
export const isRequestFault = (error) => error instanceof Error && error[REQUEST_FAULT] === true;
|
|
32
47
|
/* Why a refusal happened, kept for the trusted owner that has to diagnose it.
|
|
33
48
|
A caller hears one fixed sentence and must: a driver's error text names
|
|
34
49
|
columns, values and internal tables, and a clash on a hidden unique column
|
|
@@ -55,6 +70,31 @@ export function recordRefusalCause(error, cause) {
|
|
|
55
70
|
}
|
|
56
71
|
/** The recorded reason behind a refusal, for a trusted diagnostic only. */
|
|
57
72
|
export const refusalCause = (error) => error !== null && typeof error === 'object' && CAUSE in error ? error[CAUSE] : undefined;
|
|
73
|
+
/* A refusal that is its App author's own mistake — a command handler that set a reference outside its footprint,
|
|
74
|
+
wrote bytes where no file resource keeps them — rather than the caller's or the platform's. Its caller still
|
|
75
|
+
hears the fixed sentence, but that sentence names nothing to fix, and leading with it put "The command did not
|
|
76
|
+
produce a valid result." over the one line that said what to change (a field report). Marked where the mistake
|
|
77
|
+
is found, so the operator's terminal leads with the recorded cause; who may hear that cause does not move
|
|
78
|
+
(refusalReport.ts). */
|
|
79
|
+
const AUTHOR_FAULT = Symbol.for('mistri.refusalAuthorFault');
|
|
80
|
+
/** Mark a refusal as its App author's mistake, and record why: the operator is told the cause first. */
|
|
81
|
+
export function authorFault(error, cause) {
|
|
82
|
+
if (!Object.hasOwn(error, AUTHOR_FAULT))
|
|
83
|
+
Object.defineProperty(error, AUTHOR_FAULT, { value: true, enumerable: false });
|
|
84
|
+
return recordRefusalCause(error, cause);
|
|
85
|
+
}
|
|
86
|
+
/** Whether a refusal, or one it was rebuilt over (a command's refusals are re-issued with the outcome), was marked
|
|
87
|
+
as its App author's mistake (authorFault). */
|
|
88
|
+
export function isAuthorFault(error) {
|
|
89
|
+
const seen = new Set();
|
|
90
|
+
for (let at = error, depth = 0; at !== null && typeof at === 'object' && !seen.has(at) && depth < 8; depth++) {
|
|
91
|
+
if (AUTHOR_FAULT in at)
|
|
92
|
+
return true;
|
|
93
|
+
seen.add(at);
|
|
94
|
+
at = refusalCause(at) ?? at.cause;
|
|
95
|
+
}
|
|
96
|
+
return false;
|
|
97
|
+
}
|
|
58
98
|
/**
|
|
59
99
|
* What the operator is told about a refusal: each reason under it, outermost
|
|
60
100
|
* first — a recorded cause before `cause`, since the recorded one is the
|
package/dist/shared/rowScope.js
CHANGED
|
@@ -9,7 +9,7 @@ import { Refusal } from './refusal.js';
|
|
|
9
9
|
import { findTable } from './schema.js';
|
|
10
10
|
import { isFixedScopeCatalog } from './scopeCatalog.js';
|
|
11
11
|
import { qualifiedTable } from './sqlRelation.js';
|
|
12
|
-
import { tryResolvePath } from './viewPaths.js';
|
|
12
|
+
import { plainType, tryResolvePath } from './viewPaths.js';
|
|
13
13
|
/** Composition must budget expanded data against the same capture limits. */
|
|
14
14
|
export const ROW_SCOPE_LIMITS = Object.freeze({
|
|
15
15
|
resources: 256,
|
|
@@ -291,8 +291,8 @@ export class ScopedRelations {
|
|
|
291
291
|
this.names.set(id, name);
|
|
292
292
|
const policy = this.scope[id] ?? false;
|
|
293
293
|
const where = typeof policy === 'boolean'
|
|
294
|
-
? { text: policy ? '' :
|
|
295
|
-
: buildWhere(withoutRepeats(policy), this.style, this.params.length + 1, (column) => this.style.quote(column) + (policy.binary?.includes(column) ? ' COLLATE BINARY' : ''));
|
|
294
|
+
? { text: policy ? '' : ` WHERE ${this.style.never ?? '1 = 0'}`, params: [] }
|
|
295
|
+
: buildWhere(withoutRepeats(policy), this.style, this.params.length + 1, (column) => this.style.quote(column) + (policy.binary?.includes(column) ? ' COLLATE BINARY' : ''), undefined, undefined, undefined, false, (column) => table.columns.find((c) => c.name === column)?.type);
|
|
296
296
|
const columns = table.columns.map((column) => this.style.quote(column.name)).join(', ');
|
|
297
297
|
// The style's hint (cteHint) goes between AS and the body: Postgres inlines the CTE, so the
|
|
298
298
|
// scope's predicate meets the read's own filter, sort and limit instead of a copied slice.
|
|
@@ -363,7 +363,15 @@ export class ScopedRelations {
|
|
|
363
363
|
` WHERE ${first.on})`);
|
|
364
364
|
}
|
|
365
365
|
const local = (column) => paths.get(column) ?? own(column);
|
|
366
|
-
|
|
366
|
+
// A column's type, or a path's where it lands on a column: a computed one is an expression, compared as written.
|
|
367
|
+
const typeOf = (column) => {
|
|
368
|
+
if (written && Object.hasOwn(written, column))
|
|
369
|
+
return undefined;
|
|
370
|
+
if (!column.includes('.'))
|
|
371
|
+
return table.columns.find((c) => c.name === column)?.type;
|
|
372
|
+
return plainType(this.schema, id, column);
|
|
373
|
+
};
|
|
374
|
+
const where = buildWhere(filter, this.style, this.params.length + 1, local, local, undefined, undefined, false, typeOf);
|
|
367
375
|
const columns = table.columns.map((column) => q(column.name)).join(', ');
|
|
368
376
|
this.definitions.push(`${q(name)} AS (SELECT ${columns} FROM ${source}${row ? ` ${q(row)}` : ''}${where.text})`);
|
|
369
377
|
this.params.push(...where.params);
|
package/dist/shared/schema.d.ts
CHANGED
|
@@ -35,6 +35,12 @@ export interface ColumnMeta {
|
|
|
35
35
|
};
|
|
36
36
|
/** Declared default, if any. */
|
|
37
37
|
default?: string;
|
|
38
|
+
/**
|
|
39
|
+
* The places a `numeric(p, s)` column holds (s), where `type` cannot say them: PostgreSQL's catalog calls the
|
|
40
|
+
* type plain `numeric`. Absent for an unconstrained numeric and for every other type; SQLite's declared type
|
|
41
|
+
* string carries its own (`decimals.ts` declaredScale).
|
|
42
|
+
*/
|
|
43
|
+
scale?: number;
|
|
38
44
|
/** Public presence hint when a private schema projection omits the SQL default. */
|
|
39
45
|
hasDefault?: boolean;
|
|
40
46
|
/** Catalog-confirmed automatic identity assignment; absent is not a type-based guess. */
|
|
@@ -6,8 +6,13 @@
|
|
|
6
6
|
* committed CLAUDE.md schema section costs one command. Pure on purpose, the
|
|
7
7
|
* way shape.js is pure — a schema in, text out, importable from anywhere.
|
|
8
8
|
*/
|
|
9
|
-
/**
|
|
10
|
-
|
|
9
|
+
/**
|
|
10
|
+
* The tables to export, and the keys wholly between them.
|
|
11
|
+
*
|
|
12
|
+
* @param {any} schema
|
|
13
|
+
* @param {ReadonlySet<string> | null} [only] the tables to export, by id; every table when absent or empty
|
|
14
|
+
*/
|
|
15
|
+
export declare function selection(schema: any, only?: ReadonlySet<string> | null): {
|
|
11
16
|
tables: any;
|
|
12
17
|
keys: any;
|
|
13
18
|
};
|
|
@@ -24,15 +29,26 @@ export declare function selection(schema: any, only: any): {
|
|
|
24
29
|
* `app_invoice`. Said in a comment at the top of the output rather than
|
|
25
30
|
* silently, because someone comparing the diagram to their database will
|
|
26
31
|
* notice.
|
|
32
|
+
*
|
|
33
|
+
* @param {any} schema
|
|
34
|
+
* @param {ReadonlySet<string> | null} [only] the tables to export, by id; every table when absent or empty
|
|
27
35
|
*/
|
|
28
|
-
export declare function toMermaid(schema: any, only
|
|
29
|
-
/**
|
|
30
|
-
|
|
36
|
+
export declare function toMermaid(schema: any, only?: ReadonlySet<string> | null): string;
|
|
37
|
+
/**
|
|
38
|
+
* A readable reference document, of the kind that belongs in a repository.
|
|
39
|
+
*
|
|
40
|
+
* @param {any} schema
|
|
41
|
+
* @param {ReadonlySet<string> | null} [only] the tables to export, by id; every table when absent or empty
|
|
42
|
+
*/
|
|
43
|
+
export declare function toMarkdown(schema: any, only?: ReadonlySet<string> | null): string;
|
|
31
44
|
/**
|
|
32
45
|
* The structured form.
|
|
33
46
|
*
|
|
34
47
|
* Deliberately the shape tablewalk itself uses rather than a format invented
|
|
35
48
|
* for export — anything that reads it is reading the same model the tool
|
|
36
49
|
* reasons about, and there is no second definition to keep in step.
|
|
50
|
+
*
|
|
51
|
+
* @param {any} schema
|
|
52
|
+
* @param {ReadonlySet<string> | null} [only] the tables to export, by id; every table when absent or empty
|
|
37
53
|
*/
|
|
38
|
-
export declare function toSchemaJson(schema: any, only
|
|
54
|
+
export declare function toSchemaJson(schema: any, only?: ReadonlySet<string> | null): string;
|
|
@@ -6,7 +6,12 @@
|
|
|
6
6
|
* committed CLAUDE.md schema section costs one command. Pure on purpose, the
|
|
7
7
|
* way shape.js is pure — a schema in, text out, importable from anywhere.
|
|
8
8
|
*/
|
|
9
|
-
/**
|
|
9
|
+
/**
|
|
10
|
+
* The tables to export, and the keys wholly between them.
|
|
11
|
+
*
|
|
12
|
+
* @param {any} schema
|
|
13
|
+
* @param {ReadonlySet<string> | null} [only] the tables to export, by id; every table when absent or empty
|
|
14
|
+
*/
|
|
10
15
|
export function selection(schema, only) {
|
|
11
16
|
const wanted = only?.size ? schema.tables.filter((t) => only.has(t.id)) : schema.tables;
|
|
12
17
|
const ids = new Set(wanted.map((t) => t.id));
|
|
@@ -30,6 +35,9 @@ export function selection(schema, only) {
|
|
|
30
35
|
* `app_invoice`. Said in a comment at the top of the output rather than
|
|
31
36
|
* silently, because someone comparing the diagram to their database will
|
|
32
37
|
* notice.
|
|
38
|
+
*
|
|
39
|
+
* @param {any} schema
|
|
40
|
+
* @param {ReadonlySet<string> | null} [only] the tables to export, by id; every table when absent or empty
|
|
33
41
|
*/
|
|
34
42
|
export function toMermaid(schema, only) {
|
|
35
43
|
const { tables, keys } = selection(schema, only);
|
|
@@ -51,7 +59,12 @@ export function toMermaid(schema, only) {
|
|
|
51
59
|
const renamed = tables.some((t) => safe(t.id) !== t.id);
|
|
52
60
|
return ((renamed ? '%% Names containing a dot are written with an underscore: Mermaid ids cannot hold one.\n' : '') + lines.join('\n') + '\n');
|
|
53
61
|
}
|
|
54
|
-
/**
|
|
62
|
+
/**
|
|
63
|
+
* A readable reference document, of the kind that belongs in a repository.
|
|
64
|
+
*
|
|
65
|
+
* @param {any} schema
|
|
66
|
+
* @param {ReadonlySet<string> | null} [only] the tables to export, by id; every table when absent or empty
|
|
67
|
+
*/
|
|
55
68
|
export function toMarkdown(schema, only) {
|
|
56
69
|
const { tables, keys } = selection(schema, only);
|
|
57
70
|
const out = [`# ${schema.label}`, ''];
|
|
@@ -86,6 +99,9 @@ export function toMarkdown(schema, only) {
|
|
|
86
99
|
* Deliberately the shape tablewalk itself uses rather than a format invented
|
|
87
100
|
* for export — anything that reads it is reading the same model the tool
|
|
88
101
|
* reasons about, and there is no second definition to keep in step.
|
|
102
|
+
*
|
|
103
|
+
* @param {any} schema
|
|
104
|
+
* @param {ReadonlySet<string> | null} [only] the tables to export, by id; every table when absent or empty
|
|
89
105
|
*/
|
|
90
106
|
export function toSchemaJson(schema, only) {
|
|
91
107
|
const { tables, keys } = selection(schema, only);
|
|
@@ -167,6 +167,7 @@ export function captureScopeCatalog(schema) {
|
|
|
167
167
|
'references',
|
|
168
168
|
'allowed',
|
|
169
169
|
'flag',
|
|
170
|
+
'scale',
|
|
170
171
|
'text',
|
|
171
172
|
'comment',
|
|
172
173
|
'writable',
|
|
@@ -184,6 +185,9 @@ export function captureScopeCatalog(schema) {
|
|
|
184
185
|
typeof column.primaryKey !== 'boolean' ||
|
|
185
186
|
(column.default !== undefined && typeof column.default !== 'string') ||
|
|
186
187
|
(column.flag !== undefined && column.flag !== true) ||
|
|
188
|
+
/* `scale` (a numeric's declared places, where the type string cannot say them) is evidence like `flag`:
|
|
189
|
+
how to say a sum, never a grant. */
|
|
190
|
+
(column.scale !== undefined && (typeof column.scale !== 'number' || !Number.isInteger(column.scale) || column.scale < 0)) ||
|
|
187
191
|
(column.identity !== undefined && column.identity !== 'always' && column.identity !== 'by-default'))
|
|
188
192
|
return refuse();
|
|
189
193
|
if (column.references !== undefined) {
|
|
@@ -238,18 +238,21 @@ export interface AppDisplayRule {
|
|
|
238
238
|
/** money: currency formatting. percent: the value is 0–100, shown with %.
|
|
239
239
|
number: separators forced on a numeric-looking text column. relative:
|
|
240
240
|
a date said from today — "in 3 days", "64 days ago" — with the date
|
|
241
|
-
itself in the tooltip.
|
|
241
|
+
itself in the tooltip. date, datetime: a day, or a moment with its time and zone, said absolutely — the same
|
|
242
|
+
words on any day, for any reader; a date alone never shifts. email, phone, url: the value is a link — to write
|
|
242
243
|
to, to call, to open beside the App — where it has that shape. An App
|
|
243
244
|
links a column named like one (`email`, `phone`, `website`) without a rule. richText: the value is
|
|
244
245
|
sanitized HTML (shared/richText.ts), drawn formatted on a record, as an excerpt in a list, edited in the
|
|
245
246
|
rich text editor; every write of the column is sanitized on the server, and Markdown is read into it. */
|
|
246
|
-
format?: 'money' | 'percent' | 'number' | 'relative' | 'items' | 'duration' | 'email' | 'phone' | 'url' | 'richText' | 'avatars' | 'rating' | 'color' | 'time' | 'month' | 'year' | 'json' | 'qr';
|
|
247
|
+
format?: 'money' | 'percent' | 'number' | 'relative' | 'date' | 'datetime' | 'items' | 'duration' | 'email' | 'phone' | 'url' | 'richText' | 'avatars' | 'rating' | 'color' | 'time' | 'month' | 'year' | 'json' | 'qr';
|
|
247
248
|
/** The face this column's values are set in, over the look's own: `data` (the look's data face, usually
|
|
248
249
|
monospace), `sans` (the interface's reading face) or `code` (always monospace, for a VIN or a hash):
|
|
249
250
|
`display: { vin: { face: 'code' } }`. Left out, an App sets a key, a reference, a code or a QR value in the
|
|
250
251
|
data face and any other text in the reading face, because a name is not compared character by character.
|
|
251
252
|
A rule with a `component` takes no face, the component sets its own; `masked: true` takes none either. */
|
|
252
253
|
face?: 'data' | 'ui' | 'code';
|
|
254
|
+
/** With format "date" or "datetime": the IANA zone a moment is said in, over the App's `ui.timezone`. */
|
|
255
|
+
timezone?: string;
|
|
253
256
|
/** With format "rating": how many stars the scale has, 3 to 10 (5 when unsaid). */
|
|
254
257
|
outOf?: number;
|
|
255
258
|
/** With format "percent": the value as a small ring, filled against 100, beside the figure. */
|
|
@@ -298,6 +301,8 @@ export interface AppDisplayRule {
|
|
|
298
301
|
currencyColumn?: string;
|
|
299
302
|
/** For "money": the column holds whole minor units (money.ts), drawn and edited as the major figure. */
|
|
300
303
|
minor?: true;
|
|
304
|
+
/** For "money": the minor digits are left off a whole amount ("$24,495"); an amount with cents keeps them. */
|
|
305
|
+
whole?: true;
|
|
301
306
|
/** With "number", "money" or no format on a numeric column: the unit said after the figure — "mi", "kg", "/mo" (a leading slash
|
|
302
307
|
joins without a space: "$242/mo"). At most 12 characters. */
|
|
303
308
|
unit?: string;
|
|
@@ -481,8 +486,12 @@ export interface AppShell {
|
|
|
481
486
|
signed-out visitor does not, having nothing of their own to search; `{ signedOut: true }` offers it to a
|
|
482
487
|
visitor too, for an App whose public pages are worth searching. */
|
|
483
488
|
search?: 'members' | 'everyone' | false;
|
|
484
|
-
/**
|
|
485
|
-
|
|
489
|
+
/** The crumb bar: `true` everywhere with the home mark, `false` never; by default (`{ top: false, home: false }`)
|
|
490
|
+
not above a room reached straight from the menu, and without the home mark (Crumbs.tsx). */
|
|
491
|
+
breadcrumbs?: boolean | {
|
|
492
|
+
top?: boolean;
|
|
493
|
+
home?: boolean;
|
|
494
|
+
};
|
|
486
495
|
/** false keeps a room's heading for a screen reader only. Default true. */
|
|
487
496
|
heading?: boolean;
|
|
488
497
|
width?: 'full' | 'wide' | 'narrow';
|
|
@@ -639,6 +648,8 @@ export interface ServedApp<View extends object = ServedDashboardView | ServedFor
|
|
|
639
648
|
} & object)> {
|
|
640
649
|
id: string;
|
|
641
650
|
name: string;
|
|
651
|
+
/** What a phone's bar says where `name` does not fit (the App's `shortName`); `name` stays its accessible name. */
|
|
652
|
+
shortName?: string;
|
|
642
653
|
views: Record<string, View>;
|
|
643
654
|
nav: AppPayloadNavNode[];
|
|
644
655
|
home?: string;
|
package/dist/shared/view.js
CHANGED
|
@@ -199,7 +199,7 @@ export function compileView(schema, view, style, offset = 0, scope) {
|
|
|
199
199
|
const relations = new ScopedRelations(schema, style, scope);
|
|
200
200
|
const baseRelation = relations.table(base.id);
|
|
201
201
|
const plan = new JoinPlan(schema, base, style, relations.table);
|
|
202
|
-
const { resolve, qualify, membership, exists } = viewPaths(schema, view, plan, style, relations);
|
|
202
|
+
const { resolve, qualify, membership, exists, typeOf } = viewPaths(schema, view, plan, style, relations);
|
|
203
203
|
/* An empty column list means the base table's own columns. Expanding it
|
|
204
204
|
here rather than emitting `SELECT *` keeps the result's column list
|
|
205
205
|
knowable without running the statement, which is what the composer's
|
|
@@ -350,7 +350,7 @@ export function compileView(schema, view, style, offset = 0, scope) {
|
|
|
350
350
|
/* The other side of a column comparison is a path like any other: resolved
|
|
351
351
|
against this catalog, so a reader's pruned graph refuses one it may not
|
|
352
352
|
read exactly as it refuses the left. */
|
|
353
|
-
const where = buildWhere(conditions, style, prefix.params.length + 1, qualify, qualify, membership, exists);
|
|
353
|
+
const where = buildWhere(conditions, style, prefix.params.length + 1, qualify, qualify, membership, exists, false, typeOf);
|
|
354
354
|
/* Placeholder numbering continues across the whole statement, which is the
|
|
355
355
|
one thing Postgres needs and SQLite does not — and the exact place a join
|
|
356
356
|
builder gets it wrong, because the joins sit between the SELECT list and
|
|
@@ -737,7 +737,7 @@ export function compileViewCount(schema, view, style, scope, limit) {
|
|
|
737
737
|
const relations = new ScopedRelations(schema, style, scope);
|
|
738
738
|
const baseRelation = relations.table(base.id);
|
|
739
739
|
const plan = new JoinPlan(schema, base, style, relations.table);
|
|
740
|
-
const { qualify, membership, exists } = viewPaths(schema, view, plan, style, relations);
|
|
740
|
+
const { qualify, membership, exists, typeOf } = viewPaths(schema, view, plan, style, relations);
|
|
741
741
|
const conditions = viewConditions(view);
|
|
742
742
|
for (const group of conditions?.groups ?? []) {
|
|
743
743
|
for (const condition of group) {
|
|
@@ -752,7 +752,7 @@ export function compileViewCount(schema, view, style, scope, limit) {
|
|
|
752
752
|
}
|
|
753
753
|
const joins = plan.clauses();
|
|
754
754
|
const prefix = relations.finish();
|
|
755
|
-
const where = buildWhere(conditions, style, prefix.params.length + 1, qualify, qualify, membership, exists);
|
|
755
|
+
const where = buildWhere(conditions, style, prefix.params.length + 1, qualify, qualify, membership, exists, false, typeOf);
|
|
756
756
|
/* Only filter joins affect row count. Projection-only joins and scalar
|
|
757
757
|
aggregates deliberately do not register relations in this statement. */
|
|
758
758
|
const relation = `${baseRelation} ${style.quote(plan.baseAlias)}` + (joins.length ? `\n${joins.join('\n')}` : '') + where.text;
|
|
@@ -28,6 +28,7 @@ export declare function viewPaths(schema: DatabaseSchema, view: ViewDef, plan: J
|
|
|
28
28
|
qualify: (path: string, condition?: Condition) => string;
|
|
29
29
|
membership: (path: string, holes: readonly string[]) => string;
|
|
30
30
|
exists: (rows: AnyRows) => string;
|
|
31
|
+
typeOf: (path: string) => string | undefined;
|
|
31
32
|
};
|
|
32
33
|
/**
|
|
33
34
|
* The view with the record-label templates its `$label` paths need, read from
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { findTable } from './schema.js';
|
|
2
|
-
import { PathError, backrefsTo, labelColumnMeta, resolvePath, tableAtPrefix, tryResolvePath, } from './viewPaths.js';
|
|
2
|
+
import { PathError, backrefsTo, labelColumnMeta, plainType, resolvePath, tableAtPrefix, tryResolvePath, } from './viewPaths.js';
|
|
3
3
|
import { LABEL_SEGMENT, labelPrefix, parseLabelTemplate } from './recordLabel.js';
|
|
4
4
|
import { MASK } from './model.js';
|
|
5
5
|
import { rollupColumnMeta } from './rollups.js';
|
|
@@ -374,7 +374,13 @@ export function viewPaths(schema, view, plan, style, relations) {
|
|
|
374
374
|
return `COALESCE(${value}, '')`;
|
|
375
375
|
})));
|
|
376
376
|
};
|
|
377
|
-
|
|
377
|
+
/* The catalog's type of what a path reads where it reads one column as it is stored, as `qualify` writes it plain:
|
|
378
|
+
what a comparison names the database's own operator by (SqlStyle.builtin). A label, a JSON key, an expression,
|
|
379
|
+
a rollup or a record's tags is an expression and is compared as written. */
|
|
380
|
+
const typeOf = (path) => labelPrefix(path) !== undefined || jsonKeyAt(path) || expressionAt(path) || computedAt(path) || tagsAt(path)
|
|
381
|
+
? undefined
|
|
382
|
+
: plainType(schema, view.base, path);
|
|
383
|
+
return { resolve, qualify, membership, exists, typeOf };
|
|
378
384
|
}
|
|
379
385
|
/* What a stored column is to an expression that reads it: a yes-or-no column native or a 0/1 integer. */
|
|
380
386
|
function columnRead(column) {
|
|
@@ -206,6 +206,9 @@ export interface ResolvedPath {
|
|
|
206
206
|
key: string;
|
|
207
207
|
};
|
|
208
208
|
}
|
|
209
|
+
/** The type of the column a path lands on, where it is that column itself: undefined for a rollup, a computed column,
|
|
210
|
+
* a record's tags or a JSON key, which are expressions, and for a path that does not resolve. */
|
|
211
|
+
export declare function plainType(schema: DatabaseSchema, base: string, path: string): string | undefined;
|
|
209
212
|
/**
|
|
210
213
|
* Resolve a path against the schema, or explain precisely why it does not.
|
|
211
214
|
*
|
package/dist/shared/viewPaths.js
CHANGED
|
@@ -72,6 +72,14 @@ function latestReference(table, name) {
|
|
|
72
72
|
const rollup = table.rollups && Object.hasOwn(table.rollups, name) ? table.rollups[name] : undefined;
|
|
73
73
|
return rollup?.fn === 'latest' && rollup.references && !rollup.of ? rollup : undefined;
|
|
74
74
|
}
|
|
75
|
+
/** The type of the column a path lands on, where it is that column itself: undefined for a rollup, a computed column,
|
|
76
|
+
* a record's tags or a JSON key, which are expressions, and for a path that does not resolve. */
|
|
77
|
+
export function plainType(schema, base, path) {
|
|
78
|
+
const { resolved } = tryResolvePath(schema, base, path);
|
|
79
|
+
if (!resolved || resolved.rollup || resolved.computed || resolved.tags || resolved.jsonKey)
|
|
80
|
+
return undefined;
|
|
81
|
+
return resolved.column.type;
|
|
82
|
+
}
|
|
75
83
|
/**
|
|
76
84
|
* Resolve a path against the schema, or explain precisely why it does not.
|
|
77
85
|
*
|
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.12",
|
|
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": {
|
|
@@ -61,6 +61,7 @@
|
|
|
61
61
|
"./adapters/telemetry/trace.js": "./dist/adapters/telemetry/trace.js",
|
|
62
62
|
"./adapters/writeAttribution.js": "./dist/adapters/writeAttribution.js",
|
|
63
63
|
"./adapters/writeCapture.js": "./dist/adapters/writeCapture.js",
|
|
64
|
+
"./adapters/snapshotRead.js": "./dist/adapters/snapshotRead.js",
|
|
64
65
|
"./adapters/writeAhead.js": "./dist/adapters/writeAhead.js",
|
|
65
66
|
"./adapters/dbLatency.js": "./dist/adapters/dbLatency.js",
|
|
66
67
|
"./adapters/writeLanes.js": "./dist/adapters/writeLanes.js",
|
|
@@ -81,6 +82,7 @@
|
|
|
81
82
|
"./server/columnGrants.js": "./dist/server/columnGrants.js",
|
|
82
83
|
"./server/compileCache.js": "./dist/server/compileCache.js",
|
|
83
84
|
"./server/config/locations.js": "./dist/server/config/locations.js",
|
|
85
|
+
"./server/config/profile.js": "./dist/server/config/profile.js",
|
|
84
86
|
"./server/configPaths.js": "./dist/server/configPaths.js",
|
|
85
87
|
"./server/configSections.js": "./dist/server/configSections.js",
|
|
86
88
|
"./server/connections.js": "./dist/server/connections.js",
|
|
@@ -148,11 +150,13 @@
|
|
|
148
150
|
"./shared/appListColumns.js": "./dist/shared/appListColumns.js",
|
|
149
151
|
"./shared/appLocale.js": "./dist/shared/appLocale.js",
|
|
150
152
|
"./shared/appMessages.js": "./dist/shared/appMessages.js",
|
|
153
|
+
"./shared/aggregate.js": "./dist/shared/aggregate.js",
|
|
151
154
|
"./shared/appNoun.js": "./dist/shared/appNoun.js",
|
|
152
155
|
"./shared/autoBucket.js": "./dist/shared/autoBucket.js",
|
|
153
156
|
"./shared/autoValues.js": "./dist/shared/autoValues.js",
|
|
154
157
|
"./shared/breakdown.js": "./dist/shared/breakdown.js",
|
|
155
158
|
"./shared/breakdowntext.js": "./dist/shared/breakdowntext.js",
|
|
159
|
+
"./shared/decimals.js": "./dist/shared/decimals.js",
|
|
156
160
|
"./shared/clauses.js": "./dist/shared/clauses.js",
|
|
157
161
|
"./shared/columnCaption.js": "./dist/shared/columnCaption.js",
|
|
158
162
|
"./shared/commandFieldPath.js": "./dist/shared/commandFieldPath.js",
|
|
@@ -195,7 +199,6 @@
|
|
|
195
199
|
"./shared/moneyEntry.js": "./dist/shared/moneyEntry.js",
|
|
196
200
|
"./shared/mount.js": "./dist/shared/mount.js",
|
|
197
201
|
"./shared/niceTicks.js": "./dist/shared/niceTicks.js",
|
|
198
|
-
"./shared/order.js": "./dist/shared/order.js",
|
|
199
202
|
"./shared/page.js": "./dist/shared/page.js",
|
|
200
203
|
"./shared/pageAnatomy.js": "./dist/shared/pageAnatomy.js",
|
|
201
204
|
"./shared/pageConfig.js": "./dist/shared/pageConfig.js",
|
package/schema/model.d.ts
CHANGED
|
@@ -157,7 +157,7 @@ export type AppCommandField = (CommandValueBase & (
|
|
|
157
157
|
| { type: 'richText'; minLength?: number; maxLength?: number; mentions?: CommandRichTextMentions; images?: string }
|
|
158
158
|
| { type: 'number'; min?: number; max?: number; integer?: boolean; step?: number; below?: string; above?: string; live?: CommandLiveLines }
|
|
159
159
|
/** An amount of money in the App's currency (`ui.currency`), from 0 unless `min` says less, on cents unless `step` says otherwise. */
|
|
160
|
-
| { type: 'money'; min?: number; max?: number; step?: number; below?: string; above?: string; live?: CommandLiveLines }
|
|
160
|
+
| { type: 'money'; min?: number; max?: number; step?: number; minor?: boolean; currency?: string; below?: string; above?: string; live?: CommandLiveLines }
|
|
161
161
|
/** `statement`: the long words a consent box stands beside (at most 2,000 characters), drawn as one paragraph. */
|
|
162
162
|
| { type: 'boolean'; accept?: true; statement?: string }
|
|
163
163
|
| { type: 'date'; min?: string; max?: string; below?: string; above?: string }
|
package/dist/shared/order.d.ts
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* What has to exist first, and what comes apart in which order.
|
|
3
|
-
*
|
|
4
|
-
* Every foreign key is a statement about time: a row cannot point at a row
|
|
5
|
-
* that is not there yet, and a row that is pointed at cannot leave before the
|
|
6
|
-
* rows pointing at it. Building test data means knowing that order, and
|
|
7
|
-
* deriving it by hand from a catalog is exactly the work this tool already
|
|
8
|
-
* did to draw the graph.
|
|
9
|
-
*
|
|
10
|
-
* A topological sort, with the two things a topological sort usually leaves
|
|
11
|
-
* out said out loud:
|
|
12
|
-
*
|
|
13
|
-
* - **Cycles.** Two tables that point at each other have no order. Rather
|
|
14
|
-
* than picking one and pretending, the cycle is named — and where one of
|
|
15
|
-
* its edges is nullable, the way through is named too: insert with the
|
|
16
|
-
* column null, then update it once the other row exists.
|
|
17
|
-
* - **Self-references.** `work_order.parent_id → work_order` is not a
|
|
18
|
-
* cycle between tables and does not affect the order at all, but it does
|
|
19
|
-
* mean the rows inside that table have an order of their own. Reported
|
|
20
|
-
* separately, because it is a different problem with a different answer.
|
|
21
|
-
*
|
|
22
|
-
* Ties break alphabetically. A stable answer is worth more than a marginally
|
|
23
|
-
* shorter one: an order that changes between runs makes a fixture that
|
|
24
|
-
* "sometimes works", which is the failure this exists to prevent.
|
|
25
|
-
*/
|
|
26
|
-
import { type DatabaseSchema } from './schema.js';
|
|
27
|
-
interface Requirement {
|
|
28
|
-
/** The table that must have the row already. */
|
|
29
|
-
table: string;
|
|
30
|
-
/** The columns pointing at it. */
|
|
31
|
-
via: string[];
|
|
32
|
-
/**
|
|
33
|
-
* Whether every one of those columns may be null.
|
|
34
|
-
*
|
|
35
|
-
* A nullable reference is a requirement you can postpone: insert the row
|
|
36
|
-
* without it, then update. That is the only way out of a cycle, so it is
|
|
37
|
-
* worth saying even where the order came out fine.
|
|
38
|
-
*/
|
|
39
|
-
optional: boolean;
|
|
40
|
-
}
|
|
41
|
-
interface OrderPlan {
|
|
42
|
-
/** Parents first: insert in this order and no reference dangles. */
|
|
43
|
-
insert: string[];
|
|
44
|
-
/** Children first: the reverse, which is what teardown needs. */
|
|
45
|
-
remove: string[];
|
|
46
|
-
/** Per table, what must exist before it. */
|
|
47
|
-
requires: Record<string, Requirement[]>;
|
|
48
|
-
/** Tables whose order could not be decided, grouped by the cycle they are in. */
|
|
49
|
-
cycles: string[][];
|
|
50
|
-
/** Tables that point at themselves: an order *within* the table. */
|
|
51
|
-
selfReferencing: string[];
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* @param tables The tables to order. Omitted means every table in the schema.
|
|
55
|
-
* Names are resolved through `findTable`, so a bare name works where the
|
|
56
|
-
* schema qualifies it.
|
|
57
|
-
*/
|
|
58
|
-
export declare function insertOrder(schema: DatabaseSchema, tables?: string[]): OrderPlan;
|
|
59
|
-
export {};
|