@valbuild/server 0.136.1 → 0.136.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,20 @@
1
1
  # @valbuild/server
2
2
 
3
+ ## 0.136.2
4
+
5
+ ### Patch Changes
6
+
7
+ - [#720](https://github.com/valbuild/val/pull/720) [`f76cd56`](https://github.com/valbuild/val/commit/f76cd56b9f1c1bcc0a608a7a4de24b1e776adccb) Thanks [@freekh](https://github.com/freekh)! - A managed project published from the Studio keeps its images, and a project created from a template can publish from the Studio at all.
8
+
9
+ - A publish from the Studio carries over every file under `public/` that the site already serves, so the favicon and images no longer disappear after the first Studio publish. When content published the live build, it already holds those files and nothing is uploaded again. When it didn't (a project cloned from a template), the Studio reads them from the site it runs on and builds with them.
10
+ - An image uploaded in the Studio is now part of the build that publishes it. For a managed project, `/save` returns the files the commit wrote (`binaryFiles`), the same way it already returns the `.val.ts` text.
11
+ - `/save` also returns the project's branch for a managed project, and the Studio's build uses it. A project cloned from a template was wired at no commit and no branch, so its first Studio publish went out branchless and the platform refused it.
12
+ - When neither content nor the platform can say which public files the live site serves, the Studio refuses to publish and says so, rather than publishing a site without them.
13
+
14
+ - Updated dependencies [[`f76cd56`](https://github.com/valbuild/val/commit/f76cd56b9f1c1bcc0a608a7a4de24b1e776adccb)]:
15
+ - @valbuild/ui@0.136.2
16
+ - @valbuild/shared@0.136.2
17
+
3
18
  ## 0.136.1
4
19
 
5
20
  ### Patch Changes
@@ -433,6 +433,18 @@ export declare abstract class ValOps {
433
433
  * an older service.
434
434
  */
435
435
  sourceMode(): "managed" | "connected" | null;
436
+ /**
437
+ * The branch the content service keeps this project's commits on, or `null`
438
+ * where there is no such service, or it has not said yet.
439
+ *
440
+ * For the Studio's in-tab build of a managed project, which has to name the
441
+ * branch its build was made at. Its other source is the `val.server.ts` the
442
+ * last build was wired with -- and a project cloned from a template seed has
443
+ * one wired at NO commit and no branch, so its first publish went out
444
+ * branchless and the loader refused it for a project whose pointer follows a
445
+ * branch. This is the project's own word for it.
446
+ */
447
+ projectBranch(): string | null;
436
448
  /**
437
449
  * Forward one call to the content service's publish API, as this project.
438
450
  *
@@ -141,6 +141,8 @@ export declare class ValOpsHttp extends ValOps {
141
141
  * has just arrived.
142
142
  */
143
143
  sourceMode(): "managed" | "connected" | null;
144
+ /** Remembered with {@link sourceMode}, from the same response. */
145
+ projectBranch(): string | null;
144
146
  /**
145
147
  * The short-lived publish token, and when it stops being usable.
146
148
  *
@@ -4595,6 +4595,21 @@ class ValOps {
4595
4595
  return null;
4596
4596
  }
4597
4597
 
4598
+ /**
4599
+ * The branch the content service keeps this project's commits on, or `null`
4600
+ * where there is no such service, or it has not said yet.
4601
+ *
4602
+ * For the Studio's in-tab build of a managed project, which has to name the
4603
+ * branch its build was made at. Its other source is the `val.server.ts` the
4604
+ * last build was wired with -- and a project cloned from a template seed has
4605
+ * one wired at NO commit and no branch, so its first publish went out
4606
+ * branchless and the loader refused it for a project whose pointer follows a
4607
+ * branch. This is the project's own word for it.
4608
+ */
4609
+ projectBranch() {
4610
+ return null;
4611
+ }
4612
+
4598
4613
  /**
4599
4614
  * Forward one call to the content service's publish API, as this project.
4600
4615
  *
@@ -7519,6 +7534,42 @@ class FSOpsHost {
7519
7534
  }
7520
7535
  }
7521
7536
 
7537
+ /**
7538
+ * The bytes of the local binary files a commit is about to write, base64.
7539
+ *
7540
+ * For the Studio's in-tab build of a managed project, which publishes the site:
7541
+ * an image uploaded in this save is in no earlier build, so unless the build
7542
+ * is given it the published page links a file that 404s. Remote files are left
7543
+ * out -- they are served from their own URL and never were part of a build.
7544
+ *
7545
+ * A file that cannot be read is NAMED rather than dropped, and does not stop
7546
+ * the save: the commit is what makes an edit durable, and the build is the
7547
+ * step that can refuse.
7548
+ *
7549
+ * Read BEFORE the commit, because after it the files are no longer the
7550
+ * patch's to read. Generic over the patch id so it asks for exactly the one
7551
+ * method it uses, and a test can hand it a plain object.
7552
+ */
7553
+ async function readCommittedBinaryFiles(ops, descriptors) {
7554
+ const files = {};
7555
+ const unread = [];
7556
+ await Promise.all(Object.entries(descriptors).map(async ([filePath, {
7557
+ patchId,
7558
+ remote
7559
+ }]) => {
7560
+ if (remote) return;
7561
+ const bytes = await ops.getBase64EncodedBinaryFileFromPatch(filePath, patchId, remote).catch(error => {
7562
+ console.error("Could not read a committed file", filePath, error);
7563
+ return null;
7564
+ });
7565
+ if (bytes === null) unread.push(filePath);else files[filePath] = bytes.toString("base64");
7566
+ }));
7567
+ return {
7568
+ files,
7569
+ unread: unread.sort()
7570
+ };
7571
+ }
7572
+
7522
7573
  /**
7523
7574
  * Which unpublished changes a failed save has to throw away to make progress.
7524
7575
  *
@@ -8001,6 +8052,12 @@ class ValOpsHttp extends ValOps {
8001
8052
  return ((_this$projectExpectat2 = this.projectExpectation) === null || _this$projectExpectat2 === void 0 ? void 0 : _this$projectExpectat2.sourceMode) ?? null;
8002
8053
  }
8003
8054
 
8055
+ /** Remembered with {@link sourceMode}, from the same response. */
8056
+ projectBranch() {
8057
+ var _this$projectExpectat3;
8058
+ return ((_this$projectExpectat3 = this.projectExpectation) === null || _this$projectExpectat3 === void 0 ? void 0 : _this$projectExpectat3.branch) ?? null;
8059
+ }
8060
+
8004
8061
  /**
8005
8062
  * The short-lived publish token, and when it stops being usable.
8006
8063
  *
@@ -13757,6 +13814,12 @@ const ValServer = (valModules, options, callbacks) => {
13757
13814
  }
13758
13815
  }
13759
13816
  const message = body.message || "Val CMS update (" + Object.keys(analysis.patchesByModule).length + " files changed)";
13817
+ /*
13818
+ * Before the commit, because after it the files are no longer the
13819
+ * patch's to read. See `binaryFiles` on the route.
13820
+ */
13821
+ const managedBranch = serverOps.sourceMode() === "managed" ? serverOps.projectBranch() : null;
13822
+ const committedBinaries = serverOps.sourceMode() === "managed" ? await readCommittedBinaryFiles(serverOps, preparedCommit.patchedBinaryFilesDescriptors) : null;
13760
13823
  const commitToGit = () => {
13761
13824
  var _options$config$files;
13762
13825
  return serverOps.commit(preparedCommit, message, auth.id, ((_options$config$files = options.config.files) === null || _options$config$files === void 0 ? void 0 : _options$config$files.directory) || "/public/val", undefined,
@@ -13823,6 +13886,15 @@ const ValServer = (valModules, options, callbacks) => {
13823
13886
  */
13824
13887
  ...(serverOps.sourceMode() === "managed" ? {
13825
13888
  sourceFiles: preparedCommit.patchedSourceFiles
13889
+ } : {}),
13890
+ ...(managedBranch !== null ? {
13891
+ branch: managedBranch
13892
+ } : {}),
13893
+ ...(committedBinaries !== null ? {
13894
+ binaryFiles: committedBinaries.files,
13895
+ ...(committedBinaries.unread.length > 0 ? {
13896
+ binaryFilesUnread: committedBinaries.unread
13897
+ } : {})
13826
13898
  } : {})
13827
13899
  }
13828
13900
  };
@@ -4595,6 +4595,21 @@ class ValOps {
4595
4595
  return null;
4596
4596
  }
4597
4597
 
4598
+ /**
4599
+ * The branch the content service keeps this project's commits on, or `null`
4600
+ * where there is no such service, or it has not said yet.
4601
+ *
4602
+ * For the Studio's in-tab build of a managed project, which has to name the
4603
+ * branch its build was made at. Its other source is the `val.server.ts` the
4604
+ * last build was wired with -- and a project cloned from a template seed has
4605
+ * one wired at NO commit and no branch, so its first publish went out
4606
+ * branchless and the loader refused it for a project whose pointer follows a
4607
+ * branch. This is the project's own word for it.
4608
+ */
4609
+ projectBranch() {
4610
+ return null;
4611
+ }
4612
+
4598
4613
  /**
4599
4614
  * Forward one call to the content service's publish API, as this project.
4600
4615
  *
@@ -7519,6 +7534,42 @@ class FSOpsHost {
7519
7534
  }
7520
7535
  }
7521
7536
 
7537
+ /**
7538
+ * The bytes of the local binary files a commit is about to write, base64.
7539
+ *
7540
+ * For the Studio's in-tab build of a managed project, which publishes the site:
7541
+ * an image uploaded in this save is in no earlier build, so unless the build
7542
+ * is given it the published page links a file that 404s. Remote files are left
7543
+ * out -- they are served from their own URL and never were part of a build.
7544
+ *
7545
+ * A file that cannot be read is NAMED rather than dropped, and does not stop
7546
+ * the save: the commit is what makes an edit durable, and the build is the
7547
+ * step that can refuse.
7548
+ *
7549
+ * Read BEFORE the commit, because after it the files are no longer the
7550
+ * patch's to read. Generic over the patch id so it asks for exactly the one
7551
+ * method it uses, and a test can hand it a plain object.
7552
+ */
7553
+ async function readCommittedBinaryFiles(ops, descriptors) {
7554
+ const files = {};
7555
+ const unread = [];
7556
+ await Promise.all(Object.entries(descriptors).map(async ([filePath, {
7557
+ patchId,
7558
+ remote
7559
+ }]) => {
7560
+ if (remote) return;
7561
+ const bytes = await ops.getBase64EncodedBinaryFileFromPatch(filePath, patchId, remote).catch(error => {
7562
+ console.error("Could not read a committed file", filePath, error);
7563
+ return null;
7564
+ });
7565
+ if (bytes === null) unread.push(filePath);else files[filePath] = bytes.toString("base64");
7566
+ }));
7567
+ return {
7568
+ files,
7569
+ unread: unread.sort()
7570
+ };
7571
+ }
7572
+
7522
7573
  /**
7523
7574
  * Which unpublished changes a failed save has to throw away to make progress.
7524
7575
  *
@@ -8001,6 +8052,12 @@ class ValOpsHttp extends ValOps {
8001
8052
  return ((_this$projectExpectat2 = this.projectExpectation) === null || _this$projectExpectat2 === void 0 ? void 0 : _this$projectExpectat2.sourceMode) ?? null;
8002
8053
  }
8003
8054
 
8055
+ /** Remembered with {@link sourceMode}, from the same response. */
8056
+ projectBranch() {
8057
+ var _this$projectExpectat3;
8058
+ return ((_this$projectExpectat3 = this.projectExpectation) === null || _this$projectExpectat3 === void 0 ? void 0 : _this$projectExpectat3.branch) ?? null;
8059
+ }
8060
+
8004
8061
  /**
8005
8062
  * The short-lived publish token, and when it stops being usable.
8006
8063
  *
@@ -13757,6 +13814,12 @@ const ValServer = (valModules, options, callbacks) => {
13757
13814
  }
13758
13815
  }
13759
13816
  const message = body.message || "Val CMS update (" + Object.keys(analysis.patchesByModule).length + " files changed)";
13817
+ /*
13818
+ * Before the commit, because after it the files are no longer the
13819
+ * patch's to read. See `binaryFiles` on the route.
13820
+ */
13821
+ const managedBranch = serverOps.sourceMode() === "managed" ? serverOps.projectBranch() : null;
13822
+ const committedBinaries = serverOps.sourceMode() === "managed" ? await readCommittedBinaryFiles(serverOps, preparedCommit.patchedBinaryFilesDescriptors) : null;
13760
13823
  const commitToGit = () => {
13761
13824
  var _options$config$files;
13762
13825
  return serverOps.commit(preparedCommit, message, auth.id, ((_options$config$files = options.config.files) === null || _options$config$files === void 0 ? void 0 : _options$config$files.directory) || "/public/val", undefined,
@@ -13823,6 +13886,15 @@ const ValServer = (valModules, options, callbacks) => {
13823
13886
  */
13824
13887
  ...(serverOps.sourceMode() === "managed" ? {
13825
13888
  sourceFiles: preparedCommit.patchedSourceFiles
13889
+ } : {}),
13890
+ ...(managedBranch !== null ? {
13891
+ branch: managedBranch
13892
+ } : {}),
13893
+ ...(committedBinaries !== null ? {
13894
+ binaryFiles: committedBinaries.files,
13895
+ ...(committedBinaries.unread.length > 0 ? {
13896
+ binaryFilesUnread: committedBinaries.unread
13897
+ } : {})
13826
13898
  } : {})
13827
13899
  }
13828
13900
  };
@@ -4561,6 +4561,21 @@ class ValOps {
4561
4561
  return null;
4562
4562
  }
4563
4563
 
4564
+ /**
4565
+ * The branch the content service keeps this project's commits on, or `null`
4566
+ * where there is no such service, or it has not said yet.
4567
+ *
4568
+ * For the Studio's in-tab build of a managed project, which has to name the
4569
+ * branch its build was made at. Its other source is the `val.server.ts` the
4570
+ * last build was wired with -- and a project cloned from a template seed has
4571
+ * one wired at NO commit and no branch, so its first publish went out
4572
+ * branchless and the loader refused it for a project whose pointer follows a
4573
+ * branch. This is the project's own word for it.
4574
+ */
4575
+ projectBranch() {
4576
+ return null;
4577
+ }
4578
+
4564
4579
  /**
4565
4580
  * Forward one call to the content service's publish API, as this project.
4566
4581
  *
@@ -7485,6 +7500,42 @@ class FSOpsHost {
7485
7500
  }
7486
7501
  }
7487
7502
 
7503
+ /**
7504
+ * The bytes of the local binary files a commit is about to write, base64.
7505
+ *
7506
+ * For the Studio's in-tab build of a managed project, which publishes the site:
7507
+ * an image uploaded in this save is in no earlier build, so unless the build
7508
+ * is given it the published page links a file that 404s. Remote files are left
7509
+ * out -- they are served from their own URL and never were part of a build.
7510
+ *
7511
+ * A file that cannot be read is NAMED rather than dropped, and does not stop
7512
+ * the save: the commit is what makes an edit durable, and the build is the
7513
+ * step that can refuse.
7514
+ *
7515
+ * Read BEFORE the commit, because after it the files are no longer the
7516
+ * patch's to read. Generic over the patch id so it asks for exactly the one
7517
+ * method it uses, and a test can hand it a plain object.
7518
+ */
7519
+ async function readCommittedBinaryFiles(ops, descriptors) {
7520
+ const files = {};
7521
+ const unread = [];
7522
+ await Promise.all(Object.entries(descriptors).map(async ([filePath, {
7523
+ patchId,
7524
+ remote
7525
+ }]) => {
7526
+ if (remote) return;
7527
+ const bytes = await ops.getBase64EncodedBinaryFileFromPatch(filePath, patchId, remote).catch(error => {
7528
+ console.error("Could not read a committed file", filePath, error);
7529
+ return null;
7530
+ });
7531
+ if (bytes === null) unread.push(filePath);else files[filePath] = bytes.toString("base64");
7532
+ }));
7533
+ return {
7534
+ files,
7535
+ unread: unread.sort()
7536
+ };
7537
+ }
7538
+
7488
7539
  /**
7489
7540
  * Which unpublished changes a failed save has to throw away to make progress.
7490
7541
  *
@@ -7967,6 +8018,12 @@ class ValOpsHttp extends ValOps {
7967
8018
  return ((_this$projectExpectat2 = this.projectExpectation) === null || _this$projectExpectat2 === void 0 ? void 0 : _this$projectExpectat2.sourceMode) ?? null;
7968
8019
  }
7969
8020
 
8021
+ /** Remembered with {@link sourceMode}, from the same response. */
8022
+ projectBranch() {
8023
+ var _this$projectExpectat3;
8024
+ return ((_this$projectExpectat3 = this.projectExpectation) === null || _this$projectExpectat3 === void 0 ? void 0 : _this$projectExpectat3.branch) ?? null;
8025
+ }
8026
+
7970
8027
  /**
7971
8028
  * The short-lived publish token, and when it stops being usable.
7972
8029
  *
@@ -13723,6 +13780,12 @@ const ValServer = (valModules, options, callbacks) => {
13723
13780
  }
13724
13781
  }
13725
13782
  const message = body.message || "Val CMS update (" + Object.keys(analysis.patchesByModule).length + " files changed)";
13783
+ /*
13784
+ * Before the commit, because after it the files are no longer the
13785
+ * patch's to read. See `binaryFiles` on the route.
13786
+ */
13787
+ const managedBranch = serverOps.sourceMode() === "managed" ? serverOps.projectBranch() : null;
13788
+ const committedBinaries = serverOps.sourceMode() === "managed" ? await readCommittedBinaryFiles(serverOps, preparedCommit.patchedBinaryFilesDescriptors) : null;
13726
13789
  const commitToGit = () => {
13727
13790
  var _options$config$files;
13728
13791
  return serverOps.commit(preparedCommit, message, auth.id, ((_options$config$files = options.config.files) === null || _options$config$files === void 0 ? void 0 : _options$config$files.directory) || "/public/val", undefined,
@@ -13789,6 +13852,15 @@ const ValServer = (valModules, options, callbacks) => {
13789
13852
  */
13790
13853
  ...(serverOps.sourceMode() === "managed" ? {
13791
13854
  sourceFiles: preparedCommit.patchedSourceFiles
13855
+ } : {}),
13856
+ ...(managedBranch !== null ? {
13857
+ branch: managedBranch
13858
+ } : {}),
13859
+ ...(committedBinaries !== null ? {
13860
+ binaryFiles: committedBinaries.files,
13861
+ ...(committedBinaries.unread.length > 0 ? {
13862
+ binaryFilesUnread: committedBinaries.unread
13863
+ } : {})
13792
13864
  } : {})
13793
13865
  }
13794
13866
  };
package/package.json CHANGED
@@ -16,7 +16,7 @@
16
16
  "./package.json": "./package.json"
17
17
  },
18
18
  "types": "dist/valbuild-server.cjs.d.ts",
19
- "version": "0.136.1",
19
+ "version": "0.136.2",
20
20
  "devDependencies": {
21
21
  "@prettier/sync": "^0.6.1",
22
22
  "@types/jest": "^30.0.0",
@@ -30,9 +30,9 @@
30
30
  "typescript": "^6.0.3",
31
31
  "zod": "^4.4.3",
32
32
  "zod-validation-error": "^5.0.0",
33
+ "@valbuild/shared": "0.136.2",
33
34
  "@valbuild/core": "0.136.1",
34
- "@valbuild/shared": "0.136.1",
35
- "@valbuild/ui": "0.136.1"
35
+ "@valbuild/ui": "0.136.2"
36
36
  },
37
37
  "engines": {
38
38
  "node": "^20.19.0 || >=22"