prunelle 0.0.0-stage → 0.7.2

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 (222) hide show
  1. package/LICENSE +21 -0
  2. package/llms.txt +245 -0
  3. package/package.json +62 -4
  4. package/src/a11y/declaration.ts +373 -0
  5. package/src/a11y/index.ts +477 -0
  6. package/src/a11y/rgaa-map.ts +230 -0
  7. package/src/ambient.d.ts +6 -0
  8. package/src/attrs.ts +43 -0
  9. package/src/build/bundle.ts +661 -0
  10. package/src/build/byte-size.ts +11 -0
  11. package/src/build/carry.ts +57 -0
  12. package/src/build/client-entries.ts +107 -0
  13. package/src/build/client-plugin.ts +175 -0
  14. package/src/build/client-prune.ts +168 -0
  15. package/src/build/compile.ts +130 -0
  16. package/src/build/ecoindex.ts +238 -0
  17. package/src/build/files.ts +171 -0
  18. package/src/build/first-load.ts +235 -0
  19. package/src/build/graph.ts +237 -0
  20. package/src/build/index.ts +678 -0
  21. package/src/build/is-inside.ts +12 -0
  22. package/src/build/island-promote.ts +311 -0
  23. package/src/build/islands.ts +452 -0
  24. package/src/build/manifest.ts +204 -0
  25. package/src/build/output.ts +81 -0
  26. package/src/build/plugin-host.ts +294 -0
  27. package/src/build/precompress.ts +139 -0
  28. package/src/build/prerender.ts +288 -0
  29. package/src/build/reach.ts +200 -0
  30. package/src/build/render-rules.ts +205 -0
  31. package/src/build/report.ts +290 -0
  32. package/src/build/resolve.ts +52 -0
  33. package/src/build/routes.ts +342 -0
  34. package/src/build/server-entry.ts +38 -0
  35. package/src/build/static-headers.ts +112 -0
  36. package/src/build/static.ts +209 -0
  37. package/src/build/status-pages.ts +127 -0
  38. package/src/build/style-bundles.ts +526 -0
  39. package/src/cli/check-forms.ts +636 -0
  40. package/src/cli/check-imports.ts +31 -0
  41. package/src/cli/check-links.ts +632 -0
  42. package/src/cli/check-security.ts +64 -0
  43. package/src/cli/check.ts +409 -0
  44. package/src/cli/commands.ts +372 -0
  45. package/src/cli/docs.ts +403 -0
  46. package/src/cli/index.ts +70 -0
  47. package/src/cli/inspect.ts +406 -0
  48. package/src/cli/mcp-tools.ts +492 -0
  49. package/src/cli/mcp.ts +205 -0
  50. package/src/cli/new.ts +52 -0
  51. package/src/cli/render.ts +416 -0
  52. package/src/cli/upgrade-names.ts +209 -0
  53. package/src/cli/upgrade.ts +367 -0
  54. package/src/compiler/analyze.ts +651 -0
  55. package/src/compiler/ast.ts +82 -0
  56. package/src/compiler/browser-globals.ts +250 -0
  57. package/src/compiler/cacheability-private.ts +566 -0
  58. package/src/compiler/cacheability.ts +335 -0
  59. package/src/compiler/compliance-eco.ts +71 -0
  60. package/src/compiler/compliance-rgaa.ts +614 -0
  61. package/src/compiler/compliance-urls.ts +148 -0
  62. package/src/compiler/compliance.ts +653 -0
  63. package/src/compiler/data-keys.ts +302 -0
  64. package/src/compiler/dev-source.ts +87 -0
  65. package/src/compiler/dom-attrs.ts +452 -0
  66. package/src/compiler/dom.ts +641 -0
  67. package/src/compiler/emit.ts +131 -0
  68. package/src/compiler/expr-context.ts +587 -0
  69. package/src/compiler/foreign-imports.ts +88 -0
  70. package/src/compiler/index.ts +8 -0
  71. package/src/compiler/interactivity.ts +366 -0
  72. package/src/compiler/mistakes.ts +520 -0
  73. package/src/compiler/node-env.ts +50 -0
  74. package/src/compiler/patch.ts +97 -0
  75. package/src/compiler/props-body.ts +60 -0
  76. package/src/compiler/props.ts +511 -0
  77. package/src/compiler/scope.ts +635 -0
  78. package/src/compiler/server-only.ts +365 -0
  79. package/src/compiler/shared.ts +397 -0
  80. package/src/compiler/signal-reads.ts +246 -0
  81. package/src/compiler/slots.ts +227 -0
  82. package/src/compiler/spread-handlers.ts +295 -0
  83. package/src/compiler/ssr-helpers.ts +555 -0
  84. package/src/compiler/ssr-island.ts +90 -0
  85. package/src/compiler/ssr-prunelle-tags.ts +69 -0
  86. package/src/compiler/ssr.ts +525 -0
  87. package/src/context.ts +199 -0
  88. package/src/dev/child.ts +30 -0
  89. package/src/dev/error-log.ts +177 -0
  90. package/src/dev/host-check.ts +32 -0
  91. package/src/dev/index.ts +268 -0
  92. package/src/dev/modules.ts +68 -0
  93. package/src/dev/open-editor.ts +228 -0
  94. package/src/dev/protocol.ts +24 -0
  95. package/src/dev/queue.ts +79 -0
  96. package/src/dev/reload.ts +159 -0
  97. package/src/dev/supervisor.ts +212 -0
  98. package/src/dev/watchers.ts +276 -0
  99. package/src/dom/action.ts +187 -0
  100. package/src/dom/attrs.ts +84 -0
  101. package/src/dom/claim.ts +120 -0
  102. package/src/dom/extras.ts +579 -0
  103. package/src/dom/index.ts +329 -0
  104. package/src/dom/island.ts +318 -0
  105. package/src/dom/loop.ts +484 -0
  106. package/src/dom/revive.ts +36 -0
  107. package/src/eco/declaration.ts +328 -0
  108. package/src/eco/index.ts +69 -0
  109. package/src/index.ts +22 -0
  110. package/src/jsx-runtime.ts +566 -0
  111. package/src/plugins/config.ts +92 -0
  112. package/src/plugins/context.ts +109 -0
  113. package/src/plugins/index.ts +14 -0
  114. package/src/plugins/load.ts +90 -0
  115. package/src/plugins/order.ts +148 -0
  116. package/src/plugins/public.ts +15 -0
  117. package/src/plugins/requires.ts +47 -0
  118. package/src/plugins/services.ts +119 -0
  119. package/src/plugins/types.ts +278 -0
  120. package/src/reactivity/graph.ts +259 -0
  121. package/src/reactivity/index.ts +541 -0
  122. package/src/reactivity/selector.ts +78 -0
  123. package/src/reactivity/store.ts +252 -0
  124. package/src/server/action-flash.ts +158 -0
  125. package/src/server/action-protect.ts +199 -0
  126. package/src/server/action-registry.ts +78 -0
  127. package/src/server/action.ts +511 -0
  128. package/src/server/app-entry.ts +23 -0
  129. package/src/server/app-secret.ts +63 -0
  130. package/src/server/assets.ts +168 -0
  131. package/src/server/compress.ts +646 -0
  132. package/src/server/consent.ts +290 -0
  133. package/src/server/cookies.ts +153 -0
  134. package/src/server/document.ts +286 -0
  135. package/src/server/env.ts +47 -0
  136. package/src/server/errors.ts +396 -0
  137. package/src/server/form-schema.ts +337 -0
  138. package/src/server/health.ts +275 -0
  139. package/src/server/http.ts +588 -0
  140. package/src/server/index.ts +615 -0
  141. package/src/server/lifecycle.ts +75 -0
  142. package/src/server/loader.ts +131 -0
  143. package/src/server/page.ts +122 -0
  144. package/src/server/param-matchers.ts +112 -0
  145. package/src/server/plugin-host.ts +267 -0
  146. package/src/server/prerendered.ts +71 -0
  147. package/src/server/public.ts +20 -0
  148. package/src/server/rate-limit.ts +199 -0
  149. package/src/server/region.ts +96 -0
  150. package/src/server/request-body.ts +27 -0
  151. package/src/server/request-path.ts +73 -0
  152. package/src/server/request-scope.ts +22 -0
  153. package/src/server/route-cache.ts +541 -0
  154. package/src/server/route-table.ts +424 -0
  155. package/src/server/router.ts +261 -0
  156. package/src/server/routing.ts +388 -0
  157. package/src/server/sanitize-html.ts +309 -0
  158. package/src/server/security.ts +550 -0
  159. package/src/server/serve-handlers.ts +93 -0
  160. package/src/server/served-file.ts +128 -0
  161. package/src/server/standard-schema.ts +104 -0
  162. package/src/server/start.ts +143 -0
  163. package/src/server/static-dir.ts +246 -0
  164. package/src/server/stream.ts +233 -0
  165. package/src/ssr/consent-banner.ts +58 -0
  166. package/src/ssr/context.ts +399 -0
  167. package/src/ssr/index.ts +624 -0
  168. package/src/ssr/navigation.ts +96 -0
  169. package/src/ssr/region.ts +192 -0
  170. package/src/style.ts +96 -0
  171. package/src/test/browser.ts +201 -0
  172. package/src/test/index.ts +262 -0
  173. package/src/ts-plugin/diagnostics.ts +505 -0
  174. package/src/ts-plugin/fixes.ts +364 -0
  175. package/src/ts-plugin/index.ts +194 -0
  176. package/src/unrenderable.ts +35 -0
  177. package/templates/_shared/AGENTS.md +10 -0
  178. package/templates/_shared/CLAUDE.md +1 -0
  179. package/templates/_shared/gitignore +8 -0
  180. package/templates/_shared/mcp.json +11 -0
  181. package/templates/_shared/public/robots.txt +2 -0
  182. package/templates/_shared/src/routes/legal.tsx +22 -0
  183. package/templates/_shared/tsconfig.json +25 -0
  184. package/templates/app/.env.example +8 -0
  185. package/templates/app/package.json +22 -0
  186. package/templates/app/prunelle.config.ts +13 -0
  187. package/templates/app/src/auth.ts +12 -0
  188. package/templates/app/src/mail.ts +4 -0
  189. package/templates/app/src/routes/_layout.tsx +40 -0
  190. package/templates/app/src/routes/dashboard/_middleware.ts +3 -0
  191. package/templates/app/src/routes/dashboard/index.tsx +47 -0
  192. package/templates/app/src/routes/index.tsx +15 -0
  193. package/templates/app/src/routes/login.tsx +53 -0
  194. package/templates/app/src/routes/privacy.tsx +25 -0
  195. package/templates/app/src/styles/app.css +14 -0
  196. package/templates/app/tests/app.test.ts +73 -0
  197. package/templates/blog/content/posts/welcome.md +9 -0
  198. package/templates/blog/package.json +22 -0
  199. package/templates/blog/prunelle.config.ts +23 -0
  200. package/templates/blog/src/posts.ts +26 -0
  201. package/templates/blog/src/routes/_layout.tsx +25 -0
  202. package/templates/blog/src/routes/blog/[slug].tsx +31 -0
  203. package/templates/blog/src/routes/index.tsx +33 -0
  204. package/templates/blog/src/styles/app.css +15 -0
  205. package/templates/fullstack/package.json +19 -0
  206. package/templates/fullstack/prunelle.config.ts +6 -0
  207. package/templates/fullstack/src/actions/greet.ts +19 -0
  208. package/templates/fullstack/src/components/Counter.tsx +10 -0
  209. package/templates/fullstack/src/components/GreetForm.tsx +28 -0
  210. package/templates/fullstack/src/routes/_layout.tsx +18 -0
  211. package/templates/fullstack/src/routes/api/health.ts +5 -0
  212. package/templates/fullstack/src/routes/index.tsx +13 -0
  213. package/templates/fullstack/src/styles/app.css +39 -0
  214. package/templates/fullstack/tests/app.test.ts +37 -0
  215. package/templates/minimal/package.json +19 -0
  216. package/templates/minimal/prunelle.config.ts +6 -0
  217. package/templates/minimal/src/components/Counter.tsx +10 -0
  218. package/templates/minimal/src/routes/_layout.tsx +18 -0
  219. package/templates/minimal/src/routes/index.tsx +11 -0
  220. package/templates/minimal/src/styles/app.css +32 -0
  221. package/ts-plugin.cjs +4277 -0
  222. package/README.md +0 -3
@@ -0,0 +1,424 @@
1
+ // The page routes of a build, compiled once at startup: each route's modules, middlewares and document options, and the handler of a page nothing can intercept.
2
+
3
+ import type { BuildManifest, RouteManifestEntry } from '../build/index'
4
+ import type { Html, HydrateStrategy } from '../jsx-runtime'
5
+ import type { AppRuntimeContext } from '../plugins/index'
6
+ import type { DocumentOptions } from '../ssr/index'
7
+ import type { ActionRegistry } from './action-registry'
8
+ import type { ServedFile } from './assets'
9
+ import type { CompressionCache } from './compress'
10
+ import type { NormalizedConsentConfig } from './consent'
11
+ import type { CookieStore } from './cookies'
12
+ import type { DocumentHooks, HtmlHeaders } from './document'
13
+ import type { NotifyError } from './errors'
14
+ import type { DevTiming, RequestIdResolver } from './health'
15
+ import type { Middleware, RequestContext } from './http'
16
+ import type { LoadedLayoutModule, LoadedMiddlewareModule, LoadedPageModule } from './page'
17
+ import type { ParamMatcherMap } from './param-matchers'
18
+ import type { RequestKind } from './plugin-host'
19
+ import type { PrivateReadTracker, RouteCache, RouteCacheSingleflightResult, RouteCacheSpec } from './route-cache'
20
+ import type { FastHandler, FastStaticPageOptions } from './routing'
21
+ import type { TrustProxy } from './security'
22
+ import type { StreamTracker } from './stream'
23
+ import { runWithAppContext } from '../plugins/index'
24
+ import { createRenderContext, runWithRenderContext } from '../ssr/context'
25
+ import { raw, renderDocument, ssrChild, ssrIsland } from '../ssr/index'
26
+ import { ACTION_ERROR_COOKIE, hydrateActionErrorFlash } from './action'
27
+ import { compressedHtmlResponse, compressedHtmlStream, markCompressionHandled } from './compress'
28
+ import { addedInlineStyleHashes, headTagStyleHashes, mergeStyleHashes, resolveRenderedIslands, revivePreload } from './document'
29
+ import { endTimer, startTimer } from './health'
30
+ import { isNotFound, makeRequestContext, runChain } from './http'
31
+ import { allowedMethodsHeader, hasPublicFavicon, mergedHeadTags, pickPageIslandProps, stripHeadBody } from './page'
32
+ import { BUILTIN_PARAM_MATCHERS } from './param-matchers'
33
+ import { hasRegionHeader, invalidRegionResponse, requestedRegion, respondRegion, withRegionVary } from './region'
34
+ import { GATED_ROUTE_CACHE_CONTROL, isCacheableRequest, routeCacheKey, serveCachedHit, trackPrivateReads, withCacheControl } from './route-cache'
35
+ import { Router } from './router'
36
+ import { createFastStaticPageHandler, methodNotAllowed } from './routing'
37
+ import { styleHashesOf } from './security'
38
+ import { hasActionErrorCookie, isRead } from './serve-handlers'
39
+ import { STREAM_TAIL_MARK, streamDocument } from './stream'
40
+
41
+ export const HTTP_METHOD_EXPORTS: ReadonlySet<string> = new Set(['GET', 'HEAD', 'POST', 'PUT', 'PATCH', 'DELETE', 'OPTIONS'])
42
+
43
+ /** Returns the exported HTTP method handler for `method` only when `method` is a standard HTTP method export. */
44
+ export function routeMethodHandler(mod: LoadedPageModule, method: string): ((c: RequestContext) => Response | Promise<Response>) | undefined {
45
+ if (!HTTP_METHOD_EXPORTS.has(method))
46
+ return undefined
47
+ const handler = mod[method]
48
+ return typeof handler === 'function' ? handler as (c: RequestContext) => Response | Promise<Response> : undefined
49
+ }
50
+
51
+ export interface CompiledRoute {
52
+ entry: RouteManifestEntry
53
+ mod: LoadedPageModule
54
+ layouts: LoadedLayoutModule[]
55
+ dirMiddlewares: Middleware[]
56
+ /** Precomputed plugin + directory middlewares for non-rewritten static paths. */
57
+ middlewares: Middleware[]
58
+ /** Dynamic segments (`:param` / `*rest`), so the path names no single URL. */
59
+ dynamic: boolean
60
+ /** Options every document of this route shares; a request adds its body, head and islands. */
61
+ doc: DocumentOptions
62
+ headStyleHashes: string[]
63
+ }
64
+
65
+ function routeDocument(manifest: BuildManifest, entry: RouteManifestEntry, lang: string, alwaysLoadRuntime: boolean, navigation: DocumentOptions['navigation'], hasFavicon: boolean): DocumentOptions {
66
+ return {
67
+ body: '',
68
+ headTags: mergedHeadTags(manifest, entry),
69
+ lang,
70
+ runtimeScript: manifest.runtimeScript,
71
+ chunkImports: manifest.chunkImports,
72
+ alwaysLoadRuntime,
73
+ navigation,
74
+ hasFavicon,
75
+ regionScript: entry.usesRegion === true ? manifest.regionScript : undefined,
76
+ styles: entry.styles ?? manifest.styles,
77
+ }
78
+ }
79
+
80
+ type SharedFastOptions = Omit<FastStaticPageOptions, 'entry' | 'mod' | 'layouts' | 'doc' | 'reviveScript' | 'hasIslands' | 'hasLoad'>
81
+
82
+ export interface RouteTableOptions {
83
+ manifest: BuildManifest
84
+ modules: Record<string, unknown>
85
+ paramMatchers?: ParamMatcherMap | undefined
86
+ lang: string
87
+ alwaysLoadRuntime: boolean
88
+ navigation: DocumentOptions['navigation']
89
+ hasFavicon?: boolean | undefined
90
+ middlewaresFor: (path: string, kind?: RequestKind) => readonly Middleware[]
91
+ /** Whether a plugin rewrite, head hook, HTML transform or route may change what `path` answers. */
92
+ pluginIntercepts: (path: string) => boolean
93
+ fast: SharedFastOptions
94
+ }
95
+
96
+ export function compileRouteTable(options: RouteTableOptions): { router: Router<CompiledRoute>, fastStaticPages: Map<string, FastHandler> } {
97
+ const { manifest, modules, paramMatchers, lang, alwaysLoadRuntime, navigation, middlewaresFor, pluginIntercepts, fast } = options
98
+ const hasFavicon = options.hasFavicon ?? hasPublicFavicon(manifest)
99
+ const router = new Router<CompiledRoute>(paramMatchers ?? BUILTIN_PARAM_MATCHERS)
100
+ const fastStaticPages = new Map<string, FastHandler>()
101
+ for (const entry of manifest.routes) {
102
+ const mod = modules[entry.file] as LoadedPageModule
103
+ const layouts = entry.layouts.map(l => modules[l] as LoadedLayoutModule)
104
+ const dirMiddlewares = entry.middlewares.map(m => (modules[m] as LoadedMiddlewareModule).default)
105
+ const hasLoad = Boolean(entry.hasLoad && typeof mod.load === 'function')
106
+ const dynamic = entry.path.includes(':') || entry.path.includes('*')
107
+ const doc = routeDocument(manifest, entry, lang, alwaysLoadRuntime, navigation, hasFavicon)
108
+
109
+ // Zero-overhead path for a static route with no middleware, no <Head>/<Suspense>, no route cache, and no intercepting plugin hook
110
+ const canFastPath = middlewaresFor(entry.path, hasLoad ? 'dynamic' : 'static').length === 0
111
+ && !pluginIntercepts(entry.path) && !dynamic
112
+ && dirMiddlewares.length === 0 && !entry.usesRenderContext && entry.cache === undefined
113
+ && typeof mod.default === 'function' && mod.GET === undefined
114
+ if (canFastPath)
115
+ fastStaticPages.set(entry.path, createFastStaticPageHandler({ ...fast, entry, mod, layouts, doc, reviveScript: manifest.reviveScript, hasIslands: entry.islandChunks.length > 0, hasLoad }))
116
+
117
+ const routeEntry = entry.cache !== undefined && dirMiddlewares.length > 0 ? { ...entry, cache: { ...entry.cache, cacheControl: GATED_ROUTE_CACHE_CONTROL } } : entry
118
+ router.add(entry.path, { entry: routeEntry, mod, layouts, dirMiddlewares, middlewares: [...middlewaresFor(entry.path), ...dirMiddlewares], dynamic, doc, headStyleHashes: headTagStyleHashes(doc.headTags) })
119
+ }
120
+ return { router, fastStaticPages }
121
+ }
122
+
123
+ function lookupPrerendered<T>(map: ReadonlyMap<string, T>, staticPath: string | undefined): T | undefined {
124
+ if (staticPath === undefined)
125
+ return undefined
126
+ const normPath = staticPath.length > 1 && staticPath.endsWith('/') ? staticPath.slice(0, -1) : staticPath
127
+ return map.get(staticPath) ?? map.get(normPath)
128
+ }
129
+
130
+ async function renderRouteBody(route: CompiledRoute, data: unknown, pageProps: Record<string, unknown>, ctx: RequestContext): Promise<string> {
131
+ const { entry, mod, layouts } = route
132
+ let inner: string
133
+ if (entry.isIsland && entry.islandChunk !== undefined) {
134
+ inner = ssrIsland(
135
+ entry.islandChunk,
136
+ () => ssrChild(mod.default!(pageProps) as Html),
137
+ pickPageIslandProps(data, entry, mod),
138
+ entry.islandHydrate as HydrateStrategy | undefined,
139
+ true,
140
+ mod.default!.name,
141
+ )
142
+ }
143
+ else {
144
+ inner = ssrChild(await mod.default!(pageProps) as Html)
145
+ }
146
+ for (let i = layouts.length - 1; i >= 0; i--)
147
+ inner = ssrChild(await layouts[i]!.default({ children: raw(inner), url: ctx.url, params: ctx.params, locals: ctx.locals }) as Html)
148
+ return inner
149
+ }
150
+
151
+ export interface CompiledRouteRendererDeps {
152
+ manifest: BuildManifest
153
+ prerenderedMap: ReadonlyMap<string, ServedFile>
154
+ serveFile: (request: Request, file: ServedFile) => Promise<Response>
155
+ buildNotFoundResponse: (url?: URL, req?: Request, ctx?: RequestContext, routeFile?: string) => Promise<Response>
156
+ htmlHeaders: HtmlHeaders
157
+ resolveDocumentHead: DocumentHooks['resolveDocumentHead']
158
+ applyHtmlTransforms: DocumentHooks['applyHtmlTransforms']
159
+ hasHtmlTransformers: boolean
160
+ streamTimeout: number
161
+ /** Where a streamed page registers, so shutdown can end it. */
162
+ streams?: Pick<StreamTracker, 'trackPage'> | undefined
163
+ compressCache: CompressionCache | undefined
164
+ routeCache: RouteCache | undefined
165
+ notifyError: NotifyError
166
+ actions: ActionRegistry
167
+ rewrites: readonly ((pathname: string, ctx: RequestContext) => string | undefined)[]
168
+ trustProxy: TrustProxy
169
+ consent: NormalizedConsentConfig | undefined
170
+ resolveRequestId: RequestIdResolver
171
+ serverAppCtx: AppRuntimeContext
172
+ }
173
+
174
+ type RenderedPageOutput =
175
+ | { kind: 'stream', response: Response }
176
+ | { kind: 'html', html: string, headers: Record<string, string> }
177
+
178
+ async function renderPageDocument(
179
+ deps: CompiledRouteRendererDeps,
180
+ route: CompiledRoute,
181
+ data: unknown,
182
+ pageProps: Record<string, unknown>,
183
+ ctx: RequestContext,
184
+ hasFlash: boolean,
185
+ disableTimeout?: () => void,
186
+ timing?: DevTiming,
187
+ privateTracker?: PrivateReadTracker,
188
+ ): Promise<RenderedPageOutput> {
189
+ const { entry, doc } = route
190
+ const renderStart = startTimer(timing)
191
+ const rctx = createRenderContext(undefined, undefined, privateTracker !== undefined ? privateTracker.consent : ctx.consent, error => deps.notifyError(error, ctx.request, 'route', ctx.requestId))
192
+ const body = await runWithRenderContext(rctx, () => renderRouteBody(route, data, pageProps, privateTracker?.ctx ?? ctx))
193
+ if (hasFlash)
194
+ ctx.cookies.delete(ACTION_ERROR_COOKIE)
195
+ const docHead = await deps.resolveDocumentHead(rctx, doc.headTags as readonly string[] | undefined, ctx.url, ctx.request, ctx)
196
+ const renderedIslands = resolveRenderedIslands(rctx, body)
197
+ const isStreamed = rctx.pending.length > 0
198
+ const hasIslands = renderedIslands.hasIslands || (isStreamed && entry.islandChunks.length > 0)
199
+ const preloadChunks = [...isStreamed ? entry.eagerIslandChunks ?? entry.islandChunks : renderedIslands.eagerChunks, ...revivePreload(rctx, deps.manifest.reviveScript)]
200
+ const hasRegions = rctx.regionNames.size > 0
201
+ const trustedStyleHashes = mergeStyleHashes(route.headStyleHashes, docHead.styleHashes, styleHashesOf(rctx.inlineStyles))
202
+
203
+ if (isStreamed) {
204
+ endTimer(timing, 'render', renderStart)
205
+ const streamStart = startTimer(timing)
206
+ if (ctx.request.method === 'HEAD') {
207
+ rctx.aborted = true
208
+ endTimer(timing, 'stream', streamStart)
209
+ return { kind: 'stream', response: markCompressionHandled(new Response(null, { status: 200, headers: withRegionVary(deps.htmlHeaders(hasIslands, true, true, trustedStyleHashes), hasRegions) })) }
210
+ }
211
+ disableTimeout?.()
212
+ const docShell = renderDocument({ ...doc, body: body + STREAM_TAIL_MARK, head: docHead.head, lang: docHead.lang, htmlAttrs: docHead.htmlAttrs, preloadChunks, hasIslands, hasSuspense: true })
213
+ const shell = deps.hasHtmlTransformers ? await deps.applyHtmlTransforms(docShell, ctx.url, ctx.request, ctx) : docShell
214
+ const streamStyleHashes = mergeStyleHashes(trustedStyleHashes, addedInlineStyleHashes(docShell, shell))
215
+ rctx.headersFlushed = true
216
+ endTimer(timing, 'stream', streamStart)
217
+ const transformChunk = deps.hasHtmlTransformers ? (html: string) => deps.applyHtmlTransforms(html, ctx.url, ctx.request, ctx) : undefined
218
+ const response = await compressedHtmlStream(streamDocument(shell, rctx, deps.streamTimeout, error => deps.notifyError(error, ctx.request, 'route', ctx.requestId), transformChunk, deps.streams), 200, withRegionVary(deps.htmlHeaders(hasIslands, true, true, streamStyleHashes), hasRegions), ctx.request, deps.compressCache)
219
+ return { kind: 'stream', response }
220
+ }
221
+
222
+ const docHtml = renderDocument({ ...doc, body, head: docHead.head, lang: docHead.lang, htmlAttrs: docHead.htmlAttrs, preloadChunks, hasIslands })
223
+ const html = deps.hasHtmlTransformers ? await deps.applyHtmlTransforms(docHtml, ctx.url, ctx.request, ctx) : docHtml
224
+ const finalStyleHashes = mergeStyleHashes(trustedStyleHashes, addedInlineStyleHashes(docHtml, html))
225
+ endTimer(timing, 'render', renderStart)
226
+ return { kind: 'html', html, headers: withRegionVary(deps.htmlHeaders(hasIslands, false, true, finalStyleHashes), hasRegions) }
227
+ }
228
+
229
+ async function revalidateCompiledRoute(
230
+ deps: CompiledRouteRendererDeps,
231
+ route: CompiledRoute,
232
+ url: URL,
233
+ params: Record<string, string>,
234
+ cacheKey: string,
235
+ cacheSpec: RouteCacheSpec,
236
+ middlewares: readonly Middleware[],
237
+ ): Promise<void> {
238
+ const routeCache = deps.routeCache
239
+ if (routeCache === undefined)
240
+ return
241
+ await runWithAppContext(deps.serverAppCtx, async () => {
242
+ const bgReq = new Request(url.href, { method: 'GET' })
243
+ const bgReqId = deps.resolveRequestId(bgReq)
244
+ const { ctx, cookieStore } = makeRequestContext(bgReq, { ...params }, { trustProxy: deps.trustProxy, url, consent: deps.consent, requestId: bgReqId })
245
+ for (const rewrite of deps.rewrites)
246
+ rewrite(url.pathname, ctx)
247
+ await deps.actions.run(ctx, async () => {
248
+ let rendered: RenderedPageOutput | undefined
249
+ let nonCacheable = false
250
+ const res = await runChain(ctx, middlewares, async () => {
251
+ const tracker = trackPrivateReads(ctx)
252
+ let data: unknown
253
+ if (route.entry.hasLoad && typeof route.mod.load === 'function') {
254
+ try {
255
+ data = await route.mod.load(tracker.ctx)
256
+ }
257
+ catch (error) {
258
+ if (isNotFound(error)) {
259
+ nonCacheable = true
260
+ return new Response(null, { status: 404 })
261
+ }
262
+ throw error
263
+ }
264
+ if (isNotFound(data) || data instanceof Response) {
265
+ nonCacheable = true
266
+ return data instanceof Response ? data : new Response(null, { status: 404 })
267
+ }
268
+ }
269
+ const pageProps: Record<string, unknown> = { params: ctx.params, locals: tracker.locals, url: ctx.url, ...(data !== undefined ? { data } : {}) }
270
+ rendered = await renderPageDocument(deps, route, data, pageProps, ctx, false, undefined, undefined, tracker)
271
+ if (tracker.didReadPrivate())
272
+ nonCacheable = true
273
+ return rendered.kind === 'html'
274
+ ? new Response(null, { status: 200, headers: rendered.headers })
275
+ : rendered.response
276
+ })
277
+ if (!nonCacheable && rendered?.kind === 'html' && res.status === 200 && !cookieStore.hasChanges)
278
+ routeCache.set(cacheKey, rendered.html, withCacheControl(rendered.headers, cacheSpec.cacheControl), cacheSpec)
279
+ else
280
+ routeCache.delete(cacheKey)
281
+ })
282
+ })
283
+ }
284
+
285
+ async function runCompiledRouteLoad(
286
+ deps: CompiledRouteRendererDeps,
287
+ route: CompiledRoute,
288
+ ctx: RequestContext,
289
+ timing?: DevTiming,
290
+ ): Promise<{ kind: 'response', response: Response } | { kind: 'data', data: unknown }> {
291
+ const { entry, mod } = route
292
+ let data: unknown
293
+ if (entry.hasLoad && typeof mod.load === 'function') {
294
+ const loadStart = startTimer(timing)
295
+ try {
296
+ data = await mod.load(ctx)
297
+ }
298
+ catch (error) {
299
+ if (isNotFound(error))
300
+ return { kind: 'response', response: await deps.buildNotFoundResponse(ctx.url, ctx.request, ctx, entry.file) }
301
+ throw error
302
+ }
303
+ endTimer(timing, 'load', loadStart)
304
+ }
305
+ if (isNotFound(data))
306
+ return { kind: 'response', response: await deps.buildNotFoundResponse(ctx.url, ctx.request, ctx, entry.file) }
307
+ if (data instanceof Response)
308
+ return { kind: 'response', response: data }
309
+ return { kind: 'data', data }
310
+ }
311
+
312
+ async function resolvePrerenderedOrApi(
313
+ deps: CompiledRouteRendererDeps,
314
+ route: CompiledRoute,
315
+ ctx: RequestContext,
316
+ isRegion: boolean,
317
+ staticPath?: string,
318
+ ): Promise<Response | undefined> {
319
+ const { entry, mod } = route
320
+ if (isRead(ctx.request)) {
321
+ const pre = lookupPrerendered(deps.prerenderedMap, staticPath)
322
+ if (pre !== undefined && !isRegion && (ctx.request.method === 'HEAD' || !hasActionErrorCookie(ctx.request)))
323
+ return deps.serveFile(ctx.request, pre)
324
+ if (pre === undefined && entry.prerender === true && entry.prerendered !== undefined && route.dynamic)
325
+ return deps.buildNotFoundResponse(ctx.url, ctx.request, ctx, entry.file)
326
+ }
327
+ const method = ctx.request.method.toUpperCase()
328
+ const methodHandler = routeMethodHandler(mod, method)
329
+ if (methodHandler !== undefined)
330
+ return await methodHandler(ctx)
331
+ if (method === 'HEAD' && typeof mod.GET === 'function')
332
+ return stripHeadBody(await mod.GET(ctx))
333
+ return undefined
334
+ }
335
+
336
+ export function createCompiledRouteRenderer(deps: CompiledRouteRendererDeps) {
337
+ return async function renderCompiledRoute(
338
+ route: CompiledRoute,
339
+ ctx: RequestContext,
340
+ cookieStore: CookieStore,
341
+ disableTimeout?: () => void,
342
+ staticPath?: string,
343
+ timing?: DevTiming,
344
+ middlewares: readonly Middleware[] = route.middlewares,
345
+ ): Promise<Response> {
346
+ const { entry, mod, doc } = route
347
+ const isRegion = hasRegionHeader(ctx.request)
348
+
349
+ const early = await resolvePrerenderedOrApi(deps, route, ctx, isRegion, staticPath)
350
+ if (early !== undefined)
351
+ return early
352
+
353
+ if (typeof mod.default !== 'function' || !isRead(ctx.request))
354
+ return methodNotAllowed(allowedMethodsHeader(mod))
355
+ if (isRegion && requestedRegion(ctx.request) === undefined)
356
+ return invalidRegionResponse(ctx.request)
357
+
358
+ const hasFlash = ctx.request.method === 'GET' && !isRegion && hasActionErrorCookie(ctx.request) && hydrateActionErrorFlash(ctx)
359
+ const cacheSpec = deps.routeCache !== undefined && !isRegion && !hasFlash && isCacheableRequest(ctx.request) ? entry.cache : undefined
360
+ const cacheKey = cacheSpec !== undefined ? routeCacheKey(ctx.url) : undefined
361
+ let inflight: PromiseWithResolvers<RouteCacheSingleflightResult | undefined> | undefined
362
+ if (cacheSpec !== undefined && cacheKey !== undefined && deps.routeCache !== undefined) {
363
+ const cached = serveCachedHit(
364
+ deps.routeCache,
365
+ cacheKey,
366
+ ctx.request,
367
+ ctx.requestId,
368
+ deps.compressCache,
369
+ () => revalidateCompiledRoute(deps, route, ctx.url, ctx.params, cacheKey, cacheSpec, middlewares),
370
+ error => deps.notifyError(error, ctx.request, 'route', ctx.requestId),
371
+ )
372
+ if (cached !== undefined)
373
+ return cached
374
+ const existing = deps.routeCache.getInflight(cacheKey)
375
+ if (existing !== undefined) {
376
+ const shared = await existing
377
+ if (shared !== undefined)
378
+ return deps.routeCache.respondMiss(shared.entry, shared.html, shared.headers, ctx.request, ctx.requestId, deps.compressCache)
379
+ }
380
+ else {
381
+ inflight = Promise.withResolvers<RouteCacheSingleflightResult | undefined>()
382
+ void inflight.promise.catch(() => undefined)
383
+ deps.routeCache.trackInflight(cacheKey, inflight.promise)
384
+ }
385
+ }
386
+
387
+ try {
388
+ const privateTracker = cacheSpec !== undefined ? trackPrivateReads(ctx) : undefined
389
+ const loaded = await runCompiledRouteLoad(deps, route, privateTracker?.ctx ?? ctx, timing)
390
+ if (loaded.kind === 'response')
391
+ return loaded.response
392
+ const pageProps: Record<string, unknown> = { params: ctx.params, locals: privateTracker?.locals ?? ctx.locals, url: ctx.url, ...(loaded.data !== undefined ? { data: loaded.data } : {}) }
393
+
394
+ if (isRegion) {
395
+ return respondRegion(
396
+ ctx.request, mod, pageProps, entry.path, deps.htmlHeaders,
397
+ rctx => deps.resolveDocumentHead(rctx, doc.headTags as readonly string[] | undefined, ctx.url, ctx.request, ctx),
398
+ deps.streamTimeout, error => deps.notifyError(error, ctx.request, 'route', ctx.requestId),
399
+ deps.hasHtmlTransformers ? html => deps.applyHtmlTransforms(html, ctx.url, ctx.request, ctx) : undefined,
400
+ )
401
+ }
402
+
403
+ const rendered = await renderPageDocument(deps, route, loaded.data, pageProps, ctx, hasFlash, disableTimeout, timing, privateTracker)
404
+ if (rendered.kind === 'stream')
405
+ return rendered.response
406
+ if (privateTracker?.didReadPrivate())
407
+ return compressedHtmlResponse(rendered.html, 200, withCacheControl(rendered.headers, 'private, no-store'), ctx.request, deps.compressCache)
408
+ if (cacheSpec !== undefined && cacheKey !== undefined && deps.routeCache !== undefined && !cookieStore.hasChanges) {
409
+ const cachedHeaders = withCacheControl(rendered.headers, cacheSpec.cacheControl)
410
+ const stored = deps.routeCache.set(cacheKey, rendered.html, cachedHeaders, cacheSpec)
411
+ inflight?.resolve({ entry: stored, html: rendered.html, headers: cachedHeaders })
412
+ return deps.routeCache.respondMiss(stored, rendered.html, cachedHeaders, ctx.request, ctx.requestId, deps.compressCache)
413
+ }
414
+ return compressedHtmlResponse(rendered.html, 200, rendered.headers, ctx.request, deps.compressCache)
415
+ }
416
+ catch (error) {
417
+ inflight?.reject(error)
418
+ throw error
419
+ }
420
+ finally {
421
+ inflight?.resolve(undefined)
422
+ }
423
+ }
424
+ }
@@ -0,0 +1,261 @@
1
+ // File-based route matcher: static > matched param > param > optional > catch-all priority sorting + param extraction.
2
+
3
+ import type { ParamMatcher, ParamMatcherMap } from './param-matchers'
4
+ import type { RequestPath } from './request-path'
5
+ import { BUILTIN_PARAM_MATCHERS, parsePatternSegment } from './param-matchers'
6
+ import { decodeRequestPath } from './request-path'
7
+
8
+ const enum SegmentKind {
9
+ Static = 0,
10
+ Param = 1,
11
+ OptionalParam = 2,
12
+ CatchAll = 3,
13
+ }
14
+
15
+ interface CompiledSegment {
16
+ kind: SegmentKind
17
+ /** Exact literal for Static, parameter name for Param/OptionalParam/CatchAll. */
18
+ value: string
19
+ matcherName?: string | undefined
20
+ matcher?: ParamMatcher | undefined
21
+ }
22
+
23
+ interface RoutePattern<T> {
24
+ path: string
25
+ segments: CompiledSegment[]
26
+ isStatic: boolean
27
+ hasCatchAll: boolean
28
+ /** Number of optional segments omitted to produce this concrete match variant. */
29
+ omittedOptionals: number
30
+ /** The catch-all takes a segment holding an encoded separator, left encoded. */
31
+ encodedSlashes: boolean
32
+ data: T
33
+ }
34
+
35
+ export interface RouteOptions {
36
+ encodedSlashes?: boolean | undefined
37
+ }
38
+
39
+ export interface RouteMatch<T> {
40
+ data: T
41
+ params: Record<string, string>
42
+ }
43
+
44
+ const MAX_OPTIONAL_SEGMENTS = 6
45
+
46
+ function normalizePath(path: string): string {
47
+ return path.length > 1 && path.endsWith('/') ? path.slice(0, -1) : path
48
+ }
49
+
50
+ /**
51
+ * Segment specificity rank:
52
+ * Static (9) > SpecificMatchedParam (8) > SlugMatchedParam (7) > Param (6) > OptionalSpecificMatched (5) > OptionalSlugMatched (4) > OptionalParam (3) > End (2) > MatchedCatchAll (1) > CatchAll (0).
53
+ * Lexicographic comparison guarantees exact static > matched param > param > optional > catch-all for any shared prefix
54
+ * (e.g. `/docs/:slug` beats `/docs/:section/*rest`, `/docs/:a/:b` beats `/docs/*rest`, and `integer`/`uuid` beat `slug`).
55
+ */
56
+ function segmentRank(seg: CompiledSegment | undefined): number {
57
+ if (seg === undefined)
58
+ return 2
59
+ if (seg.kind === SegmentKind.Static)
60
+ return 9
61
+ if (seg.kind === SegmentKind.Param)
62
+ return seg.matcherName === undefined ? 6 : (seg.matcherName === 'slug' ? 7 : 8)
63
+ if (seg.kind === SegmentKind.OptionalParam)
64
+ return seg.matcherName === undefined ? 3 : (seg.matcherName === 'slug' ? 4 : 5)
65
+ return seg.matcherName !== undefined ? 1 : 0
66
+ }
67
+
68
+ function compareRoutes<T>(a: RoutePattern<T>, b: RoutePattern<T>): number {
69
+ const len = Math.max(a.segments.length, b.segments.length)
70
+ for (let i = 0; i < len; i++) {
71
+ const diff = segmentRank(b.segments[i]) - segmentRank(a.segments[i])
72
+ if (diff !== 0)
73
+ return diff
74
+ }
75
+ return a.omittedOptionals - b.omittedOptionals
76
+ }
77
+
78
+ function toCompiledSegment(seg: string, matchers: ParamMatcherMap): CompiledSegment {
79
+ const parsed = parsePatternSegment(seg)
80
+ const matcher = parsed.matcherName !== undefined ? matchers[parsed.matcherName] : undefined
81
+ if (parsed.kind === 'catchall')
82
+ return { kind: SegmentKind.CatchAll, value: parsed.value, matcherName: parsed.matcherName, matcher }
83
+ if (parsed.kind === 'optional')
84
+ return { kind: SegmentKind.OptionalParam, value: parsed.value, matcherName: parsed.matcherName, matcher }
85
+ if (parsed.kind === 'param')
86
+ return { kind: SegmentKind.Param, value: parsed.value, matcherName: parsed.matcherName, matcher }
87
+ return { kind: SegmentKind.Static, value: parsed.value }
88
+ }
89
+
90
+ /** Expands optional segments into concrete flat variants (include-first, omit-second) so matching runs with zero recursion. */
91
+ function expandOptionalVariants(base: CompiledSegment[]): { segments: CompiledSegment[], omitted: number }[] {
92
+ const optIndexes: number[] = []
93
+ for (let i = 0; i < base.length; i++) {
94
+ if (base[i]!.kind === SegmentKind.OptionalParam)
95
+ optIndexes.push(i)
96
+ }
97
+ if (optIndexes.length === 0)
98
+ return [{ segments: base, omitted: 0 }]
99
+ if (optIndexes.length > MAX_OPTIONAL_SEGMENTS)
100
+ throw new Error(`prunelle: route pattern has ${optIndexes.length} optional segments (maximum supported is ${MAX_OPTIONAL_SEGMENTS}).`)
101
+
102
+ const variants: { segments: CompiledSegment[], omitted: number }[] = []
103
+ const build = (optPos: number, omittedSet: Set<number>): void => {
104
+ if (optPos === optIndexes.length) {
105
+ const segments = omittedSet.size === 0 ? base : base.filter((_, idx) => !omittedSet.has(idx))
106
+ variants.push({ segments, omitted: omittedSet.size })
107
+ return
108
+ }
109
+ build(optPos + 1, omittedSet)
110
+ omittedSet.add(optIndexes[optPos]!)
111
+ build(optPos + 1, omittedSet)
112
+ omittedSet.delete(optIndexes[optPos]!)
113
+ }
114
+ build(0, new Set())
115
+ return variants
116
+ }
117
+
118
+ function compileRoutePatterns<T>(path: string, data: T, matchers: ParamMatcherMap, options?: RouteOptions): RoutePattern<T>[] {
119
+ const norm = normalizePath(path)
120
+ const clean = norm === '/' ? '' : norm.replace(/^\/|\/$/g, '')
121
+ const rawSegments = clean === '' ? [] : clean.split('/')
122
+ const baseSegments: CompiledSegment[] = []
123
+ let isStatic = true
124
+ let hasCatchAll = false
125
+
126
+ for (let i = 0; i < rawSegments.length; i++) {
127
+ const compiled = toCompiledSegment(rawSegments[i]!, matchers)
128
+ if (compiled.kind !== SegmentKind.Static)
129
+ isStatic = false
130
+ if (compiled.kind === SegmentKind.CatchAll)
131
+ hasCatchAll = true
132
+ baseSegments.push(compiled)
133
+ }
134
+
135
+ const encodedSlashes = options?.encodedSlashes === true
136
+ if (isStatic)
137
+ return [{ path: norm, segments: baseSegments, isStatic: true, hasCatchAll: false, omittedOptionals: 0, encodedSlashes, data }]
138
+
139
+ return expandOptionalVariants(baseSegments).map(({ segments, omitted }) => ({
140
+ path: norm,
141
+ segments,
142
+ isStatic: false,
143
+ hasCatchAll,
144
+ omittedOptionals: omitted,
145
+ encodedSlashes,
146
+ data,
147
+ }))
148
+ }
149
+
150
+ function segmentMatchesParam(seg: CompiledSegment, value: string): boolean {
151
+ if (seg.matcherName !== undefined)
152
+ return seg.matcher !== undefined && seg.matcher(value)
153
+ return true
154
+ }
155
+
156
+ export class Router<T> {
157
+ readonly #staticRoutes = new Map<string, T>()
158
+ readonly #dynamicRoutes: RoutePattern<T>[] = []
159
+ readonly #matchers: ParamMatcherMap
160
+ #sorted = true
161
+
162
+ constructor(matchers: ParamMatcherMap = BUILTIN_PARAM_MATCHERS) {
163
+ this.#matchers = matchers
164
+ }
165
+
166
+ /** Adds the route at `path`, or replaces the one already there. */
167
+ add(path: string, data: T, options?: RouteOptions): void {
168
+ const compiled = compileRoutePatterns(path, data, this.#matchers, options)
169
+ const first = compiled[0]!
170
+ if (first.isStatic) {
171
+ this.#staticRoutes.set(first.path, data)
172
+ return
173
+ }
174
+ for (let i = this.#dynamicRoutes.length - 1; i >= 0; i--) {
175
+ if (this.#dynamicRoutes[i]!.path === first.path)
176
+ this.#dynamicRoutes.splice(i, 1)
177
+ }
178
+ for (const pattern of compiled)
179
+ this.#dynamicRoutes.push(pattern)
180
+ this.#sorted = false
181
+ }
182
+
183
+ /** Matches a decoded request path; a string is a URL pathname, decoded first. */
184
+ match(input: string | RequestPath): RouteMatch<T> | undefined {
185
+ const path = typeof input === 'string' ? decodeRequestPath(input) : input
186
+ if (path === undefined)
187
+ return undefined
188
+
189
+ if (path.staticPath !== undefined) {
190
+ const exact = this.#staticRoutes.get(normalizePath(path.staticPath))
191
+ if (exact !== undefined)
192
+ return { data: exact, params: {} }
193
+ }
194
+
195
+ const dynLen = this.#dynamicRoutes.length
196
+ if (dynLen === 0)
197
+ return undefined
198
+
199
+ if (!this.#sorted) {
200
+ this.#dynamicRoutes.sort(compareRoutes)
201
+ this.#sorted = true
202
+ }
203
+
204
+ const parts = path.segments
205
+ // A param never receives a separator, a NUL or a dot segment, encoded or not: joined into a path, it would walk out of the folder it names.
206
+ const dotSegment = (k: number): boolean => parts[k] === '.' || parts[k] === '..'
207
+ const refused = (k: number): boolean => path.encoded?.has(k) === true || dotSegment(k)
208
+
209
+ for (let i = 0; i < dynLen; i++) {
210
+ const route = this.#dynamicRoutes[i]!
211
+ const segs = route.segments
212
+
213
+ if (!route.hasCatchAll && parts.length !== segs.length)
214
+ continue
215
+ if (route.hasCatchAll && parts.length < segs.length - 1)
216
+ continue
217
+
218
+ let matched = true
219
+ for (let j = 0; j < segs.length; j++) {
220
+ const seg = segs[j]!
221
+ if (seg.kind === SegmentKind.CatchAll) {
222
+ for (let k = j; k < parts.length; k++) {
223
+ if ((route.encodedSlashes ? dotSegment(k) : refused(k)) || !segmentMatchesParam(seg, parts[k]!)) {
224
+ matched = false
225
+ break
226
+ }
227
+ }
228
+ break
229
+ }
230
+ if (seg.kind === SegmentKind.Static) {
231
+ if (seg.value !== parts[j] || path.encoded?.has(j) === true) {
232
+ matched = false
233
+ break
234
+ }
235
+ }
236
+ else if (refused(j) || !segmentMatchesParam(seg, parts[j]!)) {
237
+ matched = false
238
+ break
239
+ }
240
+ }
241
+
242
+ if (!matched)
243
+ continue
244
+
245
+ // Allocate params only for the winning route.
246
+ const params: Record<string, string> = {}
247
+ for (let j = 0; j < segs.length; j++) {
248
+ const seg = segs[j]!
249
+ if (seg.kind === SegmentKind.CatchAll) {
250
+ params[seg.value] = parts.slice(j).join('/')
251
+ break
252
+ }
253
+ if (seg.kind === SegmentKind.Param || seg.kind === SegmentKind.OptionalParam)
254
+ params[seg.value] = parts[j]!
255
+ }
256
+ return { data: route.data, params }
257
+ }
258
+
259
+ return undefined
260
+ }
261
+ }