@ultimat3/cli 30.8.0 → 31.0.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 +75 -64
- package/README.md +4 -1
- package/package.json +30 -29
- package/src/admin-registration.ts +1 -1
- package/src/affected.ts +5 -1
- 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/cmd-auth.ts +3 -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-routes.ts +2 -2
- package/src/cmd-secrets-spec.ts +4 -1
- package/src/cmd-shot.ts +14 -4
- 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.ts +23 -19
- 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 +18 -4
- package/src/mcp-host.ts +5 -1
- package/src/mcp-ui-interact.ts +3 -0
- package/src/messages-gate.ts +4 -0
- package/src/new-shapes-generate.ts +1 -1
- package/src/otlp-export.ts +94 -29
- package/src/output.ts +3 -7
- package/src/page-sync.ts +3 -1
- 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/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/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 +161 -0
- package/src/verify-changed.ts +174 -0
- package/src/verify-checks.ts +31 -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/write-line.ts +21 -6
- package/wiki/Actions.md +2 -2
- package/wiki/Adapters.md +400 -0
- package/wiki/Admin-Dashboard.md +2 -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 +34 -7
- 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 +48 -2
- 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 +31 -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 +69 -56
- 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 +129 -4
package/src/mcp-errors.ts
CHANGED
|
@@ -26,7 +26,7 @@ const CLI_FIXES: Readonly<Record<CliErrorCode, string>> = {
|
|
|
26
26
|
// repo, and the suite that applies it is what reproduces the finding. A placeholder command
|
|
27
27
|
// would fail this table's own no-`<placeholder>` rule, and rightly — it would not run.
|
|
28
28
|
X_CLI_FLAG_UNREAD:
|
|
29
|
-
'bun test packages/cli/src/flag-reads.test.ts # the finding names the flag and the file to read it in',
|
|
29
|
+
'bun test ./packages/cli/src/flag-reads.test.ts # the finding names the flag and the file to read it in',
|
|
30
30
|
X_VERIFY_FAILED: 'x verify --json',
|
|
31
31
|
// Outside an app `x` is on no PATH, and `bunx x` fetches an unrelated npm package named `x`.
|
|
32
32
|
X_NOT_IN_APP: 'bunx create-ultimate myapp --json && cd myapp',
|
|
@@ -57,7 +57,7 @@ const CLI_FIXES: Readonly<Record<CliErrorCode, string>> = {
|
|
|
57
57
|
X_TEST_SHARD_FAILED: 'x verify --only unit --shard 1/2 --json',
|
|
58
58
|
X_SCAFFOLD_PATH_ESCAPE: 'x g route posts --json # a path with no ".." segment',
|
|
59
59
|
X_GENERATE_JSON_INVALID:
|
|
60
|
-
'bun test packages/cli/src/cmd-generate.test.ts # the error names the template to fix',
|
|
60
|
+
'bun test ./packages/cli/src/cmd-generate.test.ts # the error names the template to fix',
|
|
61
61
|
X_APP_PACKAGE_INVALID: 'bun pm pkg set name=my-app version=0.1.0',
|
|
62
62
|
X_ERROR_CODE_UNKNOWN: 'x errors list --json',
|
|
63
63
|
X_DECLARATION_UNKNOWN: 'x actions list --json',
|
|
@@ -179,7 +179,8 @@ const CLI_FIXES: Readonly<Record<CliErrorCode, string>> = {
|
|
|
179
179
|
// which is not what is running when a `ROLE=wroker` pod refuses to boot.
|
|
180
180
|
X_ROLE_UNKNOWN: 'docker run -e ROLE=web my-app:latest',
|
|
181
181
|
X_PORT_INVALID: 'docker run -e PORT=3000 my-app:latest',
|
|
182
|
-
X_RUNTIME_DRIVER_SPLIT:
|
|
182
|
+
X_RUNTIME_DRIVER_SPLIT:
|
|
183
|
+
'x dev --json # the boot names the driver; move it to `export const runtime = { jobs }` in apps/web/runtime.ts',
|
|
183
184
|
X_GENERATE_CONFLICT: 'x g route posts --force --json',
|
|
184
185
|
X_APP_NAME_EMPTY:
|
|
185
186
|
'x new my-app --json # a name with letters or digits; it becomes the directory',
|
|
@@ -387,13 +388,26 @@ const CLI_FIXES: Readonly<Record<CliErrorCode, string>> = {
|
|
|
387
388
|
X_ASSET_VARIANT_UNDECLARED:
|
|
388
389
|
"responsiveImage({ src: asset('assets/hero.png'), width, height, alt }) # no widths/formats override for a site asset; an upload under /media answers any width",
|
|
389
390
|
X_NEW_SHAPE_GENERATE_FAILED:
|
|
390
|
-
'bunx x g sign-in --password --json # in the app x new wrote, reproduces it; then bun test packages/cli/src/templates/shapes',
|
|
391
|
+
'bunx x g sign-in --password --json # in the app x new wrote, reproduces it; then bun test ./packages/cli/src/templates/shapes',
|
|
391
392
|
X_ISLAND_DISPOSER_MISSING:
|
|
392
393
|
'x verify --only boundaries --json # names the file; end its mount() with return render(() => <Island {...props} />, el)',
|
|
393
394
|
X_SOCKET_HAND_ROLLED:
|
|
394
395
|
'x verify --only boundaries --json — names the file and line; delete the upgrade and declare the socket with deviceSocket({ path, resolveToken, onFrame }) from @ultimat3/realtime/server',
|
|
395
396
|
X_EXERCISE_FILE_UNEDITABLE:
|
|
396
397
|
'edit apps/web/exercise.ts — paste the entry the finding names into export const exercise = defineExercise({ … })',
|
|
398
|
+
X_ERROR_REPORTER_DSN_UNCLAIMED:
|
|
399
|
+
'edit apps/web/runtime.ts — errorReporter: sentryTransport(yourWrapper) around the wrapper that sends to Sentry, or localErrorSink(yourSink) for a reporter that keeps reports on the box',
|
|
400
|
+
X_BOUNDARY_ADAPTER_IMPORT:
|
|
401
|
+
'export const runtime = { jobs: yourDriver } satisfies RuntimeOverrides; # in apps/web/runtime.ts — name the port your import installed',
|
|
402
|
+
X_PREBUILT_REGISTRY_STALE:
|
|
403
|
+
'edit docker/Dockerfile: move RUN bun node_modules/@ultimat3/cli/src/bin.ts build --target prebuilt after the last COPY in the runtime stage, then rebuild the image',
|
|
404
|
+
X_APP_ROOT_NESTED:
|
|
405
|
+
'x verify --only drift --json # after deleting the nested app.config.ts and moving what it configured into the root app.config.ts',
|
|
406
|
+
X_WORKSPACE_NAME_TAKEN: 'x g app admin-app --dry-run --json',
|
|
407
|
+
X_PARTITIONS_UNMAINTAINED:
|
|
408
|
+
'x verify --only manifest --json # after exporting partitions() from @ultimat3/jobs in a module listed under jobs in apps/web/api/index.ts, and its .schedule under tasks',
|
|
409
|
+
X_BOUNDARY_LOADER_IMPORT:
|
|
410
|
+
'export const api = defineApi({ actions: [yourActions], queries: [yourQueries] }); # in apps/web/api/index.ts — list the module there, then delete the loader import',
|
|
397
411
|
};
|
|
398
412
|
|
|
399
413
|
const isCliCode = (code: string): code is CliErrorCode =>
|
package/src/mcp-host.ts
CHANGED
|
@@ -39,6 +39,7 @@ import type {
|
|
|
39
39
|
import { DEV_SCOPES, devHost, devMcpServer, frameworkIntrospection } from '@ultimat3/mcp';
|
|
40
40
|
import { loadApp } from './app-load';
|
|
41
41
|
import { appManifest, policyFacts } from './app-manifest';
|
|
42
|
+
import { loadAppRuntime } from './app-runtime';
|
|
42
43
|
import { loadAppGraph, resolveNode } from './cmd-graph-load';
|
|
43
44
|
import { runVerify, VERIFY_STEPS } from './cmd-verify';
|
|
44
45
|
import { declareDevEnvironment } from './dev-environment';
|
|
@@ -109,7 +110,10 @@ export function lazyServices(input: DevHostInput): LazyServices {
|
|
|
109
110
|
// way out was restarting the host — `startServices` unwinds everything it started before it
|
|
110
111
|
// rejects, so there is nothing left over for a second attempt to collide with.
|
|
111
112
|
// `[]`: this host starts no role, so it only ever publishes to the bus and never waits for it.
|
|
112
|
-
|
|
113
|
+
// The app's `runtime.ts`, read per attempt as `x dev` reads it: its ports, its clock, its key.
|
|
114
|
+
const boot = retryMemo(async () =>
|
|
115
|
+
startServices(services, input.env, await loadAppRuntime(input.root), 'apply', []),
|
|
116
|
+
);
|
|
113
117
|
let closed = false;
|
|
114
118
|
return {
|
|
115
119
|
services,
|
package/src/mcp-ui-interact.ts
CHANGED
|
@@ -270,6 +270,9 @@ export async function interactRoute(
|
|
|
270
270
|
timeoutMs: DEFAULT_PAGE_TIMEOUT_MS,
|
|
271
271
|
fullPage: input.fullPage,
|
|
272
272
|
colorScheme: input.colorScheme,
|
|
273
|
+
// The same clock `runSteps` below runs on: without it the settle window is a real 2000 ms of
|
|
274
|
+
// wall time per call, whatever `deps.sleep` says — the cost that made this suite time out.
|
|
275
|
+
sleep,
|
|
273
276
|
act: async (page, settle) => {
|
|
274
277
|
ran.landedOn = page.url();
|
|
275
278
|
ran.run = await runSteps(page, steps, settle, origin, sleep);
|
package/src/messages-gate.ts
CHANGED
|
@@ -80,6 +80,10 @@ export const GATE_MESSAGES = {
|
|
|
80
80
|
// The `errors` step's own coverage, in `output`: a scan without a parser reads most fix lines
|
|
81
81
|
// and not all of them, and a step that reports findings alone claims a completeness it lacks.
|
|
82
82
|
'cli.verify.fixCoverage': 'checked {checked} fix line(s), could not read {unreadable}',
|
|
83
|
+
// The `drift` step on an app whose only store is a `defineDriver` one: migrations describe
|
|
84
|
+
// Postgres, and that store owns its schema — said in `output`, so the step is not a silent green.
|
|
85
|
+
'cli.verify.driftNonSql':
|
|
86
|
+
'skipped: no SQL driver is configured — the app stores rows in {stores}, which owns its schema; migrations, drift and x db describe Postgres only',
|
|
83
87
|
// Why a skipped step is a dash when the step can say so: the suite exists and not one of its
|
|
84
88
|
// tests ran. Each test's own name carries the reason it skipped, and `bun test` prints only the
|
|
85
89
|
// counts — so the line says how many and `x test <type>` prints the names.
|
|
@@ -26,7 +26,7 @@ export class NewShapeGenerateError extends UltimateError {
|
|
|
26
26
|
`cd ${renderFixShellArg(input.target, '<the new app directory>')}`,
|
|
27
27
|
'&&',
|
|
28
28
|
...['bunx', 'x', ...input.argv, '--json'].map(quoteArg),
|
|
29
|
-
' # reproduces it; then bun test packages/cli/src/templates/shapes',
|
|
29
|
+
' # reproduces it; then bun test ./packages/cli/src/templates/shapes',
|
|
30
30
|
].join(' '),
|
|
31
31
|
});
|
|
32
32
|
}
|
package/src/otlp-export.ts
CHANGED
|
@@ -3,77 +3,142 @@
|
|
|
3
3
|
// deployment configured a collector, the collector received nothing, and the only signal that
|
|
4
4
|
// anything was wrong was an empty dashboard.
|
|
5
5
|
|
|
6
|
+
import type { OtlpSignal, ShutdownReason } from '@ultimat3/core';
|
|
6
7
|
import {
|
|
7
|
-
configureMetrics,
|
|
8
|
-
configureTelemetry,
|
|
9
8
|
logger,
|
|
10
|
-
noopExporter,
|
|
11
|
-
noopMetricExporter,
|
|
12
9
|
onShutdown,
|
|
10
|
+
otlpEndpointLabel,
|
|
11
|
+
otlpLogExporter,
|
|
13
12
|
otlpMetricExporter,
|
|
14
13
|
otlpSpanExporter,
|
|
15
14
|
startMetricExport,
|
|
15
|
+
subscribe,
|
|
16
|
+
subscribeSemconvMetrics,
|
|
17
|
+
systemClock,
|
|
16
18
|
tryOtlpEndpoint,
|
|
17
19
|
} from '@ultimat3/core';
|
|
18
20
|
import type { Env } from './runtime-bindings';
|
|
19
21
|
|
|
22
|
+
/**
|
|
23
|
+
* The endpoint a signal exports to, unless `OTEL_<SIGNAL>_EXPORTER=none` switched it off or
|
|
24
|
+
* `OTEL_SDK_DISABLED=true` switched every signal off — the OpenTelemetry spellings, read as the
|
|
25
|
+
* spec does: case-insensitive, surrounding space ignored (`NONE`, `none `). The generic
|
|
26
|
+
* `OTEL_EXPORTER_OTLP_ENDPOINT` names all three signals, and a collector with no logs pipeline
|
|
27
|
+
* would answer every logs batch with a 404.
|
|
28
|
+
*/
|
|
29
|
+
export function signalEndpoint(signal: OtlpSignal, env: Env): string | undefined {
|
|
30
|
+
if (envWord(env['OTEL_SDK_DISABLED']) === 'true') return undefined;
|
|
31
|
+
if (envWord(env[`OTEL_${signal.toUpperCase()}_EXPORTER`]) === 'none') return undefined;
|
|
32
|
+
return tryOtlpEndpoint(signal, env);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const envWord = (value: string | undefined): string => (value ?? '').trim().toLowerCase();
|
|
36
|
+
|
|
20
37
|
/** How often counters are pushed. Core's own default; named here because the boot chose it. */
|
|
21
38
|
export const METRIC_EXPORT_INTERVAL_MS = 60_000;
|
|
22
39
|
|
|
23
40
|
/**
|
|
24
|
-
* Install whichever exporters an endpoint was configured for,
|
|
41
|
+
* Install whichever exporters an endpoint was configured for — traces, metrics, logs — plus the
|
|
42
|
+
* semconv histograms every boot records, and return the release.
|
|
25
43
|
*
|
|
26
44
|
* `tryOtlpEndpoint` is asked FIRST, per signal, because both constructors throw
|
|
27
45
|
* `X_OTLP_ENDPOINT_INVALID` when nothing configured one — deliberately, so that a telemetry
|
|
28
46
|
* exporter can never silently send nowhere. Asking is what makes the exporter optional without
|
|
29
47
|
* making it silent.
|
|
30
48
|
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
49
|
+
* ONE drain hook flushes every signal, in PARALLEL and capped at what is left of the drain's
|
|
50
|
+
* deadline (`flushWithin`): three hooks in turn, each waiting out its own 10 s export budget against
|
|
51
|
+
* a black-holed collector, overran a 25 s drain and turned a clean exit into `X_SHUTDOWN_TIMEOUT`.
|
|
52
|
+
* `phase: 'close'`: the last spans of a drain are the ones that explain it. That phase runs
|
|
53
|
+
* last-registered first, so the boot calls this BEFORE anything whose teardown should be seen.
|
|
35
54
|
*
|
|
36
|
-
* The release UNINSTALLS what it installed, per signal. `
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
* installed no exporter must not uninstall one it never owned.
|
|
55
|
+
* The release UNINSTALLS what it installed, per signal. Spans are a `span.end` SUBSCRIPTION on
|
|
56
|
+
* core's instrumentation bus and the release is its unsubscribe, so a second `serveApp` in the same
|
|
57
|
+
* process never exports into a released exporter, and `x dev`'s trace RECORDER — its own subscriber
|
|
58
|
+
* — is untouched. Each exporter is SHUT DOWN before it is unsubscribed — its queued batch goes out
|
|
59
|
+
* and its timer stops, rather than being dropped and leaked. Metrics are the same shape since
|
|
60
|
+
* 31.0.0: a `metric.export` subscription, released by its unsubscribe.
|
|
43
61
|
*/
|
|
44
62
|
export function startOtlpExport(env: Env = process.env): () => void {
|
|
45
63
|
const releases: (() => void)[] = [];
|
|
64
|
+
const flushes: (() => Promise<void>)[] = [];
|
|
65
|
+
|
|
66
|
+
// Every boot, collector or not: the semconv histograms (`db_client_operation_duration_seconds`,
|
|
67
|
+
// `job_duration_seconds`, `gen_ai_client_token_usage`) are bus subscribers, and `/metrics` serves
|
|
68
|
+
// them to a scrape-only deployment exactly as OTLP pushes them to a collector. Pushed first, so
|
|
69
|
+
// the reversed release below drops them last — the drain's own statements are still counted.
|
|
70
|
+
releases.push(subscribeSemconvMetrics());
|
|
46
71
|
|
|
47
72
|
// The boot's OWN env, not `process.env`, and the resolved endpoint is then passed to the
|
|
48
73
|
// exporter explicitly: `runRole({ env })` is a real seam — a test and an in-process host both
|
|
49
74
|
// pass an env that is not the process's — and an exporter that re-read `process.env` would
|
|
50
75
|
// answer a different question from the one this function just asked.
|
|
51
|
-
const traces =
|
|
76
|
+
const traces = signalEndpoint('traces', env);
|
|
52
77
|
if (traces !== undefined) {
|
|
53
78
|
const exporter = otlpSpanExporter({ endpoint: traces });
|
|
54
|
-
configureTelemetry({ exporter });
|
|
55
79
|
// Pushed first, so the reversed run below applies it LAST — after the drain hook is dropped,
|
|
56
80
|
// the same order `dev-boot.ts` releases the recorder in.
|
|
57
|
-
releases.push(() =>
|
|
58
|
-
releases.push(
|
|
59
|
-
|
|
81
|
+
releases.push(subscribe('span.end', (event) => exporter.export(event.payload)));
|
|
82
|
+
releases.push(() => void exporter.shutdown());
|
|
83
|
+
flushes.push(() => exporter.shutdown());
|
|
84
|
+
logger.info('ultimate otlp traces', { endpoint: otlpEndpointLabel(traces) });
|
|
60
85
|
}
|
|
61
86
|
|
|
62
|
-
const metrics =
|
|
87
|
+
const metrics = signalEndpoint('metrics', env);
|
|
63
88
|
if (metrics !== undefined) {
|
|
64
89
|
const exporter = otlpMetricExporter({ endpoint: metrics });
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
//
|
|
68
|
-
//
|
|
69
|
-
// the drain's — for the whole life of the process.
|
|
90
|
+
releases.push(subscribe('metric.export', (event) => exporter.export(event.payload)));
|
|
91
|
+
// The push loop, and not only the subscription: it names where a snapshot goes and nothing
|
|
92
|
+
// decides when one is taken, so without this the collector receives one export — the
|
|
93
|
+
// drain's — for the whole life of the process.
|
|
70
94
|
const stopTimer = startMetricExport(METRIC_EXPORT_INTERVAL_MS);
|
|
71
95
|
releases.push(stopTimer);
|
|
72
|
-
|
|
73
|
-
logger.info('ultimate otlp metrics', { endpoint: metrics });
|
|
96
|
+
flushes.push(() => exporter.flush());
|
|
97
|
+
logger.info('ultimate otlp metrics', { endpoint: otlpEndpointLabel(metrics) });
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const logs = signalEndpoint('logs', env);
|
|
101
|
+
if (logs !== undefined) {
|
|
102
|
+
const exporter = otlpLogExporter({ endpoint: logs });
|
|
103
|
+
// Synchronously inside the handler: the exporter reads the ACTIVE span there, which is what
|
|
104
|
+
// joins a log line to its trace in the collector. Only the process logger's lines reach the
|
|
105
|
+
// bus, after redaction — never a logger given its own writer.
|
|
106
|
+
releases.push(subscribe('log.record', (event) => exporter.export(event.payload)));
|
|
107
|
+
releases.push(() => void exporter.shutdown());
|
|
108
|
+
flushes.push(() => exporter.shutdown());
|
|
109
|
+
logger.info('ultimate otlp logs', { endpoint: otlpEndpointLabel(logs) });
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
if (flushes.length > 0) {
|
|
113
|
+
releases.push(onShutdown('otlp', (reason) => flushWithin(flushes, reason), { phase: 'close' }));
|
|
74
114
|
}
|
|
75
115
|
|
|
76
116
|
return () => {
|
|
77
117
|
for (const release of releases.reverse()) release();
|
|
78
118
|
};
|
|
79
119
|
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* What is left of the drain's budget a flush may spend: most of it, so the hooks behind this one
|
|
123
|
+
* and the exit still fit. Real monotonic time, as `ShutdownReason.deadlineAt` is.
|
|
124
|
+
*/
|
|
125
|
+
export const OTLP_FLUSH_SHARE = 0.8;
|
|
126
|
+
|
|
127
|
+
/** Every signal's flush at once, abandoned (not awaited further) when the share is spent. */
|
|
128
|
+
export async function flushWithin(
|
|
129
|
+
flushes: readonly (() => Promise<void>)[],
|
|
130
|
+
reason: Pick<ShutdownReason, 'deadlineAt'>,
|
|
131
|
+
): Promise<void> {
|
|
132
|
+
const budget = Math.max(0, (reason.deadlineAt - systemClock.monotonic()) * OTLP_FLUSH_SHARE);
|
|
133
|
+
let timer: ReturnType<typeof setTimeout> | undefined;
|
|
134
|
+
const spent = new Promise<'spent'>((resolve) => {
|
|
135
|
+
timer = setTimeout(() => resolve('spent'), budget);
|
|
136
|
+
timer.unref();
|
|
137
|
+
});
|
|
138
|
+
const all = Promise.allSettled(flushes.map((flush) => flush())).then(() => 'flushed' as const);
|
|
139
|
+
const outcome = await Promise.race([all, spent]);
|
|
140
|
+
clearTimeout(timer);
|
|
141
|
+
if (outcome === 'spent') {
|
|
142
|
+
logger.warn('otlp flush abandoned at the drain deadline', { signals: flushes.length });
|
|
143
|
+
}
|
|
144
|
+
}
|
package/src/output.ts
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
// output (axiom 4). The human renderer owns the canonical 3-line error format.
|
|
4
4
|
|
|
5
5
|
import { ERROR_DOCS_URL, renderThrowable, singleLine, stringField } from '@ultimat3/core';
|
|
6
|
+
import type { JsonValue } from '@ultimat3/schema';
|
|
6
7
|
import { unresolvedImportFinding } from './app-load-unresolved';
|
|
7
8
|
import { msg } from './messages';
|
|
8
9
|
import { causeWithCount, findingsForReader, type ReaderOptions } from './output-findings';
|
|
@@ -92,13 +93,8 @@ export interface StepResult {
|
|
|
92
93
|
readonly tests?: TestCounts;
|
|
93
94
|
}
|
|
94
95
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
| number
|
|
98
|
-
| boolean
|
|
99
|
-
| null
|
|
100
|
-
| readonly JsonValue[]
|
|
101
|
-
| { readonly [key: string]: JsonValue };
|
|
96
|
+
// `@ultimat3/schema`'s one declaration, re-exported for this package's callers — never restated.
|
|
97
|
+
export type { JsonValue };
|
|
102
98
|
|
|
103
99
|
export interface CommandResult {
|
|
104
100
|
readonly ok: boolean;
|
package/src/page-sync.ts
CHANGED
|
@@ -41,7 +41,7 @@ export async function pageSync(
|
|
|
41
41
|
root: string,
|
|
42
42
|
env: Readonly<Record<string, string | undefined>>,
|
|
43
43
|
buildId: string,
|
|
44
|
-
realtime: Pick<RealtimeConfig, 'enabled'>,
|
|
44
|
+
realtime: Pick<RealtimeConfig, 'enabled' | 'maxQueued'>,
|
|
45
45
|
): Promise<PageSync> {
|
|
46
46
|
// Off: no `ultimate-sync`, no worker, no boot script — the boot is the outbox and the disk
|
|
47
47
|
// restore, which exist to feed the socket. Checked before either build, which would be wasted.
|
|
@@ -59,6 +59,8 @@ export async function pageSync(
|
|
|
59
59
|
buildId,
|
|
60
60
|
...(worker === undefined ? {} : { workerUrl: worker.url }),
|
|
61
61
|
...(boot === undefined ? {} : { bootUrl: boot.url }),
|
|
62
|
+
// The page outbox's ceiling: the boot builds the outbox, and reads it off the document.
|
|
63
|
+
...(realtime.maxQueued === undefined ? {} : { outboxMaxQueued: realtime.maxQueued }),
|
|
62
64
|
},
|
|
63
65
|
persisted: persistedRecordTypes,
|
|
64
66
|
};
|
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
|
+
});
|