@thoughtbot/superglue 2.0.0-alpha.10 → 2.0.0-alpha.11

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.
@@ -628,12 +628,15 @@ function convertToInt(prop) {
628
628
  function isFragmentReference(value) {
629
629
  return !!value && typeof value === "object" && "__id" in value && typeof value.__id === "string";
630
630
  }
631
- function createArrayProxy(arrayData, fragments, dependencies, proxyCache) {
631
+ function createArrayProxy(arrayData, fragments, dependencies, proxyCache, fragmentId) {
632
632
  if (proxyCache && proxyCache.has(arrayData)) {
633
633
  return proxyCache.get(arrayData);
634
634
  }
635
635
  const proxy = new Proxy(arrayData, {
636
636
  get(target, prop) {
637
+ if (prop === "__id" && fragmentId) {
638
+ return fragmentId;
639
+ }
637
640
  if (prop === ORIGINAL_TARGET) {
638
641
  return target;
639
642
  }
@@ -660,7 +663,13 @@ function createArrayProxy(arrayData, fragments, dependencies, proxyCache) {
660
663
  if (!fragmentData) {
661
664
  return void 0;
662
665
  }
663
- return createProxy(fragmentData, fragments, dependencies, proxyCache);
666
+ return createProxy(
667
+ fragmentData,
668
+ fragments,
669
+ dependencies,
670
+ proxyCache,
671
+ item.__id
672
+ );
664
673
  }
665
674
  if (typeof item === "object" && item !== null) {
666
675
  if ("$$typeof" in item) {
@@ -705,12 +714,15 @@ function createArrayProxy(arrayData, fragments, dependencies, proxyCache) {
705
714
  }
706
715
  return proxy;
707
716
  }
708
- function createObjectProxy(objectData, fragments, dependencies, proxyCache) {
717
+ function createObjectProxy(objectData, fragments, dependencies, proxyCache, fragmentId) {
709
718
  if (proxyCache && proxyCache.has(objectData)) {
710
719
  return proxyCache.get(objectData);
711
720
  }
712
721
  const proxy = new Proxy(objectData, {
713
722
  get(target, prop) {
723
+ if (prop === "__id" && fragmentId) {
724
+ return fragmentId;
725
+ }
714
726
  if (prop === ORIGINAL_TARGET) {
715
727
  return target;
716
728
  }
@@ -721,7 +733,13 @@ function createObjectProxy(objectData, fragments, dependencies, proxyCache) {
721
733
  if (!fragmentData) {
722
734
  return void 0;
723
735
  }
724
- return createProxy(fragmentData, fragments, dependencies, proxyCache);
736
+ return createProxy(
737
+ fragmentData,
738
+ fragments,
739
+ dependencies,
740
+ proxyCache,
741
+ value.__id
742
+ );
725
743
  }
726
744
  if (typeof value === "object" && value !== null) {
727
745
  if ("$$typeof" in value) {
@@ -761,7 +779,7 @@ function createObjectProxy(objectData, fragments, dependencies, proxyCache) {
761
779
  }
762
780
  return proxy;
763
781
  }
764
- function createProxy(content, fragments, dependencies, proxyCache) {
782
+ function createProxy(content, fragments, dependencies, proxyCache, fragmentId) {
765
783
  if (!content || typeof content !== "object") {
766
784
  return content;
767
785
  }
@@ -769,9 +787,21 @@ function createProxy(content, fragments, dependencies, proxyCache) {
769
787
  return content;
770
788
  }
771
789
  if (Array.isArray(content)) {
772
- return createArrayProxy(content, fragments, dependencies, proxyCache);
790
+ return createArrayProxy(
791
+ content,
792
+ fragments,
793
+ dependencies,
794
+ proxyCache,
795
+ fragmentId
796
+ );
773
797
  }
774
- return createObjectProxy(content, fragments, dependencies, proxyCache);
798
+ return createObjectProxy(
799
+ content,
800
+ fragments,
801
+ dependencies,
802
+ proxyCache,
803
+ fragmentId
804
+ );
775
805
  }
776
806
  function unproxy(proxy) {
777
807
  if (proxy && typeof proxy === "object" && ORIGINAL_TARGET in proxy) {
@@ -1148,7 +1178,7 @@ var import_react_redux3 = require("react-redux");
1148
1178
  // lib/hooks/useContent.tsx
1149
1179
  var import_react_redux = require("react-redux");
1150
1180
  var import_react = require("react");
1151
- function useContent(fragmentRef) {
1181
+ function useContent(fragmentRef, __type) {
1152
1182
  const superglueState = useSuperglue();
1153
1183
  const currentPageKey = superglueState.currentPageKey;
1154
1184
  const dependencies = (0, import_react.useRef)(/* @__PURE__ */ new Set());
@@ -1179,12 +1209,37 @@ function useContent(fragmentRef) {
1179
1209
  if (fragmentId && !sourceData) {
1180
1210
  return void 0;
1181
1211
  }
1182
- return createProxy(
1212
+ const proxy2 = createProxy(
1183
1213
  sourceData,
1184
1214
  { current: store.getState().fragments },
1185
1215
  dependencies.current,
1186
1216
  proxyCache
1187
1217
  );
1218
+ if (process.env.NODE_ENV !== "production" && __type) {
1219
+ const proxyForValidation = createProxy(
1220
+ sourceData,
1221
+ { current: store.getState().fragments },
1222
+ /* @__PURE__ */ new Set(),
1223
+ /* @__PURE__ */ new WeakMap()
1224
+ );
1225
+ import("@deepkit/type").then(({ resolveReceiveType, validate }) => {
1226
+ const resolvedType = resolveReceiveType(__type);
1227
+ const errors = validate(proxyForValidation, resolvedType);
1228
+ if (errors.length > 0) {
1229
+ const formattedErrors = errors.map((e) => ({
1230
+ path: e.path,
1231
+ message: e.message,
1232
+ code: String(e.code)
1233
+ }));
1234
+ console.error(
1235
+ `[Superglue] Content validation failed for ${fragmentId || "page"}:`,
1236
+ formattedErrors
1237
+ );
1238
+ }
1239
+ }).catch(() => {
1240
+ });
1241
+ }
1242
+ return proxy2;
1188
1243
  }, [sourceData, trackedFragments]);
1189
1244
  return proxy;
1190
1245
  }
@@ -1738,6 +1793,12 @@ var setup = ({
1738
1793
  streamActions
1739
1794
  };
1740
1795
  };
1796
+ if (process.env.NODE_ENV !== "production") {
1797
+ console.info(
1798
+ "%cSuperglue Development Mode: Remember to build for production before deploying.",
1799
+ "font-weight:bold"
1800
+ );
1801
+ }
1741
1802
  function Application({
1742
1803
  initialPage,
1743
1804
  baseUrl,