eddev 2.0.0-beta.11 → 2.0.0-beta.111
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 +8 -3
- 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 +3 -5
- package/dist/app/entry/ssr-root-client.d.ts +3 -1
- package/dist/app/entry/ssr-root-client.js +17 -6
- package/dist/app/entry/ssr-root.d.ts +3 -4
- package/dist/app/entry/ssr-root.js +19 -19
- 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 +24 -10
- 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 +2305 -1261
- 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 +2 -2
- 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 +37 -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 +41 -14
- package/dist/app/server/render-ssr-page.d.ts +27 -2
- package/dist/app/server/render-ssr-page.js +191 -12
- 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 +195 -28
- 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 +2 -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 +2 -0
- package/dist/node/compiler/get-vite-config.js +42 -12
- 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 +342 -112
- 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 +2 -1
- 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 +11 -1
- package/dist/node/project/project.js +61 -7
- package/dist/node/project/wp-info.d.ts +1 -0
- package/dist/node/project/wp-info.js +13 -1
- package/dist/node/storybook/index.d.ts +2 -0
- package/dist/node/storybook/index.js +13 -0
- 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/report-builder.d.ts +6 -6
- package/dist/node/utils/self-signed-cert.d.ts +2 -0
- package/dist/node/utils/self-signed-cert.js +10 -2
- 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 +21 -12
- 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
|
@@ -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,13 +60,31 @@ 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: () => {
|
|
52
84
|
return code /* tsx */ `
|
|
53
85
|
${opts.serverless ? `import "./react-shim.js"` : ""}
|
|
54
86
|
${opts.serverless ? `import "vinxi/client"` : ""}
|
|
55
|
-
import "
|
|
87
|
+
import "../../${project.cssEntryFile}"
|
|
56
88
|
import "./manifest/admin"
|
|
57
89
|
import "./manifest/blocks"
|
|
58
90
|
import "./manifest/styles"
|
|
@@ -77,7 +109,7 @@ export function createVinxiCodegen(opts) {
|
|
|
77
109
|
* Also ensures that the assets used during SSR are loaded.
|
|
78
110
|
*/
|
|
79
111
|
import "vinxi/client"
|
|
80
|
-
import "
|
|
112
|
+
import "../../${project.cssEntryFile}"
|
|
81
113
|
import "./manifest/blocks"
|
|
82
114
|
import "./manifest/views"
|
|
83
115
|
|
|
@@ -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
|
+
<React.Suspense><SSRClientRoot assets={getAssets()} metaTags={window._PAGE_DATA.meta.head} /></React.Suspense>,
|
|
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 = <React.Suspense><SSRClientRoot assets={getAssets()} metaTags={window._PAGE_DATA.meta.head} /></React.Suspense>
|
|
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
|
|
|
@@ -130,7 +162,7 @@ export function createVinxiCodegen(opts) {
|
|
|
130
162
|
*/
|
|
131
163
|
import "./manifest/blocks"
|
|
132
164
|
import "./manifest/views"
|
|
133
|
-
import "
|
|
165
|
+
import "../../${project.cssEntryFile}"
|
|
134
166
|
import { devToolsStore } from 'eddev/devtools'
|
|
135
167
|
import { createRoot } from "react-dom/client"
|
|
136
168
|
import { SPARoot } from "eddev/_internal/spa-root.js"
|
|
@@ -138,130 +170,235 @@ export function createVinxiCodegen(opts) {
|
|
|
138
170
|
|
|
139
171
|
devToolsStore.loadTailwindConfig = () => import('./manifest/tailwind-config')
|
|
140
172
|
|
|
141
|
-
createRoot(document.getElementById("root")!).render(<SPARoot
|
|
173
|
+
createRoot(document.getElementById("root")!).render(<React.Suspense><SPARoot /></React.Suspense>)
|
|
142
174
|
`;
|
|
143
175
|
}
|
|
144
176
|
},
|
|
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
|
|
164
207
|
}),
|
|
165
208
|
)
|
|
166
209
|
.get(
|
|
167
|
-
"/
|
|
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 "../../${project.cssEntryFile}"
|
|
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
|
+
import { getManifest } from "vinxi/manifest"
|
|
305
|
+
import { inspect } from "node:util"
|
|
306
|
+
|
|
307
|
+
const router = createRouter()
|
|
308
|
+
.get(
|
|
309
|
+
"/_data/route/",
|
|
310
|
+
eventHandler(async (event) => {
|
|
311
|
+
const id = "/"
|
|
312
|
+
const url = getRequestURL(event)
|
|
313
|
+
|
|
314
|
+
return await serverContext.fetchRouteData({ pathname: id, newOrigin: url.origin })
|
|
315
|
+
}),
|
|
316
|
+
)
|
|
317
|
+
.get(
|
|
318
|
+
"/_data/route/**:name",
|
|
168
319
|
eventHandler(async (event) => {
|
|
169
320
|
const id = "/" + getRouterParam(event, "name")
|
|
321
|
+
const url = getRequestURL(event)
|
|
170
322
|
|
|
171
|
-
return await serverContext.fetchRouteData({
|
|
172
|
-
pathname: id,
|
|
173
|
-
withAppData: false,
|
|
174
|
-
})
|
|
323
|
+
return await serverContext.fetchRouteData({ pathname: id, newOrigin: url.origin })
|
|
175
324
|
}),
|
|
176
325
|
)
|
|
177
326
|
.get(
|
|
178
|
-
"/query/**:name",
|
|
327
|
+
"/_data/query/**:name",
|
|
179
328
|
eventHandler(async (event) => {
|
|
180
329
|
const id = "/" + getRouterParam(event, "name")
|
|
181
330
|
const paramString = getQuery(event).params
|
|
182
331
|
|
|
183
332
|
const params = typeof paramString === "string" && paramString.length ? JSON.parse(paramString) : {}
|
|
184
333
|
|
|
185
|
-
return await serverContext.fetchNamedQuery({
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
334
|
+
return await serverContext.fetchNamedQuery({ name: id, params: params, headers: getRequestHeaders(event) })
|
|
335
|
+
}),
|
|
336
|
+
)
|
|
337
|
+
.get(
|
|
338
|
+
"/_data/manifest/**:input",
|
|
339
|
+
eventHandler(async (event) => {
|
|
340
|
+
const manifest = getManifest("client")
|
|
341
|
+
const id = getRouterParam(event, "input")
|
|
342
|
+
const input = manifest.inputs[id === 'handler' ? manifest.handler : id]
|
|
343
|
+
const result = {
|
|
344
|
+
...input,
|
|
345
|
+
id,
|
|
346
|
+
assets: await input.assets(),
|
|
347
|
+
}
|
|
348
|
+
const code = inspect(result, { depth: 10 })
|
|
349
|
+
return new Response(code, { headers: { "Content-Type": "text/plain" } })
|
|
190
350
|
}),
|
|
191
351
|
)
|
|
192
352
|
.post(
|
|
193
|
-
"/mutation/**:name",
|
|
353
|
+
"/_data/mutation/**:name",
|
|
194
354
|
eventHandler(async (event) => {
|
|
195
355
|
const id = "/" + getRouterParam(event, "name")
|
|
196
356
|
const body = await getWebRequest(event).json()
|
|
197
|
-
return await serverContext.fetchMutation({
|
|
198
|
-
name: id,
|
|
199
|
-
body,
|
|
200
|
-
headers: {},
|
|
201
|
-
})
|
|
357
|
+
return await serverContext.fetchMutation({ name: id, body, headers: getRequestHeaders(event) })
|
|
202
358
|
}),
|
|
203
359
|
)
|
|
204
360
|
|
|
205
|
-
export default
|
|
361
|
+
export default eventHandler({
|
|
362
|
+
handler: async (event) => {
|
|
363
|
+
const serverContext = ServerContext.main
|
|
364
|
+
const url = getRequestURL(event)
|
|
206
365
|
|
|
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
|
-
}
|
|
366
|
+
// RPC
|
|
367
|
+
const isRPC = serverContext.rpcBases.some((base) => url.pathname.startsWith(base))
|
|
368
|
+
if (isRPC) {
|
|
369
|
+
return handleRPC(event)
|
|
370
|
+
}
|
|
231
371
|
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
return renderPageToSSRStream(url.pathname, await response.json())
|
|
242
|
-
} else {
|
|
243
|
-
return response
|
|
244
|
-
}
|
|
245
|
-
},
|
|
246
|
-
})
|
|
372
|
+
// Data API
|
|
373
|
+
if (url.pathname.startsWith("/_data/")) {
|
|
374
|
+
return router.handler(event)
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
// Proxy WordPress
|
|
378
|
+
if (url.pathname.includes(".") || url.pathname.startsWith("/graphql") || url.pathname.startsWith("/wp-")) {
|
|
379
|
+
return proxyWpAdmin(event)
|
|
380
|
+
}
|
|
247
381
|
|
|
382
|
+
// SSR
|
|
383
|
+
return renderPage({ pathname: url.pathname, newOrigin: url.origin })
|
|
384
|
+
},
|
|
385
|
+
})
|
|
248
386
|
`,
|
|
249
387
|
});
|
|
250
388
|
}
|
|
251
389
|
if (opts.serverless) {
|
|
252
|
-
codegen.registerFile({
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
});
|
|
390
|
+
// codegen.registerFile({
|
|
391
|
+
// name: "handler.wp-proxy.ts",
|
|
392
|
+
// generate: code/* tsx */ `
|
|
393
|
+
// /// <reference types="vinxi/types/server" />
|
|
394
|
+
// import { proxyWpAdmin } from "eddev/server"
|
|
395
|
+
// import { eventHandler } from "vinxi/http"
|
|
396
|
+
// import "./context.js"
|
|
397
|
+
// export default eventHandler(async (event) => {
|
|
398
|
+
// return proxyWpAdmin(event)
|
|
399
|
+
// })
|
|
400
|
+
// `,
|
|
401
|
+
// })
|
|
265
402
|
}
|
|
266
403
|
codegen.registerFile({
|
|
267
404
|
name: "manifest/blocks.ts",
|
|
@@ -276,7 +413,7 @@ export function createVinxiCodegen(opts) {
|
|
|
276
413
|
${Object.entries(blockManifest.blocks)
|
|
277
414
|
.filter(([name]) => !name.match(/^_[a-z]+$/i))
|
|
278
415
|
.map(([name, block]) => {
|
|
279
|
-
const importStatement = `dynamic(() => import(${JSON.stringify("../../../" + block.fileName)}))`;
|
|
416
|
+
const importStatement = `dynamic(() => import(${JSON.stringify("../../../" + block.fileName)}), ${JSON.stringify(block.fileName)})`;
|
|
280
417
|
return JSON.stringify(block.acfName) + ": " + importStatement;
|
|
281
418
|
})
|
|
282
419
|
.join(",\n")},
|
|
@@ -360,12 +497,17 @@ export function createVinxiCodegen(opts) {
|
|
|
360
497
|
return code /* ts */ `
|
|
361
498
|
import { viewManifestReader } from 'eddev/_internal'
|
|
362
499
|
import { dynamic } from 'eddev/dynamic'
|
|
363
|
-
const manifest = {${Object.entries(viewManifest.views)
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
500
|
+
const manifest = {${Object.entries(viewManifest.views).map(([name, view]) => {
|
|
501
|
+
const src = "../../../" + view.fileName;
|
|
502
|
+
let importStatement;
|
|
503
|
+
if (name.startsWith("_")) {
|
|
504
|
+
importStatement = imp(name + "=" + src);
|
|
505
|
+
}
|
|
506
|
+
else {
|
|
507
|
+
importStatement = code `dynamic(() => import(${JSON.stringify(src)}), ${JSON.stringify(view.fileName)})`;
|
|
508
|
+
}
|
|
509
|
+
return code `${JSON.stringify(view.slug)}: ${importStatement},\n`;
|
|
510
|
+
})}}
|
|
369
511
|
|
|
370
512
|
viewManifestReader.value = manifest
|
|
371
513
|
|
|
@@ -391,7 +533,7 @@ export function createVinxiCodegen(opts) {
|
|
|
391
533
|
name: "manifest/tailwind-config.ts",
|
|
392
534
|
generate: async () => {
|
|
393
535
|
return code /* ts */ `
|
|
394
|
-
import tw from "../../../tailwind.config"
|
|
536
|
+
import tw from "../../../tailwind.config.ts"
|
|
395
537
|
import resolveConfig from 'tailwindcss/resolveConfig'
|
|
396
538
|
import { devToolsStore } from 'eddev/devtools'
|
|
397
539
|
|
|
@@ -404,5 +546,93 @@ export function createVinxiCodegen(opts) {
|
|
|
404
546
|
`;
|
|
405
547
|
},
|
|
406
548
|
});
|
|
549
|
+
if (opts.serverless) {
|
|
550
|
+
codegen.registerFile({
|
|
551
|
+
name: "manifest/routes.ts",
|
|
552
|
+
generate: async () => {
|
|
553
|
+
const routeManifest = await project.serverRoutes.get();
|
|
554
|
+
return code /* ts */ `
|
|
555
|
+
import { instantiateRouter } from "eddev/server"
|
|
556
|
+
${routeManifest.contextFileName
|
|
557
|
+
? code /*ts*/ `
|
|
558
|
+
import createContext from "../../../${routeManifest.contextFileName}"
|
|
559
|
+
`
|
|
560
|
+
: code /*ts*/ `
|
|
561
|
+
const createContext = () => ({})
|
|
562
|
+
`}
|
|
563
|
+
|
|
564
|
+
const router = instantiateRouter({${Object.entries(routeManifest.routes).map(([name, route]) => {
|
|
565
|
+
const src = "../../../" + route.fileName;
|
|
566
|
+
const importStatement = imp(camelCase(name) + "=" + src);
|
|
567
|
+
return code `${JSON.stringify(route.prefix)}: ${importStatement},\n`;
|
|
568
|
+
})}})
|
|
569
|
+
|
|
570
|
+
export { createContext, router }
|
|
571
|
+
`;
|
|
572
|
+
},
|
|
573
|
+
subscribe: project.serverRoutes.subscribe,
|
|
574
|
+
});
|
|
575
|
+
codegen.registerFile({
|
|
576
|
+
name: "rpc.ts",
|
|
577
|
+
generate: code /* tsx */ `
|
|
578
|
+
/// <reference types="vinxi/types/server" />
|
|
579
|
+
import "./context.js"
|
|
580
|
+
import { fetchRequestHandler } from "@trpc/server/adapters/fetch"
|
|
581
|
+
import { parseURL, stringifyParsedURL } from "ufo"
|
|
582
|
+
import { EventHandlerRequest, getWebRequest, H3Event, setResponseHeaders } from "vinxi/http"
|
|
583
|
+
import { createContext, router } from "./manifest/routes.ts"
|
|
584
|
+
import { ServerContext } from "eddev/server"
|
|
585
|
+
|
|
586
|
+
export function handleRPC(event: H3Event<EventHandlerRequest>) {
|
|
587
|
+
const serverContext = ServerContext.main
|
|
588
|
+
|
|
589
|
+
// Handle CORS
|
|
590
|
+
setResponseHeaders(event, serverContext.getCorsHeaders(event.headers.get("origin") ?? event.headers.get("referer") ?? ""))
|
|
591
|
+
if (event.method === "OPTIONS") {
|
|
592
|
+
event.node.res.statusCode = 204
|
|
593
|
+
event.node.res.statusMessage = "No Content."
|
|
594
|
+
return "OK"
|
|
595
|
+
}
|
|
596
|
+
|
|
597
|
+
// Update URLs with dots, which tRPC prefers
|
|
598
|
+
const originalReq = getWebRequest(event)
|
|
599
|
+
const parsed = parseURL(originalReq.url)
|
|
600
|
+
parsed.pathname = "/" + parsed.pathname.replace(/(^\\/|\\/$)/g, "").replace(/\\//g, ".")
|
|
601
|
+
const req = new Request(stringifyParsedURL(parsed), originalReq)
|
|
602
|
+
|
|
603
|
+
// Handle any early results which are Responses
|
|
604
|
+
function processEarlyResult(value: any): Response | undefined {
|
|
605
|
+
if (value instanceof Response) {
|
|
606
|
+
return value
|
|
607
|
+
}
|
|
608
|
+
}
|
|
609
|
+
|
|
610
|
+
return new Promise(async (resolve) => {
|
|
611
|
+
let sent = false
|
|
612
|
+
const defaultResponse = await fetchRequestHandler({
|
|
613
|
+
endpoint: "/",
|
|
614
|
+
req: req,
|
|
615
|
+
router: router,
|
|
616
|
+
createContext,
|
|
617
|
+
onError: (err) => console.error(err),
|
|
618
|
+
batching: { enabled: false },
|
|
619
|
+
// If a Response object is returned by a route, it will be sent as the response
|
|
620
|
+
responseMeta(opts) {
|
|
621
|
+
const value = opts?.data?.[0]?.["result"]?.["data"]
|
|
622
|
+
const response = processEarlyResult(value)
|
|
623
|
+
if (response) {
|
|
624
|
+
sent = true
|
|
625
|
+
resolve(response)
|
|
626
|
+
}
|
|
627
|
+
return {}
|
|
628
|
+
},
|
|
629
|
+
})
|
|
630
|
+
if (sent) return
|
|
631
|
+
resolve(defaultResponse)
|
|
632
|
+
})
|
|
633
|
+
}
|
|
634
|
+
`,
|
|
635
|
+
});
|
|
636
|
+
}
|
|
407
637
|
return codegen;
|
|
408
638
|
}
|
|
@@ -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 {};
|