houdini-react 2.0.0-next.2 → 2.0.0-next.22

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 (170) hide show
  1. package/bin/houdini-react +88 -0
  2. package/package.json +43 -22
  3. package/postInstall.js +353 -0
  4. package/runtime/client.ts +5 -0
  5. package/runtime/clientPlugin.ts +17 -0
  6. package/runtime/componentFields.ts +79 -0
  7. package/runtime/hooks/index.ts +9 -0
  8. package/runtime/hooks/useDeepCompareEffect.ts +91 -0
  9. package/runtime/hooks/useDocumentHandle.ts +232 -0
  10. package/runtime/hooks/useDocumentStore.ts +76 -0
  11. package/runtime/hooks/useDocumentSubscription.ts +62 -0
  12. package/runtime/hooks/useFragment.ts +93 -0
  13. package/runtime/hooks/useFragmentHandle.ts +46 -0
  14. package/runtime/hooks/useIsMounted.ts +14 -0
  15. package/runtime/hooks/useMutation.ts +70 -0
  16. package/runtime/hooks/useQuery.ts +12 -0
  17. package/runtime/hooks/useQueryHandle.ts +185 -0
  18. package/runtime/hooks/useSubscription.ts +12 -0
  19. package/runtime/hooks/useSubscriptionHandle.ts +33 -0
  20. package/runtime/hydration.tsx +155 -0
  21. package/runtime/index.tsx +49 -0
  22. package/runtime/manifest.ts +6 -0
  23. package/runtime/routing/Router.tsx +885 -0
  24. package/runtime/routing/cache.ts +54 -0
  25. package/runtime/routing/index.ts +2 -0
  26. package/server/index.d.ts +1 -0
  27. package/server/index.js +4 -0
  28. package/server/react-streaming.d.js +0 -0
  29. package/vite/index.d.ts +3 -0
  30. package/vite/index.js +284 -0
  31. package/vite/transform.d.ts +11 -0
  32. package/vite/transform.js +92 -0
  33. package/README.md +0 -36
  34. package/build/plugin/codegen/entries/documentWrappers.d.ts +0 -6
  35. package/build/plugin/codegen/entries/fallbacks.d.ts +0 -5
  36. package/build/plugin/codegen/entries/index.d.ts +0 -16
  37. package/build/plugin/codegen/entries/pages.d.ts +0 -2
  38. package/build/plugin/codegen/index.d.ts +0 -17
  39. package/build/plugin/codegen/manifest.d.ts +0 -5
  40. package/build/plugin/codegen/render.d.ts +0 -7
  41. package/build/plugin/codegen/router.d.ts +0 -7
  42. package/build/plugin/codegen/typeRoot.d.ts +0 -5
  43. package/build/plugin/config.d.ts +0 -4
  44. package/build/plugin/dedent.d.ts +0 -1
  45. package/build/plugin/extract.d.ts +0 -6
  46. package/build/plugin/index.d.ts +0 -5
  47. package/build/plugin/state.d.ts +0 -3
  48. package/build/plugin/transform.d.ts +0 -6
  49. package/build/plugin/vite.d.ts +0 -27
  50. package/build/plugin-cjs/index.js +0 -90119
  51. package/build/plugin-cjs/package.json +0 -1
  52. package/build/plugin-esm/index.js +0 -90115
  53. package/build/runtime/client.d.ts +0 -3
  54. package/build/runtime/clientPlugin.d.ts +0 -3
  55. package/build/runtime/componentFields.d.ts +0 -9
  56. package/build/runtime/hooks/index.d.ts +0 -8
  57. package/build/runtime/hooks/useDeepCompareEffect.d.ts +0 -35
  58. package/build/runtime/hooks/useDocumentHandle.d.ts +0 -36
  59. package/build/runtime/hooks/useDocumentStore.d.ts +0 -11
  60. package/build/runtime/hooks/useDocumentSubscription.d.ts +0 -11
  61. package/build/runtime/hooks/useFragment.d.ts +0 -16
  62. package/build/runtime/hooks/useFragmentHandle.d.ts +0 -8
  63. package/build/runtime/hooks/useIsMounted.d.ts +0 -3
  64. package/build/runtime/hooks/useMutation.d.ts +0 -14
  65. package/build/runtime/hooks/useQuery.d.ts +0 -5
  66. package/build/runtime/hooks/useQueryHandle.d.ts +0 -10
  67. package/build/runtime/hooks/useSubscription.d.ts +0 -4
  68. package/build/runtime/hooks/useSubscriptionHandle.d.ts +0 -25
  69. package/build/runtime/index.d.ts +0 -14
  70. package/build/runtime/manifest.d.ts +0 -3
  71. package/build/runtime/routing/Router.d.ts +0 -62
  72. package/build/runtime/routing/cache.d.ts +0 -7
  73. package/build/runtime/routing/hooks.d.ts +0 -40
  74. package/build/runtime/routing/index.d.ts +0 -3
  75. package/build/runtime-cjs/client.d.ts +0 -3
  76. package/build/runtime-cjs/client.js +0 -25
  77. package/build/runtime-cjs/clientPlugin.d.ts +0 -3
  78. package/build/runtime-cjs/clientPlugin.js +0 -37
  79. package/build/runtime-cjs/componentFields.d.ts +0 -9
  80. package/build/runtime-cjs/componentFields.js +0 -83
  81. package/build/runtime-cjs/hooks/index.d.ts +0 -8
  82. package/build/runtime-cjs/hooks/index.js +0 -45
  83. package/build/runtime-cjs/hooks/useDeepCompareEffect.d.ts +0 -35
  84. package/build/runtime-cjs/hooks/useDeepCompareEffect.js +0 -76
  85. package/build/runtime-cjs/hooks/useDocumentHandle.d.ts +0 -36
  86. package/build/runtime-cjs/hooks/useDocumentHandle.js +0 -177
  87. package/build/runtime-cjs/hooks/useDocumentStore.d.ts +0 -11
  88. package/build/runtime-cjs/hooks/useDocumentStore.js +0 -76
  89. package/build/runtime-cjs/hooks/useDocumentSubscription.d.ts +0 -11
  90. package/build/runtime-cjs/hooks/useDocumentSubscription.js +0 -76
  91. package/build/runtime-cjs/hooks/useFragment.d.ts +0 -16
  92. package/build/runtime-cjs/hooks/useFragment.js +0 -102
  93. package/build/runtime-cjs/hooks/useFragmentHandle.d.ts +0 -8
  94. package/build/runtime-cjs/hooks/useFragmentHandle.js +0 -47
  95. package/build/runtime-cjs/hooks/useIsMounted.d.ts +0 -3
  96. package/build/runtime-cjs/hooks/useIsMounted.js +0 -38
  97. package/build/runtime-cjs/hooks/useMutation.d.ts +0 -14
  98. package/build/runtime-cjs/hooks/useMutation.js +0 -67
  99. package/build/runtime-cjs/hooks/useQuery.d.ts +0 -5
  100. package/build/runtime-cjs/hooks/useQuery.js +0 -32
  101. package/build/runtime-cjs/hooks/useQueryHandle.d.ts +0 -10
  102. package/build/runtime-cjs/hooks/useQueryHandle.js +0 -131
  103. package/build/runtime-cjs/hooks/useSubscription.d.ts +0 -4
  104. package/build/runtime-cjs/hooks/useSubscription.js +0 -32
  105. package/build/runtime-cjs/hooks/useSubscriptionHandle.d.ts +0 -25
  106. package/build/runtime-cjs/hooks/useSubscriptionHandle.js +0 -42
  107. package/build/runtime-cjs/index.d.ts +0 -14
  108. package/build/runtime-cjs/index.js +0 -88
  109. package/build/runtime-cjs/manifest.d.ts +0 -3
  110. package/build/runtime-cjs/manifest.js +0 -25
  111. package/build/runtime-cjs/package.json +0 -1
  112. package/build/runtime-cjs/routing/Router.d.ts +0 -62
  113. package/build/runtime-cjs/routing/Router.js +0 -540
  114. package/build/runtime-cjs/routing/cache.d.ts +0 -7
  115. package/build/runtime-cjs/routing/cache.js +0 -61
  116. package/build/runtime-cjs/routing/hooks.d.ts +0 -40
  117. package/build/runtime-cjs/routing/hooks.js +0 -93
  118. package/build/runtime-cjs/routing/index.d.ts +0 -3
  119. package/build/runtime-cjs/routing/index.js +0 -33
  120. package/build/runtime-esm/client.d.ts +0 -3
  121. package/build/runtime-esm/client.js +0 -5
  122. package/build/runtime-esm/clientPlugin.d.ts +0 -3
  123. package/build/runtime-esm/clientPlugin.js +0 -17
  124. package/build/runtime-esm/componentFields.d.ts +0 -9
  125. package/build/runtime-esm/componentFields.js +0 -59
  126. package/build/runtime-esm/hooks/index.d.ts +0 -8
  127. package/build/runtime-esm/hooks/index.js +0 -15
  128. package/build/runtime-esm/hooks/useDeepCompareEffect.d.ts +0 -35
  129. package/build/runtime-esm/hooks/useDeepCompareEffect.js +0 -41
  130. package/build/runtime-esm/hooks/useDocumentHandle.d.ts +0 -36
  131. package/build/runtime-esm/hooks/useDocumentHandle.js +0 -143
  132. package/build/runtime-esm/hooks/useDocumentStore.d.ts +0 -11
  133. package/build/runtime-esm/hooks/useDocumentStore.js +0 -42
  134. package/build/runtime-esm/hooks/useDocumentSubscription.d.ts +0 -11
  135. package/build/runtime-esm/hooks/useDocumentSubscription.js +0 -42
  136. package/build/runtime-esm/hooks/useFragment.d.ts +0 -16
  137. package/build/runtime-esm/hooks/useFragment.js +0 -67
  138. package/build/runtime-esm/hooks/useFragmentHandle.d.ts +0 -8
  139. package/build/runtime-esm/hooks/useFragmentHandle.js +0 -23
  140. package/build/runtime-esm/hooks/useIsMounted.d.ts +0 -3
  141. package/build/runtime-esm/hooks/useIsMounted.js +0 -14
  142. package/build/runtime-esm/hooks/useMutation.d.ts +0 -14
  143. package/build/runtime-esm/hooks/useMutation.js +0 -42
  144. package/build/runtime-esm/hooks/useQuery.d.ts +0 -5
  145. package/build/runtime-esm/hooks/useQuery.js +0 -8
  146. package/build/runtime-esm/hooks/useQueryHandle.d.ts +0 -10
  147. package/build/runtime-esm/hooks/useQueryHandle.js +0 -97
  148. package/build/runtime-esm/hooks/useSubscription.d.ts +0 -4
  149. package/build/runtime-esm/hooks/useSubscription.js +0 -8
  150. package/build/runtime-esm/hooks/useSubscriptionHandle.d.ts +0 -25
  151. package/build/runtime-esm/hooks/useSubscriptionHandle.js +0 -18
  152. package/build/runtime-esm/index.d.ts +0 -14
  153. package/build/runtime-esm/index.js +0 -48
  154. package/build/runtime-esm/manifest.d.ts +0 -3
  155. package/build/runtime-esm/manifest.js +0 -5
  156. package/build/runtime-esm/routing/Router.d.ts +0 -62
  157. package/build/runtime-esm/routing/Router.js +0 -499
  158. package/build/runtime-esm/routing/cache.d.ts +0 -7
  159. package/build/runtime-esm/routing/cache.js +0 -36
  160. package/build/runtime-esm/routing/hooks.d.ts +0 -40
  161. package/build/runtime-esm/routing/hooks.js +0 -53
  162. package/build/runtime-esm/routing/index.d.ts +0 -3
  163. package/build/runtime-esm/routing/index.js +0 -6
  164. package/build/server/index.d.ts +0 -1
  165. package/build/server-cjs/index.js +0 -28
  166. package/build/server-cjs/package.json +0 -1
  167. package/build/server-esm/index.js +0 -4
  168. /package/{build/plugin-esm → runtime}/package.json +0 -0
  169. /package/{build/runtime-esm → server}/package.json +0 -0
  170. /package/{build/server-esm → vite}/package.json +0 -0
@@ -0,0 +1,54 @@
1
+ // a suspense cache is an object that maintains a key-value store of
2
+ // objects. If a value is missing when get() is called, a promise
3
+ // is thrown that resolves when a value is passed to set()
4
+ import { LRUCache } from 'houdini/runtime'
5
+
6
+ export function suspense_cache<T>(initialData?: Record<string, T>): SuspenseCache<T> {
7
+ const cache = new SuspenseCache<T>()
8
+
9
+ for (const [key, value] of Object.entries(initialData ?? {})) {
10
+ cache.set(key, value)
11
+ }
12
+
13
+ return cache
14
+ }
15
+
16
+ export class SuspenseCache<_Data> extends LRUCache<_Data> {
17
+ // if get is called before set, we need to invoke a callback.
18
+ // that means we need a place to put our callbacks
19
+ #callbacks: Map<string, { resolve: () => void; reject: () => void }[]> = new Map()
20
+
21
+ get(key: string): _Data {
22
+ // if there is a value, use that
23
+ if (super.has(key)) {
24
+ return super.get(key)!
25
+ }
26
+
27
+ // we don't have a value, so we need to throw a promise
28
+ // that resolves when a value is passed to set()
29
+ throw new Promise<void>((resolve, reject) => {
30
+ this.#subscribe(key, resolve, reject)
31
+ })
32
+ }
33
+
34
+ // TODO: reject?
35
+
36
+ set(key: string, value: _Data) {
37
+ // perform the set like normal
38
+ super.set(key, value)
39
+
40
+ // if there are subscribers, resolve them
41
+ if (this.#callbacks.has(key)) {
42
+ // resolve all of the callbacks
43
+ this.#callbacks.get(key)?.forEach(({ resolve }) => {
44
+ resolve()
45
+ })
46
+ // delete the key
47
+ this.#callbacks.delete(key)
48
+ }
49
+ }
50
+
51
+ #subscribe(key: string, resolve: () => void, reject: () => void) {
52
+ this.#callbacks.set(key, [...(this.#callbacks.get(key) || []), { resolve, reject }])
53
+ }
54
+ }
@@ -0,0 +1,2 @@
1
+ export * from './Router'
2
+ export { type SuspenseCache, suspense_cache } from './cache'
@@ -0,0 +1 @@
1
+ export { renderToStream } from 'react-streaming/server';
@@ -0,0 +1,4 @@
1
+ import { renderToStream } from "react-streaming/server";
2
+ export {
3
+ renderToStream
4
+ };
File without changes
@@ -0,0 +1,3 @@
1
+ import { VitePluginContext } from 'houdini/vite';
2
+ import { PluginOption } from 'vite';
3
+ export default function (ctx: VitePluginContext): PluginOption;
package/vite/index.js ADDED
@@ -0,0 +1,284 @@
1
+ import { fs, path } from "houdini";
2
+ import {
3
+ app_component_path,
4
+ adapter_config_path,
5
+ plugin_dir,
6
+ client_build_directory
7
+ } from "houdini/router/conventions";
8
+ import { load_manifest } from "houdini/router/manifest";
9
+ import { createRequire } from "node:module";
10
+ import { build } from "vite";
11
+ import { transform_file } from "./transform.js";
12
+ const _require = createRequire(import.meta.url);
13
+ let reactStreamingServerPath = "";
14
+ try {
15
+ const main = _require.resolve("react-streaming");
16
+ const pkgDir = main.replace(/\/dist\/.*$/, "");
17
+ reactStreamingServerPath = path.join(pkgDir, "dist/server/index.node-and-web.js");
18
+ } catch {
19
+ }
20
+ function vite_default(ctx) {
21
+ let manifest;
22
+ let viteEnv;
23
+ let devServer = false;
24
+ let isSSRBuild = false;
25
+ let cfCache = null;
26
+ return {
27
+ name: "houdini-react",
28
+ configResolved(config) {
29
+ isSSRBuild = !!config.build.ssr;
30
+ },
31
+ async config(userConfig, env) {
32
+ viteEnv = env;
33
+ if (userConfig.build?.ssr) {
34
+ return reactStreamingServerPath ? { resolve: { alias: { "react-streaming/server": reactStreamingServerPath } } } : {};
35
+ }
36
+ try {
37
+ manifest = await load_manifest({ config: ctx.config });
38
+ } catch (e) {
39
+ console.log(
40
+ "something went wrong. please try again. \n error: " + e.message
41
+ );
42
+ manifest = {
43
+ pages: {},
44
+ layouts: {},
45
+ page_queries: {},
46
+ layout_queries: {},
47
+ artifacts: [],
48
+ local_schema: false,
49
+ local_yoga: false,
50
+ component_fields: {}
51
+ };
52
+ }
53
+ let conf = {
54
+ build: { rollupOptions: {} }
55
+ };
56
+ if (env.command === "build") {
57
+ conf.base = "/assets";
58
+ }
59
+ const compiledAssetsDir = client_build_directory(ctx.config);
60
+ await fs.mkdirp(compiledAssetsDir);
61
+ conf.build = {
62
+ outDir: compiledAssetsDir,
63
+ rollupOptions: {
64
+ output: {
65
+ assetFileNames: "assets/[name].js",
66
+ entryFileNames: "[name].js"
67
+ },
68
+ input: {
69
+ "entries/app": app_component_path(ctx.config),
70
+ ...ctx.adapter ? { "entries/adapter": adapter_config_path(ctx.config) } : {}
71
+ }
72
+ }
73
+ };
74
+ if (env.command === "build" && ctx.adapter && ctx.adapter.includePaths) {
75
+ const extra = typeof ctx.adapter.includePaths === "function" ? ctx.adapter.includePaths({ config: ctx.config }) : ctx.adapter.includePaths;
76
+ Object.assign(conf.build.rollupOptions.input, extra);
77
+ }
78
+ for (const [id, page] of Object.entries(manifest.pages)) {
79
+ ;
80
+ conf.build.rollupOptions.input[`pages/${id}`] = `virtual:houdini/pages/${page.id}.jsx`;
81
+ }
82
+ return reactStreamingServerPath ? {
83
+ ...conf,
84
+ resolve: { alias: { "react-streaming/server": reactStreamingServerPath } }
85
+ } : conf;
86
+ },
87
+ resolveId(id) {
88
+ if (!id.includes("virtual:houdini")) {
89
+ return;
90
+ }
91
+ return id.substring(id.indexOf("virtual:houdini"));
92
+ },
93
+ async transform(code, filepath) {
94
+ filepath = path.posixify(filepath);
95
+ if (filepath.startsWith("/src/")) {
96
+ filepath = path.join(process.cwd(), filepath);
97
+ }
98
+ if (!ctx.config.includeFile(filepath)) {
99
+ return;
100
+ }
101
+ if (cfCache === null) {
102
+ try {
103
+ cfCache = ctx.db.prepare("SELECT type, field, fragment FROM component_fields").all();
104
+ } catch {
105
+ cfCache = [];
106
+ }
107
+ }
108
+ return transform_file(
109
+ {
110
+ config: ctx.config,
111
+ content: code,
112
+ filepath: path.posixify(filepath),
113
+ watch_file: this.addWatchFile.bind(this)
114
+ },
115
+ cfCache
116
+ );
117
+ },
118
+ async closeBundle() {
119
+ if (viteEnv.mode !== "production" || devServer || isSSRBuild) {
120
+ return;
121
+ }
122
+ if (!ctx.adapter || ctx.adapter?.disableServer) {
123
+ return;
124
+ }
125
+ const compiledAssetsDir = client_build_directory(ctx.config);
126
+ await build({
127
+ build: {
128
+ ssr: true,
129
+ outDir: path.join(compiledAssetsDir, "ssr"),
130
+ rollupOptions: {
131
+ output: {
132
+ assetFileNames: "assets/[name].js",
133
+ entryFileNames: "[name].js"
134
+ },
135
+ input: {
136
+ "entries/adapter": adapter_config_path(ctx.config)
137
+ }
138
+ }
139
+ }
140
+ });
141
+ },
142
+ async load(id) {
143
+ if (!id.startsWith("virtual:houdini")) {
144
+ return;
145
+ }
146
+ if (!manifest) {
147
+ return;
148
+ }
149
+ let [, which, arg] = id.split("/");
150
+ const parsedPath = arg ? path.parse(arg) : "";
151
+ const pageName = parsedPath ? parsedPath.name : "";
152
+ if (which === "pages") {
153
+ const page = manifest.pages[pageName];
154
+ if (!page) {
155
+ throw new Error("unknown page" + pageName);
156
+ }
157
+ const pendingQueries = page.queries.filter((query) => {
158
+ const pg = Object.values(manifest.page_queries).find((q) => q.name === query);
159
+ if (pg) {
160
+ return pg.loading;
161
+ }
162
+ const layout = Object.values(manifest.layout_queries).find(
163
+ (q) => q.name === query
164
+ );
165
+ return layout?.loading;
166
+ });
167
+ return `
168
+ import App from '$houdini/plugins/houdini-react/units/render/App'
169
+ import Component from '$houdini/plugins/houdini-react/units/entries/${pageName}.jsx'
170
+ import { hydrate_page } from '$houdini/plugins/houdini-react/runtime/hydration'
171
+ hydrate_page(App, Component, '${pageName}', ${JSON.stringify(pendingQueries)})
172
+ `;
173
+ }
174
+ if (which === "artifacts") {
175
+ return `
176
+ import artifact from '$houdini/artifacts/${pageName}'
177
+ import { register_artifact } from '$houdini/plugins/houdini-react/runtime/hydration'
178
+ register_artifact('${pageName}', artifact)
179
+ `;
180
+ }
181
+ if (which === "static-entry") {
182
+ return `
183
+ import App from '$houdini/plugins/houdini-react/units/render/App'
184
+ import manifest from '$houdini/plugins/houdini-react/runtime/manifest'
185
+ import { mount_static_app } from '$houdini/plugins/houdini-react/runtime/hydration'
186
+ mount_static_app(App, manifest)
187
+ `;
188
+ }
189
+ },
190
+ async configureServer(server) {
191
+ devServer = true;
192
+ server.middlewares.use(async (req, res, next) => {
193
+ if (!req.url) {
194
+ next();
195
+ return;
196
+ }
197
+ const { default: router_manifest } = await server.ssrLoadModule(
198
+ path.join(plugin_dir(ctx.config, "houdini-react"), "runtime", "manifest.ts")
199
+ );
200
+ const { createServerAdapter } = await server.ssrLoadModule(
201
+ adapter_config_path(ctx.config)
202
+ );
203
+ const requestHeaders = new Headers();
204
+ for (const header of Object.entries(req.headers ?? {})) {
205
+ requestHeaders.set(header[0], header[1]);
206
+ }
207
+ const port = server.config.server.port ?? 5173;
208
+ const request = new Request(
209
+ `http://localhost:${port}` + req.url,
210
+ req.method === "POST" ? {
211
+ method: req.method,
212
+ headers: requestHeaders,
213
+ body: await getBody(req)
214
+ } : void 0
215
+ );
216
+ let documentPremable = `<script type="module" src="/@vite/client" async=""><\/script>`;
217
+ try {
218
+ const transformed = await server.transformIndexHtml(
219
+ req.url,
220
+ "<!DOCTYPE html><html><head></head><body></body></html>"
221
+ );
222
+ const headMatch = transformed.match(/<head>([\s\S]*?)<\/head>/);
223
+ if (headMatch?.[1]?.trim()) {
224
+ documentPremable = headMatch[1].trim();
225
+ }
226
+ } catch {
227
+ }
228
+ try {
229
+ const result = await createServerAdapter({
230
+ production: false,
231
+ manifest: router_manifest,
232
+ assetPrefix: "/virtual:houdini",
233
+ pipe: res,
234
+ documentPremable
235
+ })(request);
236
+ if (result && result.status === 404) {
237
+ return next();
238
+ }
239
+ if (result && typeof result !== "boolean") {
240
+ if (res.closed) {
241
+ return;
242
+ }
243
+ for (const header of result.headers ?? []) {
244
+ res.setHeader(header[0], header[1]);
245
+ }
246
+ if (result.status >= 300 && result.status < 400) {
247
+ res.writeHead(result.status, {
248
+ Location: result.headers.get("Location") ?? "",
249
+ ...[...result.headers].reduce(
250
+ (headers, [key, value]) => ({
251
+ ...headers,
252
+ [key]: value
253
+ }),
254
+ {}
255
+ )
256
+ });
257
+ } else {
258
+ res.write(await result.text());
259
+ }
260
+ res.end();
261
+ }
262
+ } catch (e) {
263
+ console.error(e);
264
+ res.end();
265
+ }
266
+ });
267
+ }
268
+ };
269
+ }
270
+ function getBody(request) {
271
+ return new Promise((resolve) => {
272
+ const bodyParts = [];
273
+ let body;
274
+ request.on("data", (chunk) => {
275
+ bodyParts.push(chunk);
276
+ }).on("end", () => {
277
+ body = Buffer.concat(bodyParts).toString();
278
+ resolve(body);
279
+ });
280
+ });
281
+ }
282
+ export {
283
+ vite_default as default
284
+ };
@@ -0,0 +1,11 @@
1
+ import type { TransformPage } from 'houdini';
2
+ import type { SourceMapInput } from 'rollup';
3
+ export type ComponentFieldRow = {
4
+ type: string;
5
+ field: string;
6
+ fragment: string;
7
+ };
8
+ export declare function transform_file(page: TransformPage, cfRows: ComponentFieldRow[]): Promise<{
9
+ code: string;
10
+ map?: SourceMapInput;
11
+ }>;
@@ -0,0 +1,92 @@
1
+ import * as graphql from "graphql";
2
+ import {
3
+ ArtifactKind,
4
+ artifact_import,
5
+ ensure_imports,
6
+ find_graphql,
7
+ parseJS,
8
+ path,
9
+ printJS
10
+ } from "houdini";
11
+ import { componentField_unit_path, houdini_root } from "houdini/router/conventions";
12
+ import * as recast from "recast";
13
+ const AST = recast.types.builders;
14
+ async function transform_file(page, cfRows) {
15
+ const isJSX = page.filepath.endsWith(".tsx") || page.filepath.endsWith(".jsx");
16
+ if (!isJSX && !page.filepath.endsWith(".ts") && !page.filepath.endsWith(".js")) {
17
+ return { code: page.content, map: page.map };
18
+ }
19
+ const script = parseJS(page.content, isJSX ? { plugins: ["jsx"] } : {});
20
+ const cfMap = {};
21
+ for (const row of cfRows) {
22
+ if (row.type && row.field && row.fragment) {
23
+ cfMap[row.type] ??= {};
24
+ cfMap[row.type][row.field] = row.fragment;
25
+ }
26
+ }
27
+ await find_graphql(page.config, script, {
28
+ skipGraphqlType: true,
29
+ tag({ node, artifact, parsedDocument }) {
30
+ const { id: artifactRef } = artifact_import({ page, script, artifact });
31
+ const properties = [AST.objectProperty(AST.stringLiteral("artifact"), artifactRef)];
32
+ if (is_paginated(parsedDocument)) {
33
+ if (artifact.kind !== ArtifactKind.Query) {
34
+ const refetchName = artifact.name + "_Pagination_Query";
35
+ const { id: refetchRef } = artifact_import({
36
+ page,
37
+ script,
38
+ artifact: { name: refetchName }
39
+ });
40
+ properties.push(
41
+ AST.objectProperty(AST.stringLiteral("refetchArtifact"), refetchRef)
42
+ );
43
+ } else {
44
+ properties.push(
45
+ AST.objectProperty(AST.stringLiteral("refetchArtifact"), artifactRef)
46
+ );
47
+ }
48
+ }
49
+ if (Object.keys(cfMap).length > 0) {
50
+ const typeInfo = new graphql.TypeInfo(page.config.schema);
51
+ graphql.visit(
52
+ parsedDocument,
53
+ graphql.visitWithTypeInfo(typeInfo, {
54
+ Field(fieldNode) {
55
+ const parentType = typeInfo.getParentType();
56
+ const typeName = parentType?.name;
57
+ if (!typeName)
58
+ return;
59
+ const fragmentName = cfMap[typeName]?.[fieldNode.name.value];
60
+ if (!fragmentName)
61
+ return;
62
+ const entryPointPath = componentField_unit_path(
63
+ page.config,
64
+ fragmentName
65
+ );
66
+ ensure_imports({
67
+ script,
68
+ sourceModule: "$houdini/" + path.relative(houdini_root(page.config), entryPointPath)
69
+ });
70
+ }
71
+ })
72
+ );
73
+ }
74
+ node.replaceWith(AST.objectExpression(properties));
75
+ }
76
+ });
77
+ return printJS(script);
78
+ }
79
+ function is_paginated(doc) {
80
+ let paginated = false;
81
+ graphql.visit(doc, {
82
+ Directive(node) {
83
+ if (node.name.value === "paginate") {
84
+ paginated = true;
85
+ }
86
+ }
87
+ });
88
+ return paginated;
89
+ }
90
+ export {
91
+ transform_file
92
+ };
package/README.md DELETED
@@ -1,36 +0,0 @@
1
- <div align="center">
2
- <picture>
3
- <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/HoudiniGraphql/houdini/main/.github/assets/logo_l.svg">
4
- <img height="140" alt="Houdini's logo (dark or light)" src="https://raw.githubusercontent.com/HoudiniGraphql/houdini/main/.github/assets/logo_d.svg">
5
- </picture>
6
- <br />
7
- <br />
8
- <strong>
9
- The disappearing GraphQL clients.
10
- </strong>
11
- <br />
12
- <br />
13
- <a href="https://npmjs.org/package/houdini">
14
- <img src="https://img.shields.io/npm/v/houdini.svg" alt="version" />
15
- </a>
16
- <a href="https://github.com/HoudiniGraphql/houdini/actions">
17
- <img src="https://github.com/HoudiniGraphql/houdini/actions/workflows/tests.yml/badge.svg" alt="CI Tests" />
18
- </a>
19
- <a href="https://github.com/HoudiniGraphql/houdini">
20
- <img src="https://img.shields.io/github/stars/HoudiniGraphql/houdini.svg?label=stars" alt="github stars" />
21
- </a>
22
- <a href="https://npmjs.org/package/houdini">
23
- <img src="https://img.shields.io/npm/dm/houdini.svg" alt="downloads" />
24
- </a>
25
- <a href="https://github.com/HoudiniGraphql/houdini/blob/main/LICENSE">
26
- <img src="https://img.shields.io/github/license/HoudiniGraphql/houdini.svg?maxAge=2592000" alt="license" />
27
- </a>
28
- </div>
29
-
30
- ----
31
-
32
- At its core, houdini seeks to enable a high quality developer experience
33
- without compromising bundle size. Like Svelte, houdini shifts what is
34
- traditionally handled by a bloated runtime into a compile step that allows
35
- for the generation of an incredibly lean GraphQL abstraction for your application.
36
- See more at <a href="https://www.houdinigraphql.com">HoudiniGraphQL.com</a> 🚀
@@ -1,6 +0,0 @@
1
- import { type Config, type ProjectManifest, type Document } from 'houdini';
2
- export declare function generate_routing_document_wrappers({ manifest, config, documents, }: {
3
- manifest: ProjectManifest;
4
- config: Config;
5
- documents: Record<string, Document>;
6
- }): Promise<void[]>;
@@ -1,5 +0,0 @@
1
- import { type Config, type ProjectManifest } from 'houdini';
2
- export declare function generate_fallbacks({ config, project, }: {
3
- config: Config;
4
- project: ProjectManifest;
5
- }): Promise<void>;
@@ -1,16 +0,0 @@
1
- import type { Config, ProjectManifest, PageManifest, Document } from 'houdini';
2
- import type { ComponentFieldData } from '..';
3
- export declare function generate_entries({ config, manifest, documents, componentFields, }: {
4
- config: Config;
5
- manifest: ProjectManifest;
6
- documents: Document[];
7
- componentFields: ComponentFieldData[];
8
- }): Promise<void>;
9
- export type PageBundleInput = {
10
- id: string;
11
- page: PageManifest;
12
- project: ProjectManifest;
13
- config: Config;
14
- documents: Record<string, Document>;
15
- componentFields: ComponentFieldData[];
16
- };
@@ -1,2 +0,0 @@
1
- import type { PageBundleInput } from '.';
2
- export declare function generate_page_entries(args: PageBundleInput): Promise<void>;
@@ -1,17 +0,0 @@
1
- import type { Config, GenerateHookInput, ProjectManifest } from 'houdini';
2
- import { processComponentFieldDirective } from 'houdini';
3
- /**
4
- * The router is fundamentally a component that knows how to render
5
- * a particular component tree for a given url. This is driven by something
6
- * we call the applications "manifest".
7
- *
8
- * In react, the tree of route directories maps to a component hierarchy
9
- * with suspense boundaries sprinkled when there is a loading directive
10
- * present on a query.
11
- */
12
- export default function routerCodegen({ config, manifest, documents, }: GenerateHookInput & {
13
- manifest: ProjectManifest;
14
- }): Promise<void>;
15
- export type ComponentFieldData = ReturnType<typeof processComponentFieldDirective> & Config['componentFields'][string][string] & {
16
- type: string;
17
- };
@@ -1,5 +0,0 @@
1
- import { type Config, type ProjectManifest } from 'houdini';
2
- export declare function write_manifest({ config, manifest, }: {
3
- config: Config;
4
- manifest: ProjectManifest;
5
- }): Promise<void>;
@@ -1,7 +0,0 @@
1
- import { type Config, type ProjectManifest } from 'houdini';
2
- import type { ComponentFieldData } from '.';
3
- export declare function generate_renders({ componentFields, config, manifest, }: {
4
- componentFields: ComponentFieldData[];
5
- config: Config;
6
- manifest: ProjectManifest;
7
- }): Promise<void>;
@@ -1,7 +0,0 @@
1
- import { type Config, type ProjectManifest } from 'houdini';
2
- export declare function format_router_manifest({ config, manifest, exportDefaultStatement, }: {
3
- config: Config;
4
- manifest: ProjectManifest;
5
- exportDefaultStatement: (name: string) => string;
6
- importStatement: (from: string, as: string) => string;
7
- }): string;
@@ -1,5 +0,0 @@
1
- import { type Config, type ProjectManifest } from 'houdini';
2
- export declare function generate_type_root({ config, manifest, }: {
3
- config: Config;
4
- manifest: ProjectManifest;
5
- }): Promise<void>;
@@ -1,4 +0,0 @@
1
- import type { Config } from 'houdini';
2
- import type { HoudiniReactPluginConfig } from '.';
3
- export declare function plugin_config(config: Config): HoudiniReactPluginConfig;
4
- export declare function test_config(): Promise<Config>;
@@ -1 +0,0 @@
1
- export declare function dedent(indentString: string, input?: string): string;
@@ -1,6 +0,0 @@
1
- import type { Config } from 'houdini';
2
- export declare function extractDocuments({ content, config, filepath, }: {
3
- config: Config;
4
- content: string;
5
- filepath: string;
6
- }): Promise<string[]>;
@@ -1,5 +0,0 @@
1
- import { type Plugin } from 'houdini';
2
- export declare const hooks: Plugin;
3
- declare const _default: import("houdini").PluginInit;
4
- export default _default;
5
- export type HoudiniReactPluginConfig = {};
@@ -1,3 +0,0 @@
1
- import type { ProjectManifest } from 'houdini';
2
- export declare let manifest: ProjectManifest;
3
- export declare function setManifest(newManifest: ProjectManifest): void;
@@ -1,6 +0,0 @@
1
- import type { TransformPage } from 'houdini/vite';
2
- import type { SourceMapInput } from 'rollup';
3
- export declare function transformFile(page: TransformPage): Promise<{
4
- code: string;
5
- map?: SourceMapInput;
6
- }>;
@@ -1,27 +0,0 @@
1
- import { ConfigEnv } from 'vite';
2
- declare const _default: {
3
- config?: ((config: import("houdini").Config, env: ConfigEnv) => import("vite").UserConfig | Promise<import("vite").UserConfig>) | undefined;
4
- buildStart?: ((this: import("rollup").PluginContext, options: import("rollup").NormalizedInputOptions & {
5
- houdiniConfig: import("houdini").Config;
6
- }) => void | Promise<void>) | undefined;
7
- buildEnd?: ((this: import("rollup").PluginContext, error?: Error | undefined, houdiniConfig?: import("houdini").Config | undefined) => void | Promise<void>) | undefined;
8
- closeBundle?: ((this: import("rollup").PluginContext, config: import("houdini").Config) => void | Promise<void>) | undefined;
9
- configResolved?: import("rollup").ObjectHook<(this: void, config: import("vite").ResolvedConfig) => void | Promise<void>, {}> | undefined;
10
- options?: ((this: import("rollup").MinimalPluginContext, options: import("rollup").InputOptions & {
11
- houdiniConfig: import("houdini").Config;
12
- }) => import("rollup").InputOptions | import("rollup").NullValue) | undefined;
13
- resolveId?: import("rollup").ObjectHook<(this: import("rollup").PluginContext, source: string, importer: string | undefined, options: {
14
- config: import("houdini").Config;
15
- custom?: import("rollup").CustomPluginOptions | undefined;
16
- ssr?: boolean | undefined;
17
- isEntry: boolean;
18
- }) => import("rollup").ResolveIdResult | Promise<import("rollup").ResolveIdResult>, {}> | undefined;
19
- load?: import("rollup").ObjectHook<(this: import("rollup").PluginContext, id: string, options: {
20
- config: import("houdini").Config;
21
- ssr?: boolean | undefined;
22
- }) => import("rollup").LoadResult | Promise<import("rollup").LoadResult>, {}> | undefined;
23
- configureServer?: import("rollup").ObjectHook<(this: void, server: import("vite").ViteDevServer & {
24
- houdiniConfig: import("houdini").Config;
25
- }) => void | (() => void) | Promise<void | (() => void)>, {}> | undefined;
26
- } | undefined;
27
- export default _default;