@flight-framework/core 0.2.2 → 0.2.4

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.
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/server/index.ts"],"names":[],"mappings":";;;;;AAuIA,SAAS,aAAA,GAAyB;AAE9B,EAAA,IAAI,OAAO,GAAA,KAAQ,WAAA,EAAa,OAAO,KAAA;AAEvC,EAAA,IAAI,OAAO,IAAA,KAAS,WAAA,EAAa,OAAO,MAAA;AACxC,EAAA,IAAI,OAAO,OAAA,KAAY,WAAA,IAAe,OAAA,CAAQ,QAAA,EAAU,MAAM,OAAO,MAAA;AACrE,EAAA,OAAO,SAAA;AACX;AA6BO,SAAS,YAAA,CAAa,OAAA,GAAyB,EAAC,EAAiB;AACpE,EAAA,MAAM,MAAA,GAAS,aAAA,CAAc,OAAA,CAAQ,MAAA,IAAU,EAAE,CAAA;AACjD,EAAA,MAAM,SAAS,YAAA,EAAyB;AACxC,EAAA,MAAM,kBAAkB,qBAAA,EAAsB;AAG9C,EAAA,MAAM,IAAA,GAAO;AAAA,IACT,IAAI,OAAA,CAAQ,EAAA;AAAA,IACZ,MAAM,OAAA,CAAQ,IAAA;AAAA,IACd,OAAO,OAAA,CAAQ;AAAA,GACnB;AAEA,EAAA,SAAS,QAAA,CAAS,MAAA,EAA2B,IAAA,EAAc,OAAA,EAAqC;AAC5F,IAAA,MAAM,UAAU,KAAA,CAAM,OAAA,CAAQ,MAAM,CAAA,GAAI,MAAA,GAAS,CAAC,MAAM,CAAA;AACxD,IAAA,MAAM,SAAA,GAAY,IAAI,GAAA,CAAI,OAAA,CAAQ,IAAI,CAAA,CAAA,KAAK,CAAA,CAAE,WAAA,EAAa,CAAC,CAAA;AAG3D,IAAA,MAAM,aAAA,GAAgB,MAAA,CAAO,KAAA,CAAM,IAAI,CAAA;AACvC,IAAA,IAAI,aAAA,IAAiB,aAAA,CAAc,KAAA,CAAM,IAAA,KAAS,IAAA,E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,MAAA,GAAS;AAAE,MAAA,OAAO,MAAA;AAAA,IAA2C,CAAA;AAAA,IACjE,IAAI,UAAA,GAAa;AAAE,MAAA,OAAO,eAAA;AAAA,IAAiB;AAAA,GAC/C;AAEA,EAAA,OAAO,MAAA;AACX;AAOO,SAAS,eAAe,GAAA,EAAmC;AAC9D,EAAA,OACI,OAAO,GAAA,KAAQ,QAAA,IACf,GAAA,KAAQ,IAAA,IACR,QAAA,IAAY,GAAA,IACZ,OAAA,IAAW,GAAA,IACX,OAAQ,GAAA,CAAqB,MAAA,KAAW,UAAA;AAEhD;AAGO,SAAS,UAAA,GAAsB;AAClC,EAAA,OAAO,aAAA,EAAc;AACzB","file":"chunk-6LYV4VQX.js","sourcesContent":["/**\r\n * Flight Server - Main server factory\r\n * \r\n * Creates a Flight server instance that handles routing, middleware, and rendering.\r\n * This is the primary entry point for Flight applications.\r\n * \r\n * @example\r\n * ```typescript\r\n * import { createServer } from '@flight-framework/core';\r\n * \r\n * const server = createServer();\r\n * \r\n * server.get('/api/health', () => Response.json({ status: 'ok' }));\r\n * \r\n * // Just works! Auto-detects Node.js, Bun, or Deno\r\n * server.listen(3000);\r\n * ```\r\n */\r\n\r\nimport { createRouter, type Router } from '../router/index.js';\r\nimport {\r\n createMiddlewareChain,\r\n createContextFromRequest,\r\n createResponseFromContext,\r\n type MiddlewareChain,\r\n type Middleware,\r\n} from '../middleware/index.js';\r\nimport { type FlightConfig, type FlightUserConfig, resolveConfig } from '../config/index.js';\r\nimport type { FlightAdapter } from '../adapters/index.js';\r\n\r\n// ============================================================================\r\n// Types\r\n// ============================================================================\r\n\r\n/** Route handler function signature */\r\nexport type RouteHandler = (context: RouteHandlerContext) => Promise<Response> | Response;\r\n\r\n/** Context passed to route handlers */\r\nexport interface RouteHandlerContext {\r\n /** The incoming request */\r\n request: Request;\r\n /** URL parameters from routing */\r\n params: Record<string, string | string[]>;\r\n /** Query parameters */\r\n query: URLSearchParams;\r\n /** Parsed URL */\r\n url: URL;\r\n /** Local data from middleware */\r\n locals: Record<string, unknown>;\r\n /** Database instance (if configured) */\r\n db?: unknown;\r\n /** Auth instance (if configured) */\r\n auth?: unknown;\r\n /** Email instance (if configured) */\r\n email?: unknown;\r\n}\r\n\r\n/** Server options */\r\nexport interface ServerOptions {\r\n /** Server configuration */\r\n config?: FlightUserConfig;\r\n /** Deployment adapter */\r\n adapter?: FlightAdapter;\r\n /** Database instance */\r\n db?: unknown;\r\n /** Auth instance */\r\n auth?: unknown;\r\n /** Email instance */\r\n email?: unknown;\r\n}\r\n\r\n/** Route definition for the server */\r\nexport interface ServerRoute {\r\n /** HTTP method (GET, POST, etc.) */\r\n method: string | string[];\r\n /** Route path pattern */\r\n path: string;\r\n /** Route handler */\r\n handler: RouteHandler;\r\n}\r\n\r\n/** Listen options */\r\nexport interface ListenOptions {\r\n /** Port to listen on (default: 3000) */\r\n port?: number;\r\n /** Hostname to bind to (default: 'localhost') */\r\n hostname?: string;\r\n /** Callback when server starts */\r\n onListen?: (info: { port: number; hostname: string }) => void;\r\n}\r\n\r\n/** Flight Server instance */\r\nexport interface FlightServer {\r\n /** Add a route */\r\n route(method: string | string[], path: string, handler: RouteHandler): FlightServer;\r\n\r\n /** Convenience methods for common HTTP methods */\r\n get(path: string, handler: RouteHandler): FlightServer;\r\n post(path: string, handler: RouteHandler): FlightServer;\r\n put(path: string, handler: RouteHandler): FlightServer;\r\n delete(path: string, handler: RouteHandler): FlightServer;\r\n patch(path: string, handler: RouteHandler): FlightServer;\r\n\r\n /** Add middleware */\r\n use(middleware: Middleware): FlightServer;\r\n use(path: string, middleware: Middleware): FlightServer;\r\n\r\n /** Handle incoming request (Web standard Request/Response) */\r\n handle(request: Request): Promise<Response>;\r\n\r\n /** \r\n * Start the HTTP server\r\n * Auto-detects runtime: Node.js, Bun, or Deno\r\n */\r\n listen(port?: number | ListenOptions): Promise<void>;\r\n\r\n /** Fetch handler for Bun.serve() and Deno.serve() */\r\n fetch(request: Request): Promise<Response>;\r\n\r\n /** Get the resolved configuration */\r\n readonly config: FlightConfig;\r\n\r\n /** Get the router instance */\r\n readonly router: Router<RouteHandler>;\r\n\r\n /** Get the middleware chain */\r\n readonly middleware: MiddlewareChain;\r\n}\r\n\r\n// ============================================================================\r\n// Runtime Detection\r\n// ============================================================================\r\n\r\ntype Runtime = 'node' | 'bun' | 'deno' | 'unknown';\r\n\r\nfunction detectRuntime(): Runtime {\r\n // @ts-expect-error - Bun global\r\n if (typeof Bun !== 'undefined') return 'bun';\r\n // @ts-expect-error - Deno global \r\n if (typeof Deno !== 'undefined') return 'deno';\r\n if (typeof process !== 'undefined' && process.versions?.node) return 'node';\r\n return 'unknown';\r\n}\r\n\r\n// ============================================================================\r\n// Server Implementation\r\n// ============================================================================\r\n\r\ninterface RouteEntry {\r\n methods: Set<string>;\r\n handler: RouteHandler;\r\n}\r\n\r\n/**\r\n * Create a new Flight server instance\r\n * \r\n * @example\r\n * ```typescript\r\n * import { createServer } from '@flight-framework/core';\r\n * \r\n * const server = createServer();\r\n * \r\n * server.get('/api/users', async ({ db }) => {\r\n * const users = await db.query('SELECT * FROM users');\r\n * return Response.json(users);\r\n * });\r\n * \r\n * // Works on Node.js, Bun, and Deno!\r\n * server.listen(3000);\r\n * ```\r\n */\r\nexport function createServer(options: ServerOptions = {}): FlightServer {\r\n const config = resolveConfig(options.config ?? {});\r\n const router = createRouter<RouteEntry>();\r\n const middlewareChain = createMiddlewareChain();\r\n\r\n // Store dependencies\r\n const deps = {\r\n db: options.db,\r\n auth: options.auth,\r\n email: options.email,\r\n };\r\n\r\n function addRoute(method: string | string[], path: string, handler: RouteHandler): FlightServer {\r\n const methods = Array.isArray(method) ? method : [method];\r\n const methodSet = new Set(methods.map(m => m.toUpperCase()));\r\n\r\n // Check if route already exists\r\n const existingMatch = router.match(path);\r\n if (existingMatch && existingMatch.route.path === path) {\r\n // Merge methods\r\n for (const m of methodSet) {\r\n existingMatch.route.handler.methods.add(m);\r\n }\r\n existingMatch.route.handler.handler = handler;\r\n } else {\r\n router.add({\r\n path,\r\n handler: { methods: methodSet, handler },\r\n });\r\n }\r\n\r\n return server;\r\n }\r\n\r\n function useMiddleware(\r\n pathOrMiddleware: string | Middleware,\r\n maybeMiddleware?: Middleware\r\n ): FlightServer {\r\n if (typeof pathOrMiddleware === 'string' && maybeMiddleware) {\r\n middlewareChain.use(pathOrMiddleware, maybeMiddleware);\r\n } else if (typeof pathOrMiddleware === 'function') {\r\n middlewareChain.use(pathOrMiddleware);\r\n }\r\n return server;\r\n }\r\n\r\n async function handle(request: Request): Promise<Response> {\r\n const url = new URL(request.url);\r\n const method = request.method.toUpperCase();\r\n\r\n // Run middleware\r\n const ctx = createContextFromRequest(request);\r\n await middlewareChain.execute(ctx);\r\n\r\n // If middleware already set a response, return it\r\n if (ctx.responseBody !== undefined) {\r\n return createResponseFromContext(ctx);\r\n }\r\n\r\n // Match route\r\n const match = router.match(url.pathname);\r\n if (!match) {\r\n return new Response('Not Found', { status: 404 });\r\n }\r\n\r\n // Check method\r\n if (!match.route.handler.methods.has(method) && !match.route.handler.methods.has('*')) {\r\n return new Response('Method Not Allowed', { status: 405 });\r\n }\r\n\r\n // Build handler context\r\n const handlerContext: RouteHandlerContext = {\r\n request,\r\n params: match.params,\r\n query: url.searchParams,\r\n url,\r\n locals: ctx.locals,\r\n ...deps,\r\n };\r\n\r\n try {\r\n return await match.route.handler.handler(handlerContext);\r\n } catch (error) {\r\n console.error('Route handler error:', error);\r\n return new Response('Internal Server Error', { status: 500 });\r\n }\r\n }\r\n\r\n /**\r\n * Start the HTTP server\r\n * Auto-detects the runtime and uses the appropriate server\r\n */\r\n async function listen(portOrOptions?: number | ListenOptions): Promise<void> {\r\n const opts: ListenOptions = typeof portOrOptions === 'number'\r\n ? { port: portOrOptions }\r\n : portOrOptions ?? {};\r\n\r\n const port = opts.port ?? config.dev.port ?? 3000;\r\n const hostname = opts.hostname ?? 'localhost';\r\n\r\n // Check for custom adapter first\r\n const adapter = options.adapter ?? config.adapter;\r\n if (adapter?.listen) {\r\n await adapter.listen(server, port);\r\n return;\r\n }\r\n\r\n const runtime = detectRuntime();\r\n\r\n switch (runtime) {\r\n case 'bun':\r\n await startBunServer(port, hostname, opts.onListen);\r\n break;\r\n case 'deno':\r\n await startDenoServer(port, hostname, opts.onListen);\r\n break;\r\n case 'node':\r\n default:\r\n await startNodeServer(port, hostname, opts.onListen);\r\n break;\r\n }\r\n }\r\n\r\n /**\r\n * Start Node.js HTTP server\r\n */\r\n async function startNodeServer(port: number, hostname: string, onListen?: ListenOptions['onListen']): Promise<void> {\r\n const { createServer: createHttpServer } = await import('node:http');\r\n\r\n const httpServer = createHttpServer(async (req, res) => {\r\n const url = new URL(req.url || '/', `http://${hostname}:${port}`);\r\n\r\n // Build headers\r\n const headers = new Headers();\r\n for (const [key, value] of Object.entries(req.headers)) {\r\n if (value) {\r\n const headerValue = Array.isArray(value) ? value[0] : value;\r\n if (headerValue) headers.set(key, headerValue);\r\n }\r\n }\r\n\r\n // Read body for POST/PUT/PATCH\r\n let body: string | undefined;\r\n if (['POST', 'PUT', 'PATCH'].includes(req.method || '')) {\r\n body = await new Promise<string>((resolve) => {\r\n let data = '';\r\n req.on('data', chunk => data += chunk);\r\n req.on('end', () => resolve(data));\r\n });\r\n }\r\n\r\n const request = new Request(url.toString(), {\r\n method: req.method,\r\n headers,\r\n body: body || undefined,\r\n });\r\n\r\n try {\r\n const response = await handle(request);\r\n\r\n res.statusCode = response.status;\r\n response.headers.forEach((value, key) => {\r\n res.setHeader(key, value);\r\n });\r\n\r\n const responseBody = await response.text();\r\n res.end(responseBody);\r\n } catch (error) {\r\n console.error('Server error:', error);\r\n res.statusCode = 500;\r\n res.setHeader('Content-Type', 'application/json');\r\n res.end(JSON.stringify({ error: 'Internal Server Error' }));\r\n }\r\n });\r\n\r\n return new Promise((resolve) => {\r\n httpServer.listen(port, hostname, () => {\r\n const info = { port, hostname };\r\n if (onListen) {\r\n onListen(info);\r\n } else {\r\n console.log(`\r\n╔═══════════════════════════════════════════════════════════╗\r\n║ Flight Server (Node.js) ║\r\n╠═══════════════════════════════════════════════════════════╣\r\n║ Server: http://${hostname}:${port.toString().padEnd(37)}║\r\n╚═══════════════════════════════════════════════════════════╝\r\n`);\r\n }\r\n resolve();\r\n });\r\n });\r\n }\r\n\r\n /**\r\n * Start Bun server\r\n */\r\n async function startBunServer(port: number, hostname: string, onListen?: ListenOptions['onListen']): Promise<void> {\r\n // @ts-expect-error - Bun types\r\n Bun.serve({\r\n port,\r\n hostname,\r\n fetch: handle,\r\n });\r\n\r\n const info = { port, hostname };\r\n if (onListen) {\r\n onListen(info);\r\n } else {\r\n console.log(`\r\n╔═══════════════════════════════════════════════════════════╗\r\n║ Flight Server (Bun) ║\r\n╠═══════════════════════════════════════════════════════════╣\r\n║ Server: http://${hostname}:${port.toString().padEnd(37)}║\r\n╚═══════════════════════════════════════════════════════════╝\r\n`);\r\n }\r\n }\r\n\r\n /**\r\n * Start Deno server\r\n */\r\n async function startDenoServer(port: number, hostname: string, onListen?: ListenOptions['onListen']): Promise<void> {\r\n // @ts-expect-error - Deno types\r\n Deno.serve({ port, hostname }, handle);\r\n\r\n const info = { port, hostname };\r\n if (onListen) {\r\n onListen(info);\r\n } else {\r\n console.log(`\r\n╔═══════════════════════════════════════════════════════════╗\r\n║ Flight Server (Deno) ║\r\n╠═══════════════════════════════════════════════════════════╣\r\n║ Server: http://${hostname}:${port.toString().padEnd(37)}║\r\n╚═══════════════════════════════════════════════════════════╝\r\n`);\r\n }\r\n }\r\n\r\n const server: FlightServer = {\r\n route: addRoute,\r\n get: (path, handler) => addRoute('GET', path, handler),\r\n post: (path, handler) => addRoute('POST', path, handler),\r\n put: (path, handler) => addRoute('PUT', path, handler),\r\n delete: (path, handler) => addRoute('DELETE', path, handler),\r\n patch: (path, handler) => addRoute('PATCH', path, handler),\r\n use: useMiddleware as FlightServer['use'],\r\n handle,\r\n listen,\r\n fetch: handle, // Alias for Bun/Deno compatibility\r\n get config() { return config; },\r\n get router() { return router as unknown as Router<RouteHandler>; },\r\n get middleware() { return middlewareChain; },\r\n };\r\n\r\n return server;\r\n}\r\n\r\n// ============================================================================\r\n// Helper Exports\r\n// ============================================================================\r\n\r\n/** Type guard to check if an object is a FlightServer */\r\nexport function isFlightServer(obj: unknown): obj is FlightServer {\r\n return (\r\n typeof obj === 'object' &&\r\n obj !== null &&\r\n 'handle' in obj &&\r\n 'route' in obj &&\r\n typeof (obj as FlightServer).handle === 'function'\r\n );\r\n}\r\n\r\n/** Get current runtime */\r\nexport function getRuntime(): Runtime {\r\n return detectRuntime();\r\n}\r\n\r\n"]}
1
+ {"version":3,"sources":["../src/server/index.ts"],"names":[],"mappings":";;;;;AAuIA,SAAS,aAAA,GAAyB;AAE9B,EAAA,IAAI,OAAO,GAAA,KAAQ,WAAA,EAAa,OAAO,KAAA;AAEvC,EAAA,IAAI,OAAO,IAAA,KAAS,WAAA,EAAa,OAAO,MAAA;AACxC,EAAA,IAAI,OAAO,OAAA,KAAY,WAAA,IAAe,OAAA,CAAQ,QAAA,EAAU,MAAM,OAAO,MAAA;AACrE,EAAA,OAAO,SAAA;AACX;AA6BO,SAAS,YAAA,CAAa,OAAA,GAAyB,EAAC,EAAiB;AACpE,EAAA,MAAM,MAAA,GAAS,aAAA,CAAc,OAAA,CAAQ,MAAA,IAAU,EAAE,CAAA;AACjD,EAAA,MAAM,SAAS,YAAA,EAAyB;AACxC,EAAA,MAAM,kBAAkB,qBAAA,EAAsB;AAG9C,EAAA,MAAM,IAAA,GAAO;AAAA,IACT,IAAI,OAAA,CAAQ,EAAA;AAAA,IACZ,MAAM,OAAA,CAAQ,IAAA;AAAA,IACd,OAAO,OAAA,CAAQ;AAAA,GACnB;AAEA,EAAA,SAAS,QAAA,CAAS,MAAA,EAA2B,IAAA,EAAc,OAAA,EAAqC;AAC5F,IAAA,MAAM,UAAU,KAAA,CAAM,OAAA,CAAQ,MAAM,CAAA,GAAI,MAAA,GAAS,CAAC,MAAM,CAAA;AACxD,IAAA,MA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,IAAA,EAAM,YAAY,QAAA,CAAS,OAAA,EAAS,MAAM,OAAO,CAAA;AAAA,IACzD,GAAA,EAAK,aAAA;AAAA,IACL,MAAA;AAAA,IACA,MAAA;AAAA,IACA,KAAA,EAAO,MAAA;AAAA;AAAA,IACP,IAAI,MAAA,GAAS;AAAE,MAAA,OAAO,MAAA;AAAA,IAAQ,CAAA;AAAA,IAC9B,IAAI,MAAA,GAAS;AAAE,MAAA,OAAO,MAAA;AAAA,IAA2C,CAAA;AAAA,IACjE,IAAI,UAAA,GAAa;AAAE,MAAA,OAAO,eAAA;AAAA,IAAiB;AAAA,GAC/C;AAEA,EAAA,OAAO,MAAA;AACX;AAOO,SAAS,eAAe,GAAA,EAAmC;AAC9D,EAAA,OACI,OAAO,GAAA,KAAQ,QAAA,IACf,GAAA,KAAQ,IAAA,IACR,QAAA,IAAY,GAAA,IACZ,OAAA,IAAW,GAAA,IACX,OAAQ,GAAA,CAAqB,MAAA,KAAW,UAAA;AAEhD;AAGO,SAAS,UAAA,GAAsB;AAClC,EAAA,OAAO,aAAA,EAAc;AACzB","file":"chunk-VOBQDQKX.js","sourcesContent":["/**\r\n * Flight Server - Main server factory\r\n * \r\n * Creates a Flight server instance that handles routing, middleware, and rendering.\r\n * This is the primary entry point for Flight applications.\r\n * \r\n * @example\r\n * ```typescript\r\n * import { createServer } from '@flight-framework/core';\r\n * \r\n * const server = createServer();\r\n * \r\n * server.get('/api/health', () => Response.json({ status: 'ok' }));\r\n * \r\n * // Just works! Auto-detects Node.js, Bun, or Deno\r\n * server.listen(3000);\r\n * ```\r\n */\r\n\r\nimport { createRouter, type Router } from '../router/index.js';\r\nimport {\r\n createMiddlewareChain,\r\n createContextFromRequest,\r\n createResponseFromContext,\r\n type MiddlewareChain,\r\n type Middleware,\r\n} from '../middleware/index.js';\r\nimport { type FlightConfig, type FlightUserConfig, resolveConfig } from '../config/index.js';\r\nimport type { FlightAdapter } from '../adapters/index.js';\r\n\r\n// ============================================================================\r\n// Types\r\n// ============================================================================\r\n\r\n/** Route handler function signature */\r\nexport type RouteHandler = (context: RouteHandlerContext) => Promise<Response> | Response;\r\n\r\n/** Context passed to route handlers */\r\nexport interface RouteHandlerContext {\r\n /** The incoming request */\r\n request: Request;\r\n /** URL parameters from routing */\r\n params: Record<string, string | string[]>;\r\n /** Query parameters */\r\n query: URLSearchParams;\r\n /** Parsed URL */\r\n url: URL;\r\n /** Local data from middleware */\r\n locals: Record<string, unknown>;\r\n /** Database instance (if configured) */\r\n db?: unknown;\r\n /** Auth instance (if configured) */\r\n auth?: unknown;\r\n /** Email instance (if configured) */\r\n email?: unknown;\r\n}\r\n\r\n/** Server options */\r\nexport interface ServerOptions {\r\n /** Server configuration */\r\n config?: FlightUserConfig;\r\n /** Deployment adapter */\r\n adapter?: FlightAdapter;\r\n /** Database instance */\r\n db?: unknown;\r\n /** Auth instance */\r\n auth?: unknown;\r\n /** Email instance */\r\n email?: unknown;\r\n}\r\n\r\n/** Route definition for the server */\r\nexport interface ServerRoute {\r\n /** HTTP method (GET, POST, etc.) */\r\n method: string | string[];\r\n /** Route path pattern */\r\n path: string;\r\n /** Route handler */\r\n handler: RouteHandler;\r\n}\r\n\r\n/** Listen options */\r\nexport interface ListenOptions {\r\n /** Port to listen on (default: 3000) */\r\n port?: number;\r\n /** Hostname to bind to (default: 'localhost') */\r\n hostname?: string;\r\n /** Callback when server starts */\r\n onListen?: (info: { port: number; hostname: string }) => void;\r\n}\r\n\r\n/** Flight Server instance */\r\nexport interface FlightServer {\r\n /** Add a route */\r\n route(method: string | string[], path: string, handler: RouteHandler): FlightServer;\r\n\r\n /** Convenience methods for common HTTP methods */\r\n get(path: string, handler: RouteHandler): FlightServer;\r\n post(path: string, handler: RouteHandler): FlightServer;\r\n put(path: string, handler: RouteHandler): FlightServer;\r\n delete(path: string, handler: RouteHandler): FlightServer;\r\n patch(path: string, handler: RouteHandler): FlightServer;\r\n\r\n /** Add middleware */\r\n use(middleware: Middleware): FlightServer;\r\n use(path: string, middleware: Middleware): FlightServer;\r\n\r\n /** Handle incoming request (Web standard Request/Response) */\r\n handle(request: Request): Promise<Response>;\r\n\r\n /** \r\n * Start the HTTP server\r\n * Auto-detects runtime: Node.js, Bun, or Deno\r\n */\r\n listen(port?: number | ListenOptions): Promise<void>;\r\n\r\n /** Fetch handler for Bun.serve() and Deno.serve() */\r\n fetch(request: Request): Promise<Response>;\r\n\r\n /** Get the resolved configuration */\r\n readonly config: FlightConfig;\r\n\r\n /** Get the router instance */\r\n readonly router: Router<RouteHandler>;\r\n\r\n /** Get the middleware chain */\r\n readonly middleware: MiddlewareChain;\r\n}\r\n\r\n// ============================================================================\r\n// Runtime Detection\r\n// ============================================================================\r\n\r\ntype Runtime = 'node' | 'bun' | 'deno' | 'unknown';\r\n\r\nfunction detectRuntime(): Runtime {\r\n // @ts-expect-error - Bun global\r\n if (typeof Bun !== 'undefined') return 'bun';\r\n // @ts-expect-error - Deno global \r\n if (typeof Deno !== 'undefined') return 'deno';\r\n if (typeof process !== 'undefined' && process.versions?.node) return 'node';\r\n return 'unknown';\r\n}\r\n\r\n// ============================================================================\r\n// Server Implementation\r\n// ============================================================================\r\n\r\ninterface RouteEntry {\r\n methods: Set<string>;\r\n handler: RouteHandler;\r\n}\r\n\r\n/**\r\n * Create a new Flight server instance\r\n * \r\n * @example\r\n * ```typescript\r\n * import { createServer } from '@flight-framework/core';\r\n * \r\n * const server = createServer();\r\n * \r\n * server.get('/api/users', async ({ db }) => {\r\n * const users = await db.query('SELECT * FROM users');\r\n * return Response.json(users);\r\n * });\r\n * \r\n * // Works on Node.js, Bun, and Deno!\r\n * server.listen(3000);\r\n * ```\r\n */\r\nexport function createServer(options: ServerOptions = {}): FlightServer {\r\n const config = resolveConfig(options.config ?? {});\r\n const router = createRouter<RouteEntry>();\r\n const middlewareChain = createMiddlewareChain();\r\n\r\n // Store dependencies\r\n const deps = {\r\n db: options.db,\r\n auth: options.auth,\r\n email: options.email,\r\n };\r\n\r\n function addRoute(method: string | string[], path: string, handler: RouteHandler): FlightServer {\r\n const methods = Array.isArray(method) ? method : [method];\r\n const methodSet = new Set(methods.map(m => m.toUpperCase()));\r\n\r\n // Check if route already exists\r\n const existingMatch = router.match(path);\r\n if (existingMatch && existingMatch.route.path === path) {\r\n // Merge methods\r\n for (const m of methodSet) {\r\n existingMatch.route.handler.methods.add(m);\r\n }\r\n existingMatch.route.handler.handler = handler;\r\n } else {\r\n router.add({\r\n path,\r\n handler: { methods: methodSet, handler },\r\n });\r\n }\r\n\r\n return server;\r\n }\r\n\r\n function useMiddleware(\r\n pathOrMiddleware: string | Middleware,\r\n maybeMiddleware?: Middleware\r\n ): FlightServer {\r\n if (typeof pathOrMiddleware === 'string' && maybeMiddleware) {\r\n middlewareChain.use(pathOrMiddleware, maybeMiddleware);\r\n } else if (typeof pathOrMiddleware === 'function') {\r\n middlewareChain.use(pathOrMiddleware);\r\n }\r\n return server;\r\n }\r\n\r\n async function handle(request: Request): Promise<Response> {\r\n const url = new URL(request.url);\r\n const method = request.method.toUpperCase();\r\n\r\n // Run middleware\r\n const ctx = createContextFromRequest(request);\r\n await middlewareChain.execute(ctx);\r\n\r\n // If middleware already set a response, return it\r\n if (ctx.responseBody !== undefined) {\r\n return createResponseFromContext(ctx);\r\n }\r\n\r\n // Match route\r\n const match = router.match(url.pathname);\r\n if (!match) {\r\n return new Response('Not Found', { status: 404 });\r\n }\r\n\r\n // Check method\r\n if (!match.route.handler.methods.has(method) && !match.route.handler.methods.has('*')) {\r\n return new Response('Method Not Allowed', { status: 405 });\r\n }\r\n\r\n // Build handler context\r\n const handlerContext: RouteHandlerContext = {\r\n request,\r\n params: match.params,\r\n query: url.searchParams,\r\n url,\r\n locals: ctx.locals,\r\n ...deps,\r\n };\r\n\r\n try {\r\n return await match.route.handler.handler(handlerContext);\r\n } catch (error) {\r\n console.error('Route handler error:', error);\r\n return new Response('Internal Server Error', { status: 500 });\r\n }\r\n }\r\n\r\n /**\r\n * Start the HTTP server\r\n * Auto-detects the runtime and uses the appropriate server\r\n */\r\n async function listen(portOrOptions?: number | ListenOptions): Promise<void> {\r\n const opts: ListenOptions = typeof portOrOptions === 'number'\r\n ? { port: portOrOptions }\r\n : portOrOptions ?? {};\r\n\r\n const port = opts.port ?? config.dev.port ?? 3000;\r\n const hostname = opts.hostname ?? 'localhost';\r\n\r\n // Check for custom adapter first\r\n const adapter = options.adapter ?? config.adapter;\r\n if (adapter?.listen) {\r\n await adapter.listen(server, port);\r\n return;\r\n }\r\n\r\n const runtime = detectRuntime();\r\n\r\n switch (runtime) {\r\n case 'bun':\r\n await startBunServer(port, hostname, opts.onListen);\r\n break;\r\n case 'deno':\r\n await startDenoServer(port, hostname, opts.onListen);\r\n break;\r\n case 'node':\r\n default:\r\n await startNodeServer(port, hostname, opts.onListen);\r\n break;\r\n }\r\n }\r\n\r\n /**\r\n * Start Node.js HTTP server\r\n */\r\n async function startNodeServer(port: number, hostname: string, onListen?: ListenOptions['onListen']): Promise<void> {\r\n const { createServer: createHttpServer } = await import('node:http');\r\n\r\n const httpServer = createHttpServer(async (req, res) => {\r\n const url = new URL(req.url || '/', `http://${hostname}:${port}`);\r\n\r\n // Build headers\r\n const headers = new Headers();\r\n for (const [key, value] of Object.entries(req.headers)) {\r\n if (value) {\r\n const headerValue = Array.isArray(value) ? value[0] : value;\r\n if (headerValue) headers.set(key, headerValue);\r\n }\r\n }\r\n\r\n // Read body for POST/PUT/PATCH\r\n let body: string | undefined;\r\n if (['POST', 'PUT', 'PATCH'].includes(req.method || '')) {\r\n body = await new Promise<string>((resolve) => {\r\n let data = '';\r\n req.on('data', chunk => data += chunk);\r\n req.on('end', () => resolve(data));\r\n });\r\n }\r\n\r\n const request = new Request(url.toString(), {\r\n method: req.method,\r\n headers,\r\n body: body || undefined,\r\n });\r\n\r\n try {\r\n const response = await handle(request);\r\n\r\n res.statusCode = response.status;\r\n response.headers.forEach((value, key) => {\r\n res.setHeader(key, value);\r\n });\r\n\r\n const responseBody = await response.text();\r\n res.end(responseBody);\r\n } catch (error) {\r\n console.error('Server error:', error);\r\n res.statusCode = 500;\r\n res.setHeader('Content-Type', 'application/json');\r\n res.end(JSON.stringify({ error: 'Internal Server Error' }));\r\n }\r\n });\r\n\r\n return new Promise((resolve) => {\r\n httpServer.listen(port, hostname, () => {\r\n const info = { port, hostname };\r\n if (onListen) {\r\n onListen(info);\r\n } else {\r\n console.log(`\r\n╔═══════════════════════════════════════════════════════════╗\r\n║ Flight Server (Node.js) ║\r\n╠═══════════════════════════════════════════════════════════╣\r\n║ Server: http://${hostname}:${port.toString().padEnd(37)}║\r\n╚═══════════════════════════════════════════════════════════╝\r\n`);\r\n }\r\n resolve();\r\n });\r\n });\r\n }\r\n\r\n /**\r\n * Start Bun server\r\n */\r\n async function startBunServer(port: number, hostname: string, onListen?: ListenOptions['onListen']): Promise<void> {\r\n // @ts-expect-error - Bun types\r\n Bun.serve({\r\n port,\r\n hostname,\r\n fetch: handle,\r\n });\r\n\r\n const info = { port, hostname };\r\n if (onListen) {\r\n onListen(info);\r\n } else {\r\n console.log(`\r\n╔═══════════════════════════════════════════════════════════╗\r\n║ Flight Server (Bun) ║\r\n╠═══════════════════════════════════════════════════════════╣\r\n║ Server: http://${hostname}:${port.toString().padEnd(37)}║\r\n╚═══════════════════════════════════════════════════════════╝\r\n`);\r\n }\r\n }\r\n\r\n /**\r\n * Start Deno server\r\n */\r\n async function startDenoServer(port: number, hostname: string, onListen?: ListenOptions['onListen']): Promise<void> {\r\n // @ts-expect-error - Deno types\r\n Deno.serve({ port, hostname }, handle);\r\n\r\n const info = { port, hostname };\r\n if (onListen) {\r\n onListen(info);\r\n } else {\r\n console.log(`\r\n╔═══════════════════════════════════════════════════════════╗\r\n║ Flight Server (Deno) ║\r\n╠═══════════════════════════════════════════════════════════╣\r\n║ Server: http://${hostname}:${port.toString().padEnd(37)}║\r\n╚═══════════════════════════════════════════════════════════╝\r\n`);\r\n }\r\n }\r\n\r\n const server: FlightServer = {\r\n route: addRoute,\r\n get: (path, handler) => addRoute('GET', path, handler),\r\n post: (path, handler) => addRoute('POST', path, handler),\r\n put: (path, handler) => addRoute('PUT', path, handler),\r\n delete: (path, handler) => addRoute('DELETE', path, handler),\r\n patch: (path, handler) => addRoute('PATCH', path, handler),\r\n use: useMiddleware as FlightServer['use'],\r\n handle,\r\n listen,\r\n fetch: handle, // Alias for Bun/Deno compatibility\r\n get config() { return config; },\r\n get router() { return router as unknown as Router<RouteHandler>; },\r\n get middleware() { return middlewareChain; },\r\n };\r\n\r\n return server;\r\n}\r\n\r\n// ============================================================================\r\n// Helper Exports\r\n// ============================================================================\r\n\r\n/** Type guard to check if an object is a FlightServer */\r\nexport function isFlightServer(obj: unknown): obj is FlightServer {\r\n return (\r\n typeof obj === 'object' &&\r\n obj !== null &&\r\n 'handle' in obj &&\r\n 'route' in obj &&\r\n typeof (obj as FlightServer).handle === 'function'\r\n );\r\n}\r\n\r\n/** Get current runtime */\r\nexport function getRuntime(): Runtime {\r\n return detectRuntime();\r\n}\r\n\r\n"]}
@@ -5,6 +5,22 @@ import { FlightAdapter } from '../adapters/index.js';
5
5
  * Flight Configuration - User configuration system
6
6
  */
7
7
 
8
+ /**
9
+ * Bundler adapter interface.
10
+ * Import the full type from @flight-framework/bundler for implementation.
11
+ */
12
+ interface BundlerAdapter {
13
+ /** Adapter identifier */
14
+ name: string;
15
+ /** Bundler name (vite, esbuild, rolldown, etc.) */
16
+ bundler: string;
17
+ /** Bundler-specific options */
18
+ options?: Record<string, unknown>;
19
+ /** Create dev server */
20
+ createDevServer(config: FlightConfig): Promise<unknown>;
21
+ /** Build for production */
22
+ build(config: FlightConfig): Promise<unknown>;
23
+ }
8
24
  /** UI Framework configuration */
9
25
  interface UIConfig {
10
26
  /** The UI framework to use */
@@ -62,6 +78,8 @@ interface FlightConfig {
62
78
  root: string;
63
79
  /** Deployment adapter */
64
80
  adapter: FlightAdapter | null;
81
+ /** Bundler adapter (Vite, esbuild, Rolldown, etc.) */
82
+ bundler: BundlerAdapter | null;
65
83
  /** UI framework configuration */
66
84
  ui: UIConfig;
67
85
  /** Rendering configuration */
@@ -70,7 +88,9 @@ interface FlightConfig {
70
88
  dev: Required<DevConfig>;
71
89
  /** Build configuration */
72
90
  build: Required<BuildConfig>;
73
- /** Vite configuration overrides */
91
+ /** Bundler-specific configuration (passed to adapter) */
92
+ bundlerOptions?: Record<string, unknown>;
93
+ /** @deprecated Use bundler adapter instead */
74
94
  vite?: Record<string, unknown>;
75
95
  /** Plugin configurations */
76
96
  plugins: FlightPlugin[];
@@ -94,6 +114,8 @@ interface FlightUserConfig {
94
114
  root?: string;
95
115
  /** Deployment adapter */
96
116
  adapter?: FlightAdapter;
117
+ /** Bundler adapter (Vite, esbuild, Rolldown, etc.) */
118
+ bundler?: BundlerAdapter;
97
119
  /** UI framework configuration */
98
120
  ui?: UIConfig;
99
121
  /** Rendering configuration */
@@ -102,7 +124,9 @@ interface FlightUserConfig {
102
124
  dev?: DevConfig;
103
125
  /** Build configuration */
104
126
  build?: BuildConfig;
105
- /** Vite configuration overrides */
127
+ /** Bundler-specific configuration */
128
+ bundlerOptions?: Record<string, unknown>;
129
+ /** @deprecated Use bundler adapter instead */
106
130
  vite?: Record<string, unknown>;
107
131
  /** Plugins */
108
132
  plugins?: FlightPlugin[];
@@ -143,4 +167,4 @@ declare function findConfigFile(root: string): Promise<string | null>;
143
167
  */
144
168
  declare function loadConfig(root?: string): Promise<FlightConfig>;
145
169
 
146
- export { type BuildConfig, type DevConfig, type FlightConfig, type FlightPlugin, type FlightUserConfig, type RenderConfig, type UIConfig, defineConfig, findConfigFile, loadConfig, resolveConfig };
170
+ export { type BuildConfig, type BundlerAdapter, type DevConfig, type FlightConfig, type FlightPlugin, type FlightUserConfig, type RenderConfig, type UIConfig, defineConfig, findConfigFile, loadConfig, resolveConfig };
@@ -1,3 +1,3 @@
1
- export { defineConfig, findConfigFile, loadConfig, resolveConfig } from '../chunk-3TPAA52K.js';
1
+ export { defineConfig, findConfigFile, loadConfig, resolveConfig } from '../chunk-IXMD5QH2.js';
2
2
  //# sourceMappingURL=index.js.map
3
3
  //# sourceMappingURL=index.js.map
package/dist/index.d.ts CHANGED
@@ -3,7 +3,7 @@ export { Route, RouteMatch, RouteParams, Router, createRouter } from './router/i
3
3
  export { FlightServer, RouteHandler, RouteHandlerContext, ServerOptions, ServerRoute, createServer } from './server/index.js';
4
4
  export { RenderContext, RenderMode, RenderResult } from './render/index.js';
5
5
  import { CacheOptions, Cache } from './cache/index.js';
6
- export { createCache } from './cache/index.js';
6
+ export { CacheAdapter, CacheEntry, CacheStats, CreateCacheOptions, Serializer, cacheKey, cached, createCache, dedupe, jsonSerializer, memory } from './cache/index.js';
7
7
  export { Middleware, MiddlewareContext, MiddlewareNext, createMiddlewareChain } from './middleware/index.js';
8
8
  export { AdapterBuilder, FlightAdapter } from './adapters/index.js';
9
9
  export { FileRoute, FileRouter, FileRouterOptions, ScanResult, createFileRouter, loadRoutes, scanRoutes } from './file-router/index.js';
@@ -574,6 +574,313 @@ declare function isDevToolsEnabled(): boolean;
574
574
  */
575
575
  declare function createDevToolsData(startTime: number, options?: Partial<DevToolsOptions>): DevToolsOptions;
576
576
 
577
+ /**
578
+ * @flight-framework/core - Error Handling
579
+ *
580
+ * Comprehensive error handling utilities for Flight applications.
581
+ * All utilities are OPTIONAL - developers can use their own error handling.
582
+ *
583
+ * Philosophy: Flight OFFERS these utilities, but never IMPOSES them.
584
+ * Using throw new Error() works perfectly fine - this is your choice.
585
+ */
586
+ /**
587
+ * Options for creating a Flight error
588
+ */
589
+ interface FlightErrorOptions {
590
+ /** HTTP status code */
591
+ statusCode: number;
592
+ /** Short status message (e.g., "Not Found") */
593
+ statusMessage?: string;
594
+ /** Detailed error message */
595
+ message?: string;
596
+ /** Additional data to include with the error */
597
+ data?: Record<string, unknown>;
598
+ /** If true, shows full-screen error page instead of error boundary */
599
+ fatal?: boolean;
600
+ /** Original error that caused this error */
601
+ cause?: Error;
602
+ }
603
+ /**
604
+ * Extended error props with digest for production error correlation
605
+ */
606
+ interface FlightErrorProps {
607
+ /** The error object */
608
+ error: Error & {
609
+ digest?: string;
610
+ };
611
+ /** Function to attempt recovery by re-rendering */
612
+ reset: () => void;
613
+ }
614
+ /**
615
+ * Reset details provided to onReset callback
616
+ */
617
+ interface ResetDetails {
618
+ /** Reason for the reset */
619
+ reason: 'imperative-api' | 'keys';
620
+ /** Arguments passed to resetErrorBoundary (if imperative) */
621
+ args?: unknown[];
622
+ /** Previous resetKeys values (if keys changed) */
623
+ prev?: unknown[];
624
+ /** New resetKeys values (if keys changed) */
625
+ next?: unknown[];
626
+ }
627
+ /**
628
+ * Options for error boundary behavior
629
+ */
630
+ interface ErrorBoundaryOptions {
631
+ /** Keys that trigger automatic reset when changed */
632
+ resetKeys?: unknown[];
633
+ /** Callback when error boundary resets */
634
+ onReset?: (details: ResetDetails) => void;
635
+ /** Callback when error is caught */
636
+ onError?: (error: Error, info: {
637
+ componentStack?: string;
638
+ }) => void;
639
+ }
640
+ /**
641
+ * Custom error class with status code and metadata support.
642
+ *
643
+ * You can use this class or regular Error - Flight handles both.
644
+ *
645
+ * @example
646
+ * ```typescript
647
+ * throw new FlightError({
648
+ * statusCode: 404,
649
+ * message: 'User not found',
650
+ * data: { userId: '123' }
651
+ * });
652
+ * ```
653
+ */
654
+ declare class FlightError extends Error {
655
+ /** HTTP status code */
656
+ readonly statusCode: number;
657
+ /** Short status message */
658
+ readonly statusMessage: string;
659
+ /** Additional error data */
660
+ readonly data?: Record<string, unknown>;
661
+ /** Whether this is a fatal error (shows full-screen) */
662
+ readonly fatal: boolean;
663
+ /** Unique digest for production error correlation */
664
+ readonly digest?: string;
665
+ constructor(options: FlightErrorOptions);
666
+ /**
667
+ * Convert to plain object for serialization
668
+ */
669
+ toJSON(): Record<string, unknown>;
670
+ }
671
+ /**
672
+ * 400 Bad Request error
673
+ */
674
+ declare class BadRequestError extends FlightError {
675
+ constructor(message?: string, data?: Record<string, unknown>);
676
+ }
677
+ /**
678
+ * 401 Unauthorized error
679
+ */
680
+ declare class UnauthorizedError extends FlightError {
681
+ constructor(message?: string, data?: Record<string, unknown>);
682
+ }
683
+ /**
684
+ * 403 Forbidden error
685
+ */
686
+ declare class ForbiddenError extends FlightError {
687
+ constructor(message?: string, data?: Record<string, unknown>);
688
+ }
689
+ /**
690
+ * 404 Not Found error
691
+ */
692
+ declare class NotFoundError extends FlightError {
693
+ constructor(message?: string, data?: Record<string, unknown>);
694
+ }
695
+ /**
696
+ * 500 Internal Server Error
697
+ */
698
+ declare class InternalError extends FlightError {
699
+ constructor(message?: string, data?: Record<string, unknown>);
700
+ }
701
+ /**
702
+ * Create a FlightError with the specified options.
703
+ *
704
+ * This is a convenience function - you can also use `new FlightError()` directly
705
+ * or just `throw new Error()` - Flight handles all cases.
706
+ *
707
+ * @example
708
+ * ```typescript
709
+ * // With full options
710
+ * throw createError({
711
+ * statusCode: 404,
712
+ * message: 'Product not found',
713
+ * data: { productId: 'abc123' }
714
+ * });
715
+ *
716
+ * // Simple string shorthand (becomes 500 error)
717
+ * throw createError('Something went wrong');
718
+ * ```
719
+ */
720
+ declare function createError(options: FlightErrorOptions | string): FlightError;
721
+ /**
722
+ * Create a 404 Not Found error.
723
+ * Convenience function equivalent to `createError({ statusCode: 404, ... })`.
724
+ *
725
+ * @example
726
+ * ```typescript
727
+ * if (!user) {
728
+ * throw notFound('User not found');
729
+ * }
730
+ * ```
731
+ */
732
+ declare function notFound(message?: string, data?: Record<string, unknown>): never;
733
+ /**
734
+ * Create a 403 Forbidden error.
735
+ *
736
+ * @example
737
+ * ```typescript
738
+ * if (!user.isAdmin) {
739
+ * throw forbidden('Admin access required');
740
+ * }
741
+ * ```
742
+ */
743
+ declare function forbidden(message?: string, data?: Record<string, unknown>): never;
744
+ /**
745
+ * Create a 401 Unauthorized error.
746
+ *
747
+ * @example
748
+ * ```typescript
749
+ * if (!session) {
750
+ * throw unauthorized('Please log in to continue');
751
+ * }
752
+ * ```
753
+ */
754
+ declare function unauthorized(message?: string, data?: Record<string, unknown>): never;
755
+ declare global {
756
+ interface Window {
757
+ __FLIGHT_ERROR__?: FlightError | null;
758
+ }
759
+ }
760
+ /**
761
+ * Programmatically show an error page.
762
+ *
763
+ * This triggers the nearest error boundary or navigates to the error page.
764
+ * Only works on the client side.
765
+ *
766
+ * @example
767
+ * ```typescript
768
+ * // Show error with full options
769
+ * showError({
770
+ * statusCode: 500,
771
+ * message: 'Connection lost'
772
+ * });
773
+ *
774
+ * // Simple string shorthand
775
+ * showError('Something went wrong');
776
+ * ```
777
+ */
778
+ declare function showError(error: FlightErrorOptions | FlightError | string): void;
779
+ /**
780
+ * Clear the current error state and optionally redirect.
781
+ *
782
+ * Use this to dismiss an error and return to normal state.
783
+ *
784
+ * @example
785
+ * ```typescript
786
+ * // Just clear the error
787
+ * clearError();
788
+ *
789
+ * // Clear and redirect to home
790
+ * clearError({ redirect: '/' });
791
+ * ```
792
+ */
793
+ declare function clearError(options?: {
794
+ redirect?: string;
795
+ }): void;
796
+ /**
797
+ * Get the current error from global state.
798
+ * Returns null if no error is active.
799
+ */
800
+ declare function getError(): FlightError | null;
801
+ /**
802
+ * Check if an error is a FlightError
803
+ */
804
+ declare function isFlightError(error: unknown): error is FlightError;
805
+ /**
806
+ * Check if an error is a NotFoundError (404)
807
+ */
808
+ declare function isNotFoundError(error: unknown): error is NotFoundError;
809
+ /**
810
+ * Check if an error is a ForbiddenError (403)
811
+ */
812
+ declare function isForbiddenError(error: unknown): error is ForbiddenError;
813
+ /**
814
+ * Check if an error is an UnauthorizedError (401)
815
+ */
816
+ declare function isUnauthorizedError(error: unknown): error is UnauthorizedError;
817
+ /**
818
+ * Get the status code from any error.
819
+ * Returns 500 for non-FlightError errors.
820
+ */
821
+ declare function getErrorStatusCode(error: unknown): number;
822
+ /**
823
+ * Create an error Response from a FlightError.
824
+ *
825
+ * @example
826
+ * ```typescript
827
+ * try {
828
+ * // ... some operation
829
+ * } catch (error) {
830
+ * return createErrorResponse(error);
831
+ * }
832
+ * ```
833
+ */
834
+ declare function createErrorResponse(error: unknown): Response;
835
+ /**
836
+ * Wrap an error with a digest if it doesn't have one.
837
+ * Useful for adding correlation IDs to third-party errors.
838
+ */
839
+ declare function wrapWithDigest<T extends Error>(error: T): T & {
840
+ digest: string;
841
+ };
842
+
843
+ /**
844
+ * @flight-framework/core - Environment Utilities
845
+ *
846
+ * Environment detection utilities that work across Node.js, browsers, and edge runtimes.
847
+ * No hardcoded values - detects environment dynamically.
848
+ */
849
+ /**
850
+ * Check if running in production environment.
851
+ *
852
+ * Detection order:
853
+ * 1. Node.js process.env.NODE_ENV
854
+ * 2. Vite/modern bundlers import.meta.env.MODE or import.meta.env.PROD
855
+ * 3. Default: false (not production)
856
+ */
857
+ declare function isProduction(): boolean;
858
+ /**
859
+ * Check if running in development environment.
860
+ *
861
+ * Detection order:
862
+ * 1. Node.js process.env.NODE_ENV
863
+ * 2. Vite/modern bundlers import.meta.env.MODE or import.meta.env.DEV
864
+ * 3. Default: true (assume development if unknown)
865
+ */
866
+ declare function isDevelopment(): boolean;
867
+ /**
868
+ * Check if running in test environment.
869
+ */
870
+ declare function isTest(): boolean;
871
+ /**
872
+ * Check if running on the server (not browser).
873
+ */
874
+ declare function isServer(): boolean;
875
+ /**
876
+ * Check if running in the browser.
877
+ */
878
+ declare function isBrowser(): boolean;
879
+ /**
880
+ * Get the current environment name.
881
+ */
882
+ declare function getEnvironment(): 'production' | 'development' | 'test' | 'unknown';
883
+
577
884
  /**
578
885
  * Flight Framework - Core
579
886
  *
@@ -583,4 +890,4 @@ declare function createDevToolsData(startTime: number, options?: Partial<DevTool
583
890
 
584
891
  declare const VERSION = "0.0.1";
585
892
 
586
- export { Cache, CacheOptions, type DevToolsOptions, type GenerateMetadataFn, type GenerateMetadataFunction, type GenerateStaticParamsFunction, type ISRCacheAdapter, type ISRCacheEntry, type Metadata, type PageMetadata, type PageModule, type PrerenderError, type PrerenderOptions, type PrerenderProgress, type PrerenderResult, type PrerenderSummary, type RevalidateHandlerOptions, type RevalidationResult, type RouteRule, type RouteRules, type StaticParams, VERSION, buildCacheControlHeader, createDefaultRouteRules, createDevToolsData, createHtmlStream, createISRCacheFromFlightCache, createMemoryISRCache, createRevalidateHandler, createStreamingResponse as createStaticStreamingResponse, expandDynamicRoutes, extractLinks, generateAllStaticPaths, getCacheOptionsFromRule, getISRCache, getOrGeneratePage, getRenderModeFromRule, getRevalidateTime, injectDevTools, isDevToolsEnabled, matchRouteRule, mergeMetadata, mergeRouteRules, prerenderRoutes, purgeAllPages, purgePage, renderMetadataToHead, resolveMetadata, revalidatePath, revalidatePaths, revalidateTag, setISRCache, shouldDynamicallyRender };
893
+ export { BadRequestError, Cache, CacheOptions, type DevToolsOptions, type ErrorBoundaryOptions, FlightError, type FlightErrorOptions, type FlightErrorProps, ForbiddenError, type GenerateMetadataFn, type GenerateMetadataFunction, type GenerateStaticParamsFunction, type ISRCacheAdapter, type ISRCacheEntry, InternalError, type Metadata, NotFoundError, type PageMetadata, type PageModule, type PrerenderError, type PrerenderOptions, type PrerenderProgress, type PrerenderResult, type PrerenderSummary, type ResetDetails, type RevalidateHandlerOptions, type RevalidationResult, type RouteRule, type RouteRules, type StaticParams, UnauthorizedError, VERSION, buildCacheControlHeader, clearError, createDefaultRouteRules, createDevToolsData, createError, createErrorResponse, forbidden as createForbidden, createHtmlStream, createISRCacheFromFlightCache, createMemoryISRCache, notFound as createNotFound, createRevalidateHandler, createStreamingResponse as createStaticStreamingResponse, unauthorized as createUnauthorized, expandDynamicRoutes, extractLinks, generateAllStaticPaths, getCacheOptionsFromRule, getEnvironment, getError, getErrorStatusCode, getISRCache, getOrGeneratePage, getRenderModeFromRule, getRevalidateTime, injectDevTools, isBrowser, isDevToolsEnabled, isDevelopment, isFlightError, isForbiddenError as isForbidden, isNotFoundError as isNotFound, isProduction, isServer, isTest, isUnauthorizedError as isUnauthorized, matchRouteRule, mergeMetadata, mergeRouteRules, prerenderRoutes, purgeAllPages, purgePage, renderMetadataToHead, resolveMetadata, revalidatePath, revalidatePaths, revalidateTag, setISRCache, shouldDynamicallyRender, showError, wrapWithDigest };