payload-react-router 0.0.0-stage → 0.1.0
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/LICENSE +24 -0
- package/README.md +263 -2
- package/dist/client/PayloadRootProviders.d.ts +22 -0
- package/dist/client/PayloadRootProviders.js +29 -0
- package/dist/client/PayloadRootProviders.js.map +1 -0
- package/dist/client/RouterAdapter.d.ts +14 -0
- package/dist/client/RouterAdapter.js +64 -0
- package/dist/client/RouterAdapter.js.map +1 -0
- package/dist/client/navigation.d.ts +11 -0
- package/dist/client/navigation.js +31 -0
- package/dist/client/navigation.js.map +1 -0
- package/dist/exports/client.d.ts +2 -0
- package/dist/exports/client.js +3 -0
- package/dist/exports/client.js.map +1 -0
- package/dist/exports/server.d.ts +10 -0
- package/dist/exports/server.js +11 -0
- package/dist/exports/server.js.map +1 -0
- package/dist/exports/vite.d.ts +1 -0
- package/dist/exports/vite.js +2 -0
- package/dist/exports/vite.js.map +1 -0
- package/dist/server/adminPage.d.ts +50 -0
- package/dist/server/adminPage.js +136 -0
- package/dist/server/adminPage.js.map +1 -0
- package/dist/server/auth.d.ts +16 -0
- package/dist/server/auth.js +17 -0
- package/dist/server/auth.js.map +1 -0
- package/dist/server/cookies.d.ts +3 -0
- package/dist/server/cookies.js +27 -0
- package/dist/server/cookies.js.map +1 -0
- package/dist/server/graphql.d.ts +9 -0
- package/dist/server/graphql.js +114 -0
- package/dist/server/graphql.js.map +1 -0
- package/dist/server/initAdminContext.d.ts +17 -0
- package/dist/server/initAdminContext.js +39 -0
- package/dist/server/initAdminContext.js.map +1 -0
- package/dist/server/layout.d.ts +28 -0
- package/dist/server/layout.js +37 -0
- package/dist/server/layout.js.map +1 -0
- package/dist/server/middleware.d.ts +16 -0
- package/dist/server/middleware.js +35 -0
- package/dist/server/middleware.js.map +1 -0
- package/dist/server/requestStore.d.ts +29 -0
- package/dist/server/requestStore.js +54 -0
- package/dist/server/requestStore.js.map +1 -0
- package/dist/server/rest.d.ts +34 -0
- package/dist/server/rest.js +54 -0
- package/dist/server/rest.js.map +1 -0
- package/dist/server/searchParams.d.ts +6 -0
- package/dist/server/searchParams.js +13 -0
- package/dist/server/searchParams.js.map +1 -0
- package/dist/server/serverAdapter.d.ts +28 -0
- package/dist/server/serverAdapter.js +79 -0
- package/dist/server/serverAdapter.js.map +1 -0
- package/dist/server/serverFunctions.d.ts +21 -0
- package/dist/server/serverFunctions.js +25 -0
- package/dist/server/serverFunctions.js.map +1 -0
- package/dist/vite/config/external.d.ts +43 -0
- package/dist/vite/config/external.js +102 -0
- package/dist/vite/config/external.js.map +1 -0
- package/dist/vite/config/optimizeDeps.d.ts +24 -0
- package/dist/vite/config/optimizeDeps.js +162 -0
- package/dist/vite/config/optimizeDeps.js.map +1 -0
- package/dist/vite/config/scss.d.ts +13 -0
- package/dist/vite/config/scss.js +29 -0
- package/dist/vite/config/scss.js.map +1 -0
- package/dist/vite/devConfigReload.d.ts +13 -0
- package/dist/vite/devConfigReload.js +74 -0
- package/dist/vite/devConfigReload.js.map +1 -0
- package/dist/vite/devConfigReload.server.d.ts +1 -0
- package/dist/vite/devConfigReload.server.js +62 -0
- package/dist/vite/devConfigReload.server.js.map +1 -0
- package/dist/vite/devConfigReloadEvent.d.ts +8 -0
- package/dist/vite/devConfigReloadEvent.js +9 -0
- package/dist/vite/devConfigReloadEvent.js.map +1 -0
- package/dist/vite/index.d.ts +31 -0
- package/dist/vite/index.js +148 -0
- package/dist/vite/index.js.map +1 -0
- package/dist/vite/workarounds/clientModuleResolution.d.ts +13 -0
- package/dist/vite/workarounds/clientModuleResolution.js +80 -0
- package/dist/vite/workarounds/clientModuleResolution.js.map +1 -0
- package/dist/vite/workarounds/reactDomServerInRsc.d.ts +26 -0
- package/dist/vite/workarounds/reactDomServerInRsc.js +84 -0
- package/dist/vite/workarounds/reactDomServerInRsc.js.map +1 -0
- package/dist/vite/workarounds/stripDistStyleImports.d.ts +20 -0
- package/dist/vite/workarounds/stripDistStyleImports.js +140 -0
- package/dist/vite/workarounds/stripDistStyleImports.js.map +1 -0
- package/dist/vite/workarounds/stubPrettierInClient.d.ts +12 -0
- package/dist/vite/workarounds/stubPrettierInClient.js +32 -0
- package/dist/vite/workarounds/stubPrettierInClient.js.map +1 -0
- package/dist/vite/workarounds/wrapCjsForClient.d.ts +14 -0
- package/dist/vite/workarounds/wrapCjsForClient.js +104 -0
- package/dist/vite/workarounds/wrapCjsForClient.js.map +1 -0
- package/package.json +79 -4
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { createFromReadableStream, renderToReadableStream } from '@vitejs/plugin-rsc/rsc';
|
|
3
|
+
import { data, redirect } from 'react-router';
|
|
4
|
+
import { getRequestI18n, initAdminContext } from "./initAdminContext.js";
|
|
5
|
+
import { toSearchParams } from "./searchParams.js";
|
|
6
|
+
import { createPageRenderServerAdapter } from "./serverAdapter.js";
|
|
7
|
+
/**
|
|
8
|
+
* Serializes `node` to a Flight stream and reads it to the end, then decodes it
|
|
9
|
+
* back into a React tree.
|
|
10
|
+
*
|
|
11
|
+
* Every async server component in the admin tree runs during this call, so any
|
|
12
|
+
* `req.server.redirect()` / `.notFound()` they make lands in `nav` *before* the
|
|
13
|
+
* loader returns — while a redirect or a 404 status can still be sent. The
|
|
14
|
+
* decoded tree contains client references and resolved server output, so React
|
|
15
|
+
* Router re-serializes it without running the views a second time.
|
|
16
|
+
*
|
|
17
|
+
* The TanStack adapter forces the same full render, through a TanStack-internal
|
|
18
|
+
* stream symbol (`packages/tanstack-start/src/adapters/views/server.tsx`).
|
|
19
|
+
*/
|
|
20
|
+
async function renderToCompletion(node) {
|
|
21
|
+
const buffer = await new Response(renderToReadableStream(node)).arrayBuffer();
|
|
22
|
+
return createFromReadableStream(new Response(buffer).body);
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Loads one admin page for the `admin/*` splat route. Call it from the route
|
|
26
|
+
* `loader` and render the result with {@link AdminPage}:
|
|
27
|
+
*
|
|
28
|
+
* ```tsx
|
|
29
|
+
* export const loader = ({ params, request }: Route.LoaderArgs) =>
|
|
30
|
+
* loadAdminPage({ config, importMap, request, splat: params['*'] })
|
|
31
|
+
*
|
|
32
|
+
* export function ServerComponent({ loaderData }: Route.ComponentProps) {
|
|
33
|
+
* return <AdminPage {...loaderData} />
|
|
34
|
+
* }
|
|
35
|
+
* ```
|
|
36
|
+
*
|
|
37
|
+
* Navigation becomes React Router primitives: a redirect is thrown as
|
|
38
|
+
* `redirect()`, and an unknown or forbidden page returns Payload's not-found
|
|
39
|
+
* view (with the admin chrome) under an HTTP 404.
|
|
40
|
+
*/
|
|
41
|
+
export async function loadAdminPage({ config: configInput, importMap, request, splat, }) {
|
|
42
|
+
const [{ renderRoot }, { defaultAdminViews }, { generatePageMetadata }] = await Promise.all([
|
|
43
|
+
import('@payloadcms/ui/views/Root'),
|
|
44
|
+
import('@payloadcms/ui/views/Root/adminViews'),
|
|
45
|
+
import('@payloadcms/ui/views/Root/generatePageMetadata'),
|
|
46
|
+
]);
|
|
47
|
+
const config = await configInput;
|
|
48
|
+
const url = new URL(request.url);
|
|
49
|
+
const searchParams = toSearchParams(url);
|
|
50
|
+
const splatSegments = splat ? splat.split('/').filter(Boolean) : [];
|
|
51
|
+
// `/admin` itself has no segments (Next's optional catch-all). An empty array
|
|
52
|
+
// would make `renderRoot` see `/admin/` and add `?redirect=/admin/` on login.
|
|
53
|
+
const segments = splatSegments.length > 0 ? splatSegments : undefined;
|
|
54
|
+
const nav = {};
|
|
55
|
+
const pageServerAdapter = createPageRenderServerAdapter(nav);
|
|
56
|
+
const renderNotFound = async () => {
|
|
57
|
+
const { renderNotFoundPage } = await import('@payloadcms/ui/views/NotFound/page');
|
|
58
|
+
const node = await renderNotFoundPage({
|
|
59
|
+
config: Promise.resolve(config),
|
|
60
|
+
importMap,
|
|
61
|
+
initAdminContext: (args) => initAdminContext({ ...args }),
|
|
62
|
+
params: Promise.resolve({ segments: splatSegments }),
|
|
63
|
+
searchParams: Promise.resolve(searchParams),
|
|
64
|
+
});
|
|
65
|
+
const i18n = await getRequestI18n({ config });
|
|
66
|
+
return data({ meta: { title: i18n.t('general:notFound') }, page: await renderToCompletion(node) }, { status: 404 });
|
|
67
|
+
};
|
|
68
|
+
let page;
|
|
69
|
+
try {
|
|
70
|
+
const node = await renderRoot({
|
|
71
|
+
adminViews: defaultAdminViews,
|
|
72
|
+
config: Promise.resolve(config),
|
|
73
|
+
importMap,
|
|
74
|
+
initAdminContext: (args) => initAdminContext({ ...args, serverAdapter: pageServerAdapter }),
|
|
75
|
+
// Remount the view when the route changes, so client providers holding
|
|
76
|
+
// per-document state start fresh. Search-only changes keep the key.
|
|
77
|
+
key: splat ?? '',
|
|
78
|
+
notFound: pageServerAdapter.notFound,
|
|
79
|
+
params: Promise.resolve({ segments }),
|
|
80
|
+
redirect: pageServerAdapter.redirect,
|
|
81
|
+
searchParams: Promise.resolve(searchParams),
|
|
82
|
+
});
|
|
83
|
+
page = await renderToCompletion(node);
|
|
84
|
+
}
|
|
85
|
+
catch (error) {
|
|
86
|
+
const message = error instanceof Error ? error.message : '';
|
|
87
|
+
if (nav.type === undefined && message === 'not-found') {
|
|
88
|
+
nav.type = 'notFound';
|
|
89
|
+
}
|
|
90
|
+
else if (nav.type === undefined && message.startsWith('redirect:')) {
|
|
91
|
+
nav.type = 'redirect';
|
|
92
|
+
nav.url = message.slice('redirect:'.length);
|
|
93
|
+
}
|
|
94
|
+
else if (nav.type === undefined) {
|
|
95
|
+
throw error;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
if (nav.type === 'redirect' && nav.url) {
|
|
99
|
+
// eslint-disable-next-line @typescript-eslint/only-throw-error -- React Router control flow
|
|
100
|
+
throw redirect(nav.url);
|
|
101
|
+
}
|
|
102
|
+
if (nav.type === 'notFound') {
|
|
103
|
+
return renderNotFound();
|
|
104
|
+
}
|
|
105
|
+
const i18n = await getRequestI18n({ config });
|
|
106
|
+
const metadata = await generatePageMetadata({
|
|
107
|
+
adminViews: defaultAdminViews,
|
|
108
|
+
config,
|
|
109
|
+
i18n,
|
|
110
|
+
params: { segments },
|
|
111
|
+
});
|
|
112
|
+
return { meta: toAdminPageMeta(metadata), page };
|
|
113
|
+
}
|
|
114
|
+
function toAdminPageMeta(metadata) {
|
|
115
|
+
const title = typeof metadata.title === 'string'
|
|
116
|
+
? metadata.title
|
|
117
|
+
: metadata.title && typeof metadata.title === 'object' && 'absolute' in metadata.title
|
|
118
|
+
? String(metadata.title.absolute)
|
|
119
|
+
: undefined;
|
|
120
|
+
return {
|
|
121
|
+
description: typeof metadata.description === 'string' ? metadata.description : undefined,
|
|
122
|
+
title,
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Renders a page loaded by {@link loadAdminPage}, with its `<title>` hoisted by React.
|
|
127
|
+
*
|
|
128
|
+
* `page` is typed `unknown` on purpose: React Router's generated route types
|
|
129
|
+
* describe loader data as if it were turbo-stream serialized, which mangles
|
|
130
|
+
* `ReactNode`. In RSC mode loader data travels as Flight, so the element arrives
|
|
131
|
+
* intact and can be passed straight through: `<AdminPage {...loaderData} />`.
|
|
132
|
+
*/
|
|
133
|
+
export function AdminPage({ meta, page }) {
|
|
134
|
+
return (_jsxs(_Fragment, { children: [meta.title ? _jsx("title", { children: meta.title }) : null, meta.description ? _jsx("meta", { content: meta.description, name: "description" }) : null, page] }));
|
|
135
|
+
}
|
|
136
|
+
//# sourceMappingURL=adminPage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adminPage.js","sourceRoot":"","sources":["../../src/server/adminPage.tsx"],"names":[],"mappings":";AAGA,OAAO,EAAE,wBAAwB,EAAE,sBAAsB,EAAE,MAAM,wBAAwB,CAAA;AACzF,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAA;AAI7C,OAAO,EAAE,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+
import { type LoginArgsWithoutServerAdapter, type LogoutArgs, type RefreshArgs } from 'payload/auth';
|
|
3
|
+
/**
|
|
4
|
+
* Payload's auth server functions bound to React Router. Call them from a
|
|
5
|
+
* `'use server'` function or a route `action`; the auth cookie reaches the
|
|
6
|
+
* browser through `payloadMiddleware`.
|
|
7
|
+
*/
|
|
8
|
+
export declare function login<TSlug extends AuthCollectionSlug>(args: LoginArgsWithoutServerAdapter<TSlug>): Promise<LoginResult<TSlug>>;
|
|
9
|
+
export declare function logout(args: Omit<LogoutArgs, 'serverAdapter'>): Promise<{
|
|
10
|
+
message: string;
|
|
11
|
+
success: boolean;
|
|
12
|
+
}>;
|
|
13
|
+
export declare function refresh(args: Omit<RefreshArgs, 'serverAdapter'>): Promise<{
|
|
14
|
+
message: string;
|
|
15
|
+
success: boolean;
|
|
16
|
+
}>;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { login as loginFn, logout as logoutFn, refresh as refreshFn, } from 'payload/auth';
|
|
2
|
+
import { reactRouterServerAdapter } from "./serverAdapter.js";
|
|
3
|
+
/**
|
|
4
|
+
* Payload's auth server functions bound to React Router. Call them from a
|
|
5
|
+
* `'use server'` function or a route `action`; the auth cookie reaches the
|
|
6
|
+
* browser through `payloadMiddleware`.
|
|
7
|
+
*/
|
|
8
|
+
export function login(args) {
|
|
9
|
+
return loginFn({ ...args, serverAdapter: reactRouterServerAdapter });
|
|
10
|
+
}
|
|
11
|
+
export function logout(args) {
|
|
12
|
+
return logoutFn({ ...args, serverAdapter: reactRouterServerAdapter });
|
|
13
|
+
}
|
|
14
|
+
export function refresh(args) {
|
|
15
|
+
return refreshFn({ ...args, serverAdapter: reactRouterServerAdapter });
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=auth.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.js","sourceRoot":"","sources":["../../src/server/auth.ts"],"names":[],"mappings":"AAEA,OAAO,EAGL,KAAK,IAAI,OAAO,EAEhB,MAAM,IAAI,QAAQ,EAClB,OAAO,IAAI,SAAS,GAErB,MAAM,cAAc,CAAA;AAErB,OAAO,EAAE,wBAAwB,EAAE,MAAM,oBAAoB,CAAA;AAE7D;;;;GAIG;AACH,MAAM,UAAU,KAAK,CACnB,IAA0C;IAE1C,OAAO,OAAO,CAAC,EAAE,GAAG,IAAI,EAAE,aAAa,EAAE,wBAAwB,EAAsB,CAAC,CAAA;AAC1F,CAAC;AAED,MAAM,UAAU,MAAM,CACpB,IAAuC;IAEvC,OAAO,QAAQ,CAAC,EAAE,GAAG,IAAI,EAAE,aAAa,EAAE,wBAAwB,EAAE,CAAC,CAAA;AACvE,CAAC;AAED,MAAM,UAAU,OAAO,CAAC,IAAwC;IAC9D,OAAO,SAAS,CAAC,EAAE,GAAG,IAAI,EAAE,aAAa,EAAE,wBAAwB,EAAE,CAAC,CAAA;AACxE,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/** Serializes one `Set-Cookie` value from Payload's `CookieOptions`. */
|
|
2
|
+
export function serializeCookie(name, value, options = {}) {
|
|
3
|
+
let cookie = `${encodeURIComponent(name)}=${encodeURIComponent(value)}`;
|
|
4
|
+
if (options.path) {
|
|
5
|
+
cookie += `; Path=${options.path}`;
|
|
6
|
+
}
|
|
7
|
+
if (options.domain) {
|
|
8
|
+
cookie += `; Domain=${options.domain}`;
|
|
9
|
+
}
|
|
10
|
+
if (options.maxAge !== undefined) {
|
|
11
|
+
cookie += `; Max-Age=${Math.floor(options.maxAge)}`;
|
|
12
|
+
}
|
|
13
|
+
if (options.expires) {
|
|
14
|
+
cookie += `; Expires=${options.expires.toUTCString()}`;
|
|
15
|
+
}
|
|
16
|
+
if (options.httpOnly) {
|
|
17
|
+
cookie += '; HttpOnly';
|
|
18
|
+
}
|
|
19
|
+
if (options.secure) {
|
|
20
|
+
cookie += '; Secure';
|
|
21
|
+
}
|
|
22
|
+
if (options.sameSite) {
|
|
23
|
+
cookie += `; SameSite=${options.sameSite.charAt(0).toUpperCase()}${options.sameSite.slice(1)}`;
|
|
24
|
+
}
|
|
25
|
+
return cookie;
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=cookies.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cookies.js","sourceRoot":"","sources":["../../src/server/cookies.ts"],"names":[],"mappings":"AAEA,wEAAwE;AACxE,MAAM,UAAU,eAAe,CAAC,IAAY,EAAE,KAAa,EAAE,UAAyB,EAAE;IACtF,IAAI,MAAM,GAAG,GAAG,kBAAkB,CAAC,IAAI,CAAC,IAAI,kBAAkB,CAAC,KAAK,CAAC,EAAE,CAAA;IAEvE,IAAI,OAAO,CAAC,IAAI,EAAE,CAAC;QACjB,MAAM,IAAI,UAAU,OAAO,CAAC,IAAI,EAAE,CAAA;IACpC,CAAC;IACD,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;QACnB,MAAM,IAAI,YAAY,OAAO,CAAC,MAAM,EAAE,CAAA;IACxC,CAAC;IACD,IAAI,OAAO,CAAC,MAAM,KAAK,SAAS,EAAE,CAAC;QACjC,MAAM,IAAI,aAAa,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAA;IACrD,CAAC;IACD,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC;QACpB,MAAM,IAAI,aAAa,OAAO,CAAC,OAAO,CAAC,WAAW,EAAE,EAAE,CAAA;IACxD,CAAC;IACD,IAAI,OAAO,CAAC,QAAQ,EAAE,CAAC;QACrB,MAAM,IAAI,YAAY,CAAA;IACxB,CAAC;IACD,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;QACnB,MAAM,IAAI,UAAU,CAAA;IACtB,CAAC;IACD,IAAI,OAAO,CAAC,QAAQ,EAAE,CAAC;QACrB,MAAM,IAAI,cAAc,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAA;IAChG,CAAC;IAED,OAAO,MAAM,CAAA;AACf,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { SanitizedConfig } from 'payload';
|
|
2
|
+
/**
|
|
3
|
+
* Handles GraphQL HTTP requests (`POST /api/graphql`).
|
|
4
|
+
* Mirrors the behaviour of `@payloadcms/next`'s GraphQL route handler.
|
|
5
|
+
*/
|
|
6
|
+
export declare const handleGraphQL: ({ config, request, }: {
|
|
7
|
+
config: Promise<SanitizedConfig> | SanitizedConfig;
|
|
8
|
+
request: Request;
|
|
9
|
+
}) => Promise<Response>;
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { addDataAndFileToRequest, addLocalesToRequestFromData, createPayloadRequestFromWebRequest, headersWithCors, logError, mergeHeaders, } from 'payload';
|
|
2
|
+
const handleError = async ({ err, payload, req, }) => {
|
|
3
|
+
const status = err.originalError?.status || 500;
|
|
4
|
+
let errorMessage = err.message;
|
|
5
|
+
logError({ err, payload });
|
|
6
|
+
if (!payload.config.debug && status === 500) {
|
|
7
|
+
errorMessage = 'Something went wrong.';
|
|
8
|
+
}
|
|
9
|
+
let response = {
|
|
10
|
+
extensions: {
|
|
11
|
+
name: err?.originalError?.name || undefined,
|
|
12
|
+
data: (err && err.originalError && err.originalError.data) || undefined,
|
|
13
|
+
stack: payload.config.debug ? err.stack : undefined,
|
|
14
|
+
statusCode: status,
|
|
15
|
+
},
|
|
16
|
+
locations: err.locations,
|
|
17
|
+
message: errorMessage,
|
|
18
|
+
path: err.path,
|
|
19
|
+
};
|
|
20
|
+
await payload.config.hooks.afterError?.reduce(async (promise, hook) => {
|
|
21
|
+
await promise;
|
|
22
|
+
const result = await hook({
|
|
23
|
+
context: req.context,
|
|
24
|
+
error: err,
|
|
25
|
+
graphqlResult: response,
|
|
26
|
+
req,
|
|
27
|
+
});
|
|
28
|
+
if (result) {
|
|
29
|
+
response = result.graphqlResult || response;
|
|
30
|
+
}
|
|
31
|
+
}, Promise.resolve());
|
|
32
|
+
return response;
|
|
33
|
+
};
|
|
34
|
+
let cached = { graphql: null, promise: null };
|
|
35
|
+
const getGraphql = async (config) => {
|
|
36
|
+
if (process.env.NODE_ENV === 'development') {
|
|
37
|
+
cached = { graphql: null, promise: null };
|
|
38
|
+
}
|
|
39
|
+
if (cached.graphql) {
|
|
40
|
+
return cached.graphql;
|
|
41
|
+
}
|
|
42
|
+
if (!cached.promise) {
|
|
43
|
+
const resolvedConfig = await config;
|
|
44
|
+
const { configToSchema } = await import('@payloadcms/graphql');
|
|
45
|
+
cached.promise = new Promise((resolve) => {
|
|
46
|
+
const schema = configToSchema(resolvedConfig);
|
|
47
|
+
resolve(cached.graphql || schema);
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
try {
|
|
51
|
+
cached.graphql = await cached.promise;
|
|
52
|
+
}
|
|
53
|
+
catch (e) {
|
|
54
|
+
cached.promise = null;
|
|
55
|
+
throw e;
|
|
56
|
+
}
|
|
57
|
+
return cached.graphql;
|
|
58
|
+
};
|
|
59
|
+
/**
|
|
60
|
+
* Handles GraphQL HTTP requests (`POST /api/graphql`).
|
|
61
|
+
* Mirrors the behaviour of `@payloadcms/next`'s GraphQL route handler.
|
|
62
|
+
*/
|
|
63
|
+
export const handleGraphQL = async ({ config, request, }) => {
|
|
64
|
+
const originalRequest = request.clone();
|
|
65
|
+
const req = await createPayloadRequestFromWebRequest({
|
|
66
|
+
canSetHeaders: true,
|
|
67
|
+
config,
|
|
68
|
+
request,
|
|
69
|
+
});
|
|
70
|
+
const { payload } = req;
|
|
71
|
+
if (payload.config.graphQL?.disable) {
|
|
72
|
+
return new Response(null, {
|
|
73
|
+
status: 404,
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
await addDataAndFileToRequest(req);
|
|
77
|
+
addLocalesToRequestFromData(req);
|
|
78
|
+
const { schema, validationRules } = await getGraphql(config);
|
|
79
|
+
const { createHandler } = await import('graphql-http/lib/use/fetch');
|
|
80
|
+
const headers = {};
|
|
81
|
+
const apiResponse = await createHandler({
|
|
82
|
+
context: { headers, req },
|
|
83
|
+
onOperation: async (_request, args, result) => {
|
|
84
|
+
const response = typeof payload.extensions === 'function'
|
|
85
|
+
? await payload.extensions({
|
|
86
|
+
args,
|
|
87
|
+
req: _request,
|
|
88
|
+
result,
|
|
89
|
+
})
|
|
90
|
+
: result;
|
|
91
|
+
if (response.errors) {
|
|
92
|
+
const errors = await Promise.all(response.errors.map((error) => {
|
|
93
|
+
return handleError({ err: error, payload, req });
|
|
94
|
+
}));
|
|
95
|
+
return { ...response, errors };
|
|
96
|
+
}
|
|
97
|
+
return response;
|
|
98
|
+
},
|
|
99
|
+
schema,
|
|
100
|
+
validationRules: (_, args, defaultRules) => defaultRules.concat(validationRules(args)),
|
|
101
|
+
})(originalRequest);
|
|
102
|
+
const resHeaders = headersWithCors({
|
|
103
|
+
headers: new Headers(apiResponse.headers),
|
|
104
|
+
req,
|
|
105
|
+
});
|
|
106
|
+
for (const key of Object.keys(headers)) {
|
|
107
|
+
resHeaders.append(key, headers[key]);
|
|
108
|
+
}
|
|
109
|
+
return new Response(apiResponse.body, {
|
|
110
|
+
headers: req.responseHeaders ? mergeHeaders(req.responseHeaders, resHeaders) : resHeaders,
|
|
111
|
+
status: apiResponse.status,
|
|
112
|
+
});
|
|
113
|
+
};
|
|
114
|
+
//# sourceMappingURL=graphql.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"graphql.js","sourceRoot":"","sources":["../../src/server/graphql.ts"],"names":[],"mappings":"AAKA,OAAO,EACL,uBAAuB,EACvB,2BAA2B,EAC3B,kCAAkC,EAClC,eAAe,EACf,QAAQ,EACR,YAAY,GACb,MAAM,SAAS,CAAA;AAEhB,MAAM,WAAW,GAAG,KAAK,EAAE,EACzB,GAAG,EACH,OAAO,EACP,GAAG,GAKJ,EAAgB,EAAE;IACjB,MAAM,MAAM,GAAG,GAAG,CAAC,aAAa,EAAE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EAAE,CAAA;YAChC,CAAC;YACD,OAAO,QAAQ,CAAA;QACjB,CAAC;QACD,MAAM;QACN,eAAe,EAAE,CAAC,CAAM,EAAE,IAAS,EAAE,YAAiB,EAAE,EAAE,CACxD,YAAY,CAAC,MAAM,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;KAC7C,CAAC,CAAC,eAAe,CAAC,CAAA;IAEnB,MAAM,UAAU,GAAG,eAAe,CAAC;QACjC,OAAO,EAAE,IAAI,OAAO,CAAC,WAAW,CAAC,OAAO,CAAC;QACzC,GAAG;KACJ,CAAC,CAAA;IAEF,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC;QACvC,UAAU,CAAC,MAAM,CAAC,GAAG,EAAE,OAAO,CAAC,GAAG,CAAE,CAAC,CAAA;IACvC,CAAC;IAED,OAAO,IAAI,QAAQ,CAAC,WAAW,CAAC,IAAI,EAAE;QACpC,OAAO,EAAE,GAAG,CAAC,eAAe,CAAC,CAAC,CAAC,YAAY,CAAC,GAAG,CAAC,eAAe,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC,UAAU;QACzF,MAAM,EAAE,WAAW,CAAC,MAAM;KAC3B,CAAC,CAAA;AACJ,CAAC,CAAA"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { I18nClient } from '@payloadcms/translations';
|
|
2
|
+
import type { SanitizedConfig, ServerAdapter } from 'payload';
|
|
3
|
+
import type { InitAdminContextArgs } from 'payload/internal';
|
|
4
|
+
import '../vite/devConfigReload.server.ts';
|
|
5
|
+
export type ReactRouterInitAdminContextArgs = {
|
|
6
|
+
key?: string;
|
|
7
|
+
serverAdapter?: ServerAdapter;
|
|
8
|
+
} & Omit<InitAdminContextArgs, 'cache' | 'key' | 'requestURL' | 'serverAdapter'>;
|
|
9
|
+
/** `initAdminContext` bound to the current React Router request. */
|
|
10
|
+
export declare const initAdminContext: ({ key, serverAdapter, ...args }: ReactRouterInitAdminContextArgs) => Promise<import("payload").AdminContext>;
|
|
11
|
+
/**
|
|
12
|
+
* Resolves the admin `I18n` for the current request without a full admin
|
|
13
|
+
* context. Used for page metadata.
|
|
14
|
+
*/
|
|
15
|
+
export declare function getRequestI18n({ config }: {
|
|
16
|
+
config: SanitizedConfig;
|
|
17
|
+
}): Promise<I18nClient>;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { initI18n } from '@payloadcms/translations';
|
|
2
|
+
import { getRequestLanguage, parseCookies } from 'payload';
|
|
3
|
+
import { initAdminContext as initPayloadAdminContext } from 'payload/internal';
|
|
4
|
+
// Registers the dev reload strategy before a Payload instance is built. No-op
|
|
5
|
+
// outside of `vite dev`.
|
|
6
|
+
import "../vite/devConfigReload.server.js";
|
|
7
|
+
import { getRequest, requestMemo } from "./requestStore.js";
|
|
8
|
+
import { reactRouterServerAdapter } from "./serverAdapter.js";
|
|
9
|
+
/**
|
|
10
|
+
* Only the partial context (Payload instance, i18n, authenticated user) is
|
|
11
|
+
* shared within a request: the admin layout and the admin page each build one
|
|
12
|
+
* per request, and running the auth strategies twice would be wasted work.
|
|
13
|
+
*
|
|
14
|
+
* The full context is not cached. It embeds `req.server`, and the layout and
|
|
15
|
+
* the page deliberately use different server adapters.
|
|
16
|
+
*/
|
|
17
|
+
const cache = {
|
|
18
|
+
getPartial: (createPartialContext) => requestMemo('payload:partial-admin-context', createPartialContext),
|
|
19
|
+
getRequest: (createContext) => createContext(),
|
|
20
|
+
};
|
|
21
|
+
/** `initAdminContext` bound to the current React Router request. */
|
|
22
|
+
export const initAdminContext = ({ key = 'payload-react-router', serverAdapter = reactRouterServerAdapter, ...args }) => initPayloadAdminContext({
|
|
23
|
+
...args,
|
|
24
|
+
cache,
|
|
25
|
+
key,
|
|
26
|
+
requestURL: getRequest().url,
|
|
27
|
+
serverAdapter,
|
|
28
|
+
});
|
|
29
|
+
/**
|
|
30
|
+
* Resolves the admin `I18n` for the current request without a full admin
|
|
31
|
+
* context. Used for page metadata.
|
|
32
|
+
*/
|
|
33
|
+
export async function getRequestI18n({ config }) {
|
|
34
|
+
const headers = new Headers(getRequest().headers);
|
|
35
|
+
const cookies = parseCookies(headers);
|
|
36
|
+
const language = getRequestLanguage({ config, cookies, headers });
|
|
37
|
+
return initI18n({ config: config.i18n, context: 'client', language });
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=initAdminContext.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"initAdminContext.js","sourceRoot":"","sources":["../../src/server/initAdminContext.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAA;AACnD,OAAO,EAAE,kBAAkB,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AAC1D,OAAO,EAAE,gBAAgB,IAAI,uBAAuB,EAAE,MAAM,kBAAkB,CAAA;AAE9E,8EAA8E;AAC9E,yBAAyB;AACzB,OAAO,mCAAmC,CAAA;AAC1C,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAC3D,OAAO,EAAE,wBAAwB,EAAE,MAAM,oBAAoB,CAAA;AAE7D;;;;;;;GAOG;AACH,MAAM,KAAK,GAAsB;IAC/B,UAAU,EAAE,CAAC,oBAAoB,EAAE,EAAE,CACnC,WAAW,CAAsB,+BAA+B,EAAE,oBAAoB,CAAC;IACzF,UAAU,EAAE,CAAC,aAAa,EAAE,EAAE,CAAC,aAAa,EAAE;CAC/C,CAAA;AAOD,oEAAoE;AACpE,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,EAC/B,GAAG,GAAG,sBAAsB,EAC5B,aAAa,GAAG,wBAAwB,EACxC,GAAG,IAAI,EACyB,EAAE,EAAE,CACpC,uBAAuB,CAAC;IACtB,GAAG,IAAI;IACP,KAAK;IACL,GAAG;IACH,UAAU,EAAE,UAAU,EAAE,CAAC,GAAG;IAC5B,aAAa;CACd,CAAC,CAAA;AAEJ;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc,CAAC,EAAE,MAAM,EAA+B;IAC1E,MAAM,OAAO,GAAG,IAAI,OAAO,CAAC,UAAU,EAAE,CAAC,OAAO,CAAC,CAAA;IACjD,MAAM,OAAO,GAAG,YAAY,CAAC,OAAO,CAAC,CAAA;IACrC,MAAM,QAAQ,GAAG,kBAAkB,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC,CAAA;IAEjE,OAAO,QAAQ,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,IAAI,EAAE,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,CAAC,CAAA;AACvE,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { RootLayoutFont } from '@payloadcms/ui';
|
|
2
|
+
import type { ImportMap, SanitizedConfig } from 'payload';
|
|
3
|
+
import type { HtmlHTMLAttributes, ReactNode } from 'react';
|
|
4
|
+
import type { PayloadServerFunction } from '../client/PayloadRootProviders.tsx';
|
|
5
|
+
export type PayloadAdminLayoutProps = {
|
|
6
|
+
readonly children: ReactNode;
|
|
7
|
+
readonly config: Promise<SanitizedConfig> | SanitizedConfig;
|
|
8
|
+
readonly fonts?: RootLayoutFont[];
|
|
9
|
+
/** Extra `<head>` content (fonts, analytics, favicons…). */
|
|
10
|
+
readonly head?: ReactNode;
|
|
11
|
+
readonly htmlProps?: HtmlHTMLAttributes<HTMLHtmlElement>;
|
|
12
|
+
readonly importMap: ImportMap;
|
|
13
|
+
/** The app's `'use server'` function that calls `handleServerFunctions`. */
|
|
14
|
+
readonly serverFunction: PayloadServerFunction;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* The admin document: `<html>` with Payload's theme / language / direction
|
|
18
|
+
* attributes, the admin providers, and any custom
|
|
19
|
+
* `config.admin.components.providers`.
|
|
20
|
+
*
|
|
21
|
+
* The React Router counterpart of `RootLayout` from `@payloadcms/ui/layouts`
|
|
22
|
+
* (what `@payloadcms/next` renders in `app/(payload)/layout.tsx`). It differs in
|
|
23
|
+
* one place: providers go through {@link PayloadRootProviders}, a client
|
|
24
|
+
* component that binds the router adapter and wraps `serverFunction` (see there).
|
|
25
|
+
*
|
|
26
|
+
* Render it as the `ServerComponent` of the layout route wrapping `/admin/*`.
|
|
27
|
+
*/
|
|
28
|
+
export declare function PayloadAdminLayout({ children, config: configInput, fonts, head, htmlProps, importMap, serverFunction, }: PayloadAdminLayoutProps): Promise<import("react/jsx-runtime").JSX.Element>;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { DocumentRoot } from '@payloadcms/ui';
|
|
3
|
+
import { getViewportMeta } from '@payloadcms/ui/layouts';
|
|
4
|
+
import { NestProviders } from '@payloadcms/ui/layouts/NestProviders';
|
|
5
|
+
import { getRootLayoutData } from '@payloadcms/ui/layouts/Root/getRootLayoutData';
|
|
6
|
+
import { PayloadRootProviders } from "../client/PayloadRootProviders.js";
|
|
7
|
+
import { initAdminContext } from "./initAdminContext.js";
|
|
8
|
+
/**
|
|
9
|
+
* The admin document: `<html>` with Payload's theme / language / direction
|
|
10
|
+
* attributes, the admin providers, and any custom
|
|
11
|
+
* `config.admin.components.providers`.
|
|
12
|
+
*
|
|
13
|
+
* The React Router counterpart of `RootLayout` from `@payloadcms/ui/layouts`
|
|
14
|
+
* (what `@payloadcms/next` renders in `app/(payload)/layout.tsx`). It differs in
|
|
15
|
+
* one place: providers go through {@link PayloadRootProviders}, a client
|
|
16
|
+
* component that binds the router adapter and wraps `serverFunction` (see there).
|
|
17
|
+
*
|
|
18
|
+
* Render it as the `ServerComponent` of the layout route wrapping `/admin/*`.
|
|
19
|
+
*/
|
|
20
|
+
export async function PayloadAdminLayout({ children, config: configInput, fonts, head, htmlProps, importMap, serverFunction, }) {
|
|
21
|
+
const configPromise = Promise.resolve(configInput);
|
|
22
|
+
const { cookies, permissions, req, user } = await initAdminContext({
|
|
23
|
+
configPromise,
|
|
24
|
+
importMap,
|
|
25
|
+
key: 'RootLayout',
|
|
26
|
+
});
|
|
27
|
+
const data = await getRootLayoutData({ cookies, importMap, permissions, req, user });
|
|
28
|
+
const providers = req.payload.config.admin?.components?.providers;
|
|
29
|
+
return (_jsx(DocumentRoot, { dir: data.dir, fonts: fonts, head: head, highContrastMode: data.highContrastMode, htmlProps: htmlProps, languageCode: data.languageCode, suppressHydrationWarning: data.suppressHydrationWarning, theme: data.theme, themeSource: data.themeSource, viewport: getViewportMeta(req.headers.get('user-agent') ?? undefined), children: _jsx(PayloadRootProviders, { data: data, serverFunction: serverFunction, children: Array.isArray(providers) && providers.length > 0 ? (_jsx(NestProviders, { importMap: req.payload.importMap, providers: providers, serverProps: {
|
|
30
|
+
i18n: req.i18n,
|
|
31
|
+
payload: req.payload,
|
|
32
|
+
permissions,
|
|
33
|
+
server: req.server,
|
|
34
|
+
user: user ?? undefined,
|
|
35
|
+
}, children: children })) : (children) }) }));
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=layout.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"layout.js","sourceRoot":"","sources":["../../src/server/layout.tsx"],"names":[],"mappings":";AAIA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAC7C,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAA;AACxD,OAAO,EAAE,aAAa,EAAE,MAAM,sCAAsC,CAAA;AACpE,OAAO,EAAE,iBAAiB,EAAE,MAAM,+CAA+C,CAAA;AAIjF,OAAO,EAAE,oBAAoB,EAAE,MAAM,mCAAoC,CAAA;AACzE,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAA;AAcxD;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,KAAK,UAAU,kBAAkB,CAAC,EACvC,QAAQ,EACR,MAAM,EAAE,WAAW,EACnB,KAAK,EACL,IAAI,EACJ,SAAS,EACT,SAAS,EACT,cAAc,GACU;IACxB,MAAM,aA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AG,CAAC,MAAO;oBACnB,IAAI,EAAE,IAAI,IAAI,SAAS;iBACxB,YAEA,QAAQ,GACK,CACjB,CAAC,CAAC,CAAC,CACF,QAAQ,CACT,GACoB,GACV,CAChB,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { MiddlewareFunction } from 'react-router';
|
|
2
|
+
/**
|
|
3
|
+
* Root route middleware. Opens the request store Payload's server adapter reads
|
|
4
|
+
* headers from, and copies cookies Payload set during the request (e.g. the
|
|
5
|
+
* `switch-language` server function) onto the response.
|
|
6
|
+
*
|
|
7
|
+
* Register it once in `app/root.tsx`:
|
|
8
|
+
*
|
|
9
|
+
* ```ts
|
|
10
|
+
* export const middleware = [payloadMiddleware]
|
|
11
|
+
* ```
|
|
12
|
+
*
|
|
13
|
+
* It runs for documents, RSC data requests, server functions and resource
|
|
14
|
+
* routes alike, because all of them go through the root route's middleware.
|
|
15
|
+
*/
|
|
16
|
+
export declare const payloadMiddleware: MiddlewareFunction<Response>;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { createRequestStore, runWithRequestStore } from "./requestStore.js";
|
|
2
|
+
/**
|
|
3
|
+
* Root route middleware. Opens the request store Payload's server adapter reads
|
|
4
|
+
* headers from, and copies cookies Payload set during the request (e.g. the
|
|
5
|
+
* `switch-language` server function) onto the response.
|
|
6
|
+
*
|
|
7
|
+
* Register it once in `app/root.tsx`:
|
|
8
|
+
*
|
|
9
|
+
* ```ts
|
|
10
|
+
* export const middleware = [payloadMiddleware]
|
|
11
|
+
* ```
|
|
12
|
+
*
|
|
13
|
+
* It runs for documents, RSC data requests, server functions and resource
|
|
14
|
+
* routes alike, because all of them go through the root route's middleware.
|
|
15
|
+
*/
|
|
16
|
+
export const payloadMiddleware = ({ request }, next) => {
|
|
17
|
+
const store = createRequestStore(request);
|
|
18
|
+
return runWithRequestStore(store, async () => {
|
|
19
|
+
const response = await next();
|
|
20
|
+
if (store.setCookies.length === 0) {
|
|
21
|
+
return response;
|
|
22
|
+
}
|
|
23
|
+
// Response headers can be immutable (e.g. a `fetch` response), so rebuild.
|
|
24
|
+
const headers = new Headers(response.headers);
|
|
25
|
+
for (const cookie of store.setCookies) {
|
|
26
|
+
headers.append('Set-Cookie', cookie);
|
|
27
|
+
}
|
|
28
|
+
return new Response(response.body, {
|
|
29
|
+
headers,
|
|
30
|
+
status: response.status,
|
|
31
|
+
statusText: response.statusText,
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
};
|
|
35
|
+
//# sourceMappingURL=middleware.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"middleware.js","sourceRoot":"","sources":["../../src/server/middleware.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAA;AAE3E;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAiC,CAAC,EAAE,OAAO,EAAE,EAAE,IAAI,EAAE,EAAE;IACnF,MAAM,KAAK,GAAG,kBAAkB,CAAC,OAAO,CAAC,CAAA;IAEzC,OAAO,mBAAmB,CAAC,KAAK,EAAE,KAAK,IAAI,EAAE;QAC3C,MAAM,QAAQ,GAAG,MAAM,IAAI,EAAE,CAAA;QAE7B,IAAI,KAAK,CAAC,UAAU,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAClC,OAAO,QAAQ,CAAA;QACjB,CAAC;QAED,2EAA2E;QAC3E,MAAM,OAAO,GAAG,IAAI,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAA;QAC7C,KAAK,MAAM,MAAM,IAAI,KAAK,CAAC,UAAU,EAAE,CAAC;YACtC,OAAO,CAAC,MAAM,CAAC,YAAY,EAAE,MAAM,CAAC,CAAA;QACtC,CAAC;QAED,OAAO,IAAI,QAAQ,CAAC,QAAQ,CAAC,IAAI,EAAE;YACjC,OAAO;YACP,MAAM,EAAE,QAAQ,CAAC,MAAM;YACvB,UAAU,EAAE,QAAQ,CAAC,UAAU;SAChC,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;AACJ,CAAC,CAAA"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Per-request state shared by every Payload adapter call made while React Router
|
|
3
|
+
* handles one request: loaders, server components, server functions and resource
|
|
4
|
+
* routes.
|
|
5
|
+
*
|
|
6
|
+
* Payload's `ServerAdapter.getHeaders()` / `setCookie()` take no request argument
|
|
7
|
+
* (they were shaped after Next's `headers()` / `cookies()`), so the adapter needs
|
|
8
|
+
* an ambient request. React Router's own `unstable_getRequest()` covers reads, but
|
|
9
|
+
* has no way to add a header to the outgoing response — hence this store, opened
|
|
10
|
+
* by {@link payloadMiddleware} around the whole request.
|
|
11
|
+
*/
|
|
12
|
+
export type PayloadRequestStore = {
|
|
13
|
+
/** Request-scoped memoization (admin context). Never shared across requests. */
|
|
14
|
+
readonly cache: Map<string, Promise<unknown>>;
|
|
15
|
+
readonly request: Request;
|
|
16
|
+
/** Serialized `Set-Cookie` values appended to the response by the middleware. */
|
|
17
|
+
readonly setCookies: string[];
|
|
18
|
+
};
|
|
19
|
+
export declare function createRequestStore(request: Request): PayloadRequestStore;
|
|
20
|
+
export declare function runWithRequestStore<T>(store: PayloadRequestStore, fn: () => T): T;
|
|
21
|
+
/**
|
|
22
|
+
* Returns the current request store. Falls back to React Router's
|
|
23
|
+
* `unstable_getRequest()` when {@link payloadMiddleware} is not installed, in
|
|
24
|
+
* which case reads work but cookies written by Payload are dropped.
|
|
25
|
+
*/
|
|
26
|
+
export declare function getRequestStore(): PayloadRequestStore;
|
|
27
|
+
export declare function getRequest(): Request;
|
|
28
|
+
/** Memoizes `create()` for the lifetime of the current request. */
|
|
29
|
+
export declare function requestMemo<T>(key: string, create: () => Promise<T>): Promise<T>;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
2
|
+
// Namespace import: `unstable_getRequest` only exists in React Router's
|
|
3
|
+
// `react-server` build, and a named import would fail to link elsewhere.
|
|
4
|
+
import * as ReactRouter from 'react-router';
|
|
5
|
+
// Shared through globalThis: Vite can evaluate this module more than once (HMR,
|
|
6
|
+
// separate optimizer chunks), and every copy has to see the same store.
|
|
7
|
+
const storageKey = Symbol.for('payload-react-router.request-store');
|
|
8
|
+
const globalWithStorage = globalThis;
|
|
9
|
+
const storage = (globalWithStorage[storageKey] ??= new AsyncLocalStorage());
|
|
10
|
+
export function createRequestStore(request) {
|
|
11
|
+
return { cache: new Map(), request, setCookies: [] };
|
|
12
|
+
}
|
|
13
|
+
export function runWithRequestStore(store, fn) {
|
|
14
|
+
return storage.run(store, fn);
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Returns the current request store. Falls back to React Router's
|
|
18
|
+
* `unstable_getRequest()` when {@link payloadMiddleware} is not installed, in
|
|
19
|
+
* which case reads work but cookies written by Payload are dropped.
|
|
20
|
+
*/
|
|
21
|
+
export function getRequestStore() {
|
|
22
|
+
const store = storage.getStore();
|
|
23
|
+
if (store) {
|
|
24
|
+
return store;
|
|
25
|
+
}
|
|
26
|
+
let request;
|
|
27
|
+
try {
|
|
28
|
+
request = ReactRouter.unstable_getRequest?.();
|
|
29
|
+
}
|
|
30
|
+
catch {
|
|
31
|
+
request = undefined;
|
|
32
|
+
}
|
|
33
|
+
if (!request) {
|
|
34
|
+
throw new Error('payload-react-router: no request in scope. Add `payloadMiddleware` to the `middleware` export of app/root.tsx.');
|
|
35
|
+
}
|
|
36
|
+
return createRequestStore(request);
|
|
37
|
+
}
|
|
38
|
+
export function getRequest() {
|
|
39
|
+
return getRequestStore().request;
|
|
40
|
+
}
|
|
41
|
+
/** Memoizes `create()` for the lifetime of the current request. */
|
|
42
|
+
export function requestMemo(key, create) {
|
|
43
|
+
const { cache } = getRequestStore();
|
|
44
|
+
const cached = cache.get(key);
|
|
45
|
+
if (cached) {
|
|
46
|
+
return cached;
|
|
47
|
+
}
|
|
48
|
+
const promise = create();
|
|
49
|
+
cache.set(key, promise);
|
|
50
|
+
// A failed attempt must not poison later calls in the same request.
|
|
51
|
+
promise.catch(() => cache.delete(key));
|
|
52
|
+
return promise;
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=requestStore.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"requestStore.js","sourceRoot":"","sources":["../../src/server/requestStore.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAA;AACpD,wEAAwE;AACxE,yEAAyE;AACzE,OAAO,KAAK,WAAW,MAAM,cAAc,CAAA;AAqB3C,gFAAgF;AAChF,wEAAwE;AACxE,MAAM,UAAU,GAAG,MAAM,CAAC,GAAG,CAAC,oCAAoC,CAAC,CAAA;AACnE,MAAM,iBAAiB,GAAG,UAEzB,CAAA;AACD,MAAM,OAAO,GAAG,CAAC,iBAAiB,CAAC,UAAU,CAAC,KAAK,IAAI,iBAAiB,EAAuB,CAAC,CAAA;AAEhG,MAAM,UAAU,kBAAkB,CAAC,OAAgB;IACjD,OAAO,EAAE,KAAK,EAAE,IAAI,GAAG,EAAE,EAAE,OAAO,EAAE,UAAU,EAAE,EAAE,EAAE,CAAA;AACtD,CAAC;AAED,MAAM,UAAU,mBAAmB,CAAI,KAA0B,EAAE,EAAW;IAC5E,OAAO,OAAO,CAAC,GAAG,CAAC,KAAK,EAAE,EAAE,CAAC,CAAA;AAC/B,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,eAAe;IAC7B,MAAM,KAAK,GAAG,OAAO,CAAC,QAAQ,EAAE,CAAA;IAChC,IAAI,KAAK,EAAE,CAAC;QACV,OAAO,KAAK,CAAA;IACd,CAAC;IAED,IAAI,OAA4B,CAAA;IAChC,IAAI,CAAC;QACH,OAAO,GAAI,WAAuD,CAAC,mBAAmB,EAAE,EAAE,CAAA;IAC5F,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,GAAG,SAAS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