@flight-framework/core 0.0.3 → 0.2.0
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/dist/{chunk-5KF3QQWZ.js → chunk-3AY23FZP.js} +5 -19
- package/dist/chunk-3AY23FZP.js.map +1 -0
- package/dist/chunk-4F77J5TY.js +324 -0
- package/dist/chunk-4F77J5TY.js.map +1 -0
- package/dist/{chunk-CLMFEKYM.js → chunk-54HPVE7N.js} +67 -2
- package/dist/chunk-54HPVE7N.js.map +1 -0
- package/dist/chunk-5GUCB2CG.js +300 -0
- package/dist/chunk-5GUCB2CG.js.map +1 -0
- package/dist/chunk-62C7LX2E.js +205 -0
- package/dist/chunk-62C7LX2E.js.map +1 -0
- package/dist/chunk-63SCEXD7.js +3 -0
- package/dist/chunk-63SCEXD7.js.map +1 -0
- package/dist/chunk-6BDCTUQY.js +282 -0
- package/dist/chunk-6BDCTUQY.js.map +1 -0
- package/dist/chunk-6CD5FIYI.js +252 -0
- package/dist/chunk-6CD5FIYI.js.map +1 -0
- package/dist/chunk-6XZQPPYC.js +285 -0
- package/dist/chunk-6XZQPPYC.js.map +1 -0
- package/dist/chunk-BJIMTO2I.js +213 -0
- package/dist/chunk-BJIMTO2I.js.map +1 -0
- package/dist/chunk-CLZSB5QD.js +258 -0
- package/dist/chunk-CLZSB5QD.js.map +1 -0
- package/dist/chunk-K2CQZPCG.js +257 -0
- package/dist/chunk-K2CQZPCG.js.map +1 -0
- package/dist/chunk-MQQLYWZZ.js +288 -0
- package/dist/chunk-MQQLYWZZ.js.map +1 -0
- package/dist/chunk-MRLCNFSD.js +341 -0
- package/dist/chunk-MRLCNFSD.js.map +1 -0
- package/dist/chunk-PSJPMEQK.js +212 -0
- package/dist/chunk-PSJPMEQK.js.map +1 -0
- package/dist/chunk-Q62ZQ6FM.js +218 -0
- package/dist/chunk-Q62ZQ6FM.js.map +1 -0
- package/dist/{chunk-ABNCAPQB.js → chunk-RSVA2EYO.js} +2 -2
- package/dist/chunk-RSVA2EYO.js.map +1 -0
- package/dist/chunk-T3S5YC7L.js +256 -0
- package/dist/chunk-T3S5YC7L.js.map +1 -0
- package/dist/chunk-WFAWAHJH.js +267 -0
- package/dist/chunk-WFAWAHJH.js.map +1 -0
- package/dist/chunk-WOEIJWGJ.js +351 -0
- package/dist/chunk-WOEIJWGJ.js.map +1 -0
- package/dist/chunk-XOIYNY4I.js +164 -0
- package/dist/chunk-XOIYNY4I.js.map +1 -0
- package/dist/chunk-XSY5AAXT.js +125 -0
- package/dist/chunk-XSY5AAXT.js.map +1 -0
- package/dist/chunk-Y22AMGTM.js +3 -0
- package/dist/chunk-Y22AMGTM.js.map +1 -0
- package/dist/file-router/index.d.ts +9 -0
- package/dist/file-router/index.js +1 -1
- 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/index.d.ts +9 -1
- package/dist/index.js +23 -5
- package/dist/index.js.map +1 -1
- 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/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 +20 -124
- package/dist/rsc/index.js +13 -1
- package/dist/rsc/legacy.d.ts +131 -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 +160 -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/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 +8 -0
- package/dist/streaming/index.js +1 -1
- 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/package.json +180 -100
- package/dist/chunk-5KF3QQWZ.js.map +0 -1
- package/dist/chunk-ABNCAPQB.js.map +0 -1
- package/dist/chunk-CLMFEKYM.js.map +0 -1
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import { FlightChunk, ServerComponentChunk, ClientReferenceChunk } from './payload.js';
|
|
2
|
+
import { ServerContext } from './context.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @flight-framework/core - Server Component Renderer
|
|
6
|
+
*
|
|
7
|
+
* Renders Server Components to FlightChunks.
|
|
8
|
+
* Framework-agnostic rendering engine that works with adapters.
|
|
9
|
+
*
|
|
10
|
+
* @module @flight-framework/core/rsc/renderer
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* UI Framework adapter for rendering
|
|
15
|
+
*/
|
|
16
|
+
interface UIAdapter {
|
|
17
|
+
/** Adapter name */
|
|
18
|
+
name: string;
|
|
19
|
+
/** Check if value is a framework element */
|
|
20
|
+
isElement(value: unknown): boolean;
|
|
21
|
+
/** Get element type info */
|
|
22
|
+
getElementType(element: unknown): ElementTypeInfo;
|
|
23
|
+
/** Get element props */
|
|
24
|
+
getProps(element: unknown): Record<string, unknown>;
|
|
25
|
+
/** Get element children */
|
|
26
|
+
getChildren(element: unknown): unknown[];
|
|
27
|
+
/** Get element key */
|
|
28
|
+
getKey(element: unknown): string | number | undefined;
|
|
29
|
+
/** Check if component is a client boundary */
|
|
30
|
+
isClientBoundary(component: unknown): boolean;
|
|
31
|
+
/** Render element to HTML string (for SSR fallback) */
|
|
32
|
+
renderToString?(element: unknown): Promise<string>;
|
|
33
|
+
}
|
|
34
|
+
type ElementTypeInfo = {
|
|
35
|
+
kind: 'host';
|
|
36
|
+
tag: string;
|
|
37
|
+
} | {
|
|
38
|
+
kind: 'component';
|
|
39
|
+
fn: ComponentFn;
|
|
40
|
+
name: string;
|
|
41
|
+
} | {
|
|
42
|
+
kind: 'fragment';
|
|
43
|
+
} | {
|
|
44
|
+
kind: 'suspense';
|
|
45
|
+
fallback?: unknown;
|
|
46
|
+
} | {
|
|
47
|
+
kind: 'provider';
|
|
48
|
+
value?: unknown;
|
|
49
|
+
} | {
|
|
50
|
+
kind: 'context';
|
|
51
|
+
} | {
|
|
52
|
+
kind: 'text';
|
|
53
|
+
value: string;
|
|
54
|
+
} | {
|
|
55
|
+
kind: 'null';
|
|
56
|
+
};
|
|
57
|
+
/**
|
|
58
|
+
* Component function type
|
|
59
|
+
*/
|
|
60
|
+
type ComponentFn = (props: Record<string, unknown>, ctx?: ServerContext) => unknown | Promise<unknown>;
|
|
61
|
+
/**
|
|
62
|
+
* Render options
|
|
63
|
+
*/
|
|
64
|
+
interface RenderOptions {
|
|
65
|
+
/** Include SSR fallbacks for client components */
|
|
66
|
+
includeSSRFallbacks?: boolean;
|
|
67
|
+
/** Error handler */
|
|
68
|
+
onError?: (error: Error, componentName?: string) => void;
|
|
69
|
+
/** Dev mode (include extra debug info) */
|
|
70
|
+
dev?: boolean;
|
|
71
|
+
/** Max render depth to prevent infinite loops */
|
|
72
|
+
maxDepth?: number;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Render result with metadata
|
|
76
|
+
*/
|
|
77
|
+
interface RenderResult {
|
|
78
|
+
/** All chunks generated */
|
|
79
|
+
chunks: FlightChunk[];
|
|
80
|
+
/** Root chunk */
|
|
81
|
+
root: ServerComponentChunk;
|
|
82
|
+
/** Client references found */
|
|
83
|
+
clientRefs: ClientReferenceChunk[];
|
|
84
|
+
/** Timing info */
|
|
85
|
+
timing: {
|
|
86
|
+
startTime: number;
|
|
87
|
+
endTime: number;
|
|
88
|
+
duration: number;
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Flight Server Component Renderer
|
|
93
|
+
*/
|
|
94
|
+
declare class FlightRenderer {
|
|
95
|
+
private adapter;
|
|
96
|
+
private options;
|
|
97
|
+
private chunks;
|
|
98
|
+
private clientRefs;
|
|
99
|
+
private pendingPromises;
|
|
100
|
+
private depth;
|
|
101
|
+
constructor(adapter: UIAdapter, options?: RenderOptions);
|
|
102
|
+
/**
|
|
103
|
+
* Render a component tree to Flight chunks
|
|
104
|
+
*/
|
|
105
|
+
render(element: unknown, ctx: ServerContext): Promise<RenderResult>;
|
|
106
|
+
/**
|
|
107
|
+
* Render as async generator (for streaming)
|
|
108
|
+
*/
|
|
109
|
+
renderStreaming(element: unknown, ctx: ServerContext): AsyncGenerator<FlightChunk>;
|
|
110
|
+
/**
|
|
111
|
+
* Render an element to FlightElement
|
|
112
|
+
*/
|
|
113
|
+
private renderElement;
|
|
114
|
+
/**
|
|
115
|
+
* Render a framework-specific element
|
|
116
|
+
*/
|
|
117
|
+
private renderFrameworkElement;
|
|
118
|
+
/**
|
|
119
|
+
* Render a host element (div, span, etc.)
|
|
120
|
+
*/
|
|
121
|
+
private renderHostElement;
|
|
122
|
+
/**
|
|
123
|
+
* Render a component (server or client)
|
|
124
|
+
*/
|
|
125
|
+
private renderComponent;
|
|
126
|
+
/**
|
|
127
|
+
* Render a client boundary
|
|
128
|
+
*/
|
|
129
|
+
private renderClientBoundary;
|
|
130
|
+
/**
|
|
131
|
+
* Render a Suspense boundary
|
|
132
|
+
*/
|
|
133
|
+
private renderSuspense;
|
|
134
|
+
/**
|
|
135
|
+
* Render an async boundary (promise thrown from component)
|
|
136
|
+
*/
|
|
137
|
+
private renderAsyncBoundary;
|
|
138
|
+
/**
|
|
139
|
+
* Render a Client Reference directly
|
|
140
|
+
*/
|
|
141
|
+
private renderClientReference;
|
|
142
|
+
/**
|
|
143
|
+
* Resolve all pending async chunks
|
|
144
|
+
*/
|
|
145
|
+
private resolvePendingChunks;
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Create a renderer with adapter
|
|
149
|
+
*/
|
|
150
|
+
declare function createRenderer(adapter: UIAdapter, options?: RenderOptions): FlightRenderer;
|
|
151
|
+
/**
|
|
152
|
+
* Render a server component tree
|
|
153
|
+
*/
|
|
154
|
+
declare function renderServerComponent<P>(component: ComponentFn, props: P, ctx: ServerContext, adapter: UIAdapter, options?: RenderOptions): Promise<RenderResult>;
|
|
155
|
+
/**
|
|
156
|
+
* Render server component as streaming chunks
|
|
157
|
+
*/
|
|
158
|
+
declare function renderServerComponentStreaming<P>(component: ComponentFn, props: P, ctx: ServerContext, adapter: UIAdapter, options?: RenderOptions): AsyncGenerator<FlightChunk>;
|
|
159
|
+
|
|
160
|
+
export { type ComponentFn, type ElementTypeInfo, FlightRenderer, type RenderOptions, type RenderResult, type UIAdapter, createRenderer, renderServerComponent, renderServerComponentStreaming };
|
|
@@ -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
|
+
* @flight-framework/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 @flight-framework/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-T3S5YC7L.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
|
+
* @flight-framework/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 @flight-framework/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 '@flight-framework/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,223 @@
|
|
|
1
|
+
import { StreamingRenderOptions, StreamingRenderResult } from '../index.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @flight-framework/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"}
|