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

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.
@@ -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",
@@ -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',
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.37",
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;