@runeditrun/rer 0.2.79 → 0.2.80
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/README.md +17 -3
- package/cli/README.md +25 -13
- package/cli/authoring.mjs +14 -0
- package/cli/contract.mjs +25 -5
- package/cli/demo-host.mjs +4 -2
- package/cli/dev-identity.mjs +2 -2
- package/cli/export.mjs +1 -1
- package/cli/inspect.mjs +38 -2
- package/cli/main.mjs +8 -2
- package/cli/managed-server.mjs +1 -1
- package/cli/parse.mjs +7 -6
- package/cli/portability-worker.mjs +2 -1
- package/cli/portability.mjs +6 -2
- package/cli/production-auth.mjs +2 -1
- package/cli/production-mail.mjs +36 -9
- package/cli/project.mjs +5 -14
- package/cli/release.mjs +2 -1
- package/cli/site-preview.mjs +4 -1
- package/cli/site.mjs +3 -2
- package/edition-authoring/adopt.mjs +39 -0
- package/edition-authoring/base-acknowledgements.mjs +24 -0
- package/edition-authoring/base-copies.mjs +418 -0
- package/edition-authoring/cli.mjs +85 -0
- package/edition-authoring/copy-checkout.mjs +69 -0
- package/edition-authoring/files.mjs +15 -2
- package/edition-authoring/lock.mjs +48 -0
- package/edition-authoring/offline-git.mjs +28 -0
- package/edition-authoring/parent-comparison.mjs +77 -0
- package/edition-authoring/projection-lock.mjs +38 -0
- package/edition-authoring/release.mjs +48 -0
- package/edition-authoring/sources.mjs +114 -0
- package/edition-authoring/updates.mjs +105 -0
- package/global/CHANGELOG.md +12 -0
- package/global/README.md +17 -3
- package/global/cli/install.mjs +3 -1
- package/global/main.mjs +9 -12
- package/modules/container/build.mjs +1 -1
- package/modules/d1-transport/index.mjs +68 -21
- package/modules/demo/README.md +8 -2
- package/modules/demo/declaration.mjs +21 -0
- package/modules/demo/input-path.mjs +18 -0
- package/modules/demo/label.d.mts +1 -1
- package/modules/demo/label.mjs +10 -5
- package/modules/demo/navigation.mjs +32 -0
- package/modules/demo/run-url.mjs +9 -0
- package/modules/demo/vite.d.mts +7 -2
- package/modules/demo/vite.mjs +17 -2
- package/modules/demo-host/README.md +5 -3
- package/modules/demo-host/page-style.mjs +2 -2
- package/modules/demo-host/pages.mjs +3 -3
- package/modules/demo-host/plan.mjs +6 -4
- package/modules/demo-host/theme.mjs +5 -2
- package/modules/deploy-kit/README.md +19 -15
- package/modules/deploy-kit/owner-cli.mjs +1 -1
- package/modules/deploy-kit/readiness-window.mjs +3 -3
- package/modules/erasure/README.md +10 -5
- package/modules/import-kit/src/d1/README.md +15 -9
- package/modules/import-kit/src/d1/apply.ts +10 -6
- package/modules/import-kit/src/d1/atomic-prefix.ts +64 -0
- package/modules/import-kit/src/d1/budget.ts +48 -26
- package/modules/import-kit/src/d1/compressed-plan.ts +9 -2
- package/modules/import-kit/src/d1/database.ts +2 -1
- package/modules/import-kit/src/d1/jobs.ts +2 -1
- package/modules/import-kit/src/d1/plans.ts +4 -2
- package/modules/import-kit/src/d1/verified-plan.ts +63 -0
- package/modules/integrations/core/README.md +2 -2
- package/modules/mail/README.md +4 -3
- package/modules/mail/pnpm-lock.yaml +16 -0
- package/modules/operator-auth/accounts/native.mjs +3 -1
- package/modules/operator-auth/accounts/provider-control.mjs +7 -4
- package/modules/operator-auth/accounts/provider-setup.mjs +34 -0
- package/modules/operator-auth/accounts/settings-page.mjs +13 -4
- package/modules/operator-auth/conformance/README.md +1 -1
- package/modules/operator-auth/dev/index.mjs +22 -4
- package/modules/operator-auth/dev/refusal.mjs +19 -0
- package/modules/operator-auth/docs/README.md +6 -5
- package/modules/operator-auth/docs/tanstack-start.md +1 -1
- package/modules/operator-auth/docs/vite-spa.md +5 -6
- package/modules/operator-auth/index.d.mts +1 -1
- package/modules/operator-auth/page.mjs +14 -0
- package/modules/operator-auth/representation.mjs +83 -0
- package/modules/operator-auth/routes.mjs +25 -2
- package/modules/portability/README.md +91 -14
- package/modules/portability/bookkeeping.mjs +3 -3
- package/modules/portability/bridge.mjs +5 -4
- package/modules/portability/catalogue.mjs +12 -8
- package/modules/portability/cli.mjs +5 -1
- package/modules/portability/export.mjs +5 -11
- package/modules/portability/format.mjs +7 -1
- package/modules/portability/http-errors.mjs +51 -0
- package/modules/portability/http.mjs +4 -1
- package/modules/portability/import-lease.mjs +13 -2
- package/modules/portability/import.mjs +10 -0
- package/modules/portability/index.d.mts +3 -0
- package/modules/portability/references.mjs +20 -0
- package/modules/portability/schema-identity.mjs +13 -0
- package/modules/portability/schema-legacy.mjs +21 -0
- package/modules/portability/sqlite-tokens.mjs +121 -0
- package/modules/release/README.md +20 -9
- package/modules/release/github-verify.mjs +30 -9
- package/modules/site/docs-search/search.css +1 -1
- package/onboarding/README.md +16 -4
- package/onboarding/adapter.mjs +5 -1
- package/onboarding/schema/SETUP.schema.json +26 -1
- package/onboarding/schema/business-field-inputs.mjs +37 -0
- package/onboarding/schema/json-schema.mjs +6 -2
- package/onboarding/schema/setup-validation.mjs +20 -3
- package/onboarding/server.mjs +1 -1
- package/onboarding/setup-manifest.mjs +2 -0
- package/onboarding/start-origin-diagnostic.mjs +24 -0
- package/onboarding/ui/style.css +9 -9
- package/package.json +1 -1
- package/scripts/publish-check/README.md +1 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# Native hosted demos
|
|
2
2
|
|
|
3
3
|
`rer deploy --demo` builds the seed's production Worker for a Worker Loader
|
|
4
|
-
host. See [adoption and deployment](
|
|
4
|
+
host. See [adoption and deployment](https://github.com/runeditrun/base/blob/main/export/DEMO.md#hosting-the-demo).
|
|
5
5
|
|
|
6
6
|
- `build.mjs`: ordinary Vite output, declared SQL and public configuration,
|
|
7
7
|
using the shared container migration-inventory and image-variable checks.
|
|
@@ -21,8 +21,10 @@ host. See [adoption and deployment](../../export/DEMO.md#hosting-the-demo).
|
|
|
21
21
|
`theme-script.mjs` sets the page and Turnstile scheme from the painted card's
|
|
22
22
|
background and text before the widget renders, and updates on preference changes.
|
|
23
23
|
The maintained default seed's theme assets supply missing tokens or an
|
|
24
|
-
absent theme, under `/__demo/theme
|
|
25
|
-
|
|
24
|
+
absent theme, under `/__demo/theme/`, except the link colour: a seed theme
|
|
25
|
+
without `--rer-link` links in its own `--rer-text`, as the theme grammar reads
|
|
26
|
+
it. Styles, fonts and marks stay same-origin; a missing mark leaves the
|
|
27
|
+
product name visible.
|
|
26
28
|
- `native/warm.mjs`: the start page's prefetch list, built from `dist/client`
|
|
27
29
|
(the Vite manifest if the build wrote one, else the build's `assetsDir`, else
|
|
28
30
|
`assets`) and TanStack Start's route manifest, the console's views first,
|
|
@@ -9,11 +9,11 @@ ul{padding:0;margin:23px 0 35px;list-style:none;color:var(--rer-muted);font-size
|
|
|
9
9
|
.button:disabled{background:var(--rer-surface);border-color:var(--rer-border);color:var(--rer-muted);font-weight:600;cursor:default}
|
|
10
10
|
.spinner{display:none;flex:none;width:20px;height:20px;border:3px solid color-mix(in srgb,currentColor 35%,transparent);border-top-color:currentColor;border-radius:50%;animation:spin .8s linear infinite}[data-state=working] .spinner,[data-state=signing] .spinner{display:block}@keyframes spin{to{transform:rotate(360deg)}}
|
|
11
11
|
ol.steps{display:none;list-style:none;margin:22px auto 0;padding:0;width:max-content;max-width:100%;font-size:16px;line-height:22px;color:var(--rer-muted)}[data-state=working] .steps,[data-state=signing] .steps,[data-state=slow] .steps{display:grid;gap:10px}[data-state=failed] .note{display:none}
|
|
12
|
-
.steps li{padding-left:30px;margin:0}.steps li:before{left:0;top:2px;width:18px;height:18px;box-sizing:border-box;background:none;border:2px solid var(--rer-muted)}.steps [data-at=done]{color:var(--rer-muted)}.steps [data-at=done]:before{content:'✓';border:0;background:var(--rer-accent);color:var(--rer-accent-text);font-size:
|
|
12
|
+
.steps li{padding-left:30px;margin:0}.steps li:before{left:0;top:2px;width:18px;height:18px;box-sizing:border-box;background:none;border:2px solid var(--rer-muted)}.steps [data-at=done]{color:var(--rer-muted)}.steps [data-at=done]:before{content:'✓';border:0;background:var(--rer-accent);color:var(--rer-accent-text);font-size:13px;line-height:18px;font-weight:700;text-align:center}.steps [data-at=now]{color:var(--rer-text);font-weight:600}.steps [data-at=now]:before{border-color:var(--rer-border);border-top-color:var(--rer-accent);animation:spin .8s linear infinite}
|
|
13
13
|
.visually-hidden{position:absolute;width:1px;height:1px;margin:-1px;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap}
|
|
14
14
|
@media(prefers-reduced-motion:reduce){.spinner,.steps [data-at=now]:before{animation:none}.steps [data-at=now]:before{border-color:var(--rer-accent)}}.button:focus-visible,a:focus-visible{outline:3px solid var(--rer-focus);outline-offset:4px}
|
|
15
15
|
.note{font-size:15px;line-height:21px;color:var(--rer-muted);text-align:center;margin:21px 0 0}.secondary{text-align:center;margin:22px 0 0;font-size:18px;line-height:24px;font-weight:600}.secondary a{color:var(--rer-link,var(--rer-text));text-underline-offset:3px}
|
|
16
|
-
.back{text-align:center;margin:32px 0 0;font-size:15px;line-height:22px}.back a{color:var(--rer-link,var(--rer-text));text-underline-offset:3px}
|
|
16
|
+
.back{display:flex;flex-wrap:wrap;justify-content:center;gap:12px 24px;text-align:center;margin:32px 0 0;font-size:15px;line-height:22px}.back a{color:var(--rer-link,var(--rer-text));text-underline-offset:3px}
|
|
17
17
|
.ended main{width:min(560px,calc(100% - 32px));margin-top:clamp(32px,26vh,262px)}.ended .card{padding:28px 36px 42px}.ended .brand{font-size:16px;margin-bottom:26px}.ended h1{font-size:36px;line-height:44px;margin-bottom:22px}.ended .intro{margin-bottom:36px}.ended .button{margin-top:0;font-size:18px}
|
|
18
18
|
@media(min-width:600px) and (max-width:1023px){main{width:calc(100% - 64px);max-width:666px;margin:100px auto 48px}.card{padding:36px}h1{font-size:38px;line-height:46px}.intro{font-size:18px;line-height:27px}}
|
|
19
19
|
@media(max-width:599px){main,.ended main{width:calc(100% - 32px);margin:32px auto}.ended .card{padding:26px 22px}.ended h1{font-size:29px;line-height:36px}.ended .intro{font-size:17px;line-height:25px;margin-bottom:28px}.card{padding:26px 22px;border-radius:var(--rer-radius)}.brand{font-size:16px}h1{font-size:34px;line-height:41px;letter-spacing:-.8px}.intro{font-size:17px;line-height:25px}ul{font-size:16px;line-height:25px;margin:22px 0 26px}li{padding-left:22px;margin-bottom:9px}li:before{left:2px;top:9px}.button{font-size:18px;margin-top:22px}.note{font-size:13px;line-height:20px}.steps{font-size:15px}.back{margin-top:24px;font-size:14px}}`;
|
|
@@ -16,7 +16,7 @@ function html(env, { page, title, body, status = 200, headers = {}, turnstile =
|
|
|
16
16
|
const nonce = crypto.randomUUID().replaceAll('-', ''), site = new URL(env.DEMO_SITE);
|
|
17
17
|
const policy = `default-src 'none'; style-src 'self' 'nonce-${nonce}'; font-src 'self'; img-src 'self'; form-action 'self'; base-uri 'none'; frame-ancestors 'none'; script-src 'nonce-${nonce}'${turnstile ? ` https://challenges.cloudflare.com; frame-src https://challenges.cloudflare.com; connect-src 'self' https://challenges.cloudflare.com` : ''}`;
|
|
18
18
|
return new Response(`<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><meta name="robots" content="noindex"><title>${escape(title)}</title>${env.DEMO_ICON_HEAD ?? ''}${refresh ? '<noscript><meta http-equiv="refresh" content="2;url=/__demo/status"></noscript>' : ''}<style nonce="${nonce}">${(env.DEMO_THEME ?? '').replace(/<(?=\/style)/gi, '\\3c ')}\n${STYLE}</style>${turnstile ? `<noscript><style nonce="${nonce}">#note{display:none}</style></noscript><script nonce="${nonce}">${START_SCRIPT}</script>${warm(env)}` : ''}</head>
|
|
19
|
-
<body class="${page}"><main><section class="card" aria-labelledby="title"><p class="brand"><img class="mark" alt="${escape(env.DEMO_NAME)}" width="40" height="40" hidden><span>${escape(env.DEMO_NAME)}</span></p>${body}</section><nav class="back" aria-label="Return"><a href="${escape(site.origin)}/">Back to ${escape(site.host)}</a
|
|
19
|
+
<body class="${page}"><main><section class="card" aria-labelledby="title"><p class="brand"><img class="mark" alt="${escape(env.DEMO_NAME)}" width="40" height="40" hidden><span>${escape(env.DEMO_NAME)}</span></p>${body}</section><nav class="back" aria-label="Return"><a href="${escape(site.origin)}/">Back to ${escape(site.host)}</a>${page === 'start' ? `<a href="${escape(env.DEMO_RUN_URL ?? new URL('/run', site).href)}">Run ${escape(env.DEMO_NAME)}</a>` : ''}</nav></main><script nonce="${nonce}">${THEME_SCRIPT}</script>${turnstile ? `<script nonce="${nonce}" src="https://challenges.cloudflare.com/turnstile/v0/api.js?onload=rerDemoRender&render=explicit" async defer></script>` : ''}</body></html>`,
|
|
20
20
|
{ status, headers: { 'content-type': 'text/html; charset=utf-8', 'cache-control': 'no-store', 'content-security-policy': policy, 'referrer-policy': 'strict-origin', 'x-content-type-options': 'nosniff', ...headers } });
|
|
21
21
|
}
|
|
22
22
|
|
|
@@ -25,7 +25,7 @@ export function startPage(env, { status = 200, notice, pending = false, headers
|
|
|
25
25
|
const name = escape(env.DEMO_NAME);
|
|
26
26
|
return html(env, { page: 'start', title: `Try ${env.DEMO_NAME}`, status, headers, turnstile: true, refresh: pending, body: `<h1 id="title">Try ${name}</h1>
|
|
27
27
|
<p class="intro">Your own copy of ${name}, signed in as its owner, with sample data.</p>
|
|
28
|
-
<ul><li>Public checks run live
|
|
28
|
+
<ul><li>Public checks run live.</li><li>It ends after an hour, or 15 idle minutes.</li><li>Then it is deleted. Nobody else can see it.</li></ul>
|
|
29
29
|
<p class="notice" id="notice" role="alert"${notice ? '' : ' hidden'}>${notice ? escape(notice) : ''}</p><form id="start" method="post" action="/__demo/start" data-auto="${notice || pending ? '0' : '1'}"${pending ? ' data-resume="1" data-state="working"' : ' data-state="waiting"'}><div class="cf-turnstile" data-theme="light" data-sitekey="${escape(env.TURNSTILE_SITE_KEY)}" data-size="flexible" data-callback="rerDemoVerified" data-before-interactive-callback="rerDemoInteractive" data-after-interactive-callback="rerDemoChecking" data-expired-callback="rerDemoExpired" data-error-callback="rerDemoCheckFailed"></div>
|
|
30
30
|
<button class="button" type="submit" disabled><span class="spinner" aria-hidden="true"></span><span class="label">${pending ? 'Starting your demo…' : 'Waiting for the human check…'}</span></button>
|
|
31
31
|
<ol class="steps" aria-hidden="true"><li data-at="done">Checking you're human</li><li data-at="now">Starting a private copy</li><li data-at="next">Signing you in</li></ol>
|
|
@@ -37,7 +37,7 @@ export function endedPage(env, { status = 410, headers = {} } = {}) {
|
|
|
37
37
|
const name = escape(env.DEMO_NAME);
|
|
38
38
|
return html(env, { page: 'ended', title: 'This demo has ended', status, headers, body: `<h1 id="title">This demo has ended</h1>
|
|
39
39
|
<p class="intro">A demo ends when you sign out, after an hour, or after 15 minutes with nothing happening. Its copy of ${name} and everything in it have been deleted.</p>
|
|
40
|
-
<a class="button" href="${escape(env.DEMO_ORIGIN)}/">Start a new demo</a><p class="secondary"><a href="${escape(new URL(env.DEMO_SITE).
|
|
40
|
+
<a class="button" href="${escape(env.DEMO_ORIGIN)}/">Start a new demo</a><p class="secondary"><a href="${escape(env.DEMO_RUN_URL ?? new URL('/run', env.DEMO_SITE).href)}">Run ${name} yourself</a></p>` });
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
const cookie = (env, value, seconds) => `rer_demo=${value}; Domain=${new URL(env.DEMO_ORIGIN).hostname}; Path=/; Max-Age=${seconds}; HttpOnly; Secure; SameSite=Lax`;
|
|
@@ -2,15 +2,17 @@ import { createHash } from 'node:crypto';
|
|
|
2
2
|
import { assert, hash, resourceName } from '../deploy-kit/validation.mjs';
|
|
3
3
|
import { ownerWorkerName } from '../deploy-kit/owner.mjs';
|
|
4
4
|
import { siteDeclaration } from '../deploy-kit/site.mjs';
|
|
5
|
+
import { demoRunUrl } from '../demo/run-url.mjs';
|
|
5
6
|
|
|
6
7
|
// Native Loader front, admission and visitor session support.
|
|
7
8
|
export const DEMO_FILES = ['worker.mjs', 'capacity.mjs', 'claim.mjs', 'pages.mjs', 'page-style.mjs', 'theme-script.mjs', 'start-script.mjs', 'diagnostics.mjs', 'operator.mjs', 'measurement.mjs'];
|
|
8
9
|
const FRONT_SET = /^(?:RER_.*|SESSION_SECRET|SETUP_TOKEN|OWNER_EMAIL)$/;
|
|
9
10
|
const SECRET = /SECRET|TOKEN|PASSWORD|_KEY$/;
|
|
10
11
|
export function demoDeclaration(value, originVar) {
|
|
11
|
-
assert(value && typeof value === 'object' && !Array.isArray(value) && value.version === 1 && Object.keys(value).every(key => ['version', 'domain', 'name', 'maxInstances', 'ownerEmail', 'settings'].includes(key)), 'invalid-demo-declaration');
|
|
12
|
+
assert(value && typeof value === 'object' && !Array.isArray(value) && value.version === 1 && Object.keys(value).every(key => ['version', 'domain', 'name', 'maxInstances', 'ownerEmail', 'settings', 'runUrl'].includes(key)), 'invalid-demo-declaration');
|
|
12
13
|
siteDeclaration({ version: 1, domain: value.domain });
|
|
13
14
|
assert(typeof value.name === 'string' && value.name.trim() === value.name && value.name.length > 0 && value.name.length <= 60 && !/[\p{Cc}\p{Cf}]/u.test(value.name), 'invalid-demo-name');
|
|
15
|
+
const runUrl = demoRunUrl(value.runUrl === undefined ? `https://${value.domain}/run` : value.runUrl);
|
|
14
16
|
const maxInstances = value.maxInstances ?? 10;
|
|
15
17
|
assert(Number.isSafeInteger(maxInstances) && maxInstances >= 1 && maxInstances <= 100, 'invalid-demo-max-instances');
|
|
16
18
|
const ownerEmail = value.ownerEmail;
|
|
@@ -18,13 +20,13 @@ export function demoDeclaration(value, originVar) {
|
|
|
18
20
|
const settings = value.settings ?? {};
|
|
19
21
|
assert(settings && typeof settings === 'object' && !Array.isArray(settings) && Object.entries(settings).every(([name, setting]) =>
|
|
20
22
|
/^[A-Z][A-Z0-9_]{0,63}$/.test(name) && !FRONT_SET.test(name) && !SECRET.test(name) && name !== originVar && typeof setting === 'string' && setting.length <= 1024), 'invalid-demo-settings');
|
|
21
|
-
return { domain: value.domain, name: value.name, maxInstances, ownerEmail, settings };
|
|
23
|
+
return { domain: value.domain, name: value.name, runUrl, maxInstances, ownerEmail, settings };
|
|
22
24
|
}
|
|
23
25
|
|
|
24
26
|
/** The demo Worker's name and its Wrangler configuration; no provider request. */
|
|
25
27
|
export function demoPlan({ project, environment, compatibilityDate, originVar, hostVariables = [], declaration, turnstileSiteKey }) {
|
|
26
28
|
assert(/^\d{4}-\d{2}-\d{2}$/.test(compatibilityDate ?? '') && /^[A-Z][A-Z0-9_]{0,63}$/.test(originVar ?? ''), 'invalid-plan');
|
|
27
|
-
const { domain, name, maxInstances, ownerEmail, settings } = demoDeclaration(declaration, originVar);
|
|
29
|
+
const { domain, name, runUrl, maxInstances, ownerEmail, settings } = demoDeclaration(declaration, originVar);
|
|
28
30
|
// Keep the historical container name in the ownership hash for released hosts.
|
|
29
31
|
const worker = `${ownerWorkerName(project, environment)}--demo`, hostname = `demo.${domain}`, container = worker.replace(/-+/g, '-');
|
|
30
32
|
assert(resourceName(worker), 'owner-name-too-long');
|
|
@@ -44,7 +46,7 @@ export function demoPlan({ project, environment, compatibilityDate, originVar, h
|
|
|
44
46
|
name: worker, main: 'worker.mjs', compatibility_date: compatibilityDate, workers_dev: false, preview_urls: false,
|
|
45
47
|
routes: hostnames.map(pattern => ({ pattern, custom_domain: true })),
|
|
46
48
|
observability: { enabled: true, head_sampling_rate: 1, logs: { enabled: true, invocation_logs: false } },
|
|
47
|
-
vars: { DEMO_ORIGIN: `https://${hostname}`, DEMO_SITE: `https://${domain}`, DEMO_NAME: name, DEMO_ORIGIN_VAR: originVar, DEMO_MAX_INSTANCES: String(maxInstances), DEMO_SETTINGS: JSON.stringify(settings), DEMO_SECONDARY_ORIGINS: JSON.stringify(secondaryHosts.map(host => `https://${host}`)),
|
|
49
|
+
vars: { DEMO_ORIGIN: `https://${hostname}`, DEMO_SITE: `https://${domain}`, DEMO_NAME: name, DEMO_RUN_URL: runUrl, DEMO_ORIGIN_VAR: originVar, DEMO_MAX_INSTANCES: String(maxInstances), DEMO_SETTINGS: JSON.stringify(settings), DEMO_SECONDARY_ORIGINS: JSON.stringify(secondaryHosts.map(host => `https://${host}`)),
|
|
48
50
|
...(ownerEmail ? { DEMO_OWNER_EMAIL: ownerEmail } : {}), ...(turnstileSiteKey ? { TURNSTILE_SITE_KEY: turnstileSiteKey } : {}) },
|
|
49
51
|
durable_objects: { bindings: [{ name: 'DEMO', class_name: 'NativeDemo' }, { name: 'CAPACITY', class_name: 'DemoCapacity' }] },
|
|
50
52
|
migrations: [{ tag: 'native-v2', new_sqlite_classes: ['NativeDemo', 'DemoCapacity'] }],
|
|
@@ -22,6 +22,9 @@ export async function prepareTheme(folder, assets) {
|
|
|
22
22
|
files.set(prefix + path, bytes);
|
|
23
23
|
paths.push(prefix + path);
|
|
24
24
|
}
|
|
25
|
-
const
|
|
26
|
-
|
|
25
|
+
const seed = ['/fonts/fonts.css', '/rer-theme.css'].filter(path => files.has(path));
|
|
26
|
+
// A seed theme without --rer-link links in its own --rer-text, as the theme
|
|
27
|
+
// grammar reads it (onboarding/theme.mjs), never in the default's link colour.
|
|
28
|
+
const link = files.has('/rer-theme.css') ? ':root{--rer-link:var(--rer-text)}' : '';
|
|
29
|
+
return { paths, css: [inlineTheme(files, [prefix + '/rer-theme.css']), link, inlineTheme(files, seed)].join('\n') };
|
|
27
30
|
}
|
|
@@ -40,7 +40,7 @@ The maintained default-seed `/health` returns the existing `status: 'ok'` plus t
|
|
|
40
40
|
} }
|
|
41
41
|
```
|
|
42
42
|
|
|
43
|
-
Assets upload with `run_worker_first: true` (`RUN_WORKER_FIRST` in `render.mjs`). Every request reaches the Worker first, so the seed's routing, origin admission, `no-store` document policy and private-path refusals decide what is served, and the Base delivery producer accepts no other setting. A built file therefore reaches the browser only through the Worker: seed entries call `staticAssetResponse(request, env)` from `foundation/runtime/static-assets.ts` first. After the deploy identity passes, health requests one built file (the first artifact asset that is neither an HTML document nor under a dot path) without credentials,
|
|
43
|
+
Assets upload with `run_worker_first: true` (`RUN_WORKER_FIRST` in `render.mjs`). Every request reaches the Worker first, so the seed's routing, origin admission, `no-store` document policy and private-path refusals decide what is served, and the Base delivery producer accepts no other setting. A built file therefore reaches the browser only through the Worker: seed entries call `staticAssetResponse(request, env)` from `foundation/runtime/static-assets.ts` first. After the deploy identity passes, health requests one built file (the first artifact asset that is neither an HTML document nor under a dot path) without credentials, polls a missing asset after upload within the smaller of 60 seconds and the remaining readiness window, replays 5xx and transport failures at most once, and fails with `asset-http-failed` unless it answers 200; the result is recorded as `health.asset`. `rer verify` serves the local build with the same setting (`cli/hosted-output.mjs`).
|
|
44
44
|
|
|
45
45
|
The controller supplies the two public variables and Cloudflare version-metadata binding. The parent owns default-seed source/types, package scripts, shared manifests and workflows. Keep the staged-deploy descriptor blocked until the three-stage isolation and actual build/health integration pass; the original deploy-then-health executor cannot safely run installation/build with its credentials.
|
|
46
46
|
|
|
@@ -48,7 +48,7 @@ The controller supplies the two public variables and Cloudflare version-metadata
|
|
|
48
48
|
|
|
49
49
|
`deploy({api,plan,artifact,artifactSha256,previousReceipt,env,fetch})` is the shared implementation for deploy and stage. Plans are controller-owned and validated; do not derive a secret-bearing plan from executable project configuration. `defaultStagePlan` demonstrates the full schema. Optional R2 `{binding,name}`, Queue `{binding,name,consumer?}`, DO `{binding,className,storage:'sqlite'|'classic'}`, and secret `{binding,environment}` declarations are supported. New DOs must use SQLite; existing classic namespaces are reusable. Namespace creation occurs through Worker upload migrations, with old/new migration tags, then authenticated namespace readback. No namespace create endpoint is invented. Cron and queue consumers reconcile after Worker creation. Conflicting consumers and resource identities fail; resources/data are never deleted.
|
|
50
50
|
|
|
51
|
-
Cron reads require the documented `result: {schedules: [...]}` envelope, including valid unique Cron strings; bare arrays and partial/malformed results fail. Before changing an existing Worker, deployment reads its schedules and rejects any Cron outside the requested plan with `cron-drift`, before resource writes, SQL migrations or Worker upload. Trigger reconciliation repeats that read before any trigger write. This applies to ordinary changed-source upgrades with or without a prior receipt. The kit may add requested schedules; it never intentionally removes existing schedules. Removing a Cron from the plan while it still exists remotely requires a separate reviewed removal first. Every changed upload reapplies its nonempty declared Cron set after workers.dev activation, even when the Worker-scoped list already matches. The kit reads the exact schedule set back after the write and checks that the active deployment identity remained stable. A declared Cron also requires the authenticated active version to report a `scheduled` handler; absent detection fails with `missing-scheduled-handler`. These checks establish provider configuration, not proof that a scheduled invocation has executed. Dispatch is the provider's
|
|
51
|
+
Cron reads require the documented `result: {schedules: [...]}` envelope, including valid unique Cron strings; bare arrays and partial/malformed results fail. Before changing an existing Worker, deployment reads its schedules and rejects any Cron outside the requested plan with `cron-drift`, before resource writes, SQL migrations or Worker upload. Trigger reconciliation repeats that read before any trigger write. This applies to ordinary changed-source upgrades with or without a prior receipt. The kit may add requested schedules; it never intentionally removes existing schedules. Removing a Cron from the plan while it still exists remotely requires a separate reviewed removal first. Every changed upload reapplies its nonempty declared Cron set after workers.dev activation, even when the Worker-scoped list already matches. The kit reads the exact schedule set back after the write and checks that the active deployment identity remained stable. A declared Cron also requires the authenticated active version to report a `scheduled` handler; absent detection fails with `missing-scheduled-handler`. These checks establish provider configuration, not proof that a scheduled invocation has executed. Dispatch is the provider's. The following account-specific observation is historical and unverified here; no independent receipt is retained in this repository. On the RunEditRun account (11 October 2026) a correctly registered Cron started only at the account scheduler's next refresh, observed 60 to 106 minutes apart, so a first tick can arrive well after Cloudflare's documented 15 minutes; a cleared schedule keeps running, and a deleted Worker keeps being invoked (as `internalError`), until a later refresh. A redeploy keeps the existing dispatch: the first run after it executes the new version. Judge first-deploy Cron by the seed's own scheduled-run record, not by a short watch. Unchanged deployment and health require the exact desired schedule set and perform no repairs. Callers must serialize deployments and out-of-band schedule edits for a Worker: the provider schedule replacement API offers no conditional update in this interface.
|
|
52
52
|
|
|
53
53
|
`workerConsumerScript(consumer)` (also exported from `index.mjs`) decodes Worker consumer identities from either documented `script_name` or the observed GET response string `script`. It returns the exact name using the plan's resource-name grammar, or `null` for missing, malformed, conflicting, or non-Worker identities. If both fields are present, each must be valid and both must agree; a malformed alias is never ignored. Reconciliation checks every consumer on queues with a requested consumer before any trigger write and rejects foreign or duplicate consumers. Writes continue to use the documented `script_name` request field. Read-only health and retained-receipt repeats accept either response variant without repairs.
|
|
54
54
|
|
|
@@ -94,7 +94,7 @@ A declaration may also bind another owner-deployed Worker and may keep its own w
|
|
|
94
94
|
"workersDev": false }
|
|
95
95
|
```
|
|
96
96
|
|
|
97
|
-
A service's Worker name is derived from its `project` and this deploy's environment, so the example above binds `egress-service-production`. `allowedHosts` becomes the binding's `props` (`{allowedHosts}`), which the bound Worker reads as `ctx.props`. The binding is uploaded and read back like every other binding, so a changed `props` is reported as `binding-readback-mismatch`. Before any write, deploy reads each bound Worker. If it is absent, deploy refuses with `service-worker-missing` and resource `service:<worker>`; deploy that Worker first. `workersDev: false` keeps the route off: an enabled route is switched off on upload, the receipt's `origin` is `null`, and health uses provider readback only, because there is no public `/health` to request. [modules/egress-service](
|
|
97
|
+
A service's Worker name is derived from its `project` and this deploy's environment, so the example above binds `egress-service-production`. `allowedHosts` becomes the binding's `props` (`{allowedHosts}`), which the bound Worker reads as `ctx.props`. The binding is uploaded and read back like every other binding, so a changed `props` is reported as `binding-readback-mismatch`. Before any write, deploy reads each bound Worker. If it is absent, deploy refuses with `service-worker-missing` and resource `service:<worker>`; deploy that Worker first. `workersDev: false` keeps the route off: an enabled route is switched off on upload, the receipt's `origin` is `null`, and health uses provider readback only, because there is no public `/health` to request. [modules/egress-service](https://github.com/runeditrun/base/blob/main/modules/egress-service/README.md) is the Worker this exists for.
|
|
98
98
|
|
|
99
99
|
`ownerTarget`, `ownerPlan`, `ownerDeploy` and `ownerHealth` (exported from `index.mjs`) are the same steps for a seed's own script. A seed script can compute vars before calling `ownerPlan`.
|
|
100
100
|
|
|
@@ -104,8 +104,8 @@ Ownership lives in a state file, by default `.rer/deploy/<environment>.json` und
|
|
|
104
104
|
- **Re-run.** The same build writes nothing: no create, upload, migration, trigger or secret write, and the state file stays byte-identical. A later release that declares a new resource creates only that resource.
|
|
105
105
|
- **Partial failure and resume.** The kit records each create as `pending` before the request and `created` with the provider id after it. A failed create leaves `pending`. On the next run an absent pending name is created again, and a present one is refused as `uncertain-resource-create`, because a lost response cannot prove who created it. Inspect it: if it is the empty resource from the interrupted run, delete it and re-run. A Worker upload is recorded as created when the upload succeeds, so a failure after it resumes with one fresh upload. If the response to the very first upload is lost, the Worker exists but is still `pending`. The kit records the upload's fingerprint before sending it. When an upload's response or its readback is lost (a first upload or a redeploy), the next run accepts the live version as this deploy's own only when it carries that fingerprint both as its `RER_DEPLOY_FINGERPRINT` binding and as its `rer-deploy:<fingerprint>` annotation: it records the live version id, deployment id and etag, then resumes with one fresh upload. Any other live version is refused, as `uncertain-resource-create` with no prior receipt and as `owned-resource-replaced` with one. If the uncertain Worker cannot be authenticated, inspect it and delete it only after confirming that it is the kit-created Worker and that its Durable Object data is disposable. Back up any needed data before deleting it. Migration claims keep the rules under Migration safety.
|
|
106
106
|
- **Drift.** A created resource that has gone is refused as `owned-resource-missing`; one replaced under the same name is refused as `owned-resource-replaced`. The kit never deletes or recreates them. This covers D1, KV, Queues and R2 (a bucket is identified by its creation date; a state file written before that was recorded keeps working and is not checked for that bucket). For the Worker, the live deployment (version id, deployment id and etag) must be the last receipt's before any write; someone else's upload under the same name is refused as `owned-resource-replaced` and never overwritten. Immediately before the Worker PUT, the kit rechecks every saved resource identity, including resources omitted from the current plan, then the Worker identity. A replacement during provisioning or asset upload is refused before the upload intent or receipt is saved. An interrupted successful upload may resume only when the live version id, deployment id and etag match the identity saved immediately after that upload, or, when its readback was lost before that identity was saved, when the live version carries the fingerprint saved immediately before that upload (binding and annotation). A receipt's historical fingerprint never overrides a receipt mismatch.
|
|
107
|
-
- **Lost upgrade response.**
|
|
108
|
-
- **Settling listings.** Right after a create or delete, an account listing can briefly disagree with its own page counts (`provider-partial-list`: on 13 October 2026 D1's `total_count` lagged its rows by about 7 seconds after a create). Owner-mode deploy, health and removal discard such a snapshot and list again from the start for up to
|
|
107
|
+
- **Lost upgrade response.** An interrupted upload can resume when its saved upload intent authenticates the live version by the pending fingerprint binding and annotation, or by its saved provider identity. Otherwise deployment refuses the mismatch. A [Cloudflare rollback](https://developers.cloudflare.com/workers/versions-and-deployments/rollbacks/) creates a new deployment, so it does not restore the recorded identity.
|
|
108
|
+
- **Settling listings.** Right after a create or delete, an account listing can briefly disagree with its own page counts (`provider-partial-list`: on 13 October 2026 D1's `total_count` lagged its rows by about 7 seconds after a create). Owner-mode deploy, health and removal discard such a snapshot and list again from the start for up to 120 seconds with a short backoff; a partial listing is never accepted.
|
|
109
109
|
- **One run at a time.** A deploy takes an exclusive lock file, `<state file>.lock`, for the whole run and removes it at the end, even after a failure. A second run on the same state file is refused as `owner-state-locked` before any provider request. If a run was killed (power loss, `kill -9`) and no deploy is running, delete the lock file by hand.
|
|
110
110
|
|
|
111
111
|
The CLI prints JSON: refusal codes and resource names only, never inputs, tokens or provider bodies.
|
|
@@ -348,10 +348,12 @@ the standalone window: 2, 2, 4, 8, 10, 10 ... seconds. Only transport failures,
|
|
|
348
348
|
names another Worker version (the edge still serving the previous version just
|
|
349
349
|
after the upload). A redirect, any other status, a malformed or unhealthy body
|
|
350
350
|
and a wrong identity from the uploaded version itself fail at once. The one
|
|
351
|
-
built file then requested must answer 200
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
13 October 2026
|
|
351
|
+
built file then requested must answer 200. After an upload, only asset 404
|
|
352
|
+
propagation receives repeated polling within the smaller of 60 seconds and the
|
|
353
|
+
remaining readiness window; asset 5xx and transport failures receive at most one
|
|
354
|
+
replay. A historical, unverified 13 October 2026 observation attributed missing
|
|
355
|
+
hashed files to an edge still serving the previous build; no independent receipt
|
|
356
|
+
is retained here.
|
|
355
357
|
Each request is capped by both the 30-second request limit and the remaining
|
|
356
358
|
budget, and no request starts at the deadline. An unchanged repeat uses the
|
|
357
359
|
existing library window and does not record first-upload readiness attempts.
|
|
@@ -370,9 +372,10 @@ retains the existing window, retrying only 404, 503 and network failures for
|
|
|
370
372
|
Custom-hook `rer deploy` finalization gets a separate 90-second `/health` wait
|
|
371
373
|
after the hook returns, using the current recorded Worker version when available.
|
|
372
374
|
The hook can already have claimed the owner and retired its token, which creates
|
|
373
|
-
another version and can exhaust the original upload window.
|
|
374
|
-
and Pencil deploys on 15 October 2026
|
|
375
|
-
named the right commit seconds later
|
|
375
|
+
another version and can exhaust the original upload window. A historical,
|
|
376
|
+
unverified report says first hosted Slate and Pencil deploys on 15 October 2026
|
|
377
|
+
failed this final gate even though health named the right commit seconds later;
|
|
378
|
+
no independent receipt is retained here. Reusing the existing 90-second propagation
|
|
376
379
|
budget gives this final observation the same bounded allowance, without spending
|
|
377
380
|
it on the hook's earlier work. Transport failures and healthy identity mismatches wait;
|
|
378
381
|
permanent HTTP or malformed responses still fail. The deadline includes request
|
|
@@ -415,8 +418,9 @@ untrusted response prefixes are never written into that record.
|
|
|
415
418
|
|
|
416
419
|
## Read-only teardown verification
|
|
417
420
|
|
|
418
|
-
|
|
419
|
-
|
|
421
|
+
`verifyTeardown` performs no deletes. Explicit owner-account removal deletes
|
|
422
|
+
authenticated owned resources and purges owned R2 objects. After a seed has
|
|
423
|
+
validated its receipt and removed only its authenticated disposable resources, call
|
|
420
424
|
`verifyTeardown({api, plan, receipt})`. The default CLI exposes
|
|
421
425
|
`node modules/deploy-kit/cli.mjs verify-teardown` with the same controller inputs.
|
|
422
426
|
The target must be the exact receipt Worker with a `rer-seedproof-` prefix or
|
|
@@ -479,7 +483,7 @@ Only the ordinary named service binding is uploaded. This supports service-owned
|
|
|
479
483
|
narrowing where Cloudflare omits service-binding `props` from settings/version
|
|
480
484
|
readback. Ordinary `allowedHosts` still maps to `props` and retains strict
|
|
481
485
|
readback; missing props are never silently accepted. See the
|
|
482
|
-
[egress service guide](
|
|
486
|
+
[egress service guide](https://github.com/runeditrun/base/blob/main/modules/egress-service/README.md).
|
|
483
487
|
|
|
484
488
|
### List completion and deployment failures
|
|
485
489
|
|
|
@@ -68,7 +68,7 @@ export async function main(argv = process.argv.slice(2), env = process.env, {fet
|
|
|
68
68
|
if (!requestWindow?.active) return undefined;
|
|
69
69
|
const remaining = requestWindow.remaining();
|
|
70
70
|
assert(remaining > 0, 'deployment-readiness-timeout');
|
|
71
|
-
return
|
|
71
|
+
return requestWindow.timeout(Math.max(1, Math.ceil(remaining)));
|
|
72
72
|
};
|
|
73
73
|
fetch = (input, init = {}) => {
|
|
74
74
|
const deadline = requestSignal();
|
|
@@ -3,11 +3,11 @@ import { assert } from './validation.mjs';
|
|
|
3
3
|
|
|
4
4
|
// A single, in-memory deadline travels with this upload. It is deliberately not
|
|
5
5
|
// persisted: an old receipt is not evidence of a fresh propagation window.
|
|
6
|
-
export function readinessWindow({ totalMs = 90000, clock = () => performance.now(), sleep = ms => new Promise(resolve => setTimeout(resolve, ms)) } = {}) {
|
|
6
|
+
export function readinessWindow({ totalMs = 90000, clock = () => performance.now(), sleep = ms => new Promise(resolve => setTimeout(resolve, ms)), timeout = ms => AbortSignal.timeout(ms) } = {}) {
|
|
7
7
|
assert(Number.isFinite(totalMs) && totalMs > 0 && totalMs <= 90000, 'invalid-health-bound');
|
|
8
8
|
let start;
|
|
9
9
|
return {
|
|
10
|
-
clock, sleep,
|
|
10
|
+
clock, sleep, timeout,
|
|
11
11
|
get active() { return start !== undefined; },
|
|
12
12
|
start() { start ??= clock(); },
|
|
13
13
|
remaining() { return start === undefined ? totalMs : Math.max(0, totalMs - (clock() - start)); },
|
|
@@ -26,7 +26,7 @@ export function readinessAPI(api, window, failure = 'deployment-readiness-timeou
|
|
|
26
26
|
return {...api, request(path, options = {}) {
|
|
27
27
|
const remaining = window.remaining();
|
|
28
28
|
assert(remaining > 0, failure);
|
|
29
|
-
const deadline =
|
|
29
|
+
const deadline = window.timeout(Math.max(1, Math.ceil(remaining)));
|
|
30
30
|
return api.request(path, {...options, signal:options.signal ? AbortSignal.any([options.signal,deadline]) : deadline});
|
|
31
31
|
}};
|
|
32
32
|
}
|
|
@@ -188,6 +188,9 @@ the seed retires them in its own migration.
|
|
|
188
188
|
retires imports whose headers hold the person's exact identifiers and writes
|
|
189
189
|
the import erasure journal (import-kit `src/d1/README.md`).
|
|
190
190
|
|
|
191
|
+
If a required retained row disappears, erasure refuses with `retained_row_missing`
|
|
192
|
+
and leaves the work pending.
|
|
193
|
+
|
|
191
194
|
## Adopting
|
|
192
195
|
|
|
193
196
|
Copy these files byte for byte to a folder the Worker build serves, such as
|
|
@@ -207,6 +210,7 @@ modules/erasure/scope.mjs
|
|
|
207
210
|
modules/erasure/completion.mjs
|
|
208
211
|
modules/erasure/verification.mjs
|
|
209
212
|
modules/erasure/cascade.mjs
|
|
213
|
+
modules/erasure/queue.mjs
|
|
210
214
|
modules/erasure/blobs.mjs
|
|
211
215
|
modules/erasure/audit.mjs
|
|
212
216
|
modules/erasure/receipt.mjs
|
|
@@ -229,11 +233,12 @@ archives; the blob work list does not.
|
|
|
229
233
|
|
|
230
234
|
## Historical measurements before the review fixes
|
|
231
235
|
|
|
232
|
-
|
|
233
|
-
10,000 dependent rows (9,500
|
|
234
|
-
|
|
235
|
-
bounded D1 steps, then the blob phase, with no queue continuation needed. The
|
|
236
|
-
|
|
236
|
+
A historical, unverified report through the default seed's route in a local
|
|
237
|
+
`rer dev` Worker recorded erasing a subject with 10,000 dependent rows (9,500
|
|
238
|
+
notes and 500 file rows) and 500 R2 blobs in 10.7 s in one run and 15.0 s in
|
|
239
|
+
another, in one request: 20 bounded D1 steps, then the blob phase, with no queue continuation needed. The cited
|
|
240
|
+
consolidation proof table is outside this repository; no corresponding benchmark
|
|
241
|
+
receipt is retained here.
|
|
237
242
|
These pre-fix measurements do not establish the performance of the corrected
|
|
238
243
|
helper. They are local Miniflare measurements, not production capacity claims. Real D1
|
|
239
244
|
statement, CPU and request limits decide `rows` per step and the request budget.
|
|
@@ -13,7 +13,7 @@ use Undo from the same history when needed. Base's reference accepts people JSON
|
|
|
13
13
|
here, not installation `.rer` archives. Editions adopt this same door
|
|
14
14
|
with their own supported readers and native adapters.
|
|
15
15
|
|
|
16
|
-
For seed integration, follow [the door adoption guide](
|
|
16
|
+
For seed integration, follow [the door adoption guide](https://github.com/runeditrun/base/blob/main/modules/import-kit/src/door/ADOPTING.md)
|
|
17
17
|
first. The D1 primitives below back that shared pipeline; do not mount separate
|
|
18
18
|
job creation/apply routes beside it. Keep native readers and target adapters.
|
|
19
19
|
|
|
@@ -29,6 +29,10 @@ provenance and inert-effect policy through an asynchronous native SQL port.
|
|
|
29
29
|
When copying Base source directly, copy the shared [D1 transport](../../../d1-transport/index.mjs) and its
|
|
30
30
|
[types](../../../d1-transport/index.d.mts), preserving their sibling location
|
|
31
31
|
beside the import-kit directory.
|
|
32
|
+
Reading codec-dependent stored plans without the matching codec ID refuses with
|
|
33
|
+
`IMPORT_PLAN_CODEC_REQUIRED`; encoding a codec whose round trip changes the plan
|
|
34
|
+
fingerprint refuses with `IMPORT_PLAN_CODEC_MISMATCH`.
|
|
35
|
+
|
|
32
36
|
The D1 entry uses this shared transport automatically. It accounts for actual
|
|
33
37
|
UTF-8 bytes and workerd's whole-call two-byte strings, escapes sparse wide text
|
|
34
38
|
for SQLite to decode, and keeps each mutation in its original transaction.
|
|
@@ -44,7 +48,9 @@ and D1 engine for the same jobs: each engine owns its checkpoint protocol.
|
|
|
44
48
|
For reviewed reversal-policy conversion, also apply the additive
|
|
45
49
|
`d1ReversalPolicyConversionSchema` after these existing schemas in a new
|
|
46
50
|
product-owned numbered migration. `initializeD1ImportStorage` installs it
|
|
47
|
-
automatically. Do not rewrite an applied migration.
|
|
51
|
+
automatically. Do not rewrite an applied migration. Partial preserved-undo schema
|
|
52
|
+
evolution refuses with `IMPORT_SCHEMA_EVOLUTION_INCOMPLETE`; complete the additive
|
|
53
|
+
evolution before continuing.
|
|
48
54
|
|
|
49
55
|
Apply stream-origin backfill and legacy receipt conversion in one transaction.
|
|
50
56
|
Origins record actual page, parent and job bindings and remain immutable until
|
|
@@ -64,10 +70,10 @@ evaluates the expression at both ends of every atomic mutation batch. A false
|
|
|
64
70
|
predicate raises `IMPORT_ATOMIC_GUARD` and rolls back every native and kit write.
|
|
65
71
|
Read operations also require current authority. Jobs remain bound to their actor.
|
|
66
72
|
The plan and its fingerprint carry that `principalId`, so a job can never be rebound
|
|
67
|
-
to another one
|
|
68
|
-
|
|
69
|
-
product that wants restored jobs to
|
|
70
|
-
restore, such as the operator's role (`'role:' + role`), and lets `predicate` check
|
|
73
|
+
to another one. Identity retention depends on the seed's archive policy: a
|
|
74
|
+
restored job remains bound to its recorded principal, so verify whether that
|
|
75
|
+
principal survives the selected policy. A product that wants restored jobs to
|
|
76
|
+
stay usable passes a principal that survives a restore, such as the operator's role (`'role:' + role`), and lets `predicate` check
|
|
71
77
|
that the acting operator is still active in that role. A product that passes the
|
|
72
78
|
operator's row id keeps its jobs bound to that operator for good.
|
|
73
79
|
|
|
@@ -932,9 +938,9 @@ the new conversion and preview operations refuse with the `schema` reason until
|
|
|
932
938
|
their additive migration is installed. Updating kit source does not silently
|
|
933
939
|
adopt conversion or require an edit to an existing seed migration.
|
|
934
940
|
|
|
935
|
-
|
|
936
|
-
containing the capability, or a
|
|
937
|
-
its migration, current authority, conversion and later reversal through its own
|
|
941
|
+
Historically, rer 0.2.77 lacked this API. A seed adopts a reviewed vendored Base
|
|
942
|
+
revision containing the capability, or a pinned rer release that supplies it,
|
|
943
|
+
and proves its migration, current authority, conversion and later reversal through its own
|
|
938
944
|
public door. Base's tests do not prove that adoption. Until then, existing strict
|
|
939
945
|
jobs retain their policy and the seed's compensation-unavailable refusal remains
|
|
940
946
|
in force. Adoption, seed release and deployment are separate from this Base
|
|
@@ -7,7 +7,7 @@ import { canonicalJson, sha256, attachmentHash } from '../provenance/identity.ts
|
|
|
7
7
|
import { validateEffect } from '../plan/index.ts';
|
|
8
8
|
import { effectIdentity } from '../storage/provenance.ts';
|
|
9
9
|
import type { D1ImportContext, D1Sql } from './types.ts';
|
|
10
|
-
import { atomic, atomicCount, authorize, guard, limits, sql, fitsBatch } from './database.ts';
|
|
10
|
+
import { atomic, atomicCount, atomicPrefix, authorize, guard, limits, sql, fitsBatch } from './database.ts';
|
|
11
11
|
import { stored, boundary, storedReads } from './jobs.ts';
|
|
12
12
|
import { custodyGuards, validatedProvenance, inventoryGuards, reusedSourceGuards } from './integrity.ts';
|
|
13
13
|
import { supersedeTarget } from './history.ts';
|
|
@@ -27,7 +27,9 @@ export async function applyD1ImportBatches(jobOrId: ImportJob | string, context:
|
|
|
27
27
|
if (job.state === 'completed') { await atomic(context, 'apply', [...boundary(job, plan, 'apply'), ...custodyGuards(plan, id), ...await inventoryGuards(job, plan, context)], 0, nativeStagingScope(job, plan)); return job; }
|
|
28
28
|
if (!['queued', 'applying', 'failed'].includes(job.state)) throw new Error('IMPORT_ALREADY_REVERSING');
|
|
29
29
|
const statements: D1Sql[] = [...boundary(job, plan, 'apply'), ...custodyGuards(plan, id), ...await inventoryGuards(job, plan, context)], entries: PlanEntry[] = [], returnReads = storedReads(job);
|
|
30
|
-
let effects = 0, scope = nativeStagingScope(job, plan)
|
|
30
|
+
let effects = 0, scope = nativeStagingScope(job, plan);
|
|
31
|
+
let prefix = atomicPrefix(context, 'apply', statements, scope);
|
|
32
|
+
let planned = prefix ? prefix.count(progress(job, 0), returnReads) : cost(context, publication(job, 0, statements, scope), returnReads);
|
|
31
33
|
for (const entry of plan.entries.slice(job.checkpoint, job.checkpoint + batchSize)) {
|
|
32
34
|
if (entries.length && effects + entry.effects.length > 1000) break;
|
|
33
35
|
if (entry.effects.length > 1000) throw new Error('SOURCE_EFFECT_LIMIT');
|
|
@@ -35,13 +37,15 @@ export async function applyD1ImportBatches(jobOrId: ImportJob | string, context:
|
|
|
35
37
|
// request, as atomic will send it, is counted again once the entry is built.
|
|
36
38
|
const reserve = 40 + entry.effects.length * 16;
|
|
37
39
|
if (remaining(context) - planned < reserve) { if (!entries.length) { if (count > 0) return job; throw new D1RequestLimitError(); } break; }
|
|
38
|
-
const candidate = [
|
|
40
|
+
const candidate: D1Sql[] = [], nextScope = { ...scope, nativeGuards:[...scope.nativeGuards], postGuards:[...scope.postGuards], targets:[...scope.targets] };
|
|
39
41
|
await publishEntry(id, entry, job.checkpoint + entries.length, context, candidate, nextScope);
|
|
40
|
-
const
|
|
42
|
+
const nextPrefix = prefix?.extend(candidate);
|
|
43
|
+
const next = nextPrefix ? undefined : publication(job, entries.length + 1, [...statements, ...candidate], nextScope);
|
|
44
|
+
const spent = nextPrefix ? nextPrefix.count(progress(job, entries.length + 1), returnReads) : cost(context, next!, returnReads);
|
|
41
45
|
if (spent > remaining(context)) { if (entries.length) break; if (count > 0) return job; throw new D1RequestLimitError(); }
|
|
42
|
-
const fits = fitsBatch(context, 'apply', next
|
|
46
|
+
const fits = nextPrefix ? true : fitsBatch(context, 'apply', next!.statements, next!.scope);
|
|
43
47
|
if (!fits && entries.length) break;
|
|
44
|
-
statements.
|
|
48
|
+
statements.push(...candidate); prefix = nextPrefix;
|
|
45
49
|
scope = nextScope; entries.push(entry); effects += entry.effects.length; planned = spent;
|
|
46
50
|
if (!fits) break;
|
|
47
51
|
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import type { ImportAction } from '../types.ts';
|
|
2
|
+
import type { D1ImportContext, D1Sql } from './types.ts';
|
|
3
|
+
import type { NativeStagingScope } from './native-staging-context.ts';
|
|
4
|
+
import { GuardPacking, valueBytes } from './budget.ts';
|
|
5
|
+
import { authority, finalAuthority, postConditions, sql } from './database.ts';
|
|
6
|
+
|
|
7
|
+
/** Unbounded publication has append-only SQL and final checks. Bounded native
|
|
8
|
+
* staging derives an ExpectedState from the complete transaction instead. */
|
|
9
|
+
export function atomicPrefix(context: D1ImportContext, action: ImportAction, statements: D1Sql[], scope: NativeStagingScope) {
|
|
10
|
+
if (context.maxBatchBytes !== undefined) return undefined;
|
|
11
|
+
type Part = { statements: D1Sql[]; unchanged: () => boolean; prior?: Part };
|
|
12
|
+
const observe = (statement: D1Sql): (() => boolean) => {
|
|
13
|
+
const text = statement.sql, params = [...statement.params ?? []], sizes = params.map(p => p instanceof ArrayBuffer || ArrayBuffer.isView(p) ? valueBytes(p) : undefined);
|
|
14
|
+
const checks = [...statement.finalChecks ?? []], unchanged = checks.map(observe);
|
|
15
|
+
return () => statement.sql === text && (statement.params?.length ?? 0) === params.length
|
|
16
|
+
&& params.every((p, i) => p === statement.params![i] && (sizes[i] === undefined || sizes[i] === valueBytes(p)))
|
|
17
|
+
&& (statement.finalChecks?.length ?? 0) === checks.length && checks.every((check, i) => check === statement.finalChecks![i] && unchanged[i]());
|
|
18
|
+
};
|
|
19
|
+
const part = (statements: D1Sql[], prior?: Part): Part => {
|
|
20
|
+
const checks = statements.map(observe);
|
|
21
|
+
return { statements: [...statements], prior, unchanged: () => checks.every(check => check()) };
|
|
22
|
+
};
|
|
23
|
+
const same = (a: D1Sql, b: D1Sql) => a.sql === b.sql && (a.params?.length ?? 0) === (b.params?.length ?? 0) && (a.params ?? []).every((p, i) => p === b.params![i]);
|
|
24
|
+
const collect = (part: Part): D1Sql[] => {
|
|
25
|
+
const parts: D1Sql[][] = [];
|
|
26
|
+
for (let current: Part | undefined = part; current; current = current.prior) parts.push(current.statements);
|
|
27
|
+
return parts.reverse().flat();
|
|
28
|
+
};
|
|
29
|
+
class Prefix {
|
|
30
|
+
private writes?: GuardPacking;
|
|
31
|
+
private first?: D1Sql;
|
|
32
|
+
private firstUnchanged?: () => boolean;
|
|
33
|
+
private part: Part;
|
|
34
|
+
private post: GuardPacking;
|
|
35
|
+
private postLength: number;
|
|
36
|
+
constructor(part: Part, post: GuardPacking, postLength: number, prior?: Prefix) {
|
|
37
|
+
this.part = part; this.post = post; this.postLength = postLength;
|
|
38
|
+
if (prior) { this.writes = prior.writes?.fork().append(part.statements); this.first = prior.first; this.firstUnchanged = prior.firstUnchanged; }
|
|
39
|
+
}
|
|
40
|
+
extend(added: D1Sql[]): Prefix {
|
|
41
|
+
const checks = added.flatMap(s => s.finalChecks ?? []);
|
|
42
|
+
return new Prefix(part(added, this.part), this.post.fork().append(checks), this.postLength + checks.length, this);
|
|
43
|
+
}
|
|
44
|
+
count(tail: D1Sql[], returnReads: number): number {
|
|
45
|
+
// Authority is evaluated afresh even when its SQL remains equivalent.
|
|
46
|
+
const first = authority(context, action);
|
|
47
|
+
let changed = false;
|
|
48
|
+
for (let current: Part | undefined = this.part; current; current = current.prior) changed ||= !current.unchanged();
|
|
49
|
+
if (changed) {
|
|
50
|
+
const post = postConditions(context, collect(this.part), scope, action);
|
|
51
|
+
this.post = new GuardPacking().append(post); this.postLength = post.length;
|
|
52
|
+
}
|
|
53
|
+
if (changed || !this.writes || !this.first || !same(first, this.first) || !this.firstUnchanged?.()) {
|
|
54
|
+
this.writes = new GuardPacking().append([first, ...collect(this.part)]); this.first = first; this.firstUnchanged = observe(first);
|
|
55
|
+
}
|
|
56
|
+
const writes = this.writes.count([...tail, authority(context, action), sql('DELETE FROM ik_d1_assertions')]);
|
|
57
|
+
const checks = tail.flatMap(s => s.finalChecks ?? []), post = this.post.count(checks);
|
|
58
|
+
if (this.postLength + checks.length) finalAuthority(context, action);
|
|
59
|
+
return writes + post + Number(this.postLength + checks.length > 0) + returnReads;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
const post = postConditions(context, statements, scope, action);
|
|
63
|
+
return new Prefix(part(statements), new GuardPacking().append(post), post.length);
|
|
64
|
+
}
|
|
@@ -57,33 +57,55 @@ function conjunction(predicates: string[], start = 0, end = predicates.length):
|
|
|
57
57
|
}
|
|
58
58
|
/** Adjacent assertions can share one CHECK without changing transactional order.
|
|
59
59
|
* Native statements remain between their original pre/postconditions. */
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
60
|
+
/** Append-only state for the exact same packing algorithm. Count-only forks
|
|
61
|
+
* retain the open guard run, never copy or rebuild the already packed prefix. */
|
|
62
|
+
export class GuardPacking {
|
|
63
|
+
private seen = new Map<string, D1Sql[]>();
|
|
64
|
+
private predicates: string[] = [];
|
|
65
|
+
private params: any[] = [];
|
|
66
|
+
private bytes = 0;
|
|
67
|
+
private values = 0;
|
|
68
|
+
private completed = 0;
|
|
69
|
+
private output: D1Sql[] | undefined;
|
|
70
|
+
private readOnly: boolean;
|
|
71
|
+
constructor(readOnly = false, collect = false) { this.readOnly = readOnly; if (collect) this.output = []; }
|
|
72
|
+
fork(): GuardPacking {
|
|
73
|
+
const next = new GuardPacking(this.readOnly);
|
|
74
|
+
next.seen = new Map([...this.seen].map(([key, value]) => [key, [...value]]));
|
|
75
|
+
next.predicates = [...this.predicates]; next.params = [...this.params];
|
|
76
|
+
next.bytes = this.bytes; next.values = this.values; next.completed = this.completed;
|
|
77
|
+
return next;
|
|
78
|
+
}
|
|
79
|
+
private flush(): void {
|
|
80
|
+
if (this.predicates.length) {
|
|
81
|
+
const text = conjunction(this.predicates), packed = this.readOnly
|
|
82
|
+
? { sql: `SELECT CASE WHEN (${text}) THEN 1 ELSE 0 END AS ok`, params: this.params }
|
|
83
|
+
: guard({ sql: text, params: this.params });
|
|
84
|
+
checkSql(packed); this.output?.push(packed); this.completed++;
|
|
70
85
|
}
|
|
71
|
-
predicates = []; params = []; bytes = 0;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
if (
|
|
78
|
-
|
|
86
|
+
this.predicates = []; this.params = []; this.bytes = this.values = 0;
|
|
87
|
+
}
|
|
88
|
+
append(statements: D1Sql[]): this {
|
|
89
|
+
for (const statement of statements) {
|
|
90
|
+
checkSql(statement);
|
|
91
|
+
const predicate = guardPredicate(statement);
|
|
92
|
+
if (!predicate) {
|
|
93
|
+
if (this.readOnly) throw new Error('IMPORT_READ_GUARD_REQUIRED');
|
|
94
|
+
this.flush(); this.seen.clear(); this.output?.push(statement); this.completed++; continue;
|
|
95
|
+
}
|
|
96
|
+
const prior = this.seen.get(statement.sql) ?? [];
|
|
97
|
+
if (prior.some(s => (s.params?.length ?? 0) === (statement.params?.length ?? 0) && (s.params ?? []).every((p, i) => p === statement.params![i]))) continue;
|
|
98
|
+
prior.push(statement); this.seen.set(statement.sql, prior);
|
|
99
|
+
const params = predicate.params ?? [], text = `(${predicate.sql})`;
|
|
100
|
+
const bytes = Buffer.byteLength(text), values = params.reduce((n, p) => n + valueBytes(p), 0);
|
|
101
|
+
if (this.predicates.length && (this.params.length + params.length > 100 || this.bytes + bytes > 90000 || this.values + values > 1500000 || this.predicates.length >= 50)) this.flush();
|
|
102
|
+
this.predicates.push(text); this.params.push(...params); this.bytes += bytes; this.values += values;
|
|
79
103
|
}
|
|
80
|
-
|
|
81
|
-
if (prior.some(s => (s.params?.length ?? 0) === (statement.params?.length ?? 0) && (s.params ?? []).every((p, i) => p === statement.params![i]))) continue;
|
|
82
|
-
prior.push(statement); seen.set(statement.sql, prior);
|
|
83
|
-
const p = predicate.params ?? [], text = `(${predicate.sql})`;
|
|
84
|
-
const nextBytes = Buffer.byteLength(text);
|
|
85
|
-
if (predicates.length && (params.length + p.length > 100 || bytes + nextBytes > 90000 || params.reduce((n, p) => n + valueBytes(p), 0) + p.reduce((n, p) => n + valueBytes(p), 0) > 1500000 || predicates.length >= 50)) flush();
|
|
86
|
-
predicates.push(text); params.push(...p); bytes += nextBytes;
|
|
104
|
+
return this;
|
|
87
105
|
}
|
|
88
|
-
flush(); return
|
|
106
|
+
count(tail: D1Sql[] = []): number { const next = this.fork().append(tail); next.flush(); return next.completed; }
|
|
107
|
+
finish(): D1Sql[] { this.flush(); return this.output!; }
|
|
108
|
+
}
|
|
109
|
+
export function packGuards(statements: D1Sql[], readOnly = false): D1Sql[] {
|
|
110
|
+
return new GuardPacking(readOnly, true).append(statements).finish();
|
|
89
111
|
}
|