@zenithbuild/cli 0.7.4 → 0.7.7

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 (112) hide show
  1. package/README.md +5 -3
  2. package/dist/adapters/adapter-netlify.d.ts +1 -1
  3. package/dist/adapters/adapter-netlify.js +48 -14
  4. package/dist/adapters/adapter-static-export.d.ts +5 -0
  5. package/dist/adapters/adapter-static-export.js +115 -0
  6. package/dist/adapters/adapter-types.d.ts +3 -1
  7. package/dist/adapters/adapter-types.js +5 -2
  8. package/dist/adapters/adapter-vercel.d.ts +1 -1
  9. package/dist/adapters/adapter-vercel.js +67 -19
  10. package/dist/adapters/copy-hosted-page-runtime.d.ts +1 -0
  11. package/dist/adapters/copy-hosted-page-runtime.js +50 -0
  12. package/dist/adapters/resolve-adapter.js +4 -0
  13. package/dist/adapters/route-rules.d.ts +5 -0
  14. package/dist/adapters/route-rules.js +9 -0
  15. package/dist/adapters/validate-hosted-resource-routes.d.ts +1 -0
  16. package/dist/adapters/validate-hosted-resource-routes.js +13 -0
  17. package/dist/auth/route-auth.d.ts +6 -0
  18. package/dist/auth/route-auth.js +236 -0
  19. package/dist/build/compiler-runtime.d.ts +1 -1
  20. package/dist/build/compiler-runtime.js +8 -2
  21. package/dist/build/hoisted-code-transforms.d.ts +4 -1
  22. package/dist/build/hoisted-code-transforms.js +5 -3
  23. package/dist/build/page-ir-normalization.d.ts +1 -1
  24. package/dist/build/page-ir-normalization.js +33 -3
  25. package/dist/build/page-loop-state.js +1 -1
  26. package/dist/build/page-loop.js +46 -2
  27. package/dist/build/server-script.d.ts +2 -1
  28. package/dist/build/server-script.js +7 -3
  29. package/dist/build-output-manifest.d.ts +3 -2
  30. package/dist/build-output-manifest.js +3 -0
  31. package/dist/build.js +29 -17
  32. package/dist/dev-build-session/helpers.d.ts +29 -0
  33. package/dist/dev-build-session/helpers.js +223 -0
  34. package/dist/dev-build-session/session.d.ts +24 -0
  35. package/dist/dev-build-session/session.js +204 -0
  36. package/dist/dev-build-session/state.d.ts +37 -0
  37. package/dist/dev-build-session/state.js +17 -0
  38. package/dist/dev-build-session.d.ts +1 -24
  39. package/dist/dev-build-session.js +1 -434
  40. package/dist/dev-server/css-state.d.ts +7 -0
  41. package/dist/dev-server/css-state.js +92 -0
  42. package/dist/dev-server/not-found.d.ts +23 -0
  43. package/dist/dev-server/not-found.js +129 -0
  44. package/dist/dev-server/request-handler.d.ts +1 -0
  45. package/dist/dev-server/request-handler.js +376 -0
  46. package/dist/dev-server/route-check.d.ts +9 -0
  47. package/dist/dev-server/route-check.js +100 -0
  48. package/dist/dev-server/watcher.d.ts +5 -0
  49. package/dist/dev-server/watcher.js +216 -0
  50. package/dist/dev-server.js +136 -883
  51. package/dist/download-result.d.ts +14 -0
  52. package/dist/download-result.js +148 -0
  53. package/dist/images/payload.js +4 -0
  54. package/dist/images/service.d.ts +13 -1
  55. package/dist/images/service.js +45 -15
  56. package/dist/manifest.d.ts +15 -1
  57. package/dist/manifest.js +70 -6
  58. package/dist/preview/create-preview-server.d.ts +18 -0
  59. package/dist/preview/create-preview-server.js +71 -0
  60. package/dist/preview/manifest.d.ts +42 -0
  61. package/dist/preview/manifest.js +57 -0
  62. package/dist/preview/paths.d.ts +3 -0
  63. package/dist/preview/paths.js +38 -0
  64. package/dist/preview/payload.d.ts +6 -0
  65. package/dist/preview/payload.js +34 -0
  66. package/dist/preview/request-handler.d.ts +1 -0
  67. package/dist/preview/request-handler.js +300 -0
  68. package/dist/preview/server-runner.d.ts +49 -0
  69. package/dist/preview/server-runner.js +220 -0
  70. package/dist/preview/server-script-runner-template.d.ts +1 -0
  71. package/dist/preview/server-script-runner-template.js +425 -0
  72. package/dist/preview.d.ts +5 -104
  73. package/dist/preview.js +7 -993
  74. package/dist/request-body.d.ts +0 -1
  75. package/dist/request-body.js +0 -6
  76. package/dist/resource-manifest.d.ts +16 -0
  77. package/dist/resource-manifest.js +53 -0
  78. package/dist/resource-response.d.ts +49 -0
  79. package/dist/resource-response.js +160 -0
  80. package/dist/resource-route-module.d.ts +15 -0
  81. package/dist/resource-route-module.js +129 -0
  82. package/dist/route-check-support.js +1 -1
  83. package/dist/server-contract/constants.d.ts +5 -0
  84. package/dist/server-contract/constants.js +5 -0
  85. package/dist/server-contract/export-validation.d.ts +5 -0
  86. package/dist/server-contract/export-validation.js +59 -0
  87. package/dist/server-contract/json-serializable.d.ts +1 -0
  88. package/dist/server-contract/json-serializable.js +52 -0
  89. package/dist/server-contract/resolve.d.ts +15 -0
  90. package/dist/server-contract/resolve.js +271 -0
  91. package/dist/server-contract/result-helpers.d.ts +51 -0
  92. package/dist/server-contract/result-helpers.js +59 -0
  93. package/dist/server-contract/route-result-validation.d.ts +2 -0
  94. package/dist/server-contract/route-result-validation.js +73 -0
  95. package/dist/server-contract/stage.d.ts +6 -0
  96. package/dist/server-contract/stage.js +22 -0
  97. package/dist/server-contract.d.ts +6 -54
  98. package/dist/server-contract.js +9 -301
  99. package/dist/server-error.d.ts +1 -1
  100. package/dist/server-error.js +2 -0
  101. package/dist/server-middleware.d.ts +10 -0
  102. package/dist/server-middleware.js +30 -0
  103. package/dist/server-output.d.ts +2 -1
  104. package/dist/server-output.js +72 -12
  105. package/dist/server-runtime/node-server.js +59 -7
  106. package/dist/server-runtime/route-render.d.ts +25 -1
  107. package/dist/server-runtime/route-render.js +81 -29
  108. package/dist/server-script-composition.d.ts +4 -2
  109. package/dist/server-script-composition.js +6 -3
  110. package/dist/static-export-paths.d.ts +3 -0
  111. package/dist/static-export-paths.js +160 -0
  112. package/package.json +3 -3
@@ -0,0 +1,425 @@
1
+ export const SERVER_SCRIPT_RUNNER = String.raw `
2
+ import vm from 'node:vm';
3
+ import fs from 'node:fs/promises';
4
+ import path from 'node:path';
5
+ import { pathToFileURL, fileURLToPath } from 'node:url';
6
+
7
+ const source = process.env.ZENITH_SERVER_SOURCE || '';
8
+ const sourcePath = process.env.ZENITH_SERVER_SOURCE_PATH || '';
9
+ const params = JSON.parse(process.env.ZENITH_SERVER_PARAMS || '{}');
10
+ const requestUrl = process.env.ZENITH_SERVER_REQUEST_URL || 'http://localhost/';
11
+ const requestMethod = String(process.env.ZENITH_SERVER_REQUEST_METHOD || 'GET').toUpperCase();
12
+ const requestHeaders = JSON.parse(process.env.ZENITH_SERVER_REQUEST_HEADERS || '{}');
13
+ const routePattern = process.env.ZENITH_SERVER_ROUTE_PATTERN || '';
14
+ const routeFile = process.env.ZENITH_SERVER_ROUTE_FILE || sourcePath || '';
15
+ const routeId = process.env.ZENITH_SERVER_ROUTE_ID || routePattern || '';
16
+ const routeKind = process.env.ZENITH_SERVER_ROUTE_KIND || 'page';
17
+ const guardOnly = process.env.ZENITH_SERVER_GUARD_ONLY === '1';
18
+
19
+ if (!source.trim()) {
20
+ process.stdout.write('null');
21
+ process.exit(0);
22
+ }
23
+
24
+ let cachedTypeScript = undefined;
25
+ async function loadTypeScript() {
26
+ if (cachedTypeScript !== undefined) {
27
+ return cachedTypeScript;
28
+ }
29
+ try {
30
+ const mod = await import('typescript');
31
+ cachedTypeScript = mod.default || mod;
32
+ } catch {
33
+ cachedTypeScript = null;
34
+ }
35
+ return cachedTypeScript;
36
+ }
37
+
38
+ async function transpileIfNeeded(filename, code) {
39
+ const lower = String(filename || '').toLowerCase();
40
+ const isTs =
41
+ lower.endsWith('.ts') ||
42
+ lower.endsWith('.tsx') ||
43
+ lower.endsWith('.mts') ||
44
+ lower.endsWith('.cts');
45
+ if (!isTs) {
46
+ return code;
47
+ }
48
+ const ts = await loadTypeScript();
49
+ if (!ts || typeof ts.transpileModule !== 'function') {
50
+ throw new Error('[zenith-preview] TypeScript is required to execute server modules that import .ts files');
51
+ }
52
+ const output = ts.transpileModule(code, {
53
+ fileName: filename || 'server-script.ts',
54
+ compilerOptions: {
55
+ target: ts.ScriptTarget.ES2022,
56
+ module: ts.ModuleKind.ESNext,
57
+ moduleResolution: ts.ModuleResolutionKind.NodeNext
58
+ },
59
+ reportDiagnostics: false
60
+ });
61
+ return output.outputText;
62
+ }
63
+
64
+ async function exists(filePath) {
65
+ try {
66
+ await fs.access(filePath);
67
+ return true;
68
+ } catch {
69
+ return false;
70
+ }
71
+ }
72
+
73
+ async function resolveRelativeSpecifier(specifier, parentIdentifier) {
74
+ let basePath = sourcePath;
75
+ if (parentIdentifier && parentIdentifier.startsWith('file:')) {
76
+ basePath = fileURLToPath(parentIdentifier);
77
+ }
78
+
79
+ const baseDir = basePath ? path.dirname(basePath) : process.cwd();
80
+ const candidateBase = specifier.startsWith('file:')
81
+ ? fileURLToPath(specifier)
82
+ : path.resolve(baseDir, specifier);
83
+
84
+ const candidates = [];
85
+ if (path.extname(candidateBase)) {
86
+ candidates.push(candidateBase);
87
+ } else {
88
+ candidates.push(candidateBase);
89
+ candidates.push(candidateBase + '.ts');
90
+ candidates.push(candidateBase + '.tsx');
91
+ candidates.push(candidateBase + '.mts');
92
+ candidates.push(candidateBase + '.cts');
93
+ candidates.push(candidateBase + '.js');
94
+ candidates.push(candidateBase + '.mjs');
95
+ candidates.push(candidateBase + '.cjs');
96
+ candidates.push(path.join(candidateBase, 'index.ts'));
97
+ candidates.push(path.join(candidateBase, 'index.tsx'));
98
+ candidates.push(path.join(candidateBase, 'index.mts'));
99
+ candidates.push(path.join(candidateBase, 'index.cts'));
100
+ candidates.push(path.join(candidateBase, 'index.js'));
101
+ candidates.push(path.join(candidateBase, 'index.mjs'));
102
+ candidates.push(path.join(candidateBase, 'index.cjs'));
103
+ }
104
+
105
+ for (const candidate of candidates) {
106
+ if (await exists(candidate)) {
107
+ return pathToFileURL(candidate).href;
108
+ }
109
+ }
110
+
111
+ throw new Error(
112
+ '[zenith-preview] Cannot resolve server import "' + specifier + '" from "' + (basePath || '<inline>') + '"'
113
+ );
114
+ }
115
+
116
+ function isRelativeSpecifier(specifier) {
117
+ return (
118
+ specifier.startsWith('./') ||
119
+ specifier.startsWith('../') ||
120
+ specifier.startsWith('/') ||
121
+ specifier.startsWith('file:')
122
+ );
123
+ }
124
+
125
+ const safeRequestHeaders =
126
+ requestHeaders && typeof requestHeaders === 'object'
127
+ ? { ...requestHeaders }
128
+ : {};
129
+ function parseCookies(rawCookieHeader) {
130
+ const out = Object.create(null);
131
+ const raw = String(rawCookieHeader || '');
132
+ if (!raw) return out;
133
+ const pairs = raw.split(';');
134
+ for (let i = 0; i < pairs.length; i++) {
135
+ const part = pairs[i];
136
+ const eq = part.indexOf('=');
137
+ if (eq <= 0) continue;
138
+ const key = part.slice(0, eq).trim();
139
+ if (!key) continue;
140
+ const value = part.slice(eq + 1).trim();
141
+ try {
142
+ out[key] = decodeURIComponent(value);
143
+ } catch {
144
+ out[key] = value;
145
+ }
146
+ }
147
+ return out;
148
+ }
149
+ const cookieHeader = typeof safeRequestHeaders.cookie === 'string'
150
+ ? safeRequestHeaders.cookie
151
+ : '';
152
+ const requestCookies = parseCookies(cookieHeader);
153
+
154
+ function ctxAllow() {
155
+ return { kind: 'allow' };
156
+ }
157
+ function ctxRedirect(location, status = 302) {
158
+ return {
159
+ kind: 'redirect',
160
+ location: String(location || ''),
161
+ status: Number.isInteger(status) ? status : 302
162
+ };
163
+ }
164
+ function ctxDeny(status = 403, message = undefined) {
165
+ return {
166
+ kind: 'deny',
167
+ status: Number.isInteger(status) ? status : 403,
168
+ message: typeof message === 'string' ? message : undefined
169
+ };
170
+ }
171
+ function ctxInvalid(payload, status = 400) {
172
+ return {
173
+ kind: 'invalid',
174
+ data: payload,
175
+ status: Number.isInteger(status) ? status : 400
176
+ };
177
+ }
178
+ function ctxData(payload) {
179
+ return {
180
+ kind: 'data',
181
+ data: payload
182
+ };
183
+ }
184
+ function ctxJson(payload, status = 200) {
185
+ return {
186
+ kind: 'json',
187
+ data: payload,
188
+ status: Number.isInteger(status) ? status : 200
189
+ };
190
+ }
191
+ function ctxText(body, status = 200) {
192
+ return {
193
+ kind: 'text',
194
+ body: typeof body === 'string' ? body : String(body ?? ''),
195
+ status: Number.isInteger(status) ? status : 200
196
+ };
197
+ }
198
+
199
+ async function readStdinBuffer() {
200
+ const chunks = [];
201
+ for await (const chunk of process.stdin) {
202
+ chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk));
203
+ }
204
+ return Buffer.concat(chunks);
205
+ }
206
+
207
+ const requestInit = {
208
+ method: requestMethod,
209
+ headers: new Headers(safeRequestHeaders)
210
+ };
211
+ const requestBodyBuffer =
212
+ requestMethod !== 'GET' && requestMethod !== 'HEAD'
213
+ ? await readStdinBuffer()
214
+ : Buffer.alloc(0);
215
+ if (requestMethod !== 'GET' && requestMethod !== 'HEAD' && requestBodyBuffer.length > 0) {
216
+ requestInit.body = requestBodyBuffer;
217
+ requestInit.duplex = 'half';
218
+ }
219
+ const requestSnapshot = new Request(requestUrl, requestInit);
220
+ const routeParams = { ...params };
221
+ const routeMeta = {
222
+ id: routeId,
223
+ pattern: routePattern,
224
+ file: routeFile ? path.relative(process.cwd(), routeFile) : ''
225
+ };
226
+ const routeContext = {
227
+ params: routeParams,
228
+ url: new URL(requestUrl),
229
+ headers: { ...safeRequestHeaders },
230
+ cookies: requestCookies,
231
+ request: requestSnapshot,
232
+ method: requestMethod,
233
+ route: routeMeta,
234
+ env: {},
235
+ action: null,
236
+ allow: ctxAllow,
237
+ redirect: ctxRedirect,
238
+ deny: ctxDeny,
239
+ invalid: ctxInvalid,
240
+ data: ctxData,
241
+ json: ctxJson,
242
+ text: ctxText
243
+ };
244
+
245
+ const context = vm.createContext({
246
+ params: routeParams,
247
+ ctx: routeContext,
248
+ fetch: globalThis.fetch,
249
+ Blob: globalThis.Blob,
250
+ File: globalThis.File,
251
+ FormData: globalThis.FormData,
252
+ Headers: globalThis.Headers,
253
+ Request: globalThis.Request,
254
+ Response: globalThis.Response,
255
+ TextEncoder: globalThis.TextEncoder,
256
+ TextDecoder: globalThis.TextDecoder,
257
+ URL,
258
+ URLSearchParams,
259
+ Buffer,
260
+ console,
261
+ process,
262
+ setTimeout,
263
+ clearTimeout,
264
+ setInterval,
265
+ clearInterval
266
+ });
267
+
268
+ const moduleCache = new Map();
269
+ const syntheticModuleCache = new Map();
270
+
271
+ async function createSyntheticModule(specifier) {
272
+ if (syntheticModuleCache.has(specifier)) {
273
+ return syntheticModuleCache.get(specifier);
274
+ }
275
+
276
+ const ns = await import(specifier);
277
+ const exportNames = Object.keys(ns);
278
+ const module = new vm.SyntheticModule(
279
+ exportNames,
280
+ function() {
281
+ for (const key of exportNames) {
282
+ this.setExport(key, ns[key]);
283
+ }
284
+ },
285
+ { context }
286
+ );
287
+ await module.link(() => {
288
+ throw new Error(
289
+ '[zenith-preview] synthetic modules cannot contain nested imports: ' + specifier
290
+ );
291
+ });
292
+ syntheticModuleCache.set(specifier, module);
293
+ return module;
294
+ }
295
+
296
+ async function loadFileModule(moduleUrl) {
297
+ if (moduleCache.has(moduleUrl)) {
298
+ return moduleCache.get(moduleUrl);
299
+ }
300
+ const modulePromise = (async () => {
301
+ const filename = fileURLToPath(moduleUrl);
302
+ let code = await fs.readFile(filename, 'utf8');
303
+ code = await transpileIfNeeded(filename, code);
304
+ const module = new vm.SourceTextModule(code, {
305
+ context,
306
+ identifier: moduleUrl,
307
+ initializeImportMeta(meta) {
308
+ meta.url = moduleUrl;
309
+ }
310
+ });
311
+
312
+ await module.link((specifier, referencingModule) => {
313
+ return linkModule(specifier, referencingModule.identifier);
314
+ });
315
+ return module;
316
+ })();
317
+
318
+ moduleCache.set(moduleUrl, modulePromise);
319
+ try {
320
+ return await modulePromise;
321
+ } catch (error) {
322
+ moduleCache.delete(moduleUrl);
323
+ throw error;
324
+ }
325
+ }
326
+
327
+ async function linkModule(specifier, parentIdentifier) {
328
+ if (!isRelativeSpecifier(specifier)) {
329
+ return createSyntheticModule(specifier);
330
+ }
331
+ const resolvedUrl = await resolveRelativeSpecifier(specifier, parentIdentifier);
332
+ return loadFileModule(resolvedUrl);
333
+ }
334
+
335
+ const allowed = new Set(['data', 'load', 'guard', 'action', 'ssr_data', 'props', 'ssr', 'prerender', 'exportPaths']);
336
+ const prelude = "const params = globalThis.params;\n" +
337
+ "const ctx = globalThis.ctx;\n" +
338
+ "import { download, resolveRouteResult } from 'zenith:server-contract';\n" +
339
+ "import { attachRouteAuth } from 'zenith:route-auth';\n" +
340
+ "ctx.download = download;\n" +
341
+ "globalThis.resolveRouteResult = resolveRouteResult;\n" +
342
+ "globalThis.attachRouteAuth = attachRouteAuth;\n";
343
+ const entryIdentifier = sourcePath
344
+ ? pathToFileURL(sourcePath).href
345
+ : 'zenith:server-script';
346
+ const entryTranspileFilename = sourcePath && sourcePath.toLowerCase().endsWith('.zen')
347
+ ? sourcePath.replace(/\.zen$/i, '.ts')
348
+ : (sourcePath || 'server-script.ts');
349
+
350
+ const entryCode = await transpileIfNeeded(entryTranspileFilename, prelude + source);
351
+ const entryModule = new vm.SourceTextModule(entryCode, {
352
+ context,
353
+ identifier: entryIdentifier,
354
+ initializeImportMeta(meta) {
355
+ meta.url = entryIdentifier;
356
+ }
357
+ });
358
+
359
+ moduleCache.set(entryIdentifier, entryModule);
360
+ await entryModule.link((specifier, referencingModule) => {
361
+ if (specifier === 'zenith:server-contract') {
362
+ const defaultPath = path.join(process.cwd(), 'node_modules', '@zenithbuild', 'cli', 'src', 'server-contract.js');
363
+ const configuredPath = process.env.ZENITH_SERVER_CONTRACT_PATH || '';
364
+ const contractUrl = pathToFileURL(configuredPath || defaultPath).href;
365
+ if (configuredPath) {
366
+ return loadFileModule(contractUrl);
367
+ }
368
+ return loadFileModule(contractUrl).catch(() =>
369
+ loadFileModule(pathToFileURL(defaultPath).href)
370
+ );
371
+ }
372
+ if (specifier === 'zenith:route-auth') {
373
+ const defaultPath = path.join(process.cwd(), 'node_modules', '@zenithbuild', 'cli', 'src', 'auth', 'route-auth.js');
374
+ const configuredPath = process.env.ZENITH_SERVER_ROUTE_AUTH_PATH || '';
375
+ const authUrl = pathToFileURL(configuredPath || defaultPath).href;
376
+ if (configuredPath) {
377
+ return loadFileModule(authUrl);
378
+ }
379
+ return loadFileModule(authUrl).catch(() =>
380
+ loadFileModule(pathToFileURL(defaultPath).href)
381
+ );
382
+ }
383
+ return linkModule(specifier, referencingModule.identifier);
384
+ });
385
+ await entryModule.evaluate();
386
+ context.attachRouteAuth(routeContext, {
387
+ requestUrl: routeContext.url,
388
+ guardOnly,
389
+ redirect: ctxRedirect,
390
+ deny: ctxDeny
391
+ });
392
+
393
+ const namespaceKeys = Object.keys(entryModule.namespace);
394
+ for (const key of namespaceKeys) {
395
+ if (!allowed.has(key)) {
396
+ throw new Error('[zenith-preview] unsupported server export "' + key + '"');
397
+ }
398
+ }
399
+
400
+ const exported = entryModule.namespace;
401
+ try {
402
+ const resolved = await context.resolveRouteResult({
403
+ exports: exported,
404
+ ctx: context.ctx,
405
+ filePath: sourcePath || 'server_script',
406
+ guardOnly: guardOnly,
407
+ routeKind: routeKind
408
+ });
409
+
410
+ process.stdout.write(JSON.stringify(resolved || null));
411
+ } catch (error) {
412
+ const message = error instanceof Error
413
+ ? (typeof error.stack === 'string' && error.stack.length > 0 ? error.stack : error.message)
414
+ : String(error);
415
+ process.stderr.write('[Zenith:Server] preview route execution failed\\n' + message + '\\n');
416
+ process.stdout.write(
417
+ JSON.stringify({
418
+ __zenith_error: {
419
+ status: 500,
420
+ code: 'LOAD_FAILED'
421
+ }
422
+ })
423
+ );
424
+ }
425
+ `;
package/dist/preview.d.ts CHANGED
@@ -1,104 +1,5 @@
1
- /**
2
- * Create and start a preview server.
3
- *
4
- * @param {{ distDir: string, port?: number, host?: string, logger?: object | null, config?: object, projectRoot?: string }} options
5
- * @returns {Promise<{ server: import('http').Server, port: number, close: () => void }>}
6
- */
7
- export function createPreviewServer(options: {
8
- distDir: string;
9
- port?: number;
10
- host?: string;
11
- logger?: object | null;
12
- config?: object;
13
- projectRoot?: string;
14
- }): Promise<{
15
- server: import("http").Server;
16
- port: number;
17
- close: () => void;
18
- }>;
19
- /**
20
- * @typedef {{
21
- * path: string;
22
- * output: string;
23
- * server_script?: string | null;
24
- * server_script_path?: string | null;
25
- * prerender?: boolean;
26
- * route_id?: string;
27
- * pattern?: string;
28
- * params_shape?: Record<string, string>;
29
- * has_guard?: boolean;
30
- * has_load?: boolean;
31
- * guard_module_ref?: string | null;
32
- * load_module_ref?: string | null;
33
- * }} PreviewRoute
34
- */
35
- /**
36
- * @param {string} distDir
37
- * @returns {Promise<PreviewRoute[]>}
38
- */
39
- export function loadRouteManifest(distDir: string): Promise<PreviewRoute[]>;
40
- /**
41
- * @param {{ source: string, sourcePath: string, params: Record<string, string>, requestUrl?: string, requestMethod?: string, requestHeaders?: Record<string, string | string[] | undefined>, routePattern?: string, routeFile?: string, routeId?: string }} input
42
- * @returns {Promise<{ result: { kind: string, [key: string]: unknown }, trace: { guard: string, action: string, load: string }, status?: number }>}
43
- */
44
- export function executeServerRoute({ source, sourcePath, params, requestUrl, requestMethod, requestHeaders, requestBodyBase64, routePattern, routeFile, routeId, guardOnly }: {
45
- source: string;
46
- sourcePath: string;
47
- params: Record<string, string>;
48
- requestUrl?: string;
49
- requestMethod?: string;
50
- requestHeaders?: Record<string, string | string[] | undefined>;
51
- routePattern?: string;
52
- routeFile?: string;
53
- routeId?: string;
54
- }): Promise<{
55
- result: {
56
- kind: string;
57
- [key: string]: unknown;
58
- };
59
- trace: {
60
- guard: string;
61
- action: string;
62
- load: string;
63
- };
64
- status?: number;
65
- }>;
66
- /**
67
- * @param {{ source: string, sourcePath: string, params: Record<string, string>, requestUrl?: string, requestMethod?: string, requestHeaders?: Record<string, string | string[] | undefined>, routePattern?: string, routeFile?: string, routeId?: string }} input
68
- * @returns {Promise<Record<string, unknown> | null>}
69
- */
70
- export function executeServerScript(input: {
71
- source: string;
72
- sourcePath: string;
73
- params: Record<string, string>;
74
- requestUrl?: string;
75
- requestMethod?: string;
76
- requestHeaders?: Record<string, string | string[] | undefined>;
77
- routePattern?: string;
78
- routeFile?: string;
79
- routeId?: string;
80
- }): Promise<Record<string, unknown> | null>;
81
- /**
82
- * @param {string} html
83
- * @param {Record<string, unknown>} payload
84
- * @returns {string}
85
- */
86
- export function injectSsrPayload(html: string, payload: Record<string, unknown>): string;
87
- export function toStaticFilePath(distDir: any, pathname: any): string | null;
88
- export function resolveWithinDist(distDir: any, requestPath: any): string | null;
89
- export const matchRoute: typeof matchManifestRoute;
90
- export type PreviewRoute = {
91
- path: string;
92
- output: string;
93
- server_script?: string | null;
94
- server_script_path?: string | null;
95
- prerender?: boolean;
96
- route_id?: string;
97
- pattern?: string;
98
- params_shape?: Record<string, string>;
99
- has_guard?: boolean;
100
- has_load?: boolean;
101
- guard_module_ref?: string | null;
102
- load_module_ref?: string | null;
103
- };
104
- import { matchRoute as matchManifestRoute } from './server/resolve-request-route.js';
1
+ export { createPreviewServer } from "./preview/create-preview-server.js";
2
+ export { injectSsrPayload } from "./preview/payload.js";
3
+ export { loadRouteManifest, loadRouteSurfaceState, matchRoute } from "./preview/manifest.js";
4
+ export { executeServerRoute, executeServerScript } from "./preview/server-runner.js";
5
+ export { toStaticFilePath, resolveWithinDist } from "./preview/paths.js";