@mistriwork/engine 1.0.0-rc.36 → 1.0.0-rc.38

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.
@@ -140,10 +140,19 @@ const writesHead = (head) => Boolean(head?.title ||
140
140
  head?.social ||
141
141
  head?.pane ||
142
142
  head?.pwa);
143
+ /** What an App's own theme carries that a page's head never writes: its served files and where its menu sits. */
144
+ const HEAD_UNWRITTEN = new Set(['faces', 'stylesheet', 'shell']);
143
145
  /** Generate only registered token names and validated theme values. Row text
144
146
  * exists only in escaped JSON; it can never close a style/script element. */
145
147
  function brandingHead(html, presentation, base) {
146
- const theme = parseThemes([presentation.value.theme], 'Request branding', 'themes', { platform: true })[0];
148
+ /* A tenant's theme starts from the App's own, which may ship font files, a stylesheet or a menu placement. The head
149
+ writes none of them (the shell serves the App's already), so the validator is not asked them: a field report's
150
+ App wore its own faces, and every public form of a tenant that had saved a name answered 403. */
151
+ const said = presentation.value.theme;
152
+ const tokens = said && typeof said === 'object' && !Array.isArray(said)
153
+ ? Object.fromEntries(Object.entries(said).filter(([key]) => !HEAD_UNWRITTEN.has(key)))
154
+ : said;
155
+ const theme = parseThemes([tokens], 'Request branding', 'themes', { platform: true })[0];
147
156
  const declarations = (mode) => {
148
157
  const pairs = [];
149
158
  for (const [key, token] of Object.entries(PALETTE_TOKENS)) {
@@ -127,8 +127,11 @@ export async function exportFile(asked) {
127
127
  return stream(res, format, view.base, rowsWanted(view.limit), read, requested(body) ?? undefined, amountsOf(view.base), asked.headers, byOffset ? answer : undefined);
128
128
  }
129
129
  }
130
+ /* Not a file, so not a 200: a client reads the status before the body. A table this reader is not served is not
131
+ found — the same answer whether it exists or not, so a refusal tells nothing — and any other question that cannot
132
+ be read is a bad request. Either way `errors` says why, as `/api/run`'s does. */
130
133
  if (!parsed.query || parsed.errors.length) {
131
- answer(200, { errors: parsed.errors });
134
+ answer(servesTable(schema, text) ? 400 : 404, { errors: parsed.errors });
132
135
  return undefined;
133
136
  }
134
137
  const query = parsed.query;
@@ -170,6 +173,11 @@ export async function exportFile(asked) {
170
173
  };
171
174
  return stream(res, format, table.id, rowsWanted(query.limit), read, wanted, amountsOf(table.id), asked.headers, byOffset ? answer : undefined);
172
175
  }
176
+ /** Whether the question's first word is a table in this reader's schema, by id or by bare name (as parseQuery finds it); an empty question names none and is no missing table. */
177
+ function servesTable(schema, text) {
178
+ const first = text.trim().split(/\s+/)[0];
179
+ return !first || findTable(schema, first) !== undefined || schema.tables.some((table) => table.name === first);
180
+ }
173
181
  function refuseTable(answer, tableId) {
174
182
  answer(403, {
175
183
  error: `Export of "${tableId}" is not available to this person.`,
@@ -35,7 +35,7 @@ import { claimContext, contextJson, contextLines, fromProfile, projectContext }
35
35
  const migrateUsage = () => product() +
36
36
  ' migrate <new <name> | diff <name> | check | squash | status | up | validate | baseline | repair> [--app <dir>] ' +
37
37
  '[<db> | --db <target> | --config <path>] [--connection <name>] [--schema <name>] [--migrations <dir>] [--history-table <name>] ' +
38
- '[--schema-file <path>] [--dev-url <url>] [--dry-run] [--tool flyway] [--repeatable]';
38
+ '[--schema-file <path>] [--dev-url <url>] [--dry-run] [--tool flyway] [--repeatable] [--number <n>]';
39
39
  /** The exit codes: what went wrong, for CI. */
40
40
  const EXIT = { ok: 0, couldNot: 1, invalid: 2, failed: 3, app: 4, stores: 5 };
41
41
  const COMMANDS = ['new', 'diff', 'check', 'squash', 'status', 'up', 'validate', 'baseline', 'repair'];
@@ -72,7 +72,7 @@ export async function runMigrate(argv, write = (line) => process.stdout.write(`$
72
72
  write(`${migrateUsage()}\n\n` +
73
73
  "Versioned SQL files in Flyway's format (V3__add_payoff_quote.sql, R__views.sql), in migrations/ inside the App\n" +
74
74
  'by default, run forward only, each in its own transaction.\n' +
75
- ' new <name> write the next V file (--repeatable: an R__ file)\n' +
75
+ ' new <name> write the next V file (--repeatable: an R__ file; --number 0042: that version, refused when taken)\n' +
76
76
  ' diff <name> write the next V file from schema.sql: what the migrations still lack to build it (Atlas;\n' +
77
77
  ' the first is schema.sql itself, with no download)\n' +
78
78
  ' check the migrations, applied to a scratch database, build schema.sql (exit 2 if not)\n' +
@@ -108,6 +108,7 @@ export async function runMigrate(argv, write = (line) => process.stdout.write(`$
108
108
  let tool;
109
109
  let dryRun = false;
110
110
  let repeatable = false;
111
+ let number;
111
112
  let json = false;
112
113
  let schemaFile;
113
114
  let devUrl;
@@ -173,6 +174,10 @@ export async function runMigrate(argv, write = (line) => process.stdout.write(`$
173
174
  repeatable = true;
174
175
  continue;
175
176
  }
177
+ if (arg === '--number') {
178
+ number = value(i++, arg);
179
+ continue;
180
+ }
176
181
  if (arg === '--json') {
177
182
  json = true;
178
183
  continue;
@@ -209,6 +214,10 @@ export async function runMigrate(argv, write = (line) => process.stdout.write(`$
209
214
  }
210
215
  if (repeatable && command !== 'new')
211
216
  return fail('--repeatable is for new: it names the file R__<name>.sql.');
217
+ if (number !== undefined && command !== 'new')
218
+ return fail('--number is for new: it is the version the V file is written with.');
219
+ if (number !== undefined && repeatable)
220
+ return fail('--number is for a V file; an R__ file has no version.');
212
221
  if (json && (app === undefined || !['status', 'up', 'validate'].includes(command)))
213
222
  return fail('--json is for status, up and validate with --app: it prints the bootstrap plan as data.');
214
223
  if (json && tool)
@@ -275,7 +284,7 @@ export async function runMigrate(argv, write = (line) => process.stdout.write(`$
275
284
  }, write);
276
285
  }
277
286
  if (command === 'new') {
278
- const path = newMigration(targetDir(registry, config, flags, appDir, loaded?.binding), name, repeatable);
287
+ const path = newMigration(targetDir(registry, config, flags, appDir, loaded?.binding), name, repeatable, new Date(), undefined, number);
279
288
  write(`wrote ${shown(path)}`);
280
289
  return EXIT.ok;
281
290
  }
@@ -29,6 +29,8 @@ export declare function readMigrations(dir: string): MigrationDirectory;
29
29
  * runner will do with it. The version is one past the highest the directory
30
30
  * holds, in the directory's own style: a team that numbers by timestamp gets a
31
31
  * timestamp. `body` is the file's text when something already wrote it
32
- * (`migrate diff`).
32
+ * (`migrate diff`). `number` is the version a person chose (`--number 0042`),
33
+ * spelled as given: a team that zero-pads keeps its padding. One the directory
34
+ * already holds is refused, since two files of one version stop every run.
33
35
  */
34
- export declare function newMigration(dir: string, name: string, repeatable: boolean, now?: Date, body?: string): string;
36
+ export declare function newMigration(dir: string, name: string, repeatable: boolean, now?: Date, body?: string, number?: string): string;
@@ -107,9 +107,11 @@ export function readMigrations(dir) {
107
107
  * runner will do with it. The version is one past the highest the directory
108
108
  * holds, in the directory's own style: a team that numbers by timestamp gets a
109
109
  * timestamp. `body` is the file's text when something already wrote it
110
- * (`migrate diff`).
110
+ * (`migrate diff`). `number` is the version a person chose (`--number 0042`),
111
+ * spelled as given: a team that zero-pads keeps its padding. One the directory
112
+ * already holds is refused, since two files of one version stop every run.
111
113
  */
112
- export function newMigration(dir, name, repeatable, now = new Date(), body) {
114
+ export function newMigration(dir, name, repeatable, now = new Date(), body, number) {
113
115
  const slug = name
114
116
  .trim()
115
117
  .replace(/[^A-Za-z0-9]+/g, '_')
@@ -122,6 +124,15 @@ export function newMigration(dir, name, repeatable, now = new Date(), body) {
122
124
  if (repeatable) {
123
125
  file = `R__${slug}.sql`;
124
126
  }
127
+ else if (number !== undefined) {
128
+ if (!/^\d+(?:[._]\d+)*$/.test(number))
129
+ throw new Error(`--number takes a version of digits, like 0042 or 2.1; "${number}" is not one.`);
130
+ const version = number.replace(/_/g, '.');
131
+ const taken = files.find((f) => f.version !== undefined && compareVersions(f.version, version) === 0);
132
+ if (taken)
133
+ throw new Error(`version ${number} is taken: ${taken.script} has it. Choose another --number, or leave it out for the next.`);
134
+ file = `V${number}__${slug}.sql`;
135
+ }
125
136
  else {
126
137
  const majors = files.filter((f) => f.version !== undefined).map((f) => BigInt(f.version.split('.')[0]));
127
138
  const highest = majors.reduce((a, b) => (b > a ? b : a), 0n);
@@ -89,6 +89,17 @@ export function migrateUp(target, options = {}) {
89
89
  }
90
90
  if (initial.plan.problems.length)
91
91
  return { status: initial, applied: [] };
92
+ /* A V file `migrate new` wrote and nobody filled in would be recorded as applied, and the statements written
93
+ into it afterwards never run: its checksum then disagrees and every later run stops on it. An R__ file runs
94
+ again whenever its text changes, so an empty one (a placeholder for views to come) does no harm. */
95
+ const blank = initial.plan.pending.filter((file) => file.kind === 'versioned' && !splitPostgres(file.sql).length);
96
+ if (blank.length) {
97
+ return {
98
+ status: initial,
99
+ applied: [],
100
+ refused: `${blank.map((file) => file.script).join(', ')} ${blank.length === 1 ? 'holds' : 'hold'} no statement, only comments or blank lines. Write the migration into it, or delete it; nothing was applied.`,
101
+ };
102
+ }
92
103
  if (options.dryRun)
93
104
  return { status: initial, applied: [], wouldRun: initial.plan.pending };
94
105
  const expected = initial.snapshot?.objects;
@@ -383,8 +383,11 @@ const words = (raw) => Array.isArray(raw) && raw.every((name) => typeof name ===
383
383
  export function parsePage(raw, at) {
384
384
  const component = parseComponentDecl(raw.component, `${at}, "component"`, 'page');
385
385
  const reads = raw.reads;
386
- if (!words(reads) || !reads.length) {
387
- throw new Error(`[page-reads] ${at} has no "reads": the resources the page reads — reads: ['pick_list', 'order_line']. A page reads nothing it does not declare.`);
386
+ /* `reads: []` is a page that says it reads nothing (a welcome page, one
387
+ that only runs commands): what it declares is still checked against what
388
+ its module reads. Only a missing or malformed list is refused. */
389
+ if (!words(reads)) {
390
+ throw new Error(`[page-reads] ${at} has no "reads": the resources the page reads — reads: ['pick_list', 'order_line'], or reads: [] for none. A page reads nothing it does not declare.`);
388
391
  }
389
392
  const commands = raw.commands === undefined ? [] : raw.commands;
390
393
  if (!words(commands))
@@ -280,7 +280,8 @@ export const THEME_PRESETS = [
280
280
  },
281
281
  "radius": {
282
282
  "control": "8px",
283
- "field": "8px"
283
+ "field": "8px",
284
+ "pill": "999px"
284
285
  },
285
286
  "recipes": {
286
287
  "nav": "pill",
@@ -419,7 +420,8 @@ export const THEME_PRESETS = [
419
420
  },
420
421
  "radius": {
421
422
  "control": "0px",
422
- "field": "0px"
423
+ "field": "0px",
424
+ "pill": "999px"
423
425
  },
424
426
  "recipes": {
425
427
  "nav": "inverted",
@@ -560,7 +562,8 @@ export const THEME_PRESETS = [
560
562
  },
561
563
  "radius": {
562
564
  "control": "8px",
563
- "field": "8px"
565
+ "field": "8px",
566
+ "pill": "999px"
564
567
  },
565
568
  "recipes": {
566
569
  "nav": "quiet",
@@ -454,6 +454,32 @@ export function recordPageReads(names, page, base, plans, key, options) {
454
454
  assertNever(section.kind, 'page section kind');
455
455
  }
456
456
  });
457
+ /* A strip of related tabs decides which tabs it has before one is opened (kit ListTabs, useStandings): the condition of a
458
+ list that has one, and the first page of a list that hides while empty, which is the answer to "has it rows?". They
459
+ are the reads the list asks itself when its tab is opened, so they are asked here too, once, and the strip finds
460
+ them waiting (as for a list alone). A closed tab is asked what it must decide on and no more. */
461
+ for (const run of runs) {
462
+ if (run.length < 2)
463
+ continue;
464
+ for (const index of run) {
465
+ const section = page.sections[index];
466
+ if (section.hidden || drawn.has(index) || section.kind !== 'list')
467
+ continue;
468
+ kind = 'related';
469
+ if (section.when)
470
+ reads.push({ path: '/api/run', body: whenBody(base, key, section.when) });
471
+ const plan = planOf(index);
472
+ if (section.emptyMode !== 'hide' || !plan || plan.error || plan.empty)
473
+ continue;
474
+ if (section.group && plan.groups) {
475
+ reads.push({ path: '/api/breakdown', body: groupsBody(plan.groups, 0), kind });
476
+ continue;
477
+ }
478
+ const listed = listView(names, section, plan, options.rows).view;
479
+ if (listed)
480
+ view({ view: listed, offset: 0 });
481
+ }
482
+ }
457
483
  /* An inferred page's tabs say how many rows each holds, all of them in one read; a list alone says it in its head. */
458
484
  if (isInferredPage(page, names.app))
459
485
  for (const run of runs) {
@@ -287,7 +287,9 @@ const HOUSE = [
287
287
  chart: ['#3559e6', '#9a78ec', '#12a678', '#c88317', '#e0559b', '#1597b9', '#d26b3b', '#6b7694'],
288
288
  },
289
289
  },
290
- shape: { radius: { control: '8px', field: '8px' }, elevation: 'raised', border: { rule: '1px' } },
290
+ /* `pill` is said in every look: an App's stylesheet may read var(--pill-radius) (check accepts it), and a look that left it
291
+ unsaid gave that rule no value and square corners. Round is what the sheets draw a tag as already. */
292
+ shape: { radius: { control: '8px', field: '8px', pill: 'round' }, elevation: 'raised', border: { rule: '1px' } },
291
293
  /* The page's name anchors it: 28px, tight; a list's name a step under, and a section's heading 16px, so the
292
294
  page reads title, section, row at a glance. On a flat page the type is the hierarchy the boxes used to be. */
293
295
  type: {
@@ -380,7 +382,7 @@ const HOUSE = [
380
382
  chart: ['#ffffff', '#8a8a8a', '#cccccc', '#6a6a6a', '#a8a8a8', '#4a4a4a', '#e6e6e6', '#333333'],
381
383
  },
382
384
  },
383
- shape: { radius: { control: '0px', field: '0px' }, elevation: 'flat' },
385
+ shape: { radius: { control: '0px', field: '0px', pill: 'round' }, elevation: 'flat' },
384
386
  /* Figures and the labels that make the look in the platform's monospace, the labels and the bar's entries in
385
387
  capitals: not data, which a reader who wants monospace picks in Preferences. */
386
388
  type: {
@@ -464,7 +466,7 @@ const HOUSE = [
464
466
  chart: ['#7fd1a0', '#c4b1f2', '#f2a08a', '#f08cc4', '#ecc36e', '#6fd1c8', '#92b8f2', '#8c887f'],
465
467
  },
466
468
  },
467
- shape: { radius: { control: '8px', field: '8px' }, elevation: 'soft' },
469
+ shape: { radius: { control: '8px', field: '8px', pill: 'round' }, elevation: 'soft' },
468
470
  type: { font: { ui: SANS, data: SANS, heading: SANS, figures: FIGURES }, roles: { title: { weight: 600 } } },
469
471
  // Compact, as Mono and Lumen: see Mono's density.
470
472
  density: 'compact',
@@ -211,7 +211,7 @@ export declare function typeAttributes(type: ThemeTypeDefinition | undefined): R
211
211
  * The published parts a theme may dress one by one (themeParts.ts says what each may take and how it is worn). Here,
212
212
  * with the words the root wears for them, because the first paint sets `data-parts` as it sets the recipes'.
213
213
  */
214
- export declare const THEME_PARTS: readonly ["ground", "bar", "bar.search", "nav", "nav.item", "nav.current", "nav.group", "logo", "page.title", "tabs", "tab.current", "section", "section.title", "stat", "stat.figure", "fields", "field.label", "table", "table.head", "table.row", "status", "tag", "button.primary", "button.secondary", "button.quiet", "link", "board.lane", "board.card", "workflow.step", "banner", "steps.step", "avatar", "identityMark", "menu", "dialog", "chart"];
214
+ export declare const THEME_PARTS: readonly ["ground", "bar", "bar.search", "nav", "nav.item", "nav.current", "nav.group", "logo", "page.title", "tabs", "tab.current", "section", "section.title", "stat", "stat.figure", "fields", "field.label", "table", "table.head", "table.row", "status", "tag", "button.primary", "button.secondary", "button.quiet", "link", "board.lane", "board.card", "workflow.step", "banner", "steps.step", "avatar", "identityMark", "menu", "dialog", "chart", "kicker"];
215
215
  /** What a part style may say, in the order its words are written. */
216
216
  export declare const PART_PROPERTIES: readonly ['ground', 'ink', 'edge', 'radius', 'lift', 'face', 'weight', 'case'];
217
217
  /** The root's `data-parts`: one word per property a part says (`stat:ground button.primary:case`); undefined when none. */
@@ -220,6 +220,7 @@ export const THEME_PARTS = [
220
220
  'menu',
221
221
  'dialog',
222
222
  'chart',
223
+ 'kicker',
223
224
  ];
224
225
  /** What a part style may say, in the order its words are written. */
225
226
  export const PART_PROPERTIES = ['ground', 'ink', 'edge', 'radius', 'lift', 'face', 'weight', 'case'];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mistriwork/engine",
3
- "version": "1.0.0-rc.36",
3
+ "version": "1.0.0-rc.38",
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
@@ -122,6 +122,8 @@ export interface CommandChoiceSource {
122
122
  from: string;
123
123
  by: string;
124
124
  labelColumn: string;
125
+ /** The order the rows are offered in: a column of `from` and a direction. Absent, the rows are in the order of `labelColumn`. */
126
+ sort?: { column: string; direction: 'asc' | 'desc' };
125
127
  /** Set by the server on a public form it served this field's rows with: `options` is the whole answer, an empty list
126
128
  meaning none to offer, and the page reads nothing of its own. Never written in an App. */
127
129
  served?: true;
@@ -281,8 +283,12 @@ export interface AppCommandAction<Target extends string = string, Label extends
281
283
  /** Its key in `resources.<table>.actions`. */
282
284
  id: string;
283
285
  command: AppCommandReference<Target>;
284
- /** Where the button is offered: the command's own `when`, or the states a machine's verb leaves. Visibility only; the server judges the command's. */
286
+ /** Where the button is offered: the command's own `when` and the action's together, or the states a machine's verb
287
+ leaves. Visibility only; the server judges the command's. */
285
288
  when?: string;
289
+ /** The action's own `when` alone, when it has one: what a record's bar asks, since the server's availability answer
290
+ already holds the command's. */
291
+ offered?: string;
286
292
  /** A machine's verb that says itself differently from different states (a per-edge `label`, or `{to}` in it):
287
293
  each label with the states it is said from, as a condition. `label` is the first state's. */
288
294
  labels?: Array<{ when: string; label: string }>;
package/schema/theme.d.ts CHANGED
@@ -178,7 +178,8 @@ export type ThemePart =
178
178
  | 'identityMark'
179
179
  | 'menu'
180
180
  | 'dialog'
181
- | 'chart';
181
+ | 'chart'
182
+ | 'kicker';
182
183
 
183
184
  /** A color role by its path in `colors`: `ink`, `nav.ground`, `status.good`, `chart[2]`. */
184
185
  export type ThemeColorPath =