@real-router/core 0.35.1 → 0.36.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.
@@ -0,0 +1,165 @@
1
+ import { DefaultDependencies, Router as Router$1, Route, Options, Params, State, PluginFactory, Unsubscribe, SubscribeFn, NavigationOptions } from '@real-router/types';
2
+
3
+ /**
4
+ * Router class with integrated namespace architecture.
5
+ *
6
+ * All functionality is provided by namespace classes:
7
+ * - OptionsNamespace: getOptions (immutable)
8
+ * - DependenciesStore: get/set/remove dependencies
9
+ * - EventEmitter: subscribe
10
+ * - StateNamespace: state storage (getState, setState, getPreviousState)
11
+ * - RoutesNamespace: route tree operations
12
+ * - RouteLifecycleNamespace: canActivate/canDeactivate guards
13
+ * - PluginsNamespace: plugin lifecycle
14
+ * - NavigationNamespace: navigate
15
+ * - RouterLifecycleNamespace: start, stop, isStarted
16
+ *
17
+ * @internal This class implementation is internal. Use createRouter() instead.
18
+ */
19
+ declare class Router<Dependencies extends DefaultDependencies = DefaultDependencies> implements Router$1<Dependencies> {
20
+ #private;
21
+ [key: string]: unknown;
22
+ /**
23
+ * @param routes - Route definitions
24
+ * @param options - Router options
25
+ * @param dependencies - DI dependencies
26
+ */
27
+ constructor(routes?: Route<Dependencies>[], options?: Partial<Options>, dependencies?: Dependencies);
28
+ isActiveRoute(name: string, params?: Params, strictEquality?: boolean, ignoreQueryParams?: boolean): boolean;
29
+ buildPath(route: string, params?: Params): string;
30
+ getState<P extends Params = Params, MP extends Params = Params>(): State<P, MP> | undefined;
31
+ getPreviousState(): State | undefined;
32
+ areStatesEqual(state1: State | undefined, state2: State | undefined, ignoreQueryParams?: boolean): boolean;
33
+ shouldUpdateNode(nodeName: string): (toState: State, fromState?: State) => boolean;
34
+ isActive(): boolean;
35
+ start(startPath: string): Promise<State>;
36
+ stop(): this;
37
+ dispose(): void;
38
+ canNavigateTo(name: string, params?: Params): boolean;
39
+ usePlugin(...plugins: PluginFactory<Dependencies>[]): Unsubscribe;
40
+ subscribe(listener: SubscribeFn): Unsubscribe;
41
+ navigate(routeName: string, routeParams?: Params, options?: NavigationOptions): Promise<State>;
42
+ navigateToDefault(options?: NavigationOptions): Promise<State>;
43
+ navigateToNotFound(path?: string): State;
44
+ }
45
+
46
+ /**
47
+ * Path Matcher Type Definitions.
48
+ *
49
+ * Core types for path matching and parameter extraction.
50
+ *
51
+ * @module path-matcher/types
52
+ */
53
+ /**
54
+ * Constraint pattern for a URL parameter.
55
+ */
56
+ interface ConstraintPattern {
57
+ /**
58
+ * Compiled RegExp for validating the parameter value.
59
+ *
60
+ * @example /^(\d+)$/ for constraint "<\\d+>"
61
+ */
62
+ readonly pattern: RegExp;
63
+ /**
64
+ * Raw constraint string from the route pattern.
65
+ *
66
+ * @example "<\\d+>"
67
+ */
68
+ readonly constraint: string;
69
+ }
70
+ /**
71
+ * Parameter metadata extracted from a route path pattern.
72
+ */
73
+ interface ParamMeta {
74
+ /**
75
+ * URL parameter names extracted from the path pattern.
76
+ *
77
+ * @example [":id", ":postId"] from "/users/:id/posts/:postId"
78
+ */
79
+ readonly urlParams: readonly string[];
80
+ /**
81
+ * Query parameter names extracted from the path pattern.
82
+ *
83
+ * @example ["q", "page"] from "/search?q&page"
84
+ */
85
+ readonly queryParams: readonly string[];
86
+ /**
87
+ * Splat parameter names extracted from the path pattern.
88
+ *
89
+ * @example ["path"] from "/files/*path"
90
+ */
91
+ readonly spatParams: readonly string[];
92
+ /**
93
+ * Map of parameter names to their type (url or query).
94
+ *
95
+ * @example { id: "url", q: "query" }
96
+ */
97
+ readonly paramTypeMap: Readonly<Record<string, "url" | "query">>;
98
+ /**
99
+ * Map of parameter names to their constraint patterns.
100
+ *
101
+ * Only includes parameters with explicit constraints (e.g., `:id<\\d+>`).
102
+ * Parameters without constraints are not included in this map.
103
+ *
104
+ * @example
105
+ * ```typescript
106
+ * buildParamMeta("/users/:id<\\d+>").constraintPatterns.get("id")
107
+ * // → { pattern: /^(\d+)$/, constraint: "<\\d+>" }
108
+ *
109
+ * buildParamMeta("/users/:id").constraintPatterns.size
110
+ * // → 0 (no constraints)
111
+ * ```
112
+ */
113
+ readonly constraintPatterns: ReadonlyMap<string, ConstraintPattern>;
114
+ /**
115
+ * Path pattern without query string, pre-computed for buildPath.
116
+ *
117
+ * @example "/users/:id" from "/users/:id?q&page"
118
+ */
119
+ readonly pathPattern: string;
120
+ }
121
+
122
+ /**
123
+ * Immutable route tree node.
124
+ *
125
+ * This is the core data structure of the new route-tree architecture.
126
+ * It contains only data (no methods) and is created by the builder.
127
+ *
128
+ * All caches are pre-computed at build time:
129
+ * - nonAbsoluteChildren: filtered children without absolute paths
130
+ * - absoluteDescendants: all descendants with absolute paths (recursive)
131
+ * - parentSegments: array from root to parent
132
+ * - fullName: pre-computed "users.profile" instead of runtime join
133
+ */
134
+ interface RouteTree {
135
+ /** Route segment name (e.g., "users" in "users.profile") */
136
+ readonly name: string;
137
+ /** Route path pattern (e.g., "/users/:id") */
138
+ readonly path: string;
139
+ /** Whether this route uses absolute path matching (path starts with "~") */
140
+ readonly absolute: boolean;
141
+ /** Child route nodes (Map for O(1) lookup by name) */
142
+ readonly children: ReadonlyMap<string, RouteTree>;
143
+ /** Parameter metadata extracted from path pattern (replaces parser dependency) */
144
+ readonly paramMeta: ParamMeta;
145
+ /** Parent node (null for root) */
146
+ readonly parent: RouteTree | null;
147
+ /** Children without absolute paths (for regular matching) */
148
+ readonly nonAbsoluteChildren: readonly RouteTree[];
149
+ /** Pre-computed full name (e.g., "users.profile") */
150
+ readonly fullName: string;
151
+ /**
152
+ * Pre-computed static path for routes without parameters.
153
+ * Used by buildPath fast path to avoid inject() overhead.
154
+ * Only set when route has no URL params, query params, or splat params.
155
+ */
156
+ readonly staticPath: string | null;
157
+ /**
158
+ * Pre-computed parameter type map for this segment.
159
+ * Cached to avoid recomputing on every navigation.
160
+ * Maps param name → "url" | "query".
161
+ */
162
+ readonly paramTypeMap: Readonly<Record<string, "url" | "query">>;
163
+ }
164
+
165
+ export { Router as R, type RouteTree as a };
@@ -1,5 +1,7 @@
1
- import { Params, RouteTreeState, DefaultDependencies, Router as Router$1, Route, Options, State, PluginFactory, Unsubscribe, SubscribeFn, NavigationOptions, ErrorCodeKeys, ErrorCodeValues, ErrorCodeToValueMap, EventToNameMap, Navigator, PluginApi as PluginApi$1, RoutesApi, DependenciesApi, LifecycleApi } from '@real-router/types';
2
- export { Config, DefaultDependencies, DependenciesApi, GuardFn, GuardFnFactory, LifecycleApi, Listener, NavigationOptions, Navigator, Options, Params, Plugin, PluginFactory, Route, RouteConfigUpdate, RoutesApi, SimpleState, State, StateMeta, SubscribeFn, SubscribeState, Subscription, Unsubscribe } from '@real-router/types';
1
+ import { Params, RouteTreeState, ErrorCodeKeys, ErrorCodeValues, ErrorCodeToValueMap, EventToNameMap, State, DefaultDependencies, Route, Options, Router as Router$1, Navigator } from '@real-router/types';
2
+ export { Config, DefaultDependencies, GuardFn, GuardFnFactory, Listener, NavigationOptions, Navigator, Options, Params, Plugin, PluginFactory, Route, RouteConfigUpdate, SimpleState, State, StateMeta, SubscribeFn, SubscribeState, Subscription, Unsubscribe } from '@real-router/types';
3
+ import { R as Router } from './index.d-DDimDpYc.js';
4
+ export { a as RouteTree } from './index.d-DDimDpYc.js';
3
5
 
4
6
  /**
5
7
  * Core-internal types + re-exports from @real-router/types.
@@ -21,49 +23,6 @@ interface BuildStateResultWithSegments<P extends Params = Params> {
21
23
  readonly segments: readonly unknown[];
22
24
  }
23
25
 
24
- /**
25
- * Router class with integrated namespace architecture.
26
- *
27
- * All functionality is provided by namespace classes:
28
- * - OptionsNamespace: getOptions (immutable)
29
- * - DependenciesStore: get/set/remove dependencies
30
- * - EventEmitter: subscribe
31
- * - StateNamespace: state storage (getState, setState, getPreviousState)
32
- * - RoutesNamespace: route tree operations
33
- * - RouteLifecycleNamespace: canActivate/canDeactivate guards
34
- * - PluginsNamespace: plugin lifecycle
35
- * - NavigationNamespace: navigate
36
- * - RouterLifecycleNamespace: start, stop, isStarted
37
- *
38
- * @internal This class implementation is internal. Use createRouter() instead.
39
- */
40
- declare class Router<Dependencies extends DefaultDependencies = DefaultDependencies> implements Router$1<Dependencies> {
41
- #private;
42
- [key: string]: unknown;
43
- /**
44
- * @param routes - Route definitions
45
- * @param options - Router options
46
- * @param dependencies - DI dependencies
47
- */
48
- constructor(routes?: Route<Dependencies>[], options?: Partial<Options>, dependencies?: Dependencies);
49
- isActiveRoute(name: string, params?: Params, strictEquality?: boolean, ignoreQueryParams?: boolean): boolean;
50
- buildPath(route: string, params?: Params): string;
51
- getState<P extends Params = Params, MP extends Params = Params>(): State<P, MP> | undefined;
52
- getPreviousState(): State | undefined;
53
- areStatesEqual(state1: State | undefined, state2: State | undefined, ignoreQueryParams?: boolean): boolean;
54
- shouldUpdateNode(nodeName: string): (toState: State, fromState?: State) => boolean;
55
- isActive(): boolean;
56
- start(startPath: string): Promise<State>;
57
- stop(): this;
58
- dispose(): void;
59
- canNavigateTo(name: string, params?: Params): boolean;
60
- usePlugin(...plugins: PluginFactory<Dependencies>[]): Unsubscribe;
61
- subscribe(listener: SubscribeFn): Unsubscribe;
62
- navigate(routeName: string, routeParams?: Params, options?: NavigationOptions): Promise<State>;
63
- navigateToDefault(options?: NavigationOptions): Promise<State>;
64
- navigateToNotFound(path?: string): State;
65
- }
66
-
67
26
  type ConstantsKeys = "UNKNOWN_ROUTE";
68
27
  type Constants = Record<ConstantsKeys, string>;
69
28
  type ErrorCodes = Record<ErrorCodeKeys, ErrorCodeValues>;
@@ -292,137 +251,4 @@ declare const createRouter: <Dependencies extends DefaultDependencies = DefaultD
292
251
 
293
252
  declare const getNavigator: <Dependencies extends DefaultDependencies = DefaultDependencies>(router: Router$1<Dependencies>) => Navigator;
294
253
 
295
- /**
296
- * Path Matcher Type Definitions.
297
- *
298
- * Core types for path matching and parameter extraction.
299
- *
300
- * @module path-matcher/types
301
- */
302
- /**
303
- * Constraint pattern for a URL parameter.
304
- */
305
- interface ConstraintPattern {
306
- /**
307
- * Compiled RegExp for validating the parameter value.
308
- *
309
- * @example /^(\d+)$/ for constraint "<\\d+>"
310
- */
311
- readonly pattern: RegExp;
312
- /**
313
- * Raw constraint string from the route pattern.
314
- *
315
- * @example "<\\d+>"
316
- */
317
- readonly constraint: string;
318
- }
319
- /**
320
- * Parameter metadata extracted from a route path pattern.
321
- */
322
- interface ParamMeta {
323
- /**
324
- * URL parameter names extracted from the path pattern.
325
- *
326
- * @example [":id", ":postId"] from "/users/:id/posts/:postId"
327
- */
328
- readonly urlParams: readonly string[];
329
- /**
330
- * Query parameter names extracted from the path pattern.
331
- *
332
- * @example ["q", "page"] from "/search?q&page"
333
- */
334
- readonly queryParams: readonly string[];
335
- /**
336
- * Splat parameter names extracted from the path pattern.
337
- *
338
- * @example ["path"] from "/files/*path"
339
- */
340
- readonly spatParams: readonly string[];
341
- /**
342
- * Map of parameter names to their type (url or query).
343
- *
344
- * @example { id: "url", q: "query" }
345
- */
346
- readonly paramTypeMap: Readonly<Record<string, "url" | "query">>;
347
- /**
348
- * Map of parameter names to their constraint patterns.
349
- *
350
- * Only includes parameters with explicit constraints (e.g., `:id<\\d+>`).
351
- * Parameters without constraints are not included in this map.
352
- *
353
- * @example
354
- * ```typescript
355
- * buildParamMeta("/users/:id<\\d+>").constraintPatterns.get("id")
356
- * // → { pattern: /^(\d+)$/, constraint: "<\\d+>" }
357
- *
358
- * buildParamMeta("/users/:id").constraintPatterns.size
359
- * // → 0 (no constraints)
360
- * ```
361
- */
362
- readonly constraintPatterns: ReadonlyMap<string, ConstraintPattern>;
363
- /**
364
- * Path pattern without query string, pre-computed for buildPath.
365
- *
366
- * @example "/users/:id" from "/users/:id?q&page"
367
- */
368
- readonly pathPattern: string;
369
- }
370
-
371
- /**
372
- * Immutable route tree node.
373
- *
374
- * This is the core data structure of the new route-tree architecture.
375
- * It contains only data (no methods) and is created by the builder.
376
- *
377
- * All caches are pre-computed at build time:
378
- * - nonAbsoluteChildren: filtered children without absolute paths
379
- * - absoluteDescendants: all descendants with absolute paths (recursive)
380
- * - parentSegments: array from root to parent
381
- * - fullName: pre-computed "users.profile" instead of runtime join
382
- */
383
- interface RouteTree {
384
- /** Route segment name (e.g., "users" in "users.profile") */
385
- readonly name: string;
386
- /** Route path pattern (e.g., "/users/:id") */
387
- readonly path: string;
388
- /** Whether this route uses absolute path matching (path starts with "~") */
389
- readonly absolute: boolean;
390
- /** Child route nodes (Map for O(1) lookup by name) */
391
- readonly children: ReadonlyMap<string, RouteTree>;
392
- /** Parameter metadata extracted from path pattern (replaces parser dependency) */
393
- readonly paramMeta: ParamMeta;
394
- /** Parent node (null for root) */
395
- readonly parent: RouteTree | null;
396
- /** Children without absolute paths (for regular matching) */
397
- readonly nonAbsoluteChildren: readonly RouteTree[];
398
- /** Pre-computed full name (e.g., "users.profile") */
399
- readonly fullName: string;
400
- /**
401
- * Pre-computed static path for routes without parameters.
402
- * Used by buildPath fast path to avoid inject() overhead.
403
- * Only set when route has no URL params, query params, or splat params.
404
- */
405
- readonly staticPath: string | null;
406
- /**
407
- * Pre-computed parameter type map for this segment.
408
- * Cached to avoid recomputing on every navigation.
409
- * Maps param name → "url" | "query".
410
- */
411
- readonly paramTypeMap: Readonly<Record<string, "url" | "query">>;
412
- }
413
-
414
- interface PluginApi extends Omit<PluginApi$1, "getTree"> {
415
- getTree: () => RouteTree;
416
- }
417
-
418
- declare function getPluginApi<Dependencies extends DefaultDependencies = DefaultDependencies>(router: Router$1<Dependencies>): PluginApi;
419
-
420
- declare function getRoutesApi<Dependencies extends DefaultDependencies = DefaultDependencies>(router: Router$1<Dependencies>): RoutesApi<Dependencies>;
421
-
422
- declare function getDependenciesApi<Dependencies extends DefaultDependencies = DefaultDependencies>(router: Router$1<Dependencies>): DependenciesApi<Dependencies>;
423
-
424
- declare function getLifecycleApi<Dependencies extends DefaultDependencies = DefaultDependencies>(router: Router$1<Dependencies>): LifecycleApi<Dependencies>;
425
-
426
- declare function cloneRouter<Dependencies extends DefaultDependencies = DefaultDependencies>(router: Router$1<Dependencies>, dependencies?: Dependencies): Router<Dependencies>;
427
-
428
- export { type BuildStateResultWithSegments, type Constants, type ErrorCodes, type PluginApi, type RouteTree, Router, RouterError, UNKNOWN_ROUTE, cloneRouter, constants, createRouter, errorCodes, events, getDependenciesApi, getLifecycleApi, getNavigator, getPluginApi, getRoutesApi };
254
+ export { type BuildStateResultWithSegments, type Constants, type ErrorCodes, Router, RouterError, UNKNOWN_ROUTE, constants, createRouter, errorCodes, events, getNavigator };