@valbuild/server 0.152.1 → 0.153.0

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.
Files changed (34) hide show
  1. package/CHANGELOG.md +42 -0
  2. package/browser/dist/valbuild-server-browser.cjs.dev.js +2 -2
  3. package/browser/dist/valbuild-server-browser.cjs.prod.js +2 -2
  4. package/browser/dist/valbuild-server-browser.esm.js +2 -2
  5. package/dist/{ValRouter-b4125d35.esm.js → ValRouter-0393906a.esm.js} +86 -12
  6. package/dist/{ValRouter-541c76f5.cjs.dev.js → ValRouter-c289e074.cjs.prod.js} +86 -11
  7. package/dist/{ValRouter-e1e0101b.cjs.prod.js → ValRouter-cf781930.cjs.dev.js} +86 -11
  8. package/dist/{ValRouterCore-bd3e9b6c.cjs.dev.js → ValRouterCore-0aff3db3.cjs.dev.js} +305 -251
  9. package/dist/{ValRouterCore-0c0359fe.cjs.prod.js → ValRouterCore-356d7093.cjs.prod.js} +305 -251
  10. package/dist/{ValRouterCore-eea19e82.esm.js → ValRouterCore-5cf45273.esm.js} +305 -251
  11. package/dist/declarations/src/ValOps.d.ts +42 -4
  12. package/dist/declarations/src/ValOpsFS.d.ts +6 -3
  13. package/dist/declarations/src/ValOpsHttp.d.ts +5 -2
  14. package/dist/declarations/src/ValOpsMemory.d.ts +3 -2
  15. package/dist/declarations/src/ValRouter.d.ts +10 -0
  16. package/dist/declarations/src/ValServer.d.ts +2 -0
  17. package/dist/declarations/src/internal/index.d.ts +1 -1
  18. package/dist/declarations/src/proposal.d.ts +19 -3
  19. package/dist/{inTabFetch-de7cf596.esm.js → inTabFetch-3c5fa83d.esm.js} +1 -1
  20. package/dist/{inTabFetch-6d54acd8.cjs.dev.js → inTabFetch-40a26012.cjs.dev.js} +1 -1
  21. package/dist/{inTabFetch-5caf8250.cjs.prod.js → inTabFetch-731f199d.cjs.prod.js} +1 -1
  22. package/dist/{publishKit-c13ba76f.esm.js → publishKit-3f9af1dd.esm.js} +3 -3
  23. package/dist/{publishKit-42f08a69.cjs.dev.js → publishKit-90ea0493.cjs.dev.js} +2 -2
  24. package/dist/{publishKit-9600ecef.cjs.prod.js → publishKit-c17c1152.cjs.prod.js} +2 -2
  25. package/dist/valbuild-server.cjs.dev.js +2 -2
  26. package/dist/valbuild-server.cjs.prod.js +2 -2
  27. package/dist/valbuild-server.esm.js +4 -4
  28. package/internal/browser/dist/valbuild-server-internal-browser.cjs.dev.js +2 -2
  29. package/internal/browser/dist/valbuild-server-internal-browser.cjs.prod.js +2 -2
  30. package/internal/browser/dist/valbuild-server-internal-browser.esm.js +2 -2
  31. package/internal/dist/valbuild-server-internal.cjs.dev.js +3 -2
  32. package/internal/dist/valbuild-server-internal.cjs.prod.js +3 -2
  33. package/internal/dist/valbuild-server-internal.esm.js +2 -2
  34. package/package.json +4 -4
@@ -2,7 +2,7 @@
2
2
 
3
3
  var core = require('@valbuild/core');
4
4
  var server = require('@valbuild/ui/server');
5
- var ValRouterCore = require('./ValRouterCore-0c0359fe.cjs.prod.js');
5
+ var ValRouterCore = require('./ValRouterCore-0aff3db3.cjs.dev.js');
6
6
  var path = require('path');
7
7
  var ts = require('typescript');
8
8
  var z = require('zod');
@@ -2205,7 +2205,7 @@ function createFsSketchpadStore(rootDir, now = () => new Date()) {
2205
2205
  * as a bundler does.
2206
2206
  */
2207
2207
  function loadTypeScriptKit() {
2208
- return Promise.resolve().then(function () { return require('./publishKit-9600ecef.cjs.prod.js'); });
2208
+ return Promise.resolve().then(function () { return require('./publishKit-90ea0493.cjs.dev.js'); });
2209
2209
  }
2210
2210
 
2211
2211
  /** Serializes a schema, or gives up quietly — serialization errors are reported elsewhere. */
@@ -2424,9 +2424,12 @@ class ValOpsFS extends ValRouterCore.ValOps {
2424
2424
  const didChange = !params ||
2425
2425
  // An entry file changed on disk: nothing else here can see that, since a
2426
2426
  // jsonValues module's source is markers.
2427
- params.jsonEntriesSha !== undefined && currentJsonEntriesSha !== params.jsonEntriesSha || currentBaseSha !== params.baseSha ||
2428
- // base sha covers both sources sha and schema sha, so we could remove checks for schema sha and sources sha
2429
- currentSourcesSha !== params.sourcesSha || currentSchemaSha !== params.schemaSha || patches.length !== params.patches.length || patches.some((p, i) => p !== params.patches[i]);
2427
+ params.jsonEntriesSha !== undefined && currentJsonEntriesSha !== params.jsonEntriesSha || currentBaseSha !== params.baseSha || (
2428
+ // Another build: by the version the Studio echoes -- the build the
2429
+ // chain is relative to (`chainBuild`), which every instance on this
2430
+ // store answers with -- or, from a Studio that echoes no version
2431
+ // (the release that shipped the one content model), by the shas.
2432
+ params.version !== undefined ? params.version.build !== (await this.chainBuild()) : currentSourcesSha !== params.sourcesSha || currentSchemaSha !== params.schemaSha) || patches.length !== params.patches.length || patches.some((p, i) => p !== params.patches[i]);
2430
2433
  if (didChange) {
2431
2434
  return {
2432
2435
  type: "did-change",
@@ -3607,16 +3610,76 @@ class FSOpsHost {
3607
3610
  * sound: a module's schema can move with a file it imports, so "its own file
3608
3611
  * is unchanged" never says its code is in the build.
3609
3612
  */
3610
- function stagedAfterBuild(proposal) {
3613
+ function stagedAfterBuild(proposal, build) {
3611
3614
  const inBuild = proposal.buildInputs === null || proposal.buildInputs === undefined ? null : `${internal.STAGED_SCHEMA_PREFIX}${proposal.buildInputs}`;
3612
3615
  const after = {};
3613
3616
  for (const [path, version] of Object.entries(proposal.staged ?? {})) {
3614
3617
  if (version === inBuild) continue;
3615
3618
  after[path] = version;
3616
3619
  }
3620
+ if (build === undefined || proposal.files === undefined) return after;
3621
+ /*
3622
+ * Through what a module imports. The overlay names only staged MODULE
3623
+ * files, and a module's schema moves with any file it imports, so a module
3624
+ * whose own file is not staged can still be of code the build was not made
3625
+ * of. What changed since the build is read from text: a file the proposal
3626
+ * holds that is code (not a module file, not an entry's `*.val.json` --
3627
+ * saves write those, stagings write code) and whose text is not what the
3628
+ * build was made of; and every module file staged after the build. A
3629
+ * module that depends on one of those, as the build resolved its imports,
3630
+ * is staged after the build as well.
3631
+ */
3632
+ const changed = new Set(Object.keys(after).map(path => path.replace(/^\/+/, "")));
3633
+ const changedCode = [];
3634
+ for (const [path, text] of Object.entries(proposal.files)) {
3635
+ if (isModuleOrEntryFile(path)) continue;
3636
+ if (build.source[path] === text) continue;
3637
+ changed.add(path);
3638
+ changedCode.push([path, text]);
3639
+ }
3640
+ if (changed.size === 0) return after;
3641
+ /*
3642
+ * Named after the staging where the overlay names it (every staged
3643
+ * module's version is the same `staged:<inputs>`); where it names none --
3644
+ * only code that is not a module was staged -- after the code that
3645
+ * changed, which is as distinct per staging and is never a build's.
3646
+ */
3647
+ const named = Object.values(proposal.staged ?? {})[0] ?? `${internal.STAGED_SCHEMA_PREFIX}${hashOfFiles(changedCode)}`;
3648
+ for (const [modulePath, dependencies] of Object.entries(build.moduleDependencies)) {
3649
+ const moduleFilePath = `/${modulePath.replace(/^\/+/, "")}`;
3650
+ if (after[moduleFilePath] !== undefined) continue;
3651
+ if (dependencies.some(dependency => changed.has(dependency))) {
3652
+ after[moduleFilePath] = named;
3653
+ }
3654
+ }
3617
3655
  return after;
3618
3656
  }
3619
3657
 
3658
+ /**
3659
+ * What the build serving the address was made of, as the platform builds it
3660
+ * and embeds it: its own source (`platform:project-source`) and, for each
3661
+ * module file, every project file it depends on as the build resolved its
3662
+ * imports (`moduleDependencies`, by path with no leading slash, transitive).
3663
+ * For {@link stagedAfterBuild}.
3664
+ */
3665
+
3666
+ /** The {@link ServingBuild} a host handed over, or `undefined` when not both. */
3667
+ function servingBuildOf(http) {
3668
+ return http.projectSource !== undefined && http.moduleDependencies !== undefined ? {
3669
+ source: http.projectSource,
3670
+ moduleDependencies: http.moduleDependencies
3671
+ } : undefined;
3672
+ }
3673
+ function isModuleOrEntryFile(path) {
3674
+ return /\.val\.(ts|js|json)$/.test(path);
3675
+ }
3676
+
3677
+ /** A 64-hex name for code that changed: its paths and text, in order. */
3678
+ function hashOfFiles(files) {
3679
+ const sorted = [...files].sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0);
3680
+ return core.Internal.getSHA256Hash(new TextEncoder().encode(JSON.stringify(sorted)));
3681
+ }
3682
+
3620
3683
  /**
3621
3684
  * The proposal a platform describes in its runtime env, or `undefined` when
3622
3685
  * this is not a proposal's address.
@@ -3890,8 +3953,8 @@ function layeredSnapshot(proposal, contentVersion) {
3890
3953
  * -- until a build of the staging serves the address. The same rule as
3891
3954
  * `layered`'s, for the one source that carries no version.
3892
3955
  */
3893
- function proposalAsBuilt(proposal) {
3894
- const after = stagedAfterBuild(proposal);
3956
+ function proposalAsBuilt(proposal, build) {
3957
+ const after = stagedAfterBuild(proposal, build);
3895
3958
  if (Object.keys(after).length === 0) return proposal;
3896
3959
  const modules = {};
3897
3960
  for (const [path, source] of Object.entries(proposal.modules)) {
@@ -4926,7 +4989,7 @@ async function stagedModuleSources(files) {
4926
4989
  parseValFile,
4927
4990
  analyzeValModule,
4928
4991
  evaluateModuleSource
4929
- } = await Promise.resolve().then(function () { return require('./publishKit-9600ecef.cjs.prod.js'); });
4992
+ } = await Promise.resolve().then(function () { return require('./publishKit-90ea0493.cjs.dev.js'); });
4930
4993
  const sources = {};
4931
4994
  for (const {
4932
4995
  path,
@@ -5763,7 +5826,7 @@ class ValOpsHttp extends ValRouterCore.ValOps {
5763
5826
  * their staged text, versioned as their staging. See `stagedAfterBuild`.
5764
5827
  */
5765
5828
  const proposal = options === null || options === void 0 ? void 0 : options.proposal;
5766
- const staged = proposal !== undefined ? stagedAfterBuild(proposal) : {};
5829
+ const staged = proposal !== undefined ? stagedAfterBuild(proposal, servingBuildOf(options ?? {})) : {};
5767
5830
  const stagedPaths = Object.keys(staged);
5768
5831
  super(valModules, options && snapshot ? {
5769
5832
  ...options,
@@ -5774,8 +5837,12 @@ class ValOpsHttp extends ValRouterCore.ValOps {
5774
5837
  stagedAfterBuild: {
5775
5838
  versions: staged,
5776
5839
  readSources: () => stagedModuleSources(Object.fromEntries(stagedPaths.map(path => {
5840
+ var _options$projectSourc;
5777
5841
  const file = path.replace(/^\/+/, "");
5778
- return [file, proposal.files[file] ?? null];
5842
+ // A module staged after the build through a file
5843
+ // it imports has its own text unstaged: the
5844
+ // build's, unless a save rewrote it.
5845
+ return [file, proposal.files[file] ?? ((_options$projectSourc = options.projectSource) === null || _options$projectSourc === void 0 ? void 0 : _options$projectSourc[file]) ?? null];
5779
5846
  })))
5780
5847
  }
5781
5848
  } : {}),
@@ -8872,6 +8939,9 @@ async function initHandlerOptions(route, opts, config) {
8872
8939
  ...(opts.projectSource !== undefined ? {
8873
8940
  projectSource: opts.projectSource
8874
8941
  } : {}),
8942
+ ...(opts.moduleDependencies !== undefined ? {
8943
+ moduleDependencies: opts.moduleDependencies
8944
+ } : {}),
8875
8945
  ...(opts.publishJob !== undefined ? {
8876
8946
  publishJob: opts.publishJob
8877
8947
  } : {}),
@@ -8955,6 +9025,9 @@ function createValOps(valModules, options) {
8955
9025
  ...(options.projectSource !== undefined ? {
8956
9026
  projectSource: options.projectSource
8957
9027
  } : {}),
9028
+ ...(options.moduleDependencies !== undefined ? {
9029
+ moduleDependencies: options.moduleDependencies
9030
+ } : {}),
8958
9031
  ...(options.publishJob !== undefined ? {
8959
9032
  publishJob: options.publishJob
8960
9033
  } : {}),
@@ -9462,6 +9535,7 @@ function differences(a, b) {
9462
9535
  check("git", sameValue(a.git, b.git));
9463
9536
  check("root", a.root === b.root);
9464
9537
  check("projectSource", sameValue(a.projectSource, b.projectSource));
9538
+ check("moduleDependencies", sameValue(a.moduleDependencies, b.moduleDependencies));
9465
9539
  check("publishJob", a.publishJob === b.publishJob);
9466
9540
  check("publishBuild", a.publishBuild === b.publishBuild);
9467
9541
  check("proposal", sameValue(a.proposal, b.proposal));
@@ -14431,6 +14505,7 @@ exports.readPatchStore = readPatchStore;
14431
14505
  exports.removeValJsonEntry = removeValJsonEntry;
14432
14506
  exports.resolveRemoteFileAuth = resolveRemoteFileAuth;
14433
14507
  exports.safeReadGit = safeReadGit;
14508
+ exports.servingBuildOf = servingBuildOf;
14434
14509
  exports.stagedAfterBuild = stagedAfterBuild;
14435
14510
  exports.unreadableVideoMetadataMessage = unreadableVideoMetadataMessage;
14436
14511
  exports.uploadBytesToRemote = uploadBytesToRemote;