@real-router/types 0.8.0 → 0.9.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.
@@ -233,7 +233,7 @@ interface NavigationOptions {
233
233
  *
234
234
  * @example
235
235
  * // Accessing redirect flag in lifecycle
236
- * router.canActivate('dashboard', (toState, fromState) => {
236
+ * router.addActivateGuard('dashboard', (toState, fromState) => {
237
237
  * if (toState.meta?.redirected) {
238
238
  * console.log('This navigation is from a redirect');
239
239
  * }
@@ -460,8 +460,69 @@ interface Navigator {
460
460
  navigate: (routeName: string, routeParamsOrDone?: Params | DoneFn, optionsOrDone?: NavigationOptions | DoneFn, done?: DoneFn) => CancelFn;
461
461
  getState: () => State | undefined;
462
462
  isActiveRoute: (name: string, params?: Params, strictEquality?: boolean, ignoreQueryParams?: boolean) => boolean;
463
+ canNavigateTo: (name: string, params?: Params) => boolean;
463
464
  subscribe: (listener: SubscribeFn) => Unsubscribe;
464
465
  }
466
+ /**
467
+ * Router interface - public API for route navigation and lifecycle management.
468
+ *
469
+ * Defines the contract for router implementations. The actual Router class in
470
+ * @real-router/core implements this interface with full functionality.
471
+ *
472
+ * This interface uses `ActivationFn | boolean` for guard types to avoid circular
473
+ * dependencies. The concrete Router class in @real-router/core narrows this to
474
+ * `ActivationFnFactory | boolean` for more precise type checking.
475
+ */
476
+ interface Router {
477
+ /**
478
+ * Register an activation guard for a route.
479
+ *
480
+ * @param name - Route name
481
+ * @param guard - Guard function or boolean
482
+ * @returns this for method chaining
483
+ */
484
+ addActivateGuard: (name: string, guard: ActivationFn | boolean) => this;
485
+ /**
486
+ * Register a deactivation guard for a route.
487
+ *
488
+ * @param name - Route name
489
+ * @param guard - Guard function or boolean
490
+ * @returns this for method chaining
491
+ */
492
+ addDeactivateGuard: (name: string, guard: ActivationFn | boolean) => this;
493
+ /**
494
+ * Remove an activation guard from a route.
495
+ *
496
+ * @param name - Route name
497
+ */
498
+ removeActivateGuard: (name: string) => void;
499
+ /**
500
+ * Remove a deactivation guard from a route.
501
+ *
502
+ * @param name - Route name
503
+ */
504
+ removeDeactivateGuard: (name: string) => void;
505
+ /**
506
+ * Check if navigation to a route is allowed without performing actual navigation.
507
+ *
508
+ * Synchronously checks all activation and deactivation guards in the transition path.
509
+ * Async guards return false with a console warning.
510
+ *
511
+ * @param name - Route name to check
512
+ * @param params - Route parameters (optional)
513
+ * @returns true if navigation is allowed, false otherwise
514
+ */
515
+ canNavigateTo: (name: string, params?: Params) => boolean;
516
+ /**
517
+ * Get a minimal, safe Navigator interface for passing to components.
518
+ *
519
+ * The returned Navigator object is frozen and includes only essential methods:
520
+ * navigate, getState, isActiveRoute, canNavigateTo, subscribe.
521
+ *
522
+ * @returns Frozen Navigator object
523
+ */
524
+ getNavigator: () => Navigator;
525
+ }
465
526
 
466
527
  /**
467
528
  * Plugin lifecycle method names
@@ -520,4 +581,4 @@ interface ErrorCodeToValueMap {
520
581
  TRANSITION_CANCELLED: "CANCELLED";
521
582
  }
522
583
 
523
- 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, RouterError, SimpleState, State, StateMeta, StateMetaInput, SubscribeFn, SubscribeState, Subscription, Unsubscribe };
584
+ 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 };
@@ -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":1238,"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":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}}}
@@ -233,7 +233,7 @@ interface NavigationOptions {
233
233
  *
234
234
  * @example
235
235
  * // Accessing redirect flag in lifecycle
236
- * router.canActivate('dashboard', (toState, fromState) => {
236
+ * router.addActivateGuard('dashboard', (toState, fromState) => {
237
237
  * if (toState.meta?.redirected) {
238
238
  * console.log('This navigation is from a redirect');
239
239
  * }
@@ -460,8 +460,69 @@ interface Navigator {
460
460
  navigate: (routeName: string, routeParamsOrDone?: Params | DoneFn, optionsOrDone?: NavigationOptions | DoneFn, done?: DoneFn) => CancelFn;
461
461
  getState: () => State | undefined;
462
462
  isActiveRoute: (name: string, params?: Params, strictEquality?: boolean, ignoreQueryParams?: boolean) => boolean;
463
+ canNavigateTo: (name: string, params?: Params) => boolean;
463
464
  subscribe: (listener: SubscribeFn) => Unsubscribe;
464
465
  }
466
+ /**
467
+ * Router interface - public API for route navigation and lifecycle management.
468
+ *
469
+ * Defines the contract for router implementations. The actual Router class in
470
+ * @real-router/core implements this interface with full functionality.
471
+ *
472
+ * This interface uses `ActivationFn | boolean` for guard types to avoid circular
473
+ * dependencies. The concrete Router class in @real-router/core narrows this to
474
+ * `ActivationFnFactory | boolean` for more precise type checking.
475
+ */
476
+ interface Router {
477
+ /**
478
+ * Register an activation guard for a route.
479
+ *
480
+ * @param name - Route name
481
+ * @param guard - Guard function or boolean
482
+ * @returns this for method chaining
483
+ */
484
+ addActivateGuard: (name: string, guard: ActivationFn | boolean) => this;
485
+ /**
486
+ * Register a deactivation guard for a route.
487
+ *
488
+ * @param name - Route name
489
+ * @param guard - Guard function or boolean
490
+ * @returns this for method chaining
491
+ */
492
+ addDeactivateGuard: (name: string, guard: ActivationFn | boolean) => this;
493
+ /**
494
+ * Remove an activation guard from a route.
495
+ *
496
+ * @param name - Route name
497
+ */
498
+ removeActivateGuard: (name: string) => void;
499
+ /**
500
+ * Remove a deactivation guard from a route.
501
+ *
502
+ * @param name - Route name
503
+ */
504
+ removeDeactivateGuard: (name: string) => void;
505
+ /**
506
+ * Check if navigation to a route is allowed without performing actual navigation.
507
+ *
508
+ * Synchronously checks all activation and deactivation guards in the transition path.
509
+ * Async guards return false with a console warning.
510
+ *
511
+ * @param name - Route name to check
512
+ * @param params - Route parameters (optional)
513
+ * @returns true if navigation is allowed, false otherwise
514
+ */
515
+ canNavigateTo: (name: string, params?: Params) => boolean;
516
+ /**
517
+ * Get a minimal, safe Navigator interface for passing to components.
518
+ *
519
+ * The returned Navigator object is frozen and includes only essential methods:
520
+ * navigate, getState, isActiveRoute, canNavigateTo, subscribe.
521
+ *
522
+ * @returns Frozen Navigator object
523
+ */
524
+ getNavigator: () => Navigator;
525
+ }
465
526
 
466
527
  /**
467
528
  * Plugin lifecycle method names
@@ -520,4 +581,4 @@ interface ErrorCodeToValueMap {
520
581
  TRANSITION_CANCELLED: "CANCELLED";
521
582
  }
522
583
 
523
- 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, RouterError, SimpleState, State, StateMeta, StateMetaInput, SubscribeFn, SubscribeState, Subscription, Unsubscribe };
584
+ 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 };
@@ -1 +1 @@
1
- {"inputs":{"src/index.ts":{"bytes":1238,"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":1248,"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.8.0",
3
+ "version": "0.9.0",
4
4
  "type": "commonjs",
5
5
  "description": "Shared TypeScript types for Real Router ecosystem",
6
6
  "types": "./dist/esm/index.d.mts",