houdini-react 0.0.0-20231008055552

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 (236) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +36 -0
  3. package/build/plugin/codegen/entries.d.ts +5 -0
  4. package/build/plugin/codegen/index.d.ts +13 -0
  5. package/build/plugin/codegen/manifest.d.ts +5 -0
  6. package/build/plugin/codegen/render.d.ts +5 -0
  7. package/build/plugin/codegen/router.d.ts +7 -0
  8. package/build/plugin/codegen/typeRoot.d.ts +6 -0
  9. package/build/plugin/config.d.ts +4 -0
  10. package/build/plugin/dedent.d.ts +1 -0
  11. package/build/plugin/extract.d.ts +6 -0
  12. package/build/plugin/index.d.ts +7 -0
  13. package/build/plugin/transform.d.ts +6 -0
  14. package/build/plugin/vite.d.ts +54 -0
  15. package/build/plugin-cjs/index.js +79966 -0
  16. package/build/plugin-cjs/package.json +1 -0
  17. package/build/plugin-esm/index.js +79956 -0
  18. package/build/plugin-esm/package.json +1 -0
  19. package/build/runtime/client.d.ts +3 -0
  20. package/build/runtime/clientPlugin.d.ts +3 -0
  21. package/build/runtime/hooks/index.d.ts +8 -0
  22. package/build/runtime/hooks/useDeepCompareEffect.d.ts +35 -0
  23. package/build/runtime/hooks/useDocumentHandle.d.ts +34 -0
  24. package/build/runtime/hooks/useDocumentStore.d.ts +12 -0
  25. package/build/runtime/hooks/useDocumentSubscription.d.ts +15 -0
  26. package/build/runtime/hooks/useFragment.d.ts +16 -0
  27. package/build/runtime/hooks/useFragmentHandle.d.ts +8 -0
  28. package/build/runtime/hooks/useIsMounted.d.ts +3 -0
  29. package/build/runtime/hooks/useMutation.d.ts +10 -0
  30. package/build/runtime/hooks/useQuery.d.ts +5 -0
  31. package/build/runtime/hooks/useQueryHandle.d.ts +10 -0
  32. package/build/runtime/hooks/useSubscription.d.ts +4 -0
  33. package/build/runtime/hooks/useSubscriptionHandle.d.ts +25 -0
  34. package/build/runtime/index.d.ts +11 -0
  35. package/build/runtime/manifest.d.ts +3 -0
  36. package/build/runtime/routing/Router.d.ts +67 -0
  37. package/build/runtime/routing/cache.d.ts +7 -0
  38. package/build/runtime/routing/index.d.ts +2 -0
  39. package/build/runtime/server/index.d.ts +17 -0
  40. package/build/runtime/server/renderToStream/createBuffer.d.ts +17 -0
  41. package/build/runtime/server/renderToStream/createPipeWrapper.d.ts +12 -0
  42. package/build/runtime/server/renderToStream/createReadableWrapper.d.ts +6 -0
  43. package/build/runtime/server/renderToStream/loadNodeStreamModule.d.ts +10 -0
  44. package/build/runtime/server/renderToStream/resolveSeoStrategy.d.ts +9 -0
  45. package/build/runtime/server/renderToStream.d.ts +28 -0
  46. package/build/runtime/server/shared/initData.d.ts +8 -0
  47. package/build/runtime/server/shared/key.d.ts +4 -0
  48. package/build/runtime/server/shared/utils.d.ts +3 -0
  49. package/build/runtime/server/useStream.d.ts +9 -0
  50. package/build/runtime/server/utils/assert.d.ts +15 -0
  51. package/build/runtime/server/utils/createErrorWithCleanStackTrace.d.ts +2 -0
  52. package/build/runtime/server/utils/debug.d.ts +14 -0
  53. package/build/runtime/server/utils/getGlobalVariable.d.ts +4 -0
  54. package/build/runtime/server/utils/isBrowser.d.ts +2 -0
  55. package/build/runtime/server/utils/isCallable.d.ts +2 -0
  56. package/build/runtime/server/utils/isClientSide.d.ts +2 -0
  57. package/build/runtime/server/utils/isPromise.d.ts +1 -0
  58. package/build/runtime/server/utils/isServerSide.d.ts +2 -0
  59. package/build/runtime/server/utils/objectAssign.d.ts +2 -0
  60. package/build/runtime/server/utils/projectInfo.d.ts +10 -0
  61. package/build/runtime/server/utils.d.ts +4 -0
  62. package/build/runtime-cjs/client.d.ts +3 -0
  63. package/build/runtime-cjs/client.js +27 -0
  64. package/build/runtime-cjs/clientPlugin.d.ts +3 -0
  65. package/build/runtime-cjs/clientPlugin.js +39 -0
  66. package/build/runtime-cjs/hooks/index.d.ts +8 -0
  67. package/build/runtime-cjs/hooks/index.js +45 -0
  68. package/build/runtime-cjs/hooks/useDeepCompareEffect.d.ts +35 -0
  69. package/build/runtime-cjs/hooks/useDeepCompareEffect.js +72 -0
  70. package/build/runtime-cjs/hooks/useDocumentHandle.d.ts +34 -0
  71. package/build/runtime-cjs/hooks/useDocumentHandle.js +131 -0
  72. package/build/runtime-cjs/hooks/useDocumentStore.d.ts +12 -0
  73. package/build/runtime-cjs/hooks/useDocumentStore.js +68 -0
  74. package/build/runtime-cjs/hooks/useDocumentSubscription.d.ts +15 -0
  75. package/build/runtime-cjs/hooks/useDocumentSubscription.js +72 -0
  76. package/build/runtime-cjs/hooks/useFragment.d.ts +16 -0
  77. package/build/runtime-cjs/hooks/useFragment.js +97 -0
  78. package/build/runtime-cjs/hooks/useFragmentHandle.d.ts +8 -0
  79. package/build/runtime-cjs/hooks/useFragmentHandle.js +47 -0
  80. package/build/runtime-cjs/hooks/useIsMounted.d.ts +3 -0
  81. package/build/runtime-cjs/hooks/useIsMounted.js +38 -0
  82. package/build/runtime-cjs/hooks/useMutation.d.ts +10 -0
  83. package/build/runtime-cjs/hooks/useMutation.js +50 -0
  84. package/build/runtime-cjs/hooks/useQuery.d.ts +5 -0
  85. package/build/runtime-cjs/hooks/useQuery.js +32 -0
  86. package/build/runtime-cjs/hooks/useQueryHandle.d.ts +10 -0
  87. package/build/runtime-cjs/hooks/useQueryHandle.js +125 -0
  88. package/build/runtime-cjs/hooks/useSubscription.d.ts +4 -0
  89. package/build/runtime-cjs/hooks/useSubscription.js +32 -0
  90. package/build/runtime-cjs/hooks/useSubscriptionHandle.d.ts +25 -0
  91. package/build/runtime-cjs/hooks/useSubscriptionHandle.js +42 -0
  92. package/build/runtime-cjs/index.d.ts +11 -0
  93. package/build/runtime-cjs/index.js +77 -0
  94. package/build/runtime-cjs/manifest.d.ts +3 -0
  95. package/build/runtime-cjs/manifest.js +27 -0
  96. package/build/runtime-cjs/package.json +1 -0
  97. package/build/runtime-cjs/routing/Router.d.ts +67 -0
  98. package/build/runtime-cjs/routing/Router.js +429 -0
  99. package/build/runtime-cjs/routing/cache.d.ts +7 -0
  100. package/build/runtime-cjs/routing/cache.js +58 -0
  101. package/build/runtime-cjs/routing/index.d.ts +2 -0
  102. package/build/runtime-cjs/routing/index.js +30 -0
  103. package/build/runtime-cjs/server/index.d.ts +17 -0
  104. package/build/runtime-cjs/server/index.js +28 -0
  105. package/build/runtime-cjs/server/renderToStream/createBuffer.d.ts +17 -0
  106. package/build/runtime-cjs/server/renderToStream/createBuffer.js +101 -0
  107. package/build/runtime-cjs/server/renderToStream/createPipeWrapper.d.ts +12 -0
  108. package/build/runtime-cjs/server/renderToStream/createPipeWrapper.js +90 -0
  109. package/build/runtime-cjs/server/renderToStream/createReadableWrapper.d.ts +6 -0
  110. package/build/runtime-cjs/server/renderToStream/createReadableWrapper.js +85 -0
  111. package/build/runtime-cjs/server/renderToStream/loadNodeStreamModule.d.ts +10 -0
  112. package/build/runtime-cjs/server/renderToStream/loadNodeStreamModule.js +51 -0
  113. package/build/runtime-cjs/server/renderToStream/resolveSeoStrategy.d.ts +9 -0
  114. package/build/runtime-cjs/server/renderToStream/resolveSeoStrategy.js +44 -0
  115. package/build/runtime-cjs/server/renderToStream.d.ts +28 -0
  116. package/build/runtime-cjs/server/renderToStream.js +183 -0
  117. package/build/runtime-cjs/server/shared/initData.d.ts +8 -0
  118. package/build/runtime-cjs/server/shared/initData.js +28 -0
  119. package/build/runtime-cjs/server/shared/key.d.ts +4 -0
  120. package/build/runtime-cjs/server/shared/key.js +45 -0
  121. package/build/runtime-cjs/server/shared/utils.d.ts +3 -0
  122. package/build/runtime-cjs/server/shared/utils.js +20 -0
  123. package/build/runtime-cjs/server/useStream.d.ts +9 -0
  124. package/build/runtime-cjs/server/useStream.js +44 -0
  125. package/build/runtime-cjs/server/utils/assert.d.ts +15 -0
  126. package/build/runtime-cjs/server/utils/assert.js +119 -0
  127. package/build/runtime-cjs/server/utils/createErrorWithCleanStackTrace.d.ts +2 -0
  128. package/build/runtime-cjs/server/utils/createErrorWithCleanStackTrace.js +62 -0
  129. package/build/runtime-cjs/server/utils/debug.d.ts +14 -0
  130. package/build/runtime-cjs/server/utils/debug.js +112 -0
  131. package/build/runtime-cjs/server/utils/getGlobalVariable.d.ts +4 -0
  132. package/build/runtime-cjs/server/utils/getGlobalVariable.js +32 -0
  133. package/build/runtime-cjs/server/utils/isBrowser.d.ts +2 -0
  134. package/build/runtime-cjs/server/utils/isBrowser.js +30 -0
  135. package/build/runtime-cjs/server/utils/isCallable.d.ts +2 -0
  136. package/build/runtime-cjs/server/utils/isCallable.js +30 -0
  137. package/build/runtime-cjs/server/utils/isClientSide.d.ts +2 -0
  138. package/build/runtime-cjs/server/utils/isClientSide.js +30 -0
  139. package/build/runtime-cjs/server/utils/isPromise.d.ts +1 -0
  140. package/build/runtime-cjs/server/utils/isPromise.js +31 -0
  141. package/build/runtime-cjs/server/utils/isServerSide.d.ts +2 -0
  142. package/build/runtime-cjs/server/utils/isServerSide.js +31 -0
  143. package/build/runtime-cjs/server/utils/objectAssign.d.ts +2 -0
  144. package/build/runtime-cjs/server/utils/objectAssign.js +30 -0
  145. package/build/runtime-cjs/server/utils/projectInfo.d.ts +10 -0
  146. package/build/runtime-cjs/server/utils/projectInfo.js +37 -0
  147. package/build/runtime-cjs/server/utils.d.ts +4 -0
  148. package/build/runtime-cjs/server/utils.js +21 -0
  149. package/build/runtime-esm/client.d.ts +3 -0
  150. package/build/runtime-esm/client.js +5 -0
  151. package/build/runtime-esm/clientPlugin.d.ts +3 -0
  152. package/build/runtime-esm/clientPlugin.js +17 -0
  153. package/build/runtime-esm/hooks/index.d.ts +8 -0
  154. package/build/runtime-esm/hooks/index.js +16 -0
  155. package/build/runtime-esm/hooks/useDeepCompareEffect.d.ts +35 -0
  156. package/build/runtime-esm/hooks/useDeepCompareEffect.js +41 -0
  157. package/build/runtime-esm/hooks/useDocumentHandle.d.ts +34 -0
  158. package/build/runtime-esm/hooks/useDocumentHandle.js +101 -0
  159. package/build/runtime-esm/hooks/useDocumentStore.d.ts +12 -0
  160. package/build/runtime-esm/hooks/useDocumentStore.js +38 -0
  161. package/build/runtime-esm/hooks/useDocumentSubscription.d.ts +15 -0
  162. package/build/runtime-esm/hooks/useDocumentSubscription.js +42 -0
  163. package/build/runtime-esm/hooks/useFragment.d.ts +16 -0
  164. package/build/runtime-esm/hooks/useFragment.js +66 -0
  165. package/build/runtime-esm/hooks/useFragmentHandle.d.ts +8 -0
  166. package/build/runtime-esm/hooks/useFragmentHandle.js +23 -0
  167. package/build/runtime-esm/hooks/useIsMounted.d.ts +3 -0
  168. package/build/runtime-esm/hooks/useIsMounted.js +14 -0
  169. package/build/runtime-esm/hooks/useMutation.d.ts +10 -0
  170. package/build/runtime-esm/hooks/useMutation.js +26 -0
  171. package/build/runtime-esm/hooks/useQuery.d.ts +5 -0
  172. package/build/runtime-esm/hooks/useQuery.js +8 -0
  173. package/build/runtime-esm/hooks/useQueryHandle.d.ts +10 -0
  174. package/build/runtime-esm/hooks/useQueryHandle.js +95 -0
  175. package/build/runtime-esm/hooks/useSubscription.d.ts +4 -0
  176. package/build/runtime-esm/hooks/useSubscription.js +8 -0
  177. package/build/runtime-esm/hooks/useSubscriptionHandle.d.ts +25 -0
  178. package/build/runtime-esm/hooks/useSubscriptionHandle.js +18 -0
  179. package/build/runtime-esm/index.d.ts +11 -0
  180. package/build/runtime-esm/index.js +45 -0
  181. package/build/runtime-esm/manifest.d.ts +3 -0
  182. package/build/runtime-esm/manifest.js +5 -0
  183. package/build/runtime-esm/package.json +1 -0
  184. package/build/runtime-esm/routing/Router.d.ts +67 -0
  185. package/build/runtime-esm/routing/Router.js +390 -0
  186. package/build/runtime-esm/routing/cache.d.ts +7 -0
  187. package/build/runtime-esm/routing/cache.js +33 -0
  188. package/build/runtime-esm/routing/index.d.ts +2 -0
  189. package/build/runtime-esm/routing/index.js +5 -0
  190. package/build/runtime-esm/server/index.d.ts +17 -0
  191. package/build/runtime-esm/server/index.js +4 -0
  192. package/build/runtime-esm/server/renderToStream/createBuffer.d.ts +17 -0
  193. package/build/runtime-esm/server/renderToStream/createBuffer.js +77 -0
  194. package/build/runtime-esm/server/renderToStream/createPipeWrapper.d.ts +12 -0
  195. package/build/runtime-esm/server/renderToStream/createPipeWrapper.js +66 -0
  196. package/build/runtime-esm/server/renderToStream/createReadableWrapper.d.ts +6 -0
  197. package/build/runtime-esm/server/renderToStream/createReadableWrapper.js +61 -0
  198. package/build/runtime-esm/server/renderToStream/loadNodeStreamModule.d.ts +10 -0
  199. package/build/runtime-esm/server/renderToStream/loadNodeStreamModule.js +20 -0
  200. package/build/runtime-esm/server/renderToStream/resolveSeoStrategy.d.ts +9 -0
  201. package/build/runtime-esm/server/renderToStream/resolveSeoStrategy.js +20 -0
  202. package/build/runtime-esm/server/renderToStream.d.ts +28 -0
  203. package/build/runtime-esm/server/renderToStream.js +152 -0
  204. package/build/runtime-esm/server/shared/initData.d.ts +8 -0
  205. package/build/runtime-esm/server/shared/initData.js +4 -0
  206. package/build/runtime-esm/server/shared/key.d.ts +4 -0
  207. package/build/runtime-esm/server/shared/key.js +20 -0
  208. package/build/runtime-esm/server/shared/utils.d.ts +3 -0
  209. package/build/runtime-esm/server/shared/utils.js +3 -0
  210. package/build/runtime-esm/server/useStream.d.ts +9 -0
  211. package/build/runtime-esm/server/useStream.js +13 -0
  212. package/build/runtime-esm/server/utils/assert.d.ts +15 -0
  213. package/build/runtime-esm/server/utils/assert.js +91 -0
  214. package/build/runtime-esm/server/utils/createErrorWithCleanStackTrace.d.ts +2 -0
  215. package/build/runtime-esm/server/utils/createErrorWithCleanStackTrace.js +38 -0
  216. package/build/runtime-esm/server/utils/debug.d.ts +14 -0
  217. package/build/runtime-esm/server/utils/debug.js +87 -0
  218. package/build/runtime-esm/server/utils/getGlobalVariable.d.ts +4 -0
  219. package/build/runtime-esm/server/utils/getGlobalVariable.js +8 -0
  220. package/build/runtime-esm/server/utils/isBrowser.d.ts +2 -0
  221. package/build/runtime-esm/server/utils/isBrowser.js +6 -0
  222. package/build/runtime-esm/server/utils/isCallable.d.ts +2 -0
  223. package/build/runtime-esm/server/utils/isCallable.js +6 -0
  224. package/build/runtime-esm/server/utils/isClientSide.d.ts +2 -0
  225. package/build/runtime-esm/server/utils/isClientSide.js +6 -0
  226. package/build/runtime-esm/server/utils/isPromise.d.ts +1 -0
  227. package/build/runtime-esm/server/utils/isPromise.js +7 -0
  228. package/build/runtime-esm/server/utils/isServerSide.d.ts +2 -0
  229. package/build/runtime-esm/server/utils/isServerSide.js +7 -0
  230. package/build/runtime-esm/server/utils/objectAssign.d.ts +2 -0
  231. package/build/runtime-esm/server/utils/objectAssign.js +6 -0
  232. package/build/runtime-esm/server/utils/projectInfo.d.ts +10 -0
  233. package/build/runtime-esm/server/utils/projectInfo.js +13 -0
  234. package/build/runtime-esm/server/utils.d.ts +4 -0
  235. package/build/runtime-esm/server/utils.js +4 -0
  236. package/package.json +67 -0
@@ -0,0 +1,429 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
22
+ mod
23
+ ));
24
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
25
+ var Router_exports = {};
26
+ __export(Router_exports, {
27
+ Router: () => Router,
28
+ RouterContextProvider: () => RouterContextProvider,
29
+ router_cache: () => router_cache,
30
+ updateLocalSession: () => updateLocalSession,
31
+ useCache: () => useCache,
32
+ useClient: () => useClient,
33
+ useCurrentVariables: () => useCurrentVariables,
34
+ useQueryResult: () => useQueryResult,
35
+ useRouterContext: () => useRouterContext,
36
+ useSession: () => useSession
37
+ });
38
+ module.exports = __toCommonJS(Router_exports);
39
+ var import_jsx_runtime = require("react/jsx-runtime");
40
+ var import_deepEquals = require("$houdini/runtime/lib/deepEquals");
41
+ var import_match = require("$houdini/runtime/router/match");
42
+ var import_react = __toESM(require("react"));
43
+ var import_useDocumentStore = require("../hooks/useDocumentStore");
44
+ var import_cache = require("./cache");
45
+ const PreloadWhich = {
46
+ component: "component",
47
+ data: "data",
48
+ page: "page"
49
+ };
50
+ function Router({
51
+ manifest,
52
+ initialURL,
53
+ assetPrefix,
54
+ injectToStream
55
+ }) {
56
+ const [current, setCurrent] = import_react.default.useState(() => {
57
+ return initialURL || window.location.pathname;
58
+ });
59
+ const [page, variables] = (0, import_match.find_match)(manifest, current);
60
+ const { loadData, loadComponent } = usePageData({
61
+ page,
62
+ variables,
63
+ assetPrefix,
64
+ injectToStream
65
+ });
66
+ const { component_cache } = useRouterContext();
67
+ const PageComponent = component_cache.get(page.id);
68
+ import_react.default.useEffect(() => {
69
+ if (globalThis.window && window.location.pathname !== current) {
70
+ window.history.pushState({}, "", current);
71
+ }
72
+ }, [current]);
73
+ import_react.default.useEffect(() => {
74
+ if (!globalThis.window) {
75
+ return;
76
+ }
77
+ const onChange = (evt) => {
78
+ setCurrent(window.location.pathname);
79
+ };
80
+ window.addEventListener("popstate", onChange);
81
+ return () => {
82
+ window.removeEventListener("popstate", onChange);
83
+ };
84
+ }, []);
85
+ useLinkBehavior({
86
+ goto: setCurrent,
87
+ preload(url, which) {
88
+ const [page2, variables2] = (0, import_match.find_match)(manifest, url);
89
+ if (["both", "component"].includes(which)) {
90
+ loadComponent(page2);
91
+ }
92
+ if (["both", "data"].includes(which)) {
93
+ loadData(page2, variables2);
94
+ }
95
+ }
96
+ });
97
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(VariableContext.Provider, { value: variables, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(PageComponent, { url: current }) });
98
+ }
99
+ function usePageData({
100
+ page,
101
+ variables,
102
+ assetPrefix,
103
+ injectToStream
104
+ }) {
105
+ const {
106
+ client,
107
+ cache,
108
+ data_cache,
109
+ component_cache,
110
+ artifact_cache,
111
+ pending_cache,
112
+ last_variables
113
+ } = useRouterContext();
114
+ const session = useSession();
115
+ function load_query({ id, artifact }) {
116
+ last_variables.set(page.id, variables);
117
+ if (pending_cache.has(id)) {
118
+ return pending_cache.get(id);
119
+ }
120
+ const observer = client.observe({ artifact, cache });
121
+ let resolve = () => {
122
+ };
123
+ let reject = () => {
124
+ };
125
+ const promise = new Promise((res, rej) => {
126
+ resolve = res;
127
+ reject = rej;
128
+ observer.send({
129
+ variables,
130
+ cacheParams: { disableSubscriptions: true },
131
+ session
132
+ }).then(() => {
133
+ data_cache.set(id, observer);
134
+ injectToStream?.(`
135
+ <script>
136
+ window.__houdini__cache__?.hydrate(${cache.serialize()}, window.__houdini__hydration__layer)
137
+
138
+ const artifactName = "${artifact.name}"
139
+ const value = ${JSON.stringify(observer.state.data)}
140
+
141
+ // if the data is pending, we need to resolve it
142
+ if (window.__houdini__nav_caches__?.data_cache.has(artifactName)) {
143
+ // before we resolve the pending signals,
144
+ // fill the data cache with values we got on the server
145
+ const new_store = window.__houdini__client__.observe({
146
+ artifact: window.__houdini__nav_caches__.artifact_cache.get(artifactName),
147
+ cache: window.__houdini__cache__,
148
+ initialValue: value
149
+ })
150
+
151
+ window.__houdini__nav_caches__?.data_cache.set(artifactName, new_store)
152
+ }
153
+
154
+
155
+ // if there are no data caches available we need to populate the pending one instead
156
+ if (!window.__houdini__nav_caches__) {
157
+ if (!window.__houdini__pending_data__) {
158
+ window.__houdini__pending_data__ = {}
159
+ }
160
+
161
+ if (!window.__houdini__pending_artifacts__) {
162
+ window.__houdini__pending_artifacts__ = {}
163
+ }
164
+
165
+ window.__houdini__pending_data__[artifactName] = value
166
+ window.__houdini__pending_artifacts__[artifactName] = ${JSON.stringify(artifact)}
167
+ }
168
+
169
+ if (window.__houdini__nav_caches__?.pending_cache.has(artifactName)) {
170
+ // we're pushing this store onto the client, it should be initialized
171
+ new_store.send({
172
+ setup: true,
173
+ variables: ${JSON.stringify(variables)}
174
+ })
175
+
176
+ // notify anyone waiting on the pending cache
177
+ window.__houdini__nav_caches__.pending_cache.get(artifactName).resolve()
178
+ window.__houdini__nav_caches__.pending_cache.delete(artifactName)
179
+ }
180
+ <\/script>
181
+ `);
182
+ resolve();
183
+ }).catch(reject).finally(() => {
184
+ pending_cache.delete(id);
185
+ });
186
+ });
187
+ pending_cache.set(id, { ...promise, resolve, reject });
188
+ return pending_cache.get(id);
189
+ }
190
+ function loadData(targetPage, variables2) {
191
+ if (last_variables.has(targetPage.id) && !(0, import_deepEquals.deepEquals)(last_variables.get(targetPage.id), variables2)) {
192
+ data_cache.clear();
193
+ }
194
+ const missing_artifacts = [];
195
+ const found_artifacts = {};
196
+ for (const key of Object.keys(targetPage.documents)) {
197
+ if (artifact_cache.has(key)) {
198
+ found_artifacts[key] = artifact_cache.get(key);
199
+ } else {
200
+ missing_artifacts.push(key);
201
+ }
202
+ }
203
+ for (const artifact_id of missing_artifacts) {
204
+ targetPage.documents[artifact_id].artifact().then((mod) => {
205
+ const artifact = mod.default;
206
+ artifact_cache.set(artifact_id, artifact);
207
+ injectToStream?.(`
208
+ <script type="module" src="${assetPrefix}/artifacts/${artifact.name}.js" async=""><\/script>
209
+ `);
210
+ load_query({ id: artifact.name, artifact });
211
+ }).catch((err) => {
212
+ console.log(err);
213
+ });
214
+ }
215
+ for (const artifact of Object.values(found_artifacts)) {
216
+ if (!data_cache.has(artifact.name)) {
217
+ load_query({ id: artifact.name, artifact });
218
+ }
219
+ }
220
+ }
221
+ async function loadComponent(targetPage) {
222
+ if (component_cache.has(targetPage.id)) {
223
+ return;
224
+ }
225
+ const mod = await targetPage.component();
226
+ component_cache.set(targetPage.id, mod.default);
227
+ }
228
+ loadData(page, variables);
229
+ if (!component_cache.has(page.id)) {
230
+ throw loadComponent(page);
231
+ }
232
+ return {
233
+ loadData,
234
+ loadComponent
235
+ };
236
+ }
237
+ function RouterContextProvider({
238
+ children,
239
+ client,
240
+ cache,
241
+ artifact_cache,
242
+ component_cache,
243
+ data_cache,
244
+ pending_cache,
245
+ last_variables,
246
+ session: ssrSession = {}
247
+ }) {
248
+ const [session, setSession] = import_react.default.useState(ssrSession);
249
+ const handleNewSession = import_react.default.useCallback((event) => {
250
+ setSession(event.detail);
251
+ }, []);
252
+ import_react.default.useEffect(() => {
253
+ window.addEventListener("_houdini_session_", handleNewSession);
254
+ return () => {
255
+ window.removeEventListener("_houdini_session_", handleNewSession);
256
+ };
257
+ }, []);
258
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
259
+ Context.Provider,
260
+ {
261
+ value: {
262
+ client,
263
+ cache,
264
+ artifact_cache,
265
+ component_cache,
266
+ data_cache,
267
+ pending_cache,
268
+ last_variables,
269
+ session
270
+ },
271
+ children
272
+ }
273
+ );
274
+ }
275
+ const Context = import_react.default.createContext(null);
276
+ const useRouterContext = () => {
277
+ const ctx = import_react.default.useContext(Context);
278
+ if (!ctx) {
279
+ console.log(ctx);
280
+ throw new Error("Could not find router context");
281
+ }
282
+ return ctx;
283
+ };
284
+ function useClient() {
285
+ return useRouterContext().client;
286
+ }
287
+ function useCache() {
288
+ return useRouterContext().cache;
289
+ }
290
+ function updateLocalSession(session) {
291
+ window.dispatchEvent(
292
+ new CustomEvent("_houdini_session_", {
293
+ bubbles: true,
294
+ detail: session
295
+ })
296
+ );
297
+ }
298
+ function useSession() {
299
+ return useRouterContext().session;
300
+ }
301
+ function useCurrentVariables() {
302
+ return import_react.default.useContext(VariableContext);
303
+ }
304
+ const VariableContext = import_react.default.createContext(null);
305
+ function useQueryResult(name) {
306
+ const store_ref = useRouterContext().data_cache.get(name);
307
+ const [{ data }, observer] = (0, import_useDocumentStore.useDocumentStore)({
308
+ artifact: store_ref.artifact,
309
+ observer: store_ref
310
+ });
311
+ return [data, observer];
312
+ }
313
+ function useLinkBehavior({
314
+ goto,
315
+ preload
316
+ }) {
317
+ useLinkNavigation({ goto });
318
+ if (!globalThis.navigator?.connection?.saveData) {
319
+ usePreload({ preload });
320
+ }
321
+ }
322
+ function useLinkNavigation({ goto }) {
323
+ const [pending, startTransition] = import_react.default.useTransition();
324
+ import_react.default.useEffect(() => {
325
+ const onClick = (e) => {
326
+ const link = e.target?.closest("a");
327
+ if (link && link instanceof HTMLAnchorElement && link.href && (!link.target || link.target === "_self") && link.origin === location.origin && !link.hasAttribute("download") && e.button === 0 && !e.metaKey && !e.ctrlKey && !e.altKey && !e.shiftKey && !e.defaultPrevented) {
328
+ const target = link.attributes.getNamedItem("href")?.value;
329
+ if (!target || !target.startsWith("/")) {
330
+ return;
331
+ }
332
+ e.preventDefault();
333
+ startTransition(() => {
334
+ goto(target);
335
+ });
336
+ }
337
+ };
338
+ document.addEventListener("click", onClick);
339
+ return () => {
340
+ document.removeEventListener("click", onClick);
341
+ };
342
+ }, []);
343
+ }
344
+ function usePreload({ preload }) {
345
+ const timeoutRef = import_react.default.useRef(null);
346
+ import_react.default.useEffect(() => {
347
+ const mouseMove = (e) => {
348
+ const target = e.target;
349
+ if (!(target instanceof HTMLAnchorElement)) {
350
+ return;
351
+ }
352
+ let preloadWhichRaw = target.attributes.getNamedItem("data-houdini-preload")?.value;
353
+ let preloadWhich = !preloadWhichRaw || preloadWhichRaw === "true" ? "page" : preloadWhichRaw;
354
+ if (!PreloadWhich[preloadWhich]) {
355
+ console.log(
356
+ `invalid preload value "${preloadWhich}" must be "${PreloadWhich.component}", "${PreloadWhich.data}", or "${PreloadWhich.page}"`
357
+ );
358
+ return;
359
+ }
360
+ if (timeoutRef.current) {
361
+ clearTimeout(timeoutRef.current);
362
+ }
363
+ timeoutRef.current = setTimeout(() => {
364
+ const url = target.attributes.getNamedItem("href")?.value;
365
+ if (!url) {
366
+ return;
367
+ }
368
+ preload(url, preloadWhich);
369
+ }, 20);
370
+ };
371
+ document.addEventListener("mousemove", mouseMove);
372
+ return () => {
373
+ document.removeEventListener("mousemove", mouseMove);
374
+ };
375
+ }, []);
376
+ }
377
+ function router_cache({
378
+ pending_queries = [],
379
+ artifacts = {},
380
+ components = {},
381
+ initialData = {},
382
+ initialArtifacts = {}
383
+ } = {}) {
384
+ const result = {
385
+ artifact_cache: (0, import_cache.suspense_cache)(initialArtifacts),
386
+ component_cache: (0, import_cache.suspense_cache)(),
387
+ data_cache: (0, import_cache.suspense_cache)(initialData),
388
+ pending_cache: (0, import_cache.suspense_cache)(),
389
+ last_variables: (0, import_cache.suspense_cache)()
390
+ };
391
+ for (const query of pending_queries) {
392
+ result.pending_cache.set(query, signal_promise());
393
+ }
394
+ for (const [name, artifact] of Object.entries(artifacts)) {
395
+ result.artifact_cache.set(name, artifact);
396
+ }
397
+ for (const [name, component] of Object.entries(components)) {
398
+ result.component_cache.set(name, component);
399
+ }
400
+ return result;
401
+ }
402
+ function signal_promise() {
403
+ let resolve = () => {
404
+ };
405
+ let reject = () => {
406
+ };
407
+ const promise = new Promise((res, rej) => {
408
+ resolve = res;
409
+ reject = rej;
410
+ });
411
+ return {
412
+ ...promise,
413
+ resolve,
414
+ reject
415
+ };
416
+ }
417
+ // Annotate the CommonJS export names for ESM import in node:
418
+ 0 && (module.exports = {
419
+ Router,
420
+ RouterContextProvider,
421
+ router_cache,
422
+ updateLocalSession,
423
+ useCache,
424
+ useClient,
425
+ useCurrentVariables,
426
+ useQueryResult,
427
+ useRouterContext,
428
+ useSession
429
+ });
@@ -0,0 +1,7 @@
1
+ import { LRUCache } from '$houdini/runtime/lib/lru';
2
+ export declare function suspense_cache<T>(initialData?: Record<string, T>): SuspenseCache<T>;
3
+ export declare class SuspenseCache<_Data> extends LRUCache<_Data> {
4
+ #private;
5
+ get(key: string): _Data;
6
+ set(key: string, value: _Data): void;
7
+ }
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var cache_exports = {};
20
+ __export(cache_exports, {
21
+ SuspenseCache: () => SuspenseCache,
22
+ suspense_cache: () => suspense_cache
23
+ });
24
+ module.exports = __toCommonJS(cache_exports);
25
+ var import_lru = require("$houdini/runtime/lib/lru");
26
+ function suspense_cache(initialData) {
27
+ const cache = new SuspenseCache();
28
+ for (const [key, value] of Object.entries(initialData ?? {})) {
29
+ cache.set(key, value);
30
+ }
31
+ return cache;
32
+ }
33
+ class SuspenseCache extends import_lru.LRUCache {
34
+ #callbacks = /* @__PURE__ */ new Map();
35
+ get(key) {
36
+ if (super.has(key)) {
37
+ return super.get(key);
38
+ }
39
+ throw new Promise((resolve, reject) => {
40
+ this.#subscribe(key, resolve, reject);
41
+ });
42
+ }
43
+ set(key, value) {
44
+ super.set(key, value);
45
+ if (this.#callbacks.has(key)) {
46
+ this.#callbacks.get(key)?.forEach(({ resolve }) => resolve());
47
+ this.#callbacks.delete(key);
48
+ }
49
+ }
50
+ #subscribe(key, resolve, reject) {
51
+ this.#callbacks.set(key, [...this.#callbacks.get(key) || [], { resolve, reject }]);
52
+ }
53
+ }
54
+ // Annotate the CommonJS export names for ESM import in node:
55
+ 0 && (module.exports = {
56
+ SuspenseCache,
57
+ suspense_cache
58
+ });
@@ -0,0 +1,2 @@
1
+ export * from './Router';
2
+ export { type SuspenseCache, suspense_cache } from './cache';
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
19
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
+ var routing_exports = {};
21
+ __export(routing_exports, {
22
+ suspense_cache: () => import_cache.suspense_cache
23
+ });
24
+ module.exports = __toCommonJS(routing_exports);
25
+ __reExport(routing_exports, require("./Router"), module.exports);
26
+ var import_cache = require("./cache");
27
+ // Annotate the CommonJS export names for ESM import in node:
28
+ 0 && (module.exports = {
29
+ suspense_cache
30
+ });
@@ -0,0 +1,17 @@
1
+ /**
2
+ This directory is largely copied from https://github.com/brillout/react-streaming and adapted to fit the needs of this project. It is subject to the MIT license, found [here](https://github.com/brillout/react-streaming/blob/main/LICENSE.md). Duplicated below for reference:
3
+
4
+ MIT License
5
+
6
+ Copyright (c) 2022-present Romuald Brillout
7
+
8
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
11
+
12
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
13
+ */
14
+ import { renderToStream } from './renderToStream';
15
+ import type { InjectToStream } from './renderToStream/createBuffer';
16
+ export { renderToStream };
17
+ export type { InjectToStream };
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var server_exports = {};
20
+ __export(server_exports, {
21
+ renderToStream: () => import_renderToStream.renderToStream
22
+ });
23
+ module.exports = __toCommonJS(server_exports);
24
+ var import_renderToStream = require("./renderToStream");
25
+ // Annotate the CommonJS export names for ESM import in node:
26
+ 0 && (module.exports = {
27
+ renderToStream
28
+ });
@@ -0,0 +1,17 @@
1
+ export { createBuffer };
2
+ export type { InjectToStream };
3
+ export type { StreamOperations };
4
+ type InjectToStream = (chunk: unknown, options?: {
5
+ flush?: boolean;
6
+ }) => void;
7
+ type StreamOperations = {
8
+ operations: null | {
9
+ writeChunk: (chunk: unknown) => void;
10
+ flush: null | (() => void);
11
+ };
12
+ };
13
+ declare function createBuffer(streamOperations: StreamOperations): {
14
+ injectToStream: InjectToStream;
15
+ onBeforeWrite: (chunk: unknown) => void;
16
+ onBeforeEnd: () => void;
17
+ };
@@ -0,0 +1,101 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var createBuffer_exports = {};
20
+ __export(createBuffer_exports, {
21
+ createBuffer: () => createBuffer
22
+ });
23
+ module.exports = __toCommonJS(createBuffer_exports);
24
+ var import_utils = require("../utils");
25
+ const debug = (0, import_utils.createDebugger)("react-streaming:buffer");
26
+ function createBuffer(streamOperations) {
27
+ const buffer = [];
28
+ let state = "UNSTARTED";
29
+ let writePermission = null;
30
+ return { injectToStream, onBeforeWrite, onBeforeEnd };
31
+ function injectToStream(chunk, options) {
32
+ (0, import_utils.assertUsage)(
33
+ state !== "ENDED",
34
+ `Cannot inject following chunk after stream has ended: \`${chunk}\``
35
+ );
36
+ if (debug.isEnabled) {
37
+ debug("injectToStream()", String(chunk));
38
+ }
39
+ buffer.push({ chunk, flush: options?.flush });
40
+ flushBuffer();
41
+ }
42
+ function flushBuffer() {
43
+ if (!writePermission) {
44
+ return;
45
+ }
46
+ if (buffer.length === 0) {
47
+ return;
48
+ }
49
+ if (state !== "STREAMING") {
50
+ (0, import_utils.assert)(state === "UNSTARTED");
51
+ return;
52
+ }
53
+ let flushStream = false;
54
+ buffer.forEach((bufferEntry) => {
55
+ (0, import_utils.assert)(streamOperations.operations);
56
+ const { writeChunk } = streamOperations.operations;
57
+ writeChunk(bufferEntry.chunk);
58
+ if (bufferEntry.flush) {
59
+ flushStream = true;
60
+ }
61
+ });
62
+ buffer.length = 0;
63
+ (0, import_utils.assert)(streamOperations.operations);
64
+ if (flushStream && streamOperations.operations.flush !== null) {
65
+ streamOperations.operations.flush();
66
+ debug("stream flushed");
67
+ }
68
+ }
69
+ function onBeforeWrite(chunk) {
70
+ state === "UNSTARTED" && debug(">>> START");
71
+ if (debug.isEnabled) {
72
+ debug(`react write${!writePermission ? "" : " (allowed)"}`, String(chunk));
73
+ }
74
+ state = "STREAMING";
75
+ if (writePermission) {
76
+ flushBuffer();
77
+ }
78
+ if (writePermission == true || writePermission === null) {
79
+ writePermission = false;
80
+ debug("writePermission =", writePermission);
81
+ setTimeout(() => {
82
+ debug(">>> setTimeout()");
83
+ writePermission = true;
84
+ debug("writePermission =", writePermission);
85
+ flushBuffer();
86
+ });
87
+ }
88
+ }
89
+ function onBeforeEnd() {
90
+ writePermission = true;
91
+ debug("writePermission =", writePermission);
92
+ flushBuffer();
93
+ (0, import_utils.assert)(buffer.length === 0);
94
+ state = "ENDED";
95
+ debug(">>> END");
96
+ }
97
+ }
98
+ // Annotate the CommonJS export names for ESM import in node:
99
+ 0 && (module.exports = {
100
+ createBuffer
101
+ });