@real-router/types 0.20.0 → 0.21.0
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/dist/cjs/index.d.ts +20 -5
- package/dist/cjs/metafile-cjs.json +1 -1
- package/dist/esm/index.d.mts +20 -5
- package/dist/esm/metafile-esm.json +1 -1
- package/package.json +1 -1
- package/src/api.ts +26 -21
- package/src/index.ts +2 -0
package/dist/cjs/index.d.ts
CHANGED
|
@@ -631,6 +631,24 @@ interface ErrorCodeToValueMap {
|
|
|
631
631
|
* These interfaces are implemented by standalone API functions in @real-router/core.
|
|
632
632
|
*/
|
|
633
633
|
|
|
634
|
+
/**
|
|
635
|
+
* Maps interceptable method names to their signatures.
|
|
636
|
+
* Used by {@link PluginApi.addInterceptor} to provide type-safe interceptor registration.
|
|
637
|
+
*
|
|
638
|
+
* To add a new interceptable method:
|
|
639
|
+
* 1. Add its signature here
|
|
640
|
+
* 2. Wrap it with `createInterceptable()` in `RouterWiringBuilder`
|
|
641
|
+
*/
|
|
642
|
+
interface InterceptableMethodMap {
|
|
643
|
+
start: (path?: string) => Promise<State>;
|
|
644
|
+
buildPath: (route: string, params?: Params) => string;
|
|
645
|
+
forwardState: (routeName: string, routeParams: Params) => SimpleState;
|
|
646
|
+
}
|
|
647
|
+
/**
|
|
648
|
+
* Type-safe interceptor callback.
|
|
649
|
+
* Receives `next` (the next function in the chain) followed by the method's original parameters.
|
|
650
|
+
*/
|
|
651
|
+
type InterceptorFn<M extends keyof InterceptableMethodMap> = (next: InterceptableMethodMap[M], ...args: Parameters<InterceptableMethodMap[M]>) => ReturnType<InterceptableMethodMap[M]>;
|
|
634
652
|
/**
|
|
635
653
|
* Plugin API — for plugins and infrastructure packages.
|
|
636
654
|
* Hides plugin-internal methods from public autocomplete.
|
|
@@ -642,14 +660,11 @@ interface PluginApi {
|
|
|
642
660
|
matchPath: <P extends Params = Params, MP extends Params = Params>(path: string) => State<P, MP> | undefined;
|
|
643
661
|
setRootPath: (rootPath: string) => void;
|
|
644
662
|
getRootPath: () => string;
|
|
645
|
-
navigateToState: (toState: State, fromState: State | undefined, opts: NavigationOptions) => Promise<State>;
|
|
646
663
|
addEventListener: <E extends EventName>(eventName: E, cb: Plugin[EventMethodMap[E]]) => Unsubscribe;
|
|
647
664
|
buildNavigationState: (name: string, params?: Params) => State | undefined;
|
|
648
665
|
getOptions: () => Options;
|
|
649
666
|
getTree: () => unknown;
|
|
650
|
-
|
|
651
|
-
setForwardState: (fn: <P extends Params = Params>(routeName: string, routeParams: P) => SimpleState<P>) => void;
|
|
652
|
-
addBuildPathInterceptor: (fn: (routeName: string, params: Params) => Params) => Unsubscribe;
|
|
667
|
+
addInterceptor: <M extends keyof InterceptableMethodMap>(method: M, fn: InterceptorFn<M>) => Unsubscribe;
|
|
653
668
|
}
|
|
654
669
|
/**
|
|
655
670
|
* Routes API — for dynamic route mutation.
|
|
@@ -688,4 +703,4 @@ interface LifecycleApi<Dependencies extends DefaultDependencies = DefaultDepende
|
|
|
688
703
|
removeDeactivateGuard: (name: string) => void;
|
|
689
704
|
}
|
|
690
705
|
|
|
691
|
-
export type { Config, DefaultDependencies, DefaultParamsCallback, DefaultRouteCallback, DependenciesApi, ErrorCodeKeys, ErrorCodeToValueMap, ErrorCodeValues, EventMethodMap, EventName, EventToNameMap, EventToPluginMap, EventsKeys, ForwardToCallback, GuardFn, GuardFnFactory, LifecycleApi, LimitsConfig, Listener, NavigationOptions, Navigator, Options, Params, Plugin, PluginApi, PluginFactory, PluginMethod, QueryParamsMode, QueryParamsOptions, Route, RouteConfigUpdate, RouteParams, RouteTreeState, Router, RouterError, RoutesApi, SimpleState, State, StateMeta, StateMetaInput, SubscribeFn, SubscribeState, Subscription, TransitionMeta, TransitionPhase, TransitionReason, Unsubscribe };
|
|
706
|
+
export type { Config, DefaultDependencies, DefaultParamsCallback, DefaultRouteCallback, DependenciesApi, ErrorCodeKeys, ErrorCodeToValueMap, ErrorCodeValues, EventMethodMap, EventName, EventToNameMap, EventToPluginMap, EventsKeys, ForwardToCallback, GuardFn, GuardFnFactory, InterceptableMethodMap, InterceptorFn, LifecycleApi, LimitsConfig, Listener, NavigationOptions, Navigator, Options, Params, Plugin, PluginApi, PluginFactory, PluginMethod, QueryParamsMode, QueryParamsOptions, Route, RouteConfigUpdate, RouteParams, RouteTreeState, Router, RouterError, RoutesApi, SimpleState, State, StateMeta, StateMetaInput, SubscribeFn, SubscribeState, Subscription, TransitionMeta, TransitionPhase, TransitionReason, Unsubscribe };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"inputs":{"../../node_modules/.pnpm/tsup@8.5.1_jiti@2.6.1_postcss@8.5.6_typescript@5.9.3/node_modules/tsup/assets/cjs_shims.js":{"bytes":569,"imports":[],"format":"esm"},"src/index.ts":{"bytes":
|
|
1
|
+
{"inputs":{"../../node_modules/.pnpm/tsup@8.5.1_jiti@2.6.1_postcss@8.5.6_typescript@5.9.3/node_modules/tsup/assets/cjs_shims.js":{"bytes":569,"imports":[],"format":"esm"},"src/index.ts":{"bytes":1392,"imports":[{"path":"/home/runner/work/real-router/real-router/node_modules/.pnpm/tsup@8.5.1_jiti@2.6.1_postcss@8.5.6_typescript@5.9.3/node_modules/tsup/assets/cjs_shims.js","kind":"import-statement","external":true}],"format":"esm"}},"outputs":{"dist/cjs/index.js":{"imports":[],"exports":[],"entryPoint":"src/index.ts","inputs":{"src/index.ts":{"bytesInOutput":0}},"bytes":0}}}
|
package/dist/esm/index.d.mts
CHANGED
|
@@ -631,6 +631,24 @@ interface ErrorCodeToValueMap {
|
|
|
631
631
|
* These interfaces are implemented by standalone API functions in @real-router/core.
|
|
632
632
|
*/
|
|
633
633
|
|
|
634
|
+
/**
|
|
635
|
+
* Maps interceptable method names to their signatures.
|
|
636
|
+
* Used by {@link PluginApi.addInterceptor} to provide type-safe interceptor registration.
|
|
637
|
+
*
|
|
638
|
+
* To add a new interceptable method:
|
|
639
|
+
* 1. Add its signature here
|
|
640
|
+
* 2. Wrap it with `createInterceptable()` in `RouterWiringBuilder`
|
|
641
|
+
*/
|
|
642
|
+
interface InterceptableMethodMap {
|
|
643
|
+
start: (path?: string) => Promise<State>;
|
|
644
|
+
buildPath: (route: string, params?: Params) => string;
|
|
645
|
+
forwardState: (routeName: string, routeParams: Params) => SimpleState;
|
|
646
|
+
}
|
|
647
|
+
/**
|
|
648
|
+
* Type-safe interceptor callback.
|
|
649
|
+
* Receives `next` (the next function in the chain) followed by the method's original parameters.
|
|
650
|
+
*/
|
|
651
|
+
type InterceptorFn<M extends keyof InterceptableMethodMap> = (next: InterceptableMethodMap[M], ...args: Parameters<InterceptableMethodMap[M]>) => ReturnType<InterceptableMethodMap[M]>;
|
|
634
652
|
/**
|
|
635
653
|
* Plugin API — for plugins and infrastructure packages.
|
|
636
654
|
* Hides plugin-internal methods from public autocomplete.
|
|
@@ -642,14 +660,11 @@ interface PluginApi {
|
|
|
642
660
|
matchPath: <P extends Params = Params, MP extends Params = Params>(path: string) => State<P, MP> | undefined;
|
|
643
661
|
setRootPath: (rootPath: string) => void;
|
|
644
662
|
getRootPath: () => string;
|
|
645
|
-
navigateToState: (toState: State, fromState: State | undefined, opts: NavigationOptions) => Promise<State>;
|
|
646
663
|
addEventListener: <E extends EventName>(eventName: E, cb: Plugin[EventMethodMap[E]]) => Unsubscribe;
|
|
647
664
|
buildNavigationState: (name: string, params?: Params) => State | undefined;
|
|
648
665
|
getOptions: () => Options;
|
|
649
666
|
getTree: () => unknown;
|
|
650
|
-
|
|
651
|
-
setForwardState: (fn: <P extends Params = Params>(routeName: string, routeParams: P) => SimpleState<P>) => void;
|
|
652
|
-
addBuildPathInterceptor: (fn: (routeName: string, params: Params) => Params) => Unsubscribe;
|
|
667
|
+
addInterceptor: <M extends keyof InterceptableMethodMap>(method: M, fn: InterceptorFn<M>) => Unsubscribe;
|
|
653
668
|
}
|
|
654
669
|
/**
|
|
655
670
|
* Routes API — for dynamic route mutation.
|
|
@@ -688,4 +703,4 @@ interface LifecycleApi<Dependencies extends DefaultDependencies = DefaultDepende
|
|
|
688
703
|
removeDeactivateGuard: (name: string) => void;
|
|
689
704
|
}
|
|
690
705
|
|
|
691
|
-
export type { Config, DefaultDependencies, DefaultParamsCallback, DefaultRouteCallback, DependenciesApi, ErrorCodeKeys, ErrorCodeToValueMap, ErrorCodeValues, EventMethodMap, EventName, EventToNameMap, EventToPluginMap, EventsKeys, ForwardToCallback, GuardFn, GuardFnFactory, LifecycleApi, LimitsConfig, Listener, NavigationOptions, Navigator, Options, Params, Plugin, PluginApi, PluginFactory, PluginMethod, QueryParamsMode, QueryParamsOptions, Route, RouteConfigUpdate, RouteParams, RouteTreeState, Router, RouterError, RoutesApi, SimpleState, State, StateMeta, StateMetaInput, SubscribeFn, SubscribeState, Subscription, TransitionMeta, TransitionPhase, TransitionReason, Unsubscribe };
|
|
706
|
+
export type { Config, DefaultDependencies, DefaultParamsCallback, DefaultRouteCallback, DependenciesApi, ErrorCodeKeys, ErrorCodeToValueMap, ErrorCodeValues, EventMethodMap, EventName, EventToNameMap, EventToPluginMap, EventsKeys, ForwardToCallback, GuardFn, GuardFnFactory, InterceptableMethodMap, InterceptorFn, LifecycleApi, LimitsConfig, Listener, NavigationOptions, Navigator, Options, Params, Plugin, PluginApi, PluginFactory, PluginMethod, QueryParamsMode, QueryParamsOptions, Route, RouteConfigUpdate, RouteParams, RouteTreeState, Router, RouterError, RoutesApi, SimpleState, State, StateMeta, StateMetaInput, SubscribeFn, SubscribeState, Subscription, TransitionMeta, TransitionPhase, TransitionReason, Unsubscribe };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"inputs":{"src/index.ts":{"bytes":
|
|
1
|
+
{"inputs":{"src/index.ts":{"bytes":1392,"imports":[],"format":"esm"}},"outputs":{"dist/esm/index.mjs":{"imports":[],"exports":[],"entryPoint":"src/index.ts","inputs":{"src/index.ts":{"bytesInOutput":0}},"bytes":0}}}
|
package/package.json
CHANGED
package/src/api.ts
CHANGED
|
@@ -10,7 +10,6 @@ import type {
|
|
|
10
10
|
State,
|
|
11
11
|
SimpleState,
|
|
12
12
|
StateMetaInput,
|
|
13
|
-
NavigationOptions,
|
|
14
13
|
Unsubscribe,
|
|
15
14
|
} from "./base";
|
|
16
15
|
import type { EventMethodMap, EventName } from "./constants";
|
|
@@ -24,6 +23,29 @@ import type {
|
|
|
24
23
|
RouteConfigUpdate,
|
|
25
24
|
} from "./router";
|
|
26
25
|
|
|
26
|
+
/**
|
|
27
|
+
* Maps interceptable method names to their signatures.
|
|
28
|
+
* Used by {@link PluginApi.addInterceptor} to provide type-safe interceptor registration.
|
|
29
|
+
*
|
|
30
|
+
* To add a new interceptable method:
|
|
31
|
+
* 1. Add its signature here
|
|
32
|
+
* 2. Wrap it with `createInterceptable()` in `RouterWiringBuilder`
|
|
33
|
+
*/
|
|
34
|
+
export interface InterceptableMethodMap {
|
|
35
|
+
start: (path?: string) => Promise<State>;
|
|
36
|
+
buildPath: (route: string, params?: Params) => string;
|
|
37
|
+
forwardState: (routeName: string, routeParams: Params) => SimpleState;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Type-safe interceptor callback.
|
|
42
|
+
* Receives `next` (the next function in the chain) followed by the method's original parameters.
|
|
43
|
+
*/
|
|
44
|
+
export type InterceptorFn<M extends keyof InterceptableMethodMap> = (
|
|
45
|
+
next: InterceptableMethodMap[M],
|
|
46
|
+
...args: Parameters<InterceptableMethodMap[M]>
|
|
47
|
+
) => ReturnType<InterceptableMethodMap[M]>;
|
|
48
|
+
|
|
27
49
|
/**
|
|
28
50
|
* Plugin API — for plugins and infrastructure packages.
|
|
29
51
|
* Hides plugin-internal methods from public autocomplete.
|
|
@@ -54,12 +76,6 @@ export interface PluginApi {
|
|
|
54
76
|
setRootPath: (rootPath: string) => void;
|
|
55
77
|
getRootPath: () => string;
|
|
56
78
|
|
|
57
|
-
navigateToState: (
|
|
58
|
-
toState: State,
|
|
59
|
-
fromState: State | undefined,
|
|
60
|
-
opts: NavigationOptions,
|
|
61
|
-
) => Promise<State>;
|
|
62
|
-
|
|
63
79
|
addEventListener: <E extends EventName>(
|
|
64
80
|
eventName: E,
|
|
65
81
|
cb: Plugin[EventMethodMap[E]],
|
|
@@ -71,20 +87,9 @@ export interface PluginApi {
|
|
|
71
87
|
|
|
72
88
|
getTree: () => unknown;
|
|
73
89
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
) => SimpleState<P>;
|
|
78
|
-
|
|
79
|
-
setForwardState: (
|
|
80
|
-
fn: <P extends Params = Params>(
|
|
81
|
-
routeName: string,
|
|
82
|
-
routeParams: P,
|
|
83
|
-
) => SimpleState<P>,
|
|
84
|
-
) => void;
|
|
85
|
-
|
|
86
|
-
addBuildPathInterceptor: (
|
|
87
|
-
fn: (routeName: string, params: Params) => Params,
|
|
90
|
+
addInterceptor: <M extends keyof InterceptableMethodMap>(
|
|
91
|
+
method: M,
|
|
92
|
+
fn: InterceptorFn<M>,
|
|
88
93
|
) => Unsubscribe;
|
|
89
94
|
}
|
|
90
95
|
|