@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.
- package/dist/mod.d.ts +50 -0
- package/dist/src/build/integration-bundler-plugin.d.ts +25 -0
- package/dist/src/build/integration-config.d.ts +44 -0
- package/dist/src/build/integration-detection-plugin.d.ts +20 -0
- package/dist/src/build/integration-resolver-plugin.d.ts +10 -0
- package/dist/src/build/island-manifest.d.ts +57 -0
- package/dist/src/build/island-types-generator.d.ts +49 -0
- package/dist/src/build/mdx-island-transform.d.ts +23 -0
- package/dist/src/build/mdx-plugin.d.ts +36 -0
- package/dist/src/build/page-island-transform.d.ts +41 -0
- package/dist/src/build/prop-extractors/index.d.ts +8 -0
- package/dist/src/build/prop-extractors/lit.d.ts +11 -0
- package/dist/src/build/prop-extractors/qwik.d.ts +9 -0
- package/dist/src/build/prop-extractors/solid.d.ts +12 -0
- package/dist/src/build/prop-extractors/svelte.d.ts +13 -0
- package/dist/src/build/prop-extractors/vue.d.ts +19 -0
- package/dist/src/build/sidecar-file-manager.d.ts +23 -0
- package/dist/src/build/sidecar-renderer.d.ts +22 -0
- package/dist/src/client/adapters/index.d.ts +15 -0
- package/dist/src/client/components.d.ts +21 -0
- package/dist/src/client/css-hmr-handler.d.ts +94 -0
- package/dist/src/client/framework-adapter.d.ts +225 -0
- package/dist/src/client/hmr-coordinator.d.ts +88 -0
- package/dist/src/client/main.js +1 -1
- package/dist/src/components/Image.d.ts +61 -0
- package/dist/src/components/IslandErrorBoundary.d.ts +37 -0
- package/dist/src/components/IslandErrorBoundary.js +1 -1
- package/dist/src/components/LayoutDataErrorBoundary.d.ts +34 -0
- package/dist/src/components/LayoutDataErrorBoundary.js +1 -1
- package/dist/src/components/LayoutErrorBoundary.d.ts +25 -0
- package/dist/src/components/LayoutErrorBoundary.js +1 -1
- package/dist/src/components/PersistentIsland.d.ts +36 -0
- package/dist/src/components/StreamingErrorBoundary.d.ts +42 -0
- package/dist/src/components/StreamingErrorBoundary.js +1 -1
- package/dist/src/components/StreamingLayout.d.ts +83 -0
- package/dist/src/components/StreamingLayout.js +1 -1
- package/dist/src/core/components/component-analyzer.d.ts +48 -0
- package/dist/src/core/components/component-detection.d.ts +72 -0
- package/dist/src/core/components/enhanced-framework-detector.d.ts +78 -0
- package/dist/src/core/components/framework-registry.d.ts +114 -0
- package/dist/src/core/content/mdx-processor.d.ts +14 -0
- package/dist/src/core/integrations/index.d.ts +6 -0
- package/dist/src/core/integrations/loader.d.ts +35 -0
- package/dist/src/core/integrations/registry.d.ts +51 -0
- package/dist/src/core/islands/island-persistence.d.ts +74 -0
- package/dist/src/core/islands/island-state-serializer.d.ts +53 -0
- package/dist/src/core/islands/persistent-island-context.d.ts +36 -0
- package/dist/src/core/islands/use-persistent-state.d.ts +17 -0
- package/dist/src/core/layout/enhanced-layout-resolver.d.ts +73 -0
- package/dist/src/core/layout/layout-cache-manager.d.ts +66 -0
- package/dist/src/core/layout/layout-composer.d.ts +63 -0
- package/dist/src/core/layout/layout-data-loader.d.ts +146 -0
- package/dist/src/core/layout/layout-discovery.d.ts +51 -0
- package/dist/src/core/layout/layout-matcher.d.ts +77 -0
- package/dist/src/core/layout/layout-types.d.ts +94 -0
- package/dist/src/core/modules/framework-module-resolver.d.ts +85 -0
- package/dist/src/islands/component-analysis.d.ts +38 -0
- package/dist/src/islands/css-utils.d.ts +81 -0
- package/dist/src/islands/discovery/index.d.ts +16 -0
- package/dist/src/islands/discovery/registry.d.ts +141 -0
- package/dist/src/islands/discovery/resolver.d.ts +190 -0
- package/dist/src/islands/discovery/scanner.d.ts +55 -0
- package/dist/src/islands/discovery/types.d.ts +92 -0
- package/dist/src/islands/discovery/validator.d.ts +89 -0
- package/dist/src/islands/discovery/watcher.d.ts +95 -0
- package/dist/src/islands/framework-detection.d.ts +53 -0
- package/dist/src/islands/integration-loader.d.ts +139 -0
- package/dist/src/islands/island.d.ts +55 -0
- package/dist/src/islands/render-cache.d.ts +203 -0
- package/dist/src/islands/types.d.ts +63 -0
- package/dist/src/islands/universal-css-collector.d.ts +41 -0
- package/dist/src/islands/universal-head-collector.d.ts +42 -0
- package/dist/src/layout-system.d.ts +92 -592
- package/dist/src/middleware/discovery.d.ts +70 -0
- package/dist/src/middleware/executor.d.ts +52 -0
- package/dist/src/middleware/index.d.ts +43 -0
- package/dist/src/middleware/types.d.ts +89 -0
- package/dist/src/nitro/build-config.d.ts +163 -0
- package/dist/src/nitro/config.d.ts +268 -0
- package/dist/src/nitro/error-handler.d.ts +151 -0
- package/dist/src/nitro/index.d.ts +15 -0
- package/dist/src/nitro/island-manifest.d.ts +191 -0
- package/dist/src/nitro/middleware-adapter.d.ts +151 -0
- package/dist/src/nitro/renderer.d.ts +342 -0
- package/dist/src/nitro/route-discovery.d.ts +142 -0
- package/dist/src/nitro/types.d.ts +278 -0
- package/dist/src/render/collect-css.d.ts +28 -0
- package/dist/src/render/error-pages.d.ts +14 -0
- package/dist/src/render/isolated-ssr-renderer.d.ts +127 -0
- package/dist/src/render/ssr.d.ts +56 -0
- package/dist/src/schemas/api.d.ts +27 -0
- package/dist/src/schemas/core.d.ts +75 -0
- package/dist/src/schemas/index.d.ts +79 -0
- package/dist/src/schemas/index.js +1 -1
- package/dist/src/schemas/layout.d.ts +282 -0
- package/dist/src/schemas/routing/index.d.ts +181 -0
- package/dist/src/schemas/routing.d.ts +388 -0
- package/dist/src/types/as-island.d.ts +17 -0
- package/dist/src/types/layout.d.ts +177 -0
- package/dist/src/types/routing.d.ts +297 -0
- package/dist/src/types/types.d.ts +6 -0
- package/dist/src/utils/dev-logger.d.ts +84 -0
- package/dist/src/utils/fs.d.ts +41 -0
- package/dist/src/vite-plugin/auto-discover.d.ts +72 -0
- package/dist/src/vite-plugin/config.d.ts +82 -0
- package/dist/src/vite-plugin/errors.d.ts +62 -0
- package/dist/src/vite-plugin/image-optimization.d.ts +36 -0
- package/dist/src/vite-plugin/integration-activator.d.ts +48 -0
- package/dist/src/vite-plugin/island-sidecar-plugin.d.ts +17 -0
- package/dist/src/vite-plugin/module-discovery.d.ts +66 -0
- package/dist/src/vite-plugin/nitro-integration.d.ts +56 -0
- package/dist/src/vite-plugin/plugin.d.ts +51 -0
- package/dist/src/vite-plugin/types.d.ts +281 -0
- package/dist/src/vite-plugin/validation.d.ts +93 -0
- package/package.json +33 -9
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Nitro Error Handler for Avalon
|
|
3
|
+
*
|
|
4
|
+
* This module provides error handling utilities for the Nitro integration,
|
|
5
|
+
* including support for custom error pages (404, 500, _error).
|
|
6
|
+
*
|
|
7
|
+
* Custom error pages are discovered from the pages directory:
|
|
8
|
+
* - src/pages/404.tsx → Custom 404 page
|
|
9
|
+
* - src/pages/500.tsx → Custom 500 page
|
|
10
|
+
* - src/pages/_error.tsx → Generic error page (fallback)
|
|
11
|
+
*
|
|
12
|
+
* Requirements: 10.1, 10.2, 10.3, 10.4, 10.5
|
|
13
|
+
*/
|
|
14
|
+
import type { PageModule, NitroRenderContext, AvalonRuntimeConfig } from "./types.ts";
|
|
15
|
+
import type { H3Event } from "h3";
|
|
16
|
+
import { HttpError } from "./types.ts";
|
|
17
|
+
/**
|
|
18
|
+
* Error page props passed to custom error page components
|
|
19
|
+
*/
|
|
20
|
+
export interface ErrorPageProps {
|
|
21
|
+
/** HTTP status code */
|
|
22
|
+
statusCode: number;
|
|
23
|
+
/** Error message */
|
|
24
|
+
message: string;
|
|
25
|
+
/** Error object (development only) */
|
|
26
|
+
error?: Error;
|
|
27
|
+
/** Stack trace (development only) */
|
|
28
|
+
stack?: string;
|
|
29
|
+
/** Request URL that caused the error */
|
|
30
|
+
url?: string;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Options for error handling
|
|
34
|
+
*/
|
|
35
|
+
export interface ErrorHandlerOptions {
|
|
36
|
+
/** Whether running in development mode */
|
|
37
|
+
isDev?: boolean;
|
|
38
|
+
/** Avalon runtime configuration */
|
|
39
|
+
avalonConfig?: AvalonRuntimeConfig;
|
|
40
|
+
/** Custom page module loader */
|
|
41
|
+
loadPageModule?: (filePath: string) => Promise<PageModule>;
|
|
42
|
+
/** Pages directory path */
|
|
43
|
+
pagesDir?: string;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Cache for discovered error pages
|
|
47
|
+
*/
|
|
48
|
+
interface ErrorPageCache {
|
|
49
|
+
/** Custom 404 page module */
|
|
50
|
+
notFound?: PageModule | null;
|
|
51
|
+
/** Custom 500 page module */
|
|
52
|
+
serverError?: PageModule | null;
|
|
53
|
+
/** Generic error page module */
|
|
54
|
+
genericError?: PageModule | null;
|
|
55
|
+
/** Whether cache has been initialized */
|
|
56
|
+
initialized: boolean;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Clears the error page cache
|
|
60
|
+
* Call this during development when error pages change
|
|
61
|
+
*/
|
|
62
|
+
export declare function clearErrorPageCache(): void;
|
|
63
|
+
/**
|
|
64
|
+
* Discovers and caches custom error pages from the pages directory
|
|
65
|
+
*
|
|
66
|
+
* @param options - Error handler options
|
|
67
|
+
* @returns Object containing discovered error page modules
|
|
68
|
+
*/
|
|
69
|
+
export declare function discoverErrorPages(options: ErrorHandlerOptions): Promise<ErrorPageCache>;
|
|
70
|
+
/**
|
|
71
|
+
* Gets the appropriate error page module for a status code
|
|
72
|
+
*
|
|
73
|
+
* @param statusCode - HTTP status code
|
|
74
|
+
* @param cache - Error page cache
|
|
75
|
+
* @returns Error page module or null if no custom page exists
|
|
76
|
+
*/
|
|
77
|
+
export declare function getErrorPageModule(statusCode: number, cache: ErrorPageCache): PageModule | null;
|
|
78
|
+
/**
|
|
79
|
+
* Creates error page props from an error
|
|
80
|
+
*
|
|
81
|
+
* @param error - The error that occurred
|
|
82
|
+
* @param url - Request URL
|
|
83
|
+
* @param isDev - Whether running in development mode
|
|
84
|
+
* @returns Error page props
|
|
85
|
+
*/
|
|
86
|
+
export declare function createErrorPageProps(error: Error | HttpError, url?: string, isDev?: boolean): ErrorPageProps;
|
|
87
|
+
/**
|
|
88
|
+
* Renders a custom error page to HTML
|
|
89
|
+
*
|
|
90
|
+
* @param pageModule - The error page module
|
|
91
|
+
* @param props - Error page props
|
|
92
|
+
* @param context - Render context
|
|
93
|
+
* @param isDev - Whether running in development mode
|
|
94
|
+
* @returns Rendered HTML string
|
|
95
|
+
*/
|
|
96
|
+
export declare function renderErrorPage(pageModule: PageModule, props: ErrorPageProps, context: NitroRenderContext, isDev: boolean): Promise<string>;
|
|
97
|
+
/**
|
|
98
|
+
* Generates a default error page when no custom page is available
|
|
99
|
+
*
|
|
100
|
+
* @param statusCode - HTTP status code
|
|
101
|
+
* @param message - Error message
|
|
102
|
+
* @param isDev - Whether running in development mode
|
|
103
|
+
* @param stack - Stack trace (development only)
|
|
104
|
+
* @returns HTML string
|
|
105
|
+
*/
|
|
106
|
+
export declare function generateDefaultErrorPage(statusCode: number, message: string, isDev: boolean, stack?: string): string;
|
|
107
|
+
/**
|
|
108
|
+
* Handles a render error and returns an appropriate response
|
|
109
|
+
*
|
|
110
|
+
* This function:
|
|
111
|
+
* 1. Discovers custom error pages if available
|
|
112
|
+
* 2. Renders the appropriate error page (custom or default)
|
|
113
|
+
* 3. Returns a Response with the correct status code
|
|
114
|
+
*
|
|
115
|
+
* Requirements: 10.1, 10.2, 10.3, 10.4, 10.5
|
|
116
|
+
*
|
|
117
|
+
* @param error - The error that occurred
|
|
118
|
+
* @param event - H3 event
|
|
119
|
+
* @param options - Error handler options
|
|
120
|
+
* @returns Response with error page
|
|
121
|
+
*/
|
|
122
|
+
export declare function handleRenderError(error: Error | HttpError, event: H3Event, options: ErrorHandlerOptions): Promise<Response>;
|
|
123
|
+
/**
|
|
124
|
+
* Handles an API error and returns an appropriate JSON response
|
|
125
|
+
*
|
|
126
|
+
* Requirements: 10.1, 10.2, 10.4
|
|
127
|
+
*
|
|
128
|
+
* @param error - The error that occurred
|
|
129
|
+
* @param options - Error handler options
|
|
130
|
+
* @returns Response with JSON error
|
|
131
|
+
*/
|
|
132
|
+
export declare function handleApiError(error: Error | HttpError, options: ErrorHandlerOptions): Response;
|
|
133
|
+
/**
|
|
134
|
+
* Creates a 404 Not Found response
|
|
135
|
+
*
|
|
136
|
+
* @param pathname - The requested path
|
|
137
|
+
* @param event - H3 event
|
|
138
|
+
* @param options - Error handler options
|
|
139
|
+
* @returns Response with 404 error page
|
|
140
|
+
*/
|
|
141
|
+
export declare function handleNotFound(pathname: string, event: H3Event, options: ErrorHandlerOptions): Promise<Response>;
|
|
142
|
+
/**
|
|
143
|
+
* Creates a 500 Internal Server Error response
|
|
144
|
+
*
|
|
145
|
+
* @param error - The original error
|
|
146
|
+
* @param event - H3 event
|
|
147
|
+
* @param options - Error handler options
|
|
148
|
+
* @returns Response with 500 error page
|
|
149
|
+
*/
|
|
150
|
+
export declare function handleInternalError(error: Error, event: H3Event, options: ErrorHandlerOptions): Promise<Response>;
|
|
151
|
+
export {};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Nitro Integration Module for Avalon
|
|
3
|
+
*
|
|
4
|
+
* This module provides the Nitro server runtime integration for Avalon,
|
|
5
|
+
* enabling universal deployment through Nitro presets while maintaining
|
|
6
|
+
* Avalon's multi-framework SSR and islands architecture.
|
|
7
|
+
*/
|
|
8
|
+
export { createNitroConfig, isValidPreset, mergeRouteRules, createDefaultStaticAssetRouteRules, DEFAULT_NITRO_CONFIG, DEFAULT_STATIC_ASSETS_CONFIG, type AvalonNitroConfig, type CacheOptions, type RouteRule, type NitroConfigOutput, type AvalonRuntimeConfig, type StaticAssetsConfig, } from "./config.ts";
|
|
9
|
+
export { type H3Event, type NitroRenderContext, type LayoutContext, type DiscoveredRoute, type NitroRouteConfig, type SSRRenderOptions, type SSRRenderResult, type AvalonEventContext, type IslandEntry, type IslandManifest, type PageModule, type PageMetadata, type ErrorResponse, HttpError, isHttpError, createNotFoundError, createMethodNotAllowedError, createInternalError, type DevServerOptions, type BuildOptions, } from "./types.ts";
|
|
10
|
+
export { createNitroRenderer, createNitroCatchAllRenderer, createRenderContext, renderPage, renderPageStream, createStreamingResponse, injectHydrationScript, validateHydrationMarkers, extractIslandMarkers, ensureHydrationMarkers, processHydrationRequirements, createErrorResponse, getRequestURL as getRendererRequestURL, toRequest as rendererToRequest, setResponseHeader, type RenderHandlerOptions, type ResolvedPageRoute, type StreamingSSROptions, type IslandMarker, type NitroCatchAllOptions, } from "./renderer.ts";
|
|
11
|
+
export { createMiddlewareContext, storeMiddlewareContext, getMiddlewareContext, getOrCreateMiddlewareContext, setMiddlewareState, getMiddlewareState, setMiddlewareLocal, getMiddlewareLocal, hasAvalonContext, ensureAvalonContext, getRequestURL as getMiddlewareRequestURL, getRequestHeaders as getMiddlewareRequestHeaders, toRequest as middlewareToRequest, getRouterParams as getMiddlewareRouterParams, type MiddlewareContextOptions, } from "./middleware-adapter.ts";
|
|
12
|
+
export { discoverPageRoutes, filePathToPattern, isPrivateFile, calculateRouteSpecificity, sortRoutesBySpecificity, validateRoutePattern, extractParamsFromPattern, matchRoutePattern, PAGE_EXTENSIONS, type PageDiscoveryOptions, type FilePathPatternResult, } from "./route-discovery.ts";
|
|
13
|
+
export { createClientBuildConfig, createServerBuildConfig, createCombinedBuildConfig, createNitroBuildPlugin, getPresetOutputConfig, presetSupportsStreaming, validateBuildConfig, createSourceMapConfig, createSourceMapPlugin, getViteSourceMapOption, DEFAULT_BUILD_CONFIG, DEFAULT_SOURCEMAP_CONFIG, PRESET_OUTPUT_CONFIGS, type BuildMode, type PresetOutputConfig, type AvalonBuildConfig, type SourceMapConfig, } from "./build-config.ts";
|
|
14
|
+
export { createIslandManifestPlugin, createIslandEntry, detectIslandFramework, generateContentHash, extractIslandDependencies, generatePreloadHints, generatePreloadTags, loadIslandManifest, getIslandAssetPath, getPageCssAssets, DEFAULT_MANIFEST_OPTIONS, type BuildIslandEntry, type BuildIslandManifest, type PreloadHint, type IslandManifestOptions, type AssetMetadata, } from "./island-manifest.ts";
|
|
15
|
+
export { discoverErrorPages, getErrorPageModule, renderErrorPage, generateDefaultErrorPage, createErrorPageProps, clearErrorPageCache, handleRenderError, handleApiError, handleNotFound, handleInternalError, type ErrorPageProps, type ErrorHandlerOptions, } from "./error-handler.ts";
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Island Manifest Generation Module for Nitro
|
|
3
|
+
*
|
|
4
|
+
* This module provides island manifest generation during production builds.
|
|
5
|
+
* The manifest contains information about all discovered islands, their
|
|
6
|
+
* compiled asset paths, and framework metadata for client-side hydration.
|
|
7
|
+
*
|
|
8
|
+
* ## Build Output
|
|
9
|
+
*
|
|
10
|
+
* During production build, this module generates:
|
|
11
|
+
* - `island-manifest.json` in the build output directory
|
|
12
|
+
* - Contains metadata for all islands (src, framework, css, preload)
|
|
13
|
+
* - Includes build timestamp and content hashes for cache busting
|
|
14
|
+
* - Generates preload hints for critical assets
|
|
15
|
+
*
|
|
16
|
+
* ## Nitro Integration
|
|
17
|
+
*
|
|
18
|
+
* The manifest is used by Nitro's renderer to:
|
|
19
|
+
* - Resolve compiled island paths for hydration scripts
|
|
20
|
+
* - Inject CSS assets for islands used on a page
|
|
21
|
+
* - Generate preload tags for critical resources
|
|
22
|
+
*
|
|
23
|
+
* ## Asset Metadata
|
|
24
|
+
*
|
|
25
|
+
* Each island entry includes:
|
|
26
|
+
* - `src`: Compiled JavaScript path (e.g., `/islands/Counter.abc123.js`)
|
|
27
|
+
* - `framework`: Detected framework (react, preact, vue, svelte, solid, lit)
|
|
28
|
+
* - `css`: Associated CSS files
|
|
29
|
+
* - `contentHash`: Hash for cache busting
|
|
30
|
+
* - `preloadDeps`: Dependencies to preload
|
|
31
|
+
*
|
|
32
|
+
* @module nitro/island-manifest
|
|
33
|
+
*/
|
|
34
|
+
import type { Plugin } from "vite";
|
|
35
|
+
import type { ResolvedAvalonConfig } from "../vite-plugin/types.ts";
|
|
36
|
+
import type { IslandManifest, IslandEntry } from "./types.ts";
|
|
37
|
+
/**
|
|
38
|
+
* Extended island entry with build-time metadata
|
|
39
|
+
*/
|
|
40
|
+
export interface BuildIslandEntry extends IslandEntry {
|
|
41
|
+
/** Original source file path */
|
|
42
|
+
sourcePath: string;
|
|
43
|
+
/** Compiled JavaScript chunk name */
|
|
44
|
+
chunkName: string;
|
|
45
|
+
/** Content hash for cache busting */
|
|
46
|
+
contentHash: string;
|
|
47
|
+
/** Dependencies that need to be preloaded */
|
|
48
|
+
preloadDeps: string[];
|
|
49
|
+
/** Whether the island uses streaming */
|
|
50
|
+
usesStreaming: boolean;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Asset metadata for Nitro's asset manifest format
|
|
54
|
+
* This matches Nitro's expected asset metadata structure
|
|
55
|
+
*/
|
|
56
|
+
export interface AssetMetadata {
|
|
57
|
+
/** MIME type of the asset */
|
|
58
|
+
type: string;
|
|
59
|
+
/** ETag for cache validation */
|
|
60
|
+
etag: string;
|
|
61
|
+
/** Last modification time (ISO string) */
|
|
62
|
+
mtime: string;
|
|
63
|
+
/** File size in bytes */
|
|
64
|
+
size: number;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Build-time island manifest with additional metadata
|
|
68
|
+
*/
|
|
69
|
+
export interface BuildIslandManifest extends IslandManifest {
|
|
70
|
+
/** Build timestamp */
|
|
71
|
+
buildTime: number;
|
|
72
|
+
/** Build version/hash */
|
|
73
|
+
buildHash: string;
|
|
74
|
+
/** Avalon version */
|
|
75
|
+
avalonVersion: string;
|
|
76
|
+
/** All CSS assets to inject */
|
|
77
|
+
cssAssets: string[];
|
|
78
|
+
/** Preload hints for critical assets */
|
|
79
|
+
preloadHints: PreloadHint[];
|
|
80
|
+
/** Framework-specific bundles */
|
|
81
|
+
frameworkBundles: Record<string, string>;
|
|
82
|
+
/** Asset metadata for cache headers (Nitro format) */
|
|
83
|
+
assetMetadata?: Record<string, AssetMetadata>;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Preload hint for resource optimization
|
|
87
|
+
*/
|
|
88
|
+
export interface PreloadHint {
|
|
89
|
+
/** Resource URL */
|
|
90
|
+
href: string;
|
|
91
|
+
/** Resource type (script, style, font, etc.) */
|
|
92
|
+
as: "script" | "style" | "font" | "image";
|
|
93
|
+
/** MIME type */
|
|
94
|
+
type?: string;
|
|
95
|
+
/** Cross-origin setting */
|
|
96
|
+
crossorigin?: "anonymous" | "use-credentials";
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Options for island manifest generation
|
|
100
|
+
*/
|
|
101
|
+
export interface IslandManifestOptions {
|
|
102
|
+
/** Output path for the manifest file */
|
|
103
|
+
outputPath?: string;
|
|
104
|
+
/** Include source maps in manifest */
|
|
105
|
+
includeSourceMaps?: boolean;
|
|
106
|
+
/** Generate preload hints */
|
|
107
|
+
generatePreloadHints?: boolean;
|
|
108
|
+
/** Verbose logging */
|
|
109
|
+
verbose?: boolean;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Default manifest generation options
|
|
113
|
+
*/
|
|
114
|
+
export declare const DEFAULT_MANIFEST_OPTIONS: Required<IslandManifestOptions>;
|
|
115
|
+
/**
|
|
116
|
+
* Detects the framework used by an island based on file content and extension
|
|
117
|
+
*
|
|
118
|
+
* @param filePath - Path to the island file
|
|
119
|
+
* @param content - File content
|
|
120
|
+
* @returns Detected framework name
|
|
121
|
+
*/
|
|
122
|
+
export declare function detectIslandFramework(filePath: string, content: string): string;
|
|
123
|
+
/**
|
|
124
|
+
* Generates a content hash for cache busting
|
|
125
|
+
*
|
|
126
|
+
* @param content - Content to hash
|
|
127
|
+
* @returns Short hash string
|
|
128
|
+
*/
|
|
129
|
+
export declare function generateContentHash(content: string): Promise<string>;
|
|
130
|
+
/**
|
|
131
|
+
* Extracts dependencies from island file content
|
|
132
|
+
*
|
|
133
|
+
* @param content - File content
|
|
134
|
+
* @returns Array of dependency names
|
|
135
|
+
*/
|
|
136
|
+
export declare function extractIslandDependencies(content: string): string[];
|
|
137
|
+
/**
|
|
138
|
+
* Creates an island entry from discovered island information
|
|
139
|
+
*
|
|
140
|
+
* @param name - Island name
|
|
141
|
+
* @param sourcePath - Source file path
|
|
142
|
+
* @param content - File content
|
|
143
|
+
* @param compiledPath - Compiled asset path
|
|
144
|
+
* @returns Island entry
|
|
145
|
+
*/
|
|
146
|
+
export declare function createIslandEntry(name: string, sourcePath: string, content: string, compiledPath: string): Promise<BuildIslandEntry>;
|
|
147
|
+
/**
|
|
148
|
+
* Generates preload hints for critical assets
|
|
149
|
+
*
|
|
150
|
+
* @param manifest - Island manifest
|
|
151
|
+
* @returns Array of preload hints
|
|
152
|
+
*/
|
|
153
|
+
export declare function generatePreloadHints(manifest: Partial<BuildIslandManifest>): PreloadHint[];
|
|
154
|
+
/**
|
|
155
|
+
* Creates a Vite plugin for island manifest generation
|
|
156
|
+
*
|
|
157
|
+
* @param avalonConfig - Resolved Avalon configuration
|
|
158
|
+
* @param options - Manifest generation options
|
|
159
|
+
* @returns Vite plugin
|
|
160
|
+
*/
|
|
161
|
+
export declare function createIslandManifestPlugin(avalonConfig: ResolvedAvalonConfig, options?: IslandManifestOptions): Plugin;
|
|
162
|
+
/**
|
|
163
|
+
* Loads an existing island manifest from disk
|
|
164
|
+
*
|
|
165
|
+
* @param manifestPath - Path to the manifest file
|
|
166
|
+
* @returns Loaded manifest or null if not found
|
|
167
|
+
*/
|
|
168
|
+
export declare function loadIslandManifest(manifestPath?: string): Promise<BuildIslandManifest | null>;
|
|
169
|
+
/**
|
|
170
|
+
* Gets the compiled asset path for an island
|
|
171
|
+
*
|
|
172
|
+
* @param islandName - Name of the island
|
|
173
|
+
* @param manifest - Island manifest
|
|
174
|
+
* @returns Compiled asset path or null if not found
|
|
175
|
+
*/
|
|
176
|
+
export declare function getIslandAssetPath(islandName: string, manifest: BuildIslandManifest | null): string | null;
|
|
177
|
+
/**
|
|
178
|
+
* Gets all CSS assets that should be injected for a page
|
|
179
|
+
*
|
|
180
|
+
* @param islandNames - Names of islands used on the page
|
|
181
|
+
* @param manifest - Island manifest
|
|
182
|
+
* @returns Array of CSS asset paths
|
|
183
|
+
*/
|
|
184
|
+
export declare function getPageCssAssets(islandNames: string[], manifest: BuildIslandManifest | null): string[];
|
|
185
|
+
/**
|
|
186
|
+
* Generates HTML preload tags for critical assets
|
|
187
|
+
*
|
|
188
|
+
* @param manifest - Island manifest
|
|
189
|
+
* @returns HTML string with preload tags
|
|
190
|
+
*/
|
|
191
|
+
export declare function generatePreloadTags(manifest: BuildIslandManifest): string;
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Nitro Middleware Adapter for Avalon
|
|
3
|
+
*
|
|
4
|
+
* This module provides utilities for creating and managing middleware context
|
|
5
|
+
* in Nitro's h3 middleware system. Nitro handles middleware ordering and execution
|
|
6
|
+
* automatically via the middleware/ directory with numbered prefixes.
|
|
7
|
+
*
|
|
8
|
+
* Key responsibilities:
|
|
9
|
+
* - Create MiddlewareContext from H3 events
|
|
10
|
+
* - Store/retrieve context in event.context.avalon for downstream handlers
|
|
11
|
+
* - Provide utilities for middleware to access request data
|
|
12
|
+
*
|
|
13
|
+
* Requirements: 6.1, 6.2, 6.3, 6.4
|
|
14
|
+
*/
|
|
15
|
+
import type { AvalonEventContext } from './types.ts';
|
|
16
|
+
import type { H3Event } from 'h3';
|
|
17
|
+
/**
|
|
18
|
+
* Context object passed through the middleware chain
|
|
19
|
+
*/
|
|
20
|
+
export interface MiddlewareContext {
|
|
21
|
+
request: Request;
|
|
22
|
+
url: URL;
|
|
23
|
+
params: Record<string, string>;
|
|
24
|
+
query: Record<string, string | string[]>;
|
|
25
|
+
state: Map<string, unknown>;
|
|
26
|
+
locals: Record<string, unknown>;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Options for middleware context creation
|
|
30
|
+
*/
|
|
31
|
+
export interface MiddlewareContextOptions {
|
|
32
|
+
/** Whether running in development mode */
|
|
33
|
+
isDev?: boolean;
|
|
34
|
+
/** Enable detailed logging */
|
|
35
|
+
enableLogging?: boolean;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Gets the request URL from an H3 event
|
|
39
|
+
* Requirements: 6.3
|
|
40
|
+
*/
|
|
41
|
+
export declare function getRequestURL(event: H3Event): URL;
|
|
42
|
+
/**
|
|
43
|
+
* Gets request headers from an H3 event
|
|
44
|
+
*/
|
|
45
|
+
export declare function getRequestHeaders(event: H3Event): Headers;
|
|
46
|
+
/**
|
|
47
|
+
* Converts an H3 event to a standard Request object
|
|
48
|
+
* Requirements: 6.3
|
|
49
|
+
*/
|
|
50
|
+
export declare function toRequest(event: H3Event): Request;
|
|
51
|
+
/**
|
|
52
|
+
* Extracts route parameters from an H3 event
|
|
53
|
+
* Uses Nitro's built-in parameter extraction via event.context.params
|
|
54
|
+
* Requirements: 6.3
|
|
55
|
+
*/
|
|
56
|
+
export declare function getRouterParams(event: H3Event): Record<string, string>;
|
|
57
|
+
/**
|
|
58
|
+
* Creates a MiddlewareContext from an H3 event
|
|
59
|
+
* Requirements: 6.3, 6.4
|
|
60
|
+
*
|
|
61
|
+
* This context is used by downstream handlers to access request data
|
|
62
|
+
* and any state set by middleware.
|
|
63
|
+
*
|
|
64
|
+
* @param event - The H3 event
|
|
65
|
+
* @param options - Optional configuration
|
|
66
|
+
* @returns MiddlewareContext for use in handlers
|
|
67
|
+
*/
|
|
68
|
+
export declare function createMiddlewareContext(event: H3Event, options?: MiddlewareContextOptions): MiddlewareContext;
|
|
69
|
+
/**
|
|
70
|
+
* Stores the middleware context in the H3 event for downstream handlers
|
|
71
|
+
* Requirements: 6.3, 6.4
|
|
72
|
+
*
|
|
73
|
+
* This allows API handlers and page renderers to access the middleware context
|
|
74
|
+
* that was created during middleware execution.
|
|
75
|
+
*
|
|
76
|
+
* @param event - The H3 event
|
|
77
|
+
* @param context - The middleware context to store
|
|
78
|
+
*/
|
|
79
|
+
export declare function storeMiddlewareContext(event: H3Event, context: MiddlewareContext): void;
|
|
80
|
+
/**
|
|
81
|
+
* Retrieves the middleware context from an H3 event
|
|
82
|
+
* Requirements: 6.3, 6.4
|
|
83
|
+
*
|
|
84
|
+
* @param event - The H3 event
|
|
85
|
+
* @returns The stored middleware context or undefined
|
|
86
|
+
*/
|
|
87
|
+
export declare function getMiddlewareContext(event: H3Event): MiddlewareContext | undefined;
|
|
88
|
+
/**
|
|
89
|
+
* Gets or creates a middleware context for an H3 event
|
|
90
|
+
* Requirements: 6.3, 6.4
|
|
91
|
+
*
|
|
92
|
+
* This is a convenience function that retrieves an existing context
|
|
93
|
+
* or creates a new one if none exists.
|
|
94
|
+
*
|
|
95
|
+
* @param event - The H3 event
|
|
96
|
+
* @param options - Optional configuration for context creation
|
|
97
|
+
* @returns The middleware context
|
|
98
|
+
*/
|
|
99
|
+
export declare function getOrCreateMiddlewareContext(event: H3Event, options?: MiddlewareContextOptions): MiddlewareContext;
|
|
100
|
+
/**
|
|
101
|
+
* Updates the middleware context state
|
|
102
|
+
* Requirements: 6.3, 6.4
|
|
103
|
+
*
|
|
104
|
+
* Allows middleware to set state that can be accessed by downstream handlers.
|
|
105
|
+
*
|
|
106
|
+
* @param event - The H3 event
|
|
107
|
+
* @param key - The state key
|
|
108
|
+
* @param value - The state value
|
|
109
|
+
*/
|
|
110
|
+
export declare function setMiddlewareState(event: H3Event, key: string, value: unknown): void;
|
|
111
|
+
/**
|
|
112
|
+
* Gets a value from the middleware context state
|
|
113
|
+
* Requirements: 6.3, 6.4
|
|
114
|
+
*
|
|
115
|
+
* @param event - The H3 event
|
|
116
|
+
* @param key - The state key
|
|
117
|
+
* @returns The state value or undefined
|
|
118
|
+
*/
|
|
119
|
+
export declare function getMiddlewareState<T = unknown>(event: H3Event, key: string): T | undefined;
|
|
120
|
+
/**
|
|
121
|
+
* Sets a local value in the middleware context
|
|
122
|
+
* Requirements: 6.3, 6.4
|
|
123
|
+
*
|
|
124
|
+
* Locals are similar to state but use a plain object for simpler access.
|
|
125
|
+
*
|
|
126
|
+
* @param event - The H3 event
|
|
127
|
+
* @param key - The local key
|
|
128
|
+
* @param value - The local value
|
|
129
|
+
*/
|
|
130
|
+
export declare function setMiddlewareLocal(event: H3Event, key: string, value: unknown): void;
|
|
131
|
+
/**
|
|
132
|
+
* Gets a local value from the middleware context
|
|
133
|
+
* Requirements: 6.3, 6.4
|
|
134
|
+
*
|
|
135
|
+
* @param event - The H3 event
|
|
136
|
+
* @param key - The local key
|
|
137
|
+
* @returns The local value or undefined
|
|
138
|
+
*/
|
|
139
|
+
export declare function getMiddlewareLocal<T = unknown>(event: H3Event, key: string): T | undefined;
|
|
140
|
+
/**
|
|
141
|
+
* Type guard to check if avalon context exists on an event
|
|
142
|
+
*/
|
|
143
|
+
export declare function hasAvalonContext(event: H3Event): boolean;
|
|
144
|
+
/**
|
|
145
|
+
* Ensures the avalon context is initialized on an event
|
|
146
|
+
* Requirements: 6.3
|
|
147
|
+
*
|
|
148
|
+
* @param event - The H3 event
|
|
149
|
+
* @returns The avalon context
|
|
150
|
+
*/
|
|
151
|
+
export declare function ensureAvalonContext(event: H3Event): AvalonEventContext;
|