@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.
Files changed (187) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +541 -0
  3. package/dist/actions/index.d.ts +743 -0
  4. package/dist/actions/index.js +3 -0
  5. package/dist/actions/index.js.map +1 -0
  6. package/dist/adapters/index.d.ts +502 -0
  7. package/dist/adapters/index.js +3 -0
  8. package/dist/adapters/index.js.map +1 -0
  9. package/dist/cache/index.d.ts +191 -0
  10. package/dist/cache/index.js +3 -0
  11. package/dist/cache/index.js.map +1 -0
  12. package/dist/chunk-62HISNA3.js +354 -0
  13. package/dist/chunk-62HISNA3.js.map +1 -0
  14. package/dist/chunk-63LWTEDQ.js +341 -0
  15. package/dist/chunk-63LWTEDQ.js.map +1 -0
  16. package/dist/chunk-63SCEXD7.js +3 -0
  17. package/dist/chunk-63SCEXD7.js.map +1 -0
  18. package/dist/chunk-72MYOTUB.js +667 -0
  19. package/dist/chunk-72MYOTUB.js.map +1 -0
  20. package/dist/chunk-7CNW24MQ.js +257 -0
  21. package/dist/chunk-7CNW24MQ.js.map +1 -0
  22. package/dist/chunk-7WIEAUJT.js +300 -0
  23. package/dist/chunk-7WIEAUJT.js.map +1 -0
  24. package/dist/chunk-7ZZF4ULK.js +259 -0
  25. package/dist/chunk-7ZZF4ULK.js.map +1 -0
  26. package/dist/chunk-AE3JTS73.js +222 -0
  27. package/dist/chunk-AE3JTS73.js.map +1 -0
  28. package/dist/chunk-AP5NLUSB.js +258 -0
  29. package/dist/chunk-AP5NLUSB.js.map +1 -0
  30. package/dist/chunk-C37YQQI7.js +221 -0
  31. package/dist/chunk-C37YQQI7.js.map +1 -0
  32. package/dist/chunk-DCLVXFVH.js +225 -0
  33. package/dist/chunk-DCLVXFVH.js.map +1 -0
  34. package/dist/chunk-DZMWWDFD.js +223 -0
  35. package/dist/chunk-DZMWWDFD.js.map +1 -0
  36. package/dist/chunk-GCQZ4FHI.js +245 -0
  37. package/dist/chunk-GCQZ4FHI.js.map +1 -0
  38. package/dist/chunk-IPP44XY6.js +47 -0
  39. package/dist/chunk-IPP44XY6.js.map +1 -0
  40. package/dist/chunk-IW7FTQQX.js +267 -0
  41. package/dist/chunk-IW7FTQQX.js.map +1 -0
  42. package/dist/chunk-JX4YSCBH.js +428 -0
  43. package/dist/chunk-JX4YSCBH.js.map +1 -0
  44. package/dist/chunk-KX6UYWWR.js +229 -0
  45. package/dist/chunk-KX6UYWWR.js.map +1 -0
  46. package/dist/chunk-LWVETFJV.js +46 -0
  47. package/dist/chunk-LWVETFJV.js.map +1 -0
  48. package/dist/chunk-MCL2MCA2.js +285 -0
  49. package/dist/chunk-MCL2MCA2.js.map +1 -0
  50. package/dist/chunk-MZXCF35B.js +205 -0
  51. package/dist/chunk-MZXCF35B.js.map +1 -0
  52. package/dist/chunk-NCGPUFWV.js +96 -0
  53. package/dist/chunk-NCGPUFWV.js.map +1 -0
  54. package/dist/chunk-OEJMIE2Q.js +351 -0
  55. package/dist/chunk-OEJMIE2Q.js.map +1 -0
  56. package/dist/chunk-OYF2OAKS.js +394 -0
  57. package/dist/chunk-OYF2OAKS.js.map +1 -0
  58. package/dist/chunk-P6S43FYZ.js +316 -0
  59. package/dist/chunk-P6S43FYZ.js.map +1 -0
  60. package/dist/chunk-PL37KFRJ.js +3 -0
  61. package/dist/chunk-PL37KFRJ.js.map +1 -0
  62. package/dist/chunk-Q7BS5QC5.js +197 -0
  63. package/dist/chunk-Q7BS5QC5.js.map +1 -0
  64. package/dist/chunk-SDYPG3JD.js +288 -0
  65. package/dist/chunk-SDYPG3JD.js.map +1 -0
  66. package/dist/chunk-SUG56SZO.js +256 -0
  67. package/dist/chunk-SUG56SZO.js.map +1 -0
  68. package/dist/chunk-UVH5XJRP.js +164 -0
  69. package/dist/chunk-UVH5XJRP.js.map +1 -0
  70. package/dist/chunk-WZIJKCL3.js +282 -0
  71. package/dist/chunk-WZIJKCL3.js.map +1 -0
  72. package/dist/chunk-Y22AMGTM.js +3 -0
  73. package/dist/chunk-Y22AMGTM.js.map +1 -0
  74. package/dist/chunk-Z7G23XWU.js +200 -0
  75. package/dist/chunk-Z7G23XWU.js.map +1 -0
  76. package/dist/chunk-ZJU5M4IB.js +125 -0
  77. package/dist/chunk-ZJU5M4IB.js.map +1 -0
  78. package/dist/chunk-ZVC3ZWLM.js +52 -0
  79. package/dist/chunk-ZVC3ZWLM.js.map +1 -0
  80. package/dist/chunk-ZZZML7Y3.js +310 -0
  81. package/dist/chunk-ZZZML7Y3.js.map +1 -0
  82. package/dist/client.d.ts +25 -0
  83. package/dist/client.js +16 -0
  84. package/dist/client.js.map +1 -0
  85. package/dist/config/index.d.ts +170 -0
  86. package/dist/config/index.js +3 -0
  87. package/dist/config/index.js.map +1 -0
  88. package/dist/errors/index.d.ts +267 -0
  89. package/dist/errors/index.js +4 -0
  90. package/dist/errors/index.js.map +1 -0
  91. package/dist/file-router/index.d.ts +184 -0
  92. package/dist/file-router/index.js +3 -0
  93. package/dist/file-router/index.js.map +1 -0
  94. package/dist/file-router/streaming-hints.d.ts +129 -0
  95. package/dist/file-router/streaming-hints.js +3 -0
  96. package/dist/file-router/streaming-hints.js.map +1 -0
  97. package/dist/handlers/index.d.ts +59 -0
  98. package/dist/handlers/index.js +3 -0
  99. package/dist/handlers/index.js.map +1 -0
  100. package/dist/index.d.ts +588 -0
  101. package/dist/index.js +886 -0
  102. package/dist/index.js.map +1 -0
  103. package/dist/islands/index.d.ts +234 -0
  104. package/dist/islands/index.js +3 -0
  105. package/dist/islands/index.js.map +1 -0
  106. package/dist/middleware/index.d.ts +305 -0
  107. package/dist/middleware/index.js +3 -0
  108. package/dist/middleware/index.js.map +1 -0
  109. package/dist/react/index.d.ts +73 -0
  110. package/dist/react/index.js +52 -0
  111. package/dist/react/index.js.map +1 -0
  112. package/dist/render/index.d.ts +131 -0
  113. package/dist/render/index.js +3 -0
  114. package/dist/render/index.js.map +1 -0
  115. package/dist/router/index.d.ts +65 -0
  116. package/dist/router/index.js +3 -0
  117. package/dist/router/index.js.map +1 -0
  118. package/dist/rsc/adapters/index.d.ts +8 -0
  119. package/dist/rsc/adapters/index.js +7 -0
  120. package/dist/rsc/adapters/index.js.map +1 -0
  121. package/dist/rsc/adapters/preact.d.ts +97 -0
  122. package/dist/rsc/adapters/preact.js +3 -0
  123. package/dist/rsc/adapters/preact.js.map +1 -0
  124. package/dist/rsc/adapters/react.d.ts +82 -0
  125. package/dist/rsc/adapters/react.js +3 -0
  126. package/dist/rsc/adapters/react.js.map +1 -0
  127. package/dist/rsc/adapters/solid.d.ts +84 -0
  128. package/dist/rsc/adapters/solid.js +3 -0
  129. package/dist/rsc/adapters/solid.js.map +1 -0
  130. package/dist/rsc/adapters/vue.d.ts +80 -0
  131. package/dist/rsc/adapters/vue.js +3 -0
  132. package/dist/rsc/adapters/vue.js.map +1 -0
  133. package/dist/rsc/boundaries.d.ts +182 -0
  134. package/dist/rsc/boundaries.js +3 -0
  135. package/dist/rsc/boundaries.js.map +1 -0
  136. package/dist/rsc/context.d.ts +201 -0
  137. package/dist/rsc/context.js +3 -0
  138. package/dist/rsc/context.js.map +1 -0
  139. package/dist/rsc/index.d.ts +232 -0
  140. package/dist/rsc/index.js +15 -0
  141. package/dist/rsc/index.js.map +1 -0
  142. package/dist/rsc/legacy.d.ts +155 -0
  143. package/dist/rsc/legacy.js +3 -0
  144. package/dist/rsc/legacy.js.map +1 -0
  145. package/dist/rsc/payload.d.ts +262 -0
  146. package/dist/rsc/payload.js +3 -0
  147. package/dist/rsc/payload.js.map +1 -0
  148. package/dist/rsc/plugins/esbuild.d.ts +124 -0
  149. package/dist/rsc/plugins/esbuild.js +4 -0
  150. package/dist/rsc/plugins/esbuild.js.map +1 -0
  151. package/dist/rsc/plugins/index.d.ts +4 -0
  152. package/dist/rsc/plugins/index.js +6 -0
  153. package/dist/rsc/plugins/index.js.map +1 -0
  154. package/dist/rsc/plugins/rollup.d.ts +103 -0
  155. package/dist/rsc/plugins/rollup.js +4 -0
  156. package/dist/rsc/plugins/rollup.js.map +1 -0
  157. package/dist/rsc/renderer.d.ts +162 -0
  158. package/dist/rsc/renderer.js +5 -0
  159. package/dist/rsc/renderer.js.map +1 -0
  160. package/dist/rsc/stream.d.ts +129 -0
  161. package/dist/rsc/stream.js +3 -0
  162. package/dist/rsc/stream.js.map +1 -0
  163. package/dist/rsc/vite-plugin.d.ts +78 -0
  164. package/dist/rsc/vite-plugin.js +4 -0
  165. package/dist/rsc/vite-plugin.js.map +1 -0
  166. package/dist/server/index.d.ts +135 -0
  167. package/dist/server/index.js +6 -0
  168. package/dist/server/index.js.map +1 -0
  169. package/dist/streaming/adapters/index.d.ts +223 -0
  170. package/dist/streaming/adapters/index.js +3 -0
  171. package/dist/streaming/adapters/index.js.map +1 -0
  172. package/dist/streaming/conditional.d.ts +130 -0
  173. package/dist/streaming/conditional.js +3 -0
  174. package/dist/streaming/conditional.js.map +1 -0
  175. package/dist/streaming/index.d.ts +177 -0
  176. package/dist/streaming/index.js +3 -0
  177. package/dist/streaming/index.js.map +1 -0
  178. package/dist/streaming/observability.d.ts +201 -0
  179. package/dist/streaming/observability.js +4 -0
  180. package/dist/streaming/observability.js.map +1 -0
  181. package/dist/streaming/priority.d.ts +103 -0
  182. package/dist/streaming/priority.js +3 -0
  183. package/dist/streaming/priority.js.map +1 -0
  184. package/dist/utils/index.d.ts +42 -0
  185. package/dist/utils/index.js +4 -0
  186. package/dist/utils/index.js.map +1 -0
  187. package/package.json +228 -0
@@ -0,0 +1,428 @@
1
+ import { readdir } from 'fs/promises';
2
+ import { join, extname, basename } from 'path';
3
+ import { pathToFileURL } from 'url';
4
+
5
+ // src/file-router/index.ts
6
+ async function scanRoutes(options) {
7
+ const {
8
+ directory,
9
+ extensions = [".ts", ".js"]
10
+ } = options;
11
+ const routes = [];
12
+ const errors = [];
13
+ async function scanDir(dir, basePath = "") {
14
+ try {
15
+ const entries = await readdir(dir, { withFileTypes: true });
16
+ for (const entry of entries) {
17
+ const fullPath = join(dir, entry.name);
18
+ if (entry.isDirectory()) {
19
+ if (entry.name.startsWith(".") || entry.name === "node_modules") {
20
+ continue;
21
+ }
22
+ if (entry.name.startsWith("@")) {
23
+ const slotName = entry.name.slice(1);
24
+ const slotRoutes = await scanSlotDir(fullPath, basePath, slotName, extensions);
25
+ routes.push(...slotRoutes);
26
+ continue;
27
+ }
28
+ const interceptMatch = entry.name.match(/^\((\.+)\)(.+)$/);
29
+ if (interceptMatch) {
30
+ const level = interceptMatch[1].length;
31
+ const targetSegment = interceptMatch[2];
32
+ const interceptRoutes = await scanInterceptDir(
33
+ fullPath,
34
+ basePath,
35
+ level,
36
+ targetSegment,
37
+ extensions
38
+ );
39
+ routes.push(...interceptRoutes);
40
+ continue;
41
+ }
42
+ const groupMatch = entry.name.match(/^\(([^.]+)\)$/);
43
+ if (groupMatch) {
44
+ await scanDir(fullPath, basePath);
45
+ continue;
46
+ }
47
+ await scanDir(fullPath, `${basePath}/${entry.name}`);
48
+ } else if (entry.isFile()) {
49
+ const ext = extname(entry.name);
50
+ if (!extensions.includes(ext)) {
51
+ continue;
52
+ }
53
+ const routeInfo = parseRouteFile(entry.name, basePath);
54
+ if (routeInfo && routeInfo.method && routeInfo.path) {
55
+ routes.push({
56
+ method: routeInfo.method,
57
+ path: routeInfo.path,
58
+ filePath: fullPath,
59
+ type: routeInfo.type
60
+ });
61
+ }
62
+ }
63
+ }
64
+ } catch (error) {
65
+ errors.push(`Failed to scan ${dir}: ${error}`);
66
+ }
67
+ }
68
+ await scanDir(directory);
69
+ return { routes, errors };
70
+ }
71
+ async function scanSlotDir(dir, basePath, slotName, extensions = [".ts", ".js", ".tsx", ".jsx"]) {
72
+ const routes = [];
73
+ try {
74
+ const entries = await readdir(dir, { withFileTypes: true });
75
+ for (const entry of entries) {
76
+ const fullPath = join(dir, entry.name);
77
+ if (entry.isFile()) {
78
+ const ext = extname(entry.name);
79
+ if (!extensions.includes(ext)) {
80
+ continue;
81
+ }
82
+ const routeInfo = parseRouteFile(entry.name, basePath);
83
+ if (routeInfo && routeInfo.method && routeInfo.path) {
84
+ routes.push({
85
+ method: routeInfo.method,
86
+ path: routeInfo.path,
87
+ filePath: fullPath,
88
+ type: routeInfo.type,
89
+ slot: slotName
90
+ });
91
+ }
92
+ }
93
+ }
94
+ } catch (error) {
95
+ console.error(`[Flight] Failed to scan slot @${slotName}:`, error);
96
+ }
97
+ return routes;
98
+ }
99
+ async function scanInterceptDir(dir, basePath, level, targetSegment, extensions = [".ts", ".js", ".tsx", ".jsx"]) {
100
+ const routes = [];
101
+ const pathParts = basePath.split("/").filter(Boolean);
102
+ let interceptPath;
103
+ if (level === 1) {
104
+ interceptPath = `${basePath}/${targetSegment}`;
105
+ } else if (level === 2) {
106
+ pathParts.pop();
107
+ interceptPath = `/${pathParts.join("/")}/${targetSegment}`;
108
+ } else {
109
+ interceptPath = `/${targetSegment}`;
110
+ }
111
+ try {
112
+ const entries = await readdir(dir, { withFileTypes: true });
113
+ for (const entry of entries) {
114
+ const fullPath = join(dir, entry.name);
115
+ if (entry.isFile()) {
116
+ const ext = extname(entry.name);
117
+ if (!extensions.includes(ext)) {
118
+ continue;
119
+ }
120
+ const routeInfo = parseRouteFile(entry.name, basePath);
121
+ if (routeInfo && routeInfo.method && routeInfo.path) {
122
+ routes.push({
123
+ method: routeInfo.method,
124
+ path: routeInfo.path,
125
+ filePath: fullPath,
126
+ type: routeInfo.type,
127
+ interceptInfo: {
128
+ level,
129
+ target: targetSegment,
130
+ interceptPath: interceptPath.replace(/\/+/g, "/") || "/"
131
+ }
132
+ });
133
+ }
134
+ } else if (entry.isDirectory()) {
135
+ const subRoutes = await scanInterceptDir(
136
+ fullPath,
137
+ `${basePath}/${entry.name}`,
138
+ level,
139
+ targetSegment,
140
+ extensions
141
+ );
142
+ routes.push(...subRoutes);
143
+ }
144
+ }
145
+ } catch (error) {
146
+ console.error(`[Flight] Failed to scan intercept (${".".repeat(level)})${targetSegment}:`, error);
147
+ }
148
+ return routes;
149
+ }
150
+ function parseRouteFile(filename, basePath) {
151
+ const ext = extname(filename);
152
+ const nameWithoutExt = basename(filename, ext);
153
+ if (nameWithoutExt.startsWith("_")) {
154
+ return null;
155
+ }
156
+ let type = "api";
157
+ let routeName = nameWithoutExt;
158
+ let method = "ALL";
159
+ const pageMatch = nameWithoutExt.match(/^(.+)?\.page$/i);
160
+ if (pageMatch) {
161
+ type = "page";
162
+ method = "GET";
163
+ routeName = pageMatch[1] || "index";
164
+ } else {
165
+ const methodMatch = nameWithoutExt.match(/^(.+)\.(get|post|put|delete|patch|head|options)$/i);
166
+ if (methodMatch) {
167
+ routeName = methodMatch[1] || nameWithoutExt;
168
+ method = (methodMatch[2] || "ALL").toUpperCase();
169
+ }
170
+ }
171
+ if (basePath.startsWith("/api") || basePath.includes("/api/")) {
172
+ type = "api";
173
+ }
174
+ let path = basePath;
175
+ if (routeName !== "index") {
176
+ path = `${basePath}/${convertToRoutePath(routeName)}`;
177
+ }
178
+ if (!path.startsWith("/")) {
179
+ path = "/" + path;
180
+ }
181
+ if (path !== "/" && path.endsWith("/")) {
182
+ path = path.slice(0, -1);
183
+ }
184
+ return { method, path, type };
185
+ }
186
+ function convertToRoutePath(name) {
187
+ if (name.startsWith("[[...") && name.endsWith("]]")) {
188
+ const paramName = name.slice(5, -2);
189
+ return `:${paramName}*`;
190
+ }
191
+ if (name.startsWith("[...") && name.endsWith("]")) {
192
+ const paramName = name.slice(4, -1);
193
+ return `:${paramName}+`;
194
+ }
195
+ if (name.startsWith("[") && name.endsWith("]")) {
196
+ const paramName = name.slice(1, -1);
197
+ return `:${paramName}`;
198
+ }
199
+ return name;
200
+ }
201
+ async function loadRoutes(scanResult, moduleLoader) {
202
+ const loadedRoutes = [];
203
+ for (const route of scanResult.routes) {
204
+ try {
205
+ let module;
206
+ if (moduleLoader) {
207
+ module = await moduleLoader(route.filePath);
208
+ } else {
209
+ const fileUrl = pathToFileURL(route.filePath).href;
210
+ module = await import(fileUrl);
211
+ }
212
+ if (route.type === "page") {
213
+ const component = module.default;
214
+ const meta = module.meta || module.metadata || {};
215
+ if (component) {
216
+ loadedRoutes.push({
217
+ ...route,
218
+ component,
219
+ meta
220
+ });
221
+ }
222
+ continue;
223
+ }
224
+ if (route.method === "ALL") {
225
+ const methods = ["GET", "POST", "PUT", "DELETE", "PATCH", "HEAD", "OPTIONS"];
226
+ for (const method of methods) {
227
+ if (typeof module[method] === "function") {
228
+ loadedRoutes.push({
229
+ ...route,
230
+ method,
231
+ handler: module[method]
232
+ });
233
+ }
234
+ }
235
+ if (typeof module.default === "function") {
236
+ loadedRoutes.push({
237
+ ...route,
238
+ method: "ALL",
239
+ handler: module.default
240
+ });
241
+ }
242
+ } else {
243
+ const handler = module[route.method] || module.default;
244
+ if (typeof handler === "function") {
245
+ loadedRoutes.push({
246
+ ...route,
247
+ handler
248
+ });
249
+ }
250
+ }
251
+ } catch (error) {
252
+ console.error(`[Flight] Failed to load route ${route.filePath}:`, error);
253
+ }
254
+ }
255
+ return loadedRoutes;
256
+ }
257
+ async function createFileRouter(options) {
258
+ let routes = [];
259
+ const { moduleLoader } = options;
260
+ async function refresh() {
261
+ const scanResult = await scanRoutes(options);
262
+ if (scanResult.errors.length > 0) {
263
+ console.warn("[Flight] Route scan errors:", scanResult.errors);
264
+ }
265
+ routes = await loadRoutes(scanResult, moduleLoader);
266
+ console.log(`[Flight] Loaded ${routes.length} routes from ${options.directory}`);
267
+ }
268
+ await refresh();
269
+ return {
270
+ get routes() {
271
+ return routes;
272
+ },
273
+ refresh
274
+ };
275
+ }
276
+ function resolveParallelSlots(routes, currentPath) {
277
+ const slots = {};
278
+ const normalizedPath = normalizePath(currentPath);
279
+ const slotNames = /* @__PURE__ */ new Set();
280
+ for (const route of routes) {
281
+ if (route.slot) {
282
+ slotNames.add(route.slot);
283
+ }
284
+ }
285
+ for (const slotName of slotNames) {
286
+ const slotRoutes = routes.filter((r) => r.slot === slotName);
287
+ let matchingRoute = slotRoutes.find((r) => {
288
+ const routePath = normalizePath(r.path);
289
+ return pathMatches(routePath, normalizedPath);
290
+ });
291
+ if (!matchingRoute) {
292
+ matchingRoute = slotRoutes.find(
293
+ (r) => r.path.endsWith("/default") || r.filePath.includes("default.page")
294
+ );
295
+ }
296
+ if (matchingRoute && matchingRoute.component) {
297
+ slots[slotName] = {
298
+ component: matchingRoute.component,
299
+ route: matchingRoute
300
+ };
301
+ } else {
302
+ slots[slotName] = null;
303
+ }
304
+ }
305
+ return slots;
306
+ }
307
+ function getSlotDefault(routes, slotName, basePath = "") {
308
+ const normalizedBase = normalizePath(basePath);
309
+ return routes.find(
310
+ (r) => r.slot === slotName && (r.filePath.includes("default.page") || r.path === `${normalizedBase}/default`)
311
+ ) || null;
312
+ }
313
+ function getSlotNames(routes) {
314
+ const names = /* @__PURE__ */ new Set();
315
+ for (const route of routes) {
316
+ if (route.slot) {
317
+ names.add(route.slot);
318
+ }
319
+ }
320
+ return Array.from(names);
321
+ }
322
+ function findInterceptingRoute(routes, fromPath, toPath) {
323
+ const normalizedFrom = normalizePath(fromPath);
324
+ const normalizedTo = normalizePath(toPath);
325
+ const interceptingRoutes = routes.filter((r) => r.interceptInfo);
326
+ for (const route of interceptingRoutes) {
327
+ const { interceptInfo } = route;
328
+ if (!interceptInfo) continue;
329
+ const interceptPath = normalizePath(interceptInfo.interceptPath);
330
+ if (!pathMatches(interceptPath, normalizedTo)) {
331
+ continue;
332
+ }
333
+ let validOrigin = false;
334
+ const routePathStr = normalizePath(route.path);
335
+ const interceptMarkerMatch = routePathStr.match(/\/\(\.+\)/);
336
+ if (interceptInfo.level >= 3) {
337
+ validOrigin = true;
338
+ } else if (interceptMarkerMatch && interceptMarkerMatch.index !== void 0) {
339
+ const routeBase = routePathStr.substring(0, interceptMarkerMatch.index);
340
+ if (interceptInfo.level === 1) {
341
+ validOrigin = normalizedFrom === routeBase || normalizedFrom.startsWith(routeBase + "/") || routeBase === "" && normalizedFrom.startsWith("/");
342
+ } else if (interceptInfo.level === 2) {
343
+ validOrigin = normalizedFrom === routeBase || normalizedFrom.startsWith(routeBase + "/");
344
+ }
345
+ }
346
+ if (validOrigin) {
347
+ return route;
348
+ }
349
+ }
350
+ return null;
351
+ }
352
+ function shouldDismissIntercept(currentRoute, toPath) {
353
+ if (!currentRoute || !currentRoute.interceptInfo) {
354
+ return false;
355
+ }
356
+ const normalizedTo = normalizePath(toPath);
357
+ const interceptPath = normalizePath(currentRoute.interceptInfo.interceptPath);
358
+ return !pathMatches(interceptPath, normalizedTo);
359
+ }
360
+ function extractRouteParams(routePath, actualPath) {
361
+ const routeParts = routePath.split("/").filter(Boolean);
362
+ const actualParts = actualPath.split("/").filter(Boolean);
363
+ if (routeParts.length !== actualParts.length) {
364
+ const hasCatchAll = routeParts.some((p) => p.endsWith("+") || p.endsWith("*"));
365
+ if (!hasCatchAll) {
366
+ return null;
367
+ }
368
+ }
369
+ const params = {};
370
+ for (let i = 0; i < routeParts.length; i++) {
371
+ const routePart = routeParts[i];
372
+ const actualPart = actualParts[i];
373
+ if (!routePart) continue;
374
+ if (routePart.startsWith(":")) {
375
+ const paramName = routePart.slice(1).replace(/[+*]$/, "");
376
+ if (routePart.endsWith("+") || routePart.endsWith("*")) {
377
+ params[paramName] = actualParts.slice(i).join("/");
378
+ break;
379
+ }
380
+ if (!actualPart) {
381
+ if (routePart.endsWith("*")) {
382
+ params[paramName] = "";
383
+ break;
384
+ }
385
+ return null;
386
+ }
387
+ params[paramName] = actualPart;
388
+ } else if (routePart !== actualPart) {
389
+ return null;
390
+ }
391
+ }
392
+ return params;
393
+ }
394
+ function normalizePath(path) {
395
+ let normalized = path.trim();
396
+ if (!normalized.startsWith("/")) {
397
+ normalized = "/" + normalized;
398
+ }
399
+ if (normalized !== "/" && normalized.endsWith("/")) {
400
+ normalized = normalized.slice(0, -1);
401
+ }
402
+ normalized = normalized.replace(/\/+/g, "/");
403
+ return normalized;
404
+ }
405
+ function pathMatches(routePath, actualPath) {
406
+ const routeParts = routePath.split("/").filter(Boolean);
407
+ const actualParts = actualPath.split("/").filter(Boolean);
408
+ for (let i = 0; i < routeParts.length; i++) {
409
+ const routePart = routeParts[i];
410
+ const actualPart = actualParts[i];
411
+ if (!routePart) continue;
412
+ if (routePart.startsWith(":") && (routePart.endsWith("+") || routePart.endsWith("*"))) {
413
+ return true;
414
+ }
415
+ if (routePart.startsWith(":")) {
416
+ if (!actualPart) return false;
417
+ continue;
418
+ }
419
+ if (routePart !== actualPart) {
420
+ return false;
421
+ }
422
+ }
423
+ return routeParts.length === actualParts.length;
424
+ }
425
+
426
+ export { createFileRouter, extractRouteParams, findInterceptingRoute, getSlotDefault, getSlotNames, loadRoutes, resolveParallelSlots, scanRoutes, shouldDismissIntercept };
427
+ //# sourceMappingURL=chunk-JX4YSCBH.js.map
428
+ //# sourceMappingURL=chunk-JX4YSCBH.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/file-router/index.ts"],"names":[],"mappings":";;;;;AA6EA,eAAsB,WAAW,OAAA,EAAiD;AAC9E,EAAA,MAAM;AAAA,IACF,SAAA;AAAA,IACA,UAAA,GAAa,CAAC,KAAA,EAAO,KAAK;AAAA,GAC9B,GAAI,OAAA;AAEJ,EAAA,MAAM,SAAsB,EAAC;AAC7B,EAAA,MAAM,SAAmB,EAAC;AAE1B,EAAA,eAAe,OAAA,CAAQ,GAAA,EAAa,QAAA,GAAmB,EAAA,EAAmB;AACtE,IAAA,IAAI;AACA,MAAA,MAAM,UAAU,MAAM,OAAA,CAAQ,KAAK,EAAE,aAAA,EAAe,MAAM,CAAA;AAE1D,MAAA,KAAA,MAAW,SAAS,OAAA,EAAS;AACzB,QAAA,MAAM,QAAA,GAAW,IAAA,CAAK,GAAA,EAAK,KAAA,CAAM,IAAI,CAAA;AAErC,QAAA,IAAI,KAAA,CAAM,aAAY,EAAG;AAErB,UAAA,IAAI,MAAM,IAAA,CAAK,UAAA,CAAW,GAAG,CAAA,IAAK,KAAA,CAAM,SAAS,cAAA,EAAgB;A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A,CAAW,QAAQ,CAAA,EAAA,EAAK;AACxC,IAAA,MAAM,SAAA,GAAY,WAAW,CAAC,CAAA;AAC9B,IAAA,MAAM,UAAA,GAAa,YAAY,CAAC,CAAA;AAEhC,IAAA,IAAI,CAAC,SAAA,EAAW;AAGhB,IAAA,IAAI,SAAA,CAAU,UAAA,CAAW,GAAG,CAAA,KAAM,SAAA,CAAU,QAAA,CAAS,GAAG,CAAA,IAAK,SAAA,CAAU,QAAA,CAAS,GAAG,CAAA,CAAA,EAAI;AACnF,MAAA,OAAO,IAAA;AAAA,IACX;AAGA,IAAA,IAAI,SAAA,CAAU,UAAA,CAAW,GAAG,CAAA,EAAG;AAC3B,MAAA,IAAI,CAAC,YAAY,OAAO,KAAA;AACxB,MAAA;AAAA,IACJ;AAGA,IAAA,IAAI,cAAc,UAAA,EAAY;AAC1B,MAAA,OAAO,KAAA;AAAA,IACX;AAAA,EACJ;AAGA,EAAA,OAAO,UAAA,CAAW,WAAW,WAAA,CAAY,MAAA;AAC7C","file":"chunk-JX4YSCBH.js","sourcesContent":["/**\r\n * @flightdev/core - File Router\r\n * \r\n * Auto-discovery of routes from file system.\r\n * Similar to Next.js App Router and Nuxt server/api patterns.\r\n */\r\n\r\nimport { readdir } from 'node:fs/promises';\r\nimport { join, basename, extname } from 'node:path';\r\nimport { pathToFileURL } from 'node:url';\r\n\r\n// ============================================================================\r\n// Types\r\n// ============================================================================\r\n\r\nexport type HttpMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH' | 'HEAD' | 'OPTIONS';\r\n\r\nexport type Handler = (context: unknown) => Response | Promise<Response>;\r\nexport type Middleware = (context: unknown, next: () => Promise<Response>) => Response | Promise<Response>;\r\n\r\nexport interface FileRoute {\r\n /** HTTP method (GET, POST, etc) or 'ALL' */\r\n method: HttpMethod | 'ALL';\r\n /** Route path with params (e.g., /users/:id) */\r\n path: string;\r\n /** Original file path */\r\n filePath: string;\r\n /** Handler function (for APIs) */\r\n handler?: Handler;\r\n /** Route-specific middleware */\r\n middleware?: Middleware[];\r\n /** Route type: 'page' for SSR pages, 'api' for API endpoints */\r\n type: 'page' | 'api';\r\n /** Component function (for pages) */\r\n component?: () => unknown;\r\n /** Page metadata (title, description, etc) */\r\n meta?: Record<string, unknown>;\r\n /** Parallel route slot name (for @folder convention) */\r\n slot?: string;\r\n /** Intercepting route info (for (.) (..) (...) convention) */\r\n interceptInfo?: {\r\n /** Number of levels to intercept: 1 = same, 2 = parent, 3+ = root */\r\n level: number;\r\n /** Target route segment to intercept */\r\n target: string;\r\n /** Original path that triggers interception */\r\n interceptPath: string;\r\n };\r\n}\r\n\r\nexport interface FileRouterOptions {\r\n /** Root directory to scan (default: src/routes) */\r\n directory: string;\r\n /** File extensions to consider (default: ['.ts', '.js']) */\r\n extensions?: string[];\r\n /** Whether to watch for changes (default: false in prod) */\r\n watch?: boolean;\r\n /** \r\n * Custom module loader for development with Vite.\r\n * Pass vite.ssrLoadModule to load TSX files correctly.\r\n * Falls back to native import() if not provided.\r\n */\r\n moduleLoader?: (filePath: string) => Promise<any>;\r\n}\r\n\r\nexport interface ScanResult {\r\n routes: FileRoute[];\r\n errors: string[];\r\n}\r\n\r\n// ============================================================================\r\n// File Scanner\r\n// ============================================================================\r\n\r\n/**\r\n * Scan a directory for route files\r\n */\r\nexport async function scanRoutes(options: FileRouterOptions): Promise<ScanResult> {\r\n const {\r\n directory,\r\n extensions = ['.ts', '.js'],\r\n } = options;\r\n\r\n const routes: FileRoute[] = [];\r\n const errors: string[] = [];\r\n\r\n async function scanDir(dir: string, basePath: string = ''): Promise<void> {\r\n try {\r\n const entries = await readdir(dir, { withFileTypes: true });\r\n\r\n for (const entry of entries) {\r\n const fullPath = join(dir, entry.name);\r\n\r\n if (entry.isDirectory()) {\r\n // Skip hidden directories and node_modules\r\n if (entry.name.startsWith('.') || entry.name === 'node_modules') {\r\n continue;\r\n }\r\n\r\n // Detect parallel route slots (@folder convention)\r\n if (entry.name.startsWith('@')) {\r\n const slotName = entry.name.slice(1);\r\n // Scan slot directory and mark routes with slot name\r\n const slotRoutes = await scanSlotDir(fullPath, basePath, slotName, extensions);\r\n routes.push(...slotRoutes);\r\n continue;\r\n }\r\n\r\n // Detect intercepting routes ((.) (..) (...) convention)\r\n const interceptMatch = entry.name.match(/^\\((\\.+)\\)(.+)$/);\r\n if (interceptMatch) {\r\n const level = interceptMatch[1].length;\r\n const targetSegment = interceptMatch[2];\r\n // Scan intercept directory and mark routes with interceptInfo\r\n const interceptRoutes = await scanInterceptDir(\r\n fullPath,\r\n basePath,\r\n level,\r\n targetSegment,\r\n extensions\r\n );\r\n routes.push(...interceptRoutes);\r\n continue;\r\n }\r\n\r\n // Detect route groups ((groupName) without dots - organizational only)\r\n // Route groups allow organizing routes without affecting URL structure\r\n // Example: (marketing)/about.page.tsx -> /about (not /marketing/about)\r\n const groupMatch = entry.name.match(/^\\(([^.]+)\\)$/);\r\n if (groupMatch) {\r\n // This is a route group - scan contents but don't add group to path\r\n await scanDir(fullPath, basePath);\r\n continue;\r\n }\r\n\r\n // Recurse into subdirectory\r\n await scanDir(fullPath, `${basePath}/${entry.name}`);\r\n } else if (entry.isFile()) {\r\n const ext = extname(entry.name);\r\n\r\n if (!extensions.includes(ext)) {\r\n continue;\r\n }\r\n\r\n // Parse route from filename\r\n const routeInfo = parseRouteFile(entry.name, basePath);\r\n\r\n if (routeInfo && routeInfo.method && routeInfo.path) {\r\n routes.push({\r\n method: routeInfo.method,\r\n path: routeInfo.path,\r\n filePath: fullPath,\r\n type: routeInfo.type,\r\n });\r\n }\r\n }\r\n }\r\n } catch (error) {\r\n errors.push(`Failed to scan ${dir}: ${error}`);\r\n }\r\n }\r\n\r\n await scanDir(directory);\r\n\r\n return { routes, errors };\r\n}\r\n\r\n/**\r\n * Scan a parallel route slot directory\r\n */\r\nasync function scanSlotDir(\r\n dir: string,\r\n basePath: string,\r\n slotName: string,\r\n extensions: string[] = ['.ts', '.js', '.tsx', '.jsx']\r\n): Promise<FileRoute[]> {\r\n const routes: FileRoute[] = [];\r\n\r\n try {\r\n const entries = await readdir(dir, { withFileTypes: true });\r\n\r\n for (const entry of entries) {\r\n const fullPath = join(dir, entry.name);\r\n\r\n if (entry.isFile()) {\r\n const ext = extname(entry.name);\r\n\r\n if (!extensions.includes(ext)) {\r\n continue;\r\n }\r\n\r\n const routeInfo = parseRouteFile(entry.name, basePath);\r\n\r\n if (routeInfo && routeInfo.method && routeInfo.path) {\r\n routes.push({\r\n method: routeInfo.method,\r\n path: routeInfo.path,\r\n filePath: fullPath,\r\n type: routeInfo.type,\r\n slot: slotName,\r\n });\r\n }\r\n }\r\n }\r\n } catch (error) {\r\n console.error(`[Flight] Failed to scan slot @${slotName}:`, error);\r\n }\r\n\r\n return routes;\r\n}\r\n\r\n/**\r\n * Scan an intercepting route directory\r\n * Uses (.) (..) (...) convention similar to Next.js\r\n * - (.)segment - intercepts from same level\r\n * - (..)segment - intercepts from parent level\r\n * - (...)segment - intercepts from root\r\n */\r\nasync function scanInterceptDir(\r\n dir: string,\r\n basePath: string,\r\n level: number,\r\n targetSegment: string,\r\n extensions: string[] = ['.ts', '.js', '.tsx', '.jsx']\r\n): Promise<FileRoute[]> {\r\n const routes: FileRoute[] = [];\r\n\r\n // Calculate the intercept path based on level\r\n const pathParts = basePath.split('/').filter(Boolean);\r\n let interceptPath: string;\r\n\r\n if (level === 1) {\r\n // (.) - Same level, intercepts sibling route\r\n interceptPath = `${basePath}/${targetSegment}`;\r\n } else if (level === 2) {\r\n // (..) - Parent level\r\n pathParts.pop();\r\n interceptPath = `/${pathParts.join('/')}/${targetSegment}`;\r\n } else {\r\n // (...) - Root level (3 or more dots)\r\n interceptPath = `/${targetSegment}`;\r\n }\r\n\r\n try {\r\n const entries = await readdir(dir, { withFileTypes: true });\r\n\r\n for (const entry of entries) {\r\n const fullPath = join(dir, entry.name);\r\n\r\n if (entry.isFile()) {\r\n const ext = extname(entry.name);\r\n\r\n if (!extensions.includes(ext)) {\r\n continue;\r\n }\r\n\r\n const routeInfo = parseRouteFile(entry.name, basePath);\r\n\r\n if (routeInfo && routeInfo.method && routeInfo.path) {\r\n routes.push({\r\n method: routeInfo.method,\r\n path: routeInfo.path,\r\n filePath: fullPath,\r\n type: routeInfo.type,\r\n interceptInfo: {\r\n level,\r\n target: targetSegment,\r\n interceptPath: interceptPath.replace(/\\/+/g, '/') || '/',\r\n },\r\n });\r\n }\r\n } else if (entry.isDirectory()) {\r\n // Recurse into subdirectories within intercept folder\r\n const subRoutes = await scanInterceptDir(\r\n fullPath,\r\n `${basePath}/${entry.name}`,\r\n level,\r\n targetSegment,\r\n extensions\r\n );\r\n routes.push(...subRoutes);\r\n }\r\n }\r\n } catch (error) {\r\n console.error(`[Flight] Failed to scan intercept (${'.'.repeat(level)})${targetSegment}:`, error);\r\n }\r\n\r\n return routes;\r\n}\r\n\r\n// ============================================================================\r\n// Route Parser\r\n// ============================================================================\r\n\r\ninterface ParsedRoute {\r\n method: HttpMethod | 'ALL';\r\n path: string;\r\n type: 'page' | 'api';\r\n}\r\n\r\n/**\r\n * Parse route information from filename and path\r\n * \r\n * Patterns:\r\n * - index.ts → /\r\n * - users.ts → /users\r\n * - users.get.ts → GET /users (API)\r\n * - users.post.ts → POST /users (API)\r\n * - about.page.tsx → GET /about (Page)\r\n * - blog/[slug].page.tsx → GET /blog/:slug (Page)\r\n * - [id].ts → /:id\r\n * - [...slug].ts → /* (catch-all)\r\n * - [[...slug]].ts → /* (optional catch-all)\r\n */\r\nfunction parseRouteFile(filename: string, basePath: string): ParsedRoute | null {\r\n const ext = extname(filename);\r\n const nameWithoutExt = basename(filename, ext);\r\n\r\n // Skip files starting with underscore (private)\r\n if (nameWithoutExt.startsWith('_')) {\r\n return null;\r\n }\r\n\r\n // Detect route type\r\n let type: 'page' | 'api' = 'api';\r\n let routeName = nameWithoutExt;\r\n let method: HttpMethod | 'ALL' = 'ALL';\r\n\r\n // Check for page suffix (e.g., about.page.tsx, index.page.tsx)\r\n const pageMatch = nameWithoutExt.match(/^(.+)?\\.page$/i);\r\n if (pageMatch) {\r\n type = 'page';\r\n method = 'GET'; // Pages are always GET\r\n routeName = pageMatch[1] || 'index';\r\n } else {\r\n // Check for method suffix (e.g., users.get.ts)\r\n const methodMatch = nameWithoutExt.match(/^(.+)\\.(get|post|put|delete|patch|head|options)$/i);\r\n if (methodMatch) {\r\n routeName = methodMatch[1] || nameWithoutExt;\r\n method = (methodMatch[2] || 'ALL').toUpperCase() as HttpMethod;\r\n }\r\n }\r\n\r\n // Also check if file is in /api/ directory\r\n if (basePath.startsWith('/api') || basePath.includes('/api/')) {\r\n type = 'api';\r\n }\r\n\r\n // Build route path\r\n let path = basePath;\r\n\r\n if (routeName !== 'index') {\r\n path = `${basePath}/${convertToRoutePath(routeName)}`;\r\n }\r\n\r\n // Ensure path starts with /\r\n if (!path.startsWith('/')) {\r\n path = '/' + path;\r\n }\r\n\r\n // Remove trailing slash (except for root)\r\n if (path !== '/' && path.endsWith('/')) {\r\n path = path.slice(0, -1);\r\n }\r\n\r\n return { method, path, type };\r\n}\r\n\r\n/**\r\n * Convert filename segment to route path segment\r\n * \r\n * - [id] → :id\r\n * - [...slug] → *\r\n * - [[...slug]] → *?\r\n */\r\nfunction convertToRoutePath(name: string): string {\r\n // Optional catch-all: [[...slug]]\r\n if (name.startsWith('[[...') && name.endsWith(']]')) {\r\n const paramName = name.slice(5, -2);\r\n return `:${paramName}*`;\r\n }\r\n\r\n // Catch-all: [...slug]\r\n if (name.startsWith('[...') && name.endsWith(']')) {\r\n const paramName = name.slice(4, -1);\r\n return `:${paramName}+`;\r\n }\r\n\r\n // Dynamic param: [id]\r\n if (name.startsWith('[') && name.endsWith(']')) {\r\n const paramName = name.slice(1, -1);\r\n return `:${paramName}`;\r\n }\r\n\r\n return name;\r\n}\r\n\r\n// ============================================================================\r\n// Route Loader\r\n// ============================================================================\r\n\r\n/**\r\n * Load routes with their handlers or components\r\n * @param scanResult - Result from scanRoutes\r\n * @param moduleLoader - Optional custom loader (use vite.ssrLoadModule for dev)\r\n */\r\nexport async function loadRoutes(\r\n scanResult: ScanResult,\r\n moduleLoader?: (filePath: string) => Promise<any>\r\n): Promise<FileRoute[]> {\r\n const loadedRoutes: FileRoute[] = [];\r\n\r\n for (const route of scanResult.routes) {\r\n try {\r\n // Use custom loader if provided (Vite ssrLoadModule for TSX)\r\n // Otherwise fall back to native import() for production\r\n let module: any;\r\n if (moduleLoader) {\r\n module = await moduleLoader(route.filePath);\r\n } else {\r\n // Convert to file:// URL for Windows ESM compatibility\r\n const fileUrl = pathToFileURL(route.filePath).href;\r\n module = await import(fileUrl);\r\n }\r\n\r\n // Handle PAGE routes\r\n if (route.type === 'page') {\r\n // Pages export default component\r\n const component = module.default;\r\n const meta = module.meta || module.metadata || {};\r\n\r\n if (component) {\r\n loadedRoutes.push({\r\n ...route,\r\n component,\r\n meta,\r\n });\r\n }\r\n continue;\r\n }\r\n\r\n // Handle API routes\r\n if (route.method === 'ALL') {\r\n // Look for named exports: GET, POST, PUT, DELETE, etc\r\n const methods: HttpMethod[] = ['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'HEAD', 'OPTIONS'];\r\n\r\n for (const method of methods) {\r\n if (typeof module[method] === 'function') {\r\n loadedRoutes.push({\r\n ...route,\r\n method,\r\n handler: module[method],\r\n });\r\n }\r\n }\r\n\r\n // Also check for default export as handler\r\n if (typeof module.default === 'function') {\r\n loadedRoutes.push({\r\n ...route,\r\n method: 'ALL',\r\n handler: module.default,\r\n });\r\n }\r\n } else {\r\n // Specific method from filename suffix\r\n const handler = module[route.method] || module.default;\r\n\r\n if (typeof handler === 'function') {\r\n loadedRoutes.push({\r\n ...route,\r\n handler,\r\n });\r\n }\r\n }\r\n } catch (error) {\r\n console.error(`[Flight] Failed to load route ${route.filePath}:`, error);\r\n }\r\n }\r\n\r\n return loadedRoutes;\r\n}\r\n\r\n// ============================================================================\r\n// File Router Factory\r\n// ============================================================================\r\n\r\nexport interface FileRouter {\r\n routes: FileRoute[];\r\n refresh: () => Promise<void>;\r\n}\r\n\r\n/**\r\n * Create a file-based router\r\n * \r\n * @example\r\n * ```typescript\r\n * import { createFileRouter } from '@flightdev/core/file-router';\r\n * import { createServer } from '@flightdev/http';\r\n * \r\n * const router = await createFileRouter({ directory: './src/routes' });\r\n * const app = createServer();\r\n * \r\n * // Register all discovered routes\r\n * for (const route of router.routes) {\r\n * app[route.method.toLowerCase()](route.path, route.handler);\r\n * }\r\n * ```\r\n */\r\nexport async function createFileRouter(options: FileRouterOptions): Promise<FileRouter> {\r\n let routes: FileRoute[] = [];\r\n const { moduleLoader } = options;\r\n\r\n async function refresh(): Promise<void> {\r\n const scanResult = await scanRoutes(options);\r\n\r\n if (scanResult.errors.length > 0) {\r\n console.warn('[Flight] Route scan errors:', scanResult.errors);\r\n }\r\n\r\n routes = await loadRoutes(scanResult, moduleLoader);\r\n\r\n console.log(`[Flight] Loaded ${routes.length} routes from ${options.directory}`);\r\n }\r\n\r\n // Initial load\r\n await refresh();\r\n\r\n return {\r\n get routes() {\r\n return routes;\r\n },\r\n refresh,\r\n };\r\n}\r\n\r\n// ============================================================================\r\n// Parallel Routes Resolution\r\n// ============================================================================\r\n\r\n/**\r\n * Resolved parallel route slots for a layout.\r\n * Each slot name maps to its resolved component or null if not matched.\r\n */\r\nexport interface ResolvedSlots {\r\n [slotName: string]: {\r\n /** The component to render */\r\n component: () => unknown;\r\n /** The full route information */\r\n route: FileRoute;\r\n } | null;\r\n}\r\n\r\n/**\r\n * Resolve parallel route slots for a given path.\r\n * \r\n * Parallel routes use the @folder convention to define named slots\r\n * that can render alongside the main content in a layout.\r\n * \r\n * @param routes - All loaded routes from the file router\r\n * @param currentPath - The current URL path to resolve slots for\r\n * @returns Object mapping slot names to their resolved components\r\n * \r\n * @example\r\n * ```typescript\r\n * // Given routes from @modal/ and @sidebar/ directories\r\n * const slots = resolveParallelSlots(router.routes, '/dashboard');\r\n * \r\n * // In layout:\r\n * if (slots.modal) {\r\n * renderModal(slots.modal.component);\r\n * }\r\n * ```\r\n */\r\nexport function resolveParallelSlots(\r\n routes: FileRoute[],\r\n currentPath: string\r\n): ResolvedSlots {\r\n const slots: ResolvedSlots = {};\r\n const normalizedPath = normalizePath(currentPath);\r\n\r\n // Get all unique slot names from routes\r\n const slotNames = new Set<string>();\r\n for (const route of routes) {\r\n if (route.slot) {\r\n slotNames.add(route.slot);\r\n }\r\n }\r\n\r\n // For each slot, find matching route or default\r\n for (const slotName of slotNames) {\r\n const slotRoutes = routes.filter(r => r.slot === slotName);\r\n\r\n // Find exact match for current path\r\n let matchingRoute = slotRoutes.find(r => {\r\n const routePath = normalizePath(r.path);\r\n return pathMatches(routePath, normalizedPath);\r\n });\r\n\r\n // If no match, look for default.page in the slot\r\n if (!matchingRoute) {\r\n matchingRoute = slotRoutes.find(r =>\r\n r.path.endsWith('/default') || r.filePath.includes('default.page')\r\n );\r\n }\r\n\r\n if (matchingRoute && matchingRoute.component) {\r\n slots[slotName] = {\r\n component: matchingRoute.component,\r\n route: matchingRoute,\r\n };\r\n } else {\r\n // Slot has no matching content for this path\r\n slots[slotName] = null;\r\n }\r\n }\r\n\r\n return slots;\r\n}\r\n\r\n/**\r\n * Get the default page for an unmatched slot.\r\n * \r\n * When a parallel route slot doesn't have a matching route for the current path,\r\n * it should render its default.page if one exists, or null.\r\n * \r\n * @param routes - All loaded routes\r\n * @param slotName - Name of the slot (without @)\r\n * @param basePath - Base path to search from\r\n * @returns The default route for the slot, or null\r\n */\r\nexport function getSlotDefault(\r\n routes: FileRoute[],\r\n slotName: string,\r\n basePath: string = ''\r\n): FileRoute | null {\r\n const normalizedBase = normalizePath(basePath);\r\n\r\n return routes.find(r =>\r\n r.slot === slotName &&\r\n (r.filePath.includes('default.page') || r.path === `${normalizedBase}/default`)\r\n ) || null;\r\n}\r\n\r\n/**\r\n * Get all slot names used in the routes.\r\n * \r\n * @param routes - All loaded routes\r\n * @returns Array of unique slot names\r\n */\r\nexport function getSlotNames(routes: FileRoute[]): string[] {\r\n const names = new Set<string>();\r\n for (const route of routes) {\r\n if (route.slot) {\r\n names.add(route.slot);\r\n }\r\n }\r\n return Array.from(names);\r\n}\r\n\r\n// ============================================================================\r\n// Intercepting Routes Resolution\r\n// ============================================================================\r\n\r\n/**\r\n * Check if a navigation should be intercepted by an intercepting route.\r\n * \r\n * Intercepting routes use the (.) (..) (...) convention:\r\n * - (.)segment - intercepts from same level\r\n * - (..)segment - intercepts from parent level \r\n * - (...)segment - intercepts from root\r\n * \r\n * @param routes - All loaded routes\r\n * @param fromPath - Current path where navigation originates\r\n * @param toPath - Target path the user wants to navigate to\r\n * @returns The intercepting route if found, null otherwise\r\n * \r\n * @example\r\n * ```typescript\r\n * // User is on /feed and clicks link to /photo/123\r\n * const intercepted = findInterceptingRoute(routes, '/feed', '/photo/123');\r\n * \r\n * if (intercepted) {\r\n * // Render intercepted.component as modal instead of navigating\r\n * showModal(intercepted);\r\n * }\r\n * ```\r\n */\r\nexport function findInterceptingRoute(\r\n routes: FileRoute[],\r\n fromPath: string,\r\n toPath: string\r\n): FileRoute | null {\r\n const normalizedFrom = normalizePath(fromPath);\r\n const normalizedTo = normalizePath(toPath);\r\n\r\n // Filter to only intercepting routes\r\n const interceptingRoutes = routes.filter(r => r.interceptInfo);\r\n\r\n for (const route of interceptingRoutes) {\r\n const { interceptInfo } = route;\r\n if (!interceptInfo) continue;\r\n\r\n // Check if the interceptPath matches the target path\r\n const interceptPath = normalizePath(interceptInfo.interceptPath);\r\n\r\n if (!pathMatches(interceptPath, normalizedTo)) {\r\n continue;\r\n }\r\n\r\n // Check if we're navigating from a valid origin based on level\r\n // For level 1 (.), the intercept route is at same level as navigation origin\r\n // For level 2 (..), the intercept route is one level up from navigation origin\r\n // For level 3+ (...), intercepts from anywhere\r\n\r\n let validOrigin = false;\r\n\r\n // Find the intercept marker position in route path\r\n // Route path example: /feed/(.)photo/:id -> base is /feed\r\n const routePathStr = normalizePath(route.path);\r\n const interceptMarkerMatch = routePathStr.match(/\\/\\(\\.+\\)/);\r\n\r\n if (interceptInfo.level >= 3) {\r\n // (...) - Root level: intercepts from anywhere\r\n validOrigin = true;\r\n } else if (interceptMarkerMatch && interceptMarkerMatch.index !== undefined) {\r\n // Extract the base path before the intercept marker\r\n const routeBase = routePathStr.substring(0, interceptMarkerMatch.index);\r\n\r\n if (interceptInfo.level === 1) {\r\n // (.) - Same level: origin should be at or under the route base\r\n // Route at /feed/(.)photo, origin should be /feed or /feed/*\r\n validOrigin = normalizedFrom === routeBase ||\r\n normalizedFrom.startsWith(routeBase + '/') ||\r\n (routeBase === '' && normalizedFrom.startsWith('/'));\r\n } else if (interceptInfo.level === 2) {\r\n // (..) - Parent level: origin is one level deeper\r\n // Route at /gallery/albums/(..)photo, origin should be /gallery/albums/*\r\n validOrigin = normalizedFrom === routeBase ||\r\n normalizedFrom.startsWith(routeBase + '/');\r\n }\r\n }\r\n\r\n if (validOrigin) {\r\n return route;\r\n }\r\n }\r\n\r\n return null;\r\n}\r\n\r\n/**\r\n * Check if an intercepting route should be dismissed on this navigation.\r\n * \r\n * @param currentRoute - The currently active intercepting route\r\n * @param toPath - The path being navigated to\r\n * @returns true if the interception should be dismissed\r\n */\r\nexport function shouldDismissIntercept(\r\n currentRoute: FileRoute | null,\r\n toPath: string\r\n): boolean {\r\n if (!currentRoute || !currentRoute.interceptInfo) {\r\n return false;\r\n }\r\n\r\n const normalizedTo = normalizePath(toPath);\r\n const interceptPath = normalizePath(currentRoute.interceptInfo.interceptPath);\r\n\r\n // Dismiss if navigating away from the intercepted path\r\n return !pathMatches(interceptPath, normalizedTo);\r\n}\r\n\r\n/**\r\n * Get route params from a path match.\r\n * \r\n * @param routePath - The route pattern with params (e.g., /photo/:id)\r\n * @param actualPath - The actual URL path (e.g., /photo/123)\r\n * @returns Object with matched params, or null if no match\r\n */\r\nexport function extractRouteParams(\r\n routePath: string,\r\n actualPath: string\r\n): Record<string, string> | null {\r\n const routeParts = routePath.split('/').filter(Boolean);\r\n const actualParts = actualPath.split('/').filter(Boolean);\r\n\r\n if (routeParts.length !== actualParts.length) {\r\n // Check for catch-all\r\n const hasCatchAll = routeParts.some(p => p.endsWith('+') || p.endsWith('*'));\r\n if (!hasCatchAll) {\r\n return null;\r\n }\r\n }\r\n\r\n const params: Record<string, string> = {};\r\n\r\n for (let i = 0; i < routeParts.length; i++) {\r\n const routePart = routeParts[i];\r\n const actualPart = actualParts[i];\r\n\r\n if (!routePart) continue;\r\n\r\n if (routePart.startsWith(':')) {\r\n // Dynamic param\r\n const paramName = routePart.slice(1).replace(/[+*]$/, '');\r\n\r\n if (routePart.endsWith('+') || routePart.endsWith('*')) {\r\n // Catch-all: collect remaining parts\r\n params[paramName] = actualParts.slice(i).join('/');\r\n break;\r\n }\r\n\r\n if (!actualPart) {\r\n if (routePart.endsWith('*')) {\r\n // Optional catch-all, can be empty\r\n params[paramName] = '';\r\n break;\r\n }\r\n return null;\r\n }\r\n\r\n params[paramName] = actualPart;\r\n } else if (routePart !== actualPart) {\r\n return null;\r\n }\r\n }\r\n\r\n return params;\r\n}\r\n\r\n// ============================================================================\r\n// Path Utilities\r\n// ============================================================================\r\n\r\n/**\r\n * Normalize a path for consistent comparison.\r\n */\r\nfunction normalizePath(path: string): string {\r\n let normalized = path.trim();\r\n\r\n // Ensure starts with /\r\n if (!normalized.startsWith('/')) {\r\n normalized = '/' + normalized;\r\n }\r\n\r\n // Remove trailing slash (except for root)\r\n if (normalized !== '/' && normalized.endsWith('/')) {\r\n normalized = normalized.slice(0, -1);\r\n }\r\n\r\n // Remove duplicate slashes\r\n normalized = normalized.replace(/\\/+/g, '/');\r\n\r\n return normalized;\r\n}\r\n\r\n/**\r\n * Check if a route path matches an actual path.\r\n * Handles dynamic segments (:param) and catch-alls.\r\n */\r\nfunction pathMatches(routePath: string, actualPath: string): boolean {\r\n const routeParts = routePath.split('/').filter(Boolean);\r\n const actualParts = actualPath.split('/').filter(Boolean);\r\n\r\n for (let i = 0; i < routeParts.length; i++) {\r\n const routePart = routeParts[i];\r\n const actualPart = actualParts[i];\r\n\r\n if (!routePart) continue;\r\n\r\n // Catch-all segment\r\n if (routePart.startsWith(':') && (routePart.endsWith('+') || routePart.endsWith('*'))) {\r\n return true; // Matches rest of path\r\n }\r\n\r\n // Dynamic segment\r\n if (routePart.startsWith(':')) {\r\n if (!actualPart) return false;\r\n continue; // Any value matches\r\n }\r\n\r\n // Static segment - must match exactly\r\n if (routePart !== actualPart) {\r\n return false;\r\n }\r\n }\r\n\r\n // Check lengths match (unless catch-all was present)\r\n return routeParts.length === actualParts.length;\r\n}\r\n\r\n"]}