@valbuild/tanstack-build 0.144.0 → 0.144.2
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/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# @valbuild/tanstack-build
|
|
2
2
|
|
|
3
|
+
## 0.144.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#832](https://github.com/valbuild/val/pull/832) [`ab0ea20`](https://github.com/valbuild/val/commit/ab0ea2046e3872c4955f34b363881f76d48d1b1e) Thanks [@freekh](https://github.com/freekh)! - A site served by Val's platform can now be given its content separately from its build. When the platform hands a TanStack app a content version (`VAL_CONTENT`) that differs from what the build bundles, Val renders that content, in the Studio and in draft mode too. It reads it the way it already reads a proposal's saved content.
|
|
8
|
+
|
|
9
|
+
Nothing changes for an app that is not given one, and nothing hands one over yet. This is the reading side of publishing content without rebuilding the site.
|
|
10
|
+
|
|
11
|
+
A version too large for one environment variable can name others under `refs` (`"env://VAL_CONTENT_1"`), each holding one module's Source or one file's text. Only `refs` is resolved, never a string inside your content, and only variables named `VAL_CONTENT_<n>` are read.
|
|
12
|
+
|
|
13
|
+
At a proposal's address, a proposal's saved content is shown over the content version the site serves, so modules the proposal did not change show what the site shows rather than what the build bundles.
|
|
14
|
+
|
|
15
|
+
When Val's platform puts a publish live without building the site, because it changed only content, the Studio shows it being checked and going live instead of "Building".
|
|
16
|
+
|
|
3
17
|
## 0.144.0
|
|
4
18
|
|
|
5
19
|
### Patch Changes
|
|
@@ -3812,14 +3812,23 @@ var LEGACY_CONTROL_HOST = "platform.internal";
|
|
|
3812
3812
|
* rewrites single lines of its `val.server.ts` and never regenerates it.
|
|
3813
3813
|
*/
|
|
3814
3814
|
var PROPOSAL_BLOCK = "/*\n * THE PROPOSAL this isolate serves the address of, when it does: its name and\n * content branch, and the content it has saved (`VAL_OVERLAY`: the save's\n * commit, its Source by module and its `.val.ts` text by path). Val reads\n * that Source instead of the bundle's, commits a save to the proposal, and\n * names the save as its position. valbuild/home `docs/proposals.md`,\n * \"Saving\".\n *\n * Parsed here rather than with `proposalFromEnv` from @valbuild/server,\n * because this file is compiled against whatever @valbuild/tanstack the\n * PROJECT installed, and one from before proposals has no such export -- it\n * also ignores the `proposal` key below, and serves the base build, which\n * is the best an old app can do. A snapshot that does not parse is thrown,\n * not served as the base: a reviewer must not be shown the wrong content as\n * though it were the proposal.\n */\nconst proposal = (() => {\n const name = secret(\"VAL_PROPOSAL\");\n const branch = secret(\"VAL_BRANCH\");\n if (!name || !branch) return undefined;\n const overlay: {\n commit?: string | null;\n modules?: Record<string, unknown>;\n files?: Record<string, string>;\n } = JSON.parse(secret(\"VAL_OVERLAY\") ?? \"{}\");\n return {\n name,\n branch,\n commit: overlay.commit ?? null,\n modules: overlay.modules ?? {},\n files: overlay.files ?? {},\n };\n})();\n";
|
|
3815
|
+
/**
|
|
3816
|
+
* THE CONTENT VERSION the site serves, when it differs from the one this build
|
|
3817
|
+
* bundles (\`VAL_CONTENT\`). See valbuild/home \`docs/hosted-publishing.md\`,
|
|
3818
|
+
* step 2. A constant for the same reason as {@link PROPOSAL_BLOCK}, and it
|
|
3819
|
+
* arrives in files wired before it the same way: {@link rebakeContent}.
|
|
3820
|
+
*/
|
|
3821
|
+
var CONTENT_BLOCK = "/*\n * THE CONTENT VERSION the site serves, when the platform says it differs from\n * the one this build bundles (`VAL_CONTENT`: its id, the publish that made\n * it, and the Source and Val files that differ). Val reads that Source instead\n * of the bundle's and names that publish as its position. valbuild/home\n * `docs/hosted-publishing.md`, step 2.\n *\n * Parsed here, like the proposal above, because this file is compiled against\n * whatever @valbuild/tanstack the PROJECT installed. One from before content\n * versions ignores the `contentVersion` key below and serves the bundle --\n * and never says it applied the version, which is how the platform knows not\n * to serve this build a version it does not bundle. A version that does not\n * parse is thrown, not served as the bundle.\n *\n * A version too large for one variable names others under `refs`\n * (`\"env://VAL_CONTENT_1\"`), each holding one module's Source or one file's\n * text. Only `refs` is resolved, never a string inside Source, and only\n * `VAL_CONTENT_<n>` is read: Source is text editors write, and resolving a\n * reference in there would read `VAL_SECRET` into a page. The same rules as\n * `contentFromEnv` in @valbuild/server.\n */\nconst contentVersion = (() => {\n const handed = secret(\"VAL_CONTENT\");\n if (!handed) return undefined;\n const isRecord = (value: unknown): value is Record<string, unknown> =>\n typeof value === \"object\" && value !== null && !Array.isArray(value);\n const parsed: unknown = JSON.parse(handed);\n if (!isRecord(parsed)) throw new Error(\"Val: VAL_CONTENT is not an object\");\n const id = parsed.id;\n if (typeof id !== \"string\" || id === \"\") {\n throw new Error(\"Val: VAL_CONTENT has no id\");\n }\n const where = \"Val: content version \" + id;\n const nullableString = (key: string): string | null => {\n const value = parsed[key] ?? null;\n if (value !== null && typeof value !== \"string\") {\n throw new Error(where + \": \" + key + \" must be a string or null\");\n }\n return value;\n };\n const record = (value: unknown, name: string): Record<string, unknown> => {\n const found = value ?? {};\n if (!isRecord(found)) throw new Error(where + \": \" + name + \" must be an object\");\n return found;\n };\n const job = nullableString(\"job\");\n const commit = nullableString(\"commit\");\n const modules: Record<string, unknown> = { ...record(parsed.modules, \"modules\") };\n const filesIn = record(parsed.files, \"files\");\n const files: Record<string, string> = {};\n for (const [path, text] of Object.entries(filesIn)) {\n if (typeof text === \"string\") files[path] = text;\n }\n const refs = record(parsed.refs, \"refs\");\n const read = (kind: string, path: string, ref: unknown): string => {\n const at = where + \": refs.\" + kind + \"[\" + path + \"]\";\n if (typeof ref !== \"string\" || !ref.startsWith(\"env://\")) {\n throw new Error(at + \" is \" + String(ref) + \": only env://VAL_CONTENT_<n> is read\");\n }\n const name = ref.slice(\"env://\".length);\n if (!/^VAL_CONTENT_[0-9]+$/.test(name)) {\n throw new Error(at + \" names \" + name + \": only VAL_CONTENT_<n> is read\");\n }\n const value = secret(name);\n if (value === undefined) {\n throw new Error(at + \" names \" + name + \", which is not set\");\n }\n return value;\n };\n for (const [path, ref] of Object.entries(record(refs.modules, \"refs.modules\"))) {\n if (Object.prototype.hasOwnProperty.call(modules, path)) {\n throw new Error(where + \": \" + path + \" is in modules and refs.modules\");\n }\n modules[path] = JSON.parse(read(\"modules\", path, ref));\n }\n for (const [path, ref] of Object.entries(record(refs.files, \"refs.files\"))) {\n if (Object.prototype.hasOwnProperty.call(filesIn, path)) {\n throw new Error(where + \": \" + path + \" is in files and refs.files\");\n }\n files[path] = read(\"files\", path, ref);\n }\n if (job === null && commit === null) {\n throw new Error(where + \" must name a job or a commit, or it would be placed at the build it runs in\");\n }\n return { id, job, commit, modules, files };\n})();\n";
|
|
3815
3822
|
/** Where {@link PROPOSAL_BLOCK} goes: right after this line. */
|
|
3816
3823
|
var SERVED_BUILD_LINE = 'const servedBuild = secret("VAL_BUILD");\n';
|
|
3817
3824
|
/** And the option that hands it to Val, after the build's. */
|
|
3818
3825
|
var PROPOSAL_OPTION = " ...(proposal !== undefined ? { proposal } : {}),\n";
|
|
3826
|
+
/** And the content version's, after the proposal's. */
|
|
3827
|
+
var CONTENT_OPTION = " ...(contentVersion !== undefined ? { contentVersion } : {}),\n";
|
|
3819
3828
|
var PUBLISH_BUILD_OPTION = " ...(servedBuild !== undefined ? { publishBuild: servedBuild } : {}),\n";
|
|
3820
3829
|
var valServerSource = function valServerSource(_ref) {
|
|
3821
3830
|
var git = _ref.git;
|
|
3822
|
-
return "".concat(WIRED_MARKER, "\nimport {\n initValContent,\n initValServer,\n} from \"@valbuild/tanstack/server\";\nimport { config } from \"../../val.config\";\nimport valModules from \"../../val.modules\";\n/*\n * This build's own source, which a publish patches. A project with no\n * repository has no other copy of its `.val.ts` text: content keeps its\n * content as data. Ignored by a @valbuild/tanstack that predates it.\n */\nimport { FILES } from \"platform:project-source\";\n\n/**\n * A secret, as the platform hands it over at RUNTIME.\n *\n * Preferred over `process.env`, which the builder inlines as a literal into\n * this bundle: that puts the value in storage inside the code, copies it into\n * every isolate that loads it, and makes rotating it a republish.\n *\n * Falls back to the build-time value, so an app published before secrets\n * existed keeps working.\n */\nfunction secret(name: string): string | undefined {\n return (globalThis.__PLATFORM_SECRETS ?? {})[name] ?? process.env[name];\n}\n\n/**\n * The commit this build was made from, and the branch it commits to.\n *\n * Baked in rather than handed over at runtime, unlike a secret, because it is\n * not configuration -- it is a property OF THIS BUILD. Every read of a\n * `.val.ts` in http mode fetches that path from the content service at this\n * sha, so a build served with somebody else's commit renders and edits a\n * version of its files it was not compiled from. A secret can be rotated under\n * a running build; this cannot, and publishing again is how it changes.\n *\n * WHAT THIS IS NOT. It is not every read: a committed render reads the source\n * bundled into this build and asks the content service nothing. It is the\n * PUBLISH path -- turning pending patches into new `.val.ts` text means\n * fetching the current text to patch, and that is the read that happens at\n * this sha. The docblock used to say \"every read\", which sent readers looking\n * for a content call on the serving path that is not there.\n *\n * `null` when the source came from no commit -- a record assembled in a tab,\n * a fixture, or ANY build this platform makes, which is the common case rather\n * than the exception. Such a build has no repository to mirror commits into,\n * and does not need one: the content service is the store of record for\n * content and mints its own commit shas. Val is in http mode on credentials\n * alone.\n */\nconst BUILT_FROM = ").concat(git ? JSON.stringify(git) : "null", ";\n\n/**\n * The publish job this build was made for, when a Studio built it in a tab.\n *\n * A tab's build has no commit to bake -- the job's is minted at the seal, after\n * the build -- so this is how it says where it sits in the content service's\n * chain. Without it the service places it at whatever build is live, which is\n * a different build for a request this one is still serving when the pointer\n * moves. Set by the Studio (`rebakeGit`), `null` for any other build.\n */\nconst BUILT_FOR_JOB = null;\n\n/**\n * What puts Val in http mode: its content service owns the content.\n *\n * The same three things any deployed Val app is configured with. Note what is\n * NOT here: no `sourceFiles`, so patches are relayed to the content service\n * instead of being kept by this platform, and the browser uploads an image\n * straight there on a presigned URL instead of streaming it through here.\n *\n * `undefined` when a credential or the commit is missing, and deliberately not\n * a throw at module scope: that would take the isolate down with it, page\n * renders included. Val is left to refuse the request and name what it wanted\n * -- `VAL_ENV=app` is set on this build precisely so that a missing credential\n * is an error instead of a fall-through to `fs` mode, looking for a working\n * tree that is not in here.\n */\nconst apiKey = secret(\"VAL_API_KEY\");\nconst valSecret = secret(\"VAL_SECRET\");\n/*\n * Which content service, for a project that is not pointed at the real one.\n *\n * A secret rather than a baked literal, because unlike the commit this IS\n * configuration: the same build should be servable against a stand-in and\n * against production. It is what makes the editing path testable at all --\n * Val's own `e2e/mock-content-host` implements this wire protocol with no git\n * repository behind it -- and without it a build could only ever talk to\n * content.val.build.\n *\n * It does NOT redirect everything, and the gap is in Val rather than here:\n * `getSettings`, which remote FILES use, reads `process.env.VAL_CONTENT_URL`\n * at module scope inside @valbuild/server. This platform bundles its\n * dependencies separately from the app, so nothing it sets reaches that read --\n * the same reason `apiKey` has to be passed in rather than found. So patches,\n * commits and source reads go where this says, and remote file uploads still\n * address the real host.\n */\nconst valContentUrl = secret(\"VAL_CONTENT_URL\");\n/*\n * WHICH project's content this is, at the content service.\n *\n * Val's own name for the project (`org/name`), which is not the platform's\n * project id and cannot be derived from it. A repository that is deployed\n * anywhere else puts it in `val.config.ts`; one imported here need not have,\n * so it is configuration the platform can supply -- and it goes through\n * `secret` rather than `--env` for a second reason: a build-time literal\n * would have to be baked into the shared dependency layer, where\n * @valbuild/server reads `process.env.VAL_PROJECT`, and that layer is reused\n * by every project with the same dependencies.\n *\n * What the app configured wins over nothing at all, so a repository that does\n * name its project keeps working with no secret set.\n */\nconst valProject = secret(\"VAL_PROJECT\");\n/*\n * WHICH BUILD this is, as the platform running it says.\n *\n * Not baked like `BUILT_FROM`, because it cannot be: a build's hash is taken\n * of its output, this file included. The platform hands it over at runtime,\n * and Val sends it to the content service, which places this build's overlay\n * by it -- the one answer that holds for the minute after a publish in which\n * the edge still serves this build while the pointer already names the next.\n * Ignored by a @valbuild/tanstack that predates it.\n */\nconst servedBuild = secret(\"VAL_BUILD\");\n").concat(PROPOSAL_BLOCK, "const valConfig = {\n ...config,\n ...(valProject !== undefined ? { project: valProject } : {}),\n};\n/*\n * CREDENTIALS ALONE. A commit is not part of what puts Val in http mode.\n *\n * It used to be: `GIT !== null` was in this condition, and a build with no\n * commit fell through to `undefined` -- which meant every site this platform\n * seeded was silently unable to edit, because a shared build cannot know a\n * commit. The binding that worked around it (`VAL_GIT_COMMIT` /\n * `VAL_GIT_BRANCH` out of the project's secrets) is gone with it: it named a\n * commit in the TEMPLATE's repository, which was true only for as long as\n * seeding and repository creation shared a template, and it was one more thing\n * in KV that could go stale.\n *\n * The commit is optional NOW, and it is still sent where there is one -- see\n * the note at the spread below. What is gone is the binding that supplied one\n * from KV, so there is one source per environment and no precedence rule\n * between a baked value and a bound one.\n */\nconst http =\n apiKey !== undefined && valSecret !== undefined\n ? {\n apiKey,\n valSecret,\n /*\n * BOTH SPELLINGS OF THE COMMIT, because the APP decides which one is\n * read and this file cannot know which app it is being written into.\n *\n * `ValHttpMode` has been renamed in both directions. Up to 0.132 it\n * took `gitCommit`/`gitBranch`; 0.133.0 replaced that pair with a\n * nested `git`; the version this package ships beside flattens it\n * back again. The generated file is compiled against whatever\n * `@valbuild/tanstack` the PROJECT installed -- the starter pins\n * 0.133.0 -- and a platform writing this file has no say in that. So\n * this is not one rename behind or ahead: it is on both sides of one at\n * once, and will be until every app it publishes has moved.\n *\n * Sending only the wrong one is SILENT, which is why this is belt and\n * braces rather than a version check. An unknown key on the options\n * object is ignored, so the commit is simply dropped and a build wired\n * FROM A COMMIT runs as though it had none -- which means a publish\n * produces no mirrored `.val.ts`, so a save commits and hands over\n * nothing, and the site keeps serving its old content with the patches\n * already consumed. Nothing reports it. valbuild/home's loop is the one\n * thing that sees it, and it was bisected there: 25/25 with the key the\n * installed version reads, 21/23 without, failing at exactly \"the save\n * left the file it rewrote pending\".\n *\n * Whichever version is installed reads its own key and ignores the\n * other two. Drop this to one spelling when every app this platform\n * publishes is past the rename -- not before, and not on the say-so of\n * a compiler in the Val repository, which is looking at a different\n * version of `@valbuild/tanstack` than the app is.\n */\n ...(BUILT_FROM !== null\n ? {\n git: BUILT_FROM,\n gitCommit: BUILT_FROM.commit,\n gitBranch: BUILT_FROM.branch,\n }\n : {}),\n ...(valContentUrl !== undefined ? { valContentUrl } : {}),\n projectSource: FILES,\n ...(BUILT_FOR_JOB !== null ? { publishJob: BUILT_FOR_JOB } : {}),\n ...(servedBuild !== undefined ? { publishBuild: servedBuild } : {}),\n").concat(PROPOSAL_OPTION, " }\n : undefined;\n\nconst { valApiHandler, draftMode } = initValServer(\n valModules,\n valConfig,\n {\n ...(http ? { http } : {}),\n },\n);\n\nconst content = initValContent(valConfig, valModules, {\n draftMode,\n /*\n * The SAME object the API got.\n *\n * These readers resolve content through a Val server of their own rather than\n * by calling the API over HTTP, so the mode question is put to them\n * separately -- configuring only `initValServer` left them inferring `fs`\n * mode, looking for a working tree that is not in here. `gitCommit` is the\n * field that would be silently wrong rather than loudly missing: two\n * different shas means the API edits one version of a file while the page\n * renders another.\n */\n ...(http ? { http } : {}),\n});\n\nconst {\n fetchValStega: fetchVal,\n fetchValKeyStega: fetchValKey,\n fetchValRouteStega: fetchValRoute,\n fetchValRouteUrl,\n} = content;\n\n/**\n * The draft a page renders with in preview: `<ValProvider draft>`, read in the\n * site layout's loader. The starter imports it from this file, so a file\n * without it fails the build with a missing export.\n *\n * Asked of the result rather than destructured, because this file is compiled\n * against whatever `@valbuild/tanstack` the PROJECT installed, and one from\n * before 0.140 has no such reader. There it is \"no draft\", which is the\n * render that version had anyway -- and it is still a function either way, so\n * a page that calls it compiles against both.\n */\nconst fetchValDraft = async () =>\n \"fetchValDraft\" in content && typeof content.fetchValDraft === \"function\"\n ? content.fetchValDraft()\n : null;\n\n/**\n * A build that is MEANT to edit and cannot, refusing instead of pretending to.\n *\n * `BUILT_FROM` being non-null says this build came from a commit, so it was\n * made to edit against a content service. If the credentials for that service are not\n * here, the configuration is broken -- and the failure that was reaching people\n * was not an error at all. Val picks its storage mode by inference, so an\n * isolate with no api key lands in a mode that ACCEPTS the write and keeps it\n * in the isolate. Cloudflare starts an isolate per concurrent request, so the\n * save answers 200 and the next request, served by a different isolate, has\n * never heard of it. The edit is simply gone, and nothing anywhere said so.\n *\n * That is the worst available outcome: a person is told their work is saved\n * when it is not. Refusing is strictly better, and naming the missing secret\n * turns an evening of reading logs into one line in a response body.\n *\n * WHY HERE rather than relying on `VAL_ENV=app`: that is a build-time\n * substitution into the shared dependency layer, so whether a build fails\n * loudly depends on which layer it happens to be pinned to. This file is\n * written on every build, by the platform, and cannot be missing from one.\n *\n * Only the editing API. Page renders do not come through here, and a site whose\n * content cannot be edited should still serve the content it has.\n */\nconst editingApiHandler =\n http === undefined\n ? async () => {\n const missing = [\n apiKey === undefined ? \"VAL_API_KEY\" : null,\n valSecret === undefined ? \"VAL_SECRET\" : null,\n /*\n * A build from no commit is listed the same way, because from the\n * outside the two are one state. It is not a secret somebody can set\n * -- a commit is a property OF THE BUILD, and the only cure is\n * publishing this project's own repository over whatever is serving\n * it. Named anyway, because \"it was built from no commit\" is the\n * sentence that ends the search.\n */\n BUILT_FROM === null ? \"a commit (this build was made from none)\" : null,\n ].filter(Boolean);\n return Response.json(\n {\n error:\n \"This site cannot be edited. Its content lives in a content service, and \" +\n missing.join(\", \") +\n \" \" +\n (missing.length > 1 ? \"are\" : \"is\") +\n \" missing, so there is nothing to edit against. Editing is refused rather \" +\n \"than kept in this isolate's memory, where it would be lost without being \" +\n \"reported.\" +\n (BUILT_FROM === null\n ? \" A build made from no commit is usually one SEEDED from a template: \" +\n \"publish this project's own repository to replace it.\"\n : \" This build was made from commit \" + BUILT_FROM.commit.slice(0, 8) + \".\"),\n missing,\n },\n { status: 503 },\n );\n }\n : valApiHandler;\n\nexport {\n editingApiHandler as valApiHandler,\n draftMode,\n fetchVal,\n fetchValKey,\n fetchValRoute,\n fetchValRouteUrl,\n fetchValDraft,\n};\n");
|
|
3831
|
+
return "".concat(WIRED_MARKER, "\nimport {\n initValContent,\n initValServer,\n} from \"@valbuild/tanstack/server\";\nimport { config } from \"../../val.config\";\nimport valModules from \"../../val.modules\";\n/*\n * This build's own source, which a publish patches. A project with no\n * repository has no other copy of its `.val.ts` text: content keeps its\n * content as data. Ignored by a @valbuild/tanstack that predates it.\n */\nimport { FILES } from \"platform:project-source\";\n\n/**\n * A secret, as the platform hands it over at RUNTIME.\n *\n * Preferred over `process.env`, which the builder inlines as a literal into\n * this bundle: that puts the value in storage inside the code, copies it into\n * every isolate that loads it, and makes rotating it a republish.\n *\n * Falls back to the build-time value, so an app published before secrets\n * existed keeps working.\n */\nfunction secret(name: string): string | undefined {\n return (globalThis.__PLATFORM_SECRETS ?? {})[name] ?? process.env[name];\n}\n\n/**\n * The commit this build was made from, and the branch it commits to.\n *\n * Baked in rather than handed over at runtime, unlike a secret, because it is\n * not configuration -- it is a property OF THIS BUILD. Every read of a\n * `.val.ts` in http mode fetches that path from the content service at this\n * sha, so a build served with somebody else's commit renders and edits a\n * version of its files it was not compiled from. A secret can be rotated under\n * a running build; this cannot, and publishing again is how it changes.\n *\n * WHAT THIS IS NOT. It is not every read: a committed render reads the source\n * bundled into this build and asks the content service nothing. It is the\n * PUBLISH path -- turning pending patches into new `.val.ts` text means\n * fetching the current text to patch, and that is the read that happens at\n * this sha. The docblock used to say \"every read\", which sent readers looking\n * for a content call on the serving path that is not there.\n *\n * `null` when the source came from no commit -- a record assembled in a tab,\n * a fixture, or ANY build this platform makes, which is the common case rather\n * than the exception. Such a build has no repository to mirror commits into,\n * and does not need one: the content service is the store of record for\n * content and mints its own commit shas. Val is in http mode on credentials\n * alone.\n */\nconst BUILT_FROM = ").concat(git ? JSON.stringify(git) : "null", ";\n\n/**\n * The publish job this build was made for, when a Studio built it in a tab.\n *\n * A tab's build has no commit to bake -- the job's is minted at the seal, after\n * the build -- so this is how it says where it sits in the content service's\n * chain. Without it the service places it at whatever build is live, which is\n * a different build for a request this one is still serving when the pointer\n * moves. Set by the Studio (`rebakeGit`), `null` for any other build.\n */\nconst BUILT_FOR_JOB = null;\n\n/**\n * What puts Val in http mode: its content service owns the content.\n *\n * The same three things any deployed Val app is configured with. Note what is\n * NOT here: no `sourceFiles`, so patches are relayed to the content service\n * instead of being kept by this platform, and the browser uploads an image\n * straight there on a presigned URL instead of streaming it through here.\n *\n * `undefined` when a credential or the commit is missing, and deliberately not\n * a throw at module scope: that would take the isolate down with it, page\n * renders included. Val is left to refuse the request and name what it wanted\n * -- `VAL_ENV=app` is set on this build precisely so that a missing credential\n * is an error instead of a fall-through to `fs` mode, looking for a working\n * tree that is not in here.\n */\nconst apiKey = secret(\"VAL_API_KEY\");\nconst valSecret = secret(\"VAL_SECRET\");\n/*\n * Which content service, for a project that is not pointed at the real one.\n *\n * A secret rather than a baked literal, because unlike the commit this IS\n * configuration: the same build should be servable against a stand-in and\n * against production. It is what makes the editing path testable at all --\n * Val's own `e2e/mock-content-host` implements this wire protocol with no git\n * repository behind it -- and without it a build could only ever talk to\n * content.val.build.\n *\n * It does NOT redirect everything, and the gap is in Val rather than here:\n * `getSettings`, which remote FILES use, reads `process.env.VAL_CONTENT_URL`\n * at module scope inside @valbuild/server. This platform bundles its\n * dependencies separately from the app, so nothing it sets reaches that read --\n * the same reason `apiKey` has to be passed in rather than found. So patches,\n * commits and source reads go where this says, and remote file uploads still\n * address the real host.\n */\nconst valContentUrl = secret(\"VAL_CONTENT_URL\");\n/*\n * WHICH project's content this is, at the content service.\n *\n * Val's own name for the project (`org/name`), which is not the platform's\n * project id and cannot be derived from it. A repository that is deployed\n * anywhere else puts it in `val.config.ts`; one imported here need not have,\n * so it is configuration the platform can supply -- and it goes through\n * `secret` rather than `--env` for a second reason: a build-time literal\n * would have to be baked into the shared dependency layer, where\n * @valbuild/server reads `process.env.VAL_PROJECT`, and that layer is reused\n * by every project with the same dependencies.\n *\n * What the app configured wins over nothing at all, so a repository that does\n * name its project keeps working with no secret set.\n */\nconst valProject = secret(\"VAL_PROJECT\");\n/*\n * WHICH BUILD this is, as the platform running it says.\n *\n * Not baked like `BUILT_FROM`, because it cannot be: a build's hash is taken\n * of its output, this file included. The platform hands it over at runtime,\n * and Val sends it to the content service, which places this build's overlay\n * by it -- the one answer that holds for the minute after a publish in which\n * the edge still serves this build while the pointer already names the next.\n * Ignored by a @valbuild/tanstack that predates it.\n */\nconst servedBuild = secret(\"VAL_BUILD\");\n").concat(PROPOSAL_BLOCK).concat(CONTENT_BLOCK, "const valConfig = {\n ...config,\n ...(valProject !== undefined ? { project: valProject } : {}),\n};\n/*\n * CREDENTIALS ALONE. A commit is not part of what puts Val in http mode.\n *\n * It used to be: `GIT !== null` was in this condition, and a build with no\n * commit fell through to `undefined` -- which meant every site this platform\n * seeded was silently unable to edit, because a shared build cannot know a\n * commit. The binding that worked around it (`VAL_GIT_COMMIT` /\n * `VAL_GIT_BRANCH` out of the project's secrets) is gone with it: it named a\n * commit in the TEMPLATE's repository, which was true only for as long as\n * seeding and repository creation shared a template, and it was one more thing\n * in KV that could go stale.\n *\n * The commit is optional NOW, and it is still sent where there is one -- see\n * the note at the spread below. What is gone is the binding that supplied one\n * from KV, so there is one source per environment and no precedence rule\n * between a baked value and a bound one.\n */\nconst http =\n apiKey !== undefined && valSecret !== undefined\n ? {\n apiKey,\n valSecret,\n /*\n * BOTH SPELLINGS OF THE COMMIT, because the APP decides which one is\n * read and this file cannot know which app it is being written into.\n *\n * `ValHttpMode` has been renamed in both directions. Up to 0.132 it\n * took `gitCommit`/`gitBranch`; 0.133.0 replaced that pair with a\n * nested `git`; the version this package ships beside flattens it\n * back again. The generated file is compiled against whatever\n * `@valbuild/tanstack` the PROJECT installed -- the starter pins\n * 0.133.0 -- and a platform writing this file has no say in that. So\n * this is not one rename behind or ahead: it is on both sides of one at\n * once, and will be until every app it publishes has moved.\n *\n * Sending only the wrong one is SILENT, which is why this is belt and\n * braces rather than a version check. An unknown key on the options\n * object is ignored, so the commit is simply dropped and a build wired\n * FROM A COMMIT runs as though it had none -- which means a publish\n * produces no mirrored `.val.ts`, so a save commits and hands over\n * nothing, and the site keeps serving its old content with the patches\n * already consumed. Nothing reports it. valbuild/home's loop is the one\n * thing that sees it, and it was bisected there: 25/25 with the key the\n * installed version reads, 21/23 without, failing at exactly \"the save\n * left the file it rewrote pending\".\n *\n * Whichever version is installed reads its own key and ignores the\n * other two. Drop this to one spelling when every app this platform\n * publishes is past the rename -- not before, and not on the say-so of\n * a compiler in the Val repository, which is looking at a different\n * version of `@valbuild/tanstack` than the app is.\n */\n ...(BUILT_FROM !== null\n ? {\n git: BUILT_FROM,\n gitCommit: BUILT_FROM.commit,\n gitBranch: BUILT_FROM.branch,\n }\n : {}),\n ...(valContentUrl !== undefined ? { valContentUrl } : {}),\n projectSource: FILES,\n ...(BUILT_FOR_JOB !== null ? { publishJob: BUILT_FOR_JOB } : {}),\n ...(servedBuild !== undefined ? { publishBuild: servedBuild } : {}),\n").concat(PROPOSAL_OPTION).concat(CONTENT_OPTION, " }\n : undefined;\n\nconst { valApiHandler, draftMode } = initValServer(\n valModules,\n valConfig,\n {\n ...(http ? { http } : {}),\n },\n);\n\nconst content = initValContent(valConfig, valModules, {\n draftMode,\n /*\n * The SAME object the API got.\n *\n * These readers resolve content through a Val server of their own rather than\n * by calling the API over HTTP, so the mode question is put to them\n * separately -- configuring only `initValServer` left them inferring `fs`\n * mode, looking for a working tree that is not in here. `gitCommit` is the\n * field that would be silently wrong rather than loudly missing: two\n * different shas means the API edits one version of a file while the page\n * renders another.\n */\n ...(http ? { http } : {}),\n});\n\nconst {\n fetchValStega: fetchVal,\n fetchValKeyStega: fetchValKey,\n fetchValRouteStega: fetchValRoute,\n fetchValRouteUrl,\n} = content;\n\n/**\n * The draft a page renders with in preview: `<ValProvider draft>`, read in the\n * site layout's loader. The starter imports it from this file, so a file\n * without it fails the build with a missing export.\n *\n * Asked of the result rather than destructured, because this file is compiled\n * against whatever `@valbuild/tanstack` the PROJECT installed, and one from\n * before 0.140 has no such reader. There it is \"no draft\", which is the\n * render that version had anyway -- and it is still a function either way, so\n * a page that calls it compiles against both.\n */\nconst fetchValDraft = async () =>\n \"fetchValDraft\" in content && typeof content.fetchValDraft === \"function\"\n ? content.fetchValDraft()\n : null;\n\n/**\n * A build that is MEANT to edit and cannot, refusing instead of pretending to.\n *\n * `BUILT_FROM` being non-null says this build came from a commit, so it was\n * made to edit against a content service. If the credentials for that service are not\n * here, the configuration is broken -- and the failure that was reaching people\n * was not an error at all. Val picks its storage mode by inference, so an\n * isolate with no api key lands in a mode that ACCEPTS the write and keeps it\n * in the isolate. Cloudflare starts an isolate per concurrent request, so the\n * save answers 200 and the next request, served by a different isolate, has\n * never heard of it. The edit is simply gone, and nothing anywhere said so.\n *\n * That is the worst available outcome: a person is told their work is saved\n * when it is not. Refusing is strictly better, and naming the missing secret\n * turns an evening of reading logs into one line in a response body.\n *\n * WHY HERE rather than relying on `VAL_ENV=app`: that is a build-time\n * substitution into the shared dependency layer, so whether a build fails\n * loudly depends on which layer it happens to be pinned to. This file is\n * written on every build, by the platform, and cannot be missing from one.\n *\n * Only the editing API. Page renders do not come through here, and a site whose\n * content cannot be edited should still serve the content it has.\n */\nconst editingApiHandler =\n http === undefined\n ? async () => {\n const missing = [\n apiKey === undefined ? \"VAL_API_KEY\" : null,\n valSecret === undefined ? \"VAL_SECRET\" : null,\n /*\n * A build from no commit is listed the same way, because from the\n * outside the two are one state. It is not a secret somebody can set\n * -- a commit is a property OF THE BUILD, and the only cure is\n * publishing this project's own repository over whatever is serving\n * it. Named anyway, because \"it was built from no commit\" is the\n * sentence that ends the search.\n */\n BUILT_FROM === null ? \"a commit (this build was made from none)\" : null,\n ].filter(Boolean);\n return Response.json(\n {\n error:\n \"This site cannot be edited. Its content lives in a content service, and \" +\n missing.join(\", \") +\n \" \" +\n (missing.length > 1 ? \"are\" : \"is\") +\n \" missing, so there is nothing to edit against. Editing is refused rather \" +\n \"than kept in this isolate's memory, where it would be lost without being \" +\n \"reported.\" +\n (BUILT_FROM === null\n ? \" A build made from no commit is usually one SEEDED from a template: \" +\n \"publish this project's own repository to replace it.\"\n : \" This build was made from commit \" + BUILT_FROM.commit.slice(0, 8) + \".\"),\n missing,\n },\n { status: 503 },\n );\n }\n : valApiHandler;\n\nexport {\n editingApiHandler as valApiHandler,\n draftMode,\n fetchVal,\n fetchValKey,\n fetchValRoute,\n fetchValRouteUrl,\n fetchValDraft,\n};\n");
|
|
3823
3832
|
};
|
|
3824
3833
|
|
|
3825
3834
|
/**
|
|
@@ -3916,6 +3925,28 @@ function rebakeProposal(source) {
|
|
|
3916
3925
|
});
|
|
3917
3926
|
}
|
|
3918
3927
|
|
|
3928
|
+
/**
|
|
3929
|
+
* `source` able to serve a content version: {@link CONTENT_BLOCK} and its
|
|
3930
|
+
* option added after the proposal's, to a file wired before they existed.
|
|
3931
|
+
* Idempotent, and only where both places are exactly as generated -- a file
|
|
3932
|
+
* somebody edited is left as it is, and serves the bundle's content.
|
|
3933
|
+
*/
|
|
3934
|
+
function rebakeContent(source) {
|
|
3935
|
+
if (source.includes("const contentVersion = (() => {")) return source;
|
|
3936
|
+
var once = function once(needle) {
|
|
3937
|
+
var at = source.indexOf(needle);
|
|
3938
|
+
return at !== -1 && source.indexOf(needle, at + 1) === -1;
|
|
3939
|
+
};
|
|
3940
|
+
if (!once(PROPOSAL_BLOCK) || !once(PROPOSAL_OPTION)) return source;
|
|
3941
|
+
var withBlock = source.replace(PROPOSAL_BLOCK, function () {
|
|
3942
|
+
return PROPOSAL_BLOCK + CONTENT_BLOCK;
|
|
3943
|
+
});
|
|
3944
|
+
// The option once, whatever left it there: two would hand Val the same key twice.
|
|
3945
|
+
return withBlock.includes(CONTENT_OPTION) ? withBlock : withBlock.replace(PROPOSAL_OPTION, function () {
|
|
3946
|
+
return PROPOSAL_OPTION + CONTENT_OPTION;
|
|
3947
|
+
});
|
|
3948
|
+
}
|
|
3949
|
+
|
|
3919
3950
|
/** `source` with its job set, or `source` itself when it cannot carry one. */
|
|
3920
3951
|
function rebakeJob(source, job) {
|
|
3921
3952
|
var line = "const BUILT_FOR_JOB = ".concat(job === null ? "null" : JSON.stringify(job), ";");
|
|
@@ -3999,7 +4030,7 @@ job) {
|
|
|
3999
4030
|
if (!BUILT_FROM_LINE.test(source)) return files;
|
|
4000
4031
|
var withGit = source.replace(BUILT_FROM_LINE, "const BUILT_FROM = ".concat(git === null ? "null" : JSON.stringify(git), ";"));
|
|
4001
4032
|
var withJob = job === undefined ? withGit : rebakeJob(withGit, job);
|
|
4002
|
-
return regeneratorValues._objectSpread2(regeneratorValues._objectSpread2({}, files), {}, regeneratorValues._defineProperty({}, VAL_SERVER, rebakeProposal(withJob)));
|
|
4033
|
+
return regeneratorValues._objectSpread2(regeneratorValues._objectSpread2({}, files), {}, regeneratorValues._defineProperty({}, VAL_SERVER, rebakeContent(rebakeProposal(withJob))));
|
|
4003
4034
|
}
|
|
4004
4035
|
|
|
4005
4036
|
/** Is this a Val project at all? */
|
|
@@ -3812,14 +3812,23 @@ var LEGACY_CONTROL_HOST = "platform.internal";
|
|
|
3812
3812
|
* rewrites single lines of its `val.server.ts` and never regenerates it.
|
|
3813
3813
|
*/
|
|
3814
3814
|
var PROPOSAL_BLOCK = "/*\n * THE PROPOSAL this isolate serves the address of, when it does: its name and\n * content branch, and the content it has saved (`VAL_OVERLAY`: the save's\n * commit, its Source by module and its `.val.ts` text by path). Val reads\n * that Source instead of the bundle's, commits a save to the proposal, and\n * names the save as its position. valbuild/home `docs/proposals.md`,\n * \"Saving\".\n *\n * Parsed here rather than with `proposalFromEnv` from @valbuild/server,\n * because this file is compiled against whatever @valbuild/tanstack the\n * PROJECT installed, and one from before proposals has no such export -- it\n * also ignores the `proposal` key below, and serves the base build, which\n * is the best an old app can do. A snapshot that does not parse is thrown,\n * not served as the base: a reviewer must not be shown the wrong content as\n * though it were the proposal.\n */\nconst proposal = (() => {\n const name = secret(\"VAL_PROPOSAL\");\n const branch = secret(\"VAL_BRANCH\");\n if (!name || !branch) return undefined;\n const overlay: {\n commit?: string | null;\n modules?: Record<string, unknown>;\n files?: Record<string, string>;\n } = JSON.parse(secret(\"VAL_OVERLAY\") ?? \"{}\");\n return {\n name,\n branch,\n commit: overlay.commit ?? null,\n modules: overlay.modules ?? {},\n files: overlay.files ?? {},\n };\n})();\n";
|
|
3815
|
+
/**
|
|
3816
|
+
* THE CONTENT VERSION the site serves, when it differs from the one this build
|
|
3817
|
+
* bundles (\`VAL_CONTENT\`). See valbuild/home \`docs/hosted-publishing.md\`,
|
|
3818
|
+
* step 2. A constant for the same reason as {@link PROPOSAL_BLOCK}, and it
|
|
3819
|
+
* arrives in files wired before it the same way: {@link rebakeContent}.
|
|
3820
|
+
*/
|
|
3821
|
+
var CONTENT_BLOCK = "/*\n * THE CONTENT VERSION the site serves, when the platform says it differs from\n * the one this build bundles (`VAL_CONTENT`: its id, the publish that made\n * it, and the Source and Val files that differ). Val reads that Source instead\n * of the bundle's and names that publish as its position. valbuild/home\n * `docs/hosted-publishing.md`, step 2.\n *\n * Parsed here, like the proposal above, because this file is compiled against\n * whatever @valbuild/tanstack the PROJECT installed. One from before content\n * versions ignores the `contentVersion` key below and serves the bundle --\n * and never says it applied the version, which is how the platform knows not\n * to serve this build a version it does not bundle. A version that does not\n * parse is thrown, not served as the bundle.\n *\n * A version too large for one variable names others under `refs`\n * (`\"env://VAL_CONTENT_1\"`), each holding one module's Source or one file's\n * text. Only `refs` is resolved, never a string inside Source, and only\n * `VAL_CONTENT_<n>` is read: Source is text editors write, and resolving a\n * reference in there would read `VAL_SECRET` into a page. The same rules as\n * `contentFromEnv` in @valbuild/server.\n */\nconst contentVersion = (() => {\n const handed = secret(\"VAL_CONTENT\");\n if (!handed) return undefined;\n const isRecord = (value: unknown): value is Record<string, unknown> =>\n typeof value === \"object\" && value !== null && !Array.isArray(value);\n const parsed: unknown = JSON.parse(handed);\n if (!isRecord(parsed)) throw new Error(\"Val: VAL_CONTENT is not an object\");\n const id = parsed.id;\n if (typeof id !== \"string\" || id === \"\") {\n throw new Error(\"Val: VAL_CONTENT has no id\");\n }\n const where = \"Val: content version \" + id;\n const nullableString = (key: string): string | null => {\n const value = parsed[key] ?? null;\n if (value !== null && typeof value !== \"string\") {\n throw new Error(where + \": \" + key + \" must be a string or null\");\n }\n return value;\n };\n const record = (value: unknown, name: string): Record<string, unknown> => {\n const found = value ?? {};\n if (!isRecord(found)) throw new Error(where + \": \" + name + \" must be an object\");\n return found;\n };\n const job = nullableString(\"job\");\n const commit = nullableString(\"commit\");\n const modules: Record<string, unknown> = { ...record(parsed.modules, \"modules\") };\n const filesIn = record(parsed.files, \"files\");\n const files: Record<string, string> = {};\n for (const [path, text] of Object.entries(filesIn)) {\n if (typeof text === \"string\") files[path] = text;\n }\n const refs = record(parsed.refs, \"refs\");\n const read = (kind: string, path: string, ref: unknown): string => {\n const at = where + \": refs.\" + kind + \"[\" + path + \"]\";\n if (typeof ref !== \"string\" || !ref.startsWith(\"env://\")) {\n throw new Error(at + \" is \" + String(ref) + \": only env://VAL_CONTENT_<n> is read\");\n }\n const name = ref.slice(\"env://\".length);\n if (!/^VAL_CONTENT_[0-9]+$/.test(name)) {\n throw new Error(at + \" names \" + name + \": only VAL_CONTENT_<n> is read\");\n }\n const value = secret(name);\n if (value === undefined) {\n throw new Error(at + \" names \" + name + \", which is not set\");\n }\n return value;\n };\n for (const [path, ref] of Object.entries(record(refs.modules, \"refs.modules\"))) {\n if (Object.prototype.hasOwnProperty.call(modules, path)) {\n throw new Error(where + \": \" + path + \" is in modules and refs.modules\");\n }\n modules[path] = JSON.parse(read(\"modules\", path, ref));\n }\n for (const [path, ref] of Object.entries(record(refs.files, \"refs.files\"))) {\n if (Object.prototype.hasOwnProperty.call(filesIn, path)) {\n throw new Error(where + \": \" + path + \" is in files and refs.files\");\n }\n files[path] = read(\"files\", path, ref);\n }\n if (job === null && commit === null) {\n throw new Error(where + \" must name a job or a commit, or it would be placed at the build it runs in\");\n }\n return { id, job, commit, modules, files };\n})();\n";
|
|
3815
3822
|
/** Where {@link PROPOSAL_BLOCK} goes: right after this line. */
|
|
3816
3823
|
var SERVED_BUILD_LINE = 'const servedBuild = secret("VAL_BUILD");\n';
|
|
3817
3824
|
/** And the option that hands it to Val, after the build's. */
|
|
3818
3825
|
var PROPOSAL_OPTION = " ...(proposal !== undefined ? { proposal } : {}),\n";
|
|
3826
|
+
/** And the content version's, after the proposal's. */
|
|
3827
|
+
var CONTENT_OPTION = " ...(contentVersion !== undefined ? { contentVersion } : {}),\n";
|
|
3819
3828
|
var PUBLISH_BUILD_OPTION = " ...(servedBuild !== undefined ? { publishBuild: servedBuild } : {}),\n";
|
|
3820
3829
|
var valServerSource = function valServerSource(_ref) {
|
|
3821
3830
|
var git = _ref.git;
|
|
3822
|
-
return "".concat(WIRED_MARKER, "\nimport {\n initValContent,\n initValServer,\n} from \"@valbuild/tanstack/server\";\nimport { config } from \"../../val.config\";\nimport valModules from \"../../val.modules\";\n/*\n * This build's own source, which a publish patches. A project with no\n * repository has no other copy of its `.val.ts` text: content keeps its\n * content as data. Ignored by a @valbuild/tanstack that predates it.\n */\nimport { FILES } from \"platform:project-source\";\n\n/**\n * A secret, as the platform hands it over at RUNTIME.\n *\n * Preferred over `process.env`, which the builder inlines as a literal into\n * this bundle: that puts the value in storage inside the code, copies it into\n * every isolate that loads it, and makes rotating it a republish.\n *\n * Falls back to the build-time value, so an app published before secrets\n * existed keeps working.\n */\nfunction secret(name: string): string | undefined {\n return (globalThis.__PLATFORM_SECRETS ?? {})[name] ?? process.env[name];\n}\n\n/**\n * The commit this build was made from, and the branch it commits to.\n *\n * Baked in rather than handed over at runtime, unlike a secret, because it is\n * not configuration -- it is a property OF THIS BUILD. Every read of a\n * `.val.ts` in http mode fetches that path from the content service at this\n * sha, so a build served with somebody else's commit renders and edits a\n * version of its files it was not compiled from. A secret can be rotated under\n * a running build; this cannot, and publishing again is how it changes.\n *\n * WHAT THIS IS NOT. It is not every read: a committed render reads the source\n * bundled into this build and asks the content service nothing. It is the\n * PUBLISH path -- turning pending patches into new `.val.ts` text means\n * fetching the current text to patch, and that is the read that happens at\n * this sha. The docblock used to say \"every read\", which sent readers looking\n * for a content call on the serving path that is not there.\n *\n * `null` when the source came from no commit -- a record assembled in a tab,\n * a fixture, or ANY build this platform makes, which is the common case rather\n * than the exception. Such a build has no repository to mirror commits into,\n * and does not need one: the content service is the store of record for\n * content and mints its own commit shas. Val is in http mode on credentials\n * alone.\n */\nconst BUILT_FROM = ").concat(git ? JSON.stringify(git) : "null", ";\n\n/**\n * The publish job this build was made for, when a Studio built it in a tab.\n *\n * A tab's build has no commit to bake -- the job's is minted at the seal, after\n * the build -- so this is how it says where it sits in the content service's\n * chain. Without it the service places it at whatever build is live, which is\n * a different build for a request this one is still serving when the pointer\n * moves. Set by the Studio (`rebakeGit`), `null` for any other build.\n */\nconst BUILT_FOR_JOB = null;\n\n/**\n * What puts Val in http mode: its content service owns the content.\n *\n * The same three things any deployed Val app is configured with. Note what is\n * NOT here: no `sourceFiles`, so patches are relayed to the content service\n * instead of being kept by this platform, and the browser uploads an image\n * straight there on a presigned URL instead of streaming it through here.\n *\n * `undefined` when a credential or the commit is missing, and deliberately not\n * a throw at module scope: that would take the isolate down with it, page\n * renders included. Val is left to refuse the request and name what it wanted\n * -- `VAL_ENV=app` is set on this build precisely so that a missing credential\n * is an error instead of a fall-through to `fs` mode, looking for a working\n * tree that is not in here.\n */\nconst apiKey = secret(\"VAL_API_KEY\");\nconst valSecret = secret(\"VAL_SECRET\");\n/*\n * Which content service, for a project that is not pointed at the real one.\n *\n * A secret rather than a baked literal, because unlike the commit this IS\n * configuration: the same build should be servable against a stand-in and\n * against production. It is what makes the editing path testable at all --\n * Val's own `e2e/mock-content-host` implements this wire protocol with no git\n * repository behind it -- and without it a build could only ever talk to\n * content.val.build.\n *\n * It does NOT redirect everything, and the gap is in Val rather than here:\n * `getSettings`, which remote FILES use, reads `process.env.VAL_CONTENT_URL`\n * at module scope inside @valbuild/server. This platform bundles its\n * dependencies separately from the app, so nothing it sets reaches that read --\n * the same reason `apiKey` has to be passed in rather than found. So patches,\n * commits and source reads go where this says, and remote file uploads still\n * address the real host.\n */\nconst valContentUrl = secret(\"VAL_CONTENT_URL\");\n/*\n * WHICH project's content this is, at the content service.\n *\n * Val's own name for the project (`org/name`), which is not the platform's\n * project id and cannot be derived from it. A repository that is deployed\n * anywhere else puts it in `val.config.ts`; one imported here need not have,\n * so it is configuration the platform can supply -- and it goes through\n * `secret` rather than `--env` for a second reason: a build-time literal\n * would have to be baked into the shared dependency layer, where\n * @valbuild/server reads `process.env.VAL_PROJECT`, and that layer is reused\n * by every project with the same dependencies.\n *\n * What the app configured wins over nothing at all, so a repository that does\n * name its project keeps working with no secret set.\n */\nconst valProject = secret(\"VAL_PROJECT\");\n/*\n * WHICH BUILD this is, as the platform running it says.\n *\n * Not baked like `BUILT_FROM`, because it cannot be: a build's hash is taken\n * of its output, this file included. The platform hands it over at runtime,\n * and Val sends it to the content service, which places this build's overlay\n * by it -- the one answer that holds for the minute after a publish in which\n * the edge still serves this build while the pointer already names the next.\n * Ignored by a @valbuild/tanstack that predates it.\n */\nconst servedBuild = secret(\"VAL_BUILD\");\n").concat(PROPOSAL_BLOCK, "const valConfig = {\n ...config,\n ...(valProject !== undefined ? { project: valProject } : {}),\n};\n/*\n * CREDENTIALS ALONE. A commit is not part of what puts Val in http mode.\n *\n * It used to be: `GIT !== null` was in this condition, and a build with no\n * commit fell through to `undefined` -- which meant every site this platform\n * seeded was silently unable to edit, because a shared build cannot know a\n * commit. The binding that worked around it (`VAL_GIT_COMMIT` /\n * `VAL_GIT_BRANCH` out of the project's secrets) is gone with it: it named a\n * commit in the TEMPLATE's repository, which was true only for as long as\n * seeding and repository creation shared a template, and it was one more thing\n * in KV that could go stale.\n *\n * The commit is optional NOW, and it is still sent where there is one -- see\n * the note at the spread below. What is gone is the binding that supplied one\n * from KV, so there is one source per environment and no precedence rule\n * between a baked value and a bound one.\n */\nconst http =\n apiKey !== undefined && valSecret !== undefined\n ? {\n apiKey,\n valSecret,\n /*\n * BOTH SPELLINGS OF THE COMMIT, because the APP decides which one is\n * read and this file cannot know which app it is being written into.\n *\n * `ValHttpMode` has been renamed in both directions. Up to 0.132 it\n * took `gitCommit`/`gitBranch`; 0.133.0 replaced that pair with a\n * nested `git`; the version this package ships beside flattens it\n * back again. The generated file is compiled against whatever\n * `@valbuild/tanstack` the PROJECT installed -- the starter pins\n * 0.133.0 -- and a platform writing this file has no say in that. So\n * this is not one rename behind or ahead: it is on both sides of one at\n * once, and will be until every app it publishes has moved.\n *\n * Sending only the wrong one is SILENT, which is why this is belt and\n * braces rather than a version check. An unknown key on the options\n * object is ignored, so the commit is simply dropped and a build wired\n * FROM A COMMIT runs as though it had none -- which means a publish\n * produces no mirrored `.val.ts`, so a save commits and hands over\n * nothing, and the site keeps serving its old content with the patches\n * already consumed. Nothing reports it. valbuild/home's loop is the one\n * thing that sees it, and it was bisected there: 25/25 with the key the\n * installed version reads, 21/23 without, failing at exactly \"the save\n * left the file it rewrote pending\".\n *\n * Whichever version is installed reads its own key and ignores the\n * other two. Drop this to one spelling when every app this platform\n * publishes is past the rename -- not before, and not on the say-so of\n * a compiler in the Val repository, which is looking at a different\n * version of `@valbuild/tanstack` than the app is.\n */\n ...(BUILT_FROM !== null\n ? {\n git: BUILT_FROM,\n gitCommit: BUILT_FROM.commit,\n gitBranch: BUILT_FROM.branch,\n }\n : {}),\n ...(valContentUrl !== undefined ? { valContentUrl } : {}),\n projectSource: FILES,\n ...(BUILT_FOR_JOB !== null ? { publishJob: BUILT_FOR_JOB } : {}),\n ...(servedBuild !== undefined ? { publishBuild: servedBuild } : {}),\n").concat(PROPOSAL_OPTION, " }\n : undefined;\n\nconst { valApiHandler, draftMode } = initValServer(\n valModules,\n valConfig,\n {\n ...(http ? { http } : {}),\n },\n);\n\nconst content = initValContent(valConfig, valModules, {\n draftMode,\n /*\n * The SAME object the API got.\n *\n * These readers resolve content through a Val server of their own rather than\n * by calling the API over HTTP, so the mode question is put to them\n * separately -- configuring only `initValServer` left them inferring `fs`\n * mode, looking for a working tree that is not in here. `gitCommit` is the\n * field that would be silently wrong rather than loudly missing: two\n * different shas means the API edits one version of a file while the page\n * renders another.\n */\n ...(http ? { http } : {}),\n});\n\nconst {\n fetchValStega: fetchVal,\n fetchValKeyStega: fetchValKey,\n fetchValRouteStega: fetchValRoute,\n fetchValRouteUrl,\n} = content;\n\n/**\n * The draft a page renders with in preview: `<ValProvider draft>`, read in the\n * site layout's loader. The starter imports it from this file, so a file\n * without it fails the build with a missing export.\n *\n * Asked of the result rather than destructured, because this file is compiled\n * against whatever `@valbuild/tanstack` the PROJECT installed, and one from\n * before 0.140 has no such reader. There it is \"no draft\", which is the\n * render that version had anyway -- and it is still a function either way, so\n * a page that calls it compiles against both.\n */\nconst fetchValDraft = async () =>\n \"fetchValDraft\" in content && typeof content.fetchValDraft === \"function\"\n ? content.fetchValDraft()\n : null;\n\n/**\n * A build that is MEANT to edit and cannot, refusing instead of pretending to.\n *\n * `BUILT_FROM` being non-null says this build came from a commit, so it was\n * made to edit against a content service. If the credentials for that service are not\n * here, the configuration is broken -- and the failure that was reaching people\n * was not an error at all. Val picks its storage mode by inference, so an\n * isolate with no api key lands in a mode that ACCEPTS the write and keeps it\n * in the isolate. Cloudflare starts an isolate per concurrent request, so the\n * save answers 200 and the next request, served by a different isolate, has\n * never heard of it. The edit is simply gone, and nothing anywhere said so.\n *\n * That is the worst available outcome: a person is told their work is saved\n * when it is not. Refusing is strictly better, and naming the missing secret\n * turns an evening of reading logs into one line in a response body.\n *\n * WHY HERE rather than relying on `VAL_ENV=app`: that is a build-time\n * substitution into the shared dependency layer, so whether a build fails\n * loudly depends on which layer it happens to be pinned to. This file is\n * written on every build, by the platform, and cannot be missing from one.\n *\n * Only the editing API. Page renders do not come through here, and a site whose\n * content cannot be edited should still serve the content it has.\n */\nconst editingApiHandler =\n http === undefined\n ? async () => {\n const missing = [\n apiKey === undefined ? \"VAL_API_KEY\" : null,\n valSecret === undefined ? \"VAL_SECRET\" : null,\n /*\n * A build from no commit is listed the same way, because from the\n * outside the two are one state. It is not a secret somebody can set\n * -- a commit is a property OF THE BUILD, and the only cure is\n * publishing this project's own repository over whatever is serving\n * it. Named anyway, because \"it was built from no commit\" is the\n * sentence that ends the search.\n */\n BUILT_FROM === null ? \"a commit (this build was made from none)\" : null,\n ].filter(Boolean);\n return Response.json(\n {\n error:\n \"This site cannot be edited. Its content lives in a content service, and \" +\n missing.join(\", \") +\n \" \" +\n (missing.length > 1 ? \"are\" : \"is\") +\n \" missing, so there is nothing to edit against. Editing is refused rather \" +\n \"than kept in this isolate's memory, where it would be lost without being \" +\n \"reported.\" +\n (BUILT_FROM === null\n ? \" A build made from no commit is usually one SEEDED from a template: \" +\n \"publish this project's own repository to replace it.\"\n : \" This build was made from commit \" + BUILT_FROM.commit.slice(0, 8) + \".\"),\n missing,\n },\n { status: 503 },\n );\n }\n : valApiHandler;\n\nexport {\n editingApiHandler as valApiHandler,\n draftMode,\n fetchVal,\n fetchValKey,\n fetchValRoute,\n fetchValRouteUrl,\n fetchValDraft,\n};\n");
|
|
3831
|
+
return "".concat(WIRED_MARKER, "\nimport {\n initValContent,\n initValServer,\n} from \"@valbuild/tanstack/server\";\nimport { config } from \"../../val.config\";\nimport valModules from \"../../val.modules\";\n/*\n * This build's own source, which a publish patches. A project with no\n * repository has no other copy of its `.val.ts` text: content keeps its\n * content as data. Ignored by a @valbuild/tanstack that predates it.\n */\nimport { FILES } from \"platform:project-source\";\n\n/**\n * A secret, as the platform hands it over at RUNTIME.\n *\n * Preferred over `process.env`, which the builder inlines as a literal into\n * this bundle: that puts the value in storage inside the code, copies it into\n * every isolate that loads it, and makes rotating it a republish.\n *\n * Falls back to the build-time value, so an app published before secrets\n * existed keeps working.\n */\nfunction secret(name: string): string | undefined {\n return (globalThis.__PLATFORM_SECRETS ?? {})[name] ?? process.env[name];\n}\n\n/**\n * The commit this build was made from, and the branch it commits to.\n *\n * Baked in rather than handed over at runtime, unlike a secret, because it is\n * not configuration -- it is a property OF THIS BUILD. Every read of a\n * `.val.ts` in http mode fetches that path from the content service at this\n * sha, so a build served with somebody else's commit renders and edits a\n * version of its files it was not compiled from. A secret can be rotated under\n * a running build; this cannot, and publishing again is how it changes.\n *\n * WHAT THIS IS NOT. It is not every read: a committed render reads the source\n * bundled into this build and asks the content service nothing. It is the\n * PUBLISH path -- turning pending patches into new `.val.ts` text means\n * fetching the current text to patch, and that is the read that happens at\n * this sha. The docblock used to say \"every read\", which sent readers looking\n * for a content call on the serving path that is not there.\n *\n * `null` when the source came from no commit -- a record assembled in a tab,\n * a fixture, or ANY build this platform makes, which is the common case rather\n * than the exception. Such a build has no repository to mirror commits into,\n * and does not need one: the content service is the store of record for\n * content and mints its own commit shas. Val is in http mode on credentials\n * alone.\n */\nconst BUILT_FROM = ").concat(git ? JSON.stringify(git) : "null", ";\n\n/**\n * The publish job this build was made for, when a Studio built it in a tab.\n *\n * A tab's build has no commit to bake -- the job's is minted at the seal, after\n * the build -- so this is how it says where it sits in the content service's\n * chain. Without it the service places it at whatever build is live, which is\n * a different build for a request this one is still serving when the pointer\n * moves. Set by the Studio (`rebakeGit`), `null` for any other build.\n */\nconst BUILT_FOR_JOB = null;\n\n/**\n * What puts Val in http mode: its content service owns the content.\n *\n * The same three things any deployed Val app is configured with. Note what is\n * NOT here: no `sourceFiles`, so patches are relayed to the content service\n * instead of being kept by this platform, and the browser uploads an image\n * straight there on a presigned URL instead of streaming it through here.\n *\n * `undefined` when a credential or the commit is missing, and deliberately not\n * a throw at module scope: that would take the isolate down with it, page\n * renders included. Val is left to refuse the request and name what it wanted\n * -- `VAL_ENV=app` is set on this build precisely so that a missing credential\n * is an error instead of a fall-through to `fs` mode, looking for a working\n * tree that is not in here.\n */\nconst apiKey = secret(\"VAL_API_KEY\");\nconst valSecret = secret(\"VAL_SECRET\");\n/*\n * Which content service, for a project that is not pointed at the real one.\n *\n * A secret rather than a baked literal, because unlike the commit this IS\n * configuration: the same build should be servable against a stand-in and\n * against production. It is what makes the editing path testable at all --\n * Val's own `e2e/mock-content-host` implements this wire protocol with no git\n * repository behind it -- and without it a build could only ever talk to\n * content.val.build.\n *\n * It does NOT redirect everything, and the gap is in Val rather than here:\n * `getSettings`, which remote FILES use, reads `process.env.VAL_CONTENT_URL`\n * at module scope inside @valbuild/server. This platform bundles its\n * dependencies separately from the app, so nothing it sets reaches that read --\n * the same reason `apiKey` has to be passed in rather than found. So patches,\n * commits and source reads go where this says, and remote file uploads still\n * address the real host.\n */\nconst valContentUrl = secret(\"VAL_CONTENT_URL\");\n/*\n * WHICH project's content this is, at the content service.\n *\n * Val's own name for the project (`org/name`), which is not the platform's\n * project id and cannot be derived from it. A repository that is deployed\n * anywhere else puts it in `val.config.ts`; one imported here need not have,\n * so it is configuration the platform can supply -- and it goes through\n * `secret` rather than `--env` for a second reason: a build-time literal\n * would have to be baked into the shared dependency layer, where\n * @valbuild/server reads `process.env.VAL_PROJECT`, and that layer is reused\n * by every project with the same dependencies.\n *\n * What the app configured wins over nothing at all, so a repository that does\n * name its project keeps working with no secret set.\n */\nconst valProject = secret(\"VAL_PROJECT\");\n/*\n * WHICH BUILD this is, as the platform running it says.\n *\n * Not baked like `BUILT_FROM`, because it cannot be: a build's hash is taken\n * of its output, this file included. The platform hands it over at runtime,\n * and Val sends it to the content service, which places this build's overlay\n * by it -- the one answer that holds for the minute after a publish in which\n * the edge still serves this build while the pointer already names the next.\n * Ignored by a @valbuild/tanstack that predates it.\n */\nconst servedBuild = secret(\"VAL_BUILD\");\n").concat(PROPOSAL_BLOCK).concat(CONTENT_BLOCK, "const valConfig = {\n ...config,\n ...(valProject !== undefined ? { project: valProject } : {}),\n};\n/*\n * CREDENTIALS ALONE. A commit is not part of what puts Val in http mode.\n *\n * It used to be: `GIT !== null` was in this condition, and a build with no\n * commit fell through to `undefined` -- which meant every site this platform\n * seeded was silently unable to edit, because a shared build cannot know a\n * commit. The binding that worked around it (`VAL_GIT_COMMIT` /\n * `VAL_GIT_BRANCH` out of the project's secrets) is gone with it: it named a\n * commit in the TEMPLATE's repository, which was true only for as long as\n * seeding and repository creation shared a template, and it was one more thing\n * in KV that could go stale.\n *\n * The commit is optional NOW, and it is still sent where there is one -- see\n * the note at the spread below. What is gone is the binding that supplied one\n * from KV, so there is one source per environment and no precedence rule\n * between a baked value and a bound one.\n */\nconst http =\n apiKey !== undefined && valSecret !== undefined\n ? {\n apiKey,\n valSecret,\n /*\n * BOTH SPELLINGS OF THE COMMIT, because the APP decides which one is\n * read and this file cannot know which app it is being written into.\n *\n * `ValHttpMode` has been renamed in both directions. Up to 0.132 it\n * took `gitCommit`/`gitBranch`; 0.133.0 replaced that pair with a\n * nested `git`; the version this package ships beside flattens it\n * back again. The generated file is compiled against whatever\n * `@valbuild/tanstack` the PROJECT installed -- the starter pins\n * 0.133.0 -- and a platform writing this file has no say in that. So\n * this is not one rename behind or ahead: it is on both sides of one at\n * once, and will be until every app it publishes has moved.\n *\n * Sending only the wrong one is SILENT, which is why this is belt and\n * braces rather than a version check. An unknown key on the options\n * object is ignored, so the commit is simply dropped and a build wired\n * FROM A COMMIT runs as though it had none -- which means a publish\n * produces no mirrored `.val.ts`, so a save commits and hands over\n * nothing, and the site keeps serving its old content with the patches\n * already consumed. Nothing reports it. valbuild/home's loop is the one\n * thing that sees it, and it was bisected there: 25/25 with the key the\n * installed version reads, 21/23 without, failing at exactly \"the save\n * left the file it rewrote pending\".\n *\n * Whichever version is installed reads its own key and ignores the\n * other two. Drop this to one spelling when every app this platform\n * publishes is past the rename -- not before, and not on the say-so of\n * a compiler in the Val repository, which is looking at a different\n * version of `@valbuild/tanstack` than the app is.\n */\n ...(BUILT_FROM !== null\n ? {\n git: BUILT_FROM,\n gitCommit: BUILT_FROM.commit,\n gitBranch: BUILT_FROM.branch,\n }\n : {}),\n ...(valContentUrl !== undefined ? { valContentUrl } : {}),\n projectSource: FILES,\n ...(BUILT_FOR_JOB !== null ? { publishJob: BUILT_FOR_JOB } : {}),\n ...(servedBuild !== undefined ? { publishBuild: servedBuild } : {}),\n").concat(PROPOSAL_OPTION).concat(CONTENT_OPTION, " }\n : undefined;\n\nconst { valApiHandler, draftMode } = initValServer(\n valModules,\n valConfig,\n {\n ...(http ? { http } : {}),\n },\n);\n\nconst content = initValContent(valConfig, valModules, {\n draftMode,\n /*\n * The SAME object the API got.\n *\n * These readers resolve content through a Val server of their own rather than\n * by calling the API over HTTP, so the mode question is put to them\n * separately -- configuring only `initValServer` left them inferring `fs`\n * mode, looking for a working tree that is not in here. `gitCommit` is the\n * field that would be silently wrong rather than loudly missing: two\n * different shas means the API edits one version of a file while the page\n * renders another.\n */\n ...(http ? { http } : {}),\n});\n\nconst {\n fetchValStega: fetchVal,\n fetchValKeyStega: fetchValKey,\n fetchValRouteStega: fetchValRoute,\n fetchValRouteUrl,\n} = content;\n\n/**\n * The draft a page renders with in preview: `<ValProvider draft>`, read in the\n * site layout's loader. The starter imports it from this file, so a file\n * without it fails the build with a missing export.\n *\n * Asked of the result rather than destructured, because this file is compiled\n * against whatever `@valbuild/tanstack` the PROJECT installed, and one from\n * before 0.140 has no such reader. There it is \"no draft\", which is the\n * render that version had anyway -- and it is still a function either way, so\n * a page that calls it compiles against both.\n */\nconst fetchValDraft = async () =>\n \"fetchValDraft\" in content && typeof content.fetchValDraft === \"function\"\n ? content.fetchValDraft()\n : null;\n\n/**\n * A build that is MEANT to edit and cannot, refusing instead of pretending to.\n *\n * `BUILT_FROM` being non-null says this build came from a commit, so it was\n * made to edit against a content service. If the credentials for that service are not\n * here, the configuration is broken -- and the failure that was reaching people\n * was not an error at all. Val picks its storage mode by inference, so an\n * isolate with no api key lands in a mode that ACCEPTS the write and keeps it\n * in the isolate. Cloudflare starts an isolate per concurrent request, so the\n * save answers 200 and the next request, served by a different isolate, has\n * never heard of it. The edit is simply gone, and nothing anywhere said so.\n *\n * That is the worst available outcome: a person is told their work is saved\n * when it is not. Refusing is strictly better, and naming the missing secret\n * turns an evening of reading logs into one line in a response body.\n *\n * WHY HERE rather than relying on `VAL_ENV=app`: that is a build-time\n * substitution into the shared dependency layer, so whether a build fails\n * loudly depends on which layer it happens to be pinned to. This file is\n * written on every build, by the platform, and cannot be missing from one.\n *\n * Only the editing API. Page renders do not come through here, and a site whose\n * content cannot be edited should still serve the content it has.\n */\nconst editingApiHandler =\n http === undefined\n ? async () => {\n const missing = [\n apiKey === undefined ? \"VAL_API_KEY\" : null,\n valSecret === undefined ? \"VAL_SECRET\" : null,\n /*\n * A build from no commit is listed the same way, because from the\n * outside the two are one state. It is not a secret somebody can set\n * -- a commit is a property OF THE BUILD, and the only cure is\n * publishing this project's own repository over whatever is serving\n * it. Named anyway, because \"it was built from no commit\" is the\n * sentence that ends the search.\n */\n BUILT_FROM === null ? \"a commit (this build was made from none)\" : null,\n ].filter(Boolean);\n return Response.json(\n {\n error:\n \"This site cannot be edited. Its content lives in a content service, and \" +\n missing.join(\", \") +\n \" \" +\n (missing.length > 1 ? \"are\" : \"is\") +\n \" missing, so there is nothing to edit against. Editing is refused rather \" +\n \"than kept in this isolate's memory, where it would be lost without being \" +\n \"reported.\" +\n (BUILT_FROM === null\n ? \" A build made from no commit is usually one SEEDED from a template: \" +\n \"publish this project's own repository to replace it.\"\n : \" This build was made from commit \" + BUILT_FROM.commit.slice(0, 8) + \".\"),\n missing,\n },\n { status: 503 },\n );\n }\n : valApiHandler;\n\nexport {\n editingApiHandler as valApiHandler,\n draftMode,\n fetchVal,\n fetchValKey,\n fetchValRoute,\n fetchValRouteUrl,\n fetchValDraft,\n};\n");
|
|
3823
3832
|
};
|
|
3824
3833
|
|
|
3825
3834
|
/**
|
|
@@ -3916,6 +3925,28 @@ function rebakeProposal(source) {
|
|
|
3916
3925
|
});
|
|
3917
3926
|
}
|
|
3918
3927
|
|
|
3928
|
+
/**
|
|
3929
|
+
* `source` able to serve a content version: {@link CONTENT_BLOCK} and its
|
|
3930
|
+
* option added after the proposal's, to a file wired before they existed.
|
|
3931
|
+
* Idempotent, and only where both places are exactly as generated -- a file
|
|
3932
|
+
* somebody edited is left as it is, and serves the bundle's content.
|
|
3933
|
+
*/
|
|
3934
|
+
function rebakeContent(source) {
|
|
3935
|
+
if (source.includes("const contentVersion = (() => {")) return source;
|
|
3936
|
+
var once = function once(needle) {
|
|
3937
|
+
var at = source.indexOf(needle);
|
|
3938
|
+
return at !== -1 && source.indexOf(needle, at + 1) === -1;
|
|
3939
|
+
};
|
|
3940
|
+
if (!once(PROPOSAL_BLOCK) || !once(PROPOSAL_OPTION)) return source;
|
|
3941
|
+
var withBlock = source.replace(PROPOSAL_BLOCK, function () {
|
|
3942
|
+
return PROPOSAL_BLOCK + CONTENT_BLOCK;
|
|
3943
|
+
});
|
|
3944
|
+
// The option once, whatever left it there: two would hand Val the same key twice.
|
|
3945
|
+
return withBlock.includes(CONTENT_OPTION) ? withBlock : withBlock.replace(PROPOSAL_OPTION, function () {
|
|
3946
|
+
return PROPOSAL_OPTION + CONTENT_OPTION;
|
|
3947
|
+
});
|
|
3948
|
+
}
|
|
3949
|
+
|
|
3919
3950
|
/** `source` with its job set, or `source` itself when it cannot carry one. */
|
|
3920
3951
|
function rebakeJob(source, job) {
|
|
3921
3952
|
var line = "const BUILT_FOR_JOB = ".concat(job === null ? "null" : JSON.stringify(job), ";");
|
|
@@ -3999,7 +4030,7 @@ job) {
|
|
|
3999
4030
|
if (!BUILT_FROM_LINE.test(source)) return files;
|
|
4000
4031
|
var withGit = source.replace(BUILT_FROM_LINE, "const BUILT_FROM = ".concat(git === null ? "null" : JSON.stringify(git), ";"));
|
|
4001
4032
|
var withJob = job === undefined ? withGit : rebakeJob(withGit, job);
|
|
4002
|
-
return regeneratorValues._objectSpread2(regeneratorValues._objectSpread2({}, files), {}, regeneratorValues._defineProperty({}, VAL_SERVER, rebakeProposal(withJob)));
|
|
4033
|
+
return regeneratorValues._objectSpread2(regeneratorValues._objectSpread2({}, files), {}, regeneratorValues._defineProperty({}, VAL_SERVER, rebakeContent(rebakeProposal(withJob))));
|
|
4003
4034
|
}
|
|
4004
4035
|
|
|
4005
4036
|
/** Is this a Val project at all? */
|
|
@@ -3811,14 +3811,23 @@ var LEGACY_CONTROL_HOST = "platform.internal";
|
|
|
3811
3811
|
* rewrites single lines of its `val.server.ts` and never regenerates it.
|
|
3812
3812
|
*/
|
|
3813
3813
|
var PROPOSAL_BLOCK = "/*\n * THE PROPOSAL this isolate serves the address of, when it does: its name and\n * content branch, and the content it has saved (`VAL_OVERLAY`: the save's\n * commit, its Source by module and its `.val.ts` text by path). Val reads\n * that Source instead of the bundle's, commits a save to the proposal, and\n * names the save as its position. valbuild/home `docs/proposals.md`,\n * \"Saving\".\n *\n * Parsed here rather than with `proposalFromEnv` from @valbuild/server,\n * because this file is compiled against whatever @valbuild/tanstack the\n * PROJECT installed, and one from before proposals has no such export -- it\n * also ignores the `proposal` key below, and serves the base build, which\n * is the best an old app can do. A snapshot that does not parse is thrown,\n * not served as the base: a reviewer must not be shown the wrong content as\n * though it were the proposal.\n */\nconst proposal = (() => {\n const name = secret(\"VAL_PROPOSAL\");\n const branch = secret(\"VAL_BRANCH\");\n if (!name || !branch) return undefined;\n const overlay: {\n commit?: string | null;\n modules?: Record<string, unknown>;\n files?: Record<string, string>;\n } = JSON.parse(secret(\"VAL_OVERLAY\") ?? \"{}\");\n return {\n name,\n branch,\n commit: overlay.commit ?? null,\n modules: overlay.modules ?? {},\n files: overlay.files ?? {},\n };\n})();\n";
|
|
3814
|
+
/**
|
|
3815
|
+
* THE CONTENT VERSION the site serves, when it differs from the one this build
|
|
3816
|
+
* bundles (\`VAL_CONTENT\`). See valbuild/home \`docs/hosted-publishing.md\`,
|
|
3817
|
+
* step 2. A constant for the same reason as {@link PROPOSAL_BLOCK}, and it
|
|
3818
|
+
* arrives in files wired before it the same way: {@link rebakeContent}.
|
|
3819
|
+
*/
|
|
3820
|
+
var CONTENT_BLOCK = "/*\n * THE CONTENT VERSION the site serves, when the platform says it differs from\n * the one this build bundles (`VAL_CONTENT`: its id, the publish that made\n * it, and the Source and Val files that differ). Val reads that Source instead\n * of the bundle's and names that publish as its position. valbuild/home\n * `docs/hosted-publishing.md`, step 2.\n *\n * Parsed here, like the proposal above, because this file is compiled against\n * whatever @valbuild/tanstack the PROJECT installed. One from before content\n * versions ignores the `contentVersion` key below and serves the bundle --\n * and never says it applied the version, which is how the platform knows not\n * to serve this build a version it does not bundle. A version that does not\n * parse is thrown, not served as the bundle.\n *\n * A version too large for one variable names others under `refs`\n * (`\"env://VAL_CONTENT_1\"`), each holding one module's Source or one file's\n * text. Only `refs` is resolved, never a string inside Source, and only\n * `VAL_CONTENT_<n>` is read: Source is text editors write, and resolving a\n * reference in there would read `VAL_SECRET` into a page. The same rules as\n * `contentFromEnv` in @valbuild/server.\n */\nconst contentVersion = (() => {\n const handed = secret(\"VAL_CONTENT\");\n if (!handed) return undefined;\n const isRecord = (value: unknown): value is Record<string, unknown> =>\n typeof value === \"object\" && value !== null && !Array.isArray(value);\n const parsed: unknown = JSON.parse(handed);\n if (!isRecord(parsed)) throw new Error(\"Val: VAL_CONTENT is not an object\");\n const id = parsed.id;\n if (typeof id !== \"string\" || id === \"\") {\n throw new Error(\"Val: VAL_CONTENT has no id\");\n }\n const where = \"Val: content version \" + id;\n const nullableString = (key: string): string | null => {\n const value = parsed[key] ?? null;\n if (value !== null && typeof value !== \"string\") {\n throw new Error(where + \": \" + key + \" must be a string or null\");\n }\n return value;\n };\n const record = (value: unknown, name: string): Record<string, unknown> => {\n const found = value ?? {};\n if (!isRecord(found)) throw new Error(where + \": \" + name + \" must be an object\");\n return found;\n };\n const job = nullableString(\"job\");\n const commit = nullableString(\"commit\");\n const modules: Record<string, unknown> = { ...record(parsed.modules, \"modules\") };\n const filesIn = record(parsed.files, \"files\");\n const files: Record<string, string> = {};\n for (const [path, text] of Object.entries(filesIn)) {\n if (typeof text === \"string\") files[path] = text;\n }\n const refs = record(parsed.refs, \"refs\");\n const read = (kind: string, path: string, ref: unknown): string => {\n const at = where + \": refs.\" + kind + \"[\" + path + \"]\";\n if (typeof ref !== \"string\" || !ref.startsWith(\"env://\")) {\n throw new Error(at + \" is \" + String(ref) + \": only env://VAL_CONTENT_<n> is read\");\n }\n const name = ref.slice(\"env://\".length);\n if (!/^VAL_CONTENT_[0-9]+$/.test(name)) {\n throw new Error(at + \" names \" + name + \": only VAL_CONTENT_<n> is read\");\n }\n const value = secret(name);\n if (value === undefined) {\n throw new Error(at + \" names \" + name + \", which is not set\");\n }\n return value;\n };\n for (const [path, ref] of Object.entries(record(refs.modules, \"refs.modules\"))) {\n if (Object.prototype.hasOwnProperty.call(modules, path)) {\n throw new Error(where + \": \" + path + \" is in modules and refs.modules\");\n }\n modules[path] = JSON.parse(read(\"modules\", path, ref));\n }\n for (const [path, ref] of Object.entries(record(refs.files, \"refs.files\"))) {\n if (Object.prototype.hasOwnProperty.call(filesIn, path)) {\n throw new Error(where + \": \" + path + \" is in files and refs.files\");\n }\n files[path] = read(\"files\", path, ref);\n }\n if (job === null && commit === null) {\n throw new Error(where + \" must name a job or a commit, or it would be placed at the build it runs in\");\n }\n return { id, job, commit, modules, files };\n})();\n";
|
|
3814
3821
|
/** Where {@link PROPOSAL_BLOCK} goes: right after this line. */
|
|
3815
3822
|
var SERVED_BUILD_LINE = 'const servedBuild = secret("VAL_BUILD");\n';
|
|
3816
3823
|
/** And the option that hands it to Val, after the build's. */
|
|
3817
3824
|
var PROPOSAL_OPTION = " ...(proposal !== undefined ? { proposal } : {}),\n";
|
|
3825
|
+
/** And the content version's, after the proposal's. */
|
|
3826
|
+
var CONTENT_OPTION = " ...(contentVersion !== undefined ? { contentVersion } : {}),\n";
|
|
3818
3827
|
var PUBLISH_BUILD_OPTION = " ...(servedBuild !== undefined ? { publishBuild: servedBuild } : {}),\n";
|
|
3819
3828
|
var valServerSource = function valServerSource(_ref) {
|
|
3820
3829
|
var git = _ref.git;
|
|
3821
|
-
return "".concat(WIRED_MARKER, "\nimport {\n initValContent,\n initValServer,\n} from \"@valbuild/tanstack/server\";\nimport { config } from \"../../val.config\";\nimport valModules from \"../../val.modules\";\n/*\n * This build's own source, which a publish patches. A project with no\n * repository has no other copy of its `.val.ts` text: content keeps its\n * content as data. Ignored by a @valbuild/tanstack that predates it.\n */\nimport { FILES } from \"platform:project-source\";\n\n/**\n * A secret, as the platform hands it over at RUNTIME.\n *\n * Preferred over `process.env`, which the builder inlines as a literal into\n * this bundle: that puts the value in storage inside the code, copies it into\n * every isolate that loads it, and makes rotating it a republish.\n *\n * Falls back to the build-time value, so an app published before secrets\n * existed keeps working.\n */\nfunction secret(name: string): string | undefined {\n return (globalThis.__PLATFORM_SECRETS ?? {})[name] ?? process.env[name];\n}\n\n/**\n * The commit this build was made from, and the branch it commits to.\n *\n * Baked in rather than handed over at runtime, unlike a secret, because it is\n * not configuration -- it is a property OF THIS BUILD. Every read of a\n * `.val.ts` in http mode fetches that path from the content service at this\n * sha, so a build served with somebody else's commit renders and edits a\n * version of its files it was not compiled from. A secret can be rotated under\n * a running build; this cannot, and publishing again is how it changes.\n *\n * WHAT THIS IS NOT. It is not every read: a committed render reads the source\n * bundled into this build and asks the content service nothing. It is the\n * PUBLISH path -- turning pending patches into new `.val.ts` text means\n * fetching the current text to patch, and that is the read that happens at\n * this sha. The docblock used to say \"every read\", which sent readers looking\n * for a content call on the serving path that is not there.\n *\n * `null` when the source came from no commit -- a record assembled in a tab,\n * a fixture, or ANY build this platform makes, which is the common case rather\n * than the exception. Such a build has no repository to mirror commits into,\n * and does not need one: the content service is the store of record for\n * content and mints its own commit shas. Val is in http mode on credentials\n * alone.\n */\nconst BUILT_FROM = ").concat(git ? JSON.stringify(git) : "null", ";\n\n/**\n * The publish job this build was made for, when a Studio built it in a tab.\n *\n * A tab's build has no commit to bake -- the job's is minted at the seal, after\n * the build -- so this is how it says where it sits in the content service's\n * chain. Without it the service places it at whatever build is live, which is\n * a different build for a request this one is still serving when the pointer\n * moves. Set by the Studio (`rebakeGit`), `null` for any other build.\n */\nconst BUILT_FOR_JOB = null;\n\n/**\n * What puts Val in http mode: its content service owns the content.\n *\n * The same three things any deployed Val app is configured with. Note what is\n * NOT here: no `sourceFiles`, so patches are relayed to the content service\n * instead of being kept by this platform, and the browser uploads an image\n * straight there on a presigned URL instead of streaming it through here.\n *\n * `undefined` when a credential or the commit is missing, and deliberately not\n * a throw at module scope: that would take the isolate down with it, page\n * renders included. Val is left to refuse the request and name what it wanted\n * -- `VAL_ENV=app` is set on this build precisely so that a missing credential\n * is an error instead of a fall-through to `fs` mode, looking for a working\n * tree that is not in here.\n */\nconst apiKey = secret(\"VAL_API_KEY\");\nconst valSecret = secret(\"VAL_SECRET\");\n/*\n * Which content service, for a project that is not pointed at the real one.\n *\n * A secret rather than a baked literal, because unlike the commit this IS\n * configuration: the same build should be servable against a stand-in and\n * against production. It is what makes the editing path testable at all --\n * Val's own `e2e/mock-content-host` implements this wire protocol with no git\n * repository behind it -- and without it a build could only ever talk to\n * content.val.build.\n *\n * It does NOT redirect everything, and the gap is in Val rather than here:\n * `getSettings`, which remote FILES use, reads `process.env.VAL_CONTENT_URL`\n * at module scope inside @valbuild/server. This platform bundles its\n * dependencies separately from the app, so nothing it sets reaches that read --\n * the same reason `apiKey` has to be passed in rather than found. So patches,\n * commits and source reads go where this says, and remote file uploads still\n * address the real host.\n */\nconst valContentUrl = secret(\"VAL_CONTENT_URL\");\n/*\n * WHICH project's content this is, at the content service.\n *\n * Val's own name for the project (`org/name`), which is not the platform's\n * project id and cannot be derived from it. A repository that is deployed\n * anywhere else puts it in `val.config.ts`; one imported here need not have,\n * so it is configuration the platform can supply -- and it goes through\n * `secret` rather than `--env` for a second reason: a build-time literal\n * would have to be baked into the shared dependency layer, where\n * @valbuild/server reads `process.env.VAL_PROJECT`, and that layer is reused\n * by every project with the same dependencies.\n *\n * What the app configured wins over nothing at all, so a repository that does\n * name its project keeps working with no secret set.\n */\nconst valProject = secret(\"VAL_PROJECT\");\n/*\n * WHICH BUILD this is, as the platform running it says.\n *\n * Not baked like `BUILT_FROM`, because it cannot be: a build's hash is taken\n * of its output, this file included. The platform hands it over at runtime,\n * and Val sends it to the content service, which places this build's overlay\n * by it -- the one answer that holds for the minute after a publish in which\n * the edge still serves this build while the pointer already names the next.\n * Ignored by a @valbuild/tanstack that predates it.\n */\nconst servedBuild = secret(\"VAL_BUILD\");\n").concat(PROPOSAL_BLOCK, "const valConfig = {\n ...config,\n ...(valProject !== undefined ? { project: valProject } : {}),\n};\n/*\n * CREDENTIALS ALONE. A commit is not part of what puts Val in http mode.\n *\n * It used to be: `GIT !== null` was in this condition, and a build with no\n * commit fell through to `undefined` -- which meant every site this platform\n * seeded was silently unable to edit, because a shared build cannot know a\n * commit. The binding that worked around it (`VAL_GIT_COMMIT` /\n * `VAL_GIT_BRANCH` out of the project's secrets) is gone with it: it named a\n * commit in the TEMPLATE's repository, which was true only for as long as\n * seeding and repository creation shared a template, and it was one more thing\n * in KV that could go stale.\n *\n * The commit is optional NOW, and it is still sent where there is one -- see\n * the note at the spread below. What is gone is the binding that supplied one\n * from KV, so there is one source per environment and no precedence rule\n * between a baked value and a bound one.\n */\nconst http =\n apiKey !== undefined && valSecret !== undefined\n ? {\n apiKey,\n valSecret,\n /*\n * BOTH SPELLINGS OF THE COMMIT, because the APP decides which one is\n * read and this file cannot know which app it is being written into.\n *\n * `ValHttpMode` has been renamed in both directions. Up to 0.132 it\n * took `gitCommit`/`gitBranch`; 0.133.0 replaced that pair with a\n * nested `git`; the version this package ships beside flattens it\n * back again. The generated file is compiled against whatever\n * `@valbuild/tanstack` the PROJECT installed -- the starter pins\n * 0.133.0 -- and a platform writing this file has no say in that. So\n * this is not one rename behind or ahead: it is on both sides of one at\n * once, and will be until every app it publishes has moved.\n *\n * Sending only the wrong one is SILENT, which is why this is belt and\n * braces rather than a version check. An unknown key on the options\n * object is ignored, so the commit is simply dropped and a build wired\n * FROM A COMMIT runs as though it had none -- which means a publish\n * produces no mirrored `.val.ts`, so a save commits and hands over\n * nothing, and the site keeps serving its old content with the patches\n * already consumed. Nothing reports it. valbuild/home's loop is the one\n * thing that sees it, and it was bisected there: 25/25 with the key the\n * installed version reads, 21/23 without, failing at exactly \"the save\n * left the file it rewrote pending\".\n *\n * Whichever version is installed reads its own key and ignores the\n * other two. Drop this to one spelling when every app this platform\n * publishes is past the rename -- not before, and not on the say-so of\n * a compiler in the Val repository, which is looking at a different\n * version of `@valbuild/tanstack` than the app is.\n */\n ...(BUILT_FROM !== null\n ? {\n git: BUILT_FROM,\n gitCommit: BUILT_FROM.commit,\n gitBranch: BUILT_FROM.branch,\n }\n : {}),\n ...(valContentUrl !== undefined ? { valContentUrl } : {}),\n projectSource: FILES,\n ...(BUILT_FOR_JOB !== null ? { publishJob: BUILT_FOR_JOB } : {}),\n ...(servedBuild !== undefined ? { publishBuild: servedBuild } : {}),\n").concat(PROPOSAL_OPTION, " }\n : undefined;\n\nconst { valApiHandler, draftMode } = initValServer(\n valModules,\n valConfig,\n {\n ...(http ? { http } : {}),\n },\n);\n\nconst content = initValContent(valConfig, valModules, {\n draftMode,\n /*\n * The SAME object the API got.\n *\n * These readers resolve content through a Val server of their own rather than\n * by calling the API over HTTP, so the mode question is put to them\n * separately -- configuring only `initValServer` left them inferring `fs`\n * mode, looking for a working tree that is not in here. `gitCommit` is the\n * field that would be silently wrong rather than loudly missing: two\n * different shas means the API edits one version of a file while the page\n * renders another.\n */\n ...(http ? { http } : {}),\n});\n\nconst {\n fetchValStega: fetchVal,\n fetchValKeyStega: fetchValKey,\n fetchValRouteStega: fetchValRoute,\n fetchValRouteUrl,\n} = content;\n\n/**\n * The draft a page renders with in preview: `<ValProvider draft>`, read in the\n * site layout's loader. The starter imports it from this file, so a file\n * without it fails the build with a missing export.\n *\n * Asked of the result rather than destructured, because this file is compiled\n * against whatever `@valbuild/tanstack` the PROJECT installed, and one from\n * before 0.140 has no such reader. There it is \"no draft\", which is the\n * render that version had anyway -- and it is still a function either way, so\n * a page that calls it compiles against both.\n */\nconst fetchValDraft = async () =>\n \"fetchValDraft\" in content && typeof content.fetchValDraft === \"function\"\n ? content.fetchValDraft()\n : null;\n\n/**\n * A build that is MEANT to edit and cannot, refusing instead of pretending to.\n *\n * `BUILT_FROM` being non-null says this build came from a commit, so it was\n * made to edit against a content service. If the credentials for that service are not\n * here, the configuration is broken -- and the failure that was reaching people\n * was not an error at all. Val picks its storage mode by inference, so an\n * isolate with no api key lands in a mode that ACCEPTS the write and keeps it\n * in the isolate. Cloudflare starts an isolate per concurrent request, so the\n * save answers 200 and the next request, served by a different isolate, has\n * never heard of it. The edit is simply gone, and nothing anywhere said so.\n *\n * That is the worst available outcome: a person is told their work is saved\n * when it is not. Refusing is strictly better, and naming the missing secret\n * turns an evening of reading logs into one line in a response body.\n *\n * WHY HERE rather than relying on `VAL_ENV=app`: that is a build-time\n * substitution into the shared dependency layer, so whether a build fails\n * loudly depends on which layer it happens to be pinned to. This file is\n * written on every build, by the platform, and cannot be missing from one.\n *\n * Only the editing API. Page renders do not come through here, and a site whose\n * content cannot be edited should still serve the content it has.\n */\nconst editingApiHandler =\n http === undefined\n ? async () => {\n const missing = [\n apiKey === undefined ? \"VAL_API_KEY\" : null,\n valSecret === undefined ? \"VAL_SECRET\" : null,\n /*\n * A build from no commit is listed the same way, because from the\n * outside the two are one state. It is not a secret somebody can set\n * -- a commit is a property OF THE BUILD, and the only cure is\n * publishing this project's own repository over whatever is serving\n * it. Named anyway, because \"it was built from no commit\" is the\n * sentence that ends the search.\n */\n BUILT_FROM === null ? \"a commit (this build was made from none)\" : null,\n ].filter(Boolean);\n return Response.json(\n {\n error:\n \"This site cannot be edited. Its content lives in a content service, and \" +\n missing.join(\", \") +\n \" \" +\n (missing.length > 1 ? \"are\" : \"is\") +\n \" missing, so there is nothing to edit against. Editing is refused rather \" +\n \"than kept in this isolate's memory, where it would be lost without being \" +\n \"reported.\" +\n (BUILT_FROM === null\n ? \" A build made from no commit is usually one SEEDED from a template: \" +\n \"publish this project's own repository to replace it.\"\n : \" This build was made from commit \" + BUILT_FROM.commit.slice(0, 8) + \".\"),\n missing,\n },\n { status: 503 },\n );\n }\n : valApiHandler;\n\nexport {\n editingApiHandler as valApiHandler,\n draftMode,\n fetchVal,\n fetchValKey,\n fetchValRoute,\n fetchValRouteUrl,\n fetchValDraft,\n};\n");
|
|
3830
|
+
return "".concat(WIRED_MARKER, "\nimport {\n initValContent,\n initValServer,\n} from \"@valbuild/tanstack/server\";\nimport { config } from \"../../val.config\";\nimport valModules from \"../../val.modules\";\n/*\n * This build's own source, which a publish patches. A project with no\n * repository has no other copy of its `.val.ts` text: content keeps its\n * content as data. Ignored by a @valbuild/tanstack that predates it.\n */\nimport { FILES } from \"platform:project-source\";\n\n/**\n * A secret, as the platform hands it over at RUNTIME.\n *\n * Preferred over `process.env`, which the builder inlines as a literal into\n * this bundle: that puts the value in storage inside the code, copies it into\n * every isolate that loads it, and makes rotating it a republish.\n *\n * Falls back to the build-time value, so an app published before secrets\n * existed keeps working.\n */\nfunction secret(name: string): string | undefined {\n return (globalThis.__PLATFORM_SECRETS ?? {})[name] ?? process.env[name];\n}\n\n/**\n * The commit this build was made from, and the branch it commits to.\n *\n * Baked in rather than handed over at runtime, unlike a secret, because it is\n * not configuration -- it is a property OF THIS BUILD. Every read of a\n * `.val.ts` in http mode fetches that path from the content service at this\n * sha, so a build served with somebody else's commit renders and edits a\n * version of its files it was not compiled from. A secret can be rotated under\n * a running build; this cannot, and publishing again is how it changes.\n *\n * WHAT THIS IS NOT. It is not every read: a committed render reads the source\n * bundled into this build and asks the content service nothing. It is the\n * PUBLISH path -- turning pending patches into new `.val.ts` text means\n * fetching the current text to patch, and that is the read that happens at\n * this sha. The docblock used to say \"every read\", which sent readers looking\n * for a content call on the serving path that is not there.\n *\n * `null` when the source came from no commit -- a record assembled in a tab,\n * a fixture, or ANY build this platform makes, which is the common case rather\n * than the exception. Such a build has no repository to mirror commits into,\n * and does not need one: the content service is the store of record for\n * content and mints its own commit shas. Val is in http mode on credentials\n * alone.\n */\nconst BUILT_FROM = ").concat(git ? JSON.stringify(git) : "null", ";\n\n/**\n * The publish job this build was made for, when a Studio built it in a tab.\n *\n * A tab's build has no commit to bake -- the job's is minted at the seal, after\n * the build -- so this is how it says where it sits in the content service's\n * chain. Without it the service places it at whatever build is live, which is\n * a different build for a request this one is still serving when the pointer\n * moves. Set by the Studio (`rebakeGit`), `null` for any other build.\n */\nconst BUILT_FOR_JOB = null;\n\n/**\n * What puts Val in http mode: its content service owns the content.\n *\n * The same three things any deployed Val app is configured with. Note what is\n * NOT here: no `sourceFiles`, so patches are relayed to the content service\n * instead of being kept by this platform, and the browser uploads an image\n * straight there on a presigned URL instead of streaming it through here.\n *\n * `undefined` when a credential or the commit is missing, and deliberately not\n * a throw at module scope: that would take the isolate down with it, page\n * renders included. Val is left to refuse the request and name what it wanted\n * -- `VAL_ENV=app` is set on this build precisely so that a missing credential\n * is an error instead of a fall-through to `fs` mode, looking for a working\n * tree that is not in here.\n */\nconst apiKey = secret(\"VAL_API_KEY\");\nconst valSecret = secret(\"VAL_SECRET\");\n/*\n * Which content service, for a project that is not pointed at the real one.\n *\n * A secret rather than a baked literal, because unlike the commit this IS\n * configuration: the same build should be servable against a stand-in and\n * against production. It is what makes the editing path testable at all --\n * Val's own `e2e/mock-content-host` implements this wire protocol with no git\n * repository behind it -- and without it a build could only ever talk to\n * content.val.build.\n *\n * It does NOT redirect everything, and the gap is in Val rather than here:\n * `getSettings`, which remote FILES use, reads `process.env.VAL_CONTENT_URL`\n * at module scope inside @valbuild/server. This platform bundles its\n * dependencies separately from the app, so nothing it sets reaches that read --\n * the same reason `apiKey` has to be passed in rather than found. So patches,\n * commits and source reads go where this says, and remote file uploads still\n * address the real host.\n */\nconst valContentUrl = secret(\"VAL_CONTENT_URL\");\n/*\n * WHICH project's content this is, at the content service.\n *\n * Val's own name for the project (`org/name`), which is not the platform's\n * project id and cannot be derived from it. A repository that is deployed\n * anywhere else puts it in `val.config.ts`; one imported here need not have,\n * so it is configuration the platform can supply -- and it goes through\n * `secret` rather than `--env` for a second reason: a build-time literal\n * would have to be baked into the shared dependency layer, where\n * @valbuild/server reads `process.env.VAL_PROJECT`, and that layer is reused\n * by every project with the same dependencies.\n *\n * What the app configured wins over nothing at all, so a repository that does\n * name its project keeps working with no secret set.\n */\nconst valProject = secret(\"VAL_PROJECT\");\n/*\n * WHICH BUILD this is, as the platform running it says.\n *\n * Not baked like `BUILT_FROM`, because it cannot be: a build's hash is taken\n * of its output, this file included. The platform hands it over at runtime,\n * and Val sends it to the content service, which places this build's overlay\n * by it -- the one answer that holds for the minute after a publish in which\n * the edge still serves this build while the pointer already names the next.\n * Ignored by a @valbuild/tanstack that predates it.\n */\nconst servedBuild = secret(\"VAL_BUILD\");\n").concat(PROPOSAL_BLOCK).concat(CONTENT_BLOCK, "const valConfig = {\n ...config,\n ...(valProject !== undefined ? { project: valProject } : {}),\n};\n/*\n * CREDENTIALS ALONE. A commit is not part of what puts Val in http mode.\n *\n * It used to be: `GIT !== null` was in this condition, and a build with no\n * commit fell through to `undefined` -- which meant every site this platform\n * seeded was silently unable to edit, because a shared build cannot know a\n * commit. The binding that worked around it (`VAL_GIT_COMMIT` /\n * `VAL_GIT_BRANCH` out of the project's secrets) is gone with it: it named a\n * commit in the TEMPLATE's repository, which was true only for as long as\n * seeding and repository creation shared a template, and it was one more thing\n * in KV that could go stale.\n *\n * The commit is optional NOW, and it is still sent where there is one -- see\n * the note at the spread below. What is gone is the binding that supplied one\n * from KV, so there is one source per environment and no precedence rule\n * between a baked value and a bound one.\n */\nconst http =\n apiKey !== undefined && valSecret !== undefined\n ? {\n apiKey,\n valSecret,\n /*\n * BOTH SPELLINGS OF THE COMMIT, because the APP decides which one is\n * read and this file cannot know which app it is being written into.\n *\n * `ValHttpMode` has been renamed in both directions. Up to 0.132 it\n * took `gitCommit`/`gitBranch`; 0.133.0 replaced that pair with a\n * nested `git`; the version this package ships beside flattens it\n * back again. The generated file is compiled against whatever\n * `@valbuild/tanstack` the PROJECT installed -- the starter pins\n * 0.133.0 -- and a platform writing this file has no say in that. So\n * this is not one rename behind or ahead: it is on both sides of one at\n * once, and will be until every app it publishes has moved.\n *\n * Sending only the wrong one is SILENT, which is why this is belt and\n * braces rather than a version check. An unknown key on the options\n * object is ignored, so the commit is simply dropped and a build wired\n * FROM A COMMIT runs as though it had none -- which means a publish\n * produces no mirrored `.val.ts`, so a save commits and hands over\n * nothing, and the site keeps serving its old content with the patches\n * already consumed. Nothing reports it. valbuild/home's loop is the one\n * thing that sees it, and it was bisected there: 25/25 with the key the\n * installed version reads, 21/23 without, failing at exactly \"the save\n * left the file it rewrote pending\".\n *\n * Whichever version is installed reads its own key and ignores the\n * other two. Drop this to one spelling when every app this platform\n * publishes is past the rename -- not before, and not on the say-so of\n * a compiler in the Val repository, which is looking at a different\n * version of `@valbuild/tanstack` than the app is.\n */\n ...(BUILT_FROM !== null\n ? {\n git: BUILT_FROM,\n gitCommit: BUILT_FROM.commit,\n gitBranch: BUILT_FROM.branch,\n }\n : {}),\n ...(valContentUrl !== undefined ? { valContentUrl } : {}),\n projectSource: FILES,\n ...(BUILT_FOR_JOB !== null ? { publishJob: BUILT_FOR_JOB } : {}),\n ...(servedBuild !== undefined ? { publishBuild: servedBuild } : {}),\n").concat(PROPOSAL_OPTION).concat(CONTENT_OPTION, " }\n : undefined;\n\nconst { valApiHandler, draftMode } = initValServer(\n valModules,\n valConfig,\n {\n ...(http ? { http } : {}),\n },\n);\n\nconst content = initValContent(valConfig, valModules, {\n draftMode,\n /*\n * The SAME object the API got.\n *\n * These readers resolve content through a Val server of their own rather than\n * by calling the API over HTTP, so the mode question is put to them\n * separately -- configuring only `initValServer` left them inferring `fs`\n * mode, looking for a working tree that is not in here. `gitCommit` is the\n * field that would be silently wrong rather than loudly missing: two\n * different shas means the API edits one version of a file while the page\n * renders another.\n */\n ...(http ? { http } : {}),\n});\n\nconst {\n fetchValStega: fetchVal,\n fetchValKeyStega: fetchValKey,\n fetchValRouteStega: fetchValRoute,\n fetchValRouteUrl,\n} = content;\n\n/**\n * The draft a page renders with in preview: `<ValProvider draft>`, read in the\n * site layout's loader. The starter imports it from this file, so a file\n * without it fails the build with a missing export.\n *\n * Asked of the result rather than destructured, because this file is compiled\n * against whatever `@valbuild/tanstack` the PROJECT installed, and one from\n * before 0.140 has no such reader. There it is \"no draft\", which is the\n * render that version had anyway -- and it is still a function either way, so\n * a page that calls it compiles against both.\n */\nconst fetchValDraft = async () =>\n \"fetchValDraft\" in content && typeof content.fetchValDraft === \"function\"\n ? content.fetchValDraft()\n : null;\n\n/**\n * A build that is MEANT to edit and cannot, refusing instead of pretending to.\n *\n * `BUILT_FROM` being non-null says this build came from a commit, so it was\n * made to edit against a content service. If the credentials for that service are not\n * here, the configuration is broken -- and the failure that was reaching people\n * was not an error at all. Val picks its storage mode by inference, so an\n * isolate with no api key lands in a mode that ACCEPTS the write and keeps it\n * in the isolate. Cloudflare starts an isolate per concurrent request, so the\n * save answers 200 and the next request, served by a different isolate, has\n * never heard of it. The edit is simply gone, and nothing anywhere said so.\n *\n * That is the worst available outcome: a person is told their work is saved\n * when it is not. Refusing is strictly better, and naming the missing secret\n * turns an evening of reading logs into one line in a response body.\n *\n * WHY HERE rather than relying on `VAL_ENV=app`: that is a build-time\n * substitution into the shared dependency layer, so whether a build fails\n * loudly depends on which layer it happens to be pinned to. This file is\n * written on every build, by the platform, and cannot be missing from one.\n *\n * Only the editing API. Page renders do not come through here, and a site whose\n * content cannot be edited should still serve the content it has.\n */\nconst editingApiHandler =\n http === undefined\n ? async () => {\n const missing = [\n apiKey === undefined ? \"VAL_API_KEY\" : null,\n valSecret === undefined ? \"VAL_SECRET\" : null,\n /*\n * A build from no commit is listed the same way, because from the\n * outside the two are one state. It is not a secret somebody can set\n * -- a commit is a property OF THE BUILD, and the only cure is\n * publishing this project's own repository over whatever is serving\n * it. Named anyway, because \"it was built from no commit\" is the\n * sentence that ends the search.\n */\n BUILT_FROM === null ? \"a commit (this build was made from none)\" : null,\n ].filter(Boolean);\n return Response.json(\n {\n error:\n \"This site cannot be edited. Its content lives in a content service, and \" +\n missing.join(\", \") +\n \" \" +\n (missing.length > 1 ? \"are\" : \"is\") +\n \" missing, so there is nothing to edit against. Editing is refused rather \" +\n \"than kept in this isolate's memory, where it would be lost without being \" +\n \"reported.\" +\n (BUILT_FROM === null\n ? \" A build made from no commit is usually one SEEDED from a template: \" +\n \"publish this project's own repository to replace it.\"\n : \" This build was made from commit \" + BUILT_FROM.commit.slice(0, 8) + \".\"),\n missing,\n },\n { status: 503 },\n );\n }\n : valApiHandler;\n\nexport {\n editingApiHandler as valApiHandler,\n draftMode,\n fetchVal,\n fetchValKey,\n fetchValRoute,\n fetchValRouteUrl,\n fetchValDraft,\n};\n");
|
|
3822
3831
|
};
|
|
3823
3832
|
|
|
3824
3833
|
/**
|
|
@@ -3915,6 +3924,28 @@ function rebakeProposal(source) {
|
|
|
3915
3924
|
});
|
|
3916
3925
|
}
|
|
3917
3926
|
|
|
3927
|
+
/**
|
|
3928
|
+
* `source` able to serve a content version: {@link CONTENT_BLOCK} and its
|
|
3929
|
+
* option added after the proposal's, to a file wired before they existed.
|
|
3930
|
+
* Idempotent, and only where both places are exactly as generated -- a file
|
|
3931
|
+
* somebody edited is left as it is, and serves the bundle's content.
|
|
3932
|
+
*/
|
|
3933
|
+
function rebakeContent(source) {
|
|
3934
|
+
if (source.includes("const contentVersion = (() => {")) return source;
|
|
3935
|
+
var once = function once(needle) {
|
|
3936
|
+
var at = source.indexOf(needle);
|
|
3937
|
+
return at !== -1 && source.indexOf(needle, at + 1) === -1;
|
|
3938
|
+
};
|
|
3939
|
+
if (!once(PROPOSAL_BLOCK) || !once(PROPOSAL_OPTION)) return source;
|
|
3940
|
+
var withBlock = source.replace(PROPOSAL_BLOCK, function () {
|
|
3941
|
+
return PROPOSAL_BLOCK + CONTENT_BLOCK;
|
|
3942
|
+
});
|
|
3943
|
+
// The option once, whatever left it there: two would hand Val the same key twice.
|
|
3944
|
+
return withBlock.includes(CONTENT_OPTION) ? withBlock : withBlock.replace(PROPOSAL_OPTION, function () {
|
|
3945
|
+
return PROPOSAL_OPTION + CONTENT_OPTION;
|
|
3946
|
+
});
|
|
3947
|
+
}
|
|
3948
|
+
|
|
3918
3949
|
/** `source` with its job set, or `source` itself when it cannot carry one. */
|
|
3919
3950
|
function rebakeJob(source, job) {
|
|
3920
3951
|
var line = "const BUILT_FOR_JOB = ".concat(job === null ? "null" : JSON.stringify(job), ";");
|
|
@@ -3998,7 +4029,7 @@ job) {
|
|
|
3998
4029
|
if (!BUILT_FROM_LINE.test(source)) return files;
|
|
3999
4030
|
var withGit = source.replace(BUILT_FROM_LINE, "const BUILT_FROM = ".concat(git === null ? "null" : JSON.stringify(git), ";"));
|
|
4000
4031
|
var withJob = job === undefined ? withGit : rebakeJob(withGit, job);
|
|
4001
|
-
return _objectSpread2(_objectSpread2({}, files), {}, _defineProperty({}, VAL_SERVER, rebakeProposal(withJob)));
|
|
4032
|
+
return _objectSpread2(_objectSpread2({}, files), {}, _defineProperty({}, VAL_SERVER, rebakeContent(rebakeProposal(withJob))));
|
|
4002
4033
|
}
|
|
4003
4034
|
|
|
4004
4035
|
/** Is this a Val project at all? */
|
package/package.json
CHANGED