@rangojs/router 0.0.0-experimental.77 → 0.0.0-experimental.77ed8945
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/README.md +120 -25
- package/dist/bin/rango.js +147 -57
- package/dist/vite/index.js +2103 -861
- package/dist/vite/plugins/cloudflare-protocol-loader-hook.mjs +76 -0
- package/package.json +13 -8
- package/skills/api-client/SKILL.md +211 -0
- package/skills/breadcrumbs/SKILL.md +3 -1
- package/skills/bundle-analysis/SKILL.md +159 -0
- package/skills/cache-guide/SKILL.md +220 -30
- package/skills/caching/SKILL.md +116 -8
- package/skills/composability/SKILL.md +27 -2
- package/skills/css/SKILL.md +76 -0
- package/skills/document-cache/SKILL.md +78 -55
- package/skills/handler-use/SKILL.md +3 -1
- package/skills/hooks/SKILL.md +229 -20
- package/skills/host-router/SKILL.md +66 -20
- package/skills/i18n/SKILL.md +276 -0
- package/skills/intercept/SKILL.md +26 -4
- package/skills/layout/SKILL.md +6 -7
- package/skills/links/SKILL.md +247 -17
- package/skills/loader/SKILL.md +219 -9
- package/skills/middleware/SKILL.md +47 -12
- package/skills/migrate-nextjs/SKILL.md +562 -0
- package/skills/migrate-react-router/SKILL.md +769 -0
- package/skills/mime-routes/SKILL.md +27 -0
- package/skills/observability/SKILL.md +137 -0
- package/skills/parallel/SKILL.md +12 -6
- package/skills/prerender/SKILL.md +14 -33
- package/skills/rango/SKILL.md +238 -22
- package/skills/react-compiler/SKILL.md +168 -0
- package/skills/response-routes/SKILL.md +122 -47
- package/skills/route/SKILL.md +33 -4
- package/skills/router-setup/SKILL.md +3 -3
- package/skills/server-actions/SKILL.md +751 -0
- package/skills/streams-and-websockets/SKILL.md +283 -0
- package/skills/tailwind/SKILL.md +27 -3
- package/skills/typesafety/SKILL.md +319 -27
- package/skills/use-cache/SKILL.md +34 -5
- package/skills/view-transitions/SKILL.md +294 -0
- package/src/__augment-tests__/augment.ts +81 -0
- package/src/__augment-tests__/augmented.check.ts +116 -0
- package/src/browser/action-coordinator.ts +53 -36
- package/src/browser/app-shell.ts +39 -0
- package/src/browser/event-controller.ts +86 -70
- package/src/browser/history-state.ts +21 -0
- package/src/browser/index.ts +3 -3
- package/src/browser/navigation-bridge.ts +29 -9
- package/src/browser/navigation-client.ts +99 -77
- package/src/browser/navigation-store.ts +7 -8
- package/src/browser/navigation-transaction.ts +10 -28
- package/src/browser/partial-update.ts +60 -40
- package/src/browser/prefetch/cache.ts +196 -49
- package/src/browser/prefetch/fetch.ts +203 -59
- package/src/browser/prefetch/queue.ts +36 -5
- package/src/browser/rango-state.ts +37 -13
- package/src/browser/react/Link.tsx +18 -13
- package/src/browser/react/NavigationProvider.tsx +75 -31
- package/src/browser/react/filter-segment-order.ts +51 -7
- package/src/browser/react/index.ts +3 -0
- package/src/browser/react/location-state-shared.ts +175 -4
- package/src/browser/react/location-state.ts +39 -13
- package/src/browser/react/use-handle.ts +17 -9
- package/src/browser/react/use-navigation.ts +22 -2
- package/src/browser/react/use-params.ts +20 -8
- package/src/browser/react/use-reverse.ts +106 -0
- package/src/browser/react/use-router.ts +23 -2
- package/src/browser/react/use-segments.ts +11 -8
- package/src/browser/response-adapter.ts +52 -1
- package/src/browser/rsc-router.tsx +71 -22
- package/src/browser/scroll-restoration.ts +22 -14
- package/src/browser/segment-reconciler.ts +10 -14
- package/src/browser/segment-structure-assert.ts +2 -2
- package/src/browser/server-action-bridge.ts +44 -30
- package/src/browser/types.ts +12 -2
- package/src/build/collect-fallback-refs.ts +107 -0
- package/src/build/generate-manifest.ts +60 -35
- package/src/build/generate-route-types.ts +2 -0
- package/src/build/index.ts +8 -1
- package/src/build/prefix-tree-utils.ts +123 -0
- package/src/build/route-trie.ts +45 -1
- package/src/build/route-types/codegen.ts +4 -4
- package/src/build/route-types/include-resolution.ts +1 -1
- package/src/build/route-types/per-module-writer.ts +7 -4
- package/src/build/route-types/router-processing.ts +55 -14
- package/src/build/route-types/scan-filter.ts +1 -1
- package/src/build/route-types/source-scan.ts +118 -0
- package/src/build/runtime-discovery.ts +9 -20
- package/src/cache/cache-runtime.ts +17 -5
- package/src/cache/cache-scope.ts +51 -49
- package/src/cache/cf/cf-cache-store.ts +502 -32
- package/src/cache/cf/index.ts +3 -0
- package/src/cache/handle-snapshot.ts +103 -0
- package/src/cache/index.ts +3 -0
- package/src/cache/memory-segment-store.ts +3 -2
- package/src/cache/types.ts +10 -6
- package/src/client.rsc.tsx +3 -0
- package/src/client.tsx +96 -205
- package/src/context-var.ts +5 -5
- package/src/decode-loader-results.ts +36 -0
- package/src/errors.ts +30 -4
- package/src/handle.ts +4 -6
- package/src/host/index.ts +2 -2
- package/src/host/router.ts +129 -57
- package/src/host/types.ts +31 -2
- package/src/host/utils.ts +1 -1
- package/src/href-client.ts +140 -21
- package/src/index.rsc.ts +10 -6
- package/src/index.ts +17 -8
- package/src/loader-store.ts +500 -0
- package/src/loader.rsc.ts +2 -5
- package/src/loader.ts +3 -10
- package/src/missing-id-error.ts +68 -0
- package/src/outlet-context.ts +1 -1
- package/src/prerender/store.ts +9 -7
- package/src/prerender.ts +4 -4
- package/src/response-utils.ts +37 -0
- package/src/reverse.ts +65 -39
- package/src/route-content-wrapper.tsx +6 -28
- package/src/route-definition/dsl-helpers.ts +253 -265
- package/src/route-definition/helper-factories.ts +29 -139
- package/src/route-definition/helpers-types.ts +43 -15
- package/src/route-definition/resolve-handler-use.ts +6 -0
- package/src/route-definition/use-item-types.ts +32 -0
- package/src/route-types.ts +26 -41
- package/src/router/content-negotiation.ts +15 -2
- package/src/router/error-handling.ts +1 -1
- package/src/router/find-match.ts +54 -6
- package/src/router/handler-context.ts +21 -41
- package/src/router/intercept-resolution.ts +4 -18
- package/src/router/lazy-includes.ts +41 -22
- package/src/router/loader-resolution.ts +82 -36
- package/src/router/manifest.ts +41 -19
- package/src/router/match-api.ts +4 -3
- package/src/router/match-handlers.ts +1 -0
- package/src/router/match-middleware/cache-lookup.ts +57 -95
- package/src/router/match-middleware/cache-store.ts +3 -2
- package/src/router/match-result.ts +53 -32
- package/src/router/metrics.ts +1 -1
- package/src/router/middleware-types.ts +15 -26
- package/src/router/middleware.ts +99 -84
- package/src/router/pattern-matching.ts +116 -19
- package/src/router/prerender-match.ts +40 -15
- package/src/router/preview-match.ts +3 -1
- package/src/router/request-classification.ts +40 -37
- package/src/router/revalidation.ts +58 -2
- package/src/router/router-interfaces.ts +51 -35
- package/src/router/router-options.ts +25 -1
- package/src/router/router-registry.ts +2 -5
- package/src/router/segment-resolution/fresh.ts +27 -6
- package/src/router/segment-resolution/revalidation.ts +147 -106
- package/src/router/segment-resolution/static-store.ts +19 -5
- package/src/router/segment-resolution/view-transition-default.ts +36 -0
- package/src/router/substitute-pattern-params.ts +56 -0
- package/src/router/trie-matching.ts +40 -16
- package/src/router/types.ts +8 -0
- package/src/router/url-params.ts +49 -0
- package/src/router.ts +37 -25
- package/src/rsc/handler-context.ts +2 -2
- package/src/rsc/handler.ts +58 -77
- package/src/rsc/helpers.ts +72 -43
- package/src/rsc/index.ts +1 -1
- package/src/rsc/manifest-init.ts +28 -41
- package/src/rsc/origin-guard.ts +30 -10
- package/src/rsc/progressive-enhancement.ts +4 -0
- package/src/rsc/response-error.ts +79 -12
- package/src/rsc/response-route-handler.ts +76 -61
- package/src/rsc/rsc-rendering.ts +45 -51
- package/src/rsc/runtime-warnings.ts +9 -10
- package/src/rsc/server-action.ts +33 -39
- package/src/rsc/ssr-setup.ts +16 -0
- package/src/rsc/types.ts +8 -2
- package/src/search-params.ts +4 -4
- package/src/segment-content-promise.ts +67 -0
- package/src/segment-loader-promise.ts +122 -0
- package/src/segment-system.tsx +132 -116
- package/src/serialize.ts +243 -0
- package/src/server/context.ts +175 -53
- package/src/server/cookie-store.ts +28 -4
- package/src/server/request-context.ts +57 -51
- package/src/ssr/index.tsx +5 -1
- package/src/static-handler.ts +1 -1
- package/src/types/global-namespace.ts +39 -26
- package/src/types/handler-context.ts +68 -50
- package/src/types/index.ts +1 -0
- package/src/types/loader-types.ts +11 -9
- package/src/types/request-scope.ts +126 -0
- package/src/types/route-entry.ts +11 -0
- package/src/types/segments.ts +35 -2
- package/src/urls/include-helper.ts +34 -67
- package/src/urls/index.ts +1 -5
- package/src/urls/path-helper-types.ts +17 -3
- package/src/urls/path-helper.ts +17 -52
- package/src/urls/pattern-types.ts +36 -19
- package/src/urls/response-types.ts +22 -29
- package/src/urls/type-extraction.ts +58 -139
- package/src/urls/urls-function.ts +1 -5
- package/src/use-loader.tsx +413 -42
- package/src/vite/debug.ts +185 -0
- package/src/vite/discovery/bundle-postprocess.ts +6 -6
- package/src/vite/discovery/discover-routers.ts +106 -75
- package/src/vite/discovery/discovery-errors.ts +194 -0
- package/src/vite/discovery/gate-state.ts +171 -0
- package/src/vite/discovery/prerender-collection.ts +72 -31
- package/src/vite/discovery/route-types-writer.ts +40 -84
- package/src/vite/discovery/self-gen-tracking.ts +27 -1
- package/src/vite/discovery/state.ts +33 -0
- package/src/vite/discovery/virtual-module-codegen.ts +13 -23
- package/src/vite/index.ts +2 -0
- package/src/vite/plugin-types.ts +67 -0
- package/src/vite/plugins/cjs-to-esm.ts +8 -7
- package/src/vite/plugins/client-ref-dedup.ts +16 -0
- package/src/vite/plugins/client-ref-hashing.ts +28 -5
- 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/plugins/expose-action-id.ts +54 -30
- package/src/vite/plugins/expose-id-utils.ts +12 -8
- package/src/vite/plugins/expose-ids/export-analysis.ts +100 -20
- package/src/vite/plugins/expose-ids/handler-transform.ts +8 -61
- package/src/vite/plugins/expose-ids/loader-transform.ts +3 -5
- package/src/vite/plugins/expose-ids/router-transform.ts +20 -3
- package/src/vite/plugins/expose-internal-ids.ts +496 -486
- package/src/vite/plugins/performance-tracks.ts +29 -25
- package/src/vite/plugins/use-cache-transform.ts +65 -50
- package/src/vite/plugins/version-injector.ts +39 -23
- package/src/vite/plugins/version-plugin.ts +59 -2
- package/src/vite/plugins/virtual-entries.ts +2 -2
- package/src/vite/rango.ts +116 -29
- package/src/vite/router-discovery.ts +753 -104
- package/src/vite/utils/ast-handler-extract.ts +15 -15
- package/src/vite/utils/banner.ts +1 -1
- package/src/vite/utils/bundle-analysis.ts +4 -2
- package/src/vite/utils/client-chunks.ts +190 -0
- package/src/vite/utils/forward-user-plugins.ts +193 -0
- package/src/vite/utils/manifest-utils.ts +8 -59
- package/src/vite/utils/package-resolution.ts +41 -1
- package/src/vite/utils/prerender-utils.ts +5 -4
- package/src/vite/utils/shared-utils.ts +107 -26
- package/src/browser/action-response-classifier.ts +0 -99
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { JsonSerialize } from "../serialize.js";
|
|
2
2
|
import type {
|
|
3
3
|
TypedRouteItem,
|
|
4
4
|
TypedIncludeItem,
|
|
@@ -6,11 +6,7 @@ import type {
|
|
|
6
6
|
TypedCacheItem,
|
|
7
7
|
TypedTransitionItem,
|
|
8
8
|
} from "../route-types.js";
|
|
9
|
-
import type {
|
|
10
|
-
LocalOnlyInclude,
|
|
11
|
-
UnnamedRoute,
|
|
12
|
-
UrlPatterns,
|
|
13
|
-
} from "./pattern-types.js";
|
|
9
|
+
import type { LocalOnlyInclude, UnnamedRoute } from "./pattern-types.js";
|
|
14
10
|
|
|
15
11
|
// ============================================================================
|
|
16
12
|
// Route Type Extraction Utilities
|
|
@@ -67,62 +63,6 @@ type PrefixPatterns<
|
|
|
67
63
|
: TRoutes[K];
|
|
68
64
|
};
|
|
69
65
|
|
|
70
|
-
/**
|
|
71
|
-
* Depth counter for limiting recursion (max 40 levels)
|
|
72
|
-
* Supports up to 40 sibling items at any level of a urls() call
|
|
73
|
-
* Note: Higher values hit TypeScript's internal recursion limits
|
|
74
|
-
*/
|
|
75
|
-
type Depth = [
|
|
76
|
-
never,
|
|
77
|
-
0,
|
|
78
|
-
1,
|
|
79
|
-
2,
|
|
80
|
-
3,
|
|
81
|
-
4,
|
|
82
|
-
5,
|
|
83
|
-
6,
|
|
84
|
-
7,
|
|
85
|
-
8,
|
|
86
|
-
9,
|
|
87
|
-
10,
|
|
88
|
-
11,
|
|
89
|
-
12,
|
|
90
|
-
13,
|
|
91
|
-
14,
|
|
92
|
-
15,
|
|
93
|
-
16,
|
|
94
|
-
17,
|
|
95
|
-
18,
|
|
96
|
-
19,
|
|
97
|
-
20,
|
|
98
|
-
21,
|
|
99
|
-
22,
|
|
100
|
-
23,
|
|
101
|
-
24,
|
|
102
|
-
25,
|
|
103
|
-
26,
|
|
104
|
-
27,
|
|
105
|
-
28,
|
|
106
|
-
29,
|
|
107
|
-
30,
|
|
108
|
-
31,
|
|
109
|
-
32,
|
|
110
|
-
33,
|
|
111
|
-
34,
|
|
112
|
-
35,
|
|
113
|
-
36,
|
|
114
|
-
37,
|
|
115
|
-
38,
|
|
116
|
-
39,
|
|
117
|
-
];
|
|
118
|
-
|
|
119
|
-
/**
|
|
120
|
-
* Force TypeScript to eagerly evaluate a type.
|
|
121
|
-
* This helps with interface extension by creating a "concrete" object type.
|
|
122
|
-
*/
|
|
123
|
-
type Simplify<T> =
|
|
124
|
-
T extends Record<string, string> ? { [K in keyof T]: T[K] } : T;
|
|
125
|
-
|
|
126
66
|
/**
|
|
127
67
|
* Convert a union type to an intersection type.
|
|
128
68
|
* Used to combine route maps from multiple siblings without recursive tuple processing.
|
|
@@ -135,13 +75,11 @@ type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (
|
|
|
135
75
|
|
|
136
76
|
/**
|
|
137
77
|
* Extract routes from a single item (path, include, layout, cache with children)
|
|
138
|
-
* D is the current depth level for nested layouts/caches
|
|
139
78
|
*/
|
|
140
|
-
type ExtractRoutesFromItem<T
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
T extends TypedRouteItem<infer TName, infer TPattern, any, infer TSearch>
|
|
79
|
+
type ExtractRoutesFromItem<T> =
|
|
80
|
+
// TypedRouteItem: extract name -> pattern (exclude unnamed routes)
|
|
81
|
+
// When search schema is non-empty, value becomes { path, search } object
|
|
82
|
+
T extends TypedRouteItem<infer TName, infer TPattern, any, infer TSearch>
|
|
145
83
|
? TName extends string
|
|
146
84
|
? TName extends UnnamedRoute
|
|
147
85
|
? {} // Exclude unnamed routes from type map
|
|
@@ -185,14 +123,10 @@ type ExtractRoutesFromItem<T, D extends number = 40> = [D] extends [never]
|
|
|
185
123
|
* Extract routes from an array of items using mapped types.
|
|
186
124
|
* Uses UnionToIntersection to combine routes without recursive tuple processing,
|
|
187
125
|
* removing the sibling limit that was caused by TypeScript recursion limits.
|
|
188
|
-
* D is passed to ExtractRoutesFromItem for nested depth tracking.
|
|
189
126
|
*/
|
|
190
|
-
type ExtractRoutesFromItems<
|
|
191
|
-
T extends readonly any[],
|
|
192
|
-
D extends number = 40,
|
|
193
|
-
> = T extends readonly any[]
|
|
127
|
+
type ExtractRoutesFromItems<T extends readonly any[]> = T extends readonly any[]
|
|
194
128
|
? UnionToIntersection<
|
|
195
|
-
{ [K in keyof T]: ExtractRoutesFromItem<T[K]
|
|
129
|
+
{ [K in keyof T]: ExtractRoutesFromItem<T[K]> }[number]
|
|
196
130
|
> extends infer R
|
|
197
131
|
? R extends Record<string, any>
|
|
198
132
|
? R
|
|
@@ -203,12 +137,8 @@ type ExtractRoutesFromItems<
|
|
|
203
137
|
/**
|
|
204
138
|
* Main utility: extract route map from urls() callback return type
|
|
205
139
|
* Uses mapped types for sibling processing (no sibling limit).
|
|
206
|
-
* Uses Simplify to force eager evaluation for interface extension compatibility.
|
|
207
140
|
*/
|
|
208
|
-
export type ExtractRoutes<T extends readonly any[]> = ExtractRoutesFromItems<
|
|
209
|
-
T,
|
|
210
|
-
40
|
|
211
|
-
>;
|
|
141
|
+
export type ExtractRoutes<T extends readonly any[]> = ExtractRoutesFromItems<T>;
|
|
212
142
|
|
|
213
143
|
// ============================================================================
|
|
214
144
|
// Response Type Extraction Utilities
|
|
@@ -236,9 +166,8 @@ type PrefixKeys<
|
|
|
236
166
|
* Extract response data types from a single item.
|
|
237
167
|
* Parallel to ExtractRoutesFromItem but extracts name -> TData mapping.
|
|
238
168
|
*/
|
|
239
|
-
type ExtractResponsesFromItem<T
|
|
240
|
-
|
|
241
|
-
: T extends TypedRouteItem<infer TName, any, infer TData>
|
|
169
|
+
type ExtractResponsesFromItem<T> =
|
|
170
|
+
T extends TypedRouteItem<infer TName, any, infer TData>
|
|
242
171
|
? TName extends string
|
|
243
172
|
? TName extends UnnamedRoute
|
|
244
173
|
? {}
|
|
@@ -272,86 +201,72 @@ type ExtractResponsesFromItem<T, D extends number = 40> = [D] extends [never]
|
|
|
272
201
|
* Extract responses from an array of items using mapped types.
|
|
273
202
|
* Parallel to ExtractRoutesFromItems.
|
|
274
203
|
*/
|
|
275
|
-
type ExtractResponsesFromItems<
|
|
276
|
-
T extends readonly any[]
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
? R
|
|
204
|
+
type ExtractResponsesFromItems<T extends readonly any[]> =
|
|
205
|
+
T extends readonly any[]
|
|
206
|
+
? UnionToIntersection<
|
|
207
|
+
{ [K in keyof T]: ExtractResponsesFromItem<T[K]> }[number]
|
|
208
|
+
> extends infer R
|
|
209
|
+
? R extends Record<string, unknown>
|
|
210
|
+
? R
|
|
211
|
+
: {}
|
|
284
212
|
: {}
|
|
285
|
-
: {}
|
|
286
|
-
: {};
|
|
213
|
+
: {};
|
|
287
214
|
|
|
288
215
|
/**
|
|
289
216
|
* Main utility: extract response data type map from urls() callback return type.
|
|
290
217
|
* Parallel to ExtractRoutes.
|
|
291
218
|
*/
|
|
292
219
|
export type ExtractResponses<T extends readonly any[]> =
|
|
293
|
-
ExtractResponsesFromItems<T
|
|
220
|
+
ExtractResponsesFromItems<T>;
|
|
294
221
|
|
|
295
222
|
// ============================================================================
|
|
296
|
-
//
|
|
223
|
+
// Response Error (RFC 9457 problem+json) Type
|
|
297
224
|
// ============================================================================
|
|
298
225
|
|
|
299
226
|
/**
|
|
300
|
-
*
|
|
301
|
-
*
|
|
302
|
-
|
|
303
|
-
export type ExtractRouteNames<T extends UrlPatterns<any>> =
|
|
304
|
-
T extends UrlPatterns<infer _TEnv>
|
|
305
|
-
? string // For now, will be refined with full implementation
|
|
306
|
-
: never;
|
|
307
|
-
|
|
308
|
-
/**
|
|
309
|
-
* Extract params for a specific route name
|
|
310
|
-
*/
|
|
311
|
-
export type ExtractPathParams<
|
|
312
|
-
T extends UrlPatterns<any>,
|
|
313
|
-
K extends string,
|
|
314
|
-
> = ExtractParams<string>; // Will be refined with pattern tracking
|
|
315
|
-
|
|
316
|
-
// ============================================================================
|
|
317
|
-
// Response Envelope Types
|
|
318
|
-
// ============================================================================
|
|
319
|
-
|
|
320
|
-
/**
|
|
321
|
-
* Error shape returned in the `{ error }` side of a JSON response envelope.
|
|
322
|
-
*/
|
|
323
|
-
export interface ResponseError {
|
|
324
|
-
message: string;
|
|
325
|
-
code?: string;
|
|
326
|
-
type?: string;
|
|
327
|
-
stack?: string;
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
/**
|
|
331
|
-
* Discriminated union envelope for JSON response routes.
|
|
332
|
-
* Consumers check `result.error` to discriminate between success and failure.
|
|
227
|
+
* RFC 9457 (problem+json) error body returned by JSON response routes on a
|
|
228
|
+
* non-2xx status. Sent verbatim as the response body (not wrapped) with
|
|
229
|
+
* content-type `application/problem+json`.
|
|
333
230
|
*
|
|
334
231
|
* @example
|
|
335
232
|
* ```typescript
|
|
336
|
-
* const
|
|
337
|
-
* if (
|
|
338
|
-
*
|
|
233
|
+
* const res = await fetch(url);
|
|
234
|
+
* if (!res.ok) {
|
|
235
|
+
* const problem: ProblemDetails = await res.json();
|
|
236
|
+
* console.log(problem.code, problem.detail); // "NOT_FOUND", "Product not found"
|
|
339
237
|
* return;
|
|
340
238
|
* }
|
|
341
|
-
*
|
|
239
|
+
* const product = await res.json(); // bare value, no envelope
|
|
342
240
|
* ```
|
|
343
241
|
*/
|
|
344
|
-
export
|
|
345
|
-
|
|
346
|
-
|
|
242
|
+
export interface ProblemDetails {
|
|
243
|
+
/**
|
|
244
|
+
* URI reference identifying the problem type. Omitted in this phase (per RFC
|
|
245
|
+
* 9457 an absent `type` is treated as `"about:blank"` — no semantics beyond
|
|
246
|
+
* the HTTP status); per-route problem-type URIs arrive with the
|
|
247
|
+
* declared-errors map later.
|
|
248
|
+
*/
|
|
249
|
+
type?: string;
|
|
250
|
+
/** Short, human-readable summary (the HTTP status reason phrase). */
|
|
251
|
+
title: string;
|
|
252
|
+
/** The HTTP status code. */
|
|
253
|
+
status: number;
|
|
254
|
+
/** Human-readable explanation specific to this occurrence (the error message). */
|
|
255
|
+
detail: string;
|
|
256
|
+
/** Stable machine-readable error code (`RouterError.code`, else `"INTERNAL"`). */
|
|
257
|
+
code: string;
|
|
258
|
+
/** Stack trace, included in development only. */
|
|
259
|
+
stack?: string;
|
|
260
|
+
}
|
|
347
261
|
|
|
348
262
|
// ============================================================================
|
|
349
263
|
// Response Type Consumer Utilities
|
|
350
264
|
// ============================================================================
|
|
351
265
|
|
|
352
266
|
/**
|
|
353
|
-
* Extract the response
|
|
354
|
-
*
|
|
267
|
+
* Extract the JSON response payload type for a named route from a UrlPatterns
|
|
268
|
+
* instance. JSON response routes send the handler's return value verbatim
|
|
269
|
+
* (bare), so this resolves to the wire value a consumer receives — no envelope.
|
|
355
270
|
*
|
|
356
271
|
* @example
|
|
357
272
|
* ```typescript
|
|
@@ -360,13 +275,17 @@ export type ResponseEnvelope<T> =
|
|
|
360
275
|
* ]);
|
|
361
276
|
*
|
|
362
277
|
* type HealthData = RouteResponse<typeof apiPatterns, "health">;
|
|
363
|
-
* //
|
|
278
|
+
* // { status: string; timestamp: number }
|
|
364
279
|
* ```
|
|
280
|
+
*
|
|
281
|
+
* The payload is the JSON wire shape (via `Rango.JsonSerialize`), matching
|
|
282
|
+
* `Rango.PathResponse` and what `fetch().then(r => r.json())` actually yields —
|
|
283
|
+
* e.g. a `Date` field resolves as `string`.
|
|
365
284
|
*/
|
|
366
285
|
export type RouteResponse<TPatterns, TName extends string> = TPatterns extends {
|
|
367
286
|
readonly _responses?: infer R;
|
|
368
287
|
}
|
|
369
288
|
? TName extends keyof R
|
|
370
|
-
?
|
|
289
|
+
? JsonSerialize<Exclude<R[TName], Response>>
|
|
371
290
|
: never
|
|
372
291
|
: never;
|
|
@@ -3,7 +3,7 @@ import type { AllUseItems } from "../route-types.js";
|
|
|
3
3
|
import { getContext } from "../server/context";
|
|
4
4
|
import { invariant } from "../errors";
|
|
5
5
|
import { createRouteHelpers } from "../route-definition.js";
|
|
6
|
-
import type {
|
|
6
|
+
import type { UrlPatterns } from "./pattern-types.js";
|
|
7
7
|
import type { PathHelpers } from "./path-helper-types.js";
|
|
8
8
|
import type { ExtractRoutes, ExtractResponses } from "./type-extraction.js";
|
|
9
9
|
import { createPathHelper, attachPathResponseTags } from "./path-helper.js";
|
|
@@ -34,9 +34,6 @@ export function urls<
|
|
|
34
34
|
>(
|
|
35
35
|
builder: (helpers: PathHelpers<TEnv>) => TItems,
|
|
36
36
|
): UrlPatterns<TEnv, ExtractRoutes<TItems>, ExtractResponses<TItems>> {
|
|
37
|
-
// Collect path definitions during build
|
|
38
|
-
const definitions: PathDefinition[] = [];
|
|
39
|
-
|
|
40
37
|
// Create the handler function that will be called by the router
|
|
41
38
|
const handler = () => {
|
|
42
39
|
invariant(
|
|
@@ -82,7 +79,6 @@ export function urls<
|
|
|
82
79
|
// trailingSlash config is populated when handler() runs
|
|
83
80
|
// We expose it via a getter that reads from the context after handler execution
|
|
84
81
|
return {
|
|
85
|
-
definitions,
|
|
86
82
|
handler,
|
|
87
83
|
get trailingSlash() {
|
|
88
84
|
// Get the trailingSlash map from the current context
|