@ultimat3/cli 30.9.0 → 31.1.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 +80 -64
- package/README.md +4 -1
- package/package.json +30 -29
- package/src/admin-registration.ts +1 -1
- package/src/affected-base.ts +51 -0
- package/src/affected.ts +34 -11
- package/src/app-boundaries.ts +88 -9
- package/src/app-load-async.ts +133 -0
- package/src/app-load-batch.ts +203 -0
- package/src/app-load-prebuilt.ts +147 -0
- package/src/app-load-register.ts +175 -0
- package/src/app-load.ts +143 -175
- package/src/app-loader-imports.ts +31 -0
- package/src/app-root.ts +13 -0
- package/src/app-runtime.ts +5 -1
- package/src/boundary-findings.ts +12 -0
- package/src/browser-launcher-port.ts +3 -7
- package/src/browser-launcher.ts +1 -1
- package/src/budgets-scan.ts +8 -0
- package/src/budgets.ts +10 -1
- package/src/build-registry-background.ts +59 -0
- package/src/build-registry.ts +207 -0
- package/src/cdp-shot-clock.ts +3 -11
- package/src/cdp-shot-driver.ts +3 -2
- package/src/cdp-shot-element.ts +3 -2
- package/src/cdp-shot-page.ts +2 -2
- package/src/cdp-shot-watch.ts +4 -3
- package/src/ci-log.ts +76 -13
- package/src/cmd-affected-spec.ts +7 -3
- package/src/cmd-affected.ts +91 -77
- package/src/cmd-auth.ts +3 -3
- package/src/cmd-ci.ts +6 -3
- package/src/cmd-db-recount.ts +15 -0
- package/src/cmd-drill.ts +10 -6
- package/src/cmd-exercise.ts +2 -1
- package/src/cmd-generate-spec.ts +6 -0
- package/src/cmd-generate.ts +22 -4
- package/src/cmd-mail.ts +1 -1
- package/src/cmd-pr-spec.ts +1 -1
- package/src/cmd-pr.ts +72 -1
- package/src/cmd-routes.ts +2 -2
- package/src/cmd-secrets-spec.ts +4 -1
- package/src/cmd-shot.ts +14 -262
- package/src/cmd-test-spec.ts +2 -2
- package/src/cmd-verify-spec.ts +21 -1
- package/src/cmd-verify.ts +16 -4
- package/src/coverage-source.ts +4 -1
- package/src/db-diagnostics.ts +8 -1
- package/src/dev-boot.ts +29 -15
- package/src/dev-dashboard-invalidations.ts +43 -0
- package/src/dev-dashboard.ts +13 -16
- package/src/dev-n-plus-one.ts +7 -3
- package/src/dev-rebuild.ts +2 -1
- package/src/dev-route-table.ts +1 -1
- package/src/dev-traces.ts +16 -15
- package/src/document-options.ts +12 -1
- package/src/drift-store.ts +55 -0
- package/src/error-catalog.ts +8 -3
- package/src/error-codes-boundary.ts +32 -0
- package/src/error-codes-package.ts +38 -0
- package/src/error-codes.ts +28 -40
- package/src/errors.ts +17 -7
- package/src/exercise-database.ts +13 -1
- package/src/exercise-findings.ts +36 -18
- package/src/exercise-services.ts +84 -0
- package/src/exercise-subject.ts +38 -13
- package/src/failure-capture-boot.ts +9 -5
- package/src/framework-schema.ts +5 -5
- package/src/generate-exercise.ts +1 -1
- package/src/generate-files.ts +27 -7
- package/src/generate-kinds.ts +5 -0
- package/src/generate-refresh.ts +53 -0
- package/src/generate-workspace.ts +169 -0
- package/src/generate-write.ts +8 -2
- package/src/hold.ts +19 -8
- package/src/image-prepare.ts +6 -2
- package/src/index.ts +5 -20
- package/src/island-bundle.ts +7 -3
- package/src/island-capture.ts +2 -2
- package/src/island-harness.ts +1 -1
- package/src/job-registration.ts +43 -6
- package/src/jobs-driver.ts +4 -5
- package/src/mcp-errors.ts +20 -4
- package/src/mcp-host.ts +5 -1
- package/src/mcp-ui-interact.ts +3 -0
- package/src/messages-gate.ts +10 -0
- package/src/new-shapes-generate.ts +1 -1
- package/src/otlp-export.ts +94 -29
- package/src/output.ts +24 -10
- package/src/page-sync.ts +3 -1
- package/src/pr-activity.ts +150 -0
- package/src/pr-bots.ts +109 -0
- package/src/pr-threads.ts +7 -2
- package/src/role-load.ts +17 -11
- package/src/role-start.ts +5 -4
- package/src/role-sync.ts +7 -8
- package/src/route-islands-preload.ts +46 -0
- package/src/route-islands.ts +6 -2
- package/src/runtime-admin.ts +5 -1
- package/src/runtime-bindings.ts +25 -19
- package/src/runtime-boot-ports.ts +66 -0
- package/src/runtime-bus.ts +29 -5
- package/src/runtime-cache-bus.ts +53 -0
- package/src/runtime-cache.ts +43 -13
- package/src/runtime-isr-outcome.ts +5 -4
- package/src/runtime-jobs.ts +2 -2
- package/src/runtime-keys.ts +37 -0
- package/src/runtime-overrides.ts +148 -42
- package/src/runtime-port-bindings-queue.ts +36 -0
- package/src/runtime-port-bindings.ts +117 -0
- package/src/runtime-ports.ts +164 -0
- package/src/runtime-purge.ts +41 -28
- package/src/runtime-push.ts +7 -3
- package/src/runtime-queue.ts +70 -55
- package/src/runtime-realtime.ts +5 -5
- package/src/runtime-render-document.ts +4 -1
- package/src/runtime-services.ts +110 -158
- package/src/runtime-storage-boot.ts +111 -0
- package/src/runtime-storage-upload.ts +9 -7
- package/src/runtime-storage.ts +7 -1
- package/src/serve-boot.ts +8 -4
- package/src/serve-entry.ts +3 -0
- package/src/serve-env.ts +47 -14
- package/src/serve-prebuilt-paths.ts +3 -0
- package/src/serve-prebuilt.ts +15 -4
- package/src/serve.ts +2 -2
- package/src/shot-gpu.ts +61 -0
- package/src/shot-route.ts +95 -0
- package/src/shot-run.ts +189 -0
- package/src/shot-verdict.ts +5 -0
- package/src/static-cards.ts +3 -2
- package/src/static-report.ts +2 -2
- package/src/style-bundle.ts +1 -1
- package/src/sync-authenticator.ts +17 -18
- package/src/templates/action-tests.ts +4 -4
- package/src/templates/backfill.ts +5 -8
- package/src/templates/entity.ts +3 -0
- package/src/templates/github/ci.yml.ts +3 -1
- package/src/templates/github/dependabot.yml.ts +73 -0
- package/src/templates/job.ts +13 -22
- package/src/templates/naming.ts +20 -1
- package/src/templates/pinned/docker-compose.yml +1 -1
- package/src/templates/query.ts +7 -8
- package/src/templates/route.ts +5 -3
- package/src/templates/scaffold-api.ts +1 -1
- package/src/templates/scaffold-auth.ts +5 -3
- package/src/templates/scaffold-claude-commands.ts +6 -3
- package/src/templates/scaffold-claude.ts +4 -4
- package/src/templates/scaffold-container-compose.ts +2 -4
- package/src/templates/scaffold-domain-package.ts +1 -1
- package/src/templates/scaffold-entries.ts +6 -1
- package/src/templates/scaffold-helm-fences.ts +3 -2
- package/src/templates/scaffold-helm.ts +35 -6
- package/src/templates/scaffold-repo.ts +47 -135
- package/src/templates/scaffold-runtime-ports.ts +62 -0
- package/src/templates/scaffold-verify-floor.ts +97 -0
- package/src/templates/shapes/overlay.ts +1 -1
- package/src/templates/sign-in-oidc.ts +5 -3
- package/src/templates/sign-in-shared.ts +28 -10
- package/src/templates/workspace.ts +75 -0
- package/src/test-ignores.ts +5 -2
- package/src/test-select.ts +4 -1
- package/src/tsconfig-aliases.ts +85 -0
- package/src/upgrade-gate.ts +30 -5
- package/src/upgrade-report.ts +7 -1
- package/src/verify-changed-facts.ts +53 -0
- package/src/verify-changed-scope.ts +162 -0
- package/src/verify-changed.ts +174 -0
- package/src/verify-checks.ts +33 -19
- package/src/verify-drift-owner.ts +30 -0
- package/src/verify-e2e.ts +2 -1
- package/src/verify-factories.ts +86 -0
- package/src/verify-run.ts +13 -11
- package/src/verify-step.ts +13 -0
- package/src/verify-tests.ts +58 -6
- package/src/workspace-external-deps.ts +164 -0
- package/src/write-line.ts +21 -6
- package/wiki/Actions.md +2 -2
- package/wiki/Adapters.md +400 -0
- package/wiki/Admin-Dashboard.md +1 -1
- package/wiki/Agents.md +9 -9
- package/wiki/Auth.md +78 -2
- package/wiki/Building-Your-Own-Base.md +1 -1
- package/wiki/CLI-Reference.md +45 -14
- package/wiki/Caching-And-Invalidation.md +17 -5
- package/wiki/Compared.md +8 -2
- package/wiki/Configuration.md +14 -14
- package/wiki/Deployment.md +28 -1
- package/wiki/Entities-And-Migrations.md +47 -1
- package/wiki/FAQ.md +8 -2
- package/wiki/Feature-Flags.md +1 -1
- package/wiki/Home.md +3 -2
- package/wiki/Jobs-And-Workflows.md +107 -6
- package/wiki/Known-Gaps.md +4 -3
- package/wiki/MCP-And-AI.md +18 -4
- package/wiki/Mail.md +14 -5
- package/wiki/Migrations-And-Backfills.md +29 -4
- package/wiki/Money.md +2 -0
- package/wiki/N-Plus-One-Detection.md +24 -22
- package/wiki/Notify.md +28 -4
- package/wiki/Observability.md +121 -15
- package/wiki/Queries-And-Live-Queries.md +2 -2
- package/wiki/Realtime.md +9 -4
- package/wiki/Routes-And-Render-Modes.md +5 -0
- package/wiki/Scraping.md +57 -11
- package/wiki/Shapes.md +2 -2
- package/wiki/Stability.md +7 -5
- package/wiki/Storage-And-Uploads.md +56 -4
- package/wiki/Testing.md +65 -52
- package/wiki/Troubleshooting.md +1 -1
- package/wiki/Tutorial-01-First-App.md +1 -1
- package/wiki/Tutorial-04-Jobs-And-Realtime.md +1 -1
- package/wiki/Tutorial-05-Deploy-Free.md +1 -1
- package/wiki/Tutorial-06-Growing-Up.md +8 -8
- package/wiki/Upgrading.md +136 -5
package/src/role-load.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
// What a container role imports of the app
|
|
2
|
-
//
|
|
3
|
-
//
|
|
4
|
-
//
|
|
1
|
+
// What a container role imports of the app: `web`, `sync` and `replicator` every module (routes,
|
|
2
|
+
// queries, entities); `worker` and `scheduler` the API index and every module that brings no
|
|
3
|
+
// document (a component, a stylesheet) with it. Every role reads the image's prebuilt registry
|
|
4
|
+
// first (`app-load-prebuilt.ts`), which holds both lists, and scans only when there is none.
|
|
5
5
|
|
|
6
6
|
// why: Bun ships no path API; the API index is named app-root-relative and imported absolute.
|
|
7
7
|
import { join, resolve } from 'node:path';
|
|
@@ -10,6 +10,7 @@ import { isJsonObject, logger, UltimateError } from '@ultimat3/core';
|
|
|
10
10
|
import { registeredJobs, registeredTasks } from '@ultimat3/jobs';
|
|
11
11
|
import type { AppScan } from './app-load';
|
|
12
12
|
import { scanAppModules } from './app-load';
|
|
13
|
+
import { loadPrebuiltApp } from './app-load-prebuilt';
|
|
13
14
|
import { API_INDEX } from './app-root';
|
|
14
15
|
import { createDocumentGraph } from './document-graph';
|
|
15
16
|
|
|
@@ -116,7 +117,7 @@ export async function scanBackground(root: string): Promise<AppScan> {
|
|
|
116
117
|
* answered by importing everything, loudly.
|
|
117
118
|
*/
|
|
118
119
|
async function loadBackground(root: string, role: Role): Promise<AppScan> {
|
|
119
|
-
const scan = await scanBackground(root);
|
|
120
|
+
const scan = (await loadPrebuiltApp(root, 'background')) ?? (await scanBackground(root));
|
|
120
121
|
const missing = await unregisteredFromManifest(root);
|
|
121
122
|
if (missing !== undefined && missing.length === 0) return scan;
|
|
122
123
|
if (missing === undefined) {
|
|
@@ -129,15 +130,20 @@ async function loadBackground(root: string, role: Role): Promise<AppScan> {
|
|
|
129
130
|
const error = new RoleLoadIncompleteError({ role, missing });
|
|
130
131
|
logger.error(error.format(), { code: error.code, role, missing });
|
|
131
132
|
}
|
|
132
|
-
return
|
|
133
|
+
return loadEverything(root);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/** Every module: from the prebuilt registry when it is the app on disk, else the scan. */
|
|
137
|
+
async function loadEverything(root: string): Promise<AppScan> {
|
|
138
|
+
return (await loadPrebuiltApp(root)) ?? (await scanAppModules(root, { track: false }));
|
|
133
139
|
}
|
|
134
140
|
|
|
135
141
|
/**
|
|
136
|
-
* What `serve-boot.ts` calls instead of `loadApp`: the
|
|
137
|
-
* reads from
|
|
142
|
+
* What `serve-boot.ts` calls instead of `loadApp`: the modules a role needs and none of what a
|
|
143
|
+
* tool reads from them afterwards — no reload graph, no error-code walk of the app's source. The
|
|
144
|
+
* prebuilt registry when it is the app (`x build --target prebuilt`): the scan, and a background
|
|
145
|
+
* role's walk of the import graph per module, is what grew a pod's start with the file count.
|
|
138
146
|
*/
|
|
139
147
|
export async function loadAppForRole(root: string, role: Role): Promise<AppScan> {
|
|
140
|
-
return roleLoadFor(role) === 'background'
|
|
141
|
-
? loadBackground(root, role)
|
|
142
|
-
: scanAppModules(root, { track: false });
|
|
148
|
+
return roleLoadFor(role) === 'background' ? loadBackground(root, role) : loadEverything(root);
|
|
143
149
|
}
|
package/src/role-start.ts
CHANGED
|
@@ -11,13 +11,13 @@ import { ctxOf, isRole, logger, markReady, ROLES } from '@ultimat3/core';
|
|
|
11
11
|
import { dbExecutor } from '@ultimat3/db';
|
|
12
12
|
import type { RateLimitStore, Route, ServerHandle, WebSocketMount } from '@ultimat3/http';
|
|
13
13
|
import {
|
|
14
|
-
adoptRateLimitStore,
|
|
15
14
|
configuredAuthenticator,
|
|
16
15
|
configuredHttp,
|
|
17
16
|
defineHttpConfig,
|
|
18
17
|
httpServer,
|
|
19
18
|
mergeHttpConfig,
|
|
20
19
|
} from '@ultimat3/http';
|
|
20
|
+
import { installRateLimitStore } from '@ultimat3/http/adapter';
|
|
21
21
|
import type { OutboxRelay } from '@ultimat3/jobs';
|
|
22
22
|
import {
|
|
23
23
|
jobDriver,
|
|
@@ -194,7 +194,8 @@ function startWeb(
|
|
|
194
194
|
...(options.overrides?.middleware === undefined
|
|
195
195
|
? {}
|
|
196
196
|
: { middleware: options.overrides.middleware }),
|
|
197
|
-
|
|
197
|
+
// No store here: `httpServer` reads the INSTALLED one, which `startRoles` installed (the same
|
|
198
|
+
// `rateLimitStoreFor` answer) before any role could serve.
|
|
198
199
|
// The app's own declaration UNDERNEATH, this boot's facts on top. Without the first half the
|
|
199
200
|
// entire HTTP tuning surface was unreachable from a shipped app — this literal was its only
|
|
200
201
|
// construction, so `cors.origins` stayed `[]` in every deployment (no cross-origin call could
|
|
@@ -242,7 +243,7 @@ function startWeb(
|
|
|
242
243
|
* The one moment the boot can still see both answers.
|
|
243
244
|
*
|
|
244
245
|
* `startServices` captures the drivers it built; `loadApp` imports the app's modules after it, and
|
|
245
|
-
* a module calling `
|
|
246
|
+
* a module calling `installJobDriver()` at import time moves the ambient slot and leaves the capture
|
|
246
247
|
* alone. From here on the two are indistinguishable at every call site: `handle.enqueue()` reads
|
|
247
248
|
* the ambient one, `jobWorker` claims from the captured one, and `/_x` reads the ambient one —
|
|
248
249
|
* so the dashboard agrees with the enqueue side and disagrees with reality.
|
|
@@ -281,7 +282,7 @@ export async function startRoles(options: StartRolesOptions): Promise<RunningRol
|
|
|
281
282
|
// A frame of its own over what `startServices` adopted, popped by its own undo — so stopping
|
|
282
283
|
// these roles takes back exactly this install, whatever else stacked over or under it.
|
|
283
284
|
const limits = rateLimitStoreFor(options);
|
|
284
|
-
const restoreLimits = limits === undefined ? () => undefined :
|
|
285
|
+
const restoreLimits = limits === undefined ? () => undefined : installRateLimitStore(limits);
|
|
285
286
|
started.push(async () => restoreLimits());
|
|
286
287
|
// First, and for every role rather than only the two that open an HTTP socket: `worker` and
|
|
287
288
|
// `sync` are precisely the roles whose HPAs read a series the process itself has to publish,
|
package/src/role-sync.ts
CHANGED
|
@@ -256,15 +256,14 @@ export async function prepareSync(options: StartRolesOptions): Promise<PreparedS
|
|
|
256
256
|
const hub = new ChannelHub({ transport: options.runtime.transport, sockets });
|
|
257
257
|
// The node evaluated no credential of its own and no host ever handed it one, so every socket
|
|
258
258
|
// the framework opened was anonymous and every guard, gate, presence entry and tenant cap
|
|
259
|
-
// decided against `null`.
|
|
260
|
-
//
|
|
259
|
+
// decided against `null`. The app's own HTTP resolver, or nothing at all — which is what `x dev`
|
|
260
|
+
// with no authenticator should stay. ONE seam: the `runtime.syncAuthenticate` override beside it
|
|
261
|
+
// was deleted in v31, so a socket and a request can never be answered by two identities.
|
|
261
262
|
//
|
|
262
|
-
//
|
|
263
|
-
//
|
|
264
|
-
// `cookie`/`authorization`, so `logout` closes the socket and not only the HTTP session.
|
|
265
|
-
|
|
266
|
-
// `exp`), or resolves identity from a header the adapter deliberately does not retain.
|
|
267
|
-
const authenticate = options.overrides?.syncAuthenticate ?? syncAuthenticator(options.buildId);
|
|
263
|
+
// It re-authorizes: `syncAuthenticator` carries an `expiresAt` and a `refresh` of its own
|
|
264
|
+
// (`MAX_CREDENTIAL_TTL_MS`), re-asking the app's resolver with the upgrade's own
|
|
265
|
+
// `cookie`/`authorization`, so `logout` closes the socket and not only the HTTP session.
|
|
266
|
+
const authenticate = syncAuthenticator(options.buildId);
|
|
268
267
|
const registry = registerLiveQueries(options);
|
|
269
268
|
const origins = syncOriginsFrom(options.env);
|
|
270
269
|
const node = syncNode({
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
// The `<link rel="modulepreload">` tags for the islands ONE render recorded: every shared chunk an
|
|
2
|
+
// eagerly booted island imports, each once, so the browser fetches them beside the entry instead of
|
|
3
|
+
// discovering them only after the entry is parsed. A page that rendered no island gets none.
|
|
4
|
+
|
|
5
|
+
import { escapeHtml } from '@ultimat3/core';
|
|
6
|
+
import type { IslandCollector, IslandDirective, RouteEntry } from '@ultimat3/render';
|
|
7
|
+
import type { DocumentOptions } from './document-options';
|
|
8
|
+
import { isRuntimeChunk } from './island-runtime';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Only an island booted as soon as the page is idle, or held until it mounts (`island-hold.ts`,
|
|
12
|
+
* booted at once). `visible` and `interaction` defer the entry on purpose; fetching its chunks
|
|
13
|
+
* early would spend the bytes that deferral exists to save, on a visit that may never need them.
|
|
14
|
+
*/
|
|
15
|
+
const eager = (directive: IslandDirective): boolean =>
|
|
16
|
+
directive.strategy === 'idle' || directive.hold === true;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* The tags, sorted, after the body beside the boot — `<link rel="modulepreload">` is body-ok, and
|
|
20
|
+
* which islands rendered is known only once the walk ran. `booted`: the document carries the page
|
|
21
|
+
* boot, which supplies the realtime runtime, so an island there never fetches the runtime chunk
|
|
22
|
+
* (`awaitPageRuntime`) and a preload of it would download 64 kB for nothing — the same rule the
|
|
23
|
+
* `budgets` step charges by (`MeasureOptions.boot`). `linked` is what an earlier flush of the same
|
|
24
|
+
* document already emitted; it is extended with what this call emits.
|
|
25
|
+
*/
|
|
26
|
+
export function preloadTags(
|
|
27
|
+
entry: RouteEntry,
|
|
28
|
+
islands: IslandCollector,
|
|
29
|
+
options: DocumentOptions,
|
|
30
|
+
booted: boolean,
|
|
31
|
+
linked: Set<string> = new Set(),
|
|
32
|
+
): string {
|
|
33
|
+
const importsOf = options.resolveIsland?.(entry.file).importsOf;
|
|
34
|
+
if (importsOf === undefined) return '';
|
|
35
|
+
const fresh = new Set<string>();
|
|
36
|
+
for (const directive of islands.directives) {
|
|
37
|
+
if (!eager(directive)) continue;
|
|
38
|
+
for (const url of importsOf(directive.entry)) {
|
|
39
|
+
if (linked.has(url) || (booted && isRuntimeChunk(url))) continue;
|
|
40
|
+
fresh.add(url);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
const urls = [...fresh].sort();
|
|
44
|
+
for (const url of urls) linked.add(url);
|
|
45
|
+
return urls.map((url) => `<link rel="modulepreload" href="${escapeHtml(url)}">`).join('');
|
|
46
|
+
}
|
package/src/route-islands.ts
CHANGED
|
@@ -14,6 +14,7 @@ import {
|
|
|
14
14
|
renderHead,
|
|
15
15
|
} from '@ultimat3/render';
|
|
16
16
|
import type { DocumentOptions } from './document-options';
|
|
17
|
+
import { preloadTags } from './route-islands-preload';
|
|
17
18
|
|
|
18
19
|
/**
|
|
19
20
|
* One collector per RENDER, never module-global: two requests render different params, and a
|
|
@@ -102,14 +103,17 @@ export function streamScripts(
|
|
|
102
103
|
const boot = bootScript(entry, islands, options, scope);
|
|
103
104
|
const flushed = islands.directives.length;
|
|
104
105
|
let booted = boot !== '';
|
|
106
|
+
// One set per document: a hole's chunk links only what no earlier flush already preloaded.
|
|
107
|
+
const linked = new Set<string>();
|
|
108
|
+
const preloads = (): string => preloadTags(entry, islands, options, booted, linked);
|
|
105
109
|
return {
|
|
106
|
-
first: `${boot}${hydrateRuntime(islands.directives, { async: holes && !booted })}`,
|
|
110
|
+
first: `${boot}${preloads()}${hydrateRuntime(islands.directives, { async: holes && !booted })}`,
|
|
107
111
|
after: (outcome) => {
|
|
108
112
|
const recorded = islands.directives.length;
|
|
109
113
|
if (recorded === (outcome === 'failed' ? 0 : flushed)) return '';
|
|
110
114
|
const late = booted ? '' : bootScript(entry, islands, options, scope);
|
|
111
115
|
booted = booted || late !== '';
|
|
112
|
-
return `${late}${hydrateRuntime(islands.directives, { async: !booted })}`;
|
|
116
|
+
return `${late}${preloads()}${hydrateRuntime(islands.directives, { async: !booted })}`;
|
|
113
117
|
},
|
|
114
118
|
};
|
|
115
119
|
}
|
package/src/runtime-admin.ts
CHANGED
|
@@ -77,7 +77,11 @@ async function answer(
|
|
|
77
77
|
// Dynamic, and only here: reached only when an admin is mounted, by which point the app has
|
|
78
78
|
// already loaded the package — and after `loadApp` installed the `.tsx` loader its screens need.
|
|
79
79
|
const { adminRouteMatch } = await import('@ultimat3/admin');
|
|
80
|
-
|
|
80
|
+
// The path the route table MATCHED — routed locale prefix and base path removed — never the raw
|
|
81
|
+
// pathname: the router serves `/en/admin/jobs` through `${base}/*rest`, and asking the admin
|
|
82
|
+
// for `/en/admin/jobs` was a 404 in every locale but the default (adopter-found).
|
|
83
|
+
const path = context.routePath ?? request.url.pathname;
|
|
84
|
+
const matched = app === undefined ? null : adminRouteMatch(app, path);
|
|
81
85
|
if (app === undefined || matched === null) throw routeNotFound(method, request.url.pathname);
|
|
82
86
|
|
|
83
87
|
const form = method === 'POST' ? await request.bodyRaw() : null;
|
package/src/runtime-bindings.ts
CHANGED
|
@@ -4,10 +4,8 @@
|
|
|
4
4
|
|
|
5
5
|
import { mkdirSync } from 'node:fs';
|
|
6
6
|
import { join } from 'node:path';
|
|
7
|
-
import type { RealtimeConfig } from '@ultimat3/core';
|
|
8
7
|
import { renderThrowable } from '@ultimat3/core';
|
|
9
8
|
import { StorageUnwritableError } from './errors';
|
|
10
|
-
import { REALTIME_DEFAULTS } from './runtime-realtime';
|
|
11
9
|
import { safeUrlLabel } from './safe-url-label';
|
|
12
10
|
|
|
13
11
|
export type ServiceMode = 'embedded' | 'external';
|
|
@@ -79,11 +77,7 @@ function makeStateDir(stateDir: string): void {
|
|
|
79
77
|
* Embedded Postgres is PGlite on disk under `.x/`, so a restart keeps the data and a `x db reset`
|
|
80
78
|
* is a directory delete rather than a container dance.
|
|
81
79
|
*/
|
|
82
|
-
export function resolveServices(
|
|
83
|
-
root: string,
|
|
84
|
-
env: Env,
|
|
85
|
-
realtime: RealtimeConfig = REALTIME_DEFAULTS,
|
|
86
|
-
): DevServices {
|
|
80
|
+
export function resolveServices(root: string, env: Env): DevServices {
|
|
87
81
|
// `ULTIMATE_STATE_DIR` relocates the whole of `.x/` — the embedded database, the local disk and
|
|
88
82
|
// the dev lock — for one process tree. It is how an e2e run boots the app on a THROWAWAY database
|
|
89
83
|
// (`e2e-app.ts`) instead of resetting the developer's own, beside a running `x dev`.
|
|
@@ -107,7 +101,7 @@ export function resolveServices(
|
|
|
107
101
|
detail: 'PGlite in this process — set DATABASE_URL to use a real Postgres',
|
|
108
102
|
}
|
|
109
103
|
: { name: 'db', mode: 'external', url: databaseUrl, detail: 'DATABASE_URL' },
|
|
110
|
-
events: eventsBinding(env
|
|
104
|
+
events: eventsBinding(env),
|
|
111
105
|
storage:
|
|
112
106
|
s3Endpoint === undefined
|
|
113
107
|
? {
|
|
@@ -140,26 +134,38 @@ export const describeServices = (services: DevServices): string =>
|
|
|
140
134
|
.join(' ');
|
|
141
135
|
|
|
142
136
|
/**
|
|
143
|
-
* The bus
|
|
144
|
-
* `@ultimat3/realtime`'s `selectTransport` obeys
|
|
145
|
-
*
|
|
137
|
+
* The bus the environment selects: `NATS_URL` set is NATS, unset is the in-process fanout — the
|
|
138
|
+
* one rule `@ultimat3/realtime`'s `selectTransport` obeys (v31: the `realtime.transport`/`urlEnv`
|
|
139
|
+
* config is gone; a bus of the app's own is `transport` in `apps/<app>/runtime.ts`).
|
|
146
140
|
*/
|
|
147
|
-
export function eventsBinding(env: Env
|
|
148
|
-
const
|
|
149
|
-
const url = realtime.transport === 'nats' && name !== undefined ? nonEmpty(env[name]) : undefined;
|
|
141
|
+
export function eventsBinding(env: Env): ServiceBinding {
|
|
142
|
+
const url = nonEmpty(env['NATS_URL']);
|
|
150
143
|
return url === undefined
|
|
151
144
|
? {
|
|
152
145
|
name: 'events',
|
|
153
146
|
mode: 'embedded',
|
|
154
147
|
url: 'inproc://events',
|
|
155
|
-
detail:
|
|
148
|
+
detail: 'in-process fanout — set NATS_URL to use NATS',
|
|
156
149
|
}
|
|
157
|
-
: { name: 'events', mode: 'external', url, detail:
|
|
150
|
+
: { name: 'events', mode: 'external', url, detail: 'NATS_URL' };
|
|
158
151
|
}
|
|
159
152
|
|
|
160
|
-
/**
|
|
153
|
+
/**
|
|
154
|
+
* `services` with the events binding the booted runtime actually chose: a `runtime.ts` transport
|
|
155
|
+
* is reported as the app's own, never as whatever `NATS_URL` happens to say.
|
|
156
|
+
*/
|
|
161
157
|
export const withRealtimeEvents = (
|
|
162
158
|
services: DevServices,
|
|
163
159
|
env: Env,
|
|
164
|
-
|
|
165
|
-
): DevServices => ({
|
|
160
|
+
supplied: boolean,
|
|
161
|
+
): DevServices => ({
|
|
162
|
+
...services,
|
|
163
|
+
events: supplied
|
|
164
|
+
? {
|
|
165
|
+
name: 'events',
|
|
166
|
+
mode: 'external',
|
|
167
|
+
url: 'runtime://transport',
|
|
168
|
+
detail: 'runtime.ts transport',
|
|
169
|
+
}
|
|
170
|
+
: eventsBinding(env),
|
|
171
|
+
});
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
// The `boot` ports (`runtime.ts`'s `clock`, `secretSource`), installed by ONE helper on every path
|
|
2
|
+
// that reads `runtime.ts` — after that module (and all it imports) has evaluated on the defaults,
|
|
3
|
+
// before `app.config.ts` and the app's modules do. `startServices` and every queue-only command
|
|
4
|
+
// (`x jobs`, `x auth`, `ROLE=migrate`) call it; a path that skipped it ran on the wrong key.
|
|
5
|
+
|
|
6
|
+
import { loadAppRuntime } from './app-runtime';
|
|
7
|
+
import type { DevServices, Env } from './runtime-bindings';
|
|
8
|
+
import { resolveServices } from './runtime-bindings';
|
|
9
|
+
import type { RuntimeOverrides } from './runtime-overrides';
|
|
10
|
+
import { BOOT_PORT_BINDINGS } from './runtime-port-bindings-queue';
|
|
11
|
+
import { installPorts, type PortRelease } from './runtime-ports';
|
|
12
|
+
import { type RunningQueue, type SchemaMode, startQueue } from './runtime-queue';
|
|
13
|
+
|
|
14
|
+
/** Install `runtime.ts`'s boot ports; answers the releases, in install order. */
|
|
15
|
+
export const installBootPorts = (overrides: RuntimeOverrides | undefined): Promise<PortRelease[]> =>
|
|
16
|
+
installPorts(BOOT_PORT_BINDINGS, 'boot', {
|
|
17
|
+
clock: overrides?.clock,
|
|
18
|
+
secretSource: overrides?.secretSource,
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
/** Newest first, every one, the first failure rethrown after the rest ran. */
|
|
22
|
+
async function releaseAll(releases: readonly PortRelease[]): Promise<void> {
|
|
23
|
+
let first: { readonly error: unknown } | undefined;
|
|
24
|
+
for (const release of [...releases].reverse()) {
|
|
25
|
+
try {
|
|
26
|
+
await release();
|
|
27
|
+
} catch (error) {
|
|
28
|
+
first ??= { error };
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
if (first !== undefined) throw first.error;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* The queue with `runtime.ts` honoured whole: its boot ports first, then its queue ports
|
|
36
|
+
* (`jobs`, `eventBus`, …) through `startQueue`. `stop()` releases the queue, then the boot ports.
|
|
37
|
+
*/
|
|
38
|
+
export async function startQueueWithBoot(
|
|
39
|
+
services: DevServices,
|
|
40
|
+
overrides: RuntimeOverrides | undefined,
|
|
41
|
+
env: Env,
|
|
42
|
+
schema?: SchemaMode,
|
|
43
|
+
): Promise<RunningQueue> {
|
|
44
|
+
const booted = await installBootPorts(overrides);
|
|
45
|
+
try {
|
|
46
|
+
const queue = await startQueue(services, overrides, env, schema);
|
|
47
|
+
return {
|
|
48
|
+
...queue,
|
|
49
|
+
async stop() {
|
|
50
|
+
try {
|
|
51
|
+
await queue.stop();
|
|
52
|
+
} finally {
|
|
53
|
+
await releaseAll(booted);
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
} catch (error) {
|
|
58
|
+
await releaseAll(booted).catch(() => undefined);
|
|
59
|
+
throw error;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** A command's queue over the app at `root`: its `runtime.ts` read, then `startQueueWithBoot`. */
|
|
64
|
+
export async function openAppQueue(root: string, env: Env): Promise<RunningQueue> {
|
|
65
|
+
return startQueueWithBoot(resolveServices(root, env), await loadAppRuntime(root), env);
|
|
66
|
+
}
|
package/src/runtime-bus.ts
CHANGED
|
@@ -17,8 +17,10 @@
|
|
|
17
17
|
|
|
18
18
|
import type { RealtimeConfig, Role } from '@ultimat3/core';
|
|
19
19
|
import { isUltimateError, logger, registerReadinessCheck } from '@ultimat3/core';
|
|
20
|
+
import { redisUrlSource } from '@ultimat3/core/redis';
|
|
21
|
+
import { installChannelTransport } from '@ultimat3/realtime/adapter';
|
|
20
22
|
import type { BusUse, SelectTransportOptions, Transport } from '@ultimat3/realtime/server';
|
|
21
|
-
import { selectTransport
|
|
23
|
+
import { selectTransport } from '@ultimat3/realtime/server';
|
|
22
24
|
import type { Env } from './runtime-bindings';
|
|
23
25
|
|
|
24
26
|
/**
|
|
@@ -99,17 +101,39 @@ export interface SelectBusInput {
|
|
|
99
101
|
}
|
|
100
102
|
|
|
101
103
|
/**
|
|
102
|
-
*
|
|
103
|
-
*
|
|
104
|
+
* A production boot on the in-process bus, said once. Since v31 nothing refuses it — the
|
|
105
|
+
* `realtime.transport` declaration is gone, and `NATS_URL` alone selects — so a forgotten variable
|
|
106
|
+
* is one replica's worth of fanout behind a load balancer. Warned, never refused: a single-replica
|
|
107
|
+
* deploy is legal, and `X_REALTIME_TOPOLOGY` stays the hard check for a topology that cannot work.
|
|
108
|
+
*/
|
|
109
|
+
function warnInProcessInProduction(input: SelectBusInput, mode: 'embedded' | 'external'): void {
|
|
110
|
+
if (input.env['NODE_ENV'] !== 'production' || mode !== 'embedded') return;
|
|
111
|
+
if (input.override !== undefined) return;
|
|
112
|
+
// With Redis the cache hop rides Redis pub/sub (`runtime-cache-bus.ts`): saying busts stay
|
|
113
|
+
// local would send an operator after a fault that is not there.
|
|
114
|
+
const redis = redisUrlSource(input.env);
|
|
115
|
+
logger.warn('ultimate bus is the in-process bus', {
|
|
116
|
+
cause:
|
|
117
|
+
redis === undefined
|
|
118
|
+
? 'NATS_URL is unset and apps/<app>/runtime.ts supplies no transport, so channel events, live queries and cache invalidations reach this replica only'
|
|
119
|
+
: `NATS_URL is unset and apps/<app>/runtime.ts supplies no transport, so channel events and live queries reach this replica only (cache invalidations ride ${redis.key}: see the cache.broadcast boot line)`,
|
|
120
|
+
fix: 'NATS_URL=nats://<host>:4222 # in the deploy environment of every role; or `transport` in apps/<app>/runtime.ts — leave both unset only for a single-replica deploy',
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Selection is pure — it parses env and constructs, it dials nothing — so nothing is refused for a
|
|
126
|
+
* bus that is merely away until a role that needs it dials (`selectTransport`).
|
|
104
127
|
*/
|
|
105
128
|
export function selectBus(input: SelectBusInput): SelectedBus {
|
|
106
129
|
const use = busUseFor(input.roles, input.realtime);
|
|
107
130
|
const tolerant = input.dev === true && use !== 'publish';
|
|
108
|
-
const selection = selectTransport(input.env,
|
|
131
|
+
const selection = selectTransport(input.env, {
|
|
109
132
|
...(tolerant ? { connectWithinMs: DEV_BUS_WAIT_MS } : {}),
|
|
110
133
|
...input.select,
|
|
111
134
|
use,
|
|
112
135
|
});
|
|
136
|
+
warnInProcessInProduction(input, selection.mode);
|
|
113
137
|
return {
|
|
114
138
|
use,
|
|
115
139
|
tolerant,
|
|
@@ -155,7 +179,7 @@ export function selectBus(input: SelectBusInput): SelectedBus {
|
|
|
155
179
|
// role: the hub is the `sync` role's, so a job or an action reached none, and an
|
|
156
180
|
// events-only channel — the one kind that needs no replicator — could be fed by nothing
|
|
157
181
|
// but a socket.
|
|
158
|
-
started.push(
|
|
182
|
+
started.push(installChannelTransport(transport));
|
|
159
183
|
// Only a transport that can be disconnected gets a check. `NatsTransport.connected` is a
|
|
160
184
|
// synchronous getter over the client's own state, so no probe is needed; the in-process
|
|
161
185
|
// bus has nothing to lose a connection to, and a check that can only answer `true` is a
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
// Which bus carries this process's cache invalidations to the other replicas — one rule, said once
|
|
2
|
+
// at boot. The fanout transport when it reaches other processes (NATS, or one `runtime.ts`
|
|
3
|
+
// supplied); Redis pub/sub when the transport is the in-process bus and `REDIS_URL` is set (rung
|
|
4
|
+
// 1: roles split, Redis, no NATS); else the in-process bus, which reaches this replica only.
|
|
5
|
+
|
|
6
|
+
import type { InvalidationBus } from '@ultimat3/cache';
|
|
7
|
+
import { redisPubSubAt } from '@ultimat3/cache';
|
|
8
|
+
import { logger } from '@ultimat3/core';
|
|
9
|
+
import { redisUrlSource } from '@ultimat3/core/redis';
|
|
10
|
+
import type { Transport } from '@ultimat3/realtime/server';
|
|
11
|
+
import { InProcessTransport } from '@ultimat3/realtime/server';
|
|
12
|
+
import type { Env } from './runtime-bindings';
|
|
13
|
+
|
|
14
|
+
export interface CacheBusSelection {
|
|
15
|
+
readonly bus: InvalidationBus;
|
|
16
|
+
/** What the boot line says: `redis`, `nats`, `in-process`, or a supplied transport's name. */
|
|
17
|
+
readonly label: string;
|
|
18
|
+
/** The env key that chose Redis, or `transport` — never the URL. */
|
|
19
|
+
readonly source: string;
|
|
20
|
+
/** Closes a bus this selection built. The fanout transport is the boot's to close, not this. */
|
|
21
|
+
release(): Promise<void>;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface SelectCacheBusInput {
|
|
25
|
+
readonly env: Env;
|
|
26
|
+
readonly transport: Transport;
|
|
27
|
+
/** The Redis bus for a URL. Default `redisPubSubAt`; a test hands in one on its own server. */
|
|
28
|
+
readonly redisPubSub?: ((url: string) => InvalidationBus) | undefined;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Pure apart from the Redis bus it builds (which dials in the background). A transport that
|
|
33
|
+
* already crosses processes always wins: a second hop beside NATS would deliver every bust twice
|
|
34
|
+
* through two systems that can each be down on their own.
|
|
35
|
+
*/
|
|
36
|
+
export function selectCacheBus(input: SelectCacheBusInput): CacheBusSelection {
|
|
37
|
+
const redis = redisUrlSource(input.env);
|
|
38
|
+
if (input.transport instanceof InProcessTransport && redis !== undefined) {
|
|
39
|
+
const bus = (input.redisPubSub ?? redisPubSubAt)(redis.url);
|
|
40
|
+
return { bus, label: bus.name, source: redis.key, release: () => bus.close() };
|
|
41
|
+
}
|
|
42
|
+
return {
|
|
43
|
+
bus: input.transport,
|
|
44
|
+
label: input.transport.name,
|
|
45
|
+
source: 'transport',
|
|
46
|
+
release: async () => undefined,
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** The boot's one line about the hop: a script may parse `bus=` (a fixed vocabulary). */
|
|
51
|
+
export function logCacheBus(selection: CacheBusSelection): void {
|
|
52
|
+
logger.info('cache.broadcast', { bus: selection.label, source: selection.source });
|
|
53
|
+
}
|
package/src/runtime-cache.ts
CHANGED
|
@@ -4,7 +4,13 @@
|
|
|
4
4
|
// and lru unconditionally, redis on `REDIS_URL` and cdn on any real purge driver, so the key was
|
|
5
5
|
// declared, validated at boot, documented, and read by nothing.
|
|
6
6
|
|
|
7
|
-
import type {
|
|
7
|
+
import type {
|
|
8
|
+
CacheTier,
|
|
9
|
+
InvalidationBus,
|
|
10
|
+
InvalidationSubscription,
|
|
11
|
+
PurgeDriver,
|
|
12
|
+
RedisLike,
|
|
13
|
+
} from '@ultimat3/cache';
|
|
8
14
|
import {
|
|
9
15
|
CacheDriverUnavailableError,
|
|
10
16
|
cdnTier,
|
|
@@ -29,8 +35,9 @@ import {
|
|
|
29
35
|
renderThrowable,
|
|
30
36
|
} from '@ultimat3/core';
|
|
31
37
|
import { redisClient, redisUrlSource } from '@ultimat3/core/redis';
|
|
32
|
-
import type { Transport
|
|
38
|
+
import type { Transport } from '@ultimat3/realtime/server';
|
|
33
39
|
import type { Env } from './runtime-bindings';
|
|
40
|
+
import { logCacheBus, selectCacheBus } from './runtime-cache-bus';
|
|
34
41
|
|
|
35
42
|
/**
|
|
36
43
|
* The subject every replica of every app publishes tag invalidations on. One subject and not one
|
|
@@ -63,6 +70,12 @@ export interface CacheTiersOptions {
|
|
|
63
70
|
* a convention to remember. `cacheTiersOf` is what a boot holding the loaded config calls for it.
|
|
64
71
|
*/
|
|
65
72
|
readonly tiers: readonly CacheTierName[];
|
|
73
|
+
/**
|
|
74
|
+
* `runtime.ts`'s `cacheTiers`: each replaces the rung of its own `name` — built from nothing
|
|
75
|
+
* here, so a supplied `redis` tier needs no `REDIS_URL`. A supplied tier `tiers` does not name is
|
|
76
|
+
* logged (`cache.tier.unnamed`) and never registered: the declaration decides the ladder.
|
|
77
|
+
*/
|
|
78
|
+
readonly supplied?: readonly CacheTier[] | undefined;
|
|
66
79
|
/** The wait before re-subscribing after `attempt` failures (1-based). Injected by a test. */
|
|
67
80
|
readonly subscribeRetryMs?: ((attempt: number) => number) | undefined;
|
|
68
81
|
/**
|
|
@@ -72,6 +85,11 @@ export interface CacheTiersOptions {
|
|
|
72
85
|
readonly firstDialGraceMs?: number | undefined;
|
|
73
86
|
/** The client a `redis` rung reads, for the URL `env` names. Default core's `redisClient`. */
|
|
74
87
|
readonly redisClient?: ((url: string) => RedisLike) | undefined;
|
|
88
|
+
/**
|
|
89
|
+
* The invalidation bus over Redis pub/sub, for the URL `env` names — used only when `transport`
|
|
90
|
+
* is the in-process bus (`selectCacheBus`). Default `@ultimat3/cache`'s `redisPubSubAt`.
|
|
91
|
+
*/
|
|
92
|
+
readonly redisPubSub?: ((url: string) => InvalidationBus) | undefined;
|
|
75
93
|
}
|
|
76
94
|
|
|
77
95
|
/**
|
|
@@ -167,6 +185,10 @@ function buildTier(name: CacheTierName, options: CacheTiersOptions): CacheTier {
|
|
|
167
185
|
*/
|
|
168
186
|
function warnUnnamed(options: CacheTiersOptions): void {
|
|
169
187
|
const named = new Set(options.tiers);
|
|
188
|
+
for (const tier of options.supplied ?? []) {
|
|
189
|
+
if (!named.has(tier.name))
|
|
190
|
+
logger.warn('cache.tier.unnamed', { tier: tier.name, source: 'runtime.ts' });
|
|
191
|
+
}
|
|
170
192
|
const redis = redisUrlSource(options.env);
|
|
171
193
|
if (!named.has('redis') && redis !== undefined) {
|
|
172
194
|
logger.warn('cache.tier.unnamed', { tier: 'redis', source: redis.key });
|
|
@@ -201,12 +223,22 @@ export function startCacheTiers(options: CacheTiersOptions): () => Promise<void>
|
|
|
201
223
|
// Nothing installs a read tier beyond these, and that is the point: `invalidateTags` fans out to
|
|
202
224
|
// registered tiers and to nothing else, so a read cache holding entries of its own was a
|
|
203
225
|
// `cache:` query an action's `invalidates` could never bust.
|
|
204
|
-
|
|
226
|
+
// A supplied rung is used as handed over; the last of one name wins, as `registerTier` would.
|
|
227
|
+
const supplied = new Map((options.supplied ?? []).map((tier) => [tier.name, tier] as const));
|
|
228
|
+
const built = options.tiers.map((name) => supplied.get(name) ?? buildTier(name, options));
|
|
205
229
|
for (const tier of built) registerTier(tier);
|
|
206
230
|
warnUnnamed(options);
|
|
231
|
+
// NATS (or a supplied transport) when it crosses processes; Redis pub/sub when the transport is
|
|
232
|
+
// the in-process bus and REDIS_URL is set; else in-process. One rule, one boot line.
|
|
233
|
+
const selected = selectCacheBus({
|
|
234
|
+
env: options.env,
|
|
235
|
+
transport: options.transport,
|
|
236
|
+
redisPubSub: options.redisPubSub,
|
|
237
|
+
});
|
|
238
|
+
logCacheBus(selected);
|
|
239
|
+
const bus = selected.bus;
|
|
207
240
|
|
|
208
|
-
const send = (payload: string): Promise<void> =>
|
|
209
|
-
options.transport.publish(CACHE_INVALIDATE_SUBJECT, payload);
|
|
241
|
+
const send = (payload: string): Promise<void> => bus.publish(CACHE_INVALIDATE_SUBJECT, payload);
|
|
210
242
|
// What the bus refused, kept for its return. A publish with no live connection is refused, not
|
|
211
243
|
// buffered (`NatsTransport`), so without this a bust made during a two-second NATS restart
|
|
212
244
|
// reached no peer at all. De-duplicated — a tag is a fact, not an event — and bounded.
|
|
@@ -311,15 +343,12 @@ export function startCacheTiers(options: CacheTiersOptions): () => Promise<void>
|
|
|
311
343
|
const bootedAt = performance.now();
|
|
312
344
|
/** Whether an operator has been told of this outage — what makes `recovered` worth a line. */
|
|
313
345
|
let warned = false;
|
|
314
|
-
const subscribing = (async (): Promise<
|
|
346
|
+
const subscribing = (async (): Promise<InvalidationSubscription | undefined> => {
|
|
315
347
|
for (let attempt = 1; !stopped; attempt += 1) {
|
|
316
348
|
try {
|
|
317
|
-
const subscription = await
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
void applyBroadcast(payload);
|
|
321
|
-
},
|
|
322
|
-
);
|
|
349
|
+
const subscription = await bus.subscribe(CACHE_INVALIDATE_SUBJECT, (payload: string) => {
|
|
350
|
+
void applyBroadcast(payload);
|
|
351
|
+
});
|
|
323
352
|
subscribed = true;
|
|
324
353
|
if (attempt > 1) {
|
|
325
354
|
// The outage's one closing line, beside the thinned warnings it ends — and only then: a
|
|
@@ -352,7 +381,7 @@ export function startCacheTiers(options: CacheTiersOptions): () => Promise<void>
|
|
|
352
381
|
})();
|
|
353
382
|
// The bus is (back) up. The subscription came back with the connection, so from here this
|
|
354
383
|
// process hears again: drop what it held while deaf, and say what it could not say.
|
|
355
|
-
const offReconnect =
|
|
384
|
+
const offReconnect = bus.onReconnect(() => {
|
|
356
385
|
wake();
|
|
357
386
|
if (subscribed) flushDeaf('cache.bus-reconnect');
|
|
358
387
|
settleQuietly();
|
|
@@ -366,6 +395,7 @@ export function startCacheTiers(options: CacheTiersOptions): () => Promise<void>
|
|
|
366
395
|
released.resolve(undefined);
|
|
367
396
|
(await subscribing)?.unsubscribe();
|
|
368
397
|
resetTiers();
|
|
398
|
+
await selected.release();
|
|
369
399
|
};
|
|
370
400
|
}
|
|
371
401
|
|
|
@@ -119,9 +119,10 @@ const isRedirectMarker = (entry: IsrEntry): boolean => {
|
|
|
119
119
|
* fence was sampled, and the controller refuses to store a render its fence no longer covers — so
|
|
120
120
|
* the marker this producer returns is never published, and never served from the store.
|
|
121
121
|
*/
|
|
122
|
-
function dropPage(isr: IsrController, key: string): void {
|
|
123
|
-
|
|
124
|
-
isr.
|
|
122
|
+
async function dropPage(isr: IsrController, key: string): Promise<void> {
|
|
123
|
+
// Awaited, so the producer returns only once a shared store has dropped it too.
|
|
124
|
+
await isr.store().delete(key);
|
|
125
|
+
await isr.markStale(key);
|
|
125
126
|
}
|
|
126
127
|
|
|
127
128
|
/**
|
|
@@ -181,7 +182,7 @@ export async function isrOutcome(arrived: IsrRequest): Promise<IsrOutcome> {
|
|
|
181
182
|
// Set by THIS request's producer only. On a stale page it runs behind the answer, and when it
|
|
182
183
|
// has already decided by the time `serve` returns, the redirect is still this request's own.
|
|
183
184
|
decided = to;
|
|
184
|
-
dropPage(isr, key);
|
|
185
|
+
await dropPage(isr, key);
|
|
185
186
|
return { html: '', status: to.status };
|
|
186
187
|
}),
|
|
187
188
|
);
|
package/src/runtime-jobs.ts
CHANGED
|
@@ -82,8 +82,8 @@ export function workerConfigOf(config: AppConfig | undefined, env: Env = {}): Wo
|
|
|
82
82
|
|
|
83
83
|
/**
|
|
84
84
|
* The queues a worker serves: the configured ones, then every queue a registered job is enqueued
|
|
85
|
-
* on. The union and not the list, decided 2026-09-23:
|
|
86
|
-
* `
|
|
85
|
+
* on. The union and not the list, decided 2026-09-23: an app configured `['<app>-default']` (what
|
|
86
|
+
* `x new` wrote until 31.0.0) while a `job()` naming no queue lands on `default`, so the list alone
|
|
87
87
|
* would leave every such job queued for ever — the silent direction. `exact` (a Deployment that
|
|
88
88
|
* set `WORKER_QUEUES`) is the list alone: that operator split the queues across Deployments on
|
|
89
89
|
* purpose, and widening one to the rest is what made their grace periods mean nothing (#673).
|