rwsdk 1.0.0-beta.35 → 1.0.0-beta.37
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.
|
@@ -21,5 +21,8 @@ export type AppRoutePaths<App> = RoutePaths<AppRoutes<App>>;
|
|
|
21
21
|
export type AppLink<App> = LinkFunction<AppRoutePaths<App>>;
|
|
22
22
|
export declare function linkFor<App>(): AppLink<App>;
|
|
23
23
|
export declare function createLinks<App>(_app?: App): AppLink<App>;
|
|
24
|
+
export declare function defineLinks<App extends {
|
|
25
|
+
__rwRoutes: any;
|
|
26
|
+
}>(): AppLink<App>;
|
|
24
27
|
export declare function defineLinks<const T extends readonly string[]>(routes: T): LinkFunction<T[number]>;
|
|
25
28
|
export {};
|
|
@@ -4,7 +4,19 @@ export function linkFor() {
|
|
|
4
4
|
export function createLinks(_app) {
|
|
5
5
|
return linkFor();
|
|
6
6
|
}
|
|
7
|
+
// Implementation
|
|
7
8
|
export function defineLinks(routes) {
|
|
9
|
+
// If no routes provided, this is the app type overload
|
|
10
|
+
// At runtime, we can't distinguish, but the type system ensures
|
|
11
|
+
// this only happens when called as defineLinks<App>()
|
|
12
|
+
// We delegate to linkFor which handles app types correctly
|
|
13
|
+
if (routes === undefined) {
|
|
14
|
+
// This branch is only reachable when called as defineLinks<App>()
|
|
15
|
+
// The return type is AppLink<App> due to the overload
|
|
16
|
+
// We use linkFor internally which doesn't need runtime route validation
|
|
17
|
+
return linkFor();
|
|
18
|
+
}
|
|
19
|
+
// Original implementation for route arrays
|
|
8
20
|
routes.forEach((route) => {
|
|
9
21
|
if (typeof route !== "string") {
|
|
10
22
|
throw new Error(`Invalid route: ${route}. Routes must be strings.`);
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import { RequestInfo } from "../requestInfo/types";
|
|
3
3
|
import type { DocumentProps, LayoutProps } from "./types.js";
|
|
4
|
-
export type RouteMiddleware<T extends RequestInfo = RequestInfo> = (requestInfo: T) => MaybePromise<React.JSX.Element | Response | void>;
|
|
5
|
-
type RouteFunction<T extends RequestInfo = RequestInfo> = (requestInfo: T) => MaybePromise<Response>;
|
|
6
4
|
type MaybePromise<T> = T | Promise<T>;
|
|
7
|
-
type
|
|
5
|
+
type BivariantRouteHandler<T extends RequestInfo, R> = {
|
|
6
|
+
bivarianceHack(requestInfo: T): R;
|
|
7
|
+
}["bivarianceHack"];
|
|
8
|
+
export type RouteMiddleware<T extends RequestInfo = RequestInfo> = BivariantRouteHandler<T, MaybePromise<React.JSX.Element | Response | void>>;
|
|
9
|
+
type RouteFunction<T extends RequestInfo = RequestInfo> = BivariantRouteHandler<T, MaybePromise<Response>>;
|
|
10
|
+
type RouteComponent<T extends RequestInfo = RequestInfo> = BivariantRouteHandler<T, MaybePromise<React.JSX.Element | Response | void>>;
|
|
8
11
|
type RouteHandler<T extends RequestInfo = RequestInfo> = RouteFunction<T> | RouteComponent<T> | readonly [...RouteMiddleware<T>[], RouteFunction<T> | RouteComponent<T>];
|
|
9
12
|
declare const METHOD_VERBS: readonly ["delete", "get", "head", "patch", "post", "put"];
|
|
10
13
|
export type MethodVerb = (typeof METHOD_VERBS)[number];
|