@reckona/mreact-router 0.0.138 → 0.0.139

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 (76) hide show
  1. package/README.md +1 -1
  2. package/dist/actions.d.ts +1 -0
  3. package/dist/actions.d.ts.map +1 -1
  4. package/dist/actions.js +32 -12
  5. package/dist/actions.js.map +1 -1
  6. package/dist/adapters/static.js +10 -4
  7. package/dist/adapters/static.js.map +1 -1
  8. package/dist/build.d.ts.map +1 -1
  9. package/dist/build.js +28 -21
  10. package/dist/build.js.map +1 -1
  11. package/dist/cache.d.ts +2 -0
  12. package/dist/cache.d.ts.map +1 -1
  13. package/dist/cache.js +23 -1
  14. package/dist/cache.js.map +1 -1
  15. package/dist/client.d.ts.map +1 -1
  16. package/dist/client.js +49 -12
  17. package/dist/client.js.map +1 -1
  18. package/dist/dev-server.d.ts +1 -0
  19. package/dist/dev-server.d.ts.map +1 -1
  20. package/dist/dev-server.js +6 -4
  21. package/dist/dev-server.js.map +1 -1
  22. package/dist/link.js +17 -3
  23. package/dist/link.js.map +1 -1
  24. package/dist/middleware.d.ts.map +1 -1
  25. package/dist/middleware.js +10 -7
  26. package/dist/middleware.js.map +1 -1
  27. package/dist/multipart.d.ts +5 -0
  28. package/dist/multipart.d.ts.map +1 -1
  29. package/dist/multipart.js +24 -1
  30. package/dist/multipart.js.map +1 -1
  31. package/dist/native-route-matcher.d.ts +9 -0
  32. package/dist/native-route-matcher.d.ts.map +1 -1
  33. package/dist/native-route-matcher.js +23 -11
  34. package/dist/native-route-matcher.js.map +1 -1
  35. package/dist/navigation.d.ts.map +1 -1
  36. package/dist/navigation.js +8 -1
  37. package/dist/navigation.js.map +1 -1
  38. package/dist/render.d.ts +5 -1
  39. package/dist/render.d.ts.map +1 -1
  40. package/dist/render.js +239 -95
  41. package/dist/render.js.map +1 -1
  42. package/dist/route-source.d.ts +3 -1
  43. package/dist/route-source.d.ts.map +1 -1
  44. package/dist/route-source.js +13 -11
  45. package/dist/route-source.js.map +1 -1
  46. package/dist/route-styles.d.ts +4 -0
  47. package/dist/route-styles.d.ts.map +1 -1
  48. package/dist/route-styles.js +15 -3
  49. package/dist/route-styles.js.map +1 -1
  50. package/dist/serve.d.ts.map +1 -1
  51. package/dist/serve.js +39 -9
  52. package/dist/serve.js.map +1 -1
  53. package/dist/server-action-inference.d.ts.map +1 -1
  54. package/dist/server-action-inference.js +57 -0
  55. package/dist/server-action-inference.js.map +1 -1
  56. package/dist/vite.d.ts.map +1 -1
  57. package/dist/vite.js +27 -11
  58. package/dist/vite.js.map +1 -1
  59. package/package.json +11 -11
  60. package/src/actions.ts +44 -10
  61. package/src/adapters/static.ts +11 -4
  62. package/src/build.ts +28 -17
  63. package/src/cache.ts +33 -1
  64. package/src/client.ts +49 -12
  65. package/src/dev-server.ts +11 -4
  66. package/src/link.ts +24 -3
  67. package/src/middleware.ts +12 -7
  68. package/src/multipart.ts +32 -1
  69. package/src/native-route-matcher.ts +34 -13
  70. package/src/navigation.ts +11 -2
  71. package/src/render.ts +321 -113
  72. package/src/route-source.ts +14 -10
  73. package/src/route-styles.ts +28 -3
  74. package/src/serve.ts +68 -15
  75. package/src/server-action-inference.ts +86 -0
  76. package/src/vite.ts +39 -12
@@ -52,22 +52,43 @@ export function createNativeRouteMatcher(
52
52
 
53
53
  return {
54
54
  match(pathname): MatchedRoute | undefined {
55
- const output = matcher.matchRoute(pathname);
55
+ return matchNativeRoute(matcher, sortedRoutes, pathname);
56
+ },
57
+ };
58
+ }
56
59
 
57
- if (output == null) {
58
- return undefined;
59
- }
60
+ export function __matchNativeRouteForTesting(
61
+ matcher: NativeRouteMatcherInstance,
62
+ sortedRoutes: readonly AppRoute[],
63
+ pathname: string,
64
+ ): MatchedRoute | undefined {
65
+ return matchNativeRoute(matcher, sortedRoutes, pathname);
66
+ }
60
67
 
61
- const route = sortedRoutes[output.index];
68
+ function matchNativeRoute(
69
+ matcher: NativeRouteMatcherInstance,
70
+ sortedRoutes: readonly AppRoute[],
71
+ pathname: string,
72
+ ): MatchedRoute | undefined {
73
+ let output: NativeMatchOutput | null | undefined;
74
+ try {
75
+ output = matcher.matchRoute(pathname);
76
+ } catch {
77
+ return undefined;
78
+ }
62
79
 
63
- return route === undefined
64
- ? undefined
65
- : {
66
- route,
67
- params: normalizeNativeParams(route, output.params),
68
- };
69
- },
70
- };
80
+ if (output == null) {
81
+ return undefined;
82
+ }
83
+
84
+ const route = sortedRoutes[output.index];
85
+
86
+ return route === undefined
87
+ ? undefined
88
+ : {
89
+ route,
90
+ params: normalizeNativeParams(route, output.params),
91
+ };
71
92
  }
72
93
 
73
94
  export function normalizeNativeParams(
package/src/navigation.ts CHANGED
@@ -57,6 +57,10 @@ function throwUnsafeRedirect(location: string): never {
57
57
  );
58
58
  }
59
59
 
60
+ function throwUnsafeRewrite(location: string): never {
61
+ throw new TypeError(`unsafe rewrite target: ${JSON.stringify(location)}`);
62
+ }
63
+
60
64
  export function redirect(location: string, options: RedirectOptions = {}): never {
61
65
  if (!isSafeInternalRedirect(location)) {
62
66
  throwUnsafeRedirect(location);
@@ -134,6 +138,10 @@ export function next(): MiddlewareNext {
134
138
  }
135
139
 
136
140
  export function rewrite(location: string, init: ResponseInit = {}): Response {
141
+ if (!isSafeInternalRedirect(location)) {
142
+ throwUnsafeRewrite(location);
143
+ }
144
+
137
145
  const response = new Response(null, {
138
146
  ...init,
139
147
  status: init.status ?? 200,
@@ -198,10 +206,11 @@ export function cookies(request: Request): RequestCookies {
198
206
 
199
207
  export function rewriteLocation(response: Response): string | undefined {
200
208
  const marked = (response as { [rewriteLocationSymbol]?: unknown })[rewriteLocationSymbol];
201
-
202
- return typeof marked === "string"
209
+ const candidate = typeof marked === "string"
203
210
  ? marked
204
211
  : response.headers.get(rewriteHeaderName) ?? undefined;
212
+
213
+ return candidate !== undefined && isSafeInternalRedirect(candidate) ? candidate : undefined;
205
214
  }
206
215
 
207
216
  export function isRedirectError(error: unknown): error is Error & { location: string; status: number } {