@real-router/types 0.20.0 → 0.22.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.
@@ -576,11 +576,11 @@ type EventsKeys = "ROUTER_START" | "ROUTER_STOP" | "TRANSITION_START" | "TRANSIT
576
576
  /**
577
577
  * Error code values
578
578
  */
579
- type ErrorCodeValues = "NOT_STARTED" | "NO_START_PATH_OR_STATE" | "ALREADY_STARTED" | "ROUTE_NOT_FOUND" | "SAME_STATES" | "CANNOT_DEACTIVATE" | "CANNOT_ACTIVATE" | "TRANSITION_ERR" | "CANCELLED" | "DISPOSED";
579
+ type ErrorCodeValues = "NOT_STARTED" | "NO_START_PATH_OR_STATE" | "ALREADY_STARTED" | "ROUTE_NOT_FOUND" | "SAME_STATES" | "CANNOT_DEACTIVATE" | "CANNOT_ACTIVATE" | "TRANSITION_ERR" | "CANCELLED" | "DISPOSED" | "PLUGIN_CONFLICT";
580
580
  /**
581
581
  * Error code keys
582
582
  */
583
- type ErrorCodeKeys = "ROUTER_NOT_STARTED" | "NO_START_PATH_OR_STATE" | "ROUTER_ALREADY_STARTED" | "ROUTE_NOT_FOUND" | "SAME_STATES" | "CANNOT_DEACTIVATE" | "CANNOT_ACTIVATE" | "TRANSITION_ERR" | "TRANSITION_CANCELLED" | "ROUTER_DISPOSED";
583
+ type ErrorCodeKeys = "ROUTER_NOT_STARTED" | "NO_START_PATH_OR_STATE" | "ROUTER_ALREADY_STARTED" | "ROUTE_NOT_FOUND" | "SAME_STATES" | "CANNOT_DEACTIVATE" | "CANNOT_ACTIVATE" | "TRANSITION_ERR" | "TRANSITION_CANCELLED" | "ROUTER_DISPOSED" | "PLUGIN_CONFLICT";
584
584
  /**
585
585
  * Mapping of event keys to plugin methods
586
586
  */
@@ -624,6 +624,7 @@ interface ErrorCodeToValueMap {
624
624
  TRANSITION_ERR: "TRANSITION_ERR";
625
625
  TRANSITION_CANCELLED: "CANCELLED";
626
626
  ROUTER_DISPOSED: "DISPOSED";
627
+ PLUGIN_CONFLICT: "PLUGIN_CONFLICT";
627
628
  }
628
629
 
629
630
  /**
@@ -631,6 +632,24 @@ interface ErrorCodeToValueMap {
631
632
  * These interfaces are implemented by standalone API functions in @real-router/core.
632
633
  */
633
634
 
635
+ /**
636
+ * Maps interceptable method names to their signatures.
637
+ * Used by {@link PluginApi.addInterceptor} to provide type-safe interceptor registration.
638
+ *
639
+ * To add a new interceptable method:
640
+ * 1. Add its signature here
641
+ * 2. Wrap it with `createInterceptable()` in `RouterWiringBuilder`
642
+ */
643
+ interface InterceptableMethodMap {
644
+ start: (path?: string) => Promise<State>;
645
+ buildPath: (route: string, params?: Params) => string;
646
+ forwardState: (routeName: string, routeParams: Params) => SimpleState;
647
+ }
648
+ /**
649
+ * Type-safe interceptor callback.
650
+ * Receives `next` (the next function in the chain) followed by the method's original parameters.
651
+ */
652
+ type InterceptorFn<M extends keyof InterceptableMethodMap> = (next: InterceptableMethodMap[M], ...args: Parameters<InterceptableMethodMap[M]>) => ReturnType<InterceptableMethodMap[M]>;
634
653
  /**
635
654
  * Plugin API — for plugins and infrastructure packages.
636
655
  * Hides plugin-internal methods from public autocomplete.
@@ -642,14 +661,12 @@ interface PluginApi {
642
661
  matchPath: <P extends Params = Params, MP extends Params = Params>(path: string) => State<P, MP> | undefined;
643
662
  setRootPath: (rootPath: string) => void;
644
663
  getRootPath: () => string;
645
- navigateToState: (toState: State, fromState: State | undefined, opts: NavigationOptions) => Promise<State>;
646
664
  addEventListener: <E extends EventName>(eventName: E, cb: Plugin[EventMethodMap[E]]) => Unsubscribe;
647
665
  buildNavigationState: (name: string, params?: Params) => State | undefined;
648
666
  getOptions: () => Options;
649
667
  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;
652
- addBuildPathInterceptor: (fn: (routeName: string, params: Params) => Params) => Unsubscribe;
668
+ addInterceptor: <M extends keyof InterceptableMethodMap>(method: M, fn: InterceptorFn<M>) => Unsubscribe;
669
+ extendRouter: (extensions: Record<string, unknown>) => Unsubscribe;
653
670
  }
654
671
  /**
655
672
  * Routes API — for dynamic route mutation.
@@ -688,4 +705,4 @@ interface LifecycleApi<Dependencies extends DefaultDependencies = DefaultDepende
688
705
  removeDeactivateGuard: (name: string) => void;
689
706
  }
690
707
 
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 };
708
+ 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}}}
@@ -576,11 +576,11 @@ type EventsKeys = "ROUTER_START" | "ROUTER_STOP" | "TRANSITION_START" | "TRANSIT
576
576
  /**
577
577
  * Error code values
578
578
  */
579
- type ErrorCodeValues = "NOT_STARTED" | "NO_START_PATH_OR_STATE" | "ALREADY_STARTED" | "ROUTE_NOT_FOUND" | "SAME_STATES" | "CANNOT_DEACTIVATE" | "CANNOT_ACTIVATE" | "TRANSITION_ERR" | "CANCELLED" | "DISPOSED";
579
+ type ErrorCodeValues = "NOT_STARTED" | "NO_START_PATH_OR_STATE" | "ALREADY_STARTED" | "ROUTE_NOT_FOUND" | "SAME_STATES" | "CANNOT_DEACTIVATE" | "CANNOT_ACTIVATE" | "TRANSITION_ERR" | "CANCELLED" | "DISPOSED" | "PLUGIN_CONFLICT";
580
580
  /**
581
581
  * Error code keys
582
582
  */
583
- type ErrorCodeKeys = "ROUTER_NOT_STARTED" | "NO_START_PATH_OR_STATE" | "ROUTER_ALREADY_STARTED" | "ROUTE_NOT_FOUND" | "SAME_STATES" | "CANNOT_DEACTIVATE" | "CANNOT_ACTIVATE" | "TRANSITION_ERR" | "TRANSITION_CANCELLED" | "ROUTER_DISPOSED";
583
+ type ErrorCodeKeys = "ROUTER_NOT_STARTED" | "NO_START_PATH_OR_STATE" | "ROUTER_ALREADY_STARTED" | "ROUTE_NOT_FOUND" | "SAME_STATES" | "CANNOT_DEACTIVATE" | "CANNOT_ACTIVATE" | "TRANSITION_ERR" | "TRANSITION_CANCELLED" | "ROUTER_DISPOSED" | "PLUGIN_CONFLICT";
584
584
  /**
585
585
  * Mapping of event keys to plugin methods
586
586
  */
@@ -624,6 +624,7 @@ interface ErrorCodeToValueMap {
624
624
  TRANSITION_ERR: "TRANSITION_ERR";
625
625
  TRANSITION_CANCELLED: "CANCELLED";
626
626
  ROUTER_DISPOSED: "DISPOSED";
627
+ PLUGIN_CONFLICT: "PLUGIN_CONFLICT";
627
628
  }
628
629
 
629
630
  /**
@@ -631,6 +632,24 @@ interface ErrorCodeToValueMap {
631
632
  * These interfaces are implemented by standalone API functions in @real-router/core.
632
633
  */
633
634
 
635
+ /**
636
+ * Maps interceptable method names to their signatures.
637
+ * Used by {@link PluginApi.addInterceptor} to provide type-safe interceptor registration.
638
+ *
639
+ * To add a new interceptable method:
640
+ * 1. Add its signature here
641
+ * 2. Wrap it with `createInterceptable()` in `RouterWiringBuilder`
642
+ */
643
+ interface InterceptableMethodMap {
644
+ start: (path?: string) => Promise<State>;
645
+ buildPath: (route: string, params?: Params) => string;
646
+ forwardState: (routeName: string, routeParams: Params) => SimpleState;
647
+ }
648
+ /**
649
+ * Type-safe interceptor callback.
650
+ * Receives `next` (the next function in the chain) followed by the method's original parameters.
651
+ */
652
+ type InterceptorFn<M extends keyof InterceptableMethodMap> = (next: InterceptableMethodMap[M], ...args: Parameters<InterceptableMethodMap[M]>) => ReturnType<InterceptableMethodMap[M]>;
634
653
  /**
635
654
  * Plugin API — for plugins and infrastructure packages.
636
655
  * Hides plugin-internal methods from public autocomplete.
@@ -642,14 +661,12 @@ interface PluginApi {
642
661
  matchPath: <P extends Params = Params, MP extends Params = Params>(path: string) => State<P, MP> | undefined;
643
662
  setRootPath: (rootPath: string) => void;
644
663
  getRootPath: () => string;
645
- navigateToState: (toState: State, fromState: State | undefined, opts: NavigationOptions) => Promise<State>;
646
664
  addEventListener: <E extends EventName>(eventName: E, cb: Plugin[EventMethodMap[E]]) => Unsubscribe;
647
665
  buildNavigationState: (name: string, params?: Params) => State | undefined;
648
666
  getOptions: () => Options;
649
667
  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;
652
- addBuildPathInterceptor: (fn: (routeName: string, params: Params) => Params) => Unsubscribe;
668
+ addInterceptor: <M extends keyof InterceptableMethodMap>(method: M, fn: InterceptorFn<M>) => Unsubscribe;
669
+ extendRouter: (extensions: Record<string, unknown>) => Unsubscribe;
653
670
  }
654
671
  /**
655
672
  * Routes API — for dynamic route mutation.
@@ -688,4 +705,4 @@ interface LifecycleApi<Dependencies extends DefaultDependencies = DefaultDepende
688
705
  removeDeactivateGuard: (name: string) => void;
689
706
  }
690
707
 
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 };
708
+ 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.20.0",
3
+ "version": "0.22.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,21 +87,12 @@ 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;
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;
94
+
95
+ extendRouter: (extensions: Record<string, unknown>) => Unsubscribe;
89
96
  }
90
97
 
91
98
  /**
package/src/constants.ts CHANGED
@@ -46,7 +46,8 @@ export type ErrorCodeValues =
46
46
  | "CANNOT_ACTIVATE"
47
47
  | "TRANSITION_ERR"
48
48
  | "CANCELLED"
49
- | "DISPOSED";
49
+ | "DISPOSED"
50
+ | "PLUGIN_CONFLICT";
50
51
 
51
52
  /**
52
53
  * Error code keys
@@ -61,7 +62,8 @@ export type ErrorCodeKeys =
61
62
  | "CANNOT_ACTIVATE"
62
63
  | "TRANSITION_ERR"
63
64
  | "TRANSITION_CANCELLED"
64
- | "ROUTER_DISPOSED";
65
+ | "ROUTER_DISPOSED"
66
+ | "PLUGIN_CONFLICT";
65
67
 
66
68
  /**
67
69
  * Mapping of event keys to plugin methods
@@ -109,4 +111,5 @@ export interface ErrorCodeToValueMap {
109
111
  TRANSITION_ERR: "TRANSITION_ERR";
110
112
  TRANSITION_CANCELLED: "CANCELLED";
111
113
  ROUTER_DISPOSED: "DISPOSED";
114
+ PLUGIN_CONFLICT: "PLUGIN_CONFLICT";
112
115
  }
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