@mistriwork/engine 1.0.0-rc.17 → 1.0.0-rc.18

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 (63) hide show
  1. package/dist/adapters/adapter.d.ts +35 -2
  2. package/dist/adapters/adapter.js +32 -1
  3. package/dist/adapters/postgres.js +8 -4
  4. package/dist/adapters/scoped/scopedReads.js +23 -5
  5. package/dist/adapters/scoped/sqliteTriggers.js +65 -38
  6. package/dist/adapters/sqlite.js +8 -4
  7. package/dist/server/columnGrants.d.ts +5 -0
  8. package/dist/server/connections.d.ts +1 -0
  9. package/dist/server/connections.js +13 -3
  10. package/dist/server/http/firstPaint.d.ts +5 -1
  11. package/dist/server/http/firstPaint.js +4 -4
  12. package/dist/server/httpConnection.d.ts +4 -2
  13. package/dist/server/httpConnection.js +10 -3
  14. package/dist/server/journalStore.d.ts +2 -2
  15. package/dist/server/journalStore.js +33 -10
  16. package/dist/server/resourceReadHttp.d.ts +4 -2
  17. package/dist/server/resourceReadHttp.js +40 -4
  18. package/dist/server/resourceReadOperations.d.ts +4 -0
  19. package/dist/server/scaffoldMachine.js +12 -1
  20. package/dist/shared/boardLanes.d.ts +44 -0
  21. package/dist/shared/boardLanes.js +69 -0
  22. package/dist/shared/builtInThemes.js +26 -20
  23. package/dist/shared/dashboardAsks.d.ts +2 -0
  24. package/dist/shared/filter.d.ts +2 -0
  25. package/dist/shared/filter.js +3 -2
  26. package/dist/shared/form.d.ts +24 -1
  27. package/dist/shared/form.js +53 -0
  28. package/dist/shared/keysetPage.js +3 -0
  29. package/dist/shared/listInference.d.ts +91 -0
  30. package/dist/shared/listInference.js +323 -0
  31. package/dist/shared/listPresentations.d.ts +3 -0
  32. package/dist/shared/listQuestion.d.ts +2 -0
  33. package/dist/shared/listQuestion.js +1 -0
  34. package/dist/shared/pageAnatomy.d.ts +27 -3
  35. package/dist/shared/pageAnatomy.js +217 -36
  36. package/dist/shared/pageModel.d.ts +17 -1
  37. package/dist/shared/pageModel.js +8 -0
  38. package/dist/shared/query.d.ts +2 -0
  39. package/dist/shared/query.js +11 -3
  40. package/dist/shared/reads.d.ts +9 -0
  41. package/dist/shared/reads.js +9 -0
  42. package/dist/shared/recordLabel.d.ts +5 -0
  43. package/dist/shared/recordLabel.js +22 -2
  44. package/dist/shared/recordReads.d.ts +30 -0
  45. package/dist/shared/recordReads.js +72 -8
  46. package/dist/shared/referenceSubline.d.ts +18 -0
  47. package/dist/shared/referenceSubline.js +62 -0
  48. package/dist/shared/resourceHttp.d.ts +5 -0
  49. package/dist/shared/rowScope.js +52 -6
  50. package/dist/shared/schema.d.ts +2 -0
  51. package/dist/shared/servedApp.d.ts +18 -0
  52. package/dist/shared/servedApp.js +10 -0
  53. package/dist/shared/themeLooks.js +61 -35
  54. package/dist/shared/themeRecipeWords.d.ts +5 -0
  55. package/dist/shared/themeRecipeWords.js +6 -1
  56. package/dist/shared/themeRecipes.d.ts +5 -0
  57. package/dist/shared/themeRecipes.js +3 -0
  58. package/dist/shared/themeType.js +2 -1
  59. package/dist/shared/view.js +29 -2
  60. package/dist/shared/viewLabels.js +16 -0
  61. package/dist/shared/viewPaths.d.ts +9 -0
  62. package/package.json +4 -1
  63. package/schema/theme.d.ts +8 -4
@@ -28,9 +28,11 @@ export interface HttpConnectionConfig {
28
28
  * An entry's HTTP fields, checked: the resolved block for an `http`
29
29
  * connection, undefined for a database. Throws naming the field, because a
30
30
  * config someone wrote is refused rather than half-read. Service kinds
31
- * (`cache`, `webhook`, …) are read by serviceConnections.ts before this is asked.
31
+ * (`cache`, `webhook`, …) are read by serviceConnections.ts before this is asked;
32
+ * `kinds` are the ones the reader's sections know, so an unknown kind is answered
33
+ * with the list this reader takes rather than one written down once and outgrown.
32
34
  */
33
- export declare function httpConnectionOf(entry: Record<string, unknown>, path: string): HttpConnectionConfig | undefined;
35
+ export declare function httpConnectionOf(entry: Record<string, unknown>, path: string, kinds?: readonly string[]): HttpConnectionConfig | undefined;
34
36
  /**
35
37
  * Open an HTTP connection: read its description, resolve its credential and
36
38
  * hand both to the adapter. `secrets: false` — a URL a browser supplied —
@@ -23,6 +23,11 @@ import { HttpAdapter } from '../adapters/http/httpAdapter.js';
23
23
  import { readDescription } from '../adapters/http/httpDescription.js';
24
24
  import { expandEnvReferences } from './auth/credentials.js';
25
25
  import { product } from './product.js';
26
+ /** `"a", "b" and "c"`. */
27
+ const listed = (words) => {
28
+ const quoted = words.map((word) => JSON.stringify(word));
29
+ return quoted.length < 2 ? quoted.join('') : `${quoted.slice(0, -1).join(', ')} and ${quoted.at(-1)}`;
30
+ };
26
31
  const HTTP_ONLY = ['description', 'auth', 'insecure', 'allowLinkLocal', 'cache'];
27
32
  /* RFC 9110's token, minus the headers the request itself owns. */
28
33
  const HEADER_NAME = /^[A-Za-z0-9!#$%&'*+.^_`|~-]+$/;
@@ -33,9 +38,11 @@ const MAX_CACHE_TTL_SECONDS = 86_400;
33
38
  * An entry's HTTP fields, checked: the resolved block for an `http`
34
39
  * connection, undefined for a database. Throws naming the field, because a
35
40
  * config someone wrote is refused rather than half-read. Service kinds
36
- * (`cache`, `webhook`, …) are read by serviceConnections.ts before this is asked.
41
+ * (`cache`, `webhook`, …) are read by serviceConnections.ts before this is asked;
42
+ * `kinds` are the ones the reader's sections know, so an unknown kind is answered
43
+ * with the list this reader takes rather than one written down once and outgrown.
37
44
  */
38
- export function httpConnectionOf(entry, path) {
45
+ export function httpConnectionOf(entry, path, kinds = ['cache']) {
39
46
  const where = `${path}: connection "${String(entry.name)}"`;
40
47
  if (entry.kind === undefined) {
41
48
  const stray = HTTP_ONLY.find((key) => entry[key] !== undefined);
@@ -48,7 +55,7 @@ export function httpConnectionOf(entry, path) {
48
55
  throw new Error(`${where} has "kind": "search". Search providers are not part of ${product()}: they are packs (Typesense is @mistriwork/search-typesense, SQLite FTS5 is @mistriwork/search-sqlite, Postgres tsvector is @mistriwork/search-postgres), which ship after 1.0. Remove the entry, and a text filter runs on the database.`);
49
56
  }
50
57
  if (entry.kind !== 'http') {
51
- throw new Error(`${where} has "kind": ${JSON.stringify(entry.kind)}. The kinds are "http", "cache" and "webhook"; a database needs none.`);
58
+ throw new Error(`${where} has "kind": ${JSON.stringify(entry.kind)}. The kinds are ${listed(['http', ...[...kinds].sort()])}; a database needs none.`);
52
59
  }
53
60
  // Writes to an API arrive with their own slice; until then a flag saying otherwise would be a promise nothing keeps.
54
61
  if (entry.writable === true)
@@ -30,8 +30,8 @@ export declare function provisionPostgresWriteJournal(url: string): Promise<{
30
30
  /**
31
31
  * Keep `connection`'s journal in its database when the database holds the
32
32
  * store: what it held is read back, and every write from here on is kept
33
- * there too. Never fatal: a store that cannot be read leaves the journal in
34
- * memory, said through `warn`. Resolves to whether the store is now used.
33
+ * there too. Never fatal: a store that is missing or cannot be read leaves the
34
+ * journal in memory, said through `warn` (the caller says it once). Resolves to whether the store is now used.
35
35
  */
36
36
  export declare function keepWriteJournal(connection: string, adapter: Adapter, warn?: (message: string) => void): Promise<boolean>;
37
37
  export {};
@@ -8,8 +8,12 @@
8
8
  * or the provisioning functions here for a host that has no App framework),
9
9
  * never by opening a connection. A writable connection whose database holds
10
10
  * this build's layout keeps its journal there; one that holds none keeps it in
11
- * memory, as before, and one that holds another layout keeps it in memory and
12
- * says why once.
11
+ * memory, as before, and in the database browser says so once, naming the
12
+ * step that provisions it (a journal that silently outlasts nothing is a
13
+ * promise the docs make and the run does not keep). An App says nothing of it:
14
+ * Undo is the Workbench's, an App offers none, so the notice would be an
15
+ * operator chore with nothing to gain, and `mistri check` read it as the App's
16
+ * failure. One that holds another layout keeps it in memory and says why once.
13
17
  *
14
18
  * It sits in the business database, beside the rows it describes, under the
15
19
  * reserved prefix: the catalog never lists it, and a copy of the database
@@ -32,6 +36,7 @@ import { withPostgresMaintenanceTransaction } from '../adapters/postgresMaintena
32
36
  import { storeHostOf, writeViewOf } from '../adapters/storeHost.js';
33
37
  import { runtimeName, runtimeSchema, runtimeTable } from '../shared/runtimeTables.js';
34
38
  import { attachJournalStore } from './journal.js';
39
+ import { product } from './product.js';
35
40
  const WRITE_JOURNAL_VERSION = 1;
36
41
  /** The reserved prefix of its tables (`mistri.undo_*` on PostgreSQL). */
37
42
  const WRITE_JOURNAL_PREFIX = '__mistri_undo_';
@@ -305,11 +310,14 @@ function postgresStore(host) {
305
310
  }),
306
311
  };
307
312
  }
313
+ /** A database that can hold the store and holds none of it: the journal stays in memory, and the operator is told. */
314
+ const NOT_PROVISIONED = 'not-provisioned';
308
315
  /**
309
- * The store an adapter's database holds, or undefined where it holds none of
310
- * it (the journal then stays in memory). An adapter a wrapper narrowed is
311
- * looked through to the one it wraps. Throws WriteJournalUnavailable for a
312
- * layout that is not this build's.
316
+ * The store an adapter's database holds; NOT_PROVISIONED where the database
317
+ * could hold it and holds none (the journal then stays in memory); undefined
318
+ * where the adapter has no database to hold one (an HTTP source). An adapter a
319
+ * wrapper narrowed is looked through to the one it wraps. Throws
320
+ * WriteJournalUnavailable for a layout that is not this build's.
313
321
  */
314
322
  async function writeJournalStoreOf(adapter) {
315
323
  const host = storeHostOf(adapter) ?? storeHostOf(writeViewOf(adapter)?.over);
@@ -318,28 +326,43 @@ async function writeJournalStoreOf(adapter) {
318
326
  if (host.dialect === 'sqlite') {
319
327
  const db = host.reader();
320
328
  if (!sqliteCatalog(db).length)
321
- return undefined;
329
+ return NOT_PROVISIONED;
322
330
  if (!sqliteWriteJournalReady(db))
323
331
  throw new WriteJournalUnavailable(layoutRefusal('The write journal store', sqliteLayoutVersion(db, META), WRITE_JOURNAL_VERSION));
324
332
  return sqliteStore(host);
325
333
  }
326
334
  return host.withReadClient(async (client) => {
327
335
  if (!(await pgRelations(client)).count)
328
- return undefined;
336
+ return NOT_PROVISIONED;
329
337
  if (!(await postgresWriteJournalReady(client)))
330
338
  throw new WriteJournalUnavailable(layoutRefusal('The write journal store', await postgresLayoutVersion(client, pgMeta), WRITE_JOURNAL_VERSION));
331
339
  return postgresStore(host);
332
340
  });
333
341
  }
342
+ /** What an operator needs when a writable connection's database holds no store: what is lost, and the one step that provisions it. */
343
+ function unprovisioned(connection, adapter) {
344
+ const host = storeHostOf(adapter) ?? storeHostOf(writeViewOf(adapter)?.over);
345
+ const target = host?.dialect === 'postgres' ? "postgres: '<the connection's URL>'" : "sqlite: '<the database file>'";
346
+ return (`"${connection}": Undo history is kept in memory for this run, and a restart forgets it: this database holds no undo-journal store. ` +
347
+ `It is provisioned once, never by opening a connection. With the server stopped, run ` +
348
+ `provisionStores({ ${target} }, { only: ['undo-journal'] }) from @mistriwork/mistri/maintenance ` +
349
+ `(or ${host?.dialect === 'postgres' ? 'provisionPostgresWriteJournal' : 'provisionSqliteWriteJournal'} from @mistriwork/engine/server/journalStore.js), then start again.`);
350
+ }
334
351
  /**
335
352
  * Keep `connection`'s journal in its database when the database holds the
336
353
  * store: what it held is read back, and every write from here on is kept
337
- * there too. Never fatal: a store that cannot be read leaves the journal in
338
- * memory, said through `warn`. Resolves to whether the store is now used.
354
+ * there too. Never fatal: a store that is missing or cannot be read leaves the
355
+ * journal in memory, said through `warn` (the caller says it once). Resolves to whether the store is now used.
339
356
  */
340
357
  export async function keepWriteJournal(connection, adapter, warn = (message) => console.error(message)) {
341
358
  try {
342
359
  const store = await writeJournalStoreOf(adapter);
360
+ if (store === NOT_PROVISIONED) {
361
+ // Only the browser offers Undo (the header says why an App stays quiet).
362
+ if (product() === 'tablewalk')
363
+ warn(unprovisioned(connection, adapter));
364
+ return false;
365
+ }
343
366
  if (!store)
344
367
  return false;
345
368
  await attachJournalStore(connection, store, warn);
@@ -24,7 +24,9 @@ export interface AppReads {
24
24
  * request's reader (app/appMe.ts), or nothing where no text compares with
25
25
  * the person.
26
26
  */
27
- person(me: () => Promise<QueryPerson | null>, texts: readonly unknown[], schema: DatabaseSchema, adapter: Adapter): Promise<{
27
+ person(
28
+ /** Given the texts, a lookup may be skipped where they need only the email (app/appMe.ts emailOnly). */
29
+ me: (texts?: readonly unknown[]) => Promise<QueryPerson | null>, texts: readonly unknown[], schema: DatabaseSchema, adapter: Adapter): Promise<{
28
30
  me?: QueryPerson | null;
29
31
  }>;
30
32
  }
@@ -37,7 +39,7 @@ interface ResourceReadHttpOptions {
37
39
  * asked only when the text says `me` (appMe.ts). Absent — the database
38
40
  * browser, a tenant App — `me` is the word it is.
39
41
  */
40
- me?: () => Promise<QueryPerson | null>;
42
+ me?: (texts?: readonly unknown[]) => Promise<QueryPerson | null>;
41
43
  /**
42
44
  * The ISO weekday an App's weeks start on (its `ui.locale`, weekStart.ts),
43
45
  * set on every breakdown in place of whatever the request said. Absent —
@@ -40,7 +40,21 @@ function plainCount(schema, view) {
40
40
  : {};
41
41
  }
42
42
  /* What a batched list's page may say: what `/api/run` reads of a first page. */
43
- const RUN_FIELDS = ['q', 'limit', 'offset', 'count', 'exactCount', 'countLimit'];
43
+ const RUN_FIELDS = ['q', 'limit', 'offset', 'count', 'exactCount', 'countLimit', 'lanes'];
44
+ /** The most rows a lanes read keeps per lane: a board's page, a few times over. */
45
+ const LANE_MOST = 100;
46
+ /** A run's `lanes`, read: absent, refused, or the column and how many of each. */
47
+ function readLanes(raw) {
48
+ if (raw === undefined)
49
+ return undefined;
50
+ const lanes = raw;
51
+ if (!lanes || typeof lanes !== 'object' || Array.isArray(lanes) || Object.keys(lanes).some((key) => key !== 'by' && key !== 'limit'))
52
+ return 'invalid';
53
+ const { by, limit } = lanes;
54
+ if (typeof by !== 'string' || !by || typeof limit !== 'number' || !Number.isInteger(limit) || limit < 1 || limit > LANE_MOST)
55
+ return 'invalid';
56
+ return { by, limit };
57
+ }
44
58
  /** A dashboard is at most a few dozen sections; a batch past this is not one. */
45
59
  export const BREAKDOWN_BATCH = 48;
46
60
  /* How many of a batch's breakdowns read at once: the PostgreSQL read pool's
@@ -122,6 +136,10 @@ export async function dispatchResourceReadHttp(path, body, adapter, schema, opti
122
136
  if (body.count !== undefined && body.count !== 'none' && body.count !== 'exact' && body.count !== 'estimate') {
123
137
  return refusal(400, ['count must be "none", "exact" or "estimate".']);
124
138
  }
139
+ /* A board's lanes, each its first page, in one statement (adapter.ts lanesStatement): a list of one table, no total. */
140
+ const lanes = readLanes(body.lanes);
141
+ if (lanes === 'invalid')
142
+ return refusal(400, [`lanes is { by: a column, limit: 1 to ${LANE_MOST} }.`]);
125
143
  const text = String(body.q ?? '');
126
144
  const person = await personFor(text);
127
145
  const parsed = parseQuery(text, { schema, now: options.now(), ...person });
@@ -139,6 +157,14 @@ export async function dispatchResourceReadHttp(path, body, adapter, schema, opti
139
157
  const asView = textToView(schema, text, { id: 'bar', name: '', now: options.now(), ...person });
140
158
  if (asView.view && !asView.errors.length) {
141
159
  const base = findTable(schema, asView.view.base);
160
+ /* A list that names a path (`customer_id.name`) is a view, and its lanes are read the same one way. */
161
+ if (lanes) {
162
+ if (!base || base.union || step || !base.columns.some((column) => column.name === lanes.by))
163
+ return refusal(400, [`A board reads its lanes in one read only by a column of ${asView.view.base}'s own rows.`]);
164
+ const most = options.rowsMost?.(asView.view.base);
165
+ const bounded = most === undefined ? body : { ...body, limit: Math.min(clampLimit(body.limit ?? asView.view.limit), most) };
166
+ return runViewForBar(adapter, schema, { ...asView.view, lanes }, bounded, app, 'none');
167
+ }
142
168
  /* A union pages by offset: its rows have no one key order across branches (unionReads.ts). */
143
169
  const paging = base && !base.union ? viewPaging(schema, base, asView.view, step) : undefined;
144
170
  if (step && !paging?.continuation) {
@@ -179,22 +205,32 @@ export async function dispatchResourceReadHttp(path, body, adapter, schema, opti
179
205
  every page of someone else's rate budget: its lists page by whether a
180
206
  full page came back, as a view without a count does. */
181
207
  const exact = body.exactCount === true || body.count === 'exact';
182
- const countMode = schema.dialect === 'http' || body.count === 'none' ? 'none' : exact ? 'exact' : 'estimate';
208
+ const countMode = schema.dialect === 'http' || body.count === 'none' || lanes ? 'none' : exact ? 'exact' : 'estimate';
183
209
  /* A filtered total is counted to DEFAULT_COUNT_LIMIT unless the request
184
210
  asks for the exact number or names its own bound: past it the list says
185
211
  "10,000+" and offers to count exactly. Unfiltered, the catalog's
186
212
  estimate or a plain count answers as before. */
187
213
  const countLimit = body.countLimit ?? (!exact && q.filter?.groups?.length ? DEFAULT_COUNT_LIMIT : undefined);
188
214
  const own = findTable(schema, q.table);
215
+ /* Lanes are a column of one stored table's rows: a union pages its branches apart, an API answers in its own order. */
216
+ if (lanes && (!own || own.union || schema.dialect === 'http' || step || !own.columns.some((column) => column.name === lanes.by))) {
217
+ return refusal(400, [`A board reads its lanes in one read only by a column of ${q.table}'s own rows.`]);
218
+ }
189
219
  const most = options.rowsMost?.(own?.id ?? q.table);
190
220
  const bounded = (limit) => (most === undefined ? limit : Math.min(clampLimit(limit), most));
191
- const paging = own && !own.union ? recordsPaging(own, schema.dialect, q.orderBy, q.columns, q.filter, step) : undefined;
221
+ const paging = own && !own.union && !lanes ? recordsPaging(own, schema.dialect, q.orderBy, q.columns, q.filter, step) : undefined;
192
222
  if (step && !paging?.continuation) {
193
223
  const refused = tooDeep();
194
224
  if (refused)
195
225
  return refused;
196
226
  }
197
- const { result, total, order, request: { limit, offset }, } = await readRecords(adapter, schema, { ...q, ...(paging?.columns ? { columns: paging.columns } : {}), limit: bounded(body.limit ?? q.limit), offset: body.offset }, countMode, countLimit, paging?.continuation);
227
+ const { result, total, order, request: { limit, offset }, } = await readRecords(adapter, schema, {
228
+ ...q,
229
+ ...(paging?.columns ? { columns: paging.columns } : {}),
230
+ ...(lanes ? { lanes } : {}),
231
+ limit: bounded(body.limit ?? q.limit),
232
+ offset: body.offset,
233
+ }, countMode, countLimit, paging?.continuation);
198
234
  const settled = paging ? settlePage(paging.order, paging.extra, result) : undefined;
199
235
  return sendData(path, {
200
236
  table: q.table,
@@ -96,6 +96,10 @@ export declare function readView(reader: ResourceReader, schema: DatabaseSchema,
96
96
  filter?: (import("../shared/viewPaths.js").ViewFilter & StructuredFilter<"path">) | undefined;
97
97
  orderBy?: import("../shared/viewPaths.js").ViewOrder[];
98
98
  limit?: number;
99
+ lanes?: {
100
+ by: string;
101
+ limit: number;
102
+ };
99
103
  text?: string;
100
104
  connection?: string;
101
105
  source?: 'config' | 'saved';
@@ -24,7 +24,9 @@ const said = (value) => value
24
24
  .toLowerCase()
25
25
  .replace(/[\s-]+/g, '_');
26
26
  /* Words that call the work off: the exits. */
27
- const EXIT = /^(cancell?ed|rejected|declined|denied|lost|closed_lost|void|voided|withdrawn|abandoned|failed|expired|refunded|no_show|dismissed|discarded|dropped|disqualified|unqualified|churned|terminated|aborted|wont_fix|duplicate|spam)$/;
27
+ const EXIT = /^(cancell?ed|rejected|declined|denied|lost|closed_lost|void|voided|withdrawn|abandoned|failed|expired|refunded|no_show|noshow|missed|skipped|dismissed|discarded|dropped|disqualified|unqualified|churned|terminated|aborted|wont_fix|duplicate|spam)$/;
28
+ /* Words that say the work is done: the path's end. */
29
+ const DONE = /^(done|complete|completed|finished|resolved|closed|fulfilled|delivered|collected)$/;
28
30
  /* Words that park the work: a side state, left the way it was entered. */
29
31
  const HOLD = /^(on_hold|hold|paused|blocked|stalled|deferred|snoozed|backordered|waiting|waiting_\w+)$/;
30
32
  /* The verb that leads into a state, by the state's word: what a person does to put the record there. */
@@ -99,6 +101,15 @@ export function draftMachine(table, column) {
99
101
  if (states.length < 3 || states.length > 10 || column.flag || !states.every((state) => /^[A-Za-z0-9][A-Za-z0-9_-]*$/.test(state)))
100
102
  return undefined;
101
103
  const exits = states.filter((state, i) => i > 0 && EXIT.test(said(state)));
104
+ /* The work ends where it is done. Past `completed`, only a step this file knows a verb for (invoiced, archived)
105
+ goes on; a word it does not know there is another way the work ended — read as a step, a visit's `missed`
106
+ listed after `completed` became `completed → markMissed`, a way out of a finished visit. */
107
+ const done = states.findIndex((state) => DONE.test(said(state)));
108
+ if (done !== -1)
109
+ for (const state of states.slice(done + 1))
110
+ if (!exits.includes(state) && !HOLD.test(said(state)) && !INTO[said(state)])
111
+ exits.push(state);
112
+ exits.sort((a, b) => states.indexOf(a) - states.indexOf(b));
102
113
  const holdStates = states.filter((state, i) => i > 0 && !exits.includes(state) && HOLD.test(said(state)));
103
114
  const path = states.filter((state) => !exits.includes(state) && !holdStates.includes(state));
104
115
  if (path.length < 2)
@@ -0,0 +1,44 @@
1
+ /** A lane's cards are read this many at a time; "Show more" reads the next. */
2
+ export declare const LANE_PAGE = 20;
3
+ export declare const LANE_COUNT = "lane_cards";
4
+ export declare const LANE_SUM = "lane_amount";
5
+ export declare const LANE_CURRENCY = "lane_currency";
6
+ /** The lane breakdown's question: the list's conditions, without its show, sort or page, counted (and summed) by the lane column. */
7
+ export declare function laneCountsText(query: string | undefined, by: string, amount?: string, currencyBy?: string): string | null;
8
+ /** What the list's read adds to read as a board's lanes: the first page of each lane, one statement, no total. */
9
+ export declare const laneWindow: (by: string) => {
10
+ limit: number;
11
+ count: 'none';
12
+ lanes: {
13
+ by: string;
14
+ limit: number;
15
+ };
16
+ };
17
+ type AmountRule = {
18
+ format?: string;
19
+ currencyColumn?: string;
20
+ };
21
+ /**
22
+ * What a card is worth: the board's `sum`, else the first money its card shows (a line, a fact on its foot), and
23
+ * the column that says each card's currency where it says its own. `rule` is a column's display rule where it
24
+ * says money or a number, else null.
25
+ */
26
+ export declare function boardAmount(spec: {
27
+ sum?: string;
28
+ lines?: readonly string[];
29
+ footer?: ReadonlyArray<{
30
+ column: string;
31
+ }>;
32
+ }, rule: (column: string) => AmountRule | null): {
33
+ amount?: string;
34
+ said?: AmountRule;
35
+ currencyBy?: string;
36
+ };
37
+ /**
38
+ * The lists this browser reads as boards (kit LayoutSwitch.tsx), said to the server too, so a page it opens on one
39
+ * carries the board's reads rather than the list's: the view ids, each encoded, joined by commas.
40
+ */
41
+ export declare const BOARD_COOKIE = "mistri_boards";
42
+ /** The views a request's Cookie header says are read as boards. */
43
+ export declare function boardsInCookie(header: string | undefined): ReadonlySet<string>;
44
+ export {};
@@ -0,0 +1,69 @@
1
+ /**
2
+ * What a board asks to draw its lanes, written once for the browser that asks
3
+ * it (mistri client BoardList.tsx, kit TableRoom.tsx) and the first page that
4
+ * asks it ahead of the browser (mistri server firstPaintRooms.ts): a carried
5
+ * answer is found by its question, so the two must ask in the same words.
6
+ *
7
+ * Two reads: every lane's count (and sum) in one breakdown by the lane
8
+ * column, and every lane's first cards in one read windowed by it
9
+ * (`lanes: { by, limit }`, adapter.ts lanesStatement). A lane's "Show more"
10
+ * reads that lane alone.
11
+ */
12
+ import { currencyPath } from './money.js';
13
+ import { splitQuery } from './clauses.js';
14
+ /** A lane's cards are read this many at a time; "Show more" reads the next. */
15
+ export const LANE_PAGE = 20;
16
+ /** The window over every lane: a page of each of a board's eight lanes and its four final states, at most. */
17
+ const LANE_WINDOW = LANE_PAGE * 12;
18
+ /* The lane breakdown's two measures, and the currency each is summed apart by, by names no column is read by. */
19
+ export const LANE_COUNT = 'lane_cards';
20
+ export const LANE_SUM = 'lane_amount';
21
+ export const LANE_CURRENCY = 'lane_currency';
22
+ /** The lane breakdown's question: the list's conditions, without its show, sort or page, counted (and summed) by the lane column. */
23
+ export function laneCountsText(query, by, amount, currencyBy) {
24
+ const parts = query ? splitQuery(query) : undefined;
25
+ /* With an amount, the same breakdown sums it beside each count, named so neither is read for the other. */
26
+ const measures = amount ? `count as ${LANE_COUNT}, sum ${amount} as ${LANE_SUM}` : 'count';
27
+ const keys = amount && currencyBy ? `${by}, ${currencyBy} as ${LANE_CURRENCY}` : by;
28
+ return parts ? `${parts.table} ${parts.filter ?? ''} ${measures} by ${keys}`.replace(/\s+/g, ' ') : null;
29
+ }
30
+ /** What the list's read adds to read as a board's lanes: the first page of each lane, one statement, no total. */
31
+ export const laneWindow = (by) => ({ limit: LANE_WINDOW, count: 'none', lanes: { by, limit: LANE_PAGE } });
32
+ /**
33
+ * What a card is worth: the board's `sum`, else the first money its card shows (a line, a fact on its foot), and
34
+ * the column that says each card's currency where it says its own. `rule` is a column's display rule where it
35
+ * says money or a number, else null.
36
+ */
37
+ export function boardAmount(spec, rule) {
38
+ const amount = spec.sum ?? [...(spec.lines ?? []), ...(spec.footer ?? []).map((fact) => fact.column)].find((name) => rule(name)?.format === 'money');
39
+ if (!amount)
40
+ return {};
41
+ const said = rule(amount) ?? { format: 'number' };
42
+ const currencyBy = said.format === 'money' ? currencyPath(said, amount) : undefined;
43
+ return { amount, said, ...(currencyBy ? { currencyBy } : {}) };
44
+ }
45
+ /**
46
+ * The lists this browser reads as boards (kit LayoutSwitch.tsx), said to the server too, so a page it opens on one
47
+ * carries the board's reads rather than the list's: the view ids, each encoded, joined by commas.
48
+ */
49
+ export const BOARD_COOKIE = 'mistri_boards';
50
+ /** The views a request's Cookie header says are read as boards. */
51
+ export function boardsInCookie(header) {
52
+ const found = header
53
+ ?.split(';')
54
+ .map((part) => part.trim())
55
+ .find((part) => part.startsWith(`${BOARD_COOKIE}=`));
56
+ if (!found)
57
+ return new Set();
58
+ return new Set(found
59
+ .slice(BOARD_COOKIE.length + 1)
60
+ .split(',')
61
+ .flatMap((each) => {
62
+ try {
63
+ return each ? [decodeURIComponent(each)] : [];
64
+ }
65
+ catch {
66
+ return [];
67
+ }
68
+ }));
69
+ }
@@ -12,8 +12,8 @@ export const THEME_PRESETS = [
12
12
  {
13
13
  "id": "workshop",
14
14
  "label": "Workshop",
15
- "light": p("#f2ede3 #faf8f3 #ece6da #ddd5c6 #8b8274 #7d7466 #1b1813 #4f483d #5f574b #f26a1b #e7dfd0 #aa3600 #c9530b #1b1813 #1b1813 #106b38 #934a06 #c52a2a #2f5578 #ebe5d9 #1b1813 #4f483d #d8cfbe #aa3600 - - #e8691f #2b2620 #9a6cf7 #0e9a6c #0e8fb0 #e0428a #a3510b #94a3b8 #1b1813 #1b1813 2px - #f26a1b #1b1813 #3a3020"),
16
- "dark": p("#15130f #1d1a15 #26221c #2f2a22 #6d6555 #7a7262 #efe9de #c2b9aa #a59c8d #ff7a2e #2c261e #ffb88f #e8742c #15130f #efe9de #4ade80 #fbbf24 #f87171 #91a8ff #110f0c #efe9de #b3aa9b #26221c #ffb88f - - #f07a32 #d9d0c0 #9a78ec #12a678 #1597b9 #e0559b #c88317 #6b7694 #8a8170 #8a8170 2px - #ff7a2e #15130f"),
15
+ "light": p("#fbfaf7 #ffffff #f2ede3 #e6e1d8 #8b8274 #7d7466 #1b1813 #4f483d #5f574b #f26a1b #e7dfd0 #aa3600 #c9530b #1b1813 #1b1813 #106b38 #934a06 #c52a2a #2f5578 #f2ede3 #1b1813 #4f483d #d8cfbe #aa3600 #e3ded4 #1b1813 #e8691f #2b2620 #9a6cf7 #0e9a6c #0e8fb0 #e0428a #a3510b #94a3b8 #e6e1d8 #e6e1d8 1px - #f26a1b #1b1813 #3a3020"),
16
+ "dark": p("#121110 #1a1917 #24221f #2c2a26 #6d6555 #7a7262 #efe9de #c2b9aa #a59c8d #ff7a2e #2a2723 #ffb88f #e8742c #15130f #efe9de #4ade80 #fbbf24 #f87171 #91a8ff #0f0e0d #efe9de #b3aa9b #24221f #ffb88f #252422 #efe9de #f07a32 #d9d0c0 #9a78ec #12a678 #1597b9 #e0559b #c88317 #6b7694 #2c2a26 #2c2a26 1px - #ff7a2e #15130f"),
17
17
  "palettes": [
18
18
  {
19
19
  "id": "crimson",
@@ -108,7 +108,7 @@ export const THEME_PRESETS = [
108
108
  "bar": "ruled",
109
109
  "tabs": "rule",
110
110
  "windows": "segmented",
111
- "stat": "ruled",
111
+ "stat": "divided",
112
112
  "section": "open",
113
113
  "fields": "open",
114
114
  "table": "open",
@@ -117,13 +117,14 @@ export const THEME_PRESETS = [
117
117
  "chart": "plain",
118
118
  "buttons": "keyed",
119
119
  "links": "plain",
120
- "rules": "ink",
120
+ "rules": "hairline",
121
121
  "avatar": "plain",
122
122
  "workflow": "markers",
123
123
  "banner": "plain",
124
124
  "steps": "strip",
125
125
  "lanes": "tag",
126
- "header": "plain",
126
+ "header": "band",
127
+ "filters": "solid",
127
128
  "required": "star",
128
129
  "checkbox": "native",
129
130
  "formStep": "plain",
@@ -135,31 +136,32 @@ export const THEME_PRESETS = [
135
136
  "roles": {
136
137
  "title": {
137
138
  "face": "heading",
138
- "size": "30px",
139
+ "size": "28px",
139
140
  "weight": 700,
140
- "case": "upper",
141
- "tracking": "0.01em",
142
- "leading": 1.1
141
+ "case": "none",
142
+ "tracking": "0em",
143
+ "leading": 1.15
143
144
  },
144
145
  "heading": {
145
146
  "face": "heading",
146
- "size": "22px",
147
+ "size": "23px",
147
148
  "weight": 700,
148
- "case": "upper",
149
- "tracking": "0.01em"
149
+ "case": "none",
150
+ "tracking": "0em"
150
151
  },
151
152
  "section": {
152
- "face": "heading",
153
+ "face": "ui",
153
154
  "size": "15px",
154
- "weight": 700,
155
- "case": "upper",
156
- "tracking": "0.04em"
155
+ "weight": 600,
156
+ "case": "none",
157
+ "tracking": "0em"
157
158
  },
158
159
  "label": {
159
- "face": "heading",
160
- "weight": 700,
161
- "case": "upper",
162
- "tracking": "0.06em"
160
+ "face": "ui",
161
+ "size": "12px",
162
+ "weight": 600,
163
+ "case": "none",
164
+ "tracking": "0em"
163
165
  },
164
166
  "data": {
165
167
  "features": [
@@ -299,6 +301,7 @@ export const THEME_PRESETS = [
299
301
  "steps": "strip",
300
302
  "lanes": "tint",
301
303
  "header": "plain",
304
+ "filters": "quiet",
302
305
  "required": "star",
303
306
  "checkbox": "native",
304
307
  "formStep": "plain",
@@ -436,6 +439,7 @@ export const THEME_PRESETS = [
436
439
  "steps": "flat",
437
440
  "lanes": "tint",
438
441
  "header": "plain",
442
+ "filters": "dashed",
439
443
  "required": "star",
440
444
  "checkbox": "native",
441
445
  "formStep": "plain",
@@ -575,6 +579,7 @@ export const THEME_PRESETS = [
575
579
  "steps": "flat",
576
580
  "lanes": "tint",
577
581
  "header": "band",
582
+ "filters": "dashed",
578
583
  "required": "star",
579
584
  "checkbox": "native",
580
585
  "formStep": "plain",
@@ -706,6 +711,7 @@ export const THEME_PRESETS = [
706
711
  "steps": "strip",
707
712
  "lanes": "plain",
708
713
  "header": "plain",
714
+ "filters": "dashed",
709
715
  "required": "star",
710
716
  "checkbox": "native",
711
717
  "formStep": "plain",
@@ -47,6 +47,8 @@ export interface AskedSection {
47
47
  };
48
48
  /** The target is the whole this metric is a share of, not a goal (it follows the metric's window and picks). */
49
49
  targetWhole?: true;
50
+ /** A rows section asked for its rows and no total (served only: an overview's, which says none). */
51
+ counted?: false;
50
52
  error?: string;
51
53
  }
52
54
  /** A breakdown's goals, a row per group: the target table's measure by its own `by`, within its query. */
@@ -209,6 +209,8 @@ interface OrderTerm {
209
209
  direction: 'asc' | 'desc';
210
210
  /** The values in their declared order (schema.ts `declaredOrder`). */
211
211
  declared?: readonly string[];
212
+ /** An empty value after every other, in either direction: said as `IS NULL` first, which every dialect reads (view.ts). */
213
+ nulls?: 'last';
212
214
  }
213
215
  /**
214
216
  * An ORDER BY clause, or nothing. A term with a declared vocabulary sorts its
@@ -162,15 +162,16 @@ export function orderClauseSql(terms, style, startIndex = 1) {
162
162
  if (typeof term === 'string')
163
163
  return term;
164
164
  const dir = term.direction === 'desc' ? 'DESC' : 'ASC';
165
+ const last = term.nulls === 'last' ? `${term.expression} IS NULL ASC, ` : '';
165
166
  if (!term.declared?.length)
166
- return `${term.expression} ${dir}`;
167
+ return `${last}${term.expression} ${dir}`;
167
168
  const rank = term.declared
168
169
  .map((value, at) => {
169
170
  params.push(value);
170
171
  return `WHEN ${style.placeholder(startIndex + params.length - 1)} THEN ${at}`;
171
172
  })
172
173
  .join(' ');
173
- return `CASE ${term.expression} ${rank} ELSE ${term.declared.length} END ${dir}, ${term.expression} ${dir}`;
174
+ return `${last}CASE ${term.expression} ${rank} ELSE ${term.declared.length} END ${dir}, ${term.expression} ${dir}`;
174
175
  })
175
176
  .join(', ');
176
177
  return { text: ` ORDER BY ${text}`, params };
@@ -1,4 +1,4 @@
1
- import type { ColumnMeta, TableMeta } from './schema.js';
1
+ import { type ColumnMeta, type TableMeta } from './schema.js';
2
2
  /** The explicit selection wins; otherwise steps declare the form's fields
3
3
  * in order. Groups only arrange fields and do not narrow a schema-derived form. */
4
4
  export declare function formShownFields(form: {
@@ -19,3 +19,26 @@ export declare function isRequired(column: ColumnMeta, assigned: string | null):
19
19
  * cannot fill either.
20
20
  */
21
21
  export declare function unformedColumns(table: TableMeta, writes: (column: string) => boolean): string[];
22
+ /** A machine as a New form reads it: its column and its states' stored values. */
23
+ interface FormMachine {
24
+ column: string;
25
+ since?: string;
26
+ states: readonly string[];
27
+ }
28
+ /**
29
+ * The columns a New form leaves to the database and the App's machine, where the App's form does not name them: a
30
+ * moment the database stamps (a timestamp with a default, or a creation or upkeep stamp with one), a number a
31
+ * sequence hands out, and a state's own stamp (`completed_at` beside a `completed` state), which the platform
32
+ * writes as the record enters the state (stateStampColumn) — a new record starts in its first one. None of these is
33
+ * the creator's to say, and a form that asked for them asked a person to invent a value the system keeps. Each stays
34
+ * on the record, editable there where it is writable. A day with a default (an invoice's date, today unless said)
35
+ * is the creator's, and stays asked.
36
+ */
37
+ export declare function platformWritten(table: TableMeta, machine?: FormMachine): Set<string>;
38
+ /**
39
+ * The columns a New form starts at now where nothing else starts them: a required stamp of when the record was
40
+ * entered (`opened_at`, `created_at`) with no default of the database's or the form's. The form still asks it, so a
41
+ * record entered late can say when it really was; it no longer asks a person to type the moment they are in.
42
+ */
43
+ export declare function enteredNow(columns: readonly ColumnMeta[], defaults: Readonly<Record<string, unknown>>): ColumnMeta[];
44
+ export {};