@runeditrun/rer 0.2.83 → 0.2.85
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 +21 -24
- package/cli/README.md +17 -1
- package/cli/authoring.mjs +1 -0
- package/cli/bounded.mjs +1 -1
- package/cli/business/carry.mjs +149 -0
- package/cli/business/command.mjs +6 -1
- package/cli/business/connect.mjs +1 -1
- package/cli/business/local-commands.mjs +2 -0
- package/cli/business/opt-ins.mjs +8 -4
- package/cli/business/questions.mjs +4 -1
- package/cli/business/state.mjs +1 -1
- package/cli/business/supervisor.mjs +7 -1
- package/cli/container-transfer.mjs +2 -2
- package/cli/contract.mjs +7 -7
- package/cli/demo-host.mjs +5 -1
- package/cli/demo-native.mjs +2 -1
- package/cli/demo.mjs +6 -1
- package/cli/deploy-command.mjs +6 -4
- package/cli/deploy.mjs +9 -7
- package/cli/errors.mjs +1 -1
- package/cli/export.mjs +1 -1
- package/cli/human-error.mjs +20 -0
- package/cli/lifecycle.mjs +23 -5
- package/cli/main.mjs +1 -1
- package/cli/managed-data-schema.mjs +114 -0
- package/cli/managed-data-zip.mjs +116 -0
- package/cli/managed-data.mjs +110 -0
- package/cli/managed-server.mjs +25 -14
- package/cli/native-owner-entry.mjs +86 -0
- package/cli/output.mjs +3 -2
- package/cli/parse.mjs +3 -3
- package/cli/portability-empty.mjs +59 -0
- package/cli/portability-migrations.mjs +7 -5
- package/cli/portability-policy.mjs +5 -2
- package/cli/portability-worker.mjs +15 -6
- package/cli/portability.mjs +30 -8
- package/cli/ready-summary.mjs +9 -0
- package/cli/run-transfers.mjs +37 -0
- package/cli/runtime-front-door.mjs +4 -4
- package/cli/server-proxy.mjs +4 -3
- package/cli/server-registry.mjs +13 -8
- package/cli/site.mjs +6 -1
- package/cli/transfers.mjs +17 -4
- package/edition-authoring/base-copies.mjs +125 -30
- package/edition-authoring/copy-checkout.mjs +7 -120
- package/edition-authoring/edition-migrations.mjs +41 -0
- package/edition-authoring/files.mjs +67 -0
- package/edition-authoring/lock.mjs +2 -2
- package/edition-authoring/module-closure.mjs +232 -0
- package/edition-authoring/module-edges.mjs +100 -0
- package/edition-authoring/module-resolution.mjs +66 -0
- package/edition-authoring/module-syntax.mjs +57 -0
- package/edition-authoring/package-target.mjs +92 -0
- package/edition-authoring/runtime-dependencies.mjs +74 -97
- package/edition-authoring/vendor/babel-parser/LICENSE +22 -0
- package/edition-authoring/vendor/babel-parser/README.md +21 -0
- package/edition-authoring/vendor/babel-parser/babel-helper-string-parser/index.mjs +292 -0
- package/edition-authoring/vendor/babel-parser/babel-helper-validator-identifier/identifier.mjs +66 -0
- package/edition-authoring/vendor/babel-parser/babel-helper-validator-identifier/index.mjs +13 -0
- package/edition-authoring/vendor/babel-parser/babel-helper-validator-identifier/keyword.mjs +31 -0
- package/edition-authoring/vendor/babel-parser/babel-parser/index.mjs +99 -0
- package/edition-authoring/vendor/babel-parser/babel-parser/options.mjs +81 -0
- package/edition-authoring/vendor/babel-parser/babel-parser/parse-error/bind-operator-errors.mjs +8 -0
- package/edition-authoring/vendor/babel-parser/babel-parser/parse-error/module-errors.mjs +15 -0
- package/edition-authoring/vendor/babel-parser/babel-parser/parse-error/parse-expression-errors.mjs +10 -0
- package/edition-authoring/vendor/babel-parser/babel-parser/parse-error/pipeline-operator-errors.mjs +29 -0
- package/edition-authoring/vendor/babel-parser/babel-parser/parse-error/standard-errors.mjs +224 -0
- package/edition-authoring/vendor/babel-parser/babel-parser/parse-error/strict-mode-errors.mjs +17 -0
- package/edition-authoring/vendor/babel-parser/babel-parser/parse-error/to-node-description.mjs +31 -0
- package/edition-authoring/vendor/babel-parser/babel-parser/parse-error.mjs +114 -0
- package/edition-authoring/vendor/babel-parser/babel-parser/parser/base.mjs +34 -0
- package/edition-authoring/vendor/babel-parser/babel-parser/parser/comments.mjs +199 -0
- package/edition-authoring/vendor/babel-parser/babel-parser/parser/expression.mjs +1794 -0
- package/edition-authoring/vendor/babel-parser/babel-parser/parser/index.mjs +76 -0
- package/edition-authoring/vendor/babel-parser/babel-parser/parser/lval.mjs +439 -0
- package/edition-authoring/vendor/babel-parser/babel-parser/parser/node.mjs +111 -0
- package/edition-authoring/vendor/babel-parser/babel-parser/parser/statement.mjs +1962 -0
- package/edition-authoring/vendor/babel-parser/babel-parser/parser/util.mjs +244 -0
- package/edition-authoring/vendor/babel-parser/babel-parser/plugin-utils.mjs +116 -0
- package/edition-authoring/vendor/babel-parser/babel-parser/plugins/estree.mjs +417 -0
- package/edition-authoring/vendor/babel-parser/babel-parser/plugins/flow/index.mjs +2412 -0
- package/edition-authoring/vendor/babel-parser/babel-parser/plugins/flow/scope.mjs +37 -0
- package/edition-authoring/vendor/babel-parser/babel-parser/plugins/jsx/index.mjs +420 -0
- package/edition-authoring/vendor/babel-parser/babel-parser/plugins/jsx/xhtml.mjs +261 -0
- package/edition-authoring/vendor/babel-parser/babel-parser/plugins/placeholders.mjs +205 -0
- package/edition-authoring/vendor/babel-parser/babel-parser/plugins/typescript/index.mjs +2889 -0
- package/edition-authoring/vendor/babel-parser/babel-parser/plugins/typescript/scope.mjs +115 -0
- package/edition-authoring/vendor/babel-parser/babel-parser/plugins/v8intrinsic.mjs +26 -0
- package/edition-authoring/vendor/babel-parser/babel-parser/tokenizer/context.mjs +22 -0
- package/edition-authoring/vendor/babel-parser/babel-parser/tokenizer/index.mjs +1037 -0
- package/edition-authoring/vendor/babel-parser/babel-parser/tokenizer/state.mjs +178 -0
- package/edition-authoring/vendor/babel-parser/babel-parser/tokenizer/types.mjs +583 -0
- package/edition-authoring/vendor/babel-parser/babel-parser/types.mjs +1 -0
- package/edition-authoring/vendor/babel-parser/babel-parser/util/class-scope.mjs +82 -0
- package/edition-authoring/vendor/babel-parser/babel-parser/util/expression-scope.mjs +121 -0
- package/edition-authoring/vendor/babel-parser/babel-parser/util/identifier.mjs +23 -0
- package/edition-authoring/vendor/babel-parser/babel-parser/util/location.mjs +34 -0
- package/edition-authoring/vendor/babel-parser/babel-parser/util/production-parameter.mjs +40 -0
- package/edition-authoring/vendor/babel-parser/babel-parser/util/scope.mjs +173 -0
- package/edition-authoring/vendor/babel-parser/babel-parser/util/scopeflags.mjs +66 -0
- package/edition-authoring/vendor/babel-parser/babel-parser/util/whitespace.mjs +61 -0
- package/edition-authoring/vendor/yaml/LICENSE +13 -0
- package/edition-authoring/vendor/yaml/README.md +11 -0
- package/edition-authoring/vendor/yaml/compose/compose-collection.mjs +88 -0
- package/edition-authoring/vendor/yaml/compose/compose-doc.mjs +43 -0
- package/edition-authoring/vendor/yaml/compose/compose-node.mjs +110 -0
- package/edition-authoring/vendor/yaml/compose/compose-scalar.mjs +86 -0
- package/edition-authoring/vendor/yaml/compose/composer.mjs +218 -0
- package/edition-authoring/vendor/yaml/compose/resolve-block-map.mjs +115 -0
- package/edition-authoring/vendor/yaml/compose/resolve-block-scalar.mjs +198 -0
- package/edition-authoring/vendor/yaml/compose/resolve-block-seq.mjs +49 -0
- package/edition-authoring/vendor/yaml/compose/resolve-end.mjs +37 -0
- package/edition-authoring/vendor/yaml/compose/resolve-flow-collection.mjs +207 -0
- package/edition-authoring/vendor/yaml/compose/resolve-flow-scalar.mjs +228 -0
- package/edition-authoring/vendor/yaml/compose/resolve-props.mjs +148 -0
- package/edition-authoring/vendor/yaml/compose/util-contains-newline.mjs +34 -0
- package/edition-authoring/vendor/yaml/compose/util-empty-scalar-position.mjs +27 -0
- package/edition-authoring/vendor/yaml/compose/util-flow-indent-check.mjs +15 -0
- package/edition-authoring/vendor/yaml/compose/util-map-includes.mjs +13 -0
- package/edition-authoring/vendor/yaml/doc/Document.mjs +333 -0
- package/edition-authoring/vendor/yaml/doc/anchors.mjs +74 -0
- package/edition-authoring/vendor/yaml/doc/applyReviver.mjs +54 -0
- package/edition-authoring/vendor/yaml/doc/createNode.mjs +88 -0
- package/edition-authoring/vendor/yaml/doc/directives.mjs +176 -0
- package/edition-authoring/vendor/yaml/errors.mjs +57 -0
- package/edition-authoring/vendor/yaml/index.mjs +17 -0
- package/edition-authoring/vendor/yaml/log.mjs +11 -0
- package/edition-authoring/vendor/yaml/nodes/Alias.mjs +119 -0
- package/edition-authoring/vendor/yaml/nodes/Collection.mjs +147 -0
- package/edition-authoring/vendor/yaml/nodes/Node.mjs +38 -0
- package/edition-authoring/vendor/yaml/nodes/Pair.mjs +36 -0
- package/edition-authoring/vendor/yaml/nodes/Scalar.mjs +24 -0
- package/edition-authoring/vendor/yaml/nodes/YAMLMap.mjs +144 -0
- package/edition-authoring/vendor/yaml/nodes/YAMLSeq.mjs +113 -0
- package/edition-authoring/vendor/yaml/nodes/addPairToJSMap.mjs +62 -0
- package/edition-authoring/vendor/yaml/nodes/identity.mjs +36 -0
- package/edition-authoring/vendor/yaml/nodes/toJS.mjs +35 -0
- package/edition-authoring/vendor/yaml/parse/cst-scalar.mjs +214 -0
- package/edition-authoring/vendor/yaml/parse/cst-stringify.mjs +61 -0
- package/edition-authoring/vendor/yaml/parse/cst-visit.mjs +97 -0
- package/edition-authoring/vendor/yaml/parse/cst.mjs +98 -0
- package/edition-authoring/vendor/yaml/parse/lexer.mjs +722 -0
- package/edition-authoring/vendor/yaml/parse/line-counter.mjs +39 -0
- package/edition-authoring/vendor/yaml/parse/parser.mjs +975 -0
- package/edition-authoring/vendor/yaml/public-api.mjs +102 -0
- package/edition-authoring/vendor/yaml/schema/Schema.mjs +37 -0
- package/edition-authoring/vendor/yaml/schema/common/map.mjs +17 -0
- package/edition-authoring/vendor/yaml/schema/common/null.mjs +15 -0
- package/edition-authoring/vendor/yaml/schema/common/seq.mjs +17 -0
- package/edition-authoring/vendor/yaml/schema/common/string.mjs +14 -0
- package/edition-authoring/vendor/yaml/schema/core/bool.mjs +19 -0
- package/edition-authoring/vendor/yaml/schema/core/float.mjs +43 -0
- package/edition-authoring/vendor/yaml/schema/core/int.mjs +38 -0
- package/edition-authoring/vendor/yaml/schema/core/schema.mjs +23 -0
- package/edition-authoring/vendor/yaml/schema/json/schema.mjs +62 -0
- package/edition-authoring/vendor/yaml/schema/tags.mjs +96 -0
- package/edition-authoring/vendor/yaml/schema/yaml-1.1/binary.mjs +59 -0
- package/edition-authoring/vendor/yaml/schema/yaml-1.1/bool.mjs +26 -0
- package/edition-authoring/vendor/yaml/schema/yaml-1.1/float.mjs +46 -0
- package/edition-authoring/vendor/yaml/schema/yaml-1.1/int.mjs +71 -0
- package/edition-authoring/vendor/yaml/schema/yaml-1.1/merge.mjs +67 -0
- package/edition-authoring/vendor/yaml/schema/yaml-1.1/omap.mjs +74 -0
- package/edition-authoring/vendor/yaml/schema/yaml-1.1/pairs.mjs +78 -0
- package/edition-authoring/vendor/yaml/schema/yaml-1.1/schema.mjs +39 -0
- package/edition-authoring/vendor/yaml/schema/yaml-1.1/set.mjs +93 -0
- package/edition-authoring/vendor/yaml/schema/yaml-1.1/timestamp.mjs +101 -0
- package/edition-authoring/vendor/yaml/stringify/foldFlowLines.mjs +146 -0
- package/edition-authoring/vendor/yaml/stringify/stringify.mjs +130 -0
- package/edition-authoring/vendor/yaml/stringify/stringifyCollection.mjs +155 -0
- package/edition-authoring/vendor/yaml/stringify/stringifyComment.mjs +20 -0
- package/edition-authoring/vendor/yaml/stringify/stringifyDocument.mjs +85 -0
- package/edition-authoring/vendor/yaml/stringify/stringifyNumber.mjs +25 -0
- package/edition-authoring/vendor/yaml/stringify/stringifyPair.mjs +150 -0
- package/edition-authoring/vendor/yaml/stringify/stringifyString.mjs +338 -0
- package/edition-authoring/vendor/yaml/util.mjs +11 -0
- package/edition-authoring/vendor/yaml/visit.mjs +233 -0
- package/edition-authoring/workflow-copies.mjs +125 -0
- package/edition-authoring/workflow-scripts.mjs +112 -0
- package/foundation/runtime/contract-docs.mjs +754 -0
- package/foundation/runtime/run-data.d.mts +1 -0
- package/foundation/runtime/run-data.mjs +2 -0
- package/global/CHANGELOG.md +55 -3
- package/global/README.md +21 -24
- package/global/cli/command.mjs +8 -2
- package/global/cli/install.mjs +4 -5
- package/global/cli/path-link.mjs +3 -2
- package/global/cli/repo-command.mjs +3 -7
- package/global/launch/dev.mjs +12 -2
- package/global/launch/facts.mjs +2 -2
- package/global/launch/render.mjs +16 -9
- package/global/launch/state.mjs +4 -4
- package/global/main.mjs +12 -7
- package/install.sh +17 -6
- package/modules/container/README.md +6 -1
- package/modules/container/adapters/d1-limits.mjs +286 -0
- package/modules/container/adapters/d1-sqlite.mjs +95 -0
- package/modules/container/adapters/d1-workerd-preload.mjs +19 -0
- package/modules/container/adapters/d1-workerd-setup.mjs +26 -0
- package/modules/container/adapters/d1-workerd.mjs +5 -0
- package/modules/container/adapters/sqlite-worker.mjs +5 -3
- package/modules/container/build.mjs +1 -0
- package/modules/container/image-variables.mjs +8 -3
- package/modules/container/transfer.mjs +14 -4
- package/modules/container/worker-engine.mjs +3 -3
- package/modules/demo/declaration.mjs +1 -4
- package/modules/demo/vite.mjs +1 -1
- package/modules/demo-host/build.mjs +1 -0
- package/modules/demo-host/native/prepare.mjs +2 -1
- package/modules/demo-host/native/sql.mjs +7 -2
- package/modules/deploy-kit/README.md +23 -3
- package/modules/deploy-kit/d1-import-diagnostics.mjs +56 -0
- package/modules/deploy-kit/d1-import.mjs +17 -5
- package/modules/deploy-kit/diagnostics.mjs +29 -3
- package/modules/deploy-kit/owner-cli.mjs +20 -7
- package/modules/deploy-kit/provider-transport.mjs +19 -4
- package/modules/deploy-kit/provider.mjs +57 -22
- package/modules/deploy-kit/readiness-window.mjs +1 -1
- package/modules/deploy-kit/site.mjs +8 -3
- package/modules/deploy-kit/templates.mjs +3 -3
- package/modules/deploy-kit/worker.mjs +4 -4
- package/modules/import-kit/src/d1/README.md +23 -4
- package/modules/import-kit/src/d1/atomic-prefix.ts +2 -2
- package/modules/import-kit/src/d1/budget.ts +15 -7
- package/modules/import-kit/src/d1/column-layout.ts +5 -0
- package/modules/import-kit/src/d1/creation.ts +15 -8
- package/modules/import-kit/src/d1/database.ts +3 -3
- package/modules/import-kit/src/d1/erasure-pages.ts +2 -1
- package/modules/import-kit/src/d1/erasure.ts +2 -2
- package/modules/import-kit/src/d1/jobs.ts +10 -6
- package/modules/import-kit/src/d1/plans.ts +14 -8
- package/modules/import-kit/src/d1/retirement.ts +2 -2
- package/modules/import-kit/src/d1/sets.ts +1 -3
- package/modules/import-kit/src/d1/staged-creation.ts +3 -3
- package/modules/import-kit/src/door/limits.ts +1 -1
- package/modules/import-kit/src/door/refusals.ts +1 -1
- package/modules/portability/README.md +112 -4
- package/modules/portability/backfills.mjs +9 -8
- package/modules/portability/bridge.mjs +12 -5
- package/modules/portability/catalogue.mjs +12 -5
- package/modules/portability/files.mjs +4 -3
- package/modules/portability/http.mjs +3 -3
- package/modules/portability/import.mjs +18 -9
- package/modules/portability/index.d.mts +4 -3
- package/modules/portability/index.mjs +1 -1
- package/modules/portability/ledgers.mjs +3 -2
- package/modules/portability/legacy-safety.mjs +11 -2
- package/modules/portability/migration-history.mjs +2 -2
- package/modules/portability/progress.mjs +1 -0
- package/modules/portability/restore-empty.mjs +12 -0
- package/modules/release/github-verify.mjs +11 -2
- package/onboarding/adapter.mjs +35 -6
- package/onboarding/app-fetch.mjs +6 -4
- package/onboarding/development-runtime.mjs +19 -0
- package/onboarding/local/operation.mjs +45 -27
- package/onboarding/loopback-fetch.mjs +16 -0
- package/onboarding/operator-installer.mjs +4 -6
- package/onboarding/process-diagnostics.mjs +6 -2
- package/onboarding/production-runtime.mjs +4 -2
- package/onboarding/readiness.mjs +1 -0
- package/package.json +1 -1
- package/scripts/publish-check/README.md +6 -0
- package/scripts/publish-check/history_scan.py +5 -3
- package/scripts/publish-check/hygiene_config.py +2 -1
- package/scripts/publish-check/public_hygiene.py +1 -1
- package/scripts/publish-check/report.py +9 -3
- package/scripts/publish-check/third-party-notices.json +13 -0
- package/scripts/publish-check/third_party_notices.py +38 -0
- package/scripts/publish-check/tree_scan.py +6 -0
- package/scripts/publish-check.mjs +1 -1
package/cli/managed-server.mjs
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import { launchSummary } from './run-transfers.mjs';
|
|
2
|
+
import { readySummary } from './ready-summary.mjs';
|
|
3
|
+
import { nativeOwnerEntry } from './native-owner-entry.mjs';
|
|
1
4
|
import { prepareLiveModels } from './ai-local.mjs';
|
|
2
5
|
import {fileURLToPath} from 'node:url';
|
|
3
6
|
import {join} from 'node:path';
|
|
@@ -19,23 +22,29 @@ import { readDevKey,requireDevKey,refuseManagedInstallation,resolvePersona,openU
|
|
|
19
22
|
import { announceDoorRoute,claimSavedName,moveCheckout,routeRunning,verifyDoorFor } from './door-mode.mjs';
|
|
20
23
|
|
|
21
24
|
// Dev opens through the local identity exchange. Preview serves production output.
|
|
22
|
-
export function ready(out,url,dev,json=false,siteUrl,demo){
|
|
23
|
-
if(json){out.event('ready',{url,...(dev?{signedInAs:dev.signedInAs??null,openUrl:dev.openUrl}:{}),...(siteUrl?{siteUrl}:{}),...(demo?{demo}:{})});return;}
|
|
25
|
+
export async function ready(out,url,dev,json=false,siteUrl,demo,root,ownerOpenUrl){
|
|
26
|
+
if(json){out.event('ready',{url,...(dev?{signedInAs:dev.signedInAs??null,openUrl:dev.openUrl}:{}),...(ownerOpenUrl?{ownerOpenUrl}:{}),...(siteUrl?{siteUrl}:{}),...(demo?{demo}:{})});return;}
|
|
27
|
+
if (root) {
|
|
28
|
+
for (const line of readySummary({ url, ...dev, siteUrl })) out.human(line);
|
|
29
|
+
for (const line of await launchSummary(root)) out.human(line);
|
|
30
|
+
out.human('Details for tools and troubleshooting:');
|
|
31
|
+
} else out.human(`Your app is ready, open it: ${dev?.openUrl ?? url}`);
|
|
24
32
|
out.human(`RER_READY ${url}`);
|
|
25
33
|
if(dev){
|
|
26
34
|
if(dev.signedInAs)out.human(`RER_SIGNED_IN ${dev.signedInAs}`);
|
|
27
35
|
else if(dev.ownerLeft)out.human('No active owner remains in this app. Use rer dev --as PERSONA with an active operator, or rer reset --yes and rer setup for a new owner.');
|
|
28
36
|
out.human(`RER_OPEN ${dev.openUrl}`);
|
|
29
|
-
out.human("Open that link on this computer. Its fragment holds this checkout's dev key, which the page keeps only as a cookie; never share the link.");
|
|
37
|
+
if (!root && !dev.native) out.human("Open that link on this computer. Its fragment holds this checkout's dev key, which the page keeps only as a cookie; never share the link.");
|
|
30
38
|
}
|
|
31
|
-
if(
|
|
39
|
+
if(ownerOpenUrl){out.human(`RER_OWNER_OPEN ${ownerOpenUrl}`);out.human('Native owner entry: open on this computer once within 15 minutes. The link is not saved.');}
|
|
40
|
+
if(siteUrl){if(!root)out.human(`Site: ${siteUrl}`);out.human(`RER_SITE ${siteUrl}`);}
|
|
32
41
|
if(demo){out.human(`RER_DEMO_ENDS_ON_STOP ${demo.state}`);out.human(`This demo runs on its own data in that folder, which is deleted when it stops: rer demo --stop, Ctrl-C, or at its end (${demo.ends.slice(11,16)}). Public reads and checks run for real. This checkout's own data is untouched.`);}
|
|
33
42
|
}
|
|
34
43
|
export async function managedServer(project,options,out,{clock={}}={}){
|
|
35
44
|
const registry=await serverRegistry(project.root),controller=new AbortController();
|
|
36
45
|
// A demo registers as its own mode: `rer dev --stop` never stops it by accident.
|
|
37
46
|
const mode=options.demo?'demo':options.verb;
|
|
38
|
-
let store,operation,proxy,activity,app,termination,reason,cleanupPromise,finished,selected,cleaned,site,demo,demoEnd;
|
|
47
|
+
let store,operation,proxy,activity,app,termination,reason,cleanupPromise,finished,selected,cleaned,site,demo,demoEnd,ownerEntry;
|
|
39
48
|
const scheduling=new AbortController();
|
|
40
49
|
let activityWrites=Promise.resolve(),pendingActivity,activityWriting=false,infrastructureFailure;
|
|
41
50
|
function recordActivity(fields){
|
|
@@ -44,7 +53,7 @@ export async function managedServer(project,options,out,{clock={}}={}){
|
|
|
44
53
|
}
|
|
45
54
|
const stopped=new Promise(resolve=>{finished=resolve;});
|
|
46
55
|
const cleanupDone=new Promise(resolve=>{cleaned=resolve;});
|
|
47
|
-
const cleanup=()=>cleanupPromise??=(async()=>{scheduling.abort();clearTimeout(demoEnd);activity?.close();await site?.close();await store?.closeCommands();if(demo)await rm(demo.state,{recursive:true,force:true});await proxy?.close();await operation?.release();})();
|
|
56
|
+
const cleanup=()=>cleanupPromise??=(async()=>{scheduling.abort();clearTimeout(demoEnd);activity?.close();await site?.close();await ownerEntry?.close();await store?.closeCommands();if(demo)await rm(demo.state,{recursive:true,force:true});await proxy?.close();await operation?.release();})();
|
|
48
57
|
const stop=async why=>{reason??=why;controller.abort();finished();await cleanupDone;return {};};
|
|
49
58
|
const handlers=new Map(['SIGINT','SIGTERM'].map(name=>[name,()=>{termination=name;void stop(name);} ]));
|
|
50
59
|
for(const [name,handler]of handlers)process.on(name,handler);
|
|
@@ -77,10 +86,11 @@ export async function managedServer(project,options,out,{clock={}}={}){
|
|
|
77
86
|
// A key is sent (or printed) for a door origin only once the door proves it is ours.
|
|
78
87
|
if(devIdentity)await verifyDoorFor(running.url);
|
|
79
88
|
const dev=devIdentity&&options.verb==='dev'&&await devReady(running.url,devKey,options,controller.signal);
|
|
80
|
-
await emitReady(out,options,project.root,running.url,dev,running.siteUrl,running.demo);return {reused:true};
|
|
89
|
+
await emitReady(out,options,project.root,running.url,dev,running.siteUrl,running.demo,(await registry.ownerEntry(running)).ownerOpenUrl);return {reused:true};
|
|
81
90
|
}
|
|
82
91
|
await registry.serve(async action=>{
|
|
83
92
|
if(action==='status')return {...activity?.snapshot(),url:selected?.url,probe:proxy?.probe,siteUrl:site?.url,demo};
|
|
93
|
+
if(action==='owner-entry')return ownerEntry?{ownerOpenUrl:ownerEntry.issue()}:{};
|
|
84
94
|
if(action==='stop')return stop('explicit stop');
|
|
85
95
|
throw Error('Unknown management operation');
|
|
86
96
|
});
|
|
@@ -97,7 +107,7 @@ export async function managedServer(project,options,out,{clock={}}={}){
|
|
|
97
107
|
if(!selected.door)await availablePort(selected.host,selected.port,{root:project.root,saved:!selected.explicitPort&&selected.savedOrigin!==undefined,verb:options.verb});
|
|
98
108
|
if(!selected.vars[keys.email])throw missing('Private owner settings are missing. Run rer setup first.');
|
|
99
109
|
if(devIdentity&&!devKey)devKey=await requireDevKey(project.root);
|
|
100
|
-
if(devIdentity&&options.verb
|
|
110
|
+
if(devIdentity&&['dev','preview'].includes(options.verb))refuseManagedInstallation(selected.vars,process.env);
|
|
101
111
|
if(options.demo)demo=await demoPreflight(project,selected.vars,options.idleTimeout);
|
|
102
112
|
const prerequisites=async()=>{
|
|
103
113
|
if(!demo&&project.adapter.localPrerequisites&&!await project.adapter.localPrerequisites({root:project.root,vars:selected.vars,email:selected.vars[keys.email],demo:false}))throw missing('Local migrations, owner or local authentication/mail settings are missing. Run rer setup first.');
|
|
@@ -115,10 +125,11 @@ export async function managedServer(project,options,out,{clock={}}={}){
|
|
|
115
125
|
activity=activityClock({...clock,seconds:options.idleTimeout,onIdle:()=>void stop('idle timeout'),onChange:recordActivity});
|
|
116
126
|
if(demo)demoEnd=setTimeout(()=>void stop('demo ended'),Math.min(Date.parse(demo.ends)-Date.now(),2**31-1));
|
|
117
127
|
const crons=project.adapter.scheduled!==false?await declaredCrons(project.root,project.adapter).catch(error=>{throw refuse(`The declared scheduled triggers cannot run locally: ${error.message}`);}):[];
|
|
118
|
-
|
|
128
|
+
if(devIdentity&&(options.verb==='preview'||demo))ownerEntry=nativeOwnerEntry({origin:selected.url,state:demo?.state??join(project.root,'.wrangler','state'),store,demo:!!demo,devKey});
|
|
129
|
+
proxy=await runtimeFrontDoor({host:selected.host,port:selected.port,activity,door:selected.door,devKey:devKey??undefined,origin:selected.url,ownerEntry:(req,res)=>ownerEntry?.handle(req,res)});const internal=proxy.runtimePort;
|
|
119
130
|
if(selected.door)await announceDoorRoute(selected,proxy,registry);
|
|
120
131
|
const modelsLive = options.verb==='dev' ? await prepareLiveModels(project.root,options,store,controller.signal) : undefined;
|
|
121
|
-
const adapterOptions={modelsLive,demo,selectedOrigin:selected.url,operationToken:operation.token,privateSettings:project.adapter.settings,runtimePort:internal,devKey:devKey??undefined,devLogin:false,scheduled:crons.length>0,beforeStart:options.verb==='dev'?prerequisites:undefined};
|
|
132
|
+
const adapterOptions={modelsLive,demo,selectedOrigin:selected.url,operationToken:operation.token,privateSettings:project.adapter.settings,runtimePort:internal,setRuntimePort:port=>proxy.setRuntimePort(port),devKey:devKey??undefined,devLogin:false,scheduled:crons.length>0,beforeStart:options.verb==='dev'?prerequisites:undefined};
|
|
122
133
|
const input={[keys.email]:selected.vars[keys.email]};
|
|
123
134
|
if(options.verb==='preview')await productionBuild(project,()=>store.run('Building fixed production output',process.execPath,[fileURLToPath(new URL('../bin/rer.mjs',import.meta.url)),'build','--cwd',project.root,'--json'],{cwd:project.root,phase:'build',signal:controller.signal,env:{...process.env,RER_LOCAL_OPERATION:operation.token},afterCommand:()=>recoverInterrupted(project.root,operation)}),text=>store.report(text));
|
|
124
135
|
await serverResources(project.root);
|
|
@@ -144,10 +155,10 @@ export async function managedServer(project,options,out,{clock={}}={}){
|
|
|
144
155
|
if(options.json)out.event('warning',{code:error.code,message});else out.progress(`Warning: ${message}\n`);
|
|
145
156
|
}
|
|
146
157
|
}
|
|
147
|
-
activity.ready();await emitReady(out,options,project.root,selected.url,dev,site?.url,demo);
|
|
158
|
+
activity.ready();await emitReady(out,options,project.root,selected.url,dev,site?.url,demo,ownerEntry?.issue());
|
|
148
159
|
if(crons.length){
|
|
149
160
|
out.progress(`Running ${crons.length===1?'the scheduled trigger':'the scheduled triggers'} locally: ${crons.join(' | ')}\n`);
|
|
150
|
-
void runScheduled({crons,url:`http://127.0.0.1:${
|
|
161
|
+
void runScheduled({crons,url:`http://127.0.0.1:${proxy.runtimePort}`,path:options.verb==='preview'?'/cdn-cgi/local/scheduled':undefined,signal:scheduling.signal,report:run=>reportScheduled(out,options,run)});
|
|
151
162
|
}
|
|
152
163
|
const result=await stopped;
|
|
153
164
|
if(termination)throw new RerError('cancelled',`Stopped by ${termination} after owned children were stopped.`,termination==='SIGINT'?130:143);
|
|
@@ -164,12 +175,12 @@ function reportScheduled(out,options,run){
|
|
|
164
175
|
// dev also keeps its RER_OPEN link in owner-only .rer/local/open-url (0600),
|
|
165
176
|
// which reset removes with the rest of .rer/local, for a person or agent that
|
|
166
177
|
// did not keep the terminal output.
|
|
167
|
-
async function emitReady(out,options,root,url,dev,siteUrl,demo){
|
|
178
|
+
async function emitReady(out,options,root,url,dev,siteUrl,demo,ownerOpenUrl){
|
|
168
179
|
if(options.verb==='dev'&&dev?.openUrl){
|
|
169
180
|
const {privateDirectory,writePrivateFile}=await shared('private-files.mjs');
|
|
170
181
|
await writePrivateFile(join(await privateDirectory(root,['.rer','local']),'open-url'),dev.openUrl+'\n');
|
|
171
182
|
}
|
|
172
|
-
ready(out,url,dev||undefined,options.json,siteUrl,demo);
|
|
183
|
+
await ready(out,url,dev||(ownerOpenUrl?{openUrl:ownerOpenUrl,native:true}:undefined),options.json,siteUrl,demo,options.verb === 'dev' && !options.demo ? root : undefined,ownerOpenUrl);
|
|
173
184
|
}
|
|
174
185
|
async function devReady(url,key,options,signal){
|
|
175
186
|
const as=options.as??'owner',persona=await resolvePersona(url,key,as,signal);
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { randomBytes, randomUUID, timingSafeEqual } from 'node:crypto';
|
|
2
|
+
import { readdir } from 'node:fs/promises';
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
import { devGate, DEV_KEY_PATH } from '../modules/operator-auth/dev-gate.mjs';
|
|
5
|
+
import { OWNER_SIGNIN_SECONDS, OWNER_SIGNIN_PATH, ownerSigninDigest } from '../modules/operator-auth/owner-signin-grant.mjs';
|
|
6
|
+
import { loopback } from './parse.mjs';
|
|
7
|
+
import { openUrl } from './dev-identity.mjs';
|
|
8
|
+
import { shared } from './shared.mjs';
|
|
9
|
+
|
|
10
|
+
// The dev fragment exchange, with a run-owned, expiring, single-use key. Only
|
|
11
|
+
// an independent native grant digest enters the local ledger, on redemption.
|
|
12
|
+
// The public key cannot redeem that grant outside this proxy's lifetime. Neither
|
|
13
|
+
// credential is saved; the native grant supplies normal owner fencing.
|
|
14
|
+
export function nativeOwnerEntry({ origin, state, store, demo, devKey, clock = Date.now }) {
|
|
15
|
+
if (!loopback(new URL(origin).hostname)) return null;
|
|
16
|
+
let entry, grant;
|
|
17
|
+
const same = (a, b) => { const left = Buffer.from(a), right = Buffer.from(b); return left.length === right.length && timingSafeEqual(left, right); };
|
|
18
|
+
function issue() {
|
|
19
|
+
const key = randomBytes(32).toString('base64url');
|
|
20
|
+
store.addSecrets([key]);
|
|
21
|
+
entry = { key, expires: clock() + OWNER_SIGNIN_SECONDS * 1000, used: false, gate: devGate({ key, origin, local: true }) };
|
|
22
|
+
return openUrl(origin, key, { path: DEV_KEY_PATH, next: '/' });
|
|
23
|
+
}
|
|
24
|
+
async function database() {
|
|
25
|
+
const { DatabaseSync } = await import('node:sqlite');
|
|
26
|
+
const directory = join(state, 'v3/d1/miniflare-D1DatabaseObject'), found = [];
|
|
27
|
+
for (const file of await readdir(directory)) {
|
|
28
|
+
if (!file.endsWith('.sqlite')) continue;
|
|
29
|
+
const path = join(directory, file), db = new DatabaseSync(path, { readOnly: true });
|
|
30
|
+
try { if (db.prepare("SELECT 1 FROM sqlite_master WHERE name='oa_owner_signins' AND type='table'").get()) found.push(path); }
|
|
31
|
+
finally { db.close(); }
|
|
32
|
+
}
|
|
33
|
+
if (found.length !== 1) throw Error('Local native owner entry requires exactly one owner sign-in ledger.');
|
|
34
|
+
return new DatabaseSync(found[0]);
|
|
35
|
+
}
|
|
36
|
+
async function clear() {
|
|
37
|
+
if (!grant) return;
|
|
38
|
+
const db = await database();
|
|
39
|
+
try { db.prepare('DELETE FROM oa_owner_signins WHERE id=?').run(grant); grant = undefined; }
|
|
40
|
+
finally { db.close(); }
|
|
41
|
+
}
|
|
42
|
+
return {
|
|
43
|
+
issue,
|
|
44
|
+
async close() { entry = undefined; await clear(); },
|
|
45
|
+
async handle(req, res) {
|
|
46
|
+
if (req.url !== DEV_KEY_PATH) return false;
|
|
47
|
+
const reply = async response => {
|
|
48
|
+
res.writeHead(response.status, Object.fromEntries(response.headers));
|
|
49
|
+
res.end(Buffer.from(await response.arrayBuffer()));
|
|
50
|
+
return true;
|
|
51
|
+
};
|
|
52
|
+
const denied = () => new Response('This owner link is unavailable. Run the command again for a fresh link.', { status: 403, headers: { 'cache-control': 'no-store', 'content-type': 'text/plain; charset=utf-8', 'referrer-policy': 'no-referrer' } });
|
|
53
|
+
if (req.headers.host !== new URL(origin).host || req.headers['sec-fetch-site'] === 'cross-site' || req.headers.origin && req.headers.origin !== origin) return reply(denied());
|
|
54
|
+
if (req.method === 'GET' || req.method === 'HEAD') {
|
|
55
|
+
if (demo) return false;
|
|
56
|
+
return reply(await entry.gate.exchange(new Request(origin + DEV_KEY_PATH, { method: req.method })));
|
|
57
|
+
}
|
|
58
|
+
if (req.method !== 'POST') return demo ? false : reply(denied());
|
|
59
|
+
let body = '';
|
|
60
|
+
for await (const bytes of req) { body += bytes; if (body.length > 1024) return reply(denied()); }
|
|
61
|
+
let key; try { key = JSON.parse(body).key; } catch {}
|
|
62
|
+
// Preserve the demo persona through the same dev gate as its Worker.
|
|
63
|
+
if (demo && entry && typeof key === 'string' && !same(key, entry.key)) return reply(await devGate({ key: devKey, origin, local: true }).exchange(new Request(origin + DEV_KEY_PATH, { method: 'POST', headers: { 'content-type': 'application/json' }, body })));
|
|
64
|
+
if (!entry || typeof key !== 'string' || !same(key, entry.key) || entry.used || clock() >= entry.expires || req.headers.origin !== origin) return reply(denied());
|
|
65
|
+
entry.used = true;
|
|
66
|
+
const exchange = await entry.gate.exchange(new Request(origin + DEV_KEY_PATH, { method: 'POST', headers: { 'content-type': 'application/json' }, body }));
|
|
67
|
+
if (!exchange.ok) return reply(denied());
|
|
68
|
+
await clear();
|
|
69
|
+
const id = randomUUID(), nativeToken = randomBytes(32).toString('base64url');
|
|
70
|
+
store.addSecrets([nativeToken]);
|
|
71
|
+
const db = await database(), now = clock();
|
|
72
|
+
try {
|
|
73
|
+
db.prepare(`INSERT INTO oa_owner_signins(id,token_hash,operator_id,operator_version,created_at,expires_at)
|
|
74
|
+
SELECT ?,?,o.id,o.version,?,? FROM oa_operators o LEFT JOIN oa_bootstrap b ON b.claim_id=o.id
|
|
75
|
+
WHERE o.role='owner' AND o.status='active' ORDER BY b.claim_id IS NULL,o.created_at,o.id LIMIT 1`).run(id, await ownerSigninDigest(nativeToken), now, entry.expires);
|
|
76
|
+
grant = id;
|
|
77
|
+
} finally { db.close(); }
|
|
78
|
+
const { appFetch } = await shared('app-fetch.mjs');
|
|
79
|
+
const response = await appFetch(origin + OWNER_SIGNIN_PATH, { method: 'POST', redirect: 'manual', headers: { Origin: origin, 'content-type': 'application/json' }, body: JSON.stringify({ token: nativeToken }), signal: AbortSignal.timeout(10000) });
|
|
80
|
+
if (response.status !== 303) { await response.body?.cancel(); return reply(denied()); }
|
|
81
|
+
const cookies = response.headers.getSetCookie(); await response.body?.cancel();
|
|
82
|
+
res.writeHead(204, { 'cache-control': 'no-store', 'referrer-policy': 'no-referrer', 'set-cookie': cookies }); res.end();
|
|
83
|
+
return true;
|
|
84
|
+
},
|
|
85
|
+
};
|
|
86
|
+
}
|
package/cli/output.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { humanError } from './human-error.mjs';
|
|
1
2
|
import { handleBrokenPipes } from './stdio.mjs';
|
|
2
3
|
import { exportSummary } from './export-summary.mjs';
|
|
3
4
|
import { importSafetySummary } from './import-summary.mjs';
|
|
@@ -24,8 +25,8 @@ export function output(options) {
|
|
|
24
25
|
else if (!['describe', 'check', 'dev', 'preview', 'setup'].includes(options.verb) || !ok) this.human(`${options.verb}: ${ok ? 'complete' : 'failed'} (exit ${exitCode})`);
|
|
25
26
|
},
|
|
26
27
|
error(error) {
|
|
27
|
-
if (structuredResult) this.event('error', { code: error.code, message: error.message, exitCode: error.exitCode, ...(error.availableDeployments ? { environment: error.environment, availableDeployments: error.availableDeployments } : {}), ...(error.step ? { step: error.step } : {}) });
|
|
28
|
-
else write(2, error
|
|
28
|
+
if (structuredResult) this.event('error', { code: error.code, message: error.message, exitCode: error.exitCode, ...(!options.json && error.humanMessage ? { humanMessage: error.humanMessage } : {}), ...(error.availableDeployments ? { environment: error.environment, availableDeployments: error.availableDeployments } : {}), ...(error.siteDeploy ? {siteDeploy:error.siteDeploy} : {}), ...(error.step ? { step: error.step } : {}), ...(error.d1Import ? {d1Import:error.d1Import} : {}) });
|
|
29
|
+
else write(2, humanError(error) + '\n');
|
|
29
30
|
},
|
|
30
31
|
};
|
|
31
32
|
}
|
package/cli/parse.mjs
CHANGED
|
@@ -3,7 +3,7 @@ import { authoringVerbs, commonFlags, serverDefaults, signinVerb, verbs } from '
|
|
|
3
3
|
import { invalid, refuse } from './errors.mjs';
|
|
4
4
|
import { isLoopbackHost } from '../modules/operator-auth/loopback.mjs';
|
|
5
5
|
import { normalizeEmail } from '../modules/operator-auth/policy.mjs';
|
|
6
|
-
const booleans = new Set(['--help', '--json', '--non-interactive', '--yes', '--dry-run', '--stop', '--detach', '--foreground', '--no-queue', '--login', '--legacy-v1', '--acknowledge-unverified-metadata', '--door', '--direct', '--site', '--remove', '--demo', '--offline']);
|
|
6
|
+
const booleans = new Set(['--help', '--json', '--non-interactive', '--yes', '--dry-run', '--stop', '--detach', '--foreground', '--no-queue', '--login', '--legacy-v1', '--acknowledge-unverified-metadata', '--acknowledge-unverified-schema-objects', '--door', '--direct', '--site', '--remove', '--demo', '--offline']);
|
|
7
7
|
export const mailbox = value => typeof value === 'string' && value.length <= 254 && /^[a-zA-Z0-9.!+_%\-]+@[a-zA-Z0-9\-]+(?:\.[a-zA-Z0-9\-]+)+$/.test(value);
|
|
8
8
|
export const validOwnerName = value => typeof value === 'string' && Boolean(value.trim()) && value.length <= 200 && !/[\p{Cc}\p{Cf}]/u.test(value);
|
|
9
9
|
// A loopback host: the shared predicate (including `*.localhost` door names),
|
|
@@ -40,7 +40,7 @@ export function parse(argv, cwd = process.cwd(), { independent = false, deferTai
|
|
|
40
40
|
throw invalid(`Unsupported flag ${/^--[a-zA-Z-]{1,40}$/.test(flag)?flag:'(invalid)'} for ${verb}.${suggestion?` Did you mean ${suggestion}?`:''} Run rer ${verb} --help.`);
|
|
41
41
|
}
|
|
42
42
|
// Several secrets change in one deploy: --set-secret A --set-secret B is --set-secret A,B.
|
|
43
|
-
const listed = ['--set-secret', '--unset-secret'].includes(flag);
|
|
43
|
+
const listed = ['--set-secret', '--unset-secret', '--edition-migration'].includes(flag);
|
|
44
44
|
if (options.supplied.has(flag) && !listed) throw invalid(`Repeated flag ${flag} for ${verb}. Run rer ${verb} --help.`);
|
|
45
45
|
options.supplied.add(flag);
|
|
46
46
|
const key = flag.slice(2).replace(/-([a-z])/g, (_, c) => c.toUpperCase());
|
|
@@ -76,7 +76,7 @@ export function parse(argv, cwd = process.cwd(), { independent = false, deferTai
|
|
|
76
76
|
options.idleTimeout=Number(value);
|
|
77
77
|
}
|
|
78
78
|
if (options.port !== undefined) {
|
|
79
|
-
if (!/^\d+$/.test(options.port) || Number(options.port) < 1 || Number(options.port) > 65535) throw invalid('Port must be a decimal integer from 1 to 65535.');
|
|
79
|
+
if (!/^\d+$/.test(options.port) || Number(options.port) < 1 || Number(options.port) > 65535) throw Object.assign(invalid('Port must be a decimal integer from 1 to 65535.'), { humanMessage: `Port ${JSON.stringify(options.port)} is invalid. Use a port from 1 to 65535, for example: rer ${verb} --port 4800` });
|
|
80
80
|
options.port = Number(options.port);
|
|
81
81
|
}
|
|
82
82
|
for(const key of ['httpPort','httpsPort'])if(options[key]!==undefined){if(!/^[0-9]+$/.test(options[key])||Number(options[key])<1||Number(options[key])>65535)throw invalid('Ingress port must be an integer from 1 to 65535.');options[key]=Number(options[key]);}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { DatabaseSync } from 'node:sqlite';
|
|
2
|
+
import { createHash, createHmac } from 'node:crypto';
|
|
3
|
+
import { copyFile, lstat, mkdtemp, readFile, rm } from 'node:fs/promises';
|
|
4
|
+
import { join } from 'node:path';
|
|
5
|
+
import { tmpdir } from 'node:os';
|
|
6
|
+
import { parseJsonc } from './jsonc.mjs';
|
|
7
|
+
import { loadPolicy } from './portability-policy.mjs';
|
|
8
|
+
import { appliedMigrations, platformMigrationDeclaration } from './portability-migrations.mjs';
|
|
9
|
+
import { migrationReplay } from '../modules/portability/migration-history.mjs';
|
|
10
|
+
import { splitStatements } from '../modules/portability/sql-text.mjs';
|
|
11
|
+
import { requireEmptyTables } from '../modules/portability/restore-empty.mjs';
|
|
12
|
+
import { insist } from '../modules/portability/storage.mjs';
|
|
13
|
+
import { shared } from './shared.mjs';
|
|
14
|
+
|
|
15
|
+
const status = path => lstat(path).catch(error => { if (error.code === 'ENOENT') return null; throw error; });
|
|
16
|
+
// Miniflare's named D1 identity: the declared binding determines its file.
|
|
17
|
+
function databaseFile(id) {
|
|
18
|
+
const key = createHash('sha256').update('miniflare-D1DatabaseObject').digest();
|
|
19
|
+
const name = createHmac('sha256', key).update(id).digest().subarray(0, 16);
|
|
20
|
+
return Buffer.concat([name, createHmac('sha256', key).update(name).digest().subarray(0, 16)]).toString('hex') + '.sqlite';
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// Called under the runner's stopped-writer custody and operation lock. Even a
|
|
24
|
+
// read-only SQLite connection can checkpoint or alter shared memory: open only
|
|
25
|
+
// a private copy, including existing journal sidecars, before any native proxy.
|
|
26
|
+
export async function emptyNativePreflight({ root, binding, policy, policyModule, platformMigrations }) {
|
|
27
|
+
const { selectLocalState } = await shared('local/state.mjs');
|
|
28
|
+
const state = await selectLocalState(root);
|
|
29
|
+
const config = parseJsonc(await readFile(join(root, 'wrangler.jsonc'), 'utf8'));
|
|
30
|
+
const bindings = config.d1_databases?.filter(entry => entry.binding === binding) ?? [];
|
|
31
|
+
insist(bindings.length === 1, 'migration_ledger:binding', 409);
|
|
32
|
+
const id = bindings[0].preview_database_id ?? bindings[0].database_id;
|
|
33
|
+
insist(typeof id === 'string' && id.length > 0, 'migration_ledger:binding', 409);
|
|
34
|
+
let parent = state;
|
|
35
|
+
for (const part of ['v3', 'd1', 'miniflare-D1DatabaseObject']) {
|
|
36
|
+
parent = join(parent, part); const info = await status(parent);
|
|
37
|
+
if (!info) return;
|
|
38
|
+
insist(info.isDirectory() && !info.isSymbolicLink(), 'restore_state_unsafe', 409);
|
|
39
|
+
}
|
|
40
|
+
const path = join(parent, databaseFile(id)), paths = [path, path + '-wal', path + '-journal'];
|
|
41
|
+
const before = await Promise.all(paths.map(status));
|
|
42
|
+
if (!before[0]) return;
|
|
43
|
+
insist(before.every(info => !info || info.isFile() && !info.isSymbolicLink() && info.nlink === 1 && info.uid === process.getuid()), 'restore_state_unsafe', 409);
|
|
44
|
+
const directory = await mkdtemp(join(tmpdir(), 'rer-empty-preflight-')); let snapshot;
|
|
45
|
+
try {
|
|
46
|
+
for (let i = 0; i < paths.length; i++) if (before[i]) await copyFile(paths[i], join(directory, 'database.sqlite' + paths[i].slice(path.length)));
|
|
47
|
+
const after = await Promise.all(paths.map(status));
|
|
48
|
+
insist(before.every((info, i) => info ? after[i] && ['ino', 'size', 'mtimeMs', 'ctimeMs'].every(key => info[key] === after[i][key]) : !after[i]), 'restore_state_changed', 409);
|
|
49
|
+
snapshot = new DatabaseSync(join(directory, 'database.sqlite'), { readOnly: true });
|
|
50
|
+
const db = { prepare(sql) { const query = snapshot.prepare(sql); let values = []; return {
|
|
51
|
+
bind(...args) { values = args; return this; },
|
|
52
|
+
async all() { return { results: query.all(...values) }; },
|
|
53
|
+
async first() { return query.get(...values) ?? null; },
|
|
54
|
+
}; } };
|
|
55
|
+
const rules = await loadPolicy(root, policy, policyModule), declaration = platformMigrationDeclaration(platformMigrations);
|
|
56
|
+
const migrations = async () => migrationReplay(await appliedMigrations(root, db, binding, declaration, splitStatements), rules, declaration);
|
|
57
|
+
await requireEmptyTables({ db, policy: rules, migrations });
|
|
58
|
+
} finally { try { snapshot?.close(); } finally { await rm(directory, { recursive: true, force: true }); } }
|
|
59
|
+
}
|
|
@@ -18,7 +18,7 @@ export function platformMigrationDeclaration(input={}) {
|
|
|
18
18
|
|
|
19
19
|
// Reproduce the runner's stored SQL text, then recover SQLite's statement
|
|
20
20
|
// boundaries (migration-sql.mjs).
|
|
21
|
-
async function
|
|
21
|
+
export async function migrationInventory(root,binding,{prefix},split) {
|
|
22
22
|
const config=parseJsonc(await readFile(join(root,'wrangler.jsonc'),'utf8'));
|
|
23
23
|
const bindings=config.d1_databases?.filter(entry=>entry.binding===binding) ?? [];
|
|
24
24
|
insist(bindings.length===1,'migration_ledger:binding',409);
|
|
@@ -31,7 +31,7 @@ async function inventory(root,binding,{prefix},split) {
|
|
|
31
31
|
|
|
32
32
|
// Preserve the runner's applied order, resolving file identities by hash.
|
|
33
33
|
export async function appliedMigrations(root,db,binding,declaration,split) {
|
|
34
|
-
const ledger=await destinationLedger(db) ?? [],files=await
|
|
34
|
+
const ledger=await destinationLedger(db) ?? [],files=await migrationInventory(root,binding,declaration,split);
|
|
35
35
|
return matchMigrationLedger(ledger,files,declaration).map(name=>files.find(file=>file.name===name));
|
|
36
36
|
}
|
|
37
37
|
|
|
@@ -54,7 +54,7 @@ function constantRefusal(error) {
|
|
|
54
54
|
export async function mapMigrationLedger({root,binding='DB',platformMigrations,entries}) {
|
|
55
55
|
const declaration=platformMigrationDeclaration(platformMigrations);
|
|
56
56
|
insist(Array.isArray(entries) && entries.every(entry=>entry && typeof entry.name==='string' && typeof entry.sha256==='string' && /^[a-f0-9]{64}$/.test(entry.sha256)) && new Set(entries.map(entry=>entry.name)).size===entries.length,'migration_ledger:incompatible',409);
|
|
57
|
-
const files=await
|
|
57
|
+
const files=await migrationInventory(root,binding,declaration);
|
|
58
58
|
try {
|
|
59
59
|
const mapped=entries.map(({name,sha256})=>({name:matchMigrationLedger([{name,sha256}],files,declaration)[0]??name,sha256}));
|
|
60
60
|
insist(new Set(mapped.map(entry=>entry.name)).size===mapped.length,'migration_ledger:ambiguous',409);
|
|
@@ -74,13 +74,15 @@ export async function nativeMigrationPreflight({root,db,binding='DB',platformMig
|
|
|
74
74
|
if(!table)return {nativeApply:true};
|
|
75
75
|
// This runner's history cannot authorize Wrangler to apply the same files.
|
|
76
76
|
insist(table!=='_rer_deploy_migrations','migration_ledger:runner',409);
|
|
77
|
-
const files=await
|
|
77
|
+
const files=await migrationInventory(root,binding,declaration);
|
|
78
|
+
let nativeApply=false;
|
|
78
79
|
try {
|
|
79
80
|
const ledger=await destinationLedger(db),applied=matchMigrationLedger(ledger,files,declaration);
|
|
80
81
|
// Wrangler skips only literal filenames, not transfer aliases or hashes.
|
|
81
82
|
if(table==='d1_migrations')insist(ledger.every(row=>files.some(file=>file.name===row.name)),'migration_ledger:incompatible',409);
|
|
83
|
+
nativeApply=table==='d1_migrations' && files.some(file=>!applied.includes(file.name));
|
|
82
84
|
// The checkout file is named: it is the seed's own, never a ledger value.
|
|
83
85
|
if(table==='rer_migrations')for(const file of files)if(!applied.includes(file.name))throw Object.assign(new PortabilityError('migration_ledger:unapplied',409),{migration:file.name});
|
|
84
86
|
} catch(error) { throw constantRefusal(error); }
|
|
85
|
-
return {nativeApply
|
|
87
|
+
return {nativeApply};
|
|
86
88
|
}
|
|
@@ -44,11 +44,14 @@ export function serializablePolicy(input) {
|
|
|
44
44
|
return result;
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
-
export async function loadPolicy(root, policy, policyModule) {
|
|
47
|
+
export async function loadPolicy(root, policy, policyModule, bindings) {
|
|
48
48
|
if (policyModule === undefined) return serializablePolicy(policy);
|
|
49
49
|
if (policy !== undefined) throw new PortabilityError('ambiguous_policy', 409);
|
|
50
50
|
try {
|
|
51
|
-
const
|
|
51
|
+
const module = await import(await policyModuleURL(root, policyModule));
|
|
52
|
+
validatePolicy(module.default);
|
|
53
|
+
if (module.createPolicy !== undefined && typeof module.createPolicy !== 'function') throw new Error();
|
|
54
|
+
const input = bindings && module.createPolicy ? await module.createPolicy(bindings) : module.default;
|
|
52
55
|
validatePolicy(input);
|
|
53
56
|
return input;
|
|
54
57
|
} catch { throw new PortabilityError('invalid_policy_module', 409); }
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
+
import { installD1Preflight } from '../modules/container/adapters/d1-workerd-setup.mjs';
|
|
1
2
|
import { portabilityPlan, ensurePortabilitySchema } from '../modules/container/portability-schema.mjs';
|
|
2
3
|
import { exportArchive, importArchive, fileRecords } from '../modules/portability/files.mjs';
|
|
3
4
|
import { readLegacyArchive } from '../modules/portability/format.mjs';
|
|
4
5
|
import { recoverLegacyArchive } from '../modules/portability/legacy-files.mjs';
|
|
5
|
-
import {
|
|
6
|
+
import { requireEmptyTables } from '../modules/portability/restore-empty.mjs';
|
|
7
|
+
import { legacyTargetState, requireLegacyEmpty, requireProductEmpty } from '../modules/portability/legacy-safety.mjs';
|
|
6
8
|
import { migrationReplay } from '../modules/portability/migration-history.mjs';
|
|
7
9
|
import { join } from 'node:path';
|
|
8
10
|
import { mkdir, readFile, rm, stat, writeFile } from 'node:fs/promises';
|
|
@@ -25,7 +27,7 @@ async function dataConfiguration(root) {
|
|
|
25
27
|
return path;
|
|
26
28
|
}
|
|
27
29
|
|
|
28
|
-
async function run(direction, { root, path, journal, binding, buckets, policy, policyModule, transient, legacyRecovery, platformMigrations }) {
|
|
30
|
+
async function run(direction, { root, path, journal, binding, buckets, policy, policyModule, transient, legacyRecovery, acknowledgeUnverifiedSchemaObjects, platformMigrations }) {
|
|
29
31
|
// Lines for the person go to the CLI over IPC, which prints them as the command's progress.
|
|
30
32
|
const progress = transferProgress(line => process.send({ progress: line }));
|
|
31
33
|
if (!legacyRecovery && ['export', 'import'].includes(direction)) progress({ phase: 'start', direction, bytes: direction === 'export' ? await stateBytes(join(root, '.wrangler/state')) : (await stat(path)).size });
|
|
@@ -35,10 +37,13 @@ async function run(direction, { root, path, journal, binding, buckets, policy, p
|
|
|
35
37
|
for await (const record of fileRecords(path,legacyRecovery?readLegacyArchive:readArchive)) {}
|
|
36
38
|
if(journal)for await(const record of fileRecords(journal)) {}
|
|
37
39
|
}
|
|
38
|
-
|
|
40
|
+
const inputPolicy = policy;
|
|
41
|
+
policy = await loadPolicy(root, inputPolicy, policyModule);
|
|
39
42
|
const declaration=platformMigrationDeclaration(platformMigrations);
|
|
40
43
|
if (direction === 'policy-preflight') return { checkedPolicy: true };
|
|
41
|
-
const
|
|
44
|
+
const require = createRequire(join(root, 'package.json'));
|
|
45
|
+
const { getPlatformProxy, unstable_splitSqlQuery } = require('wrangler');
|
|
46
|
+
installD1Preflight(createRequire(require.resolve('wrangler/package.json'))('miniflare').D1_PLUGIN);
|
|
42
47
|
|
|
43
48
|
// Unlike Wrangler's --persist-to base, the API takes the versioned directory.
|
|
44
49
|
const configPath = await dataConfiguration(root);
|
|
@@ -47,19 +52,23 @@ async function run(direction, { root, path, journal, binding, buckets, policy, p
|
|
|
47
52
|
proxy = await getPlatformProxy({ configPath, persist: { path: join(root, '.wrangler/state/v3') }, remoteBindings: false });
|
|
48
53
|
if(direction==='migration-preflight')return await nativeMigrationPreflight({root,db:proxy.env[binding],binding,platformMigrations});
|
|
49
54
|
const migrations=async()=>migrationReplay(await appliedMigrations(root,proxy.env[binding],binding,declaration,unstable_splitSqlQuery),policy,declaration);
|
|
50
|
-
const
|
|
55
|
+
const boundBuckets = Object.fromEntries(Object.entries(buckets).map(([name, binding]) => [name, proxy.env[binding]]));
|
|
56
|
+
policy = await loadPolicy(root, inputPolicy, policyModule, { db: proxy.env[binding], buckets: boundBuckets });
|
|
57
|
+
const options={ db: proxy.env[binding], buckets: boundBuckets, policy, migrations };
|
|
58
|
+
if(direction==='schema-recovery-preflight') { await requireProductEmpty(options);return {checkedEmpty:true}; }
|
|
51
59
|
if(direction==='legacy-preflight') {
|
|
52
60
|
await requireLegacyEmpty(options,await legacyTargetState(options.db,options.migrations));
|
|
53
61
|
return {checkedEmpty:true};
|
|
54
62
|
}
|
|
55
63
|
await ensurePortabilitySchema(proxy.env[binding], await portabilityPlan(unstable_splitSqlQuery));
|
|
56
64
|
if(legacyRecovery)return await recoverLegacyArchive(options,path,legacyRecovery.output,transient,legacyRecovery.acknowledged);
|
|
65
|
+
if (direction === 'import') await requireEmptyTables(options);
|
|
57
66
|
const service = await createPortability(options);
|
|
58
67
|
// This checkout's operation lock means no other import can be running. Abort
|
|
59
68
|
// the recorded abandoned job, dropping only its exact staging copies and
|
|
60
69
|
// sidecars before the replacement import creates its own scratch tables.
|
|
61
70
|
if (direction === 'import' && await service.imports.abortAbandoned()) process.send({ progress: 'Cleaned up an unfinished earlier import: a restore that stopped part-way left its staged data here. Its staging is removed and this import starts from the beginning.' });
|
|
62
|
-
return await (direction === 'export' ? exportArchive(service,path,transient,progress) : importArchive(service,path,transient,journal,progress));
|
|
71
|
+
return await (direction === 'export' ? exportArchive(service,path,transient,progress) : importArchive(service,path,transient,journal,progress,{acknowledgeUnverifiedSchemaObjects}));
|
|
63
72
|
} finally { await proxy?.dispose(); await rm(configPath, { force: true }); }
|
|
64
73
|
}
|
|
65
74
|
|
package/cli/portability.mjs
CHANGED
|
@@ -7,23 +7,30 @@ import { fileRecords } from '../modules/portability/files.mjs';
|
|
|
7
7
|
import { RerError, refuse } from './errors.mjs';
|
|
8
8
|
import { policyModuleURL, serializablePolicy } from './portability-policy.mjs';
|
|
9
9
|
import { shared } from './shared.mjs';
|
|
10
|
+
import { emptyNativePreflight } from './portability-empty.mjs';
|
|
11
|
+
import { withManagedDataImport } from './managed-data.mjs';
|
|
10
12
|
import { ledgerRefusal } from './ledger-refusal.mjs';
|
|
11
13
|
|
|
14
|
+
export { withManagedDataImport };
|
|
15
|
+
|
|
12
16
|
const reExport = 'Re-export from the original installation with rer export --output exports/recovered.rer (add --target remote for a hosted installation), then retry rer import --input exports/recovered.rer --yes. Keep the original archive until recovery succeeds.';
|
|
13
17
|
|
|
14
18
|
// Seeds declare their real bindings and data policy. The shared module owns the
|
|
15
19
|
// archive format and atomic restore; the shared runner owns its native children.
|
|
16
|
-
export function localPortability({ database, binding = 'DB', buckets = {}, policy, policyModule, transient = [], platformMigrations }) {
|
|
17
|
-
async function run({ root, path, journal, store, signal, operationToken, platform, legacyRecovery }, direction) {
|
|
20
|
+
export function localPortability({ database, binding = 'DB', buckets = {}, policy, policyModule, transient = [], platformMigrations, managedData = false }) {
|
|
21
|
+
async function run({ root, path, journal, store, signal, operationToken, platform, legacyRecovery, acknowledgeUnverifiedSchemaObjects }, direction) {
|
|
18
22
|
if (direction === 'export') {
|
|
19
23
|
if (await lstat(path).catch(error => { if (error.code === 'ENOENT') return null; throw error; })) throw refuse('Export requires a new archive path.');
|
|
20
24
|
}
|
|
21
25
|
if(legacyRecovery && (!legacyRecovery.acknowledged || await lstat(legacyRecovery.output).catch(error=>{if(error.code==='ENOENT')return null;throw error;})))throw refuse('Legacy recovery requires acknowledgement and a new output archive path.');
|
|
26
|
+
let unverifiedSchemaRecovery=false;
|
|
22
27
|
if (direction === 'import') {
|
|
23
28
|
// Refuse damaged or unverifiable archives before migrations open the
|
|
24
29
|
// destination database. Worker and finalization verify again before publish.
|
|
25
30
|
try {
|
|
26
|
-
for await (const record of fileRecords(path,legacyRecovery?readLegacyArchive:readArchive)) {
|
|
31
|
+
for await (const record of fileRecords(path,legacyRecovery?readLegacyArchive:readArchive)) {
|
|
32
|
+
if(record.kind==='manifest')unverifiedSchemaRecovery=!legacyRecovery && acknowledgeUnverifiedSchemaObjects===true && record.schemaObjects===undefined;
|
|
33
|
+
}
|
|
27
34
|
if(journal)for await(const record of fileRecords(journal)) {}
|
|
28
35
|
}
|
|
29
36
|
catch (error) {
|
|
@@ -48,14 +55,23 @@ export function localPortability({ database, binding = 'DB', buckets = {}, polic
|
|
|
48
55
|
if (!(error instanceof PortabilityError)) throw error;
|
|
49
56
|
throw refuse(`Local portability policy refused (${error.code}). Executable policies require a seed-owned policyModule with a valid default policy export; policyModule requires native local transport.`);
|
|
50
57
|
}
|
|
51
|
-
if(platform==='container') return (await import('./container-transfer.mjs')).containerTransfer({root,path,journal,store,signal,direction,binding,buckets,policy:declaration.policy,transient});
|
|
52
|
-
const input={ root, path, journal, binding, buckets, ...declaration, transient, legacyRecovery, platformMigrations };
|
|
58
|
+
if(platform==='container') return (await import('./container-transfer.mjs')).containerTransfer({root,path,journal,store,signal,direction,binding,buckets,policy:declaration.policy,transient,acknowledgeUnverifiedSchemaObjects});
|
|
59
|
+
const input={ root, path, journal, binding, buckets, ...declaration, transient, legacyRecovery, acknowledgeUnverifiedSchemaObjects, platformMigrations };
|
|
53
60
|
// Check the executable policy before migrations; the transfer worker imports
|
|
54
61
|
// it again in its own process so module closures are retained during restore.
|
|
55
62
|
if (policyModule !== undefined) await nativeWorker(store,'policy-preflight',input,signal);
|
|
56
63
|
// Do not apply pending product migrations to a populated recovery target.
|
|
57
64
|
// Check real existing bindings first; finalize repeats this under the lock.
|
|
58
65
|
if(legacyRecovery)await nativeWorker(store,'legacy-preflight',input,signal);
|
|
66
|
+
if(direction==='import' && !legacyRecovery) {
|
|
67
|
+
try { await emptyNativePreflight(input); }
|
|
68
|
+
catch(error) {
|
|
69
|
+
if(error instanceof PortabilityError && error.code.startsWith('target_not_empty:'))throw new RerError('restore_refused',occupiedRefusal(input,'target_not_empty',error.code.slice(error.code.indexOf(':')+1)),4);
|
|
70
|
+
if(error instanceof PortabilityError)throw refuse(`Local restore refused (${error.code}).`);
|
|
71
|
+
throw error;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
if(unverifiedSchemaRecovery)await nativeWorker(store,'schema-recovery-preflight',input,signal);
|
|
59
75
|
const {nativeApply}=await nativeWorker(store,'migration-preflight',input,signal);
|
|
60
76
|
// Local migrations need no provider account: wrangler runs without credentials.
|
|
61
77
|
// Its info lines (the local location and "Use --remote if you want to access
|
|
@@ -68,13 +84,15 @@ export function localPortability({ database, binding = 'DB', buckets = {}, polic
|
|
|
68
84
|
if(legacyRecovery)receipt.output=relative(root,legacyRecovery.output);
|
|
69
85
|
return { target: 'local', [direction === 'export' ? 'output' : 'input']: relative(root, path), ...receipt };
|
|
70
86
|
}
|
|
71
|
-
|
|
87
|
+
const restore = context => run(context, 'import');
|
|
88
|
+
const intake = context => withManagedDataImport(context, { binding, buckets, policy, policyModule, platformMigrations, transient }, restore);
|
|
89
|
+
return { legacyRecovery:true, export: context => run(context, 'export'), import: managedData ? intake : restore, ...(managedData ? { managedDataImport: intake } : {}) };
|
|
72
90
|
}
|
|
73
91
|
|
|
74
92
|
async function nativeWorker(store,direction,input,signal) {
|
|
75
93
|
// The notice filter loads before the worker links its static node:sqlite import.
|
|
76
94
|
const worker = fileURLToPath(new URL('./portability-worker.mjs', import.meta.url)), notice = new URL('./sqlite-notice.mjs', import.meta.url).href;
|
|
77
|
-
const child = store.spawn(`${direction === 'migration-preflight' ? 'Checking migration history for' : direction === 'policy-preflight' ? 'Checking archive policy' :
|
|
95
|
+
const child = store.spawn(`${direction === 'migration-preflight' ? 'Checking migration history for' : direction === 'policy-preflight' ? 'Checking archive policy' : ['legacy-preflight','schema-recovery-preflight'].includes(direction) ? 'Checking empty recovery destination' : direction === 'export' ? 'Exporting' : 'Restoring'} local installation data`, process.execPath,
|
|
78
96
|
['--import', notice, worker, direction, JSON.stringify(input)], { cwd: input.root, signal, env: { ...process.env, WRANGLER_SEND_METRICS: 'false' }, stdio: ['ignore', 'pipe', 'pipe', 'ipc'] });
|
|
79
97
|
let receipt;
|
|
80
98
|
// Progress lines come first, as {progress}; the last message is the receipt.
|
|
@@ -91,8 +109,12 @@ async function nativeWorker(store,direction,input,signal) {
|
|
|
91
109
|
: receipt.safety ? `Restore refused (${receipt.reason}): safety normalization for ${receipt.safety} violates the declared import policy.`
|
|
92
110
|
: receipt.reason?.startsWith('migration_ledger:') ? ledgerRefusal(receipt)
|
|
93
111
|
: receipt.migration ? `Restore refused (schema_mismatch:migration_data): migration ${receipt.migration} changed data after this archive was made, so its rows would skip that change. Restore an archive made after it.`
|
|
94
|
-
: receipt.occupied ?
|
|
112
|
+
: receipt.occupied ? occupiedRefusal(input,receipt.reason,receipt.occupied)
|
|
95
113
|
: `The portability module refused or failed the archive operation (${receipt.reason ?? 'incomplete'}${receipt.native ? `: ${receipt.native.class}${receipt.native.code && receipt.native.code !== receipt.reason ? `, code ${receipt.native.code}` : ''}` : ''}).${receipt.native && receipt.exitCode === 1 ? ' Run the same command again; it starts over.' : ''}`, receipt.exitCode ?? 1);
|
|
96
114
|
delete receipt.ok;
|
|
97
115
|
return receipt;
|
|
98
116
|
}
|
|
117
|
+
|
|
118
|
+
function occupiedRefusal(input,reason,occupied) {
|
|
119
|
+
return `Restore refused (${reason}): ${reason === 'bucket_not_empty' ? `storage bucket ${occupied} in this installation already holds files` : `table ${occupied} in this installation already holds rows its migrations did not insert`}, and a restore only goes into an empty installation. To replace this installation's data with the archive, keep a copy with rer export --output exports/before-restore.rer, then run rer reset --yes and rer import --input ${relative(input.root, input.path)} --yes again.`;
|
|
120
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// Keep the credential link only where the caller already permits openUrl.
|
|
2
|
+
export function readySummary({ url, openUrl, signedInAs, siteUrl }) {
|
|
3
|
+
const lines = [openUrl
|
|
4
|
+
? `Open your app${signedInAs ? ', already signed in' : ''} on this computer: ${openUrl}`
|
|
5
|
+
: `Open your app on this computer: ${url}`];
|
|
6
|
+
if (siteUrl) lines.push(`Help and public site preview (secondary): ${siteUrl}`);
|
|
7
|
+
if (openUrl) lines.push(`App address (without sign-in): ${url}`, 'Keep the sign-in link private.');
|
|
8
|
+
return lines;
|
|
9
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
// Archive payloads measured by install.sh; Git and package managers do not
|
|
2
|
+
// expose wire-byte totals here. Disk blocks are measured separately, never
|
|
3
|
+
// substituted for download sizes. No checkout content or credentials are read.
|
|
4
|
+
import { execFile } from 'node:child_process';
|
|
5
|
+
import { join } from 'node:path';
|
|
6
|
+
import { fileURLToPath } from 'node:url';
|
|
7
|
+
import { promisify } from 'node:util';
|
|
8
|
+
import { coldRunBudget } from '../foundation/runtime/run-data.mjs';
|
|
9
|
+
const ownRoot = fileURLToPath(new URL('../', import.meta.url));
|
|
10
|
+
|
|
11
|
+
const execute = promisify(execFile);
|
|
12
|
+
export function showBudget(args) {
|
|
13
|
+
if (!args.includes('--json') && !process.env.RER_BUDGET_SHOWN) process.stderr.write(coldRunBudget + '\n');
|
|
14
|
+
process.env.RER_BUDGET_SHOWN = '1';
|
|
15
|
+
}
|
|
16
|
+
const payload = value => /^\d+$/.test(value ?? '') ? `${value} bytes` : 'not measured';
|
|
17
|
+
async function disk(path) {
|
|
18
|
+
try {
|
|
19
|
+
const { stdout } = await execute('du', ['-sk', path], { timeout: 10000 });
|
|
20
|
+
const blocks = Number(stdout.match(/^\d+/)?.[0]);
|
|
21
|
+
if (Number.isSafeInteger(blocks)) return `${blocks * 1024} bytes`;
|
|
22
|
+
} catch { /* An unavailable measurement is stated, never estimated. */ }
|
|
23
|
+
return 'not measured';
|
|
24
|
+
}
|
|
25
|
+
export async function launchSummary(root) {
|
|
26
|
+
const components = [['rer', ownRoot], ['clone (Git objects)', root && join(root, '.git')], ['dependencies', root && join(root, 'node_modules')]];
|
|
27
|
+
const sizes = await Promise.all(components.map(async ([name, path]) => `${name}: ${path ? await disk(path) : 'not measured'}`));
|
|
28
|
+
const lines = [
|
|
29
|
+
`Downloads this run (archive payloads): Node installer: ${payload(process.env.RER_TRANSFER_NODE_BYTES)}; rer installer: ${payload(process.env.RER_TRANSFER_RER_BYTES)}.`,
|
|
30
|
+
'Other downloads: project Node, clone and dependencies: not measured. Package-manager caches and metadata are not included in archive counts.',
|
|
31
|
+
`Disk use now (allocated space, not download sizes): ${sizes.join('; ')}.`,
|
|
32
|
+
];
|
|
33
|
+
if (process.env.RER_TRANSFER_NODE_DISK) lines.push(`Installer Node disk use: ${payload(process.env.RER_TRANSFER_NODE_DISK)}.`);
|
|
34
|
+
if (process.env.RER_LAUNCH_PATH_STEP) lines.push(process.env.RER_LAUNCH_PATH_STEP);
|
|
35
|
+
|
|
36
|
+
return lines;
|
|
37
|
+
}
|
|
@@ -9,11 +9,11 @@ import { trafficProxy } from './server-proxy.mjs';
|
|
|
9
9
|
// for application URLs, cookies and sign-in links.
|
|
10
10
|
// In door mode (`door`) the listener is 127.0.0.1 on a port the OS assigns,
|
|
11
11
|
// and only the machine's front door reaches it.
|
|
12
|
-
export async function runtimeFrontDoor({ host, port, activity, door, devKey, origin }) {
|
|
13
|
-
|
|
12
|
+
export async function runtimeFrontDoor({ host, port, activity, door, devKey, origin, ownerEntry }) {
|
|
13
|
+
let runtimePort = await runtimeLoopbackPort(port);
|
|
14
14
|
const observer = activity ?? { begin: () => () => {}, touch: () => {} };
|
|
15
|
-
const proxy = await trafficProxy({ host, port, target: runtimePort, activity: observer, door, devKey, origin });
|
|
16
|
-
return { ...proxy, runtimePort };
|
|
15
|
+
const proxy = await trafficProxy({ host, port, target: runtimePort, activity: observer, door, devKey, origin, ownerEntry });
|
|
16
|
+
return { ...proxy, get runtimePort(){return runtimePort;}, setRuntimePort(port){runtimePort=port;proxy.setTarget(port);} };
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
// The runtime binds this port strictly, seconds after it is chosen. A port the
|