@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/runtime-purge.ts
CHANGED
|
@@ -47,18 +47,20 @@ export const PURGE_TASK_NAME = 'x.purge.hourly';
|
|
|
47
47
|
* deletes reservations a retry is still entitled to.
|
|
48
48
|
*
|
|
49
49
|
* The auth limiter is absent on purpose: it does not exist yet at boot. `defineAuth` builds it
|
|
50
|
-
* through the
|
|
50
|
+
* through the `authLimiter` port's factory, and that happens when the app's modules
|
|
51
51
|
* import — after this. `purgeAuthLimits()` is the seam that reads whatever was built.
|
|
52
52
|
*/
|
|
53
53
|
export interface RetentionStores {
|
|
54
|
-
|
|
55
|
-
readonly
|
|
54
|
+
/** `undefined` when `runtime.ts` supplied the store: the app's backend is the app's to expire. */
|
|
55
|
+
readonly idempotency: PostgresIdempotencyStore | undefined;
|
|
56
|
+
/** `undefined` for `idempotency`'s reason. */
|
|
57
|
+
readonly rateLimit: PostgresRateLimitStore | undefined;
|
|
56
58
|
/**
|
|
57
|
-
* The guard this boot
|
|
58
|
-
*
|
|
59
|
-
* factor for the life of the deployment.
|
|
59
|
+
* The guard this boot built for the `totpReplay` port. Unlike the limiter it takes nothing from
|
|
60
|
+
* the app, so it exists here. Passed whenever the boot built it, or `x_totp_steps` keeps a row
|
|
61
|
+
* per second factor for the life of the deployment; `undefined` when `runtime.ts` supplied one.
|
|
60
62
|
*/
|
|
61
|
-
readonly totpReplay: PostgresTotpReplayGuard;
|
|
63
|
+
readonly totpReplay: PostgresTotpReplayGuard | undefined;
|
|
62
64
|
/**
|
|
63
65
|
* The bus this boot installed for `step.waitForEvent`. REQUIRED: `x_job_events` takes a row per
|
|
64
66
|
* publish and `find` only filters an expired one, so a boot that left it out is the table
|
|
@@ -85,9 +87,9 @@ export interface RetentionStores {
|
|
|
85
87
|
|
|
86
88
|
/**
|
|
87
89
|
* The three notify tables, and no store is in `RetentionStores` — deliberately, and for the
|
|
88
|
-
* reason `authTarget` is not either. `
|
|
89
|
-
*
|
|
90
|
-
*
|
|
90
|
+
* reason `authTarget` is not either. The `notifyStores` port is `runtime.ts`'s and the boot builds
|
|
91
|
+
* no default (`framework-schema.ts` applies the DDL whether or not one is supplied). So the sweep
|
|
92
|
+
* can only ask,
|
|
91
93
|
* per attempt, what is installed now — `purgeNotifyInbox`/`purgeNotifyDeliveries` answer 0 for a
|
|
92
94
|
* memory store or none at all, which is a boot that made a decision, not a failure.
|
|
93
95
|
*/
|
|
@@ -122,7 +124,7 @@ function notifyTargets(retention: InboxRetention): readonly PurgeTarget[] {
|
|
|
122
124
|
/**
|
|
123
125
|
* Read per attempt by the job, and emptied by the disposer `installRetentionSweep` returns: a
|
|
124
126
|
* sweep left declared after its boot has stopped must not reach through a closed pool. Module
|
|
125
|
-
* scope for the reason
|
|
127
|
+
* scope for the reason the installed job driver and `installKdfGate` are — a process has one boot at a
|
|
126
128
|
* time, and the registry the job lives in is process-wide too.
|
|
127
129
|
*/
|
|
128
130
|
let installed: readonly PurgeTarget[] = [];
|
|
@@ -141,26 +143,37 @@ const authTarget: PurgeTarget = {
|
|
|
141
143
|
purgeExpired: () => purgeAuthLimits(),
|
|
142
144
|
};
|
|
143
145
|
|
|
146
|
+
/** The sweep over a store this boot built, or none when `runtime.ts` supplied it. */
|
|
147
|
+
const own = (target: PurgeTarget | undefined): readonly PurgeTarget[] =>
|
|
148
|
+
target === undefined ? [] : [target];
|
|
149
|
+
|
|
144
150
|
function retentionTargets(stores: RetentionStores): readonly PurgeTarget[] {
|
|
151
|
+
const { idempotency, rateLimit, totpReplay } = stores;
|
|
145
152
|
return [
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
153
|
+
...own(
|
|
154
|
+
idempotency && {
|
|
155
|
+
name: 'x_idempotency',
|
|
156
|
+
purgeExpired: (): Promise<number> => idempotency.purgeExpired(),
|
|
157
|
+
},
|
|
158
|
+
),
|
|
159
|
+
...own(
|
|
160
|
+
rateLimit && {
|
|
161
|
+
name: 'x_rate_limit',
|
|
162
|
+
// The job's clock, not the server's. `last_ms` is written by whichever process took the
|
|
163
|
+
// token, so a purge measured against `now()` in Postgres computes a refill from the offset
|
|
164
|
+
// between two clocks — and against a frozen one it read 20,000,000 seconds of refill and
|
|
165
|
+
// deleted a bucket holding 0 of 4 tokens, which is a free limit reset from the cleanup.
|
|
166
|
+
purgeExpired: (nowMs: number): Promise<number> => rateLimit.purgeExpired(nowMs),
|
|
167
|
+
},
|
|
168
|
+
),
|
|
158
169
|
authTarget,
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
170
|
+
...own(
|
|
171
|
+
totpReplay && {
|
|
172
|
+
name: 'x_totp_steps',
|
|
173
|
+
// The job's clock: `verifyTotp` derived every step in that table from a process's clock.
|
|
174
|
+
purgeExpired: (nowMs: number): Promise<number> => totpReplay.purgeExpired(nowMs),
|
|
175
|
+
},
|
|
176
|
+
),
|
|
164
177
|
...notifyTargets(stores.inboxRetention ?? NO_INBOX_RETENTION),
|
|
165
178
|
// Its own clock, and so no `nowMs`: every instant in that table is the database's.
|
|
166
179
|
eventsPurgeTarget(stores.events),
|
package/src/runtime-push.ts
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
|
|
9
9
|
import type { AppConfig, PgExecutor } from '@ultimat3/core';
|
|
10
10
|
import { logger, PWA_PUSH_FIX, pushWired } from '@ultimat3/core';
|
|
11
|
-
import type { ResolvedVapidKeys } from '@ultimat3/pwa';
|
|
11
|
+
import type { PushSubscriptionStore, ResolvedVapidKeys } from '@ultimat3/pwa';
|
|
12
12
|
import type { Env } from './runtime-bindings';
|
|
13
13
|
|
|
14
14
|
/** `pwa.vapid.subject` when this app's boot owes a push runtime, else `undefined`. */
|
|
@@ -57,10 +57,14 @@ export async function selectWebPush(
|
|
|
57
57
|
};
|
|
58
58
|
}
|
|
59
59
|
|
|
60
|
-
/**
|
|
60
|
+
/**
|
|
61
|
+
* Install the runtime over the boot's executor; answers its release. `store` is `runtime.ts`'s
|
|
62
|
+
* `pushSubscriptionStore` port; omitted, the Postgres store over the boot's pool.
|
|
63
|
+
*/
|
|
61
64
|
export async function installAppWebPush(
|
|
62
65
|
selection: PushSelection,
|
|
63
66
|
executor: PgExecutor,
|
|
67
|
+
store?: PushSubscriptionStore,
|
|
64
68
|
): Promise<() => void> {
|
|
65
69
|
const { installWebPush, postgresPushSubscriptionStore } = await import('@ultimat3/pwa');
|
|
66
70
|
if (selection.resolved.source === 'development') {
|
|
@@ -72,7 +76,7 @@ export async function installAppWebPush(
|
|
|
72
76
|
});
|
|
73
77
|
}
|
|
74
78
|
return installWebPush({
|
|
75
|
-
store: postgresPushSubscriptionStore({ executor }),
|
|
79
|
+
store: store ?? postgresPushSubscriptionStore({ executor }),
|
|
76
80
|
keys: selection.resolved.keys,
|
|
77
81
|
subject: selection.subject,
|
|
78
82
|
pushHosts: selection.pushHosts,
|
package/src/runtime-queue.ts
CHANGED
|
@@ -9,10 +9,6 @@ import {
|
|
|
9
9
|
postgresIdempotencyStore,
|
|
10
10
|
postgresMeterStore,
|
|
11
11
|
requestDeadlineMs,
|
|
12
|
-
resetIdempotency,
|
|
13
|
-
resetMeterStore,
|
|
14
|
-
setIdempotencyStore,
|
|
15
|
-
setMeterStore,
|
|
16
12
|
} from '@ultimat3/action';
|
|
17
13
|
import type { PgliteClient, PostgresClient } from '@ultimat3/db';
|
|
18
14
|
import {
|
|
@@ -34,17 +30,15 @@ import {
|
|
|
34
30
|
postgresEventBus,
|
|
35
31
|
postgresJobDriver,
|
|
36
32
|
postgresOutboxStore,
|
|
37
|
-
resetEventBus,
|
|
38
|
-
resetJobDriver,
|
|
39
33
|
resetJobsFacade,
|
|
40
|
-
setEventBus,
|
|
41
|
-
setJobDriver,
|
|
42
34
|
setJobsFacade,
|
|
43
35
|
} from '@ultimat3/jobs';
|
|
44
36
|
import { applyLockedSchema, ensureSchema, verifySchema } from './framework-schema-apply';
|
|
45
37
|
import { appExtensions } from './migration-extensions';
|
|
46
38
|
import type { DevServices } from './runtime-bindings';
|
|
47
39
|
import type { RuntimeOverrides } from './runtime-overrides';
|
|
40
|
+
import { QUEUE_PORT_BINDINGS } from './runtime-port-bindings-queue';
|
|
41
|
+
import { installPorts, type PortRelease, suppliedOr } from './runtime-ports';
|
|
48
42
|
import { attachReplica, type ReplicaEnv, replicaUrlFor } from './runtime-replica';
|
|
49
43
|
|
|
50
44
|
/** Both embedded and external clients boot lazily and close explicitly. */
|
|
@@ -67,12 +61,13 @@ export interface RunningQueue {
|
|
|
67
61
|
/** The `x_job_events` bus a `step.waitForEvent` resumes from. Durable, not per-process. */
|
|
68
62
|
readonly events: EventBus;
|
|
69
63
|
/**
|
|
70
|
-
* The `x_idempotency` store this boot
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
-
*
|
|
64
|
+
* The `x_idempotency` store this boot BUILT behind `idempotent: true` — `undefined` when
|
|
65
|
+
* `runtime.ts` supplied its own, which is then the app's to expire. Returned for the reason
|
|
66
|
+
* `outbox` is: the retention sweep over that table is a ROLE's work, not the queue's, and it has
|
|
67
|
+
* to sweep the store that was INSTALLED — a second one built beside it would purge on the
|
|
68
|
+
* default window even where this boot had configured another.
|
|
74
69
|
*/
|
|
75
|
-
readonly idempotency: PostgresIdempotencyStore;
|
|
70
|
+
readonly idempotency: PostgresIdempotencyStore | undefined;
|
|
76
71
|
stop(): Promise<void>;
|
|
77
72
|
}
|
|
78
73
|
|
|
@@ -157,18 +152,20 @@ async function applySchema(client: DevDbClient, mode: SchemaMode): Promise<void>
|
|
|
157
152
|
* one-live-job-per-key index all behave here exactly as in production. A memory queue in dev
|
|
158
153
|
* would hide every bug this driver exists to make impossible.
|
|
159
154
|
*
|
|
160
|
-
*
|
|
155
|
+
* Five ambient installs, not one, and they go in together because they are one decision. Each is
|
|
156
|
+
* a port (`ADAPTER_PORTS`): `runtime.ts`'s value or the default below, installed by the
|
|
157
|
+
* one loop in `runtime-ports.ts` (`PORT_BINDINGS`' `queue` rows).
|
|
161
158
|
*
|
|
162
|
-
* - `
|
|
163
|
-
* - `
|
|
164
|
-
* transaction STAGES a row that commits or vanishes with the business rows. Without it the
|
|
159
|
+
* - `jobs` is what `jobDriver()` answers and what a worker claims from.
|
|
160
|
+
* - `outboxStore`, behind the facade, is what `handle.enqueue()` routes through, so an enqueue
|
|
161
|
+
* inside a request's transaction STAGES a row that commits or vanishes with the business rows. Without it the
|
|
165
162
|
* fallback facade publishes straight to the driver, and a job for a transaction that rolled
|
|
166
163
|
* back still runs. `currentTx()` resolves the executor because a `DbTx` IS a client on the
|
|
167
164
|
* transaction's own connection, while the `Tx` token `@ultimat3/entity` hands over is not that
|
|
168
165
|
* object — so the token is a key and the ALS is the lookup.
|
|
169
|
-
* - `
|
|
166
|
+
* - `eventBus` makes `step.waitForEvent` durable. The memory bus this replaced forgot every
|
|
170
167
|
* pending correlation on restart, which is a job that waits forever.
|
|
171
|
-
* - `
|
|
168
|
+
* - `idempotencyStore` makes `idempotent: true` mean it across replicas. The memory default is
|
|
172
169
|
* one process' worth of keys, so a client retrying `POST /api/payments/charge` after a timeout
|
|
173
170
|
* lands on a replica that has never seen the key and charges the card a second time.
|
|
174
171
|
*
|
|
@@ -190,46 +187,66 @@ async function startJobs(
|
|
|
190
187
|
// Bound to `client`, never the ambient `db()`: the queue and the idempotency reservations stay
|
|
191
188
|
// on the boot's pool whatever transaction is open.
|
|
192
189
|
const executor = dbExecutor(() => client);
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
const
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
190
|
+
// Built only when `runtime.ts` is silent: the retention sweep expires the boot's own store and
|
|
191
|
+
// never one the app handed over.
|
|
192
|
+
const idempotency = suppliedOr(overrides?.idempotencyStore, () =>
|
|
193
|
+
postgresIdempotencyStore({
|
|
194
|
+
executor,
|
|
195
|
+
// `baseClient`, read per call and never `client`: a transaction's origin is the AMBIENT
|
|
196
|
+
// client `startDb` installed, which is the replicated pair when a standby is configured.
|
|
197
|
+
origin: baseClient,
|
|
198
|
+
// The app's own `requestTimeoutMs`, read per reservation — declared after this boot.
|
|
199
|
+
reclaimAfterMs: requestDeadlineMs,
|
|
200
|
+
}),
|
|
202
201
|
);
|
|
202
|
+
const idempotencyStore = idempotency.value;
|
|
203
|
+
// Each port: `runtime.ts`'s value, else the env default — one `??`, and nothing else selects.
|
|
204
|
+
const jobs = overrides?.jobs ?? postgresJobDriver({ executor });
|
|
205
|
+
const outboxStore =
|
|
206
|
+
overrides?.outboxStore ??
|
|
207
|
+
postgresOutboxStore({
|
|
208
|
+
executor,
|
|
209
|
+
// The open transaction is a client on its own connection; the `Tx` token is not that object.
|
|
210
|
+
txExecutor: () => dbExecutor(() => currentTx() ?? client),
|
|
211
|
+
});
|
|
203
212
|
// The open transaction's connection, as the outbox beside it: an answer belongs to the unit of
|
|
204
213
|
// work that gave it, so a refusal that rolls back never resumes the run waiting on it.
|
|
205
214
|
//
|
|
206
215
|
// `wakes` only when the queue in hand is the boot's own `postgresJobDriver`: the wake is an update
|
|
207
216
|
// of `x_jobs` on this database, and an override driver (Redis) keeps no rows here — its waiters
|
|
208
217
|
// keep the 30 s poll. Waking, a parked wait's backstop is 15 min instead.
|
|
209
|
-
const
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
executor,
|
|
216
|
-
// `baseClient`, read per call and never `client`: a transaction's origin is the AMBIENT client
|
|
217
|
-
// `startDb` installed, which is the replicated pair when a standby is configured.
|
|
218
|
-
origin: baseClient,
|
|
219
|
-
// The app's own `requestTimeoutMs`, read per reservation — it is declared after this boot.
|
|
220
|
-
reclaimAfterMs: requestDeadlineMs,
|
|
221
|
-
});
|
|
222
|
-
setIdempotencyStore(idempotency);
|
|
218
|
+
const eventBus =
|
|
219
|
+
overrides?.eventBus ??
|
|
220
|
+
postgresEventBus({
|
|
221
|
+
executor: dbExecutor(() => currentTx() ?? client),
|
|
222
|
+
wakes: overrides?.jobs === undefined,
|
|
223
|
+
});
|
|
223
224
|
// `meter:` counters on the boot's pool, never the open transaction: a draw is the caller's
|
|
224
225
|
// whether or not the business write commits, and one tenant's day is one row on every replica.
|
|
225
|
-
|
|
226
|
+
const meterStore = overrides?.meterStore ?? postgresMeterStore({ executor });
|
|
227
|
+
const releases = await installPorts(QUEUE_PORT_BINDINGS, 'queue', {
|
|
228
|
+
jobs,
|
|
229
|
+
eventBus,
|
|
230
|
+
idempotencyStore,
|
|
231
|
+
meterStore,
|
|
232
|
+
});
|
|
233
|
+
// The outbox port is read here, not installed by the loop: the facade `handle.enqueue()` routes
|
|
234
|
+
// through needs BOTH it and the queue, so an enqueue inside a request's transaction STAGES a row
|
|
235
|
+
// that commits or vanishes with the business rows. The `Tx` token is a key; the ALS holds the client.
|
|
236
|
+
setJobsFacade(
|
|
237
|
+
outboxJobsFacade(
|
|
238
|
+
{ store: outboxStore, driver: jobs },
|
|
239
|
+
() => currentTx() as unknown as Tx | undefined,
|
|
240
|
+
),
|
|
241
|
+
);
|
|
242
|
+
releases.push(resetJobsFacade);
|
|
226
243
|
return {
|
|
227
244
|
db: client,
|
|
228
|
-
jobs
|
|
229
|
-
outbox,
|
|
230
|
-
events,
|
|
231
|
-
idempotency,
|
|
232
|
-
stop: () => releaseQueue(client,
|
|
245
|
+
jobs,
|
|
246
|
+
outbox: outboxStore,
|
|
247
|
+
events: eventBus,
|
|
248
|
+
idempotency: idempotency.own,
|
|
249
|
+
stop: () => releaseQueue(client, jobs, replica, releases),
|
|
233
250
|
};
|
|
234
251
|
}
|
|
235
252
|
|
|
@@ -247,14 +264,12 @@ async function releaseQueue(
|
|
|
247
264
|
db: DevDbClient,
|
|
248
265
|
jobs: JobDriver | undefined,
|
|
249
266
|
replica?: PostgresClient,
|
|
267
|
+
releases: readonly PortRelease[] = [],
|
|
250
268
|
): Promise<void> {
|
|
251
|
-
//
|
|
252
|
-
//
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
resetJobsFacade();
|
|
256
|
-
resetEventBus();
|
|
257
|
-
resetJobDriver();
|
|
269
|
+
// Every queue port back to its package default, newest first — the idempotency store, the
|
|
270
|
+
// facade and the bus all hold this client, and the next command in this process would otherwise
|
|
271
|
+
// reserve keys, stage rows or publish over a closed one.
|
|
272
|
+
for (const release of [...releases].reverse()) await release();
|
|
258
273
|
setDbClient(undefined);
|
|
259
274
|
await jobs?.close?.();
|
|
260
275
|
await db.close();
|
package/src/runtime-realtime.ts
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
// The `realtime` section for the boot, out of the config `startServices` loads once
|
|
2
|
-
// (`app-config-load.ts`).
|
|
3
|
-
// `
|
|
2
|
+
// (`app-config-load.ts`). `enabled` decides the realtime roles; the two per-actor caps are read by
|
|
3
|
+
// the `sync` role, `maxQueued` by `page-sync.ts` (the page outbox's ceiling, on every document).
|
|
4
|
+
// The bus is not here: `NATS_URL`, or `transport` in `apps/<app>/runtime.ts` (v31).
|
|
4
5
|
|
|
5
6
|
import type { AppConfig, RealtimeConfig } from '@ultimat3/core';
|
|
6
7
|
|
|
7
8
|
/** Core's `defaults()` for the section — the answer for a root with no `app.config.ts`. */
|
|
8
9
|
export const REALTIME_DEFAULTS: RealtimeConfig = Object.freeze({
|
|
9
10
|
enabled: true,
|
|
10
|
-
transport: 'memory',
|
|
11
|
-
urlEnv: undefined,
|
|
12
11
|
maxSubscriptionsPerActor: undefined,
|
|
13
12
|
maxSocketsPerActor: undefined,
|
|
13
|
+
maxQueued: undefined,
|
|
14
14
|
});
|
|
15
15
|
|
|
16
16
|
/**
|
|
17
17
|
* The section as the boot obeys it — `defineConfig`'s per-key merge, so the boot and the app's own
|
|
18
|
-
* config object agree
|
|
18
|
+
* config object agree.
|
|
19
19
|
*/
|
|
20
20
|
export const realtimeConfigOf = (config: AppConfig | undefined): RealtimeConfig =>
|
|
21
21
|
config?.realtime ?? REALTIME_DEFAULTS;
|
|
@@ -27,6 +27,7 @@ import { routeQuery } from './isr-query-guard';
|
|
|
27
27
|
import { navigationTagsOf } from './page-navigation';
|
|
28
28
|
import { servedPins } from './page-pins';
|
|
29
29
|
import { bootScript, collectorFor } from './route-islands';
|
|
30
|
+
import { preloadTags } from './route-islands-preload';
|
|
30
31
|
import { siteAssetTable } from './site-assets';
|
|
31
32
|
import { styleBundle } from './style-bundle';
|
|
32
33
|
|
|
@@ -197,8 +198,10 @@ export async function documentFrom(
|
|
|
197
198
|
headFor(entry, ctx, data, options, scope),
|
|
198
199
|
routeBody(entry, ctx, data, islands),
|
|
199
200
|
]);
|
|
201
|
+
const boot = bootScript(entry, islands, options, scope);
|
|
202
|
+
const preloads = preloadTags(entry, islands, options, boot !== '');
|
|
200
203
|
return (
|
|
201
204
|
`<!doctype html><html lang="${lang()}"><head>${head}${stylesFor(entry, options)}</head>` +
|
|
202
|
-
`<body>${body}${
|
|
205
|
+
`<body>${body}${boot}${preloads}${hydrateRuntime(islands.directives)}</body></html>`
|
|
203
206
|
);
|
|
204
207
|
}
|