@valbuild/tanstack 0.136.0 → 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.
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var version = require('../../dist/version-4a61902e.cjs.dev.js');
5
+ var version = require('../../dist/version-822a861e.cjs.dev.js');
6
6
  var core = require('@valbuild/core');
7
7
  var createForOfIteratorHelper = require('../../dist/createForOfIteratorHelper-e75681d7.cjs.dev.js');
8
8
  var server = require('@valbuild/server');
@@ -325,109 +325,260 @@ function initValServer(valModules, config, opts) {
325
325
  * is server-RENDERED and then hydrated, so every element it produces is a
326
326
  * normal client element and the distinction does not exist.
327
327
  */
328
- var initFetchValStega = function initFetchValStega(config, valApiEndpoints, valServerPromise, isEnabled, getHeaders, getCookies) {
328
+
329
+ /**
330
+ * The `modules` map every `fetchVal` in one request shares.
331
+ *
332
+ * Derived from the route's own response type rather than restated, so it cannot
333
+ * drift from what `/sources/~` actually returns.
334
+ */
335
+
336
+ /**
337
+ * The slice of `ValServer` the draft-sources reader uses.
338
+ *
339
+ * Narrower than `ValServer` for the same reason `JsonEntryValServer` below is:
340
+ * it says what the dependency IS, and it lets a test drive the reader with a
341
+ * one-route fake instead of casting a partial object to the whole server type.
342
+ */
343
+
344
+ /** What the route readers need: the tree, plus the single-entry route. */
345
+
346
+ /**
347
+ * Where the reader gets its per-request memo box.
348
+ *
349
+ * Injected rather than reached for, so that "this reader needs a request to
350
+ * scope its cache to" is part of its contract and a test can supply a scope it
351
+ * controls — there is no TanStack request in jest.
352
+ */
353
+
354
+ /**
355
+ * A per-request memo box, keyed on the `Request` itself.
356
+ *
357
+ * That is what makes this safe: TanStack resolves one `Request` object per
358
+ * in-flight request out of async local storage, so two visitors cannot collide,
359
+ * and a `WeakMap` lets the entry go when the request does. This is the TanStack
360
+ * half of the Next package's `cache()` — there is no RSC here, so React's
361
+ * request memoisation does not exist (see the note at the top of this file).
362
+ *
363
+ * Outside a request there is nothing to scope to and `getRequest` throws;
364
+ * `null` then means "compute every time", which is what this did before the
365
+ * memo existed. See `memoizePerRequest`.
366
+ *
367
+ * Built PER `initValContent` rather than once for the module, because the box
368
+ * is only as specific as the map it came from: two Val servers in one process
369
+ * sharing one would answer each other's reads within a request, and they hold
370
+ * different content.
371
+ */
372
+ function createTanStackRequestScope() {
373
+ var boxes = new WeakMap();
374
+ return /*#__PURE__*/version._asyncToGenerator(/*#__PURE__*/version._regenerator().m(function _callee() {
375
+ var request, _yield$import, getRequest, existing, box;
376
+ return version._regenerator().w(function (_context) {
377
+ while (1) switch (_context.p = _context.n) {
378
+ case 0:
379
+ _context.p = 0;
380
+ _context.n = 1;
381
+ return Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require('@tanstack/react-start/server')); });
382
+ case 1:
383
+ _yield$import = _context.v;
384
+ getRequest = _yield$import.getRequest;
385
+ request = getRequest();
386
+ _context.n = 3;
387
+ break;
388
+ case 2:
389
+ _context.p = 2;
390
+ _context.v;
391
+ return _context.a(2, null);
392
+ case 3:
393
+ existing = boxes.get(request);
394
+ if (!existing) {
395
+ _context.n = 4;
396
+ break;
397
+ }
398
+ return _context.a(2, existing);
399
+ case 4:
400
+ box = {};
401
+ boxes.set(request, box);
402
+ return _context.a(2, box);
403
+ }
404
+ }, _callee, null, [[0, 2]]);
405
+ }));
406
+ }
407
+
408
+ /**
409
+ * ONE read of the whole module tree, for the session in `sessionCookie`.
410
+ *
411
+ * `path` stays `"/"` on purpose, and the measurement is why. `/sources/~`
412
+ * evaluates, previews and validates EVERY module and only THEN filters the
413
+ * response by `req.path` (the two TODOs in `ValServer.ts` say so), so narrowing
414
+ * the path shrinks the answer and changes the work not at all: on a 60-module
415
+ * project, `path: "/"` took 53.6ms and a single-module path 53.5ms. And this is
416
+ * an in-process call rather than a round trip, so the object it builds is never
417
+ * serialised or sent anywhere — the bytes it saves are not bytes anyone pays
418
+ * for. Narrowing would also give each caller a different answer to cache, which
419
+ * is what would cost the saving that IS real (2.7x on the same project).
420
+ *
421
+ * `draftRead.perf.test.ts` prints both numbers; re-run it before believing
422
+ * anything different.
423
+ *
424
+ * Returns `null` when the session is not one the server accepts; the caller
425
+ * then renders published content, which is what it did before.
426
+ */
427
+ function loadDraftSources(_x, _x2) {
428
+ return _loadDraftSources.apply(this, arguments);
429
+ }
430
+ function _loadDraftSources() {
431
+ _loadDraftSources = version._asyncToGenerator(/*#__PURE__*/version._regenerator().m(function _callee6(valServerPromise, sessionCookie) {
432
+ var valServer, treeRes;
433
+ return version._regenerator().w(function (_context6) {
434
+ while (1) switch (_context6.n) {
435
+ case 0:
436
+ _context6.n = 1;
437
+ return valServerPromise;
438
+ case 1:
439
+ valServer = _context6.v;
440
+ _context6.n = 2;
441
+ return valServer["/sources/~"]["PUT"]({
442
+ path: "/",
443
+ query: {
444
+ validate_sources: true,
445
+ validate_binary_files: false,
446
+ exclude_patches: false,
447
+ // The server-side read uses the legacy "server applies patches"
448
+ // path, same as the Next package's.
449
+ apply_patches: undefined,
450
+ /*
451
+ * The caller's own staged work, and nobody else's.
452
+ *
453
+ * A draft render cannot name its group ids — it has no client
454
+ * state — so it asks for "mine" and the server resolves them from
455
+ * the session. Without this a preview shows base + every pending
456
+ * patch on the branch, so one person's half-finished edit appears
457
+ * in another person's draft.
458
+ *
459
+ * `patch_id` stays `undefined`: naming an explicit list is for a
460
+ * caller that already knows what it wants, and it would override
461
+ * the resolution rather than intersect with it.
462
+ */
463
+ patch_id: undefined,
464
+ own_patch_groups_only: true
465
+ },
466
+ cookies: createForOfIteratorHelper._defineProperty({}, internal.VAL_SESSION_COOKIE, sessionCookie)
467
+ });
468
+ case 2:
469
+ treeRes = _context6.v;
470
+ if (!(treeRes.status === 200)) {
471
+ _context6.n = 3;
472
+ break;
473
+ }
474
+ return _context6.a(2, treeRes.json.modules);
475
+ case 3:
476
+ if (!(treeRes.status === 401)) {
477
+ _context6.n = 4;
478
+ break;
479
+ }
480
+ console.warn("Val: authentication error: ", treeRes.json.message);
481
+ return _context6.a(2, null);
482
+ case 4:
483
+ throw Error(JSON.stringify(treeRes.json, null, 2));
484
+ case 5:
485
+ return _context6.a(2);
486
+ }
487
+ }, _callee6);
488
+ }));
489
+ return _loadDraftSources.apply(this, arguments);
490
+ }
491
+ var initFetchValStega = function initFetchValStega(config, valApiEndpoints, valServerPromise, isEnabled, getHeaders, getCookies, getDraftSourcesScope) {
329
492
  return function (selector) {
330
493
  var exec = /*#__PURE__*/function () {
331
- var _ref = version._asyncToGenerator(/*#__PURE__*/version._regenerator().m(function _callee() {
332
- var enabled, headers, cookies, host, _cookies, valServer, treeRes, modules, _t, _t2, _t3;
333
- return version._regenerator().w(function (_context) {
334
- while (1) switch (_context.p = _context.n) {
494
+ var _ref2 = version._asyncToGenerator(/*#__PURE__*/version._regenerator().m(function _callee2() {
495
+ var enabled, headers, cookies, host, _cookies, sessionCookie, modules, _t2, _t3, _t4, _t5;
496
+ return version._regenerator().w(function (_context2) {
497
+ while (1) switch (_context2.p = _context2.n) {
335
498
  case 0:
336
499
  enabled = false;
337
- _context.p = 1;
338
- _context.n = 2;
500
+ _context2.p = 1;
501
+ _context2.n = 2;
339
502
  return isEnabled();
340
503
  case 2:
341
- enabled = _context.v;
342
- _context.n = 4;
504
+ enabled = _context2.v;
505
+ _context2.n = 4;
343
506
  break;
344
507
  case 3:
345
- _context.p = 3;
346
- _t = _context.v;
347
- console.error("Val: could not check if Val is enabled! This might be due to an error reading draft mode. fetchVal can only be used server-side (in a loader, a server function, or a server route). Use useVal in components.", _t);
508
+ _context2.p = 3;
509
+ _t2 = _context2.v;
510
+ console.error("Val: could not check if Val is enabled! This might be due to an error reading draft mode. fetchVal can only be used server-side (in a loader, a server function, or a server route). Use useVal in components.", _t2);
348
511
  case 4:
349
512
  if (!enabled) {
350
- _context.n = 17;
513
+ _context2.n = 15;
351
514
  break;
352
515
  }
353
516
  stega.SET_AUTO_TAG_JSX_ENABLED(true);
354
- _context.p = 5;
355
- _context.n = 6;
517
+ _context2.p = 5;
518
+ _context2.n = 6;
356
519
  return getHeaders();
357
520
  case 6:
358
- headers = _context.v;
521
+ headers = _context2.v;
359
522
  if (!(typeof headers.get !== "function")) {
360
- _context.n = 7;
523
+ _context2.n = 7;
361
524
  break;
362
525
  }
363
526
  throw new Error("Invalid headers");
364
527
  case 7:
365
- _context.n = 9;
528
+ _context2.n = 9;
366
529
  break;
367
530
  case 8:
368
- _context.p = 8;
369
- _t2 = _context.v;
370
- console.error("Val: could not read headers! fetchVal can only be used server-side (in a loader, a server function, or a server route). Use useVal in components.", _t2);
531
+ _context2.p = 8;
532
+ _t3 = _context2.v;
533
+ console.error("Val: could not read headers! fetchVal can only be used server-side (in a loader, a server function, or a server route). Use useVal in components.", _t3);
371
534
  headers = null;
372
535
  case 9:
373
- _context.p = 9;
374
- _context.n = 10;
536
+ _context2.p = 9;
537
+ _context2.n = 10;
375
538
  return getCookies();
376
539
  case 10:
377
- cookies = _context.v;
378
- _context.n = 12;
540
+ cookies = _context2.v;
541
+ _context2.n = 12;
379
542
  break;
380
543
  case 11:
381
- _context.p = 11;
382
- _t3 = _context.v;
383
- console.error("Val: could not read cookies! fetchVal can only be used server-side (in a loader, a server function, or a server route). Use useVal in components.", _t3);
544
+ _context2.p = 11;
545
+ _t4 = _context2.v;
546
+ console.error("Val: could not read cookies! fetchVal can only be used server-side (in a loader, a server function, or a server route). Use useVal in components.", _t4);
384
547
  cookies = null;
385
548
  case 12:
386
549
  host = headers && getHost(headers);
387
550
  if (!(host && cookies)) {
388
- _context.n = 17;
551
+ _context2.n = 15;
389
552
  break;
390
553
  }
391
- _context.n = 13;
392
- return valServerPromise;
554
+ sessionCookie = (_cookies = cookies) === null || _cookies === void 0 || (_cookies = _cookies.get(internal.VAL_SESSION_COOKIE)) === null || _cookies === void 0 ? void 0 : _cookies.value;
555
+ /*
556
+ * Once per request, however many times the page reads.
557
+ *
558
+ * Every `fetchVal` in one request asks the same question — same
559
+ * query, same session — so the second and third answer were identical
560
+ * and cost the same as the first. `fetchValRouteUrl` made that worse
561
+ * by calling `fetchVal` again on top of the caller's own.
562
+ *
563
+ * The key is the session, so a box that somehow outlived its request
564
+ * misses rather than serving another author's draft. See
565
+ * `memoizePerRequest`.
566
+ */
567
+ _t5 = internal.memoizePerRequest;
568
+ _context2.n = 13;
569
+ return getDraftSourcesScope();
393
570
  case 13:
394
- valServer = _context.v;
395
- _context.n = 14;
396
- return valServer["/sources/~"]["PUT"]({
397
- path: "/",
398
- query: {
399
- validate_sources: true,
400
- validate_binary_files: false,
401
- exclude_patches: false,
402
- // The server-side read uses the legacy "server applies patches"
403
- // path, same as the Next package's.
404
- apply_patches: undefined,
405
- /*
406
- * The caller's own staged work, and nobody else's.
407
- *
408
- * A draft render cannot name its group ids — it has no client
409
- * state — so it asks for "mine" and the server resolves them from
410
- * the session. Without this a preview shows base + every pending
411
- * patch on the branch, so one person's half-finished edit appears
412
- * in another person's draft.
413
- *
414
- * `patch_id` stays `undefined`: naming an explicit list is for a
415
- * caller that already knows what it wants, and it would override
416
- * the resolution rather than intersect with it.
417
- */
418
- patch_id: undefined,
419
- own_patch_groups_only: true
420
- },
421
- cookies: createForOfIteratorHelper._defineProperty({}, internal.VAL_SESSION_COOKIE, (_cookies = cookies) === null || _cookies === void 0 || (_cookies = _cookies.get(internal.VAL_SESSION_COOKIE)) === null || _cookies === void 0 ? void 0 : _cookies.value)
571
+ _context2.n = 14;
572
+ return _t5(_context2.v, sessionCookie !== null && sessionCookie !== void 0 ? sessionCookie : "", function () {
573
+ return loadDraftSources(valServerPromise, sessionCookie);
422
574
  });
423
575
  case 14:
424
- treeRes = _context.v;
425
- if (!(treeRes.status === 200)) {
426
- _context.n = 15;
576
+ modules = _context2.v;
577
+ if (!modules) {
578
+ _context2.n = 15;
427
579
  break;
428
580
  }
429
- modules = treeRes.json.modules;
430
- return _context.a(2, stega.stegaEncode(selector, {
581
+ return _context2.a(2, stega.stegaEncode(selector, {
431
582
  disabled: !enabled,
432
583
  getModule: function getModule(path) {
433
584
  var module = modules[path];
@@ -437,24 +588,14 @@ var initFetchValStega = function initFetchValStega(config, valApiEndpoints, valS
437
588
  }
438
589
  }));
439
590
  case 15:
440
- if (!(treeRes.status === 401)) {
441
- _context.n = 16;
442
- break;
443
- }
444
- console.warn("Val: authentication error: ", treeRes.json.message);
445
- _context.n = 17;
446
- break;
447
- case 16:
448
- throw Error(JSON.stringify(treeRes.json, null, 2));
449
- case 17:
450
- return _context.a(2, stega.stegaEncode(selector, {
591
+ return _context2.a(2, stega.stegaEncode(selector, {
451
592
  disabled: !enabled
452
593
  }));
453
594
  }
454
- }, _callee, null, [[9, 11], [5, 8], [1, 3]]);
595
+ }, _callee2, null, [[9, 11], [5, 8], [1, 3]]);
455
596
  }));
456
597
  return function exec() {
457
- return _ref.apply(this, arguments);
598
+ return _ref2.apply(this, arguments);
458
599
  };
459
600
  }();
460
601
  return exec()["catch"](function (err) {
@@ -503,17 +644,17 @@ function getHost(headers) {
503
644
  // }
504
645
  // }
505
646
 
506
- var initFetchValRouteStega = function initFetchValRouteStega(config, valApiEndpoints, valServerPromise, isEnabled, getHeaders, getCookies) {
647
+ var initFetchValRouteStega = function initFetchValRouteStega(config, valApiEndpoints, valServerPromise, isEnabled, getHeaders, getCookies, getDraftSourcesScope) {
507
648
  return /*#__PURE__*/function () {
508
- var _ref2 = version._asyncToGenerator(/*#__PURE__*/version._regenerator().m(function _callee2(selector, params) {
509
- var resolvedParams, valModule, path, schema, source, url, enabled, draft, content, fetchVal, val, route, _t5;
510
- return version._regenerator().w(function (_context2) {
511
- while (1) switch (_context2.p = _context2.n) {
649
+ var _ref3 = version._asyncToGenerator(/*#__PURE__*/version._regenerator().m(function _callee3(selector, params) {
650
+ var resolvedParams, valModule, path, schema, source, url, enabled, draft, content, fetchVal, val, route, _t7;
651
+ return version._regenerator().w(function (_context3) {
652
+ while (1) switch (_context3.p = _context3.n) {
512
653
  case 0:
513
- _context2.n = 1;
654
+ _context3.n = 1;
514
655
  return Promise.resolve(params);
515
656
  case 1:
516
- resolvedParams = _context2.v;
657
+ resolvedParams = _context3.v;
517
658
  // A view is a pointer: everything below reads a path, a schema and a source
518
659
  // off this, and a pointer has none of them. See `resolveViewedModule`.
519
660
  valModule = core.Internal.resolveViewedModule(selector);
@@ -522,78 +663,78 @@ var initFetchValRouteStega = function initFetchValRouteStega(config, valApiEndpo
522
663
  // entry's backing `*.val.json`, instead of eagerly resolving the whole
523
664
  // record via `fetchVal`.
524
665
  if (!routeFromVal.isJsonValuesRecordSchema(schema)) {
525
- _context2.n = 11;
666
+ _context3.n = 11;
526
667
  break;
527
668
  }
528
669
  source = valModule && core.Internal.getSource(valModule);
529
670
  url = routeFromVal.getValRouteUrlFromVal(resolvedParams, "fetchValRoute", path, schema, source);
530
671
  if (url) {
531
- _context2.n = 2;
672
+ _context3.n = 2;
532
673
  break;
533
674
  }
534
- return _context2.a(2, null);
675
+ return _context3.a(2, null);
535
676
  case 2:
536
677
  enabled = false;
537
- _context2.p = 3;
538
- _context2.n = 4;
678
+ _context3.p = 3;
679
+ _context3.n = 4;
539
680
  return isEnabled();
540
681
  case 4:
541
- enabled = _context2.v;
542
- _context2.n = 6;
682
+ enabled = _context3.v;
683
+ _context3.n = 6;
543
684
  break;
544
685
  case 5:
545
- _context2.p = 5;
546
- _context2.v;
686
+ _context3.p = 5;
687
+ _context3.v;
547
688
  case 6:
548
689
  draft = {
549
690
  status: "unavailable"
550
691
  };
551
692
  if (!(enabled && path)) {
552
- _context2.n = 8;
693
+ _context3.n = 8;
553
694
  break;
554
695
  }
555
696
  stega.SET_AUTO_TAG_JSX_ENABLED(true);
556
- _context2.n = 7;
697
+ _context3.n = 7;
557
698
  return loadDraftJsonEntry(valServerPromise, getCookies, path, url);
558
699
  case 7:
559
- draft = _context2.v;
700
+ draft = _context3.v;
560
701
  case 8:
561
- _context2.n = 9;
702
+ _context3.n = 9;
562
703
  return resolveDraftOrCommittedEntry(draft, function () {
563
704
  return loadJsonEntryContent(source, url);
564
705
  });
565
706
  case 9:
566
- content = _context2.v;
707
+ content = _context3.v;
567
708
  if (!(content === undefined)) {
568
- _context2.n = 10;
709
+ _context3.n = 10;
569
710
  break;
570
711
  }
571
- return _context2.a(2, null);
712
+ return _context3.a(2, null);
572
713
  case 10:
573
- return _context2.a(2, stega.stegaEncode(content, {
714
+ return _context3.a(2, stega.stegaEncode(content, {
574
715
  disabled: !enabled,
575
716
  root: routeFromVal.getJsonEntryStegaRoot(valModule, url)
576
717
  }));
577
718
  case 11:
578
- fetchVal = initFetchValStega(config, valApiEndpoints, valServerPromise, isEnabled, getHeaders, getCookies);
579
- _t5 = valModule;
580
- if (!_t5) {
581
- _context2.n = 13;
719
+ fetchVal = initFetchValStega(config, valApiEndpoints, valServerPromise, isEnabled, getHeaders, getCookies, getDraftSourcesScope);
720
+ _t7 = valModule;
721
+ if (!_t7) {
722
+ _context3.n = 13;
582
723
  break;
583
724
  }
584
- _context2.n = 12;
725
+ _context3.n = 12;
585
726
  return fetchVal(valModule);
586
727
  case 12:
587
- _t5 = _context2.v;
728
+ _t7 = _context3.v;
588
729
  case 13:
589
- val = _t5;
730
+ val = _t7;
590
731
  route = routeFromVal.initValRouteFromVal(resolvedParams, "fetchValRoute", path, schema, val);
591
- return _context2.a(2, route);
732
+ return _context3.a(2, route);
592
733
  }
593
- }, _callee2, null, [[3, 5]]);
734
+ }, _callee3, null, [[3, 5]]);
594
735
  }));
595
- return function (_x, _x2) {
596
- return _ref2.apply(this, arguments);
736
+ return function (_x3, _x4) {
737
+ return _ref3.apply(this, arguments);
597
738
  };
598
739
  }();
599
740
  };
@@ -603,7 +744,7 @@ var initFetchValRouteStega = function initFetchValRouteStega(config, valApiEndpo
603
744
  * source markers (one dynamic import). Returns `undefined` when the key is
604
745
  * missing or its marker has no runtime thunk (transport marker / draft entry).
605
746
  */
606
- function loadJsonEntryContent(_x3, _x4) {
747
+ function loadJsonEntryContent(_x5, _x6) {
607
748
  return _loadJsonEntryContent.apply(this, arguments);
608
749
  }
609
750
  /**
@@ -628,37 +769,37 @@ function loadJsonEntryContent(_x3, _x4) {
628
769
  * to the whole server type.
629
770
  */
630
771
  function _loadJsonEntryContent() {
631
- _loadJsonEntryContent = version._asyncToGenerator(/*#__PURE__*/version._regenerator().m(function _callee5(source, key) {
772
+ _loadJsonEntryContent = version._asyncToGenerator(/*#__PURE__*/version._regenerator().m(function _callee7(source, key) {
632
773
  var marker, thunk;
633
- return version._regenerator().w(function (_context5) {
634
- while (1) switch (_context5.n) {
774
+ return version._regenerator().w(function (_context7) {
775
+ while (1) switch (_context7.n) {
635
776
  case 0:
636
777
  if (!(!source || routeFromVal._typeof(source) !== "object")) {
637
- _context5.n = 1;
778
+ _context7.n = 1;
638
779
  break;
639
780
  }
640
- return _context5.a(2, undefined);
781
+ return _context7.a(2, undefined);
641
782
  case 1:
642
783
  marker = source[key];
643
784
  if (core.Internal.isJson(marker)) {
644
- _context5.n = 2;
785
+ _context7.n = 2;
645
786
  break;
646
787
  }
647
- return _context5.a(2, undefined);
788
+ return _context7.a(2, undefined);
648
789
  case 2:
649
790
  thunk = core.Internal.getJsonImport(marker);
650
791
  if (thunk) {
651
- _context5.n = 3;
792
+ _context7.n = 3;
652
793
  break;
653
794
  }
654
- return _context5.a(2, undefined);
795
+ return _context7.a(2, undefined);
655
796
  case 3:
656
- _context5.n = 4;
797
+ _context7.n = 4;
657
798
  return thunk();
658
799
  case 4:
659
- return _context5.a(2, _context5.v["default"]);
800
+ return _context7.a(2, _context7.v["default"]);
660
801
  }
661
- }, _callee5);
802
+ }, _callee7);
662
803
  }));
663
804
  return _loadJsonEntryContent.apply(this, arguments);
664
805
  }
@@ -671,33 +812,33 @@ function _loadJsonEntryContent() {
671
812
  * ask). Returning `undefined` means "render nothing"; both callers turn that into
672
813
  * a null/undefined result.
673
814
  */
674
- function resolveDraftOrCommittedEntry(_x5, _x6) {
815
+ function resolveDraftOrCommittedEntry(_x7, _x8) {
675
816
  return _resolveDraftOrCommittedEntry.apply(this, arguments);
676
817
  }
677
818
  function _resolveDraftOrCommittedEntry() {
678
- _resolveDraftOrCommittedEntry = version._asyncToGenerator(/*#__PURE__*/version._regenerator().m(function _callee6(draft, loadCommitted) {
679
- return version._regenerator().w(function (_context6) {
680
- while (1) switch (_context6.n) {
819
+ _resolveDraftOrCommittedEntry = version._asyncToGenerator(/*#__PURE__*/version._regenerator().m(function _callee8(draft, loadCommitted) {
820
+ return version._regenerator().w(function (_context8) {
821
+ while (1) switch (_context8.n) {
681
822
  case 0:
682
823
  if (!(draft.status === "content")) {
683
- _context6.n = 1;
824
+ _context8.n = 1;
684
825
  break;
685
826
  }
686
- return _context6.a(2, draft.content);
827
+ return _context8.a(2, draft.content);
687
828
  case 1:
688
829
  if (!(draft.status === "absent")) {
689
- _context6.n = 2;
830
+ _context8.n = 2;
690
831
  break;
691
832
  }
692
- return _context6.a(2, undefined);
833
+ return _context8.a(2, undefined);
693
834
  case 2:
694
- return _context6.a(2, loadCommitted());
835
+ return _context8.a(2, loadCommitted());
695
836
  }
696
- }, _callee6);
837
+ }, _callee8);
697
838
  }));
698
839
  return _resolveDraftOrCommittedEntry.apply(this, arguments);
699
840
  }
700
- function loadDraftJsonEntry(_x7, _x8, _x9, _x0) {
841
+ function loadDraftJsonEntry(_x9, _x0, _x1, _x10) {
701
842
  return _loadDraftJsonEntry.apply(this, arguments);
702
843
  }
703
844
  /**
@@ -712,31 +853,31 @@ function loadDraftJsonEntry(_x7, _x8, _x9, _x0) {
712
853
  * the draft read yields nothing.
713
854
  */
714
855
  function _loadDraftJsonEntry() {
715
- _loadDraftJsonEntry = version._asyncToGenerator(/*#__PURE__*/version._regenerator().m(function _callee7(valServerPromise, getCookies, moduleFilePath, key) {
856
+ _loadDraftJsonEntry = version._asyncToGenerator(/*#__PURE__*/version._regenerator().m(function _callee9(valServerPromise, getCookies, moduleFilePath, key) {
716
857
  var _cookies3;
717
858
  var cookies, valServer, res;
718
- return version._regenerator().w(function (_context7) {
719
- while (1) switch (_context7.p = _context7.n) {
859
+ return version._regenerator().w(function (_context9) {
860
+ while (1) switch (_context9.p = _context9.n) {
720
861
  case 0:
721
- _context7.p = 0;
722
- _context7.n = 1;
862
+ _context9.p = 0;
863
+ _context9.n = 1;
723
864
  return getCookies();
724
865
  case 1:
725
- cookies = _context7.v;
726
- _context7.n = 3;
866
+ cookies = _context9.v;
867
+ _context9.n = 3;
727
868
  break;
728
869
  case 2:
729
- _context7.p = 2;
730
- _context7.v;
731
- return _context7.a(2, {
870
+ _context9.p = 2;
871
+ _context9.v;
872
+ return _context9.a(2, {
732
873
  status: "unavailable"
733
874
  });
734
875
  case 3:
735
- _context7.n = 4;
876
+ _context9.n = 4;
736
877
  return valServerPromise;
737
878
  case 4:
738
- valServer = _context7.v;
739
- _context7.n = 5;
879
+ valServer = _context9.v;
880
+ _context9.n = 5;
740
881
  return valServer["/json"]["GET"]({
741
882
  query: {
742
883
  path: moduleFilePath,
@@ -759,60 +900,60 @@ function _loadDraftJsonEntry() {
759
900
  cookies: createForOfIteratorHelper._defineProperty({}, internal.VAL_SESSION_COOKIE, (_cookies3 = cookies) === null || _cookies3 === void 0 || (_cookies3 = _cookies3.get(internal.VAL_SESSION_COOKIE)) === null || _cookies3 === void 0 ? void 0 : _cookies3.value)
760
901
  });
761
902
  case 5:
762
- res = _context7.v;
903
+ res = _context9.v;
763
904
  if (!(res.status === 200 && "content" in res.json)) {
764
- _context7.n = 6;
905
+ _context9.n = 6;
765
906
  break;
766
907
  }
767
- return _context7.a(2, {
908
+ return _context9.a(2, {
768
909
  status: "content",
769
910
  content: res.json.content
770
911
  });
771
912
  case 6:
772
913
  if (!(res.status === 401)) {
773
- _context7.n = 7;
914
+ _context9.n = 7;
774
915
  break;
775
916
  }
776
917
  console.warn("Val: authentication error: ", res.json.message);
777
- return _context7.a(2, {
918
+ return _context9.a(2, {
778
919
  status: "unavailable"
779
920
  });
780
921
  case 7:
781
922
  if (!(res.status === 404)) {
782
- _context7.n = 8;
923
+ _context9.n = 8;
783
924
  break;
784
925
  }
785
- return _context7.a(2, {
926
+ return _context9.a(2, {
786
927
  status: "absent"
787
928
  });
788
929
  case 8:
789
930
  console.error("Val: could not load draft JSON entry: ", "message" in res.json ? res.json.message : "status ".concat(res.status));
790
- return _context7.a(2, {
931
+ return _context9.a(2, {
791
932
  status: "unavailable"
792
933
  });
793
934
  }
794
- }, _callee7, null, [[0, 2]]);
935
+ }, _callee9, null, [[0, 2]]);
795
936
  }));
796
937
  return _loadDraftJsonEntry.apply(this, arguments);
797
938
  }
798
939
  var initFetchValKeyStega = function initFetchValKeyStega(valServerPromise, isEnabled, getCookies) {
799
940
  return /*#__PURE__*/function () {
800
- var _ref3 = version._asyncToGenerator(/*#__PURE__*/version._regenerator().m(function _callee3(selector, key) {
941
+ var _ref4 = version._asyncToGenerator(/*#__PURE__*/version._regenerator().m(function _callee4(selector, key) {
801
942
  var enabled, valModule, source, moduleFilePath, draft, content;
802
- return version._regenerator().w(function (_context3) {
803
- while (1) switch (_context3.p = _context3.n) {
943
+ return version._regenerator().w(function (_context4) {
944
+ while (1) switch (_context4.p = _context4.n) {
804
945
  case 0:
805
946
  enabled = false;
806
- _context3.p = 1;
807
- _context3.n = 2;
947
+ _context4.p = 1;
948
+ _context4.n = 2;
808
949
  return isEnabled();
809
950
  case 2:
810
- enabled = _context3.v;
811
- _context3.n = 4;
951
+ enabled = _context4.v;
952
+ _context4.n = 4;
812
953
  break;
813
954
  case 3:
814
- _context3.p = 3;
815
- _context3.v;
955
+ _context4.p = 3;
956
+ _context4.v;
816
957
  case 4:
817
958
  // A view is a pointer: everything below reads a path and a source off this,
818
959
  // and a pointer has neither. See `resolveViewedModule`.
@@ -823,84 +964,84 @@ var initFetchValKeyStega = function initFetchValKeyStega(valServerPromise, isEna
823
964
  status: "unavailable"
824
965
  };
825
966
  if (!(enabled && moduleFilePath)) {
826
- _context3.n = 6;
967
+ _context4.n = 6;
827
968
  break;
828
969
  }
829
970
  stega.SET_AUTO_TAG_JSX_ENABLED(true);
830
- _context3.n = 5;
971
+ _context4.n = 5;
831
972
  return loadDraftJsonEntry(valServerPromise, getCookies, moduleFilePath, key);
832
973
  case 5:
833
- draft = _context3.v;
974
+ draft = _context4.v;
834
975
  case 6:
835
- _context3.n = 7;
976
+ _context4.n = 7;
836
977
  return resolveDraftOrCommittedEntry(draft, function () {
837
978
  return loadJsonEntryContent(source, key);
838
979
  });
839
980
  case 7:
840
- content = _context3.v;
981
+ content = _context4.v;
841
982
  if (!(content === undefined)) {
842
- _context3.n = 8;
983
+ _context4.n = 8;
843
984
  break;
844
985
  }
845
- return _context3.a(2, undefined);
986
+ return _context4.a(2, undefined);
846
987
  case 8:
847
- return _context3.a(2, stega.stegaEncode(content, {
988
+ return _context4.a(2, stega.stegaEncode(content, {
848
989
  disabled: !enabled,
849
990
  root: routeFromVal.getJsonEntryStegaRoot(valModule, key)
850
991
  }));
851
992
  }
852
- }, _callee3, null, [[1, 3]]);
993
+ }, _callee4, null, [[1, 3]]);
853
994
  }));
854
- return function (_x1, _x10) {
855
- return _ref3.apply(this, arguments);
995
+ return function (_x11, _x12) {
996
+ return _ref4.apply(this, arguments);
856
997
  };
857
998
  }();
858
999
  };
859
- var initFetchValRouteUrl = function initFetchValRouteUrl(config, valApiEndpoints, valServerPromise, isEnabled, getHeaders, getCookies) {
1000
+ var initFetchValRouteUrl = function initFetchValRouteUrl(config, valApiEndpoints, valServerPromise, isEnabled, getHeaders, getCookies, getDraftSourcesScope) {
860
1001
  return /*#__PURE__*/function () {
861
- var _ref4 = version._asyncToGenerator(/*#__PURE__*/version._regenerator().m(function _callee4(selector, params) {
862
- var fetchVal, resolvedParams, valModule, path, schema, val, route, _t7, _t8;
863
- return version._regenerator().w(function (_context4) {
864
- while (1) switch (_context4.n) {
1002
+ var _ref5 = version._asyncToGenerator(/*#__PURE__*/version._regenerator().m(function _callee5(selector, params) {
1003
+ var fetchVal, resolvedParams, valModule, path, schema, val, route, _t9, _t0;
1004
+ return version._regenerator().w(function (_context5) {
1005
+ while (1) switch (_context5.n) {
865
1006
  case 0:
866
- fetchVal = initFetchValStega(config, valApiEndpoints, valServerPromise, isEnabled, getHeaders, getCookies);
1007
+ fetchVal = initFetchValStega(config, valApiEndpoints, valServerPromise, isEnabled, getHeaders, getCookies, getDraftSourcesScope);
867
1008
  if (!(params === undefined)) {
868
- _context4.n = 1;
1009
+ _context5.n = 1;
869
1010
  break;
870
1011
  }
871
- _t7 = undefined;
872
- _context4.n = 3;
1012
+ _t9 = undefined;
1013
+ _context5.n = 3;
873
1014
  break;
874
1015
  case 1:
875
- _context4.n = 2;
1016
+ _context5.n = 2;
876
1017
  return Promise.resolve(params);
877
1018
  case 2:
878
- _t7 = _context4.v;
1019
+ _t9 = _context5.v;
879
1020
  case 3:
880
- resolvedParams = _t7;
1021
+ resolvedParams = _t9;
881
1022
  // A view is a pointer: everything below reads a path, a schema and a source
882
1023
  // off this, and a pointer has none of them. See `resolveViewedModule`.
883
1024
  valModule = core.Internal.resolveViewedModule(selector);
884
1025
  path = valModule && core.Internal.getValPath(valModule);
885
1026
  schema = valModule && core.Internal.getSchema(valModule);
886
- _t8 = valModule;
887
- if (!_t8) {
888
- _context4.n = 5;
1027
+ _t0 = valModule;
1028
+ if (!_t0) {
1029
+ _context5.n = 5;
889
1030
  break;
890
1031
  }
891
- _context4.n = 4;
1032
+ _context5.n = 4;
892
1033
  return fetchVal(valModule);
893
1034
  case 4:
894
- _t8 = _context4.v;
1035
+ _t0 = _context5.v;
895
1036
  case 5:
896
- val = _t8;
1037
+ val = _t0;
897
1038
  route = routeFromVal.getValRouteUrlFromVal(resolvedParams, "fetchValRouteUrl", path, schema, val);
898
- return _context4.a(2, route);
1039
+ return _context5.a(2, route);
899
1040
  }
900
- }, _callee4);
1041
+ }, _callee5);
901
1042
  }));
902
- return function (_x11, _x12) {
903
- return _ref4.apply(this, arguments);
1043
+ return function (_x13, _x14) {
1044
+ return _ref5.apply(this, arguments);
904
1045
  };
905
1046
  }();
906
1047
  };
@@ -918,25 +1059,25 @@ function requestHeaders() {
918
1059
  }
919
1060
  /** The request's cookies, in the `{ name, value }` shape the readers want. */
920
1061
  function _requestHeaders() {
921
- _requestHeaders = version._asyncToGenerator(/*#__PURE__*/version._regenerator().m(function _callee8() {
922
- var _yield$import, getRequestHeaders, headers;
923
- return version._regenerator().w(function (_context8) {
924
- while (1) switch (_context8.n) {
1062
+ _requestHeaders = version._asyncToGenerator(/*#__PURE__*/version._regenerator().m(function _callee0() {
1063
+ var _yield$import2, getRequestHeaders, headers;
1064
+ return version._regenerator().w(function (_context0) {
1065
+ while (1) switch (_context0.n) {
925
1066
  case 0:
926
- _context8.n = 1;
1067
+ _context0.n = 1;
927
1068
  return Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require('@tanstack/react-start/server')); });
928
1069
  case 1:
929
- _yield$import = _context8.v;
930
- getRequestHeaders = _yield$import.getRequestHeaders;
1070
+ _yield$import2 = _context0.v;
1071
+ getRequestHeaders = _yield$import2.getRequestHeaders;
931
1072
  headers = getRequestHeaders();
932
- return _context8.a(2, {
1073
+ return _context0.a(2, {
933
1074
  get: function get(name) {
934
1075
  var _headers$get2;
935
1076
  return (_headers$get2 = headers.get(name)) !== null && _headers$get2 !== void 0 ? _headers$get2 : null;
936
1077
  }
937
1078
  });
938
1079
  }
939
- }, _callee8);
1080
+ }, _callee0);
940
1081
  }));
941
1082
  return _requestHeaders.apply(this, arguments);
942
1083
  }
@@ -964,17 +1105,17 @@ function requestCookies() {
964
1105
  * } = initValContent(config, valModules);
965
1106
  */
966
1107
  function _requestCookies() {
967
- _requestCookies = version._asyncToGenerator(/*#__PURE__*/version._regenerator().m(function _callee9() {
968
- var _yield$import2, getCookie;
969
- return version._regenerator().w(function (_context9) {
970
- while (1) switch (_context9.n) {
1108
+ _requestCookies = version._asyncToGenerator(/*#__PURE__*/version._regenerator().m(function _callee1() {
1109
+ var _yield$import3, getCookie;
1110
+ return version._regenerator().w(function (_context1) {
1111
+ while (1) switch (_context1.n) {
971
1112
  case 0:
972
- _context9.n = 1;
1113
+ _context1.n = 1;
973
1114
  return Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require('@tanstack/react-start/server')); });
974
1115
  case 1:
975
- _yield$import2 = _context9.v;
976
- getCookie = _yield$import2.getCookie;
977
- return _context9.a(2, {
1116
+ _yield$import3 = _context1.v;
1117
+ getCookie = _yield$import3.getCookie;
1118
+ return _context1.a(2, {
978
1119
  get: function get(name) {
979
1120
  var value = getCookie(name);
980
1121
  return value === undefined ? undefined : {
@@ -984,7 +1125,7 @@ function _requestCookies() {
984
1125
  }
985
1126
  });
986
1127
  }
987
- }, _callee9);
1128
+ }, _callee1);
988
1129
  }));
989
1130
  return _requestCookies.apply(this, arguments);
990
1131
  }
@@ -998,6 +1139,7 @@ function initValContent(config, valModules, opts) {
998
1139
  if (!tanstackVersion) {
999
1140
  throw new Error("Could not get @valbuild/tanstack package version");
1000
1141
  }
1142
+ var draftSourcesScope = createTanStackRequestScope();
1001
1143
  var draftMode = (_opts$draftMode = opts === null || opts === void 0 ? void 0 : opts.draftMode) !== null && _opts$draftMode !== void 0 ? _opts$draftMode : valDraftMode();
1002
1144
  var isEnabled = function isEnabled() {
1003
1145
  return draftMode.isEnabled();
@@ -1026,10 +1168,10 @@ function initValContent(config, valModules, opts) {
1026
1168
  return {
1027
1169
  fetchValStega: initFetchValStega(config, valApiEndpoints,
1028
1170
  // TODO: get from config
1029
- valServerPromise, isEnabled, requestHeaders, requestCookies),
1171
+ valServerPromise, isEnabled, requestHeaders, requestCookies, draftSourcesScope),
1030
1172
  fetchValKeyStega: initFetchValKeyStega(valServerPromise, isEnabled, requestCookies),
1031
- fetchValRouteStega: initFetchValRouteStega(config, valApiEndpoints, valServerPromise, isEnabled, requestHeaders, requestCookies),
1032
- fetchValRouteUrl: initFetchValRouteUrl(config, valApiEndpoints, valServerPromise, isEnabled, requestHeaders, requestCookies)
1173
+ fetchValRouteStega: initFetchValRouteStega(config, valApiEndpoints, valServerPromise, isEnabled, requestHeaders, requestCookies, draftSourcesScope),
1174
+ fetchValRouteUrl: initFetchValRouteUrl(config, valApiEndpoints, valServerPromise, isEnabled, requestHeaders, requestCookies, draftSourcesScope)
1033
1175
  };
1034
1176
  }
1035
1177