eddev 2.0.0-beta.56 → 2.0.0-beta.58
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/spa-root.js +4 -5
- package/dist/app/entry/ssr-root-client.js +4 -5
- package/dist/app/entry/ssr-root.js +2 -3
- package/dist/app/lib/blocks/editor/EditorSupport.js +2 -3
- package/dist/app/lib/blocks/editor/installGutenbergHooks.js +7 -4
- package/dist/app/lib/hooks/queryUtils.d.ts +27 -0
- package/dist/app/lib/hooks/queryUtils.js +28 -8
- 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 +1 -0
- package/dist/app/lib/internal/index.js +1 -0
- package/dist/app/server/index.d.ts +1 -0
- package/dist/app/server/index.js +1 -0
- package/dist/app/server/proxy-wp-admin.d.ts +1 -2
- package/dist/app/server/proxy-wp-admin.js +3 -1
- package/dist/app/server/render-ssr-page.d.ts +11 -5
- package/dist/app/server/render-ssr-page.js +75 -6
- 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 +1 -0
- package/dist/app/server/server-context.js +2 -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 +1 -1
- package/dist/app/utils/BlockErrorBoundary.js +2 -2
- package/dist/app/utils/RouteErrorBoundary.d.ts +1 -1
- package/dist/app/utils/RouteErrorBoundary.js +2 -2
- 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 +34 -0
- package/dist/node/cli/version.d.ts +1 -1
- package/dist/node/cli/version.js +1 -1
- package/dist/node/compiler/dev-server.js +1 -0
- package/dist/node/compiler/get-vite-config.js +1 -1
- package/dist/node/compiler/vinxi-app.d.ts +1 -0
- package/dist/node/compiler/vinxi-app.js +42 -5
- package/dist/node/compiler/vinxi-codegen.js +124 -41
- package/dist/node/graphql/graphql-codegen.d.ts +1 -0
- package/dist/node/graphql/graphql-codegen.js +42 -1
- 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/project.d.ts +2 -0
- package/dist/node/project/project.js +3 -0
- package/package.json +5 -1
- package/types.app.d.ts +2 -0
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { QueryClientProvider } from "@tanstack/react-query";
|
|
3
|
-
import { BrowserRouter } from "../lib/routing/components/BrowserRouter.js";
|
|
4
|
-
import { getQueryClient } from "../utils/query-client.js";
|
|
5
|
-
import { DevUILoader } from "../lib/devtools/loader.js";
|
|
6
2
|
import { Suspense } from "react";
|
|
3
|
+
import { DevUILoader } from "../lib/devtools/loader.js";
|
|
4
|
+
import { BrowserRouter } from "../lib/routing/components/BrowserRouter.js";
|
|
5
|
+
import { APIProvider } from "../utils/APIProvider.js";
|
|
7
6
|
export function SPARoot() {
|
|
8
|
-
return (_jsxs(
|
|
7
|
+
return (_jsxs(APIProvider, { children: [_jsx(Suspense, { children: _jsx(BrowserRouter, {}) }), _jsx(DevUILoader, {})] }));
|
|
9
8
|
}
|
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
-
import { QueryClientProvider } from "@tanstack/react-query";
|
|
3
2
|
import { Suspense, useEffect, useState } from "react";
|
|
3
|
+
import { useSnapshot } from "valtio";
|
|
4
4
|
import { DevUILoader } from "../lib/devtools/loader.js";
|
|
5
5
|
import { BrowserRouter } from "../lib/routing/components/BrowserRouter.js";
|
|
6
|
-
import { getQueryClient } from "../utils/query-client.js";
|
|
7
|
-
import { MetaTags } from "./MetaTags.js";
|
|
8
|
-
import { useSnapshot } from "valtio";
|
|
9
6
|
import { clientMetaTags } from "../lib/routing/context.js";
|
|
7
|
+
import { APIProvider } from "../utils/APIProvider.js";
|
|
8
|
+
import { MetaTags } from "./MetaTags.js";
|
|
10
9
|
export function SSRClientRoot(props) {
|
|
11
|
-
return (_jsxs("html", { lang: "en", children: [_jsxs("head", { children: [_jsx(DynamicMetaTags, { tags: props.metaTags }), _jsx(Trackers, { position: "head" }), props.assets] }), _jsxs("body", { children: [_jsx(Trackers, { position: "body" }), _jsxs(
|
|
10
|
+
return (_jsxs("html", { lang: "en", children: [_jsxs("head", { children: [_jsx(DynamicMetaTags, { tags: props.metaTags }), _jsx(Trackers, { position: "head" }), props.assets] }), _jsxs("body", { children: [_jsx(Trackers, { position: "body" }), _jsxs(APIProvider, { children: [_jsx(Suspense, { children: _jsx(BrowserRouter, {}) }), _jsx(DevUILoader, {})] }), _jsx(Trackers, { position: "footer" })] })] }));
|
|
12
11
|
}
|
|
13
12
|
function DynamicMetaTags(props) {
|
|
14
13
|
const dynamicTags = useSnapshot(clientMetaTags).tags;
|
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { QueryClientProvider } from "@tanstack/react-query";
|
|
3
2
|
import { Suspense } from "react";
|
|
4
3
|
import { SSRRouter } from "../lib/routing/components/SSRRouter.js";
|
|
5
4
|
import { getRouteMeta, normalizeRoute } from "../lib/routing/utils.js";
|
|
6
|
-
import {
|
|
5
|
+
import { APIProvider } from "../utils/APIProvider.js";
|
|
7
6
|
import { MetaTags } from "./MetaTags.js";
|
|
8
7
|
export function SSRRoot(props) {
|
|
9
8
|
const loader = props.loader;
|
|
10
9
|
loader.setAppData(props.initialData.appData.data);
|
|
11
10
|
loader.populateRouteData(props.pathname, props.initialData);
|
|
12
|
-
return (_jsxs("html", { lang: "en", children: [_jsxs("head", { children: [_jsx(MetaTags, { tags: props.metaTags }), props.assets] }), _jsx("body", { children: _jsx(
|
|
11
|
+
return (_jsxs("html", { lang: "en", children: [_jsxs("head", { children: [_jsx(MetaTags, { tags: props.metaTags }), props.assets] }), _jsx("body", { children: _jsx(APIProvider, { children: _jsx(Suspense, { children: _jsx(SSRRouter, { loader: loader, route: normalizeRoute({
|
|
13
12
|
id: "initial",
|
|
14
13
|
component: loader.getRouteComponent(props.initialData.view),
|
|
15
14
|
key: "",
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import { QueryClientProvider } from "@tanstack/react-query";
|
|
3
2
|
import { createContext, Suspense, useContext } from "react";
|
|
4
|
-
import { getQueryClient } from "../../../utils/query-client.js";
|
|
5
3
|
import { blockManifestReader } from "../../internal/read-block-manifest.js";
|
|
4
|
+
import { APIProvider } from "../../../utils/APIProvider.js";
|
|
6
5
|
import { ErrorBoundaryEditor } from "./ErrorBoundaryEditor.js";
|
|
7
6
|
export const BlockContext = createContext(undefined);
|
|
8
7
|
export function EditableBlock({ payload }) {
|
|
@@ -15,5 +14,5 @@ export function EditableBlock({ payload }) {
|
|
|
15
14
|
const BlockComponent = getBlock();
|
|
16
15
|
if (!BlockComponent)
|
|
17
16
|
return _jsx("div", { children: "Unable to load block component" });
|
|
18
|
-
return (_jsx(ErrorBoundaryEditor, { children: _jsx(
|
|
17
|
+
return (_jsx(ErrorBoundaryEditor, { children: _jsx(APIProvider, { children: _jsx(Suspense, { children: _jsx(BlockComponent, { ...payload }) }) }) }));
|
|
19
18
|
}
|
|
@@ -74,15 +74,18 @@ export function installEDGutenbergHooks() {
|
|
|
74
74
|
;
|
|
75
75
|
wp.data.dispatch("core/block-editor").setTemplateValidity(true);
|
|
76
76
|
}, []);
|
|
77
|
-
const children = wp.data.useSelect((select) => {
|
|
78
|
-
const { getBlock, getBlockOrder } = select("core/block-editor");
|
|
77
|
+
const { children, index } = wp.data.useSelect((select) => {
|
|
78
|
+
const { getBlock, getBlockOrder, getBlockIndex } = select("core/block-editor");
|
|
79
79
|
const innerBlockIDs = getBlockOrder(props.clientId);
|
|
80
80
|
const children = innerBlockIDs.map((id) => {
|
|
81
81
|
return getBlock(id);
|
|
82
82
|
});
|
|
83
|
-
return
|
|
83
|
+
return {
|
|
84
|
+
children,
|
|
85
|
+
index: getBlockIndex(props.clientId),
|
|
86
|
+
};
|
|
84
87
|
}, []);
|
|
85
|
-
return (_jsx(BlockContext.Provider, { value: { name, props }, children: _jsx(InlineEditingContextProvider, { values: props.attributes.inline || {}, innerBlocks: children, block: [name, props], index: -1, onChange: (attrs) => {
|
|
88
|
+
return (_jsx(BlockContext.Provider, { value: { name, props }, children: _jsx(InlineEditingContextProvider, { values: props.attributes.inline || {}, innerBlocks: children, block: [name, props], index: index ?? -1, onChange: (attrs) => {
|
|
86
89
|
props.setAttributes({ ...props.attributes, inline: attrs });
|
|
87
90
|
}, insertBlocksAfter: props.insertBlocksAfter, children: edit.call(self, props) }) }));
|
|
88
91
|
};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { FetchQueryOptions, UndefinedInitialDataInfiniteOptions, UndefinedInitialDataOptions, UseInfiniteQueryResult, UseMutationOptions, UseMutationResult, UseQueryResult } from "@tanstack/react-query";
|
|
2
|
+
import { TRPCClientError } from "@trpc/client";
|
|
2
3
|
type OptionalMaybes<T> = T extends any[] ? T : T extends {
|
|
3
4
|
[key: string]: any;
|
|
4
5
|
} ? {
|
|
@@ -53,4 +54,30 @@ export type UseMutationFunction<TData, TArgs> = ((options?: Omit<UseMutationOpti
|
|
|
53
54
|
}) => Promise<TData>;
|
|
54
55
|
};
|
|
55
56
|
export declare function createUseMutation<TData extends any, TArgs extends MaybeVars>(init: CreateUseQueryOptions): UseMutationFunction<TData, TArgs>;
|
|
57
|
+
type RPCQueryName = RPCRouter["queries"]["key"];
|
|
58
|
+
type RPCQueryResult<T> = Extract<RPCRouter["queries"], {
|
|
59
|
+
key: T;
|
|
60
|
+
}>["output"];
|
|
61
|
+
type RPCQueryInput<T> = Extract<RPCRouter["queries"], {
|
|
62
|
+
key: T;
|
|
63
|
+
}>["input"];
|
|
64
|
+
type RPCQueryError<T> = TRPCClientError<Extract<RPCRouter["queries"], {
|
|
65
|
+
key: T;
|
|
66
|
+
}>["procedure"]>;
|
|
67
|
+
export declare function useRPCQuery<TName extends RPCQueryName>(key: TName, args: OptionalMaybes<RPCQueryInput<TName>>, options?: Omit<UndefinedInitialDataOptions<RPCQueryResult<TName>, RPCQueryError<TName>, RPCQueryResult<TName>>, "queryKey" | "queryFn"> & {
|
|
68
|
+
headers?: Record<string, string>;
|
|
69
|
+
}): UseQueryResult<RPCQueryResult<TName>, RPCQueryError<TName>>;
|
|
70
|
+
type RPCMutationName = RPCRouter["mutations"]["key"];
|
|
71
|
+
type RPCMutationResult<T> = Extract<RPCRouter["mutations"], {
|
|
72
|
+
key: T;
|
|
73
|
+
}>["output"];
|
|
74
|
+
type RPCMutationInput<T> = Extract<RPCRouter["mutations"], {
|
|
75
|
+
key: T;
|
|
76
|
+
}>["input"];
|
|
77
|
+
type RPCMutationError<T> = TRPCClientError<Extract<RPCRouter["mutations"], {
|
|
78
|
+
key: T;
|
|
79
|
+
}>["procedure"]>;
|
|
80
|
+
export declare function useRPCMutation<TName extends RPCMutationName>(key: TName, options?: Omit<UseMutationOptions<RPCMutationResult<TName>, RPCMutationError<TName>, RPCMutationInput<TName>>, "mutationFn"> & {
|
|
81
|
+
headers?: Record<string, string>;
|
|
82
|
+
}): UseMutationResult<RPCMutationResult<TName>, RPCMutationError<TName>, RPCMutationInput<TName>>;
|
|
56
83
|
export {};
|
|
@@ -2,6 +2,7 @@ import { useInfiniteQuery, useMutation, useQuery, } from "@tanstack/react-query"
|
|
|
2
2
|
import { useEffect, useState } from "react";
|
|
3
3
|
import { joinURL } from "ufo";
|
|
4
4
|
import { getQueryClient } from "../../utils/query-client.js";
|
|
5
|
+
import { getRPCClient } from "../../utils/trpc-client.js";
|
|
5
6
|
import { apiConfig } from "../runtime/apiConfig.js";
|
|
6
7
|
class QueryError extends Error {
|
|
7
8
|
name = "QueryError";
|
|
@@ -52,8 +53,8 @@ export function createUseQuery(init) {
|
|
|
52
53
|
const hook = (args, options) => {
|
|
53
54
|
const customKey = apiConfig.customQueryKey;
|
|
54
55
|
return useQuery({
|
|
55
|
-
queryKey: [init.name, args, options?.headers,
|
|
56
|
-
queryFn: (args) => fetchGETQuery(init.name, args.queryKey[
|
|
56
|
+
queryKey: ["query", init.name, args, options?.headers, customKey],
|
|
57
|
+
queryFn: (args) => fetchGETQuery(init.name, args.queryKey[2] ? JSON.stringify(args.queryKey[2]) : "", {
|
|
57
58
|
headers: options?.headers,
|
|
58
59
|
}),
|
|
59
60
|
...options,
|
|
@@ -62,8 +63,8 @@ export function createUseQuery(init) {
|
|
|
62
63
|
hook.fetch = async (args, options) => {
|
|
63
64
|
const customKey = apiConfig.customQueryKey;
|
|
64
65
|
return getQueryClient().fetchQuery({
|
|
65
|
-
queryKey: [init.name, args, options?.headers,
|
|
66
|
-
queryFn: (args) => fetchGETQuery(init.name, args.queryKey[
|
|
66
|
+
queryKey: ["query", init.name, args, options?.headers, customKey],
|
|
67
|
+
queryFn: (args) => fetchGETQuery(init.name, args.queryKey[2] ? JSON.stringify(args.queryKey[2]) : "", {
|
|
67
68
|
headers: options?.headers,
|
|
68
69
|
}),
|
|
69
70
|
...options,
|
|
@@ -99,11 +100,11 @@ export function createUseInfiniteQuery(init) {
|
|
|
99
100
|
});
|
|
100
101
|
}, []);
|
|
101
102
|
return useInfiniteQuery({
|
|
102
|
-
queryKey: [init.name, args, init.defaultLimit, options?.headers,
|
|
103
|
+
queryKey: ["query", init.name, args, init.defaultLimit, options?.headers, customKey],
|
|
103
104
|
queryFn: async (args) => {
|
|
104
105
|
const finalArgs = {
|
|
105
|
-
limit: args.queryKey[
|
|
106
|
-
...(args.queryKey[
|
|
106
|
+
limit: args.queryKey[3],
|
|
107
|
+
...(args.queryKey[2] ?? {}),
|
|
107
108
|
cursor: args.pageParam,
|
|
108
109
|
};
|
|
109
110
|
const data = await fetchGETQuery(init.name, JSON.stringify(finalArgs), {
|
|
@@ -181,7 +182,7 @@ const fetchMutation = async (name, params, opts) => {
|
|
|
181
182
|
export function createUseMutation(init) {
|
|
182
183
|
const hook = (options) => {
|
|
183
184
|
return useMutation({
|
|
184
|
-
mutationKey: [init.name],
|
|
185
|
+
mutationKey: ["mutation", init.name],
|
|
185
186
|
mutationFn: (args) => fetchMutation(init.name, args, {
|
|
186
187
|
headers: options?.headers,
|
|
187
188
|
}),
|
|
@@ -195,3 +196,22 @@ export function createUseMutation(init) {
|
|
|
195
196
|
};
|
|
196
197
|
return hook;
|
|
197
198
|
}
|
|
199
|
+
// @ts-ignore
|
|
200
|
+
export function useRPCQuery(key, args, options) {
|
|
201
|
+
return useQuery({
|
|
202
|
+
queryKey: ["rpcQuery", key, args],
|
|
203
|
+
queryFn: async (args) => {
|
|
204
|
+
return getRPCClient().query(key, args.queryKey[2]);
|
|
205
|
+
},
|
|
206
|
+
...options,
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
export function useRPCMutation(key, options) {
|
|
210
|
+
return useMutation({
|
|
211
|
+
mutationKey: ["rpcMutation", key],
|
|
212
|
+
mutationFn: async (args) => {
|
|
213
|
+
return getRPCClient().mutation(key, args);
|
|
214
|
+
},
|
|
215
|
+
...options,
|
|
216
|
+
});
|
|
217
|
+
}
|
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
export declare const useRPCQuery: RPCUseQuery;
|
|
2
|
-
export declare const useRPCMutation: RPCUseMutation;
|
|
3
|
-
export declare const useRPCInfiniteQuery: RPCUseInfiniteQuery;
|
|
4
|
-
export declare const rpcClient: null;
|
|
5
1
|
export type UseRPCMutationResult = any;
|
|
6
2
|
export type UseRPCQueryResult = any;
|
|
7
3
|
export type UseRPCInfiniteQueryResult = any;
|
|
@@ -1,9 +1,2 @@
|
|
|
1
|
-
const trpc = {}
|
|
2
|
-
// @ts-ignore
|
|
3
|
-
export const useRPCQuery = trpc.useQuery;
|
|
4
|
-
// @ts-ignore
|
|
5
|
-
export const useRPCMutation = trpc.useMutation;
|
|
6
|
-
// @ts-ignore
|
|
7
|
-
export const useRPCInfiniteQuery = trpc.useInfiniteQuery;
|
|
8
|
-
export const rpcClient = null;
|
|
1
|
+
// const trpc = {}
|
|
9
2
|
export const RPCClientError = null;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { AnyTRPCMutationProcedure, AnyTRPCProcedure, AnyTRPCQueryProcedure, AnyTRPCSubscriptionProcedure, inferProcedureInput, inferProcedureOutput } from "@trpc/server";
|
|
2
|
+
type RouterTable = Record<string, Record<string, AnyTRPCProcedure> | AnyTRPCProcedure>;
|
|
3
|
+
type RouterEntry<T extends RouterTable, U extends AnyTRPCProcedure, P extends string = ""> = {
|
|
4
|
+
[K in keyof T]: K extends string ? T[K] extends U ? {
|
|
5
|
+
key: `${P}${K}`;
|
|
6
|
+
input: inferProcedureInput<T[K]>;
|
|
7
|
+
output: inferProcedureOutput<T[K]>;
|
|
8
|
+
procedure: T[K] extends AnyTRPCProcedure ? T[K] : never;
|
|
9
|
+
} : T[K] extends Record<string, U> ? RouterEntry<T[K], U, `${K}.`> : never : never;
|
|
10
|
+
}[keyof T];
|
|
11
|
+
type RouterTypes<T extends RouterTable> = {
|
|
12
|
+
queries: RouterEntry<T, AnyTRPCQueryProcedure>;
|
|
13
|
+
mutations: RouterEntry<T, AnyTRPCMutationProcedure>;
|
|
14
|
+
subscriptions: RouterEntry<T, AnyTRPCSubscriptionProcedure>;
|
|
15
|
+
};
|
|
16
|
+
export declare function finalizeRPCRouter<T extends RouterTable>(router: T): RouterTypes<T>;
|
|
17
|
+
export {};
|
package/dist/app/server/index.js
CHANGED
|
@@ -1,3 +1,2 @@
|
|
|
1
1
|
import { EventHandlerRequest, H3Event } from "vinxi/http";
|
|
2
|
-
|
|
3
|
-
export declare function proxyWpAdmin(event: H3Event<EventHandlerRequest>, serverContext: ServerContext): Promise<Response>;
|
|
2
|
+
export declare function proxyWpAdmin(event: H3Event<EventHandlerRequest>): Promise<Response>;
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
/// <reference types="vinxi/types/server" />
|
|
2
2
|
import { splitSetCookieString } from "cookie-es";
|
|
3
3
|
import { getProxyRequestHeaders, getRequestURL, getWebRequest } from "vinxi/http";
|
|
4
|
-
|
|
4
|
+
import { ServerContext } from "./server-context.js";
|
|
5
|
+
export async function proxyWpAdmin(event) {
|
|
6
|
+
const serverContext = ServerContext.main;
|
|
5
7
|
const replaceUrls = serverContext.replaceUrls;
|
|
6
8
|
const req = getWebRequest(event);
|
|
7
9
|
const proxyUrl = serverContext.getOriginUrl(getRequestURL(event).href);
|
|
@@ -1,5 +1,11 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
}
|
|
1
|
+
import type { RouteDataWithTrackers } from "../lib/routing/types.js";
|
|
2
|
+
type SSRArgs = {
|
|
3
|
+
pathname: string;
|
|
4
|
+
initialData: RouteDataWithTrackers;
|
|
5
|
+
};
|
|
6
|
+
export declare function getSsrStream(args: SSRArgs): Promise<ReadableStream<Uint8Array>>;
|
|
7
|
+
type RenderArgs = {
|
|
8
|
+
pathname: string;
|
|
9
|
+
};
|
|
10
|
+
export declare function renderPage(args: RenderArgs): Promise<Response>;
|
|
11
|
+
export {};
|
|
@@ -4,10 +4,12 @@ import { Suspense } from "react";
|
|
|
4
4
|
import { renderToPipeableStream } from "react-dom/server";
|
|
5
5
|
import { SSRRoot } from "../entry/ssr-root.js";
|
|
6
6
|
import { RouteLoader } from "../lib/routing/loader.js";
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
import { ServerContext } from "./server-context.js";
|
|
8
|
+
import { Writable } from "stream";
|
|
9
|
+
export async function getSsrStream(args) {
|
|
10
|
+
const clientManifest = ServerContext.main.runtime.getManifest("client");
|
|
9
11
|
const assets = await clientManifest.inputs[clientManifest.handler].assets();
|
|
10
|
-
const jsx = (_jsx(SSRRoot, { assets: _jsx(Suspense, { children: assets.map((m) => renderAsset(m)) }), metaTags: initialData?.meta?.head || [], pathname: pathname, initialData: initialData, loader: new RouteLoader() }));
|
|
12
|
+
const jsx = (_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() }));
|
|
11
13
|
const stream = await new Promise(async (resolve, reject) => {
|
|
12
14
|
// console.log("Rendering to pipable")
|
|
13
15
|
const stream = renderToPipeableStream(jsx, {
|
|
@@ -17,15 +19,82 @@ export async function renderPageToSSRStream(pathname, initialData, serverContext
|
|
|
17
19
|
},
|
|
18
20
|
onShellError(err) {
|
|
19
21
|
console.log("onShellError", err);
|
|
20
|
-
|
|
22
|
+
reject(err);
|
|
21
23
|
},
|
|
22
24
|
onError(err, errInfo) {
|
|
23
25
|
console.log("Error occurred after shell ready", err, errInfo);
|
|
24
26
|
console.error(err);
|
|
25
27
|
},
|
|
26
28
|
bootstrapModules: [clientManifest.inputs[clientManifest.handler].output.path],
|
|
27
|
-
bootstrapScriptContent: `window.manifest = ${JSON.stringify(await clientManifest.json())};\nwindow._PAGE_DATA = ${JSON.stringify(initialData)};\nwindow._TRACKERS = ${JSON.stringify(initialData.trackers)}`,
|
|
29
|
+
bootstrapScriptContent: `window.manifest = ${JSON.stringify(await clientManifest.json())};\nwindow._PAGE_DATA = ${JSON.stringify(args.initialData)};\nwindow._TRACKERS = ${JSON.stringify(args.initialData.trackers)}`,
|
|
28
30
|
});
|
|
29
31
|
});
|
|
30
|
-
return
|
|
32
|
+
return new ReadableStream({
|
|
33
|
+
async start(controller) {
|
|
34
|
+
const writableStream = new Writable({
|
|
35
|
+
emitClose: true,
|
|
36
|
+
write(chunk, encoding, callback) {
|
|
37
|
+
controller.enqueue(chunk);
|
|
38
|
+
callback();
|
|
39
|
+
},
|
|
40
|
+
final(callback) {
|
|
41
|
+
controller.close();
|
|
42
|
+
callback();
|
|
43
|
+
},
|
|
44
|
+
});
|
|
45
|
+
stream.pipe(writableStream);
|
|
46
|
+
},
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
export async function renderPage(args) {
|
|
50
|
+
const serverContext = ServerContext.main;
|
|
51
|
+
let headers = new Headers();
|
|
52
|
+
let responseInit = {
|
|
53
|
+
headers,
|
|
54
|
+
};
|
|
55
|
+
try {
|
|
56
|
+
const [{ appData, trackers }, response] = await Promise.all([
|
|
57
|
+
serverContext.fetchAppData(),
|
|
58
|
+
serverContext.fetchRouteData({
|
|
59
|
+
pathname: args.pathname,
|
|
60
|
+
withAppData: false,
|
|
61
|
+
headers: {},
|
|
62
|
+
query: {},
|
|
63
|
+
}),
|
|
64
|
+
]);
|
|
65
|
+
let data;
|
|
66
|
+
try {
|
|
67
|
+
data = await response.json();
|
|
68
|
+
data.appData = appData;
|
|
69
|
+
data.trackers = trackers;
|
|
70
|
+
}
|
|
71
|
+
catch (err) {
|
|
72
|
+
data = {
|
|
73
|
+
view: "_error",
|
|
74
|
+
viewType: "react",
|
|
75
|
+
viewData: {},
|
|
76
|
+
appData: appData,
|
|
77
|
+
};
|
|
78
|
+
console.error(err);
|
|
79
|
+
responseInit.status = 500;
|
|
80
|
+
}
|
|
81
|
+
headers.set("Content-Type", "text/html; charset=utf-8");
|
|
82
|
+
const stream = await getSsrStream({
|
|
83
|
+
...args,
|
|
84
|
+
initialData: data,
|
|
85
|
+
});
|
|
86
|
+
return new Response(stream, responseInit);
|
|
87
|
+
}
|
|
88
|
+
catch (err) {
|
|
89
|
+
console.error(err);
|
|
90
|
+
return new Response('<!DOCTYPE html><html><head><title>500 Internal Server Error</title></head><body><h1>500 Internal Server Error</h1><p>"' +
|
|
91
|
+
String(err) +
|
|
92
|
+
'"</p></body></html>', {
|
|
93
|
+
status: 500,
|
|
94
|
+
statusText: "Internal Server Error",
|
|
95
|
+
headers: {
|
|
96
|
+
"Content-Type": "text/html; charset=utf-8",
|
|
97
|
+
},
|
|
98
|
+
});
|
|
99
|
+
}
|
|
31
100
|
}
|
|
@@ -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
|
+
}
|
|
@@ -21,6 +21,7 @@ export declare class ServerContext {
|
|
|
21
21
|
dev: boolean;
|
|
22
22
|
origin: string;
|
|
23
23
|
replaceUrls?: (text: string) => string;
|
|
24
|
+
static main: ServerContext;
|
|
24
25
|
constructor(conf: ServerContextArgs);
|
|
25
26
|
get runtime(): ServerContextRuntime;
|
|
26
27
|
static setRuntime(rt: ServerContextRuntime): void;
|
|
@@ -18,12 +18,14 @@ export class ServerContext {
|
|
|
18
18
|
dev;
|
|
19
19
|
origin;
|
|
20
20
|
replaceUrls;
|
|
21
|
+
static main;
|
|
21
22
|
constructor(conf) {
|
|
22
23
|
this.dev = conf.dev;
|
|
23
24
|
this.origin = conf.origin;
|
|
24
25
|
if (conf.replaceUrls) {
|
|
25
26
|
this.replaceUrls = createUrlReplacer(conf.replaceUrls);
|
|
26
27
|
}
|
|
28
|
+
ServerContext.main = this;
|
|
27
29
|
}
|
|
28
30
|
get runtime() {
|
|
29
31
|
return runtime;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Component, ErrorInfo, ReactNode } from "react";
|
|
2
|
-
import { BlocksContext, ContentBlock } from "../lib/blocks/ContentBlocks";
|
|
2
|
+
import { BlocksContext, ContentBlock } from "../lib/blocks/ContentBlocks.js";
|
|
3
3
|
interface Props {
|
|
4
4
|
block: ContentBlock;
|
|
5
5
|
blockContext: BlocksContext;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { Component } from "react";
|
|
3
|
-
import { errorHandling } from "../lib/runtime";
|
|
4
|
-
import { ErrorMessage } from "./ErrorMessage";
|
|
3
|
+
import { errorHandling } from "../lib/runtime/errorHandling.js";
|
|
4
|
+
import { ErrorMessage } from "./ErrorMessage.js";
|
|
5
5
|
export class BlockErrorBoundary extends Component {
|
|
6
6
|
state = {
|
|
7
7
|
hasError: false,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { Component } from "react";
|
|
3
|
-
import { errorHandling } from "../lib/runtime";
|
|
4
|
-
import { ErrorMessage } from "./ErrorMessage";
|
|
3
|
+
import { errorHandling } from "../lib/runtime/errorHandling.js";
|
|
4
|
+
import { ErrorMessage } from "./ErrorMessage.js";
|
|
5
5
|
export class RouteErrorBoundary extends Component {
|
|
6
6
|
state = {
|
|
7
7
|
hasError: false,
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { QueryClientProvider, QueryClient } from "@tanstack/react-query";
|
|
2
3
|
let queryClient = null;
|
|
3
4
|
export function getQueryClient() {
|
|
4
5
|
if (!queryClient) {
|
|
@@ -14,3 +15,6 @@ export function getQueryClient() {
|
|
|
14
15
|
}
|
|
15
16
|
return queryClient;
|
|
16
17
|
}
|
|
18
|
+
export function QueryProvider(props) {
|
|
19
|
+
return _jsx(QueryClientProvider, { client: getQueryClient(), children: props.children });
|
|
20
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { createTRPCUntypedClient, httpLink, splitLink, unstable_httpSubscriptionLink, } from "@trpc/client";
|
|
2
|
+
import SuperJSON from "superjson";
|
|
3
|
+
import { parseURL, stringifyParsedURL } from "ufo";
|
|
4
|
+
let client;
|
|
5
|
+
export function getRPCClient() {
|
|
6
|
+
if (env.rpcEnabled) {
|
|
7
|
+
if (!client) {
|
|
8
|
+
// @ts-ignore
|
|
9
|
+
const endpoint = env.serverless ? "/" : window.SERVERLESS_ENDPOINT ?? "/";
|
|
10
|
+
client = createTRPCUntypedClient({
|
|
11
|
+
links: [
|
|
12
|
+
splitLink({
|
|
13
|
+
// uses the httpSubscriptionLink for subscriptions
|
|
14
|
+
condition: (op) => op.type === "subscription",
|
|
15
|
+
true: unstable_httpSubscriptionLink({
|
|
16
|
+
url: endpoint,
|
|
17
|
+
transformer: SuperJSON,
|
|
18
|
+
}),
|
|
19
|
+
false: httpLink({
|
|
20
|
+
url: endpoint,
|
|
21
|
+
fetch: (input, init) => {
|
|
22
|
+
const parsed = parseURL(input);
|
|
23
|
+
parsed.pathname = "/" + parsed.pathname.replace(/(^\/|\/$)/g, "").replace(/\./g, "/") + "/";
|
|
24
|
+
return fetch(stringifyParsedURL(parsed), init);
|
|
25
|
+
},
|
|
26
|
+
transformer: SuperJSON,
|
|
27
|
+
}),
|
|
28
|
+
}),
|
|
29
|
+
],
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return client;
|
|
34
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const VERSION = "2.0.0-beta.
|
|
1
|
+
export declare const VERSION = "2.0.0-beta.58";
|