@useavalon/avalon 0.1.23 → 0.1.25

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 (115) hide show
  1. package/dist/mod.d.ts +50 -0
  2. package/dist/src/build/integration-bundler-plugin.d.ts +25 -0
  3. package/dist/src/build/integration-config.d.ts +44 -0
  4. package/dist/src/build/integration-detection-plugin.d.ts +20 -0
  5. package/dist/src/build/integration-resolver-plugin.d.ts +10 -0
  6. package/dist/src/build/island-manifest.d.ts +57 -0
  7. package/dist/src/build/island-types-generator.d.ts +49 -0
  8. package/dist/src/build/mdx-island-transform.d.ts +23 -0
  9. package/dist/src/build/mdx-plugin.d.ts +36 -0
  10. package/dist/src/build/page-island-transform.d.ts +41 -0
  11. package/dist/src/build/prop-extractors/index.d.ts +8 -0
  12. package/dist/src/build/prop-extractors/lit.d.ts +11 -0
  13. package/dist/src/build/prop-extractors/qwik.d.ts +9 -0
  14. package/dist/src/build/prop-extractors/solid.d.ts +12 -0
  15. package/dist/src/build/prop-extractors/svelte.d.ts +13 -0
  16. package/dist/src/build/prop-extractors/vue.d.ts +19 -0
  17. package/dist/src/build/sidecar-file-manager.d.ts +23 -0
  18. package/dist/src/build/sidecar-renderer.d.ts +22 -0
  19. package/dist/src/client/adapters/index.d.ts +15 -0
  20. package/dist/src/client/components.d.ts +21 -0
  21. package/dist/src/client/css-hmr-handler.d.ts +94 -0
  22. package/dist/src/client/framework-adapter.d.ts +225 -0
  23. package/dist/src/client/hmr-coordinator.d.ts +88 -0
  24. package/dist/src/client/main.js +1 -1
  25. package/dist/src/components/Image.d.ts +61 -0
  26. package/dist/src/components/IslandErrorBoundary.d.ts +37 -0
  27. package/dist/src/components/IslandErrorBoundary.js +1 -1
  28. package/dist/src/components/LayoutDataErrorBoundary.d.ts +34 -0
  29. package/dist/src/components/LayoutDataErrorBoundary.js +1 -1
  30. package/dist/src/components/LayoutErrorBoundary.d.ts +25 -0
  31. package/dist/src/components/LayoutErrorBoundary.js +1 -1
  32. package/dist/src/components/PersistentIsland.d.ts +36 -0
  33. package/dist/src/components/StreamingErrorBoundary.d.ts +42 -0
  34. package/dist/src/components/StreamingErrorBoundary.js +1 -1
  35. package/dist/src/components/StreamingLayout.d.ts +83 -0
  36. package/dist/src/components/StreamingLayout.js +1 -1
  37. package/dist/src/core/components/component-analyzer.d.ts +48 -0
  38. package/dist/src/core/components/component-detection.d.ts +72 -0
  39. package/dist/src/core/components/enhanced-framework-detector.d.ts +78 -0
  40. package/dist/src/core/components/framework-registry.d.ts +114 -0
  41. package/dist/src/core/content/mdx-processor.d.ts +14 -0
  42. package/dist/src/core/integrations/index.d.ts +6 -0
  43. package/dist/src/core/integrations/loader.d.ts +35 -0
  44. package/dist/src/core/integrations/registry.d.ts +51 -0
  45. package/dist/src/core/islands/island-persistence.d.ts +74 -0
  46. package/dist/src/core/islands/island-state-serializer.d.ts +53 -0
  47. package/dist/src/core/islands/persistent-island-context.d.ts +36 -0
  48. package/dist/src/core/islands/use-persistent-state.d.ts +17 -0
  49. package/dist/src/core/layout/enhanced-layout-resolver.d.ts +73 -0
  50. package/dist/src/core/layout/layout-cache-manager.d.ts +66 -0
  51. package/dist/src/core/layout/layout-composer.d.ts +63 -0
  52. package/dist/src/core/layout/layout-data-loader.d.ts +146 -0
  53. package/dist/src/core/layout/layout-discovery.d.ts +51 -0
  54. package/dist/src/core/layout/layout-matcher.d.ts +77 -0
  55. package/dist/src/core/layout/layout-types.d.ts +94 -0
  56. package/dist/src/core/modules/framework-module-resolver.d.ts +85 -0
  57. package/dist/src/islands/component-analysis.d.ts +38 -0
  58. package/dist/src/islands/css-utils.d.ts +81 -0
  59. package/dist/src/islands/discovery/index.d.ts +16 -0
  60. package/dist/src/islands/discovery/registry.d.ts +141 -0
  61. package/dist/src/islands/discovery/resolver.d.ts +190 -0
  62. package/dist/src/islands/discovery/scanner.d.ts +55 -0
  63. package/dist/src/islands/discovery/types.d.ts +92 -0
  64. package/dist/src/islands/discovery/validator.d.ts +89 -0
  65. package/dist/src/islands/discovery/watcher.d.ts +95 -0
  66. package/dist/src/islands/framework-detection.d.ts +53 -0
  67. package/dist/src/islands/integration-loader.d.ts +139 -0
  68. package/dist/src/islands/island.d.ts +55 -0
  69. package/dist/src/islands/render-cache.d.ts +203 -0
  70. package/dist/src/islands/types.d.ts +63 -0
  71. package/dist/src/islands/universal-css-collector.d.ts +41 -0
  72. package/dist/src/islands/universal-head-collector.d.ts +42 -0
  73. package/dist/src/layout-system.d.ts +92 -592
  74. package/dist/src/middleware/discovery.d.ts +70 -0
  75. package/dist/src/middleware/executor.d.ts +52 -0
  76. package/dist/src/middleware/index.d.ts +43 -0
  77. package/dist/src/middleware/types.d.ts +89 -0
  78. package/dist/src/nitro/build-config.d.ts +163 -0
  79. package/dist/src/nitro/config.d.ts +268 -0
  80. package/dist/src/nitro/error-handler.d.ts +151 -0
  81. package/dist/src/nitro/index.d.ts +15 -0
  82. package/dist/src/nitro/island-manifest.d.ts +191 -0
  83. package/dist/src/nitro/middleware-adapter.d.ts +151 -0
  84. package/dist/src/nitro/renderer.d.ts +342 -0
  85. package/dist/src/nitro/route-discovery.d.ts +142 -0
  86. package/dist/src/nitro/types.d.ts +278 -0
  87. package/dist/src/render/collect-css.d.ts +28 -0
  88. package/dist/src/render/error-pages.d.ts +14 -0
  89. package/dist/src/render/isolated-ssr-renderer.d.ts +127 -0
  90. package/dist/src/render/ssr.d.ts +56 -0
  91. package/dist/src/schemas/api.d.ts +27 -0
  92. package/dist/src/schemas/core.d.ts +75 -0
  93. package/dist/src/schemas/index.d.ts +79 -0
  94. package/dist/src/schemas/index.js +1 -1
  95. package/dist/src/schemas/layout.d.ts +282 -0
  96. package/dist/src/schemas/routing/index.d.ts +181 -0
  97. package/dist/src/schemas/routing.d.ts +388 -0
  98. package/dist/src/types/as-island.d.ts +17 -0
  99. package/dist/src/types/layout.d.ts +177 -0
  100. package/dist/src/types/routing.d.ts +297 -0
  101. package/dist/src/types/types.d.ts +6 -0
  102. package/dist/src/utils/dev-logger.d.ts +84 -0
  103. package/dist/src/utils/fs.d.ts +41 -0
  104. package/dist/src/vite-plugin/auto-discover.d.ts +72 -0
  105. package/dist/src/vite-plugin/config.d.ts +82 -0
  106. package/dist/src/vite-plugin/errors.d.ts +62 -0
  107. package/dist/src/vite-plugin/image-optimization.d.ts +36 -0
  108. package/dist/src/vite-plugin/integration-activator.d.ts +48 -0
  109. package/dist/src/vite-plugin/island-sidecar-plugin.d.ts +17 -0
  110. package/dist/src/vite-plugin/module-discovery.d.ts +66 -0
  111. package/dist/src/vite-plugin/nitro-integration.d.ts +56 -0
  112. package/dist/src/vite-plugin/plugin.d.ts +51 -0
  113. package/dist/src/vite-plugin/types.d.ts +281 -0
  114. package/dist/src/vite-plugin/validation.d.ts +93 -0
  115. package/package.json +33 -9
@@ -0,0 +1,70 @@
1
+ /**
2
+ * Simplified Middleware Discovery
3
+ *
4
+ * This module provides a streamlined middleware discovery system that scans
5
+ * for _middleware.ts files in src/pages/ directories.
6
+ *
7
+ * Key features:
8
+ * - Scans src/pages/ for page middleware
9
+ * - Calculates priority based on directory depth (parent before child)
10
+ * - Creates URL patterns for route matching
11
+ *
12
+ * Note: API middleware is handled natively by Nitro and is not scanned here.
13
+ *
14
+ * Requirements: 3.1, 3.2, 3.3, 3.4
15
+ */
16
+ import type { MiddlewareRoute, MiddlewareDiscoveryOptions } from './types.ts';
17
+ /**
18
+ * Discovers route-scoped middleware files in the project
19
+ *
20
+ * Scans for _middleware.ts files in:
21
+ * - src/pages/ directory (and subdirectories) for page routes
22
+ *
23
+ * API middleware is handled natively by Nitro and is not scanned here.
24
+ *
25
+ * Middleware files are sorted by priority (directory depth), ensuring
26
+ * parent middleware executes before child middleware.
27
+ *
28
+ * @param options - Discovery options
29
+ * @returns Array of discovered middleware routes, sorted by priority
30
+ *
31
+ * @example
32
+ * ```ts
33
+ * const routes = await discoverScopedMiddleware({
34
+ * baseDir: 'src',
35
+ * devMode: true,
36
+ * });
37
+ *
38
+ * // Returns routes like:
39
+ * // [
40
+ * // { pattern: URLPattern('/blog/*'), filePath: 'src/pages/blog/_middleware.ts', priority: 51, type: 'pages' },
41
+ * // ]
42
+ * ```
43
+ */
44
+ export declare function discoverScopedMiddleware(options: MiddlewareDiscoveryOptions): Promise<MiddlewareRoute[]>;
45
+ /**
46
+ * Gets middleware routes that match a given URL
47
+ *
48
+ * Filters discovered routes to only include those that match the URL,
49
+ * respecting type isolation (page middleware doesn't run for API routes
50
+ * and vice versa).
51
+ *
52
+ * @param routes - All discovered middleware routes
53
+ * @param url - URL to match against
54
+ * @returns Matching routes, sorted by priority
55
+ *
56
+ * @example
57
+ * ```ts
58
+ * const allRoutes = await discoverScopedMiddleware({ baseDir: 'src' });
59
+ * const matchingRoutes = getMatchingMiddleware(allRoutes, new URL('http://localhost/blog/post-1'));
60
+ * ```
61
+ */
62
+ export declare function getMatchingMiddleware(routes: MiddlewareRoute[], url: URL): MiddlewareRoute[];
63
+ /**
64
+ * Clears the middleware discovery cache
65
+ *
66
+ * This is a no-op in the simplified discovery module since we don't
67
+ * maintain a persistent cache. The function is provided for API
68
+ * compatibility with the executor module.
69
+ */
70
+ export declare function clearDiscoveryCache(): void;
@@ -0,0 +1,52 @@
1
+ /**
2
+ * Simplified Middleware Executor
3
+ *
4
+ * This module provides a streamlined middleware execution system that aligns
5
+ * with Nitro's conventions while supporting Avalon's route-scoped middleware.
6
+ *
7
+ * Key features:
8
+ * - Nitro-style handler signature: return void to continue, return Response to terminate
9
+ * - Middleware caching for performance
10
+
11
+ * - Error propagation to Nitro's error handling
12
+ * - Context preservation: event.context modifications persist through the chain
13
+ * - Development logging for context changes
14
+ *
15
+ * Requirements: 1.2, 1.3, 1.4, 2.1, 2.2
16
+ */
17
+ import type { H3Event } from 'h3';
18
+ import type { MiddlewareRoute, MiddlewareExecutorOptions } from './types.ts';
19
+ /**
20
+ * Executes route-scoped middleware chain for a request
21
+ *
22
+ * 1. Finds middleware that matches the request URL
23
+ * 2. Executes them in priority order (parent before child)
24
+ * 3. Handles void return (continue) and Response return (terminate)
25
+ * 4. Propagates errors to Nitro's error handling
26
+ * 5. Preserves event.context modifications across the chain
27
+ * 6. Logs context changes in development mode
28
+ *
29
+ * @param event - H3 event object from Nitro
30
+ * @param routes - Discovered middleware routes from discoverScopedMiddleware
31
+ * @param options - Execution options
32
+ * @returns Response if middleware terminated the chain, undefined otherwise
33
+ */
34
+ export declare function executeScopedMiddleware(event: H3Event, routes: MiddlewareRoute[], options?: MiddlewareExecutorOptions): Promise<Response | undefined>;
35
+ /**
36
+ * Converts an absolute file path to a valid ESM import specifier.
37
+ * Windows absolute paths (C:\...) are converted to file:// URLs.
38
+ * On Unix, the path is returned as-is (no-op).
39
+ */
40
+ export declare function toImportSpecifier(filePath: string): string;
41
+ /** Clears the middleware cache (e.g. during hot reload) */
42
+ export declare function clearMiddlewareCache(): void;
43
+ /** Removes a specific middleware from the cache */
44
+ export declare function invalidateMiddleware(filePath: string): boolean;
45
+ /** Gets the current size of the middleware cache */
46
+ export declare function getMiddlewareCacheSize(): number;
47
+ /** Checks if a key exists in event.context */
48
+ export declare function hasContextValue(event: H3Event, key: string): boolean;
49
+ /** Gets a typed value from event.context */
50
+ export declare function getContextValue<T>(event: H3Event, key: string): T | undefined;
51
+ /** Sets a value in event.context with optional development logging */
52
+ export declare function setContextValue<T>(event: H3Event, key: string, value: T, devMode?: boolean): void;
@@ -0,0 +1,43 @@
1
+ /**
2
+ * Avalon Middleware Module
3
+ *
4
+ * This module provides a Nitro-aligned middleware system for Avalon that supports
5
+ * both global middleware (via Nitro's middleware/ directory) and route-scoped
6
+ * middleware (via _middleware.ts files in page/API directories).
7
+ *
8
+ * Key features:
9
+ * - Nitro-compatible handler signature: return void to continue, return Response to terminate
10
+ * - Route-scoped middleware discovery in src/pages/ and src/api/
11
+ * - Priority-based execution order (parent before child)
12
+ * - Type-safe context augmentation for H3 events
13
+ *
14
+ * @example
15
+ * ```ts
16
+ * // Define middleware with proper typing
17
+ * import { defineMiddleware } from 'avalon/middleware';
18
+ * import { getHeader, createError } from 'h3';
19
+ *
20
+ * export default defineMiddleware(async (event) => {
21
+ * const token = getHeader(event, 'Authorization');
22
+ * if (!token) {
23
+ * throw createError({ statusCode: 401, message: 'Unauthorized' });
24
+ * }
25
+ * event.context.user = await validateToken(token);
26
+ * });
27
+ * ```
28
+ *
29
+ * @example
30
+ * ```ts
31
+ * // Discover and execute middleware in your server
32
+ * import { discoverScopedMiddleware, executeScopedMiddleware } from 'avalon/middleware';
33
+ *
34
+ * const routes = await discoverScopedMiddleware({ baseDir: 'src', devMode: true });
35
+ * const response = await executeScopedMiddleware(event, routes);
36
+ * if (response) return response;
37
+ * ```
38
+ *
39
+ * Requirements: 4.3
40
+ */
41
+ export type { MiddlewareHandler, MiddlewareFileExport, MiddlewareRoute, MiddlewareDiscoveryOptions, MiddlewareExecutorOptions, } from './types.ts';
42
+ export { discoverScopedMiddleware, getMatchingMiddleware, clearDiscoveryCache } from './discovery.ts';
43
+ export { executeScopedMiddleware, clearMiddlewareCache, invalidateMiddleware, getMiddlewareCacheSize, hasContextValue, getContextValue, setContextValue, } from './executor.ts';
@@ -0,0 +1,89 @@
1
+ /**
2
+ * Nitro-Aligned Middleware Types
3
+ *
4
+ * This module defines types for Avalon's middleware system that align with
5
+ * Nitro's conventions while preserving route-scoped middleware features.
6
+ *
7
+ * Key differences from old middleware system:
8
+ * - Handler signature: (event: H3Event) => void | Response | Promise<void | Response>
9
+ * - Return void to continue, return Response to terminate
10
+ * - Uses event.context for data passing instead of custom state/locals
11
+ *
12
+ * Requirements: 1.1
13
+ */
14
+ import type { H3Event } from 'h3';
15
+ /**
16
+ * Nitro-aligned middleware handler signature
17
+ *
18
+ * This signature matches Nitro's middleware conventions:
19
+ * - Return nothing (void/undefined) to continue to next middleware
20
+ * - Return a Response to terminate the chain and send that response
21
+ * - Throw an error to trigger Nitro's error handling
22
+ *
23
+ * @example
24
+ * ```ts
25
+ * const handler: MiddlewareHandler = async (event) => {
26
+ * // Check auth
27
+ * if (!event.context.user) {
28
+ * return new Response('Unauthorized', { status: 401 });
29
+ * }
30
+ * // Continue to next middleware
31
+ * };
32
+ * ```
33
+ */
34
+ export type MiddlewareHandler = (event: H3Event) => void | Response | Promise<void | Response>;
35
+ /**
36
+ * Route-scoped middleware file export interface
37
+ *
38
+ * Middleware files should export a default function matching the MiddlewareHandler signature.
39
+ *
40
+ * @example
41
+ * ```ts
42
+ * // src/pages/admin/_middleware.ts
43
+ * export default async (event) => {
44
+ * // middleware logic
45
+ * };
46
+ * ```
47
+ */
48
+ export interface MiddlewareFileExport {
49
+ /** Default export must be a MiddlewareHandler function */
50
+ default: MiddlewareHandler;
51
+ }
52
+ /**
53
+ * Discovered middleware route configuration
54
+ *
55
+ * Represents a middleware file discovered during scanning, with its
56
+ * URL pattern, file path, execution priority, and type.
57
+ */
58
+ export interface MiddlewareRoute {
59
+ /** URL pattern for matching requests */
60
+ pattern: URLPattern;
61
+ /** Absolute path to the middleware file */
62
+ filePath: string;
63
+ /** Execution priority (lower numbers execute first) */
64
+ priority: number;
65
+ /** Middleware type - determines which routes it applies to */
66
+ type: 'global' | 'pages';
67
+ }
68
+ /**
69
+ * Middleware discovery options
70
+ */
71
+ export interface MiddlewareDiscoveryOptions {
72
+ /** Base directory to scan (e.g., 'src') */
73
+ baseDir: string;
74
+ /** File pattern to match (default: '_middleware.ts') */
75
+ filePattern?: string;
76
+ /** Directories to exclude from scanning */
77
+ excludeDirs?: string[];
78
+ /** Enable development mode logging */
79
+ devMode?: boolean;
80
+ }
81
+ /**
82
+ * Middleware execution options
83
+ */
84
+ export interface MiddlewareExecutorOptions {
85
+ /** Enable development mode logging */
86
+ devMode?: boolean;
87
+ /** Timeout for middleware execution in milliseconds */
88
+ timeout?: number;
89
+ }
@@ -0,0 +1,163 @@
1
+ /**
2
+ * Nitro Build Configuration Module for Avalon
3
+ *
4
+ * This module provides build configuration utilities for integrating Nitro
5
+ * with Avalon's Vite-based build pipeline. It handles:
6
+ * - Vite client build configuration
7
+ * - Nitro server build configuration
8
+ * - Preset-specific output configuration
9
+ * - Source map generation
10
+ *
11
+ * @module nitro/build-config
12
+ */
13
+ import type { Plugin, UserConfig, BuildOptions } from "vite";
14
+ import type { ResolvedAvalonConfig } from "../vite-plugin/types.ts";
15
+ import type { AvalonNitroConfig } from "./config.ts";
16
+ /**
17
+ * Build mode for the Avalon application
18
+ */
19
+ export type BuildMode = "client" | "server" | "both";
20
+ /**
21
+ * Sourcemap option type
22
+ */
23
+ export type SourcemapOption = boolean | "inline" | "hidden";
24
+ /**
25
+ * Minify option type
26
+ */
27
+ export type MinifyOption = boolean | "oxc" | "esbuild" | "terser";
28
+ /**
29
+ * Preset-specific build output configuration
30
+ */
31
+ export interface PresetOutputConfig {
32
+ /** Output directory for the preset */
33
+ outputDir: string;
34
+ /** Server entry file name */
35
+ serverEntry: string;
36
+ /** Whether the preset supports streaming */
37
+ supportsStreaming: boolean;
38
+ /** Whether the preset requires bundled dependencies */
39
+ bundleDependencies: boolean;
40
+ /** Additional files to include in output */
41
+ additionalFiles?: string[];
42
+ /** Environment-specific configuration */
43
+ env?: Record<string, string>;
44
+ }
45
+ /**
46
+ * Avalon build configuration options
47
+ */
48
+ export interface AvalonBuildConfig {
49
+ /** Build mode: client, server, or both */
50
+ mode: BuildMode;
51
+ /** Output directory for client assets */
52
+ clientOutDir: string;
53
+ /** Output directory for server bundle */
54
+ serverOutDir: string;
55
+ /** Enable source maps */
56
+ sourcemap: SourcemapOption;
57
+ /** Minify output */
58
+ minify: MinifyOption;
59
+ /** Target environment */
60
+ target: string | string[];
61
+ /** Enable SSR build */
62
+ ssr: boolean;
63
+ /** Nitro preset for deployment */
64
+ preset: string;
65
+ /** Enable verbose logging */
66
+ verbose: boolean;
67
+ /** Nitro v3: Compatibility date for preset features (YYYY-MM-DD) */
68
+ compatibilityDate?: string;
69
+ /** Nitro v3: Dependencies to trace instead of bundle */
70
+ traceDeps?: string[];
71
+ /** Nitro v3: Rolldown-specific configuration */
72
+ rolldownConfig?: Record<string, unknown>;
73
+ /** Nitro v3: Custom server entry point */
74
+ serverEntry?: string;
75
+ }
76
+ /**
77
+ * Default build configuration values
78
+ */
79
+ export declare const DEFAULT_BUILD_CONFIG: AvalonBuildConfig;
80
+ /**
81
+ * Preset-specific output configurations
82
+ */
83
+ export declare const PRESET_OUTPUT_CONFIGS: Record<string, PresetOutputConfig>;
84
+ /**
85
+ * Creates the Vite client build configuration
86
+ *
87
+ * @param avalonConfig - Resolved Avalon configuration
88
+ * @param buildConfig - Build configuration options
89
+ * @returns Vite build options for client build
90
+ */
91
+ export declare function createClientBuildConfig(avalonConfig: ResolvedAvalonConfig, buildConfig?: Partial<AvalonBuildConfig>): BuildOptions;
92
+ /**
93
+ * Creates the Vite server build configuration for Nitro
94
+ *
95
+ * @param avalonConfig - Resolved Avalon configuration
96
+ * @param nitroConfig - Nitro configuration
97
+ * @param buildConfig - Build configuration options
98
+ * @returns Vite build options for server build
99
+ */
100
+ export declare function createServerBuildConfig(avalonConfig: ResolvedAvalonConfig, nitroConfig: AvalonNitroConfig, buildConfig?: Partial<AvalonBuildConfig>): BuildOptions;
101
+ /**
102
+ * Gets the preset output configuration
103
+ *
104
+ * @param preset - Nitro preset name
105
+ * @returns Preset output configuration
106
+ */
107
+ export declare function getPresetOutputConfig(preset: string): PresetOutputConfig;
108
+ /**
109
+ * Checks if a preset supports streaming SSR
110
+ *
111
+ * @param preset - Nitro preset name
112
+ * @returns True if the preset supports streaming
113
+ */
114
+ export declare function presetSupportsStreaming(preset: string): boolean;
115
+ /**
116
+ * Creates the combined build configuration for both client and server
117
+ *
118
+ * @param avalonConfig - Resolved Avalon configuration
119
+ * @param nitroConfig - Nitro configuration
120
+ * @param buildConfig - Build configuration options
121
+ * @returns Combined Vite user config
122
+ */
123
+ export declare function createCombinedBuildConfig(avalonConfig: ResolvedAvalonConfig, nitroConfig: AvalonNitroConfig, buildConfig?: Partial<AvalonBuildConfig>): Partial<UserConfig>;
124
+ /**
125
+ * Creates a Vite plugin for Nitro build integration
126
+ */
127
+ export declare function createNitroBuildPlugin(avalonConfig: ResolvedAvalonConfig, nitroConfig: AvalonNitroConfig): Plugin;
128
+ /**
129
+ * Validates build configuration
130
+ */
131
+ export declare function validateBuildConfig(config: Partial<AvalonBuildConfig>): {
132
+ valid: boolean;
133
+ errors: string[];
134
+ };
135
+ /**
136
+ * Source map configuration options
137
+ */
138
+ export interface SourceMapConfig {
139
+ /** Enable source maps */
140
+ enabled: boolean;
141
+ /** Source map type: true for external, 'inline' for inline, 'hidden' for hidden */
142
+ type: SourcemapOption;
143
+ /** Include source content in source maps */
144
+ includeContent: boolean;
145
+ /** Source map URL prefix */
146
+ sourceRoot?: string;
147
+ }
148
+ /**
149
+ * Default source map configuration
150
+ */
151
+ export declare const DEFAULT_SOURCEMAP_CONFIG: SourceMapConfig;
152
+ /**
153
+ * Creates source map configuration based on environment and preset
154
+ */
155
+ export declare function createSourceMapConfig(preset: string, isDev: boolean): SourceMapConfig;
156
+ /**
157
+ * Gets the Vite sourcemap option from SourceMapConfig
158
+ */
159
+ export declare function getViteSourceMapOption(config: SourceMapConfig): SourcemapOption;
160
+ /**
161
+ * Creates a Vite plugin for source map handling
162
+ */
163
+ export declare function createSourceMapPlugin(config: SourceMapConfig): Plugin;
@@ -0,0 +1,268 @@
1
+ /**
2
+ * Nitro Configuration Module for Avalon
3
+ *
4
+ * This module provides configuration interfaces and utilities for integrating
5
+ * Nitro as Avalon's server runtime. It handles preset configuration, route rules,
6
+ * and merging Avalon-specific options with Nitro defaults.
7
+ *
8
+ * ## Static Asset Handling
9
+ *
10
+ * Nitro automatically serves static assets from the `public/` directory at the root path.
11
+ * The configuration supports:
12
+ * - `publicAssets`: Configures directories for static file serving
13
+ * - `routeRules`: Configures cache headers for different asset types
14
+ * - `staticAssets`: Avalon-specific static asset configuration
15
+ *
16
+ * Default route rules for static assets are generated by `createDefaultStaticAssetRouteRules()`:
17
+ * - `/assets/**`, `/islands/**`, `/chunks/**`: Long cache (1 year, immutable)
18
+ * - `/*.woff`, `/*.woff2`: Long cache for fonts
19
+ * - `/*.html`, `/*.css`: Short cache with revalidation
20
+ * - `/favicon.ico`: Medium cache (1 day)
21
+ */
22
+ import type { ResolvedAvalonConfig } from '../vite-plugin/types.ts';
23
+ /**
24
+ * Cache configuration options for route rules
25
+ */
26
+ export interface CacheOptions {
27
+ /** Maximum age in seconds for cache validity */
28
+ maxAge?: number;
29
+ /** Maximum age in seconds for stale content */
30
+ staleMaxAge?: number;
31
+ /** Enable stale-while-revalidate behavior */
32
+ swr?: boolean;
33
+ }
34
+ /**
35
+ * Route rule configuration for caching, redirects, proxying, and headers
36
+ */
37
+ export interface RouteRule {
38
+ /** Cache configuration or boolean to enable/disable */
39
+ cache?: CacheOptions | boolean;
40
+ /** Redirect destination URL */
41
+ redirect?: string;
42
+ /** Proxy destination URL */
43
+ proxy?: string;
44
+ /** Custom headers to set */
45
+ headers?: Record<string, string>;
46
+ /** Enable CORS for this route */
47
+ cors?: boolean;
48
+ }
49
+ /**
50
+ * Static asset serving configuration
51
+ */
52
+ export interface StaticAssetsConfig {
53
+ /**
54
+ * Directory containing public static assets
55
+ * @default "public"
56
+ */
57
+ publicDir?: string;
58
+ /**
59
+ * Directory containing compiled build output
60
+ * @default "dist"
61
+ */
62
+ buildDir?: string;
63
+ /**
64
+ * Enable serving pre-compressed assets (gzip, brotli)
65
+ * @default true
66
+ */
67
+ compression?: boolean;
68
+ /**
69
+ * Default cache control header for immutable static assets
70
+ * @default "public, max-age=31536000, immutable"
71
+ */
72
+ cacheControl?: string;
73
+ /**
74
+ * Cache control header for mutable assets (HTML, etc.)
75
+ * @default "public, max-age=0, must-revalidate"
76
+ */
77
+ mutableCacheControl?: string;
78
+ /**
79
+ * Custom headers to add to all static asset responses
80
+ */
81
+ headers?: Record<string, string>;
82
+ }
83
+ /**
84
+ * Avalon-specific Nitro configuration options
85
+ */
86
+ export interface AvalonNitroConfig {
87
+ /**
88
+ * Deployment preset (vercel, cloudflare, deno-deploy, node-server, netlify, etc.)
89
+ * @default "node-server"
90
+ */
91
+ preset?: string;
92
+ /**
93
+ * Directory containing server routes
94
+ * @default "server"
95
+ */
96
+ serverDir?: string;
97
+ /**
98
+ * Directory containing pages (overrides Avalon config if set)
99
+ */
100
+ pagesDir?: string;
101
+ /**
102
+ * Enable streaming SSR responses
103
+ * @default true
104
+ */
105
+ streaming?: boolean;
106
+ /**
107
+ * Route rules for caching, redirects, proxying, and headers
108
+ * Keys are route patterns (e.g., "/api/**", "/static/**")
109
+ */
110
+ routeRules?: Record<string, RouteRule>;
111
+ /**
112
+ * Runtime configuration accessible via useRuntimeConfig()
113
+ * Can be overridden by NITRO_ prefixed environment variables
114
+ */
115
+ runtimeConfig?: Record<string, unknown>;
116
+ /**
117
+ * Public runtime configuration (exposed to client)
118
+ */
119
+ publicRuntimeConfig?: Record<string, unknown>;
120
+ /**
121
+ * Static asset serving configuration
122
+ */
123
+ staticAssets?: StaticAssetsConfig;
124
+ /** Nitro v3: Compatibility date for preset features (YYYY-MM-DD) */
125
+ compatibilityDate?: string;
126
+ /** Nitro v3: Dependencies to trace instead of bundle */
127
+ traceDeps?: string[];
128
+ /** Nitro v3: Rolldown-specific configuration */
129
+ rolldownConfig?: Record<string, unknown>;
130
+ /** Nitro v3: Custom server entry point */
131
+ serverEntry?: string;
132
+ /** Nitro v3: Renderer configuration, or false to disable */
133
+ renderer?: {
134
+ handler: string;
135
+ } | false;
136
+ /** Nitro v3: Pre-compress public assets (gzip, brotli, zstd) */
137
+ compressPublicAssets?: boolean | {
138
+ gzip?: boolean;
139
+ brotli?: boolean;
140
+ zstd?: boolean;
141
+ };
142
+ }
143
+ /**
144
+ * Nitro configuration output structure
145
+ * This matches the expected NitroConfig interface from nitro/types
146
+ */
147
+ export interface NitroConfigOutput {
148
+ /** Deployment preset */
149
+ preset: string;
150
+ /** Server directory */
151
+ serverDir: string;
152
+ /** Route rules */
153
+ routeRules: Record<string, RouteRule>;
154
+ /** Runtime configuration */
155
+ runtimeConfig: {
156
+ avalon: AvalonRuntimeConfig;
157
+ [key: string]: unknown;
158
+ };
159
+ /** Public runtime configuration */
160
+ publicRuntimeConfig?: Record<string, unknown>;
161
+ /** Renderer configuration, or false to disable */
162
+ renderer?: {
163
+ handler: string;
164
+ } | false;
165
+ /** Nitro v3: Compatibility date for preset features (YYYY-MM-DD) */
166
+ compatibilityDate?: string;
167
+ /** Nitro v3: Dependencies to trace instead of bundle */
168
+ traceDeps?: string[];
169
+ /** Nitro v3: Rolldown-specific configuration */
170
+ rolldownConfig?: Record<string, unknown>;
171
+ /** Nitro v3: Custom server entry point */
172
+ serverEntry?: string;
173
+ /** Nitro v3: Pre-compress public assets (gzip, brotli, zstd) */
174
+ compressPublicAssets?: boolean | {
175
+ gzip?: boolean;
176
+ brotli?: boolean;
177
+ zstd?: boolean;
178
+ };
179
+ /** Public assets directory */
180
+ publicAssets?: Array<{
181
+ dir: string;
182
+ baseURL?: string;
183
+ maxAge?: number;
184
+ }>;
185
+ /** Server assets configuration */
186
+ serverAssets?: Array<{
187
+ baseName: string;
188
+ dir: string;
189
+ }>;
190
+ /** Static assets configuration */
191
+ staticAssets?: StaticAssetsConfig;
192
+ }
193
+ /**
194
+ * Avalon-specific runtime configuration stored in Nitro's runtimeConfig
195
+ */
196
+ export interface AvalonRuntimeConfig {
197
+ /** Enable streaming SSR */
198
+ streaming: boolean;
199
+ /** Pages directory path */
200
+ pagesDir: string;
201
+ /** Layouts directory path */
202
+ layoutsDir: string;
203
+ /** Source directory path */
204
+ srcDir?: string;
205
+ }
206
+ /**
207
+ * Default static assets configuration
208
+ */
209
+ export declare const DEFAULT_STATIC_ASSETS_CONFIG: Required<StaticAssetsConfig>;
210
+ /**
211
+ * All valid Nitro v3 preset names (underscore convention).
212
+ */
213
+ export declare const VALID_V3_PRESETS: string[];
214
+ /**
215
+ * Validates a preset name against the v3 preset list.
216
+ * Returns the preset name if valid, throws if unrecognized.
217
+ *
218
+ * @param preset - The preset name to validate (must be a v3 name)
219
+ * @returns The validated v3 preset name
220
+ * @throws Error if the preset is not recognized
221
+ */
222
+ export declare function resolvePresetName(preset: string): string;
223
+ /**
224
+ * Default Nitro configuration values
225
+ */
226
+ export declare const DEFAULT_NITRO_CONFIG: Required<Pick<AvalonNitroConfig, 'preset' | 'serverDir' | 'streaming'>>;
227
+ /**
228
+ * Creates a Nitro configuration from Avalon plugin config and Nitro-specific options
229
+ *
230
+ * This function merges Avalon's resolved configuration with Nitro-specific options
231
+ * to produce a complete Nitro configuration object. Avalon-specific settings are
232
+ * stored in `runtimeConfig.avalon` for access by handlers.
233
+ *
234
+ * @param avalonNitroConfig - Nitro-specific configuration options
235
+ * @param resolvedAvalonConfig - Resolved Avalon plugin configuration
236
+ * @returns Complete Nitro configuration object
237
+ *
238
+ * @example
239
+ * ```ts
240
+ * const nitroConfig = createNitroConfig(
241
+ * { preset: 'vercel', streaming: true },
242
+ * resolvedAvalonConfig
243
+ * );
244
+ * ```
245
+ */
246
+ export declare function createNitroConfig(avalonNitroConfig: AvalonNitroConfig, resolvedAvalonConfig: ResolvedAvalonConfig): NitroConfigOutput;
247
+ /**
248
+ * Creates default route rules for static asset caching
249
+ *
250
+ * @param config - Static assets configuration
251
+ * @returns Route rules for static assets
252
+ */
253
+ export declare function createDefaultStaticAssetRouteRules(config: StaticAssetsConfig): Record<string, RouteRule>;
254
+ /**
255
+ * Validates a Nitro preset name against the v3 preset list
256
+ *
257
+ * @param preset - The preset name to validate
258
+ * @returns True if the preset is a known valid v3 preset
259
+ */
260
+ export declare function isValidPreset(preset: string): boolean;
261
+ /**
262
+ * Merges route rules, with later rules taking precedence
263
+ *
264
+ * @param baseRules - Base route rules
265
+ * @param overrideRules - Override route rules
266
+ * @returns Merged route rules
267
+ */
268
+ export declare function mergeRouteRules(baseRules: Record<string, RouteRule>, overrideRules: Record<string, RouteRule>): Record<string, RouteRule>;