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

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.
@@ -71,5 +71,5 @@ export declare class ValkeyCacheStore implements CacheStore {
71
71
  close(): Promise<void>;
72
72
  private unavailable;
73
73
  }
74
- /** The same store under a key prefix: `tw:<app>:http:<connection>:`, say. */
74
+ /** The same store under a key prefix: `mistri:<app>:http:<connection>:`, say. */
75
75
  export declare function scopedCache(store: CacheStore, prefix: string): CacheStore;
@@ -147,7 +147,7 @@ export class ValkeyCacheStore {
147
147
  this.onUnavailable(error instanceof CacheUnavailable || error instanceof RespReplyError ? error.message : 'the cache failed.');
148
148
  }
149
149
  }
150
- /** The same store under a key prefix: `tw:<app>:http:<connection>:`, say. */
150
+ /** The same store under a key prefix: `mistri:<app>:http:<connection>:`, say. */
151
151
  export function scopedCache(store, prefix) {
152
152
  return {
153
153
  kind: store.kind,
@@ -212,7 +212,7 @@ export class HttpAdapter {
212
212
  throw new Refusal(`${view.base} comes from an API, so a view over it ${why}`);
213
213
  };
214
214
  if (view.aggregates?.length || view.orderBy?.some((order) => order.alias))
215
- refuse('cannot summarise the records that point at it.');
215
+ refuse('cannot summarize the records that point at it.');
216
216
  if (view.filter?.groups.some((group) => group.some((condition) => condition.any)))
217
217
  refuse('cannot ask about the records that point at it.');
218
218
  const deep = compiled.columns.find((column) => column.hops > 1);
@@ -73,9 +73,11 @@ export function exposureLines(host, apps, authProxyHeader) {
73
73
  return [];
74
74
  if (authProxyHeader)
75
75
  return [];
76
- const remedy = 'Bind --host 127.0.0.1, put it behind a proxy that signs people in (--auth-proxy-header), or give the App sign-in.';
76
+ const way = 'Bind --host 127.0.0.1, put it behind a proxy that signs people in (--auth-proxy-header)';
77
+ /* No App is served (the database browser, or a Workbench): there is no App sign-in to give. */
77
78
  if (!apps.length)
78
- return [`Warning: bound to ${host}, beyond loopback, with no sign-in. Anyone who can reach this port can read the database. ${remedy}`];
79
+ return [`Warning: bound to ${host}, beyond loopback, with no sign-in. Anyone who can reach this port can read the database. ${way}.`];
80
+ const remedy = `${way}, or give the App sign-in.`;
79
81
  return apps.map((app) => !app.auth
80
82
  ? `Warning: bound to ${host}, beyond loopback, and "${app.name}" signs no one in: anyone who can reach this port reads what it shows. ${remedy}`
81
83
  : app.auth.public?.read.length
@@ -9,5 +9,8 @@ export declare function commandWordsOf(usage: string, bin: string): string[];
9
9
  export declare function flagWordsOf(usage: string): string[];
10
10
  /** What was probably meant, said the way a person would type it, or nothing when nothing is near. */
11
11
  export declare function didYouMean(said: string, among: readonly string[]): Promise<string>;
12
- /** What the package says it is, best effort. Every package of the workspace carries the one version. */
12
+ /**
13
+ * What this process says it is, best effort: the host product's own version when its main gave one (`setProduct`),
14
+ * else the package's. Every package of the workspace carries the one version.
15
+ */
13
16
  export declare function packageVersion(): Promise<string>;
@@ -3,6 +3,7 @@
3
3
  * is read for its command and flag words. Each binary keeps its own `USAGE` (packages/mistri/src/server/cli/usage.ts
4
4
  * here, the database browser's in its own repository), and each is held to its own README.
5
5
  */
6
+ import { productVersion } from '../product.js';
6
7
  /** The command words a usage names (`tablewalk migrate`, `mistri check`, …), for a near miss's suggestion. */
7
8
  export function commandWordsOf(usage, bin) {
8
9
  return [...new Set([...usage.matchAll(new RegExp(`^ {2}${bin} ([a-z][a-z-]*)(?=\\s|$)`, 'gm'))].map((match) => match[1]))];
@@ -19,8 +20,14 @@ export async function didYouMean(said, among) {
19
20
  ? ` Did you mean ${near}?`
20
21
  : '';
21
22
  }
22
- /** What the package says it is, best effort. Every package of the workspace carries the one version. */
23
+ /**
24
+ * What this process says it is, best effort: the host product's own version when its main gave one (`setProduct`),
25
+ * else the package's. Every package of the workspace carries the one version.
26
+ */
23
27
  export async function packageVersion() {
28
+ const host = productVersion();
29
+ if (host)
30
+ return host;
24
31
  try {
25
32
  const { runtimeVersion } = await import('../packageVersion.js');
26
33
  return runtimeVersion();
@@ -19,7 +19,7 @@
19
19
  */
20
20
  import { readFile, writeFile, mkdir } from 'node:fs/promises';
21
21
  import { dirname, resolve } from 'node:path';
22
- import { connect } from '../adapters/connect.js';
22
+ import { connect, MYSQL_REFUSAL } from '../adapters/connect.js';
23
23
  import { UNTRUSTED_NETWORK } from '../adapters/net/untrustedDatabase.js';
24
24
  import { configLocations } from './config/locations.js';
25
25
  import { redact, scrubSecrets } from './connectionRedaction.js';
@@ -438,13 +438,18 @@ export class Registry {
438
438
  const opened = await openHttp(entry.config.name, entry.config.url, entry.config.http, {
439
439
  secrets: !entry.untrustedUrl,
440
440
  environment: this.environment,
441
- ...(entry.config.http.cache ? { cache: scopedCache(this.cache(), `tw:http:${entry.config.id}:`) } : {}),
441
+ ...(entry.config.http.cache ? { cache: scopedCache(this.cache(), `${product()}:http:${entry.config.id}:`) } : {}),
442
442
  });
443
443
  entry.secret = opened.secret;
444
444
  entry.warning = opened.warning;
445
445
  adapter = opened.adapter;
446
446
  }
447
447
  else {
448
+ /* Before any secret is looked for: a mysql:// address has no password worth resolving, and "no password
449
+ found" said first hid the refusal that is the actual answer. connect() says it again for a reference
450
+ that only resolves to one. */
451
+ if (/^(mysql|mariadb):\/\//i.test(entry.config.url))
452
+ throw new Error(MYSQL_REFUSAL);
448
453
  resolved = await resolveConnection(entry.config.name, entry.config.url, {
449
454
  secrets: !entry.untrustedUrl,
450
455
  environment: this.environment,
@@ -16,7 +16,7 @@ import { DatabaseSync } from 'node:sqlite';
16
16
  import { mkdirSync, mkdtempSync, rmSync } from 'node:fs';
17
17
  import { dirname, join } from 'node:path';
18
18
  import { tmpdir } from 'node:os';
19
- import { productEnv } from './product.js';
19
+ import { product, productEnv } from './product.js';
20
20
  const SCHEMA = `
21
21
  CREATE TABLE country (
22
22
  code TEXT PRIMARY KEY,
@@ -134,7 +134,7 @@ INSERT INTO shipment (id, invoice_id, line_no, shipped_on) VALUES
134
134
  (3,1002,1,'2025-07-04'),(4,1004,1,'2026-01-10'),(5,1004,2,NULL);
135
135
  `;
136
136
  /**
137
- * Where `--demo` builds its database. A fixed `$TMPDIR/tablewalk-demo.db` was
137
+ * Where `--demo` builds its database. A fixed `$TMPDIR/<product>-demo.db` was
138
138
  * a machine-global path that every boot deletes and rebuilds, so two people —
139
139
  * or two test runs, or a run beside a demo someone left open — silently
140
140
  * corrupted each other. Observed as twelve browser failures that looked
@@ -152,7 +152,7 @@ export function demoDatabaseFile() {
152
152
  return named;
153
153
  if (chosen)
154
154
  return chosen;
155
- const directory = mkdtempSync(join(tmpdir(), 'tablewalk-demo-'));
155
+ const directory = mkdtempSync(join(tmpdir(), `${product()}-demo-`));
156
156
  // The demo is disposable by definition: nothing here outlives the process
157
157
  // that built it, and leaving a directory per run in $TMPDIR would be litter.
158
158
  process.on('exit', () => {
@@ -117,12 +117,12 @@ export declare const PUBLIC_FORM_SUBMIT_TOTAL: readonly RateWindow[];
117
117
  export declare const PUBLIC_FORM_READ_WINDOWS: readonly RateWindow[];
118
118
  export declare const INVITATION_CLAIM_WINDOWS: readonly RateWindow[];
119
119
  export declare const INVITATION_CLAIM_TOTAL: readonly RateWindow[];
120
- export declare function publicFormLimiter(kind: 'submit' | 'read' | 'start' | 'status' | 'link' | 'code' | 'check'): FixedWindowLimiter | SharedWindowLimiter;
120
+ export declare function publicFormLimiter(kind: 'submit' | 'read' | 'start' | 'status' | 'link' | 'code' | 'check' | 'file'): FixedWindowLimiter | SharedWindowLimiter;
121
121
  /** The invitation claims' own budget (tenantInvitationHttp.ts), never the forms'. */
122
122
  export declare function invitationClaimLimiter(): FixedWindowLimiter | SharedWindowLimiter;
123
123
  /**
124
124
  * Count the public forms' windows in the deployment's cache, under the
125
- * deployment's namespace (`tw:<app>:form:`), or — with no cache, or the
125
+ * deployment's namespace (`mistri:<app>:form:`, in the running product's name), or — with no cache, or the
126
126
  * process's own — in this process, as before.
127
127
  */
128
128
  export declare function configurePublicFormLimits(cache: CacheStore | undefined, namespace: string): void;
@@ -1,5 +1,6 @@
1
1
  import { CacheUnavailable, scopedCache } from '../../adapters/cache/cacheStore.js';
2
2
  import { forwardedClient, ipv6Groups } from './trust.js';
3
+ import { product } from '../product.js';
3
4
  const MAX_CLIENTS = 10_000;
4
5
  function assertWindows(windows) {
5
6
  if (!windows.length || windows.some((w) => !Number.isSafeInteger(w.limit) || w.limit < 1 || !Number.isFinite(w.ms) || w.ms <= 0)) {
@@ -285,7 +286,16 @@ const CODE_TOTAL = Object.freeze([{ limit: 300, ms: 3_600_000 }]);
285
286
  client, and never counted against what that client may submit. */
286
287
  const CHECK_WINDOWS = Object.freeze([{ limit: 60, ms: 60_000 }]);
287
288
  const CHECK_TOTAL = Object.freeze([{ limit: 6_000, ms: 60_000 }]);
289
+ /* A file sent to be held for a public form's command (stagedFiles.ts): a person attaches a few, so twenty a minute
290
+ and sixty an hour from one client; and few enough from every visitor together that the form's files cannot be made
291
+ a place to keep things. */
292
+ const FILE_WINDOWS = Object.freeze([
293
+ { limit: 20, ms: 60_000 },
294
+ { limit: 60, ms: 3_600_000 },
295
+ ]);
296
+ const FILE_TOTAL = Object.freeze([{ limit: 1_200, ms: 3_600_000 }]);
288
297
  const check = new FixedWindowLimiter(CHECK_WINDOWS, Date.now, { total: CHECK_TOTAL, whenFull: 'evict' });
298
+ const file = new FixedWindowLimiter(FILE_WINDOWS, Date.now, { total: FILE_TOTAL, whenFull: 'refuse' });
289
299
  const submit = new FixedWindowLimiter(PUBLIC_FORM_SUBMIT_WINDOWS, Date.now, { total: PUBLIC_FORM_SUBMIT_TOTAL, whenFull: 'refuse' });
290
300
  const read = new FixedWindowLimiter(PUBLIC_FORM_READ_WINDOWS, Date.now, { whenFull: 'evict' });
291
301
  const claim = new FixedWindowLimiter(INVITATION_CLAIM_WINDOWS, Date.now, { total: INVITATION_CLAIM_TOTAL, whenFull: 'refuse' });
@@ -299,6 +309,8 @@ export function publicFormLimiter(kind) {
299
309
  return shared[kind];
300
310
  if (kind === 'check')
301
311
  return check;
312
+ if (kind === 'file')
313
+ return file;
302
314
  return kind === 'submit'
303
315
  ? submit
304
316
  : kind === 'read'
@@ -317,7 +329,7 @@ export function invitationClaimLimiter() {
317
329
  }
318
330
  /**
319
331
  * Count the public forms' windows in the deployment's cache, under the
320
- * deployment's namespace (`tw:<app>:form:`), or — with no cache, or the
332
+ * deployment's namespace (`mistri:<app>:form:`, in the running product's name), or — with no cache, or the
321
333
  * process's own — in this process, as before.
322
334
  */
323
335
  export function configurePublicFormLimits(cache, namespace) {
@@ -325,7 +337,7 @@ export function configurePublicFormLimits(cache, namespace) {
325
337
  shared = undefined;
326
338
  return;
327
339
  }
328
- const scoped = scopedCache(cache, `tw:${namespace}:form:`);
340
+ const scoped = scopedCache(cache, `${product()}:${namespace}:form:`);
329
341
  shared = {
330
342
  submit: new SharedWindowLimiter('submit', PUBLIC_FORM_SUBMIT_WINDOWS, scoped, submit, PUBLIC_FORM_SUBMIT_TOTAL),
331
343
  read: new SharedWindowLimiter('read', PUBLIC_FORM_READ_WINDOWS, scoped, read),
@@ -336,6 +348,7 @@ export function configurePublicFormLimits(cache, namespace) {
336
348
  link: new SharedWindowLimiter('link', LINK_WINDOWS, scoped, link, LINK_TOTAL),
337
349
  code: new SharedWindowLimiter('code', CODE_WINDOWS, scoped, code, CODE_TOTAL),
338
350
  check: new SharedWindowLimiter('check', CHECK_WINDOWS, scoped, check, CHECK_TOTAL),
351
+ file: new SharedWindowLimiter('file', FILE_WINDOWS, scoped, file, FILE_TOTAL),
339
352
  };
340
353
  }
341
354
  /** Forgets the forms' budgets and the claims'; tests and a policy reload use it. */
@@ -348,4 +361,5 @@ export function resetPublicFormLimits() {
348
361
  link.reset();
349
362
  code.reset();
350
363
  check.reset();
364
+ file.reset();
351
365
  }
@@ -136,7 +136,7 @@ async function scratch(url, devUrl) {
136
136
  if (devUrl !== undefined && dialectOf(devUrl) !== dialect)
137
137
  throw new Error(`--dev-url must be the same kind of database as the connection (${dialect}).`);
138
138
  if (dialect === 'sqlite') {
139
- const dir = mkdtempSync(join(tmpdir(), 'tablewalk-schema-'));
139
+ const dir = mkdtempSync(join(tmpdir(), `${product()}-schema-`));
140
140
  return {
141
141
  built: join(dir, 'built.db'),
142
142
  dev: 'sqlite://dev?mode=memory',
@@ -144,7 +144,7 @@ async function scratch(url, devUrl) {
144
144
  };
145
145
  }
146
146
  const server = devUrl ?? url;
147
- const stem = `tablewalk_schema_${process.pid}_${randomBytes(3).toString('hex')}`;
147
+ const stem = `${product()}_schema_${process.pid}_${randomBytes(3).toString('hex')}`;
148
148
  const names = [`${stem}_built`, `${stem}_dev`];
149
149
  const admin = await openMigrationDb(server, [], false);
150
150
  const at = (name) => {
@@ -8,8 +8,14 @@
8
8
  * Only the variables both binaries read go through here. A variable one product alone reads names itself.
9
9
  */
10
10
  type ProductName = 'tablewalk' | 'mistri';
11
- /** Say which product this process is. A main calls it first. */
12
- export declare function setProduct(name: ProductName): void;
11
+ /**
12
+ * Say which product this process is. A main calls it first. A host product that runs the engine from npm passes
13
+ * its own version too: `--version`, MCP's serverInfo and telemetry (`packageVersion`) then report it, where the
14
+ * engine's number is the framework's and moves on its own schedule. Left out, they report the engine's.
15
+ */
16
+ export declare function setProduct(name: ProductName, version?: string): void;
17
+ /** The version the host said it is, if it said one (`setProduct`). */
18
+ export declare const productVersion: () => string | undefined;
13
19
  export declare const product: () => ProductName;
14
20
  /** The config file a project keeps beside it: `mistri.json` for an App, `tablewalk.json` for the browser. */
15
21
  export declare const configFileName: () => string;
@@ -1,8 +1,16 @@
1
1
  let current = 'mistri';
2
- /** Say which product this process is. A main calls it first. */
3
- export function setProduct(name) {
2
+ let hostVersion;
3
+ /**
4
+ * Say which product this process is. A main calls it first. A host product that runs the engine from npm passes
5
+ * its own version too: `--version`, MCP's serverInfo and telemetry (`packageVersion`) then report it, where the
6
+ * engine's number is the framework's and moves on its own schedule. Left out, they report the engine's.
7
+ */
8
+ export function setProduct(name, version) {
4
9
  current = name;
10
+ hostVersion = version;
5
11
  }
12
+ /** The version the host said it is, if it said one (`setProduct`). */
13
+ export const productVersion = () => hostVersion;
6
14
  export const product = () => current;
7
15
  /** The config file a project keeps beside it: `mistri.json` for an App, `tablewalk.json` for the browser. */
8
16
  export const configFileName = () => `${current}.json`;
@@ -89,4 +89,4 @@ export const RESET_WITHOUT_MAIL_WARNING = 'password reset is offered (MISTRI_AUT
89
89
  'the link is never written to the log outside `mistri dev`. Name an email service in the config file, or unset MISTRI_AUTH_RESET.';
90
90
  /** A fetch-style host that names no client: every visitor is one address to the sign-in and form rate limits. */
91
91
  export const SHARED_RATE_LIMIT_WARNING = 'the fetch handler was called without a clientAddress, so every visitor shares one sign-in rate limit and lockout. ' +
92
- "Pass the visitor's address as the second argument: tw.fetch(request, { clientAddress }).";
92
+ "Pass the visitor's address as the second argument: mistri.fetch(request, { clientAddress }).";
@@ -12,6 +12,7 @@ export const ICON_WEIGHT_GLYPHS = {
12
12
  'calendar-blank': [["M208,34H182V24a6,6,0,0,0-12,0V34H86V24a6,6,0,0,0-12,0V34H48A14,14,0,0,0,34,48V208a14,14,0,0,0,14,14H208a14,14,0,0,0,14-14V48A14,14,0,0,0,208,34ZM48,46H74V56a6,6,0,0,0,12,0V46h84V56a6,6,0,0,0,12,0V46h26a2,2,0,0,1,2,2V82H46V48A2,2,0,0,1,48,46ZM208,210H48a2,2,0,0,1-2-2V94H210V208A2,2,0,0,1,208,210Z"], ["M208,32H184V24a8,8,0,0,0-16,0v8H88V24a8,8,0,0,0-16,0v8H48A16,16,0,0,0,32,48V208a16,16,0,0,0,16,16H208a16,16,0,0,0,16-16V48A16,16,0,0,0,208,32Zm0,48H48V48H72v8a8,8,0,0,0,16,0V48h80v8a8,8,0,0,0,16,0V48h24Z"]],
13
13
  'bell': [["M220.07,176.94C214.41,167.2,206,139.73,206,104a78,78,0,1,0-156,0c0,35.74-8.42,63.2-14.08,72.94A14,14,0,0,0,48,198H90.48a38,38,0,0,0,75,0H208a14,14,0,0,0,12.06-21.06ZM128,218a26,26,0,0,1-25.29-20h50.58A26,26,0,0,1,128,218Zm81.71-33a1.9,1.9,0,0,1-1.7,1H48a1.9,1.9,0,0,1-1.7-1,2,2,0,0,1,0-2C53.87,170,62,139.69,62,104a66,66,0,1,1,132,0c0,35.68,8.14,65.95,15.71,79A2,2,0,0,1,209.71,185Z"], ["M221.8,175.94C216.25,166.38,208,139.33,208,104a80,80,0,1,0-160,0c0,35.34-8.26,62.38-13.81,71.94A16,16,0,0,0,48,200H88.81a40,40,0,0,0,78.38,0H208a16,16,0,0,0,13.8-24.06ZM128,216a24,24,0,0,1-22.62-16h45.24A24,24,0,0,1,128,216Z"]],
14
14
  'check-circle': [["M172.24,99.76a6,6,0,0,1,0,8.48l-56,56a6,6,0,0,1-8.48,0l-24-24a6,6,0,0,1,8.48-8.48L112,151.51l51.76-51.75A6,6,0,0,1,172.24,99.76ZM230,128A102,102,0,1,1,128,26,102.12,102.12,0,0,1,230,128Zm-12,0a90,90,0,1,0-90,90A90.1,90.1,0,0,0,218,128Z"], ["M128,24A104,104,0,1,0,232,128,104.11,104.11,0,0,0,128,24Zm45.66,85.66-56,56a8,8,0,0,1-11.32,0l-24-24a8,8,0,0,1,11.32-11.32L112,148.69l50.34-50.35a8,8,0,0,1,11.32,11.32Z"]],
15
+ 'copy': [["M216,34H88a6,6,0,0,0-6,6V82H40a6,6,0,0,0-6,6V216a6,6,0,0,0,6,6H168a6,6,0,0,0,6-6V174h42a6,6,0,0,0,6-6V40A6,6,0,0,0,216,34ZM162,210H46V94H162Zm48-48H174V88a6,6,0,0,0-6-6H94V46H210Z"], ["M216,32H88a8,8,0,0,0-8,8V80H40a8,8,0,0,0-8,8V216a8,8,0,0,0,8,8H168a8,8,0,0,0,8-8V176h40a8,8,0,0,0,8-8V40A8,8,0,0,0,216,32Zm-8,128H176V88a8,8,0,0,0-8-8H96V48H208Z"]],
15
16
  'gear': [["M128,82a46,46,0,1,0,46,46A46.06,46.06,0,0,0,128,82Zm0,80a34,34,0,1,1,34-34A34,34,0,0,1,128,162ZM214,130.84c.06-1.89.06-3.79,0-5.68L229.33,106a6,6,0,0,0,1.11-5.29A105.34,105.34,0,0,0,219.76,74.9a6,6,0,0,0-4.53-3l-24.45-2.71q-1.93-2.07-4-4l-2.72-24.46a6,6,0,0,0-3-4.53,105.65,105.65,0,0,0-25.77-10.66A6,6,0,0,0,150,26.68l-19.2,15.37c-1.89-.06-3.79-.06-5.68,0L106,26.67a6,6,0,0,0-5.29-1.11A105.34,105.34,0,0,0,74.9,36.24a6,6,0,0,0-3,4.53L69.23,65.22q-2.07,1.94-4,4L40.76,72a6,6,0,0,0-4.53,3,105.65,105.65,0,0,0-10.66,25.77A6,6,0,0,0,26.68,106l15.37,19.2c-.06,1.89-.06,3.79,0,5.68L26.67,150.05a6,6,0,0,0-1.11,5.29A105.34,105.34,0,0,0,36.24,181.1a6,6,0,0,0,4.53,3l24.45,2.71q1.94,2.07,4,4L72,215.24a6,6,0,0,0,3,4.53,105.65,105.65,0,0,0,25.77,10.66,6,6,0,0,0,5.29-1.11L125.16,214c1.89.06,3.79.06,5.68,0l19.21,15.38a6,6,0,0,0,3.75,1.31,6.2,6.2,0,0,0,1.54-.2,105.34,105.34,0,0,0,25.76-10.68,6,6,0,0,0,3-4.53l2.71-24.45q2.07-1.93,4-4l24.46-2.72a6,6,0,0,0,4.53-3,105.49,105.49,0,0,0,10.66-25.77,6,6,0,0,0-1.11-5.29Zm-3.1,41.63-23.64,2.63a6,6,0,0,0-3.82,2,75.14,75.14,0,0,1-6.31,6.31,6,6,0,0,0-2,3.82l-2.63,23.63A94.28,94.28,0,0,1,155.14,218l-18.57-14.86a6,6,0,0,0-3.75-1.31h-.36a78.07,78.07,0,0,1-8.92,0,6,6,0,0,0-4.11,1.3L100.87,218a94.13,94.13,0,0,1-17.34-7.17L80.9,187.21a6,6,0,0,0-2-3.82,75.14,75.14,0,0,1-6.31-6.31,6,6,0,0,0-3.82-2l-23.63-2.63A94.28,94.28,0,0,1,38,155.14l14.86-18.57a6,6,0,0,0,1.3-4.11,78.07,78.07,0,0,1,0-8.92,6,6,0,0,0-1.3-4.11L38,100.87a94.13,94.13,0,0,1,7.17-17.34L68.79,80.9a6,6,0,0,0,3.82-2,75.14,75.14,0,0,1,6.31-6.31,6,6,0,0,0,2-3.82l2.63-23.63A94.28,94.28,0,0,1,100.86,38l18.57,14.86a6,6,0,0,0,4.11,1.3,78.07,78.07,0,0,1,8.92,0,6,6,0,0,0,4.11-1.3L155.13,38a94.13,94.13,0,0,1,17.34,7.17l2.63,23.64a6,6,0,0,0,2,3.82,75.14,75.14,0,0,1,6.31,6.31,6,6,0,0,0,3.82,2l23.63,2.63A94.28,94.28,0,0,1,218,100.86l-14.86,18.57a6,6,0,0,0-1.3,4.11,78.07,78.07,0,0,1,0,8.92,6,6,0,0,0,1.3,4.11L218,155.13A94.13,94.13,0,0,1,210.85,172.47Z"], ["M216,130.16q.06-2.16,0-4.32l14.92-18.64a8,8,0,0,0,1.48-7.06,107.6,107.6,0,0,0-10.88-26.25,8,8,0,0,0-6-3.93l-23.72-2.64q-1.48-1.56-3-3L186,40.54a8,8,0,0,0-3.94-6,107.29,107.29,0,0,0-26.25-10.86,8,8,0,0,0-7.06,1.48L130.16,40Q128,40,125.84,40L107.2,25.11a8,8,0,0,0-7.06-1.48A107.6,107.6,0,0,0,73.89,34.51a8,8,0,0,0-3.93,6L67.32,64.27q-1.56,1.49-3,3L40.54,70a8,8,0,0,0-6,3.94,107.71,107.71,0,0,0-10.87,26.25,8,8,0,0,0,1.49,7.06L40,125.84Q40,128,40,130.16L25.11,148.8a8,8,0,0,0-1.48,7.06,107.6,107.6,0,0,0,10.88,26.25,8,8,0,0,0,6,3.93l23.72,2.64q1.49,1.56,3,3L70,215.46a8,8,0,0,0,3.94,6,107.71,107.71,0,0,0,26.25,10.87,8,8,0,0,0,7.06-1.49L125.84,216q2.16.06,4.32,0l18.64,14.92a8,8,0,0,0,7.06,1.48,107.21,107.21,0,0,0,26.25-10.88,8,8,0,0,0,3.93-6l2.64-23.72q1.56-1.48,3-3L215.46,186a8,8,0,0,0,6-3.94,107.71,107.71,0,0,0,10.87-26.25,8,8,0,0,0-1.49-7.06ZM128,168a40,40,0,1,1,40-40A40,40,0,0,1,128,168Z"]],
16
17
  'list': [["M222,128a6,6,0,0,1-6,6H40a6,6,0,0,1,0-12H216A6,6,0,0,1,222,128ZM40,70H216a6,6,0,0,0,0-12H40a6,6,0,0,0,0,12ZM216,186H40a6,6,0,0,0,0,12H216a6,6,0,0,0,0-12Z"], ["M208,32H48A16,16,0,0,0,32,48V208a16,16,0,0,0,16,16H208a16,16,0,0,0,16-16V48A16,16,0,0,0,208,32ZM192,184H64a8,8,0,0,1,0-16H192a8,8,0,0,1,0,16Zm0-48H64a8,8,0,0,1,0-16H192a8,8,0,0,1,0,16Zm0-48H64a8,8,0,0,1,0-16H192a8,8,0,0,1,0,16Z"]],
17
18
  'lock': [["M208,82H174V56a46,46,0,0,0-92,0V82H48A14,14,0,0,0,34,96V208a14,14,0,0,0,14,14H208a14,14,0,0,0,14-14V96A14,14,0,0,0,208,82ZM94,56a34,34,0,0,1,68,0V82H94ZM210,208a2,2,0,0,1-2,2H48a2,2,0,0,1-2-2V96a2,2,0,0,1,2-2H208a2,2,0,0,1,2,2Zm-72-56a10,10,0,1,1-10-10A10,10,0,0,1,138,152Z"], ["M208,80H176V56a48,48,0,0,0-96,0V80H48A16,16,0,0,0,32,96V208a16,16,0,0,0,16,16H208a16,16,0,0,0,16-16V96A16,16,0,0,0,208,80Zm-80,84a12,12,0,1,1,12-12A12,12,0,0,1,128,164Zm32-84H96V56a32,32,0,0,1,64,0Z"]],
@@ -124,13 +124,17 @@ export interface AppBoardFact {
124
124
  icon?: AppIconName;
125
125
  }
126
126
  /** A month of records by one date column, each on its day — or, with `end`, across the days from one date
127
- column to another; a phone reads it as an agenda. */
127
+ column to another; a phone reads it as an agenda. With a `span` of a week or a day, a time grid: the hours down
128
+ the side, a record placed by its start and end. */
128
129
  export interface AppCalendarList {
129
130
  kind: 'calendar';
130
131
  /** The date (or timestamp) column a record sits on, or starts on when it has an `end`. */
131
132
  date: string;
132
- /** A local date column holding a record's last day: the record is drawn across every day between. */
133
+ /** A local date column holding a record's last day: the record is drawn across every day between. In a week or a
134
+ day, a timestamp column holding the record's end, so it is drawn from its start to it. */
133
135
  end?: string;
136
+ /** What one page of the calendar shows: a week or a day as a time grid, read by timestamp columns. Absent, a month. */
137
+ span?: Exclude<CalendarSpan, 'month'>;
134
138
  /** A local text column or one-hop reference label path. */
135
139
  primary: string;
136
140
  /** At most one local column or one-hop label path beneath the primary. */
@@ -153,6 +157,9 @@ export interface AppCalendarBackdrop {
153
157
  /** The span's shade, in a display tone; absent, the quiet neutral. */
154
158
  tone?: (typeof DISPLAY_TONES)[number];
155
159
  }
160
+ /** What one page of a calendar shows: a month of days, or a week or a day of hours. */
161
+ export declare const CALENDAR_SPANS: readonly ['month', 'week', 'day'];
162
+ export type CalendarSpan = (typeof CALENDAR_SPANS)[number];
156
163
  /** How many kinds of span one calendar shades. */
157
164
  export declare const CALENDAR_BACKDROPS_MAX = 4;
158
165
  /** Records as the tree their parent column makes: a root per record with no parent, its children folded under it. */
@@ -1,4 +1,6 @@
1
1
  import { DISPLAY_TONES } from './model.js';
2
+ /** What one page of a calendar shows: a month of days, or a week or a day of hours. */
3
+ export const CALENDAR_SPANS = ['month', 'week', 'day'];
2
4
  /** How many kinds of span one calendar shades. */
3
5
  export const CALENDAR_BACKDROPS_MAX = 4;
4
6
  /** 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. */
@@ -28,6 +28,8 @@ export interface ListQuestionSpec {
28
28
  editable?: true | string[];
29
29
  /** The reference column whose record a row opens (a view's `opens`): fetched, as the row's key is, to open it. */
30
30
  opens?: string;
31
+ /** The column a grid's rows are grouped by (a view's `group`): fetched, shown or not, as each row's head is read from it. */
32
+ group?: string;
31
33
  }
32
34
  /**
33
35
  * The references among a list's columns, each with the path its record's
@@ -48,6 +50,13 @@ export declare function listReferenceNames(rules: ListRules, spec: Pick<ListQues
48
50
  export declare function showClause(rules: ListRules, spec: ListQuestionSpec): string;
49
51
  export declare const limitClause: (spec: Pick<ListQuestionSpec, 'limit'>) => string;
50
52
  export declare const orderClause: (spec: Pick<ListQuestionSpec, 'order' | 'sort'>) => string;
53
+ /**
54
+ * A grouped list's question as its rows are read: ordered by the group's column before anything else, so each
55
+ * group's rows stand together under its head, and then as the list or its reader sorts them. A sort the reader gave
56
+ * the group's column keeps its direction, at the front. Said only to the read (TableRoom.tsx, firstPaintRooms.ts):
57
+ * the bar, the address and the tab a list lights stay the reader's own question.
58
+ */
59
+ export declare function groupedQuestion(question: string, column: string): string;
51
60
  export declare function withOrder(spec: Pick<ListQuestionSpec, 'table' | 'order' | 'sort'>, question: string): string;
52
61
  /** The full query text one of the app's tabs stands for. A module's
53
62
  standing conditions come first; a tab refines on top of them. */
@@ -112,6 +112,7 @@ export function showClause(rules, spec) {
112
112
  ...subtitleColumns(rules, spec.table, names),
113
113
  ...editedReferences(rules, spec),
114
114
  ...(spec.opens ? [spec.opens] : []),
115
+ ...(spec.group ? [spec.group] : []),
115
116
  ...primaryKey(t),
116
117
  ]),
117
118
  ].join(', ')}`;
@@ -124,6 +125,23 @@ export const limitClause = (spec) => (spec.limit ? `limit ${spec.limit}` : '');
124
125
  folded out of what the bar shows. A view's default `sort` is the same
125
126
  reading, said in the query bar's words. */
126
127
  export const orderClause = (spec) => spec.order ? `sort ${spec.order}` : spec.sort ? `sort ${spec.sort}` : '';
128
+ /**
129
+ * A grouped list's question as its rows are read: ordered by the group's column before anything else, so each
130
+ * group's rows stand together under its head, and then as the list or its reader sorts them. A sort the reader gave
131
+ * the group's column keeps its direction, at the front. Said only to the read (TableRoom.tsx, firstPaintRooms.ts):
132
+ * the bar, the address and the tab a list lights stay the reader's own question.
133
+ */
134
+ export function groupedQuestion(question, column) {
135
+ const parts = splitQuery(question);
136
+ const fields = (parts.sort ?? '')
137
+ .replace(/^(?:sort|order\s+by)\s+/i, '')
138
+ .split(',')
139
+ .map((field) => field.trim())
140
+ .filter(Boolean);
141
+ const own = fields.find((field) => field.split(/\s+/)[0] === column);
142
+ const sort = `sort ${[own ?? column, ...fields.filter((field) => field !== own)].join(', ')}`;
143
+ return [parts.table, parts.filter, parts.show, sort, parts.limit].filter((part) => part && part.trim()).join(' ');
144
+ }
127
145
  export function withOrder(spec, question) {
128
146
  const order = orderClause(spec);
129
147
  return order && !splitQuery(`${spec.table} ${question}`).sort ? squeeze(`${question} ${order}`) : question;
@@ -2,7 +2,7 @@ import { type DatabaseSchema } from './schema.js';
2
2
  import { type BreakdownDef, type BreakdownKey } from './breakdown.js';
3
3
  import type { AuthoredPage, AuthoredSection } from '../../schema/model.js';
4
4
  import { type PageCustomTotal } from './appComponents.js';
5
- import { type PageBreakdown, type PageChart, type PageSection, type PageTimeline, type PageDef } from './pageModel.js';
5
+ import { type PageBreakdown, type PageChart, type PageSection, type PageTimeline, type TimelineStream, type TimelineReactions, type PageDef } from './pageModel.js';
6
6
  import { type OfKeys } from './pagePaths.js';
7
7
  export { type SectionWidth, WIDTHS, type SectionOffset, OFFSETS, type SectionRegion, SECTION_REGIONS, FIELD_COLUMNS, type ResolvedWorkflowStatus, type PageFields, type PageMetric, type PageList, type PageBreakdown, type PageChart, type TimelineStream, type PageTimeline, type PageSection, type PageDef, timelineMarkColumns, DEFAULT_PAGE_LIST_LIMIT, MAX_PAGE_SECTIONS, } from './pageModel.js';
8
8
  export { resolvePath, rootFilter, resolveOf, type OfKeys, listView, sectionQuery, metricView, defaultColumns, customReadView, } from './pagePaths.js';
@@ -16,6 +16,13 @@ export { parsePagesConfig, PAGE_KEYS, PAGE_SECTION_KEYS, STREAM_KEYS, parsePageB
16
16
  * always describe some connection someone is not on.
17
17
  */
18
18
  export declare function validatePage(schema: DatabaseSchema, page: PageDef): PageDef;
19
+ /**
20
+ * The column of a stream's table a timeline's reactions name its entries by — the column `whose` refers to — or
21
+ * undefined where the stream's rows are not what the reactions are to. Read on a validated page, whose `whose` is named.
22
+ */
23
+ export declare function reactedColumn(schema: DatabaseSchema, section: Pick<PageTimeline, 'reactions'>, stream: Pick<TimelineStream, 'from'>): string | undefined;
24
+ /** The table a timeline's reactions are to: the one `whose` refers to, on a validated page. */
25
+ export declare function reactionEntryTable(schema: DatabaseSchema, reactions: Pick<TimelineReactions, 'from' | 'whose'>): string | undefined;
19
26
  /**
20
27
  * Which rows of each timeline stream are the other party's: the condition each stream is asked, with `record.` reached
21
28
  * by the stream's way back to the record, or undefined for a stream that has no far side. A stream's own `side` is its
@@ -28,7 +28,7 @@
28
28
  import { ANYONE, saidAt } from './query.js';
29
29
  import { listEmptyConfig } from './listEmpty.js';
30
30
  import { withDefaultAside } from './pageAnatomy.js';
31
- import { columnKind, columnOrRollup, findTable, primaryKey, looksLikeDate, rowName, referencesTo, tableNamed, } from './schema.js';
31
+ import { columnKind, columnOrRollup, findTable, primaryKey, looksLikeDate, rowName, referencesTo, referencesFrom, tableNamed, } from './schema.js';
32
32
  import { tryResolvePath } from './viewPaths.js';
33
33
  import { hopName, parseViewQuery, validateView } from './view.js';
34
34
  import { DATE_UNITS } from './breakdown.js';
@@ -134,6 +134,7 @@ function validated(schema, page) {
134
134
  if (error)
135
135
  return { ...page, error: `document: "number": ${error}` };
136
136
  }
137
+ const reactions = new Map();
137
138
  for (const [i, section] of page.sections.entries()) {
138
139
  const at = section.title ? `"${section.title}"` : `section ${i + 1}`;
139
140
  /* A note reads nothing. Nor does a history (the record's own writes), a flows section (the runs are the record's
@@ -257,6 +258,14 @@ function validated(schema, page) {
257
258
  const sides = timelineSides(schema, section);
258
259
  if (sides.error)
259
260
  return { ...page, error: `${at}${sides.error}` };
261
+ /* Reactions name their columns, or have the one candidate each: the page is served with them named, so the
262
+ browser reads and the check refuses the same three. */
263
+ if (section.reactions) {
264
+ const reacted = timelineReactions(schema, section);
265
+ if ('error' in reacted)
266
+ return { ...page, error: `${at}: ${reacted.error}` };
267
+ reactions.set(i, reacted.reactions);
268
+ }
260
269
  continue;
261
270
  }
262
271
  /* A custom section's reads are judged as the lists they are planned
@@ -377,7 +386,112 @@ function validated(schema, page) {
377
386
  }
378
387
  }
379
388
  }
380
- return { ...page, error: undefined };
389
+ if (!reactions.size)
390
+ return { ...page, error: undefined };
391
+ return {
392
+ ...page,
393
+ sections: page.sections.map((section, i) => section.kind === 'timeline' && reactions.has(i) ? { ...section, reactions: reactions.get(i) } : section),
394
+ error: undefined,
395
+ };
396
+ }
397
+ /**
398
+ * A timeline's reactions with their three columns named: `whose`, the column of `from` that refers to an entry of one
399
+ * of the streams; `by`, the one that refers to the table people are rows of (`person`, an App's `auth.me`), read as
400
+ * `<by> = me`; `column`, the text column the kinds are values of. Each one the author left out is the one candidate
401
+ * `from` has, and two or none is refused with the key to add. A kind the column's database constraint does not allow
402
+ * is refused by name.
403
+ */
404
+ function timelineReactions(schema, section) {
405
+ const r = section.reactions;
406
+ const from = findTable(schema, r.from);
407
+ if (!from)
408
+ return { error: `"reactions" reads "${r.from}", which is not a table here.` };
409
+ const entries = new Set(section.streams.map((stream) => findTable(schema, stream.from)?.id).filter(Boolean));
410
+ const listed = (columns) => columns.map((c) => `"${c.name}"`).join(', ');
411
+ const choose = (key, candidates, what) => {
412
+ if (candidates.length === 1)
413
+ return candidates[0];
414
+ return {
415
+ error: candidates.length
416
+ ? `"reactions" names no "${key}", and ${listed(candidates)} could each be ${what}. Add "${key}": the one that is.`
417
+ : `"reactions" names no "${key}", and no column of ${from.name} is ${what}. Add "${key}": the column that is.`,
418
+ };
419
+ };
420
+ const refs = singleReferences(schema, from.id);
421
+ const refersTo = (tables) => (c) => tables.has(findTable(schema, refs.get(c.name)?.table ?? '')?.id);
422
+ const column = (key, name) => {
423
+ const found = from.columns.find((c) => c.name === name);
424
+ return found ?? { error: `reactions.${key} names "${name}", which is not a column on ${from.name}.` };
425
+ };
426
+ const whose = r.whose
427
+ ? column('whose', r.whose)
428
+ : choose('whose', from.columns.filter(refersTo(entries)), `the entry a reaction is to (a reference to ${[...entries].join(' or ')})`);
429
+ if ('error' in whose)
430
+ return whose;
431
+ if (r.whose && !refersTo(entries)(whose))
432
+ return {
433
+ error: `reactions.whose names "${r.whose}", which does not refer to an entry of this timeline (${[...entries].join(' or ')}).`,
434
+ };
435
+ /* A press runs the command on the entry the reaction names, by the column `whose` refers to as its key: a reference
436
+ to another unique column (a post's slug) would hand the command a value that is not the entry's key. */
437
+ const target = refs.get(whose.name);
438
+ const entry = findTable(schema, target.table);
439
+ const entryKey = primaryKey(entry);
440
+ if (entryKey.length !== 1 || entryKey[0] !== target.column)
441
+ return {
442
+ error: `reactions.whose "${whose.name}" refers to ${entry.name}.${target.column}, which is not ${entry.name}'s primary key` +
443
+ `${entryKey.length ? ` (${entryKey.join(', ')})` : ''}; a reaction is pressed on its entry by that key, so "whose" must refer to it.`,
444
+ };
445
+ const person = r.person === undefined ? undefined : findTable(schema, r.person)?.id;
446
+ if (!r.by && !person)
447
+ return {
448
+ error: `"reactions" names no "by", and the App does not say which table people are rows of (auth.me). Add "by": the column of ${from.name} that holds who reacted.`,
449
+ };
450
+ const by = r.by
451
+ ? column('by', r.by)
452
+ : choose('by', from.columns.filter((c) => c.name !== whose.name && refersTo(new Set([person]))(c)), `who reacted (a reference to ${person})`);
453
+ if ('error' in by)
454
+ return by;
455
+ if (by.name === whose.name)
456
+ return { error: `reactions.by and reactions.whose both name "${by.name}"; a reaction is someone's, to something.` };
457
+ const kinds = (c) => !c.allowed || r.kinds.every((kind) => c.allowed.includes(kind));
458
+ const kind = r.column
459
+ ? column('column', r.column)
460
+ : choose('column', from.columns.filter((c) => !c.primaryKey && !refs.has(c.name) && c.name !== whose.name && c.name !== by.name && columnKind(c.type) === 'text' && kinds(c)), `the kind of a reaction (a text column holding ${r.kinds.map((k) => `"${k}"`).join(', ')})`);
461
+ if ('error' in kind)
462
+ return kind;
463
+ if (kind.name === whose.name || kind.name === by.name)
464
+ return { error: `reactions.column names "${kind.name}", which is already "${kind.name === whose.name ? 'whose' : 'by'}".` };
465
+ const allowed = kind.allowed;
466
+ const stray = allowed && r.kinds.find((each) => !allowed.includes(each));
467
+ if (stray)
468
+ return { error: `reactions.kinds names "${stray}", which ${from.name}.${kind.name} does not allow (${allowed.join(', ')}).` };
469
+ return { reactions: { ...r, whose: whose.name, by: by.name, column: kind.name } };
470
+ }
471
+ /**
472
+ * The column of a stream's table a timeline's reactions name its entries by — the column `whose` refers to — or
473
+ * undefined where the stream's rows are not what the reactions are to. Read on a validated page, whose `whose` is named.
474
+ */
475
+ export function reactedColumn(schema, section, stream) {
476
+ const r = section.reactions;
477
+ if (!r?.whose)
478
+ return undefined;
479
+ const from = findTable(schema, r.from);
480
+ const ref = from && singleReferences(schema, from.id).get(r.whose);
481
+ const table = findTable(schema, stream.from);
482
+ return ref && table && findTable(schema, ref.table)?.id === table.id ? ref.column : undefined;
483
+ }
484
+ /** The table a timeline's reactions are to: the one `whose` refers to, on a validated page. */
485
+ export function reactionEntryTable(schema, reactions) {
486
+ const from = findTable(schema, reactions.from);
487
+ const ref = from && reactions.whose ? singleReferences(schema, from.id).get(reactions.whose) : undefined;
488
+ return ref && findTable(schema, ref.table)?.id;
489
+ }
490
+ /* A table's one-column references by the column that holds each: the only kind a reaction's entry or person can be. */
491
+ function singleReferences(schema, tableId) {
492
+ return new Map(referencesFrom(schema, tableId)
493
+ .filter((fk) => fk.from.columns.length === 1)
494
+ .map((fk) => [fk.from.columns[0], { table: fk.to.table, column: fk.to.columns[0] }]));
381
495
  }
382
496
  /**
383
497
  * Which rows of each timeline stream are the other party's: the condition each stream is asked, with `record.` reached
@@ -765,6 +879,18 @@ export function sectionConfig(s) {
765
879
  ...(s.tone ? { tone: s.tone } : {}),
766
880
  ...(s.compact ? { compact: s.compact } : {}),
767
881
  ...(s.side ? { side: s.side } : {}),
882
+ ...(s.reactions
883
+ ? {
884
+ reactions: {
885
+ from: s.reactions.from,
886
+ kinds: s.reactions.kinds,
887
+ command: s.reactions.command,
888
+ ...(s.reactions.whose ? { whose: s.reactions.whose } : {}),
889
+ ...(s.reactions.by ? { by: s.reactions.by } : {}),
890
+ ...(s.reactions.column ? { column: s.reactions.column } : {}),
891
+ },
892
+ }
893
+ : {}),
768
894
  };
769
895
  case 'metric':
770
896
  return {
@@ -91,7 +91,7 @@ export const PAGE_SECTION_KEYS = {
91
91
  header: ['kind', 'status', 'facts', 'primary', 'destructive', 'actions'],
92
92
  /* The one current related row as a card: nothing to page, sum or add under it. */
93
93
  current: ['kind', 'title', 'region', 'tab', 'width', 'when', 'from', 'whose', 'show', 'query', 'sort', 'empty'],
94
- timeline: [...SECTION_COMMON, 'streams', 'limit', 'create', 'newest', 'composer', 'tone', 'compact', 'side'],
94
+ timeline: [...SECTION_COMMON, 'streams', 'limit', 'create', 'newest', 'composer', 'tone', 'compact', 'side', 'reactions'],
95
95
  history: [...SECTION_COMMON, 'limit'],
96
96
  flows: [...SECTION_COMMON],
97
97
  diagram: [...SECTION_COMMON],
@@ -526,6 +526,7 @@ function parseSection(entry, at, config) {
526
526
  throw new Error(`${at} has a "side" that is not a condition like "author_id = record.caller_id".`);
527
527
  }
528
528
  const side = typeof s.side === 'string' ? s.side.trim() : undefined;
529
+ const reactions = s.reactions === undefined ? undefined : parseTimelineReactions(s.reactions, at);
529
530
  if (composer && s.create !== undefined) {
530
531
  throw new Error(`${at} has both "composer" and "create": a conversation's composer is the commands' (reply, note), and "create" is the form's. Keep one.`);
531
532
  }
@@ -544,6 +545,7 @@ function parseSection(entry, at, config) {
544
545
  ...(tone ? { tone } : {}),
545
546
  ...(compact ? { compact } : {}),
546
547
  ...(side ? { side } : {}),
548
+ ...(reactions ? { reactions } : {}),
547
549
  ...(s.create === undefined ? {} : { create: parseRelatedCreate(s.create, at) }),
548
550
  ...(when ? { when } : {}),
549
551
  };
@@ -1076,6 +1078,41 @@ function parseTimelineComposer(raw, at) {
1076
1078
  const templates = c.templates === undefined ? undefined : parseComposerTemplates(c.templates, at);
1077
1079
  return { reply, ...(note === undefined ? {} : { note }), ...(templates ? { templates } : {}) };
1078
1080
  }
1081
+ /* Reactions under each entry: the table that holds them, the kinds offered, and the command that gives or takes one
1082
+ back. Its columns are judged against the catalog with the rest of the section (page.ts timelineReactions). */
1083
+ function parseTimelineReactions(raw, at) {
1084
+ if (!raw || typeof raw !== 'object' || Array.isArray(raw))
1085
+ throw new Error(`${at} has "reactions" that is not { from, kinds, command, whose?, by?, column? }: the table reactions are rows of, the kinds offered, and the command that toggles one.`);
1086
+ const r = raw;
1087
+ allowKeys(r, ['from', 'kinds', 'command', 'whose', 'by', 'column'], `${at}, reactions`);
1088
+ for (const key of ['from', 'command']) {
1089
+ if (typeof r[key] !== 'string' || !r[key].trim())
1090
+ throw new Error(`${at}: reactions needs "${key}", ${key === 'from' ? 'the table whose rows are the reactions' : "the name of the App's command that gives a reaction or takes it back"}.`);
1091
+ }
1092
+ for (const key of ['whose', 'by', 'column']) {
1093
+ if (r[key] !== undefined && (typeof r[key] !== 'string' || !r[key].trim()))
1094
+ throw new Error(`${at}: reactions.${key} is not a column's name.`);
1095
+ }
1096
+ const kinds = r.kinds;
1097
+ if (!Array.isArray(kinds) || !kinds.length || kinds.some((kind) => typeof kind !== 'string' || !kind.trim()))
1098
+ throw new Error(`${at}: reactions needs "kinds", the values a reaction may be, in the order they are drawn: ['like', 'thanks'].`);
1099
+ const trimmed = kinds.map((kind) => kind.trim());
1100
+ const twice = trimmed.find((kind, i) => trimmed.indexOf(kind) !== i);
1101
+ if (twice !== undefined)
1102
+ throw new Error(`${at}: reactions.kinds names "${twice}" twice.`);
1103
+ if (trimmed.length > MAX_REACTION_KINDS)
1104
+ throw new Error(`${at}: reactions.kinds names ${trimmed.length} kinds; a row of reactions holds at most ${MAX_REACTION_KINDS}.`);
1105
+ return {
1106
+ from: r.from.trim(),
1107
+ kinds: trimmed,
1108
+ command: r.command.trim(),
1109
+ ...(typeof r.whose === 'string' ? { whose: r.whose.trim() } : {}),
1110
+ ...(typeof r.by === 'string' ? { by: r.by.trim() } : {}),
1111
+ ...(typeof r.column === 'string' ? { column: r.column.trim() } : {}),
1112
+ };
1113
+ }
1114
+ /* A row of reactions under an entry stays one quiet line: more kinds than this is a survey, not a reaction. */
1115
+ const MAX_REACTION_KINDS = 8;
1079
1116
  /* Canned replies: the rows of a resource, each a label to pick and the text it puts in the box. */
1080
1117
  function parseComposerTemplates(raw, at) {
1081
1118
  if (!raw || typeof raw !== 'object' || Array.isArray(raw))
@@ -476,6 +476,9 @@ export interface PageTimeline {
476
476
  `record.<column>` is the page's record — `author_id = record.caller_id`. A stream whose table lacks a column it
477
477
  names is never on the far side; a stream's own `side` replaces it (timelineSides, page.ts). */
478
478
  side?: string;
479
+ /** Reactions under each entry: the rows of `from` that name it, counted by kind, the reader's own pressed, and the
480
+ App's command run to give or take one back (timelineReactions, page.ts). */
481
+ reactions?: TimelineReactions;
479
482
  width?: SectionWidth;
480
483
  offsetLeft?: SectionOffset;
481
484
  offsetRight?: SectionOffset;
@@ -484,6 +487,23 @@ export interface PageTimeline {
484
487
  language: "status = converted". Judged against the base table. */
485
488
  when?: string;
486
489
  }
490
+ /**
491
+ * A timeline's reactions: rows of `from`, one per person per kind per entry. `whose` names the entry, `by` the person
492
+ * (read as `<by> = me`), `column` the kind; each is inferred where `from` has exactly one candidate and named
493
+ * otherwise (page.ts timelineReactions). `command` is the App's own, offered by an action of the entry's resource and
494
+ * handed the kind as its `<column>` input: it gives a reaction or takes it back, under the reader's grants.
495
+ */
496
+ export interface TimelineReactions {
497
+ from: string;
498
+ /** The kinds offered, in the order they are drawn; each a value of `column`, said through its display rule. */
499
+ kinds: string[];
500
+ command: string;
501
+ whose?: string;
502
+ by?: string;
503
+ column?: string;
504
+ /** The table people are rows of (an App's `auth.me`), set as the App loads: `by` is inferred among its references. */
505
+ person?: string;
506
+ }
487
507
  /** The tones a timeline row may be tinted: the display tones' words. */
488
508
  export type TimelineTone = 'good' | 'warn' | 'bad' | 'info' | 'neutral';
489
509
  /** The commands a conversation's composer runs: a Reply and, beside it, an Internal note. Each is offered to the reader by an action of the page's resource. */
@@ -26,6 +26,8 @@ type HttpPagePlan = {
26
26
  by?: string;
27
27
  /** With a `side`: the stream's key columns, and the same read narrowed to the other party's rows. */
28
28
  key?: string[];
29
+ /** The column the section's reactions name this stream's rows by (page.ts reactedColumn), read with them. */
30
+ reacts?: string;
29
31
  side?: ReturnType<typeof listView>;
30
32
  } & ReturnType<typeof listView>>;
31
33
  } | {
@@ -1,5 +1,5 @@
1
1
  /** Section planning only: callers own page validation, root lookup and access. */
2
- import { breakdownPlan, chartPlan, customReadView, customTotalPlan, listView, metricView, sectionQuery, timelineMarkColumns, timelineSides, } from './page.js';
2
+ import { breakdownPlan, chartPlan, customReadView, customTotalPlan, listView, metricView, reactedColumn, sectionQuery, timelineMarkColumns, timelineSides, } from './page.js';
3
3
  import { groupsView, totalsView } from './pagePaths.js';
4
4
  import { sectionReading } from './pageModel.js';
5
5
  import { findTable, primaryKey } from './schema.js';
@@ -38,12 +38,13 @@ export function planPageSections(schema, page, key, ofKeys, now = new Date(), ro
38
38
  const side = sides[s];
39
39
  const table = side === undefined ? undefined : findTable(schema, stream.from);
40
40
  const keyColumns = table ? primaryKey(table) : [];
41
+ const reacts = reactedColumn(schema, section, stream);
41
42
  const asList = {
42
43
  kind: 'list',
43
44
  from: stream.from,
44
45
  path: stream.path,
45
46
  columns: [
46
- ...new Set([stream.at, stream.show, stream.detail, stream.by, ...streamMarks(stream), ...keyColumns].filter((c) => Boolean(c))),
47
+ ...new Set([stream.at, stream.show, stream.detail, stream.by, ...streamMarks(stream), ...keyColumns, reacts].filter((c) => Boolean(c))),
47
48
  ],
48
49
  filter: stream.filter,
49
50
  orderBy: [{ column: stream.at, direction: 'desc' }],
@@ -64,6 +65,7 @@ export function planPageSections(schema, page, key, ofKeys, now = new Date(), ro
64
65
  empty: built.empty,
65
66
  error: built.error,
66
67
  ...(others ? { key: keyColumns, side: others } : {}),
68
+ ...(reacts ? { reacts } : {}),
67
69
  };
68
70
  }),
69
71
  };
@@ -244,7 +244,7 @@ export interface AppDisplayRule {
244
244
  links a column named like one (`email`, `phone`, `website`) without a rule. richText: the value is
245
245
  sanitized HTML (shared/richText.ts), drawn formatted on a record, as an excerpt in a list, edited in the
246
246
  rich text editor; every write of the column is sanitized on the server, and Markdown is read into it. */
247
- format?: 'money' | 'percent' | 'number' | 'relative' | 'date' | 'datetime' | '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' | 'address';
248
248
  /** The face this column's values are set in, over the look's own: `data` (the look's data face, usually
249
249
  monospace), `sans` (the interface's reading face) or `code` (always monospace, for a VIN or a hash):
250
250
  `display: { vin: { face: 'code' } }`. Left out, an App sets a key, a reference, a code or a QR value in the
@@ -271,6 +271,8 @@ export interface AppDisplayRule {
271
271
  table: string;
272
272
  key: string;
273
273
  };
274
+ /** A copy button beside the value on a record: the stored value copied, a toast saying so. */
275
+ copy?: true;
274
276
  /** Value → one of the theme's chart colors, 1 to 8: a category's own color — a board card's chip and stripe, a
275
277
  chip in a cell — kept apart from `tone`, which says meaning. A value it does not name takes a color of its
276
278
  own, fixed by its words. */
@@ -416,6 +418,8 @@ export interface AppFormField<Field extends string = string> {
416
418
  as?: 'cards' | 'buttons' | 'radios' | 'select';
417
419
  /** The referenced table's column → this form's field whose value it must equal. */
418
420
  where?: Record<string, Field>;
421
+ /** The referenced table's column naming each record's parent: the picker draws the hierarchy it makes. */
422
+ tree?: string;
419
423
  }
420
424
  /** A resource's tags resolved against the catalog: the link table, its reference back to the record and out to the tag, and how a tag is named. */
421
425
  export interface AppTagRule extends Omit<AppTagsDef, 'toneOf'> {
@@ -895,7 +895,7 @@ function parseAggregates(raw, at, name) {
895
895
  if (typeof a.via !== 'string' || !a.via.trim())
896
896
  throw new Error(`${where} has no "via".`);
897
897
  if (a.fn !== 'count' && (typeof a.column !== 'string' || !a.column.trim())) {
898
- throw new Error(`${where} is a ${a.fn} and needs a "column" to summarise.`);
898
+ throw new Error(`${where} is a ${a.fn} and needs a "column" to summarize.`);
899
899
  }
900
900
  if (a.on !== undefined && typeof a.on !== 'string') {
901
901
  throw new Error(`${where} has an "on" that is not a string.`);
@@ -255,7 +255,7 @@ export function resolveAggregate(schema, baseId, aggregate) {
255
255
  let column;
256
256
  if (aggregate.fn !== 'count') {
257
257
  if (!aggregate.column) {
258
- fail(`${aggregate.fn} needs a column on ${child.name} to summarise.`, aggregate.via);
258
+ fail(`${aggregate.fn} needs a column on ${child.name} to summarize.`, aggregate.via);
259
259
  }
260
260
  column = child.columns.find((c) => c.name === aggregate.column);
261
261
  if (!column) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mistriwork/engine",
3
- "version": "1.0.0-rc.13",
3
+ "version": "1.0.0-rc.15",
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": {
package/schema/model.d.ts CHANGED
@@ -105,8 +105,9 @@ export interface CommandValueBase {
105
105
  input?: string;
106
106
  }
107
107
  /** How a field is drawn: a slider (a bounded number or amount), cards (one or several, with icons), two buttons (a
108
- yes or a no; a choice's few), a select, or radios. */
109
- export type CommandFieldPresentation = 'slider' | 'cards' | 'buttons' | 'select' | 'radios';
108
+ yes or a no; a choice's few), a select, or radios; a number as stars (`'rating'`), a text as a code the camera
109
+ reads (`'scan'`) or as a color with the system's picker (`'color'`). */
110
+ export type CommandFieldPresentation = 'slider' | 'cards' | 'buttons' | 'select' | 'radios' | 'rating' | 'scan' | 'color';
110
111
  /** What a sensitive text keeps once its own rules have read the whole value: its last four characters, a keyed hash
111
112
  (HMAC under the form key), nothing at all, or — for the handler alone, once, in memory — the whole value
112
113
  (`'handler'`); whatever it keeps, the journal, the audit, events, flags, logs and the idempotency fingerprint
@@ -155,7 +156,8 @@ export type AppCommandField = (CommandValueBase & (
155
156
  (`'000-00-0000'`). The value is what the mask's places hold (`123456789`), and the mask is its pattern. */
156
157
  mask?: string; sensitive?: CommandSensitive }
157
158
  | { type: 'richText'; minLength?: number; maxLength?: number; mentions?: CommandRichTextMentions; images?: string }
158
- | { type: 'number'; min?: number; max?: number; integer?: boolean; step?: number; below?: string; above?: string; live?: CommandLiveLines }
159
+ /** `outOf`: with `as: 'rating'`, the stars of its scale; the field is then a whole number from 1 to it. */
160
+ | { type: 'number'; min?: number; max?: number; integer?: boolean; step?: number; below?: string; above?: string; live?: CommandLiveLines; outOf?: number }
159
161
  /** An amount of money in the App's currency (`ui.currency`), from 0 unless `min` says less, on cents unless `step` says otherwise. */
160
162
  | { type: 'money'; min?: number; max?: number; step?: number; minor?: boolean; currency?: string; below?: string; above?: string; live?: CommandLiveLines }
161
163
  /** `statement`: the long words a consent box stands beside (at most 2,000 characters), drawn as one paragraph. */
@@ -164,12 +166,19 @@ export type AppCommandField = (CommandValueBase & (
164
166
  /** A month, `YYYY-MM`: `min` and `max` are months too. */
165
167
  | { type: 'month'; min?: string; max?: string; below?: string; above?: string }
166
168
  | { type: 'datetime'; min?: string; max?: string; below?: string; above?: string }
169
+ /** A time of day, `HH:MM` on a 24-hour clock: `min` and `max` are times too. */
170
+ | { type: 'time'; min?: string; max?: string; below?: string; above?: string }
167
171
  /** One of the options; or, with `source`, one of a table's rows by its key (the options then come from the table). */
168
172
  | { type: 'choice'; options: readonly AppCommandChoice[]; source?: CommandChoiceSource }
169
173
  /** Several of the options: from `min` to `max` of them, and an `exclusive` option (`'none'`) stands alone. */
170
174
  | { type: 'choices'; options: readonly AppCommandChoice[]; source?: CommandChoiceSource; min?: number; max?: number; exclusive?: readonly (string | number)[] }
171
- | { type: 'reference'; from: string; by: string; labelColumn: string; query?: string }
175
+ | { type: 'reference'; from: string; by: string; labelColumn: string; query?: string; tree?: string }
172
176
  | { type: 'defined'; from: string; whose?: string }
177
+ /** Files of the file resource `from`, from `min` (1 unless said) to `max`; `accept` the media types taken
178
+ (`image/*`). Each is sent as it is picked and held for the command; the value is the held files' ids. */
179
+ | { type: 'files'; from: string; min?: number; max: number; accept?: readonly string[] }
180
+ /** A signature drawn on a pad, held as a PNG of the file resource `from`; the value is the held file's id. */
181
+ | { type: 'signature'; from: string }
173
182
  )) | AppCommandGroup | AppCommandLines;
174
183
 
175
184
  /**
@@ -288,7 +297,7 @@ export interface AppCommandAction<Target extends string = string, Label extends
288
297
  /** A resource action as the App serves it. */
289
298
  export type AppAction<Target extends string = string, Label extends string | AppMessageRef = string> = AppUpdateAction<Label> | AppCommandAction<Target, Label>;
290
299
 
291
- /** The authored spelling of a page and its sections — the plain data a pages/ file and tablewalk.json hold — as the
300
+ /** The authored spelling of a page and its sections — the plain data a pages/ file and the config file (mistri.json) hold — as the
292
301
  page rules write it back (packages/engine/src/shared/page.ts `sectionConfig`, `pageConfig`). The App framework's types say what it
293
302
  is: packages/mistri/schema/app.d.ts fills these shapes in with `Plain<PageSection>` and `Plain<AppPage>`, so a rule that writes a
294
303
  section the authored types refuse does not compile, while the engine names none of the App's authoring types.
package/schema/theme.d.ts CHANGED
@@ -567,7 +567,7 @@ interface ThemeSpecCommon {
567
567
  * the theme is worn (theme-css).
568
568
  */
569
569
  stylesheet?: `./${string}.css`;
570
- /** The theme contract it was written to. A package says `1`; a newer one than this tablewalk knows is refused. */
570
+ /** The theme contract it was written to. A package says `1`; a newer one than this mistri knows is refused. */
571
571
  contract?: 1;
572
572
  /** Where its files are read from: a package's `import.meta.url`. Omitted, the App's directory. */
573
573
  from?: string;