eddev 2.0.0-beta.6 → 2.0.0-beta.60

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 +51 -0
  124. package/dist/app/server/server-context.js +147 -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 +204 -0
  166. package/dist/node/compiler/vinxi-codegen.d.ts +12 -0
  167. package/dist/node/compiler/vinxi-codegen.js +547 -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,547 @@
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: () => {
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
+ };
34
+ return code /* tsx */ `
35
+ import { ServerContext } from "eddev/server"
36
+ import { getManifest } from "vinxi/manifest"
37
+
38
+ ServerContext.setRuntime({
39
+ getManifest
40
+ })
41
+
42
+ export const serverContext = new ServerContext({${Object.entries(args)
43
+ .map(([key, value]) => `${key}: ${JSON.stringify(value)}`)
44
+ .join(",\n")}
45
+ })
46
+ `.toString();
47
+ },
48
+ });
49
+ }
50
+ if (opts.serverless) {
51
+ codegen.registerFile({
52
+ name: "react-shim.js",
53
+ generate: code /* tsx */ `
54
+ import React from "react"
55
+ import ReactDOM from "react-dom/client"
56
+ Object.assign(React, window.React)
57
+ Object.assign(ReactDOM, window.ReactDOM)
58
+ `,
59
+ });
60
+ }
61
+ if (opts.serverless) {
62
+ // codegen.registerFile({
63
+ // name: "manifest/extra-routes.ts",
64
+ // generate: code/* tsx */ `
65
+ // import { createRouter, eventHandler, getRouterParam, getQuery, getWebRequest, getRequestHeaders } from "vinxi/http"
66
+ // import { serverContext } from "./context.js"
67
+ // export const routes = [
68
+ // {
69
+ // pattern: '/test1',
70
+ // handler: () => import('../../../test.ts')
71
+ // }
72
+ // ]
73
+ // export default eventHandler((event) => {
74
+ // routes
75
+ // })
76
+ // `,
77
+ // })
78
+ }
79
+ codegen.registerFile({
80
+ name: "entry.admin.tsx",
81
+ generate: () => {
82
+ return code /* tsx */ `
83
+ ${opts.serverless ? `import "./react-shim.js"` : ""}
84
+ ${opts.serverless ? `import "vinxi/client"` : ""}
85
+ import "../../views/index.css"
86
+ import "./manifest/admin"
87
+ import "./manifest/blocks"
88
+ import "./manifest/styles"
89
+ import bootAdmin from "eddev/_internal/boot-admin.js"
90
+
91
+ bootAdmin()
92
+ `;
93
+ },
94
+ });
95
+ codegen.registerFile({
96
+ name: "entry.client.tsx",
97
+ generate: () => {
98
+ if (opts.serverless) {
99
+ /**
100
+ * Client entry for SSR mode
101
+ */
102
+ return code /* tsx */ `
103
+ /// <reference types="vinxi/types/client" />
104
+ /**
105
+ * SSR-mode frontend entry.
106
+ * Hydrates the main app, including the html/head/body elements.
107
+ * Also ensures that the assets used during SSR are loaded.
108
+ */
109
+ import "vinxi/client"
110
+ import "../../views/index.css"
111
+ import "./manifest/blocks"
112
+ import "./manifest/views"
113
+
114
+ import * as React from "react"
115
+ import { Root, hydrateRoot } from "react-dom/client"
116
+ import { SSRClientRoot } from "eddev/_internal/ssr-root-client.js"
117
+ import { getManifest } from "vinxi/manifest"
118
+ import { createAssets } from "@vinxi/react"
119
+ import { devToolsStore } from 'eddev/devtools'
120
+
121
+ // Set up a dynamic entry which will load the configured tailwind manifest
122
+ devToolsStore.loadTailwindConfig = () => import('./manifest/tailwind-config.js')
123
+
124
+ // Create the asset renderer, which will ensure scripts/styles are mounted correctly
125
+ function getAssets() {
126
+ const Assets = createAssets(getManifest("client").handler, getManifest("client"))
127
+ return <React.Suspense><Assets /></React.Suspense>
128
+ }
129
+
130
+ window.$reactRoot =
131
+ window.$reactRoot ||
132
+ hydrateRoot(
133
+ document,
134
+ <SSRClientRoot assets={getAssets()} metaTags={window._PAGE_DATA.meta.head} />,
135
+ )
136
+
137
+ if (import.meta.hot) {
138
+ import.meta.hot.accept((mod) => {
139
+ if (mod) {
140
+ const Assets = createAssets(getManifest("client").handler, getManifest("client"))
141
+ const app = <SSRClientRoot assets={getAssets()} metaTags={window._PAGE_DATA.meta.head} />
142
+ window.$reactRoot?.render(app)
143
+ }
144
+ })
145
+ }
146
+
147
+ declare global {
148
+ interface Window {
149
+ $reactRoot?: Root
150
+ _PAGE_DATA: any
151
+ }
152
+ }
153
+
154
+ `;
155
+ }
156
+ else {
157
+ return code /* tsx */ `
158
+ /**
159
+ * SPA-mode frontend entry.
160
+ * Renders the main app into the empty <div id='root'> element, and expects window._PAGE_DATA to be set.
161
+ */
162
+ import "./manifest/blocks"
163
+ import "./manifest/views"
164
+ import "../../views/index.css"
165
+ import { devToolsStore } from 'eddev/devtools'
166
+ import { createRoot } from "react-dom/client"
167
+ import { SPARoot } from "eddev/_internal/spa-root.js"
168
+ import * as React from "react"
169
+
170
+ devToolsStore.loadTailwindConfig = () => import('./manifest/tailwind-config')
171
+
172
+ createRoot(document.getElementById("root")!).render(<SPARoot />)
173
+ `;
174
+ }
175
+ },
176
+ });
177
+ if (opts.serverless) {
178
+ codegen.registerFile({
179
+ name: "handler.data-api.ts",
180
+ generate: code /* tsx */ `
181
+ /// <reference types="vinxi/types/server" />
182
+ import { createRouter, eventHandler, getRouterParam, getQuery, getWebRequest, getRequestHeaders } from "vinxi/http"
183
+ import { serverContext } from "./context.js"
184
+
185
+ const router = createRouter()
186
+ .get(
187
+ "/route/",
188
+ eventHandler(async (event) => {
189
+ const id = "/"
190
+
191
+ return await serverContext.fetchRouteData({
192
+ pathname: id,
193
+ withAppData: false,
194
+ })
195
+ }),
196
+ )
197
+ .get(
198
+ "/route/**:name",
199
+ eventHandler(async (event) => {
200
+ const id = "/" + getRouterParam(event, "name")
201
+
202
+ return await serverContext.fetchRouteData({
203
+ pathname: id,
204
+ withAppData: false,
205
+ })
206
+ }),
207
+ )
208
+ .get(
209
+ "/query/**:name",
210
+ eventHandler(async (event) => {
211
+ const id = "/" + getRouterParam(event, "name")
212
+ const paramString = getQuery(event).params
213
+
214
+ const params = typeof paramString === "string" && paramString.length ? JSON.parse(paramString) : {}
215
+
216
+ return await serverContext.fetchNamedQuery({
217
+ name: id,
218
+ params: params,
219
+ headers: getRequestHeaders(event),
220
+ })
221
+ }),
222
+ )
223
+ .post(
224
+ "/mutation/**:name",
225
+ eventHandler(async (event) => {
226
+ const id = "/" + getRouterParam(event, "name")
227
+ const body = await getWebRequest(event).json()
228
+ return await serverContext.fetchMutation({
229
+ name: id,
230
+ body,
231
+ headers: getRequestHeaders(event),
232
+ })
233
+ }),
234
+ )
235
+
236
+ export default router.handler
237
+
238
+ `,
239
+ });
240
+ }
241
+ if (opts.serverless) {
242
+ codegen.registerFile({
243
+ name: "handler.ssr-page.ts",
244
+ generate: code /* tsx */ `
245
+ /// <reference types="vinxi/types/server" />
246
+ import "../../views/index.css"
247
+ import "./manifest/blocks.js"
248
+ import "./manifest/styles.js"
249
+ import "./manifest/views.js"
250
+ import "./context.js"
251
+
252
+ import { proxyWpAdmin, ServerContext, renderPage } from "eddev/server"
253
+ import { eventHandler, getRequestURL } from "vinxi/http"
254
+ import { RouteData } from "eddev/routing"
255
+
256
+ export default eventHandler({
257
+ handler: async (event) => {
258
+ const serverContext = ServerContext.main
259
+ const url = getRequestURL(event)
260
+
261
+ if (url.pathname.includes(".")) {
262
+ return proxyWpAdmin(event)
263
+ }
264
+
265
+ return renderPage({ pathname: url.pathname })
266
+
267
+ // try {
268
+ // const [{appData, trackers}, response] = await Promise.all([
269
+ // serverContext.fetchAppData(),
270
+ // serverContext.fetchRouteData({
271
+ // pathname: url.pathname,
272
+ // withAppData: false,
273
+ // headers: {},
274
+ // query: {},
275
+ // }),
276
+ // ])
277
+
278
+ // let data: RouteData
279
+ // try {
280
+ // data = await response.json()
281
+ // data.appData = appData
282
+ // data.trackers = trackers
283
+ // } catch (err) {
284
+ // data = {
285
+ // view: "_error",
286
+ // viewType: "react",
287
+ // viewData: {},
288
+ // appData: appData,
289
+ // }
290
+ // console.error(err)
291
+ // setResponseStatus(event, 500)
292
+ // }
293
+ // setResponseHeader(event, "Content-Type", "text/html; charset=utf-8")
294
+ // return renderPageToSSRStream(url.pathname, data)
295
+ // } catch (err) {
296
+ // console.error(err)
297
+ // setResponseStatus(event, 500)
298
+ // setResponseHeader(event, "Content-Type", "text/html; charset=utf-8")
299
+ // return '<!DOCTYPE html><html><head><title>500 Internal Server Error</title></head><body><h1>500 Internal Server Error</h1><p>"'+err.message+'"</p></body></html>'
300
+ // }
301
+ }
302
+ })
303
+ `,
304
+ });
305
+ }
306
+ if (opts.serverless) {
307
+ codegen.registerFile({
308
+ name: "handler.wp-proxy.ts",
309
+ generate: code /* tsx */ `
310
+ /// <reference types="vinxi/types/server" />
311
+ import { proxyWpAdmin } from "eddev/server"
312
+ import { eventHandler } from "vinxi/http"
313
+ import "./context.js"
314
+
315
+ export default eventHandler(async (event) => {
316
+ return proxyWpAdmin(event)
317
+ })
318
+ `,
319
+ });
320
+ }
321
+ codegen.registerFile({
322
+ name: "manifest/blocks.ts",
323
+ generate: async () => {
324
+ const blockManifest = await project.blocks.get();
325
+ return code /* ts */ `
326
+ import { blockManifestReader } from 'eddev/_internal'
327
+ import { dynamic } from 'eddev/dynamic'
328
+ import core from '../../../blocks/_core'
329
+
330
+ const manifest = {
331
+ ${Object.entries(blockManifest.blocks)
332
+ .filter(([name]) => !name.match(/^_[a-z]+$/i))
333
+ .map(([name, block]) => {
334
+ const importStatement = `dynamic(() => import(${JSON.stringify("../../../" + block.fileName)}))`;
335
+ return JSON.stringify(block.acfName) + ": " + importStatement;
336
+ })
337
+ .join(",\n")},
338
+ ...core
339
+ }
340
+
341
+ const info = {
342
+ ${Object.entries(blockManifest.blocks)
343
+ .filter(([name]) => !name.match(/^_[a-z]+$/i))
344
+ .map(([name, block]) => {
345
+ return (JSON.stringify(block.acfName) +
346
+ ": " +
347
+ JSON.stringify({
348
+ slug: block.slug,
349
+ tags: block.tags,
350
+ flags: block.flags ?? {},
351
+ }));
352
+ })
353
+ .join(",\n")}
354
+ }
355
+
356
+ blockManifestReader.set(manifest, info)
357
+
358
+ export default manifest
359
+
360
+ if (import.meta.hot) {
361
+ import.meta.hot.accept()
362
+ }
363
+ `;
364
+ },
365
+ subscribe: project.blocks.subscribe,
366
+ });
367
+ codegen.registerFile({
368
+ name: "manifest/admin.ts",
369
+ generate: async () => {
370
+ const fieldManifest = await project.fields.get();
371
+ const widgetManifest = await project.widgets.get();
372
+ return code /* ts */ `
373
+ import { adminManifestReader } from 'eddev/_internal'
374
+ import editorConfig from '../../../blocks/_editor'
375
+
376
+ const fields = {${Object.entries(fieldManifest.fields)
377
+ .map(([name, field]) => {
378
+ const importStatement = `() => import(${JSON.stringify("../../../" + field.fileName)}).then(m => m.default)`;
379
+ return JSON.stringify(field.slug) + ": " + importStatement;
380
+ })
381
+ .join(",\n")}}
382
+ const widgets = {${Object.entries(widgetManifest.widgets)
383
+ .map(([name, widget]) => {
384
+ const importStatement = `() => import(${JSON.stringify("../../../" + widget.fileName)}).then(m => m.default)`;
385
+ return JSON.stringify(widget.slug) + ": " + importStatement;
386
+ })
387
+ .join(",\n")}}
388
+
389
+ const manifest = {
390
+ fields,
391
+ widgets,
392
+ editorConfig
393
+ }
394
+
395
+ adminManifestReader.set(manifest)
396
+
397
+ export default manifest
398
+
399
+ export { editorConfig }
400
+
401
+ if (import.meta.hot) {
402
+ import.meta.hot.accept()
403
+ }
404
+ `;
405
+ },
406
+ subscribe: (callback) => {
407
+ const unsub = [project.fields.subscribe(callback), project.widgets.subscribe(callback)];
408
+ return () => unsub.forEach((u) => u());
409
+ },
410
+ });
411
+ codegen.registerFile({
412
+ name: "manifest/views.ts",
413
+ generate: async () => {
414
+ const viewManifest = await project.views.get();
415
+ return code /* ts */ `
416
+ import { viewManifestReader } from 'eddev/_internal'
417
+ import { dynamic } from 'eddev/dynamic'
418
+ const manifest = {${Object.entries(viewManifest.views).map(([name, view]) => {
419
+ const src = "../../../" + view.fileName;
420
+ let importStatement;
421
+ if (name.startsWith("_")) {
422
+ importStatement = imp(name + "=" + src);
423
+ }
424
+ else {
425
+ importStatement = code `dynamic(() => import(${JSON.stringify(src)}))`;
426
+ }
427
+ return code `${JSON.stringify(view.slug)}: ${importStatement},\n`;
428
+ })}}
429
+
430
+ viewManifestReader.value = manifest
431
+
432
+ export default manifest
433
+
434
+ if (import.meta.hot) {
435
+ import.meta.hot.accept()
436
+ }
437
+ `;
438
+ },
439
+ subscribe: project.views.subscribe,
440
+ });
441
+ codegen.registerFile({
442
+ name: "manifest/styles.ts",
443
+ generate: async () => {
444
+ return code /* ts */ `
445
+ export const getCssText = undefined
446
+ export const editorGlobalStyles = () => {}
447
+ `;
448
+ },
449
+ });
450
+ codegen.registerFile({
451
+ name: "manifest/tailwind-config.ts",
452
+ generate: async () => {
453
+ return code /* ts */ `
454
+ import tw from "../../../tailwind.config.ts"
455
+ import resolveConfig from 'tailwindcss/resolveConfig'
456
+ import { devToolsStore } from 'eddev/devtools'
457
+
458
+ const value = resolveConfig(tw)
459
+ devToolsStore.tailwindConfig = value
460
+
461
+ if (import.meta.hot) {
462
+ import.meta.hot.accept()
463
+ }
464
+ `;
465
+ },
466
+ });
467
+ if (opts.serverless) {
468
+ codegen.registerFile({
469
+ name: "manifest/routes.ts",
470
+ generate: async () => {
471
+ const routeManifest = await project.serverRoutes.get();
472
+ return code /* ts */ `
473
+ import { instantiateRouter } from "eddev/server"
474
+ ${routeManifest.contextFileName
475
+ ? code /*ts*/ `
476
+ import createContext from "../../../${routeManifest.contextFileName}"
477
+ `
478
+ : code /*ts*/ `
479
+ const createContext = () => ({})
480
+ `}
481
+
482
+ const router = instantiateRouter({${Object.entries(routeManifest.routes).map(([name, route]) => {
483
+ const src = "../../../" + route.fileName;
484
+ const importStatement = imp(camelCase(name) + "=" + src);
485
+ return code `${JSON.stringify(route.prefix)}: ${importStatement},\n`;
486
+ })}})
487
+
488
+ export { createContext, router }
489
+ `;
490
+ },
491
+ subscribe: project.serverRoutes.subscribe,
492
+ });
493
+ codegen.registerFile({
494
+ name: "handler.trpc-api.ts",
495
+ generate: code /* tsx */ `
496
+ /// <reference types="vinxi/types/server" />
497
+ import "./context.js"
498
+ import { fetchRequestHandler } from "@trpc/server/adapters/fetch"
499
+ import { eventHandler, getWebRequest } from "vinxi/http"
500
+ import { createContext, router } from "./manifest/routes.ts"
501
+ import { parseURL, stringifyParsedURL } from "ufo"
502
+
503
+ export default eventHandler({
504
+ handler: async (event) => {
505
+ // Update URLs with dots, which tRPC prefers
506
+ const originalReq = getWebRequest(event)
507
+ const parsed = parseURL(originalReq.url)
508
+ parsed.pathname = "/" + parsed.pathname.replace(/(^\\/|\\/$)/g, "").replace(/\\//, ".")
509
+ const req = new Request(stringifyParsedURL(parsed), originalReq)
510
+
511
+ // Handle any early results which are Responses
512
+ function processEarlyResult(value: any): Response | undefined {
513
+ if (value instanceof Response) {
514
+ return value
515
+ }
516
+ }
517
+
518
+ return new Promise(async (resolve) => {
519
+ let sent = false
520
+ const defaultResponse = await fetchRequestHandler({
521
+ endpoint: "/",
522
+ req: req,
523
+ router: router,
524
+ createContext,
525
+ onError: (err) => console.error(err),
526
+ batching: { enabled: false },
527
+ // If a Response object is returned by a route, it will be sent as the response
528
+ responseMeta(opts) {
529
+ const value = opts?.data?.[0]?.["result"]?.["data"]
530
+ const response = processEarlyResult(value)
531
+ if (response) {
532
+ sent = true
533
+ resolve(response)
534
+ }
535
+ return {}
536
+ },
537
+ })
538
+ if (sent) return
539
+ resolve(defaultResponse)
540
+ })
541
+ },
542
+ })
543
+ `,
544
+ });
545
+ }
546
+ return codegen;
547
+ }
@@ -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 {};