@demiurgejs/core 0.0.0 → 0.1.1

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.
Files changed (157) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +75 -2
  3. package/dist/adapter/index.d.ts +20 -0
  4. package/dist/adapter/index.d.ts.map +1 -0
  5. package/dist/browser/file-router.d.ts +35 -0
  6. package/dist/browser/file-router.d.ts.map +1 -0
  7. package/dist/browser/index.d.ts +3 -0
  8. package/dist/browser/index.d.ts.map +1 -0
  9. package/dist/chunks/index-BnX9Qxbm.js +44 -0
  10. package/dist/chunks/index-BnX9Qxbm.js.map +1 -0
  11. package/dist/chunks/ssr-BJejKlkZ.js +275 -0
  12. package/dist/chunks/ssr-BJejKlkZ.js.map +1 -0
  13. package/dist/chunks/static-files-DUjHw-4H.js +11 -0
  14. package/dist/chunks/static-files-DUjHw-4H.js.map +1 -0
  15. package/dist/chunks/streaming-DN1DnbRE.js +343 -0
  16. package/dist/chunks/streaming-DN1DnbRE.js.map +1 -0
  17. package/dist/chunks/testing-DR3eQAvY.js +2872 -0
  18. package/dist/chunks/testing-DR3eQAvY.js.map +1 -0
  19. package/dist/data/cache.d.ts +95 -0
  20. package/dist/data/cache.d.ts.map +1 -0
  21. package/dist/data/idempotency.d.ts +24 -0
  22. package/dist/data/idempotency.d.ts.map +1 -0
  23. package/dist/data/index.d.ts +5 -0
  24. package/dist/data/index.d.ts.map +1 -0
  25. package/dist/data/testing.d.ts +7 -0
  26. package/dist/data/testing.d.ts.map +1 -0
  27. package/dist/data/testing.js +134 -0
  28. package/dist/data/testing.js.map +1 -0
  29. package/dist/document/hydration.d.ts +13 -0
  30. package/dist/document/hydration.d.ts.map +1 -0
  31. package/dist/document/index.d.ts +13 -0
  32. package/dist/document/index.d.ts.map +1 -0
  33. package/dist/document/links.d.ts +17 -0
  34. package/dist/document/links.d.ts.map +1 -0
  35. package/dist/document/metadata.d.ts +62 -0
  36. package/dist/document/metadata.d.ts.map +1 -0
  37. package/dist/document/render.d.ts +29 -0
  38. package/dist/document/render.d.ts.map +1 -0
  39. package/dist/document/scripts.d.ts +24 -0
  40. package/dist/document/scripts.d.ts.map +1 -0
  41. package/dist/document/seo.d.ts +42 -0
  42. package/dist/document/seo.d.ts.map +1 -0
  43. package/dist/index.d.ts +23 -0
  44. package/dist/index.d.ts.map +1 -0
  45. package/dist/index.js +1328 -0
  46. package/dist/index.js.map +1 -0
  47. package/dist/internal/testing.d.ts +3 -0
  48. package/dist/internal/testing.d.ts.map +1 -0
  49. package/dist/internal/testing.js +22 -0
  50. package/dist/internal/testing.js.map +1 -0
  51. package/dist/node/http.d.ts +28 -0
  52. package/dist/node/http.d.ts.map +1 -0
  53. package/dist/node/index.d.ts +45 -0
  54. package/dist/node/index.d.ts.map +1 -0
  55. package/dist/node/index.js +386 -0
  56. package/dist/node/index.js.map +1 -0
  57. package/dist/node/static.d.ts +9 -0
  58. package/dist/node/static.d.ts.map +1 -0
  59. package/dist/node/streaming.d.ts +5 -0
  60. package/dist/node/streaming.d.ts.map +1 -0
  61. package/dist/package-name.d.ts +2 -0
  62. package/dist/package-name.d.ts.map +1 -0
  63. package/dist/platform/analytics.d.ts +20 -0
  64. package/dist/platform/analytics.d.ts.map +1 -0
  65. package/dist/platform/fonts.d.ts +35 -0
  66. package/dist/platform/fonts.d.ts.map +1 -0
  67. package/dist/platform/images.d.ts +49 -0
  68. package/dist/platform/images.d.ts.map +1 -0
  69. package/dist/platform/index.d.ts +9 -0
  70. package/dist/platform/index.d.ts.map +1 -0
  71. package/dist/platform/observability.d.ts +60 -0
  72. package/dist/platform/observability.d.ts.map +1 -0
  73. package/dist/route/action.d.ts +33 -0
  74. package/dist/route/action.d.ts.map +1 -0
  75. package/dist/route/http-error.d.ts +24 -0
  76. package/dist/route/http-error.d.ts.map +1 -0
  77. package/dist/route/index.d.ts +10 -0
  78. package/dist/route/index.d.ts.map +1 -0
  79. package/dist/route/page.d.ts +5 -0
  80. package/dist/route/page.d.ts.map +1 -0
  81. package/dist/route/response.d.ts +100 -0
  82. package/dist/route/response.d.ts.map +1 -0
  83. package/dist/route/types.d.ts +186 -0
  84. package/dist/route/types.d.ts.map +1 -0
  85. package/dist/route/webhook.d.ts +25 -0
  86. package/dist/route/webhook.d.ts.map +1 -0
  87. package/dist/router/index.d.ts +5 -0
  88. package/dist/router/index.d.ts.map +1 -0
  89. package/dist/router/manifest.d.ts +119 -0
  90. package/dist/router/manifest.d.ts.map +1 -0
  91. package/dist/router/navigation-data.d.ts +9 -0
  92. package/dist/router/navigation-data.d.ts.map +1 -0
  93. package/dist/routing/generate.d.ts +14 -0
  94. package/dist/routing/generate.d.ts.map +1 -0
  95. package/dist/routing/index.d.ts +3 -0
  96. package/dist/routing/index.d.ts.map +1 -0
  97. package/dist/routing/types.d.ts +38 -0
  98. package/dist/routing/types.d.ts.map +1 -0
  99. package/dist/security/audit.d.ts +16 -0
  100. package/dist/security/audit.d.ts.map +1 -0
  101. package/dist/security/cors.d.ts +7 -0
  102. package/dist/security/cors.d.ts.map +1 -0
  103. package/dist/security/csrf.d.ts +15 -0
  104. package/dist/security/csrf.d.ts.map +1 -0
  105. package/dist/security/env.d.ts +69 -0
  106. package/dist/security/env.d.ts.map +1 -0
  107. package/dist/security/index.d.ts +17 -0
  108. package/dist/security/index.d.ts.map +1 -0
  109. package/dist/security/policy.d.ts +18 -0
  110. package/dist/security/policy.d.ts.map +1 -0
  111. package/dist/security/rate-limit.d.ts +6 -0
  112. package/dist/security/rate-limit.d.ts.map +1 -0
  113. package/dist/security/report.d.ts +13 -0
  114. package/dist/security/report.d.ts.map +1 -0
  115. package/dist/security/request.d.ts +11 -0
  116. package/dist/security/request.d.ts.map +1 -0
  117. package/dist/security/types.d.ts +137 -0
  118. package/dist/security/types.d.ts.map +1 -0
  119. package/dist/security/upload.d.ts +23 -0
  120. package/dist/security/upload.d.ts.map +1 -0
  121. package/dist/security/websocket.d.ts +13 -0
  122. package/dist/security/websocket.d.ts.map +1 -0
  123. package/dist/server/errors.d.ts +13 -0
  124. package/dist/server/errors.d.ts.map +1 -0
  125. package/dist/server/failure-site.d.ts +2 -0
  126. package/dist/server/failure-site.d.ts.map +1 -0
  127. package/dist/server/fallbacks.d.ts +10 -0
  128. package/dist/server/fallbacks.d.ts.map +1 -0
  129. package/dist/server/index.d.ts +14 -0
  130. package/dist/server/index.d.ts.map +1 -0
  131. package/dist/server/negotiate.d.ts +3 -0
  132. package/dist/server/negotiate.d.ts.map +1 -0
  133. package/dist/server/not-found.d.ts +11 -0
  134. package/dist/server/not-found.d.ts.map +1 -0
  135. package/dist/server/problem.d.ts +18 -0
  136. package/dist/server/problem.d.ts.map +1 -0
  137. package/dist/server/render-tree.d.ts +4 -0
  138. package/dist/server/render-tree.d.ts.map +1 -0
  139. package/dist/server/request-handler.d.ts +40 -0
  140. package/dist/server/request-handler.d.ts.map +1 -0
  141. package/dist/server/request-metadata.d.ts +7 -0
  142. package/dist/server/request-metadata.d.ts.map +1 -0
  143. package/dist/server/ssr.d.ts +17 -0
  144. package/dist/server/ssr.d.ts.map +1 -0
  145. package/dist/static/index.d.ts +28 -0
  146. package/dist/static/index.d.ts.map +1 -0
  147. package/dist/static/index.js +377 -0
  148. package/dist/static/index.js.map +1 -0
  149. package/dist/static-files.d.ts +5 -0
  150. package/dist/static-files.d.ts.map +1 -0
  151. package/dist/vite/index.d.ts +4 -0
  152. package/dist/vite/index.d.ts.map +1 -0
  153. package/dist/vite/index.js +746 -0
  154. package/dist/vite/index.js.map +1 -0
  155. package/dist/vite/plugin.d.ts +37 -0
  156. package/dist/vite/plugin.d.ts.map +1 -0
  157. package/package.json +93 -4
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 North Shore Software Labs
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,76 @@
1
- # @demiurgejs/core
1
+ # Demiurge
2
2
 
3
- Reserved for Demiurge JS. No implementation is published yet.
3
+ Demiurge is a React framework for secure routing, server rendering, and
4
+ framework-managed HTML documents. An application can run in one production
5
+ Node process. Adapter boundaries support other deployment configurations.
6
+
7
+ ## Requirements
8
+
9
+ - Node.js 22.13 or newer
10
+ - React and React DOM 19
11
+ - Vite 6 when using the `@demiurgejs/core/vite` build integration
12
+
13
+ ## Install
14
+
15
+ ```sh
16
+ pnpm add @demiurgejs/core react react-dom
17
+ pnpm add -D vite @vitejs/plugin-react typescript @types/node @types/react @types/react-dom
18
+ ```
19
+
20
+ Define a route under `src/routes`:
21
+
22
+ ```tsx
23
+ import { page } from "@demiurgejs/core";
24
+
25
+ export const GET = page({
26
+ view: () => <main>Hello from Demiurge</main>,
27
+ });
28
+ ```
29
+
30
+ Page applications also own their root `src/routes/@not-found.tsx` so a missing
31
+ URL never falls back to framework-branded markup:
32
+
33
+ ```tsx
34
+ export default function NotFound({ pathname }: { pathname: string }) {
35
+ return <main>Nothing at {pathname}</main>;
36
+ }
37
+ ```
38
+
39
+ Add the framework to Vite:
40
+
41
+ ```ts
42
+ import react from "@vitejs/plugin-react";
43
+ import { defineConfig } from "vite";
44
+ import { demiurge } from "@demiurgejs/core/vite";
45
+
46
+ export default defineConfig({
47
+ plugins: [demiurge({ typedRoutes: true }), react()],
48
+ });
49
+ ```
50
+
51
+ Run `vite` for development or `vite build` for a browser build. There is no
52
+ `index.html` to write: the framework renders the document and attaches CSP
53
+ nonces to what it emits.
54
+
55
+ Production SSR uses a separate server build and a runtime adapter. The minimum
56
+ working setup is in the
57
+ [README quickstart](https://github.com/NorthShoreSoftwareLabs/demiurge#deploy),
58
+ and [Node deployment](https://github.com/NorthShoreSoftwareLabs/demiurge/blob/main/docs/guides/node-deployment.md)
59
+ covers host allowlists, proxy trust, timeouts, and graceful shutdown.
60
+
61
+ ## Package entry points
62
+
63
+ - `@demiurgejs/core` — routes, document APIs, security, caching, and browser runtime
64
+ - `@demiurgejs/core/node` — production Node HTTP, SSR, and static-file adapter
65
+ - `@demiurgejs/core/static` — static-output adapter
66
+ - `@demiurgejs/core/vite` — Vite framework plugin
67
+ - `@demiurgejs/core/data/testing` — cache-store conformance contract
68
+ - `@demiurgejs/core/internal/testing` — explicitly unstable test helpers
69
+
70
+ The Vite entry point is optional. Core, Node, and static consumers do not need
71
+ to install Vite unless their own build imports `@demiurgejs/core/vite`.
72
+
73
+ ## Support and license
74
+
75
+ Report defects through [GitHub Issues](https://github.com/NorthShoreSoftwareLabs/demiurge/issues).
76
+ Demiurge is available under the [MIT License](./LICENSE).
@@ -0,0 +1,20 @@
1
+ export type AdapterCapability = "backgroundLifetime" | "crossOriginIsolationHeaders" | "nonceInjection" | "sharedCache" | "staticOutput" | "streaming" | "webSocket" | "webTransport";
2
+ export type AdapterCapabilityMap = Record<AdapterCapability, boolean>;
3
+ export type Adapter = {
4
+ capabilities: AdapterCapabilityMap;
5
+ name: string;
6
+ };
7
+ export type AdapterDefinition = {
8
+ capabilities?: Partial<AdapterCapabilityMap>;
9
+ name: string;
10
+ };
11
+ export type AdapterCapabilityCheck = {
12
+ adapter: string;
13
+ missing: AdapterCapability[];
14
+ ok: boolean;
15
+ required: AdapterCapability[];
16
+ };
17
+ export declare function defineAdapter(definition: AdapterDefinition): Adapter;
18
+ export declare function checkAdapterCapabilities(adapter: Adapter, required: readonly AdapterCapability[]): AdapterCapabilityCheck;
19
+ export declare function assertAdapterCapabilities(adapter: Adapter, required: readonly AdapterCapability[]): AdapterCapabilityCheck;
20
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/adapter/index.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,iBAAiB,GACzB,oBAAoB,GACpB,6BAA6B,GAC7B,gBAAgB,GAChB,aAAa,GACb,cAAc,GACd,WAAW,GACX,WAAW,GACX,cAAc,CAAC;AAEnB,MAAM,MAAM,oBAAoB,GAAG,MAAM,CAAC,iBAAiB,EAAE,OAAO,CAAC,CAAC;AAEtE,MAAM,MAAM,OAAO,GAAG;IACpB,YAAY,EAAE,oBAAoB,CAAC;IACnC,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG;IAC9B,YAAY,CAAC,EAAE,OAAO,CAAC,oBAAoB,CAAC,CAAC;IAC7C,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,MAAM,MAAM,sBAAsB,GAAG;IACnC,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,iBAAiB,EAAE,CAAC;IAC7B,EAAE,EAAE,OAAO,CAAC;IACZ,QAAQ,EAAE,iBAAiB,EAAE,CAAC;CAC/B,CAAC;AAaF,wBAAgB,aAAa,CAAC,UAAU,EAAE,iBAAiB,GAAG,OAAO,CAQpE;AAED,wBAAgB,wBAAwB,CACtC,OAAO,EAAE,OAAO,EAChB,QAAQ,EAAE,SAAS,iBAAiB,EAAE,GACrC,sBAAsB,CAYxB;AAED,wBAAgB,yBAAyB,CACvC,OAAO,EAAE,OAAO,EAChB,QAAQ,EAAE,SAAS,iBAAiB,EAAE,0BAWvC"}
@@ -0,0 +1,35 @@
1
+ import { ComponentType, ReactNode } from "react";
2
+ import { type InitialRouteData } from "../document";
3
+ import { type NotFoundProps, type RouteImporter } from "../route";
4
+ import { type PendingRouteMatch } from "../router";
5
+ import { type AppHref, type LinkTo } from "../routing";
6
+ export type NavigationDataLoader = (request: Request) => Promise<InitialRouteData>;
7
+ export type FileRouterOptions = {
8
+ initialMatch?: PendingRouteMatch;
9
+ loadNavigationData?: NavigationDataLoader;
10
+ navigation?: "document" | "server";
11
+ routes: Record<string, RouteImporter>;
12
+ loading?: ComponentType;
13
+ notFound?: ComponentType<NotFoundProps>;
14
+ };
15
+ export declare function createFileRouter(options: FileRouterOptions): () => import("react").FunctionComponentElement<import("react").ProviderProps<RouterApi>>;
16
+ export type HydrateFileRouterOptions = Omit<FileRouterOptions, "initialMatch"> & {
17
+ initialData?: InitialRouteData;
18
+ root?: Element;
19
+ };
20
+ export declare function hydrateFileRouter(options: HydrateFileRouterOptions): Promise<void>;
21
+ type ReactDomClientApi = Pick<typeof import("react-dom/client"), "createRoot" | "hydrateRoot">;
22
+ type ReactDomClientModule = Partial<ReactDomClientApi> & {
23
+ default?: ReactDomClientApi;
24
+ };
25
+ export declare function resolveReactDomClient(module: ReactDomClientModule): ReactDomClientApi;
26
+ export declare function Link<const TTo extends AppHref>(props: LinkTo<TTo> & {
27
+ children: ReactNode;
28
+ className?: string;
29
+ }): import("react").JSX.Element;
30
+ type RouterApi = {
31
+ navigation: "document" | "server";
32
+ push(to: string): void;
33
+ };
34
+ export {};
35
+ //# sourceMappingURL=file-router.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"file-router.d.ts","sourceRoot":"","sources":["../../src/browser/file-router.tsx"],"names":[],"mappings":"AAAA,OAAO,EAEL,aAAa,EAEb,SAAS,EAQV,MAAM,OAAO,CAAC;AACf,O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AAgB,IAAI,CAAC,KAAK,CAAC,GAAG,SAAS,OAAO,EAC5C,KAAK,EAAE,MAAM,CAAC,GAAG,CAAC,GAAG;IACnB,QAAQ,EAAE,SAAS,CAAC;IACpB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,+BAsBF;AA4LD,KAAK,SAAS,GAAG;IACf,UAAU,EAAE,UAAU,GAAG,QAAQ,CAAC;IAClC,IAAI,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI,CAAC;CACxB,CAAC"}
@@ -0,0 +1,3 @@
1
+ export { createFileRouter, hydrateFileRouter, Link } from "./file-router";
2
+ export type { HydrateFileRouterOptions } from "./file-router";
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/browser/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AAC1E,YAAY,EAAE,wBAAwB,EAAE,MAAM,eAAe,CAAC"}
@@ -0,0 +1,44 @@
1
+ const n = {
2
+ backgroundLifetime: !1,
3
+ crossOriginIsolationHeaders: !1,
4
+ nonceInjection: !1,
5
+ sharedCache: !1,
6
+ staticOutput: !1,
7
+ streaming: !1,
8
+ webSocket: !1,
9
+ webTransport: !1
10
+ };
11
+ function c(e) {
12
+ return {
13
+ capabilities: {
14
+ ...n,
15
+ ...e.capabilities
16
+ },
17
+ name: e.name
18
+ };
19
+ }
20
+ function r(e, i) {
21
+ const a = [...new Set(i)], s = a.filter(
22
+ (t) => !e.capabilities[t]
23
+ );
24
+ return {
25
+ adapter: e.name,
26
+ missing: s,
27
+ ok: s.length === 0,
28
+ required: a
29
+ };
30
+ }
31
+ function o(e, i) {
32
+ const a = r(e, i);
33
+ if (!a.ok)
34
+ throw new Error(
35
+ `Adapter "${e.name}" does not support required capabilities: ${a.missing.join(", ")}.`
36
+ );
37
+ return a;
38
+ }
39
+ export {
40
+ o as a,
41
+ r as c,
42
+ c as d
43
+ };
44
+ //# sourceMappingURL=index-BnX9Qxbm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index-BnX9Qxbm.js","sources":["../../src/adapter/index.ts"],"sourcesContent":["export type AdapterCapability =\n | \"backgroundLifetime\"\n | \"crossOriginIsolationHeaders\"\n | \"nonceInjection\"\n | \"sharedCache\"\n | \"staticOutput\"\n | \"streaming\"\n | \"webSocket\"\n | \"webTransport\";\n\nexport type AdapterCapabilityMap = Record<AdapterCapability, boolean>;\n\nexport type Adapter = {\n capabilities: AdapterCapabilityMap;\n name: string;\n};\n\nexport type AdapterDefinition = {\n capabilities?: Partial<AdapterCapabilityMap>;\n name: string;\n};\n\nexport type AdapterCapabilityCheck = {\n adapter: string;\n missing: AdapterCapability[];\n ok: boolean;\n required: AdapterCapability[];\n};\n\nconst defaultCapabilities = {\n backgroundLifetime: false,\n crossOriginIsolationHeaders: false,\n nonceInjection: false,\n sharedCache: false,\n staticOutput: false,\n streaming: false,\n webSocket: false,\n webTransport: false,\n} satisfies AdapterCapabilityMap;\n\nexport function defineAdapter(definition: AdapterDefinition): Adapter {\n return {\n capabilities: {\n ...defaultCapabilities,\n ...definition.capabilities,\n },\n name: definition.name,\n };\n}\n\nexport function checkAdapterCapabilities(\n adapter: Adapter,\n required: readonly AdapterCapability[],\n): AdapterCapabilityCheck {\n const uniqueRequired = [...new Set(required)];\n const missing = uniqueRequired.filter(\n (capability) => !adapter.capabilities[capability],\n );\n\n return {\n adapter: adapter.name,\n missing,\n ok: missing.length === 0,\n required: uniqueRequired,\n };\n}\n\nexport function assertAdapterCapabilities(\n adapter: Adapter,\n required: readonly AdapterCapability[],\n) {\n const check = checkAdapterCapabilities(adapter, required);\n\n if (!check.ok) {\n throw new Error(\n `Adapter \"${adapter.name}\" does not support required capabilities: ${check.missing.join(\", \")}.`,\n );\n }\n\n return check;\n}\n"],"names":["defaultCapabilities","defineAdapter","definition","checkAdapterCapabilities","adapter","required","uniqueRequired","missing","capability","assertAdapterCapabilities","check"],"mappings":"AA6BA,MAAMA,IAAsB;AAAA,EAC1B,oBAAoB;AAAA,EACpB,6BAA6B;AAAA,EAC7B,gBAAgB;AAAA,EAChB,aAAa;AAAA,EACb,cAAc;AAAA,EACd,WAAW;AAAA,EACX,WAAW;AAAA,EACX,cAAc;AAChB;AAEO,SAASC,EAAcC,GAAwC;AACpE,SAAO;AAAA,IACL,cAAc;AAAA,MACZ,GAAGF;AAAA,MACH,GAAGE,EAAW;AAAA,IAAA;AAAA,IAEhB,MAAMA,EAAW;AAAA,EAAA;AAErB;AAEO,SAASC,EACdC,GACAC,GACwB;AACxB,QAAMC,IAAiB,CAAC,GAAG,IAAI,IAAID,CAAQ,CAAC,GACtCE,IAAUD,EAAe;AAAA,IAC7B,CAACE,MAAe,CAACJ,EAAQ,aAAaI,CAAU;AAAA,EAAA;AAGlD,SAAO;AAAA,IACL,SAASJ,EAAQ;AAAA,IACjB,SAAAG;AAAA,IACA,IAAIA,EAAQ,WAAW;AAAA,IACvB,UAAUD;AAAA,EAAA;AAEd;AAEO,SAASG,EACdL,GACAC,GACA;AACA,QAAMK,IAAQP,EAAyBC,GAASC,CAAQ;AAExD,MAAI,CAACK,EAAM;AACT,UAAM,IAAI;AAAA,MACR,YAAYN,EAAQ,IAAI,6CAA6CM,EAAM,QAAQ,KAAK,IAAI,CAAC;AAAA,IAAA;AAIjG,SAAOA;AACT;"}
@@ -0,0 +1,275 @@
1
+ import { renderToString as b } from "react-dom/server";
2
+ import { createElement as h } from "react";
3
+ const g = "__demiurge_data", E = "data-demiurge-hydrate", v = "data-demiurge-fallback";
4
+ function w(e, n = {}) {
5
+ return S(
6
+ JSON.stringify({ data: e, hasData: !0, ...n })
7
+ );
8
+ }
9
+ function F(e) {
10
+ const n = e.getElementById(g), t = n?.tagName === "TEMPLATE" ? n.content.textContent : n?.textContent;
11
+ if (t)
12
+ try {
13
+ return JSON.parse(t);
14
+ } catch (o) {
15
+ throw new Error(
16
+ "Demiurge could not parse the initial route data payload.",
17
+ { cause: o }
18
+ );
19
+ }
20
+ }
21
+ function S(e) {
22
+ return e.replace(/&/g, "\\u0026").replace(/</g, "\\u003c").replace(/>/g, "\\u003e").replace(/\u2028/g, "\\u2028").replace(/\u2029/g, "\\u2029");
23
+ }
24
+ const k = "data-demiurge-structured-data";
25
+ function _(e) {
26
+ if (e.body) {
27
+ const { html: n, ...t } = e.body, { prefix: o, suffix: a } = x({ ...e, body: t });
28
+ return `${o}${n}${a}`;
29
+ }
30
+ return B(e);
31
+ }
32
+ function x({
33
+ body: e,
34
+ entrySrc: n,
35
+ lang: t = "en",
36
+ links: o = [],
37
+ metadata: a,
38
+ nonce: c,
39
+ scripts: s = [],
40
+ styles: p = [],
41
+ title: d = "Demiurge App"
42
+ }) {
43
+ const f = a?.title ?? d, $ = [
44
+ ...s.map((R) => ` ${D(R, c)}`),
45
+ C(e.data, e.navigation),
46
+ ...n ? [A(n, c)] : []
47
+ ].join(`
48
+ `);
49
+ return {
50
+ prefix: `<!doctype html>
51
+ <html lang="${i(t)}">
52
+ <head>
53
+ ${T({ links: o, metadata: a, nonce: c, styles: p, title: f })}
54
+ </head>
55
+ <body>
56
+ ${O(e)}`,
57
+ suffix: `</div>
58
+ ${$}
59
+ </body>
60
+ </html>
61
+ `
62
+ };
63
+ }
64
+ function B({
65
+ entrySrc: e,
66
+ lang: n = "en",
67
+ links: t = [],
68
+ metadata: o,
69
+ nonce: a,
70
+ scripts: c = [],
71
+ styles: s = [],
72
+ title: p = "Demiurge App"
73
+ }) {
74
+ const d = o?.title ?? p, f = [
75
+ I(),
76
+ ...c.map(($) => ` ${D($, a)}`),
77
+ ...e ? [A(e, a)] : []
78
+ ].join(`
79
+ `);
80
+ return `<!doctype html>
81
+ <html lang="${i(n)}">
82
+ <head>
83
+ ${T({ links: t, metadata: o, nonce: a, styles: s, title: d })}
84
+ </head>
85
+ <body>
86
+ ${f}
87
+ </body>
88
+ </html>
89
+ `;
90
+ }
91
+ function I(e) {
92
+ return ' <div id="root"></div>';
93
+ }
94
+ function O(e) {
95
+ const n = e.fallback ? ` ${v}="${i(e.fallback)}"` : "";
96
+ return ` <div id="root" ${E}=""${n}>`;
97
+ }
98
+ function C(e, n) {
99
+ return ` <template id="${g}">${w(e, { navigation: n })}</template>`;
100
+ }
101
+ function A(e, n) {
102
+ return ` <script type="module" src="${i(e)}"${r("nonce", n)}><\/script>`;
103
+ }
104
+ function T({
105
+ links: e,
106
+ metadata: n,
107
+ nonce: t,
108
+ styles: o,
109
+ title: a
110
+ }) {
111
+ return [
112
+ l({
113
+ content: n?.charset ?? "UTF-8",
114
+ name: "charset"
115
+ }),
116
+ l({
117
+ content: n?.viewport ?? "width=device-width, initial-scale=1.0",
118
+ name: "viewport"
119
+ }),
120
+ ` <title>${i(a)}</title>`,
121
+ ...n?.description ? [
122
+ l({
123
+ content: n.description,
124
+ name: "description"
125
+ })
126
+ ] : [],
127
+ ...n?.canonical ? [
128
+ y({
129
+ href: n.canonical,
130
+ rel: "canonical"
131
+ })
132
+ ] : [],
133
+ ...M(n),
134
+ ...G(n),
135
+ ...(n?.custom ?? []).map(N),
136
+ ...(n?.structuredData ?? []).map(
137
+ (c) => H(c, t)
138
+ ),
139
+ ...o.map(
140
+ (c) => ` <link rel="stylesheet" href="${i(c)}" />`
141
+ ),
142
+ ...e.map(y)
143
+ ].join(`
144
+ `);
145
+ }
146
+ function M(e) {
147
+ if (!e?.robots)
148
+ return [];
149
+ const n = [
150
+ e.robots.index === !1 ? "noindex" : "index",
151
+ e.robots.follow === !1 ? "nofollow" : "follow"
152
+ ];
153
+ return [
154
+ l({
155
+ content: n.join(", "),
156
+ name: "robots"
157
+ })
158
+ ];
159
+ }
160
+ function G(e) {
161
+ return e?.openGraph ? [
162
+ e.openGraph.title ? l({
163
+ content: e.openGraph.title,
164
+ property: "og:title"
165
+ }) : null,
166
+ e.openGraph.description ? l({
167
+ content: e.openGraph.description,
168
+ property: "og:description"
169
+ }) : null,
170
+ e.openGraph.image ? l({
171
+ content: e.openGraph.image,
172
+ property: "og:image"
173
+ }) : null
174
+ ].filter((n) => !!n) : [];
175
+ }
176
+ function N(e) {
177
+ return e.kind === "link" ? y(e) : l(e);
178
+ }
179
+ function H(e, n) {
180
+ return ` <script type="application/ld+json"${n ? "" : ` ${k}`}${r("nonce", n)}>${U(JSON.stringify(e.value))}<\/script>`;
181
+ }
182
+ function l(e) {
183
+ if (e.name === "charset")
184
+ return ` <meta charset="${i(e.content)}" />`;
185
+ const n = e.name ? ` name="${i(e.name)}"` : "", t = e.property ? ` property="${i(e.property)}"` : "";
186
+ return ` <meta${n}${t} content="${i(e.content)}" />`;
187
+ }
188
+ function y(e) {
189
+ return ` <link${r("rel", e.rel)}${r("href", e.href)}${r("as", e.as)}${r("type", e.type)}${r("crossorigin", e.crossOrigin)}${r("hreflang", e.hrefLang)} />`;
190
+ }
191
+ function D(e, n) {
192
+ return `<script${r("id", e.id)}${r("src", e.src)}${r("type", e.type ?? L(e.strategy))}${r("nonce", e.nonce ?? n)}${r("integrity", e.integrity)}${r("referrerpolicy", e.referrerPolicy)}${r("data-api", e.dataApi)}${r("data-domain", e.dataDomain)}${m("async", e.async)}${m("defer", e.defer)}><\/script>`;
193
+ }
194
+ function L(e) {
195
+ return e === "module" ? "module" : void 0;
196
+ }
197
+ function r(e, n) {
198
+ return n ? ` ${e}="${i(n)}"` : "";
199
+ }
200
+ function m(e, n) {
201
+ return n ? ` ${e}` : "";
202
+ }
203
+ function i(e) {
204
+ return e.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;").replaceAll('"', "&quot;");
205
+ }
206
+ function U(e) {
207
+ return e.replaceAll("<", "\\u003c").replaceAll(">", "\\u003e").replaceAll("\u2028", "\\u2028").replaceAll("\u2029", "\\u2029");
208
+ }
209
+ const u = /* @__PURE__ */ new WeakMap();
210
+ function Y(e) {
211
+ return u.get(e);
212
+ }
213
+ function z(e, n) {
214
+ u.set(e, n);
215
+ }
216
+ function W(e, n) {
217
+ const t = u.get(e);
218
+ t && u.set(n, t);
219
+ }
220
+ function j(e) {
221
+ const n = h(e.page, {
222
+ data: e.data,
223
+ path: e.path,
224
+ pathname: e.pathname
225
+ });
226
+ return e.layouts.reduceRight(
227
+ (t, o) => h(o, {
228
+ children: t,
229
+ path: e.path,
230
+ pathname: e.pathname
231
+ }),
232
+ n
233
+ );
234
+ }
235
+ function J(e, n = {}) {
236
+ const t = b(j(e));
237
+ return _({
238
+ body: {
239
+ data: e.data,
240
+ html: t,
241
+ navigation: e.render.mode === "static" ? "document" : n.navigation
242
+ },
243
+ entrySrc: n.clientEntry,
244
+ lang: n.lang,
245
+ links: e.links,
246
+ metadata: e.metadata,
247
+ nonce: n.nonce,
248
+ scripts: e.scripts,
249
+ styles: n.styles,
250
+ title: n.title
251
+ });
252
+ }
253
+ function K(e, n = {}) {
254
+ const t = J(e, n);
255
+ return new Response(t, {
256
+ headers: {
257
+ "content-type": "text/html; charset=utf-8"
258
+ }
259
+ });
260
+ }
261
+ export {
262
+ E as H,
263
+ k as S,
264
+ x as a,
265
+ _ as b,
266
+ j as c,
267
+ J as d,
268
+ F as e,
269
+ v as f,
270
+ Y as g,
271
+ W as h,
272
+ K as r,
273
+ z as s
274
+ };
275
+ //# sourceMappingURL=ssr-BJejKlkZ.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ssr-BJejKlkZ.js","sources":["../../src/document/hydration.ts","../../src/document/render.ts","../../src/server/request-metadata.ts","../../src/server/render-tree.ts","../../src/server/ssr.ts"],"sourcesContent":["export type InitialRouteData = {\n data?: unknown;\n hasData: boolean;\n navigation?: \"document\";\n};\n\nexport const HYDRATION_DATA_ELEMENT_ID = \"__demiurge_data\";\nexport const HYDRATION_ROOT_ATTRIBUTE = \"data-demiurge-hydrate\";\n// Marks a server document as a fallback, not a page. The client hydrates markup\n// that it can reproduce. It replaces other markup. This attribute distinguishes\n// a server 404 from a page that does not match the client manifest.\nexport const HYDRATION_FALLBACK_ATTRIBUTE = \"data-demiurge-fallback\";\n\nexport function serializeInitialRouteData(\n data: unknown,\n options: { navigation?: \"document\" } = {},\n) {\n return escapeJsonScript(\n JSON.stringify({ data, hasData: true, ...options }),\n );\n}\n\nexport function readInitialRouteData(source: Document) {\n const element = source.getElementById(HYDRATION_DATA_ELEMENT_ID);\n const serialized = element?.tagName === \"TEMPLATE\"\n ? (element as HTMLTemplateElement).content.textContent\n : element?.textContent;\n\n if (!serialized) {\n return undefined;\n }\n\n try {\n return JSON.parse(serialized) as InitialRouteData;\n } catch (error) {\n throw new Error(\n \"Demiurge could not parse the initial route data payload.\",\n { cause: error },\n );\n }\n}\n\nfunction escapeJsonScript(value: string) {\n return value\n .replace(/&/g, \"\\\\u0026\")\n .replace(/</g, \"\\\\u003c\")\n .replace(/>/g, \"\\\\u003e\")\n .replace(/\\u2028/g, \"\\\\u2028\")\n .replace(/\\u2029/g, \"\\\\u2029\");\n}\n","import {\n HYDRATION_DATA_ELEMENT_ID,\n HYDRATION_FALLBACK_ATTRIBUTE,\n HYDRATION_ROOT_ATTRIBUTE,\n serializeInitialRouteData,\n} from \"./hydration\";\nimport type {\n DocumentMetadataTag,\n LinkTag,\n ResolvedMetadata,\n StructuredDataTag,\n} from \"./metadata\";\nimport type { ScriptTag } from \"./scripts\";\n\nexport const STRUCTURED_DATA_ATTRIBUTE = \"data-demiurge-structured-data\";\n\nexport type DocumentBody = {\n data: unknown;\n fallback?: \"not-found\";\n html: string;\n navigation?: \"document\";\n};\n\nexport type RenderDocumentOptions = {\n body?: DocumentBody;\n entrySrc?: string;\n lang?: string;\n links?: LinkTag[];\n metadata?: ResolvedMetadata;\n nonce?: string;\n scripts?: ScriptTag[];\n styles?: string[];\n title?: string;\n};\n\nexport type RenderDocumentShellOptions = Omit<RenderDocumentOptions, \"body\"> & {\n body: Omit<DocumentBody, \"html\">;\n};\n\nexport function renderDocument(options: RenderDocumentOptions) {\n if (options.body) {\n const { html, ...body } = options.body;\n const { prefix, suffix } = renderDocumentShell({ ...options, body });\n\n return `${prefix}${html}${suffix}`;\n }\n\n return renderDocumentWithoutBody(options);\n}\n\nexport function renderDocumentShell({\n body,\n entrySrc,\n lang = \"en\",\n links = [],\n metadata,\n nonce,\n scripts = [],\n styles = [],\n title = \"Demiurge App\",\n}: RenderDocumentShellOptions) {\n const documentTitle = metadata?.title ?? title;\n const trailingBodyContent = [\n ...scripts.map((scriptTag) => ` ${renderScriptTag(scriptTag, nonce)}`),\n renderBootstrapData(body.data, body.navigation),\n ...(entrySrc ? [renderEntryScript(entrySrc, nonce)] : []),\n ].join(\"\\n\");\n\n return {\n prefix: `<!doctype html>\n<html lang=\"${escapeHtml(lang)}\">\n <head>\n${renderHeadTags({ links, metadata, nonce, styles, title: documentTitle })}\n </head>\n <body>\n${renderRootStart(body)}`,\n suffix: `</div>\n${trailingBodyContent}\n </body>\n</html>\n`,\n };\n}\n\nfunction renderDocumentWithoutBody({\n entrySrc,\n lang = \"en\",\n links = [],\n metadata,\n nonce,\n scripts = [],\n styles = [],\n title = \"Demiurge App\",\n}: RenderDocumentOptions) {\n const documentTitle = metadata?.title ?? title;\n const bodyContent = [\n renderRootElement(),\n ...scripts.map((scriptTag) => ` ${renderScriptTag(scriptTag, nonce)}`),\n ...(entrySrc ? [renderEntryScript(entrySrc, nonce)] : []),\n ].join(\"\\n\");\n\n return `<!doctype html>\n<html lang=\"${escapeHtml(lang)}\">\n <head>\n${renderHeadTags({ links, metadata, nonce, styles, title: documentTitle })}\n </head>\n <body>\n${bodyContent}\n </body>\n</html>\n`;\n}\n\nfunction renderRootElement(body?: DocumentBody) {\n if (!body) {\n return ` <div id=\"root\"></div>`;\n }\n\n return `${renderRootStart(body)}${body.html}</div>`;\n}\n\nfunction renderRootStart(body: Omit<DocumentBody, \"html\">) {\n const fallback = body.fallback\n ? ` ${HYDRATION_FALLBACK_ATTRIBUTE}=\"${escapeHtml(body.fallback)}\"`\n : \"\";\n\n return ` <div id=\"root\" ${HYDRATION_ROOT_ATTRIBUTE}=\"\"${fallback}>`;\n}\n\nfunction renderBootstrapData(data: unknown, navigation?: \"document\") {\n return ` <template id=\"${HYDRATION_DATA_ELEMENT_ID}\">${serializeInitialRouteData(data, { navigation })}</template>`;\n}\n\nfunction renderEntryScript(entrySrc: string, nonce: string | undefined) {\n return ` <script type=\"module\" src=\"${escapeHtml(entrySrc)}\"${renderAttribute(\"nonce\", nonce)}></script>`;\n}\n\nfunction renderHeadTags({\n links,\n metadata,\n nonce,\n styles,\n title,\n}: {\n links: LinkTag[];\n metadata: ResolvedMetadata | undefined;\n nonce: string | undefined;\n styles: string[];\n title: string;\n}) {\n return [\n renderMetaTag({\n content: metadata?.charset ?? \"UTF-8\",\n kind: \"meta\",\n name: \"charset\",\n }),\n renderMetaTag({\n content: metadata?.viewport ?? \"width=device-width, initial-scale=1.0\",\n kind: \"meta\",\n name: \"viewport\",\n }),\n ` <title>${escapeHtml(title)}</title>`,\n ...(metadata?.description\n ? [\n renderMetaTag({\n content: metadata.description,\n kind: \"meta\",\n name: \"description\",\n }),\n ]\n : []),\n ...(metadata?.canonical\n ? [\n renderLinkTag({\n href: metadata.canonical,\n kind: \"link\",\n rel: \"canonical\",\n }),\n ]\n : []),\n ...renderRobotsTags(metadata),\n ...renderOpenGraphTags(metadata),\n ...(metadata?.custom ?? []).map(renderDocumentMetadataTag),\n ...(metadata?.structuredData ?? []).map((tag) =>\n renderStructuredDataTag(tag, nonce),\n ),\n ...styles.map(\n (href) => ` <link rel=\"stylesheet\" href=\"${escapeHtml(href)}\" />`,\n ),\n ...links.map(renderLinkTag),\n ].join(\"\\n\");\n}\n\nfunction renderRobotsTags(metadata: ResolvedMetadata | undefined) {\n if (!metadata?.robots) {\n return [];\n }\n\n const directives = [\n metadata.robots.index === false ? \"noindex\" : \"index\",\n metadata.robots.follow === false ? \"nofollow\" : \"follow\",\n ];\n\n return [\n renderMetaTag({\n content: directives.join(\", \"),\n kind: \"meta\",\n name: \"robots\",\n }),\n ];\n}\n\nfunction renderOpenGraphTags(metadata: ResolvedMetadata | undefined) {\n if (!metadata?.openGraph) {\n return [];\n }\n\n return [\n metadata.openGraph.title\n ? renderMetaTag({\n content: metadata.openGraph.title,\n kind: \"meta\",\n property: \"og:title\",\n })\n : null,\n metadata.openGraph.description\n ? renderMetaTag({\n content: metadata.openGraph.description,\n kind: \"meta\",\n property: \"og:description\",\n })\n : null,\n metadata.openGraph.image\n ? renderMetaTag({\n content: metadata.openGraph.image,\n kind: \"meta\",\n property: \"og:image\",\n })\n : null,\n ].filter((tag): tag is string => Boolean(tag));\n}\n\nfunction renderDocumentMetadataTag(tag: DocumentMetadataTag) {\n if (tag.kind === \"link\") {\n return renderLinkTag(tag);\n }\n\n return renderMetaTag(tag);\n}\n\nfunction renderStructuredDataTag(\n tag: StructuredDataTag,\n nonce: string | undefined,\n) {\n const ownership = nonce ? \"\" : ` ${STRUCTURED_DATA_ATTRIBUTE}`;\n\n return ` <script type=\"application/ld+json\"${ownership}${renderAttribute(\"nonce\", nonce)}>${escapeJsonScript(JSON.stringify(tag.value))}</script>`;\n}\n\nfunction renderMetaTag(tag: DocumentMetadataTag & { kind: \"meta\" }) {\n if (tag.name === \"charset\") {\n return ` <meta charset=\"${escapeHtml(tag.content)}\" />`;\n }\n\n const name = tag.name ? ` name=\"${escapeHtml(tag.name)}\"` : \"\";\n const property = tag.property ? ` property=\"${escapeHtml(tag.property)}\"` : \"\";\n\n return ` <meta${name}${property} content=\"${escapeHtml(tag.content)}\" />`;\n}\n\nfunction renderLinkTag(tag: LinkTag) {\n return ` <link${renderAttribute(\"rel\", tag.rel)}${renderAttribute(\"href\", tag.href)}${renderAttribute(\"as\", tag.as)}${renderAttribute(\"type\", tag.type)}${renderAttribute(\"crossorigin\", tag.crossOrigin)}${renderAttribute(\"hreflang\", tag.hrefLang)} />`;\n}\n\nfunction renderScriptTag(scriptTag: ScriptTag, nonce: string | undefined) {\n return `<script${renderAttribute(\"id\", scriptTag.id)}${renderAttribute(\"src\", scriptTag.src)}${renderAttribute(\"type\", scriptTag.type ?? scriptTypeForStrategy(scriptTag.strategy))}${renderAttribute(\"nonce\", scriptTag.nonce ?? nonce)}${renderAttribute(\"integrity\", scriptTag.integrity)}${renderAttribute(\"referrerpolicy\", scriptTag.referrerPolicy)}${renderAttribute(\"data-api\", scriptTag.dataApi)}${renderAttribute(\"data-domain\", scriptTag.dataDomain)}${renderBooleanAttribute(\"async\", scriptTag.async)}${renderBooleanAttribute(\"defer\", scriptTag.defer)}></script>`;\n}\n\nfunction scriptTypeForStrategy(strategy: ScriptTag[\"strategy\"]) {\n return strategy === \"module\" ? \"module\" : undefined;\n}\n\nfunction renderAttribute(name: string, value: string | undefined) {\n return value ? ` ${name}=\"${escapeHtml(value)}\"` : \"\";\n}\n\nfunction renderBooleanAttribute(name: string, value: boolean | undefined) {\n return value ? ` ${name}` : \"\";\n}\n\nfunction escapeHtml(value: string) {\n return value\n .replaceAll(\"&\", \"&amp;\")\n .replaceAll(\"<\", \"&lt;\")\n .replaceAll(\">\", \"&gt;\")\n .replaceAll('\"', \"&quot;\");\n}\n\nfunction escapeJsonScript(value: string) {\n return value\n .replaceAll(\"<\", \"\\\\u003c\")\n .replaceAll(\">\", \"\\\\u003e\")\n .replaceAll(\"
\", \"\\\\u2028\")\n .replaceAll(\"
\", \"\\\\u2029\");\n}\n","export type RequestConnectionMetadata = {\n clientIp: string;\n};\n\nconst connectionMetadata = new WeakMap<Request, RequestConnectionMetadata>();\n\nexport function getRequestConnectionMetadata(request: Request) {\n return connectionMetadata.get(request);\n}\n\nexport function setRequestConnectionMetadata(\n request: Request,\n metadata: RequestConnectionMetadata,\n) {\n connectionMetadata.set(request, metadata);\n}\n\nexport function copyRequestConnectionMetadata(from: Request, to: Request) {\n const metadata = connectionMetadata.get(from);\n\n if (metadata) {\n connectionMetadata.set(to, metadata);\n }\n}\n","import { createElement, type ReactNode } from \"react\";\nimport type { LoadedRouteMatch } from \"../router\";\n\nexport function createPageRenderTree(match: LoadedRouteMatch) {\n const page = createElement(match.page, {\n data: match.data,\n path: match.path,\n pathname: match.pathname,\n });\n\n return match.layouts.reduceRight<ReactNode>(\n (children, Layout) =>\n createElement(Layout, {\n children,\n path: match.path,\n pathname: match.pathname,\n }),\n page,\n );\n}\n","import { renderToString } from \"react-dom/server\";\nimport { renderDocument } from \"../document\";\nimport type { LoadedRouteMatch } from \"../router\";\nimport { createPageRenderTree } from \"./render-tree\";\n\nexport type SsrOptions = {\n clientEntry?: string;\n lang?: string;\n navigation?: \"document\";\n styles?: string[];\n title?: string;\n};\n\nexport type SsrRenderOptions = SsrOptions & {\n nonce?: string;\n onStreamError?: (error: unknown) => void;\n signal?: AbortSignal;\n transformDocument?: (html: string) => string | Promise<string>;\n};\n\nexport function renderPageDocument(\n match: LoadedRouteMatch,\n options: SsrRenderOptions = {},\n) {\n const html = renderToString(createPageRenderTree(match));\n\n return renderDocument({\n body: {\n data: match.data,\n html,\n navigation: match.render.mode === \"static\"\n ? \"document\"\n : options.navigation,\n },\n entrySrc: options.clientEntry,\n lang: options.lang,\n links: match.links,\n metadata: match.metadata,\n nonce: options.nonce,\n scripts: match.scripts,\n styles: options.styles,\n title: options.title,\n });\n}\n\nexport function renderPageResponse(\n match: LoadedRouteMatch,\n options: SsrRenderOptions = {},\n) {\n const html = renderPageDocument(match, options);\n\n return new Response(html, {\n headers: {\n \"content-type\": \"text/html; charset=utf-8\",\n },\n });\n}\n"],"names":["HYDRATION_DATA_ELEMENT_ID","HYDRATION_ROOT_ATTRIBUTE","HYDRATION_FALLBACK_ATTRIBUTE","serializeInitialRouteData","data","options","escapeJsonScript","readInitialRouteData","source","element","serialized","error","value","STRUCTURED_DATA_ATTRIBUTE","renderDocument","html","body","prefix","suffix","renderDocumentShell","renderDocumentWithoutBody","entrySrc","lang","links","metadata","nonce","scripts","styles","title","documentTitle","trailingBodyContent","scriptTag","renderScriptTag","renderBootstrapData","renderEntryScript","escapeHtml","renderHeadTags","renderRootStart","bodyContent","renderRootElement","fallback","navigation","renderAttribute","renderMetaTag","renderLinkTag","renderRobotsTags","renderOpenGraphTags","renderDocumentMetadataTag","tag","renderStructuredDataTag","href","directives","name","property","scriptTypeForStrategy","renderBooleanAttribute","strategy","connectionMetadata","getRequestConnectionMetadata","request","setRequestConnectionMetadata","copyRequestConnectionMetadata","from","to","createPageRenderTree","match","page","createElement","children","Layout","renderPageDocument","renderToString","renderPageResponse"],"mappings":";;AAMO,MAAMA,IAA4B,mBAC5BC,IAA2B,yBAI3BC,IAA+B;AAErC,SAASC,EACdC,GACAC,IAAuC,IACvC;AACA,SAAOC;AAAAA,IACL,KAAK,UAAU,EAAE,MAAAF,GAAM,SAAS,IAAM,GAAGC,GAAS;AAAA,EAAA;AAEtD;AAEO,SAASE,EAAqBC,GAAkB;AACrD,QAAMC,IAAUD,EAAO,eAAeR,CAAyB,GACzDU,IAAaD,GAAS,YAAY,aACnCA,EAAgC,QAAQ,cACzCA,GAAS;AAEb,MAAKC;AAIL,QAAI;AACF,aAAO,KAAK,MAAMA,CAAU;AAAA,IAC9B,SAASC,GAAO;AACd,YAAM,IAAI;AAAA,QACR;AAAA,QACA,EAAE,OAAOA,EAAA;AAAA,MAAM;AAAA,IAEnB;AACF;AAEA,SAASL,EAAiBM,GAAe;AACvC,SAAOA,EACJ,QAAQ,MAAM,SAAS,EACvB,QAAQ,MAAM,SAAS,EACvB,QAAQ,MAAM,SAAS,EACvB,QAAQ,WAAW,SAAS,EAC5B,QAAQ,WAAW,SAAS;AACjC;ACnCO,MAAMC,IAA4B;AAyBlC,SAASC,EAAeT,GAAgC;AAC7D,MAAIA,EAAQ,MAAM;AAChB,UAAM,EAAE,MAAAU,GAAM,GAAGC,EAAA,IAASX,EAAQ,MAC5B,EAAE,QAAAY,GAAQ,QAAAC,EAAA,IAAWC,EAAoB,EAAE,GAAGd,GAAS,MAAAW,GAAM;AAEnE,WAAO,GAAGC,CAAM,GAAGF,CAAI,GAAGG,CAAM;AAAA,EAClC;AAEA,SAAOE,EAA0Bf,CAAO;A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AAM;AAAA,IACZ,UAAUA,EAAM;AAAA,EAAA,CACjB;AAED,SAAOA,EAAM,QAAQ;AAAA,IACnB,CAACG,GAAUC,MACTF,EAAcE,GAAQ;AAAA,MACpB,UAAAD;AAAA,MACA,MAAMH,EAAM;AAAA,MACZ,UAAUA,EAAM;AAAA,IAAA,CACjB;AAAA,IACHC;AAAA,EAAA;AAEJ;ACCO,SAASI,EACdL,GACA5D,IAA4B,IAC5B;AACA,QAAMU,IAAOwD,EAAeP,EAAqBC,CAAK,CAAC;AAEvD,SAAOnD,EAAe;AAAA,IACpB,MAAM;AAAA,MACJ,MAAMmD,EAAM;AAAA,MACZ,MAAAlD;AAAA,MACA,YAAYkD,EAAM,OAAO,SAAS,WAC9B,aACA5D,EAAQ;AAAA,IAAA;AAAA,IAEd,UAAUA,EAAQ;AAAA,IAClB,MAAMA,EAAQ;AAAA,IACd,OAAO4D,EAAM;AAAA,IACb,UAAUA,EAAM;AAAA,IAChB,OAAO5D,EAAQ;AAAA,IACf,SAAS4D,EAAM;AAAA,IACf,QAAQ5D,EAAQ;AAAA,IAChB,OAAOA,EAAQ;AAAA,EAAA,CAChB;AACH;AAEO,SAASmE,EACdP,GACA5D,IAA4B,IAC5B;AACA,QAAMU,IAAOuD,EAAmBL,GAAO5D,CAAO;AAE9C,SAAO,IAAI,SAASU,GAAM;AAAA,IACxB,SAAS;AAAA,MACP,gBAAgB;AAAA,IAAA;AAAA,EAClB,CACD;AACH;"}
@@ -0,0 +1,11 @@
1
+ const t = /-[A-Za-z0-9_-]{8,}\.[A-Za-z0-9]+$/, e = "public, max-age=31536000, immutable", E = "public, max-age=0, must-revalidate";
2
+ function s(a) {
3
+ return t.test(a);
4
+ }
5
+ export {
6
+ t as C,
7
+ e as I,
8
+ E as R,
9
+ s as i
10
+ };
11
+ //# sourceMappingURL=static-files-DUjHw-4H.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"static-files-DUjHw-4H.js","sources":["../../src/static-files.ts"],"sourcesContent":["export const CONTENT_HASHED_FILE_NAME_PATTERN =\n /-[A-Za-z0-9_-]{8,}\\.[A-Za-z0-9]+$/;\n\nexport const IMMUTABLE_FILE_CACHE_CONTROL =\n \"public, max-age=31536000, immutable\";\n\nexport const REVALIDATED_FILE_CACHE_CONTROL =\n \"public, max-age=0, must-revalidate\";\n\nexport function isContentHashedFileName(fileName: string) {\n return CONTENT_HASHED_FILE_NAME_PATTERN.test(fileName);\n}\n"],"names":["CONTENT_HASHED_FILE_NAME_PATTERN","IMMUTABLE_FILE_CACHE_CONTROL","REVALIDATED_FILE_CACHE_CONTROL","isContentHashedFileName","fileName"],"mappings":"AAAO,MAAMA,IACX,qCAEWC,IACX,uCAEWC,IACX;AAEK,SAASC,EAAwBC,GAAkB;AACxD,SAAOJ,EAAiC,KAAKI,CAAQ;AACvD;"}