eddev 2.0.0-beta.9 → 2.0.0-beta.91
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.
- package/dist/app/entry/HydrationOverlay.d.ts +1 -0
- package/dist/app/entry/HydrationOverlay.js +2 -0
- package/dist/app/entry/MetaTags.d.ts +7 -0
- package/dist/app/entry/MetaTags.js +17 -0
- package/dist/app/entry/boot-admin.js +11 -6
- package/dist/app/entry/hydration-script.d.ts +1 -0
- package/dist/app/entry/hydration-script.js +18 -0
- package/dist/app/entry/spa-root.js +4 -5
- package/dist/app/entry/ssr-root-client.d.ts +3 -1
- package/dist/app/entry/ssr-root-client.js +24 -8
- package/dist/app/entry/ssr-root.d.ts +5 -4
- package/dist/app/entry/ssr-root.js +21 -20
- package/dist/app/lib/admin/index.d.ts +2 -2
- package/dist/app/lib/admin/index.js +2 -2
- package/dist/app/lib/admin/installFieldTypes.js +1 -1
- package/dist/app/lib/admin/runWidgets.js +1 -1
- package/dist/app/lib/blocks/ContentBlocks.d.ts +1 -1
- package/dist/app/lib/blocks/ContentBlocks.js +5 -5
- package/dist/app/lib/blocks/EditableText.d.ts +1 -1
- package/dist/app/lib/blocks/EditableText.js +3 -3
- package/dist/app/lib/blocks/InnerBlocks.d.ts +13 -3
- package/dist/app/lib/blocks/InnerBlocks.js +13 -5
- package/dist/app/lib/blocks/block-utils.d.ts +2 -2
- package/dist/app/lib/blocks/block-utils.js +2 -2
- package/dist/app/lib/blocks/editor/EditorHighlights.d.ts +7 -0
- package/dist/app/lib/blocks/editor/EditorHighlights.js +130 -0
- package/dist/app/lib/blocks/editor/EditorSupport.js +4 -5
- package/dist/app/lib/blocks/editor/ErrorBoundaryEditor.d.ts +1 -1
- package/dist/app/lib/blocks/editor/editor-config.d.ts +17 -4
- package/dist/app/lib/blocks/editor/editor-config.js +21 -9
- package/dist/app/lib/blocks/editor/installGutenbergHooks.js +20 -14
- package/dist/app/lib/blocks/editor/root-blocks.d.ts +6 -0
- package/dist/app/lib/blocks/editor/root-blocks.js +30 -0
- package/dist/app/lib/blocks/editor/usePostEditor.d.ts +1 -1
- package/dist/app/lib/blocks/index.d.ts +9 -9
- package/dist/app/lib/blocks/index.js +9 -9
- package/dist/app/lib/blocks/inline-editing.d.ts +1 -1
- package/dist/app/lib/blocks/inline-editing.js +7 -5
- package/dist/app/lib/devtools/components/BreakpointIndicator.js +1 -1
- package/dist/app/lib/devtools/components/DevUI.js +4 -3
- package/dist/app/lib/devtools/components/GridIndicator.d.ts +1 -0
- package/dist/app/lib/devtools/components/GridIndicator.js +29 -0
- package/dist/app/lib/devtools/hooks/usePersistState.d.ts +1 -1
- package/dist/app/lib/devtools/hooks/usePersistState.js +11 -2
- package/dist/app/lib/devtools/hooks/useTailwind.d.ts +1014 -1014
- package/dist/app/lib/devtools/hooks/useTailwind.js +1 -1
- package/dist/app/lib/devtools/index.d.ts +1 -1
- package/dist/app/lib/devtools/index.js +1 -1
- package/dist/app/lib/devtools/loader.js +8 -7
- package/dist/app/lib/devtools/useQueryDebug.d.ts +7 -1
- package/dist/app/lib/devtools/useQueryDebug.js +5 -8
- package/dist/app/lib/dynamic/dynamic.d.ts +1 -1
- package/dist/app/lib/dynamic/dynamic.js +5 -1
- package/dist/app/lib/dynamic/index.d.ts +1 -1
- package/dist/app/lib/dynamic/index.js +1 -1
- package/dist/app/lib/hooks/index.d.ts +4 -5
- package/dist/app/lib/hooks/index.js +4 -5
- package/dist/app/lib/hooks/queryUtils.d.ts +37 -3
- package/dist/app/lib/hooks/queryUtils.js +66 -26
- package/dist/app/lib/hooks/useAppData.js +1 -1
- package/dist/app/lib/hooks/useRPC.d.ts +0 -4
- package/dist/app/lib/hooks/useRPC.js +1 -8
- package/dist/app/lib/internal/finalize-rpc.d.ts +17 -0
- package/dist/app/lib/internal/finalize-rpc.js +3 -0
- package/dist/app/lib/internal/index.d.ts +5 -4
- package/dist/app/lib/internal/index.js +5 -4
- package/dist/app/lib/internal/read-admin-manifest.d.ts +1 -1
- package/dist/app/lib/legacy-stitches/createStitches.d.ts +21 -21
- package/dist/app/lib/legacy-stitches/createStitches.js +1 -1
- package/dist/app/lib/legacy-stitches/index.d.ts +1 -1
- package/dist/app/lib/legacy-stitches/index.js +1 -1
- package/dist/app/lib/routing/components/BackButton.d.ts +49 -0
- package/dist/app/lib/routing/components/BackButton.js +47 -0
- package/dist/app/lib/routing/components/BrowserRouter.d.ts +4 -1
- package/dist/app/lib/routing/components/BrowserRouter.js +95 -19
- package/dist/app/lib/routing/components/ClientOnly.d.ts +1 -1
- package/dist/app/lib/routing/components/ClientOnly.js +1 -1
- package/dist/app/lib/routing/components/Link.d.ts +1 -0
- package/dist/app/lib/routing/components/Link.js +11 -12
- package/dist/app/lib/routing/components/RouteRenderer.d.ts +1 -1
- package/dist/app/lib/routing/components/RouteRenderer.js +7 -6
- package/dist/app/lib/routing/components/SSRRouter.d.ts +2 -2
- package/dist/app/lib/routing/components/SSRRouter.js +5 -6
- package/dist/app/lib/routing/components/ScrollRestoration.js +5 -2
- package/dist/app/lib/routing/context.d.ts +8 -5
- package/dist/app/lib/routing/context.js +13 -96
- package/dist/app/lib/routing/hooks/useRestorableState.d.ts +2 -1
- package/dist/app/lib/routing/hooks/useRestorableState.js +2 -1
- package/dist/app/lib/routing/hooks/useRoute.d.ts +16 -1
- package/dist/app/lib/routing/hooks/useRoute.js +22 -1
- package/dist/app/lib/routing/hooks/useRouteMeta.d.ts +5 -0
- package/dist/app/lib/routing/hooks/useRouteMeta.js +9 -0
- package/dist/app/lib/routing/hooks/useRouteTransition.d.ts +1 -1
- package/dist/app/lib/routing/hooks/useRouteTransition.js +1 -1
- package/dist/app/lib/routing/hooks/useRouter.d.ts +1 -1
- package/dist/app/lib/routing/hooks/useRouter.js +1 -1
- package/dist/app/lib/routing/hooks/useRouterEvents.d.ts +1 -1
- package/dist/app/lib/routing/hooks/useRouterEvents.js +1 -1
- package/dist/app/lib/routing/hooks/useRouterState.d.ts +1 -1
- package/dist/app/lib/routing/hooks/useRouterState.js +1 -1
- package/dist/app/lib/routing/hooks/useSearchParams.js +2 -2
- package/dist/app/lib/routing/index.d.ts +14 -13
- package/dist/app/lib/routing/index.js +14 -13
- package/dist/app/lib/routing/loader.d.ts +2 -2
- package/dist/app/lib/routing/loader.js +20 -11
- package/dist/app/lib/routing/types.d.ts +36 -10
- package/dist/app/lib/routing/utils.d.ts +5 -2
- package/dist/app/lib/routing/utils.js +37 -4
- package/dist/app/lib/{hooks → runtime}/apiConfig.d.ts +6 -2
- package/dist/app/lib/runtime/apiConfig.js +6 -0
- package/dist/app/lib/runtime/errorHandling.d.ts +39 -0
- package/dist/app/lib/runtime/errorHandling.js +6 -0
- package/dist/app/lib/runtime/index.d.ts +2 -0
- package/dist/app/lib/runtime/index.js +2 -0
- package/dist/app/lib/views/index.d.ts +1 -1
- package/dist/app/lib/views/index.js +1 -1
- package/dist/app/server/defineRouter.d.ts +2 -0
- package/dist/app/server/defineRouter.js +4 -0
- package/dist/app/server/index.d.ts +5 -3
- package/dist/app/server/index.js +5 -3
- package/dist/app/server/proxy-wp-admin.d.ts +1 -2
- package/dist/app/server/proxy-wp-admin.js +32 -14
- package/dist/app/server/render-ssr-page.d.ts +21 -2
- package/dist/app/server/render-ssr-page.js +143 -11
- package/dist/app/server/rpc.d.ts +56 -0
- package/dist/app/server/rpc.js +18 -0
- package/dist/app/server/server-context.d.ts +42 -4
- package/dist/app/server/server-context.js +196 -30
- package/dist/app/server/utils/replace-host.d.ts +1 -1
- package/dist/app/server/utils/replace-host.js +10 -2
- package/dist/app/server/utils/swr-cache.d.ts +4 -0
- package/dist/app/server/utils/swr-cache.js +31 -0
- package/dist/app/utils/APIProvider.d.ts +2 -0
- package/dist/app/utils/APIProvider.js +5 -0
- package/dist/app/utils/BlockErrorBoundary.d.ts +19 -0
- package/dist/app/utils/BlockErrorBoundary.js +38 -0
- package/dist/app/utils/ErrorMessage.d.ts +5 -0
- package/dist/app/utils/ErrorMessage.js +14 -0
- package/dist/app/utils/RouteErrorBoundary.d.ts +18 -0
- package/dist/app/utils/RouteErrorBoundary.js +38 -0
- package/dist/app/utils/asset-capture.d.ts +2 -0
- package/dist/app/utils/asset-capture.js +5 -0
- package/dist/app/utils/hydration-debugger.d.ts +13 -0
- package/dist/app/utils/hydration-debugger.js +11 -0
- package/dist/app/utils/query-client.d.ts +2 -0
- package/dist/app/utils/query-client.js +5 -1
- package/dist/app/utils/trpc-client.d.ts +2 -0
- package/dist/app/utils/trpc-client.js +39 -0
- package/dist/node/cli/cli-worker.js +10 -5
- package/dist/node/cli/cli.js +79 -11
- package/dist/node/cli/display/CLIApp.js +3 -6
- package/dist/node/cli/display/boot-cli-app.js +1 -1
- package/dist/node/cli/display/tools/CreateBlock.d.ts +1 -1
- package/dist/node/cli/display/tools/cli-tools.d.ts +1 -11
- package/dist/node/cli/display/tools/cli-tools.js +9 -9
- package/dist/node/cli/version.d.ts +1 -1
- package/dist/node/cli/version.js +1 -1
- package/dist/node/compiler/build-vinxi.js +3 -1
- package/dist/node/compiler/bundler.admin.d.ts +1 -1
- package/dist/node/compiler/bundler.admin.js +1 -1
- package/dist/node/compiler/bundler.frontend.js +1 -1
- package/dist/node/compiler/dev-server.js +10 -0
- package/dist/node/compiler/get-vite-config.d.ts +1 -0
- package/dist/node/compiler/get-vite-config.js +34 -11
- package/dist/node/compiler/vinxi-app.d.ts +12 -0
- package/dist/node/compiler/vinxi-app.js +139 -32
- package/dist/node/compiler/vinxi-codegen.js +321 -108
- package/dist/node/graphql/graphql-codegen.d.ts +11 -1
- package/dist/node/graphql/graphql-codegen.js +210 -33
- package/dist/node/graphql/graphql-schema-loader.d.ts +2 -1
- package/dist/node/graphql/graphql-schema-loader.js +5 -16
- package/dist/node/graphql/plugins/gql-plugin-queries.js +1 -1
- package/dist/node/graphql/query-files-loader.d.ts +3 -0
- package/dist/node/graphql/query-files-loader.js +5 -0
- package/dist/node/project/config.d.ts +159 -73
- package/dist/node/project/config.js +69 -20
- package/dist/node/project/env.d.ts +4 -0
- package/dist/node/project/env.js +1 -0
- package/dist/node/project/manifest/block-manifest.js +1 -0
- package/dist/node/project/manifest/manifest.d.ts +1 -0
- package/dist/node/project/manifest/manifest.js +14 -10
- package/dist/node/project/manifest/routes-manifest.d.ts +20 -0
- package/dist/node/project/manifest/routes-manifest.js +74 -0
- package/dist/node/project/manifest/view-manifest.js +1 -1
- package/dist/node/project/project.d.ts +9 -1
- package/dist/node/project/project.js +37 -6
- package/dist/node/project/wp-info.d.ts +1 -0
- package/dist/node/project/wp-info.js +13 -1
- package/dist/node/types/block-type.d.ts +25 -20
- package/dist/node/types/block-type.js +1 -0
- package/dist/node/types/view-type.d.ts +7 -7
- package/dist/node/utils/fetch-wp.d.ts +1 -0
- package/dist/node/utils/fetch-wp.js +27 -0
- package/dist/node/utils/fs-codegen.d.ts +2 -0
- package/dist/node/utils/fs-codegen.js +2 -1
- package/dist/node/utils/is-deploying.js +1 -1
- package/dist/node/utils/stateful-log.js +2 -0
- package/dist/node/utils/watch-file-tree.d.ts +17 -3
- package/dist/node/utils/watch-file-tree.js +12 -5
- package/package.json +17 -13
- package/types.app.d.ts +4 -2
- package/types.app.internal.d.ts +2 -2
- package/types.node.d.ts +3 -3
- package/dist/app/lib/blocks/ErrorBoundaryFrontend.d.ts +0 -15
- package/dist/app/lib/blocks/ErrorBoundaryFrontend.js +0 -35
- package/dist/app/lib/hooks/apiConfig.js +0 -4
- package/dist/app/lib/hooks/usePageLoad.d.ts +0 -6
- package/dist/app/lib/hooks/usePageLoad.js +0 -5
- package/dist/app/server/utils/index.html.d.ts +0 -2
- package/dist/app/server/utils/index.html.js +0 -14
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { code } from "ts-poet";
|
|
1
|
+
import { code, imp } from "ts-poet";
|
|
2
2
|
import { FSCodegen } from "../utils/fs-codegen.js";
|
|
3
|
+
import { camelCase } from "change-case-all";
|
|
3
4
|
export function getVinxiFolder(opts) {
|
|
4
5
|
return (opts.mode === "development" ? "dev" : "prod") + (opts.serverless ? "" : "-spa");
|
|
5
6
|
}
|
|
@@ -17,22 +18,35 @@ export function createVinxiCodegen(opts) {
|
|
|
17
18
|
if (opts.serverless) {
|
|
18
19
|
codegen.registerFile({
|
|
19
20
|
name: "context.ts",
|
|
20
|
-
generate:
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
],
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
21
|
+
generate: async () => {
|
|
22
|
+
const args = {
|
|
23
|
+
dev: opts.mode === "development",
|
|
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
|
+
config: project.config,
|
|
35
|
+
};
|
|
36
|
+
return code /* tsx */ `
|
|
37
|
+
import { ServerContext } from "eddev/server"
|
|
38
|
+
import { getManifest } from "vinxi/manifest"
|
|
39
|
+
|
|
40
|
+
ServerContext.setRuntime({
|
|
41
|
+
getManifest
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
export const serverContext = new ServerContext({${Object.entries(args)
|
|
45
|
+
.map(([key, value]) => `${key}: ${JSON.stringify(value)}`)
|
|
46
|
+
.join(",\n")}
|
|
47
|
+
})
|
|
48
|
+
`.toString();
|
|
49
|
+
},
|
|
36
50
|
});
|
|
37
51
|
}
|
|
38
52
|
if (opts.serverless) {
|
|
@@ -46,6 +60,24 @@ export function createVinxiCodegen(opts) {
|
|
|
46
60
|
`,
|
|
47
61
|
});
|
|
48
62
|
}
|
|
63
|
+
if (opts.serverless) {
|
|
64
|
+
// codegen.registerFile({
|
|
65
|
+
// name: "manifest/extra-routes.ts",
|
|
66
|
+
// generate: code/* tsx */ `
|
|
67
|
+
// import { createRouter, eventHandler, getRouterParam, getQuery, getWebRequest, getRequestHeaders } from "vinxi/http"
|
|
68
|
+
// import { serverContext } from "./context.js"
|
|
69
|
+
// export const routes = [
|
|
70
|
+
// {
|
|
71
|
+
// pattern: '/test1',
|
|
72
|
+
// handler: () => import('../../../test.ts')
|
|
73
|
+
// }
|
|
74
|
+
// ]
|
|
75
|
+
// export default eventHandler((event) => {
|
|
76
|
+
// routes
|
|
77
|
+
// })
|
|
78
|
+
// `,
|
|
79
|
+
// })
|
|
80
|
+
}
|
|
49
81
|
codegen.registerFile({
|
|
50
82
|
name: "entry.admin.tsx",
|
|
51
83
|
generate: () => {
|
|
@@ -89,7 +121,7 @@ export function createVinxiCodegen(opts) {
|
|
|
89
121
|
import { devToolsStore } from 'eddev/devtools'
|
|
90
122
|
|
|
91
123
|
// Set up a dynamic entry which will load the configured tailwind manifest
|
|
92
|
-
devToolsStore.loadTailwindConfig = () => import('./manifest/tailwind-config')
|
|
124
|
+
devToolsStore.loadTailwindConfig = () => import('./manifest/tailwind-config.js')
|
|
93
125
|
|
|
94
126
|
// Create the asset renderer, which will ensure scripts/styles are mounted correctly
|
|
95
127
|
function getAssets() {
|
|
@@ -100,15 +132,14 @@ export function createVinxiCodegen(opts) {
|
|
|
100
132
|
window.$reactRoot =
|
|
101
133
|
window.$reactRoot ||
|
|
102
134
|
hydrateRoot(
|
|
103
|
-
document
|
|
104
|
-
<SSRClientRoot assets={getAssets()} />,
|
|
135
|
+
document.getElementById('_root')!,
|
|
136
|
+
<SSRClientRoot assets={getAssets()} metaTags={window._PAGE_DATA.meta.head} />,
|
|
105
137
|
)
|
|
106
138
|
|
|
107
139
|
if (import.meta.hot) {
|
|
108
140
|
import.meta.hot.accept((mod) => {
|
|
109
141
|
if (mod) {
|
|
110
|
-
const
|
|
111
|
-
const app = <SSRClientRoot assets={getAssets()} />
|
|
142
|
+
const app = <SSRClientRoot assets={getAssets()} metaTags={window._PAGE_DATA.meta.head} />
|
|
112
143
|
window.$reactRoot?.render(app)
|
|
113
144
|
}
|
|
114
145
|
})
|
|
@@ -117,6 +148,7 @@ export function createVinxiCodegen(opts) {
|
|
|
117
148
|
declare global {
|
|
118
149
|
interface Window {
|
|
119
150
|
$reactRoot?: Root
|
|
151
|
+
_PAGE_DATA: any
|
|
120
152
|
}
|
|
121
153
|
}
|
|
122
154
|
|
|
@@ -145,123 +177,211 @@ export function createVinxiCodegen(opts) {
|
|
|
145
177
|
});
|
|
146
178
|
if (opts.serverless) {
|
|
147
179
|
codegen.registerFile({
|
|
148
|
-
name: "handler.
|
|
180
|
+
name: "handler.bypass.ts",
|
|
149
181
|
generate: code /* tsx */ `
|
|
150
182
|
/// <reference types="vinxi/types/server" />
|
|
151
|
-
import { createRouter, eventHandler,
|
|
152
|
-
|
|
183
|
+
import { createRouter, eventHandler, getCookie, setCookie } from "vinxi/http"
|
|
184
|
+
|
|
185
|
+
const BYPASS_TOKEN = process.env.VERCEL_BYPASS_TOKEN
|
|
186
|
+
const COOKIE_NAME = "__prerender_bypass"
|
|
153
187
|
|
|
154
188
|
const router = createRouter()
|
|
155
189
|
.get(
|
|
156
|
-
"/
|
|
190
|
+
"/enable",
|
|
157
191
|
eventHandler(async (event) => {
|
|
158
|
-
|
|
192
|
+
if (!BYPASS_TOKEN) return false
|
|
159
193
|
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
withAppData: false,
|
|
194
|
+
setCookie(event, COOKIE_NAME, BYPASS_TOKEN, {
|
|
195
|
+
expires: new Date(Date.now() + 1000 * 60 * 60 * 24),
|
|
163
196
|
})
|
|
197
|
+
|
|
198
|
+
return true
|
|
199
|
+
}),
|
|
200
|
+
)
|
|
201
|
+
.get(
|
|
202
|
+
"/disable",
|
|
203
|
+
eventHandler(async (event) => {
|
|
204
|
+
setCookie(event, COOKIE_NAME, "")
|
|
205
|
+
|
|
206
|
+
return true
|
|
207
|
+
}),
|
|
208
|
+
)
|
|
209
|
+
.get(
|
|
210
|
+
"/check",
|
|
211
|
+
eventHandler(async (event) => {
|
|
212
|
+
const cookie = getCookie(event, COOKIE_NAME)
|
|
213
|
+
|
|
214
|
+
if (cookie === BYPASS_TOKEN) {
|
|
215
|
+
return true
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
return false
|
|
219
|
+
}),
|
|
220
|
+
)
|
|
221
|
+
export default router.handler
|
|
222
|
+
`,
|
|
223
|
+
});
|
|
224
|
+
// codegen.registerFile({
|
|
225
|
+
// name: "handler.data-api.ts",
|
|
226
|
+
// generate: code/* tsx */ `
|
|
227
|
+
// /// <reference types="vinxi/types/server" />
|
|
228
|
+
// import { createRouter, eventHandler, getRouterParam, getQuery, getWebRequest, getRequestHeaders, getRequestURL } from "vinxi/http"
|
|
229
|
+
// import { serverContext } from "./context.js"
|
|
230
|
+
// const router = createRouter()
|
|
231
|
+
// .get(
|
|
232
|
+
// "/route/",
|
|
233
|
+
// eventHandler(async (event) => {
|
|
234
|
+
// const id = "/"
|
|
235
|
+
// const url = getRequestURL(event);
|
|
236
|
+
// return await serverContext.fetchRouteData({
|
|
237
|
+
// pathname: id,
|
|
238
|
+
// newOrigin: url.origin,
|
|
239
|
+
// })
|
|
240
|
+
// }),
|
|
241
|
+
// )
|
|
242
|
+
// .get(
|
|
243
|
+
// "/route/**:name",
|
|
244
|
+
// eventHandler(async (event) => {
|
|
245
|
+
// const id = "/" + getRouterParam(event, "name")
|
|
246
|
+
// const url = getRequestURL(event);
|
|
247
|
+
// return await serverContext.fetchRouteData({
|
|
248
|
+
// pathname: id,
|
|
249
|
+
// newOrigin: url.origin,
|
|
250
|
+
// })
|
|
251
|
+
// }),
|
|
252
|
+
// )
|
|
253
|
+
// .get(
|
|
254
|
+
// "/query/**:name",
|
|
255
|
+
// eventHandler(async (event) => {
|
|
256
|
+
// const id = "/" + getRouterParam(event, "name")
|
|
257
|
+
// const paramString = getQuery(event).params
|
|
258
|
+
// const params = typeof paramString === "string" && paramString.length ? JSON.parse(paramString) : {}
|
|
259
|
+
// return await serverContext.fetchNamedQuery({
|
|
260
|
+
// name: id,
|
|
261
|
+
// params: params,
|
|
262
|
+
// headers: getRequestHeaders(event),
|
|
263
|
+
// })
|
|
264
|
+
// }),
|
|
265
|
+
// )
|
|
266
|
+
// .post(
|
|
267
|
+
// "/mutation/**:name",
|
|
268
|
+
// eventHandler(async (event) => {
|
|
269
|
+
// const id = "/" + getRouterParam(event, "name")
|
|
270
|
+
// const body = await getWebRequest(event).json()
|
|
271
|
+
// return await serverContext.fetchMutation({
|
|
272
|
+
// name: id,
|
|
273
|
+
// body,
|
|
274
|
+
// headers: getRequestHeaders(event),
|
|
275
|
+
// })
|
|
276
|
+
// }),
|
|
277
|
+
// )
|
|
278
|
+
// export default router.handler
|
|
279
|
+
// `,
|
|
280
|
+
// })
|
|
281
|
+
}
|
|
282
|
+
if (opts.serverless) {
|
|
283
|
+
codegen.registerFile({
|
|
284
|
+
name: "handler.ssr-page.ts",
|
|
285
|
+
generate: code /* tsx */ `
|
|
286
|
+
/// <reference types="vinxi/types/server" />
|
|
287
|
+
import "../../views/index.css"
|
|
288
|
+
import "./manifest/blocks.js"
|
|
289
|
+
import "./manifest/styles.js"
|
|
290
|
+
import "./manifest/views.js"
|
|
291
|
+
import "./context.js"
|
|
292
|
+
import { proxyWpAdmin, renderPage, ServerContext } from "eddev/server"
|
|
293
|
+
import {
|
|
294
|
+
createRouter,
|
|
295
|
+
eventHandler,
|
|
296
|
+
getQuery,
|
|
297
|
+
getRequestHeaders,
|
|
298
|
+
getRequestURL,
|
|
299
|
+
getRouterParam,
|
|
300
|
+
getWebRequest,
|
|
301
|
+
} from "vinxi/http"
|
|
302
|
+
import { handleRPC } from "./rpc.js"
|
|
303
|
+
import { serverContext } from "./context.js"
|
|
304
|
+
|
|
305
|
+
const router = createRouter()
|
|
306
|
+
.get(
|
|
307
|
+
"/_data/route/",
|
|
308
|
+
eventHandler(async (event) => {
|
|
309
|
+
const id = "/"
|
|
310
|
+
const url = getRequestURL(event)
|
|
311
|
+
|
|
312
|
+
return await serverContext.fetchRouteData({ pathname: id, newOrigin: url.origin })
|
|
164
313
|
}),
|
|
165
314
|
)
|
|
166
315
|
.get(
|
|
167
|
-
"/route/**:name",
|
|
316
|
+
"/_data/route/**:name",
|
|
168
317
|
eventHandler(async (event) => {
|
|
169
318
|
const id = "/" + getRouterParam(event, "name")
|
|
319
|
+
const url = getRequestURL(event)
|
|
170
320
|
|
|
171
|
-
return await serverContext.fetchRouteData({
|
|
172
|
-
pathname: id,
|
|
173
|
-
withAppData: false,
|
|
174
|
-
})
|
|
321
|
+
return await serverContext.fetchRouteData({ pathname: id, newOrigin: url.origin })
|
|
175
322
|
}),
|
|
176
323
|
)
|
|
177
324
|
.get(
|
|
178
|
-
"/query/**:name",
|
|
325
|
+
"/_data/query/**:name",
|
|
179
326
|
eventHandler(async (event) => {
|
|
180
327
|
const id = "/" + getRouterParam(event, "name")
|
|
181
328
|
const paramString = getQuery(event).params
|
|
182
329
|
|
|
183
330
|
const params = typeof paramString === "string" && paramString.length ? JSON.parse(paramString) : {}
|
|
184
331
|
|
|
185
|
-
return await serverContext.fetchNamedQuery({
|
|
186
|
-
name: id,
|
|
187
|
-
params: params,
|
|
188
|
-
headers: getRequestHeaders(event),
|
|
189
|
-
})
|
|
332
|
+
return await serverContext.fetchNamedQuery({ name: id, params: params, headers: getRequestHeaders(event) })
|
|
190
333
|
}),
|
|
191
334
|
)
|
|
192
335
|
.post(
|
|
193
|
-
"/mutation/**:name",
|
|
336
|
+
"/_data/mutation/**:name",
|
|
194
337
|
eventHandler(async (event) => {
|
|
195
338
|
const id = "/" + getRouterParam(event, "name")
|
|
196
339
|
const body = await getWebRequest(event).json()
|
|
197
|
-
return await serverContext.fetchMutation({
|
|
198
|
-
name: id,
|
|
199
|
-
body,
|
|
200
|
-
headers: {},
|
|
201
|
-
})
|
|
340
|
+
return await serverContext.fetchMutation({ name: id, body, headers: getRequestHeaders(event) })
|
|
202
341
|
}),
|
|
203
342
|
)
|
|
204
343
|
|
|
205
|
-
export default
|
|
344
|
+
export default eventHandler({
|
|
345
|
+
handler: async (event) => {
|
|
346
|
+
const serverContext = ServerContext.main
|
|
347
|
+
const url = getRequestURL(event)
|
|
206
348
|
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
name: "handler.ssr-page.ts",
|
|
213
|
-
generate: code /* tsx */ `
|
|
214
|
-
/// <reference types="vinxi/types/server" />
|
|
215
|
-
import "../../views/index.css"
|
|
216
|
-
import "./manifest/blocks"
|
|
217
|
-
import "./manifest/styles"
|
|
218
|
-
import "./manifest/views"
|
|
219
|
-
|
|
220
|
-
import { renderPageToSSRStream, proxyWpAdmin } from "eddev/server"
|
|
221
|
-
import { eventHandler, setResponseHeader, setResponseStatus, getRequestURL } from "vinxi/http"
|
|
222
|
-
import { serverContext } from "./context"
|
|
223
|
-
|
|
224
|
-
export default eventHandler({
|
|
225
|
-
handler: async (event) => {
|
|
226
|
-
const url = getRequestURL(event)
|
|
227
|
-
|
|
228
|
-
if (url.pathname.includes('.')) {
|
|
229
|
-
return proxyWpAdmin(event, serverContext)
|
|
230
|
-
}
|
|
349
|
+
// RPC
|
|
350
|
+
const isRPC = serverContext.rpcBases.some((base) => url.pathname.startsWith(base))
|
|
351
|
+
if (isRPC) {
|
|
352
|
+
return handleRPC(event)
|
|
353
|
+
}
|
|
231
354
|
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
query: {},
|
|
237
|
-
})
|
|
238
|
-
if (response.ok) {
|
|
239
|
-
setResponseStatus(event, response.status)
|
|
240
|
-
setResponseHeader(event, "Content-Type", "text/html; charset=utf-8")
|
|
241
|
-
return renderPageToSSRStream(url.pathname, await response.json())
|
|
242
|
-
} else {
|
|
243
|
-
return response
|
|
244
|
-
}
|
|
245
|
-
},
|
|
246
|
-
})
|
|
355
|
+
// Data API
|
|
356
|
+
if (url.pathname.startsWith("/_data/")) {
|
|
357
|
+
return router.handler(event)
|
|
358
|
+
}
|
|
247
359
|
|
|
360
|
+
// Proxy WordPress
|
|
361
|
+
if (url.pathname.includes(".") || url.pathname.startsWith("/graphql") || url.pathname.startsWith("/wp-")) {
|
|
362
|
+
return proxyWpAdmin(event)
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
// SSR
|
|
366
|
+
return renderPage({ pathname: url.pathname, newOrigin: url.origin })
|
|
367
|
+
},
|
|
368
|
+
})
|
|
248
369
|
`,
|
|
249
370
|
});
|
|
250
371
|
}
|
|
251
372
|
if (opts.serverless) {
|
|
252
|
-
codegen.registerFile({
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
});
|
|
373
|
+
// codegen.registerFile({
|
|
374
|
+
// name: "handler.wp-proxy.ts",
|
|
375
|
+
// generate: code/* tsx */ `
|
|
376
|
+
// /// <reference types="vinxi/types/server" />
|
|
377
|
+
// import { proxyWpAdmin } from "eddev/server"
|
|
378
|
+
// import { eventHandler } from "vinxi/http"
|
|
379
|
+
// import "./context.js"
|
|
380
|
+
// export default eventHandler(async (event) => {
|
|
381
|
+
// return proxyWpAdmin(event)
|
|
382
|
+
// })
|
|
383
|
+
// `,
|
|
384
|
+
// })
|
|
265
385
|
}
|
|
266
386
|
codegen.registerFile({
|
|
267
387
|
name: "manifest/blocks.ts",
|
|
@@ -276,7 +396,7 @@ export function createVinxiCodegen(opts) {
|
|
|
276
396
|
${Object.entries(blockManifest.blocks)
|
|
277
397
|
.filter(([name]) => !name.match(/^_[a-z]+$/i))
|
|
278
398
|
.map(([name, block]) => {
|
|
279
|
-
const importStatement = `dynamic(() => import(${JSON.stringify("../../../" + block.fileName)}))`;
|
|
399
|
+
const importStatement = `dynamic(() => import(${JSON.stringify("../../../" + block.fileName)}), ${JSON.stringify(block.fileName)})`;
|
|
280
400
|
return JSON.stringify(block.acfName) + ": " + importStatement;
|
|
281
401
|
})
|
|
282
402
|
.join(",\n")},
|
|
@@ -360,12 +480,17 @@ export function createVinxiCodegen(opts) {
|
|
|
360
480
|
return code /* ts */ `
|
|
361
481
|
import { viewManifestReader } from 'eddev/_internal'
|
|
362
482
|
import { dynamic } from 'eddev/dynamic'
|
|
363
|
-
const manifest = {${Object.entries(viewManifest.views)
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
483
|
+
const manifest = {${Object.entries(viewManifest.views).map(([name, view]) => {
|
|
484
|
+
const src = "../../../" + view.fileName;
|
|
485
|
+
let importStatement;
|
|
486
|
+
if (name.startsWith("_")) {
|
|
487
|
+
importStatement = imp(name + "=" + src);
|
|
488
|
+
}
|
|
489
|
+
else {
|
|
490
|
+
importStatement = code `dynamic(() => import(${JSON.stringify(src)}), ${JSON.stringify(view.fileName)})`;
|
|
491
|
+
}
|
|
492
|
+
return code `${JSON.stringify(view.slug)}: ${importStatement},\n`;
|
|
493
|
+
})}}
|
|
369
494
|
|
|
370
495
|
viewManifestReader.value = manifest
|
|
371
496
|
|
|
@@ -391,7 +516,7 @@ export function createVinxiCodegen(opts) {
|
|
|
391
516
|
name: "manifest/tailwind-config.ts",
|
|
392
517
|
generate: async () => {
|
|
393
518
|
return code /* ts */ `
|
|
394
|
-
import tw from "../../../tailwind.config"
|
|
519
|
+
import tw from "../../../tailwind.config.ts"
|
|
395
520
|
import resolveConfig from 'tailwindcss/resolveConfig'
|
|
396
521
|
import { devToolsStore } from 'eddev/devtools'
|
|
397
522
|
|
|
@@ -404,5 +529,93 @@ export function createVinxiCodegen(opts) {
|
|
|
404
529
|
`;
|
|
405
530
|
},
|
|
406
531
|
});
|
|
532
|
+
if (opts.serverless) {
|
|
533
|
+
codegen.registerFile({
|
|
534
|
+
name: "manifest/routes.ts",
|
|
535
|
+
generate: async () => {
|
|
536
|
+
const routeManifest = await project.serverRoutes.get();
|
|
537
|
+
return code /* ts */ `
|
|
538
|
+
import { instantiateRouter } from "eddev/server"
|
|
539
|
+
${routeManifest.contextFileName
|
|
540
|
+
? code /*ts*/ `
|
|
541
|
+
import createContext from "../../../${routeManifest.contextFileName}"
|
|
542
|
+
`
|
|
543
|
+
: code /*ts*/ `
|
|
544
|
+
const createContext = () => ({})
|
|
545
|
+
`}
|
|
546
|
+
|
|
547
|
+
const router = instantiateRouter({${Object.entries(routeManifest.routes).map(([name, route]) => {
|
|
548
|
+
const src = "../../../" + route.fileName;
|
|
549
|
+
const importStatement = imp(camelCase(name) + "=" + src);
|
|
550
|
+
return code `${JSON.stringify(route.prefix)}: ${importStatement},\n`;
|
|
551
|
+
})}})
|
|
552
|
+
|
|
553
|
+
export { createContext, router }
|
|
554
|
+
`;
|
|
555
|
+
},
|
|
556
|
+
subscribe: project.serverRoutes.subscribe,
|
|
557
|
+
});
|
|
558
|
+
codegen.registerFile({
|
|
559
|
+
name: "rpc.ts",
|
|
560
|
+
generate: code /* tsx */ `
|
|
561
|
+
/// <reference types="vinxi/types/server" />
|
|
562
|
+
import "./context.js"
|
|
563
|
+
import { fetchRequestHandler } from "@trpc/server/adapters/fetch"
|
|
564
|
+
import { parseURL, stringifyParsedURL } from "ufo"
|
|
565
|
+
import { EventHandlerRequest, getWebRequest, H3Event, setResponseHeaders } from "vinxi/http"
|
|
566
|
+
import { createContext, router } from "./manifest/routes.ts"
|
|
567
|
+
import { ServerContext } from "eddev/server"
|
|
568
|
+
|
|
569
|
+
export function handleRPC(event: H3Event<EventHandlerRequest>) {
|
|
570
|
+
const serverContext = ServerContext.main
|
|
571
|
+
|
|
572
|
+
// Handle CORS
|
|
573
|
+
setResponseHeaders(event, serverContext.getCorsHeaders(event.headers.get("origin") ?? event.headers.get("referer") ?? ""))
|
|
574
|
+
if (event.method === "OPTIONS") {
|
|
575
|
+
event.node.res.statusCode = 204
|
|
576
|
+
event.node.res.statusMessage = "No Content."
|
|
577
|
+
return "OK"
|
|
578
|
+
}
|
|
579
|
+
|
|
580
|
+
// Update URLs with dots, which tRPC prefers
|
|
581
|
+
const originalReq = getWebRequest(event)
|
|
582
|
+
const parsed = parseURL(originalReq.url)
|
|
583
|
+
parsed.pathname = "/" + parsed.pathname.replace(/(^\\/|\\/$)/g, "").replace(/\\//g, ".")
|
|
584
|
+
const req = new Request(stringifyParsedURL(parsed), originalReq)
|
|
585
|
+
|
|
586
|
+
// Handle any early results which are Responses
|
|
587
|
+
function processEarlyResult(value: any): Response | undefined {
|
|
588
|
+
if (value instanceof Response) {
|
|
589
|
+
return value
|
|
590
|
+
}
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
return new Promise(async (resolve) => {
|
|
594
|
+
let sent = false
|
|
595
|
+
const defaultResponse = await fetchRequestHandler({
|
|
596
|
+
endpoint: "/",
|
|
597
|
+
req: req,
|
|
598
|
+
router: router,
|
|
599
|
+
createContext,
|
|
600
|
+
onError: (err) => console.error(err),
|
|
601
|
+
batching: { enabled: false },
|
|
602
|
+
// If a Response object is returned by a route, it will be sent as the response
|
|
603
|
+
responseMeta(opts) {
|
|
604
|
+
const value = opts?.data?.[0]?.["result"]?.["data"]
|
|
605
|
+
const response = processEarlyResult(value)
|
|
606
|
+
if (response) {
|
|
607
|
+
sent = true
|
|
608
|
+
resolve(response)
|
|
609
|
+
}
|
|
610
|
+
return {}
|
|
611
|
+
},
|
|
612
|
+
})
|
|
613
|
+
if (sent) return
|
|
614
|
+
resolve(defaultResponse)
|
|
615
|
+
})
|
|
616
|
+
}
|
|
617
|
+
`,
|
|
618
|
+
});
|
|
619
|
+
}
|
|
407
620
|
return codegen;
|
|
408
621
|
}
|
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
import { Project } from "../project/project.js";
|
|
2
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 {};
|