@rangojs/router 0.0.0-experimental.10 → 0.0.0-experimental.100
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +9 -0
- package/README.md +1037 -4
- package/dist/bin/rango.js +1619 -157
- package/dist/vite/index.js +5762 -2301
- package/dist/vite/plugins/cloudflare-protocol-loader-hook.mjs +76 -0
- package/package.json +71 -63
- package/skills/breadcrumbs/SKILL.md +252 -0
- package/skills/cache-guide/SKILL.md +294 -0
- package/skills/caching/SKILL.md +93 -23
- package/skills/composability/SKILL.md +172 -0
- package/skills/debug-manifest/SKILL.md +12 -8
- package/skills/document-cache/SKILL.md +18 -16
- package/skills/fonts/SKILL.md +6 -4
- package/skills/handler-use/SKILL.md +364 -0
- package/skills/hooks/SKILL.md +367 -71
- package/skills/host-router/SKILL.md +218 -0
- package/skills/i18n/SKILL.md +276 -0
- package/skills/intercept/SKILL.md +176 -8
- package/skills/layout/SKILL.md +124 -3
- package/skills/links/SKILL.md +304 -25
- package/skills/loader/SKILL.md +474 -47
- package/skills/middleware/SKILL.md +207 -37
- package/skills/migrate-nextjs/SKILL.md +562 -0
- package/skills/migrate-react-router/SKILL.md +769 -0
- package/skills/mime-routes/SKILL.md +15 -11
- package/skills/parallel/SKILL.md +272 -1
- package/skills/prerender/SKILL.md +467 -65
- package/skills/rango/SKILL.md +89 -21
- package/skills/response-routes/SKILL.md +152 -91
- package/skills/route/SKILL.md +305 -14
- package/skills/router-setup/SKILL.md +210 -32
- package/skills/server-actions/SKILL.md +739 -0
- package/skills/streams-and-websockets/SKILL.md +283 -0
- package/skills/theme/SKILL.md +9 -8
- package/skills/typesafety/SKILL.md +333 -86
- package/skills/use-cache/SKILL.md +324 -0
- package/skills/view-transitions/SKILL.md +212 -0
- package/src/__internal.ts +102 -4
- package/src/bin/rango.ts +312 -15
- package/src/browser/action-coordinator.ts +97 -0
- package/src/browser/action-response-classifier.ts +99 -0
- package/src/browser/app-shell.ts +52 -0
- package/src/browser/app-version.ts +14 -0
- package/src/browser/event-controller.ts +136 -68
- package/src/browser/history-state.ts +80 -0
- package/src/browser/intercept-utils.ts +52 -0
- package/src/browser/link-interceptor.ts +24 -4
- package/src/browser/logging.ts +55 -0
- package/src/browser/merge-segment-loaders.ts +20 -12
- package/src/browser/navigation-bridge.ts +374 -561
- package/src/browser/navigation-client.ts +228 -70
- package/src/browser/navigation-store.ts +97 -55
- package/src/browser/navigation-transaction.ts +297 -0
- package/src/browser/network-error-handler.ts +61 -0
- package/src/browser/partial-update.ts +376 -315
- package/src/browser/prefetch/cache.ts +314 -0
- package/src/browser/prefetch/fetch.ts +282 -0
- package/src/browser/prefetch/observer.ts +65 -0
- package/src/browser/prefetch/policy.ts +48 -0
- package/src/browser/prefetch/queue.ts +191 -0
- package/src/browser/prefetch/resource-ready.ts +77 -0
- package/src/browser/rango-state.ts +152 -0
- package/src/browser/react/Link.tsx +255 -71
- package/src/browser/react/NavigationProvider.tsx +152 -24
- package/src/browser/react/context.ts +11 -0
- package/src/browser/react/filter-segment-order.ts +55 -0
- package/src/browser/react/index.ts +15 -12
- package/src/browser/react/location-state-shared.ts +95 -53
- package/src/browser/react/location-state.ts +60 -15
- package/src/browser/react/mount-context.ts +6 -1
- package/src/browser/react/nonce-context.ts +23 -0
- package/src/browser/react/shallow-equal.ts +27 -0
- package/src/browser/react/use-action.ts +29 -51
- package/src/browser/react/use-client-cache.ts +5 -3
- package/src/browser/react/use-handle.ts +30 -120
- package/src/browser/react/use-link-status.ts +6 -5
- package/src/browser/react/use-navigation.ts +44 -65
- package/src/browser/react/use-params.ts +78 -0
- package/src/browser/react/use-pathname.ts +47 -0
- package/src/browser/react/use-reverse.ts +99 -0
- package/src/browser/react/use-router.ts +83 -0
- package/src/browser/react/use-search-params.ts +56 -0
- package/src/browser/react/use-segments.ts +85 -99
- package/src/browser/response-adapter.ts +73 -0
- package/src/browser/rsc-router.tsx +246 -64
- package/src/browser/scroll-restoration.ts +127 -52
- package/src/browser/segment-reconciler.ts +243 -0
- package/src/browser/segment-structure-assert.ts +16 -0
- package/src/browser/server-action-bridge.ts +510 -603
- package/src/browser/shallow.ts +6 -1
- package/src/browser/types.ts +158 -48
- package/src/browser/validate-redirect-origin.ts +29 -0
- package/src/build/generate-manifest.ts +84 -23
- package/src/build/generate-route-types.ts +39 -828
- package/src/build/index.ts +4 -5
- package/src/build/route-trie.ts +85 -32
- package/src/build/route-types/ast-helpers.ts +25 -0
- package/src/build/route-types/ast-route-extraction.ts +98 -0
- package/src/build/route-types/codegen.ts +102 -0
- package/src/build/route-types/include-resolution.ts +418 -0
- package/src/build/route-types/param-extraction.ts +48 -0
- package/src/build/route-types/per-module-writer.ts +128 -0
- package/src/build/route-types/router-processing.ts +618 -0
- package/src/build/route-types/scan-filter.ts +85 -0
- package/src/build/runtime-discovery.ts +231 -0
- package/src/cache/background-task.ts +34 -0
- package/src/cache/cache-key-utils.ts +44 -0
- package/src/cache/cache-policy.ts +125 -0
- package/src/cache/cache-runtime.ts +342 -0
- package/src/cache/cache-scope.ts +167 -307
- package/src/cache/cf/cf-cache-store.ts +573 -21
- package/src/cache/cf/index.ts +13 -3
- package/src/cache/document-cache.ts +116 -77
- package/src/cache/handle-capture.ts +81 -0
- package/src/cache/handle-snapshot.ts +41 -0
- package/src/cache/index.ts +1 -15
- package/src/cache/memory-segment-store.ts +191 -13
- package/src/cache/profile-registry.ts +73 -0
- package/src/cache/read-through-swr.ts +134 -0
- package/src/cache/segment-codec.ts +256 -0
- package/src/cache/taint.ts +153 -0
- package/src/cache/types.ts +72 -122
- package/src/client.rsc.tsx +6 -1
- package/src/client.tsx +118 -302
- package/src/component-utils.ts +4 -4
- package/src/components/DefaultDocument.tsx +5 -1
- package/src/context-var.ts +156 -0
- package/src/debug.ts +19 -9
- package/src/errors.ts +77 -7
- package/src/handle.ts +55 -10
- package/src/handles/MetaTags.tsx +73 -20
- package/src/handles/breadcrumbs.ts +66 -0
- package/src/handles/index.ts +1 -0
- package/src/handles/meta.ts +30 -13
- package/src/host/cookie-handler.ts +21 -15
- package/src/host/errors.ts +8 -8
- package/src/host/index.ts +4 -7
- package/src/host/pattern-matcher.ts +27 -27
- package/src/host/router.ts +61 -39
- package/src/host/testing.ts +8 -8
- package/src/host/types.ts +15 -7
- package/src/host/utils.ts +1 -1
- package/src/href-client.ts +65 -45
- package/src/index.rsc.ts +138 -21
- package/src/index.ts +206 -51
- package/src/internal-debug.ts +11 -0
- package/src/loader.rsc.ts +25 -143
- package/src/loader.ts +27 -10
- package/src/network-error-thrower.tsx +3 -1
- package/src/outlet-context.ts +1 -1
- package/src/outlet-provider.tsx +45 -0
- package/src/prerender/param-hash.ts +4 -2
- package/src/prerender/store.ts +159 -13
- package/src/prerender.ts +397 -29
- package/src/response-utils.ts +28 -0
- package/src/reverse.ts +231 -121
- package/src/root-error-boundary.tsx +41 -29
- package/src/route-content-wrapper.tsx +7 -4
- package/src/route-definition/dsl-helpers.ts +1134 -0
- package/src/route-definition/helper-factories.ts +200 -0
- package/src/route-definition/helpers-types.ts +483 -0
- package/src/route-definition/index.ts +55 -0
- package/src/route-definition/redirect.ts +101 -0
- package/src/route-definition/resolve-handler-use.ts +155 -0
- package/src/route-definition.ts +1 -1431
- package/src/route-map-builder.ts +162 -123
- package/src/route-name.ts +53 -0
- package/src/route-types.ts +66 -9
- package/src/router/content-negotiation.ts +215 -0
- package/src/router/debug-manifest.ts +72 -0
- package/src/router/error-handling.ts +9 -9
- package/src/router/find-match.ts +160 -0
- package/src/router/handler-context.ts +418 -86
- package/src/router/intercept-resolution.ts +35 -20
- package/src/router/lazy-includes.ts +237 -0
- package/src/router/loader-resolution.ts +359 -128
- package/src/router/logging.ts +251 -0
- package/src/router/manifest.ts +98 -32
- package/src/router/match-api.ts +196 -261
- package/src/router/match-context.ts +4 -2
- package/src/router/match-handlers.ts +441 -0
- package/src/router/match-middleware/background-revalidation.ts +108 -93
- package/src/router/match-middleware/cache-lookup.ts +415 -86
- package/src/router/match-middleware/cache-store.ts +91 -29
- package/src/router/match-middleware/intercept-resolution.ts +48 -21
- package/src/router/match-middleware/segment-resolution.ts +73 -9
- package/src/router/match-pipelines.ts +10 -45
- package/src/router/match-result.ts +154 -35
- package/src/router/metrics.ts +240 -15
- package/src/router/middleware-cookies.ts +55 -0
- package/src/router/middleware-types.ts +209 -0
- package/src/router/middleware.ts +373 -371
- package/src/router/navigation-snapshot.ts +182 -0
- package/src/router/pattern-matching.ts +292 -52
- package/src/router/prerender-match.ts +502 -0
- package/src/router/preview-match.ts +98 -0
- package/src/router/request-classification.ts +310 -0
- package/src/router/revalidation.ts +152 -39
- package/src/router/route-snapshot.ts +245 -0
- package/src/router/router-context.ts +41 -21
- package/src/router/router-interfaces.ts +484 -0
- package/src/router/router-options.ts +618 -0
- package/src/router/router-registry.ts +24 -0
- package/src/router/segment-resolution/fresh.ts +756 -0
- package/src/router/segment-resolution/helpers.ts +268 -0
- package/src/router/segment-resolution/loader-cache.ts +199 -0
- package/src/router/segment-resolution/revalidation.ts +1407 -0
- package/src/router/segment-resolution/static-store.ts +67 -0
- package/src/router/segment-resolution.ts +21 -1315
- package/src/router/segment-wrappers.ts +291 -0
- package/src/router/substitute-pattern-params.ts +56 -0
- package/src/router/telemetry-otel.ts +299 -0
- package/src/router/telemetry.ts +300 -0
- package/src/router/timeout.ts +148 -0
- package/src/router/trie-matching.ts +111 -39
- package/src/router/types.ts +17 -9
- package/src/router/url-params.ts +49 -0
- package/src/router.ts +642 -2011
- package/src/rsc/handler-context.ts +45 -0
- package/src/rsc/handler.ts +864 -1114
- package/src/rsc/helpers.ts +181 -19
- package/src/rsc/index.ts +0 -20
- package/src/rsc/loader-fetch.ts +229 -0
- package/src/rsc/manifest-init.ts +90 -0
- package/src/rsc/nonce.ts +14 -0
- package/src/rsc/origin-guard.ts +141 -0
- package/src/rsc/progressive-enhancement.ts +395 -0
- package/src/rsc/response-error.ts +37 -0
- package/src/rsc/response-route-handler.ts +360 -0
- package/src/rsc/rsc-rendering.ts +256 -0
- package/src/rsc/runtime-warnings.ts +42 -0
- package/src/rsc/server-action.ts +360 -0
- package/src/rsc/ssr-setup.ts +128 -0
- package/src/rsc/types.ts +52 -11
- package/src/search-params.ts +230 -0
- package/src/segment-content-promise.ts +67 -0
- package/src/segment-loader-promise.ts +122 -0
- package/src/segment-system.tsx +187 -38
- package/src/server/context.ts +333 -59
- package/src/server/cookie-store.ts +190 -0
- package/src/server/fetchable-loader-store.ts +37 -0
- package/src/server/handle-store.ts +113 -15
- package/src/server/loader-registry.ts +24 -64
- package/src/server/request-context.ts +603 -109
- package/src/server.ts +35 -155
- package/src/ssr/index.tsx +107 -30
- package/src/static-handler.ts +126 -0
- package/src/theme/ThemeProvider.tsx +21 -15
- package/src/theme/ThemeScript.tsx +5 -5
- package/src/theme/constants.ts +5 -2
- package/src/theme/index.ts +4 -14
- package/src/theme/theme-context.ts +4 -30
- package/src/theme/theme-script.ts +21 -18
- package/src/types/boundaries.ts +158 -0
- package/src/types/cache-types.ts +198 -0
- package/src/types/error-types.ts +192 -0
- package/src/types/global-namespace.ts +100 -0
- package/src/types/handler-context.ts +764 -0
- package/src/types/index.ts +88 -0
- package/src/types/loader-types.ts +209 -0
- package/src/types/request-scope.ts +126 -0
- package/src/types/route-config.ts +170 -0
- package/src/types/route-entry.ts +120 -0
- package/src/types/segments.ts +167 -0
- package/src/types.ts +1 -1757
- package/src/urls/include-helper.ts +207 -0
- package/src/urls/index.ts +53 -0
- package/src/urls/path-helper-types.ts +372 -0
- package/src/urls/path-helper.ts +364 -0
- package/src/urls/pattern-types.ts +107 -0
- package/src/urls/response-types.ts +108 -0
- package/src/urls/type-extraction.ts +372 -0
- package/src/urls/urls-function.ts +98 -0
- package/src/urls.ts +1 -1282
- package/src/use-loader.tsx +161 -81
- package/src/vite/debug.ts +184 -0
- package/src/vite/discovery/bundle-postprocess.ts +181 -0
- package/src/vite/discovery/discover-routers.ts +376 -0
- package/src/vite/discovery/gate-state.ts +171 -0
- package/src/vite/discovery/prerender-collection.ts +486 -0
- package/src/vite/discovery/route-types-writer.ts +258 -0
- package/src/vite/discovery/self-gen-tracking.ts +73 -0
- package/src/vite/discovery/state.ts +117 -0
- package/src/vite/discovery/virtual-module-codegen.ts +203 -0
- package/src/vite/index.ts +15 -2063
- package/src/vite/plugin-types.ts +103 -0
- package/src/vite/plugins/cjs-to-esm.ts +98 -0
- package/src/vite/plugins/client-ref-dedup.ts +131 -0
- package/src/vite/plugins/client-ref-hashing.ts +117 -0
- package/src/vite/plugins/cloudflare-protocol-loader-hook.d.mts +23 -0
- package/src/vite/plugins/cloudflare-protocol-loader-hook.mjs +76 -0
- package/src/vite/plugins/cloudflare-protocol-stub.ts +214 -0
- package/src/vite/{expose-action-id.ts → plugins/expose-action-id.ts} +107 -64
- package/src/vite/plugins/expose-id-utils.ts +299 -0
- package/src/vite/plugins/expose-ids/export-analysis.ts +296 -0
- package/src/vite/plugins/expose-ids/handler-transform.ts +209 -0
- package/src/vite/plugins/expose-ids/loader-transform.ts +74 -0
- package/src/vite/plugins/expose-ids/router-transform.ts +127 -0
- package/src/vite/plugins/expose-ids/types.ts +45 -0
- package/src/vite/plugins/expose-internal-ids.ts +816 -0
- package/src/vite/plugins/performance-tracks.ts +96 -0
- package/src/vite/plugins/refresh-cmd.ts +127 -0
- package/src/vite/plugins/use-cache-transform.ts +336 -0
- package/src/vite/plugins/version-injector.ts +109 -0
- package/src/vite/plugins/version-plugin.ts +266 -0
- package/src/vite/{virtual-entries.ts → plugins/virtual-entries.ts} +23 -14
- package/src/vite/plugins/virtual-stub-plugin.ts +29 -0
- package/src/vite/rango.ts +497 -0
- package/src/vite/router-discovery.ts +1423 -0
- package/src/vite/utils/ast-handler-extract.ts +517 -0
- package/src/vite/utils/banner.ts +36 -0
- package/src/vite/utils/bundle-analysis.ts +137 -0
- package/src/vite/utils/manifest-utils.ts +70 -0
- package/src/vite/utils/package-resolution.ts +161 -0
- package/src/vite/utils/prerender-utils.ts +222 -0
- package/src/vite/utils/shared-utils.ts +170 -0
- package/CLAUDE.md +0 -43
- package/src/browser/lru-cache.ts +0 -69
- package/src/browser/request-controller.ts +0 -164
- package/src/cache/memory-store.ts +0 -253
- package/src/href-context.ts +0 -33
- package/src/router.gen.ts +0 -6
- package/src/urls.gen.ts +0 -8
- package/src/vite/expose-handle-id.ts +0 -209
- package/src/vite/expose-loader-id.ts +0 -426
- package/src/vite/expose-location-state-id.ts +0 -177
- package/src/vite/expose-prerender-handler-id.ts +0 -429
- package/src/vite/package-resolution.ts +0 -125
- /package/src/vite/{version.d.ts → plugins/version.d.ts} +0 -0
package/src/index.rsc.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* @rangojs/router (react-server environment)
|
|
3
3
|
*
|
|
4
|
-
* This file is used when importing "
|
|
4
|
+
* This file is used when importing "@rangojs/router" from RSC (server components).
|
|
5
5
|
* It re-exports everything from the universal index.ts plus adds server-side
|
|
6
|
-
*
|
|
6
|
+
* implementations that replace the client-side error stubs.
|
|
7
7
|
*
|
|
8
8
|
* The bundler uses the "react-server" export condition to select this file
|
|
9
9
|
* in RSC context, while the regular index.ts is used in client components.
|
|
@@ -11,8 +11,6 @@
|
|
|
11
11
|
|
|
12
12
|
// Re-export all universal exports from index.ts
|
|
13
13
|
export {
|
|
14
|
-
// Universal rendering utilities
|
|
15
|
-
renderSegments,
|
|
16
14
|
// Error classes
|
|
17
15
|
RouteNotFoundError,
|
|
18
16
|
DataNotFoundError,
|
|
@@ -21,22 +19,22 @@ export {
|
|
|
21
19
|
HandlerError,
|
|
22
20
|
BuildError,
|
|
23
21
|
InvalidHandlerError,
|
|
24
|
-
NetworkError,
|
|
25
|
-
isNetworkError,
|
|
26
|
-
sanitizeError,
|
|
27
22
|
RouterError,
|
|
23
|
+
Skip,
|
|
24
|
+
isSkip,
|
|
28
25
|
} from "./index.js";
|
|
29
26
|
|
|
30
27
|
// Re-export all types from types.ts (user-facing types only)
|
|
31
28
|
export type {
|
|
32
29
|
// Configuration types
|
|
33
30
|
DocumentProps,
|
|
34
|
-
RouterEnv,
|
|
35
31
|
DefaultEnv,
|
|
36
32
|
RouteDefinition,
|
|
33
|
+
RouteConfig,
|
|
34
|
+
RouteDefinitionOptions,
|
|
35
|
+
TrailingSlashMode,
|
|
37
36
|
// Handler types
|
|
38
37
|
Handler,
|
|
39
|
-
ScopedRouteMap,
|
|
40
38
|
HandlerContext,
|
|
41
39
|
ExtractParams,
|
|
42
40
|
GenericParams,
|
|
@@ -52,9 +50,6 @@ export type {
|
|
|
52
50
|
LoaderContext,
|
|
53
51
|
FetchableLoaderOptions,
|
|
54
52
|
LoadOptions,
|
|
55
|
-
LoaderActionContext,
|
|
56
|
-
LoaderAction,
|
|
57
|
-
LoaderMiddlewareFn,
|
|
58
53
|
// Error boundary types
|
|
59
54
|
ErrorInfo,
|
|
60
55
|
ErrorBoundaryFallbackProps,
|
|
@@ -64,26 +59,74 @@ export type {
|
|
|
64
59
|
NotFoundInfo,
|
|
65
60
|
NotFoundBoundaryFallbackProps,
|
|
66
61
|
NotFoundBoundaryHandler,
|
|
62
|
+
// Error handling callback types
|
|
63
|
+
ErrorPhase,
|
|
64
|
+
OnErrorContext,
|
|
65
|
+
OnErrorCallback,
|
|
67
66
|
} from "./types.js";
|
|
68
67
|
|
|
69
68
|
// Router options type (server-only, so import directly)
|
|
70
|
-
export type {
|
|
69
|
+
export type {
|
|
70
|
+
RSCRouterOptions,
|
|
71
|
+
SSRStreamMode,
|
|
72
|
+
SSROptions,
|
|
73
|
+
ResolveStreamingContext,
|
|
74
|
+
} from "./router.js";
|
|
71
75
|
|
|
72
76
|
// Server-side createLoader and redirect
|
|
73
|
-
export {
|
|
77
|
+
export {
|
|
78
|
+
createLoader,
|
|
79
|
+
redirect,
|
|
80
|
+
type RouteHelpers,
|
|
81
|
+
type RouteHandlers,
|
|
82
|
+
// Globally importable route helpers for composition
|
|
83
|
+
layout,
|
|
84
|
+
cache,
|
|
85
|
+
middleware,
|
|
86
|
+
revalidate,
|
|
87
|
+
loader,
|
|
88
|
+
loading,
|
|
89
|
+
parallel,
|
|
90
|
+
intercept,
|
|
91
|
+
when,
|
|
92
|
+
errorBoundary,
|
|
93
|
+
notFoundBoundary,
|
|
94
|
+
transition,
|
|
95
|
+
} from "./route-definition.js";
|
|
96
|
+
|
|
97
|
+
// Composition types for reusable callback factories
|
|
98
|
+
export type {
|
|
99
|
+
RouteUseItem,
|
|
100
|
+
LayoutUseItem,
|
|
101
|
+
AllUseItems,
|
|
102
|
+
UseItems,
|
|
103
|
+
HandlerUseItem,
|
|
104
|
+
} from "./route-types.js";
|
|
74
105
|
|
|
75
106
|
// Handle API
|
|
76
107
|
export { createHandle, isHandle, type Handle } from "./handle.js";
|
|
77
108
|
|
|
109
|
+
// Context variable API (typed ctx.set/ctx.get tokens)
|
|
110
|
+
export { createVar, type ContextVar } from "./context-var.js";
|
|
111
|
+
|
|
112
|
+
// CSP nonce token (use with ctx.get(nonce) in middleware/handlers)
|
|
113
|
+
export { nonce } from "./rsc/nonce.js";
|
|
114
|
+
|
|
78
115
|
// Pre-render handler API
|
|
79
116
|
export {
|
|
80
|
-
|
|
81
|
-
|
|
117
|
+
Prerender,
|
|
118
|
+
Passthrough,
|
|
82
119
|
type PrerenderHandlerDefinition,
|
|
120
|
+
type PassthroughHandlerDefinition,
|
|
83
121
|
type PrerenderOptions,
|
|
84
122
|
type BuildContext,
|
|
123
|
+
type StaticBuildContext,
|
|
124
|
+
type GetParamsContext,
|
|
85
125
|
} from "./prerender.js";
|
|
86
126
|
|
|
127
|
+
// Static handler API
|
|
128
|
+
export { Static, type StaticHandlerDefinition } from "./static-handler.js";
|
|
129
|
+
|
|
87
130
|
// Django-style URL patterns (RSC/server context)
|
|
88
131
|
export {
|
|
89
132
|
urls,
|
|
@@ -95,6 +138,14 @@ export {
|
|
|
95
138
|
type RouteResponse,
|
|
96
139
|
type ResponseError,
|
|
97
140
|
type ResponseEnvelope,
|
|
141
|
+
type ResponseHandler,
|
|
142
|
+
type ResponseHandlerContext,
|
|
143
|
+
type JsonResponseHandler,
|
|
144
|
+
type TextResponseHandler,
|
|
145
|
+
type JsonValue,
|
|
146
|
+
type ResponsePathFn,
|
|
147
|
+
type JsonResponsePathFn,
|
|
148
|
+
type TextResponsePathFn,
|
|
98
149
|
} from "./urls.js";
|
|
99
150
|
|
|
100
151
|
// Core router (server-side)
|
|
@@ -102,6 +153,7 @@ export {
|
|
|
102
153
|
createRouter,
|
|
103
154
|
type RSCRouter,
|
|
104
155
|
type RootLayoutProps,
|
|
156
|
+
type RouterRequestInput,
|
|
105
157
|
} from "./router.js";
|
|
106
158
|
|
|
107
159
|
// RSC handler types (server-side)
|
|
@@ -109,13 +161,78 @@ export type { HandlerCacheConfig } from "./rsc/types.js";
|
|
|
109
161
|
|
|
110
162
|
// Built-in handles (server-side)
|
|
111
163
|
export { Meta } from "./handles/meta.js";
|
|
164
|
+
export { Breadcrumbs, type BreadcrumbItem } from "./handles/breadcrumbs.js";
|
|
165
|
+
|
|
166
|
+
// Request context (for accessing request data in server actions/components).
|
|
167
|
+
// Re-exported with a narrowed return type so that public consumers only see
|
|
168
|
+
// public members. Internal code imports from "./server/request-context.js"
|
|
169
|
+
// directly and gets the full type.
|
|
170
|
+
import { getRequestContext as _getRequestContextInternal } from "./server/request-context.js";
|
|
171
|
+
export type { PublicRequestContext as RequestContext } from "./server/request-context.js";
|
|
172
|
+
import type { PublicRequestContext } from "./server/request-context.js";
|
|
173
|
+
import type { DefaultEnv } from "./types/global-namespace.js";
|
|
174
|
+
|
|
175
|
+
// Shared base for every user-facing request context (mirrors index.ts).
|
|
176
|
+
export type { RequestScope, ExecutionContext } from "./types/request-scope.js";
|
|
177
|
+
|
|
178
|
+
export const getRequestContext: <
|
|
179
|
+
TEnv = DefaultEnv,
|
|
180
|
+
>() => PublicRequestContext<TEnv> = _getRequestContextInternal;
|
|
112
181
|
|
|
113
|
-
// Request
|
|
114
|
-
export {
|
|
182
|
+
// Request-scoped shorthands
|
|
183
|
+
export {
|
|
184
|
+
cookies,
|
|
185
|
+
headers,
|
|
186
|
+
type CookieStore,
|
|
187
|
+
type Cookie,
|
|
188
|
+
type ReadonlyHeaders,
|
|
189
|
+
} from "./server/cookie-store.js";
|
|
115
190
|
|
|
116
191
|
// Meta types
|
|
117
192
|
export type { MetaDescriptor, MetaDescriptorBase } from "./router/types.js";
|
|
118
193
|
|
|
194
|
+
// Middleware context types
|
|
195
|
+
export type { MiddlewareContext, CookieOptions } from "./router/middleware.js";
|
|
196
|
+
|
|
119
197
|
// Reverse type utilities for type-safe URL generation (Django-style URL reversal)
|
|
120
|
-
export type {
|
|
121
|
-
|
|
198
|
+
export type {
|
|
199
|
+
ScopedReverseFunction,
|
|
200
|
+
ReverseFunction,
|
|
201
|
+
ExtractLocalRoutes,
|
|
202
|
+
ParamsFor,
|
|
203
|
+
} from "./reverse.js";
|
|
204
|
+
export { scopedReverse, createReverse } from "./reverse.js";
|
|
205
|
+
|
|
206
|
+
// Search params schema types
|
|
207
|
+
export type {
|
|
208
|
+
SearchSchema,
|
|
209
|
+
SearchSchemaValue,
|
|
210
|
+
ResolveSearchSchema,
|
|
211
|
+
RouteSearchParams,
|
|
212
|
+
RouteParams,
|
|
213
|
+
} from "./search-params.js";
|
|
214
|
+
|
|
215
|
+
// Location state (universal)
|
|
216
|
+
export {
|
|
217
|
+
createLocationState,
|
|
218
|
+
type LocationStateDefinition,
|
|
219
|
+
type LocationStateEntry,
|
|
220
|
+
type LocationStateOptions,
|
|
221
|
+
} from "./browser/react/location-state-shared.js";
|
|
222
|
+
|
|
223
|
+
// Path-based response type lookup from RegisteredRoutes
|
|
224
|
+
export type { PathResponse } from "./href-client.js";
|
|
225
|
+
|
|
226
|
+
// Telemetry sink
|
|
227
|
+
export { createConsoleSink } from "./router/telemetry.js";
|
|
228
|
+
export { createOTelSink } from "./router/telemetry-otel.js";
|
|
229
|
+
export type { OTelTracer, OTelSpan } from "./router/telemetry-otel.js";
|
|
230
|
+
export type { TelemetrySink, TelemetryEvent } from "./router/telemetry.js";
|
|
231
|
+
|
|
232
|
+
// Timeout types and error class
|
|
233
|
+
export { RouterTimeoutError } from "./router/timeout.js";
|
|
234
|
+
export type {
|
|
235
|
+
RouterTimeouts,
|
|
236
|
+
TimeoutPhase,
|
|
237
|
+
TimeoutContext,
|
|
238
|
+
} from "./router/timeout.js";
|
package/src/index.ts
CHANGED
|
@@ -1,18 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* @rangojs/router
|
|
3
3
|
*
|
|
4
|
-
*
|
|
4
|
+
* Single user-facing entrypoint for all router APIs.
|
|
5
5
|
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
6
|
+
* The "react-server" export condition selects index.rsc.ts (real implementations)
|
|
7
|
+
* vs this file (client stubs for server-only functions).
|
|
8
8
|
*
|
|
9
|
-
* For client-only exports (Outlet, useOutlet,
|
|
10
|
-
* import from "
|
|
9
|
+
* For client-only exports (Outlet, useOutlet, hooks, components):
|
|
10
|
+
* import from "@rangojs/router/client"
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
|
-
// Universal rendering utilities (work on both server and client)
|
|
14
|
-
export { renderSegments } from "./segment-system.js";
|
|
15
|
-
|
|
16
13
|
// Error classes (can be used on both server and client)
|
|
17
14
|
export {
|
|
18
15
|
RouteNotFoundError,
|
|
@@ -22,22 +19,22 @@ export {
|
|
|
22
19
|
HandlerError,
|
|
23
20
|
BuildError,
|
|
24
21
|
InvalidHandlerError,
|
|
25
|
-
NetworkError,
|
|
26
|
-
isNetworkError,
|
|
27
|
-
sanitizeError,
|
|
28
22
|
RouterError,
|
|
23
|
+
Skip,
|
|
24
|
+
isSkip,
|
|
29
25
|
} from "./errors.js";
|
|
30
26
|
|
|
31
27
|
// Types (safe to import anywhere - no runtime code)
|
|
32
28
|
export type {
|
|
33
29
|
// Configuration types
|
|
34
30
|
DocumentProps,
|
|
35
|
-
RouterEnv,
|
|
36
31
|
DefaultEnv,
|
|
37
32
|
RouteDefinition,
|
|
33
|
+
RouteConfig,
|
|
34
|
+
RouteDefinitionOptions,
|
|
35
|
+
TrailingSlashMode,
|
|
38
36
|
// Handler types
|
|
39
|
-
Handler,
|
|
40
|
-
ScopedRouteMap, // Scoped view of GeneratedRouteMap for Handler<"localName", ScopedRouteMap<"prefix">>
|
|
37
|
+
Handler, // Supports params object, path pattern, or route name
|
|
41
38
|
HandlerContext,
|
|
42
39
|
ExtractParams,
|
|
43
40
|
GenericParams,
|
|
@@ -53,9 +50,6 @@ export type {
|
|
|
53
50
|
LoaderContext,
|
|
54
51
|
FetchableLoaderOptions,
|
|
55
52
|
LoadOptions,
|
|
56
|
-
LoaderActionContext,
|
|
57
|
-
LoaderAction,
|
|
58
|
-
LoaderMiddlewareFn,
|
|
59
53
|
// Error boundary types
|
|
60
54
|
ErrorInfo,
|
|
61
55
|
ErrorBoundaryFallbackProps,
|
|
@@ -65,12 +59,38 @@ export type {
|
|
|
65
59
|
NotFoundInfo,
|
|
66
60
|
NotFoundBoundaryFallbackProps,
|
|
67
61
|
NotFoundBoundaryHandler,
|
|
62
|
+
// Error handling callback types
|
|
63
|
+
ErrorPhase,
|
|
64
|
+
OnErrorContext,
|
|
65
|
+
OnErrorCallback,
|
|
68
66
|
} from "./types.js";
|
|
69
67
|
|
|
68
|
+
// Search params schema types
|
|
69
|
+
export type {
|
|
70
|
+
SearchSchema,
|
|
71
|
+
SearchSchemaValue,
|
|
72
|
+
ResolveSearchSchema,
|
|
73
|
+
RouteSearchParams,
|
|
74
|
+
RouteParams,
|
|
75
|
+
} from "./search-params.js";
|
|
76
|
+
|
|
70
77
|
// Client-safe createLoader - only stores the $$id, function is not included
|
|
71
78
|
// Use this when defining loaders that will be imported by client components
|
|
72
79
|
export { createLoader } from "./loader.js";
|
|
73
80
|
|
|
81
|
+
// Route definition types (safe to import anywhere)
|
|
82
|
+
export type { RouteHelpers, RouteHandlers } from "./route-definition.js";
|
|
83
|
+
export type { TransitionConfig, ViewTransitionClass } from "./types.js";
|
|
84
|
+
|
|
85
|
+
// Composition types for reusable callback factories
|
|
86
|
+
export type {
|
|
87
|
+
RouteUseItem,
|
|
88
|
+
LayoutUseItem,
|
|
89
|
+
AllUseItems,
|
|
90
|
+
UseItems,
|
|
91
|
+
HandlerUseItem,
|
|
92
|
+
} from "./route-types.js";
|
|
93
|
+
|
|
74
94
|
// Response route types (usable in both server and client contexts)
|
|
75
95
|
export type {
|
|
76
96
|
ResponseHandler,
|
|
@@ -86,80 +106,215 @@ export type {
|
|
|
86
106
|
ResponseEnvelope,
|
|
87
107
|
} from "./urls.js";
|
|
88
108
|
|
|
109
|
+
// Middleware context types
|
|
110
|
+
export type { MiddlewareContext, CookieOptions } from "./router/middleware.js";
|
|
111
|
+
|
|
112
|
+
function serverOnlyStubError(name: string): Error {
|
|
113
|
+
return new Error(
|
|
114
|
+
`${name}() is only available from "@rangojs/router" in a react-server/RSC environment. ` +
|
|
115
|
+
`For client hooks and components, import from "@rangojs/router/client".`,
|
|
116
|
+
);
|
|
117
|
+
}
|
|
118
|
+
|
|
89
119
|
/**
|
|
90
120
|
* Error-throwing stub for server-only `urls` function.
|
|
91
|
-
* Import from "@rangojs/router/server" or use within RSC context instead.
|
|
92
121
|
*/
|
|
93
122
|
export function urls(): never {
|
|
94
|
-
throw
|
|
95
|
-
'urls() is server-only. Import from "@rangojs/router/server" instead, or ensure you\'re using it in a server component.'
|
|
96
|
-
);
|
|
123
|
+
throw serverOnlyStubError("urls");
|
|
97
124
|
}
|
|
98
125
|
|
|
99
126
|
/**
|
|
100
127
|
* Error-throwing stub for server-only `createRouter` function.
|
|
101
|
-
* Import from "@rangojs/router/server" instead.
|
|
102
128
|
*/
|
|
103
129
|
export function createRouter(): never {
|
|
104
|
-
throw
|
|
105
|
-
'createRouter() is server-only. Import from "@rangojs/router/server" instead.'
|
|
106
|
-
);
|
|
130
|
+
throw serverOnlyStubError("createRouter");
|
|
107
131
|
}
|
|
108
132
|
|
|
109
133
|
/**
|
|
110
134
|
* Error-throwing stub for server-only `redirect` function.
|
|
111
|
-
* Import from "@rangojs/router/server" or use within RSC context instead.
|
|
112
135
|
*/
|
|
113
136
|
export function redirect(): never {
|
|
114
|
-
throw
|
|
115
|
-
'redirect() is server-only. Import from "@rangojs/router/server" instead.'
|
|
116
|
-
);
|
|
137
|
+
throw serverOnlyStubError("redirect");
|
|
117
138
|
}
|
|
118
139
|
|
|
140
|
+
// Handle API (universal - works on both server and client)
|
|
141
|
+
export { createHandle, isHandle, type Handle } from "./handle.js";
|
|
142
|
+
|
|
143
|
+
// Context variable API (typed ctx.set/ctx.get tokens)
|
|
144
|
+
export { createVar, type ContextVar } from "./context-var.js";
|
|
145
|
+
|
|
146
|
+
// CSP nonce token (use with ctx.get(nonce) in middleware/handlers)
|
|
147
|
+
export { nonce } from "./rsc/nonce.js";
|
|
148
|
+
|
|
119
149
|
/**
|
|
120
|
-
*
|
|
121
|
-
*
|
|
150
|
+
* SSR/client stub for server-only `Prerender` function.
|
|
151
|
+
*
|
|
152
|
+
* Returns a lightweight stub object instead of throwing so that the
|
|
153
|
+
* production SSR build can safely bundle the RSC entry chunk — the SSR
|
|
154
|
+
* bundler resolves `@rangojs/router` to this (SSR) entry, so Prerender
|
|
155
|
+
* calls in RSC code must not crash at module-evaluation time.
|
|
122
156
|
*/
|
|
123
|
-
export function
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
157
|
+
export function Prerender(
|
|
158
|
+
_handler?: any,
|
|
159
|
+
_optionsOrId?: any,
|
|
160
|
+
__injectedId?: string,
|
|
161
|
+
): any {
|
|
162
|
+
const id =
|
|
163
|
+
typeof _optionsOrId === "string" ? _optionsOrId : __injectedId || "";
|
|
164
|
+
return { __brand: "prerenderHandler" as const, $$id: id };
|
|
127
165
|
}
|
|
128
166
|
|
|
129
167
|
/**
|
|
130
|
-
*
|
|
131
|
-
* Import from "@rangojs/router/server" or use within RSC context instead.
|
|
168
|
+
* SSR/client stub for server-only `Passthrough` function.
|
|
132
169
|
*/
|
|
133
|
-
export function
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
170
|
+
export function Passthrough(
|
|
171
|
+
_handler?: any,
|
|
172
|
+
_optionsOrId?: any,
|
|
173
|
+
__injectedId?: string,
|
|
174
|
+
): any {
|
|
175
|
+
const id =
|
|
176
|
+
typeof _optionsOrId === "string" ? _optionsOrId : __injectedId || "";
|
|
177
|
+
return { __brand: "passthroughHandler" as const, $$id: id };
|
|
137
178
|
}
|
|
138
179
|
|
|
139
|
-
|
|
140
|
-
|
|
180
|
+
/**
|
|
181
|
+
* SSR/client stub for server-only `Static` function.
|
|
182
|
+
*
|
|
183
|
+
* Returns a lightweight stub object instead of throwing so that the
|
|
184
|
+
* production SSR build can safely bundle the RSC entry chunk — the SSR
|
|
185
|
+
* bundler resolves `@rangojs/router` to this (SSR) entry, so Static
|
|
186
|
+
* calls in RSC code must not crash at module-evaluation time.
|
|
187
|
+
*/
|
|
188
|
+
export function Static(
|
|
189
|
+
_handler?: any,
|
|
190
|
+
_optionsOrId?: any,
|
|
191
|
+
__injectedId?: string,
|
|
192
|
+
): any {
|
|
193
|
+
const id =
|
|
194
|
+
typeof _optionsOrId === "string" ? _optionsOrId : __injectedId || "";
|
|
195
|
+
return { __brand: "staticHandler" as const, $$id: id };
|
|
196
|
+
}
|
|
141
197
|
|
|
142
198
|
/**
|
|
143
199
|
* Error-throwing stub for server-only `getRequestContext` function.
|
|
144
|
-
* Import from "@rangojs/router/server" or use within RSC context instead.
|
|
145
200
|
*/
|
|
146
201
|
export function getRequestContext(): never {
|
|
147
|
-
throw
|
|
148
|
-
|
|
149
|
-
|
|
202
|
+
throw serverOnlyStubError("getRequestContext");
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* Error-throwing stub for server-only `cookies` function.
|
|
207
|
+
*/
|
|
208
|
+
export function cookies(): never {
|
|
209
|
+
throw serverOnlyStubError("cookies");
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* Error-throwing stub for server-only `headers` function.
|
|
214
|
+
*/
|
|
215
|
+
export function headers(): never {
|
|
216
|
+
throw serverOnlyStubError("headers");
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* Error-throwing stub for server-only `createReverse` function.
|
|
221
|
+
*/
|
|
222
|
+
export function createReverse(): never {
|
|
223
|
+
throw serverOnlyStubError("createReverse");
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
// Error-throwing stubs for server-only route helpers
|
|
227
|
+
export function layout(): never {
|
|
228
|
+
throw serverOnlyStubError("layout");
|
|
229
|
+
}
|
|
230
|
+
export function cache(): never {
|
|
231
|
+
throw serverOnlyStubError("cache");
|
|
232
|
+
}
|
|
233
|
+
export function middleware(): never {
|
|
234
|
+
throw serverOnlyStubError("middleware");
|
|
235
|
+
}
|
|
236
|
+
export function revalidate(): never {
|
|
237
|
+
throw serverOnlyStubError("revalidate");
|
|
238
|
+
}
|
|
239
|
+
export function loader(): never {
|
|
240
|
+
throw serverOnlyStubError("loader");
|
|
241
|
+
}
|
|
242
|
+
export function loading(): never {
|
|
243
|
+
throw serverOnlyStubError("loading");
|
|
244
|
+
}
|
|
245
|
+
export function parallel(): never {
|
|
246
|
+
throw serverOnlyStubError("parallel");
|
|
247
|
+
}
|
|
248
|
+
export function intercept(): never {
|
|
249
|
+
throw serverOnlyStubError("intercept");
|
|
250
|
+
}
|
|
251
|
+
export function when(): never {
|
|
252
|
+
throw serverOnlyStubError("when");
|
|
253
|
+
}
|
|
254
|
+
export function errorBoundary(): never {
|
|
255
|
+
throw serverOnlyStubError("errorBoundary");
|
|
256
|
+
}
|
|
257
|
+
export function notFoundBoundary(): never {
|
|
258
|
+
throw serverOnlyStubError("notFoundBoundary");
|
|
259
|
+
}
|
|
260
|
+
export function transition(): never {
|
|
261
|
+
throw serverOnlyStubError("transition");
|
|
150
262
|
}
|
|
151
263
|
|
|
152
264
|
// Request context type (safe for client)
|
|
153
|
-
export type { RequestContext } from "./server/request-context.js";
|
|
265
|
+
export type { PublicRequestContext as RequestContext } from "./server/request-context.js";
|
|
266
|
+
|
|
267
|
+
// Shared base for every user-facing request context.
|
|
268
|
+
export type { RequestScope, ExecutionContext } from "./types/request-scope.js";
|
|
269
|
+
|
|
270
|
+
// Cookie store types (safe for client)
|
|
271
|
+
export type {
|
|
272
|
+
CookieStore,
|
|
273
|
+
Cookie,
|
|
274
|
+
ReadonlyHeaders,
|
|
275
|
+
} from "./server/cookie-store.js";
|
|
276
|
+
|
|
277
|
+
// Built-in handles (universal — work on both server and client)
|
|
278
|
+
export { Meta } from "./handles/meta.js";
|
|
279
|
+
export { Breadcrumbs } from "./handles/breadcrumbs.js";
|
|
154
280
|
|
|
155
281
|
// Meta types
|
|
156
282
|
export type { MetaDescriptor, MetaDescriptorBase } from "./router/types.js";
|
|
157
283
|
|
|
284
|
+
// Breadcrumb types
|
|
285
|
+
export type { BreadcrumbItem } from "./handles/breadcrumbs.js";
|
|
286
|
+
|
|
158
287
|
// Reverse type utilities for type-safe URL generation (Django-style URL reversal)
|
|
159
|
-
|
|
160
|
-
|
|
288
|
+
export type {
|
|
289
|
+
ScopedReverseFunction,
|
|
290
|
+
ReverseFunction,
|
|
291
|
+
ExtractLocalRoutes,
|
|
292
|
+
ParamsFor,
|
|
293
|
+
} from "./reverse.js";
|
|
161
294
|
// scopedReverse() helper for handlers to get locally-typed reverse
|
|
162
295
|
export { scopedReverse } from "./reverse.js";
|
|
163
296
|
|
|
297
|
+
// Location state (universal - works on both server and client)
|
|
298
|
+
export {
|
|
299
|
+
createLocationState,
|
|
300
|
+
type LocationStateDefinition,
|
|
301
|
+
type LocationStateEntry,
|
|
302
|
+
type LocationStateOptions,
|
|
303
|
+
} from "./browser/react/location-state-shared.js";
|
|
304
|
+
|
|
164
305
|
// Path-based response type lookup from RegisteredRoutes
|
|
165
306
|
export type { PathResponse } from "./href-client.js";
|
|
307
|
+
|
|
308
|
+
// Telemetry sink
|
|
309
|
+
export { createConsoleSink } from "./router/telemetry.js";
|
|
310
|
+
export { createOTelSink } from "./router/telemetry-otel.js";
|
|
311
|
+
export type { OTelTracer, OTelSpan } from "./router/telemetry-otel.js";
|
|
312
|
+
export type { TelemetrySink, TelemetryEvent } from "./router/telemetry.js";
|
|
313
|
+
|
|
314
|
+
// Timeout types and error class
|
|
315
|
+
export { RouterTimeoutError } from "./router/timeout.js";
|
|
316
|
+
export type {
|
|
317
|
+
RouterTimeouts,
|
|
318
|
+
TimeoutPhase,
|
|
319
|
+
TimeoutContext,
|
|
320
|
+
} from "./router/timeout.js";
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// Internal debug gate. Enable with INTERNAL_RANGO_DEBUG=1 in the environment.
|
|
2
|
+
// Uses a Vite define (__RANGO_DEBUG__) for compile-time injection so it works
|
|
3
|
+
// in all runtimes including Cloudflare Workers where process.env is unavailable.
|
|
4
|
+
// Falls back to process.env for non-Vite contexts (tests, direct Node usage).
|
|
5
|
+
export const INTERNAL_RANGO_DEBUG: boolean =
|
|
6
|
+
typeof __RANGO_DEBUG__ !== "undefined"
|
|
7
|
+
? __RANGO_DEBUG__
|
|
8
|
+
: typeof process !== "undefined" &&
|
|
9
|
+
Boolean((process as any).env?.INTERNAL_RANGO_DEBUG);
|
|
10
|
+
|
|
11
|
+
declare const __RANGO_DEBUG__: boolean;
|