@real-router/types 0.19.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.
@@ -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,13 +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
- getForwardState: () => <P extends Params = Params>(routeName: string, routeParams: P) => SimpleState<P>;
651
- setForwardState: (fn: <P extends Params = Params>(routeName: string, routeParams: P) => SimpleState<P>) => void;
667
+ addInterceptor: <M extends keyof InterceptableMethodMap>(method: M, fn: InterceptorFn<M>) => Unsubscribe;
652
668
  }
653
669
  /**
654
670
  * Routes API — for dynamic route mutation.
@@ -687,4 +703,4 @@ interface LifecycleApi<Dependencies extends DefaultDependencies = DefaultDepende
687
703
  removeDeactivateGuard: (name: string) => void;
688
704
  }
689
705
 
690
- 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":1349,"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}}}
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}}}
@@ -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,13 +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
- getForwardState: () => <P extends Params = Params>(routeName: string, routeParams: P) => SimpleState<P>;
651
- setForwardState: (fn: <P extends Params = Params>(routeName: string, routeParams: P) => SimpleState<P>) => void;
667
+ addInterceptor: <M extends keyof InterceptableMethodMap>(method: M, fn: InterceptorFn<M>) => Unsubscribe;
652
668
  }
653
669
  /**
654
670
  * Routes API — for dynamic route mutation.
@@ -687,4 +703,4 @@ interface LifecycleApi<Dependencies extends DefaultDependencies = DefaultDepende
687
703
  removeDeactivateGuard: (name: string) => void;
688
704
  }
689
705
 
690
- 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":1349,"imports":[],"format":"esm"}},"outputs":{"dist/esm/index.mjs":{"imports":[],"exports":[],"entryPoint":"src/index.ts","inputs":{"src/index.ts":{"bytesInOutput":0}},"bytes":0}}}
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@real-router/types",
3
- "version": "0.19.0",
3
+ "version": "0.21.0",
4
4
  "type": "commonjs",
5
5
  "description": "Shared TypeScript types for Real Router ecosystem",
6
6
  "types": "./dist/esm/index.d.mts",
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,17 +87,10 @@ export interface PluginApi {
71
87
 
72
88
  getTree: () => unknown;
73
89
 
74
- getForwardState: () => <P extends Params = Params>(
75
- routeName: string,
76
- routeParams: P,
77
- ) => SimpleState<P>;
78
-
79
- setForwardState: (
80
- fn: <P extends Params = Params>(
81
- routeName: string,
82
- routeParams: P,
83
- ) => SimpleState<P>,
84
- ) => void;
90
+ addInterceptor: <M extends keyof InterceptableMethodMap>(
91
+ method: M,
92
+ fn: InterceptorFn<M>,
93
+ ) => Unsubscribe;
85
94
  }
86
95
 
87
96
  /**
package/src/index.ts CHANGED
@@ -66,6 +66,8 @@ export type {
66
66
  RoutesApi,
67
67
  DependenciesApi,
68
68
  LifecycleApi,
69
+ InterceptableMethodMap,
70
+ InterceptorFn,
69
71
  } from "./api";
70
72
 
71
73
  // Note: RouterError type is a forward declaration matching the class in real-router package