@mistriwork/engine 1.0.0-rc.11 → 1.0.0-rc.13

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.
Files changed (52) hide show
  1. package/dist/adapters/postgres.js +28 -3
  2. package/dist/adapters/scoped/postgresScopeCatalog.d.ts +22 -1
  3. package/dist/adapters/scoped/postgresScopeCatalog.js +66 -2
  4. package/dist/adapters/scoped/scopedReads.js +6 -4
  5. package/dist/adapters/scoped/scopedTransaction.d.ts +21 -2
  6. package/dist/adapters/scoped/scopedTransaction.js +37 -7
  7. package/dist/adapters/sqlite.js +1 -1
  8. package/dist/server/cli/bin.js +2 -2
  9. package/dist/server/cli/startup.js +2 -2
  10. package/dist/server/cli/usage.d.ts +2 -2
  11. package/dist/server/cli/usage.js +2 -2
  12. package/dist/server/demo.js +2 -2
  13. package/dist/server/http/baselineHeaders.d.ts +2 -0
  14. package/dist/server/http/baselineHeaders.js +2 -0
  15. package/dist/server/http/crawlerText.d.ts +4 -1
  16. package/dist/server/http/crawlerText.js +4 -1
  17. package/dist/server/http/httpOperationRoutes.d.ts +4 -1
  18. package/dist/server/http/httpOperationRoutes.js +4 -1
  19. package/dist/server/http/reply.d.ts +1 -0
  20. package/dist/server/http/reply.js +1 -0
  21. package/dist/server/http/router.d.ts +11 -22
  22. package/dist/server/http/router.js +0 -15
  23. package/dist/server/http/trust.d.ts +1 -0
  24. package/dist/server/http/trust.js +1 -0
  25. package/dist/server/product.d.ts +1 -1
  26. package/dist/server/recordWriteOperations.d.ts +2 -1
  27. package/dist/server/recordWriteOperations.js +2 -1
  28. package/dist/server/resourceReadHttp.d.ts +1 -0
  29. package/dist/server/resourceReadHttp.js +1 -0
  30. package/dist/shared/addressParams.d.ts +2 -0
  31. package/dist/shared/addressParams.js +2 -0
  32. package/dist/shared/breakdown.js +2 -2
  33. package/dist/shared/filter.d.ts +18 -1
  34. package/dist/shared/filter.js +62 -8
  35. package/dist/shared/listPresentations.d.ts +2 -0
  36. package/dist/shared/listQuestion.d.ts +3 -1
  37. package/dist/shared/moneyEntry.d.ts +6 -3
  38. package/dist/shared/moneyEntry.js +14 -7
  39. package/dist/shared/recordview.d.ts +1 -1
  40. package/dist/shared/rowScope.js +12 -4
  41. package/dist/shared/schematext.d.ts +22 -6
  42. package/dist/shared/schematext.js +18 -2
  43. package/dist/shared/servedApp.d.ts +8 -2
  44. package/dist/shared/view.js +4 -4
  45. package/dist/shared/viewLabels.d.ts +1 -0
  46. package/dist/shared/viewLabels.js +8 -2
  47. package/dist/shared/viewPaths.d.ts +3 -0
  48. package/dist/shared/viewPaths.js +8 -0
  49. package/package.json +4 -2
  50. package/schema/model.d.ts +1 -1
  51. package/dist/shared/order.d.ts +0 -59
  52. package/dist/shared/order.js +0 -133
@@ -2,7 +2,7 @@
2
2
  * Which product this process is: the database browser (`tablewalk`) or the App framework (`mistri`). The engine is
3
3
  * both binaries', and what an operator sets is said in the binary's own name: `TABLEWALK_READ_POOL` for the
4
4
  * browser, `MISTRI_READ_POOL` for an App, read by the same code here. Each main says which it is before it reads a
5
- * flag (packages/tablewalk/src/server/cli/browserMain.ts, packages/mistri/src/server/cli/mistriMain.ts); anything
5
+ * flag (packages/mistri/src/server/cli/mistriMain.ts here, the database browser's main in its own repository); anything
6
6
  * else that runs the engine — an App mounted in a host's server (`createHandler`), a test — is an App's.
7
7
  *
8
8
  * Only the variables both binaries read go through here. A variable one product alone reads names itself.
@@ -98,7 +98,8 @@ export declare function recordedImport(options: RecordWriteOptions, inputs: read
98
98
  */
99
99
  export declare function recordedDelete(options: RecordWriteOptions, input: DeleteRequest, dependents?: Dependents): Promise<Recorded<DeleteResult>>;
100
100
  /** The incoming references a deletion of `table` would change rows through:
101
- * every rule but a refusal, an unreported one included. */
101
+ * every rule but a refusal, an unreported one included.
102
+ * @public the database browser's (scripts/boundary/entries.json, "host") */
102
103
  export declare function changingReferences(schema: DatabaseSchema, table: string): ForeignKey[];
103
104
  /**
104
105
  * A deletion's dependents read off the database's own catalog, never an
@@ -303,7 +303,8 @@ async function touchesDependents(tx, key, dependents) {
303
303
  return false;
304
304
  }
305
305
  /** The incoming references a deletion of `table` would change rows through:
306
- * every rule but a refusal, an unreported one included. */
306
+ * every rule but a refusal, an unreported one included.
307
+ * @public the database browser's (scripts/boundary/entries.json, "host") */
307
308
  export function changingReferences(schema, table) {
308
309
  return referencesTo(schema, table).filter((fk) => !fk.declared && fk.onDelete !== 'restrict' && fk.onDelete !== 'no action');
309
310
  }
@@ -68,6 +68,7 @@ export declare function dispatchResourceReadHttp(path: string, body: Record<stri
68
68
  * The adapter picks its own style when it runs the statement; this is the
69
69
  * copy the user reads, and it has to agree with what actually ran or the
70
70
  * panel is teaching the wrong thing.
71
+ * @public the database browser's (scripts/boundary/entries.json, "host")
71
72
  */
72
73
  export declare function styleFor(schema: DatabaseSchema): SqlStyle;
73
74
  /**
@@ -561,6 +561,7 @@ async function runViewForBar(adapter, schema, view, body, app, countMode = 'exac
561
561
  * The adapter picks its own style when it runs the statement; this is the
562
562
  * copy the user reads, and it has to agree with what actually ran or the
563
563
  * panel is teaching the wrong thing.
564
+ * @public the database browser's (scripts/boundary/entries.json, "host")
564
565
  */
565
566
  export function styleFor(schema) {
566
567
  if (schema.dialect === 'postgres')
@@ -26,3 +26,5 @@ export declare function addressSortValue(raw: string): {
26
26
  }[] | undefined;
27
27
  /** All time, said where a dashboard opens on a window of its own (`window: 'last 30 days'`): `?period=all-time`. */
28
28
  export declare const ALL_TIME = "all-time";
29
+ /** An address's `period=` as it is read: `all` is the word a person guesses, and means all time as `all-time` does. */
30
+ export declare const readPeriod: (word: string) => string;
@@ -45,3 +45,5 @@ export function addressSortValue(raw) {
45
45
  }
46
46
  /** All time, said where a dashboard opens on a window of its own (`window: 'last 30 days'`): `?period=all-time`. */
47
47
  export const ALL_TIME = 'all-time';
48
+ /** An address's `period=` as it is read: `all` is the word a person guesses, and means all time as `all-time` does. */
49
+ export const readPeriod = (word) => (word === 'all' ? ALL_TIME : word);
@@ -416,12 +416,12 @@ function compileBreakdownFresh(schema, def, style, offset, scope) {
416
416
  const prefix = relations.finish();
417
417
  const whenParams = [];
418
418
  for (const { at, name, where: held } of whens) {
419
- const built = buildWhere(asFilter(held), style, prefix.params.length + whenParams.length + 1, qualify, qualify, membership, exists);
419
+ const built = buildWhere(asFilter(held), style, prefix.params.length + whenParams.length + 1, qualify, qualify, membership, exists, false, paths.typeOf);
420
420
  whenParams.push(...built.params);
421
421
  /* COUNT, not SUM: a count of no rows is 0, where a sum of none is null. */
422
422
  select[at] = `COUNT(CASE WHEN ${built.text.replace(/^ WHERE /, '')} THEN 1 END) AS ${style.quote(name)}`;
423
423
  }
424
- const where = buildWhere(conditions, style, prefix.params.length + whenParams.length + 1, qualify, qualify, membership, exists);
424
+ const where = buildWhere(conditions, style, prefix.params.length + whenParams.length + 1, qualify, qualify, membership, exists, false, paths.typeOf);
425
425
  /* Sorted by output name, and only by output name.
426
426
 
427
427
  Every column of a breakdown is either a key or a measure, and both are in
@@ -174,6 +174,20 @@ export interface SqlStyle {
174
174
  jsonKey?(expression: string, key: string, as: 'value' | 'text' | 'number'): string;
175
175
  /** Whether a JSON key's list (or its one value) holds any of the bound values: `has` on a many-of-a-list field. */
176
176
  jsonHas?(expression: string, key: string, holes: readonly string[]): string;
177
+ /**
178
+ * The built-in type a column of `type` (ColumnMeta.type, the catalog's own word) compares as, where a comparison
179
+ * names its operator by schema: PostgreSQL's `OPERATOR(pg_catalog.=)`, as `name` (what an IN list is read as) and
180
+ * whether a pattern reads it as text. A bare `=` resolves through the search_path, where an exact signature
181
+ * pg_catalog lacks (`varchar = varchar`) wins over pg_catalog's own. Undefined for every other type (an enum, an
182
+ * extension's citext), whose operators are its own and stay as written. Only where `buildWhere` is told the types
183
+ * (`types`): an App's scoped reads.
184
+ */
185
+ builtin?(type: string): {
186
+ readonly name: string;
187
+ readonly text: boolean;
188
+ } | undefined;
189
+ /** A condition that holds for no row, said with no operator a search_path can shadow where the dialect has one. */
190
+ never?: string;
177
191
  }
178
192
  /** The periods a breakdown can group dates by: a calendar's (day to year), and the two that recur — the ISO
179
193
  weekday, "1" (Monday) to "7", and the hour of the day, "00" to "23" — which a heat map crosses. */
@@ -234,5 +248,8 @@ membership?: (name: string, holes: readonly string[]) => string,
234
248
  /** How an `any` condition is written: an EXISTS over the child's rows, binding nothing of its own; absent, one is refused. */
235
249
  exists?: (rows: AnyRows) => string,
236
250
  /** Whether a condition may compare as a foreign key does (`Condition.equality`): a scoped write's own reads only. */
237
- references?: boolean): SqlFragment;
251
+ references?: boolean,
252
+ /** The catalog's type of a column the filter names, where the style names its operators by schema
253
+ * (SqlStyle.builtin): an App's scoped reads. Absent, or undefined for a name, the operator as written. */
254
+ types?: (name: string) => string | undefined): SqlFragment;
238
255
  export {};
@@ -105,7 +105,38 @@ export const POSTGRES_STYLE = {
105
105
  ? `CASE WHEN jsonb_typeof((${e})::jsonb -> '${key}') = 'number' THEN ((${e})::jsonb ->> '${key}')::numeric END`
106
106
  : `((${e})::jsonb ->> '${key}')`,
107
107
  jsonHas: (e, key, holes) => `(((${e})::jsonb -> '${key}') ?| ARRAY[${holes.join(', ')}]::text[])`,
108
+ /* information_schema's data_type, which says a domain by its base type: a varchar is read as text, as pg_catalog
109
+ compares it, and a char as bpchar, which keeps its trailing blanks insignificant without char(1)'s truncation. */
110
+ builtin: (type) => {
111
+ const name = POSTGRES_BUILTIN[type];
112
+ return name === undefined ? undefined : { name, text: name === 'text' || name === 'bpchar' };
113
+ },
114
+ never: 'FALSE',
108
115
  };
116
+ /* The types a comparison names pg_catalog's operator for, by information_schema's word for them, and the name an IN
117
+ list is cast to. Absent: USER-DEFINED (an enum, citext, an extension's type) and ARRAY. */
118
+ const POSTGRES_BUILTIN = Object.assign(Object.create(null), {
119
+ text: 'text',
120
+ 'character varying': 'text',
121
+ character: 'bpchar',
122
+ smallint: 'int2',
123
+ integer: 'int4',
124
+ bigint: 'int8',
125
+ numeric: 'numeric',
126
+ real: 'float4',
127
+ 'double precision': 'float8',
128
+ boolean: 'bool',
129
+ uuid: 'uuid',
130
+ date: 'date',
131
+ 'timestamp without time zone': 'timestamp',
132
+ 'timestamp with time zone': 'timestamptz',
133
+ 'time without time zone': 'time',
134
+ 'time with time zone': 'timetz',
135
+ interval: 'interval',
136
+ bytea: 'bytea',
137
+ jsonb: 'jsonb',
138
+ inet: 'inet',
139
+ });
109
140
  /**
110
141
  * Postgres 12 and later: row-scope CTEs stay inlined however often a read
111
142
  * joins their table. The adapter picks it once it knows the server's version
@@ -181,12 +212,27 @@ membership,
181
212
  /** How an `any` condition is written: an EXISTS over the child's rows, binding nothing of its own; absent, one is refused. */
182
213
  exists,
183
214
  /** Whether a condition may compare as a foreign key does (`Condition.equality`): a scoped write's own reads only. */
184
- references = false) {
215
+ references = false,
216
+ /** The catalog's type of a column the filter names, where the style names its operators by schema
217
+ * (SqlStyle.builtin): an App's scoped reads. Absent, or undefined for a name, the operator as written. */
218
+ types) {
185
219
  if (!filter?.groups.length)
186
220
  return { text: '', params: [] };
187
221
  const params = [];
188
222
  let index = startIndex;
189
223
  const next = () => style.placeholder(index++);
224
+ const never = style.never ?? '1 = 0';
225
+ /* PostgreSQL's own operator for a built-in type, named so: a schema author's `=` on the search_path cannot decide
226
+ which rows a policy or a filter admits (SqlStyle.builtin). */
227
+ const builtin = (name) => {
228
+ const type = types?.(name);
229
+ return type === undefined ? undefined : style.builtin?.(type);
230
+ };
231
+ const operator = (op) => `OPERATOR(pg_catalog.${op === '!=' ? '<>' : op})`;
232
+ /* ILIKE … ESCAPE is `~~*` of like_escape, as the parser rewrites it; spelled so, the operator can be named. */
233
+ const pattern = (col, name) => style.likeOp === 'ILIKE' && builtin(name)?.text
234
+ ? `${col} ${operator('~~*')} pg_catalog.like_escape(${next()}, '${LIKE_ESCAPE}')`
235
+ : `${col} ${style.likeOp} ${next()} ESCAPE '${LIKE_ESCAPE}'`;
190
236
  /* A condition every group holds is said once, before the OR: the same
191
237
  rows (AND distributes over OR in SQL's three-valued logic too), and the
192
238
  shape an engine can read a range from. A keyset page's bound is in every
@@ -219,7 +265,7 @@ references = false) {
219
265
  throw new RequestFault("This read cannot ask a record's tags.");
220
266
  const labels = (Array.isArray(c.value) ? c.value : [c.value]).filter((v) => typeof v === 'string' || typeof v === 'number');
221
267
  if (!labels.length)
222
- return '1 = 0';
268
+ return never;
223
269
  const holes = labels.map((v) => {
224
270
  params.push(String(v));
225
271
  return next();
@@ -231,11 +277,14 @@ references = false) {
231
277
  if (!references ||
232
278
  c.op !== '=' ||
233
279
  c.collation !== undefined ||
234
- c.other !== undefined ||
280
+ (c.other !== undefined && (!other || typeof c.other !== 'string')) ||
235
281
  typeof operator !== 'string' ||
236
282
  !SQL_OPERATOR.test(operator) ||
237
283
  ![type, left, right].every((part, at) => (at > 0 && part === undefined) || (typeof part === 'string' && SQL_TYPE.test(part))))
238
284
  throw new RequestFault('This read cannot compare as a foreign key does.');
285
+ /* A reference column on the right, as ri_triggers.c joins a key to its references: of its own type already. */
286
+ if (c.other !== undefined)
287
+ return `${column(c.column, c)}${left ? `::${left}` : ''} OPERATOR(${operator}) ${other(c.other)}${right ? `::${right}` : ''}`;
239
288
  params.push(c.value ?? null);
240
289
  return `${column(c.column, c)}${left ? `::${left}` : ''} OPERATOR(${operator}) ${next()}::${type}${right ? `::${right}` : ''}`;
241
290
  }
@@ -244,7 +293,8 @@ references = false) {
244
293
  if (!other || typeof c.other !== 'string' || !COMPARISONS.has(c.op)) {
245
294
  throw new RequestFault('This read cannot compare two columns.');
246
295
  }
247
- return `${col} ${c.op} ${collate(other(c.other), c.collation, style)}`;
296
+ const op = builtin(c.column) && builtin(c.other) ? operator(c.op) : c.op;
297
+ return `${col} ${op} ${collate(other(c.other), c.collation, style)}`;
248
298
  }
249
299
  switch (c.op) {
250
300
  case 'isNull':
@@ -254,11 +304,15 @@ references = false) {
254
304
  case 'in': {
255
305
  const list = Array.isArray(c.value) ? c.value : [c.value];
256
306
  if (!list.length)
257
- return '1 = 0'; // an empty IN matches nothing
307
+ return never; // an empty IN matches nothing
258
308
  const holes = list.map((v) => {
259
309
  params.push(v ?? null);
260
310
  return next();
261
311
  });
312
+ /* IN has no operator to name: the same rows as `= ANY` of the list read as the column's type. */
313
+ const typed = builtin(c.column);
314
+ if (typed)
315
+ return `${col} ${operator('=')} ANY (ARRAY[${holes.join(', ')}]::pg_catalog.${typed.name}[])`;
262
316
  return `${col} IN (${holes.join(', ')})`;
263
317
  }
264
318
  /* All three go through one pattern builder, which escapes the
@@ -268,7 +322,7 @@ references = false) {
268
322
  case 'startsWith':
269
323
  case 'endsWith':
270
324
  params.push(likePattern(c.value, c.op));
271
- return `${col} ${style.likeOp} ${next()} ESCAPE '${LIKE_ESCAPE}'`;
325
+ return pattern(col, c.column);
272
326
  /* Bound, not escaped: the wildcards belong to whoever typed them.
273
327
  Still a parameter — the value never becomes SQL text — so the
274
328
  safety argument is unchanged, and still `ESCAPE '#'`, so the
@@ -276,7 +330,7 @@ references = false) {
276
330
  internally. */
277
331
  case 'like':
278
332
  params.push(String(c.value ?? ''));
279
- return `${col} ${style.likeOp} ${next()} ESCAPE '${LIKE_ESCAPE}'`;
333
+ return pattern(col, c.column);
280
334
  default: {
281
335
  /* The one field in a structured request that becomes SQL text
282
336
  rather than a bound parameter — and until now it was checked
@@ -292,7 +346,7 @@ references = false) {
292
346
  throw new RequestFault(`"${String(c.op)}" is not an operator this tool knows.`);
293
347
  }
294
348
  params.push(c.value ?? null);
295
- return `${col} ${c.op} ${next()}`;
349
+ return `${col} ${builtin(c.column) ? operator(c.op) : c.op} ${next()}`;
296
350
  }
297
351
  }
298
352
  })
@@ -23,6 +23,8 @@ export interface AppListTab {
23
23
  slug?: string;
24
24
  /** The resource's segment the tab names (appSegments.ts): its `query` is that word, written out where it is read. */
25
25
  segment?: string;
26
+ /** What the tab says while nothing is under it and nothing narrows it past its own condition. */
27
+ empty?: AppListEmpty;
26
28
  }
27
29
  /**
28
30
  * Data only: the renderer supplies the list and detail nodes. One of the
@@ -1,6 +1,6 @@
1
1
  import { type DatabaseSchema } from './schema.js';
2
2
  import type { ServedResource } from './servedApp.js';
3
- import type { AppListPresentation } from './listPresentations.js';
3
+ import type { AppListEmpty, AppListPresentation } from './listPresentations.js';
4
4
  /** What a list's question is read over: the schema, and the App's resources — their record labels and display rules. */
5
5
  export interface ListRules {
6
6
  readonly schema: DatabaseSchema;
@@ -12,6 +12,8 @@ export interface ListTab {
12
12
  query?: string;
13
13
  /** Its word in an address where the label is said in another language (addressParams.ts `tabKey`). */
14
14
  slug?: string;
15
+ /** What it says while it holds no row and nothing narrows it past its own condition. */
16
+ empty?: AppListEmpty;
15
17
  }
16
18
  /** What of a list view its question is made from. */
17
19
  export interface ListQuestionSpec {
@@ -1,7 +1,10 @@
1
1
  /**
2
2
  * A major amount — a number, or decimal text with a point ("19.99", "-5",
3
- * ".5") — as the whole number of minor units it is, or undefined when it is
4
- * no amount or says more decimals than the currency has: 19.999 dollars is a
5
- * typo, not a value to round.
3
+ * ".5") — as the whole number of minor units it is, written out in digits
4
+ * ("1999"), or undefined when it is no amount or says more decimals than the
5
+ * currency has: 19.999 dollars is a typo, not a value to round. Text to text,
6
+ * never through a float, so an amount past 2^53 stays exact.
6
7
  */
8
+ export declare function majorToMinorText(major: number | string, currency: string): string | undefined;
9
+ /** The same amount as a number of minor units, or undefined past 2^53 too (use majorToMinorText there). */
7
10
  export declare function majorToMinor(major: number | string, currency: string): number | undefined;
@@ -7,11 +7,12 @@
7
7
  import { currencyDigits } from './money.js';
8
8
  /**
9
9
  * A major amount — a number, or decimal text with a point ("19.99", "-5",
10
- * ".5") — as the whole number of minor units it is, or undefined when it is
11
- * no amount or says more decimals than the currency has: 19.999 dollars is a
12
- * typo, not a value to round.
10
+ * ".5") — as the whole number of minor units it is, written out in digits
11
+ * ("1999"), or undefined when it is no amount or says more decimals than the
12
+ * currency has: 19.999 dollars is a typo, not a value to round. Text to text,
13
+ * never through a float, so an amount past 2^53 stays exact.
13
14
  */
14
- export function majorToMinor(major, currency) {
15
+ export function majorToMinorText(major, currency) {
15
16
  const text = typeof major === 'number' ? (Number.isFinite(major) ? String(major) : '') : major.trim();
16
17
  const m = /^([-+]?)(\d*)(?:\.(\d*))?$/.exec(text);
17
18
  if (!m || (!m[2] && !m[3]))
@@ -20,8 +21,14 @@ export function majorToMinor(major, currency) {
20
21
  const fraction = (m[3] ?? '').replace(/0+$/, '');
21
22
  if (fraction.length > digits)
22
23
  return undefined;
23
- const n = Number(`${m[2] || '0'}${fraction.padEnd(digits, '0')}`);
24
- if (!Number.isSafeInteger(n))
24
+ const whole = `${m[2]}${fraction.padEnd(digits, '0')}`.replace(/^0+(?=\d)/, '') || '0';
25
+ return m[1] === '-' && whole !== '0' ? `-${whole}` : whole;
26
+ }
27
+ /** The same amount as a number of minor units, or undefined past 2^53 too (use majorToMinorText there). */
28
+ export function majorToMinor(major, currency) {
29
+ const text = majorToMinorText(major, currency);
30
+ if (text === undefined)
25
31
  return undefined;
26
- return m[1] === '-' && n !== 0 ? -n : n;
32
+ const n = Number(text);
33
+ return Number.isSafeInteger(n) ? n : undefined;
27
34
  }
@@ -29,7 +29,7 @@
29
29
  */
30
30
  import { type ColumnMeta, type DatabaseSchema, type ForeignKey, type TableMeta } from './schema.js';
31
31
  /** A block of the base record's own fields, or of a to-one reference's. */
32
- interface FieldSection {
32
+ export interface FieldSection {
33
33
  kind: 'fields';
34
34
  /** Shown above the block. Absent means no heading. */
35
35
  title?: string;
@@ -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 ? '' : ' WHERE 1 = 0', params: [] }
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
- const where = buildWhere(filter, this.style, this.params.length + 1, local, local);
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);
@@ -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
- /** The tables to export, and the keys wholly between them. */
10
- export declare function selection(schema: any, only: any): {
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: any): string;
29
- /** A readable reference document, of the kind that belongs in a repository. */
30
- export declare function toMarkdown(schema: any, only: any): string;
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: any): string;
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
- /** The tables to export, and the keys wholly between them. */
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
- /** A readable reference document, of the kind that belongs in a repository. */
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);
@@ -486,8 +486,12 @@ export interface AppShell {
486
486
  signed-out visitor does not, having nothing of their own to search; `{ signedOut: true }` offers it to a
487
487
  visitor too, for an App whose public pages are worth searching. */
488
488
  search?: 'members' | 'everyone' | false;
489
- /** false hides the crumb bar above a room. Default true. */
490
- breadcrumbs?: boolean;
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
+ };
491
495
  /** false keeps a room's heading for a screen reader only. Default true. */
492
496
  heading?: boolean;
493
497
  width?: 'full' | 'wide' | 'narrow';
@@ -644,6 +648,8 @@ export interface ServedApp<View extends object = ServedDashboardView | ServedFor
644
648
  } & object)> {
645
649
  id: string;
646
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;
647
653
  views: Record<string, View>;
648
654
  nav: AppPayloadNavNode[];
649
655
  home?: string;
@@ -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
- return { resolve, qualify, membership, exists };
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
  *
@@ -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.11",
3
+ "version": "1.0.0-rc.13",
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": {
@@ -29,6 +29,9 @@
29
29
  "./adapters/connect.js": "./dist/adapters/connect.js",
30
30
  "./adapters/connectionBudget.js": "./dist/adapters/connectionBudget.js",
31
31
  "./adapters/http/egress.js": "./dist/adapters/http/egress.js",
32
+ "./adapters/http/httpAdapter.js": "./dist/adapters/http/httpAdapter.js",
33
+ "./adapters/http/httpDescription.js": "./dist/adapters/http/httpDescription.js",
34
+ "./adapters/http/openapi.js": "./dist/adapters/http/openapi.js",
32
35
  "./adapters/layoutRefusal.js": "./dist/adapters/layoutRefusal.js",
33
36
  "./adapters/net/networkPolicy.js": "./dist/adapters/net/networkPolicy.js",
34
37
  "./adapters/net/untrustedDatabase.js": "./dist/adapters/net/untrustedDatabase.js",
@@ -199,7 +202,6 @@
199
202
  "./shared/moneyEntry.js": "./dist/shared/moneyEntry.js",
200
203
  "./shared/mount.js": "./dist/shared/mount.js",
201
204
  "./shared/niceTicks.js": "./dist/shared/niceTicks.js",
202
- "./shared/order.js": "./dist/shared/order.js",
203
205
  "./shared/page.js": "./dist/shared/page.js",
204
206
  "./shared/pageAnatomy.js": "./dist/shared/pageAnatomy.js",
205
207
  "./shared/pageConfig.js": "./dist/shared/pageConfig.js",