@valbuild/server 0.154.3 → 0.155.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 (46) hide show
  1. package/CHANGELOG.md +23 -0
  2. package/browser/dist/valbuild-server-browser.cjs.dev.js +4 -4
  3. package/browser/dist/valbuild-server-browser.cjs.prod.js +4 -4
  4. package/browser/dist/valbuild-server-browser.esm.js +4 -4
  5. package/dist/{ValOpsMemory-972616ae.esm.js → ValOpsMemory-1a0bc2dc.esm.js} +33 -14
  6. package/dist/{ValOpsMemory-45ba05ad.cjs.dev.js → ValOpsMemory-6e829758.cjs.dev.js} +32 -12
  7. package/dist/{ValOpsMemory-18337353.cjs.prod.js → ValOpsMemory-f000531b.cjs.prod.js} +32 -12
  8. package/dist/{ValPatchStore-df8cdbe7.cjs.dev.js → ValPatchStore-457b166f.cjs.prod.js} +37 -59
  9. package/dist/{ValPatchStore-e23070df.esm.js → ValPatchStore-9ccc09e7.esm.js} +38 -60
  10. package/dist/{ValPatchStore-2f92eced.cjs.prod.js → ValPatchStore-b53db740.cjs.dev.js} +37 -59
  11. package/dist/{ValRouterCore-86757d56.cjs.dev.js → ValRouterCore-65bb6323.cjs.prod.js} +11 -2
  12. package/dist/{ValRouterCore-5b747abb.cjs.prod.js → ValRouterCore-adb69698.cjs.dev.js} +11 -2
  13. package/dist/{ValRouterCore-73eb843d.esm.js → ValRouterCore-f7d6394e.esm.js} +11 -2
  14. package/dist/{createPrettierFormatter-851fcf99.cjs.dev.js → createPrettierFormatter-5d830bdf.cjs.dev.js} +6 -14
  15. package/dist/{createPrettierFormatter-05ad7480.cjs.prod.js → createPrettierFormatter-b31bfbe5.cjs.prod.js} +6 -14
  16. package/dist/{createPrettierFormatter-1edca494.esm.js → createPrettierFormatter-ce478de1.esm.js} +7 -15
  17. package/dist/{createValRuntime-5cebf459.cjs.dev.js → createValRuntime-1c7d891e.cjs.dev.js} +5 -5
  18. package/dist/{createValRuntime-472df6e8.cjs.prod.js → createValRuntime-a519939b.cjs.prod.js} +5 -5
  19. package/dist/{createValRuntime-c77ee010.esm.js → createValRuntime-f55300a0.esm.js} +5 -5
  20. package/dist/declarations/src/draftReads.d.ts +5 -0
  21. package/dist/declarations/src/head.d.ts +7 -7
  22. package/dist/{draftReads-3f7dcda5.cjs.prod.js → draftReads-1f256502.cjs.dev.js} +5 -0
  23. package/dist/{draftReads-a300a02f.cjs.dev.js → draftReads-27351e97.cjs.prod.js} +5 -0
  24. package/dist/{draftReads-bca0d49c.esm.js → draftReads-7f0f0eb3.esm.js} +5 -0
  25. package/dist/{inTabFetch-c2efa1bd.cjs.prod.js → inTabFetch-3d8ceb84.cjs.prod.js} +2 -2
  26. package/dist/{inTabFetch-db6d6425.cjs.dev.js → inTabFetch-75753a09.cjs.dev.js} +2 -2
  27. package/dist/{inTabFetch-0c997998.esm.js → inTabFetch-dae5dd87.esm.js} +2 -2
  28. package/dist/{proposalJsonEntries-0669f027.esm.js → proposalJsonEntries-2cd6f6fe.esm.js} +1 -1
  29. package/dist/{proposalJsonEntries-26f397bd.cjs.dev.js → proposalJsonEntries-d21900d4.cjs.dev.js} +1 -1
  30. package/dist/{proposalJsonEntries-9e537244.cjs.prod.js → proposalJsonEntries-d4623810.cjs.prod.js} +1 -1
  31. package/dist/{publishKit-ac0af189.esm.js → publishKit-04b6d255.esm.js} +7 -7
  32. package/dist/{publishKit-7aca03bb.cjs.prod.js → publishKit-395b92e5.cjs.prod.js} +5 -5
  33. package/dist/{publishKit-38d46a51.cjs.dev.js → publishKit-de4baed6.cjs.dev.js} +5 -5
  34. package/dist/{valRuntime-e4d26702.esm.js → valRuntime-7fd12e16.esm.js} +42 -24
  35. package/dist/{valRuntime-70ee2dc2.cjs.dev.js → valRuntime-d3cc6e0d.cjs.dev.js} +41 -23
  36. package/dist/{valRuntime-2a3cc887.cjs.prod.js → valRuntime-e922e372.cjs.prod.js} +41 -23
  37. package/dist/valbuild-server.cjs.dev.js +6 -6
  38. package/dist/valbuild-server.cjs.prod.js +6 -6
  39. package/dist/valbuild-server.esm.js +9 -9
  40. package/internal/browser/dist/valbuild-server-internal-browser.cjs.dev.js +5 -5
  41. package/internal/browser/dist/valbuild-server-internal-browser.cjs.prod.js +5 -5
  42. package/internal/browser/dist/valbuild-server-internal-browser.esm.js +5 -5
  43. package/internal/dist/valbuild-server-internal.cjs.dev.js +4 -4
  44. package/internal/dist/valbuild-server-internal.cjs.prod.js +4 -4
  45. package/internal/dist/valbuild-server-internal.esm.js +4 -4
  46. package/package.json +4 -4
@@ -1,5 +1,5 @@
1
1
  import { Internal } from '@valbuild/core';
2
- import { memoryTier, tiered, bundleTier, moduleKey, EMPTY_CHAIN, baseModuleContent, applyPatchRecord, extendChain, entryState, engineWork, resolveEntry, parseModuleKey } from '@valbuild/shared/internal';
2
+ import { settledOnce, SettledCache, memoryTier, tiered, bundleTier, moduleKey, EMPTY_CHAIN, baseModuleContent, applyPatchRecord, extendChain, entryState, engineWork, resolveEntry, parseModuleKey } from '@valbuild/shared/internal';
3
3
 
4
4
  /**
5
5
  * The patches a json entry render should apply, out of the whole chain:
@@ -159,10 +159,37 @@ class ValHead {
159
159
  memory;
160
160
  store;
161
161
  facts = new WeakMap();
162
+ /*
163
+ * What the head keeps between reads is what they SETTLED to, never a
164
+ * promise one of them is still waiting on: a head lives as long as the
165
+ * process, and on workerd a promise belongs to the request that made it --
166
+ * one that ends while its read is pending leaves a promise every later
167
+ * request fails on. See `SettledCache` in `@valbuild/shared/internal`.
168
+ * So two requests that find the chain moved at the same moment each fetch
169
+ * it: they used to join one fetch.
170
+ */
162
171
  chain = null;
163
- fetching = null;
164
- serialized = null;
165
- wholeTree = null;
172
+ serialized = settledOnce(() => this.ops.getSchemas().then(schemas => {
173
+ const serialized = {};
174
+ for (const [path, schema] of Object.entries(schemas)) {
175
+ try {
176
+ serialized[path] = schema["executeSerialize"]();
177
+ } catch {
178
+ // Reported elsewhere; read as "no schema", as the engine does.
179
+ serialized[path] = undefined;
180
+ }
181
+ }
182
+ return serialized;
183
+ }));
184
+ /** {@link tree}, for the newest chain it was made at. */
185
+ wholeTree = new SettledCache({
186
+ keep: made => "ok" in made,
187
+ max: 1
188
+ });
189
+ /** {@link changed}, made once per chain: it looks at every record's markers. */
190
+ changedIn = new SettledCache({
191
+ max: 1
192
+ });
166
193
  constructor(ops, opts = {}) {
167
194
  this.ops = ops;
168
195
  this.memory = memoryTier({
@@ -184,8 +211,8 @@ class ValHead {
184
211
 
185
212
  /**
186
213
  * The chain, re-read only when `seq` moved (or the base did: a publish
187
- * adopted). A read that finds a fetch already under way at the `seq` it
188
- * saw joins it: that fetch reads at that `seq` or later.
214
+ * adopted). A read that finds it moved fetches it, even while another
215
+ * read's fetch is under way: see {@link chain}.
189
216
  *
190
217
  * Asks "has the chain moved?" once per call -- in http mode one request to
191
218
  * the content service. A caller that reads several modules for ONE answer
@@ -202,26 +229,7 @@ class ValHead {
202
229
  ok: held
203
230
  };
204
231
  }
205
- const fetching = this.fetching;
206
- if (position !== null && fetching !== null && fetching.seq === position.seq && fetching.epoch === position.epoch) {
207
- return fetching.promise;
208
- }
209
- const promise = this.fetchChain(position, base);
210
- if (position !== null) {
211
- const started = {
212
- ...position,
213
- promise
214
- };
215
- this.fetching = started;
216
- // Cleared however it ends. `finally` would hand on a rejection to a
217
- // promise nobody holds: an unhandled rejection, which ends a Node
218
- // process. The caller is handed `promise` itself, and sees it.
219
- const done = () => {
220
- if (this.fetching === started) this.fetching = null;
221
- };
222
- promise.then(done, done);
223
- }
224
- return promise;
232
+ return this.fetchChain(position, base);
225
233
  }
226
234
 
227
235
  /** The chain a read is answered at: the one given, or the newest. */
@@ -288,19 +296,7 @@ class ValHead {
288
296
  * and MCP's tools their schemas.
289
297
  */
290
298
  serializedSchemas() {
291
- this.serialized ??= this.ops.getSchemas().then(schemas => {
292
- const serialized = {};
293
- for (const [path, schema] of Object.entries(schemas)) {
294
- try {
295
- serialized[path] = schema["executeSerialize"]();
296
- } catch {
297
- // Reported elsewhere; read as "no schema", as the engine does.
298
- serialized[path] = undefined;
299
- }
300
- }
301
- return serialized;
302
- });
303
- return this.serialized;
299
+ return this.serialized();
304
300
  }
305
301
 
306
302
  // #region modules
@@ -685,25 +681,14 @@ class ValHead {
685
681
  * publish wrote that the bundle has not got. What `fetchValDraft` sends.
686
682
  */
687
683
  async changed(at) {
688
- var _made;
689
684
  const synced = await this.at(at);
690
685
  if ("error" in synced) return synced;
691
686
  const chain = synced.ok;
692
- let made = this.changedIn;
693
- if (((_made = made) === null || _made === void 0 ? void 0 : _made.chain) !== chain) {
694
- made = {
695
- chain,
696
- paths: this.changedOf(chain)
697
- };
698
- this.changedIn = made;
699
- }
687
+ const paths = await this.changedIn.get(chain, () => this.changedOf(chain));
700
688
  return {
701
- ok: [...(await made.paths)]
689
+ ok: [...paths]
702
690
  };
703
691
  }
704
-
705
- /** {@link changed}, made once per chain: it looks at every record's markers. */
706
- changedIn = null;
707
692
  async changedOf(chain) {
708
693
  const changed = new Set(chain.byModule.keys());
709
694
  for (const path of Object.keys(chain.versions)) {
@@ -722,17 +707,10 @@ class ValHead {
722
707
  * MCP read; made once per chain.
723
708
  */
724
709
  async tree() {
725
- var _this$wholeTree;
726
710
  const synced = await this.sync();
727
711
  if ("error" in synced) return synced;
728
712
  const chain = synced.ok;
729
- if (((_this$wholeTree = this.wholeTree) === null || _this$wholeTree === void 0 ? void 0 : _this$wholeTree.chain) !== chain) {
730
- this.wholeTree = {
731
- chain,
732
- promise: this.makeTree(chain)
733
- };
734
- }
735
- return this.wholeTree.promise;
713
+ return this.wholeTree.get(chain, () => this.makeTree(chain));
736
714
  }
737
715
  async makeTree(chain) {
738
716
  const base = await this.ops.getBaseSources();
@@ -161,10 +161,37 @@ class ValHead {
161
161
  memory;
162
162
  store;
163
163
  facts = new WeakMap();
164
+ /*
165
+ * What the head keeps between reads is what they SETTLED to, never a
166
+ * promise one of them is still waiting on: a head lives as long as the
167
+ * process, and on workerd a promise belongs to the request that made it --
168
+ * one that ends while its read is pending leaves a promise every later
169
+ * request fails on. See `SettledCache` in `@valbuild/shared/internal`.
170
+ * So two requests that find the chain moved at the same moment each fetch
171
+ * it: they used to join one fetch.
172
+ */
164
173
  chain = null;
165
- fetching = null;
166
- serialized = null;
167
- wholeTree = null;
174
+ serialized = internal.settledOnce(() => this.ops.getSchemas().then(schemas => {
175
+ const serialized = {};
176
+ for (const [path, schema] of Object.entries(schemas)) {
177
+ try {
178
+ serialized[path] = schema["executeSerialize"]();
179
+ } catch {
180
+ // Reported elsewhere; read as "no schema", as the engine does.
181
+ serialized[path] = undefined;
182
+ }
183
+ }
184
+ return serialized;
185
+ }));
186
+ /** {@link tree}, for the newest chain it was made at. */
187
+ wholeTree = new internal.SettledCache({
188
+ keep: made => "ok" in made,
189
+ max: 1
190
+ });
191
+ /** {@link changed}, made once per chain: it looks at every record's markers. */
192
+ changedIn = new internal.SettledCache({
193
+ max: 1
194
+ });
168
195
  constructor(ops, opts = {}) {
169
196
  this.ops = ops;
170
197
  this.memory = internal.memoryTier({
@@ -186,8 +213,8 @@ class ValHead {
186
213
 
187
214
  /**
188
215
  * The chain, re-read only when `seq` moved (or the base did: a publish
189
- * adopted). A read that finds a fetch already under way at the `seq` it
190
- * saw joins it: that fetch reads at that `seq` or later.
216
+ * adopted). A read that finds it moved fetches it, even while another
217
+ * read's fetch is under way: see {@link chain}.
191
218
  *
192
219
  * Asks "has the chain moved?" once per call -- in http mode one request to
193
220
  * the content service. A caller that reads several modules for ONE answer
@@ -204,26 +231,7 @@ class ValHead {
204
231
  ok: held
205
232
  };
206
233
  }
207
- const fetching = this.fetching;
208
- if (position !== null && fetching !== null && fetching.seq === position.seq && fetching.epoch === position.epoch) {
209
- return fetching.promise;
210
- }
211
- const promise = this.fetchChain(position, base);
212
- if (position !== null) {
213
- const started = {
214
- ...position,
215
- promise
216
- };
217
- this.fetching = started;
218
- // Cleared however it ends. `finally` would hand on a rejection to a
219
- // promise nobody holds: an unhandled rejection, which ends a Node
220
- // process. The caller is handed `promise` itself, and sees it.
221
- const done = () => {
222
- if (this.fetching === started) this.fetching = null;
223
- };
224
- promise.then(done, done);
225
- }
226
- return promise;
234
+ return this.fetchChain(position, base);
227
235
  }
228
236
 
229
237
  /** The chain a read is answered at: the one given, or the newest. */
@@ -290,19 +298,7 @@ class ValHead {
290
298
  * and MCP's tools their schemas.
291
299
  */
292
300
  serializedSchemas() {
293
- this.serialized ??= this.ops.getSchemas().then(schemas => {
294
- const serialized = {};
295
- for (const [path, schema] of Object.entries(schemas)) {
296
- try {
297
- serialized[path] = schema["executeSerialize"]();
298
- } catch {
299
- // Reported elsewhere; read as "no schema", as the engine does.
300
- serialized[path] = undefined;
301
- }
302
- }
303
- return serialized;
304
- });
305
- return this.serialized;
301
+ return this.serialized();
306
302
  }
307
303
 
308
304
  // #region modules
@@ -687,25 +683,14 @@ class ValHead {
687
683
  * publish wrote that the bundle has not got. What `fetchValDraft` sends.
688
684
  */
689
685
  async changed(at) {
690
- var _made;
691
686
  const synced = await this.at(at);
692
687
  if ("error" in synced) return synced;
693
688
  const chain = synced.ok;
694
- let made = this.changedIn;
695
- if (((_made = made) === null || _made === void 0 ? void 0 : _made.chain) !== chain) {
696
- made = {
697
- chain,
698
- paths: this.changedOf(chain)
699
- };
700
- this.changedIn = made;
701
- }
689
+ const paths = await this.changedIn.get(chain, () => this.changedOf(chain));
702
690
  return {
703
- ok: [...(await made.paths)]
691
+ ok: [...paths]
704
692
  };
705
693
  }
706
-
707
- /** {@link changed}, made once per chain: it looks at every record's markers. */
708
- changedIn = null;
709
694
  async changedOf(chain) {
710
695
  const changed = new Set(chain.byModule.keys());
711
696
  for (const path of Object.keys(chain.versions)) {
@@ -724,17 +709,10 @@ class ValHead {
724
709
  * MCP read; made once per chain.
725
710
  */
726
711
  async tree() {
727
- var _this$wholeTree;
728
712
  const synced = await this.sync();
729
713
  if ("error" in synced) return synced;
730
714
  const chain = synced.ok;
731
- if (((_this$wholeTree = this.wholeTree) === null || _this$wholeTree === void 0 ? void 0 : _this$wholeTree.chain) !== chain) {
732
- this.wholeTree = {
733
- chain,
734
- promise: this.makeTree(chain)
735
- };
736
- }
737
- return this.wholeTree.promise;
715
+ return this.wholeTree.get(chain, () => this.makeTree(chain));
738
716
  }
739
717
  async makeTree(chain) {
740
718
  const base = await this.ops.getBaseSources();
@@ -217,13 +217,22 @@ function createValRequestHandler(route, valServerPromise, convert, serveStatic)
217
217
  // Without this no-op catch, a config error (e.g. proxy mode without a project)
218
218
  // rejects with no handler attached, which becomes an unhandledRejection and kills
219
219
  // the dev server. The error is still reported per request by the try/catch below.
220
- valServerPromise.catch(() => {
220
+ //
221
+ // The server itself is kept once it is made, and every request after that
222
+ // reads it rather than awaiting the promise: the promise was made by
223
+ // whichever request first loaded the app's route module, and on workerd a
224
+ // request awaiting a promise of one that has ended fails. See
225
+ // `SettledCache` in `@valbuild/shared/internal`.
226
+ let made = null;
227
+ valServerPromise.then(server => {
228
+ made = server;
229
+ }, () => {
221
230
  // handled below
222
231
  });
223
232
  return async req => {
224
233
  let valServer;
225
234
  try {
226
- valServer = await valServerPromise;
235
+ valServer = made ?? (await valServerPromise);
227
236
  } catch (err) {
228
237
  const error = {
229
238
  message: "Val: could not start the Val server",
@@ -217,13 +217,22 @@ function createValRequestHandler(route, valServerPromise, convert, serveStatic)
217
217
  // Without this no-op catch, a config error (e.g. proxy mode without a project)
218
218
  // rejects with no handler attached, which becomes an unhandledRejection and kills
219
219
  // the dev server. The error is still reported per request by the try/catch below.
220
- valServerPromise.catch(() => {
220
+ //
221
+ // The server itself is kept once it is made, and every request after that
222
+ // reads it rather than awaiting the promise: the promise was made by
223
+ // whichever request first loaded the app's route module, and on workerd a
224
+ // request awaiting a promise of one that has ended fails. See
225
+ // `SettledCache` in `@valbuild/shared/internal`.
226
+ let made = null;
227
+ valServerPromise.then(server => {
228
+ made = server;
229
+ }, () => {
221
230
  // handled below
222
231
  });
223
232
  return async req => {
224
233
  let valServer;
225
234
  try {
226
- valServer = await valServerPromise;
235
+ valServer = made ?? (await valServerPromise);
227
236
  } catch (err) {
228
237
  const error = {
229
238
  message: "Val: could not start the Val server",
@@ -215,13 +215,22 @@ function createValRequestHandler(route, valServerPromise, convert, serveStatic)
215
215
  // Without this no-op catch, a config error (e.g. proxy mode without a project)
216
216
  // rejects with no handler attached, which becomes an unhandledRejection and kills
217
217
  // the dev server. The error is still reported per request by the try/catch below.
218
- valServerPromise.catch(() => {
218
+ //
219
+ // The server itself is kept once it is made, and every request after that
220
+ // reads it rather than awaiting the promise: the promise was made by
221
+ // whichever request first loaded the app's route module, and on workerd a
222
+ // request awaiting a promise of one that has ended fails. See
223
+ // `SettledCache` in `@valbuild/shared/internal`.
224
+ let made = null;
225
+ valServerPromise.then(server => {
226
+ made = server;
227
+ }, () => {
219
228
  // handled below
220
229
  });
221
230
  return async req => {
222
231
  let valServer;
223
232
  try {
224
- valServer = await valServerPromise;
233
+ valServer = made ?? (await valServerPromise);
225
234
  } catch (err) {
226
235
  const error = {
227
236
  message: "Val: could not start the Val server",
@@ -415,7 +415,7 @@ async function readerSnapshot(proposal, projectSource) {
415
415
  }
416
416
  const {
417
417
  proposalSnapshotForReaders
418
- } = await Promise.resolve().then(function () { return require('./proposalJsonEntries-26f397bd.cjs.dev.js'); }).then(function (n) { return n.proposalJsonEntries$1; });
418
+ } = await Promise.resolve().then(function () { return require('./proposalJsonEntries-d21900d4.cjs.dev.js'); }).then(function (n) { return n.proposalJsonEntries$1; });
419
419
  return proposalSnapshotForReaders(proposal, projectSource);
420
420
  }
421
421
 
@@ -637,19 +637,11 @@ function resolveAgainstProject(projectRoot, filePath) {
637
637
  * without a config has asked for.
638
638
  */
639
639
  function createPrettierFormatter(prettierOrLoader, options) {
640
- let loaded = null;
641
- const loadPrettier = () => {
642
- if (typeof prettierOrLoader !== "function") {
643
- return Promise.resolve(prettierOrLoader);
644
- }
645
- // Forgotten when it fails, so the next save tries again rather than
646
- // failing on the same rejected promise for the life of the process.
647
- loaded ??= prettierOrLoader().catch(err => {
648
- loaded = null;
649
- throw err;
650
- });
651
- return loaded;
652
- };
640
+ // Kept once it is loaded -- prettier, never the promise of it: a server on
641
+ // a workerd isolate shares this closure between requests, and a promise
642
+ // made by a request that has ended fails every other request awaiting it.
643
+ // One that fails is loaded again by the next save.
644
+ const loadPrettier = typeof prettierOrLoader === "function" ? internal.keptOnce(prettierOrLoader) : () => Promise.resolve(prettierOrLoader);
653
645
  const projectRoot = path__default["default"].resolve(options.projectRoot);
654
646
  // One array, built once: prettier reads and caches the ignore file itself, so
655
647
  // this is only here to avoid rebuilding the path per file.
@@ -415,7 +415,7 @@ async function readerSnapshot(proposal, projectSource) {
415
415
  }
416
416
  const {
417
417
  proposalSnapshotForReaders
418
- } = await Promise.resolve().then(function () { return require('./proposalJsonEntries-9e537244.cjs.prod.js'); }).then(function (n) { return n.proposalJsonEntries$1; });
418
+ } = await Promise.resolve().then(function () { return require('./proposalJsonEntries-d4623810.cjs.prod.js'); }).then(function (n) { return n.proposalJsonEntries$1; });
419
419
  return proposalSnapshotForReaders(proposal, projectSource);
420
420
  }
421
421
 
@@ -637,19 +637,11 @@ function resolveAgainstProject(projectRoot, filePath) {
637
637
  * without a config has asked for.
638
638
  */
639
639
  function createPrettierFormatter(prettierOrLoader, options) {
640
- let loaded = null;
641
- const loadPrettier = () => {
642
- if (typeof prettierOrLoader !== "function") {
643
- return Promise.resolve(prettierOrLoader);
644
- }
645
- // Forgotten when it fails, so the next save tries again rather than
646
- // failing on the same rejected promise for the life of the process.
647
- loaded ??= prettierOrLoader().catch(err => {
648
- loaded = null;
649
- throw err;
650
- });
651
- return loaded;
652
- };
640
+ // Kept once it is loaded -- prettier, never the promise of it: a server on
641
+ // a workerd isolate shares this closure between requests, and a promise
642
+ // made by a request that has ended fails every other request awaiting it.
643
+ // One that fails is loaded again by the next save.
644
+ const loadPrettier = typeof prettierOrLoader === "function" ? internal.keptOnce(prettierOrLoader) : () => Promise.resolve(prettierOrLoader);
653
645
  const projectRoot = path__default["default"].resolve(options.projectRoot);
654
646
  // One array, built once: prettier reads and caches the ignore file itself, so
655
647
  // this is only here to avoid rebuilding the path per file.
@@ -1,5 +1,5 @@
1
1
  import { Internal } from '@valbuild/core';
2
- import { STAGED_SCHEMA_PREFIX } from '@valbuild/shared/internal';
2
+ import { STAGED_SCHEMA_PREFIX, keptOnce } from '@valbuild/shared/internal';
3
3
  import path from 'path';
4
4
 
5
5
  /**
@@ -409,7 +409,7 @@ async function readerSnapshot(proposal, projectSource) {
409
409
  }
410
410
  const {
411
411
  proposalSnapshotForReaders
412
- } = await import('./proposalJsonEntries-0669f027.esm.js').then(function (n) { return n.l; });
412
+ } = await import('./proposalJsonEntries-2cd6f6fe.esm.js').then(function (n) { return n.l; });
413
413
  return proposalSnapshotForReaders(proposal, projectSource);
414
414
  }
415
415
 
@@ -631,19 +631,11 @@ function resolveAgainstProject(projectRoot, filePath) {
631
631
  * without a config has asked for.
632
632
  */
633
633
  function createPrettierFormatter(prettierOrLoader, options) {
634
- let loaded = null;
635
- const loadPrettier = () => {
636
- if (typeof prettierOrLoader !== "function") {
637
- return Promise.resolve(prettierOrLoader);
638
- }
639
- // Forgotten when it fails, so the next save tries again rather than
640
- // failing on the same rejected promise for the life of the process.
641
- loaded ??= prettierOrLoader().catch(err => {
642
- loaded = null;
643
- throw err;
644
- });
645
- return loaded;
646
- };
634
+ // Kept once it is loaded -- prettier, never the promise of it: a server on
635
+ // a workerd isolate shares this closure between requests, and a promise
636
+ // made by a request that has ended fails every other request awaiting it.
637
+ // One that fails is loaded again by the next save.
638
+ const loadPrettier = typeof prettierOrLoader === "function" ? keptOnce(prettierOrLoader) : () => Promise.resolve(prettierOrLoader);
647
639
  const projectRoot = path.resolve(options.projectRoot);
648
640
  // One array, built once: prettier reads and caches the ignore file itself, so
649
641
  // this is only here to avoid rebuilding the path per file.
@@ -1,21 +1,21 @@
1
1
  'use strict';
2
2
 
3
- var valRuntime = require('./valRuntime-70ee2dc2.cjs.dev.js');
3
+ var valRuntime = require('./valRuntime-d3cc6e0d.cjs.dev.js');
4
4
  require('@valbuild/core');
5
- require('./ValOpsMemory-45ba05ad.cjs.dev.js');
5
+ require('./ValOpsMemory-6e829758.cjs.dev.js');
6
6
  require('zod');
7
7
  require('@valbuild/shared/internal');
8
8
  require('./jsonValuesPatch-88bc661d.cjs.dev.js');
9
9
  require('@valbuild/core/fp');
10
10
  require('zod-validation-error');
11
- require('./ValPatchStore-df8cdbe7.cjs.dev.js');
11
+ require('./ValPatchStore-b53db740.cjs.dev.js');
12
12
  require('@valbuild/core/patch');
13
13
  require('image-size');
14
14
  require('path');
15
15
  require('typescript');
16
16
  require('fs');
17
- require('./proposalJsonEntries-26f397bd.cjs.dev.js');
18
- require('./createPrettierFormatter-851fcf99.cjs.dev.js');
17
+ require('./proposalJsonEntries-d21900d4.cjs.dev.js');
18
+ require('./createPrettierFormatter-5d830bdf.cjs.dev.js');
19
19
  require('os');
20
20
  require('crypto');
21
21
  require('buffer');
@@ -1,21 +1,21 @@
1
1
  'use strict';
2
2
 
3
- var valRuntime = require('./valRuntime-2a3cc887.cjs.prod.js');
3
+ var valRuntime = require('./valRuntime-e922e372.cjs.prod.js');
4
4
  require('@valbuild/core');
5
- require('./ValOpsMemory-18337353.cjs.prod.js');
5
+ require('./ValOpsMemory-f000531b.cjs.prod.js');
6
6
  require('zod');
7
7
  require('@valbuild/shared/internal');
8
8
  require('./jsonValuesPatch-92798812.cjs.prod.js');
9
9
  require('@valbuild/core/fp');
10
10
  require('zod-validation-error');
11
- require('./ValPatchStore-2f92eced.cjs.prod.js');
11
+ require('./ValPatchStore-457b166f.cjs.prod.js');
12
12
  require('@valbuild/core/patch');
13
13
  require('image-size');
14
14
  require('path');
15
15
  require('typescript');
16
16
  require('fs');
17
- require('./proposalJsonEntries-9e537244.cjs.prod.js');
18
- require('./createPrettierFormatter-05ad7480.cjs.prod.js');
17
+ require('./proposalJsonEntries-d4623810.cjs.prod.js');
18
+ require('./createPrettierFormatter-b31bfbe5.cjs.prod.js');
19
19
  require('os');
20
20
  require('crypto');
21
21
  require('buffer');
@@ -1,19 +1,19 @@
1
- import { i as initHandlerOptions, v as valRuntime } from './valRuntime-e4d26702.esm.js';
1
+ import { i as initHandlerOptions, v as valRuntime } from './valRuntime-7fd12e16.esm.js';
2
2
  import '@valbuild/core';
3
- import './ValOpsMemory-972616ae.esm.js';
3
+ import './ValOpsMemory-1a0bc2dc.esm.js';
4
4
  import 'zod';
5
5
  import '@valbuild/shared/internal';
6
6
  import './jsonValuesPatch-13acc674.esm.js';
7
7
  import '@valbuild/core/fp';
8
8
  import 'zod-validation-error';
9
- import './ValPatchStore-e23070df.esm.js';
9
+ import './ValPatchStore-9ccc09e7.esm.js';
10
10
  import '@valbuild/core/patch';
11
11
  import 'image-size';
12
12
  import 'path';
13
13
  import 'typescript';
14
14
  import 'fs';
15
- import './proposalJsonEntries-0669f027.esm.js';
16
- import './createPrettierFormatter-1edca494.esm.js';
15
+ import './proposalJsonEntries-2cd6f6fe.esm.js';
16
+ import './createPrettierFormatter-ce478de1.esm.js';
17
17
  import 'os';
18
18
  import 'crypto';
19
19
  import 'buffer';
@@ -16,6 +16,11 @@ type Headers = {
16
16
  * building the readers does not build the runtime: the runtime is the data
17
17
  * layer, and a visitor -- draft mode off -- never needs it. A caller that
18
18
  * already has one passes `() => runtime`; it is asked at most once a read.
19
+ *
20
+ * The frameworks' getter keeps the runtime once it is made (`settledOnce`),
21
+ * never the promise of it: the readers are made once per process, and a
22
+ * promise made in one request and awaited in another is what workerd fails a
23
+ * request for (see `SettledCache` in `@valbuild/shared/internal`).
19
24
  */
20
25
  export type ReaderRuntime = () => Promise<ValRuntime>;
21
26
  /** One module {@link readDraftChanges} read: what a reader's `reads` record. */
@@ -131,9 +131,11 @@ export declare class ValHead {
131
131
  private readonly store;
132
132
  private readonly facts;
133
133
  private chain;
134
- private fetching;
135
- private serialized;
136
- private wholeTree;
134
+ private readonly serialized;
135
+ /** {@link tree}, for the newest chain it was made at. */
136
+ private readonly wholeTree;
137
+ /** {@link changed}, made once per chain: it looks at every record's markers. */
138
+ private readonly changedIn;
137
139
  constructor(ops: ValOps, opts?: {
138
140
  budgetBytes?: number;
139
141
  lastPerModule?: number;
@@ -142,8 +144,8 @@ export declare class ValHead {
142
144
  stats(): MemoryTierStats;
143
145
  /**
144
146
  * The chain, re-read only when `seq` moved (or the base did: a publish
145
- * adopted). A read that finds a fetch already under way at the `seq` it
146
- * saw joins it: that fetch reads at that `seq` or later.
147
+ * adopted). A read that finds it moved fetches it, even while another
148
+ * read's fetch is under way: see {@link chain}.
147
149
  *
148
150
  * Asks "has the chain moved?" once per call -- in http mode one request to
149
151
  * the content service. A caller that reads several modules for ONE answer
@@ -206,8 +208,6 @@ export declare class ValHead {
206
208
  * publish wrote that the bundle has not got. What `fetchValDraft` sends.
207
209
  */
208
210
  changed(at?: HeadChain): Promise<HeadResult<ModuleFilePath[]>>;
209
- /** {@link changed}, made once per chain: it looks at every record's markers. */
210
- private changedIn;
211
211
  private changedOf;
212
212
  /**
213
213
  * Every module at the newest chain: the patched ones made (once per
@@ -24,6 +24,11 @@ var internal = require('@valbuild/shared/internal');
24
24
  * building the readers does not build the runtime: the runtime is the data
25
25
  * layer, and a visitor -- draft mode off -- never needs it. A caller that
26
26
  * already has one passes `() => runtime`; it is asked at most once a read.
27
+ *
28
+ * The frameworks' getter keeps the runtime once it is made (`settledOnce`),
29
+ * never the promise of it: the readers are made once per process, and a
30
+ * promise made in one request and awaited in another is what workerd fails a
31
+ * request for (see `SettledCache` in `@valbuild/shared/internal`).
27
32
  */
28
33
 
29
34
  /** One module {@link readDraftChanges} read: what a reader's `reads` record. */
@@ -24,6 +24,11 @@ var internal = require('@valbuild/shared/internal');
24
24
  * building the readers does not build the runtime: the runtime is the data
25
25
  * layer, and a visitor -- draft mode off -- never needs it. A caller that
26
26
  * already has one passes `() => runtime`; it is asked at most once a read.
27
+ *
28
+ * The frameworks' getter keeps the runtime once it is made (`settledOnce`),
29
+ * never the promise of it: the readers are made once per process, and a
30
+ * promise made in one request and awaited in another is what workerd fails a
31
+ * request for (see `SettledCache` in `@valbuild/shared/internal`).
27
32
  */
28
33
 
29
34
  /** One module {@link readDraftChanges} read: what a reader's `reads` record. */
@@ -22,6 +22,11 @@ import { VAL_SESSION_COOKIE } from '@valbuild/shared/internal';
22
22
  * building the readers does not build the runtime: the runtime is the data
23
23
  * layer, and a visitor -- draft mode off -- never needs it. A caller that
24
24
  * already has one passes `() => runtime`; it is asked at most once a read.
25
+ *
26
+ * The frameworks' getter keeps the runtime once it is made (`settledOnce`),
27
+ * never the promise of it: the readers are made once per process, and a
28
+ * promise made in one request and awaited in another is what workerd fails a
29
+ * request for (see `SettledCache` in `@valbuild/shared/internal`).
25
30
  */
26
31
 
27
32
  /** One module {@link readDraftChanges} read: what a reader's `reads` record. */