@pithyjs/ssr 0.0.0-stage → 0.1.2-beta.9
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 +21 -0
- package/README.md +100 -2
- package/bin/pithy-ssg.mjs +23 -0
- package/dist/browser.d.ts +38 -0
- package/dist/browser.d.ts.map +1 -0
- package/dist/browser.js +40 -0
- package/dist/browser.js.map +1 -0
- package/dist/build/cli-args.d.ts +104 -0
- package/dist/build/cli-args.d.ts.map +1 -0
- package/dist/build/cli-args.js +88 -0
- package/dist/build/cli-args.js.map +1 -0
- package/dist/build/cli-exit.d.ts +95 -0
- package/dist/build/cli-exit.d.ts.map +1 -0
- package/dist/build/cli-exit.js +237 -0
- package/dist/build/cli-exit.js.map +1 -0
- package/dist/build/cli.d.ts +11 -0
- package/dist/build/cli.d.ts.map +1 -0
- package/dist/build/cli.js +93 -0
- package/dist/build/cli.js.map +1 -0
- package/dist/build/collect-css.d.ts +168 -0
- package/dist/build/collect-css.d.ts.map +1 -0
- package/dist/build/collect-css.js +479 -0
- package/dist/build/collect-css.js.map +1 -0
- package/dist/build/css-live-props.d.ts +89 -0
- package/dist/build/css-live-props.d.ts.map +1 -0
- package/dist/build/css-live-props.js +704 -0
- package/dist/build/css-live-props.js.map +1 -0
- package/dist/build/css-purge.d.ts +153 -0
- package/dist/build/css-purge.d.ts.map +1 -0
- package/dist/build/css-purge.js +463 -0
- package/dist/build/css-purge.js.map +1 -0
- package/dist/build/index.d.ts +24 -0
- package/dist/build/index.d.ts.map +1 -0
- package/dist/build/index.js +31 -0
- package/dist/build/index.js.map +1 -0
- package/dist/build/not-found.d.ts +94 -0
- package/dist/build/not-found.d.ts.map +1 -0
- package/dist/build/not-found.js +99 -0
- package/dist/build/not-found.js.map +1 -0
- package/dist/build/relative-links.d.ts +31 -0
- package/dist/build/relative-links.d.ts.map +1 -0
- package/dist/build/relative-links.js +79 -0
- package/dist/build/relative-links.js.map +1 -0
- package/dist/build/shell-head.d.ts +68 -0
- package/dist/build/shell-head.d.ts.map +1 -0
- package/dist/build/shell-head.js +236 -0
- package/dist/build/shell-head.js.map +1 -0
- package/dist/build/sprite-ssg.d.ts +61 -0
- package/dist/build/sprite-ssg.d.ts.map +1 -0
- package/dist/build/sprite-ssg.js +114 -0
- package/dist/build/sprite-ssg.js.map +1 -0
- package/dist/build/ssg.d.ts +117 -0
- package/dist/build/ssg.d.ts.map +1 -0
- package/dist/build/ssg.js +404 -0
- package/dist/build/ssg.js.map +1 -0
- package/dist/build/vite-ssg.d.ts +396 -0
- package/dist/build/vite-ssg.d.ts.map +1 -0
- package/dist/build/vite-ssg.js +1130 -0
- package/dist/build/vite-ssg.js.map +1 -0
- package/dist/client/bootstrap.d.ts +51 -0
- package/dist/client/bootstrap.d.ts.map +1 -0
- package/dist/client/bootstrap.js +121 -0
- package/dist/client/bootstrap.js.map +1 -0
- package/dist/client/hydrate.d.ts +60 -0
- package/dist/client/hydrate.d.ts.map +1 -0
- package/dist/client/hydrate.js +168 -0
- package/dist/client/hydrate.js.map +1 -0
- package/dist/client/index.d.ts +21 -0
- package/dist/client/index.d.ts.map +1 -0
- package/dist/client/index.js +16 -0
- package/dist/client/index.js.map +1 -0
- package/dist/index.d.ts +32 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +31 -0
- package/dist/index.js.map +1 -0
- package/dist/server/app.d.ts +166 -0
- package/dist/server/app.d.ts.map +1 -0
- package/dist/server/app.js +200 -0
- package/dist/server/app.js.map +1 -0
- package/dist/server/context.d.ts +238 -0
- package/dist/server/context.d.ts.map +1 -0
- package/dist/server/context.js +371 -0
- package/dist/server/context.js.map +1 -0
- package/dist/server/environment.d.ts +88 -0
- package/dist/server/environment.d.ts.map +1 -0
- package/dist/server/environment.js +261 -0
- package/dist/server/environment.js.map +1 -0
- package/dist/server/html-shell.d.ts +41 -0
- package/dist/server/html-shell.d.ts.map +1 -0
- package/dist/server/html-shell.js +208 -0
- package/dist/server/html-shell.js.map +1 -0
- package/dist/server/index.d.ts +26 -0
- package/dist/server/index.d.ts.map +1 -0
- package/dist/server/index.js +37 -0
- package/dist/server/index.js.map +1 -0
- package/dist/server/layout-taint.d.ts +62 -0
- package/dist/server/layout-taint.d.ts.map +1 -0
- package/dist/server/layout-taint.js +313 -0
- package/dist/server/layout-taint.js.map +1 -0
- package/dist/server/loaders.d.ts +194 -0
- package/dist/server/loaders.d.ts.map +1 -0
- package/dist/server/loaders.js +479 -0
- package/dist/server/loaders.js.map +1 -0
- package/dist/server/render-route.d.ts +102 -0
- package/dist/server/render-route.d.ts.map +1 -0
- package/dist/server/render-route.js +182 -0
- package/dist/server/render-route.js.map +1 -0
- package/dist/server/render.d.ts +80 -0
- package/dist/server/render.d.ts.map +1 -0
- package/dist/server/render.js +256 -0
- package/dist/server/render.js.map +1 -0
- package/dist/server/router-adapter.d.ts +134 -0
- package/dist/server/router-adapter.d.ts.map +1 -0
- package/dist/server/router-adapter.js +225 -0
- package/dist/server/router-adapter.js.map +1 -0
- package/dist/server/serialization.d.ts +54 -0
- package/dist/server/serialization.d.ts.map +1 -0
- package/dist/server/serialization.js +287 -0
- package/dist/server/serialization.js.map +1 -0
- package/dist/server/ssr-worker.d.ts +18 -0
- package/dist/server/ssr-worker.d.ts.map +1 -0
- package/dist/server/ssr-worker.js +118 -0
- package/dist/server/ssr-worker.js.map +1 -0
- package/dist/server/utils.d.ts +11 -0
- package/dist/server/utils.d.ts.map +1 -0
- package/dist/server/utils.js +14 -0
- package/dist/server/utils.js.map +1 -0
- package/dist/server/worker-pool.d.ts +153 -0
- package/dist/server/worker-pool.d.ts.map +1 -0
- package/dist/server/worker-pool.js +451 -0
- package/dist/server/worker-pool.js.map +1 -0
- package/dist/server/worker-protocol.d.ts +61 -0
- package/dist/server/worker-protocol.d.ts.map +1 -0
- package/dist/server/worker-protocol.js +9 -0
- package/dist/server/worker-protocol.js.map +1 -0
- package/dist/shared/css-purge.d.ts +71 -0
- package/dist/shared/css-purge.d.ts.map +1 -0
- package/dist/shared/css-purge.js +177 -0
- package/dist/shared/css-purge.js.map +1 -0
- package/dist/shared/entry-path.d.ts +41 -0
- package/dist/shared/entry-path.d.ts.map +1 -0
- package/dist/shared/entry-path.js +87 -0
- package/dist/shared/entry-path.js.map +1 -0
- package/dist/shared/head.d.ts +87 -0
- package/dist/shared/head.d.ts.map +1 -0
- package/dist/shared/head.js +412 -0
- package/dist/shared/head.js.map +1 -0
- package/dist/shared/shell-helpers.d.ts +69 -0
- package/dist/shared/shell-helpers.d.ts.map +1 -0
- package/dist/shared/shell-helpers.js +160 -0
- package/dist/shared/shell-helpers.js.map +1 -0
- package/dist/shared/types.d.ts +332 -0
- package/dist/shared/types.d.ts.map +1 -0
- package/dist/shared/types.js +27 -0
- package/dist/shared/types.js.map +1 -0
- package/package.json +84 -3
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
/** @codex
|
|
2
|
+
{
|
|
3
|
+
"id": "pithy.ssr.server.app",
|
|
4
|
+
"title": "PithyApp SSR Application",
|
|
5
|
+
"category": "runtime"
|
|
6
|
+
}
|
|
7
|
+
*/
|
|
8
|
+
import { renderRoute } from './render-route.js';
|
|
9
|
+
import { htmlShell } from './html-shell.js';
|
|
10
|
+
import { SSRWorkerPool } from './worker-pool.js';
|
|
11
|
+
// =============================================================================
|
|
12
|
+
// Implementation
|
|
13
|
+
// =============================================================================
|
|
14
|
+
/** @codexApi {"parent":"pithy.ssr.server.app","name":"PithyApp","stability":"experimental","signature":"class PithyApp"} */
|
|
15
|
+
/**
|
|
16
|
+
* Web Standard SSR application.
|
|
17
|
+
*
|
|
18
|
+
* Wraps the full SSR pipeline (`renderRoute()` + `htmlShell()`) behind a
|
|
19
|
+
* `Request → Response` interface with middleware support.
|
|
20
|
+
*/
|
|
21
|
+
export class PithyApp {
|
|
22
|
+
constructor(options) {
|
|
23
|
+
this.middlewares = [];
|
|
24
|
+
this.isShutdown = false;
|
|
25
|
+
this.options = options;
|
|
26
|
+
// Validate: worker pool requires componentPath
|
|
27
|
+
if (options.workerPool && !options.componentPath) {
|
|
28
|
+
throw new Error('PithyApp: componentPath is required when workerPool is enabled. ' +
|
|
29
|
+
'Components are not serializable across worker threads.');
|
|
30
|
+
}
|
|
31
|
+
// Initialize worker pool if requested
|
|
32
|
+
if (options.workerPool) {
|
|
33
|
+
const poolOptions = typeof options.workerPool === 'object' ? options.workerPool : {};
|
|
34
|
+
this.pool = new SSRWorkerPool(poolOptions);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
/** @codexApi {"parent":"pithy.ssr.server.app","name":"use","stability":"experimental","signature":"(middleware: PithyMiddleware) => this"} */
|
|
38
|
+
/**
|
|
39
|
+
* Add a middleware to the chain.
|
|
40
|
+
*
|
|
41
|
+
* Middlewares execute in registration order (first added = outermost).
|
|
42
|
+
* Each middleware receives the request and a `next()` function to call
|
|
43
|
+
* the next middleware or the core render.
|
|
44
|
+
*
|
|
45
|
+
* @returns this (for chaining)
|
|
46
|
+
*/
|
|
47
|
+
use(middleware) {
|
|
48
|
+
this.middlewares.push(middleware);
|
|
49
|
+
return this;
|
|
50
|
+
}
|
|
51
|
+
/** @codexApi {"parent":"pithy.ssr.server.app","name":"render","stability":"experimental","signature":"(request: Request) => Promise<Response>"} */
|
|
52
|
+
/**
|
|
53
|
+
* Render a request to a Response.
|
|
54
|
+
*
|
|
55
|
+
* Executes the middleware chain, then the core render pipeline.
|
|
56
|
+
* Returns a 500 Response for unhandled runtime errors.
|
|
57
|
+
* Throws if called after shutdown() (programming error).
|
|
58
|
+
*
|
|
59
|
+
* @param request - Web Standard Request
|
|
60
|
+
* @returns Web Standard Response with rendered HTML
|
|
61
|
+
*/
|
|
62
|
+
async render(request) {
|
|
63
|
+
if (this.isShutdown) {
|
|
64
|
+
throw new Error('PithyApp: render() called after shutdown()');
|
|
65
|
+
}
|
|
66
|
+
try {
|
|
67
|
+
// Build middleware chain via reduceRight (Koa onion model)
|
|
68
|
+
const coreRender = () => this.coreRender(request);
|
|
69
|
+
const chain = this.middlewares.reduceRight((next, middleware) => () => middleware(request, next), coreRender);
|
|
70
|
+
return await chain();
|
|
71
|
+
}
|
|
72
|
+
catch (error) {
|
|
73
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
74
|
+
return new Response(`Internal Server Error: ${message}`, {
|
|
75
|
+
status: 500,
|
|
76
|
+
headers: { 'Content-Type': 'text/plain; charset=utf-8' },
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Core render pipeline: URL → renderRoute/pool → redirect or htmlShell → Response
|
|
82
|
+
*/
|
|
83
|
+
async coreRender(request) {
|
|
84
|
+
const { options } = this;
|
|
85
|
+
const urlObj = new URL(request.url);
|
|
86
|
+
const url = urlObj.pathname + urlObj.search;
|
|
87
|
+
let result;
|
|
88
|
+
if (this.pool && options.componentPath) {
|
|
89
|
+
// Worker pool mode
|
|
90
|
+
result = await this.pool.render({
|
|
91
|
+
url,
|
|
92
|
+
componentPath: options.componentPath,
|
|
93
|
+
routeManifestPath: options.routeManifestPath,
|
|
94
|
+
context: undefined, // context is not serializable across workers
|
|
95
|
+
appId: options.appId,
|
|
96
|
+
loaderTimeout: options.loaderTimeout,
|
|
97
|
+
continueOnError: options.continueOnError,
|
|
98
|
+
defaultHead: options.defaultHead,
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
// Direct render mode
|
|
103
|
+
result = await renderRoute({
|
|
104
|
+
url,
|
|
105
|
+
App: options.App,
|
|
106
|
+
routes: options.routes,
|
|
107
|
+
appId: options.appId,
|
|
108
|
+
head: options.defaultHead,
|
|
109
|
+
loaderTimeout: options.loaderTimeout,
|
|
110
|
+
continueOnError: options.continueOnError,
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
// Handle redirects
|
|
114
|
+
if (result.redirectTo) {
|
|
115
|
+
return new Response(null, {
|
|
116
|
+
status: result.status,
|
|
117
|
+
headers: { Location: result.redirectTo },
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
// Generate full HTML document
|
|
121
|
+
const fullHtml = htmlShell({
|
|
122
|
+
html: result.html,
|
|
123
|
+
head: result.head,
|
|
124
|
+
state: result.state,
|
|
125
|
+
scripts: [options.entryClient],
|
|
126
|
+
styles: options.styles,
|
|
127
|
+
preloads: options.preloads,
|
|
128
|
+
appId: options.appId,
|
|
129
|
+
});
|
|
130
|
+
// Build response headers
|
|
131
|
+
const headers = new Headers({
|
|
132
|
+
'Content-Type': 'text/html; charset=utf-8',
|
|
133
|
+
});
|
|
134
|
+
if (result.cacheControl) {
|
|
135
|
+
headers.set('Cache-Control', result.cacheControl);
|
|
136
|
+
}
|
|
137
|
+
if (result.timing) {
|
|
138
|
+
headers.set('X-Render-Time', `${result.timing.total.toFixed(2)}ms`);
|
|
139
|
+
}
|
|
140
|
+
return new Response(fullHtml, {
|
|
141
|
+
status: result.status,
|
|
142
|
+
headers,
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
/** @codexApi {"parent":"pithy.ssr.server.app","name":"warmup","stability":"experimental","signature":"() => Promise<void>"} */
|
|
146
|
+
/**
|
|
147
|
+
* Warm up the application.
|
|
148
|
+
*
|
|
149
|
+
* Currently a no-op (the worker pool initializes in the constructor).
|
|
150
|
+
* Reserved for future use (e.g., pre-compiling routes, warming caches).
|
|
151
|
+
*/
|
|
152
|
+
async warmup() {
|
|
153
|
+
// No-op: pool initializes eagerly in constructor
|
|
154
|
+
}
|
|
155
|
+
/** @codexApi {"parent":"pithy.ssr.server.app","name":"shutdown","stability":"experimental","signature":"() => Promise<void>"} */
|
|
156
|
+
/**
|
|
157
|
+
* Shut down the application and release resources.
|
|
158
|
+
*
|
|
159
|
+
* Safe to call multiple times.
|
|
160
|
+
*/
|
|
161
|
+
async shutdown() {
|
|
162
|
+
this.isShutdown = true;
|
|
163
|
+
if (this.pool) {
|
|
164
|
+
await this.pool.shutdown();
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
/** @codexApi {"parent":"pithy.ssr.server.app","name":"getStats","stability":"experimental","signature":"() => WorkerPoolStats | undefined"} */
|
|
168
|
+
/**
|
|
169
|
+
* Get worker pool statistics.
|
|
170
|
+
*
|
|
171
|
+
* @returns Pool stats if worker pool is enabled, undefined otherwise
|
|
172
|
+
*/
|
|
173
|
+
getStats() {
|
|
174
|
+
return this.pool?.getStats();
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
/** @codexApi {"parent":"pithy.ssr.server.app","name":"createApp","stability":"experimental","signature":"(options: PithyAppOptions) => PithyApp"} */
|
|
178
|
+
/**
|
|
179
|
+
* Create a new PithyApp instance.
|
|
180
|
+
*
|
|
181
|
+
* @param options - Application configuration
|
|
182
|
+
* @returns A new PithyApp instance
|
|
183
|
+
*
|
|
184
|
+
* @example
|
|
185
|
+
* ```typescript
|
|
186
|
+
* const app = createApp({
|
|
187
|
+
* routes,
|
|
188
|
+
* App,
|
|
189
|
+
* entryClient: '/entry-client.js',
|
|
190
|
+
* styles: ['/styles.css'],
|
|
191
|
+
* defaultHead: { title: 'My App' },
|
|
192
|
+
* });
|
|
193
|
+
*
|
|
194
|
+
* const response = await app.render(new Request('http://localhost/'));
|
|
195
|
+
* ```
|
|
196
|
+
*/
|
|
197
|
+
export function createApp(options) {
|
|
198
|
+
return new PithyApp(options);
|
|
199
|
+
}
|
|
200
|
+
//# sourceMappingURL=app.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"app.js","sourceRoot":"","sources":["../../src/server/app.ts"],"names":[],"mappings":"AAAA;;;;;;EAME;AAsCF,OAAO,EAAE,WAAW,EAA0B,MAAM,mBAAmB,CAAC;AACxE,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,aAAa,EAA6B,MAAM,kBAAkB,CAAC;AA4C5E,gFAAgF;AAChF,iBAAiB;AACjB,gFAAgF;AAEhF,4HAA4H;AAC5H;;;;;GAKG;AACH,MAAM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,OAAO;SACR,CAAC,CAAC;IACL,CAAC;IAED,+HAA+H;IAC/H;;;;;OAKG;IACH,KAAK,CAAC,MAAM;QACV,iDAAiD;IACnD,CAAC;IAED,iIAAiI;IACjI;;;;OAIG;IACH,KAAK,CAAC,QAAQ;QACZ,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC;QACvB,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC;YACd,MAAM,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC;QAC7B,CAAC;IACH,CAAC;IAED,+IAA+I;IAC/I;;;;OAIG;IACH,QAAQ;QACN,OAAO,IAAI,CAAC,IAAI,EAAE,QAAQ,EAAE,CAAC;IAC/B,CAAC;CACF;AAED,qJAAqJ;AACrJ;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,UAAU,SAAS,CAAC,OAAwB;IAChD,OAAO,IAAI,QAAQ,CAAC,OAAO,CAAC,CAAC;AAC/B,CAAC","sourcesContent":["/** @codex\n{\n \"id\": \"pithy.ssr.server.app\",\n \"title\": \"PithyApp SSR Application\",\n \"category\": \"runtime\"\n}\n*/\n\n/**\n * @pithyjs/ssr - PithyApp\n *\n * Web Standard `Request → Response` boundary that wraps the SSR pipeline\n * (`renderRoute()` + `htmlShell()`) into a single embeddable SSR engine.\n *\n * This is the public API layer that framework adapters (Node.js, serverless)\n * and `@pithyjs/server` (V0.2) will consume.\n *\n * ## Usage\n *\n * ```typescript\n * import { createApp } from '@pithyjs/ssr/server';\n *\n * const app = createApp({\n * routes,\n * App,\n * entryClient: '/entry-client.js',\n * });\n *\n * // Add middleware\n * app.use(async (request, next) => {\n * const start = Date.now();\n * const response = await next();\n * console.log(`${request.url} took ${Date.now() - start}ms`);\n * return response;\n * });\n *\n * // Handle a request\n * const response = await app.render(new Request('http://localhost/'));\n * ```\n */\n\nimport type { Component } from '@pithyjs/core';\nimport type { RouteNode } from '@pithyjs/router';\nimport type { HeadState, PreloadHint } from '../shared/types.js';\nimport { renderRoute, type RenderRouteResult } from './render-route.js';\nimport { htmlShell } from './html-shell.js';\nimport { SSRWorkerPool, type SSRWorkerPoolOptions } from './worker-pool.js';\n\n// =============================================================================\n// Types\n// =============================================================================\n\n/**\n * Options for creating a PithyApp instance\n */\nexport interface PithyAppOptions {\n /** Route tree from the router manifest */\n routes: RouteNode[];\n /** The root component to render */\n App: Component;\n /** Client entry script path (included in HTML via <script type=\"module\">) */\n entryClient: string;\n /** Stylesheet URLs to include in the HTML */\n styles?: string[];\n /** Resource preload hints */\n preloads?: PreloadHint[];\n /** Default head state merged with per-route head() calls */\n defaultHead?: Partial<HeadState>;\n /** App container element ID (default: 'app') */\n appId?: string;\n /** Enable worker pool for concurrent rendering (true for defaults, or SSRWorkerPoolOptions) */\n workerPool?: boolean | SSRWorkerPoolOptions;\n /** Loader execution timeout in milliseconds (default: 30000) */\n loaderTimeout?: number;\n /** Whether to continue rendering after a loader error (default: false) */\n continueOnError?: boolean;\n /** Path to the App component module (required when workerPool is enabled) */\n componentPath?: string;\n /** Path to the route manifest module (recommended when workerPool is enabled for full pipeline rendering) */\n routeManifestPath?: string;\n}\n\n/**\n * Koa-style onion middleware for request/response interception\n */\nexport type PithyMiddleware = (\n request: Request,\n next: () => Promise<Response>\n) => Promise<Response>;\n\n// =============================================================================\n// Implementation\n// =============================================================================\n\n/** @codexApi {\"parent\":\"pithy.ssr.server.app\",\"name\":\"PithyApp\",\"stability\":\"experimental\",\"signature\":\"class PithyApp\"} */\n/**\n * Web Standard SSR application.\n *\n * Wraps the full SSR pipeline (`renderRoute()` + `htmlShell()`) behind a\n * `Request → Response` interface with middleware support.\n */\nexport class PithyApp {\n private readonly options: PithyAppOptions;\n private readonly middlewares: PithyMiddleware[] = [];\n private readonly pool: SSRWorkerPool | undefined;\n private isShutdown = false;\n\n constructor(options: PithyAppOptions) {\n this.options = options;\n\n // Validate: worker pool requires componentPath\n if (options.workerPool && !options.componentPath) {\n throw new Error(\n 'PithyApp: componentPath is required when workerPool is enabled. ' +\n 'Components are not serializable across worker threads.'\n );\n }\n\n // Initialize worker pool if requested\n if (options.workerPool) {\n const poolOptions: SSRWorkerPoolOptions =\n typeof options.workerPool === 'object' ? options.workerPool : {};\n this.pool = new SSRWorkerPool(poolOptions);\n }\n }\n\n /** @codexApi {\"parent\":\"pithy.ssr.server.app\",\"name\":\"use\",\"stability\":\"experimental\",\"signature\":\"(middleware: PithyMiddleware) => this\"} */\n /**\n * Add a middleware to the chain.\n *\n * Middlewares execute in registration order (first added = outermost).\n * Each middleware receives the request and a `next()` function to call\n * the next middleware or the core render.\n *\n * @returns this (for chaining)\n */\n use(middleware: PithyMiddleware): this {\n this.middlewares.push(middleware);\n return this;\n }\n\n /** @codexApi {\"parent\":\"pithy.ssr.server.app\",\"name\":\"render\",\"stability\":\"experimental\",\"signature\":\"(request: Request) => Promise<Response>\"} */\n /**\n * Render a request to a Response.\n *\n * Executes the middleware chain, then the core render pipeline.\n * Returns a 500 Response for unhandled runtime errors.\n * Throws if called after shutdown() (programming error).\n *\n * @param request - Web Standard Request\n * @returns Web Standard Response with rendered HTML\n */\n async render(request: Request): Promise<Response> {\n if (this.isShutdown) {\n throw new Error('PithyApp: render() called after shutdown()');\n }\n\n try {\n // Build middleware chain via reduceRight (Koa onion model)\n const coreRender = () => this.coreRender(request);\n const chain = this.middlewares.reduceRight<() => Promise<Response>>(\n (next, middleware) => () => middleware(request, next),\n coreRender\n );\n\n return await chain();\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n return new Response(`Internal Server Error: ${message}`, {\n status: 500,\n headers: { 'Content-Type': 'text/plain; charset=utf-8' },\n });\n }\n }\n\n /**\n * Core render pipeline: URL → renderRoute/pool → redirect or htmlShell → Response\n */\n private async coreRender(request: Request): Promise<Response> {\n const { options } = this;\n const urlObj = new URL(request.url);\n const url = urlObj.pathname + urlObj.search;\n\n let result: RenderRouteResult;\n\n if (this.pool && options.componentPath) {\n // Worker pool mode\n result = await this.pool.render({\n url,\n componentPath: options.componentPath,\n routeManifestPath: options.routeManifestPath,\n context: undefined, // context is not serializable across workers\n appId: options.appId,\n loaderTimeout: options.loaderTimeout,\n continueOnError: options.continueOnError,\n defaultHead: options.defaultHead,\n });\n } else {\n // Direct render mode\n result = await renderRoute({\n url,\n App: options.App,\n routes: options.routes,\n appId: options.appId,\n head: options.defaultHead,\n loaderTimeout: options.loaderTimeout,\n continueOnError: options.continueOnError,\n });\n }\n\n // Handle redirects\n if (result.redirectTo) {\n return new Response(null, {\n status: result.status,\n headers: { Location: result.redirectTo },\n });\n }\n\n // Generate full HTML document\n const fullHtml = htmlShell({\n html: result.html,\n head: result.head,\n state: result.state,\n scripts: [options.entryClient],\n styles: options.styles,\n preloads: options.preloads,\n appId: options.appId,\n });\n\n // Build response headers\n const headers = new Headers({\n 'Content-Type': 'text/html; charset=utf-8',\n });\n\n if (result.cacheControl) {\n headers.set('Cache-Control', result.cacheControl);\n }\n\n if (result.timing) {\n headers.set('X-Render-Time', `${result.timing.total.toFixed(2)}ms`);\n }\n\n return new Response(fullHtml, {\n status: result.status,\n headers,\n });\n }\n\n /** @codexApi {\"parent\":\"pithy.ssr.server.app\",\"name\":\"warmup\",\"stability\":\"experimental\",\"signature\":\"() => Promise<void>\"} */\n /**\n * Warm up the application.\n *\n * Currently a no-op (the worker pool initializes in the constructor).\n * Reserved for future use (e.g., pre-compiling routes, warming caches).\n */\n async warmup(): Promise<void> {\n // No-op: pool initializes eagerly in constructor\n }\n\n /** @codexApi {\"parent\":\"pithy.ssr.server.app\",\"name\":\"shutdown\",\"stability\":\"experimental\",\"signature\":\"() => Promise<void>\"} */\n /**\n * Shut down the application and release resources.\n *\n * Safe to call multiple times.\n */\n async shutdown(): Promise<void> {\n this.isShutdown = true;\n if (this.pool) {\n await this.pool.shutdown();\n }\n }\n\n /** @codexApi {\"parent\":\"pithy.ssr.server.app\",\"name\":\"getStats\",\"stability\":\"experimental\",\"signature\":\"() => WorkerPoolStats | undefined\"} */\n /**\n * Get worker pool statistics.\n *\n * @returns Pool stats if worker pool is enabled, undefined otherwise\n */\n getStats() {\n return this.pool?.getStats();\n }\n}\n\n/** @codexApi {\"parent\":\"pithy.ssr.server.app\",\"name\":\"createApp\",\"stability\":\"experimental\",\"signature\":\"(options: PithyAppOptions) => PithyApp\"} */\n/**\n * Create a new PithyApp instance.\n *\n * @param options - Application configuration\n * @returns A new PithyApp instance\n *\n * @example\n * ```typescript\n * const app = createApp({\n * routes,\n * App,\n * entryClient: '/entry-client.js',\n * styles: ['/styles.css'],\n * defaultHead: { title: 'My App' },\n * });\n *\n * const response = await app.render(new Request('http://localhost/'));\n * ```\n */\nexport function createApp(options: PithyAppOptions): PithyApp {\n return new PithyApp(options);\n}\n"]}
|
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
/** @codex
|
|
2
|
+
{
|
|
3
|
+
"id": "pithy.ssr.server.context",
|
|
4
|
+
"title": "SSR Context & Request Isolation",
|
|
5
|
+
"category": "runtime"
|
|
6
|
+
}
|
|
7
|
+
*/
|
|
8
|
+
import type { SSRContext, HeadState } from '../shared/types.js';
|
|
9
|
+
/**
|
|
10
|
+
* Options for creating SSR context
|
|
11
|
+
*/
|
|
12
|
+
export interface CreateSSRContextOptions {
|
|
13
|
+
/** URL being rendered */
|
|
14
|
+
url: string;
|
|
15
|
+
/** Route parameters (parsed from URL) */
|
|
16
|
+
params?: Record<string, string>;
|
|
17
|
+
/** Query parameters (parsed from URL) */
|
|
18
|
+
query?: Record<string, string>;
|
|
19
|
+
/** Initial loader data (if pre-populated) */
|
|
20
|
+
loaderData?: Record<string, unknown>;
|
|
21
|
+
/** Initial head state */
|
|
22
|
+
head?: Partial<HeadState>;
|
|
23
|
+
/** Initial HTTP status code */
|
|
24
|
+
status?: number;
|
|
25
|
+
}
|
|
26
|
+
/** @codexApi {"parent":"pithy.ssr.server.context","name":"createSSRContext","stability":"stable","signature":"(options: CreateSSRContextOptions) => SSRContext"} */
|
|
27
|
+
/**
|
|
28
|
+
* Create a new SSR context for a request
|
|
29
|
+
*
|
|
30
|
+
* @param options - Context creation options
|
|
31
|
+
* @returns A new SSR context instance
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```ts
|
|
35
|
+
* const context = createSSRContext({
|
|
36
|
+
* url: '/dashboard',
|
|
37
|
+
* params: { id: '123' },
|
|
38
|
+
* query: { tab: 'settings' }
|
|
39
|
+
* });
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
export declare function createSSRContext(options: CreateSSRContextOptions): SSRContext;
|
|
43
|
+
/** @codexApi {"parent":"pithy.ssr.server.context","name":"getSSRContext","stability":"stable","signature":"() => SSRContext | undefined"} */
|
|
44
|
+
/**
|
|
45
|
+
* Get the current SSR context
|
|
46
|
+
*
|
|
47
|
+
* Returns undefined when called outside of an SSR render.
|
|
48
|
+
* Use this to access the current request's context during component rendering.
|
|
49
|
+
*
|
|
50
|
+
* @returns The current SSR context or undefined
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* ```ts
|
|
54
|
+
* function MyComponent() {
|
|
55
|
+
* const ctx = getSSRContext();
|
|
56
|
+
* if (ctx) {
|
|
57
|
+
* // Running in SSR mode
|
|
58
|
+
* console.log('Rendering URL:', ctx.url);
|
|
59
|
+
* }
|
|
60
|
+
* }
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
63
|
+
export declare function getSSRContext(): SSRContext | undefined;
|
|
64
|
+
/** @codexApi {"parent":"pithy.ssr.server.context","name":"requireSSRContext","stability":"stable","signature":"() => SSRContext"} */
|
|
65
|
+
/**
|
|
66
|
+
* Get the current SSR context or throw if not in SSR
|
|
67
|
+
*
|
|
68
|
+
* Use this when you need the context and it would be an error
|
|
69
|
+
* to call outside SSR (e.g., in head() function).
|
|
70
|
+
*
|
|
71
|
+
* @returns The current SSR context
|
|
72
|
+
* @throws Error if called outside SSR render
|
|
73
|
+
*
|
|
74
|
+
* @example
|
|
75
|
+
* ```ts
|
|
76
|
+
* function head(config: HeadConfig) {
|
|
77
|
+
* const ctx = requireSSRContext();
|
|
78
|
+
* // Merge config into ctx.head...
|
|
79
|
+
* }
|
|
80
|
+
* ```
|
|
81
|
+
*/
|
|
82
|
+
export declare function requireSSRContext(): SSRContext;
|
|
83
|
+
/** @codexApi {"parent":"pithy.ssr.server.context","name":"runWithSSRContext","stability":"stable","signature":"<T>(context: SSRContext, fn: () => T) => T"} */
|
|
84
|
+
/**
|
|
85
|
+
* Execute a function with SSR context
|
|
86
|
+
*
|
|
87
|
+
* All code executed within the callback has access to the SSR context
|
|
88
|
+
* via getSSRContext(). This uses AsyncLocalStorage for isolation,
|
|
89
|
+
* so concurrent requests don't interfere with each other.
|
|
90
|
+
*
|
|
91
|
+
* @param context - The SSR context for this request
|
|
92
|
+
* @param fn - The function to execute with context
|
|
93
|
+
* @returns The return value of the function
|
|
94
|
+
*
|
|
95
|
+
* @example
|
|
96
|
+
* ```ts
|
|
97
|
+
* const result = runWithSSRContext(context, () => {
|
|
98
|
+
* // head() calls here will use this context
|
|
99
|
+
* return renderComponent(App);
|
|
100
|
+
* });
|
|
101
|
+
* ```
|
|
102
|
+
*/
|
|
103
|
+
export declare function runWithSSRContext<T>(context: SSRContext, fn: () => T): T;
|
|
104
|
+
/** @codexApi {"parent":"pithy.ssr.server.context","name":"runWithSSRContextAsync","stability":"stable","signature":"<T>(context: SSRContext, fn: () => Promise<T>) => Promise<T>"} */
|
|
105
|
+
/**
|
|
106
|
+
* Execute an async function with SSR context
|
|
107
|
+
*
|
|
108
|
+
* Same as runWithSSRContext but for async functions.
|
|
109
|
+
* The context is preserved across await boundaries.
|
|
110
|
+
*
|
|
111
|
+
* @param context - The SSR context for this request
|
|
112
|
+
* @param fn - The async function to execute with context
|
|
113
|
+
* @returns A promise resolving to the function's return value
|
|
114
|
+
*
|
|
115
|
+
* @example
|
|
116
|
+
* ```ts
|
|
117
|
+
* const result = await runWithSSRContextAsync(context, async () => {
|
|
118
|
+
* await executeLoaders();
|
|
119
|
+
* return renderComponent(App);
|
|
120
|
+
* });
|
|
121
|
+
* ```
|
|
122
|
+
*/
|
|
123
|
+
export declare function runWithSSRContextAsync<T>(context: SSRContext, fn: () => Promise<T>): Promise<T>;
|
|
124
|
+
/** @codexApi {"parent":"pithy.ssr.server.context","name":"isSSR","stability":"stable","signature":"() => boolean"} */
|
|
125
|
+
/**
|
|
126
|
+
* Check if currently running in SSR mode
|
|
127
|
+
*
|
|
128
|
+
* @returns True if within an SSR render context
|
|
129
|
+
*
|
|
130
|
+
* @example
|
|
131
|
+
* ```ts
|
|
132
|
+
* if (isSSR()) {
|
|
133
|
+
* // Skip client-only code
|
|
134
|
+
* }
|
|
135
|
+
* ```
|
|
136
|
+
*/
|
|
137
|
+
export declare function isSSR(): boolean;
|
|
138
|
+
/** @codexApi {"parent":"pithy.ssr.server.context","name":"updateSSRContext","stability":"stable","signature":"(updates: Partial<Omit<SSRContext, 'isSSR'>>) => void"} */
|
|
139
|
+
/**
|
|
140
|
+
* Update the current SSR context
|
|
141
|
+
*
|
|
142
|
+
* Allows modifying the context during rendering (e.g., setting redirectTo, status).
|
|
143
|
+
*
|
|
144
|
+
* @param updates - Partial context updates to apply
|
|
145
|
+
* @throws Error if called outside SSR render
|
|
146
|
+
*
|
|
147
|
+
* @example
|
|
148
|
+
* ```ts
|
|
149
|
+
* updateSSRContext({ status: 404 });
|
|
150
|
+
* updateSSRContext({ redirectTo: '/login' });
|
|
151
|
+
* ```
|
|
152
|
+
*/
|
|
153
|
+
export declare function updateSSRContext(updates: Partial<Omit<SSRContext, 'isSSR'>>): void;
|
|
154
|
+
/** @codexApi {"parent":"pithy.ssr.server.context","name":"setLoaderData","stability":"stable","signature":"(key: string, data: unknown) => void"} */
|
|
155
|
+
/**
|
|
156
|
+
* Set loader data for a route segment
|
|
157
|
+
*
|
|
158
|
+
* @param key - Route segment ID or key
|
|
159
|
+
* @param data - Loader data to store
|
|
160
|
+
* @throws Error if called outside SSR render
|
|
161
|
+
*
|
|
162
|
+
* @example
|
|
163
|
+
* ```ts
|
|
164
|
+
* setLoaderData('dashboard', { user: userData, stats: dashboardStats });
|
|
165
|
+
* ```
|
|
166
|
+
*/
|
|
167
|
+
export declare function setLoaderData(key: string, data: unknown): void;
|
|
168
|
+
/** @codexApi {"parent":"pithy.ssr.server.context","name":"getLoaderData","stability":"stable","signature":"<T>(key: string) => T | undefined"} */
|
|
169
|
+
/**
|
|
170
|
+
* Get loader data for a route segment
|
|
171
|
+
*
|
|
172
|
+
* @param key - Route segment ID or key
|
|
173
|
+
* @returns The loader data or undefined
|
|
174
|
+
*
|
|
175
|
+
* @example
|
|
176
|
+
* ```ts
|
|
177
|
+
* const data = getLoaderData<DashboardData>('dashboard');
|
|
178
|
+
* ```
|
|
179
|
+
*/
|
|
180
|
+
export declare function getLoaderData<T>(key: string): T | undefined;
|
|
181
|
+
/** @codexApi {"parent":"pithy.ssr.server.context","name":"setRedirect","stability":"stable","signature":"(url: string, status?: number) => void"} */
|
|
182
|
+
/**
|
|
183
|
+
* Set a redirect response
|
|
184
|
+
*
|
|
185
|
+
* @param url - URL to redirect to
|
|
186
|
+
* @param status - HTTP status code (default: 302)
|
|
187
|
+
* @throws Error if called outside SSR render
|
|
188
|
+
*
|
|
189
|
+
* @example
|
|
190
|
+
* ```ts
|
|
191
|
+
* setRedirect('/login', 302);
|
|
192
|
+
* ```
|
|
193
|
+
*/
|
|
194
|
+
export declare function setRedirect(url: string, status?: number): void;
|
|
195
|
+
/** @codexApi {"parent":"pithy.ssr.server.context","name":"setStatus","stability":"stable","signature":"(status: number) => void"} */
|
|
196
|
+
/**
|
|
197
|
+
* Set HTTP status code
|
|
198
|
+
*
|
|
199
|
+
* @param status - HTTP status code
|
|
200
|
+
* @throws Error if called outside SSR render
|
|
201
|
+
*
|
|
202
|
+
* @example
|
|
203
|
+
* ```ts
|
|
204
|
+
* setStatus(404);
|
|
205
|
+
* ```
|
|
206
|
+
*/
|
|
207
|
+
export declare function setStatus(status: number): void;
|
|
208
|
+
/**
|
|
209
|
+
* @internal
|
|
210
|
+
* Execute a function with isolated onDestroy callback storage.
|
|
211
|
+
* Used by renderToString to prevent callback interleaving between concurrent requests.
|
|
212
|
+
*/
|
|
213
|
+
export declare function runWithDestroyCallbacks<T>(fn: () => T): T;
|
|
214
|
+
/**
|
|
215
|
+
* @internal
|
|
216
|
+
* Get the current component context
|
|
217
|
+
*
|
|
218
|
+
* Used internally by renderToString. Not exported as public API.
|
|
219
|
+
* Access from @pithyjs/core is via the __getComponentContext global getter.
|
|
220
|
+
*/
|
|
221
|
+
export declare function getComponentContext(): Record<string, unknown> | undefined;
|
|
222
|
+
/**
|
|
223
|
+
* @internal
|
|
224
|
+
* Execute a function with component context
|
|
225
|
+
*
|
|
226
|
+
* Used internally by renderToString to wrap rendering with isolated context.
|
|
227
|
+
* Not exported as public API - users pass context via renderToString options.
|
|
228
|
+
*/
|
|
229
|
+
export declare function runWithComponentContext<T>(context: Record<string, unknown>, fn: () => T): T;
|
|
230
|
+
/**
|
|
231
|
+
* @internal
|
|
232
|
+
* Execute an async function with component context
|
|
233
|
+
*
|
|
234
|
+
* Used internally. Context is preserved across await boundaries.
|
|
235
|
+
* Not exported as public API.
|
|
236
|
+
*/
|
|
237
|
+
export declare function runWithComponentContextAsync<T>(context: Record<string, unknown>, fn: () => Promise<T>): Promise<T>;
|
|
238
|
+
//# sourceMappingURL=context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../src/server/context.ts"],"names":[],"mappings":"AAAA;;;;;;EAME;AAUF,OAAO,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAuDhE;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACtC,yBAAyB;IACzB,GAAG,EAAE,MAAM,CAAC;IACZ,yCAAyC;IACzC,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAChC,yCAAyC;IACzC,KAAK,CAAC,EAAE,MAAM,CA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