@flightdev/core 0.6.7
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/LICENSE +21 -0
- package/README.md +541 -0
- package/dist/actions/index.d.ts +743 -0
- package/dist/actions/index.js +3 -0
- package/dist/actions/index.js.map +1 -0
- package/dist/adapters/index.d.ts +502 -0
- package/dist/adapters/index.js +3 -0
- package/dist/adapters/index.js.map +1 -0
- package/dist/cache/index.d.ts +191 -0
- package/dist/cache/index.js +3 -0
- package/dist/cache/index.js.map +1 -0
- package/dist/chunk-62HISNA3.js +354 -0
- package/dist/chunk-62HISNA3.js.map +1 -0
- package/dist/chunk-63LWTEDQ.js +341 -0
- package/dist/chunk-63LWTEDQ.js.map +1 -0
- package/dist/chunk-63SCEXD7.js +3 -0
- package/dist/chunk-63SCEXD7.js.map +1 -0
- package/dist/chunk-72MYOTUB.js +667 -0
- package/dist/chunk-72MYOTUB.js.map +1 -0
- package/dist/chunk-7CNW24MQ.js +257 -0
- package/dist/chunk-7CNW24MQ.js.map +1 -0
- package/dist/chunk-7WIEAUJT.js +300 -0
- package/dist/chunk-7WIEAUJT.js.map +1 -0
- package/dist/chunk-7ZZF4ULK.js +259 -0
- package/dist/chunk-7ZZF4ULK.js.map +1 -0
- package/dist/chunk-AE3JTS73.js +222 -0
- package/dist/chunk-AE3JTS73.js.map +1 -0
- package/dist/chunk-AP5NLUSB.js +258 -0
- package/dist/chunk-AP5NLUSB.js.map +1 -0
- package/dist/chunk-C37YQQI7.js +221 -0
- package/dist/chunk-C37YQQI7.js.map +1 -0
- package/dist/chunk-DCLVXFVH.js +225 -0
- package/dist/chunk-DCLVXFVH.js.map +1 -0
- package/dist/chunk-DZMWWDFD.js +223 -0
- package/dist/chunk-DZMWWDFD.js.map +1 -0
- package/dist/chunk-GCQZ4FHI.js +245 -0
- package/dist/chunk-GCQZ4FHI.js.map +1 -0
- package/dist/chunk-IPP44XY6.js +47 -0
- package/dist/chunk-IPP44XY6.js.map +1 -0
- package/dist/chunk-IW7FTQQX.js +267 -0
- package/dist/chunk-IW7FTQQX.js.map +1 -0
- package/dist/chunk-JX4YSCBH.js +428 -0
- package/dist/chunk-JX4YSCBH.js.map +1 -0
- package/dist/chunk-KX6UYWWR.js +229 -0
- package/dist/chunk-KX6UYWWR.js.map +1 -0
- package/dist/chunk-LWVETFJV.js +46 -0
- package/dist/chunk-LWVETFJV.js.map +1 -0
- package/dist/chunk-MCL2MCA2.js +285 -0
- package/dist/chunk-MCL2MCA2.js.map +1 -0
- package/dist/chunk-MZXCF35B.js +205 -0
- package/dist/chunk-MZXCF35B.js.map +1 -0
- package/dist/chunk-NCGPUFWV.js +96 -0
- package/dist/chunk-NCGPUFWV.js.map +1 -0
- package/dist/chunk-OEJMIE2Q.js +351 -0
- package/dist/chunk-OEJMIE2Q.js.map +1 -0
- package/dist/chunk-OYF2OAKS.js +394 -0
- package/dist/chunk-OYF2OAKS.js.map +1 -0
- package/dist/chunk-P6S43FYZ.js +316 -0
- package/dist/chunk-P6S43FYZ.js.map +1 -0
- package/dist/chunk-PL37KFRJ.js +3 -0
- package/dist/chunk-PL37KFRJ.js.map +1 -0
- package/dist/chunk-Q7BS5QC5.js +197 -0
- package/dist/chunk-Q7BS5QC5.js.map +1 -0
- package/dist/chunk-SDYPG3JD.js +288 -0
- package/dist/chunk-SDYPG3JD.js.map +1 -0
- package/dist/chunk-SUG56SZO.js +256 -0
- package/dist/chunk-SUG56SZO.js.map +1 -0
- package/dist/chunk-UVH5XJRP.js +164 -0
- package/dist/chunk-UVH5XJRP.js.map +1 -0
- package/dist/chunk-WZIJKCL3.js +282 -0
- package/dist/chunk-WZIJKCL3.js.map +1 -0
- package/dist/chunk-Y22AMGTM.js +3 -0
- package/dist/chunk-Y22AMGTM.js.map +1 -0
- package/dist/chunk-Z7G23XWU.js +200 -0
- package/dist/chunk-Z7G23XWU.js.map +1 -0
- package/dist/chunk-ZJU5M4IB.js +125 -0
- package/dist/chunk-ZJU5M4IB.js.map +1 -0
- package/dist/chunk-ZVC3ZWLM.js +52 -0
- package/dist/chunk-ZVC3ZWLM.js.map +1 -0
- package/dist/chunk-ZZZML7Y3.js +310 -0
- package/dist/chunk-ZZZML7Y3.js.map +1 -0
- package/dist/client.d.ts +25 -0
- package/dist/client.js +16 -0
- package/dist/client.js.map +1 -0
- package/dist/config/index.d.ts +170 -0
- package/dist/config/index.js +3 -0
- package/dist/config/index.js.map +1 -0
- package/dist/errors/index.d.ts +267 -0
- package/dist/errors/index.js +4 -0
- package/dist/errors/index.js.map +1 -0
- package/dist/file-router/index.d.ts +184 -0
- package/dist/file-router/index.js +3 -0
- package/dist/file-router/index.js.map +1 -0
- package/dist/file-router/streaming-hints.d.ts +129 -0
- package/dist/file-router/streaming-hints.js +3 -0
- package/dist/file-router/streaming-hints.js.map +1 -0
- package/dist/handlers/index.d.ts +59 -0
- package/dist/handlers/index.js +3 -0
- package/dist/handlers/index.js.map +1 -0
- package/dist/index.d.ts +588 -0
- package/dist/index.js +886 -0
- package/dist/index.js.map +1 -0
- package/dist/islands/index.d.ts +234 -0
- package/dist/islands/index.js +3 -0
- package/dist/islands/index.js.map +1 -0
- package/dist/middleware/index.d.ts +305 -0
- package/dist/middleware/index.js +3 -0
- package/dist/middleware/index.js.map +1 -0
- package/dist/react/index.d.ts +73 -0
- package/dist/react/index.js +52 -0
- package/dist/react/index.js.map +1 -0
- package/dist/render/index.d.ts +131 -0
- package/dist/render/index.js +3 -0
- package/dist/render/index.js.map +1 -0
- package/dist/router/index.d.ts +65 -0
- package/dist/router/index.js +3 -0
- package/dist/router/index.js.map +1 -0
- package/dist/rsc/adapters/index.d.ts +8 -0
- package/dist/rsc/adapters/index.js +7 -0
- package/dist/rsc/adapters/index.js.map +1 -0
- package/dist/rsc/adapters/preact.d.ts +97 -0
- package/dist/rsc/adapters/preact.js +3 -0
- package/dist/rsc/adapters/preact.js.map +1 -0
- package/dist/rsc/adapters/react.d.ts +82 -0
- package/dist/rsc/adapters/react.js +3 -0
- package/dist/rsc/adapters/react.js.map +1 -0
- package/dist/rsc/adapters/solid.d.ts +84 -0
- package/dist/rsc/adapters/solid.js +3 -0
- package/dist/rsc/adapters/solid.js.map +1 -0
- package/dist/rsc/adapters/vue.d.ts +80 -0
- package/dist/rsc/adapters/vue.js +3 -0
- package/dist/rsc/adapters/vue.js.map +1 -0
- package/dist/rsc/boundaries.d.ts +182 -0
- package/dist/rsc/boundaries.js +3 -0
- package/dist/rsc/boundaries.js.map +1 -0
- package/dist/rsc/context.d.ts +201 -0
- package/dist/rsc/context.js +3 -0
- package/dist/rsc/context.js.map +1 -0
- package/dist/rsc/index.d.ts +232 -0
- package/dist/rsc/index.js +15 -0
- package/dist/rsc/index.js.map +1 -0
- package/dist/rsc/legacy.d.ts +155 -0
- package/dist/rsc/legacy.js +3 -0
- package/dist/rsc/legacy.js.map +1 -0
- package/dist/rsc/payload.d.ts +262 -0
- package/dist/rsc/payload.js +3 -0
- package/dist/rsc/payload.js.map +1 -0
- package/dist/rsc/plugins/esbuild.d.ts +124 -0
- package/dist/rsc/plugins/esbuild.js +4 -0
- package/dist/rsc/plugins/esbuild.js.map +1 -0
- package/dist/rsc/plugins/index.d.ts +4 -0
- package/dist/rsc/plugins/index.js +6 -0
- package/dist/rsc/plugins/index.js.map +1 -0
- package/dist/rsc/plugins/rollup.d.ts +103 -0
- package/dist/rsc/plugins/rollup.js +4 -0
- package/dist/rsc/plugins/rollup.js.map +1 -0
- package/dist/rsc/renderer.d.ts +162 -0
- package/dist/rsc/renderer.js +5 -0
- package/dist/rsc/renderer.js.map +1 -0
- package/dist/rsc/stream.d.ts +129 -0
- package/dist/rsc/stream.js +3 -0
- package/dist/rsc/stream.js.map +1 -0
- package/dist/rsc/vite-plugin.d.ts +78 -0
- package/dist/rsc/vite-plugin.js +4 -0
- package/dist/rsc/vite-plugin.js.map +1 -0
- package/dist/server/index.d.ts +135 -0
- package/dist/server/index.js +6 -0
- package/dist/server/index.js.map +1 -0
- package/dist/streaming/adapters/index.d.ts +223 -0
- package/dist/streaming/adapters/index.js +3 -0
- package/dist/streaming/adapters/index.js.map +1 -0
- package/dist/streaming/conditional.d.ts +130 -0
- package/dist/streaming/conditional.js +3 -0
- package/dist/streaming/conditional.js.map +1 -0
- package/dist/streaming/index.d.ts +177 -0
- package/dist/streaming/index.js +3 -0
- package/dist/streaming/index.js.map +1 -0
- package/dist/streaming/observability.d.ts +201 -0
- package/dist/streaming/observability.js +4 -0
- package/dist/streaming/observability.js.map +1 -0
- package/dist/streaming/priority.d.ts +103 -0
- package/dist/streaming/priority.js +3 -0
- package/dist/streaming/priority.js.map +1 -0
- package/dist/utils/index.d.ts +42 -0
- package/dist/utils/index.js +4 -0
- package/dist/utils/index.js.map +1 -0
- package/package.json +228 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"renderer.js"}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { FlightChunk, ServerComponentChunk, ErrorBoundaryChunk } from './payload.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @flightdev/core - Flight Stream
|
|
5
|
+
*
|
|
6
|
+
* Protocolo de streaming para Server Components.
|
|
7
|
+
* Usa NDJSON (Newline Delimited JSON) para máxima debuggabilidad.
|
|
8
|
+
*
|
|
9
|
+
* Filosofía Flight:
|
|
10
|
+
* - Formato abierto y documentado
|
|
11
|
+
* - Works con cualquier runtime (Node, Deno, Bun, Edge)
|
|
12
|
+
* - Fácil de debuggear (text-based)
|
|
13
|
+
* - Sin dependencias
|
|
14
|
+
*
|
|
15
|
+
* @module @flightdev/core/rsc/stream
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Opciones para crear un FlightStream
|
|
20
|
+
*/
|
|
21
|
+
interface FlightStreamOptions {
|
|
22
|
+
/** Incluir timestamps en chunks */
|
|
23
|
+
timestamps?: boolean;
|
|
24
|
+
/** Prefix para IDs generados */
|
|
25
|
+
idPrefix?: string;
|
|
26
|
+
/** Callback cuando un chunk es enviado */
|
|
27
|
+
onChunk?: (chunk: FlightChunk) => void;
|
|
28
|
+
/** Callback cuando el stream termina */
|
|
29
|
+
onComplete?: () => void;
|
|
30
|
+
/** Callback en caso de error */
|
|
31
|
+
onError?: (error: Error) => void;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Resultado del parsing de un FlightStream
|
|
35
|
+
*/
|
|
36
|
+
interface FlightStreamResult {
|
|
37
|
+
/** Chunks recibidos */
|
|
38
|
+
chunks: FlightChunk[];
|
|
39
|
+
/** Componente raíz */
|
|
40
|
+
root?: ServerComponentChunk;
|
|
41
|
+
/** Errores encontrados */
|
|
42
|
+
errors: ErrorBoundaryChunk[];
|
|
43
|
+
/** Tiempo total de streaming en ms */
|
|
44
|
+
duration: number;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Crea un ReadableStream desde un AsyncIterable de chunks
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* ```typescript
|
|
51
|
+
* async function* renderApp() {
|
|
52
|
+
* yield createServerChunk('root', tree);
|
|
53
|
+
* yield createClientChunk('counter', './Counter', 'default', { initial: 0 });
|
|
54
|
+
* }
|
|
55
|
+
*
|
|
56
|
+
* const stream = createFlightStream(renderApp());
|
|
57
|
+
* return new Response(stream, { headers: { 'Content-Type': 'text/x-flight' } });
|
|
58
|
+
* ```
|
|
59
|
+
*/
|
|
60
|
+
declare function createFlightStream(chunks: AsyncIterable<FlightChunk>, options?: FlightStreamOptions): ReadableStream<Uint8Array>;
|
|
61
|
+
/**
|
|
62
|
+
* Crea un FlightStream desde un array de chunks
|
|
63
|
+
*/
|
|
64
|
+
declare function createFlightStreamFromArray(chunks: FlightChunk[], options?: FlightStreamOptions): ReadableStream<Uint8Array>;
|
|
65
|
+
/**
|
|
66
|
+
* Parsea un FlightStream a chunks individuales
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* ```typescript
|
|
70
|
+
* // En el cliente
|
|
71
|
+
* const response = await fetch('/page');
|
|
72
|
+
* const chunks = parseFlightStream(response.body!);
|
|
73
|
+
*
|
|
74
|
+
* for await (const chunk of chunks) {
|
|
75
|
+
* handleChunk(chunk);
|
|
76
|
+
* }
|
|
77
|
+
* ```
|
|
78
|
+
*/
|
|
79
|
+
declare function parseFlightStream(stream: ReadableStream<Uint8Array>): AsyncGenerator<FlightChunk>;
|
|
80
|
+
/**
|
|
81
|
+
* Parsea un string completo de FlightStream
|
|
82
|
+
*/
|
|
83
|
+
declare function parseFlightStreamSync(data: string): FlightChunk[];
|
|
84
|
+
/**
|
|
85
|
+
* Consume un FlightStream y retorna todos los chunks
|
|
86
|
+
*/
|
|
87
|
+
declare function consumeFlightStream(stream: ReadableStream<Uint8Array>): Promise<FlightStreamResult>;
|
|
88
|
+
/**
|
|
89
|
+
* Crea una Response con Flight payload
|
|
90
|
+
*/
|
|
91
|
+
declare function createFlightResponse(chunks: AsyncIterable<FlightChunk>, options?: FlightResponseOptions): Response;
|
|
92
|
+
interface FlightResponseOptions {
|
|
93
|
+
status?: number;
|
|
94
|
+
headers?: Record<string, string>;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Crea una Response HTML con streaming SSR + Flight payload embebido
|
|
98
|
+
*/
|
|
99
|
+
declare function createHybridResponse(htmlStream: ReadableStream<Uint8Array>, flightChunks: FlightChunk[], options?: FlightResponseOptions): Response;
|
|
100
|
+
/**
|
|
101
|
+
* Crea un stream controller para enviar chunks progresivamente
|
|
102
|
+
*/
|
|
103
|
+
declare function createStreamController(): {
|
|
104
|
+
stream: ReadableStream<Uint8Array>;
|
|
105
|
+
enqueue: (chunk: FlightChunk) => void;
|
|
106
|
+
error: (error: Error) => void;
|
|
107
|
+
close: () => void;
|
|
108
|
+
};
|
|
109
|
+
/**
|
|
110
|
+
* Merge múltiples streams en uno solo (para rendering paralelo)
|
|
111
|
+
*/
|
|
112
|
+
declare function mergeFlightStreams(...streams: ReadableStream<Uint8Array>[]): ReadableStream<Uint8Array>;
|
|
113
|
+
/**
|
|
114
|
+
* Pipe a flight stream through a transform
|
|
115
|
+
*/
|
|
116
|
+
declare function transformFlightStream(stream: ReadableStream<Uint8Array>, transform: (chunk: FlightChunk) => FlightChunk | null | Promise<FlightChunk | null>): ReadableStream<Uint8Array>;
|
|
117
|
+
/**
|
|
118
|
+
* Pretty print Flight chunks para debugging
|
|
119
|
+
*/
|
|
120
|
+
declare function prettyPrintChunks(chunks: FlightChunk[]): string;
|
|
121
|
+
/**
|
|
122
|
+
* Error durante parsing de FlightStream
|
|
123
|
+
*/
|
|
124
|
+
declare class FlightStreamError extends Error {
|
|
125
|
+
readonly rawData?: string | undefined;
|
|
126
|
+
constructor(message: string, rawData?: string | undefined);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export { type FlightResponseOptions, FlightStreamError, type FlightStreamOptions, type FlightStreamResult, consumeFlightStream, createFlightResponse, createFlightStream, createFlightStreamFromArray, createHybridResponse, createStreamController, mergeFlightStreams, parseFlightStream, parseFlightStreamSync, prettyPrintChunks, transformFlightStream };
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { FlightStreamError, consumeFlightStream, createFlightResponse, createFlightStream, createFlightStreamFromArray, createHybridResponse, createStreamController, mergeFlightStreams, parseFlightStream, parseFlightStreamSync, prettyPrintChunks, transformFlightStream } from '../chunk-SUG56SZO.js';
|
|
2
|
+
//# sourceMappingURL=stream.js.map
|
|
3
|
+
//# sourceMappingURL=stream.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"stream.js"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { Plugin } from 'vite';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @flightdev/vite-plugin-rsc
|
|
5
|
+
*
|
|
6
|
+
* Vite plugin for Flight Server Components.
|
|
7
|
+
* Transforms 'use client' and 'use server' directives at build time.
|
|
8
|
+
*
|
|
9
|
+
* Philosophy:
|
|
10
|
+
* - Zero config for common cases
|
|
11
|
+
* - Full control when needed
|
|
12
|
+
* - Works with any Vite project
|
|
13
|
+
* - No Next.js dependencies
|
|
14
|
+
*
|
|
15
|
+
* @module @flightdev/vite-plugin-rsc
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Plugin configuration
|
|
20
|
+
*/
|
|
21
|
+
interface FlightRSCPluginOptions {
|
|
22
|
+
/** Include patterns (glob) */
|
|
23
|
+
include?: string[];
|
|
24
|
+
/** Exclude patterns (glob) */
|
|
25
|
+
exclude?: string[];
|
|
26
|
+
/** Server actions endpoint */
|
|
27
|
+
actionsEndpoint?: string;
|
|
28
|
+
/** Client manifest output path */
|
|
29
|
+
clientManifest?: string;
|
|
30
|
+
/** Server manifest output path */
|
|
31
|
+
serverManifest?: string;
|
|
32
|
+
/** Enable dev mode features */
|
|
33
|
+
dev?: boolean;
|
|
34
|
+
/** Custom transforms */
|
|
35
|
+
transforms?: {
|
|
36
|
+
/** Transform client components */
|
|
37
|
+
client?: (code: string, id: string) => string | null;
|
|
38
|
+
/** Transform server actions */
|
|
39
|
+
server?: (code: string, id: string) => string | null;
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Client manifest entry
|
|
44
|
+
*/
|
|
45
|
+
interface ClientManifestEntry {
|
|
46
|
+
id: string;
|
|
47
|
+
file: string;
|
|
48
|
+
exports: string[];
|
|
49
|
+
chunks?: string[];
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Server manifest entry
|
|
53
|
+
*/
|
|
54
|
+
interface ServerManifestEntry {
|
|
55
|
+
id: string;
|
|
56
|
+
file: string;
|
|
57
|
+
actions: string[];
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Flight RSC Vite Plugin
|
|
61
|
+
*
|
|
62
|
+
* @example
|
|
63
|
+
* ```typescript
|
|
64
|
+
* // vite.config.ts
|
|
65
|
+
* import { flightRSC } from '@flightdev/core/rsc/vite-plugin';
|
|
66
|
+
*
|
|
67
|
+
* export default defineConfig({
|
|
68
|
+
* plugins: [
|
|
69
|
+
* flightRSC({
|
|
70
|
+
* actionsEndpoint: '/_flight/action',
|
|
71
|
+
* }),
|
|
72
|
+
* ],
|
|
73
|
+
* });
|
|
74
|
+
* ```
|
|
75
|
+
*/
|
|
76
|
+
declare function flightRSC(options?: FlightRSCPluginOptions): Plugin[];
|
|
77
|
+
|
|
78
|
+
export { type ClientManifestEntry, type FlightRSCPluginOptions, type ServerManifestEntry, flightRSC as default, flightRSC };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"vite-plugin.js"}
|
|
@@ -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 '@flightdev/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 '@flightdev/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 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"index.js"}
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
import { StreamingRenderOptions, StreamingRenderResult } from '../index.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @flightdev/core - Multi-Framework Streaming Adapters
|
|
5
|
+
*
|
|
6
|
+
* Streaming SSR adapters for React, Vue, Svelte, Solid, and HTMX.
|
|
7
|
+
* Uses dependency injection pattern for optional framework dependencies.
|
|
8
|
+
*
|
|
9
|
+
* Best Practices 2026:
|
|
10
|
+
* - Dependency injection for optional peer dependencies
|
|
11
|
+
* - Support both Node.js and Edge runtimes
|
|
12
|
+
* - Progressive hydration support
|
|
13
|
+
* - Error boundary integration
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```typescript
|
|
17
|
+
* // React adapter with your imports
|
|
18
|
+
* import { renderToReadableStream } from 'react-dom/server';
|
|
19
|
+
*
|
|
20
|
+
* const adapter = createReactStreamAdapter({
|
|
21
|
+
* renderToReadableStream,
|
|
22
|
+
* bootstrapModules: ['/client.js'],
|
|
23
|
+
* });
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Framework-specific streaming adapter
|
|
29
|
+
*/
|
|
30
|
+
interface StreamingAdapter<TComponent = unknown> {
|
|
31
|
+
/** Adapter name */
|
|
32
|
+
readonly name: string;
|
|
33
|
+
/** Framework version support */
|
|
34
|
+
readonly framework: string;
|
|
35
|
+
/** Runtime support */
|
|
36
|
+
readonly runtime: 'universal' | 'node' | 'edge';
|
|
37
|
+
/**
|
|
38
|
+
* Create a streaming response from a component
|
|
39
|
+
*/
|
|
40
|
+
stream(component: TComponent, options?: StreamingRenderOptions): Promise<StreamingRenderResult>;
|
|
41
|
+
/**
|
|
42
|
+
* Render to static string (for comparison/fallback)
|
|
43
|
+
*/
|
|
44
|
+
renderToString?(component: TComponent): Promise<string>;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Common adapter options
|
|
48
|
+
*/
|
|
49
|
+
interface AdapterOptions {
|
|
50
|
+
/** Enable streaming (default: true) */
|
|
51
|
+
streaming?: boolean;
|
|
52
|
+
/** Scripts to bootstrap on client */
|
|
53
|
+
bootstrapScripts?: string[];
|
|
54
|
+
/** Modules to bootstrap on client */
|
|
55
|
+
bootstrapModules?: string[];
|
|
56
|
+
/** Error handling strategy */
|
|
57
|
+
onError?: (error: Error) => void;
|
|
58
|
+
/** Shell ready callback */
|
|
59
|
+
onShellReady?: () => void;
|
|
60
|
+
/** All content ready callback */
|
|
61
|
+
onAllReady?: () => void;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* React streaming adapter options with required dependencies
|
|
65
|
+
*/
|
|
66
|
+
interface ReactAdapterOptions extends AdapterOptions {
|
|
67
|
+
/** React's renderToReadableStream (for Edge) */
|
|
68
|
+
renderToReadableStream?: (element: unknown, options?: {
|
|
69
|
+
bootstrapScripts?: string[];
|
|
70
|
+
bootstrapModules?: string[];
|
|
71
|
+
identifierPrefix?: string;
|
|
72
|
+
signal?: AbortSignal;
|
|
73
|
+
onError?: (error: unknown) => void;
|
|
74
|
+
}) => Promise<ReadableStream<Uint8Array> & {
|
|
75
|
+
allReady: Promise<void>;
|
|
76
|
+
}>;
|
|
77
|
+
/** React's renderToString (for static fallback) */
|
|
78
|
+
renderToString?: (element: unknown) => string;
|
|
79
|
+
/** Custom identifier prefix */
|
|
80
|
+
identifierPrefix?: string;
|
|
81
|
+
/** Abort signal */
|
|
82
|
+
signal?: AbortSignal;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Create a React streaming adapter
|
|
86
|
+
*
|
|
87
|
+
* @example
|
|
88
|
+
* ```typescript
|
|
89
|
+
* import { renderToReadableStream, renderToString } from 'react-dom/server';
|
|
90
|
+
*
|
|
91
|
+
* const adapter = createReactStreamAdapter({
|
|
92
|
+
* renderToReadableStream,
|
|
93
|
+
* renderToString,
|
|
94
|
+
* bootstrapModules: ['/client.js'],
|
|
95
|
+
* });
|
|
96
|
+
*
|
|
97
|
+
* const result = await adapter.stream(<App />);
|
|
98
|
+
* ```
|
|
99
|
+
*/
|
|
100
|
+
declare function createReactStreamAdapter(options: ReactAdapterOptions): StreamingAdapter;
|
|
101
|
+
/**
|
|
102
|
+
* Vue streaming adapter options
|
|
103
|
+
*/
|
|
104
|
+
interface VueAdapterOptions extends AdapterOptions {
|
|
105
|
+
/** Vue's renderToWebStream */
|
|
106
|
+
renderToWebStream?: (app: unknown, context?: Record<string, unknown>) => ReadableStream;
|
|
107
|
+
/** Vue's renderToString */
|
|
108
|
+
renderToString?: (app: unknown) => Promise<string>;
|
|
109
|
+
/** Vue app context */
|
|
110
|
+
context?: Record<string, unknown>;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Create a Vue 3 streaming adapter
|
|
114
|
+
*
|
|
115
|
+
* @example
|
|
116
|
+
* ```typescript
|
|
117
|
+
* import { renderToWebStream, renderToString } from 'vue/server-renderer';
|
|
118
|
+
*
|
|
119
|
+
* const adapter = createVueStreamAdapter({
|
|
120
|
+
* renderToWebStream,
|
|
121
|
+
* renderToString,
|
|
122
|
+
* });
|
|
123
|
+
*
|
|
124
|
+
* const result = await adapter.stream(createSSRApp(App));
|
|
125
|
+
* ```
|
|
126
|
+
*/
|
|
127
|
+
declare function createVueStreamAdapter(options: VueAdapterOptions): StreamingAdapter;
|
|
128
|
+
/**
|
|
129
|
+
* Solid streaming adapter options
|
|
130
|
+
*/
|
|
131
|
+
interface SolidAdapterOptions extends AdapterOptions {
|
|
132
|
+
/** Solid's renderToStream */
|
|
133
|
+
renderToStream?: (fn: () => unknown, options?: {
|
|
134
|
+
nonce?: string;
|
|
135
|
+
onCompleteShell?: () => void;
|
|
136
|
+
onCompleteAll?: () => void;
|
|
137
|
+
}) => {
|
|
138
|
+
pipeTo: (writable: WritableStream) => void;
|
|
139
|
+
};
|
|
140
|
+
/** Solid's renderToString */
|
|
141
|
+
renderToString?: (fn: () => unknown) => string;
|
|
142
|
+
/** Nonce for CSP */
|
|
143
|
+
nonce?: string;
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Create a Solid.js streaming adapter
|
|
147
|
+
*
|
|
148
|
+
* @example
|
|
149
|
+
* ```typescript
|
|
150
|
+
* import { renderToStream, renderToString } from 'solid-js/web';
|
|
151
|
+
*
|
|
152
|
+
* const adapter = createSolidStreamAdapter({
|
|
153
|
+
* renderToStream,
|
|
154
|
+
* renderToString,
|
|
155
|
+
* });
|
|
156
|
+
*
|
|
157
|
+
* const result = await adapter.stream(() => <App />);
|
|
158
|
+
* ```
|
|
159
|
+
*/
|
|
160
|
+
declare function createSolidStreamAdapter(options: SolidAdapterOptions): StreamingAdapter;
|
|
161
|
+
/**
|
|
162
|
+
* Svelte streaming adapter options
|
|
163
|
+
*/
|
|
164
|
+
interface SvelteAdapterOptions extends AdapterOptions {
|
|
165
|
+
/** Svelte's render function */
|
|
166
|
+
render?: (component: unknown, options?: {
|
|
167
|
+
props?: Record<string, unknown>;
|
|
168
|
+
}) => {
|
|
169
|
+
body: string;
|
|
170
|
+
head?: string;
|
|
171
|
+
};
|
|
172
|
+
/** Props for the component */
|
|
173
|
+
props?: Record<string, unknown>;
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Create a Svelte 5 streaming adapter
|
|
177
|
+
* Note: Svelte's SSR is primarily string-based, streaming is simulated
|
|
178
|
+
*
|
|
179
|
+
* @example
|
|
180
|
+
* ```typescript
|
|
181
|
+
* import { render } from 'svelte/server';
|
|
182
|
+
*
|
|
183
|
+
* const adapter = createSvelteStreamAdapter({
|
|
184
|
+
* render,
|
|
185
|
+
* props: { name: 'World' },
|
|
186
|
+
* });
|
|
187
|
+
*
|
|
188
|
+
* const result = await adapter.stream(App);
|
|
189
|
+
* ```
|
|
190
|
+
*/
|
|
191
|
+
declare function createSvelteStreamAdapter(options: SvelteAdapterOptions): StreamingAdapter;
|
|
192
|
+
/**
|
|
193
|
+
* HTMX streaming adapter options
|
|
194
|
+
*/
|
|
195
|
+
interface HTMXAdapterOptions extends AdapterOptions {
|
|
196
|
+
/** Event name for SSE */
|
|
197
|
+
eventName?: string;
|
|
198
|
+
/** Retry interval for SSE */
|
|
199
|
+
retryMs?: number;
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Create an HTMX SSE streaming adapter
|
|
203
|
+
* Uses Server-Sent Events for progressive updates
|
|
204
|
+
*
|
|
205
|
+
* @example
|
|
206
|
+
* ```typescript
|
|
207
|
+
* const adapter = createHTMXStreamAdapter({
|
|
208
|
+
* eventName: 'update',
|
|
209
|
+
* retryMs: 3000,
|
|
210
|
+
* });
|
|
211
|
+
*
|
|
212
|
+
* const result = await adapter.stream(['<div>Part 1</div>', '<div>Part 2</div>']);
|
|
213
|
+
* ```
|
|
214
|
+
*/
|
|
215
|
+
declare function createHTMXStreamAdapter(options?: HTMXAdapterOptions): StreamingAdapter<string[]>;
|
|
216
|
+
type FrameworkType = 'react' | 'vue' | 'solid' | 'svelte' | 'htmx';
|
|
217
|
+
/**
|
|
218
|
+
* Create a streaming adapter for any supported framework
|
|
219
|
+
* Note: For react, vue, solid, svelte you need to pass the required dependencies
|
|
220
|
+
*/
|
|
221
|
+
declare function createStreamAdapter(framework: FrameworkType, options?: AdapterOptions & Record<string, unknown>): StreamingAdapter;
|
|
222
|
+
|
|
223
|
+
export { type AdapterOptions, type FrameworkType, type HTMXAdapterOptions, type ReactAdapterOptions, type SolidAdapterOptions, type StreamingAdapter, type SvelteAdapterOptions, type VueAdapterOptions, createHTMXStreamAdapter, createReactStreamAdapter, createSolidStreamAdapter, createStreamAdapter, createSvelteStreamAdapter, createVueStreamAdapter };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"index.js"}
|