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,22 +1,154 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { renderAsset } from "@vinxi/react";
|
|
3
3
|
import { Suspense } from "react";
|
|
4
|
-
import { renderToPipeableStream } from "react-dom/server";
|
|
5
|
-
import {
|
|
6
|
-
import { RouteLoader } from "../lib/routing/loader";
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
|
|
4
|
+
import { renderToPipeableStream, renderToString } from "react-dom/server";
|
|
5
|
+
import { SSRRoot } from "../entry/ssr-root.js";
|
|
6
|
+
import { RouteLoader } from "../lib/routing/loader.js";
|
|
7
|
+
import { ServerContext } from "./server-context.js";
|
|
8
|
+
import { Writable } from "stream";
|
|
9
|
+
import { MetaTags } from "../entry/MetaTags.js";
|
|
10
|
+
import { AssetCaptureContext } from "../utils/asset-capture.js";
|
|
11
|
+
export async function getSsrStream(args) {
|
|
12
|
+
const clientManifest = ServerContext.main.runtime.getManifest("client");
|
|
10
13
|
const assets = await clientManifest.inputs[clientManifest.handler].assets();
|
|
11
|
-
|
|
12
|
-
|
|
14
|
+
// console.log(
|
|
15
|
+
// "M",
|
|
16
|
+
// assets.filter((f) => (f as any).tag === "script"),
|
|
17
|
+
// clientManifest.inputs[clientManifest.handler],
|
|
18
|
+
// )
|
|
19
|
+
// for (let k in clientManifest.chunks) {
|
|
20
|
+
// console.log(k)
|
|
21
|
+
// }
|
|
22
|
+
const dynamicAssets = new Set([]);
|
|
23
|
+
const jsx = (_jsx(AssetCaptureContext.Provider, { value: dynamicAssets, children: _jsx(SSRRoot, { assets: _jsx(Suspense, { children: assets.map((m) => renderAsset(m)) }), metaTags: args.initialData?.meta?.head || [], pathname: args.pathname, initialData: args.initialData, loader: new RouteLoader() }) }));
|
|
24
|
+
const stream = await new Promise(async (resolve, reject) => {
|
|
25
|
+
// console.log("Rendering to pipable")
|
|
13
26
|
const stream = renderToPipeableStream(jsx, {
|
|
14
27
|
onShellReady() {
|
|
28
|
+
// console.log("Shell ready")
|
|
15
29
|
resolve(stream);
|
|
16
30
|
},
|
|
31
|
+
onShellError(err) {
|
|
32
|
+
console.log("onShellError", err);
|
|
33
|
+
reject(err);
|
|
34
|
+
},
|
|
35
|
+
onError(err, errInfo) {
|
|
36
|
+
console.log("Error occurred after shell ready", err, errInfo);
|
|
37
|
+
console.error(err);
|
|
38
|
+
},
|
|
17
39
|
bootstrapModules: [clientManifest.inputs[clientManifest.handler].output.path],
|
|
18
|
-
bootstrapScriptContent: `window.manifest = ${JSON.stringify(await clientManifest.json())}
|
|
40
|
+
bootstrapScriptContent: `window.manifest = ${JSON.stringify(await clientManifest.json())};\nwindow._PAGE_DATA = ${JSON.stringify(args.initialData)};\nwindow._TRACKERS = ${JSON.stringify(args.initialData.trackers)};`,
|
|
19
41
|
});
|
|
20
42
|
});
|
|
21
|
-
|
|
43
|
+
const [initial, middle, end] = renderToString(_jsxs("html", { lang: "en", children: [_jsxs("head", { children: [_jsx(MetaTags, { tags: args.initialData.meta?.head ?? [] }), _jsx(MetaTags, { tags: args.initialData.trackers?.head ?? [] }), assets.map((m) => renderAsset(m)), "%%%%"] }), _jsxs("body", { children: [_jsx(MetaTags, { tags: args.initialData.trackers?.body ?? [] }), _jsx("div", { id: "_root", children: "%%%%" }), _jsx(MetaTags, { tags: args.initialData.trackers?.footer ?? [] })] })] })).split("%%%%");
|
|
44
|
+
return new ReadableStream({
|
|
45
|
+
async start(controller) {
|
|
46
|
+
controller.enqueue(new TextEncoder().encode(initial));
|
|
47
|
+
const inner = await new Promise((resolve, reject) => {
|
|
48
|
+
let buffer = [];
|
|
49
|
+
const writableStream = new Writable({
|
|
50
|
+
emitClose: true,
|
|
51
|
+
write(chunk, encoding, callback) {
|
|
52
|
+
buffer.push(chunk);
|
|
53
|
+
// controller.enqueue(chunk)
|
|
54
|
+
callback();
|
|
55
|
+
},
|
|
56
|
+
final(callback) {
|
|
57
|
+
resolve(buffer);
|
|
58
|
+
// controller.close()
|
|
59
|
+
callback();
|
|
60
|
+
},
|
|
61
|
+
});
|
|
62
|
+
stream.pipe(writableStream);
|
|
63
|
+
});
|
|
64
|
+
console.log(clientManifest.json());
|
|
65
|
+
for (const asset of dynamicAssets) {
|
|
66
|
+
// const assets = await clientManifest.inputs["/" + asset].assets()
|
|
67
|
+
// console.log(assets)
|
|
68
|
+
// console.log("A", assets.output, (await assets.assets())?.[0])
|
|
69
|
+
// const assets = await clientManifest.inputs[assets.output.path!]?.assets()
|
|
70
|
+
// console.log("F?", inputs)
|
|
71
|
+
controller.enqueue(new TextEncoder().encode(`\n<!-- for ${asset} -->`));
|
|
72
|
+
// controller.enqueue(new TextEncoder().encode(`\n<script>${JSON.stringify(assets)}</script>`))
|
|
73
|
+
// controller.enqueue(
|
|
74
|
+
// new TextEncoder().encode(renderToString(<>{assets.map((a) => renderAsset(asset as any))}</>)),
|
|
75
|
+
// )
|
|
76
|
+
}
|
|
77
|
+
// console.log("ASSETS", await clientManifest)
|
|
78
|
+
controller.enqueue(new TextEncoder().encode(middle));
|
|
79
|
+
for (const chunk of inner) {
|
|
80
|
+
controller.enqueue(chunk);
|
|
81
|
+
}
|
|
82
|
+
controller.enqueue(new TextEncoder().encode(end));
|
|
83
|
+
// console.log("Assets", dynamicAssets)
|
|
84
|
+
controller.close();
|
|
85
|
+
},
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
export async function renderPage(args) {
|
|
89
|
+
const serverContext = ServerContext.main;
|
|
90
|
+
let headers = new Headers();
|
|
91
|
+
let responseInit = {
|
|
92
|
+
headers,
|
|
93
|
+
};
|
|
94
|
+
try {
|
|
95
|
+
const [{ appData, trackers }, response] = await Promise.all([
|
|
96
|
+
serverContext.fetchAppData(),
|
|
97
|
+
serverContext.fetchRouteData({
|
|
98
|
+
pathname: args.pathname,
|
|
99
|
+
newOrigin: args.newOrigin,
|
|
100
|
+
}),
|
|
101
|
+
]);
|
|
102
|
+
let data;
|
|
103
|
+
try {
|
|
104
|
+
data = await response.json();
|
|
105
|
+
data.appData = appData;
|
|
106
|
+
data.trackers = trackers;
|
|
107
|
+
responseInit.status = response.status;
|
|
108
|
+
}
|
|
109
|
+
catch (err) {
|
|
110
|
+
console.error(err);
|
|
111
|
+
return renderErrorPage({
|
|
112
|
+
pathname: args.pathname,
|
|
113
|
+
code: 500,
|
|
114
|
+
newOrigin: args.newOrigin,
|
|
115
|
+
realError: err,
|
|
116
|
+
title: "Internal Server Error",
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
headers.set("Content-Type", "text/html; charset=utf-8");
|
|
120
|
+
const stream = await getSsrStream({
|
|
121
|
+
...args,
|
|
122
|
+
initialData: data,
|
|
123
|
+
});
|
|
124
|
+
return new Response(stream, responseInit);
|
|
125
|
+
}
|
|
126
|
+
catch (err) {
|
|
127
|
+
console.error(err);
|
|
128
|
+
if (args.statusCode !== 500) {
|
|
129
|
+
return renderErrorPage({
|
|
130
|
+
pathname: args.pathname,
|
|
131
|
+
code: 500,
|
|
132
|
+
newOrigin: args.newOrigin,
|
|
133
|
+
realError: err,
|
|
134
|
+
title: "Internal Server Error",
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
return new Response('<!DOCTYPE html><html><head><title>500 Internal Server Error</title></head><body><h1>500 Internal Server Error</h1><p>"' +
|
|
138
|
+
String(err) +
|
|
139
|
+
'"</p></body></html>', {
|
|
140
|
+
status: 500,
|
|
141
|
+
statusText: "Internal Server Error",
|
|
142
|
+
headers: {
|
|
143
|
+
"Content-Type": "text/html; charset=utf-8",
|
|
144
|
+
},
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
export async function renderErrorPage(args) {
|
|
149
|
+
return renderPage({
|
|
150
|
+
pathname: "/_error",
|
|
151
|
+
statusCode: args.code,
|
|
152
|
+
newOrigin: args.newOrigin,
|
|
153
|
+
});
|
|
22
154
|
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { AnyProcedure } from "@trpc/server";
|
|
2
|
+
import { FetchCreateContextFnOptions } from "@trpc/server/adapters/fetch";
|
|
3
|
+
export declare const rpcApi: {
|
|
4
|
+
_config: import("@trpc/server/unstable-core-do-not-import").RootConfig<{
|
|
5
|
+
ctx: RPCContext;
|
|
6
|
+
meta: object;
|
|
7
|
+
errorShape: import("@trpc/server/unstable-core-do-not-import").DefaultErrorShape;
|
|
8
|
+
transformer: true;
|
|
9
|
+
}>;
|
|
10
|
+
procedure: import("@trpc/server/unstable-core-do-not-import").ProcedureBuilder<RPCContext, object, object, typeof import("@trpc/server/unstable-core-do-not-import").unsetMarker, typeof import("@trpc/server/unstable-core-do-not-import").unsetMarker, typeof import("@trpc/server/unstable-core-do-not-import").unsetMarker, typeof import("@trpc/server/unstable-core-do-not-import").unsetMarker, false>;
|
|
11
|
+
middleware: <$ContextOverrides>(fn: import("@trpc/server/unstable-core-do-not-import").MiddlewareFunction<RPCContext, object, object, $ContextOverrides, unknown>) => import("@trpc/server/unstable-core-do-not-import").MiddlewareBuilder<RPCContext, object, $ContextOverrides, unknown>;
|
|
12
|
+
router: {
|
|
13
|
+
<TInput extends import("@trpc/server").RouterRecord>(input: TInput): import("@trpc/server/unstable-core-do-not-import").BuiltRouter<{
|
|
14
|
+
ctx: RPCContext;
|
|
15
|
+
meta: object;
|
|
16
|
+
errorShape: import("@trpc/server/unstable-core-do-not-import").DefaultErrorShape;
|
|
17
|
+
transformer: true;
|
|
18
|
+
}, TInput>;
|
|
19
|
+
<TInput extends import("@trpc/server/unstable-core-do-not-import").CreateRouterOptions>(input: TInput): import("@trpc/server/unstable-core-do-not-import").BuiltRouter<{
|
|
20
|
+
ctx: RPCContext;
|
|
21
|
+
meta: object;
|
|
22
|
+
errorShape: import("@trpc/server/unstable-core-do-not-import").DefaultErrorShape;
|
|
23
|
+
transformer: true;
|
|
24
|
+
}, import("@trpc/server/unstable-core-do-not-import").DecorateCreateRouterOptions<TInput>>;
|
|
25
|
+
};
|
|
26
|
+
mergeRouters: typeof import("@trpc/server/unstable-core-do-not-import").mergeRouters;
|
|
27
|
+
createCallerFactory: <TRecord extends import("@trpc/server").RouterRecord>(router: Pick<import("@trpc/server/unstable-core-do-not-import").Router<{
|
|
28
|
+
ctx: RPCContext;
|
|
29
|
+
meta: object;
|
|
30
|
+
errorShape: import("@trpc/server/unstable-core-do-not-import").DefaultErrorShape;
|
|
31
|
+
transformer: true;
|
|
32
|
+
}, TRecord>, "_def">) => import("@trpc/server/unstable-core-do-not-import").RouterCaller<{
|
|
33
|
+
ctx: RPCContext;
|
|
34
|
+
meta: object;
|
|
35
|
+
errorShape: import("@trpc/server/unstable-core-do-not-import").DefaultErrorShape;
|
|
36
|
+
transformer: true;
|
|
37
|
+
}, TRecord>;
|
|
38
|
+
};
|
|
39
|
+
type RouterSchema = Record<string, Record<string, AnyProcedure> | AnyProcedure>;
|
|
40
|
+
export declare const rpc: {
|
|
41
|
+
middleware: <$ContextOverrides>(fn: import("@trpc/server/unstable-core-do-not-import").MiddlewareFunction<RPCContext, object, object, $ContextOverrides, unknown>) => import("@trpc/server/unstable-core-do-not-import").MiddlewareBuilder<RPCContext, object, $ContextOverrides, unknown>;
|
|
42
|
+
procedure: import("@trpc/server/unstable-core-do-not-import").ProcedureBuilder<RPCContext, object, object, typeof import("@trpc/server/unstable-core-do-not-import").unsetMarker, typeof import("@trpc/server/unstable-core-do-not-import").unsetMarker, typeof import("@trpc/server/unstable-core-do-not-import").unsetMarker, typeof import("@trpc/server/unstable-core-do-not-import").unsetMarker, false>;
|
|
43
|
+
router<T extends RouterSchema>(routes: T): T;
|
|
44
|
+
};
|
|
45
|
+
export declare function defineServerContext<T>(func: (opts: FetchCreateContextFnOptions) => T): (opts: FetchCreateContextFnOptions) => T;
|
|
46
|
+
export declare function instantiateRouter<T extends RouterSchema>(routes: T): import("@trpc/server/unstable-core-do-not-import").BuiltRouter<{
|
|
47
|
+
ctx: RPCContext;
|
|
48
|
+
meta: object;
|
|
49
|
+
errorShape: import("@trpc/server/unstable-core-do-not-import").DefaultErrorShape;
|
|
50
|
+
transformer: true;
|
|
51
|
+
}, T>;
|
|
52
|
+
export type InferRPCServerContext<TFunc extends null | ((opts: FetchCreateContextFnOptions) => any)> = {
|
|
53
|
+
req: Request;
|
|
54
|
+
resHeaders: Headers;
|
|
55
|
+
} & (TFunc extends (opts: FetchCreateContextFnOptions) => infer T ? T : {});
|
|
56
|
+
export {};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { initTRPC } from "@trpc/server";
|
|
2
|
+
import superjson from "superjson";
|
|
3
|
+
export const rpcApi = initTRPC.context().create({
|
|
4
|
+
transformer: superjson,
|
|
5
|
+
});
|
|
6
|
+
export const rpc = {
|
|
7
|
+
middleware: rpcApi.middleware,
|
|
8
|
+
procedure: rpcApi.procedure,
|
|
9
|
+
router(routes) {
|
|
10
|
+
return routes;
|
|
11
|
+
},
|
|
12
|
+
};
|
|
13
|
+
export function defineServerContext(func) {
|
|
14
|
+
return func;
|
|
15
|
+
}
|
|
16
|
+
export function instantiateRouter(routes) {
|
|
17
|
+
return rpcApi.router(routes);
|
|
18
|
+
}
|
|
@@ -1,25 +1,47 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Manifest } from "vinxi/dist/types/types/manifest";
|
|
2
2
|
import { RequestHeaders } from "vinxi/http";
|
|
3
|
+
import type { EDConfig } from "../../node/project/config.js";
|
|
4
|
+
import { TrackerTags } from "../lib/routing/types.js";
|
|
5
|
+
import { UrlReplacerConf } from "./utils/replace-host.js";
|
|
3
6
|
export type ServerContextArgs = {
|
|
4
7
|
dev: boolean;
|
|
5
8
|
origin: string;
|
|
6
9
|
replaceUrls?: UrlReplacerConf;
|
|
10
|
+
rpcBases?: string[];
|
|
11
|
+
config: EDConfig;
|
|
12
|
+
};
|
|
13
|
+
export type ServerContextRuntime = {
|
|
14
|
+
getManifest: (name: string) => Manifest;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Data returned from WordPress origin /_appdata route
|
|
18
|
+
*/
|
|
19
|
+
type ServerAppData = {
|
|
20
|
+
appData: any;
|
|
21
|
+
trackers: TrackerTags;
|
|
7
22
|
};
|
|
8
23
|
export declare class ServerContext {
|
|
9
24
|
dev: boolean;
|
|
10
25
|
origin: string;
|
|
11
|
-
|
|
26
|
+
_urlReplacer?: (text: string, origin?: string) => string;
|
|
27
|
+
rpcBases: string[];
|
|
28
|
+
config: EDConfig;
|
|
29
|
+
static main: ServerContext;
|
|
12
30
|
constructor(conf: ServerContextArgs);
|
|
31
|
+
replaceUrls(text: string, origin?: string): string;
|
|
32
|
+
get runtime(): ServerContextRuntime;
|
|
33
|
+
static setRuntime(rt: ServerContextRuntime): void;
|
|
13
34
|
getOriginUrl(url: string): string;
|
|
14
35
|
fetchOrigin(url: string, opts?: RequestInit & {
|
|
15
36
|
replaceUrls?: boolean;
|
|
37
|
+
newOrigin?: string;
|
|
16
38
|
}): Promise<Response>;
|
|
17
39
|
fetchRouteData(req: {
|
|
18
40
|
pathname: string;
|
|
19
|
-
query?: Record<string, any>;
|
|
20
41
|
headers?: RequestHeaders;
|
|
21
|
-
|
|
42
|
+
newOrigin?: string;
|
|
22
43
|
}): Promise<Response>;
|
|
44
|
+
fetchAppData(): Promise<ServerAppData>;
|
|
23
45
|
extractRequestHeaders(req?: RequestHeaders): Partial<Record<import("vinxi/http").HTTPHeaderName, string | undefined>>;
|
|
24
46
|
fetchNamedQuery(req: {
|
|
25
47
|
name: string;
|
|
@@ -31,4 +53,20 @@ export declare class ServerContext {
|
|
|
31
53
|
body: object;
|
|
32
54
|
headers: RequestHeaders;
|
|
33
55
|
}): Promise<Response>;
|
|
56
|
+
get allowedCorsOrigins(): string[];
|
|
57
|
+
getCorsOrigin(originHeader: string): string | undefined;
|
|
58
|
+
getCorsHeaders(origin: string): {
|
|
59
|
+
"Access-Control-Allow-Methods"?: undefined;
|
|
60
|
+
"Access-Control-Allow-Origin"?: undefined;
|
|
61
|
+
"Access-Control-Allow-Credentials"?: undefined;
|
|
62
|
+
"Access-Control-Allow-Headers"?: undefined;
|
|
63
|
+
"Access-Control-Expose-Headers"?: undefined;
|
|
64
|
+
} | {
|
|
65
|
+
"Access-Control-Allow-Methods": string;
|
|
66
|
+
"Access-Control-Allow-Origin": string;
|
|
67
|
+
"Access-Control-Allow-Credentials": string;
|
|
68
|
+
"Access-Control-Allow-Headers": string;
|
|
69
|
+
"Access-Control-Expose-Headers": string;
|
|
70
|
+
};
|
|
34
71
|
}
|
|
72
|
+
export {};
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import { parseURL, stringifyParsedURL, withQuery } from "ufo";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
1
|
+
import { parseURL, stringifyParsedURL, withQuery, withTrailingSlash } from "ufo";
|
|
2
|
+
import { fetchWP } from "../../node/utils/fetch-wp.js";
|
|
3
|
+
import { filterHeader } from "./utils/headers.js";
|
|
4
|
+
import { createUrlReplacer } from "./utils/replace-host.js";
|
|
5
|
+
import { pageCache, queryCache, swr } from "./utils/swr-cache.js";
|
|
6
|
+
const PROXY_RESPONSE_HEADERS = ["content-type", "set-cookie", /^x-/, "cache-control", /woocommerce/];
|
|
5
7
|
const PROXY_REQUEST_HEADERS = [
|
|
6
8
|
"content-type",
|
|
7
9
|
"accept",
|
|
@@ -11,28 +13,49 @@ const PROXY_REQUEST_HEADERS = [
|
|
|
11
13
|
"referer",
|
|
12
14
|
"user-agent",
|
|
13
15
|
"authorization",
|
|
16
|
+
"woocommerce-session",
|
|
14
17
|
];
|
|
18
|
+
const VARIES_HEADERS = ["Authorization", "woocommerce-session"];
|
|
19
|
+
let runtime;
|
|
15
20
|
export class ServerContext {
|
|
16
21
|
dev;
|
|
17
22
|
origin;
|
|
18
|
-
|
|
23
|
+
_urlReplacer;
|
|
24
|
+
rpcBases = [];
|
|
25
|
+
config;
|
|
26
|
+
static main;
|
|
19
27
|
constructor(conf) {
|
|
20
28
|
this.dev = conf.dev;
|
|
21
29
|
this.origin = conf.origin;
|
|
30
|
+
this.rpcBases = conf.rpcBases ?? [];
|
|
31
|
+
this.config = conf.config;
|
|
22
32
|
if (conf.replaceUrls) {
|
|
23
|
-
this.
|
|
33
|
+
this._urlReplacer = createUrlReplacer(conf.replaceUrls);
|
|
24
34
|
}
|
|
35
|
+
ServerContext.main = this;
|
|
36
|
+
}
|
|
37
|
+
replaceUrls(text, origin) {
|
|
38
|
+
if (this._urlReplacer) {
|
|
39
|
+
return this._urlReplacer(text, origin);
|
|
40
|
+
}
|
|
41
|
+
return text;
|
|
42
|
+
}
|
|
43
|
+
get runtime() {
|
|
44
|
+
return runtime;
|
|
45
|
+
}
|
|
46
|
+
static setRuntime(rt) {
|
|
47
|
+
runtime = rt;
|
|
25
48
|
}
|
|
26
49
|
getOriginUrl(url) {
|
|
27
50
|
const parsed = parseURL(url);
|
|
28
|
-
const parsedOrigin = parseURL(
|
|
51
|
+
const parsedOrigin = parseURL(this.origin);
|
|
29
52
|
parsed.host = parsedOrigin.host;
|
|
30
53
|
parsed.protocol = parsedOrigin.protocol;
|
|
31
54
|
return stringifyParsedURL(parsed);
|
|
32
55
|
}
|
|
33
56
|
async fetchOrigin(url, opts) {
|
|
34
57
|
url = this.getOriginUrl(url);
|
|
35
|
-
const response = await
|
|
58
|
+
const response = await fetchWP(url, {
|
|
36
59
|
...opts,
|
|
37
60
|
headers: {
|
|
38
61
|
"Content-Type": "application/json",
|
|
@@ -50,8 +73,8 @@ export class ServerContext {
|
|
|
50
73
|
}
|
|
51
74
|
});
|
|
52
75
|
let text = await response.text();
|
|
53
|
-
if (opts?.replaceUrls
|
|
54
|
-
text = this.replaceUrls(text);
|
|
76
|
+
if (opts?.replaceUrls) {
|
|
77
|
+
text = this.replaceUrls(text, opts.newOrigin);
|
|
55
78
|
}
|
|
56
79
|
return new Response(text, {
|
|
57
80
|
status: response.status,
|
|
@@ -60,21 +83,93 @@ export class ServerContext {
|
|
|
60
83
|
});
|
|
61
84
|
}
|
|
62
85
|
async fetchRouteData(req) {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
86
|
+
/**
|
|
87
|
+
* Calculcate the cache key.
|
|
88
|
+
* For route data, the cache key is the pathname.
|
|
89
|
+
* TODO: Potential support for Vercel draft mode.
|
|
90
|
+
*/
|
|
91
|
+
let cacheKey = "fetchRouteData:" + req.pathname;
|
|
92
|
+
const result = await swr({
|
|
93
|
+
key: cacheKey,
|
|
94
|
+
cache: pageCache,
|
|
95
|
+
forceFresh: this.dev,
|
|
96
|
+
getFreshValue: async (ctx) => {
|
|
97
|
+
ctx.metadata.createdTime;
|
|
98
|
+
const fetchUrl = withQuery(withTrailingSlash(req.pathname), {
|
|
99
|
+
_props: "1",
|
|
100
|
+
_ssr: "1",
|
|
101
|
+
_debug: this.dev ? "1" : undefined,
|
|
102
|
+
});
|
|
103
|
+
const result = await this.fetchOrigin(fetchUrl, {
|
|
104
|
+
cache: "no-cache",
|
|
105
|
+
replaceUrls: true,
|
|
106
|
+
newOrigin: req.newOrigin,
|
|
107
|
+
headers: {
|
|
108
|
+
"Content-Type": "application/json",
|
|
109
|
+
Accept: "application/json",
|
|
110
|
+
},
|
|
111
|
+
redirect: "manual",
|
|
112
|
+
});
|
|
113
|
+
const preferredCacheDuration = parseInt(result.headers.get("x-ed-cache-duration") ?? "");
|
|
114
|
+
if (isFinite(preferredCacheDuration)) {
|
|
115
|
+
ctx.metadata.ttl = preferredCacheDuration * 1000;
|
|
116
|
+
}
|
|
117
|
+
let resultStatus = result.status;
|
|
118
|
+
let resultHeaders = result.headers;
|
|
119
|
+
let resultData = await result.json();
|
|
120
|
+
// Special case for redirects
|
|
121
|
+
if (result.headers.get("location")) {
|
|
122
|
+
let location = result.headers.get("location");
|
|
123
|
+
let status = result.status;
|
|
124
|
+
if (this.replaceUrls) {
|
|
125
|
+
location = this.replaceUrls(location);
|
|
126
|
+
}
|
|
127
|
+
resultHeaders.delete("location");
|
|
128
|
+
resultData = {
|
|
129
|
+
redirect: location,
|
|
130
|
+
status: status,
|
|
131
|
+
data: "",
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
if (resultData && typeof resultData === "object") {
|
|
135
|
+
resultData.__generated = new Date().toISOString();
|
|
136
|
+
}
|
|
137
|
+
return {
|
|
138
|
+
status: resultStatus,
|
|
139
|
+
headers: resultHeaders,
|
|
140
|
+
data: JSON.stringify(resultData),
|
|
141
|
+
};
|
|
142
|
+
},
|
|
68
143
|
});
|
|
69
|
-
return
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
144
|
+
return new Response(result.data, {
|
|
145
|
+
status: result.status,
|
|
146
|
+
headers: result.headers,
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
async fetchAppData() {
|
|
150
|
+
const data = await swr({
|
|
151
|
+
key: "fetchAppData",
|
|
152
|
+
cache: pageCache,
|
|
153
|
+
getFreshValue: async (ctx) => {
|
|
154
|
+
const response = await this.fetchOrigin("/_appdata", {
|
|
155
|
+
cache: "no-cache",
|
|
156
|
+
replaceUrls: true,
|
|
157
|
+
headers: {
|
|
158
|
+
"Content-Type": "application/json",
|
|
159
|
+
Accept: "application/json",
|
|
160
|
+
},
|
|
161
|
+
});
|
|
162
|
+
const result = await response.json();
|
|
163
|
+
const preferredCacheDuration = parseInt(response.headers.get("x-ed-cache-duration") ?? "");
|
|
164
|
+
if (isFinite(preferredCacheDuration)) {
|
|
165
|
+
ctx.metadata.ttl = preferredCacheDuration * 1000;
|
|
166
|
+
}
|
|
167
|
+
result.__generated = new Date().toISOString();
|
|
168
|
+
return result;
|
|
76
169
|
},
|
|
170
|
+
forceFresh: this.dev,
|
|
77
171
|
});
|
|
172
|
+
return data;
|
|
78
173
|
}
|
|
79
174
|
extractRequestHeaders(req) {
|
|
80
175
|
const headers = {};
|
|
@@ -89,14 +184,49 @@ export class ServerContext {
|
|
|
89
184
|
}
|
|
90
185
|
async fetchNamedQuery(req) {
|
|
91
186
|
const url = `/wp-json/ed/v1/query/${req.name}?params=${encodeURIComponent(JSON.stringify(req.params))}`;
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
187
|
+
const key = `fetchNamedQuery:${req.name}:${JSON.stringify(req.params)}`;
|
|
188
|
+
const fetch = async () => {
|
|
189
|
+
const result = await this.fetchOrigin(url, {
|
|
190
|
+
cache: "no-cache",
|
|
191
|
+
replaceUrls: true,
|
|
192
|
+
headers: {
|
|
193
|
+
...this.extractRequestHeaders(req.headers),
|
|
194
|
+
"Content-Type": "application/json",
|
|
195
|
+
Accept: "application/json",
|
|
196
|
+
},
|
|
197
|
+
});
|
|
198
|
+
const preferredCacheDuration = parseInt(result.headers.get("x-ed-cache-duration") ?? "");
|
|
199
|
+
let resultStatus = result.status;
|
|
200
|
+
let resultHeaders = result.headers;
|
|
201
|
+
let resultData = await result.json();
|
|
202
|
+
if (resultData && typeof resultData === "object") {
|
|
203
|
+
resultData.__generated = new Date().toISOString();
|
|
204
|
+
}
|
|
205
|
+
return {
|
|
206
|
+
status: resultStatus,
|
|
207
|
+
headers: resultHeaders,
|
|
208
|
+
data: JSON.stringify(resultData),
|
|
209
|
+
cacheTime: isFinite(preferredCacheDuration) ? preferredCacheDuration * 1000 : undefined,
|
|
210
|
+
};
|
|
211
|
+
};
|
|
212
|
+
// If headers like 'Authorization' are set, then we shouldn't cache.
|
|
213
|
+
const hasVariedHeaders = VARIES_HEADERS.some((key) => !!req.headers[key]);
|
|
214
|
+
// Get the result, either from cache or by fetching.
|
|
215
|
+
const result = hasVariedHeaders
|
|
216
|
+
? await fetch()
|
|
217
|
+
: await swr({
|
|
218
|
+
key,
|
|
219
|
+
cache: queryCache,
|
|
220
|
+
forceFresh: this.dev,
|
|
221
|
+
getFreshValue: async (ctx) => {
|
|
222
|
+
const result = await fetch();
|
|
223
|
+
ctx.metadata.ttl = result.cacheTime;
|
|
224
|
+
return result;
|
|
225
|
+
},
|
|
226
|
+
});
|
|
227
|
+
return new Response(result.data, {
|
|
228
|
+
status: result.status,
|
|
229
|
+
headers: result.headers,
|
|
100
230
|
});
|
|
101
231
|
}
|
|
102
232
|
async fetchMutation(req) {
|
|
@@ -113,4 +243,40 @@ export class ServerContext {
|
|
|
113
243
|
body: JSON.stringify(req.body),
|
|
114
244
|
});
|
|
115
245
|
}
|
|
246
|
+
get allowedCorsOrigins() {
|
|
247
|
+
let result = [];
|
|
248
|
+
if (this.config.serverless.endpoints) {
|
|
249
|
+
result.push(...Object.keys(this.config.serverless.endpoints));
|
|
250
|
+
result.push(...Object.values(this.config.serverless.endpoints));
|
|
251
|
+
result = result.filter((origin) => origin !== "*");
|
|
252
|
+
}
|
|
253
|
+
if (this.config.serverless.cors?.origins) {
|
|
254
|
+
result.push(...this.config.serverless.cors.origins);
|
|
255
|
+
}
|
|
256
|
+
return result;
|
|
257
|
+
}
|
|
258
|
+
getCorsOrigin(originHeader) {
|
|
259
|
+
const parsed = parseURL(originHeader);
|
|
260
|
+
if (this.allowedCorsOrigins.includes(parsed.host)) {
|
|
261
|
+
return originHeader;
|
|
262
|
+
}
|
|
263
|
+
if (this.allowedCorsOrigins.includes("*")) {
|
|
264
|
+
return "*";
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
getCorsHeaders(origin) {
|
|
268
|
+
if (!origin)
|
|
269
|
+
return {};
|
|
270
|
+
const allowedOrigin = this.getCorsOrigin(origin);
|
|
271
|
+
if (allowedOrigin) {
|
|
272
|
+
return {
|
|
273
|
+
"Access-Control-Allow-Methods": "OPTIONS,GET,HEAD,PUT,PATCH,POST,DELETE",
|
|
274
|
+
"Access-Control-Allow-Origin": allowedOrigin,
|
|
275
|
+
"Access-Control-Allow-Credentials": "true",
|
|
276
|
+
"Access-Control-Allow-Headers": "*",
|
|
277
|
+
"Access-Control-Expose-Headers": "*",
|
|
278
|
+
};
|
|
279
|
+
}
|
|
280
|
+
return {};
|
|
281
|
+
}
|
|
116
282
|
}
|
|
@@ -2,7 +2,7 @@ export function createUrlReplacer(conf) {
|
|
|
2
2
|
// Create a regular expression to match the URL
|
|
3
3
|
// Note that that the regex doesn't necessarily match the entire URL
|
|
4
4
|
const lookup = new RegExp(conf.from.replace(/https?[:\\\/]+/, "https?[:\\/\\\\]+") + "([a-z0-9\\-_/\\\\]+)", "ig");
|
|
5
|
-
return (text) => {
|
|
5
|
+
return (text, newOrigin) => {
|
|
6
6
|
return text.replace(lookup, (url) => {
|
|
7
7
|
// Strip out the origin, to create a relative path
|
|
8
8
|
const path = url.replace(/https?:[\/\\]+[^\/\\]+/, "");
|
|
@@ -18,10 +18,18 @@ export function createUrlReplacer(conf) {
|
|
|
18
18
|
return url;
|
|
19
19
|
}
|
|
20
20
|
else {
|
|
21
|
-
|
|
21
|
+
break;
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
|
+
if (newOrigin) {
|
|
26
|
+
if (isEscaped) {
|
|
27
|
+
return newOrigin.replace(/\//g, "\\/") + path;
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
return newOrigin + path;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
25
33
|
return path;
|
|
26
34
|
// if (path.startsWith("/wp-content/uploads/")) {
|
|
27
35
|
// if (!conf.ignoreUploads) {
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { LRUCache } from "lru-cache";
|
|
2
|
+
import { cachified, totalTtl } from "@epic-web/cachified";
|
|
3
|
+
function createCache() {
|
|
4
|
+
const lruInstance = new LRUCache({ max: 1000 });
|
|
5
|
+
const lru = {
|
|
6
|
+
set(key, value) {
|
|
7
|
+
const ttl = totalTtl(value?.metadata);
|
|
8
|
+
return lruInstance.set(key, value, {
|
|
9
|
+
ttl: ttl === Infinity ? undefined : ttl,
|
|
10
|
+
start: value?.metadata?.createdTime,
|
|
11
|
+
});
|
|
12
|
+
},
|
|
13
|
+
get(key) {
|
|
14
|
+
return lruInstance.get(key);
|
|
15
|
+
},
|
|
16
|
+
delete(key) {
|
|
17
|
+
return lruInstance.delete(key);
|
|
18
|
+
},
|
|
19
|
+
};
|
|
20
|
+
return lru;
|
|
21
|
+
}
|
|
22
|
+
export const pageCache = createCache();
|
|
23
|
+
export const queryCache = createCache();
|
|
24
|
+
export function swr(args) {
|
|
25
|
+
return cachified({
|
|
26
|
+
ttl: args.ttl ?? 10_000,
|
|
27
|
+
swr: 3600_000,
|
|
28
|
+
fallbackToCache: 15_000,
|
|
29
|
+
...args,
|
|
30
|
+
});
|
|
31
|
+
}
|