eddev 2.0.0-beta.6 → 2.0.0-beta.61

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 (257) hide show
  1. package/dist/app/entry/MetaTags.d.ts +7 -0
  2. package/dist/app/entry/MetaTags.js +17 -0
  3. package/dist/app/entry/boot-admin.d.ts +1 -0
  4. package/dist/app/entry/boot-admin.js +14 -0
  5. package/dist/app/entry/spa-root.d.ts +1 -0
  6. package/dist/app/entry/spa-root.js +8 -0
  7. package/dist/app/entry/ssr-root-client.d.ts +6 -0
  8. package/dist/app/entry/ssr-root-client.js +26 -0
  9. package/dist/app/entry/ssr-root.d.ts +10 -0
  10. package/dist/app/entry/ssr-root.js +23 -0
  11. package/dist/app/lib/admin/index.d.ts +2 -2
  12. package/dist/app/lib/admin/index.js +2 -2
  13. package/dist/app/lib/admin/installFieldTypes.js +1 -1
  14. package/dist/app/lib/admin/runWidgets.js +1 -1
  15. package/dist/app/lib/blocks/ContentBlocks.d.ts +1 -1
  16. package/dist/app/lib/blocks/ContentBlocks.js +5 -5
  17. package/dist/app/lib/blocks/EditableText.d.ts +1 -1
  18. package/dist/app/lib/blocks/EditableText.js +3 -3
  19. package/dist/app/lib/blocks/InnerBlocks.d.ts +13 -3
  20. package/dist/app/lib/blocks/InnerBlocks.js +13 -5
  21. package/dist/app/lib/blocks/block-utils.d.ts +2 -2
  22. package/dist/app/lib/blocks/block-utils.js +2 -2
  23. package/dist/app/lib/blocks/editor/EditorSupport.js +4 -5
  24. package/dist/app/lib/blocks/editor/editor-config.d.ts +16 -3
  25. package/dist/app/lib/blocks/editor/editor-config.js +2 -4
  26. package/dist/app/lib/blocks/editor/installGutenbergHooks.js +17 -13
  27. package/dist/app/lib/blocks/editor/root-blocks.d.ts +6 -0
  28. package/dist/app/lib/blocks/editor/root-blocks.js +30 -0
  29. package/dist/app/lib/blocks/editor/usePostEditor.d.ts +1 -1
  30. package/dist/app/lib/blocks/index.d.ts +9 -9
  31. package/dist/app/lib/blocks/index.js +9 -9
  32. package/dist/app/lib/blocks/inline-editing.d.ts +1 -1
  33. package/dist/app/lib/blocks/inline-editing.js +7 -5
  34. package/dist/app/lib/devtools/components/BreakpointIndicator.js +6 -4
  35. package/dist/app/lib/devtools/components/DevUI.js +4 -3
  36. package/dist/app/lib/devtools/components/GridIndicator.d.ts +1 -0
  37. package/dist/app/lib/devtools/components/GridIndicator.js +24 -0
  38. package/dist/app/lib/devtools/dev-tools-store.d.ts +9 -0
  39. package/dist/app/lib/devtools/dev-tools-store.js +8 -0
  40. package/dist/app/lib/devtools/hooks/usePersistState.d.ts +1 -1
  41. package/dist/app/lib/devtools/hooks/usePersistState.js +11 -2
  42. package/dist/app/lib/devtools/hooks/useTailwind.d.ts +1094 -1095
  43. package/dist/app/lib/devtools/hooks/useTailwind.js +6 -3
  44. package/dist/app/lib/devtools/index.d.ts +1 -0
  45. package/dist/app/lib/devtools/index.js +1 -1
  46. package/dist/app/lib/devtools/loader.js +8 -7
  47. package/dist/app/lib/devtools/useQueryDebug.d.ts +7 -1
  48. package/dist/app/lib/devtools/useQueryDebug.js +5 -8
  49. package/dist/app/lib/dynamic/index.d.ts +1 -1
  50. package/dist/app/lib/dynamic/index.js +1 -1
  51. package/dist/app/lib/hooks/index.d.ts +4 -5
  52. package/dist/app/lib/hooks/index.js +4 -5
  53. package/dist/app/lib/hooks/queryUtils.d.ts +37 -3
  54. package/dist/app/lib/hooks/queryUtils.js +63 -26
  55. package/dist/app/lib/hooks/useAppData.js +1 -1
  56. package/dist/app/lib/hooks/useRPC.d.ts +0 -4
  57. package/dist/app/lib/hooks/useRPC.js +1 -8
  58. package/dist/app/lib/internal/finalize-rpc.d.ts +17 -0
  59. package/dist/app/lib/internal/finalize-rpc.js +3 -0
  60. package/dist/app/lib/internal/index.d.ts +5 -4
  61. package/dist/app/lib/internal/index.js +5 -4
  62. package/dist/app/lib/internal/internal-store.d.ts +0 -2
  63. package/dist/app/lib/internal/internal-store.js +1 -3
  64. package/dist/app/lib/internal/read-admin-manifest.d.ts +1 -1
  65. package/dist/app/lib/legacy-stitches/createStitches.d.ts +21 -21
  66. package/dist/app/lib/legacy-stitches/createStitches.js +1 -1
  67. package/dist/app/lib/legacy-stitches/index.d.ts +1 -1
  68. package/dist/app/lib/legacy-stitches/index.js +1 -1
  69. package/dist/app/lib/routing/components/BackButton.d.ts +49 -0
  70. package/dist/app/lib/routing/components/BackButton.js +47 -0
  71. package/dist/app/lib/routing/components/BrowserRouter.d.ts +4 -1
  72. package/dist/app/lib/routing/components/BrowserRouter.js +79 -11
  73. package/dist/app/lib/routing/components/ClientOnly.js +1 -1
  74. package/dist/app/lib/routing/components/Link.d.ts +1 -0
  75. package/dist/app/lib/routing/components/Link.js +9 -10
  76. package/dist/app/lib/routing/components/RouteRenderer.d.ts +1 -1
  77. package/dist/app/lib/routing/components/RouteRenderer.js +7 -6
  78. package/dist/app/lib/routing/components/SSRRouter.d.ts +2 -2
  79. package/dist/app/lib/routing/components/SSRRouter.js +5 -6
  80. package/dist/app/lib/routing/components/ScrollRestoration.js +1 -1
  81. package/dist/app/lib/routing/context.d.ts +8 -5
  82. package/dist/app/lib/routing/context.js +13 -96
  83. package/dist/app/lib/routing/hooks/useRestorableState.d.ts +2 -1
  84. package/dist/app/lib/routing/hooks/useRestorableState.js +2 -1
  85. package/dist/app/lib/routing/hooks/useRoute.d.ts +16 -1
  86. package/dist/app/lib/routing/hooks/useRoute.js +22 -1
  87. package/dist/app/lib/routing/hooks/useRouteMeta.d.ts +5 -0
  88. package/dist/app/lib/routing/hooks/useRouteMeta.js +9 -0
  89. package/dist/app/lib/routing/hooks/useRouteTransition.d.ts +1 -1
  90. package/dist/app/lib/routing/hooks/useRouteTransition.js +1 -1
  91. package/dist/app/lib/routing/hooks/useRouter.d.ts +1 -1
  92. package/dist/app/lib/routing/hooks/useRouter.js +1 -1
  93. package/dist/app/lib/routing/hooks/useRouterEvents.d.ts +1 -1
  94. package/dist/app/lib/routing/hooks/useRouterEvents.js +1 -1
  95. package/dist/app/lib/routing/hooks/useRouterState.d.ts +1 -1
  96. package/dist/app/lib/routing/hooks/useRouterState.js +1 -1
  97. package/dist/app/lib/routing/hooks/useSearchParams.js +2 -2
  98. package/dist/app/lib/routing/index.d.ts +14 -13
  99. package/dist/app/lib/routing/index.js +14 -13
  100. package/dist/app/lib/routing/loader.d.ts +2 -2
  101. package/dist/app/lib/routing/loader.js +7 -5
  102. package/dist/app/lib/routing/types.d.ts +35 -9
  103. package/dist/app/lib/routing/utils.d.ts +3 -1
  104. package/dist/app/lib/routing/utils.js +12 -1
  105. package/dist/app/lib/{hooks → runtime}/apiConfig.d.ts +6 -2
  106. package/dist/app/lib/runtime/apiConfig.js +6 -0
  107. package/dist/app/lib/runtime/errorHandling.d.ts +39 -0
  108. package/dist/app/lib/runtime/errorHandling.js +6 -0
  109. package/dist/app/lib/runtime/index.d.ts +2 -0
  110. package/dist/app/lib/runtime/index.js +2 -0
  111. package/dist/app/lib/views/index.d.ts +1 -1
  112. package/dist/app/lib/views/index.js +1 -1
  113. package/dist/app/server/defineRouter.d.ts +2 -0
  114. package/dist/app/server/defineRouter.js +4 -0
  115. package/dist/app/server/index.d.ts +5 -0
  116. package/dist/app/server/index.js +5 -0
  117. package/dist/app/server/proxy-wp-admin.d.ts +2 -0
  118. package/dist/app/server/proxy-wp-admin.js +112 -0
  119. package/dist/app/server/render-ssr-page.d.ts +11 -0
  120. package/dist/app/server/render-ssr-page.js +100 -0
  121. package/dist/app/server/rpc.d.ts +56 -0
  122. package/dist/app/server/rpc.js +18 -0
  123. package/dist/app/server/server-context.d.ts +53 -0
  124. package/dist/app/server/server-context.js +149 -0
  125. package/dist/app/server/utils/headers.d.ts +1 -0
  126. package/dist/app/server/utils/headers.js +17 -0
  127. package/dist/app/server/utils/replace-host.d.ts +6 -4
  128. package/dist/app/server/utils/replace-host.js +58 -11
  129. package/dist/app/utils/APIProvider.d.ts +2 -0
  130. package/dist/app/utils/APIProvider.js +5 -0
  131. package/dist/app/utils/BlockErrorBoundary.d.ts +19 -0
  132. package/dist/app/utils/BlockErrorBoundary.js +38 -0
  133. package/dist/app/utils/ErrorMessage.d.ts +5 -0
  134. package/dist/app/utils/ErrorMessage.js +14 -0
  135. package/dist/app/utils/RouteErrorBoundary.d.ts +18 -0
  136. package/dist/app/utils/RouteErrorBoundary.js +38 -0
  137. package/dist/app/utils/query-client.d.ts +2 -0
  138. package/dist/app/utils/query-client.js +5 -1
  139. package/dist/app/utils/trpc-client.d.ts +2 -0
  140. package/dist/app/utils/trpc-client.js +34 -0
  141. package/dist/node/cli/cli-worker.d.ts +1 -1
  142. package/dist/node/cli/cli-worker.js +12 -3
  143. package/dist/node/cli/cli.js +91 -13
  144. package/dist/node/cli/display/CLIApp.d.ts +1 -1
  145. package/dist/node/cli/display/CLIApp.js +4 -7
  146. package/dist/node/cli/display/components/LogEntries.d.ts +1 -1
  147. package/dist/node/cli/display/hooks/useStatefulLog.d.ts +1 -1
  148. package/dist/node/cli/display/tools/CreateBlock.d.ts +1 -1
  149. package/dist/node/cli/display/tools/cli-tools.d.ts +1 -11
  150. package/dist/node/cli/display/tools/cli-tools.js +9 -9
  151. package/dist/node/cli/display/util/colors.d.ts +2 -2
  152. package/dist/node/cli/version.d.ts +1 -1
  153. package/dist/node/cli/version.js +1 -1
  154. package/dist/node/compiler/build-vinxi.d.ts +8 -0
  155. package/dist/node/compiler/build-vinxi.js +38 -0
  156. package/dist/node/compiler/bundler.admin.d.ts +2 -2
  157. package/dist/node/compiler/bundler.admin.js +3 -4
  158. package/dist/node/compiler/bundler.frontend.d.ts +1 -1
  159. package/dist/node/compiler/bundler.frontend.js +3 -4
  160. package/dist/node/compiler/{serverless.dev.d.ts → dev-server.d.ts} +7 -5
  161. package/dist/node/compiler/dev-server.js +106 -0
  162. package/dist/node/compiler/get-vite-config.d.ts +19 -0
  163. package/dist/node/compiler/get-vite-config.js +200 -0
  164. package/dist/node/compiler/vinxi-app.d.ts +20 -0
  165. package/dist/node/compiler/vinxi-app.js +186 -0
  166. package/dist/node/compiler/vinxi-codegen.d.ts +12 -0
  167. package/dist/node/compiler/vinxi-codegen.js +515 -0
  168. package/dist/node/graphql/graphql-codegen.d.ts +12 -2
  169. package/dist/node/graphql/graphql-codegen.js +213 -36
  170. package/dist/node/graphql/graphql-schema-loader.js +15 -18
  171. package/dist/node/graphql/plugins/gql-plugin-queries.js +1 -1
  172. package/dist/node/graphql/query-files-loader.d.ts +3 -0
  173. package/dist/node/graphql/query-files-loader.js +5 -0
  174. package/dist/node/project/config.d.ts +31 -37
  175. package/dist/node/project/config.js +13 -11
  176. package/dist/node/project/env.d.ts +1 -1
  177. package/dist/node/project/env.js +1 -1
  178. package/dist/node/project/manifest/block-manifest.js +3 -2
  179. package/dist/node/project/manifest/manifest.d.ts +2 -1
  180. package/dist/node/project/manifest/manifest.js +15 -11
  181. package/dist/node/project/manifest/routes-manifest.d.ts +20 -0
  182. package/dist/node/project/manifest/routes-manifest.js +74 -0
  183. package/dist/node/project/manifest/view-manifest.js +2 -2
  184. package/dist/node/project/project.d.ts +5 -2
  185. package/dist/node/project/project.js +21 -20
  186. package/dist/node/project/wp-info.js +3 -2
  187. package/dist/node/types/block-type.d.ts +5 -0
  188. package/dist/node/types/block-type.js +1 -0
  189. package/dist/node/types/view-type.js +3 -4
  190. package/dist/node/utils/fs-codegen.d.ts +42 -0
  191. package/dist/node/utils/fs-codegen.js +98 -0
  192. package/dist/node/utils/fs.js +2 -0
  193. package/dist/node/utils/{selfSignedCert.js → self-signed-cert.js} +1 -1
  194. package/dist/node/utils/{statefulLog.js → stateful-log.js} +1 -1
  195. package/dist/node/utils/watch-file-tree.d.ts +25 -0
  196. package/dist/node/utils/{watchFileTree.js → watch-file-tree.js} +12 -5
  197. package/package.json +39 -32
  198. package/types.app.d.ts +4 -2
  199. package/types.app.internal.d.ts +2 -2
  200. package/types.node.d.ts +3 -3
  201. package/dist/app/entry/Root.d.ts +0 -1
  202. package/dist/app/entry/Root.js +0 -9
  203. package/dist/app/entry/main.admin.d.ts +0 -3
  204. package/dist/app/entry/main.admin.js +0 -10
  205. package/dist/app/entry/main.frontend.spa.d.ts +0 -3
  206. package/dist/app/entry/main.frontend.spa.js +0 -13
  207. package/dist/app/entry/main.frontend.ssr.d.ts +0 -21
  208. package/dist/app/entry/main.frontend.ssr.js +0 -79
  209. package/dist/app/entry/main.serverless.dev.d.ts +0 -4
  210. package/dist/app/entry/main.serverless.dev.js +0 -21
  211. package/dist/app/lib/blocks/ErrorBoundaryFrontend.d.ts +0 -15
  212. package/dist/app/lib/blocks/ErrorBoundaryFrontend.js +0 -35
  213. package/dist/app/lib/hooks/apiConfig.js +0 -4
  214. package/dist/app/lib/hooks/usePageLoad.d.ts +0 -6
  215. package/dist/app/lib/hooks/usePageLoad.js +0 -5
  216. package/dist/app/server/create-api-builtin-hono.d.ts +0 -8
  217. package/dist/app/server/create-api-builtin-hono.js +0 -80
  218. package/dist/app/server/create-ssr-hono.d.ts +0 -18
  219. package/dist/app/server/create-ssr-hono.js +0 -104
  220. package/dist/app/server/utils/index.html.d.ts +0 -2
  221. package/dist/app/server/utils/index.html.js +0 -14
  222. package/dist/node/compiler/index.html.d.ts +0 -2
  223. package/dist/node/compiler/index.html.js +0 -15
  224. package/dist/node/compiler/serverless.dev.js +0 -222
  225. package/dist/node/compiler/vite/get-vite-config.d.ts +0 -13
  226. package/dist/node/compiler/vite/get-vite-config.js +0 -315
  227. package/dist/node/compiler/vite/plugin-admin.d.ts +0 -4
  228. package/dist/node/compiler/vite/plugin-admin.js +0 -67
  229. package/dist/node/compiler/vite/plugin-blocks.d.ts +0 -4
  230. package/dist/node/compiler/vite/plugin-blocks.js +0 -73
  231. package/dist/node/compiler/vite/plugin-entry.d.ts +0 -6
  232. package/dist/node/compiler/vite/plugin-entry.js +0 -16
  233. package/dist/node/compiler/vite/plugin-resolved-tailwind.d.ts +0 -4
  234. package/dist/node/compiler/vite/plugin-resolved-tailwind.js +0 -29
  235. package/dist/node/compiler/vite/plugin-theme.d.ts +0 -4
  236. package/dist/node/compiler/vite/plugin-theme.js +0 -40
  237. package/dist/node/compiler/vite/plugin-views.d.ts +0 -4
  238. package/dist/node/compiler/vite/plugin-views.js +0 -51
  239. package/dist/node/utils/console.d.ts +0 -21
  240. package/dist/node/utils/console.js +0 -28
  241. package/dist/node/utils/unsafe-fetch.d.ts +0 -2
  242. package/dist/node/utils/unsafe-fetch.js +0 -19
  243. package/dist/node/utils/watchFileTree.d.ts +0 -11
  244. package/tsup.config.ts +0 -40
  245. package/types.manifests.d.ts +0 -22
  246. /package/dist/node/utils/{formatZodError.d.ts → format-zod-error.d.ts} +0 -0
  247. /package/dist/node/utils/{formatZodError.js → format-zod-error.js} +0 -0
  248. /package/dist/node/utils/{getRepoInfo.d.ts → get-repo-info.d.ts} +0 -0
  249. /package/dist/node/utils/{getRepoInfo.js → get-repo-info.js} +0 -0
  250. /package/dist/node/utils/{highlightCode.d.ts → highlight-code.d.ts} +0 -0
  251. /package/dist/node/utils/{highlightCode.js → highlight-code.js} +0 -0
  252. /package/dist/node/utils/{isDeploying.d.ts → is-deploying.d.ts} +0 -0
  253. /package/dist/node/utils/{isDeploying.js → is-deploying.js} +0 -0
  254. /package/dist/node/utils/{selfSignedCert.d.ts → self-signed-cert.d.ts} +0 -0
  255. /package/dist/node/utils/{statefulLog.d.ts → stateful-log.d.ts} +0 -0
  256. /package/dist/node/utils/{export-extractor.d.ts → ts-export-extractor.d.ts} +0 -0
  257. /package/dist/node/utils/{export-extractor.js → ts-export-extractor.js} +0 -0
@@ -0,0 +1,515 @@
1
+ import { code, imp } from "ts-poet";
2
+ import { FSCodegen } from "../utils/fs-codegen.js";
3
+ import { camelCase } from "change-case-all";
4
+ export function getVinxiFolder(opts) {
5
+ return (opts.mode === "development" ? "dev" : "prod") + (opts.serverless ? "" : "-spa");
6
+ }
7
+ export async function runVinxiCodegen(opts) {
8
+ const codegen = createVinxiCodegen(opts);
9
+ await codegen.run();
10
+ codegen.stop();
11
+ }
12
+ export function createVinxiCodegen(opts) {
13
+ const project = opts.project;
14
+ const folder = ".eddev/" + getVinxiFolder(opts);
15
+ const codegen = new FSCodegen(opts.project, {
16
+ outDir: folder,
17
+ });
18
+ if (opts.serverless) {
19
+ codegen.registerFile({
20
+ name: "context.ts",
21
+ generate: async () => {
22
+ const args = {
23
+ dev: true,
24
+ origin: project.origin,
25
+ replaceUrls: {
26
+ from: project.origin,
27
+ to: opts.endpoint ?? "",
28
+ prefixes: [
29
+ { prefix: "/wp-content/uploads", replace: project.config?.serverless.uploads === "proxy" },
30
+ { prefix: "/wp-content/plugins", replace: project.config?.serverless.plugins === "proxy" },
31
+ ],
32
+ },
33
+ rpcBases: (await project.serverRoutes.get()).bases ?? [],
34
+ };
35
+ return code /* tsx */ `
36
+ import { ServerContext } from "eddev/server"
37
+ import { getManifest } from "vinxi/manifest"
38
+
39
+ ServerContext.setRuntime({
40
+ getManifest
41
+ })
42
+
43
+ export const serverContext = new ServerContext({${Object.entries(args)
44
+ .map(([key, value]) => `${key}: ${JSON.stringify(value)}`)
45
+ .join(",\n")}
46
+ })
47
+ `.toString();
48
+ },
49
+ });
50
+ }
51
+ if (opts.serverless) {
52
+ codegen.registerFile({
53
+ name: "react-shim.js",
54
+ generate: code /* tsx */ `
55
+ import React from "react"
56
+ import ReactDOM from "react-dom/client"
57
+ Object.assign(React, window.React)
58
+ Object.assign(ReactDOM, window.ReactDOM)
59
+ `,
60
+ });
61
+ }
62
+ if (opts.serverless) {
63
+ // codegen.registerFile({
64
+ // name: "manifest/extra-routes.ts",
65
+ // generate: code/* tsx */ `
66
+ // import { createRouter, eventHandler, getRouterParam, getQuery, getWebRequest, getRequestHeaders } from "vinxi/http"
67
+ // import { serverContext } from "./context.js"
68
+ // export const routes = [
69
+ // {
70
+ // pattern: '/test1',
71
+ // handler: () => import('../../../test.ts')
72
+ // }
73
+ // ]
74
+ // export default eventHandler((event) => {
75
+ // routes
76
+ // })
77
+ // `,
78
+ // })
79
+ }
80
+ codegen.registerFile({
81
+ name: "entry.admin.tsx",
82
+ generate: () => {
83
+ return code /* tsx */ `
84
+ ${opts.serverless ? `import "./react-shim.js"` : ""}
85
+ ${opts.serverless ? `import "vinxi/client"` : ""}
86
+ import "../../views/index.css"
87
+ import "./manifest/admin"
88
+ import "./manifest/blocks"
89
+ import "./manifest/styles"
90
+ import bootAdmin from "eddev/_internal/boot-admin.js"
91
+
92
+ bootAdmin()
93
+ `;
94
+ },
95
+ });
96
+ codegen.registerFile({
97
+ name: "entry.client.tsx",
98
+ generate: () => {
99
+ if (opts.serverless) {
100
+ /**
101
+ * Client entry for SSR mode
102
+ */
103
+ return code /* tsx */ `
104
+ /// <reference types="vinxi/types/client" />
105
+ /**
106
+ * SSR-mode frontend entry.
107
+ * Hydrates the main app, including the html/head/body elements.
108
+ * Also ensures that the assets used during SSR are loaded.
109
+ */
110
+ import "vinxi/client"
111
+ import "../../views/index.css"
112
+ import "./manifest/blocks"
113
+ import "./manifest/views"
114
+
115
+ import * as React from "react"
116
+ import { Root, hydrateRoot } from "react-dom/client"
117
+ import { SSRClientRoot } from "eddev/_internal/ssr-root-client.js"
118
+ import { getManifest } from "vinxi/manifest"
119
+ import { createAssets } from "@vinxi/react"
120
+ import { devToolsStore } from 'eddev/devtools'
121
+
122
+ // Set up a dynamic entry which will load the configured tailwind manifest
123
+ devToolsStore.loadTailwindConfig = () => import('./manifest/tailwind-config.js')
124
+
125
+ // Create the asset renderer, which will ensure scripts/styles are mounted correctly
126
+ function getAssets() {
127
+ const Assets = createAssets(getManifest("client").handler, getManifest("client"))
128
+ return <React.Suspense><Assets /></React.Suspense>
129
+ }
130
+
131
+ window.$reactRoot =
132
+ window.$reactRoot ||
133
+ hydrateRoot(
134
+ document,
135
+ <SSRClientRoot assets={getAssets()} metaTags={window._PAGE_DATA.meta.head} />,
136
+ )
137
+
138
+ if (import.meta.hot) {
139
+ import.meta.hot.accept((mod) => {
140
+ if (mod) {
141
+ const Assets = createAssets(getManifest("client").handler, getManifest("client"))
142
+ const app = <SSRClientRoot assets={getAssets()} metaTags={window._PAGE_DATA.meta.head} />
143
+ window.$reactRoot?.render(app)
144
+ }
145
+ })
146
+ }
147
+
148
+ declare global {
149
+ interface Window {
150
+ $reactRoot?: Root
151
+ _PAGE_DATA: any
152
+ }
153
+ }
154
+
155
+ `;
156
+ }
157
+ else {
158
+ return code /* tsx */ `
159
+ /**
160
+ * SPA-mode frontend entry.
161
+ * Renders the main app into the empty <div id='root'> element, and expects window._PAGE_DATA to be set.
162
+ */
163
+ import "./manifest/blocks"
164
+ import "./manifest/views"
165
+ import "../../views/index.css"
166
+ import { devToolsStore } from 'eddev/devtools'
167
+ import { createRoot } from "react-dom/client"
168
+ import { SPARoot } from "eddev/_internal/spa-root.js"
169
+ import * as React from "react"
170
+
171
+ devToolsStore.loadTailwindConfig = () => import('./manifest/tailwind-config')
172
+
173
+ createRoot(document.getElementById("root")!).render(<SPARoot />)
174
+ `;
175
+ }
176
+ },
177
+ });
178
+ if (opts.serverless) {
179
+ codegen.registerFile({
180
+ name: "handler.data-api.ts",
181
+ generate: code /* tsx */ `
182
+ /// <reference types="vinxi/types/server" />
183
+ import { createRouter, eventHandler, getRouterParam, getQuery, getWebRequest, getRequestHeaders } from "vinxi/http"
184
+ import { serverContext } from "./context.js"
185
+
186
+ const router = createRouter()
187
+ .get(
188
+ "/route/",
189
+ eventHandler(async (event) => {
190
+ const id = "/"
191
+
192
+ return await serverContext.fetchRouteData({
193
+ pathname: id,
194
+ withAppData: false,
195
+ })
196
+ }),
197
+ )
198
+ .get(
199
+ "/route/**:name",
200
+ eventHandler(async (event) => {
201
+ const id = "/" + getRouterParam(event, "name")
202
+
203
+ return await serverContext.fetchRouteData({
204
+ pathname: id,
205
+ withAppData: false,
206
+ })
207
+ }),
208
+ )
209
+ .get(
210
+ "/query/**:name",
211
+ eventHandler(async (event) => {
212
+ const id = "/" + getRouterParam(event, "name")
213
+ const paramString = getQuery(event).params
214
+
215
+ const params = typeof paramString === "string" && paramString.length ? JSON.parse(paramString) : {}
216
+
217
+ return await serverContext.fetchNamedQuery({
218
+ name: id,
219
+ params: params,
220
+ headers: getRequestHeaders(event),
221
+ })
222
+ }),
223
+ )
224
+ .post(
225
+ "/mutation/**:name",
226
+ eventHandler(async (event) => {
227
+ const id = "/" + getRouterParam(event, "name")
228
+ const body = await getWebRequest(event).json()
229
+ return await serverContext.fetchMutation({
230
+ name: id,
231
+ body,
232
+ headers: getRequestHeaders(event),
233
+ })
234
+ }),
235
+ )
236
+
237
+ export default router.handler
238
+
239
+ `,
240
+ });
241
+ }
242
+ if (opts.serverless) {
243
+ codegen.registerFile({
244
+ name: "handler.ssr-page.ts",
245
+ generate: code /* tsx */ `
246
+ /// <reference types="vinxi/types/server" />
247
+ import "../../views/index.css"
248
+ import "./manifest/blocks.js"
249
+ import "./manifest/styles.js"
250
+ import "./manifest/views.js"
251
+ import "./context.js"
252
+ import { handleRPC } from "./rpc.js"
253
+ import { proxyWpAdmin, ServerContext, renderPage } from "eddev/server"
254
+ import { eventHandler, getRequestURL } from "vinxi/http"
255
+
256
+ export default eventHandler({
257
+ handler: async (event) => {
258
+ const serverContext = ServerContext.main
259
+ const url = getRequestURL(event)
260
+
261
+ const isRPC = serverContext.rpcBases.some((base) => url.pathname.startsWith(base))
262
+ if (isRPC) {
263
+ return handleRPC(event)
264
+ }
265
+
266
+ if (url.pathname.includes(".")) {
267
+ return proxyWpAdmin(event)
268
+ }
269
+
270
+ return renderPage({ pathname: url.pathname })
271
+ }
272
+ })
273
+ `,
274
+ });
275
+ }
276
+ if (opts.serverless) {
277
+ codegen.registerFile({
278
+ name: "handler.wp-proxy.ts",
279
+ generate: code /* tsx */ `
280
+ /// <reference types="vinxi/types/server" />
281
+ import { proxyWpAdmin } from "eddev/server"
282
+ import { eventHandler } from "vinxi/http"
283
+ import "./context.js"
284
+
285
+ export default eventHandler(async (event) => {
286
+ return proxyWpAdmin(event)
287
+ })
288
+ `,
289
+ });
290
+ }
291
+ codegen.registerFile({
292
+ name: "manifest/blocks.ts",
293
+ generate: async () => {
294
+ const blockManifest = await project.blocks.get();
295
+ return code /* ts */ `
296
+ import { blockManifestReader } from 'eddev/_internal'
297
+ import { dynamic } from 'eddev/dynamic'
298
+ import core from '../../../blocks/_core'
299
+
300
+ const manifest = {
301
+ ${Object.entries(blockManifest.blocks)
302
+ .filter(([name]) => !name.match(/^_[a-z]+$/i))
303
+ .map(([name, block]) => {
304
+ const importStatement = `dynamic(() => import(${JSON.stringify("../../../" + block.fileName)}))`;
305
+ return JSON.stringify(block.acfName) + ": " + importStatement;
306
+ })
307
+ .join(",\n")},
308
+ ...core
309
+ }
310
+
311
+ const info = {
312
+ ${Object.entries(blockManifest.blocks)
313
+ .filter(([name]) => !name.match(/^_[a-z]+$/i))
314
+ .map(([name, block]) => {
315
+ return (JSON.stringify(block.acfName) +
316
+ ": " +
317
+ JSON.stringify({
318
+ slug: block.slug,
319
+ tags: block.tags,
320
+ flags: block.flags ?? {},
321
+ }));
322
+ })
323
+ .join(",\n")}
324
+ }
325
+
326
+ blockManifestReader.set(manifest, info)
327
+
328
+ export default manifest
329
+
330
+ if (import.meta.hot) {
331
+ import.meta.hot.accept()
332
+ }
333
+ `;
334
+ },
335
+ subscribe: project.blocks.subscribe,
336
+ });
337
+ codegen.registerFile({
338
+ name: "manifest/admin.ts",
339
+ generate: async () => {
340
+ const fieldManifest = await project.fields.get();
341
+ const widgetManifest = await project.widgets.get();
342
+ return code /* ts */ `
343
+ import { adminManifestReader } from 'eddev/_internal'
344
+ import editorConfig from '../../../blocks/_editor'
345
+
346
+ const fields = {${Object.entries(fieldManifest.fields)
347
+ .map(([name, field]) => {
348
+ const importStatement = `() => import(${JSON.stringify("../../../" + field.fileName)}).then(m => m.default)`;
349
+ return JSON.stringify(field.slug) + ": " + importStatement;
350
+ })
351
+ .join(",\n")}}
352
+ const widgets = {${Object.entries(widgetManifest.widgets)
353
+ .map(([name, widget]) => {
354
+ const importStatement = `() => import(${JSON.stringify("../../../" + widget.fileName)}).then(m => m.default)`;
355
+ return JSON.stringify(widget.slug) + ": " + importStatement;
356
+ })
357
+ .join(",\n")}}
358
+
359
+ const manifest = {
360
+ fields,
361
+ widgets,
362
+ editorConfig
363
+ }
364
+
365
+ adminManifestReader.set(manifest)
366
+
367
+ export default manifest
368
+
369
+ export { editorConfig }
370
+
371
+ if (import.meta.hot) {
372
+ import.meta.hot.accept()
373
+ }
374
+ `;
375
+ },
376
+ subscribe: (callback) => {
377
+ const unsub = [project.fields.subscribe(callback), project.widgets.subscribe(callback)];
378
+ return () => unsub.forEach((u) => u());
379
+ },
380
+ });
381
+ codegen.registerFile({
382
+ name: "manifest/views.ts",
383
+ generate: async () => {
384
+ const viewManifest = await project.views.get();
385
+ return code /* ts */ `
386
+ import { viewManifestReader } from 'eddev/_internal'
387
+ import { dynamic } from 'eddev/dynamic'
388
+ const manifest = {${Object.entries(viewManifest.views).map(([name, view]) => {
389
+ const src = "../../../" + view.fileName;
390
+ let importStatement;
391
+ if (name.startsWith("_")) {
392
+ importStatement = imp(name + "=" + src);
393
+ }
394
+ else {
395
+ importStatement = code `dynamic(() => import(${JSON.stringify(src)}))`;
396
+ }
397
+ return code `${JSON.stringify(view.slug)}: ${importStatement},\n`;
398
+ })}}
399
+
400
+ viewManifestReader.value = manifest
401
+
402
+ export default manifest
403
+
404
+ if (import.meta.hot) {
405
+ import.meta.hot.accept()
406
+ }
407
+ `;
408
+ },
409
+ subscribe: project.views.subscribe,
410
+ });
411
+ codegen.registerFile({
412
+ name: "manifest/styles.ts",
413
+ generate: async () => {
414
+ return code /* ts */ `
415
+ export const getCssText = undefined
416
+ export const editorGlobalStyles = () => {}
417
+ `;
418
+ },
419
+ });
420
+ codegen.registerFile({
421
+ name: "manifest/tailwind-config.ts",
422
+ generate: async () => {
423
+ return code /* ts */ `
424
+ import tw from "../../../tailwind.config.ts"
425
+ import resolveConfig from 'tailwindcss/resolveConfig'
426
+ import { devToolsStore } from 'eddev/devtools'
427
+
428
+ const value = resolveConfig(tw)
429
+ devToolsStore.tailwindConfig = value
430
+
431
+ if (import.meta.hot) {
432
+ import.meta.hot.accept()
433
+ }
434
+ `;
435
+ },
436
+ });
437
+ if (opts.serverless) {
438
+ codegen.registerFile({
439
+ name: "manifest/routes.ts",
440
+ generate: async () => {
441
+ const routeManifest = await project.serverRoutes.get();
442
+ return code /* ts */ `
443
+ import { instantiateRouter } from "eddev/server"
444
+ ${routeManifest.contextFileName
445
+ ? code /*ts*/ `
446
+ import createContext from "../../../${routeManifest.contextFileName}"
447
+ `
448
+ : code /*ts*/ `
449
+ const createContext = () => ({})
450
+ `}
451
+
452
+ const router = instantiateRouter({${Object.entries(routeManifest.routes).map(([name, route]) => {
453
+ const src = "../../../" + route.fileName;
454
+ const importStatement = imp(camelCase(name) + "=" + src);
455
+ return code `${JSON.stringify(route.prefix)}: ${importStatement},\n`;
456
+ })}})
457
+
458
+ export { createContext, router }
459
+ `;
460
+ },
461
+ subscribe: project.serverRoutes.subscribe,
462
+ });
463
+ codegen.registerFile({
464
+ name: "rpc.ts",
465
+ generate: code /* tsx */ `
466
+ /// <reference types="vinxi/types/server" />
467
+ import "./context.js"
468
+ import { fetchRequestHandler } from "@trpc/server/adapters/fetch"
469
+ import { parseURL, stringifyParsedURL } from "ufo"
470
+ import { EventHandlerRequest, getWebRequest, H3Event } from "vinxi/http"
471
+ import { createContext, router } from "./manifest/routes.ts"
472
+
473
+ export function handleRPC(event: H3Event<EventHandlerRequest>) {
474
+ // Update URLs with dots, which tRPC prefers
475
+ const originalReq = getWebRequest(event)
476
+ const parsed = parseURL(originalReq.url)
477
+ parsed.pathname = "/" + parsed.pathname.replace(/(^\\/|\\/$)/g, "").replace(/\\//, ".")
478
+ const req = new Request(stringifyParsedURL(parsed), originalReq)
479
+
480
+ // Handle any early results which are Responses
481
+ function processEarlyResult(value: any): Response | undefined {
482
+ if (value instanceof Response) {
483
+ return value
484
+ }
485
+ }
486
+
487
+ return new Promise(async (resolve) => {
488
+ let sent = false
489
+ const defaultResponse = await fetchRequestHandler({
490
+ endpoint: "/",
491
+ req: req,
492
+ router: router,
493
+ createContext,
494
+ onError: (err) => console.error(err),
495
+ batching: { enabled: false },
496
+ // If a Response object is returned by a route, it will be sent as the response
497
+ responseMeta(opts) {
498
+ const value = opts?.data?.[0]?.["result"]?.["data"]
499
+ const response = processEarlyResult(value)
500
+ if (response) {
501
+ sent = true
502
+ resolve(response)
503
+ }
504
+ return {}
505
+ },
506
+ })
507
+ if (sent) return
508
+ resolve(defaultResponse)
509
+ })
510
+ }
511
+ `,
512
+ });
513
+ }
514
+ return codegen;
515
+ }
@@ -1,7 +1,13 @@
1
1
  import { Project } from "../project/project.js";
2
- export declare const graphqlLog: import("../utils/statefulLog.js").StatefulLog<GraphQLGenerator>;
2
+ export declare const graphqlLog: import("../utils/stateful-log.js").StatefulLog<GraphQLGenerator>;
3
+ type GraphQLGeneratorOptions = {
4
+ watch?: boolean;
5
+ optimize?: boolean;
6
+ generate?: boolean;
7
+ };
3
8
  export declare class GraphQLGenerator {
4
9
  project: Project;
10
+ opts: GraphQLGeneratorOptions;
5
11
  private needsRegenerate;
6
12
  private needsReload;
7
13
  private regenerateReason;
@@ -9,22 +15,26 @@ export declare class GraphQLGenerator {
9
15
  private isGenerating;
10
16
  private schemaLoader;
11
17
  private fileLoader;
18
+ private optimizeWriter;
12
19
  private debouncer?;
13
20
  private retryTimer?;
14
- constructor(project: Project);
21
+ constructor(project: Project, opts: GraphQLGeneratorOptions);
15
22
  queueRegenerate(full: boolean, reason: string, info?: string | string[]): Promise<void>;
16
23
  start(): Promise<void>;
17
24
  private listen;
18
25
  scheduleRetry(): void;
19
26
  generate(): Promise<void>;
27
+ private getOptimizedQueries;
20
28
  /**
21
29
  * Validates a GraphQL manifest against a schema, ensuring there are no user errors.
22
30
  */
23
31
  private validateGraphQLFiles;
24
32
  private generateTS;
25
33
  generateUtilTypes(): Promise<unknown[]>;
34
+ generateAPITypes(): Promise<unknown[]>;
26
35
  /**
27
36
  * Saves the schema to a file, for use by the VSCode GraphQL extension
28
37
  */
29
38
  private writeSchemaFile;
30
39
  }
40
+ export {};