@runeditrun/rer 0.2.79 → 0.2.81
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/deploy-needs.mjs +4 -2
- package/cli/dev-identity.mjs +2 -2
- package/cli/export.mjs +1 -1
- package/cli/inspect.mjs +38 -2
- package/cli/ledger-refusal.mjs +18 -0
- package/cli/main.mjs +8 -2
- package/cli/managed-server.mjs +1 -1
- package/cli/parse.mjs +7 -6
- package/cli/portability-migrations.mjs +30 -11
- package/cli/portability-worker.mjs +4 -1
- package/cli/portability.mjs +8 -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 +6 -5
- package/cli/site-hosting.mjs +90 -0
- package/cli/site-preview.mjs +4 -1
- package/cli/site-render.mjs +3 -2
- package/cli/site.mjs +8 -4
- package/edition-authoring/adopt.mjs +39 -0
- package/edition-authoring/base-acknowledgements.mjs +24 -0
- package/edition-authoring/base-copies.mjs +427 -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/runtime-dependencies.mjs +108 -0
- package/edition-authoring/sources.mjs +114 -0
- package/edition-authoring/updates.mjs +105 -0
- package/global/CHANGELOG.md +24 -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 +16 -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 +148 -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/dependencies/auth.mjs +2 -2
- package/modules/deploy-kit/README.md +19 -15
- package/modules/deploy-kit/owner-cli.mjs +1 -1
- package/modules/deploy-kit/owner.mjs +8 -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-effects.ts +33 -0
- package/modules/import-kit/src/d1/apply.ts +46 -14
- 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/import-kit/src/types.ts +3 -1
- 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/README.md +92 -3
- package/modules/operator-auth/accounts/admin.mjs +52 -20
- package/modules/operator-auth/accounts/audit.mjs +24 -0
- package/modules/operator-auth/accounts/business-team.mjs +91 -0
- package/modules/operator-auth/accounts/domain-audit.mjs +24 -0
- package/modules/operator-auth/accounts/native.mjs +6 -2
- 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 +26 -4
- package/modules/operator-auth/accounts/status.mjs +7 -2
- package/modules/operator-auth/accounts/store.mjs +32 -6
- package/modules/operator-auth/business-settings.mjs +40 -0
- 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/identity/email-link/index.mjs +1 -1
- package/modules/operator-auth/identity/oidc/admin-audit.mjs +31 -0
- package/modules/operator-auth/identity/oidc/index.mjs +12 -5
- package/modules/operator-auth/identity/oidc/store.mjs +2 -0
- package/modules/operator-auth/index.d.mts +41 -2
- package/modules/operator-auth/page.mjs +14 -0
- package/modules/operator-auth/representation.mjs +83 -0
- package/modules/operator-auth/routes.mjs +31 -3
- package/modules/operator-auth/service.mjs +8 -3
- package/modules/operator-auth/signin/index.mjs +1 -1
- package/modules/portability/README.md +173 -15
- 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 +10 -14
- package/modules/portability/format.mjs +12 -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 +13 -2
- package/modules/portability/index.mjs +3 -2
- package/modules/portability/ledgers.mjs +27 -4
- 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 +94 -11
- package/modules/release/github-verify.mjs +30 -9
- package/modules/release/sign.mjs +4 -2
- package/modules/release/signature.mjs +14 -7
- package/modules/release/signing-cli.mjs +2 -1
- package/modules/release/statement.mjs +2 -2
- package/modules/release/vectors/generate.mjs +1 -0
- package/modules/release/vectors/publisher-projects.mjs +133 -0
- package/modules/release/vectors/release-signature-vectors.json +5195 -0
- package/modules/release/verify.mjs +5 -1
- 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 +68 -1
- package/onboarding/schema/business-field-inputs.mjs +36 -0
- package/onboarding/schema/json-schema.mjs +6 -2
- package/onboarding/schema/setup-validation.mjs +23 -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
package/global/README.md
CHANGED
|
@@ -4,6 +4,17 @@
|
|
|
4
4
|
Run Edit Run checkout: every verb runs that checkout's own pinned copy, so a
|
|
5
5
|
checkout always gets the behaviour it was built and tested with.
|
|
6
6
|
|
|
7
|
+
For source authors, `rer adopt-edition` adds a recipe and lock to existing tracked
|
|
8
|
+
seed source while preserving copy/composition provenance. `rer refresh-base
|
|
9
|
+
--ref FULL_COMMIT` refreshes recorded Base copies with the seed's pinned package;
|
|
10
|
+
no vendored authoring CLI is needed. Base source comes from a temporary clone of
|
|
11
|
+
`https://github.com/runeditrun/base.git` unless the seed declares another source
|
|
12
|
+
or you pass `--base CHECKOUT`. Offline refresh requires `--offline --base CHECKOUT`.
|
|
13
|
+
Both verbs have effect-free `--help` and newline-delimited `--json` events.
|
|
14
|
+
Review source changes and run edition tests before committing. See the
|
|
15
|
+
[edition authoring guide](https://github.com/runeditrun/base/blob/main/export/EDITION-AUTHORING.md)
|
|
16
|
+
for adoption, refusal behavior, JSON fields and the original Base-checkout form.
|
|
17
|
+
|
|
7
18
|
## Install
|
|
8
19
|
|
|
9
20
|
Start a seed from an empty folder, with or without Node:
|
|
@@ -244,8 +255,11 @@ which inside `pnpm run` is the pinned copy in `node_modules/.bin`, so
|
|
|
244
255
|
`pnpm install --frozen-lockfile && pnpm run build` needs no global `rer`. A global
|
|
245
256
|
`rer` hands every verb to the pinned package, launching included. Until
|
|
246
257
|
`node_modules` holds the pinned version (a fresh clone, or a pulled pin change),
|
|
247
|
-
|
|
248
|
-
started at once share that one install.
|
|
258
|
+
commands that run project code install it first (the frozen `pnpm install`),
|
|
259
|
+
then run it; commands started at once share that one install. Help, version,
|
|
260
|
+
read-only `doctor`, and `release sign`, `release receipt` and `release keygen`
|
|
261
|
+
do not install dependencies. The release producer still bootstraps before it
|
|
262
|
+
runs project build or verification scripts.
|
|
249
263
|
Every dependency install, `rer release`'s included, receives an allowlisted
|
|
250
264
|
environment: the shell, locale, terminal and temporary-folder variables, `CI`,
|
|
251
265
|
`TZ`, `SSH_AUTH_SOCK`, `NODE_OPTIONS`, `NODE_EXTRA_CA_CERTS`, `XDG_*`, proxy
|
|
@@ -514,7 +528,7 @@ The current MCP `next_question` filters out owner items. When an owner summary
|
|
|
514
528
|
is supplied, the CLI displays its browser link and refuses to answer it.
|
|
515
529
|
|
|
516
530
|
The four deterministic adapter implementations and their native output formats
|
|
517
|
-
are described in [the adapter guide](cli/business/vendors/README.md). Their
|
|
531
|
+
are described in [the adapter guide](https://github.com/runeditrun/base/blob/main/cli/business/vendors/README.md). Their
|
|
518
532
|
presence does not enable export until the seed import authority and remaining
|
|
519
533
|
transport contracts are connected.
|
|
520
534
|
|
package/global/cli/install.mjs
CHANGED
|
@@ -8,6 +8,7 @@ import { ownManifest, ownRoot, packageDigest, packageFileList } from '../package
|
|
|
8
8
|
import { installRecord, launcherOwner, launcherScript, layout } from './layout.mjs';
|
|
9
9
|
import { pathAdvice } from './path-link.mjs';
|
|
10
10
|
import { runningDoor } from '../../cli/door.mjs';
|
|
11
|
+
import { channelOf } from './status.mjs';
|
|
11
12
|
|
|
12
13
|
async function readLink(path) { try { return await readlink(path); } catch (error) { if (['ENOENT', 'EINVAL'].includes(error.code)) return undefined; throw error; } }
|
|
13
14
|
|
|
@@ -49,7 +50,8 @@ async function closing(paths) {
|
|
|
49
50
|
|
|
50
51
|
export async function install({ quiet = false } = {}) {
|
|
51
52
|
const paths = layout(), manifest = ownManifest(), digest = await packageDigest(ownRoot);
|
|
52
|
-
const name = `${manifest.version}-${digest.slice(0, 8)}
|
|
53
|
+
const name = `${manifest.version}-${digest.slice(0, 8)}`;
|
|
54
|
+
const channel = (process.env.RER_INSTALL_CHANNEL ?? (await channelOf(paths)).channel) === 'script' ? 'script' : 'npx';
|
|
53
55
|
const launcher = await launcherOwner(paths.launcher);
|
|
54
56
|
if (launcher.state === 'foreign') {
|
|
55
57
|
process.stderr.write(`rer cli install: ${paths.launcher} already exists and was not written by rer cli install (it may be the unrelated npm package "rer"). Nothing was changed. Remove or rename it, then run the install again.\n`);
|
package/global/main.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { checkoutBootstrap, checkoutVerbs } from '../cli/contract.mjs';
|
|
2
2
|
import { dispatcher, locate, pinnedPackage, unsupportedMessage } from './checkout.mjs';
|
|
3
3
|
import { delegate } from './delegate.mjs';
|
|
4
4
|
import { localDefaults } from './launch/local-defaults.mjs';
|
|
@@ -15,7 +15,8 @@ ${repositoryHelp}
|
|
|
15
15
|
|
|
16
16
|
Inside a project (the nearest OPERATIONS.json at or above this folder, or --cwd DIR),
|
|
17
17
|
every verb runs that checkout's own pinned rer: the @runeditrun/rer version its package.json
|
|
18
|
-
pins (installed first
|
|
18
|
+
pins (installed first for commands that run project code when node_modules holds another),
|
|
19
|
+
else its vendored scripts/rer.mjs.
|
|
19
20
|
|
|
20
21
|
rer dev Launch a first-party checkout with no setup steps: installs dependencies,
|
|
21
22
|
sets up a local owner and a free port when needed, starts the app and prints
|
|
@@ -44,17 +45,13 @@ pins (installed first by any verb when node_modules holds another), else its ven
|
|
|
44
45
|
Run COMMAND once this computer's job queue admits it (heavy package scripts
|
|
45
46
|
of a checkout that pins the rer package use it).
|
|
46
47
|
|
|
47
|
-
Checkout verbs:
|
|
48
|
-
import, doctor, describe, check, release, listing. Run rer VERB --help in a checkout for its flags.
|
|
48
|
+
Checkout verbs: ${Object.keys(checkoutVerbs).join(', ')}, listing. Run rer VERB --help in a checkout for its flags.
|
|
49
49
|
`;
|
|
50
50
|
|
|
51
|
-
// The checkout verbs that install the pinned package before they run when
|
|
52
|
-
// node_modules holds another version or none (dev installs it in its launch).
|
|
53
|
-
const installsFirst = new Set([...Object.keys(verbs), 'signin', 'release'].filter(verb => !['dev', 'doctor'].includes(verb)));
|
|
54
|
-
|
|
55
51
|
export async function main(argv) {
|
|
56
52
|
handleBrokenPipes();
|
|
57
53
|
const [verb] = argv;
|
|
54
|
+
const installsFirst = checkoutBootstrap(argv) === 'before';
|
|
58
55
|
if (verb === '--version' || verb === '-v') return (await import('./version.mjs')).versionCommand(argv);
|
|
59
56
|
if (verb === 'queue' && argv.length === 2 && argv[1] === '--help') {
|
|
60
57
|
process.stdout.write('Usage: rer queue NAME -- COMMAND [ARGS]\nRun COMMAND once this computer\'s job queue admits it.\n');
|
|
@@ -102,7 +99,7 @@ export async function main(argv) {
|
|
|
102
99
|
const code = await (await import('./browser-runtime.mjs')).browserPreflight(target.root, target.args);
|
|
103
100
|
if (code !== undefined) return code;
|
|
104
101
|
}
|
|
105
|
-
const bootstrap = pinnedPackage(target.root)?.ready === false && installsFirst
|
|
102
|
+
const bootstrap = pinnedPackage(target.root)?.ready === false && installsFirst;
|
|
106
103
|
if ((bootstrap || ['install', 'setup', 'dev', 'preview', 'build', 'verify'].includes(verb)) && !argv.includes('--help') && !argv.includes('--stop')) {
|
|
107
104
|
const { parse } = await import('../cli/parse.mjs');
|
|
108
105
|
// The door's launch marker belongs to launchDev, which consumes it before
|
|
@@ -125,13 +122,13 @@ export async function main(argv) {
|
|
|
125
122
|
}
|
|
126
123
|
// A checkout that pins its own rer package runs all of it, launching included.
|
|
127
124
|
// Until node_modules holds the pinned version (a fresh clone, or a pulled pin
|
|
128
|
-
// change),
|
|
125
|
+
// change), a command that runs project code installs it with the frozen lockfile and then
|
|
129
126
|
// runs the pinned verb, so a fresh clone checks and a changed pin deploys with
|
|
130
127
|
// the pinned bytes; the zero-setup launch installs it first.
|
|
131
128
|
// Verbs started at once share one install, and one whose pin already looks
|
|
132
129
|
// installed waits for an install still running.
|
|
133
130
|
const pinned = first && mode !== 'package' ? pinnedPackage(target.root) : undefined;
|
|
134
|
-
if (pinned && !pinned.ready && !argv.includes('--help') && installsFirst
|
|
131
|
+
if (pinned && !pinned.ready && !argv.includes('--help') && installsFirst) {
|
|
135
132
|
const { installPinned } = await import('./launch/install-pinned.mjs'), { LaunchFailure } = await import('./launch/failure.mjs');
|
|
136
133
|
try { await installPinned(target.root); }
|
|
137
134
|
catch (failure) {
|
|
@@ -142,7 +139,7 @@ export async function main(argv) {
|
|
|
142
139
|
return failure.exitCode;
|
|
143
140
|
}
|
|
144
141
|
}
|
|
145
|
-
if (mode === 'package' && installsFirst
|
|
142
|
+
if (mode === 'package' && installsFirst) await (await import('./launch/install-pinned.mjs')).settledPin(target.root);
|
|
146
143
|
if (verb === 'describe' && !argv.includes('--help')) return (await import('./cli/describe.mjs')).describeCommand(target);
|
|
147
144
|
if (first && dispatcher(target.root).mode !== 'bundled' && verb === 'verify' && !argv.includes('--help') && !argv.includes('--site')) {
|
|
148
145
|
const code = await (await import('./browser-runtime.mjs')).browserPreflight(target.root, target.args);
|
|
@@ -91,7 +91,7 @@ async function buildImage(root, { output = join(root,'.rer/container/image'), en
|
|
|
91
91
|
}
|
|
92
92
|
const base = resolve(import.meta.dirname,'../..');
|
|
93
93
|
for (const path of ['modules/container','modules/portability','modules/d1-transport','modules/deploy-kit','cli/scheduled.mjs','cli/jsonc.mjs','modules/integrations/core/public-address.ts']) { await mkdir(join(output,'runtime',path,'..'),{recursive:true}); await cp(join(base,path),join(output,'runtime',path),{recursive:true,filter:path => !path.includes('/tests/')}); }
|
|
94
|
-
const dependencies = { ws:'8.
|
|
94
|
+
const dependencies = { ws:'8.22.0', ...(engine === 'workerd' ? { miniflare:'5.20260907.0-alpha' } : {}) };
|
|
95
95
|
await writeFile(join(output,'runtime/package.json'),JSON.stringify({private:true,type:'module',dependencies}));
|
|
96
96
|
await writeFile(join(output,'Dockerfile'),`FROM node:26.8.1-bookworm-slim\nRUN apt-get update && apt-get install -y --no-install-recommends util-linux ca-certificates && apt-get clean\nRUN mkdir -p /private /archive\nWORKDIR /runtime\nCOPY runtime/package.json ./package.json\nRUN npm install --omit=dev --no-audit --no-fund\nCOPY runtime/ /runtime/\nCOPY app/ /app/\nENV NODE_ENV=production PORT=8080 WRANGLER_SEND_METRICS=false\nEXPOSE 8080\nVOLUME /data\nENTRYPOINT ["sh", "/runtime/modules/container/entrypoint.sh"]\n`);
|
|
97
97
|
return { output,manifest };
|
|
@@ -26,7 +26,7 @@ function parameters(sql) {
|
|
|
26
26
|
* and decoded in SQLite. Stored values and transaction boundaries are unchanged.
|
|
27
27
|
* Values whose encoding exceeds D1's bind ceiling remain native; rpcBytes then
|
|
28
28
|
* accounts for their effect on the ENTIRE call, never just that parameter. */
|
|
29
|
-
|
|
29
|
+
function encodeSql(statement) {
|
|
30
30
|
const { sql, params = [] } = statement;
|
|
31
31
|
if (!params.some(value => typeof value === 'string' && wide.test(value))) return { sql, params };
|
|
32
32
|
const tokens = parameters(sql), values = [...params], replacements = new Set();
|
|
@@ -57,33 +57,78 @@ export function wireSql(statement) {
|
|
|
57
57
|
return result;
|
|
58
58
|
}
|
|
59
59
|
|
|
60
|
+
// Weak keys retain work only while the caller retains a statement. Snapshots
|
|
61
|
+
// validate replaced arrays and in-place changes; mutable binding objects bypass
|
|
62
|
+
// reuse because their JSON representation can change without changing identity.
|
|
63
|
+
const representations = new WeakMap();
|
|
64
|
+
const primitive = value => value === null || !['object', 'function'].includes(typeof value);
|
|
65
|
+
function representation(statement) {
|
|
66
|
+
const { sql, params = [] } = statement;
|
|
67
|
+
if (typeof sql !== 'string' || !Array.isArray(params) || !params.every(primitive)) return { sql, params };
|
|
68
|
+
const prior = representations.get(statement);
|
|
69
|
+
if (prior && prior.sql === sql && prior.params.length === params.length && params.every((value, index) => Object.is(value, prior.params[index]))) return prior;
|
|
70
|
+
const current = { sql, params: [...params] };
|
|
71
|
+
representations.set(statement, current);
|
|
72
|
+
return current;
|
|
73
|
+
}
|
|
74
|
+
const encoded = record => record.encoded ??= encodeSql(record);
|
|
75
|
+
function publicQuery(record, statement) {
|
|
76
|
+
const query = encoded(record);
|
|
77
|
+
// Public callers may mutate returned SQL and bindings. Never expose cached
|
|
78
|
+
// encoded state; retain the native parameter alias when no encoding occurred.
|
|
79
|
+
const result = { sql: query.sql, params: query.params === record.params ? statement.params ?? [] : [...query.params] };
|
|
80
|
+
if (result.params.every(primitive)) representations.set(result, { sql: result.sql, params: [...result.params], rawSize: record.encodedSize });
|
|
81
|
+
return result;
|
|
82
|
+
}
|
|
83
|
+
export function wireSql(statement) { return publicQuery(representation(statement), statement); }
|
|
84
|
+
|
|
60
85
|
/** A conservative size of D1's JSON request plus RPC envelope. A single wide
|
|
61
86
|
* character makes workerd serialize every UTF-16 code unit in the call at two
|
|
62
87
|
* bytes. UTF-8 also matters independently for provider payload limits. */
|
|
63
|
-
|
|
64
|
-
let utf8 =
|
|
88
|
+
function contribution(statement) {
|
|
89
|
+
let utf8 = 0, units = 0, hasWide = false;
|
|
65
90
|
const add = text => { utf8 += bytes(text); units += text.length; hasWide ||= wide.test(text); };
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
91
|
+
add('{"sql":' + JSON.stringify(statement.sql) + ',"params":[');
|
|
92
|
+
for (const value of statement.params ?? []) {
|
|
93
|
+
if (value instanceof ArrayBuffer || ArrayBuffer.isView(value)) {
|
|
94
|
+
// D1 sends binary bindings as numeric arrays. Four bytes per element is
|
|
95
|
+
// conservative and avoids constructing a second large byte array.
|
|
96
|
+
const size = 3 + value.byteLength * 4; utf8 += size; units += size;
|
|
97
|
+
} else add(JSON.stringify(value) + ',');
|
|
98
|
+
}
|
|
99
|
+
add(']},');
|
|
100
|
+
return { utf8, units, hasWide };
|
|
101
|
+
}
|
|
102
|
+
function combined(records, encode = false) {
|
|
103
|
+
let utf8 = 2, units = 2, hasWide = false;
|
|
104
|
+
for (const record of records) {
|
|
105
|
+
let size;
|
|
106
|
+
if (encode) {
|
|
107
|
+
const query = encoded(record);
|
|
108
|
+
size = record.encodedSize ??= query.params === record.params ? record.rawSize ??= contribution(record) : contribution(query);
|
|
109
|
+
} else size = record.rawSize ??= contribution(record);
|
|
110
|
+
utf8 += size.utf8; units += size.units; hasWide ||= size.hasWide;
|
|
76
111
|
}
|
|
77
112
|
return { utf8, units, hasWide };
|
|
78
113
|
}
|
|
114
|
+
export function rpcSize(statements) { return combined(statements.map(representation)); }
|
|
79
115
|
export const rpcSizeBytes = ({ utf8, units, hasWide }) => 4096 + Math.max(utf8, units * (hasWide ? 2 : 1));
|
|
80
116
|
export const rpcBytes = statements => rpcSizeBytes(rpcSize(statements));
|
|
81
117
|
|
|
82
|
-
|
|
83
|
-
const
|
|
118
|
+
function selectBatch(statements) {
|
|
119
|
+
const records = statements.map(representation), queries = records.map(encoded);
|
|
120
|
+
const nativeBytes = rpcSizeBytes(combined(records)), encodedBytes = rpcSizeBytes(combined(records, true));
|
|
84
121
|
// Dense CJK may be smaller as native two-byte text than as six-byte escapes.
|
|
85
|
-
//
|
|
86
|
-
return
|
|
122
|
+
// One wide value affects the complete call; ties retain encoded selection.
|
|
123
|
+
return nativeBytes < encodedBytes ? { queries: statements, bytes: nativeBytes, encoded: false, records } : { queries, bytes: encodedBytes, encoded: true, records };
|
|
124
|
+
}
|
|
125
|
+
export function wireBatch(statements) {
|
|
126
|
+
const selection = selectBatch(statements);
|
|
127
|
+
return selection.encoded ? selection.records.map((record, index) => publicQuery(record, statements[index])) : statements;
|
|
128
|
+
}
|
|
129
|
+
function sameQuery(left, right) {
|
|
130
|
+
const a = left.params ?? [], b = right.params ?? [];
|
|
131
|
+
return left.sql === right.sql && a.length === b.length && a.every((value, index) => primitive(value) && Object.is(value, b[index]));
|
|
87
132
|
}
|
|
88
133
|
|
|
89
134
|
/** Adapt only D1's prepare/batch boundary; native statements supplied by a
|
|
@@ -91,7 +136,7 @@ export function wireBatch(statements) {
|
|
|
91
136
|
export function wireDatabase(db) {
|
|
92
137
|
const statements = new WeakMap();
|
|
93
138
|
const prepare = (sql, params = []) => {
|
|
94
|
-
const original = { sql, params },
|
|
139
|
+
const original = { sql, params }, selection = selectBatch([original]), query = selection.queries[0];
|
|
95
140
|
const native = params.length ? db.prepare(query.sql).bind(...query.params) : db.prepare(sql);
|
|
96
141
|
const wrapped = new Proxy(native, { get(target, key) {
|
|
97
142
|
if (key === 'bind') return (...values) => prepare(sql, values);
|
|
@@ -102,19 +147,21 @@ export function wireDatabase(db) {
|
|
|
102
147
|
};
|
|
103
148
|
return typeof value === 'function' ? value.bind(target) : value;
|
|
104
149
|
} });
|
|
105
|
-
statements.set(wrapped, { native, query, original });
|
|
150
|
+
statements.set(wrapped, { native, query: { sql: query.sql, params: [...query.params] }, original });
|
|
106
151
|
return wrapped;
|
|
107
152
|
};
|
|
108
153
|
return new Proxy(db, { get(target, key) {
|
|
109
154
|
if (key === 'prepare') return prepare;
|
|
110
155
|
if (key === 'batch') return members => {
|
|
111
156
|
const known = members.map(member => statements.get(member));
|
|
112
|
-
const
|
|
113
|
-
|
|
157
|
+
const selection = selectBatch(known.filter(Boolean).map(member => member.original));
|
|
158
|
+
const queries = selection.queries;
|
|
159
|
+
if (selection.bytes > RPC_LIMIT) throw new Error('D1_RPC_TRANSPORT_LIMIT');
|
|
114
160
|
let index = 0;
|
|
115
161
|
return db.batch(members.map((member, i) => {
|
|
116
162
|
if (!known[i]) return member;
|
|
117
163
|
const query = queries[index++];
|
|
164
|
+
if (sameQuery(query, known[i].query)) return known[i].native;
|
|
118
165
|
return query.params?.length ? db.prepare(query.sql).bind(...query.params) : db.prepare(query.sql);
|
|
119
166
|
}));
|
|
120
167
|
};
|
package/modules/demo/README.md
CHANGED
|
@@ -28,11 +28,25 @@ Production build/deploy refuses that setting; ordinary builds keep real effects.
|
|
|
28
28
|
Put `data-rer-name` on the product's text label, for example
|
|
29
29
|
`<span data-rer-name>Uptime</span>`, to show **Uptime Demo** in its nav.
|
|
30
30
|
The same attribute shows **Uptime Dev** under the local dev wrapper. No bar,
|
|
31
|
-
layout offset or timer is injected.
|
|
31
|
+
layout offset or timer is injected. In demo mode a **Run <Seed>** link sits
|
|
32
|
+
beside each marked navigation label and opens `https://<domain>/run`. The
|
|
33
|
+
existing `demoSockets()` Vite plugin supplies the public `name` and canonical
|
|
34
|
+
run-site `domain` from `deploy-demo.json` and the command adapter's
|
|
35
|
+
`site.declaration` (normally `deploy-site.json`); an explicit HTTPS `/run`
|
|
36
|
+
`runUrl` in the demo declaration takes precedence and is validated for both
|
|
37
|
+
local and hosted demos. No per-seed link is required. CSS adds the label suffix without
|
|
32
38
|
changing the application's hydrated text; CSP allows exact hashes only.
|
|
33
39
|
|
|
40
|
+
The exit uses only spare space beside or directly below the label and truncates its own text.
|
|
41
|
+
It stays out of the host layout, preserving sibling rectangles and document
|
|
42
|
+
width relative to the same header with the Demo suffix but no exit. It never
|
|
43
|
+
repairs an already overflowing host header. With no readable room it remains
|
|
44
|
+
a keyboard stop; keyboard focus reveals the full link above clipping ancestors.
|
|
45
|
+
The full name is also its accessible name and title. The host keeps ownership
|
|
46
|
+
of its responsive layout.
|
|
47
|
+
|
|
34
48
|
Public sockets, WebSockets and event streams remain usable for checks. The
|
|
35
49
|
local sockets guard and hosted egress retain a small direct mail/SMS denylist;
|
|
36
50
|
use the effect helper for such sends. Hosted demos keep their isolated
|
|
37
51
|
container, Turnstile, per-IP start limit, TTL/idle end and maximum instances.
|
|
38
|
-
See [adoption and hosting](
|
|
52
|
+
See [adoption and hosting](https://github.com/runeditrun/base/blob/main/export/DEMO.md).
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { readFile } from 'node:fs/promises';
|
|
2
|
+
import { containedInput } from './input-path.mjs';
|
|
3
|
+
import { pathToFileURL } from 'node:url';
|
|
4
|
+
|
|
5
|
+
export async function demoRunDeclaration(declaration, { root, adapter, read } = {}) {
|
|
6
|
+
if (declaration.runUrl !== undefined) return declaration;
|
|
7
|
+
read ??= async path => JSON.parse(await readFile(await containedInput(root, path), 'utf8'));
|
|
8
|
+
let bare = false;
|
|
9
|
+
if (adapter === undefined) {
|
|
10
|
+
let operations;
|
|
11
|
+
try { operations = await read('OPERATIONS.json'); }
|
|
12
|
+
catch (error) { if (error.code !== 'ENOENT') throw error; bare = true; }
|
|
13
|
+
if (operations?.seedContract) adapter = (await import(pathToFileURL(await containedInput(root, operations.seedContract.adapter)).href)).commandAdapter;
|
|
14
|
+
}
|
|
15
|
+
const path = adapter?.site?.declaration ?? (bare ? 'deploy-site.json' : undefined);
|
|
16
|
+
if (!path) return declaration;
|
|
17
|
+
let site;
|
|
18
|
+
try { site = await read(path); }
|
|
19
|
+
catch (error) { if (!bare || error.code !== 'ENOENT') throw error; }
|
|
20
|
+
return site ? { ...declaration, runUrl: `https://${site.domain}/run` } : declaration;
|
|
21
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { lstat, realpath } from 'node:fs/promises';
|
|
2
|
+
import { isAbsolute, relative, resolve, sep } from 'node:path';
|
|
3
|
+
|
|
4
|
+
// The CLI and standalone Vite copy share checkout-path resolution. The CLI
|
|
5
|
+
// supplies its public diagnostics; other callers retain filesystem errors.
|
|
6
|
+
export async function containedInput(root, path, { optional = false, privateFile = false, refuse = message => new Error(message), missing = (_message, error) => error } = {}) {
|
|
7
|
+
if (typeof path !== 'string' || !path || isAbsolute(path) || path.split(/[\\/]/).some(part => part === '..' || part === '')) throw refuse('Path must be a contained checkout path without traversal.');
|
|
8
|
+
const checkout = await realpath(root), destination = resolve(checkout, path), parts = relative(checkout, destination).split(sep);
|
|
9
|
+
let current = checkout;
|
|
10
|
+
for (let i = 0; i < parts.length; i++) {
|
|
11
|
+
current = resolve(current, parts[i]);
|
|
12
|
+
let status; try { status = await lstat(current); } catch (error) { if (error.code === 'ENOENT' && optional) return destination; if (error.code === 'ENOENT') throw missing(`Missing input file: ${path}. See the project operating documentation.`, error); throw error; }
|
|
13
|
+
if (status.isSymbolicLink()) throw refuse(`Symlink refused at ${path}; preserve it and resolve placement first.`);
|
|
14
|
+
if (i < parts.length - 1 && !status.isDirectory()) throw refuse(`Unsafe path ancestor for ${path}.`);
|
|
15
|
+
if (privateFile && i === parts.length - 1 && (!status.isFile() || status.nlink !== 1 || (status.mode & 0o077) !== 0 || (process.getuid && status.uid !== process.getuid()))) throw refuse(`Input must be an owned regular private file (0600): ${path}.`);
|
|
16
|
+
}
|
|
17
|
+
return destination;
|
|
18
|
+
}
|
package/modules/demo/label.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/** Suffix the document title and the text marked data-rer-name, without a bar. */
|
|
2
|
-
export function decorateLabel(response: Response, mode: 'Demo' | 'Dev'): Promise<Response>;
|
|
2
|
+
export function decorateLabel(response: Response, mode: 'Demo' | 'Dev', exit?: { name: string; url: string } | null): Promise<Response>;
|
package/modules/demo/label.mjs
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import { allow, sha256 } from '../operator-auth/csp.mjs';
|
|
2
|
+
import { NAVIGATION_SCRIPT, NAVIGATION_STYLE } from './navigation.mjs';
|
|
3
|
+
|
|
4
|
+
const escape = value => String(value).replace(/[&<>"']/g, character => `&#${character.charCodeAt(0)};`);
|
|
2
5
|
|
|
3
6
|
// CSS leaves React's text alone during hydration. The title observer handles
|
|
4
7
|
// client-side route changes, whose head manager writes a fresh title. The script
|
|
@@ -6,25 +9,27 @@ import { allow, sha256 } from '../operator-auth/csp.mjs';
|
|
|
6
9
|
// on the label's style element, never as code.
|
|
7
10
|
const SCRIPT = "(()=>{const suffix=document.querySelector('style[data-rer-label]').dataset.rerLabel,update=()=>{const base=document.title.replace(/\\s*(?:Demo|Dev)$/,''),title=(base?base+' ':'')+suffix;if(document.title!==title)document.title=title};update();new MutationObserver(update).observe(document.head,{childList:true,subtree:true,characterData:true})})()";
|
|
8
11
|
|
|
9
|
-
export async function decorateLabel(response, mode) {
|
|
12
|
+
export async function decorateLabel(response, mode, exit = import.meta.rerDemo) {
|
|
10
13
|
if (!response.body || !response.headers.get('content-type')?.toLowerCase().startsWith('text/html')) return response;
|
|
11
14
|
const suffix = mode === 'Demo' ? 'Demo' : 'Dev';
|
|
12
|
-
const style = `[data-rer-name]::after{content:" ${suffix}"}`;
|
|
15
|
+
const style = `[data-rer-name]::after{content:" ${suffix}"}${suffix === 'Demo' && exit ? NAVIGATION_STYLE : ''}`;
|
|
16
|
+
const script = SCRIPT + ';' + (suffix === 'Demo' && exit ? NAVIGATION_SCRIPT : '');
|
|
13
17
|
const html = await response.text();
|
|
14
18
|
if (html.includes('data-rer-label=')) return new Response(html, response);
|
|
15
19
|
const headers = new Headers(response.headers);
|
|
16
20
|
let policy = headers.get('content-security-policy');
|
|
17
21
|
if (policy) {
|
|
18
22
|
policy = allow(policy, 'style-src', await sha256(style));
|
|
19
|
-
headers.set('content-security-policy', allow(policy, 'script-src', await sha256(
|
|
23
|
+
headers.set('content-security-policy', allow(policy, 'script-src', await sha256(script)));
|
|
20
24
|
}
|
|
21
25
|
headers.delete('content-length');
|
|
22
26
|
headers.delete('etag');
|
|
23
|
-
const
|
|
27
|
+
const metadata = suffix === 'Demo' && exit ? ` data-rer-product="${escape(exit.name)}" data-rer-run="${escape(exit.url)}"` : '';
|
|
28
|
+
const addition = `<style data-rer-label="${suffix}"${metadata}>${style}</style><script>${script}</script>`;
|
|
24
29
|
const titled = html.replace(/(<title\b[^>]*>)([\s\S]*?)(<\/title>)/i, (_, open, title, close) => {
|
|
25
30
|
const base = title.replace(/\s*(?:Demo|Dev)$/, '');
|
|
26
31
|
return `${open}${base ? `${base} ` : ''}${suffix}${close}`;
|
|
27
32
|
});
|
|
28
|
-
const body = /<\/head\s*>/i.test(titled) ? titled.replace(/<\/head\s*>/i, `${addition}</head>`) : addition + titled;
|
|
33
|
+
const body = /<\/head\s*>/i.test(titled) ? titled.replace(/<\/head\s*>/i, () => `${addition}</head>`) : addition + titled;
|
|
29
34
|
return new Response(body, { status: response.status, statusText: response.statusText, headers });
|
|
30
35
|
}
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
// Runs after hydration and follows client navigation. Exits are out of flow:
|
|
2
|
+
// even a zero-width flex item would add a host gap and move its siblings.
|
|
3
|
+
export const NAVIGATION_SCRIPT = `(() => {
|
|
4
|
+
const settings = document.querySelector('style[data-rer-label]');
|
|
5
|
+
if (!settings.dataset.rerRun) return;
|
|
6
|
+
const exits = new Map();
|
|
7
|
+
let pending = false;
|
|
8
|
+
const set = (element, values) => {
|
|
9
|
+
for (const [key, value] of Object.entries(values)) {
|
|
10
|
+
if (element.style[key] !== value) element.style[key] = value;
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
const place = (link, x, y) => {
|
|
14
|
+
const parent = link.offsetParent;
|
|
15
|
+
if (!parent || (parent === document.body && getComputedStyle(parent).position === 'static')) {
|
|
16
|
+
set(link, { left: x + scrollX + 'px', top: y + scrollY + 'px' });
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
const box = parent.getBoundingClientRect();
|
|
20
|
+
const scaleX = box.width / parent.offsetWidth || 1;
|
|
21
|
+
const scaleY = box.height / parent.offsetHeight || 1;
|
|
22
|
+
set(link, {
|
|
23
|
+
left: ((x - box.left) / scaleX - parent.clientLeft + parent.scrollLeft) + 'px',
|
|
24
|
+
top: ((y - box.top) / scaleY - parent.clientTop + parent.scrollTop) + 'px'
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
const fit = (position, link) => {
|
|
28
|
+
if (link.matches(':popover-open')) return;
|
|
29
|
+
const box = position.getBoundingClientRect();
|
|
30
|
+
if (!position.getClientRects().length || !box.width || !box.height) {
|
|
31
|
+
set(link, { display: 'none' });
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
set(link, { display: 'block' });
|
|
35
|
+
const parent = position.parentElement;
|
|
36
|
+
const layout = getComputedStyle(parent);
|
|
37
|
+
const bounds = parent.getBoundingClientRect();
|
|
38
|
+
const rtl = layout.direction === 'rtl';
|
|
39
|
+
const height = parseFloat(getComputedStyle(link).lineHeight);
|
|
40
|
+
let top = box.top + (box.height - height) / 2;
|
|
41
|
+
// Clip only our own allocation to the viewport and any clipping ancestors.
|
|
42
|
+
let left = Math.max(0, bounds.left + parseFloat(layout.paddingLeft));
|
|
43
|
+
let right = Math.min(document.documentElement.clientWidth, bounds.right - parseFloat(layout.paddingRight));
|
|
44
|
+
let bottom = bounds.bottom - parseFloat(layout.paddingBottom);
|
|
45
|
+
for (let ancestor = parent; ancestor; ancestor = ancestor.parentElement) {
|
|
46
|
+
const style = getComputedStyle(ancestor);
|
|
47
|
+
if (style.overflowX !== 'visible') {
|
|
48
|
+
const clip = ancestor.getBoundingClientRect();
|
|
49
|
+
left = Math.max(left, clip.left + ancestor.clientLeft);
|
|
50
|
+
right = Math.min(right, clip.left + ancestor.clientLeft + ancestor.clientWidth);
|
|
51
|
+
bottom = Math.min(bottom, clip.top + ancestor.clientTop + ancestor.clientHeight);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
left = Math.min(document.documentElement.clientWidth, left);
|
|
55
|
+
right = Math.max(left, right);
|
|
56
|
+
const start = rtl ? box.left : box.right;
|
|
57
|
+
const siblings = [...parent.children].filter(sibling => sibling !== position && !sibling.hasAttribute('data-rer-demo-exit'));
|
|
58
|
+
const outerLeft = left, outerRight = right;
|
|
59
|
+
for (const sibling of siblings) {
|
|
60
|
+
const rect = sibling.getBoundingClientRect();
|
|
61
|
+
if (!rect.width || rect.bottom <= top || rect.top >= top + height) continue;
|
|
62
|
+
if (rtl && rect.left < start) left = Math.max(left, Math.min(start, rect.right));
|
|
63
|
+
if (!rtl && rect.right > start) right = Math.min(right, Math.max(start, rect.left));
|
|
64
|
+
}
|
|
65
|
+
const range = document.createRange();
|
|
66
|
+
range.selectNodeContents(link.firstElementChild);
|
|
67
|
+
const natural = range.getBoundingClientRect().width;
|
|
68
|
+
const gap = parseFloat(getComputedStyle(link).fontSize) / 2;
|
|
69
|
+
const room = Math.max(0, (rtl ? start - left : right - start) - 2 * gap);
|
|
70
|
+
let width = Math.min(natural, room);
|
|
71
|
+
let x = Math.max(left, Math.min(right, rtl ? start - gap - width : start + gap));
|
|
72
|
+
// A vertical rail may already have an empty row under the lockup. Use it
|
|
73
|
+
// only if the whole exit fits there without touching any existing item.
|
|
74
|
+
const below = box.bottom + gap;
|
|
75
|
+
const belowX = rtl ? box.right - gap - natural : box.left + gap;
|
|
76
|
+
if (width < natural && below + height <= bottom && belowX >= outerLeft && belowX + natural <= outerRight && siblings.every(sibling => {
|
|
77
|
+
const rect = sibling.getBoundingClientRect();
|
|
78
|
+
return !rect.width || rect.bottom <= below || rect.top >= below + height || rect.right <= belowX || rect.left >= belowX + natural;
|
|
79
|
+
})) { width = natural; x = belowX; top = below; }
|
|
80
|
+
// With no readable room, retain a keyboard stop, revealed in the top layer
|
|
81
|
+
// on focus. Neither its box nor its focus ring can extend the document.
|
|
82
|
+
const concealed = width < height;
|
|
83
|
+
set(link, { width: (concealed ? 0 : width) + 'px', height: height + 'px', clipPath: concealed ? 'inset(50%)' : 'none' });
|
|
84
|
+
place(link, x, top);
|
|
85
|
+
};
|
|
86
|
+
const schedule = () => {
|
|
87
|
+
if (pending) return;
|
|
88
|
+
pending = true;
|
|
89
|
+
requestAnimationFrame(() => { pending = false; update(); });
|
|
90
|
+
};
|
|
91
|
+
const sizes = new ResizeObserver(schedule);
|
|
92
|
+
const update = () => {
|
|
93
|
+
for (const [position, link] of exits) {
|
|
94
|
+
if (!position.isConnected || link.previousElementSibling !== position) {
|
|
95
|
+
link.remove();
|
|
96
|
+
exits.delete(position);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
for (const label of document.querySelectorAll('[data-rer-name]')) {
|
|
100
|
+
const position = label.closest('a,button') ?? label;
|
|
101
|
+
if (exits.has(position)) continue;
|
|
102
|
+
const link = document.createElement('a');
|
|
103
|
+
link.setAttribute('data-rer-demo-exit', '');
|
|
104
|
+
link.setAttribute('popover', 'manual');
|
|
105
|
+
link.href = settings.dataset.rerRun;
|
|
106
|
+
link.title = link.ariaLabel = 'Run ' + settings.dataset.rerProduct;
|
|
107
|
+
const text = document.createElement('span');
|
|
108
|
+
text.textContent = link.title;
|
|
109
|
+
link.append(text);
|
|
110
|
+
// Own only the exit's box, including when a host styles all nav anchors.
|
|
111
|
+
set(link, { position: 'absolute', display: 'block', boxSizing: 'border-box', margin: '0', padding: '0', border: '0', minWidth: '0', maxWidth: 'none', inset: 'auto', width: '0', overflow: 'visible', background: 'transparent' });
|
|
112
|
+
link.addEventListener('focus', () => {
|
|
113
|
+
if (!link.matches(':focus-visible')) return;
|
|
114
|
+
link.showPopover();
|
|
115
|
+
const box = position.getBoundingClientRect();
|
|
116
|
+
set(link, { position: 'fixed', clipPath: 'none', width: 'max-content', maxWidth: 'calc(100vw - 16px)', height: 'auto', padding: '6px', background: 'Canvas', color: 'CanvasText' });
|
|
117
|
+
const rect = link.getBoundingClientRect();
|
|
118
|
+
set(link, { left: Math.max(8, Math.min(box.left, innerWidth - rect.width - 8)) + 'px', top: Math.max(8, Math.min(box.bottom + 4, innerHeight - rect.height - 8)) + 'px' });
|
|
119
|
+
});
|
|
120
|
+
link.addEventListener('blur', () => {
|
|
121
|
+
if (!link.matches(':popover-open')) return;
|
|
122
|
+
link.hidePopover();
|
|
123
|
+
set(link, { position: 'absolute', maxWidth: 'none', padding: '0', background: 'transparent', color: '' });
|
|
124
|
+
schedule();
|
|
125
|
+
});
|
|
126
|
+
position.after(link);
|
|
127
|
+
exits.set(position, link);
|
|
128
|
+
sizes.observe(position);
|
|
129
|
+
sizes.observe(position.parentElement);
|
|
130
|
+
for (const sibling of position.parentElement.children) if (sibling !== link) sizes.observe(sibling);
|
|
131
|
+
}
|
|
132
|
+
for (const [position, link] of exits) fit(position, link);
|
|
133
|
+
};
|
|
134
|
+
const start = () => {
|
|
135
|
+
update();
|
|
136
|
+
new MutationObserver(records => {
|
|
137
|
+
if (records.some(record => !record.target.closest?.('[data-rer-demo-exit]'))) schedule();
|
|
138
|
+
}).observe(document.body, { childList: true, subtree: true, attributes: true, characterData: true });
|
|
139
|
+
addEventListener('resize', schedule);
|
|
140
|
+
addEventListener('scroll', schedule, true);
|
|
141
|
+
document.fonts.addEventListener('loadingdone', schedule);
|
|
142
|
+
};
|
|
143
|
+
const ready = () => requestAnimationFrame(() => requestAnimationFrame(start));
|
|
144
|
+
if (document.readyState === 'complete') ready();
|
|
145
|
+
else addEventListener('load', ready, { once: true });
|
|
146
|
+
})()`;
|
|
147
|
+
|
|
148
|
+
export const NAVIGATION_STYLE = '[data-rer-demo-exit]{color:var(--rer-link,inherit);font:inherit;font-size:.8125rem;font-weight:400;line-height:1.5;white-space:nowrap;text-decoration:underline;text-underline-offset:3px}[data-rer-demo-exit]>span{display:block;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}[data-rer-demo-exit]:focus-visible{outline:2px solid var(--rer-focus,currentColor);outline-offset:-2px}';
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// Shared by Vite and the hosted plan; this file also travels with src/modules/demo.
|
|
2
|
+
export function demoRunUrl(value) {
|
|
3
|
+
if (typeof value !== 'string' || !/^https:\/\//i.test(value) || /[\s\p{Cc}\\]/u.test(value)) throw new Error('invalid-demo-run-url');
|
|
4
|
+
let run;
|
|
5
|
+
try { run = new URL(value); } catch { throw new Error('invalid-demo-run-url'); }
|
|
6
|
+
if (run.protocol !== 'https:' || run.username || run.password || run.pathname !== '/run' || run.search || run.hash) throw new Error('invalid-demo-run-url');
|
|
7
|
+
if (run.hostname.length > 253 || !/^(?!www\.)(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z][a-z0-9-]{0,62}$/.test(run.hostname)) throw new Error('invalid-site-domain');
|
|
8
|
+
return run.href;
|
|
9
|
+
}
|
package/modules/demo/vite.d.mts
CHANGED
|
@@ -1,2 +1,7 @@
|
|
|
1
|
-
/**
|
|
2
|
-
export function demoSockets(): {
|
|
1
|
+
/** Supplies public demo navigation metadata and guards local demo sockets. */
|
|
2
|
+
export function demoSockets(): {
|
|
3
|
+
name: string;
|
|
4
|
+
enforce: 'pre';
|
|
5
|
+
config(config: { root?: string }, environment: { command: string }): Promise<object>;
|
|
6
|
+
resolveId(id: string): string | undefined;
|
|
7
|
+
};
|
package/modules/demo/vite.mjs
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
import { fileURLToPath } from 'node:url';
|
|
2
|
+
import { readFile } from 'node:fs/promises';
|
|
3
|
+
import { resolve } from 'node:path';
|
|
4
|
+
import { demoRunDeclaration } from './declaration.mjs';
|
|
5
|
+
import { demoRunUrl } from './run-url.mjs';
|
|
2
6
|
|
|
3
7
|
// A module namespace cannot be patched at runtime, so under `rer demo`
|
|
4
8
|
// (RER_DEMO=1) Vite hands the Worker's `cloudflare:sockets` imports the guarded
|
|
@@ -8,10 +12,21 @@ export function demoSockets() {
|
|
|
8
12
|
const on = () => process.env.RER_DEMO === '1';
|
|
9
13
|
return {
|
|
10
14
|
name: 'rer-demo-sockets',
|
|
11
|
-
apply: 'serve',
|
|
12
15
|
enforce: 'pre',
|
|
13
16
|
// Vite resolves a Worker's builtin import only when an alias names it.
|
|
14
|
-
config
|
|
17
|
+
async config(config, { command }) {
|
|
18
|
+
let declaration;
|
|
19
|
+
try { declaration = JSON.parse(await readFile(resolve(config.root ?? process.cwd(), 'deploy-demo.json'), 'utf8')); }
|
|
20
|
+
catch (error) {
|
|
21
|
+
if (error.code !== 'ENOENT') throw error;
|
|
22
|
+
if (on()) throw new Error('rer demo needs deploy-demo.json with the product name and canonical run-site domain. See DEMO.md.');
|
|
23
|
+
}
|
|
24
|
+
const resolved = declaration && await demoRunDeclaration(declaration, { root: config.root ?? process.cwd() });
|
|
25
|
+
return {
|
|
26
|
+
define: { 'import.meta.rerDemo': JSON.stringify(resolved ? { name: resolved.name, url: demoRunUrl(resolved.runUrl === undefined ? `https://${resolved.domain}/run` : resolved.runUrl) } : null) },
|
|
27
|
+
...(on() && command === 'serve' ? { resolve: { alias: [{ find: /^cloudflare:sockets$/, replacement: 'cloudflare:sockets' }] } } : {}),
|
|
28
|
+
};
|
|
29
|
+
},
|
|
15
30
|
resolveId(id) {
|
|
16
31
|
if (on() && id === 'cloudflare:sockets') return guarded;
|
|
17
32
|
},
|
|
@@ -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,
|