@valbuild/server 0.150.19 → 0.150.21

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,21 @@
1
1
  # @valbuild/server
2
2
 
3
+ ## 0.150.21
4
+
5
+ ### Patch Changes
6
+
7
+ - [#1000](https://github.com/valbuild/val/pull/1000) [`0d516bf`](https://github.com/valbuild/val/commit/0d516bf5347950071444eaa07baf48d1d7fe418c) Thanks [@freekh](https://github.com/freekh)! - **Edits to fields the design tab added no longer revert.** When the design tab added something to a `.val.ts` in a proposal, such as a new button, the module's code changed but the content the proposal served for it did not. An edit to the new button showed on the canvas and then went back. A staged module file now goes to Val Build with the content its text declares, so the two stay in step. This needs the matching Val Build update.
8
+ - Updated dependencies [[`0d516bf`](https://github.com/valbuild/val/commit/0d516bf5347950071444eaa07baf48d1d7fe418c)]:
9
+ - @valbuild/ui@0.150.21
10
+
11
+ ## 0.150.20
12
+
13
+ ### Patch Changes
14
+
15
+ - Updated dependencies [[`c597b3b`](https://github.com/valbuild/val/commit/c597b3bcb9f3bbda285ab6f4977d65ed7f5f161d)]:
16
+ - @valbuild/shared@0.150.20
17
+ - @valbuild/ui@0.150.20
18
+
3
19
  ## 0.150.19
4
20
 
5
21
  ### Patch Changes
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var core = require('@valbuild/core');
6
- var ValRouterCore = require('../../dist/ValRouterCore-de8f4917.cjs.dev.js');
6
+ var ValRouterCore = require('../../dist/ValRouterCore-d37b85cf.cjs.dev.js');
7
7
  require('@valbuild/shared/internal');
8
8
  require('zod');
9
9
  require('zod-validation-error');
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var core = require('@valbuild/core');
6
- var ValRouterCore = require('../../dist/ValRouterCore-080665a2.cjs.prod.js');
6
+ var ValRouterCore = require('../../dist/ValRouterCore-499077da.cjs.prod.js');
7
7
  require('@valbuild/shared/internal');
8
8
  require('zod');
9
9
  require('zod-validation-error');
@@ -1,5 +1,5 @@
1
1
  import { DEFAULT_CONTENT_HOST } from '@valbuild/core';
2
- import { o as ValOpsMemory, M as bytesToBase64, F as ValServer, G as createValRequestHandler } from '../../dist/ValRouterCore-98eeccbe.esm.js';
2
+ import { o as ValOpsMemory, M as bytesToBase64, F as ValServer, G as createValRequestHandler } from '../../dist/ValRouterCore-f8afc4c6.esm.js';
3
3
  import '@valbuild/shared/internal';
4
4
  import 'zod';
5
5
  import 'zod-validation-error';
@@ -3606,7 +3606,7 @@ class ValOps {
3606
3606
  jsonValuesRecordKeys,
3607
3607
  insertValJsonEntry,
3608
3608
  removeValJsonEntry
3609
- } = await Promise.resolve().then(function () { return require('./publishKit-580f558a.cjs.prod.js'); });
3609
+ } = await Promise.resolve().then(function () { return require('./publishKit-a3533ffe.cjs.prod.js'); });
3610
3610
  const {
3611
3611
  patchesByModule,
3612
3612
  fileLastUpdatedByPatchId
@@ -5509,7 +5509,7 @@ var packageJson = {
5509
5509
  ],
5510
5510
  exports: true
5511
5511
  },
5512
- version: "0.150.19",
5512
+ version: "0.150.21",
5513
5513
  scripts: {
5514
5514
  typecheck: "tsc --noEmit",
5515
5515
  test: "jest",
@@ -9695,7 +9695,7 @@ const ValServer = (valModules, options, callbacks, platform) => {
9695
9695
  // TypeScript compiler. See `patch/ts/publishKit.ts`.
9696
9696
  const {
9697
9697
  getJsonEntryAtCommit
9698
- } = await Promise.resolve().then(function () { return require('./getJsonEntryAtCommit-4e6661b7.cjs.prod.js'); });
9698
+ } = await Promise.resolve().then(function () { return require('./getJsonEntryAtCommit-18cac885.cjs.prod.js'); });
9699
9699
  const res = await getJsonEntryAtCommit(serverOps, req.query.commit_sha, req.query.path, req.query.key);
9700
9700
  if (fp.result.isErr(res)) {
9701
9701
  return historyErrorResponse(res.error);
@@ -3606,7 +3606,7 @@ class ValOps {
3606
3606
  jsonValuesRecordKeys,
3607
3607
  insertValJsonEntry,
3608
3608
  removeValJsonEntry
3609
- } = await Promise.resolve().then(function () { return require('./publishKit-5865095c.cjs.dev.js'); });
3609
+ } = await Promise.resolve().then(function () { return require('./publishKit-3c7f44cb.cjs.dev.js'); });
3610
3610
  const {
3611
3611
  patchesByModule,
3612
3612
  fileLastUpdatedByPatchId
@@ -5509,7 +5509,7 @@ var packageJson = {
5509
5509
  ],
5510
5510
  exports: true
5511
5511
  },
5512
- version: "0.150.19",
5512
+ version: "0.150.21",
5513
5513
  scripts: {
5514
5514
  typecheck: "tsc --noEmit",
5515
5515
  test: "jest",
@@ -9695,7 +9695,7 @@ const ValServer = (valModules, options, callbacks, platform) => {
9695
9695
  // TypeScript compiler. See `patch/ts/publishKit.ts`.
9696
9696
  const {
9697
9697
  getJsonEntryAtCommit
9698
- } = await Promise.resolve().then(function () { return require('./getJsonEntryAtCommit-3f0fa4eb.cjs.dev.js'); });
9698
+ } = await Promise.resolve().then(function () { return require('./getJsonEntryAtCommit-3907580e.cjs.dev.js'); });
9699
9699
  const res = await getJsonEntryAtCommit(serverOps, req.query.commit_sha, req.query.path, req.query.key);
9700
9700
  if (fp.result.isErr(res)) {
9701
9701
  return historyErrorResponse(res.error);
@@ -3600,7 +3600,7 @@ class ValOps {
3600
3600
  jsonValuesRecordKeys,
3601
3601
  insertValJsonEntry,
3602
3602
  removeValJsonEntry
3603
- } = await import('./publishKit-bc8df53d.esm.js');
3603
+ } = await import('./publishKit-bc7c9a0c.esm.js');
3604
3604
  const {
3605
3605
  patchesByModule,
3606
3606
  fileLastUpdatedByPatchId
@@ -5503,7 +5503,7 @@ var packageJson = {
5503
5503
  ],
5504
5504
  exports: true
5505
5505
  },
5506
- version: "0.150.19",
5506
+ version: "0.150.21",
5507
5507
  scripts: {
5508
5508
  typecheck: "tsc --noEmit",
5509
5509
  test: "jest",
@@ -9689,7 +9689,7 @@ const ValServer = (valModules, options, callbacks, platform) => {
9689
9689
  // TypeScript compiler. See `patch/ts/publishKit.ts`.
9690
9690
  const {
9691
9691
  getJsonEntryAtCommit
9692
- } = await import('./getJsonEntryAtCommit-4c2e4b5c.esm.js');
9692
+ } = await import('./getJsonEntryAtCommit-5718bbed.esm.js');
9693
9693
  const res = await getJsonEntryAtCommit(serverOps, req.query.commit_sha, req.query.path, req.query.key);
9694
9694
  if (result.isErr(res)) {
9695
9695
  return historyErrorResponse(res.error);
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  var ts = require('typescript');
4
- var ValRouterCore = require('./ValRouterCore-080665a2.cjs.prod.js');
4
+ var ValRouterCore = require('./ValRouterCore-499077da.cjs.prod.js');
5
5
  var fp = require('@valbuild/core/fp');
6
6
  var jsonValuesModule = require('./jsonValuesModule-d1bb8d8f.cjs.prod.js');
7
7
  require('@valbuild/core');
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  var ts = require('typescript');
4
- var ValRouterCore = require('./ValRouterCore-de8f4917.cjs.dev.js');
4
+ var ValRouterCore = require('./ValRouterCore-d37b85cf.cjs.dev.js');
5
5
  var fp = require('@valbuild/core/fp');
6
6
  var jsonValuesModule = require('./jsonValuesModule-8ae503a8.cjs.dev.js');
7
7
  require('@valbuild/core');
@@ -1,5 +1,5 @@
1
1
  import ts from 'typescript';
2
- import { N as bytesToUtf8, O as posixPath } from './ValRouterCore-98eeccbe.esm.js';
2
+ import { N as bytesToUtf8, O as posixPath } from './ValRouterCore-f8afc4c6.esm.js';
3
3
  import { result } from '@valbuild/core/fp';
4
4
  import { a as analyzeValModule, c as analyzeJsonValuesEntries } from './jsonValuesModule-427d68c8.esm.js';
5
5
  import '@valbuild/core';
@@ -1,5 +1,5 @@
1
1
  import ts from 'typescript';
2
- import { pipe, result } from '@valbuild/core/fp';
2
+ import { result, pipe } from '@valbuild/core/fp';
3
3
 
4
4
  class ValSyntaxError {
5
5
  constructor(message, node) {
@@ -36,6 +36,7 @@ exports.insertValJsonEntry = ops.insertValJsonEntry;
36
36
  exports.removeValJsonEntry = ops.removeValJsonEntry;
37
37
  exports.analyzeJsonValuesEntries = jsonValuesModule.analyzeJsonValuesEntries;
38
38
  exports.analyzeValModule = jsonValuesModule.analyzeValModule;
39
+ exports.evaluateExpression = jsonValuesModule.evaluateExpression;
39
40
  exports.jsonValuesRecordKeys = jsonValuesModule.jsonValuesRecordKeys;
40
41
  exports.parseValFile = parseValFile;
41
42
  exports.tsOps = tsOps;
@@ -36,6 +36,7 @@ exports.insertValJsonEntry = ops.insertValJsonEntry;
36
36
  exports.removeValJsonEntry = ops.removeValJsonEntry;
37
37
  exports.analyzeJsonValuesEntries = jsonValuesModule.analyzeJsonValuesEntries;
38
38
  exports.analyzeValModule = jsonValuesModule.analyzeValModule;
39
+ exports.evaluateExpression = jsonValuesModule.evaluateExpression;
39
40
  exports.jsonValuesRecordKeys = jsonValuesModule.jsonValuesRecordKeys;
40
41
  exports.parseValFile = parseValFile;
41
42
  exports.tsOps = tsOps;
@@ -3,7 +3,7 @@ import { pipe, result } from '@valbuild/core/fp';
3
3
  import { T as TSOps } from './ops-0d05feaf.esm.js';
4
4
  export { i as insertValJsonEntry, r as removeValJsonEntry } from './ops-0d05feaf.esm.js';
5
5
  import { a as analyzeValModule } from './jsonValuesModule-427d68c8.esm.js';
6
- export { c as analyzeJsonValuesEntries, a as analyzeValModule, j as jsonValuesRecordKeys } from './jsonValuesModule-427d68c8.esm.js';
6
+ export { c as analyzeJsonValuesEntries, a as analyzeValModule, g as evaluateExpression, j as jsonValuesRecordKeys } from './jsonValuesModule-427d68c8.esm.js';
7
7
  import '@valbuild/core/patch';
8
8
 
9
9
  /**
@@ -12,7 +12,7 @@ var path = require('path');
12
12
  var fs = require('fs');
13
13
  var vm = require('node:vm');
14
14
  var node_module = require('node:module');
15
- var ValRouterCore = require('./ValRouterCore-de8f4917.cjs.dev.js');
15
+ var ValRouterCore = require('./ValRouterCore-d37b85cf.cjs.dev.js');
16
16
  var server = require('@valbuild/ui/server');
17
17
  var z = require('zod');
18
18
  var zodValidationError = require('zod-validation-error');
@@ -5083,7 +5083,7 @@ async function patchModuleText(text, patch$1) {
5083
5083
  const {
5084
5084
  tsOps,
5085
5085
  parseValFile
5086
- } = await Promise.resolve().then(function () { return require('./publishKit-5865095c.cjs.dev.js'); });
5086
+ } = await Promise.resolve().then(function () { return require('./publishKit-3c7f44cb.cjs.dev.js'); });
5087
5087
  const applied = patch.applyPatch(parseValFile(text), tsOps, patch$1);
5088
5088
  if (fp.result.isErr(applied)) {
5089
5089
  const reason = messagesOf(applied.error).join(" ");
@@ -5104,6 +5104,55 @@ function messagesOf(error) {
5104
5104
  return Array.isArray(error) ? error.flatMap(messagesOf) : [error.message];
5105
5105
  }
5106
5106
 
5107
+ /**
5108
+ * The Source each staged module file declares, read from its text: what a
5109
+ * staging sends content beside the files (`POST /proposals/:name/files`,
5110
+ * `modules`), so the proposal's Source moves with its code.
5111
+ *
5112
+ * A proposal's address serves a module's Source from what the proposal has
5113
+ * SAVED, over the site's, over the build -- never from the text. A save writes
5114
+ * both, so they agree. A staging wrote only the text, so after the design
5115
+ * tab's `create_patch` added a button to a module, its text and its build had
5116
+ * the button and the Source the server served and saved did not. The Studio,
5117
+ * lined up with that Source, could not apply an edit into the new button: the
5118
+ * canvas showed it, and then it was gone.
5119
+ *
5120
+ * Only what can be read without running anything: a `c.define(...)` whose
5121
+ * Source is a literal. Anything else -- a `.jsonValues()` module, a Source
5122
+ * built by code, a file of shared schemas -- is left out, and content keeps
5123
+ * the Source it has for it, as before this existed.
5124
+ */
5125
+ async function stagedModuleSources(files) {
5126
+ const modules = Object.entries(files).flatMap(([path, text]) => text !== null && /\.val\.(ts|js)$/.test(path) ? [{
5127
+ path,
5128
+ text
5129
+ }] : []);
5130
+ if (modules.length === 0) return {};
5131
+ // The compiler, loaded when a staging asks for it, as a save loads it.
5132
+ const {
5133
+ parseValFile,
5134
+ analyzeValModule,
5135
+ evaluateExpression
5136
+ } = await Promise.resolve().then(function () { return require('./publishKit-3c7f44cb.cjs.dev.js'); });
5137
+ const sources = {};
5138
+ for (const {
5139
+ path,
5140
+ text
5141
+ } of modules) {
5142
+ try {
5143
+ const analysis = analyzeValModule(parseValFile(text));
5144
+ if (fp.result.isErr(analysis)) continue;
5145
+ const source = evaluateExpression(analysis.value.source);
5146
+ if (fp.result.isErr(source)) continue;
5147
+ sources[`/${path.replace(/^\/+/, "")}`] = source.value;
5148
+ } catch {
5149
+ // No `c.define` at all (`analyzeValModule` throws): code, not a module.
5150
+ continue;
5151
+ }
5152
+ }
5153
+ return sources;
5154
+ }
5155
+
5107
5156
  /**
5108
5157
  * Which of the site's pending changes a merge of a proposal moves into
5109
5158
  * proposals of their own (valbuild/home `docs/hosted-publishing.md`, step 8.2,
@@ -5335,6 +5384,35 @@ const PatchFileBody = z.z.object({
5335
5384
  message: z.z.string().max(500).optional()
5336
5385
  });
5337
5386
 
5387
+ /** A staging's body, as `write_files` sends it. */
5388
+ const StageFilesBody = z.z.object({
5389
+ files: z.z.record(z.z.string(), z.z.string().nullable())
5390
+ });
5391
+
5392
+ /**
5393
+ * A staging's body with the Source its module files declare added
5394
+ * (`stagedModuleSources`). A body this does not read goes as it came: content
5395
+ * answers it.
5396
+ */
5397
+ async function withStagedModuleSources(body) {
5398
+ let parsed;
5399
+ try {
5400
+ parsed = JSON.parse(body);
5401
+ } catch {
5402
+ return body;
5403
+ }
5404
+ const request = StageFilesBody.safeParse(parsed);
5405
+ if (!request.success || typeof parsed !== "object" || parsed === null) {
5406
+ return body;
5407
+ }
5408
+ const modules = await stagedModuleSources(request.data.files);
5409
+ if (Object.keys(modules).length === 0) return body;
5410
+ return JSON.stringify({
5411
+ ...parsed,
5412
+ modules
5413
+ });
5414
+ }
5415
+
5338
5416
  /** What `patchFileInProposal` reads of content's answer for a proposal's files. */
5339
5417
  const ProposalFilesRead = z.z.object({
5340
5418
  files: z.z.record(z.z.string(), z.z.string().nullable())
@@ -6223,6 +6301,8 @@ class ValOpsHttp extends ValRouterCore.ValOps {
6223
6301
  })
6224
6302
  };
6225
6303
  }
6304
+ // Staged module files go with the Source they declare.
6305
+ const body = (writes === null || writes === void 0 ? void 0 : writes.write) === "files" && init.body !== undefined ? await withStagedModuleSources(init.body) : init.body;
6226
6306
  const res = await fetch(`${this.contentUrl}/v1/${this.project}/proposals${path}`, {
6227
6307
  method: init.method,
6228
6308
  headers: {
@@ -6235,12 +6315,12 @@ class ValOpsHttp extends ValRouterCore.ValOps {
6235
6315
  ...(profileId !== null ? {
6236
6316
  "x-val-profile-id": profileId
6237
6317
  } : {}),
6238
- ...(init.body === undefined ? {} : {
6318
+ ...(body === undefined ? {} : {
6239
6319
  "Content-Type": json
6240
6320
  })
6241
6321
  },
6242
- ...(init.body === undefined ? {} : {
6243
- body: init.body
6322
+ ...(body === undefined ? {} : {
6323
+ body
6244
6324
  })
6245
6325
  });
6246
6326
  return {
@@ -6347,12 +6427,18 @@ class ValOpsHttp extends ValRouterCore.ValOps {
6347
6427
  });
6348
6428
  }
6349
6429
  }
6430
+ const staging = {
6431
+ [filePath]: formatted
6432
+ };
6433
+ const modules = await stagedModuleSources(staging);
6350
6434
  const staged = await content("/files", {
6351
6435
  method: "POST",
6352
6436
  body: JSON.stringify({
6353
- files: {
6354
- [filePath]: formatted
6355
- },
6437
+ files: staging,
6438
+ // The Source the patched text declares: see `stagedModuleSources`.
6439
+ ...(Object.keys(modules).length > 0 ? {
6440
+ modules
6441
+ } : {}),
6356
6442
  ...(message !== undefined ? {
6357
6443
  message
6358
6444
  } : {})
@@ -12,7 +12,7 @@ var path = require('path');
12
12
  var fs = require('fs');
13
13
  var vm = require('node:vm');
14
14
  var node_module = require('node:module');
15
- var ValRouterCore = require('./ValRouterCore-080665a2.cjs.prod.js');
15
+ var ValRouterCore = require('./ValRouterCore-499077da.cjs.prod.js');
16
16
  var server = require('@valbuild/ui/server');
17
17
  var z = require('zod');
18
18
  var zodValidationError = require('zod-validation-error');
@@ -5083,7 +5083,7 @@ async function patchModuleText(text, patch$1) {
5083
5083
  const {
5084
5084
  tsOps,
5085
5085
  parseValFile
5086
- } = await Promise.resolve().then(function () { return require('./publishKit-580f558a.cjs.prod.js'); });
5086
+ } = await Promise.resolve().then(function () { return require('./publishKit-a3533ffe.cjs.prod.js'); });
5087
5087
  const applied = patch.applyPatch(parseValFile(text), tsOps, patch$1);
5088
5088
  if (fp.result.isErr(applied)) {
5089
5089
  const reason = messagesOf(applied.error).join(" ");
@@ -5104,6 +5104,55 @@ function messagesOf(error) {
5104
5104
  return Array.isArray(error) ? error.flatMap(messagesOf) : [error.message];
5105
5105
  }
5106
5106
 
5107
+ /**
5108
+ * The Source each staged module file declares, read from its text: what a
5109
+ * staging sends content beside the files (`POST /proposals/:name/files`,
5110
+ * `modules`), so the proposal's Source moves with its code.
5111
+ *
5112
+ * A proposal's address serves a module's Source from what the proposal has
5113
+ * SAVED, over the site's, over the build -- never from the text. A save writes
5114
+ * both, so they agree. A staging wrote only the text, so after the design
5115
+ * tab's `create_patch` added a button to a module, its text and its build had
5116
+ * the button and the Source the server served and saved did not. The Studio,
5117
+ * lined up with that Source, could not apply an edit into the new button: the
5118
+ * canvas showed it, and then it was gone.
5119
+ *
5120
+ * Only what can be read without running anything: a `c.define(...)` whose
5121
+ * Source is a literal. Anything else -- a `.jsonValues()` module, a Source
5122
+ * built by code, a file of shared schemas -- is left out, and content keeps
5123
+ * the Source it has for it, as before this existed.
5124
+ */
5125
+ async function stagedModuleSources(files) {
5126
+ const modules = Object.entries(files).flatMap(([path, text]) => text !== null && /\.val\.(ts|js)$/.test(path) ? [{
5127
+ path,
5128
+ text
5129
+ }] : []);
5130
+ if (modules.length === 0) return {};
5131
+ // The compiler, loaded when a staging asks for it, as a save loads it.
5132
+ const {
5133
+ parseValFile,
5134
+ analyzeValModule,
5135
+ evaluateExpression
5136
+ } = await Promise.resolve().then(function () { return require('./publishKit-a3533ffe.cjs.prod.js'); });
5137
+ const sources = {};
5138
+ for (const {
5139
+ path,
5140
+ text
5141
+ } of modules) {
5142
+ try {
5143
+ const analysis = analyzeValModule(parseValFile(text));
5144
+ if (fp.result.isErr(analysis)) continue;
5145
+ const source = evaluateExpression(analysis.value.source);
5146
+ if (fp.result.isErr(source)) continue;
5147
+ sources[`/${path.replace(/^\/+/, "")}`] = source.value;
5148
+ } catch {
5149
+ // No `c.define` at all (`analyzeValModule` throws): code, not a module.
5150
+ continue;
5151
+ }
5152
+ }
5153
+ return sources;
5154
+ }
5155
+
5107
5156
  /**
5108
5157
  * Which of the site's pending changes a merge of a proposal moves into
5109
5158
  * proposals of their own (valbuild/home `docs/hosted-publishing.md`, step 8.2,
@@ -5335,6 +5384,35 @@ const PatchFileBody = z.z.object({
5335
5384
  message: z.z.string().max(500).optional()
5336
5385
  });
5337
5386
 
5387
+ /** A staging's body, as `write_files` sends it. */
5388
+ const StageFilesBody = z.z.object({
5389
+ files: z.z.record(z.z.string(), z.z.string().nullable())
5390
+ });
5391
+
5392
+ /**
5393
+ * A staging's body with the Source its module files declare added
5394
+ * (`stagedModuleSources`). A body this does not read goes as it came: content
5395
+ * answers it.
5396
+ */
5397
+ async function withStagedModuleSources(body) {
5398
+ let parsed;
5399
+ try {
5400
+ parsed = JSON.parse(body);
5401
+ } catch {
5402
+ return body;
5403
+ }
5404
+ const request = StageFilesBody.safeParse(parsed);
5405
+ if (!request.success || typeof parsed !== "object" || parsed === null) {
5406
+ return body;
5407
+ }
5408
+ const modules = await stagedModuleSources(request.data.files);
5409
+ if (Object.keys(modules).length === 0) return body;
5410
+ return JSON.stringify({
5411
+ ...parsed,
5412
+ modules
5413
+ });
5414
+ }
5415
+
5338
5416
  /** What `patchFileInProposal` reads of content's answer for a proposal's files. */
5339
5417
  const ProposalFilesRead = z.z.object({
5340
5418
  files: z.z.record(z.z.string(), z.z.string().nullable())
@@ -6223,6 +6301,8 @@ class ValOpsHttp extends ValRouterCore.ValOps {
6223
6301
  })
6224
6302
  };
6225
6303
  }
6304
+ // Staged module files go with the Source they declare.
6305
+ const body = (writes === null || writes === void 0 ? void 0 : writes.write) === "files" && init.body !== undefined ? await withStagedModuleSources(init.body) : init.body;
6226
6306
  const res = await fetch(`${this.contentUrl}/v1/${this.project}/proposals${path}`, {
6227
6307
  method: init.method,
6228
6308
  headers: {
@@ -6235,12 +6315,12 @@ class ValOpsHttp extends ValRouterCore.ValOps {
6235
6315
  ...(profileId !== null ? {
6236
6316
  "x-val-profile-id": profileId
6237
6317
  } : {}),
6238
- ...(init.body === undefined ? {} : {
6318
+ ...(body === undefined ? {} : {
6239
6319
  "Content-Type": json
6240
6320
  })
6241
6321
  },
6242
- ...(init.body === undefined ? {} : {
6243
- body: init.body
6322
+ ...(body === undefined ? {} : {
6323
+ body
6244
6324
  })
6245
6325
  });
6246
6326
  return {
@@ -6347,12 +6427,18 @@ class ValOpsHttp extends ValRouterCore.ValOps {
6347
6427
  });
6348
6428
  }
6349
6429
  }
6430
+ const staging = {
6431
+ [filePath]: formatted
6432
+ };
6433
+ const modules = await stagedModuleSources(staging);
6350
6434
  const staged = await content("/files", {
6351
6435
  method: "POST",
6352
6436
  body: JSON.stringify({
6353
- files: {
6354
- [filePath]: formatted
6355
- },
6437
+ files: staging,
6438
+ // The Source the patched text declares: see `stagedModuleSources`.
6439
+ ...(Object.keys(modules).length > 0 ? {
6440
+ modules
6441
+ } : {}),
6356
6442
  ...(message !== undefined ? {
6357
6443
  message
6358
6444
  } : {})
@@ -10,8 +10,8 @@ import path from 'path';
10
10
  import fs from 'fs';
11
11
  import vm from 'node:vm';
12
12
  import { Module } from 'node:module';
13
- import { r as resolveExistingJsonPath, f as findNestedJsonValuesRecords, v as validateJsonValuesEntries, i as isJsonValuesRootOp, a as rebaseContentOp, c as classifyJsonValuesOp, s as summaryOf, m as matchesFilter, b as byUpdatedAt, n as newSketchpad, d as isSketchpadId, e as applySketchpadChange, V as ValOps, g as bufferFromDataUrl, h as getFieldsForType, u as uploadRemoteFile, j as getFileExt, k as guessMimeTypeFromPath, l as createMetadataFromBuffer, D as DEFAULT_ANALYTICS_INGEST_URL, o as ValOpsMemory, p as isHlsMasterPlaylist, q as sumHlsSegmentDurations, t as parseHlsMasterVariants, w as largestHlsVariant, x as fallbackRefOf, y as mapHlsUris, z as movedRemoteHost, A as needsHostCheck, B as rewriteRefHost, C as fallbackRemoteHost, E as checkRemoteFiles, F as ValServer, G as createValRequestHandler, H as getNewJsonEntryPaths, I as formatPatchSourceError } from './ValRouterCore-98eeccbe.esm.js';
14
- export { L as InMemoryPatchStore, o as ValOpsMemory, J as askOncePerHost, c as classifyJsonValuesOp, I as formatPatchSourceError, j as getFileExt, K as getSettings, a as rebaseContentOp, u as uploadRemoteFile } from './ValRouterCore-98eeccbe.esm.js';
13
+ import { r as resolveExistingJsonPath, f as findNestedJsonValuesRecords, v as validateJsonValuesEntries, i as isJsonValuesRootOp, a as rebaseContentOp, c as classifyJsonValuesOp, s as summaryOf, m as matchesFilter, b as byUpdatedAt, n as newSketchpad, d as isSketchpadId, e as applySketchpadChange, V as ValOps, g as bufferFromDataUrl, h as getFieldsForType, u as uploadRemoteFile, j as getFileExt, k as guessMimeTypeFromPath, l as createMetadataFromBuffer, D as DEFAULT_ANALYTICS_INGEST_URL, o as ValOpsMemory, p as isHlsMasterPlaylist, q as sumHlsSegmentDurations, t as parseHlsMasterVariants, w as largestHlsVariant, x as fallbackRefOf, y as mapHlsUris, z as movedRemoteHost, A as needsHostCheck, B as rewriteRefHost, C as fallbackRemoteHost, E as checkRemoteFiles, F as ValServer, G as createValRequestHandler, H as getNewJsonEntryPaths, I as formatPatchSourceError } from './ValRouterCore-f8afc4c6.esm.js';
14
+ export { L as InMemoryPatchStore, o as ValOpsMemory, J as askOncePerHost, c as classifyJsonValuesOp, I as formatPatchSourceError, j as getFileExt, K as getSettings, a as rebaseContentOp, u as uploadRemoteFile } from './ValRouterCore-f8afc4c6.esm.js';
15
15
  import { createUIRequestHandler } from '@valbuild/ui/server';
16
16
  import z$1, { z } from 'zod';
17
17
  import { fromError } from 'zod-validation-error';
@@ -5047,7 +5047,7 @@ async function patchModuleText(text, patch) {
5047
5047
  const {
5048
5048
  tsOps,
5049
5049
  parseValFile
5050
- } = await import('./publishKit-bc8df53d.esm.js');
5050
+ } = await import('./publishKit-bc7c9a0c.esm.js');
5051
5051
  const applied = applyPatch(parseValFile(text), tsOps, patch);
5052
5052
  if (result.isErr(applied)) {
5053
5053
  const reason = messagesOf(applied.error).join(" ");
@@ -5068,6 +5068,55 @@ function messagesOf(error) {
5068
5068
  return Array.isArray(error) ? error.flatMap(messagesOf) : [error.message];
5069
5069
  }
5070
5070
 
5071
+ /**
5072
+ * The Source each staged module file declares, read from its text: what a
5073
+ * staging sends content beside the files (`POST /proposals/:name/files`,
5074
+ * `modules`), so the proposal's Source moves with its code.
5075
+ *
5076
+ * A proposal's address serves a module's Source from what the proposal has
5077
+ * SAVED, over the site's, over the build -- never from the text. A save writes
5078
+ * both, so they agree. A staging wrote only the text, so after the design
5079
+ * tab's `create_patch` added a button to a module, its text and its build had
5080
+ * the button and the Source the server served and saved did not. The Studio,
5081
+ * lined up with that Source, could not apply an edit into the new button: the
5082
+ * canvas showed it, and then it was gone.
5083
+ *
5084
+ * Only what can be read without running anything: a `c.define(...)` whose
5085
+ * Source is a literal. Anything else -- a `.jsonValues()` module, a Source
5086
+ * built by code, a file of shared schemas -- is left out, and content keeps
5087
+ * the Source it has for it, as before this existed.
5088
+ */
5089
+ async function stagedModuleSources(files) {
5090
+ const modules = Object.entries(files).flatMap(([path, text]) => text !== null && /\.val\.(ts|js)$/.test(path) ? [{
5091
+ path,
5092
+ text
5093
+ }] : []);
5094
+ if (modules.length === 0) return {};
5095
+ // The compiler, loaded when a staging asks for it, as a save loads it.
5096
+ const {
5097
+ parseValFile,
5098
+ analyzeValModule,
5099
+ evaluateExpression
5100
+ } = await import('./publishKit-bc7c9a0c.esm.js');
5101
+ const sources = {};
5102
+ for (const {
5103
+ path,
5104
+ text
5105
+ } of modules) {
5106
+ try {
5107
+ const analysis = analyzeValModule(parseValFile(text));
5108
+ if (result.isErr(analysis)) continue;
5109
+ const source = evaluateExpression(analysis.value.source);
5110
+ if (result.isErr(source)) continue;
5111
+ sources[`/${path.replace(/^\/+/, "")}`] = source.value;
5112
+ } catch {
5113
+ // No `c.define` at all (`analyzeValModule` throws): code, not a module.
5114
+ continue;
5115
+ }
5116
+ }
5117
+ return sources;
5118
+ }
5119
+
5071
5120
  /**
5072
5121
  * Which of the site's pending changes a merge of a proposal moves into
5073
5122
  * proposals of their own (valbuild/home `docs/hosted-publishing.md`, step 8.2,
@@ -5299,6 +5348,35 @@ const PatchFileBody = z.object({
5299
5348
  message: z.string().max(500).optional()
5300
5349
  });
5301
5350
 
5351
+ /** A staging's body, as `write_files` sends it. */
5352
+ const StageFilesBody = z.object({
5353
+ files: z.record(z.string(), z.string().nullable())
5354
+ });
5355
+
5356
+ /**
5357
+ * A staging's body with the Source its module files declare added
5358
+ * (`stagedModuleSources`). A body this does not read goes as it came: content
5359
+ * answers it.
5360
+ */
5361
+ async function withStagedModuleSources(body) {
5362
+ let parsed;
5363
+ try {
5364
+ parsed = JSON.parse(body);
5365
+ } catch {
5366
+ return body;
5367
+ }
5368
+ const request = StageFilesBody.safeParse(parsed);
5369
+ if (!request.success || typeof parsed !== "object" || parsed === null) {
5370
+ return body;
5371
+ }
5372
+ const modules = await stagedModuleSources(request.data.files);
5373
+ if (Object.keys(modules).length === 0) return body;
5374
+ return JSON.stringify({
5375
+ ...parsed,
5376
+ modules
5377
+ });
5378
+ }
5379
+
5302
5380
  /** What `patchFileInProposal` reads of content's answer for a proposal's files. */
5303
5381
  const ProposalFilesRead = z.object({
5304
5382
  files: z.record(z.string(), z.string().nullable())
@@ -6187,6 +6265,8 @@ class ValOpsHttp extends ValOps {
6187
6265
  })
6188
6266
  };
6189
6267
  }
6268
+ // Staged module files go with the Source they declare.
6269
+ const body = (writes === null || writes === void 0 ? void 0 : writes.write) === "files" && init.body !== undefined ? await withStagedModuleSources(init.body) : init.body;
6190
6270
  const res = await fetch(`${this.contentUrl}/v1/${this.project}/proposals${path}`, {
6191
6271
  method: init.method,
6192
6272
  headers: {
@@ -6199,12 +6279,12 @@ class ValOpsHttp extends ValOps {
6199
6279
  ...(profileId !== null ? {
6200
6280
  "x-val-profile-id": profileId
6201
6281
  } : {}),
6202
- ...(init.body === undefined ? {} : {
6282
+ ...(body === undefined ? {} : {
6203
6283
  "Content-Type": json
6204
6284
  })
6205
6285
  },
6206
- ...(init.body === undefined ? {} : {
6207
- body: init.body
6286
+ ...(body === undefined ? {} : {
6287
+ body
6208
6288
  })
6209
6289
  });
6210
6290
  return {
@@ -6311,12 +6391,18 @@ class ValOpsHttp extends ValOps {
6311
6391
  });
6312
6392
  }
6313
6393
  }
6394
+ const staging = {
6395
+ [filePath]: formatted
6396
+ };
6397
+ const modules = await stagedModuleSources(staging);
6314
6398
  const staged = await content("/files", {
6315
6399
  method: "POST",
6316
6400
  body: JSON.stringify({
6317
- files: {
6318
- [filePath]: formatted
6319
- },
6401
+ files: staging,
6402
+ // The Source the patched text declares: see `stagedModuleSources`.
6403
+ ...(Object.keys(modules).length > 0 ? {
6404
+ modules
6405
+ } : {}),
6320
6406
  ...(message !== undefined ? {
6321
6407
  message
6322
6408
  } : {})
package/package.json CHANGED
@@ -27,7 +27,7 @@
27
27
  ],
28
28
  "exports": true
29
29
  },
30
- "version": "0.150.19",
30
+ "version": "0.150.21",
31
31
  "devDependencies": {
32
32
  "@prettier/sync": "^0.6.1",
33
33
  "@types/jest": "^30.0.0",
@@ -41,9 +41,9 @@
41
41
  "typescript": "^6.0.3",
42
42
  "zod": "^4.4.3",
43
43
  "zod-validation-error": "^5.0.0",
44
- "@valbuild/shared": "0.150.18",
45
- "@valbuild/ui": "0.150.19",
46
- "@valbuild/core": "0.150.3"
44
+ "@valbuild/core": "0.150.3",
45
+ "@valbuild/ui": "0.150.21",
46
+ "@valbuild/shared": "0.150.20"
47
47
  },
48
48
  "engines": {
49
49
  "node": "^20.19.0 || >=22"