@ultimat3/cli 31.50.0 → 31.52.0
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.
- package/CLAUDE.md +1 -1
- package/README.md +9 -9
- package/package.json +29 -29
- package/src/app-boundaries.ts +2 -0
- package/src/app-dev-imports.ts +77 -0
- package/src/app-load-import-chain.ts +112 -0
- package/src/app-load-unresolved.ts +173 -16
- package/src/app-load.ts +22 -5
- package/src/catalog-layout.ts +194 -0
- package/src/cmd-i18n-spec.ts +4 -4
- package/src/cmd-i18n-split.ts +133 -0
- package/src/cmd-i18n.ts +46 -66
- package/src/config-redact.ts +20 -4
- package/src/db-rollback-pass.ts +4 -1
- package/src/dev-child-watch.ts +16 -0
- package/src/dev-db-migrate.ts +27 -46
- package/src/dev-db-migrator-hold.ts +131 -0
- package/src/dev-db-rollback.ts +11 -2
- package/src/dev-only-imports.ts +59 -0
- package/src/dev-rebuild-schema.ts +7 -24
- package/src/error-codes-boundary.ts +2 -0
- package/src/evaluated-walk.ts +103 -0
- package/src/generate-catalog-locales.ts +25 -2
- package/src/generate-follow-ups.ts +8 -3
- package/src/i18n-audit.ts +17 -33
- package/src/i18n-index.ts +108 -31
- package/src/i18n-locale-parity.ts +14 -6
- package/src/i18n-new-locale.ts +75 -0
- package/src/i18n-registration.ts +52 -27
- package/src/index.ts +2 -0
- package/src/island-capture.ts +36 -7
- package/src/mcp-errors.ts +3 -1
- package/src/merge-state.ts +3 -2
- package/src/messages-floor.ts +2 -0
- package/src/messages.ts +2 -0
- package/src/module-imports.ts +26 -15
- package/src/page-route.ts +75 -0
- package/src/scan-ways.ts +145 -0
- package/src/serve-boot-telemetry.ts +106 -0
- package/src/serve-boot.ts +23 -4
- package/src/shot-blank.ts +70 -0
- package/src/templates/catalog-barrel.ts +84 -0
- package/src/templates/guard-released-forms.ts +2 -1
- package/src/templates/guard-untranslated-string.ts +27 -6
- package/src/templates/locales.ts +6 -0
- package/src/templates/scaffold-gitattributes.ts +9 -2
- package/src/templates/scaffold-i18n.ts +10 -6
- package/src/templates/shapes/offline.ts +5 -2
- package/src/test-ignores.ts +3 -2
- package/src/verify-checks.ts +7 -3
- package/src/verify-floor.ts +9 -1
- package/src/verify-local-only.ts +66 -0
- package/src/verify-run.ts +17 -2
- package/wiki/Actions.md +1 -1
- package/wiki/Auth.md +4 -4
- package/wiki/Batching-And-Preloading.md +1 -0
- package/wiki/CLI-Reference-Data.md +241 -0
- package/wiki/CLI-Reference-Gate.md +572 -0
- package/wiki/CLI-Reference-Project.md +414 -0
- package/wiki/CLI-Reference-Ship.md +348 -0
- package/wiki/CLI-Reference-Tools.md +666 -0
- package/wiki/CLI-Reference.md +14 -2225
- package/wiki/Compared.md +8 -8
- package/wiki/Configuration.md +26 -2
- package/wiki/Deployment.md +1 -1
- package/wiki/Entities-And-Migrations.md +3 -2
- package/wiki/I18n.md +39 -5
- package/wiki/Installation.md +1 -1
- package/wiki/Jobs-And-Workflows.md +29 -1
- package/wiki/Known-Gaps.md +3 -0
- package/wiki/Observability.md +15 -1
- package/wiki/Outbound-HTTP.md +62 -2
- package/wiki/PWA-And-Offline.md +1 -1
- package/wiki/Policies-And-Authz.md +10 -0
- package/wiki/Realtime.md +29 -2
- package/wiki/Static-Assets.md +1 -1
- package/wiki/Testing.md +58 -0
- package/wiki/Theming.md +31 -8
- package/wiki/Troubleshooting.md +2 -2
- package/wiki/Upgrading.md +6 -1
package/src/dev-db-migrate.ts
CHANGED
|
@@ -3,26 +3,25 @@
|
|
|
3
3
|
// so the command asks the holder instead of opening `.x/pgdata` a second time. Loopback Host and
|
|
4
4
|
// peer, same-origin: the `/_x/db` doors.
|
|
5
5
|
|
|
6
|
-
import {
|
|
6
|
+
import { renderThrowable, UltimateError } from '@ultimat3/core';
|
|
7
7
|
import type { DriftDifference } from '@ultimat3/db';
|
|
8
|
-
import { checkDrift,
|
|
8
|
+
import { checkDrift, migrate } from '@ultimat3/db';
|
|
9
9
|
import type { CatalogDescription } from '@ultimat3/db/schema-dump';
|
|
10
10
|
import { introspectCatalog } from '@ultimat3/db/schema-dump';
|
|
11
11
|
import type { Route, UltimateRequest } from '@ultimat3/http';
|
|
12
12
|
import { jsonResponse } from '@ultimat3/http';
|
|
13
|
-
import { loadAppConfig } from './app-config-load';
|
|
14
13
|
import { acceptCreatedTables } from './db-accept-created';
|
|
15
14
|
import { DEV_LEDGER_PATH, DEV_MIGRATE_PATH, DEV_ROLLBACK_PATH } from './db-dev-wire';
|
|
16
15
|
import { frameworkStorageDrift } from './db-object-drift';
|
|
17
16
|
import { assertSameOrigin, hostRefusal } from './dev-dashboard-guard';
|
|
17
|
+
import { devMigratorPass } from './dev-db-migrator-hold';
|
|
18
18
|
import { ledgerInDev, rollbackInDev, stepsOf } from './dev-db-rollback';
|
|
19
19
|
import { ledgerMoved } from './dev-db-settled';
|
|
20
20
|
import { readMigrations } from './migrations';
|
|
21
|
-
import { rowSecurityDeclared } from './row-security-boot';
|
|
22
21
|
import { stopRunStartFix } from './stop-run-start';
|
|
23
22
|
|
|
24
23
|
/** The command that works when this process cannot apply: the embedded database to itself. */
|
|
25
|
-
|
|
24
|
+
const MIGRATE_ALONE_FIX = stopRunStartFix(['db', 'migrate']);
|
|
26
25
|
|
|
27
26
|
/** One applied pass as it crosses the wire: `runMigrations`' report, and the live catalog. */
|
|
28
27
|
export interface DevMigrateData {
|
|
@@ -38,50 +37,36 @@ export interface DevMigrateData {
|
|
|
38
37
|
|
|
39
38
|
type Env = Readonly<Record<string, string | undefined>>;
|
|
40
39
|
|
|
41
|
-
/**
|
|
42
|
-
* With `database.rowSecurity`, this process serves as `x_app` and a migration must run as
|
|
43
|
-
* `x_migrator` from the bootstrap session — one embedded session cannot be both while it serves.
|
|
44
|
-
*/
|
|
45
|
-
export async function devCanMigrate(root: string): Promise<boolean> {
|
|
46
|
-
return !rowSecurityDeclared(await loadAppConfig(root));
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/** Refused where this process serves as `x_app`; `fix` is the command run alone, start to start. */
|
|
50
|
-
async function assertDevCanMigrate(root: string, fix: string): Promise<void> {
|
|
51
|
-
if (await devCanMigrate(root)) return;
|
|
52
|
-
throw new NotImplementedError({
|
|
53
|
-
cause:
|
|
54
|
-
'this x dev serves the embedded database as x_app (database.rowSecurity), and migrations run as x_migrator — one embedded session cannot hold both',
|
|
55
|
-
fix,
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
|
|
59
40
|
/**
|
|
60
41
|
* `serve.ts`'s `runMigrations` over the client this process already holds: the same file list,
|
|
61
42
|
* the same ledger, the same post-condition. No boot and no `stop()` — the database is `x dev`'s.
|
|
43
|
+
* Where it serves as `x_app`, the whole pass is one hold of the session (`devMigratorPass`).
|
|
62
44
|
*/
|
|
63
45
|
export async function migrateInDev(root: string, env: Env): Promise<DevMigrateData> {
|
|
64
|
-
await assertDevCanMigrate(root, MIGRATE_ALONE_FIX);
|
|
65
46
|
const migrations = await readMigrations(root);
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
47
|
+
return devMigratorPass(root, env, async ({ client, lock, bootstrap }) => {
|
|
48
|
+
const report = await migrate({
|
|
49
|
+
migrations,
|
|
50
|
+
client,
|
|
51
|
+
lock,
|
|
52
|
+
...(env['APP_VERSION'] === undefined ? {} : { appVersion: env['APP_VERSION'] }),
|
|
53
|
+
});
|
|
54
|
+
// As `runMigrations` reads them: after the migrate step, as the bootstrap user. One at a
|
|
55
|
+
// time — under the hold they share one session with no turn queue between them.
|
|
56
|
+
await bootstrap();
|
|
57
|
+
const drift = acceptCreatedTables(await checkDrift({ migrations, client }), migrations);
|
|
58
|
+
const catalog = await introspectCatalog({ client });
|
|
59
|
+
const storage = await frameworkStorageDrift(client);
|
|
60
|
+
return {
|
|
61
|
+
applied: report.applied.map((entry) => entry.id),
|
|
62
|
+
skipped: report.skipped.length,
|
|
63
|
+
appVersion: report.appVersion,
|
|
64
|
+
durationMs: report.durationMs,
|
|
65
|
+
drift: drift.differences,
|
|
66
|
+
catalog,
|
|
67
|
+
storage,
|
|
68
|
+
};
|
|
69
69
|
});
|
|
70
|
-
const drift = acceptCreatedTables(await checkDrift({ migrations }), migrations);
|
|
71
|
-
const client = db();
|
|
72
|
-
const [catalog, storage] = await Promise.all([
|
|
73
|
-
introspectCatalog({ client }),
|
|
74
|
-
frameworkStorageDrift(client),
|
|
75
|
-
]);
|
|
76
|
-
return {
|
|
77
|
-
applied: report.applied.map((entry) => entry.id),
|
|
78
|
-
skipped: report.skipped.length,
|
|
79
|
-
appVersion: report.appVersion,
|
|
80
|
-
durationMs: report.durationMs,
|
|
81
|
-
drift: drift.differences,
|
|
82
|
-
catalog,
|
|
83
|
-
storage,
|
|
84
|
-
};
|
|
85
70
|
}
|
|
86
71
|
|
|
87
72
|
/** The refusal as the command re-throws it: the code, cause and fix of whatever stopped the pass. */
|
|
@@ -143,10 +128,6 @@ export function devMigrateRoutes(input: DevMigrateRouteInput): readonly Route[]
|
|
|
143
128
|
),
|
|
144
129
|
door(input, DEV_ROLLBACK_PATH, 'dev._x.db.rollback', async (request) => {
|
|
145
130
|
const steps = stepsOf(request.url.searchParams.get('steps'));
|
|
146
|
-
await assertDevCanMigrate(
|
|
147
|
-
root,
|
|
148
|
-
stopRunStartFix(['db', 'rollback', '--steps', String(steps)]),
|
|
149
|
-
);
|
|
150
131
|
return rollbackInDev(root, env, steps).finally(ledgerMoved);
|
|
151
132
|
}),
|
|
152
133
|
// A read, behind the same doors and the same verb: nothing under `/_x/db` answers a GET.
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
// A migrate or rollback pass inside a live `x dev` whose embedded session serves as `x_app`
|
|
2
|
+
// (`database.rowSecurity`): the one PGlite session is taken exclusively, becomes `x_migrator` for
|
|
3
|
+
// the pass, and serves as `x_app` again before any other statement runs — or never serves again.
|
|
4
|
+
|
|
5
|
+
import { logger, renderThrowable } from '@ultimat3/core';
|
|
6
|
+
import type { DbClient } from '@ultimat3/db';
|
|
7
|
+
import {
|
|
8
|
+
assertRowSecurityBinds,
|
|
9
|
+
baseClient,
|
|
10
|
+
DbError,
|
|
11
|
+
db,
|
|
12
|
+
holdMigratorRole,
|
|
13
|
+
isReservable,
|
|
14
|
+
raw,
|
|
15
|
+
serveAsAppRole,
|
|
16
|
+
} from '@ultimat3/db';
|
|
17
|
+
import { loadAppConfig } from './app-config-load';
|
|
18
|
+
import { stopDevServing } from './dev-child-watch';
|
|
19
|
+
import { rowSecurityDeclared } from './row-security-boot';
|
|
20
|
+
import { resolveServices } from './runtime-bindings';
|
|
21
|
+
import { stopRunStartFix } from './stop-run-start';
|
|
22
|
+
|
|
23
|
+
type Env = Readonly<Record<string, string | undefined>>;
|
|
24
|
+
|
|
25
|
+
/** What a pass runs on. Every statement of the pass goes to `client`, never to the ambient one. */
|
|
26
|
+
export interface MigratorPass {
|
|
27
|
+
readonly client: DbClient;
|
|
28
|
+
/**
|
|
29
|
+
* `migrate()`/`rollback()`'s `lock`. `false` under the hold: the advisory lock would reserve the
|
|
30
|
+
* session a second time and wait for the turn this pass is holding, and the hold already is the
|
|
31
|
+
* exclusion — PGlite has one session and one opener.
|
|
32
|
+
*/
|
|
33
|
+
readonly lock: boolean;
|
|
34
|
+
/** `reset role`: the reads `x db migrate` alone makes after its migrate step, as the bootstrap user. */
|
|
35
|
+
readonly bootstrap: () => Promise<void>;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export interface MigratorHoldSeams {
|
|
39
|
+
/** The client whose session is held. Defaults to the ambient one. */
|
|
40
|
+
readonly client?: DbClient | undefined;
|
|
41
|
+
/** Run once when the session could not be made `x_app` again. Defaults to `stopDevServing`. */
|
|
42
|
+
readonly stopServing?: (() => void) | undefined;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** After the turn that will never be released: start again, and the boot arms the roles afresh. */
|
|
46
|
+
const RESTART_FIX = 'x stop --json && x dev';
|
|
47
|
+
|
|
48
|
+
const roleLost = (error: unknown): DbError =>
|
|
49
|
+
new DbError({
|
|
50
|
+
code: 'X_DB_ROW_SECURITY_BYPASSED',
|
|
51
|
+
cause: `x dev ran a migrate pass as x_migrator and could not serve as x_app again (${renderThrowable(error)}), so it stopped serving: no statement reaches the embedded session, whose role is no longer one row security binds`,
|
|
52
|
+
fix: RESTART_FIX,
|
|
53
|
+
sourceError: error,
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Back to what the boot armed (`armRowSecurity`), judged again. `rollback` first: a pass that died
|
|
58
|
+
* inside a transaction would otherwise take the `set role` below with it at that transaction's end
|
|
59
|
+
* — and outside a transaction it is a warning, not an error.
|
|
60
|
+
*/
|
|
61
|
+
async function serveAgain(session: DbClient): Promise<void> {
|
|
62
|
+
await session.execute(raw('rollback'));
|
|
63
|
+
await session.execute(raw('reset role'));
|
|
64
|
+
await serveAsAppRole(session);
|
|
65
|
+
await assertRowSecurityBinds(session);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* `run` as `x_migrator` on the reserved session. PGlite's `reserve()` holds its turn queue, so a
|
|
70
|
+
* request's statement issued meanwhile waits and then runs as `x_app`: nothing but the pass ever
|
|
71
|
+
* sees the migrator or the bootstrap superuser. The turn is given back only once the session is
|
|
72
|
+
* `x_app` and bound by row security again; otherwise it is kept for the life of the process —
|
|
73
|
+
* every later statement waits rather than reading every tenant's rows — and `stopServing` runs.
|
|
74
|
+
*/
|
|
75
|
+
export async function withMigratorHold<T>(
|
|
76
|
+
run: (pass: MigratorPass) => Promise<T>,
|
|
77
|
+
seams: MigratorHoldSeams = {},
|
|
78
|
+
): Promise<T> {
|
|
79
|
+
const client = seams.client ?? baseClient();
|
|
80
|
+
if (!isReservable(client)) {
|
|
81
|
+
throw new DbError({
|
|
82
|
+
code: 'X_DB_ROW_SECURITY_BYPASSED',
|
|
83
|
+
cause:
|
|
84
|
+
'x dev serves the embedded database as x_app and its client cannot reserve the session, so a pass as x_migrator would run beside the requests it serves',
|
|
85
|
+
fix: stopRunStartFix(['db', 'migrate']),
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
const session = await client.reserve();
|
|
89
|
+
let outcome: { readonly value: T } | { readonly error: unknown };
|
|
90
|
+
try {
|
|
91
|
+
await session.execute(raw('reset role'));
|
|
92
|
+
await holdMigratorRole(session);
|
|
93
|
+
const value = await run({
|
|
94
|
+
client: session,
|
|
95
|
+
lock: false,
|
|
96
|
+
bootstrap: async () => {
|
|
97
|
+
await session.execute(raw('reset role'));
|
|
98
|
+
},
|
|
99
|
+
});
|
|
100
|
+
outcome = { value };
|
|
101
|
+
} catch (error) {
|
|
102
|
+
outcome = { error };
|
|
103
|
+
}
|
|
104
|
+
try {
|
|
105
|
+
await serveAgain(session);
|
|
106
|
+
} catch (error) {
|
|
107
|
+
// No `session.release()`: the turn is the only thing between a request and a superuser.
|
|
108
|
+
const lost = roleLost(error);
|
|
109
|
+
logger.error(lost.code, { code: lost.code, cause: lost.cause, fix: lost.fix });
|
|
110
|
+
(seams.stopServing ?? (() => stopDevServing('row-security-lost')))();
|
|
111
|
+
throw lost;
|
|
112
|
+
}
|
|
113
|
+
session.release();
|
|
114
|
+
if ('error' in outcome) throw outcome.error;
|
|
115
|
+
return outcome.value;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* A pass run by this `x dev`. Held only where the roles are ours and the session is one — the
|
|
120
|
+
* embedded database with `database.rowSecurity`. Anywhere else it is the ambient client under the
|
|
121
|
+
* migrate lock: an external database's migrator is whoever `DATABASE_URL` connects as.
|
|
122
|
+
*/
|
|
123
|
+
export async function devMigratorPass<T>(
|
|
124
|
+
root: string,
|
|
125
|
+
env: Env,
|
|
126
|
+
run: (pass: MigratorPass) => Promise<T>,
|
|
127
|
+
): Promise<T> {
|
|
128
|
+
const embedded = resolveServices(root, env).db.mode === 'embedded';
|
|
129
|
+
if (embedded && rowSecurityDeclared(await loadAppConfig(root))) return withMigratorHold(run);
|
|
130
|
+
return run({ client: db(), lock: true, bootstrap: async () => undefined });
|
|
131
|
+
}
|
package/src/dev-db-rollback.ts
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
import { db, isLedgerMissing, readLedger } from '@ultimat3/db';
|
|
6
6
|
import { ROLLBACK_STEPS } from './db-dev-wire';
|
|
7
7
|
import { reverseApplied } from './db-rollback-pass';
|
|
8
|
+
import { devMigratorPass } from './dev-db-migrator-hold';
|
|
8
9
|
import { parseIntFlag } from './flag-number';
|
|
9
10
|
|
|
10
11
|
type Env = Readonly<Record<string, string | undefined>>;
|
|
@@ -12,13 +13,21 @@ type Env = Readonly<Record<string, string | undefined>>;
|
|
|
12
13
|
/** `?steps=n`, through the command's own reader: the door refuses what the flag refuses. */
|
|
13
14
|
export const stepsOf = (raw: string | null): number => parseIntFlag(raw ?? '', ROLLBACK_STEPS);
|
|
14
15
|
|
|
15
|
-
/**
|
|
16
|
+
/**
|
|
17
|
+
* `rollback()` over the client this process already holds, with the command's own two refusals.
|
|
18
|
+
* Where it serves as `x_app`, the reversal runs as `x_migrator` under the same hold a migrate
|
|
19
|
+
* pass takes (`dev-db-migrator-hold.ts`).
|
|
20
|
+
*/
|
|
16
21
|
export async function rollbackInDev(
|
|
17
22
|
root: string,
|
|
18
23
|
env: Env,
|
|
19
24
|
steps: number,
|
|
20
25
|
): Promise<{ readonly reverted: readonly string[] }> {
|
|
21
|
-
return {
|
|
26
|
+
return {
|
|
27
|
+
reverted: await devMigratorPass(root, env, ({ client, lock }) =>
|
|
28
|
+
reverseApplied(root, env, steps, { client, lock }),
|
|
29
|
+
),
|
|
30
|
+
};
|
|
22
31
|
}
|
|
23
32
|
|
|
24
33
|
/** Each applied migration's id and the checksum it was applied with; no ledger is no rows. */
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
// The specifiers no container role may evaluate, and the one edit that clears an app of one: where
|
|
2
|
+
// on the way from a scanned module to the import the cut is, and the line to run there. The gate's
|
|
3
|
+
// check (`app-dev-imports.ts`) and the load's explanation of a failed import
|
|
4
|
+
// (`app-load-import-chain.ts`) read one rule, so a finding at boot and one at the gate agree.
|
|
5
|
+
|
|
6
|
+
import { scannedModulePaths } from './app-load';
|
|
7
|
+
import { realPath } from './app-load-unresolved';
|
|
8
|
+
import { commentSafe } from './comment-safe';
|
|
9
|
+
import type { ChainStep } from './evaluated-walk';
|
|
10
|
+
import { quoteArg } from './shell-quote';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* `@ultimat3/cli`'s barrel is every command, template and the test harness, and it imports
|
|
14
|
+
* `@ultimat3/testing`; a role's entry is `@ultimat3/cli/serve`. `bun:test` is the runner's own.
|
|
15
|
+
*/
|
|
16
|
+
export const isDevOnlySpecifier = (specifier: string): boolean =>
|
|
17
|
+
specifier === '@ultimat3/cli' ||
|
|
18
|
+
specifier === 'bun:test' ||
|
|
19
|
+
/^@ultimat3\/testing(?:\/|$)/.test(specifier);
|
|
20
|
+
|
|
21
|
+
/** Every module the boot scan imports under `base`, links followed: what a cut may be made in. */
|
|
22
|
+
export const scannedModules = async (base: string): Promise<ReadonlySet<string>> =>
|
|
23
|
+
new Set((await scannedModulePaths(base)).map(realPath));
|
|
24
|
+
|
|
25
|
+
/** `apps/web/app/x.ts` → `apps/web/test/`: beside the surfaces, and outside every app-scan glob. */
|
|
26
|
+
const testHome = (at: string): string => {
|
|
27
|
+
const workspace = /^(?:apps|packages)\/[^/]+(?=\/)/.exec(at)?.[0];
|
|
28
|
+
return workspace === undefined ? 'a test/ directory' : `${workspace}/test/`;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
/** Where the cut is, and the import to look for there. */
|
|
32
|
+
export interface DevOnlyCut {
|
|
33
|
+
/** Its index in the steps: the last module the boot scan imports. */
|
|
34
|
+
readonly index: number;
|
|
35
|
+
/** What that module imports on the way; `undefined` when it holds the development import itself. */
|
|
36
|
+
readonly into: string | undefined;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* The cut on the way to a development import, whose holder is the last of `steps`. The holder when
|
|
41
|
+
* the scan imports it; when it sits outside the scan (a kit under `test/`), moving it clears nothing
|
|
42
|
+
* and the cut is the scanned module's edge towards it.
|
|
43
|
+
*/
|
|
44
|
+
export function devOnlyCut(steps: readonly ChainStep[], scanned: ReadonlySet<string>): DevOnlyCut {
|
|
45
|
+
const index = Math.max(
|
|
46
|
+
0,
|
|
47
|
+
steps.findLastIndex((step) => scanned.has(step.path)),
|
|
48
|
+
);
|
|
49
|
+
return { index, into: steps[index + 1]?.specifier };
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** The edit, opening with the line to look at. `at` is app-root-relative: the cut's module. */
|
|
53
|
+
export function devOnlyFix(at: string, cut: DevOnlyCut, specifier: string): string {
|
|
54
|
+
const line = `grep -nF -- ${quoteArg(cut.into ?? specifier)} ${quoteArg(at)}`;
|
|
55
|
+
// `commentSafe`: a workspace directory's name is the repository's, and a newline ends a comment.
|
|
56
|
+
return cut.into === undefined
|
|
57
|
+
? `${line} # test support moves to ${commentSafe(testHome(at))}, which no role loads; a module a role needs drops this import`
|
|
58
|
+
: `${line} # it brings test support into a module a role loads: only a test imports that`;
|
|
59
|
+
}
|
|
@@ -6,27 +6,18 @@ import type { Migration } from '@ultimat3/db';
|
|
|
6
6
|
import { db, dbClientInstalled, isLedgerMissing, readLedger } from '@ultimat3/db';
|
|
7
7
|
import { AppMigrationsUnappliedError } from './app-migrations-verdict';
|
|
8
8
|
import { type AppliedRow, refuseEdited } from './db-applied-edits';
|
|
9
|
-
import { devCanMigrate, MIGRATE_ALONE_FIX } from './dev-db-migrate';
|
|
10
9
|
import { checkSourceDrift } from './drift';
|
|
11
10
|
import { readMigrations } from './migrations';
|
|
12
11
|
import type { Finding } from './output';
|
|
13
12
|
import { findingFrom } from './output';
|
|
14
|
-
import { resolveServices } from './runtime-bindings';
|
|
15
13
|
|
|
16
14
|
/**
|
|
17
15
|
* The migrate half too: `x dev` applies no migration unasked, so `x db gen` alone leaves the page
|
|
18
|
-
* red. Beside this process `x db migrate` is applied BY it (`dev-db-migrate.ts`), embedded or not
|
|
16
|
+
* red. Beside this process `x db migrate` is applied BY it (`dev-db-migrate.ts`), embedded or not,
|
|
17
|
+
* and with `database.rowSecurity` as `x_migrator` under a hold (`dev-db-migrator-hold.ts`).
|
|
19
18
|
*/
|
|
20
19
|
export const SCHEMA_AHEAD_FIX = 'x db gen "describe the change" && x db migrate';
|
|
21
20
|
|
|
22
|
-
/** Where this process cannot apply the pass itself: the embedded database, to the command alone. */
|
|
23
|
-
export const SCHEMA_AHEAD_FIX_ALONE = `x db gen "describe the change" && ${MIGRATE_ALONE_FIX}`;
|
|
24
|
-
|
|
25
|
-
/** Whether `x db migrate` works while this `x dev` runs: any external database, or a pass it takes. */
|
|
26
|
-
export async function migratesBesideDev(root: string): Promise<boolean> {
|
|
27
|
-
return resolveServices(root, Bun.env).db.mode !== 'embedded' || (await devCanMigrate(root));
|
|
28
|
-
}
|
|
29
|
-
|
|
30
21
|
/** What `ledgerFindings` asks — the seam a test hands rows through. */
|
|
31
22
|
export interface LedgerReads {
|
|
32
23
|
readonly migrations: (root: string) => Promise<readonly Migration[]>;
|
|
@@ -62,7 +53,6 @@ const READS: LedgerReads = {
|
|
|
62
53
|
*/
|
|
63
54
|
export async function ledgerFindings(
|
|
64
55
|
root: string,
|
|
65
|
-
beside: (root: string) => Promise<boolean> = migratesBesideDev,
|
|
66
56
|
reads: LedgerReads = READS,
|
|
67
57
|
): Promise<readonly Finding[]> {
|
|
68
58
|
const migrations = await reads.migrations(root);
|
|
@@ -72,10 +62,9 @@ export async function ledgerFindings(
|
|
|
72
62
|
const missing = migrations.map((migration) => migration.id).filter((id) => !applied.has(id));
|
|
73
63
|
const findings: Finding[] = [];
|
|
74
64
|
if (missing.length > 0) {
|
|
75
|
-
|
|
76
|
-
new AppMigrationsUnappliedError({ missing, ledger: ledger !== undefined }),
|
|
65
|
+
findings.push(
|
|
66
|
+
findingFrom(new AppMigrationsUnappliedError({ missing, ledger: ledger !== undefined })),
|
|
77
67
|
);
|
|
78
|
-
findings.push((await beside(root)) ? behind : { ...behind, fix: MIGRATE_ALONE_FIX });
|
|
79
68
|
}
|
|
80
69
|
try {
|
|
81
70
|
refuseEdited(ledger ?? [], migrations);
|
|
@@ -109,23 +98,17 @@ function marked(findings: readonly Finding[]): readonly Finding[] {
|
|
|
109
98
|
export async function schemaAheadFindings(
|
|
110
99
|
root: string,
|
|
111
100
|
check: (root: string) => Promise<readonly Finding[]> = checkSourceDrift,
|
|
112
|
-
|
|
113
|
-
ledger: (
|
|
114
|
-
root: string,
|
|
115
|
-
beside: (root: string) => Promise<boolean>,
|
|
116
|
-
) => Promise<readonly Finding[]> = ledgerFindings,
|
|
101
|
+
ledger: (root: string) => Promise<readonly Finding[]> = ledgerFindings,
|
|
117
102
|
): Promise<readonly Finding[]> {
|
|
118
103
|
try {
|
|
119
104
|
const drifted = await check(root);
|
|
120
|
-
const fix =
|
|
121
|
-
drifted.length === 0 || (await beside(root)) ? SCHEMA_AHEAD_FIX : SCHEMA_AHEAD_FIX_ALONE;
|
|
122
105
|
return marked([
|
|
123
106
|
...drifted.map((finding) => ({
|
|
124
107
|
...finding,
|
|
125
108
|
cause: `entities are ahead of the migrations: ${finding.cause}`,
|
|
126
|
-
fix,
|
|
109
|
+
fix: SCHEMA_AHEAD_FIX,
|
|
127
110
|
})),
|
|
128
|
-
...(await ledger(root
|
|
111
|
+
...(await ledger(root)),
|
|
129
112
|
]);
|
|
130
113
|
} catch (error) {
|
|
131
114
|
return marked([findingFrom(error)]);
|
|
@@ -14,6 +14,7 @@ export const CLI_BOUNDARY_ERROR_CODES = [
|
|
|
14
14
|
'X_BOUNDARY_PACKAGE_TO_APP',
|
|
15
15
|
'X_BOUNDARY_ADAPTER_IMPORT',
|
|
16
16
|
'X_BOUNDARY_LOADER_IMPORT',
|
|
17
|
+
'X_BOUNDARY_DEV_IMPORT',
|
|
17
18
|
] as const;
|
|
18
19
|
|
|
19
20
|
export type CliBoundaryErrorCode = (typeof CLI_BOUNDARY_ERROR_CODES)[number];
|
|
@@ -29,4 +30,5 @@ export const CLI_BOUNDARY_ERROR_TITLES: Readonly<Record<CliBoundaryErrorCode, st
|
|
|
29
30
|
X_BOUNDARY_PACKAGE_TO_APP: 'packages/ imported apps/ at runtime',
|
|
30
31
|
X_BOUNDARY_ADAPTER_IMPORT: 'an app module imports an adapter installer',
|
|
31
32
|
X_BOUNDARY_LOADER_IMPORT: 'an app module imports a registration loader',
|
|
33
|
+
X_BOUNDARY_DEV_IMPORT: 'a module a role loads imports a development entry',
|
|
32
34
|
};
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
// What importing a set of modules EVALUATES, walked breadth first with the path to each module
|
|
2
|
+
// kept — so a finding about a module deep in the graph can name how it was reached. Two callers:
|
|
3
|
+
// the load's explanation of an import that failed inside a package (`app-load-import-chain.ts`)
|
|
4
|
+
// and the gate's check of what a role loads (`app-dev-imports.ts`). Never in a healthy boot.
|
|
5
|
+
|
|
6
|
+
import { importedSpecifiers, resolveImport } from './module-imports';
|
|
7
|
+
|
|
8
|
+
/** One static import, as the module at `from` spells it. `target` resolves it when it is asked. */
|
|
9
|
+
export interface EvaluatedImport {
|
|
10
|
+
readonly from: string;
|
|
11
|
+
readonly specifier: string;
|
|
12
|
+
target(): string | undefined;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/** `follow` walks the import's target, `skip` leaves it, `stop` ends the walk with it as the end. */
|
|
16
|
+
export type WalkVerdict = 'follow' | 'skip' | 'stop';
|
|
17
|
+
|
|
18
|
+
/** A module on a chain, and how the one before it spelled it — absent on the start. */
|
|
19
|
+
export interface ChainStep {
|
|
20
|
+
readonly path: string;
|
|
21
|
+
readonly specifier?: string;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface EvaluatedWalk {
|
|
25
|
+
/** Start first, `path` last: the shortest way there. Empty for a module the walk never reached. */
|
|
26
|
+
chainTo(path: string): readonly ChainStep[];
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export interface EvaluatedGraph {
|
|
30
|
+
walk(
|
|
31
|
+
starts: readonly string[],
|
|
32
|
+
judge: (edge: EvaluatedImport) => WalkVerdict,
|
|
33
|
+
): Promise<EvaluatedWalk>;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** What names an import at all: a dataset or a stylesheet is a target, and never read as source. */
|
|
37
|
+
const CODE = /\.[cm]?[jt]sx?$/;
|
|
38
|
+
|
|
39
|
+
/** One graph, however many walks: a module is read and parsed once, whoever reaches it. */
|
|
40
|
+
export function createEvaluatedGraph(): EvaluatedGraph {
|
|
41
|
+
const edges = new Map<string, readonly EvaluatedImport[]>();
|
|
42
|
+
|
|
43
|
+
async function edgesOf(path: string): Promise<readonly EvaluatedImport[]> {
|
|
44
|
+
const known = edges.get(path);
|
|
45
|
+
if (known !== undefined) return known;
|
|
46
|
+
if (!CODE.test(path)) return [];
|
|
47
|
+
// Unreadable (a builtin, an asset Bun resolves elsewhere): no edge, as an unparseable file has.
|
|
48
|
+
const source = await Bun.file(path)
|
|
49
|
+
.text()
|
|
50
|
+
.catch(() => '');
|
|
51
|
+
const found = importedSpecifiers(path, source, 'evaluated').map(
|
|
52
|
+
(specifier): EvaluatedImport => {
|
|
53
|
+
let resolved: { readonly path: string | undefined } | undefined;
|
|
54
|
+
return {
|
|
55
|
+
from: path,
|
|
56
|
+
specifier,
|
|
57
|
+
target() {
|
|
58
|
+
resolved ??= { path: resolveImport(specifier, path) };
|
|
59
|
+
return resolved.path;
|
|
60
|
+
},
|
|
61
|
+
};
|
|
62
|
+
},
|
|
63
|
+
);
|
|
64
|
+
edges.set(path, found);
|
|
65
|
+
return found;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return {
|
|
69
|
+
async walk(starts, judge) {
|
|
70
|
+
const via = new Map<string, EvaluatedImport | undefined>(
|
|
71
|
+
starts.map((start): [string, undefined] => [start, undefined]),
|
|
72
|
+
);
|
|
73
|
+
const reached = [...via.keys()];
|
|
74
|
+
walking: for (const path of reached) {
|
|
75
|
+
for (const edge of await edgesOf(path)) {
|
|
76
|
+
const verdict = judge(edge);
|
|
77
|
+
if (verdict === 'skip') continue;
|
|
78
|
+
const target = edge.target();
|
|
79
|
+
if (target !== undefined && !via.has(target)) {
|
|
80
|
+
via.set(target, edge);
|
|
81
|
+
reached.push(target);
|
|
82
|
+
}
|
|
83
|
+
if (verdict === 'stop') break walking;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return {
|
|
87
|
+
chainTo(path) {
|
|
88
|
+
if (!via.has(path)) return [];
|
|
89
|
+
const chain: ChainStep[] = [];
|
|
90
|
+
for (let at: string | undefined = path; at !== undefined; ) {
|
|
91
|
+
const edge: EvaluatedImport | undefined = via.get(at);
|
|
92
|
+
chain.push({
|
|
93
|
+
path: at,
|
|
94
|
+
...(edge === undefined ? {} : { specifier: edge.specifier }),
|
|
95
|
+
});
|
|
96
|
+
at = edge?.from;
|
|
97
|
+
}
|
|
98
|
+
return chain.reverse();
|
|
99
|
+
},
|
|
100
|
+
};
|
|
101
|
+
},
|
|
102
|
+
};
|
|
103
|
+
}
|
|
@@ -4,13 +4,16 @@
|
|
|
4
4
|
// with `x i18n add <locale>`, the one command that starts a catalog holding every existing key.
|
|
5
5
|
|
|
6
6
|
import { renderFixShellArg } from '@ultimat3/core';
|
|
7
|
-
import { type Catalog, loadCatalog } from '@ultimat3/i18n';
|
|
7
|
+
import { type Catalog, loadCatalog, partitionCatalog } from '@ultimat3/i18n';
|
|
8
8
|
import { loadAppCatalogs } from '@ultimat3/i18n/app-catalogs';
|
|
9
|
+
import type { CatalogLayout } from './catalog-layout';
|
|
10
|
+
import { readCatalogLayout } from './catalog-layout';
|
|
9
11
|
import { BadFlagError } from './errors';
|
|
10
12
|
import { resolveDefaultLocale, seedCatalog, serializeCatalog } from './i18n-audit';
|
|
11
13
|
import { catalogLocales } from './i18n-index';
|
|
12
14
|
import type { GeneratedFile } from './templates';
|
|
13
15
|
import { CATALOG_ROOT, catalogPath } from './templates';
|
|
16
|
+
import { catalogDir } from './templates/locales';
|
|
14
17
|
|
|
15
18
|
/** The locale a `merge: 'json'` file is the catalog of, or `undefined` for any other file. */
|
|
16
19
|
const localeOf = (file: GeneratedFile): string | undefined => {
|
|
@@ -69,13 +72,33 @@ export async function localiseCatalogs(
|
|
|
69
72
|
});
|
|
70
73
|
}
|
|
71
74
|
}
|
|
72
|
-
|
|
75
|
+
const localised = files.map((file) => {
|
|
73
76
|
const locale = localeOf(file);
|
|
74
77
|
if (file.merge !== 'json' || locale === undefined || locale === fallback) return file;
|
|
75
78
|
if (fallback === undefined) return file;
|
|
76
79
|
const generated: unknown = JSON.parse(file.contents);
|
|
77
80
|
return { ...file, contents: serializeCatalog(seedCatalog(loadCatalog(generated))) };
|
|
78
81
|
});
|
|
82
|
+
const layout = await readCatalogLayout(root);
|
|
83
|
+
return localised.flatMap((file) => intoLayout(file, layout));
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* A template's `catalogs/<locale>.json` landed where the app keeps that locale: as is for a flat
|
|
88
|
+
* one, and for a split one as one `merge: 'json'` file per namespace — each key in the existing
|
|
89
|
+
* file of its longest prefix, else in its namespace's own, created. Written as `<locale>.json`
|
|
90
|
+
* beside the directory, it would be `X_CATALOG_LAYOUT_MIXED` on the next read.
|
|
91
|
+
*/
|
|
92
|
+
function intoLayout(file: GeneratedFile, layout: CatalogLayout): readonly GeneratedFile[] {
|
|
93
|
+
const locale = localeOf(file);
|
|
94
|
+
const entry = locale === undefined ? undefined : layout[locale];
|
|
95
|
+
if (file.merge !== 'json' || locale === undefined || entry?.form !== 'split') return [file];
|
|
96
|
+
const parts = partitionCatalog(loadCatalog(JSON.parse(file.contents)), entry.files);
|
|
97
|
+
return [...parts].map(([name, part]) => ({
|
|
98
|
+
...file,
|
|
99
|
+
path: `${catalogDir(locale)}/${name}`,
|
|
100
|
+
contents: serializeCatalog(part),
|
|
101
|
+
}));
|
|
79
102
|
}
|
|
80
103
|
|
|
81
104
|
/**
|
|
@@ -26,11 +26,16 @@ export interface FollowUps {
|
|
|
26
26
|
readonly findings: readonly Finding[];
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
/**
|
|
29
|
+
/**
|
|
30
|
+
* The locale each written catalog file is for: a dry run's catalogs are not on the disk yet. A
|
|
31
|
+
* flat `<locale>.json`, or any namespace file under a split locale's `<locale>/`.
|
|
32
|
+
*/
|
|
30
33
|
const writtenLocales = (written: readonly string[]): readonly string[] =>
|
|
31
34
|
written.flatMap((path) => {
|
|
32
35
|
const stem = path.startsWith(`${CATALOG_ROOT}/`) ? path.slice(CATALOG_ROOT.length + 1) : '';
|
|
33
|
-
|
|
36
|
+
if (!stem.endsWith('.json')) return [];
|
|
37
|
+
const slash = stem.indexOf('/');
|
|
38
|
+
return [slash === -1 ? stem.slice(0, -'.json'.length) : stem.slice(0, slash)];
|
|
34
39
|
});
|
|
35
40
|
|
|
36
41
|
export async function followUpEdits(
|
|
@@ -55,7 +60,7 @@ export async function followUpEdits(
|
|
|
55
60
|
// A catalog on disk and a locale the app can select are two facts — see `syncI18nIndex`.
|
|
56
61
|
const indexSync =
|
|
57
62
|
written.length > 0
|
|
58
|
-
? await syncI18nIndex(root, disk, writtenLocales(written))
|
|
63
|
+
? await syncI18nIndex(root, disk, [...new Set(writtenLocales(written))], written)
|
|
59
64
|
: { registered: true, findings: [] };
|
|
60
65
|
return {
|
|
61
66
|
edited: [
|