@valbuild/tanstack 0.141.1 → 0.143.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.
@@ -1,7 +1,7 @@
1
- import { _ as _asyncToGenerator, a as _regenerator, V as VERSION, s as setValEnableCookieReader } from '../../dist/version-2cca9e77.esm.js';
1
+ import { _ as _asyncToGenerator, a as _regenerator, V as VERSION, s as setValEnableCookieReader } from '../../dist/version-b000d197.esm.js';
2
2
  import { Internal } from '@valbuild/core';
3
3
  import { _ as _objectSpread2, a as _slicedToArray, e as _arrayLikeToArray, f as _unsupportedIterableToArray, b as _createForOfIteratorHelper, d as _defineProperty } from '../../dist/createForOfIteratorHelper-93a62170.esm.js';
4
- import { createValApiRouter, createValServer } from '@valbuild/server';
4
+ import { createValApiRouter, createValServer, proposalSnapshot } from '@valbuild/server';
5
5
  export { InMemoryPatchStore, createPrettierFormatter } from '@valbuild/server';
6
6
  import { _ as _typeof, b as initValRouteFromVal, g as getJsonEntryStegaRoot, i as isJsonValuesRecordSchema, a as getValRouteUrlFromVal } from '../../dist/routeFromVal-1221e70d.esm.js';
7
7
  import { stegaEncode, SET_AUTO_TAG_JSX_ENABLED } from '@valbuild/react/stega';
@@ -483,7 +483,7 @@ function _loadDraftSources() {
483
483
  }));
484
484
  return _loadDraftSources.apply(this, arguments);
485
485
  }
486
- var initFetchValStega = function initFetchValStega(config, valApiEndpoints, valServerPromise, isEnabled, getHeaders, getCookies, getDraftSourcesScope) {
486
+ var initFetchValStega = function initFetchValStega(config, valApiEndpoints, valServerPromise, isEnabled, getHeaders, getCookies, getDraftSourcesScope, snapshot) {
487
487
  return function (selector) {
488
488
  var exec = /*#__PURE__*/function () {
489
489
  var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2() {
@@ -580,12 +580,17 @@ var initFetchValStega = function initFetchValStega(config, valApiEndpoints, valS
580
580
  if (module) {
581
581
  return module.source;
582
582
  }
583
+ return snapshot === null || snapshot === void 0 ? void 0 : snapshot[path];
583
584
  }
584
585
  }));
585
586
  case 15:
586
- return _context2.a(2, stegaEncode(selector, {
587
+ return _context2.a(2, stegaEncode(selector, _objectSpread2({
587
588
  disabled: !enabled
588
- }));
589
+ }, snapshot !== undefined ? {
590
+ getModule: function getModule(path) {
591
+ return snapshot[path];
592
+ }
593
+ } : {})));
589
594
  }
590
595
  }, _callee2, null, [[9, 11], [5, 8], [1, 3]]);
591
596
  }));
@@ -595,11 +600,17 @@ var initFetchValStega = function initFetchValStega(config, valApiEndpoints, valS
595
600
  }();
596
601
  return exec()["catch"](function (err) {
597
602
  console.error("Val: failed to fetch ", err);
598
- return stegaEncode(selector, {});
603
+ return stegaEncode(selector, _objectSpread2({}, snapshot !== undefined ? {
604
+ getModule: function getModule(path) {
605
+ return snapshot[path];
606
+ }
607
+ } : {}));
599
608
  });
600
609
  };
601
610
  };
602
611
 
612
+ /** A proposal's saved Source, by module: see `ValProposal` in `@valbuild/server`. */
613
+
603
614
  /** What `fetchValDraft` reads: the tree, the entries, and the patches' ops. */
604
615
 
605
616
  /**
@@ -614,98 +625,107 @@ var initFetchValStega = function initFetchValStega(config, valApiEndpoints, valS
614
625
  * a draft page was rendered as the published site and only then replaced, in
615
626
  * the browser, by what the editor holds -- old text first on every load.
616
627
  */
617
- var initFetchValDraft = function initFetchValDraft(valServerPromise, isEnabled, getCookies, getDraftSourcesScope) {
628
+ var initFetchValDraft = function initFetchValDraft(valServerPromise, isEnabled, getCookies, getDraftSourcesScope, snapshot) {
618
629
  return /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3() {
619
- var _yield$getCookies$get, sessionCookie, modules, sources, _i, _Object$entries, _Object$entries$_i, path, module, source, _t6, _t7, _t8, _t9, _t0;
630
+ var onlySnapshot, _yield$getCookies$get, sessionCookie, modules, sources, _i, _Object$entries, _Object$entries$_i, path, module, source, _t6, _t7, _t8, _t9, _t0;
620
631
  return _regenerator().w(function (_context3) {
621
632
  while (1) switch (_context3.p = _context3.n) {
622
633
  case 0:
623
- _context3.p = 0;
624
- _context3.n = 1;
634
+ // At a proposal's address the page needs the snapshot whatever draft mode
635
+ // says, so a reviewer who is not editing sees the proposal too.
636
+ onlySnapshot = snapshot !== undefined ? {
637
+ sources: {},
638
+ snapshot: snapshot,
639
+ draftMode: false
640
+ } : null;
641
+ _context3.p = 1;
642
+ _context3.n = 2;
625
643
  return isEnabled();
626
- case 1:
644
+ case 2:
627
645
  if (_context3.v) {
628
- _context3.n = 2;
646
+ _context3.n = 3;
629
647
  break;
630
648
  }
631
- return _context3.a(2, null);
632
- case 2:
633
- _context3.n = 3;
634
- return getCookies();
649
+ return _context3.a(2, onlySnapshot);
635
650
  case 3:
651
+ _context3.n = 4;
652
+ return getCookies();
653
+ case 4:
636
654
  _t7 = _yield$getCookies$get = _context3.v.get(VAL_SESSION_COOKIE);
637
655
  _t6 = _t7 === null;
638
656
  if (_t6) {
639
- _context3.n = 4;
657
+ _context3.n = 5;
640
658
  break;
641
659
  }
642
660
  _t6 = _yield$getCookies$get === void 0;
643
- case 4:
661
+ case 5:
644
662
  if (!_t6) {
645
- _context3.n = 5;
663
+ _context3.n = 6;
646
664
  break;
647
665
  }
648
666
  _t8 = void 0;
649
- _context3.n = 6;
667
+ _context3.n = 7;
650
668
  break;
651
- case 5:
652
- _t8 = _yield$getCookies$get.value;
653
669
  case 6:
670
+ _t8 = _yield$getCookies$get.value;
671
+ case 7:
654
672
  sessionCookie = _t8;
655
673
  _t9 = memoizePerRequest;
656
- _context3.n = 7;
657
- return getDraftSourcesScope();
658
- case 7:
659
674
  _context3.n = 8;
675
+ return getDraftSourcesScope();
676
+ case 8:
677
+ _context3.n = 9;
660
678
  return _t9(_context3.v, sessionCookie !== null && sessionCookie !== void 0 ? sessionCookie : "", function () {
661
679
  return loadDraftSources(valServerPromise, sessionCookie);
662
680
  });
663
- case 8:
681
+ case 9:
664
682
  modules = _context3.v;
665
683
  if (modules) {
666
- _context3.n = 9;
684
+ _context3.n = 10;
667
685
  break;
668
686
  }
669
- return _context3.a(2, null);
670
- case 9:
687
+ return _context3.a(2, onlySnapshot);
688
+ case 10:
671
689
  sources = {};
672
690
  _i = 0, _Object$entries = Object.entries(modules);
673
- case 10:
691
+ case 11:
674
692
  if (!(_i < _Object$entries.length)) {
675
- _context3.n = 14;
693
+ _context3.n = 15;
676
694
  break;
677
695
  }
678
696
  _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2), path = _Object$entries$_i[0], module = _Object$entries$_i[1];
679
697
  if (!(module.patches === undefined)) {
680
- _context3.n = 11;
698
+ _context3.n = 12;
681
699
  break;
682
700
  }
683
- return _context3.a(3, 13);
684
- case 11:
685
- _context3.n = 12;
686
- return withDraftJsonEntries(valServerPromise, sessionCookie, path, module.source, module.patches.applied);
701
+ return _context3.a(3, 14);
687
702
  case 12:
703
+ _context3.n = 13;
704
+ return withDraftJsonEntries(valServerPromise, sessionCookie, path, module.source, module.patches.applied);
705
+ case 13:
688
706
  source = _context3.v;
689
707
  if (source !== undefined) {
690
708
  sources[path] = source;
691
709
  }
692
- case 13:
710
+ case 14:
693
711
  _i++;
694
- _context3.n = 10;
712
+ _context3.n = 11;
695
713
  break;
696
- case 14:
697
- return _context3.a(2, {
698
- sources: sources
699
- });
700
714
  case 15:
701
- _context3.p = 15;
715
+ return _context3.a(2, _objectSpread2({
716
+ sources: sources
717
+ }, snapshot !== undefined ? {
718
+ snapshot: snapshot
719
+ } : {}));
720
+ case 16:
721
+ _context3.p = 16;
702
722
  _t0 = _context3.v;
703
723
  // Published content, as before this existed: a draft page that renders
704
724
  // the site is a degraded preview, one that fails to render is an outage.
705
725
  console.error("Val: could not read the draft", _t0);
706
- return _context3.a(2, null);
726
+ return _context3.a(2, onlySnapshot);
707
727
  }
708
- }, _callee3, null, [[0, 15]]);
728
+ }, _callee3, null, [[1, 16]]);
709
729
  }));
710
730
  };
711
731
 
@@ -948,7 +968,7 @@ function getHost(headers) {
948
968
  // }
949
969
  // }
950
970
 
951
- var initFetchValRouteStega = function initFetchValRouteStega(config, valApiEndpoints, valServerPromise, isEnabled, getHeaders, getCookies, getDraftSourcesScope) {
971
+ var initFetchValRouteStega = function initFetchValRouteStega(config, valApiEndpoints, valServerPromise, isEnabled, getHeaders, getCookies, getDraftSourcesScope, snapshot) {
952
972
  return /*#__PURE__*/function () {
953
973
  var _ref4 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee4(selector, params) {
954
974
  var resolvedParams, valModule, path, schema, source, url, enabled, draft, content, fetchVal, val, route, _t10;
@@ -1020,7 +1040,7 @@ var initFetchValRouteStega = function initFetchValRouteStega(config, valApiEndpo
1020
1040
  root: getJsonEntryStegaRoot(valModule, url)
1021
1041
  }));
1022
1042
  case 11:
1023
- fetchVal = initFetchValStega(config, valApiEndpoints, valServerPromise, isEnabled, getHeaders, getCookies, getDraftSourcesScope);
1043
+ fetchVal = initFetchValStega(config, valApiEndpoints, valServerPromise, isEnabled, getHeaders, getCookies, getDraftSourcesScope, snapshot);
1024
1044
  _t10 = valModule;
1025
1045
  if (!_t10) {
1026
1046
  _context4.n = 13;
@@ -1301,14 +1321,14 @@ var initFetchValKeyStega = function initFetchValKeyStega(valServerPromise, isEna
1301
1321
  };
1302
1322
  }();
1303
1323
  };
1304
- var initFetchValRouteUrl = function initFetchValRouteUrl(config, valApiEndpoints, valServerPromise, isEnabled, getHeaders, getCookies, getDraftSourcesScope) {
1324
+ var initFetchValRouteUrl = function initFetchValRouteUrl(config, valApiEndpoints, valServerPromise, isEnabled, getHeaders, getCookies, getDraftSourcesScope, snapshot) {
1305
1325
  return /*#__PURE__*/function () {
1306
1326
  var _ref6 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee6(selector, params) {
1307
1327
  var fetchVal, resolvedParams, valModule, path, schema, val, route, _t12, _t13;
1308
1328
  return _regenerator().w(function (_context6) {
1309
1329
  while (1) switch (_context6.n) {
1310
1330
  case 0:
1311
- fetchVal = initFetchValStega(config, valApiEndpoints, valServerPromise, isEnabled, getHeaders, getCookies, getDraftSourcesScope);
1331
+ fetchVal = initFetchValStega(config, valApiEndpoints, valServerPromise, isEnabled, getHeaders, getCookies, getDraftSourcesScope, snapshot);
1312
1332
  if (!(params === undefined)) {
1313
1333
  _context6.n = 1;
1314
1334
  break;
@@ -1434,7 +1454,7 @@ function _requestCookies() {
1434
1454
  return _requestCookies.apply(this, arguments);
1435
1455
  }
1436
1456
  function initValContent(config, valModules, opts) {
1437
- var _opts$draftMode;
1457
+ var _opts$http, _opts$draftMode;
1438
1458
  var coreVersion = Internal.VERSION.core;
1439
1459
  if (!coreVersion) {
1440
1460
  throw new Error("Could not get @valbuild/core package version");
@@ -1444,6 +1464,7 @@ function initValContent(config, valModules, opts) {
1444
1464
  throw new Error("Could not get @valbuild/tanstack package version");
1445
1465
  }
1446
1466
  var draftSourcesScope = createTanStackRequestScope();
1467
+ var snapshot = (opts === null || opts === void 0 || (_opts$http = opts.http) === null || _opts$http === void 0 ? void 0 : _opts$http.proposal) !== undefined ? proposalSnapshot(opts.http.proposal) : undefined;
1447
1468
  var draftMode = (_opts$draftMode = opts === null || opts === void 0 ? void 0 : opts.draftMode) !== null && _opts$draftMode !== void 0 ? _opts$draftMode : valDraftMode();
1448
1469
  var isEnabled = function isEnabled() {
1449
1470
  return draftMode.isEnabled();
@@ -1472,11 +1493,11 @@ function initValContent(config, valModules, opts) {
1472
1493
  return {
1473
1494
  fetchValStega: initFetchValStega(config, valApiEndpoints,
1474
1495
  // TODO: get from config
1475
- valServerPromise, isEnabled, requestHeaders, requestCookies, draftSourcesScope),
1496
+ valServerPromise, isEnabled, requestHeaders, requestCookies, draftSourcesScope, snapshot),
1476
1497
  fetchValKeyStega: initFetchValKeyStega(valServerPromise, isEnabled, requestCookies),
1477
- fetchValRouteStega: initFetchValRouteStega(config, valApiEndpoints, valServerPromise, isEnabled, requestHeaders, requestCookies, draftSourcesScope),
1478
- fetchValRouteUrl: initFetchValRouteUrl(config, valApiEndpoints, valServerPromise, isEnabled, requestHeaders, requestCookies, draftSourcesScope),
1479
- fetchValDraft: initFetchValDraft(valServerPromise, isEnabled, requestCookies, draftSourcesScope)
1498
+ fetchValRouteStega: initFetchValRouteStega(config, valApiEndpoints, valServerPromise, isEnabled, requestHeaders, requestCookies, draftSourcesScope, snapshot),
1499
+ fetchValRouteUrl: initFetchValRouteUrl(config, valApiEndpoints, valServerPromise, isEnabled, requestHeaders, requestCookies, draftSourcesScope, snapshot),
1500
+ fetchValDraft: initFetchValDraft(valServerPromise, isEnabled, requestCookies, draftSourcesScope, snapshot)
1480
1501
  };
1481
1502
  }
1482
1503