@real-router/types 0.10.0 → 0.12.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.
@@ -40,16 +40,29 @@ interface RouteTreeState<P extends Record<string, unknown> = RouteParams> {
40
40
  }
41
41
 
42
42
  type Unsubscribe = () => void;
43
- type CancelFn = () => void;
44
43
  interface SimpleState<P extends Params = Params> {
45
44
  name: string;
46
45
  params: P;
47
46
  }
47
+ type TransitionPhase = "deactivating" | "activating" | "middleware";
48
+ type TransitionReason = "success" | "blocked" | "cancelled" | "error";
49
+ interface TransitionMeta {
50
+ phase: TransitionPhase;
51
+ from?: string;
52
+ reason: TransitionReason;
53
+ blocker?: string;
54
+ segments: {
55
+ deactivated: string[];
56
+ activated: string[];
57
+ intersection: string;
58
+ };
59
+ }
48
60
  interface State<P extends Params = Params, MP extends Params = Params> {
49
61
  name: string;
50
62
  params: P;
51
63
  path: string;
52
64
  meta?: StateMeta<MP> | undefined;
65
+ transition?: TransitionMeta | undefined;
53
66
  }
54
67
  interface StateMeta<P extends Params = Params> {
55
68
  id: number;
@@ -82,7 +95,6 @@ interface RouterError extends Error {
82
95
  getField: (key: string) => unknown;
83
96
  toJSON: () => Record<string, unknown>;
84
97
  }
85
- type DoneFn = (error?: RouterError, state?: State) => void;
86
98
  /**
87
99
  * Configuration options that control navigation transition behavior.
88
100
  *
@@ -282,6 +294,13 @@ interface LimitsConfig {
282
294
  * @default 10000
283
295
  */
284
296
  maxListeners: number;
297
+ /**
298
+ * Listener count at which a memory leak warning is logged per event type.
299
+ * Set to 0 to disable the warning.
300
+ *
301
+ * @default 1000
302
+ */
303
+ warnListeners: number;
285
304
  /**
286
305
  * Maximum depth of nested event propagation.
287
306
  * Prevents infinite recursion in event handling chains.
@@ -415,7 +434,7 @@ interface Options {
415
434
  */
416
435
  noValidate?: boolean;
417
436
  }
418
- type ActivationFn = (toState: State, fromState: State | undefined, done: DoneFn) => boolean | Promise<boolean | object | void> | State | void;
437
+ type ActivationFn = (toState: State, fromState: State | undefined) => boolean | Promise<boolean | State | void> | State | void;
419
438
  type DefaultDependencies = object;
420
439
  interface Config {
421
440
  decoders: Record<string, (params: Params) => Params>;
@@ -457,7 +476,7 @@ interface Subscription {
457
476
  * For full router access, use the Router interface directly or the useRouter() hook.
458
477
  */
459
478
  interface Navigator {
460
- navigate: (routeName: string, routeParamsOrDone?: Params | DoneFn, optionsOrDone?: NavigationOptions | DoneFn, done?: DoneFn) => CancelFn;
479
+ navigate: (routeName: string, routeParams?: Params, options?: NavigationOptions) => Promise<State>;
461
480
  getState: () => State | undefined;
462
481
  isActiveRoute: (name: string, params?: Params, strictEquality?: boolean, ignoreQueryParams?: boolean) => boolean;
463
482
  canNavigateTo: (name: string, params?: Params) => boolean;
@@ -513,6 +532,15 @@ interface Router {
513
532
  * @returns true if navigation is allowed, false otherwise
514
533
  */
515
534
  canNavigateTo: (name: string, params?: Params) => boolean;
535
+ /**
536
+ * Dispose the router and release all resources.
537
+ *
538
+ * Stops the router if active, calls plugin teardown, clears all event
539
+ * listeners, middleware, routes, and dependencies. After disposal, all
540
+ * mutating methods throw a ROUTER_DISPOSED error. Idempotent — safe to
541
+ * call multiple times.
542
+ */
543
+ dispose: () => void;
516
544
  }
517
545
 
518
546
  /**
@@ -530,11 +558,11 @@ type EventsKeys = "ROUTER_START" | "ROUTER_STOP" | "TRANSITION_START" | "TRANSIT
530
558
  /**
531
559
  * Error code values
532
560
  */
533
- type ErrorCodeValues = "NOT_STARTED" | "NO_START_PATH_OR_STATE" | "ALREADY_STARTED" | "ROUTE_NOT_FOUND" | "SAME_STATES" | "CANNOT_DEACTIVATE" | "CANNOT_ACTIVATE" | "TRANSITION_ERR" | "CANCELLED";
561
+ type ErrorCodeValues = "NOT_STARTED" | "NO_START_PATH_OR_STATE" | "ALREADY_STARTED" | "ROUTE_NOT_FOUND" | "SAME_STATES" | "CANNOT_DEACTIVATE" | "CANNOT_ACTIVATE" | "TRANSITION_ERR" | "CANCELLED" | "DISPOSED";
534
562
  /**
535
563
  * Error code keys
536
564
  */
537
- 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";
565
+ 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";
538
566
  /**
539
567
  * Mapping of event keys to plugin methods
540
568
  */
@@ -570,6 +598,7 @@ interface ErrorCodeToValueMap {
570
598
  CANNOT_ACTIVATE: "CANNOT_ACTIVATE";
571
599
  TRANSITION_ERR: "TRANSITION_ERR";
572
600
  TRANSITION_CANCELLED: "CANCELLED";
601
+ ROUTER_DISPOSED: "DISPOSED";
573
602
  }
574
603
 
575
- export type { ActivationFn, CancelFn, Config, DefaultDependencies, DefaultParamsCallback, DefaultRouteCallback, DoneFn, ErrorCodeKeys, ErrorCodeToValueMap, ErrorCodeValues, EventName, EventToNameMap, EventToPluginMap, EventsKeys, ForwardToCallback, LimitsConfig, Listener, Middleware, NavigationOptions, Navigator, Options, Params, Plugin, PluginMethod, QueryParamsMode, QueryParamsOptions, RouteTreeState, Router, RouterError, SimpleState, State, StateMeta, StateMetaInput, SubscribeFn, SubscribeState, Subscription, Unsubscribe };
604
+ export type { ActivationFn, Config, DefaultDependencies, DefaultParamsCallback, DefaultRouteCallback, ErrorCodeKeys, ErrorCodeToValueMap, ErrorCodeValues, EventName, EventToNameMap, EventToPluginMap, EventsKeys, ForwardToCallback, LimitsConfig, Listener, Middleware, NavigationOptions, Navigator, Options, Params, Plugin, PluginMethod, QueryParamsMode, QueryParamsOptions, RouteTreeState, Router, RouterError, 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":1248,"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":1283,"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}}}
@@ -40,16 +40,29 @@ interface RouteTreeState<P extends Record<string, unknown> = RouteParams> {
40
40
  }
41
41
 
42
42
  type Unsubscribe = () => void;
43
- type CancelFn = () => void;
44
43
  interface SimpleState<P extends Params = Params> {
45
44
  name: string;
46
45
  params: P;
47
46
  }
47
+ type TransitionPhase = "deactivating" | "activating" | "middleware";
48
+ type TransitionReason = "success" | "blocked" | "cancelled" | "error";
49
+ interface TransitionMeta {
50
+ phase: TransitionPhase;
51
+ from?: string;
52
+ reason: TransitionReason;
53
+ blocker?: string;
54
+ segments: {
55
+ deactivated: string[];
56
+ activated: string[];
57
+ intersection: string;
58
+ };
59
+ }
48
60
  interface State<P extends Params = Params, MP extends Params = Params> {
49
61
  name: string;
50
62
  params: P;
51
63
  path: string;
52
64
  meta?: StateMeta<MP> | undefined;
65
+ transition?: TransitionMeta | undefined;
53
66
  }
54
67
  interface StateMeta<P extends Params = Params> {
55
68
  id: number;
@@ -82,7 +95,6 @@ interface RouterError extends Error {
82
95
  getField: (key: string) => unknown;
83
96
  toJSON: () => Record<string, unknown>;
84
97
  }
85
- type DoneFn = (error?: RouterError, state?: State) => void;
86
98
  /**
87
99
  * Configuration options that control navigation transition behavior.
88
100
  *
@@ -282,6 +294,13 @@ interface LimitsConfig {
282
294
  * @default 10000
283
295
  */
284
296
  maxListeners: number;
297
+ /**
298
+ * Listener count at which a memory leak warning is logged per event type.
299
+ * Set to 0 to disable the warning.
300
+ *
301
+ * @default 1000
302
+ */
303
+ warnListeners: number;
285
304
  /**
286
305
  * Maximum depth of nested event propagation.
287
306
  * Prevents infinite recursion in event handling chains.
@@ -415,7 +434,7 @@ interface Options {
415
434
  */
416
435
  noValidate?: boolean;
417
436
  }
418
- type ActivationFn = (toState: State, fromState: State | undefined, done: DoneFn) => boolean | Promise<boolean | object | void> | State | void;
437
+ type ActivationFn = (toState: State, fromState: State | undefined) => boolean | Promise<boolean | State | void> | State | void;
419
438
  type DefaultDependencies = object;
420
439
  interface Config {
421
440
  decoders: Record<string, (params: Params) => Params>;
@@ -457,7 +476,7 @@ interface Subscription {
457
476
  * For full router access, use the Router interface directly or the useRouter() hook.
458
477
  */
459
478
  interface Navigator {
460
- navigate: (routeName: string, routeParamsOrDone?: Params | DoneFn, optionsOrDone?: NavigationOptions | DoneFn, done?: DoneFn) => CancelFn;
479
+ navigate: (routeName: string, routeParams?: Params, options?: NavigationOptions) => Promise<State>;
461
480
  getState: () => State | undefined;
462
481
  isActiveRoute: (name: string, params?: Params, strictEquality?: boolean, ignoreQueryParams?: boolean) => boolean;
463
482
  canNavigateTo: (name: string, params?: Params) => boolean;
@@ -513,6 +532,15 @@ interface Router {
513
532
  * @returns true if navigation is allowed, false otherwise
514
533
  */
515
534
  canNavigateTo: (name: string, params?: Params) => boolean;
535
+ /**
536
+ * Dispose the router and release all resources.
537
+ *
538
+ * Stops the router if active, calls plugin teardown, clears all event
539
+ * listeners, middleware, routes, and dependencies. After disposal, all
540
+ * mutating methods throw a ROUTER_DISPOSED error. Idempotent — safe to
541
+ * call multiple times.
542
+ */
543
+ dispose: () => void;
516
544
  }
517
545
 
518
546
  /**
@@ -530,11 +558,11 @@ type EventsKeys = "ROUTER_START" | "ROUTER_STOP" | "TRANSITION_START" | "TRANSIT
530
558
  /**
531
559
  * Error code values
532
560
  */
533
- type ErrorCodeValues = "NOT_STARTED" | "NO_START_PATH_OR_STATE" | "ALREADY_STARTED" | "ROUTE_NOT_FOUND" | "SAME_STATES" | "CANNOT_DEACTIVATE" | "CANNOT_ACTIVATE" | "TRANSITION_ERR" | "CANCELLED";
561
+ type ErrorCodeValues = "NOT_STARTED" | "NO_START_PATH_OR_STATE" | "ALREADY_STARTED" | "ROUTE_NOT_FOUND" | "SAME_STATES" | "CANNOT_DEACTIVATE" | "CANNOT_ACTIVATE" | "TRANSITION_ERR" | "CANCELLED" | "DISPOSED";
534
562
  /**
535
563
  * Error code keys
536
564
  */
537
- 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";
565
+ 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";
538
566
  /**
539
567
  * Mapping of event keys to plugin methods
540
568
  */
@@ -570,6 +598,7 @@ interface ErrorCodeToValueMap {
570
598
  CANNOT_ACTIVATE: "CANNOT_ACTIVATE";
571
599
  TRANSITION_ERR: "TRANSITION_ERR";
572
600
  TRANSITION_CANCELLED: "CANCELLED";
601
+ ROUTER_DISPOSED: "DISPOSED";
573
602
  }
574
603
 
575
- export type { ActivationFn, CancelFn, Config, DefaultDependencies, DefaultParamsCallback, DefaultRouteCallback, DoneFn, ErrorCodeKeys, ErrorCodeToValueMap, ErrorCodeValues, EventName, EventToNameMap, EventToPluginMap, EventsKeys, ForwardToCallback, LimitsConfig, Listener, Middleware, NavigationOptions, Navigator, Options, Params, Plugin, PluginMethod, QueryParamsMode, QueryParamsOptions, RouteTreeState, Router, RouterError, SimpleState, State, StateMeta, StateMetaInput, SubscribeFn, SubscribeState, Subscription, Unsubscribe };
604
+ export type { ActivationFn, Config, DefaultDependencies, DefaultParamsCallback, DefaultRouteCallback, ErrorCodeKeys, ErrorCodeToValueMap, ErrorCodeValues, EventName, EventToNameMap, EventToPluginMap, EventsKeys, ForwardToCallback, LimitsConfig, Listener, Middleware, NavigationOptions, Navigator, Options, Params, Plugin, PluginMethod, QueryParamsMode, QueryParamsOptions, RouteTreeState, Router, RouterError, SimpleState, State, StateMeta, StateMetaInput, SubscribeFn, SubscribeState, Subscription, TransitionMeta, TransitionPhase, TransitionReason, Unsubscribe };
@@ -1 +1 @@
1
- {"inputs":{"src/index.ts":{"bytes":1248,"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":1283,"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.10.0",
3
+ "version": "0.12.0",
4
4
  "type": "commonjs",
5
5
  "description": "Shared TypeScript types for Real Router ecosystem",
6
6
  "types": "./dist/esm/index.d.mts",