@flight-framework/core 0.3.0 → 0.3.2

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/index.js CHANGED
@@ -1,36 +1,36 @@
1
+ export { streamWithPriority, validateDependencies } from './chunk-NZS2YJ43.js';
1
2
  export { MetricsAggregator, createHttpObserver, createInstrumentedStream, createLoggerObserver } from './chunk-YNTMYL36.js';
2
- export { DEFAULT_BOT_PATTERNS, addStreamingHeaders, createConditionalStreamer, createStreamingResponse as createConditionalStreamingResponse, createStaticResponse, isBot, isSlowConnection, prefersNoStream, streamIf, supportsStreaming } from './chunk-VNO2YUVD.js';
3
3
  export { createHTMXStreamAdapter, createReactStreamAdapter, createSolidStreamAdapter, createStreamAdapter, createSvelteStreamAdapter, createVueStreamAdapter } from './chunk-GNS2FGPC.js';
4
- export { createIslandRegistry, createPreactIslandAdapter, createReactIslandAdapter, createSolidIslandAdapter, createVueIslandAdapter, defineIsland, hydrateIslands, registerFlightIslandElement, registerIsland, renderIsland, renderIslands, setIslandAdapter } from './chunk-UFWGOJL7.js';
5
4
  export { DEFAULT_STREAMING_HINTS, createStreamingController, generateCacheKey, getStreamingCacheHeaders, hasStreamingConfig, isValidStreamingHints, loadRouteWithStreaming, resolveStreamingConfig, shouldStream } from './chunk-PO7IHPFF.js';
6
- export { streamWithPriority, validateDependencies } from './chunk-NZS2YJ43.js';
7
- import './chunk-QK6UEQ75.js';
8
- export { createServer } from './chunk-UL4Q5CIJ.js';
9
- export { defineConfig } from './chunk-EHVUAFNH.js';
10
- export { createFileRouter, loadRoutes, scanRoutes } from './chunk-UGTETAJ2.js';
11
- export { RedirectError, redirect as actionRedirect, cookies, executeAction, executeFormAction, getAction, handleActionRequest, isRedirectError, parseFormData, registerAction } from './chunk-OZ3EXPLE.js';
12
- export { createRouteContext, error, json, parseBody, redirect } from './chunk-A4TKWQBU.js';
13
- export { createLazyContent, createStreamingResponse, createStreamingSSR, renderWithStreaming, streamParallel, streamSequential } from './chunk-CNY3ZUVG.js';
14
5
  import './chunk-63SCEXD7.js';
6
+ import './chunk-Y22AMGTM.js';
7
+ import './chunk-HNPO6LFW.js';
8
+ import './chunk-3UQJE3XZ.js';
9
+ import './chunk-3N5ZBVZJ.js';
10
+ import './chunk-65JYF3DJ.js';
15
11
  export { createServerContext, isNotFoundError, isRedirectError as isRscRedirectError, notFound, redirect as rscRedirect } from './chunk-CKJHJPKQ.js';
16
12
  import './chunk-A2QRUBVE.js';
17
13
  import './chunk-FRAH5QNY.js';
18
14
  import './chunk-6GI6HFSQ.js';
19
- export { composeComponents, createAsyncComponent, createClientBoundary, createRenderContext, deserializeProps, executeServerComponent, revalidatePath as rscRevalidatePath, revalidateTag as rscRevalidateTag, serializeProps, serverFetch, withErrorBoundary } from './chunk-2R23X5Z3.js';
15
+ export { composeComponents, createAsyncComponent, createClientBoundary, createRenderContext, deserializeProps, executeServerComponent, revalidatePath as rscRevalidatePath, revalidateTag as rscRevalidateTag, serializeProps, serverFetch, withErrorBoundary } from './chunk-6IG6XIXU.js';
20
16
  import './chunk-XU6MRYG2.js';
21
17
  export { detectBoundaryType, hasUseClientDirective, hasUseServerDirective } from './chunk-5XHOLZBJ.js';
22
- import './chunk-Y22AMGTM.js';
23
- import './chunk-HNPO6LFW.js';
24
- import './chunk-3UQJE3XZ.js';
25
- import './chunk-3N5ZBVZJ.js';
26
- import './chunk-65JYF3DJ.js';
18
+ import './chunk-QK6UEQ75.js';
19
+ export { createServer } from './chunk-KDEA64UX.js';
20
+ export { createFileRouter, loadRoutes, scanRoutes } from './chunk-4U7CJVNQ.js';
21
+ export { RedirectError, redirect as actionRedirect, cookies, executeAction, executeFormAction, getAction, handleActionRequest, isRedirectError, parseFormData, registerAction } from './chunk-OZ3EXPLE.js';
22
+ export { createRouteContext, error, json, parseBody, redirect } from './chunk-A4TKWQBU.js';
23
+ export { createLazyContent, createStreamingResponse, createStreamingSSR, renderWithStreaming, streamParallel, streamSequential } from './chunk-CNY3ZUVG.js';
24
+ export { DEFAULT_BOT_PATTERNS, addStreamingHeaders, createConditionalStreamer, createStreamingResponse as createConditionalStreamingResponse, createStaticResponse, isBot, isSlowConnection, prefersNoStream, streamIf, supportsStreaming } from './chunk-VNO2YUVD.js';
25
+ export { createIslandRegistry, createPreactIslandAdapter, createReactIslandAdapter, createSolidIslandAdapter, createVueIslandAdapter, defineIsland, hydrateIslands, registerFlightIslandElement, registerIsland, renderIsland, renderIslands, setIslandAdapter } from './chunk-UFWGOJL7.js';
26
+ export { createMiddlewareChain } from './chunk-R7MEVVA4.js';
27
+ export { defineConfig } from './chunk-EHVUAFNH.js';
27
28
  export { BadRequestError, FlightError, ForbiddenError, InternalError, NotFoundError, UnauthorizedError, clearError, createError, createErrorResponse, forbidden as createForbidden, notFound as createNotFound, unauthorized as createUnauthorized, getError, getErrorStatusCode, isFlightError, isForbiddenError as isForbidden, isNotFoundError as isNotFound, isUnauthorizedError as isUnauthorized, showError, wrapWithDigest } from './chunk-2JVEH76V.js';
28
29
  import './chunk-PL37KFRJ.js';
29
30
  export { getEnvironment, isBrowser, isDevelopment, isProduction, isServer, isTest } from './chunk-OZBPR27I.js';
30
31
  export { createRouter } from './chunk-ARBKF6VI.js';
31
32
  import './chunk-B2LPSCES.js';
32
33
  export { cacheKey, cached, createCache, dedupe, jsonSerializer, memory } from './chunk-LKOPJ3GS.js';
33
- export { createMiddlewareChain } from './chunk-JFUKVWSO.js';
34
34
  import { promises } from 'fs';
35
35
  import { dirname, join } from 'path';
36
36
 
@@ -2,9 +2,41 @@
2
2
  * Flight Middleware - Composable request/response handlers
3
3
  *
4
4
  * Framework-agnostic middleware system inspired by Koa/Hono.
5
+ * Provides primitives for building your own middleware solutions.
6
+ *
7
+ * @example
8
+ * ```typescript
9
+ * // Type-safe middleware with custom variables (Hono pattern)
10
+ * interface MyLocals {
11
+ * user: { id: string; role: string };
12
+ * requestId: string;
13
+ * }
14
+ *
15
+ * const authMiddleware: Middleware<MyLocals> = async (ctx, next) => {
16
+ * ctx.locals.user = { id: '123', role: 'admin' };
17
+ * await next();
18
+ * };
19
+ * ```
5
20
  */
6
- /** Request context passed through middleware chain */
7
- interface MiddlewareContext {
21
+ /**
22
+ * Request context passed through middleware chain.
23
+ *
24
+ * Supports generic type parameter for type-safe locals (like Hono Variables).
25
+ *
26
+ * @typeParam TLocals - Type of the locals object for type-safe middleware data sharing
27
+ *
28
+ * @example
29
+ * ```typescript
30
+ * interface AppLocals {
31
+ * user: User;
32
+ * db: DatabaseClient;
33
+ * }
34
+ *
35
+ * const ctx: MiddlewareContext<AppLocals> = createContextFromRequest(request);
36
+ * ctx.locals.user = currentUser; // Type-safe!
37
+ * ```
38
+ */
39
+ interface MiddlewareContext<TLocals extends Record<string, unknown> = Record<string, unknown>> {
8
40
  /** Request URL */
9
41
  url: URL;
10
42
  /** Request method */
@@ -17,8 +49,8 @@ interface MiddlewareContext {
17
49
  query: URLSearchParams;
18
50
  /** Parsed request body (if any) */
19
51
  body?: unknown;
20
- /** Local data shared between middleware */
21
- locals: Record<string, unknown>;
52
+ /** Local data shared between middleware - type-safe with generics */
53
+ locals: TLocals;
22
54
  /** Original request (platform-specific) */
23
55
  request?: Request;
24
56
  /** Response status code */
@@ -30,8 +62,12 @@ interface MiddlewareContext {
30
62
  }
31
63
  /** Next function to call the next middleware */
32
64
  type MiddlewareNext = () => Promise<void>;
33
- /** Middleware function signature */
34
- type Middleware = (ctx: MiddlewareContext, next: MiddlewareNext) => Promise<void> | void;
65
+ /**
66
+ * Middleware function signature with optional typed locals.
67
+ *
68
+ * @typeParam TLocals - Type of the locals object for type-safe data sharing
69
+ */
70
+ type Middleware<TLocals extends Record<string, unknown> = Record<string, unknown>> = (ctx: MiddlewareContext<TLocals>, next: MiddlewareNext) => Promise<void> | void;
35
71
  /** Middleware with optional path matching */
36
72
  interface MiddlewareDefinition {
37
73
  /** Path pattern to match (undefined = match all) */
@@ -58,13 +94,52 @@ declare function createMiddlewareChain(): MiddlewareChain;
58
94
  /**
59
95
  * CORS middleware factory
60
96
  */
61
- declare function cors(options?: {
62
- origin?: string | string[] | ((origin: string) => boolean);
97
+ /**
98
+ * CORS options for configuring cross-origin requests.
99
+ */
100
+ interface CorsOptions {
101
+ /**
102
+ * Allowed origins. Can be:
103
+ * - '*' for any origin
104
+ * - A specific origin string
105
+ * - An array of allowed origins
106
+ * - A function that returns true if origin is allowed
107
+ * - An async function for dynamic origin validation
108
+ */
109
+ origin?: string | string[] | ((origin: string) => boolean | Promise<boolean>);
110
+ /** Allowed HTTP methods */
63
111
  methods?: string[];
112
+ /** Allowed headers */
64
113
  headers?: string[];
114
+ /** Whether to include credentials */
65
115
  credentials?: boolean;
116
+ /** Preflight cache duration in seconds */
66
117
  maxAge?: number;
67
- }): Middleware;
118
+ /** Exposed headers that can be accessed from the response */
119
+ exposeHeaders?: string[];
120
+ }
121
+ /**
122
+ * CORS middleware factory.
123
+ *
124
+ * Handles cross-origin resource sharing with best practices:
125
+ * - Adds Vary: Origin for dynamic origins (CDN compatibility)
126
+ * - Supports async origin validation
127
+ * - Proper preflight handling
128
+ *
129
+ * @example
130
+ * ```typescript
131
+ * // Allow specific origins
132
+ * chain.use(cors({ origin: ['https://app.example.com'] }));
133
+ *
134
+ * // Dynamic validation
135
+ * chain.use(cors({
136
+ * origin: async (origin) => {
137
+ * return await db.allowedOrigins.exists(origin);
138
+ * }
139
+ * }));
140
+ * ```
141
+ */
142
+ declare function cors(options?: CorsOptions): Middleware;
68
143
  /** Log levels in order of verbosity */
69
144
  type LogLevel = 'debug' | 'info' | 'warn' | 'error' | 'silent';
70
145
  /** Log format types */
@@ -136,6 +211,84 @@ declare function securityHeaders(options?: {
136
211
  * Compression middleware (requires implementation in adapter)
137
212
  */
138
213
  declare function compress(): Middleware;
214
+ /**
215
+ * Error information passed to error handlers.
216
+ */
217
+ interface ErrorInfo {
218
+ /** The original error */
219
+ error: Error;
220
+ /** HTTP status code (derived from error or default 500) */
221
+ status: number;
222
+ /** Error code for categorization */
223
+ code?: string;
224
+ /** Request context */
225
+ ctx: MiddlewareContext;
226
+ /** Request timestamp */
227
+ timestamp: string;
228
+ }
229
+ /**
230
+ * Error handler options.
231
+ */
232
+ interface ErrorHandlerOptions {
233
+ /**
234
+ * Custom error handler function.
235
+ * Called when an error is caught. Can modify ctx to set response.
236
+ * If not provided, a default JSON response is sent.
237
+ */
238
+ onError?: (info: ErrorInfo) => void | Promise<void>;
239
+ /**
240
+ * Whether to expose error details in response.
241
+ * Set to false in production to hide internal error messages.
242
+ * @default false
243
+ */
244
+ expose?: boolean;
245
+ /**
246
+ * Default status code for errors without a status property.
247
+ * @default 500
248
+ */
249
+ defaultStatus?: number;
250
+ /**
251
+ * Emit error events for centralized logging (Koa pattern).
252
+ * Provide a function to receive error events.
253
+ */
254
+ emit?: (error: Error, ctx: MiddlewareContext) => void;
255
+ }
256
+ /**
257
+ * Error handler middleware factory.
258
+ *
259
+ * Provides centralized error handling following Koa best practices:
260
+ * - Catches all downstream errors
261
+ * - Sets appropriate status codes
262
+ * - Supports custom error handlers
263
+ * - Supports error event emission for logging
264
+ *
265
+ * Place this as one of the FIRST middleware in your chain.
266
+ *
267
+ * @example
268
+ * ```typescript
269
+ * // Basic usage - default JSON error response
270
+ * chain.use(errorHandler());
271
+ *
272
+ * // With custom handler
273
+ * chain.use(errorHandler({
274
+ * onError: ({ error, status, ctx }) => {
275
+ * ctx.status = status;
276
+ * ctx.responseBody = JSON.stringify({
277
+ * error: error.message,
278
+ * code: 'SERVER_ERROR'
279
+ * });
280
+ * },
281
+ * emit: (error, ctx) => {
282
+ * logger.error('Request error:', error);
283
+ * errorTracker.capture(error);
284
+ * }
285
+ * }));
286
+ *
287
+ * // Production-safe (hide error details)
288
+ * chain.use(errorHandler({ expose: false }));
289
+ * ```
290
+ */
291
+ declare function errorHandler(options?: ErrorHandlerOptions): Middleware;
139
292
  /**
140
293
  * Create a middleware context from a Web Request
141
294
  */
@@ -149,4 +302,4 @@ declare function createResponseFromContext(ctx: MiddlewareContext): Response;
149
302
  */
150
303
  declare function compose(...middlewares: Middleware[]): Middleware;
151
304
 
152
- export { type LogEntry, type LogFormat, type LogLevel, type LogWriter, type LoggerOptions, type Middleware, type MiddlewareChain, type MiddlewareContext, type MiddlewareDefinition, type MiddlewareNext, compose, compress, cors, createContextFromRequest, createMiddlewareChain, createResponseFromContext, logger, securityHeaders };
305
+ export { type CorsOptions, type ErrorHandlerOptions, type ErrorInfo, type LogEntry, type LogFormat, type LogLevel, type LogWriter, type LoggerOptions, type Middleware, type MiddlewareChain, type MiddlewareContext, type MiddlewareDefinition, type MiddlewareNext, compose, compress, cors, createContextFromRequest, createMiddlewareChain, createResponseFromContext, errorHandler, logger, securityHeaders };
@@ -1,3 +1,3 @@
1
- export { compose, compress, cors, createContextFromRequest, createMiddlewareChain, createResponseFromContext, logger, securityHeaders } from '../chunk-JFUKVWSO.js';
1
+ export { compose, compress, cors, createContextFromRequest, createMiddlewareChain, createResponseFromContext, errorHandler, logger, securityHeaders } from '../chunk-R7MEVVA4.js';
2
2
  //# sourceMappingURL=index.js.map
3
3
  //# sourceMappingURL=index.js.map
@@ -7,21 +7,226 @@ export { FlightResponseOptions, FlightStreamError, FlightStreamOptions, FlightSt
7
7
  export { ComponentFn, ElementTypeInfo, FlightRenderer, RenderOptions, RenderResult, UIAdapter, createRenderer, renderServerComponent, renderServerComponentStreaming } from './renderer.js';
8
8
  export { ReactConsumerOptions, ReactServerComponent, createReactAdapter, createReactConsumer, markAsClientComponent } from './adapters/react.js';
9
9
  export { ClientManifestEntry, FlightRSCPluginOptions, ServerManifestEntry, default as flightRSC } from './vite-plugin.js';
10
- export { ComponentType, ClientComponent as LegacyClientComponent, ServerComponent as LegacyServerComponent, RenderContext, composeComponents, createAsyncComponent, createClientBoundary, createRenderContext, deserializeProps, executeServerComponent, isNotFoundError as legacyIsNotFoundError, isRedirectError as legacyIsRedirectError, notFound as legacyNotFound, redirect as legacyRedirect, revalidatePath, revalidateTag, serializeProps, serverFetch, withErrorBoundary } from './legacy.js';
10
+ export { AsyncErrorBoundaryOptions, ComponentType, ClientComponent as LegacyClientComponent, ServerComponent as LegacyServerComponent, RenderContext, composeComponents, createAsyncComponent, createClientBoundary, createRenderContext, deserializeProps, executeServerComponent, isNotFoundError as legacyIsNotFoundError, isRedirectError as legacyIsRedirectError, notFound as legacyNotFound, redirect as legacyRedirect, revalidatePath, revalidateTag, serializeProps, serverFetch, withAsyncErrorBoundary, withErrorBoundary } from './legacy.js';
11
11
  import 'react';
12
12
  import 'vite';
13
13
 
14
+ /**
15
+ * @flight-framework/core - RSC Type Helpers
16
+ *
17
+ * Type utilities for async server components, loaders, and actions.
18
+ * These types provide better TypeScript inference and developer experience.
19
+ *
20
+ * @module @flight-framework/core/rsc/types
21
+ */
22
+
23
+ /**
24
+ * Type for async server components with data fetching.
25
+ *
26
+ * @example
27
+ * ```typescript
28
+ * const UserPage: AsyncServerComponent<{ id: string }> = async ({ id }, ctx) => {
29
+ * const user = await db.users.get(id);
30
+ * return h('div', null, text(user.name));
31
+ * };
32
+ * ```
33
+ */
34
+ type AsyncServerComponent<Props = Record<string, unknown>, Result = FlightElement> = (props: Props, ctx: ServerContext) => Promise<Result>;
35
+ /**
36
+ * Type for sync server components.
37
+ */
38
+ type SyncServerComponent<Props = Record<string, unknown>, Result = FlightElement> = (props: Props, ctx: ServerContext) => Result;
39
+ /**
40
+ * Union type for any server component (sync or async).
41
+ */
42
+ type ServerComponent<Props = Record<string, unknown>, Result = FlightElement> = AsyncServerComponent<Props, Result> | SyncServerComponent<Props, Result>;
43
+ /**
44
+ * Context provided to loader functions.
45
+ */
46
+ interface LoaderContext {
47
+ /** Route parameters extracted from the URL path */
48
+ params: Record<string, string>;
49
+ /** The incoming request object */
50
+ request: Request;
51
+ /** URL search parameters */
52
+ searchParams: URLSearchParams;
53
+ }
54
+ /**
55
+ * Type for loader functions.
56
+ *
57
+ * @example
58
+ * ```typescript
59
+ * export const loader: LoaderFn = async ({ params }) => {
60
+ * const user = await db.users.get(params.id);
61
+ * return { user };
62
+ * };
63
+ * ```
64
+ */
65
+ type LoaderFn<T = unknown> = (context: LoaderContext) => Promise<T> | T;
66
+ /**
67
+ * Infer the return type of a loader function.
68
+ *
69
+ * @example
70
+ * ```typescript
71
+ * export async function loader() {
72
+ * return { count: 42, items: ['a', 'b'] };
73
+ * }
74
+ *
75
+ * // Type is { count: number; items: string[] }
76
+ * type Data = InferLoaderData<typeof loader>;
77
+ * ```
78
+ */
79
+ type InferLoaderData<T extends (...args: never[]) => unknown> = Awaited<ReturnType<T>>;
80
+ /**
81
+ * Context provided to action functions.
82
+ */
83
+ interface ActionContext {
84
+ /** The incoming request object */
85
+ request: Request;
86
+ /** Route parameters extracted from the URL path */
87
+ params: Record<string, string>;
88
+ }
89
+ /**
90
+ * Type for action functions.
91
+ *
92
+ * @example
93
+ * ```typescript
94
+ * export const action: ActionFn = async ({ request }) => {
95
+ * const formData = await request.formData();
96
+ * await db.items.create({ name: formData.get('name') });
97
+ * return { success: true };
98
+ * };
99
+ * ```
100
+ */
101
+ type ActionFn<T = unknown> = (context: ActionContext) => Promise<T> | T;
102
+ /**
103
+ * Infer the return type of an action function.
104
+ *
105
+ * @example
106
+ * ```typescript
107
+ * export async function action() {
108
+ * return { success: true, id: '123' };
109
+ * }
110
+ *
111
+ * // Type is { success: boolean; id: string }
112
+ * type Result = InferActionReturn<typeof action>;
113
+ * ```
114
+ */
115
+ type InferActionReturn<T extends (...args: never[]) => unknown> = Awaited<ReturnType<T>>;
116
+ /**
117
+ * Extract props type from a component function.
118
+ *
119
+ * @example
120
+ * ```typescript
121
+ * async function UserCard(props: { name: string; age: number }) {
122
+ * return <div>{props.name}</div>;
123
+ * }
124
+ *
125
+ * // Type is { name: string; age: number }
126
+ * type Props = ComponentProps<typeof UserCard>;
127
+ * ```
128
+ */
129
+ type ComponentProps<T> = T extends (props: infer P, ...args: unknown[]) => unknown ? P : never;
130
+ /**
131
+ * Extract the return type of a component (after awaiting if async).
132
+ */
133
+ type ComponentReturn<T> = T extends (...args: unknown[]) => infer R ? Awaited<R> : never;
134
+ /**
135
+ * Props for page components with route parameters.
136
+ */
137
+ interface PageProps<Params extends Record<string, string> = Record<string, string>> {
138
+ /** Route parameters from dynamic segments */
139
+ params: Params;
140
+ /** URL search parameters */
141
+ searchParams?: Record<string, string | string[]>;
142
+ }
143
+ /**
144
+ * Type for page components.
145
+ *
146
+ * @example
147
+ * ```typescript
148
+ * const PostPage: PageComponent<{ slug: string }> = async ({ params }) => {
149
+ * const post = await getPost(params.slug);
150
+ * return <article>{post.title}</article>;
151
+ * };
152
+ * ```
153
+ */
154
+ type PageComponent<Params extends Record<string, string> = Record<string, string>> = AsyncServerComponent<PageProps<Params>>;
155
+ /**
156
+ * Props for layout components.
157
+ */
158
+ interface LayoutProps<Params extends Record<string, string> = Record<string, string>> {
159
+ /** Child components to render */
160
+ children: FlightElement;
161
+ /** Route parameters from dynamic segments */
162
+ params: Params;
163
+ }
164
+ /**
165
+ * Type for layout components.
166
+ */
167
+ type LayoutComponent<Params extends Record<string, string> = Record<string, string>> = ServerComponent<LayoutProps<Params>>;
168
+ /**
169
+ * Props for error boundary components.
170
+ */
171
+ interface ErrorProps {
172
+ /** The error that was thrown */
173
+ error: Error;
174
+ /** Function to reset the error boundary */
175
+ reset: () => void;
176
+ }
177
+ /**
178
+ * Type for error components.
179
+ */
180
+ type ErrorComponent = (props: ErrorProps) => FlightElement;
181
+ /**
182
+ * Type for loading components (shown during Suspense).
183
+ */
184
+ type LoadingComponent = () => FlightElement;
185
+ /**
186
+ * Generate metadata for a page.
187
+ */
188
+ type GenerateMetadata<Params extends Record<string, string> = Record<string, string>> = (props: PageProps<Params>) => Promise<Metadata> | Metadata;
189
+ /**
190
+ * Page metadata type.
191
+ */
192
+ interface Metadata {
193
+ title?: string | {
194
+ default: string;
195
+ template?: string;
196
+ };
197
+ description?: string;
198
+ keywords?: string[];
199
+ authors?: Array<{
200
+ name: string;
201
+ url?: string;
202
+ }>;
203
+ openGraph?: {
204
+ title?: string;
205
+ description?: string;
206
+ images?: string[];
207
+ url?: string;
208
+ type?: string;
209
+ };
210
+ twitter?: {
211
+ card?: 'summary' | 'summary_large_image' | 'player' | 'app';
212
+ title?: string;
213
+ description?: string;
214
+ images?: string[];
215
+ };
216
+ robots?: string | {
217
+ index?: boolean;
218
+ follow?: boolean;
219
+ };
220
+ }
221
+
14
222
  /**
15
223
  * Server Component function type
224
+ * @deprecated Use AsyncServerComponent or ServerComponent from './types.js'
16
225
  */
17
226
  type ServerComponentFn<P = unknown, R = FlightElement> = (props: P, ctx: ServerContext) => R | Promise<R>;
18
227
  /**
19
228
  * Server Action function type
20
229
  */
21
230
  type ServerActionFn<Args extends unknown[] = unknown[], R = unknown> = (...args: Args) => Promise<R>;
22
- /**
23
- * Props for a component
24
- */
25
- type ComponentProps<T> = T extends (props: infer P, ...args: unknown[]) => unknown ? P : never;
26
231
 
27
- export { type ComponentProps, FlightElement, type ServerActionFn, type ServerComponentFn, ServerContext };
232
+ export { type ActionContext, type ActionFn, type AsyncServerComponent, type ComponentProps, type ComponentReturn, type ErrorComponent, type ErrorProps, FlightElement, type GenerateMetadata, type InferActionReturn, type InferLoaderData, type LayoutComponent, type LayoutProps, type LoaderContext, type LoaderFn, type LoadingComponent, type Metadata, type PageComponent, type PageProps, type ServerActionFn, type ServerComponent, type ServerComponentFn, ServerContext, type SyncServerComponent };
package/dist/rsc/index.js CHANGED
@@ -1,15 +1,15 @@
1
1
  import '../chunk-63SCEXD7.js';
2
+ import '../chunk-Y22AMGTM.js';
3
+ export { createReactAdapter, createReactConsumer, markAsClientComponent } from '../chunk-HNPO6LFW.js';
4
+ import '../chunk-3UQJE3XZ.js';
5
+ import '../chunk-3N5ZBVZJ.js';
6
+ import '../chunk-65JYF3DJ.js';
2
7
  export { acceptsJson, createServerContext, deleteCookie, getHeader, getHeaders, getPreferredLanguage, getRedirectInfo, isAjaxRequest, isBotRequest, isMutationRequest, isNotFoundError, isRedirectError, notFound, redirect, setCacheControl, setCookie, supportsStreaming } from '../chunk-CKJHJPKQ.js';
3
8
  export { FlightStreamError, consumeFlightStream, createFlightResponse, createFlightStream, createFlightStreamFromArray, createHybridResponse, createStreamController, mergeFlightStreams, parseFlightStream, parseFlightStreamSync, prettyPrintChunks, transformFlightStream } from '../chunk-A2QRUBVE.js';
4
9
  export { FlightRenderer, createRenderer, renderServerComponent, renderServerComponentStreaming } from '../chunk-FRAH5QNY.js';
5
10
  export { FlightPayloadError, FlightSerializationError, clientRef, createActionChunk, createClientChunk, createErrorChunk, createHintChunk, createServerChunk, deserialize, fragment, generateChunkId, h, isFlightElement, resetChunkIdCounter, serialize, suspense, text, toFlightElement } from '../chunk-6GI6HFSQ.js';
6
- export { composeComponents, createAsyncComponent, createClientBoundary, createRenderContext, deserializeProps, executeServerComponent, isNotFoundError as legacyIsNotFoundError, isRedirectError as legacyIsRedirectError, notFound as legacyNotFound, redirect as legacyRedirect, revalidatePath, revalidateTag, serializeProps, serverFetch, withErrorBoundary } from '../chunk-2R23X5Z3.js';
11
+ export { composeComponents, createAsyncComponent, createClientBoundary, createRenderContext, deserializeProps, executeServerComponent, isNotFoundError as legacyIsNotFoundError, isRedirectError as legacyIsRedirectError, notFound as legacyNotFound, redirect as legacyRedirect, revalidatePath, revalidateTag, serializeProps, serverFetch, withAsyncErrorBoundary, withErrorBoundary } from '../chunk-6IG6XIXU.js';
7
12
  export { flightRSC } from '../chunk-XU6MRYG2.js';
8
13
  export { BoundaryRegistry, CLIENT_REFERENCE, SERVER_REFERENCE, analyzeModule, createClientReference, createServerReference, detectAsyncComponents, detectBoundaryType, detectInlineServerActions, getReferenceId, globalRegistry, hasUseClientDirective, hasUseServerDirective, isClientReference, isServerReference, registerClientComponent, registerServerAction } from '../chunk-5XHOLZBJ.js';
9
- import '../chunk-Y22AMGTM.js';
10
- export { createReactAdapter, createReactConsumer, markAsClientComponent } from '../chunk-HNPO6LFW.js';
11
- import '../chunk-3UQJE3XZ.js';
12
- import '../chunk-3N5ZBVZJ.js';
13
- import '../chunk-65JYF3DJ.js';
14
14
  //# sourceMappingURL=index.js.map
15
15
  //# sourceMappingURL=index.js.map
@@ -99,9 +99,33 @@ declare function createAsyncComponent<P, T>(fetcher: (props: P, context: RenderC
99
99
  * @deprecated Use Promise.all with async components
100
100
  */
101
101
  declare function composeComponents(...components: Array<() => Promise<string> | string>): () => Promise<string>;
102
+ /**
103
+ * Options for async error boundary
104
+ */
105
+ interface AsyncErrorBoundaryOptions<P, R> {
106
+ /** Fallback to render on error */
107
+ fallback: (error: Error, props: P) => R;
108
+ /** Optional callback when error occurs */
109
+ onError?: (error: Error, props: P, context: RenderContext) => void;
110
+ /** Whether to rethrow certain errors (e.g., redirects, not found) */
111
+ rethrowNavigation?: boolean;
112
+ }
113
+ /**
114
+ * Wrap an async server component with comprehensive error handling.
115
+ *
116
+ * @example
117
+ * ```typescript
118
+ * const SafeUserPage = withAsyncErrorBoundary(UserPage, {
119
+ * fallback: (error, props) => `<div>Error loading user ${props.id}</div>`,
120
+ * onError: (error, props) => console.error(`Failed to load user ${props.id}:`, error),
121
+ * rethrowNavigation: true,
122
+ * });
123
+ * ```
124
+ */
125
+ declare function withAsyncErrorBoundary<P, R = string>(component: (props: P, context: RenderContext) => Promise<R> | R, options: AsyncErrorBoundaryOptions<P, R>): (props: P, context: RenderContext) => Promise<R>;
102
126
  /**
103
127
  * Wrap a server component with error handling
104
- * @deprecated Use try/catch in async components
128
+ * @deprecated Use withAsyncErrorBoundary instead
105
129
  */
106
130
  declare function withErrorBoundary<P>(component: ServerComponent<P>, errorFallback: (error: Error) => string): ServerComponent<P>;
107
131
  /**
@@ -128,4 +152,4 @@ declare function isRedirectError(error: unknown): {
128
152
  type: string;
129
153
  } | null;
130
154
 
131
- export { type ClientComponent, type ComponentType, type RenderContext, type ServerComponent, composeComponents, createAsyncComponent, createClientBoundary, createRenderContext, deserializeProps, executeServerComponent, isNotFoundError, isRedirectError, notFound, redirect, revalidatePath, revalidateTag, serializeProps, serverFetch, withErrorBoundary };
155
+ export { type AsyncErrorBoundaryOptions, type ClientComponent, type ComponentType, type RenderContext, type ServerComponent, composeComponents, createAsyncComponent, createClientBoundary, createRenderContext, deserializeProps, executeServerComponent, isNotFoundError, isRedirectError, notFound, redirect, revalidatePath, revalidateTag, serializeProps, serverFetch, withAsyncErrorBoundary, withErrorBoundary };
@@ -1,3 +1,3 @@
1
- export { composeComponents, createAsyncComponent, createClientBoundary, createRenderContext, deserializeProps, executeServerComponent, isNotFoundError, isRedirectError, notFound, redirect, revalidatePath, revalidateTag, serializeProps, serverFetch, withErrorBoundary } from '../chunk-2R23X5Z3.js';
1
+ export { composeComponents, createAsyncComponent, createClientBoundary, createRenderContext, deserializeProps, executeServerComponent, isNotFoundError, isRedirectError, notFound, redirect, revalidatePath, revalidateTag, serializeProps, serverFetch, withAsyncErrorBoundary, withErrorBoundary } from '../chunk-6IG6XIXU.js';
2
2
  //# sourceMappingURL=legacy.js.map
3
3
  //# sourceMappingURL=legacy.js.map
@@ -1,6 +1,6 @@
1
- export { createServer, getRuntime, isFlightServer } from '../chunk-UL4Q5CIJ.js';
1
+ export { createServer, getRuntime, isFlightServer } from '../chunk-KDEA64UX.js';
2
+ import '../chunk-R7MEVVA4.js';
2
3
  import '../chunk-EHVUAFNH.js';
3
4
  import '../chunk-ARBKF6VI.js';
4
- import '../chunk-JFUKVWSO.js';
5
5
  //# sourceMappingURL=index.js.map
6
6
  //# sourceMappingURL=index.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flight-framework/core",
3
- "version": "0.3.0",
3
+ "version": "0.3.2",
4
4
  "description": "Core primitives for Flight Framework - routing, rendering, caching",
5
5
  "keywords": [
6
6
  "flight",
@@ -15,7 +15,13 @@
15
15
  "exports": {
16
16
  ".": {
17
17
  "types": "./dist/index.d.ts",
18
- "import": "./dist/index.js"
18
+ "node": "./dist/index.js",
19
+ "default": "./dist/client.js"
20
+ },
21
+ "./client": {
22
+ "types": "./dist/client.d.ts",
23
+ "browser": "./dist/client.js",
24
+ "import": "./dist/client.js"
19
25
  },
20
26
  "./errors": {
21
27
  "types": "./dist/errors/index.d.ts",
@@ -168,6 +174,14 @@
168
174
  "./rsc/plugins/rollup": {
169
175
  "types": "./dist/rsc/plugins/rollup.d.ts",
170
176
  "import": "./dist/rsc/plugins/rollup.js"
177
+ },
178
+ "./plugins": {
179
+ "types": "./dist/plugins/index.d.ts",
180
+ "import": "./dist/plugins/index.js"
181
+ },
182
+ "./plugins/critical-css": {
183
+ "types": "./dist/plugins/critical-css.d.ts",
184
+ "import": "./dist/plugins/critical-css.js"
171
185
  }
172
186
  },
173
187
  "main": "./dist/index.js",
@@ -188,7 +202,8 @@
188
202
  },
189
203
  "peerDependencies": {
190
204
  "react": "^18.0.0 || ^19.0.0",
191
- "vite": "^6.0.0 || ^7.0.0"
205
+ "vite": "^6.0.0 || ^7.0.0",
206
+ "critters": ">=0.0.20"
192
207
  },
193
208
  "peerDependenciesMeta": {
194
209
  "react": {
@@ -196,6 +211,9 @@
196
211
  },
197
212
  "vite": {
198
213
  "optional": true
214
+ },
215
+ "critters": {
216
+ "optional": true
199
217
  }
200
218
  },
201
219
  "scripts": {