@farm.js/core 0.1.16 → 0.1.17

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 (180) hide show
  1. package/dist/agent-runtime.d.mts +3 -3
  2. package/dist/agent-runtime.d.ts +3 -3
  3. package/dist/api/client.cjs +62 -28
  4. package/dist/api/client.d.mts +3 -3
  5. package/dist/api/client.d.ts +3 -3
  6. package/dist/api/client.mjs +3 -3
  7. package/dist/api/route-manager.cjs +69 -32
  8. package/dist/api/route-manager.d.mts +3 -3
  9. package/dist/api/route-manager.d.ts +3 -3
  10. package/dist/api/route-manager.mjs +5 -5
  11. package/dist/api/runtime.cjs +65 -29
  12. package/dist/api/runtime.d.mts +3 -3
  13. package/dist/api/runtime.d.ts +3 -3
  14. package/dist/api/runtime.mjs +6 -3
  15. package/dist/{api-client-B-n3pm_Q.d.mts → api-client-Cx54IR5g.d.mts} +2 -2
  16. package/dist/{api-client-C0_NZEBl.d.ts → api-client-DykpaKcY.d.ts} +2 -2
  17. package/dist/api.cjs +106 -33
  18. package/dist/api.d.mts +5 -5
  19. package/dist/api.d.ts +5 -5
  20. package/dist/api.mjs +8 -8
  21. package/dist/{app-AyjEsCBq.d.ts → app-BHY_10Lm.d.ts} +3 -3
  22. package/dist/{app-CYPHeOo_.d.mts → app-BMk0do23.d.mts} +3 -3
  23. package/dist/app-markdown.d.mts +4 -4
  24. package/dist/app-markdown.d.ts +4 -4
  25. package/dist/app-markdown.mjs +3 -3
  26. package/dist/cache.cjs +62 -28
  27. package/dist/cache.d.mts +11 -1
  28. package/dist/cache.d.ts +11 -1
  29. package/dist/cache.mjs +1 -1
  30. package/dist/{chunk-7HDZYYS4.mjs → chunk-4OOBRCJX.mjs} +27 -5
  31. package/dist/{chunk-NHHKW2T6.mjs → chunk-56DAX2BE.mjs} +170 -52
  32. package/dist/{chunk-B76DT5Y6.mjs → chunk-57J3Y7Y3.mjs} +1 -1
  33. package/dist/{chunk-MOQNHLTS.mjs → chunk-5QOEPUYE.mjs} +5 -2
  34. package/dist/{chunk-HKLRP3BN.mjs → chunk-5SPPCN5J.mjs} +1 -1
  35. package/dist/{chunk-LUC2FAGW.mjs → chunk-6VQIKZZO.mjs} +1 -1
  36. package/dist/{chunk-7ZWL7XOU.mjs → chunk-76DG3LF3.mjs} +1 -1
  37. package/dist/{chunk-EWDK36MM.mjs → chunk-A72YEUZ3.mjs} +1 -1
  38. package/dist/{chunk-ZHOIQC6U.mjs → chunk-ATERBVHQ.mjs} +2 -2
  39. package/dist/{chunk-27JNCYEK.mjs → chunk-EN7WTEAY.mjs} +2 -2
  40. package/dist/{chunk-IGO2HEV7.mjs → chunk-F6SJAKFJ.mjs} +62 -28
  41. package/dist/{chunk-GSDIZACQ.mjs → chunk-FG5H2VCJ.mjs} +2 -2
  42. package/dist/{chunk-LZK5CXDW.mjs → chunk-KLSSO6YD.mjs} +2 -2
  43. package/dist/{chunk-KUO3GBPK.mjs → chunk-L6V3P73N.mjs} +1 -1
  44. package/dist/{chunk-TYVVIQ5M.mjs → chunk-MVIWBEJF.mjs} +32 -25
  45. package/dist/{chunk-KTGFMHET.mjs → chunk-N6UROPT7.mjs} +1 -1
  46. package/dist/{chunk-NDD2YVGU.mjs → chunk-NRVGEI5I.mjs} +10 -3
  47. package/dist/{chunk-IXTEENRS.mjs → chunk-QGVJVSNX.mjs} +5 -5
  48. package/dist/{chunk-6SCB2MXB.mjs → chunk-SXHV42UQ.mjs} +16 -1
  49. package/dist/{chunk-OWTIOHON.mjs → chunk-SYGGPS4A.mjs} +2 -2
  50. package/dist/{chunk-NC333MFA.mjs → chunk-TSWW5BVH.mjs} +7 -4
  51. package/dist/{chunk-LK6FGAQR.mjs → chunk-UDBJCUPA.mjs} +7 -4
  52. package/dist/{chunk-NUD6XBMO.mjs → chunk-UTBVHYS3.mjs} +2 -2
  53. package/dist/{chunk-76MNRHTS.mjs → chunk-UUYF3CHN.mjs} +2 -2
  54. package/dist/{chunk-VVTREAG5.mjs → chunk-WD4YXVLV.mjs} +11 -3
  55. package/dist/{chunk-UQZPTIML.mjs → chunk-WD5PNSOB.mjs} +2 -2
  56. package/dist/{chunk-DPZUDPVJ.mjs → chunk-XP777LRD.mjs} +1 -1
  57. package/dist/{chunk-KATQ6I56.mjs → chunk-XWAYMDLB.mjs} +1 -1
  58. package/dist/{chunk-IL5RWYK7.mjs → chunk-YD4J4XCI.mjs} +1 -1
  59. package/dist/{chunk-Q3MDL7TM.mjs → chunk-ZCNJKLA2.mjs} +30 -11
  60. package/dist/{client-plugins-CqVtZi5X.d.ts → client-plugins-C089bQhN.d.ts} +2 -2
  61. package/dist/{client-plugins-CIPRtSsW.d.mts → client-plugins-JXXmZliS.d.mts} +2 -2
  62. package/dist/client-plugins.d.mts +3 -3
  63. package/dist/client-plugins.d.ts +3 -3
  64. package/dist/client.cjs +62 -28
  65. package/dist/client.d.mts +8 -8
  66. package/dist/client.d.ts +8 -8
  67. package/dist/client.mjs +6 -6
  68. package/dist/config.d.mts +3 -3
  69. package/dist/config.d.ts +3 -3
  70. package/dist/cron.mjs +2 -2
  71. package/dist/{devtools-IU7LKZOH.mjs → devtools-UFVTMQX5.mjs} +7 -7
  72. package/dist/docs.cjs +18 -10
  73. package/dist/docs.mjs +9 -9
  74. package/dist/{endpoint-kSAxE52R.d.ts → endpoint-1zA994xL.d.ts} +1 -1
  75. package/dist/{endpoint-Bu3XgeMK.d.mts → endpoint-DAc96i93.d.mts} +1 -1
  76. package/dist/env.cjs +39 -5
  77. package/dist/env.d.mts +5 -3
  78. package/dist/env.d.ts +5 -3
  79. package/dist/env.mjs +2 -1
  80. package/dist/index.cjs +311 -93
  81. package/dist/index.d.mts +14 -14
  82. package/dist/index.d.ts +14 -14
  83. package/dist/index.mjs +34 -34
  84. package/dist/integrations.d.mts +3 -3
  85. package/dist/integrations.d.ts +3 -3
  86. package/dist/internal/app-markdown-runtime.d.mts +3 -3
  87. package/dist/internal/app-markdown-runtime.d.ts +3 -3
  88. package/dist/internal/app-markdown-runtime.mjs +2 -2
  89. package/dist/internal/build-runtime.cjs +342 -121
  90. package/dist/internal/build-runtime.d.mts +5 -5
  91. package/dist/internal/build-runtime.d.ts +5 -5
  92. package/dist/internal/build-runtime.mjs +23 -23
  93. package/dist/internal/cli-runtime.cjs +77 -31
  94. package/dist/internal/cli-runtime.mjs +13 -13
  95. package/dist/internal/client-error-overlay.cjs +1 -1
  96. package/dist/internal/client-error-overlay.mjs +1 -1
  97. package/dist/internal/compression-runtime.d.mts +3 -3
  98. package/dist/internal/compression-runtime.d.ts +3 -3
  99. package/dist/internal/config-runtime.cjs +14 -2
  100. package/dist/internal/config-runtime.d.mts +4 -4
  101. package/dist/internal/config-runtime.d.ts +4 -4
  102. package/dist/internal/config-runtime.mjs +7 -7
  103. package/dist/internal/product-telemetry-runtime.cjs +1 -1
  104. package/dist/internal/product-telemetry-runtime.mjs +1 -1
  105. package/dist/internal/production-runtime.cjs +101 -41
  106. package/dist/internal/production-runtime.d.mts +9 -9
  107. package/dist/internal/production-runtime.d.ts +9 -9
  108. package/dist/internal/production-runtime.mjs +6 -6
  109. package/dist/markdown.cjs +16 -1
  110. package/dist/markdown.mjs +1 -1
  111. package/dist/{metadata-8g__AMPM.d.ts → metadata-BcNJP4fq.d.ts} +1 -1
  112. package/dist/{metadata-OMX6wFNf.d.mts → metadata-C1Z9vLbb.d.mts} +1 -1
  113. package/dist/middleware.cjs +10 -3
  114. package/dist/middleware.d.mts +5 -5
  115. package/dist/middleware.d.ts +5 -5
  116. package/dist/middleware.mjs +4 -4
  117. package/dist/{nitro-3N4ZXRYM.mjs → nitro-CVZ36JM5.mjs} +4 -4
  118. package/dist/plugin.cjs +256 -105
  119. package/dist/plugin.d.mts +3 -3
  120. package/dist/plugin.d.ts +3 -3
  121. package/dist/plugin.mjs +19 -19
  122. package/dist/{production-runtime-W3M0eNDV.d.mts → production-runtime-jcrTlRTb.d.mts} +1 -1
  123. package/dist/{production-runtime-BJh7o6Cr.d.ts → production-runtime-oKmC0WU-.d.ts} +1 -1
  124. package/dist/{render-plan-io7pvDNc.d.mts → render-plan-BLIfc4jt.d.mts} +1 -1
  125. package/dist/{render-plan-Be4ZGTJP.d.ts → render-plan-DOB9cV-h.d.ts} +1 -1
  126. package/dist/renderer-client.cjs +62 -28
  127. package/dist/renderer-client.d.mts +5 -5
  128. package/dist/renderer-client.d.ts +5 -5
  129. package/dist/renderer-client.mjs +3 -3
  130. package/dist/{request-DZkHYQ89.d.mts → request-Cr53NRHr.d.mts} +1 -1
  131. package/dist/{request-G8JhKr4F.d.ts → request-Dt2gNuQD.d.ts} +1 -1
  132. package/dist/request.d.mts +4 -4
  133. package/dist/request.d.ts +4 -4
  134. package/dist/{route-C_eLaFTZ.d.mts → route-B0XrsrFk.d.mts} +1 -1
  135. package/dist/{route-BxNJT447.d.ts → route-DOEpbyWZ.d.ts} +1 -1
  136. package/dist/{route-rendering-BcLLPJgN.d.ts → route-rendering-CWYd8Mv1.d.ts} +1 -1
  137. package/dist/{route-rendering-CbAKr1TY.d.mts → route-rendering-CeFBEAoZ.d.mts} +1 -1
  138. package/dist/routes.cjs +68 -31
  139. package/dist/routes.d.mts +4 -4
  140. package/dist/routes.d.ts +4 -4
  141. package/dist/routes.mjs +2 -2
  142. package/dist/server-fn-client.d.mts +3 -3
  143. package/dist/server-fn-client.d.ts +3 -3
  144. package/dist/server-fn.cjs +72 -30
  145. package/dist/server-fn.d.mts +1 -1
  146. package/dist/server-fn.d.ts +1 -1
  147. package/dist/server-fn.mjs +2 -2
  148. package/dist/server-plugins.d.mts +4 -4
  149. package/dist/server-plugins.d.ts +4 -4
  150. package/dist/server-query-client.cjs +62 -28
  151. package/dist/server-query-client.d.mts +1 -1
  152. package/dist/server-query-client.d.ts +1 -1
  153. package/dist/server-query-client.mjs +4 -4
  154. package/dist/server-query.cjs +72 -30
  155. package/dist/server-query.d.mts +1 -1
  156. package/dist/server-query.d.ts +1 -1
  157. package/dist/server-query.mjs +3 -3
  158. package/dist/server.cjs +239 -80
  159. package/dist/server.d.mts +9 -9
  160. package/dist/server.d.ts +9 -9
  161. package/dist/server.mjs +22 -22
  162. package/dist/{spa-router-BcS_4nqm.d.mts → spa-router-CQWiYGxS.d.mts} +2 -2
  163. package/dist/{spa-router-BzFBUJkn.d.ts → spa-router-Wjiw-8hB.d.ts} +2 -2
  164. package/dist/testing.cjs +73 -32
  165. package/dist/testing.d.mts +3 -3
  166. package/dist/testing.d.ts +3 -3
  167. package/dist/testing.mjs +11 -7
  168. package/dist/{utils-C4yrAhNc.d.ts → utils-B0XJmG_b.d.ts} +1 -1
  169. package/dist/{utils-5kQP1mFR.d.mts → utils-uUxF0K0P.d.mts} +1 -1
  170. package/dist/version.cjs +1 -1
  171. package/dist/version.mjs +1 -1
  172. package/dist/vite.cjs +260 -109
  173. package/dist/vite.d.mts +3 -3
  174. package/dist/vite.d.ts +3 -3
  175. package/dist/vite.mjs +19 -19
  176. package/dist/workflows.mjs +2 -2
  177. package/package.json +2 -2
  178. package/dist/{chunk-VO5SCWF5.mjs → chunk-BNGS6KJ6.mjs} +0 -0
  179. package/dist/{chunk-MUUZJLCI.mjs → chunk-EGJDUF4Q.mjs} +3 -3
  180. package/dist/{chunk-4L7SZOHZ.mjs → chunk-YHOCRI4H.mjs} +3 -3
package/dist/routes.cjs CHANGED
@@ -428,6 +428,8 @@ var _FarmDataCache = class _FarmDataCache {
428
428
  constructor(config = {}) {
429
429
  this.entries = /* @__PURE__ */ new Map();
430
430
  this.inflight = /* @__PURE__ */ new Map();
431
+ /** Local entries by tag, so tag counts and pruning never scan unrelated entries. */
432
+ this.entriesByTag = /* @__PURE__ */ new Map();
431
433
  this.invalidatedTagVersions = /* @__PURE__ */ new Map();
432
434
  this.activeGenerations = /* @__PURE__ */ new Set();
433
435
  this.version = 0;
@@ -446,6 +448,7 @@ var _FarmDataCache = class _FarmDataCache {
446
448
  configure(config = {}) {
447
449
  this.generation++;
448
450
  this.entries.clear();
451
+ this.entriesByTag.clear();
449
452
  this.inflight.clear();
450
453
  this.invalidatedTagVersions.clear();
451
454
  this.activeGenerations.clear();
@@ -612,14 +615,12 @@ var _FarmDataCache = class _FarmDataCache {
612
615
  return entry;
613
616
  }
614
617
  delete(key) {
615
- const deleted = this.entries.delete(key);
616
- if (deleted) this.pruneInvalidatedTagVersions();
618
+ const deleted = this.deleteLocalEntry(key);
617
619
  emitFarmEvent({ type: "cache.delete", key, deleted });
618
620
  return deleted;
619
621
  }
620
622
  async deleteAsync(key) {
621
- const deleted = this.entries.delete(key);
622
- if (deleted) this.pruneInvalidatedTagVersions();
623
+ const deleted = this.deleteLocalEntry(key);
623
624
  if (this.adapter) {
624
625
  await this.adapter.delete(this.createAdapterKey(key));
625
626
  }
@@ -630,6 +631,7 @@ var _FarmDataCache = class _FarmDataCache {
630
631
  const count = this.entries.size;
631
632
  this.generation++;
632
633
  this.entries.clear();
634
+ this.entriesByTag.clear();
633
635
  this.inflight.clear();
634
636
  this.invalidatedTagVersions.clear();
635
637
  this.activeGenerations.clear();
@@ -715,23 +717,32 @@ var _FarmDataCache = class _FarmDataCache {
715
717
  return cached.value;
716
718
  }
717
719
  const inflight = this.inflight.get(key);
718
- if (inflight) {
720
+ if (inflight && !this.wasInvalidatedSince(inflight.tags, inflight.startVersion)) {
719
721
  emitFarmEvent({ type: "cache.dedupe", key });
720
- return inflight;
722
+ return inflight.promise;
721
723
  }
722
724
  const tags = Array.from(normalizeCacheOptionsTags(options));
723
725
  const generation = this.generation;
726
+ const startVersion = this.version;
724
727
  const promise = this.fillCacheEntry(key, producer, options, tags, generation).catch((error) => {
725
728
  emitFarmEvent({ type: "cache.error", key, operation: "set", error });
726
729
  throw error;
727
730
  }).finally(() => {
728
- if (this.inflight.get(key) === promise) {
731
+ if (this.inflight.get(key)?.promise === promise) {
729
732
  this.inflight.delete(key);
730
733
  }
731
734
  });
732
- this.inflight.set(key, promise);
735
+ this.inflight.set(key, { promise, tags, startVersion });
733
736
  return promise;
734
737
  }
738
+ /** A fill that started before one of its tags was invalidated cannot satisfy later readers. */
739
+ wasInvalidatedSince(tags, version) {
740
+ for (const tag of tags) {
741
+ const invalidatedVersion = this.invalidatedTagVersions.get(tag);
742
+ if (invalidatedVersion !== void 0 && invalidatedVersion > version) return true;
743
+ }
744
+ return false;
745
+ }
735
746
  async fillCacheEntry(key, producer, options, tags, generation) {
736
747
  const adapter = this.adapter;
737
748
  const namespace = this.namespace;
@@ -772,7 +783,7 @@ var _FarmDataCache = class _FarmDataCache {
772
783
  return value;
773
784
  } finally {
774
785
  this.activeGenerations.delete(activeGeneration);
775
- this.pruneInvalidatedTagVersions();
786
+ this.pruneInvalidatedTagVersions(activeGeneration.tags);
776
787
  if (leaseToken && adapter?.releaseLease) {
777
788
  try {
778
789
  await adapter.releaseLease(leaseKey, leaseToken);
@@ -817,18 +828,9 @@ var _FarmDataCache = class _FarmDataCache {
817
828
  }
818
829
  return void 0;
819
830
  }
820
- countEntriesForTag(tag) {
821
- let count = 0;
822
- for (const entry of this.entries.values()) {
823
- if (entry.tags.has(tag)) {
824
- count++;
825
- }
826
- }
827
- return count;
828
- }
829
831
  countEntriesForTags(tags) {
830
832
  let count = 0;
831
- for (const entry of this.entries.values()) {
833
+ for (const entry of this.entriesByTag.get(tags[0]) ?? []) {
832
834
  if (tags.every((tag) => entry.tags.has(tag))) {
833
835
  count++;
834
836
  }
@@ -836,10 +838,10 @@ var _FarmDataCache = class _FarmDataCache {
836
838
  return count;
837
839
  }
838
840
  invalidateTag(normalizedTag) {
839
- const count = this.countEntriesForTag(normalizedTag);
841
+ const count = this.entriesByTag.get(normalizedTag)?.size ?? 0;
840
842
  this.invalidatedTagVersions.delete(normalizedTag);
841
843
  this.invalidatedTagVersions.set(normalizedTag, ++this.version);
842
- this.pruneInvalidatedTagVersions();
844
+ this.pruneInvalidatedTagVersions([normalizedTag]);
843
845
  return count;
844
846
  }
845
847
  toPublicEntry(entry) {
@@ -869,19 +871,51 @@ var _FarmDataCache = class _FarmDataCache {
869
871
  this.entries.set(key, entry);
870
872
  }
871
873
  storeLocalEntry(entry) {
872
- this.entries.delete(entry.key);
874
+ const removed = [];
875
+ const replaced = this.detachLocalEntry(entry.key);
876
+ if (replaced) removed.push(replaced);
873
877
  this.entries.set(entry.key, entry);
878
+ for (const tag of entry.tags) {
879
+ let tagged = this.entriesByTag.get(tag);
880
+ if (!tagged) this.entriesByTag.set(tag, tagged = /* @__PURE__ */ new Set());
881
+ tagged.add(entry);
882
+ }
874
883
  while (this.entries.size > this.maxEntries) {
875
884
  const oldestKey = this.entries.keys().next().value;
876
885
  if (oldestKey === void 0) break;
877
- this.entries.delete(oldestKey);
886
+ removed.push(this.detachLocalEntry(oldestKey));
878
887
  }
879
- this.pruneInvalidatedTagVersions();
888
+ for (const removedEntry of removed) this.pruneInvalidatedTagVersions(removedEntry.tags);
889
+ }
890
+ deleteLocalEntry(key) {
891
+ const entry = this.detachLocalEntry(key);
892
+ if (!entry) return false;
893
+ this.pruneInvalidatedTagVersions(entry.tags);
894
+ return true;
880
895
  }
881
- pruneInvalidatedTagVersions() {
882
- tags: for (const [tag, invalidatedVersion] of this.invalidatedTagVersions) {
883
- for (const entry of this.entries.values()) {
884
- if (entry.tags.has(tag) && entry.createdVersion < invalidatedVersion) continue tags;
896
+ detachLocalEntry(key) {
897
+ const entry = this.entries.get(key);
898
+ if (!entry) return void 0;
899
+ this.entries.delete(key);
900
+ for (const tag of entry.tags) {
901
+ const tagged = this.entriesByTag.get(tag);
902
+ if (!tagged) continue;
903
+ tagged.delete(entry);
904
+ if (tagged.size === 0) this.entriesByTag.delete(tag);
905
+ }
906
+ return entry;
907
+ }
908
+ /**
909
+ * Drop invalidation versions that no local entry or active fill can be stale against.
910
+ * Callers pass only the tags whose dependents just changed, so the cost is bounded by
911
+ * the entries sharing those tags rather than by the whole cache.
912
+ */
913
+ pruneInvalidatedTagVersions(tags) {
914
+ tags: for (const tag of tags) {
915
+ const invalidatedVersion = this.invalidatedTagVersions.get(tag);
916
+ if (invalidatedVersion === void 0) continue;
917
+ for (const entry of this.entriesByTag.get(tag) ?? []) {
918
+ if (entry.createdVersion < invalidatedVersion) continue tags;
885
919
  }
886
920
  for (const generation of this.activeGenerations) {
887
921
  if (generation.tags.has(tag) && generation.createdVersion < invalidatedVersion)
@@ -2066,6 +2100,7 @@ function createProgrammaticPageComponent(route, rendererRuntime) {
2066
2100
  }
2067
2101
  return rendererRuntime.createElement(...args);
2068
2102
  }, "createElement");
2103
+ const markFunctionComponent = /* @__PURE__ */ __name((component) => rendererRuntime?.markFunctionComponent?.(component) ?? component, "markFunctionComponent");
2069
2104
  const Component = route.component;
2070
2105
  if (route.pending) {
2071
2106
  const PendingComponent = route.pending;
@@ -2087,7 +2122,9 @@ function createProgrammaticPageComponent(route, rendererRuntime) {
2087
2122
  throw error;
2088
2123
  }
2089
2124
  }, "FarmProgrammaticPageContent");
2090
- const PageContent = FarmProgrammaticPageContent2;
2125
+ const PageContent = markFunctionComponent(
2126
+ FarmProgrammaticPageContent2
2127
+ );
2091
2128
  const FarmProgrammaticPage = /* @__PURE__ */ __name(function FarmProgrammaticPage2(props) {
2092
2129
  return createElement(
2093
2130
  rendererRuntime.Suspense,
@@ -2097,7 +2134,7 @@ function createProgrammaticPageComponent(route, rendererRuntime) {
2097
2134
  createElement(PageContent, props)
2098
2135
  );
2099
2136
  }, "FarmProgrammaticPage");
2100
- return FarmProgrammaticPage;
2137
+ return markFunctionComponent(FarmProgrammaticPage);
2101
2138
  }
2102
2139
  const FarmProgrammaticPageContent = /* @__PURE__ */ __name(async function FarmProgrammaticPageContent2(props) {
2103
2140
  try {
@@ -2116,7 +2153,7 @@ function createProgrammaticPageComponent(route, rendererRuntime) {
2116
2153
  throw error;
2117
2154
  }
2118
2155
  }, "FarmProgrammaticPageContent");
2119
- return FarmProgrammaticPageContent;
2156
+ return markFunctionComponent(FarmProgrammaticPageContent);
2120
2157
  }
2121
2158
  __name(createProgrammaticPageComponent, "createProgrammaticPageComponent");
2122
2159
  function readProgrammaticRouteProps(route, props, resources) {
package/dist/routes.d.mts CHANGED
@@ -1,11 +1,11 @@
1
- import { F as FarmRouteRuntimeConfig, L as LayoutProps, M as Metadata, e as FarmRouteRuntime, f as FarmRouteRegions, g as FarmRouteMaxDuration, h as FarmAppContext, i as PageProps, j as PluginContextProps, k as RouteModule, P as ParsedRoute } from './client-plugins-CIPRtSsW.mjs';
1
+ import { F as FarmRouteRuntimeConfig, L as LayoutProps, M as Metadata, e as FarmRouteRuntime, f as FarmRouteRegions, g as FarmRouteMaxDuration, h as FarmAppContext, i as PageProps, j as PluginContextProps, k as RouteModule, P as ParsedRoute } from './client-plugins-JXXmZliS.mjs';
2
2
  import { ComponentType } from 'react';
3
3
  import { RouteDataCacheKey } from './cache.mjs';
4
4
  import { ServerFn } from './server-fn.mjs';
5
5
  import { FarmServerRendererRuntime } from './renderer.mjs';
6
6
  import './lifecycle-DK06VuKP.mjs';
7
- import './route-C_eLaFTZ.mjs';
8
- import './endpoint-Bu3XgeMK.mjs';
7
+ import './route-B0XrsrFk.mjs';
8
+ import './endpoint-DAc96i93.mjs';
9
9
  import 'http';
10
10
  import './markdown.mjs';
11
11
  import './types-Cc8l9IqS.mjs';
@@ -261,7 +261,7 @@ declare function parseProgrammaticRouteModuleId(moduleId: string): {
261
261
  routePath: string;
262
262
  } | null;
263
263
  declare function parseProgrammaticRoutePath(routePath: string, type?: ParsedRoute["type"]): ParsedRoute;
264
- declare function createRouteModuleFromProgrammaticPage(route: ProgrammaticPageRoute, rendererRuntime?: Pick<FarmServerRendererRuntime, "createElement" | "Suspense">): RouteModule;
264
+ declare function createRouteModuleFromProgrammaticPage(route: ProgrammaticPageRoute, rendererRuntime?: Pick<FarmServerRendererRuntime, "createElement" | "Suspense" | "markFunctionComponent">): RouteModule;
265
265
  declare function createLayoutModuleFromProgrammaticLayout(route: ProgrammaticLayoutRoute): {
266
266
  metadata: (Metadata & Record<string, any>) | undefined;
267
267
  generateMetadata: ((props: {
package/dist/routes.d.ts CHANGED
@@ -1,11 +1,11 @@
1
- import { F as FarmRouteRuntimeConfig, L as LayoutProps, M as Metadata, e as FarmRouteRuntime, f as FarmRouteRegions, g as FarmRouteMaxDuration, h as FarmAppContext, i as PageProps, j as PluginContextProps, k as RouteModule, P as ParsedRoute } from './client-plugins-CqVtZi5X.js';
1
+ import { F as FarmRouteRuntimeConfig, L as LayoutProps, M as Metadata, e as FarmRouteRuntime, f as FarmRouteRegions, g as FarmRouteMaxDuration, h as FarmAppContext, i as PageProps, j as PluginContextProps, k as RouteModule, P as ParsedRoute } from './client-plugins-C089bQhN.js';
2
2
  import { ComponentType } from 'react';
3
3
  import { RouteDataCacheKey } from './cache.js';
4
4
  import { ServerFn } from './server-fn.js';
5
5
  import { FarmServerRendererRuntime } from './renderer.js';
6
6
  import './lifecycle-DK06VuKP.js';
7
- import './route-BxNJT447.js';
8
- import './endpoint-kSAxE52R.js';
7
+ import './route-DOEpbyWZ.js';
8
+ import './endpoint-1zA994xL.js';
9
9
  import 'http';
10
10
  import './markdown.js';
11
11
  import './types-Cc8l9IqS.js';
@@ -261,7 +261,7 @@ declare function parseProgrammaticRouteModuleId(moduleId: string): {
261
261
  routePath: string;
262
262
  } | null;
263
263
  declare function parseProgrammaticRoutePath(routePath: string, type?: ParsedRoute["type"]): ParsedRoute;
264
- declare function createRouteModuleFromProgrammaticPage(route: ProgrammaticPageRoute, rendererRuntime?: Pick<FarmServerRendererRuntime, "createElement" | "Suspense">): RouteModule;
264
+ declare function createRouteModuleFromProgrammaticPage(route: ProgrammaticPageRoute, rendererRuntime?: Pick<FarmServerRendererRuntime, "createElement" | "Suspense" | "markFunctionComponent">): RouteModule;
265
265
  declare function createLayoutModuleFromProgrammaticLayout(route: ProgrammaticLayoutRoute): {
266
266
  metadata: (Metadata & Record<string, any>) | undefined;
267
267
  generateMetadata: ((props: {
package/dist/routes.mjs CHANGED
@@ -19,11 +19,11 @@ import {
19
19
  redirect,
20
20
  routesBuilder,
21
21
  scanProgrammaticPagePaths
22
- } from "./chunk-NC333MFA.mjs";
22
+ } from "./chunk-TSWW5BVH.mjs";
23
23
  import "./chunk-SEJ5N6SL.mjs";
24
24
  import "./chunk-EA5K5BKU.mjs";
25
25
  import "./chunk-FS7FLPOG.mjs";
26
- import "./chunk-IGO2HEV7.mjs";
26
+ import "./chunk-F6SJAKFJ.mjs";
27
27
  import "./chunk-4SIYUGRY.mjs";
28
28
  import "./chunk-C4NCTZLM.mjs";
29
29
  import "./chunk-FUZEBRP3.mjs";
@@ -1,12 +1,12 @@
1
1
  import { FormHTMLAttributes, ComponentType } from 'react';
2
2
  import { ServerFn } from './server-fn.mjs';
3
- import { R as RetryOptions } from './api-client-B-n3pm_Q.mjs';
3
+ import { R as RetryOptions } from './api-client-Cx54IR5g.mjs';
4
4
  import './cache.mjs';
5
5
  import './server-fn-error-DDh14a0V.mjs';
6
- import './endpoint-Bu3XgeMK.mjs';
6
+ import './endpoint-DAc96i93.mjs';
7
7
  import './integration-api-BbaiokCC.mjs';
8
8
  import './client-cache-di_Nasxa.mjs';
9
- import './route-C_eLaFTZ.mjs';
9
+ import './route-B0XrsrFk.mjs';
10
10
 
11
11
  type ServerFnActionStatus = "idle" | "pending" | "success" | "error";
12
12
  type ServerFnSubmit<TInput, TResult> = [unknown] extends [TInput] ? (input?: TInput | FormData) => Promise<TResult> : (input: TInput | FormData) => Promise<TResult>;
@@ -1,12 +1,12 @@
1
1
  import { FormHTMLAttributes, ComponentType } from 'react';
2
2
  import { ServerFn } from './server-fn.js';
3
- import { R as RetryOptions } from './api-client-C0_NZEBl.js';
3
+ import { R as RetryOptions } from './api-client-DykpaKcY.js';
4
4
  import './cache.js';
5
5
  import './server-fn-error-DDh14a0V.js';
6
- import './endpoint-kSAxE52R.js';
6
+ import './endpoint-1zA994xL.js';
7
7
  import './integration-api-BbaiokCC.js';
8
8
  import './client-cache-Deoqq-nM.js';
9
- import './route-BxNJT447.js';
9
+ import './route-DOEpbyWZ.js';
10
10
 
11
11
  type ServerFnActionStatus = "idle" | "pending" | "success" | "error";
12
12
  type ServerFnSubmit<TInput, TResult> = [unknown] extends [TInput] ? (input?: TInput | FormData) => Promise<TResult> : (input: TInput | FormData) => Promise<TResult>;
@@ -594,6 +594,8 @@ var _FarmDataCache = class _FarmDataCache {
594
594
  constructor(config = {}) {
595
595
  this.entries = /* @__PURE__ */ new Map();
596
596
  this.inflight = /* @__PURE__ */ new Map();
597
+ /** Local entries by tag, so tag counts and pruning never scan unrelated entries. */
598
+ this.entriesByTag = /* @__PURE__ */ new Map();
597
599
  this.invalidatedTagVersions = /* @__PURE__ */ new Map();
598
600
  this.activeGenerations = /* @__PURE__ */ new Set();
599
601
  this.version = 0;
@@ -612,6 +614,7 @@ var _FarmDataCache = class _FarmDataCache {
612
614
  configure(config = {}) {
613
615
  this.generation++;
614
616
  this.entries.clear();
617
+ this.entriesByTag.clear();
615
618
  this.inflight.clear();
616
619
  this.invalidatedTagVersions.clear();
617
620
  this.activeGenerations.clear();
@@ -778,14 +781,12 @@ var _FarmDataCache = class _FarmDataCache {
778
781
  return entry;
779
782
  }
780
783
  delete(key) {
781
- const deleted = this.entries.delete(key);
782
- if (deleted) this.pruneInvalidatedTagVersions();
784
+ const deleted = this.deleteLocalEntry(key);
783
785
  emitFarmEvent({ type: "cache.delete", key, deleted });
784
786
  return deleted;
785
787
  }
786
788
  async deleteAsync(key) {
787
- const deleted = this.entries.delete(key);
788
- if (deleted) this.pruneInvalidatedTagVersions();
789
+ const deleted = this.deleteLocalEntry(key);
789
790
  if (this.adapter) {
790
791
  await this.adapter.delete(this.createAdapterKey(key));
791
792
  }
@@ -796,6 +797,7 @@ var _FarmDataCache = class _FarmDataCache {
796
797
  const count = this.entries.size;
797
798
  this.generation++;
798
799
  this.entries.clear();
800
+ this.entriesByTag.clear();
799
801
  this.inflight.clear();
800
802
  this.invalidatedTagVersions.clear();
801
803
  this.activeGenerations.clear();
@@ -881,23 +883,32 @@ var _FarmDataCache = class _FarmDataCache {
881
883
  return cached.value;
882
884
  }
883
885
  const inflight = this.inflight.get(key);
884
- if (inflight) {
886
+ if (inflight && !this.wasInvalidatedSince(inflight.tags, inflight.startVersion)) {
885
887
  emitFarmEvent({ type: "cache.dedupe", key });
886
- return inflight;
888
+ return inflight.promise;
887
889
  }
888
890
  const tags = Array.from(normalizeCacheOptionsTags(options));
889
891
  const generation = this.generation;
892
+ const startVersion = this.version;
890
893
  const promise = this.fillCacheEntry(key, producer, options, tags, generation).catch((error) => {
891
894
  emitFarmEvent({ type: "cache.error", key, operation: "set", error });
892
895
  throw error;
893
896
  }).finally(() => {
894
- if (this.inflight.get(key) === promise) {
897
+ if (this.inflight.get(key)?.promise === promise) {
895
898
  this.inflight.delete(key);
896
899
  }
897
900
  });
898
- this.inflight.set(key, promise);
901
+ this.inflight.set(key, { promise, tags, startVersion });
899
902
  return promise;
900
903
  }
904
+ /** A fill that started before one of its tags was invalidated cannot satisfy later readers. */
905
+ wasInvalidatedSince(tags, version) {
906
+ for (const tag of tags) {
907
+ const invalidatedVersion = this.invalidatedTagVersions.get(tag);
908
+ if (invalidatedVersion !== void 0 && invalidatedVersion > version) return true;
909
+ }
910
+ return false;
911
+ }
901
912
  async fillCacheEntry(key, producer, options, tags, generation) {
902
913
  const adapter = this.adapter;
903
914
  const namespace = this.namespace;
@@ -938,7 +949,7 @@ var _FarmDataCache = class _FarmDataCache {
938
949
  return value;
939
950
  } finally {
940
951
  this.activeGenerations.delete(activeGeneration);
941
- this.pruneInvalidatedTagVersions();
952
+ this.pruneInvalidatedTagVersions(activeGeneration.tags);
942
953
  if (leaseToken && adapter?.releaseLease) {
943
954
  try {
944
955
  await adapter.releaseLease(leaseKey, leaseToken);
@@ -983,18 +994,9 @@ var _FarmDataCache = class _FarmDataCache {
983
994
  }
984
995
  return void 0;
985
996
  }
986
- countEntriesForTag(tag) {
987
- let count = 0;
988
- for (const entry of this.entries.values()) {
989
- if (entry.tags.has(tag)) {
990
- count++;
991
- }
992
- }
993
- return count;
994
- }
995
997
  countEntriesForTags(tags) {
996
998
  let count = 0;
997
- for (const entry of this.entries.values()) {
999
+ for (const entry of this.entriesByTag.get(tags[0]) ?? []) {
998
1000
  if (tags.every((tag) => entry.tags.has(tag))) {
999
1001
  count++;
1000
1002
  }
@@ -1002,10 +1004,10 @@ var _FarmDataCache = class _FarmDataCache {
1002
1004
  return count;
1003
1005
  }
1004
1006
  invalidateTag(normalizedTag) {
1005
- const count = this.countEntriesForTag(normalizedTag);
1007
+ const count = this.entriesByTag.get(normalizedTag)?.size ?? 0;
1006
1008
  this.invalidatedTagVersions.delete(normalizedTag);
1007
1009
  this.invalidatedTagVersions.set(normalizedTag, ++this.version);
1008
- this.pruneInvalidatedTagVersions();
1010
+ this.pruneInvalidatedTagVersions([normalizedTag]);
1009
1011
  return count;
1010
1012
  }
1011
1013
  toPublicEntry(entry) {
@@ -1035,19 +1037,51 @@ var _FarmDataCache = class _FarmDataCache {
1035
1037
  this.entries.set(key, entry);
1036
1038
  }
1037
1039
  storeLocalEntry(entry) {
1038
- this.entries.delete(entry.key);
1040
+ const removed = [];
1041
+ const replaced = this.detachLocalEntry(entry.key);
1042
+ if (replaced) removed.push(replaced);
1039
1043
  this.entries.set(entry.key, entry);
1044
+ for (const tag of entry.tags) {
1045
+ let tagged = this.entriesByTag.get(tag);
1046
+ if (!tagged) this.entriesByTag.set(tag, tagged = /* @__PURE__ */ new Set());
1047
+ tagged.add(entry);
1048
+ }
1040
1049
  while (this.entries.size > this.maxEntries) {
1041
1050
  const oldestKey = this.entries.keys().next().value;
1042
1051
  if (oldestKey === void 0) break;
1043
- this.entries.delete(oldestKey);
1052
+ removed.push(this.detachLocalEntry(oldestKey));
1053
+ }
1054
+ for (const removedEntry of removed) this.pruneInvalidatedTagVersions(removedEntry.tags);
1055
+ }
1056
+ deleteLocalEntry(key) {
1057
+ const entry = this.detachLocalEntry(key);
1058
+ if (!entry) return false;
1059
+ this.pruneInvalidatedTagVersions(entry.tags);
1060
+ return true;
1061
+ }
1062
+ detachLocalEntry(key) {
1063
+ const entry = this.entries.get(key);
1064
+ if (!entry) return void 0;
1065
+ this.entries.delete(key);
1066
+ for (const tag of entry.tags) {
1067
+ const tagged = this.entriesByTag.get(tag);
1068
+ if (!tagged) continue;
1069
+ tagged.delete(entry);
1070
+ if (tagged.size === 0) this.entriesByTag.delete(tag);
1044
1071
  }
1045
- this.pruneInvalidatedTagVersions();
1072
+ return entry;
1046
1073
  }
1047
- pruneInvalidatedTagVersions() {
1048
- tags: for (const [tag, invalidatedVersion] of this.invalidatedTagVersions) {
1049
- for (const entry of this.entries.values()) {
1050
- if (entry.tags.has(tag) && entry.createdVersion < invalidatedVersion) continue tags;
1074
+ /**
1075
+ * Drop invalidation versions that no local entry or active fill can be stale against.
1076
+ * Callers pass only the tags whose dependents just changed, so the cost is bounded by
1077
+ * the entries sharing those tags rather than by the whole cache.
1078
+ */
1079
+ pruneInvalidatedTagVersions(tags) {
1080
+ tags: for (const tag of tags) {
1081
+ const invalidatedVersion = this.invalidatedTagVersions.get(tag);
1082
+ if (invalidatedVersion === void 0) continue;
1083
+ for (const entry of this.entriesByTag.get(tag) ?? []) {
1084
+ if (entry.createdVersion < invalidatedVersion) continue tags;
1051
1085
  }
1052
1086
  for (const generation of this.activeGenerations) {
1053
1087
  if (generation.tags.has(tag) && generation.createdVersion < invalidatedVersion)
@@ -1534,7 +1568,7 @@ function createServerFn(options) {
1534
1568
  try {
1535
1569
  input = await _parseServerFnSchema(options.input, rawInput, "input");
1536
1570
  } catch (cause) {
1537
- throw labelInputErrors ? new ServerFnInputError(cause) : cause;
1571
+ throw labelInputErrors && isSchemaValidationFailure(cause) ? new ServerFnInputError(cause) : cause;
1538
1572
  }
1539
1573
  const executionContext = getServerActionExecutionContext();
1540
1574
  const request = executionContext?.request ?? _resolveCurrentRequest();
@@ -1754,9 +1788,17 @@ async function _parseServerFnSchema(schema, value, contract, owner = "createServ
1754
1788
  throw new TypeError(`${owner} ${contract} must provide parse, parseAsync, or safeParse`);
1755
1789
  }
1756
1790
  __name(_parseServerFnSchema, "_parseServerFnSchema");
1791
+ var schemaValidationFailures = /* @__PURE__ */ new WeakSet();
1792
+ function isSchemaValidationFailure(error) {
1793
+ if (!error || typeof error !== "object") return false;
1794
+ return schemaValidationFailures.has(error) || Array.isArray(error.issues);
1795
+ }
1796
+ __name(isSchemaValidationFailure, "isSchemaValidationFailure");
1757
1797
  function unwrapSafeParseResult(result) {
1758
1798
  if (result && typeof result === "object" && "success" in result && result.success === false) {
1759
- throw result.error;
1799
+ const error = result.error;
1800
+ if (error && typeof error === "object") schemaValidationFailures.add(error);
1801
+ throw error;
1760
1802
  }
1761
1803
  if (result && typeof result === "object" && "success" in result && result.success === true) {
1762
1804
  return result.data;
@@ -1,7 +1,7 @@
1
1
  import { FarmCacheInvalidationTarget } from './cache.mjs';
2
2
  import { S as ServerFnFailure, a as ServerActionError } from './server-fn-error-DDh14a0V.mjs';
3
3
  export { F as FARM_SERVER_FN_FAILURE_SYMBOL, b as SerializedServerFnFailure, c as createServerFnTransportError, i as isServerFnFailure } from './server-fn-error-DDh14a0V.mjs';
4
- import { d as EndpointMCPMetadata } from './endpoint-Bu3XgeMK.mjs';
4
+ import { d as EndpointMCPMetadata } from './endpoint-DAc96i93.mjs';
5
5
 
6
6
  type MaybePromise<T> = T | Promise<T>;
7
7
  type ServerFnSchema = {
@@ -1,7 +1,7 @@
1
1
  import { FarmCacheInvalidationTarget } from './cache.js';
2
2
  import { S as ServerFnFailure, a as ServerActionError } from './server-fn-error-DDh14a0V.js';
3
3
  export { F as FARM_SERVER_FN_FAILURE_SYMBOL, b as SerializedServerFnFailure, c as createServerFnTransportError, i as isServerFnFailure } from './server-fn-error-DDh14a0V.js';
4
- import { d as EndpointMCPMetadata } from './endpoint-kSAxE52R.js';
4
+ import { d as EndpointMCPMetadata } from './endpoint-1zA994xL.js';
5
5
 
6
6
  type MaybePromise<T> = T | Promise<T>;
7
7
  type ServerFnSchema = {
@@ -8,7 +8,7 @@ import {
8
8
  createServerFn,
9
9
  createServerFunctionDescriptor,
10
10
  createServerMiddleware
11
- } from "./chunk-VVTREAG5.mjs";
11
+ } from "./chunk-WD4YXVLV.mjs";
12
12
  import {
13
13
  FARM_SERVER_FN_FAILURE_SYMBOL,
14
14
  ServerActionError,
@@ -18,7 +18,7 @@ import {
18
18
  } from "./chunk-QCFFHV5H.mjs";
19
19
  import "./chunk-FP2INE7H.mjs";
20
20
  import "./chunk-XF7Q24PF.mjs";
21
- import "./chunk-IGO2HEV7.mjs";
21
+ import "./chunk-F6SJAKFJ.mjs";
22
22
  import "./chunk-4SIYUGRY.mjs";
23
23
  import "./chunk-C4NCTZLM.mjs";
24
24
  import "./chunk-FUZEBRP3.mjs";
@@ -1,10 +1,10 @@
1
- import { ch as RedirectConfig, b as FarmRequest, c as FarmResponse, d as FarmPluginContext, a as FarmPlugin, ci as HeaderConfig, cj as RewriteConfig } from './client-plugins-CIPRtSsW.mjs';
2
- export { bF as FarmPluginLifecycle, bO as FarmPluginRuntimeEndpoint, bP as FarmPluginRuntimeEndpointEvent, bG as FarmRequestPluginContext, bH as FarmRequestStore } from './client-plugins-CIPRtSsW.mjs';
1
+ import { ch as RedirectConfig, b as FarmRequest, c as FarmResponse, d as FarmPluginContext, a as FarmPlugin, ci as HeaderConfig, cj as RewriteConfig } from './client-plugins-JXXmZliS.mjs';
2
+ export { bF as FarmPluginLifecycle, bO as FarmPluginRuntimeEndpoint, bP as FarmPluginRuntimeEndpointEvent, bG as FarmRequestPluginContext, bH as FarmRequestStore } from './client-plugins-JXXmZliS.mjs';
3
3
  import { R as ResolvedFarmI18nConfig } from './types-Z0aotQ8w.mjs';
4
4
  export { createCompressionPlugin } from './internal/compression-runtime.mjs';
5
5
  import './lifecycle-DK06VuKP.mjs';
6
- import './route-C_eLaFTZ.mjs';
7
- import './endpoint-Bu3XgeMK.mjs';
6
+ import './route-B0XrsrFk.mjs';
7
+ import './endpoint-DAc96i93.mjs';
8
8
  import './cache.mjs';
9
9
  import './renderer.mjs';
10
10
  import './deployment.mjs';
@@ -1,10 +1,10 @@
1
- import { ch as RedirectConfig, b as FarmRequest, c as FarmResponse, d as FarmPluginContext, a as FarmPlugin, ci as HeaderConfig, cj as RewriteConfig } from './client-plugins-CqVtZi5X.js';
2
- export { bF as FarmPluginLifecycle, bO as FarmPluginRuntimeEndpoint, bP as FarmPluginRuntimeEndpointEvent, bG as FarmRequestPluginContext, bH as FarmRequestStore } from './client-plugins-CqVtZi5X.js';
1
+ import { ch as RedirectConfig, b as FarmRequest, c as FarmResponse, d as FarmPluginContext, a as FarmPlugin, ci as HeaderConfig, cj as RewriteConfig } from './client-plugins-C089bQhN.js';
2
+ export { bF as FarmPluginLifecycle, bO as FarmPluginRuntimeEndpoint, bP as FarmPluginRuntimeEndpointEvent, bG as FarmRequestPluginContext, bH as FarmRequestStore } from './client-plugins-C089bQhN.js';
3
3
  import { R as ResolvedFarmI18nConfig } from './types-Z0aotQ8w.js';
4
4
  export { createCompressionPlugin } from './internal/compression-runtime.js';
5
5
  import './lifecycle-DK06VuKP.js';
6
- import './route-BxNJT447.js';
7
- import './endpoint-kSAxE52R.js';
6
+ import './route-DOEpbyWZ.js';
7
+ import './endpoint-1zA994xL.js';
8
8
  import './cache.js';
9
9
  import './renderer.js';
10
10
  import './deployment.js';