eddev 2.0.0-beta.12 → 2.0.0-beta.121
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/css/editor-styles.css +4 -0
- 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 +9 -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 +18 -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 +3 -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 +15 -2
- package/dist/app/lib/blocks/EditableText.js +10 -4
- package/dist/app/lib/blocks/InnerBlocks.d.ts +21 -7
- package/dist/app/lib/blocks/InnerBlocks.js +75 -28
- 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/defineBlock.d.ts +3 -0
- package/dist/app/lib/blocks/defineBlock.js +7 -0
- package/dist/app/lib/blocks/editor/EditorHighlights.d.ts +7 -0
- package/dist/app/lib/blocks/editor/EditorHighlights.js +164 -0
- package/dist/app/lib/blocks/editor/EditorSupport.js +17 -12
- package/dist/app/lib/blocks/editor/ErrorBoundaryEditor.d.ts +1 -1
- package/dist/app/lib/blocks/editor/block-templates.d.ts +6 -0
- package/dist/app/lib/blocks/editor/block-templates.js +64 -0
- package/dist/app/lib/blocks/editor/create-block.d.ts +9 -0
- package/dist/app/lib/blocks/editor/create-block.js +13 -0
- package/dist/app/lib/blocks/editor/editor-config.d.ts +70 -7
- package/dist/app/lib/blocks/editor/editor-config.js +29 -62
- package/dist/app/lib/blocks/editor/installGutenbergHooks.d.ts +3 -0
- package/dist/app/lib/blocks/editor/installGutenbergHooks.js +105 -16
- 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 +10 -9
- package/dist/app/lib/blocks/index.js +10 -9
- package/dist/app/lib/blocks/inline-editing.d.ts +9 -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 +12 -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 +5 -1
- package/dist/app/lib/routing/components/BrowserRouter.js +98 -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 +192 -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 +44 -4
- package/dist/app/server/server-context.js +305 -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/query-monitor.d.ts +26 -0
- package/dist/app/utils/query-monitor.js +7 -0
- 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 +81 -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 +7 -1
- package/dist/node/compiler/get-vite-config.js +96 -16
- 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 +345 -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.meta.d.ts +105 -0
- 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,17 @@ 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>,
|
|
137
|
+
{
|
|
138
|
+
identifierPrefix: "ed",
|
|
139
|
+
}
|
|
105
140
|
)
|
|
106
141
|
|
|
107
142
|
if (import.meta.hot) {
|
|
108
143
|
import.meta.hot.accept((mod) => {
|
|
109
144
|
if (mod) {
|
|
110
|
-
const
|
|
111
|
-
const app = <SSRClientRoot assets={getAssets()} />
|
|
145
|
+
const app = <React.Suspense><SSRClientRoot assets={getAssets()} metaTags={window._PAGE_DATA.meta.head} /></React.Suspense>
|
|
112
146
|
window.$reactRoot?.render(app)
|
|
113
147
|
}
|
|
114
148
|
})
|
|
@@ -117,6 +151,7 @@ export function createVinxiCodegen(opts) {
|
|
|
117
151
|
declare global {
|
|
118
152
|
interface Window {
|
|
119
153
|
$reactRoot?: Root
|
|
154
|
+
_PAGE_DATA: any
|
|
120
155
|
}
|
|
121
156
|
}
|
|
122
157
|
|
|
@@ -130,7 +165,7 @@ export function createVinxiCodegen(opts) {
|
|
|
130
165
|
*/
|
|
131
166
|
import "./manifest/blocks"
|
|
132
167
|
import "./manifest/views"
|
|
133
|
-
import "
|
|
168
|
+
import "../../${project.cssEntryFile}"
|
|
134
169
|
import { devToolsStore } from 'eddev/devtools'
|
|
135
170
|
import { createRoot } from "react-dom/client"
|
|
136
171
|
import { SPARoot } from "eddev/_internal/spa-root.js"
|
|
@@ -138,130 +173,235 @@ export function createVinxiCodegen(opts) {
|
|
|
138
173
|
|
|
139
174
|
devToolsStore.loadTailwindConfig = () => import('./manifest/tailwind-config')
|
|
140
175
|
|
|
141
|
-
createRoot(document.getElementById("root")!).render(<SPARoot
|
|
176
|
+
createRoot(document.getElementById("root")!).render(<React.Suspense><SPARoot /></React.Suspense>)
|
|
142
177
|
`;
|
|
143
178
|
}
|
|
144
179
|
},
|
|
145
180
|
});
|
|
146
181
|
if (opts.serverless) {
|
|
147
182
|
codegen.registerFile({
|
|
148
|
-
name: "handler.
|
|
183
|
+
name: "handler.bypass.ts",
|
|
149
184
|
generate: code /* tsx */ `
|
|
150
185
|
/// <reference types="vinxi/types/server" />
|
|
151
|
-
import { createRouter, eventHandler,
|
|
152
|
-
|
|
186
|
+
import { createRouter, eventHandler, getCookie, setCookie } from "vinxi/http"
|
|
187
|
+
|
|
188
|
+
const BYPASS_TOKEN = process.env.VERCEL_BYPASS_TOKEN
|
|
189
|
+
const COOKIE_NAME = "__prerender_bypass"
|
|
153
190
|
|
|
154
191
|
const router = createRouter()
|
|
155
192
|
.get(
|
|
156
|
-
"/
|
|
193
|
+
"/enable",
|
|
157
194
|
eventHandler(async (event) => {
|
|
158
|
-
|
|
195
|
+
if (!BYPASS_TOKEN) return false
|
|
159
196
|
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
withAppData: false,
|
|
197
|
+
setCookie(event, COOKIE_NAME, BYPASS_TOKEN, {
|
|
198
|
+
expires: new Date(Date.now() + 1000 * 60 * 60 * 24),
|
|
163
199
|
})
|
|
200
|
+
|
|
201
|
+
return true
|
|
202
|
+
}),
|
|
203
|
+
)
|
|
204
|
+
.get(
|
|
205
|
+
"/disable",
|
|
206
|
+
eventHandler(async (event) => {
|
|
207
|
+
setCookie(event, COOKIE_NAME, "")
|
|
208
|
+
|
|
209
|
+
return true
|
|
210
|
+
}),
|
|
211
|
+
)
|
|
212
|
+
.get(
|
|
213
|
+
"/check",
|
|
214
|
+
eventHandler(async (event) => {
|
|
215
|
+
const cookie = getCookie(event, COOKIE_NAME)
|
|
216
|
+
|
|
217
|
+
if (cookie === BYPASS_TOKEN) {
|
|
218
|
+
return true
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
return false
|
|
164
222
|
}),
|
|
165
223
|
)
|
|
224
|
+
export default router.handler
|
|
225
|
+
`,
|
|
226
|
+
});
|
|
227
|
+
// codegen.registerFile({
|
|
228
|
+
// name: "handler.data-api.ts",
|
|
229
|
+
// generate: code/* tsx */ `
|
|
230
|
+
// /// <reference types="vinxi/types/server" />
|
|
231
|
+
// import { createRouter, eventHandler, getRouterParam, getQuery, getWebRequest, getRequestHeaders, getRequestURL } from "vinxi/http"
|
|
232
|
+
// import { serverContext } from "./context.js"
|
|
233
|
+
// const router = createRouter()
|
|
234
|
+
// .get(
|
|
235
|
+
// "/route/",
|
|
236
|
+
// eventHandler(async (event) => {
|
|
237
|
+
// const id = "/"
|
|
238
|
+
// const url = getRequestURL(event);
|
|
239
|
+
// return await serverContext.fetchRouteData({
|
|
240
|
+
// pathname: id,
|
|
241
|
+
// newOrigin: url.origin,
|
|
242
|
+
// })
|
|
243
|
+
// }),
|
|
244
|
+
// )
|
|
245
|
+
// .get(
|
|
246
|
+
// "/route/**:name",
|
|
247
|
+
// eventHandler(async (event) => {
|
|
248
|
+
// const id = "/" + getRouterParam(event, "name")
|
|
249
|
+
// const url = getRequestURL(event);
|
|
250
|
+
// return await serverContext.fetchRouteData({
|
|
251
|
+
// pathname: id,
|
|
252
|
+
// newOrigin: url.origin,
|
|
253
|
+
// })
|
|
254
|
+
// }),
|
|
255
|
+
// )
|
|
256
|
+
// .get(
|
|
257
|
+
// "/query/**:name",
|
|
258
|
+
// eventHandler(async (event) => {
|
|
259
|
+
// const id = "/" + getRouterParam(event, "name")
|
|
260
|
+
// const paramString = getQuery(event).params
|
|
261
|
+
// const params = typeof paramString === "string" && paramString.length ? JSON.parse(paramString) : {}
|
|
262
|
+
// return await serverContext.fetchNamedQuery({
|
|
263
|
+
// name: id,
|
|
264
|
+
// params: params,
|
|
265
|
+
// headers: getRequestHeaders(event),
|
|
266
|
+
// })
|
|
267
|
+
// }),
|
|
268
|
+
// )
|
|
269
|
+
// .post(
|
|
270
|
+
// "/mutation/**:name",
|
|
271
|
+
// eventHandler(async (event) => {
|
|
272
|
+
// const id = "/" + getRouterParam(event, "name")
|
|
273
|
+
// const body = await getWebRequest(event).json()
|
|
274
|
+
// return await serverContext.fetchMutation({
|
|
275
|
+
// name: id,
|
|
276
|
+
// body,
|
|
277
|
+
// headers: getRequestHeaders(event),
|
|
278
|
+
// })
|
|
279
|
+
// }),
|
|
280
|
+
// )
|
|
281
|
+
// export default router.handler
|
|
282
|
+
// `,
|
|
283
|
+
// })
|
|
284
|
+
}
|
|
285
|
+
if (opts.serverless) {
|
|
286
|
+
codegen.registerFile({
|
|
287
|
+
name: "handler.ssr-page.ts",
|
|
288
|
+
generate: code /* tsx */ `
|
|
289
|
+
/// <reference types="vinxi/types/server" />
|
|
290
|
+
import "../../${project.cssEntryFile}"
|
|
291
|
+
import "./manifest/blocks.js"
|
|
292
|
+
import "./manifest/styles.js"
|
|
293
|
+
import "./manifest/views.js"
|
|
294
|
+
import "./context.js"
|
|
295
|
+
import { proxyWpAdmin, renderPage, ServerContext } from "eddev/server"
|
|
296
|
+
import {
|
|
297
|
+
createRouter,
|
|
298
|
+
eventHandler,
|
|
299
|
+
getQuery,
|
|
300
|
+
getRequestHeaders,
|
|
301
|
+
getRequestURL,
|
|
302
|
+
getRouterParam,
|
|
303
|
+
getWebRequest,
|
|
304
|
+
} from "vinxi/http"
|
|
305
|
+
import { handleRPC } from "./rpc.js"
|
|
306
|
+
import { serverContext } from "./context.js"
|
|
307
|
+
import { getManifest } from "vinxi/manifest"
|
|
308
|
+
import { inspect } from "node:util"
|
|
309
|
+
|
|
310
|
+
const router = createRouter()
|
|
166
311
|
.get(
|
|
167
|
-
"/route
|
|
312
|
+
"/_data/route/",
|
|
313
|
+
eventHandler(async (event) => {
|
|
314
|
+
const id = "/"
|
|
315
|
+
const url = getRequestURL(event)
|
|
316
|
+
|
|
317
|
+
return await serverContext.fetchRouteData({ pathname: id, newOrigin: url.origin })
|
|
318
|
+
}),
|
|
319
|
+
)
|
|
320
|
+
.get(
|
|
321
|
+
"/_data/route/**:name",
|
|
168
322
|
eventHandler(async (event) => {
|
|
169
323
|
const id = "/" + getRouterParam(event, "name")
|
|
324
|
+
const url = getRequestURL(event)
|
|
170
325
|
|
|
171
|
-
return await serverContext.fetchRouteData({
|
|
172
|
-
pathname: id,
|
|
173
|
-
withAppData: false,
|
|
174
|
-
})
|
|
326
|
+
return await serverContext.fetchRouteData({ pathname: id, newOrigin: url.origin })
|
|
175
327
|
}),
|
|
176
328
|
)
|
|
177
329
|
.get(
|
|
178
|
-
"/query/**:name",
|
|
330
|
+
"/_data/query/**:name",
|
|
179
331
|
eventHandler(async (event) => {
|
|
180
332
|
const id = "/" + getRouterParam(event, "name")
|
|
181
333
|
const paramString = getQuery(event).params
|
|
182
334
|
|
|
183
335
|
const params = typeof paramString === "string" && paramString.length ? JSON.parse(paramString) : {}
|
|
184
336
|
|
|
185
|
-
return await serverContext.fetchNamedQuery({
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
337
|
+
return await serverContext.fetchNamedQuery({ name: id, params: params, headers: getRequestHeaders(event) })
|
|
338
|
+
}),
|
|
339
|
+
)
|
|
340
|
+
.get(
|
|
341
|
+
"/_data/manifest/**:input",
|
|
342
|
+
eventHandler(async (event) => {
|
|
343
|
+
const manifest = getManifest("client")
|
|
344
|
+
const id = getRouterParam(event, "input")
|
|
345
|
+
const input = manifest.inputs[id === 'handler' ? manifest.handler : id]
|
|
346
|
+
const result = {
|
|
347
|
+
...input,
|
|
348
|
+
id,
|
|
349
|
+
assets: await input.assets(),
|
|
350
|
+
}
|
|
351
|
+
const code = inspect(result, { depth: 10 })
|
|
352
|
+
return new Response(code, { headers: { "Content-Type": "text/plain" } })
|
|
190
353
|
}),
|
|
191
354
|
)
|
|
192
355
|
.post(
|
|
193
|
-
"/mutation/**:name",
|
|
356
|
+
"/_data/mutation/**:name",
|
|
194
357
|
eventHandler(async (event) => {
|
|
195
358
|
const id = "/" + getRouterParam(event, "name")
|
|
196
359
|
const body = await getWebRequest(event).json()
|
|
197
|
-
return await serverContext.fetchMutation({
|
|
198
|
-
name: id,
|
|
199
|
-
body,
|
|
200
|
-
headers: {},
|
|
201
|
-
})
|
|
360
|
+
return await serverContext.fetchMutation({ name: id, body, headers: getRequestHeaders(event) })
|
|
202
361
|
}),
|
|
203
362
|
)
|
|
204
363
|
|
|
205
|
-
export default
|
|
364
|
+
export default eventHandler({
|
|
365
|
+
handler: async (event) => {
|
|
366
|
+
const serverContext = ServerContext.main
|
|
367
|
+
const url = getRequestURL(event)
|
|
206
368
|
|
|
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
|
-
}
|
|
369
|
+
// RPC
|
|
370
|
+
const isRPC = serverContext.rpcBases.some((base) => url.pathname.startsWith(base))
|
|
371
|
+
if (isRPC) {
|
|
372
|
+
return handleRPC(event)
|
|
373
|
+
}
|
|
231
374
|
|
|
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
|
-
})
|
|
375
|
+
// Data API
|
|
376
|
+
if (url.pathname.startsWith("/_data/")) {
|
|
377
|
+
return router.handler(event)
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
// Proxy WordPress
|
|
381
|
+
if (url.pathname.includes(".") || url.pathname.startsWith("/graphql") || url.pathname.startsWith("/wp-")) {
|
|
382
|
+
return proxyWpAdmin(event)
|
|
383
|
+
}
|
|
247
384
|
|
|
385
|
+
// SSR
|
|
386
|
+
return renderPage({ pathname: url.pathname, newOrigin: url.origin })
|
|
387
|
+
},
|
|
388
|
+
})
|
|
248
389
|
`,
|
|
249
390
|
});
|
|
250
391
|
}
|
|
251
392
|
if (opts.serverless) {
|
|
252
|
-
codegen.registerFile({
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
});
|
|
393
|
+
// codegen.registerFile({
|
|
394
|
+
// name: "handler.wp-proxy.ts",
|
|
395
|
+
// generate: code/* tsx */ `
|
|
396
|
+
// /// <reference types="vinxi/types/server" />
|
|
397
|
+
// import { proxyWpAdmin } from "eddev/server"
|
|
398
|
+
// import { eventHandler } from "vinxi/http"
|
|
399
|
+
// import "./context.js"
|
|
400
|
+
// export default eventHandler(async (event) => {
|
|
401
|
+
// return proxyWpAdmin(event)
|
|
402
|
+
// })
|
|
403
|
+
// `,
|
|
404
|
+
// })
|
|
265
405
|
}
|
|
266
406
|
codegen.registerFile({
|
|
267
407
|
name: "manifest/blocks.ts",
|
|
@@ -276,7 +416,7 @@ export function createVinxiCodegen(opts) {
|
|
|
276
416
|
${Object.entries(blockManifest.blocks)
|
|
277
417
|
.filter(([name]) => !name.match(/^_[a-z]+$/i))
|
|
278
418
|
.map(([name, block]) => {
|
|
279
|
-
const importStatement = `dynamic(() => import(${JSON.stringify("../../../" + block.fileName)}))`;
|
|
419
|
+
const importStatement = `dynamic(() => import(${JSON.stringify("../../../" + block.fileName)}), ${JSON.stringify(block.fileName)})`;
|
|
280
420
|
return JSON.stringify(block.acfName) + ": " + importStatement;
|
|
281
421
|
})
|
|
282
422
|
.join(",\n")},
|
|
@@ -360,12 +500,17 @@ export function createVinxiCodegen(opts) {
|
|
|
360
500
|
return code /* ts */ `
|
|
361
501
|
import { viewManifestReader } from 'eddev/_internal'
|
|
362
502
|
import { dynamic } from 'eddev/dynamic'
|
|
363
|
-
const manifest = {${Object.entries(viewManifest.views)
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
503
|
+
const manifest = {${Object.entries(viewManifest.views).map(([name, view]) => {
|
|
504
|
+
const src = "../../../" + view.fileName;
|
|
505
|
+
let importStatement;
|
|
506
|
+
if (name.startsWith("_")) {
|
|
507
|
+
importStatement = imp(name + "=" + src);
|
|
508
|
+
}
|
|
509
|
+
else {
|
|
510
|
+
importStatement = code `dynamic(() => import(${JSON.stringify(src)}), ${JSON.stringify(view.fileName)})`;
|
|
511
|
+
}
|
|
512
|
+
return code `${JSON.stringify(view.slug)}: ${importStatement},\n`;
|
|
513
|
+
})}}
|
|
369
514
|
|
|
370
515
|
viewManifestReader.value = manifest
|
|
371
516
|
|
|
@@ -391,7 +536,7 @@ export function createVinxiCodegen(opts) {
|
|
|
391
536
|
name: "manifest/tailwind-config.ts",
|
|
392
537
|
generate: async () => {
|
|
393
538
|
return code /* ts */ `
|
|
394
|
-
import tw from "../../../tailwind.config"
|
|
539
|
+
import tw from "../../../tailwind.config.ts"
|
|
395
540
|
import resolveConfig from 'tailwindcss/resolveConfig'
|
|
396
541
|
import { devToolsStore } from 'eddev/devtools'
|
|
397
542
|
|
|
@@ -404,5 +549,93 @@ export function createVinxiCodegen(opts) {
|
|
|
404
549
|
`;
|
|
405
550
|
},
|
|
406
551
|
});
|
|
552
|
+
if (opts.serverless) {
|
|
553
|
+
codegen.registerFile({
|
|
554
|
+
name: "manifest/routes.ts",
|
|
555
|
+
generate: async () => {
|
|
556
|
+
const routeManifest = await project.serverRoutes.get();
|
|
557
|
+
return code /* ts */ `
|
|
558
|
+
import { instantiateRouter } from "eddev/server"
|
|
559
|
+
${routeManifest.contextFileName
|
|
560
|
+
? code /*ts*/ `
|
|
561
|
+
import createContext from "../../../${routeManifest.contextFileName}"
|
|
562
|
+
`
|
|
563
|
+
: code /*ts*/ `
|
|
564
|
+
const createContext = () => ({})
|
|
565
|
+
`}
|
|
566
|
+
|
|
567
|
+
const router = instantiateRouter({${Object.entries(routeManifest.routes).map(([name, route]) => {
|
|
568
|
+
const src = "../../../" + route.fileName;
|
|
569
|
+
const importStatement = imp(camelCase(name) + "=" + src);
|
|
570
|
+
return code `${JSON.stringify(route.prefix)}: ${importStatement},\n`;
|
|
571
|
+
})}})
|
|
572
|
+
|
|
573
|
+
export { createContext, router }
|
|
574
|
+
`;
|
|
575
|
+
},
|
|
576
|
+
subscribe: project.serverRoutes.subscribe,
|
|
577
|
+
});
|
|
578
|
+
codegen.registerFile({
|
|
579
|
+
name: "rpc.ts",
|
|
580
|
+
generate: code /* tsx */ `
|
|
581
|
+
/// <reference types="vinxi/types/server" />
|
|
582
|
+
import "./context.js"
|
|
583
|
+
import { fetchRequestHandler } from "@trpc/server/adapters/fetch"
|
|
584
|
+
import { parseURL, stringifyParsedURL } from "ufo"
|
|
585
|
+
import { EventHandlerRequest, getWebRequest, H3Event, setResponseHeaders } from "vinxi/http"
|
|
586
|
+
import { createContext, router } from "./manifest/routes.ts"
|
|
587
|
+
import { ServerContext } from "eddev/server"
|
|
588
|
+
|
|
589
|
+
export function handleRPC(event: H3Event<EventHandlerRequest>) {
|
|
590
|
+
const serverContext = ServerContext.main
|
|
591
|
+
|
|
592
|
+
// Handle CORS
|
|
593
|
+
setResponseHeaders(event, serverContext.getCorsHeaders(event.headers.get("origin") ?? event.headers.get("referer") ?? ""))
|
|
594
|
+
if (event.method === "OPTIONS") {
|
|
595
|
+
event.node.res.statusCode = 204
|
|
596
|
+
event.node.res.statusMessage = "No Content."
|
|
597
|
+
return "OK"
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
// Update URLs with dots, which tRPC prefers
|
|
601
|
+
const originalReq = getWebRequest(event)
|
|
602
|
+
const parsed = parseURL(originalReq.url)
|
|
603
|
+
parsed.pathname = "/" + parsed.pathname.replace(/(^\\/|\\/$)/g, "").replace(/\\//g, ".")
|
|
604
|
+
const req = new Request(stringifyParsedURL(parsed), originalReq)
|
|
605
|
+
|
|
606
|
+
// Handle any early results which are Responses
|
|
607
|
+
function processEarlyResult(value: any): Response | undefined {
|
|
608
|
+
if (value instanceof Response) {
|
|
609
|
+
return value
|
|
610
|
+
}
|
|
611
|
+
}
|
|
612
|
+
|
|
613
|
+
return new Promise(async (resolve) => {
|
|
614
|
+
let sent = false
|
|
615
|
+
const defaultResponse = await fetchRequestHandler({
|
|
616
|
+
endpoint: "/",
|
|
617
|
+
req: req,
|
|
618
|
+
router: router,
|
|
619
|
+
createContext,
|
|
620
|
+
onError: (err) => console.error(err),
|
|
621
|
+
batching: { enabled: false },
|
|
622
|
+
// If a Response object is returned by a route, it will be sent as the response
|
|
623
|
+
responseMeta(opts) {
|
|
624
|
+
const value = opts?.data?.[0]?.["result"]?.["data"]
|
|
625
|
+
const response = processEarlyResult(value)
|
|
626
|
+
if (response) {
|
|
627
|
+
sent = true
|
|
628
|
+
resolve(response)
|
|
629
|
+
}
|
|
630
|
+
return {}
|
|
631
|
+
},
|
|
632
|
+
})
|
|
633
|
+
if (sent) return
|
|
634
|
+
resolve(defaultResponse)
|
|
635
|
+
})
|
|
636
|
+
}
|
|
637
|
+
`,
|
|
638
|
+
});
|
|
639
|
+
}
|
|
407
640
|
return codegen;
|
|
408
641
|
}
|
|
@@ -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 {};
|