@ultimat3/cli 31.22.3 → 31.24.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 +4 -3
- package/package.json +29 -29
- package/src/cmd-db-recount.ts +81 -24
- package/src/cmd-db-spec.ts +9 -1
- package/src/cmd-db.ts +1 -0
- package/src/cmd-doctor.ts +7 -1
- package/src/db-generate.ts +14 -3
- package/src/doctor-guards.ts +5 -3
- package/src/doctor-redundant-indexes.ts +76 -0
- package/src/fix-sequence.ts +0 -1
- package/src/messages.ts +3 -0
- package/src/redundant-indexes.ts +101 -0
- package/src/retained-assets-boot.ts +38 -5
- package/src/retained-assets-warned.ts +76 -0
- package/src/role-start.ts +13 -0
- package/src/runtime-boot-warnings.ts +65 -0
- package/src/runtime-cache.ts +14 -8
- package/src/schema-drift.ts +5 -2
- package/src/serve-boot-warnings.ts +9 -8
- package/src/serve.ts +4 -1
- package/src/templates/guard-error-declared.ts +48 -11
- package/src/templates/guard-repo-unbounded.ts +29 -13
- package/src/templates/scaffold-guards.ts +26 -3
- package/wiki/Actions.md +1 -0
- package/wiki/CLI-Reference.md +4 -1
- package/wiki/Entities-And-Migrations.md +6 -2
- package/wiki/Jobs-And-Workflows.md +3 -1
- package/wiki/Migrations-And-Backfills.md +1 -1
- package/wiki/Observability.md +4 -1
- package/wiki/Outbound-HTTP.md +40 -0
- package/wiki/Policies-And-Authz.md +52 -20
- package/wiki/Realtime.md +1 -0
- package/wiki/Stability.md +1 -1
- package/wiki/Testing.md +1 -0
- package/wiki/Upgrading.md +2 -0
|
@@ -3,7 +3,13 @@
|
|
|
3
3
|
// binds, so before `/readyz` can say ready — and hand back the reader the asset routes miss into.
|
|
4
4
|
|
|
5
5
|
import type { AppConfig, AssetsRetainConfig } from '@ultimat3/core';
|
|
6
|
-
import {
|
|
6
|
+
import {
|
|
7
|
+
bootWarning,
|
|
8
|
+
ConfigInvalidError,
|
|
9
|
+
logger,
|
|
10
|
+
renderFixLiteral,
|
|
11
|
+
UltimateError,
|
|
12
|
+
} from '@ultimat3/core';
|
|
7
13
|
import type { Storage } from '@ultimat3/storage';
|
|
8
14
|
import type { IslandBundle } from './island-bundle';
|
|
9
15
|
import type { BuildAsset, PublishReport, RetainLog } from './retained-assets';
|
|
@@ -11,6 +17,7 @@ import { publishBuildAssets } from './retained-assets';
|
|
|
11
17
|
import { retainedPrefix } from './retained-assets-layout';
|
|
12
18
|
import type { RetainedAssets } from './retained-assets-read';
|
|
13
19
|
import { retainedAssets } from './retained-assets-read';
|
|
20
|
+
import { retainedBuildOnce } from './runtime-boot-warnings';
|
|
14
21
|
import { siteAssetTable } from './site-assets';
|
|
15
22
|
import type { StyleBundle } from './style-bundle';
|
|
16
23
|
import type { FrameworkScript } from './worker-bundle';
|
|
@@ -80,13 +87,39 @@ export class AssetRetainUndeclaredError extends UltimateError {
|
|
|
80
87
|
/** Where a boot has no rolling deploy to survive: a laptop, a test run. */
|
|
81
88
|
const LOCAL_ENVIRONMENTS: ReadonlySet<string> = new Set(['development', 'test']);
|
|
82
89
|
|
|
83
|
-
|
|
90
|
+
/** This file is the web role's boot alone (`serve-web.ts`): the role half of the warned key. */
|
|
91
|
+
const WEB_ROLE = 'web';
|
|
92
|
+
/**
|
|
93
|
+
* Once per build id for the web role, not per boot (`retainedBuildOnce`). With no `app.config.ts`
|
|
94
|
+
* there is no app name to scope the marker by, so that boot says it every time.
|
|
95
|
+
*/
|
|
96
|
+
async function warnUndeclared(input: RetainBootInput): Promise<void> {
|
|
84
97
|
if (LOCAL_ENVIRONMENTS.has(input.environment) || buildAssetsOf(input).length === 0) return;
|
|
85
98
|
const warning = new AssetRetainUndeclaredError({
|
|
86
99
|
environment: input.environment,
|
|
87
100
|
disks: input.storage.diskNames,
|
|
88
101
|
});
|
|
89
|
-
|
|
102
|
+
await bootWarning(
|
|
103
|
+
{
|
|
104
|
+
code: warning.code,
|
|
105
|
+
roles: [WEB_ROLE],
|
|
106
|
+
once: input.config === undefined ? undefined : 'build',
|
|
107
|
+
message: warning.format(),
|
|
108
|
+
fields: warning.meta,
|
|
109
|
+
},
|
|
110
|
+
{
|
|
111
|
+
roles: [WEB_ROLE],
|
|
112
|
+
log: input.log ?? logger,
|
|
113
|
+
buildOnce:
|
|
114
|
+
input.config === undefined
|
|
115
|
+
? undefined
|
|
116
|
+
: retainedBuildOnce({
|
|
117
|
+
storage: input.storage,
|
|
118
|
+
prefix: retainedPrefix(input.config.name, input.environment),
|
|
119
|
+
buildId: input.buildId,
|
|
120
|
+
}),
|
|
121
|
+
},
|
|
122
|
+
);
|
|
90
123
|
}
|
|
91
124
|
|
|
92
125
|
export interface RetainBootInput extends BuiltSurface {
|
|
@@ -109,7 +142,7 @@ export interface RetainedBoot {
|
|
|
109
142
|
|
|
110
143
|
/**
|
|
111
144
|
* `undefined` when the app declared no window — and, outside development and test, one
|
|
112
|
-
* `X_ASSET_RETAIN_UNDECLARED` warning naming the edit (`warnUndeclared`). A misnamed disk refuses
|
|
145
|
+
* `X_ASSET_RETAIN_UNDECLARED` warning per build naming the edit (`warnUndeclared`). A misnamed disk refuses
|
|
113
146
|
* the boot: it is the app's config, wrong, and every pod of the deploy would otherwise run without
|
|
114
147
|
* the window it asked for.
|
|
115
148
|
* A disk that refuses a write does NOT: `publishBuildAssets` logs it and the pod serves, reading
|
|
@@ -119,7 +152,7 @@ export interface RetainedBoot {
|
|
|
119
152
|
export async function retainBuildAssets(input: RetainBootInput): Promise<RetainedBoot | undefined> {
|
|
120
153
|
const retain = retainOf(input.config);
|
|
121
154
|
if (input.config === undefined || retain === undefined) {
|
|
122
|
-
warnUndeclared(input);
|
|
155
|
+
await warnUndeclared(input);
|
|
123
156
|
return undefined;
|
|
124
157
|
}
|
|
125
158
|
const names = input.storage.diskNames;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
// A boot warning said once per build id per role, not once per boot: a zero-byte marker on the
|
|
2
|
+
// disk the role's pods share remembers that some process of this build already said it. Fail
|
|
3
|
+
// open — a disk that refuses or stalls costs a duplicate line, never a lost one or a held boot.
|
|
4
|
+
|
|
5
|
+
import { finiteCount } from '@ultimat3/core';
|
|
6
|
+
import type { StorageDriver } from '@ultimat3/storage';
|
|
7
|
+
|
|
8
|
+
/** How long the marker may hold a boot: a warning never delays readiness past this. */
|
|
9
|
+
export const WARNED_MARKER_DEADLINE_MS = 2_000;
|
|
10
|
+
/** Markers kept per role, newest first: a rolling deploy's old build restarting stays quiet. */
|
|
11
|
+
export const WARNED_BUILDS_KEPT = 3;
|
|
12
|
+
|
|
13
|
+
export interface WarnOnceInput {
|
|
14
|
+
/** Resolved inside the fail-open guard: a storage that cannot name its disk still warns. */
|
|
15
|
+
readonly disk: () => StorageDriver;
|
|
16
|
+
/** The app-and-environment scope (`retainedPrefix`), so staging never silences production. */
|
|
17
|
+
readonly prefix: string;
|
|
18
|
+
readonly role: string;
|
|
19
|
+
readonly buildId: string;
|
|
20
|
+
/** Test seam; `WARNED_MARKER_DEADLINE_MS` otherwise. */
|
|
21
|
+
readonly deadlineMs?: number | undefined;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** `<prefix>/warned/<role>/` — beside the retained files, outside `org/`, so never served. */
|
|
25
|
+
export const warnedPrefix = (prefix: string, role: string): string =>
|
|
26
|
+
`${prefix}/warned/${encodeURIComponent(role)}/`;
|
|
27
|
+
|
|
28
|
+
const markerKey = (input: WarnOnceInput): string =>
|
|
29
|
+
`${warnedPrefix(input.prefix, input.role)}${encodeURIComponent(input.buildId)}`;
|
|
30
|
+
|
|
31
|
+
async function prune(input: WarnOnceInput, disk: StorageDriver): Promise<void> {
|
|
32
|
+
const own = markerKey(input);
|
|
33
|
+
const page = await disk.list({ prefix: warnedPrefix(input.prefix, input.role) });
|
|
34
|
+
// This build's marker is kept whatever the clock says (a disk's timestamps can tie); the rest
|
|
35
|
+
// newest first. One with no `lastModified` has no age to rank by: spared, never guessed old.
|
|
36
|
+
const others = page.rows.filter((row) => row.key !== own && row.lastModified !== undefined);
|
|
37
|
+
const stale = others
|
|
38
|
+
.sort((a, b) => (b.lastModified?.getTime() ?? 0) - (a.lastModified?.getTime() ?? 0))
|
|
39
|
+
.slice(WARNED_BUILDS_KEPT - 1);
|
|
40
|
+
for (const row of stale) await disk.delete(row.key);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** `true` when this process should say it: no marker, or the disk could not answer. */
|
|
44
|
+
async function claim(input: WarnOnceInput): Promise<boolean> {
|
|
45
|
+
// `async`, so a synchronous throw from `disk()` is a rejection the caller's guard catches.
|
|
46
|
+
const key = markerKey(input);
|
|
47
|
+
const disk = input.disk();
|
|
48
|
+
if (await disk.exists(key)) return false;
|
|
49
|
+
await disk.put(key, new Uint8Array(0), { contentType: 'application/octet-stream' });
|
|
50
|
+
await prune(input, disk);
|
|
51
|
+
return true;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Calls `warn` unless a process of this build and role already did. Two pods booting in the same
|
|
56
|
+
* instant may both say it — no shipped driver offers a create-if-absent put — which is the bound:
|
|
57
|
+
* once per build per simultaneous boot, never once per boot.
|
|
58
|
+
*/
|
|
59
|
+
export async function warnOncePerBuild(input: WarnOnceInput, warn: () => void): Promise<void> {
|
|
60
|
+
// Checked up front (`X_INVARIANT`): `setTimeout` fires a `NaN` at once, as `publishBuildAssets`.
|
|
61
|
+
const ms = finiteCount(
|
|
62
|
+
'warnOncePerBuild',
|
|
63
|
+
'deadlineMs',
|
|
64
|
+
input.deadlineMs ?? WARNED_MARKER_DEADLINE_MS,
|
|
65
|
+
1,
|
|
66
|
+
);
|
|
67
|
+
let timer: ReturnType<typeof setTimeout> | undefined;
|
|
68
|
+
const deadline = new Promise<'deadline'>((resolve) => {
|
|
69
|
+
timer = setTimeout(() => resolve('deadline'), ms);
|
|
70
|
+
});
|
|
71
|
+
// The marker is memory, not correctness: any failure of the disk says the warning instead.
|
|
72
|
+
const said = await Promise.race([claim(input).catch(() => true), deadline]).finally(() =>
|
|
73
|
+
clearTimeout(timer),
|
|
74
|
+
);
|
|
75
|
+
if (said !== false) warn();
|
|
76
|
+
}
|
package/src/role-start.ts
CHANGED
|
@@ -29,6 +29,7 @@ import {
|
|
|
29
29
|
registeredJobs,
|
|
30
30
|
} from '@ultimat3/jobs';
|
|
31
31
|
import type { SyncWs } from '@ultimat3/realtime/server';
|
|
32
|
+
import { loadAppConfig } from './app-config-load';
|
|
32
33
|
import { errorPageHook } from './error-pages';
|
|
33
34
|
import { BadFlagError, RuntimeDriverSplitError } from './errors';
|
|
34
35
|
import {
|
|
@@ -44,6 +45,7 @@ import type { RunningRoles, StartRolesOptions } from './role-start-types';
|
|
|
44
45
|
import { DEV_ROLES } from './role-start-types';
|
|
45
46
|
import { prepareSync, type RunningSync, syncReadsChanges } from './role-sync';
|
|
46
47
|
import { startWorkerWake } from './role-wake';
|
|
48
|
+
import { installRoleBootWarnings } from './runtime-boot-warnings';
|
|
47
49
|
import { devHooks } from './runtime-hooks';
|
|
48
50
|
import { workerOptionsFor } from './runtime-jobs';
|
|
49
51
|
import { reportUnservedQueues } from './runtime-jobs-unserved';
|
|
@@ -287,6 +289,17 @@ export async function startRoles(options: StartRolesOptions): Promise<RunningRol
|
|
|
287
289
|
// call and another's HTTP call spend one bucket in one table.
|
|
288
290
|
// A frame of its own over what `startServices` adopted, popped by its own undo — so stopping
|
|
289
291
|
// these roles takes back exactly this install, whatever else stacked over or under it.
|
|
292
|
+
// Once, before any role serves: which roles core's `bootWarning` concerns, and its per-build
|
|
293
|
+
// marker store (`runtime-boot-warnings.ts`). Released by the stop, like every frame here.
|
|
294
|
+
const config = options.root === undefined ? undefined : await loadAppConfig(options.root);
|
|
295
|
+
const releaseWarnings = installRoleBootWarnings({
|
|
296
|
+
roles: selected,
|
|
297
|
+
config,
|
|
298
|
+
storage: options.runtime.storage,
|
|
299
|
+
env: options.env,
|
|
300
|
+
buildId: options.buildId,
|
|
301
|
+
});
|
|
302
|
+
started.push(async () => releaseWarnings());
|
|
290
303
|
const limits = rateLimitStoreFor(options);
|
|
291
304
|
const restoreLimits = limits === undefined ? () => undefined : installRateLimitStore(limits);
|
|
292
305
|
started.push(async () => restoreLimits());
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
// The boot's half of core's `bootWarning`: the roles this process runs and the per-build memory —
|
|
2
|
+
// a zero-byte marker on the disk every pod of a deploy shares (`retained-assets-warned.ts`) —
|
|
3
|
+
// installed once by `startRoles`. The marker and storage modules load on the first `once: 'build'`
|
|
4
|
+
// claim, so a role that never says one evaluates neither.
|
|
5
|
+
|
|
6
|
+
import type { AppConfig, BuildOnceStore, Role } from '@ultimat3/core';
|
|
7
|
+
import { resolveEnvironment } from '@ultimat3/core';
|
|
8
|
+
import { installBootWarnings } from '@ultimat3/core/adapter';
|
|
9
|
+
import type { Storage } from '@ultimat3/storage';
|
|
10
|
+
import { retainedPrefix } from './retained-assets-layout';
|
|
11
|
+
|
|
12
|
+
/** The code whose marker predates the store: it keeps `<prefix>/warned/<role>/`. */
|
|
13
|
+
const RETAIN_UNDECLARED = 'X_ASSET_RETAIN_UNDECLARED';
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Core's `once: 'build'` memory over `warnOncePerBuild`. The retain warning keeps the marker it
|
|
17
|
+
* always had, `<prefix>/warned/<role>/`; any other code is `<role>~<code>`, its own directory, so
|
|
18
|
+
* neither silences nor prunes the other. The app's own disks win over the host's, as every
|
|
19
|
+
* framework route reads them (`servedStorage`).
|
|
20
|
+
*/
|
|
21
|
+
export function retainedBuildOnce(input: {
|
|
22
|
+
readonly storage: Storage;
|
|
23
|
+
readonly prefix: string;
|
|
24
|
+
readonly buildId: string;
|
|
25
|
+
}): BuildOnceStore {
|
|
26
|
+
return async (claim, say) => {
|
|
27
|
+
const [{ warnOncePerBuild }, { servedStorage }] = await Promise.all([
|
|
28
|
+
import('./retained-assets-warned'),
|
|
29
|
+
import('./runtime-storage'),
|
|
30
|
+
]);
|
|
31
|
+
const storage = servedStorage(input.storage);
|
|
32
|
+
await warnOncePerBuild(
|
|
33
|
+
{
|
|
34
|
+
disk: () => storage.disk(),
|
|
35
|
+
prefix: input.prefix,
|
|
36
|
+
role: claim.code === RETAIN_UNDECLARED ? claim.role : `${claim.role}~${claim.code}`,
|
|
37
|
+
buildId: input.buildId,
|
|
38
|
+
},
|
|
39
|
+
say,
|
|
40
|
+
);
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export interface RoleBootWarningsInput {
|
|
45
|
+
readonly roles: readonly Role[];
|
|
46
|
+
/** `undefined` with no `app.config.ts`: no app name to scope a marker by, so no build store. */
|
|
47
|
+
readonly config: Pick<AppConfig, 'name'> | undefined;
|
|
48
|
+
readonly storage: Storage;
|
|
49
|
+
readonly env: Readonly<Record<string, string | undefined>>;
|
|
50
|
+
readonly buildId: string;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** Installs the booting roles and, with an app config, the build store. Returns the release. */
|
|
54
|
+
export function installRoleBootWarnings(input: RoleBootWarningsInput): () => void {
|
|
55
|
+
if (input.config === undefined) return installBootWarnings({ roles: input.roles });
|
|
56
|
+
const environment = resolveEnvironment({ env: input.env, fallback: 'production' });
|
|
57
|
+
return installBootWarnings({
|
|
58
|
+
roles: input.roles,
|
|
59
|
+
buildOnce: retainedBuildOnce({
|
|
60
|
+
storage: input.storage,
|
|
61
|
+
prefix: retainedPrefix(input.config.name, environment),
|
|
62
|
+
buildId: input.buildId,
|
|
63
|
+
}),
|
|
64
|
+
});
|
|
65
|
+
}
|
package/src/runtime-cache.ts
CHANGED
|
@@ -29,6 +29,7 @@ import type { AppConfig, CacheTierName } from '@ultimat3/core';
|
|
|
29
29
|
import {
|
|
30
30
|
backoffDelay,
|
|
31
31
|
defineConfig,
|
|
32
|
+
failureStreak,
|
|
32
33
|
finiteCount,
|
|
33
34
|
isOutageMilestone,
|
|
34
35
|
logger,
|
|
@@ -290,15 +291,23 @@ export function startCacheTiers(options: CacheTiersOptions): () => Promise<void>
|
|
|
290
291
|
// delete too; this is the sender's half, and does not depend on hearing its own publish.)
|
|
291
292
|
await purgeEdgeAgain(batch);
|
|
292
293
|
};
|
|
294
|
+
// A flapping bus refuses the settle of every reconnect: one line per cause, one when it lands.
|
|
295
|
+
const settleFailures = failureStreak({
|
|
296
|
+
event: 'cache.broadcast.deferred-failed',
|
|
297
|
+
recoveredEvent: 'cache.broadcast.deferred-recovered',
|
|
298
|
+
level: 'warn',
|
|
299
|
+
});
|
|
293
300
|
// ONE settle at a time. It is asked for by every reconnect and after every accepted publish,
|
|
294
301
|
// and two that overlapped both published the same batch (and the same flush-all). A call that
|
|
295
302
|
// arrives mid-run asks for one more pass instead, which finds whatever the run did not carry.
|
|
303
|
+
// The outcome is reported HERE, once per run: a joiner that reported it too counted one refused
|
|
304
|
+
// settle once per reconnect that joined it. Never rejects — what is unpublished stays owed.
|
|
296
305
|
let settling: Promise<void> | undefined;
|
|
297
306
|
let again = false;
|
|
298
|
-
const
|
|
307
|
+
const settleQuietly = (): void => {
|
|
299
308
|
if (settling !== undefined) {
|
|
300
309
|
again = true;
|
|
301
|
-
return
|
|
310
|
+
return;
|
|
302
311
|
}
|
|
303
312
|
settling = (async (): Promise<void> => {
|
|
304
313
|
try {
|
|
@@ -306,17 +315,14 @@ export function startCacheTiers(options: CacheTiersOptions): () => Promise<void>
|
|
|
306
315
|
again = false;
|
|
307
316
|
await settleOnce();
|
|
308
317
|
} while (again);
|
|
318
|
+
settleFailures.passed();
|
|
319
|
+
} catch (error) {
|
|
320
|
+
settleFailures.failed(error);
|
|
309
321
|
} finally {
|
|
310
322
|
again = false;
|
|
311
323
|
settling = undefined;
|
|
312
324
|
}
|
|
313
325
|
})();
|
|
314
|
-
return settling;
|
|
315
|
-
};
|
|
316
|
-
const settleQuietly = (): void => {
|
|
317
|
-
void settle().catch((error: unknown) => {
|
|
318
|
-
logger.warn('cache.broadcast.deferred-failed', { error: broadcastErrorText(error) });
|
|
319
|
-
});
|
|
320
326
|
};
|
|
321
327
|
|
|
322
328
|
registerInvalidationBroadcast(async (wireTags) => {
|
package/src/schema-drift.ts
CHANGED
|
@@ -22,7 +22,7 @@ import {
|
|
|
22
22
|
snapshotOf,
|
|
23
23
|
unrenderedOf,
|
|
24
24
|
} from '@ultimat3/db';
|
|
25
|
-
import {
|
|
25
|
+
import { registeredEntities } from '@ultimat3/entity';
|
|
26
26
|
import { loadApp } from './app-load';
|
|
27
27
|
import { checkSourceDrift, DB_PACKAGE } from './drift';
|
|
28
28
|
import {
|
|
@@ -32,6 +32,7 @@ import {
|
|
|
32
32
|
} from './drift-replica-identity';
|
|
33
33
|
import { MIGRATIONS_DIR, readMigrations } from './migrations';
|
|
34
34
|
import type { Finding } from './output';
|
|
35
|
+
import { settledDescriptions } from './redundant-indexes';
|
|
35
36
|
import { appRowSecurity, type RowSecurityWanted, rowSecurityFindings } from './row-security-wanted';
|
|
36
37
|
import { diffDeclaredSchema, type SchemaDifference } from './schema-diff';
|
|
37
38
|
|
|
@@ -53,7 +54,9 @@ export type DeclaredEntities = (
|
|
|
53
54
|
export const appEntities: DeclaredEntities = async (root) => {
|
|
54
55
|
const app = await loadApp(root);
|
|
55
56
|
if (app.findings.length > 0) return undefined;
|
|
56
|
-
|
|
57
|
+
// What `x db gen` diffed (`settledDescriptions`): a covered index `--drop-redundant` dropped is
|
|
58
|
+
// still described by its entity, and reading the raw registry would report it as unmigrated.
|
|
59
|
+
return settledDescriptions(registeredEntities(), await readMigrations(root), false);
|
|
57
60
|
};
|
|
58
61
|
|
|
59
62
|
/**
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
// The roles each boot warning concerns, in one table, and the step that runs the
|
|
2
|
-
// the booting role alone.
|
|
3
|
-
//
|
|
1
|
+
// The roles each FRAMEWORK boot warning concerns, in one table, and the step that runs the
|
|
2
|
+
// post-load ones for the booting role alone. The role rule is core's `bootWarning`'s
|
|
3
|
+
// (`bootRolesConcerned`) — one answer for these and for an app's own role-scoped boot line.
|
|
4
4
|
|
|
5
5
|
import type { Role } from '@ultimat3/core';
|
|
6
|
+
import { bootRolesConcerned } from '@ultimat3/core';
|
|
6
7
|
|
|
7
8
|
/** Every warning a container boot can say. A new one does not compile until it names its roles. */
|
|
8
9
|
export type BootWarning =
|
|
@@ -32,13 +33,13 @@ export const BOOT_WARNINGS: ReadonlyMap<BootWarning, readonly Role[]> = new Map(
|
|
|
32
33
|
Object.entries(DECLARED) as [BootWarning, readonly Role[]][],
|
|
33
34
|
);
|
|
34
35
|
|
|
35
|
-
/** Whether `warning` is one `role` can act on. An unknown warning concerns nobody. */
|
|
36
|
-
export const bootWarningConcerns = (warning: BootWarning, role: Role): boolean =>
|
|
37
|
-
BOOT_WARNINGS.get(warning)?.includes(role) ?? false;
|
|
38
|
-
|
|
39
36
|
/** Whether any of `roles` — `x dev` runs several in one process — can act on `warning`. */
|
|
40
37
|
export const bootWarningConcernsAny = (warning: BootWarning, roles: readonly Role[]): boolean =>
|
|
41
|
-
|
|
38
|
+
bootRolesConcerned(BOOT_WARNINGS.get(warning) ?? [], roles);
|
|
39
|
+
|
|
40
|
+
/** Whether `warning` is one `role` can act on. An unknown warning concerns nobody. */
|
|
41
|
+
export const bootWarningConcerns = (warning: BootWarning, role: Role): boolean =>
|
|
42
|
+
bootWarningConcernsAny(warning, [role]);
|
|
42
43
|
|
|
43
44
|
/** The post-load probes: each logs its own line and answers whether it had anything to say. */
|
|
44
45
|
export interface BootWarningProbes {
|
package/src/serve.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
// `dev: true`. The only production-shaped decisions live here: which role, which port, and which
|
|
5
5
|
// interface — every one by default, because a container is reached through a port mapping.
|
|
6
6
|
|
|
7
|
-
import { assertNoDevSecretsOutsideLocal, logger } from '@ultimat3/core';
|
|
7
|
+
import { assertNoDevSecretsOutsideLocal, frameworkVersion, logger } from '@ultimat3/core';
|
|
8
8
|
import { assertNoSchemaDrift, checkDrift, migrate } from '@ultimat3/db';
|
|
9
9
|
import { loadAppRuntime } from './app-runtime';
|
|
10
10
|
import { acceptCreatedTables } from './db-accept-created';
|
|
@@ -218,6 +218,9 @@ export async function runRole(input: ServeOptions): Promise<StartedApp> {
|
|
|
218
218
|
// `nats(connecting)` on a role that only publishes is a served pod with the bus down;
|
|
219
219
|
// `ultimate bus` is logged with `nats(up)` when the dial lands.
|
|
220
220
|
bus: app.bus,
|
|
221
|
+
// `buildId` is the app's; this is which framework release booted it — the same fact the
|
|
222
|
+
// monitor's `framework_version` tag and `target_info`'s label carry.
|
|
223
|
+
frameworkVersion: frameworkVersion(),
|
|
221
224
|
});
|
|
222
225
|
await hold();
|
|
223
226
|
return app;
|
|
@@ -113,12 +113,43 @@ const literalCodeIn = (text: string, open: number): boolean => {
|
|
|
113
113
|
return false;
|
|
114
114
|
};
|
|
115
115
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
116
|
+
/** The first literal code in a span: the one a finding's fix declares. */
|
|
117
|
+
const CODE_LITERAL = /\\b(?:code|'code'|"code")\\s*:\\s*['"\`](X(?:_[A-Z0-9]+)+)['"\`]/;
|
|
118
|
+
const CLASS_NAME = /\\bclass\\s+([A-Za-z_$][\\w$]*)\\s*$/;
|
|
119
|
+
/** Where the next declaration starts, so a span never reads the following class's code. */
|
|
120
|
+
const NEXT_DECLARATION = /\\b(?:class|new)\\s/g;
|
|
121
|
+
|
|
122
|
+
const codeIn = (text: string, from: number): string | undefined => {
|
|
123
|
+
NEXT_DECLARATION.lastIndex = from + 1;
|
|
124
|
+
const next = NEXT_DECLARATION.exec(text);
|
|
125
|
+
return CODE_LITERAL.exec(text.slice(from, next === null ? text.length : next.index))?.[1];
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
/** The code's own words, the binding a class-less finding's fix declares: X_POST_GONE → PostGone. */
|
|
129
|
+
const bindingOf = (code: string): string =>
|
|
130
|
+
code
|
|
131
|
+
.slice(2)
|
|
132
|
+
.split('_')
|
|
133
|
+
.map((word) => word.charAt(0) + word.slice(1).toLowerCase())
|
|
134
|
+
.join('');
|
|
135
|
+
|
|
136
|
+
/** What a finding can name of the class it replaces; a placeholder for whatever it cannot read. */
|
|
137
|
+
interface Declared {
|
|
138
|
+
readonly name?: string | undefined;
|
|
139
|
+
readonly code?: string | undefined;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
const finding = (file: SourceFile, line: number, what: string, declared: Declared): Finding => {
|
|
143
|
+
const name =
|
|
144
|
+
declared.name ?? (declared.code === undefined ? '<ErrorName>' : bindingOf(declared.code));
|
|
145
|
+
const code = \`'\${declared.code ?? 'X_<CODE>'}'\`;
|
|
146
|
+
return {
|
|
147
|
+
code: CODE,
|
|
148
|
+
cause: \`\${file.path}:\${line} \${what} — the title, the HTTP status and the class are then declared apart, and a code with no status answers 500 and hides its cause\`,
|
|
149
|
+
fix: \`rewrite it in \${file.path} as one call per class, from @ultimat3/core/page: export const \${name} = defineError({ code: \${code}, title, status, cause, fix, problemMeta: ['<meta key>'] }) — it replaces the class and its registerErrorStatus / registerProblemMeta rows (offSocket: true instead of status for a code no response carries; publicCause: true for a 5xx whose cause a caller may read; drop problemMeta when its meta stays operator-only), then: x verify\`,
|
|
150
|
+
at: file.path,
|
|
151
|
+
};
|
|
152
|
+
};
|
|
122
153
|
|
|
123
154
|
const barrelFinding = (file: SourceFile, line: number): Finding => ({
|
|
124
155
|
code: CODE,
|
|
@@ -150,24 +181,30 @@ export function undeclaredErrors(files: readonly SourceFile[]): readonly Finding
|
|
|
150
181
|
for (const file of files) {
|
|
151
182
|
const text = blank(file.source);
|
|
152
183
|
const names = nameSource(classNames(text));
|
|
153
|
-
const push = (index: number, what: string): void => {
|
|
184
|
+
const push = (index: number, what: string, declared: Declared): void => {
|
|
154
185
|
const line = lineOf(text, index);
|
|
155
|
-
found.push({ path: file.path, line, finding: finding(file, line, what) });
|
|
186
|
+
found.push({ path: file.path, line, finding: finding(file, line, what, declared) });
|
|
156
187
|
};
|
|
157
188
|
for (const line of barrelDefineErrorLines(text)) {
|
|
158
189
|
found.push({ path: file.path, line, finding: barrelFinding(file, line) });
|
|
159
190
|
}
|
|
160
191
|
for (const match of text.matchAll(new RegExp(\`\\\\bextends\\\\s+(?:\${names})\\\\b\`, 'g'))) {
|
|
161
|
-
|
|
192
|
+
const name = CLASS_NAME.exec(text.slice(0, match.index))?.[1];
|
|
193
|
+
push(match.index, 'subclasses UltimateError by hand', {
|
|
194
|
+
name,
|
|
195
|
+
code: codeIn(text, match.index),
|
|
196
|
+
});
|
|
162
197
|
}
|
|
163
198
|
for (const match of text.matchAll(new RegExp(\`\\\\bnew\\\\s+(?:\${names})\\\\s*\\\\(\\\\s*\`, 'g'))) {
|
|
164
199
|
const at = match.index + match[0].length;
|
|
165
200
|
// Anything but an object literal hides its code from this read: a value built elsewhere,
|
|
166
201
|
// Object.assign over a literal. A re-raise is written as a literal, with code: err.code.
|
|
167
202
|
if (text[at] !== '{')
|
|
168
|
-
push(match.index, 'builds new UltimateError from a value this guard cannot read');
|
|
203
|
+
push(match.index, 'builds new UltimateError from a value this guard cannot read', {});
|
|
169
204
|
else if (literalCodeIn(text, at))
|
|
170
|
-
push(match.index, 'builds new UltimateError with a literal code'
|
|
205
|
+
push(match.index, 'builds new UltimateError with a literal code', {
|
|
206
|
+
code: codeIn(text, at),
|
|
207
|
+
});
|
|
171
208
|
}
|
|
172
209
|
}
|
|
173
210
|
return found
|
|
@@ -1,17 +1,22 @@
|
|
|
1
|
-
// The `repo-unbounded` guard `x new` ships
|
|
2
|
-
// `.
|
|
3
|
-
//
|
|
1
|
+
// The `repo-unbounded` guard `x new` ships: a handle chain in a `repo.ts` ending in `.all()` with no
|
|
2
|
+
// `.limit(n)` answers the handle's default page and drops the cursor to the rest — neither every
|
|
3
|
+
// row nor a page the caller chose. Pairs with entity's `X_ENTITY_ALL_TRUNCATED` warning. A new app
|
|
4
|
+
// gets it FAILING the gate; `'warning'` renders the report-only form apps scaffolded earlier hold.
|
|
4
5
|
|
|
5
6
|
import { guardCode } from './guard';
|
|
6
7
|
import { repoUnboundedTest } from './guard-repo-unbounded-test';
|
|
7
8
|
import type { GeneratedFile } from './naming';
|
|
8
9
|
|
|
10
|
+
/** How the emitted guard reports: failing `boundaries`, or listing on it (`severity: 'warning'`). */
|
|
11
|
+
export type RepoUnboundedSeverity = 'error' | 'warning';
|
|
12
|
+
|
|
9
13
|
/** Derived from the guard's name, never a literal: an `X_*` literal here is a FRAMEWORK code. */
|
|
10
14
|
const NAME = 'repo-unbounded';
|
|
11
15
|
const CODE = guardCode(NAME);
|
|
12
16
|
|
|
13
|
-
const source =
|
|
14
|
-
|
|
17
|
+
const source = (
|
|
18
|
+
severity: RepoUnboundedSeverity,
|
|
19
|
+
): string => `// repo-unbounded: a repo.ts read says how many rows it wants, never a bare \`.all()\`.
|
|
15
20
|
// \`x verify\` discovers every file in \`guards/\` and runs its \`guard\` inside the \`boundaries\`
|
|
16
21
|
// step — nothing registers this file, so nothing can forget to. Delete it to drop the rule.
|
|
17
22
|
//
|
|
@@ -20,8 +25,11 @@ const source =
|
|
|
20
25
|
// only from a missing row. Read: a \`db.<table>…all()\` or \`tx.<table>…all()\` chain with no
|
|
21
26
|
// \`.limit(\`, \`.page(\`, \`.keyset(\` or \`.one(\` in it, in \`{apps,packages}/**/repo{,-*}.ts\`, never a
|
|
22
27
|
// test. Admitted: a \`// why:\` on the chain's first line or the line above it, naming the bound.
|
|
23
|
-
|
|
24
|
-
|
|
28
|
+
${
|
|
29
|
+
severity === 'warning'
|
|
30
|
+
? "// REPORT ONLY (`severity: 'warning'`): its findings list on `boundaries`, never fail it.\n"
|
|
31
|
+
: ''
|
|
32
|
+
}
|
|
25
33
|
import type { Finding, Guard } from '@ultimat3/cli';
|
|
26
34
|
|
|
27
35
|
/** The app owns the codes its own conventions raise — this one is named for the guard. */
|
|
@@ -179,9 +187,11 @@ export function unboundedReads(files: readonly RepoFile[]): readonly Finding[] {
|
|
|
179
187
|
|
|
180
188
|
export const guard: Guard = {
|
|
181
189
|
summary: 'a repo.ts read says how many rows it wants: no .all() without a .limit(n)',
|
|
182
|
-
|
|
183
|
-
severity
|
|
184
|
-
|
|
190
|
+
${
|
|
191
|
+
severity === 'warning'
|
|
192
|
+
? " // REPORT ONLY: findings are warnings on the `boundaries` step. Delete this line to enforce it.\n severity: 'warning',\n"
|
|
193
|
+
: ''
|
|
194
|
+
} async check(_root, sources) {
|
|
185
195
|
// The run's ONE read of these files: \`repo-raw-sql\` asks for the same glob, so they share it.
|
|
186
196
|
const repos = await sources.files('{apps,packages}/**/repo{,-*}.ts');
|
|
187
197
|
const read = repos.filter((file) => !file.path.endsWith('.test.ts'));
|
|
@@ -190,8 +200,14 @@ export const guard: Guard = {
|
|
|
190
200
|
};
|
|
191
201
|
`;
|
|
192
202
|
|
|
193
|
-
/**
|
|
194
|
-
|
|
195
|
-
|
|
203
|
+
/**
|
|
204
|
+
* `guards/repo-unbounded.ts` and its test. No index, no registry — the directory registers it.
|
|
205
|
+
* `'error'` is what `x new` and `x g guard` write; `'warning'` is the form shipped before, which an
|
|
206
|
+
* existing app keeps until it deletes the severity line itself.
|
|
207
|
+
*/
|
|
208
|
+
export const repoUnboundedGuardFiles = (
|
|
209
|
+
severity: RepoUnboundedSeverity = 'error',
|
|
210
|
+
): readonly GeneratedFile[] => [
|
|
211
|
+
{ path: `guards/${NAME}.ts`, contents: source(severity) },
|
|
196
212
|
{ path: `guards/${NAME}.test.ts`, contents: repoUnboundedTest(CODE) },
|
|
197
213
|
];
|
|
@@ -25,8 +25,9 @@
|
|
|
25
25
|
// about the TAB: an island polls with `visibleInterval()`, which a hidden tab and a lost session stop.
|
|
26
26
|
// One is about the QUESTION: a destructive act asks through `ConfirmDialog`, never `confirm(`.
|
|
27
27
|
// One is about the POOL: a database call per row runs through `mapBounded`, never all at once.
|
|
28
|
-
// Two more are about the REPO, REPORT ONLY (`severity: 'warning'`)
|
|
29
|
-
//
|
|
28
|
+
// Two more are about the REPO: an `await` per turn of a loop, REPORT ONLY (`severity: 'warning'`)
|
|
29
|
+
// until the apps are clean of it, and a `.all()` that says no bound — failing the gate in an app
|
|
30
|
+
// scaffolded from 31.23 on, while an older app keeps the report-only copy it was given.
|
|
30
31
|
|
|
31
32
|
import { animatedLayoutPropertyGuardFiles } from './guard-animated-layout-property';
|
|
32
33
|
import { bareErrorGuardFiles } from './guard-bare-error';
|
|
@@ -80,7 +81,7 @@ const SHIPPED: readonly (readonly [string, () => readonly GeneratedFile[]])[] =
|
|
|
80
81
|
['raw-z-index', rawZIndexGuardFiles],
|
|
81
82
|
['repo-await-in-loop', repoAwaitInLoopGuardFiles],
|
|
82
83
|
['repo-raw-sql', repoRawSqlGuardFiles],
|
|
83
|
-
['repo-unbounded', repoUnboundedGuardFiles],
|
|
84
|
+
['repo-unbounded', () => repoUnboundedGuardFiles('error')],
|
|
84
85
|
['semantic-interactive', semanticInteractiveGuardFiles],
|
|
85
86
|
['unbounded-fanout', unboundedFanoutGuardFiles],
|
|
86
87
|
['undeclared-custom-property', undeclaredCustomPropertyGuardFiles],
|
|
@@ -111,6 +112,28 @@ export const shippedGuardSource = (name: string): string | undefined => {
|
|
|
111
112
|
return typeof contents === 'string' ? contents : undefined;
|
|
112
113
|
};
|
|
113
114
|
|
|
115
|
+
/**
|
|
116
|
+
* A shipped guard's earlier form that still counts as current for an app holding it: the template
|
|
117
|
+
* moved for NEW apps only. `repo-unbounded` became failing in 31.23; an app scaffolded before keeps
|
|
118
|
+
* its report-only copy, and `x doctor` must not call that copy stale.
|
|
119
|
+
*/
|
|
120
|
+
const ALSO_CURRENT: Readonly<Record<string, () => readonly GeneratedFile[]>> = {
|
|
121
|
+
'repo-unbounded': () => repoUnboundedGuardFiles('warning'),
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Every rule-file text that reads as current for a shipped guard — the template first, then any
|
|
126
|
+
* earlier form an existing app is allowed to keep. Empty when the name was never shipped.
|
|
127
|
+
*/
|
|
128
|
+
export const shippedGuardSources = (name: string): readonly string[] => {
|
|
129
|
+
const current = shippedGuardSource(name);
|
|
130
|
+
if (current === undefined) return [];
|
|
131
|
+
const earlier = (Object.hasOwn(ALSO_CURRENT, name) ? ALSO_CURRENT[name] : undefined)?.().find(
|
|
132
|
+
(file) => file.path === `guards/${name}.ts`,
|
|
133
|
+
);
|
|
134
|
+
return typeof earlier?.contents === 'string' ? [current, earlier.contents] : [current];
|
|
135
|
+
};
|
|
136
|
+
|
|
114
137
|
/**
|
|
115
138
|
* Every guard `x new` ships, each with its test. One module per guard, because an app deletes a
|
|
116
139
|
* rule it does not want by deleting one file — and a guard the app then writes for itself is
|
package/wiki/Actions.md
CHANGED
|
@@ -165,6 +165,7 @@ export const load = async (): Promise<{ readonly answer: ActionAnswer | null }>
|
|
|
165
165
|
| `useActionAnswer(createPost)` answers only that action's outcome — or by name, `useActionAnswer('createPost' satisfies keyof Api['actions'])`, from a page that may not import the action; `useActionAnswer()` any | two forms on one page |
|
|
166
166
|
| a cookie that is not one this package wrote reads as `null` | it arrives from the browser: parsed, bounded, never trusted |
|
|
167
167
|
| `static` / `isr` pages read `null` | a shared document is rendered as nobody, with no inbound cookie |
|
|
168
|
+
| outside a request (the `llms.txt` build runs `load` with none) reads `null`, never `X_NO_REQUEST` | no request, no answer |
|
|
168
169
|
| translate on `code` and `issues[].rule` with `t()` | the flash carries no prose, so no locale |
|
|
169
170
|
| field values are not carried back | a password or a card number does not belong in a cookie; the form re-renders empty, or the page keeps a draft |
|
|
170
171
|
|