@flight-framework/core 0.1.0 → 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-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-YIOQC3DC.js → chunk-6BDCTUQY.js} +3 -3
- package/dist/{chunk-YIOQC3DC.js.map → chunk-6BDCTUQY.js.map} +1 -1
- 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-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-6WSPUG5L.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-OBNYNJB5.js → chunk-WOEIJWGJ.js} +6 -8
- package/dist/chunk-WOEIJWGJ.js.map +1 -0
- package/dist/{chunk-I2B4WSHC.js → chunk-XSY5AAXT.js} +3 -4
- 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/streaming-hints.d.ts +1 -1
- package/dist/file-router/streaming-hints.js +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +19 -7
- package/dist/index.js.map +1 -1
- 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/index.js +1 -1
- package/dist/streaming/observability.js +2 -2
- package/dist/streaming/priority.js +1 -1
- package/package.json +180 -124
- package/dist/chunk-5KF3QQWZ.js.map +0 -1
- package/dist/chunk-6WSPUG5L.js.map +0 -1
- package/dist/chunk-I2B4WSHC.js.map +0 -1
- package/dist/chunk-OBNYNJB5.js.map +0 -1
|
@@ -0,0 +1,341 @@
|
|
|
1
|
+
import { analyzeModule, hasUseClientDirective, hasUseServerDirective, detectInlineServerActions } from './chunk-CLZSB5QD.js';
|
|
2
|
+
|
|
3
|
+
// src/rsc/vite-plugin.ts
|
|
4
|
+
function flightRSC(options = {}) {
|
|
5
|
+
const {
|
|
6
|
+
include = ["**/*.tsx", "**/*.ts", "**/*.jsx", "**/*.js"],
|
|
7
|
+
exclude = ["**/node_modules/**", "**/.git/**"],
|
|
8
|
+
actionsEndpoint = "/_flight/action",
|
|
9
|
+
clientManifest = ".flight/client-manifest.json",
|
|
10
|
+
serverManifest = ".flight/server-manifest.json",
|
|
11
|
+
dev = false
|
|
12
|
+
} = options;
|
|
13
|
+
const clientModules = /* @__PURE__ */ new Map();
|
|
14
|
+
const serverActions = /* @__PURE__ */ new Map();
|
|
15
|
+
let config;
|
|
16
|
+
let isSSR = false;
|
|
17
|
+
return [
|
|
18
|
+
// ================================================================
|
|
19
|
+
// 1. Analyze modules and track boundaries
|
|
20
|
+
// ================================================================
|
|
21
|
+
{
|
|
22
|
+
name: "flight-rsc:analyze",
|
|
23
|
+
enforce: "pre",
|
|
24
|
+
configResolved(resolvedConfig) {
|
|
25
|
+
config = resolvedConfig;
|
|
26
|
+
},
|
|
27
|
+
transform(code, id) {
|
|
28
|
+
if (!shouldProcess(id, include, exclude)) {
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
const analysis = analyzeModule(code, id);
|
|
32
|
+
if (analysis.fileDirective === "client") {
|
|
33
|
+
clientModules.set(id, {
|
|
34
|
+
id: createModuleId(id, config),
|
|
35
|
+
file: id,
|
|
36
|
+
exports: analysis.clientComponents
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
if (analysis.fileDirective === "server" || analysis.serverActions.length > 0) {
|
|
40
|
+
serverActions.set(id, {
|
|
41
|
+
id: createModuleId(id, config),
|
|
42
|
+
file: id,
|
|
43
|
+
actions: analysis.serverActions
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
// ================================================================
|
|
50
|
+
// 2. Transform client components to references (server bundle)
|
|
51
|
+
// ================================================================
|
|
52
|
+
{
|
|
53
|
+
name: "flight-rsc:client-transform",
|
|
54
|
+
transform(code, id, opts) {
|
|
55
|
+
isSSR = opts?.ssr ?? false;
|
|
56
|
+
if (!isSSR) return null;
|
|
57
|
+
if (!hasUseClientDirective(code)) return null;
|
|
58
|
+
if (!shouldProcess(id, include, exclude)) return null;
|
|
59
|
+
if (options.transforms?.client) {
|
|
60
|
+
const result = options.transforms.client(code, id);
|
|
61
|
+
if (result) return result;
|
|
62
|
+
}
|
|
63
|
+
const moduleId = createModuleId(id, config);
|
|
64
|
+
const exports$1 = extractExportNames(code);
|
|
65
|
+
let transformed = `
|
|
66
|
+
// Flight RSC: Client Component Reference
|
|
67
|
+
// Original: ${id}
|
|
68
|
+
|
|
69
|
+
const __flight_client_module_id = ${JSON.stringify(moduleId)};
|
|
70
|
+
|
|
71
|
+
`;
|
|
72
|
+
for (const exportName of exports$1) {
|
|
73
|
+
if (exportName === "default") {
|
|
74
|
+
transformed += `
|
|
75
|
+
const __flight_default_proxy = Object.assign(
|
|
76
|
+
function() {
|
|
77
|
+
throw new Error('Client Component cannot be called on the server. Module: ' + __flight_client_module_id);
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
$$typeof: Symbol.for('flight.client.reference'),
|
|
81
|
+
$$id: __flight_client_module_id + '#default',
|
|
82
|
+
$$async: false,
|
|
83
|
+
__flight_client: true,
|
|
84
|
+
__flight_module: __flight_client_module_id,
|
|
85
|
+
__flight_export: 'default',
|
|
86
|
+
}
|
|
87
|
+
);
|
|
88
|
+
|
|
89
|
+
export default __flight_default_proxy;
|
|
90
|
+
`;
|
|
91
|
+
} else {
|
|
92
|
+
transformed += `
|
|
93
|
+
export const ${exportName} = Object.assign(
|
|
94
|
+
function() {
|
|
95
|
+
throw new Error('Client Component cannot be called on the server. Module: ' + __flight_client_module_id);
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
$$typeof: Symbol.for('flight.client.reference'),
|
|
99
|
+
$$id: __flight_client_module_id + '#${exportName}',
|
|
100
|
+
$$async: false,
|
|
101
|
+
__flight_client: true,
|
|
102
|
+
__flight_module: __flight_client_module_id,
|
|
103
|
+
__flight_export: '${exportName}',
|
|
104
|
+
}
|
|
105
|
+
);
|
|
106
|
+
`;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
return {
|
|
110
|
+
code: transformed,
|
|
111
|
+
map: null
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
},
|
|
115
|
+
// ================================================================
|
|
116
|
+
// 3. Transform server actions to RPC calls (client bundle)
|
|
117
|
+
// ================================================================
|
|
118
|
+
{
|
|
119
|
+
name: "flight-rsc:server-transform",
|
|
120
|
+
transform(code, id, opts) {
|
|
121
|
+
isSSR = opts?.ssr ?? false;
|
|
122
|
+
if (isSSR) return null;
|
|
123
|
+
if (!shouldProcess(id, include, exclude)) return null;
|
|
124
|
+
if (hasUseServerDirective(code)) {
|
|
125
|
+
if (options.transforms?.server) {
|
|
126
|
+
const result = options.transforms.server(code, id);
|
|
127
|
+
if (result) return result;
|
|
128
|
+
}
|
|
129
|
+
const moduleId = createModuleId(id, config);
|
|
130
|
+
const exports$1 = extractExportNames(code);
|
|
131
|
+
let transformed = `
|
|
132
|
+
// Flight RSC: Server Actions (RPC Proxies)
|
|
133
|
+
// Original: ${id}
|
|
134
|
+
|
|
135
|
+
const __flight_actions_endpoint = ${JSON.stringify(actionsEndpoint)};
|
|
136
|
+
const __flight_module_id = ${JSON.stringify(moduleId)};
|
|
137
|
+
|
|
138
|
+
async function __flight_call_action(actionId, args) {
|
|
139
|
+
const response = await fetch(__flight_actions_endpoint, {
|
|
140
|
+
method: 'POST',
|
|
141
|
+
headers: {
|
|
142
|
+
'Content-Type': 'application/json',
|
|
143
|
+
'X-Flight-Action': actionId,
|
|
144
|
+
},
|
|
145
|
+
body: JSON.stringify({ actionId, args }),
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
if (!response.ok) {
|
|
149
|
+
const error = await response.json().catch(() => ({ message: 'Server action failed' }));
|
|
150
|
+
throw new Error(error.message || 'Server action failed');
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
return response.json();
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
`;
|
|
157
|
+
for (const exportName of exports$1) {
|
|
158
|
+
const actionId = `${moduleId}#${exportName}`;
|
|
159
|
+
if (exportName === "default") {
|
|
160
|
+
transformed += `
|
|
161
|
+
export default async function(...args) {
|
|
162
|
+
return __flight_call_action(${JSON.stringify(actionId)}, args);
|
|
163
|
+
}
|
|
164
|
+
`;
|
|
165
|
+
} else {
|
|
166
|
+
transformed += `
|
|
167
|
+
export async function ${exportName}(...args) {
|
|
168
|
+
return __flight_call_action(${JSON.stringify(actionId)}, args);
|
|
169
|
+
}
|
|
170
|
+
`;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
return {
|
|
174
|
+
code: transformed,
|
|
175
|
+
map: null
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
const inlineActions = detectInlineServerActions(code);
|
|
179
|
+
if (inlineActions.length > 0) {
|
|
180
|
+
let transformed = code;
|
|
181
|
+
const moduleId = createModuleId(id, config);
|
|
182
|
+
for (const actionName of inlineActions) {
|
|
183
|
+
const actionId = `${moduleId}#${actionName}`;
|
|
184
|
+
const asyncFnPattern = new RegExp(
|
|
185
|
+
`(async\\s+function\\s+${actionName}\\s*\\([^)]*\\)\\s*\\{[^}]*['"]use server['"][^}]*\\})`,
|
|
186
|
+
"g"
|
|
187
|
+
);
|
|
188
|
+
transformed = transformed.replace(
|
|
189
|
+
asyncFnPattern,
|
|
190
|
+
`
|
|
191
|
+
async function ${actionName}(...args) {
|
|
192
|
+
const response = await fetch(${JSON.stringify(actionsEndpoint)}, {
|
|
193
|
+
method: 'POST',
|
|
194
|
+
headers: {
|
|
195
|
+
'Content-Type': 'application/json',
|
|
196
|
+
'X-Flight-Action': ${JSON.stringify(actionId)},
|
|
197
|
+
},
|
|
198
|
+
body: JSON.stringify({ actionId: ${JSON.stringify(actionId)}, args }),
|
|
199
|
+
});
|
|
200
|
+
if (!response.ok) throw new Error('Server action failed');
|
|
201
|
+
return response.json();
|
|
202
|
+
}`
|
|
203
|
+
);
|
|
204
|
+
}
|
|
205
|
+
if (transformed !== code) {
|
|
206
|
+
return {
|
|
207
|
+
code: transformed,
|
|
208
|
+
map: null
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
return null;
|
|
213
|
+
}
|
|
214
|
+
},
|
|
215
|
+
// ================================================================
|
|
216
|
+
// 4. Generate manifests
|
|
217
|
+
// ================================================================
|
|
218
|
+
{
|
|
219
|
+
name: "flight-rsc:manifest",
|
|
220
|
+
generateBundle() {
|
|
221
|
+
if (clientModules.size > 0) {
|
|
222
|
+
const manifest = Object.fromEntries(clientModules);
|
|
223
|
+
this.emitFile({
|
|
224
|
+
type: "asset",
|
|
225
|
+
fileName: clientManifest,
|
|
226
|
+
source: JSON.stringify(manifest, null, 2)
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
if (serverActions.size > 0) {
|
|
230
|
+
const manifest = Object.fromEntries(serverActions);
|
|
231
|
+
this.emitFile({
|
|
232
|
+
type: "asset",
|
|
233
|
+
fileName: serverManifest,
|
|
234
|
+
source: JSON.stringify(manifest, null, 2)
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
},
|
|
239
|
+
// ================================================================
|
|
240
|
+
// 5. Dev server middleware for server actions
|
|
241
|
+
// ================================================================
|
|
242
|
+
{
|
|
243
|
+
name: "flight-rsc:dev-server",
|
|
244
|
+
apply: "serve",
|
|
245
|
+
configureServer(server) {
|
|
246
|
+
server.middlewares.use(async (req, res, next) => {
|
|
247
|
+
if (req.url?.startsWith(actionsEndpoint) && req.method === "POST") {
|
|
248
|
+
try {
|
|
249
|
+
const chunks = [];
|
|
250
|
+
for await (const chunk of req) {
|
|
251
|
+
chunks.push(chunk);
|
|
252
|
+
}
|
|
253
|
+
const body = JSON.parse(Buffer.concat(chunks).toString());
|
|
254
|
+
const { actionId, args } = body;
|
|
255
|
+
const [moduleId, actionName] = actionId.split("#");
|
|
256
|
+
const entry = [...serverActions.values()].find((e) => e.id === moduleId);
|
|
257
|
+
if (!entry) {
|
|
258
|
+
res.statusCode = 404;
|
|
259
|
+
res.end(JSON.stringify({ error: "Action not found" }));
|
|
260
|
+
return;
|
|
261
|
+
}
|
|
262
|
+
const mod = await server.ssrLoadModule(entry.file);
|
|
263
|
+
const action = mod[actionName] || mod.default;
|
|
264
|
+
if (typeof action !== "function") {
|
|
265
|
+
res.statusCode = 404;
|
|
266
|
+
res.end(JSON.stringify({ error: "Action not found" }));
|
|
267
|
+
return;
|
|
268
|
+
}
|
|
269
|
+
const result = await action(...args);
|
|
270
|
+
res.setHeader("Content-Type", "application/json");
|
|
271
|
+
res.end(JSON.stringify(result));
|
|
272
|
+
} catch (error) {
|
|
273
|
+
console.error("[Flight RSC] Action error:", error);
|
|
274
|
+
res.statusCode = 500;
|
|
275
|
+
res.end(JSON.stringify({
|
|
276
|
+
error: error.message
|
|
277
|
+
}));
|
|
278
|
+
}
|
|
279
|
+
return;
|
|
280
|
+
}
|
|
281
|
+
next();
|
|
282
|
+
});
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
];
|
|
286
|
+
}
|
|
287
|
+
function shouldProcess(id, include, exclude) {
|
|
288
|
+
const isIncluded = include.some((pattern) => {
|
|
289
|
+
const regex = globToRegex(pattern);
|
|
290
|
+
return regex.test(id);
|
|
291
|
+
});
|
|
292
|
+
const isExcluded = exclude.some((pattern) => {
|
|
293
|
+
const regex = globToRegex(pattern);
|
|
294
|
+
return regex.test(id);
|
|
295
|
+
});
|
|
296
|
+
return isIncluded && !isExcluded;
|
|
297
|
+
}
|
|
298
|
+
function globToRegex(pattern) {
|
|
299
|
+
const escaped = pattern.replace(/[.+^${}()|[\]\\]/g, "\\$&").replace(/\*\*/g, "{{GLOBSTAR}}").replace(/\*/g, "[^/]*").replace(/{{GLOBSTAR}}/g, ".*");
|
|
300
|
+
return new RegExp(escaped);
|
|
301
|
+
}
|
|
302
|
+
function createModuleId(id, config) {
|
|
303
|
+
let moduleId = id;
|
|
304
|
+
if (config?.root && id.startsWith(config.root)) {
|
|
305
|
+
moduleId = id.slice(config.root.length);
|
|
306
|
+
}
|
|
307
|
+
moduleId = moduleId.replace(/\\/g, "/");
|
|
308
|
+
if (!moduleId.startsWith("/")) {
|
|
309
|
+
moduleId = "/" + moduleId;
|
|
310
|
+
}
|
|
311
|
+
return moduleId;
|
|
312
|
+
}
|
|
313
|
+
function extractExportNames(code) {
|
|
314
|
+
const exports$1 = [];
|
|
315
|
+
if (/export\s+default\s+/.test(code)) {
|
|
316
|
+
exports$1.push("default");
|
|
317
|
+
}
|
|
318
|
+
const namedPattern = /export\s+(?:async\s+)?(?:function|const|let|var|class)\s+(\w+)/g;
|
|
319
|
+
let match;
|
|
320
|
+
while ((match = namedPattern.exec(code)) !== null) {
|
|
321
|
+
if (match[1] && match[1] !== "default") {
|
|
322
|
+
exports$1.push(match[1]);
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
const bracketPattern = /export\s*\{\s*([^}]+)\s*\}/g;
|
|
326
|
+
while ((match = bracketPattern.exec(code)) !== null) {
|
|
327
|
+
if (match[1]) {
|
|
328
|
+
const names = match[1].split(",").map((n) => {
|
|
329
|
+
const parts = n.trim().split(/\s+as\s+/);
|
|
330
|
+
return parts[parts.length - 1].trim();
|
|
331
|
+
});
|
|
332
|
+
exports$1.push(...names.filter((n) => n && n !== "default"));
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
return [...new Set(exports$1)];
|
|
336
|
+
}
|
|
337
|
+
var vite_plugin_default = flightRSC;
|
|
338
|
+
|
|
339
|
+
export { flightRSC, vite_plugin_default };
|
|
340
|
+
//# sourceMappingURL=chunk-MRLCNFSD.js.map
|
|
341
|
+
//# sourceMappingURL=chunk-MRLCNFSD.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/rsc/vite-plugin.ts"],"names":["exports"],"mappings":";;;AAkGO,SAAS,SAAA,CAAU,OAAA,GAAkC,EAAC,EAAa;AACtE,EAAA,MAAM;AAAA,IACF,OAAA,GAAU,CAAC,UAAA,EAAY,SAAA,EAAW,YAAY,SAAS,CAAA;AAAA,IACvD,OAAA,GAAU,CAAC,oBAAA,EAAsB,YAAY,CAAA;AAAA,IAC7C,eAAA,GAAkB,iBAAA;AAAA,IAClB,cAAA,GAAiB,8BAAA;AAAA,IACjB,cAAA,GAAiB,8BAAA;AA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AAE,IAAA,EAAK,CAAE,MAAM,UAAU,CAAA;AACvC,QAAA,OAAO,KAAA,CAAM,KAAA,CAAM,MAAA,GAAS,CAAC,EAAG,IAAA,EAAK;AAAA,MACzC,CAAC,CAAA;AACD,MAAAA,SAAA,CAAQ,IAAA,CAAK,GAAG,KAAA,CAAM,MAAA,CAAO,OAAK,CAAA,IAAK,CAAA,KAAM,SAAS,CAAC,CAAA;AAAA,IAC3D;AAAA,EACJ;AAEA,EAAA,OAAO,CAAC,GAAG,IAAI,GAAA,CAAIA,SAAO,CAAC,CAAA;AAC/B;AAEA,IAAO,mBAAA,GAAQ","file":"chunk-MRLCNFSD.js","sourcesContent":["/**\r\n * @flight-framework/vite-plugin-rsc\r\n * \r\n * Vite plugin for Flight Server Components.\r\n * Transforms 'use client' and 'use server' directives at build time.\r\n * \r\n * Philosophy:\r\n * - Zero config for common cases\r\n * - Full control when needed\r\n * - Works with any Vite project\r\n * - No Next.js dependencies\r\n * \r\n * @module @flight-framework/vite-plugin-rsc\r\n */\r\n\r\nimport type { Plugin, ResolvedConfig } from 'vite';\r\nimport {\r\n analyzeModule,\r\n hasUseClientDirective,\r\n hasUseServerDirective,\r\n detectInlineServerActions,\r\n} from './boundaries.js';\r\n\r\n// ============================================================================\r\n// Types\r\n// ============================================================================\r\n\r\n/**\r\n * Plugin configuration\r\n */\r\nexport interface FlightRSCPluginOptions {\r\n /** Include patterns (glob) */\r\n include?: string[];\r\n\r\n /** Exclude patterns (glob) */\r\n exclude?: string[];\r\n\r\n /** Server actions endpoint */\r\n actionsEndpoint?: string;\r\n\r\n /** Client manifest output path */\r\n clientManifest?: string;\r\n\r\n /** Server manifest output path */\r\n serverManifest?: string;\r\n\r\n /** Enable dev mode features */\r\n dev?: boolean;\r\n\r\n /** Custom transforms */\r\n transforms?: {\r\n /** Transform client components */\r\n client?: (code: string, id: string) => string | null;\r\n /** Transform server actions */\r\n server?: (code: string, id: string) => string | null;\r\n };\r\n}\r\n\r\n/**\r\n * Client manifest entry\r\n */\r\nexport interface ClientManifestEntry {\r\n id: string;\r\n file: string;\r\n exports: string[];\r\n chunks?: string[];\r\n}\r\n\r\n/**\r\n * Server manifest entry\r\n */\r\nexport interface ServerManifestEntry {\r\n id: string;\r\n file: string;\r\n actions: string[];\r\n}\r\n\r\n// ============================================================================\r\n// Plugin Implementation\r\n// ============================================================================\r\n\r\n/**\r\n * Flight RSC Vite Plugin\r\n * \r\n * @example\r\n * ```typescript\r\n * // vite.config.ts\r\n * import { flightRSC } from '@flight-framework/core/rsc/vite-plugin';\r\n * \r\n * export default defineConfig({\r\n * plugins: [\r\n * flightRSC({\r\n * actionsEndpoint: '/_flight/action',\r\n * }),\r\n * ],\r\n * });\r\n * ```\r\n */\r\nexport function flightRSC(options: FlightRSCPluginOptions = {}): Plugin[] {\r\n const {\r\n include = ['**/*.tsx', '**/*.ts', '**/*.jsx', '**/*.js'],\r\n exclude = ['**/node_modules/**', '**/.git/**'],\r\n actionsEndpoint = '/_flight/action',\r\n clientManifest = '.flight/client-manifest.json',\r\n serverManifest = '.flight/server-manifest.json',\r\n dev = false,\r\n } = options;\r\n\r\n // State\r\n const clientModules = new Map<string, ClientManifestEntry>();\r\n const serverActions = new Map<string, ServerManifestEntry>();\r\n let config: ResolvedConfig;\r\n let isSSR = false;\r\n\r\n return [\r\n // ================================================================\r\n // 1. Analyze modules and track boundaries\r\n // ================================================================\r\n {\r\n name: 'flight-rsc:analyze',\r\n enforce: 'pre',\r\n\r\n configResolved(resolvedConfig) {\r\n config = resolvedConfig;\r\n },\r\n\r\n transform(code, id) {\r\n // Skip excluded files\r\n if (!shouldProcess(id, include, exclude)) {\r\n return null;\r\n }\r\n\r\n // Analyze module\r\n const analysis = analyzeModule(code, id);\r\n\r\n // Track client modules\r\n if (analysis.fileDirective === 'client') {\r\n clientModules.set(id, {\r\n id: createModuleId(id, config),\r\n file: id,\r\n exports: analysis.clientComponents,\r\n });\r\n }\r\n\r\n // Track server actions\r\n if (analysis.fileDirective === 'server' || analysis.serverActions.length > 0) {\r\n serverActions.set(id, {\r\n id: createModuleId(id, config),\r\n file: id,\r\n actions: analysis.serverActions,\r\n });\r\n }\r\n\r\n return null;\r\n },\r\n },\r\n\r\n // ================================================================\r\n // 2. Transform client components to references (server bundle)\r\n // ================================================================\r\n {\r\n name: 'flight-rsc:client-transform',\r\n\r\n transform(code, id, opts) {\r\n isSSR = opts?.ssr ?? false;\r\n\r\n if (!isSSR) return null;\r\n if (!hasUseClientDirective(code)) return null;\r\n if (!shouldProcess(id, include, exclude)) return null;\r\n\r\n // Custom transform\r\n if (options.transforms?.client) {\r\n const result = options.transforms.client(code, id);\r\n if (result) return result;\r\n }\r\n\r\n // Replace client component with reference proxy\r\n const moduleId = createModuleId(id, config);\r\n const exports = extractExportNames(code);\r\n\r\n let transformed = `\r\n// Flight RSC: Client Component Reference\r\n// Original: ${id}\r\n\r\nconst __flight_client_module_id = ${JSON.stringify(moduleId)};\r\n\r\n`;\r\n\r\n // Create proxy for each export\r\n for (const exportName of exports) {\r\n if (exportName === 'default') {\r\n transformed += `\r\nconst __flight_default_proxy = Object.assign(\r\n function() {\r\n throw new Error('Client Component cannot be called on the server. Module: ' + __flight_client_module_id);\r\n },\r\n {\r\n $$typeof: Symbol.for('flight.client.reference'),\r\n $$id: __flight_client_module_id + '#default',\r\n $$async: false,\r\n __flight_client: true,\r\n __flight_module: __flight_client_module_id,\r\n __flight_export: 'default',\r\n }\r\n);\r\n\r\nexport default __flight_default_proxy;\r\n`;\r\n } else {\r\n transformed += `\r\nexport const ${exportName} = Object.assign(\r\n function() {\r\n throw new Error('Client Component cannot be called on the server. Module: ' + __flight_client_module_id);\r\n },\r\n {\r\n $$typeof: Symbol.for('flight.client.reference'),\r\n $$id: __flight_client_module_id + '#${exportName}',\r\n $$async: false,\r\n __flight_client: true,\r\n __flight_module: __flight_client_module_id,\r\n __flight_export: '${exportName}',\r\n }\r\n);\r\n`;\r\n }\r\n }\r\n\r\n return {\r\n code: transformed,\r\n map: null,\r\n };\r\n },\r\n },\r\n\r\n // ================================================================\r\n // 3. Transform server actions to RPC calls (client bundle)\r\n // ================================================================\r\n {\r\n name: 'flight-rsc:server-transform',\r\n\r\n transform(code, id, opts) {\r\n isSSR = opts?.ssr ?? false;\r\n\r\n if (isSSR) return null; // Only transform for client\r\n if (!shouldProcess(id, include, exclude)) return null;\r\n\r\n // Check for file-level 'use server'\r\n if (hasUseServerDirective(code)) {\r\n // Custom transform\r\n if (options.transforms?.server) {\r\n const result = options.transforms.server(code, id);\r\n if (result) return result;\r\n }\r\n\r\n // Replace all exports with RPC calls\r\n const moduleId = createModuleId(id, config);\r\n const exports = extractExportNames(code);\r\n\r\n let transformed = `\r\n// Flight RSC: Server Actions (RPC Proxies)\r\n// Original: ${id}\r\n\r\nconst __flight_actions_endpoint = ${JSON.stringify(actionsEndpoint)};\r\nconst __flight_module_id = ${JSON.stringify(moduleId)};\r\n\r\nasync function __flight_call_action(actionId, args) {\r\n const response = await fetch(__flight_actions_endpoint, {\r\n method: 'POST',\r\n headers: {\r\n 'Content-Type': 'application/json',\r\n 'X-Flight-Action': actionId,\r\n },\r\n body: JSON.stringify({ actionId, args }),\r\n });\r\n \r\n if (!response.ok) {\r\n const error = await response.json().catch(() => ({ message: 'Server action failed' }));\r\n throw new Error(error.message || 'Server action failed');\r\n }\r\n \r\n return response.json();\r\n}\r\n\r\n`;\r\n\r\n for (const exportName of exports) {\r\n const actionId = `${moduleId}#${exportName}`;\r\n if (exportName === 'default') {\r\n transformed += `\r\nexport default async function(...args) {\r\n return __flight_call_action(${JSON.stringify(actionId)}, args);\r\n}\r\n`;\r\n } else {\r\n transformed += `\r\nexport async function ${exportName}(...args) {\r\n return __flight_call_action(${JSON.stringify(actionId)}, args);\r\n}\r\n`;\r\n }\r\n }\r\n\r\n return {\r\n code: transformed,\r\n map: null,\r\n };\r\n }\r\n\r\n // Check for inline 'use server' in functions\r\n const inlineActions = detectInlineServerActions(code);\r\n if (inlineActions.length > 0) {\r\n // Transform specific functions to RPC calls\r\n let transformed = code;\r\n const moduleId = createModuleId(id, config);\r\n\r\n for (const actionName of inlineActions) {\r\n const actionId = `${moduleId}#${actionName}`;\r\n\r\n // Replace function with RPC call\r\n // This is a simplified transform - a real implementation would use AST\r\n const asyncFnPattern = new RegExp(\r\n `(async\\\\s+function\\\\s+${actionName}\\\\s*\\\\([^)]*\\\\)\\\\s*\\\\{[^}]*['\"]use server['\"][^}]*\\\\})`,\r\n 'g'\r\n );\r\n\r\n transformed = transformed.replace(asyncFnPattern, `\r\nasync function ${actionName}(...args) {\r\n const response = await fetch(${JSON.stringify(actionsEndpoint)}, {\r\n method: 'POST',\r\n headers: {\r\n 'Content-Type': 'application/json',\r\n 'X-Flight-Action': ${JSON.stringify(actionId)},\r\n },\r\n body: JSON.stringify({ actionId: ${JSON.stringify(actionId)}, args }),\r\n });\r\n if (!response.ok) throw new Error('Server action failed');\r\n return response.json();\r\n}`\r\n );\r\n }\r\n\r\n if (transformed !== code) {\r\n return {\r\n code: transformed,\r\n map: null,\r\n };\r\n }\r\n }\r\n\r\n return null;\r\n },\r\n },\r\n\r\n // ================================================================\r\n // 4. Generate manifests\r\n // ================================================================\r\n {\r\n name: 'flight-rsc:manifest',\r\n\r\n generateBundle() {\r\n // Client manifest\r\n if (clientModules.size > 0) {\r\n const manifest = Object.fromEntries(clientModules);\r\n this.emitFile({\r\n type: 'asset',\r\n fileName: clientManifest,\r\n source: JSON.stringify(manifest, null, 2),\r\n });\r\n }\r\n\r\n // Server manifest\r\n if (serverActions.size > 0) {\r\n const manifest = Object.fromEntries(serverActions);\r\n this.emitFile({\r\n type: 'asset',\r\n fileName: serverManifest,\r\n source: JSON.stringify(manifest, null, 2),\r\n });\r\n }\r\n },\r\n },\r\n\r\n // ================================================================\r\n // 5. Dev server middleware for server actions\r\n // ================================================================\r\n {\r\n name: 'flight-rsc:dev-server',\r\n apply: 'serve',\r\n\r\n configureServer(server) {\r\n server.middlewares.use(async (req, res, next) => {\r\n if (req.url?.startsWith(actionsEndpoint) && req.method === 'POST') {\r\n try {\r\n // Parse request body\r\n const chunks: Buffer[] = [];\r\n for await (const chunk of req) {\r\n chunks.push(chunk as Buffer);\r\n }\r\n const body = JSON.parse(Buffer.concat(chunks).toString());\r\n\r\n const { actionId, args } = body;\r\n\r\n // Find and execute action\r\n const [moduleId, actionName] = actionId.split('#');\r\n const entry = [...serverActions.values()].find(e => e.id === moduleId);\r\n\r\n if (!entry) {\r\n res.statusCode = 404;\r\n res.end(JSON.stringify({ error: 'Action not found' }));\r\n return;\r\n }\r\n\r\n // Load module and execute action\r\n const mod = await server.ssrLoadModule(entry.file);\r\n const action = mod[actionName] || mod.default;\r\n\r\n if (typeof action !== 'function') {\r\n res.statusCode = 404;\r\n res.end(JSON.stringify({ error: 'Action not found' }));\r\n return;\r\n }\r\n\r\n const result = await action(...args);\r\n\r\n res.setHeader('Content-Type', 'application/json');\r\n res.end(JSON.stringify(result));\r\n\r\n } catch (error) {\r\n console.error('[Flight RSC] Action error:', error);\r\n res.statusCode = 500;\r\n res.end(JSON.stringify({\r\n error: (error as Error).message\r\n }));\r\n }\r\n return;\r\n }\r\n\r\n next();\r\n });\r\n },\r\n },\r\n ];\r\n}\r\n\r\n// ============================================================================\r\n// Helper Functions\r\n// ============================================================================\r\n\r\n/**\r\n * Check if file should be processed\r\n */\r\nfunction shouldProcess(id: string, include: string[], exclude: string[]): boolean {\r\n // Simple glob matching (for production, use picomatch)\r\n const isIncluded = include.some(pattern => {\r\n const regex = globToRegex(pattern);\r\n return regex.test(id);\r\n });\r\n\r\n const isExcluded = exclude.some(pattern => {\r\n const regex = globToRegex(pattern);\r\n return regex.test(id);\r\n });\r\n\r\n return isIncluded && !isExcluded;\r\n}\r\n\r\n/**\r\n * Convert glob pattern to regex (simplified)\r\n */\r\nfunction globToRegex(pattern: string): RegExp {\r\n const escaped = pattern\r\n .replace(/[.+^${}()|[\\]\\\\]/g, '\\\\$&')\r\n .replace(/\\*\\*/g, '{{GLOBSTAR}}')\r\n .replace(/\\*/g, '[^/]*')\r\n .replace(/{{GLOBSTAR}}/g, '.*');\r\n\r\n return new RegExp(escaped);\r\n}\r\n\r\n/**\r\n * Create a stable module ID from file path\r\n */\r\nfunction createModuleId(id: string, config: ResolvedConfig): string {\r\n // Remove root prefix\r\n let moduleId = id;\r\n if (config?.root && id.startsWith(config.root)) {\r\n moduleId = id.slice(config.root.length);\r\n }\r\n\r\n // Normalize path\r\n moduleId = moduleId.replace(/\\\\/g, '/');\r\n if (!moduleId.startsWith('/')) {\r\n moduleId = '/' + moduleId;\r\n }\r\n\r\n return moduleId;\r\n}\r\n\r\n/**\r\n * Extract export names from source code\r\n */\r\nfunction extractExportNames(code: string): string[] {\r\n const exports: string[] = [];\r\n\r\n // export default\r\n if (/export\\s+default\\s+/.test(code)) {\r\n exports.push('default');\r\n }\r\n\r\n // export function/const/let/class Name\r\n const namedPattern = /export\\s+(?:async\\s+)?(?:function|const|let|var|class)\\s+(\\w+)/g;\r\n let match;\r\n while ((match = namedPattern.exec(code)) !== null) {\r\n if (match[1] && match[1] !== 'default') {\r\n exports.push(match[1]);\r\n }\r\n }\r\n\r\n // export { a, b, c }\r\n const bracketPattern = /export\\s*\\{\\s*([^}]+)\\s*\\}/g;\r\n while ((match = bracketPattern.exec(code)) !== null) {\r\n if (match[1]) {\r\n const names = match[1].split(',').map(n => {\r\n const parts = n.trim().split(/\\s+as\\s+/);\r\n return parts[parts.length - 1]!.trim();\r\n });\r\n exports.push(...names.filter(n => n && n !== 'default'));\r\n }\r\n }\r\n\r\n return [...new Set(exports)];\r\n}\r\n\r\nexport default flightRSC;\r\n"]}
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
// src/rsc/adapters/react.ts
|
|
2
|
+
var REACT_ELEMENT_TYPE = /* @__PURE__ */ Symbol.for("react.element");
|
|
3
|
+
var REACT_FRAGMENT_TYPE = /* @__PURE__ */ Symbol.for("react.fragment");
|
|
4
|
+
var REACT_PROVIDER_TYPE = /* @__PURE__ */ Symbol.for("react.provider");
|
|
5
|
+
var REACT_CONTEXT_TYPE = /* @__PURE__ */ Symbol.for("react.context");
|
|
6
|
+
var REACT_FORWARD_REF_TYPE = /* @__PURE__ */ Symbol.for("react.forward_ref");
|
|
7
|
+
var REACT_SUSPENSE_TYPE = /* @__PURE__ */ Symbol.for("react.suspense");
|
|
8
|
+
var REACT_MEMO_TYPE = /* @__PURE__ */ Symbol.for("react.memo");
|
|
9
|
+
var REACT_LAZY_TYPE = /* @__PURE__ */ Symbol.for("react.lazy");
|
|
10
|
+
var CLIENT_REFERENCE = /* @__PURE__ */ Symbol.for("flight.client.reference");
|
|
11
|
+
function createReactAdapter(deps) {
|
|
12
|
+
const { React, renderToString } = deps || {};
|
|
13
|
+
return {
|
|
14
|
+
name: "react",
|
|
15
|
+
isElement(value) {
|
|
16
|
+
if (React) {
|
|
17
|
+
return React.isValidElement(value);
|
|
18
|
+
}
|
|
19
|
+
return typeof value === "object" && value !== null && "$$typeof" in value && value.$$typeof === REACT_ELEMENT_TYPE;
|
|
20
|
+
},
|
|
21
|
+
getElementType(element) {
|
|
22
|
+
const el = element;
|
|
23
|
+
const type = el.type;
|
|
24
|
+
if (typeof type === "string") {
|
|
25
|
+
return { kind: "host", tag: type };
|
|
26
|
+
}
|
|
27
|
+
if (typeof type === "symbol") {
|
|
28
|
+
if (type === REACT_FRAGMENT_TYPE || type === React?.Fragment) {
|
|
29
|
+
return { kind: "fragment" };
|
|
30
|
+
}
|
|
31
|
+
if (type === REACT_SUSPENSE_TYPE || React?.Suspense && type === React.Suspense) {
|
|
32
|
+
return {
|
|
33
|
+
kind: "suspense",
|
|
34
|
+
fallback: el.props.fallback
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
if (type === REACT_PROVIDER_TYPE) {
|
|
38
|
+
return { kind: "provider", value: el.props.value };
|
|
39
|
+
}
|
|
40
|
+
if (type === REACT_CONTEXT_TYPE) {
|
|
41
|
+
return { kind: "context" };
|
|
42
|
+
}
|
|
43
|
+
return { kind: "null" };
|
|
44
|
+
}
|
|
45
|
+
if (typeof type === "object" && type !== null) {
|
|
46
|
+
const typeObj = type;
|
|
47
|
+
if (typeObj.$$typeof === REACT_MEMO_TYPE) {
|
|
48
|
+
return this.getElementType({ ...el, type: typeObj.type });
|
|
49
|
+
}
|
|
50
|
+
if (typeObj.$$typeof === REACT_LAZY_TYPE) {
|
|
51
|
+
return { kind: "component", fn: () => null, name: "Lazy" };
|
|
52
|
+
}
|
|
53
|
+
if (typeObj.$$typeof === REACT_FORWARD_REF_TYPE && typeObj.render) {
|
|
54
|
+
return {
|
|
55
|
+
kind: "component",
|
|
56
|
+
fn: typeObj.render,
|
|
57
|
+
name: "ForwardRef"
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
if ("$$typeof" in typeObj && typeObj.$$typeof === REACT_SUSPENSE_TYPE) {
|
|
61
|
+
return { kind: "suspense", fallback: el.props.fallback };
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
if (typeof type === "function") {
|
|
65
|
+
const fn = type;
|
|
66
|
+
return {
|
|
67
|
+
kind: "component",
|
|
68
|
+
fn,
|
|
69
|
+
name: fn.displayName || fn.name || "Component"
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
return { kind: "null" };
|
|
73
|
+
},
|
|
74
|
+
getProps(element) {
|
|
75
|
+
return element.props || {};
|
|
76
|
+
},
|
|
77
|
+
getChildren(element) {
|
|
78
|
+
const props = element.props;
|
|
79
|
+
const children = props?.children;
|
|
80
|
+
if (children === void 0 || children === null) {
|
|
81
|
+
return [];
|
|
82
|
+
}
|
|
83
|
+
if (React?.Children) {
|
|
84
|
+
return React.Children.toArray(children);
|
|
85
|
+
}
|
|
86
|
+
if (Array.isArray(children)) {
|
|
87
|
+
return children.flat();
|
|
88
|
+
}
|
|
89
|
+
return [children];
|
|
90
|
+
},
|
|
91
|
+
getKey(element) {
|
|
92
|
+
const key = element.key;
|
|
93
|
+
return key !== null ? key : void 0;
|
|
94
|
+
},
|
|
95
|
+
isClientBoundary(component) {
|
|
96
|
+
if (typeof component !== "function") return false;
|
|
97
|
+
const comp = component;
|
|
98
|
+
if (comp.__flight_client === true) return true;
|
|
99
|
+
if (comp.$$typeof === CLIENT_REFERENCE) return true;
|
|
100
|
+
return false;
|
|
101
|
+
},
|
|
102
|
+
async renderToString(element) {
|
|
103
|
+
if (renderToString) {
|
|
104
|
+
return renderToString(element);
|
|
105
|
+
}
|
|
106
|
+
throw new Error(
|
|
107
|
+
"renderToString not provided. Pass it when creating the adapter: createReactAdapter({ renderToString })"
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
function createReactConsumer(deps, options = {}) {
|
|
113
|
+
const { React } = deps;
|
|
114
|
+
const { registry = /* @__PURE__ */ new Map() } = options;
|
|
115
|
+
return {
|
|
116
|
+
/**
|
|
117
|
+
* Register a client component
|
|
118
|
+
*/
|
|
119
|
+
register(id, loader) {
|
|
120
|
+
registry.set(id, loader);
|
|
121
|
+
},
|
|
122
|
+
/**
|
|
123
|
+
* Convert Flight elements to React elements
|
|
124
|
+
*/
|
|
125
|
+
toReactElement(element) {
|
|
126
|
+
switch (element.$$type) {
|
|
127
|
+
case "null":
|
|
128
|
+
return null;
|
|
129
|
+
case "text":
|
|
130
|
+
return element.value;
|
|
131
|
+
case "host": {
|
|
132
|
+
const children = element.children.map((c) => this.toReactElement(c));
|
|
133
|
+
return React.createElement(
|
|
134
|
+
element.tag,
|
|
135
|
+
{ ...element.props, key: element.key },
|
|
136
|
+
...children
|
|
137
|
+
);
|
|
138
|
+
}
|
|
139
|
+
case "fragment": {
|
|
140
|
+
const children = element.children.map((c) => this.toReactElement(c));
|
|
141
|
+
return React.createElement(React.Fragment, null, ...children);
|
|
142
|
+
}
|
|
143
|
+
case "suspense": {
|
|
144
|
+
const fallback = this.toReactElement(element.fallback);
|
|
145
|
+
const children = element.children.map((c) => this.toReactElement(c));
|
|
146
|
+
return React.createElement(
|
|
147
|
+
React.Suspense,
|
|
148
|
+
{ fallback },
|
|
149
|
+
...children
|
|
150
|
+
);
|
|
151
|
+
}
|
|
152
|
+
case "client": {
|
|
153
|
+
const loader = registry.get(element.ref);
|
|
154
|
+
if (!loader) {
|
|
155
|
+
console.warn(`[Flight] Client component not registered: ${element.ref}`);
|
|
156
|
+
if (element.ssr) {
|
|
157
|
+
return React.createElement("div", {
|
|
158
|
+
dangerouslySetInnerHTML: { __html: element.ssr }
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
return null;
|
|
162
|
+
}
|
|
163
|
+
const LazyComponent = React.lazy(async () => {
|
|
164
|
+
const mod = await loader();
|
|
165
|
+
return { default: mod.default ?? mod };
|
|
166
|
+
});
|
|
167
|
+
return React.createElement(LazyComponent);
|
|
168
|
+
}
|
|
169
|
+
case "lazy": {
|
|
170
|
+
if (element.fallback) {
|
|
171
|
+
return this.toReactElement(element.fallback);
|
|
172
|
+
}
|
|
173
|
+
return React.createElement("div", { "data-flight-pending": element.id });
|
|
174
|
+
}
|
|
175
|
+
default:
|
|
176
|
+
return null;
|
|
177
|
+
}
|
|
178
|
+
},
|
|
179
|
+
/**
|
|
180
|
+
* Process Flight chunks and build React tree
|
|
181
|
+
*/
|
|
182
|
+
processChunks(chunks) {
|
|
183
|
+
const rootChunk = chunks.find((c) => c.type === "S" && c.id === "root");
|
|
184
|
+
if (!rootChunk || rootChunk.type !== "S") {
|
|
185
|
+
throw new Error("[Flight] No root chunk found in payload");
|
|
186
|
+
}
|
|
187
|
+
for (const chunk of chunks) {
|
|
188
|
+
if (chunk.type === "C") {
|
|
189
|
+
if (!registry.has(chunk.id)) {
|
|
190
|
+
registry.set(chunk.id, () => import(
|
|
191
|
+
/* webpackIgnore: true */
|
|
192
|
+
chunk.module
|
|
193
|
+
));
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
return this.toReactElement(rootChunk.tree);
|
|
198
|
+
}
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
function markAsClientComponent(component, moduleId, exportName = "default") {
|
|
202
|
+
const marked = component;
|
|
203
|
+
marked.$$typeof = CLIENT_REFERENCE;
|
|
204
|
+
marked.__flight_client = true;
|
|
205
|
+
marked.__flight_module = moduleId;
|
|
206
|
+
marked.__flight_export = exportName;
|
|
207
|
+
return marked;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
export { createReactAdapter, createReactConsumer, markAsClientComponent };
|
|
211
|
+
//# sourceMappingURL=chunk-PSJPMEQK.js.map
|
|
212
|
+
//# sourceMappingURL=chunk-PSJPMEQK.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/rsc/adapters/react.ts"],"names":[],"mappings":";AAgBA,IAAM,kBAAA,mBAAqB,MAAA,CAAO,GAAA,CAAI,eAAe,CAAA;AAErD,IAAM,mBAAA,mBAAsB,MAAA,CAAO,GAAA,CAAI,gBAAgB,CAAA;AAGvD,IAAM,mBAAA,mBAAsB,MAAA,CAAO,GAAA,CAAI,gBAAgB,CAAA;AACvD,IAAM,kBAAA,mBAAqB,MAAA,CAAO,GAAA,CAAI,eAAe,CAAA;AACrD,IAAM,sBAAA,mBAAyB,MAAA,CAAO,GAAA,CAAI,mBAAmB,CAAA;AAC7D,IAAM,mBAAA,mBAAsB,MAAA,CAAO,GAAA,CAAI,gBAAgB,CAAA;AAEvD,IAAM,eAAA,mBAAkB,MAAA,CAAO,GAAA,CAAI,YAAY,CAAA;AAC/C,IAAM,eAAA,mBAAkB,MAAA,CAAO,GAAA,CAAI,YAAY,CAAA;AAG/C,IAAM,gBAAA,mBAAmB,MAAA,CAAO,GAAA,CAAI,yBAAyB,CAAA;AAgDtD,SAAS,mBAAmB,IAAA,EAUrB;AACV,EAAA,MAAM,EAAE,KAAA,EAAO,cAAA,EAAe,GAAI,QAAQ,EAAC;AAE3C,EAAA,OAAO;AAAA,IACH,IAAA,EAAM,OAAA;AAAA,IAEN,UAAU,KAAA,E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E,EAAA,KAAO,MAAM,CAAA;AACpE,MAAA,IAAI,CAAC,SAAA,IAAa,SAAA,CAAU,IAAA,KAAS,GAAA,EAAK;AACtC,QAAA,MAAM,IAAI,MAAM,yCAAyC,CAAA;AAAA,MAC7D;AAGA,MAAA,KAAA,MAAW,SAAS,MAAA,EAAQ;AACxB,QAAA,IAAI,KAAA,CAAM,SAAS,GAAA,EAAK;AAEpB,UAAA,IAAI,CAAC,QAAA,CAAS,GAAA,CAAI,KAAA,CAAM,EAAE,CAAA,EAAG;AACzB,YAAA,QAAA,CAAS,GAAA,CAAI,KAAA,CAAM,EAAA,EAAI,MAAM;AAAA;AAAA,cAAiC,KAAA,CAAM;AAAA,aAAO,CAAA;AAAA,UAC/E;AAAA,QACJ;AAAA,MACJ;AAEA,MAAA,OAAO,IAAA,CAAK,cAAA,CAAe,SAAA,CAAU,IAAI,CAAA;AAAA,IAC7C;AAAA,GACJ;AACJ;AAiBO,SAAS,qBAAA,CACZ,SAAA,EACA,QAAA,EACA,UAAA,GAAa,SAAA,EACZ;AACD,EAAA,MAAM,MAAA,GAAS,SAAA;AAOf,EAAA,MAAA,CAAO,QAAA,GAAW,gBAAA;AAClB,EAAA,MAAA,CAAO,eAAA,GAAkB,IAAA;AACzB,EAAA,MAAA,CAAO,eAAA,GAAkB,QAAA;AACzB,EAAA,MAAA,CAAO,eAAA,GAAkB,UAAA;AAEzB,EAAA,OAAO,MAAA;AACX","file":"chunk-PSJPMEQK.js","sourcesContent":["/**\r\n * @flight-framework/core - React UI Adapter\r\n * \r\n * Adapter for using React with Flight Server Components.\r\n * Enables Flight to render React elements without tight coupling.\r\n * \r\n * @module @flight-framework/core/rsc/adapters/react\r\n */\r\n\r\nimport type { UIAdapter, ElementTypeInfo } from '../renderer.js';\r\n\r\n// ============================================================================\r\n// React Symbols\r\n// ============================================================================\r\n\r\n// React internal symbols (stable across versions)\r\nconst REACT_ELEMENT_TYPE = Symbol.for('react.element');\r\nconst REACT_PORTAL_TYPE = Symbol.for('react.portal');\r\nconst REACT_FRAGMENT_TYPE = Symbol.for('react.fragment');\r\nconst REACT_STRICT_MODE_TYPE = Symbol.for('react.strict_mode');\r\nconst REACT_PROFILER_TYPE = Symbol.for('react.profiler');\r\nconst REACT_PROVIDER_TYPE = Symbol.for('react.provider');\r\nconst REACT_CONTEXT_TYPE = Symbol.for('react.context');\r\nconst REACT_FORWARD_REF_TYPE = Symbol.for('react.forward_ref');\r\nconst REACT_SUSPENSE_TYPE = Symbol.for('react.suspense');\r\nconst REACT_SUSPENSE_LIST_TYPE = Symbol.for('react.suspense_list');\r\nconst REACT_MEMO_TYPE = Symbol.for('react.memo');\r\nconst REACT_LAZY_TYPE = Symbol.for('react.lazy');\r\n\r\n// Flight reference symbols\r\nconst CLIENT_REFERENCE = Symbol.for('flight.client.reference');\r\nconst SERVER_REFERENCE = Symbol.for('flight.server.reference');\r\n\r\n// ============================================================================\r\n// Types\r\n// ============================================================================\r\n\r\n/**\r\n * React element shape (minimal interface)\r\n */\r\ninterface ReactElement {\r\n $$typeof: symbol;\r\n type: unknown;\r\n key: string | number | null;\r\n ref: unknown;\r\n props: Record<string, unknown>;\r\n _owner: unknown;\r\n}\r\n\r\n/**\r\n * React component type\r\n */\r\ntype ReactComponent =\r\n | string\r\n | ((props: Record<string, unknown>) => unknown)\r\n | { render: (props: Record<string, unknown>) => unknown };\r\n\r\n// ============================================================================\r\n// Adapter Implementation\r\n// ============================================================================\r\n\r\n/**\r\n * Create React UI Adapter\r\n * \r\n * @example\r\n * ```typescript\r\n * import { createReactAdapter } from '@flight-framework/core/rsc/adapters/react';\r\n * import { renderToString } from 'react-dom/server';\r\n * import * as React from 'react';\r\n * \r\n * const adapter = createReactAdapter({\r\n * React,\r\n * renderToString,\r\n * });\r\n * \r\n * const renderer = createRenderer(adapter);\r\n * ```\r\n */\r\nexport function createReactAdapter(deps?: {\r\n /** React module (optional - for SSR) */\r\n React?: {\r\n isValidElement: (value: unknown) => boolean;\r\n Children: { toArray: (children: unknown) => unknown[] };\r\n Fragment: symbol;\r\n Suspense: unknown;\r\n };\r\n /** renderToString function (optional - for SSR fallbacks) */\r\n renderToString?: (element: unknown) => string;\r\n}): UIAdapter {\r\n const { React, renderToString } = deps || {};\r\n\r\n return {\r\n name: 'react',\r\n\r\n isElement(value: unknown): boolean {\r\n if (React) {\r\n return React.isValidElement(value);\r\n }\r\n // Fallback: check for $$typeof\r\n return (\r\n typeof value === 'object' &&\r\n value !== null &&\r\n '$$typeof' in value &&\r\n (value as ReactElement).$$typeof === REACT_ELEMENT_TYPE\r\n );\r\n },\r\n\r\n getElementType(element: unknown): ElementTypeInfo {\r\n const el = element as ReactElement;\r\n const type = el.type;\r\n\r\n // String = host element (div, span, etc.)\r\n if (typeof type === 'string') {\r\n return { kind: 'host', tag: type };\r\n }\r\n\r\n // Symbol types\r\n if (typeof type === 'symbol') {\r\n if (type === REACT_FRAGMENT_TYPE || type === (React?.Fragment as symbol)) {\r\n return { kind: 'fragment' };\r\n }\r\n if (type === REACT_SUSPENSE_TYPE || (React?.Suspense && type === (React.Suspense as unknown as symbol))) {\r\n return {\r\n kind: 'suspense',\r\n fallback: el.props.fallback\r\n };\r\n }\r\n if (type === REACT_PROVIDER_TYPE) {\r\n return { kind: 'provider', value: el.props.value };\r\n }\r\n if (type === REACT_CONTEXT_TYPE) {\r\n return { kind: 'context' };\r\n }\r\n return { kind: 'null' };\r\n }\r\n\r\n // Object types (memo, lazy, forwardRef)\r\n if (typeof type === 'object' && type !== null) {\r\n const typeObj = type as { $$typeof?: symbol; type?: unknown; render?: unknown };\r\n\r\n if (typeObj.$$typeof === REACT_MEMO_TYPE) {\r\n // Unwrap memo\r\n return this.getElementType({ ...el, type: typeObj.type });\r\n }\r\n\r\n if (typeObj.$$typeof === REACT_LAZY_TYPE) {\r\n return { kind: 'component', fn: () => null, name: 'Lazy' };\r\n }\r\n\r\n if (typeObj.$$typeof === REACT_FORWARD_REF_TYPE && typeObj.render) {\r\n return {\r\n kind: 'component',\r\n fn: typeObj.render as (props: Record<string, unknown>) => unknown,\r\n name: 'ForwardRef'\r\n };\r\n }\r\n\r\n // Check for Suspense object\r\n if ('$$typeof' in typeObj &&\r\n (typeObj.$$typeof === REACT_SUSPENSE_TYPE)) {\r\n return { kind: 'suspense', fallback: el.props.fallback };\r\n }\r\n }\r\n\r\n // Function component\r\n if (typeof type === 'function') {\r\n const fn = type as ((props: Record<string, unknown>) => unknown) & {\r\n displayName?: string;\r\n name?: string;\r\n };\r\n return {\r\n kind: 'component',\r\n fn,\r\n name: fn.displayName || fn.name || 'Component'\r\n };\r\n }\r\n\r\n return { kind: 'null' };\r\n },\r\n\r\n getProps(element: unknown): Record<string, unknown> {\r\n return (element as ReactElement).props || {};\r\n },\r\n\r\n getChildren(element: unknown): unknown[] {\r\n const props = (element as ReactElement).props;\r\n const children = props?.children;\r\n\r\n if (children === undefined || children === null) {\r\n return [];\r\n }\r\n\r\n if (React?.Children) {\r\n return React.Children.toArray(children);\r\n }\r\n\r\n // Fallback array handling\r\n if (Array.isArray(children)) {\r\n return children.flat();\r\n }\r\n\r\n return [children];\r\n },\r\n\r\n getKey(element: unknown): string | number | undefined {\r\n const key = (element as ReactElement).key;\r\n return key !== null ? key : undefined;\r\n },\r\n\r\n isClientBoundary(component: unknown): boolean {\r\n if (typeof component !== 'function') return false;\r\n\r\n const comp = component as {\r\n $$typeof?: symbol;\r\n __flight_client?: boolean;\r\n };\r\n\r\n // Check for Flight client marker\r\n if (comp.__flight_client === true) return true;\r\n\r\n // Check for client reference symbol\r\n if (comp.$$typeof === CLIENT_REFERENCE) return true;\r\n\r\n return false;\r\n },\r\n\r\n async renderToString(element: unknown): Promise<string> {\r\n if (renderToString) {\r\n return renderToString(element);\r\n }\r\n throw new Error(\r\n 'renderToString not provided. Pass it when creating the adapter: ' +\r\n 'createReactAdapter({ renderToString })'\r\n );\r\n },\r\n };\r\n}\r\n\r\n// ============================================================================\r\n// React Client Consumer\r\n// ============================================================================\r\n\r\n/**\r\n * Opciones para el consumer de React\r\n */\r\nexport interface ReactConsumerOptions {\r\n /** Registry de client components */\r\n registry?: Map<string, () => Promise<unknown>>;\r\n /** Callback when hydration completes */\r\n onHydrate?: (id: string) => void;\r\n}\r\n\r\n/**\r\n * Create a React client-side consumer for Flight payloads\r\n * \r\n * This reconstructs React elements from Flight chunks on the client.\r\n */\r\nexport function createReactConsumer(deps: {\r\n React: {\r\n createElement: (type: unknown, props?: unknown, ...children: unknown[]) => unknown;\r\n Suspense: unknown;\r\n Fragment: unknown;\r\n lazy: (factory: () => Promise<{ default: unknown }>) => unknown;\r\n };\r\n}, options: ReactConsumerOptions = {}) {\r\n const { React } = deps;\r\n const { registry = new Map() } = options;\r\n\r\n return {\r\n /**\r\n * Register a client component\r\n */\r\n register(id: string, loader: () => Promise<unknown>): void {\r\n registry.set(id, loader);\r\n },\r\n\r\n /**\r\n * Convert Flight elements to React elements\r\n */\r\n toReactElement(element: import('../payload.js').FlightElement): unknown {\r\n switch (element.$$type) {\r\n case 'null':\r\n return null;\r\n\r\n case 'text':\r\n return element.value;\r\n\r\n case 'host': {\r\n const children = element.children.map(c => this.toReactElement(c));\r\n return React.createElement(\r\n element.tag,\r\n { ...element.props, key: element.key },\r\n ...children\r\n );\r\n }\r\n\r\n case 'fragment': {\r\n const children = element.children.map(c => this.toReactElement(c));\r\n return React.createElement(React.Fragment, null, ...children);\r\n }\r\n\r\n case 'suspense': {\r\n const fallback = this.toReactElement(element.fallback);\r\n const children = element.children.map(c => this.toReactElement(c));\r\n return React.createElement(\r\n React.Suspense,\r\n { fallback },\r\n ...children\r\n );\r\n }\r\n\r\n case 'client': {\r\n // Get loader from registry\r\n const loader = registry.get(element.ref);\r\n if (!loader) {\r\n console.warn(`[Flight] Client component not registered: ${element.ref}`);\r\n // Return SSR fallback if available\r\n if (element.ssr) {\r\n return React.createElement('div', {\r\n dangerouslySetInnerHTML: { __html: element.ssr }\r\n });\r\n }\r\n return null;\r\n }\r\n\r\n // Create lazy component\r\n const LazyComponent = React.lazy(async () => {\r\n const mod = await loader() as { default?: unknown };\r\n return { default: mod.default ?? mod };\r\n });\r\n\r\n return React.createElement(LazyComponent);\r\n }\r\n\r\n case 'lazy': {\r\n // This is a pending chunk - render fallback\r\n if (element.fallback) {\r\n return this.toReactElement(element.fallback);\r\n }\r\n return React.createElement('div', { 'data-flight-pending': element.id });\r\n }\r\n\r\n default:\r\n return null;\r\n }\r\n },\r\n\r\n /**\r\n * Process Flight chunks and build React tree\r\n */\r\n processChunks(chunks: import('../payload.js').FlightChunk[]): unknown {\r\n // Find root chunk\r\n const rootChunk = chunks.find(c => c.type === 'S' && c.id === 'root');\r\n if (!rootChunk || rootChunk.type !== 'S') {\r\n throw new Error('[Flight] No root chunk found in payload');\r\n }\r\n\r\n // Register all client references\r\n for (const chunk of chunks) {\r\n if (chunk.type === 'C') {\r\n // Default registry - lazy load via dynamic import\r\n if (!registry.has(chunk.id)) {\r\n registry.set(chunk.id, () => import(/* webpackIgnore: true */ chunk.module));\r\n }\r\n }\r\n }\r\n\r\n return this.toReactElement(rootChunk.tree);\r\n }\r\n };\r\n}\r\n\r\n// ============================================================================\r\n// Utility Types\r\n// ============================================================================\r\n\r\n/**\r\n * Type helper for React Server Component\r\n */\r\nexport type ReactServerComponent<P = Record<string, unknown>> = (\r\n props: P,\r\n ctx: import('../context.js').ServerContext\r\n) => Promise<ReturnType<typeof import('react').createElement>> | ReturnType<typeof import('react').createElement>;\r\n\r\n/**\r\n * Mark a component as a client component (for use without bundler transform)\r\n */\r\nexport function markAsClientComponent<T extends (...args: unknown[]) => unknown>(\r\n component: T,\r\n moduleId: string,\r\n exportName = 'default'\r\n): T {\r\n const marked = component as T & {\r\n $$typeof: symbol;\r\n __flight_client: boolean;\r\n __flight_module: string;\r\n __flight_export: string;\r\n };\r\n\r\n marked.$$typeof = CLIENT_REFERENCE;\r\n marked.__flight_client = true;\r\n marked.__flight_module = moduleId;\r\n marked.__flight_export = exportName;\r\n\r\n return marked;\r\n}\r\n"]}
|