@flight-framework/core 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (65) hide show
  1. package/LICENSE +21 -0
  2. package/dist/actions/index.d.ts +108 -0
  3. package/dist/actions/index.js +3 -0
  4. package/dist/actions/index.js.map +1 -0
  5. package/dist/adapters/index.d.ts +243 -0
  6. package/dist/adapters/index.js +3 -0
  7. package/dist/adapters/index.js.map +1 -0
  8. package/dist/cache/index.d.ts +76 -0
  9. package/dist/cache/index.js +3 -0
  10. package/dist/cache/index.js.map +1 -0
  11. package/dist/chunk-3AIQVGTM.js +120 -0
  12. package/dist/chunk-3AIQVGTM.js.map +1 -0
  13. package/dist/chunk-AFSKXC6V.js +188 -0
  14. package/dist/chunk-AFSKXC6V.js.map +1 -0
  15. package/dist/chunk-AJ3IBYXT.js +47 -0
  16. package/dist/chunk-AJ3IBYXT.js.map +1 -0
  17. package/dist/chunk-GCQZ4FHI.js +245 -0
  18. package/dist/chunk-GCQZ4FHI.js.map +1 -0
  19. package/dist/chunk-I5RHYGX6.js +167 -0
  20. package/dist/chunk-I5RHYGX6.js.map +1 -0
  21. package/dist/chunk-KWFX6WHG.js +311 -0
  22. package/dist/chunk-KWFX6WHG.js.map +1 -0
  23. package/dist/chunk-Q4C5CCHK.js +13 -0
  24. package/dist/chunk-Q4C5CCHK.js.map +1 -0
  25. package/dist/chunk-QEFGUHYD.js +221 -0
  26. package/dist/chunk-QEFGUHYD.js.map +1 -0
  27. package/dist/chunk-TKXN7KGE.js +145 -0
  28. package/dist/chunk-TKXN7KGE.js.map +1 -0
  29. package/dist/chunk-WAGCTWGY.js +93 -0
  30. package/dist/chunk-WAGCTWGY.js.map +1 -0
  31. package/dist/chunk-Y22KEW2F.js +223 -0
  32. package/dist/chunk-Y22KEW2F.js.map +1 -0
  33. package/dist/chunk-ZVC3ZWLM.js +52 -0
  34. package/dist/chunk-ZVC3ZWLM.js.map +1 -0
  35. package/dist/config/index.d.ts +146 -0
  36. package/dist/config/index.js +3 -0
  37. package/dist/config/index.js.map +1 -0
  38. package/dist/file-router/index.d.ts +71 -0
  39. package/dist/file-router/index.js +3 -0
  40. package/dist/file-router/index.js.map +1 -0
  41. package/dist/handlers/index.d.ts +59 -0
  42. package/dist/handlers/index.js +3 -0
  43. package/dist/handlers/index.js.map +1 -0
  44. package/dist/index.d.ts +23 -0
  45. package/dist/index.js +19 -0
  46. package/dist/index.js.map +1 -0
  47. package/dist/middleware/index.d.ts +152 -0
  48. package/dist/middleware/index.js +3 -0
  49. package/dist/middleware/index.js.map +1 -0
  50. package/dist/render/index.d.ts +131 -0
  51. package/dist/render/index.js +3 -0
  52. package/dist/render/index.js.map +1 -0
  53. package/dist/router/index.d.ts +65 -0
  54. package/dist/router/index.js +3 -0
  55. package/dist/router/index.js.map +1 -0
  56. package/dist/rsc/index.d.ts +131 -0
  57. package/dist/rsc/index.js +3 -0
  58. package/dist/rsc/index.js.map +1 -0
  59. package/dist/server/index.d.ts +135 -0
  60. package/dist/server/index.js +6 -0
  61. package/dist/server/index.js.map +1 -0
  62. package/dist/streaming/index.d.ts +169 -0
  63. package/dist/streaming/index.js +3 -0
  64. package/dist/streaming/index.js.map +1 -0
  65. package/package.json +100 -0
@@ -0,0 +1,135 @@
1
+ import { Router } from '../router/index.js';
2
+ import { Middleware, MiddlewareChain } from '../middleware/index.js';
3
+ import { FlightUserConfig, FlightConfig } from '../config/index.js';
4
+ import { FlightAdapter } from '../adapters/index.js';
5
+ import '../render/index.js';
6
+
7
+ /**
8
+ * Flight Server - Main server factory
9
+ *
10
+ * Creates a Flight server instance that handles routing, middleware, and rendering.
11
+ * This is the primary entry point for Flight applications.
12
+ *
13
+ * @example
14
+ * ```typescript
15
+ * import { createServer } from '@flight/core';
16
+ *
17
+ * const server = createServer();
18
+ *
19
+ * server.get('/api/health', () => Response.json({ status: 'ok' }));
20
+ *
21
+ * // Just works! Auto-detects Node.js, Bun, or Deno
22
+ * server.listen(3000);
23
+ * ```
24
+ */
25
+
26
+ /** Route handler function signature */
27
+ type RouteHandler = (context: RouteHandlerContext) => Promise<Response> | Response;
28
+ /** Context passed to route handlers */
29
+ interface RouteHandlerContext {
30
+ /** The incoming request */
31
+ request: Request;
32
+ /** URL parameters from routing */
33
+ params: Record<string, string | string[]>;
34
+ /** Query parameters */
35
+ query: URLSearchParams;
36
+ /** Parsed URL */
37
+ url: URL;
38
+ /** Local data from middleware */
39
+ locals: Record<string, unknown>;
40
+ /** Database instance (if configured) */
41
+ db?: unknown;
42
+ /** Auth instance (if configured) */
43
+ auth?: unknown;
44
+ /** Email instance (if configured) */
45
+ email?: unknown;
46
+ }
47
+ /** Server options */
48
+ interface ServerOptions {
49
+ /** Server configuration */
50
+ config?: FlightUserConfig;
51
+ /** Deployment adapter */
52
+ adapter?: FlightAdapter;
53
+ /** Database instance */
54
+ db?: unknown;
55
+ /** Auth instance */
56
+ auth?: unknown;
57
+ /** Email instance */
58
+ email?: unknown;
59
+ }
60
+ /** Route definition for the server */
61
+ interface ServerRoute {
62
+ /** HTTP method (GET, POST, etc.) */
63
+ method: string | string[];
64
+ /** Route path pattern */
65
+ path: string;
66
+ /** Route handler */
67
+ handler: RouteHandler;
68
+ }
69
+ /** Listen options */
70
+ interface ListenOptions {
71
+ /** Port to listen on (default: 3000) */
72
+ port?: number;
73
+ /** Hostname to bind to (default: 'localhost') */
74
+ hostname?: string;
75
+ /** Callback when server starts */
76
+ onListen?: (info: {
77
+ port: number;
78
+ hostname: string;
79
+ }) => void;
80
+ }
81
+ /** Flight Server instance */
82
+ interface FlightServer {
83
+ /** Add a route */
84
+ route(method: string | string[], path: string, handler: RouteHandler): FlightServer;
85
+ /** Convenience methods for common HTTP methods */
86
+ get(path: string, handler: RouteHandler): FlightServer;
87
+ post(path: string, handler: RouteHandler): FlightServer;
88
+ put(path: string, handler: RouteHandler): FlightServer;
89
+ delete(path: string, handler: RouteHandler): FlightServer;
90
+ patch(path: string, handler: RouteHandler): FlightServer;
91
+ /** Add middleware */
92
+ use(middleware: Middleware): FlightServer;
93
+ use(path: string, middleware: Middleware): FlightServer;
94
+ /** Handle incoming request (Web standard Request/Response) */
95
+ handle(request: Request): Promise<Response>;
96
+ /**
97
+ * Start the HTTP server
98
+ * Auto-detects runtime: Node.js, Bun, or Deno
99
+ */
100
+ listen(port?: number | ListenOptions): Promise<void>;
101
+ /** Fetch handler for Bun.serve() and Deno.serve() */
102
+ fetch(request: Request): Promise<Response>;
103
+ /** Get the resolved configuration */
104
+ readonly config: FlightConfig;
105
+ /** Get the router instance */
106
+ readonly router: Router<RouteHandler>;
107
+ /** Get the middleware chain */
108
+ readonly middleware: MiddlewareChain;
109
+ }
110
+ type Runtime = 'node' | 'bun' | 'deno' | 'unknown';
111
+ /**
112
+ * Create a new Flight server instance
113
+ *
114
+ * @example
115
+ * ```typescript
116
+ * import { createServer } from '@flight/core';
117
+ *
118
+ * const server = createServer();
119
+ *
120
+ * server.get('/api/users', async ({ db }) => {
121
+ * const users = await db.query('SELECT * FROM users');
122
+ * return Response.json(users);
123
+ * });
124
+ *
125
+ * // Works on Node.js, Bun, and Deno!
126
+ * server.listen(3000);
127
+ * ```
128
+ */
129
+ declare function createServer(options?: ServerOptions): FlightServer;
130
+ /** Type guard to check if an object is a FlightServer */
131
+ declare function isFlightServer(obj: unknown): obj is FlightServer;
132
+ /** Get current runtime */
133
+ declare function getRuntime(): Runtime;
134
+
135
+ export { type FlightServer, type ListenOptions, type RouteHandler, type RouteHandlerContext, type ServerOptions, type ServerRoute, createServer, getRuntime, isFlightServer };
@@ -0,0 +1,6 @@
1
+ export { createServer, getRuntime, isFlightServer } from '../chunk-Y22KEW2F.js';
2
+ import '../chunk-GCQZ4FHI.js';
3
+ import '../chunk-KWFX6WHG.js';
4
+ import '../chunk-WAGCTWGY.js';
5
+ //# sourceMappingURL=index.js.map
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"index.js"}
@@ -0,0 +1,169 @@
1
+ /**
2
+ * @flight/core - Streaming SSR
3
+ *
4
+ * Full streaming server-side rendering implementation following React 18+/19 patterns.
5
+ * Supports both Node.js (renderToPipeableStream) and Edge (renderToReadableStream) environments.
6
+ *
7
+ * Best Practices 2025/2026:
8
+ * - Progressive HTML streaming with Suspense boundaries
9
+ * - Shell-first rendering for fast TTFB
10
+ * - Nested Suspense for granular loading states
11
+ * - Error boundaries for graceful degradation
12
+ * - Web Streams API for Edge runtime compatibility
13
+ */
14
+ /**
15
+ * Streaming render options following React's conventions
16
+ */
17
+ interface StreamingRenderOptions {
18
+ /** Bootstrap scripts to load on client */
19
+ bootstrapScripts?: string[];
20
+ /** Bootstrap ES modules */
21
+ bootstrapModules?: string[];
22
+ /** Inline script content */
23
+ bootstrapScriptContent?: string;
24
+ /** Prefix for React IDs (useId) */
25
+ identifierPrefix?: string;
26
+ /** Nonce for CSP */
27
+ nonce?: string;
28
+ /** Callback when shell is ready (main content before Suspense) */
29
+ onShellReady?: () => void;
30
+ /** Callback when shell errors */
31
+ onShellError?: (error: Error) => void;
32
+ /** Callback when all content is ready */
33
+ onAllReady?: () => void;
34
+ /** Callback for any error */
35
+ onError?: (error: Error) => void;
36
+ /** Timeout before aborting stream */
37
+ timeoutMs?: number;
38
+ /** Progressive hydration enabled */
39
+ progressiveHydration?: boolean;
40
+ }
41
+ /**
42
+ * Streaming render result
43
+ */
44
+ interface StreamingRenderResult {
45
+ /** The readable stream to pipe to response */
46
+ stream: ReadableStream<Uint8Array>;
47
+ /** Abort the stream */
48
+ abort: () => void;
49
+ /** Promise that resolves when shell is ready */
50
+ shellReady: Promise<void>;
51
+ /** Promise that resolves when all content is ready */
52
+ allReady: Promise<void>;
53
+ }
54
+ /**
55
+ * Suspense boundary configuration
56
+ */
57
+ interface SuspenseBoundaryConfig {
58
+ /** Unique ID for this boundary */
59
+ id: string;
60
+ /** Fallback HTML to show while loading */
61
+ fallback: string;
62
+ /** Content resolver promise */
63
+ contentPromise: Promise<string>;
64
+ }
65
+ /**
66
+ * Create a streaming SSR response using Web Streams API.
67
+ * Compatible with Edge Runtime (Cloudflare, Vercel Edge, Deno).
68
+ *
69
+ * @example
70
+ * ```typescript
71
+ * const result = await createStreamingSSR({
72
+ * shell: '<html><body><div id="root">',
73
+ * shellEnd: '</div></body></html>',
74
+ * suspenseBoundaries: [
75
+ * {
76
+ * id: 'posts',
77
+ * fallback: '<div>Loading posts...</div>',
78
+ * contentPromise: fetchAndRenderPosts(),
79
+ * }
80
+ * ],
81
+ * bootstrapScripts: ['/client.js'],
82
+ * });
83
+ *
84
+ * return new Response(result.stream, {
85
+ * headers: { 'Content-Type': 'text/html' },
86
+ * });
87
+ * ```
88
+ */
89
+ declare function createStreamingSSR(config: {
90
+ /** Initial HTML shell (before suspense content) */
91
+ shell: string;
92
+ /** Closing HTML shell */
93
+ shellEnd: string;
94
+ /** Suspense boundaries with async content */
95
+ suspenseBoundaries?: SuspenseBoundaryConfig[];
96
+ /** Streaming options */
97
+ options?: StreamingRenderOptions;
98
+ }): Promise<StreamingRenderResult>;
99
+ /**
100
+ * Create a streaming HTML Response object
101
+ */
102
+ declare function createStreamingResponse(stream: ReadableStream<Uint8Array>, options?: {
103
+ status?: number;
104
+ headers?: Record<string, string>;
105
+ }): Response;
106
+ /**
107
+ * Higher-level API: Render page with Suspense boundaries
108
+ *
109
+ * @example
110
+ * ```typescript
111
+ * return renderWithStreaming({
112
+ * layout: ({ children }) => `
113
+ * <html>
114
+ * <head><title>My App</title></head>
115
+ * <body><div id="root">${children}</div></body>
116
+ * </html>
117
+ * `,
118
+ * page: async () => '<h1>Welcome</h1>',
119
+ * suspense: {
120
+ * posts: {
121
+ * fallback: '<div class="skeleton">Loading...</div>',
122
+ * content: fetchPosts().then(renderPosts),
123
+ * },
124
+ * },
125
+ * });
126
+ * ```
127
+ */
128
+ declare function renderWithStreaming(config: {
129
+ /** Layout wrapper */
130
+ layout: (props: {
131
+ children: string;
132
+ }) => string;
133
+ /** Main page content (sync part) */
134
+ page: () => string | Promise<string>;
135
+ /** Suspense boundaries keyed by ID */
136
+ suspense?: Record<string, {
137
+ fallback: string;
138
+ content: Promise<string>;
139
+ }>;
140
+ /** Bootstrap scripts */
141
+ bootstrapScripts?: string[];
142
+ /** Timeout in ms */
143
+ timeoutMs?: number;
144
+ }): Promise<Response>;
145
+ /**
146
+ * Create a lazy component that streams its content
147
+ */
148
+ declare function createLazyContent<T>(fetcher: () => Promise<T>, renderer: (data: T) => string, fallback: string): {
149
+ fallback: string;
150
+ content: Promise<string>;
151
+ };
152
+ /**
153
+ * Parallel streaming: resolve multiple boundaries simultaneously
154
+ */
155
+ declare function streamParallel(boundaries: Array<{
156
+ id: string;
157
+ fallback: string;
158
+ content: () => Promise<string>;
159
+ }>): Promise<SuspenseBoundaryConfig[]>;
160
+ /**
161
+ * Sequential streaming: resolve boundaries in order
162
+ */
163
+ declare function streamSequential(boundaries: Array<{
164
+ id: string;
165
+ fallback: string;
166
+ content: () => Promise<string>;
167
+ }>): Promise<SuspenseBoundaryConfig[]>;
168
+
169
+ export { type StreamingRenderOptions, type StreamingRenderResult, type SuspenseBoundaryConfig, createLazyContent, createStreamingResponse, createStreamingSSR, renderWithStreaming, streamParallel, streamSequential };
@@ -0,0 +1,3 @@
1
+ export { createLazyContent, createStreamingResponse, createStreamingSSR, renderWithStreaming, streamParallel, streamSequential } from '../chunk-QEFGUHYD.js';
2
+ //# sourceMappingURL=index.js.map
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"index.js"}
package/package.json ADDED
@@ -0,0 +1,100 @@
1
+ {
2
+ "name": "@flight-framework/core",
3
+ "version": "0.0.1",
4
+ "description": "Core primitives for Flight Framework - routing, rendering, caching",
5
+ "keywords": [
6
+ "flight",
7
+ "framework",
8
+ "core",
9
+ "ssr",
10
+ "routing"
11
+ ],
12
+ "license": "MIT",
13
+ "author": "Flight Contributors",
14
+ "type": "module",
15
+ "exports": {
16
+ ".": {
17
+ "types": "./dist/index.d.ts",
18
+ "import": "./dist/index.js"
19
+ },
20
+ "./router": {
21
+ "types": "./dist/router/index.d.ts",
22
+ "import": "./dist/router/index.js"
23
+ },
24
+ "./render": {
25
+ "types": "./dist/render/index.d.ts",
26
+ "import": "./dist/render/index.js"
27
+ },
28
+ "./cache": {
29
+ "types": "./dist/cache/index.d.ts",
30
+ "import": "./dist/cache/index.js"
31
+ },
32
+ "./middleware": {
33
+ "types": "./dist/middleware/index.d.ts",
34
+ "import": "./dist/middleware/index.js"
35
+ },
36
+ "./config": {
37
+ "types": "./dist/config/index.d.ts",
38
+ "import": "./dist/config/index.js"
39
+ },
40
+ "./adapters": {
41
+ "types": "./dist/adapters/index.d.ts",
42
+ "import": "./dist/adapters/index.js"
43
+ },
44
+ "./server": {
45
+ "types": "./dist/server/index.d.ts",
46
+ "import": "./dist/server/index.js"
47
+ },
48
+ "./file-router": {
49
+ "types": "./dist/file-router/index.d.ts",
50
+ "import": "./dist/file-router/index.js"
51
+ },
52
+ "./actions": {
53
+ "types": "./dist/actions/index.d.ts",
54
+ "import": "./dist/actions/index.js"
55
+ },
56
+ "./handlers": {
57
+ "types": "./dist/handlers/index.d.ts",
58
+ "import": "./dist/handlers/index.js"
59
+ },
60
+ "./streaming": {
61
+ "types": "./dist/streaming/index.d.ts",
62
+ "import": "./dist/streaming/index.js"
63
+ },
64
+ "./rsc": {
65
+ "types": "./dist/rsc/index.d.ts",
66
+ "import": "./dist/rsc/index.js"
67
+ }
68
+ },
69
+ "main": "./dist/index.js",
70
+ "types": "./dist/index.d.ts",
71
+ "files": [
72
+ "dist"
73
+ ],
74
+ "dependencies": {
75
+ "radix3": "^1.1.0"
76
+ },
77
+ "devDependencies": {
78
+ "@types/node": "^22.0.0",
79
+ "rimraf": "^6.0.0",
80
+ "tsup": "^8.0.0",
81
+ "typescript": "^5.7.0",
82
+ "vitest": "^2.0.0"
83
+ },
84
+ "peerDependencies": {
85
+ "vite": "^6.0.0 || ^7.0.0"
86
+ },
87
+ "peerDependenciesMeta": {
88
+ "vite": {
89
+ "optional": true
90
+ }
91
+ },
92
+ "scripts": {
93
+ "build": "tsup",
94
+ "dev": "tsup --watch",
95
+ "test": "vitest run",
96
+ "test:watch": "vitest",
97
+ "lint": "eslint src/",
98
+ "clean": "rimraf dist"
99
+ }
100
+ }